[vlc-commits] [Git][videolan/vlc][master] 2 commits: dialogs: split callbacks between interactive and non-interactive callbacks

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Fri Apr 29 17:38:44 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
211baa3f by Pierre Lamot at 2022-04-29T17:19:30+00:00
dialogs: split callbacks between interactive and non-interactive callbacks

this allows an application to manage error messages outside of the UI
lifetime. For instance to store error messages before the UI is loaded and able
to handle dialogs.

ref: #26378

- - - - -
c801d4f2 by Pierre Lamot at 2022-04-29T17:19:30+00:00
qt: handle error messages separately from dialog

this allows to store error messages before the UI is loaded and not to miss
dialogs messages if they are requested before the QML is ready.

fix: #26111

- - - - -


11 changed files:

- include/vlc/libvlc_dialog.h
- include/vlc_dialog.h
- lib/dialog.c
- modules/gui/macosx/panels/dialogs/VLCCoreDialogProvider.m
- modules/gui/qt/dialogs/dialogs/dialogmodel.cpp
- modules/gui/qt/dialogs/dialogs/dialogmodel.hpp
- modules/gui/qt/dialogs/dialogs/qml/Dialogs.qml
- modules/gui/qt/maininterface/mainui.cpp
- src/interface/dialog.c
- src/libvlccore.sym
- test/src/interface/dialog.c


Changes:

=====================================
include/vlc/libvlc_dialog.h
=====================================
@@ -46,19 +46,15 @@ typedef enum libvlc_dialog_question_type
 
 /**
  * Dialog callbacks to be implemented
+ *
+ * @attention starting with vlc 4.0.0 the error callback (pf_display_error) is
+ *            no longer part of this struct and need to be registered separately
+ *            using @a libvlc_dialog_set_error_callback
+ *
+ * @see libvlc_dialog_set_error_callback
  */
 typedef struct libvlc_dialog_cbs
 {
-    /**
-     * Called when an error message needs to be displayed
-     *
-     * @param p_data opaque pointer for the callback
-     * @param psz_title title of the dialog
-     * @param psz_text text of the dialog
-     */
-    void (*pf_display_error)(void *p_data, const char *psz_title,
-                             const char *psz_text);
-
     /**
      * Called when a login dialog needs to be displayed
      *
@@ -154,6 +150,16 @@ typedef struct libvlc_dialog_cbs
                                float f_position, const char *psz_text);
 } libvlc_dialog_cbs;
 
+
+/**
+ * Called when an error message needs to be displayed
+ *
+ * @param p_data opaque pointer for the callback
+ * @param psz_title title of the dialog
+ * @param psz_text text of the dialog
+ */
+typedef void (*libvlc_dialog_error_cbs)(void *p_data, const char *psz_title, const char *psz_text);
+
 /**
  * Register callbacks in order to handle VLC dialogs
  *
@@ -166,6 +172,18 @@ LIBVLC_API void
 libvlc_dialog_set_callbacks(libvlc_instance_t *p_instance,
                             const libvlc_dialog_cbs *p_cbs, void *p_data);
 
+/*
+* Register callback in order to handle VLC error messages
+*
+* @version LibVLC 4.0.0 and later.
+*
+* @param p_cbs a pointer to callback, or NULL to unregister callback.
+* @param p_data opaque pointer for the callback
+*/
+LIBVLC_API void
+libvlc_dialog_set_error_callback(libvlc_instance_t *p_instance,
+                                 libvlc_dialog_error_cbs p_cbs, void *p_data);
+
 /**
  * Associate an opaque pointer with the dialog id
  *


=====================================
include/vlc_dialog.h
=====================================
@@ -274,16 +274,6 @@ vlc_dialog_is_cancelled(vlc_object_t *p_obj, vlc_dialog_id *p_id);
  */
 typedef struct vlc_dialog_cbs
 {
-    /**
-     * Called when an error message needs to be displayed
-     *
-     * @param p_data opaque pointer for the callback
-     * @param psz_title title of the dialog
-     * @param psz_text text of the dialog
-     */
-    void (*pf_display_error)(void *p_data, const char *psz_title,
-                             const char *psz_text);
-
     /**
      * Called when a login dialog needs to be displayed
      *
@@ -379,6 +369,15 @@ typedef struct vlc_dialog_cbs
                                float f_position, const char *psz_text);
 } vlc_dialog_cbs;
 
+/**
+ * Called when an error message needs to be displayed
+ *
+ * @param p_data opaque pointer for the callback
+ * @param psz_title title of the dialog
+ * @param psz_text text of the dialog
+ */
+typedef void (*vlc_dialog_error_cbs)(void *p_data, const char *psz_title, const char *psz_text);
+
 /**
  * Register callbacks to handle VLC dialogs
  *
@@ -391,6 +390,20 @@ vlc_dialog_provider_set_callbacks(vlc_object_t *p_obj,
 #define vlc_dialog_provider_set_callbacks(a, b, c) \
     vlc_dialog_provider_set_callbacks(VLC_OBJECT(a), b, c)
 
+/**
+ * Register callbacks to handle VLC error messages
+ *
+ * @version LibVLC 4.0.0 and later.
+ *
+ * @param p_cbs a pointer to the callback, or NULL to unregister the callback.
+ * @param p_data opaque pointer for the callback
+ */
+VLC_API void
+vlc_dialog_provider_set_error_callback(vlc_object_t *p_obj,
+                                       vlc_dialog_error_cbs p_cbs, void *p_data);
+#define vlc_dialog_provider_set_error_callback(a, b, c) \
+    vlc_dialog_provider_set_error_callback(VLC_OBJECT(a), b, c)
+
 /**
  * Associate an opaque pointer with the dialog id
  */


=====================================
lib/dialog.c
=====================================
@@ -44,15 +44,6 @@ vlc_to_libvlc_dialog_question_type(vlc_dialog_question_type i_type)
     }
 }
 
