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

@ -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) {
setId(record.value(CAT_DB_ID_INDEX).toInt());

@ -22,6 +22,7 @@
#include "miscellaneous/application.h"
#include "miscellaneous/databasequeries.h"
#include "miscellaneous/feedreader.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/mutex.h"
#include "services/abstract/cacheforserviceroot.h"
#include "services/abstract/recyclebin.h"
@ -35,7 +36,17 @@ Feed::Feed(RootItem* parent)
m_totalCount(0), m_unreadCount(0) {
setKind(RootItemKind::Feed);
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) {

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

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

@ -28,15 +28,7 @@
OwnCloudFeed::OwnCloudFeed(RootItem* parent) : Feed(parent) {}
OwnCloudFeed::OwnCloudFeed(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 Nextcloud feed when loading from DB is '%s'.", qPrintable(customId()));
}
OwnCloudFeed::OwnCloudFeed(const QSqlRecord& record) : Feed(record) {}
OwnCloudFeed::~OwnCloudFeed() {}
@ -91,7 +83,7 @@ OwnCloudServiceRoot* OwnCloudFeed::serviceRoot() const {
}
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) {
setStatus(Feed::NetworkError);

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