Skip to content

Commit

Permalink
Fix module downloading, g_signal_connect overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Nov 3, 2021
1 parent c8c9f7a commit f1c13e5
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions gtk.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// This is the GTK based app for Windows / Linux
// TODO: decide on function/variable name style
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -55,7 +56,7 @@ int returnMessage(unsigned int code)
logprint("Return Code OK.\n");
return 0;
case 0x201d:
logprint("Return Code INVALID.\n");
logprint("Return Code INVALID_PARAMETER.\n");
return 1;
}

Expand Down Expand Up @@ -233,6 +234,8 @@ static void oneclick(GtkWidget *widget, gpointer data)
}
}

// As per Ant123's findings
// https://www.magiclantern.fm/forum/index.php?topic=26162.msg236146#msg236146
static void activate9052(GtkWidget *widget, gpointer data)
{
logclear();
Expand All @@ -252,8 +255,6 @@ static void activate9052(GtkWidget *widget, gpointer data)
ptp_activate9052(&params);
}

static void removemodule(GtkWidget *widget, gpointer data);

static void downloadmodule(GtkWidget *widget, gpointer data) {
logclear();

Expand All @@ -264,10 +265,7 @@ static void downloadmodule(GtkWidget *widget, gpointer data) {
logprint("Error downloading module.");
} else {
logprint("Module downloaded to card.");
gtk_button_set_label(GTK_BUTTON(widget), "Remove");
g_signal_connect(widget, "clicked", G_CALLBACK(removemodule), NULL);
}

}

static void removemodule(GtkWidget *widget, gpointer data) {
Expand All @@ -277,9 +275,17 @@ static void removemodule(GtkWidget *widget, gpointer data) {

if (!appstore_remove(name)) {
logprint("Module removed.");

}
}

static void modulebtn_callback(GtkWidget *widget, gpointer data) {
const char *name = gtk_button_get_label(GTK_BUTTON(widget));
if (!strcmp(name, "Remove")) {
removemodule(widget, data);
gtk_button_set_label(GTK_BUTTON(widget), "Install");
g_signal_connect(widget, "clicked", G_CALLBACK(downloadmodule), NULL);
} else if (!strcmp(name, "Install")) {
downloadmodule(widget, data);
gtk_button_set_label(GTK_BUTTON(widget), "Remove");
}
}

Expand Down Expand Up @@ -324,13 +330,13 @@ static void appstore(GtkWidget *widget, gpointer data)
FILE *f = fopen(moduleTest, "r");
if (f == NULL) {
button = gtk_button_new_with_label("Install");
g_signal_connect(button, "clicked", G_CALLBACK(downloadmodule), NULL);
} else {
button = gtk_button_new_with_label("Remove");
g_signal_connect(button, "clicked", G_CALLBACK(removemodule), NULL);
fclose(f);
}

g_signal_connect(button, "clicked", G_CALLBACK(modulebtn_callback), NULL);

gtk_widget_set_halign(button, GTK_ALIGN_END);
gtk_grid_attach(GTK_GRID(app), button, 1, 1, 1, 1);
gtk_widget_show(button);
Expand Down

0 comments on commit f1c13e5

Please sign in to comment.