Added new base class for group and tabbed message dialogs (forums, channels)

- GxsGroupFrameDialog, GxsMessageFrameWidget

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7329 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-05-04 22:59:06 +00:00
parent 4c8eaeb421
commit 50bb541c4e
16 changed files with 2193 additions and 2434 deletions

File diff suppressed because it is too large Load diff

View file

@ -22,23 +22,10 @@
#ifndef _GXS_CHANNEL_DIALOG_H
#define _GXS_CHANNEL_DIALOG_H
#include <map>
#include "gui/gxs/RsGxsUpdateBroadcastPage.h"
#include "ui_GxsChannelDialog.h"
#include "gui/feeds/FeedHolder.h"
#include "gui/gxs/GxsGroupFrameDialog.h"
#include "gui/gxs/GxsCommentContainer.h"
#include "util/TokenQueue.h"
//class ChanMsgItem;
class GxsChannelPostItem;
class QTreeWidgetItem;
class UIStateHelper;
class GxsChannelDialog : public RsGxsUpdateBroadcastPage, public TokenResponse, public GxsServiceDialog, public FeedHolder
class GxsChannelDialog : public GxsGroupFrameDialog, public GxsServiceDialog
{
Q_OBJECT
@ -50,94 +37,20 @@ public:
// virtual UserNotify *getUserNotify(QObject *parent);
/* FeedHolder */
virtual QScrollArea *getScrollArea();
virtual void deleteFeedItem(QWidget *item, uint32_t type);
virtual void openChat(const RsPeerId& peerId);
virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &title);
bool navigate(const std::string& channelId, const std::string& msgId);
/* NEW GXS FNS */
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
protected:
virtual void updateDisplay(bool complete);
private slots:
void todo();
void channelListCustomPopupMenu(QPoint point);
void selectChannel(const QString &id);
void createChannel();
void subscribeChannel();
void unsubscribeChannel();
void setAllAsReadClicked();
void toggleAutoDownload();
void createMsg();
void showChannelDetails();
void restoreChannelKeys();
void editChannelDetail();
void shareKey();
void copyChannelLink();
// void channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status);
//void fillThreadFinished();
//void fillThreadAddMsg(const QString &channelId, const QString &channelMsgId, int current, int count);
void loadComment(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId, const QString &title);
private:
//void updateChannelList();
//void updateChannelMsgs();
void updateMessageSummaryList(const std::string &channelId);
void processSettings(bool load);
void setAutoDownloadButton(bool autoDl);
/* NEW GXS FNS */
void insertChannels();
void requestGroupSummary();
void loadGroupSummary(const uint32_t &token);
void requestGroupData(const RsGxsGroupId &grpId);
void loadGroupData(const uint32_t &token);
void requestPosts(const RsGxsGroupId &grpId);
void loadPosts(const uint32_t &token);
void insertChannelData(const std::list<RsGroupMetaData> &channelList);
void insertChannelDetails(const RsGxsChannelGroup &group);
void insertChannelPosts(const std::vector<RsGxsChannelPost> &posts);
void acknowledgeGroupUpdate(const uint32_t &token);
void acknowledgeMessageUpdate(const uint32_t &token);
RsGxsGroupId mChannelId; /* current Channel */
TokenQueue *mChannelQueue;
/* Layout Pointers */
QBoxLayout *mMsgLayout;
//QList<ChanMsgItem *> mChanMsgItems;
QList<GxsChannelPostItem *> mChannelPostItems;
std::map<std::string, uint32_t> mChanSearchScore; //chanId, score
QTreeWidgetItem *ownChannels;
QTreeWidgetItem *subcribedChannels;
QTreeWidgetItem *popularChannels;
QTreeWidgetItem *otherChannels;
UIStateHelper *mStateHelper;
/* UI - from Designer */
Ui::GxsChannelDialog ui;
/* GxsGroupFrameDialog */
virtual QString text(TextType type);
virtual QString icon(IconType type);
virtual QString settingsGroupName() { return "GxsChannelDialog"; }
virtual GxsGroupDialog *createNewGroupDialog(TokenQueue *tokenQueue);
virtual GxsGroupDialog *createGroupDialog(TokenQueue *tokenQueue, RsTokenService *tokenService, GxsGroupDialog::Mode mode, RsGxsGroupId groupId);
virtual int shareKeyType();
virtual GxsMessageFrameWidget *createMessageFrameWidget(const RsGxsGroupId &groupId);
virtual void groupTreeCustomActions(RsGxsGroupId grpId, int subscribeFlags, QList<QAction*> &actions);
};
#endif

