-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the dde-clipboard plugin Log:
- Loading branch information
wangfei
committed
Oct 29, 2024
1 parent
d7dc745
commit 4494faf
Showing
20 changed files
with
1,038 additions
and
1 deletion.
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
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
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": "2.0.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,37 @@ | ||
// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
#ifndef CLIPBOARDCONTROLLER_H | ||
#define CLIPBOARDCONTROLLER_H | ||
|
||
#include <DSingleton> | ||
|
||
#include <QDBusInterface> | ||
#include <QObject> | ||
|
||
class ClipboardController : public QObject, public Dtk::Core::DSingleton<ClipboardController> | ||
{ | ||
friend Dtk::Core::DSingleton<ClipboardController>; | ||
|
||
Q_OBJECT | ||
public: | ||
ClipboardController() | ||
{ | ||
} | ||
|
||
~ClipboardController() { } | ||
|
||
void toggle() | ||
{ | ||
QDBusInterface interface("org.deepin.dde.ClipboardLoader1", | ||
"/org/deepin/dde/ClipboardLoader1", | ||
"org.deepin.dde.ClipboardLoader1", | ||
QDBusConnection::sessionBus()); | ||
if (interface.isValid()) { | ||
interface.call("quit"); | ||
} | ||
} | ||
}; | ||
|
||
#endif |
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,107 @@ | ||
// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
#include "clipboarditem.h" | ||
#include "constants.h" | ||
#include "clipboardcontroller.h" | ||
|
||
#include <DDBusSender> | ||
#include <DGuiApplicationHelper> | ||
|
||
#include <QDBusConnection> | ||
#include <QIcon> | ||
#include <QJsonDocument> | ||
#include <QPainter> | ||
#include <QVBoxLayout> | ||
#include <QMouseEvent> | ||
|
||
DGUI_USE_NAMESPACE | ||
|
||
#define SHIFT "shift" | ||
|
||
ClipboardItem::ClipboardItem(QWidget* parent) | ||
: QWidget(parent) | ||
, m_tipsLabel(new TipsWidget(this)) | ||
, m_icon(new CommonIconButton(this)) | ||
{ | ||
init(); | ||
} | ||
|
||
void ClipboardItem::init() | ||
{ | ||
m_tipsLabel->setVisible(false); | ||
m_tipsLabel->setText(tr("Clipboard")); | ||
|
||
m_icon->setFixedSize(Dock::DOCK_PLUGIN_ITEM_FIXED_SIZE); | ||
m_icon->setIcon(QIcon::fromTheme("clipboard")); | ||
m_icon->setClickable(true); | ||
|
||
auto vLayout = new QVBoxLayout(this); | ||
vLayout->setSpacing(0); | ||
vLayout->setMargin(0); | ||
vLayout->addWidget(m_icon, 0, Qt::AlignCenter); | ||
|
||
refreshIcon(); | ||
|
||
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &ClipboardItem::refreshIcon); | ||
connect(m_icon, &CommonIconButton::clicked, this, [] { | ||
ClipboardController::ref().toggle(); | ||
}); | ||
} | ||
|
||
QWidget* ClipboardItem::tipsWidget() | ||
{ | ||
return m_tipsLabel; | ||
} | ||
|
||
const QString ClipboardItem::contextMenu() const | ||
{ | ||
QList<QVariant> items; | ||
items.reserve(1); | ||
|
||
QMap<QString, QVariant> shift; | ||
shift["itemId"] = SHIFT; | ||
shift["itemText"] = tr("Open"); | ||
shift["isActive"] = true; | ||
items.push_back(shift); | ||
|
||
QMap<QString, QVariant> menu; | ||
menu["items"] = items; | ||
menu["checkableMenu"] = false; | ||
menu["singleCheck"] = false; | ||
|
||
return QJsonDocument::fromVariant(menu).toJson(); | ||
} | ||
|
||
void ClipboardItem::invokeMenuItem(const QString menuId, const bool checked) | ||
{ | ||
Q_UNUSED(menuId); | ||
Q_UNUSED(checked); | ||
|
||
if (menuId == SHIFT) { | ||
ClipboardController::ref().toggle(); | ||
Q_EMIT requestHideApplet(); | ||
} | ||
} | ||
|
||
void ClipboardItem::refreshIcon() | ||
{ | ||
m_icon->setState(CommonIconButton::Default); | ||
} | ||
|
||
void ClipboardItem::resizeEvent(QResizeEvent* e) | ||
{ | ||
QWidget::resizeEvent(e); | ||
|
||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>(); | ||
if (position == Dock::Bottom || position == Dock::Top) { | ||
setMaximumWidth(height()); | ||
setMaximumHeight(QWIDGETSIZE_MAX); | ||
} else { | ||
setMaximumHeight(width()); | ||
setMaximumWidth(QWIDGETSIZE_MAX); | ||
} | ||
|
||
refreshIcon(); | ||
} |
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,40 @@ | ||
// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
#ifndef CLIPBOARDITEM_H | ||
#define CLIPBOARDITEM_H | ||
|
||
#include "commoniconbutton.h" | ||
#include "widget/tipswidget.h" | ||
|
||
#include <QWidget> | ||
|
||
class ClipboardItem : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ClipboardItem(QWidget *parent = nullptr); | ||
|
||
QWidget *tipsWidget(); | ||
const QString contextMenu() const; | ||
void invokeMenuItem(const QString menuId, const bool checked); | ||
void refreshIcon(); | ||
|
||
protected: | ||
void resizeEvent(QResizeEvent *e) override; | ||
|
||
signals: | ||
void requestHideApplet(); | ||
|
||
private: | ||
void init(); | ||
|
||
private: | ||
TipsWidget *m_tipsLabel; | ||
CommonIconButton *m_icon; | ||
QPixmap m_iconPixmap; | ||
}; | ||
|
||
#endif // CLIPBOARDITEM_H |
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,151 @@ | ||
// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
#include "clipboardplugin.h" | ||
|
||
#include <QDBusConnection> | ||
|
||
#define CLIPBOARD_KEY "clipboard-key" | ||
DCORE_USE_NAMESPACE | ||
|
||
ClipboardPlugin::ClipboardPlugin(QObject *parent) | ||
: QObject(parent) | ||
, m_quickPanelWidget(nullptr) | ||
, m_item(nullptr) | ||
, m_messageCallback(nullptr) | ||
{ | ||
QTranslator *translator = new QTranslator(this); | ||
translator->load(QString("/usr/share/dde-clipboard/translations/dde-clipboard_%1.qm").arg(QLocale::system().name())); | ||
QCoreApplication::installTranslator(translator); | ||
} | ||
|
||
ClipboardPlugin::~ClipboardPlugin() | ||
{ | ||
if (m_quickPanelWidget) { | ||
delete m_quickPanelWidget; | ||
m_quickPanelWidget = nullptr; | ||
} | ||
|
||
if (m_item) { | ||
delete m_item; | ||
m_item = nullptr; | ||
} | ||
} | ||
|
||
const QString ClipboardPlugin::pluginName() const | ||
{ | ||
return "clipboard"; | ||
} | ||
|
||
const QString ClipboardPlugin::pluginDisplayName() const | ||
{ | ||
return tr("Clipboard"); | ||
} | ||
|
||
void ClipboardPlugin::init(PluginProxyInterface *proxyInter) | ||
{ | ||
m_proxyInter = proxyInter; | ||
|
||
if (m_item || m_quickPanelWidget) { | ||
return; | ||
} | ||
m_item = new ClipboardItem(); | ||
m_quickPanelWidget = new QuickPanelWidget(); | ||
|
||
m_proxyInter->itemAdded(this, CLIPBOARD_KEY); | ||
m_quickPanelWidget->setDescription(pluginDisplayName()); | ||
m_quickPanelWidget->setIcon(QIcon::fromTheme("clipboard")); | ||
|
||
connect(m_item, &ClipboardItem::requestHideApplet, this, [this] { | ||
m_proxyInter->requestSetAppletVisible(this, CLIPBOARD_KEY, false); | ||
}); | ||
connect(m_quickPanelWidget, &QuickPanelWidget::requestHideApplet, this, [this] { | ||
m_proxyInter->requestSetAppletVisible(this, CLIPBOARD_KEY, false); | ||
}); | ||
QDBusConnection::sessionBus().connect("com.deepin.dde.Clipboard", "/com/deepin/dde/Clipboard", "com.deepin.dde.Clipboard", "clipboardVisibleChanged", this, SLOT(onClipboardVisibleChanged(bool))); | ||
} | ||
|
||
QWidget *ClipboardPlugin::itemWidget(const QString &itemKey) | ||
{ | ||
if (itemKey == CLIPBOARD_KEY) { | ||
return m_item; | ||
} | ||
|
||
if (itemKey == Dock::QUICK_ITEM_KEY) { | ||
return m_quickPanelWidget; | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
QWidget *ClipboardPlugin::itemTipsWidget(const QString &itemKey) | ||
{ | ||
if (itemKey == CLIPBOARD_KEY) { | ||
return m_item->tipsWidget(); | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
QWidget *ClipboardPlugin::itemPopupApplet(const QString &itemKey) | ||
{ | ||
return nullptr; | ||
} | ||
|
||
const QString ClipboardPlugin::itemContextMenu(const QString &itemKey) | ||
{ | ||
if (itemKey == CLIPBOARD_KEY) { | ||
return m_item->contextMenu(); | ||
} | ||
|
||
return QString(); | ||
} | ||
|
||
void ClipboardPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) | ||
{ | ||
if (itemKey == CLIPBOARD_KEY) { | ||
m_item->invokeMenuItem(menuId, checked); | ||
} | ||
} | ||
|
||
int ClipboardPlugin::itemSortKey(const QString &itemKey) | ||
{ | ||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient); | ||
|
||
return m_proxyInter->getValue(this, key, -1).toInt(); | ||
} | ||
|
||
void ClipboardPlugin::setSortKey(const QString &itemKey, const int order) | ||
{ | ||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient); | ||
|
||
m_proxyInter->saveValue(this, key, order); | ||
} | ||
|
||
void ClipboardPlugin::refreshIcon(const QString &itemKey) | ||
{ | ||
if (itemKey == CLIPBOARD_KEY) { | ||
m_item->refreshIcon(); | ||
} | ||
} | ||
|
||
const QString ClipboardPlugin::itemCommand(const QString &itemKey) | ||
{ | ||
Q_UNUSED(itemKey); | ||
return QString("dbus-send --session --print-reply --dest=org.deepin.dde.Clipboard1 /org/deepin/dde/Clipboard1 org.deepin.dde.Clipboard1.Toggle"); | ||
} | ||
|
||
void ClipboardPlugin::onClipboardVisibleChanged(bool visible) | ||
{ | ||
if (!m_messageCallback) { | ||
qWarning() << "Message callback function is nullptr"; | ||
return; | ||
} | ||
QJsonObject msg; | ||
msg[Dock::MSG_TYPE] = Dock::MSG_ITEM_ACTIVE_STATE; | ||
msg[Dock::MSG_DATA] = visible; | ||
QJsonDocument doc; | ||
doc.setObject(msg); | ||
m_messageCallback(this, doc.toJson()); | ||
} |
Oops, something went wrong.