kaddressbook

main.cpp

00001 /*
00002     This file is part of KAddressBook.
00003     Copyright (C) 1999 Don Sanders <sanders@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 
00024 #include <stdlib.h>
00025 #include <unistd.h>
00026 
00027 #include <qstring.h>
00028 
00029 #include <kabc/stdaddressbook.h>
00030 #include <kaboutdata.h>
00031 #include <kcmdlineargs.h>
00032 #include <kcrash.h>
00033 #include <kdebug.h>
00034 #include <klocale.h>
00035 #include <kstartupinfo.h>
00036 #include <kuniqueapplication.h>
00037 #include <kwin.h>
00038 
00039 #include "kaddressbookmain.h"
00040 #include "kaddressbook_options.h"
00041 #include "kabcore.h"
00042 
00043 class KAddressBookApp : public KUniqueApplication {
00044   public:
00045     KAddressBookApp() : mMainWin( 0 ), mDefaultIsOpen( false ) {}
00046     ~KAddressBookApp() {}
00047 
00048     int newInstance();
00049 
00050   private:
00051     KAddressBookMain *mMainWin;
00052     bool mDefaultIsOpen;
00053 };
00054 
00055 int KAddressBookApp::newInstance()
00056 {
00057   if ( isRestored() ) {
00058     // There can only be one main window
00059     if ( KMainWindow::canBeRestored( 1 ) ) {
00060       mMainWin = new KAddressBookMain;
00061       setMainWidget( mMainWin );
00062       mMainWin->show();
00063       mMainWin->restore( 1 );
00064     }
00065   } else {
00066     KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00067 
00068     if ( args->isSet( "editor-only" ) ) {
00069         if ( !mMainWin ) {
00070           mMainWin = new KAddressBookMain;
00071           setMainWidget( mMainWin );
00072           mMainWin->hide();
00073         }
00074         // otherwise, leave the window like it is (hidden or shown)
00075         KStartupInfo::appStarted();
00076     } else {
00077       QString file;
00078       if ( args->isSet( "document" ) ) {
00079          file = args->getOption( "document" );
00080       }
00081       if ( !( file.isEmpty() && mDefaultIsOpen ) ) {
00082         if ( !mMainWin ) {
00083           mMainWin = new KAddressBookMain( file );
00084           setMainWidget( mMainWin );
00085           mMainWin->show();
00086         } else {
00087           KAddressBookMain *m = new KAddressBookMain( file );
00088           m->show();
00089         }
00090         if ( file.isEmpty() ) mDefaultIsOpen = true;
00091       }
00092     }
00093 
00094     mMainWin->handleCommandLine();
00095   }
00096 
00097   // Handle startup notification and window activation
00098   // We do it ourselves instead of calling KUniqueApplication::newInstance
00099   // to avoid the show() call there.
00100 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
00101   static bool firstInstance = true;
00102 
00103   if ( !firstInstance )
00104     KStartupInfo::setNewStartupId( mMainWin, kapp->startupId() );
00105 
00106   firstInstance = false;
00107 #endif
00108 
00109   return 0;
00110 }
00111 
00112 int main( int argc, char *argv[] )
00113 {
00114   KLocale::setMainCatalogue( "kaddressbook" );
00115 
00116   KCmdLineArgs::init( argc, argv, KABCore::createAboutData() );
00117   KCmdLineArgs::addCmdLineOptions( kaddressbook_options );
00118   KUniqueApplication::addCmdLineOptions();
00119 
00120   if ( !KAddressBookApp::start() )
00121     return 0;
00122 
00123   KAddressBookApp app;
00124   KGlobal::locale()->insertCatalogue( "libkdepim" );
00125 
00126   bool ret = app.exec();
00127   while (KMainWindow::memberList->first())
00128       delete KMainWindow::memberList->first();
00129   return ret;
00130 }
KDE Home | KDE Accessibility Home | Description of Access Keys