1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2006 Jonathan Matthew <jonathan@kaolin.wh9.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 * This source lists files rhythmbox cannot find, and maybe tries to stop
23 * you from trying to play them.
29 #include <glib/gi18n.h>
31 #include "rb-entry-view.h"
32 #include "rb-missing-files-source.h"
33 #include "rb-song-info.h"
37 static void rb_missing_files_source_class_init (RBMissingFilesSourceClass
*klass
);
38 static void rb_missing_files_source_init (RBMissingFilesSource
*source
);
39 static GObject
*rb_missing_files_source_constructor (GType type
, guint n_construct_properties
,
40 GObjectConstructParam
*construct_properties
);
41 static void rb_missing_files_source_dispose (GObject
*object
);
42 static void rb_missing_files_source_set_property (GObject
*object
,
46 static void rb_missing_files_source_get_property (GObject
*object
,
51 static RBEntryView
*impl_get_entry_view (RBSource
*source
);
52 static void impl_song_properties (RBSource
*source
);
53 static void impl_delete (RBSource
*source
);
54 static void impl_get_status (RBSource
*source
, char **text
, char **progress_text
, float *progress
);
56 static void rb_missing_files_source_songs_show_popup_cb (RBEntryView
*view
,
58 RBMissingFilesSource
*source
);
59 static void rb_missing_files_source_songs_sort_order_changed_cb (RBEntryView
*view
,
60 RBMissingFilesSource
*source
);
62 #define MISSING_FILES_SOURCE_SONGS_POPUP_PATH "/MissingFilesViewPopup"
64 struct RBMissingFilesSourcePrivate
70 G_DEFINE_TYPE (RBMissingFilesSource
, rb_missing_files_source
, RB_TYPE_SOURCE
);
73 rb_missing_files_source_class_init (RBMissingFilesSourceClass
*klass
)
75 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
76 RBSourceClass
*source_class
= RB_SOURCE_CLASS (klass
);
78 object_class
->dispose
= rb_missing_files_source_dispose
;
79 object_class
->constructor
= rb_missing_files_source_constructor
;
81 object_class
->set_property
= rb_missing_files_source_set_property
;
82 object_class
->get_property
= rb_missing_files_source_get_property
;
84 source_class
->impl_can_browse
= (RBSourceFeatureFunc
) rb_false_function
;
85 source_class
->impl_get_entry_view
= impl_get_entry_view
;
86 source_class
->impl_can_rename
= (RBSourceFeatureFunc
) rb_false_function
;
87 source_class
->impl_can_search
= (RBSourceFeatureFunc
) rb_false_function
;
89 source_class
->impl_can_cut
= (RBSourceFeatureFunc
) rb_false_function
;
90 source_class
->impl_can_delete
= (RBSourceFeatureFunc
) rb_true_function
;
91 source_class
->impl_can_move_to_trash
= (RBSourceFeatureFunc
) rb_false_function
;
92 source_class
->impl_can_copy
= (RBSourceFeatureFunc
) rb_false_function
;
93 source_class
->impl_can_add_to_queue
= (RBSourceFeatureFunc
) rb_false_function
;
95 source_class
->impl_delete
= impl_delete
;
97 source_class
->impl_song_properties
= impl_song_properties
;
98 source_class
->impl_try_playlist
= (RBSourceFeatureFunc
) rb_false_function
;
99 source_class
->impl_can_pause
= (RBSourceFeatureFunc
) rb_false_function
;
101 source_class
->impl_get_status
= impl_get_status
;
103 g_type_class_add_private (klass
, sizeof (RBMissingFilesSourcePrivate
));
107 rb_missing_files_source_init (RBMissingFilesSource
*source
)
112 source
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (source
, RB_TYPE_MISSING_FILES_SOURCE
, RBMissingFilesSourcePrivate
);
114 gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR
, &size
, NULL
);
115 pixbuf
= gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
116 GTK_STOCK_MISSING_IMAGE
,
119 rb_source_set_pixbuf (RB_SOURCE (source
), pixbuf
);
120 if (pixbuf
!= NULL
) {
121 g_object_unref (pixbuf
);
126 rb_missing_files_source_constructor (GType type
, guint n_construct_properties
,
127 GObjectConstructParam
*construct_properties
)
129 GObject
*shell_player
;
130 RBMissingFilesSource
*source
;
131 RBMissingFilesSourceClass
*klass
;
134 RhythmDBQueryModel
*model
;
135 RhythmDBEntryType entry_type
;
137 klass
= RB_MISSING_FILES_SOURCE_CLASS (g_type_class_peek (RB_TYPE_MISSING_FILES_SOURCE
));
139 source
= RB_MISSING_FILES_SOURCE (G_OBJECT_CLASS (rb_missing_files_source_parent_class
)->
140 constructor (type
, n_construct_properties
, construct_properties
));
142 g_object_get (source
,
144 "entry-type", &entry_type
,
146 g_object_get (shell
, "db", &source
->priv
->db
, NULL
);
147 shell_player
= rb_shell_get_player (shell
);
148 g_object_unref (shell
);
150 /* construct real query */
151 query
= rhythmdb_query_parse (source
->priv
->db
,
152 RHYTHMDB_QUERY_PROP_EQUALS
,
155 RHYTHMDB_QUERY_PROP_EQUALS
,
156 RHYTHMDB_PROP_HIDDEN
,
159 g_boxed_free (RHYTHMDB_TYPE_ENTRY_TYPE
, entry_type
);
161 model
= rhythmdb_query_model_new (source
->priv
->db
, query
,
162 NULL
, NULL
, NULL
, FALSE
);
164 rhythmdb_query_free (query
);
166 g_object_set (model
, "show-hidden", TRUE
, NULL
);
168 /* set up entry view */
169 source
->priv
->view
= rb_entry_view_new (source
->priv
->db
, shell_player
,
172 rb_entry_view_set_model (source
->priv
->view
, model
);
174 rb_entry_view_append_column (source
->priv
->view
, RB_ENTRY_VIEW_COL_TRACK_NUMBER
, FALSE
);
175 rb_entry_view_append_column (source
->priv
->view
, RB_ENTRY_VIEW_COL_TITLE
, TRUE
);
176 /* rb_entry_view_append_column (source->priv->view, RB_ENTRY_VIEW_COL_GENRE, FALSE); */
177 rb_entry_view_append_column (source
->priv
->view
, RB_ENTRY_VIEW_COL_ARTIST
, FALSE
);
178 rb_entry_view_append_column (source
->priv
->view
, RB_ENTRY_VIEW_COL_ALBUM
, FALSE
);
179 rb_entry_view_append_column (source
->priv
->view
, RB_ENTRY_VIEW_COL_LOCATION
, TRUE
);
180 rb_entry_view_append_column (source
->priv
->view
, RB_ENTRY_VIEW_COL_LAST_SEEN
, TRUE
);
182 rb_entry_view_set_columns_clickable (source
->priv
->view
, TRUE
);
184 gtk_container_add (GTK_CONTAINER (source
), GTK_WIDGET (source
->priv
->view
));
185 g_signal_connect_object (source
->priv
->view
, "show_popup",
186 G_CALLBACK (rb_missing_files_source_songs_show_popup_cb
), source
, 0);
187 g_signal_connect_object (source
->priv
->view
, "sort-order-changed",
188 G_CALLBACK (rb_missing_files_source_songs_sort_order_changed_cb
), source
, 0);
190 gtk_widget_show_all (GTK_WIDGET (source
));
192 g_object_set (source
, "query-model", model
, NULL
);
193 g_object_unref (model
);
195 return G_OBJECT (source
);
199 rb_missing_files_source_dispose (GObject
*object
)
201 RBMissingFilesSource
*source
= RB_MISSING_FILES_SOURCE (object
);
203 if (source
->priv
->db
!= NULL
) {
204 g_object_unref (source
->priv
->db
);
205 source
->priv
->db
= NULL
;
208 G_OBJECT_CLASS (rb_missing_files_source_parent_class
)->dispose (object
);
212 impl_get_entry_view (RBSource
*asource
)
214 RBMissingFilesSource
*source
= RB_MISSING_FILES_SOURCE (asource
);
215 return source
->priv
->view
;
219 rb_missing_files_source_set_property (GObject
*object
,
224 /*RBMissingFilesSource *source = RB_MISSING_FILES_SOURCE (object);*/
229 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
235 rb_missing_files_source_get_property (GObject
*object
,
240 /*RBMissingFilesSource *source = RB_MISSING_FILES_SOURCE (object);*/
245 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
251 rb_missing_files_source_new (RBShell
*shell
,
252 RBLibrarySource
*library
)
255 RhythmDBEntryType entry_type
;
257 g_object_get (library
, "entry-type", &entry_type
, NULL
);
258 source
= RB_SOURCE (g_object_new (RB_TYPE_MISSING_FILES_SOURCE
,
259 "name", _("Missing Files"),
260 "entry-type", entry_type
,
263 "hidden-when-empty", TRUE
,
265 g_boxed_free (RHYTHMDB_TYPE_ENTRY_TYPE
, entry_type
);
270 rb_missing_files_source_songs_show_popup_cb (RBEntryView
*view
,
272 RBMissingFilesSource
*source
)
275 _rb_source_show_popup (RB_SOURCE (source
), MISSING_FILES_SOURCE_SONGS_POPUP_PATH
);
279 impl_song_properties (RBSource
*asource
)
281 RBMissingFilesSource
*source
= RB_MISSING_FILES_SOURCE (asource
);
282 GtkWidget
*song_info
= NULL
;
284 g_return_if_fail (source
->priv
->view
!= NULL
);
286 song_info
= rb_song_info_new (asource
, NULL
);
288 gtk_widget_show_all (song_info
);
290 rb_debug ("failed to create dialog, or no selection!");
294 impl_delete (RBSource
*asource
)
296 RBMissingFilesSource
*source
= RB_MISSING_FILES_SOURCE (asource
);
299 sel
= rb_entry_view_get_selected_entries (source
->priv
->view
);
300 for (tem
= sel
; tem
!= NULL
; tem
= tem
->next
) {
301 rhythmdb_entry_delete (source
->priv
->db
, tem
->data
);
302 rhythmdb_commit (source
->priv
->db
);
305 g_list_foreach (sel
, (GFunc
)rhythmdb_entry_unref
, NULL
);
310 rb_missing_files_source_songs_sort_order_changed_cb (RBEntryView
*view
,
311 RBMissingFilesSource
*source
)
313 rb_entry_view_resort_model (view
);
317 impl_get_status (RBSource
*asource
, char **text
, char **progress_text
, float *progress
)
319 RhythmDBQueryModel
*model
;
322 g_object_get (asource
, "query-model", &model
, NULL
);
323 count
= gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model
), NULL
);
324 g_object_unref (model
);
326 *text
= g_strdup_printf (ngettext ("%d missing file", "%d missing files", count
),