1
// This file is part of QtUbuntu, a set of Qt components for Ubuntu.
2
// Copyright © 2013 Canonical Ltd.
4
// This program is free software: you can redistribute it and/or modify it under
5
// the terms of the GNU General Public License version 3, as published by
6
// the Free Software Foundation.
8
// This program is distributed in the hope that it will be useful, but WITHOUT
9
// ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10
// SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
// General Public License for more details.
13
// You should have received a copy of the GNU General Public License
14
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
#include <QtGui/QGuiApplication>
17
#include <QtGui/QClipboard>
20
enum Operation { kNone, kCopy, kPaste };
24
"Usage: clipboard [options]\n\n"
26
" -c or --copy \"text\" ... Copy text to clipboard\n"
27
" -p or --paste ... Paste text from clipboard\n"
28
" -h or --help ... Show that help\n");
31
int main(int argc, char* argv[]) {
32
Operation operation = kNone;
35
for (int i = 1; i < argc; ++i) {
36
const QString kArg = QString::fromLatin1(argv[i]).toLower();
37
if ((kArg == QLatin1String("-c") || kArg == QLatin1String("--copy")) && i + 1 < argc) {
39
text = QString::fromLatin1(argv[++i]);
40
} else if (kArg == QLatin1String("-p") || kArg == QLatin1String("--paste")) {
42
} else if (kArg == QLatin1String("-h") || kArg == QLatin1String("--help")) {
47
if (operation == kNone) {
52
QGuiApplication app(argc, argv);
53
if (operation == kCopy) {
54
QGuiApplication::clipboard()->setText(text);
55
fprintf(stdout, "Copied: \"%s\"\n", text.toLatin1().data());
57
fprintf(stdout, "Pasted: \"%s\"\n", QGuiApplication::clipboard()->text().toLatin1().data());