Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import from klipper/plain text #1839

Closed
DUOLabs333 opened this issue Dec 3, 2021 · 1 comment
Closed

Import from klipper/plain text #1839

DUOLabs333 opened this issue Dec 3, 2021 · 1 comment
Labels
feature New feature request

Comments

@DUOLabs333
Copy link

Is your feature request related to a problem? Please describe.
Since #1692 got fixed, I want to move back to copyq from klipper (KDE's clipboard).

Describe the solution you'd like
So, is there a way to import from klipper directly? klipper saves its history as a .lst file, so maybe you can import from there? With a bit of work, you can also export klipper history is a plain text file, so maybe that could work as well (you would obviously lose date information, but order should still be preserved).

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@DUOLabs333 DUOLabs333 added the feature New feature request label Dec 3, 2021
@hluk
Copy link
Owner

hluk commented Dec 4, 2021

The history lst file seems to be some internal data format of Klipper. I'm not going to support this in CopyQ.

I took a quick peek at the implementation and to parse the file you would need to use Qt framework. Below is a simple script to import the data file with Python and PyQt5 library (it does not support import "url" and "image" type of objects, only simple text). Argument is path to the .lst file:

#!/usr/bin/env python3
import sys
from subprocess import PIPE, Popen

from PyQt5.QtCore import QByteArray, QDataStream, QFile, QIODevice

COMMAND = ["copyq", "tab", "klipper", "add", "-"]

filename = sys.argv[1]
f = QFile(filename)
if not f.open(QFile.ReadOnly):
    raise RuntimeError(f"Failed to open file {filename}: {f.errorString()}")

try:
    file_stream = QDataStream(f)
    crc = file_stream.readUInt32()
    print(f"CRC: {crc}")
    data = QByteArray()
    file_stream >> data
finally:
    f.close()

history_stream = QDataStream(data, QIODevice.ReadOnly)
version = history_stream.readString()
print(f"version: {version}")

while True:
    type_ = history_stream.readQString()
    if not type_:
        break

    if type_ == "string":
        text = history_stream.readQString()
        print(f"Adding: {text}")
        with Popen(COMMAND, stdin=PIPE) as p:
            p.stdin.write(text.encode("utf-8"))
            p.stdin.close()
    else:
        print(f"WARNING: Type {type_} is not supported")

@hluk hluk closed this as completed Dec 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

2 participants