1
/****************************************************************************
2
** historydlg.cpp - a dialog to show message history
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
****************************************************************************/
24
#include<qpushbutton.h>
26
#include<qpopupmenu.h>
28
#include<qapplication.h>
29
#include<qclipboard.h>
31
#include"historydlg.h"
34
/****************************************************************************
35
HistoryDlg - a dialog window for history
36
****************************************************************************/
37
HistoryDlg::HistoryDlg(UserListItem *item, QWidget *parent, const char *name)
38
:QWidget(parent, name), UniqueWindow(TRUE, "HistoryDlg", this, cleanJid(item->jid))
42
setWFlags(getWFlags() | WDestructiveClose);
44
setCaption(item->jid);
45
setIcon(*pix_history);
47
QVBoxLayout *vb1 = new QVBoxLayout(this, 8);
48
lv = new HistoryView(this);
49
connect(lv, SIGNAL(aOpenMessage(const Message &)), SLOT(actionOpenMessage(const Message &)));
52
QHBoxLayout *hb1 = new QHBoxLayout(vb1);
54
QPushButton *pb = new QPushButton(tr("&Refresh"), this);
55
pb->setMinimumWidth(80);
56
connect(pb, SIGNAL(clicked()), SLOT(doRefresh()));
59
QLabel *lb = new QLabel(tr("Search:"), this);
61
le_search = new QLineEdit(this);
62
connect(le_search, SIGNAL(textChanged(const QString &)), SLOT(searchTextChanged(const QString &)));
63
connect(le_search, SIGNAL(returnPressed()), SLOT(doSearch()));
64
hb1->addWidget(le_search);
65
pb_go = new QPushButton(tr("&Go"), this);
66
//pb->setMinimumWidth(80);
67
pb_go->setEnabled(FALSE);
68
connect(pb_go, SIGNAL(clicked()), SLOT(doSearch()));
69
hb1->addWidget(pb_go);
71
QComboBox *cb = new QComboBox(this);
72
cb->insertItem(tr("Show Last 50"));
73
cb->insertItem(tr("Show Last 100"));
74
cb->insertItem(tr("Show Last 500"));
75
cb->insertItem(tr("Show all"));
76
connect(cb, SIGNAL(activated(int)), SLOT(comboChanged(int)));
81
pb = new QPushButton(tr("&Close"), this);
82
pb->setMinimumWidth(80);
83
connect(pb, SIGNAL(clicked()), SLOT(close()));
87
lv->setAllColumnsShowFocus(TRUE);
88
lv->addColumn(tr("Type"));
89
lv->addColumn(tr("Origin"));
90
lv->addColumn(tr("Date"));
91
lv->addColumn(tr("Text"));
93
lv->setResizeMode(QListView::LastColumn);
94
lv->setShowToolTips(FALSE);
95
lv->header()->setClickEnabled(FALSE);
96
lv->header()->setMovingEnabled(FALSE);
97
lv->header()->setResizeEnabled(FALSE);
104
void HistoryDlg::keyPressEvent(QKeyEvent *e)
106
if(e->key() == Key_Escape)
113
void HistoryDlg::show()
120
void HistoryDlg::doRefresh()
122
le_search->setText("");
127
void HistoryDlg::refresh()
130
MessageHistory log(v_jid, HISTORY_READ);
133
bool useSearch = !searchStr.isEmpty();
135
for(int n = 0; n != amountToShow; ++n) {
136
msg = log.readEntry();
140
if(msg->text.find(searchStr, 0, FALSE) == -1)
148
lv->setSelected(lv->firstChild(), TRUE);
151
void HistoryDlg::comboChanged(int x)
165
void HistoryDlg::searchTextChanged(const QString &str)
168
pb_go->setEnabled(!searchStr.isEmpty());
171
void HistoryDlg::doSearch()
173
if(searchStr.isEmpty())
179
void HistoryDlg::actionOpenMessage(const Message &msg)
184
/*static*/ HistoryDlg * HistoryDlg::find(const QString &xjid)
186
return (HistoryDlg *)UniqueWindowBank::find("HistoryDlg", cleanJid(xjid));
190
/****************************************************************************
191
HistoryView - a list view for history items
192
****************************************************************************/
193
HistoryView::HistoryView(QWidget *parent, const char *name)
194
:QListView(parent, name)
197
connect(this, SIGNAL(doubleClicked(QListViewItem *)), SLOT(qlv_doubleclick(QListViewItem *)));
198
connect(this, SIGNAL(rightButtonPressed(QListViewItem *, const QPoint &, int)), SLOT(qlv_contextPopup(QListViewItem *, const QPoint &, int)));
201
void HistoryView::resizeEvent(QResizeEvent *e)
203
QListView::resizeEvent(e);
205
if(e->oldSize().width() != e->size().width())
209
void HistoryView::keyPressEvent(QKeyEvent *e)
211
if(e->key() == Key_Enter || e->key() == Key_Return)
214
QListView::keyPressEvent(e);
217
void HistoryView::doResize()
219
QListViewItemIterator it(this);
220
HistoryViewItem *item;
221
for(; it.current() ; ++it) {
222
item = (HistoryViewItem *)it.current();
227
void HistoryView::addMessage(Message *msg)
229
HistoryViewItem *lvi;
230
lvi = new HistoryViewItem(msg, at_id++, this);
233
void HistoryView::doOpenMessage()
235
HistoryViewItem *i = (HistoryViewItem *)selectedItem();
238
aOpenMessage(*i->msg);
241
void HistoryView::qlv_doubleclick(QListViewItem *xi)
243
HistoryViewItem *i = (HistoryViewItem *)xi;
245
setSelected(i, TRUE);
249
void HistoryView::qlv_contextPopup(QListViewItem *ix, const QPoint &pos, int)
251
HistoryViewItem *i = (HistoryViewItem *)ix;
256
popup.insertItem(tr("Open"), 1);
257
popup.insertSeparator();
258
popup.insertItem(tr("Copy"), 2);
260
int x = popup.exec(pos);
265
HistoryViewItem *i = (HistoryViewItem *)selectedItem();
268
QApplication::clipboard()->setText(i->msg->text);
273
/****************************************************************************
274
HistoryViewItem - a history item
275
****************************************************************************/
276
HistoryViewItem::HistoryViewItem(Message *message, int xid, QListView *parent)
277
:QListViewItem(parent)
283
if(msg->type == MESSAGE_NORM) {
284
text = plain2rich(msg->text);
286
if(!msg->url.isEmpty())
287
setPixmap(0, *pix_url);
288
else if(msg->originLocal)
289
setPixmap(0, *pix_send);
291
setPixmap(0, anim_message->base());
293
else if(msg->type == MESSAGE_CHAT) {
294
text = plain2rich(msg->text);
295
setPixmap(0, anim_chat->base());
297
else if(msg->type == MESSAGE_HEADLINE) {
298
text = plain2rich(msg->text);
299
setPixmap(0, anim_headline->base());
303
setPixmap(0, anim_system->base());
307
setText(1, QObject::tr("To"));
309
setText(1, QObject::tr("From"));
312
date.sprintf("%02d/%02d/%02d %02d:%02d:%02d",
313
msg->timeStamp.date().month(),
314
msg->timeStamp.date().day(),
315
msg->timeStamp.date().year(),
316
msg->timeStamp.time().hour(),
317
msg->timeStamp.time().minute(),
318
msg->timeStamp.time().second());
322
rt = new QSimpleRichText(text, listView()->font());
325
HistoryViewItem::~HistoryViewItem()
334
// reimplemented from QListViewItem. setup() and paintCell() are tricky stuff
335
void HistoryViewItem::setup()
339
QListView *lv = listView();
342
int w = lv->columnWidth(3);
347
//y = lv->fontMetrics().size(AlignVCenter, displayStr).height();
353
y += lv->itemMargin() * 2;
355
// ensure an even number
362
void HistoryViewItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int alignment)
364
QColorGroup mycg = cg;
366
mycg.setColor(QColorGroup::Text, Qt::red);
368
mycg.setColor(QColorGroup::Text, Qt::blue);
373
mycg.setColor(QColorGroup::Text, Qt::white);
375
br = cg.brush(QColorGroup::Highlight);
378
br = cg.brush(QColorGroup::Base);
382
QSimpleRichText tmp(QString("<qt><font color=\"%1\">" + text + "</font></qt>").arg(mycg.text().name()), listView()->font());
383
tmp.setWidth(rt->width());
384
tmp.draw(p, 0, 0, QRegion(0, 0, width/* - (a * 2)*/, height()), mycg, &br);
388
alignment = AlignTop;
390
QListViewItem::paintCell(p, mycg, column, width, alignment);
394
int HistoryViewItem::compare(QListViewItem *xi, int, bool) const
396
HistoryViewItem *i = (HistoryViewItem *)xi;