1
#ifndef _KVI_KVS_SCRIPTADDONMANAGER_H_
2
#define _KVI_KVS_SCRIPTADDONMANAGER_H_
3
//=============================================================================
5
// File : kvi_kvs_scriptaddonmanager.h
6
// Creation date : Thu 31 Mar 2005 01:21:23 by Szymon Stefanek
8
// This file is part of the KVIrc IRC client distribution
9
// Copyright (C) 2005-2008 Szymon Stefanek <pragma at kvirc dot net>
11
// This program is FREE software. You can redistribute it and/or
12
// modify it under the terms of the GNU General Public License
13
// as published by the Free Software Foundation; either version 2
14
// of the License, or (at your opinion) any later version.
16
// This program is distributed in the HOPE that it will be USEFUL,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
// See the GNU General Public License for more details.
21
// You should have received a copy of the GNU General Public License
22
// along with this program. If not, write to the Free Software Foundation,
23
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
//=============================================================================
27
#include "kvi_settings.h"
28
#include "kvi_heapobject.h"
29
#include "kvi_qstring.h"
30
#include "kvi_pointerhashtable.h"
32
#include <QStringList>
39
class KVIRC_API KviKvsScriptAddon : public KviHeapObject
41
friend class KviKvsScriptAddonManager;
45
const QString &szName,
46
const QString &szVersion,
47
const QString &szVisibleNameCode,
48
const QString &szDescriptionCode,
49
const QString &szUninstallCallbackCode,
50
const QString &szIconId
53
KviKvsScriptAddon(const KviKvsScriptAddon &a);
54
public: // KviDict wants that... how to restrict the deletion to KviKvsScriptAddonManager only ?
57
QString m_szName; // the short name of the addon
58
QString m_szVersion; // x.y.z
59
KviKvsScript * m_pVisibleNameScript; // the visible name, possibly translated
60
KviKvsScript * m_pDescriptionScript; // the description, possibly translated
61
KviKvsScript * m_pUninstallCallback; // uninstall callback
62
KviKvsScript * m_pConfigureCallback; // configure callback
63
KviKvsScript * m_pHelpCallback; // help callback
64
QString m_szDescription; // parsed description
65
QString m_szVisibleName; // parsed visible name
66
QString m_szIconId; // the id of the associated icon
67
QStringList m_lInstalledFiles; // the list of the installed files
69
const QStringList &installedFiles() const { return m_lInstalledFiles; };
70
const QString &name() const { return m_szName; };
71
const QString &version() const { return m_szVersion; };
72
const QString &visibleName();
73
const QString &description();
74
const QString &visibleNameCode();
75
const QString &descriptionCode();
76
const QString &uninstallCallbackCode();
77
const QString &configureCallbackCode();
78
const QString &helpCallbackCode();
79
const QString &iconId(){ return m_szIconId; };
82
/// Register a file to be uninstalled after the uninstall callback.
83
/// The file name *MUST* be relative to the local kvirc directory.
85
void addInstalledFile(const QString &szFileName);
86
void setConfigureCallback(const QString &szConfigureCallbackCode);
87
void setHelpCallback(const QString &szHelpCallbackCode);
88
void executeConfigureCallback(KviWindow * pWnd);
89
void executeHelpCallback(KviWindow * pWnd);
91
bool load(KviConfig * cfg,const QString &szName);
92
void save(KviConfig * cfg);
93
void executeUninstallCallback(KviWindow * pWnd);
94
// this assumes that the script pointers are clean (i.e. not needing to be freed!)
95
void allocateScripts(const QString &sVisibleNameCode,const QString &szDescriptionCode,const QString &szUninstallCallbackCode);
98
class KVIRC_API KviKvsScriptAddonRegistrationData
101
QString szName; // the addon name
102
QString szVersion; // the addon version in form x.y.z
103
QString szVisibleNameScript; // the code that evaluates to the visible name, possibly translated
104
QString szDescriptionScript; // the code that evaluates to the description, possibly translated
105
QString szUninstallCallbackScript; // the uninstall callback code, will be executed at uninstallation
106
QString szIconId; // the icon identifier (scaled to 32x32 atm)
109
class KVIRC_API KviKvsScriptAddonManager
112
KviKvsScriptAddonManager();
113
~KviKvsScriptAddonManager();
115
static KviKvsScriptAddonManager * m_pInstance;
116
// this class implements delayed loading
117
QString m_szFileName; // the file name that we will load from
118
bool m_bLoaded; // have we loaded stuff from disk yet ?
119
KviPointerHashTable<QString,KviKvsScriptAddon> * m_pAddonDict; // all the registered addons
121
static KviKvsScriptAddonManager * instance(){ return m_pInstance; };
122
static void init(); // called by KviKvs::init()
123
static void done(); // called by KviKvs::done()
125
bool registerAddon(KviKvsScriptAddonRegistrationData * d);
126
KviKvsScriptAddon * findAddon(const QString &szName);
127
bool unregisterAddon(const QString &szName,KviWindow * pWnd,bool bExecuteUninstallCallback = true,bool bUninstallFiles = true);
128
KviPointerHashTable<QString,KviKvsScriptAddon> * addonDict();
131
void load(const QString &szFileName); // called in the KviKvs namespace
132
void save(const QString &szFileName); // called in the KViKvs namespace
137
#endif //!_KVI_KVS_SCRIPTADDONMANAGER_H_