~ubuntu-branches/ubuntu/edgy/psi/edgy

« back to all changes in this revision

Viewing changes to src/jabcommon.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2002-04-19 02:28:44 UTC
  • Revision ID: james.westby@ubuntu.com-20020419022844-za7xgai5qyfd9xv6
Tags: upstream-0.8.5
ImportĀ upstreamĀ versionĀ 0.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** jabcommon.cpp - common classes and functions for handling Jabber data
 
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"jabcommon.h"
 
22
#include<qregexp.h>
 
23
#include<qobject.h>
 
24
 
 
25
 
 
26
QString lineEncode(QString str)
 
27
{
 
28
        str.replace(QRegExp("\\\\"), "\\\\");   // backslash to double-backslash
 
29
        str.replace(QRegExp("\\|"), "\\p");     // pipe to \p
 
30
        str.replace(QRegExp("\n"), "\\n");      // newline to \n
 
31
        return str;
 
32
}
 
33
 
 
34
QString lineDecode(const QString &str)
 
35
{
 
36
        QString ret;
 
37
 
 
38
        for(unsigned int n = 0; n < str.length(); ++n) {
 
39
                if(str.at(n) == '\\') {
 
40
                        ++n;
 
41
                        if(n >= str.length())
 
42
                                break;
 
43
 
 
44
                        if(str.at(n) == 'n')
 
45
                                ret.append('\n');
 
46
                        if(str.at(n) == 'p')
 
47
                                ret.append('|');
 
48
                        if(str.at(n) == '\\')
 
49
                                ret.append('\\');
 
50
                }
 
51
                else {
 
52
                        ret.append(str.at(n));
 
53
                }
 
54
        }
 
55
 
 
56
        return ret;
 
57
}
 
58
 
 
59
QString lineEncodeList(QStringList list)
 
60
{
 
61
        QString str = "";
 
62
 
 
63
        int n = 0;
 
64
        for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
 
65
                if(n > 0)
 
66
                        str += '|';
 
67
                str += lineEncode(*it);
 
68
                ++n;
 
69
        }
 
70
 
 
71
        return lineEncode(str);
 
72
}
 
73
 
 
74
QStringList lineDecodeList(const QString &in)
 
75
{
 
76
        QString str = lineDecode(in);
 
77
        QStringList list;
 
78
 
 
79
        int p1 = 0;
 
80
        int p2;
 
81
        while(p1 != -1) {
 
82
                p2 = str.find('|', p1);
 
83
                QString chunk;
 
84
                if(p2 == -1) {
 
85
                        chunk = str.mid(p1);
 
86
                        p1 = -1;
 
87
                }
 
88
                else {
 
89
                        chunk = str.mid(p1, p2-p1);
 
90
                        p1 = p2 + 1;
 
91
                }
 
92
 
 
93
                list.append(lineDecode(chunk));
 
94
        }
 
95
 
 
96
        return list;
 
97
}
 
98
 
 
99
 
 
100
QString status2jabprestxt(int status)
 
101
{
 
102
        switch(status) {
 
103
                case STATUS_AWAY:       return "away";
 
104
                case STATUS_XA:         return "xa";
 
105
                case STATUS_DND:        return "dnd";
 
106
        }
 
107
 
 
108
        return "";
 
109
}
 
110
 
 
111
int jabprestxt2status(const QString &str)
 
112
{
 
113
        if(str == "away")       return STATUS_AWAY;
 
114
        else if(str == "xa")    return STATUS_XA;
 
115
        else if(str == "dnd")   return STATUS_DND;
 
116
        else
 
117
                return STATUS_ONLINE;
 
118
}
 
119
 
 
120
QString cleanJid(QString jid)
 
121
{
 
122
        int x = jid.find('/');
 
123
        if(x) {
 
124
                jid.truncate(x);
 
125
        }
 
126
 
 
127
        return jid;
 
128
}
 
129
 
 
130
bool jidcmp(const QString &jid1, const QString &jid2)
 
