Merge branch 'scripts'

This commit is contained in:
august-alt 2023-03-05 17:34:52 +04:00
commit d182a8cc4c
49 changed files with 4032 additions and 2 deletions

View File

@ -95,6 +95,7 @@ LD_PRELOAD=%buildroot%_libdir/gpui/plugins/libadministrative-templates-plugin.so
%_libdir/gpui/plugins/libreg-plugin.so
%_libdir/gpui/plugins/libspol-plugin.so
%_libdir/gpui/plugins/libpol-plugin.so
%_libdir/gpui/plugins/libscripts-plugin.so
%_libdir/gpui/plugins/libsmb-storage-plugin.so

25
src/io/genericwriter.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef GENERICWRITER_H
#define GENERICWRITER_H
#include "io.h"
#include <memory>
#include <string>
namespace io {
class GPUI_IO_EXPORT GenericWriter
{
public:
virtual ~GenericWriter() = default;
template<typename TData , typename TFormat>
bool save(const std::string &filename, TData *fileData);
template<typename TData, typename TFormat>
bool save(std::ostream &file, const std::string& plName, TData *fileData);
};
}
#include "genericwriter.inl"
#endif // GENERICWRITER_H

78
src/io/genericwriter.inl Normal file
View File

@ -0,0 +1,78 @@
#include "genericwriter.h"
#include "../core/pluginstorage.h"
#include <fstream>
#include <QDebug>
#include <QString>
namespace io {
template<typename TData, typename TFormat>
bool GenericWriter::save(const std::string &filename, TData *fileData)
{
QString pluginName = QString::fromStdString(filename);
pluginName = pluginName.mid(pluginName.lastIndexOf('.') + 1);
TFormat *format = gpui::PluginStorage::instance()->createPluginClass<TFormat>(pluginName);
if(!format)
{
qWarning() << "Format supporting: " << pluginName << " not found.";
return false;
}
std::ofstream file;
file.open(filename, std::ofstream::out);
if(file.good())
{
if(!format->write(file, fileData))
{
qWarning() << "Error while writing file contents: " << format->getErrorString().c_str();
return false;
}
}
file.close();
delete format;
return true;
}
template<typename TData, typename TFormat>
bool GenericWriter::save(std::ostream &fileContent, const std::string &plName, TData *fileData)
{
QString pluginName = QString::fromStdString(plName);
pluginName = pluginName.mid(pluginName.lastIndexOf('.') + 1);
TFormat *format = gpui::PluginStorage::instance()->createPluginClass<TFormat>(pluginName);
if(!format)
{
qWarning() << "Format supporting: " << pluginName << " not found.";
return false;
}
if(fileContent.good())
{
if(!format->write(fileContent, fileData))
{
qWarning() << "Error while writing file contents: " << format->getErrorString().c_str();
return false;
}
}
delete format;
return true;
}
}

View File

@ -25,5 +25,6 @@ add_subdirectory(ini)
add_subdirectory(pol)
add_subdirectory(preferences)
add_subdirectory(reg)
add_subdirectory(scripts)
add_subdirectory(spol)
add_subdirectory(storage)

View File

@ -77,9 +77,12 @@ bool IniFormat::write(std::ostream &output, IniFile *file)
while (keyIterator != section_iterator->constEnd())
{
qDebug() << keyIterator->c_str() << "=" << section_iterator->value(*keyIterator).c_str() << "\n";
pt.add(section_iterator.key() + "." + (*keyIterator), section_iterator->value(*keyIterator));
qDebug() << section_iterator.key().c_str() << "." << keyIterator.key().c_str()
<< keyIterator.value().c_str() << "\n";
pt.add(section_iterator.key() + "." + keyIterator.key(), keyIterator.value());
++keyIterator;
}
++section_iterator;
}
boost::property_tree::ini_parser::write_ini(output, pt);

View File

@ -0,0 +1,82 @@
find_package(GPUI COMPONENTS core io REQUIRED)
find_package(Qt5 COMPONENTS Widgets Core LinguistTools REQUIRED)
find_package(MVVM REQUIRED)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(HEADERS
scriptscontentwidget.h
scriptssnapin.h
scriptswidget.h
scriptspowershellwidget.h
groupscriptcontaineritem.h
scriptitem.h
scriptitemcontainer.h
scriptmodelbuilder.h
scriptsdialog.h
scriptsmodel.h
basescripttabwidget.h
addscriptwidget.h
scriptssnapin.h
scriptssnapinprivate.h
scriptstreemodel.h
scriptsmodelio.h
scriptstreeproxymodel.h
)
set(SOURCES
scriptscontentwidget.cpp
scriptssnapin.cpp
scriptsplugin.cpp
scriptswidget.cpp
scriptspowershellwidget.cpp
groupscriptcontaineritem.cpp
scriptitem.cpp
scriptitemcontainer.cpp
scriptmodelbuilder.cpp
scriptsdialog.cpp
scriptsmodel.cpp
basescripttabwidget.cpp
addscriptwidget.cpp
scriptssnapin.cpp
scriptssnapinprivate.cpp
scriptstreemodel.cpp
scriptsmodelio.cpp
scriptstreeproxymodel.cpp
)
set(UIFORMS
scriptscontentwidget.ui
scriptswidget.ui
scriptsdialog.ui
scriptspowershellwidget.ui
addscriptwidget.ui
)
set(TS_FILES
${CMAKE_CURRENT_SOURCE_DIR}/i18n/scripts_plugin_ru.ts
${CMAKE_CURRENT_SOURCE_DIR}/i18n/scripts_plugin_en.ts
)
include_directories(${CMAKE_SOURCE_DIR}/src)
set(PLUGIN_NAME scripts-plugin)
add_translation(QM_FILES "${TS_FILES}")
add_translation_resource(RESOURCES_SRC "scripts_plugin" "${QM_FILES}")
qt5_add_resources(LIB_RESOURCES ${RESOURCES_SRC})
set(SOURCES ${SOURCES} ${HEADERS} ${UIFORMS})
add_gpui_plugin(${PLUGIN_NAME} ${SOURCES} ${LIB_RESOURCES})
target_link_libraries(${PLUGIN_NAME} Qt5::Core Qt5::Widgets)
target_link_libraries(${PLUGIN_NAME} ${GPUI_LIBRARIES})
target_link_libraries(${PLUGIN_NAME} ${MVVM_LIBRARIES})

View File

@ -0,0 +1,115 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "addscriptwidget.h"
#include "ui_addscriptwidget.h"
#include <gui/filedialogutils.h>
#include <mvvm/factories/viewmodelfactory.h>
#include <mvvm/model/sessionitem.h>
#include <mvvm/model/sessionmodel.h>
#include <mvvm/viewmodel/viewmodeldelegate.h>
#include "scriptitem.h"
#include <QDataWidgetMapper>
#include <QDebug>
namespace scripts_plugin
{
AddScriptWidget::AddScriptWidget(QWidget *parent)
: QDialog(parent)
, m_item(nullptr)
, view_model(nullptr)
, delegate(new ModelView::ViewModelDelegate())
, mapper(new QDataWidgetMapper())
, ui(new Ui::AddScriptWidget())
{
ui->setupUi(this);
}
AddScriptWidget::~AddScriptWidget()
{
delete ui;
}
void AddScriptWidget::setItem(ModelView::SessionItem *item)
{
m_item = item;
view_model = ModelView::Factory::CreatePropertyFlatViewModel(item->model());
view_model->setRootSessionItem(item);
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
mapper->setOrientation(Qt::Vertical);
mapper->setModel(view_model.get());
mapper->setItemDelegate(delegate.get());
mapper->setRootIndex(QModelIndex());
mapper->addMapping(ui->nameLineEdit, 0);
mapper->addMapping(ui->paramLineEdit, 1);
mapper->setCurrentModelIndex(view_model->index(0, 1));
}
void AddScriptWidget::setDeletingFlag(bool flag)
{
deletingFlag = flag;
}
void AddScriptWidget::on_okPushButton_clicked()
{
if (ui->nameLineEdit->text().isEmpty())
{
if (deletingFlag)
{
auto model = m_item->parent()->model();
model->removeItem(m_item->parent(), m_item->tagRow());
}
}
else
{
mapper->submit();
}
this->close();
}
void AddScriptWidget::on_cancelPushButton_clicked()
{
this->close();
}
void AddScriptWidget::on_browsePushButton_clicked()
{
auto dialog = new gpui::FileDialogUtils();
QString file = dialog->getOpenFileName();
if (!file.isEmpty())
{
ui->nameLineEdit->setText(file);
}
delete dialog;
}
} // namespace scripts_plugin

View File

