File: main.cpp

package info (click to toggle)
kget 4%3A18.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 18,632 kB
  • sloc: cpp: 36,172; xml: 591; python: 290; perl: 41; sh: 11; makefile: 10
file content (184 lines) | stat: -rw-r--r-- 7,417 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* This file is part of the KDE project

   Copyright (C) 2002 by Patrick Charbonnier <pch@freeshell.org>
   Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
*/

#include <Kdelibs4ConfigMigrator>
#include <Kdelibs4Migration>
#include <kstartupinfo.h>
#include <kwindowsystem.h>
#include <klocale.h>
#include <kaboutdata.h>
#include <kdbusservice.h>
#include <kstandarddirs.h>
#include <QCommandLineParser>
#include <QCommandLineOption>

#include "core/kget.h"
#include "dbus/dbuskgetwrapper.h"
#include "mainadaptor.h"
#include "settings.h"
#include "mainwindow.h"
#include "ui/newtransferdialog.h"
#include "kget_version.h"

class KGetApp : public QObject
{
public:
    KGetApp(QCommandLineParser *p)
        : kget( nullptr ), parser( p )
    {
    }

    ~KGetApp()
    {
        delete kget;
    }

    int newInstance()
    {
        if (!kget)
        {
#ifdef DEBUG
            kget = new MainWindow(!parser->isSet("showDropTarget"), parser->isSet("startWithoutAnimation"), parser->isSet("test"));
#else
            kget = new MainWindow(!parser->isSet("showDropTarget"), parser->isSet("startWithoutAnimation"), false);
#endif

            DBusKGetWrapper *wrapper = new DBusKGetWrapper(kget);
            new MainAdaptor(wrapper);
            QDBusConnection::sessionBus().registerObject("/KGet", wrapper);
        } else {
            // activate window if it is already open
            KStartupInfo::setNewStartupId(kget, KStartupInfo::startupId());
            KWindowSystem::forceActiveWindow(kget->winId());
        }

        if (parser->isSet("showDropTarget"))
            Settings::setShowDropTarget( true );

        QList<QUrl> l;
        const QStringList args = parser->positionalArguments();
        for (int i = 0; i < args.count(); i++)
        {
            QString txt(args.at(i));
            if ( txt.endsWith( QLatin1String(".kgt"), Qt::CaseInsensitive ) )
                KGet::load( txt );
            else
                l.push_back(QUrl::fromUserInput(args.at(i)));
        }

        if (!l.isEmpty())
            NewTransferDialogHandler::showNewTransferDialog(l);

        return 0;
    }

public slots:
    void slotActivateRequested (QStringList args, const QString & /*workingDir*/)
    {
        parser->parse(args);
        newInstance();
    }

private:
    MainWindow * kget;
    QCommandLineParser *parser;
};


