main.cpp 3.27 KB
Newer Older
Frank Osterfeld's avatar
Frank Osterfeld committed
1 2 3
/*
    This file is part of Akregator.

4
    SPDX-FileCopyrightText: 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>
Frank Osterfeld's avatar
Frank Osterfeld committed
5

6
    SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
Frank Osterfeld's avatar
Frank Osterfeld committed
7
*/
Stanislav Karchebny's avatar
 
Stanislav Karchebny committed
8

Frank Osterfeld's avatar
Frank Osterfeld committed
9 10 11
#include "aboutdata.h"
#include "mainwindow.h"
#include "akregator_options.h"
Laurent Montel's avatar
Laurent Montel committed
12
#include "akregator_debug.h"
Laurent Montel's avatar
Laurent Montel committed
13
#include "akregratormigrateapplication.h"
Laurent Montel's avatar
Laurent Montel committed
14 15 16
#ifdef WITH_KUSERFEEDBACK
#include "userfeedback/akregatoruserfeedbackprovider.h"
#endif
17 18
#include <KontactInterface/PimUniqueApplication>

Heiko Becker's avatar
Heiko Becker committed
19
#include <KCrash>
20 21

#include <QDBusInterface>
22

Laurent Montel's avatar
Laurent Montel committed
23
namespace Akregator {
Laurent Montel's avatar
Laurent Montel committed
24 25 26
class Application : public KontactInterface::PimUniqueApplication
{
public:
27 28
    Application(int &argc, char **argv[])
        : KontactInterface::PimUniqueApplication(argc, argv)
Laurent Montel's avatar
Laurent Montel committed
29 30
    {
    }
31

Laurent Montel's avatar
Laurent Montel committed
32
    ~Application() override
Laurent Montel's avatar
Laurent Montel committed
33 34
    {
    }
35

36
    int activate(const QStringList &args, const QString &workingDir) override;
37

Laurent Montel's avatar
Laurent Montel committed
38
private:
Laurent Montel's avatar
Laurent Montel committed
39
    Akregator::MainWindow *mMainWindow = nullptr;
40 41
};

42
int Application::activate(const QStringList &args, const QString &workingDir)
43
{
Laurent Montel's avatar
Laurent Montel committed
44
    if (!isSessionRestored()) {
45 46
        QDBusInterface akr(QStringLiteral("org.kde.akregator"), QStringLiteral("/Akregator"),
                           QStringLiteral("org.kde.akregator.part"));
Laurent Montel's avatar
Laurent Montel committed
47

48 49
        QCommandLineParser *parser = cmdArgs();
        parser->process(args);
Laurent Montel's avatar
Laurent Montel committed
50 51 52 53 54

        if (!mMainWindow) {
            mMainWindow = new Akregator::MainWindow();
            mMainWindow->loadPart();
            mMainWindow->setupProgressWidgets();
55
            if (!parser->isSet(QStringLiteral("hide-mainwindow"))) {
Laurent Montel's avatar
Laurent Montel committed
56 57
                mMainWindow->show();
            }
Laurent Montel's avatar
Laurent Montel committed
58
            akr.call(QStringLiteral("openStandardFeedList"));
Laurent Montel's avatar
Laurent Montel committed
59 60
        }

61
        akr.call(QStringLiteral("handleCommandLine"), args);
62
    }
63
    return PimUniqueApplication::activate(args, workingDir);
Laurent Montel's avatar
Laurent Montel committed
64
}
65 66
} // namespace Akregator

Stanislav Karchebny's avatar
 
Stanislav Karchebny committed
67 68
int main(int argc, char **argv)
{
69
    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
70
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
Laurent Montel's avatar
Laurent Montel committed
71
    QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
72
    Akregator::Application app(argc, &argv);
Laurent Montel's avatar
Laurent Montel committed
73 74
    KLocalizedString::setApplicationDomain("akregator");

Heiko Becker's avatar
Heiko Becker committed
75 76
    KCrash::initialize();

Laurent Montel's avatar
Laurent Montel committed
77
    app.setDesktopFileName(QStringLiteral("org.kde.akregator"));
78
    Akregator::AboutData about;
79
    app.setAboutData(about);
80

81 82
    QCommandLineParser *cmdArgs = app.cmdArgs();
    Akregator::akregator_options(cmdArgs);
83

84 85 86
    const QStringList args = QCoreApplication::arguments();
    cmdArgs->process(args);
    about.processCommandLine(cmdArgs);
87

Laurent Montel's avatar
Laurent Montel committed
88
#ifdef WITH_KUSERFEEDBACK
Laurent Montel's avatar
Laurent Montel committed
89
    if (cmdArgs->isSet(QStringLiteral("feedback"))) {
Laurent Montel's avatar
Laurent Montel committed
90
        auto *userFeedBack = new Akregator::AkregatorUserFeedbackProvider(nullptr);
Laurent Montel's avatar
Laurent Montel committed
91 92
        QTextStream(stdout) << userFeedBack->describeDataSources() << '\n';
        delete userFeedBack;
Laurent Montel's avatar
Laurent Montel committed
93 94 95
        return 0;
    }
#endif
96
    if (!Akregator::Application::start(args)) {
Laurent Montel's avatar
Laurent Montel committed
97
        qCWarning(AKREGATOR_LOG) << "akregator is already running, exiting.";
Laurent Montel's avatar
Laurent Montel committed
98
        exit(0);
Frank Osterfeld's avatar
Frank Osterfeld committed
99
    }
Laurent Montel's avatar
Laurent Montel committed
100 101
    AkregratorMigrateApplication migrate;
    migrate.migrate();
Frank Osterfeld's avatar
Frank Osterfeld committed
102

Heinrich Wendel's avatar
Heinrich Wendel committed
103
    // see if we are starting with session management
Laurent Montel's avatar
Laurent Montel committed
104
    if (app.isSessionRestored()) {
105 106 107 108 109
        auto mainWindow = new Akregator::MainWindow();
        mainWindow->loadPart();
        if (KMainWindow::canBeRestored(1)) {
            mainWindow->restore(1, false);
        }
Heinrich Wendel's avatar
Heinrich Wendel committed
110
    }
Stanislav Karchebny's avatar
 
Stanislav Karchebny committed
111

Heinrich Wendel's avatar
Heinrich Wendel committed
112
    return app.exec();
Stanislav Karchebny's avatar
 
Stanislav Karchebny committed
113
}