FeedReader plugin

- reserved service id
- reworked error codes
- added xpath manipulation and basic gui elements in preview dialog

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5514 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-09-04 23:53:04 +00:00
parent 08904bf82f
commit c7ed9c6df7
23 changed files with 1595 additions and 430 deletions

View file

@ -27,6 +27,7 @@
#include "ui_AddFeedDialog.h"
#include "PreviewFeedDialog.h"
#include "FeedReaderStringDefs.h"
#include "gui/settings/rsharesettings.h"
#include "retroshare/rsforums.h"
@ -36,7 +37,7 @@ bool sortForumInfo(const ForumInfo& info1, const ForumInfo& info2)
}
AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, QWidget *parent)
: QDialog(parent), mFeedReader(feedReader), mNotify(notify), ui(new Ui::AddFeedDialog)
: QDialog(parent, Qt::Window), mFeedReader(feedReader), mNotify(notify), ui(new Ui::AddFeedDialog)
{
ui->setupUi(this);
@ -93,13 +94,37 @@ AddFeedDialog::AddFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify,
validate();
ui->urlLineEdit->setFocus();
/* load settings */
processSettings(true);
}
AddFeedDialog::~AddFeedDialog()
{
/* save settings */
processSettings(false);
delete ui;
}
void AddFeedDialog::processSettings(bool load)
{
Settings->beginGroup(QString("AddFeedDialog"));
if (load) {
// load settings
QByteArray geometry = Settings->value("Geometry").toByteArray();
if (!geometry.isEmpty()) {
restoreGeometry(geometry);
}
} else {
// save settings
Settings->setValue("Geometry", saveGeometry());
}
Settings->endGroup();
}
void AddFeedDialog::authenticationToggled()
{
bool checked = ui->useAuthenticationCheckBox->isChecked();
@ -234,6 +259,9 @@ bool AddFeedDialog::fillFeed(const std::string &feedId)
ui->useStandardStorageTimeCheckBox->setChecked(feedInfo.flag.standardStorageTime);
ui->storageTimeSpinBox->setValue(feedInfo.storageTime / (60 * 60 *24));
mXPathsToUse = feedInfo.xpathsToUse;
mXPathsToRemove = feedInfo.xpathsToRemove;
}
return true;
@ -274,6 +302,9 @@ void AddFeedDialog::getFeedInfo(FeedInfo &feedInfo)
feedInfo.flag.standardStorageTime = ui->useStandardStorageTimeCheckBox->isChecked();
feedInfo.storageTime = ui->storageTimeSpinBox->value() * 60 *60 * 24;
feedInfo.xpathsToUse = mXPathsToUse;
feedInfo.xpathsToRemove = mXPathsToRemove;
}
void AddFeedDialog::createFeed()
@ -310,5 +341,7 @@ void AddFeedDialog::preview()
getFeedInfo(feedInfo);
PreviewFeedDialog dialog(mFeedReader, mNotify, feedInfo, this);
dialog.exec();
if (dialog.exec() == QDialog::Accepted) {
dialog.getXPaths(mXPathsToUse, mXPathsToRemove);
}
}

View file

@ -55,6 +55,7 @@ private slots:
void preview();
private:
void processSettings(bool load);
void getFeedInfo(FeedInfo &feedInfo);
RsFeedReader *mFeedReader;
@ -62,6 +63,9 @@ private:
std::string mFeedId;
std::string mParentId;
std::list<std::string> mXPathsToUse;
std::list<std::string> mXPathsToRemove;
Ui::AddFeedDialog *ui;
};

View file

