Changeset View
Changeset View
Standalone View
Standalone View
src/HistorySizeWidget.cpp
Show All 14 Lines | 1 | /* | |||
---|---|---|---|---|---|
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
18 | 02110-1301 USA. | 18 | 02110-1301 USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | // Own | 21 | // Own | ||
22 | #include "HistorySizeWidget.h" | 22 | #include "HistorySizeWidget.h" | ||
23 | #include "KonsoleSettings.h" | ||||
23 | 24 | | |||
24 | // Qt | 25 | // Qt | ||
25 | #include <QButtonGroup> | 26 | #include <QButtonGroup> | ||
26 | #include <QAbstractButton> | 27 | #include <QAbstractButton> | ||
27 | #include <QToolTip> | 28 | #include <QToolTip> | ||
28 | #include <QWhatsThis> | 29 | #include <QWhatsThis> | ||
29 | 30 | #include <QStandardPaths> | |||
30 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
32 | #include <KConfigDialogManager> | ||||
31 | 33 | | |||
32 | // Konsole | 34 | // Konsole | ||
33 | #include "ui_HistorySizeWidget.h" | 35 | #include "ui_HistorySizeWidget.h" | ||
34 | 36 | | |||
35 | using namespace Konsole; | 37 | using namespace Konsole; | ||
36 | 38 | | |||
37 | HistorySizeWidget::HistorySizeWidget(QWidget *parent) : | 39 | HistorySizeWidget::HistorySizeWidget(QWidget *parent) : | ||
38 | QWidget(parent), | 40 | QWidget(parent), | ||
39 | _ui(nullptr) | 41 | _ui(new Ui::HistorySizeWidget()) | ||
40 | { | 42 | { | ||
41 | _ui = new Ui::HistorySizeWidget(); | | |||
42 | _ui->setupUi(this); | 43 | _ui->setupUi(this); | ||
44 | _ui->kcfg_scrollbackUseCacheLocation->setToolTip(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); | ||||
45 | _ui->kcfg_scrollbackUseSystemLocation->setToolTip(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); | ||||
43 | 46 | | |||
44 | // focus and select the spinner automatically when appropriate | 47 | // focus and select the spinner automatically when appropriate | ||
45 | _ui->fixedSizeHistoryButton->setFocusProxy(_ui->historyLineSpinner); | 48 | _ui->fixedSizeHistoryButton->setFocusProxy(_ui->historyLineSpinner); | ||
46 | connect(_ui->fixedSizeHistoryButton, &QRadioButton::clicked, | 49 | connect(_ui->fixedSizeHistoryButton, &QRadioButton::clicked, | ||
47 | _ui->historyLineSpinner, | 50 | _ui->historyLineSpinner, &KPluralHandlingSpinBox::selectAll); | ||
48 | &KPluralHandlingSpinBox::selectAll); | | |||
49 | 51 | | |||
50 | auto modeGroup = new QButtonGroup(this); | 52 | for(auto *widget : {_ui->noHistoryButton, _ui->fixedSizeHistoryButton, _ui->unlimitedHistoryButton}) { | ||
51 | modeGroup->addButton(_ui->noHistoryButton); | 53 | connect(widget, &QRadioButton::clicked, this, [this]{ emit historyModeChanged(mode()); }); | ||
52 | modeGroup->addButton(_ui->fixedSizeHistoryButton); | 54 | } | ||
53 | modeGroup->addButton(_ui->unlimitedHistoryButton); | | |||
54 | connect(modeGroup, | | |||
55 | static_cast<void (QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked), | | |||
56 | this, &Konsole::HistorySizeWidget::buttonClicked); | | |||
57 | 55 | | |||
58 | _ui->historyLineSpinner->setSuffix(ki18ncp("@label:textbox Unit of scrollback", " line", " lines")); | 56 | _ui->historyLineSpinner->setSuffix(ki18ncp("@label:textbox Unit of scrollback", " line", " lines")); | ||
59 | setLineCount(HistorySizeWidget::DefaultLineCount); | 57 | setLineCount(HistorySizeWidget::DefaultLineCount); | ||
60 | 58 | | |||
61 | connect(_ui->historyLineSpinner, | 59 | connect(_ui->historyLineSpinner, | ||
62 | static_cast<void (KPluralHandlingSpinBox::*)(int)>(&KPluralHandlingSpinBox::valueChanged), | 60 | static_cast<void (KPluralHandlingSpinBox::*)(int)>(&KPluralHandlingSpinBox::valueChanged), | ||
63 | this, &Konsole::HistorySizeWidget::historySizeChanged); | 61 | this, &Konsole::HistorySizeWidget::historySizeChanged); | ||
64 | 62 | | |||
65 | auto warningButtonSizePolicy = _ui->fixedSizeHistoryWarningButton->sizePolicy(); | 63 | auto warningButtonSizePolicy = _ui->fixedSizeHistoryWarningButton->sizePolicy(); | ||
66 | warningButtonSizePolicy.setRetainSizeWhenHidden(true); | 64 | warningButtonSizePolicy.setRetainSizeWhenHidden(true); | ||
67 | 65 | | |||
68 | _ui->fixedSizeHistoryWarningButton->setSizePolicy(warningButtonSizePolicy); | 66 | _ui->fixedSizeHistoryWarningButton->setSizePolicy(warningButtonSizePolicy); | ||
69 | _ui->fixedSizeHistoryWarningButton->hide(); | 67 | _ui->fixedSizeHistoryWarningButton->hide(); | ||
70 | connect(_ui->fixedSizeHistoryButton, &QAbstractButton::toggled, _ui->historyLineSpinner, &QWidget::setEnabled); | 68 | connect(_ui->fixedSizeHistoryButton, &QAbstractButton::toggled, [this] (bool toggled) { | ||
71 | connect(_ui->fixedSizeHistoryButton, &QAbstractButton::toggled, _ui->fixedSizeHistoryWarningButton, &QWidget::setVisible); | 69 | _ui->historyLineSpinner->setEnabled(toggled); | ||
70 | _ui->fixedSizeHistoryWarningButton->setVisible(toggled); | ||||
71 | }); | ||||
72 | | ||||
72 | connect(_ui->fixedSizeHistoryWarningButton, &QToolButton::clicked, this, [this](bool) { | 73 | connect(_ui->fixedSizeHistoryWarningButton, &QToolButton::clicked, this, [this](bool) { | ||
73 | const QString message = i18nc("@info:whatsthis", "When using this option, the scrollback data will be saved to RAM. If you choose a huge value, your system may run out of free RAM and cause serious issues with your system."); | 74 | const QString message = i18nc("@info:whatsthis", | ||
74 | const QPoint pos = QPoint(_ui->fixedSizeHistoryWrapper->width() / 2, _ui->fixedSizeHistoryWrapper->height()); | 75 | "When using this option, the scrollback data will be saved to RAM." | ||
75 | QWhatsThis::showText(_ui->fixedSizeHistoryWrapper->mapToGlobal(pos), message, _ui->fixedSizeHistoryWrapper); | 76 | " If you choose a huge value, your system may run out of free RAM " | ||
77 | "and cause serious issues with your system."); | ||||
78 | | ||||
79 | const QPoint pos = QPoint(_ui->fixedSizeHistoryWarningButton->width() / 2, _ui->fixedSizeHistoryWarningButton->height()); | ||||
80 | QWhatsThis::showText(_ui->fixedSizeHistoryWarningButton->mapToGlobal(pos), message, _ui->fixedSizeHistoryWarningButton); | ||||
76 | }); | 81 | }); | ||
77 | 82 | | |||
78 | _ui->unlimitedHistoryWarningButton->setSizePolicy(warningButtonSizePolicy); | 83 | _ui->unlimitedHistoryWarningButton->setSizePolicy(warningButtonSizePolicy); | ||
79 | _ui->unlimitedHistoryWarningButton->hide(); | 84 | _ui->unlimitedHistoryWarningButton->hide(); | ||
80 | connect(_ui->unlimitedHistoryButton, &QAbstractButton::toggled, _ui->unlimitedHistoryWarningButton, &QWidget::setVisible); | 85 | connect(_ui->unlimitedHistoryButton, &QAbstractButton::toggled, [this](bool toggled) { | ||
81 | connect(_ui->unlimitedHistoryWarningButton, &QToolButton::clicked, this, [this](bool) { | 86 | _ui->unlimitedHistoryWarningButton->setVisible(toggled); | ||
82 | const auto message = xi18nc("@info:tooltip", "When using this option, the scrollback data will be written unencrypted to temporary files. Those temporary files will be deleted automatically when Konsole is closed in a normal manner.<nl/>Use <emphasis>Settings → Configure Konsole → File Location</emphasis> to select the location of the temporary files."); | 87 | _ui->unlimitedHistoryGroupBox->setVisible(!_temporary && toggled); | ||
83 | const QPoint pos = QPoint(_ui->unlimitedHistoryWrapper->width() / 2, _ui->unlimitedHistoryWrapper->height()); | | |||
84 | QWhatsThis::showText(_ui->unlimitedHistoryWrapper->mapToGlobal(pos), message, _ui->unlimitedHistoryWrapper); | | |||
85 | }); | 88 | }); | ||
86 | 89 | | |||
87 | // Make radio buttons height equal | 90 | connect(_ui->unlimitedHistoryWarningButton, &QToolButton::clicked, this, [this](bool) { | ||
88 | // fixedSizeHistoryWrapper contains radio + spinbox + toolbutton, so it | 91 | const auto message = xi18nc("@info:tooltip", | ||
89 | // has height always equal to or larger than single radio button, and | 92 | "When using this option, the scrollback data will be written unencrypted to " | ||
90 | // radio + toolbutton | 93 | "temporary files. Those temporary files will be deleted automatically when " | ||
91 | const int radioButtonHeight = _ui->fixedSizeHistoryWrapper->sizeHint().height(); | 94 | "Konsole is closed in a normal manner."); | ||
92 | _ui->noHistoryButton->setMinimumHeight(radioButtonHeight); | 95 | const QPoint pos = QPoint(_ui->unlimitedHistoryWarningButton->width() / 2, _ui->unlimitedHistoryWarningButton->height()); | ||
93 | _ui->unlimitedHistoryButton->setMinimumHeight(radioButtonHeight); | 96 | QWhatsThis::showText(_ui->unlimitedHistoryWarningButton->mapToGlobal(pos), message, _ui->unlimitedHistoryWarningButton); | ||
97 | }); | ||||
94 | } | 98 | } | ||
95 | 99 | | |||
96 | HistorySizeWidget::~HistorySizeWidget() | 100 | HistorySizeWidget::~HistorySizeWidget() | ||
97 | { | 101 | { | ||
98 | delete _ui; | 102 | delete _ui; | ||
99 | } | 103 | } | ||
100 | 104 | | |||
101 | void HistorySizeWidget::buttonClicked(QAbstractButton *) | 105 | void HistorySizeWidget::setTemporary(bool temporary) | ||
102 | { | 106 | { | ||
103 | Enum::HistoryModeEnum selectedMode = mode(); | 107 | _temporary = temporary; | ||
104 | emit historyModeChanged(selectedMode); | | |||
105 | } | 108 | } | ||
106 | 109 | | |||
107 | void HistorySizeWidget::setMode(Enum::HistoryModeEnum aMode) | 110 | void HistorySizeWidget::setMode(Enum::HistoryModeEnum aMode) | ||
108 | { | 111 | { | ||
109 | if (aMode == Enum::NoHistory) { | 112 | auto widget = aMode == Enum::NoHistory ? _ui->noHistoryButton | ||
110 | _ui->noHistoryButton->setChecked(true); | 113 | : aMode == Enum::FixedSizeHistory ? _ui->fixedSizeHistoryButton | ||
111 | } else if (aMode == Enum::FixedSizeHistory) { | 114 | : /* aMode == Enum::UnlimitedHistory */ _ui->unlimitedHistoryButton; | ||
112 | _ui->fixedSizeHistoryButton->setChecked(true); | 115 | widget->setChecked(true); | ||
113 | } else if (aMode == Enum::UnlimitedHistory) { | | |||
114 | _ui->unlimitedHistoryButton->setChecked(true); | | |||
115 | } | | |||
116 | } | 116 | } | ||
117 | 117 | | |||
118 | Enum::HistoryModeEnum HistorySizeWidget::mode() const | 118 | Enum::HistoryModeEnum HistorySizeWidget::mode() const | ||
119 | { | 119 | { | ||
120 | if (_ui->noHistoryButton->isChecked()) { | 120 | return _ui->unlimitedHistoryButton->isChecked() ? Enum::UnlimitedHistory | ||
121 | return Enum::NoHistory; | 121 | : _ui->fixedSizeHistoryButton->isChecked() ? Enum::FixedSizeHistory | ||
122 | } else if (_ui->fixedSizeHistoryButton->isChecked()) { | 122 | : /* _ui->noHistoryButton->isChecked() */ Enum::NoHistory; | ||
123 | return Enum::FixedSizeHistory; | | |||
124 | } else if (_ui->unlimitedHistoryButton->isChecked()) { | | |||
125 | return Enum::UnlimitedHistory; | | |||
126 | } | | |||
127 | | ||||
128 | Q_ASSERT(false); | | |||
129 | return Enum::NoHistory; | | |||
130 | } | 123 | } | ||
131 | 124 | | |||
132 | void HistorySizeWidget::setLineCount(int lines) | 125 | void HistorySizeWidget::setLineCount(int lines) | ||
133 | { | 126 | { | ||
134 | _ui->historyLineSpinner->setValue(lines); | 127 | _ui->historyLineSpinner->setValue(lines); | ||
135 | _ui->historyLineSpinner->setSingleStep(lines / 10); | 128 | _ui->historyLineSpinner->setSingleStep(lines / 10); | ||
136 | } | 129 | } | ||
137 | 130 | | |||
138 | int HistorySizeWidget::lineCount() const | 131 | int HistorySizeWidget::lineCount() const | ||
139 | { | 132 | { | ||
140 | return _ui->historyLineSpinner->value(); | 133 | return _ui->historyLineSpinner->value(); | ||
141 | } | 134 | } | ||
142 | | ||||
143 | int HistorySizeWidget::preferredLabelHeight() | | |||
144 | { | | |||
145 | Q_ASSERT(_ui); | | |||
146 | Q_ASSERT(_ui->noHistoryButton); | | |||
147 | | ||||
148 | return _ui->fixedSizeHistoryWrapper->sizeHint().height(); | | |||
149 | } | |