From 9088b6bcfe02d0b8813a37a9d4954a1ce437d454 Mon Sep 17 00:00:00 2001 From: Dmitry Degtyarev Date: Thu, 21 May 2020 13:39:27 +0400 Subject: [PATCH] add "New" submenu to entry context menu add NewEntryType::COUNT for iteration add optional parent_dn argument to create_entry_dialog() --- src/ad_interface.cpp | 2 ++ src/ad_interface.h | 10 +++++++++- src/create_entry_dialog.cpp | 15 +++++++-------- src/create_entry_dialog.h | 3 +++ src/entry_context_menu.cpp | 15 ++++++++++++++- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/ad_interface.cpp b/src/ad_interface.cpp index 4f41e621..54b662a3 100644 --- a/src/ad_interface.cpp +++ b/src/ad_interface.cpp @@ -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) { diff --git a/src/ad_interface.h b/src/ad_interface.h index b2aba334..bf86b511 100644 --- a/src/ad_interface.h +++ b/src/ad_interface.h @@ -13,7 +13,15 @@ enum NewEntryType { User, Computer, OU, - Group + Group, + COUNT +}; + +const QMap new_entry_type_to_string = { + {NewEntryType::User, "User"}, + {NewEntryType::Computer, "Computer"}, + {NewEntryType::OU, "Organization Unit"}, + {NewEntryType::Group, "Group"}, }; // Class solely for emitting signals diff --git a/src/create_entry_dialog.cpp b/src/create_entry_dialog.cpp index bc5fb78d..7917f299 100644 --- a/src/create_entry_dialog.cpp +++ b/src/create_entry_dialog.cpp @@ -6,15 +6,9 @@ #include #include -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 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 new_entry_type_to_suffix = { {NewEntryType::User, "CN"}, diff --git a/src/create_entry_dialog.h b/src/create_entry_dialog.h index c31cc177..be19c916 100644 --- a/src/create_entry_dialog.h +++ b/src/create_entry_dialog.h @@ -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(); diff --git a/src/entry_context_menu.cpp b/src/entry_context_menu.cpp index 2d5d1d62..053bdd14 100644 --- a/src/entry_context_menu.cpp +++ b/src/entry_context_menu.cpp @@ -1,6 +1,7 @@ #include "entry_context_menu.h" #include "ad_model.h" +#include "create_entry_dialog.h" #include "ad_interface.h" #include @@ -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(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); } - }); + }); }