[vlc-devel] [PATCH 11/13] npapi: switch to vlc_player_options

Sergey Radionov rsatom at gmail.com
Fri Jan 13 04:54:35 CET 2012


---
 npapi/vlcplugin_base.cpp |   17 +++++------------
 npapi/vlcplugin_base.h   |    8 ++------
 npapi/vlcplugin_gtk.cpp  |    6 +++---
 npapi/vlcplugin_mac.cpp  |    4 ++--
 npapi/vlcplugin_win.cpp  |    4 +---
 npapi/vlcplugin_xcb.cpp  |    6 +++---
 npapi/vlcshell.cpp       |   12 ++++++------
 7 files changed, 22 insertions(+), 35 deletions(-)

diff --git a/npapi/vlcplugin_base.cpp b/npapi/vlcplugin_base.cpp
index 5447fc6..847490c 100644
--- a/npapi/vlcplugin_base.cpp
+++ b/npapi/vlcplugin_base.cpp
@@ -350,12 +350,7 @@ void EventObj::unhook_manager( void *userdata )
 VlcPluginBase::VlcPluginBase( NPP instance, NPuint16_t mode ) :
     i_npmode(mode),
     b_stream(0),
-    b_autoplay(1),
-    b_toolbar(1),
-    b_allowfullscreen(1),
-    psz_text(NULL),
     psz_target(NULL),
-    psz_bgcolor("#000000"),
     playlist_index(-1),
     libvlc_instance(NULL),
     libvlc_media_list(NULL),
@@ -457,18 +452,17 @@ NPError VlcPluginBase::init(int argc, char* const argn[], char* const argv[])
         }
         else if( !strcmp( argn[i], "text" ) )
         {
-            free( psz_text );
-            psz_text = strdup( argv[i] );
+            set_bg_text( argv[i] );
         }
         else if( !strcmp( argn[i], "autoplay")
               || !strcmp( argn[i], "autostart") )
         {
-            b_autoplay = boolValue(argv[i]);
+            set_autoplay(boolValue(argv[i]));
         }
         else if( !strcmp( argn[i], "fullscreen" )
               || !strcmp( argn[i], "allowfullscreen" ) )
         {
-            b_allowfullscreen = boolValue(argv[i]);
+            set_enable_fs( boolValue(argv[i]) );
         }
         else if( !strcmp( argn[i], "mute" ) )
         {
@@ -491,11 +485,11 @@ NPError VlcPluginBase::init(int argc, char* const argn[], char* const argv[])
         }
         else if( !strcmp( argn[i], "toolbar" ) )
         {
-            b_toolbar = boolValue(argv[i]);
+            set_show_toolbar( boolValue(argv[i]) );
         }
         else if( !strcmp( argn[i], "bgcolor" ) )
         {
-            psz_bgcolor = strdup( argv[i] );
+            set_bg_color( argv[i] );
         }
     }
 