@ -0,0 +1,86 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef MVVM_FOLDERS_ADDSCRIPTS_WIDGET_H
#define MVVM_FOLDERS_ADDSCRIPTS_WIDGET_H
#include <QtWidgets>
QT_BEGIN_NAMESPACE
namespace Ui
{
class AddScriptWidget;
}
QT_END_NAMESPACE
class QDataWidgetMapper;
namespace ModelView
{
class ViewModel;
class ViewModelDelegate;
class SessionItem;
} // namespace ModelView
namespace scripts_plugin
{
class AddScriptWidget : public QDialog
{
public:
Q_OBJECT
public:
explicit AddScriptWidget(QWidget *parent = nullptr);
~AddScriptWidget();
void setItem(ModelView::SessionItem *item);
void setDeletingFlag(bool flag);
private slots:
void on_okPushButton_clicked();
void on_cancelPushButton_clicked();
void on_browsePushButton_clicked();
private:
AddScriptWidget(const AddScriptWidget &) = delete; // copy ctor
AddScriptWidget(AddScriptWidget &&) = delete; // move ctor
AddScriptWidget &operator=(const AddScriptWidget &) = delete; // copy assignment
AddScriptWidget &operator=(AddScriptWidget &&) = delete; // move assignment
private:
//!< Underlying item of this view.
ModelView::SessionItem *m_item{nullptr};
std::unique_ptr<ModelView::ViewModel> view_model;
std::unique_ptr<ModelView::ViewModelDelegate> delegate;
std::unique_ptr<QDataWidgetMapper> mapper;
bool deletingFlag = false;
private:
Ui::AddScriptWidget *ui{nullptr};
};
} // namespace scripts_plugin
#endif //MVVM_FOLDERS_ADDSCRIPTS_WIDGET_H

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AddScriptWidget</class>
<widget class="QWidget" name="AddScriptWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>163</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Script Name:</string>
</property>
<property name="buddy">
<cstring>nameLineEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLineEdit" name="nameLineEdit"/>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="browsePushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Browse...</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="paramLabel">
<property name="text">
<string>Script Parameters:</string>
</property>
<property name="buddy">
<cstring>paramLineEdit</cstring>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLineEdit" name="paramLineEdit"/>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="okPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QPushButton" name="cancelPushButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,168 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "basescripttabwidget.h"
#include "addscriptwidget.h"
#include "scriptitem.h"
#include "../../gui/filedialogutils.h"
#include <mvvm/model/modelutils.h>
#include <mvvm/viewmodel/viewitem.h>
#include <QDebug>
#include <QDesktopServices>
namespace scripts_plugin
{
BaseScriptTabWidget::BaseScriptTabWidget(QWidget *p)
: parent(p)
{}
void BaseScriptTabWidget::onUpClicked()
{
auto *item = this->selectedItem;
if (item != nullptr)
{
ModelView::Utils::MoveUp(this->selectedItem->item()->parent());
}
}
void BaseScriptTabWidget::onDownClicked()
{
auto *item = this->selectedItem;
if (item != nullptr)
{
ModelView::Utils::MoveDown(this->selectedItem->item()->parent());
}
}
void BaseScriptTabWidget::onAddClicked(bool isScripts)
{
auto root = findRootItem(isScripts);
if (root == nullptr)
{
return;
}
auto newItem = this->rootItem->insertItem<ScriptItem>({"", 0});
auto addWidget = new AddScriptWidget(parent);
addWidget->setDeletingFlag(true);
addWidget->setWindowTitle(QObject::tr("Add script"));
addWidget->setItem(newItem);
addWidget->setModal(true);
addWidget->show();
}
void BaseScriptTabWidget::onEditClicked()
{
auto *item = this->selectedItem;
if (item != nullptr)
{
auto addWidget = new AddScriptWidget(parent);
addWidget->setWindowTitle(QObject::tr("Edit script"));
addWidget->setItem(this->selectedItem->item()->parent());
addWidget->setModal(true);
addWidget->show();
}
}
void BaseScriptTabWidget::onDeleteClicked()
{
auto *item = this->selectedItem;
if (item != nullptr)
{
if (this->selectedItem && this->selectedItem->item()->parent())
{
auto parentItem = this->selectedItem->item()->parent();
this->sessionModel->removeItem(parentItem->parent(), parentItem->tagRow());
}
else
{
qWarning() << "Selected item: " << this->selectedItem
<< " Parent: " << this->selectedItem->item()->parent();
}
}
}
void BaseScriptTabWidget::onBrowseClicked()
{
auto path = scriptsItemContainer->property<std::string>(ScriptItemContainer::INI_FILE_PATH);
QDesktopServices::openUrl(QUrl(QString::fromStdString(path), QUrl::TolerantMode));
}
ScriptItemContainer *BaseScriptTabWidget::findRootItem(bool isScripts)
{
std::string sectionName = "Shutdown";
if (isScripts)
{
if (this->isStartUpScripts)
{
sectionName = "Logon";
}
else
{
sectionName = "Logoff";
}
}
else
{
if (this->isStartUpScripts)
{
sectionName = "Startup";
}
}
auto containers = this->sessionModel->topItems();
for (size_t i = 0; i < containers.size(); i++)
{
auto itemContainer = containers[i];
auto section = dynamic_cast<ScriptItemContainer *>(itemContainer);
if (section)
{
if (sectionName.compare(
section->property<std::string>(ScriptItemContainer::SECTION_NAME))
== 0)
{
return section;
}
}
}
qWarning() << "Section:" << sectionName.c_str() << " not found!!";
return nullptr;
}
BaseScriptTabWidget::~BaseScriptTabWidget() {}
} // namespace scripts_plugin

View File

@ -0,0 +1,109 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef BASESCRIPTSWIDGET_H
#define BASESCRIPTSWIDGET_H
#include "groupscriptcontaineritem.h"
#include "scriptitemcontainer.h"
#include <mvvm/viewmodel/viewmodel.h>
#include <mvvm/viewmodel/viewmodeldelegate.h>
#include <mvvm/factories/viewmodelfactory.h>
#include <QHeaderView>
namespace scripts_plugin
{
class BaseScriptTabWidget
{
public:
BaseScriptTabWidget(QWidget *p);
virtual ~BaseScriptTabWidget();
BaseScriptTabWidget(const BaseScriptTabWidget &) = delete; //copy ctor
BaseScriptTabWidget(BaseScriptTabWidget &&) = delete; // mode ctor
BaseScriptTabWidget &operator=(const BaseScriptTabWidget &) = delete; //copy assignment
BaseScriptTabWidget &operator=(BaseScriptTabWidget &&) = delete; //mode assignment
public:
void onUpClicked();
void onDownClicked();
void onAddClicked(bool isScripts);
void onEditClicked();
void onDeleteClicked();
void onBrowseClicked();
public:
std::unique_ptr<ModelView::ViewModel> model = nullptr;
ModelView::SessionModel *sessionModel = nullptr;
ModelView::SessionItem *rootItem = nullptr;
ScriptItemContainer *scriptsItemContainer = nullptr;
ModelView::ViewItem *selectedItem = nullptr;
bool isStartUpScripts = false;
template<typename TUi>
void setItem(TUi *ui, ScriptItemContainer *item, bool startUpScriptsFlag)
{
isStartUpScripts = startUpScriptsFlag;
scriptsItemContainer = item;
rootItem = item->getScripts();
sessionModel = rootItem->model();
model = ModelView::Factory::CreatePropertyTableViewModel(rootItem->model());
model->setRootSessionItem(rootItem);
ui->treeView->setModel(model.get());
setupConnections(ui);
}
template<typename TUi>
void setupConnections(TUi *ui)
{
QObject::connect(ui->treeView->selectionModel(),
&QItemSelectionModel::selectionChanged,
[&](const QItemSelection &selected, const QItemSelection &deselected) {
Q_UNUSED(deselected);
if (model && selected.indexes().size() > 0)
{
QModelIndex selectedIndex = selected.indexes().at(0);
selectedItem = model->itemFromIndex(selectedIndex);
}
});
}
private:
ScriptItemContainer *findRootItem(bool isScripts);
private:
QWidget *parent;
};
} // namespace scripts_plugin
#endif // BASESCRIPTSWIDGET_H

View File

@ -0,0 +1,38 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "groupscriptcontaineritem.h"
#include "scriptitemcontainer.h"
namespace scripts_plugin
{
GroupScriptContainerItem::GroupScriptContainerItem()
: ModelView::CompoundItem("GroupScriptContainerItem")
{
registerTag(ModelView::TagInfo::universalTag(ITEM, {GROUP_ITEM_MEMBER_TYPE}), true);
}
GroupScriptContainerItem::GroupScriptContainerItem(const GroupScriptContainerItem &other)
: ModelView::CompoundItem("GroupScriptContainerItem")
{
registerTag(ModelView::TagInfo::universalTag(ITEM, {GROUP_ITEM_MEMBER_TYPE}), true);
}
} // namespace scripts_plugin

View File

@ -0,0 +1,42 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef GROUPSCRIPTCONTAINERITEM_H
#define GROUPSCRIPTCONTAINERITEM_H
#include <mvvm/model/compounditem.h>
namespace scripts_plugin
{
class GroupScriptContainerItem : public ModelView::CompoundItem
{
public:
static inline const std::string ITEM = "ITEMS";
static inline const std::string GROUP_ITEM_MEMBER_TYPE = "ScriptItem";
public:
GroupScriptContainerItem();
GroupScriptContainerItem(const GroupScriptContainerItem &other);
};
} // namespace scripts_plugin
Q_DECLARE_METATYPE(scripts_plugin::GroupScriptContainerItem)
#endif // GROUPSCRIPTCONTAINERITEM_H

View File

