FeedReader plugin:

- added new classes for XML/HTML parse and modify
- added basic error handling
- added new GUI for a preview and a tree to show the structure of the page (will be continued)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5412 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-08-13 21:35:11 +00:00
parent acaefada65
commit f51af0d4de
24 changed files with 1959 additions and 509 deletions

View file

@ -25,6 +25,9 @@
#include "AddFeedDialog.h"
#include "ui_AddFeedDialog.h"
#include "PreviewFeedDialog.h"
#include "FeedReaderStringDefs.h"
#include "retroshare/rsforums.h"
bool sortForumInfo(const ForumInfo& info1, const ForumInfo& info2)
@ -32,8 +35,8 @@ bool sortForumInfo(const ForumInfo& info1, const ForumInfo& info2)
return QString::fromStdWString(info1.forumName).compare(QString::fromStdWString(info2.forumName), Qt::CaseInsensitive);
}
AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, QWidget *parent)
: QDialog(parent), mFeedReader(feedReader), ui(new Ui::AddFeedDialog)
AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent)
: QDialog(parent), mFeedReader(feedReader), mNotify(notify), ui(new Ui::AddFeedDialog)
{
ui->setupUi(this);
@ -45,6 +48,7 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, QWidget *parent)
connect(ui->useStandardUpdateInterval, SIGNAL(toggled(bool)), this, SLOT(useStandardUpdateIntervalToggled()));
connect(ui->useStandardProxyCheckBox, SIGNAL(toggled(bool)), this, SLOT(useStandardProxyToggled()));
connect(ui->typeForumRadio, SIGNAL(toggled(bool)), this, SLOT(typeForumToggled()));
connect(ui->previewButton, SIGNAL(clicked()), this, SLOT(preview()));
/* currently only for loacl feeds */
connect(ui->saveCompletePageCheckBox, SIGNAL(toggled(bool)), this, SLOT(denyForumToggled()));
@ -149,6 +153,9 @@ void AddFeedDialog::validate()
if (ui->nameLineEdit->text().isEmpty() && !ui->useInfoFromFeedCheckBox->isChecked()) {
ok = false;
}
ui->previewButton->setEnabled(ok);
if (!ui->typeLocalRadio->isChecked() && !ui->typeForumRadio->isChecked()) {
ok = false;
}
@ -156,38 +163,6 @@ void AddFeedDialog::validate()
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok);
}
bool AddFeedDialog::showError(QWidget *parent, RsFeedAddResult result, const QString &title, const QString &text)
{
QString error;
switch (result) {
case RS_FEED_ADD_RESULT_SUCCESS:
/* no error */
return false;
case RS_FEED_ADD_RESULT_FEED_NOT_FOUND:
error = tr("Feed not found.");
break;
case RS_FEED_ADD_RESULT_PARENT_NOT_FOUND:
error = tr("Parent not found.");
break;
case RS_FEED_ADD_RESULT_PARENT_IS_NO_FOLDER:
error = tr("Parent is no folder.");
break;
case RS_FEED_ADD_RESULT_FEED_IS_FOLDER:
error = tr("Feed is a folder.");
break;
case RS_FEED_ADD_RESULT_FEED_IS_NO_FOLDER:
error = tr("Feed is no folder.");
break;
default:
error = tr("Unknown error occured.");
}
QMessageBox::critical(parent, title, text + "\n" + error);
return true;
}
void AddFeedDialog::setParent(const std::string &parentId)
{
mParentId = parentId;
@ -264,16 +239,8 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
return true;
}
void AddFeedDialog::createFeed()
void AddFeedDialog::getFeedInfo(FeedInfo &feedInfo)
{
FeedInfo feedInfo;
if (!mFeedId.empty()) {
if (!mFeedReader->getFeedInfo(mFeedId, feedInfo)) {
QMessageBox::critical(this, tr("Edit feed"), tr("Can't edit feed. Feed does not exist."));
return;
}
}
feedInfo.parentId = mParentId;
feedInfo.name = ui->nameLineEdit->text().toUtf8().constData();
@ -307,19 +274,41 @@ void AddFeedDialog::createFeed()
feedInfo.flag.standardStorageTime = ui->useStandardStorageTimeCheckBox->isChecked();
feedInfo.storageTime = ui->storageTimeSpinBox->value() * 60 *60 * 24;
}
void AddFeedDialog::createFeed()
{
FeedInfo feedInfo;
if (!mFeedId.empty()) {
if (!mFeedReader->getFeedInfo(mFeedId, feedInfo)) {
QMessageBox::critical(this, tr("Edit feed"), tr("Can't edit feed. Feed does not exist."));
return;
}
}
getFeedInfo(feedInfo);
if (mFeedId.empty()) {
/* add new feed */
RsFeedAddResult result = mFeedReader->addFeed(feedInfo, mFeedId);
if (showError(this, result, tr("Create feed"), tr("Cannot create feed."))) {
if (FeedReaderStringDefs::showError(this, result, tr("Create feed"), tr("Cannot create feed."))) {
return;
}
} else {
RsFeedAddResult result = mFeedReader->setFeed(mFeedId, feedInfo);
if (showError(this, result, tr("Edit feed"), tr("Cannot change feed."))) {
if (FeedReaderStringDefs::showError(this, result, tr("Edit feed"), tr("Cannot change feed."))) {
return;
}
}
close();
}
void AddFeedDialog::preview()
{
FeedInfo feedInfo;
getFeedInfo(feedInfo);
PreviewFeedDialog dialog(mFeedReader, mNotify, feedInfo, this);
dialog.exec();
}