~ubuntu-branches/ubuntu/maverick/gnome-media-player/maverick

« back to all changes in this revision

Viewing changes to src/gnome-media-player.cc

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung, Bilal Akhtar, Benjamin Drung
  • Date: 2010-07-20 10:27:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720102712-g7h0kn9b2w3zel3k
Tags: 0.1.3-0ubuntu1
[ Bilal Akhtar ]
* New Upstream release (LP: #606870).
* debian/patches/add-translation-support.patch:
  - This patch enables translation support in the application
    by setting the Gtk::Builder object translation domain to
    that of the application.
* debian/patches/vlc-1.1.0-upgrade.patch:
  - This patch fixes FTBFS in maverick by making GNOME Media Player
    use libvlc 1.1.0, which is the version of VLC in maverick.
* Removed unneeded build-dependency on libgstreamermm-0.10-dev.
* Added build-dependency on libgstreamer0.10-dev and 
  libgstreamer-plugins-base0.10-dev .
* Bumped Standards-Version to 3.9.0 (no changes needed).

[ Benjamin Drung ]
* Switch from debhelper 5 to 7.
* Replace cdbs by simple dh rule and drop build-dependency autotools-dev.
* Add build-dependency intltool.
* Remove COPYING and INSTALL from installation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "main_window.h"
22
22
#include "config.h"
23
23
#include <unique/unique.h>
 
24
#include <gconf/gconf-client.h>
 
25
#include <gconf/gconf-value.h>
24
26
#include <gst/gst.h>
25
27
 
26
28
#ifdef ENABLE_NLS
27
29
#  include <libintl.h>
 
30
#  define _(String) gettext (String)
28
31
#endif
29
32
 
30
33
#define UI_FILE PACKAGE_DATA_DIR"/gnome-media-player/ui/gnome-media-player.ui"
 
34
#define WINDOWICON PACKAGE_DATA_DIR"/gnome-media-player/icons/gnome-media-player-small.png"
31
35
 
32
36
Glib::RefPtr<Gtk::Builder>              builder;
33
37
Glib::RefPtr<Gtk::UIManager>    ui_manager;
53
57
Glib::RefPtr<Gtk::Action>               action_restart_engine;
54
58
Glib::RefPtr<Gtk::Action>               action_stop;
55
59
Glib::RefPtr<Gtk::ToggleAction> action_deinterlace;
 
60
Glib::RefPtr<Gtk::ToggleAction> action_show_drawable;
56
61
 
57
62
Glib::ustring   engine_type;
58
63
bool                    hide_volume_controls = false;
59
64
bool                    next = true;
60
65
bool                    deinterlace = false;
61
66
MainWindow*             main_window = NULL;
 
67
bool                    gtk_initialised = false;
 
68
bool                    on_top = false;
 
69
GConfClient*    gconf_client;
62
70
 
63
71
enum
64
72
{
108
116
        return response;
109
117
}
110
118
 
111
 
void show_error_dialog(const Glib::ustring& message)
 
119
void handle_error_message(const Glib::ustring& message)
112
120
{
113
 
        g_debug("Showing message: '%s'", message.c_str());
 
121
        g_message("Error: '%s'", message.c_str());
114
122
 
115
 
        if (main_window != NULL)
116
 
        {
117
 
                Gtk::MessageDialog dialog(*main_window, message, false, Gtk::MESSAGE_ERROR);
118
 
                dialog.set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
119
 
                dialog.set_title(PACKAGE_NAME);
120
 
                dialog.run();
121
 
        }
122
 
        else
123
 
        {
124
 
                Gtk::MessageDialog dialog(message, false, Gtk::MESSAGE_ERROR);
125
 
                dialog.set_title(PACKAGE_NAME);
126
 
                dialog.run();
 
123
        if (gtk_initialised)
 
124
        {
 
125
                if (main_window != NULL)
 
126
                {
 
127
                        Gtk::MessageDialog dialog(*main_window, message, false, Gtk::MESSAGE_ERROR);
 
128
                        dialog.set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
 
129
                        dialog.set_title(PACKAGE_NAME);
 
130
                        dialog.run();
 
131
                }
 
132
                else
 
133
                {
 
134
                        Gtk::MessageDialog dialog(message, false, Gtk::MESSAGE_ERROR);
 
135
                        dialog.set_title(PACKAGE_NAME);
 
136
                        dialog.run();
 
137
                }
127
138
        }
128
139
}
129
140
 
135
146
        }
136
147
        catch (const Exception& exception)
137
148
        {
138
 
                show_error_dialog(exception.what());
 
149
                handle_error_message(exception.what());
139
150
        }
140
151
        catch (const Glib::Error& exception)
141
152
        {
142
 
                show_error_dialog(exception.what());
 
153
                handle_error_message(exception.what());
143
154
        }
144
155
        catch (...)
145
156
        {
146
 
                show_error_dialog("Unhandled exception");
 
157
                handle_error_message("Unhandled exception");
147
158
        }
148
159
}
149
160
 
