~gerboland/qtubuntu/devicePixelRatio

« back to all changes in this revision

Viewing changes to tests/clipboard/clipboard.cc

  • Committer: Daniel d'Andrada
  • Date: 2015-08-06 16:36:57 UTC
  • mto: This revision was merged to the branch mainline in revision 278.
  • Revision ID: daniel.dandrada@canonical.com-20150806163657-vos0w93miy9b6a1r
Remove unneeded dependencies from debian/control and ancient manual tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// This file is part of QtUbuntu, a set of Qt components for Ubuntu.
2
 
// Copyright © 2013 Canonical Ltd.
3
 
//
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.
7
 
//
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.
12
 
//
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/>.
15
 
 
16
 
#include <QtGui/QGuiApplication>
17
 
#include <QtGui/QClipboard>
18
 
#include <cstdio>
19
 
 
20
 
enum Operation { kNone, kCopy, kPaste };
21
 
 
22
 
static void usage() {
23
 
  fprintf(stdout,
24
 
          "Usage: clipboard [options]\n\n"
25
 
          "  Options:\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");
29
 
}
30
 
 
31
 
int main(int argc, char* argv[]) {
32
 
  Operation operation = kNone;
33
 
  QString text;
34
 
 
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) {
38
 
      operation = kCopy;
39
 
      text = QString::fromLatin1(argv[++i]);
40
 
    } else if (kArg == QLatin1String("-p") || kArg == QLatin1String("--paste")) {
41
 
      operation = kPaste;
42
 
    } else if (kArg == QLatin1String("-h") || kArg == QLatin1String("--help")) {
43
 
      usage();
44
 
      return 1;
45
 
    }
46
 
  }
47
 
  if (operation == kNone) {
48
 
    usage();
49
 
    return 1;
50
 
  }
51
 
 
52
 
  QGuiApplication app(argc, argv);
53
 
  if (operation == kCopy) {
54
 
    QGuiApplication::clipboard()->setText(text);
55
 
    fprintf(stdout, "Copied: \"%s\"\n", text.toLatin1().data());
56
 
  } else {
57
 
    fprintf(stdout, "Pasted: \"%s\"\n", QGuiApplication::clipboard()->text().toLatin1().data());
58
 
  }
59
 
 
60
 
  return 0;
61
 
}