uniqueapphandler.h
1 /*
2  This file is part of KDE Kontact.
3 
4  Copyright (c) 2003 David Faure <faure@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library 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 GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #ifndef KONTACT_UNIQUEAPPHANDLER_H
23 #define KONTACT_UNIQUEAPPHANDLER_H
24 
25 #include <dcopobject.h>
26 #include <plugin.h>
27 #include <tdemacros.h>
28 
29 namespace Kontact
30 {
31 
39 class TDE_EXPORT UniqueAppHandler : public DCOPObject
40 {
41  K_DCOP
42 
43  public:
44  UniqueAppHandler( Plugin* plugin ) : DCOPObject( plugin->name() ), mPlugin( plugin ) {}
45 
47  virtual void loadCommandLineOptions() = 0;
48 
51  virtual int newInstance();
52 
53  Plugin* plugin() const { return mPlugin; }
54 
56  static void loadKontactCommandLineOptions();
57 
58  private:
59  Plugin* mPlugin;
60 };
61 
64 {
65  public:
67  virtual ~UniqueAppHandlerFactoryBase() {}
68  virtual UniqueAppHandler* createHandler( Plugin* ) = 0;
69 };
70 
77 template <class T> class UniqueAppHandlerFactory : public UniqueAppHandlerFactoryBase
78 {
79  public:
80  virtual UniqueAppHandler* createHandler( Plugin* plugin ) {
81  (void)plugin->dcopClient(); // ensure that we take over the DCOP name
82  return new T( plugin );
83  }
84 };
85 
86 
94 class TDE_EXPORT UniqueAppWatcher : public TQObject
95 {
96  TQ_OBJECT
97 
98 
99  public:
110 
111  virtual ~UniqueAppWatcher();
112 
113  bool isRunningStandalone() const { return mRunningStandalone; }
114 
115  protected slots:
116  void unregisteredFromDCOP( const TQCString& appId );
117 
118  private:
119  bool mRunningStandalone;
120  UniqueAppHandlerFactoryBase* mFactory;
121  Plugin* mPlugin;
122 };
123 
124 } // namespace
125 
126 #endif /* KONTACT_UNIQUEAPPHANDLER_H */
Base class for all Plugins in Kontact.
Definition: plugin.h:59
DCOPClient * dcopClient() const
Retrieve the current DCOP Client for the plugin.
Definition: plugin.cpp:163
Base class for UniqueAppHandler.
Used by UniqueAppWatcher below, to create the above UniqueAppHandler object when necessary.
DCOP Object that has the name of the standalone application (e.g.
virtual void loadCommandLineOptions()=0
This must be reimplemented so that app-specific command line options can be parsed.
If the standalone application is running by itself, we need to watch for when the user closes it,...