~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/tools/contactlist/contactlist.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "contactlist.h"
 
2
#include "contactlistgroupitem.h"
 
3
#include "contactlistrootitem.h"
 
4
#include "contactlistalphacomparator.h"
 
5
 
 
6
 
 
7
ContactList::ContactList(QObject* parent)
 
8
        : QObject(parent), showOffline_(false), showGroups_(true)
 
9
{
 
10
        rootItem_ = new ContactListRootItem(this);
 
11
        invisibleGroup_ = new ContactListRootItem(this);
 
12
        altInvisibleGroup_ = new ContactListRootItem(this);
 
13
        itemComparator_ = new ContactListAlphaComparator();
 
14
}
 
15
 
 
16
const ContactListItemComparator* ContactList::itemComparator() const
 
17
{
 
18
        return itemComparator_;
 
19
}
 
20
 
 
21
const QString& ContactList::search() const
 
22
{
 
23
        return search_;
 
24
}
 
25
 
 
26
void ContactList::setShowOffline(bool showOffline)
 
27
{
 
28
        if (showOffline_ != showOffline) {
 
29
                showOffline_ = showOffline;
 
30
                updateParents();
 
31
        }
 
32
}
 
33
 
 
34
void ContactList::setShowGroups(bool showGroups)
 
35
{
 
36
        if (showGroups_ != showGroups) {
 
37
                showGroups_ = showGroups;
 
38
                updateParents();
 
39
        }
 
40
}
 
41
 
 
42
void ContactList::setSearch(const QString& search)
 
43
{
 
44
        QString oldSearch = search_;
 
45
        search_ = search;
 
46
 
 
47
        if ((oldSearch.isEmpty() && !search.isEmpty()) || search.isEmpty()) {
 
48
                updateParents();
 
49
        }
 
50
        if (search.isEmpty()) {
 
51
                updateParents();
 
52
        }
 
53
        else if (search.startsWith(oldSearch)) {
 
54
                updateVisibleParents();
 
55
        }
 
56
        else if (oldSearch.startsWith(search)) {
 
57
                updateInvisibleParents();
 
58
        }
 
59
        else {
 
60
                updateParents();
 
61
        }
 
62
}
 
63
 
 
64
void ContactList::emitDataChanged() 
 
65
{
 
66
        emit dataChanged();
 
67
}
 
68
 
 
69
/*void ContactList::setShowGroups(bool showGroups)
 
70
{
 
71
        showGroups_ = showGroups;
 
72
}
 
73
 
 
74
void ContactList::setShowAccounts(bool showAccounts)
 
75
{
 
76
        showAccounts_ = showAccounts;
 
77
}*/
 
78
 
 
79
ContactListRootItem* ContactList::rootItem()
 
80
{
 
81
        return rootItem_;
 
82
}
 
83
 
 
84
ContactListRootItem* ContactList::invisibleGroup()
 
85
{
 
86
        return invisibleGroup_;
 
87
}
 
88
 
 
89
/*ContactListGroupItem* ContactList::hiddenGroup()
 
90
{
 
91
        return hiddenGroup_;
 
92
}
 
93
 
 
94
ContactListGroupItem* ContactList::agentsGroup()
 
95
{
 
96
        return agentsGroup_;
 
97
}
 
98
 
 
99
ContactListGroupItem* ContactList::conferenceGroup()
 
100
{
 
101
        return conferenceGroup_;
 
102
}*/
 
103
 
 
104
void ContactList::updateVisibleParents()
 
105
{
 
106
        rootItem()->updateParents();
 
107
        emit dataChanged();
 
108
}
 
109
 
 
110
void ContactList::updateInvisibleParents()
 
111
{
 
112
        invisibleGroup()->updateParents();
 
113
        emit dataChanged();
 
114
}
 
115
 
 
116
void ContactList::updateParents()
 
117
{
 
118
        // Switch invisible groups
 
119
        ContactListRootItem* tmpInvisibleGroup = invisibleGroup_;
 
120
        invisibleGroup_ = altInvisibleGroup_;
 
121
        altInvisibleGroup_ = tmpInvisibleGroup;
 
122
 
 
123
        // Move items around
 
124
        rootItem()->updateParents();
 
125
        altInvisibleGroup_->updateParents();
 
126
 
 
127
        emit dataChanged();
 
128
}