Turn deltachat::configure functions into Context methods

Now configure module is no longer public. Users should call
Context.configure() and Context.is_configured() methods.

Configure module is completely hidden from documentation unless
--document-private-items option is specified.
This commit is contained in:
Alexander Krotov
2020-02-16 17:12:46 +03:00
committed by Floris Bruynooghe
parent e00d4e0ed8
commit 2977ceb459
6 changed files with 20 additions and 23 deletions

View File

@@ -488,9 +488,7 @@ pub unsafe extern "C" fn dc_configure(context: *mut dc_context_t) {
return; return;
} }
let ffi_context = &*context; let ffi_context = &*context;
ffi_context ffi_context.with_inner(|ctx| ctx.configure()).unwrap_or(())
.with_inner(|ctx| configure::configure(ctx))
.unwrap_or(())
} }
#[no_mangle] #[no_mangle]
@@ -501,7 +499,7 @@ pub unsafe extern "C" fn dc_is_configured(context: *mut dc_context_t) -> libc::c
} }
let ffi_context = &*context; let ffi_context = &*context;
ffi_context ffi_context
.with_inner(|ctx| configure::dc_is_configured(ctx) as libc::c_int) .with_inner(|ctx| ctx.is_configured() as libc::c_int)
.unwrap_or(0) .unwrap_or(0)
} }

View File

@@ -22,7 +22,6 @@ use std::sync::{Arc, Mutex, RwLock};
use deltachat::chat::ChatId; use deltachat::chat::ChatId;
use deltachat::config; use deltachat::config;
use deltachat::configure::*;
use deltachat::context::*; use deltachat::context::*;
use deltachat::job::*; use deltachat::job::*;
use deltachat::oauth2::*; use deltachat::oauth2::*;
@@ -463,7 +462,7 @@ fn handle_cmd(line: &str, ctx: Arc<RwLock<Context>>) -> Result<ExitResult, failu
} }
"configure" => { "configure" => {
start_threads(ctx.clone()); start_threads(ctx.clone());
configure(&ctx.read().unwrap()); ctx.read().unwrap().configure();
} }
"oauth2" => { "oauth2" => {
if let Some(addr) = ctx.read().unwrap().get_config(config::Config::Addr) { if let Some(addr) = ctx.read().unwrap().get_config(config::Config::Addr) {

View File

@@ -7,7 +7,6 @@ use tempfile::tempdir;
use deltachat::chat; use deltachat::chat;
use deltachat::chatlist::*; use deltachat::chatlist::*;
use deltachat::config; use deltachat::config;
use deltachat::configure::*;
use deltachat::contact::*; use deltachat::contact::*;
use deltachat::context::*; use deltachat::context::*;
use deltachat::job::{ use deltachat::job::{
@@ -77,7 +76,7 @@ fn main() {
ctx.set_config(config::Config::Addr, Some("d@testrun.org")) ctx.set_config(config::Config::Addr, Some("d@testrun.org"))
.unwrap(); .unwrap();
ctx.set_config(config::Config::MailPw, Some(&pw)).unwrap(); ctx.set_config(config::Config::MailPw, Some(&pw)).unwrap();
configure(&ctx); ctx.configure();
thread::sleep(duration); thread::sleep(duration);

View File

@@ -32,26 +32,28 @@ macro_rules! progress {
}; };
} }
// connect impl Context {
pub fn configure(context: &Context) { /// Starts a configuration job.
if context.has_ongoing() { pub fn configure(&self) {
warn!(context, "There is already another ongoing process running.",); if self.has_ongoing() {
return; warn!(self, "There is already another ongoing process running.",);
return;
}
job_kill_action(self, job::Action::ConfigureImap);
job_add(self, job::Action::ConfigureImap, 0, Params::new(), 0);
} }
job_kill_action(context, job::Action::ConfigureImap);
job_add(context, job::Action::ConfigureImap, 0, Params::new(), 0);
}
/// Check if the context is already configured. /// Checks if the context is already configured.
pub fn dc_is_configured(context: &Context) -> bool { pub fn is_configured(&self) -> bool {
context.sql.get_raw_config_bool(context, "configured") self.sql.get_raw_config_bool(self, "configured")
}
} }
/******************************************************************************* /*******************************************************************************
* Configure JOB * Configure JOB
******************************************************************************/ ******************************************************************************/
#[allow(non_snake_case, unused_must_use, clippy::cognitive_complexity)] #[allow(non_snake_case, unused_must_use, clippy::cognitive_complexity)]
pub fn JobConfigureImap(context: &Context) -> job::Status { pub(crate) fn JobConfigureImap(context: &Context) -> job::Status {
if !context.sql.is_open() { if !context.sql.is_open() {
error!(context, "Cannot configure, database not opened.",); error!(context, "Cannot configure, database not opened.",);
progress!(context, 0); progress!(context, 0);

View File

@@ -10,7 +10,6 @@ use crate::blob::BlobObject;
use crate::chat; use crate::chat;
use crate::chat::delete_and_reset_all_device_msgs; use crate::chat::delete_and_reset_all_device_msgs;
use crate::config::Config; use crate::config::Config;
use crate::configure::*;
use crate::constants::*; use crate::constants::*;
use crate::context::Context; use crate::context::Context;
use crate::dc_tools::*; use crate::dc_tools::*;
@@ -414,7 +413,7 @@ fn import_backup(context: &Context, backup_to_import: impl AsRef<Path>) -> Resul
); );
ensure!( ensure!(
!dc_is_configured(context), !context.is_configured(),
"Cannot import backups to accounts in use." "Cannot import backups to accounts in use."
); );
context.sql.close(&context); context.sql.close(&context);

View File

@@ -31,7 +31,7 @@ pub mod blob;
pub mod chat; pub mod chat;
pub mod chatlist; pub mod chatlist;
pub mod config; pub mod config;
pub mod configure; mod configure;
pub mod constants; pub mod constants;
pub mod contact; pub mod contact;
pub mod context; pub mod context;