From 92379b35344a439a133c192b1775458ca42fd94e Mon Sep 17 00:00:00 2001 From: defnax Date: Thu, 11 Jun 2020 16:32:55 +0200 Subject: [PATCH] Added open file feature for file status widget * Added open file feature for file status widget --- .../GxsChannelFilesStatusWidget.cpp | 70 +++++++++++++++--- .../gxschannels/GxsChannelFilesStatusWidget.h | 1 + .../GxsChannelFilesStatusWidget.ui | 22 +++++- retroshare-gui/src/gui/icons.qrc | 1 + retroshare-gui/src/gui/icons/png/arrow.png | Bin 0 -> 935 bytes 5 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 retroshare-gui/src/gui/icons/png/arrow.png diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.cpp index c28601fed..bc019e426 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.cpp @@ -18,6 +18,7 @@ * * *******************************************************************************/ +#include #include #include #include @@ -27,6 +28,8 @@ #include "GxsChannelFilesStatusWidget.h" #include "ui_GxsChannelFilesStatusWidget.h" #include "gui/common/RsUrlHandler.h" +#include "gui/common/FilesDefs.h" +#include "util/misc.h" #include "retroshare/rsfiles.h" @@ -40,11 +43,21 @@ GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsFile &file, setSize(mFile.mSize); /* Connect signals */ - connect(ui->downloadToolButton, SIGNAL(clicked()), this, SLOT(download())); + connect(ui->downloadPushButton, SIGNAL(clicked()), this, SLOT(download())); connect(ui->resumeToolButton, SIGNAL(clicked()), this, SLOT(resume())); connect(ui->pauseToolButton, SIGNAL(clicked()), this, SLOT(pause())); connect(ui->cancelToolButton, SIGNAL(clicked()), this, SLOT(cancel())); - connect(ui->openFolderToolButton, SIGNAL(clicked()), this, SLOT(openFolder())); + connect(ui->openFilePushButton, SIGNAL(clicked()), this, SLOT(openFile())); + + ui->downloadPushButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/icons/png/download.png")); + ui->openFolderToolButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/icons/png/arrow.png")); + + QAction *openfolder = new QAction(tr("Open folder"), this); + connect(openfolder, SIGNAL(triggered()), this, SLOT(openFolder())); + + QMenu *menu = new QMenu(); + menu->addAction(openfolder); + ui->openFolderToolButton->setMenu(menu); check(); } @@ -80,6 +93,17 @@ void GxsChannelFilesStatusWidget::check() if (rsFiles->alreadyHaveFile(mFile.mHash, fileInfo)) { mState = STATE_LOCAL; setSize(fileInfo.size); + + /* check if the file is a media file */ + if (!misc::isPreviewable(QFileInfo(QString::fromUtf8(fileInfo.path.c_str())).suffix())) + { + /* check if the file is not a media file and change text */ + ui->openFilePushButton->setText(tr("Open file")); + } else { + ui->openFilePushButton->setText(tr("Play")); + ui->openFilePushButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/icons/png/play.png")); + } + } else { FileInfo fileInfo; bool detailsOk = rsFiles->FileDetails(mFile.mHash, RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_SPEC_ONLY, fileInfo); @@ -126,11 +150,12 @@ void GxsChannelFilesStatusWidget::check() case STATE_ERROR: repeat = 0; - ui->downloadToolButton->hide(); + ui->downloadPushButton->hide(); ui->resumeToolButton->hide(); ui->pauseToolButton->hide(); ui->cancelToolButton->hide(); ui->progressBar->hide(); + ui->openFilePushButton->hide(); ui->openFolderToolButton->hide(); statusText = tr("Error"); @@ -140,11 +165,12 @@ void GxsChannelFilesStatusWidget::check() case STATE_REMOTE: repeat = 30000; - ui->downloadToolButton->show(); + ui->downloadPushButton->show(); ui->resumeToolButton->hide(); ui->pauseToolButton->hide(); ui->cancelToolButton->hide(); ui->progressBar->hide(); + ui->openFilePushButton->hide(); ui->openFolderToolButton->hide(); break; @@ -152,11 +178,12 @@ void GxsChannelFilesStatusWidget::check() case STATE_DOWNLOAD: repeat = 1000; - ui->downloadToolButton->hide(); + ui->downloadPushButton->hide(); ui->resumeToolButton->hide(); ui->pauseToolButton->show(); ui->cancelToolButton->show(); ui->progressBar->show(); + ui->openFilePushButton->hide(); ui->openFolderToolButton->hide(); break; @@ -164,11 +191,12 @@ void GxsChannelFilesStatusWidget::check() case STATE_PAUSED: repeat = 1000; - ui->downloadToolButton->hide(); + ui->downloadPushButton->hide(); ui->resumeToolButton->show(); ui->pauseToolButton->hide(); ui->cancelToolButton->show(); ui->progressBar->hide(); + ui->openFilePushButton->hide(); ui->openFolderToolButton->hide(); statusText = tr("Paused"); @@ -178,11 +206,12 @@ void GxsChannelFilesStatusWidget::check() case STATE_WAITING: repeat = 1000; - ui->downloadToolButton->hide(); + ui->downloadPushButton->hide(); ui->resumeToolButton->hide(); ui->pauseToolButton->show(); ui->cancelToolButton->show(); ui->progressBar->hide(); + ui->openFilePushButton->hide(); ui->openFolderToolButton->hide(); statusText = tr("Waiting"); @@ -192,11 +221,12 @@ void GxsChannelFilesStatusWidget::check() case STATE_CHECKING: repeat = 1000; - ui->downloadToolButton->hide(); + ui->downloadPushButton->hide(); ui->resumeToolButton->hide(); ui->pauseToolButton->hide(); ui->cancelToolButton->show(); ui->progressBar->hide(); + ui->openFilePushButton->hide(); ui->openFolderToolButton->hide(); statusText = tr("Checking"); @@ -206,11 +236,12 @@ void GxsChannelFilesStatusWidget::check() case STATE_LOCAL: repeat = 60000; - ui->downloadToolButton->hide(); + ui->downloadPushButton->hide(); ui->resumeToolButton->hide(); ui->pauseToolButton->hide(); ui->cancelToolButton->hide(); ui->progressBar->hide(); + ui->openFilePushButton->show(); ui->openFolderToolButton->show(); break; @@ -296,3 +327,24 @@ void GxsChannelFilesStatusWidget::openFolder() } } } + +void GxsChannelFilesStatusWidget::openFile() +{ + FileInfo fileInfo; + if (!rsFiles->alreadyHaveFile(mFile.mHash, fileInfo)) { + return; + } + + /* open file with a suitable application */ + QFileInfo qinfo; + qinfo.setFile(QString::fromUtf8(fileInfo.path.c_str())); + if (qinfo.exists()) { + if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) { + std::cerr << "GxsChannelFilesStatusWidget(): can't open file " << fileInfo.path << std::endl; + } + }else{ + QMessageBox::information(this, tr("Play File"), + tr("File %1 does not exist at location.").arg(fileInfo.path.c_str())); + return; + } +} diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.h b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.h index 3d58cc4d7..1effe0549 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.h @@ -44,6 +44,7 @@ private slots: void pause(); void resume(); void openFolder(); + void openFile(); private: void setSize(uint64_t size); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.ui index 39e32271d..c1b02ab83 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.ui @@ -48,7 +48,7 @@ 2 - + 0 @@ -126,18 +126,31 @@ - + 0 0 + + Play + + + + + + + + 0 + 0 + + Qt::NoFocus - - Open folder + + QToolButton::InstantPopup @@ -148,6 +161,7 @@ + diff --git a/retroshare-gui/src/gui/icons.qrc b/retroshare-gui/src/gui/icons.qrc index 6e4bd7569..656cdc7fd 100644 --- a/retroshare-gui/src/gui/icons.qrc +++ b/retroshare-gui/src/gui/icons.qrc @@ -60,6 +60,7 @@ icons/png/anonymous.png icons/png/attach-image.png icons/png/attach.png + icons/png/arrow.png icons/png/cert.png icons/png/channels-notify.png icons/png/channels.png diff --git a/retroshare-gui/src/gui/icons/png/arrow.png b/retroshare-gui/src/gui/icons/png/arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..e238538026d1e88b3f373287ead27e503f5c161d GIT binary patch literal 935 zcmeAS@N?(olHy`uVBq!ia0vp^4Is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