1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * $Id: media.c,v 1.9 2005/02/20 15:32:23 nedko Exp $
12 *****************************************************************************/
20 #include "../result.h"
21 #include "../libdb/libdb.h"
22 #include "../libfrontend/db.h"
23 #include "../libfrontend/error.h"
40 struct InsertChildsContext
42 GtkTreeStore
*pTreeStore
;
46 struct MediaWindowContext
48 mediadb_uint nMediaID
;
53 GtkTreeStore
*pTreeStore
,
57 GtkTreeIter IterChild
;
59 gtk_tree_store_append(
71 mediadb_filetype Filetype
,
75 GtkTreeIter IterChild
;
79 char strSize
[MAX_SIZE_DESCRIPTION
];
82 GError
* error
= NULL
;
84 gchar
* pszIconFullname
;
86 localtime_r(&time
, &tm
);
88 "%u-%02u-%02u %02u:%02u:%02u",
96 get_size_description(nSize
, strSize
);
100 if (Filetype
== MEDIADB_FILETYPE_DIR
)
102 pszIcon
= "icon_folder.png";
106 pszIcon
= "icon_unknown.png";
109 pszIconFullname
= path_get_data_filename(pszIcon
);
110 if (pszIconFullname
!= NULL
)
112 pIcon
= gdk_pixbuf_new_from_file(pszIconFullname
, &error
);
115 g_warning("Could not load icon: %s\n", error
->message
);
120 g_free(pszIconFullname
);
124 g_warning("Could not find icon %s\n", pszIcon
);
127 gtk_tree_store_append(
128 ((struct InsertChildsContext
*)pUserContext
)->pTreeStore
,
130 ((struct InsertChildsContext
*)pUserContext
)->pIter
);
133 ((struct InsertChildsContext
*)pUserContext
)->pTreeStore
,
137 COL_SIZE
, (Filetype
== MEDIADB_FILETYPE_DIR
)?NULL
:strSize
,
141 if (Filetype
== MEDIADB_FILETYPE_DIR
)
144 ((struct InsertChildsContext
*)pUserContext
)->pTreeStore
,
147 pszFullPath
= g_malloc(strlen(pszPath
)+strlen(pszName
)+1);
148 sprintf(pszFullPath
, "%s%s", pszPath
, pszName
);
150 ((struct InsertChildsContext
*)pUserContext
)->pTreeStore
,
152 COL_PATH
, pszFullPath
,
160 mediadb_uint nMediaID
,
161 GtkTreeStore
*pTreeStore
,
166 struct InsertChildsContext context
;
169 context
.pTreeStore
= pTreeStore
;
170 context
.pIter
= pIter
;
172 r
= mediadb_files_get(
179 if (MEDIADB_IS_ERROR(r
))
181 mediadb_error_printf(
182 MEDIADB_ERROR_NONCRITICAL
,
183 "Cannot retrieve contents of \"%s/\" directory from media with ID %u (%s)",
185 (unsigned int)nMediaID
,
186 mediadb_get_error_message(g_hDB
));
192 GtkTreeView
*pTreeView
,
197 GtkTreeModel
*pModel
;
199 GtkTreeIter IterChild
;
201 pModel
= gtk_tree_view_get_model(pTreeView
);
203 if (!gtk_tree_model_iter_children(pModel
, &IterChild
, pIter
))
206 gtk_tree_model_get(pModel
, pIter
, COL_PATH
, &pszPath
, -1);
209 ((struct MediaWindowContext
*)pUserData
)->nMediaID
,
210 GTK_TREE_STORE(pModel
),
216 gtk_tree_store_remove(GTK_TREE_STORE(pModel
), &IterChild
);
221 GtkTreeView
*pTreeView
,
226 GtkTreeModel
*pModel
;
227 GtkTreeIter IterChild
;
229 pModel
= gtk_tree_view_get_model(pTreeView
);
231 if (!gtk_tree_model_iter_children(pModel
, &IterChild
, pIter
))
236 gtk_tree_store_remove(GTK_TREE_STORE(pModel
), &IterChild
);
238 while (gtk_tree_model_iter_children(pModel
, &IterChild
, pIter
));
240 InsertPseudoChild(GTK_TREE_STORE(pModel
), pIter
);
244 OnMediaWindowDestroy(
252 CreateMediaWindow(mediadb_uint nMediaID
)
255 mediadb_uint nTimeAdded
;
256 mediadb_uint nTotalFiles
;
257 mediadb_uint nTotalSize
;
260 GtkWidget
*pMediaWindow
= NULL
;
262 GtkCellRenderer
* pRendererText
;
263 GtkCellRenderer
* pRendererPixbuf
;
264 GtkTreeViewColumn
* pColumn
;
265 GtkTreeStore
*pTreeStore
;
266 struct MediaWindowContext
* pContext
;
269 char strTotalSize
[MAX_SIZE_DESCRIPTION
];
270 mediadb_mediatype nType
;
273 mediadb_uint nLocationID
;
274 mediadb_uint nLocationTypeID
;
276 char *pszLocationType
;
278 r
= mediadb_media_get_properties(
285 if (MEDIADB_IS_ERROR(r
))
287 g_warning("%s\n", mediadb_get_error_message(g_hDB
));
289 pDialog
= gtk_message_dialog_new(
290 GTK_WINDOW(pMainWindow
),
291 GTK_DIALOG_DESTROY_WITH_PARENT
,
295 mediadb_get_error_message(g_hDB
));
297 gtk_dialog_run(GTK_DIALOG(pDialog
));
298 gtk_widget_destroy(pDialog
);
303 if (nType
!= MEDIADB_MT_DATA
)
305 g_warning("Only data cd type is supported.\n");
307 pDialog
= gtk_message_dialog_new(
308 GTK_WINDOW(pMainWindow
),
309 GTK_DIALOG_DESTROY_WITH_PARENT
,
312 "Only data cd type is supported.");
314 gtk_dialog_run(GTK_DIALOG(pDialog
));
315 gtk_widget_destroy(pDialog
);
320 r
= mediadb_location_get_properties(
325 if (MEDIADB_IS_ERROR(r
))
327 g_warning("%s\n", mediadb_get_error_message(g_hDB
));
329 pDialog
= gtk_message_dialog_new(
330 GTK_WINDOW(pMainWindow
),
331 GTK_DIALOG_DESTROY_WITH_PARENT
,
335 mediadb_get_error_message(g_hDB
));
337 gtk_dialog_run(GTK_DIALOG(pDialog
));
338 gtk_widget_destroy(pDialog
);
344 r
= mediadb_location_type_get_properties(
348 if (MEDIADB_IS_ERROR(r
))
350 g_warning("%s\n", mediadb_get_error_message(g_hDB
));
352 pDialog
= gtk_message_dialog_new(
353 GTK_WINDOW(pMainWindow
),
354 GTK_DIALOG_DESTROY_WITH_PARENT
,
358 mediadb_get_error_message(g_hDB
));
360 gtk_dialog_run(GTK_DIALOG(pDialog
));
361 gtk_widget_destroy(pDialog
);
368 r
= mediadb_media_get_properties_data(
373 if (MEDIADB_IS_ERROR(r
))
375 g_warning("%s\n", mediadb_get_error_message(g_hDB
));
377 pDialog
= gtk_message_dialog_new(
378 GTK_WINDOW(pMainWindow
),
379 GTK_DIALOG_DESTROY_WITH_PARENT
,
383 mediadb_get_error_message(g_hDB
));
385 gtk_dialog_run(GTK_DIALOG(pDialog
));
386 gtk_widget_destroy(pDialog
);
390 free(pszLocationType
);
395 localtime_r(&time
, &tm
);
397 "%u-%02u-%02u %02u:%02u:%02u",
405 get_size_description(nTotalSize
, strTotalSize
);
407 pContext
= g_malloc(sizeof(struct MediaWindowContext
));
408 pContext
->nMediaID
= nMediaID
;
410 pMediaWindow
= construct_glade_widget("media_window");
412 gtk_window_set_title(GTK_WINDOW(pMediaWindow
),
416 G_OBJECT(pMediaWindow
),
418 G_CALLBACK(OnMediaWindowDestroy
),
422 gtk_label_set_text(GTK_LABEL(get_glade_widget_child(pMediaWindow
, "media_window_label_name_data")), pszTitle
);
425 str
= g_string_sized_new(100);
428 g_string_printf(str
, "%u", (unsigned int)nMediaID
);
429 gtk_label_set_text(GTK_LABEL(get_glade_widget_child(pMediaWindow
, "media_window_label_id_data")), str
->str
);
432 gtk_label_set_text(GTK_LABEL(get_glade_widget_child(pMediaWindow
, "media_window_label_time_data")), strTime
);
435 pChild
= get_glade_widget_child(pMediaWindow
, "media_window_label_location_data");
436 if (*pszLocation
== 0)
438 gtk_label_set_text(GTK_LABEL(pChild
), "");
440 else if (*pszLocationType
== 0)
442 g_string_printf(str
, "%s", pszLocation
);
443 gtk_label_set_text(GTK_LABEL(pChild
), str
->str
);
447 g_string_printf(str
, "%s (%s)", pszLocation
, pszLocationType
);
448 gtk_label_set_text(GTK_LABEL(pChild
), str
->str
);
452 /* "Data CD" os hardcoded until we have support for something else */
453 gtk_label_set_text(GTK_LABEL(get_glade_widget_child(pMediaWindow
, "media_window_label_type_data")), "Data CD");
455 /* -- files_count -- */
456 g_string_printf(str
, "%u", (unsigned int)nTotalFiles
);
457 gtk_label_set_text(GTK_LABEL(get_glade_widget_child(pMediaWindow
, "media_window_label_files_count_data")), str
->str
);
460 gtk_label_set_text(GTK_LABEL(get_glade_widget_child(pMediaWindow
, "media_window_label_size_data")), strTotalSize
);
463 pChild
= get_glade_widget_child(pMediaWindow
, "treeview");
465 pRendererText
= gtk_cell_renderer_text_new();
466 pRendererPixbuf
= gtk_cell_renderer_pixbuf_new();
468 /* --- Column #1 --- */
470 pColumn
= gtk_tree_view_column_new();
471 gtk_tree_view_column_set_title(pColumn
, "Name");
473 gtk_tree_view_column_pack_start(pColumn
, pRendererPixbuf
, FALSE
);
474 gtk_tree_view_column_set_attributes(pColumn
, pRendererPixbuf
,
478 gtk_tree_view_column_pack_start(pColumn
, pRendererText
, TRUE
);
479 gtk_tree_view_column_set_attributes(pColumn
,
484 gtk_tree_view_append_column(
485 GTK_TREE_VIEW(pChild
),
488 /* --- Column #2 --- */
490 pColumn
= gtk_tree_view_column_new_with_attributes(
496 gtk_tree_view_append_column(
497 GTK_TREE_VIEW(pChild
),
500 /* --- Column #3 --- */
502 pColumn
= gtk_tree_view_column_new_with_attributes(
508 gtk_tree_view_append_column(
509 GTK_TREE_VIEW(pChild
),
512 /* Create the store */
513 pTreeStore
= gtk_tree_store_new(
521 /* Fill the top level items in store */
523 InsertChilds(nMediaID
, pTreeStore
, NULL
, NULL
);
525 /* connect the row-expanded and row-collapsed signals */
529 G_CALLBACK(OnRowExpanded
),
535 G_CALLBACK(OnRowCollapsed
),
539 gtk_tree_view_set_model(GTK_TREE_VIEW(pChild
), GTK_TREE_MODEL(pTreeStore
));
541 gtk_widget_show_all(pMediaWindow
);
544 /*****************************************************************************
548 * !!! WARNING !!! Following lines are automatically updated by the CVS system.
551 * Revision 1.9 2005/02/20 15:32:23 nedko
552 * Align labels in media dialog in glade
554 * Revision 1.8 2005/02/19 13:38:56 nedko
555 * Remove disabled pre-glade code.
557 * Revision 1.7 2005/02/19 00:26:42 nedko
558 * Add prefix to media window label names
560 * Revision 1.6 2005/02/19 00:21:32 nedko
561 * Switch media window to glade
563 * Revision 1.5 2005/02/18 02:12:08 nedko
564 * Use path module to access project specific data files.
566 * Revision 1.4 2004/08/31 22:40:15 nedko
567 * Partitally implemented search feature.
569 * Revision 1.3 2004/08/08 00:47:42 nedko
570 * Get more info for media from database.
572 * Revision 1.2 2004/05/22 00:36:24 nedko
573 * set WM_WINDOWS_ROLE
575 * Revision 1.1 2004/05/21 23:43:38 nedko
576 * Implement media window.
578 *****************************************************************************/