View file

@ -1,314 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GxsChannelDialog</class>
<widget class="QWidget" name="GxsChannelDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>681</width>
<height>476</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QFrame" name="channelTreeFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_9">
<property name="verticalSpacing">
<number>1</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QFrame" name="titleBarFrame">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="titleBarPixmap">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/channels32.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="titleBarLabel">
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Channels</string>
</property>
</widget>
</item>
<item>
<spacer name="spacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="todoPushButton">
<property name="text">
<string>Todo</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="GroupTreeWidget" name="treeWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<layout class="QGridLayout" name="channelLayout">
<item row="0" column="0">
<widget class="QFrame" name="headFrame">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="margin">
<number>4</number>
</property>
<item>
<widget class="QLabel" name="logoLabel">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/channels.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="nameLabel">
<property name="palette">
<palette>
<active/>
<inactive/>
<disabled/>
</palette>
</property>
<property name="font">
<font>
<pointsize>21</pointsize>
</font>
</property>
<property name="text">
<string notr="true">Channel Name</string>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>389</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
</layout>
</widget>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="progressLayout">
<item>
<widget class="QLabel" name="progressLabel">
<property name="text">
<string>Loading</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>24</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QFrame" name="toolBarFrame">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="margin">
<number>2</number>
</property>
<item>
<widget class="QToolButton" name="postButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Post to Channel</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/mail_send.png</normaloff>:/images/mail_send.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>314</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
<action name="actionsetAllAsRead">
<property name="text">
<string>Set all as read</string>
</property>
<property name="toolTip">
<string>Set all as read</string>
</property>
</action>
<action name="actionEnable_Auto_Download">
<property name="text">
<string>Enable Auto-Download</string>
</property>
<property name="toolTip">
<string>Enable Auto-Download</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>GroupTreeWidget</class>
<extends>QWidget</extends>
<header>gui/common/GroupTreeWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -0,0 +1,616 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2008 Robert Fernie
*
* 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 "GxsChannelPostsWidget.h"
#include "ui_GxsChannelPostsWidget.h"
#include "gui/feeds/GxsChannelPostItem.h"
#include "gui/gxschannels/CreateGxsChannelMsg.h"
#include "gui/common/UIStateHelper.h"
#define CHAN_DEFAULT_IMAGE ":/images/channels.png"
#define WARNING_LIMIT 3600*24*2
/* Images for TreeWidget */
#define IMAGE_CHANNELBLUE ":/images/channelsblue.png"
#define IMAGE_CHANNELGREEN ":/images/channelsgreen.png"
#define IMAGE_CHANNELRED ":/images/channelsred.png"
#define IMAGE_CHANNELYELLOW ":/images/channelsyellow.png"
/****
* #define DEBUG_CHANNEL
***/
#define USE_THREAD
#define TOKEN_TYPE_MESSAGE_CHANGE 4
#define TOKEN_TYPE_GROUP_DATA 6
#define TOKEN_TYPE_POSTS 7
/** Constructor */
GxsChannelPostsWidget::GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWidget *parent)
: GxsMessageFrameWidget(rsGxsChannels, parent),
ui(new Ui::GxsChannelPostsWidget)
{
/* Invoke the Qt Designer generated object setup routine */
ui->setupUi(this);
/* Setup UI helper */
mStateHelper = new UIStateHelper(this);
mStateHelper->addWidget(TOKEN_TYPE_POSTS, ui->progressBar, UISTATE_LOADING_VISIBLE);
mStateHelper->addWidget(TOKEN_TYPE_POSTS, ui->progressLabel, UISTATE_LOADING_VISIBLE);
mStateHelper->addLoadPlaceholder(TOKEN_TYPE_GROUP_DATA, ui->nameLabel);
mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->postButton);
mStateHelper->addWidget(TOKEN_TYPE_GROUP_DATA, ui->logoLabel);
mChannelQueue = new TokenQueue(rsGxsChannels->getTokenService(), this);
connect(ui->postButton, SIGNAL(clicked()), this, SLOT(createMsg()));
// connect(NotifyQt::getInstance(), SIGNAL(channelMsgReadSatusChanged(QString,QString,int)), this, SLOT(channelMsgReadSatusChanged(QString,QString,int)));
/*************** Setup Left Hand Side (List of Channels) ****************/
ui->progressLabel->hide();
ui->progressBar->hide();
ui->nameLabel->setMinimumWidth(20);
/* load settings */
processSettings(true);
/* Initialize GUI */
setGroupId(channelId);
}
GxsChannelPostsWidget::~GxsChannelPostsWidget()
{
// save settings
processSettings(false);
}
void GxsChannelPostsWidget::updateDisplay(bool complete)
{
if (complete) {
/* Not needed */
return;
}
std::list<RsGxsGroupId> &grpIds = getGrpIds();
if (!mChannelId.isNull() && std::find(grpIds.begin(), grpIds.end(), mChannelId) != grpIds.end()) {
requestGroupData(mChannelId);
} else {
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> > &msgs = getMsgIds();
if (!msgs.empty())
{
std::map<RsGxsGroupId, std::vector<RsGxsMessageId> >::iterator mit = msgs.find(mChannelId);
if(mit != msgs.end())
{
requestPosts(mChannelId);
}
}
}
}
//UserNotify *GxsChannelPostsWidget::getUserNotify(QObject *parent)
//{
// return new ChannelUserNotify(parent);
//}
void GxsChannelPostsWidget::processSettings(bool load)
{
// Settings->beginGroup(QString("GxsChannelDialog"));
//
// if (load) {
// // load settings
// } else {
// // save settings
// }
//
// Settings->endGroup();
}
void GxsChannelPostsWidget::setGroupId(const RsGxsGroupId &groupId)
{
if (mChannelId == groupId) {
if (!groupId.isNull()) {
return;
}
}
mChannelId = groupId;
ui->nameLabel->setText(mChannelId.isNull () ? "" : tr("Loading"));
emit groupChanged(this);
requestGroupData(mChannelId);
}
QString GxsChannelPostsWidget::groupName(bool withUnreadCount)
{
QString name = mChannelId.isNull () ? tr("No name") : ui->nameLabel->text();
// if (withUnreadCount && mUnreadCount) {
// name += QString(" (%1)").arg(mUnreadCount);
// }
return name;
}
QIcon GxsChannelPostsWidget::groupIcon()
{
if (mStateHelper->isLoading(TOKEN_TYPE_POSTS)) {
return QIcon(":/images/kalarm.png");
}
// if (mNewCount) {
// return QIcon(":/images/message-state-new.png");
// }
return QIcon();
}
/*************************************************************************************/
/*************************************************************************************/
/*************************************************************************************/
QScrollArea *GxsChannelPostsWidget::getScrollArea()
{
return ui->scrollArea;
}
void GxsChannelPostsWidget::deleteFeedItem(QWidget * /*item*/, uint32_t /*type*/)
{
}
void GxsChannelPostsWidget::openChat(const RsPeerId & /*peerId*/)
{
}
// Callback from Widget->FeedHolder->ServiceDialog->CommentContainer->CommentDialog,
void GxsChannelPostsWidget::openComments(uint32_t /*type*/, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &title)
{
emit commentLoad(groupId, msgId, title);
}
void GxsChannelPostsWidget::createMsg()
{
if (mChannelId.isNull()) {
return;
}
CreateGxsChannelMsg *msgDialog = new CreateGxsChannelMsg(mChannelId);
msgDialog->show();
/* window will destroy itself! */
}
//void GxsChannelPostsWidget::channelMsgReadSatusChanged(const QString& channelId, const QString& /*msgId*/, int /*status*/)
//{
// updateMessageSummaryList(channelId.toStdString());
//}
void GxsChannelPostsWidget::insertChannelDetails(const RsGxsChannelGroup &group)
{
mStateHelper->setActive(TOKEN_TYPE_GROUP_DATA, true);
/* IMAGE */
QPixmap chanImage;
if (group.mImage.mData != NULL) {
chanImage.loadFromData(group.mImage.mData, group.mImage.mSize, "PNG");
} else {
chanImage = QPixmap(CHAN_DEFAULT_IMAGE);
}
ui->logoLabel->setPixmap(chanImage);
/* set Channel name */
ui->nameLabel->setText(QString::fromUtf8(group.mMeta.mGroupName.c_str()));
if (group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH)
{
mStateHelper->setWidgetEnabled(ui->postButton, true);
}
else
{
mStateHelper->setWidgetEnabled(ui->postButton, false);
}
setAutoDownloadButton(group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED);
emit groupChanged(this);
requestPosts(mChannelId);
}
void GxsChannelPostsWidget::insertChannelPosts(const std::vector<RsGxsChannelPost> &posts)
{
std::vector<RsGxsChannelPost>::const_iterator it;
// Do these need sorting? probably.
// can we add that into the request?
//msgs.sort(sortChannelMsgSummary);
uint32_t subscribeFlags = 0xffffffff;
for (it = posts.begin(); it != posts.end(); it++)
{
GxsChannelPostItem *item = new GxsChannelPostItem(this, 0, *it, subscribeFlags, true);
mChannelPostItems.push_back(item);
ui->verticalLayout->addWidget(item);
}
}
#if 0
void GxsChannelPostsWidget::updateChannelMsgs()
{
if (fillThread) {
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::updateChannelMsgs() stop current fill thread" << std::endl;
#endif
// stop current fill thread
GxsChannelFillThread *thread = fillThread;
fillThread = NULL;
thread->stop();
delete(thread);
progressLabel->hide();
progressBar->hide();
}
if (!rsChannels) {
return;
}
/* replace all the messages with new ones */
QList<ChanMsgItem *>::iterator mit;
for (mit = mChanMsgItems.begin(); mit != mChanMsgItems.end(); mit++) {
delete (*mit);
}
mChanMsgItems.clear();
ChannelInfo ci;
if (!rsChannels->getChannelInfo(mChannelId, ci)) {
postButton->setEnabled(false);
nameLabel->setText(tr("No Channel Selected"));
logoLabel->setPixmap(QPixmap(":/images/channels.png"));
logoLabel->setEnabled(false);
return;
}
QPixmap chanImage;
if (ci.pngImageLen != 0) {
chanImage.loadFromData(ci.pngChanImage, ci.pngImageLen, "PNG");
} else {
chanImage = QPixmap(CHAN_DEFAULT_IMAGE);
}
logoLabel->setPixmap(chanImage);
logoLabel->setEnabled(true);
/* set Channel name */
nameLabel->setText(QString::fromStdWString(ci.channelName));
if (ci.channelFlags & RS_DISTRIB_PUBLISH) {
postButton->setEnabled(true);
} else {
postButton->setEnabled(false);
}
if (!(ci.channelFlags & RS_DISTRIB_ADMIN) &&
(ci.channelFlags & RS_DISTRIB_SUBSCRIBED)) {
actionEnable_Auto_Download->setEnabled(true);
} else {
actionEnable_Auto_Download->setEnabled(false);
}
#ifdef USE_THREAD
progressLabel->show();
progressBar->reset();
progressBar->show();
// create fill thread
fillThread = new GxsChannelFillThread(this, mChannelId);
// connect thread
connect(fillThread, SIGNAL(finished()), this, SLOT(fillThreadFinished()), Qt::BlockingQueuedConnection);
connect(fillThread, SIGNAL(addMsg(QString,QString,int,int)), this, SLOT(fillThreadAddMsg(QString,QString,int,int)), Qt::BlockingQueuedConnection);
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::updateChannelMsgs() Start fill thread" << std::endl;
#endif
// start thread
fillThread->start();
#else
std::list<ChannelMsgSummary> msgs;
std::list<ChannelMsgSummary>::iterator it;
rsChannels->getChannelMsgList(mChannelId, msgs);
msgs.sort(sortChannelMsgSummary);
for (it = msgs.begin(); it != msgs.end(); it++) {
ChanMsgItem *cmi = new ChanMsgItem(this, 0, mChannelId, it->msgId, true);
mChanMsgItems.push_back(cmi);
verticalLayout_2->addWidget(cmi);
}
#endif
}
void GxsChannelPostsWidget::fillThreadFinished()
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::fillThreadFinished()" << std::endl;
#endif
// thread has finished
GxsChannelFillThread *thread = dynamic_cast<GxsChannelFillThread*>(sender());
if (thread) {
if (thread == fillThread) {
// current thread has finished, hide progressbar and release thread
progressBar->hide();
progressLabel->hide();
fillThread = NULL;
}
#ifdef DEBUG_CHANNEL
if (thread->wasStopped()) {
// thread was stopped
std::cerr << "GxsChannelPostsWidget::fillThreadFinished() Thread was stopped" << std::endl;
}
#endif
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::fillThreadFinished() Delete thread" << std::endl;
#endif
thread->deleteLater();
thread = NULL;
}
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::fillThreadFinished done()" << std::endl;
#endif
}
void GxsChannelPostsWidget::fillThreadAddMsg(const QString &channelId, const QString &channelMsgId, int current, int count)
{
if (sender() == fillThread) {
// show fill progress
if (count) {
progressBar->setValue(current * progressBar->maximum() / count);
}
lockLayout(NULL, true);
ChanMsgItem *cmi = new ChanMsgItem(this, 0, channelId.toStdString(), channelMsgId.toStdString(), true);
mChanMsgItems.push_back(cmi);
verticalLayout->addWidget(cmi);
cmi->show();
lockLayout(cmi, false);
}
}
#endif
void GxsChannelPostsWidget::setAllMessagesRead(bool read)
{
#if 0
if (mChannelId.isNull()) {
return;
}
if (!rsChannels) {
return;
}
ChannelInfo ci;
if (rsChannels->getChannelInfo(mChannelId, ci) == false) {
return;
}
if (ci.channelFlags & RS_DISTRIB_SUBSCRIBED) {
std::list<ChannelMsgSummary> msgs;
std::list<ChannelMsgSummary>::iterator it;
rsChannels->getChannelMsgList(mChannelId, msgs);
for(it = msgs.begin(); it != msgs.end(); it++) {
rsChannels->setMessageStatus(mChannelId, it->msgId, CHANNEL_MSG_STATUS_READ, CHANNEL_MSG_STATUS_READ | CHANNEL_MSG_STATUS_UNREAD_BY_USER);
}
}
#endif
}
void GxsChannelPostsWidget::setAutoDownloadButton(bool autoDl)
{
if (autoDl) {
ui->actionEnable_Auto_Download->setText(tr("Disable Auto-Download"));
}else{
ui->actionEnable_Auto_Download->setText(tr("Enable Auto-Download"));
}
}
/**********************************************************************************************
* New Stuff here.
*************/
/*********************** **** **** **** ***********************/
/** Request / Response of Data ********************************/
/*********************** **** **** **** ***********************/
void GxsChannelPostsWidget::requestGroupData(const RsGxsGroupId &grpId)
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::requestGroupData()";
std::cerr << std::endl;
#endif
mChannelQueue->cancelActiveRequestTokens(TOKEN_TYPE_GROUP_DATA);
if (grpId.isNull()) {
mStateHelper->setActive(TOKEN_TYPE_GROUP_DATA, false);
mStateHelper->setLoading(TOKEN_TYPE_GROUP_DATA, false);
mStateHelper->clear(TOKEN_TYPE_GROUP_DATA);
ui->nameLabel->setText(tr("No Channel Selected"));
ui->logoLabel->setPixmap(QPixmap(":/images/channels.png"));
emit groupChanged(this);
return;
}
mStateHelper->setLoading(TOKEN_TYPE_GROUP_DATA, true);
emit groupChanged(this);
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(grpId);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
uint32_t token;
mChannelQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, TOKEN_TYPE_GROUP_DATA);
}
void GxsChannelPostsWidget::loadGroupData(const uint32_t &token)
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::loadGroupData()";
std::cerr << std::endl;
#endif
std::vector<RsGxsChannelGroup> groups;
rsGxsChannels->getGroupData(token, groups);
mStateHelper->setLoading(TOKEN_TYPE_GROUP_DATA, false);
if (groups.size() == 1)
{
insertChannelDetails(groups[0]);
}
else
{
std::cerr << "GxsChannelPostsWidget::loadGroupData() ERROR Not just one Group";
std::cerr << std::endl;
mStateHelper->setActive(TOKEN_TYPE_GROUP_DATA, false);
mStateHelper->clear(TOKEN_TYPE_GROUP_DATA);
emit groupChanged(this);
}
}
void GxsChannelPostsWidget::requestPosts(const RsGxsGroupId &grpId)
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::requestPosts()";
std::cerr << std::endl;
#endif
/* replace all the messages with new ones */
QList<GxsChannelPostItem *>::iterator mit;
for (mit = mChannelPostItems.begin(); mit != mChannelPostItems.end(); mit++) {
delete (*mit);
}
mChannelPostItems.clear();
mChannelQueue->cancelActiveRequestTokens(TOKEN_TYPE_POSTS);
if (grpId.isNull()) {
mStateHelper->setActive(TOKEN_TYPE_POSTS, false);
mStateHelper->setLoading(TOKEN_TYPE_POSTS, false);
mStateHelper->clear(TOKEN_TYPE_POSTS);
return;
}
mStateHelper->setLoading(TOKEN_TYPE_POSTS, true);
std::list<RsGxsGroupId> groupIds;
groupIds.push_back(grpId);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
uint32_t token;
mChannelQueue->requestMsgInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, groupIds, TOKEN_TYPE_POSTS);
}
void GxsChannelPostsWidget::loadPosts(const uint32_t &token)
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::loadPosts()";
std::cerr << std::endl;
#endif
std::vector<RsGxsChannelPost> posts;
rsGxsChannels->getPostData(token, posts);
mStateHelper->setActive(TOKEN_TYPE_POSTS, true);
insertChannelPosts(posts);
mStateHelper->setLoading(TOKEN_TYPE_POSTS, false);
}
void GxsChannelPostsWidget::acknowledgeMessageUpdate(const uint32_t &token)
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::acknowledgeMessageUpdate() TODO";
std::cerr << std::endl;
#endif
std::pair<RsGxsGroupId, RsGxsMessageId> msgId;
rsGxsChannels->acknowledgeMsg(token, msgId);
if (msgId.first == mChannelId)
{
requestPosts(mChannelId);
}
}
void GxsChannelPostsWidget::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
#ifdef DEBUG_CHANNEL
std::cerr << "GxsChannelPostsWidget::loadRequest() UserType: " << req.mUserType;
std::cerr << std::endl;
#endif
if (queue == mChannelQueue)
{
/* now switch on req */
switch(req.mUserType)
{
case TOKEN_TYPE_MESSAGE_CHANGE:
acknowledgeMessageUpdate(req.mToken);
break;
case TOKEN_TYPE_GROUP_DATA:
loadGroupData(req.mToken);
break;
case TOKEN_TYPE_POSTS:
loadPosts(req.mToken);
break;
default:
std::cerr << "GxsChannelPostsWidget::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
break;
}
}
}

