korganizer Library API Documentation

korganizer_part.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2000 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include "korganizer_part.h"
00026 
00027 #include "calendarview.h"
00028 #include "actionmanager.h"
00029 #include "koglobals.h"
00030 #include "koprefs.h"
00031 #include "resourceview.h"
00032 #include "aboutdata.h"
00033 #include "kocore.h"
00034 #include "korganizerifaceimpl.h"
00035 #include "stdcalendar.h"
00036 #include "alarmclient.h"
00037 
00038 #include <libkcal/calendarlocal.h>
00039 #include <libkcal/calendarresources.h>
00040 #include <libkcal/resourcecalendar.h>
00041 #include <libkcal/resourcelocal.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 <kkeydialog.h>
00056 #include <kparts/genericfactory.h>
00057 
00058 #include <kparts/statusbarextension.h>
00059 
00060 #include <sidebarextension.h>
00061 #include <infoextension.h>
00062 
00063 #include <qapplication.h>
00064 #include <qfile.h>
00065 #include <qtimer.h>
00066 #include <qlayout.h>
00067 
00068 typedef KParts::GenericFactory< KOrganizerPart > KOrganizerFactory;
00069 K_EXPORT_COMPONENT_FACTORY( libkorganizerpart, KOrganizerFactory )
00070 
00071 KOrganizerPart::KOrganizerPart( QWidget *parentWidget, const char *widgetName,
00072                                 QObject *parent, const char *name,
00073                                 const QStringList & ) :
00074   KParts::ReadOnlyPart(parent, name)
00075 {
00076   KGlobal::locale()->insertCatalogue( "libkcal" );
00077   KGlobal::locale()->insertCatalogue( "libkdepim" );
00078   KGlobal::locale()->insertCatalogue( "kdgantt" );
00079 
00080   KOCore::self()->setXMLGUIClient( this );
00081 
00082   QString pname( name );
00083 
00084   // create a canvas to insert our widget
00085   QWidget *canvas = new QWidget( parentWidget, widgetName );
00086   canvas->setFocusPolicy( QWidget::ClickFocus );
00087   setWidget( canvas );
00088   mView = new CalendarView( canvas );
00089 
00090   mActionManager = new ActionManager( this, mView, this, this, true );
00091   (void)new KOrganizerIfaceImpl( mActionManager, this, "IfaceImpl" );
00092 
00093   if ( pname == "kontact" ) {
00094     mActionManager->createCalendarResources();
00095     setHasDocument( false );
00096     KOrg::StdCalendar::self()->load();
00097     mView->updateCategories();
00098   } else {
00099     mActionManager->createCalendarLocal();
00100     setHasDocument( true );
00101   }
00102 
00103   mBrowserExtension = new KOrganizerBrowserExtension( this );
00104   mStatusBarExtension = new KParts::StatusBarExtension( this );
00105 
00106   setInstance( KOrganizerFactory::instance() );
00107 
00108   QVBoxLayout *topLayout = new QVBoxLayout( canvas );
00109   topLayout->addWidget( mView );
00110 
00111   KGlobal::iconLoader()->addAppDir( "korganizer" );
00112 
00113   new KParts::SideBarExtension( mView->leftFrame(), this, "SBE" );
00114 
00115   KParts::InfoExtension *ie = new KParts::InfoExtension( this,
00116                                                          "KOrganizerInfo" );
00117   connect( mView, SIGNAL( incidenceSelected( Incidence * ) ),
00118            SLOT( slotChangeInfo( Incidence * ) ) );
00119   connect( this, SIGNAL( textChanged( const QString & ) ),
00120            ie, SIGNAL( textChanged( const QString & ) ) );
00121 
00122   mView->show();
00123 
00124   mActionManager->init();
00125   mActionManager->readSettings();
00126   connect( mActionManager, SIGNAL( actionKeyBindings() ),
00127            SLOT( configureKeyBindings() ) );
00128 
00129   setXMLFile( "korganizer_part.rc" );
00130   mActionManager->loadParts();
00131   // If korganizer is run as part inside kontact, the alarmdaemon
00132   // is not started by KOrganizerApp, so we have to start it here.
00133   KOGlobals::self()->alarmClient()->startDaemon();
00134 }
00135 
00136 KOrganizerPart::~KOrganizerPart()
00137 {
00138   mActionManager->saveCalendar();
00139   mActionManager->writeSettings();
00140 
00141   delete mActionManager;
00142   mActionManager = 0;
00143 
00144   closeURL();
00145 }
00146 
00147 KAboutData *KOrganizerPart::createAboutData()
00148 {
00149   return KOrg::AboutData::self();
00150 }
00151 
00152 void KOrganizerPart::startCompleted( KProcess *process )
00153 {
00154   delete process;
00155 }
00156 
00157 void KOrganizerPart::slotChangeInfo( Incidence *incidence )
00158 {
00159   if ( incidence ) {
00160     emit textChanged( incidence->summary() + " / " +
00161                       incidence->dtStartTimeStr() );
00162   } else {
00163     emit textChanged( QString::null );
00164   }
00165 }
00166 
00167 QWidget *KOrganizerPart::topLevelWidget()
00168 {
00169   return mView->topLevelWidget();
00170 }
00171 
00172 ActionManager *KOrganizerPart::actionManager()
00173 {
00174   return mActionManager;
00175 }
00176 
00177 void KOrganizerPart::showStatusMessage( const QString &message )
00178 {
00179   KStatusBar *statusBar = mStatusBarExtension->statusBar();
00180   if ( statusBar ) statusBar->message( message );
00181 }
00182 
00183 KOrg::CalendarViewBase *KOrganizerPart::view() const
00184 {
00185   return mView;
00186 }
00187 
00188 bool KOrganizerPart::openURL( const KURL &url, bool merge )
00189 {
00190   return mActionManager->openURL( url, merge );
00191 }
00192 
00193 bool KOrganizerPart::saveURL()
00194 {
00195   return mActionManager->saveURL();
00196 }
00197 
00198 bool KOrganizerPart::saveAsURL( const KURL &kurl )
00199 {
00200   return mActionManager->saveAsURL( kurl );
00201 }
00202 
00203 KURL KOrganizerPart::getCurrentURL() const
00204 {
00205   return mActionManager->url();
00206 }
00207 
00208 bool KOrganizerPart::openFile()
00209 {
00210   mView->openCalendar( m_file );
00211   mView->show();
00212   return true;
00213 }
00214 
00215 void KOrganizerPart::configureKeyBindings()
00216 {
00217   KKeyDialog::configure( actionCollection(), true );
00218 }
00219 
00220 
00221 KOrganizerBrowserExtension::KOrganizerBrowserExtension(KOrganizerPart *parent) :
00222   KParts::BrowserExtension(parent, "KOrganizerBrowserExtension")
00223 {
00224 }
00225 
00226 KOrganizerBrowserExtension::~KOrganizerBrowserExtension()
00227 {
00228 }
00229 
00230 using namespace KParts;
00231 
00232 #include "korganizer_part.moc"
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 Wed Mar 23 22:45:26 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003