~ubuntu-branches/ubuntu/hoary/psi/hoary

« back to all changes in this revision

Viewing changes to src/uniquewindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
** uniquewindow.cpp - helps keep track of unique windows
3
 
** Copyright (C) 2001, 2002  Justin Karneges
4
 
**
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.
9
 
**
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.
14
 
**
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.
18
 
**
19
 
****************************************************************************/
20
 
 
21
 
#include"uniquewindow.h"
22
 
 
23
 
static UniqueWindowBank UWB;
24
 
 
25
 
/****************************************************************************
26
 
  UniqueWindowBank
27
 
****************************************************************************/
28
 
UniqueWindowBank::UniqueWindowBank()
29
 
{
30
 
}
31
 
 
32
 
UniqueWindowBank::~UniqueWindowBank()
33
 
{
34
 
        for(UniqueWindowBankItem *i = list.first(); i;) {
35
 
                list.remove(i);
36
 
                delete i->dict;
37
 
                delete i;
38
 
                i = list.current();
39
 
        }
40
 
}
41
 
 
42
 
void UniqueWindowBank::add(const QString &type, void *p, const QString &key)
43
 
{
44
 
        // see if we already have the type
45
 
        UniqueWindowBankItem *i;
46
 
        for(i = list.first(); i; i = list.next()) {
47
 
                if(i->type == type)
48
 
                        break;
49
 
        }
50
 
        if(!i) {
51
 
                i = new UniqueWindowBankItem;
52
 
                i->type = type;
53
 
                i->dict = new QDict<void>(17,FALSE);
54
 
                list.insert(0, i);
55
 
        }
56
 
 
57
 
        i->dict->insert(key, p);
58
 
 
59
 
        //printf("Registering: type=%s, jid=%s, p=[%p]\n", type.latin1(), jid.latin1(), p);
60
 
}
61
 
 
62
 
void UniqueWindowBank::remove(const QString &type, const QString &key)
63
 
{
64
 
        // see if we already have the type
65
 
        UniqueWindowBankItem *i;
66
 
        for(i = list.first(); i; i = list.next()) {
67
 
                if(i->type == type)
68
 
                        break;
69
 
        }
70
 
        if(!i)
71
 
                return;
72
 
 
73
 
        i->dict->remove(key);
74
 
 
75
 
        // last entry?  remove it
76
 
        if(i->dict->count() == 0) {
77
 
                list.remove(i);
78
 
                delete i->dict;
79
 
                delete i;
80
 
        }
81
 
 
82
 
        //printf("UnRegistering: type=%s, jid=%s\n", type.latin1(), jid.latin1());
83
 
}
84
 
 
85
 
void * UniqueWindowBank::finditem(const QString &type, const QString &key)
86
 
{
87
 
        // find the bank item
88
 
        UniqueWindowBankItem *i;
89
 
        for(i = list.first(); i; i = list.next()) {
90
 
                if(i->type == type)
91
 
                        break;
92
 
        }
93
 
        if(!i) {
94
 
                //printf("finditem: no such type! [%s]\n", type.latin1());
95
 
                return 0;
96
 
        }
97
 
 
98
 
        void *p = i->dict->find(key);
99
 
 
100
 
        //printf("finditem: type=%s, jid=%s, found=[%p]\n", type.latin1(), jid.latin1(), p);
101
 
 
102
 
        return p;
103
 
}
104
 
 
105
 
/*static*/ void * UniqueWindowBank::find(const QString &type, const QString &key)
106
 
{
107
 
        return UWB.finditem(type, key);
108
 
}
109
 
 
110
 
 
111
 
/****************************************************************************
112
 
  UniqueWindow
113
 
****************************************************************************/
114
 
UniqueWindow::UniqueWindow(bool xisUnique, const QString &xtype, void *p, const QString &xkey)
115
 
{
116
 
        v_isUnique = xisUnique;
117
 
 
118
 
        if(v_isUnique) {
119
 
                v_key = xkey;
120
 
                v_type = xtype;
121
 
 
122
 
                UWB.add(v_type, p, v_key);
123
 
        }
124
 
}
125
 
 
126
 
UniqueWindow::~UniqueWindow()
127
 
{
128
 
        if(v_isUnique)
129
 
                UWB.remove(v_type, v_key);
130
 
}