pax_global_header00006660000000000000000000000064125337752430014525gustar00rootroot0000000000000052 comment=2d0f2bd6202c0d0a95e7ef5188cf61769257dd68 gkrellm-tz-0.8/000077500000000000000000000000001253377524300134645ustar00rootroot00000000000000gkrellm-tz-0.8/Makefile000066400000000000000000000034411253377524300151260ustar00rootroot00000000000000# Timezone plugin for GKrellM # Copyright (C) 2002--2012 Jiri Denemark # # This file is part of gkrellm-tz. # # gkrellm-tz 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # VERSION = "$(shell git describe --tags 2>/dev/null | sed 's/^v//')" ifeq ($(VERSION), "") VERSION = 0.8 endif GKRELLM_CFLAGS = $(shell pkg-config gkrellm --cflags) GKRELLM_LDFLAGS = $(shell pkg-config gkrellm --libs) CFLAGS = -fPIC -Wall -Werror -g $(GKRELLM_CFLAGS) -DVERSION=\"$(VERSION)\" LDFLAGS = -shared $(GKRELLM_LDFLAGS) OBJS = list.o config.o gkrellm-tz.o .PHONY: all clean install all: @echo "Making gkrellm-tz version $(VERSION)" @$(MAKE) --no-print-directory gkrellm-tz.so DEFAULT := 0 V_CC = $(V_CC_$(V)) V_CC_ = $(V_CC_$(DEFAULT)) V_CC_0 = @echo " CC " $@; V_LD = $(V_LD_$(V)) V_LD_ = $(V_LD_$(DEFAULT)) V_LD_0 = @echo " LD " $@; gkrellm-tz.so: $(OBJS) Makefile $(V_LD)$(CC) $(LDFLAGS) $(OBJS) -o $@ gkrellm-tz.o: gkrellm-tz.c $(patsubst %.o,%.h,$(OBJS)) Makefile features.h $(V_CC)$(CC) $(CFLAGS) -c $< -o $@ %.o: %.c %.h Makefile features.h $(V_CC)$(CC) $(CFLAGS) -c $< -o $@ install: clean all cp gkrellm-tz.so $$HOME/.gkrellm2/plugins/ clean: rm -f $(OBJS) gkrellm-tz.so gkrellm-tz-0.8/NEWS000066400000000000000000000021331253377524300141620ustar00rootroot00000000000000------------------------------------------------------------------------------ Notation: + a new feature was added - something was removed * code change F a bug was fixed o note ----------------------------------------------------------------------------- version 0.8 (2014-04-06) ======================== * Code and build process changes for better interoperability + Support pango markup in custom time format (Elliot Kendall) version 0.7 (2010-09-30) ======================== F SIGSEGV when edit boxes are empty and Add/Edit is pushed version 0.6 (2010-01-14) ======================== + GtkTooltip API is used for gtk+ >= 2.12 F tooltips handling F contact information version 0.5 (2007-11-20) ======================== F it didn't display correctly on gkrellm 2.2.7 -- the time panels had incorrect heights (thanks to Ian Langworth) F don't lose spaces at the beginning of format strings version 0.4 (2006-12-09) ======================== + customizable look (time format and alignment) version 0.3 (2006-11-19) ======================== o the first public release of gkrellm-tz gkrellm-tz-0.8/config.c000066400000000000000000000511731253377524300151040ustar00rootroot00000000000000/* * Plugin configuration. * Copyright (C) 2005--2010 Jiri Denemark * * This file is part of gkrellm-tz. * * gkrellm-tz 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** @file * Plugin configuration. * @author Jiri Denemark */ #include #include #include #include #include #include #include #include #include "list.h" #include "config.h" static gchar about_text[] = "gkrellm-tz " VERSION "\n" "GKrellM Timezone Plugin\n" "\n" "Copyright (C) 2005--2014\n" "\tJiri Denemark \n" "\tand contributors (see NEWS)\n" "http://mamuti.net/gkrellm/index.en.html\n" "\n" "Released under the GNU General Public Licence"; static gchar *info_text[] = { "GKrellM Timezone Plugin\n", "\n", "This plugin displays current time in several configurable timezones.\n", "\n", "Timezone Configuration\n", "Checkbox\n", "\tSpecifies whether current time for a particular timezone will actually be shown or not.\n", "Label\n", "\tA short description of a timezone. It is shown in a tooltip.\n", "Timezone\n", "\tTimezone identification as can be found under /usr/share/zoneinfo/.\n", "\tFor example, \"Europe/Prague\" or \"UTC\"\n", "\n", "Options Configuration\n", "Custom time format\n", "\t\"Short\" format string is used for displaying time in panels.\n", "\t\"Long\" format string is used for tooltips.\n", "\tSee strftime(3) or date(1) man pages for format string specification.\n", "\n", "Configured timezones are stored in ~/.gkrellm2/data/gkrellm-tz file.\n" }; static gchar *list_titles[] = { "", "Label", "Timezone" }; static struct tz_options options; static GtkWidget *entry_label; static GtkWidget *entry_tz; static GtkWidget *toggle_12h; static GtkWidget *toggle_sec; static GtkWidget *label_short; static GtkWidget *entry_short; static GtkWidget *label_long; static GtkWidget *entry_long; static GtkTreeSelection *sel_row; static GtkTreeIter sel_row_iter; static GtkListStore *list_store; static GtkTreeModel *treemodel; static void tz_reset_entries(void); static void tz_config_toggled(GtkCellRendererToggle *cell_renderer, gchar *path, gpointer user_data); static void tz_config_selected(GtkTreeSelection *selection, gpointer data); static void tz_config_add(GtkWidget *widget, gpointer data); static void tz_config_set(GtkWidget *widget, gpointer data); static void tz_config_delete(GtkWidget *widget, gpointer data); static void tz_config_up(GtkWidget *widget, gpointer data); static void tz_config_down(GtkWidget *widget, gpointer data); /* options callbacks */ static void tz_config_op_12h(GtkToggleButton *toggle, gpointer data); static void tz_config_op_seconds(GtkToggleButton *toggle, gpointer data); static void tz_config_op_custom(GtkToggleButton *toggle, gpointer data); static void tz_config_op_left(GtkToggleButton *toggle, gpointer data); static void tz_config_op_center(GtkToggleButton *toggle, gpointer data); static void tz_config_op_right(GtkToggleButton *toggle, gpointer data); void tz_config_apply(struct tz_plugin *plugin) { GtkTreeIter iter; gboolean enabled; gchar *entry[2]; struct tz_list_item *item; if (gtk_tree_model_get_iter_first(treemodel, &iter) == FALSE) return; do { gtk_tree_model_get(treemodel, &iter, 0, &enabled, 1, &entry[0], 2, &entry[1], -1); tz_list_add(plugin, enabled, entry[0], entry[1]); } while (gtk_tree_model_iter_next(treemodel, &iter) == TRUE); gtk_list_store_clear(list_store); for (item = plugin->first; item != NULL; item = item->next) { if (item->tz.enabled) enabled = TRUE; else enabled = FALSE; entry[0] = item->tz.label; entry[1] = item->tz.timezone; gtk_list_store_append(list_store, &iter); gtk_list_store_set(list_store, &iter, 0, enabled, 1, entry[0], 2, entry[1], -1); } if (plugin->options.format_short != NULL) { free(plugin->options.format_short); plugin->options.format_short = NULL; } if (plugin->options.format_long != NULL) { free(plugin->options.format_long); plugin->options.format_long = NULL; } plugin->options.twelve_hour = options.twelve_hour; plugin->options.seconds = options.seconds; plugin->options.custom = options.custom; if (options.custom) { plugin->options.format_short = strdup(gtk_entry_get_text(GTK_ENTRY(entry_short))); plugin->options.format_long = strdup(gtk_entry_get_text(GTK_ENTRY(entry_long))); } plugin->options.align = options.align; } static void tz_config_tz_list(GtkWidget *vbox, struct tz_plugin *plugin) { GtkWidget *scrolled; GtkWidget *tree; GtkTreeIter iter; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeSelection *select; gboolean enabled; gchar *buf[2]; struct tz_list_item *item; scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); list_store = gtk_list_store_new(3, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING); for (item = plugin->first; item != NULL; item = item->next) { if (item->tz.enabled) enabled = TRUE; else enabled = FALSE; buf[0] = item->tz.label; buf[1] = item->tz.timezone; gtk_list_store_append(list_store, &iter); gtk_list_store_set(list_store, &iter, 0, enabled, 1, buf[0], 2, buf[1], -1); } treemodel = GTK_TREE_MODEL(list_store); tree = gtk_tree_view_new_with_model(treemodel); renderer = gtk_cell_renderer_toggle_new(); column = gtk_tree_view_column_new_with_attributes(list_titles[0], renderer, "active", 0, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(tz_config_toggled), NULL); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(list_titles[1], renderer, "text", 1, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(list_titles[2], renderer, "text", 2, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); select = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); g_signal_connect(G_OBJECT(select), "changed", G_CALLBACK(tz_config_selected), NULL); gtk_container_add(GTK_CONTAINER(scrolled), tree); } static void tz_config_timezones(GtkWidget *vbox, struct tz_plugin *plugin) { GtkWidget *label; GtkWidget *hbox; GtkWidget *button; GtkWidget *table; table = gtk_table_new(2, 2, FALSE); gtk_table_set_col_spacing(GTK_TABLE(table), 0, 5); gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, TRUE, 0); /* Label */ label = gtk_label_new("Label"); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_SHRINK, 0, 0); entry_label = gtk_entry_new_with_max_length(MAX_LABEL_LENGTH); gtk_table_attach_defaults(GTK_TABLE(table), entry_label, 1, 2, 0, 1); /* Timezone */ label = gtk_label_new("Timezone"); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, GTK_SHRINK, 0, 0); entry_tz = gtk_entry_new_with_max_length(MAX_TIMEZONE_LENGTH); gtk_table_attach_defaults(GTK_TABLE(table), entry_tz, 1, 2, 1, 2); /* Action buttons */ hbox = gtk_hbutton_box_new(); gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_START); gtk_button_box_set_spacing(GTK_BUTTON_BOX(hbox), 5); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 5); button = gtk_button_new_from_stock(GTK_STOCK_ADD); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(tz_config_add), NULL); gtk_container_add(GTK_CONTAINER(hbox), button); button = gtk_button_new_from_stock(GTK_STOCK_EDIT); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(tz_config_set), NULL); gtk_container_add(GTK_CONTAINER(hbox), button); button = gtk_button_new_from_stock(GTK_STOCK_DELETE); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(tz_config_delete), NULL); gtk_container_add(GTK_CONTAINER(hbox), button); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); vbox = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); tz_config_tz_list(vbox, plugin); vbox = gtk_vbutton_box_new(); gtk_button_box_set_layout(GTK_BUTTON_BOX(vbox), GTK_BUTTONBOX_START); gtk_button_box_set_spacing(GTK_BUTTON_BOX(vbox), 5); gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, TRUE, 5); button = gtk_button_new_from_stock(GTK_STOCK_GO_UP); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(tz_config_up), NULL); gtk_container_add(GTK_CONTAINER(vbox), button); button = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(tz_config_down), NULL); gtk_container_add(GTK_CONTAINER(vbox), button); } static void tz_config_options(GtkWidget *vbox, struct tz_plugin *plugin) { GtkWidget *hbox; GtkWidget *bbox; GtkWidget *button; GtkWidget *label; GtkWidget *table; GtkWidget *entry; options = plugin->options; hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); /* Options checkboxes */ bbox = gtk_vbutton_box_new(); gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_START); gtk_box_pack_start(GTK_BOX(hbox), bbox, FALSE, FALSE, 0); button = gtk_check_button_new_with_label( "Display 12 hour instead of 24 hour time"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), options.twelve_hour); g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(tz_config_op_12h), NULL); gtk_container_add(GTK_CONTAINER(bbox), button); toggle_12h = button; button = gtk_check_button_new_with_label("Show seconds"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), options.seconds); g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(tz_config_op_seconds), NULL); gtk_container_add(GTK_CONTAINER(bbox), button); toggle_sec = button; /* Custom time formats */ button = gtk_check_button_new_with_label("Custom time format:"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), options.custom); gtk_container_add(GTK_CONTAINER(bbox), button); table = gtk_table_new(2, 3, FALSE); gtk_table_set_col_spacing(GTK_TABLE(table), 0, 15); gtk_table_set_col_spacing(GTK_TABLE(table), 1, 5); gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, TRUE, 0); label = gtk_label_new("Short"); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_table_attach(GTK_TABLE(table), label, 1, 2, 0, 1, GTK_FILL, GTK_SHRINK, 0, 0); label_short = label; entry = gtk_entry_new_with_max_length(TZ_SHORT); gtk_table_attach_defaults(GTK_TABLE(table), entry, 2, 3, 0, 1); entry_short = entry; label = gtk_label_new("Long"); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_table_attach(GTK_TABLE(table), label, 1, 2, 1, 2, GTK_FILL, GTK_SHRINK, 0, 0); label_long = label; entry = gtk_entry_new_with_max_length(TZ_LONG); gtk_table_attach_defaults(GTK_TABLE(table), entry, 2, 3, 1, 2); entry_long = entry; g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(tz_config_op_custom), NULL); tz_config_op_custom(GTK_TOGGLE_BUTTON(button), NULL); options.format_short = NULL; options.format_long = NULL; /* Time alignment */ hbox = gtk_hbutton_box_new(); gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_START); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); label = gtk_label_new("Time alignment:"); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_container_add(GTK_CONTAINER(hbox), label); button = gtk_radio_button_new_with_label(NULL, "left"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), options.align == TA_LEFT); g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(tz_config_op_left), NULL); gtk_container_add(GTK_CONTAINER(hbox), button); button = gtk_radio_button_new_with_label( gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)), "center"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), options.align == TA_CENTER); g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(tz_config_op_center), NULL); gtk_container_add(GTK_CONTAINER(hbox), button); button = gtk_radio_button_new_with_label( gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)), "right"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), options.align == TA_RIGHT); g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(tz_config_op_right), NULL); gtk_container_add(GTK_CONTAINER(hbox), button); } void tz_config_create_tabs(GtkWidget *tab_vbox, struct tz_plugin *plugin) { int i; GtkWidget *tabs; GtkWidget *label; GtkWidget *vbox; GtkWidget *text; tabs = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs), GTK_POS_TOP); gtk_box_pack_start(GTK_BOX(tab_vbox), tabs, TRUE, TRUE, 0); /* Timezones configuration */ vbox = gkrellm_gtk_framed_notebook_page(tabs, "Timezones"); tz_config_timezones(vbox, plugin); /* Options */ vbox = gkrellm_gtk_framed_notebook_page(tabs, "Options"); tz_config_options(vbox, plugin); /* Info tab */ vbox = gkrellm_gtk_framed_notebook_page(tabs, "Info"); text = gkrellm_gtk_scrolled_text_view(vbox, NULL, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); for (i = 0; i < sizeof(info_text) / sizeof(gchar *); i++) gkrellm_gtk_text_view_append(text, info_text[i]); /* About tab */ label = gtk_label_new("About"); gtk_notebook_append_page(GTK_NOTEBOOK(tabs), gtk_label_new(about_text), label); } static void tz_reset_entries(void) { gtk_entry_set_text(GTK_ENTRY(entry_label), ""); gtk_entry_set_text(GTK_ENTRY(entry_tz), ""); } static void tz_config_toggled(GtkCellRendererToggle *cell_renderer, gchar *path, gpointer user_data) { gboolean enabled; GtkTreeIter iter; gtk_tree_model_get_iter_from_string(treemodel, &iter, path); gtk_tree_model_get(treemodel, &iter, 0, &enabled, -1); gtk_list_store_set(list_store, &iter, 0, !enabled, -1); } static void tz_config_selected(GtkTreeSelection *selection, gpointer data) { GtkTreeModel *treemodel; GtkTreeIter iter; gchar *entry[2]; if (gtk_tree_selection_get_selected(selection, &treemodel, &iter)) { gtk_tree_model_get(treemodel, &iter, 1, &entry[0], 2, &entry[1], -1); gtk_entry_set_text(GTK_ENTRY(entry_label), entry[0]); gtk_entry_set_text(GTK_ENTRY(entry_tz), entry[1]); g_free(entry[0]); g_free(entry[1]); sel_row_iter = iter; sel_row = selection; } else { tz_reset_entries(); } } static void tz_config_delete(GtkWidget *widget, gpointer data) { tz_reset_entries(); gtk_list_store_remove(list_store, &sel_row_iter); } static void tz_config_add(GtkWidget *widget, gpointer data) { gchar *entry[2]; entry[0] = g_strdup(gkrellm_gtk_entry_get_text(&entry_label)); g_strstrip(entry[0]); entry[1] = g_strdup(gkrellm_gtk_entry_get_text(&entry_tz)); g_strstrip(entry[1]); if (strlen(entry[0]) == 0 || strlen(entry[1]) == 0) goto cleanup; gtk_list_store_append(list_store, &sel_row_iter); gtk_list_store_set(list_store, &sel_row_iter, 0, TRUE, 1, entry[0], 2, entry[1], -1); cleanup: tz_reset_entries(); g_free(entry[0]); g_free(entry[1]); } static void tz_config_set(GtkWidget *widget, gpointer data) { gchar *entry[2]; entry[0] = g_strdup(gkrellm_gtk_entry_get_text(&entry_label)); g_strstrip(entry[0]); entry[1] = g_strdup(gkrellm_gtk_entry_get_text(&entry_tz)); g_strstrip(entry[1]); if (strlen(entry[0]) == 0 || strlen(entry[1]) == 0) goto cleanup; gtk_list_store_set(list_store, &sel_row_iter, 0, TRUE, 1, entry[0], 2, entry[1], -1); cleanup: tz_reset_entries(); g_free(entry[0]); g_free(entry[1]); } static void tz_config_up(GtkWidget *widget, gpointer data) { GtkTreeIter iter; GtkTreeIter iter2; if (GTK_IS_TREE_SELECTION(sel_row) && gtk_tree_selection_iter_is_selected(sel_row, &sel_row_iter)) { gtk_tree_model_get_iter_first(treemodel, &iter); if (!gtk_tree_selection_iter_is_selected(sel_row, &iter)) { while (!gtk_tree_selection_iter_is_selected(sel_row, &iter)) { iter2 = iter; gtk_tree_model_iter_next(treemodel, &iter); } iter = iter2; gtk_list_store_swap(list_store, &iter, &sel_row_iter); } } } static void tz_config_down(GtkWidget *widget, gpointer data) { GtkTreeIter iter; if (GTK_IS_TREE_SELECTION(sel_row) && gtk_tree_selection_iter_is_selected(sel_row, &sel_row_iter)) { iter = sel_row_iter; if (gtk_tree_model_iter_next(treemodel, &iter)) gtk_list_store_swap(list_store, &iter, &sel_row_iter); } } static void tz_config_op_12h(GtkToggleButton *toggle, gpointer data) { options.twelve_hour = gtk_toggle_button_get_active(toggle); } static void tz_config_op_seconds(GtkToggleButton *toggle, gpointer data) { options.seconds = gtk_toggle_button_get_active(toggle); } static void tz_config_op_custom(GtkToggleButton *toggle, gpointer data) { options.custom = gtk_toggle_button_get_active(toggle); if (options.custom) { gtk_entry_set_text(GTK_ENTRY(entry_short), tz_format_short(options)); gtk_entry_set_text(GTK_ENTRY(entry_long), tz_format_long(options)); } else { gtk_entry_set_text(GTK_ENTRY(entry_short), ""); gtk_entry_set_text(GTK_ENTRY(entry_long), ""); } gtk_widget_set_sensitive(toggle_12h, !options.custom); gtk_widget_set_sensitive(toggle_sec, !options.custom); gtk_widget_set_sensitive(label_short, options.custom); gtk_widget_set_sensitive(entry_short, options.custom); gtk_widget_set_sensitive(label_long, options.custom); gtk_widget_set_sensitive(entry_long, options.custom); } static void tz_config_op_left(GtkToggleButton *toggle, gpointer data) { if (gtk_toggle_button_get_active(toggle)) options.align = TA_LEFT; } static void tz_config_op_center(GtkToggleButton *toggle, gpointer data) { if (gtk_toggle_button_get_active(toggle)) options.align = TA_CENTER; } static void tz_config_op_right(GtkToggleButton *toggle, gpointer data) { if (gtk_toggle_button_get_active(toggle)) options.align = TA_RIGHT; } gkrellm-tz-0.8/config.h000066400000000000000000000020661253377524300151060ustar00rootroot00000000000000/* * Plugin configuration. * Copyright (C) 2005--2010 Jiri Denemark * * This file is part of gkrellm-tz. * * gkrellm-tz 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** @file * Plugin configuration. * @author Jiri Denemark */ #ifndef CONFIG_H #define CONFIG_H #include "list.h" void tz_config_create_tabs(GtkWidget *tab_vbox, struct tz_plugin *plugin); void tz_config_apply(struct tz_plugin *plugin); #endif gkrellm-tz-0.8/features.h000066400000000000000000000021231253377524300154510ustar00rootroot00000000000000/* * Compile time features. * Copyright (C) 2010 Jiri Denemark * * This file is part of gkrellm-tz. * * gkrellm-tz 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef FEATURES_H #define FEATURES_H #include #if (GKRELLM_VERSION_MAJOR < 2) # error This plugin requires GKrellM version >= 2.0 #endif #if GTK_CHECK_VERSION(2,12,0) # define TOOLTIP_API 1 #else # define TOOLTIP_API 0 #endif #define GTK_DISABLE_DEPRECATED 1 #endif gkrellm-tz-0.8/gkrellm-tz.c000066400000000000000000000143661253377524300157320ustar00rootroot00000000000000/* * Timezone plugin for GKrellM. * Copyright (C) 2005--2010 Jiri Denemark * * This file is part of gkrellm-tz. * * gkrellm-tz 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** @file * Timezone plugin for GKrellM. * @author Jiri Denemark */ #include #include #include #include #include #include #include "features.h" #include "list.h" #include "config.h" #define CONFIG_TAB "Timezone" #define CONFIG_KEYWORD "gkrellm-tz" #define PLACEMENT (MON_CLOCK | MON_INSERT_AFTER) static struct tz_plugin plugin; static gint panel_expose_event(GtkWidget *widget, GdkEventExpose *ev) { struct tz_list_item *item; for (item = plugin.first; item != NULL; item = item->next) { if (item->tz.enabled && widget == item->panel->drawing_area) { gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], item->panel->pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y, ev->area.width, ev->area.height); } } return FALSE; } static void panel_click_event(GtkWidget *widget, GdkEventButton *ev, gpointer data) { if (ev->button == 3) gkrellm_open_config_window(plugin.monitor); } static void update(void) { if (gkrellm_ticks()->second_tick) tz_list_update(&plugin, mktime(gkrellm_get_current_time())); tz_plugin_update(&plugin); } static void create(GtkWidget *vbox, gint first_create) { if (first_create) { plugin.vbox = vbox; tz_list_clean(&plugin); tz_list_load(&plugin); } else { struct tz_list_item *item; for (item = plugin.first; item != NULL; item = item->next) { if (item->tz.enabled) tz_panel_create(&plugin, item); } } } static void config(GtkWidget *tab_vbox) { tz_config_create_tabs(tab_vbox, &plugin); } static void apply(void) { tz_list_clean(&plugin); tz_config_apply(&plugin); tz_list_store(&plugin); } static void save(FILE *f) { fprintf(f, "%s options %d %d %d %d\n", CONFIG_KEYWORD, plugin.options.twelve_hour, plugin.options.seconds, plugin.options.custom, plugin.options.align); fprintf(f, "%s format_short \"%s\"\n", CONFIG_KEYWORD, (plugin.options.custom) ? plugin.options.format_short : ""); fprintf(f, "%s format_long \"%s\"\n", CONFIG_KEYWORD, (plugin.options.custom) ? plugin.options.format_long : ""); } static char * strdup_quoted(char *str) { int len; if (str == NULL) return NULL; if (*str == '"') str++; len = strlen(str); if (str[len - 1] == '"') str[len - 1] = '\0'; return strdup(str); } static void load(gchar *line) { char config[32]; char value[CFG_BUFSIZE]; if (sscanf(line, "%31s %[^\n]", config, value) != 2) return; if (strcmp(config, "options") == 0) { int twelve_hour; int seconds; int custom; int align; sscanf(value, "%d %d %d %d", &twelve_hour, &seconds, &custom, &align); plugin.options.twelve_hour = twelve_hour != 0; plugin.options.seconds = seconds != 0; plugin.options.custom = custom != 0; switch (align) { case TA_LEFT: plugin.options.align = TA_LEFT; break; case TA_CENTER: plugin.options.align = TA_CENTER; break; case TA_RIGHT: plugin.options.align = TA_RIGHT; break; default: plugin.options.align = TA_LEFT; break; } } else if (strcmp(config, "format_short") == 0) { if (*value != '\0') plugin.options.format_short = strdup_quoted(value); } else if (strcmp(config, "format_long") == 0) { if (*value != '\0') plugin.options.format_long = strdup_quoted(value); } } static GkrellmMonitor plugin_mon = { CONFIG_TAB, /* Title for config tab. */ 0, /* Id, 0 if a plugin */ create, /* The create function */ update, /* The update function */ config, /* The config tab create function */ apply, /* Apply the config function */ save, /* Save user config */ load, /* Load user config */ CONFIG_KEYWORD, /* Config file keyword */ NULL, /* Undefined 2 */ NULL, /* Undefined 1 */ NULL, /* Undefined 0 */ PLACEMENT, /* Plugin placement */ NULL, /* Handle if a plugin, filled in by GKrellM */ NULL /* path if a plugin, filled in by GKrellM */ }; /** Plugin's entry point. */ GkrellmMonitor * gkrellm_init_plugin(void) { plugin.options.twelve_hour = 0; plugin.options.seconds = 1; plugin.options.custom = 0; plugin.options.format_short = NULL; plugin.options.format_long = NULL; plugin.options.align = TA_LEFT; plugin.first = NULL; plugin.last = NULL; plugin.vbox = NULL; #if !TOOLTIP_API plugin.tooltips = gtk_tooltips_new(); gtk_tooltips_enable(plugin.tooltips); gtk_tooltips_set_delay(plugin.tooltips, 500); #endif plugin.monitor = &plugin_mon; plugin.expose_event = panel_expose_event; plugin.click_event = panel_click_event; plugin.style_id = gkrellm_add_meter_style(&plugin_mon, CONFIG_KEYWORD); return plugin.monitor; } gkrellm-tz-0.8/gkrellm-tz.h000066400000000000000000000016751253377524300157360ustar00rootroot00000000000000/* * Timezone plugin for GKrellM. * Copyright (C) 2005--2010 Jiri Denemark * * This file is part of gkrellm-tz. * * gkrellm-tz 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** @file * Timezone plugin for GKrellM. * @author Jiri Denemark */ #ifndef GKRELLM_TZ_H #define GKRELLM_TZ_H #endif gkrellm-tz-0.8/list.c000066400000000000000000000215151253377524300146070ustar00rootroot00000000000000/* * List of timezones to be shown. * Copyright (C) 2005--2010 Jiri Denemark * * This file is part of gkrellm-tz. * * gkrellm-tz 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** @file * List of timezones to be shown. * @author Jiri Denemark */ #include #include #include #include #include #include #include #include #include "features.h" #include "list.h" #define LINE (1 + MAX_TIMEZONE_LENGTH + 1 + MAX_LABEL_LENGTH + 1) /** Update given timezone structure according to current time. * This function sets short and long time strings according to current time * in given timezone. It is supposed to be called from a loop once in a * second. * * @param t * current time as returned by time(). * * @param item * timezone structure to be updated. * * @param options * plugin options. * * @return * nothing. */ static void tz_item_update(time_t t, struct tz_item *item, struct tz_options *options); static FILE * tz_list_file(const char *mode) { gchar *filename; FILE *file = NULL; filename = g_build_path(G_DIR_SEPARATOR_S, gkrellm_homedir(), GKRELLM_DATA_DIR, "gkrellm-tz", NULL); if (filename != NULL) file = fopen(filename, mode); return file; } void tz_list_load(struct tz_plugin *plugin) { FILE *file; char line[LINE + 1]; char *tz; char *lbl; int enabled; int i; int len; if ((file = tz_list_file("r")) == NULL) return; while (fgets(line, LINE, file) != NULL) { len = strlen(line); for (i = 0; i < MAX_TIMEZONE_LENGTH && line[i] != ':'; i++) ; line[i] = '\0'; switch (*line) { case '-': enabled = 0; tz = line + 1; break; case '+': enabled = 1; tz = line + 1; break; default: enabled = 1; tz = line; } lbl = line + i + 1; if (line[len - 1] != '\n') { tz_list_add(plugin, enabled, lbl, tz); /* ignore rest of the line */ while (fgets(line, LINE, file) != NULL) { len = strlen(line); if (line[len - 1] == '\n') break; } } else { line[len - 1] = '\0'; tz_list_add(plugin, enabled, lbl, tz); } } fclose(file); } void tz_list_store(struct tz_plugin *plugin) { FILE *file; struct tz_list_item *item; if ((file = tz_list_file("w")) == NULL) return; for (item = plugin->first; item != NULL; item = item->next) fprintf(file, "%c%s:%s\n", (item->tz.enabled) ? '+' : '-', item->tz.timezone, item->tz.label); fclose(file); } void tz_plugin_update(struct tz_plugin *plugin) { struct tz_list_item *item; gint wdecl; gint hdecl; gint wtext; gint offset; gint h; for (item = plugin->first; item != NULL; item = item->next) { if (!item->tz.enabled) continue; if (strchr(item->tz.time_short, '<') != NULL && !pango_parse_markup(item->tz.time_short, -1, 0, NULL, NULL, NULL, NULL)) continue; offset = 0; if (plugin->options.align != TA_LEFT) { gkrellm_decal_get_size(item->decal, &wdecl, &hdecl); gkrellm_text_markup_extents(item->decal->text_style.font, item->tz.time_short, strlen(item->tz.time_short), &wtext, &h, NULL, &item->decal->y_ink); wtext += item->decal->text_style.effect; if (wtext < wdecl) { switch (plugin->options.align) { case TA_CENTER: offset = (wdecl - wtext) / 2; break; case TA_RIGHT: offset = wdecl - wtext; break; default: offset = 0; } } } gkrellm_decal_text_set_offset(item->decal, offset, 0); gkrellm_draw_decal_markup(item->panel, item->decal, item->tz.time_short); gkrellm_draw_panel_layers(item->panel); } } void tz_list_update(struct tz_plugin *plugin, time_t t) { struct tz_list_item *item; for (item = plugin->first; item != NULL; item = item->next) { if (item->tz.enabled) { gchar *tmp; gchar *tt; tz_item_update(t, &item->tz, &plugin->options); tmp = g_strdup_printf("%s: %s", item->tz.label, item->tz.time_long); tt = g_locale_to_utf8(tmp, strlen(tmp), NULL, NULL, NULL); g_free(tmp); #if TOOLTIP_API gtk_widget_set_tooltip_text(item->panel->drawing_area, tt); #else gtk_tooltips_set_tip(plugin->tooltips, item->panel->drawing_area, tt, NULL); #endif g_free(tt); } } } void tz_list_clean(struct tz_plugin *plugin) { struct tz_list_item *item; struct tz_list_item *p; for (item = plugin->first; item != NULL; ) { if (item->tz.enabled) gkrellm_panel_destroy(item->panel); free(item->tz.label); free(item->tz.timezone); p = item->next; free(item); item = p; } plugin->first = NULL; plugin->last = NULL; } int tz_list_add(struct tz_plugin *plugin, int enabled, const char *label, const char *timezone) { struct tz_list_item *item; if (timezone == NULL || *timezone == '\0') return -1; if (label == NULL) label = timezone; for (item = plugin->first; item != NULL; item = item->next) { if (strcmp(item->tz.label, label) == 0) return -1; } item = (struct tz_list_item *) malloc(sizeof(struct tz_list_item)); if (item == NULL) return -1; memset((void *) item, '\0', sizeof(struct tz_list_item)); item->tz.enabled = enabled; item->tz.label = strdup(label); item->tz.timezone = strdup(timezone); if (enabled) { item->panel = gkrellm_panel_new0(); tz_panel_create(plugin, item); g_signal_connect(G_OBJECT(item->panel->drawing_area), "expose_event", G_CALLBACK(plugin->expose_event), NULL); g_signal_connect(G_OBJECT(item->panel->drawing_area), "button_press_event", G_CALLBACK(plugin->click_event), NULL); } else { item->panel = NULL; } item->prev = plugin->last; plugin->last = item; if (item->prev == NULL) plugin->first = item; else item->prev->next = item; return 0; } void tz_panel_create(struct tz_plugin *plugin, struct tz_list_item *item) { GkrellmStyle *style; GkrellmTextstyle *text_style; style = gkrellm_meter_style(plugin->style_id); text_style = gkrellm_meter_alt_textstyle(plugin->style_id); item->panel->textstyle = text_style; item->decal = gkrellm_create_decal_text(item->panel, "Yq", text_style, style, -1, -1, -1); gkrellm_panel_configure(item->panel, NULL, style); gkrellm_panel_create(plugin->vbox, plugin->monitor, item->panel); } static void tz_item_update(time_t t, struct tz_item *item, struct tz_options *options) { struct tm tm; char *tz_old; tz_old = getenv("TZ"); setenv("TZ", item->timezone, 1); tzset(); localtime_r(&t, &tm); strftime(item->time_short, TZ_SHORT, tz_format_short(*options), &tm); strftime(item->time_long, TZ_LONG, tz_format_long(*options), &tm); if (tz_old != NULL) setenv("TZ", tz_old, 1); else unsetenv("TZ"); tzset(); } gkrellm-tz-0.8/list.h000066400000000000000000000126601253377524300146150ustar00rootroot00000000000000/* * List of timezones to be shown. * Copyright (C) 2005--2010 Jiri Denemark * * This file is part of gkrellm-tz. * * gkrellm-tz 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /** @file * List of timezones to be shown. * @author Jiri Denemark */ #ifndef LIST_H #define LIST_H #include #define MAX_LABEL_LENGTH 60 #define MAX_TIMEZONE_LENGTH 60 /** Short time format (used for gkrellm panel) -- 24h+s. */ #define TZ_SHORT_FORMAT_24s "%T %Z" /** Short time format (used for gkrellm panel) -- 24h-s. */ #define TZ_SHORT_FORMAT_24 "%R %Z" /** Short time format (used for gkrellm panel) -- 12h+s. */ #define TZ_SHORT_FORMAT_12s "%r %Z" /** Short time format (used for gkrellm panel) -- 12h-s. */ #define TZ_SHORT_FORMAT_12 "%I:%M %p %Z" /** Length of a buffer for short time string. */ #define TZ_SHORT 255 /** Get short time format according to plugin options. * * @param options * plugin options itself (the structure, not a pointer to it). * * @return * short time format. */ #define tz_format_short(options) \ (((options).custom && (options).format_short != NULL) \ ? (options).format_short \ : ((!(options).twelve_hour && (options).seconds) \ ? TZ_SHORT_FORMAT_24s \ : ((!(options).twelve_hour && !(options).seconds) \ ? TZ_SHORT_FORMAT_24 \ : (((options).twelve_hour && (options).seconds) \ ? TZ_SHORT_FORMAT_12s \ : TZ_SHORT_FORMAT_12)))) /** Long time format (used for tooltip message). */ #define TZ_LONG_FORMAT "%c %Z (%z)" /** Length of a buffer for long time string. */ #define TZ_LONG 100 /** Get long time format according to plugin options. * * @param options * plugin options itself (the structure, not a pointer to it). * * @return * long time format. */ #define tz_format_long(options) \ (((options).custom && (options).format_long != NULL) \ ? (options).format_long \ : TZ_LONG_FORMAT) /** Timezone structure. */ struct tz_item { /** Nonzero if enabled. */ int enabled; /** Label to be shown for a given time. * In case it is NULL, timezone field is used as a label. */ char *label; /** Timezone in a form usable for TZ environment variable. * E.g. "US/Central". */ char *timezone; /** Buffer for short time string. */ char time_short[TZ_SHORT]; /** Buffer for long time string. */ char time_long[TZ_LONG]; }; /** Timezone list item. */ struct tz_list_item { /** Pointer to the previous item in the list. */ struct tz_list_item *prev; /** Pointer to the next item in the list. */ struct tz_list_item *next; /** GKrellM panel dedicated for this timezone. */ GkrellmPanel *panel; /** GKrellM decal containing short time string. */ GkrellmDecal *decal; /** Timezone description and current time. */ struct tz_item tz; }; /** Text alignment. */ enum tz_align { TA_LEFT, TA_CENTER, TA_RIGHT }; /** Plugin options. */ struct tz_options { /** 12 hour time instead of 24 hour time. */ int twelve_hour; /** Show seconds in krells. */ int seconds; /** Use custom formats. */ int custom; /** Custom format for time in krells. */ char *format_short; /** Custom format for time in tooltips. */ char *format_long; /** Alignmet of the text in krells. */ enum tz_align align; }; /** Plugin data. */ struct tz_plugin { /** Plugin options. */ struct tz_options options; /** Pointer to the first item in the list. */ struct tz_list_item *first; /** Pointer to the last item in the list. */ struct tz_list_item *last; /** Plugin's vbox. */ GtkWidget *vbox; /** Plugin's description structure. */ GkrellmMonitor *monitor; #if !TOOLTIP_API /** Tooltips for labels and long time strings. */ GtkTooltips *tooltips; #endif /** Handler for expose_event. */ gint (*expose_event)(GtkWidget *widget, GdkEventExpose *ev); /** Handler for button_press_event. */ void (*click_event)(GtkWidget *widget, GdkEventButton *ev, gpointer data); /** Pointer to a panel style. */ gint style_id; }; void tz_plugin_update(struct tz_plugin *plugin); void tz_panel_create(struct tz_plugin *plugin, struct tz_list_item *item); void tz_list_load(struct tz_plugin *plugin); void tz_list_store(struct tz_plugin *plugin); void tz_list_clean(struct tz_plugin *plugin); int tz_list_add(struct tz_plugin *plugin, int enabled, const char *label, const char *timezone); void tz_list_update(struct tz_plugin *plugin, time_t t); int tz_list_remove(); int tz_list_move_up(); int tz_list_move_down(); #endif