diff --git a/CMakeLists.txt b/CMakeLists.txt index fe4915afa..a41b733be 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -417,6 +417,7 @@ set(APP_SOURCES # ABSTRACT service sources. src/services/abstract/serviceentrypoint.cpp + src/services/abstract/feed.cpp src/services/abstract/serviceroot.cpp # STANDARD feed service sources. diff --git a/src/core/feeddownloader.cpp b/src/core/feeddownloader.cpp index 8afef756c..505c947e6 100755 --- a/src/core/feeddownloader.cpp +++ b/src/core/feeddownloader.cpp @@ -17,7 +17,7 @@ #include "core/feeddownloader.h" -#include "services/standard/standardfeed.h" +#include "services/abstract/feed.h" #include "definitions/definitions.h" #include @@ -32,7 +32,7 @@ FeedDownloader::~FeedDownloader() { qDebug("Destroying FeedDownloader instance."); } -void FeedDownloader::updateFeeds(const QList &feeds) { +void FeedDownloader::updateFeeds(const QList &feeds) { qDebug().nospace() << "Performing feed updates in thread: \'" << QThread::currentThreadId() << "\'."; // Job starts now. diff --git a/src/core/feeddownloader.h b/src/core/feeddownloader.h index eab2aac2e..88f8992b7 100755 --- a/src/core/feeddownloader.h +++ b/src/core/feeddownloader.h @@ -23,7 +23,7 @@ #include -class StandardFeed; +class Feed; // Represents results of batch feed updates. struct FeedDownloadResults { @@ -55,7 +55,7 @@ class FeedDownloader : public QObject { // New messages are downloaded for each feed and they // are stored persistently in the database. // Appropriate signals are emitted. - void updateFeeds(const QList &feeds); + void updateFeeds(const QList &feeds); signals: // Emitted if feed updates started. @@ -69,7 +69,7 @@ class FeedDownloader : public QObject { // "Current" number indicates count of processed feeds // and "total" number indicates total number of feeds // which were in the initial queue. - void progress(StandardFeed *feed, int current, int total); + void progress(Feed *feed, int current, int total); }; #endif // FEEDDOWNLOADER_H diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index 7dad793e8..ac4905a2b 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -18,8 +18,9 @@ #include "core/feedsmodel.h" #include "definitions/definitions.h" -#include "services/standard/standardcategory.h" +#include "services/abstract/feed.h" #include "services/standard/standardfeed.h" +#include "services/standard/standardcategory.h" #include "services/standard/standardfeedsimportexportmodel.h" #include "core/recyclebin.h" #include "miscellaneous/textfactory.h" @@ -100,7 +101,7 @@ void FeedsModel::executeNextAutoUpdate() { // Pass needed interval data and lets the model decide which feeds // should be updated in this pass. - QList feeds_for_update = feedsForScheduledUpdate(m_globalAutoUpdateEnabled && m_globalAutoUpdateRemainingInterval == 0); + QList feeds_for_update = feedsForScheduledUpdate(m_globalAutoUpdateEnabled && m_globalAutoUpdateRemainingInterval == 0); qApp->feedUpdateLock()->unlock(); @@ -432,10 +433,10 @@ bool FeedsModel::editFeed(StandardFeed *original_feed, StandardFeed *new_feed_da return result; } -QList FeedsModel::feedsForScheduledUpdate(bool auto_update_now) { - QList feeds_for_update; +QList FeedsModel::feedsForScheduledUpdate(bool auto_update_now) { + QList feeds_for_update; - foreach (StandardFeed *feed, allFeeds()) { + foreach (Feed *feed, allFeeds()) { switch (feed->autoUpdateType()) { case StandardFeed::DontAutoUpdate: // Do not auto-update this feed ever. @@ -471,7 +472,7 @@ QList FeedsModel::feedsForScheduledUpdate(bool auto_update_now) { return feeds_for_update; } -QList FeedsModel::messagesForFeeds(const QList &feeds) { +QList FeedsModel::messagesForFeeds(const QList &feeds) { QList messages; QSqlDatabase database = qApp->database()->connection(objectName(), @@ -482,7 +483,7 @@ QList FeedsModel::messagesForFeeds(const QList &feeds) { "FROM Messages " "WHERE is_deleted = 0 AND feed = :feed;"); - foreach (StandardFeed *feed, feeds) { + foreach (Feed *feed, feeds) { query_read_msg.bindValue(QSL(":feed"), feed->id()); if (query_read_msg.exec()) { @@ -567,7 +568,7 @@ QModelIndex FeedsModel::indexForItem(RootItem *item) const { } bool FeedsModel::hasAnyFeedNewMessages() { - foreach (const StandardFeed *feed, allFeeds()) { + foreach (const Feed *feed, allFeeds()) { if (feed->status() == StandardFeed::NewMessages) { return true; } @@ -664,11 +665,11 @@ void FeedsModel::reloadChangedLayout(QModelIndexList list) { } } -QStringList FeedsModel::textualFeedIds(const QList &feeds) { +QStringList FeedsModel::textualFeedIds(const QList &feeds) { QStringList stringy_ids; stringy_ids.reserve(feeds.size()); - foreach (StandardFeed *feed, feeds) { + foreach (Feed *feed, feeds) { stringy_ids.append(QString::number(feed->id())); } @@ -746,24 +747,24 @@ void FeedsModel::loadFromDatabase() { m_rootItem->appendChild(m_recycleBin); } -QList FeedsModel::feedsForIndex(const QModelIndex &index) { +QList FeedsModel::feedsForIndex(const QModelIndex &index) { RootItem *item = itemForIndex(index); return feedsForItem(item); } -StandardFeed *FeedsModel::feedForIndex(const QModelIndex &index) { +Feed *FeedsModel::feedForIndex(const QModelIndex &index) { RootItem *item = itemForIndex(index); if (item->kind() == RootItem::Feeed) { - return item->toFeed(); + return static_cast(item); } else { return NULL; } } -QList FeedsModel::feedsForIndexes(const QModelIndexList &indexes) { - QList feeds; +QList FeedsModel::feedsForIndexes(const QModelIndexList &indexes) { + QList feeds; // Get selected feeds for each index. foreach (const QModelIndex &index, indexes) { @@ -782,7 +783,7 @@ QList FeedsModel::feedsForIndexes(const QModelIndexList &indexes) return feeds; } -bool FeedsModel::markFeedsRead(const QList &feeds, int read) { +bool FeedsModel::markFeedsRead(const QList &feeds, int read) { QSqlDatabase db_handle = qApp->database()->connection(objectName(), DatabaseFactory::FromSettings); if (!db_handle.transaction()) { @@ -817,7 +818,7 @@ bool FeedsModel::markFeedsRead(const QList &feeds, int read) { } } -bool FeedsModel::markFeedsDeleted(const QList &feeds, int deleted, bool read_only) { +bool FeedsModel::markFeedsDeleted(const QList &feeds, int deleted, bool read_only) { QSqlDatabase db_handle = qApp->database()->connection(objectName(), DatabaseFactory::FromSettings); if (!db_handle.transaction()) { @@ -893,13 +894,13 @@ QHash FeedsModel::categoriesForItem(RootItem *root) { return categories; } -QList FeedsModel::allFeeds() { +QList FeedsModel::allFeeds() { return feedsForItem(m_rootItem); } -QList FeedsModel::feedsForItem(RootItem *root) { +QList FeedsModel::feedsForItem(RootItem *root) { QList children = root->getRecursiveChildren(); - QList feeds; + QList feeds; foreach (RootItem *child, children) { if (child->kind() == RootItem::Feeed) { diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index ad029b443..98ea28b7d 100755 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -27,7 +27,7 @@ class StandardCategory; -class StandardFeed; +class Feed; class RecycleBin; class FeedsImportExportModel; class QTimer; @@ -95,12 +95,12 @@ class FeedsModel : public QAbstractItemModel { // Variable "auto_update_now" is true, when global timeout // for scheduled auto-update was met and global auto-update strategy is enabled // so feeds with "default" auto-update strategy should be updated. - QList feedsForScheduledUpdate(bool auto_update_now); + QList feedsForScheduledUpdate(bool auto_update_now); // Returns (undeleted) messages for given feeds. // This is usually used for displaying whole feeds // in "newspaper" mode. - QList messagesForFeeds(const QList &feeds); + QList messagesForFeeds(const QList &feeds); // Returns all categories, each pair // consists of ID of parent item and pointer to category. @@ -111,21 +111,21 @@ class FeedsModel : public QAbstractItemModel { QHash categoriesForItem(RootItem *root); // Returns list of all feeds contained in the model. - QList allFeeds(); + QList allFeeds(); // Get list of feeds from tree with particular item // as root. If root itself is a feed, then it is returned. - QList feedsForItem(RootItem *root); + QList feedsForItem(RootItem *root); // Returns list of ALL CHILD feeds which belong to given parent indexes. - QList feedsForIndexes(const QModelIndexList &indexes); + QList feedsForIndexes(const QModelIndexList &indexes); // Returns ALL CHILD feeds contained within single index. - QList feedsForIndex(const QModelIndex &index); + QList feedsForIndex(const QModelIndex &index); // Returns pointer to feed if it lies on given index // or NULL if no feed lies on given index. - StandardFeed *feedForIndex(const QModelIndex &index); + Feed *feedForIndex(const QModelIndex &index); // Returns pointer to category if it lies on given index // or NULL if no category lies on given index. @@ -166,8 +166,8 @@ class FeedsModel : public QAbstractItemModel { public slots: // Feeds operations. - bool markFeedsRead(const QList &feeds, int read); - bool markFeedsDeleted(const QList &feeds, int deleted, bool read_only); + bool markFeedsRead(const QList &feeds, int read); + bool markFeedsDeleted(const QList &feeds, int deleted, bool read_only); // Signals that properties (probably counts) // of ALL items have changed. @@ -185,7 +185,7 @@ class FeedsModel : public QAbstractItemModel { protected: // Returns converted ids of given feeds // which are suitable as IN clause for SQL queries. - QStringList textualFeedIds(const QList &feeds); + QStringList textualFeedIds(const QList &feeds); // Loads feed/categories from the database. void loadFromDatabase(); @@ -199,7 +199,7 @@ class FeedsModel : public QAbstractItemModel { void requireItemValidationAfterDragDrop(const QModelIndex &source_index); // Emitted when model requests update of some feeds. - void feedsUpdateRequested(const QList feeds); + void feedsUpdateRequested(const QList feeds); private: RootItem *m_rootItem; diff --git a/src/core/rootitem.h b/src/core/rootitem.h index b54cd6616..96914ed7f 100755 --- a/src/core/rootitem.h +++ b/src/core/rootitem.h @@ -67,6 +67,17 @@ class RootItem { child->setParent(this); } + virtual bool canBeEdited() { + return false; + } + + virtual bool canBeDeleted() { + return false; + } + + virtual void edit() { + } + virtual int row() const; virtual QVariant data(int column, int role) const; diff --git a/src/gui/dialogs/formmain.ui b/src/gui/dialogs/formmain.ui index bca5de13f..f1179c599 100755 --- a/src/gui/dialogs/formmain.ui +++ b/src/gui/dialogs/formmain.ui @@ -691,17 +691,17 @@ - &Add new service + &Add new service account - &Delete selected service + &Delete selected service account - &Edit selected service + &Edit selected service account diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 922dd667e..0d2f93bc6 100755 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -252,7 +252,7 @@ void FeedMessageViewer::onFeedUpdatesStarted() { qApp->mainForm()->statusBar()->showProgressFeeds(0, tr("Feed update started")); } -void FeedMessageViewer::onFeedUpdatesProgress(StandardFeed *feed, int current, int total) { +void FeedMessageViewer::onFeedUpdatesProgress(Feed *feed, int current, int total) { // Some feed got updated. m_feedsView->updateCountsOfParticularFeed(feed, true); qApp->mainForm()->statusBar()->showProgressFeeds((current * 100.0) / total, @@ -369,7 +369,7 @@ void FeedMessageViewer::createConnections() { form_main->m_ui->m_tabWidget, SLOT(addBrowserWithMessages(QList))); // Downloader connections. - connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList)), this, SLOT(updateFeeds(QList))); + connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList)), this, SLOT(updateFeeds(QList))); // Toolbar forwardings. connect(form_main->m_ui->m_actionCleanupDatabase, @@ -548,7 +548,7 @@ void FeedMessageViewer::refreshVisualProperties() { m_toolBarMessages->setToolButtonStyle(button_style); } -void FeedMessageViewer::updateFeeds(QList feeds) { +void FeedMessageViewer::updateFeeds(QList feeds) { if (!qApp->feedUpdateLock()->tryLock()) { qApp->showGuiMessage(tr("Cannot update all items"), tr("You cannot update all items because another another critical operation is ongoing."), @@ -561,14 +561,14 @@ void FeedMessageViewer::updateFeeds(QList feeds) { m_feedDownloaderThread = new QThread(); // Downloader setup. - qRegisterMetaType >("QList"); + qRegisterMetaType >("QList"); m_feedDownloader->moveToThread(m_feedDownloaderThread); - connect(this, SIGNAL(feedsUpdateRequested(QList)), m_feedDownloader, SLOT(updateFeeds(QList))); + connect(this, SIGNAL(feedsUpdateRequested(QList)), m_feedDownloader, SLOT(updateFeeds(QList))); connect(m_feedDownloaderThread, SIGNAL(finished()), m_feedDownloaderThread, SLOT(deleteLater())); connect(m_feedDownloader, SIGNAL(finished(FeedDownloadResults)), this, SLOT(onFeedUpdatesFinished(FeedDownloadResults))); connect(m_feedDownloader, SIGNAL(started()), this, SLOT(onFeedUpdatesStarted())); - connect(m_feedDownloader, SIGNAL(progress(StandardFeed*,int,int)), this, SLOT(onFeedUpdatesProgress(StandardFeed*,int,int))); + connect(m_feedDownloader, SIGNAL(progress(Feed*,int,int)), this, SLOT(onFeedUpdatesProgress(Feed*,int,int))); // Connections are made, start the feed downloader thread. m_feedDownloaderThread->start(); diff --git a/src/gui/feedmessageviewer.h b/src/gui/feedmessageviewer.h index 8c087427f..22020203d 100755 --- a/src/gui/feedmessageviewer.h +++ b/src/gui/feedmessageviewer.h @@ -103,7 +103,7 @@ class FeedMessageViewer : public TabContent { // Reloads some changeable visual settings. void refreshVisualProperties(); - void updateFeeds(QList feeds); + void updateFeeds(QList feeds); private slots: // Updates counts of messages for example in tray icon. @@ -111,7 +111,7 @@ class FeedMessageViewer : public TabContent { // Reacts on feed updates. void onFeedUpdatesStarted(); - void onFeedUpdatesProgress(StandardFeed *feed, int current, int total); + void onFeedUpdatesProgress(Feed *feed, int current, int total); void onFeedUpdatesFinished(FeedDownloadResults results); // Switches visibility of feed list and related @@ -135,7 +135,7 @@ class FeedMessageViewer : public TabContent { signals: // Emitted if user/application requested updating of some feeds. - void feedsUpdateRequested(const QList feeds); + void feedsUpdateRequested(const QList feeds); private: bool m_toolBarsEnabled; diff --git a/src/gui/feedsview.cpp b/src/gui/feedsview.cpp index 0c01a9698..cba9fa970 100755 --- a/src/gui/feedsview.cpp +++ b/src/gui/feedsview.cpp @@ -22,15 +22,15 @@ #include "core/feedsproxymodel.h" #include "core/rootitem.h" #include "core/recyclebin.h" -#include "services/standard/standardcategory.h" -#include "services/standard/standardfeed.h" -#include "services/standard/standardfeed.h" #include "miscellaneous/systemfactory.h" #include "miscellaneous/mutex.h" #include "gui/systemtrayicon.h" #include "gui/messagebox.h" #include "gui/styleditemdelegatewithoutfocus.h" #include "gui/dialogs/formmain.h" +#include "services/abstract/feed.h" +#include "services/standard/standardcategory.h" +#include "services/standard/standardfeed.h" #include "services/standard/gui/formstandardcategorydetails.h" #include "services/standard/gui/formstandardfeeddetails.h" @@ -56,7 +56,7 @@ FeedsView::FeedsView(QWidget *parent) // Connections. connect(m_sourceModel, SIGNAL(requireItemValidationAfterDragDrop(QModelIndex)), this, SLOT(validateItemAfterDragDrop(QModelIndex))); - connect(m_sourceModel, SIGNAL(feedsUpdateRequested(QList)), this, SIGNAL(feedsUpdateRequested(QList))); + connect(m_sourceModel, SIGNAL(feedsUpdateRequested(QList)), this, SIGNAL(feedsUpdateRequested(QList))); connect(header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(saveSortState(int,Qt::SortOrder))); setModel(m_proxyModel); @@ -73,18 +73,18 @@ void FeedsView::setSortingEnabled(bool enable) { connect(header(), SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)), this, SLOT(saveSortState(int,Qt::SortOrder))); } -QList FeedsView::selectedFeeds() const { +QList FeedsView::selectedFeeds() const { QModelIndex current_index = currentIndex(); if (current_index.isValid()) { return m_sourceModel->feedsForIndex(m_proxyModel->mapToSource(current_index)); } else { - return QList(); + return QList(); } } -QList FeedsView::allFeeds() const { +QList FeedsView::allFeeds() const { return m_sourceModel->allFeeds(); } @@ -104,7 +104,7 @@ StandardCategory *FeedsView::selectedCategory() const { return m_sourceModel->categoryForIndex(current_mapped); } -StandardFeed *FeedsView::selectedFeed() const { +Feed *FeedsView::selectedFeed() const { QModelIndex current_mapped = m_proxyModel->mapToSource(currentIndex()); return m_sourceModel->feedForIndex(current_mapped); } @@ -214,14 +214,6 @@ void FeedsView::addNewCategory() { qApp->feedUpdateLock()->unlock(); } -void FeedsView::editCategory(StandardCategory *category) { - QPointer form_pointer = new FormStandardCategoryDetails(m_sourceModel, this); - - form_pointer.data()->exec(category, NULL); - - delete form_pointer.data(); -} - void FeedsView::addNewFeed() { if (!qApp->feedUpdateLock()->tryLock()) { // Lock was not obtained because @@ -243,14 +235,6 @@ void FeedsView::addNewFeed() { qApp->feedUpdateLock()->unlock(); } -void FeedsView::editFeed(StandardFeed *feed) { - QPointer form_pointer = new FormStandardFeedDetails(m_sourceModel, this); - - form_pointer.data()->exec(feed, NULL); - - delete form_pointer.data(); -} - void FeedsView::receiveMessageCountsChange(FeedsSelection::SelectionMode mode, bool total_msg_count_changed, bool any_msg_restored) { @@ -297,19 +281,19 @@ void FeedsView::editSelectedItem() { qApp->showGuiMessage(tr("Cannot edit item"), tr("Selected item cannot be edited because another critical operation is ongoing."), QSystemTrayIcon::Warning, qApp->mainForm(), true); - // Thus, cannot delete and quit the method. return; } - StandardCategory *category; - StandardFeed *feed; - - if ((category = selectedCategory()) != NULL) { - editCategory(category); + if (selectedItem()->canBeEdited()) { + selectedItem()->edit(); } - else if ((feed = selectedFeed()) != NULL) { - editFeed(feed); + else { + qApp->showGuiMessage(tr("Cannot edit item"), + tr("Selected item cannot be edited, this is not (yet?) supported."), + QSystemTrayIcon::Warning, + qApp->mainForm(), + true); } // Changes are done, unlock the update master lock. @@ -388,7 +372,8 @@ void FeedsView::markAllFeedsRead() { } void FeedsView::fetchMetadataForSelectedFeed() { - StandardFeed *selected_feed = selectedFeed(); + // TODO: fix + StandardFeed *selected_feed = (StandardFeed*) selectedFeed(); if (selected_feed != NULL) { selected_feed->fetchMetadataForItself(); @@ -429,7 +414,7 @@ void FeedsView::restoreRecycleBin() { } void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) { - foreach (StandardFeed *feed, selectedFeeds()) { + foreach (Feed *feed, selectedFeeds()) { feed->updateCounts(update_total_too); } @@ -455,7 +440,7 @@ void FeedsView::updateCountsOfRecycleBin(bool update_total_too) { } void FeedsView::updateCountsOfAllFeeds(bool update_total_too) { - foreach (StandardFeed *feed, allFeeds()) { + foreach (Feed *feed, allFeeds()) { feed->updateCounts(update_total_too); } @@ -469,7 +454,7 @@ void FeedsView::updateCountsOfAllFeeds(bool update_total_too) { notifyWithCounts(); } -void FeedsView::updateCountsOfParticularFeed(StandardFeed *feed, bool update_total_too) { +void FeedsView::updateCountsOfParticularFeed(Feed *feed, bool update_total_too) { QModelIndex index = m_sourceModel->indexForItem(feed); if (index.isValid()) { diff --git a/src/gui/feedsview.h b/src/gui/feedsview.h index 0a8615f94..26d47dc5e 100755 --- a/src/gui/feedsview.h +++ b/src/gui/feedsview.h @@ -28,7 +28,7 @@ class FeedsProxyModel; -class StandardFeed; +class Feed; class StandardCategory; class QTimer; @@ -53,14 +53,14 @@ class FeedsView : public QTreeView { // Returns list of selected/all feeds. // NOTE: This is recursive method which returns all descendants. - QList selectedFeeds() const; - QList allFeeds() const; + QList selectedFeeds() const; + QList allFeeds() const; // Returns pointers to selected feed/category if they are really // selected. RootItem *selectedItem() const; StandardCategory *selectedCategory() const; - StandardFeed *selectedFeed() const; + Feed *selectedFeed() const; RecycleBin *selectedRecycleBin() const; // Saves/loads expand states of all nodes (feeds/categories) of the list to/from settings. @@ -104,11 +104,9 @@ class FeedsView : public QTreeView { // Standard category manipulators. void addNewCategory(); - void editCategory(StandardCategory *category); // Standard feed manipulators. void addNewFeed(); - void editFeed(StandardFeed *feed); // Is called when counts of messages are changed externally, // typically from message view. @@ -124,7 +122,7 @@ class FeedsView : public QTreeView { void updateCountsOfAllFeeds(bool update_total_too); // Reloads counts for particular feed. - void updateCountsOfParticularFeed(StandardFeed *feed, bool update_total_too); + void updateCountsOfParticularFeed(Feed *feed, bool update_total_too); // Notifies other components about messages // counts. @@ -168,7 +166,7 @@ class FeedsView : public QTreeView { signals: // Emitted if user/application requested updating of some feeds. - void feedsUpdateRequested(const QList feeds); + void feedsUpdateRequested(const QList feeds); // Emitted if counts of messages are changed. void messageCountsChanged(int unread_messages, int total_messages, bool any_feed_has_unread_messages); diff --git a/src/services/abstract/feed.cpp b/src/services/abstract/feed.cpp index 7436aa231..b3d8c61e8 100755 --- a/src/services/abstract/feed.cpp +++ b/src/services/abstract/feed.cpp @@ -17,9 +17,20 @@ #include "services/abstract/feed.h" +#include "definitions/definitions.h" -Feed::Feed() { + +Feed::Feed(RootItem *parent) : RootItem(parent) { + m_status = Normal; + m_autoUpdateType = DontAutoUpdate; + m_autoUpdateInitialInterval = DEFAULT_AUTO_UPDATE_INTERVAL; + m_autoUpdateRemainingInterval = DEFAULT_AUTO_UPDATE_INTERVAL; } Feed::~Feed() { } + +int Feed::childCount() const { + // Because feed has no children. + return 0; +} diff --git a/src/services/abstract/feed.h b/src/services/abstract/feed.h index 93b945a67..df2b28776 100755 --- a/src/services/abstract/feed.h +++ b/src/services/abstract/feed.h @@ -21,10 +21,78 @@ #include "core/rootitem.h" +// Base class for "feed" nodes. class Feed : public RootItem { public: - explicit Feed(); + // Specifies the auto-update strategy for the feed. + enum AutoUpdateType { + DontAutoUpdate = 0, + DefaultAutoUpdate = 1, + SpecificAutoUpdate = 2 + }; + + // Specifies the actual "status" of the feed. + // For example if it has new messages, error + // occurred, and so on. + enum Status { + Normal = 0, + NewMessages = 1, + NetworkError = 2 + }; + + // Constructors. + explicit Feed(RootItem *parent = NULL); virtual ~Feed(); + + // Returns 0, feeds have no children. + int childCount() const; + + // Performs synchronous update and returns number of newly updated messages. + virtual int update() = 0; + + // Updates counts of all/unread messages for this feed. + virtual void updateCounts(bool including_total_count = true, bool update_feed_statuses = true) = 0; + + 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; + } + + inline Status status() const { + return m_status; + } + + inline void setStatus(const Status &status) { + m_status = status; + } + + protected: + Status m_status; + AutoUpdateType m_autoUpdateType; + int m_autoUpdateInitialInterval; + int m_autoUpdateRemainingInterval; }; #endif // FEED_H diff --git a/src/services/standard/standardcategory.cpp b/src/services/standard/standardcategory.cpp index b87ae4b6f..eeae4d9c5 100755 --- a/src/services/standard/standardcategory.cpp +++ b/src/services/standard/standardcategory.cpp @@ -23,10 +23,15 @@ #include "miscellaneous/settings.h" #include "miscellaneous/iconfactory.h" #include "core/feedsmodel.h" +#include "gui/dialogs/formmain.h" +#include "gui/feedmessageviewer.h" +#include "gui/feedsview.h" +#include "services/standard/gui/formstandardcategorydetails.h" #include #include #include +#include StandardCategory::StandardCategory(RootItem *parent_item) : RootItem(parent_item) { @@ -121,6 +126,16 @@ QVariant StandardCategory::data(int column, int role) const { } } +void StandardCategory::edit() { + // TODO: fix passing of the model + QPointer form_pointer = new FormStandardCategoryDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), + qApp->mainForm()); + + form_pointer.data()->exec(this, NULL); + + delete form_pointer.data(); +} + bool StandardCategory::removeItself() { bool children_removed = true; diff --git a/src/services/standard/standardcategory.h b/src/services/standard/standardcategory.h index c0a952b8a..eb18a7cc8 100755 --- a/src/services/standard/standardcategory.h +++ b/src/services/standard/standardcategory.h @@ -42,6 +42,16 @@ class StandardCategory : public RootItem { // Returns the actual data representation of standard category. QVariant data(int column, int role) const; + bool canBeEdited() { + return true; + } + + bool canBeDeleted() { + return true; + } + + void edit(); + // Removes category and all its children from persistent // database. bool removeItself(); diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index 812529db0..13d8a244d 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -26,12 +26,17 @@ #include "miscellaneous/iconfactory.h" #include "miscellaneous/simplecrypt/simplecrypt.h" #include "network-web/networkfactory.h" +#include "gui/dialogs/formmain.h" +#include "gui/feedmessageviewer.h" +#include "gui/feedsview.h" +#include "services/standard/gui/formstandardfeeddetails.h" #include #include #include #include #include +#include #include #include #include @@ -42,26 +47,22 @@ void StandardFeed::init() { m_passwordProtected = false; m_username = QString(); m_password = QString(); - m_status = Normal; m_networkError = QNetworkReply::NoError; m_type = Rss0X; m_totalCount = 0; m_unreadCount = 0; - m_autoUpdateType = DontAutoUpdate; - m_autoUpdateInitialInterval = DEFAULT_AUTO_UPDATE_INTERVAL; - m_autoUpdateRemainingInterval = DEFAULT_AUTO_UPDATE_INTERVAL; m_encoding = QString(); m_url = QString(); m_kind = RootItem::Feeed; } StandardFeed::StandardFeed(RootItem *parent_item) - : RootItem(parent_item) { + : Feed(parent_item) { init(); } StandardFeed::StandardFeed(const StandardFeed &other) - : RootItem(NULL) { + : Feed(NULL) { m_passwordProtected = other.passwordProtected(); m_username = other.username(); m_password = other.password(); @@ -89,11 +90,6 @@ StandardFeed::~StandardFeed() { qDebug("Destroying Feed instance."); } -int StandardFeed::childCount() const { - // Because feed has no children. - return 0; -} - int StandardFeed::countOfAllMessages() const { return m_totalCount; } @@ -102,6 +98,15 @@ int StandardFeed::countOfUnreadMessages() const { return m_unreadCount; } +void StandardFeed::edit() { + // TODO: fix passing of the model + QPointer form_pointer = new FormStandardFeedDetails(qApp->mainForm()->tabWidget()->feedMessageViewer()->feedsView()->sourceModel(), + qApp->mainForm()); + form_pointer.data()->exec(this, NULL); + + delete form_pointer.data(); +} + QString StandardFeed::typeToString(StandardFeed::Type type) { switch (type) { case Atom10: @@ -710,7 +715,7 @@ QNetworkReply::NetworkError StandardFeed::networkError() const { return m_networkError; } -StandardFeed::StandardFeed(const QSqlRecord &record) : RootItem(NULL) { +StandardFeed::StandardFeed(const QSqlRecord &record) : Feed(NULL) { m_kind = RootItem::Feeed; setTitle(record.value(FDS_DB_TITLE_INDEX).toString()); diff --git a/src/services/standard/standardfeed.h b/src/services/standard/standardfeed.h index 41dfeec43..3c00b8e01 100755 --- a/src/services/standard/standardfeed.h +++ b/src/services/standard/standardfeed.h @@ -18,7 +18,7 @@ #ifndef FEEDSMODELFEED_H #define FEEDSMODELFEED_H -#include "core/rootitem.h" +#include "services/abstract/feed.h" #include #include @@ -33,7 +33,7 @@ class FeedsModel; // Represents BASE class for feeds contained in FeedsModel. // NOTE: This class should be derived to create PARTICULAR feed types. -class StandardFeed : public RootItem { +class StandardFeed : public Feed { Q_DECLARE_TR_FUNCTIONS(StandardFeed) public: @@ -46,43 +46,37 @@ class StandardFeed : public RootItem { Atom10 = 3 }; - // Specifies the auto-update strategy for the feed. - enum AutoUpdateType { - DontAutoUpdate = 0, - DefaultAutoUpdate = 1, - SpecificAutoUpdate = 2 - }; - - // Specifies the actual "status" of the feed. - // For example if it has new messages, error - // occurred, and so on. - enum Status { - Normal = 0, - NewMessages = 1, - NetworkError = 2 - }; - // Constructors and destructors. explicit StandardFeed(RootItem *parent_item = NULL); explicit StandardFeed(const StandardFeed &other); explicit StandardFeed(const QSqlRecord &record); virtual ~StandardFeed(); - // Returns 0, feeds have no children. - int childCount() const; - // Getters/setters for count of messages. // NOTE: For feeds, counts are stored internally // and can be updated from the database. int countOfAllMessages() const; int countOfUnreadMessages() const; + bool canBeEdited() { + return true; + } + + bool canBeDeleted() { + return true; + } + + void edit(); + // Obtains data related to this feed. QVariant data(int column, int role) const; // Perform fetching of new messages. Returns number of newly updated messages. int update(); + // Updates counts of all/unread messages for this feed. + void updateCounts(bool including_total_count = true, bool update_feed_statuses = true); + // Removes this standard feed from persistent // storage. bool removeItself(); @@ -138,41 +132,6 @@ class StandardFeed : public RootItem { 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; - } - - inline Status status() const { - return m_status; - } - - inline void setStatus(const Status &status) { - m_status = status; - } - QNetworkReply::NetworkError networkError() const; // Tries to guess feed hidden under given URL @@ -186,9 +145,7 @@ class StandardFeed : public RootItem { static QString typeToString(Type type); public slots: - // Updates counts of all/unread messages for this feed. - void updateCounts(bool including_total_count = true, bool update_feed_statuses = true); - + // Fetches metadata for the feed. void fetchMetadataForItself(); protected: @@ -205,16 +162,11 @@ class StandardFeed : public RootItem { QString m_username; QString m_password; - Status m_status; - QNetworkReply::NetworkError m_networkError; Type m_type; + QNetworkReply::NetworkError m_networkError; int m_totalCount; int m_unreadCount; - AutoUpdateType m_autoUpdateType; - int m_autoUpdateInitialInterval; - int m_autoUpdateRemainingInterval; - QString m_encoding; QString m_url; };