(copied from https://gitlab.com/postmarketOS/megapixels/-/issues/72 running version megapixels-1.7.0-r0 on Linux 6.6.3 with pmos)
So I am trying to work out what megapixels is doing with the QR code; My knowledge is extremely limited so please bear with me:
- I cannot see how to debug the code. There are very few messages logged in normal use.
- I have found the following code which seems to be relevant:
main.c #612
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 =
g_uri_is_valid(code->data, G_URI_FLAGS_PARSE_RELAXED, NULL);
char *data = strdup(code->data);
if (data_is_url) {
dialog = gtk_message_dialog_new(
GTK_WINDOW(gtk_widget_get_root(widget)),
flags,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"Found a URL '%s' encoded in a %s.",
code->data,
code->type);
gtk_dialog_add_buttons(
GTK_DIALOG(dialog), "_Open URL", GTK_RESPONSE_YES, NULL);
} else {
dialog = gtk_message_dialog_new(
GTK_WINDOW(gtk_widget_get_root(widget)),
flags,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"Found data encoded in a %s.",
code->type);
gtk_message_dialog_format_secondary_markup(
GTK_MESSAGE_DIALOG(dialog), "<small>%s</small>", code->data);
}
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
"_Copy",
GTK_RESPONSE_ACCEPT,
"_Cancel",
GTK_RESPONSE_CANCEL,
NULL);
g_signal_connect(
dialog, "response", G_CALLBACK(on_zbar_dialog_response), data);
gtk_widget_show(GTK_WIDGET(dialog));
}
main.c #588
on_zbar_dialog_response(GtkDialog *dialog, int response, char *data)
{
g_autoptr(GError) error = NULL;
switch (response) {
case GTK_RESPONSE_YES:
if (!g_app_info_launch_default_for_uri(data, NULL, &error)) {
g_printerr("Could not launch application: %s\n",
error->message);
}
case GTK_RESPONSE_ACCEPT: {
GdkDisplay *display = gtk_widget_get_display(GTK_WIDGET(dialog));
gdk_clipboard_set_text(gdk_display_get_clipboard(display), data);
}
case GTK_RESPONSE_CANCEL:
break;
default:
g_printerr("Wrong dialog response: %d\n", response);
}
g_free(data);
gtk_window_destroy(GTK_WINDOW(dialog));
}
The first appears to check whether the entry is a valid URL, and, if true; adds the line "Found a URL '%s' encoded in a %s." and adds a button "_Open URL". If false; adds the line "Found data encoded in a %s." It then adds two buttons "_Copy" and "_Cancel".
The second appears to handle the response to the dialog. On "YES" attempts to launch the URL and if that fails then prints an error "Could not launch application: %s\n". ON "ACCEPT" copies the data to the clipboard. On "CANCEL" breaks.
I have tried three different QR codes with the following results:
- Code for a simple address: Correctly shows the address and only shows buttons for Copy and Cancel. Select Copy, leave megapixels open, enter wl-paste in a terminal, address is not found in the clipboard.
- Code for a wifi uri: First set an xdg-mime type for a wifi uri. Test it with
xdg-open 'wifi code' (note the single inverted commas). Enter wl-paste in a terminal, wifi code has been copied and is correctly retrieved from the clipboard. Now try by scanning the QR code with megapixels; correctly shows the wifi code and shows the three buttons Open URL, Copy and Cancel. Select Open URL, prints "Could not launch application: The specified location is not supported"
- Code for a URL: TL;DR opens the URL in the browser.
Speculation:
The URL/URI is accepted because G_URI_FLAGS_PARSE_RELAXED allows the semi-colons to pass. Normally a URL should/would not include semi-colons whereas a wifi URI will have them. Possibly the wifi URI is passed without escaping the semi-colons, or quoting the wifi-code?
Could the failure to copy be to do with wayland? Above I used wayland copy/paste to access the clipbooard. I have tried some other clipboard utilities, but without any more success.
(copied from https://gitlab.com/postmarketOS/megapixels/-/issues/72 running version megapixels-1.7.0-r0 on Linux 6.6.3 with pmos)
So I am trying to work out what megapixels is doing with the QR code; My knowledge is extremely limited so please bear with me:
The first appears to check whether the entry is a valid URL, and, if true; adds the line "Found a URL '%s' encoded in a %s." and adds a button "_Open URL". If false; adds the line "Found data encoded in a %s." It then adds two buttons "_Copy" and "_Cancel".
The second appears to handle the response to the dialog. On "YES" attempts to launch the URL and if that fails then prints an error "Could not launch application: %s\n". ON "ACCEPT" copies the data to the clipboard. On "CANCEL" breaks.
I have tried three different QR codes with the following results:
xdg-open 'wifi code'(note the single inverted commas). Enter wl-paste in a terminal, wifi code has been copied and is correctly retrieved from the clipboard. Now try by scanning the QR code with megapixels; correctly shows the wifi code and shows the three buttons Open URL, Copy and Cancel. Select Open URL, prints "Could not launch application: The specified location is not supported"Speculation:
The URL/URI is accepted because G_URI_FLAGS_PARSE_RELAXED allows the semi-colons to pass. Normally a URL should/would not include semi-colons whereas a wifi URI will have them. Possibly the wifi URI is passed without escaping the semi-colons, or quoting the wifi-code?
Could the failure to copy be to do with wayland? Above I used wayland copy/paste to access the clipbooard. I have tried some other clipboard utilities, but without any more success.