~ubuntu-branches/ubuntu/quantal/gnome-games/quantal-proposed

« back to all changes in this revision

Viewing changes to gnect/src/games-stock.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell, Jeremy Bicha, Robert Ancell
  • Date: 2012-11-06 10:56:12 UTC
  • mfrom: (170.1.5 quantal)
  • Revision ID: package-import@ubuntu.com-20121106105612-80ig0ec8l36noz2v
Tags: 1:3.6.0.2-0ubuntu1.1
[ Jeremy Bicha ]
* debian/patches/03_add-keywords.patch:
  - Dropped, already applied

[ Robert Ancell ]
* debian/scores/gnome-mahjongg.inst:
 - Fix name of score files (LP: #1074861)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2005 Richard Hoelscher
 
3
 * Copyright © 2006 Andreas Røsdal
 
4
 * Copyright © 2007 Christian Persch
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 *
 
20
 * Authors:
 
21
 *      Richard Hoelscher <rah@rahga.com>
 
22
 */
 
23
 
 
24
#include <config.h>
 
25
 
 
26
#include <string.h>
 
27
#include <gtk/gtk.h>
 
28
#include <glib/gi18n.h>
 
29
 
 
30
#include "games-stock.h"
 
31
 
 
32
typedef struct {
 
33
  const char *stock_id;
 
34
  const char *tooltip;
 
35
} GamesStockItemTooltip;
 
36
 
 
37
static const char *
 
38
games_stock_get_tooltip_from_stockid (const char* stockid)
 
39
{
 
40
  static const GamesStockItemTooltip stock_item_tooltip[] = {
 
41
    { GAMES_STOCK_CONTENTS,         N_("View help for this game") },
 
42
    { GAMES_STOCK_END_GAME,         N_("End the current game") },
 
43
    { GAMES_STOCK_FULLSCREEN,       N_("Toggle fullscreen mode") },
 
44
    { GAMES_STOCK_HINT,             N_("Get a hint for your next move") },
 
45
    { GAMES_STOCK_LEAVE_FULLSCREEN, N_("Leave fullscreen mode") },
 
46
    { GAMES_STOCK_NETWORK_GAME,     N_("Start a new multiplayer network game") },
 
47
    { GAMES_STOCK_NETWORK_LEAVE,    N_("End the current network game and return to network server") },
 
48
    { GAMES_STOCK_NEW_GAME,         N_("Start a new game") },
 
49
    { GAMES_STOCK_PAUSE_GAME,       N_("Pause the game") },
 
50
    { GAMES_STOCK_PLAYER_LIST,      N_("Show a list of players in the network game") },
 
51
    { GAMES_STOCK_REDO_MOVE,        N_("Redo the undone move") },
 
52
    { GAMES_STOCK_RESTART_GAME,     N_("Restart the game") },
 
53
    { GAMES_STOCK_RESUME_GAME,      N_("Resume the paused game") },
 
54
    { GAMES_STOCK_SCORES,           N_("View the scores") },
 
55
    { GAMES_STOCK_UNDO_MOVE,        N_("Undo the last move") },
 
56
    { GTK_STOCK_ABOUT,              N_("About this game") },
 
57
    { GTK_STOCK_CLOSE,              N_("Close this window") },
 
58
    { GTK_STOCK_PREFERENCES,        N_("Configure the game") },
 
59
    { GTK_STOCK_QUIT,               N_("Quit this game") },
 
60
  };
 
61
 
 
62
  guint i;
 
63
  const char *tooltip = NULL;
 
64
 
 
65
  if (!stockid)
 
66
    return NULL;
 
67
 
 
68
  for (i = 0; i < G_N_ELEMENTS (stock_item_tooltip); i++) {
 
69
    if (strcmp (stock_item_tooltip[i].stock_id, stockid) == 0) {
 
70
      tooltip = stock_item_tooltip[i].tooltip;
 
71
      break;
 
72
    }
 
73
  }
 
74
 
 
75
  return tooltip ? _(tooltip) : NULL;
 
76
}
 
77
 
 
78
static void
 
79
menu_item_select_cb (GtkWidget * widget, GtkStatusbar * statusbar)
 
80
{
 
81
  GtkAction *action;
 
82
  gchar *tooltip;
 
83
  guint context_id;
 
84
 
 
85
  context_id = gtk_statusbar_get_context_id (statusbar, "games-tooltip");
 
86
 
 
87
  action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
 
88
  g_return_if_fail (action != NULL);
 
89
 
 
90
  g_object_get (action, "tooltip", &tooltip, NULL);
 
91
 
 
92
  if (tooltip) {
 
93
    gtk_statusbar_push (statusbar, context_id, tooltip);
 
94
    g_free (tooltip);
 
95
  } else {
 
96
    const gchar *stock_tip = NULL;
 
97
    gchar *stockid;
 
98
 
 
99
    g_object_get (action, "stock-id", &stockid, NULL);
 
100
    if (stockid != NULL) {
 
101
      stock_tip = games_stock_get_tooltip_from_stockid (stockid);
 
102
      g_free (stockid);
 
103
    }
 
104
 
 
105
    if (stock_tip != NULL) {
 
106
      gtk_statusbar_push (statusbar, context_id, stock_tip);
 
107
    }
 
108
  }
 
109
}
 
110
 
 
111
static void
 
112
menu_item_deselect_cb (GtkWidget * widget, GtkStatusbar * statusbar)
 
113
{
 
114
  guint context_id;
 
115
 
 
116
  context_id = gtk_statusbar_get_context_id (statusbar, "games-tooltip");
 
117
  gtk_statusbar_pop (statusbar, context_id);
 
118
}
 
119
 
 
120
static void
 
121
connect_proxy_cb (GtkUIManager * ui_manager,
 
122
                  GtkAction * action,
 
123
                  GtkWidget * proxy, GtkWidget * statusbar)
 
124
{
 
125
  if (!GTK_IS_MENU_ITEM (proxy))
 
126
    return;
 
127
 
 
128
  g_signal_connect (proxy, "select",
 
129
                    G_CALLBACK (menu_item_select_cb), statusbar);
 
130
  g_signal_connect (proxy, "deselect",
 
131
                    G_CALLBACK (menu_item_deselect_cb), statusbar);
 
132
}
 
133
 
 
134
static void
 
135
disconnect_proxy_cb (GtkUIManager * ui_manager,
 
136
                     GtkAction * action,
 
137
                     GtkWidget * proxy, GtkWidget * statusbar)
 
138
{
 
139
  if (!GTK_IS_MENU_ITEM (proxy))
 
140
    return;
 
141
 
 
142
  g_signal_handlers_disconnect_by_func
 
143
    (proxy, G_CALLBACK (menu_item_select_cb), statusbar);
 
144
  g_signal_handlers_disconnect_by_func
 
145
    (proxy, G_CALLBACK (menu_item_deselect_cb), statusbar);
 
146
}
 
147
 
 
148
/** 
 
149
 *  Call this once, after creating the UI Manager but before 
 
150
 *  you start adding actions. Then, whenever an action is added, 
 
151
 *  connect_proxy() will set tooltips to be displayed in the statusbar.
 
152
 */
 
153
void
 
154
games_stock_prepare_for_statusbar_tooltips (GtkUIManager * ui_manager,
 
155
                                            GtkWidget * statusbar)
 
156
{
 
157
  g_signal_connect (ui_manager, "connect-proxy",
 
158
                    G_CALLBACK (connect_proxy_cb), statusbar);
 
159
  g_signal_connect (ui_manager, "disconnect-proxy",
 
160
                    G_CALLBACK (disconnect_proxy_cb), statusbar);
 
161
}
 
162
 
 
163
static void
 
164
register_stock_icon (GtkIconFactory * icon_factory,
 
165
                     const char * stock_id,
 
166
                     const char * icon_name)
 
167
{
 
168
  GtkIconSource *source;
 
169
  GtkIconSet *set;
 
170
 
 
171
  set = gtk_icon_set_new ();
 
172
 
 
173
  source = gtk_icon_source_new ();
 
174
  gtk_icon_source_set_icon_name (source, icon_name);
 
175
  gtk_icon_set_add_source (set, source);
 
176
  gtk_icon_source_free (source);
 
177
 
 
178
  gtk_icon_factory_add (icon_factory, stock_id, set);
 
179
  gtk_icon_set_unref (set);
 
180
}
 
181
 
 
182
static void
 
183
register_stock_icon_bidi (GtkIconFactory * icon_factory,
 
184
                          const char * stock_id,
 
185
                          const char * icon_name_ltr,
 
186
                          const char * icon_name_rtl)
 
187
{
 
188
  GtkIconSource *source;
 
189
  GtkIconSet *set;
 
190
 
 
191
  set = gtk_icon_set_new ();
 
192
 
 
193
  source = gtk_icon_source_new ();
 
194
  gtk_icon_source_set_icon_name (source, icon_name_ltr);
 
195
  gtk_icon_source_set_direction (source, GTK_TEXT_DIR_LTR);
 
196
  gtk_icon_source_set_direction_wildcarded (source, FALSE);
 
197
  gtk_icon_set_add_source (set, source);
 
198
  gtk_icon_source_free (source);
 
199
 
 
200
  source = gtk_icon_source_new ();
 
201
  gtk_icon_source_set_icon_name (source, icon_name_rtl);
 
202
  gtk_icon_source_set_direction (source, GTK_TEXT_DIR_RTL);
 
203
  gtk_icon_source_set_direction_wildcarded (source, FALSE);
 
204
  gtk_icon_set_add_source (set, source);
 
205
  gtk_icon_source_free (source);
 
206
 
 
207
  gtk_icon_factory_add (icon_factory, stock_id, set);
 
208
  gtk_icon_set_unref (set);
 
209
}
 
210
 
 
211
void
 
212
games_stock_init (void)
 
213
{
 
214
  /* These stocks have a gtk stock icon */
 
215
  const char *stock_icon_aliases[][2] = {
 
216
    { GAMES_STOCK_CONTENTS,         "help-contents" },
 
217
    { GAMES_STOCK_HINT,             "dialog-information" },
 
218
    { GAMES_STOCK_NEW_GAME,         "document-new" },
 
219
    { GAMES_STOCK_START_NEW_GAME,   "document-new" },
 
220
    { GAMES_STOCK_RESET,            "edit-clear" },
 
221
    { GAMES_STOCK_RESTART_GAME,     "view-refresh" },
 
222
    { GAMES_STOCK_FULLSCREEN,       "view-fullscreen" },
 
223
    { GAMES_STOCK_LEAVE_FULLSCREEN, "view-restore" },
 
224
    { GAMES_STOCK_NETWORK_GAME,     "network-idle" },
 
225
    { GAMES_STOCK_NETWORK_LEAVE,    "process-stop" },
 
226
    { GAMES_STOCK_PLAYER_LIST,      "dialog-information" },
 
227
    { GAMES_STOCK_PAUSE_GAME,       "media-playback-pause" },
 
228
  };
 
229
 
 
230
  const char *stock_icon_aliases_bidi[][3] = {
 
231
    { GAMES_STOCK_REDO_MOVE, "edit-redo", "edit-undo" },
 
232
    { GAMES_STOCK_UNDO_MOVE, "edit-undo", "edit-redo" },
 
233
    { GAMES_STOCK_RESUME_GAME, "media-playback-start", "media-playback-start" },
 
234
  };
 
235
 
 
236
  /* Private icon names */
 
237
  const char *private_icon_names[][2] = {
 
238
    { GAMES_STOCK_TELEPORT, "teleport" },
 
239
    { GAMES_STOCK_RTELEPORT, "teleport-random" },
 
240
    { GAMES_STOCK_SCORES, "scores" },
 
241
    { GAMES_STOCK_DEAL_CARDS, "cards-deal" }
 
242
  };
 
243
 
 
244
/* Use different accels on GTK/GNOME and Maemo */
 
245
 
 
246
  static const GtkStockItem games_stock_items[] = {
 
247
    { GAMES_STOCK_CONTENTS,         N_("_Contents"),          0, GDK_KEY_F1, NULL },
 
248
    { GAMES_STOCK_FULLSCREEN,       N_("_Fullscreen"),        0, GDK_KEY_F11, NULL },
 
249
    { GAMES_STOCK_HINT,             N_("_Hint"),              GDK_CONTROL_MASK, 'h', NULL },
 
250
    /* Translators: This "_New" is for the menu item 'Game->New', implies "New Game" */
 
251
    { GAMES_STOCK_NEW_GAME,         N_("_New"),               GDK_CONTROL_MASK, 'n', NULL },
 
252
    /* Translators: This "_New Game" is for the game-over dialogue */
 
253
    { GAMES_STOCK_START_NEW_GAME,   N_("_New Game"),          0, 0, NULL },
 
254
    { GAMES_STOCK_REDO_MOVE,        N_("_Redo Move"),         GDK_CONTROL_MASK | GDK_SHIFT_MASK, 'z', NULL },
 
255
    /* Translators: this is the "Reset" scores button in a scores dialogue */
 
256
    { GAMES_STOCK_RESET,            N_("_Reset"),             0, 0, NULL },
 
257
    /* Translators: "_Restart" is the menu item 'Game->Restart', implies "Restart Game" */
 
258
    { GAMES_STOCK_RESTART_GAME,     N_("_Restart"),           0, 0, NULL },
 
259
    { GAMES_STOCK_UNDO_MOVE,        N_("_Undo Move"),         GDK_CONTROL_MASK, 'z', NULL },
 
260
    { GAMES_STOCK_DEAL_CARDS,       N_("_Deal"),              GDK_CONTROL_MASK, 'd', NULL },
 
261
    { GAMES_STOCK_LEAVE_FULLSCREEN, N_("_Leave Fullscreen"),  0, GDK_KEY_F11, NULL },
 
262
    { GAMES_STOCK_NETWORK_GAME,     N_("Network _Game"),      GDK_CONTROL_MASK, 'g', NULL },
 
263
    { GAMES_STOCK_NETWORK_LEAVE,    N_("L_eave Game"),        GDK_CONTROL_MASK, 'e', NULL },
 
264
    { GAMES_STOCK_PLAYER_LIST,      N_("Player _List"),       GDK_CONTROL_MASK, 'l', NULL },
 
265
    { GAMES_STOCK_PAUSE_GAME,       N_("_Pause"),             0, GDK_KEY_Pause, NULL },
 
266
    { GAMES_STOCK_RESUME_GAME,      N_("Res_ume"),            0, GDK_KEY_Pause, NULL },
 
267
    { GAMES_STOCK_SCORES,           N_("_Scores"),            0, 0, NULL },
 
268
    { GAMES_STOCK_END_GAME,         N_("_End Game"),          0, 0, NULL },
 
269
  };
 
270
 
 
271
  guint i;
 
272
  GtkIconFactory *icon_factory;
 
273
 
 
274
  icon_factory = gtk_icon_factory_new ();
 
275
 
 
276
  for (i = 0; i < G_N_ELEMENTS (stock_icon_aliases); ++i) {
 
277
    register_stock_icon (icon_factory,
 
278
                         stock_icon_aliases[i][0],
 
279
                         stock_icon_aliases[i][1]);
 
280
  }
 
281
 
 
282
  for (i = 0; i < G_N_ELEMENTS (stock_icon_aliases_bidi); ++i) {
 
283
    register_stock_icon_bidi (icon_factory,
 
284
                              stock_icon_aliases_bidi[i][0],
 
285
                              stock_icon_aliases_bidi[i][1],
 
286
                              stock_icon_aliases_bidi[i][2]);
 
287
  }
 
288
 
 
289
  /* Register our private themeable icons */
 
290
  for (i = 0; i < G_N_ELEMENTS (private_icon_names); i++) {
 
291
    register_stock_icon (icon_factory,
 
292
                         private_icon_names[i][0],
 
293
                         private_icon_names[i][1]);
 
294
  }
 
295
 
 
296
  gtk_icon_factory_add_default (icon_factory);
 
297
  g_object_unref (icon_factory);
 
298
 
 
299
  /* GtkIconTheme will then look in our custom hicolor dir
 
300
   * for icons as well as the standard search paths.
 
301
   */
 
302
  /* FIXME: multi-head! */
 
303
  gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), ICON_THEME_DIRECTORY);
 
