From b5b4611ba28a24bd33ca2351a12bc3afcb849932 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 25 Mar 2014 13:47:45 +0100 Subject: [PATCH 1/6] Probably fixed #39. --- src/gui/tabwidget.cpp | 32 ++++++++++++++++++++------------ src/gui/tabwidget.h | 4 ---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/gui/tabwidget.cpp b/src/gui/tabwidget.cpp index 1637fbec4..d18a64da0 100644 --- a/src/gui/tabwidget.cpp +++ b/src/gui/tabwidget.cpp @@ -109,20 +109,33 @@ void TabWidget::checkTabBarVisibility() { } void TabWidget::tabInserted(int index) { - QTabWidget::tabInserted(index); + QTabWidget::tabInserted(index); checkTabBarVisibility(); + + int count_of_tabs = count(); + + if (index < count_of_tabs - 1 && count_of_tabs > 1) { + // New tab was inserted and the tab is not the last one. + fixContentsAfterMove(index, count_of_tabs - 1); + } } void TabWidget::tabRemoved(int index) { QTabWidget::tabRemoved(index); checkTabBarVisibility(); + + int count_of_tabs = count(); + + if (index < count_of_tabs && count_of_tabs > 1) { + // Some tab was removed and the tab was not the last one. + fixContentsAfterMove(index, count_of_tabs - 1); + } } void TabWidget::createConnections() { connect(tabBar(), SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); connect(tabBar(), SIGNAL(emptySpaceDoubleClicked()), this, SLOT(addEmptyBrowser())); connect(tabBar(), SIGNAL(tabMoved(int,int)), this, SLOT(fixContentsAfterMove(int,int))); - connect(tabBar(), SIGNAL(currentChanged(int)), this, SLOT(fixContentAfterIndexChange(int))); } void TabWidget::initializeTabs() { @@ -324,17 +337,12 @@ void TabWidget::changeTitle(int index, const QString &new_title) { setTabToolTip(index, new_title); } -void TabWidget::fixContentAfterIndexChange(int from) { - fixContentsIndexes(from, count() - 1); -} - void TabWidget::fixContentsAfterMove(int from, int to) { - fixContentsIndexes(qMin(from, to), qMax(from, to)); -} + from = qMin(from, to); + to = qMax(from, to); -void TabWidget::fixContentsIndexes(int starting_index, int ending_index) { - for ( ; starting_index <= ending_index; starting_index++) { - TabContent *content = static_cast(widget(starting_index)); - content->setIndex(starting_index); + for ( ; from <= to; from++) { + TabContent *content = static_cast(widget(from)); + content->setIndex(from); } } diff --git a/src/gui/tabwidget.h b/src/gui/tabwidget.h index 0ff91a1c4..db0f516ce 100644 --- a/src/gui/tabwidget.h +++ b/src/gui/tabwidget.h @@ -85,12 +85,8 @@ class TabWidget : public QTabWidget { public slots: // Fixes tabs indexes. - void fixContentAfterIndexChange(int from); void fixContentsAfterMove(int from, int to); - // Fixes indexes of tab contents. - void fixContentsIndexes(int starting_index, int ending_index); - // Called when number of tab pages changes. void checkTabBarVisibility(); From 04a49a1eff5bc04d2ed0bd5d3877dd61f3213cac Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 25 Mar 2014 12:49:03 +0000 Subject: [PATCH 2/6] CHANGELOG edited online with Bitbucket. --- resources/text/CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG index 33d2a5960..4a8574501 100644 --- a/resources/text/CHANGELOG +++ b/resources/text/CHANGELOG @@ -5,6 +5,7 @@ Fixed:
  • Informative buttons now do not accept focus.
  • Button for resetting keyboard shortcut now works.
  • +
  • Fixed web browser tab title/icon handling (bug #39).
Added: From f1f84acbe67ce19649b2c7db754cab3c8e12c891 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 26 Mar 2014 07:30:26 +0100 Subject: [PATCH 3/6] Some commenting. --- src/gui/feedsview.cpp | 2 ++ src/gui/feedsview.h | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 8201a2c16..cbc219a11 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -431,6 +431,8 @@ void FeedsView::deleteSelectedItem() { if (m_sourceModel->removeItem(m_proxyModel->mapToSource(current_index))) { // Item WAS removed, update counts. + // TODO:_I do not need to update counts of all items here. + // Updating counts of parent item (feed) should be enough. updateCountsOfAllFeeds(true); } else { diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 257623435..3eadb5a63 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -38,6 +38,7 @@ class FeedsView : public QTreeView { explicit FeedsView(QWidget *parent = 0); virtual ~FeedsView(); + // Fundamental accessors. inline FeedsProxyModel *model() { return m_proxyModel; } @@ -66,6 +67,8 @@ class FeedsView : public QTreeView { FeedsModelCategory *isCurrentIndexCategory() const; FeedsModelFeed *isCurrentIndexFeed() const; + // Saves/loads expand states of all nodes (feeds/categories) of the list + // to/from settings. void saveExpandedStates(); void loadExpandedStates(); @@ -82,7 +85,6 @@ class FeedsView : public QTreeView { void markSelectedFeedsReadStatus(int read); void markSelectedFeedsRead(); void markSelectedFeedsUnread(); - void markAllFeedsReadStatus(int read); void markAllFeedsRead(); @@ -124,6 +126,7 @@ class FeedsView : public QTreeView { m_sourceModel->countOfAllMessages()); } + // Selects next/previous item (feed/category) in the list. void selectNextItem(); void selectPreviousItem(); From cefbefda2ad915981ab3051bb6b6cab44417f2f6 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 26 Mar 2014 08:33:50 +0100 Subject: [PATCH 4/6] Massive cleanups. --- CMakeLists.txt | 2 - resources/text/CHANGELOG | 1 + src/core/feedsmodel.cpp | 45 ++- src/core/feedsmodel.h | 18 +- src/core/feedsmodelcategory.cpp | 121 ++++++- src/core/feedsmodelcategory.h | 18 +- src/core/feedsmodelfeed.cpp | 408 +++++++++++++++++++++- src/core/feedsmodelfeed.h | 108 +++++- src/core/feedsmodelstandardcategory.cpp | 146 -------- src/core/feedsmodelstandardcategory.h | 52 --- src/core/feedsmodelstandardfeed.cpp | 431 ------------------------ src/core/feedsmodelstandardfeed.h | 130 ------- src/core/networkfactory.cpp | 3 +- src/core/networkfactory.h | 2 - src/core/silentnetworkaccessmanager.cpp | 2 - src/gui/feedmessageviewer.cpp | 10 +- src/gui/feedsview.cpp | 26 +- src/gui/feedsview.h | 8 +- src/gui/formmain.cpp | 9 +- src/gui/formmain.ui | 29 +- src/gui/formstandardcategorydetails.cpp | 11 +- src/gui/formstandardcategorydetails.h | 8 +- src/gui/formstandardfeeddetails.cpp | 43 ++- src/gui/formstandardfeeddetails.h | 8 +- 24 files changed, 745 insertions(+), 894 deletions(-) delete mode 100755 src/core/feedsmodelstandardcategory.cpp delete mode 100644 src/core/feedsmodelstandardcategory.h delete mode 100755 src/core/feedsmodelstandardfeed.cpp delete mode 100644 src/core/feedsmodelstandardfeed.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 21aeabba4..182ed27ba 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -320,8 +320,6 @@ set(APP_SOURCES src/core/feedsmodelcategory.cpp src/core/feedsmodelrootitem.cpp src/core/feedsmodelfeed.cpp - src/core/feedsmodelstandardcategory.cpp - src/core/feedsmodelstandardfeed.cpp src/core/parsingfactory.cpp src/core/feeddownloader.cpp src/core/networkfactory.cpp diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG index 4a8574501..c7cbc7353 100644 --- a/resources/text/CHANGELOG +++ b/resources/text/CHANGELOG @@ -20,6 +20,7 @@ Added: Changed:
    +
  • Massive code cleanups.
  • Removed "progress bar" from address text edit of web browser.
  • Removed "blau" skin due to its slowness.
  • Tab order and default widget changed for category/feed add/edit dialogs.
  • diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index df4dbe26e..1dc6f08b7 100644 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -19,8 +19,8 @@ #include "core/defs.h" #include "core/databasefactory.h" -#include "core/feedsmodelstandardcategory.h" -#include "core/feedsmodelstandardfeed.h" +#include "core/feedsmodelcategory.h" +#include "core/feedsmodelfeed.h" #include "core/textfactory.h" #include "gui/iconthemefactory.h" #include "gui/iconfactory.h" @@ -177,7 +177,7 @@ bool FeedsModel::removeItem(const QModelIndex &index) { return false; } -bool FeedsModel::addStandardCategory(FeedsModelStandardCategory *category, +bool FeedsModel::addCategory(FeedsModelCategory *category, FeedsModelRootItem *parent) { // Get index of parent item (parent standard category). QModelIndex parent_index = indexForItem(parent); @@ -225,8 +225,8 @@ bool FeedsModel::addStandardCategory(FeedsModelStandardCategory *category, return true; } -bool FeedsModel::editStandardCategory(FeedsModelStandardCategory *original_category, - FeedsModelStandardCategory *new_category) { +bool FeedsModel::editCategory(FeedsModelCategory *original_category, + FeedsModelCategory *new_category) { QSqlDatabase database = DatabaseFactory::instance()->connection(objectName(), DatabaseFactory::FromSettings); QSqlQuery query_update_category(database); @@ -281,7 +281,7 @@ bool FeedsModel::editStandardCategory(FeedsModelStandardCategory *original_categ return true; } -bool FeedsModel::addStandardFeed(FeedsModelStandardFeed *feed, +bool FeedsModel::addFeed(FeedsModelFeed *feed, FeedsModelRootItem *parent) { // Get index of parent item (parent standard category). QModelIndex parent_index = indexForItem(parent); @@ -336,8 +336,8 @@ bool FeedsModel::addStandardFeed(FeedsModelStandardFeed *feed, return true; } -bool FeedsModel::editStandardFeed(FeedsModelStandardFeed *original_feed, - FeedsModelStandardFeed *new_feed) { +bool FeedsModel::editFeed(FeedsModelFeed *original_feed, + FeedsModelFeed *new_feed) { QSqlDatabase database = DatabaseFactory::instance()->connection(objectName(), DatabaseFactory::FromSettings); QSqlQuery query_update_feed(database); @@ -413,34 +413,32 @@ QList FeedsModel::feedsForScheduledUpdate(bool auto_update_now) QList feeds_for_update; foreach (FeedsModelFeed *feed, allFeeds()) { - FeedsModelStandardFeed *std_feed = static_cast(feed); - - switch (std_feed->autoUpdateType()) { - case FeedsModelStandardFeed::DontAutoUpdate: + switch (feed->autoUpdateType()) { + case FeedsModelFeed::DontAutoUpdate: // Do not auto-update this feed ever. continue; - case FeedsModelStandardFeed::DefaultAutoUpdate: + case FeedsModelFeed::DefaultAutoUpdate: if (auto_update_now) { feeds_for_update.append(feed); } break; - case FeedsModelStandardFeed::SpecificAutoUpdate: + case FeedsModelFeed::SpecificAutoUpdate: default: - int remaining_interval = std_feed->autoUpdateRemainingInterval(); + int remaining_interval = feed->autoUpdateRemainingInterval(); if (--remaining_interval <= 0) { // Interval of this feed passed, include this feed in the output list // and reset the interval. feeds_for_update.append(feed); - std_feed->setAutoUpdateRemainingInterval(std_feed->autoUpdateInitialInterval()); + feed->setAutoUpdateRemainingInterval(feed->autoUpdateInitialInterval()); } else { // Interval did not pass, set new decremented interval and do NOT // include this feed in the output list. - std_feed->setAutoUpdateRemainingInterval(remaining_interval); + feed->setAutoUpdateRemainingInterval(remaining_interval); } break; @@ -613,13 +611,12 @@ void FeedsModel::loadFromDatabase() { case FeedsModelCategory::Standard: { CategoryAssignmentItem pair; pair.first = query_categories.value(CAT_DB_PARENT_ID_INDEX).toInt(); - pair.second = FeedsModelStandardCategory::loadFromRecord(query_categories.record()); + pair.second = FeedsModelCategory::loadFromRecord(query_categories.record()); categories << pair; break; } - case FeedsModelCategory::Feedly: default: break; } @@ -639,13 +636,13 @@ void FeedsModel::loadFromDatabase() { FeedsModelFeed::Type type = static_cast(query_feeds.value(FDS_DB_TYPE_INDEX).toInt()); switch (type) { - case FeedsModelFeed::StandardAtom10: - case FeedsModelFeed::StandardRdf: - case FeedsModelFeed::StandardRss0X: - case FeedsModelFeed::StandardRss2X: { + case FeedsModelFeed::Atom10: + case FeedsModelFeed::Rdf: + case FeedsModelFeed::Rss0X: + case FeedsModelFeed::Rss2X: { FeedAssignmentItem pair; pair.first = query_feeds.value(FDS_DB_CATEGORY_INDEX).toInt(); - pair.second = FeedsModelStandardFeed::loadFromRecord(query_feeds.record()); + pair.second = FeedsModelFeed::loadFromRecord(query_feeds.record()); pair.second->setType(type); feeds << pair; diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index aec09edec..6e2b1333b 100644 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -28,8 +28,6 @@ class FeedsModelCategory; class FeedsModelFeed; -class FeedsModelStandardCategory; -class FeedsModelStandardFeed; typedef QList > CategoryAssignment; typedef QPair CategoryAssignmentItem; @@ -72,20 +70,20 @@ class FeedsModel : public QAbstractItemModel { bool removeItem(const QModelIndex &index); // Standard category manipulators. - bool addStandardCategory(FeedsModelStandardCategory *category, - FeedsModelRootItem *parent); - bool editStandardCategory(FeedsModelStandardCategory *original_category, - FeedsModelStandardCategory *new_category); + bool addCategory(FeedsModelCategory *category, + FeedsModelRootItem *parent); + bool editCategory(FeedsModelCategory *original_category, + FeedsModelCategory *new_category); // Standard feed manipulators. - bool addStandardFeed(FeedsModelStandardFeed *feed, - FeedsModelRootItem *parent); + bool addFeed(FeedsModelFeed *feed, + FeedsModelRootItem *parent); // New feed is just temporary feed, it is not added to the model. // It is used to fetch its data to the original feed // and the original feed is moved if needed. - bool editStandardFeed(FeedsModelStandardFeed *original_feed, - FeedsModelStandardFeed *new_feed); + bool editFeed(FeedsModelFeed *original_feed, + FeedsModelFeed *new_feed); // Returns the list of updates which should be updated // according to auto-update schedule. diff --git a/src/core/feedsmodelcategory.cpp b/src/core/feedsmodelcategory.cpp index 3f343b320..ec86a7f2a 100755 --- a/src/core/feedsmodelcategory.cpp +++ b/src/core/feedsmodelcategory.cpp @@ -17,12 +17,20 @@ #include "core/feedsmodelcategory.h" -#include "core/feedsmodelstandardcategory.h" -#include "core/feedsmodelstandardfeed.h" +#include "core/defs.h" +#include "core/databasefactory.h" +#include "core/textfactory.h" +#include "core/settings.h" +#include "gui/iconthemefactory.h" +#include "gui/iconfactory.h" + +#include +#include FeedsModelCategory::FeedsModelCategory(FeedsModelRootItem *parent_item) : FeedsModelRootItem(parent_item) { + m_type = Standard; m_kind = FeedsModelRootItem::Category; } @@ -40,4 +48,113 @@ FeedsModelCategory::FeedsModelCategory(const FeedsModelCategory &other) } FeedsModelCategory::~FeedsModelCategory() { + qDebug("Destroying FeedsModelCategory instance."); +} + +QVariant FeedsModelCategory::data(int column, int role) const { + switch (role) { + case Qt::ToolTipRole: + if (column == FDS_MODEL_TITLE_INDEX) { + //: Tooltip for standard feed. + return tr("%1 (category)\n" + "%2%3").arg(m_title, + m_description, + m_childItems.size() == 0 ? + tr("\n\nThis category does not contain any nested items.") : + ""); + } + else if (column == FDS_MODEL_COUNTS_INDEX) { + //: Tooltip for "unread" column of feed list. + return tr("%n unread message(s).", "", countOfUnreadMessages()); + } + else { + return QVariant(); + } + + case Qt::EditRole: + if (column == FDS_MODEL_TITLE_INDEX) { + return m_title; + } + else if (column == FDS_MODEL_COUNTS_INDEX) { + return countOfUnreadMessages(); + } + else { + return QVariant(); + } + + case Qt::FontRole: + return countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont; + + case Qt::DisplayRole: + if (column == FDS_MODEL_TITLE_INDEX) { + return m_title; + } + else if (column == FDS_MODEL_COUNTS_INDEX) { + return Settings::instance()->value(APP_CFG_FEEDS, + "count_format", + "(%unread)").toString() + .replace("%unread", QString::number(countOfUnreadMessages())) + .replace("%all", QString::number(countOfAllMessages())); + } + else { + return QVariant(); + } + + case Qt::DecorationRole: + if (column == FDS_MODEL_TITLE_INDEX) { + return m_icon; + } + else { + return QVariant(); + } + + case Qt::TextAlignmentRole: + if (column == FDS_MODEL_COUNTS_INDEX) { + return Qt::AlignCenter; + } + else { + return QVariant(); + } + + default: + return QVariant(); + } +} + +bool FeedsModelCategory::removeItself() { + bool result = true; + + // Remove all child items (feeds, categories.) + foreach (FeedsModelRootItem *child, m_childItems) { + result &= child->removeItself(); + } + + if (!result) { + return result; + } + + // Children are removed, remove this standard category too. + QSqlDatabase database = DatabaseFactory::instance()->connection("FeedsModelCategory", + DatabaseFactory::FromSettings); + QSqlQuery query_remove(database); + + query_remove.setForwardOnly(true); + + // Remove all messages from this standard feed. + query_remove.prepare("DELETE FROM Categories WHERE id = :category;"); + query_remove.bindValue(":category", id()); + + return query_remove.exec(); +} + +FeedsModelCategory *FeedsModelCategory::loadFromRecord(const QSqlRecord &record) { + FeedsModelCategory *category = new FeedsModelCategory(NULL); + + category->setId(record.value(CAT_DB_ID_INDEX).toInt()); + category->setTitle(record.value(CAT_DB_TITLE_INDEX).toString()); + category->setDescription(record.value(CAT_DB_DESCRIPTION_INDEX).toString()); + category->setCreationDate(TextFactory::parseDateTime(record.value(CAT_DB_DCREATED_INDEX).value()).toLocalTime()); + category->setIcon(IconFactory::fromByteArray(record.value(CAT_DB_ICON_INDEX).toByteArray())); + + return category; } diff --git a/src/core/feedsmodelcategory.h b/src/core/feedsmodelcategory.h index 4d729b6ec..41fc62458 100755 --- a/src/core/feedsmodelcategory.h +++ b/src/core/feedsmodelcategory.h @@ -20,6 +20,9 @@ #include "core/feedsmodelrootitem.h" +#include +#include + class FeedsModelFeed; @@ -27,12 +30,13 @@ class FeedsModelFeed; // NOTE: This class should be derived to create PARTICULAR category types. // NOTE: This class should not be instantiated directly. class FeedsModelCategory : public FeedsModelRootItem { + Q_DECLARE_TR_FUNCTIONS(FeedsModelCategory) + public: // Describes possible types of categories. // NOTE: This is equivavelnt to Categories(type). enum Type { - Standard = 0, - Feedly = 1 + Standard = 0 }; // Constructors and destructors @@ -40,6 +44,13 @@ class FeedsModelCategory : public FeedsModelRootItem { explicit FeedsModelCategory(const FeedsModelCategory &other); virtual ~FeedsModelCategory(); + // Returns the actual data representation of standard category. + QVariant data(int column, int role) const; + + // Removes category and all its children from persistent + // database. + bool removeItself(); + // All types of categories offer these getters/setters. inline Type type() const { return m_type; @@ -49,6 +60,9 @@ class FeedsModelCategory : public FeedsModelRootItem { m_type = type; } + // Loads particular "standard category" from given sql record. + static FeedsModelCategory *loadFromRecord(const QSqlRecord &record); + protected: Type m_type; }; diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index ead675e89..eac81a210 100755 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -17,23 +17,38 @@ #include "core/feedsmodelfeed.h" +#include "core/defs.h" +#include "core/settings.h" +#include "core/parsingfactory.h" #include "core/databasefactory.h" +#include "core/networkfactory.h" +#include "core/textfactory.h" +#include "gui/iconfactory.h" +#include "gui/iconthemefactory.h" #include #include #include #include +#include +#include +#include +#include +#include FeedsModelFeed::FeedsModelFeed(FeedsModelRootItem *parent_item) : FeedsModelRootItem(parent_item), - m_type(StandardRss0X), + m_type(Rss0X), m_totalCount(0), - m_unreadCount(0) { + m_unreadCount(0), + m_autoUpdateType(DontAutoUpdate), + m_autoUpdateInitialInterval(DEFAULT_AUTO_UPDATE_INTERVAL) { m_kind = FeedsModelRootItem::Feed; } FeedsModelFeed::~FeedsModelFeed() { + qDebug("Destroying FeedsModelFeed instance."); } int FeedsModelFeed::childCount() const { @@ -51,16 +66,16 @@ int FeedsModelFeed::countOfUnreadMessages() const { QString FeedsModelFeed::typeToString(FeedsModelFeed::Type type) { switch (type) { - case StandardAtom10: + case Atom10: return "ATOM 1.0"; - case StandardRdf: - return "RDF"; + case Rdf: + return "RDF (RSS 1.0)"; - case StandardRss0X: + case Rss0X: return "RSS 0.91/0.92/0.93"; - case StandardRss2X: + case Rss2X: default: return "RSS 2.0/2.0.1"; } @@ -88,5 +103,384 @@ void FeedsModelFeed::updateCounts(bool including_total_count) { } } +FeedsModelFeed *FeedsModelFeed::loadFromRecord(const QSqlRecord &record) { + FeedsModelFeed *feed = new FeedsModelFeed(); + feed->setTitle(record.value(FDS_DB_TITLE_INDEX).toString()); + feed->setId(record.value(FDS_DB_ID_INDEX).toInt()); + feed->setDescription(record.value(FDS_DB_DESCRIPTION_INDEX).toString()); + feed->setCreationDate(TextFactory::parseDateTime(record.value(FDS_DB_DCREATED_INDEX).value()).toLocalTime()); + feed->setIcon(IconFactory::fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray())); + feed->setEncoding(record.value(FDS_DB_ENCODING_INDEX).toString()); + feed->setUrl(record.value(FDS_DB_URL_INDEX).toString()); + feed->setPasswordProtected(record.value(FDS_DB_PROTECTED_INDEX).toBool()); + feed->setUsername(record.value(FDS_DB_USERNAME_INDEX).toString()); + feed->setPassword(record.value(FDS_DB_PASSWORD_INDEX).toString()); + feed->setAutoUpdateType(static_cast(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt())); + feed->setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt()); + feed->updateCounts(); + return feed; +} + +QPair FeedsModelFeed::guessFeed(const QString &url, + const QString &username, + const QString &password) { + QPair result; result.first = NULL; + + // Try to obtain icon. + QIcon icon_data; + + if ((result.second = NetworkFactory::downloadIcon(url, 5000, icon_data)) == + QNetworkReply::NoError) { + // Icon for feed was downloaded and is stored now in _icon_data. + result.first = new FeedsModelFeed(); + result.first->setIcon(icon_data); + } + + QByteArray feed_contents; + if ((result.second = NetworkFactory::downloadFeedFile(url, + Settings::instance()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(), + feed_contents, + !username.isEmpty(), + username, + password)) == QNetworkReply::NoError) { + // Feed XML was obtained, now we need to try to guess + // its encoding before we can read further data. + QString xml_schema_encoding; + QString xml_contents_encoded; + QRegExp encoding_rexp("encoding=\"[^\"]\\S+\""); + + if (encoding_rexp.indexIn(feed_contents) != -1 && + !(xml_schema_encoding = encoding_rexp.cap(0)).isEmpty()) { + // Some "encoding" attribute was found get the encoding + // out of it. + encoding_rexp.setPattern("[^\"]\\S+[^\"]"); + encoding_rexp.indexIn(xml_schema_encoding, 9); + xml_schema_encoding = encoding_rexp.cap(0); + } + + if (result.first == NULL) { + result.first = new FeedsModelFeed(); + } + + QTextCodec *custom_codec = QTextCodec::codecForName(xml_schema_encoding.toLocal8Bit()); + + if (custom_codec != NULL) { + // Feed encoding was probably guessed. + xml_contents_encoded = custom_codec->toUnicode(feed_contents); + result.first->setEncoding(xml_schema_encoding); + } + else { + // Feed encoding probably not guessed, set it as + // default. + xml_contents_encoded = feed_contents; + result.first->setEncoding(DEFAULT_FEED_ENCODING); + } + + // Feed XML was obtained, guess it now. + QDomDocument xml_document; + QString error_msg; + int error_line, error_column; + + if (!xml_document.setContent(xml_contents_encoded, + &error_msg, + &error_line, + &error_column)) { + qDebug("XML of feed '%s' is not valid and cannot be loaded. Error: '%s' " + "(line %d, column %d).", + qPrintable(url), + qPrintable(error_msg), + error_line, error_column); + + result.second = QNetworkReply::UnknownContentError; + + // XML is invalid, exit. + return result; + } + + QDomElement root_element = xml_document.documentElement(); + QString root_tag_name = root_element.tagName(); + + if (root_tag_name == "rdf:RDF") { + // We found RDF feed. + QDomElement channel_element = root_element.namedItem("channel").toElement(); + + result.first->setType(Rdf); + result.first->setTitle(channel_element.namedItem("title").toElement().text()); + result.first->setDescription(channel_element.namedItem("description").toElement().text()); + } + else if (root_tag_name == "rss") { + // We found RSS 0.91/0.92/0.93/2.0/2.0.1 feed. + QString rss_type = root_element.attribute("version", "2.0"); + + if (rss_type == "0.91" || rss_type == "0.92" || rss_type == "0.93") { + result.first->setType(Rss0X); + } + else { + result.first->setType(Rss2X); + } + + QDomElement channel_element = root_element.namedItem("channel").toElement(); + + result.first->setTitle(channel_element.namedItem("title").toElement().text()); + result.first->setDescription(channel_element.namedItem("description").toElement().text()); + } + else if (root_tag_name == "feed") { + // We found ATOM feed. + result.first->setType(Atom10); + result.first->setTitle(root_element.namedItem("title").toElement().text()); + result.first->setDescription(root_element.namedItem("subtitle").toElement().text()); + } + else { + // File was downloaded and it really was XML file + // but feed format was NOT recognized. + result.second = QNetworkReply::UnknownContentError; + } + } + + return result; +} + +QVariant FeedsModelFeed::data(int column, int role) const { + switch (role) { + case Qt::DisplayRole: + if (column == FDS_MODEL_TITLE_INDEX) { + return m_title; + } + else if (column == FDS_MODEL_COUNTS_INDEX) { + return Settings::instance()->value(APP_CFG_FEEDS, + "count_format", + "(%unread)").toString() + .replace("%unread", QString::number(countOfUnreadMessages())) + .replace("%all", QString::number(countOfAllMessages())); + } + else { + return QVariant(); + } + + case Qt::EditRole: + if (column == FDS_MODEL_TITLE_INDEX) { + return m_title; + } + else if (column == FDS_MODEL_COUNTS_INDEX) { + return countOfUnreadMessages(); + } + else { + return QVariant(); + } + + case Qt::DecorationRole: + if (column == FDS_MODEL_TITLE_INDEX) { + return m_icon; + } + else { + return QVariant(); + } + + case Qt::ToolTipRole: + if (column == FDS_MODEL_TITLE_INDEX) { + QString auto_update_string; + + switch (m_autoUpdateType) { + case DontAutoUpdate: + //: Describes feed auto-update status. + auto_update_string = tr("does not use auto-update"); + break; + + case DefaultAutoUpdate: + //: Describes feed auto-update status. + auto_update_string = tr("uses global settings"); + break; + + case SpecificAutoUpdate: + default: + //: Describes feed auto-update status. + auto_update_string = tr("uses specific settings " + "(%n minute(s) to next auto-update)", + 0, + m_autoUpdateRemainingInterval); + break; + } + + //: Tooltip for feed. + return tr("%1 (%2)\n" + "%3\n\n" + "Encoding: %4\n" + "Auto-update status: %5").arg(m_title, + FeedsModelFeed::typeToString(m_type), + m_description, + m_encoding, + auto_update_string); + } + else if (column == FDS_MODEL_COUNTS_INDEX) { + //: Tooltip for "unread" column of feed list. + return tr("%n unread message(s).", 0, countOfUnreadMessages()); + } + else { + return QVariant(); + } + + case Qt::TextAlignmentRole: + if (column == FDS_MODEL_COUNTS_INDEX) { + return Qt::AlignCenter; + } + else { + return QVariant(); + } + + case Qt::FontRole: + return countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont; + + default: + return QVariant(); + } +} + +void FeedsModelFeed::update() { + QByteArray feed_contents; + int download_timeout = Settings::instance()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(); + QNetworkReply::NetworkError download_result = NetworkFactory::downloadFeedFile(url(), + download_timeout, + feed_contents, + passwordProtected(), + username(), + password()); + + if (download_result != QNetworkReply::NoError) { + qWarning("Error during fetching of new messages for feed '%s' (id %d).", + qPrintable(url()), + id()); + return; + } + + // Encode downloaded data for further parsing. + QTextCodec *codec = QTextCodec::codecForName(encoding().toLocal8Bit()); + QString formatted_feed_contents; + + if (codec == NULL) { + // No suitable codec for this encoding was found. + // Use non-converted data. + formatted_feed_contents = feed_contents; + } + else { + formatted_feed_contents = codec->toUnicode(feed_contents); + } + + // Feed data are downloaded and encoded. + // Parse data and obtain messages. + QList messages; + + switch (type()) { + case FeedsModelFeed::Rss0X: + case FeedsModelFeed::Rss2X: + messages = ParsingFactory::parseAsRSS20(formatted_feed_contents); + break; + + case FeedsModelFeed::Rdf: + messages = ParsingFactory::parseAsRDF(formatted_feed_contents); + break; + + case FeedsModelFeed::Atom10: + messages = ParsingFactory::parseAsATOM10(formatted_feed_contents); + + default: + break; + } + + updateMessages(messages); +} + +bool FeedsModelFeed::removeItself() { + QSqlDatabase database = DatabaseFactory::instance()->connection("FeedsModelFeed", + DatabaseFactory::FromSettings); + QSqlQuery query_remove(database); + + query_remove.setForwardOnly(true); + + // Remove all messages from this standard feed. + query_remove.prepare("DELETE FROM Messages WHERE feed = :feed;"); + query_remove.bindValue(":feed", id()); + + if (!query_remove.exec()) { + return false; + } + + // Remove feed itself. + query_remove.prepare("DELETE FROM Feeds WHERE id = :feed;"); + query_remove.bindValue(":feed", id()); + + return query_remove.exec(); +} + +void FeedsModelFeed::updateMessages(const QList &messages) { + int feed_id = id(); + QSqlDatabase database = DatabaseFactory::instance()->connection("FeedsModelFeed", + DatabaseFactory::FromSettings); + + // Prepare queries. + QSqlQuery query_select(database); + QSqlQuery query_insert(database); + + // Used to check if give feed contains with message with given + // title, url and date_created. + // WARNING: One feed CANNOT contain two (or more) messages with same + // AUTHOR AND TITLE AND URL AND DATE_CREATED. + query_select.setForwardOnly(true); + query_select.prepare("SELECT id, feed, date_created FROM Messages " + "WHERE feed = :feed AND title = :title AND url = :url AND author = :author;"); + + // Used to insert new messages. + query_insert.setForwardOnly(true); + query_insert.prepare("INSERT INTO Messages " + "(feed, title, url, author, date_created, contents) " + "VALUES (:feed, :title, :url, :author, :date_created, :contents);"); + + if (!database.transaction()) { + database.rollback(); + + qDebug("Transaction start for message downloader failed."); + return; + } + + foreach (const Message &message, messages) { + query_select.bindValue(":feed", feed_id); + query_select.bindValue(":title", message.m_title); + query_select.bindValue(":url", message.m_url); + query_select.bindValue(":author", message.m_author); + query_select.exec(); + + QList datetime_stamps; + + while (query_select.next()) { + datetime_stamps << query_select.value(2).value(); + } + + query_select.finish(); + + if (datetime_stamps.size() == 0 || + (message.m_createdFromFeed && + !datetime_stamps.contains(message.m_created.toMSecsSinceEpoch()))) { + // Message is not fetched in this feed yet + // or it is. If it is, then go + // through datetime stamps of stored messages + // and check if new (not auto-generated timestamp + // is among them and add this message if it is not. + query_insert.bindValue(":feed", feed_id); + query_insert.bindValue(":title", message.m_title); + query_insert.bindValue(":url", message.m_url); + query_insert.bindValue(":author", message.m_author); + query_insert.bindValue(":date_created", message.m_created.toMSecsSinceEpoch()); + query_insert.bindValue(":contents", message.m_contents); + + query_insert.exec(); + query_insert.finish(); + } + } + + if (!database.commit()) { + database.rollback(); + + qDebug("Transaction commit for message downloader failed."); + } +} diff --git a/src/core/feedsmodelfeed.h b/src/core/feedsmodelfeed.h index 72028b132..884874ae0 100755 --- a/src/core/feedsmodelfeed.h +++ b/src/core/feedsmodelfeed.h @@ -21,19 +21,36 @@ #include "core/feedsmodelrootitem.h" #include +#include +#include +#include +#include +#include + + +class Message; // Represents BASE class for feeds contained in FeedsModel. // NOTE: This class should be derived to create PARTICULAR feed types. class FeedsModelFeed : public FeedsModelRootItem { + Q_DECLARE_TR_FUNCTIONS(FeedsModelFeed) + public: // Describes possible types of feeds. // NOTE: This is equivalent to attribute Feeds(type). enum Type { - StandardRss0X = 0, - StandardRss2X = 1, - StandardRdf = 2, - StandardAtom10 = 3 + Rss0X = 0, + Rss2X = 1, + Rdf = 2, + Atom10 = 3 + }; + + // Specifies the auto-update strategy for the feed. + enum AutoUpdateType { + DontAutoUpdate = 0, + DefaultAutoUpdate = 1, + SpecificAutoUpdate = 2 }; // Constructors and destructors. @@ -49,12 +66,15 @@ class FeedsModelFeed : public FeedsModelRootItem { int countOfAllMessages() const; int countOfUnreadMessages() const; - // Each feed can be "updated". - // NOTE: This method is used in the "update worker". - // For example, it can fetch new messages from a remote destination - // and store them in a local database and so on. - virtual void update() { - } + // Obtains data related to this feed. + QVariant data(int column, int role) const; + + // Perform fetching of new messages. + void update(); + + // Removes this standard feed from persistent + // storage. + bool removeItself(); // Other getters/setters. inline Type type() const { @@ -89,6 +109,61 @@ class FeedsModelFeed : public FeedsModelRootItem { m_password = password; } + inline QString encoding() const { + return m_encoding; + } + + inline void setEncoding(const QString &encoding) { + m_encoding = encoding; + } + + inline QString url() const { + return m_url; + } + + inline void setUrl(const QString &url) { + m_url = url; + } + + inline int autoUpdateInitialInterval() const { + return m_autoUpdateInitialInterval; + } + + inline void setAutoUpdateInitialInterval(int auto_update_interval) { + // If new initial auto-update interval is set, then + // we should reset time that remains to the next auto-update. + m_autoUpdateInitialInterval = auto_update_interval; + m_autoUpdateRemainingInterval = auto_update_interval; + } + + inline AutoUpdateType autoUpdateType() const { + return m_autoUpdateType; + } + + inline void setAutoUpdateType(const AutoUpdateType &autoUpdateType) { + m_autoUpdateType = autoUpdateType; + } + + inline int autoUpdateRemainingInterval() const { + return m_autoUpdateRemainingInterval; + } + + inline void setAutoUpdateRemainingInterval(int autoUpdateRemainingInterval) { + m_autoUpdateRemainingInterval = autoUpdateRemainingInterval; + } + + // Loads standard feed object from given SQL record. + static FeedsModelFeed *loadFromRecord(const QSqlRecord &record); + + // Tries to guess feed hidden under given URL + // and uses given credentials. + // Returns pointer to guessed feed (if at least partially + // guessed) and retrieved error/status code from network layer + // or NULL feed. + static QPair guessFeed(const QString &url, + const QString &username, + const QString &password); + // Converts particular feed type to string. static QString typeToString(Type type); @@ -97,6 +172,12 @@ class FeedsModelFeed : public FeedsModelRootItem { void updateCounts(bool including_total_count = true); protected: + // Persistently stores given messages into the database + // and updates existing messages if newer version is + // available. + void updateMessages(const QList &messages); + + private: bool m_passwordProtected; QString m_username; QString m_password; @@ -104,6 +185,13 @@ class FeedsModelFeed : public FeedsModelRootItem { Type m_type; int m_totalCount; int m_unreadCount; + + AutoUpdateType m_autoUpdateType; + int m_autoUpdateInitialInterval; + int m_autoUpdateRemainingInterval; + + QString m_encoding; + QString m_url; }; Q_DECLARE_METATYPE(FeedsModelFeed::Type) diff --git a/src/core/feedsmodelstandardcategory.cpp b/src/core/feedsmodelstandardcategory.cpp deleted file mode 100755 index 3781f4a91..000000000 --- a/src/core/feedsmodelstandardcategory.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// This file is part of RSS Guard. -// -// Copyright (C) 2011-2014 by Martin Rotter -// -// RSS Guard is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// RSS Guard is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with RSS Guard. If not, see . - -#include "core/feedsmodelstandardcategory.h" - -#include "core/defs.h" -#include "core/databasefactory.h" -#include "core/textfactory.h" -#include "core/settings.h" -#include "gui/iconthemefactory.h" -#include "gui/iconfactory.h" - -#include -#include - - -FeedsModelStandardCategory::FeedsModelStandardCategory(FeedsModelRootItem *parent_item) - : FeedsModelCategory(parent_item) { - m_type = Standard; -} - -FeedsModelStandardCategory::~FeedsModelStandardCategory() { - qDebug("Destroying FeedsModelStandardCategory instance."); -} - -QVariant FeedsModelStandardCategory::data(int column, int role) const { - switch (role) { - case Qt::ToolTipRole: - if (column == FDS_MODEL_TITLE_INDEX) { - //: Tooltip for standard feed. - return tr("%1 (standard category)\n" - "%2%3").arg(m_title, - m_description, - m_childItems.size() == 0 ? - tr("\n\nThis category does not contain any nested items.") : - ""); - } - else if (column == FDS_MODEL_COUNTS_INDEX) { - //: Tooltip for "unread" column of feed list. - return tr("%n unread message(s).", "", countOfUnreadMessages()); - } - else { - return QVariant(); - } - - case Qt::EditRole: - if (column == FDS_MODEL_TITLE_INDEX) { - return m_title; - } - else if (column == FDS_MODEL_COUNTS_INDEX) { - return countOfUnreadMessages(); - } - else { - return QVariant(); - } - - case Qt::FontRole: - return countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont; - - case Qt::DisplayRole: - if (column == FDS_MODEL_TITLE_INDEX) { - return m_title; - } - else if (column == FDS_MODEL_COUNTS_INDEX) { - return Settings::instance()->value(APP_CFG_FEEDS, - "count_format", - "(%unread)").toString() - .replace("%unread", QString::number(countOfUnreadMessages())) - .replace("%all", QString::number(countOfAllMessages())); - } - else { - return QVariant(); - } - - case Qt::DecorationRole: - if (column == FDS_MODEL_TITLE_INDEX) { - return m_icon; - } - else { - return QVariant(); - } - - case Qt::TextAlignmentRole: - if (column == FDS_MODEL_COUNTS_INDEX) { - return Qt::AlignCenter; - } - else { - return QVariant(); - } - - default: - return QVariant(); - } -} - -bool FeedsModelStandardCategory::removeItself() { - bool result = true; - - // Remove all child items (feeds, categories.) - foreach (FeedsModelRootItem *child, m_childItems) { - result &= child->removeItself(); - } - - if (!result) { - return result; - } - - // Children are removed, remove this standard category too. - QSqlDatabase database = DatabaseFactory::instance()->connection("FeedsModelStandardCategory", - DatabaseFactory::FromSettings); - QSqlQuery query_remove(database); - - query_remove.setForwardOnly(true); - - // Remove all messages from this standard feed. - query_remove.prepare("DELETE FROM Categories WHERE id = :category;"); - query_remove.bindValue(":category", id()); - - return query_remove.exec(); -} - -FeedsModelStandardCategory *FeedsModelStandardCategory::loadFromRecord(const QSqlRecord &record) { - FeedsModelStandardCategory *category = new FeedsModelStandardCategory(NULL); - - category->setId(record.value(CAT_DB_ID_INDEX).toInt()); - category->setTitle(record.value(CAT_DB_TITLE_INDEX).toString()); - category->setDescription(record.value(CAT_DB_DESCRIPTION_INDEX).toString()); - category->setCreationDate(TextFactory::parseDateTime(record.value(CAT_DB_DCREATED_INDEX).value()).toLocalTime()); - category->setIcon(IconFactory::fromByteArray(record.value(CAT_DB_ICON_INDEX).toByteArray())); - - return category; -} diff --git a/src/core/feedsmodelstandardcategory.h b/src/core/feedsmodelstandardcategory.h deleted file mode 100644 index f5703631e..000000000 --- a/src/core/feedsmodelstandardcategory.h +++ /dev/null @@ -1,52 +0,0 @@ -// This file is part of RSS Guard. -// -// Copyright (C) 2011-2014 by Martin Rotter -// -// RSS Guard is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// RSS Guard is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with RSS Guard. If not, see . - -#ifndef FEEDSMODELSTANDARDCATEGORY_H -#define FEEDSMODELSTANDARDCATEGORY_H - -#include "core/feedsmodelcategory.h" - -#include -#include -#include - - -// Represents STANDARD category container. -// Standard category container can contain: -// a) other standard category containers, -// b) standard feeds, -// c) other containers and feeds (synchronized ones). -class FeedsModelStandardCategory : public FeedsModelCategory { - Q_DECLARE_TR_FUNCTIONS(FeedsModelStandardCategory) - - public: - // Constructors and destructors. - explicit FeedsModelStandardCategory(FeedsModelRootItem *parent_item = NULL); - virtual ~FeedsModelStandardCategory(); - - // Returns the actual data representation of standard category. - QVariant data(int column, int role) const; - - // Removes category and all its children from persistent - // database. - bool removeItself(); - - // Loads particular "standard category" from given sql record. - static FeedsModelStandardCategory *loadFromRecord(const QSqlRecord &record); -}; - -#endif // FEEDSMODELSTANDARDCATEGORY_H diff --git a/src/core/feedsmodelstandardfeed.cpp b/src/core/feedsmodelstandardfeed.cpp deleted file mode 100755 index 25299bbcc..000000000 --- a/src/core/feedsmodelstandardfeed.cpp +++ /dev/null @@ -1,431 +0,0 @@ -// This file is part of RSS Guard. -// -// Copyright (C) 2011-2014 by Martin Rotter -// -// RSS Guard is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// RSS Guard is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with RSS Guard. If not, see . - -#include "core/feedsmodelstandardfeed.h" - -#include "core/defs.h" -#include "core/settings.h" -#include "core/parsingfactory.h" -#include "core/databasefactory.h" -#include "core/networkfactory.h" -#include "core/textfactory.h" -#include "gui/iconfactory.h" -#include "gui/iconthemefactory.h" - -#include -#include -#include - -#include -#include -#include -#include - - -FeedsModelStandardFeed::FeedsModelStandardFeed(FeedsModelRootItem *parent_item) - : FeedsModelFeed(parent_item), - m_autoUpdateType(DontAutoUpdate), - m_autoUpdateInitialInterval(DEFAULT_AUTO_UPDATE_INTERVAL) { -} - -FeedsModelStandardFeed::~FeedsModelStandardFeed() { - qDebug("Destroying FeedsModelStandardFeed instance."); -} - -FeedsModelStandardFeed *FeedsModelStandardFeed::loadFromRecord(const QSqlRecord &record) { - FeedsModelStandardFeed *feed = new FeedsModelStandardFeed(NULL); - - feed->setTitle(record.value(FDS_DB_TITLE_INDEX).toString()); - feed->setId(record.value(FDS_DB_ID_INDEX).toInt()); - feed->setDescription(record.value(FDS_DB_DESCRIPTION_INDEX).toString()); - feed->setCreationDate(TextFactory::parseDateTime(record.value(FDS_DB_DCREATED_INDEX).value()).toLocalTime()); - feed->setIcon(IconFactory::fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray())); - feed->setEncoding(record.value(FDS_DB_ENCODING_INDEX).toString()); - feed->setUrl(record.value(FDS_DB_URL_INDEX).toString()); - feed->setPasswordProtected(record.value(FDS_DB_PROTECTED_INDEX).toBool()); - feed->setUsername(record.value(FDS_DB_USERNAME_INDEX).toString()); - feed->setPassword(record.value(FDS_DB_PASSWORD_INDEX).toString()); - feed->setAutoUpdateType(static_cast(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt())); - feed->setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt()); - feed->updateCounts(); - - return feed; -} - -QPair FeedsModelStandardFeed::guessFeed(const QString &url, - const QString &username, - const QString &password) { - QPair result; result.first = NULL; - - // Try to obtain icon. - QIcon icon_data; - - if ((result.second = NetworkFactory::downloadIcon(url, - 5000, - icon_data)) == - QNetworkReply::NoError) { - // Icon for feed was downloaded and is stored now in _icon_data. - result.first = new FeedsModelStandardFeed(); - result.first->setIcon(icon_data); - } - - QByteArray feed_contents; - if ((result.second = NetworkFactory::downloadFeedFile(url, - Settings::instance()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(), - feed_contents, - !username.isEmpty(), - username, - password)) == QNetworkReply::NoError) { - // Feed XML was obtained, now we need to try to guess - // its encoding before we can read further data. - QString xml_schema_encoding; - QString xml_contents_encoded; - QRegExp encoding_rexp("encoding=\"[^\"]\\S+\""); - - if (encoding_rexp.indexIn(feed_contents) != -1 && - !(xml_schema_encoding = encoding_rexp.cap(0)).isEmpty()) { - // Some "encoding" attribute was found get the encoding - // out of it. - encoding_rexp.setPattern("[^\"]\\S+[^\"]"); - encoding_rexp.indexIn(xml_schema_encoding, 9); - xml_schema_encoding = encoding_rexp.cap(0); - } - - if (result.first == NULL) { - result.first = new FeedsModelStandardFeed(); - } - - QTextCodec *custom_codec = QTextCodec::codecForName(xml_schema_encoding.toLocal8Bit()); - - if (custom_codec != NULL) { - // Feed encoding was probably guessed. - xml_contents_encoded = custom_codec->toUnicode(feed_contents); - result.first->setEncoding(xml_schema_encoding); - } - else { - // Feed encoding probably not guessed, set it as - // default. - xml_contents_encoded = feed_contents; - result.first->setEncoding(DEFAULT_FEED_ENCODING); - } - - // Feed XML was obtained, guess it now. - QDomDocument xml_document; - QString error_msg; - int error_line, error_column; - - if (!xml_document.setContent(xml_contents_encoded, - &error_msg, - &error_line, - &error_column)) { - qDebug("XML of feed '%s' is not valid and cannot be loaded. Error: '%s' " - "(line %d, column %d).", - qPrintable(url), - qPrintable(error_msg), - error_line, error_column); - - result.second = QNetworkReply::UnknownContentError; - - // XML is invalid, exit. - return result; - } - - QDomElement root_element = xml_document.documentElement(); - QString root_tag_name = root_element.tagName(); - - if (root_tag_name == "rdf:RDF") { - // We found RDF feed. - QDomElement channel_element = root_element.namedItem("channel").toElement(); - - result.first->setType(StandardRdf); - result.first->setTitle(channel_element.namedItem("title").toElement().text()); - result.first->setDescription(channel_element.namedItem("description").toElement().text()); - } - else if (root_tag_name == "rss") { - // We found RSS 0.91/0.92/0.93/2.0/2.0.1 feed. - QString rss_type = root_element.attribute("version", "2.0"); - - if (rss_type == "0.91" || rss_type == "0.92" || rss_type == "0.93") { - result.first->setType(StandardRss0X); - } - else { - result.first->setType(StandardRss2X); - } - - QDomElement channel_element = root_element.namedItem("channel").toElement(); - - result.first->setTitle(channel_element.namedItem("title").toElement().text()); - result.first->setDescription(channel_element.namedItem("description").toElement().text()); - } - else if (root_tag_name == "feed") { - // We found ATOM feed. - result.first->setType(StandardAtom10); - result.first->setTitle(root_element.namedItem("title").toElement().text()); - result.first->setDescription(root_element.namedItem("subtitle").toElement().text()); - } - else { - // File was downloaded and it really was XML file - // but feed format was NOT recognized. - result.second = QNetworkReply::UnknownContentError; - } - } - - return result; -} - -QVariant FeedsModelStandardFeed::data(int column, int role) const { - switch (role) { - case Qt::DisplayRole: - if (column == FDS_MODEL_TITLE_INDEX) { - return m_title; - } - else if (column == FDS_MODEL_COUNTS_INDEX) { - return Settings::instance()->value(APP_CFG_FEEDS, - "count_format", - "(%unread)").toString() - .replace("%unread", QString::number(countOfUnreadMessages())) - .replace("%all", QString::number(countOfAllMessages())); - } - else { - return QVariant(); - } - - case Qt::EditRole: - if (column == FDS_MODEL_TITLE_INDEX) { - return m_title; - } - else if (column == FDS_MODEL_COUNTS_INDEX) { - return countOfUnreadMessages(); - } - else { - return QVariant(); - } - - case Qt::DecorationRole: - if (column == FDS_MODEL_TITLE_INDEX) { - return m_icon; - } - else { - return QVariant(); - } - - case Qt::ToolTipRole: - if (column == FDS_MODEL_TITLE_INDEX) { - QString auto_update_string; - - switch (m_autoUpdateType) { - case DontAutoUpdate: - //: Describes feed auto-update status. - auto_update_string = tr("does not use auto-update"); - break; - - case DefaultAutoUpdate: - //: Describes feed auto-update status. - auto_update_string = tr("uses global settings"); - break; - - case SpecificAutoUpdate: - default: - //: Describes feed auto-update status. - auto_update_string = tr("uses specific settings " - "(%n minute(s) to next auto-update)", - 0, - m_autoUpdateRemainingInterval); - break; - } - - //: Tooltip for feed. - return tr("%1 (%2)\n" - "%3\n\n" - "Encoding: %4\n" - "Auto-update status: %5").arg(m_title, - FeedsModelFeed::typeToString(m_type), - m_description, - m_encoding, - auto_update_string); - } - else if (column == FDS_MODEL_COUNTS_INDEX) { - //: Tooltip for "unread" column of feed list. - return tr("%n unread message(s).", 0, countOfUnreadMessages()); - } - else { - return QVariant(); - } - - case Qt::TextAlignmentRole: - if (column == FDS_MODEL_COUNTS_INDEX) { - return Qt::AlignCenter; - } - else { - return QVariant(); - } - - case Qt::FontRole: - return countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont; - - default: - return QVariant(); - } -} - -void FeedsModelStandardFeed::update() { - QByteArray feed_contents; - int download_timeout = Settings::instance()->value(APP_CFG_FEEDS, "feed_update_timeout", DOWNLOAD_TIMEOUT).toInt(); - QNetworkReply::NetworkError download_result = NetworkFactory::downloadFeedFile(url(), - download_timeout, - feed_contents, - passwordProtected(), - username(), - password()); - - if (download_result != QNetworkReply::NoError) { - qWarning("Error during fetching of new messages for feed '%s' (id %d).", - qPrintable(url()), - id()); - return; - } - - // Encode downloaded data for further parsing. - QTextCodec *codec = QTextCodec::codecForName(encoding().toLocal8Bit()); - QString formatted_feed_contents; - - if (codec == NULL) { - // No suitable codec for this encoding was found. - // Use non-converted data. - formatted_feed_contents = feed_contents; - } - else { - formatted_feed_contents = codec->toUnicode(feed_contents); - } - - // Feed data are downloaded and encoded. - // Parse data and obtain messages. - QList messages; - - switch (type()) { - case FeedsModelFeed::StandardRss0X: - case FeedsModelFeed::StandardRss2X: - messages = ParsingFactory::parseAsRSS20(formatted_feed_contents); - break; - - case FeedsModelFeed::StandardRdf: - messages = ParsingFactory::parseAsRDF(formatted_feed_contents); - break; - - case FeedsModelFeed::StandardAtom10: - messages = ParsingFactory::parseAsATOM10(formatted_feed_contents); - - default: - break; - } - - updateMessages(messages); -} - -bool FeedsModelStandardFeed::removeItself() { - QSqlDatabase database = DatabaseFactory::instance()->connection("FeedsModelStandardFeed", - DatabaseFactory::FromSettings); - QSqlQuery query_remove(database); - - query_remove.setForwardOnly(true); - - // Remove all messages from this standard feed. - query_remove.prepare("DELETE FROM Messages WHERE feed = :feed;"); - query_remove.bindValue(":feed", id()); - - if (!query_remove.exec()) { - return false; - } - - // Remove feed itself. - query_remove.prepare("DELETE FROM Feeds WHERE id = :feed;"); - query_remove.bindValue(":feed", id()); - - return query_remove.exec(); -} - -void FeedsModelStandardFeed::updateMessages(const QList &messages) { - int feed_id = id(); - QSqlDatabase database = DatabaseFactory::instance()->connection("FeedsModelStandardFeed", - DatabaseFactory::FromSettings); - - // Prepare queries. - QSqlQuery query_select(database); - QSqlQuery query_insert(database); - - // Used to check if give feed contains with message with given - // title, url and date_created. - // WARNING: One feed CANNOT contain two (or more) messages with same - // AUTHOR AND TITLE AND URL AND DATE_CREATED. - query_select.setForwardOnly(true); - query_select.prepare("SELECT id, feed, date_created FROM Messages " - "WHERE feed = :feed AND title = :title AND url = :url AND author = :author;"); - - // Used to insert new messages. - query_insert.setForwardOnly(true); - query_insert.prepare("INSERT INTO Messages " - "(feed, title, url, author, date_created, contents) " - "VALUES (:feed, :title, :url, :author, :date_created, :contents);"); - - if (!database.transaction()) { - database.rollback(); - - qDebug("Transaction start for message downloader failed."); - return; - } - - foreach (const Message &message, messages) { - query_select.bindValue(":feed", feed_id); - query_select.bindValue(":title", message.m_title); - query_select.bindValue(":url", message.m_url); - query_select.bindValue(":author", message.m_author); - query_select.exec(); - - QList datetime_stamps; - - while (query_select.next()) { - datetime_stamps << query_select.value(2).value(); - } - - query_select.finish(); - - if (datetime_stamps.size() == 0 || - (message.m_createdFromFeed && - !datetime_stamps.contains(message.m_created.toMSecsSinceEpoch()))) { - // Message is not fetched in this feed yet - // or it is. If it is, then go - // through datetime stamps of stored messages - // and check if new (not auto-generated timestamp - // is among them and add this message if it is not. - query_insert.bindValue(":feed", feed_id); - query_insert.bindValue(":title", message.m_title); - query_insert.bindValue(":url", message.m_url); - query_insert.bindValue(":author", message.m_author); - query_insert.bindValue(":date_created", message.m_created.toMSecsSinceEpoch()); - query_insert.bindValue(":contents", message.m_contents); - - query_insert.exec(); - query_insert.finish(); - } - } - - if (!database.commit()) { - database.rollback(); - - qDebug("Transaction commit for message downloader failed."); - } -} diff --git a/src/core/feedsmodelstandardfeed.h b/src/core/feedsmodelstandardfeed.h deleted file mode 100644 index 6f77a9b83..000000000 --- a/src/core/feedsmodelstandardfeed.h +++ /dev/null @@ -1,130 +0,0 @@ -// This file is part of RSS Guard. -// -// Copyright (C) 2011-2014 by Martin Rotter -// -// RSS Guard is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// RSS Guard is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with RSS Guard. If not, see . - -#ifndef FEEDSMODELSTANDARDFEED_H -#define FEEDSMODELSTANDARDFEED_H - -#include "core/feedsmodelfeed.h" - -#include -#include -#include -#include -#include - - -class Message; - -// Represents STANDARD RSS/RDF/ATOM feed with no -// online synchronization services (NO TT-RSS, NO FEEDLY). -// So, parent item is either root item or category. -class FeedsModelStandardFeed : public FeedsModelFeed { - Q_DECLARE_TR_FUNCTIONS(FeedsModelStandardFeed) - - public: - enum AutoUpdateType { - DontAutoUpdate = 0, - DefaultAutoUpdate = 1, - SpecificAutoUpdate = 2 - }; - - // Constructors and destructors. - explicit FeedsModelStandardFeed(FeedsModelRootItem *parent_item = NULL); - virtual ~FeedsModelStandardFeed(); - - // Obtains data related to this feed. - QVariant data(int column, int role) const; - - // Perform fetching of new messages. - void update(); - - // Removes this standard feed from persistent - // storage. - bool removeItself(); - - // Various getters/setters. - inline QString encoding() const { - return m_encoding; - } - - inline void setEncoding(const QString &encoding) { - m_encoding = encoding; - } - - inline QString url() const { - return m_url; - } - - inline void setUrl(const QString &url) { - m_url = url; - } - - inline int autoUpdateInitialInterval() const { - return m_autoUpdateInitialInterval; - } - - inline void setAutoUpdateInitialInterval(int auto_update_interval) { - // If new initial auto-update interval is set, then - // we should reset time that remains to the next auto-update. - m_autoUpdateInitialInterval = auto_update_interval; - m_autoUpdateRemainingInterval = auto_update_interval; - } - - inline AutoUpdateType autoUpdateType() const { - return m_autoUpdateType; - } - - inline void setAutoUpdateType(const AutoUpdateType &autoUpdateType) { - m_autoUpdateType = autoUpdateType; - } - - inline int autoUpdateRemainingInterval() const { - return m_autoUpdateRemainingInterval; - } - - inline void setAutoUpdateRemainingInterval(int autoUpdateRemainingInterval) { - m_autoUpdateRemainingInterval = autoUpdateRemainingInterval; - } - - // Loads standard feed object from given SQL record. - static FeedsModelStandardFeed *loadFromRecord(const QSqlRecord &record); - - // Tries to guess feed hidden under given URL - // and uses given credentials. - // Returns pointer to guessed feed (if at least partially - // guessed) and retrieved error/status code from network layer - // or NULL feed. - static QPair guessFeed(const QString &url, - const QString &username, - const QString &password); - - protected: - // Persistently stores given messages into the database - // and updates existing messages if newer version is - // available. - void updateMessages(const QList &messages); - - private: - AutoUpdateType m_autoUpdateType; - int m_autoUpdateInitialInterval; - int m_autoUpdateRemainingInterval; - - QString m_encoding; - QString m_url; -}; - -#endif // FEEDSMODELSTANDARDFEED_H diff --git a/src/core/networkfactory.cpp b/src/core/networkfactory.cpp index b6fd38709..bd89b6752 100644 --- a/src/core/networkfactory.cpp +++ b/src/core/networkfactory.cpp @@ -19,11 +19,12 @@ #include "core/defs.h" #include "core/silentnetworkaccessmanager.h" -#include "core/feedsmodelstandardfeed.h" #include "core/settings.h" #include #include +#include +#include #include diff --git a/src/core/networkfactory.h b/src/core/networkfactory.h index b1b93a060..c6707ca2d 100644 --- a/src/core/networkfactory.h +++ b/src/core/networkfactory.h @@ -22,8 +22,6 @@ #include -class FeedsModelStandardFeed; - class NetworkFactory { Q_DECLARE_TR_FUNCTIONS(NetworkFactory) diff --git a/src/core/silentnetworkaccessmanager.cpp b/src/core/silentnetworkaccessmanager.cpp index 5c420a150..68647e821 100644 --- a/src/core/silentnetworkaccessmanager.cpp +++ b/src/core/silentnetworkaccessmanager.cpp @@ -17,8 +17,6 @@ #include "core/silentnetworkaccessmanager.h" -#include "core/feedsmodelstandardfeed.h" - #include #include #include diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 535611af7..da7774113 100644 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -21,7 +21,7 @@ #include "core/databasefactory.h" #include "core/messagesproxymodel.h" #include "core/feeddownloader.h" -#include "core/feedsmodelstandardfeed.h" +#include "core/feedsmodelfeed.h" #include "core/systemfactory.h" #include "gui/webbrowser.h" #include "gui/formmain.h" @@ -249,10 +249,10 @@ void FeedMessageViewer::createConnections() { SIGNAL(triggered()), m_feedsView, SLOT(updateSelectedFeeds())); connect(form_main->m_ui->m_actionUpdateAllFeeds, SIGNAL(triggered()), m_feedsView, SLOT(updateAllFeeds())); - connect(form_main->m_ui->m_actionAddStandardCategory, - SIGNAL(triggered()), m_feedsView, SLOT(addNewStandardCategory())); - connect(form_main->m_ui->m_actionAddStandardFeed, - SIGNAL(triggered()), m_feedsView, SLOT(addNewStandardFeed())); + connect(form_main->m_ui->m_actionAddCategory, + SIGNAL(triggered()), m_feedsView, SLOT(addNewCategory())); + connect(form_main->m_ui->m_actionAddFeed, + SIGNAL(triggered()), m_feedsView, SLOT(addNewFeed())); connect(form_main->m_ui->m_actionEditSelectedFeedCategory, SIGNAL(triggered()), m_feedsView, SLOT(editSelectedItem())); connect(form_main->m_ui->m_actionViewSelectedItemsNewspaperMode, diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index cbc219a11..5ee916405 100644 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -24,8 +24,7 @@ #include "core/feedsproxymodel.h" #include "core/feedsmodelrootitem.h" #include "core/feedsmodelcategory.h" -#include "core/feedsmodelstandardfeed.h" -#include "core/feedsmodelstandardcategory.h" +#include "core/feedsmodelfeed.h" #include "gui/formmain.h" #include "gui/formstandardcategorydetails.h" #include "gui/formstandardfeeddetails.h" @@ -250,7 +249,7 @@ void FeedsView::clearAllFeeds() { setAllFeedsClearStatus(1); } -void FeedsView::addNewStandardCategory() { +void FeedsView::addNewCategory() { if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) { // Lock was not obtained because // it is used probably by feed updater or application @@ -281,7 +280,7 @@ void FeedsView::addNewStandardCategory() { SystemFactory::instance()->applicationCloseLock()->unlock(); } -void FeedsView::editStandardCategory(FeedsModelStandardCategory *category) { +void FeedsView::editCategory(FeedsModelCategory *category) { QPointer form_pointer = new FormStandardCategoryDetails(m_sourceModel, this); form_pointer.data()->exec(category); @@ -289,7 +288,7 @@ void FeedsView::editStandardCategory(FeedsModelStandardCategory *category) { delete form_pointer.data(); } -void FeedsView::addNewStandardFeed() { +void FeedsView::addNewFeed() { if (!SystemFactory::instance()->applicationCloseLock()->tryLock()) { // Lock was not obtained because // it is used probably by feed updater or application @@ -320,7 +319,7 @@ void FeedsView::addNewStandardFeed() { SystemFactory::instance()->applicationCloseLock()->unlock(); } -void FeedsView::editStandardFeed(FeedsModelStandardFeed *feed) { +void FeedsView::editFeed(FeedsModelFeed *feed) { QPointer form_pointer = new FormStandardFeedDetails(m_sourceModel, this); form_pointer.data()->exec(feed); @@ -359,7 +358,7 @@ void FeedsView::editSelectedItem() { switch (category->type()) { case FeedsModelCategory::Standard: { // User wants to edit standard category. - editStandardCategory(static_cast(category)); + editCategory(static_cast(category)); break; } @@ -370,12 +369,12 @@ void FeedsView::editSelectedItem() { else if ((feed = isCurrentIndexFeed()) != NULL) { // Feed is selected. switch (feed->type()) { - case FeedsModelFeed::StandardAtom10: - case FeedsModelFeed::StandardRdf: - case FeedsModelFeed::StandardRss0X: - case FeedsModelFeed::StandardRss2X: { + case FeedsModelFeed::Atom10: + case FeedsModelFeed::Rdf: + case FeedsModelFeed::Rss0X: + case FeedsModelFeed::Rss2X: { // User wants to edit standard feed. - editStandardFeed(static_cast(feed)); + editFeed(static_cast(feed)); break; } @@ -553,7 +552,8 @@ void FeedsView::initializeContextMenuEmptySpace() { m_contextMenuEmptySpace = new QMenu(tr("Context menu for feeds"), this); m_contextMenuEmptySpace->addActions(QList() << FormMain::instance()->m_ui->m_actionUpdateAllFeeds << - FormMain::instance()->m_ui->m_actionAddStandardFeed); + FormMain::instance()->m_ui->m_actionAddCategory << + FormMain::instance()->m_ui->m_actionAddFeed); } void FeedsView::setupAppearance() { diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 3eadb5a63..e29b6c313 100644 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -103,12 +103,12 @@ class FeedsView : public QTreeView { void deleteSelectedItem(); // Standard category manipulators. - void addNewStandardCategory(); - void editStandardCategory(FeedsModelStandardCategory *category); + void addNewCategory(); + void editCategory(FeedsModelCategory *category); // Standard feed manipulators. - void addNewStandardFeed(); - void editStandardFeed(FeedsModelStandardFeed *feed); + void addNewFeed(); + void editFeed(FeedsModelFeed *feed); // Reloads counts for selected feeds. void updateCountsOfSelectedFeeds(bool update_total_too = true); diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index b38205e3d..615ea8755 100755 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -115,8 +115,8 @@ QList FormMain::allActions() { m_ui->m_actionEditSelectedFeedCategory << m_ui->m_actionDeleteSelectedFeedCategory << m_ui->m_actionViewSelectedItemsNewspaperMode << - m_ui->m_actionAddStandardCategory << - m_ui->m_actionAddStandardFeed << + m_ui->m_actionAddCategory << + m_ui->m_actionAddFeed << m_ui->m_actionSelectNextFeedCategory << m_ui->m_actionSelectPreviousFeedCategory << m_ui->m_actionSelectNextMessage << @@ -291,8 +291,8 @@ void FormMain::setupIcons() { m_ui->m_actionClearAllFeeds->setIcon(icon_theme_factory->fromTheme("mail-remove")); m_ui->m_actionDeleteSelectedFeedCategory->setIcon(icon_theme_factory->fromTheme("item-remove")); m_ui->m_actionDeleteSelectedMessages->setIcon(icon_theme_factory->fromTheme("mail-remove")); - m_ui->m_actionAddStandardCategory->setIcon(icon_theme_factory->fromTheme("folder-category")); - m_ui->m_actionAddStandardFeed->setIcon(icon_theme_factory->fromTheme("folder-feed")); + m_ui->m_actionAddCategory->setIcon(icon_theme_factory->fromTheme("folder-category")); + m_ui->m_actionAddFeed->setIcon(icon_theme_factory->fromTheme("folder-feed")); m_ui->m_actionEditSelectedFeedCategory->setIcon(icon_theme_factory->fromTheme("item-edit")); m_ui->m_actionMarkAllFeedsRead->setIcon(icon_theme_factory->fromTheme("mail-mark-read")); m_ui->m_actionMarkSelectedFeedsAsRead->setIcon(icon_theme_factory->fromTheme("mail-mark-read")); @@ -309,7 +309,6 @@ void FormMain::setupIcons() { m_ui->m_actionSelectNextMessage->setIcon(icon_theme_factory->fromTheme("go-down")); m_ui->m_actionSelectPreviousMessage->setIcon(icon_theme_factory->fromTheme("go-up")); - // Setup icons for underlying components: opened web browsers... foreach (WebBrowser *browser, WebBrowser::runningWebBrowsers()) { browser->setupIcons(); diff --git a/src/gui/formmain.ui b/src/gui/formmain.ui index d0e51dcdc..388b64179 100644 --- a/src/gui/formmain.ui +++ b/src/gui/formmain.ui @@ -15,7 +15,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -39,7 +48,7 @@ 0 0 979 - 20 + 21 @@ -111,8 +120,8 @@ Add &new feed/category - - + + @@ -300,12 +309,12 @@ Deletes all messages from selected feeds. - + - New standard &feed + New &feed - Add new standard feed. + Add new feed. @@ -323,12 +332,12 @@ Open selected source articles in &internal browser - + - New standard &category + New &category - Add new standard category. + Add new category. diff --git a/src/gui/formstandardcategorydetails.cpp b/src/gui/formstandardcategorydetails.cpp index 6e5b5d227..5d0f1c06f 100644 --- a/src/gui/formstandardcategorydetails.cpp +++ b/src/gui/formstandardcategorydetails.cpp @@ -20,7 +20,6 @@ #include "core/defs.h" #include "core/feedsmodelrootitem.h" #include "core/feedsmodelcategory.h" -#include "core/feedsmodelstandardcategory.h" #include "core/feedsmodel.h" #include "gui/iconthemefactory.h" #include "gui/feedsview.h" @@ -70,7 +69,7 @@ void FormStandardCategoryDetails::createConnections() { connect(m_actionUseDefaultIcon, SIGNAL(triggered()), this, SLOT(onUseDefaultIcon())); } -void FormStandardCategoryDetails::setEditableCategory(FeedsModelStandardCategory *editable_category) { +void FormStandardCategoryDetails::setEditableCategory(FeedsModelCategory *editable_category) { m_editableCategory = editable_category; m_ui->m_cmbParentCategory->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) editable_category->parent()))); @@ -79,7 +78,7 @@ void FormStandardCategoryDetails::setEditableCategory(FeedsModelStandardCategory m_ui->m_btnIcon->setIcon(editable_category->icon()); } -int FormStandardCategoryDetails::exec(FeedsModelStandardCategory *input_category) { +int FormStandardCategoryDetails::exec(FeedsModelCategory *input_category) { // Load categories. loadCategories(m_feedsModel->allCategories().values(), m_feedsModel->rootItem(), @@ -105,7 +104,7 @@ int FormStandardCategoryDetails::exec(FeedsModelStandardCategory *input_category void FormStandardCategoryDetails::apply() { FeedsModelRootItem *parent = static_cast(m_ui->m_cmbParentCategory->itemData(m_ui->m_cmbParentCategory->currentIndex()).value()); - FeedsModelStandardCategory *new_category = new FeedsModelStandardCategory(); + FeedsModelCategory *new_category = new FeedsModelCategory(); new_category->setTitle(m_ui->m_txtTitle->lineEdit()->text()); new_category->setCreationDate(QDateTime::currentDateTime()); @@ -115,7 +114,7 @@ void FormStandardCategoryDetails::apply() { if (m_editableCategory == NULL) { // Add the category. - if (m_feedsModel->addStandardCategory(new_category, parent)) { + if (m_feedsModel->addCategory(new_category, parent)) { accept(); } else { @@ -133,7 +132,7 @@ void FormStandardCategoryDetails::apply() { } } else { - if (m_feedsModel->editStandardCategory(m_editableCategory, new_category)) { + if (m_feedsModel->editCategory(m_editableCategory, new_category)) { accept(); } else { diff --git a/src/gui/formstandardcategorydetails.h b/src/gui/formstandardcategorydetails.h index ab7c95cd4..c36868f11 100644 --- a/src/gui/formstandardcategorydetails.h +++ b/src/gui/formstandardcategorydetails.h @@ -28,7 +28,7 @@ namespace Ui { } class FeedsModelCategory; -class FeedsModelStandardCategory; +class FeedsModelCategory; class FeedsModel; class FeedsModelRootItem; class QMenu; @@ -44,7 +44,7 @@ class FormStandardCategoryDetails : public QDialog { public slots: // Executes add/edit standard category dialog. - int exec(FeedsModelStandardCategory *input_category); + int exec(FeedsModelCategory *input_category); protected slots: // Applies changes. @@ -64,7 +64,7 @@ class FormStandardCategoryDetails : public QDialog { void createConnections(); // Sets the category which will be edited. - void setEditableCategory(FeedsModelStandardCategory *editable_category); + void setEditableCategory(FeedsModelCategory *editable_category); // Initializes the dialog. void initialize(); @@ -78,7 +78,7 @@ class FormStandardCategoryDetails : public QDialog { private: Ui::FormStandardCategoryDetails *m_ui; - FeedsModelStandardCategory *m_editableCategory; + FeedsModelCategory *m_editableCategory; FeedsModel *m_feedsModel; QMenu *m_iconMenu; diff --git a/src/gui/formstandardfeeddetails.cpp b/src/gui/formstandardfeeddetails.cpp index 71fa8947f..428522772 100644 --- a/src/gui/formstandardfeeddetails.cpp +++ b/src/gui/formstandardfeeddetails.cpp @@ -23,7 +23,6 @@ #include "core/feedsmodelrootitem.h" #include "core/feedsmodelcategory.h" #include "core/feedsmodelfeed.h" -#include "core/feedsmodelstandardfeed.h" #include "core/networkfactory.h" #include "gui/iconthemefactory.h" #include "gui/baselineedit.h" @@ -57,7 +56,7 @@ FormStandardFeedDetails::~FormStandardFeedDetails() { delete m_ui; } -int FormStandardFeedDetails::exec(FeedsModelStandardFeed *input_feed) { +int FormStandardFeedDetails::exec(FeedsModelFeed *input_feed) { // Load categories. loadCategories(m_feedsModel->allCategories().values(), m_feedsModel->rootItem()); @@ -151,15 +150,15 @@ void FormStandardFeedDetails::onAuthenticationSwitched() { } void FormStandardFeedDetails::onAutoUpdateTypeChanged(int new_index) { - FeedsModelStandardFeed::AutoUpdateType auto_update_type = static_cast(m_ui->m_cmbAutoUpdateType->itemData(new_index).toInt()); + FeedsModelFeed::AutoUpdateType auto_update_type = static_cast(m_ui->m_cmbAutoUpdateType->itemData(new_index).toInt()); switch (auto_update_type) { - case FeedsModelStandardFeed::DontAutoUpdate: - case FeedsModelStandardFeed::DefaultAutoUpdate: + case FeedsModelFeed::DontAutoUpdate: + case FeedsModelFeed::DefaultAutoUpdate: m_ui->m_spinAutoUpdateInterval->setEnabled(false); break; - case FeedsModelStandardFeed::SpecificAutoUpdate: + case FeedsModelFeed::SpecificAutoUpdate: default: m_ui->m_spinAutoUpdateInterval->setEnabled(true); } @@ -203,8 +202,8 @@ void FormStandardFeedDetails::onUseDefaultIcon() { void FormStandardFeedDetails::apply() { FeedsModelRootItem *parent = static_cast(m_ui->m_cmbParentCategory->itemData(m_ui->m_cmbParentCategory->currentIndex()).value()); - FeedsModelStandardFeed::Type type = static_cast(m_ui->m_cmbType->itemData(m_ui->m_cmbType->currentIndex()).value()); - FeedsModelStandardFeed *new_feed = new FeedsModelStandardFeed(); + FeedsModelFeed::Type type = static_cast(m_ui->m_cmbType->itemData(m_ui->m_cmbType->currentIndex()).value()); + FeedsModelFeed *new_feed = new FeedsModelFeed(); // Setup data for new_feed. new_feed->setTitle(m_ui->m_txtTitle->lineEdit()->text()); @@ -217,13 +216,13 @@ void FormStandardFeedDetails::apply() { new_feed->setPasswordProtected(m_ui->m_gbAuthentication->isChecked()); new_feed->setUsername(m_ui->m_txtUsername->lineEdit()->text()); new_feed->setPassword(m_ui->m_txtPassword->lineEdit()->text()); - new_feed->setAutoUpdateType(static_cast(m_ui->m_cmbAutoUpdateType->itemData(m_ui->m_cmbAutoUpdateType->currentIndex()).toInt())); + new_feed->setAutoUpdateType(static_cast(m_ui->m_cmbAutoUpdateType->itemData(m_ui->m_cmbAutoUpdateType->currentIndex()).toInt())); new_feed->setAutoUpdateInitialInterval(m_ui->m_spinAutoUpdateInterval->value()); new_feed->setParent(parent); if (m_editableFeed == NULL) { // Add the feed. - if (m_feedsModel->addStandardFeed(new_feed, parent)) { + if (m_feedsModel->addFeed(new_feed, parent)) { accept(); } else { @@ -242,7 +241,7 @@ void FormStandardFeedDetails::apply() { } else { // Edit the feed. - if (m_feedsModel->editStandardFeed(m_editableFeed, new_feed)) { + if (m_feedsModel->editFeed(m_editableFeed, new_feed)) { accept(); } else { @@ -262,9 +261,9 @@ void FormStandardFeedDetails::apply() { } void FormStandardFeedDetails::guessFeed() { - QPair result = FeedsModelStandardFeed::guessFeed(m_ui->m_txtUrl->lineEdit()->text(), - m_ui->m_txtUsername->lineEdit()->text(), - m_ui->m_txtPassword->lineEdit()->text()); + QPair result = FeedsModelFeed::guessFeed(m_ui->m_txtUrl->lineEdit()->text(), + m_ui->m_txtUsername->lineEdit()->text(), + m_ui->m_txtPassword->lineEdit()->text()); if (result.first != NULL) { // Icon or whole feed was guessed. @@ -332,7 +331,7 @@ void FormStandardFeedDetails::createConnections() { connect(m_actionUseDefaultIcon, SIGNAL(triggered()), this, SLOT(onUseDefaultIcon())); } -void FormStandardFeedDetails::setEditableFeed(FeedsModelStandardFeed *editable_feed) { +void FormStandardFeedDetails::setEditableFeed(FeedsModelFeed *editable_feed) { m_editableFeed = editable_feed; m_ui->m_cmbParentCategory->setCurrentIndex(m_ui->m_cmbParentCategory->findData(QVariant::fromValue((void*) editable_feed->parent()))); @@ -381,10 +380,10 @@ void FormStandardFeedDetails::initialize() { #endif // Add standard feed types. - m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardAtom10), QVariant::fromValue((int) FeedsModelFeed::StandardAtom10)); - m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRdf), QVariant::fromValue((int) FeedsModelFeed::StandardRdf)); - m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRss0X), QVariant::fromValue((int) FeedsModelFeed::StandardRss0X)); - m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::StandardRss2X), QVariant::fromValue((int) FeedsModelFeed::StandardRss2X)); + m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::Atom10), QVariant::fromValue((int) FeedsModelFeed::Atom10)); + m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::Rdf), QVariant::fromValue((int) FeedsModelFeed::Rdf)); + m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::Rss0X), QVariant::fromValue((int) FeedsModelFeed::Rss0X)); + m_ui->m_cmbType->addItem(FeedsModelFeed::typeToString(FeedsModelFeed::Rss2X), QVariant::fromValue((int) FeedsModelFeed::Rss2X)); // Load available encodings. QList encodings = QTextCodec::availableCodecs(); @@ -421,9 +420,9 @@ void FormStandardFeedDetails::initialize() { // Setup auto-update options. m_ui->m_spinAutoUpdateInterval->setValue(DEFAULT_AUTO_UPDATE_INTERVAL); - m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update using global interval"), QVariant::fromValue((int) FeedsModelStandardFeed::DefaultAutoUpdate)); - m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update every"), QVariant::fromValue((int) FeedsModelStandardFeed::SpecificAutoUpdate)); - m_ui->m_cmbAutoUpdateType->addItem(tr("Do not auto-update at all"), QVariant::fromValue((int) FeedsModelStandardFeed::DontAutoUpdate)); + m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update using global interval"), QVariant::fromValue((int) FeedsModelFeed::DefaultAutoUpdate)); + m_ui->m_cmbAutoUpdateType->addItem(tr("Auto-update every"), QVariant::fromValue((int) FeedsModelFeed::SpecificAutoUpdate)); + m_ui->m_cmbAutoUpdateType->addItem(tr("Do not auto-update at all"), QVariant::fromValue((int) FeedsModelFeed::DontAutoUpdate)); // Set tab order. setTabOrder(m_ui->m_cmbParentCategory, m_ui->m_cmbType); diff --git a/src/gui/formstandardfeeddetails.h b/src/gui/formstandardfeeddetails.h index 791581782..5774168ef 100644 --- a/src/gui/formstandardfeeddetails.h +++ b/src/gui/formstandardfeeddetails.h @@ -28,7 +28,7 @@ namespace Ui { } class FeedsModel; -class FeedsModelStandardFeed; +class FeedsModelFeed; class FeedsModelCategory; class FeedsModelRootItem; @@ -42,7 +42,7 @@ class FormStandardFeedDetails : public QDialog { public slots: // Executes add/edit standard feed dialog. - int exec(FeedsModelStandardFeed *input_feed); + int exec(FeedsModelFeed *input_feed); protected slots: // Applies changes. @@ -71,7 +71,7 @@ class FormStandardFeedDetails : public QDialog { void createConnections(); // Sets the feed which will be edited. - void setEditableFeed(FeedsModelStandardFeed *editable_feed); + void setEditableFeed(FeedsModelFeed *editable_feed); // Initializes the dialog. void initialize(); @@ -82,7 +82,7 @@ class FormStandardFeedDetails : public QDialog { private: Ui::FormStandardFeedDetails *m_ui; - FeedsModelStandardFeed *m_editableFeed; + FeedsModelFeed *m_editableFeed; FeedsModel *m_feedsModel; QMenu *m_iconMenu; From 36a1f43c47cc8890eb3fae4cd5abfb547c6f4f8f Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 26 Mar 2014 12:23:27 +0100 Subject: [PATCH 5/6] Refactorings... --- CMakeLists.txt | 29 +++++++++++-------- src/core/feedsmodelfeed.cpp | 2 +- src/core/parsingfactory.cpp | 2 +- src/core/systemfactory.cpp | 2 +- src/gui/formmain.cpp | 2 +- src/gui/formsettings.cpp | 6 ++-- src/gui/formstandardfeeddetails.cpp | 2 +- src/gui/formupdate.cpp | 4 +-- src/gui/messagesview.cpp | 4 +-- src/gui/webbrowser.cpp | 4 +-- src/gui/webview.cpp | 2 +- .../basenetworkaccessmanager.cpp | 2 +- .../basenetworkaccessmanager.h | 0 src/{core => network-web}/networkfactory.cpp | 4 +-- src/{core => network-web}/networkfactory.h | 0 .../silentnetworkaccessmanager.cpp | 2 +- .../silentnetworkaccessmanager.h | 2 +- .../webbrowsernetworkaccessmanager.cpp | 2 +- .../webbrowsernetworkaccessmanager.h | 2 +- src/{core => network-web}/webfactory.cpp | 2 +- src/{core => network-web}/webfactory.h | 0 src/{core => network-web}/webpage.cpp | 4 +-- src/{core => network-web}/webpage.h | 0 23 files changed, 42 insertions(+), 37 deletions(-) rename src/{core => network-web}/basenetworkaccessmanager.cpp (96%) rename src/{core => network-web}/basenetworkaccessmanager.h (100%) rename src/{core => network-web}/networkfactory.cpp (98%) rename src/{core => network-web}/networkfactory.h (100%) rename src/{core => network-web}/silentnetworkaccessmanager.cpp (97%) rename src/{core => network-web}/silentnetworkaccessmanager.h (96%) rename src/{core => network-web}/webbrowsernetworkaccessmanager.cpp (94%) rename src/{core => network-web}/webbrowsernetworkaccessmanager.h (94%) rename src/{core => network-web}/webfactory.cpp (95%) rename src/{core => network-web}/webfactory.h (100%) rename src/{core => network-web}/webpage.cpp (94%) rename src/{core => network-web}/webpage.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 182ed27ba..5bf125206 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -307,10 +307,6 @@ set(APP_SOURCES src/core/systemfactory.cpp src/core/localization.cpp src/core/dynamicshortcuts.cpp - src/core/basenetworkaccessmanager.cpp - src/core/webpage.cpp - src/core/webbrowsernetworkaccessmanager.cpp - src/core/silentnetworkaccessmanager.cpp src/core/textfactory.cpp src/core/databasefactory.cpp src/core/messagesmodel.cpp @@ -322,10 +318,16 @@ set(APP_SOURCES src/core/feedsmodelfeed.cpp src/core/parsingfactory.cpp src/core/feeddownloader.cpp - src/core/networkfactory.cpp - src/core/webfactory.cpp - # Basic application sources. + # NETWORK-WEB sources. + src/network-web/basenetworkaccessmanager.cpp + src/network-web/webpage.cpp + src/network-web/webbrowsernetworkaccessmanager.cpp + src/network-web/silentnetworkaccessmanager.cpp + src/network-web/networkfactory.cpp + src/network-web/webfactory.cpp + + # MAIN sources. src/main.cpp ) @@ -371,10 +373,7 @@ set(APP_HEADERS # CORE headers. src/core/settings.h src/core/localization.h - src/core/basenetworkaccessmanager.h - src/core/webbrowsernetworkaccessmanager.h - src/core/silentnetworkaccessmanager.h - src/core/webpage.h + src/network-web/webpage.h src/core/systemfactory.h src/core/databasefactory.h src/core/messagesmodel.h @@ -382,7 +381,12 @@ set(APP_HEADERS src/core/feedsmodel.h src/core/feedsproxymodel.h src/core/feeddownloader.h - src/core/webfactory.h + + # NETWORK-WEB headers. + src/network-web/basenetworkaccessmanager.h + src/network-web/webbrowsernetworkaccessmanager.h + src/network-web/silentnetworkaccessmanager.h + src/network-web/webfactory.h ) # Add form files. @@ -452,6 +456,7 @@ endif(${USE_QT_5}) include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/gui + ${CMAKE_CURRENT_SOURCE_DIR}/src/network-web ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src ) diff --git a/src/core/feedsmodelfeed.cpp b/src/core/feedsmodelfeed.cpp index eac81a210..f069db200 100755 --- a/src/core/feedsmodelfeed.cpp +++ b/src/core/feedsmodelfeed.cpp @@ -21,8 +21,8 @@ #include "core/settings.h" #include "core/parsingfactory.h" #include "core/databasefactory.h" -#include "core/networkfactory.h" #include "core/textfactory.h" +#include "network-web/networkfactory.h" #include "gui/iconfactory.h" #include "gui/iconthemefactory.h" diff --git a/src/core/parsingfactory.cpp b/src/core/parsingfactory.cpp index 4c5a00172..e1d3df51d 100755 --- a/src/core/parsingfactory.cpp +++ b/src/core/parsingfactory.cpp @@ -17,8 +17,8 @@ #include "core/parsingfactory.h" -#include "core/webfactory.h" #include "core/textfactory.h" +#include "network-web/webfactory.h" #include #include diff --git a/src/core/systemfactory.cpp b/src/core/systemfactory.cpp index 0e2746d6c..b8577730f 100644 --- a/src/core/systemfactory.cpp +++ b/src/core/systemfactory.cpp @@ -18,7 +18,7 @@ #include "core/systemfactory.h" #include "core/defs.h" -#include "core/networkfactory.h" +#include "network-web/networkfactory.h" #if defined(Q_OS_WIN) #include "qtsingleapplication/qtsingleapplication.h" diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index 615ea8755..1123a19e6 100755 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -21,7 +21,7 @@ #include "core/settings.h" #include "core/systemfactory.h" #include "core/databasefactory.h" -#include "core/webfactory.h" +#include "network-web/webfactory.h" #include "gui/formabout.h" #include "gui/formsettings.h" #include "gui/feedsview.h" diff --git a/src/gui/formsettings.cpp b/src/gui/formsettings.cpp index 97fbdcbd8..c7a8bd0fc 100755 --- a/src/gui/formsettings.cpp +++ b/src/gui/formsettings.cpp @@ -22,11 +22,11 @@ #include "core/databasefactory.h" #include "core/localization.h" #include "core/systemfactory.h" -#include "core/webfactory.h" #include "core/feeddownloader.h" #include "core/dynamicshortcuts.h" -#include "core/webbrowsernetworkaccessmanager.h" -#include "core/silentnetworkaccessmanager.h" +#include "network-web/webfactory.h" +#include "network-web/webbrowsernetworkaccessmanager.h" +#include "network-web/silentnetworkaccessmanager.h" #include "core/feedsmodel.h" #include "gui/iconthemefactory.h" #include "gui/skinfactory.h" diff --git a/src/gui/formstandardfeeddetails.cpp b/src/gui/formstandardfeeddetails.cpp index 428522772..dcfe6618d 100644 --- a/src/gui/formstandardfeeddetails.cpp +++ b/src/gui/formstandardfeeddetails.cpp @@ -23,7 +23,7 @@ #include "core/feedsmodelrootitem.h" #include "core/feedsmodelcategory.h" #include "core/feedsmodelfeed.h" -#include "core/networkfactory.h" +#include "network-web/networkfactory.h" #include "gui/iconthemefactory.h" #include "gui/baselineedit.h" #include "gui/messagebox.h" diff --git a/src/gui/formupdate.cpp b/src/gui/formupdate.cpp index 65f6184d7..91453226e 100755 --- a/src/gui/formupdate.cpp +++ b/src/gui/formupdate.cpp @@ -19,8 +19,8 @@ #include "core/defs.h" #include "core/systemfactory.h" -#include "core/networkfactory.h" -#include "core/webfactory.h" +#include "network-web/networkfactory.h" +#include "network-web/webfactory.h" #include "gui/iconthemefactory.h" #include "gui/messagebox.h" #include "gui/systemtrayicon.h" diff --git a/src/gui/messagesview.cpp b/src/gui/messagesview.cpp index 01bddfa9c..573bff128 100644 --- a/src/gui/messagesview.cpp +++ b/src/gui/messagesview.cpp @@ -20,8 +20,8 @@ #include "core/messagesproxymodel.h" #include "core/messagesmodel.h" #include "core/settings.h" -#include "core/networkfactory.h" -#include "core/webfactory.h" +#include "network-web/networkfactory.h" +#include "network-web/webfactory.h" #include "gui/formmain.h" #include "gui/messagebox.h" diff --git a/src/gui/webbrowser.cpp b/src/gui/webbrowser.cpp index 822c32a8a..200c22f71 100644 --- a/src/gui/webbrowser.cpp +++ b/src/gui/webbrowser.cpp @@ -18,8 +18,8 @@ #include "gui/webbrowser.h" #include "core/defs.h" -#include "core/webbrowsernetworkaccessmanager.h" -#include "core/webpage.h" +#include "network-web/webbrowsernetworkaccessmanager.h" +#include "network-web/webpage.h" #include "gui/skinfactory.h" #include "gui/webview.h" #include "gui/formmain.h" diff --git a/src/gui/webview.cpp b/src/gui/webview.cpp index 956d6aefb..1490bcdf3 100644 --- a/src/gui/webview.cpp +++ b/src/gui/webview.cpp @@ -19,7 +19,7 @@ #include "core/defs.h" #include "core/settings.h" -#include "core/webpage.h" +#include "network-web/webpage.h" #include "gui/skinfactory.h" #include "gui/iconthemefactory.h" diff --git a/src/core/basenetworkaccessmanager.cpp b/src/network-web/basenetworkaccessmanager.cpp similarity index 96% rename from src/core/basenetworkaccessmanager.cpp rename to src/network-web/basenetworkaccessmanager.cpp index 8c96f7e70..196175a42 100644 --- a/src/core/basenetworkaccessmanager.cpp +++ b/src/network-web/basenetworkaccessmanager.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "core/basenetworkaccessmanager.h" +#include "network-web/basenetworkaccessmanager.h" #include "core/defs.h" #include "core/settings.h" diff --git a/src/core/basenetworkaccessmanager.h b/src/network-web/basenetworkaccessmanager.h similarity index 100% rename from src/core/basenetworkaccessmanager.h rename to src/network-web/basenetworkaccessmanager.h diff --git a/src/core/networkfactory.cpp b/src/network-web/networkfactory.cpp similarity index 98% rename from src/core/networkfactory.cpp rename to src/network-web/networkfactory.cpp index bd89b6752..2737b3ce2 100644 --- a/src/core/networkfactory.cpp +++ b/src/network-web/networkfactory.cpp @@ -15,11 +15,11 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "core/networkfactory.h" +#include "network-web/networkfactory.h" #include "core/defs.h" -#include "core/silentnetworkaccessmanager.h" #include "core/settings.h" +#include "network-web/silentnetworkaccessmanager.h" #include #include diff --git a/src/core/networkfactory.h b/src/network-web/networkfactory.h similarity index 100% rename from src/core/networkfactory.h rename to src/network-web/networkfactory.h diff --git a/src/core/silentnetworkaccessmanager.cpp b/src/network-web/silentnetworkaccessmanager.cpp similarity index 97% rename from src/core/silentnetworkaccessmanager.cpp rename to src/network-web/silentnetworkaccessmanager.cpp index 68647e821..05ea2bd4f 100644 --- a/src/core/silentnetworkaccessmanager.cpp +++ b/src/network-web/silentnetworkaccessmanager.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "core/silentnetworkaccessmanager.h" +#include "network-web/silentnetworkaccessmanager.h" #include #include diff --git a/src/core/silentnetworkaccessmanager.h b/src/network-web/silentnetworkaccessmanager.h similarity index 96% rename from src/core/silentnetworkaccessmanager.h rename to src/network-web/silentnetworkaccessmanager.h index d3eade0dc..701b59e7a 100644 --- a/src/core/silentnetworkaccessmanager.h +++ b/src/network-web/silentnetworkaccessmanager.h @@ -18,7 +18,7 @@ #ifndef SILENTNETWORKACCESSMANAGER_H #define SILENTNETWORKACCESSMANAGER_H -#include "core/basenetworkaccessmanager.h" +#include "network-web/basenetworkaccessmanager.h" #include diff --git a/src/core/webbrowsernetworkaccessmanager.cpp b/src/network-web/webbrowsernetworkaccessmanager.cpp similarity index 94% rename from src/core/webbrowsernetworkaccessmanager.cpp rename to src/network-web/webbrowsernetworkaccessmanager.cpp index f195975bd..4b2db15ed 100644 --- a/src/core/webbrowsernetworkaccessmanager.cpp +++ b/src/network-web/webbrowsernetworkaccessmanager.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "core/webbrowsernetworkaccessmanager.h" +#include "network-web/webbrowsernetworkaccessmanager.h" #include #include diff --git a/src/core/webbrowsernetworkaccessmanager.h b/src/network-web/webbrowsernetworkaccessmanager.h similarity index 94% rename from src/core/webbrowsernetworkaccessmanager.h rename to src/network-web/webbrowsernetworkaccessmanager.h index a05c4651b..27aa9cb73 100644 --- a/src/core/webbrowsernetworkaccessmanager.h +++ b/src/network-web/webbrowsernetworkaccessmanager.h @@ -18,7 +18,7 @@ #ifndef WEBBROWSERNETWORKACCESSMANAGER_H #define WEBBROWSERNETWORKACCESSMANAGER_H -#include "core/basenetworkaccessmanager.h" +#include "network-web/basenetworkaccessmanager.h" #include diff --git a/src/core/webfactory.cpp b/src/network-web/webfactory.cpp similarity index 95% rename from src/core/webfactory.cpp rename to src/network-web/webfactory.cpp index d2dbe6057..72f796d64 100644 --- a/src/core/webfactory.cpp +++ b/src/network-web/webfactory.cpp @@ -1,4 +1,4 @@ -#include "core/webfactory.h" +#include "network-web/webfactory.h" #include "core/defs.h" #include "core/settings.h" diff --git a/src/core/webfactory.h b/src/network-web/webfactory.h similarity index 100% rename from src/core/webfactory.h rename to src/network-web/webfactory.h diff --git a/src/core/webpage.cpp b/src/network-web/webpage.cpp similarity index 94% rename from src/core/webpage.cpp rename to src/network-web/webpage.cpp index 77a30bdf0..04255df63 100644 --- a/src/core/webpage.cpp +++ b/src/network-web/webpage.cpp @@ -15,9 +15,9 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "core/webpage.h" +#include "network-web/webpage.h" -#include "core/webbrowsernetworkaccessmanager.h" +#include "network-web/webbrowsernetworkaccessmanager.h" #include "gui/webbrowser.h" #include diff --git a/src/core/webpage.h b/src/network-web/webpage.h similarity index 100% rename from src/core/webpage.h rename to src/network-web/webpage.h From 8cf920771581c1b24558b0a6de50e7625539be4e Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 26 Mar 2014 13:30:18 +0100 Subject: [PATCH 6/6] Refactorings.... --- CMakeLists.txt | 8 ++++---- src/gui/feedmessageviewer.cpp | 2 +- src/gui/formmain.cpp | 2 +- src/gui/formsettings.cpp | 2 +- src/gui/tabwidget.cpp | 2 +- src/{gui => network-web}/webbrowser.cpp | 4 ++-- src/{gui => network-web}/webbrowser.h | 2 +- src/network-web/webpage.cpp | 2 +- src/{gui => network-web}/webview.cpp | 2 +- src/{gui => network-web}/webview.h | 0 10 files changed, 13 insertions(+), 13 deletions(-) rename src/{gui => network-web}/webbrowser.cpp (96%) rename src/{gui => network-web}/webbrowser.h (95%) rename src/{gui => network-web}/webview.cpp (99%) rename src/{gui => network-web}/webview.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bf125206..0cfb7f9ab 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,8 +279,6 @@ set(APP_SOURCES src/gui/shortcutcatcher.cpp src/gui/shortcutbutton.cpp src/gui/dynamicshortcutswidget.cpp - src/gui/webbrowser.cpp - src/gui/webview.cpp src/gui/baselineedit.cpp src/gui/locationlineedit.cpp src/gui/tabwidget.cpp @@ -326,6 +324,8 @@ set(APP_SOURCES src/network-web/silentnetworkaccessmanager.cpp src/network-web/networkfactory.cpp src/network-web/webfactory.cpp + src/network-web/webbrowser.cpp + src/network-web/webview.cpp # MAIN sources. src/main.cpp @@ -349,8 +349,6 @@ set(APP_HEADERS src/gui/shortcutcatcher.h src/gui/shortcutbutton.h src/gui/dynamicshortcutswidget.h - src/gui/webbrowser.h - src/gui/webview.h src/gui/baselineedit.h src/gui/locationlineedit.h src/gui/tabwidget.h @@ -387,6 +385,8 @@ set(APP_HEADERS src/network-web/webbrowsernetworkaccessmanager.h src/network-web/silentnetworkaccessmanager.h src/network-web/webfactory.h + src/network-web/webbrowser.h + src/network-web/webview.h ) # Add form files. diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index da7774113..c499b5924 100644 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -23,7 +23,7 @@ #include "core/feeddownloader.h" #include "core/feedsmodelfeed.h" #include "core/systemfactory.h" -#include "gui/webbrowser.h" +#include "network-web/webbrowser.h" #include "gui/formmain.h" #include "gui/iconthemefactory.h" #include "gui/messagesview.h" diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index 1123a19e6..479718de1 100755 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -22,11 +22,11 @@ #include "core/systemfactory.h" #include "core/databasefactory.h" #include "network-web/webfactory.h" +#include "network-web/webbrowser.h" #include "gui/formabout.h" #include "gui/formsettings.h" #include "gui/feedsview.h" #include "gui/messagebox.h" -#include "gui/webbrowser.h" #include "gui/iconthemefactory.h" #include "gui/systemtrayicon.h" #include "gui/tabbar.h" diff --git a/src/gui/formsettings.cpp b/src/gui/formsettings.cpp index c7a8bd0fc..c39ea1196 100755 --- a/src/gui/formsettings.cpp +++ b/src/gui/formsettings.cpp @@ -27,6 +27,7 @@ #include "network-web/webfactory.h" #include "network-web/webbrowsernetworkaccessmanager.h" #include "network-web/silentnetworkaccessmanager.h" +#include "network-web/webbrowser.h" #include "core/feedsmodel.h" #include "gui/iconthemefactory.h" #include "gui/skinfactory.h" @@ -34,7 +35,6 @@ #include "gui/feedmessageviewer.h" #include "gui/feedsview.h" #include "gui/formmain.h" -#include "gui/webbrowser.h" #include "gui/messagebox.h" #include "qtsingleapplication/qtsingleapplication.h" diff --git a/src/gui/tabwidget.cpp b/src/gui/tabwidget.cpp index d18a64da0..1402e8232 100644 --- a/src/gui/tabwidget.cpp +++ b/src/gui/tabwidget.cpp @@ -20,9 +20,9 @@ #include "core/defs.h" #include "core/settings.h" #include "core/textfactory.h" +#include "network-web/webbrowser.h" #include "gui/tabbar.h" #include "gui/iconthemefactory.h" -#include "gui/webbrowser.h" #include "gui/formmain.h" #include "gui/feedmessageviewer.h" #include "gui/plaintoolbutton.h" diff --git a/src/gui/webbrowser.cpp b/src/network-web/webbrowser.cpp similarity index 96% rename from src/gui/webbrowser.cpp rename to src/network-web/webbrowser.cpp index 200c22f71..cf2e0b110 100644 --- a/src/gui/webbrowser.cpp +++ b/src/network-web/webbrowser.cpp @@ -15,13 +15,13 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "gui/webbrowser.h" +#include "network-web/webbrowser.h" #include "core/defs.h" #include "network-web/webbrowsernetworkaccessmanager.h" #include "network-web/webpage.h" +#include "network-web/webview.h" #include "gui/skinfactory.h" -#include "gui/webview.h" #include "gui/formmain.h" #include "gui/iconthemefactory.h" #include "gui/tabwidget.h" diff --git a/src/gui/webbrowser.h b/src/network-web/webbrowser.h similarity index 95% rename from src/gui/webbrowser.h rename to src/network-web/webbrowser.h index 28a8d3399..759c39930 100644 --- a/src/gui/webbrowser.h +++ b/src/network-web/webbrowser.h @@ -19,8 +19,8 @@ #define WEBBROWSER_H #include "core/messagesmodel.h" +#include "network-web/webview.h" #include "gui/tabcontent.h" -#include "gui/webview.h" #include "gui/locationlineedit.h" #include diff --git a/src/network-web/webpage.cpp b/src/network-web/webpage.cpp index 04255df63..9ecfa29ac 100644 --- a/src/network-web/webpage.cpp +++ b/src/network-web/webpage.cpp @@ -18,7 +18,7 @@ #include "network-web/webpage.h" #include "network-web/webbrowsernetworkaccessmanager.h" -#include "gui/webbrowser.h" +#include "network-web/webbrowser.h" #include #include diff --git a/src/gui/webview.cpp b/src/network-web/webview.cpp similarity index 99% rename from src/gui/webview.cpp rename to src/network-web/webview.cpp index 1490bcdf3..aaf138553 100644 --- a/src/gui/webview.cpp +++ b/src/network-web/webview.cpp @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License // along with RSS Guard. If not, see . -#include "gui/webview.h" +#include "network-web/webview.h" #include "core/defs.h" #include "core/settings.h" diff --git a/src/gui/webview.h b/src/network-web/webview.h similarity index 100% rename from src/gui/webview.h rename to src/network-web/webview.h