1
/* This file is part of Zanshin Todo.
3
Copyright 2008 Kevin Ottens <ervin@kde.org>
4
Copyright 2008, 2009 Mario Bensi <nef@ipsquad.net>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public License as
8
published by the Free Software Foundation; either version 2 of
9
the License or (at your option) version 3 or any later version
10
accepted by the membership of KDE e.V. (or its successor approved
11
by the membership of KDE e.V.), which shall act as a proxy
12
defined in Section 14 of version 3 of the license.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25
#include "mainwindow.h"
27
#include <akonadi/control.h>
29
#include <akonadi/collectionfetchjob.h>
31
#include <KDE/KAction>
32
#include <KDE/KActionCollection>
33
#include <KDE/KConfigGroup>
35
#include <KDE/KLocale>
37
#include <QtGui/QDockWidget>
38
#include <QtGui/QHeaderView>
40
#include "actionlisteditor.h"
41
#include "actionlistview.h"
42
#include "configdialog.h"
43
#include "globalmodel.h"
44
#include "globalsettings.h"
45
#include "todoflatmodel.h"
48
MainWindow::MainWindow(QWidget *parent)
49
: KXmlGuiWindow(parent)
51
Akonadi::Control::start();
62
actionCollection()->action("project_mode")->trigger();
65
void MainWindow::setupCentralWidget()
67
m_editor = new ActionListEditor(this, actionCollection());
69
connect(m_sidebar, SIGNAL(noProjectInboxActivated()),
70
m_editor, SLOT(showNoProjectInbox()));
71
connect(m_sidebar, SIGNAL(projectActivated(QModelIndex)),
72
m_editor, SLOT(focusOnProject(QModelIndex)));
73
connect(m_sidebar, SIGNAL(noContextInboxActivated()),
74
m_editor, SLOT(showNoContextInbox()));
75
connect(m_sidebar, SIGNAL(contextActivated(QModelIndex)),
76
m_editor, SLOT(focusOnContext(QModelIndex)));
78
setCentralWidget(m_editor);
81
void MainWindow::setupSideBar()
83
m_sidebar = new SideBar(this, actionCollection());
85
QDockWidget *dock = new QDockWidget(this);
86
dock->setObjectName("SideBar");
87
dock->setFeatures(dock->features() & ~QDockWidget::DockWidgetClosable);
88
dock->setWidget(m_sidebar);
89
addDockWidget(Qt::LeftDockWidgetArea, dock);
92
void MainWindow::setupActions()
94
KActionCollection *ac = actionCollection();
96
QActionGroup *modeGroup = new QActionGroup(this);
97
modeGroup->setExclusive(true);
99
KAction *action = ac->addAction("project_mode", m_sidebar, SLOT(switchToProjectMode()));
100
action->setText(i18n("Project View"));
101
action->setIcon(KIcon("view-pim-tasks"));
102
action->setShortcut(Qt::CTRL | Qt::Key_P);
103
action->setCheckable(true);
104
modeGroup->addAction(action);
106
action = ac->addAction("context_mode", m_sidebar, SLOT(switchToContextMode()));
107
action->setText(i18n("Context View"));
108
action->setIcon(KIcon("view-pim-notes"));
109
action->setShortcut(Qt::CTRL | Qt::Key_O);
110
action->setCheckable(true);
111
modeGroup->addAction(action);
113
ac->addAction(KStandardAction::Preferences, this, SLOT(showConfigDialog()));
114
ac->addAction(KStandardAction::Quit, this, SLOT(close()));
117
void MainWindow::closeEvent(QCloseEvent *event)
120
KXmlGuiWindow::closeEvent(event);
123
void MainWindow::saveAutoSaveSettings()
126
KXmlGuiWindow::saveAutoSaveSettings();
129
void MainWindow::saveColumnsState()
131
KConfigGroup cg = autoSaveConfigGroup();
132
QByteArray state = m_editor->view()->header()->saveState();
133
cg.writeEntry("MainHeaderState", state.toBase64());
136
void MainWindow::restoreColumnState()
138
KConfigGroup cg = autoSaveConfigGroup();
140
if (cg.hasKey("MainHeaderState")) {
141
state = cg.readEntry("MainHeaderState", state);
142
m_editor->view()->header()->restoreState(QByteArray::fromBase64(state));
146
void MainWindow::showConfigDialog()
148
if (KConfigDialog::showDialog("settings")) {
152
ConfigDialog *dialog = new ConfigDialog(this, "settings",
153
GlobalSettings::self());
155
connect(dialog, SIGNAL(settingsChanged(const QString&)),
156
this, SLOT(applySettings()));
161
void MainWindow::applySettings()
163
Akonadi::Collection collection(GlobalSettings::collectionId());
165
if (!collection.isValid()) {
170
Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(collection, Akonadi::CollectionFetchJob::Base);
173
if (job->collections().isEmpty()) {
178
GlobalModel::todoFlat()->setCollection(job->collections().first());