knode_plugin.cpp
1/*
2 This file is part of Kontact.
3
4 Copyright (c) 2003 Zack Rusin <zack@kde.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include "knode_plugin.h"
26
27#include "core.h"
28
29#include <tdeapplication.h>
30#include <tdeparts/componentfactory.h>
31#include <kgenericfactory.h>
32#include <tdeapplication.h>
33#include <tdeaction.h>
34#include <kiconloader.h>
35#include <kdebug.h>
36
37#include <dcopclient.h>
38
39#include <tqwidget.h>
40
41
42typedef KGenericFactory<KNodePlugin, Kontact::Core> KNodePluginFactory;
43K_EXPORT_COMPONENT_FACTORY( libkontact_knodeplugin,
44 KNodePluginFactory( "kontact_knodeplugin" ) )
45
46
47KNodePlugin::KNodePlugin( Kontact::Core *core, const char *, const TQStringList& )
48 : Kontact::Plugin( core, core, "knode" ), mStub(0)
49{
50 setInstance( KNodePluginFactory::instance() );
51
52 insertNewAction( new TDEAction( i18n( "New Article..." ), "mail-message-new", CTRL+SHIFT+Key_A,
53 this, TQ_SLOT( slotPostArticle() ), actionCollection(), "post_article" ) );
54
55 mUniqueAppWatcher = new Kontact::UniqueAppWatcher(
57}
58
59KNodePlugin::~KNodePlugin()
60{
61}
62
63bool KNodePlugin::createDCOPInterface( const TQString& /*serviceType*/ )
64{
65 return false;
66}
67
68bool KNodePlugin::isRunningStandalone()
69{
70 return mUniqueAppWatcher->isRunningStandalone();
71}
72
73TQStringList KNodePlugin::invisibleToolbarActions() const
74{
75 return TQStringList( "article_postNew" );
76}
77
78void KNodePlugin::slotPostArticle()
79{
80 (void) part(); // ensure part is loaded
81 Q_ASSERT( mStub );
82 if ( mStub )
83 mStub->postArticle();
84}
85
86KParts::ReadOnlyPart* KNodePlugin::createPart()
87{
88 KParts::ReadOnlyPart *part = loadPart();
89 if ( !part ) return 0;
90
91 mStub = new KNodeIface_stub( dcopClient(), "knode", "KNodeIface" );
92 return part;
93}
94
96
97#include "../../../knode/knode_options.h"
98void KNodeUniqueAppHandler::loadCommandLineOptions()
99{
100 TDECmdLineArgs::addCmdLineOptions( knode_options );
101}
102
103int KNodeUniqueAppHandler::newInstance()
104{
105 // Ensure part is loaded
106 (void)plugin()->part();
107 DCOPRef knode( "knode", "KNodeIface" );
108 DCOPReply reply = knode.call( "handleCommandLine" );
109#if 0
110 if ( reply.isValid() ) {
111 bool handled = reply;
112 kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
113 if ( !handled )
114#endif
115 // in all cases, bring knode plugin to front
117#if 0
118 }
119 return 0;
120#endif
121}
122
123#include "knode_plugin.moc"
Used by UniqueAppWatcher below, to create the above UniqueAppHandler object when necessary.
virtual int newInstance()
We can't use k_dcop and dcopidl here, because the data passed to newInstance can't be expressed in te...
If the standalone application is running by itself, we need to watch for when the user closes it,...