kontact

uniqueapphandler.h

00001 /*
00002    This file is part of KDE Kontact.
00003 
00004    Copyright (c) 2003 David Faure <faure@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #ifndef KONTACT_UNIQUEAPPHANDLER_H
00023 #define KONTACT_UNIQUEAPPHANDLER_H
00024 
00025 #include <dcopobject.h>
00026 #include <plugin.h>
00027 #include <kdepimmacros.h>
00028 
00029 namespace Kontact
00030 {
00031 
00039 class KDE_EXPORT UniqueAppHandler : public DCOPObject
00040 {
00041   K_DCOP
00042 
00043   public:
00044     UniqueAppHandler( Plugin* plugin ) : DCOPObject( plugin->name() ), mPlugin( plugin ) {}
00045 
00047     virtual void loadCommandLineOptions() = 0;
00048 
00051     virtual int newInstance();
00052 
00053     Plugin* plugin() const { return mPlugin; }
00054 
00055   private:
00056     Plugin* mPlugin;
00057 };
00058 
00060 class UniqueAppHandlerFactoryBase
00061 {
00062   public:
00063     virtual UniqueAppHandler* createHandler( Plugin* ) = 0;
00064 };
00065 
00072 template <class T> class UniqueAppHandlerFactory : public UniqueAppHandlerFactoryBase
00073 {
00074   public:
00075     virtual UniqueAppHandler* createHandler( Plugin* plugin ) {
00076         (void)plugin->dcopClient(); // ensure that we take over the DCOP name
00077         return new T( plugin );
00078     }
00079 };
00080 
00081 
00089 class KDE_EXPORT UniqueAppWatcher : public QObject
00090 {
00091   Q_OBJECT
00092 
00093   public:
00103     UniqueAppWatcher( UniqueAppHandlerFactoryBase* factory, Plugin* plugin );
00104 
00105     virtual ~UniqueAppWatcher();
00106 
00107     bool isRunningStandalone() const { return mRunningStandalone; }
00108 
00109   protected slots:
00110     void unregisteredFromDCOP( const QCString& appId );
00111 
00112   private:
00113     bool mRunningStandalone;
00114     UniqueAppHandlerFactoryBase* mFactory;
00115     Plugin* mPlugin;
00116 };
00117 
00118 } // namespace
00119 
00120 #endif /* KONTACT_UNIQUEAPPHANDLER_H */
KDE Home | KDE Accessibility Home | Description of Access Keys