~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to src/historydlg.cpp

  • Committer: Package Import Robot
  • Author(s): Jan Niehusmann
  • Date: 2014-07-01 21:49:34 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20140701214934-gt4dkgm94byi4vnn
Tags: 0.15-1
* New upstream version
* set debhelper compat level to 9
* set Standards-Version to 3.9.5 (no further changes)
* add lintian override regarding license-problem-non-free-RFC
* use qconf to regenerate configure script
* implement hardening using buildflags instead of hardening-wrapper

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * historydlg.cpp - a dialog to show event history
3
 
 * Copyright (C) 2001, 2002  Justin Karneges
 
2
 * historydlg.cpp
 
3
 * Copyright (C) 2001-2010  Justin Karneges, Michail Pishchagin,
 
4
 * Piotr Okonski, Evgeny Khryukin
4
5
 *
5
6
 * This program is free software; you can redistribute it and/or
6
7
 * modify it under the terms of the GNU General Public License
14
15
 *
15
16
 * You should have received a copy of the GNU General Public License
16
17
 * along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19
 *
19
20
 */
20
21
 
 
22
#include <QMessageBox>
 
23
#include <QScrollBar>
 
24
#include <QMenu>
 
25
#include <QProgressDialog>
 
26
 
21
27
#include "historydlg.h"
22
 
 
23
 
#include <q3popupmenu.h>
24
 
#include <q3header.h>
25
 
#include <qlayout.h>
26
 
#include <qlabel.h>
27
 
#include <qlineedit.h>
28
 
#include <qpushbutton.h>
29
 
#include <QFileDialog>
30
 
#include <Q3SimpleRichText>
31
 
#include <qmessagebox.h>
32
 
#include <QFrame>
33
 
#include <qapplication.h>
34
 
#include <qclipboard.h>
35
 
#include <QTextStream>
36
 
#include <QCloseEvent>
37
 
#include <QKeyEvent>
38
 
#include <QHBoxLayout>
39
 
#include <QVBoxLayout>
40
 
#include <QResizeEvent>
41
28
#include "psiaccount.h"
42
 
#include "psievent.h"
43
 
#include "busywidget.h"
44
 
#include "applicationinfo.h"
45
 
#include "common.h"
46
 
#include "eventdb.h"
 
29
#include "psicon.h"
 
30
#include "psicontact.h"
47
31
#include "psiiconset.h"
 
32
#include "psioptions.h"
 
33
#include "coloropt.h"
48
34
#include "textutil.h"
49
35
#include "jidutil.h"
 
36
#include "fileutil.h"
50
37
#include "userlist.h"
51
 
#include "psioptions.h"
52
 
#include "fileutil.h"
 
38
#include "common.h"
 
39
 
 
40
static const QString geometryOption = "options.ui.history.size";
53
41
 
54
42
static QString getNext(QString *str)
55
43
{
106
94
        return lines;
107
95
}
108
96
 
109
 
//----------------------------------------------------------------------------
110
 
// HistoryView
111
 
//----------------------------------------------------------------------------
 
97
 
112
98
class HistoryDlg::Private
113
99
{
114
100
public:
115
 
        Private() {}
116
 
 
117
101
        Jid jid;
118
102
        PsiAccount *pa;
119
 
        HistoryView *lv;
120
 
        //BusyWidget *busy;
121
 
        QPushButton *pb_prev, *pb_next, *pb_refresh, *pb_find;
122
 
        QLineEdit *le_find;
123
 
 
 
103
        PsiCon *psi;
124
104
        QString id_prev, id_begin, id_end, id_next;
125
 
        int reqtype;
 
105
        HistoryDlg::RequestType reqType;
126
106
        QString findStr;
127
 
 
128
 
        EDBHandle *h, *exp;
 
107
        QDate date;
129
108
};
130
109
 
131
110
HistoryDlg::HistoryDlg(const Jid &jid, PsiAccount *pa)
 
111
        : AdvancedWidget<QDialog>(0, Qt::Window)
132
112
{
 
113
        ui_.setupUi(this);
133
114
        setAttribute(Qt::WA_DeleteOnClose);
134
 
        if ( PsiOptions::instance()->getOption("options.ui.mac.use-brushed-metal-windows").toBool() )
135
 
                setAttribute(Qt::WA_MacMetalStyle);
 
115
        setModal(false);
136
116
        d = new Private;
 
117
        d->reqType = TypeNone;
137
118
        d->pa = pa;
 
119
        d->psi = pa->psi();
138
120
        d->jid = jid;
139
121
        d->pa->dialogRegister(this, d->jid);
140
 
        d->exp = 0;
141
122
 
142
 
        setWindowTitle(d->jid.full());
143
123
#ifndef Q_WS_MAC
144
124
        setWindowIcon(IconsetFactory::icon("psi/history").icon());
145
125
#endif
146
 
 
147
 
        d->h = new EDBHandle(d->pa->edb());
148
 
        connect(d->h, SIGNAL(finished()), SLOT(edb_finished()));
149
 
 
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);
158
 
 
159
 
        QHBoxLayout *hb1 = new QHBoxLayout;
