main.cpp
00001 #include <stdlib.h>
00002
00003 #include <qstring.h>
00004
00005 #include <kabc/stdaddressbook.h>
00006 #include <kcmdlineargs.h>
00007 #include <kcrash.h>
00008 #include <klocale.h>
00009 #include <kaboutdata.h>
00010 #include <kdebug.h>
00011 #include <kuniqueapplication.h>
00012 #include <kwin.h>
00013 #include <kstartupinfo.h>
00014
00015 #include "kaddressbookmain.h"
00016 #include "kaddressbook_part.h"
00017
00018 extern "C" {
00019
00020 void crashHandler( int )
00021 {
00022 KABC::StdAddressBook::handleCrash();
00023 ::exit( 0 );
00024 }
00025
00026 }
00027
00028 class KAddressBookApp : public KUniqueApplication {
00029 public:
00030 KAddressBookApp() : mMainWin(0) {}
00031 ~KAddressBookApp() {}
00032
00033 int newInstance();
00034
00035 private:
00036 KAddressBookMain *mMainWin;
00037 };
00038
00039 int KAddressBookApp::newInstance()
00040 {
00041 if (isRestored()) {
00042
00043 if (KMainWindow::canBeRestored(1)) {
00044 mMainWin = new KAddressBookMain;
00045 mMainWin->show();
00046 mMainWin->restore(1);
00047 }
00048 } else {
00049 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00050
00051 QCString addrStr = args->getOption("addr");
00052 QCString uidStr = args->getOption("uid");
00053 QString addr;
00054 QString uid;
00055 if (!addrStr.isEmpty()) addr = QString::fromLocal8Bit(addrStr);
00056 if (!uidStr.isEmpty()) uid = QString::fromLocal8Bit(uidStr);
00057
00058
00059 if (args->isSet("editor-only")) {
00060 if (!mMainWin)
00061 mMainWin = new KAddressBookMain;
00062 KStartupInfo::appStarted();
00063 mMainWin->hide();
00064 } else {
00065 if (mMainWin) {
00066 mMainWin->show();
00067 KWin::setActiveWindow(mMainWin->winId());
00068 } else {
00069 mMainWin = new KAddressBookMain;
00070 mMainWin->show();
00071 }
00072 }
00073
00074 if (!addr.isEmpty()) mMainWin->addEmail(addr);
00075 if (!uid.isEmpty()) mMainWin->showContactEditor(uid);
00076 }
00077
00078 KCrash::setEmergencySaveFunction( crashHandler );
00079
00080 return 0;
00081 }
00082
00083
00084
00085 static KCmdLineOptions kmoptions[] =
00086 {
00087 { "a", 0 , 0 },
00088 { "addr <email>", I18N_NOOP("Shows contact editor with given email address"), 0 },
00089 { "uid <uid>", I18N_NOOP("Shows contact editor with given uid"), 0 },
00090 { "editor-only", I18N_NOOP("Launches in editor only mode"), 0 },
00091 { "+[argument]", I18N_NOOP("dummy argument"), 0},
00092 { 0, 0, 0}
00093 };
00094
00095 int main(int argc, char *argv[])
00096 {
00097 KLocale::setMainCatalogue("kaddressbook");
00098
00099 KCmdLineArgs::init(argc, argv, KAddressbookPart::createAboutData());
00100 KCmdLineArgs::addCmdLineOptions( kmoptions );
00101 KUniqueApplication::addCmdLineOptions();
00102
00103 if (!KAddressBookApp::start()) exit(0);
00104
00105 KAddressBookApp app;
00106 KGlobal::locale()->insertCatalogue("libkdepim");
00107
00108 return app.exec();
00109 }
00110
This file is part of the documentation for kdelibs Version 3.1.5.