Enabled creating forum messages in FeedReader plugin

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7706 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2014-11-24 22:40:29 +00:00
parent 30d9671ca6
commit 069e8e490a
8 changed files with 422 additions and 246 deletions

View file

@ -28,20 +28,28 @@
#include "PreviewFeedDialog.h"
#include "FeedReaderStringDefs.h"
#include "gui/settings/rsharesettings.h"
#include "gui/common/UIStateHelper.h"
//Todo: Replace with gxs forums
//#include "retroshare/rsforums.h"
#include <retroshare/rsgxsforums.h>
#include <iostream>
//bool sortForumInfo(const ForumInfo& info1, const ForumInfo& info2)
//{
// return QString::fromStdWString(info1.forumName).compare(QString::fromStdWString(info2.forumName), Qt::CaseInsensitive);
//}
#define TOKEN_TYPE_FORUM_GROUPS 1
AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent)
: QDialog(parent, Qt::Window), mFeedReader(feedReader), mNotify(notify), ui(new Ui::AddFeedDialog)
{
ui->setupUi(this);
/* Setup UI helper */
mStateHelper = new UIStateHelper(this);
mStateHelper->addWidget(TOKEN_TYPE_FORUM_GROUPS, ui->forumComboBox, UISTATE_LOADING_DISABLED);
mStateHelper->addWidget(TOKEN_TYPE_FORUM_GROUPS, ui->buttonBox->button(QDialogButtonBox::Ok), UISTATE_LOADING_DISABLED);
/* Setup TokenQueue */
mTokenQueue = new TokenQueue(rsGxsForums->getTokenService(), this);
/* Connect signals */
connect(ui->buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(createFeed()));
connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
@ -52,7 +60,7 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
connect(ui->typeForumRadio, SIGNAL(toggled(bool)), this, SLOT(typeForumToggled()));
connect(ui->previewButton, SIGNAL(clicked()), this, SLOT(preview()));
/* currently only for loacl feeds */
/* currently only for local feeds */
connect(ui->saveCompletePageCheckBox, SIGNAL(toggled(bool)), this, SLOT(denyForumToggled()));
connect(ui->urlLineEdit, SIGNAL(textChanged(QString)), this, SLOT(validate()));
@ -60,16 +68,18 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
connect(ui->useInfoFromFeedCheckBox, SIGNAL(toggled(bool)), this, SLOT(validate()));
connect(ui->typeLocalRadio, SIGNAL(toggled(bool)), this, SLOT(validate()));
connect(ui->typeForumRadio, SIGNAL(toggled(bool)), this, SLOT(validate()));
connect(ui->forumComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(validate()));
connect(ui->clearCachePushButton, SIGNAL(clicked()), this, SLOT(clearMessageCache()));
ui->headerFrame->setHeaderText(tr("Feed Details"));
ui->headerFrame->setHeaderImage(QPixmap(":/images/FeedReader.png"));
ui->activatedCheckBox->setChecked(true);
ui->forumComboBox->setEnabled(false);
mStateHelper->setWidgetEnabled(ui->forumComboBox, false);
ui->useInfoFromFeedCheckBox->setChecked(true);
ui->updateForumInfoCheckBox->setEnabled(false);
ui->updateForumInfoCheckBox->setChecked(true);
ui->forumNameLabel->hide();
ui->useAuthenticationCheckBox->setChecked(false);
ui->useStandardStorageTimeCheckBox->setChecked(true);
ui->useStandardUpdateInterval->setChecked(true);
@ -81,22 +91,10 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
mTransformationType = RS_FEED_TRANSFORMATION_TYPE_NONE;
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
ui->clearCachePushButton->show();
/* fill own forums */
//Todo: Replace with gxs forums
// std::list<ForumInfo> forumList;
// if (rsForums->getForumList(forumList)) {
// forumList.sort(sortForumInfo);
// for (std::list<ForumInfo>::iterator it = forumList.begin(); it != forumList.end(); ++it) {
// ForumInfo &forumInfo = *it;
// /* show only own anonymous forums */
// if ((forumInfo.subscribeFlags & RS_DISTRIB_ADMIN) && (forumInfo.forumFlags & RS_DISTRIB_AUTHEN_ANON)) {
// ui->forumComboBox->addItem(QString::fromStdWString(forumInfo.forumName), QString::fromStdString(forumInfo.forumId));
// }
// }
// }
/* insert item to create a new forum */
ui->forumComboBox->insertItem(0, tr("Create a new anonymous public forum"), "");
ui->forumComboBox->setCurrentIndex(0);
requestForumGroups();
validate();
@ -104,9 +102,6 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
/* load settings */
processSettings(true);
//Todo: Replace with gxs forums
ui->typeForumRadio->setEnabled(false);
}
AddFeedDialog::~AddFeedDialog()
@ -114,7 +109,8 @@ AddFeedDialog::~AddFeedDialog()
/* save settings */
processSettings(false);
delete ui;
delete(ui);
delete(mTokenQueue);
}
void AddFeedDialog::processSettings(bool load)
@ -164,7 +160,7 @@ void AddFeedDialog::useStandardProxyToggled()
void AddFeedDialog::typeForumToggled()
{
bool checked = ui->typeForumRadio->isChecked();
ui->forumComboBox->setEnabled(checked);
mStateHelper->setWidgetEnabled(ui->forumComboBox, checked);
ui->updateForumInfoCheckBox->setEnabled(checked);
}
@ -195,7 +191,11 @@ void AddFeedDialog::validate()
ok = false;
}
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
if (ui->typeForumRadio->isChecked() && ui->forumComboBox->itemData(ui->forumComboBox->currentIndex()).toString().isEmpty()) {
ok = false;
}
mStateHelper->setWidgetEnabled(ui->buttonBox->button(QDialogButtonBox::Ok), ok);
}
void AddFeedDialog::setParent(const std::string &parentId)
@ -215,7 +215,6 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
}
setWindowTitle(tr("Edit feed"));
ui->typeGroupBox->setEnabled(false);
mParentId = feedInfo.parentId;
@ -229,28 +228,15 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
ui->descriptionPlainTextEdit->setPlainText(QString::fromUtf8(feedInfo.description.c_str()));
ui->typeGroupBox->setEnabled(false);
ui->forumComboBox->hide();
ui->forumNameLabel->clear();
ui->forumNameLabel->show();
if (feedInfo.flag.forum) {
mStateHelper->setWidgetEnabled(ui->forumComboBox, true);
ui->typeForumRadio->setChecked(true);
ui->saveCompletePageCheckBox->setEnabled(false);
if (feedInfo.forumId.empty()) {
ui->forumNameLabel->setText(tr("Not yet created"));
} else {
//Todo: Replace with gxs forums
// ForumInfo forumInfo;
// if (rsForums->getForumInfo(feedInfo.forumId, forumInfo)) {
// ui->forumNameLabel->setText(QString::fromStdWString(forumInfo.forumName));
// } else {
// ui->forumNameLabel->setText(tr("Unknown forum"));
// }
}
setActiveForumId(feedInfo.forumId);
} else {
ui->typeLocalRadio->setChecked(true);
mStateHelper->setWidgetEnabled(ui->forumComboBox, false);
}
ui->useAuthenticationCheckBox->setChecked(feedInfo.flag.authentication);
@ -276,11 +262,28 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
mXslt = feedInfo.xslt;
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
ui->clearCachePushButton->show();
}
return true;
}
void AddFeedDialog::setActiveForumId(const std::string &forumId)
{
if (mStateHelper->isLoading(TOKEN_TYPE_FORUM_GROUPS)) {
mFillForumId = forumId;
return;
}
int index = ui->forumComboBox->findData(QString::fromStdString(forumId));
if (index >= 0) {
ui->forumComboBox->setCurrentIndex(index);
} else {
ui->forumComboBox->setCurrentIndex(0);
}
}
void AddFeedDialog::getFeedInfo(FeedInfo &feedInfo)
{
feedInfo.parentId = mParentId;
@ -296,11 +299,9 @@ void AddFeedDialog::getFeedInfo(FeedInfo &feedInfo)
feedInfo.description = ui->descriptionPlainTextEdit->toPlainText().toUtf8().constData();
feedInfo.flag.forum = ui->typeForumRadio->isChecked();
if (mFeedId.empty()) {
if (feedInfo.flag.forum) {
/* set forum (only when create a new feed) */
feedInfo.forumId = ui->forumComboBox->itemData(ui->forumComboBox->currentIndex()).toString().toStdString();
}
if (feedInfo.flag.forum) {
feedInfo.forumId = ui->forumComboBox->itemData(ui->forumComboBox->currentIndex()).toString().toStdString();
}
feedInfo.flag.authentication = ui->useAuthenticationCheckBox->isChecked();
@ -362,3 +363,72 @@ void AddFeedDialog::preview()
ui->transformationTypeLabel->setText(FeedReaderStringDefs::transforationTypeString(mTransformationType));
}
}
void AddFeedDialog::clearMessageCache()
{
if (mFeedId.empty()) {
return;
}
mFeedReader->clearMessageCache(mFeedId);
}
void AddFeedDialog::requestForumGroups()
{
mStateHelper->setLoading(TOKEN_TYPE_FORUM_GROUPS, true);
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_GROUP_DATA;
mTokenQueue->cancelActiveRequestTokens(TOKEN_TYPE_FORUM_GROUPS);
uint32_t token;
mTokenQueue->requestGroupInfo(token, RS_TOKREQ_ANSTYPE_DATA, opts, TOKEN_TYPE_FORUM_GROUPS);
}
void AddFeedDialog::loadForumGroups(const uint32_t &token)
{
std::vector<RsGxsForumGroup> groups;
rsGxsForums->getGroupData(token, groups);
ui->forumComboBox->clear();
for (std::vector<RsGxsForumGroup>::iterator it = groups.begin(); it != groups.end(); ++it) {
const RsGxsForumGroup &group = *it;
/* show only own forums */
if (IS_GROUP_PUBLISHER(group.mMeta.mSubscribeFlags) && IS_GROUP_ADMIN(group.mMeta.mSubscribeFlags)) {
ui->forumComboBox->addItem(QString::fromUtf8(group.mMeta.mGroupName.c_str()), QString::fromStdString(group.mMeta.mGroupId.toStdString()));
}
}
/* insert empty item */
ui->forumComboBox->insertItem(0, "", "");
ui->forumComboBox->setCurrentIndex(0);
mStateHelper->setLoading(TOKEN_TYPE_FORUM_GROUPS, false);
if (!mFillForumId.empty()) {
setActiveForumId(mFillForumId);
mFillForumId.clear();
}
}
void AddFeedDialog::loadRequest(const TokenQueue *queue, const TokenRequest &req)
{
if (queue == mTokenQueue)
{
/* now switch on req */
switch(req.mUserType)
{
case TOKEN_TYPE_FORUM_GROUPS:
loadForumGroups(req.mToken);
break;
default:
std::cerr << "AddFeedDialog::loadRequest() ERROR: INVALID TYPE";
std::cerr << std::endl;
}
}
}

