diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index a753ea741..33fcc505e 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -21,6 +21,10 @@ #include "src/misc/style.h" #include +#include +#include +#include +#include #include FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file) @@ -31,6 +35,10 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file) { ui->setupUi(this); + // hide the QWidget background (background-color: transparent doesn't seem to work) + setAttribute(Qt::WA_TranslucentBackground, true); + + ui->previewLabel->hide(); ui->filenameLabel->setText(file.fileName); ui->progressBar->setValue(0); ui->fileSizeLabel->setText(getHumanReadableSize(file.filesize)); @@ -48,6 +56,10 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file) setupButtons(); + //preview + if(fileInfo.direction == ToxFile::SENDING) + showPreview(fileInfo.filePath); + setFixedHeight(85); } @@ -123,7 +135,7 @@ void FileTransferWidget::onFileTransferCancelled(ToxFile file) setupButtons(); hideWidgets(); - disconnect(Core::getInstance()); + disconnect(Core::getInstance(), 0, this, 0); } void FileTransferWidget::onFileTransferPaused(ToxFile file) @@ -152,7 +164,11 @@ void FileTransferWidget::onFileTransferFinished(ToxFile file) setupButtons(); hideWidgets(); - disconnect(Core::getInstance()); + // preview + if(fileInfo.direction == ToxFile::RECEIVING) + showPreview(fileInfo.filePath); + + disconnect(Core::getInstance(), 0, this, 0); } QString FileTransferWidget::getHumanReadableSize(qint64 size) @@ -194,6 +210,19 @@ void FileTransferWidget::setupButtons() break; case ToxFile::STOPPED: case ToxFile::BROKEN: //TODO: ? + ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/no_2x.png")); + ui->topButton->setObjectName("cancel"); + + if(fileInfo.direction == ToxFile::SENDING) + { + ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/pause_2x.png")); + ui->bottomButton->setObjectName("pause"); + } + else + { + ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/yes_2x.png")); + ui->bottomButton->setObjectName("accept"); + } break; } } @@ -217,9 +246,33 @@ void FileTransferWidget::handleButton(QPushButton *btn) Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum); if(btn->objectName() == "resume") Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum); + if(btn->objectName() == "accept") + { + QString path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(fileInfo.fileName)); + + if(!QFileInfo(QDir(path).path()).isWritable()) + { + QMessageBox::warning(0, + tr("Location not writable","Title of permissions popup"), + tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup")); + + return; + } + + if(!path.isEmpty()) + Core::getInstance()->acceptFileRecvRequest(fileInfo.friendId, fileInfo.fileNum, path); + } } } +void FileTransferWidget::showPreview(const QString &filename) +{ + //QPixmap pmap = QPixmap(filename).scaled(QSize(ui->previewLabel->maximumWidth(), maximumHeight()), Qt::KeepAspectRatio, Qt::SmoothTransformation); + QPixmap pmap = QPixmap(filename).scaledToWidth(ui->previewLabel->maximumWidth(), Qt::SmoothTransformation); + ui->previewLabel->setPixmap(pmap); + ui->previewLabel->show(); +} + void FileTransferWidget::on_topButton_clicked() { handleButton(ui->topButton); diff --git a/src/chatlog/content/filetransferwidget.h b/src/chatlog/content/filetransferwidget.h index d4a32e6e0..11d6b52ee 100644 --- a/src/chatlog/content/filetransferwidget.h +++ b/src/chatlog/content/filetransferwidget.h @@ -48,6 +48,7 @@ protected: void hideWidgets(); void setupButtons(); void handleButton(QPushButton* btn); + void showPreview(const QString& filename); private slots: void on_topButton_clicked(); diff --git a/src/chatlog/content/filetransferwidget.ui b/src/chatlog/content/filetransferwidget.ui index 7467ee60e..7992bce16 100644 --- a/src/chatlog/content/filetransferwidget.ui +++ b/src/chatlog/content/filetransferwidget.ui @@ -13,12 +13,7 @@ Form - - #FileTransferWidget { - background-color:transparent; -} - - + @@ -40,6 +35,31 @@ 0 + + 0 + + + 0 + + + + + + 80 + 0 + + + + + 80 + 16777215 + + + + [preview] + + + diff --git a/src/corestructs.cpp b/src/corestructs.cpp index 3f66354de..5ed31df65 100644 --- a/src/corestructs.cpp +++ b/src/corestructs.cpp @@ -14,7 +14,7 @@ ToxFile::ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePat bool ToxFile::operator==(const ToxFile &other) const { - return fileNum == other.fileNum && friendId && other.friendId; + return (fileNum == other.fileNum) && (friendId == other.friendId) && (direction == other.direction); } bool ToxFile::operator!=(const ToxFile &other) const diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 9a6aaac6d..467258633 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -164,19 +164,6 @@ void ChatForm::startFileSend(ToxFile file) if (file.friendId != f->getFriendID()) return; - - - FileTransferInstance* fileTrans = new FileTransferInstance(file); - ftransWidgets.insert(fileTrans->getId(), fileTrans); - -// connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo); -// connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled); -// connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished); -// connect(Core::getInstance(), SIGNAL(fileTransferAccepted(ToxFile)), fileTrans, SLOT(onFileTransferAccepted(ToxFile))); -// connect(Core::getInstance(), SIGNAL(fileTransferPaused(int,int,ToxFile::FileDirection)), fileTrans, SLOT(onFileTransferPaused(int,int,ToxFile::FileDirection))); -// connect(Core::getInstance(), SIGNAL(fileTransferRemotePausedUnpaused(ToxFile,bool)), fileTrans, SLOT(onFileTransferRemotePausedUnpaused(ToxFile,bool))); -// connect(Core::getInstance(), SIGNAL(fileTransferBrokenUnbroken(ToxFile, bool)), fileTrans, SLOT(onFileTransferBrokenUnbroken(ToxFile, bool))); - QString name; if (!previousId.isMine()) { @@ -194,17 +181,6 @@ void ChatForm::onFileRecvRequest(ToxFile file) if (file.friendId != f->getFriendID()) return; - FileTransferInstance* fileTrans = new FileTransferInstance(file); - ftransWidgets.insert(fileTrans->getId(), fileTrans); - -// connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo); -// connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled); -// connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished); -// connect(Core::getInstance(), SIGNAL(fileTransferAccepted(ToxFile)), fileTrans, SLOT(onFileTransferAccepted(ToxFile))); -// connect(Core::getInstance(), SIGNAL(fileTransferPaused(int,int,ToxFile::FileDirection)), fileTrans, SLOT(onFileTransferPaused(int,int,ToxFile::FileDirection))); -// connect(Core::getInstance(), SIGNAL(fileTransferRemotePausedUnpaused(ToxFile,bool)), fileTrans, SLOT(onFileTransferRemotePausedUnpaused(ToxFile,bool))); -// connect(Core::getInstance(), SIGNAL(fileTransferBrokenUnbroken(ToxFile, bool)), fileTrans, SLOT(onFileTransferBrokenUnbroken(ToxFile, bool))); - Widget* w = Widget::getInstance(); if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow()) { @@ -221,12 +197,11 @@ void ChatForm::onFileRecvRequest(ToxFile file) previousId = friendId; } - //TODO: chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name), - // QTime::currentTime().toString("hh:mm"), false))); - - if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty() - || Settings::getInstance().getAutoSaveEnabled()) - fileTrans->pressFromHtml("btnB"); + chatWidget->addFileTransferMessage(name, file, QDateTime::currentDateTime(), false); +//TODO: +// if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty() +// || Settings::getInstance().getAutoSaveEnabled()) +// fileTrans->pressFromHtml("btnB"); } void ChatForm::onAvInvite(int FriendId, int CallId, bool video) diff --git a/ui/fileTransferInstance/green.css b/ui/fileTransferInstance/green.css new file mode 100644 index 000000000..9a37b0b0b --- /dev/null +++ b/ui/fileTransferInstance/green.css @@ -0,0 +1,27 @@ +QFrame { + border-image: url(:/ui/fileTransferInstance/background_green.png); + border-left:25;padding-top:-30; + border-top:28; + border-right:25; padding-right:-28; + border-bottom:28;padding-bottom:-30; +} + +QLabel { + color:white; +} + +QPushButton { + margin:0; +} + +QProgressBar { + border: 2px solid black; + border-radius: 0px; + color: white; + background-color:white; +} + +QProgressBar::chunk { + background-color: black; + width: 20px; +} \ No newline at end of file diff --git a/ui/fileTransferInstance/grey.css b/ui/fileTransferInstance/grey.css new file mode 100644 index 000000000..1d390374d --- /dev/null +++ b/ui/fileTransferInstance/grey.css @@ -0,0 +1,27 @@ +QFrame { + border-image: url(:/ui/fileTransferInstance/background_grey.png); + border-left:25;padding-top:-30; + border-top:28; + border-right:25; padding-right:-28; + border-bottom:28;padding-bottom:-30; +} + +QLabel { + color:black; +} + +QPushButton { + margin:0; +} + +QProgressBar { + border: 2px solid black; + border-radius: 0px; + color: white; + background-color:white; +} + +QProgressBar::chunk { + background-color: black; + width: 20px; +} \ No newline at end of file diff --git a/ui/fileTransferInstance/red.css b/ui/fileTransferInstance/red.css new file mode 100644 index 000000000..13800e049 --- /dev/null +++ b/ui/fileTransferInstance/red.css @@ -0,0 +1,27 @@ +QFrame { + border-image: url(:/ui/fileTransferInstance/background_red.png); + border-left:25;padding-top:-30; + border-top:28; + border-right:25; padding-right:-28; + border-bottom:28;padding-bottom:-30; +} + +QLabel { + color:white; +} + +QPushButton { + margin:0; +} + +QProgressBar { + border: 2px solid black; + border-radius: 0px; + color: white; + background-color:white; +} + +QProgressBar::chunk { + background-color: black; + width: 20px; +} \ No newline at end of file diff --git a/ui/fileTransferInstance/yellow.css b/ui/fileTransferInstance/yellow.css new file mode 100644 index 000000000..f748c7975 --- /dev/null +++ b/ui/fileTransferInstance/yellow.css @@ -0,0 +1,27 @@ +QFrame { + border-image: url(:/ui/fileTransferInstance/background_yellow.png); + border-left:25;padding-top:-30; + border-top:28; + border-right:25; padding-right:-28; + border-bottom:28;padding-bottom:-30; +} + +QLabel { + color:black; +} + +QPushButton { + margin:0; +} + +QProgressBar { + border: 2px solid black; + border-radius: 0px; + color: white; + background-color:white; +} + +QProgressBar::chunk { + background-color: black; + width: 20px; +} \ No newline at end of file