kontact

knode_plugin.cpp

00001 /*
00002     This file is part of Kontact.
00003 
00004     Copyright (c) 2003 Zack Rusin <zack@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 Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include "knode_plugin.h"
00026 
00027 #include "core.h"
00028 
00029 #include <kapplication.h>
00030 #include <kparts/componentfactory.h>
00031 #include <kgenericfactory.h>
00032 #include <kapplication.h>
00033 #include <kaction.h>
00034 #include <kiconloader.h>
00035 #include <kdebug.h>
00036 
00037 #include <dcopclient.h>
00038 
00039 #include <qwidget.h>
00040 
00041 
00042 typedef KGenericFactory<KNodePlugin, Kontact::Core> KNodePluginFactory;
00043 K_EXPORT_COMPONENT_FACTORY( libkontact_knodeplugin,
00044                             KNodePluginFactory( "kontact_knodeplugin" ) )
00045 
00046 
00047 KNodePlugin::KNodePlugin( Kontact::Core *core, const char *, const QStringList& )
00048   : Kontact::Plugin( core, core, "knode" ), mStub(0)
00049 {
00050   setInstance( KNodePluginFactory::instance() );
00051 
00052   insertNewAction( new KAction( i18n( "New Article..." ), "mail_new", CTRL+SHIFT+Key_A,
00053                    this, SLOT( slotPostArticle() ), actionCollection(), "post_article" ) );
00054 
00055   mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
00056       new Kontact::UniqueAppHandlerFactory<KNodeUniqueAppHandler>(), this );
00057 }
00058 
00059 KNodePlugin::~KNodePlugin()
00060 {
00061 }
00062 
00063 bool KNodePlugin::createDCOPInterface( const QString& /*serviceType*/ )
00064 {
00065   return false;
00066 }
00067 
00068 bool KNodePlugin::isRunningStandalone()
00069 {
00070   return mUniqueAppWatcher->isRunningStandalone();
00071 }
00072 
00073 QStringList KNodePlugin::invisibleToolbarActions() const
00074 {
00075   return QStringList( "article_postNew" );
00076 }
00077 
00078 void KNodePlugin::slotPostArticle()
00079 {
00080   (void) part(); // ensure part is loaded
00081   Q_ASSERT( mStub );
00082   if ( mStub )
00083     mStub->postArticle();
00084 }
00085 
00086 KParts::ReadOnlyPart* KNodePlugin::createPart()
00087 {
00088   KParts::ReadOnlyPart *part = loadPart();
00089   if ( !part ) return 0;
00090 
00091   mStub = new KNodeIface_stub( dcopClient(), "knode", "KNodeIface" );
00092   return part;
00093 }
00094 
00096 
00097 #include "../../../knode/knode_options.h"
00098 void KNodeUniqueAppHandler::loadCommandLineOptions()
00099 {
00100     KCmdLineArgs::addCmdLineOptions( knode_options );
00101 }
00102 
00103 int KNodeUniqueAppHandler::newInstance()
00104 {
00105     // Ensure part is loaded
00106     (void)plugin()->part();
00107     DCOPRef knode( "knode", "KNodeIface" );
00108     DCOPReply reply = knode.call( "handleCommandLine" );
00109 #if 0
00110     if ( reply.isValid() ) {
00111         bool handled = reply;
00112         kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
00113         if ( !handled )
00114 #endif
00115     // in all cases, bring knode plugin to front
00116     return Kontact::UniqueAppHandler::newInstance();
00117 #if 0
00118     }
00119     return 0;
00120 #endif
00121 }
00122 
00123 #include "knode_plugin.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys