1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2003 Jeffrey Yasskin <jyasskin@mail.utexas.edu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The Rhythmbox authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Rhythmbox. This permission is above and beyond the permissions granted
* by the GPL license by which Rhythmbox is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include "config.h"
#include <string.h>
#include <glib/gi18n.h>
#include "rb-play-order.h"
#include "rb-shell-player.h"
#include "rb-debug.h"
/**
* SECTION:rbplayorder
* @short_description: base class for play order implementations
*
* A play order defines an ordering of the entries from a #RhythmDBQueryModel that
* the #RBShellPlayer uses to get the next or previous entry to play.
*
* Play order methods are invoked when changes are made to the query model, when
* the query model is replaced, the playing source is changed, or a new playing
* entry is selected.
*
* The play order must implement methods to check for, retrieve, and move to the
* next and previous entries in the play order. Only the go_next and go_previous
* methods actually change anything.
*
* The play order should also emit the have-next-previous-changed signal to hint that
* the availability of either a next or previous entry in the order may have changed.
* This information is used to update the sensitivity of the next and previous buttons.
*/
static void rb_play_order_class_init (RBPlayOrderClass *klass);
static void rb_play_order_init (RBPlayOrder *porder);
static void rb_play_order_dispose (GObject *object);
static void rb_play_order_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void rb_play_order_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static gboolean default_has_next (RBPlayOrder *porder);
static gboolean default_has_previous (RBPlayOrder *porder);
static void default_playing_entry_removed (RBPlayOrder *porder, RhythmDBEntry *entry);
static void rb_play_order_entry_added_cb (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
RBPlayOrder *porder);
static void rb_play_order_row_deleted_cb (GtkTreeModel *model,
GtkTreePath *path,
RBPlayOrder *porder);
static void rb_play_order_query_model_changed_cb (GObject *source,
GParamSpec *arg,
RBPlayOrder *porder);
static void rb_play_order_update_have_next_previous (RBPlayOrder *porder);
struct RBPlayOrderPrivate
{
RBShellPlayer *player;
RBSource *source;
RhythmDB *db;
RhythmDBQueryModel *query_model;
RhythmDBEntry *playing_entry;
gulong query_model_change_id;
gulong sync_playing_entry_id;
gboolean have_next;
gboolean have_previous;
};
#define RB_PLAY_ORDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), RB_TYPE_PLAY_ORDER, RBPlayOrderPrivate))
enum
{
PROP_0,
PROP_PLAYER,
PROP_PLAYING_ENTRY
};
enum
{
HAVE_NEXT_PREVIOUS_CHANGED,
LAST_SIGNAL
};
static guint rb_play_order_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (RBPlayOrder, rb_play_order, G_TYPE_OBJECT)
static void
rb_play_order_class_init (RBPlayOrderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = rb_play_order_dispose;
object_class->set_property = rb_play_order_set_property;
object_class->get_property = rb_play_order_get_property;
klass->has_next = default_has_next;
klass->has_previous = default_has_previous;
klass->playing_entry_removed = default_playing_entry_removed;
/**
* RBPlayOrder:player:
*
* The #RBShellPlayer instance
*/
g_object_class_install_property (object_class,
PROP_PLAYER,
g_param_spec_object ("player",
"RBShellPlayer",
"Rhythmbox Player",
RB_TYPE_SHELL_PLAYER,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/**
* RBPlayOrder:playing-entry:
*
* The current playing #RhythmDBEntry
*/
g_object_class_install_property (object_class,
PROP_PLAYING_ENTRY,
g_param_spec_boxed ("playing-entry",
"RhythmDBEntry",
"Playing entry",
RHYTHMDB_TYPE_ENTRY,
G_PARAM_READWRITE));
/**
* RBPlayOrder::have-next-previous-changed:
* @porder: the #RBPlayOrder
* @have_next: if %TRUE, the play order has at least one more entry
* @have_previous: if %TRUE, the play order has at least one entry
* before the current entry
*
* Emitted as a hint to suggest that the sensitivity of next/previous
* buttons may need to be updated.
*/
rb_play_order_signals[HAVE_NEXT_PREVIOUS_CHANGED] =
g_signal_new ("have_next_previous_changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (RBPlayOrderClass, have_next_previous_changed),
NULL, NULL,
NULL,
G_TYPE_NONE,
2, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN);
g_type_class_add_private (klass, sizeof (RBPlayOrderPrivate));
}
static void
rb_play_order_init (RBPlayOrder *porder)
{
porder->priv = RB_PLAY_ORDER_GET_PRIVATE (porder);
}
static void
rb_play_order_dispose (GObject *object)
{
RBPlayOrder *porder;
g_return_if_fail (object != NULL);
g_return_if_fail (RB_IS_PLAY_ORDER (object));
porder = RB_PLAY_ORDER (object);
if (porder->priv->query_model != NULL) {
g_signal_handlers_disconnect_by_func (G_OBJECT (porder->priv->query_model),
G_CALLBACK (rb_play_order_entry_added_cb),
porder);
g_signal_handlers_disconnect_by_func (G_OBJECT (porder->priv->query_model),
G_CALLBACK (rb_play_order_row_deleted_cb),
porder);
g_object_unref (porder->priv->query_model);
porder->priv->query_model = NULL;
}
if (porder->priv->db != NULL) {
g_object_unref (porder->priv->db);
porder->priv->db = NULL;
}
if (porder->priv->playing_entry != NULL) {
rhythmdb_entry_unref (porder->priv->playing_entry);
porder->priv->playing_entry = NULL;
}
G_OBJECT_CLASS (rb_play_order_parent_class)->dispose (object);
}
static void
rb_play_order_set_player (RBPlayOrder *porder,
RBShellPlayer *player)
{
porder->priv->player = player;
}
static void
rb_play_order_set_playing_entry_internal (RBPlayOrder *porder,
RhythmDBEntry *entry)
{
RhythmDBEntry *old_entry;
old_entry = porder->priv->playing_entry;
porder->priv->playing_entry = entry;
if (porder->priv->playing_entry != NULL) {
rhythmdb_entry_ref (porder->priv->playing_entry);
}
if (RB_PLAY_ORDER_GET_CLASS (porder)->playing_entry_changed)
RB_PLAY_ORDER_GET_CLASS (porder)->playing_entry_changed (porder, old_entry, entry);
if (old_entry != NULL) {
rhythmdb_entry_unref (old_entry);
}
rb_play_order_update_have_next_previous (porder);
}
static void
rb_play_order_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
RBPlayOrder *porder = RB_PLAY_ORDER (object);
switch (prop_id) {
case PROP_PLAYER:
rb_play_order_set_player (porder, g_value_get_object (value));
break;
case PROP_PLAYING_ENTRY:
rb_play_order_set_playing_entry_internal (porder, g_value_get_boxed (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
rb_play_order_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
RBPlayOrder *porder = RB_PLAY_ORDER (object);
switch (prop_id)
{
case PROP_PLAYER:
g_value_set_object (value, porder->priv->player);
break;
case PROP_PLAYING_ENTRY:
g_value_set_boxed (value, porder->priv->playing_entry);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* rb_play_order_get_player:
* @porder: #RBPlayOrder instance
*
* Only for use by #RBPlayOrder subclasses.
*
* Returns: (transfer none): #RBShellPlayer instance
*/
RBShellPlayer *
rb_play_order_get_player (RBPlayOrder *porder)
{
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
return porder->priv->player;
}
/**
* rb_play_order_get_source:
* @porder: #RBPlayOrder instance
*
* Only for use by #RBPlayOrder subclasses.
*
* Returns: (transfer none): the playing #RBSource instance.
**/
RBSource *
rb_play_order_get_source (RBPlayOrder *porder)
{
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
return porder->priv->source;
}
/**
* rb_play_order_get_db:
* @porder: #RBPlayOrder instance
*
* Only for use by #RBPlayOrder subclasses.
*
* Returns: (transfer none): the #RhythmDB instance.
**/
RhythmDB *
rb_play_order_get_db (RBPlayOrder *porder)
{
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
return porder->priv->db;
}
/**
* rb_play_order_get_query_model:
* @porder: #RBPlayOrder instance
*
* Only for use by #RBPlayOrder subclasses.
*
* Returns: (transfer none): the active #RhythmDBQueryModel for the playing source.
*/
RhythmDBQueryModel *
rb_play_order_get_query_model (RBPlayOrder *porder)
{
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
return porder->priv->query_model;
}
/**
* rb_play_order_player_is_playing:
* @porder: #RBPlayOrder instance
*
* Returns %TRUE if there is a current playing entry in the play order.
*
* Return value: %TRUE if playing
**/
gboolean
rb_play_order_player_is_playing (RBPlayOrder *porder)
{
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), FALSE);
return (porder->priv->playing_entry != NULL);
}
/**
* rb_play_order_set_playing_entry:
* @porder: #RBPlayOrder instance
* @entry: (transfer none) (allow-none): The new playing entry (or NULL for none)
*
* Sets the playing entry in the play order.
**/
void
rb_play_order_set_playing_entry (RBPlayOrder *porder,
RhythmDBEntry *entry)
{
g_return_if_fail (RB_IS_PLAY_ORDER (porder));
rb_play_order_set_playing_entry_internal (porder, entry);
}
/**
* rb_play_order_get_playing_entry:
* @porder: #RBPlayOrder instance
*
* Returns the current playing entry in the play order.
*
* Returns: (transfer full): playing entry
*/
RhythmDBEntry *
rb_play_order_get_playing_entry (RBPlayOrder *porder)
{
RhythmDBEntry *entry;
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
entry = porder->priv->playing_entry;
if (entry != NULL) {
rhythmdb_entry_ref (entry);
}
return entry;
}
/**
* rb_play_order_playing_source_changed:
* @porder: #RBPlayOrder instance
* @source: New playing #RBSource
*
* Sets the playing #RBSource for the play order. Should be called
* by #RBShellPlayer when the active source changes. Subclasses
* should implement playing_source_changed() to make any necessary
* changes.
*/
void
rb_play_order_playing_source_changed (RBPlayOrder *porder,
RBSource *source)
{
RhythmDB *db = NULL;
g_return_if_fail (RB_IS_PLAY_ORDER (porder));
g_object_get (porder->priv->player,
"db", &db,
NULL);
if (db != porder->priv->db) {
if (RB_PLAY_ORDER_GET_CLASS (porder)->db_changed)
RB_PLAY_ORDER_GET_CLASS (porder)->db_changed (porder, db);
if (porder->priv->db != NULL) {
g_object_unref (porder->priv->db);
}
porder->priv->db = g_object_ref (db);
}
g_object_unref (db);
if (source != porder->priv->source) {
if (porder->priv->source) {
g_signal_handler_disconnect (G_OBJECT (porder->priv->source),
porder->priv->query_model_change_id);
}
porder->priv->source = source;
if (porder->priv->source) {
porder->priv->query_model_change_id =
g_signal_connect_object (G_OBJECT (porder->priv->source),
"notify::query-model",
G_CALLBACK (rb_play_order_query_model_changed_cb),
porder, 0);
}
rb_play_order_query_model_changed (porder);
if (RB_PLAY_ORDER_GET_CLASS (porder)->playing_source_changed)
RB_PLAY_ORDER_GET_CLASS (porder)->playing_source_changed (porder);
rb_play_order_update_have_next_previous (porder);
}
}
static void
rb_play_order_query_model_changed_cb (GObject *source,
GParamSpec *arg,
RBPlayOrder *porder)
{
rb_play_order_query_model_changed (porder);
}
/**
* rb_play_order_query_model_changed:
* @porder: RBPlayOrder instance
*
* Updates the #RhythmDBQueryModel instance for the play order.
* Called from the #RBSource notify signal handler, and also from
* #rb_play_order_source_changed. Subclasses should implement
* query_model_changed() to make any necessary adjustments if they
* store any state based on the contents of the #RhythmDBQueryModel.
*/
void
rb_play_order_query_model_changed (RBPlayOrder *porder)
{
RhythmDBQueryModel *new_model = NULL;
g_return_if_fail (RB_IS_PLAY_ORDER (porder));
if (porder->priv->source)
g_object_get (porder->priv->source, "query-model", &new_model, NULL);
if (porder->priv->query_model == new_model) {
if (new_model != NULL)
g_object_unref (new_model);
return;
}
if (porder->priv->query_model != NULL) {
g_signal_handlers_disconnect_by_func (G_OBJECT (porder->priv->query_model),
rb_play_order_entry_added_cb,
porder);
g_signal_handlers_disconnect_by_func (G_OBJECT (porder->priv->query_model),
rb_play_order_row_deleted_cb,
porder);
g_object_unref (porder->priv->query_model);
porder->priv->query_model = NULL;
}
if (new_model != NULL) {
porder->priv->query_model = new_model;
g_signal_connect_object (G_OBJECT (porder->priv->query_model),
"row-inserted",
G_CALLBACK (rb_play_order_entry_added_cb),
porder, 0);
g_signal_connect_object (G_OBJECT (porder->priv->query_model),
"row-deleted",
G_CALLBACK (rb_play_order_row_deleted_cb),
porder, 0);
}
if (RB_PLAY_ORDER_GET_CLASS (porder)->query_model_changed)
RB_PLAY_ORDER_GET_CLASS (porder)->query_model_changed (porder);
rb_play_order_update_have_next_previous (porder);
}
/**
* rb_play_order_entry_added_cb:
* @model: #GtkTreeModel
* @path: #GtkTreePath for added entry
* @iter: #GtkTreeIter for added entry
* @porder: #RBPlayOrder instance
*
* Called when a new entry is added to the active #RhythmDBQueryModel.
* Subclasses should implement entry_added() to make any necessary
* changes if they store any state based on the contents of the
* #RhythmDBQueryModel.
*/
static void
rb_play_order_entry_added_cb (GtkTreeModel *model,
GtkTreePath *path,
GtkTreeIter *iter,
RBPlayOrder *porder)
{
RhythmDBEntry *entry;
entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model),
iter);
if (RB_PLAY_ORDER_GET_CLASS (porder)->entry_added)
RB_PLAY_ORDER_GET_CLASS (porder)->entry_added (porder, entry);
if (!rhythmdb_query_model_has_pending_changes (RHYTHMDB_QUERY_MODEL (model)))
rb_play_order_update_have_next_previous (porder);
rhythmdb_entry_unref (entry);
}
/**
* rb_play_order_row_deleted_cb:
* @model: #GtkTreeModel
* @entry: the #RhythmDBEntry removed from the model
* @porder: #RBPlayOrder instance
*
* Called when an entry is removed from the active #RhythmDBQueryModel.
* Subclasses should implement entry_removed() to make any necessary
* changes if they store any state based on the contents of the
* #RhythmDBQueryModel.
*
* If the removed entry is the current playing entry, the playing-entry-deleted
* signal is emitted.
*/
static void
rb_play_order_row_deleted_cb (GtkTreeModel *model,
GtkTreePath *row,
RBPlayOrder *porder)
{
RhythmDBEntry *entry;
entry = rhythmdb_query_model_tree_path_to_entry (RHYTHMDB_QUERY_MODEL (model), row);
if (entry == porder->priv->playing_entry) {
RB_PLAY_ORDER_GET_CLASS (porder)->playing_entry_removed (porder, entry);
}
if (RB_PLAY_ORDER_GET_CLASS (porder)->entry_removed)
RB_PLAY_ORDER_GET_CLASS (porder)->entry_removed (porder, entry);
if (!rhythmdb_query_model_has_pending_changes (RHYTHMDB_QUERY_MODEL (model)))
rb_play_order_update_have_next_previous (porder);
rhythmdb_entry_unref (entry);
}
static gboolean
default_has_next (RBPlayOrder *porder)
{
RhythmDBEntry *entry;
gboolean res;
entry = rb_play_order_get_next (porder);
res = (entry != NULL);
if (entry)
rhythmdb_entry_unref (entry);
return res;
}
static gboolean
default_has_previous (RBPlayOrder *porder)
{
RhythmDBEntry *entry;
gboolean res;
entry = rb_play_order_get_previous (porder);
res = (entry != NULL);
if (entry)
rhythmdb_entry_unref (entry);
return res;
}
static gboolean
sync_playing_entry_cb (RBPlayOrder *porder)
{
RBShellPlayer *player;
player = rb_play_order_get_player (porder);
if (porder->priv->playing_entry) {
rb_shell_player_play_entry (player,
porder->priv->playing_entry,
rb_play_order_get_source (porder));
} else {
/* Just try to play something. This is mostly here to make
* the play queue work correctly, but it might be helpful otherwise.
*/
GError *error = NULL;
if (!rb_shell_player_do_next (player, &error)) {
if (error->domain != RB_SHELL_PLAYER_ERROR ||
error->code != RB_SHELL_PLAYER_ERROR_END_OF_PLAYLIST)
g_warning ("sync_playing_entry_cb: Unhandled error: %s", error->message);
}
}
porder->priv->sync_playing_entry_id = 0;
return FALSE;
}
static void
default_playing_entry_removed (RBPlayOrder *porder,
RhythmDBEntry *entry)
{
RBShellPlayer *player = rb_play_order_get_player (porder);
RBSource *source = rb_shell_player_get_playing_source (player);
rb_debug ("playing entry removed");
/* only clear the playing source if the source this play order is using
* is currently playing.
*/
if (source == rb_play_order_get_source (porder)) {
switch (rb_source_handle_eos (source)) {
case RB_SOURCE_EOF_ERROR:
case RB_SOURCE_EOF_STOP:
case RB_SOURCE_EOF_RETRY:
/* stop playing */
rb_shell_player_stop (player);
break;
case RB_SOURCE_EOF_NEXT:
{
RhythmDBEntry *next_entry;
/* go to next song, in an idle function so that other handlers run first */
next_entry = rb_play_order_get_next (porder);
if (next_entry == entry) {
rhythmdb_entry_unref (next_entry);
next_entry = NULL;
}
rb_play_order_set_playing_entry_internal (porder, next_entry);
if (porder->priv->sync_playing_entry_id == 0) {
porder->priv->sync_playing_entry_id =
g_idle_add_full (G_PRIORITY_HIGH_IDLE,
(GSourceFunc) sync_playing_entry_cb,
porder,
NULL);
}
if (next_entry != NULL) {
rhythmdb_entry_unref (next_entry);
}
break;
}
}
} else {
rb_play_order_set_playing_entry (porder, NULL);
}
}
/**
* rb_play_order_has_next:
* @porder: RBPlayOrder instance.
*
* If there is no current playing entry, returns true if the play order is non-empty.
*
* Returns: true if there is an entry after the current playing entry in the play order.
*/
gboolean
rb_play_order_has_next (RBPlayOrder *porder)
{
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), FALSE);
g_return_val_if_fail (RB_PLAY_ORDER_GET_CLASS (porder)->has_next != NULL, FALSE);
return RB_PLAY_ORDER_GET_CLASS (porder)->has_next (porder);
}
/**
* rb_play_order_get_next:
* @porder: RBPlayOrder instance
*
* Returns the next entry in the play order, or the first if not currently playing.
*
* Returns: (transfer full): next entry to play
*/
RhythmDBEntry *
rb_play_order_get_next (RBPlayOrder *porder)
{
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
g_return_val_if_fail (RB_PLAY_ORDER_GET_CLASS (porder)->get_next != NULL, NULL);
return RB_PLAY_ORDER_GET_CLASS (porder)->get_next (porder);
}
/**
* rb_play_order_go_next:
* @porder: RBPlayOrder instance
*
* Moves to the next entry in the play order. If not currently playing, sets the
* first entry in the play order as the playing entry.
*/
void
rb_play_order_go_next (RBPlayOrder *porder)
{
g_return_if_fail (RB_IS_PLAY_ORDER (porder));
if (RB_PLAY_ORDER_GET_CLASS (porder)->go_next) {
RB_PLAY_ORDER_GET_CLASS (porder)->go_next (porder);
} else if (RB_PLAY_ORDER_GET_CLASS (porder)->get_next) {
RhythmDBEntry *entry;
entry = RB_PLAY_ORDER_GET_CLASS (porder)->get_next (porder);
rb_play_order_set_playing_entry (porder, entry);
if (entry != NULL) {
rhythmdb_entry_unref (entry);
}
}
}
/**
* rb_play_order_has_previous:
* @porder: RBPlayOrder instance
*
* Returns %TRUE if there is an entry before the current entry in the play order.
* If not currently playing, returns %FALSE.
*
* Return value: %TRUE if previous entry exists
*/
gboolean
rb_play_order_has_previous (RBPlayOrder *porder)
{
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), FALSE);
g_return_val_if_fail (RB_PLAY_ORDER_GET_CLASS (porder)->has_previous != NULL, FALSE);
return RB_PLAY_ORDER_GET_CLASS (porder)->has_previous (porder);
}
/**
* rb_play_order_get_previous:
* @porder: RBPlayOrder instance
*
* Returns the previous entry in the play order, or NULL if not currently playing.
*
* Return value: (transfer full): previous entry
*/
RhythmDBEntry *
rb_play_order_get_previous (RBPlayOrder *porder)
{
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), NULL);
g_return_val_if_fail (RB_PLAY_ORDER_GET_CLASS (porder)->get_previous != NULL, NULL);
return RB_PLAY_ORDER_GET_CLASS (porder)->get_previous (porder);
}
/**
* rb_play_order_go_previous:
* @porder: RBPlayOrder instance
*
* Moves to the previous entry in the play order. If not currently playing, does nothing.
*/
void
rb_play_order_go_previous (RBPlayOrder *porder)
{
g_return_if_fail (RB_IS_PLAY_ORDER (porder));
if (RB_PLAY_ORDER_GET_CLASS (porder)->go_previous) {
RB_PLAY_ORDER_GET_CLASS (porder)->go_previous (porder);
} else if (RB_PLAY_ORDER_GET_CLASS (porder)->get_previous) {
RhythmDBEntry *entry;
entry = RB_PLAY_ORDER_GET_CLASS (porder)->get_previous (porder);
rb_play_order_set_playing_entry (porder, entry);
if (entry != NULL) {
rhythmdb_entry_unref (entry);
}
}
}
/**
* rb_play_order_model_not_empty:
* @porder: RBPlayOrder instance
*
* Returns %TRUE if the #RhythmDBQueryModel is not empty.
* Can be used to implement has_next and has_previous for play orders
* that have no beginning or end.
*
* Return value: %TRUE if not empty
*/
gboolean
rb_play_order_model_not_empty (RBPlayOrder *porder)
{
GtkTreeIter iter;
g_return_val_if_fail (RB_IS_PLAY_ORDER (porder), FALSE);
if (!porder->priv->query_model)
return FALSE;
return gtk_tree_model_get_iter_first (GTK_TREE_MODEL (porder->priv->query_model), &iter);
}
/**
* rb_play_order_update_have_next_previous:
* @porder: RBPlayOrder instance
*
* Updates the have_next and have_previous flags, and emits a signal if they
* change. This is called whenever the play order changes in such a way that
* these flags might change.
*/
void
rb_play_order_update_have_next_previous (RBPlayOrder *porder)
{
gboolean have_next;
gboolean have_previous;
g_return_if_fail (RB_IS_PLAY_ORDER (porder));
have_next = rb_play_order_has_next (porder);
have_previous = rb_play_order_has_previous (porder);
if ((have_next != porder->priv->have_next) ||
(have_previous != porder->priv->have_previous)) {
g_signal_emit (G_OBJECT (porder), rb_play_order_signals[HAVE_NEXT_PREVIOUS_CHANGED],
0, have_next, have_previous);
porder->priv->have_next = have_next;
porder->priv->have_previous = have_previous;
}
}
|