View file

@ -0,0 +1,115 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2008 Robert Fernie
*
* 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 _GXS_CHANNELPOSTSWIDGET_H
#define _GXS_CHANNELPOSTSWIDGET_H
#include <map>
#include "gui/gxs/GxsMessageFrameWidget.h"
#include "gui/feeds/FeedHolder.h"
#include "util/TokenQueue.h"
namespace Ui {
class GxsChannelPostsWidget;
}
//class ChanMsgItem;
class GxsChannelPostItem;
class QTreeWidgetItem;
class UIStateHelper;
class QBoxLayout;
class GxsChannelPostsWidget : public GxsMessageFrameWidget, public TokenResponse, public FeedHolder
{
Q_OBJECT
public:
/** Default Constructor */
GxsChannelPostsWidget(const RsGxsGroupId &channelId, QWidget *parent = 0);
/** Default Destructor */
~GxsChannelPostsWidget();
/* GxsMessageFrameWidget */
virtual RsGxsGroupId groupId() { return mChannelId; }
virtual void setGroupId(const RsGxsGroupId &channelId);
virtual QString groupName(bool withUnreadCount);
virtual QIcon groupIcon();
virtual void setAllMessagesRead(bool read);
/* FeedHolder */
virtual QScrollArea *getScrollArea();
virtual void deleteFeedItem(QWidget *item, uint32_t type);
virtual void openChat(const RsPeerId& peerId);
virtual void openComments(uint32_t type, const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &title);
/* NEW GXS FNS */
void loadRequest(const TokenQueue *queue, const TokenRequest &req);
signals:
void commentLoad(const RsGxsGroupId &groupId, const RsGxsMessageId &msgId, const QString &title);
protected:
virtual void updateDisplay(bool complete);
private slots:
void createMsg();
//void fillThreadFinished();
//void fillThreadAddMsg(const QString &channelId, const QString &channelMsgId, int current, int count);
private:
void processSettings(bool load);
void setAutoDownloadButton(bool autoDl);
/* NEW GXS FNS */
void requestGroupData(const RsGxsGroupId &grpId);
void loadGroupData(const uint32_t &token);
void requestPosts(const RsGxsGroupId &grpId);
void loadPosts(const uint32_t &token);
void insertChannelDetails(const RsGxsChannelGroup &group);
void insertChannelPosts(const std::vector<RsGxsChannelPost> &posts);
void acknowledgeMessageUpdate(const uint32_t &token);
RsGxsGroupId mChannelId; /* current Channel */
TokenQueue *mChannelQueue;
/* Layout Pointers */
QBoxLayout *mMsgLayout;
//QList<ChanMsgItem *> mChanMsgItems;
QList<GxsChannelPostItem *> mChannelPostItems;
std::map<std::string, uint32_t> mChanSearchScore; //chanId, score
UIStateHelper *mStateHelper;
/* UI - from Designer */
Ui::GxsChannelPostsWidget *ui;
};
#endif

