add new/old age indicator for shared files

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1725 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
alexandrut 2009-10-13 20:36:29 +00:00
parent d9d77c0cef
commit c7c9163c2c
5 changed files with 144 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/****************************************************************
/*************************************:***************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2006 - 2009 RetroShare Team
@ -39,11 +39,11 @@
RemoteDirModel::RemoteDirModel(bool mode, QObject *parent)
: QAbstractItemModel(parent),
RemoteMode(mode), nIndex(1), indexSet(1) /* ass zero index cant be used */
RemoteMode(mode), nIndex(1), indexSet(1) /* ass zero index cant be used */,
ageIndicator(0)
{
setSupportedDragActions(Qt::CopyAction);
treeStyle();
}
void RemoteDirModel::treeStyle()
@ -156,7 +156,7 @@ void RemoteDirModel::treeStyle()
int RemoteDirModel::columnCount(const QModelIndex &parent) const
{
return 4;
return 5;
}
QString RemoteDirModel::getFlagsString(uint32_t flags)
{
@ -170,6 +170,35 @@ QString RemoteDirModel::getFlagsString(uint32_t flags)
}
}
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;
case IND_OLDER:
if (age >= 30 * 24 * 60 * 60) return oind;
break;
case IND_DEFAULT:
return ret;
default:
return ret;
}
return ret;
}
QVariant RemoteDirModel::data(const QModelIndex &index, int role) const
{
#ifdef RDM_DEBUG
@ -454,6 +483,14 @@ QString RemoteDirModel::getFlagsString(uint32_t flags)
std::ostringstream out;
//out << details.age;
return misc::userFriendlyDuration(details.age);
}
break;
case 4:
{
QString ind("");
if (ageIndicator != IND_DEFAULT)
ind = getAgeIndicatorString(details);
return ind;
}
break;
default:
@ -482,7 +519,21 @@ QString RemoteDirModel::getFlagsString(uint32_t flags)
case 3:
return misc::userFriendlyDuration(details.age);
break;
case 4:
{
if (ageIndicator == IND_DEFAULT)
return QString("");
QModelIndex pidx = parent(index);
QModelIndex pidxs = pidx.sibling(pidx.row(), 4);
if (pidxs.isValid() && pidxs.data() != tr(""))
return pidxs.data();
else {
QString ind("");
getAgeIndicatorRec(details, ind);
return ind;
}
}
break;
default:
return QString(tr("DIR"));
break;
@ -503,7 +554,27 @@ QString RemoteDirModel::getFlagsString(uint32_t flags)
return QVariant();
}
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);
}
}
}
QVariant RemoteDirModel::headerData(int section, Qt::Orientation orientation,
int role) const
@ -545,6 +616,9 @@ QString RemoteDirModel::getFlagsString(uint32_t flags)
case 3:
return QString(tr("Age"));
break;
case 4:
return QString(tr("What's new"));
break;
}
return QString("Column %1").arg(section);
}

View File

@ -30,6 +30,12 @@
#include "util/misc.h"
#include "rsiface/rstypes.h"
#define IND_DEFAULT 0
#define IND_LAST_DAY 1
#define IND_LAST_WEEK 2
#define IND_LAST_MONTH 3
#define IND_OLDER 4
class RemoteDirModel : public QAbstractItemModel
{
Q_OBJECT
@ -76,6 +82,9 @@ public:
void getFilePaths(QModelIndexList list, std::list<std::string> &fullpaths);
void changeAgeIndicator(int indicator) { ageIndicator = indicator; }
public slots:
void collapsed ( const QModelIndex & index ) { update(index); }
@ -92,6 +101,10 @@ virtual QStringList mimeTypes () const;
void treeStyle();
void downloadDirectory(const DirDetails & details, int prefixLen);
static QString getFlagsString(uint32_t) ;
QString getAgeIndicatorString(const DirDetails &) const;
void getAgeIndicatorRec(DirDetails &details, QString &ret) const;
int ageIndicator;
QIcon categoryIcon;
QIcon peerIcon;

View File

@ -95,7 +95,7 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
connect( ui.remoteDirTreeView, SIGNAL( doubleClicked(const QModelIndex&)), this, SLOT( downloadRemoteSelected()));
connect( ui.downloadButton, SIGNAL( clicked()), this, SLOT( downloadRemoteSelected()));
connect(ui.indicatorCBox, SIGNAL(currentIndexChanged(int)), this, SLOT(indicatorChanged(int)));
/*
connect( ui.remoteDirTreeView, SIGNAL( itemExpanded( QTreeWidgetItem * ) ),
@ -128,11 +128,13 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
l_header->setResizeMode (1, QHeaderView::Fixed);
l_header->setResizeMode (2, QHeaderView::Interactive);
l_header->setResizeMode (3, QHeaderView::Interactive);
l_header->setResizeMode (4, QHeaderView::Interactive);
l_header->resizeSection ( 0, 490 );
l_header->resizeSection ( 1, 70 );
l_header->resizeSection ( 2, 130 );
l_header->resizeSection ( 3, 100 );
l_header->resizeSection ( 4, 100 );
/* Set header resize modes and initial section sizes */
QHeaderView * r_header = ui.remoteDirTreeView->header () ;
@ -143,12 +145,14 @@ SharedFilesDialog::SharedFilesDialog(QWidget *parent)
r_header->setResizeMode (1, QHeaderView::Fixed);
r_header->setResizeMode (2, QHeaderView::Interactive);
r_header->setResizeMode (3, QHeaderView::Fixed);
r_header->setResizeMode (4, QHeaderView::Interactive);
r_header->resizeSection ( 0, 490 );
r_header->resizeSection ( 1, 70 );
r_header->resizeSection ( 2, 130 );
r_header->resizeSection ( 3, 100 );
r_header->resizeSection ( 4, 100 );
l_header->setHighlightSections(false);
r_header->setHighlightSections(false);
@ -779,3 +783,10 @@ void SharedFilesDialog::showFrameSplitted(bool show)
ui.labeltext->setText( label2Str.arg(tr("<strong>Files</strong>")));
}
}
void SharedFilesDialog::indicatorChanged(int index)
{
model->changeAgeIndicator(index);
localModel->changeAgeIndicator(index);
}

View File

@ -72,8 +72,6 @@ private slots:
void showFrameRemote(bool show);
void showFrameSplitted(bool show);
// void recommendfile();
void playselectedfiles();
void openfile();
@ -85,6 +83,8 @@ private slots:
void runCommandForFile();
void tryToAddNewAssotiation();
void indicatorChanged(int index);
signals:
void playFiles(QStringList files);

View File

@ -578,7 +578,7 @@ p, li { white-space: pre-wrap; }
</property>
</spacer>
</item>
<item row="0" column="3">
<item row="0" column="4">
<widget class="QPushButton" name="splittedButton">
<property name="maximumSize">
<size>
@ -607,7 +607,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="0" column="4">
<item row="0" column="5">
<widget class="QPushButton" name="remoteButton">
<property name="maximumSize">
<size>
@ -636,7 +636,7 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="0" column="5">
<item row="0" column="6">
<widget class="QPushButton" name="localButton">
<property name="maximumSize">
<size>
@ -665,6 +665,35 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QComboBox" name="indicatorCBox">
<item>
<property name="text">
<string>No indicator</string>
</property>
</item>
<item>
<property name="text">
<string>Last day</string>
</property>
</item>
<item>
<property name="text">
<string>Last week</string>
</property>
</item>
<item>
<property name="text">
<string>Last month</string>
</property>
</item>
<item>
<property name="text">
<string>Older</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>