1 /*****************************************************************************
2 * maemo_interface.c : Interface creation of the maemo plugin
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
7 * Authors: Antoine Lejeune <phytos@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include <vlc_common.h>
29 #include "maemo_callbacks.h"
30 #include "maemo_interface.h"
31 #include "maemo_input.h"
33 static void scan_maemo_for_media ( intf_thread_t *p_intf );
34 static void find_media_in_dir ( const char *psz_dir, GList **pp_list );
36 static const char *ppsz_extensions[] =
37 { "aac", "flac", "m4a", "m4p", "mka", "mp1", "mp2", "mp3",
38 "ogg", "wav", "wma", "asf", "avi", "divx", "flv", "m1v",
39 "m2v", "m4v", "mkv", "mov", "mpeg", "mpeg1", "mpeg2", "mpeg4",
40 "mpg", "ogm", "wmv", NULL };
42 static const char *ppsz_media_dirs[] =
43 { "/media/mmc1", "/media/mmc2", "/home/user/MyDocs/.videos", NULL };
45 void create_playlist( intf_thread_t *p_intf )
49 GtkListStore *playlist_store;
50 GtkTreeViewColumn *col;
51 GtkCellRenderer *renderer;
53 playlist = gtk_tree_view_new();
55 playlist_store = gtk_list_store_new( 1, G_TYPE_STRING );
56 p_intf->p_sys->p_playlist_store = playlist_store;
58 gtk_tree_view_set_model( GTK_TREE_VIEW( playlist ),
59 GTK_TREE_MODEL( playlist_store ) );
61 renderer = gtk_cell_renderer_text_new();
62 col = gtk_tree_view_column_new_with_attributes( "File", renderer,
64 gtk_tree_view_append_column( GTK_TREE_VIEW( playlist ), col );
66 g_object_set( playlist, "headers-visible", TRUE, NULL );
67 scan_maemo_for_media( p_intf );
69 scroll = gtk_scrolled_window_new( NULL, NULL );
70 gtk_container_add( GTK_CONTAINER( scroll ), playlist );
72 p_intf->p_sys->p_playlist_window = scroll;
74 g_signal_connect( playlist, "row-activated",
75 G_CALLBACK( pl_row_activated_cb ), NULL );
77 // Set callback with the vlc core
78 var_AddCallback( p_intf->p_sys->p_playlist, "item-change",
79 item_changed_cb, p_intf );
80 var_AddCallback( p_intf->p_sys->p_playlist, "item-current",
81 playlist_current_cb, p_intf );
82 var_AddCallback( p_intf->p_sys->p_playlist, "activity",
83 activity_cb, p_intf );
86 void delete_playlist( intf_thread_t *p_intf )
88 var_DelCallback( p_intf->p_sys->p_playlist, "item-change",
89 item_changed_cb, p_intf );
90 var_DelCallback( p_intf->p_sys->p_playlist, "item-current",
91 playlist_current_cb, p_intf );
92 var_DelCallback( p_intf->p_sys->p_playlist, "activity",
93 activity_cb, p_intf );
96 static void scan_maemo_for_media( intf_thread_t *p_intf )
98 GtkListStore *playlist_store = GTK_LIST_STORE( p_intf->p_sys->p_playlist_store );
102 for( int i = 0; ppsz_media_dirs[i]; i++ )
104 find_media_in_dir( ppsz_media_dirs[i], &list );
105 msg_Dbg( p_intf, "Looking for media in %s", ppsz_media_dirs[i] );
108 list = g_list_first( list );
111 msg_Dbg( p_intf, "Adding : %s", (char *)list->data );
112 gtk_list_store_append( playlist_store, &iter );
113 gtk_list_store_set( playlist_store, &iter,
115 list = g_list_next( list );
119 static void find_media_in_dir( const char *psz_dir, GList **pp_list )
122 const gchar *psz_name;
125 dir = g_dir_open( psz_dir, 0, NULL );
128 while( ( psz_name = g_dir_read_name( dir ) ) != NULL )
130 psz_path = g_build_path( "/", psz_dir, psz_name, NULL );
131 if( g_file_test( psz_path, G_FILE_TEST_IS_DIR ) &&
132 !g_file_test( psz_path, G_FILE_TEST_IS_SYMLINK ) )
133 find_media_in_dir( psz_path, pp_list );
136 char *psz_ext = strrchr( psz_name, '.' );
140 for( int i = 0; ppsz_extensions[i]; i++ )
142 if( strcmp( psz_ext, ppsz_extensions[i] ) == 0 )
144 *pp_list = g_list_append( *pp_list, g_strdup( psz_path ) );