blob: c411c061dfb49e5de2530b8aeedeffda6aa40326 [file] [log] [blame]
Stepan Salenikovichd81ef292015-02-17 18:47:37 -05001/*
2 * Copyright (C) 2015 Savoir-Faire Linux Inc.
3 * Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Additional permission under GNU GPL version 3 section 7:
20 *
21 * If you modify this program, or any covered work, by linking or
22 * combining it with the OpenSSL project's OpenSSL library (or a
23 * modified version of that library), containing parts covered by the
24 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
25 * grants you additional permission to convey the resulting work.
26 * Corresponding Source for a non-source form of such a combination
27 * shall include the source code for the parts of OpenSSL used as well
28 * as that of the covered work.
29 */
30
31#include "ring_client.h"
32
33#include <gtk/gtk.h>
34#include <glib/gi18n.h>
Stepan Salenikovichd2dbcee2015-02-27 16:52:28 -050035#include <QtCore/QCoreApplication>
36#include <QtCore/QString>
37#include <QtCore/QByteArray>
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050038#include <callmodel.h>
Stepan Salenikovichd2dbcee2015-02-27 16:52:28 -050039#include <QtCore/QItemSelectionModel>
Stepan Salenikovichc64523b2015-02-27 16:31:00 -050040#include <useractionmodel.h>
Stepan Salenikovich36c025c2015-03-03 19:06:44 -050041#include <clutter-gtk/clutter-gtk.h>
Stepan Salenikovichdd84cf92015-03-19 21:38:19 -040042#include <categorizedhistorymodel.h>
Stepan Salenikovich6f687072015-03-26 10:43:37 -040043#include <personmodel.h>
44#include <fallbackpersoncollection.h>
45#include <QtCore/QStandardPaths>
Stepan Salenikovich1e131a42015-05-27 14:12:21 -040046#include <localhistorycollection.h>
Stepan Salenikovich67112d12015-06-16 16:57:06 -040047#include <media/text.h>
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -040048#include <numbercategorymodel.h>
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050049
50#include "ring_client_options.h"
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050051#include "ringmainwindow.h"
Stepan Salenikovich24dcd5c2015-03-26 17:40:34 -040052#include "dialogs.h"
Stepan Salenikovich6f687072015-03-26 10:43:37 -040053#include "backends/edscontactbackend.h"
54#include "delegates/pixbufdelegate.h"
Stepan Salenikovich76c33e62015-05-22 12:24:07 -040055#include "ringnotify.h"
Stepan Salenikovich76350582015-05-25 14:56:32 -040056#include "config.h"
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -040057#include "utils/files.h"
Stepan Salenikovich4f9bb982015-06-23 14:26:30 -040058#include "revision.h"
Stepan Salenikovich75a39172015-07-10 13:21:08 -040059#include "utils/accounts.h"
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050060
61struct _RingClientClass
62{
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -040063 GtkApplicationClass parent_class;
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050064};
65
66struct _RingClient
67{
68 GtkApplication parent;
69};
70
71typedef struct _RingClientPrivate RingClientPrivate;
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050072
73struct _RingClientPrivate {
Stepan Salenikovich0d515e52015-05-19 16:31:05 -040074 /* args */
75 int argc;
76 char **argv;
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -040077
78 GSettings *settings;
79
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050080 /* main window */
81 GtkWidget *win;
82 /* for libRingclient */
83 QCoreApplication *qtapp;
Stepan Salenikovich068fb692015-03-23 14:58:32 -040084 /* UAM */
85 QMetaObject::Connection uam_updated;
Stepan Salenikovich6f687072015-03-26 10:43:37 -040086
87 GCancellable *cancellable;
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050088};
89
Stepan Salenikovich0d515e52015-05-19 16:31:05 -040090/* this union is used to pass ints as pointers and vice versa for GAction parameters*/
91typedef union _int_ptr_t
92{
93 int value;
94 gint64 value64;
95 gpointer ptr;
96} int_ptr_t;
97
Stepan Salenikovich434b88f2015-02-19 17:49:08 -050098G_DEFINE_TYPE_WITH_PRIVATE(RingClient, ring_client, GTK_TYPE_APPLICATION);
Stepan Salenikovichd81ef292015-02-17 18:47:37 -050099
100#define RING_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), RING_CLIENT_TYPE, RingClientPrivate))
101
102static void
103init_exception_dialog(const char* msg)
104{
105 g_warning("%s", msg);
106 GtkWidget *dialog = gtk_message_dialog_new(NULL,
107 (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
108 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
109 _("Unable to initialize.\nMake sure the Ring daemon (dring) is running.\nError: %s"),
110 msg);
111
112 gtk_window_set_title(GTK_WINDOW(dialog), _("Ring Error"));
113 gtk_dialog_run(GTK_DIALOG(dialog));
114 gtk_widget_destroy(dialog);
115}
116
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400117static void
118ring_accelerators(RingClient *client)
119{
Stepan Salenikovich39ee49a2015-03-24 12:44:55 -0400120#if GTK_CHECK_VERSION(3,12,0)
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400121 const gchar *quit_accels[2] = { "<Ctrl>Q", NULL };
122 gtk_application_set_accels_for_action(GTK_APPLICATION(client), "app.quit", quit_accels);
123#else
124 gtk_application_add_accelerator(GTK_APPLICATION(client), "<Control>Q", "win.quit", NULL);
125#endif
126}
127
128static void
129action_quit(G_GNUC_UNUSED GSimpleAction *simple,
130 G_GNUC_UNUSED GVariant *parameter,
131 gpointer user_data)
132{
133 g_return_if_fail(G_IS_APPLICATION(user_data));
134
135#if GLIB_CHECK_VERSION(2,32,0)
136 g_application_quit(G_APPLICATION(user_data));
137#else
138 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(user_data);
139 gtk_widget_destroy(priv->win);
140#endif
141}
142
Stepan Salenikovich24dcd5c2015-03-26 17:40:34 -0400143static void
144action_about(G_GNUC_UNUSED GSimpleAction *simple,
145 G_GNUC_UNUSED GVariant *parameter,
146 gpointer user_data)
147{
148 g_return_if_fail(G_IS_APPLICATION(user_data));
149 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(user_data);
150
151 ring_about_dialog(priv->win);
152}
153
Stepan Salenikovich69771842015-02-24 18:11:45 -0500154static const GActionEntry ring_actions[] =
155{
Stepan Salenikovich24dcd5c2015-03-26 17:40:34 -0400156 { "accept", NULL, NULL, NULL, NULL, {0} },
157 { "hangup", NULL, NULL, NULL, NULL, {0} },
158 { "hold", NULL, NULL, "false", NULL, {0} },
159 { "quit", action_quit, NULL, NULL, NULL, {0} },
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400160 { "about", action_about, NULL, NULL, NULL, {0} },
Stepan Salenikovich7d75eab2015-06-12 12:11:45 -0400161 { "mute_audio", NULL, NULL, "false", NULL, {0} },
162 { "mute_video", NULL, NULL, "false", NULL, {0} },
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500163 /* TODO implement the other actions */
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500164 // { "transfer", NULL, NULL, "flase", NULL, {0} },
165 // { "record", NULL, NULL, "false", NULL, {0} }
Stepan Salenikovich69771842015-02-24 18:11:45 -0500166};
167
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500168static void
169activate_action(GSimpleAction *action, G_GNUC_UNUSED GVariant *parameter, gpointer user_data)
170{
171 g_debug("activating action: %s", g_action_get_name(G_ACTION(action)));
172
173 int_ptr_t key;
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400174
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500175 key.ptr = user_data;
176 UserActionModel::Action a = static_cast<UserActionModel::Action>(key.value);
177 UserActionModel* uam = CallModel::instance()->userActionModel();
178
179 uam << a;
180}
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500181
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400182static void
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -0400183autostart_toggled(GSettings *settings, G_GNUC_UNUSED gchar *key, G_GNUC_UNUSED gpointer user_data)
184{
185 autostart_symlink(g_settings_get_boolean(settings, "start-on-login"));
186}
187
188static void
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400189ring_client_startup(GApplication *app)
Stepan Salenikovich69771842015-02-24 18:11:45 -0500190{
Stepan Salenikovich69771842015-02-24 18:11:45 -0500191 RingClient *client = RING_CLIENT(app);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400192 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
Stepan Salenikovich69771842015-02-24 18:11:45 -0500193
Stepan Salenikovich4f9bb982015-06-23 14:26:30 -0400194 g_message("Ring GNOME client version: %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH);
195 g_message("git ref: %s", RING_CLIENT_REVISION);
196
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -0400197 /* make sure that the system corresponds to the autostart setting */
198 autostart_symlink(g_settings_get_boolean(priv->settings, "start-on-login"));
199 g_signal_connect(priv->settings, "changed::start-on-login", G_CALLBACK(autostart_toggled), NULL);
200
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400201 /* init clutter */
202 int clutter_error;
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400203 if ((clutter_error = gtk_clutter_init(&priv->argc, &priv->argv)) != CLUTTER_INIT_SUCCESS) {
204 g_error("Could not init clutter : %d\n", clutter_error);
205 exit(1); /* the g_error above should normally cause the applicaiton to exit */
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400206 }
207
208 /* init libRingClient and make sure its connected to the dbus */
209 try {
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400210 priv->qtapp = new QCoreApplication(priv->argc, priv->argv);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400211 /* the call model will try to connect to dring via dbus */
212 CallModel::instance();
213 } catch (const char * msg) {
214 init_exception_dialog(msg);
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400215 g_error("%s", msg);
216 exit(1); /* the g_error above should normally cause the applicaiton to exit */
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400217 } catch(QString& msg) {
218 QByteArray ba = msg.toLocal8Bit();
219 const char *c_str = ba.data();
220 init_exception_dialog(c_str);
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400221 g_error("%s", c_str);
222 exit(1); /* the g_error above should normally cause the applicaiton to exit */
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400223 }
224
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400225 /* init delegates */
226 /* FIXME: put in smart pointer? */
227 new PixbufDelegate();
228
Stepan Salenikovich75a39172015-07-10 13:21:08 -0400229 /* make sure all RING accounts have a display name... this basically makes sure
230 * that all accounts created before the display name patch have a display name
231 * set... a bit of a hack as this should maybe be done in LRC */
232 force_ring_display_name();
233
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -0400234 /* make sure basic number categories exist, in case user has no contacts
235 * from which these would be automatically created
236 */
237 NumberCategoryModel::instance()->addCategory("work", QVariant());
238 NumberCategoryModel::instance()->addCategory("home", QVariant());
239
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400240 /* add backends */
Stepan Salenikovich1e131a42015-05-27 14:12:21 -0400241 CategorizedHistoryModel::instance()->addCollection<LocalHistoryCollection>(LoadOptions::FORCE_ENABLED);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400242
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -0400243 /* fallback backend for vcards */
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400244 PersonModel::instance()->addCollection<FallbackPersonCollection>(LoadOptions::FORCE_ENABLED);
245
Stepan Salenikovichf2d76c52015-07-17 17:54:56 -0400246 /* EDS backend(s) */
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400247 load_eds_sources(priv->cancellable);
248
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400249 /* Override theme since we don't have appropriate icons for a dark them (yet) */
250 GtkSettings *gtk_settings = gtk_settings_get_default();
251 g_object_set(G_OBJECT(gtk_settings), "gtk-application-prefer-dark-theme",
252 FALSE, NULL);
253 /* enable button icons */
254 g_object_set(G_OBJECT(gtk_settings), "gtk-button-images",
255 TRUE, NULL);
256
257 /* add GActions */
Stepan Salenikovich69771842015-02-24 18:11:45 -0500258 g_action_map_add_action_entries(
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400259 G_ACTION_MAP(app), ring_actions, G_N_ELEMENTS(ring_actions), app);
260
261 /* add accelerators */
262 ring_accelerators(RING_CLIENT(app));
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500263
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400264 /* Bind GActions to the UserActionModel */
265 UserActionModel* uam = CallModel::instance()->userActionModel();
266 QHash<int, GSimpleAction*> actionHash;
267 actionHash[ (int)UserActionModel::Action::ACCEPT ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "accept"));
268 actionHash[ (int)UserActionModel::Action::HOLD ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "hold"));
Stepan Salenikovich7d75eab2015-06-12 12:11:45 -0400269 actionHash[ (int)UserActionModel::Action::MUTE_AUDIO ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "mute_audio"));
270 actionHash[ (int)UserActionModel::Action::MUTE_VIDEO ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "mute_video"));
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400271 /* TODO: add commented actions when ready */
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400272 // actionHash[ (int)UserActionModel::Action::SERVER_TRANSFER ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "transfer"));
273 // actionHash[ (int)UserActionModel::Action::RECORD ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "record"));
274 actionHash[ (int)UserActionModel::Action::HANGUP ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "hangup"));
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500275
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400276 for (QHash<int,GSimpleAction*>::const_iterator i = actionHash.begin(); i != actionHash.end(); ++i) {
277 GSimpleAction* sa = i.value();
278 int_ptr_t user_data;
279 user_data.value = i.key();
280 g_signal_connect(G_OBJECT(sa), "activate", G_CALLBACK(activate_action), user_data.ptr);
281 }
Stepan Salenikovichc64523b2015-02-27 16:31:00 -0500282
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400283 /* change the state of the GActions based on the UserActionModel */
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400284 priv->uam_updated = QObject::connect(uam,&UserActionModel::dataChanged, [actionHash,uam](const QModelIndex& tl, const QModelIndex& br) {
Stepan Salenikovich347b73a2015-03-22 10:39:00 -0400285 const int first(tl.row()),last(br.row());
286 for(int i = first; i <= last;i++) {
287 const QModelIndex& idx = uam->index(i,0);
288 GSimpleAction* sa = actionHash[(int)qvariant_cast<UserActionModel::Action>(idx.data(UserActionModel::Role::ACTION))];
289 if (sa) {
290 /* enable/disable GAction based on UserActionModel */
291 g_simple_action_set_enabled(sa, idx.flags() & Qt::ItemIsEnabled);
292 /* set the state of the action if its stateful */
293 if (g_action_get_state_type(G_ACTION(sa)) != NULL)
294 g_simple_action_set_state(sa, g_variant_new_boolean(idx.data(Qt::CheckStateRole) == Qt::Checked));
295 }
296 }
297 });
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400298
Stepan Salenikovich76c33e62015-05-22 12:24:07 -0400299 /* send call notifications */
300 ring_notify_init();
301 QObject::connect(CallModel::instance(), &CallModel::incomingCall,
Stepan Salenikovich67112d12015-06-16 16:57:06 -0400302 [] (Call *call) { ring_notify_incoming_call(call);}
Stepan Salenikovich76c33e62015-05-22 12:24:07 -0400303 );
304
Stepan Salenikovich67112d12015-06-16 16:57:06 -0400305 /* chat notifications for incoming messages on all calls which are not the
306 * currently selected call */
307 ring_notify_monitor_chat_notifications(client);
308
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400309#if GLIB_CHECK_VERSION(2,40,0)
310 G_APPLICATION_CLASS(ring_client_parent_class)->startup(app);
311#else
312 /* don't need to chain up to the parent callback as this function will
313 * be called manually by the command_line callback in this case */
314#endif
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400315}
316
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400317#if !GLIB_CHECK_VERSION(2,40,0)
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400318static int
319ring_client_command_line(GApplication *app, GApplicationCommandLine *cmdline)
320{
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400321 gint argc;
322 gchar **argv = g_application_command_line_get_arguments(cmdline, &argc);
323 GOptionContext *context = ring_client_options_get_context();
324 GError *error = NULL;
325 if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
326 g_print(_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
327 error->message, argv[0]);
Stepan Salenikovich8a287fc2015-05-01 16:53:20 -0400328 g_clear_error(&error);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400329 g_option_context_free(context);
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400330 g_strfreev(argv);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400331 return 1;
332 }
333 g_option_context_free(context);
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400334 g_strfreev(argv);
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400335
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400336 if (!g_application_get_is_remote(app)) {
337 /* if this is the primary instance, we must peform the startup */
338 ring_client_startup(app);
339 }
340
341 g_application_activate(app);
342
343 return 0;
344}
345#endif
346
347static void
348ring_client_activate(GApplication *app)
349{
350 RingClient *client = RING_CLIENT(app);
351 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
352
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400353 if (priv->win == NULL) {
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400354 priv->win = ring_main_window_new(GTK_APPLICATION(app));
355 }
356
357 gtk_window_present(GTK_WINDOW(priv->win));
Stepan Salenikovich69771842015-02-24 18:11:45 -0500358}
359
360static void
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500361ring_client_shutdown(GApplication *app)
362{
363 RingClient *self = RING_CLIENT(app);
364 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(self);
365
Stepan Salenikovich2d63d5e2015-03-22 23:23:54 -0400366 g_debug("quitting");
367
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400368 /* cancel any pending cancellable operations */
369 g_cancellable_cancel(priv->cancellable);
370 g_object_unref(priv->cancellable);
371
Stepan Salenikovich068fb692015-03-23 14:58:32 -0400372 QObject::disconnect(priv->uam_updated);
373
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500374 /* free the QCoreApplication, which will destroy all libRingClient models
375 * and thus send the Unregister signal over dbus to dring */
376 delete priv->qtapp;
377
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400378 /* free the copied cmd line args */
379 g_strfreev(priv->argv);
380
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -0400381 g_clear_object(&priv->settings);
382
Stepan Salenikovich76c33e62015-05-22 12:24:07 -0400383 ring_notify_uninit();
384
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500385 /* Chain up to the parent class */
386 G_APPLICATION_CLASS(ring_client_parent_class)->shutdown(app);
387}
388
389static void
390ring_client_init(RingClient *self)
391{
392 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(self);
393
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500394 priv->win = NULL;
395 priv->qtapp = NULL;
Stepan Salenikovich6f687072015-03-26 10:43:37 -0400396 priv->cancellable = g_cancellable_new();
Stepan Salenikovichfb7f2952015-05-25 16:44:19 -0400397 priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400398
399#if GLIB_CHECK_VERSION(2,40,0)
400 /* add custom cmd line options */
401 ring_client_add_options(G_APPLICATION(self));
402#endif
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500403}
404
405static void
406ring_client_class_init(RingClientClass *klass)
407{
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400408#if GLIB_CHECK_VERSION(2,40,0)
409 G_APPLICATION_CLASS(klass)->startup = ring_client_startup;
410#else
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500411 G_APPLICATION_CLASS(klass)->command_line = ring_client_command_line;
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400412#endif
413 G_APPLICATION_CLASS(klass)->activate = ring_client_activate;
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500414 G_APPLICATION_CLASS(klass)->shutdown = ring_client_shutdown;
415}
416
417RingClient *
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400418ring_client_new(int argc, char *argv[])
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500419{
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400420 /* because the g_application_add_main_option_entries was only added in
421 * glib 2.40, for lower versions we must handle the command line options
422 * ourselves
423 */
424 RingClient *client = (RingClient *)g_object_new(ring_client_get_type(),
Stepan Salenikovich76350582015-05-25 14:56:32 -0400425 "application-id", RING_CLIENT_APP_ID,
Stepan Salenikovich0d515e52015-05-19 16:31:05 -0400426#if GLIB_CHECK_VERSION(2,40,0)
427 NULL);
428#else
429 "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
430 NULL);
431#endif
432
433 /* copy the cmd line args before they get processed by the GApplication*/
434 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
435 priv->argc = argc;
436 priv->argv = g_strdupv((gchar **)argv);
437
438 return client;
Stepan Salenikovichd81ef292015-02-17 18:47:37 -0500439}
Stepan Salenikovich67112d12015-06-16 16:57:06 -0400440
441GtkWindow *
442ring_client_get_main_windw(RingClient *client)
443{
444 g_return_val_if_fail(IS_RING_CLIENT(client), NULL);
445 RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client);
446
447 return (GtkWindow *)priv->win;
448}