added static to fcts
[psensor.git] / src / ui_graph.c
1 /*
2     Copyright (C) 2010-2011 jeanfi@gmail.com
3
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.
8
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.
13
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
17     02110-1301 USA
18 */
19
20 #include "graph.h"
21 #include "ui_graph.h"
22 #include "ui_pref.h"
23
24 static void cb_menu_quit(GtkMenuItem *mi, gpointer data)
25 {
26         ui_psensor_quit();
27 }
28
29 static void cb_preferences(GtkMenuItem *mi, gpointer data)
30 {
31         ui_pref_dialog_run((struct ui_psensor *)data);
32 }
33
34 static const char *menu_desc =
35 "<ui>"
36 "  <popup name='MainMenu'>"
37 "      <menuitem name='Preferences' action='PreferencesAction' />"
38 "      <separator />"
39 "      <menuitem name='Quit' action='QuitAction' />"
40 "  </popup>"
41 "</ui>";
42
43 static GtkActionEntry entries[] = {
44   { "PsensorMenuAction", NULL, "_Psensor" }, /* name, stock id, label */
45
46   { "PreferencesAction", GTK_STOCK_PREFERENCES,     /* name, stock id */
47     "_Preferences", NULL,                           /* label, accelerator */
48     "Preferences",                                  /* tooltip */
49     G_CALLBACK(cb_preferences) },
50
51   { "QuitAction",
52     GTK_STOCK_QUIT, "_Quit", NULL, "Quit", G_CALLBACK(cb_menu_quit) }
53 };
54 static guint n_entries = G_N_ELEMENTS(entries);
55
56 static GtkWidget *get_menu(struct ui_psensor *ui)
57 {
58         GtkActionGroup      *action_group;
59         GtkUIManager        *menu_manager;
60         GError              *error;
61
62         action_group = gtk_action_group_new("PsensorActions");
63         gtk_action_group_set_translation_domain(action_group, PACKAGE);
64         menu_manager = gtk_ui_manager_new();
65
66         gtk_action_group_add_actions(action_group, entries, n_entries, ui);
67         gtk_ui_manager_insert_action_group(menu_manager, action_group, 0);
68
69         error = NULL;
70         gtk_ui_manager_add_ui_from_string(menu_manager, menu_desc, -1, &error);
71
72         if (error)
73                 g_error(_("building menus failed: %s"), error->message);
74
75         return gtk_ui_manager_get_widget(menu_manager, "/MainMenu");
76 }
77
78
79 static int 
80 on_graph_clicked(GtkWidget *widget, GdkEventButton *event, gpointer data)
81 {
82         GtkWidget *menu;
83
84         if (event->type != GDK_BUTTON_PRESS)
85                 return FALSE;
86
87         menu = get_menu((struct ui_psensor *)data);
88
89         gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
90                        event->button, event->time);
91
92         return TRUE;
93 }
94
95 static gboolean
96 on_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
97 {
98         struct ui_psensor *ui_psensor = (struct ui_psensor *)data;
99
100         graph_update(ui_psensor->sensors,
101                      ui_psensor->w_graph, ui_psensor->config);
102
103         return FALSE;
104 }
105
106 GtkWidget *ui_graph_create(struct ui_psensor * ui)
107 {
108         GtkWidget *w_graph;
109
110         w_graph = gtk_drawing_area_new();
111
112         g_signal_connect(GTK_WIDGET(w_graph),
113                          "expose-event", G_CALLBACK(on_expose_event), ui);
114
115         gtk_widget_add_events(w_graph, GDK_BUTTON_PRESS_MASK);
116
117         g_signal_connect(GTK_WIDGET(w_graph),
118                            "button_press_event",
119                            (GCallback) on_graph_clicked, ui);
120
121         return w_graph;
122 }