Work is ongoing - refactored some of "edit" methods. Very sloppy, though.

This commit is contained in:
Martin Rotter 2015-10-30 10:47:43 +01:00
parent 6e22510e7c
commit fd94a1bd8f
17 changed files with 229 additions and 172 deletions

View File

@ -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.

View File

@ -17,7 +17,7 @@
#include "core/feeddownloader.h"
#include "services/standard/standardfeed.h"
#include "services/abstract/feed.h"
#include "definitions/definitions.h"
#include <QThread>
@ -32,7 +32,7 @@ FeedDownloader::~FeedDownloader() {
qDebug("Destroying FeedDownloader instance.");
}
void FeedDownloader::updateFeeds(const QList<StandardFeed*> &feeds) {
void FeedDownloader::updateFeeds(const QList<Feed*> &feeds) {
qDebug().nospace() << "Performing feed updates in thread: \'" << QThread::currentThreadId() << "\'.";
// Job starts now.

View File

@ -23,7 +23,7 @@
#include <QPair>
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<StandardFeed*> &feeds);
void updateFeeds(const QList<Feed*> &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

View File

@ -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<StandardFeed*> feeds_for_update = feedsForScheduledUpdate(m_globalAutoUpdateEnabled && m_globalAutoUpdateRemainingInterval == 0);
QList<Feed*> 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<StandardFeed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
QList<StandardFeed*> feeds_for_update;
QList<Feed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
QList<Feed*> 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<StandardFeed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
return feeds_for_update;
}
QList<Message> FeedsModel::messagesForFeeds(const QList<StandardFeed*> &feeds) {
QList<Message> FeedsModel::messagesForFeeds(const QList<Feed*> &feeds) {
QList<Message> messages;
QSqlDatabase database = qApp->database()->connection(objectName(),
@ -482,7 +483,7 @@ QList<Message> FeedsModel::messagesForFeeds(const QList<StandardFeed*> &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<StandardFeed*> &feeds) {
QStringList FeedsModel::textualFeedIds(const QList<Feed*> &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<StandardFeed*> FeedsModel::feedsForIndex(const QModelIndex &index) {
QList<Feed*> 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<Feed*>(item);
}
else {
return NULL;
}
}
QList<StandardFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
QList<StandardFeed*> feeds;
QList<Feed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes) {
QList<Feed*> feeds;
// Get selected feeds for each index.
foreach (const QModelIndex &index, indexes) {
@ -782,7 +783,7 @@ QList<StandardFeed*> FeedsModel::feedsForIndexes(const QModelIndexList &indexes)
return feeds;
}
bool FeedsModel::markFeedsRead(const QList<StandardFeed*> &feeds, int read) {
bool FeedsModel::markFeedsRead(const QList<Feed *> &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<StandardFeed*> &feeds, int read) {
}
}
bool FeedsModel::markFeedsDeleted(const QList<StandardFeed*> &feeds, int deleted, bool read_only) {
bool FeedsModel::markFeedsDeleted(const QList<Feed*> &feeds, int deleted, bool read_only) {
QSqlDatabase db_handle = qApp->database()->connection(objectName(), DatabaseFactory::FromSettings);
if (!db_handle.transaction()) {
@ -893,13 +894,13 @@ QHash<int, StandardCategory*> FeedsModel::categoriesForItem(RootItem *root) {
return categories;
}
QList<StandardFeed*> FeedsModel::allFeeds() {
QList<Feed*> FeedsModel::allFeeds() {
return feedsForItem(m_rootItem);
}
QList<StandardFeed*> FeedsModel::feedsForItem(RootItem *root) {
QList<Feed*> FeedsModel::feedsForItem(RootItem *root) {
QList<RootItem*> children = root->getRecursiveChildren();
QList<StandardFeed*> feeds;
QList<Feed*> feeds;
foreach (RootItem *child, children) {
if (child->kind() == RootItem::Feeed) {

View File

@ -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<StandardFeed*> feedsForScheduledUpdate(bool auto_update_now);
QList<Feed*> feedsForScheduledUpdate(bool auto_update_now);
// Returns (undeleted) messages for given feeds.
// This is usually used for displaying whole feeds
// in "newspaper" mode.
QList<Message> messagesForFeeds(const QList<StandardFeed*> &feeds);
QList<Message> messagesForFeeds(const QList<Feed*> &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<int, StandardCategory*> categoriesForItem(RootItem *root);
// Returns list of all feeds contained in the model.
QList<StandardFeed*> allFeeds();
QList<Feed*> allFeeds();
// Get list of feeds from tree with particular item
// as root. If root itself is a feed, then it is returned.
QList<StandardFeed*> feedsForItem(RootItem *root);
QList<Feed*> feedsForItem(RootItem *root);
// Returns list of ALL CHILD feeds which belong to given parent indexes.
QList<StandardFeed*> feedsForIndexes(const QModelIndexList &indexes);
QList<Feed*> feedsForIndexes(const QModelIndexList &indexes);
// Returns ALL CHILD feeds contained within single index.
QList<StandardFeed*> feedsForIndex(const QModelIndex &index);
QList<Feed*> 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<StandardFeed*> &feeds, int read);
bool markFeedsDeleted(const QList<StandardFeed*> &feeds, int deleted, bool read_only);
bool markFeedsRead(const QList<Feed*> &feeds, int read);
bool markFeedsDeleted(const QList<Feed*> &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<StandardFeed*> &feeds);
QStringList textualFeedIds(const QList<Feed*> &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<StandardFeed*> feeds);
void feedsUpdateRequested(const QList<Feed*> feeds);
private:
RootItem *m_rootItem;

View File

@ -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;

View File

@ -691,17 +691,17 @@
</action>
<action name="m_actionServiceAdd">
<property name="text">
<string>&amp;Add new service</string>
<string>&amp;Add new service account</string>
</property>
</action>
<action name="m_actionServiceDelete">
<property name="text">
<string>&amp;Delete selected service</string>
<string>&amp;Delete selected service account</string>
</property>
</action>
<action name="m_actionServiceEdit">
<property name="text">
<string>&amp;Edit selected service</string>
<string>&amp;Edit selected service account</string>
</property>
</action>
</widget>

View File

@ -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<Message>)));
// Downloader connections.
connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList<StandardFeed*>)), this, SLOT(updateFeeds(QList<StandardFeed*>)));
connect(m_feedsView, SIGNAL(feedsUpdateRequested(QList<Feed*>)), this, SLOT(updateFeeds(QList<Feed*>)));
// 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<StandardFeed *> feeds) {
void FeedMessageViewer::updateFeeds(QList<Feed*> 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<StandardFeed *> feeds) {
m_feedDownloaderThread = new QThread();
// Downloader setup.
qRegisterMetaType<QList<StandardFeed*> >("QList<StandardFeed*>");
qRegisterMetaType<QList<Feed*> >("QList<Feed*>");
m_feedDownloader->moveToThread(m_feedDownloaderThread);
connect(this, SIGNAL(feedsUpdateRequested(QList<StandardFeed*>)), m_feedDownloader, SLOT(updateFeeds(QList<StandardFeed*>)));
connect(this, SIGNAL(feedsUpdateRequested(QList<Feed*>)), m_feedDownloader, SLOT(updateFeeds(QList<Feed*>)));
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();

View File

@ -103,7 +103,7 @@ class FeedMessageViewer : public TabContent {
// Reloads some changeable visual settings.
void refreshVisualProperties();
void updateFeeds(QList<StandardFeed*> feeds);
void updateFeeds(QList<Feed*> 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<StandardFeed*> feeds);
void feedsUpdateRequested(const QList<Feed*> feeds);
private:
bool m_toolBarsEnabled;

View File

@ -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<StandardFeed*>)), this, SIGNAL(feedsUpdateRequested(QList<StandardFeed*>)));
connect(m_sourceModel, SIGNAL(feedsUpdateRequested(QList<Feed*>)), this, SIGNAL(feedsUpdateRequested(QList<Feed*>)));
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<StandardFeed*> FeedsView::selectedFeeds() const {
QList<Feed*> FeedsView::selectedFeeds() const {
QModelIndex current_index = currentIndex();
if (current_index.isValid()) {
return m_sourceModel->feedsForIndex(m_proxyModel->mapToSource(current_index));
}
else {
return QList<StandardFeed*>();
return QList<Feed*>();
}
}
QList<StandardFeed*> FeedsView::allFeeds() const {
QList<Feed*> 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<FormStandardCategoryDetails> 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<FormStandardFeedDetails> 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()) {

View File

@ -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<StandardFeed*> selectedFeeds() const;
QList<StandardFeed*> allFeeds() const;
QList<Feed*> selectedFeeds() const;
QList<Feed*> 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<StandardFeed*> feeds);
void feedsUpdateRequested(const QList<Feed*> feeds);
// Emitted if counts of messages are changed.
void messageCountsChanged(int unread_messages, int total_messages, bool any_feed_has_unread_messages);

View File

@ -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;
}

View File

@ -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

View File

@ -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 <QVariant>
#include <QSqlQuery>
#include <QSqlError>
#include <QPointer>
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<FormStandardCategoryDetails> 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;

View File

@ -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();

View File

@ -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 <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QVariant>
#include <QTextCodec>
#include <QPointer>
#include <QDomDocument>
#include <QDomNode>
#include <QDomElement>
@ -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<FormStandardFeedDetails> 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());

View File

@ -18,7 +18,7 @@
#ifndef FEEDSMODELFEED_H
#define FEEDSMODELFEED_H
#include "core/rootitem.h"
#include "services/abstract/feed.h"
#include <QMetaType>
#include <QDateTime>
@ -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;
};