]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwidgets/wxwidgets.cpp
svg module: fix memleak.
[vlc] / modules / gui / wxwidgets / wxwidgets.cpp
index a5450b568f6dafd7170d6d658eecfe473185c926..a919fa3cb457cb1607661ff3817995a99452578b 100644 (file)
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
 #include <errno.h>                                                 /* ENOMEM */
-#include <string.h>                                            /* strerror() */
-#include <stdio.h>
 
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_interface.h>
 
 #ifdef HAVE_LOCALE_H
 #   include <locale.h>
 #endif
 
-#include "wxwidgets.h"
+#include "interface.hpp"
 
 /* Temporary hack */
 #if defined(WIN32) && defined(_WX_INIT_H_)
@@ -86,63 +88,83 @@ private:
 #define EMBED_TEXT N_("Embed video in interface")
 #define EMBED_LONGTEXT N_("Embed the video inside the interface instead " \
     "of having it in a separate window.")
-#define BOOKMARKS_TEXT N_("Show bookmarks dialog")
-#define BOOKMARKS_LONGTEXT N_("Show bookmarks dialog when the interface " \
-    "starts.")
-#define TASKBAR_TEXT N_("Show taskbar entry")
-#define TASKBAR_LONGTEXT N_("Show taskbar entry")
+#define BOOKMARKS_TEXT N_("Bookmarks dialog")
+#define BOOKMARKS_LONGTEXT N_("Show bookmarks dialog at startup" )
+#define EXTENDED_TEXT N_("Extended GUI")
+#define EXTENDED_LONGTEXT N_("Show extended GUI (equalizer, image adjust, "  \
+              "video filters...) at startup"  )
+#define TASKBAR_TEXT N_("Taskbar")
+#define TASKBAR_LONGTEXT N_("Show VLC on the taskbar")
 #define MINIMAL_TEXT N_("Minimal interface")
-#define MINIMAL_LONGTEXT N_("Use minimal interface, no toolbar, few menus")
+#define MINIMAL_LONGTEXT N_("Use minimal interface, with no toolbar and " \
+                "fewer menus.")
 #define SIZE_TO_VIDEO_TEXT N_("Size to video")
-#define SIZE_TO_VIDEO_LONGTEXT N_("Resize VLC to match the video resolution")
-#define SYSTRAY_TEXT N_("Show systray icon")
-#define SYSTRAY_LONGTEXT N_("Show systray icon")
+#define SIZE_TO_VIDEO_LONGTEXT N_("Resize VLC to match the video resolution.")
+#define SYSTRAY_TEXT N_("Systray icon")
+#define SYSTRAY_LONGTEXT N_("Show a systray icon for VLC")
+#define LABEL_TEXT N_("Show labels in toolbar")
+#define LABEL_LONGTEXT N_("Show labels below the icons in the toolbar.")
+
+#define PLAYLIST_TEXT N_("Playlist view" )
+#define PLAYLIST_LONGTEXT N_("There are two possible playlist views in the " \
+                "interface : the normal playlist (separate window), or an " \
+                "embedded playlist (within the main interface, but with " \
+                "less features). You can select which one will be available " \
+                "on the toolbar (or both)." )
+
+static const int pi_playlist_views[] = { 0,1,2 };
+static const char *const psz_playlist_views[] = {
+    N_("Normal" ), N_("Embedded" ), N_("Both") };
 
 vlc_module_begin();
-#ifdef WIN32
-    int i_score = 150;
-#else
-    int i_score = getenv( "DISPLAY" ) == NULL ? 15 : 150;
-#endif
-    set_shortname( (char*) "wxWidgets" );
-    set_description( (char *) _("wxWidgets interface module") );
+    set_shortname( "wxWidgets" );
+    set_description( N_("wxWidgets interface module") );
     set_category( CAT_INTERFACE );
-    set_subcategory( SUBCAT_INTERFACE_GENERAL );
-    set_capability( "interface", i_score );
+    set_subcategory( SUBCAT_INTERFACE_MAIN );
+    set_capability( "interface", 150 );
     set_callbacks( Open, Close );
     add_shortcut( "wxwindows" );
     add_shortcut( "wxwin" );
     add_shortcut( "wx" );
     add_shortcut( "wxwidgets" );
