2018-12-25 15:34:59 -05:00
/*******************************************************************************
* gui / RemoteDirModel . cpp *
* *
* Copyright ( c ) 2006 Retroshare Team < retroshare . project @ gmail . com > *
* *
* This program is free software : you can redistribute it and / or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation , either version 3 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 Affero General Public License for more details . *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program . If not , see < https : //www.gnu.org/licenses/>. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-08-11 17:59:40 -04:00
2018-02-19 14:13:38 -05:00
# include "RemoteDirModel.h"
# include "RsAutoUpdatePage.h"
# include "gui/common/FilesDefs.h"
# include "gui/common/GroupDefs.h"
# include "gui/common/RsCollection.h"
# include "gui/common/RsUrlHandler.h"
# include "gui/gxs/GxsIdDetails.h"
# include "retroshare/rsfiles.h"
# include "retroshare/rspeers.h"
# include "util/misc.h"
2018-04-22 11:15:40 -04:00
# include "retroshare/rsexpr.h"
2018-02-19 14:13:38 -05:00
2010-07-23 14:52:58 -04:00
# include <QDir>
2018-02-19 14:13:38 -05:00
# include <QFileInfo>
2010-07-23 14:52:58 -04:00
# include <QMimeData>
2011-04-09 15:43:09 -04:00
# include <QTimer>
2018-02-19 14:13:38 -05:00
# include <QUrl>
2007-11-14 22:18:48 -05:00
2008-11-02 10:20:42 -05:00
# include <algorithm>
2018-02-19 14:13:38 -05:00
# include <set>
2016-09-29 06:45:01 -04:00
# include <time.h>
2007-11-14 22:18:48 -05:00
2008-07-09 05:53:47 -04:00
/*****
* # define RDM_DEBUG
2018-04-22 11:38:14 -04:00
* # define RDM_SEARCH_DEBUG
2008-07-09 05:53:47 -04:00
* * * */
2016-11-20 14:42:14 -05:00
static const uint32_t FLAT_VIEW_MAX_REFS_PER_SECOND = 2000 ;
2018-02-24 12:15:54 -05:00
static const size_t FLAT_VIEW_MAX_REFS_TABLE_SIZE = 10000 ; //
2016-11-20 14:42:14 -05:00
static const uint32_t FLAT_VIEW_MIN_DELAY_BETWEEN_UPDATES = 120 ; // dont rebuild ref list more than every 2 mins.
2011-04-01 17:46:06 -04:00
RetroshareDirModel : : RetroshareDirModel ( bool mode , QObject * parent )
2018-02-24 08:07:32 -05:00
: QAbstractItemModel ( parent ) , _visible ( false )
, ageIndicator ( IND_ALWAYS )
, RemoteMode ( mode ) //, nIndex(1), indexSet(1) /* ass zero index cant be used */
, mLastRemote ( false ) , mLastReq ( 0 ) , mUpdating ( false )
2008-07-04 10:41:24 -04:00
{
2013-10-19 16:59:55 -04:00
# if QT_VERSION < QT_VERSION_CHECK (5, 0, 0)
2008-07-04 10:41:24 -04:00
setSupportedDragActions ( Qt : : CopyAction ) ;
2013-10-19 16:59:55 -04:00
# endif
2009-10-13 16:36:29 -04:00
treeStyle ( ) ;
2016-11-07 16:24:02 -05:00
2018-02-24 08:07:32 -05:00
mDirDetails . ref = ( void * ) intptr_t ( 0xffffffff ) ;
2008-07-04 10:41:24 -04:00
}
2018-02-24 08:07:32 -05:00
TreeStyle_RDM : : TreeStyle_RDM ( bool mode )
: RetroshareDirModel ( mode ) , _showEmpty ( false )
{
_showEmptyAct = new QAction ( QIcon ( ) , tr ( " Show Empty " ) , this ) ;
_showEmptyAct - > setCheckable ( true ) ;
_showEmptyAct - > setChecked ( _showEmpty ) ;
connect ( _showEmptyAct , SIGNAL ( toggled ( bool ) ) , this , SLOT ( showEmpty ( bool ) ) ) ;
}
FlatStyle_RDM : : FlatStyle_RDM ( bool mode )
: RetroshareDirModel ( mode ) , _ref_mutex ( " Flat file list " )
{
_needs_update = true ;
{
RS_STACK_MUTEX ( _ref_mutex ) ;
_last_update = 0 ;
}
}
2013-10-19 16:59:55 -04:00
// QAbstractItemModel::setSupportedDragActions() was replaced by virtual QAbstractItemModel::supportedDragActions()
# if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
Qt : : DropActions RetroshareDirModel : : supportedDragActions ( ) const
{
return Qt : : CopyAction ;
}
# endif
2016-11-14 15:58:58 -05:00
static bool isNewerThanEpoque ( uint32_t ts )
2016-09-28 15:55:03 -04:00
{
2016-11-14 15:58:58 -05:00
return ts > 0 ; // this should be conservative enough
2016-09-28 15:55:03 -04:00
}
2011-04-01 17:46:06 -04:00
void RetroshareDirModel : : treeStyle ( )
2009-05-31 19:06:14 -04:00
{
2020-02-22 09:41:34 -05:00
categoryIcon . addPixmap ( QPixmap ( " :/icons/folder.png " ) ,
2009-05-31 19:06:14 -04:00
QIcon : : Normal , QIcon : : Off ) ;
2020-02-22 09:41:34 -05:00
categoryIcon . addPixmap ( QPixmap ( " :/icons/folderopen.png " ) ,
2009-05-31 19:06:14 -04:00
QIcon : : Normal , QIcon : : On ) ;
peerIcon = QIcon ( " :/images/user/identity16.png " ) ;
}
2017-09-14 16:01:52 -04:00
void TreeStyle_RDM : : update ( )
{
preMods ( ) ;
postMods ( ) ;
}
2016-09-11 11:52:12 -04:00
void TreeStyle_RDM : : updateRef ( const QModelIndex & indx ) const
{
rsFiles - > requestDirUpdate ( indx . internalPointer ( ) ) ;
}
2018-02-24 08:07:32 -05:00
QMenu * TreeStyle_RDM : : getContextMenu ( QMenu * contextMenu )
{
if ( ! contextMenu ) {
contextMenu = new QMenu ( ) ;
} else {
if ( RemoteMode )
contextMenu - > addSeparator ( ) ;
}
if ( RemoteMode )
contextMenu - > addAction ( _showEmptyAct ) ;
return contextMenu ;
}
2011-04-01 17:46:06 -04:00
bool TreeStyle_RDM : : hasChildren ( const QModelIndex & parent ) const
{
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::hasChildren() : " < < parent . internalPointer ( ) ;
std : : cerr < < " : " ;
2007-11-14 22:18:48 -05:00
# endif
2011-04-01 17:46:06 -04:00
if ( ! parent . isValid ( ) )
{
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " root -> true " ;
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
2011-04-01 17:46:06 -04:00
return true ;
}
2007-11-14 22:18:48 -05:00
2011-04-01 17:46:06 -04:00
void * ref = parent . internalPointer ( ) ;
2007-11-14 22:18:48 -05:00
2016-08-19 12:49:42 -04:00
DirDetails details ;
if ( ! requestDirDetails ( ref , RemoteMode , details ) )
{
2011-04-01 17:46:06 -04:00
/* error */
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " lookup failed -> false " ;
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
2011-04-01 17:46:06 -04:00
return false ;
}
2009-07-07 14:56:31 -04:00
2018-09-27 10:53:08 -04:00
if ( details . type = = DIR_TYPE_FILE | | details . type = = DIR_TYPE_EXTRA_FILE )
2011-04-01 17:46:06 -04:00
{
# ifdef RDM_DEBUG
std : : cerr < < " lookup FILE -> false " ;
std : : cerr < < std : : endl ;
# endif
return false ;
}
/* PERSON/DIR*/
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2018-04-22 11:15:40 -04:00
std : : cerr < < " lookup PER/DIR # " < < details . count ;
2011-04-01 17:46:06 -04:00
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
2016-08-19 12:49:42 -04:00
return ( details . count > 0 ) ; /* do we have children? */
2011-04-01 17:46:06 -04:00
}
bool FlatStyle_RDM : : hasChildren ( const QModelIndex & parent ) const
{
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::hasChildren() : " < < parent . internalPointer ( ) ;
std : : cerr < < " : " ;
2007-11-14 22:18:48 -05:00
# endif
2011-04-01 17:46:06 -04:00
if ( ! parent . isValid ( ) )
{
# ifdef RDM_DEBUG
std : : cerr < < " root -> true " ;
std : : cerr < < std : : endl ;
# endif
return true ;
}
else
return false ;
}
2007-11-14 22:18:48 -05:00
2011-04-01 17:46:06 -04:00
int TreeStyle_RDM : : rowCount ( const QModelIndex & parent ) const
{
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::rowCount(): " < < parent . internalPointer ( ) ;
std : : cerr < < " : " ;
2007-11-14 22:18:48 -05:00
# endif
2011-04-01 17:46:06 -04:00
void * ref = ( parent . isValid ( ) ) ? parent . internalPointer ( ) : NULL ;
2007-11-14 22:18:48 -05:00
2018-02-24 08:07:32 -05:00
if ( ( ! ref ) & & RemoteMode )
_parentRow . clear ( ) ; //Only clear it when asking root child number and in remote mode.
2007-11-14 22:18:48 -05:00
2018-02-24 08:07:32 -05:00
DirDetails details ;
if ( ! requestDirDetails ( ref , RemoteMode , details ) )
2011-04-01 17:46:06 -04:00
{
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " lookup failed -> 0 " ;
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
2011-04-01 17:46:06 -04:00
return 0 ;
}
2018-09-27 10:53:08 -04:00
if ( details . type = = DIR_TYPE_FILE | | details . type = = DIR_TYPE_EXTRA_FILE )
2011-04-01 17:46:06 -04:00
{
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " lookup FILE: 0 " ;
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
2011-04-01 17:46:06 -04:00
return 0 ;
}
2009-07-07 14:56:31 -04:00
2011-04-01 17:46:06 -04:00
/* else PERSON/DIR*/
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2018-04-22 11:15:40 -04:00
std : : cerr < < " lookup PER/DIR # " < < details . count ;
2011-04-01 17:46:06 -04:00
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
2018-02-24 08:07:32 -05:00
if ( ( details . type = = DIR_TYPE_ROOT ) & & ! _showEmpty & & RemoteMode )
{
DirDetails childDetails ;
//Scan all children to know if they are empty.
//And save their real row index
//Prefer do like that than modify requestDirDetails with a new flag (rsFiles->RequestDirDetails)
for ( uint64_t i = 0 ; i < details . count ; + + i )
{
if ( requestDirDetails ( details . children [ i ] . ref , RemoteMode , childDetails ) & & ( childDetails . count > 0 ) )
_parentRow . push_back ( i ) ;
}
return _parentRow . size ( ) ;
}
return details . count ;
2011-04-01 17:46:06 -04:00
}
int FlatStyle_RDM : : rowCount ( const QModelIndex & parent ) const
{
2011-08-12 10:06:29 -04:00
Q_UNUSED ( parent ) ;
2011-04-01 17:46:06 -04:00
# ifdef RDM_DEBUG
std : : cerr < < " RetroshareDirModel::rowCount(): " < < parent . internalPointer ( ) ;
std : : cerr < < " : " ;
# endif
2016-09-13 15:23:27 -04:00
RS_STACK_MUTEX ( _ref_mutex ) ;
2011-04-01 17:46:06 -04:00
return _ref_entries . size ( ) ;
}
2018-02-24 08:07:32 -05:00
2011-08-12 10:06:29 -04:00
int TreeStyle_RDM : : columnCount ( const QModelIndex & /*parent*/ ) const
2011-04-01 17:46:06 -04:00
{
2018-02-19 14:13:38 -05:00
return COLUMN_COUNT ;
2011-04-01 17:46:06 -04:00
}
2011-08-12 10:06:29 -04:00
int FlatStyle_RDM : : columnCount ( const QModelIndex & /*parent*/ ) const
2011-04-01 17:46:06 -04:00
{
2018-02-19 14:13:38 -05:00
return COLUMN_COUNT ;
2011-04-01 17:46:06 -04:00
}
2018-02-24 08:07:32 -05:00
2012-11-02 09:52:29 -04:00
QString RetroshareDirModel : : getFlagsString ( FileStorageFlags flags )
2009-08-10 14:55:49 -04:00
{
2012-11-06 15:46:56 -05:00
char str [ 11 ] = " - - - " ;
2012-10-21 15:39:56 -04:00
2016-10-31 09:26:01 -04:00
if ( flags & DIR_FLAGS_BROWSABLE ) str [ 0 ] = ' B ' ;
if ( flags & DIR_FLAGS_ANONYMOUS_SEARCH ) str [ 3 ] = ' S ' ;
if ( flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD ) str [ 6 ] = ' N ' ;
2012-10-21 15:39:56 -04:00
return QString ( str ) ;
}
2016-11-01 05:46:29 -04:00
QString RetroshareDirModel : : getGroupsString ( FileStorageFlags flags , const std : : list < RsNodeGroupId > & group_ids )
2012-10-21 15:39:56 -04:00
{
2016-11-01 05:46:29 -04:00
if ( ! ( flags & DIR_FLAGS_BROWSABLE ) )
return QString ( ) ;
if ( group_ids . empty ( ) )
2016-11-01 09:28:00 -04:00
return tr ( " [All friend nodes] " ) ;
2016-11-01 05:46:29 -04:00
QString groups_str = tr ( " Only " ) ;
2012-11-13 14:37:51 -05:00
RsGroupInfo group_info ;
2012-10-21 15:39:56 -04:00
2016-07-05 23:49:43 -04:00
for ( std : : list < RsNodeGroupId > : : const_iterator it ( group_ids . begin ( ) ) ; it ! = group_ids . end ( ) ; )
2012-11-13 14:37:51 -05:00
if ( rsPeers - > getGroupInfo ( * it , group_info ) )
{
2012-12-11 19:04:01 -05:00
groups_str + = GroupDefs : : name ( group_info ) ;
2012-11-13 14:37:51 -05:00
if ( + + it ! = group_ids . end ( ) )
groups_str + = " , " ;
}
2012-12-01 14:22:22 -05:00
else
+ + it ;
2012-10-21 15:39:56 -04:00
return groups_str ;
2009-08-10 14:55:49 -04:00
}
2007-11-14 22:18:48 -05:00
2011-04-01 17:46:06 -04:00
QString RetroshareDirModel : : getAgeIndicatorString ( const DirDetails & details ) const
2009-10-13 16:36:29 -04:00
{
QString ret ( " " ) ;
2010-10-28 13:26:00 -04:00
QString nind = tr ( " NEW " ) ;
// QString oind = tr("OLD");
2016-11-14 15:58:58 -05:00
int32_t age = time ( NULL ) - details . max_mtime ;
2009-10-13 16:36:29 -04:00
switch ( ageIndicator ) {
case IND_LAST_DAY :
if ( age < 24 * 60 * 60 ) return nind ;
break ;
case IND_LAST_WEEK :
if ( age < 7 * 24 * 60 * 60 ) return nind ;
break ;
case IND_LAST_MONTH :
if ( age < 30 * 24 * 60 * 60 ) return nind ;
break ;
2010-02-08 17:32:00 -05:00
// case IND_OLDER:
// if (age >= 30 * 24 * 60 * 60) return oind;
// break;
case IND_ALWAYS :
2009-10-13 16:36:29 -04:00
return ret ;
default :
return ret ;
}
return ret ;
}
2016-11-01 05:30:36 -04:00
const QIcon & RetroshareDirModel : : getFlagsIcon ( FileStorageFlags flags )
{
static QIcon * static_icons [ 8 ] = { NULL } ;
int n = 0 ;
if ( flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD ) n + = 1 ;
if ( flags & DIR_FLAGS_ANONYMOUS_SEARCH ) n + = 2 ;
if ( flags & DIR_FLAGS_BROWSABLE ) n + = 4 ;
n - = 1 ;
if ( static_icons [ n ] = = NULL )
{
QList < QIcon > icons ;
if ( flags & DIR_FLAGS_ANONYMOUS_SEARCH )
icons . push_back ( QIcon ( " :icons/search_red_128.png " ) ) ;
else
icons . push_back ( QIcon ( " :icons/void_128.png " ) ) ;
if ( flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD )
icons . push_back ( QIcon ( " :icons/anonymous_blue_128.png " ) ) ;
else
icons . push_back ( QIcon ( " :icons/void_128.png " ) ) ;
if ( flags & DIR_FLAGS_BROWSABLE )
icons . push_back ( QIcon ( " :icons/browsable_green_128.png " ) ) ;
else
icons . push_back ( QIcon ( " :icons/void_128.png " ) ) ;
QPixmap pix ;
GxsIdDetails : : GenerateCombinedPixmap ( pix , icons , 128 ) ;
static_icons [ n ] = new QIcon ( pix ) ;
2018-04-22 11:15:40 -04:00
std : : cerr < < " Generated icon for flags " < < std : : hex < < flags < < std : : dec < < std : : endl ;
2016-11-01 05:30:36 -04:00
}
return * static_icons [ n ] ;
}
2018-06-07 08:54:58 -04:00
QVariant RetroshareDirModel : : filterRole ( const DirDetails & details , int /*coln*/ ) const
2018-04-22 11:15:40 -04:00
{
if ( mFilteredPointers . empty ( ) | | mFilteredPointers . find ( details . ref ) ! = mFilteredPointers . end ( ) )
return QString ( RETROSHARE_DIR_MODEL_FILTER_STRING ) ;
else
return QVariant ( ) ;
}
2011-04-01 17:46:06 -04:00
QVariant RetroshareDirModel : : decorationRole ( const DirDetails & details , int coln ) const
{
2018-02-19 14:13:38 -05:00
if ( coln = = COLUMN_FRIEND_ACCESS )
2016-11-01 05:30:36 -04:00
{
if ( details . type = = DIR_TYPE_PERSON ) return QVariant ( ) ;
return getFlagsIcon ( details . flags ) ;
}
2011-04-01 17:46:06 -04:00
if ( coln > 0 )
return QVariant ( ) ;
2010-02-08 17:32:00 -05:00
2011-04-01 17:46:06 -04:00
if ( details . type = = DIR_TYPE_PERSON )
2016-09-28 15:55:03 -04:00
{
2016-11-14 15:58:58 -05:00
time_t now = time ( NULL ) ;
if ( ageIndicator ! = IND_ALWAYS & & now > details . max_mtime + ageIndicator )
2011-04-01 17:46:06 -04:00
return QIcon ( " :/images/folder_grey.png " ) ;
else if ( ageIndicator = = IND_LAST_DAY )
return QIcon ( " :/images/folder_green.png " ) ;
else if ( ageIndicator = = IND_LAST_WEEK )
return QIcon ( " :/images/folder_yellow.png " ) ;
else if ( ageIndicator = = IND_LAST_MONTH )
return QIcon ( " :/images/folder_red.png " ) ;
else
return ( QIcon ( peerIcon ) ) ;
}
else if ( details . type = = DIR_TYPE_DIR )
{
2016-11-14 15:58:58 -05:00
time_t now = time ( NULL ) ;
if ( ageIndicator ! = IND_ALWAYS & & now > details . max_mtime + ageIndicator )
2011-04-01 17:46:06 -04:00
return QIcon ( " :/images/folder_grey.png " ) ;
else if ( ageIndicator = = IND_LAST_DAY )
return QIcon ( " :/images/folder_green.png " ) ;
else if ( ageIndicator = = IND_LAST_WEEK )
return QIcon ( " :/images/folder_yellow.png " ) ;
else if ( ageIndicator = = IND_LAST_MONTH )
return QIcon ( " :/images/folder_red.png " ) ;
else
return QIcon ( categoryIcon ) ;
}
2018-09-27 10:53:08 -04:00
else if ( details . type = = DIR_TYPE_FILE | | details . type = = DIR_TYPE_EXTRA_FILE ) /* File */
2011-04-01 17:46:06 -04:00
{
// extensions predefined
2016-09-18 16:32:30 -04:00
if ( details . hash . isNull ( ) )
return QIcon ( " :/images/reset.png " ) ; // file is being hashed
else
2020-04-19 07:10:30 -04:00
return FilesDefs : : getIconFromFileType ( QString : : fromUtf8 ( details . name . c_str ( ) ) ) ;
2011-04-01 17:46:06 -04:00
}
else
return QVariant ( ) ;
2007-11-14 22:18:48 -05:00
2011-04-01 17:46:06 -04:00
} /* end of DecorationRole */
2007-11-14 22:18:48 -05:00
2011-04-01 17:46:06 -04:00
QVariant TreeStyle_RDM : : displayRole ( const DirDetails & details , int coln ) const
{
/*
2007-11-14 22:18:48 -05:00
* Person : name , id , 0 , 0 ;
* File : name , size , rank , ( 0 ) ts
* Dir : name , ( 0 ) count , ( 0 ) path , ( 0 ) ts
*/
if ( details . type = = DIR_TYPE_PERSON ) /* Person */
{
2016-10-22 17:48:19 -04:00
switch ( coln )
2007-11-14 22:18:48 -05:00
{
2018-02-19 14:13:38 -05:00
case COLUMN_NAME : {
2016-10-22 17:48:19 -04:00
//SharedDirStats stats ;
2016-11-16 05:03:02 -05:00
QString res ;
2016-11-11 14:25:11 -05:00
2016-11-16 05:03:02 -05:00
if ( RemoteMode )
res = QString : : fromUtf8 ( rsPeers - > getPeerName ( details . id ) . c_str ( ) ) ;
2018-09-27 15:42:21 -04:00
else if ( details . id = = rsPeers - > getOwnId ( ) )
res = tr ( " My files " ) ;
else
res = tr ( " Temporary shared files " ) ;
2016-11-16 05:03:02 -05:00
return res ;
2016-11-11 14:25:11 -05:00
}
2018-02-19 14:13:38 -05:00
case COLUMN_FILENB : {
2016-11-16 05:03:02 -05:00
SharedDirStats stats ;
2016-11-11 14:25:11 -05:00
2016-11-16 05:03:02 -05:00
if ( RemoteMode )
rsFiles - > getSharedDirStatistics ( details . id , stats ) ;
2018-09-27 16:14:00 -04:00
else if ( details . id = = rsPeers - > getOwnId ( ) )
2018-02-19 14:13:38 -05:00
rsFiles - > getSharedDirStatistics ( rsPeers - > getOwnId ( ) , stats ) ;
2018-09-27 16:14:00 -04:00
else
stats . total_number_of_files = details . count ;
2018-02-19 14:13:38 -05:00
if ( stats . total_number_of_files > 0 )
2016-11-16 05:03:02 -05:00
{
2018-02-19 14:13:38 -05:00
if ( stats . total_number_of_files > 1 )
return QString : : number ( stats . total_number_of_files ) + " " + tr ( " Files " ) ;
else
return QString : : number ( stats . total_number_of_files ) + " " + tr ( " File " ) ;
2016-11-16 05:03:02 -05:00
}
2018-02-19 14:13:38 -05:00
return tr ( " Empty " ) ;
}
case COLUMN_SIZE : {
SharedDirStats stats ;
2016-11-11 14:25:11 -05:00
2018-02-19 14:13:38 -05:00
if ( RemoteMode )
rsFiles - > getSharedDirStatistics ( details . id , stats ) ;
2018-09-27 16:14:00 -04:00
else if ( details . id = = rsPeers - > getOwnId ( ) )
2018-02-19 14:13:38 -05:00
rsFiles - > getSharedDirStatistics ( rsPeers - > getOwnId ( ) , stats ) ;
2018-09-27 16:14:00 -04:00
else
return QString ( ) ;
2016-11-11 14:25:11 -05:00
2018-02-19 14:13:38 -05:00
if ( stats . total_shared_size > 0 )
return misc : : friendlyUnit ( stats . total_shared_size ) ;
return QString ( ) ;
2016-11-16 05:03:02 -05:00
}
2018-02-19 14:13:38 -05:00
case COLUMN_AGE :
if ( ! isNewerThanEpoque ( details . max_mtime ) )
2016-11-16 05:03:02 -05:00
return QString ( ) ;
2018-09-27 16:14:00 -04:00
else if ( details . id ! = rsPeers - > getOwnId ( ) )
return QString ( ) ;
2016-11-16 05:03:02 -05:00
else
2018-02-19 14:13:38 -05:00
return misc : : timeRelativeToNow ( details . max_mtime ) ;
2016-11-16 05:03:02 -05:00
default :
2010-01-30 15:47:34 -05:00
return QString ( ) ;
2007-11-14 22:18:48 -05:00
}
}
2018-09-27 10:53:08 -04:00
else if ( details . type = = DIR_TYPE_FILE | | details . type = = DIR_TYPE_EXTRA_FILE ) /* File */
2007-11-14 22:18:48 -05:00
{
switch ( coln )
{
2018-02-19 14:13:38 -05:00
case COLUMN_NAME :
2010-01-30 15:47:34 -05:00
return QString : : fromUtf8 ( details . name . c_str ( ) ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_FILENB :
return QVariant ( ) ;
case COLUMN_SIZE :
2010-10-28 13:26:00 -04:00
return misc : : friendlyUnit ( details . count ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_AGE :
2018-09-27 16:14:00 -04:00
return ( details . type = = DIR_TYPE_FILE ) ? ( misc : : timeRelativeToNow ( details . max_mtime ) ) : QString ( ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_FRIEND_ACCESS :
return QVariant ( ) ;
case COLUMN_WN_VISU_DIR :
return getGroupsString ( details . flags , details . parent_groups ) ;
2012-10-21 15:39:56 -04:00
2007-11-14 22:18:48 -05:00
default :
2011-04-01 17:46:06 -04:00
return tr ( " FILE " ) ;
2007-11-14 22:18:48 -05:00
}
}
else if ( details . type = = DIR_TYPE_DIR ) /* Dir */
{
switch ( coln )
{
2018-02-19 14:13:38 -05:00
case COLUMN_NAME :
2011-04-01 17:46:06 -04:00
return QString : : fromUtf8 ( details . name . c_str ( ) ) ;
2009-08-10 14:55:49 -04:00
break ;
2018-02-19 14:13:38 -05:00
case COLUMN_FILENB :
2010-10-28 13:26:00 -04:00
if ( details . count > 1 )
2009-08-10 14:55:49 -04:00
{
2010-10-28 13:26:00 -04:00
return QString : : number ( details . count ) + " " + tr ( " Files " ) ;
2009-08-10 14:55:49 -04:00
}
2010-10-28 13:26:00 -04:00
return QString : : number ( details . count ) + " " + tr ( " File " ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_SIZE :
return QVariant ( ) ;
case COLUMN_AGE :
2016-11-14 15:58:58 -05:00
return misc : : timeRelativeToNow ( details . max_mtime ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_FRIEND_ACCESS :
return QVariant ( ) ;
case COLUMN_WN_VISU_DIR :
return getGroupsString ( details . flags , details . parent_groups ) ;
2012-10-21 15:39:56 -04:00
2007-11-14 22:18:48 -05:00
default :
2010-10-28 13:26:00 -04:00
return tr ( " DIR " ) ;
2007-11-14 22:18:48 -05:00
}
}
2010-10-28 13:26:00 -04:00
return QVariant ( ) ;
2011-04-01 17:46:06 -04:00
} /* end of DisplayRole */
2008-11-18 17:59:33 -05:00
2016-11-20 14:42:14 -05:00
void FlatStyle_RDM : : update ( )
{
if ( _needs_update )
{
preMods ( ) ;
postMods ( ) ;
}
}
2018-02-19 14:13:38 -05:00
2018-02-24 12:15:54 -05:00
bool FlatStyle_RDM : : isMaxRefsTableSize ( size_t * maxSize /*=NULL*/ )
{
if ( maxSize )
* maxSize = FLAT_VIEW_MAX_REFS_TABLE_SIZE ;
return ( _ref_entries . size ( ) > = FLAT_VIEW_MAX_REFS_TABLE_SIZE ) ;
}
2011-04-07 16:09:32 -04:00
QString FlatStyle_RDM : : computeDirectoryPath ( const DirDetails & details ) const
{
QString dir ;
2018-02-19 14:13:38 -05:00
DirDetails det ;
2011-04-07 16:09:32 -04:00
2018-02-19 14:13:38 -05:00
if ( ! requestDirDetails ( details . parent , RemoteMode , det ) )
return QString ( ) ;
2011-04-07 16:09:32 -04:00
2011-04-07 18:05:22 -04:00
# ifdef SHOW_TOTAL_PATH
2011-04-07 16:09:32 -04:00
do
{
2011-04-07 18:05:22 -04:00
# endif
2018-02-19 14:13:38 -05:00
dir = QString : : fromUtf8 ( det . name . c_str ( ) ) + " / " + dir ;
2011-04-07 16:09:32 -04:00
2011-04-07 18:05:22 -04:00
# ifdef SHOW_TOTAL_PATH
2011-04-07 16:09:32 -04:00
if ( ! requestDirDetails ( det . parent , det , flags ) )
break ;
}
2014-01-04 17:39:34 -05:00
while ( det - > parent ! = NULL ) ;
2011-04-07 18:05:22 -04:00
# endif
2011-04-07 16:09:32 -04:00
return dir ;
}
2011-04-01 17:46:06 -04:00
QVariant FlatStyle_RDM : : displayRole ( const DirDetails & details , int coln ) const
{
2018-09-27 10:53:08 -04:00
if ( details . type = = DIR_TYPE_FILE | | details . type = = DIR_TYPE_EXTRA_FILE ) /* File */
2011-04-01 17:46:06 -04:00
switch ( coln )
{
2018-02-19 14:13:38 -05:00
case COLUMN_NAME : return QString : : fromUtf8 ( details . name . c_str ( ) ) ;
case COLUMN_FILENB : return QString ( ) ;
case COLUMN_SIZE : return misc : : friendlyUnit ( details . count ) ;
case COLUMN_AGE : return misc : : timeRelativeToNow ( details . max_mtime ) ;
case COLUMN_FRIEND_ACCESS : return QString : : fromUtf8 ( rsPeers - > getPeerName ( details . id ) . c_str ( ) ) ;
case COLUMN_WN_VISU_DIR : return computeDirectoryPath ( details ) ;
2011-04-01 17:46:06 -04:00
default :
return QVariant ( ) ;
}
2010-09-19 20:10:51 -04:00
2011-04-01 17:46:06 -04:00
return QVariant ( ) ;
} /* end of DisplayRole */
2018-02-19 14:13:38 -05:00
2011-08-12 10:06:29 -04:00
QVariant TreeStyle_RDM : : sortRole ( const QModelIndex & /*index*/ , const DirDetails & details , int coln ) const
2011-04-01 17:46:06 -04:00
{
/*
* Person : name , id , 0 , 0 ;
* File : name , size , rank , ( 0 ) ts
* Dir : name , ( 0 ) count , ( 0 ) path , ( 0 ) ts
*/
2010-09-19 20:10:51 -04:00
2011-04-01 17:46:06 -04:00
if ( details . type = = DIR_TYPE_PERSON ) /* Person */
{
switch ( coln )
{
2018-02-19 14:13:38 -05:00
case COLUMN_NAME :
2013-06-13 11:19:38 -04:00
return ( RemoteMode ) ? ( QString : : fromUtf8 ( rsPeers - > getPeerName ( details . id ) . c_str ( ) ) ) : tr ( " My files " ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_FILENB : {
SharedDirStats stats ;
if ( RemoteMode )
rsFiles - > getSharedDirStatistics ( details . id , stats ) ;
else
rsFiles - > getSharedDirStatistics ( rsPeers - > getOwnId ( ) , stats ) ;
return ( qulonglong ) stats . total_number_of_files ;
}
case COLUMN_SIZE : {
SharedDirStats stats ;
if ( RemoteMode )
rsFiles - > getSharedDirStatistics ( details . id , stats ) ;
else
rsFiles - > getSharedDirStatistics ( rsPeers - > getOwnId ( ) , stats ) ;
return ( qulonglong ) stats . total_shared_size ;
}
case COLUMN_AGE :
2016-11-14 15:58:58 -05:00
return details . max_mtime ;
2011-04-01 17:46:06 -04:00
default :
return QString ( ) ;
}
}
2018-09-27 10:53:08 -04:00
else if ( details . type = = DIR_TYPE_FILE | | details . type = = DIR_TYPE_EXTRA_FILE ) /* File */
2011-04-01 17:46:06 -04:00
{
switch ( coln )
{
2018-02-19 14:13:38 -05:00
case COLUMN_NAME :
2011-04-01 17:46:06 -04:00
return QString : : fromUtf8 ( details . name . c_str ( ) ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_FILENB :
return ( qulonglong ) 0 ;
case COLUMN_SIZE :
2011-04-01 17:46:06 -04:00
return ( qulonglong ) details . count ;
2018-02-19 14:13:38 -05:00
case COLUMN_AGE :
return details . max_mtime ;
case COLUMN_FRIEND_ACCESS :
2011-04-01 17:46:06 -04:00
return getFlagsString ( details . flags ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_WN_VISU_DIR :
2011-04-01 17:46:06 -04:00
{
QString ind ( " " ) ;
if ( ageIndicator ! = IND_ALWAYS )
ind = getAgeIndicatorString ( details ) ;
return ind ;
}
default :
return tr ( " FILE " ) ;
}
}
else if ( details . type = = DIR_TYPE_DIR ) /* Dir */
{
switch ( coln )
{
2018-02-19 14:13:38 -05:00
case COLUMN_NAME :
2011-04-01 17:46:06 -04:00
return QString : : fromUtf8 ( details . name . c_str ( ) ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_FILENB :
2011-04-01 17:46:06 -04:00
return ( qulonglong ) details . count ;
2018-02-19 14:13:38 -05:00
case COLUMN_SIZE :
return ( qulonglong ) 0 ;
case COLUMN_AGE :
2016-11-14 15:58:58 -05:00
return details . max_mtime ;
2018-02-19 14:13:38 -05:00
case COLUMN_FRIEND_ACCESS :
2011-04-01 17:46:06 -04:00
return getFlagsString ( details . flags ) ;
default :
return tr ( " DIR " ) ;
}
}
return QVariant ( ) ;
2011-04-03 15:59:12 -04:00
}
2016-10-19 09:41:25 -04:00
QVariant FlatStyle_RDM : : sortRole ( const QModelIndex & /*index*/ , const DirDetails & details , int coln ) const
2011-04-03 15:59:12 -04:00
{
/*
* Person : name , id , 0 , 0 ;
* File : name , size , rank , ( 0 ) ts
* Dir : name , ( 0 ) count , ( 0 ) path , ( 0 ) ts
*/
2018-09-27 10:53:08 -04:00
if ( details . type = = DIR_TYPE_FILE | | details . type = = DIR_TYPE_EXTRA_FILE ) /* File */
2011-04-03 15:59:12 -04:00
{
switch ( coln )
{
2018-02-19 14:13:38 -05:00
case COLUMN_NAME : return QString : : fromUtf8 ( details . name . c_str ( ) ) ;
case COLUMN_FILENB : return ( qulonglong ) 0 ;
case COLUMN_SIZE : return ( qulonglong ) details . count ;
case COLUMN_AGE : return details . max_mtime ;
case COLUMN_FRIEND_ACCESS : return QString : : fromUtf8 ( rsPeers - > getPeerName ( details . id ) . c_str ( ) ) ;
case COLUMN_WN_VISU_DIR : {
RS_STACK_MUTEX ( _ref_mutex ) ;
return computeDirectoryPath ( details ) ;
}
2011-04-03 15:59:12 -04:00
}
}
2011-04-07 16:09:32 -04:00
return QVariant ( ) ;
2011-04-01 17:46:06 -04:00
} /* end of SortRole */
QVariant RetroshareDirModel : : data ( const QModelIndex & index , int role ) const
{
# ifdef RDM_DEBUG
2016-11-07 16:24:02 -05:00
std : : cerr < < " RetroshareDirModel::data(): " < < index . internalPointer ( ) < < std : : endl ;
2011-04-01 17:46:06 -04:00
# endif
if ( ! index . isValid ( ) )
return QVariant ( ) ;
2016-11-17 15:01:01 -05:00
// First we take care of the cases that do not require requestDirDetails()
int coln = index . column ( ) ;
if ( role = = Qt : : SizeHintRole )
return QVariant ( ) ;
if ( role = = Qt : : TextAlignmentRole )
{
2018-02-19 14:13:38 -05:00
if ( ( coln = = COLUMN_FILENB ) | | ( coln = = COLUMN_SIZE ) )
2016-11-17 15:01:01 -05:00
return int ( Qt : : AlignRight | Qt : : AlignVCenter ) ;
2018-02-19 14:13:38 -05:00
else
2016-11-17 15:01:01 -05:00
return QVariant ( ) ;
}
// This makes sorting a bit arbitrary, but prevents calling requestDirDetails(). The number of calls to sortRole is
// indeed sometimes very high and somewhat kills the GUI responsivness.
//
//if (role == SortRole)
// return QVariant(index.row()) ;
2011-04-01 17:46:06 -04:00
/* get the data from the index */
void * ref = index . internalPointer ( ) ;
2016-10-22 17:48:19 -04:00
DirDetails details ;
2011-04-01 17:46:06 -04:00
2016-10-22 17:48:19 -04:00
if ( ! requestDirDetails ( ref , RemoteMode , details ) )
return QVariant ( ) ;
2011-04-01 17:46:06 -04:00
if ( role = = RetroshareDirModel : : FileNameRole ) /* end of FileNameRole */
2016-10-22 17:48:19 -04:00
return QString : : fromUtf8 ( details . name . c_str ( ) ) ;
2011-04-01 17:46:06 -04:00
if ( role = = Qt : : TextColorRole )
{
2018-09-27 10:53:08 -04:00
if ( ( details . type = = DIR_TYPE_FILE | | details . type = = DIR_TYPE_EXTRA_FILE ) & & details . hash . isNull ( ) )
2016-09-18 16:32:30 -04:00
return QVariant ( QColor ( Qt : : green ) ) ;
2016-11-14 15:58:58 -05:00
else if ( ageIndicator ! = IND_ALWAYS & & details . max_mtime + ageIndicator < time ( NULL ) )
2013-10-19 16:59:55 -04:00
return QVariant ( QColor ( Qt : : gray ) ) ;
2016-01-09 06:01:32 -05:00
else if ( RemoteMode )
{
FileInfo info ;
QVariant local_file_color = QVariant ( QColor ( Qt : : red ) ) ;
2016-08-19 12:49:42 -04:00
if ( rsFiles - > alreadyHaveFile ( details . hash , info ) )
2016-01-09 06:01:32 -05:00
return local_file_color ;
std : : list < RsFileHash > downloads ;
rsFiles - > FileDownloads ( downloads ) ;
2016-08-19 12:49:42 -04:00
if ( std : : find ( downloads . begin ( ) , downloads . end ( ) , details . hash ) ! = downloads . end ( ) )
2016-01-09 06:01:32 -05:00
return local_file_color ;
else
return QVariant ( ) ;
}
2011-04-01 17:46:06 -04:00
else
2012-11-19 11:01:21 -05:00
return QVariant ( ) ; // standard
2011-04-01 17:46:06 -04:00
} /* end of TextColorRole */
2009-07-07 14:56:31 -04:00
2011-04-01 17:46:06 -04:00
if ( role = = Qt : : DecorationRole )
2016-08-19 12:49:42 -04:00
return decorationRole ( details , coln ) ;
2011-04-01 17:46:06 -04:00
2016-09-28 15:55:03 -04:00
if ( role = = Qt : : ToolTipRole )
2018-09-27 16:14:00 -04:00
if ( ! isNewerThanEpoque ( details . max_mtime ) & & details . type = = DIR_TYPE_PERSON )
2016-09-28 15:55:03 -04:00
return tr ( " This node hasn't sent any directory information yet. " ) ;
/*****************
2011-04-01 17:46:06 -04:00
Qt : : EditRole
Qt : : ToolTipRole
Qt : : StatusTipRole
Qt : : WhatsThisRole
Qt : : SizeHintRole
* * * * * * * * * * * * * * * */
if ( role = = Qt : : DisplayRole )
2016-08-19 12:49:42 -04:00
return displayRole ( details , coln ) ;
2011-04-01 17:46:06 -04:00
if ( role = = SortRole )
2016-08-19 12:49:42 -04:00
return sortRole ( index , details , coln ) ;
2011-04-01 17:46:06 -04:00
2018-04-22 11:15:40 -04:00
if ( role = = FilterRole )
return filterRole ( details , coln ) ;
2011-04-01 17:46:06 -04:00
return QVariant ( ) ;
2010-06-12 14:10:39 -04:00
}
2007-11-14 22:18:48 -05:00
2018-04-22 11:15:40 -04:00
2018-02-24 08:07:32 -05:00
/****
2014-01-04 17:39:34 -05:00
//void RetroshareDirModel::getAgeIndicatorRec(const DirDetails &details, QString &ret) const {
// if (details.type == DIR_TYPE_FILE) {
// ret = getAgeIndicatorString(details);
// return;
// } else if (details.type == DIR_TYPE_DIR && ret.isEmpty()) {
// std::list<DirStub>::const_iterator it;
2014-10-21 18:33:02 -04:00
// for (it = details.children.begin(); it != details.children.end(); ++it) {
2014-01-04 17:39:34 -05:00
// void *ref = it->ref;
// const DirDetails *childDetails = requestDirDetails(ref, RemoteMode);
// if (childDetails && ret == tr(""))
// getAgeIndicatorRec(*childDetails, ret);
// }
// }
//}
2018-02-24 08:07:32 -05:00
* * * */
2008-11-18 17:59:33 -05:00
2011-04-01 17:46:06 -04:00
QVariant TreeStyle_RDM : : headerData ( int section , Qt : : Orientation orientation , int role ) const
{
2015-11-18 15:24:38 -05:00
/*if (role == Qt::SizeHintRole)
2011-04-01 17:46:06 -04:00
{
2015-06-29 12:08:17 -04:00
int defw = QFontMetricsF ( QWidget ( ) . font ( ) ) . width ( headerData ( section , Qt : : Horizontal , Qt : : DisplayRole ) . toString ( ) ) ;
int defh = QFontMetricsF ( QWidget ( ) . font ( ) ) . height ( ) ;
2018-02-19 14:13:38 -05:00
if ( section < COLUMN_AGE )
2011-04-01 17:46:06 -04:00
{
2015-06-29 12:08:17 -04:00
defw = 200 / 16.0 * defh ;
2011-04-01 17:46:06 -04:00
}
return QSize ( defw , defh ) ;
2015-11-18 15:24:38 -05:00
} */
2011-04-01 17:46:06 -04:00
if ( role ! = Qt : : DisplayRole )
return QVariant ( ) ;
if ( orientation = = Qt : : Horizontal )
{
switch ( section )
{
2018-02-19 14:13:38 -05:00
case COLUMN_NAME :
2011-04-01 17:46:06 -04:00
if ( RemoteMode )
2016-11-26 13:19:15 -05:00
if ( mUpdating )
return tr ( " Friends Directories [updating...] " ) ;
else
return tr ( " Friends Directories " ) ;
2011-04-01 17:46:06 -04:00
else
2018-02-19 14:13:38 -05:00
if ( mUpdating )
2016-11-26 13:19:15 -05:00
return tr ( " My Directories [updating...] " ) ;
else
return tr ( " My Directories " ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_FILENB :
return tr ( " # Files " ) ;
case COLUMN_SIZE :
2011-04-01 17:46:06 -04:00
return tr ( " Size " ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_AGE :
2011-04-01 17:46:06 -04:00
return tr ( " Age " ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_FRIEND_ACCESS :
2011-04-01 17:46:06 -04:00
if ( RemoteMode )
return tr ( " Friend " ) ;
else
2018-02-19 14:13:38 -05:00
return tr ( " Access " ) ;
case COLUMN_WN_VISU_DIR :
2012-10-21 15:39:56 -04:00
if ( RemoteMode )
return tr ( " What's new " ) ;
else
2018-02-19 14:13:38 -05:00
return tr ( " Visibility " ) ;
2011-04-01 17:46:06 -04:00
}
2018-02-19 14:13:38 -05:00
return tr ( " Column %1 " ) . arg ( section ) ;
2011-04-01 17:46:06 -04:00
}
else
2018-02-19 14:13:38 -05:00
return tr ( " Row %1 " ) . arg ( section ) ;
2011-04-01 17:46:06 -04:00
}
QVariant FlatStyle_RDM : : headerData ( int section , Qt : : Orientation orientation , int role ) const
2009-08-10 14:55:49 -04:00
{
2015-11-18 15:24:38 -05:00
/*if (role == Qt::SizeHintRole)
2009-08-10 14:55:49 -04:00
{
2015-06-29 12:08:17 -04:00
int defw = QFontMetricsF ( QWidget ( ) . font ( ) ) . width ( headerData ( section , Qt : : Horizontal , Qt : : DisplayRole ) . toString ( ) ) ;
int defh = QFontMetricsF ( QWidget ( ) . font ( ) ) . height ( ) ;
2018-02-19 14:13:38 -05:00
if ( section < COLUMN_AGE )
2009-08-10 14:55:49 -04:00
{
2015-06-29 12:08:17 -04:00
defw = defh * 200 / 16.0 ;
2009-08-10 14:55:49 -04:00
}
return QSize ( defw , defh ) ;
2015-11-18 15:24:38 -05:00
} */
2007-11-14 22:18:48 -05:00
2009-08-10 14:55:49 -04:00
if ( role ! = Qt : : DisplayRole )
return QVariant ( ) ;
2007-11-14 22:18:48 -05:00
2009-08-10 14:55:49 -04:00
if ( orientation = = Qt : : Horizontal )
2007-11-14 22:18:48 -05:00
{
2009-08-10 14:55:49 -04:00
switch ( section )
{
2018-02-19 14:13:38 -05:00
case COLUMN_NAME :
2009-08-10 14:55:49 -04:00
if ( RemoteMode )
{
2010-10-28 13:26:00 -04:00
return tr ( " Friends Directories " ) ;
2009-08-10 14:55:49 -04:00
}
2010-10-28 13:26:00 -04:00
return tr ( " My Directories " ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_FILENB :
return tr ( " # Files " ) ;
case COLUMN_SIZE :
2010-10-28 13:26:00 -04:00
return tr ( " Size " ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_AGE :
2010-10-28 13:26:00 -04:00
return tr ( " Age " ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_FRIEND_ACCESS :
2011-04-01 17:46:06 -04:00
if ( RemoteMode )
return tr ( " Friend " ) ;
else
2013-02-22 16:42:27 -05:00
return tr ( " Share Flags " ) ;
2018-02-19 14:13:38 -05:00
case COLUMN_WN_VISU_DIR :
2011-04-07 16:09:32 -04:00
return tr ( " Directory " ) ;
2009-08-10 14:55:49 -04:00
}
2018-02-19 14:13:38 -05:00
return tr ( " Column %1 " ) . arg ( section ) ;
2007-11-14 22:18:48 -05:00
}
2009-08-10 14:55:49 -04:00
else
2018-02-19 14:13:38 -05:00
return tr ( " Row %1 " ) . arg ( section ) ;
2009-08-10 14:55:49 -04:00
}
2007-11-14 22:18:48 -05:00
2011-04-01 17:46:06 -04:00
QModelIndex TreeStyle_RDM : : index ( int row , int column , const QModelIndex & parent ) const
2010-01-30 15:47:34 -05:00
{
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::index(): " < < parent . internalPointer ( ) ;
2007-11-14 22:18:48 -05:00
std : : cerr < < " : row: " < < row < < " col: " < < column < < " " ;
# endif
2018-02-24 08:07:32 -05:00
// This function is used extensively. There's no way we can use requestDirDetails() in it, which would
// cause far too much overhead. So we use a dedicated function that only grabs the required information.
2016-09-15 04:41:40 -04:00
2010-01-30 15:47:34 -05:00
if ( row < 0 )
return QModelIndex ( ) ;
2009-07-07 14:56:31 -04:00
2010-01-30 15:47:34 -05:00
void * ref = ( parent . isValid ( ) ) ? parent . internalPointer ( ) : NULL ;
2007-11-14 22:18:48 -05:00
/********
2010-01-30 15:47:34 -05:00
if ( ! RemoteMode )
{
remote = & ( rsiface - > getLocalDirectoryList ( ) ) ;
}
* * * * * * * */
2018-02-24 08:07:32 -05:00
//If on root and don't show empty child, get real parent row
if ( ( ! ref ) & & ( ! _showEmpty ) & & RemoteMode & & ( ( size_t ) row > = _parentRow . size ( ) ) )
return QModelIndex ( ) ;
int parentRow = ( ( ! ref ) & & ( ! _showEmpty ) & & RemoteMode ) ? _parentRow [ row ] : row ;
2007-11-14 22:18:48 -05:00
2018-02-24 08:07:32 -05:00
void * result ;
2016-08-19 12:49:42 -04:00
2018-02-24 08:07:32 -05:00
if ( rsFiles - > findChildPointer ( ref , parentRow , result , ( ( RemoteMode ) ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL ) ) )
return createIndex ( row , column , result ) ;
else
2010-01-30 15:47:34 -05:00
return QModelIndex ( ) ;
}
2011-04-01 17:46:06 -04:00
QModelIndex FlatStyle_RDM : : index ( int row , int column , const QModelIndex & parent ) const
{
2011-08-12 10:06:29 -04:00
Q_UNUSED ( parent ) ;
2011-04-01 17:46:06 -04:00
# ifdef RDM_DEBUG
std : : cerr < < " RetroshareDirModel::index(): " < < parent . internalPointer ( ) ;
std : : cerr < < " : row: " < < row < < " col: " < < column < < " " ;
# endif
2007-11-14 22:18:48 -05:00
2011-04-01 17:46:06 -04:00
if ( row < 0 )
return QModelIndex ( ) ;
2016-09-13 15:23:27 -04:00
RS_STACK_MUTEX ( _ref_mutex ) ;
if ( row < ( int ) _ref_entries . size ( ) )
2011-04-01 17:46:06 -04:00
{
2016-09-13 15:23:27 -04:00
void * ref = _ref_entries [ row ] ;
2010-01-30 15:47:34 -05:00
2016-08-28 17:14:39 -04:00
# ifdef RDM_DEBUG
std : : cerr < < " Creating index 2 row= " < < row < < " , column= " < < column < < " , ref= " < < ( void * ) ref < < std : : endl ;
# endif
return createIndex ( row , column , ref ) ;
2011-04-01 17:46:06 -04:00
}
else
return QModelIndex ( ) ;
}
QModelIndex TreeStyle_RDM : : parent ( const QModelIndex & index ) const
2010-01-30 15:47:34 -05:00
{
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::parent(): " < < index . internalPointer ( ) ;
2007-11-14 22:18:48 -05:00
std : : cerr < < " : " ;
# endif
/* create the index */
2010-01-30 15:47:34 -05:00
if ( ! index . isValid ( ) )
2007-11-14 22:18:48 -05:00
{
# ifdef RDM_DEBUG
2010-01-30 15:47:34 -05:00
std : : cerr < < " Invalid Index -> invalid " ;
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
/* Parent is invalid too */
return QModelIndex ( ) ;
}
void * ref = index . internalPointer ( ) ;
2018-02-24 08:07:32 -05:00
DirDetails details ;
2007-11-14 22:18:48 -05:00
2018-02-24 08:07:32 -05:00
if ( ! requestDirDetails ( ref , RemoteMode , details ) )
{
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2010-01-30 15:47:34 -05:00
std : : cerr < < " Failed Lookup -> invalid " ;
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
2010-01-30 15:47:34 -05:00
return QModelIndex ( ) ;
}
2007-11-14 22:18:48 -05:00
2018-02-24 08:07:32 -05:00
if ( ! ( details . parent ) )
2007-11-14 22:18:48 -05:00
{
# ifdef RDM_DEBUG
2010-01-30 15:47:34 -05:00
std : : cerr < < " success. parent is Root/NULL --> invalid " ;
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
2010-01-30 15:47:34 -05:00
return QModelIndex ( ) ;
2007-11-14 22:18:48 -05:00
}
# ifdef RDM_DEBUG
2018-04-22 11:15:40 -04:00
std : : cerr < < " success index( " < < details . prow < < " ,0, " < < details . parent < < " ) " ;
2010-01-30 15:47:34 -05:00
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
2018-02-24 08:07:32 -05:00
std : : cerr < < " Creating index 3 row= " < < details . prow < < " , column= " < < 0 < < " , ref= " < < ( void * ) details . parent < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
2018-02-24 08:07:32 -05:00
return createIndex ( details . prow , COLUMN_NAME , details . parent ) ;
2010-01-30 15:47:34 -05:00
}
2011-04-01 17:46:06 -04:00
QModelIndex FlatStyle_RDM : : parent ( const QModelIndex & index ) const
{
2011-08-12 10:06:29 -04:00
Q_UNUSED ( index ) ;
2011-04-01 17:46:06 -04:00
# ifdef RDM_DEBUG
std : : cerr < < " RetroshareDirModel::parent(): " < < index . internalPointer ( ) ;
std : : cerr < < " : " ;
# endif
2007-11-14 22:18:48 -05:00
2011-04-01 17:46:06 -04:00
return QModelIndex ( ) ;
}
Qt : : ItemFlags RetroshareDirModel : : flags ( const QModelIndex & index ) const
2010-01-30 15:47:34 -05:00
{
2007-11-14 22:18:48 -05:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::flags() " ;
2010-01-30 15:47:34 -05:00
std : : cerr < < std : : endl ;
2007-11-14 22:18:48 -05:00
# endif
2010-01-30 15:47:34 -05:00
if ( ! index . isValid ( ) )
2007-11-14 22:18:48 -05:00
return ( Qt : : ItemIsSelectable ) ; // Error.
void * ref = index . internalPointer ( ) ;
2018-02-19 14:13:38 -05:00
DirDetails details ;
2007-11-14 22:18:48 -05:00
2018-02-19 14:13:38 -05:00
if ( ! requestDirDetails ( ref , RemoteMode , details ) )
return Qt : : ItemIsSelectable ; // Error.
2007-11-14 22:18:48 -05:00
2018-02-19 14:13:38 -05:00
switch ( details . type )
2007-11-14 22:18:48 -05:00
{
2018-02-19 14:13:38 -05:00
// we grey out a person that has never been updated. It's easy to spot these, since the min age of the directory is approx equal to time(NULL), which exceeds 40 years.
case DIR_TYPE_PERSON : return isNewerThanEpoque ( details . max_mtime ) ? ( Qt : : ItemIsEnabled ) : ( Qt : : NoItemFlags ) ;
case DIR_TYPE_DIR : return Qt : : ItemIsSelectable | Qt : : ItemIsEnabled ;
case DIR_TYPE_FILE : return Qt : : ItemIsSelectable | Qt : : ItemIsDragEnabled | Qt : : ItemIsEnabled ;
2018-09-27 10:53:08 -04:00
case DIR_TYPE_EXTRA_FILE : return Qt : : ItemIsSelectable | Qt : : ItemIsDragEnabled | Qt : : ItemIsEnabled ;
2007-11-14 22:18:48 -05:00
}
2010-10-28 13:26:00 -04:00
return Qt : : ItemIsSelectable ;
2007-11-14 22:18:48 -05:00
}
// The other flags...
//Qt::ItemIsUserCheckable
//Qt::ItemIsEditable
//Qt::ItemIsDropEnabled
//Qt::ItemIsTristate
2018-02-24 08:07:32 -05:00
/* Callback from Core*/
2014-01-05 17:51:54 -05:00
void RetroshareDirModel : : preMods ( )
{
2016-08-27 07:22:29 -04:00
emit layoutAboutToBeChanged ( ) ;
2016-11-26 13:19:15 -05:00
mUpdating = true ;
2014-01-11 13:34:38 -05:00
# if QT_VERSION < 0x050000
2014-01-05 17:51:54 -05:00
reset ( ) ;
2014-01-11 13:34:38 -05:00
# else
beginResetModel ( ) ;
endResetModel ( ) ;
# endif
2014-01-05 17:51:54 -05:00
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::preMods() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2014-01-05 17:51:54 -05:00
}
2018-02-24 08:07:32 -05:00
/* Callback from Core*/
2014-01-05 17:51:54 -05:00
void RetroshareDirModel : : postMods ( )
{
2016-08-27 07:22:29 -04:00
// emit layoutAboutToBeChanged();
2016-11-26 13:19:15 -05:00
mUpdating = false ;
2010-11-23 16:00:17 -05:00
# if QT_VERSION >= 0x040600
2010-11-13 13:02:08 -05:00
beginResetModel ( ) ;
2010-11-23 16:00:17 -05:00
# endif
2014-01-05 17:51:54 -05:00
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::postMods() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2014-01-05 17:51:54 -05:00
2010-11-23 16:00:17 -05:00
# if QT_VERSION >= 0x040600
2010-11-13 13:02:08 -05:00
endResetModel ( ) ;
2010-11-23 16:00:17 -05:00
# endif
2014-01-05 17:51:54 -05:00
emit layoutChanged ( ) ;
}
2007-11-14 22:18:48 -05:00
2018-02-24 08:07:32 -05:00
void FlatStyle_RDM : : postMods ( )
{
time_t now = time ( NULL ) ;
if ( _last_update + FLAT_VIEW_MIN_DELAY_BETWEEN_UPDATES > now )
return ;
if ( visible ( ) )
{
emit layoutAboutToBeChanged ( ) ;
{
RS_STACK_MUTEX ( _ref_mutex ) ;
_ref_stack . clear ( ) ;
_ref_stack . push_back ( NULL ) ; // init the stack with the topmost parent directory
_ref_entries . clear ( ) ;
_last_update = now ;
}
QTimer : : singleShot ( 100 , this , SLOT ( updateRefs ( ) ) ) ;
}
else
_needs_update = true ;
}
2016-08-19 12:49:42 -04:00
bool RetroshareDirModel : : requestDirDetails ( void * ref , bool remote , DirDetails & d ) const
2011-04-03 15:59:12 -04:00
{
2018-09-27 10:53:08 -04:00
# ifdef RDM_DEBUG
2016-11-07 16:24:02 -05:00
std : : cerr < < " RequestDirDetails:: ref = " < < ref < < " , remote= " < < remote < < std : : endl ;
2018-09-27 10:53:08 -04:00
# endif
2016-11-07 16:24:02 -05:00
// We look in cache and re-use the last result if the reference and remote are the same.
time_t now = time ( NULL ) ;
2016-11-08 13:56:07 -05:00
if ( mDirDetails . ref = = ref & & mLastRemote = = remote & & now < 2 + mLastReq )
2016-11-07 16:24:02 -05:00
{
2016-11-08 13:56:07 -05:00
d = mDirDetails ;
2016-11-07 16:24:02 -05:00
return true ;
}
2016-08-19 12:49:42 -04:00
FileSearchFlags flags = ( remote ) ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL ;
2014-01-04 17:39:34 -05:00
2016-11-07 16:24:02 -05:00
if ( rsFiles - > RequestDirDetails ( ref , d , flags ) )
{
mLastReq = now ;
mLastRemote = remote ;
2016-11-08 13:56:07 -05:00
mDirDetails = d ;
2016-11-07 16:24:02 -05:00
return true ;
}
return false ;
2011-04-03 15:59:12 -04:00
}
2007-11-14 22:18:48 -05:00
2012-08-31 10:07:15 -04:00
void RetroshareDirModel : : createCollectionFile ( QWidget * parent , const QModelIndexList & list )
2011-11-07 18:07:25 -05:00
{
2014-05-29 10:49:45 -04:00
/* if(RemoteMode)
2011-11-07 18:07:25 -05:00
{
std : : cerr < < " Cannot create a collection file from remote " < < std : : endl ;
return ;
2014-05-29 10:49:45 -04:00
} */
2011-11-07 18:07:25 -05:00
std : : vector < DirDetails > dirVec ;
getDirDetailsFromSelect ( list , dirVec ) ;
2017-11-12 16:46:29 -05:00
FileSearchFlags f = RemoteMode ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL ;
2017-11-14 11:52:48 -05:00
QString dir_name ;
if ( ! RemoteMode )
{
2018-02-19 14:13:38 -05:00
if ( ! dirVec . empty ( ) )
2017-11-14 11:52:48 -05:00
{
const DirDetails & details = dirVec [ 0 ] ;
dir_name = QDir ( QString : : fromUtf8 ( details . name . c_str ( ) ) ) . dirName ( ) ;
}
}
RsCollection ( dirVec , f ) . openNewColl ( parent , dir_name ) ;
2011-11-07 18:07:25 -05:00
}
2017-11-12 16:46:29 -05:00
void RetroshareDirModel : : downloadSelected ( const QModelIndexList & list , bool interactive )
2007-11-14 22:18:48 -05:00
{
if ( ! RemoteMode )
{
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " Cannot download from local " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2011-11-07 18:07:25 -05:00
return ;
2007-11-14 22:18:48 -05:00
}
2009-07-07 14:56:31 -04:00
/* so for all the selected .... get the name out,
2007-11-14 22:18:48 -05:00
* make it into something the RsControl can understand
*/
2009-05-18 10:23:55 -04:00
std : : vector < DirDetails > dirVec ;
getDirDetailsFromSelect ( list , dirVec ) ;
2017-11-12 16:46:29 -05:00
FileSearchFlags f = RemoteMode ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL ;
if ( interactive )
RsCollection ( dirVec , f ) . downloadFiles ( ) ;
else /* Fire off requests */
for ( int i = 0 , n = dirVec . size ( ) ; i < n ; + + i )
{
if ( ! RemoteMode )
{
continue ; /* don't try to download local stuff */
}
const DirDetails & details = dirVec [ i ] ;
/* if it is a file */
if ( details . type = = DIR_TYPE_FILE )
{
std : : cerr < < " RetroshareDirModel::downloadSelected() Calling File Request " ;
std : : cerr < < std : : endl ;
std : : list < RsPeerId > srcIds ;
srcIds . push_back ( details . id ) ;
rsFiles - > FileRequest ( details . name , details . hash ,
details . count , " " , RS_FILE_REQ_ANONYMOUS_ROUTING , srcIds ) ;
}
/* if it is a dir, copy all files included*/
else if ( details . type = = DIR_TYPE_DIR )
{
int prefixLen = details . path . rfind ( details . name ) ;
if ( prefixLen < 0 ) continue ;
downloadDirectory ( details , prefixLen ) ;
}
}
2009-05-18 10:23:55 -04:00
}
2007-11-14 22:18:48 -05:00
2009-07-17 16:07:43 -04:00
/* recursively download a directory */
2011-04-01 17:46:06 -04:00
void RetroshareDirModel : : downloadDirectory ( const DirDetails & dirDetails , int prefixLen )
2009-07-17 16:07:43 -04:00
{
if ( dirDetails . type & DIR_TYPE_FILE )
{
2014-05-29 10:49:45 -04:00
std : : list < RsPeerId > srcIds ;
2010-09-17 14:27:30 -04:00
QString cleanPath = QDir : : cleanPath ( QString : : fromUtf8 ( rsFiles - > getDownloadDirectory ( ) . c_str ( ) ) + " / " + QString : : fromUtf8 ( dirDetails . path . substr ( prefixLen ) . c_str ( ) ) ) ;
2009-07-17 16:07:43 -04:00
srcIds . push_back ( dirDetails . id ) ;
2012-11-02 09:52:29 -04:00
rsFiles - > FileRequest ( dirDetails . name , dirDetails . hash , dirDetails . count , cleanPath . toUtf8 ( ) . constData ( ) , RS_FILE_REQ_ANONYMOUS_ROUTING , srcIds ) ;
2009-07-17 16:07:43 -04:00
}
else if ( dirDetails . type & DIR_TYPE_DIR )
{
std : : list < DirStub > : : const_iterator it ;
2011-08-27 17:04:02 -04:00
QDir dwlDir ( QString : : fromUtf8 ( rsFiles - > getDownloadDirectory ( ) . c_str ( ) ) ) ;
2010-09-17 14:27:30 -04:00
QString cleanPath = QDir : : cleanPath ( QString : : fromUtf8 ( dirDetails . path . substr ( prefixLen ) . c_str ( ) ) ) ;
2009-07-17 16:07:43 -04:00
if ( ! dwlDir . mkpath ( cleanPath ) ) return ;
2016-08-19 12:49:42 -04:00
for ( uint32_t i = 0 ; i < dirDetails . children . size ( ) ; + + i )
2009-07-17 16:07:43 -04:00
{
2016-08-19 12:49:42 -04:00
if ( ! dirDetails . children [ i ] . ref ) continue ;
2009-07-17 16:07:43 -04:00
2016-08-19 12:49:42 -04:00
DirDetails subDirDetails ;
2009-07-17 16:07:43 -04:00
2016-08-19 12:49:42 -04:00
if ( ! requestDirDetails ( dirDetails . children [ i ] . ref , true , subDirDetails ) )
continue ;
2009-07-17 16:07:43 -04:00
2016-08-19 12:49:42 -04:00
downloadDirectory ( subDirDetails , prefixLen ) ;
2009-07-17 16:07:43 -04:00
}
}
}
2011-04-01 17:46:06 -04:00
void RetroshareDirModel : : getDirDetailsFromSelect ( const QModelIndexList & list , std : : vector < DirDetails > & dirVec )
2009-05-18 10:23:55 -04:00
{
2018-02-19 14:13:38 -05:00
dirVec . clear ( ) ;
2009-02-02 15:46:30 -05:00
2018-02-19 14:13:38 -05:00
/* Fire off requests */
QModelIndexList : : const_iterator it ;
for ( it = list . begin ( ) ; it ! = list . end ( ) ; + + it )
{
if ( it - > column ( ) = = COLUMN_FILENB )
{
void * ref = it - > internalPointer ( ) ;
2009-05-18 10:23:55 -04:00
2018-02-19 14:13:38 -05:00
DirDetails details ;
2009-05-18 10:23:55 -04:00
2018-02-19 14:13:38 -05:00
if ( ! requestDirDetails ( ref , RemoteMode , details ) )
continue ;
2009-05-18 10:23:55 -04:00
2018-02-19 14:13:38 -05:00
dirVec . push_back ( details ) ;
}
}
2007-11-14 22:18:48 -05:00
}
2008-07-02 12:59:56 -04:00
/****************************************************************************
* OLD RECOMMEND SYSTEM - DISABLED
*
*/
2011-04-01 17:46:06 -04:00
void RetroshareDirModel : : getFileInfoFromIndexList ( const QModelIndexList & list , std : : list < DirDetails > & file_details )
2007-11-14 22:18:48 -05:00
{
2009-05-17 15:38:42 -04:00
file_details . clear ( ) ;
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " recommendSelected() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
if ( RemoteMode )
{
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " Cannot recommend remote! (should download) " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
}
/* Fire off requests */
2009-07-07 14:56:31 -04:00
2009-05-17 15:38:42 -04:00
std : : set < std : : string > already_in ;
for ( QModelIndexList : : const_iterator it ( list . begin ( ) ) ; it ! = list . end ( ) ; + + it )
2018-02-19 14:13:38 -05:00
if ( it - > column ( ) = = COLUMN_NAME )
2007-11-14 22:18:48 -05:00
{
2010-01-31 09:21:24 -05:00
void * ref = it - > internalPointer ( ) ;
2007-11-14 22:18:48 -05:00
2016-08-19 12:49:42 -04:00
DirDetails details ;
2010-01-31 09:21:24 -05:00
2016-08-19 12:49:42 -04:00
if ( ! requestDirDetails ( ref , RemoteMode , details ) )
2010-01-31 09:21:24 -05:00
continue ;
2016-08-19 12:49:42 -04:00
if ( details . type = = DIR_TYPE_PERSON )
2010-01-31 09:21:24 -05:00
continue ;
2007-11-14 22:18:48 -05:00
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2010-01-31 09:21:24 -05:00
std : : cerr < < " ::::::::::::FileRecommend:::: " < < std : : endl ;
2018-04-22 11:15:40 -04:00
std : : cerr < < " Name: " < < details . name < < std : : endl ;
std : : cerr < < " Hash: " < < details . hash < < std : : endl ;
std : : cerr < < " Size: " < < details . count < < std : : endl ;
std : : cerr < < " Path: " < < details . path < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2010-02-03 15:59:54 -05:00
// Note: for directories, the returned hash, is the peer id, so if we collect
// dirs, we need to be a bit more conservative for the
2007-11-14 22:18:48 -05:00
2016-08-19 12:49:42 -04:00
if ( already_in . find ( details . hash . toStdString ( ) + details . name ) = = already_in . end ( ) )
2010-01-31 09:21:24 -05:00
{
2016-08-19 12:49:42 -04:00
file_details . push_back ( details ) ;
already_in . insert ( details . hash . toStdString ( ) + details . name ) ;
2010-01-31 09:21:24 -05:00
}
2009-05-17 15:38:42 -04:00
}
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2007-11-14 22:18:48 -05:00
std : : cerr < < " ::::::::::::Done FileRecommend " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2007-11-14 22:18:48 -05:00
}
2008-07-02 12:59:56 -04:00
/****************************************************************************
* OLD RECOMMEND SYSTEM - DISABLED
* * * * * */
2011-04-01 17:46:06 -04:00
void RetroshareDirModel : : openSelected ( const QModelIndexList & qmil )
2007-11-14 22:18:48 -05:00
{
2009-07-07 14:56:31 -04:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::openSelected() " < < std : : endl ;
2009-07-07 14:56:31 -04:00
# endif
if ( RemoteMode ) {
# ifdef RDM_DEBUG
std : : cerr < < " Cannot open remote. Download first. " < < std : : endl ;
# endif
return ;
}
2007-11-14 22:18:48 -05:00
2009-07-07 14:56:31 -04:00
std : : list < DirDetails > files_info ;
std : : list < DirDetails > : : iterator it ;
getFileInfoFromIndexList ( qmil , files_info ) ;
2014-10-21 18:33:02 -04:00
for ( it = files_info . begin ( ) ; it ! = files_info . end ( ) ; + + it )
2010-03-28 16:46:45 -04:00
{
2009-07-07 14:56:31 -04:00
if ( ( * it ) . type & DIR_TYPE_PERSON ) continue ;
2018-02-19 14:13:38 -05:00
QDir dir ( QString : : fromUtf8 ( ( * it ) . path . c_str ( ) ) ) ;
2010-11-20 09:50:14 -05:00
QString dest ;
2018-09-27 10:53:08 -04:00
if ( ( * it ) . type & DIR_TYPE_FILE | | ( * it ) . type & DIR_TYPE_EXTRA_FILE ) {
2010-11-20 09:50:14 -05:00
dest = dir . absoluteFilePath ( QString : : fromUtf8 ( it - > name . c_str ( ) ) ) ;
2009-07-07 14:56:31 -04:00
} else if ( ( * it ) . type & DIR_TYPE_DIR ) {
2010-11-20 09:50:14 -05:00
dest = dir . absolutePath ( ) ;
2009-07-07 14:56:31 -04:00
}
2010-11-20 09:50:14 -05:00
std : : cerr < < " Opening this file: " < < dest . toStdString ( ) < < std : : endl ;
2009-07-07 14:56:31 -04:00
2011-11-07 18:07:25 -05:00
RsUrlHandler : : openUrl ( QUrl : : fromLocalFile ( dest ) ) ;
2009-07-07 14:56:31 -04:00
}
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " ::::::::::::Done RetroshareDirModel::openSelected() " < < std : : endl ;
2009-07-07 14:56:31 -04:00
# endif
}
2008-03-31 14:37:50 -04:00
2016-08-28 17:14:39 -04:00
void RetroshareDirModel : : getFilePath ( const QModelIndex & index , std : : string & fullpath )
{
2018-02-19 14:13:38 -05:00
void * ref = index . sibling ( index . row ( ) , COLUMN_FILENB ) . internalPointer ( ) ;
2016-08-28 17:14:39 -04:00
DirDetails details ;
if ( ! requestDirDetails ( ref , false , details ) )
{
# ifdef RDM_DEBUG
std : : cerr < < " getFilePaths() Bad Request " < < std : : endl ;
# endif
return ;
}
fullpath = details . path + " / " + details . name ;
}
2011-04-01 17:46:06 -04:00
void RetroshareDirModel : : getFilePaths ( const QModelIndexList & list , std : : list < std : : string > & fullpaths )
2008-03-31 14:37:50 -04:00
{
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::getFilePaths() " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2016-10-22 17:48:19 -04:00
# warning mr-alice: make sure we atually output something here
2008-03-31 14:37:50 -04:00
if ( RemoteMode )
{
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2008-03-31 14:37:50 -04:00
std : : cerr < < " No File Paths for remote files " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2008-03-31 14:37:50 -04:00
return ;
}
/* translate */
2016-08-28 17:14:39 -04:00
for ( QModelIndexList : : const_iterator it = list . begin ( ) ; it ! = list . end ( ) ; + + it )
2008-03-31 14:37:50 -04:00
{
2016-08-28 17:14:39 -04:00
std : : string path ;
2008-03-31 14:37:50 -04:00
2016-08-28 17:14:39 -04:00
getFilePath ( * it , path ) ;
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2016-08-28 17:14:39 -04:00
std : : cerr < < " Constructed FilePath: " < < path < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2016-10-22 17:48:19 -04:00
# warning mr-alice: TERRIBLE COST here. Use a std::set!
2016-08-28 17:14:39 -04:00
if ( fullpaths . end ( ) = = std : : find ( fullpaths . begin ( ) , fullpaths . end ( ) , path ) )
fullpaths . push_back ( path ) ;
}
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2008-03-31 14:37:50 -04:00
std : : cerr < < " ::::::::::::Done getFilePaths " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2008-03-31 14:37:50 -04:00
}
2018-04-22 11:15:40 -04:00
void RetroshareDirModel : : filterItems ( const std : : list < std : : string > & keywords , uint32_t & found )
{
FileSearchFlags flags = RemoteMode ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL ;
std : : list < DirDetails > result_list ;
found = 0 ;
if ( keywords . empty ( ) )
{
mFilteredPointers . clear ( ) ;
return ;
}
else if ( keywords . size ( ) > 1 )
{
RsRegularExpression : : NameExpression exp ( RsRegularExpression : : ContainsAllStrings , keywords , true ) ;
rsFiles - > SearchBoolExp ( & exp , result_list , flags ) ;
}
else
rsFiles - > SearchKeywords ( keywords , result_list , flags ) ;
# ifdef RDM_SEARCH_DEBUG
std : : cerr < < " Found " < < result_list . size ( ) < < " results " < < std : : endl ;
# endif
if ( result_list . empty ( ) ) // in this case we dont clear the list of filtered items, so that we can keep the old filter list
return ;
mFilteredPointers . clear ( ) ;
# ifdef RDM_SEARCH_DEBUG
std : : cerr < < " Found this result: " < < std : : endl ;
# endif
// Then show only the ones we need
for ( auto it ( result_list . begin ( ) ) ; it ! = result_list . end ( ) ; + + it )
{
DirDetails & det ( * it ) ;
# ifdef RDM_SEARCH_DEBUG
std : : cerr < < ( void * ) ( * it ) . ref < < " name= \" " < < det . name < < " \" parents: " ;
# endif
void * p = det . ref ;
mFilteredPointers . insert ( p ) ;
+ + found ;
2018-09-27 10:53:08 -04:00
while ( det . type = = DIR_TYPE_FILE | | det . type = = DIR_TYPE_EXTRA_FILE | | det . type = = DIR_TYPE_DIR )
2018-04-22 11:15:40 -04:00
{
p = det . parent ;
rsFiles - > RequestDirDetails ( p , det , flags ) ;
# ifdef RDM_SEARCH_DEBUG
std : : cerr < < " " < < ( void * ) p < < " ( " < < ( int ) det . type < < " ) " ;
# endif
mFilteredPointers . insert ( p ) ;
}
# ifdef RDM_SEARCH_DEBUG
std : : cerr < < std : : endl ;
# endif
}
2018-04-22 11:57:14 -04:00
# ifdef RDM_SEARCH_DEBUG
2018-04-22 11:15:40 -04:00
std : : cerr < < mFilteredPointers . size ( ) < < " pointers in filter set. " < < std : : endl ;
2018-04-22 11:57:14 -04:00
# endif
2018-04-22 11:15:40 -04:00
}
2008-07-04 10:41:24 -04:00
/* Drag and Drop Functionality */
2011-04-01 17:46:06 -04:00
QMimeData * RetroshareDirModel : : mimeData ( const QModelIndexList & indexes ) const
2008-07-04 10:41:24 -04:00
{
/* extract from each the member text */
2012-03-28 14:02:49 -04:00
QString text ;
2008-07-04 10:41:24 -04:00
QModelIndexList : : const_iterator it ;
2014-03-17 16:56:06 -04:00
std : : map < RsFileHash , uint64_t > drags ;
std : : map < RsFileHash , uint64_t > : : iterator dit ;
2008-07-04 10:41:24 -04:00
2014-10-21 18:33:02 -04:00
for ( it = indexes . begin ( ) ; it ! = indexes . end ( ) ; + + it )
2008-07-04 10:41:24 -04:00
{
void * ref = it - > internalPointer ( ) ;
2016-08-19 12:49:42 -04:00
DirDetails details ;
if ( ! requestDirDetails ( ref , RemoteMode , details ) )
continue ;
2008-07-04 10:41:24 -04:00
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2008-07-04 10:41:24 -04:00
std : : cerr < < " ::::::::::::FileDrag:::: " < < std : : endl ;
2018-04-22 11:15:40 -04:00
std : : cerr < < " Name: " < < details . name < < std : : endl ;
std : : cerr < < " Hash: " < < details . hash < < std : : endl ;
std : : cerr < < " Size: " < < details . count < < std : : endl ;
std : : cerr < < " Path: " < < details . path < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2008-07-04 10:41:24 -04:00
2018-09-27 10:53:08 -04:00
if ( details . type ! = DIR_TYPE_FILE & & details . type ! = DIR_TYPE_EXTRA_FILE )
2008-07-04 10:41:24 -04:00
{
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::mimeData() Not File " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2008-07-04 10:41:24 -04:00
continue ; /* not file! */
}
2016-08-19 12:49:42 -04:00
if ( drags . end ( ) ! = ( dit = drags . find ( details . hash ) ) )
2008-07-04 10:41:24 -04:00
{
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2011-04-01 17:46:06 -04:00
std : : cerr < < " RetroshareDirModel::mimeData() Duplicate " < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2008-07-04 10:41:24 -04:00
continue ; /* duplicate */
}
2016-08-19 12:49:42 -04:00
drags [ details . hash ] = details . count ;
2008-07-04 10:41:24 -04:00
2016-08-19 12:49:42 -04:00
QString line = QString ( " %1/%2/%3/ " ) . arg ( QString : : fromUtf8 ( details . name . c_str ( ) ) , QString : : fromStdString ( details . hash . toStdString ( ) ) , QString : : number ( details . count ) ) ;
2008-07-04 10:41:24 -04:00
if ( RemoteMode )
{
line + = " Remote " ;
}
else
{
line + = " Local " ;
}
line + = " / \n " ;
text + = line ;
}
2008-07-09 05:53:47 -04:00
# ifdef RDM_DEBUG
2008-07-04 10:41:24 -04:00
std : : cerr < < " Created MimeData: " ;
std : : cerr < < std : : endl ;
2014-01-04 17:39:34 -05:00
std : : cerr < < text . toStdString ( ) ;
2008-07-04 10:41:24 -04:00
std : : cerr < < std : : endl ;
2008-07-09 05:53:47 -04:00
# endif
2008-07-04 10:41:24 -04:00
QMimeData * data = new QMimeData ( ) ;
2012-03-30 15:43:39 -04:00
data - > setData ( " application/x-rsfilelist " , text . toUtf8 ( ) ) ;
2008-07-04 10:41:24 -04:00
return data ;
}
2011-04-01 17:46:06 -04:00
QStringList RetroshareDirModel : : mimeTypes ( ) const
2008-07-04 10:41:24 -04:00
{
QStringList list ;
list . push_back ( " application/x-rsfilelist " ) ;
return list ;
}
2009-04-07 04:08:03 -04:00
//============================================================================
2011-04-01 17:46:06 -04:00
int RetroshareDirModel : : getType ( const QModelIndex & index ) const
2009-04-07 04:08:03 -04:00
{
2011-04-03 15:59:12 -04:00
//if (RemoteMode) // only local files can be opened
// return ;
2012-11-02 09:52:29 -04:00
FileSearchFlags flags = ( RemoteMode ) ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL ;
2009-04-07 04:08:03 -04:00
2011-04-03 15:59:12 -04:00
return rsFiles - > getType ( index . internalPointer ( ) , flags ) ;
2009-04-07 04:08:03 -04:00
}
2011-04-01 17:46:06 -04:00
TreeStyle_RDM : : ~ TreeStyle_RDM ( )
{
}
2018-02-24 08:07:32 -05:00
FlatStyle_RDM : : ~ FlatStyle_RDM ( )
2011-04-01 17:46:06 -04:00
{
2011-04-09 15:43:09 -04:00
}
void FlatStyle_RDM : : updateRefs ( )
{
2011-04-14 17:58:15 -04:00
if ( RsAutoUpdatePage : : eventsLocked ( ) )
{
2016-11-20 14:42:14 -05:00
QTimer : : singleShot ( 5000 , this , SLOT ( updateRefs ( ) ) ) ;
2011-04-14 17:58:15 -04:00
return ;
}
2016-09-13 15:23:27 -04:00
RetroshareDirModel : : preMods ( ) ;
2011-04-01 17:46:06 -04:00
2016-09-13 15:23:27 -04:00
2011-04-09 15:43:09 -04:00
uint32_t nb_treated_refs = 0 ;
2011-04-01 17:46:06 -04:00
2016-09-13 15:23:27 -04:00
{
RS_STACK_MUTEX ( _ref_mutex ) ;
2018-02-24 12:15:54 -05:00
while ( ! _ref_stack . empty ( ) & & ( _ref_entries . size ( ) < = FLAT_VIEW_MAX_REFS_TABLE_SIZE ) )
2016-09-13 15:23:27 -04:00
{
void * ref = _ref_stack . back ( ) ;
2011-04-01 17:46:06 -04:00
# ifdef RDM_DEBUG
2016-09-13 15:23:27 -04:00
std : : cerr < < " FlatStyle_RDM::postMods(): poped ref " < < ref < < std : : endl ;
2011-04-01 17:46:06 -04:00
# endif
2016-09-13 15:23:27 -04:00
_ref_stack . pop_back ( ) ;
2011-04-01 17:46:06 -04:00
2016-09-13 15:23:27 -04:00
DirDetails details ;
2016-08-19 12:49:42 -04:00
2016-09-13 15:23:27 -04:00
if ( requestDirDetails ( ref , RemoteMode , details ) )
{
2018-09-29 13:04:23 -04:00
if ( details . type = = DIR_TYPE_FILE | | details . type = = DIR_TYPE_EXTRA_FILE ) // only push files, not directories nor persons.
2016-09-13 15:23:27 -04:00
_ref_entries . push_back ( ref ) ;
2011-04-01 17:46:06 -04:00
# ifdef RDM_DEBUG
2016-09-13 15:23:27 -04:00
std : : cerr < < " FlatStyle_RDM::postMods(): adding ref " < < ref < < std : : endl ;
2011-04-01 17:46:06 -04:00
# endif
2016-09-13 15:23:27 -04:00
for ( uint32_t i = 0 ; i < details . children . size ( ) ; + + i )
_ref_stack . push_back ( details . children [ i ] . ref ) ;
}
2016-11-20 14:42:14 -05:00
// Limit the size of the table to display, otherwise it becomes impossible to Qt.
if ( _ref_entries . size ( ) > FLAT_VIEW_MAX_REFS_TABLE_SIZE )
2018-02-24 12:15:54 -05:00
continue ;
2016-11-20 14:42:14 -05:00
if ( + + nb_treated_refs > FLAT_VIEW_MAX_REFS_PER_SECOND ) // we've done enough, let's give back hand to
{ // the user and setup a timer to finish the job later.
2016-09-13 15:23:27 -04:00
if ( visible ( ) )
QTimer : : singleShot ( 2000 , this , SLOT ( updateRefs ( ) ) ) ;
else
std : : cerr < < " Not visible: suspending update " < < std : : endl ;
break ;
}
}
2016-11-20 14:42:14 -05:00
std : : cerr < < " reference tab contains " < < std : : dec < < _ref_entries . size ( ) < < " files " < < std : : endl ;
2016-09-13 15:23:27 -04:00
}
2011-04-14 17:58:15 -04:00
2018-09-29 13:04:23 -04:00
if ( _ref_stack . empty ( ) )
_needs_update = false ;
2016-09-13 15:23:27 -04:00
RetroshareDirModel : : postMods ( ) ;
2011-04-01 17:46:06 -04:00
}
2018-02-24 08:07:32 -05:00
void TreeStyle_RDM : : showEmpty ( const bool value )
{
_showEmpty = value ;
update ( ) ;
}