aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-10-31 03:11:09 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-10-31 03:11:09 +0100
commitba367143729e60b799232a80b2747bc388078014 (patch)
treee96017d4274c70c9d6be298f1bcefd327221f8c2
parent847faf46a60160a8ffdce3d3ca0bcdef0f55c886 (diff)
downloadmessenger-gtk-ba367143729e60b799232a80b2747bc388078014.tar.gz
messenger-gtk-ba367143729e60b799232a80b2747bc388078014.zip
Fixed mobile flag option properly
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/application.c64
-rw-r--r--src/application.h5
-rw-r--r--src/messenger_gtk.c2
-rw-r--r--src/ui/chat_entry.c1
-rw-r--r--src/ui/messenger.c13
-rw-r--r--src/ui/messenger.h3
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)
42 ); 42 );
43} 43}
44 44
45static void
46_application_activate(UNUSED GtkApplication* application,
47 gpointer user_data)
48{
49 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
50
51 ui_messenger_run(app);
52}
53
45void 54void
46application_init(MESSENGER_Application *app, 55application_init(MESSENGER_Application *app,
47 int argc, 56 int argc,
@@ -52,6 +61,13 @@ application_init(MESSENGER_Application *app,
52 61
53 gtk_init(&argc, &argv); 62 gtk_init(&argc, &argv);
54 63
64 app->application = gtk_application_new(
65 "org.gnunet.MESSENGER-GTK",
66 G_APPLICATION_NON_UNIQUE
67 );
68
69 notify_init("Messenger-GTK");
70
55 _load_ui_stylesheets(); 71 _load_ui_stylesheets();
56 72
57 app->chat.status = EXIT_FAILURE; 73 app->chat.status = EXIT_FAILURE;
@@ -60,15 +76,22 @@ application_init(MESSENGER_Application *app,
60 76
61 app->ui.mobile = FALSE; 77 app->ui.mobile = FALSE;
62 78
63 for (int i = 0; i < app->argc; i++) { 79 g_application_add_main_option(
64 if (0 == strcmp("--mobile", app->argv[i])) 80 G_APPLICATION(app->application),
65 { 81 "mobile",
66 app->ui.mobile = TRUE; 82 'm',
67 break; 83 G_OPTION_FLAG_NONE,
68 } 84 G_OPTION_ARG_NONE,
69 } 85 "Optimize UI spacing for mobile devices",
86 NULL
87 );
70 88
71 ui_messenger_init(app, &(app->ui.messenger)); 89 g_signal_connect(
90 app->application,
91 "activate",
92 G_CALLBACK(_application_activate),
93 app
94 );
72} 95}
73 96
74static void* 97static void*
@@ -77,6 +100,12 @@ _application_chat_thread(void *args)
77 MESSENGER_Application *app = (MESSENGER_Application*) args; 100 MESSENGER_Application *app = (MESSENGER_Application*) args;
78 101
79 struct GNUNET_GETOPT_CommandLineOption options[] = { 102 struct GNUNET_GETOPT_CommandLineOption options[] = {
103 GNUNET_GETOPT_option_flag (
104 'm',
105 "mobile",
106 "Optimize UI spacing for mobile devices",
107 &(app->ui.mobile)
108 ),
80 GNUNET_GETOPT_OPTION_END 109 GNUNET_GETOPT_OPTION_END
81 }; 110 };
82 111
@@ -94,13 +123,21 @@ _application_chat_thread(void *args)
94} 123}
95 124
96void 125void
97application_start(MESSENGER_Application *app) 126application_run(MESSENGER_Application *app)
98{ 127{
99 pthread_create(&(app->chat.tid), NULL, _application_chat_thread, app); 128 pthread_create(&(app->chat.tid), NULL, _application_chat_thread, app);
100 129
101 gtk_main(); 130 app->ui.status = g_application_run(
131 G_APPLICATION(app->application),
132 app->argc,
133 app->argv
134 );
102 135
103 pthread_join(app->chat.tid, NULL); 136 pthread_join(app->chat.tid, NULL);
137
138 notify_uninit();
139
140 g_object_unref(app->application);
104} 141}
105 142
106typedef struct MESSENGER_ApplicationEventCall 143typedef struct MESSENGER_ApplicationEventCall
@@ -142,12 +179,13 @@ application_exit(MESSENGER_Application *app,
142 MESSENGER_ApplicationSignal signal) 179 MESSENGER_ApplicationSignal signal)
143{ 180{
144 app->chat.signal = signal; 181 app->chat.signal = signal;
145
146 gtk_main_quit();
147} 182}
148 183
149int 184int
150application_status(MESSENGER_Application *app) 185application_status(MESSENGER_Application *app)
151{ 186{
152 return app->chat.status; 187 if (EXIT_SUCCESS != app->chat.status)
188 return app->chat.status;
189
190 return app->ui.status;
153} 191}
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
45 char** argv; 45 char** argv;
46 int argc; 46 int argc;
47 47
48 GtkApplication* application;
49
48 struct { 50 struct {
49 int status; 51 int status;
50 pthread_t tid; 52 pthread_t tid;
@@ -55,6 +57,7 @@ typedef struct MESSENGER_Application
55 } chat; 57 } chat;
56 58
57 struct { 59 struct {
60 int status;
58 gboolean mobile; 61 gboolean mobile;
59 62
60 UI_MESSENGER_Handle messenger; 63 UI_MESSENGER_Handle messenger;
@@ -67,7 +70,7 @@ application_init(MESSENGER_Application *app,
67 char **argv); 70 char **argv);
68 71
69void 72void
70application_start(MESSENGER_Application *app); 73application_run(MESSENGER_Application *app);
71 74
72typedef void (*MESSENGER_ApplicationEvent) (MESSENGER_Application *app); 75typedef void (*MESSENGER_ApplicationEvent) (MESSENGER_Application *app);
73 76
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) {
28 MESSENGER_Application app; 28 MESSENGER_Application app;
29 29
30 application_init(&app, argc, argv); 30 application_init(&app, argc, argv);
31 application_start(&app); 31 application_run(&app);
32 32
33 return application_status(&app); 33 return application_status(&app);
34} 34}
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)
51 gtk_builder_get_object(builder, "text") 51 gtk_builder_get_object(builder, "text")
52 ); 52 );
53 53
54 g_object_unref(builder);
54 return handle; 55 return handle;
55} 56}
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,
98 gtk_builder_get_object(builder, "main_window") 98 gtk_builder_get_object(builder, "main_window")
99 ); 99 );
100 100
101 gtk_application_add_window(
102 app->application,
103 GTK_WINDOW(handle->main_window)
104 );
105
101 handle->profile_avatar = HDY_AVATAR( 106 handle->profile_avatar = HDY_AVATAR(
102 gtk_builder_get_object(builder, "profile_avatar") 107 gtk_builder_get_object(builder, "profile_avatar")
103 ); 108 );
@@ -249,4 +254,12 @@ ui_messenger_init(MESSENGER_Application *app,
249 G_CALLBACK(handle_main_window_destroy), 254 G_CALLBACK(handle_main_window_destroy),
250 app 255 app
251 ); 256 );
257
258 g_object_unref(builder);
259}
260
261void
262ui_messenger_run(MESSENGER_Application *app)
263{
264 ui_messenger_init(app, &(app->ui.messenger));
252} 265}
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 @@
27 27
28#include <gtk-3.0/gtk/gtk.h> 28#include <gtk-3.0/gtk/gtk.h>
29#include <libhandy-1/handy.h> 29#include <libhandy-1/handy.h>
30#include <libnotify/notify.h>
30 31
31typedef struct MESSENGER_Application MESSENGER_Application; 32typedef struct MESSENGER_Application MESSENGER_Application;
32 33
@@ -74,6 +75,6 @@ ui_messenger_init(MESSENGER_Application *app,
74 UI_MESSENGER_Handle *handle); 75 UI_MESSENGER_Handle *handle);
75 76
76void 77void
77ui_messenger_update_profile(MESSENGER_Application *app); 78ui_messenger_run(MESSENGER_Application *app);
78 79
79#endif /* UI_MESSENGER_H_ */ 80#endif /* UI_MESSENGER_H_ */