This commit is contained in:
Martin Rotter 2014-09-25 11:06:03 +02:00
parent 451ff0dc4e
commit a8ca78d880
10 changed files with 86 additions and 29 deletions

View File

@ -3,18 +3,18 @@
Fixed: Fixed:
<ul> <ul>
<li>List of actions in toolbar editor now do not allow copying of items.</li> <li>List of actions in toolbar editor now does not allow copying of items.</li>
<li>Keyboard search for message list should now work with Qt 4.</li> <li>Keyboard search for message list should now work with Qt 4.</li>
<li>Overall code cleanups and refactoring primarily in area of feed/message models and recycle bin functionality.</li> <li>Overall code cleanups and refactoring primarily in area of feed/message models and recycle bin functionality.</li>
<li>Fixed bug #66, #67, #69, #64.</li> <li>Fixed bugs #66, #67, #69, #64.</li>
<li>Blau skin now has colored webkit scrollbars, fixed some button widths and enhanced menu popup tool buttons.</li> <li>Blau skin now has colored webkit scrollbars, fixed some button widths and enhanced menu popup tool buttons.</li>
</ul> </ul>
Added: Added:
<ul> <ul>
<li>Top-level recycle bin which displays count of deleted items properly.</li> <li>Recycle bin with ability to trash or restore the whole bin or individual messages.</li>
<li>MySQL backend now alows to defragment/optimize RSS Guard database.</li> <li>MySQL backend now allows to defragment/optimize RSS Guard database.</li>
<li>New blau-based yellow skin.</li> <li>Three new skins, including solarized skin.</li>
</ul> </ul>
Changed: Changed:

View File

@ -32,7 +32,7 @@ FeedsModelRecycleBin::FeedsModelRecycleBin(FeedsModelRootItem *parent)
m_description = tr("Recycle bin contains all deleted messages from all feeds."); m_description = tr("Recycle bin contains all deleted messages from all feeds.");
m_creationDate = QDateTime::currentDateTime(); m_creationDate = QDateTime::currentDateTime();
updateCounts(); updateCounts(true);
} }
FeedsModelRecycleBin::~FeedsModelRecycleBin() { FeedsModelRecycleBin::~FeedsModelRecycleBin() {
@ -48,7 +48,7 @@ void FeedsModelRecycleBin::appendChild(FeedsModelRootItem *child) {
} }
int FeedsModelRecycleBin::countOfUnreadMessages() const { int FeedsModelRecycleBin::countOfUnreadMessages() const {
return m_totalCount; return m_unreadCount;
} }
int FeedsModelRecycleBin::countOfAllMessages() const { int FeedsModelRecycleBin::countOfAllMessages() const {
@ -166,12 +166,20 @@ bool FeedsModelRecycleBin::restore() {
} }
} }
void FeedsModelRecycleBin::updateCounts() { void FeedsModelRecycleBin::updateCounts(bool update_total_count) {
QSqlDatabase database = qApp->database()->connection("FeedsModelRecycleBin", QSqlDatabase database = qApp->database()->connection("FeedsModelRecycleBin",
DatabaseFactory::FromSettings); DatabaseFactory::FromSettings);
QSqlQuery query_all(database); QSqlQuery query_all(database);
query_all.setForwardOnly(true); query_all.setForwardOnly(true);
if (query_all.exec("SELECT count(*) FROM Messages WHERE is_read = 0 AND is_deleted = 1;") && query_all.next()) {
m_unreadCount = query_all.value(0).toInt();
}
else {
m_unreadCount = 0;
}
if (update_total_count) {
if (query_all.exec("SELECT count(*) FROM Messages WHERE is_deleted = 1;") && query_all.next()) { if (query_all.exec("SELECT count(*) FROM Messages WHERE is_deleted = 1;") && query_all.next()) {
m_totalCount = query_all.value(0).toInt(); m_totalCount = query_all.value(0).toInt();
} }
@ -179,3 +187,4 @@ void FeedsModelRecycleBin::updateCounts() {
m_totalCount = 0; m_totalCount = 0;
} }
} }
}

View File

@ -40,10 +40,11 @@ class FeedsModelRecycleBin : public FeedsModelRootItem {
bool restore(); bool restore();
public slots: public slots:
void updateCounts(); void updateCounts(bool update_total_count);
private: private:
int m_totalCount; int m_totalCount;
int m_unreadCount;
}; };
#endif // FEEDSMODELRECYCLEBIN_H #endif // FEEDSMODELRECYCLEBIN_H

