1
/****************************************************************************
2
** uniquewindow.cpp - helps keep track of unique windows
3
** Copyright (C) 2001, 2002 Justin Karneges
5
** This program is free software; you can redistribute it and/or
6
** modify it under the terms of the GNU General Public License
7
** as published by the Free Software Foundation; either version 2
8
** of the License, or (at your option) any later version.
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
19
****************************************************************************/
21
#include"uniquewindow.h"
23
static UniqueWindowBank UWB;
25
/****************************************************************************
27
****************************************************************************/
28
UniqueWindowBank::UniqueWindowBank()
32
UniqueWindowBank::~UniqueWindowBank()
34
for(UniqueWindowBankItem *i = list.first(); i;) {
42
void UniqueWindowBank::add(const QString &type, void *p, const QString &key)
44
// see if we already have the type
45
UniqueWindowBankItem *i;
46
for(i = list.first(); i; i = list.next()) {
51
i = new UniqueWindowBankItem;
53
i->dict = new QDict<void>(17,FALSE);
57
i->dict->insert(key, p);
59
//printf("Registering: type=%s, jid=%s, p=[%p]\n", type.latin1(), jid.latin1(), p);
62
void UniqueWindowBank::remove(const QString &type, const QString &key)
64
// see if we already have the type
65
UniqueWindowBankItem *i;
66
for(i = list.first(); i; i = list.next()) {
75
// last entry? remove it
76
if(i->dict->count() == 0) {
82
//printf("UnRegistering: type=%s, jid=%s\n", type.latin1(), jid.latin1());
85
void * UniqueWindowBank::finditem(const QString &type, const QString &key)
88
UniqueWindowBankItem *i;
89
for(i = list.first(); i; i = list.next()) {
94
//printf("finditem: no such type! [%s]\n", type.latin1());
98
void *p = i->dict->find(key);
100
//printf("finditem: type=%s, jid=%s, found=[%p]\n", type.latin1(), jid.latin1(), p);
105
/*static*/ void * UniqueWindowBank::find(const QString &type, const QString &key)
107
return UWB.finditem(type, key);
111
/****************************************************************************
113
****************************************************************************/
114
UniqueWindow::UniqueWindow(bool xisUnique, const QString &xtype, void *p, const QString &xkey)
116
v_isUnique = xisUnique;
122
UWB.add(v_type, p, v_key);
126
UniqueWindow::~UniqueWindow()
129
UWB.remove(v_type, v_key);