Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 1 | /* |
| 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 Salenikovich | d2dbcee | 2015-02-27 16:52:28 -0500 | [diff] [blame] | 35 | #include <QtCore/QCoreApplication> |
| 36 | #include <QtCore/QString> |
| 37 | #include <QtCore/QByteArray> |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 38 | #include <callmodel.h> |
Stepan Salenikovich | d2dbcee | 2015-02-27 16:52:28 -0500 | [diff] [blame] | 39 | #include <QtCore/QItemSelectionModel> |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 40 | #include <useractionmodel.h> |
Stepan Salenikovich | 36c025c | 2015-03-03 19:06:44 -0500 | [diff] [blame] | 41 | #include <clutter-gtk/clutter-gtk.h> |
Stepan Salenikovich | dd84cf9 | 2015-03-19 21:38:19 -0400 | [diff] [blame] | 42 | #include <categorizedhistorymodel.h> |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 43 | #include <personmodel.h> |
| 44 | #include <fallbackpersoncollection.h> |
| 45 | #include <QtCore/QStandardPaths> |
Stepan Salenikovich | 1e131a4 | 2015-05-27 14:12:21 -0400 | [diff] [blame] | 46 | #include <localhistorycollection.h> |
Stepan Salenikovich | 67112d1 | 2015-06-16 16:57:06 -0400 | [diff] [blame] | 47 | #include <media/text.h> |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame^] | 48 | #include <numbercategorymodel.h> |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 49 | |
| 50 | #include "ring_client_options.h" |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 51 | #include "ringmainwindow.h" |
Stepan Salenikovich | 24dcd5c | 2015-03-26 17:40:34 -0400 | [diff] [blame] | 52 | #include "dialogs.h" |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 53 | #include "backends/edscontactbackend.h" |
| 54 | #include "delegates/pixbufdelegate.h" |
Stepan Salenikovich | 76c33e6 | 2015-05-22 12:24:07 -0400 | [diff] [blame] | 55 | #include "ringnotify.h" |
Stepan Salenikovich | 7635058 | 2015-05-25 14:56:32 -0400 | [diff] [blame] | 56 | #include "config.h" |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 57 | #include "utils/files.h" |
Stepan Salenikovich | 4f9bb98 | 2015-06-23 14:26:30 -0400 | [diff] [blame] | 58 | #include "revision.h" |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 59 | |
| 60 | struct _RingClientClass |
| 61 | { |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 62 | GtkApplicationClass parent_class; |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | struct _RingClient |
| 66 | { |
| 67 | GtkApplication parent; |
| 68 | }; |
| 69 | |
| 70 | typedef struct _RingClientPrivate RingClientPrivate; |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 71 | |
| 72 | struct _RingClientPrivate { |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 73 | /* args */ |
| 74 | int argc; |
| 75 | char **argv; |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 76 | |
| 77 | GSettings *settings; |
| 78 | |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 79 | /* main window */ |
| 80 | GtkWidget *win; |
| 81 | /* for libRingclient */ |
| 82 | QCoreApplication *qtapp; |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 83 | /* UAM */ |
| 84 | QMetaObject::Connection uam_updated; |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 85 | |
| 86 | GCancellable *cancellable; |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 87 | }; |
| 88 | |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 89 | /* this union is used to pass ints as pointers and vice versa for GAction parameters*/ |
| 90 | typedef union _int_ptr_t |
| 91 | { |
| 92 | int value; |
| 93 | gint64 value64; |
| 94 | gpointer ptr; |
| 95 | } int_ptr_t; |
| 96 | |
Stepan Salenikovich | 434b88f | 2015-02-19 17:49:08 -0500 | [diff] [blame] | 97 | G_DEFINE_TYPE_WITH_PRIVATE(RingClient, ring_client, GTK_TYPE_APPLICATION); |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 98 | |
| 99 | #define RING_CLIENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), RING_CLIENT_TYPE, RingClientPrivate)) |
| 100 | |
| 101 | static void |
| 102 | init_exception_dialog(const char* msg) |
| 103 | { |
| 104 | g_warning("%s", msg); |
| 105 | GtkWidget *dialog = gtk_message_dialog_new(NULL, |
| 106 | (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), |
| 107 | GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, |
| 108 | _("Unable to initialize.\nMake sure the Ring daemon (dring) is running.\nError: %s"), |
| 109 | msg); |
| 110 | |
| 111 | gtk_window_set_title(GTK_WINDOW(dialog), _("Ring Error")); |
| 112 | gtk_dialog_run(GTK_DIALOG(dialog)); |
| 113 | gtk_widget_destroy(dialog); |
| 114 | } |
| 115 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 116 | static void |
| 117 | ring_accelerators(RingClient *client) |
| 118 | { |
Stepan Salenikovich | 39ee49a | 2015-03-24 12:44:55 -0400 | [diff] [blame] | 119 | #if GTK_CHECK_VERSION(3,12,0) |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 120 | const gchar *quit_accels[2] = { "<Ctrl>Q", NULL }; |
| 121 | gtk_application_set_accels_for_action(GTK_APPLICATION(client), "app.quit", quit_accels); |
| 122 | #else |
| 123 | gtk_application_add_accelerator(GTK_APPLICATION(client), "<Control>Q", "win.quit", NULL); |
| 124 | #endif |
| 125 | } |
| 126 | |
| 127 | static void |
| 128 | action_quit(G_GNUC_UNUSED GSimpleAction *simple, |
| 129 | G_GNUC_UNUSED GVariant *parameter, |
| 130 | gpointer user_data) |
| 131 | { |
| 132 | g_return_if_fail(G_IS_APPLICATION(user_data)); |
| 133 | |
| 134 | #if GLIB_CHECK_VERSION(2,32,0) |
| 135 | g_application_quit(G_APPLICATION(user_data)); |
| 136 | #else |
| 137 | RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(user_data); |
| 138 | gtk_widget_destroy(priv->win); |
| 139 | #endif |
| 140 | } |
| 141 | |
Stepan Salenikovich | 24dcd5c | 2015-03-26 17:40:34 -0400 | [diff] [blame] | 142 | static void |
| 143 | action_about(G_GNUC_UNUSED GSimpleAction *simple, |
| 144 | G_GNUC_UNUSED GVariant *parameter, |
| 145 | gpointer user_data) |
| 146 | { |
| 147 | g_return_if_fail(G_IS_APPLICATION(user_data)); |
| 148 | RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(user_data); |
| 149 | |
| 150 | ring_about_dialog(priv->win); |
| 151 | } |
| 152 | |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 153 | static const GActionEntry ring_actions[] = |
| 154 | { |
Stepan Salenikovich | 24dcd5c | 2015-03-26 17:40:34 -0400 | [diff] [blame] | 155 | { "accept", NULL, NULL, NULL, NULL, {0} }, |
| 156 | { "hangup", NULL, NULL, NULL, NULL, {0} }, |
| 157 | { "hold", NULL, NULL, "false", NULL, {0} }, |
| 158 | { "quit", action_quit, NULL, NULL, NULL, {0} }, |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 159 | { "about", action_about, NULL, NULL, NULL, {0} }, |
Stepan Salenikovich | 7d75eab | 2015-06-12 12:11:45 -0400 | [diff] [blame] | 160 | { "mute_audio", NULL, NULL, "false", NULL, {0} }, |
| 161 | { "mute_video", NULL, NULL, "false", NULL, {0} }, |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 162 | /* TODO implement the other actions */ |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 163 | // { "transfer", NULL, NULL, "flase", NULL, {0} }, |
| 164 | // { "record", NULL, NULL, "false", NULL, {0} } |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 165 | }; |
| 166 | |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 167 | static void |
| 168 | activate_action(GSimpleAction *action, G_GNUC_UNUSED GVariant *parameter, gpointer user_data) |
| 169 | { |
| 170 | g_debug("activating action: %s", g_action_get_name(G_ACTION(action))); |
| 171 | |
| 172 | int_ptr_t key; |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 173 | |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 174 | key.ptr = user_data; |
| 175 | UserActionModel::Action a = static_cast<UserActionModel::Action>(key.value); |
| 176 | UserActionModel* uam = CallModel::instance()->userActionModel(); |
| 177 | |
| 178 | uam << a; |
| 179 | } |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 180 | |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 181 | static void |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 182 | autostart_toggled(GSettings *settings, G_GNUC_UNUSED gchar *key, G_GNUC_UNUSED gpointer user_data) |
| 183 | { |
| 184 | autostart_symlink(g_settings_get_boolean(settings, "start-on-login")); |
| 185 | } |
| 186 | |
| 187 | static void |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 188 | ring_client_startup(GApplication *app) |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 189 | { |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 190 | RingClient *client = RING_CLIENT(app); |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 191 | RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 192 | |
Stepan Salenikovich | 4f9bb98 | 2015-06-23 14:26:30 -0400 | [diff] [blame] | 193 | g_message("Ring GNOME client version: %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); |
| 194 | g_message("git ref: %s", RING_CLIENT_REVISION); |
| 195 | |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 196 | /* make sure that the system corresponds to the autostart setting */ |
| 197 | autostart_symlink(g_settings_get_boolean(priv->settings, "start-on-login")); |
| 198 | g_signal_connect(priv->settings, "changed::start-on-login", G_CALLBACK(autostart_toggled), NULL); |
| 199 | |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 200 | /* init clutter */ |
| 201 | int clutter_error; |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 202 | if ((clutter_error = gtk_clutter_init(&priv->argc, &priv->argv)) != CLUTTER_INIT_SUCCESS) { |
| 203 | g_error("Could not init clutter : %d\n", clutter_error); |
| 204 | exit(1); /* the g_error above should normally cause the applicaiton to exit */ |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /* init libRingClient and make sure its connected to the dbus */ |
| 208 | try { |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 209 | priv->qtapp = new QCoreApplication(priv->argc, priv->argv); |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 210 | /* the call model will try to connect to dring via dbus */ |
| 211 | CallModel::instance(); |
| 212 | } catch (const char * msg) { |
| 213 | init_exception_dialog(msg); |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 214 | g_error("%s", msg); |
| 215 | exit(1); /* the g_error above should normally cause the applicaiton to exit */ |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 216 | } catch(QString& msg) { |
| 217 | QByteArray ba = msg.toLocal8Bit(); |
| 218 | const char *c_str = ba.data(); |
| 219 | init_exception_dialog(c_str); |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 220 | g_error("%s", c_str); |
| 221 | exit(1); /* the g_error above should normally cause the applicaiton to exit */ |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 222 | } |
| 223 | |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 224 | /* init delegates */ |
| 225 | /* FIXME: put in smart pointer? */ |
| 226 | new PixbufDelegate(); |
| 227 | |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame^] | 228 | /* make sure basic number categories exist, in case user has no contacts |
| 229 | * from which these would be automatically created |
| 230 | */ |
| 231 | NumberCategoryModel::instance()->addCategory("work", QVariant()); |
| 232 | NumberCategoryModel::instance()->addCategory("home", QVariant()); |
| 233 | |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 234 | /* add backends */ |
Stepan Salenikovich | 1e131a4 | 2015-05-27 14:12:21 -0400 | [diff] [blame] | 235 | CategorizedHistoryModel::instance()->addCollection<LocalHistoryCollection>(LoadOptions::FORCE_ENABLED); |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 236 | |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame^] | 237 | /* fallback backend for vcards */ |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 238 | PersonModel::instance()->addCollection<FallbackPersonCollection>(LoadOptions::FORCE_ENABLED); |
| 239 | |
Stepan Salenikovich | f2d76c5 | 2015-07-17 17:54:56 -0400 | [diff] [blame^] | 240 | /* EDS backend(s) */ |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 241 | load_eds_sources(priv->cancellable); |
| 242 | |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 243 | /* Override theme since we don't have appropriate icons for a dark them (yet) */ |
| 244 | GtkSettings *gtk_settings = gtk_settings_get_default(); |
| 245 | g_object_set(G_OBJECT(gtk_settings), "gtk-application-prefer-dark-theme", |
| 246 | FALSE, NULL); |
| 247 | /* enable button icons */ |
| 248 | g_object_set(G_OBJECT(gtk_settings), "gtk-button-images", |
| 249 | TRUE, NULL); |
| 250 | |
| 251 | /* add GActions */ |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 252 | g_action_map_add_action_entries( |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 253 | G_ACTION_MAP(app), ring_actions, G_N_ELEMENTS(ring_actions), app); |
| 254 | |
| 255 | /* add accelerators */ |
| 256 | ring_accelerators(RING_CLIENT(app)); |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 257 | |
Stepan Salenikovich | 347b73a | 2015-03-22 10:39:00 -0400 | [diff] [blame] | 258 | /* Bind GActions to the UserActionModel */ |
| 259 | UserActionModel* uam = CallModel::instance()->userActionModel(); |
| 260 | QHash<int, GSimpleAction*> actionHash; |
| 261 | actionHash[ (int)UserActionModel::Action::ACCEPT ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "accept")); |
| 262 | actionHash[ (int)UserActionModel::Action::HOLD ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "hold")); |
Stepan Salenikovich | 7d75eab | 2015-06-12 12:11:45 -0400 | [diff] [blame] | 263 | actionHash[ (int)UserActionModel::Action::MUTE_AUDIO ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "mute_audio")); |
| 264 | actionHash[ (int)UserActionModel::Action::MUTE_VIDEO ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "mute_video")); |
Stepan Salenikovich | 347b73a | 2015-03-22 10:39:00 -0400 | [diff] [blame] | 265 | /* TODO: add commented actions when ready */ |
Stepan Salenikovich | 347b73a | 2015-03-22 10:39:00 -0400 | [diff] [blame] | 266 | // actionHash[ (int)UserActionModel::Action::SERVER_TRANSFER ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "transfer")); |
| 267 | // actionHash[ (int)UserActionModel::Action::RECORD ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "record")); |
| 268 | actionHash[ (int)UserActionModel::Action::HANGUP ] = G_SIMPLE_ACTION(g_action_map_lookup_action(G_ACTION_MAP(app), "hangup")); |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 269 | |
Stepan Salenikovich | 347b73a | 2015-03-22 10:39:00 -0400 | [diff] [blame] | 270 | for (QHash<int,GSimpleAction*>::const_iterator i = actionHash.begin(); i != actionHash.end(); ++i) { |
| 271 | GSimpleAction* sa = i.value(); |
| 272 | int_ptr_t user_data; |
| 273 | user_data.value = i.key(); |
| 274 | g_signal_connect(G_OBJECT(sa), "activate", G_CALLBACK(activate_action), user_data.ptr); |
| 275 | } |
Stepan Salenikovich | c64523b | 2015-02-27 16:31:00 -0500 | [diff] [blame] | 276 | |
Stepan Salenikovich | 347b73a | 2015-03-22 10:39:00 -0400 | [diff] [blame] | 277 | /* change the state of the GActions based on the UserActionModel */ |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 278 | priv->uam_updated = QObject::connect(uam,&UserActionModel::dataChanged, [actionHash,uam](const QModelIndex& tl, const QModelIndex& br) { |
Stepan Salenikovich | 347b73a | 2015-03-22 10:39:00 -0400 | [diff] [blame] | 279 | const int first(tl.row()),last(br.row()); |
| 280 | for(int i = first; i <= last;i++) { |
| 281 | const QModelIndex& idx = uam->index(i,0); |
| 282 | GSimpleAction* sa = actionHash[(int)qvariant_cast<UserActionModel::Action>(idx.data(UserActionModel::Role::ACTION))]; |
| 283 | if (sa) { |
| 284 | /* enable/disable GAction based on UserActionModel */ |
| 285 | g_simple_action_set_enabled(sa, idx.flags() & Qt::ItemIsEnabled); |
| 286 | /* set the state of the action if its stateful */ |
| 287 | if (g_action_get_state_type(G_ACTION(sa)) != NULL) |
| 288 | g_simple_action_set_state(sa, g_variant_new_boolean(idx.data(Qt::CheckStateRole) == Qt::Checked)); |
| 289 | } |
| 290 | } |
| 291 | }); |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 292 | |
Stepan Salenikovich | 76c33e6 | 2015-05-22 12:24:07 -0400 | [diff] [blame] | 293 | /* send call notifications */ |
| 294 | ring_notify_init(); |
| 295 | QObject::connect(CallModel::instance(), &CallModel::incomingCall, |
Stepan Salenikovich | 67112d1 | 2015-06-16 16:57:06 -0400 | [diff] [blame] | 296 | [] (Call *call) { ring_notify_incoming_call(call);} |
Stepan Salenikovich | 76c33e6 | 2015-05-22 12:24:07 -0400 | [diff] [blame] | 297 | ); |
| 298 | |
Stepan Salenikovich | 67112d1 | 2015-06-16 16:57:06 -0400 | [diff] [blame] | 299 | /* chat notifications for incoming messages on all calls which are not the |
| 300 | * currently selected call */ |
| 301 | ring_notify_monitor_chat_notifications(client); |
| 302 | |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 303 | #if GLIB_CHECK_VERSION(2,40,0) |
| 304 | G_APPLICATION_CLASS(ring_client_parent_class)->startup(app); |
| 305 | #else |
| 306 | /* don't need to chain up to the parent callback as this function will |
| 307 | * be called manually by the command_line callback in this case */ |
| 308 | #endif |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 309 | } |
| 310 | |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 311 | #if !GLIB_CHECK_VERSION(2,40,0) |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 312 | static int |
| 313 | ring_client_command_line(GApplication *app, GApplicationCommandLine *cmdline) |
| 314 | { |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 315 | gint argc; |
| 316 | gchar **argv = g_application_command_line_get_arguments(cmdline, &argc); |
| 317 | GOptionContext *context = ring_client_options_get_context(); |
| 318 | GError *error = NULL; |
| 319 | if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) { |
| 320 | g_print(_("%s\nRun '%s --help' to see a full list of available command line options.\n"), |
| 321 | error->message, argv[0]); |
Stepan Salenikovich | 8a287fc | 2015-05-01 16:53:20 -0400 | [diff] [blame] | 322 | g_clear_error(&error); |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 323 | g_option_context_free(context); |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 324 | g_strfreev(argv); |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 325 | return 1; |
| 326 | } |
| 327 | g_option_context_free(context); |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 328 | g_strfreev(argv); |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 329 | |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 330 | if (!g_application_get_is_remote(app)) { |
| 331 | /* if this is the primary instance, we must peform the startup */ |
| 332 | ring_client_startup(app); |
| 333 | } |
| 334 | |
| 335 | g_application_activate(app); |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | #endif |
| 340 | |
| 341 | static void |
| 342 | ring_client_activate(GApplication *app) |
| 343 | { |
| 344 | RingClient *client = RING_CLIENT(app); |
| 345 | RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); |
| 346 | |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 347 | if (priv->win == NULL) { |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 348 | priv->win = ring_main_window_new(GTK_APPLICATION(app)); |
| 349 | } |
| 350 | |
| 351 | gtk_window_present(GTK_WINDOW(priv->win)); |
Stepan Salenikovich | 6977184 | 2015-02-24 18:11:45 -0500 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | static void |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 355 | ring_client_shutdown(GApplication *app) |
| 356 | { |
| 357 | RingClient *self = RING_CLIENT(app); |
| 358 | RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(self); |
| 359 | |
Stepan Salenikovich | 2d63d5e | 2015-03-22 23:23:54 -0400 | [diff] [blame] | 360 | g_debug("quitting"); |
| 361 | |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 362 | /* cancel any pending cancellable operations */ |
| 363 | g_cancellable_cancel(priv->cancellable); |
| 364 | g_object_unref(priv->cancellable); |
| 365 | |
Stepan Salenikovich | 068fb69 | 2015-03-23 14:58:32 -0400 | [diff] [blame] | 366 | QObject::disconnect(priv->uam_updated); |
| 367 | |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 368 | /* free the QCoreApplication, which will destroy all libRingClient models |
| 369 | * and thus send the Unregister signal over dbus to dring */ |
| 370 | delete priv->qtapp; |
| 371 | |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 372 | /* free the copied cmd line args */ |
| 373 | g_strfreev(priv->argv); |
| 374 | |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 375 | g_clear_object(&priv->settings); |
| 376 | |
Stepan Salenikovich | 76c33e6 | 2015-05-22 12:24:07 -0400 | [diff] [blame] | 377 | ring_notify_uninit(); |
| 378 | |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 379 | /* Chain up to the parent class */ |
| 380 | G_APPLICATION_CLASS(ring_client_parent_class)->shutdown(app); |
| 381 | } |
| 382 | |
| 383 | static void |
| 384 | ring_client_init(RingClient *self) |
| 385 | { |
| 386 | RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(self); |
| 387 | |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 388 | priv->win = NULL; |
| 389 | priv->qtapp = NULL; |
Stepan Salenikovich | 6f68707 | 2015-03-26 10:43:37 -0400 | [diff] [blame] | 390 | priv->cancellable = g_cancellable_new(); |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 391 | priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL); |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 392 | |
| 393 | #if GLIB_CHECK_VERSION(2,40,0) |
| 394 | /* add custom cmd line options */ |
| 395 | ring_client_add_options(G_APPLICATION(self)); |
| 396 | #endif |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static void |
| 400 | ring_client_class_init(RingClientClass *klass) |
| 401 | { |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 402 | #if GLIB_CHECK_VERSION(2,40,0) |
| 403 | G_APPLICATION_CLASS(klass)->startup = ring_client_startup; |
| 404 | #else |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 405 | G_APPLICATION_CLASS(klass)->command_line = ring_client_command_line; |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 406 | #endif |
| 407 | G_APPLICATION_CLASS(klass)->activate = ring_client_activate; |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 408 | G_APPLICATION_CLASS(klass)->shutdown = ring_client_shutdown; |
| 409 | } |
| 410 | |
| 411 | RingClient * |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 412 | ring_client_new(int argc, char *argv[]) |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 413 | { |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 414 | /* because the g_application_add_main_option_entries was only added in |
| 415 | * glib 2.40, for lower versions we must handle the command line options |
| 416 | * ourselves |
| 417 | */ |
| 418 | RingClient *client = (RingClient *)g_object_new(ring_client_get_type(), |
Stepan Salenikovich | 7635058 | 2015-05-25 14:56:32 -0400 | [diff] [blame] | 419 | "application-id", RING_CLIENT_APP_ID, |
Stepan Salenikovich | 0d515e5 | 2015-05-19 16:31:05 -0400 | [diff] [blame] | 420 | #if GLIB_CHECK_VERSION(2,40,0) |
| 421 | NULL); |
| 422 | #else |
| 423 | "flags", G_APPLICATION_HANDLES_COMMAND_LINE, |
| 424 | NULL); |
| 425 | #endif |
| 426 | |
| 427 | /* copy the cmd line args before they get processed by the GApplication*/ |
| 428 | RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); |
| 429 | priv->argc = argc; |
| 430 | priv->argv = g_strdupv((gchar **)argv); |
| 431 | |
| 432 | return client; |
Stepan Salenikovich | d81ef29 | 2015-02-17 18:47:37 -0500 | [diff] [blame] | 433 | } |
Stepan Salenikovich | 67112d1 | 2015-06-16 16:57:06 -0400 | [diff] [blame] | 434 | |
| 435 | GtkWindow * |
| 436 | ring_client_get_main_windw(RingClient *client) |
| 437 | { |
| 438 | g_return_val_if_fail(IS_RING_CLIENT(client), NULL); |
| 439 | RingClientPrivate *priv = RING_CLIENT_GET_PRIVATE(client); |
| 440 | |
| 441 | return (GtkWindow *)priv->win; |
| 442 | } |