1
/****************************************************************************
2
** contactview.h - 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
****************************************************************************/
2
* contactview.h - contact list widget
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 library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
21
#ifndef CONTACTVIEW_H
22
22
#define CONTACTVIEW_H
24
25
#include<qlistview.h>
27
#include<qstringlist.h>
29
26
#include<qtooltip.h>
37
/****************************************************************************
42
****************************************************************************/
52
#define CVG_NOTINLIST 3
53
#define CVG_AUTHWAIT 4
58
#define LVI2CVI(x) (static_cast<ContactViewItem*>(x))
27
#include<qvaluelist.h>
30
typedef QValueList<XMPP::Jid> JidList;
31
typedef QValueListIterator<XMPP::Jid> JidListIt;
62
36
class ContactViewItem;
64
struct ContactProfileItem
70
// ContactProfile: this holds/manipulates a roster profile for an account
46
// ContactProfile: this holds/manipulates a roster profile for an account
71
47
class ContactProfile : public QObject
76
ContactProfile(const QString &, const QString &, int _localStatus, bool, ContactView *);
51
ContactProfile(PsiAccount *, const QString &name, ContactView *, bool unique=false);
81
ContactViewItem *cvi, *cvi_online, *cvi_offline;
82
QDict<ContactProfileItem> *roster;
84
ContactView *contactView() { return cv; }
85
ContactViewItem *online() { return cvi_online; }
86
ContactViewItem *offline() { return cvi_offline; }
54
void setEnabled(bool e=TRUE);
56
const QString & name() const;
57
void setName(const QString &name);
59
void setUsingSSL(bool);
60
ContactView *contactView() const;
61
ContactViewItem *self() const;
63
PsiAccount *psiAccount() const;
65
void updateEntry(const UserListItem &);
66
void removeEntry(const Jid &);
70
void setAlert(const Jid &, const Icon *);
71
void clearAlert(const Jid &);
72
void animateNick(const Jid &);
74
void addAllNeededContactItems();
75
void removeAllUnneededContactItems();
77
void ensureVisible(const Jid &);
89
ContactProfileItem *cvi2cpi(ContactViewItem *);
90
ContactProfileItem *findByJid(const QString &jid);
91
bool isMine(ContactViewItem *);
92
ContactViewItem *findCVIByJid(const QString &jid);
94
void doContextMenu(ContactViewItem *, const QPoint &);
96
ContactViewItem *addGroup(int group);
97
ContactViewItem *addGroup(const QString &group, ContactViewItem *par);
99
ContactViewItem *checkGroup(int group);
100
ContactViewItem *checkGroup(const QString &group, ContactViewItem *par);
102
ContactViewItem *ensureGroup(int group);
103
ContactViewItem *ensureGroup(const QString &group, int status);
105
void changeGroup(ContactViewItem *item, ContactViewItem *group_new);
106
void changeGroup(ContactViewItem *item, const QString &group);
80
QString makeTip(bool trim, bool doLinkify) const;
82
ContactViewItem *checkGroup(int type);
83
ContactViewItem *checkGroup(const QString &name);
85
void setName(const char *);
89
void actionDefault(const Jid &);
90
void actionRecvEvent(const Jid &);
91
void actionSendMessage(const Jid &);
92
void actionSendMessage(const JidList &);
93
void actionSendUrl(const Jid &);
94
void actionRemove(const Jid &);
95
void actionRename(const Jid &, const QString &);
96
void actionGroupRename(const QString &, const QString &);
97
void actionHistory(const Jid &);
98
void actionStatusShow(const Jid &);
99
void actionOpenChat(const Jid &);
100
void actionOpenChatSpecific(const Jid &);
101
void actionAgentSetStatus(const Jid &, int);
102
void actionInfo(const Jid &);
103
void actionAuth(const Jid &);
104
void actionAuthRequest(const Jid &);
105
void actionAuthRemove(const Jid &);
106
void actionAdd(const Jid &);
107
void actionGroupAdd(const Jid &, const QString &);
108
void actionGroupRemove(const Jid &, const QString &);
109
void actionTest(const Jid &);
110
void actionSendFile(const Jid &);
111
void actionSendFiles(const Jid &, const QStringList &);
112
void actionDisco(const Jid &, const QString &);
113
void actionInvite(const Jid &, const QString &);
114
void actionAssignKey(const Jid &);
115
void actionUnassignKey(const Jid &);
126
ContactViewItem *addGroup(int type);
127
ContactViewItem *addGroup(const QString &name);
128
ContactViewItem *ensureGroup(int type);
129
ContactViewItem *ensureGroup(const QString &name);
108
130
void checkDestroyGroup(ContactViewItem *group);
109
131
void checkDestroyGroup(const QString &group);
111
ContactProfileItem *addEntry(const UserListItem &i);
112
void updateEntry(const UserListItem &);
113
void removeEntry(const QString &jid);
115
void showAlert(const QString &jid, int type);
116
void clearAlert(const QString &jid, int at=0);
117
void clearAllAlerts(const QString &jid);
118
void animateNick(const QString &jid);
120
void removeEntry(ContactProfileItem *pi);
121
void clearAlert(ContactViewItem *, int at=0);
122
void clearAllAlerts(ContactViewItem *);
132
ContactViewItem *addContactItem(Entry *e, ContactViewItem *group_item);
133
ContactViewItem *ensureContactItem(Entry *e, ContactViewItem *group_item);
134
void removeContactItem(Entry *e, ContactViewItem *i);
135
void addNeededContactItems(Entry *e);
136
void removeUnneededContactItems(Entry *e);
137
void clearContactItems(Entry *e);
139
void removeEntry(Entry *);
140
Entry *findEntry(const Jid &) const;
141
Entry *findEntry(ContactViewItem *) const;
143
void ensureVisible(Entry *);
124
145
// useful functions to grab groups of users
125
QStringList contactListFromCVGroup(ContactViewItem *);
126
QStringList contactListFromGroup(const QString &groupName);
127
int contactSizeFromCVGroup(ContactViewItem *);
128
int contactSizeFromGroup(const QString &groupName);
146
JidList contactListFromCVGroup(ContactViewItem *) const;
147
int contactSizeFromCVGroup(ContactViewItem *) const;
148
int contactsOnlineFromCVGroup(ContactViewItem *) const;
149
JidList contactListFromGroup(const QString &groupName) const;
150
int contactSizeFromGroup(const QString &groupName) const;
130
152
void updateGroupInfo(ContactViewItem *group);
153
QStringList groupList() const;
155
void deferredUpdateGroups();
157
friend class ContactView;
133
158
void scActionDefault(ContactViewItem *);
134
159
void scRecvEvent(ContactViewItem *);
135
160
void scSendMessage(ContactViewItem *);
136
161
void scRename(ContactViewItem *);
137
void scGroupChange(const QString &, const QString &);
138
162
void scHistory(ContactViewItem *);
139
163
void scOpenChat(ContactViewItem *);
140
164
void scAgentSetStatus(ContactViewItem *, int);
141
165
void scRemove(ContactViewItem *);
142
166
void doItemRenamed(ContactViewItem *, const QString &);
145
void actionDefault(ContactViewItem *);
146
void actionRecvEvent(ContactViewItem *);
147
void actionSendMessage(ContactViewItem *);
148
void actionSendMessage(const QStringList &);
149
void actionSendUrl(const QString &);
150
void actionRemove(const QString &);
151
void actionAuthorize(ContactViewItem *);
152
void actionAdd(ContactViewItem *);
153
void actionRename(ContactViewItem *, const QString &);
154
void actionGroupChange(const QString &, const QString &);
155
void actionGroupRename(const QString &, const QString &);
156
void actionHistory(const QString &);
157
void actionStatusShow(const QString &);
158
void actionOpenChat(const QString &);
159
void actionAgentSetStatus(const QString &, int);
160
void actionInfo(const QString &);
161
void actionOfferFile(const QString &);
164
void localUpdate(const JabRosterEntry &e);
167
QStringList buildGroupList();
171
// ContactViewItem: this can be either a contact or a group
172
class ContactViewItem : public QListViewItem
176
ContactViewItem(const QString &xgroupname, int xgrouptype, QListView *parent);
178
ContactViewItem(const QString &xgroupname, int xgrouptype, QListViewItem *parent);
180
ContactViewItem(const QString &xjid, const QString &xname, bool xisAgent, QListViewItem *parent);
185
int type() { return v_type; }
186
int status() { return v_status; }
187
QString & jid() { return v_jid; }
188
QString & nick() { return v_nick; }
189
QString & group() { return v_group; }
190
QString & sub() { return v_sub; }
191
QString & statusString() { return v_statusString; }
192
bool inList() { return v_inList; }
193
bool isAgent() { return v_isAgent; }
194
bool isAlert() { return v_isAlert; }
195
bool isAnimateNick() { return v_isAnimateNick; }
196
int groupType() { return v_groupType; }
197
QString & groupName() { return v_groupName; }
198
JabResourceList & resList() { return v_resList; }
200
int parentGroupType(); // use with contacts: returns grouptype of parent group
205
void setNick(const QString &);
206
void resetNick(); // use this to cancel a rename
207
void setGroup(const QString &);
208
void setSub(const QString &);
209
void setStatusString(const QString &);
210
void setInList(bool=TRUE);
211
void setIsAgent(bool=TRUE);
212
void setAlert(int type);
213
void clearAlert(int at=0);
214
void setAttr(const QString &xnick, const QString xgroup, const QString &sub, int status);
215
void setAnimateNick();
216
void stopAnimateNick();
218
void setGroupName(const QString &);
219
void setGroupInfo(const QString &);
220
void resetGroupName(bool showInfo=TRUE);
226
void optionsUpdate();
230
bool needSorting; // dirty flag for group items
233
int v_type, v_status;
238
QString v_statusString;
239
bool v_inList, v_isAgent;
240
JabResourceList v_resList;
243
QString v_groupName, v_groupInfo;
245
bool v_isAlert, v_isAnimateNick;
248
QPtrList<int> alertQueue;
249
int animateNickX, animateNickColor;
252
void drawGroupIcon();
255
int rankGroup(int groupType) const;
256
int rankStatus(int status) const;
258
// reimplemented functions
259
void paintFocus(QPainter *, const QColorGroup &, const QRect &);
260
void paintBranches(QPainter *, const QColorGroup &, int, int, int);
261
void paintCell(QPainter *, const QColorGroup & cg, int column, int width, int alignment);
262
void setOpen(bool o);
263
int compare(QListViewItem *, int, bool) const;
264
virtual void insertItem(QListViewItem * newChild);
265
virtual void takeItem(QListViewItem * item);
268
//virtual bool acceptDrop(const QMimeSource *) const;
269
//void dropped(QDropEvent *);
167
void doContextMenu(ContactViewItem *, const QPoint &);
169
friend class ContactViewItem;
170
void dragDrop(const QString &, ContactViewItem *);
171
void dragDropFiles(const QStringList &, ContactViewItem *);
174
// ContactView: the actual widget
273
175
class ContactView : public QListView, public QToolTip
278
179
ContactView(QWidget *parent=0, const char *name=0);
281
ContactProfile *createProfile(const QString &jid, const QString &name, bool unique=FALSE);
282
ContactProfile *findProfile(const QString &jid);
283
void removeProfile(const QString &jid);
284
void removeProfile(ContactProfile *p);
285
ContactProfile *defPro();
286
ContactProfile *owner(ContactViewItem *);
288
void clear(); // override QListView
290
bool isShowOffline() { return v_showOffline; }
291
bool isShowAgents() { return v_showAgents; }
292
bool isShowAway() { return v_showAway; }
295
void deferredContactSort();
298
void ensureVisible(ContactViewItem *);
299
void setVisibility(ContactViewItem *);
301
QAction *qa_send, *qa_chat, *qa_ren, *qa_hist, *qa_logon, *qa_recv, *qa_rem;
304
bool v_showOffline, v_showAway, v_showAgents;
182
bool isShowOffline() const { return v_showOffline; }
183
bool isShowAgents() const { return v_showAgents; }
184
bool isShowAway() const { return v_showAway; }
185
bool isShowHidden() const { return v_showHidden; }
186
bool isShowSelf() const { return v_showSelf; }
190
QTimer *animTimer() const;
192
IconAction *qa_send, *qa_chat, *qa_ren, *qa_hist, *qa_logon, *qa_recv, *qa_rem;
194
//IconAction *qa_assignAvatar, *qa_clearAvatar;
307
void resizeEvent(QResizeEvent *);
199
void maybeTip(const QPoint &);
308
200
void keyPressEvent(QKeyEvent *);
309
void viewportMousePressEvent(QMouseEvent *);
310
void viewportMouseMoveEvent(QMouseEvent *);
312
QPoint mousePressPos; // store pressed position, idea taken from Licq
314
bool lcto_active; // double click active?
316
QListViewItem *lcto_item;
320
QPtrList<ContactProfile> profiles;
324
void maybeTip(const QPoint &);
325
//QDragObject *dragObject();
326
void dragEnterEvent(QDragEnterEvent *);
327
void dropEvent(QDropEvent *);
201
QDragObject *dragObject();
330
204
void showOffline(bool);
331
205
void showAway(bool);
206
void showHidden(bool);
332
207
void showAgents(bool);
335
211
void setShowOffline(bool);
336
212
void setShowAgents(bool);
337
213
void setShowAway(bool);
214
void setShowHidden(bool);
215
void setShowSelf(bool);
339
216
void optionsUpdate();
342
219
void qlv_singleclick(int, QListViewItem *, const QPoint &, int);
343
220
void qlv_doubleclick(QListViewItem *);
344
221
void qlv_contextPopup(QListViewItem *, const QPoint &, int);
222
void qlv_contextMenuRequested(QListViewItem *, const QPoint &, int);
345
223
void qlv_itemRenamed(QListViewItem *, int, const QString &);
346
224
void leftClickTimeOut();
349
226
void doRecvEvent();