diff options
author | Michael Vetter <jubalh@iodoru.org> | 2022-05-31 09:11:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 09:11:53 +0200 |
commit | 754c110a34bf608bee3990e5b626203699b879d2 (patch) | |
tree | 0f432595d07768259281a9a929691608ba576e38 /src/ui | |
parent | 010ed78b32a501395476ec98cab5cdff4c32fb12 (diff) | |
parent | 3557e46b6d1e99491be0dc4ee85fe157475c0ae3 (diff) | |
download | profani-tty-754c110a34bf608bee3990e5b626203699b879d2.tar.gz |
Merge pull request #1568 from profanity-im/feature/1320-omemo-qrcode
Show OMEMO QR Code
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/console.c | 47 | ||||
-rw-r--r-- | src/ui/ui.h | 4 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/ui/console.c b/src/ui/console.c index 3e7a0844..32575a15 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -48,6 +48,10 @@ #include <curses.h> #endif +#ifdef HAVE_QRENCODE +#include <qrencode.h> +#endif + #include "common.h" #include "log.h" #include "config/preferences.h" @@ -863,6 +867,49 @@ cons_show_disco_contact_information(GHashTable* addresses) } void +cons_show_omemo_qrcode(const char* const text) +{ +#ifdef HAVE_QRENCODE + static const size_t ZOOM_SIZE = 10; + QRcode* qrcode = QRcode_encodeString(text, 0, QR_ECLEVEL_L, QR_MODE_8, 1); + + int width = (qrcode->width * ZOOM_SIZE); + unsigned char* data = qrcode->data; + + ProfWin* console = wins_get_console(); + + char buf[(width * 4) + 1]; + memset(buf, 0, sizeof buf); + + char tmp[(width * 4) + 5]; + memset(tmp, 0, sizeof tmp); + + for (int i = 0; i < width + 2 * ZOOM_SIZE; i += ZOOM_SIZE) { + strcat(tmp, "\u2588\u2588"); + } + + win_println(console, THEME_DEFAULT, "", tmp); + for (size_t y = 0; y < width; y += ZOOM_SIZE) { + for (size_t x = 0; x < width; x += ZOOM_SIZE) { + strcat(buf, !(*data & 1) ? "\u2588\u2588" : "\u2800\u2800"); + + data++; + } + + // The extra squares are for padding, so that the QR code doesn't + // "blend in" with the rest of the terminal window. + win_println(console, THEME_DEFAULT, "", "\u2588\u2588%s\u2588\u2588", buf); + memset(buf, 0, sizeof buf); + } + win_println(console, THEME_DEFAULT, "", "%s", tmp); + + QRcode_free(qrcode); +#else + cons_show("This version of Profanity has not been built with libqrencode"); +#endif +} + +void cons_show_status(const char* const barejid) { ProfWin* console = wins_get_console(); diff --git a/src/ui/ui.h b/src/ui/ui.h index 5f31354f..8615045a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -277,7 +277,11 @@ void cons_show_bookmarks(const GList* list); void cons_show_bookmarks_ignore(gchar** list, gsize len); void cons_show_disco_items(GSList* items, const char* const jid); void cons_show_disco_info(const char* from, GSList* identities, GSList* features); + void cons_show_disco_contact_information(GHashTable* addresses); + +void cons_show_omemo_qrcode(const char* const text); + void cons_show_room_invite(const char* const invitor, const char* const room, const char* const reason); void cons_check_version(gboolean not_available_msg); void cons_show_typing(const char* const barejid); |