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 <kaboutdata.h>
30 #include <kaction.h>
31 #include <kapplication.h>
32 #include <kcmdlineargs.h>
33 #include <kdebug.h>
34 #include <kgenericfactory.h>
35 #include <kiconloader.h>
36 #include <kmessagebox.h>
37 #include <kparts/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::Plugin, Kontact::Core > PluginFactory;
48 K_EXPORT_COMPONENT_FACTORY( libkontact_akregator,
49  PluginFactory( "kontact_akregator" ) )
50 
51 Plugin::Plugin( Kontact::Core *core, const char *, const TQStringList& )
52  : Kontact::Plugin( core, TQT_TQOBJECT(core), "akregator" ), m_stub(0)
53 {
54 
55  setInstance( PluginFactory::instance() );
56 
57  insertNewAction( new KAction( i18n( "New Feed..." ), "bookmark_add", CTRL+SHIFT+Key_F, this, TQT_SLOT( addFeed() ), actionCollection(), "feed_new" ) );
58 
59  m_uniqueAppWatcher = new Kontact::UniqueAppWatcher(
61 }
62 
63 Plugin::~Plugin()
64 {
65 }
66 
67 bool Plugin::isRunningStandalone()
68 {
69  return m_uniqueAppWatcher->isRunningStandalone();
70 }
71 
72 TQStringList Plugin::invisibleToolbarActions() const
73 {
74  return TQStringList( "file_new_contact" );
75 }
76 
77 
78 Akregator::AkregatorPartIface_stub *Plugin::interface()
79 {
80  if ( !m_stub ) {
81  part();
82  }
83 
84  Q_ASSERT( m_stub );
85  return m_stub;
86 }
87 
88 
89 MyBasePart* Plugin::createPart()
90 {
91  MyBasePart* p = loadPart();
92 
93  connect(p, TQT_SIGNAL(showPart()), this, TQT_SLOT(showPart()));
94  m_stub = new Akregator::AkregatorPartIface_stub( dcopClient(), "akregator",
95  "AkregatorIface" );
96  m_stub->openStandardFeedList();
97  return p;
98 }
99 
100 
101 void Plugin::showPart()
102 {
103  core()->selectPlugin(this);
104 }
105 
106 void Plugin::addFeed()
107 {
108  interface()->addFeed();
109 }
110 
111 TQStringList Plugin::configModules() const
112 {
113  TQStringList modules;
114  modules << "PIM/akregator.desktop";
115  return modules;
116 }
117 
118 void Plugin::readProperties( KConfig *config )
119 {
120  if ( part() ) {
121  Akregator::Part *myPart = static_cast<Akregator::Part*>( part() );
122  myPart->readProperties( config );
123  }
124 }
125 
126 void Plugin::saveProperties( KConfig *config )
127 {
128  if ( part() ) {
129  Akregator::Part *myPart = static_cast<Akregator::Part*>( part() );
130  myPart->saveProperties( config );
131  }
132 }
133 
134 void UniqueAppHandler::loadCommandLineOptions()
135 {
136  KCmdLineArgs::addCmdLineOptions( akregator_options );
137 }
138 
139 int UniqueAppHandler::newInstance()
140 {
141  kdDebug(5602) << k_funcinfo << endl;
142  // Ensure part is loaded
143  (void)plugin()->part();
144  DCOPRef akr( "akregator", "AkregatorIface" );
145 // DCOPReply reply = kAB.call( "handleCommandLine" );
146  // if ( reply.isValid() ) {
147  // bool handled = reply;
148  // kdDebug(5602) << k_funcinfo << "handled=" << handled << endl;
149  // if ( !handled ) // no args -> simply bring kaddressbook plugin to front
151  // }
152  // return 0;
153 }
154 
155 } // namespace Akregator
156 #include "akregator_plugin.moc"