kaddressbook
main.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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
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
00098
00099
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 }
|