korganizer

korganizer_part.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2000 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of Qt, and distribute the resulting executable,
00023     without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include "korganizer_part.h"
00027 
00028 #include "calendarview.h"
00029 #include "actionmanager.h"
00030 #include "koglobals.h"
00031 #include "koprefs.h"
00032 #include "resourceview.h"
00033 #include "aboutdata.h"
00034 #include "kocore.h"
00035 #include "korganizerifaceimpl.h"
00036 #include "stdcalendar.h"
00037 #include "alarmclient.h"
00038 
00039 #include <libkcal/calendarlocal.h>
00040 #include <libkcal/calendarresources.h>
00041 #include <libkcal/resourcecalendar.h>
00042 
00043 #include <kpopupmenu.h>
00044 #include <kinstance.h>
00045 #include <klocale.h>
00046 #include <kaboutdata.h>
00047 #include <kiconloader.h>
00048 #include <kaction.h>
00049 #include <kdebug.h>
00050 #include <kstandarddirs.h>
00051 #include <kconfig.h>
00052 #include <kprocess.h>
00053 #include <ktempfile.h>
00054 #include <kstatusbar.h>
00055 #include <kparts/genericfactory.h>
00056 
00057 #include <kparts/statusbarextension.h>
00058 
00059 #include <sidebarextension.h>
00060 #include <infoextension.h>
00061 
00062 #include <qapplication.h>
00063 #include <qfile.h>
00064 #include <qtimer.h>
00065 #include <qlayout.h>
00066 
00067 typedef KParts::GenericFactory< KOrganizerPart > KOrganizerFactory;
00068 K_EXPORT_COMPONENT_FACTORY( libkorganizerpart, KOrganizerFactory )
00069 
00070 KOrganizerPart::KOrganizerPart( QWidget *parentWidget, const char *widgetName,
00071                                 QObject *parent, const char *name,
00072                                 const QStringList & ) :
00073   KParts::ReadOnlyPart(parent, name), mTopLevelWidget( parentWidget->topLevelWidget() )
00074 {
00075   KGlobal::locale()->insertCatalogue( "libkcal" );
00076   KGlobal::locale()->insertCatalogue( "libkdepim" );
00077   KGlobal::locale()->insertCatalogue( "kdgantt" );
00078 
00079   KOCore::self()->addXMLGUIClient( mTopLevelWidget, this );
00080 
00081   QString pname( name );
00082 
00083   // create a canvas to insert our widget
00084   QWidget *canvas = new QWidget( parentWidget, widgetName );
00085   canvas->setFocusPolicy( QWidget::ClickFocus );
00086   setWidget( canvas );
00087   mView = new CalendarView( canvas );
00088 
00089   mActionManager = new ActionManager( this, mView, this, this, true );
00090   (void)new KOrganizerIfaceImpl( mActionManager, this, "IfaceImpl" );
00091 
00092   if ( pname == "kontact" ) {
00093     mActionManager->createCalendarResources();
00094     setHasDocument( false );
00095     KOrg::StdCalendar::self()->load();
00096     mView->updateCategories();
00097   } else {
00098     mActionManager->createCalendarLocal();
00099     setHasDocument( true );
00100   }
00101 
00102   mStatusBarExtension = new KParts::StatusBarExtension( this );
00103 
00104   setInstance( KOrganizerFactory::instance() );
00105 
00106   QVBoxLayout *topLayout = new QVBoxLayout( canvas );
00107   topLayout->addWidget( mView );
00108 
00109   KGlobal::iconLoader()->addAppDir( "kdepim" );
00110 
00111   new KParts::SideBarExtension( mView->leftFrame(), this, "SBE" );
00112 
00113   KParts::InfoExtension *ie = new KParts::InfoExtension( this,
00114                                                          "KOrganizerInfo" );
00115   connect( mView, SIGNAL( incidenceSelected( Incidence * ) ),
00116            SLOT( slotChangeInfo( Incidence * ) ) );
00117   connect( this, SIGNAL( textChanged( const QString & ) ),
00118            ie, SIGNAL( textChanged( const QString & ) ) );
00119 
00120   mActionManager->init();
00121   mActionManager->readSettings();
00122 
00123   setXMLFile( "korganizer_part.rc" );
00124   mActionManager->loadParts();
00125   setTitle();
00126 }
00127 
00128 KOrganizerPart::~KOrganizerPart()
00129 {
00130   mActionManager->saveCalendar();
00131   mActionManager->writeSettings();
00132 
00133   delete mActionManager;
00134   mActionManager = 0;
00135 
00136   closeURL();
00137 
00138   KOCore::self()->removeXMLGUIClient( mTopLevelWidget );
00139 }
00140 
00141 KAboutData *KOrganizerPart::createAboutData()
00142 {
00143   return KOrg::AboutData::self();
00144 }
00145 
00146 void KOrganizerPart::startCompleted( KProcess *process )
00147 {
00148   delete process;
00149 }
00150 
00151 void KOrganizerPart::slotChangeInfo( Incidence *incidence )
00152 {
00153   if ( incidence ) {
00154     emit textChanged( incidence->summary() + " / " +
00155                       incidence->dtStartTimeStr() );
00156   } else {
00157     emit textChanged( QString::null );
00158   }
00159 }
00160 
00161 QWidget *KOrganizerPart::topLevelWidget()
00162 {
00163   return mView->topLevelWidget();
00164 }
00165 
00166 ActionManager *KOrganizerPart::actionManager()
00167 {
00168   return mActionManager;
00169 }
00170 
00171 void KOrganizerPart::showStatusMessage( const QString &message )
00172 {
00173   KStatusBar *statusBar = mStatusBarExtension->statusBar();
00174   if ( statusBar ) statusBar->message( message );
00175 }
00176 
00177 KOrg::CalendarViewBase *KOrganizerPart::view() const
00178 {
00179   return mView;
00180 }
00181 
00182 bool KOrganizerPart::openURL( const KURL &url, bool merge )
00183 {
00184   return mActionManager->openURL( url, merge );
00185 }
00186 
00187 bool KOrganizerPart::saveURL()
00188 {
00189   return mActionManager->saveURL();
00190 }
00191 
00192 bool KOrganizerPart::saveAsURL( const KURL &kurl )
00193 {
00194   return mActionManager->saveAsURL( kurl );
00195 }
00196 
00197 KURL KOrganizerPart::getCurrentURL() const
00198 {
00199   return mActionManager->url();
00200 }
00201 
00202 bool KOrganizerPart::openFile()
00203 {
00204   mView->openCalendar( m_file );
00205   mView->show();
00206   return true;
00207 }
00208 
00209 // FIXME: This is copied verbatim from the KOrganizer class. Move it to the common base class!
00210 void KOrganizerPart::setTitle()
00211 {
00212 //  kdDebug(5850) << "KOrganizer::setTitle" << endl;
00213 // FIXME: Inside kontact we want to have different titles depending on the
00214 //        type of view (calendar, to-do, journal). How can I add the filter
00215 //        name in that case?
00216 /*
00217   QString title;
00218   if ( !hasDocument() ) {
00219     title = i18n("Calendar");
00220   } else {
00221     KURL url = mActionManager->url();
00222 
00223     if ( !url.isEmpty() ) {
00224       if ( url.isLocalFile() ) title = url.fileName();
00225       else title = url.prettyURL();
00226     } else {
00227       title = i18n("New Calendar");
00228     }
00229 
00230     if ( mView->isReadOnly() ) {
00231       title += " [" + i18n("read-only") + "]";
00232     }
00233   }
00234 
00235   title += " - <" + mView->currentFilterName() + "> ";
00236 
00237   emit setWindowCaption( title );*/
00238 }
00239 
00240 #include "korganizer_part.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys