Experimental adding/removing of standard account.

This commit is contained in:
Martin Rotter 2015-11-30 11:13:00 +01:00
parent 84fed7c4ce
commit 51e9d80fbc
8 changed files with 69 additions and 11 deletions

View File

@ -687,6 +687,9 @@ void FeedsModel::reloadWholeLayout() {
bool FeedsModel::addServiceAccount(ServiceRoot *root) {
m_rootItem->appendChild(root);
// Item add, reload da shit.
reloadWholeLayout();
// Connect.
connect(root, SIGNAL(readFeedsFilterInvalidationRequested()), this, SIGNAL(readFeedsFilterInvalidationRequested()));
connect(root, SIGNAL(dataChanged(QList<RootItem*>)), this, SLOT(onItemDataChanged(QList<RootItem*>)));

View File

@ -39,6 +39,7 @@ FormAddAccount::FormAddAccount(const QList<ServiceEntryPoint*> &entry_points, Fe
MessageBox::iconify(m_ui->m_buttonBox);
#endif
connect(m_ui->m_buttonBox, SIGNAL(accepted()), this, SLOT(addSelectedAccount()));
connect(m_ui->m_listEntryPoints, SIGNAL(itemSelectionChanged()), this, SLOT(displayActiveEntryPointDetails()));
loadEntryPoints();
}
@ -47,27 +48,43 @@ FormAddAccount::~FormAddAccount() {
delete m_ui;
}
void FormAddAccount::displayActiveEntryPointDetails() {
QList<QListWidgetItem*> selected_items = m_ui->m_listEntryPoints->selectedItems();
void FormAddAccount::addSelectedAccount() {
accept();
if (!selected_items.isEmpty()) {
ServiceEntryPoint *point = static_cast<ServiceEntryPoint*>(selected_items.at(0)->data(Qt::UserRole).value<void*>());
ServiceEntryPoint *point = selectedEntryPoint();
ServiceRoot *new_root = point->createNewRoot(m_model);
if (new_root != NULL) {
m_model->addServiceAccount(new_root);
}
else {
qApp->showGuiMessage(tr("Cannot add account"),
tr("Some critical error occurred, report this to developers."),
QSystemTrayIcon::Critical, parentWidget(), true);
}
}
void FormAddAccount::displayActiveEntryPointDetails() {
ServiceEntryPoint *point = selectedEntryPoint();
m_ui->m_txtAuthor->setText(point->author());
m_ui->m_txtDescription->setText(point->description());
m_ui->m_txtName->setText(point->name());
m_ui->m_txtVersion->setText(point->version());
}
}
ServiceEntryPoint *FormAddAccount::selectedEntryPoint() {
return m_entryPoints.at(m_ui->m_listEntryPoints->currentRow());
}
void FormAddAccount::loadEntryPoints() {
foreach (ServiceEntryPoint *entry_point, m_entryPoints) {
QListWidgetItem *item = new QListWidgetItem(entry_point->icon(), entry_point->name(), m_ui->m_listEntryPoints);
item->setData(Qt::UserRole, QVariant::fromValue((void*) entry_point));
if (entry_point->isSingleInstanceService() && m_model->containsServiceRootFromEntryPoint(entry_point)) {
// Oops, this item cannot be added, it is single instance and is already added.
item->setFlags(Qt::NoItemFlags);
item->setToolTip(tr("This account can be added only once."));
}
}

View File

@ -38,9 +38,11 @@ class FormAddAccount : public QDialog {
virtual ~FormAddAccount();
private slots:
void addSelectedAccount();
void displayActiveEntryPointDetails();
private:
ServiceEntryPoint *selectedEntryPoint();
void loadEntryPoints();
Ui::FormAddAccount *m_ui;

View File

@ -33,6 +33,13 @@ class ServiceEntryPoint {
explicit ServiceEntryPoint();
virtual ~ServiceEntryPoint();
// Creates new service root item, which is ready to be added
// into the model. This method can for example display
// some kind of first-time configuration dialog inside itself
// before returning the root item.
// Returns NULL if initialization of new root cannot be done.
virtual ServiceRoot *createNewRoot(FeedsModel *main_model) = 0;
// Performs initialization of all service accounts created using this entry
// point from persistent DB.
// Returns list of root nodes which will be afterwards added

View File

@ -22,6 +22,8 @@
#include "miscellaneous/application.h"
#include "services/standard/standardserviceroot.h"
#include <QSqlQuery>
StandardServiceEntryPoint::StandardServiceEntryPoint() {
}
@ -57,10 +59,31 @@ QString StandardServiceEntryPoint::code() {
return SERVICE_CODE_STD_RSS;
}
ServiceRoot *StandardServiceEntryPoint::createNewRoot(FeedsModel *main_model) {
// Switch DB.
QSqlDatabase database = qApp->database()->connection(QSL("StandardServiceEntryPoint"), DatabaseFactory::FromSettings);
QSqlQuery query(database);
if (query.exec(QSL("UPDATE Information SET inf_value = 1 WHERE inf_key = 'standard_account_enabled';"))) {
return new StandardServiceRoot(true, main_model);
}
else {
return NULL;
}
}
QList<ServiceRoot*> StandardServiceEntryPoint::initializeSubtree(FeedsModel *main_model) {
StandardServiceRoot *root = new StandardServiceRoot(true, main_model);
// Check DB if standard account is enabled.
QSqlDatabase database = qApp->database()->connection(QSL("StandardServiceEntryPoint"), DatabaseFactory::FromSettings);
QSqlQuery query(database);
QList<ServiceRoot*> roots;
if (query.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'standard_account_enabled';"))) {
if (query.next() && query.value(0).toInt() == 1) {
StandardServiceRoot *root = new StandardServiceRoot(true, main_model);
roots.append(root);
}
}
return roots;
}

View File

@ -34,6 +34,7 @@ class StandardServiceEntryPoint : public ServiceEntryPoint {
QIcon icon();
QString code();
ServiceRoot *createNewRoot(FeedsModel *main_model);
QList<ServiceRoot*> initializeSubtree(FeedsModel *main_model);
};

View File

@ -58,6 +58,10 @@ QString TtRssServiceEntryPoint::code() {
return SERVICE_CODE_TT_RSS;
}
ServiceRoot *TtRssServiceEntryPoint::createNewRoot(FeedsModel *main_model) {
return NULL;
}
QList<ServiceRoot*> TtRssServiceEntryPoint::initializeSubtree(FeedsModel *main_model) {
return QList<ServiceRoot*>();
}

View File

@ -35,6 +35,7 @@ class TtRssServiceEntryPoint : public ServiceEntryPoint {
QIcon icon();
QString code();
ServiceRoot *createNewRoot(FeedsModel *main_model);
QList<ServiceRoot*> initializeSubtree(FeedsModel *main_model);
};