kontact

akregator_plugin.cpp

00001 /*
00002     This file is part of Akregator.
00003 
00004     Copyright (C) 2004 Sashmit Bhaduri <smt@vfemail.net>
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 Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include <qwidget.h>
00026 
00027 #include <dcopclient.h>
00028 #include <dcopref.h>
00029 #include <kaboutdata.h>
00030 #include <kaction.h>
00031 #include <kapplication.h>
00032 #include <kcmdlineargs.h>
00033 #include <kdebug.h>
00034 #include <kgenericfactory.h>
00035 #include <kiconloader.h>
00036 #include <kmessagebox.h>
00037 #include <kparts/componentfactory.h>
00038 
00039 #include <core.h>
00040 #include <plugin.h>
00041 
00042 #include <akregator_options.h>
00043 #include <akregator_part.h>
00044 #include "akregator_plugin.h"
00045 namespace Akregator {
00046 
00047 typedef KGenericFactory<Akregator::Plugin, Kontact::Core > PluginFactory;
00048 K_EXPORT_COMPONENT_FACTORY( libkontact_akregator,
00049                             PluginFactory( "kontact_akregator" ) )
00050 
00051 Plugin::Plugin( Kontact::Core *core, const char *, const QStringList& )
00052   : Kontact::Plugin( core, core, "akregator" ), m_stub(0)
00053 {
00054 
00055     setInstance( PluginFactory::instance() );
00056 
00057     insertNewAction( new KAction( i18n( "New Feed..." ), "bookmark_add", CTRL+SHIFT+Key_F, this, SLOT( addFeed() ), actionCollection(), "feed_new" ) );
00058 
00059     m_uniqueAppWatcher = new Kontact::UniqueAppWatcher(
00060     new Kontact::UniqueAppHandlerFactory<Akregator::UniqueAppHandler>(), this );
00061 }
00062 
00063 Plugin::~Plugin()
00064 {
00065 }
00066 
00067 bool Plugin::isRunningStandalone()
00068 {
00069     return m_uniqueAppWatcher->isRunningStandalone();
00070 }
00071 
00072 QStringList Plugin::invisibleToolbarActions() const
00073 {
00074     return QStringList( "file_new_contact" );
00075 }
00076 
00077 
00078 Akregator::AkregatorPartIface_stub *Plugin::interface()
00079 {
00080     if ( !m_stub ) {
00081         part();
00082     }
00083 
00084     Q_ASSERT( m_stub );
00085     return m_stub;
00086 }
00087 
00088 
00089 MyBasePart* Plugin::createPart()
00090 {
00091     MyBasePart* p = loadPart();
00092 
00093     connect(p, SIGNAL(showPart()), this, SLOT(showPart()));
00094     m_stub = new Akregator::AkregatorPartIface_stub( dcopClient(), "akregator",
00095                                       "AkregatorIface" );
00096     m_stub->openStandardFeedList();
00097     return p;
00098 }
00099 
00100 
00101 void Plugin::showPart()
00102 {
00103     core()->selectPlugin(this);
00104 }
00105 
00106 void Plugin::addFeed()
00107 {
00108     interface()->addFeed();
00109 }
00110 
00111 QStringList Plugin::configModules() const
00112 {
00113     QStringList modules;
00114     modules << "PIM/akregator.desktop";
00115     return modules;
00116 }
00117 
00118 void Plugin::readProperties( KConfig *config )
00119 {
00120     if ( part() ) {
00121         Akregator::Part *myPart = static_cast<Akregator::Part*>( part() );    
00122         myPart->readProperties( config );
00123     }
00124 }
00125 
00126 void Plugin::saveProperties( KConfig *config )
00127 {
00128     if ( part() ) {
00129         Akregator::Part *myPart = static_cast<Akregator::Part*>( part() );    
00130         myPart->saveProperties( config );
00131     }
00132 }
00133 
00134 void UniqueAppHandler::loadCommandLineOptions()
00135 {
00136     KCmdLineArgs::addCmdLineOptions( akregator_options );
00137 }
00138 
00139 int UniqueAppHandler::newInstance()
00140 {
00141     kdDebug(5602) << k_funcinfo << endl;
00142     // Ensure part is loaded
00143     (void)plugin()->part();
00144     DCOPRef akr( "akregator", "AkregatorIface" );
00145 //    DCOPReply reply = kAB.call( "handleCommandLine" );
00146   //  if ( reply.isValid() ) {
00147     //    bool handled = reply;
00148      //   kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
00149      //   if ( !handled ) // no args -> simply bring kaddressbook plugin to front
00150             return Kontact::UniqueAppHandler::newInstance();
00151    // }
00152    // return 0;
00153 }
00154 
00155 } // namespace Akregator
00156 #include "akregator_plugin.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys