File indexing completed on 2024-04-14 04:52:19

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2002 by Patrick Charbonnier <pch@freeshell.org>
0004    Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 */
0011 
0012 #include <KAboutData>
0013 #include <KDBusService>
0014 #include <KLocalizedString>
0015 #include <KWindowSystem>
0016 
0017 #include <QCommandLineOption>
0018 #include <QCommandLineParser>
0019 #include <QStandardPaths>
0020 
0021 #include "core/kget.h"
0022 #include "dbus/dbuskgetwrapper.h"
0023 #include "kget_version.h"
0024 #include "mainadaptor.h"
0025 #include "mainwindow.h"
0026 #include "settings.h"
0027 #include "ui/newtransferdialog.h"
0028 
0029 class KGetApp : public QObject
0030 {
0031 public:
0032     KGetApp(QCommandLineParser *p)
0033         : kget(nullptr)
0034         , parser(p)
0035     {
0036     }
0037 
0038     ~KGetApp() override
0039     {
0040         delete kget;
0041     }
0042 
0043     int newInstance()
0044     {
0045         if (!kget) {
0046 #ifdef DEBUG
0047             kget = new MainWindow(!parser->isSet("showDropTarget"), parser->isSet("startWithoutAnimation"), parser->isSet("test"));
0048 #else
0049             kget = new MainWindow(!parser->isSet("showDropTarget"), parser->isSet("startWithoutAnimation"), false);
0050 #endif
0051 
0052             auto *wrapper = new DBusKGetWrapper(kget);
0053             new MainAdaptor(wrapper);
0054             QDBusConnection::sessionBus().registerObject("/KGet", wrapper);
0055         } else {
0056             // activate window if it is already open
0057             kget->setAttribute(Qt::WA_NativeWindow, true);
0058             KWindowSystem::updateStartupId(kget->windowHandle());
0059             KWindowSystem::activateWindow(kget->windowHandle());
0060         }
0061 
0062         if (parser->isSet("showDropTarget"))
0063             Settings::setShowDropTarget(true);
0064 
0065         QList<QUrl> l;
0066         const QStringList args = parser->positionalArguments();
0067         for (int i = 0; i < args.count(); i++) {
0068             QString txt(args.at(i));
0069             if (txt.endsWith(QLatin1String(".kgt"), Qt::CaseInsensitive))
0070                 KGet::load(txt);
0071             else
0072                 l.push_back(QUrl::fromUserInput(args.at(i)));
0073         }
0074 
0075         if (!l.isEmpty())
0076             NewTransferDialogHandler::showNewTransferDialog(l);
0077 
0078         return 0;
0079     }
0080 
0081 public Q_SLOTS:
0082     void slotActivateRequested(QStringList args, const QString & /*workingDir*/)
0083     {
0084         parser->parse(args);
0085         newInstance();
0086     }
0087 
0088 private:
0089     MainWindow *kget;
0090     QCommandLineParser *parser;
0091 };
0092 
0093 int main(int argc, char *argv[])
0094 {
0095     QApplication app(argc, argv);
0096     QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0097     KLocalizedString::setApplicationDomain("kget");
0098     KAboutData aboutData(QStringLiteral("kget"),
0099                          i18n("KGet"),
0100                          QStringLiteral(KGET_VERSION_STRING),
0101                          i18n("An advanced download manager by KDE"),
0102                          KAboutLicense::GPL,
0103                          i18n("(C) 2005 - 2014, The KGet developers\n"
0104                               "(C) 2001 - 2002, Patrick Charbonnier\n"
0105                               "(C) 2002, Carsten Pfeiffer\n"
0106                               "(C) 1998 - 2000, Matej Koss"),
0107                          i18n("<a href=\"mailto:kget@kde.org\">kget@kde.org</a>"));
0108 
0109     aboutData.addAuthor(i18n("Lukas Appelhans"), i18n("Maintainer, Core Developer, Torrent Plugin Author"), "l.appelhans@gmx.de");
0110     aboutData.addAuthor(i18n("Dario Massarin"), i18n("Core Developer"), "nekkar@libero.it");
0111     aboutData.addAuthor(i18n("Urs Wolfer"), i18n("Core Developer"), "uwolfer@kde.org");
0112     aboutData.addAuthor(i18n("Manolo Valdes"), i18n("Core Developer, Multithreaded Plugin Author"), "nolis71cu@gmail.com");
0113     aboutData.addAuthor(i18n("Matthias Fuchs"), i18n("Core Developer"), "mat69@gmx.net");
0114     aboutData.addAuthor(i18n("Javier Goday"), i18n("Developer"), "jgoday@gmail.com");
0115     aboutData.addAuthor(i18n("Aish Raj Dahal"), i18n("Google Summer of Code Student"));
0116     aboutData.addAuthor(i18n("Ernesto Rodriguez Ortiz"), i18n("Mms Plugin Author"), "eortiz@uci.cu");
0117     aboutData.addAuthor(i18n("Patrick Charbonnier"), i18n("Former Developer"), "pch@freeshell.org");
0118     aboutData.addAuthor(i18n("Carsten Pfeiffer"), i18n("Former Developer"), "pfeiffer@kde.org");
0119     aboutData.addAuthor(i18n("Matej Koss"), i18n("Former Developer"));
0120     aboutData.addCredit(i18n("Joris Guisson"), i18n("BTCore (KTorrent) Developer"), "joris.guisson@gmail.com");
0121     aboutData.addCredit(i18n("Mensur Zahirovic (Nookie)"), i18n("Design of Web Interface"), "linuxsajten@gmail.com");
0122     // necessary to make the "Translators" tab appear in the About dialog
0123     aboutData.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
0124     KAboutData::setApplicationData(aboutData);
0125     QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("kget")));
0126 
0127     QCommandLineParser parser;
0128     aboutData.setupCommandLine(&parser);
0129 
0130     parser.addOption(QCommandLineOption(QStringList() << QLatin1String("showDropTarget"), i18n("Start KGet with drop target")));
0131     parser.addOption(QCommandLineOption(QStringList() << QLatin1String("hideMainWindow"), i18n("Start KGet with hidden main window")));
0132     parser.addOption(QCommandLineOption(QStringList() << QLatin1String("startWithoutAnimation"), i18n("Start KGet without drop target animation")));
0133 #ifdef DEBUG
0134     parser.addOption(QCommandLineOption(QStringList() << QLatin1String("test"), i18n("Execute Unit Testing")));
0135 #endif
0136     parser.addPositionalArgument(QLatin1String("[URL(s)]"), i18n("URL(s) to download"));
0137 
0138     parser.process(app);
0139     aboutData.processCommandLine(&parser);
0140 
0141     KDBusService dbusService(KDBusService::Unique);
0142 
0143     KGetApp kApp(&parser);
0144 
0145     QObject::connect(&dbusService, &KDBusService::activateRequested, &kApp, &KGetApp::slotActivateRequested);
0146 
0147     kApp.newInstance();
0148 
0149     return app.exec();
0150 }