diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-10-31 03:11:09 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-10-31 03:11:09 +0100 |
commit | ba367143729e60b799232a80b2747bc388078014 (patch) | |
tree | e96017d4274c70c9d6be298f1bcefd327221f8c2 | |
parent | 847faf46a60160a8ffdce3d3ca0bcdef0f55c886 (diff) |
Fixed mobile flag option properly
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/application.c | 64 | ||||
-rw-r--r-- | src/application.h | 5 | ||||
-rw-r--r-- | src/messenger_gtk.c | 2 | ||||
-rw-r--r-- | src/ui/chat_entry.c | 1 | ||||
-rw-r--r-- | src/ui/messenger.c | 13 | ||||
-rw-r--r-- | src/ui/messenger.h | 3 |
6 files changed, 72 insertions, 16 deletions
diff --git a/src/application.c b/src/application.c index 529ba55..4c69951 100644 --- a/src/application.c +++ b/src/application.c @@ -42,6 +42,15 @@ _load_ui_stylesheets(void) ); } +static void +_application_activate(UNUSED GtkApplication* application, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + ui_messenger_run(app); +} + void application_init(MESSENGER_Application *app, int argc, @@ -52,6 +61,13 @@ application_init(MESSENGER_Application *app, gtk_init(&argc, &argv); + app->application = gtk_application_new( + "org.gnunet.MESSENGER-GTK", + G_APPLICATION_NON_UNIQUE + ); + + notify_init("Messenger-GTK"); + _load_ui_stylesheets(); app->chat.status = EXIT_FAILURE; @@ -60,15 +76,22 @@ application_init(MESSENGER_Application *app, app->ui.mobile = FALSE; - for (int i = 0; i < app->argc; i++) { - if (0 == strcmp("--mobile", app->argv[i])) - { - app->ui.mobile = TRUE; - break; - } - } + g_application_add_main_option( + G_APPLICATION(app->application), + "mobile", + 'm', + G_OPTION_FLAG_NONE, + G_OPTION_ARG_NONE, + "Optimize UI spacing for mobile devices", + NULL + ); - ui_messenger_init(app, &(app->ui.messenger)); + g_signal_connect( + app->application, + "activate", + G_CALLBACK(_application_activate), + app + ); } static void* @@ -77,6 +100,12 @@ _application_chat_thread(void *args) MESSENGER_Application *app = (MESSENGER_Application*) args; struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_flag ( + 'm', + "mobile", + "Optimize UI spacing for mobile devices", + &(app->ui.mobile) + ), GNUNET_GETOPT_OPTION_END }; @@ -94,13 +123,21 @@ _application_chat_thread(void *args) } void -application_start(MESSENGER_Application *app) +application_run(MESSENGER_Application *app) { pthread_create(&(app->chat.tid), NULL, _application_chat_thread, app); - gtk_main(); + app->ui.status = g_application_run( + G_APPLICATION(app->application), + app->argc, + app->argv + ); pthread_join(app->chat.tid, NULL); + + notify_uninit(); + + g_object_unref(app->application); } typedef struct MESSENGER_ApplicationEventCall @@ -142,12 +179,13 @@ application_exit(MESSENGER_Application *app, MESSENGER_ApplicationSignal signal) { app->chat.signal = signal; - - gtk_main_quit(); } int application_status(MESSENGER_Application *app) { - return app->chat.status; + if (EXIT_SUCCESS != app->chat.status) + return app->chat.status; + + return app->ui.status; } diff --git a/src/application.h b/src/application.h index 1c3d638..5801f6d 100644 --- a/src/application.h +++ b/src/application.h @@ -45,6 +45,8 @@ typedef struct MESSENGER_Application char** argv; int argc; + GtkApplication* application; + struct { int status; pthread_t tid; @@ -55,6 +57,7 @@ typedef struct MESSENGER_Application } chat; struct { + int status; gboolean mobile; UI_MESSENGER_Handle messenger; @@ -67,7 +70,7 @@ application_init(MESSENGER_Application *app, char **argv); void -application_start(MESSENGER_Application *app); +application_run(MESSENGER_Application *app); typedef void (*MESSENGER_ApplicationEvent) (MESSENGER_Application *app); diff --git a/src/messenger_gtk.c b/src/messenger_gtk.c index dc2c87a..f1c414c 100644 --- a/src/messenger_gtk.c +++ b/src/messenger_gtk.c @@ -28,7 +28,7 @@ int main(int argc, char **argv) { MESSENGER_Application app; application_init(&app, argc, argv); - application_start(&app); + application_run(&app); return application_status(&app); } diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c index 5ff7063..cdf7c6b 100644 --- a/src/ui/chat_entry.c +++ b/src/ui/chat_entry.c @@ -51,5 +51,6 @@ ui_chat_entry_new(void) gtk_builder_get_object(builder, "text") ); + g_object_unref(builder); return handle; } diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 46ee362..a101eba 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c @@ -98,6 +98,11 @@ ui_messenger_init(MESSENGER_Application *app, gtk_builder_get_object(builder, "main_window") ); + gtk_application_add_window( + app->application, + GTK_WINDOW(handle->main_window) + ); + handle->profile_avatar = HDY_AVATAR( gtk_builder_get_object(builder, "profile_avatar") ); @@ -249,4 +254,12 @@ ui_messenger_init(MESSENGER_Application *app, G_CALLBACK(handle_main_window_destroy), app ); + + g_object_unref(builder); +} + +void +ui_messenger_run(MESSENGER_Application *app) +{ + ui_messenger_init(app, &(app->ui.messenger)); } diff --git a/src/ui/messenger.h b/src/ui/messenger.h index ed37ad3..efb5122 100644 --- a/src/ui/messenger.h +++ b/src/ui/messenger.h @@ -27,6 +27,7 @@ #include <gtk-3.0/gtk/gtk.h> #include <libhandy-1/handy.h> +#include <libnotify/notify.h> typedef struct MESSENGER_Application MESSENGER_Application; @@ -74,6 +75,6 @@ ui_messenger_init(MESSENGER_Application *app, UI_MESSENGER_Handle *handle); void -ui_messenger_update_profile(MESSENGER_Application *app); +ui_messenger_run(MESSENGER_Application *app); #endif /* UI_MESSENGER_H_ */ |