feat: add clipboard

pull/39/head
kate 4 years ago
parent 97fc1bdffe
commit 5290885d1c

@ -33,5 +33,6 @@ add_subdirectory(cupdatecursor)
add_subdirectory(gmenuproxy)
add_subdirectory(notificationd)
add_subdirectory(sddm-helper)
add_subdirectory(clipboard)
install(FILES cutefish DESTINATION /etc/ COMPONENT Runtime)

@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.14)
project(cutefish-clipboard LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
add_executable(cutefish-clipboard
main.cpp
clipboard.cpp
)
target_link_libraries(cutefish-clipboard
Qt5::Core
Qt5::Gui
Qt5::Widgets
)
install(TARGETS cutefish-clipboard DESTINATION ${CMAKE_INSTALL_BINDIR})

@ -0,0 +1,71 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Kate Leet <kate@cutefishos.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "clipboard.h"
#include <QApplication>
#include <QMimeData>
#include <QPixmap>
#include <QDebug>
#include <QBuffer>
Clipboard::Clipboard(QObject *parent)
: QObject(parent)
, m_qtClipboard(qApp->clipboard())
{
connect(m_qtClipboard, &QClipboard::dataChanged, this, &Clipboard::onDataChanged);
}
void Clipboard::onDataChanged()
{
const QMimeData *mimeData = m_qtClipboard->mimeData();
if (mimeData->formats().isEmpty())
return;
if (mimeData->hasFormat("application/x-cutefish-clipboard") &&
mimeData->data("application/x-cutefish-clipboard") == "1")
return;
QByteArray timeStamp = mimeData->data("TIMESTAMP");
QMimeData *newMimeData = new QMimeData;
if (mimeData->hasImage()) {
QPixmap srcPix = m_qtClipboard->pixmap();
QByteArray bArray;
QBuffer buffer(&bArray);
buffer.open(QIODevice::WriteOnly);
srcPix.save(&buffer);
newMimeData->setImageData(srcPix);
newMimeData->setData("TIMESTAMP", timeStamp);
} else {
for (const QString &key : mimeData->formats()) {
newMimeData->setData(key, mimeData->data(key));
}
}
// cutefish flag.
newMimeData->setData("application/x-cutefish-clipboard", QByteArray("1"));
m_qtClipboard->setMimeData(newMimeData);
}

@ -0,0 +1,40 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Kate Leet <kate@cutefishos.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef CLIPBOARD_H
#define CLIPBOARD_H
#include <QObject>
#include <QClipboard>
class Clipboard : public QObject
{
Q_OBJECT
public:
explicit Clipboard(QObject *parent = nullptr);
private slots:
void onDataChanged();
private:
QClipboard *m_qtClipboard;
};
#endif // CLIPBOARD_H

@ -0,0 +1,30 @@
/*
* Copyright (C) 2021 CutefishOS Team.
*
* Author: Kate Leet <kate@cutefishos.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <QApplication>
#include "clipboard.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Clipboard clipboard;
return a.exec();
}

@ -366,9 +366,15 @@ void Application::createConfigDirectory()
void Application::updateUserDirs()
{
QProcess p;
p.start("xdg-user-dirs-update", QStringList());
p.waitForFinished(-1);
// bool isCutefishOS = QFile::exists("/etc/cutefishos");
// if (!isCutefishOS)
// return;
// QProcess p;
// p.setEnvironment(QStringList() << "LC_ALL=C");
// p.start("xdg-user-dirs-update", QStringList() << "--force");
// p.waitForFinished(-1);
}
int Application::runSync(const QString &program, const QStringList &args, const QStringList &env)

@ -120,6 +120,7 @@ void ProcessManager::startDesktopProcess()
list << qMakePair(QString("cutefish-filemanager"), QStringList("--desktop"));
list << qMakePair(QString("cutefish-launcher"), QStringList());
list << qMakePair(QString("cutefish-powerman"), QStringList());
list << qMakePair(QString("cutefish-clipboard"), QStringList());
// For CutefishOS.
if (QFile("/usr/bin/cutefish-welcome").exists() &&

Loading…
Cancel
Save