korganizer

korganizer_part.cpp
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2000 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of TQt, and distribute the resulting executable,
23  without including the source code for TQt in the source distribution.
24 */
25 
26 #include "korganizer_part.h"
27 
28 #include "calendarview.h"
29 #include "actionmanager.h"
30 #include "koglobals.h"
31 #include "koprefs.h"
32 #include "resourceview.h"
33 #include "aboutdata.h"
34 #include "kocore.h"
35 #include "korganizerifaceimpl.h"
36 #include "stdcalendar.h"
37 #include "alarmclient.h"
38 
39 #include <libkcal/calendarlocal.h>
41 #include <libkcal/resourcecalendar.h>
42 
43 #include <tdepopupmenu.h>
44 #include <kinstance.h>
45 #include <tdelocale.h>
46 #include <kiconloader.h>
47 #include <tdeaction.h>
48 #include <kdebug.h>
49 #include <kstandarddirs.h>
50 #include <tdeconfig.h>
51 #include <tdeprocess.h>
52 #include <tdetempfile.h>
53 #include <kstatusbar.h>
54 #include <tdeparts/genericfactory.h>
55 #include <tdeparts/partmanager.h>
56 #include <tdeparts/statusbarextension.h>
57 
58 #include <sidebarextension.h>
59 #include <infoextension.h>
60 
61 #include <tqapplication.h>
62 #include <tqfile.h>
63 #include <tqtimer.h>
64 #include <tqlayout.h>
65 
66 typedef KParts::GenericFactory< KOrganizerPart > KOrganizerFactory;
67 K_EXPORT_COMPONENT_FACTORY( libkorganizerpart, KOrganizerFactory )
68 
69 KOrganizerPart::KOrganizerPart( TQWidget *parentWidget, const char *widgetName,
70  TQObject *parent, const char *name,
71  const TQStringList & ) :
72  KParts::ReadOnlyPart(parent, name), mTopLevelWidget( parentWidget->topLevelWidget() )
73 {
74  TDEGlobal::locale()->insertCatalogue( "libkcal" );
75  TDEGlobal::locale()->insertCatalogue( "libtdepim" );
76  TDEGlobal::locale()->insertCatalogue( "kdgantt" );
77 
78  KOCore::self()->addXMLGUIClient( mTopLevelWidget, this );
79 
80  TQString pname( name );
81 
82  // create a canvas to insert our widget
83  TQWidget *canvas = new TQWidget( parentWidget, widgetName );
84  canvas->setFocusPolicy( TQWidget::ClickFocus );
85  setWidget( canvas );
86  mView = new CalendarView( canvas );
87 
88  mActionManager = new ActionManager( this, mView, this, this, true );
89  (void)new KOrganizerIfaceImpl( mActionManager, this, "IfaceImpl" );
90 
91  if ( pname == "kontact" ) {
92  mActionManager->createCalendarResources();
93  setHasDocument( false );
94  KOrg::StdCalendar::self()->load();
95  mView->updateCategories();
96  } else {
97  mActionManager->createCalendarLocal();
98  setHasDocument( true );
99  }
100 
101  mStatusBarExtension = new KParts::StatusBarExtension( this );
102 
103  setInstance( KOrganizerFactory::instance() );
104 
105  TQVBoxLayout *topLayout = new TQVBoxLayout( canvas );
106  topLayout->addWidget( mView );
107 
108  new KParts::SideBarExtension( mView->leftFrame(), this, "SBE" );
109 
110  KParts::InfoExtension *ie = new KParts::InfoExtension( this,
111  "KOrganizerInfo" );
112  connect( mView, TQ_SIGNAL( incidenceSelected( Incidence *,const TQDate & ) ),
113  TQ_SLOT( slotChangeInfo( Incidence *,const TQDate & ) ) );
114  connect( this, TQ_SIGNAL( textChanged( const TQString & ) ),
115  ie, TQ_SIGNAL( textChanged( const TQString & ) ) );
116 
117  mActionManager->init();
118  mActionManager->readSettings();
119 
120  setXMLFile( "korganizer_part.rc" );
121  mActionManager->loadParts();
122  setTitle();
123 }
124 
125 KOrganizerPart::~KOrganizerPart()
126 {
127  mActionManager->saveCalendar();
128  mActionManager->writeSettings();
129 
130  delete mActionManager;
131  mActionManager = 0;
132 
133  closeURL();
134 
135  KOCore::self()->removeXMLGUIClient( mTopLevelWidget );
136 }
137 
138 TDEAboutData *KOrganizerPart::createAboutData()
139 {
140  return new KOrg::AboutData;
141 }
142 
143 void KOrganizerPart::startCompleted( TDEProcess *process )
144 {
145  delete process;
146 }
147 
148 void KOrganizerPart::slotChangeInfo( Incidence *incidence, const TQDate & )
149 {
150  if ( incidence ) {
151  emit textChanged( incidence->summary() + " / " +
152  incidence->dtStartTimeStr() );
153  } else {
154  emit textChanged( TQString() );
155  }
156 }
157 
158 TQWidget *KOrganizerPart::topLevelWidget()
159 {
160  return mView->topLevelWidget();
161 }
162 
163 ActionManager *KOrganizerPart::actionManager()
164 {
165  return mActionManager;
166 }
167 
168 void KOrganizerPart::showStatusMessage( const TQString &message )
169 {
170  KStatusBar *statusBar = mStatusBarExtension->statusBar();
171  if ( statusBar ) statusBar->message( message );
172 }
173 
174 KOrg::CalendarViewBase *KOrganizerPart::view() const
175 {
176  return mView;
177 }
178 
179 bool KOrganizerPart::openURL( const KURL &url, bool merge )
180 {
181  return mActionManager->openURL( url, merge );
182 }
183 
184 bool KOrganizerPart::saveURL()
185 {
186  return mActionManager->saveURL();
187 }
188 
189 bool KOrganizerPart::saveAsURL( const KURL &kurl )
190 {
191  return mActionManager->saveAsURL( kurl );
192 }
193 
194 KURL KOrganizerPart::getCurrentURL() const
195 {
196  return mActionManager->url();
197 }
198 
199 bool KOrganizerPart::openFile()
200 {
201  mView->openCalendar( m_file );
202  mView->show();
203  return true;
204 }
205 
206 // FIXME: This is copied verbatim from the KOrganizer class. Move it to the common base class!
207 void KOrganizerPart::setTitle()
208 {
209 // kdDebug(5850) << "KOrganizer::setTitle" << endl;
210 // FIXME: Inside kontact we want to have different titles depending on the
211 // type of view (calendar, to-do, journal). How can I add the filter
212 // name in that case?
213 /*
214  TQString title;
215  if ( !hasDocument() ) {
216  title = i18n("Calendar");
217  } else {
218  KURL url = mActionManager->url();
219 
220  if ( !url.isEmpty() ) {
221  if ( url.isLocalFile() ) title = url.fileName();
222  else title = url.prettyURL();
223  } else {
224  title = i18n("New Calendar");
225  }
226 
227  if ( mView->isReadOnly() ) {
228  title += " [" + i18n("read-only") + "]";
229  }
230  }
231 
232  title += " - <" + mView->currentFilterName() + "> ";
233 
234  emit setWindowCaption( title );*/
235 }
236 
237 bool KOrganizerPart::isCurrentlyActivePart()
238 {
239  if ( manager() ) {
240  return ( manager()->activePart() == this );
241  } else {
242  return false;
243  }
244 }
245 
246 #include "korganizer_part.moc"
The ActionManager creates all the actions in KOrganizer.
Definition: actionmanager.h:74
This is the main calendar widget.
Definition: calendarview.h:82
virtual TDE_DEPRECATED TQString dtStartTimeStr() const
TQString summary() const
interface for main calendar view widget