summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: a5788fb5fa34d173fbc8d3d026e1534b97f5f0bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/***************************************************************************
                          main.cpp  -  description
                             -------------------
    begin                : Thu Jun 19 14:43:55 BST 2003
    copyright            : (C) 2003 by KoolDock team
    email                : 
 ***************************************************************************/

/***************************************************************************
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#include <tdecmdlineargs.h>
#include <tdeaboutdata.h>
#include <tdelocale.h>
#include <kcrash.h>
#include <kdebug.h>
#include <kuniqueapplication.h>

#include <stdio.h>
#include <stdlib.h>
#include <tdemessagebox.h>

#include "kooldock.h"

#define KOOLDOCK_VERSION "0.4.7"
TQString argv0;

#ifndef _ENABLE_DEBUG
extern "C"
{
  static void crashHandler(int /*signal*/)
  {
    char cmd[1024];
    fprintf(stderr, "kooldock: crashHandler called\n");
    snprintf(cmd, 1023, "%s &", argv0.ascii());
    int status = system(cmd); // try to restart according to argv[0]
    status++;
  }
}
#endif

static const char *description = I18N_NOOP("<center><b>KoolDock</b></center>A Kool Dock for KDE<br><br>KoolDock is based upon the original work of Dang Viet Dung, Ksmoothdock 2.1<br><br>");

static TDECmdLineOptions options[] =
{
   { "o", 0, 0 },
   { "options", I18N_NOOP("Show configuration window on start"), 0 },
   { "k", 0, 0 },
   { "kill", I18N_NOOP("Kills all processes called Kooldock"), 0 },
   {0, 0, 0}
};

int main(int argc, char *argv[])
{
   argv0 = TQString("%1").arg(argv[0]);

   TDEAboutData aboutData("kooldock", I18N_NOOP("KoolDock"),
                          KOOLDOCK_VERSION, description, TDEAboutData::License_GPL,
                          "(c) 2003, 2006 - KoolDock team", 0, "http://ktown.kde.cl/kooldock", "[email protected]");
   aboutData.addAuthor("Matias Fernandez",0, "[email protected]");
   aboutData.addAuthor("Francisco Guidi",0, "[email protected]", "http://francisco.guidi.com");
   aboutData.addAuthor("Blase Stanek", 0, "[email protected]");
   aboutData.addCredit("Mauricio Bahamonde", I18N_NOOP("Project Webmaster"), "[email protected]", "http://ktown.kde.cl/~elkrammer/");
   aboutData.addCredit("Sebastian Sariego Benitez", I18N_NOOP("Icon and artwork"), "[email protected]", "http://segfault.kde.cl");
   aboutData.setTranslator(I18N_NOOP("_: NAME OF TRANSLATORS\nYour names"), I18N_NOOP("_: EMAIL OF TRANSLATORS\nYour emails"));
   TDECmdLineArgs::init( argc, argv, &aboutData );
   TDECmdLineArgs::addCmdLineOptions( options ); // Add our own options.
   
   #ifdef _ENABLE_DEBUG
   TDEApplication::addCmdLineOptions();
   #endif
   #ifndef _ENABLE_DEBUG
   KUniqueApplication::addCmdLineOptions();
   #endif
   if ((TQString("%1").arg(argv[1]) == "-kill") || (TQString("%1").arg(argv[1]) == "-k")) {
	   int status = system("killall kooldock");
     status++;
	   exit(0);
   } 
   
   #ifndef _ENABLE_DEBUG
   if (!KUniqueApplication::start()) {
    fprintf(stderr, "Kooldock is already running!\n");
    exit(0);
   }
   #endif
  
   #ifndef _ENABLE_DEBUG
   KUniqueApplication a;
   #endif
   #ifdef _ENABLE_DEBUG
   TDEApplication a;
   #endif
   KoolDock* kooldock = new KoolDock();
   a.setMainWidget(kooldock);

   #ifndef _ENABLE_DEBUG
   if (TDECrash::crashHandler() !=0 ) {
     kdDebug(0) << "Installing crash handler" << endl;
     TDECrash::setEmergencySaveFunction(crashHandler); // Try to restart on crash
   }
   #endif
   
   kooldock->setMainPath(argv0);
   kooldock->setArgs(TQString("%1").arg(argv[1]));
   return a.exec();
}