main.cpp 3.15 KB
Newer Older
1
/*
Allen Winter's avatar
Allen Winter committed
2
  This file is part of KAddressBook.
3

Allen Winter's avatar
Allen Winter committed
4
  Copyright (c) 2007 Tobias Koenig <tokoe@kde.org>
5

Allen Winter's avatar
Allen Winter committed
6
7
8
9
  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.
10

Allen Winter's avatar
Allen Winter committed
11
12
13
14
  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.
15

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

#include "aboutdata.h"
Volker Krause's avatar
Volker Krause committed
22
#include "mainwindow.h"
23
#include "mainwidget.h"
Laurent Montel's avatar
Laurent Montel committed
24
#include "kaddressbook_options.h"
Laurent Montel's avatar
Laurent Montel committed
25
#include "kaddressbookmigrateapplication.h"
Volker Krause's avatar
Volker Krause committed
26

Laurent Montel's avatar
Laurent Montel committed
27
#include <KCrash>
28
29
#include <QCommandLineParser>

Laurent Montel's avatar
Laurent Montel committed
30
#include "kaddressbook_debug.h"
Laurent Montel's avatar
Laurent Montel committed
31
#include <kontactinterface/pimuniqueapplication.h>
Laurent Montel's avatar
Laurent Montel committed
32
33
34
#ifdef WITH_KUSERFEEDBACK
#include "userfeedback/kaddressbookuserfeedbackprovider.h"
#endif
Laurent Montel's avatar
Laurent Montel committed
35
36
37
38
39
40

//-----------------------------------------------------------------------------

class KAddressBookApplication : public KontactInterface::PimUniqueApplication
{
public:
41
    KAddressBookApplication(int &argc, char **argv[])
Laurent Montel's avatar
Laurent Montel committed
42
43
        : KontactInterface::PimUniqueApplication(argc, argv)
        , mMainWindow(nullptr)
Laurent Montel's avatar
Laurent Montel committed
44
45
    {
    }
Laurent Montel's avatar
Laurent Montel committed
46

47
    int activate(const QStringList &arguments, const QString &) override;
Laurent Montel's avatar
Laurent Montel committed
48
49

private:
Laurent Montel's avatar
Laurent Montel committed
50
    MainWindow *mMainWindow = nullptr;
Laurent Montel's avatar
Laurent Montel committed
51
52
};

Laurent Montel's avatar
Laurent Montel committed
53
int KAddressBookApplication::activate(const QStringList &arguments, const QString &)
Laurent Montel's avatar
Laurent Montel committed
54
55
56
57
58
{
    if (!mMainWindow) {
        mMainWindow = new MainWindow;
        mMainWindow->show();
    }
59
    mMainWindow->mainWidget()->handleCommandLine(arguments);
Laurent Montel's avatar
Laurent Montel committed
60
61
    return 0;
}
62

Laurent Montel's avatar
Laurent Montel committed
63
int main(int argc, char **argv)
64
{
65
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
66
    QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
Laurent Montel's avatar
Laurent Montel committed
67
    QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
68
    KAddressBookApplication app(argc, &argv);
Laurent Montel's avatar
Laurent Montel committed
69
    app.setDesktopFileName(QStringLiteral("org.kde.kaddressbook"));
Laurent Montel's avatar
Laurent Montel committed
70
    KCrash::initialize();
Laurent Montel's avatar
Laurent Montel committed
71
    KLocalizedString::setApplicationDomain("kaddressbook");
72

Laurent Montel's avatar
Laurent Montel committed
73
    AboutData about;
74
    app.setAboutData(about);
Laurent Montel's avatar
Laurent Montel committed
75
    app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kaddressbook")));
76
77
    QCommandLineParser *cmdArgs = app.cmdArgs();
    kaddressbook_options(cmdArgs);
78

79
80
81
    const QStringList args = QCoreApplication::arguments();
    cmdArgs->process(args);
    about.processCommandLine(cmdArgs);
82

Laurent Montel's avatar
Laurent Montel committed
83
#ifdef WITH_KUSERFEEDBACK
Laurent Montel's avatar
Laurent Montel committed
84
    if (cmdArgs->isSet(QStringLiteral("feedback"))) {
Laurent Montel's avatar
Laurent Montel committed
85
86
87
88
89
90
91
        KAddressBookUserFeedbackProvider *userFeedBack = new KAddressBookUserFeedbackProvider(nullptr);
        QTextStream(stdout) << userFeedBack->describeDataSources() << '\n';
        delete userFeedBack;
        return 0;
    }
#endif

92
    if (!KAddressBookApplication::start(args)) {
93
        qCWarning(KADDRESSBOOK_LOG) << "kaddressbook is already running, exiting.";
Laurent Montel's avatar
Laurent Montel committed
94
95
        return 0;
    }
Laurent Montel's avatar
Laurent Montel committed
96
97
    KAddressBookMigrateApplication migrate;
    migrate.migrate();
98

Laurent Montel's avatar
Laurent Montel committed
99
    return app.exec();
100
}