Added new files view to channels.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7481 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-08-05 20:50:55 +00:00
parent 7a65ad1a14
commit 899aa36fb8
13 changed files with 1061 additions and 10 deletions

View File

@ -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 <QTimer>
#include <QMessageBox>
#include <QFileInfo>
#include <QDir>
#include <QUrl>
#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<RsPeerId> 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<TransferInfo>::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()));
}
}
}

View File

@ -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 <QWidget>
#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

View File

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GxsChannelFilesStatusWidget</class>
<widget class="QWidget" name="GxsChannelFilesStatusWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>367</width>
<height>27</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frame">
<property name="autoFillBackground">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="downloadToolButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Download</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="resumeToolButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/resume.png</normaloff>:/images/resume.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="pauseToolButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/pause.png</normaloff>:/images/pause.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="cancelToolButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/cancel.png</normaloff>:/images/cancel.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="openFolderToolButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Open folder</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -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 <QDateTime>
#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<RsGxsFile>::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<RsFileHash>()) {
// continue;
// }
// if (messageId != treeItem->data(COLUMN_DATA, ROLE_MESSAGE_ID).value<RsGxsMessageId>()) {
// continue;
// }
// if (groupId != treeItem->data(COLUMN_DATA, ROLE_GROUP_ID).value<RsGxsGroupId>()) {
// 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<RsGxsMessageId>()) {
continue;
}
if (groupId != treeItem->data(COLUMN_DATA, ROLE_GROUP_ID).value<RsGxsGroupId>()) {
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<RsGxsGroupId>();
RsGxsMessageId messageId = current->data(COLUMN_DATA, ROLE_MESSAGE_ID).value<RsGxsMessageId>();
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);
}

View File

@ -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 <QWidget>
#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

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GxsChannelFilesWidget</class>
<widget class="QWidget" name="GxsChannelFilesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTreeWidget" name="treeWidget">
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<attribute name="headerShowSortIndicator" stdset="0">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QFrame" name="feedItemFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -20,6 +20,7 @@
****************************************************************/
#include <QDateTime>
#include <QSignalMapper>
#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;
}
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)

View File

@ -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);

View File

@ -193,6 +193,47 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="viewModeLayout">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="feedToolButton">
<property name="toolTip">
<string>Show feeds</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/view-feeds.png</normaloff>:/images/view-feeds.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="fileToolButton">
<property name="toolTip">
<string>Show files</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/view-files.png</normaloff>:/images/view-files.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="LineEditClear" name="filterLineEdit">
<property name="sizePolicy">
@ -224,6 +265,16 @@
</layout>
</widget>
</item>
<item>
<widget class="GxsChannelFilesWidget" name="fileWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="RSFeedWidget" name="feedWidget" native="true">
<property name="sizePolicy">
@ -235,9 +286,20 @@
</widget>
</item>
</layout>
<action name="actionFeeds">
<property name="text">
<string>Feeds</string>
</property>
</action>
<action name="actionFiles">
<property name="text">
<string>Files</string>
</property>
</action>
<zorder>toolBarFrame</zorder>
<zorder>headFrame</zorder>
<zorder>feedWidget</zorder>
<zorder>fileWidget</zorder>
</widget>
<customwidgets>
<customwidget>
@ -256,6 +318,12 @@
<header>gui/common/RSFeedWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>GxsChannelFilesWidget</class>
<extends>QWidget</extends>
<header>gui/gxschannels/GxsChannelFilesWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>

View File

@ -692,5 +692,7 @@
<file>images/btn_red_pressed.png</file>
<file>images/btn_red_hover.png</file>
<file>images/btn_red.png</file>
<file>images/view-feeds.png</file>
<file>images/view-files.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

View File

@ -1168,15 +1168,21 @@ gxschannels {
gui/gxschannels/GxsChannelGroupDialog.h \
gui/gxschannels/CreateGxsChannelMsg.h \
gui/gxschannels/GxsChannelPostsWidget.h \
gui/gxschannels/GxsChannelFilesWidget.h \
gui/gxschannels/GxsChannelFilesStatusWidget.h \
gui/feeds/GxsChannelPostItem.h \
gui/gxschannels/GxsChannelUserNotify.h
FORMS += gui/gxschannels/GxsChannelPostsWidget.ui \
gui/gxschannels/GxsChannelFilesWidget.ui \
gui/gxschannels/GxsChannelFilesStatusWidget.ui \
gui/gxschannels/CreateGxsChannelMsg.ui \
gui/feeds/GxsChannelPostItem.ui
SOURCES += gui/gxschannels/GxsChannelDialog.cpp \
gui/gxschannels/GxsChannelPostsWidget.cpp \
gui/gxschannels/GxsChannelFilesWidget.cpp \
gui/gxschannels/GxsChannelFilesStatusWidget.cpp \
gui/gxschannels/GxsChannelGroupDialog.cpp \
gui/gxschannels/CreateGxsChannelMsg.cpp \
gui/feeds/GxsChannelPostItem.cpp \