diff --git a/src/admc/console_impls/domain_info_impl.cpp b/src/admc/console_impls/domain_info_impl.cpp new file mode 100644 index 00000000..774ef14f --- /dev/null +++ b/src/admc/console_impls/domain_info_impl.cpp @@ -0,0 +1,127 @@ +/* + * ADMC - AD Management Center + * + * Copyright (C) 2020-2023 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 . + */ + +#include "domain_info_impl.h" +#include "console_widget/console_widget.h" +#include "domain_info_results_widget/domain_info_results_widget.h" +#include "console_impls/object_impl.h" +#include "console_impls/policy_root_impl.h" +#include "console_impls/query_folder_impl.h" +#include "ad_interface.h" +#include "item_type.h" +#include "connection_options_dialog.h" +#include "fsmo/fsmo_dialog.h" +#include "utils.h" +#include "status.h" +#include "globals.h" + +#include +#include +#include +#include +#include +#include + + +DomainInfoImpl::DomainInfoImpl(ConsoleWidget *console_arg): ConsoleImpl(console_arg) { + domain_info_results_widget = new DomainInfoResultsWidget(console_arg); + set_results_widget(domain_info_results_widget); + + edit_fsmo_action = new QAction(tr("Edit FSMO roles"), this); + connection_options_action = new QAction(tr("Open connection options"), this); + connect(edit_fsmo_action, &QAction::triggered, this, &DomainInfoImpl::open_fsmo_dialog); + connect(connection_options_action, &QAction::triggered, this, &DomainInfoImpl::open_connection_options); +} + +void DomainInfoImpl::selected_as_scope(const QModelIndex &index) { + Q_UNUSED(index) + domain_info_results_widget->update(); +} + +void DomainInfoImpl::refresh(const QList &index_list) { + Q_UNUSED(index_list) + + AdInterface ad; + load_domain_info_item(ad); + domain_info_results_widget->update(); + console->clear_scope_tree(); + + console->set_current_scope(console->domain_info_index()); + if (ad.is_connected()) { + console_object_tree_init(console, ad); + console_policy_tree_init(console); + console_query_tree_init(console); + } + console->expand_item(console->domain_info_index()); +} + +QList DomainInfoImpl::get_all_custom_actions() const { + return {edit_fsmo_action, connection_options_action}; +} + +QSet DomainInfoImpl::get_custom_actions(const QModelIndex &index, const bool single_selection) const { + Q_UNUSED(index) + Q_UNUSED(single_selection) + + return {edit_fsmo_action, connection_options_action}; +} + +QSet DomainInfoImpl::get_standard_actions(const QModelIndex &index, const bool single_selection) const { + Q_UNUSED(index) + Q_UNUSED(single_selection) + + return {StandardAction_Refresh}; +} + +QList DomainInfoImpl::column_labels() const { + return {tr("Name")}; +} + +void DomainInfoImpl::load_domain_info_item(const AdInterface &ad) { + QString dc = tr("Host not found"); + if (ad.is_connected()) { + dc = ad.get_dc(); + } + QStandardItem *domain_info_item = console->get_item(console->domain_info_index()); + domain_info_item->setText(tr("Active directory managment center [") + dc + ']'); + domain_info_item->setIcon(QIcon::fromTheme("network-workgroup")); +} + +void DomainInfoImpl::open_fsmo_dialog() { + AdInterface ad; + if (!ad.is_connected()) { + return; + } + + auto dialog = new FSMODialog(ad, console); + dialog->open(); + connect(dialog, &FSMODialog::master_changed, domain_info_results_widget, &DomainInfoResultsWidget::update_fsmo_roles); +} + +void DomainInfoImpl::open_connection_options() { + auto dialog = new ConnectionOptionsDialog(console); + dialog->open(); + connect(dialog, &ConnectionOptionsDialog::domain_changed, + [this](const QString &host) { + show_busy_indicator(); + console->refresh_scope(console->domain_info_index()); + hide_busy_indicator(); + g_status->add_message(tr("Connected to host ") + host, StatusType_Success); + }); +} diff --git a/src/admc/console_impls/domain_info_impl.h b/src/admc/console_impls/domain_info_impl.h new file mode 100644 index 00000000..bd2a6b56 --- /dev/null +++ b/src/admc/console_impls/domain_info_impl.h @@ -0,0 +1,64 @@ +/* + * ADMC - AD Management Center + * + * Copyright (C) 2020-2023 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 . + */ + +#ifndef DOMAININFOIMPL_H +#define DOMAININFOIMPL_H + +/** + * Impl for root domain info item in the scope tree + */ + +#include "console_widget/console_impl.h" + +class ConsoleWidget; +class QModelIndex; +template +class QList; +class DomainInfoResultsWidget; +class AdInterface; + +class DomainInfoImpl : public ConsoleImpl { + Q_OBJECT + +public: + explicit DomainInfoImpl(ConsoleWidget *console_arg); + + void selected_as_scope(const QModelIndex &index); + void refresh(const QList &index_list) override; + + virtual QList get_all_custom_actions() const; + QSet get_custom_actions(const QModelIndex &index, const bool single_selection) const override; + QSet get_standard_actions(const QModelIndex &index, const bool single_selection) const override; + + QList column_labels() const override; + + void load_domain_info_item(const AdInterface &ad); + +private: + QAction *edit_fsmo_action; + QAction *connection_options_action; + + DomainInfoResultsWidget *domain_info_results_widget; + + void open_fsmo_dialog(); + void open_connection_options(); +}; + + +#endif // DOMAININFOIMPL_H