TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.7KB

  1. /*
  2. This file is part of KAddressBook.
  3. Copyright (C) 1999 Don Sanders <sanders@kde.org>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  15. As a special exception, permission is given to link this program
  16. with any edition of TQt, and distribute the resulting executable,
  17. without including the source code for TQt in the source distribution.
  18. */
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <tqstring.h>
  22. #include <kabc/stdaddressbook.h>
  23. #include <kaboutdata.h>
  24. #include <kcmdlineargs.h>
  25. #include <kcrash.h>
  26. #include <kdebug.h>
  27. #include <klocale.h>
  28. #include <kstartupinfo.h>
  29. #include <kuniqueapplication.h>
  30. #include <kwin.h>
  31. #include "kaddressbookmain.h"
  32. #include "kaddressbook_options.h"
  33. #include "kabcore.h"
  34. class KAddressBookApp : public KUniqueApplication {
  35. public:
  36. KAddressBookApp() : mMainWin( 0 ), mDefaultIsOpen( false ) {}
  37. ~KAddressBookApp() {}
  38. int newInstance();
  39. private:
  40. KAddressBookMain *mMainWin;
  41. bool mDefaultIsOpen;
  42. };
  43. int KAddressBookApp::newInstance()
  44. {
  45. if ( isRestored() ) {
  46. // There can only be one main window
  47. if ( KMainWindow::canBeRestored( 1 ) ) {
  48. mMainWin = new KAddressBookMain;
  49. setMainWidget( mMainWin );
  50. mMainWin->show();
  51. mMainWin->restore( 1 );
  52. }
  53. } else {
  54. KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
  55. if ( args->isSet( "editor-only" ) ) {
  56. if ( !mMainWin ) {
  57. mMainWin = new KAddressBookMain;
  58. setMainWidget( mMainWin );
  59. mMainWin->hide();
  60. }
  61. // otherwise, leave the window like it is (hidden or shown)
  62. KStartupInfo::appStarted();
  63. } else {
  64. TQString file;
  65. if ( args->isSet( "document" ) ) {
  66. file = args->getOption( "document" );
  67. }
  68. if ( !( file.isEmpty() && mDefaultIsOpen ) ) {
  69. if ( !mMainWin ) {
  70. mMainWin = new KAddressBookMain( file );
  71. setMainWidget( mMainWin );
  72. mMainWin->show();
  73. } else {
  74. KAddressBookMain *m = new KAddressBookMain( file );
  75. m->show();
  76. }
  77. if ( file.isEmpty() ) mDefaultIsOpen = true;
  78. }
  79. }
  80. mMainWin->handleCommandLine();
  81. }
  82. // Handle startup notification and window activation
  83. // We do it ourselves instead of calling KUniqueApplication::newInstance
  84. // to avoid the show() call there.
  85. #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY
  86. static bool firstInstance = true;
  87. if ( !firstInstance )
  88. KStartupInfo::setNewStartupId( mMainWin, kapp->startupId() );
  89. firstInstance = false;
  90. #endif
  91. return 0;
  92. }
  93. int main( int argc, char *argv[] )
  94. {
  95. KLocale::setMainCatalogue( "kaddressbook" );
  96. KCmdLineArgs::init( argc, argv, KABCore::createAboutData() );
  97. KCmdLineArgs::addCmdLineOptions( kaddressbook_options );
  98. KUniqueApplication::addCmdLineOptions();
  99. if ( !KAddressBookApp::start() )
  100. return 0;
  101. KAddressBookApp app;
  102. KGlobal::locale()->insertCatalogue( "libtdepim" );
  103. bool ret = app.exec();
  104. while (KMainWindow::memberList->first())
  105. delete KMainWindow::memberList->first();
  106. return ret;
  107. }