kontact

journalplugin.cpp

00001 /*
00002     This file is part of Kontact.
00003 
00004     Copyright (c) 2004 Allen Winter <winter@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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of TQt, and distribute the resulting executable,
00022     without including the source code for TQt in the source distribution.
00023 */
00024 
00025 #include <tqwidget.h>
00026 
00027 #include <tdeapplication.h>
00028 #include <tdeaction.h>
00029 #include <kdebug.h>
00030 #include <kgenericfactory.h>
00031 #include <kiconloader.h>
00032 #include <tdemessagebox.h>
00033 #include <dcopclient.h>
00034 #include <dcopref.h>
00035 
00036 #include "core.h"
00037 #include "journalplugin.h" 
00038 #include "korg_uniqueapp.h"
00039 
00040 
00041 typedef KGenericFactory< JournalPlugin, Kontact::Core > JournalPluginFactory;
00042 K_EXPORT_COMPONENT_FACTORY( libkontact_journalplugin,
00043                             JournalPluginFactory( "kontact_journalplugin" ) )
00044 
00045 JournalPlugin::JournalPlugin( Kontact::Core *core, const char *, const TQStringList& )
00046   : Kontact::Plugin( core, TQT_TQOBJECT(core), "korganizer" ),
00047     mIface( 0 )
00048 {
00049   setInstance( JournalPluginFactory::instance() );
00050   instance()->iconLoader()->addAppDir("tdepim");
00051 
00052   insertNewAction( new TDEAction( i18n( "New Journal..." ), "newjournal",
00053                    CTRL+SHIFT+Key_J, this, TQT_SLOT( slotNewJournal() ), actionCollection(),
00054                    "new_journal" ) );
00055   insertSyncAction( new TDEAction( i18n( "Synchronize Journal" ), "reload",
00056                    0, this, TQT_SLOT( slotSyncJournal() ), actionCollection(),
00057                    "journal_sync" ) );
00058 
00059 
00060   mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00061       new Kontact::UniqueAppHandlerFactory<KOrganizerUniqueAppHandler>(), this );
00062 }
00063 
00064 JournalPlugin::~JournalPlugin()
00065 {
00066 }
00067 
00068 KParts::ReadOnlyPart *JournalPlugin::createPart()
00069 {
00070   KParts::ReadOnlyPart *part = loadPart();
00071 
00072   if ( !part )
00073     return 0;
00074 
00075   dcopClient(); // ensure that we register to DCOP as "korganizer"
00076   mIface = new KCalendarIface_stub( dcopClient(), "kontact", "CalendarIface" );
00077 
00078   return part;
00079 }
00080 
00081 void JournalPlugin::select()
00082 {
00083   interface()->showJournalView();
00084 }
00085 
00086 TQStringList JournalPlugin::invisibleToolbarActions() const
00087 {
00088   TQStringList invisible;
00089   invisible += "new_event";
00090   invisible += "new_todo";
00091   invisible += "new_journal";
00092 
00093   invisible += "view_day";
00094   invisible += "view_list";
00095   invisible += "view_workweek";
00096   invisible += "view_week";
00097   invisible += "view_nextx";
00098   invisible += "view_month";
00099   invisible += "view_todo";
00100   return invisible;
00101 }
00102 
00103 KCalendarIface_stub *JournalPlugin::interface()
00104 {
00105   if ( !mIface ) {
00106     part();
00107   }
00108   Q_ASSERT( mIface );
00109   return mIface;
00110 }
00111 
00112 void JournalPlugin::slotNewJournal()
00113 {
00114   interface()->openJournalEditor( "" );
00115 }
00116 
00117 void JournalPlugin::slotSyncJournal()
00118 {
00119   DCOPRef ref( "kmail", "KMailICalIface" );
00120   ref.send( "triggerSync", TQString("Journal") );
00121 }
00122 
00123 bool JournalPlugin::createDCOPInterface( const TQString& serviceType )
00124 {
00125   kdDebug(5602) << k_funcinfo << serviceType << endl;
00126   if ( serviceType == "DCOP/Organizer" || serviceType == "DCOP/Calendar" ) {
00127     if ( part() )
00128       return true;
00129   }
00130 
00131   return false;
00132 }
00133 
00134 bool JournalPlugin::isRunningStandalone()
00135 {
00136   return mUniqueAppWatcher->isRunningStandalone();
00137 }
00138 
00139 #include "journalplugin.moc"