1 /*
2 
3   Copyright (c) 2003-2013 uim Project https://github.com/uim/uim
4 
5   All rights reserved.
6 
7   Redistribution and use in source and binary forms, with or without
8   modification, are permitted provided that the following conditions
9   are met:
10 
11   1. Redistributions of source code must retain the above copyright
12      notice, this list of conditions and the following disclaimer.
13   2. Redistributions in binary form must reproduce the above copyright
14      notice, this list of conditions and the following disclaimer in the
15      documentation and/or other materials provided with the distribution.
16   3. Neither the name of authors nor the names of its contributors
17      may be used to endorse or promote products derived from this software
18      without specific prior written permission.
19 
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
21   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26   OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30   SUCH DAMAGE.
31 
32 */
33 
34 #ifdef HAVE_CONFIG_H
35 #  include <config.h>
36 #endif
37 
38 #include <stdlib.h>
39 #include <locale.h>
40 #include <panel-applet.h>
41 #include <uim/uim.h>
42 
43 PanelApplet *uimapplet;
44 
45 static void exec_switcher(BonoboUIComponent *uic, gpointer data, const gchar *verbname);
46 static void exec_pref(BonoboUIComponent *uic, gpointer data, const gchar *verbname);
47 static void exec_dic(BonoboUIComponent *uic, gpointer data, const gchar *verbname);
48 static void exec_pad(BonoboUIComponent *uic, gpointer data, const gchar *verbname);
49 static void exec_hand(BonoboUIComponent *uic, gpointer data, const gchar *verbname);
50 static void exec_help(BonoboUIComponent *uic, gpointer data, const gchar *verbname);
51 static void display_about_dialog(BonoboUIComponent *uic, gpointer data, const gchar *verbname);
52 
53 extern GtkWidget *uim_toolbar_applet_new(void);
54 extern void uim_toolbar_launch_helper_application(const char *command);
55 
56 
57 static const BonoboUIVerb uim_menu_verbs[] = {
58   BONOBO_UI_VERB("UimExecSwitcher", exec_switcher),
59   BONOBO_UI_VERB("UimExecPref", exec_pref),
60   BONOBO_UI_VERB("UimExecDic", exec_dic),
61   BONOBO_UI_VERB("UimExecPad", exec_pad),
62   BONOBO_UI_VERB("UimExecHand", exec_hand),
63   BONOBO_UI_VERB("UimExecHelp", exec_help),
64   BONOBO_UI_VERB("UimAbout", display_about_dialog),
65   BONOBO_UI_VERB_END
66 };
67 
68 
69 static const char uim_menu_xml[] =
70   "<popup name=\"button3\">\n"
71   "   <menuitem name=\"Switcher Item\" verb=\"UimExecSwitcher\" _label=\"Switch input method\"\n"
72   "             pixtype=\"filename\" pixname=\""UIM_PIXMAPSDIR"/im_switcher.png\"/>\n"
73   "   <menuitem name=\"Pref Item\" verb=\"UimExecPref\" _label=\"Preference\"\n"
74   "             pixtype=\"stock\" pixname=\"preferences\"/>\n"
75   "   <menuitem name=\"Dic Item\" verb=\"UimExecDic\" _label=\"Japanese dictionary editor\"\n"
76   "             pixtype=\"filename\" pixname=\""UIM_PIXMAPSDIR"/uim-dict.png\"/>\n"
77   "   <menuitem name=\"Pad Item\" verb=\"UimExecPad\" _label=\"Input pad\"\n"
78   "             pixtype=\"stock\" pixname=\"bold\"/>\n"
79   "   <menuitem name=\"Hand Item\" verb=\"UimExecHand\" _label=\"Handwriting input pad\"\n"
80   "             pixtype=\"stock\" pixname=\"edit\"/>\n"
81   "   <menuitem name=\"Help Item\" verb=\"UimExecHelp\" _label=\"Help\"\n"
82   "             pixtype=\"stock\" pixname=\"help\"/>\n"
83   "   <menuitem name=\"About Item\" verb=\"UimAbout\" _label=\"About\"\n"
84   "             pixtype=\"stock\" pixname=\"gnome-stock-about\"/>\n"
85   "</popup>\n";
86 
87 
88 
89 static void
exec_switcher(BonoboUIComponent * uic,gpointer data,const gchar * verbname)90 exec_switcher(BonoboUIComponent *uic, gpointer data, const gchar *verbname)
91 {
92   uim_toolbar_launch_helper_application("uim-im-switcher-gtk");
93 }
94 
95 static void
exec_pref(BonoboUIComponent * uic,gpointer data,const gchar * verbname)96 exec_pref(BonoboUIComponent *uic, gpointer data, const gchar *verbname)
97 {
98   uim_toolbar_launch_helper_application("uim-pref-gtk");
99 }
100 
101 static void
exec_dic(BonoboUIComponent * uic,gpointer data,const gchar * verbname)102 exec_dic(BonoboUIComponent *uic, gpointer data, const gchar *verbname)
103 {
104   uim_toolbar_launch_helper_application("uim-dict-gtk");
105 }
106 
107 static void
exec_pad(BonoboUIComponent * uic,gpointer data,const gchar * verbname)108 exec_pad(BonoboUIComponent *uic, gpointer data, const gchar *verbname)
109 {
110   uim_toolbar_launch_helper_application("uim-input-pad-ja");
111 }
112 
113 static void
exec_hand(BonoboUIComponent * uic,gpointer data,const gchar * verbname)114 exec_hand(BonoboUIComponent *uic, gpointer data, const gchar *verbname)
115 {
116   uim_toolbar_launch_helper_application("uim-tomoe-gtk");
117 }
118 
119 static void
exec_help(BonoboUIComponent * uic,gpointer data,const gchar * verbname)120 exec_help(BonoboUIComponent *uic, gpointer data, const gchar *verbname)
121 {
122   uim_toolbar_launch_helper_application("uim-help");
123 }
124 
125 /* Just the about window... If it's already open, just focus it */
126 static void
display_about_dialog(BonoboUIComponent * uic,gpointer data,const gchar * verbname)127 display_about_dialog(BonoboUIComponent *uic, gpointer data,
128 		     const gchar *verbname)
129 {
130   GdkPixbuf *icon = NULL;
131   const gchar *authors[] = {"uim Project", NULL};
132   /* Feel free to put your names here translators */
133   gchar *translators = _("TRANSLATORS");
134   icon = gdk_pixbuf_new_from_file(UIM_PIXMAPSDIR "/uim-icon.png", NULL);
135 
136   gtk_show_about_dialog(NULL,
137 			   "program-name", _("uim Applet"),
138 			   "version", VERSION,
139 			   "copyright", "Copyright \xc2\xa9 2003-2013 uim Project.",
140 			   "comments", _("Applet for indicating uim's status"),
141 			   "authors", authors,
142 			   "translator-credits",
143 			       strcmp("TRANSLATORS", translators) ? translators
144 			   				      : NULL,
145 			   "icon", icon,
146 			   "logo", icon, NULL);
147 
148   if (icon) {
149     g_object_unref(icon);
150   }
151 }
152 
153 static gboolean
uim_applet_new(PanelApplet * applet,const gchar * iid,gpointer data)154 uim_applet_new(PanelApplet *applet, const gchar *iid, gpointer data)
155 {
156   GtkWidget *toolbar;
157   uimapplet = applet;
158 
159   if (strcmp(iid, "OAFIID:GNOME_UimApplet") != 0)
160     return FALSE;
161 
162   uim_init();
163 
164   toolbar = (GtkWidget*)uim_toolbar_applet_new();
165 
166   gtk_container_add(GTK_CONTAINER(applet), toolbar);
167 
168   gtk_widget_show_all(GTK_WIDGET(applet));
169 
170   panel_applet_setup_menu(applet, uim_menu_xml, uim_menu_verbs, toolbar);
171 #if LIBPANEL_APPLET_HAVE_SET_BACKGROUND_WIDGET
172   panel_applet_set_background_widget(applet, GTK_WIDGET(applet));
173 #endif
174 
175   return TRUE;
176 }
177 
178 
179 
180 PANEL_APPLET_BONOBO_FACTORY("OAFIID:GNOME_UimApplet_Factory",
181                             PANEL_TYPE_APPLET,
182                             "uim Applet for GNOME",
183                             "0",
184                             (PanelAppletFactoryCallback)uim_applet_new,
185                             NULL)
186