open or preview downloading files with a suitable application

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1317 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
alexandrut 2009-07-04 21:54:58 +00:00
parent b0deb297a9
commit 8ab5cf4f3e
2 changed files with 63 additions and 44 deletions

View File

@ -54,7 +54,7 @@
#define IMAGE_OPENFOLDER ":/images/folderopen.png" #define IMAGE_OPENFOLDER ":/images/folderopen.png"
#define IMAGE_OPENFILE ":/images/fileopen.png" #define IMAGE_OPENFILE ":/images/fileopen.png"
#define IMAGE_STOP ":/images/stop.png" #define IMAGE_STOP ":/images/stop.png"
#define IMAGE_OPENPREVIEW ":/images/player_play.png"
/** Constructor */ /** Constructor */
TransfersDialog::TransfersDialog(QWidget *parent) TransfersDialog::TransfersDialog(QWidget *parent)
@ -203,7 +203,7 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
playAct = new QAction(QIcon(IMAGE_PLAY), tr( "Play" ), this ); playAct = new QAction(QIcon(IMAGE_PLAY), tr( "Play" ), this );
connect( playAct , SIGNAL( triggered() ), this, SLOT( playSelectedTransfer() ) ); connect( playAct , SIGNAL( triggered() ), this, SLOT( playSelectedTransfer() ) );
} }
pauseAct = new QAction(QIcon(IMAGE_PAUSE), tr("Pause"), this); pauseAct = new QAction(QIcon(IMAGE_PAUSE), tr("Pause"), this);
connect(pauseAct, SIGNAL(triggered()), this, SLOT(pauseFileTransfer())); connect(pauseAct, SIGNAL(triggered()), this, SLOT(pauseFileTransfer()));
@ -212,10 +212,13 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
cancelAct = new QAction(QIcon(IMAGE_CANCEL), tr( "Cancel" ), this ); cancelAct = new QAction(QIcon(IMAGE_CANCEL), tr( "Cancel" ), this );
connect( cancelAct , SIGNAL( triggered() ), this, SLOT( cancel() ) ); connect( cancelAct , SIGNAL( triggered() ), this, SLOT( cancel() ) );
openfolderAct = new QAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this); openfolderAct = new QAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this);
connect(openfolderAct, SIGNAL(triggered()), this, SLOT(openFolderTransfer())); connect(openfolderAct, SIGNAL(triggered()), this, SLOT(openFolderTransfer()));
openpreviewAct = new QAction(QIcon(IMAGE_OPENPREVIEW), tr("Open or Preview File"), this);
connect(openpreviewAct, SIGNAL(triggered()), this, SLOT(openOrPreviewTransfer()));
clearcompletedAct = new QAction(QIcon(IMAGE_CLEARCOMPLETED), tr( "Clear Completed" ), this ); clearcompletedAct = new QAction(QIcon(IMAGE_CLEARCOMPLETED), tr( "Clear Completed" ), this );
connect( clearcompletedAct , SIGNAL( triggered() ), this, SLOT( clearcompleted() ) ); connect( clearcompletedAct , SIGNAL( triggered() ), this, SLOT( clearcompleted() ) );
@ -246,6 +249,7 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
contextMnu.addAction( cancelAct); contextMnu.addAction( cancelAct);
contextMnu.addSeparator(); contextMnu.addSeparator();
contextMnu.addAction( openfolderAct); contextMnu.addAction( openfolderAct);
contextMnu.addAction( openpreviewAct);
contextMnu.addSeparator(); contextMnu.addSeparator();
contextMnu.addAction( clearcompletedAct); contextMnu.addAction( clearcompletedAct);
contextMnu.addSeparator(); contextMnu.addSeparator();
@ -886,12 +890,10 @@ void TransfersDialog::pasteLink()
} }
} }
void TransfersDialog::getIdOfSelectedItems(QList<QStandardItem *>& items)
bool TransfersDialog::controlTransferFile(uint32_t flags)
{ {
bool result = false; items.clear();
/* scan selected transfer files or it's peers */
int i, imax = DLListModel->rowCount(); int i, imax = DLListModel->rowCount();
for (i = 0; i < imax; i++) { for (i = 0; i < imax; i++) {
bool isParentSelected = false; bool isParentSelected = false;
@ -917,9 +919,21 @@ bool TransfersDialog::controlTransferFile(uint32_t flags)
/* if transfered file or it's peers are selected control it*/ /* if transfered file or it's peers are selected control it*/
if (isParentSelected || isChildSelected) { if (isParentSelected || isChildSelected) {
QStandardItem *id = DLListModel->item(i, ID); QStandardItem *id = DLListModel->item(i, ID);
result = rsFiles->FileControl(id->data(Qt::DisplayRole).toString().toStdString(), flags); items.append(id);
} }
} }
}
bool TransfersDialog::controlTransferFile(uint32_t flags)
{
bool result = true;
QList<QStandardItem *> items;
QList<QStandardItem *>::iterator it;
getIdOfSelectedItems(items);
for (it = items.begin(); it != items.end(); it ++) {
result &= rsFiles->FileControl((*it)->data(Qt::DisplayRole).toString().toStdString(), flags);
}
return result; return result;
} }
@ -940,49 +954,50 @@ void TransfersDialog::resumeFileTransfer()
} }
} }
void TransfersDialog::openFolderTransfer() void TransfersDialog::openTransfer(bool isFolder)
{ {
FileInfo info; FileInfo info;
/* scan selected transfer files or it's peers */ QList<QStandardItem *> items;
int i, imax = DLListModel->rowCount(); QList<QStandardItem *>::iterator it;
for (i = 0; i < imax; i++) { getIdOfSelectedItems(items);
bool isParentSelected = false; for (it = items.begin(); it != items.end(); it ++) {
bool isChildSelected = false; if (!rsFiles->FileDetails((*it)->data(Qt::DisplayRole).toString().toStdString(), RS_FILE_HINTS_DOWNLOAD, info)) continue;
break;
}
QStandardItem *parent = DLListModel->item(i); /* make path for downloaded or downloading files */
if (!parent) continue; QFileInfo qinfo;
QModelIndex pindex = parent->index(); std::string path;
if (selection->isSelected(pindex)) { if (info.downloadStatus == FT_STATE_COMPLETE) {
isParentSelected = true; path = rsFiles->getDownloadDirectory();
} else { if (!isFolder) {
int j, jmax = parent->rowCount(); path = path + "/" + info.fname;
for (j = 0; j < jmax && !isChildSelected; j++) {
QStandardItem *child = parent->child(j);
if (!child) continue;
QModelIndex cindex = child->index();
if (selection->isSelected(cindex)) {
isChildSelected = true;
}
}
} }
} else {
/* retain file info for first file which is selected or has selected peers */ path = rsFiles->getPartialsDirectory();
if (isParentSelected || isChildSelected) { if (!isFolder) {
QStandardItem *id = DLListModel->item(i, ID); path = path + "/" + info.hash;
if (!rsFiles->FileDetails(id->data(Qt::DisplayRole).toString().toStdString(), RS_FILE_HINTS_DOWNLOAD, info)) continue;
break;
} }
} }
QList<QUrl> directories; /* open or preview them with a suitable application */
directories << QUrl::fromLocalFile(QString(rsFiles->getPartialsDirectory().c_str())); qinfo.setFile(path.c_str());
directories << QUrl::fromLocalFile(QString(rsFiles->getDownloadDirectory().c_str())); if (qinfo.exists()) {
QFileDialog dialog; if (!QDesktopServices::openUrl(QUrl::fromLocalFile(qinfo.absoluteFilePath()))) {
dialog.setSidebarUrls(directories); std::cerr << "openTransfer(): can't open file " << path << std::endl;
dialog.setFileMode(QFileDialog::AnyFile); }
dialog.setDirectory(QString(info.path.c_str())); }
dialog.exec(); }
void TransfersDialog::openFolderTransfer()
{
openTransfer(true);
}
void TransfersDialog::openOrPreviewTransfer()
{
openTransfer(false);
} }
void TransfersDialog::clearcompleted() void TransfersDialog::clearcompleted()

View File

@ -73,6 +73,7 @@ class TransfersDialog : public MainPage
void pauseFileTransfer(); void pauseFileTransfer();
void resumeFileTransfer(); void resumeFileTransfer();
void openFolderTransfer(); void openFolderTransfer();
void openOrPreviewTransfer();
signals: signals:
void playFiles(QStringList files); void playFiles(QStringList files);
@ -108,8 +109,11 @@ class TransfersDialog : public MainPage
QAction *pauseAct; QAction *pauseAct;
QAction *resumeAct; QAction *resumeAct;
QAction *openfolderAct; QAction *openfolderAct;
QAction *openpreviewAct;
void getIdOfSelectedItems(QList<QStandardItem *>& items);
bool controlTransferFile(uint32_t flags); bool controlTransferFile(uint32_t flags);
void openTransfer(bool isFolder);
QTreeView *downloadList; QTreeView *downloadList;