From c7c9163c2c463f5ddde4679572161d4c2247057f Mon Sep 17 00:00:00 2001 From: alexandrut Date: Tue, 13 Oct 2009 20:36:29 +0000 Subject: [PATCH] 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 --- retroshare-gui/src/gui/RemoteDirModel.cpp | 92 ++++++++++++++++++-- retroshare-gui/src/gui/RemoteDirModel.h | 13 +++ retroshare-gui/src/gui/SharedFilesDialog.cpp | 17 +++- retroshare-gui/src/gui/SharedFilesDialog.h | 4 +- retroshare-gui/src/gui/SharedFilesDialog.ui | 35 +++++++- 5 files changed, 144 insertions(+), 17 deletions(-) diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index e3075d78c..b0c9b6a89 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -1,4 +1,4 @@ -/**************************************************************** +/*************************************:*************************** * RetroShare is distributed under the following license: * * Copyright (C) 2006 - 2009 RetroShare Team @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. ****************************************************************/ @@ -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(); - + 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 @@ -192,7 +221,7 @@ QString RemoteDirModel::getFlagsString(uint32_t flags) else flags |= DIR_FLAGS_LOCAL; - + if (!rsFiles->RequestDirDetails(ref, details, flags)) { return QVariant(); @@ -456,6 +485,14 @@ QString RemoteDirModel::getFlagsString(uint32_t flags) return misc::userFriendlyDuration(details.age); } break; + case 4: + { + QString ind(""); + if (ageIndicator != IND_DEFAULT) + ind = getAgeIndicatorString(details); + return ind; + } + break; default: return QString(tr("FILE")); break; @@ -479,10 +516,24 @@ QString RemoteDirModel::getFlagsString(uint32_t flags) case 2: return getFlagsString(details.flags); break; - case 3: + 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::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); } diff --git a/retroshare-gui/src/gui/RemoteDirModel.h b/retroshare-gui/src/gui/RemoteDirModel.h index a890830bb..c0af18f81 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.h +++ b/retroshare-gui/src/gui/RemoteDirModel.h @@ -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 &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; diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index 943c1c25c..2acb57c6d 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -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); @@ -734,7 +738,7 @@ void SharedFilesDialog::showFrame(bool show) ui.remoteButton->setChecked(false); ui.splittedButton->setChecked(false); - + /* set textcolor for Channel name */ QString labelStr("%1"); @@ -771,7 +775,7 @@ void SharedFilesDialog::showFrameSplitted(bool show) ui.localButton->setChecked(false); ui.remoteButton->setChecked(false); - + /* set textcolor for Channel name */ QString label2Str("%1"); @@ -779,3 +783,10 @@ void SharedFilesDialog::showFrameSplitted(bool show) ui.labeltext->setText( label2Str.arg(tr("Files"))); } } + +void SharedFilesDialog::indicatorChanged(int index) +{ + model->changeAgeIndicator(index); + localModel->changeAgeIndicator(index); +} + diff --git a/retroshare-gui/src/gui/SharedFilesDialog.h b/retroshare-gui/src/gui/SharedFilesDialog.h index 1362d0211..066a5f008 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/SharedFilesDialog.h @@ -72,8 +72,6 @@ private slots: void showFrameRemote(bool show); void showFrameSplitted(bool show); - - // void recommendfile(); void playselectedfiles(); void openfile(); @@ -84,6 +82,8 @@ private slots: void recommendFilesToMsg( std::string rsid ); void runCommandForFile(); void tryToAddNewAssotiation(); + + void indicatorChanged(int index); signals: void playFiles(QStringList files); diff --git a/retroshare-gui/src/gui/SharedFilesDialog.ui b/retroshare-gui/src/gui/SharedFilesDialog.ui index 0afe34724..809a33198 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.ui +++ b/retroshare-gui/src/gui/SharedFilesDialog.ui @@ -578,7 +578,7 @@ p, li { white-space: pre-wrap; } - + @@ -607,7 +607,7 @@ p, li { white-space: pre-wrap; } - + @@ -636,7 +636,7 @@ p, li { white-space: pre-wrap; } - + @@ -665,6 +665,35 @@ p, li { white-space: pre-wrap; } + + + + + No indicator + + + + + Last day + + + + + Last week + + + + + Last month + + + + + Older + + + +