-    set_program( "wxvlc" );
 
     add_bool( "wx-embed", 1, NULL,
-              EMBED_TEXT, EMBED_LONGTEXT, VLC_FALSE );
-    add_deprecated( "wxwin-enbed", VLC_FALSE); /*Deprecated since 0.8.4*/
+              EMBED_TEXT, EMBED_LONGTEXT, false );
+        add_deprecated_alias( "wxwin-enbed" ); /*Deprecated since 0.8.4*/
     add_bool( "wx-bookmarks", 0, NULL,
-              BOOKMARKS_TEXT, BOOKMARKS_LONGTEXT, VLC_FALSE );
-    add_deprecated( "wxwin-bookmarks", VLC_FALSE); /*Deprecated since 0.8.4*/
+              BOOKMARKS_TEXT, BOOKMARKS_LONGTEXT, false );
+        add_deprecated_alias( "wxwin-bookmarks" ); /*Deprecated since 0.8.4*/
     add_bool( "wx-taskbar", 1, NULL,
-              TASKBAR_TEXT, TASKBAR_LONGTEXT, VLC_FALSE );
-    add_deprecated( "wxwin-taskbar", VLC_FALSE); /*Deprecated since 0.8.4*/
+              TASKBAR_TEXT, TASKBAR_LONGTEXT, false );
+        add_deprecated_alias( "wxwin-taskbar" ); /*Deprecated since 0.8.4*/
+    add_bool( "wx-extended", 0, NULL,
+              EXTENDED_TEXT, EXTENDED_LONGTEXT, false );
     add_bool( "wx-minimal", 0, NULL,
-              MINIMAL_TEXT, MINIMAL_LONGTEXT, VLC_TRUE );
-    add_deprecated( "wxwin-minimal", VLC_FALSE); /*Deprecated since 0.8.4*/
+              MINIMAL_TEXT, MINIMAL_LONGTEXT, true );
+        add_deprecated_alias( "wxwin-minimal" ); /*Deprecated since 0.8.4*/
     add_bool( "wx-autosize", 1, NULL,
-              SIZE_TO_VIDEO_TEXT, SIZE_TO_VIDEO_LONGTEXT, VLC_TRUE );
-    add_deprecated( "wxwin-autosize", VLC_FALSE); /*Deprecated since 0.8.4*/
+              SIZE_TO_VIDEO_TEXT, SIZE_TO_VIDEO_LONGTEXT, true );
+        add_deprecated_alias( "wxwin-autosize" ); /*Deprecated since 0.8.4*/
+    add_integer( "wx-playlist-view", 0, NULL, PLAYLIST_TEXT, PLAYLIST_LONGTEXT,
+             false );
+        change_integer_list( pi_playlist_views, psz_playlist_views, 0 );
+/* wxCocoa pretends to support this, but at least 2.6.x doesn't */
+#ifndef __APPLE__
 #ifdef wxHAS_TASK_BAR_ICON
     add_bool( "wx-systray", 0, NULL,
-              SYSTRAY_TEXT, SYSTRAY_LONGTEXT, VLC_FALSE );
-    add_deprecated( "wxwin-systray", VLC_FALSE); /*Deprecated since 0.8.4*/
+              SYSTRAY_TEXT, SYSTRAY_LONGTEXT, false );
+        add_deprecated_alias( "wxwin-systray" ); /*Deprecated since 0.8.4*/
+#endif
 #endif
+    add_bool( "wx-labels", 0, NULL, LABEL_TEXT, LABEL_LONGTEXT, true);
     add_string( "wx-config-last", NULL, NULL,
-                "last config", "last config", VLC_TRUE );
+                N_("last config"), N_("last config"), true );
         change_autosave();
-    add_deprecated( "wxwin-config-last", VLC_FALSE); /*Deprecated since 0.8.4*/
+        change_internal();
+        add_deprecated_alias( "wxwin-config-last" ); /*Deprecated since 0.8.4*/
 
     add_submodule();
-    set_description( _("wxWidgets dialogs provider") );
+    set_description( N_("wxWidgets dialogs provider") );
     set_capability( "dialogs provider", 50 );
     set_callbacks( OpenDialogs, Close );
 