View file

@ -0,0 +1,248 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GxsChannelPostsWidget</class>
<widget class="QWidget" name="GxsChannelPostsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>681</width>
<height>476</height>
</rect>
</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>
<item>
<widget class="QFrame" name="headFrame">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QLabel" name="logoLabel">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/channels.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="nameLabel">
<property name="palette">
<palette>
<active/>
<inactive/>
<disabled/>
</palette>
</property>
<property name="font">
<font>
<pointsize>21</pointsize>
</font>
</property>
<property name="text">
<string notr="true">Channel Name</string>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="toolBarFrame">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<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="postButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Post to Channel</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/mail_send.png</normaloff>:/images/mail_send.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>314</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="progressLayout">
<item>
<widget class="QLabel" name="progressLabel">
<property name="text">
<string>Loading</string>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressBar">
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>24</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>679</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<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>
</widget>
</item>
</layout>
<action name="actionsetAllAsRead">
<property name="text">
<string>Set all as read</string>
</property>
<property name="toolTip">
<string>Set all as read</string>
</property>
</action>
<action name="actionEnable_Auto_Download">
<property name="text">
<string>Enable Auto-Download</string>
</property>
<property name="toolTip">
<string>Enable Auto-Download</string>
</property>
</action>
<zorder>toolBarFrame</zorder>
<zorder>scrollArea</zorder>
<zorder></zorder>
<zorder>headFrame</zorder>
<zorder>toolBarFrame</zorder>
<zorder>scrollArea</zorder>
<zorder></zorder>
<zorder>headFrame</zorder>
</widget>
<resources>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>