Only check SystemTray if a transfers status changed.
[kdenetwork.git] / kget / main.cpp
blobacbbfdfd1958688ba8491e08fab5327fa87542b0
1 /* This file is part of the KDE project
3 Copyright (C) 2002 by Patrick Charbonnier <pch@freeshell.org>
4 Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
13 #include <kwindowsystem.h>
14 #include <klocale.h>
15 #include <kaboutdata.h>
16 #include <kcmdlineargs.h>
17 #include <kuniqueapplication.h>
18 #include <kstandarddirs.h>
20 #include "core/kget.h"
21 #include "kgetadaptor.h"
22 #include "settings.h"
23 #include "ui/splash.h"
24 #include "mainwindow.h"
25 #include "ui/newtransferdialog.h"
27 class KGetApp : public KUniqueApplication
29 public:
30 KGetApp()
31 : KUniqueApplication(), kget( 0 ), splash( 0 )
33 showSplash();
36 ~KGetApp()
38 delete splash;
39 delete kget;
42 void showSplash()
44 //determine whether splash-screen is enabled in kgetrc
45 if ( !Settings::showSplashscreen() )
46 return;
48 // getting splash-screen path
49 QString path = KStandardDirs::locate( "data", "kget/pics/kget_splash.png" );
51 if ( !path.isEmpty() )
52 splash = new Splash( path );
55 int newInstance()
57 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
59 if (!kget)
61 kget = new MainWindow(!args->isSet("showDropTarget"), args->isSet("startWithoutAnimation"));
62 new KgetAdaptor(kget);
63 QDBusConnection::sessionBus().registerObject("/KGet", kget);
65 KWindowSystem::activateWindow(kget->winId());
67 if (args->isSet("showDropTarget"))
68 Settings::setShowDropTarget( true );
70 KUrl::List l;
71 for (int i = 0; i < args->count(); i++)
73 QString txt(args->arg(i));
74 if ( txt.endsWith( ".kgt", Qt::CaseInsensitive ) )
75 KGet::load( txt );
76 else
77 l.push_back(KUrl(args->arg(i)));
80 args->clear();
81 if (splash)
82 splash->removeSplash();
84 // the last arg read (when we have more than 1 arg) is considered
85 // as destination dir for the previous downloads
86 // if there is a valid local file
87 QString destUrl;
88 if (l.count() >= 2 && l.last().isLocalFile()) {
89 if (!QFileInfo(l.last().path()).isDir())
90 destUrl = l.last().directory();
91 else
92 destUrl = l.last().path();
94 l.removeLast();
95 KGet::addTransfer(l, destUrl, QString(), true);
96 return 0;
98 // all the args read from command line are downloads
99 if (l.count() == 1)
100 NewTransferDialog::showNewTransferDialog(l.takeFirst().url());
101 if (l.count() > 1 && !l.last().isLocalFile())
102 NewTransferDialog::showNewTransferDialog(l);
103 return 0;
106 private:
107 MainWindow * kget;
108 Splash * splash;
112 int main(int argc, char *argv[])
114 KAboutData aboutData("kget", 0, ki18n("KGet"), "2.0 RC 1",
115 ki18n("An advanced download manager for KDE"),
116 KAboutData::License_GPL,
117 ki18n("(C) 2005 - 2007, The KGet developers\n"
118 "(C) 2001 - 2002, Patrick Charbonnier\n"
119 "(C) 2002, Carsten Pfeiffer\n"
120 "(C) 1998 - 2000, Matej Koss"),
121 ki18n("<a href=\"mailto:kget@kde.org\">kget@kde.org</a>"));
123 aboutData.addAuthor(ki18n("Dario Massarin"), ki18n("Maintainer, Core Developer"), "nekkar@libero.it");
124 aboutData.addAuthor(ki18n("Urs Wolfer"), ki18n("Core Developer"), "uwolfer@kde.org");
125 aboutData.addAuthor(ki18n("Manolo Valdes"), ki18n("Core Developer, Multithreaded Plugin Author"), "nolis71cu@gmail.com");
126 aboutData.addAuthor(ki18n("Javier Goday"), ki18n("Developer"), "jgoday@gmail.com");
127 aboutData.addAuthor(ki18n("Patrick Charbonnier"), ki18n("Former Developer"), "pch@freeshell.org");
128 aboutData.addAuthor(ki18n("Carsten Pfeiffer"), ki18n("Former Developer"), "pfeiffer@kde.org");
129 aboutData.addAuthor(ki18n("Matej Koss"), ki18n("Former Developer"));
131 KCmdLineArgs::init(argc, argv, &aboutData);
133 KCmdLineOptions option;
134 option.add("showDropTarget", ki18n("Start KGet with drop target"));
135 option.add("hideMainWindow", ki18n("Start KGet with hidden main window"));
136 option.add("startWithoutAnimation", ki18n("Start KGet without drop target animation"));
137 option.add("+[URL(s)]", ki18n("URL(s) to download"));
138 KCmdLineArgs::addCmdLineOptions(option);
140 KGetApp::addCmdLineOptions();
142 if (!KGetApp::start())
144 fprintf(stderr, "kget is already running!\n");
145 exit(0);
148 KGetApp kApp;
150 return kApp.exec();