1 /* totem-options.c
2
3 Copyright (C) 2004 Bastien Nocera
4
5 The Gnome Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The Gnome Library 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 GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the Gnome Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA.
19
20 Author: Bastien Nocera <hadess@hadess.net>
21 */
22
23 #include "config.h"
24
25 #include <glib.h>
26 #include <glib/gi18n.h>
27 #include <string.h>
28 #include <stdlib.h>
29
30 #include "totem-options.h"
31 #include "totem-uri.h"
32 #include "bacon-video-widget.h"
33 #include "totem-private.h"
34
35 TotemCmdLineOptions optionstate; /* Decoded command line options */
36
37 G_GNUC_NORETURN static gboolean
option_version_cb(const gchar * option_name,const gchar * value,gpointer data,GError ** error)38 option_version_cb (const gchar *option_name,
39 const gchar *value,
40 gpointer data,
41 GError **error)
42 {
43 g_print ("%s %s\n", PACKAGE, VERSION);
44
45 exit (0);
46 }
47
48 const GOptionEntry all_options[] = {
49 {"play-pause", '\0', 0, G_OPTION_ARG_NONE, &optionstate.playpause, N_("Play/Pause"), NULL},
50 {"play", '\0', 0, G_OPTION_ARG_NONE, &optionstate.play, N_("Play"), NULL},
51 {"pause", '\0', 0, G_OPTION_ARG_NONE, &optionstate.pause, N_("Pause"), NULL},
52 {"next", '\0', 0, G_OPTION_ARG_NONE, &optionstate.next, N_("Next"), NULL},
53 {"previous", '\0', 0, G_OPTION_ARG_NONE, &optionstate.previous, N_("Previous"), NULL},
54 {"seek-fwd", '\0', 0, G_OPTION_ARG_NONE, &optionstate.seekfwd, N_("Seek Forwards"), NULL},
55 {"seek-bwd", '\0', 0, G_OPTION_ARG_NONE, &optionstate.seekbwd, N_("Seek Backwards"), NULL},
56 {"volume-up", '\0', 0, G_OPTION_ARG_NONE, &optionstate.volumeup, N_("Volume Up"), NULL},
57 {"volume-down", '\0', 0, G_OPTION_ARG_NONE, &optionstate.volumedown, N_("Volume Down"), NULL},
58 {"mute", '\0', 0, G_OPTION_ARG_NONE, &optionstate.mute, N_("Mute sound"), NULL},
59 {"fullscreen", '\0', 0, G_OPTION_ARG_NONE, &optionstate.fullscreen, N_("Toggle Fullscreen"), NULL},
60 {"quit", '\0', 0, G_OPTION_ARG_NONE, &optionstate.quit, N_("Quit"), NULL},
61 {"enqueue", '\0', 0, G_OPTION_ARG_NONE, &optionstate.enqueue, N_("Enqueue"), NULL},
62 {"replace", '\0', 0, G_OPTION_ARG_NONE, &optionstate.replace, N_("Replace"), NULL},
63 {"seek", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_INT64, &optionstate.seek, N_("Seek"), NULL},
64 {"version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_version_cb, N_("Show version information and exit"), NULL},
65 {G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &optionstate.filenames, N_("Movies to play"), NULL},
66 {NULL} /* end the list */
67 };
68
69 static void
totem_send_remote_command(Totem * totem,TotemRemoteCommand action,const char * url)70 totem_send_remote_command (Totem *totem,
71 TotemRemoteCommand action,
72 const char *url)
73 {
74 GVariant *variant;
75
76 variant = g_variant_new ("(is)", action, url ? url : "");
77 g_action_group_activate_action (G_ACTION_GROUP (totem), "remote-command", variant);
78 }
79
80 void
totem_options_process_for_server(Totem * totem,TotemCmdLineOptions * options)81 totem_options_process_for_server (Totem *totem,
82 TotemCmdLineOptions *options)
83 {
84 TotemRemoteCommand action;
85 GList *commands, *l;
86 char **filenames;
87 int i;
88
89 commands = NULL;
90 action = TOTEM_REMOTE_COMMAND_REPLACE;
91
92 /* Are we quitting ? */
93 if (options->quit) {
94 totem_send_remote_command (totem, TOTEM_REMOTE_COMMAND_QUIT, NULL);
95 return;
96 }
97
98 /* Then handle the things that modify the playlist */
99 if (options->replace && options->enqueue) {
100 g_warning (_("Can’t enqueue and replace at the same time"));
101 } else if (options->replace) {
102 action = TOTEM_REMOTE_COMMAND_REPLACE;
103 } else if (options->enqueue) {
104 action = TOTEM_REMOTE_COMMAND_ENQUEUE;
105 }
106
107 filenames = options->filenames;
108 options->filenames = NULL;
109 options->had_filenames = (filenames != NULL);
110
111 /* Send the files to enqueue */
112 for (i = 0; filenames && filenames[i] != NULL; i++) {
113 const char *filename;
114 char *full_path;
115
116 filename = filenames[i];
117 full_path = totem_create_full_path (filename);
118
119 totem_send_remote_command (totem, action, full_path ? full_path : filename);
120
121 g_free (full_path);
122
123 /* Even if the default action is replace, we only want to replace with the
124 first file. After that, we enqueue. */
125 if (i == 0) {
126 action = TOTEM_REMOTE_COMMAND_ENQUEUE;
127 }
128 }
129
130 g_clear_pointer (&filenames, g_strfreev);
131
132 if (options->playpause) {
133 commands = g_list_append (commands, GINT_TO_POINTER
134 (TOTEM_REMOTE_COMMAND_PLAYPAUSE));
135 }
136
137 if (options->play) {
138 commands = g_list_append (commands, GINT_TO_POINTER
139 (TOTEM_REMOTE_COMMAND_PLAY));
140 }
141
142 if (options->pause) {
143 commands = g_list_append (commands, GINT_TO_POINTER
144 (TOTEM_REMOTE_COMMAND_PAUSE));
145 }
146
147 if (options->next) {
148 commands = g_list_append (commands, GINT_TO_POINTER
149 (TOTEM_REMOTE_COMMAND_NEXT));
150 }
151
152 if (options->previous) {
153 commands = g_list_append (commands, GINT_TO_POINTER
154 (TOTEM_REMOTE_COMMAND_PREVIOUS));
155 }
156
157 if (options->seekfwd) {
158 commands = g_list_append (commands, GINT_TO_POINTER
159 (TOTEM_REMOTE_COMMAND_SEEK_FORWARD));
160 }
161
162 if (options->seekbwd) {
163 commands = g_list_append (commands, GINT_TO_POINTER
164 (TOTEM_REMOTE_COMMAND_SEEK_BACKWARD));
165 }
166
167 if (options->volumeup) {
168 commands = g_list_append (commands, GINT_TO_POINTER
169 (TOTEM_REMOTE_COMMAND_VOLUME_UP));
170 }
171
172 if (options->volumedown) {
173 commands = g_list_append (commands, GINT_TO_POINTER
174 (TOTEM_REMOTE_COMMAND_VOLUME_DOWN));
175 }
176
177 if (options->mute) {
178 commands = g_list_append (commands, GINT_TO_POINTER
179 (TOTEM_REMOTE_COMMAND_MUTE));
180 }
181
182 if (options->fullscreen) {
183 commands = g_list_append (commands, GINT_TO_POINTER
184 (TOTEM_REMOTE_COMMAND_FULLSCREEN));
185 }
186
187 /* No commands, no files, show ourselves */
188 if (commands == NULL &&
189 !(g_application_get_flags (G_APPLICATION (totem)) & G_APPLICATION_IS_SERVICE)) {
190 totem_send_remote_command (totem, TOTEM_REMOTE_COMMAND_SHOW, NULL);
191 return;
192 }
193
194 /* Send commands */
195 for (l = commands; l != NULL; l = l->next) {
196 totem_send_remote_command (totem, GPOINTER_TO_INT (l->data), NULL);
197 }
198
199 g_list_free (commands);
200 }
201
202