qol work on discovery dialog!
This commit is contained in:
parent
5238c7e417
commit
26c9d619d7
4 changed files with 97 additions and 131 deletions
|
@ -26,6 +26,8 @@ void AccountCheckModel::setRootItem(RootItem* root_item, bool delete_previous_ro
|
||||||
emit layoutAboutToBeChanged();
|
emit layoutAboutToBeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
beginResetModel();
|
||||||
|
|
||||||
if (delete_previous_root && m_rootItem != nullptr) {
|
if (delete_previous_root && m_rootItem != nullptr) {
|
||||||
m_rootItem->deleteLater();
|
m_rootItem->deleteLater();
|
||||||
}
|
}
|
||||||
|
@ -33,6 +35,8 @@ void AccountCheckModel::setRootItem(RootItem* root_item, bool delete_previous_ro
|
||||||
m_checkStates.clear();
|
m_checkStates.clear();
|
||||||
m_rootItem = root_item;
|
m_rootItem = root_item;
|
||||||
|
|
||||||
|
endResetModel();
|
||||||
|
|
||||||
if (with_layout_change) {
|
if (with_layout_change) {
|
||||||
emit layoutChanged();
|
emit layoutChanged();
|
||||||
}
|
}
|
||||||
|
@ -64,7 +68,7 @@ void AccountCheckModel::uncheckAllItems() {
|
||||||
|
|
||||||
QModelIndex AccountCheckModel::index(int row, int column, const QModelIndex& parent) const {
|
QModelIndex AccountCheckModel::index(int row, int column, const QModelIndex& parent) const {
|
||||||
if (!hasIndex(row, column, parent)) {
|
if (!hasIndex(row, column, parent)) {
|
||||||
return QModelIndex();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
RootItem* parent_item = itemForIndex(parent);
|
RootItem* parent_item = itemForIndex(parent);
|
||||||
|
@ -74,7 +78,7 @@ QModelIndex AccountCheckModel::index(int row, int column, const QModelIndex& par
|
||||||
return createIndex(row, column, child_item);
|
return createIndex(row, column, child_item);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return QModelIndex();
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,14 +125,14 @@ QModelIndex AccountCheckModel::indexForItem(RootItem* item) const {
|
||||||
|
|
||||||
QModelIndex AccountCheckModel::parent(const QModelIndex& child) const {
|
QModelIndex AccountCheckModel::parent(const QModelIndex& child) const {
|
||||||
if (!child.isValid()) {
|
if (!child.isValid()) {
|
||||||
return QModelIndex();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
RootItem* child_item = itemForIndex(child);
|
RootItem* child_item = itemForIndex(child);
|
||||||
RootItem* parent_item = child_item->parent();
|
RootItem* parent_item = child_item->parent();
|
||||||
|
|
||||||
if (parent_item == m_rootItem) {
|
if (parent_item == m_rootItem || parent_item == nullptr) {
|
||||||
return QModelIndex();
|
return {};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return createIndex(parent_item->row(), 0, parent_item);
|
return createIndex(parent_item->row(), 0, parent_item);
|
||||||
|
|
|
@ -47,23 +47,22 @@ FormDiscoverFeeds::FormDiscoverFeeds(ServiceRoot* service_root,
|
||||||
connect(m_btnGoAdvanced, &QPushButton::clicked, this, &FormDiscoverFeeds::userWantsAdvanced);
|
connect(m_btnGoAdvanced, &QPushButton::clicked, this, &FormDiscoverFeeds::userWantsAdvanced);
|
||||||
connect(m_ui.m_btnDiscover, &QPushButton::clicked, this, &FormDiscoverFeeds::discoverFeeds);
|
connect(m_ui.m_btnDiscover, &QPushButton::clicked, this, &FormDiscoverFeeds::discoverFeeds);
|
||||||
|
|
||||||
connect(&m_watcherLookup, &QFutureWatcher<QList<StandardFeed*>>::progressValueChanged, this, [=](int prog) {
|
connect(&m_watcherLookup,
|
||||||
m_ui.m_pbDiscovery->setValue(prog);
|
&QFutureWatcher<QList<StandardFeed*>>::progressValueChanged,
|
||||||
qDebugNN << "progress";
|
this,
|
||||||
});
|
&FormDiscoverFeeds::onDiscoveryProgress);
|
||||||
|
|
||||||
connect(&m_watcherLookup, &QFutureWatcher<QList<StandardFeed*>>::finished, this, [=]() {
|
connect(&m_watcherLookup,
|
||||||
auto res = m_watcherLookup.future().result();
|
&QFutureWatcher<QList<StandardFeed*>>::finished,
|
||||||
|
this,
|
||||||
loadDiscoveredFeeds(res);
|
&FormDiscoverFeeds::onDiscoveryFinished);
|
||||||
});
|
|
||||||
|
|
||||||
loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot);
|
loadCategories(m_serviceRoot->getSubTreeCategories(), m_serviceRoot);
|
||||||
|
|
||||||
m_ui.m_tvFeeds->setModel(m_discoveredModel);
|
m_ui.m_tvFeeds->setModel(m_discoveredModel);
|
||||||
|
|
||||||
m_ui.m_tvFeeds->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeMode::Stretch);
|
m_ui.m_tvFeeds->header()->setSectionResizeMode(0, QHeaderView::ResizeMode::Stretch);
|
||||||
m_ui.m_tvFeeds->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeMode::ResizeToContents);
|
m_ui.m_tvFeeds->header()->setSectionResizeMode(1, QHeaderView::ResizeMode::ResizeToContents);
|
||||||
|
|
||||||
m_ui.m_pbDiscovery->setVisible(false);
|
m_ui.m_pbDiscovery->setVisible(false);
|
||||||
m_ui.m_txtUrl->lineEdit()->setText(url);
|
m_ui.m_txtUrl->lineEdit()->setText(url);
|
||||||
|
@ -93,8 +92,27 @@ FormDiscoverFeeds::FormDiscoverFeeds(ServiceRoot* service_root,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FormDiscoverFeeds::onDiscoveryProgress(int progress) {
|
||||||
|
m_ui.m_pbDiscovery->setValue(progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormDiscoverFeeds::onDiscoveryFinished() {
|
||||||
|
try {
|
||||||
|
auto res = m_watcherLookup.future().result();
|
||||||
|
|
||||||
|
loadDiscoveredFeeds(res);
|
||||||
|
}
|
||||||
|
catch (const ApplicationException& ex) {
|
||||||
|
// TODO: display error
|
||||||
|
}
|
||||||
|
|
||||||
|
setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
FormDiscoverFeeds::~FormDiscoverFeeds() {
|
FormDiscoverFeeds::~FormDiscoverFeeds() {
|
||||||
qDeleteAll(m_parsers);
|
qDeleteAll(m_parsers);
|
||||||
|
|
||||||
|
m_discoveredModel->setRootItem(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<StandardFeed*> FormDiscoverFeeds::discoverFeedsWithParser(const FeedParser* parser, const QString& url) {
|
QList<StandardFeed*> FormDiscoverFeeds::discoverFeedsWithParser(const FeedParser* parser, const QString& url) {
|
||||||
|
@ -137,6 +155,7 @@ void FormDiscoverFeeds::discoverFeeds() {
|
||||||
m_ui.m_pbDiscovery->setMaximum(m_parsers.size());
|
m_ui.m_pbDiscovery->setMaximum(m_parsers.size());
|
||||||
m_ui.m_pbDiscovery->setValue(0);
|
m_ui.m_pbDiscovery->setValue(0);
|
||||||
m_ui.m_pbDiscovery->setVisible(true);
|
m_ui.m_pbDiscovery->setVisible(true);
|
||||||
|
setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormDiscoverFeeds::onUrlChanged(const QString& new_url) {
|
void FormDiscoverFeeds::onUrlChanged(const QString& new_url) {
|
||||||
|
@ -175,70 +194,34 @@ void FormDiscoverFeeds::userWantsAdvanced() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormDiscoverFeeds::loadDiscoveredFeeds(const QList<StandardFeed*>& feeds) {
|
void FormDiscoverFeeds::loadDiscoveredFeeds(const QList<StandardFeed*>& feeds) {
|
||||||
|
RootItem* root = new RootItem();
|
||||||
|
|
||||||
|
for (Feed* feed : feeds) {
|
||||||
|
root->appendChild(feed);
|
||||||
|
}
|
||||||
|
|
||||||
m_ui.m_pbDiscovery->setVisible(false);
|
m_ui.m_pbDiscovery->setVisible(false);
|
||||||
m_discoveredModel->setDiscoveredFeeds(feeds);
|
m_discoveredModel->setRootItem(root);
|
||||||
|
|
||||||
qDebugNN << "finish";
|
qDebugNN << "finish";
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscoveredFeedsModel::DiscoveredFeedsModel(QObject* parent) : QAbstractListModel(parent) {}
|
DiscoveredFeedsModel::DiscoveredFeedsModel(QObject* parent) : AccountCheckModel(parent) {}
|
||||||
|
|
||||||
int DiscoveredFeedsModel::rowCount(const QModelIndex& parent) const {
|
|
||||||
return m_discoveredFeeds.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
int DiscoveredFeedsModel::columnCount(const QModelIndex& parent) const {
|
int DiscoveredFeedsModel::columnCount(const QModelIndex& parent) const {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DiscoveredFeedsModel::data(const QModelIndex& index, int role) const {
|
QVariant DiscoveredFeedsModel::data(const QModelIndex& index, int role) const {
|
||||||
switch (role) {
|
if (role == Qt::ItemDataRole::DisplayRole && index.column() == 1) {
|
||||||
case Qt::ItemDataRole::DisplayRole: {
|
StandardFeed* fd = qobject_cast<StandardFeed*>(itemForIndex(index));
|
||||||
if (index.column() == 0) {
|
|
||||||
return m_discoveredFeeds.at(index.row()).m_feed->title();
|
if (fd != nullptr) {
|
||||||
}
|
return StandardFeed::typeToString(fd->type());
|
||||||
else {
|
|
||||||
return StandardFeed::typeToString(m_discoveredFeeds.at(index.row()).m_feed->type());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case Qt::ItemDataRole::CheckStateRole: {
|
|
||||||
if (index.column() == 0) {
|
|
||||||
return m_discoveredFeeds.at(index.row()).m_isChecked ? Qt::CheckState::Checked : Qt::CheckState::Unchecked;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Qt::ItemDataRole::DecorationRole: {
|
|
||||||
if (index.column() == 0) {
|
|
||||||
return m_discoveredFeeds.at(index.row()).m_feed->fullIcon();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
QList<DiscoveredFeedsModel::FeedItem> DiscoveredFeedsModel::discoveredFeeds() const {
|
return AccountCheckModel::data(index, role);
|
||||||
return m_discoveredFeeds;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DiscoveredFeedsModel::setDiscoveredFeeds(const QList<StandardFeed*>& feeds) {
|
|
||||||
auto std_feeds = boolinq::from(feeds)
|
|
||||||
.select([](StandardFeed* fd) {
|
|
||||||
return FeedItem{false, fd};
|
|
||||||
})
|
|
||||||
.toStdList();
|
|
||||||
|
|
||||||
m_discoveredFeeds = FROM_STD_LIST(QList<FeedItem>, std_feeds);
|
|
||||||
|
|
||||||
emit layoutAboutToBeChanged();
|
|
||||||
emit layoutChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant DiscoveredFeedsModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
QVariant DiscoveredFeedsModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||||
|
@ -254,17 +237,3 @@ QVariant DiscoveredFeedsModel::headerData(int section, Qt::Orientation orientati
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags DiscoveredFeedsModel::flags(const QModelIndex& index) const {
|
|
||||||
return index.column() == 0 ? Qt::ItemFlag::ItemIsUserCheckable | QAbstractListModel::flags(index)
|
|
||||||
: QAbstractListModel::flags(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DiscoveredFeedsModel::setData(const QModelIndex& index, const QVariant& value, int role) {
|
|
||||||
if (role == Qt::ItemDataRole::CheckStateRole && index.column() == 0) {
|
|
||||||
m_discoveredFeeds[index.row()].m_isChecked = value.value<Qt::CheckState>() == Qt::CheckState::Checked;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QAbstractListModel::setData(index, value, role);
|
|
||||||
}
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "ui_formdiscoverfeeds.h"
|
#include "ui_formdiscoverfeeds.h"
|
||||||
|
|
||||||
|
#include "services/abstract/accountcheckmodel.h"
|
||||||
#include "services/standard/parsers/feedparser.h"
|
#include "services/standard/parsers/feedparser.h"
|
||||||
|
|
||||||
#include <QFutureWatcher>
|
#include <QFutureWatcher>
|
||||||
|
@ -15,29 +16,15 @@ class ServiceRoot;
|
||||||
class RootItem;
|
class RootItem;
|
||||||
class Category;
|
class Category;
|
||||||
|
|
||||||
class DiscoveredFeedsModel : public QAbstractListModel {
|
class DiscoveredFeedsModel : public AccountCheckModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct FeedItem {
|
|
||||||
bool m_isChecked;
|
|
||||||
StandardFeed* m_feed;
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit DiscoveredFeedsModel(QObject* parent = {});
|
explicit DiscoveredFeedsModel(QObject* parent = {});
|
||||||
|
|
||||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
virtual int rowCount(const QModelIndex& parent) const;
|
|
||||||
virtual int columnCount(const QModelIndex& parent) const;
|
virtual int columnCount(const QModelIndex& parent) const;
|
||||||
virtual QVariant data(const QModelIndex& index, int role) const;
|
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||||
virtual bool setData(const QModelIndex& index, const QVariant& value, int role);
|
|
||||||
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
|
|
||||||
|
|
||||||
QList<FeedItem> discoveredFeeds() const;
|
|
||||||
void setDiscoveredFeeds(const QList<StandardFeed*>& feeds);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QList<FeedItem> m_discoveredFeeds;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class FormDiscoverFeeds : public QDialog {
|
class FormDiscoverFeeds : public QDialog {
|
||||||
|
@ -56,6 +43,9 @@ class FormDiscoverFeeds : public QDialog {
|
||||||
void addSingleFeed(StandardFeed* feed);
|
void addSingleFeed(StandardFeed* feed);
|
||||||
void importSelectedFeeds();
|
void importSelectedFeeds();
|
||||||
|
|
||||||
|
void onDiscoveryProgress(int progress);
|
||||||
|
void onDiscoveryFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<StandardFeed*> discoverFeedsWithParser(const FeedParser* parser, const QString& url);
|
QList<StandardFeed*> discoverFeedsWithParser(const FeedParser* parser, const QString& url);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>513</width>
|
<width>593</width>
|
||||||
<height>360</height>
|
<height>360</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="2">
|
<item row="2" column="0" colspan="2">
|
||||||
<widget class="QGroupBox" name="m_gbFeeds">
|
<widget class="QGroupBox" name="m_gbFeeds">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
@ -57,31 +57,6 @@
|
||||||
<string>Discovered feeds</string>
|
<string>Discovered feeds</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout_2">
|
<layout class="QFormLayout" name="formLayout_2">
|
||||||
<item row="1" column="0" colspan="2">
|
|
||||||
<widget class="QTableView" name="m_tvFeeds">
|
|
||||||
<property name="alternatingRowColors">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<property name="selectionMode">
|
|
||||||
<enum>QAbstractItemView::SingleSelection</enum>
|
|
||||||
</property>
|
|
||||||
<property name="selectionBehavior">
|
|
||||||
<enum>QAbstractItemView::SelectRows</enum>
|
|
||||||
</property>
|
|
||||||
<property name="cornerButtonEnabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<attribute name="horizontalHeaderVisible">
|
|
||||||
<bool>true</bool>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="horizontalHeaderStretchLastSection">
|
|
||||||
<bool>true</bool>
|
|
||||||
</attribute>
|
|
||||||
<attribute name="verticalHeaderVisible">
|
|
||||||
<bool>false</bool>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="m_lblParentCategory">
|
<widget class="QLabel" name="m_lblParentCategory">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -125,23 +100,38 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="1" column="0" colspan="2">
|
||||||
<widget class="QProgressBar" name="m_pbDiscovery">
|
<widget class="QTreeView" name="m_tvFeeds">
|
||||||
<property name="maximumSize">
|
<property name="alternatingRowColors">
|
||||||
<size>
|
<bool>true</bool>
|
||||||
<width>16777215</width>
|
|
||||||
<height>5</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="textVisible">
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionBehavior">
|
||||||
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
|
<property name="indentation">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="uniformRowHeights">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="itemsExpandable">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<attribute name="headerStretchLastSection">
|
||||||
|
<bool>false</bool>
|
||||||
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0" colspan="2">
|
<item row="3" column="0" colspan="2">
|
||||||
<widget class="QDialogButtonBox" name="m_buttonBox">
|
<widget class="QDialogButtonBox" name="m_buttonBox">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
|
@ -151,6 +141,19 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QProgressBar" name="m_pbDiscovery">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>8</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="textVisible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
Loading…
Add table
Reference in a new issue