Now the systrayicon change it's color when a download is in progress. I simply change...
[kdenetwork.git] / kget / main.cpp
blob8d05d4662d1af02f01375172660686bcb5c56585
1 /***************************************************************************
2 * main.cpp
3 * -------------------
5 * Revision : $Id$
6 * begin : Tue Jan 29 2002
7 * copyright : (C) 2002 by Patrick Charbonnier
8 * : Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss
9 * email : pch@freeshell.org
11 ****************************************************************************/
13 /***************************************************************************
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 ***************************************************************************/
28 #include <kwin.h>
29 #include <klocale.h>
30 #include <kaboutdata.h>
31 #include <kcmdlineargs.h>
32 #include <kurl.h>
33 #include <kuniqueapplication.h>
34 #include <kstartupinfo.h>
36 #include <signal.h>
37 #include <unistd.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include "kmainwidget.h"
41 #include "version.h"
45 static const char description[] = I18N_NOOP("An advanced download manager for KDE");
47 static const char version[] = KGETVERSION;
50 static KCmdLineOptions option[] = {
51 { "showDropTarget", I18N_NOOP("Start KGet with drop target"), 0 },
52 {"+[URL(s)]", I18N_NOOP("URL(s) to download"), 0},
53 KCmdLineLastOption
56 static void cleanup(void);
57 static void setSignalHandler(void (*handler) (int));
59 //static msg_handler oldMsgHandler = 0L;
61 //-----------------------------------------------------------------------------
62 // Crash recovery signal handler
63 static void signalHandler(int sigId)
65 fprintf(stderr, "*** KGet got signal %d\n", sigId);
67 if (sigId != SIGSEGV && kmain) {
68 fprintf(stderr, "*** KGet saving data\n");
69 delete kmain;
71 // If Kget crashes again below this line we consider the data lost :-|
72 // Otherwise Kget will end in an infinite loop.
73 setSignalHandler(SIG_DFL);
74 cleanup();
75 exit(1);
79 //-----------------------------------------------------------------------------
80 static void setSignalHandler(void (*handler) (int))
82 signal(SIGSEGV, handler);
83 signal(SIGKILL, handler);
84 signal(SIGTERM, handler);
85 signal(SIGHUP, handler);
86 signal(SIGFPE, handler);
87 signal(SIGABRT, handler);
89 // catch also the keyboard interrupt
90 signal(SIGINT, handler);
94 static void cleanup(void)
96 qInstallMsgHandler(0L /*oldMsgHandler*/);
97 // QString cmd;
101 class KGetApp : public KUniqueApplication
103 private:
104 KMainWidget *kmainwidget;
106 public:
107 KGetApp() : KUniqueApplication()
109 #ifdef _DEBUG
110 sDebugIn << endl;
111 #endif
113 kmainwidget=0;
115 #ifdef _DEBUG
116 sDebugOut << endl;
117 #endif
120 ~KGetApp()
122 #ifdef _DEBUG
123 sDebugIn << endl;
124 #endif
125 delete kmainwidget;
126 #ifdef _DEBUG
127 sDebugOut << endl;
128 #endif
132 int newInstance()
134 #ifdef _DEBUG
135 sDebugIn <<"kmainwidget="<<kmainwidget << endl;
136 #endif
138 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
141 if (kmainwidget==0)
143 if(args->count()>0)
144 kmainwidget=new KMainWidget(true);
145 else
146 kmainwidget=new KMainWidget();
147 setMainWidget(kmain);
150 else
151 KStartupInfo::setNewStartupId( mainWidget(), kapp->startupId());
153 if (args->isSet("showDropTarget"))
154 kmain->activateDropTarget();
156 if (args->count()==1)
158 #ifdef _DEBUG
159 sDebug <<"args(0)= "<<args->arg(0) << endl;
160 #endif
161 QString txt(args->arg(0));
162 if ( txt.endsWith( ".kgt" ) )
163 kmain->readTransfersEx(KURL::fromPathOrURL( txt ));
164 else
165 kmain->addTransferEx( KURL::fromPathOrURL( txt ),
166 KURL());
168 else if(args->count()==2)
169 kmain->addTransferEx( KURL::fromPathOrURL( args->arg(0) ),
170 KURL::fromPathOrURL( args->arg(1) ));
172 args->clear();
174 #ifdef _DEBUG
175 sDebugOut << endl;
176 #endif
178 return 0;
183 /////////////////////////////////////////////////////////////////
185 int main(int argc, char *argv[])
187 KAboutData aboutData("kget", I18N_NOOP("KGet"), version, description, KAboutData::License_GPL, "(C) 2001 - 2002, Patrick Charbonnier \n(C) 2002, Carsten Pfeiffer\n(C) 1998 - 2000, Matej Koss", 0, "http://kget.sourceforge.net");
189 aboutData.addAuthor("Patrick Charbonnier", 0, "pch@freeshell.org");
190 aboutData.addAuthor("Carsten Pfeiffer", 0, "pfeiffer@kde.org");
191 aboutData.addAuthor("Matej Koss", 0);
194 KCmdLineArgs::init(argc, argv, &aboutData);
195 KCmdLineArgs::addCmdLineOptions(option);
197 KGetApp::addCmdLineOptions();
199 if (!KGetApp::start()) {
200 fprintf(stderr, "kget is already running!\n");
201 return 0;
204 KGetApp kApp;
206 // disabling he custom signal handler, so at least we have the backtraces for
207 // crashes...
208 // setSignalHandler(signalHandler);
209 kApp.exec();
211 cleanup();