diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index 02bafa3c7..e72ec77b4 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -4669,7 +4669,7 @@ void dc_event_unref(dc_event_t* event); * Inform about the configuration progress started by dc_configure(). * * @param data1 (int) 0=error, 1-999=progress in permille, 1000=success and done - * @param data2 0 + * @param data2 (char*) progress comment, error message or NULL if not applicable */ #define DC_EVENT_CONFIGURE_PROGRESS 2041 @@ -4733,7 +4733,7 @@ void dc_event_unref(dc_event_t* event); #define DC_EVENT_DATA1_IS_STRING(e) 0 // not used anymore -#define DC_EVENT_DATA2_IS_STRING(e) ((e)==DC_EVENT_IMEX_FILE_WRITTEN || ((e)>=100 && (e)<=499)) +#define DC_EVENT_DATA2_IS_STRING(e) ((e)==DC_EVENT_CONFIGURE_PROGRESS || (e)==DC_EVENT_IMEX_FILE_WRITTEN || ((e)>=100 && (e)<=499)) /* diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 0ff77c69a..57bce29ba 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -372,7 +372,7 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc: let id = id.unwrap_or_default(); id as libc::c_int } - EventType::ConfigureProgress(progress) | EventType::ImexProgress(progress) => { + EventType::ConfigureProgress { progress, .. } | EventType::ImexProgress(progress) => { *progress as libc::c_int } EventType::ImexFileWritten(_) => 0, @@ -405,7 +405,7 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc: | EventType::ErrorSelfNotInGroup(_) | EventType::ContactsChanged(_) | EventType::LocationChanged(_) - | EventType::ConfigureProgress(_) + | EventType::ConfigureProgress { .. } | EventType::ImexProgress(_) | EventType::ImexFileWritten(_) | EventType::ChatModified(_) => 0, @@ -453,11 +453,17 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut | EventType::ChatModified(_) | EventType::ContactsChanged(_) | EventType::LocationChanged(_) - | EventType::ConfigureProgress(_) | EventType::ImexProgress(_) | EventType::SecurejoinInviterProgress { .. } | EventType::SecurejoinJoinerProgress { .. } | EventType::ChatEphemeralTimerModified { .. } => ptr::null_mut(), + EventType::ConfigureProgress { comment, .. } => { + if let Some(comment) = comment { + comment.to_c_string().unwrap_or_default().into_raw() + } else { + ptr::null_mut() + } + } EventType::ImexFileWritten(file) => { let data2 = file.to_c_string().unwrap_or_default(); data2.into_raw() diff --git a/examples/repl/main.rs b/examples/repl/main.rs index c216157e2..9e5b32922 100644 --- a/examples/repl/main.rs +++ b/examples/repl/main.rs @@ -80,11 +80,21 @@ fn receive_event(event: EventType) { yellow.paint(format!("Received LOCATION_CHANGED(contact={:?})", contact)) ); } - EventType::ConfigureProgress(progress) => { - info!( - "{}", - yellow.paint(format!("Received CONFIGURE_PROGRESS({} ‰)", progress)) - ); + EventType::ConfigureProgress { progress, comment } => { + if let Some(comment) = comment { + info!( + "{}", + yellow.paint(format!( + "Received CONFIGURE_PROGRESS({} ‰, {})", + progress, comment + )) + ); + } else { + info!( + "{}", + yellow.paint(format!("Received CONFIGURE_PROGRESS({} ‰)", progress)) + ); + } } EventType::ImexProgress(progress) => { info!( diff --git a/examples/simple.rs b/examples/simple.rs index 863960ea3..4f84db137 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -10,7 +10,7 @@ use deltachat::EventType; fn cb(event: EventType) { match event { - EventType::ConfigureProgress(progress) => { + EventType::ConfigureProgress { progress, .. } => { log::info!("progress: {}", progress); } EventType::Info(msg) => { diff --git a/src/configure/mod.rs b/src/configure/mod.rs index 8783fd30e..0d25c5baf 100644 --- a/src/configure/mod.rs +++ b/src/configure/mod.rs @@ -27,12 +27,18 @@ use auto_outlook::outlk_autodiscover; use server_params::{expand_param_vector, ServerParams}; macro_rules! progress { - ($context:tt, $progress:expr) => { + ($context:tt, $progress:expr, $comment:expr) => { assert!( $progress <= 1000, "value in range 0..1000 expected with: 0=error, 1..999=progress, 1000=success" ); - $context.emit_event($crate::events::EventType::ConfigureProgress($progress)); + $context.emit_event($crate::events::EventType::ConfigureProgress { + progress: $progress, + comment: $comment, + }); + }; + ($context:tt, $progress:expr) => { + progress!($context, $progress, None); }; } @@ -111,7 +117,7 @@ impl Context { Ok(()) } Err(err) => { - progress!(self, 0); + progress!(self, 0, Some(err.to_string())); Err(err) } } diff --git a/src/events.rs b/src/events.rs index a0c5b07ce..87006a49b 100644 --- a/src/events.rs +++ b/src/events.rs @@ -233,10 +233,16 @@ pub enum EventType { LocationChanged(Option), /// Inform about the configuration progress started by configure(). - /// - /// @param data1 (usize) 0=error, 1-999=progress in permille, 1000=success and done #[strum(props(id = "2041"))] - ConfigureProgress(usize), + ConfigureProgress { + /// Progress. + /// + /// 0=error, 1-999=progress in permille, 1000=success and done + progress: usize, + + /// Progress comment or error, something to display to the user. + comment: Option, + }, /// Inform about the import/export progress started by imex(). ///