View File

@ -262,9 +262,8 @@ bool MessagesModel::setMessageRead(int row_index, int read) {
if (db_handle.commit()) { if (db_handle.commit()) {
// If commit succeeded, then emit changes, so that view // If commit succeeded, then emit changes, so that view
// can reflect. // can reflect.
emit dataChanged(index(row_index, 0), emit dataChanged(index(row_index, 0), index(row_index, columnCount() - 1));
index(row_index, columnCount() - 1)); emit messageCountsChanged(m_messageMode, false, false);
emit messageCountsChanged(false);
return true; return true;
} }
else { else {
@ -375,7 +374,7 @@ bool MessagesModel::setBatchMessagesDeleted(const QModelIndexList &messages, int
select(); select();
fetchAll(); fetchAll();
emit messageCountsChanged(true); emit messageCountsChanged(m_messageMode, true, false);
return true; return true;
} }
else { else {
@ -400,7 +399,7 @@ bool MessagesModel::setBatchMessagesRead(const QModelIndexList &messages, int re
select(); select();
fetchAll(); fetchAll();
emit messageCountsChanged(true); emit messageCountsChanged(m_messageMode, false, false);
return true; return true;
} }
else { else {
@ -436,7 +435,7 @@ bool MessagesModel::setBatchMessagesRestored(const QModelIndexList &messages) {
select(); select();
fetchAll(); fetchAll();
emit messageCountsChanged(true); emit messageCountsChanged(m_messageMode, true, true);
return true; return true;
} }
else { else {

View File

@ -114,7 +114,9 @@ class MessagesModel : public QSqlTableModel {
signals: signals:
// Emitted if some persistent change is made which affects count of "unread/all" messages. // Emitted if some persistent change is made which affects count of "unread/all" messages.
void messageCountsChanged(bool total_message_number_changed); void messageCountsChanged(MessagesModel::MessageMode mode,
bool total_msg_count_changed,
bool any_msg_restored);
protected: protected:
// Returns selected feed ids in concatenated textual form, // Returns selected feed ids in concatenated textual form,
@ -146,6 +148,7 @@ class MessagesModel : public QSqlTableModel {
QIcon m_unreadIcon; QIcon m_unreadIcon;
}; };
Q_DECLARE_METATYPE(MessagesModel::MessageMode)
Q_DECLARE_METATYPE(MessagesModel::MessageFilter) Q_DECLARE_METATYPE(MessagesModel::MessageFilter)
#endif // MESSAGESMODEL_H #endif // MESSAGESMODEL_H

View File

@ -191,7 +191,8 @@ void FeedMessageViewer::createConnections() {
connect(m_feedsView, SIGNAL(feedsSelected(QList<int>)), m_messagesView, SLOT(loadFeeds(QList<int>))); connect(m_feedsView, SIGNAL(feedsSelected(QList<int>)), m_messagesView, SLOT(loadFeeds(QList<int>)));
// If user changes status of some messages, recalculate message counts. // If user changes status of some messages, recalculate message counts.
connect(m_messagesView, SIGNAL(messageCountsChanged(bool)), m_feedsView, SLOT(updateCountsOfSelectedFeeds(bool))); connect(m_messagesView->sourceModel(), SIGNAL(messageCountsChanged(MessagesModel::MessageMode,bool,bool)),
m_feedsView, SLOT(receiveMessageCountsChange(MessagesModel::MessageMode,bool,bool)));
// State of many messages is changed, then we need // State of many messages is changed, then we need
// to reload selections. // to reload selections.

View File

@ -291,6 +291,43 @@ void FeedsView::editFeed(FeedsModelFeed *feed) {
delete form_pointer.data(); delete form_pointer.data();
} }
void FeedsView::receiveMessageCountsChange(MessagesModel::MessageMode mode,
bool total_msg_count_changed,
bool any_msg_restored) {
// If the change came from recycle bin mode, then:
// a) total count of message was changed AND no message was restored - some messages
// were permanently deleted from recycle bin --> we need to update counts of
// just recycle bin, including total counts.
// b) total count of message was changed AND some message was restored - some messages
// were restored --> we need to update counts from all items and bin, including total counts.
// c) total count of message was not changed - state of some messages was switched, no
// deletings or restorings were made --> update counts of just recycle bin, excluding total counts.
//
// If the change came from feed mode, then:
// a) total count of message was changed - some messages were deleted --> we need to update
// counts of recycle bin, including total counts and update counts of selected feeds, including
// total counts.
// b) total count of message was not changed - some messages switched state --> we need to update
// counts of just selected feeds.
if (mode == MessagesModel::MessagesFromRecycleBin) {
if (total_msg_count_changed) {
if (any_msg_restored) {
updateCountsOfAllFeeds(true);
}
else {
updateCountsOfRecycleBin(true);
}
}
else {
updateCountsOfRecycleBin(false);
}
}
else {
updateCountsOfSelectedFeeds(total_msg_count_changed);
}
}
void FeedsView::editSelectedItem() { void FeedsView::editSelectedItem() {
if (!qApp->closeLock()->tryLock()) { if (!qApp->closeLock()->tryLock()) {
// Lock was not obtained because // Lock was not obtained because
@ -434,7 +471,7 @@ void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) {
if (update_total_too) { if (update_total_too) {
// Number of items in recycle bin has changed. // Number of items in recycle bin has changed.
m_sourceModel->recycleBin()->updateCounts(); m_sourceModel->recycleBin()->updateCounts(true);
// We need to refresh data for recycle bin too. // We need to refresh data for recycle bin too.
selected_indexes.append(m_sourceModel->indexForItem(m_sourceModel->recycleBin())); selected_indexes.append(m_sourceModel->indexForItem(m_sourceModel->recycleBin()));
@ -445,6 +482,12 @@ void FeedsView::updateCountsOfSelectedFeeds(bool update_total_too) {
notifyWithCounts(); notifyWithCounts();
} }
void FeedsView::updateCountsOfRecycleBin(bool update_total_too) {
m_sourceModel->recycleBin()->updateCounts(update_total_too);
m_sourceModel->reloadChangedLayout(QModelIndexList() << m_sourceModel->indexForItem(m_sourceModel->recycleBin()));
notifyWithCounts();
}
void FeedsView::updateCountsOfAllFeeds(bool update_total_too) { void FeedsView::updateCountsOfAllFeeds(bool update_total_too) {
foreach (FeedsModelFeed *feed, allFeeds()) { foreach (FeedsModelFeed *feed, allFeeds()) {
feed->updateCounts(update_total_too); feed->updateCounts(update_total_too);
@ -452,7 +495,7 @@ void FeedsView::updateCountsOfAllFeeds(bool update_total_too) {
if (update_total_too) { if (update_total_too) {
// Number of items in recycle bin has changed. // Number of items in recycle bin has changed.
m_sourceModel->recycleBin()->updateCounts(); m_sourceModel->recycleBin()->updateCounts(true);
} }
// Make sure that all views reloads its data. // Make sure that all views reloads its data.

View File

@ -111,9 +111,17 @@ class FeedsView : public QTreeView {
void addNewFeed(); void addNewFeed();
void editFeed(FeedsModelFeed *feed); void editFeed(FeedsModelFeed *feed);
// Is called when counts of messages are changed externally,
// typically from message view.
void receiveMessageCountsChange(MessagesModel::MessageMode mode,
bool total_msg_count_changed,
bool any_msg_restored);
// Reloads counts for selected feeds. // Reloads counts for selected feeds.
void updateCountsOfSelectedFeeds(bool update_total_too); void updateCountsOfSelectedFeeds(bool update_total_too);
void updateCountsOfRecycleBin(bool update_total_too);
// Reloads counts for all feeds. // Reloads counts for all feeds.
void updateCountsOfAllFeeds(bool update_total_too); void updateCountsOfAllFeeds(bool update_total_too);

View File

@ -51,9 +51,6 @@ MessagesView::~MessagesView() {
} }
void MessagesView::createConnections() { void MessagesView::createConnections() {
// Forward feed counts changes.
connect(m_sourceModel, SIGNAL(messageCountsChanged(bool)), this, SIGNAL(messageCountsChanged(bool)));
// Make sure that source message is opened // Make sure that source message is opened
// in new tab on double click. // in new tab on double click.
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openSelectedSourceMessagesInternally())); connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openSelectedSourceMessagesInternally()));

View File

@ -113,10 +113,6 @@ class MessagesView : public QTreeView {
void currentMessagesChanged(const QList<Message> &messages); void currentMessagesChanged(const QList<Message> &messages);
void currentMessagesRemoved(); void currentMessagesRemoved();
// Emitted if counts of unread/total messages has changed
// because of user interaction with list of messages.
void messageCountsChanged(bool total_message_number_changed);
private: private:
QMenu *m_contextMenu; QMenu *m_contextMenu;