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)
30 static void cb_preferences(GtkMenuItem *mi, gpointer data)
32 ui_pref_dialog_run((struct ui_psensor *)data);
35 static void cb_sensor_preferences(GtkMenuItem *mi, gpointer data)
37 struct ui_psensor *ui = data;
39 if (ui->sensors && *ui->sensors)
40 ui_sensorpref_dialog_run(*ui->sensors, ui);
43 static const char *menu_desc =
45 " <popup name='MainMenu'>"
46 " <menuitem name='Preferences' action='PreferencesAction' />"
47 " <menuitem name='SensorPreferences' action='SensorPreferencesAction' />"
49 " <menuitem name='Quit' action='QuitAction' />"
53 static GtkActionEntry entries[] = {
54 { "PsensorMenuAction", NULL, "_Psensor" }, /* name, stock id, label */
56 { "PreferencesAction", GTK_STOCK_PREFERENCES, /* name, stock id */
57 "_Preferences", NULL, /* label, accelerator */
58 "Preferences", /* tooltip */
59 G_CALLBACK(cb_preferences) },
61 { "SensorPreferencesAction", GTK_STOCK_PREFERENCES,/* name, stock id */
62 "_Sensor Preferences", NULL, /* label, accelerator */
63 "Sensor Preferences", /* tooltip */
64 G_CALLBACK(cb_sensor_preferences) },
67 GTK_STOCK_QUIT, "_Quit", NULL, "Quit", G_CALLBACK(cb_menu_quit) }
69 static guint n_entries = G_N_ELEMENTS(entries);
71 static GtkWidget *get_menu(struct ui_psensor *ui)
73 GtkActionGroup *action_group;
74 GtkUIManager *menu_manager;
77 action_group = gtk_action_group_new("PsensorActions");
78 gtk_action_group_set_translation_domain(action_group, PACKAGE);
79 menu_manager = gtk_ui_manager_new();
81 gtk_action_group_add_actions(action_group, entries, n_entries, ui);
82 gtk_ui_manager_insert_action_group(menu_manager, action_group, 0);
85 gtk_ui_manager_add_ui_from_string(menu_manager, menu_desc, -1, &error);
88 g_error(_("building menus failed: %s"), error->message);
90 return gtk_ui_manager_get_widget(menu_manager, "/MainMenu");
95 on_graph_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data)
99 if (event->type != GDK_BUTTON_PRESS)
102 menu = get_menu((struct ui_psensor *)data);
104 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
105 event->button, event->time);
111 on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
113 struct ui_psensor *ui_psensor = (struct ui_psensor *)data;
115 graph_update(ui_psensor->sensors,
116 ui_psensor->w_graph, ui_psensor->config);
121 GtkWidget *ui_graph_create(struct ui_psensor * ui)
125 w_graph = gtk_drawing_area_new();
127 g_signal_connect(GTK_WIDGET(w_graph),
128 "expose-event", G_CALLBACK(on_expose_event), ui);
130 gtk_widget_add_events(w_graph, GDK_BUTTON_PRESS_MASK);
132 g_signal_connect(GTK_WIDGET(w_graph),
133 "button_press_event",
134 (GCallback) on_graph_clicked, ui);