kaddressbook Library API Documentation

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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   KStartupInfo::setNewStartupId( mMainWin, kapp->startupId() );
00102 #endif
00103 
00104   return 0;
00105 }
00106 
00107 int main( int argc, char *argv[] )
00108 {
00109   KLocale::setMainCatalogue( "kaddressbook" );
00110 
00111   KCmdLineArgs::init( argc, argv, KABCore::createAboutData() );
00112   KCmdLineArgs::addCmdLineOptions( kaddressbook_options );
00113   KUniqueApplication::addCmdLineOptions();
00114 
00115   if ( !KAddressBookApp::start() )
00116     exit( 0 );
00117 
00118   KAddressBookApp app;
00119   KGlobal::locale()->insertCatalogue( "libkdepim" );
00120 
00121   bool ret = app.exec();
00122   while (KMainWindow::memberList->first())
00123       delete KMainWindow::memberList->first();
00124   return ret;
00125 }
KDE Logo
This file is part of the documentation for kaddressbook Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Dec 21 14:24:12 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003