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"
32 static void scan_maemo_for_media ( intf_thread_t *p_intf );
33 static void find_media_in_dir ( const char *psz_dir, GList **pp_list );
35 static const char *ppsz_extensions[] =
36 { "aac", "flac", "m4a", "m4p", "mka", "mp1", "mp2", "mp3",
37 "ogg", "wav", "wma", "asf", "avi", "divx", "flv", "m1v",
38 "m2v", "m4v", "mkv", "mov", "mpeg", "mpeg1", "mpeg2", "mpeg4",
39 "mpg", "ogm", "wmv", NULL };
41 static const char *ppsz_media_dirs[] =
42 { "/media/mmc1", "/media/mmc2", "/home/user/MyDocs/.videos", NULL };
44 #define ADD_MENU_ITEM( label, callback ) \
45 item = gtk_menu_item_new_with_label( label ); \
46 gtk_menu_append( main_menu, item ); \
47 g_signal_connect( GTK_OBJECT( item ), "activate", G_CALLBACK( callback ), \
49 #define ADD_CHECK_MENU_ITEM( label, callback ) \
50 item = gtk_check_menu_item_new_with_label( label ); \
51 gtk_menu_append( main_menu, item ); \
52 g_signal_connect( GTK_OBJECT( item ), "toggled", G_CALLBACK( callback ), \
54 #define ADD_SEPARATOR \
55 item = gtk_separator_menu_item_new(); \
56 gtk_menu_append( main_menu, item );
58 void create_menu( intf_thread_t *p_intf )
60 /* Needed variables */
65 /* Creating the main menu */
66 main_menu = gtk_menu_new();
68 /* Getting ffmpeg-skip-frame value */
69 i_skip = config_GetInt( p_intf, "ffmpeg-skip-frame" );
71 /* Filling the menu */
72 ADD_MENU_ITEM( "Open", open_cb );
73 ADD_MENU_ITEM( "Open Address", open_address_cb );
74 ADD_MENU_ITEM( "Open Webcam", open_webcam_cb );
76 ADD_MENU_ITEM( "Take a snapshot", snapshot_cb );
77 ADD_CHECK_MENU_ITEM( "Drop frames", dropframe_cb );
79 gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( item ), true );
81 ADD_MENU_ITEM( "Close", delete_event_cb );
83 hildon_window_set_menu( HILDON_WINDOW( p_intf->p_sys->p_main_window ),
84 GTK_MENU( main_menu ) );
86 gtk_widget_show_all( main_menu );
90 #undef ADD_CHECK_MENU_ITEM
93 void create_playlist( intf_thread_t *p_intf )
97 GtkListStore *playlist_store;
98 GtkTreeViewColumn *col;
99 GtkCellRenderer *renderer;
101 playlist = gtk_tree_view_new();
103 playlist_store = gtk_list_store_new( 1, G_TYPE_STRING );
104 p_intf->p_sys->p_playlist_store = GTK_WIDGET( playlist_store );
106 gtk_tree_view_set_model( GTK_TREE_VIEW( playlist ),
107 GTK_TREE_MODEL( playlist_store ) );
109 renderer = gtk_cell_renderer_text_new();
110 col = gtk_tree_view_column_new_with_attributes( "File", renderer,
112 gtk_tree_view_append_column( GTK_TREE_VIEW( playlist ), col );
114 g_object_set( playlist, "headers-visible", TRUE, NULL );
115 scan_maemo_for_media( p_intf );
117 scroll = gtk_scrolled_window_new( NULL, NULL );
118 gtk_container_add( GTK_CONTAINER( scroll ), playlist );
120 gtk_notebook_append_page( GTK_NOTEBOOK( p_intf->p_sys->p_tabs ), scroll,
121 gtk_image_new_from_stock( "vlc-playlist",
122 GTK_ICON_SIZE_DIALOG ) );
123 gtk_notebook_set_tab_label_packing( GTK_NOTEBOOK( p_intf->p_sys->p_tabs ), scroll,
124 FALSE, FALSE, GTK_PACK_START );
126 g_signal_connect( playlist, "row-activated",
127 G_CALLBACK( pl_row_activated_cb ), NULL );
130 static void scan_maemo_for_media( intf_thread_t *p_intf )
132 GtkListStore *playlist_store = GTK_LIST_STORE( p_intf->p_sys->p_playlist_store );
136 for( int i = 0; ppsz_media_dirs[i]; i++ )
138 find_media_in_dir( ppsz_media_dirs[i], &list );
139 msg_Dbg( p_intf, "Looking for media in %s", ppsz_media_dirs[i] );
142 list = g_list_first( list );
145 msg_Dbg( p_intf, "Adding : %s", (char *)list->data );
146 gtk_list_store_append( playlist_store, &iter );
147 gtk_list_store_set( playlist_store, &iter,
149 list = g_list_next( list );
153 static void find_media_in_dir( const char *psz_dir, GList **pp_list )
156 const gchar *psz_name;
159 dir = g_dir_open( psz_dir, 0, NULL );
162 while( ( psz_name = g_dir_read_name( dir ) ) != NULL )
164 psz_path = g_build_path( "/", psz_dir, psz_name, NULL );
165 if( g_file_test( psz_path, G_FILE_TEST_IS_DIR ) &&
166 !g_file_test( psz_path, G_FILE_TEST_IS_SYMLINK ) )
167 find_media_in_dir( psz_path, pp_list );
170 char *psz_ext = strrchr( psz_name, '.' );
174 for( int i = 0; ppsz_extensions[i]; i++ )
176 if( strcmp( psz_ext, ppsz_extensions[i] ) == 0 )
178 *pp_list = g_list_append( *pp_list, g_strdup( psz_path ) );