-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init: Fork datatime plugin from commit 39c1a6b609c
Fork datatime plugin from dde-dock/master at commit 39c1a6b609c65026a505bd6b74a451bff26ee456
- Loading branch information
0 parents
commit cb2437d
Showing
30 changed files
with
959 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
set(PLUGIN_NAME "datetime") | ||
|
||
project(${PLUGIN_NAME}) | ||
|
||
# Sources files | ||
file(GLOB SRCS "*.h" "*.cpp") | ||
|
||
find_package(PkgConfig REQUIRED) | ||
find_package(Qt5Widgets REQUIRED) | ||
find_package(Qt5Svg REQUIRED) | ||
find_package(Qt5DBus REQUIRED) | ||
find_package(DtkWidget REQUIRED) | ||
|
||
add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN") | ||
add_library(${PLUGIN_NAME} SHARED ${SRCS} resources.qrc) | ||
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../) | ||
target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ../../interfaces) | ||
target_link_libraries(${PLUGIN_NAME} PRIVATE | ||
${Qt5DBus_LIBRARIES} | ||
${DtkWidget_LIBRARIES} | ||
${Qt5Widgets_LIBRARIES} | ||
${Qt5Svg_LIBRARIES} | ||
) | ||
|
||
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"api": "1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* | ||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd. | ||
* | ||
* Author: sbw <[email protected]> | ||
* | ||
* Maintainer: sbw <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "datetimeplugin.h" | ||
|
||
#include <DDBusSender> | ||
#include <QLabel> | ||
#include <QDebug> | ||
|
||
DatetimePlugin::DatetimePlugin(QObject *parent) | ||
: QObject(parent), | ||
|
||
m_dateTipsLabel(new QLabel), | ||
|
||
m_refershTimer(new QTimer(this)), | ||
m_settings("deepin", "dde-dock-datetime") | ||
{ | ||
m_dateTipsLabel->setObjectName("datetime"); | ||
m_dateTipsLabel->setStyleSheet("color:white;" | ||
"padding:0px 3px;"); | ||
|
||
m_refershTimer->setInterval(1000); | ||
m_refershTimer->start(); | ||
|
||
m_centralWidget = new DatetimeWidget; | ||
|
||
connect(m_centralWidget, &DatetimeWidget::requestContextMenu, [this] { m_proxyInter->requestContextMenu(this, QString()); }); | ||
connect(m_centralWidget, &DatetimeWidget::requestUpdateGeometry, [this] { m_proxyInter->itemUpdate(this, QString()); }); | ||
|
||
connect(m_refershTimer, &QTimer::timeout, this, &DatetimePlugin::updateCurrentTimeString); | ||
} | ||
|
||
const QString DatetimePlugin::pluginName() const | ||
{ | ||
return "datetime"; | ||
} | ||
|
||
const QString DatetimePlugin::pluginDisplayName() const | ||
{ | ||
return tr("Datetime"); | ||
} | ||
|
||
void DatetimePlugin::init(PluginProxyInterface *proxyInter) | ||
{ | ||
m_proxyInter = proxyInter; | ||
|
||
if (m_centralWidget->enabled()) | ||
m_proxyInter->itemAdded(this, QString()); | ||
} | ||
|
||
void DatetimePlugin::pluginStateSwitched() | ||
{ | ||
m_centralWidget->setEnabled(!m_centralWidget->enabled()); | ||
|
||
if (m_centralWidget->enabled()) | ||
m_proxyInter->itemAdded(this, QString()); | ||
else | ||
m_proxyInter->itemRemoved(this, QString()); | ||
} | ||
|
||
bool DatetimePlugin::pluginIsDisable() | ||
{ | ||
return !m_centralWidget->enabled(); | ||
} | ||
|
||
int DatetimePlugin::itemSortKey(const QString &itemKey) | ||
{ | ||
Q_UNUSED(itemKey); | ||
|
||
const QString key = QString("pos_%1").arg(displayMode()); | ||
return m_settings.value(key, 0).toInt(); | ||
} | ||
|
||
void DatetimePlugin::setSortKey(const QString &itemKey, const int order) | ||
{ | ||
Q_UNUSED(itemKey); | ||
|
||
const QString key = QString("pos_%1").arg(displayMode()); | ||
m_settings.setValue(key, order); | ||
} | ||
|
||
QWidget *DatetimePlugin::itemWidget(const QString &itemKey) | ||
{ | ||
Q_UNUSED(itemKey); | ||
|
||
return m_centralWidget; | ||
} | ||
|
||
QWidget *DatetimePlugin::itemTipsWidget(const QString &itemKey) | ||
{ | ||
Q_UNUSED(itemKey); | ||
|
||
return m_dateTipsLabel; | ||
} | ||
|
||
const QString DatetimePlugin::itemCommand(const QString &itemKey) | ||
{ | ||
Q_UNUSED(itemKey); | ||
|
||
return "dbus-send --print-reply --dest=com.deepin.Calendar /com/deepin/Calendar com.deepin.Calendar.RaiseWindow"; | ||
} | ||
|
||
const QString DatetimePlugin::itemContextMenu(const QString &itemKey) | ||
{ | ||
Q_UNUSED(itemKey); | ||
|
||
QList<QVariant> items; | ||
items.reserve(1); | ||
|
||
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); | ||
|
||
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) | ||
|
||
if (menuId == "open") { | ||
DDBusSender() | ||
.service("com.deepin.dde.ControlCenter") | ||
.interface("com.deepin.dde.ControlCenter") | ||
.path("/com/deepin/dde/ControlCenter") | ||
.method(QString("ShowModule")) | ||
.arg(QString("datetime")) | ||
.call(); | ||
} else { | ||
m_centralWidget->toggleHourFormat(); | ||
} | ||
} | ||
|
||
void DatetimePlugin::updateCurrentTimeString() | ||
{ | ||
const QDateTime currentDateTime = QDateTime::currentDateTime(); | ||
|
||
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")); | ||
|
||
const QString currentString = currentDateTime.toString("mm"); | ||
|
||
if (currentString == m_currentTimeString) | ||
return; | ||
|
||
m_currentTimeString = currentString; | ||
m_centralWidget->update(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd. | ||
* | ||
* Author: sbw <[email protected]> | ||
* | ||
* Maintainer: sbw <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef DATETIMEPLUGIN_H | ||
#define DATETIMEPLUGIN_H | ||
|
||
#include "pluginsiteminterface.h" | ||
#include "datetimewidget.h" | ||
|
||
#include <QTimer> | ||
#include <QLabel> | ||
#include <QSettings> | ||
|
||
class DatetimePlugin : public QObject, PluginsItemInterface | ||
{ | ||
Q_OBJECT | ||
Q_INTERFACES(PluginsItemInterface) | ||
Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "datetime.json") | ||
|
||
public: | ||
explicit DatetimePlugin(QObject *parent = 0); | ||
|
||
const QString pluginName() const override; | ||
const QString pluginDisplayName() const override; | ||
void init(PluginProxyInterface *proxyInter) override; | ||
|
||
void pluginStateSwitched() override; | ||
bool pluginIsAllowDisable() override { return true; } | ||
bool pluginIsDisable() override; | ||
|
||
int itemSortKey(const QString &itemKey); | ||
void setSortKey(const QString &itemKey, const int order); | ||
|
||
QWidget *itemWidget(const QString &itemKey) override; | ||
QWidget *itemTipsWidget(const QString &itemKey) override; | ||
|
||
const QString itemCommand(const QString &itemKey) override; | ||
const QString itemContextMenu(const QString &itemKey) override; | ||
|
||
void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) override; | ||
|
||
private slots: | ||
void updateCurrentTimeString(); | ||
|
||
private: | ||
QPointer<DatetimeWidget> m_centralWidget; | ||
QPointer<QLabel> m_dateTipsLabel; | ||
|
||
QTimer *m_refershTimer; | ||
|
||
QString m_currentTimeString; | ||
QSettings m_settings; | ||
}; | ||
|
||
#endif // DATETIMEPLUGIN_H |
Oops, something went wrong.