@ -0,0 +1,251 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>AddScriptWidget</name>
<message>
<source>Form</source>
<translatorcomment>Форма</translatorcomment>
<translation>Form</translation>
</message>
<message>
<source>Script Name:</source>
<translation>Script Name:</translation>
</message>
<message>
<source>Browse...</source>
<translation>Browse...</translation>
</message>
<message>
<source>Script Parameters:</source>
<translation>Script Parameters:</translation>
</message>
<message>
<source>OK</source>
<translation>OK</translation>
</message>
<message>
<source>Cancel</source>
<translation>Cancel</translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<source>[Local Group Policy]</source>
<translation>[Local Group Policy]</translation>
</message>
<message>
<source>Group policy</source>
<translation>Group policy</translation>
</message>
<message>
<source>Machine</source>
<translatorcomment>Machine</translatorcomment>
<translation>Machine</translation>
</message>
<message>
<source>Machine level policies</source>
<translation>Machine level policies</translation>
</message>
<message>
<source>System settings</source>
<translation>System settings</translation>
</message>
<message>
<source>Scripts</source>
<translation>Scripts</translation>
</message>
<message>
<source>On startup</source>
<translation>On startup</translation>
</message>
<message>
<source>On shutdown</source>
<translation>On shutdown</translation>
</message>
<message>
<source>User</source>
<translation>User</translation>
</message>
<message>
<source>User level policies.</source>
<translation>User level policies.</translation>
</message>
<message>
<source>Logon</source>
<translation>Logon</translation>
</message>
<message>
<source>Logoff</source>
<translation>Logoff</translation>
</message>
<message>
<source>Startup</source>
<translation>Startup</translation>
</message>
<message>
<source>Shutdown</source>
<translation>Shutdown</translation>
</message>
<message>
<source>Add script</source>
<translation>Add script</translation>
</message>
<message>
<source>Edit script</source>
<translation>Edit script</translation>
</message>
<message>
<source>System settings for computer</source>
<translation>System settings for computer</translation>
</message>
<message>
<source>Scripts for computer</source>
<translation>Scripts for computer</translation>
</message>
<message>
<source>System settings for user</source>
<translation>System settings for user</translation>
</message>
<message>
<source>Scripts for user</source>
<translation>Scripts for user</translation>
</message>
</context>
<context>
<name>ScriptsContentWidget</name>
<message>
<source>Form</source>
<translation>Form</translation>
</message>
</context>
<context>
<name>ScriptsDialog</name>
<message>
<source>Dialog</source>
<translation>Dialog</translation>
</message>
<message>
<source>Scripts</source>
<translation>Scripts</translation>
</message>
<message>
<source>PowerShell Scripts</source>
<translation>PowerShell Scripts</translation>
</message>
</context>
<context>
<name>ScriptsPowerShellWidget</name>
<message>
<source>Form</source>
<translation>Form</translation>
</message>
<message>
<source>Not configured</source>
<translation>Not configured</translation>
</message>
<message>
<source>Up</source>
<translation>Up</translation>
</message>
<message>
<source>Show files</source>
<translation>Show files</translation>
</message>
<message>
<source>Edit</source>
<translation>Edit</translation>
</message>
<message>
<source>Powershell scrips require at least Windows 7 or Windows Server 2008 R2</source>
<translation>Powershell scrips require at least Windows 7 or Windows Server 2008 R2</translation>
</message>
<message>
<source>For this GPO, run scripts in the following opder:</source>
<translation>For this GPO, run scripts in the following opder:</translation>
</message>
<message>
<source>Down</source>
<translation>Down</translation>
</message>
<message>
<source>Remove</source>
<translation>Remove</translation>
</message>
<message>
<source>Add</source>
<translation>Add</translation>
</message>
<message>
<source>Windows PowerShell Logon Scripts for Default Domain Policy</source>
<translation>Windows PowerShell Logon Scripts for Default Domain Policy</translation>
</message>
<message>
<source>For this GPO, run scripts in the following order:</source>
<translation>For this GPO, run scripts in the following order:</translation>
</message>
</context>
<context>
<name>ScriptsWidget</name>
<message>
<source>Form</source>
<translation>Form</translation>
</message>
<message>
<source>Logon scripts for Default Domain Policy</source>
<translation>Logon scripts for Default Domain Policy</translation>
</message>
<message>
<source>Up</source>
<translation>Up</translation>
</message>
<message>
<source>Down</source>
<translation>Down</translation>
</message>
<message>
<source>Add</source>
<translation>Add</translation>
</message>
<message>
<source>Edit</source>
<translation>Edit</translation>
</message>
<message>
<source>Remove</source>
<translation>Remove</translation>
</message>
<message>
<source>To view the script filess stored in this Group Policy Object, press the button below</source>
<translation type="vanished">To view the script files stored in this Group Policy Object, press the button below</translation>
</message>
<message>
<source>To view the script files stored in this Group Policy Object, press the button below</source>
<translation>To view the script files stored in this Group Policy Object, press the button below</translation>
</message>
<message>
<source>Show files</source>
<translation>Show files</translation>
</message>
</context>
<context>
<name>scripts_plugin::ScriptsContentWidget</name>
<message>
<source>Logon</source>
<translation>Logon</translation>
</message>
<message>
<source>Logoff</source>
<translation>Logoff</translation>
</message>
<message>
<source>Startup</source>
<translation>Startup</translation>
</message>
<message>
<source>Shutdown</source>
<translation>Shutdown</translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,249 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="ru_RU">
<context>
<name>AddScriptWidget</name>
<message>
<source>Form</source>
<translation>Форма</translation>
</message>
<message>
<source>Script Name:</source>
<translation>Имя сценария:</translation>
</message>
<message>
<source>Browse...</source>
<translation>Обзор...</translation>
</message>
<message>
<source>Script Parameters:</source>
<translation>Параметры сценария:</translation>
</message>
<message>
<source>OK</source>
<translation>OK</translation>
</message>
<message>
<source>Cancel</source>
<translation>Отмена</translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<source>[Local Group Policy]</source>
<translation>[Локальная групповая политика]</translation>
</message>
<message>
<source>Group policy</source>
<translation>Групповая политика</translation>
</message>
<message>
<source>Machine</source>
<translation>Компьютер</translation>
</message>
<message>
<source>Machine level policies</source>
<translation>Политика для компьютера</translation>
</message>
<message>
<source>System settings</source>
<translation>Настройки системы</translation>
</message>
<message>
<source>Scripts</source>
<translation>Скрипты</translation>
</message>
<message>
<source>On startup</source>
<translation>При запуске</translation>
</message>
<message>
<source>On shutdown</source>
<translation>При выключении</translation>
</message>
<message>
<source>User</source>
<translation>Пользователь</translation>
</message>
<message>
<source>User level policies.</source>
<translation>Политика для пользователя</translation>
</message>
<message>
<source>Logon</source>
<translation>Вход в систему</translation>
</message>
<message>
<source>Logoff</source>
<translation>Выход из системы</translation>
</message>
<message>
<source>Startup</source>
<translation>Запуск</translation>
</message>
<message>
<source>Shutdown</source>
<translation>Завершение работы</translation>
</message>
<message>
<source>Add script</source>
<translation>Добавить скрипт</translation>
</message>
<message>
<source>Edit script</source>
<translation>Редактировать скрипт</translation>
</message>
<message>
<source>System settings for computer</source>
<translation>Настройки системы для компьютера</translation>
</message>
<message>
<source>Scripts for computer</source>
<translation>Скрипты для компютера</translation>
</message>
<message>
<source>System settings for user</source>
<translation>Системные настройки для пользователя</translation>
</message>
<message>
<source>Scripts for user</source>
<translation>Скрипты для пользователя</translation>
</message>
</context>
<context>
<name>ScriptsContentWidget</name>
<message>
<source>Form</source>
<translation>Форма</translation>
</message>
</context>
<context>
<name>ScriptsDialog</name>
<message>
<source>Dialog</source>
<translation>Диалог</translation>
</message>
<message>
<source>Scripts</source>
<translation>Сценарий</translation>
</message>
<message>
<source>PowerShell Scripts</source>
<translation>Скрипты PowerShell</translation>
</message>
</context>
<context>
<name>ScriptsPowerShellWidget</name>
<message>
<source>Form</source>
<translation>Форма</translation>
</message>
<message>
<source>Not configured</source>
<translation>Не настроено</translation>
</message>
<message>
<source>Up</source>
<translation>Вверх</translation>
</message>
<message>
<source>Show files</source>
<translation>Показать файлы</translation>
</message>
<message>
<source>Edit</source>
<translation>Изменить</translation>
</message>
<message>
<source>Powershell scrips require at least Windows 7 or Windows Server 2008 R2</source>
<translation>Для сценариев Powershell требуется как минимум Windows 7 или Windows Server 2008 R2</translation>
</message>
<message>
<source>For this GPO, run scripts in the following opder:</source>
<translation>Для этого объекта групповой политики, запустите сценарии в следующем порядке:</translation>
</message>
<message>
<source>Down</source>
<translation>Вниз</translation>
</message>
<message>
<source>Remove</source>
<translation>Удалить</translation>
</message>
<message>
<source>Add</source>
<translation>Добавить</translation>
</message>
<message>
<source>Windows PowerShell Logon Scripts for Default Domain Policy</source>
<translation>Сценарии входа в Windows PowerShell для политики домена по умолчанию</translation>
</message>
<message>
<source>For this GPO, run scripts in the following order:</source>
<translation>Запуск скриптов для этого объекта в следующем порядке</translation>
</message>
</context>
<context>
<name>ScriptsWidget</name>
<message>
<source>Form</source>
<translation>Форма</translation>
</message>
<message>
<source>Logon scripts for Default Domain Policy</source>
<translation>Сценарии входа в систему для политики домена по умолчанию</translation>
</message>
<message>
<source>Up</source>
<translation>Вверх</translation>
</message>
<message>
<source>Down</source>
<translation>Вниз</translation>
</message>
<message>
<source>Add</source>
<translation>Добавить</translation>
</message>
<message>
<source>Edit</source>
<translation>Изменить</translation>
</message>
<message>
<source>Remove</source>
<translation>Удалить</translation>
</message>
<message>
<source>To view the script filess stored in this Group Policy Object, press the button below</source>
<translation type="vanished">Чтобы просмотреть файлы сценариев, хранящиеся в этом объекте групповой политики, нажмите кнопку ниже</translation>
</message>
<message>
<source>To view the script files stored in this Group Policy Object, press the button below</source>
<translation>Чтобы просмотреть файлы сценариев, хранящиеся в этом объекте групповой политики, нажмите кнопку ниже</translation>
</message>
<message>
<source>Show files</source>
<translation>Показать файлы</translation>
</message>
</context>
<context>
<name>scripts_plugin::ScriptsContentWidget</name>
<message>
<source>Logon</source>
<translation>Вход в систему</translation>
</message>
<message>
<source>Logoff</source>
<translation>Выход из системы</translation>
</message>
<message>
<source>Startup</source>
<translation>Запуск</translation>
</message>
<message>
<source>Shutdown</source>
<translation>Завершение работы</translation>
</message>
</context>
</TS>

View File

@ -0,0 +1,44 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptitem.h"
namespace scripts_plugin
{
ScriptItem::ScriptItem()
: ModelView::CompoundItem("ScriptItem")
{
addProperty(propertyToString(PATH), "");
addProperty(propertyToString(PARAMETER), "");
}
ScriptItem::ScriptItem(const ScriptItem &other)
: ModelView::CompoundItem("ScriptItem")
{
addProperty(propertyToString(PATH), other.property<std::string>(propertyToString(PATH)));
addProperty(propertyToString(PATH), other.property<std::string>(propertyToString(PATH)));
}
constexpr int ScriptItem::propertyToInt(PropertyType &type)
{
return static_cast<int>(type);
}
} // namespace scripts_plugin

View File

@ -0,0 +1,63 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef SCRIPTITEM_H
#define SCRIPTITEM_H
#include <mvvm/model/compounditem.h>
namespace scripts_plugin
{
class ScriptItem : public ModelView::CompoundItem
{
public:
enum PropertyType
{
PATH = 0,
PARAMETER = 1
};
public:
ScriptItem();
ScriptItem(const ScriptItem &other);
constexpr static int propertyToInt(PropertyType &type);
constexpr static const char *propertyToString(const PropertyType &type)
{
switch (type)
{
case PATH:
return "path";
case PARAMETER:
return "parameter";
default:
break;
}
return "";
}
};
} // namespace scripts_plugin
Q_DECLARE_METATYPE(scripts_plugin::ScriptItem)
#endif // SCRIPTITEM_H

View File

@ -0,0 +1,60 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptitemcontainer.h"
#include "groupscriptcontaineritem.h"
#include "scriptitem.h"
#include <QDebug>
namespace scripts_plugin
{
ScriptItemContainer::ScriptItemContainer()
: ModelView::CompoundItem("ScriptItemContainer")
{
addProperty(SECTION_NAME, "");
addProperty(INI_FILE_PATH, "");
addProperty<GroupScriptContainerItem>(SCRIPTS)->setVisible(false);
}
ScriptItemContainer::ScriptItemContainer(const ScriptItemContainer &other)
: ModelView::CompoundItem()
{
addProperty(SECTION_NAME, other.property<std::string>(SECTION_NAME));
addProperty(INI_FILE_PATH, other.INI_FILE_PATH);
addProperty(SCRIPTS, other.SCRIPTS);
}
GroupScriptContainerItem *ScriptItemContainer::getScripts() const
{
return dynamic_cast<GroupScriptContainerItem *>(children().back());
}
void ScriptItemContainer::retranslateStrings()
{
qWarning() << "TRanslate section: "
<< this->property<std::string>(ScriptItemContainer::SECTION_NAME).c_str();
}
} // namespace scripts_plugin