131
{
 
132
        QString jid1clean = cleanJid(jid1);
 
133
        QString jid2clean = cleanJid(jid2);
 
134
 
 
135
        if(jid1clean.length() != jid2clean.length())
 
136
                return 0;
 
137
 
 
138
        for(unsigned int n = 0; n < jid1clean.length(); ++n) {
 
139
                if(jid1clean.at(n).lower() != jid2clean.at(n).lower())
 
140
                        return 0;
 
141
        }
 
142
 
 
143
        return 1;
 
144
}
 
145
 
 
146
bool jidIsAgent(const QString &jid)
 
147
{
 
148
        return (jid.find('@') == -1) ? TRUE : FALSE;
 
149
}
 
150
 
 
151
 
 
152
/****************************************************************************
 
153
  Jid
 
154
****************************************************************************/
 
155
Jid::Jid()
 
156
{
 
157
}
 
158
 
 
159
Jid::Jid(const QString &s)
 
160
{
 
161
        set(s);
 
162
}
 
163
 
 
164
void Jid::set(const QString &s)
 
165
{
 
166
        int n, n2;
 
167
 
 
168
        realJid = s;
 
169
        if(s.isEmpty())
 
170
                return;
 
171
 
 
172
        // user
 
173
        v_user = "";
 
174
        n = realJid.find('@');
 
175
        if(n != -1)
 
176
                v_user = realJid.mid(0, n);
 
177
 
 
178
        // host: locate the '@'
 
179
        n = realJid.find('@');
 
180
        if(n == -1)
 
181
                n = 0;
 
182
        else
 
183
                ++n;
 
184
        // host: locate the '/'
 
185
        n2 = realJid.find('/', n);
 
186
        if(n2 == -1)
 
187
                v_host = realJid.mid(n);
 
188
        else
 
189
                v_host = realJid.mid(n, n2-n);
 
190
 
 
191
        // resource
 
192
        v_resource = "";
 
193
        n = realJid.find('/');
 
194
        if(n != -1)
 
195
                v_resource = realJid.mid(n+1);
 
196
 
 
197
        // s
 
198
        n = realJid.find('/');
 
199
        if(n == -1)
 
200
                v_s = realJid;
 
201
        else
 
202
                v_s = realJid.mid(0, n);
 
203
 
 
204
        // isAgent
 
205
        v_isAgent = realJid.find('@') == -1 ? TRUE: FALSE;
 
206
}
 
207
 
 
208
Jid & Jid::operator=(const QString &s)
 
209
{
 
210
        this->set(s);
 
211
        return *this;
 
212
}
 
213
 
 
214
bool operator==(const Jid &j1, const Jid &j2)
 
215
{
 
216
        if(j1.s().length() != j2.s().length())
 
217
                return FALSE;
 
218
 
 
219
        for(unsigned int n = 0; n < j1.s().length(); ++n) {
 
220
                if(j1.s().at(n).lower() != j2.s().at(n).lower())
 
221
                        return FALSE;
 
222
        }
 
223
 
 
224
        return TRUE;
 
225
}
 
226
 
 
227
 
 
228
/****************************************************************************
 
229
  JabFormField
 
230
****************************************************************************/
 
231
JabFormField::JabFormField()
 
232
{
 
233
        v_type = misc;
 
234
}
 
235
 
 
236
QString JabFormField::realName()
 
237
{
 
238
        switch(v_type) {
 
239
                case username:  return "username";
 
240
                case nick:      return "nick";
 
241
                case password:  return "password";
 
242
                case name:      return "name";
 
243
                case first:     return "first";
 
244
                case last:      return "last";
 
245
                case email:     return "email";
 
246
                case address:   return "address";
 
247
                case city:      return "city";
 
248
                case state:     return "state";
 
249
                case zip:       return "zipcode";
 
250
                case phone:     return "phone";
 
251
                case url:       return "url";
 
252
                case date:      return "date";
 
253
                case misc:      return "misc";
 
254
                default:        return "";
 
255
        };
 
256
}
 
257
 
 
258
QString JabFormField::fieldName()
 
