1 /*
2     This file is part of the Kasten Framework, made within the KDE community.
3 
4     SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8 
9 #include "bytearrayrandomdatageneratorconfigeditor.hpp"
10 
11 // KF
12 #include <KLocalizedString>
13 // Qt
14 #include <QSpinBox>
15 #include <QFormLayout>
16 
17 namespace Kasten {
18 
ByteArrayRandomDataGeneratorConfigEditor(ByteArrayRandomDataGenerator * generator,QWidget * parent)19 ByteArrayRandomDataGeneratorConfigEditor::ByteArrayRandomDataGeneratorConfigEditor(ByteArrayRandomDataGenerator* generator, QWidget* parent)
20     : AbstractModelDataGeneratorConfigEditor(parent)
21     , mGenerator(generator)
22 {
23     mSettings = mGenerator->settings();
24 
25     auto* pageLayout = new QFormLayout(this);
26     pageLayout->setContentsMargins(0, 0, 0, 0);
27 
28     // number
29     const QString numberInputLabel =
30         i18nc("@label:spinbox size of the bytearray to generate",
31               "&Size (bytes):");
32     mSizeInput = new QSpinBox(this);
33     mSizeInput->setRange(1, INT_MAX);
34     mSizeInput->setValue(mSettings.size);
35     connect(mSizeInput, QOverload<int>::of(&QSpinBox::valueChanged),
36             this, &ByteArrayRandomDataGeneratorConfigEditor::onSettingsChanged);
37     const QString numberWhatsThis =
38         i18nc("@info:whatsthis",
39               "Enter the size of the bytearray to generate.");
40     mSizeInput->setWhatsThis(numberWhatsThis);
41 
42     pageLayout->addRow(numberInputLabel, mSizeInput);
43 }
44 
45 ByteArrayRandomDataGeneratorConfigEditor::~ByteArrayRandomDataGeneratorConfigEditor() = default;
46 
name() const47 QString ByteArrayRandomDataGeneratorConfigEditor::name() const
48 {
49     return i18nc("@item name of the generated data", "Random Data");
50 }
51 
52 // TODO: get char codec
53 #if 0
54 void InsertRandomDataDialog::setCharCodec(const QString& codecName)
55 {
56     mRandomDataEdit->setCharCodec(codecName);
57 }
58 #endif
59 
onSettingsChanged()60 void ByteArrayRandomDataGeneratorConfigEditor::onSettingsChanged()
61 {
62     mSettings.size = mSizeInput->value();
63 
64     mGenerator->setSettings(mSettings);
65 }
66 
67 }
68