adding and loading of probes works
This commit is contained in:
parent
e952debbaf
commit
037633d977
@ -288,6 +288,55 @@ bool DatabaseQueries::createLabel(const QSqlDatabase& db, Label* label, int acco
|
|||||||
return q.exec() && res;
|
return q.exec() && res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DatabaseQueries::createProbe(const QSqlDatabase& db, Search* probe, int account_id) {
|
||||||
|
QSqlQuery q(db);
|
||||||
|
|
||||||
|
q.setForwardOnly(true);
|
||||||
|
q.prepare(QSL("INSERT INTO Probes (name, color, fltr, account_id) "
|
||||||
|
"VALUES (:name, :color, :fltr, :account_id);"));
|
||||||
|
q.bindValue(QSL(":name"), probe->title());
|
||||||
|
q.bindValue(QSL(":fltr"), probe->filter());
|
||||||
|
q.bindValue(QSL(":color"), probe->color().name());
|
||||||
|
q.bindValue(QSL(":account_id"), account_id);
|
||||||
|
|
||||||
|
auto res = q.exec();
|
||||||
|
|
||||||
|
if (res && q.lastInsertId().isValid()) {
|
||||||
|
probe->setId(q.lastInsertId().toInt());
|
||||||
|
probe->setCustomId(QString::number(probe->id()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw ApplicationException(q.lastError().text());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Search*> DatabaseQueries::getProbesForAccount(const QSqlDatabase& db, int account_id) {
|
||||||
|
QList<Search*> probes;
|
||||||
|
QSqlQuery q(db);
|
||||||
|
|
||||||
|
q.setForwardOnly(true);
|
||||||
|
q.prepare(QSL("SELECT * FROM Probes WHERE account_id = :account_id;"));
|
||||||
|
q.bindValue(QSL(":account_id"), account_id);
|
||||||
|
|
||||||
|
if (q.exec()) {
|
||||||
|
while (q.next()) {
|
||||||
|
Search* prob = new Search(q.value(QSL("name")).toString(),
|
||||||
|
q.value(QSL("fltr")).toString(),
|
||||||
|
QColor(q.value(QSL("color")).toString()));
|
||||||
|
|
||||||
|
prob->setId(q.value(QSL("id")).toInt());
|
||||||
|
prob->setCustomId(QString::number(prob->id()));
|
||||||
|
|
||||||
|
probes << prob;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw ApplicationException(q.lastError().text());
|
||||||
|
}
|
||||||
|
|
||||||
|
return probes;
|
||||||
|
}
|
||||||
|
|
||||||
bool DatabaseQueries::markLabelledMessagesReadUnread(const QSqlDatabase& db, Label* label, RootItem::ReadStatus read) {
|
bool DatabaseQueries::markLabelledMessagesReadUnread(const QSqlDatabase& db, Label* label, RootItem::ReadStatus read) {
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "miscellaneous/textfactory.h"
|
#include "miscellaneous/textfactory.h"
|
||||||
#include "services/abstract/category.h"
|
#include "services/abstract/category.h"
|
||||||
#include "services/abstract/label.h"
|
#include "services/abstract/label.h"
|
||||||
|
#include "services/abstract/search.h"
|
||||||
#include "services/abstract/serviceroot.h"
|
#include "services/abstract/serviceroot.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
@ -46,6 +47,10 @@ class DatabaseQueries {
|
|||||||
static bool deleteLabel(const QSqlDatabase& db, Label* label);
|
static bool deleteLabel(const QSqlDatabase& db, Label* label);
|
||||||
static bool createLabel(const QSqlDatabase& db, Label* label, int account_id);
|
static bool createLabel(const QSqlDatabase& db, Label* label, int account_id);
|
||||||
|
|
||||||
|
// Probe operators.
|
||||||
|
static void createProbe(const QSqlDatabase& db, Search* probe, int account_id);
|
||||||
|
static QList<Search*> getProbesForAccount(const QSqlDatabase& db, int account_id);
|
||||||
|
|
||||||
// Message operators.
|
// Message operators.
|
||||||
static bool markLabelledMessagesReadUnread(const QSqlDatabase& db, Label* label, RootItem::ReadStatus read);
|
static bool markLabelledMessagesReadUnread(const QSqlDatabase& db, Label* label, RootItem::ReadStatus read);
|
||||||
static bool markImportantMessagesReadUnread(const QSqlDatabase& db, int account_id, RootItem::ReadStatus read);
|
static bool markImportantMessagesReadUnread(const QSqlDatabase& db, int account_id, RootItem::ReadStatus read);
|
||||||
@ -143,7 +148,8 @@ class DatabaseQueries {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
static QList<ServiceRoot*> getAccounts(const QSqlDatabase& db, const QString& code, bool* ok = nullptr);
|
static QList<ServiceRoot*> getAccounts(const QSqlDatabase& db, const QString& code, bool* ok = nullptr);
|
||||||
|
|
||||||
template <typename Categ, typename Fee> static void loadRootFromDatabase(ServiceRoot* root);
|
template <typename Categ, typename Fee>
|
||||||
|
static void loadRootFromDatabase(ServiceRoot* root);
|
||||||
static bool storeNewOauthTokens(const QSqlDatabase& db, const QString& refresh_token, int account_id);
|
static bool storeNewOauthTokens(const QSqlDatabase& db, const QString& refresh_token, int account_id);
|
||||||
static void createOverwriteAccount(const QSqlDatabase& db, ServiceRoot* account);
|
static void createOverwriteAccount(const QSqlDatabase& db, ServiceRoot* account);
|
||||||
|
|
||||||
@ -169,7 +175,8 @@ class DatabaseQueries {
|
|||||||
static bool deleteFeed(const QSqlDatabase& db, Feed* feed, int account_id);
|
static bool deleteFeed(const QSqlDatabase& db, Feed* feed, int account_id);
|
||||||
static bool deleteCategory(const QSqlDatabase& db, Category* category);
|
static bool deleteCategory(const QSqlDatabase& db, Category* category);
|
||||||
|
|
||||||
template <typename T> static Assignment getCategories(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
|
template <typename T>
|
||||||
|
static Assignment getCategories(const QSqlDatabase& db, int account_id, bool* ok = nullptr);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static Assignment getFeeds(const QSqlDatabase& db,
|
static Assignment getFeeds(const QSqlDatabase& db,
|
||||||
@ -249,7 +256,8 @@ QList<ServiceRoot*> DatabaseQueries::getAccounts(const QSqlDatabase& db, const Q
|
|||||||
return roots;
|
return roots;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> Assignment DatabaseQueries::getCategories(const QSqlDatabase& db, int account_id, bool* ok) {
|
template <typename T>
|
||||||
|
Assignment DatabaseQueries::getCategories(const QSqlDatabase& db, int account_id, bool* ok) {
|
||||||
Assignment categories;
|
Assignment categories;
|
||||||
|
|
||||||
// Obtain data for categories from the database.
|
// Obtain data for categories from the database.
|
||||||
@ -381,13 +389,15 @@ Assignment DatabaseQueries::getFeeds(const QSqlDatabase& db,
|
|||||||
return feeds;
|
return feeds;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Categ, typename Fee> void DatabaseQueries::loadRootFromDatabase(ServiceRoot* root) {
|
template <typename Categ, typename Fee>
|
||||||
|
void DatabaseQueries::loadRootFromDatabase(ServiceRoot* root) {
|
||||||
QSqlDatabase database = qApp->database()->driver()->connection(root->metaObject()->className());
|
QSqlDatabase database = qApp->database()->driver()->connection(root->metaObject()->className());
|
||||||
Assignment categories = DatabaseQueries::getCategories<Categ>(database, root->accountId());
|
Assignment categories = DatabaseQueries::getCategories<Categ>(database, root->accountId());
|
||||||
Assignment feeds = DatabaseQueries::getFeeds<Fee>(database, qApp->feedReader()->messageFilters(), root->accountId());
|
Assignment feeds = DatabaseQueries::getFeeds<Fee>(database, qApp->feedReader()->messageFilters(), root->accountId());
|
||||||
auto labels = DatabaseQueries::getLabelsForAccount(database, root->accountId());
|
auto labels = DatabaseQueries::getLabelsForAccount(database, root->accountId());
|
||||||
|
auto probes = DatabaseQueries::getProbesForAccount(database, root->accountId());
|
||||||
|
|
||||||
root->performInitialAssembly(categories, feeds, labels);
|
root->performInitialAssembly(categories, feeds, labels, probes);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // DATABASEQUERIES_H
|
#endif // DATABASEQUERIES_H
|
||||||
|
@ -601,8 +601,8 @@ void FeedsView::onIndexExpanded(const QModelIndex& idx) {
|
|||||||
|
|
||||||
const RootItem* it = m_sourceModel->itemForIndex(m_proxyModel->mapToSource(idx));
|
const RootItem* it = m_sourceModel->itemForIndex(m_proxyModel->mapToSource(idx));
|
||||||
|
|
||||||
if (it != nullptr &&
|
if (it != nullptr && (int(it->kind()) & int(RootItem::Kind::Category | RootItem::Kind::ServiceRoot |
|
||||||
(int(it->kind()) & int(RootItem::Kind::Category | RootItem::Kind::ServiceRoot | RootItem::Kind::Labels)) > 0) {
|
RootItem::Kind::Labels | RootItem::Kind::Probes)) > 0) {
|
||||||
const QString setting_name = it->hashCode();
|
const QString setting_name = it->hashCode();
|
||||||
|
|
||||||
qApp->settings()->setValue(GROUP(CategoriesExpandStates), setting_name, true);
|
qApp->settings()->setValue(GROUP(CategoriesExpandStates), setting_name, true);
|
||||||
@ -619,8 +619,8 @@ void FeedsView::onIndexCollapsed(const QModelIndex& idx) {
|
|||||||
|
|
||||||
RootItem* it = m_sourceModel->itemForIndex(m_proxyModel->mapToSource(idx));
|
RootItem* it = m_sourceModel->itemForIndex(m_proxyModel->mapToSource(idx));
|
||||||
|
|
||||||
if (it != nullptr &&
|
if (it != nullptr && (int(it->kind()) & int(RootItem::Kind::Category | RootItem::Kind::ServiceRoot |
|
||||||
(int(it->kind()) & int(RootItem::Kind::Category | RootItem::Kind::ServiceRoot | RootItem::Kind::Labels)) > 0) {
|
RootItem::Kind::Labels | RootItem::Kind::Probes)) > 0) {
|
||||||
const QString setting_name = it->hashCode();
|
const QString setting_name = it->hashCode();
|
||||||
|
|
||||||
qApp->settings()->setValue(GROUP(CategoriesExpandStates), setting_name, false);
|
qApp->settings()->setValue(GROUP(CategoriesExpandStates), setting_name, false);
|
||||||
@ -637,8 +637,8 @@ void FeedsView::saveAllExpandStates() {
|
|||||||
|
|
||||||
void FeedsView::saveExpandStates(RootItem* item) {
|
void FeedsView::saveExpandStates(RootItem* item) {
|
||||||
Settings* settings = qApp->settings();
|
Settings* settings = qApp->settings();
|
||||||
QList<RootItem*> items =
|
QList<RootItem*> items = item->getSubTree(RootItem::Kind::Category | RootItem::Kind::ServiceRoot |
|
||||||
item->getSubTree(RootItem::Kind::Category | RootItem::Kind::ServiceRoot | RootItem::Kind::Labels);
|
RootItem::Kind::Labels | RootItem::Kind::Probes);
|
||||||
|
|
||||||
// Iterate all categories and save their expand statuses.
|
// Iterate all categories and save their expand statuses.
|
||||||
for (const RootItem* it : items) {
|
for (const RootItem* it : items) {
|
||||||
@ -655,7 +655,7 @@ void FeedsView::loadAllExpandStates() {
|
|||||||
QList<RootItem*> expandable_items;
|
QList<RootItem*> expandable_items;
|
||||||
|
|
||||||
expandable_items.append(sourceModel()->rootItem()->getSubTree(RootItem::Kind::Category | RootItem::Kind::ServiceRoot |
|
expandable_items.append(sourceModel()->rootItem()->getSubTree(RootItem::Kind::Category | RootItem::Kind::ServiceRoot |
|
||||||
RootItem::Kind::Labels));
|
RootItem::Kind::Labels | RootItem::Kind::Probes));
|
||||||
|
|
||||||
// Iterate all categories and save their expand statuses.
|
// Iterate all categories and save their expand statuses.
|
||||||
for (const RootItem* item : expandable_items) {
|
for (const RootItem* item : expandable_items) {
|
||||||
|
@ -14,15 +14,16 @@ FormAddEditProbe::FormAddEditProbe(QWidget* parent) : QDialog(parent), m_editabl
|
|||||||
|
|
||||||
connect(m_ui.m_txtName->lineEdit(), &QLineEdit::textChanged, this, [this](const QString& text) {
|
connect(m_ui.m_txtName->lineEdit(), &QLineEdit::textChanged, this, [this](const QString& text) {
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
m_ui.m_txtName->setStatus(LineEditWithStatus::StatusType::Error, tr("Label's name cannot be empty."));
|
m_ui.m_txtName->setStatus(LineEditWithStatus::StatusType::Error, tr("Probe name cannot be empty."));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_ui.m_txtName->setStatus(LineEditWithStatus::StatusType::Ok, tr("Perfect!"));
|
m_ui.m_txtName->setStatus(LineEditWithStatus::StatusType::Ok, tr("Perfect!"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(m_ui.m_txtFilter->lineEdit(), &QLineEdit::textChanged, this, [this](const QString& text) {
|
connect(m_ui.m_txtFilter->lineEdit(), &QLineEdit::textChanged, this, [this](const QString& text) {
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
m_ui.m_txtFilter->setStatus(LineEditWithStatus::StatusType::Error, tr("Probe name cannot be empty."));
|
m_ui.m_txtFilter->setStatus(LineEditWithStatus::StatusType::Error, tr("Probe filter cannot be empty."));
|
||||||
}
|
}
|
||||||
else if (!QRegularExpression(text).isValid()) {
|
else if (!QRegularExpression(text).isValid()) {
|
||||||
m_ui.m_txtFilter->setStatus(LineEditWithStatus::StatusType::Error, tr("Regular expression is not well-formed."));
|
m_ui.m_txtFilter->setStatus(LineEditWithStatus::StatusType::Error, tr("Regular expression is not well-formed."));
|
||||||
|
@ -132,6 +132,7 @@ void LabelsNode::createLabel() {
|
|||||||
DatabaseQueries::createLabel(db, new_lbl, getParentServiceRoot()->accountId());
|
DatabaseQueries::createLabel(db, new_lbl, getParentServiceRoot()->accountId());
|
||||||
|
|
||||||
getParentServiceRoot()->requestItemReassignment(new_lbl, this);
|
getParentServiceRoot()->requestItemReassignment(new_lbl, this);
|
||||||
|
getParentServiceRoot()->requestItemExpand({this}, true);
|
||||||
}
|
}
|
||||||
catch (const ApplicationException&) {
|
catch (const ApplicationException&) {
|
||||||
new_lbl->deleteLater();
|
new_lbl->deleteLater();
|
||||||
|
@ -128,9 +128,10 @@ void SearchsNode::createProbe() {
|
|||||||
QSqlDatabase db = qApp->database()->driver()->connection(metaObject()->className());
|
QSqlDatabase db = qApp->database()->driver()->connection(metaObject()->className());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// DatabaseQueries::createLabel(db, new_prb, getParentServiceRoot()->accountId());
|
DatabaseQueries::createProbe(db, new_prb, getParentServiceRoot()->accountId());
|
||||||
|
|
||||||
getParentServiceRoot()->requestItemReassignment(new_prb, this);
|
getParentServiceRoot()->requestItemReassignment(new_prb, this);
|
||||||
|
getParentServiceRoot()->requestItemExpand({this}, true);
|
||||||
}
|
}
|
||||||
catch (const ApplicationException&) {
|
catch (const ApplicationException&) {
|
||||||
new_prb->deleteLater();
|
new_prb->deleteLater();
|
||||||
|
@ -565,10 +565,13 @@ void ServiceRoot::syncIn() {
|
|||||||
|
|
||||||
void ServiceRoot::performInitialAssembly(const Assignment& categories,
|
void ServiceRoot::performInitialAssembly(const Assignment& categories,
|
||||||
const Assignment& feeds,
|
const Assignment& feeds,
|
||||||
const QList<Label*>& labels) {
|
const QList<Label*>& labels,
|
||||||
|
const QList<Search*>& probes) {
|
||||||
assembleCategories(categories);
|
assembleCategories(categories);
|
||||||
assembleFeeds(feeds);
|
assembleFeeds(feeds);
|
||||||
labelsNode()->loadLabels(labels);
|
labelsNode()->loadLabels(labels);
|
||||||
|
probesNode()->loadProbes(probes);
|
||||||
|
|
||||||
updateCounts(true);
|
updateCounts(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,11 @@ class ServiceRoot : public RootItem {
|
|||||||
Synchronised = 8
|
Synchronised = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class BagOfMessages { Read, Unread, Starred };
|
enum class BagOfMessages {
|
||||||
|
Read,
|
||||||
|
Unread,
|
||||||
|
Starred
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ServiceRoot(RootItem* parent = nullptr);
|
explicit ServiceRoot(RootItem* parent = nullptr);
|
||||||
@ -235,7 +239,10 @@ class ServiceRoot : public RootItem {
|
|||||||
QStringList customIDSOfMessagesForItem(RootItem* item,
|
QStringList customIDSOfMessagesForItem(RootItem* item,
|
||||||
RootItem::ReadStatus target_read = RootItem::ReadStatus::Unknown);
|
RootItem::ReadStatus target_read = RootItem::ReadStatus::Unknown);
|
||||||
|
|
||||||
void performInitialAssembly(const Assignment& categories, const Assignment& feeds, const QList<Label*>& labels);
|
void performInitialAssembly(const Assignment& categories,
|
||||||
|
const Assignment& feeds,
|
||||||
|
const QList<Label*>& labels,
|
||||||
|
const QList<Search*>& probes);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void addNewFeed(RootItem* selected_item, const QString& url = QString());
|
virtual void addNewFeed(RootItem* selected_item, const QString& url = QString());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user