@@ -157,14 +179,18 @@ vlc_module_end();
 static int Open( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
-
+    /* Test in we have an X*/
+#if defined HAVE_GETENV && (defined __WXGTK__ || defined __WXX11)
+    if( !getenv( "DISPLAY" ) )
+    {
+        msg_Err( p_intf, "no X server");
+        return VLC_EGENERIC;
+    }
+#endif
     /* Allocate instance and initialize some members */
     p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
     if( p_intf->p_sys == NULL )
-    {
-        msg_Err( p_intf, "out of memory" );
         return VLC_ENOMEM;
-    }
     memset( p_intf->p_sys, 0, sizeof( intf_sys_t ) );
 
     p_intf->pf_run = Run;
@@ -176,17 +202,12 @@ static int Open( vlc_object_t *p_this )
 
     p_intf->p_sys->p_input = NULL;
     p_intf->p_sys->i_playing = -1;
-    p_intf->p_sys->b_slider_free = 1;
-    p_intf->p_sys->i_slider_pos = p_intf->p_sys->i_slider_oldpos = 0;
 
     p_intf->p_sys->p_popup_menu = NULL;
     p_intf->p_sys->p_video_window = NULL;
 
     p_intf->pf_show_dialog = NULL;
 
-    /* We support play on start */
-    p_intf->b_play = VLC_TRUE;
-
     p_intf->p_sys->b_video_autosize =
         config_GetInt( p_intf, "wx-autosize" );
 
@@ -210,9 +231,9 @@ static void Close( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
 
-    vlc_mutex_lock( &p_intf->object_lock );
-    p_intf->b_dead = VLC_TRUE;
-    vlc_mutex_unlock( &p_intf->object_lock );
+    vlc_object_lock( p_intf );
+    p_intf->b_dead = true;
+    vlc_object_unlock( p_intf );
 
     if( p_intf->pf_show_dialog )
     {
@@ -258,7 +279,7 @@ static void Run( intf_thread_t *p_intf )
 
         /* Create a new thread for wxWidgets */
         if( vlc_thread_create( p_intf, "Skins Dialogs Thread",
-                               Init, 0, VLC_TRUE ) )
+                               Init, 0, true ) )
         {
             msg_Err( p_intf, "cannot create Skins Dialogs Thread" );
             p_intf->pf_show_dialog = NULL;
@@ -329,7 +350,7 @@ bool Instance::OnInit()
     /* Initialization of i18n stuff.
      * Usefull for things we don't have any control over, like wxWidgets
      * provided facilities (eg. open file dialog) */
-    locale.Init( wxLANGUAGE_DEFAULT );
+    locale.Init( wxLANGUAGE_DEFAULT, wxLOCALE_LOAD_DEFAULT );
 
     /* Load saved window settings */
     p_intf->p_sys->p_window_settings = new WindowSettings( p_intf );
@@ -366,19 +387,6 @@ bool Instance::OnInit()
     /* OK, initialization is over */
     vlc_thread_ready( p_intf );
 
-    /* Check if we need to start playing */
-    if( !p_intf->pf_show_dialog && p_intf->b_play )
-    {
-        playlist_t *p_playlist =
-            (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
-                                           FIND_ANYWHERE );
-        if( p_playlist )
-        {
-            playlist_LockControl( p_playlist, PLAYLIST_AUTOPLAY );
-            vlc_object_release( p_playlist );
-        }
-    }
-
     /* Return TRUE to tell program to continue (FALSE would terminate) */
     return TRUE;
 }
@@ -391,7 +399,7 @@ int Instance::OnExit()
     if( p_intf->pf_show_dialog )
     {
          /* We need to manually clean up the dialogs class */
-         if( p_intf->p_sys->p_wxwindow ) delete p_intf->p_sys->p_wxwindow;
+         delete p_intf->p_sys->p_wxwindow;
     }
 
 #if (wxCHECK_VERSION(2,5,0))
@@ -468,7 +476,9 @@ WindowSettings::WindowSettings( intf_thread_t *_p_intf )
 
         id = strtol( psz, &psz, 0 );
         if( *psz != ',' ) /* broken cfg */
+        {
             goto invalid;
+        }
         psz++;
 
         for( i = 0; i < 4; i++ )
@@ -478,13 +488,17 @@ WindowSettings::WindowSettings( intf_thread_t *_p_intf )
             if( i < 3 )
             {
                 if( *psz != ',' )
+                {
                     goto invalid;
+                }
                 psz++;
             }
             else
             {
                 if( *psz != ')' )
+                {
                     goto invalid;
+                }
             }
         }
         if( id == ID_SCREEN )
@@ -509,19 +523,25 @@ WindowSettings::WindowSettings( intf_thread_t *_p_intf )
     }
 
     if( i_screen_w <= 0 || i_screen_h <= 0 )
+    {
         goto invalid;
+    }
 
     for( i = 0; i < ID_MAX; i++ )
     {
         if( !b_valid[i] )
             continue;
         if( position[i].x < 0 || position[i].y < 0 )
+        {
             goto invalid;
-        if( size[i].x <= 0 || size[i].y <= 0 )
+        }
+        if( i != ID_SMALL_PLAYLIST && (size[i].x <= 0 || size[i].y <= 0)  )
+        {
             goto invalid;
+        }
     }
 
-    if( psz_org ) free( psz_org );
+    free( psz_org );
     return;
 
 invalid:
@@ -533,7 +553,7 @@ invalid:
         position[i] = wxDefaultPosition;
         size[i] = wxDefaultSize;
     }
-    if( psz_org ) free( psz_org );
+    free( psz_org );
 }
 
 
@@ -556,7 +576,7 @@ WindowSettings::~WindowSettings( )
                                      size[i].x, size[i].y );
     }
 
-    config_PutPsz( p_intf, "wx-config-last", sCfg.mb_str() );
+    config_PutPsz( p_intf, "wx-config-last", sCfg.mb_str(wxConvUTF8) );
 }
 
 void WindowSettings::SetScreen( int i_screen_w, int i_screen_h )