Skip to content

Commit 2a4d2a3

Browse files
committed
some enhancements to notifications and database behavior
1 parent bfeba1b commit 2a4d2a3

9 files changed

Lines changed: 41 additions & 30 deletions

File tree

src/librssguard/core/messagesproxymodel.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ void MessagesProxyModel::initializeFilters() {
109109
};
110110

111111
m_filters[MessageListFilter::ShowOnlyWithScore] = [this](int msg_row_index) {
112-
const int msg_score = m_sourceModel->data(msg_row_index, MSG_MDL_SCORE_INDEX, Qt::ItemDataRole::EditRole).toDouble();
112+
const int msg_score =
113+
m_sourceModel->data(msg_row_index, MSG_MDL_SCORE_INDEX, Qt::ItemDataRole::EditRole).toDouble();
113114

114115
return msg_score > MSG_SCORE_MIN;
115116
};
@@ -148,21 +149,6 @@ QModelIndex MessagesProxyModel::getNextPreviousUnreadItemIndex(int default_row)
148149
return next_index;
149150
}
150151

151-
QModelIndex MessagesProxyModel::indexFromMessage(const Message& msg) const {
152-
for (int i = 0; i < rowCount(); i++) {
153-
auto idx = index(i, 0);
154-
auto id =
155-
m_sourceModel->data(m_sourceModel->index(mapToSource(idx).row(), MSG_MDL_ID_INDEX), Qt::ItemDataRole::EditRole)
156-
.toInt();
157-
158-
if (id == msg.m_id) {
159-
return idx;
160-
}
161-
}
162-
163-
return QModelIndex();
164-
}
165-
166152
QModelIndex MessagesProxyModel::getNextUnreadItemIndex(int default_row, int max_row) const {
167153
while (default_row <= max_row) {
168154
// Get info if the message is read or not.

src/librssguard/core/messagesproxymodel.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class MessagesProxyModel : public QSortFilterProxyModel {
3434

3535
QModelIndex getNextPreviousUnreadItemIndex(int default_row) const;
3636

37-
QModelIndex indexFromMessage(const Message& msg) const;
38-
3937
// Maps list of indexes.
4038
QModelIndexList mapListToSource(const QModelIndexList& indexes) const;
4139
QModelIndexList mapListFromSource(const QModelIndexList& indexes, bool deep = false) const;

src/librssguard/database/databasedriver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "database/sqlquery.h"
66
#include "definitions/definitions.h"
77
#include "exceptions/applicationexception.h"
8+
#include "exceptions/sqlexception.h"
89
#include "gui/messagebox.h"
910
#include "miscellaneous/iofactory.h"
1011
#include "miscellaneous/thread.h"
@@ -132,7 +133,8 @@ void DatabaseDriver::updateDatabaseSchema(QSqlDatabase& db, const QString& datab
132133
int installed_db_schema = query_db.value(0).toString().toInt();
133134

134135
if (installed_db_schema < lowest_version) {
135-
throw ApplicationException(tr("this database file cannot be used because it comes from old major app version"));
136+
throw SqlException(SqlException::Type::TooOldIncompatibleDbSchema,
137+
tr("this database file cannot be used because it comes from old major app version"));
136138
}
137139

138140
if (installed_db_schema > current_version) {

src/librssguard/database/databasefactory.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ void DatabaseFactory::determineDriver() {
4747
qCriticalNN << LOGSEC_DB << "Failed to reach connection to DB source:" << QUOTE_W_SPACE_DOT(ex.message());
4848

4949
if (m_dbDriver->driverType() != DatabaseDriver::DriverType::SQLite) {
50-
MsgBox::show(nullptr,
51-
QMessageBox::Icon::Critical,
52-
tr("Cannot connect to database"),
53-
tr("Connection to your database was not established with error: %1. "
54-
"Falling back to SQLite.")
55-
.arg(ex.message()));
50+
MsgBox::
51+
show(nullptr,
52+
QMessageBox::Icon::Critical,
53+
tr("Cannot connect to database"),
54+
tr("Connection to your database was not established with error: %1. \n\nMaybe change used database name "
55+
"in settings and try again. Falling back to SQLite.")
56+
.arg(ex.message()));
5657

5758
m_dbDriver = qlinq::from(m_allDbDrivers).first([](DatabaseDriver* driv) {
5859
return driv->driverType() == DatabaseDriver::DriverType::SQLite;

src/librssguard/definitions/definitions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
#define MAX_NUMBER_OF_REDIRECTIONS 4
104104

105105
#define NOTIFICATIONS_MARGIN 16
106-
#define NOTIFICATIONS_WIDTH 300
106+
#define NOTIFICATIONS_WIDTH 350
107107
#define NOTIFICATIONS_TIMEOUT 10s
108108
#define NOTIFICATION_SHORT_TIMEOUT 3s
109109
#define NOTIFICATIONS_PAGE_SIZE 10

src/librssguard/exceptions/sqlexception.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
#include "definitions/definitions.h"
66

7+
SqlException::SqlException(Type type, const QString& message) : ApplicationException(message), m_type(type) {}
8+
79
SqlException::SqlException(const QSqlError& error, const QString& file, int line)
8-
: ApplicationException(messageForError(error), file, line) {}
10+
: ApplicationException(messageForError(error), file, line), m_type(Type::GeneralError) {}
911

1012
QString SqlException::messageForError(const QSqlError& error) const {
1113
if (!error.isValid()) {
@@ -21,3 +23,11 @@ QString SqlException::messageForError(const QSqlError& error) const {
2123
return QSL("%1/%2").arg(error_code, error.text());
2224
}
2325
}
26+
27+
SqlException::Type SqlException::type() const {
28+
return m_type;
29+
}
30+
31+
void SqlException::setType(Type type) {
32+
m_type = type;
33+
}

src/librssguard/exceptions/sqlexception.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,21 @@
99

1010
class RSSGUARD_DLLSPEC SqlException : public ApplicationException {
1111
public:
12+
enum class Type {
13+
GeneralError,
14+
TooOldIncompatibleDbSchema
15+
};
16+
17+
explicit SqlException(Type type, const QString& message = {});
1218
explicit SqlException(const QSqlError& error, const QString& file = QString(), int line = 0);
1319

20+
Type type() const;
21+
void setType(Type type);
22+
1423
private:
1524
QString messageForError(const QSqlError& error) const;
25+
26+
Type m_type;
1627
};
1728

1829
#endif // SQLEXCEPTION_H

src/librssguard/gui/feedmessageviewer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,12 @@ void FeedMessageViewer::loadMessageToFeedAndArticleList(Feed* feed, const Messag
256256

257257
m_feedsView->setExpanded(idx_map, true);
258258
m_feedsView->setCurrentIndex(idx_map);
259+
259260
QCoreApplication::processEvents();
260261

261-
auto idx_map_msg = m_messagesView->model()->indexFromMessage(message);
262-
auto msg_is_visible = !m_messagesView->isRowHidden(idx_map_msg.row(), idx_map_msg);
262+
auto idx_map_msg =
263+
m_messagesView->model()->mapFromSource(m_messagesView->sourceModel()->indexForMessage(message.m_id));
264+
auto msg_is_visible = !m_messagesView->isRowHidden(idx_map_msg.row(), QModelIndex());
263265

264266
if (!idx_map_msg.isValid() || !msg_is_visible) {
265267
qApp->showGuiMessage(Notification::Event::GeneralEvent,
@@ -272,6 +274,7 @@ void FeedMessageViewer::loadMessageToFeedAndArticleList(Feed* feed, const Messag
272274
}
273275

274276
m_messagesView->setCurrentIndex(idx_map_msg);
277+
m_messagesView->scrollTo(idx_map_msg, QAbstractItemView::ScrollHint::PositionAtCenter);
275278
}
276279

277280
void FeedMessageViewer::onMessageRemoved(RootItem* root) {

src/librssguard/gui/notifications/articlelistnotification.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void ArticleListNotification::loadResults(const QHash<Feed*, QList<Message>>& ne
8888
}
8989

9090
if (m_newMessages[fd].size() > 0) {
91-
m_ui.m_cmbFeeds->addItem(fd->sanitizedTitle(), QVariant::fromValue(fd));
91+
m_ui.m_cmbFeeds->addItem(fd->fullIcon(), fd->sanitizedTitle(), QVariant::fromValue(fd));
9292
}
9393
}
9494

0 commit comments

Comments
 (0)