main.cpp 3.98 KB
Newer Older
Frank Osterfeld's avatar
Frank Osterfeld committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
    This file is part of Akregator.

    Copyright (C) 2004 Stanislav Karchebny <Stanislav.Karchebny@kdemail.net>

    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.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
18
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Frank Osterfeld's avatar
Frank Osterfeld committed
19 20 21 22 23

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/
Stanislav Karchebny's avatar
 
Stanislav Karchebny committed
24

Frank Osterfeld's avatar
Frank Osterfeld committed
25 26 27
#include "aboutdata.h"
#include "mainwindow.h"
#include "akregator_options.h"
Laurent Montel's avatar
Laurent Montel committed
28
#include "utils.h"
Laurent Montel's avatar
Laurent Montel committed
29
#include "akregator_debug.h"
Laurent Montel's avatar
Laurent Montel committed
30
#include "akregratormigrateapplication.h"
Heiko Becker's avatar
Heiko Becker committed
31
#include <KCrash>
Laurent Montel's avatar
Laurent Montel committed
32
#include <KLocalizedString>
Laurent Montel's avatar
Laurent Montel committed
33
#include <kontactinterface/pimuniqueapplication.h>
Laurent Montel's avatar
Laurent Montel committed
34
#include <QtDBus>
35

Laurent Montel's avatar
Laurent Montel committed
36
namespace Akregator {
Laurent Montel's avatar
Laurent Montel committed
37 38 39
class Application : public KontactInterface::PimUniqueApplication
{
public:
40 41
    Application(int &argc, char **argv[])
        : KontactInterface::PimUniqueApplication(argc, argv)
42
        , mMainWindow(0)
Laurent Montel's avatar
Laurent Montel committed
43 44
    {
    }
45

Laurent Montel's avatar
Laurent Montel committed
46 47 48
    ~Application()
    {
    }
49

50
    int activate(const QStringList &args, const QString &workingDir) override;
51

Laurent Montel's avatar
Laurent Montel committed
52
private:
53 54 55
    Akregator::MainWindow *mMainWindow;
};

56
int Application::activate(const QStringList &args, const QString &workingDir)
57
{
Laurent Montel's avatar
Laurent Montel committed
58
    if (!isSessionRestored()) {
Laurent Montel's avatar
Laurent Montel committed
59
        QDBusInterface akr(QStringLiteral("org.kde.akregator"), QStringLiteral("/Akregator"), QStringLiteral("org.kde.akregator.part"));
Laurent Montel's avatar
Laurent Montel committed
60

61 62
        QCommandLineParser *parser = cmdArgs();
        parser->process(args);
Laurent Montel's avatar
Laurent Montel committed
63 64 65 66 67

        if (!mMainWindow) {
            mMainWindow = new Akregator::MainWindow();
            mMainWindow->loadPart();
            mMainWindow->setupProgressWidgets();
68
            if (!parser->isSet(QStringLiteral("hide-mainwindow"))) {
Laurent Montel's avatar
Laurent Montel committed
69 70
                mMainWindow->show();
            }
Laurent Montel's avatar
Laurent Montel committed
71
            akr.call(QStringLiteral("openStandardFeedList"));
Laurent Montel's avatar
Laurent Montel committed
72 73
        }

74
        akr.call(QStringLiteral("handleCommandLine"), args);
75
    }
76
    return PimUniqueApplication::activate(args, workingDir);
Laurent Montel's avatar
Laurent Montel committed
77
}
78 79
} // namespace Akregator

Stanislav Karchebny's avatar
 
Stanislav Karchebny committed
80 81
int main(int argc, char **argv)
{
Laurent Montel's avatar
Laurent Montel committed
82 83 84 85
    //Fix QtWebEngine + wayland
#ifdef Q_OS_UNIX
    qputenv("QT_QPA_PLATFORM", "xcb");
#endif
86
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
87
    Akregator::Application app(argc, &argv);
Laurent Montel's avatar
Laurent Montel committed
88 89
    KLocalizedString::setApplicationDomain("akregator");

Heiko Becker's avatar
Heiko Becker committed
90 91
    KCrash::initialize();

92
    app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
Laurent Montel's avatar
Laurent Montel committed
93
    app.setDesktopFileName(QStringLiteral("org.kde.akregator"));
94
    Akregator::AboutData about;
95
    app.setAboutData(about);
96

97 98
    QCommandLineParser *cmdArgs = app.cmdArgs();
    Akregator::akregator_options(cmdArgs);
99

100 101 102
    const QStringList args = QCoreApplication::arguments();
    cmdArgs->process(args);
    about.processCommandLine(cmdArgs);
103

104
    if (!Akregator::Application::start(args)) {
Laurent Montel's avatar
Laurent Montel committed
105
        qCWarning(AKREGATOR_LOG) << "akregator is already running, exiting.";
Laurent Montel's avatar
Laurent Montel committed
106
        exit(0);
Frank Osterfeld's avatar
Frank Osterfeld committed
107
    }
Laurent Montel's avatar
Laurent Montel committed
108 109
    AkregratorMigrateApplication migrate;
    migrate.migrate();
Frank Osterfeld's avatar
Frank Osterfeld committed
110

111
    // start knotifyclient if not already started. makes it work for people who doesn't use full kde, according to kmail devels
Laurent Montel's avatar
Laurent Montel committed
112
    //KNotifyClient::startDaemon();
Stanislav Karchebny's avatar
 
Stanislav Karchebny committed
113

Heinrich Wendel's avatar
Heinrich Wendel committed
114
    // see if we are starting with session management
Laurent Montel's avatar
Laurent Montel committed
115
    if (app.isSessionRestored()) {
Heinrich Wendel's avatar
Heinrich Wendel committed
116
#undef RESTORE
Laurent Montel's avatar
Laurent Montel committed
117 118 119 120 121
#define RESTORE(type) { int n = 1; \
                        while (KMainWindow::canBeRestored(n)) { \
                            (new type)->restore(n, false); \
                            n++;} \
}
122

Heinrich Wendel's avatar
Heinrich Wendel committed
123 124
        RESTORE(Akregator::MainWindow);
    }
Stanislav Karchebny's avatar
 
Stanislav Karchebny committed
125

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