SVN_SILENT made messages (.desktop file)
[kdepim.git] / calendarviews / viewerapp / mainwindow.cpp
blobb7226fc826ef9bfe7e98ebef7ad0ea3a27e1540b
1 /*
2 Copyright (C) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
3 Author: Kevin Krammer, krake@kdab.com
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "mainwindow.h"
22 #include "settings.h"
24 #include "agenda.h"
25 #include "agendaview.h"
26 #include "month/monthview.h"
27 #include "multiagenda/multiagendaview.h"
28 #include "timeline/timelineview.h"
29 #include "prefs.h"
31 #include <calendarsupport/collectionselection.h>
33 #include <Akonadi/Calendar/IncidenceChanger>
34 #include <KCalCore/Event>
36 #include <Akonadi/Collection>
37 #include <Akonadi/Control>
39 #include <KCheckableProxyModel>
40 #include <KSystemTimeZones>
42 using namespace Akonadi;
43 using namespace CalendarSupport;
44 using namespace EventViews;
46 MainWindow::MainWindow( const QStringList &viewNames )
47 : QMainWindow(),
48 mViewNames( viewNames ),
49 mIncidenceChanger( 0 ),
50 mSettings( 0 ),
51 mViewPreferences( 0 )
53 mUi.setupUi( this );
54 mUi.tabWidget->clear();
56 connect( mUi.addViewMenu, SIGNAL(triggered(QAction*)), this, SLOT(addViewTriggered(QAction*)) );
58 Akonadi::Control::widgetNeedsAkonadi( this );
60 setGeometry( 0, 0, 800, 600 );
61 QMetaObject::invokeMethod( this, "delayedInit", Qt::QueuedConnection );
64 MainWindow::~MainWindow()
66 delete mViewPreferences;
67 delete mSettings;
70 void MainWindow::addView( const QString &viewName )
72 EventView *eventView = 0;
74 const KDateTime start = KDateTime::currentLocalDateTime().addDays( -1 );
75 const KDateTime end = KDateTime::currentLocalDateTime().addDays( 1 );
77 if ( viewName == QLatin1String( "agenda" ) ) {
78 eventView = new AgendaView( start.date(), end.date(), true, false, this );
79 } else if ( viewName == QLatin1String( "multiagenda" ) ) {
80 eventView = new MultiAgendaView( this );
81 } else if ( viewName == QLatin1String( "month" ) ) {
82 eventView = new MonthView( MonthView::Visible, this );
83 } else if ( viewName == QLatin1String( "timeline" ) ) {
84 eventView = new TimelineView( this );
87 if ( eventView ) {
88 eventView->setPreferences( *mViewPreferences );
89 eventView->setCalendar( mCalendar );
90 eventView->setIncidenceChanger( mIncidenceChanger );
91 eventView->setDateRange( start, end );
92 eventView->updateConfig();
93 mUi.tabWidget->addTab( eventView, viewName );
94 } else {
95 kError() << "Cannot create view" << viewName;
99 void MainWindow::delayedInit()
101 // create our application settings
102 mSettings = new Settings;
104 // create view preferences so that matching values are retrieved from
105 // application settings
106 mViewPreferences = new PrefsPtr( new Prefs( mSettings ) );
108 mCalendar = Akonadi::ETMCalendar::Ptr( new Akonadi::ETMCalendar() );
109 KCheckableProxyModel *checkableProxy = mCalendar->checkableProxyModel();
110 QItemSelectionModel *selectionModel = checkableProxy->selectionModel();
112 CalendarSupport::CollectionSelection *collectionSelection = new CalendarSupport::CollectionSelection( selectionModel );
113 EventViews::EventView::setGlobalCollectionSelection( collectionSelection );
115 mIncidenceChanger = new IncidenceChanger( this );
116 mCalendar->setCollectionFilteringEnabled( false );
118 Q_FOREACH( const QString &viewName, mViewNames ) {
119 addView( viewName );
123 void MainWindow::addViewTriggered( QAction *action )
125 QString viewName = action->text().toLower();
126 viewName.remove( QLatin1Char( '&' ) );
127 addView( viewName );
130 #include "mainwindow.moc"
132 // kate: space-indent on; indent-width 2; replace-tabs on;