160
 
        vb1->addLayout(hb1);
161
 
 
162
 
        QVBoxLayout *vb2 = new QVBoxLayout;
163
 
        hb1->addLayout(vb2);
164
 
 
165
 
        QHBoxLayout *hb2 = new QHBoxLayout;
166
 
        vb2->addLayout(hb2);
167
 
 
168
 
        //d->busy = new BusyWidget(this);
169
 
        //hb1->addWidget(d->busy);
170
 
 
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);
175
 
 
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);
180
 
 
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);
185
 
 
186
 
        QHBoxLayout *hb3 = new QHBoxLayout;
187
 
        vb2->addLayout(hb3);
188
 
 
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);
197
 
 
198
 
        QFrame *sep;
199
 
        sep = new QFrame(this);
200
 
        sep->setFrameShape(QFrame::VLine);
201
 
        hb1->addWidget(sep);
202
 
 
203
 
        QVBoxLayout *vb3 = new QVBoxLayout;
204
 
        hb1->addLayout(vb3);
205
 
 
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);
212
 
 
213
 
        sep = new QFrame(this);
214
 
        sep->setFrameShape(QFrame::VLine);
215
 
        hb1->addWidget(sep);
216
 
 
217
 
        hb1->addStretch(1);
218
 
 
219
 
        QVBoxLayout *vb4 = new QVBoxLayout;
220
 
        hb1->addLayout(vb4);
221
 
        vb4->addStretch(1);
222
 
 
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);
227
 
 
228
 
        resize(520,320);
229
 
 
230
 
        X11WM_CLASS("history");
231
 
 
232
 
        d->le_find->setFocus();
233
 
 
234
 
        setButtons();
235
 
        doLatest();
 
126
        ui_.tb_find->setIcon(IconsetFactory::icon("psi/search").icon());
 
127
 
 
128
        ui_.msgLog->setFont(fontForOption("options.ui.look.font.chat"));
 
129
        ui_.jidList->setFont(fontForOption("options.ui.look.font.contactlist"));
 
130
 
 
131
        ui_.calendar->setFirstDayOfWeek(firstDayOfWeekFromLocale());
 
132
 
 
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()));
 
144
 
 
145
        connect(d->pa, SIGNAL(removedContact(PsiContact*)), SLOT(removedContact(PsiContact*)));
 
146
 
 
147
        ui_.jidList->installEventFilter(this);
 
148
 
 
149
        listAccounts();
 
150
        loadContacts();
 
151
 
 
152
        setGeometryOptionPath(geometryOption);
 
153
 
 
154
        ui_.jidList->setFocus();
236
155
}
237
156
 
238
157
HistoryDlg::~HistoryDlg()
239
158
{
240
 
        delete d->exp;
241
 
        d->pa->dialogUnregister(this);
242
159
        delete d;
243
160
}
244
161
 
245
 
void HistoryDlg::keyPressEvent(QKeyEvent *e)
246
 
{
247
 
        if(e->key() == Qt::Key_Escape)
248
 
                close();
249
 
        else {
250
 
                e->ignore();
251
 
        }
252
 
}
253
 
 
254
 
void HistoryDlg::closeEvent(QCloseEvent *e)
255
 
{
256
 
        if(d->exp)
257
 
                return;
258
 
 
259
 
        e->accept();
260
 
}
261
 
 
262
 
void HistoryDlg::show()
263
 
{
264
 
        QWidget::show();
265
 
        d->lv->doResize();
266
 
}
267
 
 
268
 
void HistoryDlg::le_textChanged(const QString &s)
269
 
{
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);
274
 
}
275
 
 
276
 
void HistoryDlg::setButtons()
277
 
{
278
 
        d->pb_prev->setEnabled(!d->id_prev.isEmpty());
279
 
        d->pb_next->setEnabled(!d->id_next.isEmpty());
280
 
}
281
 
 
282
 
void HistoryDlg::doLatest()
283
 
{
284
 
        loadPage(0);
285
 
}
286
 
 
287
 
void HistoryDlg::doPrev()
288
 
{
289
 
        loadPage(1);
290
 
}
291
 
 
292
 
void HistoryDlg::doNext()
293
 
{
294
 
        loadPage(2);
295
 
}
296
 
 
297
 
void HistoryDlg::doSave()
298
 
