SVN_SILENT made messages (.desktop file) - always resolve ours
[kdepim.git] / korganizer / korganizer.cpp
blob81adf8fbba16dce09e9e4809ab91bb4541594b74
1 /*
2 This file is part of KOrganizer.
4 Copyright (c) 1997, 1998, 1999 Preston Brown <preston.brown@yale.edu>
5 Fester Zigterman <F.J.F.ZigtermanRustenburg@student.utwente.nl>
6 Ian Dawes <iadawes@globalserve.net>
7 Laszlo Boloni <boloni@cs.purdue.edu>
9 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
10 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License along
23 with this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 As a special exception, permission is given to link this program
27 with any edition of Qt, and distribute the resulting executable,
28 without including the source code for Qt in the source distribution.
31 #include "korganizer.h"
32 #include "actionmanager.h"
33 #include "calendarview.h"
34 #include "kocore.h"
35 #include "koglobals.h"
36 #include "impl/korganizerifaceimpl.h"
38 #include "libkdepim/progresswidget/progressstatusbarwidget.h"
39 #include "libkdepim/progresswidget/statusbarprogresswidget.h"
41 #include <KActionCollection>
42 #include "korganizer_debug.h"
43 #include <KShortcutsDialog>
44 #include <KStandardAction>
45 #include <QLabel>
46 #include <QStatusBar>
48 KOrganizer::KOrganizer() : KParts::MainWindow(), KOrg::MainWindow()
50 // Set this to be the group leader for all subdialogs - this means
51 // modal subdialogs will only affect this dialog, not the other windows
52 setAttribute(Qt::WA_GroupLeader);
54 qCDebug(KORGANIZER_LOG);
55 KOCore::self()->addXMLGUIClient(this, this);
56 // setMinimumSize(600,400); // make sure we don't get resized too small...
58 mCalendarView = new CalendarView(this);
59 mCalendarView->setObjectName(QStringLiteral("KOrganizer::CalendarView"));
60 setCentralWidget(mCalendarView);
62 mActionManager = new ActionManager(this, mCalendarView, this, this, false, menuBar());
63 (void)new KOrganizerIfaceImpl(mActionManager, this, "IfaceImpl");
66 KOrganizer::~KOrganizer()
68 delete mActionManager;
70 KOCore::self()->removeXMLGUIClient(this);
73 void KOrganizer::init(bool document)
75 setHasDocument(document);
77 setComponentData(KComponentData::mainComponent());
79 // Create calendar object, which manages all calendar information associated
80 // with this calendar view window.
81 mActionManager->createCalendarAkonadi();
83 mActionManager->init();
84 /*connect( mActionManager, SIGNAL(actionNewMainWindow(QUrl)),
85 SLOT(newMainWindow(QUrl)) );*/
87 mActionManager->loadParts();
89 initActions();
90 readSettings();
92 QStatusBar *bar = statusBar();
94 bar->addWidget(new QLabel(this));
96 KPIM::ProgressStatusBarWidget *progressBar = new KPIM::ProgressStatusBarWidget(statusBar(), this);
98 bar->addPermanentWidget(progressBar->littleProgress());
100 connect(mActionManager->view(), &CalendarView::statusMessage,
101 this, &KOrganizer::showStatusMessage);
103 setStandardToolBarMenuEnabled(true);
104 setTitle();
107 void KOrganizer::newMainWindow(const QUrl &url)
109 KOrganizer *korg = new KOrganizer();
110 if (url.isValid() || url.isEmpty()) {
111 korg->init(true);
112 if (mActionManager->importURL(url, false) || url.isEmpty()) {
113 korg->show();
114 } else {
115 delete korg;
117 } else {
118 korg->init(false);
119 korg->show();
123 void KOrganizer::readSettings()
125 // read settings from the KConfig, supplying reasonable
126 // defaults where none are to be found
128 KConfig *config = KOGlobals::self()->config();
130 mActionManager->readSettings();
132 config->sync();
135 void KOrganizer::writeSettings()
137 qCDebug(KORGANIZER_LOG);
139 KConfig *config = KOGlobals::self()->config();
141 mActionManager->writeSettings();
142 config->sync();
145 void KOrganizer::initActions()
147 setStandardToolBarMenuEnabled(true);
148 createStandardStatusBarAction();
150 KStandardAction::keyBindings(this, SLOT(slotEditKeys()), actionCollection());
151 KStandardAction::configureToolbars(this, SLOT(configureToolbars()), actionCollection());
152 KStandardAction::quit(this, SLOT(close()), actionCollection());
154 setXMLFile(QStringLiteral("korganizerui.rc"), true);
155 createGUI(Q_NULLPTR);
157 setAutoSaveSettings();
160 void KOrganizer::slotEditKeys()
162 KShortcutsDialog::configure(actionCollection(),
163 KShortcutsEditor::LetterShortcutsAllowed);
166 bool KOrganizer::queryClose()
168 qCDebug(KORGANIZER_LOG);
170 bool close = mActionManager->queryClose();
172 // Write configuration. I don't know if it really makes sense doing it this
173 // way, when having opened multiple calendars in different CalendarViews.
174 if (close) {
175 writeSettings();
178 return close;
181 void KOrganizer::showStatusMessage(const QString &message)
183 statusBar()->showMessage(message, 2000);
186 bool KOrganizer::openURL(const QUrl &url, bool merge)
188 return mActionManager->importURL(url, merge);
191 bool KOrganizer::saveURL()
193 return mActionManager->saveURL();
196 bool KOrganizer::saveAsURL(const QUrl &kurl)
198 return mActionManager->saveAsURL(kurl) ;
201 QUrl KOrganizer::getCurrentURL() const
203 return mActionManager->url();
206 void KOrganizer::saveProperties(KConfigGroup &config)
208 return mActionManager->saveProperties(config);
211 void KOrganizer::readProperties(const KConfigGroup &config)
213 return mActionManager->readProperties(config);
216 KOrg::CalendarViewBase *KOrganizer::view() const
218 return mActionManager->view();
221 void KOrganizer::setTitle()
223 QString title;
224 if (!hasDocument()) {
225 title = i18n("Calendar");
226 } else {
227 QUrl url = mActionManager->url();
229 if (!url.isEmpty()) {
230 if (url.isLocalFile()) {
231 title = url.fileName();
232 } else {
233 title = url.toDisplayString();
235 } else {
236 title = i18n("New Calendar");
239 if (mCalendarView->isReadOnly()) {
240 title += QLatin1String(" [") + i18nc("the calendar is read-only", "read-only") + QLatin1Char(']');
243 if (mCalendarView->isFiltered()) {
244 title += QLatin1String(" - <") + mCalendarView->currentFilterName() + QLatin1String("> ");
247 setCaption(title, false);