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

add "New" submenu to entry context menu

add NewEntryType::COUNT for iteration
add optional parent_dn argument to create_entry_dialog()
This commit is contained in:
Dmitry Degtyarev 2020-05-21 13:39:27 +04:00
parent 32c5570350
commit 9088b6bcfe
5 changed files with 35 additions and 10 deletions

View File

@ -379,6 +379,7 @@ bool create_entry(const QString &name, const QString &dn, NewEntryType type) {
fake_create_group(name, dn);
break;
}
case COUNT: break;
}
return true;
@ -406,6 +407,7 @@ bool create_entry(const QString &name, const QString &dn, NewEntryType type) {
result = ad_group_create(name_cstr, dn_cstr);
break;
}
case COUNT: break;
}
if (result == AD_SUCCESS) {

View File

@ -13,7 +13,15 @@ enum NewEntryType {
User,
Computer,
OU,
Group
Group,
COUNT
};
const QMap<NewEntryType, QString> new_entry_type_to_string = {
{NewEntryType::User, "User"},
{NewEntryType::Computer, "Computer"},
{NewEntryType::OU, "Organization Unit"},
{NewEntryType::Group, "Group"},
};
// Class solely for emitting signals

View File

@ -6,15 +6,9 @@
#include <QInputDialog>
#include <QString>
void create_entry_dialog(NewEntryType type) {
void create_entry_dialog(NewEntryType type, const QString &given_parent_dn) {
// Open new user dialog and name of entry from it
const QMap<NewEntryType, QString> new_entry_type_to_string = {
{NewEntryType::User, "User"},
{NewEntryType::Computer, "Computer"},
{NewEntryType::OU, "Organization Unit"},
{NewEntryType::Group, "Group"},
};
QString type_string = new_entry_type_to_string[type];
QString dialog_title = "New " + type_string;
QString input_label = type_string + " name";
@ -36,7 +30,12 @@ void create_entry_dialog(NewEntryType type) {
{NewEntryType::OU, QString(HEAD_DN)},
{NewEntryType::Group, QString(HEAD_DN)},
};
QString parent_dn = new_entry_type_to_parent[type];
QString parent_dn;
if (given_parent_dn == "") {
parent_dn = new_entry_type_to_parent[type];
} else {
parent_dn = given_parent_dn;
}
const QMap<NewEntryType, QString> new_entry_type_to_suffix = {
{NewEntryType::User, "CN"},

View File

@ -2,6 +2,9 @@
#ifndef CREATE_ENTRY_H
#define CREATE_ENTRY_H
#include "ad_interface.h"
void create_entry_dialog(NewEntryType type, const QString &given_parent_dn = "");
void create_user_dialog();
void create_computer_dialog();
void create_ou_dialog();

View File

@ -1,6 +1,7 @@
#include "entry_context_menu.h"
#include "ad_model.h"
#include "create_entry_dialog.h"
#include "ad_interface.h"
#include <QPoint>
@ -19,6 +20,18 @@ EntryContextMenu::EntryContextMenu(QWidget *parent) : QMenu(parent) {
emit delete_clicked(this->target_dn);
});
this->addAction(delete_action);
QMenu *submenu_new = this->addMenu("New");
// Create "New X" menu for each entry type
for (int type_i = NewEntryType::User; type_i < NewEntryType::COUNT; type_i++) {
NewEntryType type = static_cast<NewEntryType>(type_i);
QString action_label = new_entry_type_to_string[type];
QAction *action = new QAction(action_label, this);
connect(action, &QAction::triggered, [this, type]() {
create_entry_dialog(type, this->target_dn);
});
submenu_new->addAction(action);
}
}
void EntryContextMenu::connect_view(const QTreeView &view) {
@ -41,5 +54,5 @@ void EntryContextMenu::connect_view(const QTreeView &view) {
this->target_dn = dn;
this->popup(global_pos);
}
});
});
}