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 "alarmclient.h"
00037 
00038 #include <libkdepim/stdcalendar.h>
00039 
00040 #include <libkcal/calendarlocal.h>
00041 #include <libkcal/calendarresources.h>
00042 #include <libkcal/resourcecalendar.h>
00043 
00044 #include <kpopupmenu.h>
00045 #include <kinstance.h>
00046 #include <klocale.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 #include <kparts/partmanager.h>
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     KCal::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   new KParts::SideBarExtension( mView->leftFrame(), this, "SBE" );
00110 
00111   KParts::InfoExtension *ie = new KParts::InfoExtension( this,
00112                                                          "KOrganizerInfo" );
00113   connect( mView, SIGNAL( incidenceSelected( Incidence *,const QDate & ) ),
00114            SLOT( slotChangeInfo( Incidence *,const QDate & ) ) );
00115   connect( this, SIGNAL( textChanged( const QString & ) ),
00116            ie, SIGNAL( textChanged( const QString & ) ) );
00117 
00118   mActionManager->init();
00119   mActionManager->readSettings();
00120 
00121   setXMLFile( "korganizer_part.rc" );
00122   mActionManager->loadParts();
00123   setTitle();
00124 }
00125 
00126 KOrganizerPart::~KOrganizerPart()
00127 {
00128   mActionManager->saveCalendar();
00129   mActionManager->writeSettings();
00130 
00131   delete mActionManager;
00132   mActionManager = 0;
00133 
00134   closeURL();
00135 
00136   KOCore::self()->removeXMLGUIClient( mTopLevelWidget );
00137 }
00138 
00139 KAboutData *KOrganizerPart::createAboutData()
00140 {
00141   return new KOrg::AboutData;
00142 }
00143 
00144 void KOrganizerPart::startCompleted( KProcess *process )
00145 {
00146   delete process;
00147 }
00148 
00149 void KOrganizerPart::slotChangeInfo( Incidence *incidence, const QDate & )
00150 {
00151   if ( incidence ) {
00152     emit textChanged( incidence->summary() + " / " +
00153                       incidence->dtStartTimeStr() );
00154   } else {
00155     emit textChanged( QString::null );
00156   }
00157 }
00158 
00159 QWidget *KOrganizerPart::topLevelWidget()
00160 {
00161   return mView->topLevelWidget();
00162 }
00163 
00164 ActionManager *KOrganizerPart::actionManager()
00165 {
00166   return mActionManager;
00167 }
00168 
00169 void KOrganizerPart::showStatusMessage( const QString &message )
00170 {
00171   KStatusBar *statusBar = mStatusBarExtension->statusBar();
00172   if ( statusBar ) statusBar->message( message );
00173 }
00174 
00175 KOrg::CalendarViewBase *KOrganizerPart::view() const
00176 {
00177   return mView;
00178 }
00179 
00180 bool KOrganizerPart::openURL( const KURL &url, bool merge )
00181 {
00182   return mActionManager->openURL( url, merge );
00183 }
00184 
00185 bool KOrganizerPart::saveURL()
00186 {
00187   return mActionManager->saveURL();
00188 }
00189 
00190 bool KOrganizerPart::saveAsURL( const KURL &kurl )
00191 {
00192   return mActionManager->saveAsURL( kurl );
00193 }
00194 
00195 KURL KOrganizerPart::getCurrentURL() const
00196 {
00197   return mActionManager->url();
00198 }
00199 
00200 bool KOrganizerPart::openFile()
00201 {
00202   mView->openCalendar( m_file );
00203   mView->show();
00204   return true;
00205 }
00206 
00207 // FIXME: This is copied verbatim from the KOrganizer class. Move it to the common base class!
00208 void KOrganizerPart::setTitle()
00209 {
00210 //  kdDebug(5850) << "KOrganizer::setTitle" << endl;
00211 // FIXME: Inside kontact we want to have different titles depending on the
00212 //        type of view (calendar, to-do, journal). How can I add the filter
00213 //        name in that case?
00214 /*
00215   QString title;
00216   if ( !hasDocument() ) {
00217     title = i18n("Calendar");
00218   } else {
00219     KURL url = mActionManager->url();
00220 
00221     if ( !url.isEmpty() ) {
00222       if ( url.isLocalFile() ) title = url.fileName();
00223       else title = url.prettyURL();
00224     } else {
00225       title = i18n("New Calendar");
00226     }
00227 
00228     if ( mView->isReadOnly() ) {
00229       title += " [" + i18n("read-only") + "]";
00230     }
00231   }
00232 
00233   title += " - <" + mView->currentFilterName() + "> ";
00234 
00235   emit setWindowCaption( title );*/
00236 }
00237 
00238 bool KOrganizerPart::isCurrentlyActivePart()
00239 {
00240   if ( manager() ) {
00241     return  ( manager()->activePart() == this );
00242   } else {
00243     return false;
00244   }
00245 }
00246 
00247 #include "korganizer_part.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys