]> git.sesse.net Git - vlc/commitdiff
* enhanced the interaction core with some method additions/changes
authorFelix Paul Kühne <fkuehne@videolan.org>
Sat, 29 Jul 2006 15:07:42 +0000 (15:07 +0000)
committerFelix Paul Kühne <fkuehne@videolan.org>
Sat, 29 Jul 2006 15:07:42 +0000 (15:07 +0000)
- intf_UserProgress* takes an additional argument now. use it to provide the time to go (in sec) until the process will be finished. Provide 0, if you don't have such info. The interface will hide the respective text-field.
- intf_UserProgressIsCancelled can be called by the module which triggered the interaction dialogue on a regular interval, to check if the user cancelled the dialogue or not. This is for dialogues with an optional cancel-button only (like the modal progress panel), so it doesn't replace p_dialog->i_return = DIALOG_CANCELLED which is for yes/no-style dialogues
- intf_UserOkayCancel was removed in favour of an enhanced intf_UserYesNo
- intf_UserYesNo takes 3 additional arguments now to get the custom captions of the default (~Yes), alternate(~No) and one optional button(~Cancel). This provides a better interface experience for the user and is more compliant with OSX's HIGL. The interface automatically hides the 3rd button, if NULL is given.

extras/MacOSX/Resources/English.lproj/Interaction.nib/classes.nib
extras/MacOSX/Resources/English.lproj/Interaction.nib/info.nib
extras/MacOSX/Resources/English.lproj/Interaction.nib/keyedobjects.nib
include/vlc_interaction.h
modules/demux/avi/avi.c
modules/gui/macosx/interaction.h
modules/gui/macosx/interaction.m
modules/services_discovery/shout.c
src/interface/interaction.c
src/misc/update.c

