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() 
00069          ? QString::fromLocal8Bit(args->getOption("group")) 
00070          : i18n("Imported Folder");
00071 
00072     QCStringList feeds = args->getOptionList("addfeed");
00073     QStringList feedsToAdd;
00074     QCStringList::ConstIterator end( feeds.end() );
00075     for (QCStringList::ConstIterator it = feeds.begin(); it != end; ++it)
00076         feedsToAdd.append(*it);
00077 
00078     if (!feedsToAdd.isEmpty())
00079         akr.send("addFeedsToGroup", feedsToAdd, addFeedGroup );
00080   
00081     args->clear();
00082   }
00083   return KUniqueApplication::newInstance();
00084 }
00085 
00086 } // namespace Akregator
00087 
00088 int main(int argc, char **argv)
00089 {
00090     Akregator::AboutData about;
00091     KCmdLineArgs::init(argc, argv, &about);
00092     KCmdLineArgs::addCmdLineOptions( Akregator::akregator_options );
00093     KUniqueApplication::addCmdLineOptions();
00094 
00095     Akregator::Application app;
00096 
00097     // start knotifyclient if not already started. makes it work for people who doesn't use full kde, according to kmail devels
00098     KNotifyClient::startDaemon();
00099 
00100     // see if we are starting with session management
00101     if (app.isRestored())
00102     {
00103 #undef RESTORE
00104 #define RESTORE(type) { int n = 1;\
00105     while (KMainWindow::canBeRestored(n)){\
00106         (new type)->restore(n, false);\
00107             n++;}}
00108 
00109         RESTORE(Akregator::MainWindow);
00110     }
00111 
00112     return app.exec();
00113 }
00114 
00115 
KDE Home | KDE Accessibility Home | Description of Access Keys