1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

more work on filetransferwidget

This commit is contained in:
krepa098 2014-11-17 20:08:55 +01:00
parent 27cb075dbb
commit 3a567d962e
9 changed files with 196 additions and 39 deletions

View File

@ -21,6 +21,10 @@
#include "src/misc/style.h" #include "src/misc/style.h"
#include <QMouseEvent> #include <QMouseEvent>
#include <QFileDialog>
#include <QDir>
#include <QFileInfo>
#include <QMessageBox>
#include <QDebug> #include <QDebug>
FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file) FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
@ -31,6 +35,10 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
{ {
ui->setupUi(this); 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->filenameLabel->setText(file.fileName);
ui->progressBar->setValue(0); ui->progressBar->setValue(0);
ui->fileSizeLabel->setText(getHumanReadableSize(file.filesize)); ui->fileSizeLabel->setText(getHumanReadableSize(file.filesize));
@ -48,6 +56,10 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
setupButtons(); setupButtons();
//preview
if(fileInfo.direction == ToxFile::SENDING)
showPreview(fileInfo.filePath);
setFixedHeight(85); setFixedHeight(85);
} }
@ -123,7 +135,7 @@ void FileTransferWidget::onFileTransferCancelled(ToxFile file)
setupButtons(); setupButtons();
hideWidgets(); hideWidgets();
disconnect(Core::getInstance()); disconnect(Core::getInstance(), 0, this, 0);
} }
void FileTransferWidget::onFileTransferPaused(ToxFile file) void FileTransferWidget::onFileTransferPaused(ToxFile file)
@ -152,7 +164,11 @@ void FileTransferWidget::onFileTransferFinished(ToxFile file)
setupButtons(); setupButtons();
hideWidgets(); hideWidgets();
disconnect(Core::getInstance()); // preview
if(fileInfo.direction == ToxFile::RECEIVING)
showPreview(fileInfo.filePath);
disconnect(Core::getInstance(), 0, this, 0);
} }
QString FileTransferWidget::getHumanReadableSize(qint64 size) QString FileTransferWidget::getHumanReadableSize(qint64 size)
@ -194,6 +210,19 @@ void FileTransferWidget::setupButtons()
break; break;
case ToxFile::STOPPED: case ToxFile::STOPPED:
case ToxFile::BROKEN: //TODO: ? 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; break;
} }
} }
@ -217,9 +246,33 @@ void FileTransferWidget::handleButton(QPushButton *btn)
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum); Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "resume") if(btn->objectName() == "resume")
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum); 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() void FileTransferWidget::on_topButton_clicked()
{ {
handleButton(ui->topButton); handleButton(ui->topButton);

View File

@ -48,6 +48,7 @@ protected:
void hideWidgets(); void hideWidgets();
void setupButtons(); void setupButtons();
void handleButton(QPushButton* btn); void handleButton(QPushButton* btn);
void showPreview(const QString& filename);
private slots: private slots:
void on_topButton_clicked(); void on_topButton_clicked();

View File

@ -13,12 +13,7 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<property name="styleSheet"> <layout class="QHBoxLayout" name="mainHorizontalLayout">
<string notr="true">#FileTransferWidget {
background-color:transparent;
}</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<widget class="QFrame" name="frame_3"> <widget class="QFrame" name="frame_3">
<property name="sizePolicy"> <property name="sizePolicy">
@ -40,6 +35,31 @@
<number>0</number> <number>0</number>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="previewLabel">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>[preview]</string>
</property>
</widget>
</item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="topMargin"> <property name="topMargin">

View File

@ -14,7 +14,7 @@ ToxFile::ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePat
bool ToxFile::operator==(const ToxFile &other) const 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 bool ToxFile::operator!=(const ToxFile &other) const

View File

@ -164,19 +164,6 @@ void ChatForm::startFileSend(ToxFile file)
if (file.friendId != f->getFriendID()) if (file.friendId != f->getFriendID())
return; 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; QString name;
if (!previousId.isMine()) if (!previousId.isMine())
{ {
@ -194,17 +181,6 @@ void ChatForm::onFileRecvRequest(ToxFile file)
if (file.friendId != f->getFriendID()) if (file.friendId != f->getFriendID())
return; 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(); Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow()) if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
{ {
@ -221,12 +197,11 @@ void ChatForm::onFileRecvRequest(ToxFile file)
previousId = friendId; previousId = friendId;
} }
//TODO: chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name), chatWidget->addFileTransferMessage(name, file, QDateTime::currentDateTime(), false);
// QTime::currentTime().toString("hh:mm"), false))); //TODO:
// if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty()
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty() // || Settings::getInstance().getAutoSaveEnabled())
|| Settings::getInstance().getAutoSaveEnabled()) // fileTrans->pressFromHtml("btnB");
fileTrans->pressFromHtml("btnB");
} }
void ChatForm::onAvInvite(int FriendId, int CallId, bool video) void ChatForm::onAvInvite(int FriendId, int CallId, bool video)

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}