Add std acc when no account is active.

This commit is contained in:
Martin Rotter 2017-09-09 09:21:30 +02:00
parent a01023629c
commit c4fec28e56
5 changed files with 2153 additions and 70 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,9 @@
3.4.3 3.4.3
————— —————
Added:
▪ Standard account is now automatically added if RSS Guard is started with empty database.
Fixed: Fixed:
▪ Fixed build on some Unit-like operating systems. ▪ Fixed build on some Unit-like operating systems.

View File

@ -187,7 +187,8 @@ win32 {
} }
DISTFILES += resources/scripts/astyle/.astylerc \ DISTFILES += resources/scripts/astyle/.astylerc \
resources/scripts/uncrustify/uncrustify.cfg resources/scripts/uncrustify/uncrustify.cfg \
resources/scripts/uncrustify/uncrustify.cfg
MOC_DIR = $$OUT_PWD/moc MOC_DIR = $$OUT_PWD/moc
RCC_DIR = $$OUT_PWD/rcc RCC_DIR = $$OUT_PWD/rcc

View File

@ -23,6 +23,7 @@
#include "services/abstract/serviceroot.h" #include "services/abstract/serviceroot.h"
#include "services/abstract/recyclebin.h" #include "services/abstract/recyclebin.h"
#include "services/abstract/serviceentrypoint.h" #include "services/abstract/serviceentrypoint.h"
#include "services/standard/standardserviceentrypoint.h"
#include "services/standard/standardserviceroot.h" #include "services/standard/standardserviceroot.h"
#include "miscellaneous/textfactory.h" #include "miscellaneous/textfactory.h"
#include "miscellaneous/databasefactory.h" #include "miscellaneous/databasefactory.h"
@ -34,6 +35,7 @@
#include <QPair> #include <QPair>
#include <QStack> #include <QStack>
#include <QMimeData> #include <QMimeData>
#include <QTimer>
#include <algorithm> #include <algorithm>
@ -42,15 +44,15 @@ FeedsModel::FeedsModel(QObject* parent) : QAbstractItemModel(parent) {
setObjectName(QSL("FeedsModel")); setObjectName(QSL("FeedsModel"));
// Create root item. // Create root item.
m_rootItem = new RootItem(); m_rootItem = new RootItem();
//: Name of root item of feed list which can be seen in feed add/edit dialog. // : Name of root item of feed list which can be seen in feed add/edit dialog.
m_rootItem->setTitle(tr("Root")); m_rootItem->setTitle(tr("Root"));
m_rootItem->setIcon(qApp->icons()->fromTheme(QSL("folder"))); m_rootItem->setIcon(qApp->icons()->fromTheme(QSL("folder")));
// Setup icons. // Setup icons.
m_countsIcon = qApp->icons()->fromTheme(QSL("mail-mark-unread")); m_countsIcon = qApp->icons()->fromTheme(QSL("mail-mark-unread"));
//: Title text in the feed list header. // : Title text in the feed list header.
m_headerData << tr("Title"); m_headerData << tr("Title");
m_tooltipData << /*: Feed list header "titles" column tooltip.*/ tr("Titles of feeds/categories.") << m_tooltipData << /*: Feed list header "titles" column tooltip.*/ tr("Titles of feeds/categories.")
/*: Feed list header "counts" column tooltip.*/ tr("Counts of unread/all mesages."); << /*: Feed list header "counts" column tooltip.*/ tr("Counts of unread/all mesages.");
} }
FeedsModel::~FeedsModel() { FeedsModel::~FeedsModel() {
@ -64,7 +66,7 @@ QMimeData* FeedsModel::mimeData(const QModelIndexList& indexes) const {
QByteArray encoded_data; QByteArray encoded_data;
QDataStream stream(&encoded_data, QIODevice::WriteOnly); QDataStream stream(&encoded_data, QIODevice::WriteOnly);
foreach (const QModelIndex& index, indexes) { foreach (const QModelIndex &index, indexes) {
if (index.column() != 0) { if (index.column() != 0) {
continue; continue;
} }
@ -72,7 +74,7 @@ QMimeData* FeedsModel::mimeData(const QModelIndexList& indexes) const {
RootItem* item_for_index = itemForIndex(index); RootItem* item_for_index = itemForIndex(index);
if (item_for_index->kind() != RootItemKind::Root) { if (item_for_index->kind() != RootItemKind::Root) {
stream << (quintptr) item_for_index; stream << (quintptr)item_for_index;
} }
} }
@ -107,7 +109,7 @@ bool FeedsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int
quintptr pointer_to_item; quintptr pointer_to_item;
stream >> pointer_to_item; stream >> pointer_to_item;
// We have item we want to drag, we also determine the target item. // We have item we want to drag, we also determine the target item.
RootItem* dragged_item = (RootItem*) pointer_to_item; RootItem* dragged_item = (RootItem*)pointer_to_item;
RootItem* target_item = itemForIndex(parent); RootItem* target_item = itemForIndex(parent);
ServiceRoot* dragged_item_root = dragged_item->getParentServiceRoot(); ServiceRoot* dragged_item_root = dragged_item->getParentServiceRoot();
ServiceRoot* target_item_root = target_item->getParentServiceRoot(); ServiceRoot* target_item_root = target_item->getParentServiceRoot();
@ -158,27 +160,27 @@ QVariant FeedsModel::headerData(int section, Qt::Orientation orientation, int ro
} }
switch (role) { switch (role) {
case Qt::DisplayRole: case Qt::DisplayRole:
if (section == FDS_MODEL_TITLE_INDEX) { if (section == FDS_MODEL_TITLE_INDEX) {
return m_headerData.at(FDS_MODEL_TITLE_INDEX); return m_headerData.at(FDS_MODEL_TITLE_INDEX);
} }
else { else {
return QVariant();
}
case Qt::ToolTipRole:
return m_tooltipData.at(section);
case Qt::DecorationRole:
if (section == FDS_MODEL_COUNTS_INDEX) {
return m_countsIcon;
}
else {
return QVariant();
}
default:
return QVariant(); return QVariant();
}
case Qt::ToolTipRole:
return m_tooltipData.at(section);
case Qt::DecorationRole:
if (section == FDS_MODEL_COUNTS_INDEX) {
return m_countsIcon;
}
else {
return QVariant();
}
default:
return QVariant();
} }
} }
@ -325,34 +327,34 @@ QList<Feed*> FeedsModel::feedsForScheduledUpdate(bool auto_update_now) {
foreach (Feed* feed, m_rootItem->getSubTreeFeeds()) { foreach (Feed* feed, m_rootItem->getSubTreeFeeds()) {
switch (feed->autoUpdateType()) { switch (feed->autoUpdateType()) {
case Feed::DontAutoUpdate: case Feed::DontAutoUpdate:
// Do not auto-update this feed ever. // Do not auto-update this feed ever.
continue; continue;
case Feed::DefaultAutoUpdate: case Feed::DefaultAutoUpdate:
if (auto_update_now) { if (auto_update_now) {
feeds_for_update.append(feed); feeds_for_update.append(feed);
} }
break; break;
case Feed::SpecificAutoUpdate: case Feed::SpecificAutoUpdate:
default: default:
int remaining_interval = feed->autoUpdateRemainingInterval(); int remaining_interval = feed->autoUpdateRemainingInterval();
if (--remaining_interval <= 0) { if (--remaining_interval <= 0) {
// Interval of this feed passed, include this feed in the output list // Interval of this feed passed, include this feed in the output list
// and reset the interval. // and reset the interval.
feeds_for_update.append(feed); feeds_for_update.append(feed);
feed->setAutoUpdateRemainingInterval(feed->autoUpdateInitialInterval()); feed->setAutoUpdateRemainingInterval(feed->autoUpdateInitialInterval());
} }
else { else {
// Interval did not pass, set new decremented interval and do NOT // Interval did not pass, set new decremented interval and do NOT
// include this feed in the output list. // include this feed in the output list.
feed->setAutoUpdateRemainingInterval(remaining_interval); feed->setAutoUpdateRemainingInterval(remaining_interval);
} }
break; break;
} }
} }
@ -403,7 +405,7 @@ QModelIndex FeedsModel::indexForItem(const RootItem* item) const {
} }
bool FeedsModel::hasAnyFeedNewMessages() const { bool FeedsModel::hasAnyFeedNewMessages() const {
foreach (const Feed* feed, m_rootItem->getSubTreeFeeds()) { foreach (const Feed * feed, m_rootItem->getSubTreeFeeds()) {
if (feed->status() == Feed::NewMessages) { if (feed->status() == Feed::NewMessages) {
return true; return true;
} }
@ -446,7 +448,7 @@ void FeedsModel::onItemDataChanged(const QList<RootItem*>& items) {
else { else {
qDebug("There is request to reload feed model, reloading the %d items individually.", items.size()); qDebug("There is request to reload feed model, reloading the %d items individually.", items.size());
foreach (RootItem* item, items) { foreach (RootItem * item, items) {
reloadChangedItem(item); reloadChangedItem(item);
} }
} }
@ -478,7 +480,7 @@ bool FeedsModel::addServiceAccount(ServiceRoot* root, bool freshly_activated) {
bool FeedsModel::restoreAllBins() { bool FeedsModel::restoreAllBins() {
bool result = true; bool result = true;
foreach (ServiceRoot* root, serviceRoots()) { foreach (ServiceRoot * root, serviceRoots()) {
RecycleBin* bin_of_root = root->recycleBin(); RecycleBin* bin_of_root = root->recycleBin();
if (bin_of_root != nullptr) { if (bin_of_root != nullptr) {
@ -492,7 +494,7 @@ bool FeedsModel::restoreAllBins() {
bool FeedsModel::emptyAllBins() { bool FeedsModel::emptyAllBins() {
bool result = true; bool result = true;
foreach (ServiceRoot* root, serviceRoots()) { foreach (ServiceRoot * root, serviceRoots()) {
RecycleBin* bin_of_root = root->recycleBin(); RecycleBin* bin_of_root = root->recycleBin();
if (bin_of_root != nullptr) { if (bin_of_root != nullptr) {
@ -513,10 +515,16 @@ void FeedsModel::loadActivatedServiceAccounts() {
addServiceAccount(root, false); addServiceAccount(root, false);
} }
} }
if (serviceRoots().isEmpty()) {
QTimer::singleShot(2000, [this]() {
addServiceAccount(StandardServiceEntryPoint().createNewRoot(), true);
});
}
} }
void FeedsModel::stopServiceAccounts() { void FeedsModel::stopServiceAccounts() {
foreach (ServiceRoot* account, serviceRoots()) { foreach (ServiceRoot * account, serviceRoots()) {
account->stop(); account->stop();
} }
} }

View File

@ -44,8 +44,8 @@
StandardServiceRoot::StandardServiceRoot(RootItem* parent) StandardServiceRoot::StandardServiceRoot(RootItem* parent)
: ServiceRoot(parent), m_recycleBin(new RecycleBin(this)), : ServiceRoot(parent), m_recycleBin(new RecycleBin(this)),
m_actionExportFeeds(nullptr), m_actionImportFeeds(nullptr), m_serviceMenu(QList<QAction*>()), m_actionExportFeeds(nullptr), m_actionImportFeeds(nullptr), m_serviceMenu(QList<QAction*>()),
m_feedContextMenu(QList<QAction*>()), m_actionFeedFetchMetadata(nullptr) { m_feedContextMenu(QList<QAction*>()), m_actionFeedFetchMetadata(nullptr) {
setTitle(qApp->system()->loggedInUser() + QL1S("@") + QL1S(APP_LOW_NAME)); setTitle(qApp->system()->loggedInUser() + QL1S("@") + QL1S(APP_LOW_NAME));
setIcon(StandardServiceEntryPoint().icon()); setIcon(StandardServiceEntryPoint().icon());
setDescription(tr("This is obligatory service account for standard RSS/RDF/ATOM feeds.")); setDescription(tr("This is obligatory service account for standard RSS/RDF/ATOM feeds."));
@ -59,7 +59,7 @@ StandardServiceRoot::~StandardServiceRoot() {
void StandardServiceRoot::start(bool freshly_activated) { void StandardServiceRoot::start(bool freshly_activated) {
loadFromDatabase(); loadFromDatabase();
if (freshly_activated) { if (freshly_activated && getSubTree(RootItemKind::Feed).isEmpty()) {
// In other words, if there are no feeds or categories added. // In other words, if there are no feeds or categories added.
if (MessageBox::show(qApp->mainFormWidget(), QMessageBox::Question, QObject::tr("Load initial set of feeds"), if (MessageBox::show(qApp->mainFormWidget(), QMessageBox::Question, QObject::tr("Load initial set of feeds"),
tr("This new account does not include any feeds. You can now add default set of feeds."), tr("This new account does not include any feeds. You can now add default set of feeds."),
@ -143,17 +143,17 @@ void StandardServiceRoot::addNewFeed(const QString& url) {
QVariant StandardServiceRoot::data(int column, int role) const { QVariant StandardServiceRoot::data(int column, int role) const {
switch (role) { switch (role) {
case Qt::ToolTipRole: case Qt::ToolTipRole:
if (column == FDS_MODEL_TITLE_INDEX) { if (column == FDS_MODEL_TITLE_INDEX) {
return tr("This is service account for standard RSS/RDF/ATOM feeds.\n\nAccount ID: %1").arg(accountId()); return tr("This is service account for standard RSS/RDF/ATOM feeds.\n\nAccount ID: %1").arg(accountId());
} }
else { else {
return ServiceRoot::data(column, role);
}
default:
return ServiceRoot::data(column, role); return ServiceRoot::data(column, role);
} }
default:
return ServiceRoot::data(column, role);
}
} }
Qt::ItemFlags StandardServiceRoot::additionalFlags() const { Qt::ItemFlags StandardServiceRoot::additionalFlags() const {
@ -178,7 +178,7 @@ void StandardServiceRoot::loadFromDatabase() {
} }
void StandardServiceRoot::checkArgumentsForFeedAdding() { void StandardServiceRoot::checkArgumentsForFeedAdding() {
foreach (const QString& arg, qApp->arguments().mid(1)) { foreach (const QString &arg, qApp->arguments().mid(1)) {
checkArgumentForFeedAdding(arg); checkArgumentForFeedAdding(arg);
} }
} }