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 
00056     static void loadKontactCommandLineOptions();
00057 
00058   private:
00059     Plugin* mPlugin;
00060 };
00061 
00063 class UniqueAppHandlerFactoryBase
00064 {
00065   public:
00066     virtual UniqueAppHandler* createHandler( Plugin* ) = 0;
00067 };
00068 
00075 template <class T> class UniqueAppHandlerFactory : public UniqueAppHandlerFactoryBase
00076 {
00077   public:
00078     virtual UniqueAppHandler* createHandler( Plugin* plugin ) {
00079         (void)plugin->dcopClient(); // ensure that we take over the DCOP name
00080         return new T( plugin );
00081     }
00082 };
00083 
00084 
00092 class KDE_EXPORT UniqueAppWatcher : public QObject
00093 {
00094   Q_OBJECT
00095 
00096   public:
00106     UniqueAppWatcher( UniqueAppHandlerFactoryBase* factory, Plugin* plugin );
00107 
00108     virtual ~UniqueAppWatcher();
00109 
00110     bool isRunningStandalone() const { return mRunningStandalone; }
00111 
00112   protected slots:
00113     void unregisteredFromDCOP( const QCString& appId );
00114 
00115   private:
00116     bool mRunningStandalone;
00117     UniqueAppHandlerFactoryBase* mFactory;
00118     Plugin* mPlugin;
00119 };
00120 
00121 } // namespace
00122 
00123 #endif /* KONTACT_UNIQUEAPPHANDLER_H */
KDE Home | KDE Accessibility Home | Description of Access Keys