demux: mkv: add ALAC atom size, tag and tag version to private data
[vlc.git] / lib / dialog.c
blobd5d986a79fff113c9c9678e8f8235f29dd24906a
1 /*****************************************************************************
2 * dialog.c: libvlc dialog API
3 *****************************************************************************
4 * Copyright © 2016 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <assert.h>
27 #include <vlc/libvlc.h>
28 #include <vlc/libvlc_dialog.h>
30 #include <vlc_common.h>
31 #include <vlc_dialog.h>
33 #include "libvlc_internal.h"
35 static libvlc_dialog_question_type
36 vlc_to_libvlc_dialog_question_type(vlc_dialog_question_type i_type)
38 switch (i_type)
40 case VLC_DIALOG_QUESTION_NORMAL: return LIBVLC_DIALOG_QUESTION_NORMAL;
41 case VLC_DIALOG_QUESTION_WARNING: return LIBVLC_DIALOG_QUESTION_WARNING;
42 case VLC_DIALOG_QUESTION_CRITICAL: return LIBVLC_DIALOG_QUESTION_CRITICAL;
43 default: vlc_assert_unreachable();
47 static void
48 display_error_cb(const char *psz_title, const char *psz_text, void *p_data)
50 libvlc_instance_t *p_instance = p_data;
52 p_instance->dialog.cbs.pf_display_error(psz_title, psz_text,
53 p_instance->dialog.data);
56 static void
57 display_login_cb(vlc_dialog_id *p_id, const char *psz_title,
58 const char *psz_text, const char *psz_default_username,
59 bool b_ask_store, void *p_data)
61 libvlc_instance_t *p_instance = p_data;
63 p_instance->dialog.cbs.pf_display_login((libvlc_dialog_id *) p_id,
64 psz_title, psz_text,
65 psz_default_username,
66 b_ask_store,
67 p_instance->dialog.data);
70 static void
71 display_question_cb(vlc_dialog_id *p_id, const char *psz_title,
72 const char *psz_text, vlc_dialog_question_type i_type,
73 const char *psz_cancel, const char *psz_action1,
74 const char *psz_action2, void *p_data)
76 libvlc_instance_t *p_instance = p_data;
77 const libvlc_dialog_question_type i_ltype =
78 vlc_to_libvlc_dialog_question_type(i_type);
80 p_instance->dialog.cbs.pf_display_question((libvlc_dialog_id *) p_id,
81 psz_title, psz_text, i_ltype,
82 psz_cancel,
83 psz_action1, psz_action2,
84 p_instance->dialog.data);
87 static void
88 display_progress_cb(vlc_dialog_id *p_id, const char *psz_title,
89 const char *psz_text, bool b_indeterminate,
90 float f_position, const char *psz_cancel, void *p_data)
92 libvlc_instance_t *p_instance = p_data;
94 p_instance->dialog.cbs.pf_display_progress((libvlc_dialog_id *) p_id,
95 psz_title, psz_text,
96 b_indeterminate, f_position,
97 psz_cancel,
98 p_instance->dialog.data);
101 static void
102 cancel_cb(vlc_dialog_id *p_id, void *p_data)
104 libvlc_instance_t *p_instance = p_data;
105 p_instance->dialog.cbs.pf_cancel((libvlc_dialog_id *)p_id,
106 p_instance->dialog.data);
109 static void
110 update_progress_cb(vlc_dialog_id *p_id, float f_position, const char *psz_text,
111 void *p_data)
113 libvlc_instance_t *p_instance = p_data;
114 p_instance->dialog.cbs.pf_update_progress((libvlc_dialog_id *) p_id,
115 f_position, psz_text,
116 p_instance->dialog.data);
119 void
120 libvlc_dialog_set_callbacks(libvlc_instance_t *p_instance,
121 const libvlc_dialog_cbs *p_cbs, void *p_data)
123 libvlc_int_t *p_libvlc = p_instance->p_libvlc_int;
125 vlc_mutex_lock(&p_instance->instance_lock);
126 if (p_cbs != NULL)
128 const vlc_dialog_cbs dialog_cbs = {
129 .pf_display_error = p_cbs->pf_display_error != NULL ?
130 display_error_cb : NULL,
131 .pf_display_login = p_cbs->pf_display_login ?
132 display_login_cb : NULL,
133 .pf_display_question = p_cbs->pf_display_question != NULL ?
134 display_question_cb : NULL,
135 .pf_display_progress = p_cbs->pf_display_progress != NULL ?
136 display_progress_cb : NULL,
137 .pf_cancel = p_cbs->pf_cancel != NULL ? cancel_cb : NULL,
138 .pf_update_progress = p_cbs->pf_update_progress != NULL ?
139 update_progress_cb : NULL,
142 p_instance->dialog.cbs = *p_cbs;
143 p_instance->dialog.data = p_data;
145 vlc_dialog_provider_set_callbacks(p_libvlc, &dialog_cbs, p_instance);
147 else
148 vlc_dialog_provider_set_callbacks(p_libvlc, NULL, NULL);
149 vlc_mutex_unlock(&p_instance->instance_lock);
152 void
153 libvlc_dialog_set_context(libvlc_dialog_id *p_id, void *p_context)
155 vlc_dialog_id_set_context((vlc_dialog_id *)p_id, p_context);
158 void *
159 libvlc_dialog_get_context(libvlc_dialog_id *p_id)
161 return vlc_dialog_id_get_context((vlc_dialog_id *)p_id);
165 libvlc_dialog_post_login(libvlc_dialog_id *p_id, const char *psz_username,
166 const char *psz_password, bool b_store)
168 int i_ret = vlc_dialog_id_post_login((vlc_dialog_id *)p_id, psz_username,
169 psz_password, b_store);
170 return i_ret == VLC_SUCCESS ? 0 : -1;
174 libvlc_dialog_post_action(libvlc_dialog_id *p_id, int i_action)
176 int i_ret = vlc_dialog_id_post_action((vlc_dialog_id *)p_id, i_action);
177 return i_ret == VLC_SUCCESS ? 0 : -1;
181 libvlc_dialog_dismiss(libvlc_dialog_id *p_id)
183 int i_ret = vlc_dialog_id_dismiss((vlc_dialog_id *)p_id);
184 return i_ret == VLC_SUCCESS ? 0 : -1;