]> git.sesse.net Git - vlc/blob - modules/gui/hildon/maemo_interface.c
Make the maemo interface a bit more useable
[vlc] / modules / gui / hildon / maemo_interface.c
1 /*****************************************************************************
2  * maemo_interface.c : Interface creation of the maemo plugin
3  *****************************************************************************
4  * Copyright (C) 2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Lejeune <phytos@videolan.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include <vlc_common.h>
25
26 #include <gtk/gtk.h>
27
28 #include "maemo.h"
29 #include "maemo_callbacks.h"
30 #include "maemo_interface.h"
31
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 );
34
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 };
40
41 static const char *ppsz_media_dirs[] =
42     { "/media/mmc1", "/media/mmc2", "/home/user/MyDocs/.videos", NULL };
43
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 ), \
48                       p_intf );
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 ), \
53                       p_intf );
54 #define ADD_SEPARATOR \
55     item = gtk_separator_menu_item_new(); \
56     gtk_menu_append( main_menu, item );
57
58 void create_menu( intf_thread_t *p_intf )
59 {
60     /* Needed variables */
61     GtkWidget *main_menu;
62     GtkWidget *item;
63     int i_skip;
64
65     /* Creating the main menu */
66     main_menu = gtk_menu_new();
67
68     /* Getting ffmpeg-skip-frame value */
69     i_skip = config_GetInt( p_intf, "ffmpeg-skip-frame" );
70
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 );
75     ADD_SEPARATOR;
76     ADD_MENU_ITEM( "Take a snapshot", snapshot_cb );
77     ADD_CHECK_MENU_ITEM( "Drop frames", dropframe_cb );
78     if( i_skip )
79         gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( item ), true );
80     ADD_SEPARATOR;
81     ADD_MENU_ITEM( "Close", delete_event_cb );
82
83     hildon_window_set_menu( HILDON_WINDOW( p_intf->p_sys->p_main_window ),
84                             GTK_MENU( main_menu ) );
85
86     gtk_widget_show_all( main_menu );
87 }
88
89 #undef ADD_MENU
90 #undef ADD_CHECK_MENU_ITEM
91 #undef ADD_SEPARATOR
92
93 void create_playlist( intf_thread_t *p_intf )
94 {
95     GtkWidget *playlist;
96     GtkWidget *scroll;
97     GtkListStore *playlist_store;
98     GtkTreeViewColumn *col;
99     GtkCellRenderer *renderer;
100
101     playlist = gtk_tree_view_new();
102
103     playlist_store = gtk_list_store_new( 1, G_TYPE_STRING );
104     p_intf->p_sys->p_playlist_store = playlist_store;
105
106     gtk_tree_view_set_model( GTK_TREE_VIEW( playlist ),
107                              GTK_TREE_MODEL( playlist_store ) );
108
109     renderer = gtk_cell_renderer_text_new();
110     col = gtk_tree_view_column_new_with_attributes( "File", renderer,
111                                                     "text", 0, NULL );
112     gtk_tree_view_append_column( GTK_TREE_VIEW( playlist ), col );
113
114     g_object_set( playlist, "headers-visible", TRUE, NULL );
115     scan_maemo_for_media( p_intf );
116
117     scroll = gtk_scrolled_window_new( NULL, NULL );
118     gtk_container_add( GTK_CONTAINER( scroll ), playlist );
119
120     p_intf->p_sys->p_playlist_window = scroll;
121
122     g_signal_connect( playlist, "row-activated",
123                       G_CALLBACK( pl_row_activated_cb ), NULL );
124 }
125
126 static void scan_maemo_for_media( intf_thread_t *p_intf )
127 {
128     GtkListStore *playlist_store = GTK_LIST_STORE( p_intf->p_sys->p_playlist_store );
129     GList *list = NULL;
130     GtkTreeIter iter;
131
132     for( int i = 0; ppsz_media_dirs[i]; i++ )
133     {
134         find_media_in_dir( ppsz_media_dirs[i], &list );
135         msg_Dbg( p_intf, "Looking for media in %s", ppsz_media_dirs[i] );
136     }
137
138     list = g_list_first( list );
139     while( list )
140     {
141         msg_Dbg( p_intf, "Adding : %s", (char *)list->data );
142         gtk_list_store_append( playlist_store, &iter );
143         gtk_list_store_set( playlist_store, &iter,
144                             0, list->data, -1 );
145         list = g_list_next( list );
146     }
147 }
148
149 static void find_media_in_dir( const char *psz_dir, GList **pp_list )
150 {
151     GDir *dir = NULL;
152     const gchar *psz_name;
153     char *psz_path;
154
155     dir = g_dir_open( psz_dir, 0, NULL );
156     if( !dir )
157         return;
158     while( ( psz_name = g_dir_read_name( dir ) ) != NULL )
159     {
160         psz_path = g_build_path( "/", psz_dir, psz_name, NULL );
161         if( g_file_test( psz_path, G_FILE_TEST_IS_DIR ) &&
162             !g_file_test( psz_path, G_FILE_TEST_IS_SYMLINK ) )
163             find_media_in_dir( psz_path, pp_list );
164         else
165         {
166             char *psz_ext = strrchr( psz_name, '.' );
167             if( psz_ext )
168             {
169                 psz_ext++;
170                 for( int i = 0; ppsz_extensions[i]; i++ )
171                 {
172                     if( strcmp( psz_ext, ppsz_extensions[i] ) == 0 )
173                     {
174                         *pp_list = g_list_append( *pp_list, g_strdup( psz_path ) );
175                         break;
176                     }
177                 }
178             }
179         }
180         g_free( psz_path );
181     }
182
183     g_dir_close( dir );
184     return;
185 }