@ -76,55 +76,73 @@ QString FeedReaderStringDefs::workState(FeedInfo::WorkState state)
QString FeedReaderStringDefs::errorString(const FeedInfo &feedInfo)
{
QString errorState;
switch (feedInfo.errorState) {
return errorString(feedInfo.errorState, feedInfo.errorString);
}
QString FeedReaderStringDefs::errorString(RsFeedReaderErrorState errorState, const std::string &errorString)
{
QString errorText;
switch (errorState) {
case RS_FEED_ERRORSTATE_OK:
break;
/* download */
case RS_FEED_ERRORSTATE_DOWNLOAD_INTERNAL_ERROR:
errorState = QApplication::translate("FeedReaderStringDefs", "Internal download error");
errorText = QApplication::translate("FeedReaderStringDefs", "Internal download error");
break;
case RS_FEED_ERRORSTATE_DOWNLOAD_ERROR:
errorState = QApplication::translate("FeedReaderStringDefs", "Download error");
errorText = QApplication::translate("FeedReaderStringDefs", "Download error");
break;
case RS_FEED_ERRORSTATE_DOWNLOAD_UNKNOWN_CONTENT_TYPE:
errorState = QApplication::translate("FeedReaderStringDefs", "Unknown content type");
errorText = QApplication::translate("FeedReaderStringDefs", "Unknown content type");
break;
case RS_FEED_ERRORSTATE_DOWNLOAD_NOT_FOUND:
errorState = QApplication::translate("FeedReaderStringDefs", "Download not found");
errorText = QApplication::translate("FeedReaderStringDefs", "Download not found");
break;
case RS_FEED_ERRORSTATE_DOWNLOAD_UNKOWN_RESPONSE_CODE:
errorState = QApplication::translate("FeedReaderStringDefs", "Unknown response code");
errorText = QApplication::translate("FeedReaderStringDefs", "Unknown response code");
break;
/* process */
case RS_FEED_ERRORSTATE_PROCESS_INTERNAL_ERROR:
errorState = QApplication::translate("FeedReaderStringDefs", "Internal process error");
errorText = QApplication::translate("FeedReaderStringDefs", "Internal process error");
break;
case RS_FEED_ERRORSTATE_PROCESS_UNKNOWN_FORMAT:
errorState = QApplication::translate("FeedReaderStringDefs", "Unknown XML format");
errorText = QApplication::translate("FeedReaderStringDefs", "Unknown XML format");
break;
case RS_FEED_ERRORSTATE_PROCESS_FORUM_CREATE:
errorState = QApplication::translate("FeedReaderStringDefs", "Can't create forum");
errorText = QApplication::translate("FeedReaderStringDefs", "Can't create forum");
break;
case RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_FOUND:
errorState = QApplication::translate("FeedReaderStringDefs", "Forum not found");
errorText = QApplication::translate("FeedReaderStringDefs", "Forum not found");
break;
case RS_FEED_ERRORSTATE_PROCESS_FORUM_NO_ADMIN:
errorState = QApplication::translate("FeedReaderStringDefs", "You are not admin of the forum");
errorText = QApplication::translate("FeedReaderStringDefs", "You are not admin of the forum");
break;
case RS_FEED_ERRORSTATE_PROCESS_FORUM_NOT_ANONYMOUS:
errorState = QApplication::translate("FeedReaderStringDefs", "The forum is no anonymous forum");
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");
break;
case RS_FEED_ERRORSTATE_PROCESS_XPATH_INTERNAL_ERROR:
errorText = QApplication::translate("FeedReaderStringDefs", "Internal XPath error");
break;
case RS_FEED_ERRORSTATE_PROCESS_XPATH_WRONG_EXPRESSION:
errorText = QApplication::translate("FeedReaderStringDefs", "Wrong XPath expression");
break;
case RS_FEED_ERRORSTATE_PROCESS_XPATH_NO_RESULT:
errorText = QApplication::translate("FeedReaderStringDefs", "Empty XPath result");
break;
default:
errorState = QApplication::translate("FeedReaderStringDefs", "Unknown error");
errorText = QApplication::translate("FeedReaderStringDefs", "Unknown error");
}
if (!feedInfo.errorString.empty()) {
errorState += QString(" (%1)").arg(QString::fromUtf8(feedInfo.errorString.c_str()));
if (!errorString.empty()) {
errorText += QString(" (%1)").arg(QString::fromUtf8(errorString.c_str()));
}
return errorState;
return errorText;
}

View file

@ -34,6 +34,7 @@ public:
static bool showError(QWidget *parent, RsFeedAddResult result, const QString &title, const QString &text);
static QString workState(FeedInfo::WorkState state);
static QString errorString(const FeedInfo &feedInfo);
static QString errorString(RsFeedReaderErrorState errorState, const std::string &errorString);
};
#endif

View file

@ -19,13 +19,16 @@
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QPainter>
//#include <QPainter>
#include <QMenu>
#include <QKeyEvent>
#include "PreviewFeedDialog.h"
#include "ui_PreviewFeedDialog.h"
#include "FeedReaderNotify.h"
#include "FeedReaderStringDefs.h"
#include "util/HandleRichText.h"
#include "gui/settings/rsharesettings.h"
#include "interface/rsFeedReader.h"
#include "retroshare/rsiface.h"
@ -138,33 +141,67 @@
//}
PreviewFeedDialog::PreviewFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, const FeedInfo &feedInfo, QWidget *parent) :
QDialog(parent), mFeedReader(feedReader), mNotify(notify), ui(new Ui::PreviewFeedDialog)
QDialog(parent, Qt::Window), mFeedReader(feedReader), mNotify(notify), ui(new Ui::PreviewFeedDialog)
{
ui->setupUi(this);
ui->feedNameLabel->clear();
ui->feedInfoLabel->clear();
ui->useXPathCheckBox->setChecked(true);
/* connect signals */
connect(ui->previousPushButton, SIGNAL(clicked()), this, SLOT(previousMsg()));
connect(ui->nextPushButton, SIGNAL(clicked()), this, SLOT(nextMsg()));
connect(ui->documentButton, SIGNAL(toggled(bool)), this, SLOT(showDocumentFrame(bool)));
connect(ui->closeStructureButton, SIGNAL(clicked()), this, SLOT(showStructureFrame()));
connect(ui->structureButton, SIGNAL(toggled(bool)), this, SLOT(showStructureFrame(bool)));
connect(ui->xpathPushButton, SIGNAL(toggled(bool)), this, SLOT(showXPathFrame(bool)));
connect(ui->useXPathCheckBox, SIGNAL(toggled(bool)), this, SLOT(fillStructureTree()));
connect(ui->xpathUseListWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(xpathListCustomPopupMenu(QPoint)));
connect(ui->xpathRemoveListWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(xpathListCustomPopupMenu(QPoint)));
connect(ui->xpathUseListWidget->itemDelegate(), SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), this, SLOT(xpathCloseEditor(QWidget*,QAbstractItemDelegate::EndEditHint)));
connect(ui->xpathRemoveListWidget->itemDelegate(), SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), this, SLOT(xpathCloseEditor(QWidget*,QAbstractItemDelegate::EndEditHint)));
connect(mNotify, SIGNAL(notifyFeedChanged(QString,int)), this, SLOT(feedChanged(QString,int)));
connect(mNotify, SIGNAL(notifyMsgChanged(QString,QString,int)), this, SLOT(msgChanged(QString,QString,int)));
// ui->documentTreeWidget->setItemDelegate(new PreviewItemDelegate(ui->documentTreeWidget));
showDocumentFrame(false);
ui->structureFrame->hide();
if (!mFeedReader->addPreviewFeed(feedInfo, mFeedId)) {
setInfo(tr("Cannot create preview"));
if (mFeedReader->addPreviewFeed(feedInfo, mFeedId)) {
setFeedInfo("");
} else {
setFeedInfo(tr("Cannot create preview"));
}
setXPathInfo("");
showXPathFrame(true);
/* fill xpath expressions */
QListWidgetItem *item;
std::string xpath;
foreach(xpath, feedInfo.xpathsToUse){
item = new QListWidgetItem(QString::fromUtf8(xpath.c_str()));
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->xpathUseListWidget->addItem(item);
}
foreach(xpath, feedInfo.xpathsToRemove){
item = new QListWidgetItem(QString::fromUtf8(xpath.c_str()));
item->setFlags(item->flags() | Qt::ItemIsEditable);
ui->xpathRemoveListWidget->addItem(item);
}
updateMsgCount();
ui->xpathUseListWidget->installEventFilter(this);
ui->xpathRemoveListWidget->installEventFilter(this);
/* load settings */
processSettings(true);
}
PreviewFeedDialog::~PreviewFeedDialog()
{
/* save settings */
processSettings(false);
disconnect(mNotify);
disconnect(mNotify);
@ -175,6 +212,51 @@ PreviewFeedDialog::~PreviewFeedDialog()
delete ui;
}
void PreviewFeedDialog::processSettings(bool load)
{
Settings->beginGroup(QString("PreviewFeedDialog"));
if (load) {
// load settings
QByteArray geometry = Settings->value("Geometry").toByteArray();
if (!geometry.isEmpty()) {
restoreGeometry(geometry);
}
} else {
// save settings
Settings->setValue("Geometry", saveGeometry());
}
Settings->endGroup();
}
bool PreviewFeedDialog::eventFilter(QObject *obj, QEvent *event)
{
long todo_here;
if (event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent) {
if (keyEvent->key() == Qt::Key_Delete) {
/* Delete pressed */
if (obj == ui->xpathUseListWidget || obj == ui->xpathRemoveListWidget) {
QListWidget *listWidget = dynamic_cast<QListWidget*>(obj);
if (listWidget) {
QListWidgetItem *item = listWidget->currentItem();
if (item) {
delete(item);
processXPath();
}
return true; // eat event
}
}
}
}
}
/* pass the event on to the parent class */
return QDialog::eventFilter(obj, event);
}
void PreviewFeedDialog::feedChanged(const QString &feedId, int type)
{
if (feedId.isEmpty()) {
@ -251,22 +333,139 @@ void PreviewFeedDialog::msgChanged(const QString &feedId, const QString &msgId,
updateMsgCount();
}
void PreviewFeedDialog::showDocumentFrame(bool show)
void PreviewFeedDialog::showStructureFrame(bool show)
{
ui->documentFrame->setVisible(show);
ui->documentButton->setChecked(show);
ui->structureButton->setChecked(show);
ui->structureFrame->setVisible(show);
if (show) {
ui->documentButton->setToolTip(tr("Hide tree"));
ui->documentButton->setIcon(QIcon(":images/hide_toolbox_frame.png"));
fillDocumentTree();
} else {
ui->documentButton->setToolTip(tr("Show tree"));
ui->documentButton->setIcon(QIcon(":images/show_toolbox_frame.png"));
fillStructureTree();
}
}
void PreviewFeedDialog::showXPathFrame(bool show)
{
ui->xpathFrame->setVisible(show);
if (show) {
ui->xpathPushButton->setToolTip(tr("Hide XPath expressions"));
ui->xpathPushButton->setIcon(QIcon(":images/show_toolbox_frame.png"));
} else {
ui->xpathPushButton->setToolTip(tr("Show XPath expressions"));
ui->xpathPushButton->setIcon(QIcon(":images/hide_toolbox_frame.png"));
}
}
void PreviewFeedDialog::xpathListCustomPopupMenu(QPoint /*point*/)
{
QListWidgetItem *item = NULL;
if (sender() == ui->xpathUseListWidget) {
item = ui->xpathUseListWidget->currentItem();
} else if (sender() == ui->xpathRemoveListWidget) {
item = ui->xpathRemoveListWidget->currentItem();
} else {
return;
}
QMenu contextMnu(this);
QAction *action = contextMnu.addAction(QIcon(), tr("Add"), this, SLOT(addXPath()));
action->setData(QVariant::fromValue(sender()));
action = contextMnu.addAction(QIcon(), tr("Edit"), this, SLOT(editXPath()));
action->setData(QVariant::fromValue(sender()));
if (!item) {
action->setEnabled(false);
}
action = contextMnu.addAction(QIcon(), tr("Delete"), this, SLOT(removeXPath()));
action->setData(QVariant::fromValue(sender()));
if (!item) {
action->setEnabled(false);
}
contextMnu.exec(QCursor::pos());
}
void PreviewFeedDialog::xpathCloseEditor(QWidget */*editor*/, QAbstractItemDelegate::EndEditHint /*hint*/)
{
processXPath();
}
void PreviewFeedDialog::addXPath()
{
QAction *action = dynamic_cast<QAction*>(sender());
if (!action) {
return;
}
QObject *source = action->data().value<QObject*>();
QListWidget *listWidget;
if (source == ui->xpathUseListWidget) {
listWidget = ui->xpathUseListWidget;
} else if (source == ui->xpathRemoveListWidget) {
listWidget = ui->xpathRemoveListWidget;
} else {
return;
}
QListWidgetItem *item = new QListWidgetItem();
item->setFlags(item->flags() | Qt::ItemIsEditable);
listWidget->addItem(item);
listWidget->editItem(item);
}
void PreviewFeedDialog::editXPath()
{
QAction *action = dynamic_cast<QAction*>(sender());
if (!action) {
return;
}
QObject *source = action->data().value<QObject*>();
QListWidget *listWidget;
if (source == ui->xpathUseListWidget) {
listWidget = ui->xpathUseListWidget;
} else if (source == ui->xpathRemoveListWidget) {
listWidget = ui->xpathRemoveListWidget;
} else {
return;
}
listWidget->editItem(listWidget->currentItem());
}
void PreviewFeedDialog::removeXPath()
{
QAction *action = dynamic_cast<QAction*>(sender());
if (!action) {
return;
}
QObject *source = action->data().value<QObject*>();
QListWidget *listWidget;
if (source == ui->xpathUseListWidget) {
listWidget = ui->xpathUseListWidget;
} else if (source == ui->xpathRemoveListWidget) {
listWidget = ui->xpathRemoveListWidget;
} else {
return;
}
QListWidgetItem *item = listWidget->currentItem();
if (item) {
delete(item);
}
processXPath();
}
int PreviewFeedDialog::getMsgPos()
{
int pos = -1;
@ -281,14 +480,18 @@ int PreviewFeedDialog::getMsgPos()
return pos;
}
void PreviewFeedDialog::setInfo(const QString &info)
void PreviewFeedDialog::setFeedInfo(const QString &info)
{
ui->feedInfoLabel->setText(info);
ui->infoLabel->setVisible(!info.isEmpty());
ui->feedInfoLabel->setVisible(!info.isEmpty());
}
void PreviewFeedDialog::setXPathInfo(const QString &info)
{
ui->xpathInfoLabel->setText(info);
ui->xpathInfoLabel->setVisible(!info.isEmpty());
}
void PreviewFeedDialog::fillFeedInfo(const FeedInfo &feedInfo)
{
QString name = feedInfo.name.empty() ? tr("No name") : QString::fromUtf8(feedInfo.name.c_str());
@ -299,7 +502,7 @@ void PreviewFeedDialog::fillFeedInfo(const FeedInfo &feedInfo)
}
ui->feedNameLabel->setText(name);
setInfo(FeedReaderStringDefs::errorString(feedInfo));
setFeedInfo(FeedReaderStringDefs::errorString(feedInfo));
}
void PreviewFeedDialog::previousMsg()
@ -344,24 +547,23 @@ void PreviewFeedDialog::updateMsg()
ui->msgTitle->clear();
ui->msgText->clear();
mDescription.clear();
mDescriptionXPath.clear();
return;
}
mDescription = msgInfo.description;
QString msgTxt = RsHtml().formatText(ui->msgText->document(), QString::fromUtf8(mDescription.c_str()), RSHTML_FORMATTEXT_EMBED_LINKS);
ui->msgText->setHtml(msgTxt);
ui->msgTitle->setText(QString::fromUtf8(msgInfo.title.c_str()));
ui->documentTreeWidget->clear();
fillDocumentTree();
/* store description */
mDescription = msgInfo.description;
/* process xpath */
processXPath();
}
static void examineChildElements(QTreeWidget *treeWidget, HTMLWrapper &html, xmlNodePtr node, QTreeWidgetItem *parentItem)
static void buildNodeText(HTMLWrapper &html, xmlNodePtr node, QString &text)
{
QTreeWidgetItem *item = new QTreeWidgetItem;
QString text;
if (node->type == XML_ELEMENT_NODE) {
switch (node->type) {
case XML_ELEMENT_NODE:
text = QString("<%1 ").arg(QString::fromUtf8(html.nodeName(node).c_str()));
for (xmlAttrPtr attr = node->properties; attr; attr = attr->next) {
@ -372,48 +574,148 @@ static void examineChildElements(QTreeWidget *treeWidget, HTMLWrapper &html, xml
text += QString("%1=\"%2\" ").arg(QString::fromUtf8(html.attrName(attr).c_str()), value);
}
text = text.trimmed() + ">";
} else {
std::string content;
if (html.getContent(node, content)) {
text = QString::fromUtf8(content.c_str());
} else {
text = QApplication::translate("PreviewFeedDialog", "Error getting content");
if (node->children && !node->children->next && node->children->type == XML_TEXT_NODE) {
/* only one text node as child */
std::string content;
if (html.getContent(node->children, content)) {
text += QString::fromUtf8(content.c_str());
} else {
text += QApplication::translate("PreviewFeedDialog", "Error getting content");
}
text += QString("<%1>").arg(QString::fromUtf8(html.nodeName(node).c_str()));
xmlUnlinkNode(node->children);
xmlFreeNode(node->children);
}
break;
case XML_TEXT_NODE:
case XML_COMMENT_NODE:
{
if (node->type == XML_COMMENT_NODE) {
text = "<!-- ";
}
std::string content;
if (html.getContent(node, content)) {
text += QString::fromUtf8(content.c_str());
} else {
text += QApplication::translate("PreviewFeedDialog", "Error getting content");
}
if (node->type == XML_COMMENT_NODE) {
text += " -->";
}
}
break;
case XML_ATTRIBUTE_NODE:
case XML_CDATA_SECTION_NODE:
case XML_ENTITY_REF_NODE:
case XML_ENTITY_NODE:
case XML_PI_NODE:
case XML_DOCUMENT_NODE:
case XML_DOCUMENT_TYPE_NODE:
case XML_DOCUMENT_FRAG_NODE:
case XML_NOTATION_NODE:
case XML_HTML_DOCUMENT_NODE:
case XML_DTD_NODE:
case XML_ELEMENT_DECL:
case XML_ATTRIBUTE_DECL:
case XML_ENTITY_DECL:
case XML_NAMESPACE_DECL:
case XML_XINCLUDE_START:
case XML_XINCLUDE_END:
#ifdef LIBXML_DOCB_ENABLED
case XML_DOCB_DOCUMENT_NODE:
#endif
break;
}
}
static void examineChildElements(QTreeWidget *treeWidget, HTMLWrapper &html, QList<xmlNodePtr> &nodes, QTreeWidgetItem *parentItem)
{
int childIndex = 0;
int childCount;
QList<QPair<xmlNodePtr, QTreeWidgetItem*> > nodeItems;
foreach (xmlNodePtr node, nodes) {
QString text;
buildNodeText(html, node, text);
QList<QTreeWidgetItem*> itemsToDelete;
QTreeWidgetItem *item = NULL;
childCount = parentItem->childCount();
for (int index = childIndex; index < childCount; ++index) {
QTreeWidgetItem *childItem = parentItem->child(index);
if (childItem->text(0) == text) {
/* reuse item */
item = childItem;
break;
}
itemsToDelete.push_back(childItem);
}
if (item) {
/* delete old items */
foreach (QTreeWidgetItem *item, itemsToDelete) {
delete(item);
}
++childIndex;
} else {
item = new QTreeWidgetItem;
item->setText(0, text);
parentItem->insertChild(childIndex, item);
item->setExpanded(true);
++childIndex;
}
nodeItems.push_back(QPair<xmlNodePtr, QTreeWidgetItem*>(node, item));
}
/* delete not used items */
while (childIndex < parentItem->childCount()) {
delete(parentItem->child(childIndex));
}
QList<QPair<xmlNodePtr, QTreeWidgetItem*> >::iterator nodeItem;
for (nodeItem = nodeItems.begin(); nodeItem != nodeItems.end(); ++nodeItem) {
QList<xmlNodePtr> childNodes;
for (xmlNodePtr childNode = nodeItem->first->children; childNode; childNode = childNode->next) {
childNodes.push_back(childNode);
}
examineChildElements(treeWidget, html, childNodes, nodeItem->second);
}
item->setText(0, text);
parentItem->addChild(item);
// QLabel *label = new QLabel(text);
// label->setTextFormat(Qt::PlainText);
// label->setWordWrap(true);
// treeWidget->setItemWidget(item, 0, label);
item->setExpanded(true);
for (xmlNodePtr child = node->children; child; child = child->next) {
examineChildElements(treeWidget, html, child, item);
}
}
void PreviewFeedDialog::fillDocumentTree()
void PreviewFeedDialog::fillStructureTree()
{
if (!ui->documentTreeWidget->isVisible()) {
if (!ui->structureTreeWidget->isVisible()) {
return;
}
if (ui->documentTreeWidget->topLevelItemCount() > 0) {
// if (ui->structureTreeWidget->topLevelItemCount() > 0) {
// return;
// }
if (mDescriptionXPath.empty()) {
ui->structureTreeWidget->clear();
return;
}
if (mDescription.empty()) {
return;
}
bool useXPath = ui->useXPathCheckBox->isChecked();
HTMLWrapper html;
if (!html.readHTML(mDescription.c_str(), "")) {
if (!html.readHTML(useXPath ? mDescriptionXPath.c_str() : mDescription.c_str(), "")) {
QTreeWidgetItem *item = new QTreeWidgetItem;
item->setText(0, tr("Error parsing document"));
ui->documentTreeWidget->addTopLevelItem(item);
ui->structureTreeWidget->addTopLevelItem(item);
return;
}
@ -423,5 +725,42 @@ void PreviewFeedDialog::fillDocumentTree()
return;
}
examineChildElements(ui->documentTreeWidget, html, root, ui->documentTreeWidget->invisibleRootItem());
QList<xmlNodePtr> nodes;
nodes.push_back(root);
examineChildElements(ui->structureTreeWidget, html, nodes, ui->structureTreeWidget->invisibleRootItem());
ui->structureTreeWidget->resizeColumnToContents(0);
}
void PreviewFeedDialog::getXPaths(std::list<std::string> &xpathsToUse, std::list<std::string> &xpathsToRemove)
{
int row;
int rowCount = ui->xpathUseListWidget->count();
for (row = 0; row < rowCount; ++row) {
xpathsToUse.push_back(ui->xpathUseListWidget->item(row)->text().toUtf8().constData());
}
rowCount = ui->xpathRemoveListWidget->count();
for (row = 0; row < rowCount; ++row) {
xpathsToRemove.push_back(ui->xpathRemoveListWidget->item(row)->text().toUtf8().constData());
}
}
void PreviewFeedDialog::processXPath()
{
std::list<std::string> xpathsToUse;
std::list<std::string> xpathsToRemove;
getXPaths(xpathsToUse, xpathsToRemove);
mDescriptionXPath = mDescription;
std::string errorString;
RsFeedReaderErrorState result = mFeedReader->processXPath(xpathsToUse, xpathsToRemove, mDescriptionXPath, errorString);
setXPathInfo(FeedReaderStringDefs::errorString(result, errorString));
/* fill message */
QString msgTxt = RsHtml().formatText(ui->msgText->document(), QString::fromUtf8(mDescriptionXPath.c_str()), RSHTML_FORMATTEXT_EMBED_LINKS);
ui->msgText->setHtml(msgTxt);
/* fill structure */
fillStructureTree();
}

View file

@ -59,22 +59,36 @@ public:
PreviewFeedDialog(RsFeedReader *feedReader, FeedReaderNotify *notify, const FeedInfo &feedInfo, QWidget *parent = 0);
~PreviewFeedDialog();
void getXPaths(std::list<std::string> &xpathsToUse, std::list<std::string> &xpathsToRemove);
protected:
bool eventFilter(QObject *obj, QEvent *ev);
private slots:
void previousMsg();
void nextMsg();
void showDocumentFrame(bool show);
void showStructureFrame(bool show = false);
void showXPathFrame(bool show);
void xpathListCustomPopupMenu(QPoint point);
void xpathCloseEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
void addXPath();
void editXPath();
void removeXPath();
void fillStructureTree();
/* FeedReaderNotify */
void feedChanged(const QString &feedId, int type);
void msgChanged(const QString &feedId, const QString &msgId, int type);
private:
void processSettings(bool load);
int getMsgPos();
void setInfo(const QString &info);
void setFeedInfo(const QString &info);
void setXPathInfo(const QString &info);
void fillFeedInfo(const FeedInfo &feedInfo);
void updateMsgCount();
void updateMsg();
void fillDocumentTree();
void processXPath();
RsFeedReader *mFeedReader;
FeedReaderNotify *mNotify;
@ -82,6 +96,7 @@ private:
std::string mMsgId;
std::list<std::string> mMsgIds;
std::string mDescription;
std::string mDescriptionXPath;
Ui::PreviewFeedDialog *ui;
};

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>350</height>
<width>800</width>
<height>783</height>
</rect>
</property>
<property name="windowTitle">
@ -45,29 +45,103 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="infoLabel">
<property name="text">
<string>Information:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="feedInfoLabel">
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>118</red>
<green>116</green>
<blue>108</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text">
<string>Information</string>
<string notr="true">Feed information</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="xpathInfoLabel">
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>118</red>
<green>116</green>
<blue>108</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text">
<string notr="true">XPath information</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="navigateLayout">
<layout class="QHBoxLayout" name="buttonLayout">
<item>
<spacer name="horizontalSpacer_1">
<spacer name="buttonSpacerLeft">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -119,7 +193,7 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<spacer name="buttonSpacerRight">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -131,6 +205,16 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="structureButton">
<property name="text">
<string>Structure</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -173,92 +257,241 @@ background: white;}</string>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="msgLayout">
<property name="spacing">
<number>0</number>
<widget class="QSplitter" name="messageSplitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<layout class="QVBoxLayout" name="leftSidelLayout">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QTextBrowser" name="msgText"/>
<widget class="QFrame" name="structureFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="documentButton">
<property name="minimumSize">
<size>
<width>14</width>
<height>31</height>
</size>
<layout class="QHBoxLayout" name="structureLayout2">
<property name="spacing">
<number>0</number>
</property>
<property name="maximumSize">
<size>
<width>14</width>
<height>31</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>31</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
<item>
<spacer name="structureSpacer">
<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="QToolButton" name="closeStructureButton">
<property name="maximumSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QToolButton
{
border-image: url(:/images/closenormal.png)
}
QToolButton:hover
{
border-image: url(:/images/closehover.png)
}
QToolButton:pressed {
border-image: url(:/images/closepressed.png)
}</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="spacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>12</width>
<height>329</height>
</size>
</property>
</spacer>
<layout class="QHBoxLayout" name="structureLayout1">
<item>
<widget class="QSplitter" name="structureSplitter">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QFrame" name="structureTreeFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="useXPathCheckBox">
<property name="text">
<string>Use XPath</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="structureTreeWidget">
<property name="wordWrap">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QFrame" name="xpathFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="xpathUseLabel">
<property name="text">
<string>XPath use</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="xpathUseListWidget">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="xpathRemoveLabel">
<property name="text">
<string>XPath remove</string>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="xpathRemoveListWidget">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="xpathLayout">
<item>
<widget class="QPushButton" name="xpathPushButton">
<property name="minimumSize">
<size>
<width>14</width>
<height>31</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>14</width>
<height>31</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QFrame" name="documentFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QTreeWidget" name="documentTreeWidget">
<property name="wordWrap">
<bool>true</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="msgText"/>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="previewLayout">