@@ -562,7 +556,6 @@ VlcPluginBase::~VlcPluginBase()
 {
     free(psz_baseURL);
     free(psz_target);
-    free(psz_text);
 
     if( libvlc_media_player )
     {
diff --git a/npapi/vlcplugin_base.h b/npapi/vlcplugin_base.h
index d26e253..174f765 100644
--- a/npapi/vlcplugin_base.h
+++ b/npapi/vlcplugin_base.h
@@ -81,6 +81,7 @@
 #include <assert.h>
 
 #include "control/nporuntime.h"
+#include "../common/vlc_player_options.h"
 
 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
     typedef uint16 NPuint16_t;
@@ -189,7 +190,7 @@ typedef enum vlc_toolbar_clicked_e {
     clicked_Unmute
 } vlc_toolbar_clicked_t;
 
-class VlcPluginBase
+class VlcPluginBase: public vlc_player_options
 {
 protected:
 
@@ -222,10 +223,6 @@ public:
 
     /* plugin properties */
     int      b_stream;
-    int      b_autoplay;
-    int      b_toolbar;
-    int      b_allowfullscreen;
-    char *   psz_text;
     char *   psz_target;
 
     void playlist_play()
@@ -321,7 +318,6 @@ protected:
 
     /* display settings */
     NPWindow  npwindow;
-    const char *psz_bgcolor;
 
     static void eventAsync(void *);
 
diff --git a/npapi/vlcplugin_gtk.cpp b/npapi/vlcplugin_gtk.cpp
index 77247ac..1d24422 100644
--- a/npapi/vlcplugin_gtk.cpp
+++ b/npapi/vlcplugin_gtk.cpp
@@ -104,7 +104,7 @@ void VlcPluginGtk::do_set_fullscreen(bool yes)
 
 void VlcPluginGtk::set_fullscreen(int yes)
 {
-    if (!b_allowfullscreen) return;
+    if (!get_enable_fs()) return;
     if (yes == is_fullscreen) return;
     if (yes) {
         gtk_widget_show(fullscreen_win);
@@ -213,7 +213,7 @@ void VlcPluginGtk::popup_menu()
     g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(menu_handler), this);
     gtk_menu_shell_append(GTK_MENU_SHELL(popupmenu), menuitem);
     /* set fullscreen */
-    if (b_allowfullscreen) {
+    if (get_enable_fs()) {
         menuitem = gtk_image_menu_item_new_from_stock(
                                     GTK_STOCK_FULLSCREEN, NULL);
         g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(menu_handler), this);
@@ -357,7 +357,7 @@ bool VlcPluginGtk::create_windows()
 
     Window socket = (Window) npwindow.window;
     GdkColor color_bg;
-    gdk_color_parse(psz_bgcolor, &color_bg);
+    gdk_color_parse(get_bg_color(), &color_bg);
 
     parent = gtk_plug_new(socket);
     gtk_widget_modify_bg(parent, GTK_STATE_NORMAL, &color_bg);
diff --git a/npapi/vlcplugin_mac.cpp b/npapi/vlcplugin_mac.cpp
index 1c79d39..0e24e12 100644
--- a/npapi/vlcplugin_mac.cpp
+++ b/npapi/vlcplugin_mac.cpp
@@ -42,14 +42,14 @@ void VlcPluginMac::set_player_window()
 
 void VlcPluginMac::toggle_fullscreen()
 {
-    if (!b_allowfullscreen) return;
+    if (!get_enable_fs()) return;
     if (playlist_isplaying())
         libvlc_toggle_fullscreen(libvlc_media_player);
 }
 
 void VlcPluginMac::set_fullscreen(int yes)
 {
-    if (!b_allowfullscreen) return;
+    if (!get_enable_fs()) return;
     if (playlist_isplaying())
         libvlc_set_fullscreen(libvlc_media_player, yes);
 }
diff --git a/npapi/vlcplugin_win.cpp b/npapi/vlcplugin_win.cpp
index a0ae09d..656c711 100644
--- a/npapi/vlcplugin_win.cpp
+++ b/npapi/vlcplugin_win.cpp
@@ -87,7 +87,7 @@ LRESULT CALLBACK VlcPluginWin::NPWndProcR(HWND hWnd, UINT uMsg, WPARAM wParam, L
 
 VlcPluginWin::VlcPluginWin(NPP instance, NPuint16_t mode) :
     VlcPluginBase(instance, mode), _NPWndProc(0),
-    _WindowsManager(DllGetModule(), _ViewRC)
+    _WindowsManager(DllGetModule(), _ViewRC, this)
 {
     _ViewRC.hDeFullscreenBitmap =
         LoadImage(DllGetModule(), MAKEINTRESOURCE(3),
@@ -125,13 +125,11 @@ VlcPluginWin::~VlcPluginWin()
 
 void VlcPluginWin::toggle_fullscreen()
 {
-    if (!b_allowfullscreen) return;
     _WindowsManager.ToggleFullScreen();
 }
 
 void VlcPluginWin::set_fullscreen(int yes)
 {
-    if (!b_allowfullscreen) return;
     if(yes){
         _WindowsManager.StartFullScreen();
     }
diff --git a/npapi/vlcplugin_xcb.cpp b/npapi/vlcplugin_xcb.cpp
index c14ecf5..3d1e68c 100644
--- a/npapi/vlcplugin_xcb.cpp
+++ b/npapi/vlcplugin_xcb.cpp
@@ -48,14 +48,14 @@ void VlcPluginXcb::set_player_window()
 
 void VlcPluginXcb::toggle_fullscreen()
 {
-    if (!b_allowfullscreen) return;
+    if (!get_enable_fs()) return;
     if (playlist_isplaying())
         libvlc_toggle_fullscreen(libvlc_media_player);
 }
 
 void VlcPluginXcb::set_fullscreen(int yes)
 {
-    if (!b_allowfullscreen) return;
+    if (!get_enable_fs()) return;
     if (playlist_isplaying())
         libvlc_set_fullscreen(libvlc_media_player,yes);
 }
@@ -83,7 +83,7 @@ bool VlcPluginXcb::create_windows()
     xcb_atom_t xembed_info_atom = xcb_intern_atom_reply(conn, cookie, NULL)->atom;
 
     /* create windows */
-    /* TODO: respect psz_bgcolor */
+    /* TODO: respect get_bg_color() */
     const uint32_t parent_values[] = {0x0FFFFF};
     parent = xcb_generate_id(conn);
     xcb_create_window(conn, XCB_COPY_FROM_PARENT, parent, socket,
diff --git a/npapi/vlcshell.cpp b/npapi/vlcshell.cpp
index de74420..71f9baa 100644
--- a/npapi/vlcshell.cpp
+++ b/npapi/vlcshell.cpp
@@ -188,7 +188,7 @@ int16_t NPP_HandleEvent( NPP instance, void * event )
 
                 if( ! hasVout )
                 {
-                    /* draw the text from p_plugin->psz_text */
+                    /* draw the text from get_bg_text() */
                     ForeColor(blackColor);
                     PenMode( patCopy );
 
@@ -206,8 +206,8 @@ int16_t NPP_HandleEvent( NPP instance, void * event )
 
                     ForeColor(whiteColor);
                     MoveTo( (npwindow.width-80)/ 2  , npwindow.height / 2 );
-                    if( p_plugin->psz_text )
-                        DrawText( p_plugin->psz_text, 0, strlen(p_plugin->psz_text) );
+                    if( !p_plugin->get_bg_text().empty() )
+                        DrawText( p_plugin->get_bg_text().c_str(), 0, p_plugin->get_bg_text().length() );
                 }
             }
             return true;
@@ -350,7 +350,7 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
             p_plugin->resize_windows();
 
             /* now set plugin state to that requested in parameters */
-            p_plugin->set_toolbar_visible( p_plugin->b_toolbar );
+            p_plugin->set_toolbar_visible( p_plugin->get_show_toolbar() );
 
             /* handle streams properly */
             if( !p_plugin->b_stream )
@@ -359,7 +359,7 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
                 {
                     if( p_plugin->playlist_add( p_plugin->psz_target ) != -1 )
                     {
-                        if( p_plugin->b_autoplay )
+                        if( p_plugin->get_autoplay() )
                         {
                             p_plugin->playlist_play();
                         }
@@ -459,7 +459,7 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
 
     if( p_plugin->playlist_add( stream->url ) != -1 )
     {
-        if( p_plugin->b_autoplay )
+        if( p_plugin->get_autoplay() )
         {
             p_plugin->playlist_play();
         }
-- 
1.7.7.1.msysgit.0




More information about the vlc-devel mailing list