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 "kogroupware.h" 00047 00048 #include <korganizer/part.h> 00049 00050 #include <libkcal/calendarlocal.h> 00051 #include <libkcal/calendarresources.h> 00052 #include <libkcal/resourcecalendar.h> 00053 #include <libkcal/resourcelocal.h> 00054 00055 #include <kglobal.h> 00056 #include <kdebug.h> 00057 #include <kiconloader.h> 00058 #include <kstandarddirs.h> 00059 #include <kstdaccel.h> 00060 #include <kfiledialog.h> 00061 #include <kaction.h> 00062 #include <kstdaction.h> 00063 #include <kedittoolbar.h> 00064 #include <ktempfile.h> 00065 #include <kio/netaccess.h> 00066 #include <kmessagebox.h> 00067 #include <dcopclient.h> 00068 #include <kprocess.h> 00069 #include <kwin.h> 00070 #include <kkeydialog.h> 00071 #include <ktip.h> 00072 #include <kstdguiitem.h> 00073 00074 #include <qcursor.h> 00075 #include <qtimer.h> 00076 #include <qvbox.h> 00077 #include <qfile.h> 00078 #include <qlabel.h> 00079 00080 #include <stdlib.h> 00081 00082 using namespace KParts; 00083 #include "korganizer.moc" 00084 using namespace KOrg; 00085 00086 KOrganizer::KOrganizer( const char *name ) 00087 : DCOPObject( "KOrganizerIface" ), 00088 KParts::MainWindow( 0, name ), 00089 KOrg::MainWindow() 00090 { 00091 kdDebug(5850) << "KOrganizer::KOrganizer()" << endl; 00092 KOCore::self()->setXMLGUIClient( this ); 00093 // setMinimumSize(600,400); // make sure we don't get resized too small... 00094 00095 mCalendarView = new CalendarView( this, "KOrganizer::CalendarView" ); 00096 setCentralWidget(mCalendarView); 00097 00098 mActionManager = new ActionManager( this, mCalendarView, this, this, false ); 00099 } 00100 00101 KOrganizer::~KOrganizer() 00102 { 00103 delete mActionManager; 00104 } 00105 00106 void KOrganizer::init( bool document ) 00107 { 00108 kdDebug() << "KOrganizer::init() " 00109 << ( document ? "hasDocument" : "resources" ) << endl; 00110 00111 setHasDocument( document ); 00112 00113 // Create calendar object, which manages all calendar information associated 00114 // with this calendar view window. 00115 if ( hasDocument() ) { 00116 mActionManager->createCalendarLocal(); 00117 } else { 00118 mActionManager->createCalendarResources(); 00119 setCaption( i18n("Calendar") ); 00120 } 00121 00122 mActionManager->init(); 00123 connect( mActionManager, SIGNAL( actionNew( const KURL & ) ), 00124 SLOT( newMainWindow( const KURL & ) ) ); 00125 connect( mActionManager, SIGNAL( actionKeyBindings() ), 00126 SLOT( configureKeyBindings() ) ); 00127 00128 mActionManager->loadParts(); 00129 00130 initActions(); 00131 readSettings(); 00132 00133 statusBar()->insertItem( "", ID_GENERAL, 10 ); 00134 00135 statusBar()->insertItem( i18n(" Incoming messages: %1 ").arg( 0 ), 00136 ID_MESSAGES_IN ); 00137 statusBar()->insertItem( i18n(" Outgoing messages: %2 ").arg( 0 ), 00138 ID_MESSAGES_OUT ); 00139 statusBar()->setItemAlignment( ID_MESSAGES_IN, AlignRight ); 00140 statusBar()->setItemAlignment( ID_MESSAGES_OUT, AlignRight ); 00141 connect( statusBar(), SIGNAL( pressed( int ) ), 00142 SLOT( statusBarPressed( int ) ) ); 00143 00144 connect( mActionManager->view(), SIGNAL( numIncomingChanged( int ) ), 00145 SLOT( setNumIncoming( int ) ) ); 00146 connect( mActionManager->view(), SIGNAL( numOutgoingChanged( int ) ), 00147 SLOT( setNumOutgoing( int ) ) ); 00148 00149 connect( mActionManager->view(), SIGNAL( statusMessage( const QString & ) ), 00150 SLOT( showStatusMessage( const QString & ) ) ); 00151 00152 setStandardToolBarMenuEnabled( true ); 00153 00154 kdDebug(5850) << "KOrganizer::KOrganizer() done" << endl; 00155 } 00156 00157 void KOrganizer::newMainWindow( const KURL &url ) 00158 { 00159 KOrganizer *korg = new KOrganizer(); 00160 if ( url.isValid() || url.isEmpty() ) { 00161 korg->init( true ); 00162 if ( korg->openURL( url ) || url.isEmpty() ) { 00163 korg->show(); 00164 } else { 00165 delete korg; 00166 } 00167 } else { 00168 korg->init( false ); 00169 korg->show(); 00170 } 00171 } 00172 00173 void KOrganizer::readSettings() 00174 { 00175 // read settings from the KConfig, supplying reasonable 00176 // defaults where none are to be found 00177 00178 KConfig *config = KOGlobals::self()->config(); 00179 00180 config->setGroup( "KOrganizer Geometry" ); 00181 00182 int windowWidth = config->readNumEntry( "Width", 600 ); 00183 int windowHeight = config->readNumEntry( "Height", 400 ); 00184 00185 resize( windowWidth, windowHeight ); 00186 00187 mActionManager->readSettings(); 00188 00189 config->sync(); 00190 } 00191 00192 00193 void KOrganizer::writeSettings() 00194 { 00195 kdDebug(5850) << "KOrganizer::writeSettings" << endl; 00196 00197 KConfig *config = KOGlobals::self()->config(); 00198 00199 config->setGroup( "KOrganizer Geometry" ); 00200 config->writeEntry( "Width",width() ); 00201 config->writeEntry( "Height",height() ); 00202 00203 mActionManager->writeSettings(); 00204 saveMainWindowSettings( config ); 00205 config->sync(); 00206 } 00207 00208 00209 void KOrganizer::initActions() 00210 { 00211 KStdAction::quit( this, SLOT( close() ), actionCollection() ); 00212 mStatusBarAction = KStdAction::showStatusbar( this, SLOT( toggleStatusBar() ), 00213 actionCollection() ); 00214 00215 KStdAction::configureToolbars( this, SLOT( configureToolbars() ), 00216 actionCollection() ); 00217 00218 setInstance( KGlobal::instance() ); 00219 00220 setXMLFile( "korganizerui.rc" ); 00221 createGUI( 0 ); 00222 00223 KConfig *config = KOGlobals::self()->config(); 00224 00225 applyMainWindowSettings( config ); 00226 00227 mStatusBarAction->setChecked( !statusBar()->isHidden() ); 00228 } 00229 00230 #if 0 00231 void KOrganizer::initViews() 00232 { 00233 kdDebug(5850) << "KOrganizer::initViews()" << endl; 00234 00235 // TODO: get calendar pointer from somewhere 00236 KOrg::View::List views = KOCore::self()->views( this ); 00237 KOrg::View *it; 00238 for( it = views.first(); it; it = views.next() ) { 00239 guiFactory()->addClient( it ); 00240 } 00241 } 00242 #endif 00243 00244 bool KOrganizer::queryClose() 00245 { 00246 kdDebug(5850) << "KOrganizer::queryClose()" << endl; 00247 00248 bool close = mActionManager->queryClose(); 00249 00250 // Write configuration. I don't know if it really makes sense doing it this 00251 // way, when having opened multiple calendars in different CalendarViews. 00252 if ( close ) writeSettings(); 00253 00254 return close; 00255 } 00256 00257 bool KOrganizer::queryExit() 00258 { 00259 // Don't call writeSettings here, because filename isn't valid anymore. It is 00260 // now called in queryClose. 00261 // writeSettings(); 00262 return true; 00263 } 00264 00265 void KOrganizer::configureToolbars() 00266 { 00267 saveMainWindowSettings( KOGlobals::self()->config(), "MainWindow" ); 00268 00269 KEditToolbar dlg( factory() ); 00270 dlg.exec(); 00271 } 00272 00273 void KOrganizer::toggleStatusBar() 00274 { 00275 bool show_statusbar = mStatusBarAction->isChecked(); 00276 if (show_statusbar) 00277 statusBar()->show(); 00278 else 00279 statusBar()->hide(); 00280 } 00281 00282 void KOrganizer::statusBarPressed( int id ) 00283 { 00284 if ( id == ID_MESSAGES_IN ) 00285 mCalendarView->dialogManager()->showIncomingDialog(); 00286 else if ( id == ID_MESSAGES_OUT ) 00287 mCalendarView->dialogManager()->showOutgoingDialog(); 00288 } 00289 00290 void KOrganizer::setNumIncoming( int num ) 00291 { 00292 statusBar()->changeItem( i18n(" Incoming messages: %1 ").arg( num ), 00293 ID_MESSAGES_IN); 00294 } 00295 00296 void KOrganizer::setNumOutgoing( int num ) 00297 { 00298 statusBar()->changeItem( i18n(" Outgoing messages: %1 ").arg( num ), 00299 ID_MESSAGES_OUT ); 00300 } 00301 00302 void KOrganizer::showStatusMessage( const QString &message ) 00303 { 00304 statusBar()->message(message,2000); 00305 } 00306 00307 bool KOrganizer::openURL( const KURL &url, bool merge ) 00308 { 00309 return mActionManager->openURL( url, merge ); 00310 } 00311 00312 bool KOrganizer::saveURL() 00313 { 00314 return mActionManager->saveURL(); 00315 } 00316 00317 bool KOrganizer::saveAsURL( const KURL & kurl ) 00318 { 00319 return mActionManager->saveAsURL( kurl ) ; 00320 } 00321 00322 KURL KOrganizer::getCurrentURL() const 00323 { 00324 return mActionManager->url(); 00325 } 00326 00327 void KOrganizer::saveProperties( KConfig *config ) 00328 { 00329 return mActionManager->saveProperties( config ); 00330 } 00331 00332 void KOrganizer::readProperties( KConfig *config ) 00333 { 00334 return mActionManager->readProperties( config ); 00335 } 00336 00337 bool KOrganizer::deleteEvent( QString uid ) 00338 { 00339 return mActionManager->deleteEvent( uid ); 00340 } 00341 00342 bool KOrganizer::eventRequest( QString request, QCString receiver, 00343 QString ical ) 00344 { 00345 return mActionManager->eventRequest( request, receiver, ical ); 00346 } 00347 00348 bool KOrganizer::eventReply( QString ical ) 00349 { 00350 return mActionManager->eventReply( ical ); 00351 } 00352 00353 KOrg::CalendarViewBase *KOrganizer::view() const 00354 { 00355 return mActionManager->view(); 00356 } 00357 00358 void KOrganizer::setTitle() 00359 { 00360 // kdDebug(5850) << "KOrganizer::setTitle" << endl; 00361 00362 if ( !hasDocument() ) return; 00363 00364 QString title; 00365 00366 KURL url = mActionManager->url(); 00367 00368 if ( !url.isEmpty() ) { 00369 if ( url.isLocalFile() ) title = url.fileName(); 00370 else title = url.prettyURL(); 00371 } else { 00372 title = i18n("New Calendar"); 00373 } 00374 00375 if ( mCalendarView->isReadOnly() ) { 00376 title += " [" + i18n("read-only") + "]"; 00377 } 00378 00379 setCaption( title, !mCalendarView->isReadOnly() && 00380 mCalendarView->isModified() ); 00381 } 00382 00383 QString KOrganizer::getCurrentURLasString() const 00384 { 00385 return mActionManager->getCurrentURLasString(); 00386 } 00387 00388 void KOrganizer::closeURL() 00389 { 00390 return mActionManager->closeURL(); 00391 } 00392 00393 bool KOrganizer::openURL( QString url ) 00394 { 00395 return mActionManager->openURL( url ); 00396 } 00397 00398 bool KOrganizer::mergeURL( QString url ) 00399 { 00400 return mActionManager->mergeURL( url ); 00401 } 00402 00403 bool KOrganizer::saveAsURL( QString url ) 00404 { 00405 return mActionManager->saveAsURL( url ); 00406 } 00407 00408 void KOrganizer::configureKeyBindings() 00409 { 00410 KKeyDialog::configure( actionCollection(), this ); 00411 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:14 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003