View File

@ -0,0 +1,54 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef SCRIPTITEMCONTAINER_H
#define SCRIPTITEMCONTAINER_H
#include <mvvm/model/compounditem.h>
class ScriptItem;
namespace scripts_plugin
{
class ScriptItem;
class GroupScriptContainerItem;
class ScriptItemContainer : public ModelView::CompoundItem
{
public:
static inline const std::string SECTION_NAME = "sectionName";
static inline const std::string SCRIPTS = "scripts";
static inline const std::string INI_FILE_PATH = "ini_file_path";
ScriptItemContainer();
ScriptItemContainer(const ScriptItemContainer &other);
GroupScriptContainerItem *getScripts() const;
void retranslateStrings();
};
} // namespace scripts_plugin
Q_DECLARE_METATYPE(scripts_plugin::ScriptItemContainer)
#endif // SCRIPTITEMCONTAINER_H

View File

@ -0,0 +1,116 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptmodelbuilder.h"
#include "groupscriptcontaineritem.h"
#include "scriptitem.h"
#include "scriptitemcontainer.h"
#include "../../io/genericwriter.h"
#include <regex>
namespace scripts_plugin
{
ScriptModelBuilder::ScriptModelBuilder() {}
void ScriptModelBuilder::iniToModel(ScriptsModel *model,
io::IniFile *iniFile,
std::string &file_path)
{
auto sections = iniFile->getAllSections();
model->clear();
static const auto reg = std::regex("^\\d+");
for (const auto &section : sections->keys())
{
auto container = model->insertItem<ScriptItemContainer>();
container->setProperty(ScriptItemContainer::SECTION_NAME, section);
container->setProperty(ScriptItemContainer::INI_FILE_PATH, file_path);
auto group = container->getScripts();
std::string iniCommandPath;
std::string iniCommandParam;
for (const auto &path : sections.get()->value(section).keys())
{
std::string value = std::regex_replace(path, reg, "");
std::string secondValue = std::regex_replace(sections.get()->value(section).value(path),
reg,
"");
if (value.compare("CmdLine") == 0)
{
iniCommandPath = secondValue;
continue;
}
if (value.compare("Parameters") == 0)
{
iniCommandParam = secondValue;
auto item = group->insertItem<ScriptItem>(GroupScriptContainerItem::ITEM);
item->setProperty(ScriptItem::propertyToString(ScriptItem::PropertyType::PATH),
iniCommandPath);
item->setProperty(ScriptItem::propertyToString(ScriptItem::PropertyType::PARAMETER),
iniCommandParam);
}
}
}
}
std::unique_ptr<io::IniFile> ScriptModelBuilder::modelToIni(ScriptsModel *model)
{
auto iniFile = std::make_unique<io::IniFile>();
for (auto section : model->rootItem()->children())
{
auto sectionName = section->property<std::string>(ScriptItemContainer::SECTION_NAME);
auto container = dynamic_cast<ScriptItemContainer *>(section);
if (container)
{
int numberOfCommand = 0;
for (auto item : container->getScripts()->children())
{
std::string cmdLine = std::to_string(numberOfCommand) + "CmdLine";
std::string paramLine = std::to_string(numberOfCommand) + "Parameters";
auto path = item->property<std::string>(
ScriptItem::propertyToString(ScriptItem::PropertyType::PATH));
auto param = item->property<std::string>(
ScriptItem::propertyToString(ScriptItem::PropertyType::PARAMETER));
iniFile->addValue(sectionName, cmdLine, path);
iniFile->addValue(sectionName, paramLine, param);
numberOfCommand++;
}
}
}
return iniFile;
}
} // namespace scripts_plugin

View File

@ -0,0 +1,42 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef SCRIPTMODELBUILDER_H
#define SCRIPTMODELBUILDER_H
#include "groupscriptcontaineritem.h"
#include "scriptsmodel.h"
#include "../../io/inifile.h"
namespace scripts_plugin
{
class ScriptModelBuilder
{
public:
ScriptModelBuilder();
void iniToModel(ScriptsModel *model, io::IniFile *iniFile, std::string &file_path);
std::unique_ptr<io::IniFile> modelToIni(ScriptsModel *model);
};
} // namespace scripts_plugin
#endif // SCRIPTMODELBUILDER_H

View File

@ -0,0 +1,35 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef GPUI_SCRIPTS_H
#define GPUI_SCRIPTS_H
#include "../../core/common.h"
#ifdef GPUI_SCRIPTS_LIBRARY
#define GPUI_SCRIPTS_EXPORT GPUI_SYMBOL_EXPORT
#else
#define GPUI_SCRIPTS_EXPORT GPUI_SYMBOL_IMPORT
#endif
namespace gpui
{}
#endif // GPUI_SCRIPTS_H

View File

@ -0,0 +1,135 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptscontentwidget.h"
#include "ui_scriptscontentwidget.h"
#include "scriptsdialog.h"
#include <mvvm/factories/viewmodelfactory.h>
#include <mvvm/model/sessionitem.h>
#include <mvvm/viewmodel/viewitem.h>
#include <mvvm/viewmodel/viewmodel.h>
#include <mvvm/viewmodel/viewmodeldelegate.h>
#include <QDataWidgetMapper>
namespace scripts_plugin
{
ScriptsContentWidget::ScriptsContentWidget(ScriptsSnapIn *sn, QWidget *parent)
: QWidget(parent)
, model(std::make_unique<QStandardItemModel>())
, ui(new Ui::ScriptsContentWidget())
, snapIn(sn)
{
ui->setupUi(this);
buildModel();
}
ScriptsContentWidget::~ScriptsContentWidget()
{
delete ui;
}
void ScriptsContentWidget::setNamespace(bool machineNamespace)
{
isMachineNamespace = machineNamespace;
buildModel();
}
void ScriptsContentWidget::buildModel()
{
model = std::make_unique<QStandardItemModel>();
QString startupItem = tr("Logon");
QString shutdownItem = tr("Logoff");
if (isMachineNamespace)
{
startupItem = tr("Startup");
shutdownItem = tr("Shutdown");
}
QStandardItem *first = new QStandardItem();
QStandardItem *second = new QStandardItem();
first->setData(QVariant(startupItem), Qt::DisplayRole);
second->setData(QVariant(shutdownItem), Qt::DisplayRole);
first->setData(QVariant(true));
second->setData(QVariant(false));
model.get()->appendRow(first);
model.get()->appendRow(second);
ui->listView->setModel(model.get());
connect(ui->listView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
this,
SLOT(startDialog(QItemSelection)));
}
void ScriptsContentWidget::startDialog(QItemSelection item)
{
if (!item.indexes().isEmpty())
{
auto isStartupItem = model.get()->data(item.indexes().first(), isStartupRole);
if (isStartupItem.toBool())
{
isStartupScripts = true;
}
else
{
isStartupScripts = false;
}
auto dialog = new ScriptsDialog(this);
if (isMachineNamespace)
{
dialog->setModels(snapIn->d->machineScriptsModel.get(),
snapIn->d->machinePowerScriptsModel.get(),
isStartupScripts);
}
else
{
dialog->setModels(snapIn->d->userScriptsModel.get(),
snapIn->d->userPowerScriptsModel.get(),
isStartupScripts);
}
QObject::connect(dialog,
&ScriptsDialog::saveDataSignal,
snapIn->d,
&ScriptsSnapInPrivate::saveData);
QObject::connect(dialog,
&ScriptsDialog::reloaddataSignal,
snapIn->d,
&ScriptsSnapInPrivate::reloadData);
dialog->exec();
}
}
} // namespace scripts_plugin

View File

@ -0,0 +1,87 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef SCRIPTS_CONTENT_WIDGET_H
#define SCRIPTS_CONTENT_WIDGET_H
#include <scriptssnapin.h>
#include <QtWidgets>
#include "../../../src/core/common.h"
QT_BEGIN_NAMESPACE
namespace Ui
{
class ScriptsContentWidget;
}
QT_END_NAMESPACE
class QDataWidgetMapper;
namespace ModelView
{
class ViewModel;
class ViewModelDelegate;
class SessionItem;
class SessionModel;
} // namespace ModelView
namespace scripts_plugin
{
class GPUI_SYMBOL_EXPORT ScriptsContentWidget : public QWidget
{
public:
Q_OBJECT
public:
explicit ScriptsContentWidget(ScriptsSnapIn *sn, QWidget *parent = nullptr);
~ScriptsContentWidget() override;
void setNamespace(bool machineNamespace);
private slots:
void startDialog(QItemSelection item);
private:
ScriptsContentWidget(const ScriptsContentWidget &) = delete; // copy ctor
ScriptsContentWidget(ScriptsContentWidget &&) = delete; // move ctor
ScriptsContentWidget &operator=(const ScriptsContentWidget &) = delete; // copy assignment
ScriptsContentWidget &operator=(ScriptsContentWidget &&) = delete; // move assignment
void buildModel();
private:
std::unique_ptr<QStandardItemModel> model = nullptr;
Ui::ScriptsContentWidget *ui{nullptr};
bool isMachineNamespace = false;
bool isStartupScripts = false;
ScriptsSnapIn *snapIn;
static inline int isStartupRole = Qt::UserRole + 1;
};
} // namespace scripts_plugin
Q_DECLARE_METATYPE(scripts_plugin::ScriptsContentWidget *)
#endif //SCRIPTS_CONTENT_WIDGET_H

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScriptsContentWidget</class>
<widget class="QWidget" name="ScriptsContentWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>663</width>
<height>577</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QListView" name="listView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,133 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptsdialog.h"
#include "groupscriptcontaineritem.h"
#include "scriptitemcontainer.h"
#include "ui_scriptsdialog.h"
#include "ui_scriptspowershellwidget.h"
#include "ui_scriptswidget.h"
#include <mvvm/factories/viewmodelfactory.h>
#include <QDebug>
namespace scripts_plugin
{
ScriptsDialog::ScriptsDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::ScriptsDialog())
, isStartUpScripts(false)
{
ui->setupUi(this);
QPushButton *applyButton = ui->buttonBox->button(QDialogButtonBox::StandardButton::Apply);
QObject::connect(applyButton, &QPushButton::clicked, this, &ScriptsDialog::on_Apply);
}
ScriptsDialog::~ScriptsDialog()
{
delete ui;
}
void ScriptsDialog::setModels(ScriptsModel *scriptsModel,
ScriptsModel *powerScriptsModel,
bool isOnStartUp)
{
ScriptItemContainer *scriptsItem = nullptr;
ScriptItemContainer *powerScriptsItem = nullptr;
isStartUpScripts = isOnStartUp;
if (isOnStartUp)
{
scriptsItem = findItemContainer(scriptsModel, "Logon");
powerScriptsItem = findItemContainer(powerScriptsModel, "Startup");
}
else
{
scriptsItem = findItemContainer(scriptsModel, "Logoff");
powerScriptsItem = findItemContainer(powerScriptsModel, "Shutdown");
}
if (scriptsItem != nullptr)
{
setItem(scriptsItem, ui->scriptsTab);
}
if (powerScriptsItem != nullptr)
{
setItem(powerScriptsItem, ui->powerShellScriptsTab);
}
}
ScriptItemContainer *ScriptsDialog::findItemContainer(ScriptsModel *model, std::string section)
{
auto containers = model->topItems();
for (size_t i = 0; i < containers.size(); i++)
{
auto item = dynamic_cast<ScriptItemContainer *>(containers[i]);
if (item)
{
auto containerSectionName = item->property<std::string>(
ScriptItemContainer::SECTION_NAME);
if (containerSectionName.compare(section) == 0)
{
return item;
}
}
}
qWarning() << "Section: " << section.c_str() << " not found!";
return nullptr;
}
template<typename TWidget>
void ScriptsDialog::setItem(ModelView::SessionItem *scriptsItem, TWidget &widget)
{
auto container = dynamic_cast<ScriptItemContainer *>(scriptsItem);
if (container)
{
widget->setItem(container, isStartUpScripts);
}
}
void ScriptsDialog::submit() {}
void ScriptsDialog::on_buttonBox_accepted()
{
emit(saveDataSignal());
}
void ScriptsDialog::on_buttonBox_rejected()
{
emit(reloaddataSignal());
}
void ScriptsDialog::on_Apply()
{
emit(saveDataSignal());
}
} // namespace scripts_plugin

