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

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