]> git.sesse.net Git - vlc/blob - modules/gui/hildon/maemo_interface.c
macosx: disable extensions submenu when they are no items to display
[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 #include "maemo_input.h"
32
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 );
35
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 };
41
42 static const char *ppsz_media_dirs[] =
43     { "/media/mmc1", "/media/mmc2", "/home/user/MyDocs/.videos", NULL };
44
45 void create_playlist( intf_thread_t *p_intf )
46 {
47     GtkWidget *playlist;
48     GtkWidget *scroll;
49     GtkListStore *playlist_store;
50     GtkTreeViewColumn *col;
51     GtkCellRenderer *renderer;
52
53     playlist = gtk_tree_view_new();
54
55     playlist_store = gtk_list_store_new( 1, G_TYPE_STRING );
56     p_intf->p_sys->p_playlist_store = playlist_store;
57
58     gtk_tree_view_set_model( GTK_TREE_VIEW( playlist ),
59                              GTK_TREE_MODEL( playlist_store ) );
60
61     renderer = gtk_cell_renderer_text_new();
62     col = gtk_tree_view_column_new_with_attributes( "File", renderer,
63                                                     "text", 0, NULL );
64     gtk_tree_view_append_column( GTK_TREE_VIEW( playlist ), col );
65
66     g_object_set( playlist, "headers-visible", TRUE, NULL );
67     scan_maemo_for_media( p_intf );
68
69     scroll = gtk_scrolled_window_new( NULL, NULL );
70     gtk_container_add( GTK_CONTAINER( scroll ), playlist );
71
72     p_intf->p_sys->p_playlist_window = scroll;
73
74     g_signal_connect( playlist, "row-activated",
75                       G_CALLBACK( pl_row_activated_cb ), NULL );
76
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 );
84 }
85
86 void delete_playlist( intf_thread_t *p_intf )
87 {
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 );
94 }
95
96 static void scan_maemo_for_media( intf_thread_t *p_intf )
97 {
98     GtkListStore *playlist_store = GTK_LIST_STORE( p_intf->p_sys->p_playlist_store );
99     GList *list = NULL;
100     GtkTreeIter iter;
101
102     for( int i = 0; ppsz_media_dirs[i]; i++ )
103     {
104         find_media_in_dir( ppsz_media_dirs[i], &list );
105         msg_Dbg( p_intf, "Looking for media in %s", ppsz_media_dirs[i] );
106     }
107
108     list = g_list_first( list );
109     while( list )
110     {
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,
114                             0, list->data, -1 );
115         list = g_list_next( list );
116     }
117 }
118
119 static void find_media_in_dir( const char *psz_dir, GList **pp_list )
120 {
121     GDir *dir = NULL;
122     const gchar *psz_name;
123     char *psz_path;
124
125     dir = g_dir_open( psz_dir, 0, NULL );
126     if( !dir )
127         return;
128     while( ( psz_name = g_dir_read_name( dir ) ) != NULL )
129     {
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 );
134         else
135         {
136             char *psz_ext = strrchr( psz_name, '.' );
137             if( psz_ext )
138             {
139                 psz_ext++;
140                 for( int i = 0; ppsz_extensions[i]; i++ )
141                 {
142                     if( strcmp( psz_ext, ppsz_extensions[i] ) == 0 )
143                     {
144                         *pp_list = g_list_append( *pp_list, g_strdup( psz_path ) );
145                         break;
146                     }
147                 }
148             }
149         }
150         g_free( psz_path );
151     }
152
153     g_dir_close( dir );
154     return;
155 }