Commit 0f1503b4 authored by Gildas Bazin's avatar Gildas Bazin

hildon: add a slightly more useful menu to the maemo interface

parent 49edd4a7
......@@ -5,4 +5,5 @@ SOURCES_hildon = maemo.c \
maemo_input.c \
maemo_input.h \
maemo_interface.c \
maemo_interface.h
maemo_interface.h \
maemo_menus.c
......@@ -44,12 +44,11 @@
#include "maemo_interface.h"
/*****************************************************************************
* Local prototypes.
* Local prototypes
*****************************************************************************/
static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * );
static void *Thread ( void * );
static gboolean should_die ( gpointer );
static int OpenWindow ( vlc_object_t * );
static void CloseWindow ( vlc_object_t * );
static int ControlWindow ( vout_window_t *, int, va_list );
......@@ -78,7 +77,7 @@ vlc_module_end();
static int Open( vlc_object_t *p_this )
{
intf_thread_t *p_intf = (intf_thread_t *)p_this;
intf_sys_t *p_sys;;
intf_sys_t *p_sys;
vlc_value_t val;
if( !XInitThreads() )
......@@ -96,6 +95,7 @@ static int Open( vlc_object_t *p_this )
p_sys->p_video_window = NULL;
p_sys->p_control_window = NULL;
p_sys->b_fullscreen = false;
p_sys->i_event = 0;
vlc_spin_init( &p_sys->event_lock );
......@@ -123,6 +123,8 @@ static void Close( vlc_object_t *p_this )
intf_thread_t *p_intf = (intf_thread_t *)p_this;
var_Destroy (p_this->p_libvlc, "hildon-iface");
gtk_main_quit();
vlc_join (p_intf->p_sys->thread, NULL);
vlc_spin_destroy( &p_intf->p_sys->event_lock );
free( p_intf->p_sys );
......@@ -142,22 +144,16 @@ static gint quit_event( GtkWidget *widget, GdkEvent *event, gpointer data )
static void *Thread( void *obj )
{
intf_thread_t *p_intf = (intf_thread_t *)obj;
const char *p_args[] = { "vlc", "--sync" };
const char *p_args[] = { "vlc" };
int i_args = sizeof(p_args)/sizeof(char *);
char **pp_args = (char **)p_args;
HildonProgram *program;
HildonWindow *window;
GtkWidget *main_vbox;
GtkWidget *video;
GtkWidget *bottom_hbox;
GtkWidget *play_button;
GtkWidget *prev_button;
GtkWidget *next_button;
GtkWidget *stop_button;
GtkWidget *playlist_button;
GtkWidget *seekbar;
GtkWidget *main_vbox, *bottom_hbox;
GtkWidget *video, *seekbar;
GtkWidget *play_button, *prev_button, *next_button;
GtkWidget *stop_button, *playlist_button;
gtk_init( &i_args, &pp_args );
......@@ -188,6 +184,20 @@ static void *Thread( void *obj )
main_vbox = gtk_vbox_new( FALSE, 0 );
gtk_container_add( GTK_CONTAINER( window ), main_vbox );
// Menubar
GtkWidget *main_menu = create_menu( p_intf );
#ifdef HAVE_MAEMO
hildon_window_set_menu( HILDON_WINDOW( p_intf->p_sys->p_main_window ),
GTK_MENU( main_menu ) );
#else
GtkWidget *menu_bar = gtk_menu_bar_new ();
GtkWidget *item = gtk_menu_item_new_with_label ("Menu");
gtk_menu_bar_append(menu_bar, item);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), main_menu);
gtk_widget_show_all (menu_bar);
gtk_box_pack_start(GTK_BOX(main_vbox), menu_bar, FALSE, FALSE, 0);
#endif
// We put first the embedded video
video = gtk_event_box_new();
GdkColor black = {0,0,0,0};
......@@ -231,8 +241,6 @@ static void *Thread( void *obj )
// We add the hbox to the main vbox
gtk_box_pack_start( GTK_BOX( main_vbox ), bottom_hbox, FALSE, FALSE, 0 );
g_signal_connect( window, "delete_event",
G_CALLBACK( delete_event_cb ), NULL );
g_signal_connect( play_button, "clicked", G_CALLBACK( play_cb ), NULL );
g_signal_connect( stop_button, "clicked", G_CALLBACK( stop_cb ), NULL );
g_signal_connect( prev_button, "clicked", G_CALLBACK( prev_cb ), NULL );
......@@ -244,8 +252,6 @@ static void *Thread( void *obj )
gtk_widget_show_all( GTK_WIDGET( window ) );
gtk_widget_hide_all( p_intf->p_sys->p_playlist_window );
create_menu( p_intf );
#if 1
/* HACK: Only one X11 client can subscribe to mouse button press events.
* VLC currently handles those in the video display.
......@@ -259,41 +265,20 @@ static void *Thread( void *obj )
XSelectInput( dpy, w, attr.your_event_mask );
#endif
// Set callback with the vlc core
g_timeout_add( 1000 /* miliseconds */, should_die, p_intf );
var_AddCallback( p_intf->p_sys->p_playlist, "item-change",
item_changed_cb, p_intf );
var_AddCallback( p_intf->p_sys->p_playlist, "item-current",
playlist_current_cb, p_intf );
var_AddCallback( p_intf->p_sys->p_playlist, "activity",
activity_cb, p_intf );
// The embedded video is only ready after gtk_main and windows are shown
g_idle_add( interface_ready, p_intf );
gtk_main();
delete_input( p_intf );
var_DelCallback( p_intf->p_sys->p_playlist, "item-change",
item_changed_cb, p_intf );
var_DelCallback( p_intf->p_sys->p_playlist, "item-current",
playlist_current_cb, p_intf );
var_DelCallback( p_intf->p_sys->p_playlist, "activity",
activity_cb, p_intf );
delete_playlist( p_intf );
gtk_object_destroy( GTK_OBJECT( main_menu ) );
gtk_object_destroy( GTK_OBJECT( window ) );
return NULL;
}
static gboolean should_die( gpointer data )
{
intf_thread_t *p_intf = (intf_thread_t *)data;
if( !vlc_object_alive( p_intf ) )
gtk_main_quit();
return TRUE;
}
/**
* Video output window provider
*/
......
......@@ -29,6 +29,7 @@
#include <hildon/hildon-seekbar.h>
#include <hildon/hildon-banner.h>
#include <vlc_interface.h>
#include <vlc_playlist.h>
#include <vlc_input.h>
#include <vlc_vout.h>
......@@ -56,4 +57,10 @@ struct intf_sys_t
bool b_fullscreen;
GtkWidget *p_control_window;
GtkMenuItem *menu_input;
GtkMenuItem *menu_audio;
GtkMenuItem *menu_video;
};
GtkWidget *create_menu( intf_thread_t *p_intf );
......@@ -54,19 +54,6 @@ static intf_thread_t *get_intf_from_widget( GtkWidget *widget )
"p_intf" );
}
gboolean delete_event_cb( GtkWidget *widget,
GdkEvent *event,
gpointer user_data )
{
(void)event; (void)user_data;
intf_thread_t *p_intf = get_intf_from_widget( widget );
libvlc_Quit( p_intf->p_libvlc );
gtk_main_quit();
return TRUE;
}
void play_cb( GtkButton *button, gpointer user_data )
{
(void)user_data;
......
......@@ -26,10 +26,6 @@
#include <vlc_common.h>
#include <vlc_interface.h>
gboolean delete_event_cb( GtkWidget *widget,
GdkEvent *event,
gpointer user_data );
void play_cb( GtkButton *button, gpointer user_data );
void stop_cb( GtkButton *button, gpointer user_data );
void prev_cb( GtkButton *button, gpointer user_data );
......
......@@ -63,11 +63,11 @@ void post_event( intf_thread_t *p_intf, int i_event )
static gboolean process_events( gpointer data )
{
intf_thread_t *p_intf = (intf_thread_t *)data;
vlc_spin_lock( &p_intf->p_sys->event_lock );
int i_event;
int i_event = p_intf->p_sys->i_event;
vlc_spin_lock( &p_intf->p_sys->event_lock );
i_event = p_intf->p_sys->i_event;
p_intf->p_sys->i_event = 0;
vlc_spin_unlock( &p_intf->p_sys->event_lock );
if( !i_event ) return TRUE;
......
......@@ -28,6 +28,7 @@
#include "maemo.h"
#include "maemo_callbacks.h"
#include "maemo_interface.h"
#include "maemo_input.h"
static void scan_maemo_for_media ( intf_thread_t *p_intf );
static void find_media_in_dir ( const char *psz_dir, GList **pp_list );
......@@ -41,55 +42,6 @@ static const char *ppsz_extensions[] =
static const char *ppsz_media_dirs[] =
{ "/media/mmc1", "/media/mmc2", "/home/user/MyDocs/.videos", NULL };
#define ADD_MENU_ITEM( label, callback ) \
item = gtk_menu_item_new_with_label( label ); \
gtk_menu_append( main_menu, item ); \
g_signal_connect( GTK_OBJECT( item ), "activate", G_CALLBACK( callback ), \
p_intf );
#define ADD_CHECK_MENU_ITEM( label, callback ) \
item = gtk_check_menu_item_new_with_label( label ); \
gtk_menu_append( main_menu, item ); \
g_signal_connect( GTK_OBJECT( item ), "toggled", G_CALLBACK( callback ), \
p_intf );
#define ADD_SEPARATOR \
item = gtk_separator_menu_item_new(); \
gtk_menu_append( main_menu, item );
void create_menu( intf_thread_t *p_intf )
{
/* Needed variables */
GtkWidget *main_menu;
GtkWidget *item;
int i_skip;
/* Creating the main menu */
main_menu = gtk_menu_new();
/* Getting ffmpeg-skip-frame value */
i_skip = config_GetInt( p_intf, "ffmpeg-skip-frame" );
/* Filling the menu */
ADD_MENU_ITEM( "Open", open_cb );
ADD_MENU_ITEM( "Open Address", open_address_cb );
ADD_MENU_ITEM( "Open Webcam", open_webcam_cb );
ADD_SEPARATOR;
ADD_MENU_ITEM( "Take a snapshot", snapshot_cb );
ADD_CHECK_MENU_ITEM( "Drop frames", dropframe_cb );
if( i_skip )
gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM( item ), true );
ADD_SEPARATOR;
ADD_MENU_ITEM( "Close", delete_event_cb );
hildon_window_set_menu( HILDON_WINDOW( p_intf->p_sys->p_main_window ),
GTK_MENU( main_menu ) );
gtk_widget_show_all( main_menu );
}
#undef ADD_MENU
#undef ADD_CHECK_MENU_ITEM
#undef ADD_SEPARATOR
void create_playlist( intf_thread_t *p_intf )
{
GtkWidget *playlist;
......@@ -121,6 +73,24 @@ void create_playlist( intf_thread_t *p_intf )
g_signal_connect( playlist, "row-activated",
G_CALLBACK( pl_row_activated_cb ), NULL );
// Set callback with the vlc core
var_AddCallback( p_intf->p_sys->p_playlist, "item-change",
item_changed_cb, p_intf );
var_AddCallback( p_intf->p_sys->p_playlist, "item-current",
playlist_current_cb, p_intf );
var_AddCallback( p_intf->p_sys->p_playlist, "activity",
activity_cb, p_intf );
}
void delete_playlist( intf_thread_t *p_intf )
{
var_DelCallback( p_intf->p_sys->p_playlist, "item-change",
item_changed_cb, p_intf );
var_DelCallback( p_intf->p_sys->p_playlist, "item-current",
playlist_current_cb, p_intf );
var_DelCallback( p_intf->p_sys->p_playlist, "activity",
activity_cb, p_intf );
}
static void scan_maemo_for_media( intf_thread_t *p_intf )
......
......@@ -25,6 +25,5 @@
#include <vlc_common.h>
void create_menu( intf_thread_t *p_intf );
void create_playlist( intf_thread_t *p_intf );
void delete_playlist( intf_thread_t *p_intf );
/*****************************************************************************
* maemo_menus.c : menus creation for the maemo plugin
*****************************************************************************
* Copyright (C) 2010 the VideoLAN team
* $Id$
*
* Authors: Gildas Bazin <gbazin@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <vlc_common.h>
#include <vlc_interface.h>
#include <gtk/gtk.h>
#include "maemo.h"
#include "maemo_callbacks.h"
/*****************************************************************************
* Local prototypes
*****************************************************************************/
static GtkMenu *Populate( intf_thread_t *p_intf, GtkMenu *menu,
const char **varnames, vlc_object_t **objects,
unsigned int elements );
/*****************************************************************************
* Utility functions
*****************************************************************************/
static input_thread_t *get_input(intf_thread_t *p_intf)
{
return p_intf->p_sys->p_input;
}
static vlc_object_t *get_vout(intf_thread_t *p_intf)
{
return (vlc_object_t *)(p_intf->p_sys->p_input ?
input_GetVout( p_intf->p_sys->p_input ) : 0);
}
static vlc_object_t *get_aout(intf_thread_t *p_intf)
{
return (vlc_object_t *)(p_intf->p_sys->p_input ?
input_GetAout( p_intf->p_sys->p_input ) : 0);
}
static gint quit_event( GtkWidget *widget, gpointer data )
{
intf_thread_t *p_intf = (intf_thread_t *)data;
(void)widget;
libvlc_Quit( p_intf->p_libvlc );
return TRUE;
}
/*****************************************************************************
* Definitions of variables for the dynamic menus
*****************************************************************************/
#define SIZE_LIST 20
#define PUSH_VAR( var ) \
ppsz_varnames[index] = var; \
p_objects[index] = VLC_OBJECT(p_object); \
if(index < SIZE_LIST - 1) index++; \
ppsz_varnames[index] = 0; p_objects[index] = 0;
#define PUSH_INPUTVAR( var ) \
ppsz_varnames[index] = var; \
p_objects[index] = VLC_OBJECT(p_input); \
if(index < SIZE_LIST - 1) index++; \
ppsz_varnames[index] = 0; p_objects[index] = 0;
#define ADD_MENU_ITEM( label, callback ) \
item = gtk_menu_item_new_with_label( label ); \
gtk_menu_append( main_menu, item ); \
g_signal_connect( GTK_OBJECT( item ), "activate", G_CALLBACK( callback ), \
p_intf );
#define ADD_SEPARATOR() \
item = gtk_separator_menu_item_new(); \
gtk_menu_append( main_menu, item );
static GtkMenu *create_video_menu( intf_thread_t *p_intf )
{
vlc_object_t *p_object = get_vout(p_intf);
input_thread_t *p_input = get_input(p_intf);;
vlc_object_t *p_objects[SIZE_LIST];
const char *ppsz_varnames[SIZE_LIST];
int index = 0;
PUSH_INPUTVAR( "video-es" );
PUSH_INPUTVAR( "spu-es" );
PUSH_VAR( "fullscreen" );
PUSH_VAR( "video-wallpaper" );
PUSH_VAR( "video-snapshot" );
PUSH_VAR( "zoom" );
PUSH_VAR( "autoscale" );
PUSH_VAR( "aspect-ratio" );
PUSH_VAR( "crop" );
PUSH_VAR( "deinterlace" );
PUSH_VAR( "deinterlace-mode" );
PUSH_VAR( "postprocess" );
GtkWidget *menu = gtk_menu_new();
return Populate( p_intf, GTK_MENU(menu), ppsz_varnames, p_objects, index );
}
static GtkMenu *create_audio_menu( intf_thread_t *p_intf )
{
vlc_object_t *p_object = get_aout(p_intf);
input_thread_t *p_input = get_input(p_intf);;
vlc_object_t *p_objects[SIZE_LIST];
const char *ppsz_varnames[SIZE_LIST];
int index = 0;
PUSH_INPUTVAR( "audio-es" );
PUSH_VAR( "audio-channels" );
PUSH_VAR( "audio-device" );
PUSH_VAR( "visual" );
GtkWidget *menu = gtk_menu_new();
return Populate( p_intf, GTK_MENU(menu), ppsz_varnames, p_objects, index );
}
static GtkMenu *create_input_menu( intf_thread_t *p_intf )
{
input_thread_t *p_object = get_input(p_intf);
vlc_object_t *p_objects[SIZE_LIST];
const char *ppsz_varnames[SIZE_LIST];
int index = 0;
PUSH_VAR( "bookmark" );
PUSH_VAR( "title" );
PUSH_VAR( "chapter" );
PUSH_VAR( "navigation" );
PUSH_VAR( "program" );
GtkWidget *menu = gtk_menu_new();
return Populate( p_intf, GTK_MENU(menu), ppsz_varnames, p_objects, index );
}
static void toplevel_menu_callback(GtkMenuItem *menuitem, gpointer data)
{
intf_thread_t *p_intf = (intf_thread_t *)data;
GtkMenu *(*pf_menu)(intf_thread_t *) = 0;
GtkMenu *menu;
if(menuitem == p_intf->p_sys->menu_input) pf_menu = create_input_menu;
else if(menuitem == p_intf->p_sys->menu_audio) pf_menu = create_audio_menu;
else if(menuitem == p_intf->p_sys->menu_video) pf_menu = create_video_menu;
else return;
menu = GTK_MENU(gtk_menu_item_get_submenu(menuitem));
if(menu) gtk_object_destroy( GTK_OBJECT(menu) );
menu = pf_menu(p_intf);
gtk_menu_item_set_submenu(menuitem, GTK_WIDGET(menu));
gtk_widget_show_all( GTK_WIDGET(menuitem) );
}
GtkWidget *create_menu( intf_thread_t *p_intf )
{
intf_sys_t *p_sys = p_intf->p_sys;
GtkWidget *main_menu, *item;
/* Creating the main menu */
main_menu = gtk_menu_new();
/* Filling the menu */
ADD_MENU_ITEM( "Open", open_cb );
ADD_MENU_ITEM( "Open Address", open_address_cb );
ADD_MENU_ITEM( "Open Webcam", open_webcam_cb );
ADD_SEPARATOR();
item = gtk_menu_item_new_with_label ("Playback");
p_sys->menu_input = GTK_MENU_ITEM(item);
gtk_menu_bar_append(main_menu, item);
g_signal_connect( GTK_OBJECT(item), "activate",
G_CALLBACK( toplevel_menu_callback ), p_intf );
item = gtk_menu_item_new_with_label ("Audio");
p_sys->menu_audio = GTK_MENU_ITEM(item);
gtk_menu_bar_append(main_menu, item);
g_signal_connect( GTK_OBJECT(item), "activate",
G_CALLBACK( toplevel_menu_callback ), p_intf );
item = gtk_menu_item_new_with_label ("Video");
p_sys->menu_video = GTK_MENU_ITEM(item);
gtk_menu_bar_append(main_menu, item);
g_signal_connect( GTK_OBJECT(item), "activate",
G_CALLBACK( toplevel_menu_callback ), p_intf );
toplevel_menu_callback(p_sys->menu_input, p_intf);
toplevel_menu_callback(p_sys->menu_video, p_intf);
toplevel_menu_callback(p_sys->menu_audio, p_intf);
ADD_SEPARATOR();
ADD_MENU_ITEM( "Exit", quit_event );
gtk_widget_show_all( main_menu );
return main_menu;
}
/*************************************************************************
* Builders for automenus
*************************************************************************/
enum
{
ITEM_NORMAL,
ITEM_CHECK,
ITEM_RADIO
};
typedef struct VlcMenuItemClass
{
GtkRadioMenuItemClass menuitemclass;
} VlcMenuItemClass;
typedef struct VlcMenuItem
{
GtkRadioMenuItem menuitem;
vlc_object_t *p_obj;
int i_type;
vlc_value_t val;
const char *psz_var;
} VlcMenuItem;
static void vlc_menu_item_destroy (GtkObject *object)
{
VlcMenuItem *menuitem = (VlcMenuItem *)object;
if(menuitem->i_type == VLC_VAR_STRING && menuitem->val.psz_string)
free(menuitem->val.psz_string);
gtk_object_destroy( object );
}
static void vlc_menu_item_class_init (VlcMenuItemClass *klass)
{
GtkObjectClass *object_class = (GtkObjectClass*)klass;
object_class->destroy = vlc_menu_item_destroy;
}
static void vlc_menu_item_init (VlcMenuItem *menuitem){(void)menuitem;}
static GtkType vlc_menu_item_get_type (void)
{
static GtkType vlc_menu_item_type = 0;
if (!vlc_menu_item_type)
{
static const GtkTypeInfo vlc_menu_item_info =
{
(char *)"VlcMenuItem",
sizeof (VlcMenuItem),
sizeof (VlcMenuItemClass),
(GtkClassInitFunc) vlc_menu_item_class_init,
(GtkObjectInitFunc) vlc_menu_item_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
vlc_menu_item_type = gtk_type_unique (GTK_TYPE_MENU_ITEM, &vlc_menu_item_info);
}
return vlc_menu_item_type;
}
static GtkType vlc_check_menu_item_get_type (void)
{
static GtkType vlc_check_menu_item_type = 0;
if (!vlc_check_menu_item_type)
{
static const GtkTypeInfo vlc_check_menu_item_info =
{
(char *)"VlcCheckMenuItem",
sizeof (VlcMenuItem),
sizeof (VlcMenuItemClass),
(GtkClassInitFunc) vlc_menu_item_class_init,
(GtkObjectInitFunc) vlc_menu_item_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
vlc_check_menu_item_type = gtk_type_unique (GTK_TYPE_CHECK_MENU_ITEM, &vlc_check_menu_item_info);
}
return vlc_check_menu_item_type;
}
static GtkType vlc_radio_menu_item_get_type (void)
{
static GtkType vlc_radio_menu_item_type = 0;
if (!vlc_radio_menu_item_type)
{
static const GtkTypeInfo vlc_radio_menu_item_info =
{
(char *)"VlcRadioMenuItem",
sizeof (VlcMenuItem),
sizeof (VlcMenuItemClass),
(GtkClassInitFunc) vlc_menu_item_class_init,
(GtkObjectInitFunc) vlc_menu_item_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};