1
0
mirror of https://github.com/altlinux/admc.git synced 2025-01-18 02:04:36 +03:00

move out AdModel update out of create_entry.cpp

add entry_created signal/slot
remove ad_model pointer from create_entry.cpp
This commit is contained in:
Dmitry Degtyarev 2020-05-20 16:35:41 +04:00
parent 8b06f482ff
commit aa3b8fe013
7 changed files with 28 additions and 40 deletions

View File

@ -409,6 +409,8 @@ bool create_entry(const QString &name, const QString &dn, NewEntryType type) {
}
if (result == AD_SUCCESS) {
emit ad_interface.entry_created(dn);
return true;
} else {
return false;

View File

@ -27,6 +27,7 @@ public slots:
signals:
void entry_deleted(const QString &dn);
void entry_changed(const QString &dn);
void entry_created(const QString &dn);
void user_moved(const QString &old_dn, const QString &new_dn , const QString &new_parent_dn);
private:

View File

@ -232,3 +232,22 @@ void AdModel::on_user_moved(const QString &old_dn, const QString &new_dn, const
}
}
}
void AdModel::on_entry_created(const QString &dn) {
// Load entry to model if it's parent has already been fetched
// If it hasn't been fetched, then this new entry will be loaded with all other children when the parent is fetched
QString parent_dn = extract_parent_dn_from_dn(parent_dn);
QList<QStandardItem *> items = this->findItems(parent_dn, Qt::MatchExactly | Qt::MatchRecursive, Column::DN);
if (items.size() > 0) {
QStandardItem *dn_item = items[0];
QModelIndex dn_index = dn_item->index();
QModelIndex parent_index = dn_index.siblingAtColumn(0);
QStandardItem *parent = this->itemFromIndex(parent_index);
bool fetched_already = !this->canFetchMore(parent_index);
if (fetched_already) {
load_and_add_row(parent, dn);
}
}
}

View File

@ -4,8 +4,6 @@
#include <QStandardItemModel>
void load_and_add_row(QStandardItem *parent, const QString &dn);
class AdModel: public QStandardItemModel {
Q_OBJECT
@ -34,6 +32,7 @@ public slots:
void on_entry_changed(const QString &dn);
void on_entry_deleted(const QString &dn);
void on_user_moved(const QString &old_dn, const QString &new_dn, const QString &new_parent_dn);
void on_entry_created(const QString &dn);
private:

View File

@ -1,14 +1,11 @@
#include "create_entry.h"
#include "ad_interface.h"
#include "ad_model.h"
#include "constants.h"
#include <QInputDialog>
#include <QString>
AdModel *admodel = NULL;
void create_entry_dialog(NewEntryType type) {
// Open new user dialog and name of entry from it
@ -105,31 +102,7 @@ void create_entry_dialog(NewEntryType type) {
const QString dn = suffix + "=" + name + "," + parent_dn;
bool success = create_entry(name, dn, type);
if (success) {
// Load entry to model if it's parent has already been fetched
// If it hasn't been fetched, then this new entry will be loaded with all other children when the parent is fetched
// TODO: for some reason doesnt work with expanded parent
QList<QStandardItem *> items = admodel->findItems(parent_dn, Qt::MatchExactly | Qt::MatchRecursive, AdModel::Column::DN);
if (items.size() > 0) {
QStandardItem *dn_item = items[0];
QModelIndex dn_index = dn_item->index();
QModelIndex parent_index = dn_index.siblingAtColumn(0);
QStandardItem *parent = admodel->itemFromIndex(parent_index);
bool fetched_already = !admodel->canFetchMore(parent_index);
if (fetched_already) {
load_and_add_row(parent, dn);
}
}
} else {
}
create_entry(name, dn, type);
}
}
@ -148,7 +121,3 @@ void create_ou_dialog() {
void create_group_dialog() {
create_entry_dialog(NewEntryType::Group);
}
void create_entry_init(AdModel *admodel_in) {
admodel = admodel_in;
}

View File

@ -2,9 +2,6 @@
#ifndef CREATE_ENTRY_H
#define CREATE_ENTRY_H
class AdModel;
void create_entry_init(AdModel *admodel_in);
void create_user_dialog();
void create_computer_dialog();
void create_ou_dialog();

View File

@ -35,8 +35,6 @@ int main(int argc, char **argv) {
AdModel ad_model;
create_entry_init(&ad_model);
// Attributes
AttributesModel attributes_model;
ui.attributes_view->setModel(&attributes_model);
@ -88,7 +86,7 @@ int main(int argc, char **argv) {
delete_entry);
}
// Update models on entry changes
// Connect signals to update models on when entries are modified
QObject::connect(
&ad_interface, &AdInterface::entry_deleted,
&ad_model, &AdModel::on_entry_deleted);
@ -101,6 +99,9 @@ int main(int argc, char **argv) {
QObject::connect(
&ad_interface, &AdInterface::user_moved,
&ad_model, &AdModel::on_user_moved);
QObject::connect(
&ad_interface, &AdInterface::entry_created,
&ad_model, &AdModel::on_entry_created);
// Set root index of contents view to selection of containers view
QObject::connect(