int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
    KLocalizedString::setApplicationDomain("kget");
    KAboutData aboutData(QStringLiteral("kget"), i18n("KGet"),
                         QStringLiteral(KGET_VERSION_STRING),
                         i18n("An advanced download manager by KDE"),
                         KAboutLicense::GPL,
                         i18n("(C) 2005 - 2014, The KGet developers\n"
                         "(C) 2001 - 2002, Patrick Charbonnier\n"
                         "(C) 2002, Carsten Pfeiffer\n"
                         "(C) 1998 - 2000, Matej Koss"),
                         i18n("<a href=\"mailto:kget@kde.org\">kget@kde.org</a>"));

    aboutData.addAuthor(i18n("Lukas Appelhans"), i18n("Maintainer, Core Developer, Torrent Plugin Author"), "l.appelhans@gmx.de");
    aboutData.addAuthor(i18n("Dario Massarin"), i18n("Core Developer"), "nekkar@libero.it");
    aboutData.addAuthor(i18n("Urs Wolfer"), i18n("Core Developer"), "uwolfer@kde.org");
    aboutData.addAuthor(i18n("Manolo Valdes"), i18n("Core Developer, Multithreaded Plugin Author"), "nolis71cu@gmail.com");
    aboutData.addAuthor(i18n("Matthias Fuchs"), i18n("Core Developer"), "mat69@gmx.net");
    aboutData.addAuthor(i18n("Javier Goday"), i18n("Developer"), "jgoday@gmail.com");
    aboutData.addAuthor(i18n("Aish Raj Dahal"), i18n("Google Summer of Code Student"));
    aboutData.addAuthor(i18n("Ernesto Rodriguez Ortiz"), i18n("Mms Plugin Author"), "eortiz@uci.cu");
    aboutData.addAuthor(i18n("Patrick Charbonnier"), i18n("Former Developer"), "pch@freeshell.org");
    aboutData.addAuthor(i18n("Carsten Pfeiffer"), i18n("Former Developer"), "pfeiffer@kde.org");
    aboutData.addAuthor(i18n("Matej Koss"), i18n("Former Developer"));
    aboutData.addCredit(i18n("Joris Guisson"), i18n("BTCore (KTorrent) Developer"), "joris.guisson@gmail.com");
    aboutData.addCredit(i18n("Mensur Zahirovic (Nookie)"), i18n("Design of Web Interface"), "linuxsajten@gmail.com");
    // necessary to make the "Translators" tab appear in the About dialog
    aboutData.setTranslator( i18nc( "NAME OF TRANSLATORS", "Your names" ), i18nc( "EMAIL OF TRANSLATORS", "Your emails" ) );
    KAboutData::setApplicationData(aboutData);

    QCommandLineParser parser;
    aboutData.setupCommandLine(&parser);

    parser.addOption(QCommandLineOption(QStringList() << QLatin1String("showDropTarget"), i18n("Start KGet with drop target")));
    parser.addOption(QCommandLineOption(QStringList() << QLatin1String("hideMainWindow"), i18n("Start KGet with hidden main window")));
    parser.addOption(QCommandLineOption(QStringList() << QLatin1String("startWithoutAnimation"), i18n("Start KGet without drop target animation")));
#ifdef DEBUG
    parser.addOption(QCommandLineOption(QStringList() << QLatin1String("test"), i18n("Execute Unit Testing")));
#endif
    parser.addPositionalArgument(QLatin1String("[URL(s)]"), i18n("URL(s) to download"));

    parser.process(app);
    aboutData.processCommandLine(&parser);

    KDBusService dbusService(KDBusService::Unique);

    Kdelibs4ConfigMigrator migrate(QStringLiteral("kget"));
    migrate.setConfigFiles(QStringList() << QStringLiteral("kgetrc")
        << QStringLiteral("kget_bittorrentfactory.rc")
        << QStringLiteral("kget_checksumsearchfactory.rc")
        << QStringLiteral("kget_metalinkfactory.rc")
        << QStringLiteral("kget_mirrorsearchfactory.rc")
        << QStringLiteral("kget_mmsfactory.rc")
        << QStringLiteral("kget_multisegkiofactory.rc")
        << QStringLiteral("kget.notifyrc"));
    if (migrate.migrate()) {
        Kdelibs4Migration dataMigrator;
        const QString sourceBasePath = dataMigrator.saveLocation("data", QStringLiteral("kget"));
        const QString targetBasePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kget/");
        QString targetFilePath;

        QDir sourceDir(sourceBasePath);
        QDir targetDir(targetBasePath);

        if (sourceDir.exists()) {
            if (!targetDir.exists()) {
                QDir().mkpath(targetBasePath);
            }
            QStringList fileNames = sourceDir.entryList(
                QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
            foreach (const QString &fileName, fileNames) {
                targetFilePath = targetBasePath + fileName;
                if (!QFile::exists(targetFilePath)) {
                    QFile::copy(sourceBasePath + fileName, targetFilePath);
                }
            }
        }
    }

    KGetApp kApp(&parser);

    QObject::connect(&dbusService, &KDBusService::activateRequested, &kApp, &KGetApp::slotActivateRequested);

    kApp.newInstance();

    return app.exec();
}