2016-06-15 17:44:38 +08:00
|
|
|
#include "datetimeplugin.h"
|
|
|
|
|
2016-07-13 10:08:38 +08:00
|
|
|
#include <QLabel>
|
|
|
|
|
2016-06-15 17:44:38 +08:00
|
|
|
DatetimePlugin::DatetimePlugin(QObject *parent)
|
2016-06-16 17:48:19 +08:00
|
|
|
: QObject(parent),
|
2016-07-01 11:07:20 +08:00
|
|
|
|
2016-07-13 10:08:38 +08:00
|
|
|
m_dateTipsLabel(new QLabel),
|
2016-07-01 11:07:20 +08:00
|
|
|
|
2016-06-16 17:48:19 +08:00
|
|
|
m_refershTimer(new QTimer(this))
|
2016-06-15 17:44:38 +08:00
|
|
|
{
|
2016-07-28 10:59:21 +08:00
|
|
|
m_dateTipsLabel->setObjectName("datetime");
|
2016-07-13 10:08:38 +08:00
|
|
|
m_dateTipsLabel->setStyleSheet("color:white;"
|
2017-03-29 10:48:42 +08:00
|
|
|
"padding:0px 3px;");
|
2016-07-01 11:07:20 +08:00
|
|
|
|
2016-06-16 17:48:19 +08:00
|
|
|
m_refershTimer->setInterval(1000);
|
|
|
|
m_refershTimer->start();
|
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
m_centralWidget = new DatetimeWidget;
|
2016-06-23 10:24:51 +08:00
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
connect(m_centralWidget, &DatetimeWidget::requestContextMenu, [this] {m_proxyInter->requestContextMenu(this, QString());});
|
2016-09-21 10:24:42 +08:00
|
|
|
|
2016-06-27 15:34:54 +08:00
|
|
|
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::updateCurrentTimeString);
|
2016-06-16 17:48:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DatetimePlugin::~DatetimePlugin()
|
|
|
|
{
|
2017-02-06 22:25:47 +08:00
|
|
|
delete m_centralWidget;
|
2016-07-13 10:08:38 +08:00
|
|
|
delete m_dateTipsLabel;
|
2016-06-15 17:44:38 +08:00
|
|
|
}
|
|
|
|
|
2016-06-28 14:23:30 +08:00
|
|
|
const QString DatetimePlugin::pluginName() const
|
2016-06-15 17:44:38 +08:00
|
|
|
{
|
2016-06-16 16:56:21 +08:00
|
|
|
return "datetime";
|
2016-07-01 11:07:20 +08:00
|
|
|
}
|
|
|
|
|
2016-06-24 11:32:25 +08:00
|
|
|
void DatetimePlugin::init(PluginProxyInterface *proxyInter)
|
|
|
|
{
|
|
|
|
m_proxyInter = proxyInter;
|
|
|
|
m_proxyInter->itemAdded(this, QString());
|
|
|
|
}
|
|
|
|
|
2016-08-02 20:14:45 +08:00
|
|
|
int DatetimePlugin::itemSortKey(const QString &itemKey)
|
2016-06-28 10:06:04 +08:00
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-06-24 11:32:25 +08:00
|
|
|
QWidget *DatetimePlugin::itemWidget(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
return m_centralWidget;
|
2016-06-16 17:48:19 +08:00
|
|
|
}
|
2016-06-27 15:34:54 +08:00
|
|
|
|
2016-07-01 11:07:20 +08:00
|
|
|
QWidget *DatetimePlugin::itemTipsWidget(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
2016-07-13 10:08:38 +08:00
|
|
|
return m_dateTipsLabel;
|
|
|
|
}
|
2016-07-01 11:20:26 +08:00
|
|
|
|
2016-07-13 10:08:38 +08:00
|
|
|
const QString DatetimePlugin::itemCommand(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
return "dde-calendar";
|
2016-07-01 11:07:20 +08:00
|
|
|
}
|
|
|
|
|
2016-09-21 10:24:42 +08:00
|
|
|
const QString DatetimePlugin::itemContextMenu(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
QList<QVariant> items;
|
|
|
|
items.reserve(1);
|
|
|
|
|
2017-03-30 16:48:34 +08:00
|
|
|
QMap<QString, QVariant> settings;
|
|
|
|
settings["itemId"] = "settings";
|
|
|
|
if (m_centralWidget->is24HourFormat())
|
|
|
|
settings["itemText"] = tr("12 Hour Time");
|
|
|
|
else
|
|
|
|
settings["itemText"] = tr("24 Hour Time");
|
|
|
|
settings["isActive"] = true;
|
|
|
|
items.push_back(settings);
|
|
|
|
|
2016-09-21 10:24:42 +08:00
|
|
|
QMap<QString, QVariant> open;
|
|
|
|
open["itemId"] = "open";
|
|
|
|
open["itemText"] = tr("Time Settings");
|
|
|
|
open["isActive"] = true;
|
|
|
|
items.push_back(open);
|
|
|
|
|
|
|
|
QMap<QString, QVariant> menu;
|
|
|
|
menu["items"] = items;
|
|
|
|
menu["checkableMenu"] = false;
|
|
|
|
menu["singleCheck"] = false;
|
|
|
|
|
|
|
|
return QJsonDocument::fromVariant(menu).toJson();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DatetimePlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey)
|
|
|
|
Q_UNUSED(checked)
|
|
|
|
|
2017-03-30 16:48:34 +08:00
|
|
|
if (menuId == "open")
|
|
|
|
QProcess::startDetached("dde-control-center", QStringList() << "datetime");
|
|
|
|
else
|
|
|
|
m_centralWidget->toggleHourFormat();
|
2016-09-21 10:24:42 +08:00
|
|
|
}
|
|
|
|
|
2016-06-27 15:34:54 +08:00
|
|
|
void DatetimePlugin::updateCurrentTimeString()
|
|
|
|
{
|
2016-07-13 10:08:38 +08:00
|
|
|
const QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
|
|
|
2017-03-31 16:48:49 +08:00
|
|
|
if (m_centralWidget->is24HourFormat())
|
|
|
|
m_dateTipsLabel->setText(currentDateTime.date().toString(Qt::SystemLocaleLongDate) + currentDateTime.toString(" HH:mm:ss"));
|
|
|
|
else
|
|
|
|
m_dateTipsLabel->setText(currentDateTime.date().toString(Qt::SystemLocaleLongDate) + currentDateTime.toString(" hh:mm:ss A"));
|
2016-07-13 10:08:38 +08:00
|
|
|
|
|
|
|
const QString currentString = currentDateTime.toString("mm");
|
2016-06-27 15:34:54 +08:00
|
|
|
|
|
|
|
if (currentString == m_currentTimeString)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_currentTimeString = currentString;
|
2017-02-06 22:25:47 +08:00
|
|
|
m_centralWidget->update();
|
2016-06-27 15:34:54 +08:00
|
|
|
}
|