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., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 #ifndef KONTACT_UNIQUEAPPHANDLER_H 00023 #define KONTACT_UNIQUEAPPHANDLER_H 00024 00025 #include <dcopobject.h> 00026 #include <plugin.h> 00027 00028 namespace Kontact 00029 { 00030 00038 class UniqueAppHandler : public DCOPObject 00039 { 00040 K_DCOP 00041 public: 00042 UniqueAppHandler( Plugin* plugin ) : DCOPObject( plugin->name() ), mPlugin( plugin ) {} 00043 00045 virtual void loadCommandLineOptions() = 0; 00046 00049 virtual int newInstance(); 00050 00051 Plugin* plugin() const { return mPlugin; } 00052 private: 00053 Plugin* mPlugin; 00054 }; 00055 00057 class UniqueAppHandlerFactoryBase 00058 { 00059 public: 00060 virtual UniqueAppHandler* createHandler( Plugin* ) = 0; 00061 }; 00062 00069 template <class T> class UniqueAppHandlerFactory : public UniqueAppHandlerFactoryBase 00070 { 00071 public: 00072 virtual UniqueAppHandler* createHandler( Plugin* plugin ) { 00073 (void)plugin->dcopClient(); // ensure that we take over the DCOP name 00074 return new T( plugin ); 00075 } 00076 }; 00077 00078 00086 class UniqueAppWatcher : public QObject { 00087 Q_OBJECT 00088 public: 00097 UniqueAppWatcher( UniqueAppHandlerFactoryBase* factory, Plugin* plugin ); 00098 00099 virtual ~UniqueAppWatcher(); 00100 00101 bool isRunningStandalone() const { return mRunningStandalone; } 00102 00103 protected slots: 00104 void unregisteredFromDCOP( const QCString& appId ); 00105 private: 00106 bool mRunningStandalone; 00107 UniqueAppHandlerFactoryBase* mFactory; 00108 Plugin* mPlugin; 00109 }; 00110 00111 } // namespace 00112 00113 #endif /* KONTACT_UNIQUEAPPHANDLER_H */