157
168
                {
158
169
                        throw Exception("XInitThreads() failed");
159
170
                }
160
 
 
161
 
                Gtk::Main main(argc, argv);
162
 
                gst_init(&argc, &argv);
163
 
 
 
171
                setlocale(LC_ALL, "");
 
172
                setlocale(LC_MESSAGES, "");
 
173
                bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
 
174
                textdomain (GETTEXT_PACKAGE);
 
175
                
 
176
                gconf_client = gconf_client_get_default();
 
177
                if (gconf_client_get_bool(gconf_client,(gchar*)"/apps/gnome-media-player/hide-volume-controls",NULL))
 
178
                {
 
179
                        hide_volume_controls = true;
 
180
                }
 
181
                if (gconf_client_get_bool(gconf_client,(gchar*)"/apps/gnome-media-player/on-top",NULL))
 
182
                {
 
183
                        on_top = true;
 
184
                }
 
185
                
164
186
                sigc::connection connection_on_error_handler = Glib::add_exception_handler(&on_error);
 
187
                Glib::OptionGroup option_group(PACKAGE_NAME, "GNOME Media Player options", _("Show GNOME Media Player help options"));
165
188
 
166
 
                Glib::OptionGroup option_group(PACKAGE_NAME, _("Show GNOME Media Player help options"));
 
189
                Glib::OptionEntry on_top_option_entry;
 
190
                on_top_option_entry.set_description(_("Set the window to always remain on top of other windows"));
 
191
                on_top_option_entry.set_long_name("on-top");
 
192
                option_group.add_entry(on_top_option_entry, on_top);
167
193
 
168
194
                Glib::OptionEntry hide_volume_controls_option_entry;
169
195
                hide_volume_controls_option_entry.set_description(_("Hide the volume controls from the user interface"));
187
213
                remaining_option_entry.set_long_name(G_OPTION_REMAINING);
188
214
                option_group.add_entry(remaining_option_entry, args);
189
215
 
190
 
                Glib::OptionContext option_context("[FILE...]");
 
216
                Glib::OptionContext option_context("[FILES...]");
191
217
                option_context.set_description("A simple media player for GNOME");
 
218
                option_context.set_help_enabled(true);
 
219
                option_context.set_ignore_unknown_options(false);
192
220
                option_context.set_main_group(option_group);
193
221
 
194
 
                option_context.parse(argc, argv);
 
222
                // Do this so we can show a Gtk::MessageDialog on error
 
223
                gtk_initialised = gtk_init_check(&argc, &argv);
 
224
 
 
225
                Gtk::Main main(argc, argv, option_context);
 
226
                gst_init(&argc, &argv);
195
227
 
