diff options
author | Michael Vetter <jubalh@iodoru.org> | 2022-05-30 18:04:36 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2022-05-30 18:04:36 +0200 |
commit | cf83976b51dd103a17b75dd77f326f64166199bc (patch) | |
tree | c4307d8ba27a81e3319ca87df7282cfed42342f4 | |
parent | 010ed78b32a501395476ec98cab5cdff4c32fb12 (diff) | |
download | profani-tty-cf83976b51dd103a17b75dd77f326f64166199bc.tar.gz |
Add basic qrcode functions
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | src/command/cmd_ac.c | 1 | ||||
-rw-r--r-- | src/command/cmd_defs.c | 3 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 12 | ||||
-rw-r--r-- | src/command/cmd_funcs.h | 1 | ||||
-rw-r--r-- | src/ui/console.c | 34 | ||||
-rw-r--r-- | src/ui/ui.h | 4 | ||||
-rw-r--r-- | tests/unittests/ui/stub_ui.c | 11 |
8 files changed, 73 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 2cf3e026..0f997dde 100644 --- a/configure.ac +++ b/configure.ac @@ -67,6 +67,8 @@ AC_ARG_ENABLE([icons-and-clipboard], [AS_HELP_STRING([--enable-icons-and-clipboard], [enable GTK tray icons and clipboard paste support])]) AC_ARG_ENABLE([gdk-pixbuf], [AS_HELP_STRING([--enable-gdk-pixbuf], [enable GDK Pixbuf support to scale avatars before uploading])]) +AC_ARG_ENABLE([omemo-qrcode], + [AS_HELP_STRING([--enable-omemo-qrcode], [enable ability to display omemo qr code])]) # Required dependencies @@ -345,6 +347,12 @@ AS_IF([test "x$with_themes" = xno -o "x$with_themes" = xyes -o "x$with_themes" = AC_SUBST(THEMES_PATH) AM_CONDITIONAL([THEMES_INSTALL], "$THEMES_INSTALL") +dnl feature: omemo qrcode +AS_IF([test "x$omemo_qrcode" != xno], + [PKG_CHECK_MODULES([libqrencode], [libqrencode], + [AC_DEFINE([HAVE_QRENCODE], [1], [qrcode module])] + [LIBS="-lqrencode $LIBS"]], [])) + ## Tests # cmocka is required only for tests, profanity shouldn't be linked with it diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 9fc70a1d..531d189b 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -700,6 +700,7 @@ cmd_ac_init(void) autocomplete_add(omemo_ac, "policy"); autocomplete_add(omemo_ac, "trustmode"); autocomplete_add(omemo_ac, "char"); + autocomplete_add(omemo_ac, "qrcode"); omemo_log_ac = autocomplete_new(); autocomplete_add(omemo_log_ac, "on"); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 57d90226..ac226544 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2312,7 +2312,8 @@ static struct cmd_t command_defs[] = { { "fingerprint", cmd_omemo_fingerprint }, { "char", cmd_omemo_char }, { "policy", cmd_omemo_policy }, - { "clear_device_list", cmd_omemo_clear_device_list }) + { "clear_device_list", cmd_omemo_clear_device_list }, + { "qrcode", cmd_omemo_qrcode }) CMD_NOMAINFUNC CMD_TAGS( CMD_TAG_CHAT, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 2a8331d1..29c8a29a 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9036,6 +9036,18 @@ cmd_omemo_policy(ProfWin* window, const char* const command, gchar** args) } gboolean +cmd_omemo_qrcode(ProfWin* window, const char* const command, gchar** args) +{ +#ifdef HAVE_OMEMO + cons_show_omemo_qrcode("some text from me"); + return TRUE; +#else + cons_show("This version of Profanity has not been built with OMEMO support enabled"); + return TRUE; +#endif +} + +gboolean cmd_save(ProfWin* window, const char* const command, gchar** args) { log_info("Saving preferences to configuration file"); diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index 621dd1c6..adc6793d 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -227,6 +227,7 @@ gboolean cmd_omemo_untrust(ProfWin* window, const char* const command, gchar** a gboolean cmd_omemo_trust_mode(ProfWin* window, const char* const command, gchar** args); gboolean cmd_omemo_policy(ProfWin* window, const char* const command, gchar** args); gboolean cmd_omemo_clear_device_list(ProfWin* window, const char* const command, gchar** args); +gboolean cmd_omemo_qrcode(ProfWin* window, const char* const command, gchar** args); gboolean cmd_save(ProfWin* window, const char* const command, gchar** args); gboolean cmd_reload(ProfWin* window, const char* const command, gchar** args); diff --git a/src/ui/console.c b/src/ui/console.c index 3e7a0844..ae1f796d 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,36 @@ 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(); + + 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"); + } + + data++; + } + win_println(console, THEME_DEFAULT, "", ""); + } + + QRcode_free(qrcode); +#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); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 768e654b..a1bb7d61 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -923,27 +923,38 @@ 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_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) { } + void cons_show_incoming_room_message(const char* const nick, const char* const room, const int win_index, gboolean mention, GList* triggers, int unread, ProfWin* const window) { } + void cons_show_incoming_message(const char* const short_from, const int win_index, int unread, ProfWin* const window) { |