akregator/src

main.cpp

00001 /*
00002     This file is part of Akregator.
00003 
00004     Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qstringlist.h>
00026 
00027 #include <dcopref.h>
00028 #include <kcmdlineargs.h>
00029 #include <klocale.h>
00030 #include <knotifyclient.h>
00031 #include <kuniqueapplication.h>
00032 
00033 #include "aboutdata.h"
00034 #include "mainwindow.h"
00035 #include "akregator_options.h"
00036 
00037 namespace Akregator {
00038 
00039 class Application : public KUniqueApplication {
00040   public:
00041     Application() : mMainWindow( ) {}
00042     ~Application() {}
00043 
00044     int newInstance();
00045 
00046   private:
00047     Akregator::MainWindow *mMainWindow;
00048 };
00049 
00050 int Application::newInstance()
00051 {
00052   if (!isRestored())
00053   {
00054     DCOPRef akr("akregator", "AkregatorIface");
00055 
00056     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00057 
00058     if ( !mMainWindow ) {
00059       mMainWindow = new Akregator::MainWindow();
00060       setMainWidget( mMainWindow );
00061       mMainWindow->loadPart();
00062       mMainWindow->setupProgressWidgets();
00063       if (!args->isSet("hide-mainwindow"))
00064         mMainWindow->show();
00065       akr.send("openStandardFeedList");
00066     }
00067 
00068     QString addFeedGroup = !args->getOption("group").isEmpty() ? args->getOption("group") : i18n("Imported Folder");
00069 
00070     QCStringList feeds = args->getOptionList("addfeed");
00071     QStringList feedsToAdd;
00072     QCStringList::ConstIterator end( feeds.end() );
00073     for (QCStringList::ConstIterator it = feeds.begin(); it != end; ++it)
00074         feedsToAdd.append(*it);
00075 
00076     if (!feedsToAdd.isEmpty())
00077         akr.send("addFeedsToGroup", feedsToAdd, addFeedGroup );
00078   
00079     args->clear();
00080   }
00081   return KUniqueApplication::newInstance();
00082 }
00083 
00084 } // namespace Akregator
00085 
00086 int main(int argc, char **argv)
00087 {
00088     Akregator::AboutData about;
00089     KCmdLineArgs::init(argc, argv, &about);
00090     KCmdLineArgs::addCmdLineOptions( Akregator::akregator_options );
00091     KUniqueApplication::addCmdLineOptions();
00092 
00093     Akregator::Application app;
00094 
00095     // start knotifyclient if not already started. makes it work for people who doesn't use full kde, according to kmail devels
00096     KNotifyClient::startDaemon();
00097 
00098     // see if we are starting with session management
00099     if (app.isRestored())
00100     {
00101 #undef RESTORE
00102 #define RESTORE(type) { int n = 1;\
00103     while (KMainWindow::canBeRestored(n)){\
00104         (new type)->restore(n, false);\
00105             n++;}}
00106 
00107         RESTORE(Akregator::MainWindow);
00108     }
00109 
00110     return app.exec();
00111 }
00112 
00113 
KDE Home | KDE Accessibility Home | Description of Access Keys