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 <QDesktopServices>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QMimeData>
|
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>
|
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>
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <sstream>
|
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
|
|
|
|
****/
|
|
|
|
|
2008-07-04 10:41:24 -04:00
|
|
|
RemoteDirModel::RemoteDirModel(bool mode, QObject *parent)
|
|
|
|
: 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
|
|
|
{
|
|
|
|
setSupportedDragActions(Qt::CopyAction);
|
2009-10-13 16:36:29 -04:00
|
|
|
treeStyle();
|
2008-07-04 10:41:24 -04:00
|
|
|
}
|
|
|
|
|
2009-05-31 19:06:14 -04:00
|
|
|
void RemoteDirModel::treeStyle()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
bool RemoteDirModel::hasChildren(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "RemoteDirModel::hasChildren() :" << parent.internalPointer();
|
|
|
|
std::cerr << ": ";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!parent.isValid())
|
|
|
|
{
|
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "root -> true ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *ref = parent.internalPointer();
|
|
|
|
|
|
|
|
DirDetails details;
|
|
|
|
uint32_t flags = DIR_FLAGS_CHILDREN;
|
|
|
|
if (RemoteMode)
|
|
|
|
flags |= DIR_FLAGS_REMOTE;
|
|
|
|
else
|
|
|
|
flags |= DIR_FLAGS_LOCAL;
|
|
|
|
|
2008-07-02 12:59:56 -04:00
|
|
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/* error */
|
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "lookup failed -> false";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-07 14:56:31 -04:00
|
|
|
|
|
|
|
if (details.type == DIR_TYPE_FILE)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "lookup FILE -> false";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* PERSON/DIR*/
|
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "lookup PER/DIR #" << details.count;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
return (details.count > 0); /* do we have children? */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int RemoteDirModel::rowCount(const QModelIndex &parent) const
|
|
|
|
{
|
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "RemoteDirModel::rowCount(): " << parent.internalPointer();
|
|
|
|
std::cerr << ": ";
|
|
|
|
#endif
|
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
void *ref = (parent.isValid())? parent.internalPointer() : NULL ;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
DirDetails details;
|
|
|
|
uint32_t flags = DIR_FLAGS_CHILDREN;
|
|
|
|
if (RemoteMode)
|
|
|
|
flags |= DIR_FLAGS_REMOTE;
|
|
|
|
else
|
|
|
|
flags |= DIR_FLAGS_LOCAL;
|
|
|
|
|
2008-07-02 12:59:56 -04:00
|
|
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "lookup failed -> 0";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (details.type == DIR_TYPE_FILE)
|
|
|
|
{
|
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "lookup FILE: 0";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* else PERSON/DIR*/
|
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "lookup PER/DIR #" << details.count;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
return details.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int RemoteDirModel::columnCount(const QModelIndex &parent) const
|
|
|
|
{
|
2009-10-13 16:36:29 -04:00
|
|
|
return 5;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-08-10 14:55:49 -04:00
|
|
|
QString RemoteDirModel::getFlagsString(uint32_t flags)
|
|
|
|
{
|
|
|
|
switch(flags & (DIR_FLAGS_NETWORK_WIDE|DIR_FLAGS_BROWSABLE))
|
|
|
|
{
|
|
|
|
case DIR_FLAGS_NETWORK_WIDE: return QString("Anonymous") ;
|
|
|
|
case DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE: return QString("Anonymous and browsable by friends") ;
|
|
|
|
case DIR_FLAGS_BROWSABLE: return QString("Only browsable by friends") ;
|
|
|
|
default:
|
|
|
|
return QString() ;
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-13 16:36:29 -04:00
|
|
|
QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
|
|
|
{
|
|
|
|
QString ret("");
|
|
|
|
QString nind("NEW");
|
|
|
|
QString oind("OLD");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
QVariant RemoteDirModel::data(const QModelIndex &index, int role) const
|
|
|
|
{
|
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "RemoteDirModel::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();
|
2009-07-07 14:56:31 -04:00
|
|
|
int coln = index.column();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
DirDetails details;
|
|
|
|
uint32_t flags = DIR_FLAGS_DETAILS;
|
|
|
|
if (RemoteMode)
|
|
|
|
flags |= DIR_FLAGS_REMOTE;
|
|
|
|
else
|
|
|
|
flags |= DIR_FLAGS_LOCAL;
|
|
|
|
|
2009-10-13 16:36:29 -04:00
|
|
|
|
2008-07-02 12:59:56 -04:00
|
|
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
2009-04-07 04:08:03 -04:00
|
|
|
if (role == RemoteDirModel::FileNameRole)
|
|
|
|
{
|
|
|
|
FileInfo finfo;
|
|
|
|
rsFiles->FileDetails(details.hash, 0, finfo);
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2009-04-07 04:08:03 -04:00
|
|
|
return QString::fromStdString(finfo.path) ;
|
2010-06-12 14:10:39 -04:00
|
|
|
} /* end of FileNameRole */
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2010-02-08 17:32:00 -05:00
|
|
|
if (role == Qt::TextColorRole)
|
|
|
|
{
|
|
|
|
FileInfo finfo;
|
|
|
|
rsFiles->FileDetails(details.hash, 0, finfo);
|
|
|
|
|
2010-06-12 14:10:39 -04:00
|
|
|
if(details.min_age > ageIndicator)
|
|
|
|
return Qt::gray ;
|
|
|
|
else
|
|
|
|
return Qt::black ;
|
|
|
|
} /* end of TextColorRole */
|
2010-02-08 17:32:00 -05:00
|
|
|
|
|
|
|
|
2010-06-12 14:10:39 -04:00
|
|
|
if (role == Qt::DecorationRole)
|
|
|
|
{
|
|
|
|
FileInfo finfo;
|
|
|
|
rsFiles->FileDetails(details.hash, 0, finfo);
|
2010-02-09 10:05:08 -05:00
|
|
|
|
2010-06-12 14:10:39 -04:00
|
|
|
if (details.type == DIR_TYPE_PERSON)
|
|
|
|
{
|
|
|
|
switch(coln)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
break;
|
2009-08-10 14:55:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (details.type == DIR_TYPE_DIR)
|
|
|
|
{
|
2010-06-12 14:10:39 -04:00
|
|
|
switch(coln)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
break;
|
2009-08-10 14:55:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (details.type == DIR_TYPE_FILE) /* File */
|
|
|
|
{
|
|
|
|
// extensions predefined
|
|
|
|
switch(coln)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
QString ext = QFileInfo(QString::fromStdString(details.name)).suffix();
|
|
|
|
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif"
|
|
|
|
|| ext == "bmp" || ext == "ico" || ext == "svg")
|
|
|
|
{
|
|
|
|
QIcon icon(":/images/FileTypePicture.png");
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
else if (ext == "avi" || ext == "AVI" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "ogm"
|
|
|
|
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov"
|
|
|
|
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp")
|
|
|
|
{
|
|
|
|
QIcon icon(":/images/FileTypeVideo.png");
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma" || ext == "xpm")
|
|
|
|
{
|
|
|
|
QIcon icon(":/images/FileTypeAudio.png");
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z"
|
|
|
|
|| ext == "rar" || ext == "rpm" || ext == "deb")
|
|
|
|
{
|
|
|
|
QIcon icon(":/images/FileTypeArchive.png");
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com"
|
|
|
|
|| ext == "bin" || ext == "exe" || ext == "js" || ext == "pif"
|
|
|
|
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
|
|
|
|
{
|
|
|
|
return(QIcon(":/images/FileTypeProgram.png"));
|
|
|
|
}
|
|
|
|
else if (ext == "iso" || ext == "nrg" || ext == "mdf" )
|
|
|
|
{
|
|
|
|
QIcon icon(":/images/FileTypeCDImage.png");
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
|
|
|
|
{
|
|
|
|
QIcon icon(":/images/FileTypeDocument.png");
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|
|
|
|
|| ext == "sxc" || ext == "odt" || ext == "ods")
|
|
|
|
{
|
|
|
|
QIcon icon(":/images/FileTypeDocument.png");
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
else if (ext == "html" || ext == "htm" || ext == "php")
|
|
|
|
{
|
|
|
|
QIcon icon(":/images/FileTypeDocument.png");
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QIcon icon(":/images/FileTypeAny.png");
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QVariant();
|
|
|
|
}
|
2010-06-12 14:10:39 -04:00
|
|
|
} /* end of DecorationRole */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-12 14:10:39 -04:00
|
|
|
/*****************
|
2007-11-14 22:18:48 -05:00
|
|
|
Qt::EditRole
|
|
|
|
Qt::ToolTipRole
|
|
|
|
Qt::StatusTipRole
|
|
|
|
Qt::WhatsThisRole
|
|
|
|
Qt::SizeHintRole
|
|
|
|
****************/
|
2010-06-12 14:10:39 -04:00
|
|
|
|
|
|
|
if (role == Qt::SizeHintRole)
|
|
|
|
{
|
|
|
|
return QSize(18, 18);
|
|
|
|
} /* end of SizeHintRole */
|
|
|
|
|
|
|
|
if (role == Qt::TextAlignmentRole)
|
|
|
|
{
|
|
|
|
if(coln == 1)
|
|
|
|
{
|
|
|
|
return int( Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
}
|
|
|
|
} /* end of TextAlignmentRole */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-12 14:10:39 -04:00
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
{
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-12 14:10:39 -04:00
|
|
|
/*
|
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:
|
2010-01-30 15:47:34 -05:00
|
|
|
return QString::fromStdString(details.name);
|
|
|
|
break;
|
2007-11-14 22:18:48 -05:00
|
|
|
case 1:
|
2010-01-30 15:47:34 -05:00
|
|
|
return QString() ;
|
|
|
|
break;
|
2007-11-14 22:18:48 -05:00
|
|
|
default:
|
2010-01-30 15:47:34 -05:00
|
|
|
return QString() ;
|
|
|
|
break;
|
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());
|
|
|
|
break;
|
2007-11-14 22:18:48 -05:00
|
|
|
case 1:
|
2010-01-30 15:47:34 -05:00
|
|
|
{
|
2010-06-12 14:10:39 -04:00
|
|
|
std::ostringstream out;
|
|
|
|
return misc::friendlyUnit(details.count);
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
break;
|
|
|
|
case 2:
|
2010-06-12 14:10:39 -04:00
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
return misc::userFriendlyDuration(details.age);
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
break;
|
|
|
|
case 3:
|
2010-06-12 14:10:39 -04:00
|
|
|
{
|
|
|
|
return getFlagsString(details.flags);
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
break;
|
2009-10-13 16:36:29 -04:00
|
|
|
case 4:
|
2010-06-12 14:10:39 -04:00
|
|
|
{
|
|
|
|
QString ind("");
|
|
|
|
if (ageIndicator != IND_ALWAYS)
|
|
|
|
ind = getAgeIndicatorString(details);
|
|
|
|
return ind;
|
|
|
|
}
|
2009-10-13 16:36:29 -04:00
|
|
|
break;
|
2007-11-14 22:18:48 -05:00
|
|
|
default:
|
2010-06-12 14:10:39 -04:00
|
|
|
return QString(tr("FILE"));
|
2007-11-14 22:18:48 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (details.type == DIR_TYPE_DIR) /* Dir */
|
|
|
|
{
|
|
|
|
switch(coln)
|
|
|
|
{
|
|
|
|
case 0:
|
2010-02-04 11:54:59 -05: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:
|
2009-08-10 14:55:49 -04:00
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << details.count;
|
2010-03-25 12:18:22 -04:00
|
|
|
if (details.count > 1)
|
|
|
|
{
|
2010-06-12 14:10:39 -04:00
|
|
|
return QString::fromStdString(out.str()) + " " + tr("Files");
|
2010-03-25 12:18:22 -04:00
|
|
|
}
|
|
|
|
else
|
2010-06-12 14:10:39 -04:00
|
|
|
return QString::fromStdString(out.str()) + " " + tr("File");
|
2009-08-10 14:55:49 -04:00
|
|
|
}
|
|
|
|
break;
|
2007-11-14 22:18:48 -05:00
|
|
|
case 2:
|
2010-03-24 14:22:58 -04:00
|
|
|
return misc::userFriendlyDuration(details.min_age);
|
2009-08-10 14:55:49 -04:00
|
|
|
break;
|
2009-10-13 16:36:29 -04:00
|
|
|
case 3:
|
2010-02-04 11:54:59 -05:00
|
|
|
return getFlagsString(details.flags);
|
2009-08-10 19:11:17 -04:00
|
|
|
break;
|
2007-11-14 22:18:48 -05:00
|
|
|
default:
|
2009-08-10 14:55:49 -04:00
|
|
|
return QString(tr("DIR"));
|
|
|
|
break;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* end of DisplayRole */
|
|
|
|
return QVariant();
|
2008-11-18 17:59:33 -05:00
|
|
|
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2010-06-12 14:10:39 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-10-13 16:36:29 -04:00
|
|
|
void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const {
|
|
|
|
if (details.type == DIR_TYPE_FILE) {
|
|
|
|
ret = getAgeIndicatorString(details);
|
|
|
|
return;
|
|
|
|
} else if (details.type == DIR_TYPE_DIR && ret == tr("")) {
|
|
|
|
std::list<DirStub>::iterator it;
|
|
|
|
for (it = details.children.begin(); it != details.children.end(); it++) {
|
|
|
|
void *ref = it->ref;
|
|
|
|
DirDetails childDetails;
|
|
|
|
uint32_t flags;
|
|
|
|
|
|
|
|
if (RemoteMode)
|
|
|
|
flags |= DIR_FLAGS_REMOTE;
|
|
|
|
else
|
|
|
|
flags |= DIR_FLAGS_LOCAL;
|
|
|
|
|
|
|
|
if (rsFiles->RequestDirDetails(ref, childDetails, flags) && ret == tr(""))
|
|
|
|
getAgeIndicatorRec(childDetails, ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-18 17:59:33 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
QVariant RemoteDirModel::headerData(int section, Qt::Orientation orientation,
|
|
|
|
int role) const
|
2009-08-10 14:55:49 -04:00
|
|
|
{
|
|
|
|
if (role == Qt::SizeHintRole)
|
|
|
|
{
|
|
|
|
int defw = 50;
|
|
|
|
int defh = 21;
|
|
|
|
if (section < 2)
|
|
|
|
{
|
|
|
|
defw = 200;
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
return QString(tr("Friends Directories"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QString(tr("My Directories"));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return QString(tr("Size"));
|
|
|
|
break;
|
|
|
|
case 2:
|
2010-02-04 11:54:59 -05:00
|
|
|
return QString(tr("Age"));
|
2009-08-10 14:55:49 -04:00
|
|
|
break;
|
|
|
|
case 3:
|
2010-02-04 11:54:59 -05:00
|
|
|
return QString(tr("Share Type"));
|
2009-08-10 14:55:49 -04:00
|
|
|
break;
|
2009-10-13 16:36:29 -04:00
|
|
|
case 4:
|
|
|
|
return QString(tr("What's new"));
|
|
|
|
break;
|
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
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
QModelIndex RemoteDirModel::index(int row, int column, const QModelIndex & parent) const
|
|
|
|
{
|
2007-11-14 22:18:48 -05:00
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "RemoteDirModel::index(): " << parent.internalPointer();
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
********/
|
|
|
|
|
|
|
|
DirDetails details;
|
|
|
|
uint32_t flags = DIR_FLAGS_CHILDREN;
|
|
|
|
if (RemoteMode)
|
|
|
|
flags |= DIR_FLAGS_REMOTE;
|
|
|
|
else
|
|
|
|
flags |= DIR_FLAGS_LOCAL;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
|
|
|
{
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
std::list<DirStub>::iterator it;
|
|
|
|
int i = 0;
|
2010-02-08 17:32:00 -05:00
|
|
|
for(it = details.children.begin(); ((i < row) && (it != details.children.end())); ++it,++i) ;
|
|
|
|
|
2009-07-07 14:56:31 -04:00
|
|
|
if (it == details.children.end())
|
|
|
|
{
|
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
|
2010-01-30 15:47:34 -05:00
|
|
|
std::cerr << "success index(" << row << "," << column << "," << it->ref << ")";
|
|
|
|
std::cerr << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* we can just grab the reference now */
|
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
return createIndex(row, column, it->ref);
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
|
|
|
|
QModelIndex RemoteDirModel::parent( const QModelIndex & index ) const
|
|
|
|
{
|
2007-11-14 22:18:48 -05:00
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "RemoteDirModel::parent(): " << index.internalPointer();
|
|
|
|
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();
|
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
DirDetails details;
|
|
|
|
uint32_t flags = (RemoteMode)?DIR_FLAGS_REMOTE:DIR_FLAGS_LOCAL;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
|
|
|
{
|
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
|
|
|
|
|
|
|
if (!(details.parent))
|
|
|
|
{
|
|
|
|
#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
|
2010-01-30 15:47:34 -05:00
|
|
|
std::cerr << "success index(" << details.prow << ",0," << details.parent << ")";
|
|
|
|
std::cerr << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
return createIndex(details.prow, 0, details.parent);
|
2010-01-30 15:47:34 -05:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
|
|
|
|
{
|
2007-11-14 22:18:48 -05:00
|
|
|
#ifdef RDM_DEBUG
|
2010-01-30 15:47:34 -05:00
|
|
|
std::cerr << "RemoteDirModel::flags()";
|
|
|
|
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();
|
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
DirDetails details;
|
|
|
|
uint32_t flags = DIR_FLAGS_DETAILS;
|
|
|
|
if (RemoteMode)
|
|
|
|
flags |= DIR_FLAGS_REMOTE;
|
|
|
|
else
|
|
|
|
flags |= DIR_FLAGS_LOCAL;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
|
|
|
return Qt::ItemIsSelectable; // Error.
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-30 15:47:34 -05:00
|
|
|
switch(details.type)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-01-30 15:47:34 -05:00
|
|
|
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;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The other flags...
|
|
|
|
//Qt::ItemIsUserCheckable
|
|
|
|
//Qt::ItemIsEditable
|
|
|
|
//Qt::ItemIsDropEnabled
|
|
|
|
//Qt::ItemIsTristate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Callback from */
|
|
|
|
void RemoteDirModel::preMods()
|
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "RemoteDirModel::preMods()" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
//modelAboutToBeReset();
|
2009-08-11 15:43:51 -04:00
|
|
|
// reset();
|
2007-11-14 22:18:48 -05:00
|
|
|
layoutAboutToBeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback from */
|
|
|
|
void RemoteDirModel::postMods()
|
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "RemoteDirModel::postMods()" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
//modelReset();
|
|
|
|
layoutChanged();
|
|
|
|
//reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-08 17:32:00 -05:00
|
|
|
//void RemoteDirModel::update (const QModelIndex &index )
|
|
|
|
//{
|
|
|
|
//#ifdef RDM_DEBUG
|
|
|
|
// //std::cerr << "Directory Request(" << id << ") : ";
|
|
|
|
// //std::cerr << path << std::endl;
|
|
|
|
//#endif
|
|
|
|
// //rsFiles -> RequestDirectories(id, path, 1);
|
|
|
|
//}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
void RemoteDirModel::downloadSelected(QModelIndexList list)
|
|
|
|
{
|
|
|
|
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
|
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)
|
|
|
|
{
|
|
|
|
std::cerr << "RemoteDirModel::downloadSelected() Calling File Request";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::list<std::string> srcIds;
|
|
|
|
srcIds.push_back(details.id);
|
|
|
|
rsFiles -> FileRequest(details.name, details.hash,
|
2010-01-26 15:40:21 -05:00
|
|
|
details.count, "", RS_FILE_HINTS_NETWORK_WIDE, 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 */
|
|
|
|
void RemoteDirModel::downloadDirectory(const DirDetails & dirDetails, int prefixLen)
|
|
|
|
{
|
|
|
|
if (dirDetails.type & DIR_TYPE_FILE)
|
|
|
|
{
|
|
|
|
std::list<std::string> srcIds;
|
|
|
|
QString cleanPath = QDir::cleanPath((rsFiles->getDownloadDirectory() + "/" + dirDetails.path.substr(prefixLen)).c_str());
|
|
|
|
|
|
|
|
srcIds.push_back(dirDetails.id);
|
2010-01-26 15:40:21 -05:00
|
|
|
rsFiles->FileRequest(dirDetails.name, dirDetails.hash, dirDetails.count, cleanPath.toStdString(), RS_FILE_HINTS_NETWORK_WIDE, srcIds);
|
2009-07-17 16:07:43 -04:00
|
|
|
}
|
|
|
|
else if (dirDetails.type & DIR_TYPE_DIR)
|
|
|
|
{
|
|
|
|
std::list<DirStub>::const_iterator it;
|
|
|
|
QDir dwlDir(rsFiles->getDownloadDirectory().c_str());
|
|
|
|
QString cleanPath = QDir::cleanPath(QString(dirDetails.path.c_str()).right(dirDetails.path.length() - prefixLen));
|
|
|
|
|
|
|
|
if (!dwlDir.mkpath(cleanPath)) return;
|
|
|
|
|
|
|
|
for (it = dirDetails.children.begin(); it != dirDetails.children.end(); it++)
|
|
|
|
{
|
|
|
|
if (!it->ref) continue;
|
|
|
|
|
|
|
|
DirDetails subDirDetails;
|
|
|
|
uint32_t flags = DIR_FLAGS_CHILDREN | DIR_FLAGS_REMOTE;
|
|
|
|
|
|
|
|
if (!rsFiles->RequestDirDetails(it->ref, subDirDetails, flags)) continue;
|
|
|
|
|
|
|
|
downloadDirectory(subDirDetails, prefixLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-18 10:23:55 -04:00
|
|
|
void RemoteDirModel::getDirDetailsFromSelect (QModelIndexList list, std::vector <DirDetails>& dirVec)
|
|
|
|
{
|
|
|
|
dirVec.clear();
|
2009-02-02 15:46:30 -05:00
|
|
|
|
2009-05-18 10:23:55 -04:00
|
|
|
/* Fire off requests */
|
|
|
|
QModelIndexList::iterator it;
|
|
|
|
for(it = list.begin(); it != list.end(); it++)
|
|
|
|
{
|
|
|
|
if(it->column()==1)
|
|
|
|
{
|
|
|
|
void *ref = it -> internalPointer();
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
dirVec.push_back(details);
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2008-07-02 12:59:56 -04:00
|
|
|
/****************************************************************************
|
|
|
|
* OLD RECOMMEND SYSTEM - DISABLED
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-05-17 15:38:42 -04:00
|
|
|
void RemoteDirModel::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
|
|
|
|
2010-01-31 09:21:24 -05:00
|
|
|
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))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(details.type == DIR_TYPE_PERSON)
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
2010-01-31 09:21:24 -05:00
|
|
|
if(already_in.find(details.hash+details.name) == already_in.end())
|
|
|
|
{
|
|
|
|
file_details.push_back(details) ;
|
|
|
|
already_in.insert(details.hash+details.name) ;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-05-17 15:38:42 -04:00
|
|
|
#if 0
|
2007-11-14 22:18:48 -05:00
|
|
|
void RemoteDirModel::recommendSelectedOnly(QModelIndexList list)
|
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "recommendSelectedOnly()" << 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
|
|
|
}
|
2008-07-02 12:59:56 -04:00
|
|
|
rsFiles->ClearInRecommend();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* Fire off requests */
|
|
|
|
QModelIndexList::iterator it;
|
|
|
|
for(it = list.begin(); it != list.end(); it++)
|
|
|
|
{
|
|
|
|
void *ref = it -> internalPointer();
|
|
|
|
|
|
|
|
DirDetails details;
|
|
|
|
uint32_t flags = DIR_FLAGS_DETAILS;
|
|
|
|
if (RemoteMode)
|
|
|
|
{
|
|
|
|
flags |= DIR_FLAGS_REMOTE;
|
|
|
|
continue; /* don't recommend remote stuff */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
flags |= DIR_FLAGS_LOCAL;
|
|
|
|
}
|
|
|
|
|
2008-07-02 12:59:56 -04:00
|
|
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "::::::::::::FileRecommend:::: " << std::endl;
|
|
|
|
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
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-07-02 12:59:56 -04:00
|
|
|
rsFiles -> FileRecommend(details.name, details.hash, details.count);
|
|
|
|
rsFiles -> SetInRecommend(details.name, true);
|
2007-11-14 22:18:48 -05: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
|
|
|
#endif
|
2009-05-17 15:38:42 -04:00
|
|
|
|
2008-07-02 12:59:56 -04:00
|
|
|
/****************************************************************************
|
|
|
|
* OLD RECOMMEND SYSTEM - DISABLED
|
|
|
|
******/
|
|
|
|
|
2009-07-07 14:56:31 -04:00
|
|
|
void RemoteDirModel::openSelected(QModelIndexList qmil, bool openFolder)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-07 14:56:31 -04:00
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "RemoteDirModel::openSelected()" << std::endl;
|
|
|
|
#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);
|
|
|
|
|
2010-03-28 16:46:45 -04:00
|
|
|
for (it = files_info.begin(); it != files_info.end(); it++)
|
|
|
|
{
|
2009-07-07 14:56:31 -04:00
|
|
|
if ((*it).type & DIR_TYPE_PERSON) continue;
|
|
|
|
|
|
|
|
std::string fullpath, name;
|
|
|
|
rsFiles->ConvertSharedFilePath((*it).path, fullpath);
|
|
|
|
int len = fullpath.length();
|
|
|
|
if (len && (fullpath[len - 1] != '/')) fullpath += '/';
|
|
|
|
|
|
|
|
if ((*it).type & DIR_TYPE_FILE) {
|
|
|
|
name = fullpath + (*it).name;
|
|
|
|
} else if ((*it).type & DIR_TYPE_DIR) {
|
|
|
|
name = fullpath;
|
|
|
|
}
|
|
|
|
|
2010-03-28 16:46:45 -04:00
|
|
|
std::cerr << "Opennign this file: " << name << std::endl ;
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2010-03-28 16:46:45 -04:00
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromUtf8(name.c_str(),name.length())));
|
2009-07-07 14:56:31 -04:00
|
|
|
}
|
|
|
|
|
2010-03-28 16:46:45 -04:00
|
|
|
// if (openFolder) {
|
|
|
|
// std::list<std::string>::iterator dit;
|
|
|
|
// for (dit = dirs_to_open.begin(); dit != dirs_to_open.end(); dit++)
|
|
|
|
// {
|
|
|
|
// std::cerr << "Opennign this folder: " << (*dit).c_str() << std::endl ;
|
|
|
|
// QDesktopServices::openUrl(QUrl::fromLocalFile(QString::fromUtf8((*dit).c_str())));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2009-07-07 14:56:31 -04:00
|
|
|
#ifdef RDM_DEBUG
|
|
|
|
std::cerr << "::::::::::::Done RemoteDirModel::openSelected()" << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
2008-03-31 14:37:50 -04:00
|
|
|
|
|
|
|
void RemoteDirModel::getFilePaths(QModelIndexList list, std::list<std::string> &fullpaths)
|
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2008-03-31 14:37:50 -04:00
|
|
|
std::cerr << "RemoteDirModel::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 */
|
|
|
|
QModelIndexList::iterator it;
|
|
|
|
for(it = list.begin(); it != list.end(); it++)
|
|
|
|
{
|
|
|
|
void *ref = it -> internalPointer();
|
|
|
|
|
|
|
|
DirDetails details;
|
|
|
|
uint32_t flags = DIR_FLAGS_DETAILS;
|
|
|
|
flags |= DIR_FLAGS_LOCAL;
|
|
|
|
|
2008-07-02 12:59:56 -04:00
|
|
|
if (!rsFiles->RequestDirDetails(ref, details, flags))
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (details.type != DIR_TYPE_FILE)
|
|
|
|
{
|
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;
|
|
|
|
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
|
|
|
|
|
|
|
std::string filepath = details.path + "/";
|
|
|
|
filepath += details.name;
|
|
|
|
|
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 */
|
|
|
|
QMimeData * RemoteDirModel::mimeData ( const QModelIndexList & indexes ) const
|
|
|
|
{
|
|
|
|
/* extract from each the member text */
|
|
|
|
std::string text;
|
|
|
|
QModelIndexList::const_iterator it;
|
|
|
|
std::map<std::string, uint64_t> drags;
|
|
|
|
std::map<std::string, uint64_t>::iterator dit;
|
|
|
|
|
|
|
|
for(it = indexes.begin(); it != indexes.end(); it++)
|
|
|
|
{
|
|
|
|
void *ref = it -> internalPointer();
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
|
|
|
if (details.type != DIR_TYPE_FILE)
|
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2008-07-04 10:41:24 -04:00
|
|
|
std::cerr << "RemoteDirModel::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! */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drags.end() != (dit = drags.find(details.hash)))
|
|
|
|
{
|
2008-07-09 05:53:47 -04:00
|
|
|
#ifdef RDM_DEBUG
|
2008-07-04 10:41:24 -04:00
|
|
|
std::cerr << "RemoteDirModel::mimeData() Duplicate" << std::endl;
|
2008-07-09 05:53:47 -04:00
|
|
|
#endif
|
2008-07-04 10:41:24 -04:00
|
|
|
continue; /* duplicate */
|
|
|
|
}
|
|
|
|
|
|
|
|
drags[details.hash] = details.count;
|
|
|
|
|
|
|
|
std::string line = details.name;
|
|
|
|
line += "/";
|
|
|
|
line += details.hash;
|
|
|
|
line += "/";
|
|
|
|
|
|
|
|
{
|
|
|
|
std::ostringstream out;
|
|
|
|
out << details.count;
|
|
|
|
line += out.str();
|
|
|
|
line += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
std::cerr << text;
|
|
|
|
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();
|
|
|
|
data->setData("application/x-rsfilelist", QByteArray(text.c_str()));
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList RemoteDirModel::mimeTypes () const
|
|
|
|
{
|
|
|
|
QStringList list;
|
|
|
|
list.push_back("application/x-rsfilelist");
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2009-04-07 04:08:03 -04:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
bool
|
|
|
|
RemoteDirModel::isDir ( const QModelIndex & index ) const
|
|
|
|
{
|
|
|
|
//if (RemoteMode) // only local files can be opened
|
|
|
|
// return ;
|
|
|
|
void *ref = index.internalPointer();
|
|
|
|
if (!ref)
|
|
|
|
return false;
|
2009-07-07 14:56:31 -04:00
|
|
|
|
2009-04-07 04:08:03 -04:00
|
|
|
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 false;//not good, but....
|
|
|
|
}
|
|
|
|
|
2009-07-07 14:56:31 -04:00
|
|
|
return (details.type == DIR_TYPE_DIR) ;
|
2009-04-07 04:08:03 -04:00
|
|
|
}
|
2008-03-31 14:37:50 -04:00
|
|
|
|
2008-11-17 20:42:17 -05:00
|
|
|
|
|
|
|
|