~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/kvirc/module/kvi_moduleextension.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
//
3
 
//   File : kvi_moduleextension.cpp
4
 
//   Creation date : Tue Sep 10 01:16:25 2002 GMT by Szymon Stefanek
5
 
//
6
 
//   This file is part of the KVirc irc client distribution
7
 
//   Copyright (C) 2002-2008 Szymon Stefanek (pragma at kvirc dot net)
8
 
//
9
 
//   This program is FREE software. You can redistribute it and/or
10
 
//   modify it under the terms of the GNU General Public License
11
 
//   as published by the Free Software Foundation; either version 2
12
 
//   of the License, or (at your opinion) any later version.
13
 
//
14
 
//   This program is distributed in the HOPE that it will be USEFUL,
15
 
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
 
//   See the GNU General Public License for more details.
18
 
//
19
 
//   You should have received a copy of the GNU General Public License
20
 
//   along with this program. If not, write to the Free Software Foundation,
21
 
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
 
//
23
 
//=============================================================================
24
 
 
25
 
#define _KVI_MODULEEXTENSION_CPP_
26
 
 
27
 
#include "kvi_moduleextension.h"
28
 
#include "kvi_module.h"
29
 
#include "kvi_modulemanager.h"
30
 
#include "kvi_app.h"
31
 
 
32
 
// created and destroyed in kvi_app.cpp
33
 
KVIRC_API KviModuleExtensionManager    * g_pModuleExtensionManager    = 0;
34
 
 
35
 
 
36
 
KviModuleExtensionDescriptor::KviModuleExtensionDescriptor(KviModule * m,const KviStr &szType,const KviStr &szName,const QString &szVisibleName,KviModuleExtensionAllocRoutine r,const QPixmap &pix)
37
 
{
38
 
        m_iId = KviApp::getGloballyUniqueId();
39
 
 
40
 
        m_pModule = m;
41
 
        m_szType = szType;
42
 
        m_szName = szName;
43
 
        m_szVisibleName = szVisibleName;
44
 
        m_allocRoutine = r;
45
 
        m_pObjectList = new KviPointerList<KviModuleExtension>;
46
 
        m_pObjectList->setAutoDelete(false);
47
 
        if(pix.isNull())m_pIcon = 0;
48
 
        else m_pIcon = new QPixmap(pix);
49
 
}
50
 
 
51
 
KviModuleExtensionDescriptor::~KviModuleExtensionDescriptor()
52
 
{
53
 
        while(KviModuleExtension * e = m_pObjectList->first())e->die();
54
 
        delete m_pObjectList;
55
 
        if(m_pIcon)delete m_pIcon;
56
 
}
57
 
 
58
 
void KviModuleExtensionDescriptor::setIcon(const QPixmap &pix)
59
 
{
60
 
        if(m_pIcon)delete m_pIcon;
61
 
        if(pix.isNull())m_pIcon = 0;
62
 
        else m_pIcon = new QPixmap(pix);
63
 
}
64
 
 
65
 
KviModuleExtension * KviModuleExtensionDescriptor::allocate(KviWindow * pWnd,KviPointerHashTable<QString,QVariant> * pParams,void * pSpecial)
66
 
{
67
 
        KviModuleExtensionAllocStruct s;
68
 
        s.pDescriptor = this;
69
 
        s.pWindow = pWnd;
70
 
        s.pParams = pParams;
71
 
        s.pSpecial = pSpecial;
72
 
        return m_allocRoutine(&s);
73
 
}
74
 
 
75
 
 
76
 
void KviModuleExtensionDescriptor::registerObject(KviModuleExtension * e)
77
 
{
78
 
        m_pObjectList->append(e);
79
 
}
80
 
 
81
 
void KviModuleExtensionDescriptor::unregisterObject(KviModuleExtension * e)
82
 
{
83
 
        m_pObjectList->removeRef(e);
84
 
}
85
 
 
86
 
 
87
 
KviModuleExtensionManager::KviModuleExtensionManager()
88
 
{
89
 
        m_pExtensionDict = new KviPointerHashTable<const char *,KviModuleExtensionDescriptorList>(17,false);
90
 
        m_pExtensionDict->setAutoDelete(true);
91
 
}
92
 
 
93
 
KviModuleExtensionManager::~KviModuleExtensionManager()
94
 
{
95
 
        delete m_pExtensionDict;
96
 
}
97
 
 
98
 
KviModuleExtensionDescriptorList * KviModuleExtensionManager::getExtensionList(const KviStr &szType)
99
 
{
100
 
        g_pModuleManager->loadModulesByCaps(szType.ptr());
101
 
        return m_pExtensionDict->find(szType.ptr());
102
 
}
103
 
 
104
 
KviModuleExtensionDescriptor * KviModuleExtensionManager::registerExtension(KviModule * m,const KviStr &szType,const KviStr &szName,const QString &szVisibleName,KviModuleExtensionAllocRoutine r,const QPixmap &icon)
105
 
{
106
 
        KviModuleExtensionDescriptor * d = new KviModuleExtensionDescriptor(m,szType,szName,szVisibleName,r,icon);
107
 
        KviModuleExtensionDescriptorList * l = m_pExtensionDict->find(szType.ptr());
108
 
        if(!l)
109
 
        {
110
 
                l = new KviModuleExtensionDescriptorList();
111
 
                l->setAutoDelete(false);
112
 
                m_pExtensionDict->insert(szType.ptr(),l);
113
 
        }
114
 
        l->append(d);
115
 
        return d;
116
 
}
117
 
 
118
 
void KviModuleExtensionManager::unregisterExtensionsByModule(KviModule * m)
119
 
{
120
 
        KviPointerHashTableIterator<const char *,KviModuleExtensionDescriptorList> it(*m_pExtensionDict);
121
 
        KviPointerList<KviStr> dying;
122
 
        dying.setAutoDelete(true);
123
 
        while(KviModuleExtensionDescriptorList * l = it.current())
124
 
        {
125
 
                KviPointerList<KviModuleExtensionDescriptor> dying2;
126
 
                dying2.setAutoDelete(true);
127
 
 
128
 
                for(KviModuleExtensionDescriptor * d = l->first();d;d = l->next())
129
 
                {
130
 
                        if(d->module() == m)dying2.append(d);
131
 
                }
132
 
 
133
 
                for(KviModuleExtensionDescriptor * de = dying2.first();de;de = dying2.next())
134
 
                {
135
 
                        l->removeRef(de);
136
 
                }
137
 
 
138
 
                if(l->isEmpty())dying.append(new KviStr(it.currentKey()));
139
 
                ++it;
140
 
        }
141
 
        for(KviStr * li = dying.first();li;li = dying.next())
142
 
        {
143
 
                m_pExtensionDict->remove(li->ptr());
144
 
        }
145
 
}
146
 
 
147
 
KviModuleExtensionDescriptorList * KviModuleExtensionManager::allocateExtensionGetDescriptorList(const KviStr &szType,const QString &preloadModule)
148
 
{
149
 
        if(!preloadModule.isEmpty())
150
 
        {
151
 
                KviModule * m = g_pModuleManager->getModule(preloadModule);
152
 
                (void)m; // get rid of the unused warning :D
153
 
        }
154
 
 
155
 
        KviModuleExtensionDescriptorList * l = m_pExtensionDict->find(szType.ptr());
156
 
        if(!l)
157
 
        {
158
 
                // retry : it might have been unloaded
159
 
                g_pModuleManager->loadModulesByCaps(szType.ptr());
160
 
                l = m_pExtensionDict->find(szType.ptr());
161
 
        }
162
 
 
163
 
        return l;
164
 
}
165
 
 
166
 
KviModuleExtensionDescriptor * KviModuleExtensionManager::findExtensionDescriptor(const KviStr &szType,const KviStr &szName)
167
 
{
168
 
        KviModuleExtensionDescriptorList * l = m_pExtensionDict->find(szType.ptr());
169
 
        if(!l)return 0;
170
 
 
171
 
        for(KviModuleExtensionDescriptor * d = l->first();d;d = l->next())
172
 
        {
173
 
                if(d->name().equalsCI(szName))return d;
174
 
        }
175
 
 
176
 
        return 0;
177
 
}
178
 
 
179
 
KviModuleExtension * KviModuleExtensionManager::allocateExtension(const KviStr &szType,const KviStr &szName,KviWindow * pWnd,KviPointerHashTable<QString,QVariant> * pParams,void * pSpecial,const QString &preloadModule)
180
 
{
181
 
        KviModuleExtensionDescriptorList * l = allocateExtensionGetDescriptorList(szType,preloadModule);
182
 
        if(!l)return 0;
183
 
 
184
 
        KviModuleExtensionDescriptor * d;
185
 
 
186
 
        for(d = l->first();d;d = l->next())
187
 
        {
188
 
                if(d->name().equalsCI(szName))return d->allocate(pWnd,pParams,pSpecial);
189
 
        }
190
 
 
191
 
        // uhm... not there ?
192
 
        g_pModuleManager->loadModulesByCaps(szType.ptr());
193
 
        // try again after loading the modules
194
 
        // l = m_pExtensionDict->find(szType.ptr()); <--- this shouldn't change!
195
 
        for(d = l->first();d;d = l->next())
196
 
        {
197
 
                if(d->name().equalsCI(szName))return d->allocate(pWnd,pParams,pSpecial);
198
 
        }
199
 
 
200
 
        // no way : no such extension
201
 
 
202
 
        return 0;
203
 
}
204
 
 
205
 
 
206
 
KviModuleExtension * KviModuleExtensionManager::allocateExtension(const KviStr &szType,int id,KviWindow * pWnd,KviPointerHashTable<QString,QVariant> * pParams,void * pSpecial,const QString &preloadModule)
207
 
{
208
 
        KviModuleExtensionDescriptorList * l = allocateExtensionGetDescriptorList(szType,preloadModule);
209
 
        if(!l)return 0;
210
 
 
211
 
        KviModuleExtensionDescriptor * d;
212
 
        for(d = l->first();d;d = l->next())
213
 
        {
214
 
                if(d->id() == id)return d->allocate(pWnd,pParams,pSpecial);
215
 
        }
216
 
 
217
 
        // uhm... not there ?
218
 
        g_pModuleManager->loadModulesByCaps(szType.ptr());
219
 
        // try again after loading the modules
220
 
        // l = m_pExtensionDict->find(szType.ptr()); <--- this shouldn't change!
221
 
        for(d = l->first();d;d = l->next())
222
 
        {
223
 
                if(d->id() == id)return d->allocate(pWnd,pParams,pSpecial);
224
 
        }
225
 
        // no way : no such extension
226
 
 
227
 
        return 0;
228
 
}
229
 
 
230
 
 
231
 
KviModuleExtension::KviModuleExtension(KviModuleExtensionDescriptor * d)
232
 
: KviHeapObject()
233
 
{
234
 
        m_pDescriptor = d;
235
 
        m_pDescriptor->registerObject(this);
236
 
}
237
 
 
238
 
KviModuleExtension::~KviModuleExtension()
239
 
{
240
 
        m_pDescriptor->unregisterObject(this);
241
 
}