View File

@ -0,0 +1,94 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef SCRIPTSDIALOG_H
#define SCRIPTSDIALOG_H
#include "scriptsmodel.h"
#include "scriptswidget.h"
#include "scriptspowershellwidget.h"
#include "../../../src/core/common.h"
#include <QDataWidgetMapper>
#include <QDialog>
#include <QDialogButtonBox>
#include <qabstractbutton.h>
#include <mvvm/viewmodel/viewmodel.h>
#include <mvvm/viewmodel/viewmodeldelegate.h>
namespace Ui
{
class ScriptsDialog;
}
namespace scripts_plugin
{
class ScriptItemContainer;
class GPUI_SYMBOL_EXPORT ScriptsDialog : public QDialog
{
public:
Q_OBJECT
public:
ScriptsDialog(QWidget *parent = nullptr);
~ScriptsDialog();
void setModels(ScriptsModel *scriptsModel, ScriptsModel *powerScriptsModel, bool isOnStartUp);
private:
template<typename TWidget>
void setItem(ModelView::SessionItem *scriptsItem, TWidget &widget);
ScriptItemContainer *findItemContainer(ScriptsModel *model, std::string section);
public slots:
void submit();
private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_Apply();
signals:
void saveDataSignal();
void reloaddataSignal();
private:
ScriptsDialog(const ScriptsDialog &) = delete;
ScriptsDialog(ScriptsDialog &&) = delete;
ScriptsDialog operator=(const ScriptsDialog &) = delete;
ScriptsDialog operator=(ScriptsDialog &&) = delete;
private:
Ui::ScriptsDialog *ui;
bool isStartUpScripts;
};
} // namespace scripts_plugin
#endif // SCRIPTSDIALOG_H

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScriptsDialog</class>
<widget class="QDialog" name="ScriptsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="scripts_plugin::ScriptsWidget" name="scriptsTab">
<property name="accessibleName">
<string/>
</property>
<attribute name="title">
<string>Scripts</string>
</attribute>
</widget>
<widget class="scripts_plugin::ScriptsPowerShellWidget" name="powerShellScriptsTab">
<attribute name="title">
<string>PowerShell Scripts</string>
</attribute>
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>scripts_plugin::ScriptsWidget</class>
<extends>QWidget</extends>
<header>scriptswidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>scripts_plugin::ScriptsPowerShellWidget</class>
<extends>QWidget</extends>
<header>scriptspowershellwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ScriptsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>257</x>
<y>290</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ScriptsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>325</x>
<y>290</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,35 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptsmodel.h"
#include "groupscriptcontaineritem.h"
#include "scriptitem.h"
#include "scriptitemcontainer.h"
namespace scripts_plugin
{
ScriptsModel::ScriptsModel()
: ModelView::SessionModel("ScriptsModel")
{
registerItem<GroupScriptContainerItem>();
registerItem<ScriptItemContainer>();
registerItem<ScriptItem>();
}
} // namespace scripts_plugin

View File

