akregator_plugin.cpp
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2004 Sashmit Bhaduri <smt@vfemail.net>
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 <tqwidget.h>
26 
27 #include <dcopclient.h>
28 #include <dcopref.h>
29 #include <tdeaboutdata.h>
30 #include <tdeaction.h>
31 #include <tdeapplication.h>
32 #include <tdecmdlineargs.h>
33 #include <kdebug.h>
34 #include <kgenericfactory.h>
35 #include <kiconloader.h>
36 #include <tdemessagebox.h>
37 #include <tdeparts/componentfactory.h>
38 
39 #include <core.h>
40 #include <plugin.h>
41 
42 #include <akregator_options.h>
43 #include <akregator_part.h>
44 #include "akregator_plugin.h"
45 namespace Akregator {
46 
47 typedef KGenericFactory<Akregator::AkregatorPlugin, Kontact::Core > PluginFactory;
48 K_EXPORT_COMPONENT_FACTORY( libkontact_akregator,
49  PluginFactory( "kontact_akregator" ) )
50 
51 AkregatorPlugin::AkregatorPlugin( Kontact::Core *core, const char *, const TQStringList& )
52  : Kontact::Plugin( core, core, "akregator" ), m_stub(0)
53 {
54  setInstance( PluginFactory::instance() );
55 
56  insertNewAction( new TDEAction( i18n( "New Feed..." ), "bookmark_add", CTRL+SHIFT+Key_F, this, TQ_SLOT( addFeed() ), actionCollection(), "feed_new" ) );
57 
58  m_uniqueAppWatcher = new Kontact::UniqueAppWatcher(
60 }
61 
62 AkregatorPlugin::~AkregatorPlugin()
63 {
64 }
65 
66 bool AkregatorPlugin::isRunningStandalone()
67 {
68  return m_uniqueAppWatcher->isRunningStandalone();
69 }
70 
71 TQStringList AkregatorPlugin::invisibleToolbarActions() const
72 {
73  return TQStringList( "file_new_contact" );
74 }
75 
76 
77 Akregator::AkregatorPartIface_stub *AkregatorPlugin::interface()
78 {
79  if ( !m_stub ) {
80  part();
81  }
82 
83  Q_ASSERT( m_stub );
84  return m_stub;
85 }
86 
87 
88 MyBasePart* AkregatorPlugin::createPart()
89 {
90  MyBasePart* p = loadPart();
91 
92  connect(p, TQ_SIGNAL(showPart()), this, TQ_SLOT(showPart()));
93  m_stub = new Akregator::AkregatorPartIface_stub( dcopClient(), "akregator",
94  "AkregatorIface" );
95  m_stub->openStandardFeedList();
96  return p;
97 }
98 
99 
100 void AkregatorPlugin::showPart()
101 {
102  core()->selectPlugin(this);
103 }
104 
105 void AkregatorPlugin::addFeed()
106 {
107  interface()->addFeed();
108 }
109 
110 TQStringList AkregatorPlugin::configModules() const
111 {
112  TQStringList modules;
113  modules << "PIM/akregator.desktop";
114  return modules;
115 }
116 
117 void AkregatorPlugin::readProperties( TDEConfig *config )
118 {
119  if ( part() ) {
120  Akregator::Part *myPart = static_cast<Akregator::Part*>( part() );
121  myPart->readProperties( config );
122  }
123 }
124 
125 void AkregatorPlugin::saveProperties( TDEConfig *config )
126 {
127  if ( part() ) {
128  Akregator::Part *myPart = static_cast<Akregator::Part*>( part() );
129  myPart->saveProperties( config );
130  }
131 }
132 
133 void UniqueAppHandler::loadCommandLineOptions()
134 {
135  TDECmdLineArgs::addCmdLineOptions( akregator_options );
136 }
137 
138 int UniqueAppHandler::newInstance()
139 {
140  kdDebug(5602) << k_funcinfo << endl;
141  // Ensure part is loaded
142  (void)plugin()->part();
143  DCOPRef akr( "akregator", "AkregatorIface" );
144 // DCOPReply reply = kAB.call( "handleCommandLine" );
145  // if ( reply.isValid() ) {
146  // bool handled = reply;
147  // kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
148  // if ( !handled ) // no args -> simply bring kaddressbook plugin to front
150  // }
151  // return 0;
152 }
153 
154 } // namespace Akregator
155 #include "akregator_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,...