{
299
 
        UserListItem *u = d->pa->findFirstRelevant(d->jid);
 
162
bool HistoryDlg::eventFilter(QObject *obj, QEvent *e)
 
163
{
 
164
        if(obj == ui_.jidList && e->type() == QEvent::ContextMenu) {
 
165
                e->accept();
 
166
                QTimer::singleShot(0, this, SLOT(doMenu()));
 
167
                return true;
 
168
        }
 
169
 
 
170
        return QDialog::eventFilter(obj, e);
 
171
}
 
172
 
 
173
QFont HistoryDlg::fontForOption(const QString &option)
 
174
{
 
175
        QFont font;
 
176
        font.fromString(PsiOptions::instance()->getOption(option).toString());
 
177
        return font;
 
178
}
 
179
 
 
180
void HistoryDlg::changeAccount(const QString /*accountName*/)
 
181
{
 
182
        ui_.msgLog->clear();
 
183
        setButtons(false);
 
184
        d->jid = QString();
 
185
        d->pa = d->psi->contactList()->getAccountByJid(ui_.accountsBox->itemData(ui_.accountsBox->currentIndex()).toString());
 
186
        loadContacts();
 
187
        ui_.jidList->setCurrentRow(0);
 
188
        openSelectedContact();
 
189
}
 
190
 
 
191
void HistoryDlg::listAccounts()
 
192
{
 
193
        if (d->psi)
 
194
        {
 
195
                foreach (PsiAccount* account, d->psi->contactList()->enabledAccounts())
 
196
                        ui_.accountsBox->addItem(IconsetFactory::icon("psi/account").icon(), account->nameWithJid(), QVariant(account->jid().full()));
 
197
        }
 
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)));
 
202
}
 
203
 
 
204
void HistoryDlg::loadContacts()
 
205
{
 
206
        jids_.clear();
 
207
        ui_.jidList->clear();
 
208
        ui_.msgLog->clear();
 
209
        foreach (PsiContact* contact, d->pa->contactList())
 
210
        {
 
211
                if(contact->isPrivate()
 
212
                || jids_.contains(contact->jid().bare()))
 
213
                        continue;
 
214
 
 
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());
 
221
        }
 
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());
 
230
        }
 
231
 
 
232
        ui_.jidList->sortItems();
 
233
        //set contact in jidList to selected jid
 
234
        for (int i = 0; i < ui_.jidList->count(); i++)
 
235
        {
 
236
                if (ui_.jidList->item(i)->toolTip() == d->jid.bare().toLower())
 
237
                        ui_.jidList->setCurrentRow(i);  //triggers openSelectedContact()
 
238
        }
 
239
}
 
240
 
 
241
void HistoryDlg::openSelectedContact()
 
242
{
 
243
        ui_.msgLog->clear();
 
244
        UserListItem *u = currentUserListItem();
 
245
        if (!u)
 
246
                return;
 
247
 
 
248
        setWindowTitle(u->name() + " (" + u->jid().full() + ")");
 
249
        d->jid = u->jid();
 
250
        getLatest();
 
251
}
 
252
 
 
253
void HistoryDlg::highlightBlocks(const QString text)
 
254
{
 
255
        QTextCursor cur = ui_.msgLog->textCursor();
 
256
        cur.clearSelection();
 
257
        cur.movePosition(QTextCursor::Start);
 
258
        ui_.msgLog->setTextCursor(cur); 
 
259
 
 
260
        if (text.isEmpty()) {
 
261
                getLatest();
 
262
                return;
 
263
        }
 
264
 
 
265
        QList<QTextEdit::ExtraSelection> extras;
 
266
        QTextEdit::ExtraSelection highlight;
 
267
        highlight.format.setBackground(Qt::yellow);
 
268
        highlight.cursor = ui_.msgLog->textCursor();    
 
269
 
 
270
        bool found = ui_.msgLog->find(text);
 
271
        while (found)
 
272
        {
 
273
                highlight.cursor = ui_.msgLog->textCursor();
 
274
                extras << highlight;
 
275
                found = ui_.msgLog->find(text);
 
276
        }
 
277
 
 
278
        ui_.msgLog->setExtraSelections(extras);
 
279
}
 
280
 
 
281
void HistoryDlg::findMessages()
 
282
{
 
283
        //get the oldest event as a starting point
 
284
        startRequest();
 
285
        d->reqType = TypeFindOldest;
 
286
        getEDBHandle()->getOldest(d->jid, 1);
 
287
}
 
288
 
 
289
void HistoryDlg::removeHistory()
 
290
{
 
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();
 
297
        }
 
298
}
 
299
 
 
300
void HistoryDlg::openChat()
 
301
{
 
302
        UserListItem *u = currentUserListItem();
 
303
        if(u) {
 
304
                d->pa->actionOpenChat2(u->jid().bare());
 
305
        }
 
306
}
 
307
 
 
308
void HistoryDlg::exportHistory()
 
309
{
 
310
        UserListItem *u = currentUserListItem();
 
311
        if(!u)
 
312
                return;
300
313
        QString them = JIDUtil::nickOrJid(u->name(), u->jid().full());
301
314
        QString s = JIDUtil::encode(them).toLower();
302
 
 
303
 
        QString str = FileUtil::getSaveFileName(this,
304
 
                                                tr("Export message history"),
305
 
                                                s + ".txt",
306
 
                                                tr("Text files (*.txt);;All files (*.*)"));
307
 
 
308
 
        if (!str.isEmpty()) {
309
 
                exportHistory(str);
310
 
        }
311
 
}
312
 
 
313
 
void HistoryDlg::doErase()
314
 
