Skip to content

Commit 4da4d7a

Browse files
committed
#3371 webappclientservice: add sending of clipboard content as text
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 89121b9 commit 4da4d7a

File tree

6 files changed

+52
-2
lines changed

6 files changed

+52
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
## 25.10.4
44

5-
- Sending of HTML clipboard content was fixed (for [#3371](https://github.com/pbek/QOwnNotes/issues/3371))
5+
- There now is a menu action to the **send clipboard as text** to another instance
6+
of QOwnNotes (for [#3371](https://github.com/pbek/QOwnNotes/issues/3371))
7+
- **Sending of HTML clipboard content** to another instance of QOwnNotes was fixed
8+
(for [#3371](https://github.com/pbek/QOwnNotes/issues/3371))
69
- A PPA for Ubuntu 26.04 (Resolute Raccoon) was added
710
- See [Install on Ubuntu](https://www.qownnotes.org/installation/ubuntu.html)
811
for more information on how to install the PPA

src/mainwindow.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,10 @@ void MainWindow::readSettingsFromSettingsDialog(const bool isAppLaunch) {
27602760
}
27612761

27622762
initGlobalKeyboardShortcuts();
2763-
ui->actionSend_clipboard->setEnabled(Utils::Misc::isWebAppSupportEnabled());
2763+
2764+
const bool isWebAppSupportEnabled = Utils::Misc::isWebAppSupportEnabled();
2765+
ui->actionSend_clipboard->setEnabled(isWebAppSupportEnabled);
2766+
ui->actionSend_clipboard_as_text->setEnabled(isWebAppSupportEnabled);
27642767
}
27652768

27662769
/**
@@ -6342,6 +6345,7 @@ void MainWindow::generateSystemTrayContextMenu() {
63426345

63436346
menu->addSeparator();
63446347
menu->addAction(ui->actionSend_clipboard);
6348+
menu->addAction(ui->actionSend_clipboard_as_text);
63456349
menu->addSeparator();
63466350

63476351
const QList<NoteFolder> noteFolders = NoteFolder::fetchAll();
@@ -12508,3 +12512,19 @@ void MainWindow::on_actionSend_clipboard_triggered() {
1250812512
}
1250912513
});
1251012514
}
12515+
12516+
void MainWindow::on_actionSend_clipboard_as_text_triggered() {
12517+
// We need to show the window because on some systems the clipboard
12518+
// can't be accessed if the app is not focused
12519+
showWindow();
12520+
12521+
// We need a delay because otherwise the clipboard can't be properly accessed on some systems
12522+
QTimer::singleShot(1000, this, [this] {
12523+
if (_webAppClientService->sendClipboardAsText()) {
12524+
showStatusBarMessage(tr("Clipboard text sent successfully"), QStringLiteral(""),
12525+
3000);
12526+
} else {
12527+
showStatusBarMessage(tr("Failed to send clipboard text"), QStringLiteral("⚠️"), 5000);
12528+
}
12529+
});
12530+
}

src/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ class MainWindow : public QMainWindow {
734734

735735
void on_actionSend_clipboard_triggered();
736736

737+
void on_actionSend_clipboard_as_text_triggered();
738+
737739
public:
738740
/** Settings access **/
739741
static bool isInDistractionFreeMode();

src/mainwindow.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ li.checked::marker { content: &quot;\2612&quot;; }
12071207
<addaction name="actionManage_stored_images"/>
12081208
<addaction name="actionManage_stored_attachments"/>
12091209
<addaction name="actionSend_clipboard"/>
1210+
<addaction name="actionSend_clipboard_as_text"/>
12101211
<addaction name="menuExtra"/>
12111212
<addaction name="separator"/>
12121213
<addaction name="actionCheck_spelling"/>
@@ -2892,6 +2893,15 @@ li.checked::marker { content: &quot;\2612&quot;; }
28922893
<string>Send clipboard</string>
28932894
</property>
28942895
</action>
2896+
<action name="actionSend_clipboard_as_text">
2897+
<property name="icon">
2898+
<iconset theme="document-share" resource="breeze-qownnotes.qrc">
2899+
<normaloff>:/icons/breeze-qownnotes/16x16/document-share.svg</normaloff>:/icons/breeze-qownnotes/16x16/document-share.svg</iconset>
2900+
</property>
2901+
<property name="text">
2902+
<string>Send clipboard as text</string>
2903+
</property>
2904+
</action>
28952905
</widget>
28962906
<layoutdefault spacing="6" margin="11"/>
28972907
<customwidgets>

src/services/webappclientservice.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <QSslError>
2929
#include <QWebSocket>
3030
#include <QtWebSockets>
31+
#include <memory>
3132

3233
#include "metricsservice.h"
3334
#include "services/settingsservice.h"
@@ -77,6 +78,7 @@ void WebAppClientService::close() {
7778
*/
7879
bool WebAppClientService::keepClipboard() {
7980
QClipboard *clipboard = QApplication::clipboard();
81+
_clipboardTextContent = clipboard->text();
8082
const QMimeData *mimeData = clipboard->mimeData();
8183
const QPixmap pixmap = clipboard->pixmap();
8284
if (!pixmap.isNull()) {
@@ -113,6 +115,17 @@ bool WebAppClientService::sendClipboard() const {
113115
return true;
114116
}
115117

118+
bool WebAppClientService::sendClipboardAsText() const {
119+
if (_clipboardTextContent == "") {
120+
return false;
121+
}
122+
123+
qDebug() << __func__ << "_clipboardTextContent: " << _clipboardTextContent;
124+
125+
sendInsertIntoClipboard(QStringLiteral("text/plain"), _clipboardTextContent);
126+
return true;
127+
}
128+
116129
void WebAppClientService::initClipboardService() {
117130
QClipboard *clipboard = QApplication::clipboard();
118131

src/services/webappclientservice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class WebAppClientService : public QObject {
3636
void open();
3737
void close();
3838
bool sendClipboard() const;
39+
bool sendClipboardAsText() const;
3940

4041
private slots:
4142
void onConnected();
@@ -49,6 +50,7 @@ class WebAppClientService : public QObject {
4950
QWebSocket *_webSocket{};
5051
QString _clipboardMimeType;
5152
QString _clipboardContent;
53+
QString _clipboardTextContent;
5254
QString _url;
5355
const int _heartbeatTime = 600000; // heartbeat data transmission time interval in ms
5456
const int _reconnectHeartbeatTimerCount =

0 commit comments

Comments
 (0)