koapp.cpp 4.16 KB
Newer Older
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
/*
  This file is part of KOrganizer.

  Copyright (c) 1999 Preston Brown <pbrown@kde.org>
  Copyright (c) 2000,2001,2003 Cornelius Schumacher <schumacher@kde.org>
  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>

  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 Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

  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.
*/

#include "koapp.h"
#include "actionmanager.h"
#include "calendarview.h"
30
#include "korganizer.h"
Laurent Montel's avatar
Build++    
Laurent Montel committed
31
#include "KdepimDBusInterfaces/ReminderClient"
Laurent Montel's avatar
Laurent Montel committed
32
#include "korganizer-version.h"
33
#include <KCalCore/CalFormat>
34
#include <KStartupInfo>
35

Laurent Montel's avatar
Laurent Montel committed
36
#include "korganizer_debug.h"
37
#include "korganizer_options.h"
38
#include <KStartupInfo>
39
#include <QCommandLineParser>
40

41
42
KOrganizerApp::KOrganizerApp(int &argc, char **argv[])
    : KontactInterface::PimUniqueApplication(argc, argv)
43
{
44
    QString prodId = QStringLiteral("-//K Desktop Environment//NONSGML KOrganizer %1//EN");
Laurent Montel's avatar
Laurent Montel committed
45
    KCalCore::CalFormat::setApplication(QStringLiteral("KOrganizer"), prodId.arg(QStringLiteral(KORGANIZER_VERSION)));
46
47
48
49
50
51
}

KOrganizerApp::~KOrganizerApp()
{
}

52
int KOrganizerApp::activate(const QStringList &args, const QString &workingDir)
53
{
Laurent Montel's avatar
Laurent Montel committed
54

Laurent Montel's avatar
Laurent Montel committed
55
56
    static bool first = true;
    if (isSessionRestored() && first) {
Laurent Montel's avatar
Laurent Montel committed
57
        KOrg::MainWindow *korg = ActionManager::findInstance(QUrl());
Laurent Montel's avatar
Laurent Montel committed
58
59
60
61
62
63
64
65
        if (korg) {
            korg->view()->updateView();
        }
        first = false;
        return 0;
    }
    first = false;

66
67
68
    QCommandLineParser parser;
    korganizer_options(&parser);
    parser.process(args);
Laurent Montel's avatar
Laurent Montel committed
69
70
71
72

    KPIM::ReminderClient::startDaemon();

    // No filenames given => all other args are meaningless, show main Window
73
    if (parser.positionalArguments().isEmpty()) {
Laurent Montel's avatar
Laurent Montel committed
74
        processCalendar(QUrl());
Laurent Montel's avatar
Laurent Montel committed
75
76
77
78
79
        return 0;
    }

    // If filenames were given as arguments, load them as calendars, one per window.
    // Import, merge, or ask => we need the resource calendar window anyway.
Laurent Montel's avatar
Laurent Montel committed
80
81
    processCalendar(QUrl());
    KOrg::MainWindow *korg = ActionManager::findInstance(QUrl());
Laurent Montel's avatar
Laurent Montel committed
82
    if (!korg) {
Laurent Montel's avatar
Laurent Montel committed
83
        qCCritical(KORGANIZER_LOG) << "Unable to find default calendar resources view.";
Laurent Montel's avatar
Laurent Montel committed
84
85
86
        return -1;
    }
    // Check for import, merge or ask
87
    if (parser.isSet(QStringLiteral("import"))) {
88
89
        for (const QString &url : parser.positionalArguments()) {
            korg->actionManager()->importURL(QUrl::fromUserInput(url), false);
Laurent Montel's avatar
Laurent Montel committed
90
        }
91
    } else if (parser.isSet(QStringLiteral("merge"))) {
92
93
        for (const QString &url : parser.positionalArguments()) {
            korg->actionManager()->importURL(QUrl::fromUserInput(url), true);
Laurent Montel's avatar
Laurent Montel committed
94
95
        }
    } else {
96
97
        for (const QString &url : parser.positionalArguments()) {
            korg->actionManager()->importCalendar(QUrl::fromUserInput(url));
Laurent Montel's avatar
Laurent Montel committed
98
99
100
        }
    }

101
102
103
    return 0;
}

Laurent Montel's avatar
Laurent Montel committed
104
void KOrganizerApp::processCalendar(const QUrl &url)
105
{
Laurent Montel's avatar
Laurent Montel committed
106
107
108
109
110
111
112
    KOrg::MainWindow *korg = ActionManager::findInstance(url);
    if (!korg) {
        bool hasDocument = !url.isEmpty();
        korg = new KOrganizer();
        korg->init(hasDocument);
        korg->topLevelWidget()->show();

Laurent Montel's avatar
Laurent Montel committed
113
        qCDebug(KORGANIZER_LOG) << url.url();
Laurent Montel's avatar
Laurent Montel committed
114
115
116
117
118
119

        if (hasDocument) {
            korg->openURL(url);
        } else {
            //      korg->view()->updateView();
        }
120
    } else {
Laurent Montel's avatar
Laurent Montel committed
121
        korg->topLevelWidget()->show();
122
123
    }

Laurent Montel's avatar
Laurent Montel committed
124
    // Handle window activation
Laurent Montel's avatar
Laurent Montel committed
125
#if defined Q_OS_X11 && ! defined K_WS_QTONLY
Laurent Montel's avatar
Laurent Montel committed
126
    KStartupInfo::setNewStartupId(korg->topLevelWidget(), startupId());
127
128
129
#endif
}