~ubuntu-branches/ubuntu/jaunty/psi/jaunty

« back to all changes in this revision

Viewing changes to src/filetransdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include"filetransdlg.h"
2
 
 
3
 
#include<qlabel.h>
4
 
#include<qlineedit.h>
5
 
#include<qpushbutton.h>
6
 
#include<qtimer.h>
7
 
#include<qfiledialog.h>
8
 
#include<qfile.h>
9
 
#include<qprogressbar.h>
10
 
#include<qdir.h>
11
 
#include<qlistview.h>
12
 
#include<qlayout.h>
13
 
#include<qhbox.h>
14
 
#include<qdatetime.h>
15
 
#include<qpainter.h>
16
 
#include<qheader.h>
17
 
#include<qtooltip.h>
18
 
#include<qpopupmenu.h>
19
 
#include<qtextedit.h>
20
 
#include"psicon.h"
21
 
#include"psiaccount.h"
22
 
#include"userlist.h"
23
 
#include"common.h"
24
 
#include"iconwidget.h"
25
 
#include"busywidget.h"
26
 
#include"filetransfer.h"
27
 
#include"profiles.h"
28
 
#include"psiiconset.h"
29
 
#include"msgmle.h"
30
 
 
31
 
#if QT_VERSION >= 0x030200
 
1
#include "filetransdlg.h"
 
2
 
 
3
#include <QFileDialog>
 
4
#include <qlabel.h>
 
5
#include <qlineedit.h>
 
6
#include <QMessageBox>
 
7
#include <qpushbutton.h>
 
8
#include <qtimer.h>
 
9
#include <qfile.h>
 
10
#include <q3progressbar.h>
 
11
#include <qdir.h>
 
12
#include <q3listview.h>
 
13
#include <qlayout.h>
 
14
#include <q3hbox.h>
 
15
#include <qdatetime.h>
 
16
#include <qpainter.h>
 
17
#include <q3header.h>
 
18
#include <q3popupmenu.h>
 
19
#include <QResizeEvent>
 
20
#include <QKeyEvent>
 
21
#include <QVBoxLayout>
 
22
#include <Q3PtrList>
 
23
#include <QHBoxLayout>
 
24
#include <QPixmap>
 
25
 
 
26
#include "psicon.h"
 
27
#include "psiaccount.h"
 
28
#include "userlist.h"
 
29
#include "common.h"
 
30
#include "iconwidget.h"
 
31
#include "s5b.h"
 
32
#include "busywidget.h"
 
33
#include "filetransfer.h"
 
34
#include "accountscombobox.h"
 
35
#include "profiles.h"
 
36
#include "psiiconset.h"
 
37
#include "msgmle.h"
 
38
#include "jidutil.h"
 
39
#include "psitooltip.h"
 
40
#include "psicontactlist.h"
 
41
#include "accountlabel.h"
 
42
 
32
43
typedef Q_UINT64 LARGE_TYPE;
33
 
#else
34
 
typedef Q_UINT32 LARGE_TYPE;
35
 
#endif
36
44
 
37
45
#define CSMAX (sizeof(LARGE_TYPE)*8)
38
46
#define CSMIN 16
39
 
static int calcShift(Q_LLONG big)
 
47
static int calcShift(qlonglong big)
40
48
{
41
49
        LARGE_TYPE val = 1;
42
50
        val <<= CSMAX - 1;
48
56
        return 0;
49
57
}
50
58
 
51
 
static int calcComplement(Q_LLONG big, int shift)
 
59
static int calcComplement(qlonglong big, int shift)
52
60
{
53
61
        int block = 1 << shift;
54
 
        Q_LLONG rem = big % block;
 
62
        qlonglong rem = big % block;
55
63
        if(rem == 0)
56
64
                return 0;
57
65
        else
58
66
                return (block - (int)rem);
59
67
}
60
68
 
61
 
static int calcTotalSteps(Q_LLONG big, int shift)
 
69
static int calcTotalSteps(qlonglong big, int shift)
62
70
{
63
71
        if(big < 1)
64
72
                return 0;
65
73
        return ((big - 1) >> shift) + 1;
66
74
}
67
75
 
68
 
static int calcProgressStep(Q_LLONG big, int complement, int shift)
 
76
static int calcProgressStep(qlonglong big, int complement, int shift)
69
77
{
70
78
        return ((big + complement) >> shift);
71
79
}
100
108
//#ifdef Q_OS_WIN
101
109
        QString badchars = "\\/|?*:\"<>";
102
110
        QString str;
