This commit is contained in:
Martin Rotter 2016-01-16 19:02:27 +01:00
parent 896ba2c59a
commit 99126ad06f
7 changed files with 63 additions and 14 deletions

View File

@ -4,6 +4,7 @@
Added:
▪ Added generic "Add new feed" action, which can be accessed via "Feeds & messages" menu. (issue #146)
▪ User can now specify destination root node when importing feeds. (issue #147)
▪ Added support for import/export to/from plain TXT file (one feed URL per line). (issue #142)
▪ Optimized menu items in "Add new item" submenu. Added two new bindable actions for adding feeds & categories. (issues #146 and #148)

View File

@ -482,8 +482,7 @@ void FormStandardFeedDetails::initialize() {
m_ui->m_txtUrl->lineEdit()->setFocus(Qt::TabFocusReason);
}
void FormStandardFeedDetails::loadCategories(const QList<Category*> categories,
RootItem *root_item) {
void FormStandardFeedDetails::loadCategories(const QList<Category*> categories, RootItem *root_item) {
m_ui->m_cmbParentCategory->addItem(root_item->icon(),
root_item->title(),
QVariant::fromValue((void*) root_item));

View File

@ -17,6 +17,7 @@
#include "services/standard/gui/formstandardimportexport.h"
#include "services/abstract/category.h"
#include "services/standard/standardfeedsimportexportmodel.h"
#include "services/standard/standardserviceroot.h"
#include "core/feedsmodel.h"
@ -65,6 +66,8 @@ void FormStandardImportExport::setMode(const FeedsImportExportModel::Mode &mode)
m_model->checkAllItems();
m_ui->m_treeFeeds->setModel(m_model);
m_ui->m_treeFeeds->expandAll();
m_ui->m_cmbRootNode->setVisible(false);
m_ui->m_lblRootNode->setVisible(false);
m_ui->m_groupFile->setTitle(tr("Destination file"));
m_ui->m_groupFeeds->setTitle(tr("Source feeds && categories"));
setWindowTitle(tr("Export feeds"));
@ -76,6 +79,9 @@ void FormStandardImportExport::setMode(const FeedsImportExportModel::Mode &mode)
m_ui->m_groupFile->setTitle(tr("Source file"));
m_ui->m_groupFeeds->setTitle(tr("Target feeds && categories"));
m_ui->m_groupFeeds->setDisabled(true);
// Load categories.
loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot);
setWindowTitle(tr("Import feeds"));
setWindowIcon(qApp->icons()->fromTheme(QSL("document-import")));
break;
@ -127,6 +133,7 @@ void FormStandardImportExport::onParsingFinished(int count_failed, int count_suc
m_ui->m_treeFeeds->expandAll();
}
else {
m_ui->m_groupFeeds->setEnabled(false);
m_ui->m_lblResult->setStatus(WidgetWithStatus::Error, tr("Error, file is not well-formed. Select another file."),
tr("Error occurred. File is not well-formed. Select another file."));
}
@ -141,7 +148,7 @@ void FormStandardImportExport::onParsingProgress(int completed, int total) {
void FormStandardImportExport::selectExportFile() {
const QString filter_opml20 = tr("OPML 2.0 files (*.opml)");
const QString filter_txt_url_per_line = tr("TXT files (one URL per line) (*.txt)");
const QString filter_txt_url_per_line = tr("TXT files [one URL per line] (*.txt)");
QString filter;
QString selected_filter;
@ -178,7 +185,7 @@ void FormStandardImportExport::selectExportFile() {
void FormStandardImportExport::selectImportFile() {
const QString filter_opml20 = tr("OPML 2.0 files (*.opml)");
const QString filter_txt_url_per_line = tr("TXT files (one URL per line) (*.txt)");
const QString filter_txt_url_per_line = tr("TXT files [one URL per line] (*.txt)");
QString filter;
QString selected_filter;
@ -284,12 +291,21 @@ void FormStandardImportExport::exportFeeds() {
void FormStandardImportExport::importFeeds() {
QString output_message;
RootItem *parent = static_cast<RootItem*>(m_ui->m_cmbRootNode->itemData(m_ui->m_cmbRootNode->currentIndex()).value<void*>());
if (m_serviceRoot->mergeImportExportModel(m_model, output_message)) {
m_serviceRoot->requestItemExpand(m_serviceRoot->getSubTree(), true);
if (m_serviceRoot->mergeImportExportModel(m_model, parent, output_message)) {
m_serviceRoot->requestItemExpand(parent->getSubTree(), true);
m_ui->m_lblResult->setStatus(WidgetWithStatus::Ok, output_message, output_message);
}
else {
m_ui->m_lblResult->setStatus(WidgetWithStatus::Error, output_message, output_message);
}
}
void FormStandardImportExport::loadCategories(const QList<Category *> categories, RootItem *root_item) {
m_ui->m_cmbRootNode->addItem(root_item->icon(), root_item->title(), QVariant::fromValue((void*) root_item));
foreach (Category *category, categories) {
m_ui->m_cmbRootNode->addItem(category->icon(), category->title(), QVariant::fromValue((void*) category));
}
}

View File

@ -27,6 +27,7 @@ namespace Ui {
class FormStandardImportExport;
}
class Category;
class StandardServiceRoot;
class FormStandardImportExport : public QDialog {
@ -60,6 +61,8 @@ class FormStandardImportExport : public QDialog {
void exportFeeds();
void importFeeds();
void loadCategories(const QList<Category*> categories, RootItem *root_item);
QScopedPointer<Ui::FormStandardImportExport> m_ui;
ConversionType m_conversionType;
FeedsImportExportModel *m_model;

View File

@ -37,27 +37,57 @@
</layout>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="m_lblRootNode">
<property name="text">
<string>Root node</string>
</property>
<property name="buddy">
<cstring>m_cmbRootNode</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="m_cmbRootNode">
<property name="toolTip">
<string>Select parent item for your feed.</string>
</property>
<property name="iconSize">
<size>
<width>12</width>
<height>12</height>
</size>
</property>
<property name="frame">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="m_groupFeeds">
<property name="title">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<item row="1" column="1">
<widget class="QPushButton" name="m_btnCheckAllItems">
<property name="text">
<string>&amp;Check all items</string>
</property>
</widget>
</item>
<item row="0" column="2">
<item row="1" column="2">
<widget class="QPushButton" name="m_btnUncheckAllItems">
<property name="text">
<string>&amp;Uncheck all items</string>
</property>
</widget>
</item>
<item row="0" column="3">
<item row="1" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -70,7 +100,7 @@
</property>
</spacer>
</item>
<item row="1" column="1" colspan="3">
<item row="2" column="1" colspan="3">
<widget class="QTreeView" name="m_treeFeeds">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">

View File

@ -87,7 +87,7 @@ void StandardServiceRoot::start(bool freshly_activated) {
model.importAsOPML20(IOFactory::readTextFile(file_to_load));
model.checkAllItems();
if (mergeImportExportModel(&model, output_msg)) {
if (mergeImportExportModel(&model, this, output_msg)) {
requestItemExpand(getSubTree(), true);
}
}
@ -332,8 +332,8 @@ QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed *feed) {
return m_feedContextMenu;
}
bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel *model, QString &output_message) {
QStack<RootItem*> original_parents; original_parents.push(this);
bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel *model, RootItem *target_root_node, QString &output_message) {
QStack<RootItem*> original_parents; original_parents.push(target_root_node);
QStack<RootItem*> new_parents; new_parents.push(model->rootItem());
bool some_feed_category_error = false;

View File

@ -92,7 +92,7 @@ class StandardServiceRoot : public ServiceRoot {
// Takes structure residing under given root item and adds feeds/categories from
// it to active structure.
// NOTE: This is used for import/export of the model.
bool mergeImportExportModel(FeedsImportExportModel *model, QString &output_message);
bool mergeImportExportModel(FeedsImportExportModel *model, RootItem *target_root_node, QString &output_message);
bool markFeedsReadUnread(QList<Feed*> items, ReadStatus read);
bool cleanFeeds(QList<Feed*> items, bool clean_read_only);