259
{
 
260
        switch(v_type) {
 
261
                case username:  return QObject::tr("Username");
 
262
                case nick:      return QObject::tr("Nickname");
 
263
                case password:  return QObject::tr("Password");
 
264
                case name:      return QObject::tr("Name");
 
265
                case first:     return QObject::tr("First Name");
 
266
                case last:      return QObject::tr("Last Name");
 
267
                case email:     return QObject::tr("E-mail");
 
268
                case address:   return QObject::tr("Address");
 
269
                case city:      return QObject::tr("City");
 
270
                case state:     return QObject::tr("State");
 
271
                case zip:       return QObject::tr("Zipcode");
 
272
                case phone:     return QObject::tr("Phone");
 
273
                case url:       return QObject::tr("URL");
 
274
                case date:      return QObject::tr("Date");
 
275
                case misc:      return QObject::tr("Misc");
 
276
                default:        return "";
 
277
        };
 
278
}
 
279
 
 
280
void JabFormField::setType(int x)
 
281
{
 
282
        v_type = x;
 
283
}
 
284
 
 
285
bool JabFormField::setType(const QString &in)
 
286
{
 
287
        int x = str2type(in);
 
288
        if(x == -1)
 
289
                return FALSE;
 
290
 
 
291
        v_type = x;
 
292
        return TRUE;
 
293
}
 
294
 
 
295
void JabFormField::setValue(const QString &in)
 
296
{
 
297
        v_value = in;
 
298
}
 
299
 
 
300
int JabFormField::str2type(const QString &in)
 
301
{
 
302
        if(!in.compare("username")) return username;
 
303
        if(!in.compare("nick"))     return nick;
 
304
        if(!in.compare("password")) return password;
 
305
        if(!in.compare("name"))     return name;
 
306
        if(!in.compare("first"))    return first;
 
307
        if(!in.compare("last"))     return last;
 
308
        if(!in.compare("email"))    return email;
 
309
        if(!in.compare("address"))  return address;
 
310
        if(!in.compare("city"))     return city;
 
311
        if(!in.compare("state"))    return state;
 
312
        if(!in.compare("zip"))      return zip;
 
313
        if(!in.compare("phone"))    return phone;
 
314
        if(!in.compare("url"))      return url;
 
315
        if(!in.compare("date"))     return date;
 
316
        if(!in.compare("misc"))     return misc;
 
317
 
 
318
        return -1;
 
319
}
 
320
 
 
321
 
 
322
/****************************************************************************
 
323
  JabForm
 
324
****************************************************************************/
 
325
JabForm::JabForm()
 
326
{
 
327
        setAutoDelete(TRUE);
 
328
};
 
329
 
 
330
JabForm::JabForm(const JabForm &from)
 
331
:QPtrList<JabFormField>()
 
332
{
 
333
        *this = from;
 
334
}
 
335
 
 
336
// deep copy
 
337
JabForm & JabForm::operator=(const JabForm &from)
 
338
{
 
339
        clear();
 
340
 
 
341
        QPtrListIterator<JabFormField> it(from);
 
342
        JabFormField *f;
 
343
        for(; (f = it.current()); ++it)
 
344
                append(new JabFormField(*f));
 
345
 
 
346
        jid = from.jid;
 
347
        instructions = from.instructions;
 
348
        key = from.key;
 
349
 
 
350
        return *this;
 
351
}
 
352
 
 
353
JabFormField *JabForm::find(int type) const
 
354
{
 
355
        QPtrListIterator<JabFormField> it(*this);
 
356
        JabFormField *f;
 
357
        for(; (f = it.current()); ++it) {
 
358
                if(f->type() == type)
 
359
                        return f;
 
360
        }
 
361
 
 
362
        return 0;
 
363
}
 
364
 
 
365
 
 
366
/****************************************************************************
 
367
  JabRoster - holds a bunch of JabRosterEntries
 
368
****************************************************************************/
 
369
JabRoster::JabRoster()
 
370
{
 
371
        list.setAutoDelete(TRUE);
 
372
}
 
373
 
 
374
JabRoster::~JabRoster()
 
375
{
 
376
        //printf("JabRoster: destructing [%d]\n", list.count());
 
377
}
 
