Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / tools / gtk_clipboard_dump / gtk_clipboard_dump.cc
blobc96ee0083693da327190e572246883d8bf7be3a4
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <gtk/gtk.h>
6 #include <stdio.h>
7 #include <string.h>
9 namespace {
11 void PrintClipboardContents(GtkClipboard* clip) {
12 GdkAtom* targets;
13 int num_targets = 0;
15 // This call is bugged, the cache it checks is often stale; see
16 // <http://bugzilla.gnome.org/show_bug.cgi?id=557315>.
17 // gtk_clipboard_wait_for_targets(clip, &targets, &num_targets);
19 GtkSelectionData* target_data =
20 gtk_clipboard_wait_for_contents(clip,
21 gdk_atom_intern("TARGETS", false));
22 if (!target_data) {
23 printf("failed to get the contents!\n");
24 return;
27 gtk_selection_data_get_targets(target_data, &targets, &num_targets);
29 printf("%d available targets:\n---------------\n", num_targets);
31 for (int i = 0; i < num_targets; i++) {
32 printf(" [format: %s", gdk_atom_name(targets[i]));
33 GtkSelectionData* data = gtk_clipboard_wait_for_contents(clip, targets[i]);
34 if (!data) {
35 printf("]: NULL\n\n");
36 continue;
39 printf(" / length: %d / bits %d]: ", data->length, data->format);
41 if (strstr(gdk_atom_name(targets[i]), "image")) {
42 printf("(image omitted)\n\n");
43 continue;
44 } else if (strstr(gdk_atom_name(targets[i]), "TIMESTAMP")) {
45 // TODO(estade): Print the time stamp in human readable format.
46 printf("(time omitted)\n\n");
47 continue;
50 for (int j = 0; j < data->length; j++) {
51 // Output data one byte at a time. Currently wide strings look
52 // pretty weird.
53 printf("%c", (data->data[j] == 0 ? '_' : data->data[j]));
55 printf("\n\n");
58 if (num_targets <= 0) {
59 printf("No targets advertised. Text is: ");
60 gchar* text = gtk_clipboard_wait_for_text(clip);
61 printf("%s\n", text ? text : "NULL");
62 g_free(text);
65 g_free(targets);
70 /* Small program to dump the contents of GTK's clipboards to the terminal.
71 * Feel free to add to it or improve formatting or whatnot.
73 int main(int argc, char* argv[]) {
74 gtk_init(&argc, &argv);
76 printf("Desktop clipboard\n");
77 PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
79 printf("X clipboard\n");
80 PrintClipboardContents(gtk_clipboard_get(GDK_SELECTION_PRIMARY));