All messages methods working, some tweaks.
This commit is contained in:
parent
85c1c9229a
commit
e504d619c1
@ -58,18 +58,21 @@ void MessagesModel::setupFonts() {
|
|||||||
void MessagesModel::loadMessages(const QList<int> feed_ids) {
|
void MessagesModel::loadMessages(const QList<int> feed_ids) {
|
||||||
// Conversion of parameter.
|
// Conversion of parameter.
|
||||||
m_currentFeeds = feed_ids;
|
m_currentFeeds = feed_ids;
|
||||||
QStringList stringy_ids;
|
|
||||||
stringy_ids.reserve(feed_ids.count());
|
|
||||||
|
|
||||||
foreach (int feed_id, feed_ids) {
|
setFilter(QString("feed IN (%1) AND deleted = 0").arg(textualFeeds().join(", ")));
|
||||||
|
select();
|
||||||
|
fetchAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList MessagesModel::textualFeeds() const {
|
||||||
|
QStringList stringy_ids;
|
||||||
|
stringy_ids.reserve(m_currentFeeds.count());
|
||||||
|
|
||||||
|
foreach (int feed_id, m_currentFeeds) {
|
||||||
stringy_ids.append(QString::number(feed_id));
|
stringy_ids.append(QString::number(feed_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Enable when time is right.
|
return stringy_ids;
|
||||||
setFilter(QString("feed IN (%1) AND deleted = 0").arg(stringy_ids.join(", ")));
|
|
||||||
//setFilter(QString("deleted = 0").arg(stringy_ids.join(",")));
|
|
||||||
select();
|
|
||||||
fetchAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int MessagesModel::messageId(int row_index) const {
|
int MessagesModel::messageId(int row_index) const {
|
||||||
@ -316,6 +319,9 @@ bool MessagesModel::switchBatchMessageImportance(const QModelIndexList &messages
|
|||||||
query_delete_msg.bindValue(":id", message_id);
|
query_delete_msg.bindValue(":id", message_id);
|
||||||
query_delete_msg.bindValue(":important",
|
query_delete_msg.bindValue(":important",
|
||||||
importance == 1 ? 0 : 1);
|
importance == 1 ? 0 : 1);
|
||||||
|
|
||||||
|
// TODO: dat u vsech funkci ty execy do ifu a kdyz
|
||||||
|
// vratijou false tak udela rollback a vratit funkci s hodnotou false.
|
||||||
query_delete_msg.exec();
|
query_delete_msg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,7 +420,39 @@ bool MessagesModel::setAllMessagesDeleted(int deleted) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool MessagesModel::setAllMessagesRead(int read) {
|
bool MessagesModel::setAllMessagesRead(int read) {
|
||||||
|
QSqlDatabase db_handle = database();
|
||||||
|
|
||||||
|
if (!db_handle.transaction()) {
|
||||||
|
qWarning("Starting transaction for all message read change.");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSqlQuery query_read_msg(db_handle);
|
||||||
|
if (!query_read_msg.prepare(QString("UPDATE messages SET read = :read "
|
||||||
|
"WHERE feed IN (%1) AND deleted = 0").arg(textualFeeds().join(", ")))) {
|
||||||
|
qWarning("Query preparation failed for message read change.");
|
||||||
|
|
||||||
|
db_handle.rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
query_read_msg.bindValue(":read", read);
|
||||||
|
|
||||||
|
if (!query_read_msg.exec()) {
|
||||||
|
qDebug("Query execution for all message read change failed.");
|
||||||
|
db_handle.rollback();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit changes.
|
||||||
|
if (db_handle.commit()) {
|
||||||
|
// FULLY reload the model if underlying data is changed.
|
||||||
|
select();
|
||||||
|
fetchAll();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return db_handle.rollback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MessagesModel::headerData(int section,
|
QVariant MessagesModel::headerData(int section,
|
||||||
|
@ -81,13 +81,16 @@ class MessagesModel : public QSqlTableModel {
|
|||||||
// Loads messages of given feeds.
|
// Loads messages of given feeds.
|
||||||
void loadMessages(const QList<int> feed_ids);
|
void loadMessages(const QList<int> feed_ids);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
QStringList textualFeeds() const;
|
||||||
|
|
||||||
// Sets up header data.
|
// Sets up header data.
|
||||||
void setupHeaderData();
|
void setupHeaderData();
|
||||||
|
|
||||||
// Creates "normal" and "bold" fonts.
|
// Creates "normal" and "bold" fonts.
|
||||||
void setupFonts();
|
void setupFonts();
|
||||||
|
|
||||||
|
private:
|
||||||
QList<int> m_currentFeeds;
|
QList<int> m_currentFeeds;
|
||||||
QList<QString> m_headerData;
|
QList<QString> m_headerData;
|
||||||
QList<QString> m_tooltipData;
|
QList<QString> m_tooltipData;
|
||||||
|
@ -58,6 +58,8 @@ void FeedMessageViewer::createConnections() {
|
|||||||
SIGNAL(triggered()), m_messagesView, SLOT(openSelectedSourceMessagesInternally()));
|
SIGNAL(triggered()), m_messagesView, SLOT(openSelectedSourceMessagesInternally()));
|
||||||
connect(FormMain::getInstance()->m_ui->m_actionOpenSelectedMessagesInternally,
|
connect(FormMain::getInstance()->m_ui->m_actionOpenSelectedMessagesInternally,
|
||||||
SIGNAL(triggered()), m_messagesView, SLOT(openSelectedMessagesInternally()));
|
SIGNAL(triggered()), m_messagesView, SLOT(openSelectedMessagesInternally()));
|
||||||
|
connect(FormMain::getInstance()->m_ui->m_actionMarkAllMessagesAsRead,
|
||||||
|
SIGNAL(triggered()), m_messagesView, SLOT(setAllMessagesRead()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedMessageViewer::initialize() {
|
void FeedMessageViewer::initialize() {
|
||||||
|
@ -338,10 +338,7 @@
|
|||||||
<string>Mark &all messages read</string>
|
<string>Mark &all messages read</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Mark all messages read.</string>
|
<string>Mark all messages from selected feeds read. This does NOT take message filters into account.</string>
|
||||||
</property>
|
|
||||||
<property name="shortcut">
|
|
||||||
<string notr="true"/>
|
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="m_actionMarkAllMessagesAsUnread">
|
<action name="m_actionMarkAllMessagesAsUnread">
|
||||||
@ -349,10 +346,7 @@
|
|||||||
<string>Mark a&ll messages unread</string>
|
<string>Mark a&ll messages unread</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Mark all messages unread.</string>
|
<string>Mark all messages from selected feeds unread. This does NOT take message filters into account.</string>
|
||||||
</property>
|
|
||||||
<property name="shortcut">
|
|
||||||
<string notr="true"/>
|
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="m_actionDeleteSelectedMessages">
|
<action name="m_actionDeleteSelectedMessages">
|
||||||
@ -371,10 +365,7 @@
|
|||||||
<string>Dele&te all messages</string>
|
<string>Dele&te all messages</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Delete all messages.</string>
|
<string>Delete all messages from selected feeds. This does NOT take message filters into account.</string>
|
||||||
</property>
|
|
||||||
<property name="shortcut">
|
|
||||||
<string notr="true"/>
|
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="m_actionAddNewFeed">
|
<action name="m_actionAddNewFeed">
|
||||||
|
@ -299,6 +299,42 @@ void MessagesView::switchSelectedMessagesImportance() {
|
|||||||
reselectIndexes(selected_indexes);
|
reselectIndexes(selected_indexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MessagesView::setAllMessagesReadStatus(int read) {
|
||||||
|
QModelIndex current_index = selectionModel()->currentIndex();
|
||||||
|
QModelIndex mapped_current_index = m_proxyModel->mapToSource(current_index);
|
||||||
|
QModelIndexList selected_indexes = selectionModel()->selectedRows();
|
||||||
|
QModelIndexList mapped_indexes = m_proxyModel->mapListToSource(selected_indexes);
|
||||||
|
|
||||||
|
m_sourceModel->setAllMessagesRead(read);
|
||||||
|
sortByColumn(header()->sortIndicatorSection(), header()->sortIndicatorOrder());
|
||||||
|
|
||||||
|
selected_indexes = m_proxyModel->mapListFromSource(mapped_indexes, true);
|
||||||
|
current_index = m_proxyModel->mapFromSource(m_sourceModel->index(mapped_current_index.row(),
|
||||||
|
mapped_current_index.column()));
|
||||||
|
|
||||||
|
if (read == 0) {
|
||||||
|
// User selected to mark some messages as unread, if one
|
||||||
|
// of them will be marked as current, then it will be read again.
|
||||||
|
blockSignals(true);
|
||||||
|
setCurrentIndex(current_index);
|
||||||
|
blockSignals(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setCurrentIndex(current_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollTo(current_index);
|
||||||
|
reselectIndexes(selected_indexes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessagesView::setAllMessagesRead() {
|
||||||
|
setAllMessagesReadStatus(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessagesView::setAllMessagesUnread() {
|
||||||
|
setAllMessagesReadStatus(0);
|
||||||
|
}
|
||||||
|
|
||||||
void MessagesView::reselectIndexes(const QModelIndexList &indexes) {
|
void MessagesView::reselectIndexes(const QModelIndexList &indexes) {
|
||||||
selectionModel()->clearSelection();
|
selectionModel()->clearSelection();
|
||||||
|
|
||||||
|
@ -36,6 +36,10 @@ class MessagesView : public QTreeView {
|
|||||||
void deleteSelectedMessages();
|
void deleteSelectedMessages();
|
||||||
void switchSelectedMessagesImportance();
|
void switchSelectedMessagesImportance();
|
||||||
|
|
||||||
|
void setAllMessagesReadStatus(int read);
|
||||||
|
void setAllMessagesRead();
|
||||||
|
void setAllMessagesUnread();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
// Marks given indexes as selected.
|
// Marks given indexes as selected.
|
||||||
void reselectIndexes(const QModelIndexList &indexes);
|
void reselectIndexes(const QModelIndexList &indexes);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user