korganizer

korganizer.cpp
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 1997, 1998, 1999
5  Preston Brown (preston.brown@yale.edu)
6  Fester Zigterman (F.J.F.ZigtermanRustenburg@student.utwente.nl)
7  Ian Dawes (iadawes@globalserve.net)
8  Laszlo Boloni (boloni@cs.purdue.edu)
9 
10  Copyright (c) 2000-2003 Cornelius Schumacher <schumacher@kde.org>
11  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
12 
13  This program is free software; you can redistribute it and/or modify
14  it under the terms of the GNU General Public License as published by
15  the Free Software Foundation; either version 2 of the License, or
16  (at your option) any later version.
17 
18  This program is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 
27  As a special exception, permission is given to link this program
28  with any edition of TQt, and distribute the resulting executable,
29  without including the source code for TQt in the source distribution.
30 */
31 
32 #include "korganizer.h"
33 
34 #include "komailclient.h"
35 #include "calendarview.h"
36 #include "koviewmanager.h"
37 #include "kodialogmanager.h"
38 #include "kowindowlist.h"
39 #include "koprefs.h"
40 #include "kocore.h"
41 #include "konewstuff.h"
42 #include "actionmanager.h"
43 #include "koglobals.h"
44 #include "alarmclient.h"
45 #include "resourceview.h"
46 #include "korganizerifaceimpl.h"
47 
48 #include <korganizer/part.h>
49 
50 #include <libtdepim/statusbarprogresswidget.h>
51 #include <libtdepim/progressdialog.h>
52 
53 #include <libkcal/calendarlocal.h>
55 #include <libkcal/resourcecalendar.h>
56 
57 #include <tdeglobal.h>
58 #include <kdebug.h>
59 #include <kiconloader.h>
60 #include <kstandarddirs.h>
61 #include <tdestdaccel.h>
62 #include <tdefiledialog.h>
63 #include <tdeaction.h>
64 #include <kstdaction.h>
65 #include <kedittoolbar.h>
66 #include <tdetempfile.h>
67 #include <tdeio/netaccess.h>
68 #include <tdemessagebox.h>
69 #include <dcopclient.h>
70 #include <tdeprocess.h>
71 #include <twin.h>
72 #include <ktip.h>
73 #include <kstdguiitem.h>
74 #include <kstatusbar.h>
75 
76 #include <tqcursor.h>
77 #include <tqtimer.h>
78 #include <tqvbox.h>
79 #include <tqfile.h>
80 #include <tqlabel.h>
81 #include <tqlayout.h>
82 
83 #include <stdlib.h>
84 
85 using namespace KParts;
86 #include "korganizer.moc"
87 using namespace KOrg;
88 
89 KOrganizer::KOrganizer( const char *name )
90  : KParts::MainWindow( 0, name ),
91  KOrg::MainWindow()
92 {
93  // Set this to be the group leader for all subdialogs - this means
94  // modal subdialogs will only affect this dialog, not the other windows
95  setWFlags( getWFlags() | WGroupLeader );
96 
97  kdDebug(5850) << "KOrganizer::KOrganizer()" << endl;
98  KOCore::self()->addXMLGUIClient( this, this );
99 // setMinimumSize(600,400); // make sure we don't get resized too small...
100 
101  mCalendarView = new CalendarView( this, "KOrganizer::CalendarView" );
102  setCentralWidget(mCalendarView);
103 
104  mActionManager = new ActionManager( this, mCalendarView, this, this, false );
105  (void)new KOrganizerIfaceImpl( mActionManager, this, "IfaceImpl" );
106 }
107 
108 KOrganizer::~KOrganizer()
109 {
110  delete mActionManager;
111 
112  KOCore::self()->removeXMLGUIClient( this );
113 }
114 
115 void KOrganizer::init( bool document )
116 {
117  kdDebug(5850) << "KOrganizer::init() "
118  << ( document ? "hasDocument" : "resources" ) << endl;
119 
120  setHasDocument( document );
121 
122  // Create calendar object, which manages all calendar information associated
123  // with this calendar view window.
124  if ( hasDocument() ) {
125  mActionManager->createCalendarLocal();
126  } else {
127  mActionManager->createCalendarResources();
128  }
129 
130  mActionManager->init();
131  connect( mActionManager, TQ_SIGNAL( actionNew( const KURL & ) ),
132  TQ_SLOT( newMainWindow( const KURL & ) ) );
133 
134  mActionManager->loadParts();
135 
136  initActions();
137  readSettings();
138 
139  KStatusBar *bar = statusBar();
140 
141  bar->insertItem( "", ID_GENERAL, 10 );
142  connect( bar, TQ_SIGNAL( pressed( int ) ), TQ_SLOT( statusBarPressed( int ) ) );
143 
144  KPIM::ProgressDialog *progressDialog = new KPIM::ProgressDialog( bar, this );
145  progressDialog->hide();
146 
147  KPIM::StatusbarProgressWidget *progressWidget;
148  progressWidget = new KPIM::StatusbarProgressWidget( progressDialog, bar );
149  progressWidget->show();
150 
151  bar->addWidget( progressWidget, 0, true );
152 
153  connect( mActionManager->view(), TQ_SIGNAL( statusMessage( const TQString & ) ),
154  TQ_SLOT( showStatusMessage( const TQString & ) ) );
155 
156  setStandardToolBarMenuEnabled( true );
157  setTitle();
158 
159  kdDebug(5850) << "KOrganizer::KOrganizer() done" << endl;
160 }
161 
162 void KOrganizer::newMainWindow( const KURL &url )
163 {
164  KOrganizer *korg = new KOrganizer();
165  if ( url.isValid() || url.isEmpty() ) {
166  korg->init( true );
167  if ( korg->openURL( url ) || url.isEmpty() ) {
168  korg->show();
169  } else {
170  delete korg;
171  }
172  } else {
173  korg->init( false );
174  korg->show();
175  }
176 }
177 
179 {
180  // read settings from the TDEConfig, supplying reasonable
181  // defaults where none are to be found
182 
183  TDEConfig *config = KOGlobals::self()->config();
184 
185  mActionManager->readSettings();
186 
187  config->sync();
188 }
189 
190 
192 {
193  kdDebug(5850) << "KOrganizer::writeSettings" << endl;
194 
195  TDEConfig *config = KOGlobals::self()->config();
196 
197  mActionManager->writeSettings();
198  config->sync();
199 }
200 
201 
202 void KOrganizer::initActions()
203 {
204 
205  setInstance( TDEGlobal::instance() );
206 
207  setXMLFile( "korganizerui.rc" );
208  setStandardToolBarMenuEnabled( true );
209  createStandardStatusBarAction();
210 
211  KStdAction::keyBindings(guiFactory(), TQ_SLOT(configureShortcuts()), actionCollection());
212  KStdAction::configureToolbars(this, TQ_SLOT(configureToolbars() ), actionCollection());
213  KStdAction::quit( this, TQ_SLOT( close() ), actionCollection() );
214  setAutoSaveSettings();
215 
216  createGUI( 0 );
217 }
218 
220 {
221  kdDebug(5850) << "KOrganizer::queryClose()" << endl;
222 
223  bool close = mActionManager->queryClose();
224 
225  // Write configuration. I don't know if it really makes sense doing it this
226  // way, when having opened multiple calendars in different CalendarViews.
227  if ( close ) writeSettings();
228 
229  return close;
230 }
231 
232 bool KOrganizer::queryExit()
233 {
234  // Don't call writeSettings here, because filename isn't valid anymore. It is
235  // now called in queryClose.
236 // writeSettings();
237  return true;
238 }
239 
240 void KOrganizer::statusBarPressed( int /*id*/ )
241 {
242 }
243 
244 void KOrganizer::showStatusMessage( const TQString &message )
245 {
246  statusBar()->message(message,2000);
247 }
248 
249 bool KOrganizer::openURL( const KURL &url, bool merge )
250 {
251  return mActionManager->openURL( url, merge );
252 }
253 
255 {
256  return mActionManager->saveURL();
257 }
258 
259 bool KOrganizer::saveAsURL( const KURL & kurl )
260 {
261  return mActionManager->saveAsURL( kurl ) ;
262 }
263 
265 {
266  return mActionManager->url();
267 }
268 
269 void KOrganizer::saveProperties( TDEConfig *config )
270 {
271  return mActionManager->saveProperties( config );
272 }
273 
274 void KOrganizer::readProperties( TDEConfig *config )
275 {
276  return mActionManager->readProperties( config );
277 }
278 
279 KOrg::CalendarViewBase *KOrganizer::view() const
280 {
281  return mActionManager->view();
282 }
283 
285 {
286 // kdDebug(5850) << "KOrganizer::setTitle" << endl;
287 
288  TQString title;
289  if ( !hasDocument() ) {
290  title = i18n("Calendar");
291  } else {
292  KURL url = mActionManager->url();
293 
294  if ( !url.isEmpty() ) {
295  if ( url.isLocalFile() ) title = url.fileName();
296  else title = url.prettyURL();
297  } else {
298  title = i18n("New Calendar");
299  }
300 
301  if ( mCalendarView->isReadOnly() ) {
302  title += " [" + i18n("read-only") + "]";
303  }
304  }
305 
306  title += " - <" + mCalendarView->currentFilterName() + "> ";
307 
308  setCaption( title, !mCalendarView->isReadOnly() &&
309  mCalendarView->isModified() );
310 }
311 
312 bool KOrganizer::isCurrentlyActivePart()
313 {
314  return false;
315 }
316 
The ActionManager creates all the actions in KOrganizer.
Definition: actionmanager.h:74
bool saveURL()
Save calendar file to URL of current calendar.
void createCalendarResources()
Create Calendar object based on the resource framework and set it on the view.
void createCalendarLocal()
Create Calendar object based on local file and set it on the view.
void readSettings()
Using the TDEConfig associated with the kapp variable, read in the settings from the config file.
void writeSettings()
Write current state to config file.
void init()
Peform initialization that requires this* to be full constructed.
bool saveAsURL(const KURL &kurl)
Save calendar file to URL.
bool openURL(const KURL &url, bool merge=false)
Open calendar file from URL.
KURL url() const
Get current URL.
This is the main calendar widget.
Definition: calendarview.h:82
bool isModified()
query whether or not the calendar is "dirty".
bool isReadOnly()
query if the calendar is read-only.
TQString currentFilterName() const
Returns the name of the current filter.
interface for main calendar view widget
interface for korganizer main window
Definition: mainwindow.h:41
This is the main class for KOrganizer.
Definition: korganizer.h:66
bool queryClose()
supplied so that close events close calendar properly.
Definition: korganizer.cpp:219
bool openURL(const KURL &url, bool merge=false)
Open calendar file from URL.
Definition: korganizer.cpp:249
void writeSettings()
write current state to config file.
Definition: korganizer.cpp:191
KOrganizer(const char *name=0)
Constructs a new main window.
Definition: korganizer.cpp:89
bool saveURL()
Save calendar file to URL of current calendar.
Definition: korganizer.cpp:254
KURL getCurrentURL() const
Get current URL.
Definition: korganizer.cpp:264
void readSettings()
using the TDEConfig associated with the kapp variable, read in the settings from the config file.
Definition: korganizer.cpp:178
void showStatusMessage(const TQString &)
show status message
Definition: korganizer.cpp:244
bool saveAsURL(const KURL &kurl)
Save calendar file to URL.
Definition: korganizer.cpp:259
void setTitle()
Sets title of window according to filename and modification state.
Definition: korganizer.cpp:284