2 This file is part of the KDE Kontact Plugin Interface Library.
4 Copyright (c) 2003,2008 David Faure <faure@kde.org>
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.
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.
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.
22 #ifndef KONTACTINTERFACES_UNIQUEAPPHANDLER_H
23 #define KONTACTINTERFACES_UNIQUEAPPHANDLER_H
25 #include "kontactinterfaces_export.h"
32 * D-Bus Object that has the name of the standalone application (e.g. "kmail")
33 * and implements newInstance() so that running the separate application does
34 * the right thing when kontact is running.
35 * By default this means simply bringing the main window to the front,
36 * but newInstance can be reimplemented.
38 class KONTACTINTERFACES_EXPORT UniqueAppHandler
: public QObject
41 // We implement the KUniqueApplication interface
42 Q_CLASSINFO( "D-Bus Interface", "org.kde.KUniqueApplication" )
45 UniqueAppHandler( Plugin
*plugin
);
46 virtual ~UniqueAppHandler();
48 /// This must be reimplemented so that app-specific command line options can be parsed
49 virtual void loadCommandLineOptions() = 0;
51 Plugin
*plugin() const;
54 static void setMainWidget( QWidget
*widget
);
56 public Q_SLOTS
: // DBUS methods
57 int newInstance( const QByteArray
&asn_id
, const QByteArray
&args
);
61 virtual int newInstance();
68 /// Base class for UniqueAppHandler
69 class UniqueAppHandlerFactoryBase
72 virtual ~UniqueAppHandlerFactoryBase(){}
73 virtual UniqueAppHandler
*createHandler( Plugin
* ) = 0;
77 * Used by UniqueAppWatcher below, to create the above UniqueAppHandler object
79 * The template argument is the UniqueAppHandler-derived class.
80 * This allows to remove the need to subclass UniqueAppWatcher.
82 template <class T
> class UniqueAppHandlerFactory
: public UniqueAppHandlerFactoryBase
85 virtual UniqueAppHandler
*createHandler( Plugin
*plugin
) {
86 plugin
->registerClient();
87 return new T( plugin
);
92 * If the standalone application is running by itself, we need to watch
93 * for when the user closes it, and activate the uniqueapphandler then.
94 * This prevents, on purpose, that the standalone app can be restarted.
95 * Kontact takes over from there.
98 class KONTACTINTERFACES_EXPORT UniqueAppWatcher
: public QObject
104 * Create an instance of UniqueAppWatcher, which does everything necessary
105 * for the "unique application" behavior: create the UniqueAppHandler as soon
106 * as possible, i.e. either right now or when the standalone app is closed.
108 * @param factory templatized factory to create the handler. Example:
109 * ... Note that the watcher takes ownership of the factory.
110 * @param plugin is the plugin application
112 UniqueAppWatcher( UniqueAppHandlerFactoryBase
*factory
, Plugin
*plugin
);
114 virtual ~UniqueAppWatcher();
116 bool isRunningStandalone() const;
119 void slotApplicationRemoved( const QString
&name
, const QString
&oldOwner
,
120 const QString
&newOwner
);