Skip to content

Commit

Permalink
chore: add the dde-clipboard plugin
Browse files Browse the repository at this point in the history
add the dde-clipboard plugin

Log:
  • Loading branch information
wangfei authored and deepin-bot[bot] committed Oct 31, 2024
1 parent d7dc745 commit 8f21399
Show file tree
Hide file tree
Showing 23 changed files with 1,099 additions and 19 deletions.
36 changes: 36 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ endif ()
find_package(PkgConfig REQUIRED)
find_package(Dtk COMPONENTS Widget Core REQUIRED)
find_package(Qt5 COMPONENTS Core Gui Widgets DBus Test Concurrent REQUIRED)
find_package(DdeTrayLoader REQUIRED)

find_package(ECM REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
Expand Down Expand Up @@ -246,3 +247,38 @@ target_link_libraries(${UT_BIN_NAME} PRIVATE
-lgcov
-lgtest
)

#--------------------------dock-plugin---------------------------
set(PLUGIN_NAME dock-clipboard-plugin)

file(GLOB_RECURSE SRCS
"dock-clipboard-plugin/*.h"
"dock-clipboard-plugin/*.cpp"
"dock-clipboard-plugin/widget/*.h"
"dock-clipboard-plugin/widget/*.cpp"
)

add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
add_library(${PLUGIN_NAME} SHARED ${SRCS} dock-clipboard-plugin/resources/clipboard.qrc)
target_include_directories(${PLUGIN_NAME} PUBLIC
${DtkWidget_INCLUDE_DIRS}
${DtkCore_INCLUDE_DIRS}
${OBJECT_BINARY_DIR}
${DDE_DOCK_INCLUDE_DIR}
${QGSettings_INCLUDE_DIRS}
${DFrameworkDBus_INCLUDE_DIRS}
dock-clipboard-plugin/widget/
)
target_link_libraries(${PLUGIN_NAME} PRIVATE
${DtkWidget_LIBRARIES}
${QGSettings_LIBRARIES}
${DFrameworkDBus_LIBRARIES}
${Qt5DBus_LIBRARIES}
${Qt5Widgets_LIBRARIES}
${Qt5Svg_LIBRARIES}
${DtkCore_LIBRARIES}
)

# 设置执行 make install 时哪个目标应该被 install 到哪个位置
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins)
install(FILES "dock-clipboard-plugin/resources/clipboard.svg" DESTINATION share/dde-dock/icons/dcc-setting)
2 changes: 1 addition & 1 deletion dde-clipboard/dbus/iteminfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <QDateTime>
#include <QUrl>

#include "constants.h"
#include "dde-clipboard/constants.h"

enum DataType {
Unknown,
Expand Down
3 changes: 2 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Build-Depends: debhelper (>= 8.0.0),
extra-cmake-modules,
libdwayland-dev,
libkf5wayland-dev,
systemd
systemd,
dde-tray-loader-dev (>= 0.0.11)
Standards-Version: 3.9.5
Homepage: https://github.com/linuxdeepin/dde-clipboard

Expand Down
3 changes: 3 additions & 0 deletions dock-clipboard-plugin/clipboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"api": "2.0.0"
}
37 changes: 37 additions & 0 deletions dock-clipboard-plugin/clipboardcontroller.h
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.Clipboard1",
"/org/deepin/dde/Clipboard1",
"org.deepin.dde.Clipboard1",
QDBusConnection::sessionBus());
if (interface.isValid()) {
interface.call("Toggle");
}
}
};

#endif
107 changes: 107 additions & 0 deletions dock-clipboard-plugin/clipboarditem.cpp
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();
}
40 changes: 40 additions & 0 deletions dock-clipboard-plugin/clipboarditem.h
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
Loading

0 comments on commit 8f21399

Please sign in to comment.