mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-11-27 11:00:37 -05:00
factorized and cleaned the common code between fistore.cc and fimonitor.cc, improved the stability of FileIndex, improved the display in RemoteDirModel
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2158 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
dd5e058173
commit
8e5b1dca64
6 changed files with 321 additions and 358 deletions
|
|
@ -34,6 +34,7 @@
|
|||
#include <algorithm>
|
||||
#include "util/misc.h"
|
||||
|
||||
#define RDM_DEBUG
|
||||
/*****
|
||||
* #define RDM_DEBUG
|
||||
****/
|
||||
|
|
@ -116,11 +117,7 @@ void RemoteDirModel::treeStyle()
|
|||
std::cerr << ": ";
|
||||
#endif
|
||||
|
||||
void *ref = NULL;
|
||||
if (parent.isValid())
|
||||
{
|
||||
ref = parent.internalPointer();
|
||||
}
|
||||
void *ref = (parent.isValid())? parent.internalPointer() : NULL ;
|
||||
|
||||
DirDetails details;
|
||||
uint32_t flags = DIR_FLAGS_CHILDREN;
|
||||
|
|
@ -447,16 +444,14 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
|||
switch(coln)
|
||||
{
|
||||
case 0:
|
||||
return QString::fromStdString(details.name);
|
||||
break;
|
||||
return QString::fromStdString(details.name);
|
||||
break;
|
||||
case 1:
|
||||
//return QString("");
|
||||
return QString::fromStdString(details.id);
|
||||
break;
|
||||
return QString() ;
|
||||
break;
|
||||
default:
|
||||
//return QString("");
|
||||
return QString::fromStdString("P");
|
||||
break;
|
||||
return QString() ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (details.type == DIR_TYPE_FILE) /* File */
|
||||
|
|
@ -464,13 +459,13 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
|||
switch(coln)
|
||||
{
|
||||
case 0:
|
||||
return QString::fromUtf8(details.name.c_str());
|
||||
break;
|
||||
return QString::fromUtf8(details.name.c_str());
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
std::ostringstream out;
|
||||
//out << details.count;
|
||||
//return QString::fromStdString(out.str());
|
||||
{
|
||||
std::ostringstream out;
|
||||
//out << details.count;
|
||||
//return QString::fromStdString(out.str());
|
||||
return misc::friendlyUnit(details.count);
|
||||
}
|
||||
break;
|
||||
|
|
@ -520,21 +515,21 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
|||
case 3:
|
||||
return QString::fromUtf8("Folder");
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
if (ageIndicator == IND_DEFAULT)
|
||||
return QString("");
|
||||
QModelIndex pidx = parent(index);
|
||||
QModelIndex pidxs = pidx.sibling(pidx.row(), 4);
|
||||
if (pidxs.isValid() && pidxs.data() != tr(""))
|
||||
return pidxs.data();
|
||||
else {
|
||||
QString ind("");
|
||||
getAgeIndicatorRec(details, ind);
|
||||
return ind;
|
||||
}
|
||||
}
|
||||
break;
|
||||
// case 4:
|
||||
// {
|
||||
// if (ageIndicator == IND_DEFAULT)
|
||||
// return QString("");
|
||||
// QModelIndex pidx = parent(index);
|
||||
// QModelIndex pidxs = pidx.sibling(pidx.row(), 4);
|
||||
// if (pidxs.isValid() && pidxs.data() != tr(""))
|
||||
// return pidxs.data();
|
||||
// else {
|
||||
// QString ind("");
|
||||
// getAgeIndicatorRec(details, ind);
|
||||
// return ind;
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
default:
|
||||
return QString(tr("DIR"));
|
||||
break;
|
||||
|
|
@ -627,43 +622,40 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
|||
return QString("Row %1").arg(section);
|
||||
}
|
||||
|
||||
QModelIndex RemoteDirModel::index(int row, int column,
|
||||
const QModelIndex & parent) const
|
||||
{
|
||||
QModelIndex RemoteDirModel::index(int row, int column, const QModelIndex & parent) const
|
||||
{
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "RemoteDirModel::index(): " << parent.internalPointer();
|
||||
std::cerr << ": row:" << row << " col:" << column << " ";
|
||||
#endif
|
||||
|
||||
void *ref = NULL;
|
||||
if(row < 0)
|
||||
return QModelIndex() ;
|
||||
|
||||
if (parent.isValid())
|
||||
{
|
||||
ref = parent.internalPointer();
|
||||
}
|
||||
void *ref = (parent.isValid()) ? parent.internalPointer() : NULL;
|
||||
|
||||
/********
|
||||
if (!RemoteMode)
|
||||
{
|
||||
remote = &(rsiface->getLocalDirectoryList());
|
||||
}
|
||||
********/
|
||||
if (!RemoteMode)
|
||||
{
|
||||
remote = &(rsiface->getLocalDirectoryList());
|
||||
}
|
||||
********/
|
||||
|
||||
DirDetails details;
|
||||
uint32_t flags = DIR_FLAGS_CHILDREN;
|
||||
if (RemoteMode)
|
||||
flags |= DIR_FLAGS_REMOTE;
|
||||
else
|
||||
flags |= DIR_FLAGS_LOCAL;
|
||||
DirDetails details;
|
||||
uint32_t flags = DIR_FLAGS_CHILDREN;
|
||||
if (RemoteMode)
|
||||
flags |= DIR_FLAGS_REMOTE;
|
||||
else
|
||||
flags |= DIR_FLAGS_LOCAL;
|
||||
|
||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||
{
|
||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||
{
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "lookup failed -> invalid";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "lookup failed -> invalid";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return QModelIndex();
|
||||
}
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
/* now iterate through the details to
|
||||
* get the reference number
|
||||
|
|
@ -671,125 +663,104 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
|||
|
||||
std::list<DirStub>::iterator it;
|
||||
int i = 0;
|
||||
for(it = details.children.begin();
|
||||
((i < row) && (it != details.children.end())); it++, i++) ;
|
||||
for(it = details.children.begin(); ((i < row) && (it != details.children.end())); ++it, ++i) ;
|
||||
|
||||
if (it == details.children.end())
|
||||
{
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "wrong number of children -> invalid";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "wrong number of children -> invalid";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "success index(" << row << "," << column << "," << it->ref << ")";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "success index(" << row << "," << column << "," << it->ref << ")";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* we can just grab the reference now */
|
||||
QModelIndex qmi = createIndex(row, column, it->ref);
|
||||
return qmi;
|
||||
}
|
||||
|
||||
return createIndex(row, column, it->ref);
|
||||
}
|
||||
|
||||
|
||||
QModelIndex RemoteDirModel::parent( const QModelIndex & index ) const
|
||||
{
|
||||
QModelIndex RemoteDirModel::parent( const QModelIndex & index ) const
|
||||
{
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "RemoteDirModel::parent(): " << index.internalPointer();
|
||||
std::cerr << ": ";
|
||||
#endif
|
||||
|
||||
/* create the index */
|
||||
if (!index.isValid())
|
||||
if (!index.isValid())
|
||||
{
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "Invalid Index -> invalid";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Invalid Index -> invalid";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* Parent is invalid too */
|
||||
return QModelIndex();
|
||||
}
|
||||
void *ref = index.internalPointer();
|
||||
|
||||
DirDetails details;
|
||||
uint32_t flags = DIR_FLAGS_PARENT;
|
||||
if (RemoteMode)
|
||||
flags |= DIR_FLAGS_REMOTE;
|
||||
else
|
||||
flags |= DIR_FLAGS_LOCAL;
|
||||
DirDetails details;
|
||||
uint32_t flags = (RemoteMode)?DIR_FLAGS_REMOTE:DIR_FLAGS_LOCAL;
|
||||
|
||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||
{
|
||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||
{
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "Failed Lookup -> invalid";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Failed Lookup -> invalid";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return QModelIndex();
|
||||
}
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
if (!(details.parent))
|
||||
{
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "success. parent is Root/NULL --> invalid";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "success. parent is Root/NULL --> invalid";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return QModelIndex();
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "success index(" << details.prow << ",0," << details.parent << ")";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "success index(" << details.prow << ",0," << details.parent << ")";
|
||||
std::cerr << std::endl;
|
||||
|
||||
#endif
|
||||
return createIndex(details.prow, 0, details.parent);
|
||||
}
|
||||
}
|
||||
|
||||
Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
|
||||
{
|
||||
Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
|
||||
{
|
||||
#ifdef RDM_DEBUG
|
||||
std::cerr << "RemoteDirModel::flags()";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "RemoteDirModel::flags()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if (!index.isValid())
|
||||
if (!index.isValid())
|
||||
return (Qt::ItemIsSelectable); // Error.
|
||||
|
||||
void *ref = index.internalPointer();
|
||||
|
||||
DirDetails details;
|
||||
uint32_t flags = DIR_FLAGS_DETAILS;
|
||||
if (RemoteMode)
|
||||
flags |= DIR_FLAGS_REMOTE;
|
||||
else
|
||||
flags |= DIR_FLAGS_LOCAL;
|
||||
DirDetails details;
|
||||
uint32_t flags = DIR_FLAGS_DETAILS;
|
||||
if (RemoteMode)
|
||||
flags |= DIR_FLAGS_REMOTE;
|
||||
else
|
||||
flags |= DIR_FLAGS_LOCAL;
|
||||
|
||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||
{
|
||||
return (Qt::ItemIsSelectable); // Error.
|
||||
}
|
||||
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
||||
return Qt::ItemIsSelectable; // Error.
|
||||
|
||||
if (details.type == DIR_TYPE_PERSON)
|
||||
switch(details.type)
|
||||
{
|
||||
return (Qt::ItemIsEnabled);
|
||||
}
|
||||
else if (details.type == DIR_TYPE_DIR)
|
||||
{
|
||||
return ( Qt::ItemIsSelectable |
|
||||
Qt::ItemIsEnabled);
|
||||
|
||||
// Qt::ItemIsDragEnabled |
|
||||
// Qt::ItemIsDropEnabled |
|
||||
|
||||
}
|
||||
else // (details.type == DIR_TYPE_FILE)
|
||||
{
|
||||
return ( Qt::ItemIsSelectable |
|
||||
Qt::ItemIsDragEnabled |
|
||||
Qt::ItemIsEnabled);
|
||||
|
||||
|
||||
case DIR_TYPE_PERSON: return Qt::ItemIsEnabled;
|
||||
case DIR_TYPE_DIR: return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||
default: ;
|
||||
case DIR_TYPE_FILE: return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,118 +38,118 @@
|
|||
|
||||
class RemoteDirModel : public QAbstractItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Roles{ FileNameRole = Qt::UserRole+1 };
|
||||
public:
|
||||
enum Roles{ FileNameRole = Qt::UserRole+1 };
|
||||
|
||||
RemoteDirModel(bool mode, QObject *parent = 0);
|
||||
RemoteDirModel(bool mode, QObject *parent = 0);
|
||||
|
||||
/* These are all overloaded Virtual Functions */
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
/* These are all overloaded Virtual Functions */
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex & parent = QModelIndex() ) const;
|
||||
QModelIndex parent ( const QModelIndex & index ) const;
|
||||
QModelIndex index(int row, int column,
|
||||
const QModelIndex & parent = QModelIndex() ) const;
|
||||
QModelIndex parent ( const QModelIndex & index ) const;
|
||||
|
||||
Qt::ItemFlags flags ( const QModelIndex & index ) const;
|
||||
bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
|
||||
Qt::ItemFlags flags ( const QModelIndex & index ) const;
|
||||
bool hasChildren(const QModelIndex & parent = QModelIndex()) const;
|
||||
|
||||
/* Callback from Core */
|
||||
void preMods();
|
||||
void postMods();
|
||||
/* Callback from Core */
|
||||
void preMods();
|
||||
void postMods();
|
||||
|
||||
/* Callback from GUI */
|
||||
void downloadSelected(QModelIndexList list);
|
||||
/* Callback from GUI */
|
||||
void downloadSelected(QModelIndexList list);
|
||||
|
||||
void getDirDetailsFromSelect (QModelIndexList list, std::vector <DirDetails>& dirVec);
|
||||
void getDirDetailsFromSelect (QModelIndexList list, std::vector <DirDetails>& dirVec);
|
||||
|
||||
bool isDir ( const QModelIndex & index ) const ;
|
||||
//void openFile(QModelIndex fileIndex, const QString command);
|
||||
bool isDir ( const QModelIndex & index ) const ;
|
||||
//void openFile(QModelIndex fileIndex, const QString command);
|
||||
|
||||
//#if 0 /****** REMOVED ******/
|
||||
// void recommendSelected(QModelIndexList list);
|
||||
// void recommendSelectedOnly(QModelIndexList list);
|
||||
//#endif
|
||||
//#if 0 /****** REMOVED ******/
|
||||
// void recommendSelected(QModelIndexList list);
|
||||
// void recommendSelectedOnly(QModelIndexList list);
|
||||
//#endif
|
||||
void getFileInfoFromIndexList(const QModelIndexList& list, std::list<DirDetails>& files_info) ;
|
||||
|
||||
void openSelected(QModelIndexList list, bool openFolder);
|
||||
void openSelected(QModelIndexList list, bool openFolder);
|
||||
|
||||
void getFilePaths(QModelIndexList list, std::list<std::string> &fullpaths);
|
||||
void getFilePaths(QModelIndexList list, std::list<std::string> &fullpaths);
|
||||
|
||||
void changeAgeIndicator(int indicator) { ageIndicator = indicator; }
|
||||
void changeAgeIndicator(int indicator) { ageIndicator = indicator; }
|
||||
|
||||
|
||||
public slots:
|
||||
public slots:
|
||||
|
||||
void collapsed ( const QModelIndex & index ) { update(index); }
|
||||
void expanded ( const QModelIndex & index ) { update(index); }
|
||||
void collapsed ( const QModelIndex & index ) { update(index); }
|
||||
void expanded ( const QModelIndex & index ) { update(index); }
|
||||
|
||||
/* Drag and Drop Functionality */
|
||||
public:
|
||||
/* Drag and Drop Functionality */
|
||||
public:
|
||||
|
||||
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
|
||||
virtual QStringList mimeTypes () const;
|
||||
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;
|
||||
virtual QStringList mimeTypes () const;
|
||||
|
||||
private:
|
||||
void update (const QModelIndex &index );
|
||||
void treeStyle();
|
||||
void downloadDirectory(const DirDetails & details, int prefixLen);
|
||||
static QString getFlagsString(uint32_t) ;
|
||||
QString getAgeIndicatorString(const DirDetails &) const;
|
||||
void getAgeIndicatorRec(DirDetails &details, QString &ret) const;
|
||||
private:
|
||||
void update (const QModelIndex &index );
|
||||
void treeStyle();
|
||||
void downloadDirectory(const DirDetails & details, int prefixLen);
|
||||
static QString getFlagsString(uint32_t) ;
|
||||
QString getAgeIndicatorString(const DirDetails &) const;
|
||||
void getAgeIndicatorRec(DirDetails &details, QString &ret) const;
|
||||
|
||||
int ageIndicator;
|
||||
int ageIndicator;
|
||||
|
||||
QIcon categoryIcon;
|
||||
QIcon peerIcon;
|
||||
QIcon categoryIcon;
|
||||
QIcon peerIcon;
|
||||
|
||||
class RemoteIndex
|
||||
{
|
||||
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)
|
||||
class RemoteIndex
|
||||
{
|
||||
return;
|
||||
}
|
||||
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;
|
||||
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;
|
||||
/* display info */
|
||||
std::string name;
|
||||
int size;
|
||||
int type;
|
||||
int timestamp;
|
||||
int rank;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
bool RemoteMode;
|
||||
bool RemoteMode;
|
||||
|
||||
mutable int nIndex;
|
||||
mutable std::vector<RemoteIndex> indexSet;
|
||||
mutable int nIndex;
|
||||
mutable std::vector<RemoteIndex> indexSet;
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue