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 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 00012 00013 This program is free software; you can redistribute it and/or modify 00014 it under the terms of the GNU General Public License as published by 00015 the Free Software Foundation; either version 2 of the License, or 00016 (at your option) any later version. 00017 00018 This program is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 along with this program; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00026 00027 As a special exception, permission is given to link this program 00028 with any edition of TQt, and distribute the resulting executable, 00029 without including the source code for TQt in the source distribution. 00030 */ 00031 00032 #include "korganizer.h" 00033 00034 #include "komailclient.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 00057 #include <kglobal.h> 00058 #include <kdebug.h> 00059 #include <kiconloader.h> 00060 #include <kstandarddirs.h> 00061 #include <kstdaccel.h> 00062 #include <kfiledialog.h> 00063 #include <kaction.h> 00064 #include <kstdaction.h> 00065 #include <kedittoolbar.h> 00066 #include <ktempfile.h> 00067 #include <kio/netaccess.h> 00068 #include <kmessagebox.h> 00069 #include <dcopclient.h> 00070 #include <kprocess.h> 00071 #include <kwin.h> 00072 #include <ktip.h> 00073 #include <kstdguiitem.h> 00074 #include <kstatusbar.h> 00075 00076 #include <tqcursor.h> 00077 #include <tqtimer.h> 00078 #include <tqvbox.h> 00079 #include <tqfile.h> 00080 #include <tqlabel.h> 00081 #include <tqlayout.h> 00082 00083 #include <stdlib.h> 00084 00085 using namespace KParts; 00086 #include "korganizer.moc" 00087 using namespace KOrg; 00088 00089 KOrganizer::KOrganizer( const char *name ) 00090 : KParts::MainWindow( 0, name ), 00091 KOrg::MainWindow() 00092 { 00093 // Set this to be the group leader for all subdialogs - this means 00094 // modal subdialogs will only affect this dialog, not the other windows 00095 setWFlags( getWFlags() | WGroupLeader ); 00096 00097 kdDebug(5850) << "KOrganizer::KOrganizer()" << endl; 00098 KOCore::self()->addXMLGUIClient( this, this ); 00099 // setMinimumSize(600,400); // make sure we don't get resized too small... 00100 00101 mCalendarView = new CalendarView( this, "KOrganizer::CalendarView" ); 00102 setCentralWidget(mCalendarView); 00103 00104 mActionManager = new ActionManager( this, mCalendarView, TQT_TQOBJECT(this), this, false ); 00105 (void)new KOrganizerIfaceImpl( mActionManager, TQT_TQOBJECT(this), "IfaceImpl" ); 00106 } 00107 00108 KOrganizer::~KOrganizer() 00109 { 00110 delete mActionManager; 00111 00112 KOCore::self()->removeXMLGUIClient( this ); 00113 } 00114 00115 void KOrganizer::init( bool document ) 00116 { 00117 kdDebug(5850) << "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 } 00129 00130 mActionManager->init(); 00131 connect( mActionManager, TQT_SIGNAL( actionNew( const KURL & ) ), 00132 TQT_SLOT( newMainWindow( const KURL & ) ) ); 00133 00134 mActionManager->loadParts(); 00135 00136 initActions(); 00137 readSettings(); 00138 00139 KStatusBar *bar = statusBar(); 00140 00141 bar->insertItem( "", ID_GENERAL, 10 ); 00142 connect( bar, TQT_SIGNAL( pressed( int ) ), TQT_SLOT( statusBarPressed( int ) ) ); 00143 00144 KPIM::ProgressDialog *progressDialog = new KPIM::ProgressDialog( bar, this ); 00145 progressDialog->hide(); 00146 00147 KPIM::StatusbarProgressWidget *progressWidget; 00148 progressWidget = new KPIM::StatusbarProgressWidget( progressDialog, bar ); 00149 progressWidget->show(); 00150 00151 bar->addWidget( progressWidget, 0, true ); 00152 00153 connect( mActionManager->view(), TQT_SIGNAL( statusMessage( const TQString & ) ), 00154 TQT_SLOT( showStatusMessage( const TQString & ) ) ); 00155 00156 setStandardToolBarMenuEnabled( true ); 00157 setTitle(); 00158 00159 kdDebug(5850) << "KOrganizer::KOrganizer() done" << endl; 00160 } 00161 00162 void KOrganizer::newMainWindow( const KURL &url ) 00163 { 00164 KOrganizer *korg = new KOrganizer(); 00165 if ( url.isValid() || url.isEmpty() ) { 00166 korg->init( true ); 00167 if ( korg->openURL( url ) || url.isEmpty() ) { 00168 korg->show(); 00169 } else { 00170 delete korg; 00171 } 00172 } else { 00173 korg->init( false ); 00174 korg->show(); 00175 } 00176 } 00177 00178 void KOrganizer::readSettings() 00179 { 00180 // read settings from the KConfig, supplying reasonable 00181 // defaults where none are to be found 00182 00183 KConfig *config = KOGlobals::self()->config(); 00184 00185 mActionManager->readSettings(); 00186 00187 config->sync(); 00188 } 00189 00190 00191 void KOrganizer::writeSettings() 00192 { 00193 kdDebug(5850) << "KOrganizer::writeSettings" << endl; 00194 00195 KConfig *config = KOGlobals::self()->config(); 00196 00197 mActionManager->writeSettings(); 00198 config->sync(); 00199 } 00200 00201 00202 void KOrganizer::initActions() 00203 { 00204 00205 setInstance( KGlobal::instance() ); 00206 00207 setXMLFile( "korganizerui.rc" ); 00208 setStandardToolBarMenuEnabled( true ); 00209 createStandardStatusBarAction(); 00210 00211 KStdAction::keyBindings(guiFactory(), TQT_SLOT(configureShortcuts()), actionCollection()); 00212 KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(configureToolbars() ), actionCollection()); 00213 KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT( close() ), actionCollection() ); 00214 setAutoSaveSettings(); 00215 00216 createGUI( 0 ); 00217 } 00218 00219 bool KOrganizer::queryClose() 00220 { 00221 kdDebug(5850) << "KOrganizer::queryClose()" << endl; 00222 00223 bool close = mActionManager->queryClose(); 00224 00225 // Write configuration. I don't know if it really makes sense doing it this 00226 // way, when having opened multiple calendars in different CalendarViews. 00227 if ( close ) writeSettings(); 00228 00229 return close; 00230 } 00231 00232 bool KOrganizer::queryExit() 00233 { 00234 // Don't call writeSettings here, because filename isn't valid anymore. It is 00235 // now called in queryClose. 00236 // writeSettings(); 00237 return true; 00238 } 00239 00240 void KOrganizer::statusBarPressed( int /*id*/ ) 00241 { 00242 } 00243 00244 void KOrganizer::showStatusMessage( const TQString &message ) 00245 { 00246 statusBar()->message(message,2000); 00247 } 00248 00249 bool KOrganizer::openURL( const KURL &url, bool merge ) 00250 { 00251 return mActionManager->openURL( url, merge ); 00252 } 00253 00254 bool KOrganizer::saveURL() 00255 { 00256 return mActionManager->saveURL(); 00257 } 00258 00259 bool KOrganizer::saveAsURL( const KURL & kurl ) 00260 { 00261 return mActionManager->saveAsURL( kurl ) ; 00262 } 00263 00264 KURL KOrganizer::getCurrentURL() const 00265 { 00266 return mActionManager->url(); 00267 } 00268 00269 void KOrganizer::saveProperties( KConfig *config ) 00270 { 00271 return mActionManager->saveProperties( config ); 00272 } 00273 00274 void KOrganizer::readProperties( KConfig *config ) 00275 { 00276 return mActionManager->readProperties( config ); 00277 } 00278 00279 KOrg::CalendarViewBase *KOrganizer::view() const 00280 { 00281 return mActionManager->view(); 00282 } 00283 00284 void KOrganizer::setTitle() 00285 { 00286 // kdDebug(5850) << "KOrganizer::setTitle" << endl; 00287 00288 TQString title; 00289 if ( !hasDocument() ) { 00290 title = i18n("Calendar"); 00291 } else { 00292 KURL url = mActionManager->url(); 00293 00294 if ( !url.isEmpty() ) { 00295 if ( url.isLocalFile() ) title = url.fileName(); 00296 else title = url.prettyURL(); 00297 } else { 00298 title = i18n("New Calendar"); 00299 } 00300 00301 if ( mCalendarView->isReadOnly() ) { 00302 title += " [" + i18n("read-only") + "]"; 00303 } 00304 } 00305 00306 title += " - <" + mCalendarView->currentFilterName() + "> "; 00307 00308 setCaption( title, !mCalendarView->isReadOnly() && 00309 mCalendarView->isModified() ); 00310 } 00311 00312 bool KOrganizer::isCurrentlyActivePart() 00313 { 00314 return false; 00315 } 00316