From 899aa36fb868c1103c21f55d7fc3516e0c5bcf1b Mon Sep 17 00:00:00 2001 From: thunder2 Date: Tue, 5 Aug 2014 20:50:55 +0000 Subject: [PATCH] Added new files view to channels. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7481 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../GxsChannelFilesStatusWidget.cpp | 299 ++++++++++++++++++ .../gxschannels/GxsChannelFilesStatusWidget.h | 75 +++++ .../GxsChannelFilesStatusWidget.ui | 153 +++++++++ .../gui/gxschannels/GxsChannelFilesWidget.cpp | 243 ++++++++++++++ .../gui/gxschannels/GxsChannelFilesWidget.h | 76 +++++ .../gui/gxschannels/GxsChannelFilesWidget.ui | 78 +++++ .../gui/gxschannels/GxsChannelPostsWidget.cpp | 62 +++- .../gui/gxschannels/GxsChannelPostsWidget.h | 9 + .../gui/gxschannels/GxsChannelPostsWidget.ui | 68 ++++ retroshare-gui/src/gui/images.qrc | 2 + retroshare-gui/src/gui/images/view-feeds.png | Bin 0 -> 388 bytes retroshare-gui/src/gui/images/view-files.png | Bin 0 -> 334 bytes retroshare-gui/src/retroshare-gui.pro | 6 + 13 files changed, 1061 insertions(+), 10 deletions(-) create mode 100644 retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.cpp create mode 100644 retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.h create mode 100644 retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.ui create mode 100644 retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.cpp create mode 100644 retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.h create mode 100644 retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.ui create mode 100644 retroshare-gui/src/gui/images/view-feeds.png create mode 100644 retroshare-gui/src/gui/images/view-files.png diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.cpp new file mode 100644 index 000000000..b9b84b894 --- /dev/null +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.cpp @@ -0,0 +1,299 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2014 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include +#include +#include +#include +#include + +#include "GxsChannelFilesStatusWidget.h" +#include "ui_GxsChannelFilesStatusWidget.h" +#include "gui/common/RsUrlHandler.h" + +#include "retroshare/rsfiles.h" + +GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, const RsGxsFile &file, QWidget *parent) : + QWidget(parent), mGroupId(groupId), mMessageId(messageId), mFile(file), ui(new Ui::GxsChannelFilesStatusWidget) +{ + ui->setupUi(this); + + mState = STATE_REMOTE; + + setSize(mFile.mSize); + + /* Connect signals */ + connect(ui->downloadToolButton, SIGNAL(clicked()), this, SLOT(download())); + connect(ui->resumeToolButton, SIGNAL(clicked()), this, SLOT(resume())); + connect(ui->pauseToolButton, SIGNAL(clicked()), this, SLOT(pause())); + connect(ui->cancelToolButton, SIGNAL(clicked()), this, SLOT(cancel())); + connect(ui->openFolderToolButton, SIGNAL(clicked()), this, SLOT(openFolder())); + + check(); +} + +GxsChannelFilesStatusWidget::~GxsChannelFilesStatusWidget() +{ + delete ui; +} + +void GxsChannelFilesStatusWidget::setSize(uint64_t size) +{ + mDivisor = 1; + + if (size > 10000000) { + /* 10 Mb */ + ui->progressBar->setFormat("%v MB"); + mDivisor = 1000000; + } else if (size > 10000) { + /* 10 Kb */ + ui->progressBar->setFormat("%v kB"); + mDivisor = 1000; + } else { + ui->progressBar->setFormat("%v B"); + mDivisor = 1; + } + + ui->progressBar->setRange(0, size / mDivisor); +} + +void GxsChannelFilesStatusWidget::check() +{ + FileInfo fileInfo; + if (rsFiles->alreadyHaveFile(mFile.mHash, fileInfo)) { + mState = STATE_LOCAL; + setSize(fileInfo.size); + } else { + FileInfo fileInfo; + bool detailsOk = rsFiles->FileDetails(mFile.mHash, RS_FILE_HINTS_DOWNLOAD | RS_FILE_HINTS_SPEC_ONLY, fileInfo); + + if (detailsOk) { + switch (fileInfo.downloadStatus) { + case FT_STATE_WAITING: + mState = STATE_WAITING; + break; + case FT_STATE_DOWNLOADING: + if (fileInfo.avail == fileInfo.size) { + mState = STATE_LOCAL; + } else { + mState = STATE_DOWNLOAD; + } + setSize(fileInfo.size); + ui->progressBar->setValue(fileInfo.avail / mDivisor); + break; + case FT_STATE_COMPLETE: + mState = STATE_DOWNLOAD; + break; + case FT_STATE_QUEUED: + mState = STATE_WAITING; + break; + case FT_STATE_PAUSED: + mState = STATE_PAUSED; + break; + case FT_STATE_CHECKING_HASH: + mState = STATE_CHECKING; + break; + case FT_STATE_FAILED: + mState = STATE_ERROR; + break; + } + } else { + mState = STATE_REMOTE; + } + } + + int repeat = 0; + QString statusText; + + switch (mState) { + case STATE_ERROR: + repeat = 0; + + ui->downloadToolButton->hide(); + ui->resumeToolButton->hide(); + ui->pauseToolButton->hide(); + ui->cancelToolButton->hide(); + ui->progressBar->hide(); + ui->openFolderToolButton->hide(); + + statusText = tr("Error"); + + break; + + case STATE_REMOTE: + repeat = 30000; + + ui->downloadToolButton->show(); + ui->resumeToolButton->hide(); + ui->pauseToolButton->hide(); + ui->cancelToolButton->hide(); + ui->progressBar->hide(); + ui->openFolderToolButton->hide(); + + break; + + case STATE_DOWNLOAD: + repeat = 1000; + + ui->downloadToolButton->hide(); + ui->resumeToolButton->hide(); + ui->pauseToolButton->show(); + ui->cancelToolButton->show(); + ui->progressBar->show(); + ui->openFolderToolButton->hide(); + + break; + + case STATE_PAUSED: + repeat = 1000; + + ui->downloadToolButton->hide(); + ui->resumeToolButton->show(); + ui->pauseToolButton->hide(); + ui->cancelToolButton->show(); + ui->progressBar->hide(); + ui->openFolderToolButton->hide(); + + statusText = tr("Paused"); + + break; + + case STATE_WAITING: + repeat = 1000; + + ui->downloadToolButton->hide(); + ui->resumeToolButton->hide(); + ui->pauseToolButton->show(); + ui->cancelToolButton->show(); + ui->progressBar->hide(); + ui->openFolderToolButton->hide(); + + statusText = tr("Waiting"); + + break; + + case STATE_CHECKING: + repeat = 1000; + + ui->downloadToolButton->hide(); + ui->resumeToolButton->hide(); + ui->pauseToolButton->hide(); + ui->cancelToolButton->show(); + ui->progressBar->hide(); + ui->openFolderToolButton->hide(); + + statusText = tr("Checking"); + + break; + + case STATE_LOCAL: + repeat = 60000; + + ui->downloadToolButton->hide(); + ui->resumeToolButton->hide(); + ui->pauseToolButton->hide(); + ui->cancelToolButton->hide(); + ui->progressBar->hide(); + ui->openFolderToolButton->show(); + + break; + } + + if (statusText.isEmpty()) { + ui->label->clear(); + ui->label->hide(); + } else { + ui->label->setText(statusText); + ui->label->show(); + } + + if (repeat) { + QTimer::singleShot(repeat, this, SLOT(check())); + } +} + +void GxsChannelFilesStatusWidget::download() +{ + std::list sources; + + std::string destination; +//#if 0 +// if (!mChannelId.empty() && mType == SFI_TYPE_CHANNEL) { +// ChannelInfo ci; +// if (rsChannels->getChannelInfo(mChannelId, ci)) { +// destination = ci.destination_directory; +// } +// } +//#endif + + // Add possible direct sources. + FileInfo fileInfo; + rsFiles->FileDetails(mFile.mHash, RS_FILE_HINTS_REMOTE, fileInfo); + + for(std::list::const_iterator it = fileInfo.peers.begin(); it != fileInfo.peers.end(); ++it) { + sources.push_back((*it).peerId); + } + + rsFiles->FileRequest(mFile.mName, mFile.mHash, mFile.mSize, destination, RS_FILE_REQ_ANONYMOUS_ROUTING, sources); + + check(); +} + +void GxsChannelFilesStatusWidget::pause() +{ + rsFiles->FileControl(mFile.mHash, RS_FILE_CTRL_PAUSE); + + check(); +} + +void GxsChannelFilesStatusWidget::resume() +{ + rsFiles->FileControl(mFile.mHash, RS_FILE_CTRL_START); + + check(); +} + +void GxsChannelFilesStatusWidget::cancel() +{ + if ((QMessageBox::question(this, "", tr("Are you sure that you want to cancel and delete the file?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No)) == QMessageBox::No) { + return; + } + + rsFiles->FileCancel(mFile.mHash); + + check(); +} + +void GxsChannelFilesStatusWidget::openFolder() +{ + FileInfo fileInfo; + if (!rsFiles->alreadyHaveFile(mFile.mHash, fileInfo)) { + return; + } + + /* open folder with a suitable application */ + QDir dir = QFileInfo(QString::fromUtf8(fileInfo.path.c_str())).absoluteDir(); + if (dir.exists()) { + if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(dir.absolutePath()))) { + QMessageBox::warning(this, "", QString("%1 %2").arg(tr("Can't open folder"), dir.absolutePath())); + } + } +} diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.h b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.h new file mode 100644 index 000000000..6fd8b7607 --- /dev/null +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.h @@ -0,0 +1,75 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2014 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#ifndef GXSCHANNELFILESSTATUSWIDGET_H +#define GXSCHANNELFILESSTATUSWIDGET_H + +#include + +#include "retroshare/rsgxscommon.h" + +namespace Ui { +class GxsChannelFilesStatusWidget; +} + +class GxsChannelFilesStatusWidget : public QWidget +{ + Q_OBJECT + +public: + explicit GxsChannelFilesStatusWidget(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, const RsGxsFile &file, QWidget *parent = 0); + ~GxsChannelFilesStatusWidget(); + +private slots: + void check(); + void download(); + void cancel(); + void pause(); + void resume(); + void openFolder(); + +private: + void setSize(uint64_t size); + +private: + enum State + { + STATE_LOCAL, + STATE_REMOTE, + STATE_DOWNLOAD, + STATE_PAUSED, + STATE_WAITING, + STATE_CHECKING, + STATE_ERROR + } mState; + +private: + RsGxsGroupId mGroupId; + RsGxsMessageId mMessageId; + RsGxsFile mFile; + + uint64_t mSize; + uint64_t mDivisor; + + Ui::GxsChannelFilesStatusWidget *ui; +}; + +#endif // GXSCHANNELFILESSTATUSWIDGET_H diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.ui new file mode 100644 index 000000000..59fa846da --- /dev/null +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesStatusWidget.ui @@ -0,0 +1,153 @@ + + + GxsChannelFilesStatusWidget + + + + 0 + 0 + 367 + 27 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + 0 + 0 + + + + Qt::NoFocus + + + Download + + + + + + + + 0 + 0 + + + + 0 + + + + + + + + 0 + 0 + + + + TextLabel + + + Qt::AlignCenter + + + + + + + Qt::NoFocus + + + + :/images/resume.png:/images/resume.png + + + + + + + Qt::NoFocus + + + + :/images/pause.png:/images/pause.png + + + + + + + Qt::NoFocus + + + + :/images/cancel.png:/images/cancel.png + + + + + + + + 0 + 0 + + + + Qt::NoFocus + + + Open folder + + + + + + + + + + + + + diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.cpp new file mode 100644 index 000000000..81538a043 --- /dev/null +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.cpp @@ -0,0 +1,243 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2014 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include + +#include "GxsChannelFilesWidget.h" +#include "ui_GxsChannelFilesWidget.h" +#include "GxsChannelFilesStatusWidget.h" +#include "GxsChannelPostsWidget.h" +#include "gui/feeds/GxsChannelPostItem.h" +#include "gui/common/RSTreeWidgetItem.h" +#include "util/misc.h" +#include "util/DateTime.h" +#include "gui/gxs/GxsFeedItem.h" + +#include "retroshare/rsgxschannels.h" + +#define COLUMN_FILENAME 0 +#define COLUMN_SIZE 1 +#define COLUMN_TITLE 2 +#define COLUMN_PUBLISHED 3 +#define COLUMN_STATUS 4 +#define COLUMN_COUNT 5 +#define COLUMN_DATA 0 + +#define ROLE_SORT Qt::UserRole +#define ROLE_GROUP_ID Qt::UserRole + 1 +#define ROLE_MESSAGE_ID Qt::UserRole + 2 +#define ROLE_FILE_HASH Qt::UserRole + 3 +#define ROLE_MSG Qt::UserRole + 4 + +GxsChannelFilesWidget::GxsChannelFilesWidget(QWidget *parent) : + QWidget(parent), ui(new Ui::GxsChannelFilesWidget) +{ + ui->setupUi(this); + + mFeedItem = NULL; + + /* Connect signals */ + connect(ui->treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*))); + + /* Sort */ + mCompareRole = new RSTreeWidgetItemCompareRole; + mCompareRole->setRole(COLUMN_SIZE, ROLE_SORT); + mCompareRole->setRole(COLUMN_PUBLISHED, ROLE_SORT); + + /* Filter */ + mFilterType = 0; + + /* Initialize file tree */ + ui->treeWidget->setColumnCount(COLUMN_COUNT); + QTreeWidgetItem *headerItem = ui->treeWidget->headerItem(); + headerItem->setText(COLUMN_FILENAME, tr("Filename")); + headerItem->setText(COLUMN_SIZE, tr("Size")); + headerItem->setText(COLUMN_TITLE, tr("Title")); + headerItem->setText(COLUMN_PUBLISHED, tr("Published")); + headerItem->setText(COLUMN_STATUS, tr("Status")); + + ui->treeWidget->setColumnWidth(COLUMN_FILENAME, 400); + ui->treeWidget->setColumnWidth(COLUMN_SIZE, 80); + ui->treeWidget->setColumnWidth(COLUMN_PUBLISHED, 150); +} + +GxsChannelFilesWidget::~GxsChannelFilesWidget() +{ + delete(mCompareRole); + delete ui; +} + +void GxsChannelFilesWidget::addFiles(const RsGxsChannelPost &post, bool related) +{ + if (related) { + removeItems(post.mMeta.mGroupId, post.mMeta.mMsgId); + } + + std::list::const_iterator fileIt; + for (fileIt = post.mFiles.begin(); fileIt != post.mFiles.end(); ++fileIt) { + const RsGxsFile &file = *fileIt; + + QTreeWidgetItem *treeItem = new RSTreeWidgetItem(mCompareRole); + + treeItem->setText(COLUMN_FILENAME, QString::fromUtf8(file.mName.c_str())); + treeItem->setText(COLUMN_SIZE, misc::friendlyUnit(file.mSize)); + treeItem->setData(COLUMN_SIZE, ROLE_SORT, file.mSize); + treeItem->setText(COLUMN_TITLE, QString::fromUtf8(post.mMeta.mMsgName.c_str())); + treeItem->setText(COLUMN_PUBLISHED, DateTime::formatDateTime(post.mMeta.mPublishTs)); + treeItem->setData(COLUMN_PUBLISHED, ROLE_SORT, QDateTime::fromTime_t(post.mMeta.mPublishTs)); + + treeItem->setData(COLUMN_DATA, ROLE_GROUP_ID, qVariantFromValue(post.mMeta.mGroupId)); + treeItem->setData(COLUMN_DATA, ROLE_MESSAGE_ID, qVariantFromValue(post.mMeta.mMsgId)); + treeItem->setData(COLUMN_DATA, ROLE_FILE_HASH, qVariantFromValue(file.mHash)); + treeItem->setData(COLUMN_DATA, ROLE_MSG, QString::fromUtf8(post.mMsg.c_str())); + + ui->treeWidget->addTopLevelItem(treeItem); + + QWidget *statusWidget = new GxsChannelFilesStatusWidget(post.mMeta.mGroupId, post.mMeta.mMsgId, file); + ui->treeWidget->setItemWidget(treeItem, COLUMN_STATUS, statusWidget); + + filterItem(treeItem); + } +} + +void GxsChannelFilesWidget::setFilter(const QString &text, int type) +{ + if (mFilterText == text && mFilterType == type) { + return; + } + + mFilterText = text; + mFilterType = type; + + filterItems(); +} + +void GxsChannelFilesWidget::setFilterText(const QString &text) +{ + setFilter(text, mFilterType); +} + +void GxsChannelFilesWidget::setFilterType(int type) +{ + setFilter(mFilterText, type); +} + +void GxsChannelFilesWidget::filterItems() +{ + QTreeWidgetItemIterator it(ui->treeWidget); + QTreeWidgetItem *treeItem; + while ((treeItem = *it) != NULL) { + ++it; + filterItem(treeItem); + } +} + +void GxsChannelFilesWidget::filterItem(QTreeWidgetItem *treeItem) +{ + bool visible = mFilterText.isEmpty(); + + switch (mFilterType) { + case GxsChannelPostsWidget::FILTER_TITLE: + visible = treeItem->text(COLUMN_TITLE).contains(mFilterText, Qt::CaseInsensitive); + break; + case GxsChannelPostsWidget::FILTER_MSG: + visible = treeItem->data(COLUMN_DATA, ROLE_MSG).toString().contains(mFilterText, Qt::CaseInsensitive); + break; + case GxsChannelPostsWidget::FILTER_FILE_NAME: + visible = treeItem->text(COLUMN_FILENAME).contains(mFilterText, Qt::CaseInsensitive); + break; + } + + treeItem->setHidden(!visible); +} + +//QTreeWidgetItem *GxsChannelFilesWidget::findFile(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, const RsFileHash &fileHash) +//{ +// QTreeWidgetItemIterator it(ui->treeWidget); +// QTreeWidgetItem *treeItem; +// while ((treeItem = *it) != NULL) { +// ++it; + +// if (fileHash != treeItem->data(COLUMN_DATA, ROLE_FILE_HASH).value()) { +// continue; +// } +// if (messageId != treeItem->data(COLUMN_DATA, ROLE_MESSAGE_ID).value()) { +// continue; +// } +// if (groupId != treeItem->data(COLUMN_DATA, ROLE_GROUP_ID).value()) { +// continue; +// } + +// return treeItem; +// } + +// return NULL; +//} + +void GxsChannelFilesWidget::removeItems(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId) +{ + QTreeWidgetItemIterator it(ui->treeWidget); + QTreeWidgetItem *treeItem; + while ((treeItem = *it) != NULL) { + ++it; + + if (messageId != treeItem->data(COLUMN_DATA, ROLE_MESSAGE_ID).value()) { + continue; + } + if (groupId != treeItem->data(COLUMN_DATA, ROLE_GROUP_ID).value()) { + continue; + } + + delete(treeItem); + } +} + +void GxsChannelFilesWidget::closeFeedItem() +{ + if (mFeedItem) { + delete(mFeedItem); + mFeedItem = NULL; + } + + ui->feedItemFrame->hide(); +} + +void GxsChannelFilesWidget::currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem */*previous*/) +{ + if (!current) { + closeFeedItem(); + return; + } + + RsGxsGroupId groupId = current->data(COLUMN_DATA, ROLE_GROUP_ID).value(); + RsGxsMessageId messageId = current->data(COLUMN_DATA, ROLE_MESSAGE_ID).value(); + + if (mFeedItem) { + if (mFeedItem->groupId() == groupId && mFeedItem->messageId() == messageId) { + return; + } + closeFeedItem(); + } + + mFeedItem = new GxsChannelPostItem(NULL, 0, groupId, messageId, true, true); + ui->feedItemFrame->show(); + ui->feedItemFrame->layout()->addWidget(mFeedItem); +} diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.h b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.h new file mode 100644 index 000000000..cff9e7658 --- /dev/null +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.h @@ -0,0 +1,76 @@ +/**************************************************************** + * RetroShare is distributed under the following license: + * + * Copyright (C) 2014 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#ifndef GXSCHANNELFILESWIDGET_H +#define GXSCHANNELFILESWIDGET_H + +#include + +#include "retroshare/rsgxsifacetypes.h" + +class RsGxsChannelPost; +class RSTreeWidgetItemCompareRole; +class QTreeWidgetItem; +class GxsFeedItem; + +namespace Ui { +class GxsChannelFilesWidget; +} + +class GxsChannelFilesWidget : public QWidget +{ + Q_OBJECT + +public: + explicit GxsChannelFilesWidget(QWidget *parent = 0); + ~GxsChannelFilesWidget(); + + void addFiles(const RsGxsChannelPost &post, bool related); + +public slots: + void setFilter(const QString &text, int type); + void setFilterText(const QString &text); + void setFilterType(int type); + +private: +// QTreeWidgetItem *findFile(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, const RsFileHash &fileHash); + void removeItems(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId); + void closeFeedItem(); + void filterItems(); + void filterItem(QTreeWidgetItem *treeItem); + +private slots: + void currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); + +private: + /* Sort */ + RSTreeWidgetItemCompareRole *mCompareRole; + + /* Filter */ + QString mFilterText; + int mFilterType; + + GxsFeedItem *mFeedItem; + + Ui::GxsChannelFilesWidget *ui; +}; + +#endif // GXSCHANNELFILESWIDGET_H diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.ui new file mode 100644 index 000000000..4990b3259 --- /dev/null +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelFilesWidget.ui @@ -0,0 +1,78 @@ + + + GxsChannelFilesWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + false + + + false + + + true + + + true + + + + 1 + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp index ba00b8784..3ae3eacf0 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.cpp @@ -20,6 +20,7 @@ ****************************************************************/ #include +#include #include "GxsChannelPostsWidget.h" #include "ui_GxsChannelPostsWidget.h" @@ -39,11 +40,9 @@ * #define DEBUG_CHANNEL ***/ -/* Filters */ -#define FILTER_TITLE 1 -#define FILTER_MSG 2 -#define FILTER_FILE_NAME 3 -#define FILTER_COUNT 3 +/* View mode */ +#define VIEW_MODE_FEEDS 1 +#define VIEW_MODE_FILES 2 /** Constructor */ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWidget *parent) : @@ -76,8 +75,19 @@ GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWid ui->filterLineEdit->addFilter(QIcon(), tr("Message"), FILTER_MSG, tr("Search Message")); ui->filterLineEdit->addFilter(QIcon(), tr("Filename"), FILTER_FILE_NAME, tr("Search Filename")); connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), ui->feedWidget, SLOT(setFilterText(QString))); + connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), ui->fileWidget, SLOT(setFilterText(QString))); connect(ui->filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterChanged(int))); + /* Initialize view button */ + //setViewMode(VIEW_MODE_FEEDS); see processSettings + + QSignalMapper *signalMapper = new QSignalMapper(this); + connect(ui->feedToolButton, SIGNAL(clicked()), signalMapper, SLOT(map())); + connect(ui->fileToolButton, SIGNAL(clicked()), signalMapper, SLOT(map())); + signalMapper->setMapping(ui->feedToolButton, VIEW_MODE_FEEDS); + signalMapper->setMapping(ui->fileToolButton, VIEW_MODE_FILES); + connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(setViewMode(int))); + /*************** Setup Left Hand Side (List of Channels) ****************/ ui->loadingLabel->hide(); @@ -125,6 +135,7 @@ void GxsChannelPostsWidget::processSettings(bool load) if (load) { // load settings ui->filterLineEdit->setCurrentFilter(Settings->value("filter", FILTER_TITLE).toInt()); + setViewMode(Settings->value("viewMode", VIEW_MODE_FEEDS).toInt()); } else { // save settings } @@ -221,16 +232,45 @@ void GxsChannelPostsWidget::insertChannelDetails(const RsGxsChannelGroup &group) setAutoDownload(autoDownload); } -void GxsChannelPostsWidget::filterChanged(int filter) +void GxsChannelPostsWidget::setViewMode(int viewMode) { - ui->feedWidget->setFilterType(filter); + switch (viewMode) { + case VIEW_MODE_FEEDS: + ui->feedWidget->show(); + ui->fileWidget->hide(); - if (mInProcessSettings) { + ui->feedToolButton->setChecked(true); + ui->fileToolButton->setChecked(false); + + break; + case VIEW_MODE_FILES: + ui->feedWidget->hide(); + ui->fileWidget->show(); + + ui->feedToolButton->setChecked(false); + ui->fileToolButton->setChecked(true); + + break; + default: + setViewMode(VIEW_MODE_FEEDS); return; } - // save index - Settings->setValueToGroup("ChannelPostsWidget", "filter", filter); + if (!mInProcessSettings) { + /* Save view mode */ + Settings->setValueToGroup("ChannelPostsWidget", "viewMode", viewMode); + } +} + +void GxsChannelPostsWidget::filterChanged(int filter) +{ + ui->feedWidget->setFilterType(filter); + ui->fileWidget->setFilterType(filter); + + if (!mInProcessSettings) { + // save index + Settings->setValueToGroup("ChannelPostsWidget", "filter", filter); + } } /*static*/ bool GxsChannelPostsWidget::filterItem(FeedItem *feedItem, const QString &text, int filter) @@ -285,6 +325,8 @@ void GxsChannelPostsWidget::createPostItem(const RsGxsChannelPost &post, bool re GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, post, subscribeFlags, true, false); ui->feedWidget->addFeedItem(item, ROLE_PUBLISH, QDateTime::fromTime_t(post.mMeta.mPublishTs)); } + + ui->fileWidget->addFiles(post, related); } void GxsChannelPostsWidget::fillThreadCreatePost(const QVariant &post, bool related, int current, int count) diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h index 193deff19..4abe12bca 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.h @@ -40,6 +40,14 @@ class GxsChannelPostsWidget : public GxsMessageFramePostWidget, public FeedHolde { Q_OBJECT +public: + /* Filters */ + enum Filter { + FILTER_TITLE = 1, + FILTER_MSG = 2, + FILTER_FILE_NAME = 3 + }; + public: /** Default Constructor */ GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWidget *parent = 0); @@ -71,6 +79,7 @@ private slots: void toggleAutoDownload(); void subscribeGroup(bool subscribe); void filterChanged(int filter); + void setViewMode(int viewMode); private: void processSettings(bool load); diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui index ab1aafd6b..5d16f17bc 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidget.ui @@ -193,6 +193,47 @@ + + + + 0 + + + + + Show feeds + + + + :/images/view-feeds.png:/images/view-feeds.png + + + true + + + true + + + + + + + Show files + + + + :/images/view-files.png:/images/view-files.png + + + true + + + true + + + + + @@ -224,6 +265,16 @@ + + + + + 0 + 0 + + + + @@ -235,9 +286,20 @@ + + + Feeds + + + + + Files + + toolBarFrame headFrame feedWidget + fileWidget @@ -256,6 +318,12 @@
gui/common/RSFeedWidget.h
1
+ + GxsChannelFilesWidget + QWidget +
gui/gxschannels/GxsChannelFilesWidget.h
+ 1 +
diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index b67707dc9..21dbb34c3 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -692,5 +692,7 @@ images/btn_red_pressed.png images/btn_red_hover.png images/btn_red.png + images/view-feeds.png + images/view-files.png diff --git a/retroshare-gui/src/gui/images/view-feeds.png b/retroshare-gui/src/gui/images/view-feeds.png new file mode 100644 index 0000000000000000000000000000000000000000..5b0d8bf823198836ba8ef7e357ecf65b123d9550 GIT binary patch literal 388 zcmeAS@N?(olHy`uVBq!ia0vp^Vj#@H3?x5i&EW)6%*9TgAsieWw;%dH0CG7CJR*yM zqDdgkc-lr(1Slw3;u=vBoS#-wo>-L1P+nfHmzkGcoSayYs+V7sKKq@G6i`uGfKQ0) z|NsAiOf>NA+js8Nn*wQPq;gIx6hOA#?!?yq~g}ri{AWA1_CS(9LvN${9O~(a_Rqnb=xhRGuGbw zvuXKBmEwp6QIeto-CAEKUzw0*B*l1KATE;QrCU>Tv0bs=U55?zQnm~KC04W^YnuP@ zW10QY3eRUhYHZ(dzx|rF{p{P+J6m(V_j^uL{XE)7O>#29J!00`o5w{{oF81Z{B|S^7a4!|9vfzHb7I@OM?7@ z85sF=bdCNjVp{PYD8!iL?d~F0b8&?vkdyD};uunKYwkpEz6J#z7j1j{6$%T!+pkhS z#APsXdfBC!CU>V~tZ+Eeq9f3=!-`u({iU;o(2S%?&r6wm)eVjob-WEr5S+dBfWkhl znj_w9a-Y8ZS1x9gYkFs4wAY2d^}U5r+5^RmBYU=;mG;lx^MfsWx^(h<=VLA)4|=-# KxvX