add suggested buttons, remove typedef from struct, implement active flag for flasher

This commit is contained in:
Mario Hüttel 2017-08-14 23:48:45 +02:00
parent be7879ed45
commit 381c95d18b
2 changed files with 56 additions and 38 deletions

24
main.c
View File

@ -31,15 +31,21 @@ typedef struct _builderWidget {
GtkWidget **widget; GtkWidget **widget;
}builderWidget; }builderWidget;
typedef struct _flasher { struct flasher {
gboolean is_active;
GtkWidget **progressBar; GtkWidget **progressBar;
GtkWidget **fileEntry; GtkWidget **fileEntry;
GtkWidget **portEntry; GtkWidget **portEntry;
}flasher; };
static gboolean main_window_close(GtkWidget *widget, gpointer foo) 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_widget_destroy(widget);
gtk_main_quit(); gtk_main_quit();
return TRUE; return TRUE;
@ -61,7 +67,9 @@ int main(int argc, char *argv[]) {
static GtkWidget *portEntry; static GtkWidget *portEntry;
static GtkWidget *progressBar; static GtkWidget *progressBar;
static GtkWidget *fileDialog; static GtkWidget *fileDialog;
static flasher stmFlasher; static struct flasher stmFlasher =
{ .is_active = FALSE
};
static parameter progParams[] = { static parameter progParams[] = {
{ {
@ -110,19 +118,23 @@ int main(int argc, char *argv[]) {
parseParams(progParams, argc, argv); parseParams(progParams, argc, argv);
// Create flasher and fill elements // Create flasher and fill elements
// TODO: remove widgets from flasher. use strings instead
stmFlasher.fileEntry = &fileEntry; stmFlasher.fileEntry = &fileEntry;
stmFlasher.portEntry = &portEntry; stmFlasher.portEntry = &portEntry;
// TODO: above // TODO: above
gui = 1;
if (gui) { if (gui) {
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
g_object_set(gtk_settings_get_default(),
"gtk-application-prefer-dark-theme", TRUE,
NULL);
builder = gtk_builder_new(); builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "window.glade", NULL); gtk_builder_add_from_file(builder, "window.glade", NULL);
//Get Widgets from Builder //Get Widgets from Builder
parseBuilder(builder, builderWidgets); parseBuilder(builder, builderWidgets);
g_signal_connect(startButton, "clicked", G_CALLBACK(startFlash), &stmFlasher); 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(); gtk_main();
} else { } else {
startFlash(&stmFlasher); 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"); printf("Flasher started\n");
return; return;
} }

View File

@ -65,6 +65,9 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<style>
<class name="suggested-action"/>
</style>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -120,6 +123,9 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<style>
<class name="suggested-action"/>
</style>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>