{
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);
316
 
        if (x == 0) {
317
 
                d->h->erase(d->jid);
318
 
        }
319
 
}
320
 
 
321
 
void HistoryDlg::loadPage(int type)
322
 
{
323
 
        d->reqtype = type;
324
 
        if(type == 0) {
325
 
                d->pb_refresh->setEnabled(false);
326
 
                d->h->getLatest(d->jid, 50);
327
 
                //printf("EDB: requesting latest 50 events\n");
328
 
        }
329
 
        else if(type == 1) {
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());
333
 
        }
334
 
        else if(type == 2) {
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());
338
 
        }
339
 
 
340
 
        //d->busy->start();
341
 
}
342
 
 
343
 
void HistoryDlg::displayResult(const EDBResult *r, int direction, int max)
344
 
{
345
 
        //d->lv->setUpdatesEnabled(false);
346
 
        d->lv->clear();
347
 
        int i = (direction == EDB::Forward) ? r->count()-1 : 0;
348
 
        int at = 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());
353
 
                ++at;
354
 
                i += (direction == EDB::Forward) ? -1 : +1;
355
 
        }
356
 
        //d->lv->setUpdatesEnabled(true);
357
 
        //d->lv->repaint(true);
358
 
}
359
 
 
360
 
void HistoryDlg::edb_finished()
361
 
{
362
 
        const EDBResult *r = d->h->result();
363
 
        if(d->h->lastRequestType() == EDBHandle::Read && r) {
364
 
                //printf("EDB: retrieved %d events:\n", r->count());
365
 
                if(r->count() > 0) {
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
373
 
                                it = r->last();
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());
378
 
                        }
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
386
 
                                it = r->first();
387
 
                                d->id_begin = it->id();
388
 
                                d->id_prev = it->prevId();
389
 
                                displayResult(r, EDB::Forward);
390
 
                        }
391
 
                        else if(d->reqtype == 3) {
392
 
                                // should only be one entry
393
 
                                EDBItem *ei = r->first();
394
 
                                d->reqtype = 1;
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());
397
 
                                return;
398
 
                        }
399
 
                }
400
 
                else {
401
 
                        if(d->reqtype == 3) {
402
 
                                QMessageBox::information(this, tr("Find"), tr("Search string '%1' not found.").arg(d->findStr));
403
 
                                return;
404
 
                        }
405
 
                }
406
 
        }
407
 
        else if (d->h->lastRequestType() == EDBHandle::Erase) {
408
 
                if (d->h->writeSuccess()) {
409
 
                        d->lv->clear();
410
 
                        d->id_prev = "";
411
 
                        d->id_begin = "";
412
 
                        d->id_end = "";
413
 
                        d->id_next = "";
414
 
                }
415
 
                else {
416
 
                        QMessageBox::critical(this, tr("Error"), tr("Unable to delete history file."));
417
 
                }
418
 
        }
419
 
        else {
420
 
                //printf("EDB: error\n");
421
 
        }
422
 
 
423
 
        if(d->lv->firstChild())
424
 
                d->lv->setSelected(d->lv->firstChild(), true);
425
 
 
426
 
        //d->busy->stop();
427
 
        d->pb_refresh->setEnabled(true);
428
 
        setButtons();
429
 
}
430
 
 
431
 
void HistoryDlg::actionOpenEvent(PsiEvent *e)
432
 
{
433
 
        openEvent(e);
434
 
}
435
 
 
436
 
void HistoryDlg::doFind()
437
 
{
438
 
        QString str = d->le_find->text();
439
 
        if(str.isEmpty())
440
 
                return;
441
 
 
442
 
        if(d->lv->childCount() < 1)
443
 
                return;
444
 
 
445
 
        HistoryViewItem *i = (HistoryViewItem *)d->lv->selectedItem();
446
 
        if(!i)
447
 
                i = (HistoryViewItem *)d->lv->firstChild();
448
 
        QString id = i->eventId;
449
 
        if(id.isEmpty()) {
450
 
                QMessageBox::information(this, tr("Find"), tr("Already at beginning of message history."));
451
 
                return;
452
 
        }
453
 
 
454
 
        //printf("searching for: [%s], starting at id=[%s]\n", str.latin1(), id.latin1());
455
 
        d->reqtype = 3;
456
 
        d->findStr = str;
457
 
        d->h->find(str, d->jid, id, EDB::Backward);
458
 
}
459
 
 
460
 
void HistoryDlg::exportHistory(const QString &fname)
461
 