378
 
 
379
JabRoster::JabRoster(const JabRoster &from)
 
380
{
 
381
        //printf("JabRoster: copy()\n");
 
382
 
 
383
        *this = from;
 
384
/*      list.clear();
 
385
        QPtrList<JabRosterEntry> fromlist = from.list;
 
386
        for(JabRosterEntry *entry = fromlist.first(); entry; entry = fromlist.next())
 
387
                add(entry);*/
 
388
}
 
389
 
 
390
JabRoster & JabRoster::operator=(const JabRoster &from)
 
391
{
 
392
        //printf("JabRoster: assignment\n");
 
393
 
 
394
        //printf("JabRoster: deleting %d contacts.\n", list.count());
 
395
        list.clear();
 
396
        QPtrList<JabRosterEntry> fromlist = from.list;
 
397
        for(JabRosterEntry *entry = fromlist.first(); entry; entry = fromlist.next())
 
398
                add(new JabRosterEntry(*entry));
 
399
 
 
400
        //printf("JabRoster: list now has %d contacts.\n", list.count());
 
401
 
 
402
        return *this;
 
403
}
 
404
 
 
405
int JabRoster::size()
 
406
{
 
407
        return list.count();
 
408
}
 
409
 
 
410
JabRosterEntry *JabRoster::first()
 
411
{
 
412
        return list.first();
 
413
}
 
414
 
 
415
JabRosterEntry *JabRoster::current()
 
416
{
 
417
        return list.current();
 
418
}
 
419
 
 
420
JabRosterEntry *JabRoster::next()
 
421
{
 
422
        return list.next();
 
423
}
 
424
 
 
425
JabRosterEntry *JabRoster::getFirst() const
 
426
{
 
427
        return list.getFirst();
 
428
}
 
429
 
 
430
void JabRoster::add(JabRosterEntry *entry)
 
431
{
 
432
        list.append(entry);
 
433
}
 
434
 
 
435
void JabRoster::remove(JabRosterEntry *entry)
 
436
{
 
437
        list.remove(entry);
 
438
}
 
439
 
 
440
void JabRoster::clear()
 
441
{
 
442
        list.clear();
 
443
}
 
444
 
 
445
JabRosterEntry *JabRoster::findByJid(const QString &jid)
 
446
{
 
447
        QPtrListIterator<JabRosterEntry> it(list);
 
448
        JabRosterEntry *entry;
 
449
 
 
450
        for( ; it.current(); ++it) {
 
451
                entry = it.current();
 
452
                if(jidcmp(entry->jid,jid))
 
453
                        return entry;
 
454
        }
 
455
        return 0;
 
456
}
 
457
 
 
458
JabRosterEntry *JabRoster::findByNick(const QString &nick)
 
459
{
 
460
        QPtrListIterator<JabRosterEntry> it(list);
 
461
        JabRosterEntry *entry;
 
462
 
 
463
        for( ; it.current(); ++it) {
 
464
                entry = it.current();
 
465
                if(entry->nick == nick)
 
466
                        return entry;
 
467
        }
 
468
        return 0;
 
469
}
 
470
 
 
471
 
 
472
/****************************************************************************
 
473
  JabRosterEntry - holds minimal contact info
 
474
****************************************************************************/
 
475
JabRosterEntry::JabRosterEntry()
 
476
{
 
477
        ask = 0;
 
478
        push = FALSE;
 
479
 
 
480
        isRegisterable = isSearchable = isGCCapable = hasSubAgents = isTransport = FALSE;
 
481
 
 
482
        flagForDelete = FALSE;
 
483
}
 
484
 
 
485
JabRosterEntry::~JabRosterEntry()
 
486
{
 
487
}
 
488
 
 
489
bool JabRosterEntry::isAvailable() const
 
490
{
 
491
        return res.isEmpty() ? FALSE: TRUE;
 
492
}
 
493
 
 
494
JabResource *JabRosterEntry::local() const
 
495
{
 
496
        return res.local();
 
497
}
 
498
 
 
499
JabResource *JabRosterEntry::priority() const
 
