Refactorings.

This commit is contained in:
Martin Rotter 2017-09-26 08:18:42 +02:00
parent 589c08bc8b
commit 09f6828ee1
6 changed files with 30 additions and 25 deletions

View File

@ -34,7 +34,13 @@ Category::Category(RootItem* parent) : RootItem(parent) {
} }
} }
Category::Category(const Category& other) : RootItem(other) {} Category::Category(const Category& other) : RootItem(other) {
setKind(RootItemKind::Category);
if (icon().isNull()) {
setIcon(qApp->icons()->fromTheme(QSL("folder")));
}
}
Category::Category(const QSqlRecord& record) : Category(nullptr) { Category::Category(const QSqlRecord& record) : Category(nullptr) {
setId(record.value(CAT_DB_ID_INDEX).toInt()); setId(record.value(CAT_DB_ID_INDEX).toInt());

View File

@ -22,6 +22,7 @@
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/databasequeries.h" #include "miscellaneous/databasequeries.h"
#include "miscellaneous/feedreader.h" #include "miscellaneous/feedreader.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/mutex.h" #include "miscellaneous/mutex.h"
#include "services/abstract/cacheforserviceroot.h" #include "services/abstract/cacheforserviceroot.h"
#include "services/abstract/recyclebin.h" #include "services/abstract/recyclebin.h"
@ -35,7 +36,17 @@ Feed::Feed(RootItem* parent)
m_totalCount(0), m_unreadCount(0) { m_totalCount(0), m_unreadCount(0) {
setKind(RootItemKind::Feed); setKind(RootItemKind::Feed);
setAutoDelete(false); setAutoDelete(false);
}
Feed::Feed(const QSqlRecord& record) : Feed(nullptr) {
setTitle(record.value(FDS_DB_TITLE_INDEX).toString());
setId(record.value(FDS_DB_ID_INDEX).toInt());
setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toString());
setIcon(qApp->icons()->fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray()));
setAutoUpdateType(static_cast<Feed::AutoUpdateType>(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt()));
setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt());
qDebug("Custom ID of feed when loading from DB is '%s'.", qPrintable(customId()));
} }
Feed::Feed(const Feed& other) : RootItem(other) { Feed::Feed(const Feed& other) : RootItem(other) {

View File

@ -52,6 +52,7 @@ class Feed : public RootItem, public QRunnable {
// Constructors. // Constructors.
explicit Feed(RootItem* parent = nullptr); explicit Feed(RootItem* parent = nullptr);
explicit Feed(const QSqlRecord& record);
explicit Feed(const Feed& other); explicit Feed(const Feed& other);
virtual ~Feed(); virtual ~Feed();

View File

@ -27,20 +27,13 @@
#include <QVariant> #include <QVariant>
RootItem::RootItem(RootItem* parent_item) RootItem::RootItem(RootItem* parent_item)
: QObject(nullptr), : QObject(nullptr), m_kind(RootItemKind::Root), m_id(NO_PARENT_CATEGORY), m_customId(QSL("")),
m_kind(RootItemKind::Root), m_title(QString()), m_description(QString()), m_icon(QIcon()), m_creationDate(QDateTime()),
m_id(NO_PARENT_CATEGORY), m_childItems(QList<RootItem*>()), m_parentItem(parent_item) {
m_customId(QSL("")),
m_title(QString()),
m_description(QString()),
m_icon(QIcon()),
m_creationDate(QDateTime()),
m_childItems(QList<RootItem*>()),
m_parentItem(parent_item) {
setupFonts(); setupFonts();
} }
RootItem::RootItem(const RootItem& other) { RootItem::RootItem(const RootItem& other) : RootItem(nullptr) {
setTitle(other.title()); setTitle(other.title());
setId(other.id()); setId(other.id());
setCustomId(other.customId()); setCustomId(other.customId());
@ -174,6 +167,10 @@ QVariant RootItem::data(int column, int role) const {
} }
case Qt::FontRole: case Qt::FontRole:
if (countOfUnreadMessages() > 0) {
int a = 4;
}
return countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont; return countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont;
case Qt::DisplayRole: case Qt::DisplayRole:

View File

@ -28,15 +28,7 @@
OwnCloudFeed::OwnCloudFeed(RootItem* parent) : Feed(parent) {} OwnCloudFeed::OwnCloudFeed(RootItem* parent) : Feed(parent) {}
OwnCloudFeed::OwnCloudFeed(const QSqlRecord& record) : Feed(nullptr) { OwnCloudFeed::OwnCloudFeed(const QSqlRecord& record) : Feed(record) {}
setTitle(record.value(FDS_DB_TITLE_INDEX).toString());
setId(record.value(FDS_DB_ID_INDEX).toInt());
setCustomId(record.value(FDS_DB_CUSTOM_ID_INDEX).toString());
setIcon(qApp->icons()->fromByteArray(record.value(FDS_DB_ICON_INDEX).toByteArray()));
setAutoUpdateType(static_cast<Feed::AutoUpdateType>(record.value(FDS_DB_UPDATE_TYPE_INDEX).toInt()));
setAutoUpdateInitialInterval(record.value(FDS_DB_UPDATE_INTERVAL_INDEX).toInt());
qDebug("Custom ID of Nextcloud feed when loading from DB is '%s'.", qPrintable(customId()));
}
OwnCloudFeed::~OwnCloudFeed() {} OwnCloudFeed::~OwnCloudFeed() {}
@ -91,7 +83,7 @@ OwnCloudServiceRoot* OwnCloudFeed::serviceRoot() const {
} }
QList<Message> OwnCloudFeed::obtainNewMessages(bool* error_during_obtaining) { QList<Message> OwnCloudFeed::obtainNewMessages(bool* error_during_obtaining) {
OwnCloudGetMessagesResponse messages = serviceRoot()->network()->getMessages(customId().toInt()); OwnCloudGetMessagesResponse messages = serviceRoot()->network()->getMessages(customNumericId());
if (serviceRoot()->network()->lastError() != QNetworkReply::NoError) { if (serviceRoot()->network()->lastError() != QNetworkReply::NoError) {
setStatus(Feed::NetworkError); setStatus(Feed::NetworkError);

View File

@ -65,11 +65,9 @@ class StandardFeed : public Feed {
Qt::ItemFlags additionalFlags() const; Qt::ItemFlags additionalFlags() const;
bool performDragDropChange(RootItem* target_item); bool performDragDropChange(RootItem* target_item);
// Removes this standard feed from persistent
// storage.
bool removeItself();
bool addItself(RootItem* parent); bool addItself(RootItem* parent);
bool editItself(StandardFeed* new_feed_data); bool editItself(StandardFeed* new_feed_data);
bool removeItself();
// Other getters/setters. // Other getters/setters.
Type type() const; Type type() const;