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 <kiconloader.h>
00047 #include <kaction.h>
00048 #include <kdebug.h>
00049 #include <kstandarddirs.h>
00050 #include <kconfig.h>
00051 #include <kprocess.h>
00052 #include <ktempfile.h>
00053 #include <kstatusbar.h>
00054 #include <kparts/genericfactory.h>
00055 
00056 #include <kparts/statusbarextension.h>
00057 
00058 #include <sidebarextension.h>
00059 #include <infoextension.h>
00060 
00061 #include <qapplication.h>
00062 #include <qfile.h>
00063 #include <qtimer.h>
00064 #include <qlayout.h>
00065 
00066 typedef KParts::GenericFactory< KOrganizerPart > KOrganizerFactory;
00067 K_EXPORT_COMPONENT_FACTORY( libkorganizerpart, KOrganizerFactory )
00068 
00069 KOrganizerPart::KOrganizerPart( QWidget *parentWidget, const char *widgetName,
00070                                 QObject *parent, const char *name,
00071                                 const QStringList & ) :
00072   KParts::ReadOnlyPart(parent, name), mTopLevelWidget( parentWidget->topLevelWidget() )
00073 {
00074   KGlobal::locale()->insertCatalogue( "libkcal" );
00075   KGlobal::locale()->insertCatalogue( "libkdepim" );
00076   KGlobal::locale()->insertCatalogue( "kdgantt" );
00077 
00078   KOCore::self()->addXMLGUIClient( mTopLevelWidget, this );
00079 
00080   QString pname( name );
00081 
00082   // create a canvas to insert our widget
00083   QWidget *canvas = new QWidget( parentWidget, widgetName );
00084   canvas->setFocusPolicy( QWidget::ClickFocus );
00085   setWidget( canvas );
00086   mView = new CalendarView( canvas );
00087 
00088   mActionManager = new ActionManager( this, mView, this, this, true );
00089   (void)new KOrganizerIfaceImpl( mActionManager, this, "IfaceImpl" );
00090 
00091   if ( pname == "kontact" ) {
00092     mActionManager->createCalendarResources();
00093     setHasDocument( false );
00094     KOrg::StdCalendar::self()->load();
00095     mView->updateCategories();
00096   } else {
00097     mActionManager->createCalendarLocal();
00098     setHasDocument( true );
00099   }
00100 
00101   mStatusBarExtension = new KParts::StatusBarExtension( this );
00102 
00103   setInstance( KOrganizerFactory::instance() );
00104 
00105   QVBoxLayout *topLayout = new QVBoxLayout( canvas );
00106   topLayout->addWidget( mView );
00107 
00108   new KParts::SideBarExtension( mView->leftFrame(), this, "SBE" );
00109 
00110   KParts::InfoExtension *ie = new KParts::InfoExtension( this,
00111                                                          "KOrganizerInfo" );
00112   connect( mView, SIGNAL( incidenceSelected( Incidence * ) ),
00113            SLOT( slotChangeInfo( Incidence * ) ) );
00114   connect( this, SIGNAL( textChanged( const QString & ) ),
00115            ie, SIGNAL( textChanged( const QString & ) ) );
00116 
00117   mActionManager->init();
00118   mActionManager->readSettings();
00119 
00120   setXMLFile( "korganizer_part.rc" );
00121   mActionManager->loadParts();
00122   setTitle();
00123 }
00124 
00125 KOrganizerPart::~KOrganizerPart()
00126 {
00127   mActionManager->saveCalendar();
00128   mActionManager->writeSettings();
00129 
00130   delete mActionManager;
00131   mActionManager = 0;
00132 
00133   closeURL();
00134 
00135   KOCore::self()->removeXMLGUIClient( mTopLevelWidget );
00136 }
00137 
00138 KAboutData *KOrganizerPart::createAboutData()
00139 {
00140   return new KOrg::AboutData;
00141 }
00142 
00143 void KOrganizerPart::startCompleted( KProcess *process )
00144 {
00145   delete process;
00146 }
00147 
00148 void KOrganizerPart::slotChangeInfo( Incidence *incidence )
00149 {
00150   if ( incidence ) {
00151     emit textChanged( incidence->summary() + " / " +
00152                       incidence->dtStartTimeStr() );
00153   } else {
00154     emit textChanged( QString::null );
00155   }
00156 }
00157 
00158 QWidget *KOrganizerPart::topLevelWidget()
00159 {
00160   return mView->topLevelWidget();
00161 }
00162 
00163 ActionManager *KOrganizerPart::actionManager()
00164 {
00165   return mActionManager;
00166 }
00167 
00168 void KOrganizerPart::showStatusMessage( const QString &message )
00169 {
00170   KStatusBar *statusBar = mStatusBarExtension->statusBar();
00171   if ( statusBar ) statusBar->message( message );
00172 }
00173 
00174 KOrg::CalendarViewBase *KOrganizerPart::view() const
00175 {
00176   return mView;
00177 }
00178 
00179 bool KOrganizerPart::openURL( const KURL &url, bool merge )
00180 {
00181   return mActionManager->openURL( url, merge );
00182 }
00183 
00184 bool KOrganizerPart::saveURL()
00185 {
00186   return mActionManager->saveURL();
00187 }
00188 
00189 bool KOrganizerPart::saveAsURL( const KURL &kurl )
00190 {
00191   return mActionManager->saveAsURL( kurl );
00192 }
00193 
00194 KURL KOrganizerPart::getCurrentURL() const
00195 {
00196   return mActionManager->url();
00197 }
00198 
00199 bool KOrganizerPart::openFile()
00200 {
00201   mView->openCalendar( m_file );
00202   mView->show();
00203   return true;
00204 }
00205 
00206 // FIXME: This is copied verbatim from the KOrganizer class. Move it to the common base class!
00207 void KOrganizerPart::setTitle()
00208 {
00209 //  kdDebug(5850) << "KOrganizer::setTitle" << endl;
00210 // FIXME: Inside kontact we want to have different titles depending on the
00211 //        type of view (calendar, to-do, journal). How can I add the filter
00212 //        name in that case?
00213 /*
00214   QString title;
00215   if ( !hasDocument() ) {
00216     title = i18n("Calendar");
00217   } else {
00218     KURL url = mActionManager->url();
00219 
00220     if ( !url.isEmpty() ) {
00221       if ( url.isLocalFile() ) title = url.fileName();
00222       else title = url.prettyURL();
00223     } else {
00224       title = i18n("New Calendar");
00225     }
00226 
00227     if ( mView->isReadOnly() ) {
00228       title += " [" + i18n("read-only") + "]";
00229     }
00230   }
00231 
00232   title += " - <" + mView->currentFilterName() + "> ";
00233 
00234   emit setWindowCaption( title );*/
00235 }
00236 
00237 #include "korganizer_part.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys