korganizer Library API Documentation

korganizer.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 1997, 1998, 1999 00005 Preston Brown (preston.brown@yale.edu) 00006 Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl) 00007 Ian Dawes (iadawes@globalserve.net) 00008 Laszlo Boloni (boloni@cs.purdue.edu) 00009 00010 Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org> 00011 00012 This program is free software; you can redistribute it and/or modify 00013 it under the terms of the GNU General Public License as published by 00014 the Free Software Foundation; either version 2 of the License, or 00015 (at your option) any later version. 00016 00017 This program is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with this program; if not, write to the Free Software 00024 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00025 00026 As a special exception, permission is given to link this program 00027 with any edition of Qt, and distribute the resulting executable, 00028 without including the source code for Qt in the source distribution. 00029 */ 00030 00031 #include "korganizer.h" 00032 00033 #include "komailclient.h" 00034 #include "calprinter.h" 00035 #include "calendarview.h" 00036 #include "koviewmanager.h" 00037 #include "kodialogmanager.h" 00038 #include "kowindowlist.h" 00039 #include "koprefs.h" 00040 #include "kocore.h" 00041 #include "konewstuff.h" 00042 #include "actionmanager.h" 00043 #include "koglobals.h" 00044 #include "alarmclient.h" 00045 #include "resourceview.h" 00046 #include "korganizerifaceimpl.h" 00047 00048 #include <korganizer/part.h> 00049 00050 #include <libkdepim/statusbarprogresswidget.h> 00051 #include <libkdepim/progressdialog.h> 00052 00053 #include <libkcal/calendarlocal.h> 00054 #include <libkcal/calendarresources.h> 00055 #include <libkcal/resourcecalendar.h> 00056 #include <libkcal/resourcelocal.h> 00057 00058 #include <kglobal.h> 00059 #include <kdebug.h> 00060 #include <kiconloader.h> 00061 #include <kstandarddirs.h> 00062 #include <kstdaccel.h> 00063 #include <kfiledialog.h> 00064 #include <kaction.h> 00065 #include <kstdaction.h> 00066 #include <kedittoolbar.h> 00067 #include <ktempfile.h> 00068 #include <kio/netaccess.h> 00069 #include <kmessagebox.h> 00070 #include <dcopclient.h> 00071 #include <kprocess.h> 00072 #include <kwin.h> 00073 #include <kkeydialog.h> 00074 #include <ktip.h> 00075 #include <kstdguiitem.h> 00076 #include <kstatusbar.h> 00077 00078 #include <qcursor.h> 00079 #include <qtimer.h> 00080 #include <qvbox.h> 00081 #include <qfile.h> 00082 #include <qlabel.h> 00083 #include <qlayout.h> 00084 00085 #include <stdlib.h> 00086 00087 using namespace KParts; 00088 #include "korganizer.moc" 00089 using namespace KOrg; 00090 00091 KOrganizer::KOrganizer( const char *name ) 00092 : KParts::MainWindow( 0, name ), 00093 KOrg::MainWindow() 00094 { 00095 kdDebug(5850) << "KOrganizer::KOrganizer()" << endl; 00096 KOCore::self()->setXMLGUIClient( this ); 00097 // setMinimumSize(600,400); // make sure we don't get resized too small... 00098 00099 mCalendarView = new CalendarView( this, "KOrganizer::CalendarView" ); 00100 setCentralWidget(mCalendarView); 00101 00102 mActionManager = new ActionManager( this, mCalendarView, this, this, false ); 00103 (void)new KOrganizerIfaceImpl( mActionManager, this, "IfaceImpl" ); 00104 } 00105 00106 KOrganizer::~KOrganizer() 00107 { 00108 delete mActionManager; 00109 } 00110 00111 void KOrganizer::init( bool document ) 00112 { 00113 kdDebug() << "KOrganizer::init() " 00114 << ( document ? "hasDocument" : "resources" ) << endl; 00115 00116 setHasDocument( document ); 00117 00118 // Create calendar object, which manages all calendar information associated 00119 // with this calendar view window. 00120 if ( hasDocument() ) { 00121 mActionManager->createCalendarLocal(); 00122 } else { 00123 mActionManager->createCalendarResources(); 00124 setCaption( i18n("Calendar") ); 00125 } 00126 00127 mActionManager->init(); 00128 connect( mActionManager, SIGNAL( actionNew( const KURL & ) ), 00129 SLOT( newMainWindow( const KURL & ) ) ); 00130 connect( mActionManager, SIGNAL( actionKeyBindings() ), 00131 SLOT( configureKeyBindings() ) ); 00132 00133 mActionManager->loadParts(); 00134 00135 initActions(); 00136 readSettings(); 00137 00138 KStatusBar *bar = statusBar(); 00139 00140 bar->insertItem( "", ID_GENERAL, 10 ); 00141 00142 bar->insertItem( i18n(" Incoming messages: %1 ").arg( 0 ), ID_MESSAGES_IN ); 00143 bar->insertItem( i18n(" Outgoing messages: %2 ").arg( 0 ), ID_MESSAGES_OUT ); 00144 bar->setItemAlignment( ID_MESSAGES_IN, AlignRight ); 00145 bar->setItemAlignment( ID_MESSAGES_OUT, AlignRight ); 00146 connect( bar, SIGNAL( pressed( int ) ), SLOT( statusBarPressed( int ) ) ); 00147 00148 KPIM::ProgressDialog *progressDialog = new KPIM::ProgressDialog( bar, this ); 00149 progressDialog->hide(); 00150 00151 KPIM::StatusbarProgressWidget *progressWidget; 00152 progressWidget = new KPIM::StatusbarProgressWidget( progressDialog, bar ); 00153 progressWidget->show(); 00154 00155 bar->addWidget( progressWidget, 0, true ); 00156 00157 connect( mActionManager->view(), SIGNAL( numIncomingChanged( int ) ), 00158 SLOT( setNumIncoming( int ) ) ); 00159 connect( mActionManager->view(), SIGNAL( numOutgoingChanged( int ) ), 00160 SLOT( setNumOutgoing( int ) ) ); 00161 00162 connect( mActionManager->view(), SIGNAL( statusMessage( const QString & ) ), 00163 SLOT( showStatusMessage( const QString & ) ) ); 00164 00165 setStandardToolBarMenuEnabled( true ); 00166 00167 kdDebug(5850) << "KOrganizer::KOrganizer() done" << endl; 00168 } 00169 00170 void KOrganizer::newMainWindow( const KURL &url ) 00171 { 00172 KOrganizer *korg = new KOrganizer(); 00173 if ( url.isValid() || url.isEmpty() ) { 00174 korg->init( true ); 00175 if ( korg->openURL( url ) || url.isEmpty() ) { 00176 korg->show(); 00177 } else { 00178 delete korg; 00179 } 00180 } else { 00181 korg->init( false ); 00182 korg->show(); 00183 } 00184 } 00185 00186 void KOrganizer::readSettings() 00187 { 00188 // read settings from the KConfig, supplying reasonable 00189 // defaults where none are to be found 00190 00191 KConfig *config = KOGlobals::self()->config(); 00192 00193 config->setGroup( "KOrganizer Geometry" ); 00194 00195 int windowWidth = config->readNumEntry( "Width", 600 ); 00196 int windowHeight = config->readNumEntry( "Height", 400 ); 00197 00198 resize( windowWidth, windowHeight ); 00199 00200 mActionManager->readSettings(); 00201 00202 config->sync(); 00203 } 00204 00205 00206 void KOrganizer::writeSettings() 00207 { 00208 kdDebug(5850) << "KOrganizer::writeSettings" << endl; 00209 00210 KConfig *config = KOGlobals::self()->config(); 00211 00212 config->setGroup( "KOrganizer Geometry" ); 00213 config->writeEntry( "Width",width() ); 00214 config->writeEntry( "Height",height() ); 00215 00216 mActionManager->writeSettings(); 00217 saveMainWindowSettings( config ); 00218 config->sync(); 00219 } 00220 00221 00222 void KOrganizer::initActions() 00223 { 00224 KStdAction::quit( this, SLOT( close() ), actionCollection() ); 00225 mStatusBarAction = KStdAction::showStatusbar( this, SLOT( toggleStatusBar() ), 00226 actionCollection() ); 00227 00228 KStdAction::configureToolbars( this, SLOT( configureToolbars() ), 00229 actionCollection() ); 00230 00231 setInstance( KGlobal::instance() ); 00232 00233 setXMLFile( "korganizerui.rc" ); 00234 createGUI( 0 ); 00235 00236 KConfig *config = KOGlobals::self()->config(); 00237 00238 applyMainWindowSettings( config ); 00239 00240 mStatusBarAction->setChecked( !statusBar()->isHidden() ); 00241 } 00242 00243 #if 0 00244 void KOrganizer::initViews() 00245 { 00246 kdDebug(5850) << "KOrganizer::initViews()" << endl; 00247 00248 // TODO: get calendar pointer from somewhere 00249 KOrg::View::List views = KOCore::self()->views( this ); 00250 KOrg::View *it; 00251 for( it = views.first(); it; it = views.next() ) { 00252 guiFactory()->addClient( it ); 00253 } 00254 } 00255 #endif 00256 00257 bool KOrganizer::queryClose() 00258 { 00259 kdDebug(5850) << "KOrganizer::queryClose()" << endl; 00260 00261 bool close = mActionManager->queryClose(); 00262 00263 // Write configuration. I don't know if it really makes sense doing it this 00264 // way, when having opened multiple calendars in different CalendarViews. 00265 if ( close ) writeSettings(); 00266 00267 return close; 00268 } 00269 00270 bool KOrganizer::queryExit() 00271 { 00272 // Don't call writeSettings here, because filename isn't valid anymore. It is 00273 // now called in queryClose. 00274 // writeSettings(); 00275 return true; 00276 } 00277 00278 void KOrganizer::configureToolbars() 00279 { 00280 saveMainWindowSettings( KOGlobals::self()->config(), "MainWindow" ); 00281 00282 KEditToolbar dlg( factory() ); 00283 dlg.exec(); 00284 } 00285 00286 void KOrganizer::toggleStatusBar() 00287 { 00288 bool show_statusbar = mStatusBarAction->isChecked(); 00289 if (show_statusbar) 00290 statusBar()->show(); 00291 else 00292 statusBar()->hide(); 00293 } 00294 00295 void KOrganizer::statusBarPressed( int id ) 00296 { 00297 if ( id == ID_MESSAGES_IN ) 00298 mCalendarView->dialogManager()->showIncomingDialog(); 00299 else if ( id == ID_MESSAGES_OUT ) 00300 mCalendarView->dialogManager()->showOutgoingDialog(); 00301 } 00302 00303 void KOrganizer::setNumIncoming( int num ) 00304 { 00305 statusBar()->changeItem( i18n(" Incoming messages: %1 ").arg( num ), 00306 ID_MESSAGES_IN); 00307 } 00308 00309 void KOrganizer::setNumOutgoing( int num ) 00310 { 00311 statusBar()->changeItem( i18n(" Outgoing messages: %1 ").arg( num ), 00312 ID_MESSAGES_OUT ); 00313 } 00314 00315 void KOrganizer::showStatusMessage( const QString &message ) 00316 { 00317 statusBar()->message(message,2000); 00318 } 00319 00320 bool KOrganizer::openURL( const KURL &url, bool merge ) 00321 { 00322 return mActionManager->openURL( url, merge ); 00323 } 00324 00325 bool KOrganizer::saveURL() 00326 { 00327 return mActionManager->saveURL(); 00328 } 00329 00330 bool KOrganizer::saveAsURL( const KURL & kurl ) 00331 { 00332 return mActionManager->saveAsURL( kurl ) ; 00333 } 00334 00335 KURL KOrganizer::getCurrentURL() const 00336 { 00337 return mActionManager->url(); 00338 } 00339 00340 void KOrganizer::saveProperties( KConfig *config ) 00341 { 00342 return mActionManager->saveProperties( config ); 00343 } 00344 00345 void KOrganizer::readProperties( KConfig *config ) 00346 { 00347 return mActionManager->readProperties( config ); 00348 } 00349 00350 KOrg::CalendarViewBase *KOrganizer::view() const 00351 { 00352 return mActionManager->view(); 00353 } 00354 00355 void KOrganizer::setTitle() 00356 { 00357 // kdDebug(5850) << "KOrganizer::setTitle" << endl; 00358 00359 if ( !hasDocument() ) return; 00360 00361 QString title; 00362 00363 KURL url = mActionManager->url(); 00364 00365 if ( !url.isEmpty() ) { 00366 if ( url.isLocalFile() ) title = url.fileName(); 00367 else title = url.prettyURL(); 00368 } else { 00369 title = i18n("New Calendar"); 00370 } 00371 00372 if ( mCalendarView->isReadOnly() ) { 00373 title += " [" + i18n("read-only") + "]"; 00374 } 00375 00376 setCaption( title, !mCalendarView->isReadOnly() && 00377 mCalendarView->isModified() ); 00378 } 00379 00380 void KOrganizer::configureKeyBindings() 00381 { 00382 KKeyDialog::configure( actionCollection(), this ); 00383 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:26 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003