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
23 #include "ui_sensorpref.h"
25 static void cb_menu_quit(GtkMenuItem *mi, gpointer data)
27 ui_psensor_quit((struct ui_psensor *)data);
30 static void cb_preferences(GtkMenuItem *mi, gpointer data)
32 ui_pref_dialog_run((struct ui_psensor *)data);
35 static void cb_about(GtkMenuItem *mi, gpointer data)
37 ui_show_about_dialog();
40 static void cb_sensor_preferences(GtkMenuItem *mi, gpointer data)
42 struct ui_psensor *ui = data;
44 if (ui->sensors && *ui->sensors)
45 ui_sensorpref_dialog_run(*ui->sensors, ui);
48 static const char *menu_desc =
50 " <popup name='MainMenu'>"
51 " <menuitem name='Preferences' action='PreferencesAction' />"
52 " <menuitem name='SensorPreferences' action='SensorPreferencesAction' />"
54 " <menuitem name='About' action='AboutAction' />"
56 " <menuitem name='Quit' action='QuitAction' />"
60 static GtkActionEntry entries[] = {
61 { "PsensorMenuAction", NULL, "_Psensor" }, /* name, stock id, label */
63 { "PreferencesAction", GTK_STOCK_PREFERENCES, /* name, stock id */
64 "_Preferences", NULL, /* label, accelerator */
65 "Preferences", /* tooltip */
66 G_CALLBACK(cb_preferences) },
68 { "SensorPreferencesAction", GTK_STOCK_PREFERENCES,/* name, stock id */
69 "_Sensor Preferences", NULL, /* label, accelerator */
70 "Sensor Preferences", /* tooltip */
71 G_CALLBACK(cb_sensor_preferences) },
73 { "AboutAction", NULL,
76 G_CALLBACK(cb_about) },
79 GTK_STOCK_QUIT, "_Quit", NULL, "Quit", G_CALLBACK(cb_menu_quit) }
81 static guint n_entries = G_N_ELEMENTS(entries);
83 static GtkWidget *get_menu(struct ui_psensor *ui)
85 GtkActionGroup *action_group;
86 GtkUIManager *menu_manager;
89 action_group = gtk_action_group_new("PsensorActions");
90 gtk_action_group_set_translation_domain(action_group, PACKAGE);
91 menu_manager = gtk_ui_manager_new();
93 gtk_action_group_add_actions(action_group, entries, n_entries, ui);
94 gtk_ui_manager_insert_action_group(menu_manager, action_group, 0);
97 gtk_ui_manager_add_ui_from_string(menu_manager, menu_desc, -1, &error);
100 g_error(_("building menus failed: %s"), error->message);
102 return gtk_ui_manager_get_widget(menu_manager, "/MainMenu");
107 on_graph_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data)
111 if (event->type != GDK_BUTTON_PRESS)
114 menu = get_menu((struct ui_psensor *)data);
116 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
117 event->button, event->time);
123 on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
125 struct ui_psensor *ui_psensor = (struct ui_psensor *)data;
127 graph_update(ui_psensor->sensors,
128 ui_psensor->w_graph, ui_psensor->config);
133 GtkWidget *ui_graph_create(struct ui_psensor * ui)
137 w_graph = gtk_drawing_area_new();
139 if (GTK_MAJOR_VERSION == 2)
140 g_signal_connect(GTK_WIDGET(w_graph),
142 G_CALLBACK(on_expose_event),
145 g_signal_connect(GTK_WIDGET(w_graph),
147 G_CALLBACK(on_expose_event),
150 gtk_widget_add_events(w_graph, GDK_BUTTON_PRESS_MASK);
152 g_signal_connect(GTK_WIDGET(w_graph),
153 "button_press_event",
154 (GCallback) on_graph_clicked, ui);