Added open file feature for file status widget

* Added open file feature for file status widget
This commit is contained in:
defnax 2020-06-11 16:32:55 +02:00 committed by csoler
parent d1d977376d
commit 0b06515dfe
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
5 changed files with 81 additions and 13 deletions

View File

@ -18,6 +18,7 @@
* *
*******************************************************************************/
#include <QMenu>
#include <QTimer>
#include <QMessageBox>
#include <QFileInfo>
@ -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;
}
}

View File

@ -44,6 +44,7 @@ private slots:
void pause();
void resume();
void openFolder();
void openFile();
private:
void setSize(uint64_t size);

View File

@ -48,7 +48,7 @@
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="downloadToolButton">
<widget class="QPushButton" name="downloadPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -126,18 +126,31 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="openFolderToolButton">
<widget class="QPushButton" name="openFilePushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Play</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="openFolderToolButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Open folder</string>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
</widget>
</item>
@ -148,6 +161,7 @@
</widget>
<resources>
<include location="../images.qrc"/>
<include location="../icons.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -60,6 +60,7 @@
<file>icons/png/anonymous.png</file>
<file>icons/png/attach-image.png</file>
<file>icons/png/attach.png</file>
<file>icons/png/arrow.png</file>
<file>icons/png/cert.png</file>
<file>icons/png/channels-notify.png</file>
<file>icons/png/channels.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 935 B