2 * Copyright (C) 2010-2012 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * 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
22 #include "ui_sensorpref.h"
24 static void cb_menu_quit(GtkMenuItem *mi, gpointer data)
26 ui_psensor_quit((struct ui_psensor *)data);
29 static void cb_preferences(GtkMenuItem *mi, gpointer data)
31 ui_pref_dialog_run((struct ui_psensor *)data);
34 static void cb_about(GtkMenuItem *mi, gpointer data)
36 ui_show_about_dialog();
39 static void cb_sensor_preferences(GtkMenuItem *mi, gpointer data)
41 struct ui_psensor *ui = data;
43 if (ui->sensors && *ui->sensors)
44 ui_sensorpref_dialog_run(*ui->sensors, ui);
47 static const char *menu_desc =
49 " <popup name='MainMenu'>"
50 " <menuitem name='Preferences' action='PreferencesAction' />"
51 " <menuitem name='SensorPreferences' action='SensorPreferencesAction' />"
53 " <menuitem name='About' action='AboutAction' />"
55 " <menuitem name='Quit' action='QuitAction' />"
59 static GtkActionEntry entries[] = {
60 { "PsensorMenuAction", NULL, "_Psensor" },
62 { "PreferencesAction", GTK_STOCK_PREFERENCES,
65 G_CALLBACK(cb_preferences) },
67 { "SensorPreferencesAction", GTK_STOCK_PREFERENCES,
68 "S_ensor Preferences", NULL,
70 G_CALLBACK(cb_sensor_preferences) },
72 { "AboutAction", NULL,
75 G_CALLBACK(cb_about) },
78 GTK_STOCK_QUIT, "_Quit", NULL, "Quit", G_CALLBACK(cb_menu_quit) }
80 static guint n_entries = G_N_ELEMENTS(entries);
82 static GtkWidget *get_menu(struct ui_psensor *ui)
84 GtkActionGroup *action_group;
85 GtkUIManager *menu_manager;
88 action_group = gtk_action_group_new("PsensorActions");
89 gtk_action_group_set_translation_domain(action_group, PACKAGE);
90 menu_manager = gtk_ui_manager_new();
92 gtk_action_group_add_actions(action_group, entries, n_entries, ui);
93 gtk_ui_manager_insert_action_group(menu_manager, action_group, 0);
96 gtk_ui_manager_add_ui_from_string(menu_manager, menu_desc, -1, &error);
99 g_error(_("building menus failed: %s"), error->message);
101 return gtk_ui_manager_get_widget(menu_manager, "/MainMenu");
106 on_graph_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data)
110 if (event->type != GDK_BUTTON_PRESS)
113 menu = get_menu((struct ui_psensor *)data);
115 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
116 event->button, event->time);
122 on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
124 struct ui_psensor *ui_psensor = (struct ui_psensor *)data;
126 graph_update(ui_psensor->sensors,
129 ui_psensor->main_window);
134 GtkWidget *ui_graph_create(struct ui_psensor *ui)
138 w_graph = gtk_drawing_area_new();
140 if (GTK_MAJOR_VERSION == 2)
141 g_signal_connect(GTK_WIDGET(w_graph),
143 G_CALLBACK(on_expose_event),
146 g_signal_connect(GTK_WIDGET(w_graph),
148 G_CALLBACK(on_expose_event),
151 gtk_widget_add_events(w_graph, GDK_BUTTON_PRESS_MASK);
153 g_signal_connect(GTK_WIDGET(w_graph),
154 "button_press_event",
155 (GCallback) on_graph_clicked, ui);