2007-11-15 03:18:48 +00: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 18:56:31 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor ,
2007-11-15 03:18:48 +00:00
* Boston , MA 02110 - 1301 , USA .
2008-11-18 17:14:49 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2018-02-19 20:13:38 +01:00
# include "SharedFilesDialog.h"
2010-07-23 18:52:58 +00:00
2018-01-24 21:14:26 +01:00
# include "rshare.h"
2017-10-21 21:23:40 +02:00
# include "gui/MainWindow.h"
2018-02-19 20:13:38 +01:00
# include "gui/notifyqt.h"
2017-09-07 19:37:53 +02:00
# include "gui/RemoteDirModel.h"
# include "gui/RetroShareLink.h"
# include "gui/ShareManager.h"
# include "gui/common/PeerDefs.h"
2017-10-19 22:14:04 +02:00
# include "gui/common/RsCollection.h"
2017-09-07 19:37:53 +02:00
# include "gui/msgs/MessageComposer.h"
2017-10-21 21:23:40 +02:00
# include "gui/gxschannels/GxsChannelDialog.h"
2017-10-29 20:33:56 +01:00
# include "gui/gxsforums/GxsForumsDialog.h"
2018-02-19 20:13:38 +01:00
# include "gui/settings/AddFileAssociationDialog.h"
2017-09-07 19:37:53 +02:00
# include "gui/settings/rsharesettings.h"
# include "util/QtVersion.h"
# include "util/RsAction.h"
2009-05-18 14:23:55 +00:00
2018-01-24 21:14:26 +01:00
# include <retroshare/rsexpr.h>
2018-02-19 20:13:38 +01:00
# include <retroshare/rsfiles.h>
# include <retroshare/rspeers.h>
# include <QClipboard>
# include <QMenu>
# include <QMessageBox>
# include <QPainter>
# include <QProcess>
# include <QSortFilterProxyModel>
# include <QString>
# include <QStyledItemDelegate>
# include <QTreeView>
2007-11-15 03:18:48 +00:00
2018-02-19 20:13:38 +01:00
# include <set>
2009-04-07 08:08:03 +00:00
2007-11-15 03:18:48 +00:00
/* Images for context menu icons */
2008-08-07 10:48:18 +00:00
# define IMAGE_DOWNLOAD ": / images / download16.png"
2008-11-18 17:14:49 +00:00
# define IMAGE_PLAY ": / images / start.png"
2008-03-31 18:37:50 +00:00
# define IMAGE_HASH_BUSY ": / images / settings.png"
2009-07-11 00:45:17 +00:00
# define IMAGE_HASH_DONE ": / images / accepted16.png"
2008-04-05 14:37:22 +00:00
# define IMAGE_MSG ": / images / message-mail.png"
# define IMAGE_ATTACHMENT ": / images / attachment.png"
# define IMAGE_FRIEND ": / images / peers_16x16.png"
2008-04-05 20:03:25 +00:00
# define IMAGE_PROGRESS ": / images / browse-looking.gif"
2009-05-18 14:23:55 +00:00
# define IMAGE_COPYLINK ": / images / copyrslink.png"
2012-12-05 13:26:26 +00:00
# define IMAGE_OPENFOLDER ": / images / folderopen.png"
2014-05-29 14:49:45 +00:00
# define IMAGE_OPENFILE ": / images / fileopen.png"
# define IMAGE_LIBRARY ": / images / library.png"
2017-10-21 21:23:40 +02:00
# define IMAGE_CHANNEL ": / images / channels32.png"
2017-10-29 20:33:56 +01:00
# define IMAGE_FORUMS ": / icons / png / forums.png"
2014-05-29 14:49:45 +00:00
# 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-27 00:23:56 +00:00
# define IMAGE_EDITSHARE ": / images / edit_16.png"
2016-08-30 17:18:27 +02:00
# define IMAGE_MYFILES ": / icons / svg / folders1.svg"
2009-05-18 14:23:55 +00:00
2014-05-29 14:49:45 +00:00
/*define viewType_CB value */
# define VIEW_TYPE_TREE 0
# define VIEW_TYPE_FLAT 1
2018-01-24 21:14:26 +01:00
# define MAX_SEARCH_RESULTS 3000
2011-04-03 19:59:12 +00:00
// Define to avoid using the search in treeview, because it is really slow for now.
//
2018-01-23 22:18:35 +01:00
//#define DONT_USE_SEARCH_IN_TREE_VIEW 1
2011-04-03 19:59:12 +00:00
2016-09-08 23:43:14 +02:00
//#define DEBUG_SHARED_FILES_DIALOG 1
2009-04-07 08:08:03 +00:00
const QString Image_AddNewAssotiationForFile = " :/images/kcmsystem24.png " ;
2008-04-05 14:37:22 +00:00
2010-09-20 00:10:51 +00:00
class SFDSortFilterProxyModel : public QSortFilterProxyModel
{
public :
2011-04-01 21:46:06 +00:00
SFDSortFilterProxyModel ( RetroshareDirModel * dirModel , QObject * parent ) : QSortFilterProxyModel ( parent )
2010-09-20 00:10:51 +00:00
{
m_dirModel = dirModel ;
2014-01-05 22:51:54 +00:00
}
2010-09-20 00:10:51 +00:00
protected :
virtual bool lessThan ( const QModelIndex & left , const QModelIndex & right ) const
{
2010-11-07 21:33:48 +00:00
bool dirLeft = ( m_dirModel - > getType ( left ) = = DIR_TYPE_DIR ) ;
bool dirRight = ( m_dirModel - > getType ( right ) = = DIR_TYPE_DIR ) ;
2010-09-20 00:10:51 +00:00
if ( dirLeft ^ dirRight ) {
return dirLeft ;
}
return QSortFilterProxyModel : : lessThan ( left , right ) ;
}
private :
2011-04-01 21:46:06 +00:00
RetroshareDirModel * m_dirModel ;
2010-09-20 00:10:51 +00:00
} ;
2008-11-18 17:14:49 +00:00
2016-11-01 10:30:36 +01: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 17:14:49 +00:00
/** Constructor */
2013-02-22 21:42:27 +00:00
SharedFilesDialog : : SharedFilesDialog ( RetroshareDirModel * _tree_model , RetroshareDirModel * _flat_model , QWidget * parent )
2011-04-14 21:58:15 +00:00
: RsAutoUpdatePage ( 1000 , parent ) , model ( NULL )
2008-11-18 17:14:49 +00:00
{
2011-04-06 00:19:56 +00:00
/* Invoke the Qt Designer generated object setup routine */
ui . setupUi ( this ) ;
2009-07-07 18:56:31 +00:00
2014-01-05 22:51:54 +00:00
NotifyQt * notify = NotifyQt : : getInstance ( ) ;
connect ( notify , SIGNAL ( filesPreModChanged ( bool ) ) , this , SLOT ( preModDirectories ( bool ) ) ) ;
connect ( notify , SIGNAL ( filesPostModChanged ( bool ) ) , this , SLOT ( postModDirectories ( bool ) ) ) ;
2011-04-06 00:19:56 +00:00
connect ( ui . viewType_CB , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( changeCurrentViewModel ( int ) ) ) ;
2009-07-20 17:03:27 +00:00
2013-02-22 21:42:27 +00:00
connect ( ui . dirTreeView , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( spawnCustomPopupMenu ( QPoint ) ) ) ;
2009-01-02 00:09:59 +00:00
2009-10-13 20:36:29 +00:00
connect ( ui . indicatorCBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( indicatorChanged ( int ) ) ) ;
2009-01-02 00:09:59 +00:00
2013-02-22 21:42:27 +00:00
tree_model = _tree_model ;
flat_model = _flat_model ;
2018-02-24 18:15:54 +01:00
connect ( flat_model , SIGNAL ( layoutChanged ( ) ) , this , SLOT ( updateDirTreeView ( ) ) ) ;
2007-11-15 03:18:48 +00:00
2011-04-06 00:19:56 +00: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 14:49:45 +00:00
tree_proxyModel - > sort ( COLUMN_NAME ) ;
2010-09-20 00:10:51 +00:00
2016-09-13 21:23:27 +02: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 12:07:38 +01: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 12:02:54 +01:00
tree_proxyModel - > setDynamicSortFilter ( false ) ;
flat_proxyModel - > setDynamicSortFilter ( false ) ;
2016-09-13 21:23:27 +02:00
connect ( ui . filterClearButton , SIGNAL ( clicked ( ) ) , this , SLOT ( clearFilter ( ) ) ) ;
2011-04-06 00:19:56 +00: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 18:56:31 +00:00
2011-04-06 00:19:56 +00:00
/* Set header resize modes and initial section sizes */
2013-02-22 21:42:27 +00:00
QHeaderView * header = ui . dirTreeView - > header ( ) ;
2009-01-31 01:46:49 +00:00
2014-05-29 14:49:45 +00:00
header - > resizeSection ( COLUMN_NAME , 490 ) ;
2018-02-19 20:13:38 +01:00
header - > resizeSection ( COLUMN_FILENB , 70 ) ;
header - > resizeSection ( COLUMN_SIZE , 70 ) ;
header - > resizeSection ( COLUMN_AGE , 100 ) ;
header - > resizeSection ( COLUMN_FRIEND_ACCESS , 100 ) ;
header - > resizeSection ( COLUMN_WN_VISU_DIR , 100 ) ;
2009-01-31 01:46:49 +00:00
2013-02-22 21:42:27 +00:00
header - > setStretchLastSection ( false ) ;
2008-08-07 18:49:57 +00:00
2011-04-06 00:19:56 +00:00
/* Set Multi Selection */
2013-02-22 21:42:27 +00:00
ui . dirTreeView - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
2011-04-01 21:46:06 +00:00
2008-11-18 17:14:49 +00:00
/* Hide platform specific features */
2013-02-22 21:42:27 +00: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 20:46:45 +00:00
sendlinkAct = new QAction ( QIcon ( IMAGE_COPYLINK ) , tr ( " Send retroshare Links " ) , this ) ;
connect ( sendlinkAct , SIGNAL ( triggered ( ) ) , this , SLOT ( sendLinkTo ( ) ) ) ;
2014-05-29 14:49:45 +00: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 21:42:27 +00:00
}
LocalSharedFilesDialog : : LocalSharedFilesDialog ( QWidget * parent )
: SharedFilesDialog ( new TreeStyle_RDM ( false ) , new FlatStyle_RDM ( false ) , parent )
{
// Hide columns after loading the settings
2018-02-19 20:13:38 +01:00
ui . dirTreeView - > setColumnHidden ( COLUMN_WN_VISU_DIR , false ) ;
2013-02-22 21:42:27 +00:00
ui . downloadButton - > hide ( ) ;
// load settings
processSettings ( true ) ;
// Setup the current view model.
//
changeCurrentViewModel ( ui . viewType_CB - > currentIndex ( ) ) ;
2014-05-29 14:49:45 +00:00
connect ( ui . addShares_PB , SIGNAL ( clicked ( ) ) , this , SLOT ( addShares ( ) ) ) ;
connect ( ui . checkButton , SIGNAL ( clicked ( ) ) , this , SLOT ( forceCheck ( ) ) ) ;
2013-02-22 21:42:27 +00:00
2014-05-29 14:49:45 +00: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 ( ) ) ) ;
2013-02-22 21:42:27 +00:00
2016-11-01 10:30:36 +01:00
ui . titleBarPixmap - > setPixmap ( QPixmap ( IMAGE_MYFILES ) ) ;
2018-02-19 20:13:38 +01:00
ui . dirTreeView - > setItemDelegateForColumn ( COLUMN_FRIEND_ACCESS , new ShareFlagsItemDelegate ( ) ) ;
2010-09-20 00:10:51 +00:00
}
2010-03-28 20:46:45 +00:00
2013-02-22 21:42:27 +00:00
RemoteSharedFilesDialog : : RemoteSharedFilesDialog ( QWidget * parent )
: SharedFilesDialog ( new TreeStyle_RDM ( true ) , new FlatStyle_RDM ( true ) , parent )
{
2018-02-19 20:13:38 +01:00
ui . dirTreeView - > setColumnHidden ( COLUMN_FRIEND_ACCESS , false ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_WN_VISU_DIR , true ) ;
2013-02-22 21:42:27 +00:00
ui . checkButton - > hide ( ) ;
connect ( ui . downloadButton , SIGNAL ( clicked ( ) ) , this , SLOT ( downloadRemoteSelected ( ) ) ) ;
2018-03-03 12:05:13 +01:00
connect ( ui . dirTreeView , SIGNAL ( expanded ( const QModelIndex & ) ) , this , SLOT ( expanded ( const QModelIndex & ) ) ) ;
connect ( ui . dirTreeView , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( expanded ( const QModelIndex & ) ) ) ;
2013-02-22 21:42:27 +00: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 21:58:15 +00:00
void SharedFilesDialog : : hideEvent ( QHideEvent * )
{
if ( model ! = NULL )
model - > setVisible ( false ) ;
}
2018-01-28 21:54:56 +01:00
2011-04-14 21:58:15 +00:00
void SharedFilesDialog : : showEvent ( QShowEvent * )
{
if ( model ! = NULL )
{
2018-01-24 22:02:49 +01:00
std : : set < std : : string > expanded_indexes , hidden_indexes , selected_indexes ;
2016-10-03 21:44:34 +02:00
2018-01-24 22:02:49 +01:00
saveExpandedPathsAndSelection ( expanded_indexes , hidden_indexes , selected_indexes ) ;
2016-08-29 21:30:56 +02:00
2018-01-28 21:54:56 +01:00
model - > setVisible ( true ) ;
model - > update ( ) ;
2016-08-29 21:30:56 +02:00
2018-01-24 22:02:49 +01:00
restoreExpandedPathsAndSelection ( expanded_indexes , hidden_indexes , selected_indexes ) ;
2016-08-29 21:30:56 +02:00
}
2011-04-14 21:58:15 +00:00
}
2013-02-22 21:42:27 +00:00
RemoteSharedFilesDialog : : ~ RemoteSharedFilesDialog ( )
{
// save settings
processSettings ( false ) ;
}
LocalSharedFilesDialog : : ~ LocalSharedFilesDialog ( )
2010-09-20 00:10:51 +00:00
{
// save settings
processSettings ( false ) ;
}
2010-03-28 20:46:45 +00:00
2013-02-22 21:42:27 +00: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-20 00:10:51 +00:00
{
2018-03-03 12:08:21 +01:00
Settings - > beginGroup ( " RemoteSharedFilesDialog " ) ;
2010-09-20 00:10:51 +00:00
2011-04-06 00:19:56 +00:00
if ( bLoad ) {
// load settings
2010-09-20 00:10:51 +00:00
2011-04-06 00:19:56 +00:00
// state of the trees
2013-02-22 21:42:27 +00:00
ui . dirTreeView - > header ( ) - > restoreState ( Settings - > value ( " RemoteDirTreeView " ) . toByteArray ( ) ) ;
2010-09-20 00:10:51 +00:00
2011-04-06 00:19:56 +00:00
// state of splitter
2013-02-22 21:42:27 +00:00
ui . splitter - > restoreState ( Settings - > value ( " RemoteSplitter " ) . toByteArray ( ) ) ;
2010-09-20 00:10:51 +00:00
2011-04-06 00:19:56 +00:00
// view type
2013-02-22 21:42:27 +00:00
ui . viewType_CB - > setCurrentIndex ( Settings - > value ( " RemoteViewType " ) . toInt ( ) ) ;
2011-04-06 00:19:56 +00:00
} else {
// save settings
2010-09-20 00:10:51 +00:00
2011-04-06 00:19:56 +00:00
// state of trees
2013-02-22 21:42:27 +00:00
Settings - > setValue ( " RemoteDirTreeView " , ui . dirTreeView - > header ( ) - > saveState ( ) ) ;
2011-04-06 00:19:56 +00:00
// state of splitter
2013-02-22 21:42:27 +00:00
Settings - > setValue ( " RemoteSplitter " , ui . splitter - > saveState ( ) ) ;
2011-04-06 00:19:56 +00:00
// view type
2013-02-22 21:42:27 +00:00
Settings - > setValue ( " RemoteViewType " , ui . viewType_CB - > currentIndex ( ) ) ;
2011-04-06 00:19:56 +00:00
}
2010-09-20 00:10:51 +00:00
2011-04-06 00:19:56 +00:00
Settings - > endGroup ( ) ;
2008-11-18 17:14:49 +00:00
}
2007-11-15 03:18:48 +00:00
2014-05-29 14:49:45 +00:00
void SharedFilesDialog : : changeCurrentViewModel ( int viewTypeIndex )
2011-04-01 21:46:06 +00:00
{
2016-08-28 23:14:39 +02:00
// disconnect( ui.dirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), NULL, NULL );
// disconnect( ui.dirTreeView, SIGNAL( expanded(const QModelIndex & ) ), NULL, NULL );
2011-04-01 21:46:06 +00:00
2011-04-14 21:58:15 +00:00
if ( model ! = NULL )
model - > setVisible ( false ) ;
2014-05-29 14:49:45 +00:00
if ( viewTypeIndex = = VIEW_TYPE_TREE )
2011-04-01 21:46:06 +00:00
{
model = tree_model ;
2016-09-13 21:23:27 +02:00
proxyModel = tree_proxyModel ;
2011-04-01 21:46:06 +00:00
}
else
{
model = flat_model ;
2016-09-13 21:23:27 +02:00
proxyModel = flat_proxyModel ;
}
2011-04-01 21:46:06 +00:00
2013-02-22 21:42:27 +00:00
showProperColumns ( ) ;
2018-01-24 22:02:49 +01:00
std : : set < std : : string > expanded_indexes , hidden_indexes , selected_indexes ;
2016-10-03 21:44:34 +02:00
2018-01-24 22:02:49 +01:00
saveExpandedPathsAndSelection ( expanded_indexes , hidden_indexes , selected_indexes ) ;
2016-08-29 21:30:56 +02:00
if ( isVisible ( ) )
2011-04-14 21:58:15 +00:00
{
2016-08-29 21:30:56 +02:00
model - > setVisible ( true ) ;
2011-04-14 21:58:15 +00:00
model - > update ( ) ;
}
2011-04-01 21:46:06 +00:00
2016-08-28 23:14:39 +02:00
// connect( ui.dirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), this, SLOT( collapsed(const QModelIndex & ) ) );
2011-04-01 21:46:06 +00:00
2013-02-22 21:42:27 +00:00
ui . dirTreeView - > setModel ( proxyModel ) ;
ui . dirTreeView - > update ( ) ;
2011-04-01 21:46:06 +00:00
2018-01-24 22:02:49 +01:00
restoreExpandedPathsAndSelection ( expanded_indexes , hidden_indexes , selected_indexes ) ;
2016-08-29 21:30:56 +02:00
QHeaderView * header = ui . dirTreeView - > header ( ) ;
2015-06-26 08:14:09 +00:00
QHeaderView_setSectionResizeModeColumn ( header , COLUMN_NAME , QHeaderView : : Interactive ) ;
2013-02-27 00:23:56 +00:00
2018-02-19 20:13:38 +01:00
ui . dirTreeView - > header ( ) - > headerDataChanged ( Qt : : Horizontal , COLUMN_NAME , COLUMN_WN_VISU_DIR ) ;
2011-04-01 21:46:06 +00:00
2016-08-28 23:14:39 +02:00
// recursRestoreExpandedItems(ui.dirTreeView->rootIndex(),expanded_indexes);
2016-01-09 12:09:43 +01:00
FilterItems ( ) ;
2011-04-01 21:46:06 +00:00
}
2013-02-22 21:42:27 +00:00
void LocalSharedFilesDialog : : showProperColumns ( )
{
if ( model = = tree_model )
{
2018-02-19 20:13:38 +01:00
ui . dirTreeView - > setColumnHidden ( COLUMN_FILENB , false ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_FRIEND_ACCESS , false ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_WN_VISU_DIR , false ) ;
2013-02-22 21:42:27 +00:00
# ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui . filterLabel - > hide ( ) ;
ui . filterPatternLineEdit - > hide ( ) ;
ui . filterStartButton - > hide ( ) ;
ui . filterClearButton - > hide ( ) ;
# endif
}
else
{
2018-02-19 20:13:38 +01:00
ui . dirTreeView - > setColumnHidden ( COLUMN_FILENB , true ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_FRIEND_ACCESS , true ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_WN_VISU_DIR , false ) ;
2013-02-22 21:42:27 +00:00
# ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui . filterLabel - > show ( ) ;
ui . filterPatternLineEdit - > show ( ) ;
# endif
}
}
void RemoteSharedFilesDialog : : showProperColumns ( )
{
if ( model = = tree_model )
{
2018-02-19 20:13:38 +01:00
ui . dirTreeView - > setColumnHidden ( COLUMN_FILENB , false ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_FRIEND_ACCESS , true ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_WN_VISU_DIR , true ) ;
2013-02-22 21:42:27 +00:00
# ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui . filterLabel - > hide ( ) ;
ui . filterPatternLineEdit - > hide ( ) ;
ui . filterStartButton - > hide ( ) ;
ui . filterClearButton - > hide ( ) ;
# endif
}
else
{
2018-02-19 20:13:38 +01:00
ui . dirTreeView - > setColumnHidden ( COLUMN_FILENB , true ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_FRIEND_ACCESS , false ) ;
ui . dirTreeView - > setColumnHidden ( COLUMN_WN_VISU_DIR , false ) ;
2013-02-22 21:42:27 +00:00
# ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui . filterLabel - > show ( ) ;
ui . filterPatternLineEdit - > show ( ) ;
# endif
}
}
void LocalSharedFilesDialog : : checkUpdate ( )
2008-03-31 18:37:50 +00:00
{
2013-02-22 21:42:27 +00:00
/* update */
2008-07-02 16:59:56 +00:00
if ( rsFiles - > InDirectoryCheck ( ) )
2008-03-31 18:37:50 +00:00
{
2009-07-11 00:45:17 +00:00
ui . checkButton - > setText ( tr ( " Checking... " ) ) ;
2008-03-31 18:37:50 +00:00
}
else
{
2013-02-22 21:42:27 +00:00
ui . checkButton - > setText ( tr ( " Check files " ) ) ;
2008-03-31 18:37:50 +00:00
ui . hashLabel - > setPixmap ( QPixmap ( IMAGE_HASH_DONE ) ) ;
2009-01-25 19:05:53 +00:00
ui . hashLabel - > setToolTip ( " " ) ;
2008-03-31 18:37:50 +00:00
}
return ;
}
2013-02-22 21:42:27 +00:00
void LocalSharedFilesDialog : : forceCheck ( )
2008-03-31 18:37:50 +00:00
{
2008-07-02 16:59:56 +00:00
rsFiles - > ForceDirectoryCheck ( ) ;
2008-03-31 18:37:50 +00:00
return ;
}
2013-02-22 21:42:27 +00:00
void RemoteSharedFilesDialog : : spawnCustomPopupMenu ( QPoint point )
2008-11-18 17:14:49 +00:00
{
2014-05-29 14:49:45 +00:00
if ( ! rsPeers ) return ; /* not ready yet! */
2009-07-07 18:56:31 +00:00
2014-05-29 14:49:45 +00:00
QModelIndex idx = ui . dirTreeView - > indexAt ( point ) ;
if ( ! idx . isValid ( ) ) return ;
2009-05-18 14:23:55 +00:00
2014-05-29 14:49:45 +00:00
QModelIndex midx = proxyModel - > mapToSource ( idx ) ;
if ( ! midx . isValid ( ) ) return ;
2009-07-07 18:56:31 +00:00
2014-05-29 14:49:45 +00: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 18:56:31 +00:00
2014-05-29 14:49:45 +00:00
QMenu contextMnu ( this ) ;
2008-11-18 17:14:49 +00:00
2014-05-29 14:49:45 +00:00
collCreateAct - > setEnabled ( true ) ;
collOpenAct - > setEnabled ( true ) ;
2010-05-14 20:55:44 +00:00
2014-05-29 14:49:45 +00:00
QMenu collectionMenu ( tr ( " Collection " ) , this ) ;
collectionMenu . setIcon ( QIcon ( IMAGE_LIBRARY ) ) ;
collectionMenu . addAction ( collCreateAct ) ;
collectionMenu . addAction ( collOpenAct ) ;
2008-11-18 17:14:49 +00:00
2017-11-13 22:08:05 +01:00
QModelIndexList list = ui . dirTreeView - > selectionModel ( ) - > selectedRows ( ) ;
if ( type = = DIR_TYPE_DIR | | list . size ( ) > 1 )
2017-11-12 22:46:29 +01:00
{
QAction * downloadActI = new QAction ( QIcon ( IMAGE_DOWNLOAD ) , tr ( " Download... " ) , & contextMnu ) ;
connect ( downloadActI , SIGNAL ( triggered ( ) ) , this , SLOT ( downloadRemoteSelectedInteractive ( ) ) ) ;
contextMnu . addAction ( downloadActI ) ;
}
else
{
QAction * downloadAct = new QAction ( QIcon ( IMAGE_DOWNLOAD ) , tr ( " Download " ) , & contextMnu ) ;
connect ( downloadAct , SIGNAL ( triggered ( ) ) , this , SLOT ( downloadRemoteSelected ( ) ) ) ;
contextMnu . addAction ( downloadAct ) ;
}
2014-05-29 14:49:45 +00:00
2017-10-21 21:23:40 +02: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 ( ) ) ) ;
2014-05-29 14:49:45 +00:00
contextMnu . addSeparator ( ) ; //------------------------------------
contextMnu . addMenu ( & collectionMenu ) ;
contextMnu . exec ( QCursor : : pos ( ) ) ;
2010-09-20 00:10:51 +00:00
}
2007-11-15 03:18:48 +00:00
2014-05-29 14:49:45 +00:00
QModelIndexList SharedFilesDialog : : getSelected ( )
2011-11-07 23:07:25 +00:00
{
2014-05-29 14:49:45 +00:00
QModelIndexList list = ui . dirTreeView - > selectionModel ( ) - > selectedIndexes ( ) ;
QModelIndexList proxyList ;
2014-10-21 22:33:02 +00:00
for ( QModelIndexList : : iterator index = list . begin ( ) ; index ! = list . end ( ) ; + + index ) {
2014-05-29 14:49:45 +00:00
proxyList . append ( proxyModel - > mapToSource ( * index ) ) ;
2017-10-15 21:10:29 +02:00
}
2011-11-07 23:07:25 +00:00
2014-05-29 14:49:45 +00:00
return proxyList ;
2013-02-27 00:23:56 +00:00
}
2012-12-05 13:26:26 +00:00
2016-09-11 17:52:12 +02:00
void RemoteSharedFilesDialog : : expanded ( const QModelIndex & indx )
{
2016-09-22 21:47:58 +02:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-09-11 17:52:12 +02: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 21:47:58 +02:00
# endif
2016-09-11 17:52:12 +02:00
model - > updateRef ( proxyModel - > mapToSource ( indx ) ) ;
}
2017-11-12 22:46:29 +01:00
void RemoteSharedFilesDialog : : downloadRemoteSelectedInteractive ( )
{
/* call back to the model (which does all the interfacing? */
std : : cerr < < " Downloading Files " ;
std : : cerr < < std : : endl ;
2016-09-11 17:52:12 +02:00
2017-11-12 22:46:29 +01:00
QModelIndexList lst = getSelected ( ) ;
model - > downloadSelected ( lst , true ) ;
}
2013-02-22 21:42:27 +00:00
void RemoteSharedFilesDialog : : downloadRemoteSelected ( )
2008-11-18 17:14:49 +00:00
{
2014-05-29 14:49:45 +00:00
/* call back to the model (which does all the interfacing? */
2007-11-15 03:18:48 +00:00
2014-05-29 14:49:45 +00:00
std : : cerr < < " Downloading Files " ;
std : : cerr < < std : : endl ;
2007-11-15 03:18:48 +00:00
2014-05-29 14:49:45 +00:00
QModelIndexList lst = getSelected ( ) ;
2017-11-12 22:46:29 +01:00
model - > downloadSelected ( lst , false ) ;
2007-11-15 03:18:48 +00:00
}
2013-02-27 00:23:56 +00:00
2017-10-21 21:23:40 +02:00
void SharedFilesDialog : : copyLinks ( const QModelIndexList & lst , bool remote , QList < RetroShareLink > & urls , bool & has_unhashed_files )
2009-05-18 14:23:55 +00:00
{
2017-10-21 21:23:40 +02:00
std : : vector < DirDetails > dirVec ;
2009-05-18 14:23:55 +00:00
2017-10-21 21:23:40 +02:00
model - > getDirDetailsFromSelect ( lst , dirVec ) ;
2009-05-18 14:23:55 +00:00
2017-10-21 21:23:40 +02:00
has_unhashed_files = false ;
2010-03-10 23:09:35 +00:00
2017-10-21 21:23:40 +02:00
for ( int i = 0 , n = dirVec . size ( ) ; i < n ; + + i )
{
const DirDetails & details = dirVec [ i ] ;
2009-05-18 14:23:55 +00:00
2017-10-21 21:23:40 +02:00
if ( details . type = = DIR_TYPE_DIR )
{
2017-10-18 22:32:15 +02:00
FileTree * ft = FileTree : : create ( details , remote ) ;
std : : cerr < < " Created collection file tree: " < < std : : endl ;
ft - > print ( ) ;
2017-10-21 16:16:23 +02:00
QString dir_name = QDir ( QString : : fromUtf8 ( details . name . c_str ( ) ) ) . dirName ( ) ;
2018-02-04 17:51:26 +01:00
RetroShareLink link = RetroShareLink : : createFileTree ( dir_name , ft - > mTotalSize , ft - > mTotalFiles , QString : : fromStdString ( ft - > toRadix64 ( ) ) ) ;
2017-10-18 22:32:15 +02:00
if ( link . valid ( ) )
urls . push_back ( link ) ;
delete ft ;
2017-10-21 21:23:40 +02:00
}
else
{
if ( details . hash . isNull ( ) )
2017-01-15 21:13:27 +01:00
{
has_unhashed_files = true ;
continue ;
}
2017-10-21 21:23:40 +02:00
RetroShareLink link = RetroShareLink : : createFile ( QString : : fromUtf8 ( details . name . c_str ( ) ) , details . count , details . hash . toStdString ( ) . c_str ( ) ) ;
if ( link . valid ( ) ) {
urls . push_back ( link ) ;
}
}
}
}
void SharedFilesDialog : : copyLink ( const QModelIndexList & lst , bool remote )
{
QList < RetroShareLink > urls ;
bool has_unhashed_files = false ;
copyLinks ( lst , remote , urls , has_unhashed_files ) ;
2011-05-04 10:22:49 +00:00
RSLinkClipboard : : copyLinks ( urls ) ;
2017-01-15 21:13:27 +01:00
if ( has_unhashed_files )
2017-10-21 21:23:40 +02:00
QMessageBox : : warning ( NULL , tr ( " Some files have been omitted " ) , tr ( " Some files have been omitted because they have not been indexed yet. " ) ) ;
2009-05-18 14:23:55 +00:00
}
2013-02-22 21:42:27 +00:00
void SharedFilesDialog : : copyLink ( )
2009-05-18 14:23:55 +00:00
{
2013-02-22 21:42:27 +00:00
copyLink ( getSelected ( ) , isRemote ( ) ) ;
2009-05-18 14:23:55 +00:00
}
2010-03-04 15:42:50 +00:00
void SharedFilesDialog : : copyLinkhtml ( )
{
2013-02-22 21:42:27 +00:00
copyLink ( ) ;
2010-03-04 15:42:50 +00:00
QString link = QApplication : : clipboard ( ) - > text ( ) ;
QClipboard * clipboard = QApplication : : clipboard ( ) ;
clipboard - > setText ( " <a href=' " + link + " '> " + link + " </a> " ) ;
2009-05-18 14:23:55 +00:00
}
2010-03-04 15:42:50 +00:00
void SharedFilesDialog : : sendLinkTo ( )
2009-05-18 14:23:55 +00:00
{
2013-02-22 21:42:27 +00:00
copyLink ( ) ;
2009-05-18 14:23:55 +00:00
/* create a message */
2010-11-02 21:11:11 +00:00
MessageComposer * nMsgDialog = MessageComposer : : newMsg ( ) ;
if ( nMsgDialog = = NULL ) {
return ;
}
2009-05-18 14:23:55 +00:00
/* fill it in
* files are receommended already
* just need to set peers
*/
std : : cerr < < " SharedFilesDialog::sendLinkTo() " < < std : : endl ;
2012-05-04 23:39:36 +00:00
nMsgDialog - > setTitleText ( tr ( " RetroShare Link " ) ) ;
nMsgDialog - > setMsgText ( RSLinkClipboard : : toHtml ( ) , true ) ;
2010-01-16 18:03:35 +00:00
nMsgDialog - > show ( ) ;
2010-05-03 00:09:55 +00:00
/* window will destroy itself! */
2010-01-16 18:03:35 +00:00
}
2014-05-29 14:49:45 +00: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 ( ) ) {
2017-10-19 22:14:04 +02:00
if ( qinfo . absoluteFilePath ( ) . endsWith ( RsCollection : : ExtensionString ) ) {
RsCollection collection ;
2014-05-29 14:49:45 +00:00
collection . openColl ( qinfo . absoluteFilePath ( ) ) ;
2017-10-19 22:14:04 +02:00
}
}
2014-05-29 14:49:45 +00:00
}
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 ( ) ) {
2017-10-19 22:14:04 +02:00
if ( qinfo . absoluteFilePath ( ) . endsWith ( RsCollection : : ExtensionString ) ) {
RsCollection collection ;
2014-05-29 14:49:45 +00:00
collection . openColl ( qinfo . absoluteFilePath ( ) , true ) ;
2017-10-19 22:14:04 +02:00
}
}
2014-05-29 14:49:45 +00:00
}
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 ( ) ) {
2017-10-19 22:14:04 +02:00
if ( qinfo . absoluteFilePath ( ) . endsWith ( RsCollection : : ExtensionString ) ) {
RsCollection collection ;
2016-05-16 11:32:17 +02:00
if ( collection . load ( qinfo . absoluteFilePath ( ) ) ) {
2014-05-29 14:49:45 +00:00
collection . downloadFiles ( ) ;
return ;
2016-05-16 11:32:17 +02:00
}
}
}
}
}
2014-05-29 14:49:45 +00:00
2017-10-19 22:14:04 +02:00
RsCollection collection ;
2014-05-29 14:49:45 +00:00
if ( collection . load ( this ) ) {
collection . downloadFiles ( ) ;
2017-10-19 22:14:04 +02:00
}
2014-05-29 14:49:45 +00:00
}
2013-02-22 21:42:27 +00:00
void LocalSharedFilesDialog : : playselectedfiles ( )
2008-11-18 17:14:49 +00:00
{
2008-03-31 18:37:50 +00: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 21:42:27 +00:00
model - > getFilePaths ( getSelected ( ) , paths ) ;
2008-03-31 18:37:50 +00:00
std : : list < std : : string > : : iterator it ;
QStringList fullpaths ;
2014-10-21 22:33:02 +00:00
for ( it = paths . begin ( ) ; it ! = paths . end ( ) ; + + it )
2008-03-31 18:37:50 +00:00
{
2013-02-22 21:42:27 +00:00
std : : string fullpath ;
rsFiles - > ConvertSharedFilePath ( * it , fullpath ) ;
fullpaths . push_back ( QString : : fromStdString ( fullpath ) ) ;
2008-12-03 14:30:21 +00:00
2013-02-22 21:42:27 +00:00
std : : cerr < < " Playing: " < < fullpath ;
std : : cerr < < std : : endl ;
2008-03-31 18:37:50 +00:00
}
playFiles ( fullpaths ) ;
2008-07-10 18:52:56 +00:00
std : : cerr < < " SharedFilesDialog::playselectedfiles() Completed " ;
std : : cerr < < std : : endl ;
2008-03-31 18:37:50 +00:00
}
2010-11-07 21:33:48 +00:00
void SharedFilesDialog : : recommendFilesToMsg ( )
2008-11-18 17:14:49 +00:00
{
2010-11-07 21:33:48 +00:00
std : : list < DirDetails > files_info ;
2007-11-15 03:18:48 +00:00
2013-02-22 21:42:27 +00:00
model - > getFileInfoFromIndexList ( getSelected ( ) , files_info ) ;
2008-07-02 16:59:56 +00:00
2010-11-07 21:33:48 +00:00
if ( files_info . empty ( ) )
return ;
2007-11-15 03:18:48 +00:00
2010-11-07 21:33:48 +00:00
/* create a message */
2007-11-15 03:18:48 +00:00
2010-11-07 21:33:48 +00:00
MessageComposer * nMsgDialog = MessageComposer : : newMsg ( ) ;
if ( nMsgDialog = = NULL ) {
return ;
}
2007-11-15 03:18:48 +00:00
2012-05-04 23:39:36 +00:00
nMsgDialog - > setFileList ( files_info ) ;
nMsgDialog - > setTitleText ( tr ( " Recommendation(s) " ) ) ;
nMsgDialog - > setMsgText ( tr ( " Recommendation(s) " ) ) ;
2010-11-07 21:33:48 +00:00
nMsgDialog - > show ( ) ;
2010-05-03 00:09:55 +00:00
2010-11-07 21:33:48 +00:00
/* window will destroy itself! */
2007-11-15 03:18:48 +00:00
}
2013-02-22 21:42:27 +00:00
void LocalSharedFilesDialog : : openfile ( )
2008-11-18 17:14:49 +00:00
{
2013-02-22 21:42:27 +00:00
/* call back to the model (which does all the interfacing? */
2007-11-15 03:18:48 +00:00
2013-02-22 21:42:27 +00:00
std : : cerr < < " SharedFilesDialog::openfile " < < std : : endl ;
2007-11-15 03:18:48 +00:00
2013-02-22 21:42:27 +00:00
QModelIndexList qmil = getSelected ( ) ;
model - > openSelected ( qmil ) ;
2007-11-15 03:18:48 +00:00
}
2013-02-22 21:42:27 +00:00
void LocalSharedFilesDialog : : openfolder ( )
2008-11-18 17:14:49 +00:00
{
2009-07-07 18:56:31 +00:00
std : : cerr < < " SharedFilesDialog::openfolder " < < std : : endl ;
2007-11-15 03:18:48 +00:00
2013-02-22 21:42:27 +00:00
QModelIndexList qmil = getSelected ( ) ;
model - > openSelected ( qmil ) ;
2008-11-18 17:14:49 +00:00
}
2007-11-15 03:18:48 +00:00
2014-01-05 22:51:54 +00:00
void SharedFilesDialog : : preModDirectories ( bool local )
2007-11-15 03:18:48 +00:00
{
2016-11-26 11:26:02 +01:00
if ( isRemote ( ) = = local )
return ;
2016-11-26 11:03:31 +01:00
2016-11-26 19:19:15 +01:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-11-26 11:03:31 +01:00
std : : cerr < < " About to modify directories. Local= " < < local < < " . Temporarily disabling sorting " < < std : : endl ;
2016-11-26 19:19:15 +01:00
# endif
2016-11-26 11:03:31 +01:00
ui . dirTreeView - > setSortingEnabled ( false ) ;
2018-01-24 22:02:49 +01:00
std : : set < std : : string > expanded_indexes , hidden_indexes , selected_indexes ;
saveExpandedPathsAndSelection ( expanded_indexes , hidden_indexes , selected_indexes ) ;
2014-01-05 22:51:54 +00:00
/* Notify both models, only one is visible */
tree_model - > preMods ( ) ;
flat_model - > preMods ( ) ;
2016-11-26 11:03:31 +01:00
2018-01-24 22:02:49 +01:00
restoreExpandedPathsAndSelection ( expanded_indexes , hidden_indexes , selected_indexes ) ;
2007-11-15 03:18:48 +00:00
}
2018-01-24 22:02:49 +01:00
void SharedFilesDialog : : saveExpandedPathsAndSelection ( std : : set < std : : string > & expanded_indexes ,
std : : set < std : : string > & hidden_indexes ,
std : : set < std : : string > & selected_indexes )
2016-08-28 23:14:39 +02:00
{
2016-08-29 21:30:56 +02:00
if ( ui . dirTreeView - > model ( ) = = NULL )
return ;
2016-09-08 23:43:14 +02:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-29 21:30:56 +02:00
std : : cerr < < " Saving expanded items. " < < std : : endl ;
2016-09-08 23:43:14 +02:00
# endif
2016-08-28 23:14:39 +02: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 21:44:34 +02:00
2018-01-24 22:02:49 +01:00
recursSaveExpandedItems ( ui . dirTreeView - > model ( ) - > index ( row , 0 ) , path , expanded_indexes , hidden_indexes , selected_indexes ) ;
2016-08-28 23:14:39 +02:00
}
}
2018-01-24 22:02:49 +01:00
void SharedFilesDialog : : restoreExpandedPathsAndSelection ( const std : : set < std : : string > & expanded_indexes ,
const std : : set < std : : string > & hidden_indexes ,
const std : : set < std : : string > & selected_indexes )
2016-08-28 23:14:39 +02:00
{
2016-08-29 21:30:56 +02:00
if ( ui . dirTreeView - > model ( ) = = NULL )
return ;
2016-09-14 21:52:16 +02:00
// we need to disable this, because the signal will trigger unnecessary update at the friend.
ui . dirTreeView - > blockSignals ( true ) ;
2016-09-08 23:43:14 +02:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 23:14:39 +02:00
std : : cerr < < " Restoring expanded items. " < < std : : endl ;
2016-09-08 23:43:14 +02:00
# endif
2016-08-28 23:14:39 +02: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 ( ) ;
2018-01-24 22:02:49 +01:00
recursRestoreExpandedItems ( ui . dirTreeView - > model ( ) - > index ( row , 0 ) , path , expanded_indexes , hidden_indexes , selected_indexes ) ;
2016-08-28 23:14:39 +02:00
}
2016-10-03 21:44:34 +02:00
QItemSelection selection ;
2016-09-14 21:52:16 +02:00
ui . dirTreeView - > blockSignals ( false ) ;
2016-08-28 23:14:39 +02:00
}
2018-01-24 22:02:49 +01:00
void SharedFilesDialog : : recursSaveExpandedItems ( const QModelIndex & index , const std : : string & path , std : : set < std : : string > & exp ,
std : : set < std : : string > & vis ,
std : : set < std : : string > & sel
)
2016-08-28 23:14:39 +02:00
{
std : : string local_path = path + " / " + index . data ( Qt : : DisplayRole ) . toString ( ) . toStdString ( ) ;
2016-09-08 23:43:14 +02:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 23:14:39 +02:00
std : : cerr < < " at index " < < index . row ( ) < < " . data[1]= " < < local_path < < std : : endl ;
2016-09-08 23:43:14 +02:00
# endif
2016-08-28 23:14:39 +02:00
2016-10-03 21:44:34 +02:00
if ( ui . dirTreeView - > selectionModel ( ) - > selection ( ) . contains ( index ) )
sel . insert ( local_path ) ;
2018-01-24 22:02:49 +01:00
if ( ui . dirTreeView - > isRowHidden ( index . row ( ) , index . parent ( ) ) )
2018-01-28 21:54:56 +01:00
{
2018-01-24 22:02:49 +01:00
vis . insert ( local_path ) ;
2018-01-28 21:54:56 +01:00
return ;
}
2018-01-24 22:02:49 +01:00
2016-08-28 23:14:39 +02:00
if ( ui . dirTreeView - > isExpanded ( index ) )
{
2016-09-08 23:43:14 +02:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 23:14:39 +02:00
std : : cerr < < " Index " < < local_path < < " is expanded. " < < std : : endl ;
2016-09-08 23:43:14 +02:00
# endif
2016-08-28 23:14:39 +02:00
if ( index . isValid ( ) )
exp . insert ( local_path ) ;
for ( int row = 0 ; row < ui . dirTreeView - > model ( ) - > rowCount ( index ) ; + + row )
2018-01-24 22:02:49 +01:00
recursSaveExpandedItems ( index . child ( row , 0 ) , local_path , exp , vis , sel ) ;
2016-08-28 23:14:39 +02:00
}
2016-09-08 23:43:14 +02:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 23:14:39 +02:00
else
std : : cerr < < " Index is not expanded. " < < std : : endl ;
2016-09-08 23:43:14 +02:00
# endif
2016-08-28 23:14:39 +02:00
}
2018-01-24 22:02:49 +01:00
void SharedFilesDialog : : recursRestoreExpandedItems ( const QModelIndex & index , const std : : string & path ,
const std : : set < std : : string > & exp ,
const std : : set < std : : string > & vis ,
const std : : set < std : : string > & sel )
2016-08-28 23:14:39 +02:00
{
std : : string local_path = path + " / " + index . data ( Qt : : DisplayRole ) . toString ( ) . toStdString ( ) ;
2016-09-08 23:43:14 +02:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 23:14:39 +02:00
std : : cerr < < " at index " < < index . row ( ) < < " . data[1]= " < < local_path < < std : : endl ;
2016-09-08 23:43:14 +02:00
# endif
2016-10-03 21:44:34 +02:00
if ( sel . find ( local_path ) ! = sel . end ( ) )
ui . dirTreeView - > selectionModel ( ) - > select ( index , QItemSelectionModel : : Select | QItemSelectionModel : : Rows ) ;
2016-08-28 23:14:39 +02:00
2018-01-28 21:54:56 +01:00
bool invisible = vis . find ( local_path ) ! = vis . end ( ) ;
ui . dirTreeView - > setRowHidden ( index . row ( ) , index . parent ( ) , invisible ) ;
2018-01-24 22:02:49 +01:00
2018-02-15 00:02:08 +01:00
if ( invisible )
mHiddenIndexes . push_back ( proxyModel - > mapToSource ( index ) ) ;
2018-01-28 21:54:56 +01:00
if ( ! invisible & & exp . find ( local_path ) ! = exp . end ( ) )
2016-08-28 23:14:39 +02:00
{
2016-09-08 23:43:14 +02:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-28 23:14:39 +02:00
std : : cerr < < " re expanding index " < < local_path < < std : : endl ;
2016-09-08 23:43:14 +02:00
# endif
2016-08-28 23:14:39 +02:00
ui . dirTreeView - > setExpanded ( index , true ) ;
for ( int row = 0 ; row < ui . dirTreeView - > model ( ) - > rowCount ( index ) ; + + row )
2018-01-24 22:02:49 +01:00
recursRestoreExpandedItems ( index . child ( row , 0 ) , local_path , exp , vis , sel ) ;
2016-08-28 23:14:39 +02:00
}
}
2014-01-05 22:51:54 +00:00
void SharedFilesDialog : : postModDirectories ( bool local )
2007-11-15 03:18:48 +00:00
{
2016-11-26 11:26:02 +01:00
if ( isRemote ( ) = = local )
return ;
2018-01-24 22:02:49 +01:00
std : : set < std : : string > expanded_indexes , selected_indexes , hidden_indexes ;
2016-10-03 21:44:34 +02:00
2018-01-24 22:02:49 +01:00
saveExpandedPathsAndSelection ( expanded_indexes , hidden_indexes , selected_indexes ) ;
2016-09-08 23:43:14 +02:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-08-29 21:30:56 +02:00
std : : cerr < < " Saving expanded items. " < < expanded_indexes . size ( ) < < " items found " < < std : : endl ;
2016-09-08 23:43:14 +02:00
# endif
2014-01-05 22:51:54 +00:00
2016-08-28 23:14:39 +02:00
/* Notify both models, only one is visible */
2014-01-05 22:51:54 +00:00
tree_model - > postMods ( ) ;
flat_model - > postMods ( ) ;
2013-02-22 21:42:27 +00:00
ui . dirTreeView - > update ( ) ;
2010-11-30 12:29:04 +00:00
2016-08-28 23:14:39 +02:00
if ( ui . filterPatternLineEdit - > text ( ) . isEmpty ( ) = = false )
2013-02-22 21:42:27 +00:00
FilterItems ( ) ;
2009-08-11 18:14:55 +00:00
2016-11-26 11:03:31 +01:00
ui . dirTreeView - > setSortingEnabled ( true ) ;
2018-01-24 22:02:49 +01:00
restoreExpandedPathsAndSelection ( expanded_indexes , hidden_indexes , selected_indexes ) ;
2016-11-26 11:03:31 +01:00
2016-09-08 23:43:14 +02:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2016-11-26 11:03:31 +01:00
std : : cerr < < " ****** updated directories! Re-enabling sorting ****** " < < std : : endl ;
2016-09-08 23:43:14 +02:00
# endif
2009-08-11 18:14:55 +00:00
QCoreApplication : : flush ( ) ;
2007-11-15 03:18:48 +00:00
}
2017-10-27 22:03:42 +02:00
class ChannelCompare
{
public :
bool operator ( ) ( const std : : pair < std : : string , RsGxsGroupId > & id1 , const std : : pair < std : : string , RsGxsGroupId > & id2 ) const
{
return id1 . first < id2 . first ;
}
} ;
2013-02-22 21:42:27 +00:00
void LocalSharedFilesDialog : : spawnCustomPopupMenu ( QPoint point )
2008-11-18 17:14:49 +00:00
{
2014-05-29 14:49:45 +00: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 ) ;
2017-10-19 22:14:04 +02:00
bool bIsRsColl = currentFile . endsWith ( RsCollection : : ExtensionString ) ;
2014-05-29 14:49:45 +00:00
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 ) ;
2017-10-19 10:19:56 +02:00
contextMnu . addAction ( copylinkAct ) ;
2014-05-29 14:49:45 +00:00
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 ( ) ; //------------------------------------
2017-10-21 16:16:23 +02:00
contextMnu . addAction ( QIcon ( IMAGE_MSG ) , tr ( " Recommend in a message to... " ) , this , SLOT ( recommendFilesToMsg ( ) ) ) ;
2014-05-29 14:49:45 +00:00
break ;
2007-11-15 03:18:48 +00:00
2014-05-29 14:49:45 +00:00
default :
return ;
2017-10-21 16:16:23 +02:00
}
2014-05-29 14:49:45 +00:00
2017-10-21 21:23:40 +02:00
GxsChannelDialog * channelDialog = dynamic_cast < GxsChannelDialog * > ( MainWindow : : getPage ( MainWindow : : Channels ) ) ;
2017-10-29 20:33:56 +01:00
QMenu shareChannelMenu ( tr ( " Share on channel... " ) ) ; // added here because the shareChannelMenu QMenu object is deleted afterwards
2017-10-21 21:23:40 +02:00
if ( channelDialog ! = NULL )
{
shareChannelMenu . setIcon ( QIcon ( IMAGE_CHANNEL ) ) ;
std : : list < RsGroupMetaData > grp_metas ;
channelDialog - > getGroupList ( grp_metas ) ;
2017-10-29 20:33:56 +01:00
std : : vector < std : : pair < std : : string , RsGxsGroupId > > grplist ; // I dont use a std::map because two or more channels may have the same name.
2017-10-27 22:03:42 +02:00
2017-10-21 21:23:40 +02:00
for ( auto it ( grp_metas . begin ( ) ) ; it ! = grp_metas . end ( ) ; + + it )
2017-10-26 19:41:13 +02:00
if ( IS_GROUP_PUBLISHER ( ( * it ) . mSubscribeFlags ) & & IS_GROUP_SUBSCRIBED ( ( * it ) . mSubscribeFlags ) )
2017-10-29 20:33:56 +01:00
grplist . push_back ( std : : make_pair ( ( * it ) . mGroupName , ( * it ) . mGroupId ) ) ;
2017-10-27 22:03:42 +02:00
2017-10-29 20:33:56 +01:00
std : : sort ( grplist . begin ( ) , grplist . end ( ) , ChannelCompare ( ) ) ;
2017-10-27 22:03:42 +02:00
2017-10-29 20:33:56 +01:00
for ( auto it ( grplist . begin ( ) ) ; it ! = grplist . end ( ) ; + + it )
2017-10-27 22:03:42 +02:00
shareChannelMenu . addAction ( QString : : fromUtf8 ( ( * it ) . first . c_str ( ) ) , this , SLOT ( shareOnChannel ( ) ) ) - > setData ( QString : : fromStdString ( ( * it ) . second . toStdString ( ) ) ) ;
2017-10-21 21:23:40 +02:00
contextMnu . addMenu ( & shareChannelMenu ) ;
}
2017-10-29 20:33:56 +01:00
GxsForumsDialog * forumsDialog = dynamic_cast < GxsForumsDialog * > ( MainWindow : : getPage ( MainWindow : : Forums ) ) ;
QMenu shareForumMenu ( tr ( " Share on forum... " ) ) ; // added here because the shareChannelMenu QMenu object is deleted afterwards
if ( forumsDialog ! = NULL )
{
shareForumMenu . setIcon ( QIcon ( IMAGE_FORUMS ) ) ;
std : : list < RsGroupMetaData > grp_metas ;
forumsDialog - > getGroupList ( grp_metas ) ;
std : : vector < std : : pair < std : : string , RsGxsGroupId > > grplist ; // I dont use a std::map because two or more channels may have the same name.
for ( auto it ( grp_metas . begin ( ) ) ; it ! = grp_metas . end ( ) ; + + it )
if ( IS_GROUP_SUBSCRIBED ( ( * it ) . mSubscribeFlags ) )
grplist . push_back ( std : : make_pair ( ( * it ) . mGroupName , ( * it ) . mGroupId ) ) ;
std : : sort ( grplist . begin ( ) , grplist . end ( ) , ChannelCompare ( ) ) ;
for ( auto it ( grplist . begin ( ) ) ; it ! = grplist . end ( ) ; + + it )
shareForumMenu . addAction ( QString : : fromUtf8 ( ( * it ) . first . c_str ( ) ) , this , SLOT ( shareInForum ( ) ) ) - > setData ( QString : : fromStdString ( ( * it ) . second . toStdString ( ) ) ) ;
contextMnu . addMenu ( & shareForumMenu ) ;
}
contextMnu . exec ( QCursor : : pos ( ) ) ;
}
2017-10-21 21:23:40 +02:00
void LocalSharedFilesDialog : : shareOnChannel ( )
{
RsGxsGroupId groupId ( qobject_cast < QAction * > ( sender ( ) ) - > data ( ) . toString ( ) . toStdString ( ) ) ;
GxsChannelDialog * channelDialog = dynamic_cast < GxsChannelDialog * > ( MainWindow : : getPage ( MainWindow : : Channels ) ) ;
if ( channelDialog = = NULL )
return ;
std : : list < DirDetails > files_info ;
QList < RetroShareLink > file_links_list ;
bool has_unhashed_files ;
copyLinks ( getSelected ( ) , false , file_links_list , has_unhashed_files ) ;
channelDialog - > shareOnChannel ( groupId , file_links_list ) ;
2009-04-07 08:08:03 +00:00
}
2017-10-29 20:33:56 +01:00
void LocalSharedFilesDialog : : shareInForum ( )
{
RsGxsGroupId groupId ( qobject_cast < QAction * > ( sender ( ) ) - > data ( ) . toString ( ) . toStdString ( ) ) ;
GxsForumsDialog * forumsDialog = dynamic_cast < GxsForumsDialog * > ( MainWindow : : getPage ( MainWindow : : Forums ) ) ;
if ( forumsDialog = = NULL )
return ;
std : : list < DirDetails > files_info ;
QList < RetroShareLink > file_links_list ;
bool has_unhashed_files ;
copyLinks ( getSelected ( ) , false , file_links_list , has_unhashed_files ) ;
forumsDialog - > shareInMessage ( groupId , file_links_list ) ;
}
2007-11-15 03:18:48 +00:00
2009-04-07 08:08:03 +00:00
//============================================================================
QAction *
2013-02-22 21:42:27 +00:00
LocalSharedFilesDialog : : fileAssotiationAction ( const QString /*fileName*/ )
2009-04-07 08:08:03 +00:00
{
2014-05-29 14:49:45 +00:00
QAction * result = NULL ;
2009-04-07 08:08:03 +00:00
2010-05-20 21:53:27 +00:00
Settings - > beginGroup ( " FileAssotiations " ) ;
2009-04-07 08:08:03 +00:00
2009-12-14 17:13:10 +00:00
QString key = AddFileAssociationDialog : : cleanFileType ( currentFile ) ;
2010-05-20 21:53:27 +00:00
if ( Settings - > contains ( key ) )
2009-04-07 08:08:03 +00:00
{
result = new QAction ( QIcon ( IMAGE_PLAY ) , tr ( " Open File " ) , this ) ;
connect ( result , SIGNAL ( triggered ( ) ) ,
this , SLOT ( runCommandForFile ( ) ) ) ;
2010-05-20 21:53:27 +00:00
currentCommand = ( Settings - > value ( key ) ) . toString ( ) ;
2009-04-07 08:08:03 +00: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 21:53:27 +00:00
Settings - > endGroup ( ) ;
2009-04-07 08:08:03 +00:00
return result ;
}
//============================================================================
void
2013-02-22 21:42:27 +00:00
LocalSharedFilesDialog : : runCommandForFile ( )
2009-04-07 08:08:03 +00:00
{
QStringList tsl ;
tsl . append ( currentFile ) ;
QProcess : : execute ( currentCommand , tsl ) ;
}
//============================================================================
void
2013-02-22 21:42:27 +00:00
LocalSharedFilesDialog : : tryToAddNewAssotiation ( )
2009-04-07 08:08:03 +00:00
{
2009-12-14 17:13:10 +00:00
AddFileAssociationDialog afad ( true , this ) ; //'add file assotiations' dialog
2009-04-07 08:08:03 +00:00
2009-12-14 17:13:10 +00:00
afad . setFileType ( AddFileAssociationDialog : : cleanFileType ( currentFile ) ) ;
2009-04-07 08:08:03 +00:00
int ti = afad . exec ( ) ;
if ( ti = = QDialog : : Accepted )
{
QString currType = afad . resultFileType ( ) ;
QString currCmd = afad . resultCommand ( ) ;
2009-07-07 18:56:31 +00:00
2010-05-20 21:53:27 +00:00
Settings - > setValueToGroup ( " FileAssotiations " , currType , currCmd ) ;
2009-04-07 08:08:03 +00:00
}
2007-11-15 03:18:48 +00:00
}
2009-10-13 20:36:29 +00:00
void SharedFilesDialog : : indicatorChanged ( int index )
{
2010-02-08 22:32:00 +00: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 21:42:27 +00:00
ui . dirTreeView - > update ( ui . dirTreeView - > rootIndex ( ) ) ;
2014-05-29 14:49:45 +00:00
2011-05-21 18:34:34 +00:00
if ( correct_indicator [ index ] ! = IND_ALWAYS )
2014-05-29 14:49:45 +00:00
ui . dirTreeView - > sortByColumn ( COLUMN_AGE , Qt : : AscendingOrder ) ;
2011-05-21 18:34:34 +00:00
else
2014-05-29 14:49:45 +00:00
ui . dirTreeView - > sortByColumn ( COLUMN_NAME , Qt : : AscendingOrder ) ;
2010-02-08 23:09:46 +00:00
2011-05-21 18:34:34 +00:00
updateDisplay ( ) ;
2009-10-13 20:36:29 +00:00
}
2010-11-30 12:29:04 +00: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 ( ) ;
}
2018-01-24 21:14:26 +01:00
2018-02-19 20:13:38 +01:00
//bool valid = false ;
//QColor color ;
2018-01-24 21:14:26 +01:00
if ( text . length ( ) > 0 & & text . length ( ) < 3 )
{
2018-02-19 20:13:38 +01:00
//valid = false;
2018-01-24 21:14:26 +01:00
ui . filterStartButton - > setEnabled ( false ) ;
ui . filterPatternFrame - > setToolTip ( tr ( " Search string should be at least 3 characters long. " ) ) ;
return ;
}
if ( text . length ( ) > 0 & & proxyModel = = tree_proxyModel )
{
std : : list < DirDetails > result_list ;
std : : list < std : : string > keywords ;
QStringList lst = text . split ( " " , QString : : SkipEmptyParts ) ;
for ( auto it ( lst . begin ( ) ) ; it ! = lst . end ( ) ; + + it )
keywords . push_back ( ( * it ) . toStdString ( ) ) ;
FileSearchFlags flags = isRemote ( ) ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL ;
if ( keywords . size ( ) > 1 )
{
RsRegularExpression : : NameExpression exp ( RsRegularExpression : : ContainsAllStrings , keywords , true ) ;
rsFiles - > SearchBoolExp ( & exp , result_list , flags ) ;
}
else
rsFiles - > SearchKeywords ( keywords , result_list , flags ) ;
uint32_t nb_results = result_list . size ( ) ;
if ( nb_results > MAX_SEARCH_RESULTS )
{
ui . filterStartButton - > setEnabled ( false ) ;
ui . filterPatternFrame - > setToolTip ( tr ( " More than 3000 results. Add more/longer search words to select less. " ) ) ;
return ;
}
}
ui . filterStartButton - > setEnabled ( true ) ;
ui . filterPatternFrame - > setToolTip ( QString ( ) ) ;
/* unpolish widget to clear the stylesheet's palette cache */
// ui.filterPatternFrame->style()->unpolish(ui.filterPatternFrame);
// QPalette palette = ui.filterPatternLineEdit->palette();
// palette.setColor(ui.filterPatternLineEdit->backgroundRole(), color);
// ui.filterPatternLineEdit->setPalette(palette);
// //ui.searchLineFrame->setProperty("valid", valid);
// Rshare::refreshStyleSheet(ui.filterPatternFrame, false);
2010-11-30 12:29:04 +00:00
}
/* 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 ( ) ;
}
2018-02-24 18:15:54 +01:00
void SharedFilesDialog : : updateDirTreeView ( )
{
if ( model = = flat_model )
{
size_t maxSize = 0 ;
FlatStyle_RDM * flat = dynamic_cast < FlatStyle_RDM * > ( flat_model ) ;
if ( flat & & flat - > isMaxRefsTableSize ( & maxSize ) )
{
ui . dirTreeView - > setToolTip ( tr ( " Warning: You reach max (%1) files in flat list. No more will be added. " ) . arg ( maxSize ) ) ;
return ;
}
}
ui . dirTreeView - > setToolTip ( " " ) ;
}
2018-01-23 22:18:35 +01:00
// This macro make the search expand all items that contain the searched text.
// A bug however, makes RS expand everything when nothing is selected, which is a pain.
# define EXPAND_WHILE_SEARCHING 1
//#define DEBUG_SHARED_FILES_DIALOG
2018-02-15 00:02:08 +01:00
void recursMakeVisible ( QTreeView * tree , const QSortFilterProxyModel * proxyModel , const QModelIndex & indx , uint32_t depth , const std : : vector < std : : set < void * > > & pointers , QList < QModelIndex > & hidden_list )
2018-01-23 22:18:35 +01:00
{
# ifdef DEBUG_SHARED_FILES_DIALOG
for ( uint32_t i = 0 ; i < depth ; + + i ) std : : cerr < < " " ; std : : cerr < < " depth " < < depth < < " : current ref= " < < proxyModel - > mapToSource ( indx ) . internalPointer ( ) < < std : : endl ;
# endif
int rowCount = tree - > model ( ) - > rowCount ( indx ) ;
const std : : set < void * > & ptrs ( pointers [ depth + 1 ] ) ;
# ifdef DEBUG_SHARED_FILES_DIALOG
std : : cerr < < " Pointers are: " < < std : : endl ;
for ( auto it ( ptrs . begin ( ) ) ; it ! = ptrs . end ( ) ; + + it )
std : : cerr < < * it < < std : : endl ;
# endif
tree - > setRowHidden ( indx . row ( ) , indx . parent ( ) , false ) ;
# ifdef EXPAND_WHILE_SEARCHING
tree - > setExpanded ( indx , true ) ;
# endif
2018-01-24 21:26:35 +01:00
bool found = false ;
2018-01-23 22:18:35 +01:00
for ( int row = 0 ; row < rowCount ; + + row )
{
QModelIndex child_index = indx . child ( row , 0 ) ;
if ( ptrs . find ( proxyModel - > mapToSource ( child_index ) . internalPointer ( ) ) ! = ptrs . end ( ) )
{
# ifdef DEBUG_SHARED_FILES_DIALOG
for ( uint32_t i = 0 ; i < depth + 1 ; + + i ) std : : cerr < < " " ; std : : cerr < < " object " < < proxyModel - > mapToSource ( child_index ) . internalPointer ( ) < < " visible " < < std : : endl ;
# endif
2018-02-15 00:02:08 +01:00
recursMakeVisible ( tree , proxyModel , child_index , depth + 1 , pointers , hidden_list ) ;
2018-01-24 21:26:35 +01:00
found = true ;
2018-01-23 22:18:35 +01:00
}
else
{
tree - > setRowHidden ( child_index . row ( ) , indx , true ) ;
2018-02-15 00:02:08 +01:00
hidden_list . push_back ( proxyModel - > mapToSource ( child_index ) ) ;
2018-01-23 22:18:35 +01:00
# ifdef EXPAND_WHILE_SEARCHING
tree - > setExpanded ( child_index , false ) ;
# endif
# ifdef DEBUG_SHARED_FILES_DIALOG
for ( uint32_t i = 0 ; i < depth + 1 ; + + i ) std : : cerr < < " " ; std : : cerr < < " object " < < proxyModel - > mapToSource ( child_index ) . internalPointer ( ) < < " hidden " < < std : : endl ;
# endif
}
}
2018-01-24 21:26:35 +01:00
if ( ! found & & depth = = 0 )
2018-02-15 00:02:08 +01:00
{
2018-01-24 21:26:35 +01:00
tree - > setRowHidden ( indx . row ( ) , indx . parent ( ) , true ) ;
2018-02-15 00:02:08 +01:00
hidden_list . push_back ( proxyModel - > mapToSource ( indx ) ) ;
}
}
void SharedFilesDialog : : restoreInvisibleItems ( )
{
for ( QList < QModelIndex > : : const_iterator it ( mHiddenIndexes . begin ( ) ) ; it ! = mHiddenIndexes . end ( ) ; + + it )
{
QModelIndex indx = proxyModel - > mapFromSource ( * it ) ;
if ( indx . isValid ( ) )
ui . dirTreeView - > setRowHidden ( indx . row ( ) , indx . parent ( ) , false ) ;
}
mHiddenIndexes . clear ( ) ;
2018-01-23 22:18:35 +01:00
}
2018-01-28 21:54:56 +01:00
class QCursorContextBlocker
{
public :
QCursorContextBlocker ( QWidget * w )
: mW ( w )
{
mW - > setCursor ( Qt : : WaitCursor ) ;
mW - > blockSignals ( true ) ;
}
~ QCursorContextBlocker ( )
{
mW - > setCursor ( Qt : : ArrowCursor ) ;
mW - > blockSignals ( false ) ;
}
private :
QWidget * mW ;
} ;
2010-11-30 12:29:04 +00:00
void SharedFilesDialog : : FilterItems ( )
{
2016-01-09 12:09:43 +01:00
# ifdef DONT_USE_SEARCH_IN_TREE_VIEW
if ( proxyModel = = tree_proxyModel )
return ;
# endif
2018-01-28 21:54:56 +01:00
QString text = ui . filterPatternLineEdit - > text ( ) ;
2018-01-23 22:18:35 +01:00
2018-01-28 21:54:56 +01:00
if ( mLastFilterText = = text ) // do not filter again if we already did. This is an optimization
{
std : : cerr < < " Last text is equal to text. skipping " < < std : : endl ;
return ;
}
std : : cerr < < " New last text. Performing the filter " < < std : : endl ;
mLastFilterText = text ;
model - > update ( ) ;
2018-02-15 00:02:08 +01:00
restoreInvisibleItems ( ) ;
2018-01-28 21:54:56 +01:00
QCursorContextBlocker q ( ui . dirTreeView ) ;
2010-11-30 12:29:04 +00:00
2018-01-23 22:18:35 +01:00
if ( proxyModel = = tree_proxyModel )
{
QCoreApplication : : processEvents ( ) ;
std : : list < std : : string > keywords ;
std : : list < DirDetails > result_list ;
2018-01-24 00:26:22 +01:00
if ( text = = " " )
2018-01-23 22:18:35 +01:00
return ;
2018-01-24 21:14:26 +01:00
if ( text . length ( ) < 3 )
return ;
2018-01-23 22:18:35 +01:00
FileSearchFlags flags = isRemote ( ) ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL ;
2018-01-24 21:14:26 +01:00
QStringList lst = text . split ( " " , QString : : SkipEmptyParts ) ;
2018-01-23 22:18:35 +01:00
2018-01-24 21:14:26 +01:00
for ( auto it ( lst . begin ( ) ) ; it ! = lst . end ( ) ; + + it )
keywords . push_back ( ( * it ) . toStdString ( ) ) ;
2018-01-23 22:18:35 +01:00
2018-01-24 21:14:26 +01:00
if ( keywords . size ( ) > 1 )
{
RsRegularExpression : : NameExpression exp ( RsRegularExpression : : ContainsAllStrings , keywords , true ) ;
rsFiles - > SearchBoolExp ( & exp , result_list , flags ) ;
}
else
rsFiles - > SearchKeywords ( keywords , result_list , flags ) ;
2018-01-24 21:26:35 +01:00
# ifdef DEBUG_SHARED_FILES_DIALOG
2018-01-24 21:14:26 +01:00
std : : cerr < < " Found " < < result_list . size ( ) < < " results " < < std : : endl ;
2018-01-24 21:26:35 +01:00
# endif
2018-01-24 21:14:26 +01:00
if ( result_list . size ( ) > MAX_SEARCH_RESULTS )
return ;
2018-01-23 22:18:35 +01:00
# ifdef DEBUG_SHARED_FILES_DIALOG
std : : cerr < < " Found this result: " < < std : : endl ;
# endif
std : : vector < std : : set < void * > > pointers ( 2 , std : : set < void * > ( ) ) ; // at least two levels need to be here.
2010-11-30 12:29:04 +00:00
2018-01-23 22:18:35 +01:00
// Then show only the ones we need
for ( auto it ( result_list . begin ( ) ) ; it ! = result_list . end ( ) ; + + it )
{
# ifdef DEBUG_SHARED_FILES_DIALOG
std : : cerr < < ( void * ) ( * it ) . ref < < " parents: " ;
# endif
DirDetails & det ( * it ) ;
void * p = NULL ;
std : : list < void * > lst ;
lst . push_back ( det . ref ) ;
while ( det . type = = DIR_TYPE_FILE | | det . type = = DIR_TYPE_DIR )
{
p = det . parent ;
rsFiles - > RequestDirDetails ( p , det , flags ) ;
# ifdef DEBUG_SHARED_FILES_DIALOG
std : : cerr < < " " < < ( void * ) p < < " ( " < < ( int ) det . type < < " ) " ;
# endif
lst . push_front ( p ) ;
}
# ifdef DEBUG_SHARED_FILES_DIALOG
std : : cerr < < std : : endl ;
# endif
uint32_t u = 0 ;
for ( auto it2 ( lst . begin ( ) ) ; it2 ! = lst . end ( ) ; + + it2 , + + u )
{
if ( pointers . size ( ) < = u )
pointers . resize ( u + 5 ) ;
pointers [ u ] . insert ( * it2 ) ;
}
}
int rowCount = ui . dirTreeView - > model ( ) - > rowCount ( ) ;
for ( int row = 0 ; row < rowCount ; + + row )
2018-02-15 00:02:08 +01:00
recursMakeVisible ( ui . dirTreeView , proxyModel , ui . dirTreeView - > model ( ) - > index ( row , COLUMN_NAME ) , 0 , pointers , mHiddenIndexes ) ;
2018-01-23 22:18:35 +01:00
}
else
{
int rowCount = ui . dirTreeView - > model ( ) - > rowCount ( ) ;
for ( int row = 0 ; row < rowCount ; + + row )
flat_FilterItem ( ui . dirTreeView - > model ( ) - > index ( row , COLUMN_NAME ) , text , 0 ) ;
}
# ifdef DEPRECATED_CODE
2013-02-22 21:42:27 +00:00
int rowCount = ui . dirTreeView - > model ( ) - > rowCount ( ) ;
2014-10-21 22:33:02 +00:00
for ( int row = 0 ; row < rowCount ; + + row )
2011-04-01 21:46:06 +00:00
if ( proxyModel = = tree_proxyModel )
2014-05-29 14:49:45 +00:00
tree_FilterItem ( ui . dirTreeView - > model ( ) - > index ( row , COLUMN_NAME ) , text , 0 ) ;
2011-04-01 21:46:06 +00:00
else
2014-05-29 14:49:45 +00:00
flat_FilterItem ( ui . dirTreeView - > model ( ) - > index ( row , COLUMN_NAME ) , text , 0 ) ;
2018-01-23 22:18:35 +01:00
# endif
2010-11-30 12:29:04 +00:00
}
2011-08-12 14:06:29 +00:00
bool SharedFilesDialog : : flat_FilterItem ( const QModelIndex & index , const QString & text , int /*level*/ )
2011-04-01 21:46:06 +00:00
{
if ( index . data ( RetroshareDirModel : : FileNameRole ) . toString ( ) . contains ( text , Qt : : CaseInsensitive ) )
{
2013-02-22 21:42:27 +00:00
ui . dirTreeView - > setRowHidden ( index . row ( ) , index . parent ( ) , false ) ;
2011-04-01 21:46:06 +00:00
return false ;
}
else
{
2013-02-22 21:42:27 +00:00
ui . dirTreeView - > setRowHidden ( index . row ( ) , index . parent ( ) , true ) ;
2018-02-15 00:02:08 +01:00
mHiddenIndexes . push_back ( proxyModel - > mapToSource ( index ) ) ;
2011-04-01 21:46:06 +00:00
return true ;
}
}
bool SharedFilesDialog : : tree_FilterItem ( const QModelIndex & index , const QString & text , int level )
2010-11-30 12:29:04 +00:00
{
bool visible = true ;
if ( text . isEmpty ( ) = = false ) {
2011-04-01 21:46:06 +00:00
// better use RetroshareDirModel::getType, but its slow enough
2010-11-30 12:29:04 +00:00
if ( /*index.parent().isValid()*/ level > = 1 ) {
2011-04-01 21:46:06 +00:00
if ( index . data ( RetroshareDirModel : : FileNameRole ) . toString ( ) . contains ( text , Qt : : CaseInsensitive ) = = false ) {
2010-11-30 12:29:04 +00:00
visible = false ;
}
} else {
visible = false ;
}
}
int visibleChildCount = 0 ;
2013-02-22 21:42:27 +00:00
int rowCount = ui . dirTreeView - > model ( ) - > rowCount ( index ) ;
2014-10-21 22:33:02 +00:00
for ( int row = 0 ; row < rowCount ; + + row ) {
2013-02-22 21:42:27 +00:00
if ( tree_FilterItem ( ui . dirTreeView - > model ( ) - > index ( row , index . column ( ) , index ) , text , level + 1 ) ) {
2014-10-21 22:33:02 +00:00
+ + visibleChildCount ;
2010-11-30 12:29:04 +00:00
}
}
if ( visible | | visibleChildCount ) {
2013-02-22 21:42:27 +00:00
ui . dirTreeView - > setRowHidden ( index . row ( ) , index . parent ( ) , false ) ;
2010-11-30 12:29:04 +00:00
} else {
2018-02-15 00:02:08 +01:00
{
2013-02-22 21:42:27 +00:00
ui . dirTreeView - > setRowHidden ( index . row ( ) , index . parent ( ) , true ) ;
2018-02-15 00:02:08 +01:00
mHiddenIndexes . push_back ( proxyModel - > mapToSource ( index ) ) ;
}
2010-11-30 12:29:04 +00:00
}
return ( visible | | visibleChildCount ) ;
}
2011-04-01 21:46:06 +00:00