2009-10-13 16:36:29 -04:00
|
|
|
/*************************************:***************************
|
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-10-13 16:36:29 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2009-08-11 17:59:40 -04:00
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QMimeData>
|
2011-04-09 15:43:09 -04:00
|
|
|
#include <QTimer>
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2012-02-19 10:03:07 -05:00
|
|
|
#include <retroshare-gui/RsAutoUpdatePage.h>
|
2011-11-07 18:07:25 -05:00
|
|
|
#include <gui/common/RsCollectionFile.h>
|
|
|
|
#include <gui/common/RsUrlHandler.h>
|
2011-12-07 08:08:12 -05:00
|
|
|
#include <gui/common/FilesDefs.h>
|
2012-12-11 19:04:01 -05:00
|
|
|
#include <gui/common/GroupDefs.h>
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "RemoteDirModel.h"
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsfiles.h>
|
|
|
|
#include <retroshare/rstypes.h>
|
2011-04-01 17:46:06 -04:00
|
|
|
#include <retroshare/rspeers.h>
|
2010-07-23 14:52:58 -04:00
|
|
|
#include "util/misc.h"
|
2008-07-02 12:59:56 -04:00
|
|
|
|
2010-07-23 14:52:58 -04:00
|
|
|
#include <set>
|
2008-11-02 10:20:42 -05:00
|
|
|
#include <algorithm>
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
/*****
|
|
|
|
* #define RDM_DEBUG
|
|
|
|
****/
|
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
RetroshareDirModel::RetroshareDirModel(bool mode, QObject *parent)
|
2008-07-04 10:41:24 -04:00
|
|
|
: QAbstractItemModel(parent),
|
2010-06-10 10:13:20 -04:00
|
|
|
ageIndicator(IND_ALWAYS),
|
|
|
|
RemoteMode(mode), nIndex(1), indexSet(1) /* ass zero index cant be used */
|
2008-07-04 10:41:24 -04:00
|
|
|
{
|
2011-04-14 17:58:15 -04:00
|
|
|
_visible = false ;
|
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();
|
2008-07-04 10:41:24 -04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2014-01-05 17:51:54 -05:00
|
|
|
void FlatStyle_RDM::update()
|
2011-04-14 17:58:15 -04:00
|
|
|
{
|
|
|
|
if(_needs_update)
|
|
|
|
{
|
|
|
|
preMods() ;
|
|
|
|
postMods() ;
|
|
|
|
}
|
|
|
|
}
|
2011-04-01 17:46:06 -04:00
|
|
|
void RetroshareDirModel::treeStyle()
|
2009-05-31 19:06:14 -04:00
|
|
|
{
|
|
|
|
categoryIcon.addPixmap(QPixmap(":/images/folder16.png"),
|
|
|
|
QIcon::Normal, QIcon::Off);
|
|
|
|
categoryIcon.addPixmap(QPixmap(":/images/folder_video.png"),
|
|
|
|
QIcon::Normal, QIcon::On);
|
|
|
|
peerIcon = QIcon(":/images/user/identity16.png");
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
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
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *details = requestDirDetails(ref, RemoteMode);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!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
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (details->type == DIR_TYPE_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
|
2014-01-04 17:39:34 -05: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
|
2014-01-04 17:39:34 -05: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
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *details = requestDirDetails(ref, RemoteMode);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!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;
|
|
|
|
}
|
2014-01-04 17:39:34 -05:00
|
|
|
if (details->type == DIR_TYPE_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
|
2014-01-04 17:39:34 -05: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
|
2014-01-04 17:39:34 -05:00
|
|
|
return details->count;
|
2011-04-01 17:46:06 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
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
|
|
|
|
|
|
|
|
return _ref_entries.size() ;
|
|
|
|
}
|
2011-08-12 10:06:29 -04:00
|
|
|
int TreeStyle_RDM::columnCount(const QModelIndex &/*parent*/) const
|
2011-04-01 17:46:06 -04:00
|
|
|
{
|
2009-10-13 16:36:29 -04:00
|
|
|
return 5;
|
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
|
|
|
{
|
|
|
|
return 5;
|
|
|
|
}
|
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
|
|
|
|
2012-11-02 09:52:29 -04:00
|
|
|
if(flags & DIR_FLAGS_BROWSABLE_GROUPS) str[0] = 'B' ;
|
2012-11-06 15:46:56 -05:00
|
|
|
//if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) str[3] = 'N' ;
|
|
|
|
if(flags & DIR_FLAGS_BROWSABLE_OTHERS) str[3] = 'B' ;
|
|
|
|
if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS) str[6] = 'N' ;
|
2012-10-21 15:39:56 -04:00
|
|
|
|
|
|
|
return QString(str) ;
|
|
|
|
}
|
2012-11-13 14:37:51 -05:00
|
|
|
QString RetroshareDirModel::getGroupsString(const std::list<std::string>& group_ids)
|
2012-10-21 15:39:56 -04:00
|
|
|
{
|
|
|
|
QString groups_str ;
|
2012-11-13 14:37:51 -05:00
|
|
|
RsGroupInfo group_info ;
|
2012-10-21 15:39:56 -04:00
|
|
|
|
2012-11-13 14:37:51 -05:00
|
|
|
for(std::list<std::string>::const_iterator it(group_ids.begin());it!=group_ids.end();)
|
|
|
|
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");
|
2009-10-13 16:36:29 -04:00
|
|
|
uint32_t age = details.age;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln) const
|
|
|
|
{
|
|
|
|
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)
|
2010-06-12 14:10:39 -04:00
|
|
|
{
|
2011-04-01 17:46:06 -04:00
|
|
|
if(details.min_age > ageIndicator)
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if(details.min_age > ageIndicator)
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else if (details.type == DIR_TYPE_FILE) /* File */
|
|
|
|
{
|
|
|
|
// extensions predefined
|
2011-12-07 08:08:12 -05:00
|
|
|
return FilesDefs::getIconFromFilename(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 */
|
|
|
|
{
|
|
|
|
switch(coln)
|
|
|
|
{
|
|
|
|
case 0:
|
2013-06-02 14:50:09 -04:00
|
|
|
return (RemoteMode)?(QString::fromUtf8(rsPeers->getPeerName(details.id).c_str())):tr("My files");
|
2007-11-14 22:18:48 -05:00
|
|
|
case 1:
|
2010-01-30 15:47:34 -05:00
|
|
|
return QString() ;
|
2011-05-21 14:34:34 -04:00
|
|
|
case 2:
|
|
|
|
return misc::userFriendlyDuration(details.min_age);
|
2007-11-14 22:18:48 -05:00
|
|
|
default:
|
2010-01-30 15:47:34 -05:00
|
|
|
return QString() ;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (details.type == DIR_TYPE_FILE) /* File */
|
|
|
|
{
|
|
|
|
switch(coln)
|
|
|
|
{
|
|
|
|
case 0:
|
2010-01-30 15:47:34 -05:00
|
|
|
return QString::fromUtf8(details.name.c_str());
|
2007-11-14 22:18:48 -05:00
|
|
|
case 1:
|
2010-10-28 13:26:00 -04:00
|
|
|
return misc::friendlyUnit(details.count);
|
2007-11-14 22:18:48 -05:00
|
|
|
case 2:
|
2010-10-28 13:26:00 -04:00
|
|
|
return misc::userFriendlyDuration(details.age);
|
2007-11-14 22:18:48 -05:00
|
|
|
case 3:
|
2010-10-28 13:26:00 -04:00
|
|
|
return getFlagsString(details.flags);
|
2012-10-21 15:39:56 -04:00
|
|
|
// case 4:
|
|
|
|
// {
|
|
|
|
// QString ind("");
|
|
|
|
// if (ageIndicator != IND_ALWAYS)
|
|
|
|
// ind = getAgeIndicatorString(details);
|
|
|
|
// return ind;
|
|
|
|
// }
|
2009-10-13 16:36:29 -04:00
|
|
|
case 4:
|
2012-11-01 06:06:12 -04:00
|
|
|
return getGroupsString(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)
|
|
|
|
{
|
|
|
|
case 0:
|
2011-04-01 17:46:06 -04:00
|
|
|
return QString::fromUtf8(details.name.c_str());
|
2009-08-10 14:55:49 -04:00
|
|
|
break;
|
2007-11-14 22:18:48 -05:00
|
|
|
case 1:
|
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");
|
2007-11-14 22:18:48 -05:00
|
|
|
case 2:
|
2010-10-28 13:26:00 -04:00
|
|
|
return misc::userFriendlyDuration(details.min_age);
|
2009-10-13 16:36:29 -04:00
|
|
|
case 3:
|
2010-10-28 13:26:00 -04:00
|
|
|
return getFlagsString(details.flags);
|
2012-10-21 15:39:56 -04:00
|
|
|
case 4:
|
2012-11-01 06:06:12 -04:00
|
|
|
return getGroupsString(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
|
|
|
|
2011-04-07 16:09:32 -04:00
|
|
|
QString FlatStyle_RDM::computeDirectoryPath(const DirDetails& details) const
|
|
|
|
{
|
|
|
|
QString dir ;
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *det = requestDirDetails(details.parent,RemoteMode);
|
2011-04-07 16:09:32 -04:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if(!det)
|
2011-04-07 16:09:32 -04:00
|
|
|
return QString();
|
|
|
|
|
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
|
2014-01-04 17:39:34 -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
|
|
|
|
{
|
|
|
|
if (details.type == DIR_TYPE_FILE) /* File */
|
|
|
|
switch(coln)
|
|
|
|
{
|
|
|
|
case 0: return QString::fromUtf8(details.name.c_str());
|
|
|
|
case 1: return misc::friendlyUnit(details.count);
|
|
|
|
case 2: return misc::userFriendlyDuration(details.age);
|
2011-07-17 19:07:29 -04:00
|
|
|
case 3: return QString::fromUtf8(rsPeers->getPeerName(details.id).c_str());
|
2011-04-07 16:09:32 -04:00
|
|
|
case 4: 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 */
|
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)
|
|
|
|
{
|
|
|
|
case 0:
|
2013-06-13 11:19:38 -04:00
|
|
|
return (RemoteMode)?(QString::fromUtf8(rsPeers->getPeerName(details.id).c_str())):tr("My files");
|
2011-04-01 17:46:06 -04:00
|
|
|
case 1:
|
|
|
|
return QString();
|
2011-05-21 14:34:34 -04:00
|
|
|
case 2:
|
|
|
|
return details.min_age;
|
2011-04-01 17:46:06 -04:00
|
|
|
default:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (details.type == DIR_TYPE_FILE) /* File */
|
|
|
|
{
|
|
|
|
switch(coln)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return QString::fromUtf8(details.name.c_str());
|
|
|
|
case 1:
|
|
|
|
return (qulonglong) details.count;
|
|
|
|
case 2:
|
|
|
|
return details.age;
|
|
|
|
case 3:
|
|
|
|
return getFlagsString(details.flags);
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return QString::fromUtf8(details.name.c_str());
|
|
|
|
case 1:
|
|
|
|
return (qulonglong) details.count;
|
|
|
|
case 2:
|
|
|
|
return details.min_age;
|
|
|
|
case 3:
|
|
|
|
return getFlagsString(details.flags);
|
|
|
|
default:
|
|
|
|
return tr("DIR");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
2011-04-03 15:59:12 -04:00
|
|
|
}
|
2011-04-07 16:09:32 -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
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (details.type == DIR_TYPE_FILE) /* File */
|
|
|
|
{
|
|
|
|
switch(coln)
|
|
|
|
{
|
|
|
|
case 0: return QString::fromUtf8(details.name.c_str());
|
|
|
|
case 1: return (qulonglong) details.count;
|
|
|
|
case 2: return details.age;
|
2011-07-17 19:07:29 -04:00
|
|
|
case 3: return QString::fromUtf8(rsPeers->getPeerName(details.id).c_str());
|
2011-04-07 16:09:32 -04:00
|
|
|
case 4: return _ref_entries[index.row()].second ;
|
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
|
|
|
|
std::cerr << "RetroshareDirModel::data(): " << index.internalPointer();
|
|
|
|
std::cerr << ": ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!index.isValid())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
/* get the data from the index */
|
|
|
|
void *ref = index.internalPointer();
|
|
|
|
int coln = index.column();
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *details = requestDirDetails(ref, RemoteMode);
|
2011-04-01 17:46:06 -04:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!details)
|
2011-04-01 17:46:06 -04:00
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (role == RetroshareDirModel::FileNameRole) /* end of FileNameRole */
|
2014-01-04 17:39:34 -05:00
|
|
|
return QString::fromUtf8(details->name.c_str());
|
2011-04-01 17:46:06 -04:00
|
|
|
|
|
|
|
if (role == Qt::TextColorRole)
|
|
|
|
{
|
2014-01-04 17:39:34 -05:00
|
|
|
if(details->min_age > ageIndicator)
|
2013-10-19 16:59:55 -04:00
|
|
|
return QVariant(QColor(Qt::gray)) ;
|
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)
|
2014-01-04 17:39:34 -05:00
|
|
|
return decorationRole(*details,coln) ;
|
2011-04-01 17:46:06 -04:00
|
|
|
|
|
|
|
/*****************
|
|
|
|
Qt::EditRole
|
|
|
|
Qt::ToolTipRole
|
|
|
|
Qt::StatusTipRole
|
|
|
|
Qt::WhatsThisRole
|
|
|
|
Qt::SizeHintRole
|
|
|
|
****************/
|
|
|
|
|
|
|
|
if (role == Qt::SizeHintRole)
|
|
|
|
{
|
2015-06-23 08:19:33 -04:00
|
|
|
return QVariant(); // Use standard
|
2011-04-01 17:46:06 -04:00
|
|
|
} /* end of SizeHintRole */
|
|
|
|
|
|
|
|
if (role == Qt::TextAlignmentRole)
|
|
|
|
{
|
|
|
|
if(coln == 1)
|
|
|
|
{
|
|
|
|
return int( Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
} /* end of TextAlignmentRole */
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole)
|
2014-01-04 17:39:34 -05:00
|
|
|
return displayRole(*details,coln) ;
|
2011-04-01 17:46:06 -04:00
|
|
|
|
|
|
|
if (role == SortRole)
|
2014-01-04 17:39:34 -05:00
|
|
|
return sortRole(index,*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
|
|
|
|
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);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//}
|
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
|
|
|
|
{
|
|
|
|
if (role == Qt::SizeHintRole)
|
|
|
|
{
|
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();
|
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
if (section < 2)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (role != Qt::DisplayRole)
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (orientation == Qt::Horizontal)
|
|
|
|
{
|
|
|
|
switch(section)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (RemoteMode)
|
|
|
|
return tr("Friends Directories");
|
|
|
|
else
|
|
|
|
return tr("My Directories");
|
|
|
|
case 1:
|
|
|
|
return tr("Size");
|
|
|
|
case 2:
|
|
|
|
return tr("Age");
|
|
|
|
case 3:
|
|
|
|
if (RemoteMode)
|
|
|
|
return tr("Friend");
|
|
|
|
else
|
2013-02-22 16:42:27 -05:00
|
|
|
return tr("Share Flags");
|
2011-04-01 17:46:06 -04:00
|
|
|
case 4:
|
2012-10-21 15:39:56 -04:00
|
|
|
if (RemoteMode)
|
|
|
|
return tr("What's new");
|
|
|
|
else
|
|
|
|
return tr("Groups");
|
2011-04-01 17:46:06 -04:00
|
|
|
}
|
|
|
|
return QString("Column %1").arg(section);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return QString("Row %1").arg(section);
|
|
|
|
}
|
|
|
|
QVariant FlatStyle_RDM::headerData(int section, Qt::Orientation orientation, int role) const
|
2009-08-10 14:55:49 -04:00
|
|
|
{
|
|
|
|
if (role == Qt::SizeHintRole)
|
|
|
|
{
|
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();
|
|
|
|
|
2009-08-10 14:55:49 -04:00
|
|
|
if (section < 2)
|
|
|
|
{
|
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);
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
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");
|
2009-08-10 14:55:49 -04:00
|
|
|
case 1:
|
2010-10-28 13:26:00 -04:00
|
|
|
return tr("Size");
|
2009-08-10 14:55:49 -04:00
|
|
|
case 2:
|
2010-10-28 13:26:00 -04:00
|
|
|
return tr("Age");
|
2009-08-10 14:55:49 -04:00
|
|
|
case 3:
|
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");
|
2009-10-13 16:36:29 -04:00
|
|
|
case 4:
|
2011-04-07 16:09:32 -04:00
|
|
|
return tr("Directory");
|
2009-08-10 14:55:49 -04:00
|
|
|
}
|
|
|
|
return QString("Column %1").arg(section);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-08-10 14:55:49 -04:00
|
|
|
else
|
|
|
|
return QString("Row %1").arg(section);
|
|
|
|
}
|
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
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
********/
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetailsVector *details = requestDirDetails(ref, RemoteMode);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!details)
|
2010-01-30 15:47:34 -05:00
|
|
|
{
|
2007-11-14 22:18:48 -05:00
|
|
|
#ifdef RDM_DEBUG
|
2010-01-30 15:47:34 -05:00
|
|
|
std::cerr << "lookup failed -> 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
|
|
|
|
2010-02-08 17:32:00 -05:00
|
|
|
|
2009-07-07 14:56:31 -04:00
|
|
|
/* now iterate through the details to
|
2007-11-14 22:18:48 -05:00
|
|
|
* get the reference number
|
|
|
|
*/
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (row >= (int) details->childrenVector.size())
|
2009-07-07 14:56:31 -04:00
|
|
|
{
|
2007-11-14 22:18:48 -05:00
|
|
|
#ifdef RDM_DEBUG
|
2010-01-30 15:47:34 -05:00
|
|
|
std::cerr << "wrong number of children -> invalid";
|
|
|
|
std::cerr << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif
|
2009-07-07 14:56:31 -04:00
|
|
|
return QModelIndex();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RDM_DEBUG
|
2014-01-04 17:39:34 -05:00
|
|
|
std::cerr << "success index(" << row << "," << column << "," << details->childrenVector[row].ref << ")";
|
2010-01-30 15:47:34 -05:00
|
|
|
std::cerr << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* we can just grab the reference now */
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
return createIndex(row, column, details->childrenVector[row].ref);
|
2010-01-30 15:47:34 -05:00
|
|
|
}
|
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() ;
|
|
|
|
|
2011-08-14 17:25:41 -04:00
|
|
|
if(row < (int) _ref_entries.size())
|
2011-04-01 17:46:06 -04:00
|
|
|
{
|
2011-04-07 16:09:32 -04:00
|
|
|
void *ref = _ref_entries[row].first ;
|
2010-01-30 15:47:34 -05:00
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
return createIndex(row, column, ref);
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *details = requestDirDetails(ref, RemoteMode);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!details)
|
2010-01-30 15:47:34 -05:00
|
|
|
{
|
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
|
|
|
|
2014-01-04 17:39:34 -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
|
2014-01-04 17:39:34 -05: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
|
|
|
|
|
|
|
#endif
|
2014-01-04 17:39:34 -05:00
|
|
|
return createIndex(details->prow, 0, 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();
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *details = requestDirDetails(ref, RemoteMode);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!details)
|
2010-01-30 15:47:34 -05:00
|
|
|
return Qt::ItemIsSelectable; // Error.
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
switch(details->type)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-10-28 13:26:00 -04:00
|
|
|
case DIR_TYPE_PERSON: return Qt::ItemIsEnabled;
|
|
|
|
case DIR_TYPE_DIR: return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
|
|
|
case DIR_TYPE_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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Callback from */
|
2014-01-05 17:51:54 -05:00
|
|
|
void RetroshareDirModel::preMods()
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback from */
|
|
|
|
void RetroshareDirModel::postMods()
|
|
|
|
{
|
|
|
|
emit layoutAboutToBeChanged();
|
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
|
|
|
|
|
|
|
// QModelIndexList piList = persistentIndexList();
|
|
|
|
// QModelIndexList empty;
|
2014-10-21 18:33:02 -04:00
|
|
|
// for (int i = 0; i < piList.size(); ++i) {
|
2014-01-05 17:51:54 -05:00
|
|
|
// empty.append(QModelIndex());
|
|
|
|
// }
|
|
|
|
// changePersistentIndexList(piList, empty);
|
2014-01-04 17:39:34 -05:00
|
|
|
|
|
|
|
/* Clear caches */
|
|
|
|
mCache.clear();
|
2007-11-14 22:18:48 -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
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetailsVector *RetroshareDirModel::requestDirDetails(void *ref, bool remote) const
|
2011-04-03 15:59:12 -04:00
|
|
|
{
|
2014-01-04 17:39:34 -05:00
|
|
|
const QMap<void*, DirDetailsVector>::const_iterator it = mCache.constFind(ref);
|
|
|
|
if (it != mCache.constEnd()) {
|
|
|
|
/* Details found in cache */
|
|
|
|
return &it.value();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get details from the lib */
|
|
|
|
DirDetailsVector details;
|
|
|
|
FileSearchFlags flags = (remote) ? RS_FILE_HINTS_REMOTE : RS_FILE_HINTS_LOCAL;
|
|
|
|
if (rsFiles->RequestDirDetails(ref, details, flags)) {
|
|
|
|
/* Convert std::list to std::vector for fast access with index */
|
|
|
|
std::list<DirStub>::const_iterator childIt;
|
|
|
|
for (childIt = details.children.begin(); childIt != details.children.end(); ++childIt) {
|
|
|
|
details.childrenVector.push_back(*childIt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add to cache, must cast to none const */
|
|
|
|
const QMap<void*, DirDetailsVector>::iterator it1 = ((QMap<void*, DirDetailsVector>*) &mCache)->insert(ref, details);
|
|
|
|
return &it1.value();
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
/* No details found */
|
|
|
|
return NULL;
|
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);
|
|
|
|
|
2014-05-29 10:49:45 -04:00
|
|
|
RsCollectionFile(dirVec).openNewColl(parent);
|
2011-11-07 18:07:25 -05:00
|
|
|
}
|
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
void RetroshareDirModel::downloadSelected(const QModelIndexList &list)
|
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);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* Fire off requests */
|
2009-05-18 10:23:55 -04:00
|
|
|
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)
|
|
|
|
{
|
2011-04-01 17:46:06 -04:00
|
|
|
std::cerr << "RetroshareDirModel::downloadSelected() Calling File Request";
|
2009-05-18 10:23:55 -04:00
|
|
|
std::cerr << std::endl;
|
2014-03-17 16:56:06 -04:00
|
|
|
std::list<RsPeerId> srcIds;
|
2009-05-18 10:23:55 -04:00
|
|
|
srcIds.push_back(details.id);
|
|
|
|
rsFiles -> FileRequest(details.name, details.hash,
|
2012-11-02 09:52:29 -04:00
|
|
|
details.count, "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds);
|
2009-05-18 10:23:55 -04:00
|
|
|
}
|
|
|
|
/* if it is a dir, copy all files included*/
|
|
|
|
else if (details.type == DIR_TYPE_DIR)
|
|
|
|
{
|
2009-07-26 11:00:29 -04:00
|
|
|
int prefixLen = details.path.rfind(details.name);
|
2009-07-17 16:07:43 -04:00
|
|
|
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;
|
|
|
|
|
2014-10-21 18:33:02 -04:00
|
|
|
for (it = dirDetails.children.begin(); it != dirDetails.children.end(); ++it)
|
2009-07-17 16:07:43 -04:00
|
|
|
{
|
|
|
|
if (!it->ref) continue;
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *subDirDetails = requestDirDetails(it->ref, true);
|
2009-07-17 16:07:43 -04:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!subDirDetails) continue;
|
2009-07-17 16:07:43 -04:00
|
|
|
|
2014-01-04 17:39:34 -05: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
|
|
|
{
|
|
|
|
dirVec.clear();
|
2009-02-02 15:46:30 -05:00
|
|
|
|
2009-05-18 10:23:55 -04:00
|
|
|
/* Fire off requests */
|
2010-11-20 09:50:14 -05:00
|
|
|
QModelIndexList::const_iterator it;
|
2014-10-21 18:33:02 -04:00
|
|
|
for(it = list.begin(); it != list.end(); ++it)
|
2009-05-18 10:23:55 -04:00
|
|
|
{
|
|
|
|
if(it->column()==1)
|
|
|
|
{
|
|
|
|
void *ref = it -> internalPointer();
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *details = requestDirDetails(ref, RemoteMode);
|
2009-05-18 10:23:55 -04:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!details)
|
2009-05-18 10:23:55 -04:00
|
|
|
continue;
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
dirVec.push_back(*details);
|
2009-05-18 10:23:55 -04:00
|
|
|
}
|
|
|
|
}
|
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)
|
2010-01-31 09:21:24 -05:00
|
|
|
if(it->column()==0)
|
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
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *details = requestDirDetails(ref, RemoteMode);
|
2010-01-31 09:21:24 -05:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!details)
|
2010-01-31 09:21:24 -05:00
|
|
|
continue;
|
|
|
|
|
2014-01-04 17:39:34 -05: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;
|
2014-01-04 17:39:34 -05: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
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
if(already_in.find(details->hash.toStdString()+details->name) == already_in.end())
|
2010-01-31 09:21:24 -05:00
|
|
|
{
|
2014-01-04 17:39:34 -05:00
|
|
|
file_details.push_back(*details) ;
|
2014-03-17 16:56:06 -04:00
|
|
|
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<std::string> dirs_to_open;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2010-11-20 09:50:14 -05:00
|
|
|
std::string path, name;
|
|
|
|
rsFiles->ConvertSharedFilePath((*it).path, path);
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2010-11-20 09:50:14 -05:00
|
|
|
QDir dir(QString::fromUtf8(path.c_str()));
|
|
|
|
QString dest;
|
2009-07-07 14:56:31 -04:00
|
|
|
if ((*it).type & DIR_TYPE_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
|
|
|
|
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
|
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 */
|
2010-11-20 09:50:14 -05:00
|
|
|
QModelIndexList::const_iterator it;
|
2014-10-21 18:33:02 -04:00
|
|
|
for(it = list.begin(); it != list.end(); ++it)
|
2008-03-31 14:37:50 -04:00
|
|
|
{
|
|
|
|
void *ref = it -> internalPointer();
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *details = requestDirDetails(ref, false);
|
2008-03-31 14:37:50 -04:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!details)
|
2008-03-31 14:37:50 -04:00
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2008-03-31 14:37:50 -04:00
|
|
|
std::cerr << "getFilePaths() Bad Request" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2008-03-31 14:37:50 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (details->type != DIR_TYPE_FILE)
|
2008-03-31 14:37:50 -04:00
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2008-03-31 14:37:50 -04:00
|
|
|
std::cerr << "getFilePaths() Not File" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2008-03-31 14:37:50 -04:00
|
|
|
continue; /* not file! */
|
|
|
|
}
|
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2008-03-31 14:37:50 -04:00
|
|
|
std::cerr << "::::::::::::File Details:::: " << std::endl;
|
2014-01-04 17:39:34 -05: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-03-31 14:37:50 -04:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
std::string filepath = details->path + "/";
|
|
|
|
filepath += details->name;
|
2008-03-31 14:37:50 -04:00
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2008-03-31 14:37:50 -04:00
|
|
|
std::cerr << "Constructed FilePath: " << filepath << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2008-03-31 14:37:50 -04:00
|
|
|
if (fullpaths.end() == std::find(fullpaths.begin(), fullpaths.end(), filepath))
|
|
|
|
{
|
|
|
|
fullpaths.push_back(filepath);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *details = requestDirDetails(ref, RemoteMode);
|
2008-07-04 10:41:24 -04:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (!details)
|
2008-07-04 10:41:24 -04:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2008-07-04 10:41:24 -04:00
|
|
|
std::cerr << "::::::::::::FileDrag:::: " << std::endl;
|
2014-01-04 17:39:34 -05: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
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (details->type != DIR_TYPE_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! */
|
|
|
|
}
|
|
|
|
|
2014-01-04 17:39:34 -05: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 */
|
|
|
|
}
|
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
drags[details->hash] = details->count;
|
2008-07-04 10:41:24 -04:00
|
|
|
|
2014-03-17 16:56:06 -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
|
|
|
|
|
|
|
FlatStyle_RDM::~FlatStyle_RDM()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeStyle_RDM::~TreeStyle_RDM()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void FlatStyle_RDM::postMods()
|
|
|
|
{
|
2011-04-14 17:58:15 -04:00
|
|
|
if(visible())
|
|
|
|
{
|
|
|
|
_ref_entries.clear() ;
|
|
|
|
_ref_stack.clear() ;
|
2011-04-01 17:46:06 -04:00
|
|
|
|
2011-04-14 17:58:15 -04:00
|
|
|
_ref_stack.push_back(NULL) ; // init the stack with the topmost parent directory
|
|
|
|
|
|
|
|
std::cerr << "FlatStyle_RDM::postMods(): cleared ref entries" << std::endl;
|
|
|
|
_needs_update = false ;
|
|
|
|
updateRefs() ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_needs_update = true ;
|
2011-04-09 15:43:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void FlatStyle_RDM::updateRefs()
|
|
|
|
{
|
2011-04-14 17:58:15 -04:00
|
|
|
if(RsAutoUpdatePage::eventsLocked())
|
|
|
|
{
|
|
|
|
_needs_update = true ;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2011-04-09 15:43:09 -04:00
|
|
|
RetroshareDirModel::preMods() ;
|
2011-04-01 17:46:06 -04:00
|
|
|
|
2011-04-09 15:43:09 -04:00
|
|
|
static const uint32_t MAX_REFS_PER_SECOND = 2000 ;
|
|
|
|
uint32_t nb_treated_refs = 0 ;
|
2011-04-01 17:46:06 -04:00
|
|
|
|
2011-04-09 15:43:09 -04:00
|
|
|
while(!_ref_stack.empty())
|
2011-04-01 17:46:06 -04:00
|
|
|
{
|
2011-04-09 15:43:09 -04:00
|
|
|
void *ref = _ref_stack.back() ;
|
2011-04-01 17:46:06 -04:00
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "FlatStyle_RDM::postMods(): poped ref " << ref << std::endl;
|
|
|
|
#endif
|
2011-04-09 15:43:09 -04:00
|
|
|
_ref_stack.pop_back() ;
|
2014-01-04 17:39:34 -05:00
|
|
|
const DirDetails *details = requestDirDetails(ref, RemoteMode) ;
|
2011-04-01 17:46:06 -04:00
|
|
|
|
2014-01-04 17:39:34 -05:00
|
|
|
if (details)
|
2011-04-01 17:46:06 -04:00
|
|
|
{
|
2014-01-04 17:39:34 -05:00
|
|
|
if(details->type == DIR_TYPE_FILE) // only push files, not directories nor persons.
|
|
|
|
_ref_entries.push_back(std::pair<void*,QString>(ref,computeDirectoryPath(*details)));
|
2011-04-01 17:46:06 -04:00
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "FlatStyle_RDM::postMods(): addign ref " << ref << std::endl;
|
|
|
|
#endif
|
2014-10-21 18:33:02 -04:00
|
|
|
for(std::list<DirStub>::const_iterator it = details->children.begin(); it != details->children.end(); ++it)
|
2011-04-09 15:43:09 -04:00
|
|
|
_ref_stack.push_back(it->ref) ;
|
|
|
|
}
|
|
|
|
if(++nb_treated_refs > 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.
|
2011-04-14 17:58:15 -04:00
|
|
|
_needs_update = true ;
|
|
|
|
|
|
|
|
if(visible())
|
|
|
|
QTimer::singleShot(2000,this,SLOT(updateRefs())) ;
|
|
|
|
else
|
|
|
|
std::cerr << "Not visible: suspending update"<< std::endl;
|
2011-04-09 15:43:09 -04:00
|
|
|
break ;
|
2011-04-01 17:46:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cerr << "reference tab contains " << _ref_entries.size() << " files" << std::endl;
|
|
|
|
|
2011-04-14 17:58:15 -04:00
|
|
|
if(_ref_stack.empty())
|
|
|
|
_needs_update = false ;
|
|
|
|
|
2011-04-01 17:46:06 -04:00
|
|
|
RetroshareDirModel::postMods() ;
|
|
|
|
}
|
|
|
|
|