mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 23:49:35 -05:00
fixed open file / open dir in channel/post/files
This commit is contained in:
parent
df68d03953
commit
fe8c81e84a
@ -50,15 +50,12 @@ GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsFile &file,
|
|||||||
connect(ui->openFilePushButton, SIGNAL(clicked()), this, SLOT(openFile()));
|
connect(ui->openFilePushButton, SIGNAL(clicked()), this, SLOT(openFile()));
|
||||||
|
|
||||||
ui->downloadPushButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/icons/png/download.png"));
|
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);
|
ui->openFolderPushButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/images/folderopen.png"));
|
||||||
connect(openfolder, SIGNAL(triggered()), this, SLOT(openFolder()));
|
ui->openFolderPushButton->setToolTip(tr("Open folder"));
|
||||||
|
|
||||||
|
connect(ui->openFolderPushButton, SIGNAL(clicked()), this, SLOT(openFolder()));
|
||||||
|
|
||||||
QMenu *menu = new QMenu();
|
|
||||||
menu->addAction(openfolder);
|
|
||||||
ui->openFolderToolButton->setMenu(menu);
|
|
||||||
|
|
||||||
check();
|
check();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,13 +88,7 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
{
|
{
|
||||||
FileInfo fileInfo;
|
FileInfo fileInfo;
|
||||||
|
|
||||||
bool already_has_file = rsFiles->alreadyHaveFile(mFile.mHash, fileInfo);
|
if(haveFile(fileInfo))
|
||||||
bool detailsOk = false;
|
|
||||||
|
|
||||||
if(!already_has_file)
|
|
||||||
detailsOk = rsFiles->FileDetails(mFile.mHash, RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_SPEC_ONLY, fileInfo);
|
|
||||||
|
|
||||||
if (already_has_file || (detailsOk && fileInfo.downloadStatus == FT_STATE_COMPLETE))
|
|
||||||
{
|
{
|
||||||
mState = STATE_LOCAL;
|
mState = STATE_LOCAL;
|
||||||
setSize(fileInfo.size);
|
setSize(fileInfo.size);
|
||||||
@ -112,7 +103,7 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
ui->openFilePushButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/icons/png/play.png"));
|
ui->openFilePushButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/icons/png/play.png"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (detailsOk)
|
else
|
||||||
{
|
{
|
||||||
switch (fileInfo.downloadStatus)
|
switch (fileInfo.downloadStatus)
|
||||||
{
|
{
|
||||||
@ -140,13 +131,11 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
case FT_STATE_CHECKING_HASH:
|
case FT_STATE_CHECKING_HASH:
|
||||||
mState = STATE_CHECKING;
|
mState = STATE_CHECKING;
|
||||||
break;
|
break;
|
||||||
case FT_STATE_FAILED:
|
default:
|
||||||
mState = STATE_ERROR;
|
mState = STATE_REMOTE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
mState = STATE_REMOTE;
|
|
||||||
|
|
||||||
int repeat = 0;
|
int repeat = 0;
|
||||||
QString statusText;
|
QString statusText;
|
||||||
@ -161,7 +150,7 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
ui->cancelToolButton->hide();
|
ui->cancelToolButton->hide();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
ui->openFilePushButton->hide();
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderPushButton->hide();
|
||||||
|
|
||||||
statusText = tr("Error");
|
statusText = tr("Error");
|
||||||
|
|
||||||
@ -176,7 +165,7 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
ui->cancelToolButton->hide();
|
ui->cancelToolButton->hide();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
ui->openFilePushButton->hide();
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderPushButton->hide();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -189,7 +178,7 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
ui->cancelToolButton->show();
|
ui->cancelToolButton->show();
|
||||||
ui->progressBar->show();
|
ui->progressBar->show();
|
||||||
ui->openFilePushButton->hide();
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderPushButton->hide();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -202,7 +191,7 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
ui->cancelToolButton->show();
|
ui->cancelToolButton->show();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
ui->openFilePushButton->hide();
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderPushButton->hide();
|
||||||
|
|
||||||
statusText = tr("Paused");
|
statusText = tr("Paused");
|
||||||
|
|
||||||
@ -217,7 +206,7 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
ui->cancelToolButton->show();
|
ui->cancelToolButton->show();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
ui->openFilePushButton->hide();
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderPushButton->hide();
|
||||||
|
|
||||||
statusText = tr("Waiting");
|
statusText = tr("Waiting");
|
||||||
|
|
||||||
@ -232,7 +221,7 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
ui->cancelToolButton->show();
|
ui->cancelToolButton->show();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
ui->openFilePushButton->hide();
|
ui->openFilePushButton->hide();
|
||||||
ui->openFolderToolButton->hide();
|
ui->openFolderPushButton->hide();
|
||||||
|
|
||||||
statusText = tr("Checking");
|
statusText = tr("Checking");
|
||||||
|
|
||||||
@ -247,7 +236,7 @@ void GxsChannelFilesStatusWidget::check()
|
|||||||
ui->cancelToolButton->hide();
|
ui->cancelToolButton->hide();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
ui->openFilePushButton->show();
|
ui->openFilePushButton->show();
|
||||||
ui->openFolderToolButton->show();
|
ui->openFolderPushButton->show();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -329,35 +318,60 @@ void GxsChannelFilesStatusWidget::cancel()
|
|||||||
void GxsChannelFilesStatusWidget::openFolder()
|
void GxsChannelFilesStatusWidget::openFolder()
|
||||||
{
|
{
|
||||||
FileInfo fileInfo;
|
FileInfo fileInfo;
|
||||||
if (!rsFiles->alreadyHaveFile(mFile.mHash, fileInfo)) {
|
if (!haveFile(fileInfo))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* open folder with a suitable application */
|
QFileInfo finfo;
|
||||||
QDir dir = QFileInfo(QString::fromUtf8(fileInfo.path.c_str())).absoluteDir();
|
finfo.setFile(QString::fromUtf8(fileInfo.path.c_str()));
|
||||||
if (dir.exists()) {
|
|
||||||
if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(dir.absolutePath()))) {
|
|
||||||
if(!mUsedAsEditor)
|
|
||||||
QMessageBox::warning(this, "", QString("%1 %2").arg(tr("Can't open folder"), dir.absolutePath()));
|
|
||||||
else
|
|
||||||
RsErr() << "Can't open folder " << dir.absolutePath().toStdString() ;
|
|
||||||
|
|
||||||
}
|
/* open folder with a suitable application */
|
||||||
}
|
if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(finfo.absolutePath()))) {
|
||||||
|
if(!mUsedAsEditor)
|
||||||
|
QMessageBox::warning(this, "", QString("%1 %2").arg(tr("Can't open folder"), finfo.absolutePath()));
|
||||||
|
else
|
||||||
|
RsErr() << "Can't open folder " << finfo.absolutePath().toStdString() ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GxsChannelFilesStatusWidget::haveFile(FileInfo& info)
|
||||||
|
{
|
||||||
|
bool already_has_file = rsFiles->alreadyHaveFile(mFile.mHash, info);
|
||||||
|
|
||||||
|
if(!already_has_file)
|
||||||
|
if(!(rsFiles->FileDetails(mFile.mHash, RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_SPEC_ONLY, info) && info.downloadStatus==FT_STATE_COMPLETE))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// We need the code below because FileDetails() returns fileInfo.path as the directory when the file in COMPLETE and
|
||||||
|
// as a full path when the file is shared. The former is inconsistent with the documentation in rstypes.h, but I'm not
|
||||||
|
// sure what are the implications of changing the code in libretroshare so that the full path is always returned.
|
||||||
|
|
||||||
|
QFileInfo finfo;
|
||||||
|
|
||||||
|
if(QDir(QString::fromUtf8(info.path.c_str())).exists())
|
||||||
|
finfo.setFile(QString::fromUtf8(info.path.c_str()),QString::fromUtf8(info.fname.c_str()));
|
||||||
|
else if(QFile(QString::fromUtf8(info.path.c_str())).exists())
|
||||||
|
finfo.setFile(QString::fromUtf8(info.path.c_str()));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RsErr() << "Cannot find file!" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
info.path = finfo.absoluteFilePath().toStdString();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxsChannelFilesStatusWidget::openFile()
|
void GxsChannelFilesStatusWidget::openFile()
|
||||||
{
|
{
|
||||||
FileInfo fileInfo;
|
FileInfo fileInfo;
|
||||||
if (!rsFiles->alreadyHaveFile(mFile.mHash, fileInfo)) {
|
if(!haveFile(fileInfo))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/* open file with a suitable application */
|
QFileInfo finfo;
|
||||||
QFileInfo qinfo;
|
finfo.setFile(QString::fromUtf8(fileInfo.path.c_str()));
|
||||||
qinfo.setFile(QString::fromUtf8(fileInfo.path.c_str()));
|
|
||||||
if (qinfo.exists()) {
|
if (finfo.exists()) {
|
||||||
if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) {
|
if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(finfo.absoluteFilePath()))) {
|
||||||
std::cerr << "GxsChannelFilesStatusWidget(): can't open file " << fileInfo.path << std::endl;
|
std::cerr << "GxsChannelFilesStatusWidget(): can't open file " << fileInfo.path << std::endl;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
@ -53,6 +53,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void setSize(uint64_t size);
|
void setSize(uint64_t size);
|
||||||
|
bool haveFile(FileInfo& info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum State
|
enum State
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>421</width>
|
<width>473</width>
|
||||||
<height>29</height>
|
<height>36</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -139,7 +139,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="openFolderToolButton">
|
<widget class="QToolButton" name="openFolderPushButton">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
Loading…
Reference in New Issue
Block a user