{
 
315
        QString fname = FileUtil::getSaveFileName(this,
 
316
                                                  tr("Export message history"),
 
317
                                                  s + ".txt",
 
318
                                                  tr("Text files (*.txt);;All files (*.*)"));
 
319
        if(fname.isEmpty())
 
320
                return;
 
321
 
462
322
        QFile f(fname);
463
323
        if(!f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
464
324
                QMessageBox::information(this, tr("Error"), tr("Error writing to file."));
467
327
        QTextStream stream(&f);
468
328
 
469
329
        QString us = d->pa->nick();
470
 
        UserListItem *u = d->pa->findFirstRelevant(d->jid);
471
 
        QString them = JIDUtil::nickOrJid(u->name(), u->jid().full());
472
330
 
473
 
        d->exp = new EDBHandle(d->pa->edb());
 
331
        EDBHandle* h;
474
332
        QString id;
 
333
        startRequest();
475
334
        while(1) {
 
335
                h = new EDBHandle(d->pa->edb());
476
336
                if(id.isEmpty()) {
477
 
                        d->exp->getOldest(d->jid, 1000);
478
 
                } else {
479
 
                        d->exp->get(d->jid, id, EDB::Forward, 1000);
480
 
                }
481
 
                while(d->exp->busy()) {
 
337
                        h->getOldest(d->jid, 1000);
 
338
                }
 
339
                else {
 
340
                        h->get(d->jid, id, EDB::Forward, 1000);
 
341
                }
 
342
                while(h->busy()) {
482
343
                        qApp->processEvents();
483
344
                }
484
345
 
485
 
                const EDBResult *r = d->exp->result();
486
 
                if(!r) {
487
 
                        break;
488
 
                }
489
 
                if(r->count() <= 0) {
490
 
                        break;
491
 
                }
 
346
                const EDBResult r = h->result();
 
347
                int cnt = r.count();
492
348
 
493
349
                // events are in forward order
494
 
                for(int i = 0; i < r->count(); ++i) {
495
 
                        EDBItem* item = r->value(i);
 
350
                for(int i = 0; i < cnt; ++i) {
 
351
                        EDBItemPtr item = r.value(i);
496
352
                        id = item->nextId();
497
353
                        PsiEvent *e = item->event();
498
354
                        QString txt;
499
355
 
500
 
                        QDateTime dt = e->timeStamp();
501
 
                        QString ts;
502
 
                        //ts.sprintf("%04d/%02d/%02d %02d:%02d:%02d", dt.date().year(), dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second());
503
 
                        ts = dt.toString(Qt::LocalDate);
 
356
                        QString ts = e->timeStamp().toString(Qt::LocalDate);
504
357
 
505
358
                        QString nick;
506
359
                        if(e->originLocal()) {
507
360
                                nick = us;
508
 
                        } else {
 
361
                        }
 
362
                        else {
509
363
                                nick = them;
510
364
                        }
511
365
 
512
 
                        QString heading = QString("(%1) ").arg(ts) + nick + ": ";
513
366
                        if(e->type() == PsiEvent::Message) {
514
367
                                MessageEvent *me = (MessageEvent *)e;
515
 
                                stream << heading << endl;
 
368
                                stream << QString("[%1] <%2>: ").arg(ts, nick)/* << endl*/;
516
369
 
517
370
                                QStringList lines = me->message().body().split('\n', QString::KeepEmptyParts);
518
371
                                foreach(const QString& str, lines) {
519
372
                                        QStringList sub = wrapString(str, 72);
520
373
                                        foreach(const QString& str2, sub) {
521
 
                                                txt += QString("    ") + str2 + '\n';
 
374
                                                txt += str2 + "\n" + QString("    ");
522
375
                                        }
523
376
                                }
524
377
                        }
528
381
 
529
382
                        stream << txt << endl;
530
383
                }
 
384
                delete h;
531
385
 
532
386
                // done!
533
 
                if(id.isEmpty()) {
 
387
                if(cnt == 0 || id.isEmpty()) {
534
388
                        break;
535
389
                }
536
390
        }
537
 
        delete d->exp;
538
 
        d->exp = 0;
539
391
        f.close();
540
 
}
541
 
 
542
 
//----------------------------------------------------------------------------
543
 
// HistoryView
544
 
//----------------------------------------------------------------------------
545
 
HistoryView::HistoryView(QWidget *parent, const char *name)
546
 
:Q3ListView(parent, name)
547
 
{
548
 
        at_id = 0;
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)));
551
 
 
552
 
        setAllColumnsShowFocus(true);
553
 
        addColumn(tr("Type"));
554
 
        addColumn(tr("Origin"));
555
 
        addColumn(tr("Date"));
556
 
        addColumn(tr("Text"));
557
 
        setSorting(2);
558
 
        setResizeMode(Q3ListView::LastColumn);
559
 
        setShowToolTips(false);
560
 
        header()->setClickEnabled(false);
561
 
        header()->setMovingEnabled(false);
562
 
        header()->setResizeEnabled(false);
563
 
}
564
 
 
565
 
void HistoryView::resizeEvent(QResizeEvent *e)
566
 
{
567
 
        Q3ListView::resizeEvent(e);
568
 
 
569
 
        if(e->oldSize().width() != e->size().width())
570
 
                doResize();
571
 
}
572
 
 
573
 
void HistoryView::keyPressEvent(QKeyEvent *e)
574
 
{
575
 
        if(e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)
576
 
                doOpenEvent();
577
 
        else
578
 
                Q3ListView::keyPressEvent(e);
579
 
}
580
 
 
581
 