103
 
        for(uint n = 0; n < s.length(); ++n) {
 
111
        for(int n = 0; n < s.length(); ++n) {
104
112
                bool found = false;
105
 
                for(uint b = 0; b < badchars.length(); ++b) {
 
113
                for(int b = 0; b < badchars.length(); ++b) {
106
114
                        if(s.at(n) == badchars.at(b)) {
107
115
                                found = true;
108
116
                                break;
130
138
        S5BConnection *c;
131
139
        Jid peer;
132
140
        QString fileName, saveName;
133
 
        Q_LLONG fileSize, sent, offset, length;
 
141
        qlonglong fileSize, sent, offset, length;
134
142
        QString desc;
135
143
        bool sending;
136
144
        QFile f;
196
204
                d->ft->setProxy(proxy);
197
205
        mapSignals();
198
206
 
199
 
        d->f.setName(fname);
 
207
        d->f.setFileName(fname);
200
208
        d->ft->sendFile(d->peer, d->fileName, d->fileSize, desc);
201
209
}
202
210
 
220
228
        return d->fileName;
221
229
}
222
230
 
223
 
Q_LLONG FileTransferHandler::fileSize() const
 
231
qlonglong FileTransferHandler::fileSize() const
224
232
{
225
233
        return d->fileSize;
226
234
}
230
238
        return d->desc;
231
239
}
232
240
 
233
 
Q_LLONG FileTransferHandler::offset() const
 
241
qlonglong FileTransferHandler::offset() const
234
242
{
235
243
        return d->offset;
236
244
}
253
261
        return d->saveName;
254
262
}
255
263
 
256
 
void FileTransferHandler::accept(const QString &saveName, const QString &fileName, Q_LLONG offset)
 
264
void FileTransferHandler::accept(const QString &saveName, const QString &fileName, qlonglong offset)
257
265
{
258
266
        if(d->sending)
259
267
                return;
261
269
        d->saveName = saveName;
262
270
        d->offset = offset;
263
271
        d->length = d->fileSize;
264
 
        d->f.setName(saveName);
 
272
        d->f.setFileName(saveName);
265
273
        d->ft->accept(offset);
266
274
}
267
275
 
319
327
 
320
328
        if(d->sending)
321
329
                accepted();
 
330
        else
 
331
                statusMessage(QString());
322
332
}
323
333
 
