Imported Upstream version 0.6.2.17
[psensor-pkg-debian.git] / src / ui_color.c
1 /*
2  * Copyright (C) 2010-2012 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19 #include <gtk/gtk.h>
20
21 #include "ui_color.h"
22
23 int ui_change_color(const char *title, struct color *col)
24 {
25         GdkColor color;
26         GtkColorSelection *colorsel;
27         int res;
28         GtkColorSelectionDialog *colordlg;
29
30         color.red = col->red;
31         color.green = col->green;
32         color.blue = col->blue;
33
34         colordlg = GTK_COLOR_SELECTION_DIALOG
35                 (gtk_color_selection_dialog_new(title));
36
37         colorsel = GTK_COLOR_SELECTION
38                 (gtk_color_selection_dialog_get_color_selection(colordlg));
39
40         gtk_color_selection_set_current_color(colorsel, &color);
41
42         res = gtk_dialog_run(GTK_DIALOG(colordlg));
43
44         if (res == GTK_RESPONSE_OK) {
45                 gtk_color_selection_get_current_color(colorsel, &color);
46
47                 color_set(col, color.red, color.green, color.blue);
48         }
49
50         gtk_widget_destroy(GTK_WIDGET(colordlg));
51
52         return res == GTK_RESPONSE_OK;
53 }