void HistoryView::doResize()
582
 
{
583
 
        Q3ListViewItemIterator it(this);
584
 
        HistoryViewItem *item;
585
 
        for(; it.current() ; ++it) {
586
 
                item = (HistoryViewItem *)it.current();
587
 
                item->setup();
588
 
        }
589
 
}
590
 
 
591
 
void HistoryView::addEvent(PsiEvent *e, const QString &eid)
592
 
{
593
 
        new HistoryViewItem(e, eid, at_id++, this);
594
 
}
595
 
 
596
 
void HistoryView::doOpenEvent()
597
 
{
598
 
        HistoryViewItem *i = (HistoryViewItem *)selectedItem();
599
 
        if(!i)
600
 
                return;
601
 
        aOpenEvent(i->e);
602
 
}
603
 
 
604
 
void HistoryView::qlv_doubleclick(Q3ListViewItem *xi)
605
 
{
606
 
        HistoryViewItem *i = (HistoryViewItem *)xi;
607
 
 
608
 
        setSelected(i, true);
609
 
        doOpenEvent();
610
 
}
611
 
 
612
 
void HistoryView::qlv_contextPopup(Q3ListViewItem *ix, const QPoint &pos, int)
613
 
{
614
 
        HistoryViewItem *i = (HistoryViewItem *)ix;
615
 
        if(!i)
616
 
                return;
617
 
 
618
 
        Q3PopupMenu popup;
619
 
        popup.insertItem(tr("Open"), 1);
620
 
        popup.insertSeparator();
621
 
        popup.insertItem(tr("Copy"), 2);
622
 
 
623
 
        if(i->e->type() != PsiEvent::Message)
624
 
                popup.setItemEnabled(2, false);
625
 
 
626
 
        int x = popup.exec(pos);
627
 
 
628
 
        if(x == 1)
629
 
                doOpenEvent();
630
 
        else if(x == 2) {
631
 
                HistoryViewItem *i = (HistoryViewItem *)selectedItem();
632
 
                if(!i)
633
 
                        return;
634
 
 
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);
639
 
        }
640
 
}
641
 
 
642
 
 
643
 
//----------------------------------------------------------------------------
644
 
// HistoryViewItem
645
 
//----------------------------------------------------------------------------
646
 
HistoryViewItem::HistoryViewItem(PsiEvent *_e, const QString &eid, int xid, Q3ListView *parent)
647
 
:Q3ListViewItem(parent)
648
 
{
649
 
        rt = 0;
650
 
        id = xid;
651
 
        eventId = eid;
652
 
 
653
 
        if(_e->type() == PsiEvent::Message) {
654
 
                MessageEvent *me = (MessageEvent *)_e;
655
 
                e = new MessageEvent(*me);
656
 
        }
657
 
        else if(_e->type() == PsiEvent::Auth) {
658
 
                AuthEvent *ae = (AuthEvent *)_e;
659
 
                e = new AuthEvent(*ae);
660
 
        }
661
 
 
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());
667
 
 
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());
672
 
                else if(a)
673
 
                        setPixmap(0, a->impix());
674
 
        }
675
 
        else if(e->type() == PsiEvent::Auth) {
676
 
                AuthEvent *ae = (AuthEvent *)e;
677
 
                text = ae->authType();
678
 
                if (a)
679
 
                        setPixmap(0, a->impix());
680
 
        }
681
 
 
682
 
        if(e->originLocal())
683
 
                setText(1, HistoryView::tr("To"));
684
 
        else
685
 
                setText(1, HistoryView::tr("From"));
686
 
 
687
 
        QString date;
688
 
        const QDateTime &ts = e->timeStamp();
689
 
        /*date.sprintf("%02d/%02d/%02d %02d:%02d:%02d",
690
 
                ts.date().month(),
691
 
                ts.date().day(),
692
 
                ts.date().year(),
693
 
                ts.time().hour(),
694
 
                ts.time().minute(),
695
 
                ts.time().second());*/
696
 
        date = ts.toString(Qt::LocalDate);
697
 
 
698
 
        setText(2, date);
699
 
 
700
 
        rt = new Q3SimpleRichText(text, listView()->font());
701
 
}
702
 
 
703
 
HistoryViewItem::~HistoryViewItem()
704
 
{
705
 
        delete rt;
706
 
        delete e;
707
 
}
708
 
 
709
 
// reimplemented from QListViewItem.  setup() and paintCell() are tricky stuff
710
 
void HistoryViewItem::setup()
711
 
{
712
 
        widthChanged();
713
 
 
714
 
        Q3ListView *lv = listView();
715
 
 
716
 
        if(rt) {
717
 
                int w = lv->columnWidth(3);
718
 
                rt->setWidth(w);
719
 
        }
720
 
 
721
 
        int y;
722
 
        //y = lv->fontMetrics().size(AlignVCenter, displayStr).height();
723
 
        if(!rt)
724
 
                y = 22;
725
 
        else
726
 
                y = rt->height();
727
 
 
728
 
        y += lv->itemMargin() * 2;
729
 
 
730
 
        // ensure an even number
731
 
        if(y & 1)
732
 
                ++y;
733
 
 
734
 
        setHeight(y);
735
 
}
736
 
 
737
 
void HistoryViewItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int alignment)
738
 
{
739
 
        QColorGroup mycg = cg;
740
 
        if(e->originLocal())
741
 
{
742
 
                mycg.setColor(QColorGroup::Text, PsiOptions::instance()->getOption("options.ui.look.colors.messages.sent").toString() );
743
 
}
744
 
        else
745
 
{
746
 
                mycg.setColor(QColorGroup::Text,PsiOptions::instance()->getOption("options.ui.look.colors.messages.received").toString() );
747
 
}
748
 
 
749
 
        if(column == 3) {
750
 
                QBrush br;
751
 
                if(isSelected()) {
752
 
                        mycg.setColor(QColorGroup::Text, mycg.highlightedText());
753
 
                        br = cg.brush(QColorGroup::Highlight);
754
 
                }
755
 
                else {
756
 
                        br = cg.brush(QColorGroup::Base);
757
 
                }
758
 
 
759
 
                int h = height();
760
 
                if(rt) {
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);
764
 
                }
765
 
        }
766
 
        else {
767
 
                alignment = Qt::AlignTop;
768
 
 
769
 
                Q3ListViewItem::paintCell(p, mycg, column, width, alignment);
770
 
        }
771
 
}
772
 
 
773
 
int HistoryViewItem::compare(Q3ListViewItem *xi, int, bool) const
774
 
{
775
 
        HistoryViewItem *i = (HistoryViewItem *)xi;
776
 
        return id - i->id;
777
 
}
778
 
 
779
 
int HistoryViewItem::rtti() const
780
 
{
781
 
        return 7105;
782
 
}
783
 
 
 
392
        stopRequest();
 
393
}
 
394
 
 
395
void HistoryDlg::doMenu()
 
396
{
 
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());
 
402
}
 
403
 
 
404
void HistoryDlg::edb_finished()
 
405
{
 
406
        setButtons(false);
 
407
        stopRequest();
 
408
 
 
409
        EDBHandle* h = qobject_cast<EDBHandle*>(sender());
 
410
        if(!h) {
 
411
                return;
 
412
        }
 
413
 
 
414
        const EDBResult r = h->result();
 
415
        if (h->lastRequestType() == EDBHandle::Read)
 
416
        {
 
417
                if (r.count() > 0)
 
418
                {
 
419
                        if (d->reqType == TypeLatest || d->reqType == TypePrevious)
 
420
                        {
 
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
 
427
                                it = r.last();
 
428
                                d->id_begin = it->id();
 
429
                                d->id_prev = it->prevId();
 
430
                                displayResult(r, EDB::Forward);
 
431
                                setButtons();
 
432
                        }
 
433
                        else if (d->reqType == TypeEarliest || d->reqType == TypeNext || d->reqType == TypeDate)
 
434
                        {
 
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
 
441
                                it = r.first();
 
442
                                d->id_begin = it->id();
 
443
                                d->id_prev = it->prevId();
 
444
                                displayResult(r, EDB::Backward);
 
445
                                setButtons();
 
446
                        }
 
447
                        else if (d->reqType == TypeFindOldest)
 
448
                        {
 
449
                                QString str = ui_.searchField->text();
 
450
                                if (str.isEmpty())
 
451
                                {
 
452
                                        getLatest();
 
453
                                }
 
454
                                else
 
455
                                {
 
456
                                        d->reqType = TypeFind;
 
457
                                        d->findStr = str;
 
458
                                        EDBItemPtr ei = r.first();
 
459
                                        startRequest();
 
460
                                        getEDBHandle()->find(str, d->jid, ei->id(), EDB::Forward);
 
461
                                        setButtons();
 
462
                                }
 
463
                        }
 
464
                        else if (d->reqType == TypeFind)
 
465
                        {
 
466
                                displayResult(r, EDB::Forward);
 
467
                                highlightBlocks(ui_.searchField->text());
 
468
                        }
 
469
 
 
470
                }
 
471
                else
 
472
                {
 
473
                        ui_.msgLog->clear();
 
474
                }
 
475
        }
 
476
        delete h;
 
477
}
 
478
 
 
479
void HistoryDlg::setButtons()
 
480
{
 
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());
 
485
}
 
486
 
 
487
void HistoryDlg::setButtons(bool act)
 
488
{
 
489
        ui_.buttonPrevious->setEnabled(act);
 
490
        ui_.buttonNext->setEnabled(act);
 
491
        ui_.buttonEarliest->setEnabled(act);
 
492
        ui_.buttonLastest->setEnabled(act);
 
493
}
 
494
 
 
495
void HistoryDlg::refresh()
 
496
{
 
497
        ui_.calendar->setSelectedDate(QDate::currentDate());
 
498
        ui_.searchField->clear();
 
499
        getLatest();
 
500
}
 