304
 
 
305
  gtk_stock_add_static (games_stock_items, G_N_ELEMENTS (games_stock_items));
 
306
}
 
307
 
 
308
/* Returns a GPL N+ license string for a specific game. */
 
309
static gchar *
 
310
games_get_license_version (const gchar * game_name,
 
311
                           int version)
 
312
{
 
313
  gchar *license_trans, *license_str;
 
314
 
 
315
  static const char license0[] =
 
316
    /* %s is replaced with the name of the game in gnome-games. */
 
317
    N_("%s is free software; you can redistribute it and/or modify "
 
318
       "it under the terms of the GNU General Public License as published by "
 
319
       "the Free Software Foundation; either version %d of the License, or "
 
320
       "(at your option) any later version.");
 
321
  static const char license1[] =
 
322
    N_("%s is distributed in the hope that it will be useful, "
 
323
       "but WITHOUT ANY WARRANTY; without even the implied warranty of "
 
324
       "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the "
 
325
       "GNU General Public License for more details.");
 
326
  static const char license2[] =
 
327
    N_("You should have received a copy of the GNU General Public License "
 
328
       "along with %s; if not, write to the Free Software Foundation, Inc., "
 
329
       "51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA");
 
330
  static const char license3[] =
 
331
    N_("You should have received a copy of the GNU General Public License "
 
332
       "along with this program.  If not, see <http://www.gnu.org/licenses/>.");
 
333
 
 
334
  if (version >= 3)
 
335
    license_trans = g_strjoin ("\n\n", _(license0), _(license1), _(license3), NULL);
 
336
  else
 
337
    license_trans = g_strjoin ("\n\n", _(license0), _(license1), _(license2), NULL);
 
338
 
 
339
  license_str =
 
340
    g_strdup_printf (license_trans, game_name, version, game_name, game_name);
 
341
  g_free (license_trans);
 
342
 
 
343
  return license_str;
 
344
}
 
345
 
 
346
/**
 
347
 * gamess_get_licence:
 
348
 *
 
349
 * Returns: a newly allocated string with a GPL licence notice. The GPL version used
 
350
 *   depends on the game and the configure options and is determined from
 
351
 *   games_runtime_get_gpl_version()
 
352
 */
 
353
gchar *
 
354
games_get_license (const gchar * game_name)
 
355
{
 
356
  return games_get_license_version (game_name, 2);
 
357
}