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 <tdepimmacros.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     UniqueAppHandlerFactoryBase() {}
00067     virtual ~UniqueAppHandlerFactoryBase() {}
00068     virtual UniqueAppHandler* createHandler( Plugin* ) = 0;
00069 };
00070 
00077 template <class T> class UniqueAppHandlerFactory : public UniqueAppHandlerFactoryBase
00078 {
00079   public:
00080     virtual UniqueAppHandler* createHandler( Plugin* plugin ) {
00081         (void)plugin->dcopClient(); // ensure that we take over the DCOP name
00082         return new T( plugin );
00083     }
00084 };
00085 
00086 
00094 class KDE_EXPORT UniqueAppWatcher : public TQObject
00095 {
00096   Q_OBJECT
00097   
00098 
00099   public:
00109     UniqueAppWatcher( UniqueAppHandlerFactoryBase* factory, Plugin* plugin );
00110 
00111     virtual ~UniqueAppWatcher();
00112 
00113     bool isRunningStandalone() const { return mRunningStandalone; }
00114 
00115   protected slots:
00116     void unregisteredFromDCOP( const TQCString& appId );
00117 
00118   private:
00119     bool mRunningStandalone;
00120     UniqueAppHandlerFactoryBase* mFactory;
00121     Plugin* mPlugin;
00122 };
00123 
00124 } // namespace
00125 
00126 #endif /* KONTACT_UNIQUEAPPHANDLER_H */