mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
fix: date-time plugin enable status
Change-Id: I155423b46683393396ef07e39b28545abc3a3676
This commit is contained in:
parent
d1fa536406
commit
2d925fe74e
Notes:
gerrit
2018-11-21 09:07:59 +08:00
Verified+1: <jenkins@deepin.com> Code-Review+2: listenerri <listenerri@gmail.com> Submitted-by: listenerri <listenerri@gmail.com> Submitted-at: Wed, 21 Nov 2018 09:07:58 +0800 Reviewed-on: https://cr.deepin.io/39864 Project: dde/dde-dock Branch: refs/heads/master
@ -25,6 +25,9 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#define PLUGIN_STATE_KEY "enable"
|
||||||
|
#define TIME_FORMAT_KEY "24HourFormat"
|
||||||
|
|
||||||
DatetimePlugin::DatetimePlugin(QObject *parent)
|
DatetimePlugin::DatetimePlugin(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
|
|
||||||
@ -58,6 +61,7 @@ const QString DatetimePlugin::pluginDisplayName() const
|
|||||||
void DatetimePlugin::init(PluginProxyInterface *proxyInter)
|
void DatetimePlugin::init(PluginProxyInterface *proxyInter)
|
||||||
{
|
{
|
||||||
m_proxyInter = proxyInter;
|
m_proxyInter = proxyInter;
|
||||||
|
m_centralWidget->set24HourFormat(m_proxyInter->getValue(this, TIME_FORMAT_KEY, true).toBool());
|
||||||
|
|
||||||
// transfer config
|
// transfer config
|
||||||
QSettings settings("deepin", "dde-dock-datetime");
|
QSettings settings("deepin", "dde-dock-datetime");
|
||||||
@ -68,15 +72,15 @@ void DatetimePlugin::init(PluginProxyInterface *proxyInter)
|
|||||||
QFile::remove(settings.fileName());
|
QFile::remove(settings.fileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_centralWidget->enabled())
|
if (!pluginIsDisable())
|
||||||
m_proxyInter->itemAdded(this, QString());
|
m_proxyInter->itemAdded(this, QString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatetimePlugin::pluginStateSwitched()
|
void DatetimePlugin::pluginStateSwitched()
|
||||||
{
|
{
|
||||||
m_centralWidget->setEnabled(!m_centralWidget->enabled());
|
m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable());
|
||||||
|
|
||||||
if (m_centralWidget->enabled())
|
if (!pluginIsDisable())
|
||||||
m_proxyInter->itemAdded(this, QString());
|
m_proxyInter->itemAdded(this, QString());
|
||||||
else
|
else
|
||||||
m_proxyInter->itemRemoved(this, QString());
|
m_proxyInter->itemRemoved(this, QString());
|
||||||
@ -84,7 +88,7 @@ void DatetimePlugin::pluginStateSwitched()
|
|||||||
|
|
||||||
bool DatetimePlugin::pluginIsDisable()
|
bool DatetimePlugin::pluginIsDisable()
|
||||||
{
|
{
|
||||||
return !m_centralWidget->enabled();
|
return !(m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool());
|
||||||
}
|
}
|
||||||
|
|
||||||
int DatetimePlugin::itemSortKey(const QString &itemKey)
|
int DatetimePlugin::itemSortKey(const QString &itemKey)
|
||||||
@ -174,7 +178,9 @@ void DatetimePlugin::invokedMenuItem(const QString &itemKey, const QString &menu
|
|||||||
.arg(QString("datetime"))
|
.arg(QString("datetime"))
|
||||||
.call();
|
.call();
|
||||||
} else {
|
} else {
|
||||||
m_centralWidget->toggleHourFormat();
|
const bool value = m_proxyInter->getValue(this, TIME_FORMAT_KEY, true).toBool();
|
||||||
|
m_proxyInter->saveValue(this, TIME_FORMAT_KEY, !value);
|
||||||
|
m_centralWidget->set24HourFormat(!value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,35 +31,25 @@
|
|||||||
#define PLUGIN_STATE_KEY "enable"
|
#define PLUGIN_STATE_KEY "enable"
|
||||||
|
|
||||||
DatetimeWidget::DatetimeWidget(QWidget *parent)
|
DatetimeWidget::DatetimeWidget(QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent)
|
||||||
|
|
||||||
m_settings("deepin", "dde-dock-datetime"),
|
|
||||||
|
|
||||||
m_24HourFormat(m_settings.value("24HourFormat", true).toBool())
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatetimeWidget::enabled()
|
void DatetimeWidget::set24HourFormat(const bool value)
|
||||||
{
|
{
|
||||||
return m_settings.value(PLUGIN_STATE_KEY, true).toBool();
|
if (m_24HourFormat == value) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void DatetimeWidget::setEnabled(const bool b)
|
m_24HourFormat = value;
|
||||||
{
|
|
||||||
m_settings.setValue(PLUGIN_STATE_KEY, b);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DatetimeWidget::toggleHourFormat()
|
|
||||||
{
|
|
||||||
m_24HourFormat = !m_24HourFormat;
|
|
||||||
|
|
||||||
m_settings.setValue("24HourFormat", m_24HourFormat);
|
|
||||||
|
|
||||||
m_cachedTime.clear();
|
m_cachedTime.clear();
|
||||||
update();
|
update();
|
||||||
|
|
||||||
emit requestUpdateGeometry();
|
if (isVisible()) {
|
||||||
|
emit requestUpdateGeometry();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize DatetimeWidget::sizeHint() const
|
QSize DatetimeWidget::sizeHint() const
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#define DATETIMEWIDGET_H
|
#define DATETIMEWIDGET_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
class DatetimeWidget : public QWidget
|
class DatetimeWidget : public QWidget
|
||||||
{
|
{
|
||||||
@ -33,15 +32,13 @@ public:
|
|||||||
explicit DatetimeWidget(QWidget *parent = 0);
|
explicit DatetimeWidget(QWidget *parent = 0);
|
||||||
|
|
||||||
bool is24HourFormat() const { return m_24HourFormat; }
|
bool is24HourFormat() const { return m_24HourFormat; }
|
||||||
bool enabled();
|
|
||||||
void setEnabled(const bool b);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void requestUpdateGeometry() const;
|
void requestUpdateGeometry() const;
|
||||||
void requestContextMenu() const;
|
void requestContextMenu() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void toggleHourFormat();
|
void set24HourFormat(const bool value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const;
|
||||||
@ -54,7 +51,6 @@ private:
|
|||||||
private:
|
private:
|
||||||
QPixmap m_cachedIcon;
|
QPixmap m_cachedIcon;
|
||||||
QString m_cachedTime;
|
QString m_cachedTime;
|
||||||
QSettings m_settings;
|
|
||||||
bool m_24HourFormat;
|
bool m_24HourFormat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user