500
{
 
501
        return res.priority();
 
502
}
 
503
 
 
504
int JabRosterEntry::localStatus() const
 
505
{
 
506
        if(isAvailable())
 
507
                return res.local()->status;
 
508
        else
 
509
                return STATUS_OFFLINE;
 
510
}
 
511
 
 
512
 
 
513
 
 
514
/****************************************************************************
 
515
  VCard
 
516
****************************************************************************/
 
517
VCard::VCard()
 
518
{
 
519
}
 
520
 
 
521
QString VCard::tagContent(const QDomElement &e)
 
522
{
 
523
        // look for some tag content
 
524
        for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
 
525
                QDomText i = n.toText();
 
526
                if(i.isNull())
 
527
                        continue;
 
528
                return i.data();
 
529
        }
 
530
 
 
531
        return "";
 
532
}
 
533
 
 
534
QDomElement VCard::findSubTag(const QDomElement &e, const QString &name, bool *found)
 
535
{
 
536
        if(found)
 
537
                *found = FALSE;
 
538
 
 
539
        for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
 
540
                QDomElement i = n.toElement();
 
541
                if(i.isNull())
 
542
                        continue;
 
543
                if(i.tagName() == name) {
 
544
                        if(found)
 
545
                                *found = TRUE;
 
546
                        return i;
 
547
                }
 
548
        }
 
549
 
 
550
        QDomElement tmp;
 
551
        return tmp;
 
552
}
 
553
 
 
554
QDomElement VCard::textTag(const QString &name, const QString &content)
 
555
{
 
556
        QDomElement tag = doc.createElement(name);
 
557
        QDomText text = doc.createTextNode(content);
 
558
        tag.appendChild(text);
 
559
 
 
560
        return tag;
 
561
}
 
562
 
 
563
QDomElement VCard::toXml()
 
564
{
 
565
        QDomElement v = doc.createElement("vCard");
 
566
        v.setAttribute("version", "3.0");
 
567
        v.setAttribute("prodid", "-//HandGen//NONSGML vGen v1.0//EN");
 
568
        v.setAttribute("xmlns", "vcard-temp"); // <-- FIXME: how to do namespace attributes?
 
569
 
 
570
        if(!field[vFullname].isEmpty())
 
571
                v.appendChild(textTag("FN", field[vFullname]));
 
572
        if(!field[vNickname].isEmpty())
 
573
                v.appendChild(textTag("NICKNAME", field[vNickname]));
 
574
        if(!field[vDesc].isEmpty())
 
575
                v.appendChild(textTag("DESC", field[vDesc]));
 
576
        if(!field[vEmail].isEmpty())
 
577
                v.appendChild(textTag("EMAIL", field[vEmail]));
 
578
        if(!field[vBday].isEmpty())
 
579
                v.appendChild(textTag("BDAY", field[vBday]));
 
580
        if(!field[vHomepage].isEmpty())
 
581
                v.appendChild(textTag("URL", field[vHomepage]));
 
582
 
 
583
        if(1) {
 
584
                QDomElement w = doc.createElement("ORG");
 
585
                if(!field[vOrgName].isEmpty())
 
586
                        w.appendChild(textTag("ORGNAME", field[vOrgName]));
 
587
                if(!field[vOrgUnit].isEmpty())
 
588
                        w.appendChild(textTag("ORGUNIT", field[vOrgUnit]));
 
589
                v.appendChild(w);
 
590
        }
 
591
 
 
592
        if(!field[vTitle].isEmpty())
 
593
                v.appendChild(textTag("TITLE", field[vTitle]));
 
594
        if(!field[vRole].isEmpty())
 
595
                v.appendChild(textTag("ROLE", field[vRole]));
 
596
        if(!field[vPhone].isEmpty()) {
 
597
                QDomElement w = doc.createElement("TEL");
 
598
 
 
599
                QDomElement x = doc.createElement("HOME");
 
600
                w.appendChild(x);
 
601
 
 
602
                w.appendChild(textTag("VOICE", field[vPhone]));
 
603
 
 
604
                v.appendChild(w);
 
605
        }
 
606
 
 
607
        if(1) {
 
608
                QDomElement w = doc.createElement("ADR");
 
609
 
 
610
                QDomElement x = doc.createElement("HOME");
 
611
                w.appendChild(x);
 
612
 
 
613
                if(!field[vStreet].isEmpty())
 
614
                        w.appendChild(textTag("STREET", field[vStreet]));
 
615
                if(!field[vExt].isEmpty())
 
616
                        w.appendChild(textTag("EXTADD", field[vExt]));
 
617
                if(!field[vCity].isEmpty())
 
618
                        w.appendChild(textTag("LOCALITY", field[vCity]));
 
619
                if(!field[vState].isEmpty())
 
620
                        w.appendChild(textTag("REGION", field[vState]));
 
621
                if(!field[vPcode].isEmpty())
 
622
                        w.appendChild(textTag("PCODE", field[vPcode]));
 
623
                if(!field[vCountry].isEmpty())
 
624
                        w.appendChild(textTag("COUNTRY", field[vCountry]));
 
625
 
 
626
                v.appendChild(w);
 
627
        }
 
628
 
 
629
        xml = v;
 
630
        return xml;
 
631
}
 