196
228
                UniqueApp* unique_application = unique_app_new_with_commands(
197
229
                    "org.lamothe.gnome-media-player", NULL,
232
264
                {
233
265
                        builder = Gtk::Builder::create_from_file(UI_FILE);
234
266
                        ui_manager = Gtk::UIManager::create();
235
 
 
 
267
                        builder->set_translation_domain(GETTEXT_PACKAGE);
236
268
                        Gtk::RadioButtonGroup   engine_group;
237
269
 
238
270
                        action_about                    = Gtk::Action::create("About", Gtk::Stock::ABOUT);
255
287
                        action_quit                             = Gtk::Action::create("Quit", Gtk::Stock::QUIT);
256
288
                        action_restart_engine   = Gtk::Action::create("RestartEngine", Gtk::Stock::REFRESH, _("_Restart Engine"));
257
289
                        action_stop                             = Gtk::Action::create("Stop", Gtk::Stock::MEDIA_STOP);
 
290
                        action_show_drawable    = Gtk::ToggleAction::create("ToggleDrawable", _("Show Video"), _("Show/hide video widget"), true);
258
291
 
259
292
                        action_group                    = Gtk::ActionGroup::create();
260
 
                        action_group->add(Gtk::Action::create("File", Gtk::Stock::FILE, _("_File")));
 
293
                        action_group->add(Gtk::Action::create("File", _("_File"), _("_File")));
261
294
                        action_group->add(Gtk::Action::create("View", _("_View")));
262
295
                        action_group->add(Gtk::Action::create("Engine", _("_Engine")));
263
 
                        action_group->add(Gtk::Action::create("Help", Gtk::Stock::HELP));
 
296
                        action_group->add(Gtk::Action::create("Help", _("_Help")));
264
297
                        action_group->add(action_about, Gtk::AccelKey("F1"));
265
298
                        action_group->add(action_backward, Gtk::AccelKey("<control>Left"));
266
299
                        action_group->add(action_controls, Gtk::AccelKey("c"));
281
314
                        action_group->add(action_quit);
282
315
                        action_group->add(action_stop);
283
316
                        action_group->add(action_restart_engine, Gtk::AccelKey("F5"));
 
317
                        action_group->add(action_show_drawable);
284
318
 
285
319
                        action_controls->set_active(true);
286
 
 
 
320
                        builder->get_widget_derived("main_window", main_window);
287
321
                        action_quit->signal_activate().connect(sigc::ptr_fun(Gtk::Main::quit));
288
 
                        builder->get_widget_derived("main_window", main_window);
 
322
                        
289
323
                        main_window->show();
290
 
 
 
324
                        
291
325
                        if (engine_type == "vlc")
292
326
                        {
293
327
                                action_engine_vlc->activate();
300
334
                        {
301
335
                                action_engine_xine->activate();
302
336
                        }
303
 
                        else if (engine_type.empty() || engine_type == "auto")
 
337
                        else if (engine_type == "auto")
304
338
                        {
305
339
                                action_engine_auto->activate();
306
340
                        }
 
341
                        else if (engine_type.empty())
 
342
                        {
 
343
                                if (gconf_client_get_string(gconf_client,(gchar*)"/apps/gnome-media-player/engine",NULL))
 
344
                                {
 
345
                                        if (!strcmp(gconf_client_get_string(gconf_client,(gchar*)"/apps/gnome-media-player/engine",NULL), "auto"))
 
346
                                        {
 
347
                                                action_engine_auto->activate();
 
348
                                        }
 
349
                                        else if (!strcmp(gconf_client_get_string(gconf_client,(gchar*)"/apps/gnome-media-player/engine",NULL), "vlc"))
 
350
                                        {
 
351
                                                action_engine_vlc->activate();
 
352
                                        }
 
353
                                        else if (!strcmp(gconf_client_get_string(gconf_client,(gchar*)"/apps/gnome-media-player/engine",NULL), "gstreamer"))
 
354
                                        {
 
355
                                                action_engine_gstreamer->activate();
 
356
                                        }
 
357
                                        else if (!strcmp(gconf_client_get_string(gconf_client,(gchar*)"/apps/gnome-media-player/engine",NULL), "xine"))
 
358
                                        {
 
359
                                                action_engine_xine->activate();
 
360
                                        }
 
361
                                        else
 
362
                                        {
 
363
                                                action_engine_auto->activate();
 
364
                                        }
 
365
                                }
 
366
                                else
 
367
                                {
 
368
                                        action_engine_auto->activate();
 
369
                                }
 
370
                        }
307
371
                        else
308
372
                        {
309
373
                                throw Exception(_("Unknown engine type"));
324
388
 
325
389
                        action_pause->set_active(true);
326
390
                        action_play->activate();
327
 
 
 
391
                        
 
392
                        main_window->set_icon_from_file(WINDOWICON);
 
393
                        
328
394
                        main.run(*main_window);
329
395
                }
330
396
        }
331
397
        catch (const Exception& exception)
332
398
        {
333
 
                show_error_dialog(exception.what());
 
399
                handle_error_message(exception.what());
334
400
        }
335
401
        catch (const Glib::Error& exception)
336
402
        {
337
 
                show_error_dialog(exception.what());
 
403
                handle_error_message(exception.what());
338
404
        }
339
405
        catch (...)
340
406
        {
341
 
                show_error_dialog("Unhandled exception");
 
407
                handle_error_message("Unhandled exception");
342
408
        }
343
409
        
344
410
        return 0;