1
0
Fork 0

Add basic qrcode functions

This commit is contained in:
Michael Vetter 2022-05-30 18:04:36 +02:00
parent 010ed78b32
commit cf83976b51
8 changed files with 73 additions and 1 deletions

View File

@ -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

View File

@ -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");

View File

@ -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,

View File

@ -9035,6 +9035,18 @@ cmd_omemo_policy(ProfWin* window, const char* const command, gchar** args)
#endif
}
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)
{

View File

@ -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);

View File

@ -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"
@ -862,6 +866,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)
{

View File

@ -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);

View File

@ -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)
{