324
334
void FileTransferHandler::ft_connected()
328
338
        if(d->sending) {
329
339
                // open the file, and set the correct offset
330
340
                bool ok = false;
331
 
                if(d->f.open(IO_ReadOnly)) {
 
341
                if(d->f.open(QIODevice::ReadOnly)) {
332
342
                        if(d->offset == 0) {
333
343
                                ok = true;
334
344
                        }
340
350
                if(!ok) {
341
351
                        delete d->ft;
342
352
                        d->ft = 0;
343
 
                        error(ErrFile, 0, "");
 
353
                        error(ErrFile, 0, d->f.errorString());
344
354
                        return;
345
355
                }
346
356
 
351
361
        }
352
362
        else {
353
363
                // open the file, truncating if offset is zero, otherwise set the correct offset
354
 
                int m = IO_ReadWrite;
 
364
                QIODevice::OpenMode m = QIODevice::ReadWrite;
355
365
                if(d->offset == 0)
356
 
                        m |= IO_Truncate;
 
366
                        m |= QIODevice::Truncate;
357
367
                bool ok = false;
358
368
                if(d->f.open(m)) {
359
369
                        if(d->offset == 0) {
367
377
                if(!ok) {
368
378
                        delete d->ft;
369
379
                        d->ft = 0;
370
 
                        error(ErrFile, 0, "");
 
380
                        error(ErrFile, 0, d->f.errorString());
371
381
                        return;
372
382
                }
373
383
 
391
401
                        d->f.close();
392
402
                        delete d->ft;
393
403
                        d->ft = 0;
394
 
                        error(ErrFile, 0, "");
 
404
                        error(ErrFile, 0, d->f.errorString());
395
405
                        return;
396
406
                }
397
407
                d->sent += a.size();
437
447
void FileTransferHandler::trySend()
438
448
{
439
449
        int blockSize = d->ft->dataSizeNeeded();
440
 
        QByteArray a(blockSize);
441
 
        int r = d->f.readBlock(a.data(), a.size());
 
450
        QByteArray a(blockSize, 0);
 
451
        int r = 0;
 
452
        if(blockSize > 0)
 
453
                r = d->f.read(a.data(), a.size());
442
454
        if(r < 0) {
443
455
                d->f.close();
444
456
                delete d->ft;
445
457
                d->ft = 0;
446
 
                error(ErrFile, 0, "");
 
458
                error(ErrFile, 0, d->f.errorString());
447
459
                return;
448
460
        }
449
461
        if(r < (int)a.size())
467
479
        connect(d->ft, SIGNAL(connected()), SLOT(ft_connected()));
468
480
        connect(d->ft, SIGNAL(readyRead(const QByteArray &)), SLOT(ft_readyRead(const QByteArray &)));
469
481
        connect(d->ft, SIGNAL(bytesWritten(int)), SLOT(ft_bytesWritten(int)));
470
 
        connect(d->ft, SIGNAL(error(int)), SLOT(ft_error(int)));
 
482
        connect(d->ft, SIGNAL(error(int)), SLOT(ft_error(int)),Qt::QueuedConnection);
471
483
}
472
484
 
473
485
//----------------------------------------------------------------------------
480
492
        PsiCon *psi;
481
493
        PsiAccount *pa;
482
494
        AccountsComboBox *cb_ident;
483
 
        QLabel *lb_ident, *lb_time;
 
495
        QLabel* lb_identity;
 
496
        AccountLabel* lb_ident;
 
497
        QLabel* lb_time;
484
498
        ChatView *te;
485
499
        Jid jid;
486
500
        FileTransferHandler *ft;
487
501
        QString fileName;
488
 
        Q_LLONG fileSize;
 
502
        qlonglong fileSize;
489
503
        bool sending;
490
504
        QTimer t;
491
505
};
492
506
 
493
507
 
494
508
FileRequestDlg::FileRequestDlg(const Jid &j, PsiCon *psi, PsiAccount *pa) 
495
 
:FileTransUI(0, 0, false, psi_dialog_flags | WDestructiveClose)
 
509
        : QDialog(0, psi_dialog_flags)
496
510
{
 
511
        setAttribute(Qt::WA_DeleteOnClose);
 
512
        setModal(false);
 
513
        setupUi(this);
497
514
        QStringList l;
498
515
        FileRequestDlg(j, psi, pa, l);
499
516
}
500
517
 
501
518
 
502
 
FileRequestDlg::FileRequestDlg(const Jid &jid, PsiCon *psi, PsiAccount *pa, const QStringList& files)
503
 
:FileTransUI(0, 0, false, psi_dialog_flags | WDestructiveClose)
 
519
FileRequestDlg::FileRequestDlg(const Jid &jid, PsiCon *psi, PsiAccount *pa, const QStringList& files, bool direct)
 
520
        : QDialog(0, psi_dialog_flags)
504
521
{
 
522
        setAttribute(Qt::WA_DeleteOnClose);
505
523
        d = new Private;
 
524
        setModal(false);
 
525
        setupUi(this);
506
526
        d->psi = psi;
507
527
        d->pa = 0;
508
528
        d->jid = jid;
509
529
        d->ft = 0;
510
530
        d->sending = true;
 
531
        d->lb_ident = 0;
511
532
        updateIdentity(pa);
512
533
 
513
 
        QHBox *hb = new QHBox(this);
514
 
        new QLabel(tr("Identity: "), hb);
 
534
        Q3HBox *hb = new Q3HBox(this);
 
535
        d->lb_identity = new QLabel(tr("Identity: "), hb);
515
536
        d->cb_ident = d->psi->accountsComboBox(hb);
516
537
        connect(d->cb_ident, SIGNAL(activated(PsiAccount *)), SLOT(updateIdentity(PsiAccount *)));
517
538
        d->cb_ident->setAccount(pa);
518
539
        replaceWidget(lb_accountlabel, hb);
519
540
        setTabOrder(d->cb_ident, le_to);
 
541
        connect(d->psi, SIGNAL(accountCountChanged()), this, SLOT(updateIdentityVisibility()));
 
542
        updateIdentityVisibility();
520
543
 
521
544
        d->te = new ChatView(this);
522
545
        d->te->setReadOnly(false);
523
 
        d->te->setTextFormat(PlainText);
 
546
        d->te->setTextFormat(Qt::PlainText);
524
547
        replaceWidget(te_desc, d->te);
525
548
        setTabOrder(le_fname, d->te);
526
549
        setTabOrder(d->te, pb_stop);
527
550
 
528
 
        setCaption(tr("Send File"));
 
551
        setWindowTitle(tr("Send File"));
529
552
#ifndef Q_WS_MAC
530
 
        setIcon(IconsetFactory::icon("psi/upload"));
 
553
        setWindowIcon(IconsetFactory::icon("psi/upload").icon());
531
554
#endif
532
555
 
533
556
        le_to->setText(d->jid.full());
567
590
                le_fname->setText(QDir::convertSeparators(fi.filePath()));
568
591
                lb_size->setText(tr("%1 byte(s)").arg(fi.size())); // TODO: large file support
569
592
        }
 
593
 
 
594
        if (direct) {
 
595
                doStart();
 
596
        }
570
597
}
571
598
 
572
599
FileRequestDlg::FileRequestDlg(const QDateTime &ts, FileTransfer *ft, PsiAccount *pa)
573
 
:FileTransUI(0, 0, false, psi_dialog_flags | WDestructiveClose)
 
600
        : QDialog(0, psi_dialog_flags)
574
601
{
 
602
        setAttribute(Qt::WA_DeleteOnClose);
575
603
        d = new Private;
 
604
        setModal(false);
 
605
        setupUi(this);
576
606
        d->psi = 0;
577
607
        d->pa = 0;
578
608
        d->jid = ft->peer();
584
614
        d->fileSize = ft->fileSize();
585
615
 
586
616
        d->cb_ident = 0;
587
 
        QHBox *hb = new QHBox(this);
588
 
        new QLabel(tr("Identity: "), hb);
589
 
        d->lb_ident = d->pa->accountLabel(hb);
 
617
        Q3HBox *hb = new Q3HBox(this);
 
618
        d->lb_identity = new QLabel(tr("Identity: "), hb);
 
619
        d->lb_ident = new AccountLabel(hb);
 
620
        d->lb_ident->setAccount(d->pa);
590
621
        d->lb_ident->setSizePolicy(QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ));
591
622
        new QLabel(tr("Time:"), hb);
592
 
        d->lb_time = new QLabel(ts.time().toString(LocalDate), hb);
 
623
        d->lb_time = new QLabel(ts.time().toString(Qt::LocalDate), hb);
593
624
        d->lb_time->setFrameStyle( QFrame::Panel | QFrame::Sunken );
 
625
        connect(d->pa->psi(), SIGNAL(accountCountChanged()), this, SLOT(updateIdentityVisibility()));
 
626
        updateIdentityVisibility();
594
627
 
595
628
        replaceWidget(lb_accountlabel, hb);
596
629
 
597
630
        d->te = new ChatView(this);
598
 
        d->te->setTextFormat(PlainText);
 
631
        d->te->setTextFormat(Qt::PlainText);
599
632
        replaceWidget(te_desc, d->te);
600
633
        setTabOrder(le_fname, d->te);
601
634
        setTabOrder(d->te, pb_stop);
602
635
 
603
636
        lb_to->setText(tr("From:"));
604
 
        setCaption(tr("Receive File"));
 
637
        setWindowTitle(tr("Receive File"));
605
638
#ifndef Q_WS_MAC
606
 
        setIcon(IconsetFactory::icon("psi/download"));
 
639
        setWindowIcon(IconsetFactory::icon("psi/download").icon());
607
640
#endif
608
641
 
609
642
        le_to->setText(d->jid.full());
656
689
 
657
690
void FileRequestDlg::keyPressEvent(QKeyEvent *e)
658
691
{
659
 
        if(e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) ) {
 
692
        if(e->key() == Qt::Key_Return && ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::AltModifier)) ) {
660
693
                if(pb_start->isEnabled())
661
694
                        doStart();
662
695
        }
678
711
        connect(d->pa, SIGNAL(disconnected()), this, SLOT(pa_disconnected()));
679
712
}
680
713
 
 
714
void FileRequestDlg::updateIdentityVisibility()
 
