1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

implement working OMEMO QR code

TODO: We need to find a way to switch the colors of the QR code, so that
more QR readers can detect it, without "blending" the edges of the QR
code with the surrounding terminal window.

Signed-off-by: swirl <swurl@swurl.xyz>
This commit is contained in:
swirl 2022-05-27 15:25:28 -04:00 committed by Michael Vetter
parent cf83976b51
commit 9a9a97868d
2 changed files with 19 additions and 8 deletions

View File

@ -9039,7 +9039,18 @@ gboolean
cmd_omemo_qrcode(ProfWin* window, const char* const command, gchar** args)
{
#ifdef HAVE_OMEMO
cons_show_omemo_qrcode("some text from me");
if (connection_get_status() != JABBER_CONNECTED) {
cons_show("You must be connected with an account to load OMEMO information.");
return TRUE;
}
if (!omemo_loaded()) {
win_println(window, THEME_DEFAULT, "!", "You have not generated or loaded a cryptographic materials, use '/omemo gen'");
return TRUE;
}
char* fingerprint = omemo_own_fingerprint(TRUE);
cons_show_omemo_qrcode(fingerprint);
return TRUE;
#else
cons_show("This version of Profanity has not been built with OMEMO support enabled");
@ -9767,3 +9778,4 @@ cmd_mood(ProfWin* window, const char* const command, gchar** args)
}
return TRUE;
}

View File

@ -878,18 +878,16 @@ cons_show_omemo_qrcode(const char* const text)
ProfWin* console = wins_get_console();
char buf[(width * 4) + 1];
memset(buf, 0, sizeof buf);
for (size_t y = 0; y < width; y+=ZOOM_SIZE) {
//size_t y_index = y * width;
for (size_t x = 0; x < width; x+=ZOOM_SIZE) {
if (x==0) {
win_print(console, THEME_DEFAULT, "", "%s", (*data & 1) ? "A" : "B");
} else {
win_append(console, THEME_DEFAULT, "", "%s", (*data & 1) ? "A" : "B");
}
strcat(buf, (*data & 1) ? "\u2588\u2588" : "\u2800\u2800");
data++;
}
win_println(console, THEME_DEFAULT, "", "");
win_println(console, THEME_DEFAULT, "", "%s", buf);
memset(buf, 0, sizeof buf);
}
QRcode_free(qrcode);
@ -2928,3 +2926,4 @@ cons_remove_alert(ProfWin* window)
g_list_free_full(item, g_free);
free(win_name);
}