Fix qr segfault and support gemini urls

This commit is contained in:
Martijn Braam 2021-02-21 16:57:33 +01:00
parent a9d01640bd
commit 36193243f5
No known key found for this signature in database
GPG Key ID: C4280ACB000B060F
2 changed files with 10 additions and 4 deletions

11
main.c
View File

@ -445,7 +445,10 @@ on_zbar_code_tapped(GtkWidget *widget, const MPZBarCode *code)
GtkWidget *dialog;
GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
bool data_is_url = strncmp(code->data, "http://", 7) == 0
|| strncmp(code->data, "https://", 8) == 0;
|| strncmp(code->data, "https://", 8) == 0
|| strncmp(code->data, "gemini://", 9) == 0;
char* data = strdup(code->data);
if (data_is_url) {
dialog = gtk_message_dialog_new(
@ -484,7 +487,7 @@ on_zbar_code_tapped(GtkWidget *widget, const MPZBarCode *code)
GError *error = NULL;
switch (result) {
case GTK_RESPONSE_YES:
if (!g_app_info_launch_default_for_uri(code->data,
if (!g_app_info_launch_default_for_uri(data,
NULL, &error)) {
g_printerr("Could not launch browser: %s\n",
error->message);
@ -492,9 +495,11 @@ on_zbar_code_tapped(GtkWidget *widget, const MPZBarCode *code)
case GTK_RESPONSE_ACCEPT:
gtk_clipboard_set_text(
gtk_clipboard_get(GDK_SELECTION_PRIMARY),
code->data, -1);
data, -1);
case GTK_RESPONSE_CANCEL:
break;
default:
g_printerr("Wrong dialog result: %d\n", result);
}
gtk_widget_destroy(dialog);
}

View File

@ -102,8 +102,9 @@ process_symbol(const zbar_symbol_t *symbol)
const char *data = zbar_symbol_get_data(symbol);
unsigned int data_size = zbar_symbol_get_data_length(symbol);
code.data = strndup(data, data_size);
code.type = zbar_get_symbol_name(type);
code.data = strndup(data, data_size+1);
code.data[data_size] = 0;
return code;
}