1 | /* This file is part of the KDE project |
2 | |
3 | Copyright (C) 2002 by Patrick Charbonnier <pch@freeshell.org> |
4 | Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss |
5 | |
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. |
10 | */ |
11 | |
12 | #include <kwindowsystem.h> |
13 | #include <klocale.h> |
14 | #include <kaboutdata.h> |
15 | #include <kcmdlineargs.h> |
16 | #include <kuniqueapplication.h> |
17 | #include <kstandarddirs.h> |
18 | |
19 | #include "core/kget.h" |
20 | #include "dbus/dbuskgetwrapper.h" |
21 | #include "mainadaptor.h" |
22 | #include "settings.h" |
23 | #include "mainwindow.h" |
24 | #include "ui/newtransferdialog.h" |
25 | |
26 | #if defined Q_WS_X11 |
27 | #include <kstartupinfo.h> |
28 | #endif |
29 | |
30 | class KGetApp : public KUniqueApplication |
31 | { |
32 | public: |
33 | KGetApp() |
34 | : KUniqueApplication(), kget( 0 ) |
35 | { |
36 | } |
37 | |
38 | ~KGetApp() |
39 | { |
40 | delete kget; |
41 | } |
42 | |
43 | int newInstance() |
44 | { |
45 | KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); |
46 | |
47 | if (!kget) |
48 | { |
49 | #ifdef DEBUG |
50 | kget = new MainWindow(!args->isSet("showDropTarget" ), args->isSet("startWithoutAnimation" ), args->isSet("test" )); |
51 | #else |
52 | kget = new MainWindow(!args->isSet("showDropTarget" ), args->isSet("startWithoutAnimation" ), false); |
53 | #endif |
54 | |
55 | DBusKGetWrapper *wrapper = new DBusKGetWrapper(kget); |
56 | new MainAdaptor(wrapper); |
57 | QDBusConnection::sessionBus().registerObject("/KGet" , wrapper); |
58 | } else { |
59 | |
60 | //BEGIN taken from "kuniqueapplication.cpp" |
61 | #ifdef Q_WS_X11 |
62 | // This is the line that handles window activation if necessary, |
63 | // and what's important, it does it properly. If you reimplement newInstance(), |
64 | // and don't call the inherited one, use this (but NOT when newInstance() |
65 | // is called for the first time, like here). |
66 | KStartupInfo::setNewStartupId(kget, startupId()); |
67 | #endif |
68 | #ifdef Q_WS_WIN |
69 | KWindowSystem::forceActiveWindow(kget->winId()); |
70 | #endif |
71 | //END |
72 | |
73 | } |
74 | |
75 | if (args->isSet("showDropTarget" )) |
76 | Settings::setShowDropTarget( true ); |
77 | |
78 | KUrl::List l; |
79 | for (int i = 0; i < args->count(); i++) |
80 | { |
81 | QString txt(args->arg(i)); |
82 | if ( txt.endsWith( QLatin1String(".kgt" ), Qt::CaseInsensitive ) ) |
83 | KGet::load( txt ); |
84 | else |
85 | l.push_back(KUrl(args->arg(i))); |
86 | } |
87 | |
88 | args->clear(); |
89 | |
90 | if (!l.isEmpty()) |
91 | NewTransferDialogHandler::showNewTransferDialog(l); |
92 | |
93 | return 0; |
94 | } |
95 | |
96 | private: |
97 | MainWindow * kget; |
98 | }; |
99 | |
100 | |
101 | int main(int argc, char *argv[]) |
102 | { |
103 | KAboutData aboutData("kget" , 0, ki18n("KGet" ), |
104 | QByteArray("2." + QByteArray::number(KDE_VERSION_MINOR) + '.' + QByteArray::number(KDE_VERSION_RELEASE)), |
105 | ki18n("An advanced download manager for KDE" ), |
106 | KAboutData::License_GPL, |
107 | ki18n("(C) 2005 - 2012, The KGet developers\n" |
108 | "(C) 2001 - 2002, Patrick Charbonnier\n" |
109 | "(C) 2002, Carsten Pfeiffer\n" |
110 | "(C) 1998 - 2000, Matej Koss" ), |
111 | ki18n("<a href=\"mailto:kget@kde.org\">kget@kde.org</a>" )); |
112 | |
113 | aboutData.addAuthor(ki18n("Lukas Appelhans" ), ki18n("Maintainer, Core Developer, Torrent Plugin Author" ), "l.appelhans@gmx.de" ); |
114 | aboutData.addAuthor(ki18n("Dario Massarin" ), ki18n("Core Developer" ), "nekkar@libero.it" ); |
115 | aboutData.addAuthor(ki18n("Urs Wolfer" ), ki18n("Core Developer" ), "uwolfer@kde.org" ); |
116 | aboutData.addAuthor(ki18n("Manolo Valdes" ), ki18n("Core Developer, Multithreaded Plugin Author" ), "nolis71cu@gmail.com" ); |
117 | aboutData.addAuthor(ki18n("Matthias Fuchs" ), ki18n("Core Developer" ), "mat69@gmx.net" ); |
118 | aboutData.addAuthor(ki18n("Javier Goday" ), ki18n("Developer" ), "jgoday@gmail.com" ); |
119 | aboutData.addAuthor(ki18n("Aish Raj Dahal" ), ki18n("Google Summer of Code Student" )); |
120 | aboutData.addAuthor(ki18n("Ernesto Rodriguez Ortiz" ), ki18n("Mms Plugin Author" ), "eortiz@uci.cu" ); |
121 | aboutData.addAuthor(ki18n("Patrick Charbonnier" ), ki18n("Former Developer" ), "pch@freeshell.org" ); |
122 | aboutData.addAuthor(ki18n("Carsten Pfeiffer" ), ki18n("Former Developer" ), "pfeiffer@kde.org" ); |
123 | aboutData.addAuthor(ki18n("Matej Koss" ), ki18n("Former Developer" )); |
124 | aboutData.addCredit(ki18n("Joris Guisson" ), ki18n("BTCore (KTorrent) Developer" ), "joris.guisson@gmail.com" ); |
125 | aboutData.addCredit(ki18n("Mensur Zahirovic (Nookie)" ), ki18n("Design of Web Interface" ), "linuxsajten@gmail.com" ); |
126 | |
127 | KCmdLineArgs::init(argc, argv, &aboutData); |
128 | |
129 | KCmdLineOptions option; |
130 | option.add("showDropTarget" , ki18n("Start KGet with drop target" )); |
131 | option.add("hideMainWindow" , ki18n("Start KGet with hidden main window" )); |
132 | option.add("startWithoutAnimation" , ki18n("Start KGet without drop target animation" )); |
133 | #ifdef DEBUG |
134 | option.add("test" , ki18n("Execute Unit Testing" )); |
135 | #endif |
136 | option.add("+[URL(s)]" , ki18n("URL(s) to download" )); |
137 | KCmdLineArgs::addCmdLineOptions(option); |
138 | |
139 | KGetApp::addCmdLineOptions(); |
140 | |
141 | if (!KGetApp::start()) |
142 | { |
143 | fprintf(stderr, "kget is already running!\n" ); |
144 | exit(0); |
145 | } |
146 | |
147 | KGetApp kApp; |
148 | |
149 | return kApp.exec(); |
150 | } |
151 | |