Changeset 15354b0406c9222fd39dcee94f9d7239d65d5f39

Show
Ignore:
Timestamp:
11/12/05 17:06:19 (3 years ago)
Author:
Clément Stenac <zorglub@videolan.org>
git-committer:
Clément Stenac <zorglub@videolan.org> 1134317179 +0000
git-parent:

[0f6f58c60482c4b0698578e734f68e3a269e7ad1]

git-author:
Clément Stenac <zorglub@videolan.org> 1134317179 +0000
Message:

* Handle dialogs needing answer
* Handle interfaces not providing interaction correctly
* Add a new helper to request authentication
* Add return codes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_interaction.h

    r29c81fb r15354b0  
    4040    WIDGET_TEXT,                        //< Text display 
    4141    WIDGET_PROGRESS,                    //< A progress bar 
    42     WIDGET_INPUT                       //< Input (backed up by a variable) 
     42    WIDGET_INPUT_TEXT                   //< Input (backed up by a variable) 
    4343}; 
    4444 
     
    5353    char           *psz_description;    //< Descriptor string 
    5454 
    55     /* For dialogs */ 
    5655    int             i_widgets;          //< Nu,ber of dialog widgets 
    5756    user_widget_t **pp_widgets;         //< Dialog widgets 
    5857 
    59     vlc_bool_t      b_reusable;         //< Do we have to reuse this ? 
     58    void *          p_private;          //< Private interface data 
    6059 
    61     void *          p_private;          //< Private interface data 
    6260    int             i_status;           //< Dialog status; 
     61    int             i_action;           //< Action to perform; 
     62    int             i_flags;            //< Misc flags 
     63    int             i_return;           //< Return status 
    6364 
    64     int             i_action;           //< Action to perform; 
     65    interaction_t  *p_interaction;      //< Parent interaction object 
     66    vlc_object_t   *p_parent;           //< The vlc object that asked 
     67                                        //for interaction 
     68}; 
     69 
     70/** 
     71 * Possible flags . Reusable and button types 
     72 */ 
     73#define DIALOG_REUSABLE      0x01 
     74#define DIALOG_OK_CANCEL     0x02 
     75#define DIALOG_YES_NO        0x04 
     76#define DIALOG_YES_NO_CANCEL 0x04 
     77#define DIALOG_GOT_ANSWER    0x08 
     78 
     79/** 
     80 * Possible return codes 
     81 */ 
     82enum 
     83
     84    DIALOG_DEFAULT, 
     85    DIALOG_OK_YES, 
     86    DIALOG_NO, 
     87    DIALOG_CANCELLED 
    6588}; 
    6689 
     
    7093enum 
    7194{ 
    72     NEW_DIALOG, 
    73     SENT_DIALOG, 
    74     UPDATED_DIALOG, 
    75     ANSWERED_DIALOG, 
    76     HIDING_DIALOG, 
    77     HIDDEN_DIALOG, 
     95    NEW_DIALOG,                 //< Just created 
     96    SENT_DIALOG,                //< Sent to interface 
     97    UPDATED_DIALOG,             //< Update to send 
     98    ANSWERED_DIALOG,            //< Got "answer" 
     99    HIDING_DIALOG,              //< Hiding requested 
     100    HIDDEN_DIALOG,              //< Now hidden. Requesting destruction 
     101    DESTROYED_DIALOG,           //< Interface has destroyed it 
    78102}; 
    79103 
     
    83107enum 
    84108{ 
    85     INTERACT_PROGRESS,          //< Progress bar 
    86     INTERACT_WARNING,           //< Warning message ("codec not supported") 
    87     INTERACT_FATAL,             //< Fatal message ("File not found") 
    88     INTERACT_FATAL_LIST,        //< List of fatal messages ("File not found") 
    89     INTERACT_ASK,               //< Full-featured dialog box (password) 
     109    INTERACT_PROGRESS,          //< Progress bar (in the main interface ?) 
     110    INTERACT_DIALOG_ONEWAY,     //< Dialog box without feedback 
     111    INTERACT_DIALOG_TWOWAY,     //< Dialog box with feedback 
    90112}; 
    91113 
     
    96118{ 
    97119    DIALOG_FIRST, 
    98     DIALOG_NOACCESS, 
    99     DIALOG_NOCODEC, 
    100     DIALOG_NOAUDIO, 
     120    DIALOG_ERRORS, 
    101121 
    102122    DIALOG_LAST_PREDEFINED, 
     
    125145    INTERACT_NEW, 
    126146    INTERACT_UPDATE, 
    127     INTERACT_HIDE 
     147    INTERACT_HIDE, 
     148    INTERACT_DESTROY 
    128149}; 
    129150 
     
    135156VLC_EXPORT( int,__intf_Interact,( vlc_object_t *,interaction_dialog_t * ) ); 
    136157 
    137 #define intf_UserFatal( a,b, c, d, e... ) __intf_UserFatal( a,b,c,d, ## e ) 
    138 VLC_EXPORT( void, __intf_UserFatal,( vlc_object_t*, int, const char*, const char*, ...) ); 
     158#define intf_UserFatal( a, c, d, e... ) __intf_UserFatal( a,c,d, ## e ) 
     159VLC_EXPORT( void, __intf_UserFatal,( vlc_object_t*, const char*, const char*, ...) ); 
     160#define intf_UserLoginPassword( a, b, c, d, e... ) __intf_UserLoginPassword( a,b,c,d,e) 
     161VLC_EXPORT( int, __intf_UserLoginPassword,( vlc_object_t*, const char*, const char*, char **, char **) ); 
    139162 
    140163VLC_EXPORT( void, intf_InteractionManage,( playlist_t *) ); 
  • include/vlc_interface.h

    r29c81fb r15354b0  
    9393struct intf_dialog_args_t 
    9494{ 
     95    intf_thread_t *p_intf; 
    9596    char *psz_title; 
    9697 
     
    105106    vlc_bool_t b_save; 
    106107    vlc_bool_t b_multiple; 
     108 
     109    /* Specific to INTF_DIALOG_INTERACTION */ 
     110    interaction_dialog_t *p_dialog; 
    107111}; 
    108112 
     
    161165 
    162166#define INTF_DIALOG_FILE_GENERIC 30 
     167#define INTF_DIALOG_INTERACTION 50 
    163168 
    164169#define INTF_DIALOG_UPDATEVLC   90 
  • include/vlc_symbols.h

    rbe2365a r15354b0  
    146146int __vlc_threads_end (vlc_object_t *); 
    147147int sout_AccessOutRead (sout_access_out_t *, block_t *); 
     148int __intf_UserLoginPassword (vlc_object_t*, const char*, const char*, char **, char **); 
    148149int demux2_vaControlHelper (stream_t *, int64_t i_start, int64_t i_end, int i_bitrate, int i_align, int i_query, va_list args); 
    149150int httpd_UrlCatch (httpd_url_t *, int i_msg, httpd_callback_t, httpd_callback_sys_t *); 
     
    298299int vout_vaControlDefault (vout_thread_t *, int, va_list); 
    299300int playlist_NodeEmpty (playlist_t *, playlist_item_t *, vlc_bool_t); 
    300 void __intf_UserFatal (vlc_object_t*, int, const char*, const char*, ...); 
     301void __intf_UserFatal (vlc_object_t*, const char*, const char*, ...); 
    301302spu_t * __spu_Create (vlc_object_t *); 
    302303int playlist_NodeRemoveItem (playlist_t *,playlist_item_t*,playlist_item_t *); 
     
    859860    void (*intf_InteractionManage_inner) (playlist_t *); 
    860861    void (*intf_InteractionDestroy_inner) (interaction_t *); 
    861     void (*__intf_UserFatal_inner) (vlc_object_t*, int, const char*, const char*, ...); 
     862    void (*__intf_UserFatal_inner) (vlc_object_t*, const char*, const char*, ...); 
     863    int (*__intf_UserLoginPassword_inner) (vlc_object_t*, const char*, const char*, char **, char **); 
    862864}; 
    863865#  if defined (__PLUGIN__) 
     
    12751277#  define intf_InteractionDestroy (p_symbols)->intf_InteractionDestroy_inner 
    12761278#  define __intf_UserFatal (p_symbols)->__intf_UserFatal_inner 
     1279#  define __intf_UserLoginPassword (p_symbols)->__intf_UserLoginPassword_inner 
    12771280#  elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__) 
    12781281/****************************************************************** 
     
    16931696    ((p_symbols)->intf_InteractionDestroy_inner) = intf_InteractionDestroy; \ 
    16941697    ((p_symbols)->__intf_UserFatal_inner) = __intf_UserFatal; \ 
     1698    ((p_symbols)->__intf_UserLoginPassword_inner) = __intf_UserLoginPassword; \ 
    16951699    (p_symbols)->net_ConvertIPv4_deprecated = NULL; \ 
    16961700 
  • src/input/input.c

    r29c81fb r15354b0  
    20962096        { 
    20972097            msg_Err( p_input, "no suitable access module for `%s'", psz_mrl ); 
    2098             intf_UserFatal( VLC_OBJECT( p_input), DIALOG_NOACCESS, 
    2099                             "Error opening stream", 
    2100                             "Unable to open '%s'", psz_mrl ); 
     2098            intf_UserFatal( VLC_OBJECT( p_input), 
     2099                            _("Errors"),"Unable to open '%s'", psz_mrl ); 
    21012100            goto error; 
    21022101        } 
     
    21682167            msg_Err( p_input, "no suitable demux module for `%s/%s://%s'", 
    21692168                     psz_access, psz_demux, psz_path ); 
     2169            intf_UserFatal( VLC_OBJECT( p_input), _("Errors"), 
     2170                            "Unrecognized format for '%s'", psz_mrl ); 
    21702171            goto error; 
    21712172        } 
  • src/interface/interaction.c

    r29c81fb r15354b0  
    6464                                    p_dialog ) 
    6565{ 
    66  
    6766    interaction_t *p_interaction = intf_InteractionGet( p_this ); 
    6867 
     
    7372    } 
    7473 
    75     if( p_dialog->i_type == INTERACT_ASK ) 
     74    p_dialog->p_interaction = p_interaction; 
     75    p_dialog->p_parent = p_this; 
     76 
     77    if( p_dialog->i_type == INTERACT_DIALOG_TWOWAY ) 
    7678    { 
    7779        return intf_WaitAnswer( p_interaction, p_dialog ); 
     
    7981    else 
    8082    { 
     83        p_dialog->i_flags |=  DIALOG_GOT_ANSWER; 
    8184        return intf_Send( p_interaction, p_dialog ); 
    8285    } 
     
    115118    if( !p_interaction->p_intf ) 
    116119    { 
    117         vlc_mutex_unlock( &p_interaction->object_lock ); 
    118  
    119         /// \todo Remove all dialogs as we can't display them 
    120         return; 
    121     } 
    122  
    123     vlc_object_yield( p_interaction->p_intf ); 
     120        // We mark all dialogs as answered with their "default" answer 
     121        for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ ) 
     122        { 
     123            interaction_dialog_t *p_dialog = p_interaction->pp_dialogs[i_index]; 
     124            p_dialog->i_return = DIALOG_DEFAULT; 
     125            if( p_dialog->i_flags & DIALOG_OK_CANCEL ) 
     126                p_dialog->i_return = DIALOG_CANCELLED; 
     127            if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL ) 
     128                p_dialog->i_return = DIALOG_CANCELLED; 
     129            p_dialog->i_status = ANSWERED_DIALOG; 
     130        } 
     131    } 
     132    else 
     133    { 
     134        vlc_object_yield( p_interaction->p_intf ); 
     135    } 
    124136 
    125137    for( i_index = 0 ; i_index < p_interaction->i_dialogs; i_index ++ ) 
    126138    { 
    127139        interaction_dialog_t *p_dialog = p_interaction->pp_dialogs[i_index]; 
    128  
    129140        switch( p_dialog->i_status ) 
    130141        { 
    131142        case ANSWERED_DIALOG: 
    132             /// \todo Signal we have an answer 
    133             // - If have answer, signal what is waiting 
    134             // (vlc_cond ? dangerous in case of pb ?) 
    135  
    136143            // Ask interface to hide it 
    137144            msg_Dbg( p_interaction, "Hiding dialog %i", p_dialog->i_id ); 
    138145            p_dialog->i_action = INTERACT_HIDE; 
    139146            val.p_address = p_dialog; 
    140             var_Set( p_interaction->p_intf, "interaction", val ); 
     147            if( p_interaction->p_intf ) 
     148                var_Set( p_interaction->p_intf, "interaction", val ); 
    141149            p_dialog->i_status = HIDING_DIALOG; 
    142150            break; 
     
    144152            p_dialog->i_action = INTERACT_UPDATE; 
    145153            val.p_address = p_dialog; 
    146             var_Set( p_interaction->p_intf, "interaction", val ); 
     154            if( p_interaction->p_intf ) 
     155                var_Set( p_interaction->p_intf, "interaction", val ); 
    147156            p_dialog->i_status = SENT_DIALOG; 
    148157            msg_Dbg( p_interaction, "Updating dialog %i, %i widgets", 
     
    150159            break; 
    151160        case HIDDEN_DIALOG: 
    152             if( !p_dialog->b_reusable ) 
     161            if( !(p_dialog->i_flags & DIALOG_GOT_ANSWER) ) break; 
     162            if( !(p_dialog->i_flags & DIALOG_REUSABLE) ) 
    153163            { 
    154                 /// \todo Destroy the dialog 
     164                msg_Dbg( p_interaction, "Destroying dialog %i", 
     165                                                p_dialog->i_id ); 
     166                p_dialog->i_action = INTERACT_DESTROY; 
     167                val.p_address = p_dialog; 
     168                if( p_interaction->p_intf ) 
     169                    var_Set( p_interaction->p_intf, "interaction", val ); 
    155170            } 
    156171            break; 
     172        case DESTROYED_DIALOG: 
     173            // Interface has now destroyed it, remove it 
     174            /// \todo Remove it from the list 
     175            /// \todo Free data fields 
     176            free( p_dialog ); 
    157177        case NEW_DIALOG: 
    158178            // This is truly a new dialog, send it. 
    159179            p_dialog->i_action = INTERACT_NEW; 
    160180            val.p_address = p_dialog; 
    161             var_Set( p_interaction->p_intf, "interaction", val ); 
    162             msg_Dbg( p_interaction, "Creating dialog %i to interface %i, %i widgets", 
    163                                         p_dialog->i_id, p_interaction->p_intf->i_object_id, p_dialog->i_widgets ); 
     181            if( p_interaction->p_intf ) 
     182                var_Set( p_interaction->p_intf, "interaction", val ); 
    164183            p_dialog->i_status = SENT_DIALOG; 
    165184            break; 
     
    167186    } 
    168187 
    169     vlc_object_release( p_interaction->p_intf ); 
     188    if( p_interaction->p_intf ) 
     189    { 
     190        vlc_object_release( p_interaction->p_intf ); 
     191    } 
    170192 
    171193    vlc_mutex_unlock( &p_playlist->p_interaction->object_lock ); 
     
    188210        if( new->psz_description ) free( new->psz_description ); 
    189211 
    190 /** Helper function to send a fatal message 
     212/** Helper function to send an error message 
    191213 *  \param p_this     Parent vlc_object 
    192214 *  \param i_id       A predefined ID, 0 if not applicable 
     
    194216 *  \param psz_format The message to display 
    195217 *  */ 
    196 void __intf_UserFatal( vlc_object_t *p_this, int i_id, 
     218void __intf_UserFatal( vlc_object_t *p_this, 
    197219                       const char *psz_title, 
    198220                       const char *psz_format, ... ) 
     
    201223    interaction_dialog_t *p_new = NULL; 
    202224    user_widget_t *p_widget = NULL; 
     225    int i_id = DIALOG_ERRORS; 
    203226 
    204227    if( i_id > 0 ) 
     
    216239    } 
    217240 
    218     p_new->i_type = INTERACT_FATAL; 
     241    p_new->i_flags |= DIALOG_REUSABLE; 
     242 
     243    p_new->i_type = INTERACT_DIALOG_ONEWAY; 
    219244    p_new->psz_title = strdup( psz_title ); 
    220245 
     
    235260} 
    236261 
    237 #if 0 
    238 /** Helper function to build a progress bar 
    239  * \param p_this   Parent vlc object 
     262/** Helper function to make a login/password box 
     263 *  \param p_this           Parent vlc_object 
     264 *  \param psz_title        Title for the dialog 
     265 *  \param psz_description  A description 
     266 *  \param ppsz_login       Returned login 
     267 *  \param ppsz_password    Returned password 
     268 *  \return                 1 if user clicked Cancel, 0 if OK 
    240269 */ 
    241 interaction_dialog_t *__intf_ProgressBuild( vlc_object_t *p_this, 
    242                                             const char *psz_text ) 
    243 
    244     interaction_dialog_t *p_new = (interaction_dialog_t *)malloc( 
    245                                         sizeof( interaction_dialog_t ) ); 
    246  
    247  
    248     return p_new; 
    249 
    250 #endif 
    251  
    252  
     270int __intf_UserLoginPassword( vlc_object_t *p_this, 
     271                              const char *psz_title, 
     272                              const char *psz_description, 
     273                              char **ppsz_login, 
     274                              char **ppsz_password ) 
     275
     276    int i_ret; 
     277    interaction_dialog_t *p_new = NULL; 
     278    user_widget_t *p_widget = NULL; 
     279 
     280    INTERACT_INIT( p_new ); 
     281 
     282    p_new->i_type = INTERACT_DIALOG_TWOWAY; 
     283    p_new->psz_title = strdup( psz_title ); 
     284 
     285    /* Text */ 
     286    p_widget = (user_widget_t* )malloc( sizeof( user_widget_t ) ); 
     287    p_widget->i_type = WIDGET_TEXT; 
     288    p_widget->psz_text = strdup( psz_description ); 
     289    INSERT_ELEM ( p_new->pp_widgets, p_new->i_widgets, 
     290                  p_new->i_widgets,  p_widget ); 
     291 
     292    /* Login */ 
     293    p_widget = (user_widget_t* )malloc( sizeof( user_widget_t ) ); 
     294    p_widget->i_type = WIDGET_INPUT_TEXT; 
     295    p_widget->psz_text = strdup( _("Login") ); 
     296    p_widget->val.psz_string = NULL; 
     297    INSERT_ELEM ( p_new->pp_widgets, p_new->i_widgets, 
     298                  p_new->i_widgets,  p_widget ); 
     299 
     300    /* Password */ 
     301    p_widget = (user_widget_t* )malloc( sizeof( user_widget_t ) ); 
     302    p_widget->i_type = WIDGET_INPUT_TEXT; 
     303    p_widget->psz_text = strdup( _("Password") ); 
     304    p_widget->val.psz_string = NULL; 
     305    INSERT_ELEM ( p_new->pp_widgets, p_new->i_widgets, 
     306                  p_new->i_widgets,  p_widget ); 
     307 
     308    p_new->i_flags = DIALOG_OK_CANCEL; 
     309 
     310    i_ret = intf_Interact( p_this, p_new ); 
     311 
     312    if( i_ret == DIALOG_OK_YES ) 
     313    { 
     314        *ppsz_login = strdup( p_new->pp_widgets[1]->val.psz_string ); 
     315        *ppsz_password = strdup( p_new->pp_widgets[2]->val.psz_string ); 
     316    } 
     317    return i_ret; 
     318
    253319 
    254320/********************************************************************** 
     
    338404static int intf_WaitAnswer( interaction_t *p_interact, interaction_dialog_t *p_dialog ) 
    339405{ 
    340     // TODO: Add to queue, wait for answer 
    341     return VLC_SUCCESS; 
     406    int i; 
     407    vlc_bool_t b_found = VLC_FALSE; 
     408    vlc_mutex_lock( &p_interact->object_lock ); 
     409    for( i = 0 ; i< p_interact->i_dialogs; i++ ) 
     410    { 
     411        if( p_interact->pp_dialogs[i]->i_id == p_dialog->i_id ) 
     412        { 
     413            b_found = VLC_TRUE; 
     414        } 
     415    } 
     416    if( ! b_found ) 
     417    { 
     418        INSERT_ELEM( p_interact->pp_dialogs, 
     419                     p_interact->i_dialogs, 
     420                     p_interact->i_dialogs, 
     421                     p_dialog ); 
     422    } 
     423    else 
     424        p_dialog->i_status = UPDATED_DIALOG; 
     425    vlc_mutex_unlock( &p_interact->object_lock ); 
     426 
     427    /// \todo Check that the initiating object is not dying 
     428    while( p_dialog->i_status != ANSWERED_DIALOG && 
     429           p_dialog->i_status != HIDING_DIALOG && 
     430           !p_dialog->p_parent->b_die ) 
     431    { 
     432        msleep( 100000 ); 
     433    } 
     434    /// \todo locking 
     435    if( p_dialog->p_parent->b_die ) 
     436    { 
     437        p_dialog->i_return = DIALOG_CANCELLED; 
     438        p_dialog->i_status = ANSWERED_DIALOG; 
     439    } 
     440    p_dialog->i_flags |= DIALOG_GOT_ANSWER; 
     441    return p_dialog->i_return; 
    342442} 
    343443 
     
    345445static int intf_Send( interaction_t *p_interact, interaction_dialog_t *p_dialog ) 
    346446{ 
     447    int i; 
     448    vlc_bool_t b_found = VLC_FALSE; 
    347449    vlc_mutex_lock( &p_interact->object_lock ); 
    348450 
    349     /// \todo Check first it does not exist !!! 
    350     INSERT_ELEM( p_interact->pp_dialogs, 
    351                  p_interact->i_dialogs, 
    352                  p_interact->i_dialogs, 
    353                  p_dialog ); 
     451    for( i = 0 ; i< p_interact->i_dialogs; i++ ) 
     452    { 
     453        if( p_interact->pp_dialogs[i]->i_id == p_dialog->i_id ) 
     454        { 
     455            b_found = VLC_TRUE; 
     456        } 
     457    } 
     458    if( !b_found ) 
     459    { 
     460        INSERT_ELEM( p_interact->pp_dialogs, 
     461                     p_interact->i_dialogs, 
     462                     p_interact->i_dialogs, 
     463                     p_dialog ); 
     464    } 
     465    else 
     466        p_dialog->i_status = UPDATED_DIALOG; 
    354467    vlc_mutex_unlock( &p_interact->object_lock ); 
    355468    return VLC_SUCCESS; 
     
    363476    int i; 
    364477 
     478    if( !p_interaction ) return NULL; 
     479 
    365480    for( i = 0 ; i< p_interaction->i_dialogs; i++ ) 
    366481    {