2009-08-11 17:59:40 -04:00
|
|
|
/****************************************************************
|
|
|
|
* RetroShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 - 2009 RetroShare Team
|
|
|
|
*
|
|
|
|
* 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-08-12 15:20:32 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2009-08-11 17:59:40 -04:00
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-08-12 15:20:32 -04:00
|
|
|
****************************************************************/
|
2009-08-11 17:59:40 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#ifndef REMOTE_DIR_MODEL
|
|
|
|
#define REMOTE_DIR_MODEL
|
|
|
|
|
2018-02-19 14:13:38 -05:00
|
|
|
#include <retroshare/rstypes.h>
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <QAbstractItemModel>
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <QIcon>
|
2018-02-19 14:13:38 -05:00
|
|
|
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <stdint.h>
|
2018-02-19 14:13:38 -05:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#define COLUMN_NAME 0
|
|
|
|
#define COLUMN_FILENB 1
|
|
|
|
#define COLUMN_SIZE 2
|
|
|
|
#define COLUMN_AGE 3
|
|
|
|
#define COLUMN_FRIEND_ACCESS 4
|
|
|
|
#define COLUMN_WN_VISU_DIR 5
|
|
|
|
#define COLUMN_COUNT 6
|
2010-07-23 14:52:58 -04:00
|
|
|
|
|
|
|
class DirDetails;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
class DirDetailsVector : public DirDetails
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DirDetailsVector() : DirDetails() {}
|
|
|
|
|
|
|
|
std::vector<DirStub> childrenVector; // For fast access with index (can we change the std::list on DirDetails to std::vector?)
|
|
|
|
};
|
|
|
|
|
2010-02-08 17:32:00 -05:00
|
|
|
static const uint32_t IND_LAST_DAY = 3600*24 ;
|
|
|
|
static const uint32_t IND_LAST_WEEK = 3600*24*7 ;
|
|
|
|
static const uint32_t IND_LAST_MONTH = 3600*24*31 ; // I know, this is approximate
|
|
|
|
static const uint32_t IND_ALWAYS = ~(uint32_t)0 ;
|
2009-10-13 16:36:29 -04:00
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
class RetroshareDirModel : public QAbstractItemModel
|
2009-04-07 04:08:03 -04:00
|
|
|
{
|
2010-01-30 15:47:34 -05:00
|
|
|
Q_OBJECT
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
public:
|
2010-09-19 20:10:51 -04:00
|
|
|
enum Roles{ FileNameRole = Qt::UserRole+1, SortRole = Qt::UserRole+2 };
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
RetroshareDirModel(bool mode, QObject *parent = 0);
|
|
|
|
virtual ~RetroshareDirModel() {}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
Qt::ItemFlags flags ( const QModelIndex & index ) const;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
/* Callback from Core */
|
2011-04-01 17:46:06 -04:00
|
|
|
virtual void preMods();
|
|
|
|
virtual void postMods();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-04-14 17:58:15 -04:00
|
|
|
void setVisible(bool b) { _visible = b ; }
|
|
|
|
bool visible() { return _visible ;}
|
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
/* Callback from GUI */
|
2017-11-12 16:46:29 -05:00
|
|
|
void downloadSelected(const QModelIndexList &list, bool interactive);
|
2012-08-31 10:07:15 -04:00
|
|
|
void createCollectionFile(QWidget *parent, const QModelIndexList &list);
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2010-11-20 09:50:14 -05:00
|
|
|
void getDirDetailsFromSelect (const QModelIndexList &list, std::vector <DirDetails>& dirVec);
|
2008-07-02 12:59:56 -04:00
|
|
|
|
2010-11-07 16:33:48 -05:00
|
|
|
int getType ( const QModelIndex & index ) const ;
|
2009-05-17 15:38:42 -04:00
|
|
|
void getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& files_info) ;
|
2010-11-20 09:50:14 -05:00
|
|
|
void openSelected(const QModelIndexList &list);
|
|
|
|
void getFilePaths(const QModelIndexList &list, std::list<std::string> &fullpaths);
|
2016-08-28 17:14:39 -04:00
|
|
|
void getFilePath(const QModelIndex& index, std::string& fullpath);
|
|
|
|
void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; }
|
2009-10-13 16:36:29 -04:00
|
|
|
|
2016-08-19 12:49:42 -04:00
|
|
|
bool requestDirDetails(void *ref, bool remote,DirDetails& d) const;
|
2014-05-29 10:49:45 -04:00
|
|
|
virtual void update() {}
|
2008-07-04 10:41:24 -04:00
|
|
|
|
2016-09-11 11:52:12 -04:00
|
|
|
virtual void updateRef(const QModelIndex&) const =0;
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
public:
|
2010-01-30 15:47:34 -05:00
|
|
|
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
|
|
|
|
virtual QStringList mimeTypes () const;
|
2011-04-01 17:46:06 -04:00
|
|
|
virtual QVariant data(const QModelIndex &index, int role) const;
|
2013-10-19 16:59:55 -04:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
|
|
|
virtual Qt::DropActions supportedDragActions() const;
|
|
|
|
#endif
|
2008-07-04 10:41:24 -04:00
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
protected:
|
2011-04-14 17:58:15 -04:00
|
|
|
bool _visible ;
|
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
void treeStyle();
|
|
|
|
void downloadDirectory(const DirDetails & details, int prefixLen);
|
2012-11-02 09:52:29 -04:00
|
|
|
static QString getFlagsString(FileStorageFlags f) ;
|
2016-11-01 05:46:29 -04:00
|
|
|
static QString getGroupsString(FileStorageFlags flags, const std::list<RsNodeGroupId> &) ;
|
2010-01-30 15:47:34 -05:00
|
|
|
QString getAgeIndicatorString(const DirDetails &) const;
|
2014-01-04 17:39:34 -05:00
|
|
|
// void getAgeIndicatorRec(const DirDetails &details, QString &ret) const;
|
2016-11-01 05:30:36 -04:00
|
|
|
static const QIcon& getFlagsIcon(FileStorageFlags flags) ;
|
2009-10-13 16:36:29 -04:00
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
virtual QVariant displayRole(const DirDetails&,int) const = 0 ;
|
2011-04-07 16:09:32 -04:00
|
|
|
virtual QVariant sortRole(const QModelIndex&,const DirDetails&,int) const =0;
|
2011-04-01 17:46:06 -04:00
|
|
|
|
|
|
|
QVariant decorationRole(const DirDetails&,int) const ;
|
|
|
|
|
2010-02-08 17:32:00 -05:00
|
|
|
uint32_t ageIndicator;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
QIcon categoryIcon;
|
|
|
|
QIcon peerIcon;
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
class RemoteIndex
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-01-30 15:47:34 -05:00
|
|
|
public:
|
|
|
|
RemoteIndex() {}
|
|
|
|
RemoteIndex(std::string in_person,
|
|
|
|
std::string in_path,
|
|
|
|
int in_idx,
|
|
|
|
int in_row,
|
|
|
|
int in_column,
|
|
|
|
std::string in_name,
|
|
|
|
int in_size,
|
|
|
|
int in_type,
|
|
|
|
int in_ts, int in_rank)
|
|
|
|
:id(in_person), path(in_path), parent(in_idx),
|
|
|
|
row(in_row), column(in_column),
|
|
|
|
name(in_name), size(in_size),
|
|
|
|
type(in_type), timestamp(in_ts), rank(in_rank)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string id;
|
|
|
|
std::string path;
|
|
|
|
int parent;
|
|
|
|
int row;
|
|
|
|
int column;
|
|
|
|
|
|
|
|
/* display info */
|
|
|
|
std::string name;
|
|
|
|
int size;
|
|
|
|
int type;
|
|
|
|
int timestamp;
|
|
|
|
int rank;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
bool RemoteMode;
|
|
|
|
|
|
|
|
mutable int nIndex;
|
|
|
|
mutable std::vector<RemoteIndex> indexSet;
|
|
|
|
|
2016-11-07 16:24:02 -05:00
|
|
|
// This material attempts to keep last request in cache, with no search cost.
|
|
|
|
|
2016-11-08 13:56:07 -05:00
|
|
|
mutable DirDetails mDirDetails ;
|
2016-11-07 16:24:02 -05:00
|
|
|
mutable bool mLastRemote ;
|
|
|
|
mutable time_t mLastReq;
|
2016-11-26 13:19:15 -05:00
|
|
|
|
|
|
|
bool mUpdating ;
|
2010-01-30 15:47:34 -05:00
|
|
|
};
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
// This class shows the classical hierarchical directory view of shared files
|
|
|
|
// Columns are:
|
|
|
|
// file name | Size | Age
|
|
|
|
//
|
|
|
|
class TreeStyle_RDM: public RetroshareDirModel
|
|
|
|
{
|
2011-06-04 19:44:17 -04:00
|
|
|
Q_OBJECT
|
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
public:
|
|
|
|
TreeStyle_RDM(bool mode)
|
|
|
|
: RetroshareDirModel(mode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~TreeStyle_RDM() ;
|
|
|
|
|
|
|
|
protected:
|
2016-09-11 11:52:12 -04:00
|
|
|
virtual void updateRef(const QModelIndex&) const ;
|
2017-09-14 16:01:52 -04:00
|
|
|
virtual void update() ;
|
2016-09-11 11:52:12 -04:00
|
|
|
|
|
|
|
/* These are all overloaded Virtual Functions */
|
2011-04-01 17:46:06 -04:00
|
|
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
|
|
|
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
|
|
virtual QVariant displayRole(const DirDetails&,int) const ;
|
2011-04-07 16:09:32 -04:00
|
|
|
virtual QVariant sortRole(const QModelIndex&,const DirDetails&,int) const ;
|
2011-04-01 17:46:06 -04:00
|
|
|
|
|
|
|
virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const;
|
|
|
|
virtual QModelIndex parent ( const QModelIndex & index ) const;
|
|
|
|
virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This class shows a flat list of all shared files
|
|
|
|
// Columns are:
|
|
|
|
// file name | Owner | Size | Age
|
|
|
|
//
|
|
|
|
class FlatStyle_RDM: public RetroshareDirModel
|
|
|
|
{
|
2011-04-09 15:43:09 -04:00
|
|
|
Q_OBJECT
|
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
public:
|
2016-11-20 14:42:14 -05:00
|
|
|
FlatStyle_RDM(bool mode);
|
2011-04-01 17:46:06 -04:00
|
|
|
|
|
|
|
virtual ~FlatStyle_RDM() ;
|
|
|
|
|
2014-01-05 17:51:54 -05:00
|
|
|
virtual void update() ;
|
|
|
|
|
2011-04-09 15:43:09 -04:00
|
|
|
protected slots:
|
|
|
|
void updateRefs() ;
|
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
protected:
|
2016-09-11 11:52:12 -04:00
|
|
|
virtual void updateRef(const QModelIndex&) const {}
|
|
|
|
virtual void postMods();
|
2011-04-01 17:46:06 -04:00
|
|
|
|
|
|
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
|
|
|
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
|
|
virtual QVariant displayRole(const DirDetails&,int) const ;
|
2011-04-07 16:09:32 -04:00
|
|
|
virtual QVariant sortRole(const QModelIndex&,const DirDetails&,int) const ;
|
2011-04-01 17:46:06 -04:00
|
|
|
|
|
|
|
virtual QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const;
|
|
|
|
virtual QModelIndex parent ( const QModelIndex & index ) const;
|
|
|
|
virtual bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
|
|
|
|
|
2011-04-07 16:09:32 -04:00
|
|
|
QString computeDirectoryPath(const DirDetails& details) const ;
|
|
|
|
|
2016-09-13 15:23:27 -04:00
|
|
|
mutable RsMutex _ref_mutex ;
|
|
|
|
std::vector<void *> _ref_entries ;// used to store the refs to display
|
2011-04-09 15:43:09 -04:00
|
|
|
std::vector<void *> _ref_stack ; // used to store the refs to update
|
2014-01-05 17:51:54 -05:00
|
|
|
bool _needs_update ;
|
2016-11-20 14:42:14 -05:00
|
|
|
time_t _last_update ;
|
2011-04-01 17:46:06 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif
|