Use gtk_show_uri instead of libgnome-ui/exo.
[dhcpcd-ui] / menu.c
1 /*
2  * dhcpcd-gtk
3  * Copyright 2009 Roy Marples <roy@marples.name>
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26
27 #include <gtk/gtk.h>
28
29 #include "config.h"
30 #include "menu.h"
31
32 static const char *copyright = "Copyright (c) 2009 Roy Marples";
33
34 static const char *authors[] = {
35         "Roy Marples <roy@marples.name>",
36         NULL
37 };
38 static const char *license =
39         "Licensed under the 2 clause BSD license.\n"
40         "\n"
41         "Redistribution and use in source and binary forms, with or without\n"
42         "modification, are permitted provided that the following conditions\n"
43         "are met:\n"
44         "1. Redistributions of source code must retain the above copyright\n"
45         "   notice, this list of conditions and the following disclaimer.\n"
46         "2. Redistributions in binary form must reproduce the above copyright\n"
47         "   notice, this list of conditions and the following disclaimer in the\n"
48         "   documentation and/or other materials provided with the distribution.\n"
49         "\n"
50         "THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n"
51         "ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n"
52         "IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n"
53         "ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n"
54         "FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n"
55         "DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n"
56         "OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n"
57         "HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n"
58         "LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n"
59         "OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"
60         "SUCH DAMAGE.";
61
62 /* Should be in a header */
63 void notify_close(void);
64
65 static void
66 on_quit(_unused GtkMenuItem *item, _unused gpointer data)
67 {
68         gtk_main_quit();
69 }
70
71 static void
72 on_help(_unused GtkMenuItem *item, _unused gpointer data)
73 {
74 }
75
76 static void
77 url_show(GtkAboutDialog *dialog, const char *url)
78 {
79         GdkScreen *screen;
80
81         screen = gtk_widget_get_screen(GTK_WIDGET(dialog));
82         gtk_show_uri(screen, url, GDK_CURRENT_TIME, NULL);
83 }
84
85 static void
86 email_hook(GtkAboutDialog *dialog, const char *url, _unused gpointer p)
87 {
88         char *address;
89
90         address = g_strdup_printf("mailto:%s", url);
91         url_show(dialog, address);
92         g_free(address);
93 }
94
95 static void
96 url_hook(GtkAboutDialog *dialog, const char *url, _unused gpointer p)
97 {
98         url_show(dialog, url);
99 }
100
101 static void
102 on_about(_unused GtkMenuItem *item, _unused gpointer data)
103 {
104         gtk_window_set_default_icon_name(GTK_STOCK_NETWORK);
105         gtk_about_dialog_set_email_hook(email_hook, NULL, NULL);
106         gtk_about_dialog_set_url_hook(url_hook, NULL, NULL);
107         gtk_show_about_dialog(NULL,
108                               "version", VERSION,
109                               "copyright", copyright,
110                               "license", license,
111                               "website-label", "dhcpcd GTK Website",
112                               "website", "http://roy.marples.name/projects/dhcpcd",
113                               "authors", authors,
114                               "wrap-license", TRUE,
115                               "logo-icon-name", GTK_STOCK_NETWORK,
116                               NULL);
117 }
118
119 static void
120 on_activate(_unused GtkStatusIcon *icon, _unused guint button, _unused guint32 atime, _unused gpointer data)
121 {
122         notify_close();
123 }
124
125 static void
126 on_popup(GtkStatusIcon *icon, guint button, guint32 atime, gpointer data)
127 {
128         GtkMenu *menu;
129         GtkWidget *item, *image;
130
131         notify_close();
132
133         menu = (GtkMenu *)gtk_menu_new();
134
135         item = gtk_image_menu_item_new_with_mnemonic("_Quit");
136         image = gtk_image_new_from_icon_name(GTK_STOCK_QUIT,
137                                              GTK_ICON_SIZE_MENU);
138         gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
139         g_signal_connect(G_OBJECT(item), "activate",
140                          G_CALLBACK(on_quit), icon);
141         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
142
143         item = gtk_separator_menu_item_new();
144         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
145
146         item = gtk_image_menu_item_new_with_mnemonic("_Help");
147         image = gtk_image_new_from_icon_name(GTK_STOCK_HELP,
148                                              GTK_ICON_SIZE_MENU);
149         gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
150         g_signal_connect(G_OBJECT(item), "activate",
151                          G_CALLBACK(on_help), icon);
152         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
153
154         item = gtk_image_menu_item_new_with_mnemonic("_About");
155         image = gtk_image_new_from_icon_name(GTK_STOCK_ABOUT,
156                                              GTK_ICON_SIZE_MENU);
157         gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
158         g_signal_connect(G_OBJECT(item), "activate",
159                          G_CALLBACK(on_about), icon);
160         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
161
162         gtk_widget_show_all(GTK_WIDGET(menu));
163         gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
164                         gtk_status_icon_position_menu, data, button, atime);
165         if (button == 0)
166                 gtk_menu_shell_select_first(GTK_MENU_SHELL(menu), FALSE);
167 }
168
169 void
170 menu_init(GtkStatusIcon *icon)
171 {
172         g_signal_connect_object(G_OBJECT(icon), "activate",
173                                 G_CALLBACK(on_activate), icon, 0);
174         g_signal_connect_object(G_OBJECT(icon), "popup_menu",
175                                 G_CALLBACK(on_popup), icon, 0);
176 }