mirror of
https://github.com/altlinux/admc.git
synced 2025-03-28 18:50:45 +03:00
add delete button to entry context menu
add untracked entry_context_menu files
This commit is contained in:
parent
04e8c67545
commit
bf315bb562
@ -164,6 +164,35 @@ void fake_create_group(const QString &dn, const QString &parent, const QString &
|
||||
};
|
||||
}
|
||||
|
||||
void fake_object_delete_recurse(const QString &dn) {
|
||||
if (fake_children.contains(dn)) {
|
||||
QList<QString> children = fake_children[dn];
|
||||
|
||||
for (auto child : children) {
|
||||
fake_object_delete_recurse(child);
|
||||
}
|
||||
|
||||
fake_children.remove(dn);
|
||||
}
|
||||
|
||||
fake_attributes.remove(dn);
|
||||
}
|
||||
|
||||
void fake_object_delete(const QString &dn) {
|
||||
fake_object_delete_recurse(dn);
|
||||
|
||||
// Remove original deleted entry from parent's children list
|
||||
for (auto key : fake_children.keys()) {
|
||||
QList<QString> *children = &fake_children[key];
|
||||
|
||||
if (children->contains(dn)) {
|
||||
int i = children->indexOf(dn);
|
||||
|
||||
children->removeAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
// REAL STUFF
|
||||
// -----------------------------------------------------------------
|
||||
@ -341,3 +370,26 @@ bool create_entry(const QString &name, const QString &dn, const QString &parent_
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool delete_entry(const QString &dn) {
|
||||
if (FAKE_AD) {
|
||||
fake_object_delete(dn);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -23,5 +23,6 @@ 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);
|
||||
|
||||
#endif /* AD_INTERFACE_H */
|
||||
|
@ -172,3 +172,14 @@ void AdModel::on_entry_changed(const QString &dn) {
|
||||
load_row(row, dn);
|
||||
}
|
||||
}
|
||||
|
||||
void AdModel::on_entry_deleted(const QString &dn) {
|
||||
QList<QStandardItem *> items = this->findItems(dn, Qt::MatchExactly | Qt::MatchRecursive, AdModel::Column::DN);
|
||||
|
||||
if (items.size() > 0) {
|
||||
QStandardItem *dn_item = items[0];
|
||||
QModelIndex dn_index = dn_item->index();
|
||||
|
||||
this->removeRow(dn_index.row(), dn_index.parent());
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void on_entry_changed(const QString &dn);
|
||||
void on_entry_deleted(const QString &dn);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -40,3 +40,10 @@ void AttributesModel::change_target(const QString &new_target_dn) {
|
||||
this->setHorizontalHeaderItem(Column::Name, new QStandardItem("Name"));
|
||||
this->setHorizontalHeaderItem(Column::Value, new QStandardItem("Value"));
|
||||
}
|
||||
|
||||
void AttributesModel::on_entry_deleted(const QString &dn) {
|
||||
// Clear data if current target was deleted
|
||||
if (this->target_dn == dn) {
|
||||
this->change_target(QString(""));
|
||||
}
|
||||
}
|
@ -22,6 +22,9 @@ public:
|
||||
signals:
|
||||
void entry_changed(const QString &dn);
|
||||
|
||||
public slots:
|
||||
void on_entry_deleted(const QString &dn);
|
||||
|
||||
private:
|
||||
QString target_dn;
|
||||
|
||||
|
42
src/entry_context_menu.cpp
Normal file
42
src/entry_context_menu.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
#include "entry_context_menu.h"
|
||||
#include "ad_model.h"
|
||||
#include "ad_interface.h"
|
||||
|
||||
#include <QPoint>
|
||||
#include <QAction>
|
||||
#include <QTreeView>
|
||||
|
||||
EntryContextMenu::EntryContextMenu(QWidget *parent) : QMenu(parent) {
|
||||
QAction *attributes_action = new QAction("Attributes", this);
|
||||
connect(attributes_action, &QAction::triggered, [this]() {
|
||||
emit attributes_clicked(this->target_dn);
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void EntryContextMenu::connect_view(const QTreeView &view) {
|
||||
// Open entry context menu from given view
|
||||
// Save dn of clicked entry of the view
|
||||
connect(
|
||||
&view, &QWidget::customContextMenuRequested,
|
||||
[this, &view] (const QPoint& pos) {
|
||||
QPoint global_pos = view.mapToGlobal(pos);
|
||||
|
||||
// Get DN of clicked entry
|
||||
QModelIndex index = view.indexAt(pos);
|
||||
QModelIndex dn_index = index.siblingAtColumn(AdModel::Column::DN);
|
||||
QString dn = dn_index.data().toString();
|
||||
|
||||
this->target_dn = dn;
|
||||
this->popup(global_pos);
|
||||
});
|
||||
}
|
32
src/entry_context_menu.h
Normal file
32
src/entry_context_menu.h
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
#ifndef ENTRY_CONTEXT_MENU_H
|
||||
#define ENTRY_CONTEXT_MENU_H
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
class QWidget;
|
||||
class QPoint;
|
||||
class QString;
|
||||
class QTreeView;
|
||||
|
||||
class EntryContextMenu : public QMenu {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EntryContextMenu(QWidget *parent);
|
||||
void connect_view(const QTreeView &view);
|
||||
|
||||
public slots:
|
||||
|
||||
signals:
|
||||
void attributes_clicked(const QString &dn);
|
||||
void delete_clicked(const QString &dn);
|
||||
|
||||
private:
|
||||
QString target_dn;
|
||||
|
||||
using QMenu::popup;
|
||||
|
||||
};
|
||||
|
||||
#endif /* ENTRY_CONTEXT_MENU_H */
|
@ -81,6 +81,14 @@ int main(int argc, char **argv) {
|
||||
QObject::connect(
|
||||
entry_context_menu, &EntryContextMenu::attributes_clicked,
|
||||
ui.attributes_view, &AttributesView::set_target_dn);
|
||||
|
||||
// Delete action signals
|
||||
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);
|
||||
}
|
||||
|
||||
// Set root index of contents view to selection of containers view
|
||||
|
Loading…
x
Reference in New Issue
Block a user