632
 
 
633
bool VCard::fromXml(const QDomElement &q)
 
634
{
 
635
        if(q.tagName() != "vcard")
 
636
                return FALSE;
 
637
        //if(q.attribute("version") != "3.0")
 
638
        //      return FALSE;
 
639
 
 
640
        xml = q;
 
641
        for(QDomNode n = q.firstChild(); !n.isNull(); n = n.nextSibling()) {
 
642
                QDomElement i = n.toElement();
 
643
                if(i.isNull())
 
644
                        continue;
 
645
 
 
646
                if(i.tagName() == "fn")
 
647
                        field[vFullname] = tagContent(i);
 
648
                else if(i.tagName() == "nickname")
 
649
                        field[vNickname] = tagContent(i);
 
650
                else if(i.tagName() == "desc")
 
651
                        field[vDesc] = tagContent(i);
 
652
                else if(i.tagName() == "email") {
 
653
                        // email tag is weird.  check parent first
 
654
                        QString str = tagContent(i);
 
655
                        if(str.isEmpty()) {
 
656
                                // check children
 
657
                                for(QDomNode n = i.firstChild(); !n.isNull(); n = n.nextSibling()) {
 
658
                                        QDomElement e = n.toElement();
 
659
                                        if(e.isNull())
 
660
                                                continue;
 
661
                                        str = tagContent(e);
 
662
                                        if(!str.isEmpty())
 
663
                                                break;
 
664
                                }
 
665
                        }
 
666
                        field[vEmail] = str;
 
667
                }
 
668
                else if(i.tagName() == "bday")
 
669
                        field[vBday] = tagContent(i);
 
670
                else if(i.tagName() == "url")
 
671
                        field[vHomepage] = tagContent(i);
 
672
                else if(i.tagName() == "org") {
 
673
                        bool found;
 
674
                        QDomElement tag = findSubTag(i, "orgname", &found);
 
675
                        if(found)
 
676
                                field[vOrgName] = tagContent(tag);
 
677
                        tag = findSubTag(i, "orgunit", &found);
 
678
                        if(found)
 
679
                                field[vOrgUnit] = tagContent(tag);
 
680
                }
 
681
                else if(i.tagName() == "title")
 
682
                        field[vTitle] = tagContent(i);
 
683
                else if(i.tagName() == "role")
 
684
                        field[vRole] = tagContent(i);
 
685
                else if(i.tagName() == "tel") {
 
686
                        bool found;
 
687
                        int type = 0;
 
688
                        QDomElement tag;
 
689
 
 
690
                        findSubTag(i, "home", &found);
 
691
                        if(found)
 
692
                                type = 1;
 
693
 
 
694
                        tag = findSubTag(i, "voice", &found);
 
695
                        if(found) {
 
696
                                if(type == 1)
 
697
                                        field[vPhone] = tagContent(tag);
 
698
                        }
 
699
                }
 
700
                else if(i.tagName() == "adr") {
 
701
                        bool found;
 
702
                        int type = 0;
 
703
                        QDomElement tag;
 
704
 
 
705
                        findSubTag(i, "home", &found);
 
706
                        if(found)
 
707
                                type = 1;
 
708
                        findSubTag(i, "work", &found);
 
709
                        if(found)
 
710
                                type = 2;
 
711
 
 
712
                        if(type == 1) {
 
713
                                tag = findSubTag(i, "extadd", &found);
 
714
                                if(found)
 
715
                                        field[vExt] = tagContent(tag);
 
716
                                tag = findSubTag(i, "street", &found);
 
717
                                if(found)
 
718
                                        field[vStreet] = tagContent(tag);
 
719
                                tag = findSubTag(i, "locality", &found);
 
720
                                if(found)
 
721
                                        field[vCity] = tagContent(tag);
 
722
                                tag = findSubTag(i, "region", &found);
 
723
                                if(found)
 
724
                                        field[vState] = tagContent(tag);
 
725
                                tag = findSubTag(i, "pcode", &found);
 
726
                                if(found)
 
727
                                        field[vPcode] = tagContent(tag);
 
728
                                tag = findSubTag(i, "country", &found);
 
729
                                if(found)
 
730
                                        field[vCountry] = tagContent(tag);
 
731
                        }
 
732
                }
 
733
        }
 
734
 
 
735
        return TRUE;
 
736
}
 
