Commit 77679d8f authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Implement save group

TODO: manage list of group
parent 1e19e83f
Pipeline #44512 passed with stage
in 9 minutes and 15 seconds
......@@ -28,6 +28,8 @@
#include "saverulesjob.h"
#include "loadtoolbutton.h"
#include "savetoolbutton.h"
#include "loadgroupmenu.h"
#include "kdebugsettings_debug.h"
#include <KLocalizedString>
#include <KConfigGroup>
......@@ -42,7 +44,7 @@
#include <QPushButton>
#include <QDesktopServices>
#include <QUrl>
#include "kdebugsettings_debug.h"
#include <QInputDialog>
namespace {
constexpr char KDebugSettingsDialogGroupName[] = "KDebugSettingsDialog";
}
......@@ -85,6 +87,7 @@ KDebugSettingsDialog::KDebugSettingsDialog(QWidget *parent)
buttonBox->addButton(load, QDialogButtonBox::ActionRole);
connect(load, &LoadToolButton::loadFromFile, this, &KDebugSettingsDialog::slotLoad);
connect(load, &LoadToolButton::loadGroupRequested, this, &KDebugSettingsDialog::slotLoadGroup);
connect(this, &KDebugSettingsDialog::updateLoadGroupMenu, load, &LoadToolButton::updateLoadGroupMenu);
QPushButton *insertCategories = new QPushButton(i18n("Insert..."), this);
insertCategories->setObjectName(QStringLiteral("insert_button"));
......@@ -210,7 +213,12 @@ void KDebugSettingsDialog::slotInsertCategories()
void KDebugSettingsDialog::slotSaveAsGroup()
{
//TODO
const QString groupPath = LoadGroupMenu::defaultGroupPath();
const QString name = QInputDialog::getText(this, i18n("Group Name"), i18n("Name"));
if (!name.isEmpty()) {
saveRules(groupPath + QLatin1Char('/') + name, true);
Q_EMIT updateLoadGroupMenu();
}
}
void KDebugSettingsDialog::slotSaveAs()
......
......@@ -39,6 +39,9 @@ public:
explicit KDebugSettingsDialog(QWidget *parent = nullptr);
~KDebugSettingsDialog() override;
Q_SIGNALS:
void updateLoadGroupMenu();
private:
void slotAccepted();
void slotHelpRequested();
......
......@@ -42,9 +42,14 @@ void LoadGroupMenu::refreshMenu()
init();
}
QString LoadGroupMenu::defaultGroupPath()
{
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QLatin1String("/groups");
}
void LoadGroupMenu::init()
{
const QString groupPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QLatin1String("/groups");
const QString groupPath = LoadGroupMenu::defaultGroupPath();
if (groupPath.isEmpty()) {
setEnabled(false);
return;
......
......@@ -32,6 +32,8 @@ public:
void refreshMenu();
static Q_REQUIRED_RESULT QString defaultGroupPath();
Q_SIGNALS:
void loadGroupRequested(const QString &filePath);
......
......@@ -24,6 +24,7 @@
LoadToolButton::LoadToolButton(QWidget *parent)
: QToolButton(parent)
, mLoadMenu(new LoadGroupMenu(this))
{
setPopupMode(QToolButton::InstantPopup);
setText(i18n("Load..."));
......@@ -33,13 +34,17 @@ LoadToolButton::LoadToolButton(QWidget *parent)
QAction *act = mainMenu->addAction(i18n("Load From File..."));
connect(act, &QAction::triggered, this, &LoadToolButton::loadFromFile);
LoadGroupMenu *loadMenu = new LoadGroupMenu(this);
loadMenu->setObjectName(QStringLiteral("loadMenu"));
connect(loadMenu, &LoadGroupMenu::loadGroupRequested, this, &LoadToolButton::loadGroupRequested);
mainMenu->addMenu(loadMenu);
mLoadMenu->setObjectName(QStringLiteral("loadMenu"));
connect(mLoadMenu, &LoadGroupMenu::loadGroupRequested, this, &LoadToolButton::loadGroupRequested);
mainMenu->addMenu(mLoadMenu);
}
LoadToolButton::~LoadToolButton()
{
}
void LoadToolButton::updateLoadGroupMenu()
{
mLoadMenu->refreshMenu();
}
......@@ -24,15 +24,20 @@
#include <QToolButton>
#include "libkdebugsettings_private_export.h"
class LoadGroupMenu;
class LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT LoadToolButton : public QToolButton
{
Q_OBJECT
public:
explicit LoadToolButton(QWidget *parent = nullptr);
~LoadToolButton() override;
void updateLoadGroupMenu();
Q_SIGNALS:
void loadGroupRequested(const QString &fullPath);
void loadFromFile();
private:
LoadGroupMenu *const mLoadMenu;
};
#endif // LOADTOOLBUTTON_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment