1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * $Id: medias.c,v 1.6 2005/02/19 21:02:34 nedko Exp $
12 *****************************************************************************/
20 #include "../result.h"
21 #include "../libdb/libdb.h"
22 #include "../libfrontend/db.h"
46 mediadb_uint nMediaID
,
47 mediadb_mediatype nType
,
49 const char *pszComment
,
50 mediadb_uint nTimeAdded
,
51 mediadb_uint nTotalFiles
,
52 mediadb_uint nTotalSize
,
53 mediadb_uint nLocationID
,
54 const char *pszLocation
59 time_t time
= nTimeAdded
;
60 char strTotalSize
[MAX_SIZE_DESCRIPTION
];
63 GError
* error
= NULL
;
65 gchar
* pszIconFullname
;
67 /* ctime_r(&time, strTime); */
68 /* strTime[strlen(strTime) - 1] = 0; */
70 localtime_r(&time
, &tm
);
72 "%u-%02u-%02u %02u:%02u:%02u",
80 get_size_description(nTotalSize
, strTotalSize
);
84 if (nType
== MEDIADB_MT_AUDIO
)
86 pszIcon
= "icon_acd.png";
88 else if (nType
== MEDIADB_MT_DATA
)
90 pszIcon
= "icon_cd.png";
99 pszIconFullname
= path_get_data_filename(pszIcon
);
100 if (pszIconFullname
!= NULL
)
102 pIcon
= gdk_pixbuf_new_from_file(pszIconFullname
, &error
);
105 g_warning("Could not load icon: %s\n", error
->message
);
110 g_free(pszIconFullname
);
114 g_warning("Could not find icon %s\n", pszIcon
);
118 gtk_list_store_prepend(
119 (GtkListStore
*)pUserContext
,
122 (GtkListStore
*)pUserContext
,
124 COL_MEDIAID
, (guint
)nMediaID
,
125 COL_MEDIAICON
, pIcon
,
126 COL_MEDIANAME
, pszName
,
127 COL_MEDIAFILES
, (guint
)nTotalFiles
,
128 COL_MEDIASIZE
, strTotalSize
,
129 COL_MEDIADATE
, strTime
,
130 COL_MEDIALOCATION
, pszLocation
,
131 COL_MEDIACOMMENT
, pszComment
,
135 static GtkTreeModel
*
136 create_and_fill_model(void)
139 GtkListStore
*pStore
;
142 pStore
= gtk_list_store_new(
144 G_TYPE_UINT
, /* COL_MEDIAID */
145 GDK_TYPE_PIXBUF
, /* COL_MEDIAICON */
146 G_TYPE_STRING
, /* COL_MEDIANAME */
147 G_TYPE_UINT
, /* COL_MEDIAFILES */
148 G_TYPE_STRING
, /* COL_MEDIASIZE */
149 G_TYPE_STRING
, /* COL_MEDIADATE */
150 G_TYPE_STRING
, /* COL_MEDIALOCATION */
151 G_TYPE_STRING
); /* COL_MEDIACOMMENT */
155 r
= mediadb_media_get_all(
159 if (MEDIADB_IS_ERROR(r
))
161 g_warning("%s\n", mediadb_get_error_message(g_hDB
));
163 pDialog
= gtk_message_dialog_new(
164 GTK_WINDOW(pMainWindow
),
165 GTK_DIALOG_DESTROY_WITH_PARENT
,
169 mediadb_get_error_message(g_hDB
));
171 gtk_dialog_run(GTK_DIALOG(pDialog
));
172 gtk_widget_destroy(pDialog
);
176 return GTK_TREE_MODEL(pStore
);
181 GtkTreeView
*pTreeView
,
183 GtkTreeViewColumn
*pColumn
,
186 GtkTreeModel
*pModel
;
188 unsigned int nMediaID
;
190 pModel
= gtk_tree_view_get_model(pTreeView
);
192 if (gtk_tree_model_get_iter(pModel
, &iter
, pPath
))
194 gtk_tree_model_get(pModel
, &iter
, COL_MEDIAID
, &nMediaID
, -1);
196 CreateMediaWindow(nMediaID
);
201 setup_view_and_model(GtkWidget
*pTreeView
)
203 GtkTreeViewColumn
*col
;
204 GtkCellRenderer
*renderer
;
206 GtkCellRenderer
* pRendererPixbuf
;
208 renderer
= gtk_cell_renderer_text_new();
209 pRendererPixbuf
= gtk_cell_renderer_pixbuf_new();
211 /* --- Column #1 --- */
213 col
= gtk_tree_view_column_new_with_attributes(
219 gtk_tree_view_append_column(
220 GTK_TREE_VIEW(pTreeView
),
223 /* --- Column #2 --- */
225 col
= gtk_tree_view_column_new();
227 gtk_tree_view_column_set_title(col
, "Name");
229 gtk_tree_view_column_pack_start(col
, pRendererPixbuf
, FALSE
);
230 gtk_tree_view_column_set_attributes(col
, pRendererPixbuf
,
231 "pixbuf", COL_MEDIAICON
,
234 gtk_tree_view_column_pack_end(col
, renderer
, TRUE
);
235 gtk_tree_view_column_set_attributes(col
,
237 "text", COL_MEDIANAME
,
240 gtk_tree_view_append_column(
241 GTK_TREE_VIEW(pTreeView
),
244 gtk_tree_view_column_set_resizable(col
, TRUE
);
245 // gtk_tree_view_column_set_max_width(col, 200);
246 // gtk_tree_view_column_set_min_width(col, 200);
248 /* --- Column #3 --- */
250 col
= gtk_tree_view_column_new_with_attributes(
253 "text", COL_MEDIALOCATION
,
256 gtk_tree_view_append_column(
257 GTK_TREE_VIEW(pTreeView
),
260 /* --- Column #4 --- */
262 col
= gtk_tree_view_column_new_with_attributes(
265 "text", COL_MEDIASIZE
,
268 gtk_tree_view_append_column(
269 GTK_TREE_VIEW(pTreeView
),
272 /* --- Column #5 --- */
274 col
= gtk_tree_view_column_new_with_attributes(
277 "text", COL_MEDIAFILES
,
280 gtk_tree_view_append_column(
281 GTK_TREE_VIEW(pTreeView
),
284 /* --- Column #6 --- */
286 col
= gtk_tree_view_column_new_with_attributes(
289 "text", COL_MEDIADATE
,
292 gtk_tree_view_append_column(
293 GTK_TREE_VIEW(pTreeView
),
296 /* --- Column #7 --- */
298 col
= gtk_tree_view_column_new_with_attributes(
301 "text", COL_MEDIACOMMENT
,
304 gtk_tree_view_append_column(
305 GTK_TREE_VIEW(pTreeView
),
308 model
= create_and_fill_model();
310 gtk_tree_view_set_model(GTK_TREE_VIEW(pTreeView
), model
);
312 g_object_unref(model
); /* destroy model automatically with view */
317 (GCallback
)view_onRowActivated
,
324 GtkWidget
*pMediasWindow
;
326 pMediasWindow
= construct_glade_widget("medias_window");
328 setup_view_and_model(get_glade_widget_child(pMediasWindow
, "medias_treeview"));
330 gtk_widget_show_all(pMediasWindow
);
332 return pMediasWindow
;
335 /*****************************************************************************
339 * !!! WARNING !!! Following lines are automatically updated by the CVS system.
342 * Revision 1.6 2005/02/19 21:02:34 nedko
343 * Don't try to access database when it is not opened.
345 * Revision 1.5 2005/02/18 22:20:05 nedko
346 * Cleanup things and make them better way.
348 * Revision 1.4 2005/02/18 02:12:47 nedko
349 * Use path module to access project specific data files.
352 * Revision 1.3 2004/08/31 22:40:15 nedko
353 * Partitally implemented search feature.
355 * Revision 1.2 2004/05/22 00:36:24 nedko
356 * set WM_WINDOWS_ROLE
358 * Revision 1.1 2004/05/21 23:43:38 nedko
359 * Implement media window.
361 *****************************************************************************/