[vlc-devel] commit: Extensions/Qt: add cannotLoad() flag ( Jean-Philippe André )

git version control git at videolan.org
Thu Jan 28 16:22:14 CET 2010


vlc | branch: master | Jean-Philippe André <jpeg at videolan.org> | Thu Jan 28 15:24:58 2010 +0100| [1ce616c7b04a6b81ea552c6b1d16bd9976f3e66a] | committer: Jean-Philippe André 

Extensions/Qt: add cannotLoad() flag

This flag will indicate that we can't load the extensions module,
thus preventing many unnecessary (failing) loads on ViewMenu::exec()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1ce616c7b04a6b81ea552c6b1d16bd9976f3e66a
---

 modules/gui/qt4/extensions_manager.cpp |   46 ++++++++++++++++++--------------
 modules/gui/qt4/extensions_manager.hpp |   24 +++++++++-------
 2 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/modules/gui/qt4/extensions_manager.cpp b/modules/gui/qt4/extensions_manager.cpp
index ac99a2d..a460f55 100644
--- a/modules/gui/qt4/extensions_manager.cpp
+++ b/modules/gui/qt4/extensions_manager.cpp
@@ -47,6 +47,7 @@ ExtensionsManager::ExtensionsManager( intf_thread_t *_p_intf, QObject *parent )
     menuMapper = new QSignalMapper( this );
     CONNECT( menuMapper, mapped( int ), this, triggerMenu( int ) );
     b_unloading = false;
+    b_failed = false;
 }
 
 ExtensionsManager::~ExtensionsManager()
@@ -58,14 +59,17 @@ ExtensionsManager::~ExtensionsManager()
     }
 }
 
-void ExtensionsManager::loadExtensions()
+bool ExtensionsManager::loadExtensions()
 {
     if( !p_extensions_manager )
     {
         p_extensions_manager = ( extensions_manager_t* )
                     vlc_object_create( p_intf, sizeof( extensions_manager_t ) );
         if( !p_extensions_manager )
-            return;
+        {
+            b_failed = true;
+            return false;
+        }
         vlc_object_attach( p_extensions_manager, p_intf );
 
         p_extensions_manager->p_module =
@@ -74,7 +78,10 @@ void ExtensionsManager::loadExtensions()
         if( !p_extensions_manager->p_module )
         {
             msg_Err( p_intf, "Unable to load extensions module" );
-            return;
+            vlc_object_release( p_extensions_manager );
+            p_extensions_manager = NULL;
+            b_failed = true;
+            return false;
         }
 
         /* Initialize dialog provider */
@@ -83,10 +90,17 @@ void ExtensionsManager::loadExtensions()
         if( !p_edp )
         {
             msg_Err( p_intf, "Unable to create dialogs provider for extensions" );
-            return;
+            module_unneed( p_extensions_manager,
+                           p_extensions_manager->p_module );
+            vlc_object_release( p_extensions_manager );
+            p_extensions_manager = NULL;
+            b_failed = true;
+            return false;
         }
         b_unloading = false;
     }
+    b_failed = false;
+    return true;
 }
 
 void ExtensionsManager::unloadExtensions()
@@ -100,27 +114,24 @@ void ExtensionsManager::unloadExtensions()
     ExtensionsDialogProvider::killInstance();
 }
 
+void ExtensionsManager::reloadExtensions()
+{
+    unloadExtensions();
+    loadExtensions();
+}
+
 void ExtensionsManager::menu( QMenu *current )
 {
-    QAction *action;
     assert( current != NULL );
     if( !isLoaded() )
     {
-        // This case should not happen
-        action = current->addAction( qtr( "Extensions not loaded" ) );
-        action->setEnabled( false );
+        // This case can happen: do nothing
         return;
     }
 
-    /* Some useless message */
-    action = current->addAction( p_extensions_manager->extensions.i_size
-                                 ? qtr( "Extensions found:" )
-                                 : qtr( "No extensions found" ) );
-    action->setEnabled( false );
-    current->addSeparator();
-
     vlc_mutex_lock( &p_extensions_manager->lock );
 
+    QAction *action;
     extension_t *p_ext = NULL;
     int i_ext = 0;
     FOREACH_ARRAY( p_ext, p_extensions_manager->extensions )
@@ -186,11 +197,6 @@ void ExtensionsManager::menu( QMenu *current )
     FOREACH_END()
 
     vlc_mutex_unlock( &p_extensions_manager->lock );
-
-    /* Possibility to unload the module */
-    current->addSeparator();
-    current->addAction( QIcon( ":/menu/quit" ), qtr( "Unload extensions" ),
-                        this, SLOT( unloadExtensions() ) );
 }
 
 void ExtensionsManager::triggerMenu( int id )
diff --git a/modules/gui/qt4/extensions_manager.hpp b/modules/gui/qt4/extensions_manager.hpp
index dc427f3..c008ff9 100644
--- a/modules/gui/qt4/extensions_manager.hpp
+++ b/modules/gui/qt4/extensions_manager.hpp
@@ -41,16 +41,6 @@ class ExtensionsDialogProvider;
 class ExtensionsManager : public QObject
 {
     Q_OBJECT
-
-private:
-    static ExtensionsManager* instance;
-    intf_thread_t *p_intf;
-    extensions_manager_t *p_extensions_manager;
-    ExtensionsDialogProvider *p_edp;
-
-    QSignalMapper *menuMapper;
-    bool b_unloading;  ///< Work around threads + emit issues, see isUnloading
-
 public:
     static ExtensionsManager *getInstance( intf_thread_t *_p_intf,
                                            QObject *_parent = 0 )
@@ -69,15 +59,27 @@ public:
     virtual ~ExtensionsManager();
 
     inline bool isLoaded() { return p_extensions_manager != NULL; }
+    inline bool cannotLoad() { return b_unloading || b_failed; }
     inline bool isUnloading() { return b_unloading; }
     void menu( QMenu *current );
 
 public slots:
-    void loadExtensions();
+    bool loadExtensions();
     void unloadExtensions();
+    void reloadExtensions();
 
 private slots:
     void triggerMenu( int id );
+
+private:
+    static ExtensionsManager* instance;
+    intf_thread_t *p_intf;
+    extensions_manager_t *p_extensions_manager;
+    ExtensionsDialogProvider *p_edp;
+
+    QSignalMapper *menuMapper;
+    bool b_unloading;  ///< Work around threads + emit issues, see isUnloading
+    bool b_failed; ///< Flag set to true if we could not load the module
 };
 
 #endif // EXTENSIONS_MANAGER_HPP




More information about the vlc-devel mailing list