@ -0,0 +1,38 @@
/***********************************************************************************************************************
**
** Copyright (C) 2021 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef SCRIPTSMODEL_H
#define SCRIPTSMODEL_H
#include "../../../src/core/common.h"
#include <mvvm/model/sessionmodel.h>
namespace scripts_plugin
{
class GPUI_SYMBOL_EXPORT ScriptsModel : public ModelView::SessionModel
{
public:
ScriptsModel();
};
} // namespace scripts_plugin
#endif // SCRIPTSMODEL_H

View File

@ -0,0 +1,139 @@
#include "scriptsmodelio.h"
#include "../../io/genericreader.h"
#include "../../io/genericwriter.h"
#include "../../io/inifile.h"
#include "../../plugins/storage/smb/smbclient.h"
#include "../../plugins/storage/smb/smbfile.h"
#include "groupscriptcontaineritem.h"
#include "scriptitem.h"
#include "scriptitemcontainer.h"
#include "scriptmodelbuilder.h"
#include <QDebug>
#include <QFile>
namespace scripts_plugin
{
ScriptsModelIo::ScriptsModelIo() {}
void ScriptsModelIo::loadPolicies(std::string *path,
ScriptsModel *userScripts,
ScriptsModel *userPowerScripts,
ScriptsModel *machineScripts,
ScriptsModel *machinePowerScripts)
{
auto machinePathScripts = *path + "Machine/scripts.ini";
auto machinePathPowerScripts = *path + "Machine/psscripts.ini";
auto userPathScripts = *path + "User/scripts.ini";
auto userPathPowerScripts = *path + "User/psscripts.ini";
loadIniFile(machinePathScripts, machineScripts);
loadIniFile(machinePathPowerScripts, machinePowerScripts);
loadIniFile(userPathScripts, userScripts);
loadIniFile(userPathPowerScripts, userPowerScripts);
}
void ScriptsModelIo::savePolicies(std::string *path,
ScriptsModel *userScripts,
ScriptsModel *userPowerScripts,
ScriptsModel *machineScripts,
ScriptsModel *machinePowerScripts)
{
auto machinePathScripts = *path + "Machine/scripts.ini";
auto machinePathPowerScripts = *path + "Machine/psscripts.ini";
auto userPathScripts = *path + "User/scripts.ini";
auto userPathPowerScripts = *path + "User/psscripts.ini";
saveIniFile(machinePathScripts, machineScripts);
saveIniFile(machinePathPowerScripts, machinePowerScripts);
saveIniFile(userPathScripts, userScripts);
saveIniFile(userPathPowerScripts, userPowerScripts);
}
void ScriptsModelIo::loadIniFile(std::string &path, ScriptsModel *model)
{
QString filePath = QString::fromStdString(path);
auto stringValues = std::make_unique<std::string>();
try
{
if (filePath.startsWith("smb://"))
{
gpui::smb::SmbFile smbLocationItemFile(filePath);
smbLocationItemFile.open(QFile::ReadOnly);
stringValues->resize(smbLocationItemFile.size(), 0);
smbLocationItemFile.read(&stringValues->at(0), smbLocationItemFile.size());
smbLocationItemFile.close();
}
else
{
QFile registryFile(filePath);
registryFile.open(QFile::ReadOnly);
stringValues->resize(registryFile.size(), 0);
registryFile.read(&stringValues->at(0), registryFile.size());
registryFile.close();
}
auto iss = std::make_unique<std::istringstream>(*stringValues);
std::string pluginName("ini");
auto reader = std::make_unique<io::GenericReader>();
auto iniFile = reader->load<io::IniFile, io::PolicyFileFormat<io::IniFile>>(*iss,
pluginName);
if (!iniFile)
{
qWarning() << "Unable to load registry file contents.";
return;
}
ScriptModelBuilder builder;
builder.iniToModel(model, iniFile.get(), path);
}
catch (std::exception &e)
{
qWarning() << "Warning: Unable to read file: " << path.c_str()
<< " description: " << e.what();
}
}
void ScriptsModelIo::saveIniFile(std::string &path, ScriptsModel *model)
{
QString filePath = QString::fromStdString(path);
auto writer = std::make_unique<io::GenericWriter>();
ScriptModelBuilder builder;
auto iniFile = builder.modelToIni(model);
try
{
if (filePath.startsWith("smb://"))
{
std::stringstream fileContent;
writer->save<io::IniFile, io::PolicyFileFormat<io::IniFile>>(fileContent,
"ini",
iniFile.get());
gpui::smb::SmbFile smbLocationItemFile(filePath);
smbLocationItemFile.open(QFile::ReadWrite);
smbLocationItemFile.write(fileContent.str().c_str(), fileContent.str().size());
smbLocationItemFile.close();
}
else
{
writer.get()->save<io::IniFile, io::PolicyFileFormat<io::IniFile>>(path, iniFile.get());
}
}
catch (std::exception &e)
{
qWarning() << "Warning: Unable to write file: " << filePath.toStdString().c_str()
<< " description: " << e.what();
}
}
} // namespace scripts_plugin

View File

@ -0,0 +1,33 @@
#ifndef SCRIPTSMODELIO_H
#define SCRIPTSMODELIO_H
#include <scriptsmodel.h>
#include <string>
namespace scripts_plugin
{
class ScriptsModelIo
{
public:
ScriptsModelIo();
void loadPolicies(std::string *path,
ScriptsModel *userScripts,
ScriptsModel *userPowerScripts,
ScriptsModel *machineScripts,
ScriptsModel *machinePowerScripts);
void savePolicies(std::string *path,
ScriptsModel *userScripts,
ScriptsModel *userPowerScripts,
ScriptsModel *machineScripts,
ScriptsModel *machinePowerScripts);
private:
void loadIniFile(std::string &path, ScriptsModel *model);
void saveIniFile(std::string &path, ScriptsModel *model);
};
} // namespace scripts_plugin
#endif // SCRIPTSMODELIO_H

View File

@ -0,0 +1,41 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "../../core/plugin.h"
#include "scriptssnapin.h"
#include "../../core/isnapin.h"
namespace scripts_plugin
{
class ScriptsPlugin : public gpui::Plugin
{
public:
ScriptsPlugin()
: Plugin("ScriptsSnapIn")
{
GPUI_REGISTER_PLUGIN_CLASS(typeid(::gpui::ISnapIn).name(), ScriptsSnapIn);
}
};
} // namespace scripts_plugin
GPUI_EXPORT_PLUGIN(preferences, ::scripts_plugin::ScriptsPlugin)

View File

@ -0,0 +1,78 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptspowershellwidget.h"
#include "ui_scriptspowershellwidget.h"
#include <mvvm/factories/viewmodelfactory.h>
#include <QDebug>
namespace scripts_plugin
{
ScriptsPowerShellWidget::ScriptsPowerShellWidget(QWidget *parent)
: QWidget(parent)
, BaseScriptTabWidget(parent)
, ui(new Ui::ScriptsPowerShellWidget())
{
ui->setupUi(this);
}
ScriptsPowerShellWidget::~ScriptsPowerShellWidget()
{
delete ui;
}
void ScriptsPowerShellWidget::setItem(ScriptItemContainer *item, bool isStartUpFlag)
{
BaseScriptTabWidget::setItem(ui, item, isStartUpFlag);
}
void ScriptsPowerShellWidget::on_upPushButton_clicked()
{
BaseScriptTabWidget::onUpClicked();
}
void ScriptsPowerShellWidget::on_downPushButton_clicked()
{
BaseScriptTabWidget::onDownClicked();
}
void ScriptsPowerShellWidget::on_addPushButton_clicked()
{
BaseScriptTabWidget::onAddClicked(false);
}
void ScriptsPowerShellWidget::on_editPushButton_clicked()
{
BaseScriptTabWidget::onEditClicked();
}
void ScriptsPowerShellWidget::on_removePushButton_clicked()
{
BaseScriptTabWidget::onDeleteClicked();
}
void ScriptsPowerShellWidget::on_showPushButton_clicked()
{
BaseScriptTabWidget::onBrowseClicked();
}
} // namespace scripts_plugin

View File

@ -0,0 +1,73 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef MVVM_FOLDERS_SCRIPTS_POWER_SHELL_WIDGET_H
#define MVVM_FOLDERS_SCRIPTS_POWER_SHELL_WIDGET_H
#include "basescripttabwidget.h"
#include <mvvm/viewmodel/viewmodeldelegate.h>
QT_BEGIN_NAMESPACE
namespace Ui
{
class ScriptsPowerShellWidget;
}
QT_END_NAMESPACE
namespace scripts_plugin
{
class GroupScriptContainerItem;
class ScriptsPowerShellWidget : public QWidget, public BaseScriptTabWidget
{
public:
Q_OBJECT
public:
explicit ScriptsPowerShellWidget(QWidget *parent = nullptr);
~ScriptsPowerShellWidget();
void setItem(ScriptItemContainer *item, bool isStartUpFlag);
private slots:
void on_upPushButton_clicked();
void on_downPushButton_clicked();
void on_addPushButton_clicked();
void on_editPushButton_clicked();
void on_removePushButton_clicked();
void on_showPushButton_clicked();
private:
ScriptsPowerShellWidget(const ScriptsPowerShellWidget &) = delete; // copy ctor
ScriptsPowerShellWidget(ScriptsPowerShellWidget &&) = delete; // move ctor
ScriptsPowerShellWidget &operator=(const ScriptsPowerShellWidget &) = delete; // copy assignment
ScriptsPowerShellWidget &operator=(ScriptsPowerShellWidget &&) = delete; // move assignment
private:
Ui::ScriptsPowerShellWidget *ui;
};
} // namespace scripts_plugin
#endif //MVVM_FOLDERS_SCRIPTS_POWER_SHELL_WIDGET_H

View File

@ -0,0 +1,199 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScriptsPowerShellWidget</class>
<widget class="QWidget" name="ScriptsPowerShellWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>389</width>
<height>487</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="11" column="0">
<widget class="QComboBox" name="runComboBox">
<item>
<property name="text">
<string>Not configured</string>
</property>
</item>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="addPushButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="Line" name="line_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QPushButton" name="editPushButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QPushButton" name="removePushButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="10" column="0" colspan="2">
<widget class="QLabel" name="runLabel">
<property name="text">
<string>For this GPO, run scripts in the following order:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="buddy">
<cstring>runComboBox</cstring>
</property>
</widget>
</item>
<item row="15" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>104</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="upPushButton">
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
<item row="13" column="0" colspan="2">
<widget class="QLabel" name="requireLabel">
<property name="text">
<string>Powershell scrips require at least Windows 7 or Windows Server 2008 R2</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="buddy">
<cstring>showPushButton</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>88</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="14" column="0">
<widget class="QPushButton" name="showPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show files</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="logonLabel">
<property name="text">
<string>Windows PowerShell Logon Scripts for Default Domain Policy</string>
</property>
<property name="buddy">
<cstring>treeView</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="downPushButton">
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>88</width>
<height>24</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" rowspan="7">
<widget class="QTreeView" name="treeView"/>
</item>
</layout>
</widget>
<tabstops>
<tabstop>treeView</tabstop>
<tabstop>upPushButton</tabstop>
<tabstop>downPushButton</tabstop>
<tabstop>addPushButton</tabstop>
<tabstop>editPushButton</tabstop>
<tabstop>removePushButton</tabstop>
<tabstop>runComboBox</tabstop>
<tabstop>showPushButton</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,161 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptssnapin.h"
#include "../../io/genericreader.h"
#include "../../io/inifile.h"
#include "../../plugins/storage/smb/smbfile.h"
#include "gui/mainwindow.h"
#include "scriptmodelbuilder.h"
#include "scriptsmodel.h"
#include "scriptsmodelio.h"
#include "scriptstreemodel.h"
#include "scriptstreeproxymodel.h"
#include <mvvm/viewmodel/defaultviewmodel.h>
#include <mvvm/viewmodel/propertytableviewmodel.h>
#include <mvvm/viewmodel/topitemsviewmodel.h>
#include <../../io/genericwriter.h>
#include <mvvm/factories/viewmodelfactory.h>
#include <mvvm/model/sessionmodel.h>
#include <QDebug>
#include <QFile>
namespace scripts_plugin
{
ScriptsSnapIn::ScriptsSnapIn()
: AbstractSnapIn("ISnapIn",
"ScriptsSnapin",
"SnapIn for Scripts management",
{1, 0, 0},
"GPL-2.0",
"Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru")
, d(new ScriptsSnapInPrivate(this))
{
}
ScriptsSnapIn::~ScriptsSnapIn()
{
delete d;
}
void ScriptsSnapIn::onInitialize(QMainWindow *mainWindow)
{
auto mWindow = dynamic_cast<gpui::MainWindow *>(mainWindow);
d->proxyViewModel->setSourceModel(d->viewModel.get());
d->proxyViewModel->setSnapIn(this);
setRootNode(d->proxyViewModel.get());
if (mainWindow)
{}
}
void ScriptsSnapIn::onShutdown() {}
void ScriptsSnapIn::onDataLoad(const std::string &policyPath, const std::string &locale)
{
d->localeName = locale;
if (policyPath.empty())
{
qWarning() << "Warning: Unable to load ini file. Path is empty! ";
return;
}
d->policyPath = std::make_unique<std::string>(policyPath);
d->modelIo.get()->loadPolicies(d->policyPath.get(),
d->userScriptsModel.get(),
d->userPowerScriptsModel.get(),
d->machineScriptsModel.get(),
d->machinePowerScriptsModel.get());
}
void ScriptsSnapIn::onDataSave()
{
d->modelIo.get()->savePolicies(d->policyPath.get(),
d->userScriptsModel.get(),
d->userPowerScriptsModel.get(),
d->machineScriptsModel.get(),
d->machinePowerScriptsModel.get());
}
void ScriptsSnapIn::onRetranslateUI(const std::string &locale)
{
qWarning() << "onRetranslateUI runs";
for (const auto &translator : d->translators)
{
QCoreApplication::removeTranslator(translator.get());
}
d->translators.clear();
QString language = QString::fromStdString(locale).split("-")[0];
qWarning() << "Language: " << language;
QDirIterator it(":/", QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
while (it.hasNext())
{
qWarning() << "Resource name: " << it.fileName();
if (!it.fileInfo().isFile())
{
it.hasNext();
}
if (it.fileName().endsWith(language + ".qm"))
{
std::unique_ptr<QTranslator> qtTranslator = std::make_unique<QTranslator>();
bool loadResult = qtTranslator->load(it.fileName(), ":/");
if (loadResult)
{
qWarning() << "Tr: " << it.fileName();
QCoreApplication::installTranslator(qtTranslator.get());
d->translators.push_back(std::move(qtTranslator));
}
}
it.next();
}
d->treeModel = std::make_unique<ScriptsTreeModel>();
d->viewModel = ModelView::Factory::CreateTopItemsViewModel(d->treeModel.get());
d->proxyViewModel = std::make_unique<ScriptsTreeProxyModel>();
d->proxyViewModel->setSourceModel(d->viewModel.get());
setRootNode(d->proxyViewModel.get());
d->proxyViewModel->setSnapIn(this);
d->retranslateModels(d->userScriptsModel);
d->retranslateModels(d->userPowerScriptsModel);
d->retranslateModels(d->machineScriptsModel);
d->retranslateModels(d->machinePowerScriptsModel);
}
} // namespace scripts_plugin

View File

@ -0,0 +1,63 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef SCRIPTSSNAPIN_H
#define SCRIPTSSNAPIN_H
#include "../../core/abstractsnapin.h"
#include "../../core/core.h"
#include "../../../src/core/common.h"
#include "scriptssnapinprivate.h"
namespace scripts_plugin
{
class ScriptsSnapInPrivate;
class GPUI_SYMBOL_EXPORT ScriptsSnapIn : public gpui::AbstractSnapIn
{
public:
ScriptsSnapIn();
virtual ~ScriptsSnapIn();
virtual void onInitialize(QMainWindow *mainWindow) override;
void onShutdown() override;
virtual void onDataLoad(const std::string &policyPath, const std::string &locale) override;
public slots:
virtual void onDataSave() override;
virtual void onRetranslateUI(const std::string &locale) override;
public:
ScriptsSnapInPrivate *d;
private:
ScriptsSnapIn(const ScriptsSnapIn &) = delete; // copy ctor
ScriptsSnapIn(ScriptsSnapIn &&) = delete; // move ctor
ScriptsSnapIn &operator=(const ScriptsSnapIn &) = delete; // copy assignment
ScriptsSnapIn &operator=(ScriptsSnapIn &&) = delete; // move assignment
};
} // namespace scripts_plugin
#endif // SCRIPTSSNAPIN_H

View File

@ -0,0 +1,69 @@
#include "scriptssnapinprivate.h"
#include "scriptitemcontainer.h"
#include <QDebug>
namespace scripts_plugin
{
ScriptsSnapInPrivate::ScriptsSnapInPrivate(ScriptsSnapIn *scriptsSnapIn)
: snapIn(scriptsSnapIn)
{
//----user scripts model
auto userLogonItemContainer = userScriptsModel.get()->insertItem<ScriptItemContainer>();
userLogonItemContainer->setProperty(ScriptItemContainer::SECTION_NAME, "Logon");
auto userLogoffItemContainer = userScriptsModel.get()->insertItem<ScriptItemContainer>();
userLogoffItemContainer->setProperty(ScriptItemContainer::SECTION_NAME, "Logoff");
auto userStartUpItemContainer = userPowerScriptsModel.get()->insertItem<ScriptItemContainer>();
userStartUpItemContainer->setProperty(ScriptItemContainer::SECTION_NAME, "Startup");
auto userShutdownItemContainer = userPowerScriptsModel.get()->insertItem<ScriptItemContainer>();
userShutdownItemContainer->setProperty(ScriptItemContainer::SECTION_NAME, "Shutdown");
//--------------------------------------------------------------------------------------
//----machine scripts models
auto machineLogonItemContainer = machineScriptsModel.get()->insertItem<ScriptItemContainer>();
machineLogonItemContainer->setProperty(ScriptItemContainer::SECTION_NAME, "Logon");
auto machineLogoffItemContainer = machineScriptsModel.get()->insertItem<ScriptItemContainer>();
machineLogoffItemContainer->setProperty(ScriptItemContainer::SECTION_NAME, "Logoff");
auto machineStartUpItemContainer = machinePowerScriptsModel.get()
->insertItem<ScriptItemContainer>();
machineStartUpItemContainer->setProperty(ScriptItemContainer::SECTION_NAME, "Startup");
auto machineShutdownItemContainer = machinePowerScriptsModel.get()
->insertItem<ScriptItemContainer>();
machineShutdownItemContainer->setProperty(ScriptItemContainer::SECTION_NAME, "Shutdown");
}
void ScriptsSnapInPrivate::saveData()
{
snapIn->onDataSave();
}
void ScriptsSnapInPrivate::reloadData()
{
auto path = policyPath.get();
snapIn->onDataLoad(*path, localeName);
}
void ScriptsSnapInPrivate::retranslateModels(std::unique_ptr<ScriptsModel> &models)
{
if (models)
{
for (auto container : models.get()->topItems())
{
auto containerItem = dynamic_cast<ScriptItemContainer *>(container);
if (containerItem)
{
containerItem->retranslateStrings();
}
}
}
}
} // namespace scripts_plugin

View File

@ -0,0 +1,63 @@
#ifndef SCRIPTSSNAPINPRIVATE_H
#define SCRIPTSSNAPINPRIVATE_H
#include "scriptsmodel.h"
#include "scriptsmodelio.h"
#include "scriptssnapin.h"
#include "scriptstreemodel.h"
#include "scriptstreeproxymodel.h"
#include <QObject>
#include <QTranslator>
#include <mvvm/factories/viewmodelfactory.h>
#include <mvvm/viewmodel/viewmodel.h>
namespace scripts_plugin
{
class ScriptsSnapIn;
class ScriptsTreeProxyModel;
class ScriptsSnapInPrivate : public QObject
{
public:
Q_OBJECT
public:
std::unique_ptr<std::string> policyPath = nullptr;
std::unique_ptr<ScriptsModel> userScriptsModel = std::make_unique<ScriptsModel>();
std::unique_ptr<ScriptsModel> userPowerScriptsModel = std::make_unique<ScriptsModel>();
std::unique_ptr<ScriptsModel> machineScriptsModel = std::make_unique<ScriptsModel>();
std::unique_ptr<ScriptsModel> machinePowerScriptsModel = std::make_unique<ScriptsModel>();
std::unique_ptr<ModelView::SessionModel> treeModel = std::make_unique<ScriptsTreeModel>();
std::unique_ptr<ModelView::ViewModel> viewModel = ModelView::Factory::CreateTopItemsViewModel(
treeModel.get());
std::unique_ptr<ScriptsTreeProxyModel> proxyViewModel = std::make_unique<ScriptsTreeProxyModel>();
std::unique_ptr<ScriptsModelIo> modelIo = std::make_unique<ScriptsModelIo>();
std::vector<std::unique_ptr<QTranslator>> translators{};
ScriptsSnapIn *snapIn;
std::string localeName = "en-US";
public:
void retranslateModels(std::unique_ptr<ScriptsModel> &models);
public:
ScriptsSnapInPrivate(ScriptsSnapIn *scriptsSnapIn);
public slots:
void saveData();
void reloadData();
private:
ScriptsSnapInPrivate(const ScriptsSnapInPrivate &) = delete; //copy ctor
ScriptsSnapInPrivate(ScriptsSnapInPrivate &&) = delete; //move ctor
ScriptsSnapInPrivate operator=(ScriptsSnapInPrivate &) = delete; //copy assignment
ScriptsSnapInPrivate operator=(ScriptsSnapInPrivate &&) = delete; //move assignment
};
} // namespace scripts_plugin
#endif // SCRIPTSSNAPINPRIVATE_H

View File

@ -0,0 +1,39 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptswidget.h"
#include "ui_scriptswidget.h"
namespace preferences_editor
{
ScriptsWidget::ScriptsWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::ScriptsWidget())
{
ui->setupUi(this);
}
ScriptsWidget::~ScriptsWidget()
{
delete ui;
}
}

View File

@ -0,0 +1,126 @@
#include "scriptstreemodel.h"
#include "scriptitem.h"
#include <QUuid>
#include <mvvm/model/groupitem.h>
#include <mvvm/model/propertyitem.h>
#include <mvvm/model/taginfo.h>
namespace
{
class ScriptsFolderItem : public ModelView::GroupItem
{
public:
static inline const std::string NODE_ID = "NODE_ID";
static inline const std::string PARENT_ID = "PARENT_ID";
static inline const std::string NAMESPACE = "NAMESPACE";
static inline const std::string HELP_MSG = "HELP_MSG";
static inline const std::string CATEGORY = "CATEGORY";
public:
ScriptsFolderItem()
: ModelView::GroupItem("ScriptsFolderItem")
{
addProperty(NODE_ID, QUuid::createUuid());
addProperty(PARENT_ID, QUuid::createUuid());
addProperty(NAMESPACE, "");
addProperty(HELP_MSG, "");
addProperty<bool>(CATEGORY, false);
}
template<typename T>
T *addProperty(const std::string &name)
{
registerTag(ModelView::TagInfo::propertyTag(name, T().modelType()));
auto result = insertItem<T>({name, 0});
result->setDisplayName(name);
return result;
}
inline ModelView::PropertyItem *addProperty(const std::string &name, const char *value)
{
return addProperty(name, std::string(value));
}
template<typename V>
ModelView::PropertyItem *addProperty(const std::string &name, const V &value)
{
auto property = addProperty<ModelView::PropertyItem>(name);
property->setData(value);
if constexpr (std::is_floating_point_v<V>)
property->setData(ModelView::RealLimits::limitless(), ModelView::ItemDataRole::LIMITS);
return property;
}
};
} // namespace
namespace scripts_plugin
{
ScriptsTreeModel::ScriptsTreeModel()
: ModelView::SessionModel("ScriptsTreeModel")
{
registerItem<ScriptsFolderItem>();
populateModel();
}
void ScriptsTreeModel::populateModel()
{
auto topItem = insertItem<ScriptsFolderItem>(this->rootItem());
topItem->setDisplayName(QObject::tr("[Local Group Policy]").toStdString());
topItem->setProperty(ScriptsFolderItem::HELP_MSG, "");
auto topUuid = QUuid("{123e4567-e89b-12d3-a456-426652340003}");
topItem->setProperty(ScriptsFolderItem::NODE_ID, topUuid);
topItem->setProperty(ScriptsFolderItem::HELP_MSG, QObject::tr("Group policy").toStdString());
topItem->setProperty(ScriptsFolderItem::CATEGORY, true);
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
auto machineNamespace = insertItem<ScriptsFolderItem>(topItem);
machineNamespace->setDisplayName(QObject::tr("Machine").toStdString());
auto machineUuid = QUuid("{123e4567-e89b-12d3-a456-426652340000}");
machineNamespace->setProperty(ScriptsFolderItem::NODE_ID, machineUuid);
machineNamespace->setProperty(ScriptsFolderItem::PARENT_ID, topUuid);
machineNamespace->setProperty(ScriptsFolderItem::HELP_MSG,
QObject::tr("Machine level policies").toStdString());
machineNamespace->setProperty(ScriptsFolderItem::CATEGORY, true);
auto machineSystemSettings = insertItem<ScriptsFolderItem>(machineNamespace);
machineSystemSettings->setDisplayName(QObject::tr("System settings").toStdString());
machineSystemSettings->setProperty(ScriptsFolderItem::PARENT_ID, machineUuid);
machineSystemSettings->setProperty(ScriptsFolderItem::HELP_MSG,
QObject::tr("System settings for computer").toStdString());
machineSystemSettings->setProperty(ScriptsFolderItem::CATEGORY, true);
auto machineScripts = insertItem<ScriptsFolderItem>(machineSystemSettings);
machineScripts->setDisplayName(QObject::tr("Scripts").toStdString());
machineScripts->setProperty(ScriptsFolderItem::NAMESPACE, "Machine");
machineScripts->setProperty(ScriptsFolderItem::HELP_MSG,
QObject::tr("Scripts for computer").toStdString());
machineScripts->setProperty(ScriptsFolderItem::CATEGORY, false);
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
auto userNamespace = insertItem<ScriptsFolderItem>(topItem);
userNamespace->setDisplayName(QObject::tr("User").toStdString());
auto userUuid = QUuid("{123e4567-e89b-12d3-a456-426652340001}");
userNamespace->setProperty(ScriptsFolderItem::NODE_ID, userUuid);
userNamespace->setProperty(ScriptsFolderItem::PARENT_ID, topUuid);
userNamespace->setProperty(ScriptsFolderItem::HELP_MSG,
QObject::tr("User level policies.").toStdString());
userNamespace->setProperty(ScriptsFolderItem::CATEGORY, true);
auto userSystemSetting = insertItem<ScriptsFolderItem>(userNamespace);
userSystemSetting->setDisplayName(QObject::tr("System settings").toStdString());
userSystemSetting->setProperty(ScriptsFolderItem::PARENT_ID, userUuid);
userSystemSetting->setProperty(ScriptsFolderItem::HELP_MSG,
QObject::tr("System settings for user").toStdString());
userSystemSetting->setProperty(ScriptsFolderItem::CATEGORY, true);
auto userScripts = insertItem<ScriptsFolderItem>(userSystemSetting);
userScripts->setDisplayName(QObject::tr("Scripts").toStdString());
userScripts->setProperty(ScriptsFolderItem::NAMESPACE, "User");
userScripts->setProperty(ScriptsFolderItem::HELP_MSG,
QObject::tr("Scripts for user").toStdString());
userScripts->setProperty(ScriptsFolderItem::CATEGORY, false);
}
} // namespace scripts_plugin

View File

@ -0,0 +1,19 @@
#ifndef SCRIPTSTREEMODEL_H
#define SCRIPTSTREEMODEL_H
#include <mvvm/model/sessionmodel.h>
#include "../../../src/core/common.h"
namespace scripts_plugin
{
class GPUI_SYMBOL_EXPORT ScriptsTreeModel : public ModelView::SessionModel
{
public:
explicit ScriptsTreeModel();
private:
void populateModel();
};
} // namespace scripts_plugin
#endif // SCRIPTSTREEMODEL_H

View File

@ -0,0 +1,134 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptstreeproxymodel.h"
#include "scriptscontentwidget.h"
#include "scriptsdialog.h"
#include "scriptssnapin.h"
#include "../../plugins/administrative_templates/bundle/itemtype.h"
#include "../../plugins/administrative_templates/bundle/policyroles.h"
#include <mvvm/model/sessionitem.h>
#include <mvvm/model/sessionmodel.h>
#include <mvvm/viewmodel/viewmodel.h>
#include <memory>
#include <QIcon>
#include <QUuid>
#include <QDebug>
namespace scripts_plugin
{
ScriptsTreeProxyModel::ScriptsTreeProxyModel()
: d(std::make_unique<ScriptsTreeProxyModelPrivate>())
{}
QVariant ScriptsTreeProxyModel::data(const QModelIndex &proxyIndex, int role) const
{
static QVariant folder = QVariant(QIcon::fromTheme("folder"));
static QVariant computer = QVariant(QIcon::fromTheme("computer"));
static QVariant user = QVariant(QIcon::fromTheme("user-home"));
if (role == Qt::DecorationRole)
{
if (proxyIndex.data(Qt::DisplayRole).toString().compare("Machine", Qt::CaseInsensitive) == 0)
{
return computer;
}
if (proxyIndex.data(Qt::DisplayRole).toString().compare("User", Qt::CaseInsensitive) == 0)
{
return user;
}
return folder;
}
if (role == Qt::UserRole + 12)
{
auto viewModelProxy = static_cast<const ModelView::ViewModel *>(proxyIndex.model());
auto item = viewModelProxy->sessionItemFromIndex(proxyIndex);
return QVariant::fromValue(item->property<QUuid>("NODE_ID"));
}
if (role == Qt::UserRole + 13)
{
auto viewModelProxy = static_cast<const ModelView::ViewModel *>(proxyIndex.model());
return QVariant::fromValue(
viewModelProxy->sessionItemFromIndex(proxyIndex)->property<QUuid>("PARENT_ID"));
}
if (role == model::bundle::PolicyRoles::POLICY_WIDGET)
{
std::function<QWidget *()> widgetCreator = [=]() {
auto widget = new ScriptsContentWidget(d->snapIn);
auto sessionItem = this->viewModel->sessionItemFromIndex(proxyIndex);
auto name = sessionItem->displayName();
auto nameSpace = sessionItem->property<std::string>("NAMESPACE");
if (nameSpace.compare("Machine") == 0)
{
widget->setNamespace(true);
}
else
{
widget->setNamespace(false);
}
return widget;
};
return QVariant::fromValue(widgetCreator);
}
if (role == model::bundle::PolicyRoles::ITEM_TYPE)
{
auto sessionItem = this->viewModel->sessionItemFromIndex(proxyIndex);
if (sessionItem->property<bool>("CATEGORY"))
{
return QVariant(static_cast<uint>(model::bundle::ItemType::ITEM_TYPE_CATEGORY));
}
return QVariant(static_cast<uint>(model::bundle::ItemType::ITEM_TYPE_POLICY));
}
return QIdentityProxyModel::data(proxyIndex, role);
}
void ScriptsTreeProxyModel::setSnapIn(ScriptsSnapIn *scriptsSnapIn)
{
if (scriptsSnapIn != nullptr)
{
d->snapIn = scriptsSnapIn;
}
}
} // namespace scripts_plugin
Q_DECLARE_METATYPE(std::shared_ptr<void(QWidget *, QItemSelectionModel *, const QModelIndex &)>)
Q_DECLARE_METATYPE(std::function<QWidget *()>)

View File

@ -0,0 +1,82 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef SCRIPTS_TREE_PROXY_MODEL_H
#define SCRIPTS_TREE_PROXY_MODEL_H
#include <QIdentityProxyModel>
#include "../../../src/core/common.h"
#include "scriptsmodel.h"
#include "scriptssnapin.h"
namespace ModelView
{
class SessionModel;
class ViewModel;
} // namespace ModelView
class QItemSelectionModel;
namespace scripts_plugin
{
class ScriptsSnapIn;
}
namespace scripts_plugin
{
class ScriptsTreeProxyModelPrivate
{
public:
ScriptsModel *userScriptsModel = nullptr;
ScriptsModel *userPowerScriptsModel = nullptr;
ScriptsModel *machineScriptsModel = nullptr;
ScriptsModel *machinePowerScriptsModel = nullptr;
ScriptsSnapIn *snapIn = nullptr;
};
class GPUI_SYMBOL_EXPORT ScriptsTreeProxyModel : public QIdentityProxyModel
{
Q_OBJECT
public:
ScriptsTreeProxyModel();
QVariant data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const override;
void setSnapIn(ScriptsSnapIn *scriptsSnapIn);
private:
ModelView::SessionModel *sessionModel = nullptr;
ModelView::ViewModel *viewModel = nullptr;
std::unique_ptr<ScriptsTreeProxyModelPrivate> d;
private:
ScriptsTreeProxyModel(const ScriptsTreeProxyModel &) = delete;
ScriptsTreeProxyModel(ScriptsTreeProxyModel &&) = delete;
ScriptsTreeProxyModel &operator=(const ScriptsTreeProxyModel &) = delete;
ScriptsTreeProxyModel &operator=(const ScriptsTreeProxyModel &&) = delete;
};
} // namespace scripts_plugin
#endif //SCRIPTS_TREE_PROXY_MODEL_H

View File

@ -0,0 +1,78 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#include "scriptswidget.h"
#include "ui_scriptswidget.h"
#include <mvvm/factories/viewmodelfactory.h>
#include <QDebug>
namespace scripts_plugin
{
ScriptsWidget::ScriptsWidget(QWidget *parent)
: QWidget(parent)
, BaseScriptTabWidget(parent)
, ui(new Ui::ScriptsWidget())
{
ui->setupUi(this);
}
ScriptsWidget::~ScriptsWidget()
{
delete ui;
}
void ScriptsWidget::setItem(ScriptItemContainer *item, bool isStartUpFlag)
{
BaseScriptTabWidget::setItem(ui, item, isStartUpFlag);
}
void ScriptsWidget::on_upPushButton_clicked()
{
BaseScriptTabWidget::onUpClicked();
}
void ScriptsWidget::on_downPushButton_clicked()
{
BaseScriptTabWidget::onDownClicked();
}
void ScriptsWidget::on_addPushButton_clicked()
{
BaseScriptTabWidget::onAddClicked(true);
}
void ScriptsWidget::on_editPushButton_clicked()
{
BaseScriptTabWidget::onEditClicked();
}
void ScriptsWidget::on_removePushButton_clicked()
{
BaseScriptTabWidget::onDeleteClicked();
}
void ScriptsWidget::on_showPushButton_clicked()
{
BaseScriptTabWidget::onBrowseClicked();
}
} // namespace scripts_plugin

View File

@ -0,0 +1,74 @@
/***********************************************************************************************************************
**
** Copyright (C) 2022 BaseALT Ltd. <org@basealt.ru>
**
** 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 2
** 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, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
***********************************************************************************************************************/
#ifndef MVVM_FOLDERS_SCRIPTS_WIDGET_H
#define MVVM_FOLDERS_SCRIPTS_WIDGET_H
#include "basescripttabwidget.h"
#include <mvvm/viewmodel/viewmodeldelegate.h>
QT_BEGIN_NAMESPACE
namespace Ui
{
class ScriptsWidget;
}
QT_END_NAMESPACE
namespace scripts_plugin
{
class GroupScriptContainerItem;
class ScriptsWidget : public QWidget, public BaseScriptTabWidget
{
public:
Q_OBJECT
public:
explicit ScriptsWidget(QWidget *parent = nullptr);
~ScriptsWidget();
void setItem(ScriptItemContainer *item, bool isStartUpFlag);
private slots:
void on_upPushButton_clicked();
void on_downPushButton_clicked();
void on_addPushButton_clicked();
void on_editPushButton_clicked();
void on_removePushButton_clicked();
void on_showPushButton_clicked();
private:
ScriptsWidget(const ScriptsWidget &) = delete; // copy ctor
ScriptsWidget(ScriptsWidget &&) = delete; // move ctor
ScriptsWidget &operator=(const ScriptsWidget &) = delete; // copy assignment
ScriptsWidget &operator=(ScriptsWidget &&) = delete; // move assignment
private:
Ui::ScriptsWidget *ui = nullptr;
};
} // namespace scripts_plugin
#endif //MVVM_FOLDERS_SCRIPTS_WIDGET_H

View File

@ -0,0 +1,145 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScriptsWidget</class>
<widget class="QWidget" name="ScriptsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>389</width>
<height>440</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="logonLabel">
<property name="text">
<string>Logon scripts for Default Domain Policy</string>
</property>
<property name="buddy">
<cstring>treeView</cstring>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="upPushButton">
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="downPushButton">
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>88</width>
<height>8</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="1">
<widget class="QPushButton" name="addPushButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="editPushButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QPushButton" name="removePushButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<widget class="QLabel" name="viewLabel">
<property name="text">
<string>To view the script files stored in this Group Policy Object, press the button below</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="buddy">
<cstring>showPushButton</cstring>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QPushButton" name="showPushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Show files</string>
</property>
</widget>
</item>
<item row="11" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>104</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" rowspan="6">
<widget class="QTreeView" name="treeView">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/">
<file>scripts_en.qm</file>
<file>scripts_ru.qm</file>
</qresource>
</RCC>