737
 
 
738
bool VCard::isIncomplete()
 
739
{
 
740
        for(int n = 0; n < NUM_VCARDFIELDS; ++n) {
 
741
                if(!field[n].isEmpty())
 
742
                        return FALSE;
 
743
        }
 
744
        return TRUE;
 
745
}
 
746
 
 
747
 
 
748
/****************************************************************************
 
749
  JabResource
 
750
****************************************************************************/
 
751
JabResource::JabResource()
 
752
{
 
753
        name = "";
 
754
        priority = 0;
 
755
        status = STATUS_OFFLINE;
 
756
        statusString = "";
 
757
}
 
758
 
 
759
 
 
760
/****************************************************************************
 
761
  JabResourceList - holds a list of resources
 
762
****************************************************************************/
 
763
JabResourceList::JabResourceList()
 
764
{
 
765
        setAutoDelete(TRUE);
 
766
};
 
767
 
 
768
JabResourceList::JabResourceList(const JabResourceList &from)
 
769
:QPtrList<JabResource>()
 
770
{
 
771
        *this = from;
 
772
}
 
773
 
 
774
// deep copy
 
775
JabResourceList & JabResourceList::operator=(const JabResourceList &from)
 
776
{
 
777
        clear();
 
778
 
 
779
        QPtrListIterator<JabResource> it(from);
 
780
        JabResource *r;
 
781
        for(; (r = it.current()); ++it)
 
782
                append(new JabResource(*r));
 
783
 
 
784
        return *this;
 
785
}
 
786
 
 
787
JabResource *JabResourceList::find(const QString &name) const
 
788
{
 
789
        QPtrListIterator<JabResource> it(*this);
 
790
        JabResource *r;
 
791
        for(; (r = it.current()); ++it) {
 
792
                if(r->name == name)
 
793
                        return r;
 
794
        }
 
795
 
 
796
        return 0;
 
797
}
 
798
 
 
799
JabResource *JabResourceList::local() const
 
800
{
 
801
        return getFirst();
 
802
}
 
803
 
 
804
JabResource *JabResourceList::priority() const
 
805
{
 
806
        JabResource *highest = 0;
 
807
        int highest_val;
 
808
 
 
809
        QPtrListIterator<JabResource> it(*this);
 
810
        JabResource *r;
 
811
        for(; (r = it.current()); ++it) {
 
812
                if(!highest || (r->priority > highest->priority)) {
 
813
                        highest = r;
 
814
                        highest_val = r->priority;
 
815
                }
 
816
        }
 
817
 
 
818
        // this can be zero
 
819
        return highest;
 
820
}