mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-30 17:15:01 +01:00
defs...
This commit is contained in:
parent
f59c09b356
commit
c8b876c24b
@ -119,7 +119,13 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) {
|
||||
}
|
||||
|
||||
QSqlDatabase DatabaseFactory::addConnection(const QString &connection_name) {
|
||||
return initialize(connection_name);
|
||||
if (!m_initialized) {
|
||||
return initialize(connection_name);
|
||||
}
|
||||
else {
|
||||
return QSqlDatabase::addDatabase(DATABASE_DRIVER,
|
||||
connection_name);
|
||||
}
|
||||
}
|
||||
|
||||
QSqlDatabase DatabaseFactory::getConnection(const QString &connection_name) {
|
||||
|
@ -16,12 +16,16 @@ class DatabaseFactory : public QObject {
|
||||
// Assemblies database file path.
|
||||
void assemblyDatabaseFilePath();
|
||||
|
||||
// Returns true if database was initialized, otherwise false.
|
||||
// Creates new connection, initializes database and
|
||||
// returns opened connection.
|
||||
QSqlDatabase initialize(const QString &connection_name);
|
||||
|
||||
// Path to database file.
|
||||
QString m_databasePath;
|
||||
|
||||
// Is database file initialized?
|
||||
bool m_initialized;
|
||||
|
||||
// Private singleton value.
|
||||
static QPointer<DatabaseFactory> s_instance;
|
||||
|
||||
|
@ -87,7 +87,7 @@
|
||||
#define APP_FLAGS_PATH APP_PREFIX + QString("/share/rssguard/flags")
|
||||
#define APP_ICON_PATH APP_PREFIX + QString("/share/icons/hicolor/128x128/apps/@APP_LOW_NAME@.png")
|
||||
#define APP_ICON_PLAIN_PATH APP_PREFIX + QString("/share/icons/hicolor/128x128/apps/@APP_LOW_NAME@_plain.png")
|
||||
#elif defined(Q_OS_WIN)
|
||||
#elif defined(Q_OS_WIN) || defined(Q_OS_OS2)
|
||||
#define APP_LANG_PATH QApplication::applicationDirPath() + QString("/l10n")
|
||||
#define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/skins")
|
||||
#define APP_INFO_PATH QApplication::applicationDirPath()
|
||||
|
@ -12,7 +12,8 @@
|
||||
|
||||
|
||||
MessagesModel::MessagesModel(QObject *parent)
|
||||
: QSqlTableModel(parent, DatabaseFactory::getInstance()->addConnection("MessagesModel")) {
|
||||
: QSqlTableModel(parent,
|
||||
DatabaseFactory::getInstance()->addConnection("MessagesModel")) {
|
||||
setObjectName("MessagesModel");
|
||||
|
||||
setupFonts();
|
||||
@ -68,6 +69,10 @@ void MessagesModel::loadMessages(const QList<int> feed_ids) {
|
||||
fetchAll();
|
||||
}
|
||||
|
||||
int MessagesModel::messageId(int row_index) const {
|
||||
return record(row_index).value(MSG_DB_ID_INDEX).toInt();
|
||||
}
|
||||
|
||||
Message MessagesModel::messageAt(int row_index) const {
|
||||
QSqlRecord rec = record(row_index);
|
||||
Message message;
|
||||
@ -177,6 +182,54 @@ bool MessagesModel::switchMessageImportance(int row_index) {
|
||||
setData(target_index, 1);
|
||||
}
|
||||
|
||||
bool MessagesModel::switchBatchMessageImportance(const QModelIndexList &messages) {
|
||||
// Submit changes first.
|
||||
submitAll();
|
||||
|
||||
if (!database().transaction()) {
|
||||
qWarning("Starting transaction for batch message importance switch failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlDatabase db_handle = database();
|
||||
int message_id, importance;
|
||||
QSqlQuery query_delete_msg(db_handle);
|
||||
if (!query_delete_msg.prepare("UPDATE messages SET important = :important "
|
||||
"WHERE id = :id")) {
|
||||
qWarning("Query preparation failed for message importance switch.");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (const QModelIndex &message, messages) {
|
||||
message_id = messageId(message.row());
|
||||
importance = record(message.row()).value(MSG_DB_IMPORTANT_INDEX).toInt();
|
||||
|
||||
query_delete_msg.bindValue(":id", message_id);
|
||||
query_delete_msg.bindValue(":important",
|
||||
importance == 1 ? 0 : 1);
|
||||
query_delete_msg.exec();
|
||||
}
|
||||
|
||||
// Commit changes.
|
||||
if (db_handle.commit()) {
|
||||
// FULLY reload the model if underlying data is changed.
|
||||
select();
|
||||
fetchAll();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return db_handle.rollback();
|
||||
}
|
||||
}
|
||||
|
||||
bool MessagesModel::setBatchMessagesDeleted(const QModelIndexList &messages, int deleted) {
|
||||
|
||||
}
|
||||
|
||||
bool MessagesModel::setBatchMessagesRead(const QModelIndexList &messages, int read) {
|
||||
|
||||
}
|
||||
|
||||
QVariant MessagesModel::headerData(int section,
|
||||
Qt::Orientation orientation,
|
||||
int role) const {
|
||||
|
@ -46,13 +46,24 @@ class MessagesModel : public QSqlTableModel {
|
||||
|
||||
// Returns message at given index.
|
||||
Message messageAt(int row_index) const;
|
||||
int messageId(int row_index) const;
|
||||
|
||||
public slots:
|
||||
// Message manipulators.
|
||||
// CORE messages manipulators.
|
||||
// NOTE: These are used to change properties of one message.
|
||||
// NOTE: Model is NOT reset after these methods are applied.
|
||||
bool switchMessageImportance(int row_index);
|
||||
bool setMessageDeleted(int row_index, int deleted);
|
||||
bool setMessageRead(int row_index, int read);
|
||||
|
||||
// BATCH messages manipulators.
|
||||
// NOTE: These methods are used for changing of attributes of
|
||||
// many messages via DIRECT SQL calls.
|
||||
// NOTE: Model is reset after these methods is applied.
|
||||
bool switchBatchMessageImportance(const QModelIndexList &messages);
|
||||
bool setBatchMessagesDeleted(const QModelIndexList &messages, int deleted);
|
||||
bool setBatchMessagesRead(const QModelIndexList &messages, int read);
|
||||
|
||||
// Fetches ALL available data to the model.
|
||||
// NOTE: This is almost always needed when sorting
|
||||
// and makes the model more predictable.
|
||||
|
Loading…
x
Reference in New Issue
Block a user