[Goodies-commits] r5856 - xfce4-dict/trunk/lib
Enrico Troeger
enrico at xfce.org
Tue Oct 28 21:20:10 CET 2008
Author: enrico
Date: 2008-10-28 20:20:10 +0000 (Tue, 28 Oct 2008)
New Revision: 5856
Modified:
xfce4-dict/trunk/lib/common.c
xfce4-dict/trunk/lib/common.h
xfce4-dict/trunk/lib/dictd.c
xfce4-dict/trunk/lib/gui.c
xfce4-dict/trunk/lib/gui.h
xfce4-dict/trunk/lib/prefs.c
Log:
Make colours used for links and phonetics configurable.
Modified: xfce4-dict/trunk/lib/common.c
===================================================================
--- xfce4-dict/trunk/lib/common.c 2008-10-28 20:10:37 UTC (rev 5855)
+++ xfce4-dict/trunk/lib/common.c 2008-10-28 20:20:10 UTC (rev 5856)
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include <string.h>
+#include <math.h>
#include <gtk/gtk.h>
#include <libxfcegui4/libxfcegui4.h>
@@ -281,6 +282,32 @@
}
+static gdouble scale_round(gdouble val, gdouble factor)
+{
+ /*val = floor(val * factor + 0.5);*/
+ val = floor(val);
+ val = MAX(val, 0);
+ val = MIN(val, factor);
+
+ return val;
+}
+
+
+static gchar *get_hex_from_color(GdkColor *color)
+{
+ gchar *buffer = g_malloc0(9);
+
+ g_return_val_if_fail(color != NULL, NULL);
+
+ g_snprintf(buffer, 8, "#%02X%02X%02X",
+ (guint) (scale_round(color->red / 256, 255)),
+ (guint) (scale_round(color->green / 256, 255)),
+ (guint) (scale_round(color->blue / 256, 255)));
+
+ return buffer;
+}
+
+
void dict_read_rc_file(DictData *dd)
{
XfceRc *rc;
@@ -295,6 +322,8 @@
const gchar *spell_bin = "aspell";
const gchar *spell_dictionary = "en";
const gchar *geo = "-1;0;0;0;0;";
+ const gchar *link_color_str = "#0000ff";
+ const gchar *phon_color_str = "#006300";
if ((rc = xfce_rc_config_open(XFCE_RESOURCE_CONFIG, "xfce4-dict/xfce4-dict.rc", TRUE)) != NULL)
{
@@ -307,8 +336,10 @@
server = xfce_rc_read_entry(rc, "server", server);
dict = xfce_rc_read_entry(rc, "dict", dict);
spell_bin = xfce_rc_read_entry(rc, "spell_bin", spell_bin);
- spell_dictionary = xfce_rc_read_entry(rc, "spell_dictionary", spell_dictionary);
+ link_color_str = xfce_rc_read_entry(rc, "link_color", link_color_str);
+ phon_color_str = xfce_rc_read_entry(rc, "phonetic_color", phon_color_str);
+
geo = xfce_rc_read_entry(rc, "geometry", geo);
parse_geometry(dd, geo);
}
@@ -328,6 +359,11 @@
dd->spell_bin = g_strdup(spell_bin);
dd->spell_dictionary = g_strdup(spell_dictionary);
+ dd->link_color = g_new0(GdkColor, 1);
+ gdk_color_parse(link_color_str, dd->link_color);
+ dd->phon_color = g_new0(GdkColor, 1);
+ gdk_color_parse(phon_color_str, dd->phon_color);
+
xfce_rc_close(rc);
}
@@ -338,7 +374,7 @@
if ((rc = xfce_rc_config_open(XFCE_RESOURCE_CONFIG, "xfce4-dict/xfce4-dict.rc", FALSE)) != NULL)
{
- gchar geometry_string[128];
+ gchar *geometry_string, *link_color_str, *phon_color_str;
xfce_rc_write_int_entry(rc, "mode_in_use", dd->mode_in_use);
xfce_rc_write_int_entry(rc, "mode_default", dd->mode_default);
@@ -352,10 +388,19 @@
xfce_rc_write_entry(rc, "spell_bin", dd->spell_bin);
xfce_rc_write_entry(rc, "spell_dictionary", dd->spell_dictionary);
- g_snprintf(geometry_string, sizeof(geometry_string), "%d;%d;%d;%d;%d;",
+ link_color_str = get_hex_from_color(dd->link_color);
+ phon_color_str = get_hex_from_color(dd->phon_color);
+ xfce_rc_write_entry(rc, "link_color", link_color_str);
+ xfce_rc_write_entry(rc, "phonetic_color", phon_color_str);
+
+ geometry_string = g_strdup_printf("%d;%d;%d;%d;%d;",
dd->geometry[0], dd->geometry[1], dd->geometry[2], dd->geometry[3], dd->geometry[4]);
xfce_rc_write_entry(rc, "geometry", geometry_string);
+ g_free(link_color_str);
+ g_free(phon_color_str);
+ g_free(geometry_string);
+
xfce_rc_close(rc);
}
}
@@ -375,6 +420,9 @@
g_free(dd->web_url);
g_free(dd->spell_bin);
+ g_free(dd->link_color);
+ g_free(dd->phon_color);
+
if (dd->icon != NULL)
g_object_unref(dd->icon);
@@ -421,3 +469,4 @@
return dd;
}
+
Modified: xfce4-dict/trunk/lib/common.h
===================================================================
--- xfce4-dict/trunk/lib/common.h 2008-10-28 20:10:37 UTC (rev 5855)
+++ xfce4-dict/trunk/lib/common.h 2008-10-28 20:20:10 UTC (rev 5856)
@@ -55,13 +55,7 @@
SERVER_NOT_READY
};
-enum
-{
- COLOR_LINK,
- COLOR_PHONECTIC
-};
-
typedef struct
{
/* settings */
@@ -102,7 +96,12 @@
GtkWidget *main_textview;
GtkTextBuffer *main_textbuffer;
GtkTextIter textiter;
+ GtkTextTag *link_tag;
+ GtkTextTag *phon_tag;
GdkPixbuf *icon;
+
+ GdkColor *link_color;
+ GdkColor *phon_color;
} DictData;
Modified: xfce4-dict/trunk/lib/dictd.c
===================================================================
--- xfce4-dict/trunk/lib/dictd.c 2008-10-28 20:10:37 UTC (rev 5855)
+++ xfce4-dict/trunk/lib/dictd.c 2008-10-28 20:20:10 UTC (rev 5856)
@@ -168,7 +168,7 @@
tag = gtk_text_buffer_create_tag(dd->main_textbuffer, NULL,
"underline", PANGO_UNDERLINE_SINGLE,
- "foreground-gdk", dict_gui_get_color(dd, COLOR_LINK), NULL);
+ "foreground-gdk", dd->link_color, NULL);
g_object_set_data_full(G_OBJECT(tag), "link", g_strdup(link_str), g_free);
Modified: xfce4-dict/trunk/lib/gui.c
===================================================================
--- xfce4-dict/trunk/lib/gui.c 2008-10-28 20:10:37 UTC (rev 5855)
+++ xfce4-dict/trunk/lib/gui.c 2008-10-28 20:20:10 UTC (rev 5856)
@@ -445,23 +445,6 @@
}
-const GdkColor *dict_gui_get_color(DictData *dd, gint color)
-{
- /** TODO make colours (phonetic, link colour) configurable */
- static const GdkColor link_color = { 0, 0, 0, 0xeeee };
- static const GdkColor phon_color = { 0, 0, 0x6363, 0 };
-
- switch (color)
- {
- case COLOR_PHONECTIC:
- return &phon_color;
- case COLOR_LINK:
- return &link_color;
- }
- return NULL;
-}
-
-
void dict_gui_create_main_window(DictData *dd)
{
GtkWidget *main_box, *entry_box, *label_box;
@@ -572,14 +555,14 @@
"style", PANGO_STYLE_ITALIC,
"indent", 10,
"pixels-below-lines", 5, NULL);
- gtk_text_buffer_create_tag(dd->main_textbuffer,
+ dd->phon_tag = gtk_text_buffer_create_tag(dd->main_textbuffer,
"phonetic",
"style", PANGO_STYLE_ITALIC,
- "foreground-gdk", dict_gui_get_color(dd, COLOR_PHONECTIC), NULL);
- gtk_text_buffer_create_tag(dd->main_textbuffer,
+ "foreground-gdk", dd->phon_color, NULL);
+ dd->link_tag = gtk_text_buffer_create_tag(dd->main_textbuffer,
"link",
"underline", PANGO_UNDERLINE_SINGLE,
- "foreground-gdk", dict_gui_get_color(dd, COLOR_LINK), NULL);
+ "foreground-gdk", dd->link_color, NULL);
/* support for links (cross-references) for dictd responses */
{
Modified: xfce4-dict/trunk/lib/gui.h
===================================================================
--- xfce4-dict/trunk/lib/gui.h 2008-10-28 20:10:37 UTC (rev 5855)
+++ xfce4-dict/trunk/lib/gui.h 2008-10-28 20:20:10 UTC (rev 5856)
@@ -30,7 +30,6 @@
void dict_gui_show_main_window(DictData *dd);
void dict_gui_query_geometry(DictData *dd);
void dict_gui_finalize(DictData *dd);
-const GdkColor *dict_gui_get_color(DictData *dd, gint color);
const guint8 *dict_gui_get_icon_data(void);
Modified: xfce4-dict/trunk/lib/prefs.c
===================================================================
--- xfce4-dict/trunk/lib/prefs.c 2008-10-28 20:10:37 UTC (rev 5855)
+++ xfce4-dict/trunk/lib/prefs.c 2008-10-28 20:20:10 UTC (rev 5856)
@@ -185,6 +185,9 @@
dd->panel_entry_size = gtk_spin_button_get_value_as_int(
GTK_SPIN_BUTTON(g_object_get_data(G_OBJECT(dlg), "panel_entry_size_spinner")));
}
+ g_object_set(G_OBJECT(dd->link_tag), "foreground-gdk", dd->link_color, NULL);
+ g_object_set(G_OBJECT(dd->phon_tag), "foreground-gdk", dd->phon_color, NULL);
+
/* save settings */
dict_write_rc_file(dd);
@@ -243,6 +246,12 @@
}
+void color_set_cb(GtkColorButton *widget, GdkColor *color)
+{
+ gtk_color_button_get_color(widget, color);
+}
+
+
GtkWidget *dict_prefs_dialog_show(GtkWidget *parent, DictData *dd)
{
GtkWidget *dialog, *inner_vbox, *notebook, *notebook_vbox;
@@ -272,7 +281,7 @@
*/
#define PAGE_GENERAL /* only for navigation in Geany's symbol list ;-) */
{
- GtkWidget *radio_button, *label;
+ GtkWidget *radio_button, *label, *table, *color_link, *color_phon;
GSList *search_method;
notebook_vbox = gtk_vbox_new(FALSE, 2);
@@ -325,12 +334,52 @@
g_object_set_data(G_OBJECT(radio_button), "type", GINT_TO_POINTER(DICTMODE_LAST_USED));
g_signal_connect(G_OBJECT(radio_button), "toggled", G_CALLBACK(search_method_changed), dd);
+ label = gtk_label_new(_("<b>Colors:</b>"));
+ gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 1);
+ gtk_widget_show(label);
+ gtk_box_pack_start(GTK_BOX(inner_vbox), label, FALSE, FALSE, 5);
+
+ label1 = gtk_label_new(_("Link Color:"));
+ label2 = gtk_label_new(_("Phonectic Color:"));
+ color_link = gtk_color_button_new_with_color(dd->link_color);
+ color_phon = gtk_color_button_new_with_color(dd->phon_color);
+ g_signal_connect(color_link, "color-set", G_CALLBACK(color_set_cb), dd->link_color);
+ g_signal_connect(color_phon, "color-set", G_CALLBACK(color_set_cb), dd->phon_color);
+
+ table = gtk_table_new(2, 2, FALSE);
+ gtk_widget_show(table);
+ gtk_table_set_row_spacings(GTK_TABLE(table), 5);
+ gtk_table_set_col_spacings(GTK_TABLE(table), 5);
+
+ gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 5, 5);
+ gtk_misc_set_alignment(GTK_MISC(label1), 1, 0);
+
+ gtk_table_attach(GTK_TABLE(table), color_link, 1, 2, 0, 1,
+ (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
+ (GtkAttachOptions) (0), 5, 5);
+
+ gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 5, 0);
+ gtk_misc_set_alignment(GTK_MISC(label2), 1, 0);
+
+ gtk_table_attach(GTK_TABLE(table), color_phon, 1, 2, 1, 2,
+ (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
+ (GtkAttachOptions) (0), 5, 5);
+
+ gtk_widget_show_all(table);
+ gtk_box_pack_start(GTK_BOX(inner_vbox), table, FALSE, FALSE, 0);
+
+
/* show panel entry check box */
if (dd->is_plugin)
{
GtkWidget *pe_hbox, *panel_entry_size_label, *panel_entry_size_spinner, *check_panel_entry;
- label = gtk_label_new(_("<b>Panel text field:</b>"));
+ label = gtk_label_new(_("<b>Panel Text Field:</b>"));
gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
gtk_misc_set_alignment(GTK_MISC(label), 0, 1);
gtk_widget_show(label);
@@ -557,7 +606,7 @@
gtk_notebook_insert_page(GTK_NOTEBOOK(notebook),
notebook_vbox, gtk_label_new(_("Spell Check")), NOTEBOOK_PAGE_ASPELL);
- label1 = gtk_label_new_with_mnemonic(_("Aspell program:"));
+ label1 = gtk_label_new_with_mnemonic(_("Aspell Program:"));
gtk_widget_show(label1);
spell_entry = gtk_entry_new();
More information about the Goodies-commits
mailing list