mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-24 22:30:42 -04:00
Fixed calculation of the right QModelIndex for context menu. Indroduced with QSortFilterProxyModel.
Removed unnecessary calls to the librs in RemoveDirModel. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3708 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
741948acff
commit
162a949092
2 changed files with 48 additions and 97 deletions
|
@ -169,8 +169,8 @@ QString RemoteDirModel::getFlagsString(uint32_t flags)
|
||||||
QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
{
|
{
|
||||||
QString ret("");
|
QString ret("");
|
||||||
QString nind("NEW");
|
QString nind = tr("NEW");
|
||||||
QString oind("OLD");
|
// QString oind = tr("OLD");
|
||||||
uint32_t age = details.age;
|
uint32_t age = details.age;
|
||||||
|
|
||||||
switch (ageIndicator) {
|
switch (ageIndicator) {
|
||||||
|
@ -225,17 +225,11 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
|
|
||||||
if (role == RemoteDirModel::FileNameRole)
|
if (role == RemoteDirModel::FileNameRole)
|
||||||
{
|
{
|
||||||
FileInfo finfo;
|
return QString::fromUtf8(details.name.c_str());
|
||||||
rsFiles->FileDetails(details.hash, 0, finfo);
|
|
||||||
|
|
||||||
return QString::fromUtf8(finfo.path.c_str()) ;
|
|
||||||
} /* end of FileNameRole */
|
} /* end of FileNameRole */
|
||||||
|
|
||||||
if (role == Qt::TextColorRole)
|
if (role == Qt::TextColorRole)
|
||||||
{
|
{
|
||||||
FileInfo finfo;
|
|
||||||
rsFiles->FileDetails(details.hash, 0, finfo);
|
|
||||||
|
|
||||||
if(details.min_age > ageIndicator)
|
if(details.min_age > ageIndicator)
|
||||||
return Qt::gray ;
|
return Qt::gray ;
|
||||||
else
|
else
|
||||||
|
@ -245,9 +239,6 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
|
|
||||||
if (role == Qt::DecorationRole)
|
if (role == Qt::DecorationRole)
|
||||||
{
|
{
|
||||||
FileInfo finfo;
|
|
||||||
rsFiles->FileDetails(details.hash, 0, finfo);
|
|
||||||
|
|
||||||
if (details.type == DIR_TYPE_PERSON)
|
if (details.type == DIR_TYPE_PERSON)
|
||||||
{
|
{
|
||||||
switch(coln)
|
switch(coln)
|
||||||
|
@ -299,7 +290,7 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return(QIcon(categoryIcon));
|
return QIcon(categoryIcon);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -314,58 +305,49 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif"
|
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif"
|
||||||
|| ext == "bmp" || ext == "ico" || ext == "svg")
|
|| ext == "bmp" || ext == "ico" || ext == "svg")
|
||||||
{
|
{
|
||||||
QIcon icon(":/images/FileTypePicture.png");
|
return QIcon(":/images/FileTypePicture.png");
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
else if (ext == "avi" || ext == "AVI" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "ogm"
|
else if (ext == "avi" || ext == "AVI" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "ogm"
|
||||||
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov"
|
|| ext == "mkv" || ext == "mp4" || ext == "flv" || ext == "mov"
|
||||||
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp")
|
|| ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp")
|
||||||
{
|
{
|
||||||
QIcon icon(":/images/FileTypeVideo.png");
|
return QIcon(":/images/FileTypeVideo.png");
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma" || ext == "xpm")
|
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma" || ext == "xpm")
|
||||||
{
|
{
|
||||||
QIcon icon(":/images/FileTypeAudio.png");
|
return QIcon(":/images/FileTypeAudio.png");
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z"
|
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "7z"
|
||||||
|| ext == "rar" || ext == "rpm" || ext == "deb")
|
|| ext == "rar" || ext == "rpm" || ext == "deb")
|
||||||
{
|
{
|
||||||
QIcon icon(":/images/FileTypeArchive.png");
|
return QIcon(":/images/FileTypeArchive.png");
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com"
|
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com"
|
||||||
|| ext == "bin" || ext == "exe" || ext == "js" || ext == "pif"
|
|| ext == "bin" || ext == "exe" || ext == "js" || ext == "pif"
|
||||||
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
|
|| ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
|
||||||
{
|
{
|
||||||
return(QIcon(":/images/FileTypeProgram.png"));
|
return QIcon(":/images/FileTypeProgram.png");
|
||||||
}
|
}
|
||||||
else if (ext == "iso" || ext == "nrg" || ext == "mdf" )
|
else if (ext == "iso" || ext == "nrg" || ext == "mdf" )
|
||||||
{
|
{
|
||||||
QIcon icon(":/images/FileTypeCDImage.png");
|
return QIcon(":/images/FileTypeCDImage.png");
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
|
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
|
||||||
{
|
{
|
||||||
QIcon icon(":/images/FileTypeDocument.png");
|
return QIcon(":/images/FileTypeDocument.png");
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|
||||||
|| ext == "sxc" || ext == "odt" || ext == "ods")
|
|| ext == "sxc" || ext == "odt" || ext == "ods")
|
||||||
{
|
{
|
||||||
QIcon icon(":/images/FileTypeDocument.png");
|
return QIcon(":/images/FileTypeDocument.png");
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
else if (ext == "html" || ext == "htm" || ext == "php")
|
else if (ext == "html" || ext == "htm" || ext == "php")
|
||||||
{
|
{
|
||||||
QIcon icon(":/images/FileTypeDocument.png");
|
return QIcon(":/images/FileTypeDocument.png");
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QIcon icon(":/images/FileTypeAny.png");
|
return QIcon(":/images/FileTypeAny.png");
|
||||||
return icon;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -395,6 +377,7 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
{
|
{
|
||||||
return int( Qt::AlignRight | Qt::AlignVCenter);
|
return int( Qt::AlignRight | Qt::AlignVCenter);
|
||||||
}
|
}
|
||||||
|
return QVariant();
|
||||||
} /* end of TextAlignmentRole */
|
} /* end of TextAlignmentRole */
|
||||||
|
|
||||||
if (role == Qt::DisplayRole)
|
if (role == Qt::DisplayRole)
|
||||||
|
@ -413,13 +396,10 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return QString::fromUtf8(details.name.c_str());
|
return QString::fromUtf8(details.name.c_str());
|
||||||
break;
|
|
||||||
case 1:
|
case 1:
|
||||||
return QString() ;
|
return QString() ;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return QString() ;
|
return QString() ;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (details.type == DIR_TYPE_FILE) /* File */
|
else if (details.type == DIR_TYPE_FILE) /* File */
|
||||||
|
@ -428,24 +408,12 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return QString::fromUtf8(details.name.c_str());
|
return QString::fromUtf8(details.name.c_str());
|
||||||
break;
|
|
||||||
case 1:
|
case 1:
|
||||||
{
|
return misc::friendlyUnit(details.count);
|
||||||
std::ostringstream out;
|
|
||||||
return misc::friendlyUnit(details.count);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
case 2:
|
||||||
{
|
return misc::userFriendlyDuration(details.age);
|
||||||
std::ostringstream out;
|
|
||||||
return misc::userFriendlyDuration(details.age);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3:
|
case 3:
|
||||||
{
|
return getFlagsString(details.flags);
|
||||||
return getFlagsString(details.flags);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
QString ind("");
|
QString ind("");
|
||||||
|
@ -453,10 +421,8 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
ind = getAgeIndicatorString(details);
|
ind = getAgeIndicatorString(details);
|
||||||
return ind;
|
return ind;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return QString(tr("FILE"));
|
return tr("FILE");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (details.type == DIR_TYPE_DIR) /* Dir */
|
else if (details.type == DIR_TYPE_DIR) /* Dir */
|
||||||
|
@ -467,28 +433,20 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
return QString::fromUtf8(details.name.c_str());
|
return QString::fromUtf8(details.name.c_str());
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
if (details.count > 1)
|
||||||
{
|
{
|
||||||
std::ostringstream out;
|
return QString::number(details.count) + " " + tr("Files");
|
||||||
out << details.count;
|
|
||||||
if (details.count > 1)
|
|
||||||
{
|
|
||||||
return QString::fromStdString(out.str()) + " " + tr("Files");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return QString::fromStdString(out.str()) + " " + tr("File");
|
|
||||||
}
|
}
|
||||||
break;
|
return QString::number(details.count) + " " + tr("File");
|
||||||
case 2:
|
case 2:
|
||||||
return misc::userFriendlyDuration(details.min_age);
|
return misc::userFriendlyDuration(details.min_age);
|
||||||
break;
|
|
||||||
case 3:
|
case 3:
|
||||||
return getFlagsString(details.flags);
|
return getFlagsString(details.flags);
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return QString(tr("DIR"));
|
return tr("DIR");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return QVariant();
|
||||||
} /* end of DisplayRole */
|
} /* end of DisplayRole */
|
||||||
|
|
||||||
if (role == SortRole)
|
if (role == SortRole)
|
||||||
|
@ -533,7 +491,7 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
return ind;
|
return ind;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return QString(tr("FILE"));
|
return tr("FILE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (details.type == DIR_TYPE_DIR) /* Dir */
|
else if (details.type == DIR_TYPE_DIR) /* Dir */
|
||||||
|
@ -549,9 +507,10 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
|
||||||
case 3:
|
case 3:
|
||||||
return getFlagsString(details.flags);
|
return getFlagsString(details.flags);
|
||||||
default:
|
default:
|
||||||
return QString(tr("DIR"));
|
return tr("DIR");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return QVariant();
|
||||||
} /* end of SortRole */
|
} /* end of SortRole */
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -561,7 +520,7 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
||||||
if (details.type == DIR_TYPE_FILE) {
|
if (details.type == DIR_TYPE_FILE) {
|
||||||
ret = getAgeIndicatorString(details);
|
ret = getAgeIndicatorString(details);
|
||||||
return;
|
return;
|
||||||
} else if (details.type == DIR_TYPE_DIR && ret == tr("")) {
|
} else if (details.type == DIR_TYPE_DIR && ret.isEmpty()) {
|
||||||
std::list<DirStub>::iterator it;
|
std::list<DirStub>::iterator it;
|
||||||
for (it = details.children.begin(); it != details.children.end(); it++) {
|
for (it = details.children.begin(); it != details.children.end(); it++) {
|
||||||
void *ref = it->ref;
|
void *ref = it->ref;
|
||||||
|
@ -603,25 +562,17 @@ void RemoteDirModel::getAgeIndicatorRec(DirDetails &details, QString &ret) const
|
||||||
case 0:
|
case 0:
|
||||||
if (RemoteMode)
|
if (RemoteMode)
|
||||||
{
|
{
|
||||||
return QString(tr("Friends Directories"));
|
return tr("Friends Directories");
|
||||||
}
|
}
|
||||||
else
|
return tr("My Directories");
|
||||||
{
|
|
||||||
return QString(tr("My Directories"));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
case 1:
|
||||||
return QString(tr("Size"));
|
return tr("Size");
|
||||||
break;
|
|
||||||
case 2:
|
case 2:
|
||||||
return QString(tr("Age"));
|
return tr("Age");
|
||||||
break;
|
|
||||||
case 3:
|
case 3:
|
||||||
return QString(tr("Share Type"));
|
return tr("Share Type");
|
||||||
break;
|
|
||||||
case 4:
|
case 4:
|
||||||
return QString(tr("What's new"));
|
return tr("What's new");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return QString("Column %1").arg(section);
|
return QString("Column %1").arg(section);
|
||||||
}
|
}
|
||||||
|
@ -765,11 +716,12 @@ Qt::ItemFlags RemoteDirModel::flags( const QModelIndex & index ) const
|
||||||
|
|
||||||
switch(details.type)
|
switch(details.type)
|
||||||
{
|
{
|
||||||
case DIR_TYPE_PERSON: return Qt::ItemIsEnabled;
|
case DIR_TYPE_PERSON: return Qt::ItemIsEnabled;
|
||||||
case DIR_TYPE_DIR: return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
case DIR_TYPE_DIR: return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
default: ;
|
case DIR_TYPE_FILE: return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled;
|
||||||
case DIR_TYPE_FILE: return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Qt::ItemIsSelectable;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The other flags...
|
// The other flags...
|
||||||
|
@ -1289,6 +1241,3 @@ RemoteDirModel::isDir ( const QModelIndex & index ) const
|
||||||
|
|
||||||
return (details.type == DIR_TYPE_DIR) ;
|
return (details.type == DIR_TYPE_DIR) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -693,10 +693,12 @@ void SharedFilesDialog::postModDirectories(bool update_local)
|
||||||
void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point )
|
void SharedFilesDialog::sharedDirTreeWidgetContextMenu( QPoint point )
|
||||||
{
|
{
|
||||||
//=== at this moment we'll show menu only for files, not for folders
|
//=== at this moment we'll show menu only for files, not for folders
|
||||||
QModelIndex midx = ui.localDirTreeView->indexAt(point);
|
QModelIndex idx = ui.localDirTreeView->indexAt(point);
|
||||||
//if (localModel->isDir( midx ) )
|
if (!idx.isValid())
|
||||||
// return;
|
return;
|
||||||
|
QModelIndex midx = localProxyModel->mapToSource(idx);
|
||||||
|
if (!midx.isValid())
|
||||||
|
return;
|
||||||
currentFile = localModel->data(midx, RemoteDirModel::FileNameRole).toString();
|
currentFile = localModel->data(midx, RemoteDirModel::FileNameRole).toString();
|
||||||
|
|
||||||
QMenu contextMnu2( this );
|
QMenu contextMnu2( this );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue