mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-23 22:01:05 -05:00
Added open file feature for file status widget
* Added open file feature for file status widget
This commit is contained in:
parent
ebbdc082c0
commit
92379b3534
@ -18,6 +18,7 @@
|
|||||||
* *
|
* *
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <QMenu>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@ -27,6 +28,8 @@
|
|||||||
#include "GxsChannelFilesStatusWidget.h"
|
#include "GxsChannelFilesStatusWidget.h"
|
||||||
#include "ui_GxsChannelFilesStatusWidget.h"
|
#include "ui_GxsChannelFilesStatusWidget.h"
|
||||||
#include "gui/common/RsUrlHandler.h"
|
#include "gui/common/RsUrlHandler.h"
|
||||||
|
#include "gui/common/FilesDefs.h"
|
||||||
|
#include "util/misc.h"
|
||||||
|
|
||||||
#include "retroshare/rsfiles.h"
|
#include "retroshare/rsfiles.h"
|
||||||
|
|
||||||
@ -40,11 +43,21 @@ GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsFile &file,
|
|||||||
setSize(mFile.mSize);
|
setSize(mFile.mSize);
|
||||||
|
|
||||||
/* Connect signals */
|
/* 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->resumeToolButton, SIGNAL(clicked()), this, SLOT(resume()));
|
||||||
connect(ui->pauseToolButton, SIGNAL(clicked()), this, SLOT(pause()));
|
connect(ui->pauseToolButton, SIGNAL(clicked()), this, SLOT(pause()));
|
||||||
connect(ui->cancelToolButton, SIGNAL(clicked()), this, SLOT(cancel()));
|
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();
|
check();
|
||||||
}
|
}
|
||||||
@ -80,6 +93,17 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
if (rsFiles->alreadyHaveFile(mFile.mHash, fileInfo)) {
|
if (rsFiles->alreadyHaveFile(mFile.mHash, fileInfo)) {
|
||||||
mState = STATE_LOCAL;
|
mState = STATE_LOCAL;
|
||||||
setSize(fileInfo.size);
|
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 {
|
} else {
|
||||||
FileInfo fileInfo;
|
FileInfo fileInfo;
|
||||||
bool detailsOk = rsFiles->FileDetails(mFile.mHash, RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_SPEC_ONLY, 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:
|
case STATE_ERROR:
|
||||||
repeat = 0;
|
repeat = 0;
|
||||||
|
|
||||||
ui->downloadToolButton->hide();
|
ui->downloadPushButton->hide();
|
||||||
ui->resumeToolButton->hide();
|
ui->resumeToolButton->hide();
|
||||||
ui->pauseToolButton->hide();
|
ui->pauseToolButton->hide();
|
||||||
ui->cancelToolButton->hide();
|
ui->cancelToolButton->hide();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderToolButton->hide();
|
||||||
|
|
||||||
statusText = tr("Error");
|
statusText = tr("Error");
|
||||||
@ -140,11 +165,12 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
case STATE_REMOTE:
|
case STATE_REMOTE:
|
||||||
repeat = 30000;
|
repeat = 30000;
|
||||||
|
|
||||||
ui->downloadToolButton->show();
|
ui->downloadPushButton->show();
|
||||||
ui->resumeToolButton->hide();
|
ui->resumeToolButton->hide();
|
||||||
ui->pauseToolButton->hide();
|
ui->pauseToolButton->hide();
|
||||||
ui->cancelToolButton->hide();
|
ui->cancelToolButton->hide();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderToolButton->hide();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -152,11 +178,12 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
case STATE_DOWNLOAD:
|
case STATE_DOWNLOAD:
|
||||||
repeat = 1000;
|
repeat = 1000;
|
||||||
|
|
||||||
ui->downloadToolButton->hide();
|
ui->downloadPushButton->hide();
|
||||||
ui->resumeToolButton->hide();
|
ui->resumeToolButton->hide();
|
||||||
ui->pauseToolButton->show();
|
ui->pauseToolButton->show();
|
||||||
ui->cancelToolButton->show();
|
ui->cancelToolButton->show();
|
||||||
ui->progressBar->show();
|
ui->progressBar->show();
|
||||||
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderToolButton->hide();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -164,11 +191,12 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
case STATE_PAUSED:
|
case STATE_PAUSED:
|
||||||
repeat = 1000;
|
repeat = 1000;
|
||||||
|
|
||||||
ui->downloadToolButton->hide();
|
ui->downloadPushButton->hide();
|
||||||
ui->resumeToolButton->show();
|
ui->resumeToolButton->show();
|
||||||
ui->pauseToolButton->hide();
|
ui->pauseToolButton->hide();
|
||||||
ui->cancelToolButton->show();
|
ui->cancelToolButton->show();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderToolButton->hide();
|
||||||
|
|
||||||
statusText = tr("Paused");
|
statusText = tr("Paused");
|
||||||
@ -178,11 +206,12 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
case STATE_WAITING:
|
case STATE_WAITING:
|
||||||
repeat = 1000;
|
repeat = 1000;
|
||||||
|
|
||||||
ui->downloadToolButton->hide();
|
ui->downloadPushButton->hide();
|
||||||
ui->resumeToolButton->hide();
|
ui->resumeToolButton->hide();
|
||||||
ui->pauseToolButton->show();
|
ui->pauseToolButton->show();
|
||||||
ui->cancelToolButton->show();
|
ui->cancelToolButton->show();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderToolButton->hide();
|
||||||
|
|
||||||
statusText = tr("Waiting");
|
statusText = tr("Waiting");
|
||||||
@ -192,11 +221,12 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
case STATE_CHECKING:
|
case STATE_CHECKING:
|
||||||
repeat = 1000;
|
repeat = 1000;
|
||||||
|
|
||||||
ui->downloadToolButton->hide();
|
ui->downloadPushButton->hide();
|
||||||
ui->resumeToolButton->hide();
|
ui->resumeToolButton->hide();
|
||||||
ui->pauseToolButton->hide();
|
ui->pauseToolButton->hide();
|
||||||
ui->cancelToolButton->show();
|
ui->cancelToolButton->show();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderToolButton->hide();
|
||||||
|
|
||||||
statusText = tr("Checking");
|
statusText = tr("Checking");
|
||||||
@ -206,11 +236,12 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
case STATE_LOCAL:
|
case STATE_LOCAL:
|
||||||
repeat = 60000;
|
repeat = 60000;
|
||||||
|
|
||||||
ui->downloadToolButton->hide();
|
ui->downloadPushButton->hide();
|
||||||
ui->resumeToolButton->hide();
|
ui->resumeToolButton->hide();
|
||||||
ui->pauseToolButton->hide();
|
ui->pauseToolButton->hide();
|
||||||
ui->cancelToolButton->hide();
|
ui->cancelToolButton->hide();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
|
ui->openFilePushButton->show();
|
||||||
ui->openFolderToolButton->show();
|
ui->openFolderToolButton->show();
|
||||||
|
|
||||||
break;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -44,6 +44,7 @@ private slots:
|
|||||||
void pause();
|
void pause();
|
||||||
void resume();
|
void resume();
|
||||||
void openFolder();
|
void openFolder();
|
||||||
|
void openFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setSize(uint64_t size);
|
void setSize(uint64_t size);
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
<number>2</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="downloadToolButton">
|
<widget class="QPushButton" name="downloadPushButton">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -126,18 +126,31 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="openFolderToolButton">
|
<widget class="QPushButton" name="openFilePushButton">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</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">
|
<property name="focusPolicy">
|
||||||
<enum>Qt::NoFocus</enum>
|
<enum>Qt::NoFocus</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="popupMode">
|
||||||
<string>Open folder</string>
|
<enum>QToolButton::InstantPopup</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -148,6 +161,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../images.qrc"/>
|
<include location="../images.qrc"/>
|
||||||
|
<include location="../icons.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -60,6 +60,7 @@
|
|||||||
<file>icons/png/anonymous.png</file>
|
<file>icons/png/anonymous.png</file>
|
||||||
<file>icons/png/attach-image.png</file>
|
<file>icons/png/attach-image.png</file>
|
||||||
<file>icons/png/attach.png</file>
|
<file>icons/png/attach.png</file>
|
||||||
|
<file>icons/png/arrow.png</file>
|
||||||
<file>icons/png/cert.png</file>
|
<file>icons/png/cert.png</file>
|
||||||
<file>icons/png/channels-notify.png</file>
|
<file>icons/png/channels-notify.png</file>
|
||||||
<file>icons/png/channels.png</file>
|
<file>icons/png/channels.png</file>
|
||||||
|
BIN
retroshare-gui/src/gui/icons/png/arrow.png
Normal file
BIN
retroshare-gui/src/gui/icons/png/arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 935 B |
Loading…
Reference in New Issue
Block a user