Merge lp:~matttbe/ubuntu/quantal/rhythmbox/1010619_795765 into lp:ubuntu/quantal/rhythmbox
- Quantal (12.10)
- 1010619_795765
- Merge into quantal
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merge reported by: | Martin Pitt | ||||||||
Merged at revision: | not available | ||||||||
Proposed branch: | lp:~matttbe/ubuntu/quantal/rhythmbox/1010619_795765 | ||||||||
Merge into: | lp:ubuntu/quantal/rhythmbox | ||||||||
Diff against target: |
9647 lines (+9557/-4) 9 files modified
.pc/11_fix_cd_pausing.patch/shell/rb-shell-player.c (+3978/-0) .pc/applied-patches (+2/-0) .pc/git_rhythmdb_fix_deadlock.patch/rhythmdb/rhythmdb.c (+5478/-0) debian/changelog (+16/-0) debian/patches/11_fix_cd_pausing.patch (+23/-0) debian/patches/git_rhythmdb_fix_deadlock.patch (+46/-0) debian/patches/series (+2/-0) rhythmdb/rhythmdb.c (+8/-4) shell/rb-shell-player.c (+4/-0) |
||||||||
To merge this branch: | bzr merge lp:~matttbe/ubuntu/quantal/rhythmbox/1010619_795765 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Sponsors | Pending | ||
Review via email: mp+133343@code.launchpad.net |
Commit message
Description of the change
[IMPACT]
* Rhythmbox freezes when using a large collection. (LP: #1010619)
* Rhythmbox won't resume playing an audio CD if you pause it. (LP: #795765)
[TESTCASE]
* Rhythmbox freezes when using a large collection. (LP: #1010619)
* It happens with a large collection.
* It's due to a deadlock between db load and rhythmdb_
* With the previous version and after a few seconds, Rhythmbox will freeze.
* (this fix has been confirmed by a few people in the bug #1010619)
* Rhythmbox won't resume playing an audio CD if you pause it. (LP: #795765)
* Insert an audio CD (not an mp3 CD but a traditional one you'd buy from the music store)
* Test if play and pause work.
[Regression Potential]
* Rhythmbox freezes when using a large collection. (LP: #1010619)
* According to RB devs: None => http://
* This deadlock has been fixed by RB devs and now it seems they understand why there was a deadlock
* Rhythmbox won't resume playing an audio CD if you pause it. (LP: #795765)
* None, audio CD playback is already very badly broken.
[ Other Info ]
* A new version (2.98-0ubuntu2) has been uploaded to Raring repos and it contains the same patches to fix these bugs.
* About the version: I wanted to use the version 2.97-1ubuntu5.1 just to be sure that the version number does not conflict with any later and future versions in other Ubuntu releases but a new version has been uploaded a few days ago with the version 2.97-1ubuntu6. I hope I can use the version 2.97-1ubuntu7
Thank you for your help!
Sebastien Bacher (seb128) wrote : | # |
Matthieu Baerts (matttbe) wrote : | # |
Thank you for your help :)
Mathieu Cossette (mcossette) wrote : | # |
critical bug here.. when reaching end of a song which causes to crash Rhythmbox
Ubuntu 13.10
Matthieu Baerts (matttbe) wrote : | # |
@Mathieu: I guess it's not linked to this bug but I see that you also opened a new bug report (LP: #1179100). Let wait and see if other people have this critical bug.
PS: feel free to also report this bug upstream on bugzilla.gnome.org
Preview Diff
1 | === added directory '.pc/11_fix_cd_pausing.patch' | |||
2 | === added directory '.pc/11_fix_cd_pausing.patch/shell' | |||
3 | === added file '.pc/11_fix_cd_pausing.patch/shell/rb-shell-player.c' | |||
4 | --- .pc/11_fix_cd_pausing.patch/shell/rb-shell-player.c 1970-01-01 00:00:00 +0000 | |||
5 | +++ .pc/11_fix_cd_pausing.patch/shell/rb-shell-player.c 2012-11-07 20:44:28 +0000 | |||
6 | @@ -0,0 +1,3978 @@ | |||
7 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- | ||
8 | 2 | * | ||
9 | 3 | * Copyright (C) 2002, 2003 Jorn Baayen <jorn@nl.linux.org> | ||
10 | 4 | * Copyright (C) 2002,2003 Colin Walters <walters@debian.org> | ||
11 | 5 | * | ||
12 | 6 | * This program is free software; you can redistribute it and/or modify | ||
13 | 7 | * it under the terms of the GNU General Public License as published by | ||
14 | 8 | * the Free Software Foundation; either version 2 of the License, or | ||
15 | 9 | * (at your option) any later version. | ||
16 | 10 | * | ||
17 | 11 | * The Rhythmbox authors hereby grant permission for non-GPL compatible | ||
18 | 12 | * GStreamer plugins to be used and distributed together with GStreamer | ||
19 | 13 | * and Rhythmbox. This permission is above and beyond the permissions granted | ||
20 | 14 | * by the GPL license by which Rhythmbox is covered. If you modify this code | ||
21 | 15 | * you may extend this exception to your version of the code, but you are not | ||
22 | 16 | * obligated to do so. If you do not wish to do so, delete this exception | ||
23 | 17 | * statement from your version. | ||
24 | 18 | * | ||
25 | 19 | * This program is distributed in the hope that it will be useful, | ||
26 | 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
27 | 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
28 | 22 | * GNU General Public License for more details. | ||
29 | 23 | * | ||
30 | 24 | * You should have received a copy of the GNU General Public License | ||
31 | 25 | * along with this program; if not, write to the Free Software | ||
32 | 26 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
33 | 27 | * | ||
34 | 28 | */ | ||
35 | 29 | |||
36 | 30 | /** | ||
37 | 31 | * SECTION:rb-shell-player | ||
38 | 32 | * @short_description: playback state management | ||
39 | 33 | * | ||
40 | 34 | * The shell player (or player shell, depending on who you're talking to) | ||
41 | 35 | * manages the #RBPlayer instance, tracks the current playing #RhythmDBEntry, | ||
42 | 36 | * and manages the various #RBPlayOrder instances. It provides simple operations | ||
43 | 37 | * such as next, previous, play/pause, and seek. | ||
44 | 38 | * | ||
45 | 39 | * When playing internet radio streams, it first attempts to read the stream URL | ||
46 | 40 | * as a playlist. If this succeeds, the URLs from the playlist are stored in a | ||
47 | 41 | * list and tried in turn in case of errors. If the playlist parsing fails, the | ||
48 | 42 | * stream URL is played directly. | ||
49 | 43 | * | ||
50 | 44 | * The mapping from the separate shuffle and repeat settings to an #RBPlayOrder | ||
51 | 45 | * instance occurs in here. The play order logic can also support a number of | ||
52 | 46 | * additional play orders not accessible via the shuffle and repeat buttons. | ||
53 | 47 | * | ||
54 | 48 | * If the player backend supports multiple streams, the shell player crossfades | ||
55 | 49 | * between streams by watching the elapsed time of the current stream and simulating | ||
56 | 50 | * an end-of-stream event when it gets within the crossfade duration of the actual | ||
57 | 51 | * end. | ||
58 | 52 | */ | ||
59 | 53 | |||
60 | 54 | #include "config.h" | ||
61 | 55 | |||
62 | 56 | #include <unistd.h> | ||
63 | 57 | #include <stdlib.h> | ||
64 | 58 | #include <time.h> | ||
65 | 59 | #include <string.h> | ||
66 | 60 | |||
67 | 61 | #include <glib.h> | ||
68 | 62 | #include <glib/gi18n.h> | ||
69 | 63 | #include <gtk/gtk.h> | ||
70 | 64 | |||
71 | 65 | #include "rb-property-view.h" | ||
72 | 66 | #include "rb-shell-player.h" | ||
73 | 67 | #include "rb-stock-icons.h" | ||
74 | 68 | #include "rb-builder-helpers.h" | ||
75 | 69 | #include "rb-file-helpers.h" | ||
76 | 70 | #include "rb-cut-and-paste-code.h" | ||
77 | 71 | #include "rb-dialog.h" | ||
78 | 72 | #include "rb-debug.h" | ||
79 | 73 | #include "rb-player.h" | ||
80 | 74 | #include "rb-header.h" | ||
81 | 75 | #include "totem-pl-parser.h" | ||
82 | 76 | #include "rb-metadata.h" | ||
83 | 77 | #include "rb-library-source.h" | ||
84 | 78 | #include "rb-util.h" | ||
85 | 79 | #include "rb-play-order.h" | ||
86 | 80 | #include "rb-playlist-source.h" | ||
87 | 81 | #include "rb-play-queue-source.h" | ||
88 | 82 | #include "rhythmdb.h" | ||
89 | 83 | #include "rb-podcast-manager.h" | ||
90 | 84 | #include "rb-marshal.h" | ||
91 | 85 | #include "rb-missing-plugins.h" | ||
92 | 86 | #include "rb-ext-db.h" | ||
93 | 87 | |||
94 | 88 | /* Play Orders */ | ||
95 | 89 | #include "rb-play-order-linear.h" | ||
96 | 90 | #include "rb-play-order-linear-loop.h" | ||
97 | 91 | #include "rb-play-order-shuffle.h" | ||
98 | 92 | #include "rb-play-order-random-equal-weights.h" | ||
99 | 93 | #include "rb-play-order-random-by-age.h" | ||
100 | 94 | #include "rb-play-order-random-by-rating.h" | ||
101 | 95 | #include "rb-play-order-random-by-age-and-rating.h" | ||
102 | 96 | #include "rb-play-order-queue.h" | ||
103 | 97 | |||
104 | 98 | static const char* const state_to_play_order[2][2] = | ||
105 | 99 | {{"linear", "linear-loop"}, | ||
106 | 100 | {"shuffle", "random-by-age-and-rating"}}; | ||
107 | 101 | |||
108 | 102 | static void rb_shell_player_class_init (RBShellPlayerClass *klass); | ||
109 | 103 | static void rb_shell_player_init (RBShellPlayer *shell_player); | ||
110 | 104 | static void rb_shell_player_constructed (GObject *object); | ||
111 | 105 | static void rb_shell_player_dispose (GObject *object); | ||
112 | 106 | static void rb_shell_player_finalize (GObject *object); | ||
113 | 107 | static void rb_shell_player_set_property (GObject *object, | ||
114 | 108 | guint prop_id, | ||
115 | 109 | const GValue *value, | ||
116 | 110 | GParamSpec *pspec); | ||
117 | 111 | static void rb_shell_player_get_property (GObject *object, | ||
118 | 112 | guint prop_id, | ||
119 | 113 | GValue *value, | ||
120 | 114 | GParamSpec *pspec); | ||
121 | 115 | |||
122 | 116 | static void rb_shell_player_cmd_previous (GtkAction *action, | ||
123 | 117 | RBShellPlayer *player); | ||
124 | 118 | static void rb_shell_player_cmd_play (GtkAction *action, | ||
125 | 119 | RBShellPlayer *player); | ||
126 | 120 | static void rb_shell_player_cmd_next (GtkAction *action, | ||
127 | 121 | RBShellPlayer *player); | ||
128 | 122 | static void rb_shell_player_cmd_volume_up (GtkAction *action, | ||
129 | 123 | RBShellPlayer *player); | ||
130 | 124 | static void rb_shell_player_cmd_volume_down (GtkAction *action, | ||
131 | 125 | RBShellPlayer *player); | ||
132 | 126 | static void rb_shell_player_shuffle_changed_cb (GtkAction *action, | ||
133 | 127 | RBShellPlayer *player); | ||
134 | 128 | static void rb_shell_player_repeat_changed_cb (GtkAction *action, | ||
135 | 129 | RBShellPlayer *player); | ||
136 | 130 | static void rb_shell_player_set_playing_source_internal (RBShellPlayer *player, | ||
137 | 131 | RBSource *source, | ||
138 | 132 | gboolean sync_entry_view); | ||
139 | 133 | static void rb_shell_player_sync_with_source (RBShellPlayer *player); | ||
140 | 134 | static void rb_shell_player_sync_with_selected_source (RBShellPlayer *player); | ||
141 | 135 | static void rb_shell_player_entry_changed_cb (RhythmDB *db, | ||
142 | 136 | RhythmDBEntry *entry, | ||
143 | 137 | GValueArray *changes, | ||
144 | 138 | RBShellPlayer *player); | ||
145 | 139 | |||
146 | 140 | static void rb_shell_player_entry_activated_cb (RBEntryView *view, | ||
147 | 141 | RhythmDBEntry *entry, | ||
148 | 142 | RBShellPlayer *player); | ||
149 | 143 | static void rb_shell_player_property_row_activated_cb (RBPropertyView *view, | ||
150 | 144 | const char *name, | ||
151 | 145 | RBShellPlayer *player); | ||
152 | 146 | static void rb_shell_player_sync_volume (RBShellPlayer *player, gboolean notify, gboolean set_volume); | ||
153 | 147 | static void tick_cb (RBPlayer *player, RhythmDBEntry *entry, gint64 elapsed, gint64 duration, gpointer data); | ||
154 | 148 | static void error_cb (RBPlayer *player, RhythmDBEntry *entry, const GError *err, gpointer data); | ||
155 | 149 | static void missing_plugins_cb (RBPlayer *player, RhythmDBEntry *entry, const char **details, const char **descriptions, RBShellPlayer *sp); | ||
156 | 150 | static void playing_stream_cb (RBPlayer *player, RhythmDBEntry *entry, RBShellPlayer *shell_player); | ||
157 | 151 | static void player_image_cb (RBPlayer *player, RhythmDBEntry *entry, GdkPixbuf *image, RBShellPlayer *shell_player); | ||
158 | 152 | static void rb_shell_player_error (RBShellPlayer *player, gboolean async, const GError *err); | ||
159 | 153 | |||
160 | 154 | static void rb_shell_player_play_order_update_cb (RBPlayOrder *porder, | ||
161 | 155 | gboolean has_next, | ||
162 | 156 | gboolean has_previous, | ||
163 | 157 | RBShellPlayer *player); | ||
164 | 158 | |||
165 | 159 | static void rb_shell_player_sync_play_order (RBShellPlayer *player); | ||
166 | 160 | static void rb_shell_player_sync_control_state (RBShellPlayer *player); | ||
167 | 161 | static void rb_shell_player_sync_buttons (RBShellPlayer *player); | ||
168 | 162 | |||
169 | 163 | static void player_settings_changed_cb (GSettings *settings, | ||
170 | 164 | const char *key, | ||
171 | 165 | RBShellPlayer *player); | ||
172 | 166 | static void rb_shell_player_playing_changed_cb (RBShellPlayer *player, | ||
173 | 167 | GParamSpec *arg1, | ||
174 | 168 | gpointer user_data); | ||
175 | 169 | static void rb_shell_player_extra_metadata_cb (RhythmDB *db, | ||
176 | 170 | RhythmDBEntry *entry, | ||
177 | 171 | const char *field, | ||
178 | 172 | GValue *metadata, | ||
179 | 173 | RBShellPlayer *player); | ||
180 | 174 | |||
181 | 175 | static gboolean rb_shell_player_open_location (RBShellPlayer *player, | ||
182 | 176 | RhythmDBEntry *entry, | ||
183 | 177 | RBPlayerPlayType play_type, | ||
184 | 178 | GError **error); | ||
185 | 179 | static gboolean rb_shell_player_do_next_internal (RBShellPlayer *player, | ||
186 | 180 | gboolean from_eos, | ||
187 | 181 | gboolean allow_stop, | ||
188 | 182 | GError **error); | ||
189 | 183 | static void rb_shell_player_slider_dragging_cb (GObject *header, | ||
190 | 184 | GParamSpec *pspec, | ||
191 | 185 | RBShellPlayer *player); | ||
192 | 186 | static void rb_shell_player_volume_changed_cb (RBPlayer *player, | ||
193 | 187 | float volume, | ||
194 | 188 | RBShellPlayer *shell_player); | ||
195 | 189 | |||
196 | 190 | |||
197 | 191 | |||
198 | 192 | typedef struct { | ||
199 | 193 | /** Value of the state/play-order setting */ | ||
200 | 194 | char *name; | ||
201 | 195 | /** Contents of the play order dropdown; should be gettext()ed before use. */ | ||
202 | 196 | char *description; | ||
203 | 197 | /** the play order's gtype id */ | ||
204 | 198 | GType order_type; | ||
205 | 199 | /** TRUE if the play order should appear in the dropdown */ | ||
206 | 200 | gboolean is_in_dropdown; | ||
207 | 201 | } RBPlayOrderDescription; | ||
208 | 202 | |||
209 | 203 | static void _play_order_description_free (RBPlayOrderDescription *order); | ||
210 | 204 | |||
211 | 205 | static RBPlayOrder* rb_play_order_new (RBShellPlayer *player, const char* porder_name); | ||
212 | 206 | |||
213 | 207 | /* number of nanoseconds before the end of a track to start prerolling the next */ | ||
214 | 208 | #define PREROLL_TIME RB_PLAYER_SECOND | ||
215 | 209 | |||
216 | 210 | struct RBShellPlayerPrivate | ||
217 | 211 | { | ||
218 | 212 | RhythmDB *db; | ||
219 | 213 | |||
220 | 214 | gboolean syncing_state; | ||
221 | 215 | gboolean queue_only; | ||
222 | 216 | |||
223 | 217 | RBSource *selected_source; | ||
224 | 218 | RBSource *source; | ||
225 | 219 | RBPlayQueueSource *queue_source; | ||
226 | 220 | RBSource *current_playing_source; | ||
227 | 221 | |||
228 | 222 | GHashTable *play_orders; /* char* -> RBPlayOrderDescription* map */ | ||
229 | 223 | |||
230 | 224 | gboolean did_retry; | ||
231 | 225 | GTimeVal last_retry; | ||
232 | 226 | |||
233 | 227 | GtkUIManager *ui_manager; | ||
234 | 228 | GtkActionGroup *actiongroup; | ||
235 | 229 | |||
236 | 230 | gboolean handling_error; | ||
237 | 231 | |||
238 | 232 | RBPlayer *mmplayer; | ||
239 | 233 | |||
240 | 234 | guint elapsed; | ||
241 | 235 | gint64 track_transition_time; | ||
242 | 236 | RhythmDBEntry *playing_entry; | ||
243 | 237 | gboolean playing_entry_eos; | ||
244 | 238 | gboolean jump_to_playing_entry; | ||
245 | 239 | |||
246 | 240 | RBPlayOrder *play_order; | ||
247 | 241 | RBPlayOrder *queue_play_order; | ||
248 | 242 | |||
249 | 243 | GQueue *playlist_urls; | ||
250 | 244 | GCancellable *parser_cancellable; | ||
251 | 245 | |||
252 | 246 | RBHeader *header_widget; | ||
253 | 247 | |||
254 | 248 | GSettings *settings; | ||
255 | 249 | GSettings *ui_settings; | ||
256 | 250 | |||
257 | 251 | gboolean has_prev; | ||
258 | 252 | gboolean has_next; | ||
259 | 253 | gboolean mute; | ||
260 | 254 | float volume; | ||
261 | 255 | |||
262 | 256 | guint do_next_idle_id; | ||
263 | 257 | guint unblock_play_id; | ||
264 | 258 | }; | ||
265 | 259 | |||
266 | 260 | #define RB_SHELL_PLAYER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_SHELL_PLAYER, RBShellPlayerPrivate)) | ||
267 | 261 | |||
268 | 262 | enum | ||
269 | 263 | { | ||
270 | 264 | PROP_0, | ||
271 | 265 | PROP_SOURCE, | ||
272 | 266 | PROP_DB, | ||
273 | 267 | PROP_UI_MANAGER, | ||
274 | 268 | PROP_ACTION_GROUP, | ||
275 | 269 | PROP_PLAY_ORDER, | ||
276 | 270 | PROP_PLAYING, | ||
277 | 271 | PROP_VOLUME, | ||
278 | 272 | PROP_HEADER, | ||
279 | 273 | PROP_QUEUE_SOURCE, | ||
280 | 274 | PROP_QUEUE_ONLY, | ||
281 | 275 | PROP_PLAYING_FROM_QUEUE, | ||
282 | 276 | PROP_PLAYER, | ||
283 | 277 | PROP_MUTE, | ||
284 | 278 | PROP_HAS_NEXT, | ||
285 | 279 | PROP_HAS_PREV | ||
286 | 280 | }; | ||
287 | 281 | |||
288 | 282 | enum | ||
289 | 283 | { | ||
290 | 284 | WINDOW_TITLE_CHANGED, | ||
291 | 285 | ELAPSED_CHANGED, | ||
292 | 286 | PLAYING_SOURCE_CHANGED, | ||
293 | 287 | PLAYING_CHANGED, | ||
294 | 288 | PLAYING_SONG_CHANGED, | ||
295 | 289 | PLAYING_URI_CHANGED, | ||
296 | 290 | PLAYING_SONG_PROPERTY_CHANGED, | ||
297 | 291 | ELAPSED_NANO_CHANGED, | ||
298 | 292 | LAST_SIGNAL | ||
299 | 293 | }; | ||
300 | 294 | |||
301 | 295 | static GtkActionEntry rb_shell_player_actions [] = | ||
302 | 296 | { | ||
303 | 297 | { "ControlPlay", GTK_STOCK_MEDIA_PLAY, N_("_Play"), "<control>space", | ||
304 | 298 | N_("Start playback"), | ||
305 | 299 | G_CALLBACK (rb_shell_player_cmd_play) }, | ||
306 | 300 | { "ControlPrevious", GTK_STOCK_MEDIA_PREVIOUS, N_("Pre_vious"), "<alt>Left", | ||
307 | 301 | N_("Start playing the previous song"), | ||
308 | 302 | G_CALLBACK (rb_shell_player_cmd_previous) }, | ||
309 | 303 | { "ControlNext", GTK_STOCK_MEDIA_NEXT, N_("_Next"), "<alt>Right", | ||
310 | 304 | N_("Start playing the next song"), | ||
311 | 305 | G_CALLBACK (rb_shell_player_cmd_next) }, | ||
312 | 306 | { "ControlVolumeUp", NULL, N_("_Increase Volume"), "<control>Up", | ||
313 | 307 | N_("Increase playback volume"), | ||
314 | 308 | G_CALLBACK (rb_shell_player_cmd_volume_up) }, | ||
315 | 309 | { "ControlVolumeDown", NULL, N_("_Decrease Volume"), "<control>Down", | ||
316 | 310 | N_("Decrease playback volume"), | ||
317 | 311 | G_CALLBACK (rb_shell_player_cmd_volume_down) }, | ||
318 | 312 | }; | ||
319 | 313 | static guint rb_shell_player_n_actions = G_N_ELEMENTS (rb_shell_player_actions); | ||
320 | 314 | |||
321 | 315 | static GtkToggleActionEntry rb_shell_player_toggle_entries [] = | ||
322 | 316 | { | ||
323 | 317 | { "ControlShuffle", GNOME_MEDIA_SHUFFLE, N_("Sh_uffle"), "<control>U", | ||
324 | 318 | N_("Play songs in a random order"), | ||
325 | 319 | G_CALLBACK (rb_shell_player_shuffle_changed_cb) }, | ||
326 | 320 | { "ControlRepeat", GNOME_MEDIA_REPEAT, N_("_Repeat"), "<control>R", | ||
327 | 321 | N_("Play first song again after all songs are played"), | ||
328 | 322 | G_CALLBACK (rb_shell_player_repeat_changed_cb) }, | ||
329 | 323 | }; | ||
330 | 324 | static guint rb_shell_player_n_toggle_entries = G_N_ELEMENTS (rb_shell_player_toggle_entries); | ||
331 | 325 | |||
332 | 326 | static guint rb_shell_player_signals[LAST_SIGNAL] = { 0 }; | ||
333 | 327 | |||
334 | 328 | G_DEFINE_TYPE (RBShellPlayer, rb_shell_player, G_TYPE_OBJECT) | ||
335 | 329 | |||
336 | 330 | static void | ||
337 | 331 | rb_shell_player_class_init (RBShellPlayerClass *klass) | ||
338 | 332 | { | ||
339 | 333 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
340 | 334 | |||
341 | 335 | object_class->dispose = rb_shell_player_dispose; | ||
342 | 336 | object_class->finalize = rb_shell_player_finalize; | ||
343 | 337 | object_class->constructed = rb_shell_player_constructed; | ||
344 | 338 | |||
345 | 339 | object_class->set_property = rb_shell_player_set_property; | ||
346 | 340 | object_class->get_property = rb_shell_player_get_property; | ||
347 | 341 | |||
348 | 342 | /** | ||
349 | 343 | * RBShellPlayer:source: | ||
350 | 344 | * | ||
351 | 345 | * The current source that is selected for playback. | ||
352 | 346 | */ | ||
353 | 347 | g_object_class_install_property (object_class, | ||
354 | 348 | PROP_SOURCE, | ||
355 | 349 | g_param_spec_object ("source", | ||
356 | 350 | "RBSource", | ||
357 | 351 | "RBSource object", | ||
358 | 352 | RB_TYPE_SOURCE, | ||
359 | 353 | G_PARAM_READWRITE)); | ||
360 | 354 | |||
361 | 355 | /** | ||
362 | 356 | * RBShellPlayer:ui-manager: | ||
363 | 357 | * | ||
364 | 358 | * The GtkUIManager | ||
365 | 359 | */ | ||
366 | 360 | g_object_class_install_property (object_class, | ||
367 | 361 | PROP_UI_MANAGER, | ||
368 | 362 | g_param_spec_object ("ui-manager", | ||
369 | 363 | "GtkUIManager", | ||
370 | 364 | "GtkUIManager object", | ||
371 | 365 | GTK_TYPE_UI_MANAGER, | ||
372 | 366 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); | ||
373 | 367 | |||
374 | 368 | /** | ||
375 | 369 | * RBShellPlayer:db: | ||
376 | 370 | * | ||
377 | 371 | * The #RhythmDB | ||
378 | 372 | */ | ||
379 | 373 | g_object_class_install_property (object_class, | ||
380 | 374 | PROP_DB, | ||
381 | 375 | g_param_spec_object ("db", | ||
382 | 376 | "RhythmDB", | ||
383 | 377 | "RhythmDB object", | ||
384 | 378 | RHYTHMDB_TYPE, | ||
385 | 379 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); | ||
386 | 380 | |||
387 | 381 | /** | ||
388 | 382 | * RBShellPlayer:action-group: | ||
389 | 383 | * | ||
390 | 384 | * The #GtkActionGroup to use for player actions | ||
391 | 385 | */ | ||
392 | 386 | g_object_class_install_property (object_class, | ||
393 | 387 | PROP_ACTION_GROUP, | ||
394 | 388 | g_param_spec_object ("action-group", | ||
395 | 389 | "GtkActionGroup", | ||
396 | 390 | "GtkActionGroup object", | ||
397 | 391 | GTK_TYPE_ACTION_GROUP, | ||
398 | 392 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); | ||
399 | 393 | |||
400 | 394 | /** | ||
401 | 395 | * RBShellPlayer:queue-source: | ||
402 | 396 | * | ||
403 | 397 | * The play queue source | ||
404 | 398 | */ | ||
405 | 399 | g_object_class_install_property (object_class, | ||
406 | 400 | PROP_QUEUE_SOURCE, | ||
407 | 401 | g_param_spec_object ("queue-source", | ||
408 | 402 | "RBPlayQueueSource", | ||
409 | 403 | "RBPlayQueueSource object", | ||
410 | 404 | RB_TYPE_PLAYLIST_SOURCE, | ||
411 | 405 | G_PARAM_READWRITE)); | ||
412 | 406 | |||
413 | 407 | /** | ||
414 | 408 | * RBShellPlayer:queue-only: | ||
415 | 409 | * | ||
416 | 410 | * If %TRUE, activating an entry should only add it to the play queue. | ||
417 | 411 | */ | ||
418 | 412 | g_object_class_install_property (object_class, | ||
419 | 413 | PROP_QUEUE_ONLY, | ||
420 | 414 | g_param_spec_boolean ("queue-only", | ||
421 | 415 | "Queue only", | ||
422 | 416 | "Activation only adds to queue", | ||
423 | 417 | FALSE, | ||
424 | 418 | G_PARAM_READWRITE)); | ||
425 | 419 | |||
426 | 420 | /** | ||
427 | 421 | * RBShellPlayer:playing-from-queue: | ||
428 | 422 | * | ||
429 | 423 | * If %TRUE, the current playing entry came from the play queue. | ||
430 | 424 | */ | ||
431 | 425 | g_object_class_install_property (object_class, | ||
432 | 426 | PROP_PLAYING_FROM_QUEUE, | ||
433 | 427 | g_param_spec_boolean ("playing-from-queue", | ||
434 | 428 | "Playing from queue", | ||
435 | 429 | "Whether playing from the play queue or not", | ||
436 | 430 | FALSE, | ||
437 | 431 | G_PARAM_READABLE)); | ||
438 | 432 | |||
439 | 433 | /** | ||
440 | 434 | * RBShellPlayer:player: | ||
441 | 435 | * | ||
442 | 436 | * The player backend object (an object implementing the #RBPlayer interface). | ||
443 | 437 | */ | ||
444 | 438 | g_object_class_install_property (object_class, | ||
445 | 439 | PROP_PLAYER, | ||
446 | 440 | g_param_spec_object ("player", | ||
447 | 441 | "RBPlayer", | ||
448 | 442 | "RBPlayer object", | ||
449 | 443 | G_TYPE_OBJECT, | ||
450 | 444 | G_PARAM_READABLE)); | ||
451 | 445 | |||
452 | 446 | /** | ||
453 | 447 | * RBShellPlayer:play-order: | ||
454 | 448 | * | ||
455 | 449 | * The current play order object. | ||
456 | 450 | */ | ||
457 | 451 | g_object_class_install_property (object_class, | ||
458 | 452 | PROP_PLAY_ORDER, | ||
459 | 453 | g_param_spec_string ("play-order", | ||
460 | 454 | "play-order", | ||
461 | 455 | "What play order to use", | ||
462 | 456 | "linear", | ||
463 | 457 | G_PARAM_READABLE)); | ||
464 | 458 | /** | ||
465 | 459 | * RBShellPlayer:playing: | ||
466 | 460 | * | ||
467 | 461 | * Whether Rhythmbox is currently playing something | ||
468 | 462 | */ | ||
469 | 463 | g_object_class_install_property (object_class, | ||
470 | 464 | PROP_PLAYING, | ||
471 | 465 | g_param_spec_boolean ("playing", | ||
472 | 466 | "playing", | ||
473 | 467 | "Whether Rhythmbox is currently playing", | ||
474 | 468 | FALSE, | ||
475 | 469 | G_PARAM_READABLE)); | ||
476 | 470 | /** | ||
477 | 471 | * RBShellPlayer:volume: | ||
478 | 472 | * | ||
479 | 473 | * The current playback volume (between 0.0 and 1.0) | ||
480 | 474 | */ | ||
481 | 475 | g_object_class_install_property (object_class, | ||
482 | 476 | PROP_VOLUME, | ||
483 | 477 | g_param_spec_float ("volume", | ||
484 | 478 | "volume", | ||
485 | 479 | "Current playback volume", | ||
486 | 480 | 0.0f, 1.0f, 1.0f, | ||
487 | 481 | G_PARAM_READWRITE)); | ||
488 | 482 | |||
489 | 483 | /** | ||
490 | 484 | * RBShellPlayer:header: | ||
491 | 485 | * | ||
492 | 486 | * The #RBHeader object | ||
493 | 487 | */ | ||
494 | 488 | g_object_class_install_property (object_class, | ||
495 | 489 | PROP_HEADER, | ||
496 | 490 | g_param_spec_object ("header", | ||
497 | 491 | "RBHeader", | ||
498 | 492 | "RBHeader object", | ||
499 | 493 | RB_TYPE_HEADER, | ||
500 | 494 | G_PARAM_READWRITE)); | ||
501 | 495 | /** | ||
502 | 496 | * RBShellPlayer:mute: | ||
503 | 497 | * | ||
504 | 498 | * Whether playback is currently muted. | ||
505 | 499 | */ | ||
506 | 500 | g_object_class_install_property (object_class, | ||
507 | 501 | PROP_MUTE, | ||
508 | 502 | g_param_spec_boolean ("mute", | ||
509 | 503 | "mute", | ||
510 | 504 | "Whether playback is muted", | ||
511 | 505 | FALSE, | ||
512 | 506 | G_PARAM_READWRITE)); | ||
513 | 507 | /** | ||
514 | 508 | * RBShellPlayer:has-next: | ||
515 | 509 | * | ||
516 | 510 | * Whether there is a track to play after the current track. | ||
517 | 511 | */ | ||
518 | 512 | g_object_class_install_property (object_class, | ||
519 | 513 | PROP_HAS_NEXT, | ||
520 | 514 | g_param_spec_boolean ("has-next", | ||
521 | 515 | "has-next", | ||
522 | 516 | "Whether there is a next track", | ||
523 | 517 | FALSE, | ||
524 | 518 | G_PARAM_READABLE)); | ||
525 | 519 | /** | ||
526 | 520 | * RBShellPlayer:has-prev: | ||
527 | 521 | * | ||
528 | 522 | * Whether there was a previous track before the current track. | ||
529 | 523 | */ | ||
530 | 524 | g_object_class_install_property (object_class, | ||
531 | 525 | PROP_HAS_PREV, | ||
532 | 526 | g_param_spec_boolean ("has-prev", | ||
533 | 527 | "has-prev", | ||
534 | 528 | "Whether there is a previous track", | ||
535 | 529 | FALSE, | ||
536 | 530 | G_PARAM_READABLE)); | ||
537 | 531 | |||
538 | 532 | /** | ||
539 | 533 | * RBShellPlayer::window-title-changed: | ||
540 | 534 | * @player: the #RBShellPlayer | ||
541 | 535 | * @title: the new window title | ||
542 | 536 | * | ||
543 | 537 | * Emitted when the main window title text should be changed | ||
544 | 538 | */ | ||
545 | 539 | rb_shell_player_signals[WINDOW_TITLE_CHANGED] = | ||
546 | 540 | g_signal_new ("window_title_changed", | ||
547 | 541 | G_OBJECT_CLASS_TYPE (object_class), | ||
548 | 542 | G_SIGNAL_RUN_LAST, | ||
549 | 543 | G_STRUCT_OFFSET (RBShellPlayerClass, window_title_changed), | ||
550 | 544 | NULL, NULL, | ||
551 | 545 | g_cclosure_marshal_VOID__STRING, | ||
552 | 546 | G_TYPE_NONE, | ||
553 | 547 | 1, | ||
554 | 548 | G_TYPE_STRING); | ||
555 | 549 | |||
556 | 550 | /** | ||
557 | 551 | * RBShellPlayer::elapsed-changed: | ||
558 | 552 | * @player: the #RBShellPlayer | ||
559 | 553 | * @elapsed: the new playback position in seconds | ||
560 | 554 | * | ||
561 | 555 | * Emitted when the playback position changes. | ||
562 | 556 | */ | ||
563 | 557 | rb_shell_player_signals[ELAPSED_CHANGED] = | ||
564 | 558 | g_signal_new ("elapsed_changed", | ||
565 | 559 | G_OBJECT_CLASS_TYPE (object_class), | ||
566 | 560 | G_SIGNAL_RUN_LAST, | ||
567 | 561 | G_STRUCT_OFFSET (RBShellPlayerClass, elapsed_changed), | ||
568 | 562 | NULL, NULL, | ||
569 | 563 | g_cclosure_marshal_VOID__UINT, | ||
570 | 564 | G_TYPE_NONE, | ||
571 | 565 | 1, | ||
572 | 566 | G_TYPE_UINT); | ||
573 | 567 | |||
574 | 568 | /** | ||
575 | 569 | * RBShellPlayer::playing-source-changed: | ||
576 | 570 | * @player: the #RBShellPlayer | ||
577 | 571 | * @source: the #RBSource that is now playing | ||
578 | 572 | * | ||
579 | 573 | * Emitted when a new #RBSource instance starts playing | ||
580 | 574 | */ | ||
581 | 575 | rb_shell_player_signals[PLAYING_SOURCE_CHANGED] = | ||
582 | 576 | g_signal_new ("playing-source-changed", | ||
583 | 577 | G_OBJECT_CLASS_TYPE (object_class), | ||
584 | 578 | G_SIGNAL_RUN_LAST, | ||
585 | 579 | G_STRUCT_OFFSET (RBShellPlayerClass, playing_source_changed), | ||
586 | 580 | NULL, NULL, | ||
587 | 581 | g_cclosure_marshal_VOID__OBJECT, | ||
588 | 582 | G_TYPE_NONE, | ||
589 | 583 | 1, | ||
590 | 584 | RB_TYPE_SOURCE); | ||
591 | 585 | |||
592 | 586 | /** | ||
593 | 587 | * RBShellPlayer::playing-changed: | ||
594 | 588 | * @player: the #RBShellPlayer | ||
595 | 589 | * @playing: flag indicating playback state | ||
596 | 590 | * | ||
597 | 591 | * Emitted when playback either stops or starts. | ||
598 | 592 | */ | ||
599 | 593 | rb_shell_player_signals[PLAYING_CHANGED] = | ||
600 | 594 | g_signal_new ("playing-changed", | ||
601 | 595 | G_OBJECT_CLASS_TYPE (object_class), | ||
602 | 596 | G_SIGNAL_RUN_LAST, | ||
603 | 597 | G_STRUCT_OFFSET (RBShellPlayerClass, playing_changed), | ||
604 | 598 | NULL, NULL, | ||
605 | 599 | g_cclosure_marshal_VOID__BOOLEAN, | ||
606 | 600 | G_TYPE_NONE, | ||
607 | 601 | 1, | ||
608 | 602 | G_TYPE_BOOLEAN); | ||
609 | 603 | |||
610 | 604 | /** | ||
611 | 605 | * RBShellPlayer::playing-song-changed: | ||
612 | 606 | * @player: the #RBShellPlayer | ||
613 | 607 | * @entry: the new playing #RhythmDBEntry | ||
614 | 608 | * | ||
615 | 609 | * Emitted when the playing database entry changes | ||
616 | 610 | */ | ||
617 | 611 | rb_shell_player_signals[PLAYING_SONG_CHANGED] = | ||
618 | 612 | g_signal_new ("playing-song-changed", | ||
619 | 613 | G_OBJECT_CLASS_TYPE (object_class), | ||
620 | 614 | G_SIGNAL_RUN_LAST, | ||
621 | 615 | G_STRUCT_OFFSET (RBShellPlayerClass, playing_song_changed), | ||
622 | 616 | NULL, NULL, | ||
623 | 617 | g_cclosure_marshal_VOID__BOXED, | ||
624 | 618 | G_TYPE_NONE, | ||
625 | 619 | 1, | ||
626 | 620 | RHYTHMDB_TYPE_ENTRY); | ||
627 | 621 | |||
628 | 622 | /** | ||
629 | 623 | * RBShellPlayer::playing-uri-changed: | ||
630 | 624 | * @player: the #RBShellPlayer | ||
631 | 625 | * @uri: the URI of the new playing entry | ||
632 | 626 | * | ||
633 | 627 | * Emitted when the playing database entry changes, providing the | ||
634 | 628 | * URI of the entry. | ||
635 | 629 | */ | ||
636 | 630 | rb_shell_player_signals[PLAYING_URI_CHANGED] = | ||
637 | 631 | g_signal_new ("playing-uri-changed", | ||
638 | 632 | G_OBJECT_CLASS_TYPE (object_class), | ||
639 | 633 | G_SIGNAL_RUN_LAST, | ||
640 | 634 | G_STRUCT_OFFSET (RBShellPlayerClass, playing_uri_changed), | ||
641 | 635 | NULL, NULL, | ||
642 | 636 | g_cclosure_marshal_VOID__STRING, | ||
643 | 637 | G_TYPE_NONE, | ||
644 | 638 | 1, | ||
645 | 639 | G_TYPE_STRING); | ||
646 | 640 | |||
647 | 641 | /** | ||
648 | 642 | * RBShellPlayer::playing-song-property-changed: | ||
649 | 643 | * @player: the #RBShellPlayer | ||
650 | 644 | * @uri: the URI of the playing entry | ||
651 | 645 | * @property: the name of the property that changed | ||
652 | 646 | * @old: the previous value for the property | ||
653 | 647 | * @newvalue: the new value of the property | ||
654 | 648 | * | ||
655 | 649 | * Emitted when a property of the playing database entry changes. | ||
656 | 650 | */ | ||
657 | 651 | rb_shell_player_signals[PLAYING_SONG_PROPERTY_CHANGED] = | ||
658 | 652 | g_signal_new ("playing-song-property-changed", | ||
659 | 653 | G_OBJECT_CLASS_TYPE (object_class), | ||
660 | 654 | G_SIGNAL_RUN_LAST, | ||
661 | 655 | G_STRUCT_OFFSET (RBShellPlayerClass, playing_song_property_changed), | ||
662 | 656 | NULL, NULL, | ||
663 | 657 | rb_marshal_VOID__STRING_STRING_POINTER_POINTER, | ||
664 | 658 | G_TYPE_NONE, | ||
665 | 659 | 4, | ||
666 | 660 | G_TYPE_STRING, G_TYPE_STRING, | ||
667 | 661 | G_TYPE_VALUE, G_TYPE_VALUE); | ||
668 | 662 | |||
669 | 663 | /** | ||
670 | 664 | * RBShellPlayer::elapsed-nano-changed: | ||
671 | 665 | * @player: the #RBShellPlayer | ||
672 | 666 | * @elapsed: the new playback position in nanoseconds | ||
673 | 667 | * | ||
674 | 668 | * Emitted when the playback position changes. Only use this (as opposed to | ||
675 | 669 | * elapsed-changed) when you require subsecond precision. This signal will be | ||
676 | 670 | * emitted multiple times per second. | ||
677 | 671 | */ | ||
678 | 672 | rb_shell_player_signals[ELAPSED_NANO_CHANGED] = | ||
679 | 673 | g_signal_new ("elapsed-nano-changed", | ||
680 | 674 | G_OBJECT_CLASS_TYPE (object_class), | ||
681 | 675 | G_SIGNAL_RUN_LAST, | ||
682 | 676 | G_STRUCT_OFFSET (RBShellPlayerClass, elapsed_nano_changed), | ||
683 | 677 | NULL, NULL, | ||
684 | 678 | rb_marshal_VOID__INT64, | ||
685 | 679 | G_TYPE_NONE, | ||
686 | 680 | 1, | ||
687 | 681 | G_TYPE_INT64); | ||
688 | 682 | |||
689 | 683 | g_type_class_add_private (klass, sizeof (RBShellPlayerPrivate)); | ||
690 | 684 | } | ||
691 | 685 | |||
692 | 686 | static void | ||
693 | 687 | rb_shell_player_constructed (GObject *object) | ||
694 | 688 | { | ||
695 | 689 | RBShellPlayer *player; | ||
696 | 690 | GtkAction *action; | ||
697 | 691 | |||
698 | 692 | RB_CHAIN_GOBJECT_METHOD (rb_shell_player_parent_class, constructed, object); | ||
699 | 693 | |||
700 | 694 | player = RB_SHELL_PLAYER (object); | ||
701 | 695 | |||
702 | 696 | gtk_action_group_add_actions (player->priv->actiongroup, | ||
703 | 697 | rb_shell_player_actions, | ||
704 | 698 | rb_shell_player_n_actions, | ||
705 | 699 | player); | ||
706 | 700 | gtk_action_group_add_toggle_actions (player->priv->actiongroup, | ||
707 | 701 | rb_shell_player_toggle_entries, | ||
708 | 702 | rb_shell_player_n_toggle_entries, | ||
709 | 703 | player); | ||
710 | 704 | |||
711 | 705 | player_settings_changed_cb (player->priv->settings, "transition-time", player); | ||
712 | 706 | player_settings_changed_cb (player->priv->settings, "play-order", player); | ||
713 | 707 | |||
714 | 708 | |||
715 | 709 | action = gtk_action_group_get_action (player->priv->actiongroup, "ControlPrevious"); | ||
716 | 710 | g_object_bind_property (player, "has-prev", action, "sensitive", G_BINDING_DEFAULT); | ||
717 | 711 | action = gtk_action_group_get_action (player->priv->actiongroup, "ControlNext"); | ||
718 | 712 | g_object_bind_property (player, "has-next", action, "sensitive", G_BINDING_DEFAULT); | ||
719 | 713 | |||
720 | 714 | player->priv->syncing_state = TRUE; | ||
721 | 715 | rb_shell_player_set_playing_source (player, NULL); | ||
722 | 716 | rb_shell_player_sync_play_order (player); | ||
723 | 717 | rb_shell_player_sync_control_state (player); | ||
724 | 718 | rb_shell_player_sync_volume (player, FALSE, TRUE); | ||
725 | 719 | player->priv->syncing_state = FALSE; | ||
726 | 720 | |||
727 | 721 | g_signal_connect (player, | ||
728 | 722 | "notify::playing", | ||
729 | 723 | G_CALLBACK (rb_shell_player_playing_changed_cb), | ||
730 | 724 | NULL); | ||
731 | 725 | } | ||
732 | 726 | |||
733 | 727 | static void | ||
734 | 728 | volume_pre_unmount_cb (GVolumeMonitor *monitor, | ||
735 | 729 | GMount *mount, | ||
736 | 730 | RBShellPlayer *player) | ||
737 | 731 | { | ||
738 | 732 | const char *entry_mount_point; | ||
739 | 733 | GFile *mount_root; | ||
740 | 734 | RhythmDBEntry *entry; | ||
741 | 735 | |||
742 | 736 | entry = rb_shell_player_get_playing_entry (player); | ||
743 | 737 | if (entry == NULL) { | ||
744 | 738 | return; | ||
745 | 739 | } | ||
746 | 740 | |||
747 | 741 | entry_mount_point = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_MOUNTPOINT); | ||
748 | 742 | if (entry_mount_point == NULL) { | ||
749 | 743 | return; | ||
750 | 744 | } | ||
751 | 745 | |||
752 | 746 | mount_root = g_mount_get_root (mount); | ||
753 | 747 | if (mount_root != NULL) { | ||
754 | 748 | char *mount_point; | ||
755 | 749 | |||
756 | 750 | mount_point = g_file_get_uri (mount_root); | ||
757 | 751 | if (mount_point && entry_mount_point && | ||
758 | 752 | strcmp (entry_mount_point, mount_point) == 0) { | ||
759 | 753 | rb_shell_player_stop (player); | ||
760 | 754 | } | ||
761 | 755 | |||
762 | 756 | g_free (mount_point); | ||
763 | 757 | g_object_unref (mount_root); | ||
764 | 758 | } | ||
765 | 759 | |||
766 | 760 | rhythmdb_entry_unref (entry); | ||
767 | 761 | } | ||
768 | 762 | |||
769 | 763 | static void | ||
770 | 764 | reemit_playing_signal (RBShellPlayer *player, | ||
771 | 765 | GParamSpec *pspec, | ||
772 | 766 | gpointer data) | ||
773 | 767 | { | ||
774 | 768 | g_signal_emit (player, rb_shell_player_signals[PLAYING_CHANGED], 0, | ||
775 | 769 | rb_player_playing (player->priv->mmplayer)); | ||
776 | 770 | } | ||
777 | 771 | |||
778 | 772 | static void | ||
779 | 773 | rb_shell_player_open_playlist_url (RBShellPlayer *player, | ||
780 | 774 | const char *location, | ||
781 | 775 | RhythmDBEntry *entry, | ||
782 | 776 | RBPlayerPlayType play_type) | ||
783 | 777 | { | ||
784 | 778 | GError *error = NULL; | ||
785 | 779 | |||
786 | 780 | rb_debug ("playing stream url %s", location); | ||
787 | 781 | rb_player_open (player->priv->mmplayer, | ||
788 | 782 | location, | ||
789 | 783 | rhythmdb_entry_ref (entry), | ||
790 | 784 | (GDestroyNotify) rhythmdb_entry_unref, | ||
791 | 785 | &error); | ||
792 | 786 | if (error == NULL) | ||
793 | 787 | rb_player_play (player->priv->mmplayer, play_type, player->priv->track_transition_time, &error); | ||
794 | 788 | |||
795 | 789 | if (error) { | ||
796 | 790 | GDK_THREADS_ENTER (); | ||
797 | 791 | rb_shell_player_error (player, TRUE, error); | ||
798 | 792 | g_error_free (error); | ||
799 | 793 | GDK_THREADS_LEAVE (); | ||
800 | 794 | } | ||
801 | 795 | } | ||
802 | 796 | |||
803 | 797 | static void | ||
804 | 798 | rb_shell_player_handle_eos_unlocked (RBShellPlayer *player, RhythmDBEntry *entry, gboolean allow_stop) | ||
805 | 799 | { | ||
806 | 800 | RBSource *source; | ||
807 | 801 | gboolean update_stats; | ||
808 | 802 | gboolean dragging; | ||
809 | 803 | |||
810 | 804 | source = player->priv->current_playing_source; | ||
811 | 805 | |||
812 | 806 | /* nothing to do */ | ||
813 | 807 | if (source == NULL) { | ||
814 | 808 | return; | ||
815 | 809 | } | ||
816 | 810 | |||
817 | 811 | if (player->priv->playing_entry_eos) { | ||
818 | 812 | rb_debug ("playing entry has already EOS'd"); | ||
819 | 813 | return; | ||
820 | 814 | } | ||
821 | 815 | |||
822 | 816 | if (entry != NULL) { | ||
823 | 817 | if (player->priv->playing_entry != entry) { | ||
824 | 818 | rb_debug ("EOS'd entry is not the current playing entry; ignoring"); | ||
825 | 819 | return; | ||
826 | 820 | } | ||
827 | 821 | |||
828 | 822 | rhythmdb_entry_ref (entry); | ||
829 | 823 | } | ||
830 | 824 | |||
831 | 825 | /* defer EOS handling while the position slider is being dragged */ | ||
832 | 826 | g_object_get (player->priv->header_widget, "slider-dragging", &dragging, NULL); | ||
833 | 827 | if (dragging) { | ||
834 | 828 | rb_debug ("slider is dragging, will handle EOS (if applicable) on release"); | ||
835 | 829 | player->priv->playing_entry_eos = TRUE; | ||
836 | 830 | if (entry != NULL) | ||
837 | 831 | rhythmdb_entry_unref (entry); | ||
838 | 832 | return; | ||
839 | 833 | } | ||
840 | 834 | |||
841 | 835 | update_stats = FALSE; | ||
842 | 836 | switch (rb_source_handle_eos (source)) { | ||
843 | 837 | case RB_SOURCE_EOF_ERROR: | ||
844 | 838 | if (allow_stop) { | ||
845 | 839 | rb_error_dialog (NULL, _("Stream error"), | ||
846 | 840 | _("Unexpected end of stream!")); | ||
847 | 841 | rb_shell_player_stop (player); | ||
848 | 842 | player->priv->playing_entry_eos = TRUE; | ||
849 | 843 | update_stats = TRUE; | ||
850 | 844 | } | ||
851 | 845 | break; | ||
852 | 846 | case RB_SOURCE_EOF_STOP: | ||
853 | 847 | if (allow_stop) { | ||
854 | 848 | rb_shell_player_stop (player); | ||
855 | 849 | player->priv->playing_entry_eos = TRUE; | ||
856 | 850 | update_stats = TRUE; | ||
857 | 851 | } | ||
858 | 852 | break; | ||
859 | 853 | case RB_SOURCE_EOF_RETRY: { | ||
860 | 854 | GTimeVal current; | ||
861 | 855 | gint diff; | ||
862 | 856 | |||
863 | 857 | g_get_current_time (¤t); | ||
864 | 858 | diff = current.tv_sec - player->priv->last_retry.tv_sec; | ||
865 | 859 | player->priv->last_retry = current; | ||
866 | 860 | |||
867 | 861 | if (rb_source_try_playlist (source) && | ||
868 | 862 | !g_queue_is_empty (player->priv->playlist_urls)) { | ||
869 | 863 | char *location = g_queue_pop_head (player->priv->playlist_urls); | ||
870 | 864 | rb_debug ("trying next radio stream url: %s", location); | ||
871 | 865 | |||
872 | 866 | /* we're handling an unexpected EOS here, so crossfading isn't | ||
873 | 867 | * really possible anyway -> specify FALSE. | ||
874 | 868 | */ | ||
875 | 869 | rb_shell_player_open_playlist_url (player, location, entry, FALSE); | ||
876 | 870 | g_free (location); | ||
877 | 871 | break; | ||
878 | 872 | } | ||
879 | 873 | |||
880 | 874 | if (allow_stop) { | ||
881 | 875 | if (diff < 4) { | ||
882 | 876 | rb_debug ("Last retry was less than 4 seconds ago...aborting retry playback"); | ||
883 | 877 | rb_shell_player_stop (player); | ||
884 | 878 | } else { | ||
885 | 879 | rb_shell_player_play_entry (player, entry, NULL); | ||
886 | 880 | } | ||
887 | 881 | player->priv->playing_entry_eos = TRUE; | ||
888 | 882 | update_stats = TRUE; | ||
889 | 883 | } | ||
890 | 884 | } | ||
891 | 885 | break; | ||
892 | 886 | case RB_SOURCE_EOF_NEXT: | ||
893 | 887 | { | ||
894 | 888 | GError *error = NULL; | ||
895 | 889 | |||
896 | 890 | player->priv->playing_entry_eos = TRUE; | ||
897 | 891 | update_stats = TRUE; | ||
898 | 892 | if (!rb_shell_player_do_next_internal (player, TRUE, allow_stop, &error)) { | ||
899 | 893 | if (error->domain != RB_SHELL_PLAYER_ERROR || | ||
900 | 894 | error->code != RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST) { | ||
901 | 895 | g_warning ("Unhandled error: %s", error->message); | ||
902 | 896 | } else if (allow_stop == FALSE) { | ||
903 | 897 | /* handle the real EOS when it happens */ | ||
904 | 898 | player->priv->playing_entry_eos = FALSE; | ||
905 | 899 | update_stats = FALSE; | ||
906 | 900 | } | ||
907 | 901 | } | ||
908 | 902 | } | ||
909 | 903 | break; | ||
910 | 904 | } | ||
911 | 905 | |||
912 | 906 | if (update_stats && | ||
913 | 907 | rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_PLAYBACK_ERROR) == NULL) { | ||
914 | 908 | rb_debug ("updating play statistics"); | ||
915 | 909 | rb_source_update_play_statistics (source, | ||
916 | 910 | player->priv->db, | ||
917 | 911 | entry); | ||
918 | 912 | } | ||
919 | 913 | |||
920 | 914 | if (entry != NULL) | ||
921 | 915 | rhythmdb_entry_unref (entry); | ||
922 | 916 | } | ||
923 | 917 | |||
924 | 918 | static void | ||
925 | 919 | rb_shell_player_slider_dragging_cb (GObject *header, GParamSpec *pspec, RBShellPlayer *player) | ||
926 | 920 | { | ||
927 | 921 | gboolean drag; | ||
928 | 922 | |||
929 | 923 | g_object_get (player->priv->header_widget, "slider-dragging", &drag, NULL); | ||
930 | 924 | rb_debug ("slider dragging? %d", drag); | ||
931 | 925 | |||
932 | 926 | /* if an EOS occurred while dragging, process it now */ | ||
933 | 927 | if (drag == FALSE && player->priv->playing_entry_eos) { | ||
934 | 928 | rb_debug ("processing EOS delayed due to slider dragging"); | ||
935 | 929 | player->priv->playing_entry_eos = FALSE; | ||
936 | 930 | rb_shell_player_handle_eos_unlocked (player, rb_shell_player_get_playing_entry (player), FALSE); | ||
937 | 931 | } | ||
938 | 932 | } | ||
939 | 933 | |||
940 | 934 | static void | ||
941 | 935 | rb_shell_player_handle_eos (RBPlayer *player, | ||
942 | 936 | RhythmDBEntry *entry, | ||
943 | 937 | gboolean early, | ||
944 | 938 | RBShellPlayer *shell_player) | ||
945 | 939 | { | ||
946 | 940 | const char *location; | ||
947 | 941 | if (entry == NULL) { | ||
948 | 942 | /* special case: this is called with entry == NULL to simulate an EOS | ||
949 | 943 | * from the current playing entry. | ||
950 | 944 | */ | ||
951 | 945 | entry = shell_player->priv->playing_entry; | ||
952 | 946 | if (entry == NULL) { | ||
953 | 947 | rb_debug ("called to simulate EOS for playing entry, but nothing is playing"); | ||
954 | 948 | return; | ||
955 | 949 | } | ||
956 | 950 | } | ||
957 | 951 | |||
958 | 952 | GDK_THREADS_ENTER (); | ||
959 | 953 | |||
960 | 954 | location = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); | ||
961 | 955 | if (entry != shell_player->priv->playing_entry) { | ||
962 | 956 | rb_debug ("got unexpected eos for %s", location); | ||
963 | 957 | } else { | ||
964 | 958 | rb_debug ("handling eos for %s", location); | ||
965 | 959 | /* don't allow playback to be stopped on early EOS notifications */ | ||
966 | 960 | rb_shell_player_handle_eos_unlocked (shell_player, entry, (early == FALSE)); | ||
967 | 961 | } | ||
968 | 962 | |||
969 | 963 | GDK_THREADS_LEAVE (); | ||
970 | 964 | } | ||
971 | 965 | |||
972 | 966 | |||
973 | 967 | static void | ||
974 | 968 | rb_shell_player_handle_redirect (RBPlayer *player, | ||
975 | 969 | RhythmDBEntry *entry, | ||
976 | 970 | const gchar *uri, | ||
977 | 971 | RBShellPlayer *shell_player) | ||
978 | 972 | { | ||
979 | 973 | GValue val = { 0 }; | ||
980 | 974 | |||
981 | 975 | rb_debug ("redirect to %s", uri); | ||
982 | 976 | |||
983 | 977 | /* Stop existing stream */ | ||
984 | 978 | rb_player_close (shell_player->priv->mmplayer, NULL, NULL); | ||
985 | 979 | |||
986 | 980 | /* Update entry */ | ||
987 | 981 | g_value_init (&val, G_TYPE_STRING); | ||
988 | 982 | g_value_set_string (&val, uri); | ||
989 | 983 | rhythmdb_entry_set (shell_player->priv->db, entry, RHYTHMDB_PROP_LOCATION, &val); | ||
990 | 984 | g_value_unset (&val); | ||
991 | 985 | rhythmdb_commit (shell_player->priv->db); | ||
992 | 986 | |||
993 | 987 | /* Play new URI */ | ||
994 | 988 | rb_shell_player_open_location (shell_player, entry, RB_PLAYER_PLAY_REPLACE, NULL); | ||
995 | 989 | } | ||
996 | 990 | |||
997 | 991 | static void | ||
998 | 992 | rb_shell_player_init (RBShellPlayer *player) | ||
999 | 993 | { | ||
1000 | 994 | GError *error = NULL; | ||
1001 | 995 | |||
1002 | 996 | player->priv = RB_SHELL_PLAYER_GET_PRIVATE (player); | ||
1003 | 997 | |||
1004 | 998 | player->priv->settings = g_settings_new ("org.gnome.rhythmbox.player"); | ||
1005 | 999 | player->priv->ui_settings = g_settings_new ("org.gnome.rhythmbox"); | ||
1006 | 1000 | g_signal_connect_object (player->priv->settings, | ||
1007 | 1001 | "changed", | ||
1008 | 1002 | G_CALLBACK (player_settings_changed_cb), | ||
1009 | 1003 | player, 0); | ||
1010 | 1004 | |||
1011 | 1005 | player->priv->play_orders = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)_play_order_description_free); | ||
1012 | 1006 | |||
1013 | 1007 | rb_shell_player_add_play_order (player, "linear", N_("Linear"), | ||
1014 | 1008 | RB_TYPE_LINEAR_PLAY_ORDER, FALSE); | ||
1015 | 1009 | rb_shell_player_add_play_order (player, "linear-loop", N_("Linear looping"), | ||
1016 | 1010 | RB_TYPE_LINEAR_PLAY_ORDER_LOOP, FALSE); | ||
1017 | 1011 | rb_shell_player_add_play_order (player, "shuffle", N_("Shuffle"), | ||
1018 | 1012 | RB_TYPE_SHUFFLE_PLAY_ORDER, FALSE); | ||
1019 | 1013 | rb_shell_player_add_play_order (player, "random-equal-weights", N_("Random with equal weights"), | ||
1020 | 1014 | RB_TYPE_RANDOM_PLAY_ORDER_EQUAL_WEIGHTS, FALSE); | ||
1021 | 1015 | rb_shell_player_add_play_order (player, "random-by-age", N_("Random by time since last play"), | ||
1022 | 1016 | RB_TYPE_RANDOM_PLAY_ORDER_BY_AGE, FALSE); | ||
1023 | 1017 | rb_shell_player_add_play_order (player, "random-by-rating", N_("Random by rating"), | ||
1024 | 1018 | RB_TYPE_RANDOM_PLAY_ORDER_BY_RATING, FALSE); | ||
1025 | 1019 | rb_shell_player_add_play_order (player, "random-by-age-and-rating", N_("Random by time since last play and rating"), | ||
1026 | 1020 | RB_TYPE_RANDOM_PLAY_ORDER_BY_AGE_AND_RATING, FALSE); | ||
1027 | 1021 | rb_shell_player_add_play_order (player, "queue", N_("Linear, removing entries once played"), | ||
1028 | 1022 | RB_TYPE_QUEUE_PLAY_ORDER, TRUE); | ||
1029 | 1023 | |||
1030 | 1024 | player->priv->mmplayer = rb_player_new (g_settings_get_boolean (player->priv->settings, "use-xfade-backend"), | ||
1031 | 1025 | &error); | ||
1032 | 1026 | if (error != NULL) { | ||
1033 | 1027 | GtkWidget *dialog; | ||
1034 | 1028 | dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, | ||
1035 | 1029 | GTK_MESSAGE_ERROR, | ||
1036 | 1030 | GTK_BUTTONS_CLOSE, | ||
1037 | 1031 | _("Failed to create the player: %s"), | ||
1038 | 1032 | error->message); | ||
1039 | 1033 | gtk_dialog_run (GTK_DIALOG (dialog)); | ||
1040 | 1034 | exit (1); | ||
1041 | 1035 | } | ||
1042 | 1036 | |||
1043 | 1037 | g_signal_connect_object (player->priv->mmplayer, | ||
1044 | 1038 | "eos", | ||
1045 | 1039 | G_CALLBACK (rb_shell_player_handle_eos), | ||
1046 | 1040 | player, 0); | ||
1047 | 1041 | |||
1048 | 1042 | g_signal_connect_object (player->priv->mmplayer, | ||
1049 | 1043 | "redirect", | ||
1050 | 1044 | G_CALLBACK (rb_shell_player_handle_redirect), | ||
1051 | 1045 | player, 0); | ||
1052 | 1046 | |||
1053 | 1047 | g_signal_connect_object (player->priv->mmplayer, | ||
1054 | 1048 | "tick", | ||
1055 | 1049 | G_CALLBACK (tick_cb), | ||
1056 | 1050 | player, 0); | ||
1057 | 1051 | |||
1058 | 1052 | g_signal_connect_object (player->priv->mmplayer, | ||
1059 | 1053 | "error", | ||
1060 | 1054 | G_CALLBACK (error_cb), | ||
1061 | 1055 | player, 0); | ||
1062 | 1056 | |||
1063 | 1057 | g_signal_connect_object (player->priv->mmplayer, | ||
1064 | 1058 | "playing-stream", | ||
1065 | 1059 | G_CALLBACK (playing_stream_cb), | ||
1066 | 1060 | player, 0); | ||
1067 | 1061 | |||
1068 | 1062 | g_signal_connect_object (player->priv->mmplayer, | ||
1069 | 1063 | "missing-plugins", | ||
1070 | 1064 | G_CALLBACK (missing_plugins_cb), | ||
1071 | 1065 | player, 0); | ||
1072 | 1066 | g_signal_connect_object (player->priv->mmplayer, | ||
1073 | 1067 | "volume-changed", | ||
1074 | 1068 | G_CALLBACK (rb_shell_player_volume_changed_cb), | ||
1075 | 1069 | player, 0); | ||
1076 | 1070 | |||
1077 | 1071 | g_signal_connect_object (player->priv->mmplayer, | ||
1078 | 1072 | "image", | ||
1079 | 1073 | G_CALLBACK (player_image_cb), | ||
1080 | 1074 | player, 0); | ||
1081 | 1075 | |||
1082 | 1076 | { | ||
1083 | 1077 | GVolumeMonitor *monitor = g_volume_monitor_get (); | ||
1084 | 1078 | g_signal_connect (G_OBJECT (monitor), | ||
1085 | 1079 | "mount-pre-unmount", | ||
1086 | 1080 | G_CALLBACK (volume_pre_unmount_cb), | ||
1087 | 1081 | player); | ||
1088 | 1082 | g_object_unref (monitor); /* hmm */ | ||
1089 | 1083 | } | ||
1090 | 1084 | |||
1091 | 1085 | player->priv->volume = g_settings_get_double (player->priv->settings, "volume"); | ||
1092 | 1086 | |||
1093 | 1087 | g_signal_connect (player, "notify::playing", | ||
1094 | 1088 | G_CALLBACK (reemit_playing_signal), NULL); | ||
1095 | 1089 | } | ||
1096 | 1090 | |||
1097 | 1091 | static void | ||
1098 | 1092 | rb_shell_player_set_source_internal (RBShellPlayer *player, | ||
1099 | 1093 | RBSource *source) | ||
1100 | 1094 | { | ||
1101 | 1095 | if (player->priv->selected_source != NULL) { | ||
1102 | 1096 | RBEntryView *songs = rb_source_get_entry_view (player->priv->selected_source); | ||
1103 | 1097 | GList *property_views = rb_source_get_property_views (player->priv->selected_source); | ||
1104 | 1098 | GList *l; | ||
1105 | 1099 | |||
1106 | 1100 | if (songs != NULL) { | ||
1107 | 1101 | g_signal_handlers_disconnect_by_func (G_OBJECT (songs), | ||
1108 | 1102 | G_CALLBACK (rb_shell_player_entry_activated_cb), | ||
1109 | 1103 | player); | ||
1110 | 1104 | } | ||
1111 | 1105 | |||
1112 | 1106 | for (l = property_views; l != NULL; l = g_list_next (l)) { | ||
1113 | 1107 | g_signal_handlers_disconnect_by_func (G_OBJECT (l->data), | ||
1114 | 1108 | G_CALLBACK (rb_shell_player_property_row_activated_cb), | ||
1115 | 1109 | player); | ||
1116 | 1110 | } | ||
1117 | 1111 | |||
1118 | 1112 | g_list_free (property_views); | ||
1119 | 1113 | } | ||
1120 | 1114 | |||
1121 | 1115 | player->priv->selected_source = source; | ||
1122 | 1116 | |||
1123 | 1117 | rb_debug ("selected source %p", player->priv->selected_source); | ||
1124 | 1118 | |||
1125 | 1119 | rb_shell_player_sync_with_selected_source (player); | ||
1126 | 1120 | rb_shell_player_sync_buttons (player); | ||
1127 | 1121 | |||
1128 | 1122 | if (player->priv->selected_source != NULL) { | ||
1129 | 1123 | RBEntryView *songs = rb_source_get_entry_view (player->priv->selected_source); | ||
1130 | 1124 | GList *property_views = rb_source_get_property_views (player->priv->selected_source); | ||
1131 | 1125 | GList *l; | ||
1132 | 1126 | |||
1133 | 1127 | if (songs) | ||
1134 | 1128 | g_signal_connect_object (G_OBJECT (songs), | ||
1135 | 1129 | "entry-activated", | ||
1136 | 1130 | G_CALLBACK (rb_shell_player_entry_activated_cb), | ||
1137 | 1131 | player, 0); | ||
1138 | 1132 | for (l = property_views; l != NULL; l = g_list_next (l)) { | ||
1139 | 1133 | g_signal_connect_object (G_OBJECT (l->data), | ||
1140 | 1134 | "property-activated", | ||
1141 | 1135 | G_CALLBACK (rb_shell_player_property_row_activated_cb), | ||
1142 | 1136 | player, 0); | ||
1143 | 1137 | } | ||
1144 | 1138 | |||
1145 | 1139 | g_list_free (property_views); | ||
1146 | 1140 | } | ||
1147 | 1141 | |||
1148 | 1142 | /* If we're not playing, change the play order's view of the current source; | ||
1149 | 1143 | * if the selected source is the queue, however, set it to NULL so it'll stop | ||
1150 | 1144 | * once the queue is empty. | ||
1151 | 1145 | */ | ||
1152 | 1146 | if (player->priv->current_playing_source == NULL) { | ||
1153 | 1147 | RBPlayOrder *porder = NULL; | ||
1154 | 1148 | RBSource *source = player->priv->selected_source; | ||
1155 | 1149 | if (source == RB_SOURCE (player->priv->queue_source)) { | ||
1156 | 1150 | source = NULL; | ||
1157 | 1151 | } else if (source != NULL) { | ||
1158 | 1152 | g_object_get (source, "play-order", &porder, NULL); | ||
1159 | 1153 | } | ||
1160 | 1154 | |||
1161 | 1155 | if (porder == NULL) | ||
1162 | 1156 | porder = g_object_ref (player->priv->play_order); | ||
1163 | 1157 | |||
1164 | 1158 | rb_play_order_playing_source_changed (porder, source); | ||
1165 | 1159 | g_object_unref (porder); | ||
1166 | 1160 | } | ||
1167 | 1161 | } | ||
1168 | 1162 | |||
1169 | 1163 | static void | ||
1170 | 1164 | rb_shell_player_set_db_internal (RBShellPlayer *player, | ||
1171 | 1165 | RhythmDB *db) | ||
1172 | 1166 | { | ||
1173 | 1167 | if (player->priv->db != NULL) { | ||
1174 | 1168 | g_signal_handlers_disconnect_by_func (player->priv->db, | ||
1175 | 1169 | G_CALLBACK (rb_shell_player_entry_changed_cb), | ||
1176 | 1170 | player); | ||
1177 | 1171 | g_signal_handlers_disconnect_by_func (player->priv->db, | ||
1178 | 1172 | G_CALLBACK (rb_shell_player_extra_metadata_cb), | ||
1179 | 1173 | player); | ||
1180 | 1174 | } | ||
1181 | 1175 | |||
1182 | 1176 | player->priv->db = db; | ||
1183 | 1177 | |||
1184 | 1178 | if (player->priv->db != NULL) { | ||
1185 | 1179 | /* Listen for changed entries to update metadata display */ | ||
1186 | 1180 | g_signal_connect_object (G_OBJECT (player->priv->db), | ||
1187 | 1181 | "entry_changed", | ||
1188 | 1182 | G_CALLBACK (rb_shell_player_entry_changed_cb), | ||
1189 | 1183 | player, 0); | ||
1190 | 1184 | g_signal_connect_object (G_OBJECT (player->priv->db), | ||
1191 | 1185 | "entry_extra_metadata_notify", | ||
1192 | 1186 | G_CALLBACK (rb_shell_player_extra_metadata_cb), | ||
1193 | 1187 | player, 0); | ||
1194 | 1188 | } | ||
1195 | 1189 | } | ||
1196 | 1190 | |||
1197 | 1191 | static void | ||
1198 | 1192 | rb_shell_player_set_queue_source_internal (RBShellPlayer *player, | ||
1199 | 1193 | RBPlayQueueSource *source) | ||
1200 | 1194 | { | ||
1201 | 1195 | if (player->priv->queue_source != NULL) { | ||
1202 | 1196 | RBEntryView *sidebar; | ||
1203 | 1197 | |||
1204 | 1198 | g_object_get (player->priv->queue_source, "sidebar", &sidebar, NULL); | ||
1205 | 1199 | g_signal_handlers_disconnect_by_func (sidebar, | ||
1206 | 1200 | G_CALLBACK (rb_shell_player_entry_activated_cb), | ||
1207 | 1201 | player); | ||
1208 | 1202 | g_object_unref (sidebar); | ||
1209 | 1203 | |||
1210 | 1204 | if (player->priv->queue_play_order != NULL) { | ||
1211 | 1205 | g_signal_handlers_disconnect_by_func (player->priv->queue_play_order, | ||
1212 | 1206 | G_CALLBACK (rb_shell_player_play_order_update_cb), | ||
1213 | 1207 | player); | ||
1214 | 1208 | g_object_unref (player->priv->queue_play_order); | ||
1215 | 1209 | } | ||
1216 | 1210 | |||
1217 | 1211 | } | ||
1218 | 1212 | |||
1219 | 1213 | player->priv->queue_source = source; | ||
1220 | 1214 | |||
1221 | 1215 | if (player->priv->queue_source != NULL) { | ||
1222 | 1216 | RBEntryView *sidebar; | ||
1223 | 1217 | |||
1224 | 1218 | g_object_get (player->priv->queue_source, "play-order", &player->priv->queue_play_order, NULL); | ||
1225 | 1219 | |||
1226 | 1220 | g_signal_connect_object (G_OBJECT (player->priv->queue_play_order), | ||
1227 | 1221 | "have_next_previous_changed", | ||
1228 | 1222 | G_CALLBACK (rb_shell_player_play_order_update_cb), | ||
1229 | 1223 | player, 0); | ||
1230 | 1224 | rb_shell_player_play_order_update_cb (player->priv->play_order, | ||
1231 | 1225 | FALSE, FALSE, | ||
1232 | 1226 | player); | ||
1233 | 1227 | rb_play_order_playing_source_changed (player->priv->queue_play_order, | ||
1234 | 1228 | RB_SOURCE (player->priv->queue_source)); | ||
1235 | 1229 | |||
1236 | 1230 | g_object_get (player->priv->queue_source, "sidebar", &sidebar, NULL); | ||
1237 | 1231 | g_signal_connect_object (G_OBJECT (sidebar), | ||
1238 | 1232 | "entry-activated", | ||
1239 | 1233 | G_CALLBACK (rb_shell_player_entry_activated_cb), | ||
1240 | 1234 | player, 0); | ||
1241 | 1235 | g_object_unref (sidebar); | ||
1242 | 1236 | } | ||
1243 | 1237 | } | ||
1244 | 1238 | |||
1245 | 1239 | static void | ||
1246 | 1240 | rb_shell_player_dispose (GObject *object) | ||
1247 | 1241 | { | ||
1248 | 1242 | RBShellPlayer *player; | ||
1249 | 1243 | |||
1250 | 1244 | g_return_if_fail (object != NULL); | ||
1251 | 1245 | g_return_if_fail (RB_IS_SHELL_PLAYER (object)); | ||
1252 | 1246 | |||
1253 | 1247 | player = RB_SHELL_PLAYER (object); | ||
1254 | 1248 | |||
1255 | 1249 | g_return_if_fail (player->priv != NULL); | ||
1256 | 1250 | |||
1257 | 1251 | if (player->priv->ui_settings != NULL) { | ||
1258 | 1252 | g_object_unref (player->priv->ui_settings); | ||
1259 | 1253 | player->priv->ui_settings = NULL; | ||
1260 | 1254 | } | ||
1261 | 1255 | |||
1262 | 1256 | if (player->priv->settings != NULL) { | ||
1263 | 1257 | /* hm, is this really the place to do this? */ | ||
1264 | 1258 | g_settings_set_double (player->priv->settings, | ||
1265 | 1259 | "volume", | ||
1266 | 1260 | player->priv->volume); | ||
1267 | 1261 | |||
1268 | 1262 | g_object_unref (player->priv->settings); | ||
1269 | 1263 | player->priv->settings = NULL; | ||
1270 | 1264 | } | ||
1271 | 1265 | |||
1272 | 1266 | if (player->priv->mmplayer != NULL) { | ||
1273 | 1267 | g_object_unref (player->priv->mmplayer); | ||
1274 | 1268 | player->priv->mmplayer = NULL; | ||
1275 | 1269 | } | ||
1276 | 1270 | |||
1277 | 1271 | if (player->priv->play_order != NULL) { | ||
1278 | 1272 | g_object_unref (player->priv->play_order); | ||
1279 | 1273 | player->priv->play_order = NULL; | ||
1280 | 1274 | } | ||
1281 | 1275 | |||
1282 | 1276 | if (player->priv->queue_play_order != NULL) { | ||
1283 | 1277 | g_object_unref (player->priv->queue_play_order); | ||
1284 | 1278 | player->priv->queue_play_order = NULL; | ||
1285 | 1279 | } | ||
1286 | 1280 | |||
1287 | 1281 | if (player->priv->do_next_idle_id != 0) { | ||
1288 | 1282 | g_source_remove (player->priv->do_next_idle_id); | ||
1289 | 1283 | player->priv->do_next_idle_id = 0; | ||
1290 | 1284 | } | ||
1291 | 1285 | |||
1292 | 1286 | if (player->priv->unblock_play_id != 0) { | ||
1293 | 1287 | g_source_remove (player->priv->unblock_play_id); | ||
1294 | 1288 | player->priv->unblock_play_id = 0; | ||
1295 | 1289 | } | ||
1296 | 1290 | |||
1297 | 1291 | G_OBJECT_CLASS (rb_shell_player_parent_class)->dispose (object); | ||
1298 | 1292 | } | ||
1299 | 1293 | |||
1300 | 1294 | static void | ||
1301 | 1295 | rb_shell_player_finalize (GObject *object) | ||
1302 | 1296 | { | ||
1303 | 1297 | RBShellPlayer *player; | ||
1304 | 1298 | |||
1305 | 1299 | g_return_if_fail (object != NULL); | ||
1306 | 1300 | g_return_if_fail (RB_IS_SHELL_PLAYER (object)); | ||
1307 | 1301 | |||
1308 | 1302 | player = RB_SHELL_PLAYER (object); | ||
1309 | 1303 | |||
1310 | 1304 | g_return_if_fail (player->priv != NULL); | ||
1311 | 1305 | |||
1312 | 1306 | g_hash_table_destroy (player->priv->play_orders); | ||
1313 | 1307 | |||
1314 | 1308 | G_OBJECT_CLASS (rb_shell_player_parent_class)->finalize (object); | ||
1315 | 1309 | } | ||
1316 | 1310 | |||
1317 | 1311 | static void | ||
1318 | 1312 | rb_shell_player_set_property (GObject *object, | ||
1319 | 1313 | guint prop_id, | ||
1320 | 1314 | const GValue *value, | ||
1321 | 1315 | GParamSpec *pspec) | ||
1322 | 1316 | { | ||
1323 | 1317 | RBShellPlayer *player = RB_SHELL_PLAYER (object); | ||
1324 | 1318 | |||
1325 | 1319 | switch (prop_id) { | ||
1326 | 1320 | case PROP_SOURCE: | ||
1327 | 1321 | rb_shell_player_set_source_internal (player, g_value_get_object (value)); | ||
1328 | 1322 | break; | ||
1329 | 1323 | case PROP_UI_MANAGER: | ||
1330 | 1324 | player->priv->ui_manager = g_value_get_object (value); | ||
1331 | 1325 | break; | ||
1332 | 1326 | case PROP_DB: | ||
1333 | 1327 | rb_shell_player_set_db_internal (player, g_value_get_object (value)); | ||
1334 | 1328 | break; | ||
1335 | 1329 | case PROP_ACTION_GROUP: | ||
1336 | 1330 | player->priv->actiongroup = g_value_get_object (value); | ||
1337 | 1331 | break; | ||
1338 | 1332 | case PROP_PLAY_ORDER: | ||
1339 | 1333 | g_settings_set_string (player->priv->settings, | ||
1340 | 1334 | "play-order", | ||
1341 | 1335 | g_value_get_string (value)); | ||
1342 | 1336 | break; | ||
1343 | 1337 | case PROP_VOLUME: | ||
1344 | 1338 | player->priv->volume = g_value_get_float (value); | ||
1345 | 1339 | rb_shell_player_sync_volume (player, FALSE, TRUE); | ||
1346 | 1340 | break; | ||
1347 | 1341 | case PROP_HEADER: | ||
1348 | 1342 | player->priv->header_widget = g_value_get_object (value); | ||
1349 | 1343 | g_signal_connect_object (player->priv->header_widget, | ||
1350 | 1344 | "notify::slider-dragging", | ||
1351 | 1345 | G_CALLBACK (rb_shell_player_slider_dragging_cb), | ||
1352 | 1346 | player, 0); | ||
1353 | 1347 | break; | ||
1354 | 1348 | case PROP_QUEUE_SOURCE: | ||
1355 | 1349 | rb_shell_player_set_queue_source_internal (player, g_value_get_object (value)); | ||
1356 | 1350 | break; | ||
1357 | 1351 | case PROP_QUEUE_ONLY: | ||
1358 | 1352 | player->priv->queue_only = g_value_get_boolean (value); | ||
1359 | 1353 | break; | ||
1360 | 1354 | case PROP_MUTE: | ||
1361 | 1355 | player->priv->mute = g_value_get_boolean (value); | ||
1362 | 1356 | rb_shell_player_sync_volume (player, FALSE, TRUE); | ||
1363 | 1357 | default: | ||
1364 | 1358 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
1365 | 1359 | break; | ||
1366 | 1360 | } | ||
1367 | 1361 | } | ||
1368 | 1362 | |||
1369 | 1363 | static void | ||
1370 | 1364 | rb_shell_player_get_property (GObject *object, | ||
1371 | 1365 | guint prop_id, | ||
1372 | 1366 | GValue *value, | ||
1373 | 1367 | GParamSpec *pspec) | ||
1374 | 1368 | { | ||
1375 | 1369 | RBShellPlayer *player = RB_SHELL_PLAYER (object); | ||
1376 | 1370 | |||
1377 | 1371 | switch (prop_id) { | ||
1378 | 1372 | case PROP_SOURCE: | ||
1379 | 1373 | g_value_set_object (value, player->priv->selected_source); | ||
1380 | 1374 | break; | ||
1381 | 1375 | case PROP_UI_MANAGER: | ||
1382 | 1376 | g_value_set_object (value, player->priv->ui_manager); | ||
1383 | 1377 | break; | ||
1384 | 1378 | case PROP_DB: | ||
1385 | 1379 | g_value_set_object (value, player->priv->db); | ||
1386 | 1380 | break; | ||
1387 | 1381 | case PROP_ACTION_GROUP: | ||
1388 | 1382 | g_value_set_object (value, player->priv->actiongroup); | ||
1389 | 1383 | break; | ||
1390 | 1384 | case PROP_PLAY_ORDER: | ||
1391 | 1385 | { | ||
1392 | 1386 | char *play_order = g_settings_get_string (player->priv->settings, | ||
1393 | 1387 | "play-order"); | ||
1394 | 1388 | if (play_order == NULL) | ||
1395 | 1389 | play_order = g_strdup ("linear"); | ||
1396 | 1390 | g_value_take_string (value, play_order); | ||
1397 | 1391 | break; | ||
1398 | 1392 | } | ||
1399 | 1393 | case PROP_PLAYING: | ||
1400 | 1394 | if (player->priv->mmplayer != NULL) | ||
1401 | 1395 | g_value_set_boolean (value, rb_player_playing (player->priv->mmplayer)); | ||
1402 | 1396 | else | ||
1403 | 1397 | g_value_set_boolean (value, FALSE); | ||
1404 | 1398 | break; | ||
1405 | 1399 | case PROP_VOLUME: | ||
1406 | 1400 | g_value_set_float (value, player->priv->volume); | ||
1407 | 1401 | break; | ||
1408 | 1402 | case PROP_HEADER: | ||
1409 | 1403 | g_value_set_object (value, player->priv->header_widget); | ||
1410 | 1404 | break; | ||
1411 | 1405 | case PROP_QUEUE_SOURCE: | ||
1412 | 1406 | g_value_set_object (value, player->priv->queue_source); | ||
1413 | 1407 | break; | ||
1414 | 1408 | case PROP_QUEUE_ONLY: | ||
1415 | 1409 | g_value_set_boolean (value, player->priv->queue_only); | ||
1416 | 1410 | break; | ||
1417 | 1411 | case PROP_PLAYING_FROM_QUEUE: | ||
1418 | 1412 | g_value_set_boolean (value, player->priv->current_playing_source == RB_SOURCE (player->priv->queue_source)); | ||
1419 | 1413 | break; | ||
1420 | 1414 | case PROP_PLAYER: | ||
1421 | 1415 | g_value_set_object (value, player->priv->mmplayer); | ||
1422 | 1416 | break; | ||
1423 | 1417 | case PROP_MUTE: | ||
1424 | 1418 | g_value_set_boolean (value, player->priv->mute); | ||
1425 | 1419 | break; | ||
1426 | 1420 | case PROP_HAS_NEXT: | ||
1427 | 1421 | g_value_set_boolean (value, player->priv->has_next); | ||
1428 | 1422 | break; | ||
1429 | 1423 | case PROP_HAS_PREV: | ||
1430 | 1424 | g_value_set_boolean (value, player->priv->has_prev); | ||
1431 | 1425 | break; | ||
1432 | 1426 | default: | ||
1433 | 1427 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||
1434 | 1428 | break; | ||
1435 | 1429 | } | ||
1436 | 1430 | } | ||
1437 | 1431 | |||
1438 | 1432 | GQuark | ||
1439 | 1433 | rb_shell_player_error_quark (void) | ||
1440 | 1434 | { | ||
1441 | 1435 | static GQuark quark = 0; | ||
1442 | 1436 | if (!quark) | ||
1443 | 1437 | quark = g_quark_from_static_string ("rb_shell_player_error"); | ||
1444 | 1438 | |||
1445 | 1439 | return quark; | ||
1446 | 1440 | } | ||
1447 | 1441 | |||
1448 | 1442 | /** | ||
1449 | 1443 | * rb_shell_player_set_selected_source: | ||
1450 | 1444 | * @player: the #RBShellPlayer | ||
1451 | 1445 | * @source: the #RBSource to select | ||
1452 | 1446 | * | ||
1453 | 1447 | * Updates the player to reflect a new source being selected. | ||
1454 | 1448 | */ | ||
1455 | 1449 | void | ||
1456 | 1450 | rb_shell_player_set_selected_source (RBShellPlayer *player, | ||
1457 | 1451 | RBSource *source) | ||
1458 | 1452 | { | ||
1459 | 1453 | g_return_if_fail (RB_IS_SHELL_PLAYER (player)); | ||
1460 | 1454 | g_return_if_fail (source == NULL || RB_IS_SOURCE (source)); | ||
1461 | 1455 | |||
1462 | 1456 | g_object_set (player, "source", source, NULL); | ||
1463 | 1457 | } | ||
1464 | 1458 | |||
1465 | 1459 | /** | ||
1466 | 1460 | * rb_shell_player_get_playing_source: | ||
1467 | 1461 | * @player: the #RBShellPlayer | ||
1468 | 1462 | * | ||
1469 | 1463 | * Retrieves the current playing source. That is, the source from | ||
1470 | 1464 | * which the current song was drawn. This differs from | ||
1471 | 1465 | * #rb_shell_player_get_active_source when the current song came | ||
1472 | 1466 | * from the play queue. | ||
1473 | 1467 | * | ||
1474 | 1468 | * Return value: (transfer none): the current playing #RBSource | ||
1475 | 1469 | */ | ||
1476 | 1470 | RBSource * | ||
1477 | 1471 | rb_shell_player_get_playing_source (RBShellPlayer *player) | ||
1478 | 1472 | { | ||
1479 | 1473 | return player->priv->current_playing_source; | ||
1480 | 1474 | } | ||
1481 | 1475 | |||
1482 | 1476 | /** | ||
1483 | 1477 | * rb_shell_player_get_active_source: | ||
1484 | 1478 | * @player: the #RBShellPlayer | ||
1485 | 1479 | * | ||
1486 | 1480 | * Retrieves the active source. This is the source that the user | ||
1487 | 1481 | * selected for playback. | ||
1488 | 1482 | * | ||
1489 | 1483 | * Return value: (transfer none): the active #RBSource | ||
1490 | 1484 | */ | ||
1491 | 1485 | RBSource * | ||
1492 | 1486 | rb_shell_player_get_active_source (RBShellPlayer *player) | ||
1493 | 1487 | { | ||
1494 | 1488 | return player->priv->source; | ||
1495 | 1489 | } | ||
1496 | 1490 | |||
1497 | 1491 | /** | ||
1498 | 1492 | * rb_shell_player_new: | ||
1499 | 1493 | * @db: the #RhythmDB | ||
1500 | 1494 | * @mgr: the #GtkUIManager | ||
1501 | 1495 | * @actiongroup: the #GtkActionGroup to use | ||
1502 | 1496 | * | ||
1503 | 1497 | * Creates the #RBShellPlayer | ||
1504 | 1498 | * | ||
1505 | 1499 | * Return value: the #RBShellPlayer instance | ||
1506 | 1500 | */ | ||
1507 | 1501 | RBShellPlayer * | ||
1508 | 1502 | rb_shell_player_new (RhythmDB *db, | ||
1509 | 1503 | GtkUIManager *mgr, | ||
1510 | 1504 | GtkActionGroup *actiongroup) | ||
1511 | 1505 | { | ||
1512 | 1506 | return g_object_new (RB_TYPE_SHELL_PLAYER, | ||
1513 | 1507 | "ui-manager", mgr, | ||
1514 | 1508 | "action-group", actiongroup, | ||
1515 | 1509 | "db", db, | ||
1516 | 1510 | NULL); | ||
1517 | 1511 | } | ||
1518 | 1512 | |||
1519 | 1513 | /** | ||
1520 | 1514 | * rb_shell_player_get_playing_entry: | ||
1521 | 1515 | * @player: the #RBShellPlayer | ||
1522 | 1516 | * | ||
1523 | 1517 | * Retrieves the currently playing #RhythmDBEntry, or NULL if | ||
1524 | 1518 | * nothing is playing. The caller must unref the entry | ||
1525 | 1519 | * (using #rhythmdb_entry_unref) when it is no longer needed. | ||
1526 | 1520 | * | ||
1527 | 1521 | * Return value: (transfer full) (allow-none): the currently playing #RhythmDBEntry, or NULL | ||
1528 | 1522 | */ | ||
1529 | 1523 | RhythmDBEntry * | ||
1530 | 1524 | rb_shell_player_get_playing_entry (RBShellPlayer *player) | ||
1531 | 1525 | { | ||
1532 | 1526 | RBPlayOrder *porder; | ||
1533 | 1527 | RhythmDBEntry *entry; | ||
1534 | 1528 | |||
1535 | 1529 | if (player->priv->current_playing_source == NULL) { | ||
1536 | 1530 | return NULL; | ||
1537 | 1531 | } | ||
1538 | 1532 | |||
1539 | 1533 | g_object_get (player->priv->current_playing_source, "play-order", &porder, NULL); | ||
1540 | 1534 | if (porder == NULL) | ||
1541 | 1535 | porder = g_object_ref (player->priv->play_order); | ||
1542 | 1536 | |||
1543 | 1537 | entry = rb_play_order_get_playing_entry (porder); | ||
1544 | 1538 | g_object_unref (porder); | ||
1545 | 1539 | |||
1546 | 1540 | return entry; | ||
1547 | 1541 | } | ||
1548 | 1542 | |||
1549 | 1543 | typedef struct { | ||
1550 | 1544 | RBShellPlayer *player; | ||
1551 | 1545 | char *location; | ||
1552 | 1546 | RhythmDBEntry *entry; | ||
1553 | 1547 | RBPlayerPlayType play_type; | ||
1554 | 1548 | GCancellable *cancellable; | ||
1555 | 1549 | } OpenLocationThreadData; | ||
1556 | 1550 | |||
1557 | 1551 | static void | ||
1558 | 1552 | playlist_entry_cb (TotemPlParser *playlist, | ||
1559 | 1553 | const char *uri, | ||
1560 | 1554 | GHashTable *metadata, | ||
1561 | 1555 | OpenLocationThreadData *data) | ||
1562 | 1556 | { | ||
1563 | 1557 | if (g_cancellable_is_cancelled (data->cancellable)) { | ||
1564 | 1558 | rb_debug ("playlist parser cancelled"); | ||
1565 | 1559 | } else { | ||
1566 | 1560 | rb_debug ("adding stream url %s (%p)", uri, playlist); | ||
1567 | 1561 | g_queue_push_tail (data->player->priv->playlist_urls, g_strdup (uri)); | ||
1568 | 1562 | } | ||
1569 | 1563 | } | ||
1570 | 1564 | |||
1571 | 1565 | static gpointer | ||
1572 | 1566 | open_location_thread (OpenLocationThreadData *data) | ||
1573 | 1567 | { | ||
1574 | 1568 | TotemPlParser *playlist; | ||
1575 | 1569 | TotemPlParserResult playlist_result; | ||
1576 | 1570 | |||
1577 | 1571 | playlist = totem_pl_parser_new (); | ||
1578 | 1572 | |||
1579 | 1573 | g_signal_connect_data (playlist, "entry-parsed", | ||
1580 | 1574 | G_CALLBACK (playlist_entry_cb), | ||
1581 | 1575 | data, NULL, 0); | ||
1582 | 1576 | |||
1583 | 1577 | totem_pl_parser_add_ignored_mimetype (playlist, "x-directory/normal"); | ||
1584 | 1578 | totem_pl_parser_add_ignored_mimetype (playlist, "inode/directory"); | ||
1585 | 1579 | |||
1586 | 1580 | playlist_result = totem_pl_parser_parse (playlist, data->location, FALSE); | ||
1587 | 1581 | g_object_unref (playlist); | ||
1588 | 1582 | |||
1589 | 1583 | if (g_cancellable_is_cancelled (data->cancellable)) { | ||
1590 | 1584 | playlist_result = TOTEM_PL_PARSER_RESULT_CANCELLED; | ||
1591 | 1585 | } | ||
1592 | 1586 | |||
1593 | 1587 | switch (playlist_result) { | ||
1594 | 1588 | case TOTEM_PL_PARSER_RESULT_SUCCESS: | ||
1595 | 1589 | if (g_queue_is_empty (data->player->priv->playlist_urls)) { | ||
1596 | 1590 | GError *error = g_error_new (RB_SHELL_PLAYER_ERROR, | ||
1597 | 1591 | RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST, | ||
1598 | 1592 | _("Playlist was empty")); | ||
1599 | 1593 | GDK_THREADS_ENTER (); | ||
1600 | 1594 | rb_shell_player_error (data->player, TRUE, error); | ||
1601 | 1595 | g_error_free (error); | ||
1602 | 1596 | GDK_THREADS_LEAVE (); | ||
1603 | 1597 | } else { | ||
1604 | 1598 | char *location; | ||
1605 | 1599 | |||
1606 | 1600 | location = g_queue_pop_head (data->player->priv->playlist_urls); | ||
1607 | 1601 | rb_debug ("playing first stream url %s", location); | ||
1608 | 1602 | rb_shell_player_open_playlist_url (data->player, location, data->entry, data->play_type); | ||
1609 | 1603 | g_free (location); | ||
1610 | 1604 | } | ||
1611 | 1605 | break; | ||
1612 | 1606 | |||
1613 | 1607 | case TOTEM_PL_PARSER_RESULT_CANCELLED: | ||
1614 | 1608 | rb_debug ("playlist parser was cancelled"); | ||
1615 | 1609 | break; | ||
1616 | 1610 | |||
1617 | 1611 | default: | ||
1618 | 1612 | /* if we can't parse it as a playlist, just try playing it */ | ||
1619 | 1613 | rb_debug ("playlist parser failed, playing %s directly", data->location); | ||
1620 | 1614 | rb_shell_player_open_playlist_url (data->player, data->location, data->entry, data->play_type); | ||
1621 | 1615 | break; | ||
1622 | 1616 | } | ||
1623 | 1617 | |||
1624 | 1618 | g_object_unref (data->cancellable); | ||
1625 | 1619 | g_free (data); | ||
1626 | 1620 | return NULL; | ||
1627 | 1621 | } | ||
1628 | 1622 | |||
1629 | 1623 | static gboolean | ||
1630 | 1624 | rb_shell_player_open_location (RBShellPlayer *player, | ||
1631 | 1625 | RhythmDBEntry *entry, | ||
1632 | 1626 | RBPlayerPlayType play_type, | ||
1633 | 1627 | GError **error) | ||
1634 | 1628 | { | ||
1635 | 1629 | char *location; | ||
1636 | 1630 | gboolean ret = TRUE; | ||
1637 | 1631 | |||
1638 | 1632 | /* dispose of any existing playlist urls */ | ||
1639 | 1633 | if (player->priv->playlist_urls) { | ||
1640 | 1634 | g_queue_foreach (player->priv->playlist_urls, | ||
1641 | 1635 | (GFunc) g_free, | ||
1642 | 1636 | NULL); | ||
1643 | 1637 | g_queue_free (player->priv->playlist_urls); | ||
1644 | 1638 | player->priv->playlist_urls = NULL; | ||
1645 | 1639 | } | ||
1646 | 1640 | if (rb_source_try_playlist (player->priv->source)) { | ||
1647 | 1641 | player->priv->playlist_urls = g_queue_new (); | ||
1648 | 1642 | } | ||
1649 | 1643 | |||
1650 | 1644 | location = rhythmdb_entry_get_playback_uri (entry); | ||
1651 | 1645 | if (location == NULL) { | ||
1652 | 1646 | return FALSE; | ||
1653 | 1647 | } | ||
1654 | 1648 | |||
1655 | 1649 | if (rb_source_try_playlist (player->priv->source)) { | ||
1656 | 1650 | OpenLocationThreadData *data; | ||
1657 | 1651 | |||
1658 | 1652 | data = g_new0 (OpenLocationThreadData, 1); | ||
1659 | 1653 | data->player = player; | ||
1660 | 1654 | data->play_type = play_type; | ||
1661 | 1655 | data->entry = entry; | ||
1662 | 1656 | |||
1663 | 1657 | /* add http:// as a prefix, if it doesn't have a URI scheme */ | ||
1664 | 1658 | if (strstr (location, "://")) | ||
1665 | 1659 | data->location = g_strdup (location); | ||
1666 | 1660 | else | ||
1667 | 1661 | data->location = g_strconcat ("http://", location, NULL); | ||
1668 | 1662 | |||
1669 | 1663 | if (player->priv->parser_cancellable == NULL) { | ||
1670 | 1664 | player->priv->parser_cancellable = g_cancellable_new (); | ||
1671 | 1665 | } | ||
1672 | 1666 | data->cancellable = g_object_ref (player->priv->parser_cancellable); | ||
1673 | 1667 | |||
1674 | 1668 | g_thread_create ((GThreadFunc)open_location_thread, data, FALSE, NULL); | ||
1675 | 1669 | } else { | ||
1676 | 1670 | if (player->priv->parser_cancellable != NULL) { | ||
1677 | 1671 | g_object_unref (player->priv->parser_cancellable); | ||
1678 | 1672 | player->priv->parser_cancellable = NULL; | ||
1679 | 1673 | } | ||
1680 | 1674 | |||
1681 | 1675 | rhythmdb_entry_ref (entry); | ||
1682 | 1676 | ret = ret && rb_player_open (player->priv->mmplayer, location, entry, (GDestroyNotify) rhythmdb_entry_unref, error); | ||
1683 | 1677 | |||
1684 | 1678 | ret = ret && rb_player_play (player->priv->mmplayer, play_type, player->priv->track_transition_time, error); | ||
1685 | 1679 | } | ||
1686 | 1680 | |||
1687 | 1681 | g_free (location); | ||
1688 | 1682 | return ret; | ||
1689 | 1683 | } | ||
1690 | 1684 | |||
1691 | 1685 | /** | ||
1692 | 1686 | * rb_shell_player_play: | ||
1693 | 1687 | * @player: a #RBShellPlayer | ||
1694 | 1688 | * @error: error return | ||
1695 | 1689 | * | ||
1696 | 1690 | * Starts playback, if it is not already playing. | ||
1697 | 1691 | * | ||
1698 | 1692 | * Return value: whether playback is now occurring (TRUE when successfully started | ||
1699 | 1693 | * or already playing). | ||
1700 | 1694 | **/ | ||
1701 | 1695 | gboolean | ||
1702 | 1696 | rb_shell_player_play (RBShellPlayer *player, | ||
1703 | 1697 | GError **error) | ||
1704 | 1698 | { | ||
1705 | 1699 | RBEntryView *songs; | ||
1706 | 1700 | |||
1707 | 1701 | if (player->priv->current_playing_source == NULL) { | ||
1708 | 1702 | rb_debug ("current playing source is NULL"); | ||
1709 | 1703 | g_set_error (error, | ||
1710 | 1704 | RB_SHELL_PLAYER_ERROR, | ||
1711 | 1705 | RB_SHELL_PLAYER_ERROR_NOT_PLAYING, | ||
1712 | 1706 | "Current playing source is NULL"); | ||
1713 | 1707 | return FALSE; | ||
1714 | 1708 | } | ||
1715 | 1709 | |||
1716 | 1710 | if (rb_player_playing (player->priv->mmplayer)) | ||
1717 | 1711 | return TRUE; | ||
1718 | 1712 | |||
1719 | 1713 | if (player->priv->parser_cancellable != NULL) { | ||
1720 | 1714 | rb_debug ("currently parsing a playlist"); | ||
1721 | 1715 | return TRUE; | ||
1722 | 1716 | } | ||
1723 | 1717 | |||
1724 | 1718 | /* we're obviously not playing anything, so crossfading is irrelevant */ | ||
1725 | 1719 | if (!rb_player_play (player->priv->mmplayer, RB_PLAYER_PLAY_REPLACE, 0.0f, error)) { | ||
1726 | 1720 | rb_debug ("player doesn't want to"); | ||
1727 | 1721 | return FALSE; | ||
1728 | 1722 | } | ||
1729 | 1723 | |||
1730 | 1724 | songs = rb_source_get_entry_view (player->priv->current_playing_source); | ||
1731 | 1725 | if (songs) | ||
1732 | 1726 | rb_entry_view_set_state (songs, RB_ENTRY_VIEW_PLAYING); | ||
1733 | 1727 | |||
1734 | 1728 | return TRUE; | ||
1735 | 1729 | } | ||
1736 | 1730 | |||
1737 | 1731 | static void | ||
1738 | 1732 | rb_shell_player_set_entry_playback_error (RBShellPlayer *player, | ||
1739 | 1733 | RhythmDBEntry *entry, | ||
1740 | 1734 | char *message) | ||
1741 | 1735 | { | ||
1742 | 1736 | GValue value = { 0, }; | ||
1743 | 1737 | |||
1744 | 1738 | g_return_if_fail (RB_IS_SHELL_PLAYER (player)); | ||
1745 | 1739 | |||
1746 | 1740 | g_value_init (&value, G_TYPE_STRING); | ||
1747 | 1741 | g_value_set_string (&value, message); | ||
1748 | 1742 | rhythmdb_entry_set (player->priv->db, | ||
1749 | 1743 | entry, | ||
1750 | 1744 | RHYTHMDB_PROP_PLAYBACK_ERROR, | ||
1751 | 1745 | &value); | ||
1752 | 1746 | g_value_unset (&value); | ||
1753 | 1747 | rhythmdb_commit (player->priv->db); | ||
1754 | 1748 | } | ||
1755 | 1749 | |||
1756 | 1750 | static gboolean | ||
1757 | 1751 | rb_shell_player_set_playing_entry (RBShellPlayer *player, | ||
1758 | 1752 | RhythmDBEntry *entry, | ||
1759 | 1753 | gboolean out_of_order, | ||
1760 | 1754 | gboolean wait_for_eos, | ||
1761 | 1755 | GError **error) | ||
1762 | 1756 | { | ||
1763 | 1757 | GError *tmp_error = NULL; | ||
1764 | 1758 | GValue val = {0,}; | ||
1765 | 1759 | RBPlayerPlayType play_type; | ||
1766 | 1760 | |||
1767 | 1761 | g_return_val_if_fail (player->priv->current_playing_source != NULL, TRUE); | ||
1768 | 1762 | g_return_val_if_fail (entry != NULL, TRUE); | ||
1769 | 1763 | |||
1770 | 1764 | play_type = wait_for_eos ? RB_PLAYER_PLAY_AFTER_EOS : RB_PLAYER_PLAY_REPLACE; | ||
1771 | 1765 | |||
1772 | 1766 | if (out_of_order) { | ||
1773 | 1767 | RBPlayOrder *porder; | ||
1774 | 1768 | |||
1775 | 1769 | g_object_get (player->priv->current_playing_source, "play-order", &porder, NULL); | ||
1776 | 1770 | if (porder == NULL) | ||
1777 | 1771 | porder = g_object_ref (player->priv->play_order); | ||
1778 | 1772 | rb_play_order_set_playing_entry (porder, entry); | ||
1779 | 1773 | g_object_unref (porder); | ||
1780 | 1774 | } | ||
1781 | 1775 | |||
1782 | 1776 | if (player->priv->playing_entry != NULL && | ||
1783 | 1777 | player->priv->track_transition_time > 0) { | ||
1784 | 1778 | const char *previous_album; | ||
1785 | 1779 | const char *album; | ||
1786 | 1780 | |||
1787 | 1781 | previous_album = rhythmdb_entry_get_string (player->priv->playing_entry, RHYTHMDB_PROP_ALBUM); | ||
1788 | 1782 | album = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM); | ||
1789 | 1783 | /* only crossfade if we're not going from the end of one song on an | ||
1790 | 1784 | * album to the start of another. "Unknown" doesn't count as an album. | ||
1791 | 1785 | */ | ||
1792 | 1786 | if (wait_for_eos == FALSE || | ||
1793 | 1787 | strcmp (album, _("Unknown")) == 0 || | ||
1794 | 1788 | strcmp (album, previous_album) != 0) { | ||
1795 | 1789 | play_type = RB_PLAYER_PLAY_CROSSFADE; | ||
1796 | 1790 | } | ||
1797 | 1791 | } | ||
1798 | 1792 | |||
1799 | 1793 | if (rb_shell_player_open_location (player, entry, play_type, &tmp_error) == FALSE) { | ||
1800 | 1794 | goto lose; | ||
1801 | 1795 | } | ||
1802 | 1796 | |||
1803 | 1797 | rb_debug ("Success!"); | ||
1804 | 1798 | /* clear error on successful playback */ | ||
1805 | 1799 | g_value_init (&val, G_TYPE_STRING); | ||
1806 | 1800 | g_value_set_string (&val, NULL); | ||
1807 | 1801 | rhythmdb_entry_set (player->priv->db, entry, RHYTHMDB_PROP_PLAYBACK_ERROR, &val); | ||
1808 | 1802 | rhythmdb_commit (player->priv->db); | ||
1809 | 1803 | g_value_unset (&val); | ||
1810 | 1804 | |||
1811 | 1805 | return TRUE; | ||
1812 | 1806 | lose: | ||
1813 | 1807 | /* Ignore errors, shutdown the player */ | ||
1814 | 1808 | rb_player_close (player->priv->mmplayer, NULL /* XXX specify uri? */, NULL); | ||
1815 | 1809 | |||
1816 | 1810 | if (tmp_error == NULL) { | ||
1817 | 1811 | tmp_error = g_error_new (RB_SHELL_PLAYER_ERROR, | ||
1818 | 1812 | RB_SHELL_PLAYER_ERROR_NOT_PLAYING, | ||
1819 | 1813 | "Problem occurred without error being set. " | ||
1820 | 1814 | "This is a bug in Rhythmbox or GStreamer."); | ||
1821 | 1815 | } | ||
1822 | 1816 | /* Mark this song as failed */ | ||
1823 | 1817 | rb_shell_player_set_entry_playback_error (player, entry, tmp_error->message); | ||
1824 | 1818 | g_propagate_error (error, tmp_error); | ||
1825 | 1819 | |||
1826 | 1820 | rb_shell_player_sync_with_source (player); | ||
1827 | 1821 | rb_shell_player_sync_buttons (player); | ||
1828 | 1822 | g_object_notify (G_OBJECT (player), "playing"); | ||
1829 | 1823 | |||
1830 | 1824 | return FALSE; | ||
1831 | 1825 | } | ||
1832 | 1826 | |||
1833 | 1827 | static void | ||
1834 | 1828 | player_settings_changed_cb (GSettings *settings, const char *key, RBShellPlayer *player) | ||
1835 | 1829 | { | ||
1836 | 1830 | if (g_strcmp0 (key, "play-order") == 0) { | ||
1837 | 1831 | rb_debug ("play order setting changed"); | ||
1838 | 1832 | player->priv->syncing_state = TRUE; | ||
1839 | 1833 | rb_shell_player_sync_play_order (player); | ||
1840 | 1834 | rb_shell_player_sync_buttons (player); | ||
1841 | 1835 | rb_shell_player_sync_control_state (player); | ||
1842 | 1836 | g_object_notify (G_OBJECT (player), "play-order"); | ||
1843 | 1837 | player->priv->syncing_state = FALSE; | ||
1844 | 1838 | } else if (g_strcmp0 (key, "transition-time") == 0) { | ||
1845 | 1839 | double newtime; | ||
1846 | 1840 | rb_debug ("track transition time changed"); | ||
1847 | 1841 | newtime = g_settings_get_double (player->priv->settings, "transition-time"); | ||
1848 | 1842 | player->priv->track_transition_time = newtime * RB_PLAYER_SECOND; | ||
1849 | 1843 | } | ||
1850 | 1844 | } | ||
1851 | 1845 | |||
1852 | 1846 | /** | ||
1853 | 1847 | * rb_shell_player_get_playback_state: | ||
1854 | 1848 | * @player: the #RBShellPlayer | ||
1855 | 1849 | * @shuffle: (out): returns the current shuffle setting | ||
1856 | 1850 | * @repeat: (out): returns the current repeat setting | ||
1857 | 1851 | * | ||
1858 | 1852 | * Retrieves the current state of the shuffle and repeat settings. | ||
1859 | 1853 | * | ||
1860 | 1854 | * Return value: %TRUE if successful. | ||
1861 | 1855 | */ | ||
1862 | 1856 | gboolean | ||
1863 | 1857 | rb_shell_player_get_playback_state (RBShellPlayer *player, | ||
1864 | 1858 | gboolean *shuffle, | ||
1865 | 1859 | gboolean *repeat) | ||
1866 | 1860 | { | ||
1867 | 1861 | int i, j; | ||
1868 | 1862 | char *play_order; | ||
1869 | 1863 | |||
1870 | 1864 | play_order = g_settings_get_string (player->priv->settings, "play-order"); | ||
1871 | 1865 | for (i = 0; i < G_N_ELEMENTS(state_to_play_order); i++) | ||
1872 | 1866 | for (j = 0; j < G_N_ELEMENTS(state_to_play_order[0]); j++) | ||
1873 | 1867 | if (!strcmp (play_order, state_to_play_order[i][j])) | ||
1874 | 1868 | goto found; | ||
1875 | 1869 | |||
1876 | 1870 | g_free (play_order); | ||
1877 | 1871 | return FALSE; | ||
1878 | 1872 | |||
1879 | 1873 | found: | ||
1880 | 1874 | if (shuffle != NULL) { | ||
1881 | 1875 | *shuffle = i > 0; | ||
1882 | 1876 | } | ||
1883 | 1877 | if (repeat != NULL) { | ||
1884 | 1878 | *repeat = j > 0; | ||
1885 | 1879 | } | ||
1886 | 1880 | g_free (play_order); | ||
1887 | 1881 | return TRUE; | ||
1888 | 1882 | } | ||
1889 | 1883 | |||
1890 | 1884 | /** | ||
1891 | 1885 | * rb_shell_player_set_playback_state: | ||
1892 | 1886 | * @player: the #RBShellPlayer | ||
1893 | 1887 | * @shuffle: whether to enable the shuffle setting | ||
1894 | 1888 | * @repeat: whether to enable the repeat setting | ||
1895 | 1889 | * | ||
1896 | 1890 | * Sets the state of the shuffle and repeat settings. | ||
1897 | 1891 | */ | ||
1898 | 1892 | void | ||
1899 | 1893 | rb_shell_player_set_playback_state (RBShellPlayer *player, | ||
1900 | 1894 | gboolean shuffle, | ||
1901 | 1895 | gboolean repeat) | ||
1902 | 1896 | { | ||
1903 | 1897 | const char *neworder = state_to_play_order[shuffle ? 1 : 0][repeat ? 1 : 0]; | ||
1904 | 1898 | g_settings_set_string (player->priv->settings, "play-order", neworder); | ||
1905 | 1899 | } | ||
1906 | 1900 | |||
1907 | 1901 | static void | ||
1908 | 1902 | rb_shell_player_sync_play_order (RBShellPlayer *player) | ||
1909 | 1903 | { | ||
1910 | 1904 | char *new_play_order; | ||
1911 | 1905 | RhythmDBEntry *playing_entry = NULL; | ||
1912 | 1906 | RBSource *source; | ||
1913 | 1907 | |||
1914 | 1908 | new_play_order = g_settings_get_string (player->priv->settings, "play-order"); | ||
1915 | 1909 | if (player->priv->play_order != NULL) { | ||
1916 | 1910 | playing_entry = rb_play_order_get_playing_entry (player->priv->play_order); | ||
1917 | 1911 | g_signal_handlers_disconnect_by_func (player->priv->play_order, | ||
1918 | 1912 | G_CALLBACK (rb_shell_player_play_order_update_cb), | ||
1919 | 1913 | player); | ||
1920 | 1914 | g_object_unref (player->priv->play_order); | ||
1921 | 1915 | } | ||
1922 | 1916 | |||
1923 | 1917 | player->priv->play_order = rb_play_order_new (player, new_play_order); | ||
1924 | 1918 | |||
1925 | 1919 | g_signal_connect_object (player->priv->play_order, | ||
1926 | 1920 | "have_next_previous_changed", | ||
1927 | 1921 | G_CALLBACK (rb_shell_player_play_order_update_cb), | ||
1928 | 1922 | player, 0); | ||
1929 | 1923 | rb_shell_player_play_order_update_cb (player->priv->play_order, | ||
1930 | 1924 | FALSE, FALSE, | ||
1931 | 1925 | player); | ||
1932 | 1926 | |||
1933 | 1927 | source = player->priv->current_playing_source; | ||
1934 | 1928 | if (source == NULL) { | ||
1935 | 1929 | source = player->priv->selected_source; | ||
1936 | 1930 | } | ||
1937 | 1931 | rb_play_order_playing_source_changed (player->priv->play_order, source); | ||
1938 | 1932 | |||
1939 | 1933 | if (playing_entry != NULL) { | ||
1940 | 1934 | rb_play_order_set_playing_entry (player->priv->play_order, playing_entry); | ||
1941 | 1935 | rhythmdb_entry_unref (playing_entry); | ||
1942 | 1936 | } | ||
1943 | 1937 | |||
1944 | 1938 | g_free (new_play_order); | ||
1945 | 1939 | } | ||
1946 | 1940 | |||
1947 | 1941 | static void | ||
1948 | 1942 | rb_shell_player_play_order_update_cb (RBPlayOrder *porder, | ||
1949 | 1943 | gboolean _has_next, | ||
1950 | 1944 | gboolean _has_previous, | ||
1951 | 1945 | RBShellPlayer *player) | ||
1952 | 1946 | { | ||
1953 | 1947 | /* we cannot depend on the values of has_next, has_previous or porder | ||
1954 | 1948 | * since this can be called for the main porder, queue porder, etc | ||
1955 | 1949 | */ | ||
1956 | 1950 | gboolean has_next = FALSE; | ||
1957 | 1951 | gboolean has_prev = FALSE; | ||
1958 | 1952 | RhythmDBEntry *entry; | ||
1959 | 1953 | |||
1960 | 1954 | entry = rb_shell_player_get_playing_entry (player); | ||
1961 | 1955 | if (entry != NULL) { | ||
1962 | 1956 | has_next = TRUE; | ||
1963 | 1957 | has_prev = TRUE; | ||
1964 | 1958 | rhythmdb_entry_unref (entry); | ||
1965 | 1959 | } else { | ||
1966 | 1960 | if (player->priv->current_playing_source && | ||
1967 | 1961 | (rb_source_handle_eos (player->priv->current_playing_source) == RB_SOURCE_EOF_NEXT)) { | ||
1968 | 1962 | RBPlayOrder *porder; | ||
1969 | 1963 | g_object_get (player->priv->current_playing_source, "play-order", &porder, NULL); | ||
1970 | 1964 | if (porder == NULL) | ||
1971 | 1965 | porder = g_object_ref (player->priv->play_order); | ||
1972 | 1966 | has_next = rb_play_order_has_next (porder); | ||
1973 | 1967 | g_object_unref (porder); | ||
1974 | 1968 | } | ||
1975 | 1969 | if (player->priv->queue_play_order) { | ||
1976 | 1970 | has_next |= rb_play_order_has_next (player->priv->queue_play_order); | ||
1977 | 1971 | } | ||
1978 | 1972 | has_prev = (player->priv->current_playing_source != NULL); | ||
1979 | 1973 | } | ||
1980 | 1974 | |||
1981 | 1975 | if (has_prev != player->priv->has_prev) { | ||
1982 | 1976 | player->priv->has_prev = has_prev; | ||
1983 | 1977 | g_object_notify (G_OBJECT (player), "has-prev"); | ||
1984 | 1978 | } | ||
1985 | 1979 | if (has_next != player->priv->has_next) { | ||
1986 | 1980 | player->priv->has_next = has_next; | ||
1987 | 1981 | g_object_notify (G_OBJECT (player), "has-next"); | ||
1988 | 1982 | } | ||
1989 | 1983 | } | ||
1990 | 1984 | |||
1991 | 1985 | /** | ||
1992 | 1986 | * rb_shell_player_jump_to_current: | ||
1993 | 1987 | * @player: the #RBShellPlayer | ||
1994 | 1988 | * | ||
1995 | 1989 | * Scrolls the #RBEntryView for the current playing source so that | ||
1996 | 1990 | * the current playing entry is visible and selects the row for the | ||
1997 | 1991 | * entry. If there is no current playing entry, the selection is | ||
1998 | 1992 | * cleared instead. | ||
1999 | 1993 | */ | ||
2000 | 1994 | void | ||
2001 | 1995 | rb_shell_player_jump_to_current (RBShellPlayer *player) | ||
2002 | 1996 | { | ||
2003 | 1997 | RBSource *source; | ||
2004 | 1998 | RhythmDBEntry *entry; | ||
2005 | 1999 | RBEntryView *songs; | ||
2006 | 2000 | |||
2007 | 2001 | source = player->priv->current_playing_source ? player->priv->current_playing_source : | ||
2008 | 2002 | player->priv->selected_source; | ||
2009 | 2003 | |||
2010 | 2004 | songs = rb_source_get_entry_view (source); | ||
2011 | 2005 | entry = rb_shell_player_get_playing_entry (player); | ||
2012 | 2006 | if (songs != NULL) { | ||
2013 | 2007 | if (entry != NULL) { | ||
2014 | 2008 | rb_entry_view_scroll_to_entry (songs, entry); | ||
2015 | 2009 | rb_entry_view_select_entry (songs, entry); | ||
2016 | 2010 | } else { | ||
2017 | 2011 | rb_entry_view_select_none (songs); | ||
2018 | 2012 | } | ||
2019 | 2013 | } | ||
2020 | 2014 | |||
2021 | 2015 | if (entry != NULL) { | ||
2022 | 2016 | rhythmdb_entry_unref (entry); | ||
2023 | 2017 | } | ||
2024 | 2018 | } | ||
2025 | 2019 | |||
2026 | 2020 | static void | ||
2027 | 2021 | swap_playing_source (RBShellPlayer *player, | ||
2028 | 2022 | RBSource *new_source) | ||
2029 | 2023 | { | ||
2030 | 2024 | if (player->priv->current_playing_source != NULL) { | ||
2031 | 2025 | RBEntryView *old_songs = rb_source_get_entry_view (player->priv->current_playing_source); | ||
2032 | 2026 | if (old_songs) | ||
2033 | 2027 | rb_entry_view_set_state (old_songs, RB_ENTRY_VIEW_NOT_PLAYING); | ||
2034 | 2028 | } | ||
2035 | 2029 | if (new_source != NULL) { | ||
2036 | 2030 | RBEntryView *new_songs = rb_source_get_entry_view (new_source); | ||
2037 | 2031 | |||
2038 | 2032 | if (new_songs) { | ||
2039 | 2033 | rb_entry_view_set_state (new_songs, RB_ENTRY_VIEW_PLAYING); | ||
2040 | 2034 | rb_shell_player_set_playing_source (player, new_source); | ||
2041 | 2035 | } | ||
2042 | 2036 | } | ||
2043 | 2037 | } | ||
2044 | 2038 | |||
2045 | 2039 | /** | ||
2046 | 2040 | * rb_shell_player_do_previous: | ||
2047 | 2041 | * @player: the #RBShellPlayer | ||
2048 | 2042 | * @error: returns any error information | ||
2049 | 2043 | * | ||
2050 | 2044 | * If the current song has been playing for more than 3 seconds, | ||
2051 | 2045 | * restarts it, otherwise, goes back to the previous song. | ||
2052 | 2046 | * Fails if there is no current song, or if inside the first | ||
2053 | 2047 | * 3 seconds of the first song in the play order. | ||
2054 | 2048 | * | ||
2055 | 2049 | * Return value: %TRUE if successful | ||
2056 | 2050 | */ | ||
2057 | 2051 | gboolean | ||
2058 | 2052 | rb_shell_player_do_previous (RBShellPlayer *player, | ||
2059 | 2053 | GError **error) | ||
2060 | 2054 | { | ||
2061 | 2055 | RhythmDBEntry *entry = NULL; | ||
2062 | 2056 | RBSource *new_source; | ||
2063 | 2057 | |||
2064 | 2058 | if (player->priv->current_playing_source == NULL) { | ||
2065 | 2059 | g_set_error (error, | ||
2066 | 2060 | RB_SHELL_PLAYER_ERROR, | ||
2067 | 2061 | RB_SHELL_PLAYER_ERROR_NOT_PLAYING, | ||
2068 | 2062 | _("Not currently playing")); | ||
2069 | 2063 | return FALSE; | ||
2070 | 2064 | } | ||
2071 | 2065 | |||
2072 | 2066 | /* If we're in the first 3 seconds go to the previous song, | ||
2073 | 2067 | * else restart the current one. | ||
2074 | 2068 | */ | ||
2075 | 2069 | if (player->priv->current_playing_source != NULL | ||
2076 | 2070 | && rb_source_can_pause (player->priv->source) | ||
2077 | 2071 | && rb_player_get_time (player->priv->mmplayer) > (G_GINT64_CONSTANT (3) * RB_PLAYER_SECOND)) { | ||
2078 | 2072 | rb_debug ("after 3 second previous, restarting song"); | ||
2079 | 2073 | rb_player_set_time (player->priv->mmplayer, 0); | ||
2080 | 2074 | rb_shell_player_sync_with_source (player); | ||
2081 | 2075 | return TRUE; | ||
2082 | 2076 | } | ||
2083 | 2077 | |||
2084 | 2078 | rb_debug ("going to previous"); | ||
2085 | 2079 | |||
2086 | 2080 | /* hrm, does this actually do anything at all? */ | ||
2087 | 2081 | if (player->priv->queue_play_order) { | ||
2088 | 2082 | entry = rb_play_order_get_previous (player->priv->queue_play_order); | ||
2089 | 2083 | if (entry != NULL) { | ||
2090 | 2084 | new_source = RB_SOURCE (player->priv->queue_source); | ||
2091 | 2085 | rb_play_order_go_previous (player->priv->queue_play_order); | ||
2092 | 2086 | } | ||
2093 | 2087 | } | ||
2094 | 2088 | |||
2095 | 2089 | if (entry == NULL) { | ||
2096 | 2090 | RBPlayOrder *porder; | ||
2097 | 2091 | |||
2098 | 2092 | new_source = player->priv->source; | ||
2099 | 2093 | g_object_get (new_source, "play-order", &porder, NULL); | ||
2100 | 2094 | if (porder == NULL) | ||
2101 | 2095 | porder = g_object_ref (player->priv->play_order); | ||
2102 | 2096 | |||
2103 | 2097 | entry = rb_play_order_get_previous (porder); | ||
2104 | 2098 | if (entry) | ||
2105 | 2099 | rb_play_order_go_previous (porder); | ||
2106 | 2100 | g_object_unref (porder); | ||
2107 | 2101 | } | ||
2108 | 2102 | |||
2109 | 2103 | if (entry != NULL) { | ||
2110 | 2104 | rb_debug ("previous song found, doing previous"); | ||
2111 | 2105 | if (new_source != player->priv->current_playing_source) | ||
2112 | 2106 | swap_playing_source (player, new_source); | ||
2113 | 2107 | |||
2114 | 2108 | player->priv->jump_to_playing_entry = TRUE; | ||
2115 | 2109 | if (!rb_shell_player_set_playing_entry (player, entry, FALSE, FALSE, error)) { | ||
2116 | 2110 | rhythmdb_entry_unref (entry); | ||
2117 | 2111 | return FALSE; | ||
2118 | 2112 | } | ||
2119 | 2113 | |||
2120 | 2114 | rhythmdb_entry_unref (entry); | ||
2121 | 2115 | } else { | ||
2122 | 2116 | rb_debug ("no previous song found, signalling error"); | ||
2123 | 2117 | g_set_error (error, | ||
2124 | 2118 | RB_SHELL_PLAYER_ERROR, | ||
2125 | 2119 | RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST, | ||
2126 | 2120 | _("No previous song")); | ||
2127 | 2121 | rb_shell_player_stop (player); | ||
2128 | 2122 | return FALSE; | ||
2129 | 2123 | } | ||
2130 | 2124 | |||
2131 | 2125 | return TRUE; | ||
2132 | 2126 | } | ||
2133 | 2127 | |||
2134 | 2128 | static gboolean | ||
2135 | 2129 | rb_shell_player_do_next_internal (RBShellPlayer *player, gboolean from_eos, gboolean allow_stop, GError **error) | ||
2136 | 2130 | { | ||
2137 | 2131 | RBSource *new_source = NULL; | ||
2138 | 2132 | RhythmDBEntry *entry = NULL; | ||
2139 | 2133 | gboolean rv = TRUE; | ||
2140 | 2134 | |||
2141 | 2135 | if (player->priv->source == NULL) | ||
2142 | 2136 | return TRUE; | ||
2143 | 2137 | |||
2144 | 2138 | |||
2145 | 2139 | /* try the current playing source's play order, if it has one */ | ||
2146 | 2140 | if (player->priv->current_playing_source != NULL) { | ||
2147 | 2141 | RBPlayOrder *porder; | ||
2148 | 2142 | g_object_get (player->priv->current_playing_source, "play-order", &porder, NULL); | ||
2149 | 2143 | if (porder != NULL) { | ||
2150 | 2144 | entry = rb_play_order_get_next (porder); | ||
2151 | 2145 | if (entry != NULL) { | ||
2152 | 2146 | rb_play_order_go_next (porder); | ||
2153 | 2147 | new_source = player->priv->current_playing_source; | ||
2154 | 2148 | } | ||
2155 | 2149 | g_object_unref (porder); | ||
2156 | 2150 | } | ||
2157 | 2151 | } | ||
2158 | 2152 | |||
2159 | 2153 | /* if that's different to the playing source that the user selected | ||
2160 | 2154 | * (ie we're playing from the queue), try that too | ||
2161 | 2155 | */ | ||
2162 | 2156 | if (entry == NULL) { | ||
2163 | 2157 | RBPlayOrder *porder; | ||
2164 | 2158 | g_object_get (player->priv->source, "play-order", &porder, NULL); | ||
2165 | 2159 | if (porder == NULL) | ||
2166 | 2160 | porder = g_object_ref (player->priv->play_order); | ||
2167 | 2161 | |||
2168 | 2162 | /* | ||
2169 | 2163 | * If we interrupted this source to play from something else, | ||
2170 | 2164 | * we should go back to whatever it wanted to play before. | ||
2171 | 2165 | */ | ||
2172 | 2166 | if (player->priv->source != player->priv->current_playing_source) | ||
2173 | 2167 | entry = rb_play_order_get_playing_entry (porder); | ||
2174 | 2168 | |||
2175 | 2169 | /* if that didn't help, advance the play order */ | ||
2176 | 2170 | if (entry == NULL) { | ||
2177 | 2171 | entry = rb_play_order_get_next (porder); | ||
2178 | 2172 | if (entry != NULL) { | ||
2179 | 2173 | rb_debug ("got new entry %s from play order", | ||
2180 | 2174 | rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION)); | ||
2181 | 2175 | rb_play_order_go_next (porder); | ||
2182 | 2176 | } | ||
2183 | 2177 | } | ||
2184 | 2178 | |||
2185 | 2179 | if (entry != NULL) | ||
2186 | 2180 | new_source = player->priv->source; | ||
2187 | 2181 | |||
2188 | 2182 | g_object_unref (porder); | ||
2189 | 2183 | } | ||
2190 | 2184 | |||
2191 | 2185 | /* if the new entry isn't from the play queue anyway, let the play queue | ||
2192 | 2186 | * override the regular play order. | ||
2193 | 2187 | */ | ||
2194 | 2188 | if (player->priv->queue_play_order && | ||
2195 | 2189 | new_source != RB_SOURCE (player->priv->queue_source)) { | ||
2196 | 2190 | RhythmDBEntry *queue_entry; | ||
2197 | 2191 | |||
2198 | 2192 | queue_entry = rb_play_order_get_next (player->priv->queue_play_order); | ||
2199 | 2193 | rb_play_order_go_next (player->priv->queue_play_order); | ||
2200 | 2194 | if (queue_entry != NULL) { | ||
2201 | 2195 | rb_debug ("got new entry %s from queue play order", | ||
2202 | 2196 | rhythmdb_entry_get_string (queue_entry, RHYTHMDB_PROP_LOCATION)); | ||
2203 | 2197 | if (entry != NULL) { | ||
2204 | 2198 | rhythmdb_entry_unref (entry); | ||
2205 | 2199 | } | ||
2206 | 2200 | entry = queue_entry; | ||
2207 | 2201 | new_source = RB_SOURCE (player->priv->queue_source); | ||
2208 | 2202 | } else { | ||
2209 | 2203 | rb_debug ("didn't get a new entry from queue play order"); | ||
2210 | 2204 | } | ||
2211 | 2205 | } | ||
2212 | 2206 | |||
2213 | 2207 | /* play the new entry */ | ||
2214 | 2208 | if (entry != NULL) { | ||
2215 | 2209 | /* if the entry view containing the playing entry changed, update it */ | ||
2216 | 2210 | if (new_source != player->priv->current_playing_source) | ||
2217 | 2211 | swap_playing_source (player, new_source); | ||
2218 | 2212 | |||
2219 | 2213 | player->priv->jump_to_playing_entry = TRUE; | ||
2220 | 2214 | if (!rb_shell_player_set_playing_entry (player, entry, FALSE, from_eos, error)) | ||
2221 | 2215 | rv = FALSE; | ||
2222 | 2216 | } else { | ||
2223 | 2217 | g_set_error (error, | ||
2224 | 2218 | RB_SHELL_PLAYER_ERROR, | ||
2225 | 2219 | RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST, | ||
2226 | 2220 | _("No next song")); | ||
2227 | 2221 | rv = FALSE; | ||
2228 | 2222 | |||
2229 | 2223 | if (allow_stop) { | ||
2230 | 2224 | rb_debug ("No next entry, stopping playback"); | ||
2231 | 2225 | |||
2232 | 2226 | /* hmm, need to set playing entry on the playing source's | ||
2233 | 2227 | * play order if it has one? | ||
2234 | 2228 | */ | ||
2235 | 2229 | |||
2236 | 2230 | rb_shell_player_stop (player); | ||
2237 | 2231 | rb_play_order_set_playing_entry (player->priv->play_order, NULL); | ||
2238 | 2232 | } | ||
2239 | 2233 | } | ||
2240 | 2234 | |||
2241 | 2235 | if (entry != NULL) { | ||
2242 | 2236 | rhythmdb_entry_unref (entry); | ||
2243 | 2237 | } | ||
2244 | 2238 | |||
2245 | 2239 | return rv; | ||
2246 | 2240 | } | ||
2247 | 2241 | |||
2248 | 2242 | /** | ||
2249 | 2243 | * rb_shell_player_do_next: | ||
2250 | 2244 | * @player: the #RBShellPlayer | ||
2251 | 2245 | * @error: returns error information | ||
2252 | 2246 | * | ||
2253 | 2247 | * Skips to the next song. Consults the play queue and handles | ||
2254 | 2248 | * transitions between the play queue and the active source. | ||
2255 | 2249 | * Fails if there is no entry to play after the current one. | ||
2256 | 2250 | * | ||
2257 | 2251 | * Return value: %TRUE if successful | ||
2258 | 2252 | */ | ||
2259 | 2253 | gboolean | ||
2260 | 2254 | rb_shell_player_do_next (RBShellPlayer *player, | ||
2261 | 2255 | GError **error) | ||
2262 | 2256 | { | ||
2263 | 2257 | return rb_shell_player_do_next_internal (player, FALSE, TRUE, error); | ||
2264 | 2258 | } | ||
2265 | 2259 | |||
2266 | 2260 | static void | ||
2267 | 2261 | rb_shell_player_cmd_previous (GtkAction *action, | ||
2268 | 2262 | RBShellPlayer *player) | ||
2269 | 2263 | { | ||
2270 | 2264 | GError *error = NULL; | ||
2271 | 2265 | |||
2272 | 2266 | if (!rb_shell_player_do_previous (player, &error)) { | ||
2273 | 2267 | if (error->domain != RB_SHELL_PLAYER_ERROR || | ||
2274 | 2268 | error->code != RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST) { | ||
2275 | 2269 | g_warning ("cmd_previous: Unhandled error: %s", error->message); | ||
2276 | 2270 | } else if (error->code == RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST) { | ||
2277 | 2271 | rb_shell_player_stop (player); | ||
2278 | 2272 | } | ||
2279 | 2273 | } | ||
2280 | 2274 | } | ||
2281 | 2275 | |||
2282 | 2276 | static void | ||
2283 | 2277 | rb_shell_player_cmd_next (GtkAction *action, | ||
2284 | 2278 | RBShellPlayer *player) | ||
2285 | 2279 | { | ||
2286 | 2280 | GError *error = NULL; | ||
2287 | 2281 | |||
2288 | 2282 | if (!rb_shell_player_do_next (player, &error)) { | ||
2289 | 2283 | if (error->domain != RB_SHELL_PLAYER_ERROR || | ||
2290 | 2284 | error->code != RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST) { | ||
2291 | 2285 | g_warning ("cmd_next: Unhandled error: %s", error->message); | ||
2292 | 2286 | } else if (error->code == RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST) { | ||
2293 | 2287 | rb_shell_player_stop (player); | ||
2294 | 2288 | } | ||
2295 | 2289 | } | ||
2296 | 2290 | } | ||
2297 | 2291 | |||
2298 | 2292 | /** | ||
2299 | 2293 | * rb_shell_player_play_entry: | ||
2300 | 2294 | * @player: the #RBShellPlayer | ||
2301 | 2295 | * @entry: the #RhythmDBEntry to play | ||
2302 | 2296 | * @source: the new #RBSource to set as playing (or NULL to use the | ||
2303 | 2297 | * selected source) | ||
2304 | 2298 | * | ||
2305 | 2299 | * Plays a specified entry. | ||
2306 | 2300 | */ | ||
2307 | 2301 | void | ||
2308 | 2302 | rb_shell_player_play_entry (RBShellPlayer *player, | ||
2309 | 2303 | RhythmDBEntry *entry, | ||
2310 | 2304 | RBSource *source) | ||
2311 | 2305 | { | ||
2312 | 2306 | GError *error = NULL; | ||
2313 | 2307 | |||
2314 | 2308 | if (source == NULL) | ||
2315 | 2309 | source = player->priv->selected_source; | ||
2316 | 2310 | rb_shell_player_set_playing_source (player, source); | ||
2317 | 2311 | |||
2318 | 2312 | player->priv->jump_to_playing_entry = FALSE; | ||
2319 | 2313 | if (!rb_shell_player_set_playing_entry (player, entry, TRUE, FALSE, &error)) { | ||
2320 | 2314 | rb_shell_player_error (player, FALSE, error); | ||
2321 | 2315 | g_clear_error (&error); | ||
2322 | 2316 | } | ||
2323 | 2317 | } | ||
2324 | 2318 | |||
2325 | 2319 | static void | ||
2326 | 2320 | rb_shell_player_cmd_volume_up (GtkAction *action, | ||
2327 | 2321 | RBShellPlayer *player) | ||
2328 | 2322 | { | ||
2329 | 2323 | rb_shell_player_set_volume_relative (player, 0.1, NULL); | ||
2330 | 2324 | } | ||
2331 | 2325 | |||
2332 | 2326 | static void | ||
2333 | 2327 | rb_shell_player_cmd_volume_down (GtkAction *action, | ||
2334 | 2328 | RBShellPlayer *player) | ||
2335 | 2329 | { | ||
2336 | 2330 | rb_shell_player_set_volume_relative (player, -0.1, NULL); | ||
2337 | 2331 | } | ||
2338 | 2332 | |||
2339 | 2333 | static void | ||
2340 | 2334 | rb_shell_player_cmd_play (GtkAction *action, | ||
2341 | 2335 | RBShellPlayer *player) | ||
2342 | 2336 | { | ||
2343 | 2337 | GError *error = NULL; | ||
2344 | 2338 | rb_debug ("play!"); | ||
2345 | 2339 | if (!rb_shell_player_playpause (player, FALSE, &error)) | ||
2346 | 2340 | rb_error_dialog (NULL, | ||
2347 | 2341 | _("Couldn't start playback"), | ||
2348 | 2342 | "%s", (error) ? error->message : "(null)"); | ||
2349 | 2343 | g_clear_error (&error); | ||
2350 | 2344 | } | ||
2351 | 2345 | |||
2352 | 2346 | /* unused parameter can't be removed without breaking dbus interface compatibility */ | ||
2353 | 2347 | /** | ||
2354 | 2348 | * rb_shell_player_playpause: | ||
2355 | 2349 | * @player: the #RBShellPlayer | ||
2356 | 2350 | * @unused: nothing | ||
2357 | 2351 | * @error: returns error information | ||
2358 | 2352 | * | ||
2359 | 2353 | * Toggles between playing and paused state. If there is no playing | ||
2360 | 2354 | * entry, chooses an entry from (in order of preference) the play queue, | ||
2361 | 2355 | * the selection in the current source, or the play order. | ||
2362 | 2356 | * | ||
2363 | 2357 | * Return value: %TRUE if successful | ||
2364 | 2358 | */ | ||
2365 | 2359 | gboolean | ||
2366 | 2360 | rb_shell_player_playpause (RBShellPlayer *player, | ||
2367 | 2361 | gboolean unused, | ||
2368 | 2362 | GError **error) | ||
2369 | 2363 | { | ||
2370 | 2364 | gboolean ret; | ||
2371 | 2365 | RBEntryView *songs; | ||
2372 | 2366 | |||
2373 | 2367 | rb_debug ("doing playpause"); | ||
2374 | 2368 | |||
2375 | 2369 | g_return_val_if_fail (RB_IS_SHELL_PLAYER (player), TRUE); | ||
2376 | 2370 | |||
2377 | 2371 | ret = TRUE; | ||
2378 | 2372 | |||
2379 | 2373 | if (rb_player_playing (player->priv->mmplayer)) { | ||
2380 | 2374 | if (player->priv->source == NULL) { | ||
2381 | 2375 | rb_debug ("playing source is already NULL"); | ||
2382 | 2376 | } else if (rb_source_can_pause (player->priv->source)) { | ||
2383 | 2377 | rb_debug ("pausing mm player"); | ||
2384 | 2378 | rb_player_pause (player->priv->mmplayer); | ||
2385 | 2379 | songs = rb_source_get_entry_view (player->priv->current_playing_source); | ||
2386 | 2380 | if (songs) | ||
2387 | 2381 | rb_entry_view_set_state (songs, RB_ENTRY_VIEW_PAUSED); | ||
2388 | 2382 | |||
2389 | 2383 | /* might need a signal for when the player has actually paused here? */ | ||
2390 | 2384 | g_object_notify (G_OBJECT (player), "playing"); | ||
2391 | 2385 | /* mostly for that */ | ||
2392 | 2386 | } else { | ||
2393 | 2387 | rb_debug ("stopping playback"); | ||
2394 | 2388 | rb_shell_player_stop (player); | ||
2395 | 2389 | } | ||
2396 | 2390 | } else { | ||
2397 | 2391 | RhythmDBEntry *entry; | ||
2398 | 2392 | RBSource *new_source; | ||
2399 | 2393 | gboolean out_of_order = FALSE; | ||
2400 | 2394 | |||
2401 | 2395 | if (player->priv->source == NULL) { | ||
2402 | 2396 | /* no current stream, pull one in from the currently | ||
2403 | 2397 | * selected source */ | ||
2404 | 2398 | rb_debug ("no playing source, using selected source"); | ||
2405 | 2399 | rb_shell_player_set_playing_source (player, player->priv->selected_source); | ||
2406 | 2400 | } | ||
2407 | 2401 | new_source = player->priv->current_playing_source; | ||
2408 | 2402 | |||
2409 | 2403 | entry = rb_shell_player_get_playing_entry (player); | ||
2410 | 2404 | if (entry == NULL) { | ||
2411 | 2405 | /* queue takes precedence over selection */ | ||
2412 | 2406 | if (player->priv->queue_play_order) { | ||
2413 | 2407 | entry = rb_play_order_get_next (player->priv->queue_play_order); | ||
2414 | 2408 | if (entry != NULL) { | ||
2415 | 2409 | new_source = RB_SOURCE (player->priv->queue_source); | ||
2416 | 2410 | rb_play_order_go_next (player->priv->queue_play_order); | ||
2417 | 2411 | } | ||
2418 | 2412 | } | ||
2419 | 2413 | |||
2420 | 2414 | /* selection takes precedence over first item in play order */ | ||
2421 | 2415 | if (entry == NULL) { | ||
2422 | 2416 | GList *selection = NULL; | ||
2423 | 2417 | |||
2424 | 2418 | songs = rb_source_get_entry_view (player->priv->source); | ||
2425 | 2419 | if (songs) | ||
2426 | 2420 | selection = rb_entry_view_get_selected_entries (songs); | ||
2427 | 2421 | |||
2428 | 2422 | if (selection != NULL) { | ||
2429 | 2423 | rb_debug ("choosing first selected entry"); | ||
2430 | 2424 | entry = (RhythmDBEntry*) selection->data; | ||
2431 | 2425 | if (entry) | ||
2432 | 2426 | out_of_order = TRUE; | ||
2433 | 2427 | |||
2434 | 2428 | g_list_free (selection); | ||
2435 | 2429 | } | ||
2436 | 2430 | } | ||
2437 | 2431 | |||
2438 | 2432 | /* play order is last */ | ||
2439 | 2433 | if (entry == NULL) { | ||
2440 | 2434 | RBPlayOrder *porder; | ||
2441 | 2435 | |||
2442 | 2436 | rb_debug ("getting entry from play order"); | ||
2443 | 2437 | g_object_get (player->priv->source, "play-order", &porder, NULL); | ||
2444 | 2438 | if (porder == NULL) | ||
2445 | 2439 | porder = g_object_ref (player->priv->play_order); | ||
2446 | 2440 | |||
2447 | 2441 | entry = rb_play_order_get_next (porder); | ||
2448 | 2442 | if (entry != NULL) | ||
2449 | 2443 | rb_play_order_go_next (porder); | ||
2450 | 2444 | g_object_unref (porder); | ||
2451 | 2445 | } | ||
2452 | 2446 | |||
2453 | 2447 | if (entry != NULL) { | ||
2454 | 2448 | /* if the entry view containing the playing entry changed, update it */ | ||
2455 | 2449 | if (new_source != player->priv->current_playing_source) | ||
2456 | 2450 | swap_playing_source (player, new_source); | ||
2457 | 2451 | |||
2458 | 2452 | player->priv->jump_to_playing_entry = TRUE; | ||
2459 | 2453 | if (!rb_shell_player_set_playing_entry (player, entry, out_of_order, FALSE, error)) | ||
2460 | 2454 | ret = FALSE; | ||
2461 | 2455 | } | ||
2462 | 2456 | } else { | ||
2463 | 2457 | if (!rb_shell_player_play (player, error)) { | ||
2464 | 2458 | rb_shell_player_stop (player); | ||
2465 | 2459 | ret = FALSE; | ||
2466 | 2460 | } | ||
2467 | 2461 | } | ||
2468 | 2462 | |||
2469 | 2463 | if (entry != NULL) { | ||
2470 | 2464 | rhythmdb_entry_unref (entry); | ||
2471 | 2465 | } | ||
2472 | 2466 | } | ||
2473 | 2467 | |||
2474 | 2468 | rb_shell_player_sync_with_source (player); | ||
2475 | 2469 | rb_shell_player_sync_buttons (player); | ||
2476 | 2470 | |||
2477 | 2471 | return ret; | ||
2478 | 2472 | } | ||
2479 | 2473 | |||
2480 | 2474 | static void | ||
2481 | 2475 | rb_shell_player_sync_control_state (RBShellPlayer *player) | ||
2482 | 2476 | { | ||
2483 | 2477 | gboolean shuffle, repeat; | ||
2484 | 2478 | GtkAction *action; | ||
2485 | 2479 | rb_debug ("syncing control state"); | ||
2486 | 2480 | |||
2487 | 2481 | if (!rb_shell_player_get_playback_state (player, &shuffle, | ||
2488 | 2482 | &repeat)) | ||
2489 | 2483 | return; | ||
2490 | 2484 | |||
2491 | 2485 | action = gtk_action_group_get_action (player->priv->actiongroup, | ||
2492 | 2486 | "ControlShuffle"); | ||
2493 | 2487 | gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), shuffle); | ||
2494 | 2488 | action = gtk_action_group_get_action (player->priv->actiongroup, | ||
2495 | 2489 | "ControlRepeat"); | ||
2496 | 2490 | gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), repeat); | ||
2497 | 2491 | } | ||
2498 | 2492 | |||
2499 | 2493 | static void | ||
2500 | 2494 | sync_volume_cb (GSettings *settings, RBShellPlayer *player) | ||
2501 | 2495 | { | ||
2502 | 2496 | g_settings_set_double (player->priv->settings, "volume", player->priv->volume); | ||
2503 | 2497 | } | ||
2504 | 2498 | |||
2505 | 2499 | static void | ||
2506 | 2500 | rb_shell_player_sync_volume (RBShellPlayer *player, | ||
2507 | 2501 | gboolean notify, | ||
2508 | 2502 | gboolean set_volume) | ||
2509 | 2503 | { | ||
2510 | 2504 | GtkAction *action; | ||
2511 | 2505 | RhythmDBEntry *entry; | ||
2512 | 2506 | |||
2513 | 2507 | if (player->priv->volume <= 0.0){ | ||
2514 | 2508 | player->priv->volume = 0.0; | ||
2515 | 2509 | } else if (player->priv->volume >= 1.0){ | ||
2516 | 2510 | player->priv->volume = 1.0; | ||
2517 | 2511 | } | ||
2518 | 2512 | |||
2519 | 2513 | action = gtk_action_group_get_action (player->priv->actiongroup, | ||
2520 | 2514 | "ControlVolumeUp"); | ||
2521 | 2515 | g_object_set (G_OBJECT (action), "sensitive", player->priv->volume < 0.9999, NULL); | ||
2522 | 2516 | |||
2523 | 2517 | action = gtk_action_group_get_action (player->priv->actiongroup, | ||
2524 | 2518 | "ControlVolumeDown"); | ||
2525 | 2519 | g_object_set (G_OBJECT (action), "sensitive", player->priv->volume > 0.0001, NULL); | ||
2526 | 2520 | |||
2527 | 2521 | if (set_volume) { | ||
2528 | 2522 | rb_player_set_volume (player->priv->mmplayer, | ||
2529 | 2523 | player->priv->mute ? 0.0 : player->priv->volume); | ||
2530 | 2524 | } | ||
2531 | 2525 | |||
2532 | 2526 | if (player->priv->syncing_state == FALSE) { | ||
2533 | 2527 | rb_settings_delayed_sync (player->priv->settings, | ||
2534 | 2528 | (RBDelayedSyncFunc) sync_volume_cb, | ||
2535 | 2529 | g_object_ref (player), | ||
2536 | 2530 | g_object_unref); | ||
2537 | 2531 | } | ||
2538 | 2532 | |||
2539 | 2533 | entry = rb_shell_player_get_playing_entry (player); | ||
2540 | 2534 | if (entry != NULL) { | ||
2541 | 2535 | rhythmdb_entry_unref (entry); | ||
2542 | 2536 | } | ||
2543 | 2537 | |||
2544 | 2538 | if (notify) | ||
2545 | 2539 | g_object_notify (G_OBJECT (player), "volume"); | ||
2546 | 2540 | } | ||
2547 | 2541 | |||
2548 | 2542 | /** | ||
2549 | 2543 | * rb_shell_player_set_volume: | ||
2550 | 2544 | * @player: the #RBShellPlayer | ||
2551 | 2545 | * @volume: the volume level (between 0 and 1) | ||
2552 | 2546 | * @error: returns the error information | ||
2553 | 2547 | * | ||
2554 | 2548 | * Sets the playback volume level. | ||
2555 | 2549 | * | ||
2556 | 2550 | * Return value: %TRUE on success | ||
2557 | 2551 | */ | ||
2558 | 2552 | gboolean | ||
2559 | 2553 | rb_shell_player_set_volume (RBShellPlayer *player, | ||
2560 | 2554 | gdouble volume, | ||
2561 | 2555 | GError **error) | ||
2562 | 2556 | { | ||
2563 | 2557 | player->priv->volume = volume; | ||
2564 | 2558 | rb_shell_player_sync_volume (player, TRUE, TRUE); | ||
2565 | 2559 | return TRUE; | ||
2566 | 2560 | } | ||
2567 | 2561 | |||
2568 | 2562 | /** | ||
2569 | 2563 | * rb_shell_player_set_volume_relative: | ||
2570 | 2564 | * @player: the #RBShellPlayer | ||
2571 | 2565 | * @delta: difference to apply to the volume level (between -1 and 1) | ||
2572 | 2566 | * @error: returns error information | ||
2573 | 2567 | * | ||
2574 | 2568 | * Adds the specified value to the current volume level. | ||
2575 | 2569 | * | ||
2576 | 2570 | * Return value: %TRUE on success | ||
2577 | 2571 | */ | ||
2578 | 2572 | gboolean | ||
2579 | 2573 | rb_shell_player_set_volume_relative (RBShellPlayer *player, | ||
2580 | 2574 | gdouble delta, | ||
2581 | 2575 | GError **error) | ||
2582 | 2576 | { | ||
2583 | 2577 | /* rb_shell_player_sync_volume does clipping */ | ||
2584 | 2578 | player->priv->volume += delta; | ||
2585 | 2579 | rb_shell_player_sync_volume (player, TRUE, TRUE); | ||
2586 | 2580 | return TRUE; | ||
2587 | 2581 | } | ||
2588 | 2582 | |||
2589 | 2583 | /** | ||
2590 | 2584 | * rb_shell_player_get_volume: | ||
2591 | 2585 | * @player: the #RBShellPlayer | ||
2592 | 2586 | * @volume: (out): returns the volume level | ||
2593 | 2587 | * @error: returns error information | ||
2594 | 2588 | * | ||
2595 | 2589 | * Returns the current volume level | ||
2596 | 2590 | * | ||
2597 | 2591 | * Return value: the current volume level. | ||
2598 | 2592 | */ | ||
2599 | 2593 | gboolean | ||
2600 | 2594 | rb_shell_player_get_volume (RBShellPlayer *player, | ||
2601 | 2595 | gdouble *volume, | ||
2602 | 2596 | GError **error) | ||
2603 | 2597 | { | ||
2604 | 2598 | *volume = player->priv->volume; | ||
2605 | 2599 | return TRUE; | ||
2606 | 2600 | } | ||
2607 | 2601 | |||
2608 | 2602 | static void | ||
2609 | 2603 | rb_shell_player_volume_changed_cb (RBPlayer *player, | ||
2610 | 2604 | float volume, | ||
2611 | 2605 | RBShellPlayer *shell_player) | ||
2612 | 2606 | { | ||
2613 | 2607 | shell_player->priv->volume = volume; | ||
2614 | 2608 | rb_shell_player_sync_volume (shell_player, TRUE, FALSE); | ||
2615 | 2609 | } | ||
2616 | 2610 | |||
2617 | 2611 | /** | ||
2618 | 2612 | * rb_shell_player_set_mute | ||
2619 | 2613 | * @player: the #RBShellPlayer | ||
2620 | 2614 | * @mute: %TRUE to mute playback | ||
2621 | 2615 | * @error: returns error information | ||
2622 | 2616 | * | ||
2623 | 2617 | * Updates the mute setting on the player. | ||
2624 | 2618 | * | ||
2625 | 2619 | * Return value: %TRUE if successful | ||
2626 | 2620 | */ | ||
2627 | 2621 | gboolean | ||
2628 | 2622 | rb_shell_player_set_mute (RBShellPlayer *player, | ||
2629 | 2623 | gboolean mute, | ||
2630 | 2624 | GError **error) | ||
2631 | 2625 | { | ||
2632 | 2626 | player->priv->mute = mute; | ||
2633 | 2627 | rb_shell_player_sync_volume (player, FALSE, TRUE); | ||
2634 | 2628 | return TRUE; | ||
2635 | 2629 | } | ||
2636 | 2630 | |||
2637 | 2631 | /** | ||
2638 | 2632 | * rb_shell_player_get_mute: | ||
2639 | 2633 | * @player: the #RBShellPlayer | ||
2640 | 2634 | * @mute: (out): returns the current mute setting | ||
2641 | 2635 | * @error: returns error information | ||
2642 | 2636 | * | ||
2643 | 2637 | * Returns %TRUE if currently muted | ||
2644 | 2638 | * | ||
2645 | 2639 | * Return value: %TRUE if currently muted | ||
2646 | 2640 | */ | ||
2647 | 2641 | gboolean | ||
2648 | 2642 | rb_shell_player_get_mute (RBShellPlayer *player, | ||
2649 | 2643 | gboolean *mute, | ||
2650 | 2644 | GError **error) | ||
2651 | 2645 | { | ||
2652 | 2646 | *mute = player->priv->mute; | ||
2653 | 2647 | return TRUE; | ||
2654 | 2648 | } | ||
2655 | 2649 | |||
2656 | 2650 | static void | ||
2657 | 2651 | rb_shell_player_shuffle_changed_cb (GtkAction *action, | ||
2658 | 2652 | RBShellPlayer *player) | ||
2659 | 2653 | { | ||
2660 | 2654 | const char *neworder; | ||
2661 | 2655 | gboolean shuffle = FALSE; | ||
2662 | 2656 | gboolean repeat = FALSE; | ||
2663 | 2657 | |||
2664 | 2658 | if (player->priv->syncing_state) | ||
2665 | 2659 | return; | ||
2666 | 2660 | |||
2667 | 2661 | rb_debug ("shuffle changed"); | ||
2668 | 2662 | |||
2669 | 2663 | rb_shell_player_get_playback_state (player, &shuffle, &repeat); | ||
2670 | 2664 | |||
2671 | 2665 | shuffle = !shuffle; | ||
2672 | 2666 | neworder = state_to_play_order[shuffle ? 1 : 0][repeat ? 1 : 0]; | ||
2673 | 2667 | g_settings_set_string (player->priv->settings, "play-order", neworder); | ||
2674 | 2668 | } | ||
2675 | 2669 | |||
2676 | 2670 | static void | ||
2677 | 2671 | rb_shell_player_repeat_changed_cb (GtkAction *action, | ||
2678 | 2672 | RBShellPlayer *player) | ||
2679 | 2673 | { | ||
2680 | 2674 | const char *neworder; | ||
2681 | 2675 | gboolean shuffle = FALSE; | ||
2682 | 2676 | gboolean repeat = FALSE; | ||
2683 | 2677 | rb_debug ("repeat changed"); | ||
2684 | 2678 | |||
2685 | 2679 | if (player->priv->syncing_state) | ||
2686 | 2680 | return; | ||
2687 | 2681 | |||
2688 | 2682 | rb_shell_player_get_playback_state (player, &shuffle, &repeat); | ||
2689 | 2683 | |||
2690 | 2684 | repeat = !repeat; | ||
2691 | 2685 | neworder = state_to_play_order[shuffle ? 1 : 0][repeat ? 1 : 0]; | ||
2692 | 2686 | g_settings_set_string (player->priv->settings, "play-order", neworder); | ||
2693 | 2687 | } | ||
2694 | 2688 | |||
2695 | 2689 | static void | ||
2696 | 2690 | rb_shell_player_entry_activated_cb (RBEntryView *view, | ||
2697 | 2691 | RhythmDBEntry *entry, | ||
2698 | 2692 | RBShellPlayer *player) | ||
2699 | 2693 | { | ||
2700 | 2694 | gboolean was_from_queue = FALSE; | ||
2701 | 2695 | RhythmDBEntry *prev_entry = NULL; | ||
2702 | 2696 | GError *error = NULL; | ||
2703 | 2697 | gboolean source_set = FALSE; | ||
2704 | 2698 | gboolean jump_to_entry = FALSE; | ||
2705 | 2699 | char *playback_uri; | ||
2706 | 2700 | |||
2707 | 2701 | g_return_if_fail (entry != NULL); | ||
2708 | 2702 | |||
2709 | 2703 | rb_debug ("got entry %p activated", entry); | ||
2710 | 2704 | |||
2711 | 2705 | /* don't play hidden entries */ | ||
2712 | 2706 | if (rhythmdb_entry_get_boolean (entry, RHYTHMDB_PROP_HIDDEN)) | ||
2713 | 2707 | return; | ||
2714 | 2708 | |||
2715 | 2709 | /* skip entries with no playback uri */ | ||
2716 | 2710 | playback_uri = rhythmdb_entry_get_playback_uri (entry); | ||
2717 | 2711 | if (playback_uri == NULL) | ||
2718 | 2712 | return; | ||
2719 | 2713 | |||
2720 | 2714 | g_free (playback_uri); | ||
2721 | 2715 | |||
2722 | 2716 | /* figure out where the previous entry came from */ | ||
2723 | 2717 | if ((player->priv->queue_source != NULL) && | ||
2724 | 2718 | (player->priv->current_playing_source == RB_SOURCE (player->priv->queue_source))) { | ||
2725 | 2719 | prev_entry = rb_shell_player_get_playing_entry (player); | ||
2726 | 2720 | was_from_queue = TRUE; | ||
2727 | 2721 | } | ||
2728 | 2722 | |||
2729 | 2723 | if (player->priv->queue_source) { | ||
2730 | 2724 | RBEntryView *queue_sidebar; | ||
2731 | 2725 | |||
2732 | 2726 | g_object_get (player->priv->queue_source, "sidebar", &queue_sidebar, NULL); | ||
2733 | 2727 | |||
2734 | 2728 | if (view == queue_sidebar || view == rb_source_get_entry_view (RB_SOURCE (player->priv->queue_source))) { | ||
2735 | 2729 | |||
2736 | 2730 | /* fall back to the current selected source once the queue is empty */ | ||
2737 | 2731 | if (view == queue_sidebar && player->priv->source == NULL) { | ||
2738 | 2732 | /* XXX only do this if the selected source doesn't have its own play order? */ | ||
2739 | 2733 | rb_play_order_playing_source_changed (player->priv->play_order, | ||
2740 | 2734 | player->priv->selected_source); | ||
2741 | 2735 | player->priv->source = player->priv->selected_source; | ||
2742 | 2736 | } | ||
2743 | 2737 | |||
2744 | 2738 | rb_shell_player_set_playing_source (player, RB_SOURCE (player->priv->queue_source)); | ||
2745 | 2739 | |||
2746 | 2740 | was_from_queue = FALSE; | ||
2747 | 2741 | source_set = TRUE; | ||
2748 | 2742 | jump_to_entry = TRUE; | ||
2749 | 2743 | } else { | ||
2750 | 2744 | if (player->priv->queue_only) { | ||
2751 | 2745 | rb_source_add_to_queue (player->priv->selected_source, | ||
2752 | 2746 | RB_SOURCE (player->priv->queue_source)); | ||
2753 | 2747 | rb_shell_player_set_playing_source (player, RB_SOURCE (player->priv->queue_source)); | ||
2754 | 2748 | source_set = TRUE; | ||
2755 | 2749 | } | ||
2756 | 2750 | } | ||
2757 | 2751 | |||
2758 | 2752 | g_object_unref (queue_sidebar); | ||
2759 | 2753 | } | ||
2760 | 2754 | |||
2761 | 2755 | /* bail out if queue only */ | ||
2762 | 2756 | if (player->priv->queue_only) { | ||
2763 | 2757 | return; | ||
2764 | 2758 | } | ||
2765 | 2759 | |||
2766 | 2760 | if (!source_set) { | ||
2767 | 2761 | rb_shell_player_set_playing_source (player, player->priv->selected_source); | ||
2768 | 2762 | source_set = TRUE; | ||
2769 | 2763 | } | ||
2770 | 2764 | |||
2771 | 2765 | player->priv->jump_to_playing_entry = jump_to_entry; | ||
2772 | 2766 | if (!rb_shell_player_set_playing_entry (player, entry, TRUE, FALSE, &error)) { | ||
2773 | 2767 | rb_shell_player_error (player, FALSE, error); | ||
2774 | 2768 | g_clear_error (&error); | ||
2775 | 2769 | } | ||
2776 | 2770 | |||
2777 | 2771 | /* if we were previously playing from the queue, clear its playing entry, | ||
2778 | 2772 | * so we'll start again from the start. | ||
2779 | 2773 | */ | ||
2780 | 2774 | if (was_from_queue && prev_entry != NULL) { | ||
2781 | 2775 | rb_play_order_set_playing_entry (player->priv->queue_play_order, NULL); | ||
2782 | 2776 | } | ||
2783 | 2777 | |||
2784 | 2778 | if (prev_entry != NULL) { | ||
2785 | 2779 | rhythmdb_entry_unref (prev_entry); | ||
2786 | 2780 | } | ||
2787 | 2781 | } | ||
2788 | 2782 | |||
2789 | 2783 | static void | ||
2790 | 2784 | rb_shell_player_property_row_activated_cb (RBPropertyView *view, | ||
2791 | 2785 | const char *name, | ||
2792 | 2786 | RBShellPlayer *player) | ||
2793 | 2787 | { | ||
2794 | 2788 | RBPlayOrder *porder; | ||
2795 | 2789 | RhythmDBEntry *entry = NULL; | ||
2796 | 2790 | GError *error = NULL; | ||
2797 | 2791 | |||
2798 | 2792 | rb_debug ("got property activated"); | ||
2799 | 2793 | |||
2800 | 2794 | rb_shell_player_set_playing_source (player, player->priv->selected_source); | ||
2801 | 2795 | |||
2802 | 2796 | /* RHYTHMDBFIXME - do we need to wait here until the query is finished? | ||
2803 | 2797 | * in theory, yes, but in practice the query is started when the row is | ||
2804 | 2798 | * selected (on the first click when doubleclicking, or when using the | ||
2805 | 2799 | * keyboard to select then activate) and is pretty much always done by | ||
2806 | 2800 | * the time we get in here. | ||
2807 | 2801 | */ | ||
2808 | 2802 | |||
2809 | 2803 | g_object_get (player->priv->selected_source, "play-order", &porder, NULL); | ||
2810 | 2804 | if (porder == NULL) | ||
2811 | 2805 | porder = g_object_ref (player->priv->play_order); | ||
2812 | 2806 | |||
2813 | 2807 | entry = rb_play_order_get_next (porder); | ||
2814 | 2808 | if (entry != NULL) { | ||
2815 | 2809 | rb_play_order_go_next (porder); | ||
2816 | 2810 | |||
2817 | 2811 | player->priv->jump_to_playing_entry = TRUE; /* ? */ | ||
2818 | 2812 | if (!rb_shell_player_set_playing_entry (player, entry, TRUE, FALSE, &error)) { | ||
2819 | 2813 | rb_shell_player_error (player, FALSE, error); | ||
2820 | 2814 | g_clear_error (&error); | ||
2821 | 2815 | } | ||
2822 | 2816 | } | ||
2823 | 2817 | |||
2824 | 2818 | rhythmdb_entry_unref (entry); | ||
2825 | 2819 | g_object_unref (porder); | ||
2826 | 2820 | } | ||
2827 | 2821 | |||
2828 | 2822 | static void | ||
2829 | 2823 | rb_shell_player_entry_changed_cb (RhythmDB *db, | ||
2830 | 2824 | RhythmDBEntry *entry, | ||
2831 | 2825 | GValueArray *changes, | ||
2832 | 2826 | RBShellPlayer *player) | ||
2833 | 2827 | { | ||
2834 | 2828 | gboolean synced = FALSE; | ||
2835 | 2829 | const char *location; | ||
2836 | 2830 | RhythmDBEntry *playing_entry; | ||
2837 | 2831 | int i; | ||
2838 | 2832 | |||
2839 | 2833 | playing_entry = rb_shell_player_get_playing_entry (player); | ||
2840 | 2834 | |||
2841 | 2835 | /* We try to update only if the changed entry is currently playing */ | ||
2842 | 2836 | if (entry != playing_entry) { | ||
2843 | 2837 | if (playing_entry != NULL) { | ||
2844 | 2838 | rhythmdb_entry_unref (playing_entry); | ||
2845 | 2839 | } | ||
2846 | 2840 | return; | ||
2847 | 2841 | } | ||
2848 | 2842 | |||
2849 | 2843 | location = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); | ||
2850 | 2844 | for (i = 0; i < changes->n_values; i++) { | ||
2851 | 2845 | GValue *v = g_value_array_get_nth (changes, i); | ||
2852 | 2846 | RhythmDBEntryChange *change = g_value_get_boxed (v); | ||
2853 | 2847 | |||
2854 | 2848 | /* update UI if the artist, title or album has changed */ | ||
2855 | 2849 | switch (change->prop) { | ||
2856 | 2850 | case RHYTHMDB_PROP_TITLE: | ||
2857 | 2851 | case RHYTHMDB_PROP_ARTIST: | ||
2858 | 2852 | case RHYTHMDB_PROP_ALBUM: | ||
2859 | 2853 | if (!synced) { | ||
2860 | 2854 | rb_shell_player_sync_with_source (player); | ||
2861 | 2855 | synced = TRUE; | ||
2862 | 2856 | } | ||
2863 | 2857 | break; | ||
2864 | 2858 | default: | ||
2865 | 2859 | break; | ||
2866 | 2860 | } | ||
2867 | 2861 | |||
2868 | 2862 | /* emit dbus signals for changes with easily marshallable types */ | ||
2869 | 2863 | switch (rhythmdb_get_property_type (db, change->prop)) { | ||
2870 | 2864 | case G_TYPE_STRING: | ||
2871 | 2865 | case G_TYPE_BOOLEAN: | ||
2872 | 2866 | case G_TYPE_ULONG: | ||
2873 | 2867 | case G_TYPE_UINT64: | ||
2874 | 2868 | case G_TYPE_DOUBLE: | ||
2875 | 2869 | g_signal_emit (G_OBJECT (player), | ||
2876 | 2870 | rb_shell_player_signals[PLAYING_SONG_PROPERTY_CHANGED], 0, | ||
2877 | 2871 | location, | ||
2878 | 2872 | rhythmdb_nice_elt_name_from_propid (db, change->prop), | ||
2879 | 2873 | &change->old, | ||
2880 | 2874 | &change->new); | ||
2881 | 2875 | break; | ||
2882 | 2876 | default: | ||
2883 | 2877 | break; | ||
2884 | 2878 | } | ||
2885 | 2879 | } | ||
2886 | 2880 | |||
2887 | 2881 | if (playing_entry != NULL) { | ||
2888 | 2882 | rhythmdb_entry_unref (playing_entry); | ||
2889 | 2883 | } | ||
2890 | 2884 | } | ||
2891 | 2885 | |||
2892 | 2886 | static void | ||
2893 | 2887 | rb_shell_player_extra_metadata_cb (RhythmDB *db, | ||
2894 | 2888 | RhythmDBEntry *entry, | ||
2895 | 2889 | const char *field, | ||
2896 | 2890 | GValue *metadata, | ||
2897 | 2891 | RBShellPlayer *player) | ||
2898 | 2892 | { | ||
2899 | 2893 | |||
2900 | 2894 | RhythmDBEntry *playing_entry; | ||
2901 | 2895 | |||
2902 | 2896 | playing_entry = rb_shell_player_get_playing_entry (player); | ||
2903 | 2897 | if (entry != playing_entry) { | ||
2904 | 2898 | if (playing_entry != NULL) { | ||
2905 | 2899 | rhythmdb_entry_unref (playing_entry); | ||
2906 | 2900 | } | ||
2907 | 2901 | return; | ||
2908 | 2902 | } | ||
2909 | 2903 | |||
2910 | 2904 | rb_shell_player_sync_with_source (player); | ||
2911 | 2905 | |||
2912 | 2906 | /* emit dbus signals for changes with easily marshallable types */ | ||
2913 | 2907 | switch (G_VALUE_TYPE (metadata)) { | ||
2914 | 2908 | case G_TYPE_STRING: | ||
2915 | 2909 | /* make sure it's valid utf8, otherwise dbus barfs */ | ||
2916 | 2910 | if (g_utf8_validate (g_value_get_string (metadata), -1, NULL) == FALSE) { | ||
2917 | 2911 | rb_debug ("not emitting extra metadata field %s as value is not valid utf8", field); | ||
2918 | 2912 | return; | ||
2919 | 2913 | } | ||
2920 | 2914 | case G_TYPE_BOOLEAN: | ||
2921 | 2915 | case G_TYPE_ULONG: | ||
2922 | 2916 | case G_TYPE_UINT64: | ||
2923 | 2917 | case G_TYPE_DOUBLE: | ||
2924 | 2918 | g_signal_emit (G_OBJECT (player), | ||
2925 | 2919 | rb_shell_player_signals[PLAYING_SONG_PROPERTY_CHANGED], 0, | ||
2926 | 2920 | rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION), | ||
2927 | 2921 | field, | ||
2928 | 2922 | metadata, /* slightly silly */ | ||
2929 | 2923 | metadata); | ||
2930 | 2924 | break; | ||
2931 | 2925 | default: | ||
2932 | 2926 | break; | ||
2933 | 2927 | } | ||
2934 | 2928 | } | ||
2935 | 2929 | |||
2936 | 2930 | |||
2937 | 2931 | static void | ||
2938 | 2932 | rb_shell_player_sync_with_source (RBShellPlayer *player) | ||
2939 | 2933 | { | ||
2940 | 2934 | const char *entry_title = NULL; | ||
2941 | 2935 | const char *artist = NULL; | ||
2942 | 2936 | const char *stream_name = NULL; | ||
2943 | 2937 | char *streaming_title = NULL; | ||
2944 | 2938 | char *streaming_artist = NULL; | ||
2945 | 2939 | RhythmDBEntry *entry; | ||
2946 | 2940 | char *title = NULL; | ||
2947 | 2941 | gint64 elapsed; | ||
2948 | 2942 | |||
2949 | 2943 | entry = rb_shell_player_get_playing_entry (player); | ||
2950 | 2944 | rb_debug ("playing source: %p, active entry: %p", player->priv->current_playing_source, entry); | ||
2951 | 2945 | |||
2952 | 2946 | if (entry != NULL) { | ||
2953 | 2947 | GValue *value; | ||
2954 | 2948 | |||
2955 | 2949 | entry_title = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_TITLE); | ||
2956 | 2950 | artist = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST); | ||
2957 | 2951 | |||
2958 | 2952 | value = rhythmdb_entry_request_extra_metadata (player->priv->db, | ||
2959 | 2953 | entry, | ||
2960 | 2954 | RHYTHMDB_PROP_STREAM_SONG_TITLE); | ||
2961 | 2955 | if (value != NULL) { | ||
2962 | 2956 | streaming_title = g_value_dup_string (value); | ||
2963 | 2957 | g_value_unset (value); | ||
2964 | 2958 | g_free (value); | ||
2965 | 2959 | |||
2966 | 2960 | rb_debug ("got streaming title \"%s\"", streaming_title); | ||
2967 | 2961 | /* use entry title for stream name */ | ||
2968 | 2962 | stream_name = entry_title; | ||
2969 | 2963 | entry_title = streaming_title; | ||
2970 | 2964 | } | ||
2971 | 2965 | |||
2972 | 2966 | value = rhythmdb_entry_request_extra_metadata (player->priv->db, | ||
2973 | 2967 | entry, | ||
2974 | 2968 | RHYTHMDB_PROP_STREAM_SONG_ARTIST); | ||
2975 | 2969 | if (value != NULL) { | ||
2976 | 2970 | streaming_artist = g_value_dup_string (value); | ||
2977 | 2971 | g_value_unset (value); | ||
2978 | 2972 | g_free (value); | ||
2979 | 2973 | |||
2980 | 2974 | rb_debug ("got streaming artist \"%s\"", streaming_artist); | ||
2981 | 2975 | /* override artist from entry */ | ||
2982 | 2976 | artist = streaming_artist; | ||
2983 | 2977 | } | ||
2984 | 2978 | |||
2985 | 2979 | rhythmdb_entry_unref (entry); | ||
2986 | 2980 | } | ||
2987 | 2981 | |||
2988 | 2982 | if ((artist && artist[0] != '\0') || entry_title || stream_name) { | ||
2989 | 2983 | |||
2990 | 2984 | GString *title_str = g_string_sized_new (100); | ||
2991 | 2985 | if (artist && artist[0] != '\0') { | ||
2992 | 2986 | g_string_append (title_str, artist); | ||
2993 | 2987 | g_string_append (title_str, " - "); | ||
2994 | 2988 | } | ||
2995 | 2989 | if (entry_title != NULL) | ||
2996 | 2990 | g_string_append (title_str, entry_title); | ||
2997 | 2991 | |||
2998 | 2992 | if (stream_name != NULL) | ||
2999 | 2993 | g_string_append_printf (title_str, " (%s)", stream_name); | ||
3000 | 2994 | |||
3001 | 2995 | title = g_string_free (title_str, FALSE); | ||
3002 | 2996 | } | ||
3003 | 2997 | |||
3004 | 2998 | elapsed = rb_player_get_time (player->priv->mmplayer); | ||
3005 | 2999 | if (elapsed < 0) | ||
3006 | 3000 | elapsed = 0; | ||
3007 | 3001 | player->priv->elapsed = elapsed / RB_PLAYER_SECOND; | ||
3008 | 3002 | |||
3009 | 3003 | g_signal_emit (G_OBJECT (player), rb_shell_player_signals[WINDOW_TITLE_CHANGED], 0, | ||
3010 | 3004 | title); | ||
3011 | 3005 | g_free (title); | ||
3012 | 3006 | |||
3013 | 3007 | g_signal_emit (G_OBJECT (player), rb_shell_player_signals[ELAPSED_CHANGED], 0, | ||
3014 | 3008 | player->priv->elapsed); | ||
3015 | 3009 | |||
3016 | 3010 | g_free (streaming_artist); | ||
3017 | 3011 | g_free (streaming_title); | ||
3018 | 3012 | } | ||
3019 | 3013 | |||
3020 | 3014 | static void | ||
3021 | 3015 | rb_shell_player_sync_buttons (RBShellPlayer *player) | ||
3022 | 3016 | { | ||
3023 | 3017 | GtkAction *action; | ||
3024 | 3018 | RBSource *source; | ||
3025 | 3019 | RBEntryView *view; | ||
3026 | 3020 | int entry_view_state; | ||
3027 | 3021 | RhythmDBEntry *entry; | ||
3028 | 3022 | |||
3029 | 3023 | entry = rb_shell_player_get_playing_entry (player); | ||
3030 | 3024 | if (entry != NULL) { | ||
3031 | 3025 | source = player->priv->current_playing_source; | ||
3032 | 3026 | entry_view_state = rb_player_playing (player->priv->mmplayer) ? | ||
3033 | 3027 | RB_ENTRY_VIEW_PLAYING : RB_ENTRY_VIEW_PAUSED; | ||
3034 | 3028 | } else { | ||
3035 | 3029 | source = player->priv->selected_source; | ||
3036 | 3030 | entry_view_state = RB_ENTRY_VIEW_NOT_PLAYING; | ||
3037 | 3031 | } | ||
3038 | 3032 | |||
3039 | 3033 | source = (entry == NULL) ? player->priv->selected_source : player->priv->current_playing_source; | ||
3040 | 3034 | |||
3041 | 3035 | rb_debug ("syncing with source %p", source); | ||
3042 | 3036 | |||
3043 | 3037 | action = gtk_action_group_get_action (player->priv->actiongroup, | ||
3044 | 3038 | "ViewJumpToPlaying"); | ||
3045 | 3039 | g_object_set (action, "sensitive", entry != NULL, NULL); | ||
3046 | 3040 | |||
3047 | 3041 | action = gtk_action_group_get_action (player->priv->actiongroup, | ||
3048 | 3042 | "ControlPlay"); | ||
3049 | 3043 | g_object_set (action, "sensitive", entry != NULL || source != NULL, NULL); | ||
3050 | 3044 | |||
3051 | 3045 | if (source != NULL) { | ||
3052 | 3046 | view = rb_source_get_entry_view (source); | ||
3053 | 3047 | if (view) | ||
3054 | 3048 | rb_entry_view_set_state (view, entry_view_state); | ||
3055 | 3049 | } | ||
3056 | 3050 | |||
3057 | 3051 | if (entry != NULL) { | ||
3058 | 3052 | rhythmdb_entry_unref (entry); | ||
3059 | 3053 | } | ||
3060 | 3054 | } | ||
3061 | 3055 | |||
3062 | 3056 | /** | ||
3063 | 3057 | * rb_shell_player_set_playing_source: | ||
3064 | 3058 | * @player: the #RBShellPlayer | ||
3065 | 3059 | * @source: the new playing #RBSource | ||
3066 | 3060 | * | ||
3067 | 3061 | * Replaces the current playing source. | ||
3068 | 3062 | */ | ||
3069 | 3063 | void | ||
3070 | 3064 | rb_shell_player_set_playing_source (RBShellPlayer *player, | ||
3071 | 3065 | RBSource *source) | ||
3072 | 3066 | { | ||
3073 | 3067 | rb_shell_player_set_playing_source_internal (player, source, TRUE); | ||
3074 | 3068 | } | ||
3075 | 3069 | |||
3076 | 3070 | static void | ||
3077 | 3071 | actually_set_playing_source (RBShellPlayer *player, | ||
3078 | 3072 | RBSource *source, | ||
3079 | 3073 | gboolean sync_entry_view) | ||
3080 | 3074 | { | ||
3081 | 3075 | RBPlayOrder *porder; | ||
3082 | 3076 | |||
3083 | 3077 | player->priv->source = source; | ||
3084 | 3078 | player->priv->current_playing_source = source; | ||
3085 | 3079 | |||
3086 | 3080 | if (source != NULL) { | ||
3087 | 3081 | RBEntryView *songs = rb_source_get_entry_view (player->priv->source); | ||
3088 | 3082 | if (sync_entry_view && songs) { | ||
3089 | 3083 | rb_entry_view_set_state (songs, RB_ENTRY_VIEW_PLAYING); | ||
3090 | 3084 | } | ||
3091 | 3085 | } | ||
3092 | 3086 | |||
3093 | 3087 | if (source != RB_SOURCE (player->priv->queue_source)) { | ||
3094 | 3088 | if (source == NULL) | ||
3095 | 3089 | source = player->priv->selected_source; | ||
3096 | 3090 | |||
3097 | 3091 | if (source != NULL) { | ||
3098 | 3092 | g_object_get (source, "play-order", &porder, NULL); | ||
3099 | 3093 | if (porder == NULL) | ||
3100 | 3094 | porder = g_object_ref (player->priv->play_order); | ||
3101 | 3095 | |||
3102 | 3096 | rb_play_order_playing_source_changed (porder, source); | ||
3103 | 3097 | g_object_unref (porder); | ||
3104 | 3098 | } | ||
3105 | 3099 | } | ||
3106 | 3100 | |||
3107 | 3101 | rb_shell_player_play_order_update_cb (player->priv->play_order, | ||
3108 | 3102 | FALSE, FALSE, | ||
3109 | 3103 | player); | ||
3110 | 3104 | } | ||
3111 | 3105 | |||
3112 | 3106 | static void | ||
3113 | 3107 | rb_shell_player_set_playing_source_internal (RBShellPlayer *player, | ||
3114 | 3108 | RBSource *source, | ||
3115 | 3109 | gboolean sync_entry_view) | ||
3116 | 3110 | |||
3117 | 3111 | { | ||
3118 | 3112 | gboolean emit_source_changed = TRUE; | ||
3119 | 3113 | gboolean emit_playing_from_queue_changed = FALSE; | ||
3120 | 3114 | |||
3121 | 3115 | if (player->priv->source == source && | ||
3122 | 3116 | player->priv->current_playing_source == source && | ||
3123 | 3117 | source != NULL) | ||
3124 | 3118 | return; | ||
3125 | 3119 | |||
3126 | 3120 | rb_debug ("setting playing source to %p", source); | ||
3127 | 3121 | |||
3128 | 3122 | if (RB_SOURCE (player->priv->queue_source) == source) { | ||
3129 | 3123 | |||
3130 | 3124 | if (player->priv->current_playing_source != source) | ||
3131 | 3125 | emit_playing_from_queue_changed = TRUE; | ||
3132 | 3126 | |||
3133 | 3127 | if (player->priv->source == NULL) { | ||
3134 | 3128 | actually_set_playing_source (player, source, sync_entry_view); | ||
3135 | 3129 | } else { | ||
3136 | 3130 | emit_source_changed = FALSE; | ||
3137 | 3131 | player->priv->current_playing_source = source; | ||
3138 | 3132 | } | ||
3139 | 3133 | |||
3140 | 3134 | } else { | ||
3141 | 3135 | if (player->priv->current_playing_source != source) { | ||
3142 | 3136 | if (player->priv->current_playing_source == RB_SOURCE (player->priv->queue_source)) | ||
3143 | 3137 | emit_playing_from_queue_changed = TRUE; | ||
3144 | 3138 | |||
3145 | 3139 | /* stop the old source */ | ||
3146 | 3140 | if (player->priv->current_playing_source != NULL) { | ||
3147 | 3141 | if (sync_entry_view) { | ||
3148 | 3142 | RBEntryView *songs = rb_source_get_entry_view (player->priv->current_playing_source); | ||
3149 | 3143 | rb_debug ("source is already playing, stopping it"); | ||
3150 | 3144 | |||
3151 | 3145 | /* clear the playing entry if we're switching between non-queue sources */ | ||
3152 | 3146 | if (player->priv->current_playing_source != RB_SOURCE (player->priv->queue_source)) | ||
3153 | 3147 | rb_play_order_set_playing_entry (player->priv->play_order, NULL); | ||
3154 | 3148 | |||
3155 | 3149 | if (songs) | ||
3156 | 3150 | rb_entry_view_set_state (songs, RB_ENTRY_VIEW_NOT_PLAYING); | ||
3157 | 3151 | } | ||
3158 | 3152 | } | ||
3159 | 3153 | } | ||
3160 | 3154 | actually_set_playing_source (player, source, sync_entry_view); | ||
3161 | 3155 | } | ||
3162 | 3156 | |||
3163 | 3157 | rb_shell_player_sync_with_source (player); | ||
3164 | 3158 | /*g_object_notify (G_OBJECT (player), "playing");*/ | ||
3165 | 3159 | if (player->priv->selected_source) | ||
3166 | 3160 | rb_shell_player_sync_buttons (player); | ||
3167 | 3161 | |||
3168 | 3162 | if (emit_source_changed) { | ||
3169 | 3163 | g_signal_emit (G_OBJECT (player), rb_shell_player_signals[PLAYING_SOURCE_CHANGED], | ||
3170 | 3164 | 0, player->priv->source); | ||
3171 | 3165 | } | ||
3172 | 3166 | if (emit_playing_from_queue_changed) { | ||
3173 | 3167 | g_object_notify (G_OBJECT (player), "playing-from-queue"); | ||
3174 | 3168 | } | ||
3175 | 3169 | } | ||
3176 | 3170 | |||
3177 | 3171 | /** | ||
3178 | 3172 | * rb_shell_player_stop: | ||
3179 | 3173 | * @player: a #RBShellPlayer. | ||
3180 | 3174 | * | ||
3181 | 3175 | * Completely stops playback, freeing resources and unloading the file. | ||
3182 | 3176 | * | ||
3183 | 3177 | * In general rb_shell_player_pause() should be used instead, as it stops the | ||
3184 | 3178 | * audio, but does not completely free resources. | ||
3185 | 3179 | **/ | ||
3186 | 3180 | void | ||
3187 | 3181 | rb_shell_player_stop (RBShellPlayer *player) | ||
3188 | 3182 | { | ||
3189 | 3183 | GError *error = NULL; | ||
3190 | 3184 | rb_debug ("stopping"); | ||
3191 | 3185 | |||
3192 | 3186 | g_return_if_fail (RB_IS_SHELL_PLAYER (player)); | ||
3193 | 3187 | |||
3194 | 3188 | if (error == NULL) | ||
3195 | 3189 | rb_player_close (player->priv->mmplayer, NULL, &error); | ||
3196 | 3190 | if (error) { | ||
3197 | 3191 | rb_error_dialog (NULL, | ||
3198 | 3192 | _("Couldn't stop playback"), | ||
3199 | 3193 | "%s", error->message); | ||
3200 | 3194 | g_error_free (error); | ||
3201 | 3195 | } | ||
3202 | 3196 | |||
3203 | 3197 | if (player->priv->parser_cancellable != NULL) { | ||
3204 | 3198 | rb_debug ("cancelling playlist parser"); | ||
3205 | 3199 | g_cancellable_cancel (player->priv->parser_cancellable); | ||
3206 | 3200 | g_object_unref (player->priv->parser_cancellable); | ||
3207 | 3201 | player->priv->parser_cancellable = NULL; | ||
3208 | 3202 | } | ||
3209 | 3203 | |||
3210 | 3204 | if (player->priv->playing_entry != NULL) { | ||
3211 | 3205 | rhythmdb_entry_unref (player->priv->playing_entry); | ||
3212 | 3206 | player->priv->playing_entry = NULL; | ||
3213 | 3207 | } | ||
3214 | 3208 | |||
3215 | 3209 | rb_shell_player_set_playing_source (player, NULL); | ||
3216 | 3210 | rb_shell_player_sync_with_source (player); | ||
3217 | 3211 | g_signal_emit (G_OBJECT (player), | ||
3218 | 3212 | rb_shell_player_signals[PLAYING_SONG_CHANGED], 0, | ||
3219 | 3213 | NULL); | ||
3220 | 3214 | g_signal_emit (G_OBJECT (player), | ||
3221 | 3215 | rb_shell_player_signals[PLAYING_URI_CHANGED], 0, | ||
3222 | 3216 | NULL); | ||
3223 | 3217 | g_object_notify (G_OBJECT (player), "playing"); | ||
3224 | 3218 | rb_shell_player_sync_buttons (player); | ||
3225 | 3219 | } | ||
3226 | 3220 | |||
3227 | 3221 | /** | ||
3228 | 3222 | * rb_shell_player_pause: | ||
3229 | 3223 | * @player: a #RBShellPlayer | ||
3230 | 3224 | * @error: error return | ||
3231 | 3225 | * | ||
3232 | 3226 | * Pauses playback if possible, completely stopping if not. | ||
3233 | 3227 | * | ||
3234 | 3228 | * Return value: whether playback is not occurring (TRUE when successfully | ||
3235 | 3229 | * paused/stopped or playback was not occurring). | ||
3236 | 3230 | **/ | ||
3237 | 3231 | |||
3238 | 3232 | gboolean | ||
3239 | 3233 | rb_shell_player_pause (RBShellPlayer *player, | ||
3240 | 3234 | GError **error) | ||
3241 | 3235 | { | ||
3242 | 3236 | if (rb_player_playing (player->priv->mmplayer)) | ||
3243 | 3237 | return rb_shell_player_playpause (player, FALSE, error); | ||
3244 | 3238 | else | ||
3245 | 3239 | return TRUE; | ||
3246 | 3240 | } | ||
3247 | 3241 | |||
3248 | 3242 | /** | ||
3249 | 3243 | * rb_shell_player_get_playing: | ||
3250 | 3244 | * @player: a #RBShellPlayer | ||
3251 | 3245 | * @playing: (out): playback state return | ||
3252 | 3246 | * @error: error return | ||
3253 | 3247 | * | ||
3254 | 3248 | * Reports whether playback is occuring by setting #playing. | ||
3255 | 3249 | * | ||
3256 | 3250 | * Return value: %TRUE if successful | ||
3257 | 3251 | **/ | ||
3258 | 3252 | gboolean | ||
3259 | 3253 | rb_shell_player_get_playing (RBShellPlayer *player, | ||
3260 | 3254 | gboolean *playing, | ||
3261 | 3255 | GError **error) | ||
3262 | 3256 | { | ||
3263 | 3257 | if (playing != NULL) | ||
3264 | 3258 | *playing = rb_player_playing (player->priv->mmplayer); | ||
3265 | 3259 | |||
3266 | 3260 | return TRUE; | ||
3267 | 3261 | } | ||
3268 | 3262 | |||
3269 | 3263 | /** | ||
3270 | 3264 | * rb_shell_player_get_playing_time_string: | ||
3271 | 3265 | * @player: the #RBShellPlayer | ||
3272 | 3266 | * | ||
3273 | 3267 | * Constructs a string showing the current playback position, | ||
3274 | 3268 | * taking the time display settings into account. | ||
3275 | 3269 | * | ||
3276 | 3270 | * Return value: allocated playing time string | ||
3277 | 3271 | */ | ||
3278 | 3272 | char * | ||
3279 | 3273 | rb_shell_player_get_playing_time_string (RBShellPlayer *player) | ||
3280 | 3274 | { | ||
3281 | 3275 | gboolean elapsed; | ||
3282 | 3276 | elapsed = g_settings_get_boolean (player->priv->ui_settings, "time-display"); | ||
3283 | 3277 | return rb_make_elapsed_time_string (player->priv->elapsed, | ||
3284 | 3278 | rb_shell_player_get_playing_song_duration (player), | ||
3285 | 3279 | elapsed); | ||
3286 | 3280 | } | ||
3287 | 3281 | |||
3288 | 3282 | /** | ||
3289 | 3283 | * rb_shell_player_get_playing_time: | ||
3290 | 3284 | * @player: the #RBShellPlayer | ||
3291 | 3285 | * @time: (out): returns the current playback position | ||
3292 | 3286 | * @error: returns error information | ||
3293 | 3287 | * | ||
3294 | 3288 | * Retrieves the current playback position. Fails if | ||
3295 | 3289 | * the player currently cannot provide the playback | ||
3296 | 3290 | * position. | ||
3297 | 3291 | * | ||
3298 | 3292 | * Return value: %TRUE if successful | ||
3299 | 3293 | */ | ||
3300 | 3294 | gboolean | ||
3301 | 3295 | rb_shell_player_get_playing_time (RBShellPlayer *player, | ||
3302 | 3296 | guint *time, | ||
3303 | 3297 | GError **error) | ||
3304 | 3298 | { | ||
3305 | 3299 | gint64 ptime; | ||
3306 | 3300 | |||
3307 | 3301 | ptime = rb_player_get_time (player->priv->mmplayer); | ||
3308 | 3302 | if (ptime >= 0) { | ||
3309 | 3303 | if (time != NULL) { | ||
3310 | 3304 | *time = (guint)(ptime / RB_PLAYER_SECOND); | ||
3311 | 3305 | } | ||
3312 | 3306 | return TRUE; | ||
3313 | 3307 | } else { | ||
3314 | 3308 | g_set_error (error, | ||
3315 | 3309 | RB_SHELL_PLAYER_ERROR, | ||
3316 | 3310 | RB_SHELL_PLAYER_ERROR_POSITION_NOT_AVAILABLE, | ||
3317 | 3311 | _("Playback position not available")); | ||
3318 | 3312 | return FALSE; | ||
3319 | 3313 | } | ||
3320 | 3314 | } | ||
3321 | 3315 | |||
3322 | 3316 | /** | ||
3323 | 3317 | * rb_shell_player_set_playing_time: | ||
3324 | 3318 | * @player: the #RBShellPlayer | ||
3325 | 3319 | * @time: the target playback position (in seconds) | ||
3326 | 3320 | * @error: returns error information | ||
3327 | 3321 | * | ||
3328 | 3322 | * Attempts to set the playback position. Fails if the | ||
3329 | 3323 | * current song is not seekable. | ||
3330 | 3324 | * | ||
3331 | 3325 | * Return value: %TRUE if successful | ||
3332 | 3326 | */ | ||
3333 | 3327 | gboolean | ||
3334 | 3328 | rb_shell_player_set_playing_time (RBShellPlayer *player, | ||
3335 | 3329 | guint time, | ||
3336 | 3330 | GError **error) | ||
3337 | 3331 | { | ||
3338 | 3332 | if (rb_player_seekable (player->priv->mmplayer)) { | ||
3339 | 3333 | if (player->priv->playing_entry_eos) { | ||
3340 | 3334 | rb_debug ("forgetting that playing entry had EOS'd due to seek"); | ||
3341 | 3335 | player->priv->playing_entry_eos = FALSE; | ||
3342 | 3336 | } | ||
3343 | 3337 | rb_player_set_time (player->priv->mmplayer, ((gint64) time) * RB_PLAYER_SECOND); | ||
3344 | 3338 | return TRUE; | ||
3345 | 3339 | } else { | ||
3346 | 3340 | g_set_error (error, | ||
3347 | 3341 | RB_SHELL_PLAYER_ERROR, | ||
3348 | 3342 | RB_SHELL_PLAYER_ERROR_NOT_SEEKABLE, | ||
3349 | 3343 | _("Current song is not seekable")); | ||
3350 | 3344 | return FALSE; | ||
3351 | 3345 | } | ||
3352 | 3346 | } | ||
3353 | 3347 | |||
3354 | 3348 | /** | ||
3355 | 3349 | * rb_shell_player_seek: | ||
3356 | 3350 | * @player: the #RBShellPlayer | ||
3357 | 3351 | * @offset: relative seek target (in seconds) | ||
3358 | 3352 | * @error: returns error information | ||
3359 | 3353 | * | ||
3360 | 3354 | * Seeks forwards or backwards in the current playing | ||
3361 | 3355 | * song. Fails if the current song is not seekable. | ||
3362 | 3356 | * | ||
3363 | 3357 | * Return value: %TRUE if successful | ||
3364 | 3358 | */ | ||
3365 | 3359 | gboolean | ||
3366 | 3360 | rb_shell_player_seek (RBShellPlayer *player, | ||
3367 | 3361 | gint32 offset, | ||
3368 | 3362 | GError **error) | ||
3369 | 3363 | { | ||
3370 | 3364 | g_return_val_if_fail (RB_IS_SHELL_PLAYER (player), FALSE); | ||
3371 | 3365 | |||
3372 | 3366 | if (rb_player_seekable (player->priv->mmplayer)) { | ||
3373 | 3367 | gint64 target_time = rb_player_get_time (player->priv->mmplayer) + | ||
3374 | 3368 | (((gint64)offset) * RB_PLAYER_SECOND); | ||
3375 | 3369 | if (target_time < 0) | ||
3376 | 3370 | target_time = 0; | ||
3377 | 3371 | rb_player_set_time (player->priv->mmplayer, target_time); | ||
3378 | 3372 | return TRUE; | ||
3379 | 3373 | } else { | ||
3380 | 3374 | g_set_error (error, | ||
3381 | 3375 | RB_SHELL_PLAYER_ERROR, | ||
3382 | 3376 | RB_SHELL_PLAYER_ERROR_NOT_SEEKABLE, | ||
3383 | 3377 | _("Current song is not seekable")); | ||
3384 | 3378 | return FALSE; | ||
3385 | 3379 | } | ||
3386 | 3380 | } | ||
3387 | 3381 | |||
3388 | 3382 | /** | ||
3389 | 3383 | * rb_shell_player_get_playing_song_duration: | ||
3390 | 3384 | * @player: the #RBShellPlayer | ||
3391 | 3385 | * | ||
3392 | 3386 | * Retrieves the duration of the current playing song. | ||
3393 | 3387 | * | ||
3394 | 3388 | * Return value: duration, or -1 if not playing | ||
3395 | 3389 | */ | ||
3396 | 3390 | long | ||
3397 | 3391 | rb_shell_player_get_playing_song_duration (RBShellPlayer *player) | ||
3398 | 3392 | { | ||
3399 | 3393 | RhythmDBEntry *current_entry; | ||
3400 | 3394 | long val; | ||
3401 | 3395 | |||
3402 | 3396 | g_return_val_if_fail (RB_IS_SHELL_PLAYER (player), -1); | ||
3403 | 3397 | |||
3404 | 3398 | current_entry = rb_shell_player_get_playing_entry (player); | ||
3405 | 3399 | |||
3406 | 3400 | if (current_entry == NULL) { | ||
3407 | 3401 | rb_debug ("Did not get playing entry : return -1 as length"); | ||
3408 | 3402 | return -1; | ||
3409 | 3403 | } | ||
3410 | 3404 | |||
3411 | 3405 | val = rhythmdb_entry_get_ulong (current_entry, RHYTHMDB_PROP_DURATION); | ||
3412 | 3406 | |||
3413 | 3407 | rhythmdb_entry_unref (current_entry); | ||
3414 | 3408 | |||
3415 | 3409 | return val; | ||
3416 | 3410 | } | ||
3417 | 3411 | |||
3418 | 3412 | static void | ||
3419 | 3413 | rb_shell_player_sync_with_selected_source (RBShellPlayer *player) | ||
3420 | 3414 | { | ||
3421 | 3415 | rb_debug ("syncing with selected source: %p", player->priv->selected_source); | ||
3422 | 3416 | if (player->priv->source == NULL) | ||
3423 | 3417 | { | ||
3424 | 3418 | rb_debug ("no playing source, new source is %p", player->priv->selected_source); | ||
3425 | 3419 | rb_shell_player_sync_with_source (player); | ||
3426 | 3420 | } | ||
3427 | 3421 | } | ||
3428 | 3422 | |||
3429 | 3423 | static gboolean | ||
3430 | 3424 | do_next_idle (RBShellPlayer *player) | ||
3431 | 3425 | { | ||
3432 | 3426 | /* use the EOS callback, so that EOF_SOURCE_ conditions are handled properly */ | ||
3433 | 3427 | rb_shell_player_handle_eos (NULL, NULL, FALSE, player); | ||
3434 | 3428 | player->priv->do_next_idle_id = 0; | ||
3435 | 3429 | |||
3436 | 3430 | return FALSE; | ||
3437 | 3431 | } | ||
3438 | 3432 | |||
3439 | 3433 | static gboolean | ||
3440 | 3434 | do_next_not_found_idle (RBShellPlayer *player) | ||
3441 | 3435 | { | ||
3442 | 3436 | RhythmDBEntry *entry; | ||
3443 | 3437 | entry = rb_shell_player_get_playing_entry (player); | ||
3444 | 3438 | |||
3445 | 3439 | do_next_idle (player); | ||
3446 | 3440 | |||
3447 | 3441 | if (entry != NULL) { | ||
3448 | 3442 | rhythmdb_entry_update_availability (entry, RHYTHMDB_ENTRY_AVAIL_NOT_FOUND); | ||
3449 | 3443 | rhythmdb_commit (player->priv->db); | ||
3450 | 3444 | rhythmdb_entry_unref (entry); | ||
3451 | 3445 | } | ||
3452 | 3446 | |||
3453 | 3447 | return FALSE; | ||
3454 | 3448 | } | ||
3455 | 3449 | |||
3456 | 3450 | static void | ||
3457 | 3451 | rb_shell_player_error (RBShellPlayer *player, | ||
3458 | 3452 | gboolean async, | ||
3459 | 3453 | const GError *err) | ||
3460 | 3454 | { | ||
3461 | 3455 | RhythmDBEntry *entry; | ||
3462 | 3456 | gboolean do_next; | ||
3463 | 3457 | |||
3464 | 3458 | g_return_if_fail (player->priv->handling_error == FALSE); | ||
3465 | 3459 | |||
3466 | 3460 | player->priv->handling_error = TRUE; | ||
3467 | 3461 | |||
3468 | 3462 | entry = rb_shell_player_get_playing_entry (player); | ||
3469 | 3463 | |||
3470 | 3464 | rb_debug ("playback error while playing: %s", err->message); | ||
3471 | 3465 | /* For synchronous errors the entry playback error has already been set */ | ||
3472 | 3466 | if (entry && async) | ||
3473 | 3467 | rb_shell_player_set_entry_playback_error (player, entry, err->message); | ||
3474 | 3468 | |||
3475 | 3469 | if (entry == NULL) { | ||
3476 | 3470 | do_next = TRUE; | ||
3477 | 3471 | } else if (err->domain == RB_PLAYER_ERROR && err->code == RB_PLAYER_ERROR_NOT_FOUND) { | ||
3478 | 3472 | /* process not found errors after we've started the next track */ | ||
3479 | 3473 | if (player->priv->do_next_idle_id != 0) { | ||
3480 | 3474 | g_source_remove (player->priv->do_next_idle_id); | ||
3481 | 3475 | } | ||
3482 | 3476 | player->priv->do_next_idle_id = g_idle_add ((GSourceFunc)do_next_not_found_idle, player); | ||
3483 | 3477 | do_next = FALSE; | ||
3484 | 3478 | } else if (err->domain == RB_PLAYER_ERROR && err->code == RB_PLAYER_ERROR_NO_AUDIO) { | ||
3485 | 3479 | |||
3486 | 3480 | /* stream has completely ended */ | ||
3487 | 3481 | rb_shell_player_stop (player); | ||
3488 | 3482 | do_next = FALSE; | ||
3489 | 3483 | } else if ((player->priv->current_playing_source != NULL) && | ||
3490 | 3484 | (rb_source_handle_eos (player->priv->current_playing_source) == RB_SOURCE_EOF_RETRY)) { | ||
3491 | 3485 | /* receiving an error means a broken stream or non-audio stream, so abort | ||
3492 | 3486 | * unless we've got more URLs to try */ | ||
3493 | 3487 | if (g_queue_is_empty (player->priv->playlist_urls)) { | ||
3494 | 3488 | rb_error_dialog (NULL, | ||
3495 | 3489 | _("Couldn't start playback"), | ||
3496 | 3490 | "%s", (err) ? err->message : "(null)"); | ||
3497 | 3491 | rb_shell_player_stop (player); | ||
3498 | 3492 | do_next = FALSE; | ||
3499 | 3493 | } else { | ||
3500 | 3494 | rb_debug ("haven't yet exhausted the URLs from the playlist"); | ||
3501 | 3495 | do_next = TRUE; | ||
3502 | 3496 | } | ||
3503 | 3497 | } else { | ||
3504 | 3498 | do_next = TRUE; | ||
3505 | 3499 | } | ||
3506 | 3500 | |||
3507 | 3501 | if (do_next && player->priv->do_next_idle_id == 0) { | ||
3508 | 3502 | player->priv->do_next_idle_id = g_idle_add ((GSourceFunc)do_next_idle, player); | ||
3509 | 3503 | } | ||
3510 | 3504 | |||
3511 | 3505 | player->priv->handling_error = FALSE; | ||
3512 | 3506 | |||
3513 | 3507 | if (entry != NULL) { | ||
3514 | 3508 | rhythmdb_entry_unref (entry); | ||
3515 | 3509 | } | ||
3516 | 3510 | } | ||
3517 | 3511 | |||
3518 | 3512 | static void | ||
3519 | 3513 | playing_stream_cb (RBPlayer *mmplayer, | ||
3520 | 3514 | RhythmDBEntry *entry, | ||
3521 | 3515 | RBShellPlayer *player) | ||
3522 | 3516 | { | ||
3523 | 3517 | gboolean entry_changed; | ||
3524 | 3518 | |||
3525 | 3519 | g_return_if_fail (entry != NULL); | ||
3526 | 3520 | |||
3527 | 3521 | GDK_THREADS_ENTER (); | ||
3528 | 3522 | |||
3529 | 3523 | entry_changed = (player->priv->playing_entry != entry); | ||
3530 | 3524 | |||
3531 | 3525 | /* update playing entry */ | ||
3532 | 3526 | if (player->priv->playing_entry) | ||
3533 | 3527 | rhythmdb_entry_unref (player->priv->playing_entry); | ||
3534 | 3528 | player->priv->playing_entry = rhythmdb_entry_ref (entry); | ||
3535 | 3529 | player->priv->playing_entry_eos = FALSE; | ||
3536 | 3530 | |||
3537 | 3531 | if (entry_changed) { | ||
3538 | 3532 | const char *location; | ||
3539 | 3533 | |||
3540 | 3534 | location = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); | ||
3541 | 3535 | rb_debug ("new playing stream: %s", location); | ||
3542 | 3536 | g_signal_emit (G_OBJECT (player), | ||
3543 | 3537 | rb_shell_player_signals[PLAYING_SONG_CHANGED], 0, | ||
3544 | 3538 | entry); | ||
3545 | 3539 | g_signal_emit (G_OBJECT (player), | ||
3546 | 3540 | rb_shell_player_signals[PLAYING_URI_CHANGED], 0, | ||
3547 | 3541 | location); | ||
3548 | 3542 | } | ||
3549 | 3543 | |||
3550 | 3544 | /* resync UI */ | ||
3551 | 3545 | rb_shell_player_sync_with_source (player); | ||
3552 | 3546 | rb_shell_player_sync_buttons (player); | ||
3553 | 3547 | g_object_notify (G_OBJECT (player), "playing"); | ||
3554 | 3548 | |||
3555 | 3549 | if (player->priv->jump_to_playing_entry) { | ||
3556 | 3550 | rb_shell_player_jump_to_current (player); | ||
3557 | 3551 | player->priv->jump_to_playing_entry = FALSE; | ||
3558 | 3552 | } | ||
3559 | 3553 | |||
3560 | 3554 | GDK_THREADS_LEAVE (); | ||
3561 | 3555 | } | ||
3562 | 3556 | |||
3563 | 3557 | static void | ||
3564 | 3558 | error_cb (RBPlayer *mmplayer, | ||
3565 | 3559 | RhythmDBEntry *entry, | ||
3566 | 3560 | const GError *err, | ||
3567 | 3561 | gpointer data) | ||
3568 | 3562 | { | ||
3569 | 3563 | RBShellPlayer *player = RB_SHELL_PLAYER (data); | ||
3570 | 3564 | |||
3571 | 3565 | if (player->priv->handling_error) | ||
3572 | 3566 | return; | ||
3573 | 3567 | |||
3574 | 3568 | if (player->priv->source == NULL) { | ||
3575 | 3569 | rb_debug ("ignoring error (no source): %s", err->message); | ||
3576 | 3570 | return; | ||
3577 | 3571 | } | ||
3578 | 3572 | |||
3579 | 3573 | GDK_THREADS_ENTER (); | ||
3580 | 3574 | |||
3581 | 3575 | if (entry != player->priv->playing_entry) { | ||
3582 | 3576 | rb_debug ("got error for unexpected entry %p (expected %p)", entry, player->priv->playing_entry); | ||
3583 | 3577 | } else { | ||
3584 | 3578 | rb_shell_player_error (player, TRUE, err); | ||
3585 | 3579 | rb_debug ("exiting error hander"); | ||
3586 | 3580 | } | ||
3587 | 3581 | |||
3588 | 3582 | GDK_THREADS_LEAVE (); | ||
3589 | 3583 | } | ||
3590 | 3584 | |||
3591 | 3585 | static void | ||
3592 | 3586 | tick_cb (RBPlayer *mmplayer, | ||
3593 | 3587 | RhythmDBEntry *entry, | ||
3594 | 3588 | gint64 elapsed, | ||
3595 | 3589 | gint64 duration, | ||
3596 | 3590 | gpointer data) | ||
3597 | 3591 | { | ||
3598 | 3592 | RBShellPlayer *player = RB_SHELL_PLAYER (data); | ||
3599 | 3593 | gint64 remaining_check = 0; | ||
3600 | 3594 | gboolean duration_from_player = TRUE; | ||
3601 | 3595 | const char *uri; | ||
3602 | 3596 | long elapsed_sec; | ||
3603 | 3597 | |||
3604 | 3598 | GDK_THREADS_ENTER (); | ||
3605 | 3599 | |||
3606 | 3600 | if (player->priv->playing_entry != entry) { | ||
3607 | 3601 | rb_debug ("got tick for unexpected entry %p (expected %p)", entry, player->priv->playing_entry); | ||
3608 | 3602 | GDK_THREADS_LEAVE (); | ||
3609 | 3603 | return; | ||
3610 | 3604 | } | ||
3611 | 3605 | |||
3612 | 3606 | /* if we aren't getting a duration value from the player, use the | ||
3613 | 3607 | * value from the entry, if any. | ||
3614 | 3608 | */ | ||
3615 | 3609 | if (duration < 1) { | ||
3616 | 3610 | duration = ((gint64)rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION)) * RB_PLAYER_SECOND; | ||
3617 | 3611 | duration_from_player = FALSE; | ||
3618 | 3612 | } | ||
3619 | 3613 | |||
3620 | 3614 | uri = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); | ||
3621 | 3615 | rb_debug ("tick: [%s, %" G_GINT64_FORMAT ":%" G_GINT64_FORMAT "(%d)]", | ||
3622 | 3616 | uri, | ||
3623 | 3617 | elapsed, | ||
3624 | 3618 | duration, | ||
3625 | 3619 | duration_from_player); | ||
3626 | 3620 | |||
3627 | 3621 | if (elapsed < 0) { | ||
3628 | 3622 | elapsed_sec = 0; | ||
3629 | 3623 | } else { | ||
3630 | 3624 | elapsed_sec = elapsed / RB_PLAYER_SECOND; | ||
3631 | 3625 | } | ||
3632 | 3626 | |||
3633 | 3627 | if (player->priv->elapsed != elapsed_sec) { | ||
3634 | 3628 | player->priv->elapsed = elapsed_sec; | ||
3635 | 3629 | g_signal_emit (G_OBJECT (player), rb_shell_player_signals[ELAPSED_CHANGED], | ||
3636 | 3630 | 0, player->priv->elapsed); | ||
3637 | 3631 | } | ||
3638 | 3632 | g_signal_emit (player, rb_shell_player_signals[ELAPSED_NANO_CHANGED], 0, elapsed); | ||
3639 | 3633 | |||
3640 | 3634 | if (duration_from_player) { | ||
3641 | 3635 | /* XXX update duration in various things? */ | ||
3642 | 3636 | } | ||
3643 | 3637 | |||
3644 | 3638 | /* check if we should start a crossfade */ | ||
3645 | 3639 | if (rb_player_multiple_open (mmplayer)) { | ||
3646 | 3640 | if (player->priv->track_transition_time < PREROLL_TIME) { | ||
3647 | 3641 | remaining_check = PREROLL_TIME; | ||
3648 | 3642 | } else { | ||
3649 | 3643 | remaining_check = player->priv->track_transition_time; | ||
3650 | 3644 | } | ||
3651 | 3645 | } | ||
3652 | 3646 | |||
3653 | 3647 | /* | ||
3654 | 3648 | * just pretending we got an EOS will do exactly what we want | ||
3655 | 3649 | * here. if we don't want to crossfade, we'll just leave the stream | ||
3656 | 3650 | * prerolled until the current stream really ends. | ||
3657 | 3651 | */ | ||
3658 | 3652 | if (remaining_check > 0 && | ||
3659 | 3653 | duration > 0 && | ||
3660 | 3654 | elapsed > 0 && | ||
3661 | 3655 | ((duration - elapsed) <= remaining_check)) { | ||
3662 | 3656 | rb_debug ("%" G_GINT64_FORMAT " ns remaining in stream %s; need %" G_GINT64_FORMAT " for transition", | ||
3663 | 3657 | duration - elapsed, | ||
3664 | 3658 | uri, | ||
3665 | 3659 | remaining_check); | ||
3666 | 3660 | rb_shell_player_handle_eos_unlocked (player, entry, FALSE); | ||
3667 | 3661 | } | ||
3668 | 3662 | |||
3669 | 3663 | GDK_THREADS_LEAVE (); | ||
3670 | 3664 | } | ||
3671 | 3665 | |||
3672 | 3666 | typedef struct { | ||
3673 | 3667 | RhythmDBEntry *entry; | ||
3674 | 3668 | RBShellPlayer *player; | ||
3675 | 3669 | } MissingPluginRetryData; | ||
3676 | 3670 | |||
3677 | 3671 | static void | ||
3678 | 3672 | missing_plugins_retry_cb (gpointer inst, | ||
3679 | 3673 | gboolean retry, | ||
3680 | 3674 | MissingPluginRetryData *retry_data) | ||
3681 | 3675 | { | ||
3682 | 3676 | GError *error = NULL; | ||
3683 | 3677 | if (retry == FALSE) { | ||
3684 | 3678 | /* next? or stop playback? */ | ||
3685 | 3679 | rb_debug ("not retrying playback; stopping player"); | ||
3686 | 3680 | rb_shell_player_stop (retry_data->player); | ||
3687 | 3681 | return; | ||
3688 | 3682 | } | ||
3689 | 3683 | |||
3690 | 3684 | rb_debug ("retrying playback"); | ||
3691 | 3685 | rb_shell_player_set_playing_entry (retry_data->player, | ||
3692 | 3686 | retry_data->entry, | ||
3693 | 3687 | FALSE, FALSE, | ||
3694 | 3688 | &error); | ||
3695 | 3689 | if (error != NULL) { | ||
3696 | 3690 | rb_shell_player_error (retry_data->player, FALSE, error); | ||
3697 | 3691 | g_clear_error (&error); | ||
3698 | 3692 | } | ||
3699 | 3693 | } | ||
3700 | 3694 | |||
3701 | 3695 | static void | ||
3702 | 3696 | missing_plugins_retry_cleanup (MissingPluginRetryData *retry) | ||
3703 | 3697 | { | ||
3704 | 3698 | retry->player->priv->handling_error = FALSE; | ||
3705 | 3699 | |||
3706 | 3700 | g_object_unref (retry->player); | ||
3707 | 3701 | rhythmdb_entry_unref (retry->entry); | ||
3708 | 3702 | g_free (retry); | ||
3709 | 3703 | } | ||
3710 | 3704 | |||
3711 | 3705 | |||
3712 | 3706 | static void | ||
3713 | 3707 | missing_plugins_cb (RBPlayer *player, | ||
3714 | 3708 | RhythmDBEntry *entry, | ||
3715 | 3709 | const char **details, | ||
3716 | 3710 | const char **descriptions, | ||
3717 | 3711 | RBShellPlayer *sp) | ||
3718 | 3712 | { | ||
3719 | 3713 | gboolean processing; | ||
3720 | 3714 | GClosure *retry; | ||
3721 | 3715 | MissingPluginRetryData *retry_data; | ||
3722 | 3716 | |||
3723 | 3717 | retry_data = g_new0 (MissingPluginRetryData, 1); | ||
3724 | 3718 | retry_data->player = g_object_ref (sp); | ||
3725 | 3719 | retry_data->entry = rhythmdb_entry_ref (entry); | ||
3726 | 3720 | |||
3727 | 3721 | retry = g_cclosure_new ((GCallback) missing_plugins_retry_cb, | ||
3728 | 3722 | retry_data, | ||
3729 | 3723 | (GClosureNotify) missing_plugins_retry_cleanup); | ||
3730 | 3724 | g_closure_set_marshal (retry, g_cclosure_marshal_VOID__BOOLEAN); | ||
3731 | 3725 | processing = rb_missing_plugins_install (details, FALSE, retry); | ||
3732 | 3726 | if (processing) { | ||
3733 | 3727 | /* don't handle any further errors */ | ||
3734 | 3728 | sp->priv->handling_error = TRUE; | ||
3735 | 3729 | |||
3736 | 3730 | /* probably specify the URI here.. */ | ||
3737 | 3731 | rb_debug ("stopping player while processing missing plugins"); | ||
3738 | 3732 | rb_player_close (retry_data->player->priv->mmplayer, NULL, NULL); | ||
3739 | 3733 | } else { | ||
3740 | 3734 | rb_debug ("not processing missing plugins; simulating EOS"); | ||
3741 | 3735 | rb_shell_player_handle_eos (NULL, NULL, FALSE, retry_data->player); | ||
3742 | 3736 | } | ||
3743 | 3737 | |||
3744 | 3738 | g_closure_sink (retry); | ||
3745 | 3739 | } | ||
3746 | 3740 | |||
3747 | 3741 | static void | ||
3748 | 3742 | player_image_cb (RBPlayer *player, | ||
3749 | 3743 | RhythmDBEntry *entry, | ||
3750 | 3744 | GdkPixbuf *image, | ||
3751 | 3745 | RBShellPlayer *shell_player) | ||
3752 | 3746 | { | ||
3753 | 3747 | RBExtDB *store; | ||
3754 | 3748 | RBExtDBKey *key; | ||
3755 | 3749 | const char *artist; | ||
3756 | 3750 | GValue v = G_VALUE_INIT; | ||
3757 | 3751 | |||
3758 | 3752 | if (image == NULL) | ||
3759 | 3753 | return; | ||
3760 | 3754 | |||
3761 | 3755 | artist = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM_ARTIST); | ||
3762 | 3756 | if (artist == NULL || artist[0] == '\0' || strcmp (artist, _("Unknown")) == 0) { | ||
3763 | 3757 | artist = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST); | ||
3764 | 3758 | if (artist == NULL || artist[0] == '\0' || strcmp (artist, _("Unknown")) == 0) { | ||
3765 | 3759 | return; | ||
3766 | 3760 | } | ||
3767 | 3761 | } | ||
3768 | 3762 | |||
3769 | 3763 | store = rb_ext_db_new ("album-art"); | ||
3770 | 3764 | |||
3771 | 3765 | key = rb_ext_db_key_create_storage ("album", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM)); | ||
3772 | 3766 | rb_ext_db_key_add_field (key, "artist", artist); | ||
3773 | 3767 | |||
3774 | 3768 | g_value_init (&v, GDK_TYPE_PIXBUF); | ||
3775 | 3769 | g_value_set_object (&v, image); | ||
3776 | 3770 | rb_ext_db_store (store, key, RB_EXT_DB_SOURCE_EMBEDDED, &v); | ||
3777 | 3771 | g_value_unset (&v); | ||
3778 | 3772 | |||
3779 | 3773 | g_object_unref (store); | ||
3780 | 3774 | rb_ext_db_key_free (key); | ||
3781 | 3775 | } | ||
3782 | 3776 | |||
3783 | 3777 | /** | ||
3784 | 3778 | * rb_shell_player_get_playing_path: | ||
3785 | 3779 | * @player: the #RBShellPlayer | ||
3786 | 3780 | * @path: (out callee-allocates) (transfer full): returns the URI of the current playing entry | ||
3787 | 3781 | * @error: returns error information | ||
3788 | 3782 | * | ||
3789 | 3783 | * Retrieves the URI of the current playing entry. The | ||
3790 | 3784 | * caller must not free the returned string. | ||
3791 | 3785 | * | ||
3792 | 3786 | * Return value: %TRUE if successful | ||
3793 | 3787 | */ | ||
3794 | 3788 | gboolean | ||
3795 | 3789 | rb_shell_player_get_playing_path (RBShellPlayer *player, | ||
3796 | 3790 | const gchar **path, | ||
3797 | 3791 | GError **error) | ||
3798 | 3792 | { | ||
3799 | 3793 | RhythmDBEntry *entry; | ||
3800 | 3794 | |||
3801 | 3795 | entry = rb_shell_player_get_playing_entry (player); | ||
3802 | 3796 | if (entry != NULL) { | ||
3803 | 3797 | *path = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); | ||
3804 | 3798 | } else { | ||
3805 | 3799 | *path = NULL; | ||
3806 | 3800 | } | ||
3807 | 3801 | |||
3808 | 3802 | if (entry != NULL) { | ||
3809 | 3803 | rhythmdb_entry_unref (entry); | ||
3810 | 3804 | } | ||
3811 | 3805 | |||
3812 | 3806 | return TRUE; | ||
3813 | 3807 | } | ||
3814 | 3808 | |||
3815 | 3809 | static gboolean | ||
3816 | 3810 | _idle_unblock_signal_cb (gpointer data) | ||
3817 | 3811 | { | ||
3818 | 3812 | RBShellPlayer *player = (RBShellPlayer *)data; | ||
3819 | 3813 | GtkAction *action; | ||
3820 | 3814 | gboolean playing; | ||
3821 | 3815 | |||
3822 | 3816 | GDK_THREADS_ENTER (); | ||
3823 | 3817 | |||
3824 | 3818 | player->priv->unblock_play_id = 0; | ||
3825 | 3819 | |||
3826 | 3820 | action = gtk_action_group_get_action (player->priv->actiongroup, | ||
3827 | 3821 | "ControlPlay"); | ||
3828 | 3822 | |||
3829 | 3823 | /* sync the active state of the action again */ | ||
3830 | 3824 | g_object_get (player, "playing", &playing, NULL); | ||
3831 | 3825 | |||
3832 | 3826 | g_signal_handlers_unblock_by_func (action, rb_shell_player_cmd_play, player); | ||
3833 | 3827 | |||
3834 | 3828 | GDK_THREADS_LEAVE (); | ||
3835 | 3829 | return FALSE; | ||
3836 | 3830 | } | ||
3837 | 3831 | |||
3838 | 3832 | static void | ||
3839 | 3833 | rb_shell_player_playing_changed_cb (RBShellPlayer *player, | ||
3840 | 3834 | GParamSpec *arg1, | ||
3841 | 3835 | gpointer user_data) | ||
3842 | 3836 | { | ||
3843 | 3837 | GtkAction *action; | ||
3844 | 3838 | gboolean playing; | ||
3845 | 3839 | char *tooltip; | ||
3846 | 3840 | |||
3847 | 3841 | g_object_get (player, "playing", &playing, NULL); | ||
3848 | 3842 | action = gtk_action_group_get_action (player->priv->actiongroup, | ||
3849 | 3843 | "ControlPlay"); | ||
3850 | 3844 | if (playing) { | ||
3851 | 3845 | if (rb_source_can_pause (player->priv->source)) { | ||
3852 | 3846 | tooltip = g_strdup (_("Pause playback")); | ||
3853 | 3847 | gtk_action_set_stock_id (action, GTK_STOCK_MEDIA_PAUSE); | ||
3854 | 3848 | gtk_action_set_label (action, _("_Pause")); | ||
3855 | 3849 | } else { | ||
3856 | 3850 | tooltip = g_strdup (_("Stop playback")); | ||
3857 | 3851 | gtk_action_set_stock_id (action, GTK_STOCK_MEDIA_STOP); | ||
3858 | 3852 | gtk_action_set_label (action, _("_Stop")); | ||
3859 | 3853 | } | ||
3860 | 3854 | } else { | ||
3861 | 3855 | tooltip = g_strdup (_("Start playback")); | ||
3862 | 3856 | gtk_action_set_stock_id (action, GTK_STOCK_MEDIA_PLAY); | ||
3863 | 3857 | gtk_action_set_label (action, _("_Play")); | ||
3864 | 3858 | } | ||
3865 | 3859 | g_object_set (action, "tooltip", tooltip, NULL); | ||
3866 | 3860 | g_free (tooltip); | ||
3867 | 3861 | |||
3868 | 3862 | /* block the signal, so that it doesn't get stuck by triggering recursively, | ||
3869 | 3863 | * and don't unblock it until whatever else is happening has finished. | ||
3870 | 3864 | * don't block it again if it's already blocked, though. | ||
3871 | 3865 | */ | ||
3872 | 3866 | if (player->priv->unblock_play_id == 0) { | ||
3873 | 3867 | g_signal_handlers_block_by_func (action, rb_shell_player_cmd_play, player); | ||
3874 | 3868 | } | ||
3875 | 3869 | |||
3876 | 3870 | if (player->priv->unblock_play_id == 0) { | ||
3877 | 3871 | player->priv->unblock_play_id = g_idle_add (_idle_unblock_signal_cb, player); | ||
3878 | 3872 | } | ||
3879 | 3873 | } | ||
3880 | 3874 | |||
3881 | 3875 | /* This should really be standard. */ | ||
3882 | 3876 | #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } | ||
3883 | 3877 | |||
3884 | 3878 | GType | ||
3885 | 3879 | rb_shell_player_error_get_type (void) | ||
3886 | 3880 | { | ||
3887 | 3881 | static GType etype = 0; | ||
3888 | 3882 | |||
3889 | 3883 | if (etype == 0) { | ||
3890 | 3884 | static const GEnumValue values[] = { | ||
3891 | 3885 | ENUM_ENTRY (RB_SHELL_PLAYER_ERROR_PLAYLIST_PARSE_ERROR, "playlist-parse-failed"), | ||
3892 | 3886 | ENUM_ENTRY (RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST, "end-of-playlist"), | ||
3893 | 3887 | ENUM_ENTRY (RB_SHELL_PLAYER_ERROR_NOT_PLAYING, "not-playing"), | ||
3894 | 3888 | ENUM_ENTRY (RB_SHELL_PLAYER_ERROR_NOT_SEEKABLE, "not-seekable"), | ||
3895 | 3889 | ENUM_ENTRY (RB_SHELL_PLAYER_ERROR_POSITION_NOT_AVAILABLE, "position-not-available"), | ||
3896 | 3890 | { 0, 0, 0 } | ||
3897 | 3891 | }; | ||
3898 | 3892 | |||
3899 | 3893 | etype = g_enum_register_static ("RBShellPlayerError", values); | ||
3900 | 3894 | } | ||
3901 | 3895 | |||
3902 | 3896 | return etype; | ||
3903 | 3897 | } | ||
3904 | 3898 | |||
3905 | 3899 | static void | ||
3906 | 3900 | _play_order_description_free (RBPlayOrderDescription *order) | ||
3907 | 3901 | { | ||
3908 | 3902 | g_free (order->name); | ||
3909 | 3903 | g_free (order->description); | ||
3910 | 3904 | g_free (order); | ||
3911 | 3905 | } | ||
3912 | 3906 | |||
3913 | 3907 | /** | ||
3914 | 3908 | * rb_play_order_new: | ||
3915 | 3909 | * @porder_name: Play order type name | ||
3916 | 3910 | * @player: #RBShellPlayer instance to attach to | ||
3917 | 3911 | * | ||
3918 | 3912 | * Creates a new #RBPlayOrder of the specified type. | ||
3919 | 3913 | * | ||
3920 | 3914 | * Returns: #RBPlayOrder instance | ||
3921 | 3915 | **/ | ||
3922 | 3916 | |||
3923 | 3917 | #define DEFAULT_PLAY_ORDER "linear" | ||
3924 | 3918 | |||
3925 | 3919 | static RBPlayOrder * | ||
3926 | 3920 | rb_play_order_new (RBShellPlayer *player, const char* porder_name) | ||
3927 | 3921 | { | ||
3928 | 3922 | RBPlayOrderDescription *order; | ||
3929 | 3923 | |||
3930 | 3924 | g_return_val_if_fail (porder_name != NULL, NULL); | ||
3931 | 3925 | g_return_val_if_fail (player != NULL, NULL); | ||
3932 | 3926 | |||
3933 | 3927 | order = g_hash_table_lookup (player->priv->play_orders, porder_name); | ||
3934 | 3928 | |||
3935 | 3929 | if (order == NULL) { | ||
3936 | 3930 | g_warning ("Unknown value \"%s\" in GSettings key \"play-order" | ||
3937 | 3931 | "\". Using %s play order.", porder_name, DEFAULT_PLAY_ORDER); | ||
3938 | 3932 | order = g_hash_table_lookup (player->priv->play_orders, DEFAULT_PLAY_ORDER); | ||
3939 | 3933 | } | ||
3940 | 3934 | |||
3941 | 3935 | return RB_PLAY_ORDER (g_object_new (order->order_type, "player", player, NULL)); | ||
3942 | 3936 | } | ||
3943 | 3937 | |||
3944 | 3938 | /** | ||
3945 | 3939 | * rb_shell_player_add_play_order: | ||
3946 | 3940 | * @player: the #RBShellPlayer | ||
3947 | 3941 | * @name: name of the new play order | ||
3948 | 3942 | * @description: description of the new play order | ||
3949 | 3943 | * @order_type: the #GType of the play order class | ||
3950 | 3944 | * @hidden: if %TRUE, don't display the play order in the UI | ||
3951 | 3945 | * | ||
3952 | 3946 | * Adds a new play order to the set of available play orders. | ||
3953 | 3947 | */ | ||
3954 | 3948 | void | ||
3955 | 3949 | rb_shell_player_add_play_order (RBShellPlayer *player, const char *name, | ||
3956 | 3950 | const char *description, GType order_type, gboolean hidden) | ||
3957 | 3951 | { | ||
3958 | 3952 | RBPlayOrderDescription *order; | ||
3959 | 3953 | |||
3960 | 3954 | g_return_if_fail (g_type_is_a (order_type, RB_TYPE_PLAY_ORDER)); | ||
3961 | 3955 | |||
3962 | 3956 | order = g_new0(RBPlayOrderDescription, 1); | ||
3963 | 3957 | order->name = g_strdup (name); | ||
3964 | 3958 | order->description = g_strdup (description); | ||
3965 | 3959 | order->order_type = order_type; | ||
3966 | 3960 | order->is_in_dropdown = !hidden; | ||
3967 | 3961 | |||
3968 | 3962 | g_hash_table_insert (player->priv->play_orders, order->name, order); | ||
3969 | 3963 | } | ||
3970 | 3964 | |||
3971 | 3965 | /** | ||
3972 | 3966 | * rb_shell_player_remove_play_order: | ||
3973 | 3967 | * @player: the #RBShellPlayer | ||
3974 | 3968 | * @name: name of the play order to remove | ||
3975 | 3969 | * | ||
3976 | 3970 | * Removes a play order previously added with #rb_shell_player_add_play_order | ||
3977 | 3971 | * from the set of available play orders. | ||
3978 | 3972 | */ | ||
3979 | 3973 | void | ||
3980 | 3974 | rb_shell_player_remove_play_order (RBShellPlayer *player, const char *name) | ||
3981 | 3975 | { | ||
3982 | 3976 | g_hash_table_remove (player->priv->play_orders, name); | ||
3983 | 3977 | } | ||
3984 | 3978 | |||
3985 | 0 | 3979 | ||
3986 | === modified file '.pc/applied-patches' | |||
3987 | --- .pc/applied-patches 2012-09-19 14:30:03 +0000 | |||
3988 | +++ .pc/applied-patches 2012-11-07 20:44:28 +0000 | |||
3989 | @@ -7,6 +7,8 @@ | |||
3990 | 7 | 08_CVE-2012-3355.patch | 7 | 08_CVE-2012-3355.patch |
3991 | 8 | 09_keywords.patch | 8 | 09_keywords.patch |
3992 | 9 | 10_encoding_use_ubuntu_profiles.patch | 9 | 10_encoding_use_ubuntu_profiles.patch |
3993 | 10 | 11_fix_cd_pausing.patch | ||
3994 | 10 | dont_free_consumed_floating_gvariant.patch | 11 | dont_free_consumed_floating_gvariant.patch |
3995 | 11 | git_scale_click.patch | 12 | git_scale_click.patch |
3996 | 12 | git_crash_during_monitor.patch | 13 | git_crash_during_monitor.patch |
3997 | 14 | git_rhythmdb_fix_deadlock.patch | ||
3998 | 13 | 15 | ||
3999 | === added directory '.pc/git_rhythmdb_fix_deadlock.patch' | |||
4000 | === added directory '.pc/git_rhythmdb_fix_deadlock.patch/rhythmdb' | |||
4001 | === added file '.pc/git_rhythmdb_fix_deadlock.patch/rhythmdb/rhythmdb.c' | |||
4002 | --- .pc/git_rhythmdb_fix_deadlock.patch/rhythmdb/rhythmdb.c 1970-01-01 00:00:00 +0000 | |||
4003 | +++ .pc/git_rhythmdb_fix_deadlock.patch/rhythmdb/rhythmdb.c 2012-11-07 20:44:28 +0000 | |||
4004 | @@ -0,0 +1,5478 @@ | |||
4005 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- | ||
4006 | 2 | * | ||
4007 | 3 | * Copyright (C) 2003,2004 Colin Walters <walters@gnome.org> | ||
4008 | 4 | * | ||
4009 | 5 | * This program is free software; you can redistribute it and/or modify | ||
4010 | 6 | * it under the terms of the GNU General Public License as published by | ||
4011 | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
4012 | 8 | * (at your option) any later version. | ||
4013 | 9 | * | ||
4014 | 10 | * The Rhythmbox authors hereby grant permission for non-GPL compatible | ||
4015 | 11 | * GStreamer plugins to be used and distributed together with GStreamer | ||
4016 | 12 | * and Rhythmbox. This permission is above and beyond the permissions granted | ||
4017 | 13 | * by the GPL license by which Rhythmbox is covered. If you modify this code | ||
4018 | 14 | * you may extend this exception to your version of the code, but you are not | ||
4019 | 15 | * obligated to do so. If you do not wish to do so, delete this exception | ||
4020 | 16 | * statement from your version. | ||
4021 | 17 | * | ||
4022 | 18 | * This program is distributed in the hope that it will be useful, | ||
4023 | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
4024 | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
4025 | 21 | * GNU General Public License for more details. | ||
4026 | 22 | * | ||
4027 | 23 | * You should have received a copy of the GNU General Public License | ||
4028 | 24 | * along with this program; if not, write to the Free Software | ||
4029 | 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
4030 | 26 | * | ||
4031 | 27 | */ | ||
4032 | 28 | |||
4033 | 29 | /** | ||
4034 | 30 | * SECTION:rhythmdb | ||
4035 | 31 | * @short_description: Rhythmbox database functions | ||
4036 | 32 | * | ||
4037 | 33 | * RhythmDB is an in-memory database containing #RhythmDBEntry items. It | ||
4038 | 34 | * runs queries represented as #GPtrArray<!-- -->s containing query criteria, | ||
4039 | 35 | * feeding the results into #RhythmDBQueryResults implementations such as | ||
4040 | 36 | * #RhythmDBQueryModel. From there, entries are grouped by particular property | ||
4041 | 37 | * values to form #RhythmDBPropertyModel<!-- -->s. | ||
4042 | 38 | * | ||
4043 | 39 | * #RhythmDBEntry contains a fixed set of properties, defined by #RhythmDBPropType, | ||
4044 | 40 | */ | ||
4045 | 41 | |||
4046 | 42 | #include "config.h" | ||
4047 | 43 | |||
4048 | 44 | #define G_IMPLEMENT_INLINES 1 | ||
4049 | 45 | #define __RHYTHMDB_C__ | ||
4050 | 46 | #include "rhythmdb.h" | ||
4051 | 47 | #undef G_IMPLEMENT_INLINES | ||
4052 | 48 | |||
4053 | 49 | #include <string.h> | ||
4054 | 50 | #include <libxml/tree.h> | ||
4055 | 51 | #include <glib.h> | ||
4056 | 52 | #include <glib-object.h> | ||
4057 | 53 | #include <glib/gi18n.h> | ||
4058 | 54 | #include <gio/gio.h> | ||
4059 | 55 | #include <gobject/gvaluecollector.h> | ||
4060 | 56 | #include <gdk/gdk.h> | ||
4061 | 57 | |||
4062 | 58 | |||
4063 | 59 | #include "rb-marshal.h" | ||
4064 | 60 | #include "rb-file-helpers.h" | ||
4065 | 61 | #include "rb-debug.h" | ||
4066 | 62 | #include "rb-util.h" | ||
4067 | 63 | #include "rb-cut-and-paste-code.h" | ||
4068 | 64 | #include "rhythmdb-private.h" | ||
4069 | 65 | #include "rhythmdb-property-model.h" | ||
4070 | 66 | #include "rb-dialog.h" | ||
4071 | 67 | #include "rb-string-value-map.h" | ||
4072 | 68 | #include "rb-async-queue-watch.h" | ||
4073 | 69 | #include "rb-podcast-entry-types.h" | ||
4074 | 70 | #include "rb-gst-media-types.h" | ||
4075 | 71 | |||
4076 | 72 | #define PROP_ENTRY(p,t,n) { RHYTHMDB_PROP_ ## p, "RHYTHMDB_PROP_" #p "", t, n } | ||
4077 | 73 | |||
4078 | 74 | typedef struct _RhythmDBPropertyDef { | ||
4079 | 75 | RhythmDBPropType prop_id; | ||
4080 | 76 | const char *prop_name; | ||
4081 | 77 | GType prop_type; | ||
4082 | 78 | const char *elt_name; | ||
4083 | 79 | } RhythmDBPropertyDef; | ||
4084 | 80 | |||
4085 | 81 | static const RhythmDBPropertyDef rhythmdb_properties[] = { | ||
4086 | 82 | PROP_ENTRY(TYPE, G_TYPE_OBJECT, "type"), | ||
4087 | 83 | PROP_ENTRY(ENTRY_ID, G_TYPE_ULONG, "entry-id"), | ||
4088 | 84 | PROP_ENTRY(TITLE, G_TYPE_STRING, "title"), | ||
4089 | 85 | PROP_ENTRY(GENRE, G_TYPE_STRING, "genre"), | ||
4090 | 86 | PROP_ENTRY(ARTIST, G_TYPE_STRING, "artist"), | ||
4091 | 87 | PROP_ENTRY(ALBUM, G_TYPE_STRING, "album"), | ||
4092 | 88 | PROP_ENTRY(TRACK_NUMBER, G_TYPE_ULONG, "track-number"), | ||
4093 | 89 | PROP_ENTRY(DISC_NUMBER, G_TYPE_ULONG, "disc-number"), | ||
4094 | 90 | PROP_ENTRY(DURATION, G_TYPE_ULONG, "duration"), | ||
4095 | 91 | PROP_ENTRY(FILE_SIZE, G_TYPE_UINT64, "file-size"), | ||
4096 | 92 | PROP_ENTRY(LOCATION, G_TYPE_STRING, "location"), | ||
4097 | 93 | PROP_ENTRY(MOUNTPOINT, G_TYPE_STRING, "mountpoint"), | ||
4098 | 94 | PROP_ENTRY(MTIME, G_TYPE_ULONG, "mtime"), | ||
4099 | 95 | PROP_ENTRY(FIRST_SEEN, G_TYPE_ULONG, "first-seen"), | ||
4100 | 96 | PROP_ENTRY(LAST_SEEN, G_TYPE_ULONG, "last-seen"), | ||
4101 | 97 | PROP_ENTRY(RATING, G_TYPE_DOUBLE, "rating"), | ||
4102 | 98 | PROP_ENTRY(PLAY_COUNT, G_TYPE_ULONG, "play-count"), | ||
4103 | 99 | PROP_ENTRY(LAST_PLAYED, G_TYPE_ULONG, "last-played"), | ||
4104 | 100 | PROP_ENTRY(BITRATE, G_TYPE_ULONG, "bitrate"), | ||
4105 | 101 | PROP_ENTRY(DATE, G_TYPE_ULONG, "date"), | ||
4106 | 102 | PROP_ENTRY(TRACK_GAIN, G_TYPE_DOUBLE, "replaygain-track-gain"), | ||
4107 | 103 | PROP_ENTRY(TRACK_PEAK, G_TYPE_DOUBLE, "replaygain-track-peak"), | ||
4108 | 104 | PROP_ENTRY(ALBUM_GAIN, G_TYPE_DOUBLE, "replaygain-album-gain"), | ||
4109 | 105 | PROP_ENTRY(ALBUM_PEAK, G_TYPE_DOUBLE, "replaygain-album-peak"), | ||
4110 | 106 | PROP_ENTRY(MEDIA_TYPE, G_TYPE_STRING, "media-type"), | ||
4111 | 107 | PROP_ENTRY(TITLE_SORT_KEY, G_TYPE_STRING, "title-sort-key"), | ||
4112 | 108 | PROP_ENTRY(GENRE_SORT_KEY, G_TYPE_STRING, "genre-sort-key"), | ||
4113 | 109 | PROP_ENTRY(ARTIST_SORT_KEY, G_TYPE_STRING, "artist-sort-key"), | ||
4114 | 110 | PROP_ENTRY(ALBUM_SORT_KEY, G_TYPE_STRING, "album-sort-key"), | ||
4115 | 111 | PROP_ENTRY(TITLE_FOLDED, G_TYPE_STRING, "title-folded"), | ||
4116 | 112 | PROP_ENTRY(GENRE_FOLDED, G_TYPE_STRING, "genre-folded"), | ||
4117 | 113 | PROP_ENTRY(ARTIST_FOLDED, G_TYPE_STRING, "artist-folded"), | ||
4118 | 114 | PROP_ENTRY(ALBUM_FOLDED, G_TYPE_STRING, "album-folded"), | ||
4119 | 115 | PROP_ENTRY(LAST_PLAYED_STR, G_TYPE_STRING, "last-played-str"), | ||
4120 | 116 | PROP_ENTRY(HIDDEN, G_TYPE_BOOLEAN, "hidden"), | ||
4121 | 117 | PROP_ENTRY(PLAYBACK_ERROR, G_TYPE_STRING, "playback-error"), | ||
4122 | 118 | PROP_ENTRY(FIRST_SEEN_STR, G_TYPE_STRING, "first-seen-str"), | ||
4123 | 119 | PROP_ENTRY(LAST_SEEN_STR, G_TYPE_STRING, "last-seen-str"), | ||
4124 | 120 | |||
4125 | 121 | PROP_ENTRY(SEARCH_MATCH, G_TYPE_STRING, "search-match"), | ||
4126 | 122 | PROP_ENTRY(YEAR, G_TYPE_ULONG, "year"), | ||
4127 | 123 | PROP_ENTRY(KEYWORD, G_TYPE_STRING, "keyword"), | ||
4128 | 124 | |||
4129 | 125 | PROP_ENTRY(STATUS, G_TYPE_ULONG, "status"), | ||
4130 | 126 | PROP_ENTRY(DESCRIPTION, G_TYPE_STRING, "description"), | ||
4131 | 127 | PROP_ENTRY(SUBTITLE, G_TYPE_STRING, "subtitle"), | ||
4132 | 128 | PROP_ENTRY(SUMMARY, G_TYPE_STRING, "summary"), | ||
4133 | 129 | PROP_ENTRY(LANG, G_TYPE_STRING, "lang"), | ||
4134 | 130 | PROP_ENTRY(COPYRIGHT, G_TYPE_STRING, "copyright"), | ||
4135 | 131 | PROP_ENTRY(IMAGE, G_TYPE_STRING, "image"), | ||
4136 | 132 | PROP_ENTRY(POST_TIME, G_TYPE_ULONG, "post-time"), | ||
4137 | 133 | |||
4138 | 134 | PROP_ENTRY(MUSICBRAINZ_TRACKID, G_TYPE_STRING, "mb-trackid"), | ||
4139 | 135 | PROP_ENTRY(MUSICBRAINZ_ARTISTID, G_TYPE_STRING, "mb-artistid"), | ||
4140 | 136 | PROP_ENTRY(MUSICBRAINZ_ALBUMID, G_TYPE_STRING, "mb-albumid"), | ||
4141 | 137 | PROP_ENTRY(MUSICBRAINZ_ALBUMARTISTID, G_TYPE_STRING, "mb-albumartistid"), | ||
4142 | 138 | PROP_ENTRY(ARTIST_SORTNAME, G_TYPE_STRING, "mb-artistsortname"), | ||
4143 | 139 | PROP_ENTRY(ALBUM_SORTNAME, G_TYPE_STRING, "album-sortname"), | ||
4144 | 140 | |||
4145 | 141 | PROP_ENTRY(ARTIST_SORTNAME_SORT_KEY, G_TYPE_STRING, "artist-sortname-sort-key"), | ||
4146 | 142 | PROP_ENTRY(ARTIST_SORTNAME_FOLDED, G_TYPE_STRING, "artist-sortname-folded"), | ||
4147 | 143 | PROP_ENTRY(ALBUM_SORTNAME_SORT_KEY, G_TYPE_STRING, "album-sortname-sort-key"), | ||
4148 | 144 | PROP_ENTRY(ALBUM_SORTNAME_FOLDED, G_TYPE_STRING, "album-sortname-folded"), | ||
4149 | 145 | |||
4150 | 146 | PROP_ENTRY(COMMENT, G_TYPE_STRING, "comment"), | ||
4151 | 147 | |||
4152 | 148 | PROP_ENTRY(ALBUM_ARTIST, G_TYPE_STRING, "album-artist"), | ||
4153 | 149 | PROP_ENTRY(ALBUM_ARTIST_SORT_KEY, G_TYPE_STRING, "album-artist-sort-key"), | ||
4154 | 150 | PROP_ENTRY(ALBUM_ARTIST_FOLDED, G_TYPE_STRING, "album-artist-folded"), | ||
4155 | 151 | PROP_ENTRY(ALBUM_ARTIST_SORTNAME, G_TYPE_STRING, "album-artist-sortname"), | ||
4156 | 152 | PROP_ENTRY(ALBUM_ARTIST_SORTNAME_SORT_KEY, G_TYPE_STRING, "album-artist-sortname-sort-key"), | ||
4157 | 153 | PROP_ENTRY(ALBUM_ARTIST_SORTNAME_FOLDED, G_TYPE_STRING, "album-artist-sortname-folded"), | ||
4158 | 154 | |||
4159 | 155 | PROP_ENTRY(BPM, G_TYPE_DOUBLE, "beats-per-minute"), | ||
4160 | 156 | |||
4161 | 157 | { 0, 0, 0, 0 } | ||
4162 | 158 | }; | ||
4163 | 159 | |||
4164 | 160 | #define RB_PARSE_NICK_START (xmlChar *) "[" | ||
4165 | 161 | #define RB_PARSE_NICK_END (xmlChar *) "]" | ||
4166 | 162 | |||
4167 | 163 | |||
4168 | 164 | #define RHYTHMDB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RHYTHMDB_TYPE, RhythmDBPrivate)) | ||
4169 | 165 | G_DEFINE_ABSTRACT_TYPE(RhythmDB, rhythmdb, G_TYPE_OBJECT) | ||
4170 | 166 | |||
4171 | 167 | /* file attributes requested in RHYTHMDB_ACTION_STAT and RHYTHMDB_ACTION_LOAD */ | ||
4172 | 168 | #define RHYTHMDB_FILE_INFO_ATTRIBUTES \ | ||
4173 | 169 | G_FILE_ATTRIBUTE_STANDARD_SIZE "," \ | ||
4174 | 170 | G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," \ | ||
4175 | 171 | G_FILE_ATTRIBUTE_STANDARD_TYPE "," \ | ||
4176 | 172 | G_FILE_ATTRIBUTE_TIME_MODIFIED | ||
4177 | 173 | |||
4178 | 174 | /* file attributes requested in RHYTHMDB_ACTION_ENUM_DIR */ | ||
4179 | 175 | #define RHYTHMDB_FILE_CHILD_INFO_ATTRIBUTES \ | ||
4180 | 176 | RHYTHMDB_FILE_INFO_ATTRIBUTES "," \ | ||
4181 | 177 | G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN "," \ | ||
4182 | 178 | G_FILE_ATTRIBUTE_STANDARD_NAME | ||
4183 | 179 | |||
4184 | 180 | /* | ||
4185 | 181 | * Filters for MIME/media types to ignore. | ||
4186 | 182 | * The only complication here is that there are some application/ types that | ||
4187 | 183 | * are used for audio/video files. Otherwise, we'd ignore everything except | ||
4188 | 184 | * audio/ and video/. | ||
4189 | 185 | */ | ||
4190 | 186 | struct media_type_filter { | ||
4191 | 187 | const char *prefix; | ||
4192 | 188 | gboolean ignore; | ||
4193 | 189 | } media_type_filters[] = { | ||
4194 | 190 | { "image/", TRUE }, | ||
4195 | 191 | { "text/", TRUE }, | ||
4196 | 192 | { "application/ogg", FALSE }, | ||
4197 | 193 | { "application/x-id3", FALSE }, | ||
4198 | 194 | { "application/x-apetag", FALSE }, | ||
4199 | 195 | { "application/x-3gp", FALSE }, | ||
4200 | 196 | { "application/x-annodex", FALSE }, | ||
4201 | 197 | { "application/", TRUE }, | ||
4202 | 198 | }; | ||
4203 | 199 | |||
4204 | 200 | /* | ||
4205 | 201 | * File size below which we will simply ignore files that can't be identified. | ||
4206 | 202 | * This is mostly here so we ignore the various text files that are packaged | ||
4207 | 203 | * with many netlabel releases and other downloads. | ||
4208 | 204 | */ | ||
4209 | 205 | #define REALLY_SMALL_FILE_SIZE (4096) | ||
4210 | 206 | |||
4211 | 207 | |||
4212 | 208 | typedef struct | ||
4213 | 209 | { | ||
4214 | 210 | RhythmDB *db; | ||
4215 | 211 | GPtrArray *query; | ||
4216 | 212 | guint propid; | ||
4217 | 213 | RhythmDBQueryResults *results; | ||
4218 | 214 | gboolean cancel; | ||
4219 | 215 | } RhythmDBQueryThreadData; | ||
4220 | 216 | |||
4221 | 217 | typedef struct | ||
4222 | 218 | { | ||
4223 | 219 | RhythmDB *db; | ||
4224 | 220 | RhythmDBEntryType *type; | ||
4225 | 221 | RhythmDBEntryType *ignore_type; | ||
4226 | 222 | RhythmDBEntryType *error_type; | ||
4227 | 223 | } RhythmDBAddThreadData; | ||
4228 | 224 | |||
4229 | 225 | typedef struct | ||
4230 | 226 | { | ||
4231 | 227 | enum { | ||
4232 | 228 | RHYTHMDB_ACTION_STAT, | ||
4233 | 229 | RHYTHMDB_ACTION_LOAD, | ||
4234 | 230 | RHYTHMDB_ACTION_ENUM_DIR, | ||
4235 | 231 | RHYTHMDB_ACTION_SYNC, | ||
4236 | 232 | RHYTHMDB_ACTION_QUIT, | ||
4237 | 233 | } type; | ||
4238 | 234 | RBRefString *uri; | ||
4239 | 235 | union { | ||
4240 | 236 | struct { | ||
4241 | 237 | RhythmDBEntryType *entry_type; | ||
4242 | 238 | RhythmDBEntryType *ignore_type; | ||
4243 | 239 | RhythmDBEntryType *error_type; | ||
4244 | 240 | } types; | ||
4245 | 241 | GSList *changes; | ||
4246 | 242 | } data; | ||
4247 | 243 | } RhythmDBAction; | ||
4248 | 244 | |||
4249 | 245 | static void rhythmdb_dispose (GObject *object); | ||
4250 | 246 | static void rhythmdb_finalize (GObject *object); | ||
4251 | 247 | static void rhythmdb_set_property (GObject *object, | ||
4252 | 248 | guint prop_id, | ||
4253 | 249 | const GValue *value, | ||
4254 | 250 | GParamSpec *pspec); | ||
4255 | 251 | static void rhythmdb_get_property (GObject *object, | ||
4256 | 252 | guint prop_id, | ||
4257 | 253 | GValue *value, | ||
4258 | 254 | GParamSpec *pspec); | ||
4259 | 255 | static void rhythmdb_thread_create (RhythmDB *db, | ||
4260 | 256 | GThreadPool *pool, | ||
4261 | 257 | GThreadFunc func, | ||
4262 | 258 | gpointer data); | ||
4263 | 259 | static void rhythmdb_read_enter (RhythmDB *db); | ||
4264 | 260 | static void rhythmdb_read_leave (RhythmDB *db); | ||
4265 | 261 | static void rhythmdb_process_one_event (RhythmDBEvent *event, RhythmDB *db); | ||
4266 | 262 | static gpointer action_thread_main (RhythmDB *db); | ||
4267 | 263 | static gpointer query_thread_main (RhythmDBQueryThreadData *data); | ||
4268 | 264 | static void rhythmdb_entry_set_mount_point (RhythmDB *db, | ||
4269 | 265 | RhythmDBEntry *entry, | ||
4270 | 266 | const gchar *realuri); | ||
4271 | 267 | |||
4272 | 268 | static gboolean rhythmdb_idle_save (RhythmDB *db); | ||
4273 | 269 | static void db_settings_changed_cb (GSettings *settings, const char *key, RhythmDB *db); | ||
4274 | 270 | static void rhythmdb_sync_library_location (RhythmDB *db); | ||
4275 | 271 | static void rhythmdb_entry_sync_mirrored (RhythmDBEntry *entry, | ||
4276 | 272 | guint propid); | ||
4277 | 273 | static gboolean rhythmdb_entry_extra_metadata_accumulator (GSignalInvocationHint *ihint, | ||
4278 | 274 | GValue *return_accu, | ||
4279 | 275 | const GValue *handler_return, | ||
4280 | 276 | gpointer data); | ||
4281 | 277 | |||
4282 | 278 | static void rhythmdb_event_free (RhythmDB *db, RhythmDBEvent *event); | ||
4283 | 279 | static void rhythmdb_add_to_stat_list (RhythmDB *db, | ||
4284 | 280 | const char *uri, | ||
4285 | 281 | RhythmDBEntry *entry, | ||
4286 | 282 | RhythmDBEntryType *type, | ||
4287 | 283 | RhythmDBEntryType *ignore_type, | ||
4288 | 284 | RhythmDBEntryType *error_type); | ||
4289 | 285 | static void free_entry_changes (GSList *entry_changes); | ||
4290 | 286 | |||
4291 | 287 | static void perform_next_mount (RhythmDB *db); | ||
4292 | 288 | |||
4293 | 289 | enum | ||
4294 | 290 | { | ||
4295 | 291 | PROP_0, | ||
4296 | 292 | PROP_NAME, | ||
4297 | 293 | PROP_DRY_RUN, | ||
4298 | 294 | PROP_NO_UPDATE, | ||
4299 | 295 | }; | ||
4300 | 296 | |||
4301 | 297 | enum | ||
4302 | 298 | { | ||
4303 | 299 | ENTRY_ADDED, | ||
4304 | 300 | ENTRY_CHANGED, | ||
4305 | 301 | ENTRY_DELETED, | ||
4306 | 302 | ENTRY_KEYWORD_ADDED, | ||
4307 | 303 | ENTRY_KEYWORD_REMOVED, | ||
4308 | 304 | ENTRY_EXTRA_METADATA_REQUEST, | ||
4309 | 305 | ENTRY_EXTRA_METADATA_NOTIFY, | ||
4310 | 306 | ENTRY_EXTRA_METADATA_GATHER, | ||
4311 | 307 | LOAD_COMPLETE, | ||
4312 | 308 | SAVE_COMPLETE, | ||
4313 | 309 | SAVE_ERROR, | ||
4314 | 310 | READ_ONLY, | ||
4315 | 311 | CREATE_MOUNT_OP, | ||
4316 | 312 | LAST_SIGNAL | ||
4317 | 313 | }; | ||
4318 | 314 | |||
4319 | 315 | static guint rhythmdb_signals[LAST_SIGNAL] = { 0 }; | ||
4320 | 316 | |||
4321 | 317 | static void | ||
4322 | 318 | rhythmdb_class_init (RhythmDBClass *klass) | ||
4323 | 319 | { | ||
4324 | 320 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
4325 | 321 | |||
4326 | 322 | object_class->dispose = rhythmdb_dispose; | ||
4327 | 323 | object_class->finalize = rhythmdb_finalize; | ||
4328 | 324 | |||
4329 | 325 | object_class->set_property = rhythmdb_set_property; | ||
4330 | 326 | object_class->get_property = rhythmdb_get_property; | ||
4331 | 327 | |||
4332 | 328 | /** | ||
4333 | 329 | * RhythmDB:name | ||
4334 | 330 | * | ||
4335 | 331 | * Database name. Not sure whta this is used for. | ||
4336 | 332 | */ | ||
4337 | 333 | g_object_class_install_property (object_class, | ||
4338 | 334 | PROP_NAME, | ||
4339 | 335 | g_param_spec_string ("name", | ||
4340 | 336 | "name", | ||
4341 | 337 | "name", | ||
4342 | 338 | NULL, | ||
4343 | 339 | G_PARAM_READWRITE)); | ||
4344 | 340 | /** | ||
4345 | 341 | * RhythmDB:dry-run | ||
4346 | 342 | * | ||
4347 | 343 | * If %TRUE, no metadata changes will be written back to media fies. | ||
4348 | 344 | */ | ||
4349 | 345 | g_object_class_install_property (object_class, | ||
4350 | 346 | PROP_DRY_RUN, | ||
4351 | 347 | g_param_spec_boolean ("dry-run", | ||
4352 | 348 | "dry run", | ||
4353 | 349 | "Whether or not changes should be saved", | ||
4354 | 350 | FALSE, | ||
4355 | 351 | G_PARAM_READWRITE)); | ||
4356 | 352 | /** | ||
4357 | 353 | * RhythmDB:no-update | ||
4358 | 354 | * | ||
4359 | 355 | * If %TRUE, the database will not be updated. | ||
4360 | 356 | */ | ||
4361 | 357 | g_object_class_install_property (object_class, | ||
4362 | 358 | PROP_NO_UPDATE, | ||
4363 | 359 | g_param_spec_boolean ("no-update", | ||
4364 | 360 | "no update", | ||
4365 | 361 | "Whether or not to update the database", | ||
4366 | 362 | FALSE, | ||
4367 | 363 | G_PARAM_READWRITE)); | ||
4368 | 364 | /** | ||
4369 | 365 | * RhythmDB::entry-added: | ||
4370 | 366 | * @db: the #RhythmDB | ||
4371 | 367 | * @entry: the newly added #RhythmDBEntry | ||
4372 | 368 | * | ||
4373 | 369 | * Emitted when a new entry is added to the database. | ||
4374 | 370 | */ | ||
4375 | 371 | rhythmdb_signals[ENTRY_ADDED] = | ||
4376 | 372 | g_signal_new ("entry_added", | ||
4377 | 373 | RHYTHMDB_TYPE, | ||
4378 | 374 | G_SIGNAL_RUN_LAST, | ||
4379 | 375 | G_STRUCT_OFFSET (RhythmDBClass, entry_added), | ||
4380 | 376 | NULL, NULL, | ||
4381 | 377 | g_cclosure_marshal_VOID__BOXED, | ||
4382 | 378 | G_TYPE_NONE, | ||
4383 | 379 | 1, RHYTHMDB_TYPE_ENTRY); | ||
4384 | 380 | |||
4385 | 381 | /** | ||
4386 | 382 | * RhythmDB::entry-deleted: | ||
4387 | 383 | * @db: the #RhythmDB | ||
4388 | 384 | * @entry: the deleted #RhythmDBEntry | ||
4389 | 385 | * | ||
4390 | 386 | * Emitted when an entry is deleted from the database. | ||
4391 | 387 | */ | ||
4392 | 388 | rhythmdb_signals[ENTRY_DELETED] = | ||
4393 | 389 | g_signal_new ("entry_deleted", | ||
4394 | 390 | RHYTHMDB_TYPE, | ||
4395 | 391 | G_SIGNAL_RUN_LAST, | ||
4396 | 392 | G_STRUCT_OFFSET (RhythmDBClass, entry_deleted), | ||
4397 | 393 | NULL, NULL, | ||
4398 | 394 | g_cclosure_marshal_VOID__BOXED, | ||
4399 | 395 | G_TYPE_NONE, | ||
4400 | 396 | 1, RHYTHMDB_TYPE_ENTRY); | ||
4401 | 397 | |||
4402 | 398 | /** | ||
4403 | 399 | * RhythmDB::entry-changed: | ||
4404 | 400 | * @db: the #RhythmDB | ||
4405 | 401 | * @entry: the changed #RhythmDBEntry | ||
4406 | 402 | * @changes: a #GValueArray of #RhythmDBEntryChange structures describing the changes | ||
4407 | 403 | * | ||
4408 | 404 | * Emitted when a database entry is modified. The @changes list | ||
4409 | 405 | * contains a structure for each entry property that has been modified. | ||
4410 | 406 | */ | ||
4411 | 407 | rhythmdb_signals[ENTRY_CHANGED] = | ||
4412 | 408 | g_signal_new ("entry_changed", | ||
4413 | 409 | RHYTHMDB_TYPE, | ||
4414 | 410 | G_SIGNAL_RUN_LAST, | ||
4415 | 411 | G_STRUCT_OFFSET (RhythmDBClass, entry_changed), | ||
4416 | 412 | NULL, NULL, | ||
4417 | 413 | rb_marshal_VOID__BOXED_BOXED, | ||
4418 | 414 | G_TYPE_NONE, 2, | ||
4419 | 415 | RHYTHMDB_TYPE_ENTRY, G_TYPE_VALUE_ARRAY); | ||
4420 | 416 | |||
4421 | 417 | /** | ||
4422 | 418 | * RhythmDB::entry-keyword-added: | ||
4423 | 419 | * @db: the #RhythmDB | ||
4424 | 420 | * @entry: the #RhythmDBEntry to which a keyword has been added | ||
4425 | 421 | * @keyword: the keyword that was added | ||
4426 | 422 | * | ||
4427 | 423 | * Emitted when a keyword is added to an entry. | ||
4428 | 424 | */ | ||
4429 | 425 | rhythmdb_signals[ENTRY_KEYWORD_ADDED] = | ||
4430 | 426 | g_signal_new ("entry_keyword_added", | ||
4431 | 427 | RHYTHMDB_TYPE, | ||
4432 | 428 | G_SIGNAL_RUN_LAST, | ||
4433 | 429 | G_STRUCT_OFFSET (RhythmDBClass, entry_added), | ||
4434 | 430 | NULL, NULL, | ||
4435 | 431 | rb_marshal_VOID__BOXED_BOXED, | ||
4436 | 432 | G_TYPE_NONE, | ||
4437 | 433 | 2, RHYTHMDB_TYPE_ENTRY, RB_TYPE_REFSTRING); | ||
4438 | 434 | |||
4439 | 435 | /** | ||
4440 | 436 | * RhythmDB::entry-keyword-removed: | ||
4441 | 437 | * @db: the #RhythmDB | ||
4442 | 438 | * @entry: the #RhythmDBEntry from which a keyword has been removed | ||
4443 | 439 | * @keyword: the keyword that was removed | ||
4444 | 440 | * | ||
4445 | 441 | * Emitted when a keyword is removed from an entry. | ||
4446 | 442 | */ | ||
4447 | 443 | rhythmdb_signals[ENTRY_KEYWORD_REMOVED] = | ||
4448 | 444 | g_signal_new ("entry_keyword_removed", | ||
4449 | 445 | RHYTHMDB_TYPE, | ||
4450 | 446 | G_SIGNAL_RUN_LAST, | ||
4451 | 447 | G_STRUCT_OFFSET (RhythmDBClass, entry_deleted), | ||
4452 | 448 | NULL, NULL, | ||
4453 | 449 | rb_marshal_VOID__BOXED_BOXED, | ||
4454 | 450 | G_TYPE_NONE, | ||
4455 | 451 | 2, RHYTHMDB_TYPE_ENTRY, RB_TYPE_REFSTRING); | ||
4456 | 452 | |||
4457 | 453 | /** | ||
4458 | 454 | * RhythmDB::entry-extra-metadata-request: | ||
4459 | 455 | * @db: the #RhythmDB | ||
4460 | 456 | * @entry: the #RhythmDBEntry for which extra metadata is being requested | ||
4461 | 457 | * | ||
4462 | 458 | * This signal is emitted to allow extra (transient) metadata to be supplied | ||
4463 | 459 | * for the given entry. The detail of the signal invocation describes the | ||
4464 | 460 | * specific metadata value being requested. If the object handling the signal | ||
4465 | 461 | * can provide the requested item, but it isn't immediately available, it can | ||
4466 | 462 | * initiate an attempt to retrieve it. If successful, it would call | ||
4467 | 463 | * @rhythmdb_emit_entry_extra_metadata_notify when the metadata is available. | ||
4468 | 464 | * | ||
4469 | 465 | * Return value: the extra metadata value | ||
4470 | 466 | */ | ||
4471 | 467 | rhythmdb_signals[ENTRY_EXTRA_METADATA_REQUEST] = | ||
4472 | 468 | g_signal_new ("entry_extra_metadata_request", | ||
4473 | 469 | G_OBJECT_CLASS_TYPE (object_class), | ||
4474 | 470 | G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, | ||
4475 | 471 | G_STRUCT_OFFSET (RhythmDBClass, entry_extra_metadata_request), | ||
4476 | 472 | rhythmdb_entry_extra_metadata_accumulator, NULL, | ||
4477 | 473 | rb_marshal_BOXED__BOXED, | ||
4478 | 474 | G_TYPE_VALUE, 1, | ||
4479 | 475 | RHYTHMDB_TYPE_ENTRY); | ||
4480 | 476 | |||
4481 | 477 | /** | ||
4482 | 478 | * RhythmDB::entry-extra-metadata-notify: | ||
4483 | 479 | * @db: the #RhythmDB | ||
4484 | 480 | * @entry: the #RhythmDBEntry for which extra metadata has been supplied | ||
4485 | 481 | * @field: the extra metadata field being supplied | ||
4486 | 482 | * @metadata: the extra metadata value | ||
4487 | 483 | * | ||
4488 | 484 | * This signal is emitted when an extra metadata value is provided for a specific | ||
4489 | 485 | * entry independantly of an extra metadata request. | ||
4490 | 486 | */ | ||
4491 | 487 | rhythmdb_signals[ENTRY_EXTRA_METADATA_NOTIFY] = | ||
4492 | 488 | g_signal_new ("entry_extra_metadata_notify", | ||
4493 | 489 | G_OBJECT_CLASS_TYPE (object_class), | ||
4494 | 490 | G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, | ||
4495 | 491 | G_STRUCT_OFFSET (RhythmDBClass, entry_extra_metadata_notify), | ||
4496 | 492 | NULL, NULL, | ||
4497 | 493 | rb_marshal_VOID__BOXED_STRING_BOXED, | ||
4498 | 494 | G_TYPE_NONE, 3, | ||
4499 | 495 | RHYTHMDB_TYPE_ENTRY, G_TYPE_STRING, G_TYPE_VALUE); | ||
4500 | 496 | |||
4501 | 497 | /** | ||
4502 | 498 | * RhythmDB::entry-extra-metadata-gather: | ||
4503 | 499 | * @db: the #RhythmDB | ||
4504 | 500 | * @entry: the #RhythmDBEntry for which to gather metadata | ||
4505 | 501 | * @data: a #RBStringValueMap to hold the gathered metadata | ||
4506 | 502 | * | ||
4507 | 503 | * Emitted to gather all available extra metadata for a database entry. | ||
4508 | 504 | * Handlers for this signal should insert any metadata they can provide | ||
4509 | 505 | * into the string-value map. Only immediately available metadata | ||
4510 | 506 | * items should be returned. If one or more metadata items is not | ||
4511 | 507 | * immediately available, the handler should not initiate an attempt to | ||
4512 | 508 | * retrieve them. | ||
4513 | 509 | */ | ||
4514 | 510 | rhythmdb_signals[ENTRY_EXTRA_METADATA_GATHER] = | ||
4515 | 511 | g_signal_new ("entry_extra_metadata_gather", | ||
4516 | 512 | G_OBJECT_CLASS_TYPE (object_class), | ||
4517 | 513 | G_SIGNAL_RUN_LAST, | ||
4518 | 514 | G_STRUCT_OFFSET (RhythmDBClass, entry_extra_metadata_gather), | ||
4519 | 515 | NULL, NULL, | ||
4520 | 516 | rb_marshal_VOID__BOXED_OBJECT, | ||
4521 | 517 | G_TYPE_NONE, 2, | ||
4522 | 518 | RHYTHMDB_TYPE_ENTRY, RB_TYPE_STRING_VALUE_MAP); | ||
4523 | 519 | |||
4524 | 520 | /** | ||
4525 | 521 | * RhythmDB::load-complete: | ||
4526 | 522 | * @db: the #RhythmDB | ||
4527 | 523 | * | ||
4528 | 524 | * Emitted when the database is fully loaded. | ||
4529 | 525 | */ | ||
4530 | 526 | rhythmdb_signals[LOAD_COMPLETE] = | ||
4531 | 527 | g_signal_new ("load_complete", | ||
4532 | 528 | RHYTHMDB_TYPE, | ||
4533 | 529 | G_SIGNAL_RUN_LAST, | ||
4534 | 530 | G_STRUCT_OFFSET (RhythmDBClass, load_complete), | ||
4535 | 531 | NULL, NULL, | ||
4536 | 532 | g_cclosure_marshal_VOID__VOID, | ||
4537 | 533 | G_TYPE_NONE, | ||
4538 | 534 | 0); | ||
4539 | 535 | |||
4540 | 536 | /** | ||
4541 | 537 | * RhythmDB::save-complete: | ||
4542 | 538 | * @db: the #RhythmDB | ||
4543 | 539 | * | ||
4544 | 540 | * Emitted when the database has been saved. | ||
4545 | 541 | */ | ||
4546 | 542 | rhythmdb_signals[SAVE_COMPLETE] = | ||
4547 | 543 | g_signal_new ("save_complete", | ||
4548 | 544 | RHYTHMDB_TYPE, | ||
4549 | 545 | G_SIGNAL_RUN_LAST, | ||
4550 | 546 | G_STRUCT_OFFSET (RhythmDBClass, save_complete), | ||
4551 | 547 | NULL, NULL, | ||
4552 | 548 | g_cclosure_marshal_VOID__VOID, | ||
4553 | 549 | G_TYPE_NONE, | ||
4554 | 550 | 0); | ||
4555 | 551 | |||
4556 | 552 | /** | ||
4557 | 553 | * RhythmDB::save-error: | ||
4558 | 554 | * @db: the #RhythmDB | ||
4559 | 555 | * @uri: URI of the database file | ||
4560 | 556 | * @error: the error that occurred | ||
4561 | 557 | * | ||
4562 | 558 | * Emitted when an error occurs while saving the database. | ||
4563 | 559 | */ | ||
4564 | 560 | rhythmdb_signals[SAVE_ERROR] = | ||
4565 | 561 | g_signal_new ("save-error", | ||
4566 | 562 | G_OBJECT_CLASS_TYPE (object_class), | ||
4567 | 563 | G_SIGNAL_RUN_LAST, | ||
4568 | 564 | G_STRUCT_OFFSET (RhythmDBClass, save_error), | ||
4569 | 565 | NULL, NULL, | ||
4570 | 566 | rb_marshal_VOID__STRING_POINTER, | ||
4571 | 567 | G_TYPE_NONE, | ||
4572 | 568 | 2, | ||
4573 | 569 | G_TYPE_STRING, | ||
4574 | 570 | G_TYPE_POINTER); | ||
4575 | 571 | |||
4576 | 572 | /** | ||
4577 | 573 | * RhythmDB::read-only: | ||
4578 | 574 | * @db: the #RhythmDB | ||
4579 | 575 | * @readonly: %TRUE if the database is read-only | ||
4580 | 576 | * | ||
4581 | 577 | * Emitted when the database becomes temporarily read-only, or becomes | ||
4582 | 578 | * writeable after being read-only. | ||
4583 | 579 | */ | ||
4584 | 580 | rhythmdb_signals[READ_ONLY] = | ||
4585 | 581 | g_signal_new ("read-only", | ||
4586 | 582 | G_OBJECT_CLASS_TYPE (object_class), | ||
4587 | 583 | G_SIGNAL_RUN_LAST, | ||
4588 | 584 | G_STRUCT_OFFSET (RhythmDBClass, read_only), | ||
4589 | 585 | NULL, NULL, | ||
4590 | 586 | g_cclosure_marshal_VOID__BOOLEAN, | ||
4591 | 587 | G_TYPE_NONE, | ||
4592 | 588 | 1, | ||
4593 | 589 | G_TYPE_BOOLEAN); | ||
4594 | 590 | |||
4595 | 591 | /** | ||
4596 | 592 | * RhythmDB::create-mount-op: | ||
4597 | 593 | * @db: the #RhythmDB | ||
4598 | 594 | * | ||
4599 | 595 | * Emitted to request creation of a #GMountOperation to use to mount a volume. | ||
4600 | 596 | * | ||
4601 | 597 | * Returns: (transfer full): a #GMountOperation (usually actually a #GtkMountOperation) | ||
4602 | 598 | */ | ||
4603 | 599 | rhythmdb_signals[CREATE_MOUNT_OP] = | ||
4604 | 600 | g_signal_new ("create-mount-op", | ||
4605 | 601 | G_OBJECT_CLASS_TYPE (object_class), | ||
4606 | 602 | G_SIGNAL_RUN_LAST, | ||
4607 | 603 | 0, /* no need for an internal handler */ | ||
4608 | 604 | rb_signal_accumulator_object_handled, NULL, | ||
4609 | 605 | rb_marshal_OBJECT__VOID, | ||
4610 | 606 | G_TYPE_MOUNT_OPERATION, | ||
4611 | 607 | 0); | ||
4612 | 608 | |||
4613 | 609 | g_type_class_add_private (klass, sizeof (RhythmDBPrivate)); | ||
4614 | 610 | } | ||
4615 | 611 | |||
4616 | 612 | static void | ||
4617 | 613 | rhythmdb_push_event (RhythmDB *db, RhythmDBEvent *event) | ||
4618 | 614 | { | ||
4619 | 615 | g_async_queue_push (db->priv->event_queue, event); | ||
4620 | 616 | g_main_context_wakeup (g_main_context_default ()); | ||
4621 | 617 | } | ||
4622 | 618 | |||
4623 | 619 | static gboolean | ||
4624 | 620 | metadata_field_from_prop (RhythmDBPropType prop, | ||
4625 | 621 | RBMetaDataField *field) | ||
4626 | 622 | { | ||
4627 | 623 | switch (prop) { | ||
4628 | 624 | case RHYTHMDB_PROP_TITLE: | ||
4629 | 625 | *field = RB_METADATA_FIELD_TITLE; | ||
4630 | 626 | return TRUE; | ||
4631 | 627 | case RHYTHMDB_PROP_ARTIST: | ||
4632 | 628 | *field = RB_METADATA_FIELD_ARTIST; | ||
4633 | 629 | return TRUE; | ||
4634 | 630 | case RHYTHMDB_PROP_ALBUM: | ||
4635 | 631 | *field = RB_METADATA_FIELD_ALBUM; | ||
4636 | 632 | return TRUE; | ||
4637 | 633 | case RHYTHMDB_PROP_GENRE: | ||
4638 | 634 | *field = RB_METADATA_FIELD_GENRE; | ||
4639 | 635 | return TRUE; | ||
4640 | 636 | case RHYTHMDB_PROP_COMMENT: | ||
4641 | 637 | *field = RB_METADATA_FIELD_COMMENT; | ||
4642 | 638 | return TRUE; | ||
4643 | 639 | case RHYTHMDB_PROP_TRACK_NUMBER: | ||
4644 | 640 | *field = RB_METADATA_FIELD_TRACK_NUMBER; | ||
4645 | 641 | return TRUE; | ||
4646 | 642 | case RHYTHMDB_PROP_DISC_NUMBER: | ||
4647 | 643 | *field = RB_METADATA_FIELD_DISC_NUMBER; | ||
4648 | 644 | return TRUE; | ||
4649 | 645 | case RHYTHMDB_PROP_DATE: | ||
4650 | 646 | *field = RB_METADATA_FIELD_DATE; | ||
4651 | 647 | return TRUE; | ||
4652 | 648 | case RHYTHMDB_PROP_BPM: | ||
4653 | 649 | *field = RB_METADATA_FIELD_BPM; | ||
4654 | 650 | return TRUE; | ||
4655 | 651 | case RHYTHMDB_PROP_MUSICBRAINZ_TRACKID: | ||
4656 | 652 | *field = RB_METADATA_FIELD_MUSICBRAINZ_TRACKID; | ||
4657 | 653 | return TRUE; | ||
4658 | 654 | case RHYTHMDB_PROP_MUSICBRAINZ_ARTISTID: | ||
4659 | 655 | *field = RB_METADATA_FIELD_MUSICBRAINZ_ARTISTID; | ||
4660 | 656 | return TRUE; | ||
4661 | 657 | case RHYTHMDB_PROP_MUSICBRAINZ_ALBUMID: | ||
4662 | 658 | *field = RB_METADATA_FIELD_MUSICBRAINZ_ALBUMID; | ||
4663 | 659 | return TRUE; | ||
4664 | 660 | case RHYTHMDB_PROP_MUSICBRAINZ_ALBUMARTISTID: | ||
4665 | 661 | *field = RB_METADATA_FIELD_MUSICBRAINZ_ALBUMARTISTID; | ||
4666 | 662 | return TRUE; | ||
4667 | 663 | case RHYTHMDB_PROP_ARTIST_SORTNAME: | ||
4668 | 664 | *field = RB_METADATA_FIELD_ARTIST_SORTNAME; | ||
4669 | 665 | return TRUE; | ||
4670 | 666 | case RHYTHMDB_PROP_ALBUM_SORTNAME: | ||
4671 | 667 | *field = RB_METADATA_FIELD_ALBUM_SORTNAME; | ||
4672 | 668 | return TRUE; | ||
4673 | 669 | case RHYTHMDB_PROP_ALBUM_ARTIST: | ||
4674 | 670 | *field = RB_METADATA_FIELD_ALBUM_ARTIST; | ||
4675 | 671 | return TRUE; | ||
4676 | 672 | case RHYTHMDB_PROP_ALBUM_ARTIST_SORTNAME: | ||
4677 | 673 | *field = RB_METADATA_FIELD_ALBUM_ARTIST_SORTNAME; | ||
4678 | 674 | return TRUE; | ||
4679 | 675 | default: | ||
4680 | 676 | return FALSE; | ||
4681 | 677 | } | ||
4682 | 678 | } | ||
4683 | 679 | |||
4684 | 680 | static void | ||
4685 | 681 | rhythmdb_init (RhythmDB *db) | ||
4686 | 682 | { | ||
4687 | 683 | guint i; | ||
4688 | 684 | GEnumClass *prop_class; | ||
4689 | 685 | |||
4690 | 686 | db->priv = RHYTHMDB_GET_PRIVATE (db); | ||
4691 | 687 | |||
4692 | 688 | db->priv->settings = g_settings_new ("org.gnome.rhythmbox.rhythmdb"); | ||
4693 | 689 | g_signal_connect_object (db->priv->settings, "changed", G_CALLBACK (db_settings_changed_cb), db, 0); | ||
4694 | 690 | |||
4695 | 691 | db->priv->action_queue = g_async_queue_new (); | ||
4696 | 692 | db->priv->event_queue = g_async_queue_new (); | ||
4697 | 693 | db->priv->delayed_write_queue = g_async_queue_new (); | ||
4698 | 694 | db->priv->event_queue_watch_id = rb_async_queue_watch_new (db->priv->event_queue, | ||
4699 | 695 | G_PRIORITY_LOW, /* really? */ | ||
4700 | 696 | (RBAsyncQueueWatchFunc) rhythmdb_process_one_event, | ||
4701 | 697 | db, | ||
4702 | 698 | NULL, | ||
4703 | 699 | NULL); | ||
4704 | 700 | |||
4705 | 701 | db->priv->restored_queue = g_async_queue_new (); | ||
4706 | 702 | |||
4707 | 703 | db->priv->query_thread_pool = g_thread_pool_new ((GFunc)query_thread_main, | ||
4708 | 704 | NULL, | ||
4709 | 705 | -1, FALSE, NULL); | ||
4710 | 706 | |||
4711 | 707 | db->priv->metadata = rb_metadata_new (); | ||
4712 | 708 | |||
4713 | 709 | prop_class = g_type_class_ref (RHYTHMDB_TYPE_PROP_TYPE); | ||
4714 | 710 | |||
4715 | 711 | g_assert (prop_class->n_values == RHYTHMDB_NUM_PROPERTIES); | ||
4716 | 712 | |||
4717 | 713 | g_type_class_unref (prop_class); | ||
4718 | 714 | |||
4719 | 715 | db->priv->propname_map = g_hash_table_new (g_str_hash, g_str_equal); | ||
4720 | 716 | |||
4721 | 717 | for (i = 0; i < RHYTHMDB_NUM_PROPERTIES; i++) { | ||
4722 | 718 | const xmlChar *name = rhythmdb_nice_elt_name_from_propid (db, i); | ||
4723 | 719 | g_hash_table_insert (db->priv->propname_map, (gpointer) name, GINT_TO_POINTER (i)); | ||
4724 | 720 | } | ||
4725 | 721 | |||
4726 | 722 | db->priv->entry_type_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); | ||
4727 | 723 | db->priv->entry_type_map_mutex = g_mutex_new (); | ||
4728 | 724 | db->priv->entry_type_mutex = g_mutex_new (); | ||
4729 | 725 | |||
4730 | 726 | rhythmdb_register_song_entry_types (db); | ||
4731 | 727 | rb_podcast_register_entry_types (db); | ||
4732 | 728 | |||
4733 | 729 | db->priv->stat_mutex = g_mutex_new (); | ||
4734 | 730 | |||
4735 | 731 | db->priv->change_mutex = g_mutex_new (); | ||
4736 | 732 | |||
4737 | 733 | db->priv->changed_entries = g_hash_table_new_full (NULL, | ||
4738 | 734 | NULL, | ||
4739 | 735 | (GDestroyNotify) rhythmdb_entry_unref, | ||
4740 | 736 | NULL); | ||
4741 | 737 | db->priv->added_entries = g_hash_table_new_full (NULL, | ||
4742 | 738 | NULL, | ||
4743 | 739 | (GDestroyNotify) rhythmdb_entry_unref, | ||
4744 | 740 | NULL); | ||
4745 | 741 | db->priv->deleted_entries = g_hash_table_new_full (NULL, | ||
4746 | 742 | NULL, | ||
4747 | 743 | (GDestroyNotify) rhythmdb_entry_unref, | ||
4748 | 744 | NULL); | ||
4749 | 745 | |||
4750 | 746 | db->priv->saving_condition = g_cond_new (); | ||
4751 | 747 | db->priv->saving_mutex = g_mutex_new (); | ||
4752 | 748 | |||
4753 | 749 | db->priv->can_save = TRUE; | ||
4754 | 750 | db->priv->exiting = g_cancellable_new (); | ||
4755 | 751 | db->priv->saving = FALSE; | ||
4756 | 752 | db->priv->dirty = FALSE; | ||
4757 | 753 | |||
4758 | 754 | db->priv->empty_string = rb_refstring_new (""); | ||
4759 | 755 | db->priv->octet_stream_str = rb_refstring_new ("application/octet-stream"); | ||
4760 | 756 | |||
4761 | 757 | db->priv->next_entry_id = 1; | ||
4762 | 758 | |||
4763 | 759 | rhythmdb_init_monitoring (db); | ||
4764 | 760 | |||
4765 | 761 | rhythmdb_dbus_register (db); | ||
4766 | 762 | } | ||
4767 | 763 | |||
4768 | 764 | static GError * | ||
4769 | 765 | make_access_failed_error (const char *uri, GError *access_error) | ||
4770 | 766 | { | ||
4771 | 767 | char *unescaped; | ||
4772 | 768 | char *utf8ised; | ||
4773 | 769 | GError *error; | ||
4774 | 770 | |||
4775 | 771 | /* make sure the URI we put in the error message is valid utf8 */ | ||
4776 | 772 | unescaped = g_uri_unescape_string (uri, NULL); | ||
4777 | 773 | utf8ised = rb_make_valid_utf8 (unescaped, '?'); | ||
4778 | 774 | |||
4779 | 775 | error = g_error_new (RHYTHMDB_ERROR, | ||
4780 | 776 | RHYTHMDB_ERROR_ACCESS_FAILED, | ||
4781 | 777 | _("Couldn't access %s: %s"), | ||
4782 | 778 | utf8ised, | ||
4783 | 779 | access_error->message); | ||
4784 | 780 | rb_debug ("got error on %s: %s", uri, error->message); | ||
4785 | 781 | g_free (unescaped); | ||
4786 | 782 | g_free (utf8ised); | ||
4787 | 783 | return error; | ||
4788 | 784 | } | ||
4789 | 785 | |||
4790 | 786 | static gboolean | ||
4791 | 787 | rhythmdb_ignore_media_type (const char *media_type) | ||
4792 | 788 | { | ||
4793 | 789 | int i; | ||
4794 | 790 | |||
4795 | 791 | for (i = 0; i < G_N_ELEMENTS (media_type_filters); i++) { | ||
4796 | 792 | if (g_str_has_prefix (media_type, media_type_filters[i].prefix)) { | ||
4797 | 793 | return media_type_filters[i].ignore; | ||
4798 | 794 | } | ||
4799 | 795 | } | ||
4800 | 796 | return FALSE; | ||
4801 | 797 | } | ||
4802 | 798 | |||
4803 | 799 | typedef struct { | ||
4804 | 800 | RhythmDB *db; | ||
4805 | 801 | GList *stat_list; | ||
4806 | 802 | } RhythmDBStatThreadData; | ||
4807 | 803 | |||
4808 | 804 | static gpointer | ||
4809 | 805 | stat_thread_main (RhythmDBStatThreadData *data) | ||
4810 | 806 | { | ||
4811 | 807 | GList *i; | ||
4812 | 808 | GError *error = NULL; | ||
4813 | 809 | RhythmDBEvent *result; | ||
4814 | 810 | |||
4815 | 811 | data->db->priv->stat_thread_count = g_list_length (data->stat_list); | ||
4816 | 812 | data->db->priv->stat_thread_done = 0; | ||
4817 | 813 | |||
4818 | 814 | rb_debug ("entering stat thread: %d to process", data->db->priv->stat_thread_count); | ||
4819 | 815 | for (i = data->stat_list; i != NULL; i = i->next) { | ||
4820 | 816 | RhythmDBEvent *event = (RhythmDBEvent *)i->data; | ||
4821 | 817 | GFile *file; | ||
4822 | 818 | |||
4823 | 819 | /* if we've been cancelled, just free the event. this will | ||
4824 | 820 | * clean up the list and then we'll exit the thread. | ||
4825 | 821 | */ | ||
4826 | 822 | if (g_cancellable_is_cancelled (data->db->priv->exiting)) { | ||
4827 | 823 | rhythmdb_event_free (data->db, event); | ||
4828 | 824 | continue; | ||
4829 | 825 | } | ||
4830 | 826 | |||
4831 | 827 | if (data->db->priv->stat_thread_done > 0 && | ||
4832 | 828 | data->db->priv->stat_thread_done % 1000 == 0) { | ||
4833 | 829 | rb_debug ("%d file info queries done", | ||
4834 | 830 | data->db->priv->stat_thread_done); | ||
4835 | 831 | } | ||
4836 | 832 | |||
4837 | 833 | file = g_file_new_for_uri (rb_refstring_get (event->uri)); | ||
4838 | 834 | event->real_uri = rb_refstring_ref (event->uri); /* what? */ | ||
4839 | 835 | event->file_info = g_file_query_info (file, | ||
4840 | 836 | G_FILE_ATTRIBUTE_TIME_MODIFIED, /* anything else? */ | ||
4841 | 837 | G_FILE_QUERY_INFO_NONE, | ||
4842 | 838 | data->db->priv->exiting, | ||
4843 | 839 | &error); | ||
4844 | 840 | if (error != NULL) { | ||
4845 | 841 | event->error = make_access_failed_error (rb_refstring_get (event->uri), error); | ||
4846 | 842 | g_clear_error (&error); | ||
4847 | 843 | |||
4848 | 844 | if (event->file_info != NULL) { | ||
4849 | 845 | g_object_unref (event->file_info); | ||
4850 | 846 | event->file_info = NULL; | ||
4851 | 847 | } | ||
4852 | 848 | } | ||
4853 | 849 | |||
4854 | 850 | g_async_queue_push (data->db->priv->event_queue, event); | ||
4855 | 851 | g_object_unref (file); | ||
4856 | 852 | g_atomic_int_inc (&data->db->priv->stat_thread_done); | ||
4857 | 853 | } | ||
4858 | 854 | |||
4859 | 855 | g_list_free (data->stat_list); | ||
4860 | 856 | |||
4861 | 857 | data->db->priv->stat_thread_running = FALSE; | ||
4862 | 858 | |||
4863 | 859 | rb_debug ("exiting stat thread"); | ||
4864 | 860 | result = g_slice_new0 (RhythmDBEvent); | ||
4865 | 861 | result->db = data->db; /* need to unref? */ | ||
4866 | 862 | result->type = RHYTHMDB_EVENT_THREAD_EXITED; | ||
4867 | 863 | rhythmdb_push_event (data->db, result); | ||
4868 | 864 | |||
4869 | 865 | g_free (data); | ||
4870 | 866 | return NULL; | ||
4871 | 867 | } | ||
4872 | 868 | |||
4873 | 869 | static void | ||
4874 | 870 | perform_next_mount_cb (GObject *file, GAsyncResult *res, RhythmDB *db) | ||
4875 | 871 | { | ||
4876 | 872 | GError *error = NULL; | ||
4877 | 873 | |||
4878 | 874 | g_file_mount_enclosing_volume_finish (G_FILE (file), res, &error); | ||
4879 | 875 | if (error != NULL) { | ||
4880 | 876 | char *uri; | ||
4881 | 877 | |||
4882 | 878 | uri = g_file_get_uri (G_FILE (file)); | ||
4883 | 879 | rb_debug ("Unable to mount %s: %s", uri, error->message); | ||
4884 | 880 | g_free (uri); | ||
4885 | 881 | g_clear_error (&error); | ||
4886 | 882 | } | ||
4887 | 883 | g_object_unref (file); | ||
4888 | 884 | |||
4889 | 885 | perform_next_mount (db); | ||
4890 | 886 | } | ||
4891 | 887 | |||
4892 | 888 | static void | ||
4893 | 889 | perform_next_mount (RhythmDB *db) | ||
4894 | 890 | { | ||
4895 | 891 | GList *l; | ||
4896 | 892 | char *mountpoint; | ||
4897 | 893 | GMountOperation *mount_op = NULL; | ||
4898 | 894 | |||
4899 | 895 | if (db->priv->mount_list == NULL) { | ||
4900 | 896 | rb_debug ("finished mounting"); | ||
4901 | 897 | return; | ||
4902 | 898 | } | ||
4903 | 899 | |||
4904 | 900 | l = db->priv->mount_list; | ||
4905 | 901 | db->priv->mount_list = db->priv->mount_list->next; | ||
4906 | 902 | mountpoint = l->data; | ||
4907 | 903 | g_list_free1 (l); | ||
4908 | 904 | |||
4909 | 905 | rb_debug ("mounting %s", (char *)mountpoint); | ||
4910 | 906 | g_signal_emit (G_OBJECT (db), rhythmdb_signals[CREATE_MOUNT_OP], 0, &mount_op); | ||
4911 | 907 | g_file_mount_enclosing_volume (g_file_new_for_uri (mountpoint), | ||
4912 | 908 | G_MOUNT_MOUNT_NONE, | ||
4913 | 909 | mount_op, | ||
4914 | 910 | db->priv->exiting, | ||
4915 | 911 | (GAsyncReadyCallback) perform_next_mount_cb, | ||
4916 | 912 | db); | ||
4917 | 913 | } | ||
4918 | 914 | |||
4919 | 915 | /** | ||
4920 | 916 | * rhythmdb_start_action_thread: | ||
4921 | 917 | * @db: the #RhythmDB | ||
4922 | 918 | * | ||
4923 | 919 | * Starts the #RhythmDB processing thread. Needs to be called during startup. | ||
4924 | 920 | */ | ||
4925 | 921 | void | ||
4926 | 922 | rhythmdb_start_action_thread (RhythmDB *db) | ||
4927 | 923 | { | ||
4928 | 924 | g_mutex_lock (db->priv->stat_mutex); | ||
4929 | 925 | db->priv->action_thread_running = TRUE; | ||
4930 | 926 | rhythmdb_thread_create (db, NULL, (GThreadFunc) action_thread_main, db); | ||
4931 | 927 | |||
4932 | 928 | if (db->priv->stat_list != NULL) { | ||
4933 | 929 | RhythmDBStatThreadData *data; | ||
4934 | 930 | data = g_new0 (RhythmDBStatThreadData, 1); | ||
4935 | 931 | data->db = g_object_ref (db); | ||
4936 | 932 | data->stat_list = db->priv->stat_list; | ||
4937 | 933 | db->priv->stat_list = NULL; | ||
4938 | 934 | |||
4939 | 935 | db->priv->stat_thread_running = TRUE; | ||
4940 | 936 | rhythmdb_thread_create (db, NULL, (GThreadFunc) stat_thread_main, data); | ||
4941 | 937 | } | ||
4942 | 938 | |||
4943 | 939 | perform_next_mount (db); | ||
4944 | 940 | |||
4945 | 941 | g_mutex_unlock (db->priv->stat_mutex); | ||
4946 | 942 | } | ||
4947 | 943 | |||
4948 | 944 | static void | ||
4949 | 945 | rhythmdb_action_free (RhythmDB *db, | ||
4950 | 946 | RhythmDBAction *action) | ||
4951 | 947 | { | ||
4952 | 948 | rb_refstring_unref (action->uri); | ||
4953 | 949 | if (action->type == RHYTHMDB_ACTION_SYNC) { | ||
4954 | 950 | free_entry_changes (action->data.changes); | ||
4955 | 951 | } | ||
4956 | 952 | g_slice_free (RhythmDBAction, action); | ||
4957 | 953 | } | ||
4958 | 954 | |||
4959 | 955 | static void | ||
4960 | 956 | rhythmdb_event_free (RhythmDB *db, | ||
4961 | 957 | RhythmDBEvent *result) | ||
4962 | 958 | { | ||
4963 | 959 | switch (result->type) { | ||
4964 | 960 | case RHYTHMDB_EVENT_THREAD_EXITED: | ||
4965 | 961 | g_object_unref (db); | ||
4966 | 962 | g_assert (g_atomic_int_dec_and_test (&db->priv->outstanding_threads) >= 0); | ||
4967 | 963 | g_async_queue_unref (db->priv->action_queue); | ||
4968 | 964 | g_async_queue_unref (db->priv->event_queue); | ||
4969 | 965 | break; | ||
4970 | 966 | case RHYTHMDB_EVENT_STAT: | ||
4971 | 967 | case RHYTHMDB_EVENT_METADATA_LOAD: | ||
4972 | 968 | case RHYTHMDB_EVENT_DB_LOAD: | ||
4973 | 969 | case RHYTHMDB_EVENT_DB_SAVED: | ||
4974 | 970 | case RHYTHMDB_EVENT_QUERY_COMPLETE: | ||
4975 | 971 | break; | ||
4976 | 972 | case RHYTHMDB_EVENT_ENTRY_SET: | ||
4977 | 973 | g_value_unset (&result->change.new); | ||
4978 | 974 | break; | ||
4979 | 975 | } | ||
4980 | 976 | if (result->error) | ||
4981 | 977 | g_error_free (result->error); | ||
4982 | 978 | rb_refstring_unref (result->uri); | ||
4983 | 979 | rb_refstring_unref (result->real_uri); | ||
4984 | 980 | if (result->file_info) | ||
4985 | 981 | g_object_unref (result->file_info); | ||
4986 | 982 | if (result->metadata) | ||
4987 | 983 | g_object_unref (result->metadata); | ||
4988 | 984 | if (result->results) | ||
4989 | 985 | g_object_unref (result->results); | ||
4990 | 986 | if (result->entry != NULL) { | ||
4991 | 987 | rhythmdb_entry_unref (result->entry); | ||
4992 | 988 | } | ||
4993 | 989 | g_slice_free (RhythmDBEvent, result); | ||
4994 | 990 | } | ||
4995 | 991 | |||
4996 | 992 | static void | ||
4997 | 993 | _shutdown_foreach_swapped (RhythmDBEvent *event, RhythmDB *db) | ||
4998 | 994 | { | ||
4999 | 995 | rhythmdb_event_free (db, event); | ||
5000 | 996 | } |
Thank you for your work, the update has been uploaded and is waiting for SRU team review in the queue