diff --git a/CMakeLists.txt b/CMakeLists.txt index 86acc9e..9fef2c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/clipboard/CMakeLists.txt b/clipboard/CMakeLists.txt new file mode 100644 index 0000000..b1f2826 --- /dev/null +++ b/clipboard/CMakeLists.txt @@ -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}) \ No newline at end of file diff --git a/clipboard/clipboard.cpp b/clipboard/clipboard.cpp new file mode 100644 index 0000000..9895044 --- /dev/null +++ b/clipboard/clipboard.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Kate Leet + * + * 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 . + */ + +#include "clipboard.h" + +#include +#include +#include +#include + +#include + +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); +} diff --git a/clipboard/clipboard.h b/clipboard/clipboard.h new file mode 100644 index 0000000..51676ef --- /dev/null +++ b/clipboard/clipboard.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Kate Leet + * + * 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 . + */ + +#ifndef CLIPBOARD_H +#define CLIPBOARD_H + +#include +#include + +class Clipboard : public QObject +{ + Q_OBJECT + +public: + explicit Clipboard(QObject *parent = nullptr); + +private slots: + void onDataChanged(); + +private: + QClipboard *m_qtClipboard; +}; + +#endif // CLIPBOARD_H diff --git a/clipboard/main.cpp b/clipboard/main.cpp new file mode 100644 index 0000000..4759269 --- /dev/null +++ b/clipboard/main.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2021 CutefishOS Team. + * + * Author: Kate Leet + * + * 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 . + */ + +#include +#include "clipboard.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + Clipboard clipboard; + + return a.exec(); +} diff --git a/session/application.cpp b/session/application.cpp index 70ec9cd..51be657 100644 --- a/session/application.cpp +++ b/session/application.cpp @@ -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) diff --git a/session/processmanager.cpp b/session/processmanager.cpp index 0e17f4a..6c15187 100644 --- a/session/processmanager.cpp +++ b/session/processmanager.cpp @@ -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() &&