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

88
main.c
View File

@ -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;
}

View File

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