File indexing completed on 2025-01-05 05:23:46

0001 /*
0002  This file is part of the Okteta Kasten Framework, made within the KDE community.
0003 
0004  SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
0005  SPDX-FileCopyrightText: 2009, 2012 Alex Richardson <alex.richardson@gmx.de>
0006 
0007  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0008  */
0009 
0010 #include "structuresmanagerview.hpp"
0011 
0012 // controller
0013 #include "structuresselectiondialog.hpp"
0014 #include "structuresselector.hpp"
0015 #include "../structuresmanager.hpp"
0016 #include "../structurestool.hpp"
0017 #include <structureslogging.hpp>
0018 // KF
0019 #include <KConfigDialogManager>
0020 #include <KLocalizedString>
0021 #include <KNSWidgets/Button>
0022 // Qt
0023 #include <QPushButton>
0024 #include <QListWidgetItem>
0025 #include <QHBoxLayout>
0026 #include <QVBoxLayout>
0027 #include <QSizePolicy>
0028 
0029 StructuresManagerView::StructuresManagerView(Kasten::StructuresTool* tool, QWidget* parent)
0030     : QWidget(parent)
0031     , mTool(tool)
0032 {
0033     auto* pageLayout = new QVBoxLayout();
0034     pageLayout->setContentsMargins(0, 0, 0, 0);
0035     setLayout(pageLayout);
0036 
0037     mStructuresSelector = new StructuresSelector(this);
0038     connect(mStructuresSelector, &StructuresSelector::enabledStructuresChanged,
0039             this, &StructuresManagerView::changed);
0040 
0041     pageLayout->addWidget(mStructuresSelector);
0042 
0043     // buttons
0044     auto* buttonsLayout = new QHBoxLayout();
0045 
0046     mGetNewStructuresButton = new KNSWidgets::Button(i18n("Get New Structures..."),
0047                                                      QStringLiteral("okteta-structures.knsrc"), this);
0048     connect(mGetNewStructuresButton, &KNSWidgets::Button::dialogFinished,
0049             this, &StructuresManagerView::onGetNewStructuresClicked);
0050     buttonsLayout->addWidget(mGetNewStructuresButton);
0051 
0052     mAdvancedSelectionButton = new QPushButton(QIcon::fromTheme(QStringLiteral("configure")), i18n("Advanced Selection..."), this);
0053     connect(mAdvancedSelectionButton, &QPushButton::clicked, this, &StructuresManagerView::advancedSelection);
0054     buttonsLayout->addWidget(mAdvancedSelectionButton);
0055 
0056     pageLayout->addLayout(buttonsLayout);
0057 
0058     mStructuresSelector->setStructures(mTool->manager()->structureDefs());
0059 }
0060 
0061 StructuresManagerView::~StructuresManagerView() = default;
0062 
0063 void StructuresManagerView::onGetNewStructuresClicked(const QList<KNSCore::EntryInternal>& changedEntries)
0064 {
0065     for (const KNSCore::EntryInternal& e : changedEntries) {
0066         qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "Changed Entry: " << e.name();
0067         if (e.status() == KNS3::Entry::Installed) {
0068             // new element installed
0069             qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "installed files:" << e.installedFiles();
0070         }
0071         if (e.status() == KNS3::Entry::Deleted) {
0072             // element uninstalled
0073             qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "deleted files:" << e.uninstalledFiles();
0074         }
0075     }
0076 
0077     if (!changedEntries.isEmpty()) {
0078         qCDebug(LOG_KASTEN_OKTETA_CONTROLLERS_STRUCTURES) << "installed structures changed ->  rebuilding list of installed structures";
0079         mTool->manager()->reloadPaths();
0080         mStructuresSelector->setStructures(mTool->manager()->structureDefs());
0081     }
0082 }
0083 
0084 QStringList StructuresManagerView::values() const
0085 {
0086     return mStructuresSelector->enabledStructures();;
0087 }
0088 
0089 void StructuresManagerView::setValues(const QStringList& values)
0090 {
0091     mStructuresSelector->setEnabledStructures(values);
0092 }
0093 
0094 void StructuresManagerView::advancedSelection()
0095 {
0096     auto* dialog = new StructuresSelectionDialog(mTool->manager()->structureDefs(),
0097                                                  mStructuresSelector->enabledList(),
0098                                                  this);
0099     connect(dialog, &StructuresSelectionDialog::structuresAccepted,
0100             this, &StructuresManagerView::setEnabledStructures);
0101     dialog->open();
0102 }
0103 
0104 void StructuresManagerView::setEnabledStructures(const QStringList& enabledStructures)
0105 {
0106     mStructuresSelector->setEnabledStructures(enabledStructures);;
0107 }
0108 
0109 #include "moc_structuresmanagerview.cpp"