Commit 1ce616c7 authored by Jean-Philippe André's avatar 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()
parent c11e8245
...@@ -47,6 +47,7 @@ ExtensionsManager::ExtensionsManager( intf_thread_t *_p_intf, QObject *parent ) ...@@ -47,6 +47,7 @@ ExtensionsManager::ExtensionsManager( intf_thread_t *_p_intf, QObject *parent )
menuMapper = new QSignalMapper( this ); menuMapper = new QSignalMapper( this );
CONNECT( menuMapper, mapped( int ), this, triggerMenu( int ) ); CONNECT( menuMapper, mapped( int ), this, triggerMenu( int ) );
b_unloading = false; b_unloading = false;
b_failed = false;
} }
ExtensionsManager::~ExtensionsManager() ExtensionsManager::~ExtensionsManager()
...@@ -58,14 +59,17 @@ ExtensionsManager::~ExtensionsManager() ...@@ -58,14 +59,17 @@ ExtensionsManager::~ExtensionsManager()
} }
} }
void ExtensionsManager::loadExtensions() bool ExtensionsManager::loadExtensions()
{ {
if( !p_extensions_manager ) if( !p_extensions_manager )
{ {
p_extensions_manager = ( extensions_manager_t* ) p_extensions_manager = ( extensions_manager_t* )
vlc_object_create( p_intf, sizeof( extensions_manager_t ) ); vlc_object_create( p_intf, sizeof( extensions_manager_t ) );
if( !p_extensions_manager ) if( !p_extensions_manager )
return; {
b_failed = true;
return false;
}
vlc_object_attach( p_extensions_manager, p_intf ); vlc_object_attach( p_extensions_manager, p_intf );
p_extensions_manager->p_module = p_extensions_manager->p_module =
...@@ -74,7 +78,10 @@ void ExtensionsManager::loadExtensions() ...@@ -74,7 +78,10 @@ void ExtensionsManager::loadExtensions()
if( !p_extensions_manager->p_module ) if( !p_extensions_manager->p_module )
{ {
msg_Err( p_intf, "Unable to load extensions 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 */ /* Initialize dialog provider */
...@@ -83,10 +90,17 @@ void ExtensionsManager::loadExtensions() ...@@ -83,10 +90,17 @@ void ExtensionsManager::loadExtensions()
if( !p_edp ) if( !p_edp )
{ {
msg_Err( p_intf, "Unable to create dialogs provider for extensions" ); 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_unloading = false;
} }
b_failed = false;
return true;
} }
void ExtensionsManager::unloadExtensions() void ExtensionsManager::unloadExtensions()
...@@ -100,27 +114,24 @@ void ExtensionsManager::unloadExtensions() ...@@ -100,27 +114,24 @@ void ExtensionsManager::unloadExtensions()
ExtensionsDialogProvider::killInstance(); ExtensionsDialogProvider::killInstance();
} }
void ExtensionsManager::reloadExtensions()
{
unloadExtensions();
loadExtensions();
}
void ExtensionsManager::menu( QMenu *current ) void ExtensionsManager::menu( QMenu *current )
{ {
QAction *action;
assert( current != NULL ); assert( current != NULL );
if( !isLoaded() ) if( !isLoaded() )
{ {
// This case should not happen // This case can happen: do nothing
action = current->addAction( qtr( "Extensions not loaded" ) );
action->setEnabled( false );
return; 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 ); vlc_mutex_lock( &p_extensions_manager->lock );
QAction *action;
extension_t *p_ext = NULL; extension_t *p_ext = NULL;
int i_ext = 0; int i_ext = 0;
FOREACH_ARRAY( p_ext, p_extensions_manager->extensions ) FOREACH_ARRAY( p_ext, p_extensions_manager->extensions )
...@@ -186,11 +197,6 @@ void ExtensionsManager::menu( QMenu *current ) ...@@ -186,11 +197,6 @@ void ExtensionsManager::menu( QMenu *current )
FOREACH_END() FOREACH_END()
vlc_mutex_unlock( &p_extensions_manager->lock ); 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 ) void ExtensionsManager::triggerMenu( int id )
......
...@@ -41,16 +41,6 @@ class ExtensionsDialogProvider; ...@@ -41,16 +41,6 @@ class ExtensionsDialogProvider;
class ExtensionsManager : public QObject class ExtensionsManager : public QObject
{ {
Q_OBJECT 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: public:
static ExtensionsManager *getInstance( intf_thread_t *_p_intf, static ExtensionsManager *getInstance( intf_thread_t *_p_intf,
QObject *_parent = 0 ) QObject *_parent = 0 )
...@@ -69,15 +59,27 @@ public: ...@@ -69,15 +59,27 @@ public:
virtual ~ExtensionsManager(); virtual ~ExtensionsManager();
inline bool isLoaded() { return p_extensions_manager != NULL; } inline bool isLoaded() { return p_extensions_manager != NULL; }
inline bool cannotLoad() { return b_unloading || b_failed; }
inline bool isUnloading() { return b_unloading; } inline bool isUnloading() { return b_unloading; }
void menu( QMenu *current ); void menu( QMenu *current );
public slots: public slots:
void loadExtensions(); bool loadExtensions();
void unloadExtensions(); void unloadExtensions();
void reloadExtensions();
private slots: private slots:
void triggerMenu( int id ); 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 #endif // EXTENSIONS_MANAGER_HPP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment