~ubuntu-branches/ubuntu/edgy/psi/edgy

« back to all changes in this revision

Viewing changes to src/filetransdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2005-09-14 16:33:49 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050914163349-3zacov4afysz5cw5
Tags: 0.9.3-2ubuntu1
* Sync with debian
* Applied patch to psi.desktop to start psi without gpg-agent use (known
  issue)
* Updated README.Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
        return 0;
49
49
}
50
50
 
 
51
static int calcComplement(Q_LLONG big, int shift)
 
52
{
 
53
        int block = 1 << shift;
 
54
        Q_LLONG rem = big % block;
 
55
        if(rem == 0)
 
56
                return 0;
 
57
        else
 
58
                return (block - (int)rem);
 
59
}
 
60
 
 
61
static int calcTotalSteps(Q_LLONG big, int shift)
 
62
{
 
63
        if(big < 1)
 
64
                return 0;
 
65
        return ((big - 1) >> shift) + 1;
 
66
}
 
67
 
 
68
static int calcProgressStep(Q_LLONG big, int complement, int shift)
 
69
{
 
70
        return ((big + complement) >> shift);
 
71
}
 
72
 
51
73
static QStringList *activeFiles = 0;
52
74
 
53
75
static void active_file_add(const QString &s)
113
135
        bool sending;
114
136
        QFile f;
115
137
        int shift;
 
138
        int complement;
116
139
        QString activeFile;
117
140
};
118
141
 
129
152
                d->fileSize = ft->fileSize();
130
153
                d->desc = ft->description();
131
154
                d->shift = calcShift(d->fileSize);
 
155
                d->complement = calcComplement(d->fileSize, d->shift);
132
156
                d->ft = ft;
133
157
                Jid proxy = d->pa->userAccount().dtProxy;
134
158
                if(proxy.isValid())
164
188
        d->fileSize = fi.size(); // TODO: large file support
165
189
        d->desc = desc;
166
190
        d->shift = calcShift(d->fileSize);
 
191
        d->complement = calcComplement(d->fileSize, d->shift);
167
192
 
168
193
        d->ft = d->pa->client()->fileTransferManager()->createTransfer();
169
194
        Jid proxy = d->pa->userAccount().dtProxy;
212
237
 
213
238
int FileTransferHandler::totalSteps() const
214
239
{
215
 
        return (d->fileSize >> d->shift);
 
240
        return calcTotalSteps(d->fileSize, d->shift);
216
241
}
217
242
 
218
243
bool FileTransferHandler::resumeSupported() const
386
411
                }
387
412
                else
388
413
                        QTimer::singleShot(0, this, SLOT(trySend()));
389
 
                progress(d->sent >> d->shift, d->sent);
 
414
                progress(calcProgressStep(d->sent, d->complement, d->shift), d->sent);
390
415
        }
391
416
}
392
417
 
433
458
                delete d->ft;
434
459
                d->ft = 0;
435
460
        }
436
 
        progress(d->sent >> d->shift, d->sent);
 
461
        progress(calcProgressStep(d->sent, d->complement, d->shift), d->sent);
437
462
}
438
463
 
439
464
void FileTransferHandler::mapSignals()
466
491
        QTimer t;
467
492
};
468
493
 
469
 
FileRequestDlg::FileRequestDlg(const Jid &jid, PsiCon *psi, PsiAccount *pa)
 
494
 
 
495
FileRequestDlg::FileRequestDlg(const Jid &j, PsiCon *psi, PsiAccount *pa) 
 
496
:FileTransUI(0, 0, false, psi_dialog_flags | WDestructiveClose)
 
497
{
 
498
        QStringList l;
 
499
        FileRequestDlg(j, psi, pa, l);
 
500
}
 
501
 
 
502
 
 
503
FileRequestDlg::FileRequestDlg(const Jid &jid, PsiCon *psi, PsiAccount *pa, const QStringList& files)
470
504
:FileTransUI(0, 0, false, psi_dialog_flags | WDestructiveClose)
471
505
{
472
506
        d = new Private;
493
527
        setTabOrder(d->te, pb_stop);
494
528
 
495
529
        setCaption(tr("Send File"));
 
530
#ifndef Q_WS_MAC
496
531
        setIcon(IconsetFactory::icon("psi/upload"));
 
532
#endif
497
533
 
498
534
        le_to->setText(d->jid.full());
499
535
        le_to->setReadOnly(false);
508
544
 
509
545
        d->te->setFocus();
510
546
        d->psi->dialogRegister(this);
511
 
        QTimer::singleShot(0, this, SLOT(chooseFile()));
 
547
 
 
548
        if (files.isEmpty()) {
 
549
                QTimer::singleShot(0, this, SLOT(chooseFile()));
 
550
        }
 
551
        else {
 
552
                // TODO: Once sending of multiple files is supported, change this
 
553
                QFileInfo fi(files.first());
 
554
 
 
555
                // Check if the file is legal
 
556
                if(!fi.exists()) {
 
557
                        QMessageBox::critical(this, tr("Error"), QString("The file '%1' does not exist.").arg(files.first()));
 
558
                        QTimer::singleShot(0, this, SLOT(reject()));
 
559
                        return;
 
560
                }
 
561
                if(fi.isDir()) {
 
562
                        QMessageBox::critical(this, tr("Error"), tr("Sending folders is not supported."));
 
563
                        QTimer::singleShot(0, this, SLOT(reject()));
 
564
                        return;
 
565
                }
 
566
                
 
567
                lastPath = fi.dirPath();
 
568
                le_fname->setText(QDir::convertSeparators(fi.filePath()));
 
569
                lb_size->setText(tr("%1 byte(s)").arg(fi.size())); // TODO: large file support
 
570
        }
512
571
}
513
572
 
514
573
FileRequestDlg::FileRequestDlg(const QDateTime &ts, FileTransfer *ft, PsiAccount *pa)
544
603
 
545
604
        lb_to->setText(tr("From:"));
546
605
        setCaption(tr("Receive File"));
 
606
#ifndef Q_WS_MAC
547
607
        setIcon(IconsetFactory::icon("psi/download"));
 
608
#endif
548
609
 
549
610
        le_to->setText(d->jid.full());
550
611
        le_fname->setText(d->fileName);
1445
1506
        connect(&d->t, SIGNAL(timeout()), SLOT(updateItems()));
1446
1507
 
1447
1508
        setCaption(tr("Transfer Manager"));
 
1509
#ifndef Q_WS_MAC
1448
1510
        setIcon(IconsetFactory::icon("psi/filemanager"));
 
1511
#endif
1449
1512
 
1450
1513
        QVBoxLayout *vb = new QVBoxLayout(this, 11, 6);
1451
1514
        d->lv = new FileTransView(this);