small fixes and updates
[kdenetwork.git] / kget / main.cpp
blobc88bbe2ec2cf6c9e8a34c32f019e6f0d35409fa8
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.
12 #include <kwindowsystem.h>
13 #include <klocale.h>
14 #include <kaboutdata.h>
15 #include <kcmdlineargs.h>
16 #include <kuniqueapplication.h>
17 #include <kstandarddirs.h>
19 #include "core/kget.h"
20 #include "kgetadaptor.h"
21 #include "settings.h"
22 #include "ui/splash.h"
23 #include "mainwindow.h"
24 #include "ui/newtransferdialog.h"
26 class KGetApp : public KUniqueApplication
28 public:
29 KGetApp()
30 : KUniqueApplication(), kget( 0 ), splash( 0 )
32 showSplash();
35 ~KGetApp()
37 delete splash;
38 delete kget;
41 void showSplash()
43 //determine whether splash-screen is enabled in kgetrc
44 if ( !Settings::showSplashscreen() )
45 return;
47 // getting splash-screen path
48 QString path = KStandardDirs::locate( "data", "kget/pics/kget_splash.png" );
50 if ( !path.isEmpty() )
51 splash = new Splash( path );
54 int newInstance()
56 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
58 if (!kget)
60 kget = new MainWindow(!args->isSet("showDropTarget"), args->isSet("startWithoutAnimation"));
61 new KgetAdaptor(kget);
62 QDBusConnection::sessionBus().registerObject("/KGet", kget);
64 KWindowSystem::activateWindow(kget->winId());
66 if (args->isSet("showDropTarget"))
67 Settings::setShowDropTarget( true );
69 KUrl::List l;
70 for (int i = 0; i < args->count(); i++)
72 QString txt(args->arg(i));
73 if ( txt.endsWith( ".kgt", Qt::CaseInsensitive ) )
74 KGet::load( txt );
75 else
76 l.push_back(KUrl(args->arg(i)));
79 args->clear();
80 if (splash)
81 splash->removeSplash();
83 // the last arg read (when we have more than 1 arg) is considered
84 // as destination dir for the previous downloads
85 // if there is a valid local file
86 QString destUrl;
87 if (l.count() >= 2 && l.last().isLocalFile()) {
88 if (!QFileInfo(l.last().path()).isDir())
89 destUrl = l.last().directory();
90 else
91 destUrl = l.last().path();
93 l.removeLast();
94 KGet::addTransfer(l, destUrl, QString(), true);
95 return 0;
97 // all the args read from command line are downloads
98 if (l.count() == 1)
99 NewTransferDialog::showNewTransferDialog(l.takeFirst().url());
100 if (l.count() > 1 && !l.last().isLocalFile())
101 NewTransferDialog::showNewTransferDialog(l);
102 return 0;
105 private:
106 MainWindow * kget;
107 Splash * splash;
111 int main(int argc, char *argv[])
113 KAboutData aboutData("kget", 0, ki18n("KGet"), "2.0.80",
114 ki18n("An advanced download manager for KDE"),
115 KAboutData::License_GPL,
116 ki18n("(C) 2005 - 2008, The KGet developers\n"
117 "(C) 2001 - 2002, Patrick Charbonnier\n"
118 "(C) 2002, Carsten Pfeiffer\n"
119 "(C) 1998 - 2000, Matej Koss"),
120 ki18n("<a href=\"mailto:kget@kde.org\">kget@kde.org</a>"));
122 aboutData.addAuthor(ki18n("Dario Massarin"), ki18n("Maintainer, Core Developer"), "nekkar@libero.it");
123 aboutData.addAuthor(ki18n("Urs Wolfer"), ki18n("Core Developer"), "uwolfer@kde.org");
124 aboutData.addAuthor(ki18n("Manolo Valdes"), ki18n("Core Developer, Multithreaded Plugin Author"), "nolis71cu@gmail.com");
125 aboutData.addAuthor(ki18n("Javier Goday"), ki18n("Developer"), "jgoday@gmail.com");
126 aboutData.addAuthor(ki18n("Lukas Appelhans"), ki18n("Developer"), "l.appelhans@gmx.de");
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();