2007-11-14 22:18:48 -05:00
/****************************************************************
* RShare is distributed under the following license :
*
* Copyright ( C ) 2006 , crypton
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
2009-07-07 14:56:31 -04:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
2007-11-14 22:18:48 -05:00
* Boston , MA 02110 - 1301 , USA .
2008-11-18 12:14:49 -05:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2016-08-28 17:14:39 -04:00
# include <set>
2010-07-23 14:52:58 -04:00
# include <QString>
# include <QTreeView>
# include <QClipboard>
# include <QMenu>
2016-11-01 05:30:36 -04:00
# include <QPainter>
2010-07-23 14:52:58 -04:00
# include <QProcess>
2010-09-19 20:10:51 -04:00
# include <QSortFilterProxyModel>
2016-11-01 05:30:36 -04:00
# include <QStyledItemDelegate>
2010-07-23 14:52:58 -04:00
2008-11-18 12:14:49 -05:00
# include "SharedFilesDialog.h"
2009-12-14 12:13:10 -05:00
# include "settings/AddFileAssociationDialog.h"
2007-11-14 22:18:48 -05:00
# include "util/RsAction.h"
2010-05-23 15:13:41 -04:00
# include "msgs/MessageComposer.h"
2009-12-14 12:13:10 -05:00
# include "settings/rsharesettings.h"
2010-11-20 15:58:35 -05:00
# ifdef RS_USE_LINKS
2009-08-17 16:19:53 -04:00
# include "AddLinksDialog.h"
2010-11-20 15:58:35 -05:00
# endif
2010-03-10 16:38:26 -05:00
# include "RetroShareLink.h"
2013-02-22 16:42:27 -05:00
# include "ShareManager.h"
2013-02-26 19:23:56 -05:00
# include "RemoteDirModel.h"
2012-12-05 08:26:26 -05:00
# include "ShareDialog.h"
2010-09-28 16:33:34 -04:00
# include "common/PeerDefs.h"
2013-10-19 09:25:06 -04:00
# include "util/QtVersion.h"
2014-05-29 10:49:45 -04:00
# include "gui/common/RsCollectionFile.h"
2014-01-05 17:51:54 -05:00
# include "notifyqt.h"
2009-05-18 10:23:55 -04:00
2010-08-06 05:40:23 -04:00
# include <retroshare/rspeers.h>
# include <retroshare/rsfiles.h>
2007-11-14 22:18:48 -05:00
2009-04-07 04:08:03 -04:00
2007-11-14 22:18:48 -05:00
/* Images for context menu icons */
2008-08-07 06:48:18 -04:00
# define IMAGE_DOWNLOAD ": / images / download16.png"
2008-11-18 12:14:49 -05:00
# define IMAGE_PLAY ": / images / start.png"
2008-03-31 14:37:50 -04:00
# define IMAGE_HASH_BUSY ": / images / settings.png"
2009-07-10 20:45:17 -04:00
# define IMAGE_HASH_DONE ": / images / accepted16.png"
2008-04-05 10:37:22 -04:00
# define IMAGE_MSG ": / images / message-mail.png"
# define IMAGE_ATTACHMENT ": / images / attachment.png"
# define IMAGE_FRIEND ": / images / peers_16x16.png"
2008-04-05 16:03:25 -04:00
# define IMAGE_PROGRESS ": / images / browse-looking.gif"
2009-05-18 10:23:55 -04:00
# define IMAGE_COPYLINK ": / images / copyrslink.png"
2012-12-05 08:26:26 -05:00
# define IMAGE_OPENFOLDER ": / images / folderopen.png"
2014-05-29 10:49:45 -04:00
# define IMAGE_OPENFILE ": / images / fileopen.png"
# define IMAGE_LIBRARY ": / images / library.png"
# define IMAGE_COLLCREATE ": / images / library_add.png"
# define IMAGE_COLLMODIF ": / images / library_edit.png"
# define IMAGE_COLLVIEW ": / images / library_view.png"
# define IMAGE_COLLOPEN ": / images / library.png"
2013-02-26 19:23:56 -05:00
# define IMAGE_EDITSHARE ": / images / edit_16.png"
2016-08-30 11:18:27 -04:00
# define IMAGE_MYFILES ": / icons / svg / folders1.svg"
2009-05-18 10:23:55 -04:00
2014-05-29 10:49:45 -04:00
/*define dirTreeView Column */
# define COLUMN_NAME 0
# define COLUMN_SIZE 1
# define COLUMN_AGE 2
# define COLUMN_FRIEND 3
# define COLUMN_DIR 4
# define COLUMN_COUNT 5
/*define viewType_CB value */
# define VIEW_TYPE_TREE 0
# define VIEW_TYPE_FLAT 1
2011-04-03 15:59:12 -04:00
// Define to avoid using the search in treeview, because it is really slow for now.
//
# define DONT_USE_SEARCH_IN_TREE_VIEW 1
2016-09-08 17:43:14 -04:00
//#define DEBUG_SHARED_FILES_DIALOG 1
2009-04-07 04:08:03 -04:00
const QString Image_AddNewAssotiationForFile = " :/images/kcmsystem24.png " ;
2008-04-05 10:37:22 -04:00
2010-09-19 20:10:51 -04:00
class SFDSortFilterProxyModel : public QSortFilterProxyModel
{
public :
2011-04-01 17:46:06 -04:00
SFDSortFilterProxyModel ( RetroshareDirModel * dirModel , QObject * parent ) : QSortFilterProxyModel ( parent )
2010-09-19 20:10:51 -04:00
{
m_dirModel = dirModel ;
2014-01-05 17:51:54 -05:00
}
2010-09-19 20:10:51 -04:00
protected :
virtual bool lessThan ( const QModelIndex & left , const QModelIndex & right ) const
{
2010-11-07 16:33:48 -05:00
bool dirLeft = ( m_dirModel - > getType ( left ) = = DIR_TYPE_DIR ) ;
bool dirRight = ( m_dirModel - > getType ( right ) = = DIR_TYPE_DIR ) ;
2010-09-19 20:10:51 -04:00
if ( dirLeft ^ dirRight ) {
return dirLeft ;
}
return QSortFilterProxyModel : : lessThan ( left , right ) ;
}
private :
2011-04-01 17:46:06 -04:00
RetroshareDirModel * m_dirModel ;
2010-09-19 20:10:51 -04:00
} ;
2008-11-18 12:14:49 -05:00
2016-11-01 05:30:36 -04:00
// This class allows to draw the item in the share flags column using an appropriate size
class ShareFlagsItemDelegate : public QStyledItemDelegate
{
public :
ShareFlagsItemDelegate ( ) { }
virtual void paint ( QPainter * painter , const QStyleOptionViewItem & option , const QModelIndex & index ) const
{
Q_ASSERT ( index . isValid ( ) ) ;
QStyleOptionViewItemV4 opt = option ;
initStyleOption ( & opt , index ) ;
// disable default icon
opt . icon = QIcon ( ) ;
// draw default item
QApplication : : style ( ) - > drawControl ( QStyle : : CE_ItemViewItem , & opt , painter , 0 ) ;
const QRect r = option . rect ;
// get pixmap
QIcon icon = qvariant_cast < QIcon > ( index . data ( Qt : : DecorationRole ) ) ;
QPixmap pix = icon . pixmap ( r . size ( ) ) ;
// draw pixmap at center of item
const QPoint p = QPoint ( ( r . width ( ) - pix . width ( ) ) / 2 , ( r . height ( ) - pix . height ( ) ) / 2 ) ;
painter - > drawPixmap ( r . topLeft ( ) + p , pix ) ;
}
} ;
2008-11-18 12:14:49 -05:00
/** Constructor */
2013-02-22 16:42:27 -05:00
SharedFilesDialog : : SharedFilesDialog ( RetroshareDirModel * _tree_model , RetroshareDirModel * _flat_model , QWidget * parent )
2011-04-14 17:58:15 -04:00
: RsAutoUpdatePage ( 1000 , parent ) , model ( NULL )
2008-11-18 12:14:49 -05:00
{
2011-04-05 20:19:56 -04:00
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2009-07-07 14:56:31 -04:00
2014-01-05 17:51:54 -05:00
NotifyQt * notify = NotifyQt : : getInstance ( ) ;
connect ( notify , SIGNAL ( filesPreModChanged ( bool ) ) , this , SLOT ( preModDirectories ( bool ) ) ) ;
connect ( notify , SIGNAL ( filesPostModChanged ( bool ) ) , this , SLOT ( postModDirectories ( bool ) ) ) ;
2013-02-22 16:42:27 -05:00
//== connect(ui.localButton, SIGNAL(toggled(bool)), this, SLOT(showFrame(bool)));
//== connect(ui.remoteButton, SIGNAL(toggled(bool)), this, SLOT(showFrameRemote(bool)));
//== connect(ui.splittedButton, SIGNAL(toggled(bool)), this, SLOT(showFrameSplitted(bool)));
2011-04-05 20:19:56 -04:00
connect ( ui . viewType_CB , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( changeCurrentViewModel ( int ) ) ) ;
2009-07-20 13:03:27 -04:00
2013-02-22 16:42:27 -05:00
connect ( ui . dirTreeView , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( spawnCustomPopupMenu ( QPoint ) ) ) ;
2009-01-01 19:09:59 -05:00
2009-10-13 16:36:29 -04:00
connect ( ui . indicatorCBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( indicatorChanged ( int ) ) ) ;
2009-01-01 19:09:59 -05:00
2013-02-22 16:42:27 -05:00
tree_model = _tree_model ;
flat_model = _flat_model ;
2007-11-14 22:18:48 -05:00
2011-04-05 20:19:56 -04:00
tree_proxyModel = new SFDSortFilterProxyModel ( tree_model , this ) ;
tree_proxyModel - > setSourceModel ( tree_model ) ;
tree_proxyModel - > setSortCaseSensitivity ( Qt : : CaseInsensitive ) ;
tree_proxyModel - > setSortRole ( RetroshareDirModel : : SortRole ) ;
2014-05-29 10:49:45 -04:00
tree_proxyModel - > sort ( COLUMN_NAME ) ;
2010-09-19 20:10:51 -04:00
2016-09-13 15:23:27 -04:00
flat_proxyModel = new SFDSortFilterProxyModel ( flat_model , this ) ;
flat_proxyModel - > setSourceModel ( flat_model ) ;
flat_proxyModel - > setSortCaseSensitivity ( Qt : : CaseInsensitive ) ;
flat_proxyModel - > setSortRole ( RetroshareDirModel : : SortRole ) ;
flat_proxyModel - > sort ( COLUMN_NAME ) ;
// Mr.Alice: I removed this because it causes a crash for some obscur reason. Apparently when the model is changed, the proxy model cannot
// deal with the change by itself. Should I call something specific? I've no idea. Removing this does not seem to cause any harm either.
2016-11-16 06:07:38 -05:00
//Ghibli: set false because by default in qt5 is true and makes rs crash when sorting, all this decided by Cyril not me :D it works
2016-11-16 06:02:54 -05:00
tree_proxyModel - > setDynamicSortFilter ( false ) ;
flat_proxyModel - > setDynamicSortFilter ( false ) ;
2016-09-13 15:23:27 -04:00
connect ( ui . filterClearButton , SIGNAL ( clicked ( ) ) , this , SLOT ( clearFilter ( ) ) ) ;
2011-04-05 20:19:56 -04:00
connect ( ui . filterStartButton , SIGNAL ( clicked ( ) ) , this , SLOT ( startFilter ( ) ) ) ;
connect ( ui . filterPatternLineEdit , SIGNAL ( returnPressed ( ) ) , this , SLOT ( startFilter ( ) ) ) ;
connect ( ui . filterPatternLineEdit , SIGNAL ( textChanged ( const QString & ) ) , this , SLOT ( filterRegExpChanged ( ) ) ) ;
2009-07-07 14:56:31 -04:00
2011-04-05 20:19:56 -04:00
/* Set header resize modes and initial section sizes */
2013-02-22 16:42:27 -05:00
QHeaderView * header = ui . dirTreeView - > header ( ) ;
2009-01-30 20:46:49 -05:00
2014-05-29 10:49:45 -04:00
header - > resizeSection ( COLUMN_NAME , 490 ) ;
2016-09-14 15:52:16 -04:00
header - > resizeSection ( COLUMN_SIZE , 70 ) ;
header - > resizeSection ( COLUMN_AGE , 100 ) ;
header - > resizeSection ( COLUMN_FRIEND , 100 ) ;
header - > resizeSection ( COLUMN_DIR , 100 ) ;
2009-01-30 20:46:49 -05:00
2013-02-22 16:42:27 -05:00
header - > setStretchLastSection ( false ) ;
2008-08-07 14:49:57 -04:00
2011-04-05 20:19:56 -04:00
/* Set Multi Selection */
2013-02-22 16:42:27 -05:00
ui . dirTreeView - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
2011-04-01 17:46:06 -04:00
2008-11-18 12:14:49 -05:00
/* Hide platform specific features */
2013-02-22 16:42:27 -05:00
copylinkAct = new QAction ( QIcon ( IMAGE_COPYLINK ) , tr ( " Copy retroshare Links to Clipboard " ) , this ) ;
connect ( copylinkAct , SIGNAL ( triggered ( ) ) , this , SLOT ( copyLink ( ) ) ) ;
copylinkhtmlAct = new QAction ( QIcon ( IMAGE_COPYLINK ) , tr ( " Copy retroshare Links to Clipboard (HTML) " ) , this ) ;
connect ( copylinkhtmlAct , SIGNAL ( triggered ( ) ) , this , SLOT ( copyLinkhtml ( ) ) ) ;
2010-03-28 16:46:45 -04:00
sendlinkAct = new QAction ( QIcon ( IMAGE_COPYLINK ) , tr ( " Send retroshare Links " ) , this ) ;
connect ( sendlinkAct , SIGNAL ( triggered ( ) ) , this , SLOT ( sendLinkTo ( ) ) ) ;
2010-11-20 15:58:35 -05:00
# ifdef RS_USE_LINKS
2010-03-28 16:46:45 -04:00
sendlinkCloudAct = new QAction ( QIcon ( IMAGE_COPYLINK ) , tr ( " Send retroshare Links to Cloud " ) , this ) ;
connect ( sendlinkCloudAct , SIGNAL ( triggered ( ) ) , this , SLOT ( sendLinkToCloud ( ) ) ) ;
addlinkCloudAct = new QAction ( QIcon ( IMAGE_COPYLINK ) , tr ( " Add Links to Cloud " ) , this ) ;
connect ( addlinkCloudAct , SIGNAL ( triggered ( ) ) , this , SLOT ( addLinkToCloud ( ) ) ) ;
2010-11-20 15:58:35 -05:00
# endif
2014-05-29 10:49:45 -04:00
collCreateAct = new QAction ( QIcon ( IMAGE_COLLCREATE ) , tr ( " Create Collection... " ) , this ) ;
connect ( collCreateAct , SIGNAL ( triggered ( ) ) , this , SLOT ( collCreate ( ) ) ) ;
collModifAct = new QAction ( QIcon ( IMAGE_COLLMODIF ) , tr ( " Modify Collection... " ) , this ) ;
connect ( collModifAct , SIGNAL ( triggered ( ) ) , this , SLOT ( collModif ( ) ) ) ;
collViewAct = new QAction ( QIcon ( IMAGE_COLLVIEW ) , tr ( " View Collection... " ) , this ) ;
connect ( collViewAct , SIGNAL ( triggered ( ) ) , this , SLOT ( collView ( ) ) ) ;
collOpenAct = new QAction ( QIcon ( IMAGE_COLLOPEN ) , tr ( " Download from collection file... " ) , this ) ;
connect ( collOpenAct , SIGNAL ( triggered ( ) ) , this , SLOT ( collOpen ( ) ) ) ;
2013-02-22 16:42:27 -05:00
}
LocalSharedFilesDialog : : LocalSharedFilesDialog ( QWidget * parent )
: SharedFilesDialog ( new TreeStyle_RDM ( false ) , new FlatStyle_RDM ( false ) , parent )
{
// Hide columns after loading the settings
2014-05-29 10:49:45 -04:00
ui . dirTreeView - > setColumnHidden ( COLUMN_DIR , false ) ;
2013-02-22 16:42:27 -05:00
ui . downloadButton - > hide ( ) ;
// load settings
processSettings ( true ) ;
// Setup the current view model.
//
changeCurrentViewModel ( ui . viewType_CB - > currentIndex ( ) ) ;
2014-05-29 10:49:45 -04:00
connect ( ui . addShares_PB , SIGNAL ( clicked ( ) ) , this , SLOT ( addShares ( ) ) ) ;
connect ( ui . checkButton , SIGNAL ( clicked ( ) ) , this , SLOT ( forceCheck ( ) ) ) ;
2013-02-22 16:42:27 -05:00
2014-05-29 10:49:45 -04:00
openfileAct = new QAction ( QIcon ( IMAGE_OPENFILE ) , tr ( " Open File " ) , this ) ;
connect ( openfileAct , SIGNAL ( triggered ( ) ) , this , SLOT ( openfile ( ) ) ) ;
openfolderAct = new QAction ( QIcon ( IMAGE_OPENFOLDER ) , tr ( " Open Folder " ) , this ) ;
connect ( openfolderAct , SIGNAL ( triggered ( ) ) , this , SLOT ( openfolder ( ) ) ) ;
editshareAct = new QAction ( QIcon ( IMAGE_EDITSHARE ) , tr ( " Edit Share Permissions " ) , this ) ;
connect ( editshareAct , SIGNAL ( triggered ( ) ) , this , SLOT ( editSharePermissions ( ) ) ) ;
2013-02-22 16:42:27 -05:00
2016-11-01 05:30:36 -04:00
ui . titleBarPixmap - > setPixmap ( QPixmap ( IMAGE_MYFILES ) ) ;
ui . dirTreeView - > setItemDelegateForColumn ( COLUMN_FRIEND , new ShareFlagsItemDelegate ( ) ) ;
2010-09-19 20:10:51 -04:00
}
2010-03-28 16:46:45 -04:00
2013-02-22 16:42:27 -05:00
RemoteSharedFilesDialog : : RemoteSharedFilesDialog ( QWidget * parent )
: SharedFilesDialog ( new TreeStyle_RDM ( true ) , new FlatStyle_RDM ( true ) , parent )
{
2014-05-29 10:49:45 -04:00
ui . dirTreeView - > setColumnHidden ( COLUMN_FRIEND , false ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_DIR , true ) ;
2013-02-22 16:42:27 -05:00
ui . checkButton - > hide ( ) ;
connect ( ui . downloadButton , SIGNAL ( clicked ( ) ) , this , SLOT ( downloadRemoteSelected ( ) ) ) ;
2016-09-11 11:52:12 -04:00
connect ( ui . dirTreeView , SIGNAL ( expanded ( const QModelIndex & ) ) , this , SLOT ( expanded ( const QModelIndex & ) ) ) ;
2016-11-05 12:03:31 -04:00
connect ( ui . dirTreeView , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( expanded ( const QModelIndex & ) ) ) ;
2013-02-22 16:42:27 -05:00
// load settings
processSettings ( true ) ;
// Setup the current view model.
//
changeCurrentViewModel ( ui . viewType_CB - > currentIndex ( ) ) ;
ui . addShares_PB - > hide ( ) ;
}
void LocalSharedFilesDialog : : addShares ( )
{
ShareManager : : showYourself ( ) ;
}
2011-04-14 17:58:15 -04:00
void SharedFilesDialog : : hideEvent ( QHideEvent * )
{
if ( model ! = NULL )
model - > setVisible ( false ) ;
}
void SharedFilesDialog : : showEvent ( QShowEvent * )
{
if ( model ! = NULL )
{
2016-10-03 15:44:34 -04:00
std : : set < std : : string > expanded_indexes , selected_indexes ;
saveExpandedPathsAndSelection ( expanded_indexes , selected_indexes ) ;
2016-08-29 15:30:56 -04:00
model - > setVisible ( true ) ;
2011-04-14 17:58:15 -04:00
model - > update ( ) ;
2016-08-29 15:30:56 -04:00
2016-10-03 15:44:34 -04:00
restoreExpandedPathsAndSelection ( expanded_indexes , selected_indexes ) ;
2016-08-29 15:30:56 -04:00
}
2011-04-14 17:58:15 -04:00
}
2013-02-22 16:42:27 -05:00
RemoteSharedFilesDialog : : ~ RemoteSharedFilesDialog ( )
{
// save settings
processSettings ( false ) ;
}
LocalSharedFilesDialog : : ~ LocalSharedFilesDialog ( )
2010-09-19 20:10:51 -04:00
{
// save settings
processSettings ( false ) ;
}
2010-03-28 16:46:45 -04:00
2013-02-22 16:42:27 -05:00
void LocalSharedFilesDialog : : processSettings ( bool bLoad )
{
Settings - > beginGroup ( " LocalSharedFilesDialog " ) ;
if ( bLoad ) {
// load settings
// state of the trees
ui . dirTreeView - > header ( ) - > restoreState ( Settings - > value ( " LocalDirTreeView " ) . toByteArray ( ) ) ;
// state of splitter
ui . splitter - > restoreState ( Settings - > value ( " LocalSplitter " ) . toByteArray ( ) ) ;
// view type
ui . viewType_CB - > setCurrentIndex ( Settings - > value ( " LocalViewType " ) . toInt ( ) ) ;
} else {
// save settings
// state of trees
Settings - > setValue ( " LocalDirTreeView " , ui . dirTreeView - > header ( ) - > saveState ( ) ) ;
// state of splitter
Settings - > setValue ( " LocalSplitter " , ui . splitter - > saveState ( ) ) ;
// view type
Settings - > setValue ( " LocalViewType " , ui . viewType_CB - > currentIndex ( ) ) ;
}
Settings - > endGroup ( ) ;
}
void RemoteSharedFilesDialog : : processSettings ( bool bLoad )
2010-09-19 20:10:51 -04:00
{
2011-04-05 20:19:56 -04:00
Settings - > beginGroup ( " SharedFilesDialog " ) ;
2010-09-19 20:10:51 -04:00
2011-04-05 20:19:56 -04:00
if ( bLoad ) {
// load settings
2010-09-19 20:10:51 -04:00
2011-04-05 20:19:56 -04:00
// state of the trees
2013-02-22 16:42:27 -05:00
ui . dirTreeView - > header ( ) - > restoreState ( Settings - > value ( " RemoteDirTreeView " ) . toByteArray ( ) ) ;
2010-09-19 20:10:51 -04:00
2011-04-05 20:19:56 -04:00
// state of splitter
2013-02-22 16:42:27 -05:00
ui . splitter - > restoreState ( Settings - > value ( " RemoteSplitter " ) . toByteArray ( ) ) ;
2010-09-19 20:10:51 -04:00
2011-04-05 20:19:56 -04:00
// view type
2013-02-22 16:42:27 -05:00
ui . viewType_CB - > setCurrentIndex ( Settings - > value ( " RemoteViewType " ) . toInt ( ) ) ;
2011-04-05 20:19:56 -04:00
} else {
// save settings
2010-09-19 20:10:51 -04:00
2011-04-05 20:19:56 -04:00
// state of trees
2013-02-22 16:42:27 -05:00
Settings - > setValue ( " RemoteDirTreeView " , ui . dirTreeView - > header ( ) - > saveState ( ) ) ;
2011-04-05 20:19:56 -04:00
// state of splitter
2013-02-22 16:42:27 -05:00
Settings - > setValue ( " RemoteSplitter " , ui . splitter - > saveState ( ) ) ;
2011-04-05 20:19:56 -04:00
// view type
2013-02-22 16:42:27 -05:00
Settings - > setValue ( " RemoteViewType " , ui . viewType_CB - > currentIndex ( ) ) ;
2011-04-05 20:19:56 -04:00
}
2010-09-19 20:10:51 -04:00
2011-04-05 20:19:56 -04:00
Settings - > endGroup ( ) ;
2008-11-18 12:14:49 -05:00
}
2007-11-14 22:18:48 -05:00
2014-05-29 10:49:45 -04:00
void SharedFilesDialog : : changeCurrentViewModel ( int viewTypeIndex )
2011-04-01 17:46:06 -04:00
{
2016-08-28 17:14:39 -04:00
// disconnect( ui.dirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), NULL, NULL );
// disconnect( ui.dirTreeView, SIGNAL( expanded(const QModelIndex & ) ), NULL, NULL );
2011-04-01 17:46:06 -04:00
2011-04-14 17:58:15 -04:00
if ( model ! = NULL )
model - > setVisible ( false ) ;
2014-05-29 10:49:45 -04:00
if ( viewTypeIndex = = VIEW_TYPE_TREE )
2011-04-01 17:46:06 -04:00
{
model = tree_model ;
2016-09-13 15:23:27 -04:00
proxyModel = tree_proxyModel ;
2011-04-01 17:46:06 -04:00
}
else
{
model = flat_model ;
2016-09-13 15:23:27 -04:00
proxyModel = flat_proxyModel ;
}
2011-04-01 17:46:06 -04:00
2013-02-22 16:42:27 -05:00
showProperColumns ( ) ;
2016-10-03 15:44:34 -04:00
std : : set < std : : string > expanded_indexes , selected_indexes ;
saveExpandedPathsAndSelection ( expanded_indexes , selected_indexes ) ;
2016-08-29 15:30:56 -04:00
if ( isVisible ( ) )
2011-04-14 17:58:15 -04:00
{
2016-08-29 15:30:56 -04:00
model - > setVisible ( true ) ;
2011-04-14 17:58:15 -04:00
model - > update ( ) ;
}
2011-04-01 17:46:06 -04:00
2016-08-28 17:14:39 -04:00
// connect( ui.dirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), this, SLOT( collapsed(const QModelIndex & ) ) );
2011-04-01 17:46:06 -04:00
2013-02-22 16:42:27 -05:00
ui . dirTreeView - > setModel ( proxyModel ) ;
ui . dirTreeView - > update ( ) ;
2011-04-01 17:46:06 -04:00
2016-10-03 15:44:34 -04:00
restoreExpandedPathsAndSelection ( expanded_indexes , selected_indexes ) ;
2016-08-29 15:30:56 -04:00
QHeaderView * header = ui . dirTreeView - > header ( ) ;
2015-06-26 04:14:09 -04:00
QHeaderView_setSectionResizeModeColumn ( header , COLUMN_NAME , QHeaderView : : Interactive ) ;
2013-02-26 19:23:56 -05:00
2014-05-29 10:49:45 -04:00
ui . dirTreeView - > header ( ) - > headerDataChanged ( Qt : : Horizontal , COLUMN_NAME , COLUMN_DIR ) ;
2011-04-01 17:46:06 -04:00
2016-08-28 17:14:39 -04:00
// recursRestoreExpandedItems(ui.dirTreeView->rootIndex(),expanded_indexes);
2016-01-09 06:09:43 -05:00
FilterItems ( ) ;
2011-04-01 17:46:06 -04:00
}
2013-02-22 16:42:27 -05:00
void LocalSharedFilesDialog : : showProperColumns ( )
{
if ( model = = tree_model )
{
2014-05-29 10:49:45 -04:00
ui . dirTreeView - > setColumnHidden ( COLUMN_FRIEND , false ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_DIR , false ) ;
2013-02-22 16:42:27 -05:00
# ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui . filterLabel - > hide ( ) ;
ui . filterPatternLineEdit - > hide ( ) ;
ui . filterStartButton - > hide ( ) ;
ui . filterClearButton - > hide ( ) ;
# endif
}
else
{
2014-05-29 10:49:45 -04:00
ui . dirTreeView - > setColumnHidden ( COLUMN_FRIEND , true ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_DIR , false ) ;
2013-02-22 16:42:27 -05:00
# ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui . filterLabel - > show ( ) ;
ui . filterPatternLineEdit - > show ( ) ;
# endif
}
}
void RemoteSharedFilesDialog : : showProperColumns ( )
{
if ( model = = tree_model )
{
2014-05-29 10:49:45 -04:00
ui . dirTreeView - > setColumnHidden ( COLUMN_FRIEND , true ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_DIR , true ) ;
2013-02-22 16:42:27 -05:00
# ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui . filterLabel - > hide ( ) ;
ui . filterPatternLineEdit - > hide ( ) ;
ui . filterStartButton - > hide ( ) ;
ui . filterClearButton - > hide ( ) ;
# endif
}
else
{
2014-05-29 10:49:45 -04:00
ui . dirTreeView - > setColumnHidden ( COLUMN_FRIEND , false ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_DIR , false ) ;
2013-02-22 16:42:27 -05:00
# ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui . filterLabel - > show ( ) ;
ui . filterPatternLineEdit - > show ( ) ;
# endif
}
}
void LocalSharedFilesDialog : : checkUpdate ( )
2008-03-31 14:37:50 -04:00
{
2013-02-22 16:42:27 -05:00
/* update */
2008-07-02 12:59:56 -04:00
if ( rsFiles - > InDirectoryCheck ( ) )
2008-03-31 14:37:50 -04:00
{
2009-07-10 20:45:17 -04:00
ui . checkButton - > setText ( tr ( " Checking... " ) ) ;
2008-03-31 14:37:50 -04:00
}
else
{
2013-02-22 16:42:27 -05:00
ui . checkButton - > setText ( tr ( " Check files " ) ) ;
2008-03-31 14:37:50 -04:00
ui . hashLabel - > setPixmap ( QPixmap ( IMAGE_HASH_DONE ) ) ;
2009-01-25 14:05:53 -05:00
ui . hashLabel - > setToolTip ( " " ) ;
2008-03-31 14:37:50 -04:00
}
return ;
}
2013-02-22 16:42:27 -05:00
void LocalSharedFilesDialog : : forceCheck ( )
2008-03-31 14:37:50 -04:00
{
2008-07-02 12:59:56 -04:00
rsFiles - > ForceDirectoryCheck ( ) ;
2008-03-31 14:37:50 -04:00
return ;
}
2013-02-22 16:42:27 -05:00
void RemoteSharedFilesDialog : : spawnCustomPopupMenu ( QPoint point )
2008-11-18 12:14:49 -05:00
{
2014-05-29 10:49:45 -04:00
if ( ! rsPeers ) return ; /* not ready yet! */
2009-07-07 14:56:31 -04:00
2014-05-29 10:49:45 -04:00
QModelIndex idx = ui . dirTreeView - > indexAt ( point ) ;
if ( ! idx . isValid ( ) ) return ;
2009-05-18 10:23:55 -04:00
2014-05-29 10:49:45 -04:00
QModelIndex midx = proxyModel - > mapToSource ( idx ) ;
if ( ! midx . isValid ( ) ) return ;
2009-07-07 14:56:31 -04:00
2014-05-29 10:49:45 -04:00
currentFile = model - > data ( midx , RetroshareDirModel : : FileNameRole ) . toString ( ) ;
int type = model - > getType ( midx ) ;
if ( type ! = DIR_TYPE_DIR & & type ! = DIR_TYPE_FILE ) return ;
2009-07-07 14:56:31 -04:00
2014-05-29 10:49:45 -04:00
QMenu contextMnu ( this ) ;
2008-11-18 12:14:49 -05:00
2014-05-29 10:49:45 -04:00
//bool bIsRsColl = currentFile.endsWith(RsCollectionFile::ExtensionString);
collCreateAct - > setEnabled ( true ) ;
//collModifAct->setEnabled(bIsRsColl);
//collViewAct->setEnabled(bIsRsColl);
collOpenAct - > setEnabled ( true ) ;
2010-05-14 16:55:44 -04:00
2014-05-29 10:49:45 -04:00
QMenu collectionMenu ( tr ( " Collection " ) , this ) ;
collectionMenu . setIcon ( QIcon ( IMAGE_LIBRARY ) ) ;
collectionMenu . addAction ( collCreateAct ) ;
//collectionMenu.addAction(collModifAct);
//collectionMenu.addAction(collViewAct);
collectionMenu . addAction ( collOpenAct ) ;
2008-11-18 12:14:49 -05:00
2014-05-29 10:49:45 -04:00
QAction * downloadAct = new QAction ( QIcon ( IMAGE_DOWNLOAD ) , tr ( " Download " ) , & contextMnu ) ;
connect ( downloadAct , SIGNAL ( triggered ( ) ) , this , SLOT ( downloadRemoteSelected ( ) ) ) ;
contextMnu . addAction ( downloadAct ) ;
if ( type = = DIR_TYPE_FILE ) {
//QAction *copyremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), &contextMnu ) ;
//connect( copyremotelinkAct , SIGNAL( triggered() ), this, SLOT( copyLink() ) ) ;
//QAction *sendremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), &contextMnu ) ;
//connect( sendremotelinkAct , SIGNAL( triggered() ), this, SLOT( sendremoteLinkTo( ) ) ) ;
2010-09-19 20:10:51 -04:00
2014-05-29 10:49:45 -04:00
contextMnu . addSeparator ( ) ; //------------------------------------
contextMnu . addAction ( copylinkAct ) ;
contextMnu . addAction ( sendlinkAct ) ;
contextMnu . addSeparator ( ) ; //------------------------------------
contextMnu . addAction ( QIcon ( IMAGE_MSG ) , tr ( " Recommend in a message to " ) , this , SLOT ( recommendFilesToMsg ( ) ) ) ;
} //if (type == DIR_TYPE_FILE)
contextMnu . addSeparator ( ) ; //------------------------------------
contextMnu . addMenu ( & collectionMenu ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
2010-09-19 20:10:51 -04:00
}
2007-11-14 22:18:48 -05:00
2014-05-29 10:49:45 -04:00
QModelIndexList SharedFilesDialog : : getSelected ( )
2011-11-07 18:07:25 -05:00
{
2014-05-29 10:49:45 -04:00
QModelIndexList list = ui . dirTreeView - > selectionModel ( ) - > selectedIndexes ( ) ;
QModelIndexList proxyList ;
2014-10-21 18:33:02 -04:00
for ( QModelIndexList : : iterator index = list . begin ( ) ; index ! = list . end ( ) ; + + index ) {
2014-05-29 10:49:45 -04:00
proxyList . append ( proxyModel - > mapToSource ( * index ) ) ;
} //for (QModelIndexList::iterator index
2011-11-07 18:07:25 -05:00
2014-05-29 10:49:45 -04:00
return proxyList ;
2013-02-26 19:23:56 -05:00
}
2012-12-05 08:26:26 -05:00
2016-09-11 11:52:12 -04:00
void RemoteSharedFilesDialog : : expanded ( const QModelIndex & indx )
{
2016-09-22 15:47:58 -04:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-09-11 11:52:12 -04:00
std : : cerr < < " Expanding at " < < indx . row ( ) < < " and " < < indx . column ( ) < < " ref= " < < indx . internalPointer ( ) < < " , pointer at 1: " < < proxyModel - > mapToSource ( indx ) . internalPointer ( ) < < std : : endl ;
2016-09-22 15:47:58 -04:00
# endif
2016-09-11 11:52:12 -04:00
model - > updateRef ( proxyModel - > mapToSource ( indx ) ) ;
}
2013-02-22 16:42:27 -05:00
void RemoteSharedFilesDialog : : downloadRemoteSelected ( )
2008-11-18 12:14:49 -05:00
{
2014-05-29 10:49:45 -04:00
/* call back to the model (which does all the interfacing? */
2007-11-14 22:18:48 -05:00
2014-05-29 10:49:45 -04:00
std : : cerr < < " Downloading Files " ;
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
2014-05-29 10:49:45 -04:00
QModelIndexList lst = getSelected ( ) ;
model - > downloadSelected ( lst ) ;
2007-11-14 22:18:48 -05:00
}
2013-02-26 19:23:56 -05:00
void LocalSharedFilesDialog : : editSharePermissions ( )
{
std : : list < SharedDirInfo > dirs ;
rsFiles - > getSharedDirectories ( dirs ) ;
std : : list < SharedDirInfo > : : const_iterator it ;
2014-10-21 18:33:02 -04:00
for ( it = dirs . begin ( ) ; it ! = dirs . end ( ) ; + + it ) {
2013-02-26 19:23:56 -05:00
if ( currentFile = = currentFile ) {
/* file name found, show dialog */
ShareDialog sharedlg ( it - > filename , this ) ;
sharedlg . setWindowTitle ( tr ( " Edit Shared Folder " ) ) ;
sharedlg . exec ( ) ;
break ;
}
}
}
2007-11-14 22:18:48 -05:00
2009-05-18 10:23:55 -04:00
void SharedFilesDialog : : copyLink ( const QModelIndexList & lst , bool remote )
{
std : : vector < DirDetails > dirVec ;
2013-02-22 16:42:27 -05:00
model - > getDirDetailsFromSelect ( lst , dirVec ) ;
2009-05-18 10:23:55 -04:00
2011-09-11 18:07:24 -04:00
QList < RetroShareLink > urls ;
2010-03-10 18:09:35 -05:00
2009-05-18 10:23:55 -04:00
for ( int i = 0 , n = dirVec . size ( ) ; i < n ; + + i )
{
const DirDetails & details = dirVec [ i ] ;
if ( details . type = = DIR_TYPE_DIR )
{
2016-08-19 12:49:42 -04:00
for ( uint32_t j = 0 ; j < details . children . size ( ) ; + + j )
2009-05-18 10:23:55 -04:00
{
2016-08-19 12:49:42 -04:00
const DirStub & dirStub = details . children [ j ] ;
2009-05-18 10:23:55 -04:00
DirDetails details ;
2012-11-02 09:52:29 -04:00
FileSearchFlags flags = remote ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL ;
2009-05-18 10:23:55 -04:00
// do not recursive copy sub dirs.
if ( ! rsFiles - > RequestDirDetails ( dirStub . ref , details , flags ) | | details . type ! = DIR_TYPE_FILE )
continue ;
2011-05-04 06:22:49 -04:00
RetroShareLink link ;
2014-03-17 16:56:06 -04:00
if ( link . createFile ( QString : : fromUtf8 ( details . name . c_str ( ) ) , details . count , details . hash . toStdString ( ) . c_str ( ) ) ) {
2011-05-04 06:22:49 -04:00
urls . push_back ( link ) ;
}
2009-05-18 10:23:55 -04:00
}
}
else
2011-05-04 06:22:49 -04:00
{
RetroShareLink link ;
2014-03-17 16:56:06 -04:00
if ( link . createFile ( QString : : fromUtf8 ( details . name . c_str ( ) ) , details . count , details . hash . toStdString ( ) . c_str ( ) ) ) {
2011-05-04 06:22:49 -04:00
urls . push_back ( link ) ;
}
}
2009-05-18 10:23:55 -04:00
}
2011-05-04 06:22:49 -04:00
RSLinkClipboard : : copyLinks ( urls ) ;
2009-05-18 10:23:55 -04:00
}
2013-02-22 16:42:27 -05:00
void SharedFilesDialog : : copyLink ( )
2009-05-18 10:23:55 -04:00
{
2013-02-22 16:42:27 -05:00
copyLink ( getSelected ( ) , isRemote ( ) ) ;
2009-05-18 10:23:55 -04:00
}
2010-03-04 10:42:50 -05:00
void SharedFilesDialog : : copyLinkhtml ( )
{
2013-02-22 16:42:27 -05:00
copyLink ( ) ;
2010-03-04 10:42:50 -05:00
QString link = QApplication : : clipboard ( ) - > text ( ) ;
QClipboard * clipboard = QApplication : : clipboard ( ) ;
clipboard - > setText ( " <a href=' " + link + " '> " + link + " </a> " ) ;
2009-05-18 10:23:55 -04:00
}
2010-03-04 10:42:50 -05:00
void SharedFilesDialog : : sendLinkTo ( )
2009-05-18 10:23:55 -04:00
{
2013-02-22 16:42:27 -05:00
copyLink ( ) ;
2009-05-18 10:23:55 -04:00
/* create a message */
2010-11-02 17:11:11 -04:00
MessageComposer * nMsgDialog = MessageComposer : : newMsg ( ) ;
if ( nMsgDialog = = NULL ) {
return ;
}
2009-05-18 10:23:55 -04:00
/* fill it in
* files are receommended already
* just need to set peers
*/
std : : cerr < < " SharedFilesDialog::sendLinkTo() " < < std : : endl ;
2012-05-04 19:39:36 -04:00
nMsgDialog - > setTitleText ( tr ( " RetroShare Link " ) ) ;
nMsgDialog - > setMsgText ( RSLinkClipboard : : toHtml ( ) , true ) ;
2010-01-16 13:03:35 -05:00
nMsgDialog - > show ( ) ;
2010-05-02 20:09:55 -04:00
/* window will destroy itself! */
2010-01-16 13:03:35 -05:00
}
2010-11-20 15:58:35 -05:00
# ifdef RS_USE_LINKS
2009-08-17 16:19:53 -04:00
void SharedFilesDialog : : sendLinkToCloud ( )
{
2013-02-22 16:42:27 -05:00
copyLink ( ) ;
2009-08-17 16:19:53 -04:00
2009-08-17 18:06:48 -04:00
AddLinksDialog * nAddLinksDialog = new AddLinksDialog ( QApplication : : clipboard ( ) - > text ( ) ) ;
2009-08-17 16:19:53 -04:00
nAddLinksDialog - > addLinkComment ( ) ;
nAddLinksDialog - > close ( ) ;
2010-05-04 20:05:36 -04:00
/* window will destroy itself! */
2009-08-17 16:19:53 -04:00
}
void SharedFilesDialog : : addLinkToCloud ( )
{
2013-02-22 16:42:27 -05:00
copyLink ( ) ;
2009-08-17 16:19:53 -04:00
2009-08-17 18:06:48 -04:00
AddLinksDialog * nAddLinksDialog = new AddLinksDialog ( QApplication : : clipboard ( ) - > text ( ) ) ;
2009-08-17 16:19:53 -04:00
nAddLinksDialog - > show ( ) ;
2010-05-04 20:05:36 -04:00
/* window will destroy itself! */
2009-08-17 16:19:53 -04:00
}
2010-11-20 15:58:35 -05:00
# endif
2008-11-18 12:14:49 -05:00
2014-05-29 10:49:45 -04:00
void SharedFilesDialog : : collCreate ( )
{
QModelIndexList lst = getSelected ( ) ;
model - > createCollectionFile ( this , lst ) ;
}
void SharedFilesDialog : : collModif ( )
{
std : : list < DirDetails > files_info ;
model - > getFileInfoFromIndexList ( getSelected ( ) , files_info ) ;
if ( files_info . size ( ) ! = 1 ) return ;
/* make path for downloaded files */
std : : list < DirDetails > : : iterator it = files_info . begin ( ) ;
DirDetails details = ( * it ) ;
FileInfo info ;
if ( ! rsFiles - > FileDetails ( details . hash , RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
| RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE
| RS_FILE_HINTS_SPEC_ONLY , info ) ) return ;
std : : string path ;
path = info . path ;
/* open file with a suitable application */
QFileInfo qinfo ;
qinfo . setFile ( QString : : fromUtf8 ( path . c_str ( ) ) ) ;
if ( qinfo . exists ( ) ) {
if ( qinfo . absoluteFilePath ( ) . endsWith ( RsCollectionFile : : ExtensionString ) ) {
RsCollectionFile collection ;
collection . openColl ( qinfo . absoluteFilePath ( ) ) ;
} //if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
} //if (qinfo.exists())
}
void SharedFilesDialog : : collView ( )
{
std : : list < DirDetails > files_info ;
model - > getFileInfoFromIndexList ( getSelected ( ) , files_info ) ;
if ( files_info . size ( ) ! = 1 ) return ;
/* make path for downloaded files */
std : : list < DirDetails > : : iterator it = files_info . begin ( ) ;
DirDetails details = ( * it ) ;
FileInfo info ;
if ( ! rsFiles - > FileDetails ( details . hash , RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
| RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE
| RS_FILE_HINTS_SPEC_ONLY , info ) ) return ;
std : : string path ;
path = info . path ;
/* open file with a suitable application */
QFileInfo qinfo ;
qinfo . setFile ( QString : : fromUtf8 ( path . c_str ( ) ) ) ;
if ( qinfo . exists ( ) ) {
if ( qinfo . absoluteFilePath ( ) . endsWith ( RsCollectionFile : : ExtensionString ) ) {
RsCollectionFile collection ;
collection . openColl ( qinfo . absoluteFilePath ( ) , true ) ;
} //if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
} //if (qinfo.exists())
}
void SharedFilesDialog : : collOpen ( )
{
std : : list < DirDetails > files_info ;
model - > getFileInfoFromIndexList ( getSelected ( ) , files_info ) ;
if ( files_info . size ( ) = = 1 ) {
/* make path for downloaded files */
std : : list < DirDetails > : : iterator it = files_info . begin ( ) ;
DirDetails details = ( * it ) ;
FileInfo info ;
if ( rsFiles - > FileDetails ( details . hash , RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
| RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE
| RS_FILE_HINTS_SPEC_ONLY , info ) ) {
std : : string path ;
path = info . path ;
/* open file with a suitable application */
QFileInfo qinfo ;
qinfo . setFile ( QString : : fromUtf8 ( path . c_str ( ) ) ) ;
if ( qinfo . exists ( ) ) {
if ( qinfo . absoluteFilePath ( ) . endsWith ( RsCollectionFile : : ExtensionString ) ) {
RsCollectionFile collection ;
2016-05-16 05:32:17 -04:00
if ( collection . load ( qinfo . absoluteFilePath ( ) ) ) {
2014-05-29 10:49:45 -04:00
collection . downloadFiles ( ) ;
return ;
2016-05-16 05:32:17 -04:00
}
}
}
}
}
2014-05-29 10:49:45 -04:00
RsCollectionFile collection ;
if ( collection . load ( this ) ) {
collection . downloadFiles ( ) ;
} //if (collection.load(this))
}
2013-02-22 16:42:27 -05:00
void LocalSharedFilesDialog : : playselectedfiles ( )
2008-11-18 12:14:49 -05:00
{
2008-03-31 14:37:50 -04:00
/* call back to the model (which does all the interfacing? */
std : : cerr < < " SharedFilesDialog::playselectedfiles() " ;
std : : cerr < < std : : endl ;
std : : list < std : : string > paths ;
2013-02-22 16:42:27 -05:00
model - > getFilePaths ( getSelected ( ) , paths ) ;
2008-03-31 14:37:50 -04:00
std : : list < std : : string > : : iterator it ;
QStringList fullpaths ;
2014-10-21 18:33:02 -04:00
for ( it = paths . begin ( ) ; it ! = paths . end ( ) ; + + it )
2008-03-31 14:37:50 -04:00
{
2013-02-22 16:42:27 -05:00
std : : string fullpath ;
rsFiles - > ConvertSharedFilePath ( * it , fullpath ) ;
fullpaths . push_back ( QString : : fromStdString ( fullpath ) ) ;
2008-12-03 09:30:21 -05:00
2013-02-22 16:42:27 -05:00
std : : cerr < < " Playing: " < < fullpath ;
std : : cerr < < std : : endl ;
2008-03-31 14:37:50 -04:00
}
playFiles ( fullpaths ) ;
2008-07-10 14:52:56 -04:00
std : : cerr < < " SharedFilesDialog::playselectedfiles() Completed " ;
std : : cerr < < std : : endl ;
2008-03-31 14:37:50 -04:00
}
2010-11-07 16:33:48 -05:00
void SharedFilesDialog : : recommendFilesToMsg ( )
2008-11-18 12:14:49 -05:00
{
2010-11-07 16:33:48 -05:00
std : : list < DirDetails > files_info ;
2007-11-14 22:18:48 -05:00
2013-02-22 16:42:27 -05:00
model - > getFileInfoFromIndexList ( getSelected ( ) , files_info ) ;
2008-07-02 12:59:56 -04:00
2010-11-07 16:33:48 -05:00
if ( files_info . empty ( ) )
return ;
2007-11-14 22:18:48 -05:00
2010-11-07 16:33:48 -05:00
/* create a message */
2007-11-14 22:18:48 -05:00
2010-11-07 16:33:48 -05:00
MessageComposer * nMsgDialog = MessageComposer : : newMsg ( ) ;
if ( nMsgDialog = = NULL ) {
return ;
}
2007-11-14 22:18:48 -05:00
2012-05-04 19:39:36 -04:00
nMsgDialog - > setFileList ( files_info ) ;
nMsgDialog - > setTitleText ( tr ( " Recommendation(s) " ) ) ;
nMsgDialog - > setMsgText ( tr ( " Recommendation(s) " ) ) ;
2010-11-07 16:33:48 -05:00
nMsgDialog - > show ( ) ;
2010-05-02 20:09:55 -04:00
2010-11-07 16:33:48 -05:00
/* window will destroy itself! */
2007-11-14 22:18:48 -05:00
}
2013-02-22 16:42:27 -05:00
void LocalSharedFilesDialog : : openfile ( )
2008-11-18 12:14:49 -05:00
{
2013-02-22 16:42:27 -05:00
/* call back to the model (which does all the interfacing? */
2007-11-14 22:18:48 -05:00
2013-02-22 16:42:27 -05:00
std : : cerr < < " SharedFilesDialog::openfile " < < std : : endl ;
2007-11-14 22:18:48 -05:00
2013-02-22 16:42:27 -05:00
QModelIndexList qmil = getSelected ( ) ;
model - > openSelected ( qmil ) ;
2007-11-14 22:18:48 -05:00
}
2013-02-22 16:42:27 -05:00
void LocalSharedFilesDialog : : openfolder ( )
2008-11-18 12:14:49 -05:00
{
2009-07-07 14:56:31 -04:00
std : : cerr < < " SharedFilesDialog::openfolder " < < std : : endl ;
2007-11-14 22:18:48 -05:00
2013-02-22 16:42:27 -05:00
QModelIndexList qmil = getSelected ( ) ;
model - > openSelected ( qmil ) ;
2008-11-18 12:14:49 -05:00
}
2007-11-14 22:18:48 -05:00
2014-01-05 17:51:54 -05:00
void SharedFilesDialog : : preModDirectories ( bool local )
2007-11-14 22:18:48 -05:00
{
2014-01-05 17:51:54 -05:00
if ( isRemote ( ) = = local ) {
return ;
}
/* Notify both models, only one is visible */
tree_model - > preMods ( ) ;
flat_model - > preMods ( ) ;
2007-11-14 22:18:48 -05:00
}
2016-10-03 15:44:34 -04:00
void SharedFilesDialog : : saveExpandedPathsAndSelection ( std : : set < std : : string > & expanded_indexes , std : : set < std : : string > & selected_indexes )
2016-08-28 17:14:39 -04:00
{
2016-08-29 15:30:56 -04:00
if ( ui . dirTreeView - > model ( ) = = NULL )
return ;
2016-09-08 17:43:14 -04:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-29 15:30:56 -04:00
std : : cerr < < " Saving expanded items. " < < std : : endl ;
2016-09-08 17:43:14 -04:00
# endif
2016-08-28 17:14:39 -04:00
for ( int row = 0 ; row < ui . dirTreeView - > model ( ) - > rowCount ( ) ; + + row )
{
std : : string path = ui . dirTreeView - > model ( ) - > index ( row , 0 ) . data ( Qt : : DisplayRole ) . toString ( ) . toStdString ( ) ;
2016-10-03 15:44:34 -04:00
recursSaveExpandedItems ( ui . dirTreeView - > model ( ) - > index ( row , 0 ) , path , expanded_indexes , selected_indexes ) ;
2016-08-28 17:14:39 -04:00
}
}
2016-10-03 15:44:34 -04:00
void SharedFilesDialog : : restoreExpandedPathsAndSelection ( const std : : set < std : : string > & expanded_indexes , const std : : set < std : : string > & selected_indexes )
2016-08-28 17:14:39 -04:00
{
2016-08-29 15:30:56 -04:00
if ( ui . dirTreeView - > model ( ) = = NULL )
return ;
2016-09-14 15:52:16 -04:00
// we need to disable this, because the signal will trigger unnecessary update at the friend.
ui . dirTreeView - > blockSignals ( true ) ;
2016-09-08 17:43:14 -04:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 17:14:39 -04:00
std : : cerr < < " Restoring expanded items. " < < std : : endl ;
2016-09-08 17:43:14 -04:00
# endif
2016-08-28 17:14:39 -04:00
for ( int row = 0 ; row < ui . dirTreeView - > model ( ) - > rowCount ( ) ; + + row )
{
std : : string path = ui . dirTreeView - > model ( ) - > index ( row , 0 ) . data ( Qt : : DisplayRole ) . toString ( ) . toStdString ( ) ;
2016-10-03 15:44:34 -04:00
recursRestoreExpandedItems ( ui . dirTreeView - > model ( ) - > index ( row , 0 ) , path , expanded_indexes , selected_indexes ) ;
2016-08-28 17:14:39 -04:00
}
2016-10-03 15:44:34 -04:00
QItemSelection selection ;
2016-09-14 15:52:16 -04:00
ui . dirTreeView - > blockSignals ( false ) ;
2016-08-28 17:14:39 -04:00
}
2016-10-03 15:44:34 -04:00
void SharedFilesDialog : : recursSaveExpandedItems ( const QModelIndex & index , const std : : string & path , std : : set < std : : string > & exp , std : : set < std : : string > & sel )
2016-08-28 17:14:39 -04:00
{
std : : string local_path = path + " / " + index . data ( Qt : : DisplayRole ) . toString ( ) . toStdString ( ) ;
2016-09-08 17:43:14 -04:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 17:14:39 -04:00
std : : cerr < < " at index " < < index . row ( ) < < " . data[1]= " < < local_path < < std : : endl ;
2016-09-08 17:43:14 -04:00
# endif
2016-08-28 17:14:39 -04:00
2016-10-03 15:44:34 -04:00
if ( ui . dirTreeView - > selectionModel ( ) - > selection ( ) . contains ( index ) )
sel . insert ( local_path ) ;
2016-08-28 17:14:39 -04:00
if ( ui . dirTreeView - > isExpanded ( index ) )
{
2016-09-08 17:43:14 -04:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 17:14:39 -04:00
std : : cerr < < " Index " < < local_path < < " is expanded. " < < std : : endl ;
2016-09-08 17:43:14 -04:00
# endif
2016-08-28 17:14:39 -04:00
if ( index . isValid ( ) )
exp . insert ( local_path ) ;
for ( int row = 0 ; row < ui . dirTreeView - > model ( ) - > rowCount ( index ) ; + + row )
2016-10-03 15:44:34 -04:00
recursSaveExpandedItems ( index . child ( row , 0 ) , local_path , exp , sel ) ;
2016-08-28 17:14:39 -04:00
}
2016-09-08 17:43:14 -04:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 17:14:39 -04:00
else
std : : cerr < < " Index is not expanded. " < < std : : endl ;
2016-09-08 17:43:14 -04:00
# endif
2016-08-28 17:14:39 -04:00
}
2016-10-03 15:44:34 -04:00
void SharedFilesDialog : : recursRestoreExpandedItems ( const QModelIndex & index , const std : : string & path , const std : : set < std : : string > & exp , const std : : set < std : : string > & sel )
2016-08-28 17:14:39 -04:00
{
std : : string local_path = path + " / " + index . data ( Qt : : DisplayRole ) . toString ( ) . toStdString ( ) ;
2016-09-08 17:43:14 -04:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 17:14:39 -04:00
std : : cerr < < " at index " < < index . row ( ) < < " . data[1]= " < < local_path < < std : : endl ;
2016-09-08 17:43:14 -04:00
# endif
2016-10-03 15:44:34 -04:00
if ( sel . find ( local_path ) ! = sel . end ( ) )
ui . dirTreeView - > selectionModel ( ) - > select ( index , QItemSelectionModel : : Select | QItemSelectionModel : : Rows ) ;
2016-08-28 17:14:39 -04:00
if ( exp . find ( local_path ) ! = exp . end ( ) )
{
2016-09-08 17:43:14 -04:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 17:14:39 -04:00
std : : cerr < < " re expanding index " < < local_path < < std : : endl ;
2016-09-08 17:43:14 -04:00
# endif
2016-08-28 17:14:39 -04:00
ui . dirTreeView - > setExpanded ( index , true ) ;
for ( int row = 0 ; row < ui . dirTreeView - > model ( ) - > rowCount ( index ) ; + + row )
2016-10-03 15:44:34 -04:00
recursRestoreExpandedItems ( index . child ( row , 0 ) , local_path , exp , sel ) ;
2016-08-28 17:14:39 -04:00
}
}
2014-01-05 17:51:54 -05:00
void SharedFilesDialog : : postModDirectories ( bool local )
2007-11-14 22:18:48 -05:00
{
2016-08-17 08:48:54 -04:00
if ( isRemote ( ) = = local ) {
2016-08-28 17:14:39 -04:00
return ;
}
2016-10-03 15:44:34 -04:00
std : : set < std : : string > expanded_indexes , selected_indexes ;
saveExpandedPathsAndSelection ( expanded_indexes , selected_indexes ) ;
2016-09-08 17:43:14 -04:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-29 15:30:56 -04:00
std : : cerr < < " Saving expanded items. " < < expanded_indexes . size ( ) < < " items found " < < std : : endl ;
2016-09-08 17:43:14 -04:00
# endif
2014-01-05 17:51:54 -05:00
2016-08-28 17:14:39 -04:00
/* Notify both models, only one is visible */
2014-01-05 17:51:54 -05:00
tree_model - > postMods ( ) ;
flat_model - > postMods ( ) ;
2013-02-22 16:42:27 -05:00
ui . dirTreeView - > update ( ) ;
2010-11-30 07:29:04 -05:00
2016-10-03 15:44:34 -04:00
restoreExpandedPathsAndSelection ( expanded_indexes , selected_indexes ) ;
2016-08-28 17:14:39 -04:00
if ( ui . filterPatternLineEdit - > text ( ) . isEmpty ( ) = = false )
2013-02-22 16:42:27 -05:00
FilterItems ( ) ;
2009-08-11 14:14:55 -04:00
2016-09-08 17:43:14 -04:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 17:14:39 -04:00
std : : cerr < < " ****** updated directories! ****** " < < std : : endl ;
2016-09-08 17:43:14 -04:00
# endif
2009-08-11 14:14:55 -04:00
QCoreApplication : : flush ( ) ;
2007-11-14 22:18:48 -05:00
}
2013-02-22 16:42:27 -05:00
void LocalSharedFilesDialog : : spawnCustomPopupMenu ( QPoint point )
2008-11-18 12:14:49 -05:00
{
2014-05-29 10:49:45 -04:00
if ( ! rsPeers ) return ; /* not ready yet! */
QModelIndex idx = ui . dirTreeView - > indexAt ( point ) ;
if ( ! idx . isValid ( ) ) return ;
QModelIndex midx = proxyModel - > mapToSource ( idx ) ;
if ( ! midx . isValid ( ) ) return ;
currentFile = model - > data ( midx , RetroshareDirModel : : FileNameRole ) . toString ( ) ;
int type = model - > getType ( midx ) ;
if ( type ! = DIR_TYPE_DIR & & type ! = DIR_TYPE_FILE ) return ;
QMenu contextMnu ( this ) ;
bool bIsRsColl = currentFile . endsWith ( RsCollectionFile : : ExtensionString ) ;
collCreateAct - > setEnabled ( true ) ;
collModifAct - > setEnabled ( bIsRsColl ) ;
collViewAct - > setEnabled ( bIsRsColl ) ;
collOpenAct - > setEnabled ( true ) ;
QMenu collectionMenu ( tr ( " Collection " ) , this ) ;
collectionMenu . setIcon ( QIcon ( IMAGE_LIBRARY ) ) ;
collectionMenu . addAction ( collCreateAct ) ;
collectionMenu . addAction ( collModifAct ) ;
collectionMenu . addAction ( collViewAct ) ;
collectionMenu . addAction ( collOpenAct ) ;
switch ( type ) {
case DIR_TYPE_DIR :
contextMnu . addAction ( openfolderAct ) ;
contextMnu . addSeparator ( ) ; //------------------------------------
contextMnu . addMenu ( & collectionMenu ) ;
break ;
case DIR_TYPE_FILE :
contextMnu . addAction ( openfileAct ) ;
contextMnu . addSeparator ( ) ; //------------------------------------
contextMnu . addAction ( copylinkAct ) ;
contextMnu . addAction ( sendlinkAct ) ;
contextMnu . addSeparator ( ) ; //------------------------------------
contextMnu . addMenu ( & collectionMenu ) ;
contextMnu . addSeparator ( ) ; //------------------------------------
2010-11-20 15:58:35 -05:00
# ifdef RS_USE_LINKS
2014-05-29 10:49:45 -04:00
contextMnu . addAction ( sendlinkCloudAct ) ;
contextMnu . addAction ( addlinkCloudAct ) ;
contextMnu . addSeparator ( ) ; //------------------------------------
2010-02-07 15:10:31 -05:00
# endif
2014-05-29 10:49:45 -04:00
contextMnu . addAction ( QIcon ( IMAGE_MSG ) , tr ( " Recommend in a message to " ) , this , SLOT ( recommendFilesToMsg ( ) ) ) ;
break ;
2007-11-14 22:18:48 -05:00
2014-05-29 10:49:45 -04:00
default :
return ;
} //switch (type)
contextMnu . exec ( QCursor : : pos ( ) ) ;
2009-04-07 04:08:03 -04:00
}
2007-11-14 22:18:48 -05:00
2009-04-07 04:08:03 -04:00
//============================================================================
QAction *
2013-02-22 16:42:27 -05:00
LocalSharedFilesDialog : : fileAssotiationAction ( const QString /*fileName*/ )
2009-04-07 04:08:03 -04:00
{
2014-05-29 10:49:45 -04:00
QAction * result = NULL ;
2009-04-07 04:08:03 -04:00
2010-05-20 17:53:27 -04:00
Settings - > beginGroup ( " FileAssotiations " ) ;
2009-04-07 04:08:03 -04:00
2009-12-14 12:13:10 -05:00
QString key = AddFileAssociationDialog : : cleanFileType ( currentFile ) ;
2010-05-20 17:53:27 -04:00
if ( Settings - > contains ( key ) )
2009-04-07 04:08:03 -04:00
{
result = new QAction ( QIcon ( IMAGE_PLAY ) , tr ( " Open File " ) , this ) ;
connect ( result , SIGNAL ( triggered ( ) ) ,
this , SLOT ( runCommandForFile ( ) ) ) ;
2010-05-20 17:53:27 -04:00
currentCommand = ( Settings - > value ( key ) ) . toString ( ) ;
2009-04-07 04:08:03 -04:00
}
else
{
result = new QAction ( QIcon ( Image_AddNewAssotiationForFile ) ,
tr ( " Set command for opening this file " ) , this ) ;
connect ( result , SIGNAL ( triggered ( ) ) ,
this , SLOT ( tryToAddNewAssotiation ( ) ) ) ;
}
2010-05-20 17:53:27 -04:00
Settings - > endGroup ( ) ;
2009-04-07 04:08:03 -04:00
return result ;
}
//============================================================================
void
2013-02-22 16:42:27 -05:00
LocalSharedFilesDialog : : runCommandForFile ( )
2009-04-07 04:08:03 -04:00
{
QStringList tsl ;
tsl . append ( currentFile ) ;
QProcess : : execute ( currentCommand , tsl ) ;
}
//============================================================================
void
2013-02-22 16:42:27 -05:00
LocalSharedFilesDialog : : tryToAddNewAssotiation ( )
2009-04-07 04:08:03 -04:00
{
2009-12-14 12:13:10 -05:00
AddFileAssociationDialog afad ( true , this ) ; //'add file assotiations' dialog
2009-04-07 04:08:03 -04:00
2009-12-14 12:13:10 -05:00
afad . setFileType ( AddFileAssociationDialog : : cleanFileType ( currentFile ) ) ;
2009-04-07 04:08:03 -04:00
int ti = afad . exec ( ) ;
if ( ti = = QDialog : : Accepted )
{
QString currType = afad . resultFileType ( ) ;
QString currCmd = afad . resultCommand ( ) ;
2009-07-07 14:56:31 -04:00
2010-05-20 17:53:27 -04:00
Settings - > setValueToGroup ( " FileAssotiations " , currType , currCmd ) ;
2009-04-07 04:08:03 -04:00
}
2007-11-14 22:18:48 -05:00
}
2009-10-13 16:36:29 -04:00
void SharedFilesDialog : : indicatorChanged ( int index )
{
2010-02-08 17:32:00 -05:00
static uint32_t correct_indicator [ 4 ] = { IND_ALWAYS , IND_LAST_DAY , IND_LAST_WEEK , IND_LAST_MONTH } ;
model - > changeAgeIndicator ( correct_indicator [ index ] ) ;
2013-02-22 16:42:27 -05:00
ui . dirTreeView - > update ( ui . dirTreeView - > rootIndex ( ) ) ;
2014-05-29 10:49:45 -04:00
2011-05-21 14:34:34 -04:00
if ( correct_indicator [ index ] ! = IND_ALWAYS )
2014-05-29 10:49:45 -04:00
ui . dirTreeView - > sortByColumn ( COLUMN_AGE , Qt : : AscendingOrder ) ;
2011-05-21 14:34:34 -04:00
else
2014-05-29 10:49:45 -04:00
ui . dirTreeView - > sortByColumn ( COLUMN_NAME , Qt : : AscendingOrder ) ;
2010-02-08 18:09:46 -05:00
2011-05-21 14:34:34 -04:00
updateDisplay ( ) ;
2009-10-13 16:36:29 -04:00
}
2010-11-30 07:29:04 -05:00
void SharedFilesDialog : : filterRegExpChanged ( )
{
QString text = ui . filterPatternLineEdit - > text ( ) ;
if ( text . isEmpty ( ) ) {
ui . filterClearButton - > hide ( ) ;
} else {
ui . filterClearButton - > show ( ) ;
}
if ( text = = lastFilterString ) {
ui . filterStartButton - > hide ( ) ;
} else {
ui . filterStartButton - > show ( ) ;
}
}
/* clear Filter */
void SharedFilesDialog : : clearFilter ( )
{
ui . filterPatternLineEdit - > clear ( ) ;
ui . filterPatternLineEdit - > setFocus ( ) ;
startFilter ( ) ;
}
/* clear Filter */
void SharedFilesDialog : : startFilter ( )
{
ui . filterStartButton - > hide ( ) ;
lastFilterString = ui . filterPatternLineEdit - > text ( ) ;
FilterItems ( ) ;
}
void SharedFilesDialog : : FilterItems ( )
{
2016-01-09 06:09:43 -05:00
# ifdef DONT_USE_SEARCH_IN_TREE_VIEW
if ( proxyModel = = tree_proxyModel )
return ;
# endif
2010-11-30 07:29:04 -05:00
QString text = ui . filterPatternLineEdit - > text ( ) ;
setCursor ( Qt : : WaitCursor ) ;
2011-04-01 17:46:06 -04:00
QCoreApplication : : processEvents ( ) ;
2010-11-30 07:29:04 -05:00
2013-02-22 16:42:27 -05:00
int rowCount = ui . dirTreeView - > model ( ) - > rowCount ( ) ;
2014-10-21 18:33:02 -04:00
for ( int row = 0 ; row < rowCount ; + + row )
2011-04-01 17:46:06 -04:00
if ( proxyModel = = tree_proxyModel )
2014-05-29 10:49:45 -04:00
tree_FilterItem ( ui . dirTreeView - > model ( ) - > index ( row , COLUMN_NAME ) , text , 0 ) ;
2011-04-01 17:46:06 -04:00
else
2014-05-29 10:49:45 -04:00
flat_FilterItem ( ui . dirTreeView - > model ( ) - > index ( row , COLUMN_NAME ) , text , 0 ) ;
2010-11-30 07:29:04 -05:00
setCursor ( Qt : : ArrowCursor ) ;
}
2011-08-12 10:06:29 -04:00
bool SharedFilesDialog : : flat_FilterItem ( const QModelIndex & index , const QString & text , int /*level*/ )
2011-04-01 17:46:06 -04:00
{
if ( index . data ( RetroshareDirModel : : FileNameRole ) . toString ( ) . contains ( text , Qt : : CaseInsensitive ) )
{
2013-02-22 16:42:27 -05:00
ui . dirTreeView - > setRowHidden ( index . row ( ) , index . parent ( ) , false ) ;
2011-04-01 17:46:06 -04:00
return false ;
}
else
{
2013-02-22 16:42:27 -05:00
ui . dirTreeView - > setRowHidden ( index . row ( ) , index . parent ( ) , true ) ;
2011-04-01 17:46:06 -04:00
return true ;
}
}
bool SharedFilesDialog : : tree_FilterItem ( const QModelIndex & index , const QString & text , int level )
2010-11-30 07:29:04 -05:00
{
bool visible = true ;
if ( text . isEmpty ( ) = = false ) {
2011-04-01 17:46:06 -04:00
// better use RetroshareDirModel::getType, but its slow enough
2010-11-30 07:29:04 -05:00
if ( /*index.parent().isValid()*/ level > = 1 ) {
2011-04-01 17:46:06 -04:00
if ( index . data ( RetroshareDirModel : : FileNameRole ) . toString ( ) . contains ( text , Qt : : CaseInsensitive ) = = false ) {
2010-11-30 07:29:04 -05:00
visible = false ;
}
} else {
visible = false ;
}
}
int visibleChildCount = 0 ;
2013-02-22 16:42:27 -05:00
int rowCount = ui . dirTreeView - > model ( ) - > rowCount ( index ) ;
2014-10-21 18:33:02 -04:00
for ( int row = 0 ; row < rowCount ; + + row ) {
2013-02-22 16:42:27 -05:00
if ( tree_FilterItem ( ui . dirTreeView - > model ( ) - > index ( row , index . column ( ) , index ) , text , level + 1 ) ) {
2014-10-21 18:33:02 -04:00
+ + visibleChildCount ;
2010-11-30 07:29:04 -05:00
}
}
if ( visible | | visibleChildCount ) {
2013-02-22 16:42:27 -05:00
ui . dirTreeView - > setRowHidden ( index . row ( ) , index . parent ( ) , false ) ;
2010-11-30 07:29:04 -05:00
} else {
2013-02-22 16:42:27 -05:00
ui . dirTreeView - > setRowHidden ( index . row ( ) , index . parent ( ) , true ) ;
2010-11-30 07:29:04 -05:00
}
return ( visible | | visibleChildCount ) ;
}
2011-04-01 17:46:06 -04:00