add suggested buttons, remove typedef from struct, implement active flag for flasher
This commit is contained in:
parent
be7879ed45
commit
381c95d18b
88
main.c
88
main.c
@ -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[] = {
|
||||||
{
|
{
|
||||||
@ -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}};
|
{.name = "--port",.hasValue = hasVal,.value = (void*)port},{.name = "--file",.hasValue = hasVal,.value = (void*)fileName},{.name = NULL}};
|
||||||
static builderWidget builderWidgets[] = {
|
static builderWidget builderWidgets[] = {
|
||||||
{
|
{
|
||||||
.widgetId = "startButton",
|
.widgetId = "startButton",
|
||||||
.widget = &startButton
|
.widget = &startButton
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.widgetId = "fileDialogButton",
|
.widgetId = "fileDialogButton",
|
||||||
.widget = &fileDialogButton
|
.widget = &fileDialogButton
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.widgetId = "fileEntry",
|
.widgetId = "fileEntry",
|
||||||
.widget = &fileEntry
|
.widget = &fileEntry
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.widgetId = "portEntry",
|
.widgetId = "portEntry",
|
||||||
.widget = &portEntry
|
.widget = &portEntry
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.widgetId = "progressBar",
|
.widgetId = "progressBar",
|
||||||
.widget = &progressBar
|
.widget = &progressBar
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.widgetId = "Dialog",
|
.widgetId = "Dialog",
|
||||||
.widget = &fileDialog
|
.widget = &fileDialog
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.widgetId = "mainWindow",
|
.widgetId = "mainWindow",
|
||||||
.widget = &main_window
|
.widget = &main_window
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.widgetId = NULL,
|
.widgetId = NULL,
|
||||||
.widget = NULL
|
.widget = NULL
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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>
|
||||||
|
Reference in New Issue
Block a user