Documentation: Menus.docbook Composer menu Message and correcct formatting.
[kdepim.git] / korganizer / korganizer.cpp
blobfc11b2d91d86e23787f636f714344296db9b5e32
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 "korganizerifaceimpl.h"
38 #include <libkdepim/progresswidget/progressdialog.h>
39 #include <libkdepim/progresswidget/statusbarprogresswidget.h>
41 #include <KAction>
42 #include <KActionCollection>
43 #include <KDebug>
44 #include <KShortcutsDialog>
45 #include <KStandardAction>
46 #include <KStatusBar>
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 kDebug();
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( "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( KGlobal::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(KUrl)),
85 SLOT(newMainWindow(KUrl)) );*/
87 mActionManager->loadParts();
89 initActions();
90 readSettings();
92 KStatusBar *bar = statusBar();
94 bar->insertItem( "", ID_GENERAL, 10 );
95 connect( bar, SIGNAL(pressed(int)), SLOT(statusBarPressed(int)) );
97 KPIM::ProgressDialog *progressDialog = new KPIM::ProgressDialog( bar, this );
98 progressDialog->hide();
100 KPIM::StatusbarProgressWidget *progressWidget;
101 progressWidget = new KPIM::StatusbarProgressWidget( progressDialog, bar );
102 progressWidget->show();
104 bar->addPermanentWidget( progressWidget );
106 connect( mActionManager->view(), SIGNAL(statusMessage(QString)),
107 SLOT(showStatusMessage(QString)) );
109 setStandardToolBarMenuEnabled( true );
110 setTitle();
113 void KOrganizer::newMainWindow( const KUrl &url )
115 KOrganizer *korg = new KOrganizer();
116 if ( url.isValid() || url.isEmpty() ) {
117 korg->init( true );
118 if ( korg->openURL( url ) || url.isEmpty() ) {
119 korg->show();
120 } else {
121 delete korg;
123 } else {
124 korg->init( false );
125 korg->show();
129 void KOrganizer::readSettings()
131 // read settings from the KConfig, supplying reasonable
132 // defaults where none are to be found
134 KConfig *config = KOGlobals::self()->config();
136 mActionManager->readSettings();
138 config->sync();
141 void KOrganizer::writeSettings()
143 kDebug();
145 KConfig *config = KOGlobals::self()->config();
147 mActionManager->writeSettings();
148 config->sync();
151 void KOrganizer::initActions()
153 setStandardToolBarMenuEnabled( true );
154 createStandardStatusBarAction();
156 KStandardAction::keyBindings( this, SLOT(slotEditKeys()), actionCollection() );
157 KStandardAction::configureToolbars( this, SLOT(configureToolbars()), actionCollection() );
158 KStandardAction::quit( this, SLOT(close()), actionCollection() );
160 setXMLFile( "korganizerui.rc", true );
161 createGUI( 0 );
163 setAutoSaveSettings();
166 void KOrganizer::slotEditKeys()
168 KShortcutsDialog::configure( actionCollection(),
169 KShortcutsEditor::LetterShortcutsAllowed );
172 bool KOrganizer::queryClose()
174 kDebug();
176 bool close = mActionManager->queryClose();
178 // Write configuration. I don't know if it really makes sense doing it this
179 // way, when having opened multiple calendars in different CalendarViews.
180 if ( close ) {
181 writeSettings();
184 return close;
187 bool KOrganizer::queryExit()
189 // Don't call writeSettings here, because filename isn't valid anymore.
190 // It is now called in queryClose.
191 // writeSettings();
192 return true;
195 void KOrganizer::statusBarPressed( int id )
197 Q_UNUSED( id );
200 void KOrganizer::showStatusMessage( const QString &message )
202 statusBar()->showMessage( message, 2000 );
205 bool KOrganizer::openURL( const KUrl &url, bool merge )
207 return mActionManager->openURL( url, merge );
210 bool KOrganizer::saveURL()
212 return mActionManager->saveURL();
215 bool KOrganizer::saveAsURL( const KUrl & kurl )
217 return mActionManager->saveAsURL( kurl ) ;
220 KUrl KOrganizer::getCurrentURL() const
222 return mActionManager->url();
225 void KOrganizer::saveProperties( KConfigGroup &config )
227 return mActionManager->saveProperties( config );
230 void KOrganizer::readProperties( const KConfigGroup &config )
232 return mActionManager->readProperties( config );
235 KOrg::CalendarViewBase *KOrganizer::view() const
237 return mActionManager->view();
240 void KOrganizer::setTitle()
242 QString title;
243 if ( !hasDocument() ) {
244 title = i18n( "Calendar" );
245 } else {
246 KUrl url = mActionManager->url();
248 if ( !url.isEmpty() ) {
249 if ( url.isLocalFile() ) {
250 title = url.fileName();
251 } else {
252 title = url.prettyUrl();
254 } else {
255 title = i18n( "New Calendar" );
258 if ( mCalendarView->isReadOnly() ) {
259 title += " [" + i18nc( "the calendar is read-only", "read-only" ) + ']';
262 if ( mCalendarView->isFiltered() ) {
263 title += " - <" + mCalendarView->currentFilterName() + "> ";
266 setCaption( title, false );
269 #include "korganizer.moc"