1656
1657
static gboolean
1657
totem_playlist_add_one_mrl (TotemPlaylist *playlist, const char *mrl,
1658
const char *display_name)
1658
totem_playlist_add_one_mrl (TotemPlaylist *playlist,
1660
const char *display_name)
1660
1662
GtkListStore *store;
1661
1663
GtkTreeIter iter;
1662
char *filename_for_display, *uri;
1664
char *filename_for_display, *uri, *escaped_filename;
1663
1665
GtkTreeRowReference *ref;
1664
1666
GFileMonitor *monitor;
1704
1706
monitor = NULL;
1709
escaped_filename = g_markup_escape_text (filename_for_display, -1);
1707
1710
gtk_list_store_insert_with_values (store, &iter, pos,
1708
1711
PLAYING_COL, TOTEM_PLAYLIST_STATUS_NONE,
1709
1712
FILENAME_COL, filename_for_display,
1713
FILENAME_ESCAPED_COL, escaped_filename,
1710
1714
URI_COL, uri ? uri : mrl,
1711
1715
TITLE_CUSTOM_COL, display_name ? TRUE : FALSE,
1712
1716
FILE_MONITOR_COL, monitor,
1718
g_free (escaped_filename);
1715
1720
g_signal_emit (playlist,
1716
1721
totem_playlist_table_signals[ITEM_ADDED],
1824
compare_removal (GtkTreeRowReference *ref, GtkTreePath *path)
1826
GtkTreePath *ref_path;
1829
ref_path = gtk_tree_row_reference_get_path (ref);
1830
if (gtk_tree_path_compare (path, ref_path) == 0)
1832
gtk_tree_path_free (ref_path);
1836
/* Whether the item in question will be removed */
1838
totem_playlist_item_to_be_removed (TotemPlaylist *playlist,
1840
ClearComparisonFunc func)
1845
GtkTreeSelection *selection;
1847
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (playlist->priv->treeview));
1848
return gtk_tree_selection_path_is_selected (selection, path);
1851
ret = g_list_find_custom (playlist->priv->list, path, (GCompareFunc) compare_removal);
1852
return (ret != NULL);
1819
1856
totem_playlist_clear_with_compare (TotemPlaylist *playlist,
1820
1857
ClearComparisonFunc func,
1821
1858
gconstpointer data)
1823
1860
GtkTreeRowReference *ref;
1861
GtkTreeRowReference *next;
1829
1866
if (func == NULL) {
1830
1867
GtkTreeSelection *selection;
1862
1899
path = gtk_tree_path_new_from_indices (i, -1);
1863
1900
r = gtk_tree_row_reference_new (playlist->priv->model, path);
1864
if (playlist->priv->current != NULL) {
1865
if (gtk_tree_path_compare (path, playlist->priv->current) == 0)
1901
if (playlist->priv->current_to_be_removed == FALSE && playlist->priv->current != NULL) {
1902
if (gtk_tree_path_compare (path, playlist->priv->current) == 0) {
1866
1903
playlist->priv->current_to_be_removed = TRUE;
1868
1906
playlist->priv->list = g_list_prepend (playlist->priv->list, r);
1869
1907
gtk_tree_path_free (path);
1877
1915
/* If the current item is to change, we need to keep an static
1878
1916
* reference to it, TreeIter and TreePath don't allow that */
1879
if (playlist->priv->current != NULL) {
1917
if (playlist->priv->current_to_be_removed == FALSE &&
1918
playlist->priv->current != NULL) {
1882
1919
ref = gtk_tree_row_reference_new (playlist->priv->model,
1883
playlist->priv->current);
1884
indices = gtk_tree_path_get_indices (playlist->priv->current);
1885
next_pos = indices[0];
1920
playlist->priv->current);
1921
} else if (playlist->priv->current != NULL) {
1924
item = gtk_tree_path_copy (playlist->priv->current);
1925
gtk_tree_path_next (item);
1926
next = gtk_tree_row_reference_new (playlist->priv->model, item);
1927
while (next != NULL) {
1928
if (totem_playlist_item_to_be_removed (playlist, item, func) == FALSE) {
1929
/* Found the item after the current one that
1930
* won't be removed, thus the new current */
1933
gtk_tree_row_reference_free (next);
1934
gtk_tree_path_next (item);
1935
next = gtk_tree_row_reference_new (playlist->priv->model, item);
1889
1939
/* We destroy the items, one-by-one from the list built above */
1890
while (playlist->priv->list != NULL)
1940
while (playlist->priv->list != NULL) {
1892
1941
GtkTreePath *path;
1893
1942
GtkTreeIter iter;
1911
1960
if (playlist->priv->current_to_be_removed != FALSE) {
1912
1961
/* The current item was removed from the playlist */
1913
if (next_pos != -1) {
1918
str = g_strdup_printf ("%d", next_pos);
1919
cur = gtk_tree_path_new_from_string (str);
1921
if (gtk_tree_model_get_iter (playlist->priv->model, &iter, cur) == FALSE) {
1922
playlist->priv->current = NULL;
1923
gtk_tree_path_free (cur);
1925
playlist->priv->current = cur;
1963
playlist->priv->current = gtk_tree_row_reference_get_path (next);
1964
gtk_tree_row_reference_free (next);
1929
1966
playlist->priv->current = NULL;
1940
1977
if (ref != NULL) {
1941
1978
/* The path to the current item changed */
1942
playlist->priv->current =
1943
gtk_tree_row_reference_get_path (ref);
1944
gtk_tree_row_reference_free (ref);
1979
playlist->priv->current = gtk_tree_row_reference_get_path (ref);
1947
1982
if (playlist->priv->shuffle)
1951
1986
totem_playlist_table_signals[CHANGED], 0,
1990
gtk_tree_row_reference_free (ref);
1954
1991
totem_playlist_update_save_button (playlist);
1955
1992
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (playlist->priv->treeview));
2202
escaped_title = g_markup_escape_text (title, -1);
2164
2203
gtk_list_store_set (store, &iter,
2165
2204
FILENAME_COL, title,
2205
FILENAME_ESCAPED_COL, escaped_title,
2166
2206
TITLE_CUSTOM_COL, TRUE,
2208
g_free (escaped_title);
2169
2210
g_signal_emit (playlist,
2170
2211
totem_playlist_table_signals[ACTIVE_NAME_CHANGED], 0);
2284
2325
g_return_if_fail (TOTEM_IS_PLAYLIST (playlist));
2286
if (totem_playlist_has_next_mrl (playlist) == FALSE)
2327
if (totem_playlist_has_next_mrl (playlist) == FALSE) {
2288
2328
totem_playlist_set_at_start (playlist);
2292
2332
totem_playlist_unset_playing (playlist);
2294
if (playlist->priv->shuffle == FALSE)
2334
if (playlist->priv->shuffle == FALSE) {
2296
2335
gtk_tree_model_get_iter (playlist->priv->model,
2298
playlist->priv->current);
2337
playlist->priv->current);
2300
2339
gtk_tree_model_iter_next (playlist->priv->model, &iter);
2301
2340
gtk_tree_path_free (playlist->priv->current);
2302
playlist->priv->current = gtk_tree_model_get_path
2303
(playlist->priv->model, &iter);
2341
playlist->priv->current = gtk_tree_model_get_path (playlist->priv->model, &iter);