diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index 7ba890f6b..ed7514f55 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. ****************************************************************/ @@ -65,6 +65,8 @@ #define IMAGE_FRIEND ":/images/peers_16x16.png" #define IMAGE_PROGRESS ":/images/browse-looking.gif" #define IMAGE_COPYLINK ":/images/copyrslink.png" +#define IMAGE_OPENFOLDER ":/images/folderopen.png" +#define IMAGE_OPENFILE ":/images/fileopen.png" const QString Image_AddNewAssotiationForFile = ":/images/kcmsystem24.png"; @@ -75,7 +77,7 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); - + connect(ui.checkButton, SIGNAL(clicked()), this, SLOT(forceCheck())); @@ -93,10 +95,10 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent) /* - connect( ui.remoteDirTreeView, SIGNAL( itemExpanded( QTreeWidgetItem * ) ), + connect( ui.remoteDirTreeView, SIGNAL( itemExpanded( QTreeWidgetItem * ) ), this, SLOT( checkForLocalDirRequest( QTreeWidgetItem * ) ) ); - connect( ui.localDirTreeWidget, SIGNAL( itemExpanded( QTreeWidgetItem * ) ), + connect( ui.localDirTreeWidget, SIGNAL( itemExpanded( QTreeWidgetItem * ) ), this, SLOT( checkForRemoteDirRequest( QTreeWidgetItem * ) ) ); */ @@ -116,21 +118,21 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent) connect( ui.localDirTreeView, SIGNAL( expanded(const QModelIndex & ) ), localModel, SLOT( expanded(const QModelIndex & ) ) ); - + /* Set header resize modes and initial section sizes */ - QHeaderView * l_header = ui.localDirTreeView->header () ; + QHeaderView * l_header = ui.localDirTreeView->header () ; l_header->setResizeMode (0, QHeaderView::Interactive); l_header->setResizeMode (1, QHeaderView::Interactive); l_header->setResizeMode (2, QHeaderView::Interactive); l_header->setResizeMode (3, QHeaderView::Interactive); - + l_header->resizeSection ( 0, 490 ); l_header->resizeSection ( 1, 70 ); l_header->resizeSection ( 2, 60 ); l_header->resizeSection ( 3, 100 ); - + /* Set header resize modes and initial section sizes */ - QHeaderView * r_header = ui.remoteDirTreeView->header () ; + QHeaderView * r_header = ui.remoteDirTreeView->header () ; r_header->setResizeMode (0, QHeaderView::Interactive); r_header->setStretchLastSection(false); @@ -138,13 +140,13 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent) r_header->setResizeMode (1, QHeaderView::Fixed); r_header->setResizeMode (2, QHeaderView::Fixed); r_header->setResizeMode (3, QHeaderView::Fixed); - - + + r_header->resizeSection ( 0, 490 ); r_header->resizeSection ( 1, 70 ); r_header->resizeSection ( 2, 60 ); r_header->resizeSection ( 3, 100 ); - + l_header->setHighlightSections(false); r_header->setHighlightSections(false); @@ -196,19 +198,20 @@ void SharedFilesDialog::shareddirtreeviewCostumPopupMenu( QPoint point ) { QMenu contextMnu( this ); QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier ); - + downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), this ); connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ); - + copyremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), this ); connect( copyremotelinkAct , SIGNAL( triggered() ), this, SLOT( copyLinkRemote() ) ); sendremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), this ); connect( sendremotelinkAct , SIGNAL( triggered() ), this, SLOT( sendremoteLinkTo( ) ) ); - + + // addMsgAct = new QAction( tr( "Add to Message" ), this ); // connect( addMsgAct , SIGNAL( triggered() ), this, SLOT( addMsgRemoteSelected() ) ); - + contextMnu.clear(); contextMnu.addAction( downloadAct); @@ -425,7 +428,7 @@ void SharedFilesDialog::recommendFilesTo( std::string rsid ) /* create a message */ ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true); - /* fill it in + /* fill it in * files are receommended already * just need to set peers */ @@ -470,21 +473,21 @@ void SharedFilesDialog::openfile() { /* call back to the model (which does all the interfacing? */ - std::cerr << "Opening File"; - std::cerr << std::endl; - - QItemSelectionModel *qism = ui.localDirTreeView->selectionModel(); - model -> openSelected(qism->selectedIndexes()); + std::cerr << "SharedFilesDialog::openfile" << std::endl; + QModelIndexList qmil = ui.localDirTreeView->selectionModel()->selectedIndexes(); + localModel->openSelected(qmil, false); } void SharedFilesDialog::openfolder() { + std::cerr << "SharedFilesDialog::openfolder" << std::endl; + QModelIndexList qmil = ui.localDirTreeView->selectionModel()->selectedIndexes(); + localModel->openSelected(qmil, true); } - void SharedFilesDialog::preModDirectories(bool update_local) { std::cerr << "SharedFilesDialog::preModDirectories called with update_local = " << update_local << std::endl ; @@ -516,7 +519,7 @@ void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point ) RemoteDirModel::FileNameRole).toString(); QMenu contextMnu2( this ); - // + // QAction* menuAction = fileAssotiationAction(currentFile) ; //new QAction(QIcon(IMAGE_PLAY), currentFile, this); @@ -577,21 +580,29 @@ void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point ) } //#endif - + copylinklocalAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), this ); connect( copylinklocalAct , SIGNAL( triggered() ), this, SLOT( copyLinkLocal() ) ); sendlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), this ); connect( sendlinkAct , SIGNAL( triggered() ), this, SLOT( sendLinkTo( /*std::string rsid*/ ) ) ); + openfileAct = new QAction(QIcon(IMAGE_OPENFILE), tr("Open File"), this); + connect(openfileAct, SIGNAL(triggered()), this, SLOT(openfile())); - contextMnu2.addAction( menuAction ); - //contextMnu2.addAction( openfileAct); - contextMnu2.addAction( copylinklocalAct); - contextMnu2.addAction( sendlinkAct); - contextMnu2.addSeparator(); - contextMnu2.addMenu( recMenu); - contextMnu2.addMenu( msgMenu); + openfolderAct = new QAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this); + connect(openfolderAct, SIGNAL(triggered()), this, SLOT(openfolder())); + + + contextMnu2.addAction( menuAction ); + contextMnu2.addAction( copylinklocalAct); + contextMnu2.addAction( sendlinkAct); + contextMnu2.addSeparator(); + contextMnu2.addAction( openfileAct); + contextMnu2.addAction( openfolderAct); + contextMnu2.addSeparator(); + contextMnu2.addMenu( recMenu); + contextMnu2.addMenu( msgMenu); QMouseEvent *mevent2 = new QMouseEvent( QEvent::MouseButtonPress, point, @@ -643,7 +654,7 @@ SharedFilesDialog::runCommandForFile() tsl.append( currentFile ); QProcess::execute( currentCommand, tsl); //QString("%1 %2").arg(currentCommand).arg(currentFile) ); - + // QString tmess = "Some command(%1) should be executed here for file %2"; // tmess = tmess.arg(currentCommand).arg(currentFile); // QMessageBox::warning(this, tr("RetroShare"), tmess, QMessageBox::Ok); @@ -666,10 +677,10 @@ SharedFilesDialog::tryToAddNewAssotiation() //QSettings settings( qApp->applicationDirPath()+"/sett.ini", // QSettings::IniFormat); settings->beginGroup("FileAssotiations"); - + QString currType = afad.resultFileType() ; QString currCmd = afad.resultCommand() ; - + settings->setValue(currType, currCmd); } } @@ -677,7 +688,7 @@ SharedFilesDialog::tryToAddNewAssotiation() //============================================================================ /** Toggles the Lokal TreeView on and off, changes toggle button text - + void SharedFilesDialog::showFrame(bool show) { if (show) { diff --git a/retroshare-gui/src/rsiface/RemoteDirModel.cpp b/retroshare-gui/src/rsiface/RemoteDirModel.cpp index a5967b6d5..6cde34ff2 100644 --- a/retroshare-gui/src/rsiface/RemoteDirModel.cpp +++ b/retroshare-gui/src/rsiface/RemoteDirModel.cpp @@ -69,8 +69,8 @@ void RemoteDirModel::treeStyle() #endif return false; } - - if (details.type == DIR_TYPE_FILE) + + if (details.type == DIR_TYPE_FILE) { #ifdef RDM_DEBUG std::cerr << "lookup FILE -> false"; @@ -123,7 +123,7 @@ void RemoteDirModel::treeStyle() #endif return 0; } - + /* else PERSON/DIR*/ #ifdef RDM_DEBUG std::cerr << "lookup PER/DIR #" << details.count; @@ -151,7 +151,7 @@ void RemoteDirModel::treeStyle() /* get the data from the index */ void *ref = index.internalPointer(); - int coln = index.column(); + int coln = index.column(); DirDetails details; uint32_t flags = DIR_FLAGS_DETAILS; @@ -175,8 +175,8 @@ void RemoteDirModel::treeStyle() r = 200 + r * 5; /* 0->250 */ /*** age: log2(age) *** - * 1 hour = 3,600 - 250 - * 1 day = 86,400 - 200 + * 1 hour = 3,600 - 250 + * 1 day = 86,400 - 200 * 1 week = 604,800 - 100 * 1 month = 2,419,200 - 50 * @@ -245,10 +245,10 @@ void RemoteDirModel::treeStyle() { FileInfo finfo; rsFiles->FileDetails(details.hash, 0, finfo); - + return QString::fromStdString(finfo.path) ; } - + if (role == Qt::DecorationRole) { @@ -257,12 +257,12 @@ void RemoteDirModel::treeStyle() switch(coln) { case 0: - return (QIcon(peerIcon)); + return (QIcon(peerIcon)); break; } } else if (details.type == DIR_TYPE_DIR) - { + { switch(coln) { case 0: @@ -274,7 +274,7 @@ void RemoteDirModel::treeStyle() } else { - return(QIcon(categoryIcon)); + return(QIcon(categoryIcon)); } break; } @@ -372,7 +372,7 @@ void RemoteDirModel::treeStyle() if (role == Qt::DisplayRole) { - /* + /* * Person: name, id, 0, 0; * File : name, size, rank, (0) ts * Dir : name, (0) count, (0) path, (0) ts @@ -464,7 +464,7 @@ void RemoteDirModel::treeStyle() { return int( Qt::AlignLeft | Qt::AlignVCenter); } - + } return QVariant(); @@ -519,7 +519,7 @@ void RemoteDirModel::treeStyle() return QString("Row %1").arg(section); } - QModelIndex RemoteDirModel::index(int row, int column, + QModelIndex RemoteDirModel::index(int row, int column, const QModelIndex & parent) const { #ifdef RDM_DEBUG @@ -528,7 +528,7 @@ void RemoteDirModel::treeStyle() #endif void *ref = NULL; - + if (parent.isValid()) { ref = parent.internalPointer(); @@ -557,7 +557,7 @@ void RemoteDirModel::treeStyle() return QModelIndex(); } - /* now iterate through the details to + /* now iterate through the details to * get the reference number */ @@ -566,13 +566,13 @@ void RemoteDirModel::treeStyle() for(it = details.children.begin(); ((i < row) && (it != details.children.end())); it++, i++) ; - if (it == details.children.end()) - { + if (it == details.children.end()) + { #ifdef RDM_DEBUG std::cerr << "wrong number of children -> invalid"; std::cerr << std::endl; #endif - return QModelIndex(); + return QModelIndex(); } #ifdef RDM_DEBUG @@ -668,7 +668,7 @@ void RemoteDirModel::treeStyle() } else if (details.type == DIR_TYPE_DIR) { - return ( Qt::ItemIsSelectable | + return ( Qt::ItemIsSelectable | Qt::ItemIsEnabled); // Qt::ItemIsDragEnabled | @@ -677,7 +677,7 @@ void RemoteDirModel::treeStyle() } else // (details.type == DIR_TYPE_FILE) { - return ( Qt::ItemIsSelectable | + return ( Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled); @@ -734,7 +734,7 @@ void RemoteDirModel::downloadSelected(QModelIndexList list) #endif } - /* so for all the selected .... get the name out, + /* so for all the selected .... get the name out, * make it into something the RsControl can understand */ @@ -822,7 +822,7 @@ void RemoteDirModel::getFileInfoFromIndexList(const QModelIndexList& list, std:: #endif } /* Fire off requests */ - + std::set already_in ; for(QModelIndexList::const_iterator it(list.begin()); it != list.end(); ++it) @@ -923,11 +923,61 @@ void RemoteDirModel::recommendSelectedOnly(QModelIndexList list) * OLD RECOMMEND SYSTEM - DISABLED ******/ -void RemoteDirModel::openSelected(QModelIndexList) +void RemoteDirModel::openSelected(QModelIndexList qmil, bool openFolder) { - //recommendSelected(list); -} +#ifdef RDM_DEBUG + std::cerr << "RemoteDirModel::openSelected()" << std::endl; +#endif + if (RemoteMode) { +#ifdef RDM_DEBUG + std::cerr << "Cannot open remote. Download first." << std::endl; +#endif + return; + } + + std::list dirs_to_open; + + std::list files_info; + std::list::iterator it; + getFileInfoFromIndexList(qmil, files_info); + + for (it = files_info.begin(); it != files_info.end(); it++) { + if ((*it).type & DIR_TYPE_PERSON) continue; + + std::string fullpath, name; + rsFiles->ConvertSharedFilePath((*it).path, fullpath); + int len = fullpath.length(); + if (len && (fullpath[len - 1] != '/')) fullpath += '/'; + + if ((*it).type & DIR_TYPE_FILE) { + name = fullpath + (*it).name; + } else if ((*it).type & DIR_TYPE_DIR) { + name = fullpath; + } + + if (!openFolder) { + if ((*it).type & DIR_TYPE_FILE) { + QDesktopServices::openUrl(QUrl::fromLocalFile(name.c_str())); + } + } else { + if (dirs_to_open.end() == std::find(dirs_to_open.begin(), dirs_to_open.end(), fullpath)) { + dirs_to_open.push_back(fullpath); + } + } + } + + if (openFolder) { + std::list::iterator dit; + for (dit = dirs_to_open.begin(); dit != dirs_to_open.end(); dit++) { + QDesktopServices::openUrl(QUrl::fromLocalFile((*dit).c_str())); + } + } + +#ifdef RDM_DEBUG + std::cerr << "::::::::::::Done RemoteDirModel::openSelected()" << std::endl; +#endif +} void RemoteDirModel::getFilePaths(QModelIndexList list, std::list &fullpaths) { @@ -1105,7 +1155,7 @@ RemoteDirModel::isDir ( const QModelIndex & index ) const void *ref = index.internalPointer(); if (!ref) return false; - + DirDetails details; uint32_t flags = DIR_FLAGS_DETAILS; if (RemoteMode) @@ -1118,7 +1168,7 @@ RemoteDirModel::isDir ( const QModelIndex & index ) const return false;//not good, but.... } - return (details.type == DIR_TYPE_DIR) ; + return (details.type == DIR_TYPE_DIR) ; } diff --git a/retroshare-gui/src/rsiface/RemoteDirModel.h b/retroshare-gui/src/rsiface/RemoteDirModel.h index 8fc06dafd..e780a775e 100644 --- a/retroshare-gui/src/rsiface/RemoteDirModel.h +++ b/retroshare-gui/src/rsiface/RemoteDirModel.h @@ -12,10 +12,10 @@ class RemoteDirModel : public QAbstractItemModel { Q_OBJECT - + public: enum Roles{ FileNameRole = Qt::UserRole+1 }; - + RemoteDirModel(bool mode, QObject *parent = 0); /* These are all overloaded Virtual Functions */ @@ -26,7 +26,7 @@ public: QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - QModelIndex index(int row, int column, + QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const; QModelIndex parent ( const QModelIndex & index ) const; @@ -39,7 +39,7 @@ public: /* Callback from GUI */ void downloadSelected(QModelIndexList list); - + void getDirDetailsFromSelect (QModelIndexList list, std::vector & dirVec); bool isDir ( const QModelIndex & index ) const ; @@ -48,16 +48,16 @@ public: //#if 0 /****** REMOVED ******/ // void recommendSelected(QModelIndexList list); // void recommendSelectedOnly(QModelIndexList list); -//#endif +//#endif void getFileInfoFromIndexList(const QModelIndexList& list, std::list& files_info) ; - void openSelected(QModelIndexList list); + void openSelected(QModelIndexList list, bool openFolder); void getFilePaths(QModelIndexList list, std::list &fullpaths); public slots: - void collapsed ( const QModelIndex & index ) { update(index); } + void collapsed ( const QModelIndex & index ) { update(index); } void expanded ( const QModelIndex & index ) { update(index); } /* Drag and Drop Functionality */ @@ -72,28 +72,28 @@ virtual QStringList mimeTypes () const; QIcon categoryIcon; QIcon peerIcon; - + class RemoteIndex { public: RemoteIndex() {} - RemoteIndex(std::string in_person, - std::string in_path, - int in_idx, - int in_row, + RemoteIndex(std::string in_person, + std::string in_path, + int in_idx, + int in_row, int in_column, std::string in_name, int in_size, int in_type, int in_ts, int in_rank) :id(in_person), path(in_path), parent(in_idx), - row(in_row), column(in_column), - name(in_name), size(in_size), + row(in_row), column(in_column), + name(in_name), size(in_size), type(in_type), timestamp(in_ts), rank(in_rank) { return; } - + std::string id; std::string path; int parent;