mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-06 20:33:38 +01:00
Added some information to service roots implementations.
This commit is contained in:
parent
fa373df15c
commit
52b41e19f4
@ -69,9 +69,7 @@ int RootItem::countOfAllMessages() const {
|
||||
int total_count = 0;
|
||||
|
||||
foreach (RootItem *child_item, m_childItems) {
|
||||
if (child_item->kind() != RootItem::Bin) {
|
||||
total_count += child_item->countOfAllMessages();
|
||||
}
|
||||
total_count += child_item->countOfAllMessages();
|
||||
}
|
||||
|
||||
return total_count;
|
||||
@ -143,9 +141,7 @@ int RootItem::countOfUnreadMessages() const {
|
||||
int total_count = 0;
|
||||
|
||||
foreach (RootItem *child_item, m_childItems) {
|
||||
if (child_item->kind() != RootItem::Bin) {
|
||||
total_count += child_item->countOfUnreadMessages();
|
||||
}
|
||||
total_count += child_item->countOfUnreadMessages();
|
||||
}
|
||||
|
||||
return total_count;
|
||||
|
@ -172,6 +172,20 @@ bool SystemFactory::removeTrolltechJunkRegistryKeys() {
|
||||
}
|
||||
#endif
|
||||
|
||||
QString SystemFactory::getUsername() const {
|
||||
QString name = qgetenv("USER");
|
||||
|
||||
if (name.isEmpty()) {
|
||||
name = qgetenv("USERNAME");
|
||||
}
|
||||
|
||||
if (name.isEmpty()) {
|
||||
name = tr("anonymous");
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
QPair<UpdateInfo, QNetworkReply::NetworkError> SystemFactory::checkForUpdates() {
|
||||
QPair<UpdateInfo, QNetworkReply::NetworkError> result;
|
||||
QByteArray releases_xml;
|
||||
|
@ -80,6 +80,9 @@ class SystemFactory : public QObject {
|
||||
QString getAutostartDesktopFileLocation();
|
||||
#endif
|
||||
|
||||
// Retrieves username of currently logged-in user.
|
||||
QString getUsername() const;
|
||||
|
||||
// Tries to download list with new updates.
|
||||
QPair<UpdateInfo, QNetworkReply::NetworkError> checkForUpdates();
|
||||
|
||||
|
@ -17,10 +17,88 @@
|
||||
|
||||
#include "services/standard/standardserviceroot.h"
|
||||
|
||||
#include "definitions/definitions.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/settings.h"
|
||||
#include "services/standard/standardserviceentrypoint.h"
|
||||
|
||||
|
||||
StandardServiceRoot::StandardServiceRoot(RootItem *parent) : ServiceRoot(parent) {
|
||||
m_title = qApp->system()->getUsername() + "@" + APP_LOW_NAME;
|
||||
m_icon = StandardServiceEntryPoint().icon();
|
||||
}
|
||||
|
||||
StandardServiceRoot::~StandardServiceRoot() {
|
||||
}
|
||||
|
||||
bool StandardServiceRoot::canBeEdited() {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StandardServiceRoot::canBeDeleted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant StandardServiceRoot::data(int column, int role) const {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||
return m_title;
|
||||
}
|
||||
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||
return qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::CountFormat)).toString()
|
||||
.replace(PLACEHOLDER_UNREAD_COUNTS, QString::number(countOfUnreadMessages()))
|
||||
.replace(PLACEHOLDER_ALL_COUNTS, QString::number(countOfAllMessages()));
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::EditRole:
|
||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||
return m_title;
|
||||
}
|
||||
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||
return countOfUnreadMessages();
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::DecorationRole:
|
||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||
return m_icon;
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||
return
|
||||
m_title + "\n" +
|
||||
tr("This is service account for standard RSS/RDF/ATOM feeds.");
|
||||
}
|
||||
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||
//: Tooltip for "unread" column of feed list.
|
||||
return tr("%n unread message(s).", 0, countOfUnreadMessages());
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::TextAlignmentRole:
|
||||
if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||
return Qt::AlignCenter;
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::FontRole:
|
||||
return countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont;
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,19 @@
|
||||
|
||||
#include "services/abstract/serviceroot.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
|
||||
class StandardServiceRoot : public ServiceRoot {
|
||||
Q_DECLARE_TR_FUNCTIONS(StandardServiceRoot)
|
||||
|
||||
public:
|
||||
explicit StandardServiceRoot(RootItem *parent = NULL);
|
||||
virtual ~StandardServiceRoot();
|
||||
|
||||
bool canBeEdited();
|
||||
bool canBeDeleted();
|
||||
QVariant data(int column, int role) const;
|
||||
};
|
||||
|
||||
#endif // STANDARDSERVICEROOT_H
|
||||
|
@ -17,10 +17,95 @@
|
||||
|
||||
#include "services/tt-rss/ttrssserviceroot.h"
|
||||
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/settings.h"
|
||||
#include "services/tt-rss/ttrssserviceentrypoint.h"
|
||||
|
||||
|
||||
TtRssServiceRoot::TtRssServiceRoot(RootItem *parent) : ServiceRoot(parent) {
|
||||
// TODO: nadpis se bude měnit podle nastavení uživatelského
|
||||
// jména a serveru tohoto ttrss učtu
|
||||
m_title = qApp->system()->getUsername() + "@ttrss";
|
||||
m_icon = TtRssServiceEntryPoint().icon();
|
||||
}
|
||||
|
||||
TtRssServiceRoot::~TtRssServiceRoot() {
|
||||
}
|
||||
|
||||
void TtRssServiceRoot::editViaDialog() {
|
||||
// TODO: zobrazit custom edit dialog pro ttrss
|
||||
}
|
||||
|
||||
bool TtRssServiceRoot::canBeEdited() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TtRssServiceRoot::canBeDeleted() {
|
||||
return true;
|
||||
}
|
||||
|
||||
QVariant TtRssServiceRoot::data(int column, int role) const {
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||
return m_title;
|
||||
}
|
||||
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||
return qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::CountFormat)).toString()
|
||||
.replace(PLACEHOLDER_UNREAD_COUNTS, QString::number(countOfUnreadMessages()))
|
||||
.replace(PLACEHOLDER_ALL_COUNTS, QString::number(countOfAllMessages()));
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::EditRole:
|
||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||
return m_title;
|
||||
}
|
||||
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||
return countOfUnreadMessages();
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::DecorationRole:
|
||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||
return m_icon;
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
// TODO: zobrazovat pokročile informace a statistiky.
|
||||
if (column == FDS_MODEL_TITLE_INDEX) {
|
||||
return
|
||||
m_title + "\n" +
|
||||
tr("This is service account TT-RSS (TinyTiny RSS) server.");
|
||||
}
|
||||
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||
//: Tooltip for "unread" column of feed list.
|
||||
return tr("%n unread message(s).", 0, countOfUnreadMessages());
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::TextAlignmentRole:
|
||||
if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||
return Qt::AlignCenter;
|
||||
}
|
||||
else {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::FontRole:
|
||||
return countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont;
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,20 @@
|
||||
|
||||
#include "services/abstract/serviceroot.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
|
||||
class TtRssServiceRoot : public ServiceRoot {
|
||||
Q_DECLARE_TR_FUNCTIONS(StandardServiceRoot)
|
||||
|
||||
public:
|
||||
explicit TtRssServiceRoot(RootItem *parent = NULL);
|
||||
virtual ~TtRssServiceRoot();
|
||||
|
||||
bool canBeEdited();
|
||||
bool canBeDeleted();
|
||||
void editViaDialog();
|
||||
QVariant data(int column, int role) const;
|
||||
};
|
||||
|
||||
#endif // TTRSSSERVICEROOT_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user