1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2007-2009 Licq developers
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq 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 Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #include "contactbar.h"
21 
22 #include "contactgroup.h"
23 
24 using namespace LicqQtGui;
25 /* TRANSLATOR LicqQtGui::ContactBar */
26 
ContactBar(ContactListModel::SubGroupType subGroup,ContactGroup * group)27 ContactBar::ContactBar(ContactListModel::SubGroupType subGroup, ContactGroup* group)
28   : ContactItem(ContactListModel::BarItem),
29     myGroup(group),
30     mySubGroup(subGroup),
31     myUserCount(0),
32     myEvents(0),
33     myVisibleContacts(0)
34 {
35   switch (mySubGroup)
36   {
37     case ContactListModel::OnlineSubGroup:
38       myText = tr("Online");
39       break;
40     case ContactListModel::OfflineSubGroup:
41       myText = tr("Offline");
42       break;
43     case ContactListModel::NotInListSubGroup:
44     default:
45       myText = tr("Not In List");
46       break;
47   }
48 }
49 
countIncrease()50 void ContactBar::countIncrease()
51 {
52   myUserCount++;
53 }
54 
countDecrease()55 void ContactBar::countDecrease()
56 {
57   myUserCount--;
58 }
59 
updateNumEvents(int counter)60 void ContactBar::updateNumEvents(int counter)
61 {
62   myEvents += counter;
63 }
64 
updateVisibility(bool increase)65 void ContactBar::updateVisibility(bool increase)
66 {
67   if (increase)
68     myVisibleContacts++;
69   else
70     myVisibleContacts--;
71 }
72 
data(int column,int role) const73 QVariant ContactBar::data(int column, int role) const
74 {
75   switch (role)
76   {
77     case Qt::DisplayRole:
78       if (column == 0)
79         return myText;
80       break;
81 
82     case ContactListModel::NameRole:
83       return myText;
84 
85     case ContactListModel::ItemTypeRole:
86       return ContactListModel::BarItem;
87 
88     case ContactListModel::SortPrefixRole:
89       return 2 * mySubGroup;
90 
91     case ContactListModel::SortRole:
92       return "";
93 
94     case ContactListModel::GroupIdRole:
95       return myGroup->groupId();
96 
97     case ContactListModel::SubGroupRole:
98       return mySubGroup;
99 
100     case ContactListModel::UserCountRole:
101       return myUserCount;
102 
103     case ContactListModel::UnreadEventsRole:
104       return myEvents;
105 
106     case ContactListModel::VisibilityRole:
107       return (myVisibleContacts > 0);
108   }
109 
110   return QVariant();
111 }
112