index e384c091c36bf7a3192dba3cceb3beaa5e0a21d3..15d18c5e9b472fd8158a43dba21a2912b3985e01 100644 (file)
@@ -2,7 +2,7 @@
     IBClasses = (
         {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
         {
-            ACTIONS = {cancelAndClose = id; okayAndClose = id; }; 
+            ACTIONS = {cancelAndClose = id; cancelDialog = id; okayAndClose = id; }; 
             CLASS = VLCInteraction; 
             LANGUAGE = ObjC; 
             OUTLETS = {
@@ -24,6 +24,7 @@
                 "o_prog_bar" = id; 
                 "o_prog_cancel_btn" = id; 
                 "o_prog_description" = id; 
+                "o_prog_timeToGo" = id; 
                 "o_prog_title" = id; 
                 "o_prog_win" = id; 
             }; 
index ed64cca67e42278f0abc0ebb49e21d8c7fa8680a..39b368d3886ed6709b3fd36afad9cbf0921484b8 100644 (file)
@@ -8,9 +8,9 @@
        <string>446.1</string>
        <key>IBOpenObjects</key>
        <array>
-               <integer>5</integer>
                <integer>55</integer>
                <integer>79</integer>
+               <integer>5</integer>
        </array>
        <key>IBSystem Version</key>
        <string>8J135</string>
index 06c835ef4562315897f7a60e05c5e16ade9534ea..b40051ad80d396e0b398151948e148b870d8b51c 100644 (file)
Binary files a/extras/MacOSX/Resources/English.lproj/Interaction.nib/keyedobjects.nib and b/extras/MacOSX/Resources/English.lproj/Interaction.nib/keyedobjects.nib differ
index de999ca8c8051b4f7ce858f221c1c173dfc8fcab..c8b29407239160c7185dddebf136b6e7049a8beb 100644 (file)
@@ -24,6 +24,7 @@
 
 /**
  * This structure describes an interaction widget
+ * WIDGETS ARE OUTDATED! THIS IS ONLY A STUB TO KEEP WX COMPILING!
  */
 struct user_widget_t
 {
@@ -35,6 +36,7 @@ struct user_widget_t
 
 /**
  * Possible widget types
+ * WIDGETS ARE OUTDATED! THIS IS ONLY A STUB TO KEEP WX COMPILING!
  */
 enum
 {
@@ -52,10 +54,15 @@ struct interaction_dialog_t
     int             i_type;             ///< Type identifier
     char           *psz_title;          ///< Title
     char           *psz_description;    ///< Descriptor string
+    char           *psz_defaultButton;  ///< default button title (~OK)
+    char           *psz_alternateButton;///< alternate button title (~NO)
+    char           *psz_otherButton;    ///< other button title (optional,~Cancel)
 
     char           *psz_returned[1];    ///< returned responses from the user
 
     vlc_value_t     val;                ///< a value coming from core for dialogue
+    int             i_timeToGo;         ///< time (in sec) until shown progress is finished
+    vlc_bool_t      b_cancelled;        ///< was the dialogue cancelled by the user?
 
     int             i_widgets;          ///< Number of dialog widgets
     user_widget_t **pp_widgets;         ///< Dialog widgets
@@ -76,8 +83,6 @@ struct interaction_dialog_t
  * Possible flags . Reusable and button types
  */
 #define DIALOG_REUSABLE             0x01
-#define DIALOG_OK_CANCEL            0x02
-#define DIALOG_YES_NO               0x04
 #define DIALOG_YES_NO_CANCEL        0x04
 #define DIALOG_CLEAR_NOSHOW         0x08
 #define DIALOG_GOT_ANSWER           0x10
@@ -169,22 +174,22 @@ VLC_EXPORT( int,__intf_Interact,( vlc_object_t *,interaction_dialog_t * ) );
 VLC_EXPORT( void, __intf_UserFatal,( vlc_object_t*, const char*, const char*, ...) );
 #define intf_UserLoginPassword( a, b, c, d, e... ) __intf_UserLoginPassword( VLC_OBJECT(a),b,c,d,e)
 VLC_EXPORT( int, __intf_UserLoginPassword,( vlc_object_t*, const char*, const char*, char **, char **) );
-#define intf_UserYesNo( a, b, c ) __intf_UserYesNo( VLC_OBJECT(a),b,c )
-VLC_EXPORT( int, __intf_UserYesNo,( vlc_object_t*, const char*, const char*) );
-#define intf_UserOkayCancel( a, b, c ) __intf_UserOkayCancel( VLC_OBJECT(a),b,c )
-VLC_EXPORT( int, __intf_UserOkayCancel,( vlc_object_t*, const char*, const char*) );
+#define intf_UserYesNo( a, b, c, d, e, f ) __intf_UserYesNo( VLC_OBJECT(a),b,c, d, e, f )
+VLC_EXPORT( int, __intf_UserYesNo,( vlc_object_t*, const char*, const char*, const char*, const char*, const char*) );
 
-#define intf_UserProgress( a, b, c, d ) __intf_UserProgress( VLC_OBJECT(a),b,c, d )
-VLC_EXPORT( int, __intf_UserProgress,( vlc_object_t*, const char*, const char*, float) );
-#define intf_UserProgressUpdate( a, b, c, d ) __intf_UserProgressUpdate( VLC_OBJECT(a),b,c, d )
-VLC_EXPORT( void, __intf_UserProgressUpdate,( vlc_object_t*, int, const char*, float) );
+#define intf_UserProgress( a, b, c, d, e ) __intf_UserProgress( VLC_OBJECT(a),b,c,d,e )
+VLC_EXPORT( int, __intf_UserProgress,( vlc_object_t*, const char*, const char*, float, int) );
+#define intf_UserProgressUpdate( a, b, c, d, e ) __intf_UserProgressUpdate( VLC_OBJECT(a),b,c,d,e )
+VLC_EXPORT( void, __intf_UserProgressUpdate,( vlc_object_t*, int, const char*, float, int) );
+#define intf_UserProgressIsCancelled( a, b ) __intf_UserProgressIsCancelled( VLC_OBJECT(a),b )
+VLC_EXPORT( vlc_bool_t, __intf_UserProgressIsCancelled,( vlc_object_t*, int ) );
 
 #define intf_UserStringInput( a, b, c, d ) __intf_UserStringInput( VLC_OBJECT(a),b,c,d )
 VLC_EXPORT( int, __intf_UserStringInput,(vlc_object_t*, const char*, const char*, char **) );
 
 #define intf_IntfProgress( a, b, c ) __intf_IntfProgress( VLC_OBJECT(a),b,c )
 VLC_EXPORT( int, __intf_IntfProgress,( vlc_object_t*, const char*, float) );
-#define intf_IntfProgressUpdate( a, b, c, d ) __intf_IntfProgressUpdate( VLC_OBJECT(a),b,c, d )
+#define intf_IntfProgressUpdate( a, b, c, d ) __intf_IntfProgressUpdate( VLC_OBJECT(a),b,c,d )
 VLC_EXPORT( void, __intf_IntfProgressUpdate,( vlc_object_t*, int, const char*, float) );
 
 #define intf_UserHide( a, b ) __intf_UserHide( VLC_OBJECT(a), b )
index 923900c6df484dbbb183d170863c9885c7f490b7..164f0b2c8cbdb977f50e922cd34fa110124c6b76 100644 (file)
@@ -558,7 +558,8 @@ aviindex:
             i_create = intf_UserYesNo( p_demux, _("AVI Index") ,
                         _( "This AVI file is broken. Seeking will not "
                         "work correctly.\nDo you want to "
-                        "try to repair it (this might take a long time) ?" ) );
+                        "try to repair it (this might take a long time) ?" ),
+                        _( "Repair" ), _( "Don't repair" ), NULL );
             if( i_create == DIALOG_OK_YES )
             {
                 b_index = VLC_TRUE;
index d82141bf0cafcb147eaa09530db68df43a53ff3d..28978997ccb329b550066e09c785a8741b81f8f5 100644 (file)
 
 @interface VLCInteraction : NSObject
 {
-    /* progress widget */
+    /* progress dialogue */
     IBOutlet id o_prog_bar;
     IBOutlet id o_prog_cancel_btn;
     IBOutlet id o_prog_description;
     IBOutlet id o_prog_title;
     IBOutlet id o_prog_win;
+    IBOutlet id o_prog_timeToGo;
 
     /* authentication dialogue */
     IBOutlet id o_auth_cancel_btn;
@@ -65,6 +66,7 @@
 
 - (IBAction)cancelAndClose:(id)sender;
 - (IBAction)okayAndClose:(id)sender;
+- (IBAction)cancelDialog:(id)sender;
 
 -(id)initDialog: (interaction_dialog_t *)_p_dialog;
 -(void)runDialog;
index 62fd42376fb28605d9a07f63dc72fa7d16574705..789bfebe8613ca580b4e0927fc8edaa6c41c7578 100644 (file)
 
     NSString *o_title = [NSString stringWithUTF8String:p_dialog->psz_title ? p_dialog->psz_title : "title"];
     NSString *o_description = [NSString stringWithUTF8String:p_dialog->psz_description ? p_dialog->psz_description : ""];
-    
+    NSString *o_defaultButton = [NSString stringWithUTF8String:p_dialog->psz_defaultButton];
+    NSString *o_alternateButton = [NSString stringWithUTF8String:p_dialog->psz_alternateButton];
+    NSString *o_otherButton = p_dialog->psz_otherButton ? [NSString stringWithUTF8String:p_dialog->psz_otherButton] : nil;
+
     vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
     if( p_vout != NULL )
     {
     }
     else
     {
-        if( p_dialog->i_flags & DIALOG_OK_CANCEL )
-        {
-            msg_Dbg( p_intf, "OK-Cancel-dialog requested" );
-            NSBeginInformationalAlertSheet( o_title, _NS("OK") , _NS("Cancel"),
-                nil, o_window, self,
-                @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, 
-                o_description );
-        }
-        else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
+        if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
         {
             msg_Dbg( p_intf, "yes-no-cancel-dialog requested" );
-            NSBeginInformationalAlertSheet( o_title, _NS("Yes"), _NS("No"),
-                _NS("Cancel"), o_window, self,
+            NSBeginInformationalAlertSheet( o_title, o_defaultButton, 
+                o_alternateButton, o_otherButton, o_window, self,
                 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, 
                 o_description );
         }
             [o_prog_title setStringValue: o_title];
             [o_prog_description setStringValue: o_description];
             [o_prog_bar setDoubleValue: (double)p_dialog->val.f_float];
+            if( p_dialog->i_timeToGo < 1 )
+                [o_prog_timeToGo setStringValue: @""];
+            else
+                [o_prog_timeToGo setStringValue: [NSString stringWithFormat:
+                    _NS("Remaining time: %i seconds"), p_dialog->i_timeToGo]];
             [NSApp beginSheet: o_prog_win modalForWindow: o_window
                 modalDelegate: self didEndSelector: nil contextInfo: nil];
             [o_prog_win makeKeyWindow];
     {
         p_dialog->i_return = DIALOG_OK_YES;
     }
-    else if( i_return == NSAlertAlternateReturn && ( p_dialog->i_flags & DIALOG_OK_CANCEL ) )
-    {
-        p_dialog->i_return = DIALOG_CANCELLED;
-    }
     else if( i_return == NSAlertAlternateReturn )
     {
         p_dialog->i_return = DIALOG_NO;
             /* we are done, let's hide */
             [self hideDialog];
         }
+
+        if( p_dialog->i_timeToGo < 1 )
+            [o_prog_timeToGo setStringValue: @""];
+        else
+            [o_prog_timeToGo setStringValue: [NSString stringWithFormat:
+                    _NS("Remaining time: %i seconds"), p_dialog->i_timeToGo]];
+
         return;
     }
     if( p_dialog->i_flags & DIALOG_INTF_PROGRESS )
 
 - (IBAction)cancelAndClose:(id)sender
 {
-    /* tell the core that the dialog was cancelled */
+    /* tell the core that the dialog was cancelled in a yes/no-style dialogue */
     vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
     p_dialog->i_return = DIALOG_CANCELLED;
     p_dialog->i_status = ANSWERED_DIALOG;
     msg_Dbg( p_intf, "dialog cancelled" );
 }
 
+- (IBAction)cancelDialog:(id)sender
+{
+    /* tell core that the user wishes to cancel the dialogue
+     * Use this function if cancelling is optionally like in the progress-dialogue */
+    vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
+    p_dialog->b_cancelled = VLC_TRUE;
+    vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
+    msg_Dbg( p_intf, "cancelling dialog, will close it later on" );
+}
+
 - (IBAction)okayAndClose:(id)sender
 {
     vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
index 9d704f200bfe2e93cb58783c1215332c44e10f49..80d569c0746cba1f9afd929f8274113673207daf 100644 (file)
@@ -196,7 +196,7 @@ static void Run( services_discovery_t *p_sd )
     int i_id = input_Read( p_sd, p_sys->p_input, VLC_FALSE );
     int i_dialog_id;
 
-    i_dialog_id = intf_UserProgress( p_sd, "Shoutcast" , "Connecting...", 0.0 );
+    i_dialog_id = intf_UserProgress( p_sd, "Shoutcast" , "Connecting...", 0.0, 0 );
 
     p_sys->b_dialog = VLC_TRUE;
     while( !p_sd->b_die )
@@ -215,7 +215,7 @@ static void Run( services_discovery_t *p_sd )
                 float f_pos = (float)(p_sys->p_node_cat->i_children)* 2 *100.0 /
                               260 /* gruiiik FIXME */;
                 intf_UserProgressUpdate( p_sd, i_dialog_id, "Downloading",
-                                         f_pos );
+                                         f_pos, 0 );
             }
             vlc_object_release( p_input );
         }
index 071a54c08ab5a77d398a52c2c60319c570f4ca42..458d65f229de12a72c6d07c8bbb57813c6001cc8 100644 (file)
@@ -143,8 +143,6 @@ void intf_InteractionManage( playlist_t *p_playlist )
 
             // Give default answer
             p_dialog->i_return = DIALOG_DEFAULT;
-            if( p_dialog->i_flags & DIALOG_OK_CANCEL )
-                p_dialog->i_return = DIALOG_CANCELLED;
 
             // Pretend we have hidden and destroyed it
             if( p_dialog->i_status == HIDDEN_DIALOG )
@@ -275,15 +273,21 @@ void __intf_UserFatal( vlc_object_t *p_this,
     intf_Interact( p_this, p_new );
 }
 
-/** Helper function to ask a yes-no question
+/** Helper function to ask a yes-no-cancel question
  *  \param p_this           Parent vlc_object
  *  \param psz_title        Title for the dialog
  *  \param psz_description  A description
+ *  \param psz_default      caption for the default button
+ *  \param psz_alternate    caption for the alternate button
+ *  \param psz_other        caption for the optional 3rd button (== cancel)
  *  \return                 Clicked button code
  */
 int __intf_UserYesNo( vlc_object_t *p_this,
                       const char *psz_title,
-                      const char *psz_description )
+                      const char *psz_description,
+                      const char *psz_default,
+                      const char *psz_alternate,
+                      const char *psz_other )
 {
     int i_ret;
     interaction_dialog_t *p_new = NULL;
@@ -294,31 +298,12 @@ int __intf_UserYesNo( vlc_object_t *p_this,
     p_new->psz_title = strdup( psz_title );
     p_new->psz_description = strdup( psz_description );
     p_new->i_flags = DIALOG_YES_NO_CANCEL;
-
-    i_ret = intf_Interact( p_this, p_new );
-
-    return i_ret;
-}
-
-/** Helper function to trigger a okay-cancel dialogue
- *  \param p_this           Parent vlc_object
- *  \param psz_title        Title for the dialog
- *  \param psz_description  A description
- *  \return                 Clicked button code
- */
-int __intf_UserOkayCancel( vlc_object_t *p_this,
-                      const char *psz_title,
-                      const char *psz_description )
-{
-    int i_ret;
-    interaction_dialog_t *p_new = NULL;
-
-    INTERACT_INIT( p_new );
-
-    p_new->i_type = INTERACT_DIALOG_TWOWAY;
-    p_new->psz_title = strdup( psz_title );
-    p_new->psz_description = strdup( psz_description );
-    p_new->i_flags = DIALOG_OK_CANCEL;
+    p_new->psz_defaultButton = strdup( psz_default );
+    p_new->psz_alternateButton = strdup( psz_alternate );
+    if( psz_other )
+        p_new->psz_otherButton = strdup( psz_other );
+    else
+        p_new->psz_otherButton = NULL;
 
     i_ret = intf_Interact( p_this, p_new );
 
@@ -330,12 +315,14 @@ int __intf_UserOkayCancel( vlc_object_t *p_this,
  *  \param psz_title        Title for the dialog
  *  \param psz_status       Current status
  *  \param f_position       Current position (0.0->100.0)
+ *  \param i_timeToGo       Time (in sec) to go until process is finished
  *  \return                 Dialog id, to give to UserProgressUpdate
  */
 int __intf_UserProgress( vlc_object_t *p_this,
                          const char *psz_title,
                          const char *psz_status,
-                         float f_pos )
+                         float f_pos,
+                         int i_time )
 {
     int i_ret;
     interaction_dialog_t *p_new = NULL;
@@ -346,6 +333,7 @@ int __intf_UserProgress( vlc_object_t *p_this,
     p_new->psz_title = strdup( psz_title );
     p_new->psz_description = strdup( psz_status );
     p_new->val.f_float = f_pos;
+    p_new->i_timeToGo = i_time;
 
     p_new->i_flags = DIALOG_USER_PROGRESS;
 
@@ -359,10 +347,12 @@ int __intf_UserProgress( vlc_object_t *p_this,
  *  \param i_id             Identifier of the dialog
  *  \param psz_status       New status
  *  \param f_position       New position (0.0->100.0)
+ *  \param i_timeToGo       Time (in sec) to go until process is finished
  *  \return                 nothing
  */
 void __intf_UserProgressUpdate( vlc_object_t *p_this, int i_id,
-                                const char *psz_status, float f_pos )
+                                const char *psz_status, float f_pos, 
+                                int i_time )
 {
     interaction_t *p_interaction = intf_InteractionGet( p_this );
     interaction_dialog_t *p_dialog;
@@ -383,11 +373,37 @@ void __intf_UserProgressUpdate( vlc_object_t *p_this, int i_id,
     p_dialog->psz_description = strdup( psz_status );
 
     p_dialog->val.f_float = f_pos;
+    p_dialog->i_timeToGo = i_time;
 
     p_dialog->i_status = UPDATED_DIALOG;
     vlc_mutex_unlock( &p_interaction->object_lock) ;
 }
 
+/** Helper function to communicate dialogue cancellations between the intf-module and caller
+ *  \param p_this           Parent vlc_object
+ *  \param i_id             Identifier of the dialogue
+ *  \return                 Either true or false
+ */
+vlc_bool_t __intf_UserProgressIsCancelled( vlc_object_t *p_this, int i_id )
+{
+    interaction_t *p_interaction = intf_InteractionGet( p_this );
+    interaction_dialog_t *p_dialog;
+
+    if( !p_interaction ) return VLC_TRUE;
+
+    vlc_mutex_lock( &p_interaction->object_lock );
+    p_dialog  =  intf_InteractionGetById( p_this, i_id );
+
+    if( !p_dialog )
+    {
+        vlc_mutex_unlock( &p_interaction->object_lock ) ;
+        return VLC_TRUE;
+    }
+
+    vlc_mutex_unlock( &p_interaction->object_lock) ;
+    return p_dialog->b_cancelled;
+}
+
 /** Helper function to make a login/password dialogue
  *  \param p_this           Parent vlc_object
  *  \param psz_title        Title for the dialog
index 37a47e2fe4fca47f6f5268a9c1fbbb7ba5ed7e10..b77afc2c5ead7bbec6949340a933b33e468a6f21 100644 (file)
@@ -1264,7 +1264,7 @@ void update_download_for_real( download_thread_t *p_this )
     asprintf( &psz_status, "%s\nDownloading... 0.0/? %.1f%% done",
               p_this->psz_status, 0.0 );
     i_progress = intf_UserProgress( p_vlc, "Downloading...",
-                                    psz_status, 0.0 );
+                                    psz_status, 0.0, 0 );
 
     p_stream = stream_UrlNew( p_vlc, psz_src );
     if( !p_stream )
@@ -1309,7 +1309,7 @@ void update_download_for_real( download_thread_t *p_this )
                 free( psz_s1 ); free( psz_s2 );
 
                 intf_UserProgressUpdate( p_vlc, i_progress,
-                                         psz_status, f_progress );
+                                         psz_status, f_progress, 0 );
             }
 
             free( p_buffer );
@@ -1321,7 +1321,7 @@ void update_download_for_real( download_thread_t *p_this )
             asprintf( &psz_status, "%s\nDone %s (100.00%%)",
                        p_this->psz_status, psz_s2 );
             free( psz_s2 );
-            intf_UserProgressUpdate( p_vlc, i_progress, psz_status, 100.0 );
+            intf_UserProgressUpdate( p_vlc, i_progress, psz_status, 100.0, 0 );
             free( psz_status );
         }
     }