aboutsummaryrefslogtreecommitdiff
path: root/src/application.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/application.c')
-rw-r--r--src/application.c64
1 files changed, 51 insertions, 13 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}