-static void
-display_error_cb(void *p_data, const char *psz_title, const char *psz_text)
-{
-    libvlc_instance_t *p_instance = p_data;
-
-    p_instance->dialog.cbs.pf_display_error(p_instance->dialog.data, psz_title,
-                                            psz_text);
-}
-
 static void
 display_login_cb(void *p_data, vlc_dialog_id *p_id, const char *psz_title,
                  const char *psz_text, const char *psz_default_username,
@@ -124,8 +115,6 @@ libvlc_dialog_set_callbacks(libvlc_instance_t *p_instance,
     if (p_cbs != NULL)
     {
         const vlc_dialog_cbs dialog_cbs = {
-            .pf_display_error = p_cbs->pf_display_error != NULL ?
-                                display_error_cb : NULL,
             .pf_display_login = p_cbs->pf_display_login ?
                                 display_login_cb : NULL,
             .pf_display_question = p_cbs->pf_display_question != NULL ?
@@ -146,6 +135,14 @@ libvlc_dialog_set_callbacks(libvlc_instance_t *p_instance,
         vlc_dialog_provider_set_callbacks(p_libvlc, NULL, NULL);
 }
 
+void
+libvlc_dialog_set_error_callback(libvlc_instance_t *p_instance,
+                                 libvlc_dialog_error_cbs p_cbs, void *p_data)
+{
+    libvlc_int_t *p_libvlc = p_instance->p_libvlc_int;
+    vlc_dialog_provider_set_error_callback(p_libvlc, p_cbs, p_data);
+}
+
 void
 libvlc_dialog_set_context(libvlc_dialog_id *p_id, void *p_context)
 {


=====================================
modules/gui/macosx/panels/dialogs/VLCCoreDialogProvider.m
=====================================
@@ -186,7 +186,6 @@ static void updateProgressCallback(void *p_data,
         /* subscribe to various interactive dialogues */
 
         const vlc_dialog_cbs cbs = {
-            displayErrorCallback,
             displayLoginCallback,
             displayQuestionCallback,
             displayProgressCallback,
@@ -194,6 +193,7 @@ static void updateProgressCallback(void *p_data,
             updateProgressCallback
         };
 
+        vlc_dialog_provider_set_error_callback(p_intf, displayErrorCallback, (__bridge void *)self);
         vlc_dialog_provider_set_callbacks(p_intf, &cbs, (__bridge void *)self);
     }
 
@@ -206,6 +206,7 @@ static void updateProgressCallback(void *p_data,
 
     intf_thread_t *p_intf = getIntf();
     vlc_dialog_provider_set_callbacks(p_intf, NULL, NULL);
+    vlc_dialog_provider_set_error_callback(p_intf, NULL, NULL);
 }
 
 -(void)awakeFromNib


=====================================
modules/gui/qt/dialogs/dialogs/dialogmodel.cpp
=====================================
@@ -24,11 +24,23 @@
 #include <vlc_dialog.h>
 #include <qt.hpp>
 
+#include "maininterface/mainctx.hpp"
+
 //=================================================================================================
 // DialogErrorModel
 //=================================================================================================
 
-/* explicit */ DialogErrorModel::DialogErrorModel(QObject * parent) : QAbstractListModel(parent) {}
+DialogErrorModel::DialogErrorModel(qt_intf_t * intf, QObject * parent)
+    : QAbstractListModel(parent)
+    , m_intf(intf)
+{
+    vlc_dialog_provider_set_error_callback(intf, &DialogErrorModel::onError, this);
+}
+
+DialogErrorModel::~DialogErrorModel()
+{
+    vlc_dialog_provider_set_error_callback(m_intf, nullptr, nullptr);
+}
 
 //-------------------------------------------------------------------------------------------------
 // QAbstractItemModel implementation
@@ -74,6 +86,19 @@ QHash<int, QByteArray> DialogErrorModel::roleNames() const /* override */
 // Private functions
 //-------------------------------------------------------------------------------------------------
 
+void DialogErrorModel::onError(void * p_data,
+                               const char * psz_title, const char * psz_text)
+{
+    auto model = static_cast<DialogErrorModel *>(p_data);
+
+    DialogErrorModel::DialogError error { psz_title, psz_text };
+
+    QMetaObject::invokeMethod(model, [model, error = std::move(error)]()
+    {
+        model->pushError(error);
+    });
+}
+
 void DialogErrorModel::pushError(const DialogError & error)
 {
     int row = m_data.count();
@@ -100,17 +125,41 @@ int DialogErrorModel::count() const
 // DialogModel
 //=================================================================================================
 
-/* explicit */ DialogModel::DialogModel(qt_intf_t * intf, QObject * parent)
-    : QObject(parent), m_intf(intf)
+DialogModel::DialogModel(QObject* parent)
+    : QObject(parent)
 {
-    m_model = new DialogErrorModel(this);
+}
 
-    const vlc_dialog_cbs cbs =
-    {
-        onError, onLogin, onQuestion, onProgress, onCancelled, onProgressUpdated
-    };
+DialogModel::~DialogModel()
+{
+    if (m_ctx)
+        vlc_dialog_provider_set_callbacks(m_ctx->getIntf(), nullptr, nullptr);
+}
 
-    vlc_dialog_provider_set_callbacks(intf, &cbs, this);
+MainCtx* DialogModel::getCtx() const
+{
+    return m_ctx;
+}
+
+void DialogModel::setCtx(MainCtx* ctx)
+{
+    if (ctx == m_ctx)
+        return;
+    if (ctx) {
+        m_ctx = ctx;
+
+        const vlc_dialog_cbs cbs =
+        {
+            onLogin, onQuestion, onProgress, onCancelled, onProgressUpdated
+        };
+        vlc_dialog_provider_set_callbacks(ctx->getIntf(), &cbs, this);
+    } else {
+        if (m_ctx)
+            vlc_dialog_provider_set_callbacks(m_ctx->getIntf(), nullptr, nullptr);
+
+        m_ctx = nullptr;
+    }
+    emit ctxChanged();
 }
 
 //-------------------------------------------------------------------------------------------------
@@ -142,18 +191,6 @@ int DialogErrorModel::count() const
 // Private static functions
 //-------------------------------------------------------------------------------------------------
 
-/* static */ void DialogModel::onError(void * p_data,
-                                       const char * psz_title, const char * psz_text)
-{
-    DialogModel * model = static_cast<DialogModel *>(p_data);
-
-    DialogErrorModel::DialogError error { psz_title, psz_text };
-
-    QMetaObject::invokeMethod(model, [model, error = std::move(error)]()
-    {
-        model->m_model->pushError(error);
-    });
-}
 
 /* static */ void DialogModel::onLogin(void * p_data, vlc_dialog_id * dialogId,
                                        const char * psz_title, const char * psz_text,
@@ -200,12 +237,3 @@ int DialogErrorModel::count() const
 
     emit model->cancelled(dialogId);
 }
-
-//-------------------------------------------------------------------------------------------------
-// Properties
-//-------------------------------------------------------------------------------------------------
-
-DialogErrorModel * DialogModel::model() const
-{
-    return m_model;
-}


=====================================
modules/gui/qt/dialogs/dialogs/dialogmodel.hpp
=====================================
@@ -34,14 +34,6 @@
 
 #include "qt.hpp"
 
-// Forward declarations
-class DialogModel;
-
-
-//-------------------------------------------------------------------------------------------------
-// DialogId
-//-------------------------------------------------------------------------------------------------
-
 class DialogId
 {
     Q_GADGET
@@ -61,9 +53,6 @@ public: // Variables
 
 Q_DECLARE_METATYPE(DialogId)
 
-//-------------------------------------------------------------------------------------------------
-// DialogErrorModel
-//-------------------------------------------------------------------------------------------------
 
 class DialogErrorModel : public QAbstractListModel
 {
@@ -88,7 +77,8 @@ private:
     };
 
 public:
-    explicit DialogErrorModel(QObject * parent = nullptr);
+    explicit DialogErrorModel(qt_intf_t* intf, QObject * parent = nullptr);
+    ~DialogErrorModel();
 
 public: // QAbstractItemModel implementation
     QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
@@ -101,6 +91,8 @@ public: // QAbstractItemModel reimplementation
 private: // Functions
     void pushError(const DialogError & error);
 
+    static void onError(void * p_data, const char * psz_title, const char * psz_text);
+
 signals:
     void modelChanged();
 
@@ -111,29 +103,24 @@ public: // Properties
 
 private: // Variables
     QList<DialogError> m_data;
-
-private:
-    friend class DialogModel;
+    qt_intf_t* m_intf = nullptr;
 };
 
-//-------------------------------------------------------------------------------------------------
-// DialogModel
-//-------------------------------------------------------------------------------------------------
-
 class DialogModel : public QObject
 {
     Q_OBJECT
 
     Q_ENUMS(QuestionType)
 
-    Q_PROPERTY(DialogErrorModel * model READ model CONSTANT FINAL)
+    Q_PROPERTY(MainCtx* ctx READ getCtx WRITE setCtx NOTIFY ctxChanged FINAL)
 
 public: // Enums
     // NOTE: Is it really useful to have this declared here ?
     enum QuestionType { QUESTION_NORMAL, QUESTION_WARNING, QUESTION_CRITICAL };
 
 public:
-    explicit DialogModel(qt_intf_t * intf, QObject * parent = nullptr);
+    explicit DialogModel(QObject *parent = nullptr);
+    ~DialogModel();
 
 public: // Interface
     Q_INVOKABLE void post_login(DialogId dialogId, const QString & username,
@@ -145,8 +132,6 @@ public: // Interface
     Q_INVOKABLE void dismiss(DialogId dialogId);
 
 private: // Static functions
-    static void onError(void * p_data, const char * psz_title, const char * psz_text);
-
     static void onLogin(void * p_data, vlc_dialog_id * dialogId, const char * psz_title,
                         const char * psz_text, const char * psz_default_username,
                         bool b_ask_store);
@@ -165,11 +150,11 @@ private: // Static functions
 
     static void onCancelled(void * p_data, vlc_dialog_id * dialogId);
 
+public:
+    MainCtx* getCtx() const;
+    void setCtx(MainCtx*);
 
 signals:
-    void errorBegin();
-    void errorEnd  ();
-
     void login(DialogId dialogId, const QString & title,
                const QString & text, const QString & defaultUsername,
                bool b_ask_store);
@@ -184,13 +169,10 @@ signals:
 
     void cancelled(DialogId dialogId);
 
-public: // Properties
-    DialogErrorModel * model() const;
-
-private: // Variables
-    DialogErrorModel * m_model;
+    void ctxChanged();
 
-    qt_intf_t * m_intf;
+private:
+    MainCtx* m_ctx = nullptr;
 };
 
 #endif // DIALOGMODEL_HPP


=====================================
modules/gui/qt/dialogs/dialogs/qml/Dialogs.qml
=====================================
@@ -34,11 +34,6 @@ Item {
 
     property Item bgContent: null
 
-    //---------------------------------------------------------------------------------------------
-    // Private
-
-    readonly property DialogErrorModel _model: DialogModel.model
-
     //---------------------------------------------------------------------------------------------
     // Signal
     //---------------------------------------------------------------------------------------------
@@ -49,14 +44,14 @@ Item {
     // Events
     //---------------------------------------------------------------------------------------------
 
-    Component.onCompleted: if (_model.count) errorPopup.state = "visible"
+    Component.onCompleted: if (DialogErrorModel.count) errorPopup.state = "visible"
 
     Component.onDestruction: {
         if (questionDialog.dialogId !== null) {
-            DialogModel.dismiss(questionDialog.dialogId)
+            dialogModel.dismiss(questionDialog.dialogId)
             questionDialog.dialogId = null
         } if (loginDialog.dialogId !== null) {
-            DialogModel.dismiss(loginDialog.dialogId)
+            dialogModel.dismiss(loginDialog.dialogId)
             loginDialog.dialogId = null
         }
     }
@@ -75,7 +70,7 @@ Item {
 
     Connections
     {
-        target: DialogModel
+        target: dialogModel
 
         onLogin: {
             loginDialog.dialogId = dialogId
@@ -106,20 +101,20 @@ Item {
             if (questionDialog.dialogId === dialogId) {
                 questionDialog.close()
                 questionDialog.dialogId = null
-                DialogModel.dismiss(dialogId)
+                dialogModel.dismiss(dialogId)
             } else if (loginDialog.dialogId === dialogId)  {
                 loginDialog.close()
                 loginDialog.dialogId = null
-                DialogModel.dismiss(dialogId)
+                dialogModel.dismiss(dialogId)
             } else {
-                DialogModel.dismiss(dialogId)
+                dialogModel.dismiss(dialogId)
             }
         }
     }
 
     Connections
     {
-        target: _model
+        target: DialogErrorModel
 
         onCountChanged: errorPopup.state = "visible"
     }
@@ -128,6 +123,12 @@ Item {
     // Childs
     //---------------------------------------------------------------------------------------------
 
+    DialogModel {
+        id: dialogModel
+        ctx: MainCtx
+    }
+
+
     Widgets.DrawerExt {
         id: errorPopup
         anchors {
@@ -149,13 +150,13 @@ Item {
                 anchors.fill: parent
                 anchors.margins: VLCStyle.fontHeight_normal / 2
                 ScrollBar.vertical: ScrollBar{}
-                contentY: VLCStyle.fontHeight_normal * ((_model.count * 2) - 4)
+                contentY: VLCStyle.fontHeight_normal * ((DialogErrorModel.count * 2) - 4)
                 clip: true
 
                 ListView {
                     width: parent.width
-                    height: VLCStyle.fontHeight_normal * _model.count * 2
-                    model: _model
+                    height: VLCStyle.fontHeight_normal * DialogErrorModel.count * 2
+                    model: DialogErrorModel
                     delegate: Column {
                         Text {
                             text: model.title
@@ -305,13 +306,13 @@ Item {
 
         onAccepted: {
             if (loginDialog.dialogId !== null) {
-                DialogModel.post_login(loginDialog.dialogId, username.text, password.text, savePassword.checked)
+                dialogModel.post_login(loginDialog.dialogId, username.text, password.text, savePassword.checked)
                 loginDialog.dialogId = null
             }
         }
         onRejected: {
             if (loginDialog.dialogId !== null) {
-                DialogModel.dismiss(loginDialog.dialogId)
+                dialogModel.dismiss(loginDialog.dialogId)
                 loginDialog.dialogId = null
             }
         }
@@ -366,7 +367,7 @@ Item {
                         Keys.onPressed: Navigation.defaultKeyAction(event)
 
                         onClicked: {
-                            DialogModel.dismiss(questionDialog.dialogId)
+                            dialogModel.dismiss(questionDialog.dialogId)
                             questionDialog.dialogId = null
                             questionDialog.close()
                         }
@@ -385,7 +386,7 @@ Item {
                         Keys.onPressed: Navigation.defaultKeyAction(event)
 
                         onClicked: {
-                            DialogModel.post_action1(questionDialog.dialogId)
+                            dialogModel.post_action1(questionDialog.dialogId)
                             questionDialog.dialogId = null
                             questionDialog.close()
                         }
@@ -402,7 +403,7 @@ Item {
                         Keys.onPressed: Navigation.defaultKeyAction(event)
 
                         onClicked: {
-                            DialogModel.post_action2(questionDialog.dialogId)
+                            dialogModel.post_action2(questionDialog.dialogId)
                             questionDialog.dialogId = null
                             questionDialog.close()
                         }


=====================================
modules/gui/qt/maininterface/mainui.cpp
=====================================
@@ -126,7 +126,7 @@ MainUI::MainUI(qt_intf_t *p_intf, MainCtx *mainCtx, QWindow* interfaceWindow,  Q
     SingletonRegisterHelper<NavigationHistory>::setInstance( new NavigationHistory(this) );
     SingletonRegisterHelper<I18n>::setInstance( new I18n(this) );
     SingletonRegisterHelper<SystemPalette>::setInstance( new SystemPalette(this) );
-    SingletonRegisterHelper<DialogModel>::setInstance( new DialogModel(m_intf, this));
+    SingletonRegisterHelper<DialogErrorModel>::setInstance( new DialogErrorModel(m_intf, this));
     SingletonRegisterHelper<QmlKeyHelper>::setInstance( new QmlKeyHelper(this) );
 
     if (m_mainCtx->hasMediaLibrary())
@@ -207,7 +207,7 @@ void MainUI::registerQMLTypes()
         qmlRegisterSingletonType<I18n>(uri, versionMajor, versionMinor, "I18n", SingletonRegisterHelper<I18n>::callback);
         qmlRegisterSingletonType<DialogsProvider>(uri, versionMajor, versionMinor, "DialogsProvider", SingletonRegisterHelper<DialogsProvider>::callback);
         qmlRegisterSingletonType<SystemPalette>(uri, versionMajor, versionMinor, "SystemPalette", SingletonRegisterHelper<SystemPalette>::callback);
-        qmlRegisterSingletonType<DialogModel>(uri, versionMajor, versionMinor, "DialogModel", SingletonRegisterHelper<DialogModel>::callback);
+        qmlRegisterSingletonType<DialogErrorModel>(uri, versionMajor, versionMinor, "DialogErrorModel", SingletonRegisterHelper<DialogErrorModel>::callback);
         qmlRegisterSingletonType<QmlKeyHelper>(uri, versionMajor, versionMinor, "KeyHelper", SingletonRegisterHelper<QmlKeyHelper>::callback);
 
         qmlRegisterUncreatableType<QAbstractItemModel>(uri, versionMajor, versionMinor, "QtAbstractItemModel", "");
@@ -245,6 +245,7 @@ void MainUI::registerQMLTypes()
         qmlRegisterType<AboutModel>( uri, versionMajor, versionMinor, "AboutModel" );
 
         qmlRegisterUncreatableType<DialogErrorModel>( uri, versionMajor, versionMinor, "DialogErrorModel", "");
+        qmlRegisterType<DialogModel>(uri, versionMajor, versionMinor, "DialogModel");
         qRegisterMetaType<DialogId>();
         qmlRegisterUncreatableType<DialogId>( uri, versionMajor, versionMinor, "DialogId", "");
 


=====================================
src/interface/dialog.c
=====================================
@@ -40,6 +40,9 @@ struct vlc_dialog_provider
     vlc_dialog_cbs              cbs;
     void *                      p_cbs_data;
 
+    vlc_dialog_error_cbs        err_cbs;
+    void *                      p_err_cbs_data;
+
     vlc_dialog_ext_update_cb    pf_ext_update;
     void *                      p_ext_data;
 };
@@ -157,6 +160,9 @@ libvlc_InternalDialogInit(libvlc_int_t *p_libvlc)
     memset(&p_provider->cbs, 0, sizeof(p_provider->cbs));
     p_provider->p_cbs_data = NULL;
 
+    p_provider->err_cbs = NULL;
+    p_provider->p_err_cbs_data = NULL;
+
     p_provider->pf_ext_update = NULL;
     p_provider->p_ext_data = NULL;
     libvlc_priv(p_libvlc)->p_dialog_provider = p_provider;
@@ -271,6 +277,29 @@ vlc_dialog_provider_set_callbacks(vlc_object_t *p_obj,
     vlc_mutex_unlock(&p_provider->lock);
 }
 
+#undef vlc_dialog_provider_set_error_callback
+void
+vlc_dialog_provider_set_error_callback(vlc_object_t *p_obj,
+                                  vlc_dialog_error_cbs p_cbs, void *p_data)
+{
+    assert(p_obj != NULL);
+    vlc_dialog_provider *p_provider = get_dialog_provider(p_obj, false);
+
+    vlc_mutex_lock(&p_provider->lock);
+
+    if (p_cbs == NULL)
+    {
+        p_provider->err_cbs  = NULL;
+        p_provider->p_err_cbs_data = NULL;
+    }
+    else
+    {
+        p_provider->err_cbs = p_cbs;
+        p_provider->p_err_cbs_data = p_data;
+    }
+    vlc_mutex_unlock(&p_provider->lock);
+}
+
 static void
 dialog_wait_interrupted(void *p_data)
 {
@@ -328,7 +357,7 @@ dialog_display_error_va(vlc_dialog_provider *p_provider, const char *psz_title,
                         const char *psz_fmt, va_list ap)
 {
     vlc_mutex_lock(&p_provider->lock);
-    if (p_provider->cbs.pf_display_error == NULL)
+    if (p_provider->err_cbs == NULL)
     {
         vlc_mutex_unlock(&p_provider->lock);
         return VLC_EGENERIC;
@@ -341,7 +370,7 @@ dialog_display_error_va(vlc_dialog_provider *p_provider, const char *psz_title,
         return VLC_ENOMEM;
     }
 
-    p_provider->cbs.pf_display_error(p_provider->p_cbs_data, psz_title, psz_text);
+    p_provider->err_cbs(p_provider->p_err_cbs_data, psz_title, psz_text);
     free(psz_text);
     vlc_mutex_unlock(&p_provider->lock);
 


=====================================
src/libvlccore.sym
=====================================
@@ -533,6 +533,7 @@ vlc_dialog_id_post_login
 vlc_dialog_id_set_context
 vlc_dialog_is_cancelled
 vlc_dialog_provider_set_callbacks
+vlc_dialog_provider_set_error_callback
 vlc_dialog_provider_set_ext_callback
 vlc_dialog_release
 vlc_dialog_update_progress


=====================================
test/src/interface/dialog.c
=====================================
@@ -294,7 +294,6 @@ main(int i_argc, char *ppsz_argv[])
 
     printf("testing dialog callbacks\n");
     const vlc_dialog_cbs cbs = {
-        .pf_display_error = display_error_cb,
         .pf_display_login = display_login_cb,
         .pf_display_question = display_question_cb,
         .pf_display_progress = display_progress_cb,
@@ -303,7 +302,9 @@ main(int i_argc, char *ppsz_argv[])
     };
     struct cb_answer ans = { 0 };
     vlc_dialog_provider_set_callbacks(p_libvlc->p_libvlc_int, &cbs, &ans);
+    vlc_dialog_provider_set_error_callback(p_libvlc->p_libvlc_int, &display_error_cb, &ans);
     test_dialogs(VLC_OBJECT(p_libvlc->p_libvlc_int), &ans, 100000);
+    vlc_dialog_provider_set_error_callback(p_libvlc->p_libvlc_int, NULL, NULL);
     vlc_dialog_provider_set_callbacks(p_libvlc->p_libvlc_int, NULL, NULL);
 
     libvlc_release(p_libvlc);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1241d4bf60f8def6e5ffdf79f4f02af53c22d8b9...c801d4f2049bc0fa566f36884fe3ccae72e6fd29

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/1241d4bf60f8def6e5ffdf79f4f02af53c22d8b9...c801d4f2049bc0fa566f36884fe3ccae72e6fd29
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list