mirror of
https://github.com/altlinux/admc.git
synced 2025-03-22 14:50:36 +03:00
add AdInterface signals
move entry_deleted signal from context menu to AdInterface move entry_changed signal from AttributesModel to AdInterface don't open entry context menu from invalid entry(or no entry)
This commit is contained in:
parent
7eca4b5b39
commit
751344c00d
@ -1,5 +1,5 @@
|
||||
QT += core gui widgets
|
||||
CONFIG += c++11
|
||||
CONFIG += c++14
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
LIBS += -lldap -llber -lresolv -lgsasl
|
||||
|
@ -12,6 +12,8 @@ extern "C" {
|
||||
// FAKE STUFF
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
AdInterface ad_interface;
|
||||
|
||||
bool FAKE_AD = false;
|
||||
|
||||
QMap<QString, QList<QString>> fake_children;
|
||||
@ -307,6 +309,8 @@ bool set_attribute(const QString &dn, const QString &attribute, const QString &v
|
||||
int result = ad_mod_replace(dn_cstr, attribute_cstr, value_cstr);
|
||||
|
||||
if (result == AD_SUCCESS) {
|
||||
emit ad_interface.entry_changed(dn);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -371,25 +375,25 @@ bool create_entry(const QString &name, const QString &dn, const QString &parent_
|
||||
}
|
||||
}
|
||||
|
||||
bool delete_entry(const QString &dn) {
|
||||
void delete_entry(const QString &dn) {
|
||||
int result = AD_INVALID_DN;
|
||||
|
||||
if (FAKE_AD) {
|
||||
fake_object_delete(dn);
|
||||
|
||||
return true;
|
||||
result = AD_SUCCESS;
|
||||
} else {
|
||||
const char *dn_cstr = qstring_to_cstr(dn);
|
||||
|
||||
// TODO: handle all possible side-effects?
|
||||
// probably a lot of stuff, like group membership and stuff
|
||||
|
||||
// TODO: handle errors
|
||||
|
||||
result = ad_object_delete(dn_cstr);
|
||||
}
|
||||
|
||||
const char *dn_cstr = qstring_to_cstr(dn);
|
||||
|
||||
// TODO: handle all possible side-effects?
|
||||
// probably a lot of stuff, like group membership and stuff
|
||||
|
||||
// TODO: handle errors
|
||||
|
||||
int result = ad_object_delete(dn_cstr);
|
||||
|
||||
if (result == AD_SUCCESS) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
emit ad_interface.entry_deleted(dn);
|
||||
}
|
||||
}
|
||||
|
@ -16,13 +16,31 @@ enum NewEntryType {
|
||||
Group
|
||||
};
|
||||
|
||||
extern bool FAKE_AD;
|
||||
// Class solely for emitting signals
|
||||
class AdInterface: public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
void entry_deleted(const QString &dn);
|
||||
void entry_changed(const QString &dn);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
extern AdInterface ad_interface;
|
||||
extern bool FAKE_AD;
|
||||
|
||||
bool ad_interface_login();
|
||||
QList<QString> load_children(const QString &dn);
|
||||
QMap<QString, QList<QString>> load_attributes(const QString &dn);
|
||||
bool set_attribute(const QString &dn, const QString &attribute, const QString &value);
|
||||
bool create_entry(const QString &name, const QString &dn, const QString &parent_dn, NewEntryType type);
|
||||
bool delete_entry(const QString &dn);
|
||||
void delete_entry(const QString &dn);
|
||||
bool set_attribute(const QString &dn, const QString &attribute, const QString &value);
|
||||
|
||||
#endif /* AD_INTERFACE_H */
|
||||
|
@ -23,8 +23,6 @@ bool AttributesModel::setData(const QModelIndex &index, const QVariant &value, i
|
||||
if (success) {
|
||||
QStandardItemModel::setData(index, value, role);
|
||||
|
||||
emit entry_changed(dn);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -12,15 +12,12 @@ EntryContextMenu::EntryContextMenu(QWidget *parent) : QMenu(parent) {
|
||||
connect(attributes_action, &QAction::triggered, [this]() {
|
||||
emit attributes_clicked(this->target_dn);
|
||||
});
|
||||
this->addAction(attributes_action);
|
||||
|
||||
QAction *delete_action = new QAction("Delete", this);
|
||||
connect(delete_action, &QAction::triggered, [this]() {
|
||||
delete_entry(this->target_dn);
|
||||
|
||||
emit delete_clicked(this->target_dn);
|
||||
});
|
||||
|
||||
this->addAction(attributes_action);
|
||||
this->addAction(delete_action);
|
||||
}
|
||||
|
||||
@ -34,6 +31,8 @@ void EntryContextMenu::connect_view(const QTreeView &view) {
|
||||
|
||||
// Get DN of clicked entry
|
||||
QModelIndex index = view.indexAt(pos);
|
||||
QModelIndex dn_index = index.siblingAtColumn(AdModel::Column::DN);
|
||||
QString dn = dn_index.data().toString();
|
||||
|
||||
if (index.isValid()) {
|
||||
QModelIndex dn_index = index.siblingAtColumn(AdModel::Column::DN);
|
||||
|
18
src/main.cpp
18
src/main.cpp
@ -82,15 +82,23 @@ int main(int argc, char **argv) {
|
||||
entry_context_menu, &EntryContextMenu::attributes_clicked,
|
||||
ui.attributes_view, &AttributesView::set_target_dn);
|
||||
|
||||
// Delete action signals
|
||||
// Delete entry when delete button is pressed
|
||||
QObject::connect(
|
||||
entry_context_menu, &EntryContextMenu::delete_clicked,
|
||||
&ad_model, &AdModel::on_entry_deleted);
|
||||
QObject::connect(
|
||||
entry_context_menu, &EntryContextMenu::delete_clicked,
|
||||
&attributes_model, &AttributesModel::on_entry_deleted);
|
||||
delete_entry);
|
||||
}
|
||||
|
||||
// Update models on entry changes
|
||||
QObject::connect(
|
||||
&ad_interface, &AdInterface::entry_deleted,
|
||||
&ad_model, &AdModel::on_entry_deleted);
|
||||
QObject::connect(
|
||||
&ad_interface, &AdInterface::entry_deleted,
|
||||
&attributes_model, &AttributesModel::on_entry_deleted);
|
||||
QObject::connect(
|
||||
&ad_interface, &AdInterface::entry_changed,
|
||||
&ad_model, &AdModel::on_entry_changed);
|
||||
|
||||
// Set root index of contents view to selection of containers view
|
||||
QObject::connect(
|
||||
ui.containers_view->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
|
Loading…
x
Reference in New Issue
Block a user