109
//----------------------------------------------------------------------------
111
//----------------------------------------------------------------------------
112
98
class HistoryDlg::Private
121
QPushButton *pb_prev, *pb_next, *pb_refresh, *pb_find;
124
104
QString id_prev, id_begin, id_end, id_next;
105
HistoryDlg::RequestType reqType;
131
110
HistoryDlg::HistoryDlg(const Jid &jid, PsiAccount *pa)
111
: AdvancedWidget<QDialog>(0, Qt::Window)
133
114
setAttribute(Qt::WA_DeleteOnClose);
134
if ( PsiOptions::instance()->getOption("options.ui.mac.use-brushed-metal-windows").toBool() )
135
setAttribute(Qt::WA_MacMetalStyle);
117
d->reqType = TypeNone;
139
121
d->pa->dialogRegister(this, d->jid);
142
setWindowTitle(d->jid.full());
144
124
setWindowIcon(IconsetFactory::icon("psi/history").icon());
147
d->h = new EDBHandle(d->pa->edb());
148
connect(d->h, SIGNAL(finished()), SLOT(edb_finished()));
150
QVBoxLayout *vb1 = new QVBoxLayout(this);
151
d->lv = new HistoryView(this);
152
d->lv->setVScrollBarMode(Q3ScrollView::AlwaysOn);
153
connect(d->lv, SIGNAL(aOpenEvent(PsiEvent *)), SLOT(actionOpenEvent(PsiEvent *)));
154
QSizePolicy sp = d->lv->sizePolicy();
155
sp.setVerticalStretch(1);
156
d->lv->setSizePolicy(sp);
157
vb1->addWidget(d->lv);
159
QHBoxLayout *hb1 = new QHBoxLayout;
162
QVBoxLayout *vb2 = new QVBoxLayout;
165
QHBoxLayout *hb2 = new QHBoxLayout;
168
//d->busy = new BusyWidget(this);
169
//hb1->addWidget(d->busy);
171
d->pb_refresh = new QPushButton(tr("&Latest"), this);
172
d->pb_refresh->setMinimumWidth(80);
173
connect(d->pb_refresh, SIGNAL(clicked()), SLOT(doLatest()));
174
hb2->addWidget(d->pb_refresh);
176
d->pb_prev = new QPushButton(tr("&Previous"), this);
177
d->pb_prev->setMinimumWidth(80);
178
connect(d->pb_prev, SIGNAL(clicked()), SLOT(doPrev()));
179
hb2->addWidget(d->pb_prev);
181
d->pb_next = new QPushButton(tr("&Next"), this);
182
d->pb_next->setMinimumWidth(80);
183
connect(d->pb_next, SIGNAL(clicked()), SLOT(doNext()));
184
hb2->addWidget(d->pb_next);
186
QHBoxLayout *hb3 = new QHBoxLayout;
189
d->le_find = new QLineEdit(this);
190
connect(d->le_find, SIGNAL(textChanged(const QString &)), SLOT(le_textChanged(const QString &)));
191
connect(d->le_find, SIGNAL(returnPressed()), SLOT(doFind()));
192
hb3->addWidget(d->le_find);
193
d->pb_find = new QPushButton(tr("Find"), this);
194
connect(d->pb_find, SIGNAL(clicked()), SLOT(doFind()));
195
d->pb_find->setEnabled(false);
196
hb3->addWidget(d->pb_find);
199
sep = new QFrame(this);
200
sep->setFrameShape(QFrame::VLine);
203
QVBoxLayout *vb3 = new QVBoxLayout;
206
QPushButton *pb_save = new QPushButton(tr("&Export..."), this);
207
connect(pb_save, SIGNAL(clicked()), SLOT(doSave()));
208
vb3->addWidget(pb_save);
209
QPushButton *pb_erase = new QPushButton(tr("Er&ase All"), this);
210
connect(pb_erase, SIGNAL(clicked()), SLOT(doErase()));
211
vb3->addWidget(pb_erase);
213
sep = new QFrame(this);
214
sep->setFrameShape(QFrame::VLine);
219
QVBoxLayout *vb4 = new QVBoxLayout;
223
QPushButton *pb_close = new QPushButton(tr("&Close"), this);
224
pb_close->setMinimumWidth(80);
225
connect(pb_close, SIGNAL(clicked()), SLOT(close()));
226
vb4->addWidget(pb_close);
230
X11WM_CLASS("history");
232
d->le_find->setFocus();
126
ui_.tb_find->setIcon(IconsetFactory::icon("psi/search").icon());
128
ui_.msgLog->setFont(fontForOption("options.ui.look.font.chat"));
129
ui_.jidList->setFont(fontForOption("options.ui.look.font.contactlist"));
131
ui_.calendar->setFirstDayOfWeek(firstDayOfWeekFromLocale());
133
connect(ui_.searchField, SIGNAL(returnPressed()), SLOT(findMessages()));
134
connect(ui_.searchField, SIGNAL(textChanged(const QString)), SLOT(highlightBlocks(const QString)));
135
connect(ui_.buttonPrevious, SIGNAL(released()), SLOT(getPrevious()));
136
connect(ui_.buttonNext, SIGNAL(released()), SLOT(getNext()));
137
connect(ui_.buttonRefresh, SIGNAL(released()), SLOT(refresh()));
138
connect(ui_.jidList, SIGNAL(itemSelectionChanged()), SLOT(openSelectedContact()));
139
connect(ui_.tb_find, SIGNAL(clicked()), SLOT(findMessages()));
140
connect(ui_.buttonLastest, SIGNAL(released()), SLOT(getLatest()));
141
connect(ui_.buttonEarliest, SIGNAL(released()), SLOT(getEarliest()));
142
connect(ui_.calendar, SIGNAL(selectionChanged()), SLOT(getDate()));
143
connect(ui_.calendar, SIGNAL(activated(QDate)), SLOT(getDate()));
145
connect(d->pa, SIGNAL(removedContact(PsiContact*)), SLOT(removedContact(PsiContact*)));
147
ui_.jidList->installEventFilter(this);
152
setGeometryOptionPath(geometryOption);
154
ui_.jidList->setFocus();
238
157
HistoryDlg::~HistoryDlg()
241
d->pa->dialogUnregister(this);
245
void HistoryDlg::keyPressEvent(QKeyEvent *e)
247
if(e->key() == Qt::Key_Escape)
254
void HistoryDlg::closeEvent(QCloseEvent *e)
262
void HistoryDlg::show()
268
void HistoryDlg::le_textChanged(const QString &s)
270
if(s.isEmpty() && d->pb_find->isEnabled())
271
d->pb_find->setEnabled(false);
272
else if(!s.isEmpty() && !d->pb_find->isEnabled())
273
d->pb_find->setEnabled(true);
276
void HistoryDlg::setButtons()
278
d->pb_prev->setEnabled(!d->id_prev.isEmpty());
279
d->pb_next->setEnabled(!d->id_next.isEmpty());
282
void HistoryDlg::doLatest()
287
void HistoryDlg::doPrev()
292
void HistoryDlg::doNext()
297
void HistoryDlg::doSave()
299
UserListItem *u = d->pa->findFirstRelevant(d->jid);
162
bool HistoryDlg::eventFilter(QObject *obj, QEvent *e)
164
if(obj == ui_.jidList && e->type() == QEvent::ContextMenu) {
166
QTimer::singleShot(0, this, SLOT(doMenu()));
170
return QDialog::eventFilter(obj, e);
173
QFont HistoryDlg::fontForOption(const QString &option)
176
font.fromString(PsiOptions::instance()->getOption(option).toString());
180
void HistoryDlg::changeAccount(const QString /*accountName*/)
185
d->pa = d->psi->contactList()->getAccountByJid(ui_.accountsBox->itemData(ui_.accountsBox->currentIndex()).toString());
187
ui_.jidList->setCurrentRow(0);
188
openSelectedContact();
191
void HistoryDlg::listAccounts()
195
foreach (PsiAccount* account, d->psi->contactList()->enabledAccounts())
196
ui_.accountsBox->addItem(IconsetFactory::icon("psi/account").icon(), account->nameWithJid(), QVariant(account->jid().full()));
198
//select active account
199
ui_.accountsBox->setCurrentIndex(ui_.accountsBox->findData(d->pa->jid().full()));
200
//connect signal after the list is populated to prevent execution in the middle of the loop
201
connect(ui_.accountsBox, SIGNAL(currentIndexChanged(const QString)), SLOT(changeAccount(const QString)));
204
void HistoryDlg::loadContacts()
207
ui_.jidList->clear();
209
foreach (PsiContact* contact, d->pa->contactList())
211
if(contact->isPrivate()
212
|| jids_.contains(contact->jid().bare()))
215
QListWidgetItem *item = new QListWidgetItem(contact->name(), ui_.jidList);
216
item->setToolTip(contact->jid().bare());
217
item->setIcon(PsiIconset::instance()->statusPtr(contact->jid(),Status(Status::Online))->icon());
218
//item->setIcon(PsiIconset::instance()->status(contact->status()).icon());
219
ui_.jidList->addItem(item);
220
jids_.append(item->toolTip());
222
PsiContact* self = d->pa->selfContact();
223
if(!jids_.contains(self->jid().bare())) {
224
QListWidgetItem *item = new QListWidgetItem(self->name(), ui_.jidList);
225
item->setToolTip(self->jid().bare());
226
//item->setIcon(PsiIconset::instance()->status(self->status()).icon());
227
item->setIcon(PsiIconset::instance()->statusPtr(self->jid(),Status(Status::Online))->icon());
228
ui_.jidList->addItem(item);
229
jids_.append(item->toolTip());
232
ui_.jidList->sortItems();
233
//set contact in jidList to selected jid
234
for (int i = 0; i < ui_.jidList->count(); i++)
236
if (ui_.jidList->item(i)->toolTip() == d->jid.bare().toLower())
237
ui_.jidList->setCurrentRow(i); //triggers openSelectedContact()
241
void HistoryDlg::openSelectedContact()
244
UserListItem *u = currentUserListItem();
248
setWindowTitle(u->name() + " (" + u->jid().full() + ")");
253
void HistoryDlg::highlightBlocks(const QString text)
255
QTextCursor cur = ui_.msgLog->textCursor();
256
cur.clearSelection();
257
cur.movePosition(QTextCursor::Start);
258
ui_.msgLog->setTextCursor(cur);
260
if (text.isEmpty()) {
265
QList<QTextEdit::ExtraSelection> extras;
266
QTextEdit::ExtraSelection highlight;
267
highlight.format.setBackground(Qt::yellow);
268
highlight.cursor = ui_.msgLog->textCursor();
270
bool found = ui_.msgLog->find(text);
273
highlight.cursor = ui_.msgLog->textCursor();
275
found = ui_.msgLog->find(text);
278
ui_.msgLog->setExtraSelections(extras);
281
void HistoryDlg::findMessages()
283
//get the oldest event as a starting point
285
d->reqType = TypeFindOldest;
286
getEDBHandle()->getOldest(d->jid, 1);
289
void HistoryDlg::removeHistory()
291
int res = QMessageBox::question(this, tr("Remove history"),
292
tr("Are you sure you want to completely remove history for a contact %1?").arg(d->jid.bare())
293
,QMessageBox::Ok | QMessageBox::Cancel);
294
if(res == QMessageBox::Ok) {
295
getEDBHandle()->erase(d->jid);
296
openSelectedContact();
300
void HistoryDlg::openChat()
302
UserListItem *u = currentUserListItem();
304
d->pa->actionOpenChat2(u->jid().bare());
308
void HistoryDlg::exportHistory()
310
UserListItem *u = currentUserListItem();
300
313
QString them = JIDUtil::nickOrJid(u->name(), u->jid().full());
301
314
QString s = JIDUtil::encode(them).toLower();
303
QString str = FileUtil::getSaveFileName(this,
304
tr("Export message history"),
306
tr("Text files (*.txt);;All files (*.*)"));
308
if (!str.isEmpty()) {
313
void HistoryDlg::doErase()
315
int x = QMessageBox::information(this, tr("Confirm erase all"), tr("This will erase all message history for this contact!\nAre you sure you want to do this?"), tr("&Yes"), tr("&No"), QString::null, 1);
321
void HistoryDlg::loadPage(int type)
325
d->pb_refresh->setEnabled(false);
326
d->h->getLatest(d->jid, 50);
327
//printf("EDB: requesting latest 50 events\n");
330
d->pb_prev->setEnabled(false);
331
d->h->get(d->jid, d->id_prev, EDB::Backward, 50);
332
//printf("EDB: requesting 50 events backward, starting at %s\n", d->id_prev.latin1());
335
d->pb_next->setEnabled(false);
336
d->h->get(d->jid, d->id_next, EDB::Forward, 50);
337
//printf("EDB: requesting 50 events forward, starting at %s\n", d->id_next.latin1());
343
void HistoryDlg::displayResult(const EDBResult *r, int direction, int max)
345
//d->lv->setUpdatesEnabled(false);
347
int i = (direction == EDB::Forward) ? r->count()-1 : 0;
349
while (i >= 0 && i <= r->count()-1 && (max == -1 ? true : at < max)) {
350
EDBItem* item = r->value(i);
351
PsiEvent* e = item->event();
352
d->lv->addEvent(e, item->prevId());
354
i += (direction == EDB::Forward) ? -1 : +1;
356
//d->lv->setUpdatesEnabled(true);
357
//d->lv->repaint(true);
360
void HistoryDlg::edb_finished()
362
const EDBResult *r = d->h->result();
363
if(d->h->lastRequestType() == EDBHandle::Read && r) {
364
//printf("EDB: retrieved %d events:\n", r->count());
366
if(d->reqtype == 0 || d->reqtype == 1) {
367
// events are in backward order
368
// first entry is the end event
369
EDBItem* it = r->first();
370
d->id_end = it->id();
371
d->id_next = it->nextId();
372
// last entry is the begin event
374
d->id_begin = it->id();
375
d->id_prev = it->prevId();
376
displayResult(r, EDB::Backward);
377
//printf("[%s],[%s],[%s],[%s]\n", d->id_prev.latin1(), d->id_begin.latin1(), d->id_end.latin1(), d->id_next.latin1());
379
else if(d->reqtype == 2) {
380
// events are in forward order
381
// last entry is the end event
382
EDBItem* it = r->last();
383
d->id_end = it->id();
384
d->id_next = it->nextId();
385
// first entry is the begin event
387
d->id_begin = it->id();
388
d->id_prev = it->prevId();
389
displayResult(r, EDB::Forward);
391
else if(d->reqtype == 3) {
392
// should only be one entry
393
EDBItem *ei = r->first();
395
d->h->get(d->jid, ei->id(), EDB::Backward, 50);
396
//printf("EDB: requesting 50 events backward, starting at %s\n", d->id_prev.latin1());
401
if(d->reqtype == 3) {
402
QMessageBox::information(this, tr("Find"), tr("Search string '%1' not found.").arg(d->findStr));
407
else if (d->h->lastRequestType() == EDBHandle::Erase) {
408
if (d->h->writeSuccess()) {
416
QMessageBox::critical(this, tr("Error"), tr("Unable to delete history file."));
420
//printf("EDB: error\n");
423
if(d->lv->firstChild())
424
d->lv->setSelected(d->lv->firstChild(), true);
427
d->pb_refresh->setEnabled(true);
431
void HistoryDlg::actionOpenEvent(PsiEvent *e)
436
void HistoryDlg::doFind()
438
QString str = d->le_find->text();
442
if(d->lv->childCount() < 1)
445
HistoryViewItem *i = (HistoryViewItem *)d->lv->selectedItem();
447
i = (HistoryViewItem *)d->lv->firstChild();
448
QString id = i->eventId;
450
QMessageBox::information(this, tr("Find"), tr("Already at beginning of message history."));
454
//printf("searching for: [%s], starting at id=[%s]\n", str.latin1(), id.latin1());
457
d->h->find(str, d->jid, id, EDB::Backward);
460
void HistoryDlg::exportHistory(const QString &fname)
315
QString fname = FileUtil::getSaveFileName(this,
316
tr("Export message history"),
318
tr("Text files (*.txt);;All files (*.*)"));
463
323
if(!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
464
324
QMessageBox::information(this, tr("Error"), tr("Error writing to file."));
529
382
stream << txt << endl;
387
if(cnt == 0 || id.isEmpty()) {
542
//----------------------------------------------------------------------------
544
//----------------------------------------------------------------------------
545
HistoryView::HistoryView(QWidget *parent, const char *name)
546
:Q3ListView(parent, name)
549
connect(this, SIGNAL(doubleClicked(Q3ListViewItem *)), SLOT(qlv_doubleclick(Q3ListViewItem *)));
550
connect(this, SIGNAL(rightButtonPressed(Q3ListViewItem *, const QPoint &, int)), SLOT(qlv_contextPopup(Q3ListViewItem *, const QPoint &, int)));
552
setAllColumnsShowFocus(true);
553
addColumn(tr("Type"));
554
addColumn(tr("Origin"));
555
addColumn(tr("Date"));
556
addColumn(tr("Text"));
558
setResizeMode(Q3ListView::LastColumn);
559
setShowToolTips(false);
560
header()->setClickEnabled(false);
561
header()->setMovingEnabled(false);
562
header()->setResizeEnabled(false);
565
void HistoryView::resizeEvent(QResizeEvent *e)
567
Q3ListView::resizeEvent(e);
569
if(e->oldSize().width() != e->size().width())
573
void HistoryView::keyPressEvent(QKeyEvent *e)
575
if(e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)
578
Q3ListView::keyPressEvent(e);
581
void HistoryView::doResize()
583
Q3ListViewItemIterator it(this);
584
HistoryViewItem *item;
585
for(; it.current() ; ++it) {
586
item = (HistoryViewItem *)it.current();
591
void HistoryView::addEvent(PsiEvent *e, const QString &eid)
593
new HistoryViewItem(e, eid, at_id++, this);
596
void HistoryView::doOpenEvent()
598
HistoryViewItem *i = (HistoryViewItem *)selectedItem();
604
void HistoryView::qlv_doubleclick(Q3ListViewItem *xi)
606
HistoryViewItem *i = (HistoryViewItem *)xi;
608
setSelected(i, true);
612
void HistoryView::qlv_contextPopup(Q3ListViewItem *ix, const QPoint &pos, int)
614
HistoryViewItem *i = (HistoryViewItem *)ix;
619
popup.insertItem(tr("Open"), 1);
620
popup.insertSeparator();
621
popup.insertItem(tr("Copy"), 2);
623
if(i->e->type() != PsiEvent::Message)
624
popup.setItemEnabled(2, false);
626
int x = popup.exec(pos);
631
HistoryViewItem *i = (HistoryViewItem *)selectedItem();
635
MessageEvent *me = (MessageEvent *)i->e;
636
QApplication::clipboard()->setText(me->message().body(), QClipboard::Clipboard);
637
if(QApplication::clipboard()->supportsSelection())
638
QApplication::clipboard()->setText(me->message().body(), QClipboard::Selection);
643
//----------------------------------------------------------------------------
645
//----------------------------------------------------------------------------
646
HistoryViewItem::HistoryViewItem(PsiEvent *_e, const QString &eid, int xid, Q3ListView *parent)
647
:Q3ListViewItem(parent)
653
if(_e->type() == PsiEvent::Message) {
654
MessageEvent *me = (MessageEvent *)_e;
655
e = new MessageEvent(*me);
657
else if(_e->type() == PsiEvent::Auth) {
658
AuthEvent *ae = (AuthEvent *)_e;
659
e = new AuthEvent(*ae);
662
PsiIcon *a = PsiIconset::instance()->event2icon(e);
663
if(e->type() == PsiEvent::Message) {
664
MessageEvent *me = (MessageEvent *)e;
665
const Message &m = me->message();
666
text = TextUtil::plain2rich(m.body());
668
if(!m.urlList().isEmpty())
669
setPixmap(0, IconsetFactory::icon("psi/www").impix());
670
else if(e->originLocal())
671
setPixmap(0, IconsetFactory::icon("psi/sendMessage").impix());
673
setPixmap(0, a->impix());
675
else if(e->type() == PsiEvent::Auth) {
676
AuthEvent *ae = (AuthEvent *)e;
677
text = ae->authType();
679
setPixmap(0, a->impix());
683
setText(1, HistoryView::tr("To"));
685
setText(1, HistoryView::tr("From"));
688
const QDateTime &ts = e->timeStamp();
689
/*date.sprintf("%02d/%02d/%02d %02d:%02d:%02d",
695
ts.time().second());*/
696
date = ts.toString(Qt::LocalDate);
700
rt = new Q3SimpleRichText(text, listView()->font());
703
HistoryViewItem::~HistoryViewItem()
709
// reimplemented from QListViewItem. setup() and paintCell() are tricky stuff
710
void HistoryViewItem::setup()
714
Q3ListView *lv = listView();
717
int w = lv->columnWidth(3);
722
//y = lv->fontMetrics().size(AlignVCenter, displayStr).height();
728
y += lv->itemMargin() * 2;
730
// ensure an even number
737
void HistoryViewItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int alignment)
739
QColorGroup mycg = cg;
742
mycg.setColor(QColorGroup::Text, PsiOptions::instance()->getOption("options.ui.look.colors.messages.sent").toString() );
746
mycg.setColor(QColorGroup::Text,PsiOptions::instance()->getOption("options.ui.look.colors.messages.received").toString() );
752
mycg.setColor(QColorGroup::Text, mycg.highlightedText());
753
br = cg.brush(QColorGroup::Highlight);
756
br = cg.brush(QColorGroup::Base);
761
Q3SimpleRichText tmp(QString("<qt><font color=\"%1\">" + text + "</font></qt>").arg(mycg.text().name()), listView()->font());
762
tmp.setWidth(rt->width());
763
tmp.draw(p, 0, 0, QRect(0, 0, width, h), mycg, &br);
767
alignment = Qt::AlignTop;
769
Q3ListViewItem::paintCell(p, mycg, column, width, alignment);
773
int HistoryViewItem::compare(Q3ListViewItem *xi, int, bool) const
775
HistoryViewItem *i = (HistoryViewItem *)xi;
779
int HistoryViewItem::rtti() const
395
void HistoryDlg::doMenu()
397
QMenu *m = new QMenu(ui_.jidList);
398
m->addAction(IconsetFactory::icon("psi/chat").icon(), tr("&Open chat"), this, SLOT(openChat()));
399
m->addAction(IconsetFactory::icon("psi/save").icon(), tr("&Export history"), this, SLOT(exportHistory()));
400
m->addAction(IconsetFactory::icon("psi/clearChat").icon(), tr("&Delete history"), this, SLOT(removeHistory()));
401
m->exec(QCursor::pos());
404
void HistoryDlg::edb_finished()
409
EDBHandle* h = qobject_cast<EDBHandle*>(sender());
414
const EDBResult r = h->result();
415
if (h->lastRequestType() == EDBHandle::Read)
419
if (d->reqType == TypeLatest || d->reqType == TypePrevious)
421
// events are in backward order
422
// first entry is the end event
423
EDBItemPtr it = r.first();
424
d->id_end = it->id();
425
d->id_next = it->nextId();
426
// last entry is the begin event
428
d->id_begin = it->id();
429
d->id_prev = it->prevId();
430
displayResult(r, EDB::Forward);
433
else if (d->reqType == TypeEarliest || d->reqType == TypeNext || d->reqType == TypeDate)
435
// events are in forward order
436
// last entry is the end event
437
EDBItemPtr it = r.last();
438
d->id_end = it->id();
439
d->id_next = it->nextId();
440
// first entry is the begin event
442
d->id_begin = it->id();
443
d->id_prev = it->prevId();
444
displayResult(r, EDB::Backward);
447
else if (d->reqType == TypeFindOldest)
449
QString str = ui_.searchField->text();
456
d->reqType = TypeFind;
458
EDBItemPtr ei = r.first();
460
getEDBHandle()->find(str, d->jid, ei->id(), EDB::Forward);
464
else if (d->reqType == TypeFind)
466
displayResult(r, EDB::Forward);
467
highlightBlocks(ui_.searchField->text());
479
void HistoryDlg::setButtons()
481
ui_.buttonPrevious->setEnabled(!d->id_prev.isEmpty());
482
ui_.buttonNext->setEnabled(!d->id_next.isEmpty());
483
ui_.buttonEarliest->setEnabled(!d->id_prev.isEmpty());
484
ui_.buttonLastest->setEnabled(!d->id_next.isEmpty());
487
void HistoryDlg::setButtons(bool act)
489
ui_.buttonPrevious->setEnabled(act);
490
ui_.buttonNext->setEnabled(act);
491
ui_.buttonEarliest->setEnabled(act);
492
ui_.buttonLastest->setEnabled(act);
495
void HistoryDlg::refresh()
497
ui_.calendar->setSelectedDate(QDate::currentDate());
498
ui_.searchField->clear();
502
void HistoryDlg::getLatest()
504
d->reqType = TypeLatest;
506
getEDBHandle()->getLatest(d->jid, 50);
509
void HistoryDlg::getEarliest()
511
d->reqType = TypeEarliest;
513
getEDBHandle()->getOldest(d->jid, 50);
516
void HistoryDlg::getPrevious()
518
d->reqType = TypePrevious;
519
ui_.buttonPrevious->setEnabled(false);
520
getEDBHandle()->get(d->jid, d->id_prev, EDB::Backward, 50);
523
void HistoryDlg::getNext()
525
d->reqType = TypeNext;
526
ui_.buttonNext->setEnabled(false);
527
getEDBHandle()->get(d->jid, d->id_next, EDB::Forward, 50);
530
void HistoryDlg::getDate()
532
const QDate date = ui_.calendar->selectedDate();
533
d->reqType = TypeDate;
535
QDateTime first (d->date);
536
QDateTime last = first.addDays(1);
538
getEDBHandle()->getByDate(d->jid, first, last);
541
void HistoryDlg::removedContact(PsiContact *pc)
543
QString jid = pc->jid().bare().toLower();
544
QString curJid = ui_.jidList->currentItem()->toolTip();
545
for(int i = 0; i < ui_.jidList->count(); i++) {
546
QListWidgetItem *it = ui_.jidList->item(i);
547
if(it && it->toolTip() == jid) {
548
ui_.jidList->removeItemWidget(it);
550
ui_.jidList->setCurrentRow(0);
551
openSelectedContact();
558
void HistoryDlg::displayResult(const EDBResult r, int direction, int max)
560
int i = (direction == EDB::Forward) ? r.count() - 1 : 0;
563
while (i >= 0 && i <= r.count() - 1 && (max == -1 ? true : at < max))
565
EDBItemPtr item = r.value(i);
566
PsiEvent* e = item->event();
567
UserListItem *u = d->pa->findFirstRelevant(e->from().full());
569
QString from = JIDUtil::nickOrJid(u->name(), u->jid().full());
570
if (e->type() == PsiEvent::Message)
572
MessageEvent *me = (MessageEvent *) e;
573
QString msg = me->message().body();
574
msg = TextUtil::linkify(TextUtil::plain2rich(msg));
576
if (PsiOptions::instance()->getOption("options.ui.emoticons.use-emoticons").toBool())
577
msg = TextUtil::emoticonify(msg);
578
if (PsiOptions::instance()->getOption("options.ui.chat.legacy-formatting").toBool())
579
msg = TextUtil::legacyFormat(msg);
581
if (me->originLocal())
582
msg = "<span style='color:red'>" + me->timeStamp().toString("[dd.MM.yyyy hh:mm:ss]")+" <"+ TextUtil::plain2rich(d->pa->nick()) +"> " + msg + "</span>";
584
msg = "<span style='color:blue'>" + me->timeStamp().toString("[dd.MM.yyyy hh:mm:ss]") + " <" + TextUtil::plain2rich(from) + "> " + msg + "</span>";
586
ui_.msgLog->appendText(msg);
592
i += (direction == EDB::Forward) ? -1 : +1;
595
ui_.msgLog->verticalScrollBar()->setValue(ui_.msgLog->verticalScrollBar()->maximum());
598
UserListItem* HistoryDlg::currentUserListItem()
601
QListWidgetItem *i = ui_.jidList->currentItem();
605
u = d->pa->findFirstRelevant(i->toolTip());
609
void HistoryDlg::startRequest()
611
if(!ui_.busy->isActive()) {
617
void HistoryDlg::stopRequest()
619
if(ui_.busy->isActive()) {
625
EDBHandle* HistoryDlg::getEDBHandle()
627
EDBHandle* h = new EDBHandle(d->pa->edb());
628
connect(h, SIGNAL(finished()), SLOT(edb_finished()));