diff --git a/main.c b/main.c index 1df550f..a40da04 100644 --- a/main.c +++ b/main.c @@ -31,15 +31,21 @@ typedef struct _builderWidget { GtkWidget **widget; }builderWidget; -typedef struct _flasher { +struct flasher { + gboolean is_active; GtkWidget **progressBar; GtkWidget **fileEntry; GtkWidget **portEntry; -}flasher; +}; static gboolean main_window_close(GtkWidget *widget, gpointer foo) { + struct flasher *flash = (struct flasher *)foo; + if (flash->is_active == TRUE) { + g_print("Flashing operation in progress. Can't close window.\n"); + return TRUE; + } gtk_widget_destroy(widget); gtk_main_quit(); return TRUE; @@ -61,7 +67,9 @@ int main(int argc, char *argv[]) { static GtkWidget *portEntry; static GtkWidget *progressBar; static GtkWidget *fileDialog; - static flasher stmFlasher; + static struct flasher stmFlasher = + { .is_active = FALSE + }; static parameter progParams[] = { { @@ -71,38 +79,38 @@ int main(int argc, char *argv[]) { }, {.name = "--port",.hasValue = hasVal,.value = (void*)port},{.name = "--file",.hasValue = hasVal,.value = (void*)fileName},{.name = NULL}}; static builderWidget builderWidgets[] = { - { - .widgetId = "startButton", - .widget = &startButton - }, - { - .widgetId = "fileDialogButton", - .widget = &fileDialogButton - }, - { - .widgetId = "fileEntry", - .widget = &fileEntry - }, - { - .widgetId = "portEntry", - .widget = &portEntry - }, - { - .widgetId = "progressBar", - .widget = &progressBar - }, - { - .widgetId = "Dialog", - .widget = &fileDialog - }, - { - .widgetId = "mainWindow", - .widget = &main_window - }, - { - .widgetId = NULL, - .widget = NULL - } + { + .widgetId = "startButton", + .widget = &startButton + }, + { + .widgetId = "fileDialogButton", + .widget = &fileDialogButton + }, + { + .widgetId = "fileEntry", + .widget = &fileEntry + }, + { + .widgetId = "portEntry", + .widget = &portEntry + }, + { + .widgetId = "progressBar", + .widget = &progressBar + }, + { + .widgetId = "Dialog", + .widget = &fileDialog + }, + { + .widgetId = "mainWindow", + .widget = &main_window + }, + { + .widgetId = NULL, + .widget = NULL + } }; GtkBuilder *builder; @@ -110,19 +118,23 @@ int main(int argc, char *argv[]) { parseParams(progParams, argc, argv); // Create flasher and fill elements + // TODO: remove widgets from flasher. use strings instead stmFlasher.fileEntry = &fileEntry; stmFlasher.portEntry = &portEntry; // TODO: above - gui = 1; + if (gui) { gtk_init(&argc, &argv); + g_object_set(gtk_settings_get_default(), + "gtk-application-prefer-dark-theme", TRUE, + NULL); builder = gtk_builder_new(); gtk_builder_add_from_file(builder, "window.glade", NULL); //Get Widgets from Builder parseBuilder(builder, builderWidgets); g_signal_connect(startButton, "clicked", G_CALLBACK(startFlash), &stmFlasher); - g_signal_connect(main_window, "delete-event", G_CALLBACK(main_window_close), NULL); + g_signal_connect(main_window, "delete-event", G_CALLBACK(main_window_close), &stmFlasher); gtk_main(); } else { startFlash(&stmFlasher); @@ -134,7 +146,7 @@ int main(int argc, char *argv[]) { -void startFlash(flasher *flashObj) { +void startFlash(struct flasher *flashObj) { printf("Flasher started\n"); return; } diff --git a/window.glade b/window.glade index e3d1497..db418fd 100644 --- a/window.glade +++ b/window.glade @@ -65,6 +65,9 @@ True True True + False @@ -120,6 +123,9 @@ True True True + True