1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Copyright (C) 2001-2007 Bastien Nocera <hadess@hadess.net>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
* The Totem project hereby grant permission for non-gpl compatible GStreamer
20
* plugins to be used and distributed together with GStreamer and Totem. This
21
* permission are above and beyond the permissions granted by the GPL license
22
* Totem is covered by.
24
* Monday 7th February 2005: Christian Schaller: Add exception clause.
25
* See license_change file for details.
32
#include <glib-object.h>
33
#include <glib/gi18n.h>
38
#ifdef GDK_WINDOWING_X11
44
#include "totem-private.h"
45
#include "totem-interface.h"
46
#include "totem-options.h"
47
#include "totem-menu.h"
48
#include "totem-session.h"
49
#include "totem-uri.h"
50
#include "totem-preferences.h"
51
#include "totem-sidebar.h"
52
#include "video-utils.h"
54
static gboolean startup_called = FALSE;
56
/* Debug log message handler: discards debug messages unless Totem is run with TOTEM_DEBUG=1.
57
* If we're building in the source tree, enable debug messages by default. */
59
debug_handler (const char *log_domain,
60
GLogLevelFlags log_level,
64
static int debug = -1;
67
debug = g_settings_get_boolean (settings, "debug");
70
g_log_default_handler (log_domain, log_level, message, NULL);
74
app_init (Totem *totem, char **argv)
76
GtkSettings *gtk_settings;
79
if (gtk_clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS)
80
g_warning ("gtk-clutter failed to initialise, expect problems from here on.");
82
gtk_settings = gtk_settings_get_default ();
83
g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", TRUE, NULL);
85
/* Debug log handling */
86
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, (GLogFunc) debug_handler, totem->settings);
89
totem->xml = totem_interface_load ("totem.ui", TRUE, NULL, totem);
90
if (totem->xml == NULL)
91
totem_action_exit (NULL);
93
totem->win = GTK_WIDGET (gtk_builder_get_object (totem->xml, "totem_main_window"));
94
gtk_window_set_hide_titlebar_when_maximized (GTK_WINDOW (totem->win), TRUE);
95
g_object_bind_property (G_OBJECT (totem), "fullscreen",
96
G_OBJECT (totem->win), "show-menubar",
97
G_BINDING_INVERT_BOOLEAN);
100
totem_ui_manager_setup (totem);
103
playlist_widget_setup (totem);
105
/* The rest of the widgets */
106
totem->state = STATE_STOPPED;
107
totem->seek = GTK_WIDGET (gtk_builder_get_object (totem->xml, "tmw_seek_hscale"));
108
totem->seekadj = gtk_range_get_adjustment (GTK_RANGE (totem->seek));
109
totem->volume = GTK_WIDGET (gtk_builder_get_object (totem->xml, "tmw_volume_button"));
110
totem->statusbar = GTK_WIDGET (gtk_builder_get_object (totem->xml, "tmw_statusbar"));
111
totem->seek_lock = FALSE;
112
totem->fs = totem_fullscreen_new (GTK_WINDOW (totem->win));
113
gtk_scale_button_set_adjustment (GTK_SCALE_BUTTON (totem->fs->volume),
114
gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (totem->volume)));
115
gtk_range_set_adjustment (GTK_RANGE (totem->fs->seek), totem->seekadj);
117
totem_session_setup (totem, argv);
118
totem_setup_file_monitoring (totem);
119
totem_setup_file_filters ();
120
totem_app_menu_setup (totem);
121
totem_callback_connect (totem);
123
sidebar_pageid = totem_setup_window (totem);
126
if (optionstate.fullscreen == FALSE) {
127
gtk_widget_show (totem->win);
128
totem_gdk_window_set_waiting_cursor (gtk_widget_get_window (totem->win));
130
gtk_widget_realize (totem->win);
133
totem->controls_visibility = TOTEM_CONTROLS_UNDEFINED;
135
/* Show ! (again) the video widget this time. */
136
video_widget_create (totem);
137
gtk_widget_grab_focus (GTK_WIDGET (totem->bvw));
138
totem_fullscreen_set_video_widget (totem->fs, totem->bvw);
140
if (optionstate.fullscreen != FALSE) {
141
gtk_widget_show (totem->win);
143
totem_action_fullscreen (totem, TRUE);
146
/* The prefs after the video widget is connected */
147
totem->prefs_xml = totem_interface_load ("preferences.ui", TRUE, NULL, totem);
149
totem_setup_preferences (totem);
151
totem_setup_recent (totem);
153
/* Command-line handling */
154
totem_options_process_late (totem, &optionstate);
156
/* Initialise all the plugins, and set the default page, in case
157
* it comes from a plugin */
158
totem_object_plugins_init (totem);
159
totem_sidebar_set_current_page (totem, sidebar_pageid, FALSE);
160
g_free (sidebar_pageid);
162
if (totem->session_restored != FALSE) {
163
totem_session_restore (totem, optionstate.filenames);
164
} else if (optionstate.filenames != NULL && totem_action_open_files (totem, optionstate.filenames)) {
165
totem_action_play_pause (totem);
167
totem_action_set_mrl (totem, NULL, NULL);
170
/* Set the logo at the last minute so we won't try to show it before a video */
171
bacon_video_widget_set_logo (totem->bvw, "totem");
173
if (optionstate.fullscreen == FALSE)
174
gdk_window_set_cursor (gtk_widget_get_window (totem->win), NULL);
176
gtk_window_set_application (GTK_WINDOW (totem->win), GTK_APPLICATION (totem));
180
app_startup (GApplication *application,
183
/* We don't do anything here, as we need to know the options
184
* when we set everything up.
185
* Note that this will break D-Bus activation of the application */
186
startup_called = TRUE;
190
app_command_line (GApplication *app,
191
GApplicationCommandLine *command_line,
194
GOptionContext *context;
198
argv = g_application_command_line_get_arguments (command_line, &argc);
200
/* Reset the options, if they were used before */
201
memset (&optionstate, 0, sizeof (optionstate));
203
/* Options parsing */
204
context = totem_options_get_context ();
205
g_option_context_set_help_enabled (context, FALSE);
206
if (g_option_context_parse (context, &argc, &argv, NULL) == FALSE) {
207
g_option_context_free (context);
210
g_option_context_free (context);
212
totem_options_process_early (totem, &optionstate);
214
/* Don't create another window if we're remote.
215
* We can't use g_application_get_is_remote() because it's not registered yet */
216
if (startup_called != FALSE) {
217
app_init (totem, argv);
219
gdk_notify_startup_complete ();
221
/* Don't add files again through totem_options_process_for_server() */
222
g_strfreev (optionstate.filenames);
223
optionstate.filenames = NULL;
224
startup_called = FALSE;
227
/* Now do something with it */
228
totem_options_process_for_server (totem, &optionstate);
235
main (int argc, char **argv)
239
setlocale (LC_ALL, "");
240
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
241
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
242
textdomain (GETTEXT_PACKAGE);
244
#ifdef GDK_WINDOWING_X11
245
if (XInitThreads () == 0)
247
gtk_init (&argc, &argv);
248
g_set_application_name (_("Videos"));
249
totem_action_error_and_exit (_("Could not initialize the thread-safe libraries."), _("Verify your system installation. Totem will now exit."), NULL);
255
g_set_prgname ("totem");
256
g_set_application_name (_("Videos"));
257
gtk_window_set_default_icon_name ("totem");
258
g_setenv("PULSE_PROP_media.role", "video", TRUE);
261
/* Build the main Totem object */
262
totem = g_object_new (TOTEM_TYPE_OBJECT,
263
"application-id", "org.gnome.Totem",
264
"flags", G_APPLICATION_HANDLES_COMMAND_LINE,
266
totem->settings = g_settings_new (TOTEM_GSETTINGS_SCHEMA);
268
g_signal_connect (G_OBJECT (totem), "startup",
269
G_CALLBACK (app_startup), totem);
270
g_signal_connect (G_OBJECT (totem), "command-line",
271
G_CALLBACK (app_command_line), totem);
273
g_application_run (G_APPLICATION (totem), argc, argv);