1 /***************************************************************************
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 ***************************************************************************/
30 #include <kaboutdata.h>
31 #include <kcmdlineargs.h>
33 #include <kuniqueapplication.h>
34 #include <kstartupinfo.h>
40 #include "kmainwidget.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},
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");
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
);
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*/);
101 class KGetApp
: public KUniqueApplication
104 KMainWidget
*kmainwidget
;
107 KGetApp() : KUniqueApplication()
135 sDebugIn
<<"kmainwidget="<<kmainwidget
<< endl
;
138 KCmdLineArgs
*args
= KCmdLineArgs::parsedArgs();
144 kmainwidget
=new KMainWidget(true);
146 kmainwidget
=new KMainWidget();
147 setMainWidget(kmain
);
151 KStartupInfo::setNewStartupId( mainWidget(), kapp
->startupId());
153 if (args
->isSet("showDropTarget"))
154 kmain
->activateDropTarget();
156 if (args
->count()==1)
159 sDebug
<<"args(0)= "<<args
->arg(0) << endl
;
161 QString
txt(args
->arg(0));
162 if ( txt
.endsWith( ".kgt" ) )
163 kmain
->readTransfersEx(KURL::fromPathOrURL( txt
));
165 kmain
->addTransferEx( KURL::fromPathOrURL( txt
),
168 else if(args
->count()==2)
169 kmain
->addTransferEx( KURL::fromPathOrURL( args
->arg(0) ),
170 KURL::fromPathOrURL( args
->arg(1) ));
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");
206 // disabling he custom signal handler, so at least we have the backtraces for
208 // setSignalHandler(signalHandler);