View file

@ -24,6 +24,7 @@
#include <QDialog>
#include "interface/rsFeedReader.h"
#include "util/TokenQueue.h"
namespace Ui {
class AddFeedDialog;
@ -31,8 +32,9 @@ class AddFeedDialog;
class RsFeedReader;
class FeedReaderNotify;
class UIStateHelper;
class AddFeedDialog : public QDialog
class AddFeedDialog : public QDialog, public TokenResponse
{
Q_OBJECT
@ -43,6 +45,9 @@ public:
void setParent(const std::string &parentId);
bool fillFeed(const std::string &feedId);
/* TokenResponse */
virtual void loadRequest(const TokenQueue *queue, const TokenRequest &req);
private slots:
void authenticationToggled();
void useStandardStorageTimeToggled();
@ -53,21 +58,31 @@ private slots:
void validate();
void createFeed();
void preview();
void clearMessageCache();
private:
void processSettings(bool load);
void getFeedInfo(FeedInfo &feedInfo);
void setActiveForumId(const std::string &forumId);
void requestForumGroups();
void loadForumGroups(const uint32_t &token);
private:
RsFeedReader *mFeedReader;
FeedReaderNotify *mNotify;
std::string mFeedId;
std::string mParentId;
std::string mFillForumId;
RsFeedTransformationType mTransformationType;
std::list<std::string> mXPathsToUse;
std::list<std::string> mXPathsToRemove;
std::string mXslt;
TokenQueue *mTokenQueue;
UIStateHelper *mStateHelper;
Ui::AddFeedDialog *ui;
};

View file

@ -14,7 +14,7 @@
<string>Create new feed</string>
</property>
<property name="windowIcon">
<iconset resource="../../../retroshare-gui/src/gui/images.qrc">
<iconset>
<normaloff>:/images/rstray3.png</normaloff>:/images/rstray3.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -75,19 +75,6 @@
<item>
<widget class="QComboBox" name="forumComboBox"/>
</item>
<item>
<widget class="QLabel" name="forumNameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">Forum name</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -146,13 +133,6 @@
<string>Storage time</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="useStandardStorageTimeCheckBox">
<property name="text">
<string>Use standard storage time</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="storageTimeLabel">
<property name="text">
@ -173,6 +153,20 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="useStandardStorageTimeCheckBox">
<property name="text">
<string>Use standard storage time</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="clearCachePushButton">
<property name="text">
<string>Clear cache</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -433,8 +427,6 @@
<tabstop>proxyPortSpinBox</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources>
<include location="../../../retroshare-gui/src/gui/images.qrc"/>
</resources>
<resources/>
<connections/>
</ui>

View file

@ -119,9 +119,6 @@ QString FeedReaderStringDefs::errorString(RsFeedReaderErrorState errorState, con
case RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN:
errorText = QApplication::translate("FeedReaderStringDefs", "You are not admin of the forum");
break;
case RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_ANONYMOUS:
errorText = QApplication::translate("FeedReaderStringDefs", "The forum is no anonymous forum");
break;
case RS_FEED_ERRORSTATE_PROCESS_HTML_ERROR:
errorText = QApplication::translate("FeedReaderStringDefs", "Can't read html");