1
/****************************************************************************
2
** contactview.cpp - an Licq-like contact list
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<qpopupmenu.h>
22
#include<qmessagebox.h>
23
#include<qinputdialog.h>
27
#include<qdragobject.h>
28
#include<qapplication.h>
31
#include"contactview.h"
36
//*******************************************************
38
//*******************************************************
39
ContactView::ContactView(QWidget *parent, const char *name)
40
:QListView(parent, name), QToolTip(viewport())
42
// setup the QListView
43
setAllColumnsShowFocus(TRUE);
44
setHScrollBarMode(AlwaysOff);
45
setMinimumSize(96,64);
46
//setRootIsDecorated(TRUE);
49
setDefaultRenameAction(QListView::Accept);
50
//setSelectionMode(QListView::Extended);
52
// create columns and hide the header
55
setResizeMode(QListView::LastColumn);
56
setShowToolTips(FALSE);
58
// initialize the alerting stuff
59
QTimer *t = new QTimer(this);
60
connect(t, SIGNAL(timeout()), SLOT(animAlert()));
64
connect(this, SIGNAL(itemRenamed(QListViewItem *, int, const QString &)), SLOT(qlv_itemRenamed(QListViewItem *, int, const QString &)));
65
connect(this, SIGNAL(mouseButtonPressed(int, QListViewItem *, const QPoint &, int)),SLOT(qlv_singleclick(int, QListViewItem *, const QPoint &, int)) );
66
connect(this, SIGNAL(doubleClicked(QListViewItem *)),SLOT(qlv_doubleclick(QListViewItem *)) );
75
sortTimer = new QTimer(this);
76
connect(sortTimer, SIGNAL(timeout()), SLOT(actualContactSort()));
79
qa_send = new QAction("", tr("Send &message"), QListView::CTRL+QListView::Key_M, this);
80
connect(qa_send, SIGNAL(activated()), SLOT(doSendMessage()));
81
qa_ren = new QAction("", tr("Re&name"), QListView::Key_F2, this);
82
connect(qa_ren, SIGNAL(activated()), SLOT(doRename()));
83
qa_chat = new QAction("", tr("Open &chat window"), QListView::CTRL+QListView::Key_C, this);
84
connect(qa_chat, SIGNAL(activated()), SLOT(doOpenChat()));
85
qa_hist = new QAction("", tr("&History"), QListView::CTRL+QListView::Key_H, this);
86
connect(qa_hist, SIGNAL(activated()), SLOT(doHistory()));
87
qa_logon = new QAction("", tr("&Log on"), QListView::CTRL+QListView::Key_L, this);
88
connect(qa_logon, SIGNAL(activated()), SLOT(doLogon()));
89
qa_recv = new QAction("", tr("&Receive incoming event"), QListView::CTRL+QListView::Key_R, this);
90
connect(qa_recv, SIGNAL(activated()), SLOT(doRecvEvent()));
91
qa_rem = new QAction("", tr("Rem&ove"), QListView::Key_Delete, this);
92
connect(qa_rem, SIGNAL(activated()), SLOT(doRemove()));
99
ContactView::~ContactView()
101
pdb(DEBUG_CV, "ContactView::~ContactView()\n");
103
// delete the profiles
104
profiles.setAutoDelete(TRUE);
108
void ContactView::resizeEvent(QResizeEvent *e)
110
QListView::resizeEvent(e);
113
void ContactView::keyPressEvent(QKeyEvent *e)
115
if(e->key() == QListView::Key_Enter || e->key() == QListView::Key_Return)
117
else if(e->key() == QListView::Key_Space)
120
QListView::keyPressEvent(e);
123
void ContactView::viewportMousePressEvent(QMouseEvent *e)
125
QListView::viewportMousePressEvent(e);
126
if(e->button() == QListView::LeftButton)
127
mousePressPos = e->pos();
130
void ContactView::viewportMouseMoveEvent(QMouseEvent *e)
132
ContactViewItem *i = LVI2CVI(selectedItem());
135
if(i->type() != CV_CONTACT)
138
if((e->state() & QListView::LeftButton) && !mousePressPos.isNull() && (QPoint(e->pos() - mousePressPos).manhattanLength() > 8)) {
139
QDragObject *d = new QTextDrag(i->jid(), this);
140
d->setPixmap(*pix_online, QPoint(8,8));
145
void ContactView::dragEnterEvent(QDragEnterEvent *e)
149
// only accept text jids that are in the contact list
150
if(QTextDrag::decode(e, text)) {
151
if(defPro()->findCVIByJid(text)) {
160
void ContactView::dropEvent(QDropEvent *e)
162
ContactViewItem *i = LVI2CVI(itemAt(e->pos()));
166
ContactViewItem *dest;
167
if(i->type() == CV_GROUP)
170
dest = LVI2CVI(i->parent());
174
if(QTextDrag::decode(e, text)) {
175
ContactViewItem *src = defPro()->findCVIByJid(text);
180
if(src->isAgent() || !src->inList())
184
if(dest->groupType() == CVG_USER)
185
newgroup = dest->groupName();
189
if(src->group() == newgroup.mid(0))
192
pdb(DEBUG_CV, QString("dragdrop: moving [%1] to group [%2] (oldgroup=[%3])\n").arg(text).arg(newgroup).arg(src->group()));
193
if(newgroup != src->group()) {
194
defPro()->scGroupChange(src->jid(), newgroup);
195
//actionGroupChange(src->jid(), newgroup);
200
/*QDragObject *ContactView::dragObject()
202
ContactViewItem *i = LVI2CVI(selectedItem());
206
QDragObject *d = new QTextDrag(i->jid(), this);
207
d->setPixmap(*pix_online, QPoint(8,8));
212
void ContactView::sort()
216
setSorting(-1, TRUE);
219
void ContactView::maybeTip(const QPoint &pos)
221
ContactViewItem *i = LVI2CVI(itemAt(pos));
224
if(i->type() != CV_CONTACT)
227
QRect r(itemRect(i));
229
QString str = QString("<qt>");
230
str += QString("<nobr>%1: %2</nobr>").arg(i->nick()).arg(status2txt(i->status()));
231
if(i->jid() != i->nick())
232
str += QString("<br>[%1]").arg(i->jid());
235
str += QString("<br><nobr>") + QString(tr("Subscription") + ": %1").arg(i->sub()) + "</nobr>";
238
if(!i->resList().isEmpty()) {
241
JabResource *pr = i->resList().priority();
242
QPtrListIterator<JabResource> it(i->resList());
244
for(; (r = it.current()); ++it) {
245
// skip 'blank' resources (non-jabber contacts)
246
if(r->name.isEmpty())
255
resources += r->name;
259
if(!resources.isEmpty())
260
str += QString("<br><nobr>") + QString(tr("Resource(s)") + " : %1").arg(resources) + "</nobr>";
262
if(pr->timeStamp.isValid()) {
263
QString d = pr->timeStamp.toString();
264
str += QString("<br><nobr>") + tr("Last Status") + " @ " + d + "</nobr>";
267
if(!pr->songTitle.isEmpty())
268
str += QString("<br><nobr>") + QString(tr("Listening to") + ": %1").arg(clipStatus(pr->songTitle, 200, 1)) + "</nobr>";
271
if(!i->statusString().isEmpty()) {
272
QString head = tr("Status Message");
273
str += QString("<br><nobr><u>%1</u></nobr><br>%2").arg(head).arg(plain2rich(clipStatus(i->statusString(), 200, 12)));
280
void ContactView::qlv_singleclick(int button, QListViewItem *i, const QPoint &pos, int c)
288
ContactViewItem *item = LVI2CVI(i);
289
setSelected(item, TRUE);
292
if(button == QListView::LeftButton) {
293
if(option.singleclick) {
294
qlv_contextPopup(i, pos, c);
300
QTimer::singleShot(QApplication::doubleClickInterval()/2, this, SLOT(leftClickTimeOut()));
303
else if(option.singleclick && button == QListView::RightButton) {
304
if(item->type() == CV_CONTACT)
305
owner(item)->scActionDefault(item);
309
if(button == QListView::RightButton) {
310
qlv_contextPopup(i, pos, c);
312
else if(button == QListView::LeftButton && option.singleclick) {
313
if(item->type() == CV_CONTACT)
314
owner(item)->scActionDefault(item);
319
void ContactView::qlv_doubleclick(QListViewItem *i)
326
if(option.singleclick)
329
ContactViewItem *item = LVI2CVI(i);
331
if(item->type() == CV_CONTACT)
332
owner(item)->scActionDefault(item);
335
void ContactView::leftClickTimeOut()
339
qlv_contextPopup(lcto_item, lcto_pos, 0);
345
// Profile related functions
346
ContactProfile *ContactView::createProfile(const QString &jid, const QString &name, bool unique)
348
ContactProfile *pro = findProfile(jid);
352
pro = new ContactProfile(jid, name, STATUS_OFFLINE, unique, this);
353
profiles.append(pro);
358
ContactProfile *ContactView::findProfile(const QString &jid)
360
QPtrListIterator<ContactProfile> it(profiles);
361
for(ContactProfile *p; (p = it.current()); ++it) {
362
if(jidcmp(p->jid, jid))
368
void ContactView::removeProfile(const QString &jid)
370
ContactProfile *pro = findProfile(jid);
375
void ContactView::removeProfile(ContactProfile *p)
380
ContactProfile *ContactView::defPro()
382
return profiles.first();
385
// which profile likely deals with this item?
386
ContactProfile *ContactView::owner(ContactViewItem *i)
388
QPtrListIterator<ContactProfile> it(profiles);
389
for(ContactProfile *p; (p = it.current()); ++it) {
396
void ContactView::ensureVisible(ContactViewItem *item)
398
// ensure the item is visible
399
ContactViewItem *group_item = LVI2CVI(item->parent());
401
// if the group is a user group, go up a step
402
if(group_item && group_item->groupType() == CVG_USER)
403
group_item = LVI2CVI(group_item->parent());
405
if(group_item && !group_item->isVisible()) {
406
if(group_item->groupType() == CVG_OFFLINE)
407
setShowOffline(TRUE);
408
if(group_item->groupType() == CVG_AGENTS)
411
if(!isShowAway() && item->isAway()) {
415
ensureItemVisible(item);
418
void ContactView::animAlert()
420
// are any of the items animating?
421
QListViewItemIterator it(this);
422
ContactViewItem *item;
424
for(; it.current() ; ++it) {
425
item = LVI2CVI(it.current());
428
if(item->isAnimateNick())
433
void ContactView::clear()
435
profiles.setAutoDelete(TRUE);
437
profiles.setAutoDelete(FALSE);
440
// right-click context menu
441
void ContactView::qlv_contextPopup(QListViewItem *xi, const QPoint &pos, int)
443
ContactViewItem *i = LVI2CVI(xi);
447
owner(i)->doContextMenu(i, pos);
450
void ContactView::doRecvEvent()
452
ContactViewItem *i = LVI2CVI(selectedItem());
456
if(i->type() == CV_CONTACT)
457
owner(i)->scRecvEvent(i);
460
void ContactView::doRename()
462
ContactViewItem *i = LVI2CVI(selectedItem());
466
owner(i)->scRename(i);
469
void ContactView::doEnter()
471
ContactViewItem *i = LVI2CVI(selectedItem());
475
if(i->type() == CV_CONTACT)
476
owner(i)->scActionDefault(i);
479
void ContactView::doContext()
481
ContactViewItem *i = LVI2CVI(selectedItem());
484
ensureItemVisible(i);
486
if(i->type() == CV_GROUP)
487
setOpen(i, !i->isOpen());
489
qlv_contextPopup(i, viewport()->mapToGlobal(QPoint(32, itemPos(i))), 0);
492
void ContactView::doSendMessage()
494
ContactViewItem *i = LVI2CVI(selectedItem());
498
owner(i)->scSendMessage(i);
501
void ContactView::doOpenChat()
503
ContactViewItem *i = LVI2CVI(selectedItem());
507
owner(i)->scOpenChat(i);
510
void ContactView::doHistory()
512
ContactViewItem *i = LVI2CVI(selectedItem());
516
owner(i)->scHistory(i);
519
void ContactView::doLogon()
521
ContactViewItem *i = LVI2CVI(selectedItem());
524
if(i->type() != CV_CONTACT)
528
owner(i)->scAgentSetStatus(i, STATUS_ONLINE);
531
void ContactView::doRemove()
533
ContactViewItem *i = LVI2CVI(selectedItem());
537
owner(i)->scRemove(i);
540
void ContactView::qlv_itemRenamed(QListViewItem *xi, int, const QString &text)
542
ContactViewItem *i = LVI2CVI(xi);
544
owner(i)->doItemRenamed(i, text);
547
void ContactView::setShowOffline(bool x)
549
bool oldstate = v_showOffline;
552
if(v_showOffline != oldstate) {
553
showOffline(v_showOffline);
555
// set the visibility of all the offline groups
556
QPtrListIterator<ContactProfile> it(profiles);
557
for(ContactProfile *p; (p = it.current()); ++it) {
558
ContactViewItem *group_item = p->checkGroup(CVG_OFFLINE);
560
group_item->setVisible(v_showOffline);
565
void ContactView::setShowAway(bool x)
567
bool oldstate = v_showAway;
570
if(v_showAway != oldstate) {
571
showAway(v_showAway);
573
// we want to modify _all_ profiles, so just burn down the list
574
QListViewItemIterator it(this);
575
ContactViewItem *item;
576
for(; it.current() ; ++it) {
577
item = LVI2CVI(it.current());
578
if(item->type() != CV_CONTACT)
587
void ContactView::setShowAgents(bool x)
589
bool oldstate = v_showAgents;
592
if(v_showAgents != oldstate) {
593
showAgents(v_showAgents);
595
// set the visibility of all the offline groups
596
QPtrListIterator<ContactProfile> it(profiles);
597
for(ContactProfile *p; (p = it.current()); ++it) {
598
ContactViewItem *group_item = p->checkGroup(CVG_AGENTS);
600
group_item->setVisible(v_showAgents);
605
void ContactView::optionsUpdate()
609
f.fromString(option.font[fRoster]);
610
QListView::setFont(f);
612
// set the text and background colors
613
QPalette mypal = QListView::palette();
614
mypal.setColor(QColorGroup::Text, option.color[cOnline]);
615
mypal.setColor(QColorGroup::Base, option.color[cListBack]);
616
QListView::setPalette(mypal);
619
QListViewItemIterator it(this);
620
ContactViewItem *item;
621
for(; it.current() ; ++it) {
622
item = LVI2CVI(it.current());
623
item->optionsUpdate();
629
void ContactView::setVisibility(ContactViewItem *i)
631
ContactViewItem *par = LVI2CVI(i->parent());
632
if(par && !par->isVisible())
635
if(!isShowAway() && i->isAway())
636
i->setVisible(FALSE);
641
void ContactView::deferredContactSort()
643
sortTimer->start(500, TRUE);
646
void ContactView::actualContactSort()
648
QListViewItemIterator it(this);
649
ContactViewItem *item;
651
for(; it.current() ; ++it) {
652
item = LVI2CVI(it.current());
653
if(item->type() != CV_GROUP)
656
if(item->needSorting)
659
owner(item)->updateGroupInfo(item);
666
//*******************************************************
668
//*******************************************************
669
ContactViewItem::ContactViewItem(const QString &xgroupname, int xgrouptype, QListView *parent)
670
:QListViewItem(parent)
673
v_groupName = xgroupname;
674
v_groupType = xgrouptype;
676
v_isAnimateNick = FALSE;
684
//if(xgrouptype == CVG_USER)
685
//setRenameEnabled(1, TRUE);
689
//setDropEnabled(TRUE);
692
ContactViewItem::ContactViewItem(const QString &xgroupname, int xgrouptype, QListViewItem *parent)
693
:QListViewItem(parent)
695
if(!parent->isVisible())
699
v_groupName = xgroupname;
700
v_groupType = xgrouptype;
702
v_isAnimateNick = FALSE;
710
//if(xgrouptype == CVG_USER)
711
//setRenameEnabled(1, TRUE);
715
//setDropEnabled(TRUE);
718
ContactViewItem::ContactViewItem(const QString &xjid, const QString &xnick, bool xisAgent, QListViewItem *parent)
719
:QListViewItem(parent)
721
if(!parent->isVisible())
728
v_isAgent = xisAgent;
730
v_isAnimateNick = FALSE;
731
v_status = STATUS_OFFLINE;
736
//setDragEnabled(TRUE);
737
//setDropEnabled(TRUE);
740
ContactViewItem::~ContactViewItem()
742
// delete the alert queue
743
while(!alertQueue.isEmpty()) {
744
int *x = alertQueue.last();
745
alertQueue.remove(x);
750
void ContactViewItem::optionsUpdate()
752
if(v_type == CV_GROUP) {
763
void ContactViewItem::resetAnim()
767
if(option.alertStyle == 0)
768
setPixmap(0, messagetype2anim(alertType)->base());
772
void ContactViewItem::paintFocus(QPainter *, const QColorGroup &, const QRect &)
774
// re-implimented to do nothing. selection is enough of a focus
777
void ContactViewItem::paintBranches(QPainter *p, const QColorGroup &cg, int w, int, int h)
779
// paint a square of nothing
780
p->fillRect(0, 0, w, h, cg.base());
783
void ContactViewItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int alignment)
785
if(v_type == CV_CONTACT) {
786
QColorGroup xcg = cg;
787
if(v_status == STATUS_AWAY || v_status == STATUS_XA)
788
xcg.setColor(QColorGroup::Text, option.color[cAway]);
789
else if(v_status == STATUS_DND)
790
xcg.setColor(QColorGroup::Text, option.color[cDND]);
791
else if(v_status == STATUS_OFFLINE)
792
xcg.setColor(QColorGroup::Text, option.color[cOffline]);
794
if(v_isAnimateNick) {
795
xcg.setColor(QColorGroup::Text, animateNickColor ? Qt::red : Qt::black);
796
xcg.setColor(QColorGroup::HighlightedText, animateNickColor ? Qt::red : Qt::black);
799
QListViewItem::paintCell(p, xcg, column, width, alignment);
801
else if(v_type == CV_GROUP) {
802
QColorGroup xcg = cg;
803
xcg.setColor(QColorGroup::Text, option.color[cGroupFore]);
804
xcg.setColor(QColorGroup::Base, option.color[cGroupBack]);
806
//QFont f = p->font();
810
QListViewItem::paintCell(p, xcg, column, width, alignment);
812
//QFontMetrics fm(p->font());
813
//int x1 = fm.width(text(0)) + pixmap().width() + 4;
823
p->setPen(QPen(option.color[cGroupFore]));
824
p->drawLine(x1, y1, x2, y1);
825
p->drawLine(x1, y2, x2, y2);
826
p->drawLine(x1, y1, x1, y2);
827
p->drawLine(x2, y1, x2, y2);
837
p->setPen(QPen(option.color[cGroupFore]));
838
p->drawLine(x1, y1, x2, y1);
839
p->drawLine(x1, y2, x2, y2);
840
p->drawLine(x2, y1, x2, y2);
845
void ContactViewItem::setOpen(bool o)
847
QListViewItem::setOpen(o);
852
int ContactViewItem::parentGroupType()
854
ContactViewItem *item = LVI2CVI(parent());
855
return item->groupType();
858
void ContactViewItem::setStatus(int xstatus)
860
if(v_status == xstatus)
866
ContactViewItem *i = LVI2CVI(parent());
868
i->needSorting = TRUE;
871
void ContactViewItem::resetStatus()
876
setPixmap(0, v_isAgent ? transport2icon(v_jid, v_status) : status2pix(v_status));
879
void ContactViewItem::setNick(const QString &xnick)
887
ContactViewItem *i = LVI2CVI(parent());
889
i->needSorting = TRUE;
892
void ContactViewItem::resetNick()
894
setPixmap(0, v_isAgent ? transport2icon(v_jid, v_status) : status2pix(v_status));
898
void ContactViewItem::setGroup(const QString &xgroup)
903
void ContactViewItem::setSub(const QString &xsub)
908
void ContactViewItem::setStatusString(const QString &xstatusString)
910
v_statusString = xstatusString;
913
void ContactViewItem::setInList(bool xinList)
918
void ContactViewItem::setIsAgent(bool xisAgent)
920
bool oldstate = v_isAgent;
922
v_isAgent = xisAgent;
924
// if different, then update the status
925
if(v_isAgent != oldstate)
929
void ContactViewItem::setAlert(int xtype)
935
if(option.alertStyle == 0)
936
setPixmap(0, messagetype2anim(alertType)->base());
939
int *x = new int(xtype);
940
alertQueue.insert(0, x);
943
void ContactViewItem::clearAlert(int at)
945
if(alertQueue.isEmpty())
949
int *x = alertQueue.last();
950
for(int n = 0; n < at; ++n) {
951
x = alertQueue.prev();
954
alertQueue.remove(x);
958
// set the next alert (or stop alerting if empty)
959
if(alertQueue.isEmpty()) {
964
x = alertQueue.last();
970
void ContactViewItem::setAttr(const QString &xnick, const QString xgroup, const QString &sub, int status)
978
void ContactViewItem::setGroupName(const QString &name)
984
void ContactViewItem::setGroupInfo(const QString &info)
990
void ContactViewItem::resetGroupName(bool showInfo)
992
QString str = v_groupName;
993
if(showInfo && !v_groupInfo.isEmpty())
994
str += QString(" ") + v_groupInfo;
999
void ContactViewItem::animate()
1001
Anim *anim = messagetype2anim(alertType);
1003
if(anim->isAnim() && option.alertStyle == 2) {
1004
setPixmap(0, anim->frame(animStep));
1006
if(animStep >= anim->numFrames()-1)
1009
else if(option.alertStyle != 0) {
1011
setPixmap(0, anim->base());
1012
else if(animStep == 4)
1013
setPixmap(0, *pix_blank);
1021
int ContactViewItem::rankGroup(int groupType) const
1023
static int rankgroups[7] = {
1034
for(n = 0; n < 7; ++n) {
1035
if(rankgroups[n] == groupType)
1044
int ContactViewItem::rankStatus(int status) const
1046
static int rankstatuses[5] = {
1055
for(n = 0; n < 5; ++n) {
1056
if(rankstatuses[n] == status)
1065
int ContactViewItem::compare(QListViewItem *xi, int, bool) const
1067
ContactViewItem *i = LVI2CVI(xi);
1070
if(v_type == CV_GROUP) {
1071
// contacts always go before groups
1072
if(i->type() == CV_CONTACT)
1075
ret = rankGroup(v_groupType) - rankGroup(i->groupType());
1077
ret = text(0).lower().localeAwareCompare(i->text(0).lower());
1080
else if(v_type == CV_CONTACT) {
1081
// contacts always go before groups
1082
if(i->type() == CV_GROUP)
1085
//int x1 = v_isAlert ? 0 : (rankStatus(v_status) + 1);
1086
//int x2 = i->isAlert() ? 0 : (rankStatus(i->status()) + 1);
1088
ret = rankStatus(v_status) - rankStatus(i->status());
1091
ret = text(0).lower().localeAwareCompare(i->text(0).lower());
1098
void ContactViewItem::drawGroupIcon()
1100
if(childCount() == 0)
1101
setPixmap(0, *pix_arrow[2]);
1103
setPixmap(0, *pix_arrow[1]);
1105
setPixmap(0, *pix_arrow[0]);
1108
void ContactViewItem::insertItem(QListViewItem * newChild)
1110
QListViewItem::insertItem(newChild);
1115
void ContactViewItem::takeItem(QListViewItem * item)
1117
QListViewItem::takeItem(item);
1122
void ContactViewItem::setAnimateNick()
1126
v_isAnimateNick = TRUE;
1131
void ContactViewItem::stopAnimateNick()
1133
if(!v_isAnimateNick)
1136
v_isAnimateNick = FALSE;
1140
void ContactViewItem::animateNick()
1142
animateNickColor = (animateNickX % 10) >= 5 ? 1: 0;
1143
if((animateNickX % 5) == 0)
1147
if(animateNickX == 80)
1151
bool ContactViewItem::isAway()
1153
if(v_status == STATUS_AWAY || v_status == STATUS_XA || v_status == STATUS_DND)
1159
void ContactViewItem::sort()
1161
QListView *i = listView();
1165
i->setSorting(0, TRUE);
1166
QListViewItem::sort();
1167
i->setSorting(-1, TRUE);
1169
needSorting = FALSE;
1172
/*bool ContactViewItem::acceptDrop(const QMimeSource *mime) const
1174
printf("accept?\n");
1175
return TRUE;// QTextDrag::canDecode(mime);
1178
void ContactViewItem::dropped(QDropEvent *e)
1182
if(QTextDrag::decode(e, text)) {
1183
printf("dropped on %s, this text: %s\n", v_jid.latin1(), text.latin1());
1189
//*******************************************************
1191
//*******************************************************
1192
ContactProfile::ContactProfile(const QString &_jid, const QString &_name, int _localStatus, bool unique, ContactView *_cv)
1196
localStatus = _localStatus;
1199
roster = new QDict<ContactProfileItem>(50, TRUE);
1200
roster->setAutoDelete(TRUE);
1203
cvi = new ContactViewItem(name, CVG_USER, cv);
1207
cvi_online = addGroup(CVG_ONLINE);
1208
cvi_offline = addGroup(CVG_OFFLINE);
1211
ContactProfile::~ContactProfile()
1213
// delete the roster
1225
ContactProfileItem *ContactProfile::cvi2cpi(ContactViewItem *i)
1227
return roster->find(i->jid().lower());
1230
ContactProfileItem *ContactProfile::findByJid(const QString &jid)
1232
return roster->find(jid.lower());
1235
bool ContactProfile::isMine(ContactViewItem *i)
1237
// unique? we'll take it
1245
// reduce the depth until we hit the base
1246
i = LVI2CVI(i->parent());
1252
ContactViewItem *ContactProfile::findCVIByJid(const QString &jid)
1254
ContactProfileItem *i = findByJid(jid);
1260
ContactViewItem *ContactProfile::addGroup(int type)
1262
ContactViewItem *item;
1265
if(type == CVG_ONLINE)
1266
gname = tr("Online");
1267
else if(type == CVG_OFFLINE)
1268
gname = tr("Offline");
1269
else if(type == CVG_NOTINLIST)
1270
gname = tr("Not in list");
1271
else if(type == CVG_AUTHWAIT)
1272
gname = tr("Need Authorization");
1273
else if(type == CVG_AGENTS)
1274
gname = tr("Agents/Transports");
1277
item = new ContactViewItem(gname, type, cvi);
1279
item = new ContactViewItem(gname, type, cv);
1281
if((type == CVG_OFFLINE && !cv->isShowOffline()) || (type == CVG_AGENTS && !cv->isShowAgents()))
1282
item->setVisible(FALSE);
1284
cv->deferredContactSort();
1287
QString dstr; dstr.sprintf("ContactProfile::addGroup: [%s]\n", gname.latin1());
1288
pdb(DEBUG_CV, dstr);
1293
ContactViewItem *ContactProfile::addGroup(const QString &name, ContactViewItem *par)
1295
ContactViewItem *item = new ContactViewItem(name, CVG_USER, par);
1296
cv->deferredContactSort();
1300
ContactViewItem *ContactProfile::checkGroup(int group)
1302
ContactViewItem *item;
1304
item = LVI2CVI(cvi->firstChild());
1306
item = LVI2CVI(cv->firstChild());
1309
for(; item; item = LVI2CVI(item->nextSibling()) ) {
1310
if(item->type() == CV_GROUP && item->groupType() == group)
1317
ContactViewItem *ContactProfile::checkGroup(const QString &group, ContactViewItem *par)
1320
ContactViewItem *item = LVI2CVI(par->firstChild());
1321
for(; item; item = LVI2CVI(item->nextSibling()) ) {
1322
if(item->type() == CV_GROUP && item->groupType() == CVG_USER) {
1323
if(item->groupName() == group)
1331
ContactViewItem *ContactProfile::ensureGroup(int group)
1333
ContactViewItem *group_item = checkGroup(group);
1337
return addGroup(group);
1340
ContactViewItem *ContactProfile::ensureGroup(const QString &group, int status)
1342
// empty string == default group (online/offline)
1343
if(group.isEmpty()) {
1344
int gtype = (status == STATUS_OFFLINE) ? CVG_OFFLINE : CVG_ONLINE;
1345
return ensureGroup(gtype);
1348
ContactViewItem *group_item;
1349
ContactViewItem *par = (status == STATUS_OFFLINE) ? offline(): online();
1351
group_item = checkGroup(group, par);
1353
// doesn't exist? make it!
1355
group_item = addGroup(group, par);
1360
ContactProfileItem *ContactProfile::addEntry(const UserListItem &i)
1362
ContactViewItem *group_item;
1363
if(i.inList == FALSE)
1364
group_item = ensureGroup(CVG_NOTINLIST);
1365
else if(i.isTransport == TRUE)
1366
group_item = ensureGroup(CVG_AGENTS);
1367
else if(i.sub == "from" || i.sub == "none")
1368
group_item = ensureGroup(CVG_AUTHWAIT);
1370
group_item = ensureGroup(i.group, i.state);
1372
QString nick = jidnick(i.jid, i.nick);
1373
ContactViewItem *item = new ContactViewItem(i.jid, nick, i.isTransport, group_item);
1374
item->setAttr(nick, i.group, i.sub, i.state);
1375
item->setInList(i.inList);
1376
item->setStatusString(i.statusString);
1378
item->resList() = i.res;
1380
// insert into the profile roster
1381
ContactProfileItem *pi = new ContactProfileItem;
1384
roster->insert(i.jid.lower(), pi);
1387
QString dstr; dstr.sprintf("ContactProfile::addEntry: adding [%s] to group [%s]\n", i.jid.latin1(), group_item->groupName().latin1());
1388
pdb(DEBUG_CV, dstr);
1393
void ContactProfile::updateEntry(const UserListItem &i)
1395
ContactProfileItem *pi = findByJid(i.jid);
1396
ContactViewItem *item;
1398
item = addEntry(i)->cvi;
1403
// if the group is different, we may need to remove a floating user group
1404
QString oldgroup = item->group();
1406
item->setAttr(jidnick(i.jid, i.nick), i.group, i.sub, i.state);
1407
item->setInList(i.inList);
1408
item->setStatusString(i.statusString);
1410
item->resList() = i.res;
1412
// it is possible that a contact could be recognized later as an agent i guess
1413
item->setIsAgent(i.isTransport); // ok 99, go-go-gadget shoe phone
1416
changeGroup(item, i.group);
1418
// destroy original group?
1419
checkDestroyGroup(oldgroup);
1421
// stop animating the nick if going offline
1422
if(i.state == STATUS_OFFLINE)
1423
item->stopAnimateNick();
1426
cv->setVisibility(item);
1427
cv->deferredContactSort();
1431
void ContactProfile::changeGroup(ContactViewItem *item, ContactViewItem *group_new)
1433
// contacts are always children of groups, so this should be safe:
1434
ContactViewItem *group_in = LVI2CVI(item->parent());
1436
if(group_in != group_new) {
1437
// take from the rich, give to the poor
1438
group_in->takeItem(item);
1439
group_new->insertItem(item);
1441
// visibility of item should match that of group_new
1442
item->setVisible(group_new->isVisible());
1445
// we may need to destroy the original group(s):
1446
checkDestroyGroup(group_in);
1448
if(item->isAlert()) {
1450
cv->ensureVisible(item);
1454
void ContactProfile::changeGroup(ContactViewItem *item, const QString &group)
1456
ContactViewItem *group_item;
1458
if(item->inList() == FALSE) {
1459
item->setStatus(STATUS_OFFLINE);
1460
group_item = ensureGroup(CVG_NOTINLIST);
1462
else if(item->isAgent() == TRUE)
1463
group_item = ensureGroup(CVG_AGENTS);
1464
else if(item->sub() == "from" || item->sub() == "none") {
1465
item->setStatus(STATUS_OFFLINE);
1466
group_item = ensureGroup(CVG_AUTHWAIT);
1469
group_item = ensureGroup(group, item->status());
1471
changeGroup(item, group_item);
1474
void ContactProfile::checkDestroyGroup(const QString &group)
1479
ContactViewItem *group_item;
1481
group_item = checkGroup(group, offline());
1483
checkDestroyGroup(group_item);
1484
group_item = checkGroup(group, online());
1486
checkDestroyGroup(group_item);
1489
void ContactProfile::checkDestroyGroup(ContactViewItem *group)
1491
// don't destroy online/offline psuedogroups
1492
if(group->groupType() == CVG_ONLINE || group->groupType() == CVG_OFFLINE)
1495
if(group->childCount() == 0) {
1497
QString dstr; dstr.sprintf("ContactProfile::checkDestroyGroup: removing group [%s]\n", group->groupName().latin1());
1498
pdb(DEBUG_CV, dstr);
1504
void ContactProfile::removeEntry(const QString &jid)
1506
ContactProfileItem *pi = findByJid(jid);
1512
void ContactProfile::removeEntry(ContactProfileItem *pi)
1514
ContactViewItem *item = pi->cvi;
1516
// prepare to delete the parent group
1517
ContactViewItem *group_in = LVI2CVI(item->parent());
1520
//QString dstr; dstr.sprintf("ContactProfile::removeEntry: removing contact [%s]\n", item->jid().latin1());
1521
//pdb(DEBUG_CV, dstr);
1523
clearAllAlerts(item);
1526
QString key = pi->uli.jid.lower();
1527
roster->remove(key);
1529
updateGroupInfo(group_in);
1531
// remove the group?
1532
checkDestroyGroup(group_in);
1535
void ContactProfile::showAlert(const QString &jid, int type)
1537
ContactProfileItem *pi = findByJid(jid);
1540
ContactViewItem *item = pi->cvi;
1542
// reset all animations (so they are in sync with this new one)
1543
for(QListViewItemIterator it(cv); it.current() ; ++it) {
1544
ContactViewItem *item = LVI2CVI(it.current());
1545
if(item->type() == CV_CONTACT)
1549
// flag the alert, and account the total
1550
item->setAlert(type);
1553
cv->ensureVisible(item);
1556
void ContactProfile::clearAlert(const QString &jid, int at)
1558
ContactProfileItem *pi = findByJid(jid);
1561
ContactViewItem *item = pi->cvi;
1562
clearAlert(item, at);
1565
void ContactProfile::clearAllAlerts(const QString &jid)
1567
ContactProfileItem *pi = findByJid(jid);
1570
ContactViewItem *item = pi->cvi;
1571
clearAllAlerts(item);
1574
void ContactProfile::clearAlert(ContactViewItem *item, int at)
1577
item->clearAlert(at);
1580
void ContactProfile::clearAllAlerts(ContactViewItem *item)
1582
while(item->isAlert())
1586
void ContactProfile::animateNick(const QString &jid)
1588
ContactProfileItem *pi = findByJid(jid);
1591
ContactViewItem *item = pi->cvi;
1592
item->setAnimateNick();
1595
void ContactProfile::clear()
1597
QDictIterator<ContactProfileItem> it(*roster);
1599
for(ContactProfileItem *pi; (pi = it.current());)
1603
QStringList ContactProfile::buildGroupList()
1605
QStringList groupList;
1607
QListViewItemIterator it(cv);
1608
ContactViewItem *item;
1610
for(; it.current() ; ++it) {
1611
item = LVI2CVI(it.current());
1612
if(item->type() != CV_CONTACT)
1615
if(item->group().isEmpty())
1618
// weed out duplicates
1619
if(qstringlistmatch(groupList, item->group()) == -1)
1620
groupList.append(item->group());
1627
void ContactProfile::doContextMenu(ContactViewItem *i, const QPoint &pos)
1629
//ContactProfileItem *pi = cvi2cpi(i);
1630
QStringList groupList = buildGroupList();
1632
if(i->type() == CV_CONTACT) {
1633
QPopupMenu *popup = new QPopupMenu;
1635
if(i->parentGroupType() == CVG_NOTINLIST) {
1636
popup->insertItem(QIconSet(*pix_add), tr("Add/Authorize to contact list"), 10);
1637
if(localStatus == STATUS_OFFLINE)
1638
popup->setItemEnabled(10, FALSE);
1640
popup->insertSeparator();
1643
cv->qa_recv->addTo(popup);
1644
popup->insertSeparator();
1647
cv->qa_send->setIconSet(*pix_send);
1648
cv->qa_send->addTo(popup);
1650
popup->insertItem(QIconSet(*pix_url), tr("Send &URL"), 2);
1652
cv->qa_chat->setIconSet(anim_chat->base());
1653
cv->qa_chat->addTo(popup);
1655
popup->insertItem("Offer &file", 3);
1656
popup->setItemEnabled(3, FALSE);
1657
popup->insertSeparator();
1659
if(i->parentGroupType() != CVG_NOTINLIST)
1660
cv->qa_ren->addTo(popup);
1663
if(i->parentGroupType() != CVG_NOTINLIST) {
1666
QPopupMenu *groupmenu = new QPopupMenu(popup);
1668
groupmenu->setCheckable(TRUE);
1669
groupmenu->insertItem(tr("&None"), 8);
1670
groupmenu->insertSeparator();
1672
if(i->group().isEmpty())
1673
groupmenu->setItemChecked(8, TRUE);
1676
for(QStringList::Iterator it = groupList.begin(); it != groupList.end(); ++it, ++n) {
1680
str += QString("%1. %2").arg(n+1).arg(*it);
1681
groupmenu->insertItem(str, n+32);
1683
if(i->group() == *it)
1684
groupmenu->setItemChecked(n+32, TRUE);
1687
groupmenu->insertSeparator();
1689
groupmenu->insertItem(tr("&Create new..."), 9);
1691
popup->insertItem(tr("&Group"), groupmenu, 5);
1695
popup->insertItem(tr("(Re)send &authorization to"), 6);
1696
if(localStatus == STATUS_OFFLINE)
1697
popup->setItemEnabled(6, FALSE);
1699
//if(i->parentGroupType() == CVG_AUTHWAIT)
1700
popup->insertItem(tr("Rerequest authorization from"), 11);
1701
if(localStatus == STATUS_OFFLINE)
1702
popup->setItemEnabled(11, FALSE);
1705
popup->insertSeparator();
1707
if(i->status() != STATUS_OFFLINE || localStatus == STATUS_OFFLINE)
1708
cv->qa_logon->setEnabled(FALSE);
1710
cv->qa_logon->setEnabled(TRUE);
1712
cv->qa_logon->setIconSet(transport2icon(i->jid()));
1713
cv->qa_logon->addTo(popup);
1715
popup->insertItem(transport2icon(i->jid(), STATUS_OFFLINE), tr("Log off"), 16);
1716
if(i->status() == STATUS_OFFLINE || localStatus == STATUS_OFFLINE)
1717
popup->setItemEnabled(16, FALSE);
1719
popup->insertSeparator();
1721
if(localStatus == STATUS_OFFLINE && i->inList())
1722
cv->qa_rem->setEnabled(FALSE);
1724
cv->qa_rem->setEnabled(TRUE);
1725
cv->qa_rem->setIconSet(*pix_remove);
1726
cv->qa_rem->addTo(popup);
1728
//popup->insertItem(QIconSet(*pix_remove), tr("Rem&ove"), 7);
1729
//if(localStatus == STATUS_OFFLINE && i->inList())
1730
// popup->setItemEnabled(7, FALSE);
1731
popup->insertSeparator();
1733
popup->insertItem(tr("Check &Status"), 4);
1734
popup->insertItem(QIconSet(*pix_info), tr("User &Info"), 12);
1736
cv->qa_hist->setIconSet(*pix_history);
1737
cv->qa_hist->addTo(popup);
1739
int x = popup->exec(pos);
1747
actionSendMessage(i);
1749
actionSendUrl(i->jid());
1752
actionOfferFile(i->jid());
1755
actionStatusShow(i->jid());
1758
if(localStatus != STATUS_OFFLINE) {
1759
QString name = i->jid();
1760
if(i->nick() != i->jid())
1761
name += QString(" (%1)").arg(i->nick());
1764
QMessageBox::information(cv, CAP(tr("Authorize")),
1765
QString(tr("Authorization sent to <b>%1</b>.")).arg(name));
1769
QString dstr; dstr.sprintf("contextPopup: groupchange: None\n");
1770
pdb(DEBUG_CV, dstr);
1772
// only send signal if we are actually changing group
1773
if(!i->group().isEmpty()) {
1774
actionGroupChange(i->jid(), "");
1776
//if(i->status() == STATUS_OFFLINE)
1777
// warnOfflineGroupChange();
1783
QString newgroup = QInputDialog::getText(CAP(tr("Create New Group")), tr("Enter the new Group name:"), QLineEdit::Normal, QString::null, &ok, cv);
1787
if(newgroup.isEmpty()) {
1791
// make sure we don't have it already
1792
if(qstringlistmatch(groupList, newgroup) == -1) {
1793
QString dstr; dstr.sprintf("contextPopup: groupchange: [%s]\n", newgroup.latin1());
1794
pdb(DEBUG_CV, dstr);
1796
// only send signal if we are actually changing group
1797
if(i->group() != newgroup) {
1798
actionGroupChange(i->jid(), newgroup);
1800
//if(i->status() == STATUS_OFFLINE)
1801
// warnOfflineGroupChange();
1808
if(localStatus != STATUS_OFFLINE) {
1809
QString name = i->jid();
1810
if(i->nick() != i->jid())
1811
name += QString(" (%1)").arg(i->nick());
1815
// only add if it's _not_ a transport. see jabcon.
1819
QMessageBox::information(cv, CAP(tr("Add")),
1820
QString(tr("Added/Authorized <b>%1</b> to the contact list.")).arg(name));
1824
if(localStatus != STATUS_OFFLINE) {
1825
QString name = i->jid();
1826
if(i->nick() != i->jid())
1827
name += QString(" (%1)").arg(i->nick());
1830
QMessageBox::information(cv, CAP(tr("Authorize")),
1831
QString(tr("Rerequested authorization from <b>%1</b>.")).arg(name));
1835
actionInfo(i->jid());
1838
actionHistory(i->jid());
1842
removeEntry(i->jid());
1845
actionAgentSetStatus(i->jid(), STATUS_OFFLINE);
1852
for(QStringList::Iterator it = groupList.begin(); it != groupList.end(); ++it, ++n) {
1859
if(i->group() != newgroup) {
1860
QString dstr; dstr.sprintf("contextPopup: group change [%s].\n", newgroup.latin1());
1861
pdb(DEBUG_CV, dstr);
1863
// only send signal if we are actually changing group
1864
if(i->group() != newgroup) {
1865
actionGroupChange(i->jid(), newgroup);
1867
//if(i->status() == STATUS_OFFLINE)
1868
// warnOfflineGroupChange();
1874
else if(i->type() == CV_GROUP) {
1875
QPopupMenu *popup = new QPopupMenu(cv);
1876
popup->insertItem(QIconSet(*pix_send), tr("Send message to group"), 0);
1877
popup->insertItem(tr("Re&name"), cv, SLOT(doRename()), QListView::Key_F2, 1);
1878
popup->insertSeparator();
1879
popup->insertItem(tr("Remove group"), 2);
1880
popup->insertItem(tr("Remove group and contacts"), 3);
1882
// disable if it's not a user group
1883
if(i->groupType() != CVG_USER) {
1884
popup->setItemEnabled(1,FALSE);
1885
popup->setItemEnabled(2,FALSE);
1886
popup->setItemEnabled(3,FALSE);
1889
if(i->groupType() == CVG_OFFLINE || i->groupType() == CVG_AGENTS) {
1890
popup->insertSeparator();
1891
popup->insertItem(tr("Hide"), 4);
1894
if(localStatus == STATUS_OFFLINE) {
1895
popup->setItemEnabled(2,FALSE);
1896
popup->setItemEnabled(3,FALSE);
1899
int x = popup->exec(pos);
1907
list = contactListFromCVGroup(i);
1910
actionSendMessage(list);
1912
else if(x == 2 && localStatus != STATUS_OFFLINE) {
1913
int n = QMessageBox::information(cv, CAP(tr("Remove Group")),tr(
1914
"Removing this group will cause all contacts associated with this group\n"
1915
"to be associated with no group (affects both online and offline contacts).\n"
1917
"Proceed?"), tr("&Yes"), tr("&No"));
1920
QStringList list = contactListFromGroup(i->groupName());
1921
for(QStringList::Iterator it = list.begin(); it != list.end(); ++it)
1922
actionGroupChange(*it, "");
1925
else if(x == 3 && localStatus != STATUS_OFFLINE) {
1926
int n = QMessageBox::information(cv, CAP(tr("Remove Group and Contacts")),tr(
1927
"WARNING! This will remove all contacts associated with this group (affects\n"
1928
"both online and offline contacts)!\n"
1930
"Proceed?"), tr("&Yes"), tr("&No"));
1933
QStringList list = contactListFromGroup(i->groupName());
1934
for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
1941
if(i->groupType() == CVG_OFFLINE)
1942
cv->setShowOffline(FALSE);
1943
if(i->groupType() == CVG_AGENTS)
1944
cv->setShowAgents(FALSE);
1949
void ContactProfile::localUpdate(const JabRosterEntry &e)
1952
localStatus = e.local()->status;
1954
localStatus = STATUS_OFFLINE;
1957
void ContactProfile::scActionDefault(ContactViewItem *i)
1959
if(i->type() == CV_CONTACT)
1963
void ContactProfile::scRecvEvent(ContactViewItem *i)
1965
if(i->type() == CV_CONTACT)
1969
void ContactProfile::scSendMessage(ContactViewItem *i)
1971
if(i->type() == CV_CONTACT)
1972
actionSendMessage(i);
1975
void ContactProfile::scRename(ContactViewItem *i)
1977
if((i->type() == CV_CONTACT && i->inList()) || (i->type() == CV_GROUP && i->groupType() == CVG_USER)) {
1978
if(i->type() == CV_GROUP)
1979
i->resetGroupName(FALSE);
1981
i->setRenameEnabled(0, TRUE);
1983
i->setRenameEnabled(0, FALSE);
1987
void ContactProfile::scGroupChange(const QString &jid, const QString &newgroup)
1989
actionGroupChange(jid, newgroup);
1992
void ContactProfile::scHistory(ContactViewItem *i)
1994
if(i->type() == CV_CONTACT)
1995
actionHistory(i->jid());
1998
void ContactProfile::scOpenChat(ContactViewItem *i)
2000
if(i->type() == CV_CONTACT)
2001
actionOpenChat(i->jid());
2004
void ContactProfile::scAgentSetStatus(ContactViewItem *i, int s)
2006
if(i->status() != STATUS_OFFLINE || localStatus == STATUS_OFFLINE)
2009
actionAgentSetStatus(i->jid(), s);
2012
void ContactProfile::scRemove(ContactViewItem *i)
2014
ContactProfileItem *pi = cvi2cpi(i);
2016
if(!(localStatus == STATUS_OFFLINE && i->inList())) {
2017
QString name = i->jid();
2018
if(i->nick() != i->jid())
2019
name += QString(" (%1)").arg(i->nick());
2022
if(i->parentGroupType() != CVG_NOTINLIST) {
2023
n = QMessageBox::information(cv, CAP(tr("Remove")),
2024
QString(tr("Are you sure you want to remove <b>%1</b> from your contact list?")).arg(name),
2025
tr("&Yes"), tr("&No"));
2029
QString jid = i->jid();
2036
void ContactProfile::doItemRenamed(ContactViewItem *i, const QString &text)
2038
if(i->type() == CV_CONTACT) {
2040
if(text == i->nick())
2042
if(text.isEmpty()) {
2044
QMessageBox::information(cv, CAP(tr("Error")), tr("You can't set a blank nickname."));
2049
actionRename(i, text);
2053
if(text == i->groupName()) {
2054
i->resetGroupName();
2057
if(text.isEmpty()) {
2058
i->resetGroupName();
2059
QMessageBox::information(cv, CAP(tr("Error")), tr("You can't set a blank nickname."));
2063
// make sure we don't have it already
2064
QStringList groupList = buildGroupList();
2065
if(qstringlistmatch(groupList, text) != -1) {
2066
i->resetGroupName();
2067
QMessageBox::information(cv, CAP(tr("Error")), tr("You already have a group with that name."));
2071
QString oldName = i->groupName();
2074
i->setGroupName(text);
2075
cv->deferredContactSort();
2078
actionGroupRename(oldName, text);
2082
// return a list of contacts from a CVI group
2083
QStringList ContactProfile::contactListFromCVGroup(ContactViewItem *group)
2087
for(ContactViewItem *item = LVI2CVI(group->firstChild()); item ; item = LVI2CVI(item->nextSibling())) {
2088
if(item->type() != CV_CONTACT)
2091
list.append(item->jid());
2097
// return a list of contacts associated with "groupName"
2098
QStringList ContactProfile::contactListFromGroup(const QString &groupName)
2102
QDictIterator<ContactProfileItem> it(*roster);
2103
ContactViewItem *item;
2104
for(ContactProfileItem *pi; (pi = it.current()); ++it) {
2106
if(!item->isAgent() && item->group() == groupName)
2107
list.append(item->jid());
2113
int ContactProfile::contactSizeFromCVGroup(ContactViewItem *group)
2117
for(ContactViewItem *item = LVI2CVI(group->firstChild()); item ; item = LVI2CVI(item->nextSibling())) {
2118
if(item->type() != CV_CONTACT)
2127
// return the number of contacts associated with "groupName"
2128
int ContactProfile::contactSizeFromGroup(const QString &groupName)
2132
QDictIterator<ContactProfileItem> it(*roster);
2133
ContactViewItem *item;
2134
for(ContactProfileItem *pi; (pi = it.current()); ++it) {
2137
//printf("null item!!!\n");
2138
if(!item->parent()) {
2139
//printf("cvi: [%s]\n", item->jid().latin1());
2140
//printf("null parent!!!\n");
2143
int type = item->parentGroupType();
2144
if((type == CVG_ONLINE || type == CVG_OFFLINE || type == CVG_USER) && item->group() == groupName)
2151
void ContactProfile::updateGroupInfo(ContactViewItem *group)
2155
inGroup = contactSizeFromCVGroup(group);
2157
int type = group->groupType();
2158
if(type == CVG_ONLINE || type == CVG_OFFLINE || type == CVG_USER) {
2161
if(type == CVG_USER)
2162
gname = group->groupName();
2165
total = contactSizeFromGroup(gname);
2167
group->setGroupInfo(QString("(%1/%2)").arg(inGroup).arg(total));
2170
group->setGroupInfo(QString("(%1)").arg(inGroup));