mirror of
https://github.com/chatmail/core.git
synced 2026-10-01 18:50:39 +03:00
api: create QR codes from any data (#6090)
this PR adds a function that can be used to create any QR code, in a raw form. this can be used to create add-contact as well as add-second-device QR codes (eg. `dc_create_qr_svg(dc_get_securejoin_qr())`) - as well as for other QR codes as proxies. the disadvantage of the rich-formatted QR codes as created by `dc_get_securejoin_qr_svg()` and `dc_backup_provider_get_qr_svg()` were: - they do not look good and cannot interact with UI layout wise (but also tapping eg. an address is not easily possible) - esp. text really looks bad. even with [some](https://github.com/deltachat/deltachat-android/pull/2138/commits/e5dc8fe3d82e8b72631ae5806e9c4c7eec93a37a) [hacks](https://github.com/deltachat/deltachat-android/pull/2215) it [stays buggy](https://github.com/deltachat/deltachat-ios/issues/2200); the bugs mainly come from different SVG implementation, all need their own quirks - accessibility is probably bad as well we thought that time, SVG is a great thing for QR codes, but apart from basic geometrics, it is not. so, we avoid text, this also means to avoid putting an avatar in the middle of the QR code (we can put some generic symbol there, eg. different ones for add-contact and add-second-device). while this looks like a degradation, also other messengers use more raw QR codes. also, we removed many data from the QR code anyway, eg. the email address is no longer there. that time, sharing QR images was more a thing, meanwhile we have invite links, that are much better for that purpose. in theory, we could also leave the SVG path completely and go for PNG - which we did not that time as PNG and text looks bad, as the system font is not easily usable :) but going for PNG would add further challenges as passing binary data around, and also UI-implemtation-wise, that would be a larger step. so, let's stay with SVG in a form we know is compatible. the old QR code functions are deprecated.
This commit is contained in:
@@ -30,7 +30,7 @@ use deltachat::ephemeral::Timer as EphemeralTimer;
|
||||
use deltachat::imex::BackupProvider;
|
||||
use deltachat::key::preconfigure_keypair;
|
||||
use deltachat::message::MsgId;
|
||||
use deltachat::qr_code_generator::{generate_backup_qr, get_securejoin_qr_svg};
|
||||
use deltachat::qr_code_generator::{create_qr_svg, generate_backup_qr, get_securejoin_qr_svg};
|
||||
use deltachat::stock_str::StockMessage;
|
||||
use deltachat::webxdc::StatusUpdateSerial;
|
||||
use deltachat::*;
|
||||
@@ -2594,6 +2594,18 @@ pub unsafe extern "C" fn dc_delete_all_locations(context: *mut dc_context_t) {
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_create_qr_svg(payload: *const libc::c_char) -> *mut libc::c_char {
|
||||
if payload.is_null() {
|
||||
eprintln!("ignoring careless call to dc_create_qr_svg()");
|
||||
return "".strdup();
|
||||
}
|
||||
|
||||
create_qr_svg(&to_string_lossy(payload))
|
||||
.unwrap_or_else(|_| "".to_string())
|
||||
.strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_last_error(context: *mut dc_context_t) -> *mut libc::c_char {
|
||||
if context.is_null() {
|
||||
|
||||
Reference in New Issue
Block a user