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 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 <dcopclient.h>
00028 #include <dcopref.h>
00029 #include <tdeaboutdata.h>
00030 #include <tdeaction.h>
00031 #include <tdeapplication.h>
00032 #include <tdecmdlineargs.h>
00033 #include <kdebug.h>
00034 #include <kgenericfactory.h>
00035 #include <kiconloader.h>
00036 #include <tdemessagebox.h>
00037 #include <tdeparts/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::AkregatorPlugin, Kontact::Core > PluginFactory;
00048 K_EXPORT_COMPONENT_FACTORY( libkontact_akregator,
00049                             PluginFactory( "kontact_akregator" ) )
00050 
00051 AkregatorPlugin::AkregatorPlugin( Kontact::Core *core, const char *, const TQStringList& )
00052   : Kontact::Plugin( core, TQT_TQOBJECT(core), "akregator" ), m_stub(0)
00053 {
00054     setInstance( PluginFactory::instance() );
00055 
00056     insertNewAction( new TDEAction( i18n( "New Feed..." ), "bookmark_add", CTRL+SHIFT+Key_F, this, TQT_SLOT( addFeed() ), actionCollection(), "feed_new" ) );
00057 
00058     m_uniqueAppWatcher = new Kontact::UniqueAppWatcher(
00059     new Kontact::UniqueAppHandlerFactory<Akregator::UniqueAppHandler>(), this );
00060 }
00061 
00062 AkregatorPlugin::~AkregatorPlugin()
00063 {
00064 }
00065 
00066 bool AkregatorPlugin::isRunningStandalone()
00067 {
00068     return m_uniqueAppWatcher->isRunningStandalone();
00069 }
00070 
00071 TQStringList AkregatorPlugin::invisibleToolbarActions() const
00072 {
00073     return TQStringList( "file_new_contact" );
00074 }
00075 
00076 
00077 Akregator::AkregatorPartIface_stub *AkregatorPlugin::interface()
00078 {
00079     if ( !m_stub ) {
00080         part();
00081     }
00082 
00083     Q_ASSERT( m_stub );
00084     return m_stub;
00085 }
00086 
00087 
00088 MyBasePart* AkregatorPlugin::createPart()
00089 {
00090     MyBasePart* p = loadPart();
00091 
00092     connect(p, TQT_SIGNAL(showPart()), this, TQT_SLOT(showPart()));
00093     m_stub = new Akregator::AkregatorPartIface_stub( dcopClient(), "akregator",
00094                                       "AkregatorIface" );
00095     m_stub->openStandardFeedList();
00096     return p;
00097 }
00098 
00099 
00100 void AkregatorPlugin::showPart()
00101 {
00102     core()->selectPlugin(this);
00103 }
00104 
00105 void AkregatorPlugin::addFeed()
00106 {
00107     interface()->addFeed();
00108 }
00109 
00110 TQStringList AkregatorPlugin::configModules() const
00111 {
00112     TQStringList modules;
00113     modules << "PIM/akregator.desktop";
00114     return modules;
00115 }
00116 
00117 void AkregatorPlugin::readProperties( TDEConfig *config )
00118 {
00119     if ( part() ) {
00120         Akregator::Part *myPart = static_cast<Akregator::Part*>( part() );    
00121         myPart->readProperties( config );
00122     }
00123 }
00124 
00125 void AkregatorPlugin::saveProperties( TDEConfig *config )
00126 {
00127     if ( part() ) {
00128         Akregator::Part *myPart = static_cast<Akregator::Part*>( part() );    
00129         myPart->saveProperties( config );
00130     }
00131 }
00132 
00133 void UniqueAppHandler::loadCommandLineOptions()
00134 {
00135     TDECmdLineArgs::addCmdLineOptions( akregator_options );
00136 }
00137 
00138 int UniqueAppHandler::newInstance()
00139 {
00140     kdDebug(5602) << k_funcinfo << endl;
00141     // Ensure part is loaded
00142     (void)plugin()->part();
00143     DCOPRef akr( "akregator", "AkregatorIface" );
00144 //    DCOPReply reply = kAB.call( "handleCommandLine" );
00145   //  if ( reply.isValid() ) {
00146     //    bool handled = reply;
00147      //   kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
00148      //   if ( !handled ) // no args -> simply bring kaddressbook plugin to front
00149             return Kontact::UniqueAppHandler::newInstance();
00150    // }
00151    // return 0;
00152 }
00153 
00154 } // namespace Akregator
00155 #include "akregator_plugin.moc"