mirror of
https://github.com/altlinux/admc.git
synced 2025-03-06 16:58:21 +03:00
Merge pull request #37 from altlinuxteam/main-window-actions
Settings and actions work
This commit is contained in:
commit
0fa71bb8d4
@ -56,13 +56,13 @@ set(ADTOOL_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/attributes_model.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/containers_widget.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/contents_widget.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/create_entry_dialog.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/main_window.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/entry_widget.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/status_bar.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/members_model.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/members_widget.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/entry_model.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/settings.cpp
|
||||
)
|
||||
|
||||
add_definitions(${QT5_DEFINITIONS})
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "ad_proxy_model.h"
|
||||
#include "ad_model.h"
|
||||
#include "ad_interface.h"
|
||||
#include "main_window.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <QAction>
|
||||
|
||||
@ -30,7 +30,7 @@ AdProxyModel::AdProxyModel(AdModel *model, QObject *parent)
|
||||
setSourceModel(model);
|
||||
|
||||
connect(
|
||||
MainWindow::action_advanced_view, &QAction::triggered,
|
||||
SETTINGS()->toggle_advanced_view, &QAction::triggered,
|
||||
this, &AdProxyModel::on_advanced_view_toggled);
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ bool AdProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_pa
|
||||
|
||||
// Hide advanced view only entries if advanced view is OFF
|
||||
const bool advanced_view_only = index.data(AdModel::Roles::AdvancedViewOnly).toBool();
|
||||
const bool advanced_view_is_on = MainWindow::action_advanced_view->isChecked();
|
||||
const bool advanced_view_is_on = SETTINGS()->toggle_advanced_view->isChecked();
|
||||
if (advanced_view_only && !advanced_view_is_on) {
|
||||
return false;
|
||||
}
|
||||
|
@ -19,13 +19,19 @@
|
||||
|
||||
#include "admc.h"
|
||||
#include "ad_interface.h"
|
||||
#include "settings.h"
|
||||
|
||||
ADMC::ADMC(int& argc, char** argv)
|
||||
: QApplication(argc, argv)
|
||||
{
|
||||
m_ad_interface = new AdInterface(this);
|
||||
m_settings = new Settings(this);
|
||||
}
|
||||
|
||||
AdInterface *ADMC::ad_interface() {
|
||||
return m_ad_interface;
|
||||
}
|
||||
|
||||
const Settings *ADMC::settings() {
|
||||
return m_settings;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <QApplication>
|
||||
|
||||
class AdInterface;
|
||||
class Settings;
|
||||
|
||||
class ADMC final: public QApplication {
|
||||
Q_OBJECT
|
||||
@ -31,9 +32,11 @@ public:
|
||||
ADMC(int& argc, char** argv);
|
||||
|
||||
AdInterface* ad_interface();
|
||||
const Settings* settings();
|
||||
|
||||
private:
|
||||
AdInterface* m_ad_interface = nullptr;
|
||||
Settings* m_settings = nullptr;
|
||||
};
|
||||
|
||||
#endif /* __ADMC_APPLICATION_H */
|
||||
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* ADMC - AD Management Center
|
||||
*
|
||||
* Copyright (C) 2020 BaseALT Ltd.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "create_entry_dialog.h"
|
||||
#include "ad_interface.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QString>
|
||||
|
||||
void create_entry_dialog(NewEntryType type, const QString &parent_dn) {
|
||||
// Open new user dialog and name of entry from it
|
||||
|
||||
QString type_string = new_entry_type_to_string[type];
|
||||
QString dialog_title = "New " + type_string;
|
||||
QString input_label = type_string + " name";
|
||||
|
||||
bool ok;
|
||||
QString name = QInputDialog::getText(nullptr, dialog_title, input_label, QLineEdit::Normal, "", &ok);
|
||||
|
||||
// TODO: maybe expand tree to newly created entry?
|
||||
|
||||
// Create user once dialog is complete
|
||||
if (ok && !name.isEmpty()) {
|
||||
// Attempt to create user in AD
|
||||
|
||||
const QMap<NewEntryType, QString> new_entry_type_to_suffix = {
|
||||
{NewEntryType::User, "CN"},
|
||||
{NewEntryType::Computer, "CN"},
|
||||
{NewEntryType::OU, "OU"},
|
||||
{NewEntryType::Group, "CN"},
|
||||
};
|
||||
QString suffix = new_entry_type_to_suffix[type];
|
||||
|
||||
const QString dn = suffix + "=" + name + "," + parent_dn;
|
||||
|
||||
AD()->create_entry(name, dn, type);
|
||||
}
|
||||
}
|
@ -21,13 +21,17 @@
|
||||
#include "attributes_model.h"
|
||||
#include "ad_interface.h"
|
||||
#include "members_widget.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <QTreeView>
|
||||
#include <QStandardItemModel>
|
||||
#include <QAction>
|
||||
|
||||
DetailsWidget::DetailsWidget()
|
||||
DetailsWidget::DetailsWidget(MembersWidget *members_widget_)
|
||||
: QTabWidget()
|
||||
{
|
||||
members_widget = members_widget_;
|
||||
|
||||
attributes_model = new AttributesModel(this);
|
||||
|
||||
attributes_view = new QTreeView();
|
||||
@ -36,8 +40,9 @@ DetailsWidget::DetailsWidget()
|
||||
attributes_view->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
attributes_view->setModel(attributes_model);
|
||||
|
||||
members_widget = MembersWidget::make();
|
||||
|
||||
connect(
|
||||
AD(), &AdInterface::ad_interface_login_complete,
|
||||
this, &DetailsWidget::on_ad_interface_login_complete);
|
||||
connect(
|
||||
AD(), &AdInterface::delete_entry_complete,
|
||||
this, &DetailsWidget::on_delete_entry_complete);
|
||||
@ -115,3 +120,19 @@ void DetailsWidget::on_rename_complete(const QString &dn, const QString &new_nam
|
||||
change_target(new_dn);
|
||||
}
|
||||
}
|
||||
|
||||
void DetailsWidget::on_containers_clicked_dn(const QString &dn) {
|
||||
if (SETTINGS()->details_on_containers_click->isChecked()) {
|
||||
change_target(dn);
|
||||
}
|
||||
}
|
||||
|
||||
void DetailsWidget::on_contents_clicked_dn(const QString &dn) {
|
||||
if (SETTINGS()->details_on_contents_click->isChecked()) {
|
||||
change_target(dn);
|
||||
}
|
||||
}
|
||||
|
||||
void DetailsWidget::on_context_menu_details(const QString &dn) {
|
||||
change_target(dn);
|
||||
}
|
||||
|
@ -34,9 +34,12 @@ class DetailsWidget final : public QTabWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DetailsWidget();
|
||||
DetailsWidget(MembersWidget *members_widget_);
|
||||
|
||||
void change_target(const QString &dn);
|
||||
public slots:
|
||||
void on_containers_clicked_dn(const QString &dn);
|
||||
void on_contents_clicked_dn(const QString &dn);
|
||||
void on_context_menu_details(const QString &dn);
|
||||
|
||||
private slots:
|
||||
void on_ad_interface_login_complete(const QString &search_base, const QString &head_dn);
|
||||
@ -44,14 +47,14 @@ private slots:
|
||||
void on_move_user_complete(const QString &user_dn, const QString &container_dn, const QString &new_dn);
|
||||
void on_load_attributes_complete(const QString &dn);
|
||||
void on_rename_complete(const QString &dn, const QString &new_name, const QString &new_dn);
|
||||
|
||||
|
||||
private:
|
||||
AttributesModel *attributes_model = nullptr;
|
||||
QTreeView *attributes_view = nullptr;
|
||||
|
||||
MembersWidget *members_widget = nullptr;
|
||||
|
||||
QString target_dn;
|
||||
|
||||
void change_target(const QString &dn);
|
||||
};
|
||||
|
||||
#endif /* ATTRIBUTES_WIDGET_H */
|
||||
|
@ -18,9 +18,9 @@
|
||||
*/
|
||||
|
||||
#include "entry_widget.h"
|
||||
#include "main_window.h"
|
||||
#include "ad_interface.h"
|
||||
#include "entry_model.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QItemSelection>
|
||||
@ -35,15 +35,11 @@
|
||||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
QSet<EntryWidget *> EntryWidget::instances;
|
||||
|
||||
EntryWidget::EntryWidget(EntryModel *model)
|
||||
: QWidget()
|
||||
{
|
||||
entry_model = model;
|
||||
|
||||
instances.insert(this);
|
||||
|
||||
view = new QTreeView();
|
||||
view->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
view->setDragDropMode(QAbstractItemView::DragDrop);
|
||||
@ -60,8 +56,8 @@ EntryWidget::EntryWidget(EntryModel *model)
|
||||
update_column_visibility();
|
||||
|
||||
connect(
|
||||
MainWindow::action_toggle_dn, &QAction::triggered,
|
||||
this, &EntryWidget::on_action_toggle_dn);
|
||||
SETTINGS()->toggle_show_dn_column, &QAction::triggered,
|
||||
this, &EntryWidget::on_toggle_show_dn_column);
|
||||
|
||||
connect(
|
||||
view, &QWidget::customContextMenuRequested,
|
||||
@ -72,10 +68,6 @@ EntryWidget::EntryWidget(EntryModel *model)
|
||||
this, &EntryWidget::on_view_clicked);
|
||||
}
|
||||
|
||||
EntryWidget::~EntryWidget() {
|
||||
instances.remove(this);
|
||||
}
|
||||
|
||||
void EntryWidget::on_context_menu_requested(const QPoint &pos) {
|
||||
// Open entry context menu
|
||||
QModelIndex index = view->indexAt(pos);
|
||||
@ -84,47 +76,46 @@ void EntryWidget::on_context_menu_requested(const QPoint &pos) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString dn = entry_model->get_dn_from_index(index);
|
||||
|
||||
QMenu menu;
|
||||
|
||||
menu.addAction(MainWindow::action_details);
|
||||
menu.addAction(MainWindow::action_delete_entry);
|
||||
menu.addAction(MainWindow::action_rename);
|
||||
QAction *action_to_show_menu_at = menu.addAction("Details", [this, dn]() {
|
||||
emit context_menu_details(dn);
|
||||
});
|
||||
menu.addAction("Delete", [this, dn]() {
|
||||
emit context_menu_delete(dn);
|
||||
});
|
||||
menu.addAction("Rename", [this, dn]() {
|
||||
emit context_menu_rename(dn);
|
||||
});
|
||||
|
||||
QMenu *submenu_new = menu.addMenu("New");
|
||||
submenu_new->addAction(MainWindow::action_new_user);
|
||||
submenu_new->addAction(MainWindow::action_new_computer);
|
||||
submenu_new->addAction(MainWindow::action_new_group);
|
||||
submenu_new->addAction(MainWindow::action_new_ou);
|
||||
submenu_new->addAction("New User", [this, dn]() {
|
||||
emit context_menu_new_user(dn);
|
||||
});
|
||||
submenu_new->addAction("New Computer", [this, dn]() {
|
||||
emit context_menu_new_computer(dn);
|
||||
});
|
||||
submenu_new->addAction("New Group", [this, dn]() {
|
||||
emit context_menu_new_group(dn);
|
||||
});
|
||||
submenu_new->addAction("New OU", [this, dn]() {
|
||||
emit context_menu_new_ou(dn);
|
||||
});
|
||||
|
||||
const QString dn = entry_model->get_dn_from_index(index);
|
||||
const bool is_policy = AD()->is_policy(dn);
|
||||
if (is_policy) {
|
||||
menu.addAction(MainWindow::action_edit_policy);
|
||||
submenu_new->addAction("Edit Policy", [this, dn]() {
|
||||
emit context_menu_edit_policy(dn);
|
||||
});
|
||||
}
|
||||
|
||||
QPoint global_pos = view->mapToGlobal(pos);
|
||||
menu.exec(global_pos, MainWindow::action_details);
|
||||
menu.exec(global_pos, action_to_show_menu_at);
|
||||
}
|
||||
|
||||
QString EntryWidget::get_selected_dn() {
|
||||
for (auto e : instances) {
|
||||
if (e->view->hasFocus()) {
|
||||
const auto selection_model = e->view->selectionModel();
|
||||
|
||||
if (selection_model->hasSelection()) {
|
||||
const QList<QModelIndex> selected_indexes = selection_model->selectedIndexes();
|
||||
const QModelIndex selected = selected_indexes[0];
|
||||
const QString dn = e->entry_model->get_dn_from_index(selected);
|
||||
|
||||
return dn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void EntryWidget::on_action_toggle_dn(bool checked) {
|
||||
void EntryWidget::on_toggle_show_dn_column(bool checked) {
|
||||
const bool dn_column_hidden = !checked;
|
||||
column_hidden[entry_model->dn_column] = dn_column_hidden;
|
||||
|
||||
|
@ -34,15 +34,20 @@ Q_OBJECT
|
||||
|
||||
public:
|
||||
EntryWidget(EntryModel *model);
|
||||
~EntryWidget();
|
||||
|
||||
static QString get_selected_dn();
|
||||
|
||||
signals:
|
||||
void clicked_dn(const QString &dn);
|
||||
void context_menu_details(const QString &dn);
|
||||
void context_menu_rename(const QString &dn);
|
||||
void context_menu_delete(const QString &dn);
|
||||
void context_menu_new_user(const QString &dn);
|
||||
void context_menu_new_computer(const QString &dn);
|
||||
void context_menu_new_group(const QString &dn);
|
||||
void context_menu_new_ou(const QString &dn);
|
||||
void context_menu_edit_policy(const QString &dn);
|
||||
|
||||
private slots:
|
||||
void on_action_toggle_dn(bool checked);
|
||||
void on_toggle_show_dn_column(bool checked);
|
||||
void on_context_menu_requested(const QPoint &pos);
|
||||
void on_view_clicked(const QModelIndex &index);
|
||||
|
||||
@ -53,7 +58,6 @@ protected:
|
||||
void update_column_visibility();
|
||||
|
||||
private:
|
||||
static QSet<EntryWidget *> instances;
|
||||
EntryModel *entry_model = nullptr;
|
||||
|
||||
};
|
||||
|
@ -22,11 +22,13 @@
|
||||
#include "main_window.h"
|
||||
#include "containers_widget.h"
|
||||
#include "contents_widget.h"
|
||||
#include "members_widget.h"
|
||||
#include "details_widget.h"
|
||||
#include "ad_model.h"
|
||||
#include "attributes_model.h"
|
||||
#include "create_entry_dialog.h"
|
||||
#include "status_bar.h"
|
||||
#include "entry_widget.h"
|
||||
#include "settings.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QString>
|
||||
@ -42,17 +44,6 @@
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
QAction *MainWindow::action_advanced_view = new QAction("Advanced view");
|
||||
QAction *MainWindow::action_toggle_dn = new QAction("Show DN");
|
||||
QAction *MainWindow::action_details = new QAction("Details");
|
||||
QAction *MainWindow::action_delete_entry = new QAction("Delete");
|
||||
QAction *MainWindow::action_new_user = new QAction("New User");
|
||||
QAction *MainWindow::action_new_computer = new QAction("New Computer");
|
||||
QAction *MainWindow::action_new_group = new QAction("New Group");
|
||||
QAction *MainWindow::action_new_ou = new QAction("New OU");
|
||||
QAction *MainWindow::action_edit_policy = new QAction("Edit policy");
|
||||
QAction *MainWindow::action_rename = new QAction("Rename");
|
||||
|
||||
MainWindow::MainWindow(const bool auto_login)
|
||||
: QMainWindow()
|
||||
{
|
||||
@ -79,26 +70,14 @@ MainWindow::MainWindow(const bool auto_login)
|
||||
menubar_file->addAction(action_login);
|
||||
menubar_file->addAction(action_exit);
|
||||
|
||||
const auto menubar_new = menubar->addMenu("New");
|
||||
menubar_new->addAction(action_new_user);
|
||||
menubar_new->addAction(action_new_computer);
|
||||
menubar_new->addAction(action_new_group);
|
||||
menubar_new->addAction(action_new_ou);
|
||||
|
||||
const auto menubar_view = menubar->addMenu("View");
|
||||
menubar_view->addAction(action_advanced_view);
|
||||
menubar_view->addAction(action_toggle_dn);
|
||||
menubar_view->addAction(SETTINGS()->toggle_advanced_view);
|
||||
menubar_view->addAction(SETTINGS()->toggle_show_dn_column);
|
||||
|
||||
const auto menubar_preferences = menubar->addMenu("Preferences");
|
||||
{
|
||||
action_containers_click_attributes = menubar_preferences->addAction("Open attributes on left click in Containers window");
|
||||
action_contents_click_attributes = menubar_preferences->addAction("Open attributes on left click in Contents window");
|
||||
action_toggle_confirmations = menubar_preferences->addAction("Confirm some actions");
|
||||
|
||||
action_containers_click_attributes->setCheckable(true);
|
||||
action_contents_click_attributes->setCheckable(true);
|
||||
action_toggle_confirmations->setCheckable(true);
|
||||
}
|
||||
menubar_preferences->addAction(SETTINGS()->details_on_containers_click);
|
||||
menubar_preferences->addAction(SETTINGS()->details_on_contents_click);
|
||||
menubar_preferences->addAction(SETTINGS()->confirm_actions);
|
||||
|
||||
const auto splitter = new QSplitter();
|
||||
splitter->setOrientation(Qt::Horizontal);
|
||||
@ -108,7 +87,9 @@ MainWindow::MainWindow(const bool auto_login)
|
||||
|
||||
containers_widget = new ContainersWidget(ad_model);
|
||||
contents_widget = new ContentsWidget(ad_model);
|
||||
details_widget = new DetailsWidget();
|
||||
|
||||
MembersWidget *members_widget = MembersWidget::make();
|
||||
details_widget = new DetailsWidget(members_widget);
|
||||
|
||||
splitter->addWidget(containers_widget);
|
||||
splitter->addWidget(contents_widget);
|
||||
@ -120,37 +101,6 @@ MainWindow::MainWindow(const bool auto_login)
|
||||
splitter->setStretchFactor(1, 2);
|
||||
splitter->setStretchFactor(2, 2);
|
||||
|
||||
//
|
||||
// Setup actions
|
||||
//
|
||||
action_advanced_view->setCheckable(true);
|
||||
action_toggle_dn->setCheckable(true);
|
||||
|
||||
connect(
|
||||
action_details, &QAction::triggered,
|
||||
this, &MainWindow::on_action_details);
|
||||
connect(
|
||||
action_delete_entry, &QAction::triggered,
|
||||
this, &MainWindow::on_action_delete_entry);
|
||||
connect(
|
||||
action_new_user, &QAction::triggered,
|
||||
this, &MainWindow::on_action_new_user);
|
||||
connect(
|
||||
action_new_computer, &QAction::triggered,
|
||||
this, &MainWindow::on_action_new_computer);
|
||||
connect(
|
||||
action_new_group, &QAction::triggered,
|
||||
this, &MainWindow::on_action_new_group);
|
||||
connect(
|
||||
action_new_ou, &QAction::triggered,
|
||||
this, &MainWindow::on_action_new_ou);
|
||||
connect(
|
||||
action_rename, &QAction::triggered,
|
||||
this, &MainWindow::on_action_rename);
|
||||
|
||||
connect(
|
||||
action_edit_policy, &QAction::triggered,
|
||||
this, &MainWindow::on_action_edit_policy);
|
||||
connect(
|
||||
AD(), &AdInterface::ad_interface_login_complete,
|
||||
this, &MainWindow::on_ad_interface_login_complete);
|
||||
@ -162,11 +112,11 @@ MainWindow::MainWindow(const bool auto_login)
|
||||
|
||||
connect(
|
||||
containers_widget, &EntryWidget::clicked_dn,
|
||||
this, &MainWindow::on_containers_clicked_dn);
|
||||
details_widget, &DetailsWidget::on_containers_clicked_dn);
|
||||
|
||||
connect(
|
||||
contents_widget, &EntryWidget::clicked_dn,
|
||||
this, &MainWindow::on_contents_clicked_dn);
|
||||
details_widget, &DetailsWidget::on_contents_clicked_dn);
|
||||
|
||||
connect(
|
||||
action_login, &QAction::triggered,
|
||||
@ -175,36 +125,36 @@ MainWindow::MainWindow(const bool auto_login)
|
||||
action_exit, &QAction::triggered,
|
||||
this, &MainWindow::on_action_exit);
|
||||
|
||||
// Disable actions until login complete
|
||||
set_enabled_for_ad_actions(false);
|
||||
connect_entry_widget(*containers_widget);
|
||||
connect_entry_widget(*contents_widget);
|
||||
connect_entry_widget(*members_widget);
|
||||
|
||||
// Disable widgets until logged in
|
||||
set_enabled_for_widgets(false);
|
||||
|
||||
if (auto_login) {
|
||||
on_action_login();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::set_enabled_for_ad_actions(bool enabled) {
|
||||
QList<QAction *> ad_actions = {
|
||||
action_advanced_view,
|
||||
action_details,
|
||||
action_delete_entry,
|
||||
action_new_user,
|
||||
action_new_computer,
|
||||
action_new_group,
|
||||
action_new_ou,
|
||||
action_edit_policy,
|
||||
};
|
||||
for (auto a : ad_actions) {
|
||||
a->setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_action_login() {
|
||||
AD()->ad_interface_login(SEARCH_BASE, HEAD_DN);
|
||||
}
|
||||
|
||||
void MainWindow::set_enabled_for_widgets(bool enabled) {
|
||||
QList<QWidget *> widgets = {
|
||||
containers_widget,
|
||||
contents_widget,
|
||||
details_widget
|
||||
};
|
||||
|
||||
for (auto e : widgets) {
|
||||
e->setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_ad_interface_login_complete(const QString &base, const QString &head) {
|
||||
set_enabled_for_ad_actions(true);
|
||||
set_enabled_for_widgets(true);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_exit() {
|
||||
@ -216,25 +166,8 @@ void MainWindow::on_action_exit() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_action_details() {
|
||||
QString dn = EntryWidget::get_selected_dn();
|
||||
details_widget->change_target(dn);
|
||||
}
|
||||
|
||||
void MainWindow::on_containers_clicked_dn(const QString &dn) {
|
||||
if (action_containers_click_attributes->isChecked()) {
|
||||
details_widget->change_target(dn);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_contents_clicked_dn(const QString &dn) {
|
||||
if (action_contents_click_attributes->isChecked()) {
|
||||
details_widget->change_target(dn);
|
||||
}
|
||||
}
|
||||
|
||||
bool MainWindow::confirmation_dialog(const QString &text) {
|
||||
const bool confirm_actions = action_toggle_confirmations->isChecked();
|
||||
const bool confirm_actions = SETTINGS()->confirm_actions->isChecked();
|
||||
if (!confirm_actions) {
|
||||
return true;
|
||||
}
|
||||
@ -249,9 +182,34 @@ bool MainWindow::confirmation_dialog(const QString &text) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_action_delete_entry() {
|
||||
const QString dn = EntryWidget::get_selected_dn();
|
||||
void MainWindow::connect_entry_widget(const EntryWidget &widget) {
|
||||
connect(
|
||||
&widget, &EntryWidget::context_menu_details,
|
||||
details_widget, &DetailsWidget::on_context_menu_details);
|
||||
connect(
|
||||
&widget, &EntryWidget::context_menu_rename,
|
||||
this, &MainWindow::on_context_menu_rename);
|
||||
connect(
|
||||
&widget, &EntryWidget::context_menu_delete,
|
||||
this, &MainWindow::on_context_menu_delete);
|
||||
connect(
|
||||
&widget, &EntryWidget::context_menu_new_user,
|
||||
this, &MainWindow::on_context_menu_new_user);
|
||||
connect(
|
||||
&widget, &EntryWidget::context_menu_new_computer,
|
||||
this, &MainWindow::on_context_menu_new_computer);
|
||||
connect(
|
||||
&widget, &EntryWidget::context_menu_new_group,
|
||||
this, &MainWindow::on_context_menu_new_group);
|
||||
connect(
|
||||
&widget, &EntryWidget::context_menu_new_ou,
|
||||
this, &MainWindow::on_context_menu_new_ou);
|
||||
connect(
|
||||
&widget, &EntryWidget::context_menu_edit_policy,
|
||||
this, &MainWindow::on_context_menu_edit_policy);
|
||||
}
|
||||
|
||||
void MainWindow::on_context_menu_delete(const QString &dn) {
|
||||
const QString name = AD()->get_attribute(dn, "name");
|
||||
const QString text = QString("Are you sure you want to delete \"%1\"?").arg(name);
|
||||
const bool confirmed = confirmation_dialog(text);
|
||||
@ -259,35 +217,55 @@ void MainWindow::on_action_delete_entry() {
|
||||
if (confirmed) {
|
||||
AD()->delete_entry(dn);
|
||||
}
|
||||
|
||||
contents_widget->setEnabled(false);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_new_entry_generic(NewEntryType type) {
|
||||
QString dn = EntryWidget::get_selected_dn();
|
||||
void MainWindow::new_entry_dialog(const QString &parent_dn, NewEntryType type) {
|
||||
QString type_string = new_entry_type_to_string[type];
|
||||
QString dialog_title = "New " + type_string;
|
||||
QString input_label = type_string + " name";
|
||||
|
||||
if (dn != "") {
|
||||
create_entry_dialog(type, dn);
|
||||
bool ok;
|
||||
QString name = QInputDialog::getText(nullptr, dialog_title, input_label, QLineEdit::Normal, "", &ok);
|
||||
|
||||
// TODO: maybe expand tree to newly created entry?
|
||||
|
||||
// Create user once dialog is complete
|
||||
if (ok && !name.isEmpty()) {
|
||||
// Attempt to create user in AD
|
||||
|
||||
const QMap<NewEntryType, QString> new_entry_type_to_suffix = {
|
||||
{NewEntryType::User, "CN"},
|
||||
{NewEntryType::Computer, "CN"},
|
||||
{NewEntryType::OU, "OU"},
|
||||
{NewEntryType::Group, "CN"},
|
||||
};
|
||||
QString suffix = new_entry_type_to_suffix[type];
|
||||
|
||||
const QString dn = suffix + "=" + name + "," + parent_dn;
|
||||
|
||||
AD()->create_entry(name, dn, type);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_action_new_user() {
|
||||
on_action_new_entry_generic(NewEntryType::User);
|
||||
void MainWindow::on_context_menu_new_user(const QString &dn) {
|
||||
new_entry_dialog(dn, NewEntryType::User);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_new_computer() {
|
||||
on_action_new_entry_generic(NewEntryType::Computer);
|
||||
void MainWindow::on_context_menu_new_computer(const QString &dn) {
|
||||
new_entry_dialog(dn, NewEntryType::Computer);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_new_group() {
|
||||
on_action_new_entry_generic(NewEntryType::Group);
|
||||
void MainWindow::on_context_menu_new_group(const QString &dn) {
|
||||
new_entry_dialog(dn, NewEntryType::Group);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_new_ou() {
|
||||
on_action_new_entry_generic(NewEntryType::OU);
|
||||
void MainWindow::on_context_menu_new_ou(const QString &dn) {
|
||||
new_entry_dialog(dn, NewEntryType::OU);
|
||||
}
|
||||
|
||||
void MainWindow::on_action_rename() {
|
||||
QString dn = EntryWidget::get_selected_dn();
|
||||
|
||||
void MainWindow::on_context_menu_rename(const QString &dn) {
|
||||
// Get new name from input box
|
||||
QString dialog_title = "Rename";
|
||||
QString input_label = "New name:";
|
||||
@ -299,7 +277,7 @@ void MainWindow::on_action_rename() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_action_edit_policy() {
|
||||
void MainWindow::on_context_menu_edit_policy(const QString &dn) {
|
||||
// Start policy edit process
|
||||
const auto process = new QProcess(this);
|
||||
|
||||
@ -308,7 +286,6 @@ void MainWindow::on_action_edit_policy() {
|
||||
|
||||
const char *uri = "ldap://dc0.domain.alt";
|
||||
|
||||
const QString dn = EntryWidget::get_selected_dn();
|
||||
const QString path = AD()->get_attribute(dn, "gPCFileSysPath");
|
||||
|
||||
QStringList args;
|
||||
|
@ -30,6 +30,7 @@ class AdModel;
|
||||
class ContainersWidget;
|
||||
class ContentsWidget;
|
||||
class DetailsWidget;
|
||||
class EntryWidget;
|
||||
|
||||
class MainWindow final : public QMainWindow {
|
||||
Q_OBJECT
|
||||
@ -37,48 +38,31 @@ Q_OBJECT
|
||||
public:
|
||||
explicit MainWindow(const bool auto_login);
|
||||
|
||||
static QAction *action_advanced_view;
|
||||
static QAction *action_toggle_dn;
|
||||
static QAction *action_details;
|
||||
static QAction *action_delete_entry;
|
||||
static QAction *action_new_user;
|
||||
static QAction *action_new_computer;
|
||||
static QAction *action_new_group;
|
||||
static QAction *action_new_ou;
|
||||
static QAction *action_edit_policy;
|
||||
static QAction *action_rename;
|
||||
|
||||
private slots:
|
||||
void on_action_details();
|
||||
void on_action_delete_entry();
|
||||
void on_action_new_user();
|
||||
void on_action_new_computer();
|
||||
void on_action_new_group();
|
||||
void on_action_new_ou();
|
||||
void on_action_rename();
|
||||
void on_containers_clicked_dn(const QString &dn);
|
||||
void on_contents_clicked_dn(const QString &dn);
|
||||
void on_action_edit_policy();
|
||||
void on_context_menu_rename(const QString &dn);
|
||||
void on_context_menu_delete(const QString &dn);
|
||||
void on_context_menu_new_user(const QString &dn);
|
||||
void on_context_menu_new_computer(const QString &dn);
|
||||
void on_context_menu_new_group(const QString &dn);
|
||||
void on_context_menu_new_ou(const QString &dn);
|
||||
void on_context_menu_edit_policy(const QString &dn);
|
||||
void on_action_login();
|
||||
void on_action_exit();
|
||||
void on_ad_interface_login_complete(const QString &base, const QString &head);
|
||||
|
||||
private:
|
||||
QString get_selected_dn() const;
|
||||
void on_action_new_entry_generic(NewEntryType type);
|
||||
void set_enabled_for_ad_actions(bool enabled);
|
||||
void new_entry_dialog(const QString &parent_dn, NewEntryType type);
|
||||
void set_enabled_for_widgets(bool enabled);
|
||||
bool confirmation_dialog(const QString &text);
|
||||
void connect_entry_widget(const EntryWidget &widget);
|
||||
|
||||
AdModel *ad_model = nullptr;
|
||||
ContainersWidget *containers_widget = nullptr;
|
||||
ContentsWidget *contents_widget = nullptr;
|
||||
DetailsWidget *details_widget = nullptr;
|
||||
|
||||
QAction *action_containers_click_attributes = nullptr;
|
||||
QAction *action_contents_click_attributes = nullptr;
|
||||
QAction *action_login = nullptr;
|
||||
QAction *action_exit = nullptr;
|
||||
QAction *action_toggle_confirmations = nullptr;
|
||||
};
|
||||
|
||||
#endif /* MAIN_WINDOW_H */
|
||||
|
85
src/settings.cpp
Normal file
85
src/settings.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* ADMC - AD Management Center
|
||||
*
|
||||
* Copyright (C) 2020 BaseALT Ltd.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "settings.h"
|
||||
#include "admc.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QSettings>
|
||||
#include <QApplication>
|
||||
#include <QList>
|
||||
|
||||
QAction *make_checkable_action(const QSettings &settings, const QString& text) {
|
||||
QAction *action = new QAction(text);
|
||||
action->setCheckable(true);
|
||||
|
||||
// Load checked state from settings
|
||||
bool checked = settings.value(text, false).toBool();
|
||||
action->setChecked(checked);
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
QString get_settings_file_path() {
|
||||
// NOTE: save to app dir for now for easier debugging
|
||||
QString settings_file_path = QApplication::applicationDirPath() + "/settings.ini";
|
||||
return settings_file_path;
|
||||
}
|
||||
|
||||
Settings::Settings(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
const QString settings_file_path = get_settings_file_path();
|
||||
const QSettings settings(settings_file_path, QSettings::NativeFormat);
|
||||
|
||||
toggle_advanced_view = make_checkable_action(settings, "Advanced View");
|
||||
toggle_show_dn_column = make_checkable_action(settings, "Show DN column");
|
||||
details_on_containers_click = make_checkable_action(settings, "Open attributes on left click in Containers window");
|
||||
details_on_contents_click = make_checkable_action(settings, "Open attributes on left click in Contents window");
|
||||
confirm_actions = make_checkable_action(settings, "Confirm actions");
|
||||
|
||||
// Save settings before the app quits
|
||||
connect(
|
||||
qApp, &QCoreApplication::aboutToQuit,
|
||||
this, &Settings::save_settings);
|
||||
}
|
||||
|
||||
void Settings::save_settings() {
|
||||
const QString settings_file_path = get_settings_file_path();
|
||||
QSettings settings(settings_file_path, QSettings::NativeFormat);
|
||||
|
||||
QList<QAction *> checkable_actions = {
|
||||
toggle_advanced_view,
|
||||
toggle_show_dn_column,
|
||||
details_on_containers_click,
|
||||
details_on_contents_click,
|
||||
confirm_actions,
|
||||
};
|
||||
for (auto action : checkable_actions) {
|
||||
const bool checked = action->isChecked();
|
||||
const QString text = action->text();
|
||||
settings.setValue(text, checked);
|
||||
}
|
||||
}
|
||||
|
||||
const Settings *SETTINGS() {
|
||||
ADMC *app = qobject_cast<ADMC *>(qApp);
|
||||
const Settings *settings = app->settings();
|
||||
return settings;
|
||||
}
|
@ -17,11 +17,30 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CREATE_ENTRY_H
|
||||
#define CREATE_ENTRY_H
|
||||
#ifndef SETTINGS_H
|
||||
#define SETTINGS_H
|
||||
|
||||
#include "ad_interface.h"
|
||||
#include <QObject>
|
||||
|
||||
void create_entry_dialog(NewEntryType type, const QString &given_parent_dn);
|
||||
class QAction;
|
||||
|
||||
#endif /* CREATE_ENTRY_H */
|
||||
class Settings final : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Settings(QObject *parent);
|
||||
|
||||
QAction *toggle_advanced_view = nullptr;
|
||||
QAction *toggle_show_dn_column = nullptr;
|
||||
QAction *details_on_containers_click = nullptr;
|
||||
QAction *details_on_contents_click = nullptr;
|
||||
QAction *confirm_actions = nullptr;
|
||||
|
||||
private:
|
||||
void save_settings();
|
||||
|
||||
};
|
||||
|
||||
const Settings *SETTINGS();
|
||||
|
||||
#endif /* SETTINGS_H */
|
Loading…
x
Reference in New Issue
Block a user