1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * cafe-color.c: CAFE color selection tool
 *
 * Copyright (C) 2014 Stefano Karapetsas
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * Authors:
 *  Stefano Karapetsas <stefano@karapetsas.com>
 */

#include <config.h>
#include <ctk/ctk.h>
#include <glib/gi18n.h>
#include <libcafe-desktop/cafe-colorseldialog.h>
#include <libcafe-desktop/cafe-colorsel.h>

#define cafe_gettext(package, locale, codeset) \
    bindtextdomain(package, locale); \
    bind_textdomain_codeset(package, codeset); \
    textdomain(package);

gboolean
copy_color (CtkWidget                *widget G_GNUC_UNUSED,<--- The function 'copy_color' should have static linkage since it is not used outside of its translation unit.
	    CdkEvent                 *event G_GNUC_UNUSED,
	    CafeColorSelectionDialog *color_dialog)
{
    CdkColor color;
    gchar *color_string;

    cafe_color_selection_get_current_color (CAFE_COLOR_SELECTION (color_dialog->colorsel), &color);
    g_object_get (color_dialog->colorsel, "hex-string", &color_string, NULL);

    ctk_clipboard_set_text (ctk_clipboard_get (CDK_SELECTION_CLIPBOARD), color_string, -1);

    g_free (color_string);
    return 0;
}

int
main (int argc, char **argv)
{
    CtkWidget *color_dialog = NULL;
    CtkWidget *color_selection;
    CtkWidget *widget;

    cafe_gettext (GETTEXT_PACKAGE, LOCALE_DIR, "UTF-8");

    /* initialize CTK+ */
    ctk_init (&argc, &argv);
    ctk_window_set_default_icon_name ("ctk-select-color");

    color_dialog = cafe_color_selection_dialog_new (_("CAFE Color Selection"));
    color_selection = CAFE_COLOR_SELECTION_DIALOG (color_dialog)->colorsel;
    cafe_color_selection_set_has_palette (CAFE_COLOR_SELECTION (color_selection), TRUE);

    /* quit signal */
    g_signal_connect (color_dialog, "destroy", ctk_main_quit, NULL);

    widget = ctk_button_new_from_stock (CTK_STOCK_COPY);
    ctk_container_add (CTK_CONTAINER (ctk_dialog_get_action_area (CTK_DIALOG (color_dialog))), widget);
    g_signal_connect (widget, "button-release-event", G_CALLBACK (copy_color), color_dialog);

    widget = ctk_button_new_from_stock (CTK_STOCK_CLOSE);
    ctk_container_add (CTK_CONTAINER (ctk_dialog_get_action_area (CTK_DIALOG (color_dialog))), widget);
    g_signal_connect (widget, "button-release-event", ctk_main_quit, NULL);

    ctk_widget_show_all (color_dialog);
    ctk_widget_hide (CAFE_COLOR_SELECTION_DIALOG (color_dialog)->ok_button);
    ctk_widget_hide (CAFE_COLOR_SELECTION_DIALOG (color_dialog)->cancel_button);
    ctk_widget_hide (CAFE_COLOR_SELECTION_DIALOG (color_dialog)->help_button);

    g_object_set (ctk_settings_get_default (), "ctk-button-images", TRUE, NULL);

    /* start application */
    ctk_main ();
    return 0;
}