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   // Set this to be the group leader for all subdialogs - this means
00096   // modal subdialogs will only affect this dialog, not the other windows
00097   setWFlags( getWFlags() | WGroupLeader );
00098 
00099   kdDebug(5850) << "KOrganizer::KOrganizer()" << endl;
00100   KOCore::self()->setXMLGUIClient( this );
00101 //  setMinimumSize(600,400);  // make sure we don't get resized too small...
00102 
00103   mCalendarView = new CalendarView( this, "KOrganizer::CalendarView" );
00104   setCentralWidget(mCalendarView);
00105 
00106   mActionManager = new ActionManager( this, mCalendarView, this, this, false );
00107   (void)new KOrganizerIfaceImpl( mActionManager, this, "IfaceImpl" );
00108 }
00109 
00110 KOrganizer::~KOrganizer()
00111 {
00112   delete mActionManager;
00113 }
00114 
00115 void KOrganizer::init( bool document )
00116 {
00117   kdDebug() << "KOrganizer::init() "
00118             << ( document ? "hasDocument" : "resources" ) << endl;
00119 
00120   setHasDocument( document );
00121 
00122   // Create calendar object, which manages all calendar information associated
00123   // with this calendar view window.
00124   if ( hasDocument() ) {
00125     mActionManager->createCalendarLocal();
00126   } else {
00127     mActionManager->createCalendarResources();
00128     setCaption( i18n("Calendar") );
00129   }
00130 
00131   mActionManager->init();
00132   connect( mActionManager, SIGNAL( actionNew( const KURL & ) ),
00133            SLOT( newMainWindow( const KURL & ) ) );
00134   connect( mActionManager, SIGNAL( actionKeyBindings() ),
00135            SLOT( configureKeyBindings() ) );
00136 
00137   mActionManager->loadParts();
00138 
00139   initActions();
00140   readSettings();
00141 
00142   KStatusBar *bar = statusBar();
00143 
00144   bar->insertItem( "", ID_GENERAL, 10 );
00145 
00146   bar->insertItem( i18n(" Incoming messages: %1 ").arg( 0 ), ID_MESSAGES_IN );
00147   bar->insertItem( i18n(" Outgoing messages: %2 ").arg( 0 ), ID_MESSAGES_OUT );
00148   bar->setItemAlignment( ID_MESSAGES_IN, AlignRight );
00149   bar->setItemAlignment( ID_MESSAGES_OUT, AlignRight );
00150   connect( bar, SIGNAL( pressed( int ) ), SLOT( statusBarPressed( int ) ) );
00151 
00152   KPIM::ProgressDialog *progressDialog = new KPIM::ProgressDialog( bar, this );
00153   progressDialog->hide();
00154 
00155   KPIM::StatusbarProgressWidget *progressWidget;
00156   progressWidget = new KPIM::StatusbarProgressWidget( progressDialog, bar );
00157   progressWidget->show();
00158 
00159   bar->addWidget( progressWidget, 0, true );
00160 
00161   connect( mActionManager->view(), SIGNAL( numIncomingChanged( int ) ),
00162            SLOT( setNumIncoming( int ) ) );
00163   connect( mActionManager->view(), SIGNAL( numOutgoingChanged( int ) ),
00164            SLOT( setNumOutgoing( int ) ) );
00165 
00166   connect( mActionManager->view(), SIGNAL( statusMessage( const QString & ) ),
00167            SLOT( showStatusMessage( const QString & ) ) );
00168 
00169   setStandardToolBarMenuEnabled( true );
00170 
00171   kdDebug(5850) << "KOrganizer::KOrganizer() done" << endl;
00172 }
00173 
00174 void KOrganizer::newMainWindow( const KURL &url )
00175 {
00176   KOrganizer *korg = new KOrganizer();
00177   if ( url.isValid() || url.isEmpty() ) {
00178     korg->init( true );
00179     if ( korg->openURL( url ) || url.isEmpty() ) {
00180       korg->show();
00181     } else {
00182       delete korg;
00183     }
00184   } else {
00185     korg->init( false );
00186     korg->show();
00187   }
00188 }
00189 
00190 void KOrganizer::readSettings()
00191 {
00192   // read settings from the KConfig, supplying reasonable
00193   // defaults where none are to be found
00194 
00195   KConfig *config = KOGlobals::self()->config();
00196 
00197   config->setGroup( "KOrganizer Geometry" );
00198 
00199   int windowWidth = config->readNumEntry( "Width", 600 );
00200   int windowHeight = config->readNumEntry( "Height", 400 );
00201 
00202   resize( windowWidth, windowHeight );
00203 
00204   mActionManager->readSettings();
00205 
00206   config->sync();
00207 }
00208 
00209 
00210 void KOrganizer::writeSettings()
00211 {
00212   kdDebug(5850) << "KOrganizer::writeSettings" << endl;
00213 
00214   KConfig *config = KOGlobals::self()->config();
00215 
00216   config->setGroup( "KOrganizer Geometry" );
00217   config->writeEntry( "Width",width() );
00218   config->writeEntry( "Height",height() );
00219 
00220   mActionManager->writeSettings();
00221   saveMainWindowSettings( config );
00222   config->sync();
00223 }
00224 
00225 
00226 void KOrganizer::initActions()
00227 {
00228   KStdAction::quit( this, SLOT( close() ), actionCollection() );
00229   mStatusBarAction = KStdAction::showStatusbar( this, SLOT( toggleStatusBar() ),
00230                                                 actionCollection() );
00231 
00232   KStdAction::configureToolbars( this, SLOT( configureToolbars() ),
00233                                  actionCollection() );
00234 
00235   setInstance( KGlobal::instance() );
00236 
00237   setXMLFile( "korganizerui.rc" );
00238   createGUI( 0 );
00239 
00240   KConfig *config = KOGlobals::self()->config();
00241 
00242   applyMainWindowSettings( config );
00243 
00244   mStatusBarAction->setChecked( !statusBar()->isHidden() );
00245 }
00246 
00247 #if 0
00248 void KOrganizer::initViews()
00249 {
00250   kdDebug(5850) << "KOrganizer::initViews()" << endl;
00251 
00252   // TODO: get calendar pointer from somewhere
00253   KOrg::View::List views = KOCore::self()->views( this );
00254   KOrg::View *it;
00255   for( it = views.first(); it; it = views.next() ) {
00256     guiFactory()->addClient( it );
00257   }
00258 }
00259 #endif
00260 
00261 bool KOrganizer::queryClose()
00262 {
00263   kdDebug(5850) << "KOrganizer::queryClose()" << endl;
00264 
00265   bool close = mActionManager->queryClose();
00266 
00267   // Write configuration. I don't know if it really makes sense doing it this
00268   // way, when having opened multiple calendars in different CalendarViews.
00269   if ( close ) writeSettings();
00270 
00271   return close;
00272 }
00273 
00274 bool KOrganizer::queryExit()
00275 {
00276   // Don't call writeSettings here, because filename isn't valid anymore. It is
00277   // now called in queryClose.
00278 //  writeSettings();
00279   return true;
00280 }
00281 
00282 void KOrganizer::configureToolbars()
00283 {
00284   saveMainWindowSettings( KOGlobals::self()->config(), "MainWindow" );
00285 
00286   KEditToolbar dlg( factory() );
00287   dlg.exec();
00288 }
00289 
00290 void KOrganizer::toggleStatusBar()
00291 {
00292   bool show_statusbar = mStatusBarAction->isChecked();
00293   if (show_statusbar)
00294      statusBar()->show();
00295   else
00296      statusBar()->hide();
00297 }
00298 
00299 void KOrganizer::statusBarPressed( int id )
00300 {
00301   if ( id == ID_MESSAGES_IN )
00302     mCalendarView->dialogManager()->showIncomingDialog();
00303   else if ( id == ID_MESSAGES_OUT )
00304     mCalendarView->dialogManager()->showOutgoingDialog();
00305 }
00306 
00307 void KOrganizer::setNumIncoming( int num )
00308 {
00309   statusBar()->changeItem( i18n(" Incoming messages: %1 ").arg( num ),
00310                            ID_MESSAGES_IN);
00311 }
00312 
00313 void KOrganizer::setNumOutgoing( int num )
00314 {
00315   statusBar()->changeItem( i18n(" Outgoing messages: %1 ").arg( num ),
00316                            ID_MESSAGES_OUT );
00317 }
00318 
00319 void KOrganizer::showStatusMessage( const QString &message )
00320 {
00321   statusBar()->message(message,2000);
00322 }
00323 
00324 bool KOrganizer::openURL( const KURL &url, bool merge )
00325 {
00326   return mActionManager->openURL( url, merge );
00327 }
00328 
00329 bool KOrganizer::saveURL()
00330 {
00331   return mActionManager->saveURL();
00332 }
00333 
00334 bool KOrganizer::saveAsURL( const KURL & kurl )
00335 {
00336   return mActionManager->saveAsURL( kurl )  ;
00337 }
00338 
00339 KURL KOrganizer::getCurrentURL() const
00340 {
00341   return mActionManager->url();
00342 }
00343 
00344 void KOrganizer::saveProperties( KConfig *config )
00345 {
00346   return mActionManager->saveProperties( config );
00347 }
00348 
00349 void KOrganizer::readProperties( KConfig *config )
00350 {
00351   return mActionManager->readProperties( config );
00352 }
00353 
00354 KOrg::CalendarViewBase *KOrganizer::view() const
00355 {
00356   return mActionManager->view();
00357 }
00358 
00359 void KOrganizer::setTitle()
00360 {
00361 //  kdDebug(5850) << "KOrganizer::setTitle" << endl;
00362 
00363   if ( !hasDocument() ) return;
00364 
00365   QString title;
00366 
00367   KURL url = mActionManager->url();
00368 
00369   if ( !url.isEmpty() ) {
00370     if ( url.isLocalFile() ) title = url.fileName();
00371     else title = url.prettyURL();
00372   } else {
00373     title = i18n("New Calendar");
00374   }
00375 
00376   if ( mCalendarView->isReadOnly() ) {
00377     title += " [" + i18n("read-only") + "]";
00378   }
00379 
00380   setCaption( title, !mCalendarView->isReadOnly() &&
00381                       mCalendarView->isModified() );
00382 }
00383 
00384 void KOrganizer::configureKeyBindings()
00385 {
00386   KKeyDialog::configure( actionCollection(), this );
00387 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu May 3 20:24:57 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003