2 Copyright (C) 2010-2011 jeanfi@gmail.com
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
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
24 #include "ui_sensorlist.h"
27 on_delete_event_cb(GtkWidget *widget, GdkEvent *event, gpointer data)
29 #if defined(HAVE_APPINDICATOR) || defined(HAVE_APPINDICATOR_029)
30 gtk_widget_hide(((struct ui_psensor *)data)->main_window);
38 static void cb_menu_quit(gpointer data,
45 static void cb_menu_preferences(gpointer data,
49 ui_pref_dialog_run((struct ui_psensor *)data);
52 void ui_psensor_quit()
57 static GtkItemFactoryEntry menu_items[] = {
58 {"/Psensor", NULL, NULL, 0, "<Branch>"},
59 {"/Psensor/Preferences",
60 NULL, cb_menu_preferences, 0, "<Item>"},
62 NULL, NULL, 0, "<Separator>"},
64 "", cb_menu_quit, 0, "<StockItem>", GTK_STOCK_QUIT},
67 static gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
69 static GtkWidget *get_menu(struct ui_psensor *ui)
71 GtkItemFactory *item_factory;
73 item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", NULL);
75 gtk_item_factory_create_items(item_factory,
76 nmenu_items, menu_items, ui);
77 return gtk_item_factory_get_widget(item_factory, "<main>");
80 void ui_window_create(struct ui_psensor *ui)
82 GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
84 GdkColormap *colormap;
86 GtkIconTheme *icon_theme;
89 gtk_window_set_default_size(GTK_WINDOW(window), 800, 200);
91 gtk_window_set_title(GTK_WINDOW(window),
92 _("Psensor - Temperature Monitor"));
93 gtk_window_set_role(GTK_WINDOW(window), "psensor");
95 screen = gtk_widget_get_screen(window);
97 if (ui->config->alpha_channel_enabled
98 && gdk_screen_is_composited(screen)) {
100 colormap = gdk_screen_get_rgba_colormap(screen);
102 gtk_widget_set_colormap(window, colormap);
104 ui->config->alpha_channel_enabled = 0;
106 ui->config->alpha_channel_enabled = 0;
109 icon_theme = gtk_icon_theme_get_default();
110 icon = gtk_icon_theme_load_icon(icon_theme, "psensor", 48, 0, NULL);
112 gtk_window_set_icon(GTK_WINDOW(window), icon);
114 fprintf(stderr, _("ERROR: Failed to load psensor icon.\n"));
116 g_signal_connect(window,
117 "delete_event", G_CALLBACK(on_delete_event_cb), ui);
119 gtk_window_set_decorated(GTK_WINDOW(window),
120 ui->config->window_decoration_enabled);
122 gtk_window_set_keep_below(GTK_WINDOW(window),
123 ui->config->window_keep_below_enabled);
126 menubar = get_menu(ui);
128 ui->main_box = gtk_vbox_new(FALSE, 1);
130 gtk_box_pack_start(GTK_BOX(ui->main_box), menubar,
133 gtk_container_add(GTK_CONTAINER(window), ui->main_box);
135 ui->main_window = window;
136 ui->menu_bar = menubar;
138 gtk_widget_show_all(ui->main_window);
141 static void menu_bar_show(unsigned int show, struct ui_psensor *ui)
144 gtk_widget_show(ui->menu_bar);
146 gtk_widget_hide(ui->menu_bar);
149 void ui_window_update(struct ui_psensor *ui)
152 GtkWidget *w_sensorlist;
156 if (ui->sensor_box) {
157 ui_sensorlist_create_widget(ui->ui_sensorlist);
159 gtk_container_remove(GTK_CONTAINER(ui->main_box),
162 ui->w_graph = ui_graph_create(ui);
163 ui->w_sensorlist = ui->ui_sensorlist->widget;
166 if (cfg->sensorlist_position == SENSORLIST_POSITION_RIGHT
167 || cfg->sensorlist_position == SENSORLIST_POSITION_LEFT)
168 ui->sensor_box = gtk_hpaned_new();
170 ui->sensor_box = gtk_vpaned_new();
172 w_sensorlist = gtk_scrolled_window_new(NULL, NULL);
173 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w_sensorlist),
174 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
175 gtk_container_add(GTK_CONTAINER(w_sensorlist),
176 ui->ui_sensorlist->widget);
178 gtk_box_pack_end(GTK_BOX(ui->main_box), ui->sensor_box, TRUE, TRUE, 2);
180 if (cfg->sensorlist_position == SENSORLIST_POSITION_RIGHT
181 || cfg->sensorlist_position == SENSORLIST_POSITION_BOTTOM) {
182 gtk_paned_pack1(GTK_PANED(ui->sensor_box),
183 GTK_WIDGET(ui->w_graph), TRUE, TRUE);
184 gtk_paned_pack2(GTK_PANED(ui->sensor_box),
185 w_sensorlist, FALSE, TRUE);
187 gtk_paned_pack1(GTK_PANED(ui->sensor_box),
188 w_sensorlist, FALSE, TRUE);
189 gtk_paned_pack2(GTK_PANED(ui->sensor_box),
190 GTK_WIDGET(ui->w_graph), TRUE, TRUE);
193 gtk_widget_show_all(ui->sensor_box);
195 if (cfg->menu_bar_disabled)
196 menu_bar_show(0, ui);
198 menu_bar_show(1, ui);