Commit 1b7a1df5 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Remove separate expirydialog.ui

GnuPG-bug-id: 4717
parent 47ab3744
......@@ -308,7 +308,6 @@ if(KLEO_MODEL_TEST)
endif()
ki18n_wrap_ui(_kleopatra_SRCS
dialogs/expirydialog.ui
dialogs/lookupcertificatesdialog.ui
dialogs/ownertrustdialog.ui
dialogs/selectchecklevelwidget.ui
......
......@@ -11,16 +11,26 @@
#include "expirydialog.h"
#include "ui_expirydialog.h"
#include <KLocalizedString>
#include <KStandardGuiItem>
#include <QCalendarWidget>
#include <QComboBox>
#include <QDate>
#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QRadioButton>
#include <QSpinBox>
#include <QVBoxLayout>
using namespace Kleo;
using namespace Kleo::Dialogs;
namespace
{
enum Period {
Days,
Weeks,
......@@ -59,6 +69,14 @@ static int yearsBetween(const QDate &d1, const QDate &d2)
return qRound(days / DAYS_IN_GREGORIAN_YEAR);
}
auto radioButtonSize(const QRadioButton *radioButton)
{
QStyleOptionButton opt;
return radioButton->style()->sizeFromContents(QStyle::CT_RadioButton, &opt, QSize(), radioButton);
}
}
class ExpiryDialog::Private
{
friend class ::Kleo::Dialogs::ExpiryDialog;
......@@ -101,61 +119,103 @@ private:
private:
int inUnit;
struct UI : public Ui::ExpiryDialog {
struct UI {
QRadioButton *neverRB;
QRadioButton *inRB;
QSpinBox *inSB;
QComboBox *inCB;
QRadioButton *onRB;
QCalendarWidget *onCW;
explicit UI(Dialogs::ExpiryDialog *qq)
: Ui::ExpiryDialog{}
{
auto mainWidget = new QWidget(qq);
auto mainLayout = new QVBoxLayout{qq};
auto mainWidget = new QWidget{qq};
auto vboxLayout = new QVBoxLayout{mainWidget};
vboxLayout->setContentsMargins(0, 0, 0, 0);
vboxLayout->addWidget(new QLabel{i18n("Please select when to expire this certificate:"), mainWidget});
neverRB = new QRadioButton(i18n("Ne&ver"), mainWidget);
neverRB->setChecked(false);
vboxLayout->addWidget(neverRB);
{
auto hboxLayout = new QHBoxLayout;
inRB = new QRadioButton{i18n("In"), mainWidget};
inRB->setChecked(false);
hboxLayout->addWidget(inRB);
inSB = new QSpinBox{mainWidget};
inSB->setEnabled(false);
inSB->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
inSB->setMinimum(1);
hboxLayout->addWidget(inSB);
inCB = new QComboBox{mainWidget};
inCB->addItem(i18n("Days"));
inCB->addItem(i18n("Weeks"));
inCB->addItem(i18n("Months"));
inCB->addItem(i18n("Years"));
Q_ASSERT(inCB->count() == NumPeriods);
inCB->setEnabled(false);
hboxLayout->addWidget(inCB);
hboxLayout->addStretch(1);
vboxLayout->addLayout(hboxLayout);
}
onRB = new QRadioButton{i18n("On this da&y:"), mainWidget};
onRB->setChecked(true);
vboxLayout->addWidget(onRB);
{
auto hboxLayout = new QHBoxLayout;
hboxLayout->addSpacing(radioButtonSize(onRB).width());
onCW = new QCalendarWidget{mainWidget};
onCW->setGridVisible(true);
onCW->setMinimumDate(QDate::currentDate().addDays(1));
hboxLayout->addWidget(onCW);
hboxLayout->addStretch(1);
vboxLayout->addLayout(hboxLayout);
}
vboxLayout->addStretch(1);
setupUi(mainWidget);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, qq);
auto mainLayout = new QVBoxLayout;
qq->setLayout(mainLayout);
mainLayout->addWidget(mainWidget);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
auto buttonBox = new QDialogButtonBox{QDialogButtonBox::Ok | QDialogButtonBox::Cancel, qq};
auto okButton = buttonBox->button(QDialogButtonBox::Ok);
KGuiItem::assign(okButton, KStandardGuiItem::ok());
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
qq->connect(buttonBox, &QDialogButtonBox::accepted, qq, &QDialog::accept);
qq->connect(buttonBox, &QDialogButtonBox::rejected, qq, &QDialog::reject);
mainLayout->addWidget(buttonBox);
Q_ASSERT(inCB->count() == NumPeriods);
mainLayout->addWidget(buttonBox);
onCW->setMinimumDate(QDate::currentDate().addDays(1));
connect(onRB, &QRadioButton::toggled, onCW, &QWidget::setEnabled);
connect(inRB, &QRadioButton::toggled, inCB, &QWidget::setEnabled);
connect(inRB, &QRadioButton::toggled, inSB, &QWidget::setEnabled);
}
} ui;
};
ExpiryDialog::ExpiryDialog(QWidget *p)
: QDialog{p}
, d{new Private{this}}
{
setWindowTitle(i18nc("@title:window", "Change Expiry"));
}
ExpiryDialog::~ExpiryDialog() = default;
void ExpiryDialog::setDateOfExpiry(const QDate &date)
{
const QDate current = QDate::currentDate();
if (date.isValid()) {
d->ui.onRB->setChecked(true);
d->ui.onCW->setSelectedDate(qMax(date, current));
} else {
d->ui.neverRB->setChecked(true);
d->ui.onCW->setSelectedDate(current);
d->ui.inSB->setValue(0);
}
}
QDate ExpiryDialog::dateOfExpiry() const
{
return
d->ui.inRB->isChecked() ? d->inDate() :
d->ui.onRB->isChecked() ? d->ui.onCW->selectedDate() :
QDate{};
}
void ExpiryDialog::Private::slotInUnitChanged()
{
const int oldInAmount = ui.inSB->value();
......@@ -203,4 +263,34 @@ int ExpiryDialog::Private::inAmountByDate(const QDate &selected) const
return -1;
}
ExpiryDialog::ExpiryDialog(QWidget *p)
: QDialog{p}
, d{new Private{this}}
{
setWindowTitle(i18nc("@title:window", "Change Expiry"));
}
ExpiryDialog::~ExpiryDialog() = default;
void ExpiryDialog::setDateOfExpiry(const QDate &date)
{
const QDate current = QDate::currentDate();
if (date.isValid()) {
d->ui.onRB->setChecked(true);
d->ui.onCW->setSelectedDate(qMax(date, current));
} else {
d->ui.neverRB->setChecked(true);
d->ui.onCW->setSelectedDate(current);
d->ui.inSB->setValue(0);
}
}
QDate ExpiryDialog::dateOfExpiry() const
{
return
d->ui.inRB->isChecked() ? d->inDate() :
d->ui.onRB->isChecked() ? d->ui.onCW->selectedDate() :
QDate{};
}
#include "moc_expirydialog.cpp"
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Kleo::Dialogs::ExpiryDialog</class>
<widget class="QWidget" name="Kleo::Dialogs::ExpiryDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>436</width>
<height>386</height>
</rect>
</property>
<property name="windowTitle">
<string>Change Certificate Date of Expiry</string>
</property>
<layout class="QVBoxLayout">
<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>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Please select when to expire this certificate:</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="neverRB">
<property name="text">
<string>Ne&amp;ver</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QRadioButton" name="inRB">
<property name="text">
<string>In</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="inSB">
<property name="enabled">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="inCB">
<property name="enabled">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>Days</string>
</property>
</item>
<item>
<property name="text">
<string>Weeks</string>
</property>
</item>
<item>
<property name="text">
<string>Months</string>
</property>
</item>
<item>
<property name="text">
<string>Years</string>
</property>
</item>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="onRB">
<property name="text">
<string>On this da&amp;y:</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCalendarWidget" name="onCW">
<property name="gridVisible">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>418</width>
<height>16</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>onRB</sender>
<signal>toggled(bool)</signal>
<receiver>onCW</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>102</x>
<y>55</y>
</hint>
<hint type="destinationlabel">
<x>102</x>
<y>79</y>
</hint>
</hints>
</connection>
<connection>
<sender>inRB</sender>
<signal>toggled(bool)</signal>
<receiver>inCB</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>144</x>
<y>313</y>
</hint>
<hint type="destinationlabel">
<x>314</x>
<y>315</y>
</hint>
</hints>
</connection>
<connection>
<sender>inRB</sender>
<signal>toggled(bool)</signal>
<receiver>inSB</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>144</x>
<y>331</y>
</hint>
<hint type="destinationlabel">
<x>176</x>
<y>331</y>
</hint>
</hints>
</connection>
</connections>
</ui>
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