Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 2a901f79 authored by Wolfgang Bauer's avatar Wolfgang Bauer

Port to QApplication

Ports KApplication to QApplication, K4AboutData to KAboutData, and
KCmdLineArgs to QCommandLineParser.
Also uses KDBusService instead of KUniqueApplication to prevent more
than one instance running, and sets the translation domain via
KLocalizedString::setApplicationDomain().

Differential Revision: https://phabricator.kde.org/D8724
parent 739c0b39
......@@ -12,10 +12,10 @@
#include <kwindowsystem.h>
#include <klocale.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <kuniqueapplication.h>
#include <kdbusservice.h>
#include <kstandarddirs.h>
#include <k4aboutdata.h>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include "core/kget.h"
#include "dbus/dbuskgetwrapper.h"
......@@ -28,11 +28,11 @@
#include <kstartupinfo.h>
#endif
class KGetApp : public KUniqueApplication
class KGetApp : public QObject
{
public:
KGetApp()
: KUniqueApplication(), kget( 0 )
KGetApp(QCommandLineParser *p)
: kget( 0 ), parser( p )
{
}
......@@ -43,21 +43,19 @@ public:
int newInstance()
{
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
if (!kget)
{
#ifdef DEBUG
kget = new MainWindow(!args->isSet("showDropTarget"), args->isSet("startWithoutAnimation"), args->isSet("test"));
kget = new MainWindow(!parser->isSet("showDropTarget"), parser->isSet("startWithoutAnimation"), parser->isSet("test"));
#else
kget = new MainWindow(!args->isSet("showDropTarget"), args->isSet("startWithoutAnimation"), false);
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 {
//BEGIN taken from "kuniqueapplication.cpp"
#ifdef Q_WS_X11
// This is the line that handles window activation if necessary,
......@@ -73,79 +71,91 @@ public:
}
if (args->isSet("showDropTarget"))
if (parser->isSet("showDropTarget"))
Settings::setShowDropTarget( true );
KUrl::List l;
for (int i = 0; i < args->count(); i++)
QList<QUrl> l;
const QStringList args = parser->positionalArguments();
for (int i = 0; i < args.count(); i++)
{
QString txt(args->arg(i));
QString txt(args.at(i));
if ( txt.endsWith( QLatin1String(".kgt"), Qt::CaseInsensitive ) )
KGet::load( txt );
else
l.push_back(KUrl(args->arg(i)));
l.push_back(QUrl::fromUserInput(args.at(i)));
}
args->clear();
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[])
{
K4AboutData aboutData("kget", 0, ki18n("KGet"),
QByteArray("2.95.0"),//+ QByteArray::number(KDE_VERSION_MINOR) + '.' + QByteArray::number(KDE_VERSION_RELEASE)),
ki18n("An advanced download manager by KDE"),
K4AboutData::License_GPL,
ki18n("(C) 2005 - 2014, The KGet developers\n"
QApplication app(argc, argv);
KLocalizedString::setApplicationDomain("kget");
KAboutData aboutData(QStringLiteral("kget"), i18n("KGet"),
QStringLiteral("2.95.0"),//+ QByteArray::number(KDE_VERSION_MINOR) + '.' + QByteArray::number(KDE_VERSION_RELEASE)),
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"),
ki18n("<a href=\"mailto:kget@kde.org\">kget@kde.org</a>"));
aboutData.addAuthor(ki18n("Lukas Appelhans"), ki18n("Maintainer, Core Developer, Torrent Plugin Author"), "l.appelhans@gmx.de");
aboutData.addAuthor(ki18n("Dario Massarin"), ki18n("Core Developer"), "nekkar@libero.it");
aboutData.addAuthor(ki18n("Urs Wolfer"), ki18n("Core Developer"), "uwolfer@kde.org");
aboutData.addAuthor(ki18n("Manolo Valdes"), ki18n("Core Developer, Multithreaded Plugin Author"), "nolis71cu@gmail.com");
aboutData.addAuthor(ki18n("Matthias Fuchs"), ki18n("Core Developer"), "mat69@gmx.net");
aboutData.addAuthor(ki18n("Javier Goday"), ki18n("Developer"), "jgoday@gmail.com");
aboutData.addAuthor(ki18n("Aish Raj Dahal"), ki18n("Google Summer of Code Student"));
aboutData.addAuthor(ki18n("Ernesto Rodriguez Ortiz"), ki18n("Mms Plugin Author"), "eortiz@uci.cu");
aboutData.addAuthor(ki18n("Patrick Charbonnier"), ki18n("Former Developer"), "pch@freeshell.org");
aboutData.addAuthor(ki18n("Carsten Pfeiffer"), ki18n("Former Developer"), "pfeiffer@kde.org");
aboutData.addAuthor(ki18n("Matej Koss"), ki18n("Former Developer"));
aboutData.addCredit(ki18n("Joris Guisson"), ki18n("BTCore (KTorrent) Developer"), "joris.guisson@gmail.com");
aboutData.addCredit(ki18n("Mensur Zahirovic (Nookie)"), ki18n("Design of Web Interface"), "linuxsajten@gmail.com");
KCmdLineArgs::init(argc, argv, &aboutData);
KCmdLineOptions option;
option.add("showDropTarget", ki18n("Start KGet with drop target"));
option.add("hideMainWindow", ki18n("Start KGet with hidden main window"));
option.add("startWithoutAnimation", ki18n("Start KGet without drop target animation"));
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
option.add("test", ki18n("Execute Unit Testing"));
parser.addOption(QCommandLineOption(QStringList() << QLatin1String("test"), i18n("Execute Unit Testing")));
#endif
option.add("+[URL(s)]", ki18n("URL(s) to download"));
KCmdLineArgs::addCmdLineOptions(option);
parser.addPositionalArgument(QLatin1String("[URL(s)]"), i18n("URL(s) to download"));
KGetApp::addCmdLineOptions();
parser.process(app);
aboutData.processCommandLine(&parser);
if (!KGetApp::start())
{
fprintf(stderr, "kget is already running!\n");
exit(0);
}
KDBusService dbusService(KDBusService::Unique);
KGetApp kApp(&parser);
QObject::connect(&dbusService, &KDBusService::activateRequested, &kApp, &KGetApp::slotActivateRequested);
KGetApp kApp;
kApp.newInstance();
return kApp.exec();
return app.exec();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment