Application that allows to show clipboard contents and its MIME type?

Use xclip:

xclip -o -t TARGETS

to see all the available types. For example:

  1. copy something from you web browser
  2. investigate available types
$ xclip -o -t TARGETS
TIMESTAMP
TARGETS
MULTIPLE
text/html
text/_moz_htmlcontext
text/_moz_htmlinfo
UTF8_STRING
COMPOUND_TEXT
TEXT
STRING
text/x-moz-url-priv
  1. get the contents for the one you're interested in: xclip -o -t text/html

OK, I've actually written some code that does what I need. Good thing it's pretty easy in Qt.

Building info is at the bottom of this post.

xclipshow.cpp:

#include <QApplication>
#include <QTimer>
#include <QClipboard>
#include <QMimeData>
#include <QDebug>
#include <QStringList>

class App: public QObject {
    Q_OBJECT
private:
    void main();
public:
    App(): QObject() { }
public slots:
    void qtmain() { main(); emit finished(); }
signals:
    void finished();
};

void App::main() {
    QClipboard *clip = QApplication::clipboard();

    for(QString& formatName: clip->mimeData()->formats()) {
        std::string s;
        s = formatName.toStdString();

        QByteArray arr = clip->mimeData()->data(formatName);
        printf("name=%s, size=%d: ", s.c_str(), arr.size());

        for(int i = 0; i < arr.size(); i++) {
            printf("%02x ", (unsigned char) arr.at(i));
        }

        printf("\n");
    }
}

int main(int argc, char **argv) {
    QApplication app(argc, argv);
    App *task = new App();
    QObject::connect(task, SIGNAL(finished()), & app, SLOT(quit()));
    QTimer::singleShot(0, task, SLOT(qtmain()));
    return app.exec();
}

#include "xclipshow.moc"

CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)
project(xclipshow)
find_package(Qt5Widgets)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(SRC
    xclipshow.cpp)

add_definitions(-std=c++11)
add_executable(xclipshow ${SRC})
qt5_use_modules(xclipshow Widgets Core)

Building info as requested in the comment by @slm: it depends on the system you're using. This code needs Qt5 and CMake to compile. If you have both, all you need to do is to run:

BUILD_DIR=<path to an empty temporary dir, which will contain the executable file>
SRC_DIR=<path to the directory which contains xclipshow.cpp>

$ cd $BUILD_DIR
$ cmake $SRC_DIR
$ make

or 'gmake' if you're on FreeBSD, or 'mingw32-make' if you're on Windows, etc.

If you don't have Qt5 or CMake, you can try to get away with Qt4 and manual compilation:

$ moc xclipshow.cpp > xclipshow.moc
$ g++ xclipshow.cpp -o xclipshow `pkg-config --cflags --libs QtGui` -I. --std=c++11

If you're getting information about invalid --std=c++11 option, try --std=c++0x instead, and consider upgrading your compiler ;).

Tags:

X11

Clipboard