mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 10:22:49 +00:00
kcontrol: use message widget to warn that day and time cannot be changed in clock KCM
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
1f28be5d1c
commit
cc1afece41
2 changed files with 29 additions and 12 deletions
|
@ -52,6 +52,8 @@ K_EXPORT_PLUGIN(KCMClockFactory("kcmclock", "kcmclock"))
|
|||
KCMClock::KCMClock(QWidget *parent, const QVariantList &args)
|
||||
: KCModule(KCMClockFactory::componentData(), parent),
|
||||
m_layout(nullptr),
|
||||
m_canchangeclock(false),
|
||||
m_messagewidget(nullptr),
|
||||
m_datetimebox(nullptr),
|
||||
m_datetimelayout(nullptr),
|
||||
m_timeedit(nullptr),
|
||||
|
@ -82,6 +84,14 @@ KCMClock::KCMClock(QWidget *parent, const QVariantList &args)
|
|||
m_layout = new QVBoxLayout(this);
|
||||
setLayout(m_layout);
|
||||
|
||||
m_canchangeclock = kCanChangeClock();
|
||||
m_messagewidget = new KMessageWidget(this);
|
||||
m_messagewidget->setMessageType(KMessageWidget::Warning);
|
||||
m_messagewidget->setCloseButtonVisible(false);
|
||||
m_messagewidget->setText(i18n("Neither 'hwclock' nor 'timedatectl' utility found, setting the date and time is not possible."));
|
||||
m_messagewidget->setVisible(!m_canchangeclock);
|
||||
m_layout->addWidget(m_messagewidget);
|
||||
|
||||
m_datetimebox = new QGroupBox(this);
|
||||
m_datetimebox->setTitle(i18n("Date and time"));
|
||||
m_datetimelayout = new QHBoxLayout(m_datetimebox);
|
||||
|
@ -146,17 +156,6 @@ KCMClock::KCMClock(QWidget *parent, const QVariantList &args)
|
|||
m_timer = new QTimer(this);
|
||||
m_timer->setInterval(s_updatetime);
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(slotUpdate()));
|
||||
|
||||
if (!KAuthorization::isAuthorized("org.kde.kcontrol.kcmclock")) {
|
||||
setUseRootOnlyMessage(true);
|
||||
setRootOnlyMessage(i18n("You are not allowed to save the configuration"));
|
||||
setDisabled(true);
|
||||
} else if (!kCanChangeClock()) {
|
||||
setUseRootOnlyMessage(true);
|
||||
setRootOnlyMessage(i18n("Neither 'hwclock' nor 'timedatectl' utility not found, setting the date is not possible"));
|
||||
m_timeedit->setEnabled(false);
|
||||
m_dateedit->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void KCMClock::save()
|
||||
|
@ -167,7 +166,7 @@ void KCMClock::save()
|
|||
m_datechanged = false;
|
||||
m_zonechanged = false;
|
||||
QVariantMap savearguments;
|
||||
if (kCanChangeClock()) {
|
||||
if (m_canchangeclock) {
|
||||
const QDateTime datetime = QDateTime(m_dateedit->date(), m_timeedit->time());
|
||||
savearguments.insert("datetime", datetime.toString(s_dateformat));
|
||||
// qDebug() << Q_FUNC_INFO << datetime;
|
||||
|
@ -205,6 +204,15 @@ void KCMClock::save()
|
|||
void KCMClock::load()
|
||||
{
|
||||
setEnabled(false);
|
||||
if (!KAuthorization::isAuthorized("org.kde.kcontrol.kcmclock")) {
|
||||
setUseRootOnlyMessage(true);
|
||||
setRootOnlyMessage(i18n("You are not allowed to save the configuration"));
|
||||
setDisabled(true);
|
||||
}
|
||||
m_canchangeclock = kCanChangeClock();
|
||||
m_messagewidget->setVisible(!m_canchangeclock);
|
||||
m_timeedit->setEnabled(m_canchangeclock);
|
||||
m_dateedit->setEnabled(m_canchangeclock);
|
||||
m_timechanged = false;
|
||||
m_datechanged = false;
|
||||
m_zonechanged = false;
|
||||
|
@ -214,6 +222,11 @@ void KCMClock::load()
|
|||
setEnabled(true);
|
||||
}
|
||||
|
||||
void KCMClock::defaults()
|
||||
{
|
||||
// TODO: set timezone to UTC, check the time vs http://worldtimeapi.org/api/timezone/UTC
|
||||
}
|
||||
|
||||
void KCMClock::slotUpdate()
|
||||
{
|
||||
const QDateTime now = QDateTime::currentDateTime();
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <QTreeWidget>
|
||||
#include <QTimer>
|
||||
#include <kcmodule.h>
|
||||
#include <kmessagewidget.h>
|
||||
#include <ktreewidgetsearchline.h>
|
||||
|
||||
class KCMClock : public KCModule
|
||||
|
@ -39,6 +40,7 @@ public:
|
|||
public Q_SLOTS:
|
||||
void load() final;
|
||||
void save() final;
|
||||
void defaults() final;
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotUpdate();
|
||||
|
@ -48,6 +50,8 @@ private Q_SLOTS:
|
|||
|
||||
private:
|
||||
QVBoxLayout* m_layout;
|
||||
bool m_canchangeclock;
|
||||
KMessageWidget* m_messagewidget;
|
||||
QGroupBox* m_datetimebox;
|
||||
QHBoxLayout* m_datetimelayout;
|
||||
QTimeEdit* m_timeedit;
|
||||
|
|
Loading…
Add table
Reference in a new issue