Finalized uncrustify config, will reformat it all.

This commit is contained in:
Martin Rotter 2017-09-19 09:02:51 +02:00
parent 7b62a456a6
commit dd4a96f51f
15 changed files with 2304 additions and 1986 deletions

View File

@ -3,6 +3,10 @@
set FOR foreach set FOR foreach
set FOR forever set FOR forever
# SIGNAL/SLOT Qt macros have special formatting options. See options_for_QT.cpp for details.
# Default=True
use_options_overriding_for_qt_macros = true # false/true
## General. ## General.
newlines = auto # auto/lf/crlf/cr newlines = auto # auto/lf/crlf/cr
@ -13,10 +17,270 @@ input_tab_size = 2 # number
# The size of tabs in the output (only used if align_with_tabs=true) # The size of tabs in the output (only used if align_with_tabs=true)
output_tab_size = 2 # number output_tab_size = 2 # number
# Control what to do with the UTF-8 BOM (recommend 'remove')
utf8_bom = remove # ignore/add/remove/force
## Spaces. ## Spaces.
# Add or remove space around arithmetic operator '+', '-', '/', '*', etc
# also '>>>' '<<' '>>' '%' '|'
sp_arith = force # ignore/add/remove/force
# Add or remove space around assignment operator '=', '+=', etc
sp_assign = force # ignore/add/remove/force
# Add or remove space after ','
sp_after_comma = force # ignore/add/remove/force
# Add or remove space around '=' in C++11 lambda capture specifications. Overrides sp_assign
sp_cpp_lambda_assign = remove # ignore/add/remove/force
# Add or remove space after the capture specification in C++11 lambda.
sp_cpp_lambda_paren = remove # ignore/add/remove/force
# Add or remove space around assignment operator '=' in a prototype
sp_assign_default = force # ignore/add/remove/force
# Add or remove space around assignment '=' in enum
sp_enum_assign = force # ignore/add/remove/force
# Add or remove space before pointer star '*'
sp_before_ptr_star = remove # ignore/add/remove/force
# Add or remove space before pointer star '*' that isn't followed by a variable name
# If set to 'ignore', sp_before_ptr_star is used instead.
sp_before_unnamed_ptr_star = remove # ignore/add/remove/force
# Add or remove space between pointer stars '*'
sp_between_ptr_star = remove # ignore/add/remove/force
# Add or remove space after pointer star '*', if followed by a word.
sp_after_ptr_star = force # ignore/add/remove/force
# Add or remove space after pointer star '*', if followed by a qualifier.
sp_after_ptr_star_qualifier = force # ignore/add/remove/force
# Add or remove space after a pointer star '*', if followed by a func proto/def.
sp_after_ptr_star_func = force # ignore/add/remove/force
# Add or remove space after a pointer star '*', if followed by an open paren (function types).
sp_ptr_star_paren = force # ignore/add/remove/force
# Add or remove space before a pointer star '*', if followed by a func proto/def.
sp_before_ptr_star_func = remove # ignore/add/remove/force
# Add or remove space before a reference sign '&'
sp_before_byref = remove # ignore/add/remove/force
# Add or remove space before a reference sign '&' that isn't followed by a variable name
# If set to 'ignore', sp_before_byref is used instead.
sp_before_unnamed_byref = remove # ignore/add/remove/force
# Add or remove space after reference sign '&', if followed by a word.
sp_after_byref = force # ignore/add/remove/force
# Add or remove space after a reference sign '&', if followed by a func proto/def.
sp_after_byref_func = force # ignore/add/remove/force
# Add or remove space before a reference sign '&', if followed by a func proto/def.
sp_before_byref_func = remove # ignore/add/remove/force
# Add or remove space between '>' and '>' in '>>' (template stuff C++/C# only). Default=Add
sp_angle_shift = remove # ignore/add/remove/force
# Permit removal of the space between '>>' in 'foo<bar<int> >' (C++11 only). Default=False
# sp_angle_shift cannot remove the space without this option.
sp_permit_cpp11_shift = true # false/true
## Indents. ## Indents.
# The number of columns to indent per level.
# Usually 2, 3, 4, or 8. Default=8
indent_columns = 2 # unsigned number
# How to use tabs when indenting code
# 0=spaces only
# 1=indent with tabs to brace level, align with spaces (default)
# 2=indent and align with tabs, using spaces when not on a tabstop
indent_with_tabs = 0 # number
# Whether to indent strings broken by '\' so that they line up
indent_align_string = true # false/true
# Whether the 'namespace' body is indented
indent_namespace = true # false/true
# Whether the 'class' body is indented
indent_class = true # false/true
# Same as indent_label, but for access specifiers that are followed by a colon. Default=1
indent_access_spec = 2 # number
# Indent the code after an access specifier by one level.
# If set, this option forces 'indent_access_spec=0'
indent_access_spec_body = true # false/true
# Spaces to indent 'case' from 'switch'
# Usually 0 or indent_columns.
indent_switch_case = 2 # unsigned number
# indent the continuation of ternary operator.
# 0: (Default) off
# 1: When the `if_false` is a continuation, indent it under `if_false`
# 2: When the `:` is a continuation, indent it under `?`
indent_ternary_operator = 2 # unsigned number
## Newlines.
# Whether to collapse empty blocks between '{' and '}'
nl_collapse_empty_body = true # false/true
# Add or remove newlines at the start of the file
nl_start_of_file = remove # ignore/add/remove/force
# The number of blank lines after a block of variable definitions at the top of a function body
# 0 = No change (default)
nl_func_var_def_blk = 1 # unsigned number
# The number of newlines before a block of typedefs
# 0 = No change (default)
# the option 'nl_after_access_spec' takes preference over 'nl_typedef_blk_start'
nl_typedef_blk_start = 2 # unsigned number
# The number of newlines after a block of typedefs
# 0 = No change (default)
nl_typedef_blk_end = 2 # unsigned number
# The maximum consecutive newlines within a block of typedefs
# 0 = No change (default)
nl_typedef_blk_in = 2 # unsigned number
# The number of newlines after a block of variable definitions not at the top of a function body
# 0 = No change (default)
nl_var_def_blk_end = 2 # unsigned number
# The maximum consecutive newlines within a block of variable definitions
# 0 = No change (default)
nl_var_def_blk_in = 1 # unsigned number
# Add or remove newline between 'enum' and '{'
nl_enum_brace = remove # ignore/add/remove/force
# Add or remove newline between 'enum' and 'class'
nl_enum_class = remove # ignore/add/remove/force
# Add or remove newline between 'enum class' and the identifier
nl_enum_class_identifier = remove # ignore/add/remove/force
# Add or remove newline between 'if' and '{'
nl_if_brace = remove # ignore/add/remove/force
# Add or remove newline between '}' and 'else'
nl_brace_else = force # ignore/add/remove/force
# Add or remove newline between 'else' and '{'
nl_else_brace = remove # ignore/add/remove/force
# Add or remove newline between 'else' and 'if'
nl_else_if = remove # ignore/add/remove/force
# Add or remove newline before 'if'/'else if' closing parenthesis
nl_before_if_closing_paren = remove # ignore/add/remove/force
# Whether to put a newline after 'case' statement
nl_after_case = false # false/true
# Whether to put a newline before 'case' statement, not after the first 'case'
nl_before_case = true # false/true
# Whether to remove blanks after '#ifxx' and '#elxx', or before '#elxx' and '#endif'. Does not affect top-level #ifdefs.
nl_squeeze_ifdef = true # false/true
# Add or remove blank line after 'if' statement.
# Add/Force work only if the next token is not a closing brace
nl_after_if = force # ignore/add/remove/force
# Add or remove blank line after 'for' statement
nl_after_for = force # ignore/add/remove/force
# Add or remove blank line after 'while' statement
nl_after_while = force # ignore/add/remove/force
# Add or remove blank line after 'switch' statement
nl_after_switch = force # ignore/add/remove/force
# Add or remove blank line after 'do/while' statement
nl_after_do = force # ignore/add/remove/force
## Blank line options
# The maximum consecutive newlines (3 = 2 blank lines)
nl_max = 2 # unsigned number
# The minimum number of newlines before a multi-line comment.
# Doesn't apply if after a brace open or another multi-line comment.
nl_before_block_comment = 2 # unsigned number
# The minimum number of newlines before a single-line C comment.
# Doesn't apply if after a brace open or other single-line C comments.
nl_before_c_comment = 2 # unsigned number
# The minimum number of newlines before a CPP comment.
# Doesn't apply if after a brace open or other CPP comments.
nl_before_cpp_comment = 2 # unsigned number
# The number of newlines before a class definition
nl_before_class = 2 # unsigned number
# The number of newlines after '}' or ';' of a class definition
nl_after_class = 2 # unsigned number
# The number of newlines after '}' of a multi-line function body
nl_after_func_body = 2 # unsigned number
# The number of newlines after '}' of a multi-line function body in a class declaration
nl_after_func_body_class = 2 # unsigned number
# The number of newlines after '}' of a single line function body
nl_after_func_body_one_liner = 2 # unsigned number
# The number of newlines before a 'private:', 'public:', 'protected:', 'signals:', or 'slots:' label.
# Will not change the newline count if after a brace open.
# 0 = No change.
nl_before_access_spec = 2 # unsigned number
# The number of newlines after a try-catch-finally block that isn't followed by a brace close.
# 0 = No change.
nl_after_try_catch_finally = 2 # unsigned number
# How aggressively to remove extra newlines not in preproc.
# 0: No change
# 1: Remove most newlines not handled by other config
# 2: Remove all newlines and reformat completely by config
nl_remove_extra_newlines = 0 # unsigned number
## Splitting.
# Try to limit code width to N number of columns
code_width = 140 # unsigned number
# Whether to fully split long function protos/calls at commas
ls_func_split_full = true # false/true
## Comments.
# Set the comment reflow mode (Default=0)
# 0: no reflowing (apart from the line wrapping due to cmt_width)
# 1: no touching at all
# 2: full reflow
cmt_reflow_mode = 2 # number
# Whether to convert all tabs to spaces in comments. Default is to leave tabs inside comments alone, unless used for indenting.
cmt_convert_tab_to_spaces = true # false/true
# Whether to group c-comments that look like they are in a block
cmt_c_group = true # false/true
## Modifications. ## Modifications.
# If True, will sort consecutive single-line '#include' statements [C/C++] and '#import' statements [Obj-C] # If True, will sort consecutive single-line '#include' statements [C/C++] and '#import' statements [Obj-C]

View File

@ -1,4 +1,5 @@
// This file is part of RSS Guard. // This file is part of RSS Guard.
// //
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com> // Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// //
@ -18,45 +19,50 @@
#include "core/feedsmodel.h" #include "core/feedsmodel.h"
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "services/abstract/feed.h" #include "miscellaneous/databasefactory.h"
#include "miscellaneous/feedreader.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h"
#include "services/abstract/category.h" #include "services/abstract/category.h"
#include "services/abstract/serviceroot.h" #include "services/abstract/feed.h"
#include "services/abstract/recyclebin.h" #include "services/abstract/recyclebin.h"
#include "services/abstract/serviceentrypoint.h" #include "services/abstract/serviceentrypoint.h"
#include "services/abstract/serviceroot.h"
#include "services/standard/standardserviceentrypoint.h" #include "services/standard/standardserviceentrypoint.h"
#include "services/standard/standardserviceroot.h" #include "services/standard/standardserviceroot.h"
#include "miscellaneous/textfactory.h"
#include "miscellaneous/databasefactory.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/feedreader.h"
#include <QMimeData>
#include <QPair>
#include <QSqlError> #include <QSqlError>
#include <QSqlRecord> #include <QSqlRecord>
#include <QPair>
#include <QStack> #include <QStack>
#include <QMimeData>
#include <QTimer> #include <QTimer>
#include <algorithm> #include <algorithm>
FeedsModel::FeedsModel(QObject* parent) : QAbstractItemModel(parent) { 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() {
qDebug("Destroying FeedsModel instance."); qDebug("Destroying FeedsModel instance.");
// Delete all model items. // Delete all model items.
delete m_rootItem; delete m_rootItem;
} }
@ -79,6 +85,7 @@ QMimeData* FeedsModel::mimeData(const QModelIndexList& indexes) const {
} }
mime_data->setData(QSL(MIME_TYPE_ITEM_POINTER), encoded_data); mime_data->setData(QSL(MIME_TYPE_ITEM_POINTER), encoded_data);
return mime_data; return mime_data;
} }
@ -86,7 +93,8 @@ QStringList FeedsModel::mimeTypes() const {
return QStringList() << QSL(MIME_TYPE_ITEM_POINTER); return QStringList() << QSL(MIME_TYPE_ITEM_POINTER);
} }
bool FeedsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) { bool FeedsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
const QModelIndex& parent) {
Q_UNUSED(row) Q_UNUSED(row)
Q_UNUSED(column) Q_UNUSED(column)
@ -106,8 +114,8 @@ bool FeedsModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int
QDataStream stream(&dragged_items_data, QIODevice::ReadOnly); QDataStream stream(&dragged_items_data, QIODevice::ReadOnly);
while (!stream.atEnd()) { while (!stream.atEnd()) {
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);
@ -148,9 +156,11 @@ Qt::DropActions FeedsModel::supportedDropActions() const {
} }
Qt::ItemFlags FeedsModel::flags(const QModelIndex& index) const { Qt::ItemFlags FeedsModel::flags(const QModelIndex& index) const {
Qt::ItemFlags base_flags = QAbstractItemModel::flags(index);
const RootItem* item_for_index = itemForIndex(index); const RootItem* item_for_index = itemForIndex(index);
Qt::ItemFlags base_flags = QAbstractItemModel::flags(index);
Qt::ItemFlags additional_flags = item_for_index->additionalFlags(); Qt::ItemFlags additional_flags = item_for_index->additionalFlags();
return base_flags | additional_flags; return base_flags | additional_flags;
} }
@ -244,6 +254,7 @@ void FeedsModel::removeItem(const QModelIndex& index) {
RootItem* deleting_item = itemForIndex(index); RootItem* deleting_item = itemForIndex(index);
QModelIndex parent_index = index.parent(); QModelIndex parent_index = index.parent();
RootItem* parent_item = deleting_item->parent(); RootItem* parent_item = deleting_item->parent();
beginRemoveRows(parent_index, index.row(), index.row()); beginRemoveRows(parent_index, index.row(), index.row());
parent_item->removeChild(deleting_item); parent_item->removeChild(deleting_item);
endRemoveRows(); endRemoveRows();
@ -257,6 +268,7 @@ void FeedsModel::removeItem(RootItem* deleting_item) {
QModelIndex index = indexForItem(deleting_item); QModelIndex index = indexForItem(deleting_item);
QModelIndex parent_index = index.parent(); QModelIndex parent_index = index.parent();
RootItem* parent_item = deleting_item->parent(); RootItem* parent_item = deleting_item->parent();
beginRemoveRows(parent_index, index.row(), index.row()); beginRemoveRows(parent_index, index.row(), index.row());
parent_item->removeChild(deleting_item); parent_item->removeChild(deleting_item);
endRemoveRows(); endRemoveRows();
@ -281,6 +293,7 @@ void FeedsModel::reassignNodeToNewParent(RootItem* original_node, RootItem* new_
} }
int new_index_of_item = new_parent->childCount(); int new_index_of_item = new_parent->childCount();
// ... and insert it under the new parent. // ... and insert it under the new parent.
beginInsertRows(indexForItem(new_parent), new_index_of_item, new_index_of_item); beginInsertRows(indexForItem(new_parent), new_index_of_item, new_index_of_item);
new_parent->appendChild(original_node); new_parent->appendChild(original_node);
@ -328,10 +341,12 @@ 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);
} }
@ -366,8 +381,7 @@ QList<Message>FeedsModel::messagesForItem(RootItem* item) const {
} }
int FeedsModel::columnCount(const QModelIndex& parent) const { int FeedsModel::columnCount(const QModelIndex& parent) const {
Q_UNUSED(parent) Q_UNUSED(parent) return FEEDS_VIEW_COLUMN_COUNT;
return FEEDS_VIEW_COLUMN_COUNT;
} }
RootItem* FeedsModel::itemForIndex(const QModelIndex& index) const { RootItem* FeedsModel::itemForIndex(const QModelIndex& index) const {
@ -381,6 +395,7 @@ RootItem* FeedsModel::itemForIndex(const QModelIndex& index) const {
QModelIndex FeedsModel::indexForItem(const RootItem* item) const { QModelIndex FeedsModel::indexForItem(const RootItem* item) const {
if (item == nullptr || item->kind() == RootItemKind::Root) { if (item == nullptr || item->kind() == RootItemKind::Root) {
// Root item lies on invalid index. // Root item lies on invalid index.
return QModelIndex(); return QModelIndex();
} }
@ -398,7 +413,10 @@ QModelIndex FeedsModel::indexForItem(const RootItem* item) const {
// We go through the stack and create our target index. // We go through the stack and create our target index.
while (!chain.isEmpty()) { while (!chain.isEmpty()) {
const RootItem* parent_item = chain.pop(); const RootItem* parent_item = chain.pop();
target_index = index(parent_item->parent()->childItems().indexOf(const_cast<RootItem* const>(parent_item)), 0, target_index);
target_index = index(parent_item->parent()->childItems().indexOf(const_cast<RootItem* const>(parent_item)),
0,
target_index);
} }
return target_index; return target_index;
@ -424,16 +442,17 @@ void FeedsModel::reloadChangedLayout(QModelIndexList list) {
if (indx.isValid()) { if (indx.isValid()) {
QModelIndex indx_parent = indx.parent(); QModelIndex indx_parent = indx.parent();
// Underlying data are changed. // Underlying data are changed.
emit dataChanged(index(indx.row(), 0, indx_parent), index(indx.row(), FDS_MODEL_COUNTS_INDEX, indx_parent)); emit dataChanged(index(indx.row(), 0, indx_parent), index(indx.row(), FDS_MODEL_COUNTS_INDEX, indx_parent));
list.append(indx_parent); list.append(indx_parent);
} }
} }
} }
void FeedsModel::reloadChangedItem(RootItem* item) { void FeedsModel::reloadChangedItem(RootItem* item) {
QModelIndex index_item = indexForItem(item); reloadChangedLayout(QModelIndexList() << indexForItem(item));
reloadChangedLayout(QModelIndexList() << index_item);
} }
void FeedsModel::notifyWithCounts() { void FeedsModel::notifyWithCounts() {
@ -463,9 +482,11 @@ void FeedsModel::reloadWholeLayout() {
bool FeedsModel::addServiceAccount(ServiceRoot* root, bool freshly_activated) { bool FeedsModel::addServiceAccount(ServiceRoot* root, bool freshly_activated) {
int new_row_index = m_rootItem->childCount(); int new_row_index = m_rootItem->childCount();
beginInsertRows(indexForItem(m_rootItem), new_row_index, new_row_index); beginInsertRows(indexForItem(m_rootItem), new_row_index, new_row_index);
m_rootItem->appendChild(root); m_rootItem->appendChild(root);
endInsertRows(); endInsertRows();
// Connect. // Connect.
connect(root, &ServiceRoot::itemRemovalRequested, this, static_cast<void (FeedsModel::*)(RootItem*)>(&FeedsModel::removeItem)); connect(root, &ServiceRoot::itemRemovalRequested, this, static_cast<void (FeedsModel::*)(RootItem*)>(&FeedsModel::removeItem));
connect(root, &ServiceRoot::itemReassignmentRequested, this, &FeedsModel::reassignNodeToNewParent); connect(root, &ServiceRoot::itemReassignmentRequested, this, &FeedsModel::reassignNodeToNewParent);
@ -474,6 +495,7 @@ bool FeedsModel::addServiceAccount(ServiceRoot* root, bool freshly_activated) {
connect(root, &ServiceRoot::itemExpandRequested, this, &FeedsModel::itemExpandRequested); connect(root, &ServiceRoot::itemExpandRequested, this, &FeedsModel::itemExpandRequested);
connect(root, &ServiceRoot::itemExpandStateSaveRequested, this, &FeedsModel::itemExpandStateSaveRequested); connect(root, &ServiceRoot::itemExpandStateSaveRequested, this, &FeedsModel::itemExpandStateSaveRequested);
root->start(freshly_activated); root->start(freshly_activated);
return true; return true;
} }

View File

@ -1,4 +1,5 @@
// This file is part of RSS Guard. // This file is part of RSS Guard.
// //
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com> // Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// //
@ -20,7 +21,6 @@
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include "core/message.h"
#include "services/abstract/rootitem.h" #include "services/abstract/rootitem.h"
class Category; class Category;
@ -33,7 +33,6 @@ class FeedsModel : public QAbstractItemModel {
Q_OBJECT Q_OBJECT
public: public:
// Constructors and destructors.
explicit FeedsModel(QObject* parent = 0); explicit FeedsModel(QObject* parent = 0);
virtual ~FeedsModel(); virtual ~FeedsModel();
@ -45,6 +44,7 @@ class FeedsModel : public QAbstractItemModel {
// Drag & drop. // Drag & drop.
QMimeData* mimeData(const QModelIndexList& indexes) const; QMimeData* mimeData(const QModelIndexList& indexes) const;
QStringList mimeTypes() const; QStringList mimeTypes() const;
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent); bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
Qt::DropActions supportedDropActions() const; Qt::DropActions supportedDropActions() const;
@ -106,7 +106,6 @@ class FeedsModel : public QAbstractItemModel {
RootItem* rootItem() const; RootItem* rootItem() const;
public slots: public slots:
// Loads feed/categories from the database.
void loadActivatedServiceAccounts(); void loadActivatedServiceAccounts();
// Stops all accounts before exit. // Stops all accounts before exit.
@ -155,7 +154,6 @@ class FeedsModel : public QAbstractItemModel {
void onItemDataChanged(const QList<RootItem*>& items); void onItemDataChanged(const QList<RootItem*>& items);
signals: signals:
// Emitted if counts of messages are changed.
void messageCountsChanged(int unread_messages, bool any_feed_has_unread_messages); void messageCountsChanged(int unread_messages, bool any_feed_has_unread_messages);
// Emitted if any item requested that any view should expand it. // Emitted if any item requested that any view should expand it.
@ -174,8 +172,9 @@ class FeedsModel : public QAbstractItemModel {
private: private:
RootItem* m_rootItem; RootItem* m_rootItem;
QList<QString>m_headerData;
QList<QString>m_tooltipData; QList<QString> m_headerData;
QList<QString> m_tooltipData;
QIcon m_countsIcon; QIcon m_countsIcon;
}; };

View File

@ -220,7 +220,6 @@
#endif #endif
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
#define APP_DESKTOP_SOURCE_ENTRY_FILE "rssguard.desktop.autostart" #define APP_DESKTOP_SOURCE_ENTRY_FILE "rssguard.desktop.autostart"
#define APP_DESKTOP_ENTRY_FILE "rssguard.desktop" #define APP_DESKTOP_ENTRY_FILE "rssguard.desktop"
@ -233,9 +232,7 @@
#define APP_ICON_PATH QApplication::applicationDirPath() + QString("/../share/pixmaps/rssguard.png") #define APP_ICON_PATH QApplication::applicationDirPath() + QString("/../share/pixmaps/rssguard.png")
#define APP_ICON_PLAIN_PATH QApplication::applicationDirPath() + QString("/../share/rssguard/icons/rssguard_plain.png") #define APP_ICON_PLAIN_PATH QApplication::applicationDirPath() + QString("/../share/rssguard/icons/rssguard_plain.png")
#define APP_INITIAL_FEEDS_PATH QApplication::applicationDirPath() + QString("/../share/rssguard/initial_feeds") #define APP_INITIAL_FEEDS_PATH QApplication::applicationDirPath() + QString("/../share/rssguard/initial_feeds")
#elif defined(Q_OS_OSX) #elif defined(Q_OS_OSX)
#define APP_LANG_PATH QApplication::applicationDirPath() + QString("/../Resources/translations") #define APP_LANG_PATH QApplication::applicationDirPath() + QString("/../Resources/translations")
#define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/../Resources/skins") #define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/../Resources/skins")
#define APP_INFO_PATH QApplication::applicationDirPath() + QString("/../Resources/information") #define APP_INFO_PATH QApplication::applicationDirPath() + QString("/../Resources/information")
@ -245,9 +242,7 @@
#define APP_INFO_PATH QApplication::applicationDirPath() + QString("/../Resources/information") #define APP_INFO_PATH QApplication::applicationDirPath() + QString("/../Resources/information")
#define APP_ICON_PLAIN_PATH QApplication::applicationDirPath() + QString("/../Resources/icons/rssguard_plain.png") #define APP_ICON_PLAIN_PATH QApplication::applicationDirPath() + QString("/../Resources/icons/rssguard_plain.png")
#define APP_INITIAL_FEEDS_PATH QApplication::applicationDirPath() + QString("/../Resources/initial_feeds") #define APP_INITIAL_FEEDS_PATH QApplication::applicationDirPath() + QString("/../Resources/initial_feeds")
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)
#define APP_LANG_PATH QApplication::applicationDirPath() + QString("/translations") #define APP_LANG_PATH QApplication::applicationDirPath() + QString("/translations")
#define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/skins") #define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/skins")
#define APP_INFO_PATH QApplication::applicationDirPath() #define APP_INFO_PATH QApplication::applicationDirPath()
@ -256,7 +251,6 @@
#define APP_ICON_PATH QApplication::applicationDirPath() + QString("/rssguard.png") #define APP_ICON_PATH QApplication::applicationDirPath() + QString("/rssguard.png")
#define APP_ICON_PLAIN_PATH QApplication::applicationDirPath() + QString("/rssguard_plain.png") #define APP_ICON_PLAIN_PATH QApplication::applicationDirPath() + QString("/rssguard_plain.png")
#define APP_INITIAL_FEEDS_PATH QApplication::applicationDirPath() + QString("/initial_feeds") #define APP_INITIAL_FEEDS_PATH QApplication::applicationDirPath() + QString("/initial_feeds")
#endif #endif
#endif // DEFINITIONS_H #endif // DEFINITIONS_H

View File

@ -1,4 +1,5 @@
// This file is part of RSS Guard. // This file is part of RSS Guard.
// //
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com> // Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// //
@ -17,16 +18,15 @@
#include "gui/dialogs/formabout.h" #include "gui/dialogs/formabout.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h"
#include "miscellaneous/settingsproperties.h"
#include "gui/guiutilities.h"
#include "exceptions/applicationexception.h" #include "exceptions/applicationexception.h"
#include "gui/guiutilities.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/settingsproperties.h"
#include "miscellaneous/textfactory.h"
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
FormAbout::FormAbout(QWidget* parent) : QDialog(parent) { FormAbout::FormAbout(QWidget* parent) : QDialog(parent) {
m_ui.setupUi(this); m_ui.setupUi(this);
m_ui.m_lblIcon->setPixmap(QPixmap(APP_ICON_PATH)); m_ui.m_lblIcon->setPixmap(QPixmap(APP_ICON_PATH));
@ -47,9 +47,7 @@ void FormAbout::loadSettingsAndPaths() {
m_ui.m_txtPathsSettingsType->setText(tr("NOT portable")); m_ui.m_txtPathsSettingsType->setText(tr("NOT portable"));
} }
m_ui.m_txtPathsDatabaseRoot->setText(QDir::toNativeSeparators(qApp->userDataFolder() + m_ui.m_txtPathsDatabaseRoot->setText(QDir::toNativeSeparators(qApp->userDataFolder() + QDir::separator() + QString(APP_DB_SQLITE_PATH)));
QDir::separator() +
QString(APP_DB_SQLITE_PATH)));
m_ui.m_txtPathsSettingsFile->setText(QDir::toNativeSeparators(qApp->settings()->fileName())); m_ui.m_txtPathsSettingsFile->setText(QDir::toNativeSeparators(qApp->settings()->fileName()));
m_ui.m_txtPathsSkinsRoot->setText(QDir::toNativeSeparators(qApp->skins()->customSkinBaseFolder())); m_ui.m_txtPathsSkinsRoot->setText(QDir::toNativeSeparators(qApp->skins()->customSkinBaseFolder()));
} }
@ -84,18 +82,12 @@ void FormAbout::loadLicenseAndInformation() {
} }
// Set other informative texts. // Set other informative texts.
m_ui.m_lblDesc->setText(tr("<b>%8</b><br>" m_ui.m_lblDesc->setText(tr("<b>%8</b><br>" "<b>Version:</b> %1 (built on %2/%3)<br>" "<b>Revision:</b> %4<br>" "<b>Build date:</b> %5<br>"
"<b>Version:</b> %1 (built on %2/%3)<br>" "<b>Qt:</b> %6 (compiled against %7)<br>").arg(
"<b>Revision:</b> %4<br>" qApp->applicationVersion(), APP_SYSTEM_NAME, APP_SYSTEM_VERSION, APP_REVISION,
"<b>Build date:</b> %5<br>" TextFactory
"<b>Qt:</b> %6 (compiled against %7)<br>").arg(qApp->applicationVersion(), ::parseDateTime(QString("%1 %2").arg(__DATE__, __TIME__)).toString(Qt::DefaultLocaleShortDate),
APP_SYSTEM_NAME, qVersion(), QT_VERSION_STR,
APP_SYSTEM_VERSION,
APP_REVISION,
TextFactory::parseDateTime(QString("%1 %2").arg(__DATE__,
__TIME__)).toString(Qt::DefaultLocaleShortDate),
qVersion(),
QT_VERSION_STR,
APP_NAME)); APP_NAME));
m_ui.m_txtInfo->setText(tr("<body>%5 is a (very) tiny feed reader." m_ui.m_txtInfo->setText(tr("<body>%5 is a (very) tiny feed reader."
"<br><br>This software is distributed under the terms of GNU General Public License, version 3." "<br><br>This software is distributed under the terms of GNU General Public License, version 3."
@ -103,9 +95,8 @@ void FormAbout::loadLicenseAndInformation() {
"<ul><li><a href=\"mailto://%1\">%1</a> ~e-mail</li>" "<ul><li><a href=\"mailto://%1\">%1</a> ~e-mail</li>"
"<li><a href=\"%2\">%2</a> ~website</li></ul>" "<li><a href=\"%2\">%2</a> ~website</li></ul>"
"You can obtain source code for %5 from its website." "You can obtain source code for %5 from its website."
"<br><br><br>Copyright (C) 2011-%3 %4</body>").arg(APP_EMAIL, "<br><br><br>Copyright (C) 2011-%3 %4</body>").arg(APP_EMAIL, APP_URL,
APP_URL, QString
QString::number(QDateTime::currentDateTime().date().year()), ::number(QDateTime::currentDateTime().date().year()),
APP_AUTHOR, APP_AUTHOR, APP_NAME));
APP_NAME));
} }

View File

@ -1,4 +1,5 @@
// This file is part of RSS Guard. // This file is part of RSS Guard.
// //
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com> // Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// //
@ -17,22 +18,21 @@
#include "gui/dialogs/formrestoredatabasesettings.h" #include "gui/dialogs/formrestoredatabasesettings.h"
#include "gui/messagebox.h"
#include "gui/dialogs/formmain.h"
#include "miscellaneous/iconfactory.h"
#include "exceptions/applicationexception.h" #include "exceptions/applicationexception.h"
#include "gui/dialogs/formmain.h"
#include "gui/messagebox.h"
#include "miscellaneous/iconfactory.h"
#include "QFileDialog" #include "QFileDialog"
FormRestoreDatabaseSettings::FormRestoreDatabaseSettings(QWidget& parent) : QDialog(&parent),
FormRestoreDatabaseSettings::FormRestoreDatabaseSettings(QWidget& parent) m_shouldRestart(false) {
: QDialog(&parent), m_shouldRestart(false) {
m_ui.setupUi(this); m_ui.setupUi(this);
m_btnRestart = m_ui.m_buttonBox->addButton(tr("Restart"), QDialogButtonBox::ActionRole); m_btnRestart = m_ui.m_buttonBox->addButton(tr("Restart"), QDialogButtonBox::ActionRole);
m_ui.m_lblResult->setStatus(WidgetWithStatus::Warning, tr("No operation executed yet."), tr("No operation executed yet.")); m_ui.m_lblResult->setStatus(WidgetWithStatus::Warning, tr("No operation executed yet."), tr("No operation executed yet."));
setWindowIcon(qApp->icons()->fromTheme(QSL("document-import"))); setWindowIcon(qApp->icons()->fromTheme(QSL("document-import")));
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint); setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
connect(m_btnRestart, &QPushButton::clicked, this, [ = ]() { connect(m_btnRestart, &QPushButton::clicked, this, [=]() {
m_shouldRestart = true; m_shouldRestart = true;
close(); close();
}); });
@ -53,12 +53,10 @@ void FormRestoreDatabaseSettings::performRestoration() {
try { try {
qApp->restoreDatabaseSettings(m_ui.m_groupDatabase->isChecked(), qApp->restoreDatabaseSettings(m_ui.m_groupDatabase->isChecked(),
m_ui.m_groupSettings->isChecked(), m_ui.m_groupSettings->isChecked(),
m_ui.m_listDatabase->currentRow() >= 0 ? m_ui.m_listDatabase->currentRow() >= 0 ? m_ui.m_listDatabase->currentItem()->data(
m_ui.m_listDatabase->currentItem()->data(Qt::UserRole).toString() : Qt::UserRole).toString() : QString(),
QString(), m_ui.m_listSettings->currentRow() >= 0 ? m_ui.m_listSettings->currentItem()->data(
m_ui.m_listSettings->currentRow() >= 0 ? Qt::UserRole).toString() : QString());
m_ui.m_listSettings->currentItem()->data(Qt::UserRole).toString() :
QString());
m_btnRestart->setEnabled(true); m_btnRestart->setEnabled(true);
m_ui.m_lblResult->setStatus(WidgetWithStatus::Ok, tr("Restoration was initiated. Restart to proceed."), m_ui.m_lblResult->setStatus(WidgetWithStatus::Ok, tr("Restoration was initiated. Restart to proceed."),
tr("You need to restart application for restoration process to finish.")); tr("You need to restart application for restoration process to finish."));
@ -88,35 +86,33 @@ void FormRestoreDatabaseSettings::selectFolder(QString folder) {
} }
if (!folder.isEmpty()) { if (!folder.isEmpty()) {
m_ui.m_lblSelectFolder->setStatus(WidgetWithStatus::Ok, QDir::toNativeSeparators(folder), m_ui.m_lblSelectFolder->setStatus(WidgetWithStatus::Ok, QDir::toNativeSeparators(folder), tr("Good source directory is specified."));
tr("Good source directory is specified."));
} }
else { else {
return; return;
} }
const QDir selected_folder(folder); const QDir selected_folder(folder);
const QFileInfoList available_databases = selected_folder.entryInfoList(QStringList() const QFileInfoList available_databases = selected_folder.entryInfoList(QStringList() << QString("*") + BACKUP_SUFFIX_DATABASE,
<< QString("*") + BACKUP_SUFFIX_DATABASE, QDir::Files | QDir::NoDotAndDotDot | QDir::Readable | QDir::CaseSensitive | QDir::NoSymLinks,
QDir::Files | QDir::NoDotAndDotDot | QDir::Readable |
QDir::CaseSensitive | QDir::NoSymLinks,
QDir::Name); QDir::Name);
const QFileInfoList available_settings = selected_folder.entryInfoList(QStringList() const QFileInfoList available_settings = selected_folder.entryInfoList(QStringList() << QString("*") + BACKUP_SUFFIX_SETTINGS,
<< QString("*") + BACKUP_SUFFIX_SETTINGS, QDir::Files | QDir::NoDotAndDotDot | QDir::Readable | QDir::CaseSensitive | QDir::NoSymLinks,
QDir::Files | QDir::NoDotAndDotDot | QDir::Readable |
QDir::CaseSensitive | QDir::NoSymLinks,
QDir::Name); QDir::Name);
m_ui.m_listDatabase->clear(); m_ui.m_listDatabase->clear();
m_ui.m_listSettings->clear(); m_ui.m_listSettings->clear();
foreach (const QFileInfo& database_file, available_databases) { foreach (const QFileInfo& database_file, available_databases) {
QListWidgetItem* database_item = new QListWidgetItem(database_file.fileName(), m_ui.m_listDatabase); QListWidgetItem* database_item = new QListWidgetItem(database_file.fileName(), m_ui.m_listDatabase);
database_item->setData(Qt::UserRole, database_file.absoluteFilePath()); database_item->setData(Qt::UserRole, database_file.absoluteFilePath());
database_item->setToolTip(QDir::toNativeSeparators(database_file.absoluteFilePath())); database_item->setToolTip(QDir::toNativeSeparators(database_file.absoluteFilePath()));
} }
foreach (const QFileInfo& settings_file, available_settings) { foreach (const QFileInfo& settings_file, available_settings) {
QListWidgetItem* settings_item = new QListWidgetItem(settings_file.fileName(), m_ui.m_listSettings); QListWidgetItem* settings_item = new QListWidgetItem(settings_file.fileName(), m_ui.m_listSettings);
settings_item->setData(Qt::UserRole, settings_file.absoluteFilePath()); settings_item->setData(Qt::UserRole, settings_file.absoluteFilePath());
settings_item->setToolTip(QDir::toNativeSeparators(settings_file.absoluteFilePath())); settings_item->setToolTip(QDir::toNativeSeparators(settings_file.absoluteFilePath()));
} }

View File

@ -1,4 +1,5 @@
// This file is part of RSS Guard. // This file is part of RSS Guard.
// //
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com> // Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// //
@ -17,30 +18,30 @@
#include "gui/feedmessageviewer.h" #include "gui/feedmessageviewer.h"
#include "miscellaneous/settings.h"
#include "miscellaneous/databasefactory.h"
#include "miscellaneous/systemfactory.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/mutex.h"
#include "miscellaneous/databasecleaner.h"
#include "miscellaneous/feedreader.h"
#include "core/messagesproxymodel.h"
#include "core/feeddownloader.h" #include "core/feeddownloader.h"
#include "core/feedsproxymodel.h" #include "core/feedsproxymodel.h"
#include "services/standard/standardserviceroot.h" #include "core/messagesproxymodel.h"
#include "services/standard/standardfeed.h" #include "gui/feedstoolbar.h"
#include "services/standard/standardfeedsimportexportmodel.h"
#include "gui/messagesview.h"
#include "gui/feedsview.h" #include "gui/feedsview.h"
#include "gui/statusbar.h"
#include "gui/systemtrayicon.h"
#include "gui/messagebox.h" #include "gui/messagebox.h"
#include "gui/messagestoolbar.h" #include "gui/messagestoolbar.h"
#include "gui/feedstoolbar.h" #include "gui/messagesview.h"
#include "gui/statusbar.h"
#include "gui/systemtrayicon.h"
#include "miscellaneous/databasecleaner.h"
#include "miscellaneous/databasefactory.h"
#include "miscellaneous/feedreader.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/mutex.h"
#include "miscellaneous/settings.h"
#include "miscellaneous/systemfactory.h"
#include "services/standard/standardfeed.h"
#include "services/standard/standardfeedsimportexportmodel.h"
#include "services/standard/standardserviceroot.h"
#include "exceptions/applicationexception.h"
#include "gui/dialogs/formdatabasecleanup.h" #include "gui/dialogs/formdatabasecleanup.h"
#include "gui/dialogs/formmain.h" #include "gui/dialogs/formmain.h"
#include "exceptions/applicationexception.h"
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
#include "gui/webbrowser.h" #include "gui/webbrowser.h"
@ -48,34 +49,30 @@
#include "gui/messagepreviewer.h" #include "gui/messagepreviewer.h"
#endif #endif
#include <QVBoxLayout> #include <QAction>
#include <QSplitter>
#include <QToolBar>
#include <QDebug> #include <QDebug>
#include <QLineEdit> #include <QLineEdit>
#include <QAction>
#include <QToolButton>
#include <QMenu> #include <QMenu>
#include <QWidgetAction>
#include <QThread>
#include <QProgressBar>
#include <QStatusBar>
#include <QPointer> #include <QPointer>
#include <QProgressBar>
#include <QSplitter>
#include <QStatusBar>
#include <QThread>
#include <QToolBar>
#include <QToolButton>
#include <QVBoxLayout>
#include <QWidgetAction>
FeedMessageViewer::FeedMessageViewer(QWidget* parent) : TabContent(parent), m_toolBarsEnabled(true), m_listHeadersEnabled(true),
m_toolBarFeeds(new FeedsToolBar(tr("Toolbar for feeds"), this)), m_toolBarMessages(new MessagesToolBar(tr("Toolbar for messages"), this)),
m_messagesView(new MessagesView(this)), m_feedsView(new FeedsView(this)),
FeedMessageViewer::FeedMessageViewer(QWidget* parent)
: TabContent(parent),
m_toolBarsEnabled(true),
m_listHeadersEnabled(true),
m_toolBarFeeds(new FeedsToolBar(tr("Toolbar for feeds"), this)),
m_toolBarMessages(new MessagesToolBar(tr("Toolbar for messages"), this)),
m_messagesView(new MessagesView(this)),
m_feedsView(new FeedsView(this)),
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
m_messagesBrowser(new WebBrowser(this)) { m_messagesBrowser(new WebBrowser(this)) {
#else #else
m_messagesBrowser(new MessagePreviewer(this)) { m_messagesBrowser(new MessagePreviewer(this)) {
#endif #endif
initialize(); initialize();
initializeViews(); initializeViews();
loadMessageViewerFonts(); loadMessageViewerFonts();
@ -87,9 +84,11 @@ FeedMessageViewer::~FeedMessageViewer() {
} }
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
WebBrowser* FeedMessageViewer::webBrowser() const { WebBrowser* FeedMessageViewer::webBrowser() const {
return m_messagesBrowser; return m_messagesBrowser;
} }
#endif #endif
FeedsView* FeedMessageViewer::feedsView() const { FeedsView* FeedMessageViewer::feedsView() const {
@ -110,11 +109,14 @@ FeedsToolBar* FeedMessageViewer::feedsToolBar() const {
void FeedMessageViewer::saveSize() { void FeedMessageViewer::saveSize() {
Settings* settings = qApp->settings(); Settings* settings = qApp->settings();
m_feedsView->saveAllExpandStates(); m_feedsView->saveAllExpandStates();
// Store offsets of splitters. // Store offsets of splitters.
settings->setValue(GROUP(GUI), GUI::SplitterFeeds, QString(m_feedSplitter->saveState().toBase64())); settings->setValue(GROUP(GUI), GUI::SplitterFeeds, QString(m_feedSplitter->saveState().toBase64()));
settings->setValue(GROUP(GUI), GUI::SplitterMessages, QString(m_messageSplitter->saveState().toBase64())); settings->setValue(GROUP(GUI), GUI::SplitterMessages, QString(m_messageSplitter->saveState().toBase64()));
settings->setValue(GROUP(GUI), GUI::MessageViewState, QString(m_messagesView->header()->saveState().toBase64())); settings->setValue(GROUP(GUI), GUI::MessageViewState, QString(m_messagesView->header()->saveState().toBase64()));
// Store "visibility" of toolbars and list headers. // Store "visibility" of toolbars and list headers.
settings->setValue(GROUP(GUI), GUI::ToolbarsVisible, m_toolBarsEnabled); settings->setValue(GROUP(GUI), GUI::ToolbarsVisible, m_toolBarsEnabled);
settings->setValue(GROUP(GUI), GUI::ListHeadersVisible, m_listHeadersEnabled); settings->setValue(GROUP(GUI), GUI::ListHeadersVisible, m_listHeadersEnabled);
@ -122,6 +124,7 @@ void FeedMessageViewer::saveSize() {
void FeedMessageViewer::loadSize() { void FeedMessageViewer::loadSize() {
const Settings* settings = qApp->settings(); const Settings* settings = qApp->settings();
// Restore offsets of splitters. // Restore offsets of splitters.
m_feedSplitter->restoreState(QByteArray::fromBase64(settings->value(GROUP(GUI), SETTING(GUI::SplitterFeeds)).toString().toLocal8Bit())); m_feedSplitter->restoreState(QByteArray::fromBase64(settings->value(GROUP(GUI), SETTING(GUI::SplitterFeeds)).toString().toLocal8Bit()));
m_messageSplitter->restoreState(QByteArray::fromBase64(settings->value(GROUP(GUI), m_messageSplitter->restoreState(QByteArray::fromBase64(settings->value(GROUP(GUI),
@ -189,29 +192,27 @@ void FeedMessageViewer::createConnections() {
// Filtering & searching. // Filtering & searching.
connect(m_toolBarMessages, &MessagesToolBar::messageSearchPatternChanged, m_messagesView, &MessagesView::searchMessages); connect(m_toolBarMessages, &MessagesToolBar::messageSearchPatternChanged, m_messagesView, &MessagesView::searchMessages);
connect(m_toolBarMessages, &MessagesToolBar::messageFilterChanged, m_messagesView, &MessagesView::filterMessages); connect(m_toolBarMessages, &MessagesToolBar::messageFilterChanged, m_messagesView, &MessagesView::filterMessages);
#if defined(USE_WEBENGINE) #if defined(USE_WEBENGINE)
connect(m_messagesView, &MessagesView::currentMessageRemoved, m_messagesBrowser, &WebBrowser::clear); connect(m_messagesView, &MessagesView::currentMessageRemoved, m_messagesBrowser, &WebBrowser::clear);
connect(m_messagesView, &MessagesView::currentMessageChanged, m_messagesBrowser, &WebBrowser::loadMessage); connect(m_messagesView, &MessagesView::currentMessageChanged, m_messagesBrowser, &WebBrowser::loadMessage);
connect(m_messagesBrowser, &WebBrowser::markMessageRead, connect(m_messagesBrowser, &WebBrowser::markMessageRead, m_messagesView->sourceModel(), &MessagesModel::setMessageReadById);
m_messagesView->sourceModel(), &MessagesModel::setMessageReadById); connect(m_messagesBrowser, &WebBrowser::markMessageImportant, m_messagesView->sourceModel(), &MessagesModel::setMessageImportantById);
connect(m_messagesBrowser, &WebBrowser::markMessageImportant,
m_messagesView->sourceModel(), &MessagesModel::setMessageImportantById);
#else #else
connect(m_messagesView, &MessagesView::currentMessageRemoved, m_messagesBrowser, &MessagePreviewer::clear); connect(m_messagesView, &MessagesView::currentMessageRemoved, m_messagesBrowser, &MessagePreviewer::clear);
connect(m_messagesView, &MessagesView::currentMessageChanged, m_messagesBrowser, &MessagePreviewer::loadMessage); connect(m_messagesView, &MessagesView::currentMessageChanged, m_messagesBrowser, &MessagePreviewer::loadMessage);
connect(m_messagesBrowser, &MessagePreviewer::markMessageRead, connect(m_messagesBrowser, &MessagePreviewer::markMessageRead, m_messagesView->sourceModel(), &MessagesModel::setMessageReadById);
m_messagesView->sourceModel(), &MessagesModel::setMessageReadById); connect(m_messagesBrowser, &MessagePreviewer::markMessageImportant, m_messagesView->sourceModel(),
connect(m_messagesBrowser, &MessagePreviewer::markMessageImportant, &MessagesModel::setMessageImportantById);
m_messagesView->sourceModel(), &MessagesModel::setMessageImportantById);
#endif #endif
// If user selects feeds, load their messages. // If user selects feeds, load their messages.
connect(m_feedsView, &FeedsView::itemSelected, m_messagesView, &MessagesView::loadItem); connect(m_feedsView, &FeedsView::itemSelected, m_messagesView, &MessagesView::loadItem);
connect(m_feedsView, &FeedsView::requestViewNextUnreadMessage, m_messagesView, &MessagesView::selectNextUnreadItem); connect(m_feedsView, &FeedsView::requestViewNextUnreadMessage, m_messagesView, &MessagesView::selectNextUnreadItem);
// State of many messages is changed, then we need // State of many messages is changed, then we need
// to reload selections. // to reload selections.
connect(m_feedsView->sourceModel(), &FeedsModel::reloadMessageListRequested, connect(m_feedsView->sourceModel(), &FeedsModel::reloadMessageListRequested, m_messagesView, &MessagesView::reloadSelections);
m_messagesView, &MessagesView::reloadSelections);
} }
void FeedMessageViewer::initialize() { void FeedMessageViewer::initialize() {
@ -225,6 +226,7 @@ void FeedMessageViewer::initialize() {
m_toolBarFeeds->loadSavedActions(); m_toolBarFeeds->loadSavedActions();
m_toolBarMessages->loadSavedActions(); m_toolBarMessages->loadSavedActions();
m_messagesBrowser->clear(); m_messagesBrowser->clear();
// Now refresh visual setup. // Now refresh visual setup.
refreshVisualProperties(); refreshVisualProperties();
} }
@ -234,10 +236,12 @@ void FeedMessageViewer::initializeViews() {
m_messagesWidget = new QWidget(this); m_messagesWidget = new QWidget(this);
m_feedSplitter = new QSplitter(Qt::Horizontal, this); m_feedSplitter = new QSplitter(Qt::Horizontal, this);
m_messageSplitter = new QSplitter(Qt::Vertical, this); m_messageSplitter = new QSplitter(Qt::Vertical, this);
// Instantiate needed components. // Instantiate needed components.
QVBoxLayout* central_layout = new QVBoxLayout(this); QVBoxLayout* central_layout = new QVBoxLayout(this);
QVBoxLayout* feed_layout = new QVBoxLayout(m_feedsWidget); QVBoxLayout* feed_layout = new QVBoxLayout(m_feedsWidget);
QVBoxLayout* message_layout = new QVBoxLayout(m_messagesWidget); QVBoxLayout* message_layout = new QVBoxLayout(m_messagesWidget);
// Set layout properties. // Set layout properties.
central_layout->setMargin(0); central_layout->setMargin(0);
central_layout->setSpacing(0); central_layout->setSpacing(0);
@ -245,9 +249,11 @@ void FeedMessageViewer::initializeViews() {
feed_layout->setSpacing(0); feed_layout->setSpacing(0);
message_layout->setMargin(0); message_layout->setMargin(0);
message_layout->setSpacing(0); message_layout->setSpacing(0);
// Set views. // Set views.
m_feedsView->setFrameStyle(QFrame::NoFrame); m_feedsView->setFrameStyle(QFrame::NoFrame);
m_messagesView->setFrameStyle(QFrame::NoFrame); m_messagesView->setFrameStyle(QFrame::NoFrame);
// Setup message splitter. // Setup message splitter.
m_messageSplitter->setObjectName(QSL("MessageSplitter")); m_messageSplitter->setObjectName(QSL("MessageSplitter"));
m_messageSplitter->setHandleWidth(1); m_messageSplitter->setHandleWidth(1);
@ -255,18 +261,22 @@ void FeedMessageViewer::initializeViews() {
m_messageSplitter->setChildrenCollapsible(false); m_messageSplitter->setChildrenCollapsible(false);
m_messageSplitter->addWidget(m_messagesView); m_messageSplitter->addWidget(m_messagesView);
m_messageSplitter->addWidget(m_messagesBrowser); m_messageSplitter->addWidget(m_messagesBrowser);
// Assemble message-related components to single widget. // Assemble message-related components to single widget.
message_layout->addWidget(m_toolBarMessages); message_layout->addWidget(m_toolBarMessages);
message_layout->addWidget(m_messageSplitter); message_layout->addWidget(m_messageSplitter);
// Assemble feed-related components to another widget. // Assemble feed-related components to another widget.
feed_layout->addWidget(m_toolBarFeeds); feed_layout->addWidget(m_toolBarFeeds);
feed_layout->addWidget(m_feedsView); feed_layout->addWidget(m_feedsView);
// Assembler everything together. // Assembler everything together.
m_feedSplitter->setHandleWidth(1); m_feedSplitter->setHandleWidth(1);
m_feedSplitter->setOpaqueResize(false); m_feedSplitter->setOpaqueResize(false);
m_feedSplitter->setChildrenCollapsible(false); m_feedSplitter->setChildrenCollapsible(false);
m_feedSplitter->addWidget(m_feedsWidget); m_feedSplitter->addWidget(m_feedsWidget);
m_feedSplitter->addWidget(m_messagesWidget); m_feedSplitter->addWidget(m_messagesWidget);
// Add toolbar and main feeds/messages widget to main layout. // Add toolbar and main feeds/messages widget to main layout.
central_layout->addWidget(m_feedSplitter); central_layout->addWidget(m_feedSplitter);
setTabOrder(m_feedsView, m_messagesView); setTabOrder(m_feedsView, m_messagesView);
@ -276,8 +286,9 @@ void FeedMessageViewer::initializeViews() {
} }
void FeedMessageViewer::refreshVisualProperties() { void FeedMessageViewer::refreshVisualProperties() {
const Qt::ToolButtonStyle button_style = static_cast<Qt::ToolButtonStyle>(qApp->settings()->value(GROUP(GUI), const Qt::ToolButtonStyle button_style =
SETTING(GUI::ToolbarStyle)).toInt()); static_cast<Qt::ToolButtonStyle>(qApp->settings()->value(GROUP(GUI), SETTING(GUI::ToolbarStyle)).toInt());
m_toolBarFeeds->setToolButtonStyle(button_style); m_toolBarFeeds->setToolButtonStyle(button_style);
m_toolBarMessages->setToolButtonStyle(button_style); m_toolBarMessages->setToolButtonStyle(button_style);
} }

View File

@ -1,4 +1,5 @@
// This file is part of RSS Guard. // This file is part of RSS Guard.
// //
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com> // Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// //
@ -44,7 +45,6 @@ class FeedMessageViewer : public TabContent {
Q_OBJECT Q_OBJECT
public: public:
// Constructors and destructors.
explicit FeedMessageViewer(QWidget* parent = 0); explicit FeedMessageViewer(QWidget* parent = 0);
virtual ~FeedMessageViewer(); virtual ~FeedMessageViewer();
@ -61,9 +61,6 @@ class FeedMessageViewer : public TabContent {
bool areListHeadersEnabled() const; bool areListHeadersEnabled() const;
public slots: public slots:
// Loads/saves sizes and states of ALL
// underlying widgets, this contains primarily
// splitters, toolbar and views.
void saveSize(); void saveSize();
void loadSize(); void loadSize();
@ -87,7 +84,6 @@ class FeedMessageViewer : public TabContent {
void toggleShowOnlyUnreadFeeds(); void toggleShowOnlyUnreadFeeds();
protected: protected:
// Initializes some properties of the widget.
void initialize(); void initialize();
// Initializes both messages/feeds views. // Initializes both messages/feeds views.
@ -101,10 +97,8 @@ class FeedMessageViewer : public TabContent {
bool m_listHeadersEnabled; bool m_listHeadersEnabled;
FeedsToolBar* m_toolBarFeeds; FeedsToolBar* m_toolBarFeeds;
MessagesToolBar* m_toolBarMessages; MessagesToolBar* m_toolBarMessages;
QSplitter* m_feedSplitter; QSplitter* m_feedSplitter;
QSplitter* m_messageSplitter; QSplitter* m_messageSplitter;
MessagesView* m_messagesView; MessagesView* m_messagesView;
FeedsView* m_feedsView; FeedsView* m_feedsView;
QWidget* m_feedsWidget; QWidget* m_feedsWidget;

View File

@ -20,23 +20,22 @@
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include <QtGlobal> #include <QCheckBox>
#include <QDialogButtonBox>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QPushButton> #include <QPushButton>
#include <QDialogButtonBox>
#include <QStyle> #include <QStyle>
#include <QCheckBox> #include <QtGlobal>
MessageBox::MessageBox(QWidget* parent) : QMessageBox(parent) { MessageBox::MessageBox(QWidget* parent) : QMessageBox(parent) {}
}
MessageBox::~MessageBox() { MessageBox::~MessageBox() {}
}
void MessageBox::setIcon(QMessageBox::Icon icon) { void MessageBox::setIcon(QMessageBox::Icon icon) {
// Determine correct status icon size. // Determine correct status icon size.
const int icon_size = qApp->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this); const int icon_size = qApp->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, this);
// Setup status icon. // Setup status icon.
setIconPixmap(iconForStatus(icon).pixmap(icon_size, icon_size)); setIconPixmap(iconForStatus(icon).pixmap(icon_size, icon_size));
} }
@ -44,9 +43,10 @@ void MessageBox::setIcon(QMessageBox::Icon icon) {
void MessageBox::setCheckBox(QMessageBox* msg_box, const QString& text, bool* data) { void MessageBox::setCheckBox(QMessageBox* msg_box, const QString& text, bool* data) {
// Add "don't show this again checkbox. // Add "don't show this again checkbox.
QCheckBox* check_box = new QCheckBox(msg_box); QCheckBox* check_box = new QCheckBox(msg_box);
check_box->setChecked(*data); check_box->setChecked(*data);
check_box->setText(text); check_box->setText(text);
connect(check_box, &QCheckBox::toggled, [ = ](bool checked) { connect(check_box, &QCheckBox::toggled, [=](bool checked) {
*data = checked; *data = checked;
}); });
msg_box->setCheckBox(check_box); msg_box->setCheckBox(check_box);
@ -72,17 +72,12 @@ QIcon MessageBox::iconForStatus(QMessageBox::Icon status) {
} }
} }
QMessageBox::StandardButton MessageBox::show(QWidget* parent, QMessageBox::StandardButton MessageBox::show(QWidget* parent, QMessageBox::Icon icon, const QString& title, const QString& text,
QMessageBox::Icon icon, const QString& informative_text, const QString& detailed_text, QMessageBox::StandardButtons buttons,
const QString& title, QMessageBox::StandardButton default_button, bool* dont_show_again) {
const QString& text,
const QString& informative_text,
const QString& detailed_text,
QMessageBox::StandardButtons buttons,
QMessageBox::StandardButton default_button,
bool* dont_show_again) {
// Create and find needed components. // Create and find needed components.
MessageBox msg_box(parent); MessageBox msg_box(parent);
// Initialize message box properties. // Initialize message box properties.
msg_box.setWindowTitle(title); msg_box.setWindowTitle(title);
msg_box.setText(text); msg_box.setText(text);

View File

@ -1,5 +1,5 @@
// This file is part of RSS Guard. // This file is part of RSS Guard.
//
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com> // Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// //
// RSS Guard is free software: you can redistribute it and/or modify // RSS Guard is free software: you can redistribute it and/or modify
@ -17,36 +17,35 @@
#include "gui/messagesview.h" #include "gui/messagesview.h"
#include "core/messagesproxymodel.h"
#include "core/messagesmodel.h" #include "core/messagesmodel.h"
#include "miscellaneous/settings.h" #include "core/messagesproxymodel.h"
#include "gui/dialogs/formmain.h"
#include "gui/messagebox.h"
#include "gui/styleditemdelegatewithoutfocus.h"
#include "gui/treeviewcolumnsmenu.h"
#include "miscellaneous/externaltool.h"
#include "miscellaneous/feedreader.h" #include "miscellaneous/feedreader.h"
#include "miscellaneous/settings.h"
#include "network-web/networkfactory.h" #include "network-web/networkfactory.h"
#include "network-web/webfactory.h" #include "network-web/webfactory.h"
#include "gui/dialogs/formmain.h"
#include "miscellaneous/externaltool.h"
#include "gui/messagebox.h"
#include "gui/treeviewcolumnsmenu.h"
#include "gui/styleditemdelegatewithoutfocus.h"
#include <QFileIconProvider>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu>
#include <QProcess>
#include <QScrollBar> #include <QScrollBar>
#include <QTimer> #include <QTimer>
#include <QMenu>
#include <QFileIconProvider>
#include <QProcess>
MessagesView::MessagesView(QWidget* parent) : QTreeView(parent), m_contextMenu(nullptr), m_columnsAdjusted(false) {
MessagesView::MessagesView(QWidget* parent)
: QTreeView(parent), m_contextMenu(nullptr), m_columnsAdjusted(false) {
m_sourceModel = qApp->feedReader()->messagesModel(); m_sourceModel = qApp->feedReader()->messagesModel();
m_proxyModel = qApp->feedReader()->messagesProxyModel(); m_proxyModel = qApp->feedReader()->messagesProxyModel();
// Forward count changes to the view. // Forward count changes to the view.
createConnections(); createConnections();
setModel(m_proxyModel); setModel(m_proxyModel);
setupAppearance(); setupAppearance();
header()->setContextMenuPolicy(Qt::CustomContextMenu); header()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(header(), &QHeaderView::customContextMenuRequested, [ = ](const QPoint & point) { connect(header(), &QHeaderView::customContextMenuRequested, [=](const QPoint& point) {
TreeViewColumnsMenu mm(header()); TreeViewColumnsMenu mm(header());
mm.exec(header()->mapToGlobal(point)); mm.exec(header()->mapToGlobal(point));
}); });
@ -75,6 +74,7 @@ void MessagesView::sort(int column, Qt::SortOrder order, bool repopulate_data, b
void MessagesView::createConnections() { void MessagesView::createConnections() {
connect(this, &MessagesView::doubleClicked, this, &MessagesView::openSelectedSourceMessagesExternally); connect(this, &MessagesView::doubleClicked, this, &MessagesView::openSelectedSourceMessagesExternally);
// Adjust columns when layout gets changed. // Adjust columns when layout gets changed.
connect(header(), &QHeaderView::geometriesChanged, this, &MessagesView::adjustColumns); connect(header(), &QHeaderView::geometriesChanged, this, &MessagesView::adjustColumns);
connect(header(), &QHeaderView::sortIndicatorChanged, this, &MessagesView::onSortIndicatorChanged); connect(header(), &QHeaderView::sortIndicatorChanged, this, &MessagesView::onSortIndicatorChanged);
@ -95,6 +95,7 @@ void MessagesView::reloadSelections() {
const Message selected_message = m_sourceModel->messageAt(mapped_current_index.row()); const Message selected_message = m_sourceModel->messageAt(mapped_current_index.row());
const int col = header()->sortIndicatorSection(); const int col = header()->sortIndicatorSection();
const Qt::SortOrder ord = header()->sortIndicatorOrder(); const Qt::SortOrder ord = header()->sortIndicatorOrder();
// Reload the model now. // Reload the model now.
sort(col, ord, true, false, false); sort(col, ord, true, false, false);
@ -132,6 +133,7 @@ void MessagesView::reloadSelections() {
} }
const QDateTime dt2 = QDateTime::currentDateTime(); const QDateTime dt2 = QDateTime::currentDateTime();
qDebug("Reloading of msg selections took %lld miliseconds.", dt1.msecsTo(dt2)); qDebug("Reloading of msg selections took %lld miliseconds.", dt1.msecsTo(dt2));
} }
@ -168,6 +170,7 @@ void MessagesView::contextMenuEvent(QContextMenuEvent* event) {
if (!clicked_index.isValid()) { if (!clicked_index.isValid()) {
TreeViewColumnsMenu menu(header()); TreeViewColumnsMenu menu(header());
menu.exec(event->globalPos()); menu.exec(event->globalPos());
} }
else { else {
@ -186,6 +189,7 @@ void MessagesView::initializeContextMenu() {
QFileIconProvider icon_provider; QFileIconProvider icon_provider;
QMenu* menu = new QMenu(tr("Open with external tool"), m_contextMenu); QMenu* menu = new QMenu(tr("Open with external tool"), m_contextMenu);
menu->setIcon(qApp->icons()->fromTheme(QSL("document-open"))); menu->setIcon(qApp->icons()->fromTheme(QSL("document-open")));
foreach (const ExternalTool& tool, ExternalTool::toolsFromSettings()) { foreach (const ExternalTool& tool, ExternalTool::toolsFromSettings()) {
@ -201,19 +205,13 @@ void MessagesView::initializeContextMenu() {
if (menu->actions().isEmpty()) { if (menu->actions().isEmpty()) {
QAction* act_not_tools = new QAction("No external tools activated"); QAction* act_not_tools = new QAction("No external tools activated");
act_not_tools->setEnabled(false); act_not_tools->setEnabled(false);
menu->addAction(act_not_tools); menu->addAction(act_not_tools);
} }
m_contextMenu->addMenu(menu); m_contextMenu->addMenu(menu);
m_contextMenu->addActions(QList<QAction*>() << m_contextMenu->addActions(QList<QAction*>() << qApp->mainForm()->m_ui->m_actionSendMessageViaEmail << qApp->mainForm()->m_ui->m_actionOpenSelectedSourceArticlesExternally << qApp->mainForm()->m_ui->m_actionOpenSelectedMessagesInternally << qApp->mainForm()->m_ui->m_actionMarkSelectedMessagesAsRead << qApp->mainForm()->m_ui->m_actionMarkSelectedMessagesAsUnread << qApp->mainForm()->m_ui->m_actionSwitchImportanceOfSelectedMessages << qApp->mainForm()->m_ui->m_actionDeleteSelectedMessages);
qApp->mainForm()->m_ui->m_actionSendMessageViaEmail <<
qApp->mainForm()->m_ui->m_actionOpenSelectedSourceArticlesExternally <<
qApp->mainForm()->m_ui->m_actionOpenSelectedMessagesInternally <<
qApp->mainForm()->m_ui->m_actionMarkSelectedMessagesAsRead <<
qApp->mainForm()->m_ui->m_actionMarkSelectedMessagesAsUnread <<
qApp->mainForm()->m_ui->m_actionSwitchImportanceOfSelectedMessages <<
qApp->mainForm()->m_ui->m_actionDeleteSelectedMessages);
if (m_sourceModel->loadedItem() != nullptr && m_sourceModel->loadedItem()->kind() == RootItemKind::Bin) { if (m_sourceModel->loadedItem() != nullptr && m_sourceModel->loadedItem()->kind() == RootItemKind::Bin) {
m_contextMenu->addAction(qApp->mainForm()->m_ui->m_actionRestoreSelectedMessages); m_contextMenu->addAction(qApp->mainForm()->m_ui->m_actionRestoreSelectedMessages);
@ -268,16 +266,17 @@ void MessagesView::selectionChanged(const QItemSelection& selected, const QItemS
const QModelIndexList selected_rows = selectionModel()->selectedRows(); const QModelIndexList selected_rows = selectionModel()->selectedRows();
const QModelIndex current_index = currentIndex(); const QModelIndex current_index = currentIndex();
const QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index); const QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index);
qDebug("Current row changed - row [%d,%d] source [%d, %d].",
current_index.row(), current_index.column(), qDebug("Current row changed - row [%d,%d] source [%d, %d].",current_index.row(), current_index.column(),mapped_current_index.row(), mapped_current_index.column());
mapped_current_index.row(), mapped_current_index.column());
if (mapped_current_index.isValid() && selected_rows.count() > 0) { if (mapped_current_index.isValid() && selected_rows.count() > 0) {
Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row()); Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row());
// Set this message as read only if current item // Set this message as read only if current item
// wasn't changed by "mark selected messages unread" action. // wasn't changed by "mark selected messages unread" action.
m_sourceModel->setMessageRead(mapped_current_index.row(), RootItem::Read); m_sourceModel->setMessageRead(mapped_current_index.row(), RootItem::Read);
message.m_isRead = true; message.m_isRead = true;
emit currentMessageChanged(message, m_sourceModel->loadedItem()); emit currentMessageChanged(message, m_sourceModel->loadedItem());
} }
else { else {
@ -294,9 +293,11 @@ void MessagesView::selectionChanged(const QItemSelection& selected, const QItemS
void MessagesView::loadItem(RootItem* item) { void MessagesView::loadItem(RootItem* item) {
const int col = header()->sortIndicatorSection(); const int col = header()->sortIndicatorSection();
const Qt::SortOrder ord = header()->sortIndicatorOrder(); const Qt::SortOrder ord = header()->sortIndicatorOrder();
scrollToTop(); scrollToTop();
sort(col, ord, false, true, false); sort(col, ord, false, true, false);
m_sourceModel->loadMessages(item); m_sourceModel->loadMessages(item);
// Messages are loaded, make sure that previously // Messages are loaded, make sure that previously
// active message is not shown in browser. // active message is not shown in browser.
// BUG: Qt 5 is probably bugged here. Selections // BUG: Qt 5 is probably bugged here. Selections
@ -309,9 +310,7 @@ void MessagesView::openSelectedSourceMessagesExternally() {
const QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()).m_url; const QString link = m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()).m_url;
if (!qApp->web()->openUrlInExternalBrowser(link)) { if (!qApp->web()->openUrlInExternalBrowser(link)) {
qApp->showGuiMessage(tr("Problem with starting external web browser"), qApp->showGuiMessage(tr("Problem with starting external web browser"),tr("External web browser could not be started."),QSystemTrayIcon::Critical);
tr("External web browser could not be started."),
QSystemTrayIcon::Critical);
return; return;
} }
} }
@ -339,10 +338,7 @@ void MessagesView::sendSelectedMessageViaEmail() {
const Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(selectionModel()->selectedRows().at(0)).row()); const Message message = m_sourceModel->messageAt(m_proxyModel->mapToSource(selectionModel()->selectedRows().at(0)).row());
if (!qApp->web()->sendMessageViaEmail(message)) { if (!qApp->web()->sendMessageViaEmail(message)) {
MessageBox::show(this, MessageBox::show(this,QMessageBox::Critical,tr("Problem with starting external e-mail client"),tr("External e-mail client could not be started."));
QMessageBox::Critical,
tr("Problem with starting external e-mail client"),
tr("External e-mail client could not be started."));
} }
} }
} }
@ -364,6 +360,7 @@ void MessagesView::setSelectedMessagesReadStatus(RootItem::ReadStatus read) {
QModelIndexList selected_indexes = selectionModel()->selectedRows(); QModelIndexList selected_indexes = selectionModel()->selectedRows();
const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes); const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
m_sourceModel->setBatchMessagesRead(mapped_indexes, read); m_sourceModel->setBatchMessagesRead(mapped_indexes, read);
current_index = m_proxyModel->index(current_index.row(), current_index.column()); current_index = m_proxyModel->index(current_index.row(), current_index.column());
@ -384,11 +381,13 @@ void MessagesView::deleteSelectedMessages() {
const QModelIndexList selected_indexes = selectionModel()->selectedRows(); const QModelIndexList selected_indexes = selectionModel()->selectedRows();
const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes); const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
m_sourceModel->setBatchMessagesDeleted(mapped_indexes); m_sourceModel->setBatchMessagesDeleted(mapped_indexes);
current_index = moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier); current_index = moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier);
if (current_index.isValid()) { if (current_index.isValid()) {
setCurrentIndex(current_index); setCurrentIndex(current_index);
emit currentMessageChanged(m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row()), m_sourceModel->loadedItem()); emit currentMessageChanged(m_sourceModel->messageAt(m_proxyModel->mapToSource(current_index).row()), m_sourceModel->loadedItem());
} }
else { else {
@ -405,6 +404,7 @@ void MessagesView::restoreSelectedMessages() {
const QModelIndexList selected_indexes = selectionModel()->selectedRows(); const QModelIndexList selected_indexes = selectionModel()->selectedRows();
const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes); const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
m_sourceModel->setBatchMessagesRestored(mapped_indexes); m_sourceModel->setBatchMessagesRestored(mapped_indexes);
current_index = m_proxyModel->index(current_index.row(), current_index.column()); current_index = m_proxyModel->index(current_index.row(), current_index.column());
@ -425,6 +425,7 @@ void MessagesView::switchSelectedMessagesImportance() {
QModelIndexList selected_indexes = selectionModel()->selectedRows(); QModelIndexList selected_indexes = selectionModel()->selectedRows();
const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes); const QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
m_sourceModel->switchBatchMessageImportance(mapped_indexes); m_sourceModel->switchBatchMessageImportance(mapped_indexes);
current_index = m_proxyModel->index(current_index.row(), current_index.column()); current_index = m_proxyModel->index(current_index.row(), current_index.column());
@ -519,8 +520,7 @@ void MessagesView::openSelectedMessagesWithExternalTool() {
if (!link.isEmpty()) { if (!link.isEmpty()) {
if (!QProcess::startDetached(tool.executable(), QStringList() << tool.parameters() << link)) { if (!QProcess::startDetached(tool.executable(), QStringList() << tool.parameters() << link)) {
qApp->showGuiMessage(tr("Cannot run external tool"), tr("External tool '%1' could not be started.").arg(tool.executable()), qApp->showGuiMessage(tr("Cannot run external tool"), tr("External tool '%1' could not be started.").arg(tool.executable()),QSystemTrayIcon::Critical);
QSystemTrayIcon::Critical);
} }
} }
} }
@ -530,6 +530,7 @@ void MessagesView::openSelectedMessagesWithExternalTool() {
void MessagesView::adjustColumns() { void MessagesView::adjustColumns() {
if (header()->count() > 0 && !m_columnsAdjusted) { if (header()->count() > 0 && !m_columnsAdjusted) {
m_columnsAdjusted = true; m_columnsAdjusted = true;
// Setup column resize strategies. // Setup column resize strategies.
header()->setSectionResizeMode(MSG_DB_ID_INDEX, QHeaderView::Interactive); header()->setSectionResizeMode(MSG_DB_ID_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_READ_INDEX, QHeaderView::ResizeToContents); header()->setSectionResizeMode(MSG_DB_READ_INDEX, QHeaderView::ResizeToContents);
@ -542,6 +543,7 @@ void MessagesView::adjustColumns() {
header()->setSectionResizeMode(MSG_DB_DCREATED_INDEX, QHeaderView::Interactive); header()->setSectionResizeMode(MSG_DB_DCREATED_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_CONTENTS_INDEX, QHeaderView::Interactive); header()->setSectionResizeMode(MSG_DB_CONTENTS_INDEX, QHeaderView::Interactive);
header()->setSectionResizeMode(MSG_DB_PDELETED_INDEX, QHeaderView::Interactive); header()->setSectionResizeMode(MSG_DB_PDELETED_INDEX, QHeaderView::Interactive);
//header()->resizeSection(MSG_DB_READ_INDEX, MESSAGES_VIEW_MINIMUM_COL); //header()->resizeSection(MSG_DB_READ_INDEX, MESSAGES_VIEW_MINIMUM_COL);
//header()->resizeSection(MSG_DB_IMPORTANT_INDEX, MESSAGES_VIEW_MINIMUM_COL); //header()->resizeSection(MSG_DB_IMPORTANT_INDEX, MESSAGES_VIEW_MINIMUM_COL);
// Hide columns. // Hide columns.
@ -562,5 +564,6 @@ void MessagesView::adjustColumns() {
void MessagesView::onSortIndicatorChanged(int column, Qt::SortOrder order) { void MessagesView::onSortIndicatorChanged(int column, Qt::SortOrder order) {
// Repopulate the shit. // Repopulate the shit.
sort(column, order, true, false, false); sort(column, order, true, false, false);
emit currentMessageRemoved(); emit currentMessageRemoved();
} }

View File

@ -1,4 +1,5 @@
// This file is part of RSS Guard. // This file is part of RSS Guard.
// //
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com> // Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// //
@ -22,9 +23,8 @@
#include "services/abstract/rootitem.h" #include "services/abstract/rootitem.h"
#include <QTreeView>
#include <QHeaderView> #include <QHeaderView>
#include <QTreeView>
class MessagesProxyModel; class MessagesProxyModel;
@ -32,7 +32,6 @@ class MessagesView : public QTreeView {
Q_OBJECT Q_OBJECT
public: public:
// Constructors and destructors.
explicit MessagesView(QWidget* parent = 0); explicit MessagesView(QWidget* parent = 0);
virtual ~MessagesView(); virtual ~MessagesView();
@ -89,7 +88,6 @@ class MessagesView : public QTreeView {
void onSortIndicatorChanged(int column, Qt::SortOrder order); void onSortIndicatorChanged(int column, Qt::SortOrder order);
signals: signals:
// Link/message openers.
void openLinkNewTab(const QString& link); void openLinkNewTab(const QString& link);
void openLinkMiniBrowser(const QString& link); void openLinkMiniBrowser(const QString& link);
void openMessagesInNewspaperView(RootItem* root, const QList<Message>& messages); void openMessagesInNewspaperView(RootItem* root, const QList<Message>& messages);
@ -117,10 +115,8 @@ class MessagesView : public QTreeView {
void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
QMenu* m_contextMenu; QMenu* m_contextMenu;
MessagesProxyModel* m_proxyModel; MessagesProxyModel* m_proxyModel;
MessagesModel* m_sourceModel; MessagesModel* m_sourceModel;
bool m_columnsAdjusted; bool m_columnsAdjusted;
}; };

View File

@ -1,4 +1,5 @@
// This file is part of RSS Guard. // This file is part of RSS Guard.
// //
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com> // Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// //
@ -18,15 +19,14 @@
#include "gui/statusbar.h" #include "gui/statusbar.h"
#include "gui/dialogs/formmain.h" #include "gui/dialogs/formmain.h"
#include "gui/tabwidget.h"
#include "gui/plaintoolbutton.h" #include "gui/plaintoolbutton.h"
#include "miscellaneous/mutex.h" #include "gui/tabwidget.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "miscellaneous/mutex.h"
#include <QToolButton>
#include <QLabel> #include <QLabel>
#include <QProgressBar> #include <QProgressBar>
#include <QToolButton>
StatusBar::StatusBar(QWidget* parent) : QStatusBar(parent), m_mutex(new Mutex(QMutex::NonRecursive, this)) { StatusBar::StatusBar(QWidget* parent) : QStatusBar(parent), m_mutex(new Mutex(QMutex::NonRecursive, this)) {
setSizeGripEnabled(false); setSizeGripEnabled(false);
@ -37,20 +37,20 @@ StatusBar::StatusBar(QWidget* parent) : QStatusBar(parent), m_mutex(new Mutex(QM
m_barProgressFeeds->setFixedWidth(100); m_barProgressFeeds->setFixedWidth(100);
m_barProgressFeeds->setVisible(false); m_barProgressFeeds->setVisible(false);
m_barProgressFeeds->setObjectName(QSL("m_barProgressFeeds")); m_barProgressFeeds->setObjectName(QSL("m_barProgressFeeds"));
m_barProgressFeedsAction = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")), tr("Feed update progress bar"), this); m_barProgressFeedsAction = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")),tr("Feed update progress bar"),this);
m_barProgressFeedsAction->setObjectName(QSL("m_barProgressFeedsAction")); m_barProgressFeedsAction->setObjectName(QSL("m_barProgressFeedsAction"));
m_lblProgressFeeds = new QLabel(this); m_lblProgressFeeds = new QLabel(this);
m_lblProgressFeeds->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); m_lblProgressFeeds->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_lblProgressFeeds->setVisible(false); m_lblProgressFeeds->setVisible(false);
m_lblProgressFeeds->setObjectName(QSL("m_lblProgressFeeds")); m_lblProgressFeeds->setObjectName(QSL("m_lblProgressFeeds"));
m_lblProgressFeedsAction = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")), tr("Feed update label"), this); m_lblProgressFeedsAction = new QAction(qApp->icons()->fromTheme(QSL("application-rss+xml")), tr("Feed update label"),this);
m_lblProgressFeedsAction->setObjectName(QSL("m_lblProgressFeedsAction")); m_lblProgressFeedsAction->setObjectName(QSL("m_lblProgressFeedsAction"));
m_barProgressDownload = new QProgressBar(this); m_barProgressDownload = new QProgressBar(this);
m_barProgressDownload->setTextVisible(true); m_barProgressDownload->setTextVisible(true);
m_barProgressDownload->setFixedWidth(100); m_barProgressDownload->setFixedWidth(100);
m_barProgressDownload->setVisible(false); m_barProgressDownload->setVisible(false);
m_barProgressDownload->setObjectName(QSL("m_barProgressDownload")); m_barProgressDownload->setObjectName(QSL("m_barProgressDownload"));
m_barProgressDownloadAction = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads")), tr("File download progress bar"), this); m_barProgressDownloadAction = new QAction(qApp->icons()->fromTheme(QSL("emblem-downloads")),tr("File download progress bar"),this);
m_barProgressDownloadAction->setObjectName(QSL("m_barProgressDownloadAction")); m_barProgressDownloadAction->setObjectName(QSL("m_barProgressDownloadAction"));
m_lblProgressDownload = new QLabel(this); m_lblProgressDownload = new QLabel(this);
m_lblProgressDownload->setText("Downloading files in background"); m_lblProgressDownload->setText("Downloading files in background");
@ -70,9 +70,10 @@ StatusBar::~StatusBar() {
QList<QAction*> StatusBar::availableActions() const { QList<QAction*> StatusBar::availableActions() const {
QList<QAction*> actions = qApp->userActions(); QList<QAction*> actions = qApp->userActions();
// Now, add placeholder actions for custom stuff. // Now, add placeholder actions for custom stuff.
actions << m_barProgressDownloadAction << m_barProgressFeedsAction << actions << m_barProgressDownloadAction << m_barProgressFeedsAction << m_lblProgressDownloadAction << m_lblProgressFeedsAction;
m_lblProgressDownloadAction << m_lblProgressFeedsAction;
return actions; return actions;
} }
@ -82,6 +83,7 @@ QList<QAction*> StatusBar::changeableActions() const {
void StatusBar::saveChangeableActions(const QStringList& actions) { void StatusBar::saveChangeableActions(const QStringList& actions) {
QMutexLocker locker(*m_mutex); QMutexLocker locker(*m_mutex);
qApp->settings()->setValue(GROUP(GUI), GUI::StatusbarActions, actions.join(QSL(","))); qApp->settings()->setValue(GROUP(GUI), GUI::StatusbarActions, actions.join(QSL(",")));
loadSpecificActions(getSpecificActions(actions)); loadSpecificActions(getSpecificActions(actions));
} }
@ -91,17 +93,18 @@ QStringList StatusBar::defaultActions() const {
} }
QStringList StatusBar::savedActions() const { QStringList StatusBar::savedActions() const {
return qApp->settings()->value(GROUP(GUI), SETTING(GUI::StatusbarActions)).toString().split(',', QString::SkipEmptyParts); return qApp->settings()->value(GROUP(GUI), SETTING(GUI::StatusbarActions)).toString().split(',',QString::SkipEmptyParts);
} }
QList<QAction*> StatusBar::getSpecificActions(const QStringList& actions) { QList<QAction*> StatusBar::getSpecificActions(const QStringList& actions) {
bool progress_visible = this->actions().contains(m_barProgressFeedsAction) && bool progress_visible = this->actions().contains(m_barProgressFeedsAction) && m_lblProgressFeeds->isVisible() &&
m_lblProgressFeeds->isVisible() &&
m_barProgressFeeds->isVisible(); m_barProgressFeeds->isVisible();
QList<QAction*> available_actions = availableActions(); QList<QAction*> available_actions = availableActions();
QList<QAction*> spec_actions; QList<QAction*> spec_actions;
// Iterate action names and add respectable actions into the toolbar. // Iterate action names and add respectable
// actions into the toolbar.
foreach (const QString& action_name, actions) { foreach (const QString& action_name, actions) {
QAction* matching_action = findMatchingAction(action_name, available_actions); QAction* matching_action = findMatchingAction(action_name, available_actions);
QAction* action_to_add; QAction* action_to_add;
@ -130,6 +133,7 @@ QList<QAction*> StatusBar::getSpecificActions(const QStringList& actions) {
else { else {
if (action_name == SEPARATOR_ACTION_NAME) { if (action_name == SEPARATOR_ACTION_NAME) {
QLabel* lbl = new QLabel(QString::fromUtf8("")); QLabel* lbl = new QLabel(QString::fromUtf8(""));
widget_to_add = lbl; widget_to_add = lbl;
action_to_add = new QAction(this); action_to_add = new QAction(this);
action_to_add->setSeparator(true); action_to_add->setSeparator(true);
@ -137,6 +141,7 @@ QList<QAction*> StatusBar::getSpecificActions(const QStringList& actions) {
} }
else if (action_name == SPACER_ACTION_NAME) { else if (action_name == SPACER_ACTION_NAME) {
QLabel* lbl = new QLabel(QSL("\t\t")); QLabel* lbl = new QLabel(QSL("\t\t"));
widget_to_add = lbl; widget_to_add = lbl;
action_to_add = new QAction(this); action_to_add = new QAction(this);
action_to_add->setProperty("should_remove_action", true); action_to_add->setProperty("should_remove_action", true);
@ -147,11 +152,12 @@ QList<QAction*> StatusBar::getSpecificActions(const QStringList& actions) {
else if (matching_action != nullptr) { else if (matching_action != nullptr) {
// Add originally toolbar action. // Add originally toolbar action.
PlainToolButton* tool_button = new PlainToolButton(this); PlainToolButton* tool_button = new PlainToolButton(this);
tool_button->reactOnActionChange(matching_action); tool_button->reactOnActionChange(matching_action);
widget_to_add = tool_button; widget_to_add = tool_button;
action_to_add = matching_action; action_to_add = matching_action;
connect(tool_button, &PlainToolButton::clicked, matching_action, &QAction::trigger); connect(tool_button, &PlainToolButton::clicked, matching_action, &QAction::trigger);
connect(matching_action, &QAction::changed, tool_button, &PlainToolButton::reactOnSenderActionChange); connect(matching_action, &QAction::changed, tool_button,&PlainToolButton::reactOnSenderActionChange);
} }
else { else {
action_to_add = nullptr; action_to_add = nullptr;
@ -189,6 +195,7 @@ void StatusBar::loadSpecificActions(const QList<QAction*>& actions) {
foreach (QAction* act, actions) { foreach (QAction* act, actions) {
QWidget* widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : nullptr; QWidget* widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : nullptr;
addAction(act); addAction(act);
// And also add widget. // And also add widget.
@ -214,6 +221,7 @@ void StatusBar::clear() {
QWidget* widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : nullptr; QWidget* widget = act->property("widget").isValid() ? static_cast<QWidget*>(act->property("widget").value<void*>()) : nullptr;
bool should_remove_widget = act->property("should_remove_widget").isValid(); bool should_remove_widget = act->property("should_remove_widget").isValid();
bool should_remove_action = act->property("should_remove_action").isValid(); bool should_remove_action = act->property("should_remove_action").isValid();
removeAction(act); removeAction(act);
if (widget != nullptr) { if (widget != nullptr) {

View File

@ -1,4 +1,5 @@
// This file is part of RSS Guard. // This file is part of RSS Guard.
// //
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com> // Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
// //
@ -22,7 +23,6 @@
#include "gui/basetoolbar.h" #include "gui/basetoolbar.h"
class QProgressBar; class QProgressBar;
class PlainToolButton; class PlainToolButton;
class QLabel; class QLabel;
@ -32,7 +32,6 @@ class StatusBar : public QStatusBar, public BaseBar {
Q_OBJECT Q_OBJECT
public: public:
// Constructors and destructors.
explicit StatusBar(QWidget* parent = 0); explicit StatusBar(QWidget* parent = 0);
virtual ~StatusBar(); virtual ~StatusBar();
@ -45,7 +44,6 @@ class StatusBar : public QStatusBar, public BaseBar {
void loadSpecificActions(const QList<QAction*>& actions); void loadSpecificActions(const QList<QAction*>& actions);
public slots: public slots:
// Progress bar operations
void showProgressFeeds(int progress, const QString& label); void showProgressFeeds(int progress, const QString& label);
void clearProgressFeeds(); void clearProgressFeeds();
@ -59,16 +57,12 @@ class StatusBar : public QStatusBar, public BaseBar {
void clear(); void clear();
Mutex* m_mutex; Mutex* m_mutex;
QProgressBar* m_barProgressFeeds; QProgressBar* m_barProgressFeeds;
QAction* m_barProgressFeedsAction; QAction* m_barProgressFeedsAction;
QLabel* m_lblProgressFeeds; QLabel* m_lblProgressFeeds;
QAction* m_lblProgressFeedsAction; QAction* m_lblProgressFeedsAction;
QProgressBar* m_barProgressDownload; QProgressBar* m_barProgressDownload;
QAction* m_barProgressDownloadAction; QAction* m_barProgressDownloadAction;
QLabel* m_lblProgressDownload; QLabel* m_lblProgressDownload;
QAction* m_lblProgressDownloadAction; QAction* m_lblProgressDownloadAction;
}; };

View File

@ -17,12 +17,12 @@
#include "services/owncloud/network/owncloudnetworkfactory.h" #include "services/owncloud/network/owncloudnetworkfactory.h"
#include "services/owncloud/definitions.h"
#include "network-web/networkfactory.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/settings.h" #include "miscellaneous/settings.h"
#include "miscellaneous/textfactory.h" #include "miscellaneous/textfactory.h"
#include "network-web/networkfactory.h"
#include "services/abstract/rootitem.h" #include "services/abstract/rootitem.h"
#include "services/owncloud/definitions.h"
#include "services/owncloud/owncloudcategory.h" #include "services/owncloud/owncloudcategory.h"
#include "services/owncloud/owncloudfeed.h" #include "services/owncloud/owncloudfeed.h"
@ -36,11 +36,9 @@ OwnCloudNetworkFactory::OwnCloudNetworkFactory()
: m_url(QString()), m_fixedUrl(QString()), m_forceServerSideUpdate(false), : m_url(QString()), m_fixedUrl(QString()), m_forceServerSideUpdate(false),
m_authUsername(QString()), m_authPassword(QString()), m_batchSize(-1), m_urlUser(QString()), m_urlStatus(QString()), m_authUsername(QString()), m_authPassword(QString()), m_batchSize(-1), m_urlUser(QString()), m_urlStatus(QString()),
m_urlFolders(QString()), m_urlFeeds(QString()), m_urlMessages(QString()), m_urlFeedsUpdate(QString()), m_urlFolders(QString()), m_urlFeeds(QString()), m_urlMessages(QString()), m_urlFeedsUpdate(QString()),
m_urlDeleteFeed(QString()), m_urlRenameFeed(QString()), m_userId(QString()) { m_urlDeleteFeed(QString()), m_urlRenameFeed(QString()), m_userId(QString()) {}
}
OwnCloudNetworkFactory::~OwnCloudNetworkFactory() { OwnCloudNetworkFactory::~OwnCloudNetworkFactory() {}
}
QString OwnCloudNetworkFactory::url() const { QString OwnCloudNetworkFactory::url() const {
return m_url; return m_url;
@ -49,7 +47,8 @@ QString OwnCloudNetworkFactory::url() const {
void OwnCloudNetworkFactory::setUrl(const QString& url) { void OwnCloudNetworkFactory::setUrl(const QString& url) {
m_url = url; m_url = url;
if (url.endsWith('/')) { if (url.endsWith('/')
) {
m_fixedUrl = url; m_fixedUrl = url;
} }
else { else {
@ -109,7 +108,8 @@ OwnCloudUserResponse OwnCloudNetworkFactory::userInfo() {
true); true);
OwnCloudUserResponse user_response(QString::fromUtf8(result_raw)); OwnCloudUserResponse user_response(QString::fromUtf8(result_raw));
if (network_reply.first != QNetworkReply::NoError) { if (network_reply.first != QNetworkReply::NoError
) {
qWarning("ownCloud: Obtaining user info failed with error %d.", network_reply.first); qWarning("ownCloud: Obtaining user info failed with error %d.", network_reply.first);
} }
@ -128,7 +128,8 @@ OwnCloudStatusResponse OwnCloudNetworkFactory::status() {
true); true);
OwnCloudStatusResponse status_response(QString::fromUtf8(result_raw)); OwnCloudStatusResponse status_response(QString::fromUtf8(result_raw));
if (network_reply.first != QNetworkReply::NoError) { if (network_reply.first != QNetworkReply::NoError
) {
qWarning("ownCloud: Obtaining status info failed with error %d.", network_reply.first); qWarning("ownCloud: Obtaining status info failed with error %d.", network_reply.first);
} }
@ -146,13 +147,16 @@ OwnCloudGetFeedsCategoriesResponse OwnCloudNetworkFactory::feedsCategories() {
true, m_authUsername, m_authPassword, true, m_authUsername, m_authPassword,
true); true);
if (network_reply.first != QNetworkReply::NoError) { if (network_reply.first != QNetworkReply::NoError
) {
qWarning("ownCloud: Obtaining of categories failed with error %d.", network_reply.first); qWarning("ownCloud: Obtaining of categories failed with error %d.", network_reply.first);
m_lastError = network_reply.first; m_lastError = network_reply.first;
return OwnCloudGetFeedsCategoriesResponse(); return OwnCloudGetFeedsCategoriesResponse();
} }
QString content_categories = QString::fromUtf8(result_raw); QString content_categories = QString::fromUtf8(result_raw);
// Now, obtain feeds. // Now, obtain feeds.
network_reply = NetworkFactory::performNetworkOperation(m_urlFeeds, network_reply = NetworkFactory::performNetworkOperation(m_urlFeeds,
qApp->settings()->value(GROUP(Feeds), qApp->settings()->value(GROUP(Feeds),
@ -162,13 +166,16 @@ OwnCloudGetFeedsCategoriesResponse OwnCloudNetworkFactory::feedsCategories() {
true, m_authUsername, m_authPassword, true, m_authUsername, m_authPassword,
true); true);
if (network_reply.first != QNetworkReply::NoError) { if (network_reply.first != QNetworkReply::NoError
) {
qWarning("ownCloud: Obtaining of feeds failed with error %d.", network_reply.first); qWarning("ownCloud: Obtaining of feeds failed with error %d.", network_reply.first);
m_lastError = network_reply.first; m_lastError = network_reply.first;
return OwnCloudGetFeedsCategoriesResponse(); return OwnCloudGetFeedsCategoriesResponse();
} }
QString content_feeds = QString::fromUtf8(result_raw); QString content_feeds = QString::fromUtf8(result_raw);
m_lastError = network_reply.first; m_lastError = network_reply.first;
return OwnCloudGetFeedsCategoriesResponse(content_categories, content_feeds); return OwnCloudGetFeedsCategoriesResponse(content_categories, content_feeds);
} }
@ -182,9 +189,11 @@ bool OwnCloudNetworkFactory::deleteFeed(int feed_id) {
QByteArray(), QString(), QByteArray(), QString(),
raw_output, QNetworkAccessManager::DeleteOperation, raw_output, QNetworkAccessManager::DeleteOperation,
true, m_authUsername, m_authPassword, true); true, m_authUsername, m_authPassword, true);
m_lastError = network_reply.first; m_lastError = network_reply.first;
if (network_reply.first != QNetworkReply::NoError) { if (network_reply.first != QNetworkReply::NoError
) {
qWarning("ownCloud: Obtaining of categories failed with error %d.", network_reply.first); qWarning("ownCloud: Obtaining of categories failed with error %d.", network_reply.first);
return false; return false;
} }
@ -195,8 +204,10 @@ bool OwnCloudNetworkFactory::deleteFeed(int feed_id) {
bool OwnCloudNetworkFactory::createFeed(const QString& url, int parent_id) { bool OwnCloudNetworkFactory::createFeed(const QString& url, int parent_id) {
QJsonObject json; QJsonObject json;
json["url"] = url; json["url"] = url;
json["folderId"] = parent_id; json["folderId"] = parent_id;
QByteArray result_raw; QByteArray result_raw;
NetworkResult network_reply = NetworkFactory::performNetworkOperation(m_urlFeeds, NetworkResult network_reply = NetworkFactory::performNetworkOperation(m_urlFeeds,
qApp->settings()->value(GROUP(Feeds), qApp->settings()->value(GROUP(Feeds),
@ -206,9 +217,12 @@ bool OwnCloudNetworkFactory::createFeed(const QString& url, int parent_id) {
result_raw, result_raw,
QNetworkAccessManager::PostOperation, QNetworkAccessManager::PostOperation,
true, m_authUsername, m_authPassword, true); true, m_authUsername, m_authPassword, true);
m_lastError = network_reply.first; m_lastError = network_reply.first;
if (network_reply.first != QNetworkReply::NoError) { if (network_reply.first != QNetworkReply::NoError
) {
qWarning("ownCloud: Creating of category failed with error %d.", network_reply.first); qWarning("ownCloud: Creating of category failed with error %d.", network_reply.first);
return false; return false;
} }
@ -221,8 +235,11 @@ bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, int feed_id) {
QString final_url = m_urlRenameFeed.arg(QString::number(feed_id)); QString final_url = m_urlRenameFeed.arg(QString::number(feed_id));
QByteArray result_raw; QByteArray result_raw;
QJsonObject json; QJsonObject json;
json["feedTitle"] = new_name; json["feedTitle"] = new_name;
NetworkResult network_reply = NetworkFactory::performNetworkOperation(final_url,
NetworkResult network_reply = NetworkFactory::performNetworkOperation(
final_url,
qApp->settings()->value(GROUP(Feeds), qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(), SETTING(Feeds::UpdateTimeout)).toInt(),
QJsonDocument(json).toJson(QJsonDocument::Compact), QJsonDocument(json).toJson(QJsonDocument::Compact),
@ -230,9 +247,12 @@ bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, int feed_id) {
QNetworkAccessManager::PutOperation, QNetworkAccessManager::PutOperation,
true, m_authUsername, m_authPassword, true, m_authUsername, m_authPassword,
true); true);
m_lastError = network_reply.first; m_lastError = network_reply.first;
if (network_reply.first != QNetworkReply::NoError) { if (network_reply.first != QNetworkReply::NoError
) {
qWarning("ownCloud: Renaming of feed failed with error %d.", network_reply.first); qWarning("ownCloud: Renaming of feed failed with error %d.", network_reply.first);
return false; return false;
} }
@ -242,7 +262,8 @@ bool OwnCloudNetworkFactory::renameFeed(const QString& new_name, int feed_id) {
} }
OwnCloudGetMessagesResponse OwnCloudNetworkFactory::getMessages(int feed_id) { OwnCloudGetMessagesResponse OwnCloudNetworkFactory::getMessages(int feed_id) {
if (forceServerSideUpdate()) { if (forceServerSideUpdate()
) {
triggerFeedUpdate(feed_id); triggerFeedUpdate(feed_id);
} }
@ -259,7 +280,9 @@ OwnCloudGetMessagesResponse OwnCloudNetworkFactory::getMessages(int feed_id) {
true); true);
OwnCloudGetMessagesResponse msgs_response(QString::fromUtf8(result_raw)); OwnCloudGetMessagesResponse msgs_response(QString::fromUtf8(result_raw));
if (network_reply.first != QNetworkReply::NoError) {
if (network_reply.first != QNetworkReply::NoError
) {
qWarning("ownCloud: Obtaining messages failed with error %d.", network_reply.first); qWarning("ownCloud: Obtaining messages failed with error %d.", network_reply.first);
} }
@ -268,11 +291,14 @@ OwnCloudGetMessagesResponse OwnCloudNetworkFactory::getMessages(int feed_id) {
} }
QNetworkReply::NetworkError OwnCloudNetworkFactory::triggerFeedUpdate(int feed_id) { QNetworkReply::NetworkError OwnCloudNetworkFactory::triggerFeedUpdate(int feed_id) {
if (userId().isEmpty()) { if (userId().isEmpty()
) {
// We need to get user ID first. // We need to get user ID first.
OwnCloudUserResponse info = userInfo(); OwnCloudUserResponse info = userInfo();
if (lastError() != QNetworkReply::NoError) {
if (lastError() != QNetworkReply::NoError
) {
return lastError(); return lastError();
} }
else { else {
@ -292,7 +318,8 @@ QNetworkReply::NetworkError OwnCloudNetworkFactory::triggerFeedUpdate(int feed_i
true, m_authUsername, m_authPassword, true, m_authUsername, m_authPassword,
true); true);
if (network_reply.first != QNetworkReply::NoError) { if (network_reply.first != QNetworkReply::NoError
) {
qWarning("ownCloud: Feeds update failed with error %d.", network_reply.first); qWarning("ownCloud: Feeds update failed with error %d.", network_reply.first);
} }
@ -304,7 +331,8 @@ void OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const
QJsonArray ids; QJsonArray ids;
QString final_url; QString final_url;
if (status == RootItem::Read) { if (status == RootItem::Read
) {
final_url = m_fixedUrl + API_PATH + "items/read/multiple"; final_url = m_fixedUrl + API_PATH + "items/read/multiple";
} }
else { else {
@ -326,6 +354,7 @@ void OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const
true, m_authUsername, m_authPassword, true, m_authUsername, m_authPassword,
true); true);
QObject::connect(downloader, &Downloader::completed, downloader, &Downloader::deleteLater); QObject::connect(downloader, &Downloader::completed, downloader, &Downloader::deleteLater);
} }
@ -336,7 +365,8 @@ void OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance importance
QJsonArray ids; QJsonArray ids;
QString final_url; QString final_url;
if (importance == RootItem::Important) { if (importance == RootItem::Important
) {
final_url = m_fixedUrl + API_PATH + "items/star/multiple"; final_url = m_fixedUrl + API_PATH + "items/star/multiple";
} }
else { else {
@ -345,12 +375,15 @@ void OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance importance
for (int i = 0; i < feed_ids.size(); i++) { for (int i = 0; i < feed_ids.size(); i++) {
QJsonObject item; QJsonObject item;
item["feedId"] = feed_ids.at(i); item["feedId"] = feed_ids.at(i);
item["guidHash"] = guid_hashes.at(i); item["guidHash"] = guid_hashes.at(i);
ids.append(item); ids.append(item);
} }
json["items"] = ids; json["items"] = ids;
Downloader* downloader = NetworkFactory::performAsyncNetworkOperation(final_url, Downloader* downloader = NetworkFactory::performAsyncNetworkOperation(final_url,
qApp->settings()->value(GROUP(Feeds), qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(), SETTING(Feeds::UpdateTimeout)).toInt(),
@ -360,6 +393,7 @@ void OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance importance
true, m_authUsername, m_authPassword, true, m_authUsername, m_authPassword,
true); true);
QObject::connect(downloader, &Downloader::completed, downloader, &Downloader::deleteLater); QObject::connect(downloader, &Downloader::completed, downloader, &Downloader::deleteLater);
} }
@ -384,8 +418,7 @@ OwnCloudResponse::OwnCloudResponse(const QString& raw_content) {
m_emptyString = raw_content.isEmpty(); m_emptyString = raw_content.isEmpty();
} }
OwnCloudResponse::~OwnCloudResponse() { OwnCloudResponse::~OwnCloudResponse() {}
}
bool OwnCloudResponse::isLoaded() const { bool OwnCloudResponse::isLoaded() const {
return !m_emptyString && !m_rawContent.isEmpty(); return !m_emptyString && !m_rawContent.isEmpty();
@ -395,14 +428,13 @@ QString OwnCloudResponse::toString() const {
return QJsonDocument(m_rawContent).toJson(QJsonDocument::Compact); return QJsonDocument(m_rawContent).toJson(QJsonDocument::Compact);
} }
OwnCloudUserResponse::OwnCloudUserResponse(const QString& raw_content) : OwnCloudResponse(raw_content) { OwnCloudUserResponse::OwnCloudUserResponse(const QString& raw_content) : OwnCloudResponse(raw_content) {}
}
OwnCloudUserResponse::~OwnCloudUserResponse() { OwnCloudUserResponse::~OwnCloudUserResponse() {}
}
QString OwnCloudUserResponse::displayName() const { QString OwnCloudUserResponse::displayName() const {
if (isLoaded()) { if (isLoaded()
) {
return m_rawContent["displayName"].toString(); return m_rawContent["displayName"].toString();
} }
else { else {
@ -411,7 +443,8 @@ QString OwnCloudUserResponse::displayName() const {
} }
QString OwnCloudUserResponse::userId() const { QString OwnCloudUserResponse::userId() const {
if (isLoaded()) { if (isLoaded()
) {
return m_rawContent["userId"].toString(); return m_rawContent["userId"].toString();
} }
else { else {
@ -420,7 +453,8 @@ QString OwnCloudUserResponse::userId() const {
} }
QDateTime OwnCloudUserResponse::lastLoginTime() const { QDateTime OwnCloudUserResponse::lastLoginTime() const {
if (isLoaded()) { if (isLoaded()
) {
return QDateTime::fromMSecsSinceEpoch(m_rawContent["lastLoginTimestamp"].toDouble()); return QDateTime::fromMSecsSinceEpoch(m_rawContent["lastLoginTimestamp"].toDouble());
} }
else { else {
@ -429,12 +463,15 @@ QDateTime OwnCloudUserResponse::lastLoginTime() const {
} }
QIcon OwnCloudUserResponse::avatar() const { QIcon OwnCloudUserResponse::avatar() const {
if (isLoaded()) { if (isLoaded()
) {
QString image_data = m_rawContent["avatar"].toObject()["data"].toString(); QString image_data = m_rawContent["avatar"].toObject()["data"].toString();
QByteArray decoded_data = QByteArray::fromBase64(image_data.toLocal8Bit()); QByteArray decoded_data = QByteArray::fromBase64(image_data.toLocal8Bit());
QPixmap image; QPixmap image;
if (image.loadFromData(decoded_data)) {
if (image.loadFromData(decoded_data)
) {
return QIcon(image); return QIcon(image);
} }
} }
@ -443,14 +480,13 @@ QIcon OwnCloudUserResponse::avatar() const {
} }
OwnCloudStatusResponse::OwnCloudStatusResponse(const QString& raw_content) : OwnCloudResponse(raw_content) { OwnCloudStatusResponse::OwnCloudStatusResponse(const QString& raw_content) : OwnCloudResponse(raw_content) {}
}
OwnCloudStatusResponse::~OwnCloudStatusResponse() { OwnCloudStatusResponse::~OwnCloudStatusResponse() {}
}
QString OwnCloudStatusResponse::version() const { QString OwnCloudStatusResponse::version() const {
if (isLoaded()) { if (isLoaded()
) {
return m_rawContent["version"].toString(); return m_rawContent["version"].toString();
} }
else { else {
@ -459,7 +495,8 @@ QString OwnCloudStatusResponse::version() const {
} }
bool OwnCloudStatusResponse::misconfiguredCron() const { bool OwnCloudStatusResponse::misconfiguredCron() const {
if (isLoaded()) { if (isLoaded()
) {
return m_rawContent["warnings"].toObject()["improperlyConfiguredCron"].toBool(); return m_rawContent["warnings"].toObject()["improperlyConfiguredCron"].toBool();
} }
else { else {
@ -470,14 +507,13 @@ bool OwnCloudStatusResponse::misconfiguredCron() const {
OwnCloudGetFeedsCategoriesResponse::OwnCloudGetFeedsCategoriesResponse(const QString& raw_categories, OwnCloudGetFeedsCategoriesResponse::OwnCloudGetFeedsCategoriesResponse(const QString& raw_categories,
const QString& raw_feeds) const QString& raw_feeds)
: m_contentCategories(raw_categories), m_contentFeeds(raw_feeds) { : m_contentCategories(raw_categories), m_contentFeeds(raw_feeds) {}
}
OwnCloudGetFeedsCategoriesResponse::~OwnCloudGetFeedsCategoriesResponse() { OwnCloudGetFeedsCategoriesResponse::~OwnCloudGetFeedsCategoriesResponse() {}
}
RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons) const { RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons) const {
RootItem* parent = new RootItem(); RootItem* parent = new RootItem();
QMap<int, RootItem*>cats; QMap<int, RootItem*>cats;
cats.insert(0, parent); cats.insert(0, parent);
@ -485,6 +521,8 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
foreach (const QJsonValue& cat, QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray()) { foreach (const QJsonValue& cat, QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray()) {
QJsonObject item = cat.toObject(); QJsonObject item = cat.toObject();
OwnCloudCategory* category = new OwnCloudCategory(); OwnCloudCategory* category = new OwnCloudCategory();
category->setTitle(item["name"].toString()); category->setTitle(item["name"].toString());
category->setCustomId(item["id"].toInt()); category->setCustomId(item["id"].toInt());
cats.insert(category->customId(), category); cats.insert(category->customId(), category);
@ -497,17 +535,25 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
QJsonObject item = fed.toObject(); QJsonObject item = fed.toObject();
OwnCloudFeed* feed = new OwnCloudFeed(); OwnCloudFeed* feed = new OwnCloudFeed();
if (obtain_icons) {
if (obtain_icons
) {
QString icon_path = item["faviconLink"].toString(); QString icon_path = item["faviconLink"].toString();
if (!icon_path.isEmpty()) {
if (!icon_path.isEmpty()
) {
QByteArray icon_data; QByteArray icon_data;
if (NetworkFactory::performNetworkOperation(icon_path, DOWNLOAD_TIMEOUT, if (NetworkFactory::performNetworkOperation(icon_path, DOWNLOAD_TIMEOUT,
QByteArray(), QString(), icon_data, QByteArray(), QString(), icon_data,
QNetworkAccessManager::GetOperation).first == QNetworkReply::NoError) { QNetworkAccessManager::GetOperation).first == QNetworkReply::NoError
) {
// Icon downloaded, set it up. // Icon downloaded, set it up.
QPixmap icon_pixmap; QPixmap icon_pixmap;
icon_pixmap.loadFromData(icon_data); icon_pixmap.loadFromData(icon_data);
feed->setIcon(QIcon(icon_pixmap)); feed->setIcon(QIcon(icon_pixmap));
} }
@ -525,11 +571,9 @@ RootItem* OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
} }
OwnCloudGetMessagesResponse::OwnCloudGetMessagesResponse(const QString& raw_content) : OwnCloudResponse(raw_content) { OwnCloudGetMessagesResponse::OwnCloudGetMessagesResponse(const QString& raw_content) : OwnCloudResponse(raw_content) {}
}
OwnCloudGetMessagesResponse::~OwnCloudGetMessagesResponse() { OwnCloudGetMessagesResponse::~OwnCloudGetMessagesResponse() {}
}
QList<Message>OwnCloudGetMessagesResponse::messages() const { QList<Message>OwnCloudGetMessagesResponse::messages() const {
QList<Message>msgs; QList<Message>msgs;
@ -537,16 +581,23 @@ QList<Message>OwnCloudGetMessagesResponse::messages() const {
foreach (const QJsonValue& message, m_rawContent["items"].toArray()) { foreach (const QJsonValue& message, m_rawContent["items"].toArray()) {
QJsonObject message_map = message.toObject(); QJsonObject message_map = message.toObject();
Message msg; Message msg;
msg.m_author = message_map["author"].toString(); msg.m_author = message_map["author"].toString();
msg.m_contents = message_map["body"].toString(); msg.m_contents = message_map["body"].toString();
msg.m_created = TextFactory::parseDateTime(message_map["pubDate"].toDouble() * 1000); msg.m_created = TextFactory::parseDateTime(message_map["pubDate"].toDouble() * 1000);
msg.m_createdFromFeed = true; msg.m_createdFromFeed = true;
msg.m_customId = QString::number(message_map["id"].toInt()); msg.m_customId = QString::number(message_map["id"].toInt());
msg.m_customHash = message_map["guidHash"].toString(); msg.m_customHash = message_map["guidHash"].toString();
QString enclosure_link = message_map["enclosureLink"].toString(); QString enclosure_link = message_map["enclosureLink"].toString();
if (!enclosure_link.isEmpty()) {
if (!enclosure_link.isEmpty()
) {
Enclosure enclosure; Enclosure enclosure;
enclosure.m_mimeType = message_map["enclosureMime"].toString(); enclosure.m_mimeType = message_map["enclosureMime"].toString();
enclosure.m_url = enclosure_link; enclosure.m_url = enclosure_link;
msg.m_enclosures.append(enclosure); msg.m_enclosures.append(enclosure);

View File

@ -22,10 +22,10 @@
#include "services/abstract/rootitem.h" #include "services/abstract/rootitem.h"
#include <QDateTime> #include <QDateTime>
#include <QString>
#include <QIcon> #include <QIcon>
#include <QNetworkReply>
#include <QJsonObject> #include <QJsonObject>
#include <QNetworkReply>
#include <QString>
class OwnCloudResponse { class OwnCloudResponse {