Updated Macedonian Translation <ufo@linux.net.mk>
[rhythmbox.git] / sources / rb-missing-files-source.c
blob44d1f5375618018b091772c123c442f07f03321e
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
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.
26 #include "config.h"
28 #include <gtk/gtk.h>
29 #include <glib/gi18n.h>
31 #include "rb-entry-view.h"
32 #include "rb-missing-files-source.h"
33 #include "rb-song-info.h"
34 #include "rb-util.h"
35 #include "rb-debug.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,
43 guint prop_id,
44 const GValue *value,
45 GParamSpec *pspec);
46 static void rb_missing_files_source_get_property (GObject *object,
47 guint prop_id,
48 GValue *value,
49 GParamSpec *pspec);
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,
57 gboolean over_entry,
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
66 RhythmDB *db;
67 RBEntryView *view;
68 RhythmDBEntryType entry_type;
71 enum
73 PROP_0,
74 PROP_ENTRY_TYPE
77 G_DEFINE_TYPE (RBMissingFilesSource, rb_missing_files_source, RB_TYPE_SOURCE);
79 static void
80 rb_missing_files_source_class_init (RBMissingFilesSourceClass *klass)
82 GObjectClass *object_class = G_OBJECT_CLASS (klass);
83 RBSourceClass *source_class = RB_SOURCE_CLASS (klass);
85 object_class->dispose = rb_missing_files_source_dispose;
86 object_class->constructor = rb_missing_files_source_constructor;
88 object_class->set_property = rb_missing_files_source_set_property;
89 object_class->get_property = rb_missing_files_source_get_property;
91 source_class->impl_can_browse = (RBSourceFeatureFunc) rb_false_function;
92 source_class->impl_get_entry_view = impl_get_entry_view;
93 source_class->impl_can_rename = (RBSourceFeatureFunc) rb_false_function;
94 source_class->impl_can_search = (RBSourceFeatureFunc) rb_false_function;
96 source_class->impl_can_cut = (RBSourceFeatureFunc) rb_false_function;
97 source_class->impl_can_delete = (RBSourceFeatureFunc) rb_true_function;
98 source_class->impl_can_move_to_trash = (RBSourceFeatureFunc) rb_false_function;
99 source_class->impl_can_copy = (RBSourceFeatureFunc) rb_false_function;
100 source_class->impl_can_add_to_queue = (RBSourceFeatureFunc) rb_false_function;
102 source_class->impl_delete = impl_delete;
104 source_class->impl_song_properties = impl_song_properties;
105 source_class->impl_try_playlist = (RBSourceFeatureFunc) rb_false_function;
106 source_class->impl_can_pause = (RBSourceFeatureFunc) rb_false_function;
108 source_class->impl_have_url = (RBSourceFeatureFunc) rb_false_function;
109 source_class->impl_get_status = impl_get_status;
111 g_object_class_install_property (object_class,
112 PROP_ENTRY_TYPE,
113 g_param_spec_boxed ("entry-type",
114 "Entry type",
115 "Type of the entries which should be displayed by this source",
116 RHYTHMDB_TYPE_ENTRY_TYPE,
117 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
119 g_type_class_add_private (klass, sizeof (RBMissingFilesSourcePrivate));
122 static void
123 rb_missing_files_source_init (RBMissingFilesSource *source)
125 gint size;
126 GdkPixbuf *pixbuf;
128 source->priv = G_TYPE_INSTANCE_GET_PRIVATE (source, RB_TYPE_MISSING_FILES_SOURCE, RBMissingFilesSourcePrivate);
130 gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE_TOOLBAR, &size, NULL);
131 pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
132 GTK_STOCK_MISSING_IMAGE,
133 size,
134 0, NULL);
135 rb_source_set_pixbuf (RB_SOURCE (source), pixbuf);
136 if (pixbuf != NULL) {
137 g_object_unref (pixbuf);
140 source->priv->entry_type = RHYTHMDB_ENTRY_TYPE_SONG;
143 static GObject *
144 rb_missing_files_source_constructor (GType type, guint n_construct_properties,
145 GObjectConstructParam *construct_properties)
147 GObject *shell_player;
148 RBMissingFilesSource *source;
149 RBMissingFilesSourceClass *klass;
150 RBShell *shell;
151 GPtrArray *query;
152 RhythmDBQueryModel *model;
154 klass = RB_MISSING_FILES_SOURCE_CLASS (g_type_class_peek (RB_TYPE_MISSING_FILES_SOURCE));
156 source = RB_MISSING_FILES_SOURCE (G_OBJECT_CLASS (rb_missing_files_source_parent_class)->
157 constructor (type, n_construct_properties, construct_properties));
159 g_object_get (source, "shell", &shell, NULL);
160 g_object_get (shell, "db", &source->priv->db, NULL);
161 shell_player = rb_shell_get_player (shell);
162 g_object_unref (shell);
164 /* construct real query */
165 query = rhythmdb_query_parse (source->priv->db,
166 RHYTHMDB_QUERY_PROP_EQUALS,
167 RHYTHMDB_PROP_TYPE,
168 source->priv->entry_type,
169 RHYTHMDB_QUERY_PROP_EQUALS,
170 RHYTHMDB_PROP_HIDDEN,
171 TRUE,
172 RHYTHMDB_QUERY_END);
173 model = rhythmdb_query_model_new (source->priv->db, query,
174 NULL, NULL, NULL, FALSE);
176 rhythmdb_query_free (query);
178 g_object_set (model, "show-hidden", TRUE, NULL);
180 /* set up entry view */
181 source->priv->view = rb_entry_view_new (source->priv->db, shell_player,
182 NULL, FALSE, FALSE);
184 rb_entry_view_set_model (source->priv->view, model);
186 rb_entry_view_append_column (source->priv->view, RB_ENTRY_VIEW_COL_TRACK_NUMBER, FALSE);
187 rb_entry_view_append_column (source->priv->view, RB_ENTRY_VIEW_COL_TITLE, TRUE);
188 /* rb_entry_view_append_column (source->priv->view, RB_ENTRY_VIEW_COL_GENRE, FALSE); */
189 rb_entry_view_append_column (source->priv->view, RB_ENTRY_VIEW_COL_ARTIST, FALSE);
190 rb_entry_view_append_column (source->priv->view, RB_ENTRY_VIEW_COL_ALBUM, FALSE);
191 rb_entry_view_append_column (source->priv->view, RB_ENTRY_VIEW_COL_LOCATION, TRUE);
192 rb_entry_view_append_column (source->priv->view, RB_ENTRY_VIEW_COL_LAST_SEEN, TRUE);
194 rb_entry_view_set_columns_clickable (source->priv->view, TRUE);
196 gtk_container_add (GTK_CONTAINER (source), GTK_WIDGET (source->priv->view));
197 g_signal_connect_object (source->priv->view, "show_popup",
198 G_CALLBACK (rb_missing_files_source_songs_show_popup_cb), source, 0);
199 g_signal_connect_object (source->priv->view, "sort-order-changed",
200 G_CALLBACK (rb_missing_files_source_songs_sort_order_changed_cb), source, 0);
202 gtk_widget_show_all (GTK_WIDGET (source));
204 g_object_set (source, "query-model", model, NULL);
205 g_object_unref (model);
207 return G_OBJECT (source);
210 static void
211 rb_missing_files_source_dispose (GObject *object)
213 RBMissingFilesSource *source = RB_MISSING_FILES_SOURCE (object);
215 if (source->priv->db != NULL) {
216 g_object_unref (source->priv->db);
217 source->priv->db = NULL;
220 G_OBJECT_CLASS (rb_missing_files_source_parent_class)->dispose (object);
223 static RBEntryView *
224 impl_get_entry_view (RBSource *asource)
226 RBMissingFilesSource *source = RB_MISSING_FILES_SOURCE (asource);
227 return source->priv->view;
230 static void
231 rb_missing_files_source_set_property (GObject *object,
232 guint prop_id,
233 const GValue *value,
234 GParamSpec *pspec)
236 RBMissingFilesSource *source = RB_MISSING_FILES_SOURCE (object);
238 switch (prop_id)
240 case PROP_ENTRY_TYPE:
241 source->priv->entry_type = g_value_get_boxed (value);
242 break;
243 default:
244 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
245 break;
249 static void
250 rb_missing_files_source_get_property (GObject *object,
251 guint prop_id,
252 GValue *value,
253 GParamSpec *pspec)
255 RBMissingFilesSource *source = RB_MISSING_FILES_SOURCE (object);
257 switch (prop_id)
259 case PROP_ENTRY_TYPE:
260 g_value_set_boxed (value, source->priv->entry_type);
261 break;
262 default:
263 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
264 break;
268 RBSource *
269 rb_missing_files_source_new (RBShell *shell,
270 RBLibrarySource *library)
272 RBSource *source;
273 RhythmDBEntryType entry_type;
275 g_object_get (library, "entry-type", &entry_type, NULL);
276 source = RB_SOURCE (g_object_new (RB_TYPE_MISSING_FILES_SOURCE,
277 "name", _("Missing Files"),
278 "entry-type", entry_type,
279 "shell", shell,
280 "visibility", FALSE,
281 "hidden-when-empty", TRUE,
282 NULL));
283 g_boxed_free (RHYTHMDB_TYPE_ENTRY_TYPE, entry_type);
284 return source;
287 static void
288 rb_missing_files_source_songs_show_popup_cb (RBEntryView *view,
289 gboolean over_entry,
290 RBMissingFilesSource *source)
292 if (over_entry)
293 _rb_source_show_popup (RB_SOURCE (source), MISSING_FILES_SOURCE_SONGS_POPUP_PATH);
296 static void
297 impl_song_properties (RBSource *asource)
299 RBMissingFilesSource *source = RB_MISSING_FILES_SOURCE (asource);
300 GtkWidget *song_info = NULL;
302 g_return_if_fail (source->priv->view != NULL);
304 song_info = rb_song_info_new (asource, NULL);
305 if (song_info)
306 gtk_widget_show_all (song_info);
307 else
308 rb_debug ("failed to create dialog, or no selection!");
311 static void
312 impl_delete (RBSource *asource)
314 RBMissingFilesSource *source = RB_MISSING_FILES_SOURCE (asource);
315 GList *sel, *tem;
317 sel = rb_entry_view_get_selected_entries (source->priv->view);
318 for (tem = sel; tem != NULL; tem = tem->next) {
319 rhythmdb_entry_delete (source->priv->db, tem->data);
320 rhythmdb_commit (source->priv->db);
323 g_list_foreach (sel, (GFunc)rhythmdb_entry_unref, NULL);
324 g_list_free (sel);
327 static void
328 rb_missing_files_source_songs_sort_order_changed_cb (RBEntryView *view,
329 RBMissingFilesSource *source)
331 rb_entry_view_resort_model (view);
334 static void
335 impl_get_status (RBSource *asource, char **text, char **progress_text, float *progress)
337 RhythmDBQueryModel *model;
338 gint count;
340 g_object_get (asource, "query-model", &model, NULL);
341 count = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL);
342 g_object_unref (model);
344 *text = g_strdup_printf (ngettext ("%d missing file", "%d missing files", count),
345 count);