715
{
 
716
        bool visible = d->pa->psi()->contactList()->enabledAccounts().count() > 1;
 
717
        if (d->cb_ident) 
 
718
                d->cb_ident->setVisible(visible);
 
719
        if (d->lb_ident)
 
720
                d->lb_ident->setVisible(visible);
 
721
        d->lb_identity->setVisible(visible);
 
722
}
 
723
 
681
724
void FileRequestDlg::pa_disconnected()
682
725
{
683
726
        //if(busy->isActive()) {
713
756
        while(1) {
714
757
                if(option.lastPath.isEmpty())
715
758
                        option.lastPath = QDir::homeDirPath();
716
 
                QString str = QFileDialog::getOpenFileName(option.lastPath, tr("All files (*)"), this, 0, tr("Choose a file"));
 
759
                QString str = QFileDialog::getOpenFileName(this, tr("Choose a file"), option.lastPath, tr("All files (*)"));
717
760
                if(!str.isEmpty()) {
718
761
                        QFileInfo fi(str);
719
762
                        if(!fi.exists()) {
765
808
        }
766
809
        else {
767
810
                QString fname, savename;
768
 
                bool overwrite = false;
769
 
                while(1) {
770
 
                        if(option.lastSavePath.isEmpty())
771
 
                                option.lastSavePath = QDir::homeDirPath();
772
 
                        fname = QFileDialog::getSaveFileName(QDir(option.lastSavePath).filePath(d->fileName), tr("All files (*)"), this, 0, tr("Save As"));
773
 
                        if(!fname.isEmpty()) {
774
 
                                QFileInfo fi(fname);
775
 
                                if(fi.exists()) {
776
 
                                        int x = QMessageBox::information(this, tr("Error"), tr("File already exists.  Overwrite?"), tr("&Yes"), tr("&No"));
777
 
                                        if(x != 0)
778
 
                                                continue;
779
 
                                        overwrite = true;
780
 
                                }
781
 
                                option.lastSavePath = fi.dirPath();
782
 
                                savename = fname + ".part";
783
 
                                fname = fi.fileName();
784
 
                        }
785
 
                        else
786
 
                                return;
787
 
 
788
 
                        break;
789
 
                }
 
811
                if(option.lastSavePath.isEmpty())
 
812
                        option.lastSavePath = QDir::homeDirPath();
 
813
                fname = QFileDialog::getSaveFileName(this, tr("Save As"), QDir(option.lastSavePath).filePath(d->fileName), tr("All files (*)"));
 
814
                if(fname.isEmpty())
 
815
                        return;
 
816
                QFileInfo fi(fname);
 
817
                option.lastSavePath = fi.dirPath();
 
818
                savename = fname + ".part";
 
819
                fname = fi.fileName();
790
820
 
791
821
                if(active_file_check(savename)) {
792
822
                        QMessageBox::information(this, tr("Error"), tr("This file is being transferred already!"));
793
823
                        return;
794
824
                }
795
825
 
796
 
                Q_LLONG resume_offset = 0;
797
 
                if(!overwrite) {
 
826
                qlonglong resume_offset = 0;
 
827
                if(!fi.exists()) {
798
828
                        // supports resume?  check for a .part
799
829
                        if(d->ft->resumeSupported()) {
800
830
                                QFileInfo fi(savename);
828
858
 
829
859
void FileRequestDlg::ft_statusMessage(const QString &s)
830
860
{
831
 
        lb_status->setText(s);
 
861
        if(!s.isEmpty()) {
 
862
                lb_status->setText(s);
 
863
        }
832
864
 
833
865
        // stop the timer at first activity
834
866
        if(d->t.isActive())
914
946
//----------------------------------------------------------------------------
915
947
// FileTransDlg
916
948
//----------------------------------------------------------------------------
917
 
class FileTransItem : public QListViewItem
 
949
class FileTransItem : public Q3ListViewItem
918
950
{
919
951
public:
920
952
        QPixmap icon;
921
953
        bool sending;
922
954
        QString name;
923
 
        Q_LLONG size;
 
955
        qlonglong size;
924
956
        QString peer;
925
957
        QString rate;
926
958
        int progress;
927
 
        Q_LLONG sent;
 
959
        qlonglong sent;
928
960
        int bps;
929
961
        int timeRemaining;
930
962
        int id;
932
964
        bool done;
933
965
        QString error;
934
966
 
935
 
        FileTransItem(QListView *parent, const QString &_name, Q_LLONG _size, const QString &_peer, bool _sending)
936
 
        :QListViewItem(parent)
 
967
        FileTransItem(Q3ListView *parent, const QString &_name, qlonglong _size, const QString &_peer, bool _sending)
 
968
        :Q3ListViewItem(parent)
937
969
        {
938
970
                done = false;
939
971
                sending = _sending;
946
978
                dist = -1;
947
979
        }
948
980
 
949
 
        void niceUnit(Q_LLONG n, Q_LLONG *div, QString *unit)
 
981
        void niceUnit(qlonglong n, qlonglong *div, QString *unit)
950
982
        {
951
 
                Q_LLONG gb = 1024 * 1024 * 1024;
952
 
                Q_LLONG mb = 1024 * 1024;
953
 
                Q_LLONG kb = 1024;
 
983
                qlonglong gb = 1024 * 1024 * 1024;
 
984
                qlonglong mb = 1024 * 1024;
 
985
                qlonglong kb = 1024;
954
986
                if(n >= gb) {
955
987
                        *div = gb;
956
988
                        *unit = QString("GB");
969
1001
                }
970
1002
        }
971
1003
 
972
 
        QString roundedNumber(Q_LLONG n, Q_LLONG div)
 
1004
        QString roundedNumber(qlonglong n, qlonglong div)
973
1005
        {
974
1006
                bool decimal = false;
975
1007
                if(div >= 1024) {
976
1008
                        div /= 10;
977
1009
                        decimal = true;
978
1010
                }
979
 
                Q_LLONG x_long = n / div;
 
1011
                qlonglong x_long = n / div;
980
1012
                int x = (int)x_long;
981
1013
                if(decimal) {
982
1014
                        double f = (double)x;
987
1019
                        return QString::number(x);
988
1020
        }
989
1021
 
990
 
        bool setProgress(int _progress, Q_LLONG _sent, int _bps)
 
1022
        bool setProgress(int _progress, qlonglong _sent, int _bps)
991
1023
        {
992
1024
                progress = _progress;
993
1025
                sent = _sent;
994
1026
                bps = _bps;
995
1027
 
996
1028
                if(bps > 0) {
997
 
                        Q_LLONG rest_long = size - sent;
 
1029
                        qlonglong rest_long = size - sent;
998
1030
                        rest_long /= bps;
999
1031
                        int maxtime = (23 * 60 * 60) + (59 * 60) + (59); // 23h59m59s
1000
1032
                        if(rest_long > maxtime)
1014
1046
        {
1015
1047
                QString s;
1016
1048
                {
1017
 
                        Q_LLONG div;
 
1049
                        qlonglong div;
1018
1050
                        QString unit;
1019
1051
                        niceUnit(size, &div, &unit);
1020
1052
 
1084
1116
 
1085
1117
                p->save();
1086
1118
                p->setPen(cg.highlightedText());
1087
 
                p->setClipRect(xoff, yoff, dist, ysize, QPainter::CoordPainter);
 
1119
                p->setClipRect(xoff, yoff, dist, ysize);
1088
1120
                p->drawText(center - (textwidth / 2), ty, s);
1089
1121
                p->restore();
1090
1122
 
1091
1123
                p->save();
1092
1124
                p->setPen(cg.text());
1093
 
                p->setClipRect(xoff + dist, yoff, width - 2 - dist, ysize, QPainter::CoordPainter);
 
1125
                p->setClipRect(xoff + dist, yoff, width - 2 - dist, ysize);
1094
1126
                p->drawText(center - (textwidth / 2), ty, s);
1095
1127
                p->restore();
1096
1128
                p->restore();
1099
1131
        void setup()
1100
1132
        {
1101
1133
                widthChanged();
1102
 
                QListView *lv = listView();
 
1134
                Q3ListView *lv = listView();
1103
1135
 
1104
1136
                QFontMetrics fm = lv->fontMetrics();
1105
1137
                int m = 4;
1258
1290
        }
1259
1291
};
1260
1292
 
1261
 
class FileTransView : public QListView, public QToolTip
 
1293
class FileTransView : public Q3ListView
1262
1294
{
1263
1295
        Q_OBJECT
1264
1296
public:
1265
1297
        FileTransView(QWidget *parent=0, const char *name=0)
1266
 
        :QListView(parent, name), QToolTip(viewport())
 
1298
        :Q3ListView(parent, name)
1267
1299
        {
1268
 
                connect(this, SIGNAL(contextMenuRequested(QListViewItem *, const QPoint &, int)), this, SLOT(qlv_contextMenuRequested(QListViewItem *, const QPoint &, int)));
 
1300
                connect(this, SIGNAL(contextMenuRequested(Q3ListViewItem *, const QPoint &, int)), this, SLOT(qlv_contextMenuRequested(Q3ListViewItem *, const QPoint &, int)));
1269
1301
        }
1270
1302
 
1271
 
        void maybeTip(const QPoint &pos)
 
1303
        bool maybeTip(const QPoint &pos)
1272
1304
        {
1273
1305
                FileTransItem *i = static_cast<FileTransItem*>(itemAt(pos));
1274
1306
                if(!i)
1275
 
                        return;
 
1307
                        return false;
1276
1308
                QRect r(itemRect(i));
1277
 
                tip(r, i->makeTip());
 
1309
                PsiToolTip::showText(mapToGlobal(pos), i->makeTip(), this);
 
1310
                return true;
1278
1311
        }
1279
1312
 
1280
1313
        void resizeEvent(QResizeEvent *e)
1281
1314
        {
1282
 
                QListView::resizeEvent(e);
 
1315
                Q3ListView::resizeEvent(e);
1283
1316
 
1284
1317
                if(e->oldSize().width() != e->size().width())
1285
1318
                        doResize();
1286
1319
        }
 
1320
        
 
1321
        bool event(QEvent* e)
 
1322
        {
 
1323
                if (e->type() == QEvent::ToolTip) {
 
1324
                        QPoint pos = ((QHelpEvent*) e)->pos();
 
1325
                        e->setAccepted(maybeTip(pos));
 
1326
                        return true;
 
1327
                }
 
1328
                return Q3ListView::event(e);
 
1329
        }
1287
1330
 
1288
1331
signals:
1289
1332
        void itemCancel(int id);
1291
1334
        void itemClear(int id);
1292
1335
 
1293
1336
private slots:
1294
 
        void qlv_contextMenuRequested(QListViewItem *item, const QPoint &pos, int)
 
1337
        void qlv_contextMenuRequested(Q3ListViewItem *item, const QPoint &pos, int)
1295
1338
        {
1296
1339
                if(!item)
1297
1340
                        return;
1298
1341
 
1299
1342
                FileTransItem *i = static_cast<FileTransItem*>(item);
1300
1343
 
1301
 
                QPopupMenu p;
 
1344
                Q3PopupMenu p;
1302
1345
                p.insertItem(tr("&Cancel"), 0);
1303
1346
                p.insertSeparator();
1304
1347
                //p.insertItem(tr("&Open Destination Folder"), 1);
1329
1372
private:
1330
1373
        void doResize()
1331
1374
        {
1332
 
                QListViewItemIterator it(this);
1333
 
                for(QListViewItem *i; (i = it.current()); ++it)
 
1375
                Q3ListViewItemIterator it(this);
 
1376
                for(Q3ListViewItem *i; (i = it.current()); ++it)
1334
1377
                        i->setup();
1335
1378
        }
1336
1379
};
1341
1384
        FileTransferHandler *h;
1342
1385
        int id;
1343
1386
        int p;
1344
 
        Q_LLONG sent;
 
1387
        qlonglong sent;
1345
1388
 
1346
1389
        int at;
1347
 
        Q_LLONG last[10];
 
1390
        qlonglong last[10];
1348
1391
 
1349
1392
        TransferMapping()
1350
1393
        {
1375
1418
        FileTransDlg *parent;
1376
1419
        PsiCon *psi;
1377
1420
        FileTransView *lv;
1378
 
        QPtrList<TransferMapping> transferList;
 
1421
        Q3PtrList<TransferMapping> transferList;
1379
1422
        QTimer t;
1380
1423
 
1381
1424
        Private(FileTransDlg *_parent)
1389
1432
                int n = 0;
1390
1433
                while(1) {
1391
1434
                        bool found = false;
1392
 
                        QListViewItemIterator it(lv);
1393
 
                        for(QListViewItem *i; (i = it.current()); ++it) {
 
1435
                        Q3ListViewItemIterator it(lv);
 
1436
                        for(Q3ListViewItem *i; (i = it.current()); ++it) {
1394
1437
                                FileTransItem *fi = static_cast<FileTransItem*>(i);
1395
1438
                                if(fi->id == n) {
1396
1439
                                        found = true;
1406
1449
 
1407
1450
        FileTransItem *findItem(int id)
1408
1451
        {
1409
 
                QListViewItemIterator it(lv);
1410
 
                for(QListViewItem *i; (i = it.current()); ++it) {
 
1452
                Q3ListViewItemIterator it(lv);
 
1453
                for(Q3ListViewItem *i; (i = it.current()); ++it) {
1411
1454
                        FileTransItem *fi = static_cast<FileTransItem*>(i);
1412
1455
                        if(fi->id == id)
1413
1456
                                return fi;
1415
1458
                return 0;
1416
1459
        }
1417
1460
 
1418
 
        QPtrList<FileTransItem> getFinished()
 
1461
        Q3PtrList<FileTransItem> getFinished()
1419
1462
        {
1420
 
                QPtrList<FileTransItem> list;
1421
 
                QListViewItemIterator it(lv);
1422
 
                for(QListViewItem *i; (i = it.current()); ++it) {
 
1463
                Q3PtrList<FileTransItem> list;
 
1464
                Q3ListViewItemIterator it(lv);
 
1465
                for(Q3ListViewItem *i; (i = it.current()); ++it) {
1423
1466
                        FileTransItem *fi = static_cast<FileTransItem*>(i);
1424
1467
                        if(fi->done)
1425
1468
                                list.append(fi);
1429
1472
 
1430
1473
        TransferMapping *findMapping(FileTransferHandler *h)
1431
1474
        {
1432
 
                QPtrListIterator<TransferMapping> it(transferList);
 
1475
                Q3PtrListIterator<TransferMapping> it(transferList);
1433
1476
                for(TransferMapping *i; (i = it.current()); ++it) {
1434
1477
                        if(i->h == h)
1435
1478
                                return i;
1439
1482
 
1440
1483
        TransferMapping *findMapping(int id)
1441
1484
        {
1442
 
                QPtrListIterator<TransferMapping> it(transferList);
 
1485
                Q3PtrListIterator<TransferMapping> it(transferList);
1443
1486
                for(TransferMapping *i; (i = it.current()); ++it) {
1444
1487
                        if(i->id == id)
1445
1488
                                return i;
1455
1498
                int bps = -1;
1456
1499
                if(!done && i->at >= 2) {
1457
1500
                        int seconds = i->at - 1;
1458
 
                        Q_LLONG average = i->last[i->at-1] - i->last[0];
 
1501
                        qlonglong average = i->last[i->at-1] - i->last[0];
1459
1502
                        bps = ((int)average) / seconds;
1460
1503
                }
1461
1504
 
1504
1547
 
1505
1548
        connect(&d->t, SIGNAL(timeout()), SLOT(updateItems()));
1506
1549
 
1507
 
        setCaption(tr("Transfer Manager"));
 
1550
        setWindowTitle(tr("Transfer Manager"));
1508
1551
#ifndef Q_WS_MAC
1509
 
        setIcon(IconsetFactory::icon("psi/filemanager"));
 
1552
        setWindowIcon(IconsetFactory::icon("psi/filemanager").icon());
1510
1553
#endif
1511
1554
 
1512
1555
        QVBoxLayout *vb = new QVBoxLayout(this, 11, 6);
1530
1573
        d->lv->addColumn("");
1531
1574
        d->lv->header()->hide();
1532
1575
 
1533
 
        d->lv->setResizeMode(QListView::LastColumn);
 
1576
        d->lv->setResizeMode(Q3ListView::LastColumn);
1534
1577
        d->lv->setAllColumnsShowFocus(true);
1535
1578
        d->lv->setSorting(-1);
1536
1579
 
1543
1586
        delete d;
1544
1587
}
1545
1588
 
1546
 
int FileTransDlg::addItem(const QString &filename, Q_LLONG size, const QString &peer, bool sending)
 
1589
int FileTransDlg::addItem(const QString &filename, qlonglong size, const QString &peer, bool sending)
1547
1590
{
1548
1591
        int id = d->findFreeId();
1549
1592
        FileTransItem *i = new FileTransItem(d->lv, filename, size, peer, sending);
1556
1599
        return id;
1557
1600
}
1558
1601
 
1559
 
void FileTransDlg::setProgress(int id, int step, int total, Q_LLONG sent, int bytesPerSecond, bool updateAll)
 
1602
void FileTransDlg::setProgress(int id, int step, int total, qlonglong sent, int bytesPerSecond, bool updateAll)
1560
1603
{
1561
1604
        FileTransItem *i = d->findItem(id);
1562
1605
        if(i) {
1600
1643
        }
1601
1644
}
1602
1645
 
1603
 
void FileTransDlg::takeTransfer(FileTransferHandler *h, int p, Q_LLONG sent)
 
1646
void FileTransDlg::takeTransfer(FileTransferHandler *h, int p, qlonglong sent)
1604
1647
{
1605
1648
        QString peer;
1606
 
        UserListItem *u = h->account()->findFirstRelavent(h->peer());
 
1649
        UserListItem *u = h->account()->findFirstRelevant(h->peer());
1607
1650
        if(u)
1608
 
                peer = jidnick(u->jid().full(), u->name());
 
1651
                peer = JIDUtil::nickOrJid(u->name(),u->jid().full());
1609
1652
        else
1610
1653
                peer = h->peer().full();
1611
1654
 
1623
1666
                d->updateProgress(i, true);
1624
1667
        }
1625
1668
        else {
1626
 
                connect(h, SIGNAL(progress(int, Q_LLONG)), SLOT(ft_progress(int, Q_LLONG)));
 
1669
                connect(h, SIGNAL(progress(int, qlonglong)), SLOT(ft_progress(int, qlonglong)));
1627
1670
                connect(h, SIGNAL(error(int, int, const QString &)), SLOT(ft_error(int, int, const QString &)));
1628
1671
        }
1629
1672
}
1630
1673
 
1631
1674
void FileTransDlg::clearFinished()
1632
1675
{
1633
 
        QPtrList<FileTransItem> list = d->getFinished();
 
1676
        Q3PtrList<FileTransItem> list = d->getFinished();
1634
1677
        {
1635
1678
                // remove related transfer mappings
1636
 
                QPtrListIterator<FileTransItem> it(list);
 
1679
                Q3PtrListIterator<FileTransItem> it(list);
1637
1680
                for(FileTransItem *fi; (fi = it.current()); ++it) {
1638
1681
                        TransferMapping *i = d->findMapping(fi->id);
1639
1682
                        d->transferList.removeRef(i);
1643
1686
        list.clear();
1644
1687
}
1645
1688
 
1646
 
void FileTransDlg::ft_progress(int p, Q_LLONG sent)
 
1689
void FileTransDlg::ft_progress(int p, qlonglong sent)
1647
1690
{
1648
1691
        TransferMapping *i = d->findMapping((FileTransferHandler *)sender());
1649
1692
        i->p = p;
1666
1709
        if(x == FileTransferHandler::ErrTransfer)
1667
1710
                str = s;
1668
1711
        else
1669
 
                str = tr("File I/O error");
 
1712
                str = tr("File I/O error (%1)").arg(s);
1670
1713
        setError(id, str);
1671
1714
}
1672
1715
 
1673
1716
void FileTransDlg::updateItems()
1674
1717
{
1675
1718
        // operate on a copy so that we can delete items in updateProgress
1676
 
        QPtrList<TransferMapping> list = d->transferList;
1677
 
        QPtrListIterator<TransferMapping> it(list);
 
1719
        Q3PtrList<TransferMapping> list = d->transferList;
 
1720
        Q3PtrListIterator<TransferMapping> it(list);
1678
1721
        for(TransferMapping *i; (i = it.current()); ++it) {
1679
1722
                if(i->h) {
1680
1723
                        i->logSent();
1715
1758
 
1716
1759
void FileTransDlg::killTransfers(PsiAccount *pa)
1717
1760
{
1718
 
        QPtrList<TransferMapping> list = d->transferList;
1719
 
        QPtrListIterator<TransferMapping> it(list);
 
1761
        Q3PtrList<TransferMapping> list = d->transferList;
 
1762
        Q3PtrListIterator<TransferMapping> it(list);
1720
1763
        for(TransferMapping *i; (i = it.current()); ++it) {
1721
1764
                // this account?
1722
1765
                if(i->h->account() == pa) {
1727
1770
        }
1728
1771
}
1729
1772
 
1730
 
#include"filetransdlg.moc"
 
1773
#include "filetransdlg.moc"