501
 
 
502
void HistoryDlg::getLatest()
 
503
{
 
504
        d->reqType = TypeLatest;
 
505
        startRequest();
 
506
        getEDBHandle()->getLatest(d->jid, 50);
 
507
}
 
508
 
 
509
void HistoryDlg::getEarliest()
 
510
{
 
511
        d->reqType = TypeEarliest;
 
512
        startRequest();
 
513
        getEDBHandle()->getOldest(d->jid, 50);
 
514
}
 
515
 
 
516
void HistoryDlg::getPrevious()
 
517
{
 
518
        d->reqType = TypePrevious;
 
519
        ui_.buttonPrevious->setEnabled(false);
 
520
        getEDBHandle()->get(d->jid, d->id_prev, EDB::Backward, 50);
 
521
}
 
522
 
 
523
void HistoryDlg::getNext()
 
524
{
 
525
        d->reqType = TypeNext;
 
526
        ui_.buttonNext->setEnabled(false);
 
527
        getEDBHandle()->get(d->jid, d->id_next, EDB::Forward, 50);
 
528
}
 
529
 
 
530
void HistoryDlg::getDate()
 
531
{
 
532
        const QDate date = ui_.calendar->selectedDate();
 
533
        d->reqType = TypeDate;
 
534
        d->date = date;
 
535
        QDateTime first (d->date);
 
536
        QDateTime last = first.addDays(1);
 
537
        startRequest();
 
538
        getEDBHandle()->getByDate(d->jid, first, last);
 
539
}
 
540
 
 
541
void HistoryDlg::removedContact(PsiContact *pc)
 
542
{
 
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);
 
549
                        if(jid == curJid) {
 
550
                                ui_.jidList->setCurrentRow(0);
 
551
                                openSelectedContact();
 
552
                        }
 
553
                        break;
 
554
                }
 
555
        }
 
556
}
 
557
 
 
558
void HistoryDlg::displayResult(const EDBResult r, int direction, int max)
 
559
{
 
560
        int i  = (direction == EDB::Forward) ? r.count() - 1 : 0;
 
561
        int at = 0;
 
562
        ui_.msgLog->clear();
 
563
        while (i >= 0 && i <= r.count() - 1 && (max == -1 ? true : at < max))
 
564
        {
 
565
                EDBItemPtr item = r.value(i);
 
566
                PsiEvent* e = item->event();
 
567
                UserListItem *u = d->pa->findFirstRelevant(e->from().full());
 
568
                if(u) {
 
569
                        QString from = JIDUtil::nickOrJid(u->name(), u->jid().full());
 
570
                        if (e->type() == PsiEvent::Message)
 
571
                        {
 
572
                                MessageEvent *me = (MessageEvent *) e;
 
573
                                QString msg = me->message().body();
 
574
                                msg = TextUtil::linkify(TextUtil::plain2rich(msg));
 
575
 
 
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);
 
580
 
 
581
                                if (me->originLocal())
 
582
                                        msg = "<span style='color:red'>" + me->timeStamp().toString("[dd.MM.yyyy hh:mm:ss]")+" &lt;"+ TextUtil::plain2rich(d->pa->nick()) +"&gt; " + msg + "</span>";
 
583
                                else
 
584
                                        msg = "<span style='color:blue'>" + me->timeStamp().toString("[dd.MM.yyyy hh:mm:ss]") + " &lt;" +  TextUtil::plain2rich(from) + "&gt; " + msg + "</span>";
 
585
 
 
586
                                ui_.msgLog->appendText(msg);
 
587
 
 
588
                        }
 
589
                }
 
590
 
 
591
                ++at;
 
592
                i += (direction == EDB::Forward) ? -1 : +1;
 
593
        }
 
594
 
 
595
        ui_.msgLog->verticalScrollBar()->setValue(ui_.msgLog->verticalScrollBar()->maximum());
 
596
}
 
597
 
 
598
UserListItem* HistoryDlg::currentUserListItem()
 
599
{
 
600
        UserListItem* u = 0;
 
601
        QListWidgetItem *i = ui_.jidList->currentItem();
 
602
        if(!i)
 
603
                return u;
 
604
 
 
605
        u = d->pa->findFirstRelevant(i->toolTip());
 
606
        return u;
 
607
}
 
608
 
 
609
void HistoryDlg::startRequest()
 
610
{
 
611
        if(!ui_.busy->isActive()) {
 
612
                ui_.busy->start();
 
613
        }
 
614
        setEnabled(false);
 
615
}
 
616
 
 
617
void HistoryDlg::stopRequest()
 
618
{
 
619
        if(ui_.busy->isActive()) {
 
620
                ui_.busy->stop();               
 
621
        }
 
622
        setEnabled(true);
 
623
}
 
624
 
 
625
EDBHandle* HistoryDlg::getEDBHandle()
 
626
{
 
627
        EDBHandle* h = new EDBHandle(d->pa->edb());
 
628
        connect(h, SIGNAL(finished()), SLOT(edb_finished()));
 
629
        return h;
 
630
}