Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 1 | /* |
Stepan Salenikovich | be87d2c | 2016-01-25 14:14:34 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 Savoir-faire Linux Inc. |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 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. |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "generalsettingsview.h" |
| 21 | |
Stepan Salenikovich | 5a12767 | 2016-09-13 11:19:50 -0400 | [diff] [blame] | 22 | // GTK+ related |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 23 | #include <gtk/gtk.h> |
Stepan Salenikovich | a1b8cb3 | 2015-09-11 14:58:35 -0400 | [diff] [blame] | 24 | #include <glib/gi18n.h> |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 25 | |
Stepan Salenikovich | 5a12767 | 2016-09-13 11:19:50 -0400 | [diff] [blame] | 26 | // LRC |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 27 | #include <person.h> |
| 28 | #include <profile.h> |
| 29 | #include <profilemodel.h> |
Stepan Salenikovich | 5a12767 | 2016-09-13 11:19:50 -0400 | [diff] [blame] | 30 | #include <categorizedhistorymodel.h> |
Stepan Salenikovich | 738e59a | 2016-09-16 15:36:11 -0400 | [diff] [blame] | 31 | #include <media/recordingmodel.h> |
Stepan Salenikovich | 5a12767 | 2016-09-13 11:19:50 -0400 | [diff] [blame] | 32 | |
| 33 | // Ring client |
| 34 | #include "utils/files.h" |
| 35 | #include "avatarmanipulation.h" |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 36 | |
| 37 | struct _GeneralSettingsView |
| 38 | { |
Stepan Salenikovich | ab0f5be | 2016-02-05 15:16:35 -0500 | [diff] [blame] | 39 | GtkScrolledWindow parent; |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | struct _GeneralSettingsViewClass |
| 43 | { |
Stepan Salenikovich | ab0f5be | 2016-02-05 15:16:35 -0500 | [diff] [blame] | 44 | GtkScrolledWindowClass parent_class; |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | typedef struct _GeneralSettingsViewPrivate GeneralSettingsViewPrivate; |
| 48 | |
| 49 | struct _GeneralSettingsViewPrivate |
| 50 | { |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 51 | GSettings *settings; |
| 52 | |
| 53 | /* Rint settings */ |
| 54 | GtkWidget *checkbutton_autostart; |
Stepan Salenikovich | 982b288 | 2016-06-15 13:13:37 -0400 | [diff] [blame] | 55 | GtkWidget *checkbutton_showstatusicon; |
Stepan Salenikovich | bc6c4be | 2015-07-31 16:07:54 -0400 | [diff] [blame] | 56 | GtkWidget *checkbutton_bringtofront; |
Stepan Salenikovich | 5a12767 | 2016-09-13 11:19:50 -0400 | [diff] [blame] | 57 | GtkWidget *checkbutton_callnotifications; |
| 58 | GtkWidget *checkbutton_chatnotifications; |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 59 | GtkWidget *checkbutton_searchentryplacescall; |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 60 | GtkWidget *radiobutton_chatright; |
| 61 | GtkWidget *radiobutton_chatbottom; |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 62 | GtkWidget *box_profil_settings; |
| 63 | GtkWidget *avatarmanipulation; |
| 64 | GtkWidget *profile_name; |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 65 | |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 66 | /* history settings */ |
| 67 | GtkWidget *adjustment_history_duration; |
| 68 | GtkWidget *button_clear_history; |
| 69 | }; |
| 70 | |
Stepan Salenikovich | ab0f5be | 2016-02-05 15:16:35 -0500 | [diff] [blame] | 71 | G_DEFINE_TYPE_WITH_PRIVATE(GeneralSettingsView, general_settings_view, GTK_TYPE_SCROLLED_WINDOW); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 72 | |
| 73 | #define GENERAL_SETTINGS_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GENERAL_SETTINGS_VIEW_TYPE, GeneralSettingsViewPrivate)) |
| 74 | |
| 75 | static void |
| 76 | general_settings_view_dispose(GObject *object) |
| 77 | { |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 78 | GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(object); |
| 79 | |
| 80 | g_clear_object(&priv->settings); |
| 81 | |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 82 | //make sure the VideoWidget is destroyed |
| 83 | general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(object), FALSE); |
| 84 | |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 85 | G_OBJECT_CLASS(general_settings_view_parent_class)->dispose(object); |
| 86 | } |
| 87 | |
| 88 | static void |
| 89 | history_limit_changed(GtkAdjustment *adjustment, G_GNUC_UNUSED gpointer user_data) |
| 90 | { |
| 91 | int limit = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment)); |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 92 | CategorizedHistoryModel::instance().setHistoryLimit(limit); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | static gboolean |
| 96 | clear_history_dialog(GeneralSettingsView *self) |
| 97 | { |
| 98 | gboolean response = FALSE; |
| 99 | GtkWidget *dialog = gtk_message_dialog_new(NULL, |
| 100 | (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), |
| 101 | GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, |
Stepan Salenikovich | 738e59a | 2016-09-16 15:36:11 -0400 | [diff] [blame] | 102 | _("This is a destructive operation. Are you sure you want to delete all of your chat and call history?")); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 103 | |
| 104 | gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); |
| 105 | |
| 106 | /* get parent window so we can center on it */ |
| 107 | GtkWidget *parent = gtk_widget_get_toplevel(GTK_WIDGET(self)); |
| 108 | if (gtk_widget_is_toplevel(parent)) { |
| 109 | gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent)); |
| 110 | gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT); |
| 111 | } |
| 112 | |
| 113 | switch (gtk_dialog_run(GTK_DIALOG(dialog))) { |
| 114 | case GTK_RESPONSE_OK: |
| 115 | response = TRUE; |
| 116 | break; |
| 117 | default: |
| 118 | response = FALSE; |
| 119 | break; |
| 120 | } |
| 121 | |
| 122 | gtk_widget_destroy(dialog); |
| 123 | |
| 124 | return response; |
| 125 | } |
| 126 | |
| 127 | static void |
| 128 | clear_history(G_GNUC_UNUSED GtkWidget *button, GeneralSettingsView *self) |
| 129 | { |
| 130 | g_return_if_fail(IS_GENERAL_SETTINGS_VIEW(self)); |
| 131 | |
Stepan Salenikovich | 738e59a | 2016-09-16 15:36:11 -0400 | [diff] [blame] | 132 | if (clear_history_dialog(self) ) { |
| 133 | CategorizedHistoryModel::instance().clear(); |
| 134 | Media::RecordingModel::instance().clear(); |
| 135 | } |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static void |
| 139 | general_settings_view_init(GeneralSettingsView *self) |
| 140 | { |
| 141 | gtk_widget_init_template(GTK_WIDGET(self)); |
| 142 | |
| 143 | GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(self); |
| 144 | |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 145 | priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL); |
| 146 | |
Stepan Salenikovich | bc6c4be | 2015-07-31 16:07:54 -0400 | [diff] [blame] | 147 | /* bind client option to gsettings */ |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 148 | g_settings_bind(priv->settings, "start-on-login", |
| 149 | priv->checkbutton_autostart, "active", |
| 150 | G_SETTINGS_BIND_DEFAULT); |
Stepan Salenikovich | 982b288 | 2016-06-15 13:13:37 -0400 | [diff] [blame] | 151 | g_settings_bind(priv->settings, "show-status-icon", |
| 152 | priv->checkbutton_showstatusicon, "active", |
Stepan Salenikovich | bc6c4be | 2015-07-31 16:07:54 -0400 | [diff] [blame] | 153 | G_SETTINGS_BIND_DEFAULT); |
| 154 | g_settings_bind(priv->settings, "bring-window-to-front", |
| 155 | priv->checkbutton_bringtofront, "active", |
| 156 | G_SETTINGS_BIND_DEFAULT); |
Stepan Salenikovich | 5a12767 | 2016-09-13 11:19:50 -0400 | [diff] [blame] | 157 | g_settings_bind(priv->settings, "enable-call-notifications", |
| 158 | priv->checkbutton_callnotifications, "active", |
| 159 | G_SETTINGS_BIND_DEFAULT); |
| 160 | g_settings_bind(priv->settings, "enable-chat-notifications", |
| 161 | priv->checkbutton_chatnotifications, "active", |
| 162 | G_SETTINGS_BIND_DEFAULT); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 163 | g_settings_bind(priv->settings, "search-entry-places-call", |
| 164 | priv->checkbutton_searchentryplacescall, "active", |
| 165 | G_SETTINGS_BIND_DEFAULT); |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 166 | g_settings_bind(priv->settings, "chat-pane-horizontal", |
| 167 | priv->radiobutton_chatright, "active", |
| 168 | G_SETTINGS_BIND_DEFAULT); |
| 169 | g_settings_bind(priv->settings, "chat-pane-horizontal", |
| 170 | priv->radiobutton_chatbottom, "active", |
| 171 | (GSettingsBindFlags) (G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN)); |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 172 | |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 173 | /* history limit */ |
| 174 | gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_history_duration), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 175 | CategorizedHistoryModel::instance().historyLimit()); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 176 | g_signal_connect(priv->adjustment_history_duration, |
| 177 | "value-changed", G_CALLBACK(history_limit_changed), NULL); |
| 178 | |
| 179 | /* clear history */ |
| 180 | g_signal_connect(priv->button_clear_history, "clicked", G_CALLBACK(clear_history), self); |
| 181 | } |
| 182 | |
| 183 | static void |
| 184 | general_settings_view_class_init(GeneralSettingsViewClass *klass) |
| 185 | { |
| 186 | G_OBJECT_CLASS(klass)->dispose = general_settings_view_dispose; |
| 187 | |
| 188 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
| 189 | "/cx/ring/RingGnome/generalsettingsview.ui"); |
| 190 | |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 191 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_autostart); |
Stepan Salenikovich | 982b288 | 2016-06-15 13:13:37 -0400 | [diff] [blame] | 192 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_showstatusicon); |
Stepan Salenikovich | bc6c4be | 2015-07-31 16:07:54 -0400 | [diff] [blame] | 193 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_bringtofront); |
Stepan Salenikovich | 5a12767 | 2016-09-13 11:19:50 -0400 | [diff] [blame] | 194 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_callnotifications); |
| 195 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_chatnotifications); |
Stepan Salenikovich | e993324 | 2016-06-21 18:08:48 -0400 | [diff] [blame] | 196 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_searchentryplacescall); |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 197 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, radiobutton_chatright); |
| 198 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, radiobutton_chatbottom); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 199 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, adjustment_history_duration); |
| 200 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, button_clear_history); |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 201 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, box_profil_settings); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | GtkWidget * |
| 205 | general_settings_view_new() |
| 206 | { |
| 207 | gpointer view = g_object_new(GENERAL_SETTINGS_VIEW_TYPE, NULL); |
| 208 | |
| 209 | return (GtkWidget *)view; |
| 210 | } |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 211 | |
| 212 | static void |
| 213 | change_profile_name(GtkEntry *entry) |
| 214 | { |
| 215 | auto profile = ProfileModel::instance().selectedProfile(); |
| 216 | profile->person()->setFormattedName(gtk_entry_get_text(entry)); |
| 217 | profile->save(); |
| 218 | } |
| 219 | |
| 220 | void |
| 221 | general_settings_view_show_profile(GeneralSettingsView *self, gboolean show_profile) |
| 222 | { |
| 223 | g_return_if_fail(GENERAL_SETTINGS_VIEW(self)); |
| 224 | GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(self); |
| 225 | |
| 226 | /* We will construct and destroy the profile (AvatarManipulation widget) each time the profile |
| 227 | * should be visible and hidden, respectively. It is not the "prettiest" way of doing things, |
| 228 | * but this way we ensure 1. that the profile is updated correctly when it is shown and 2. that |
| 229 | * the VideoWidget inside is destroyed when it is not being shown. |
| 230 | */ |
| 231 | if (show_profile) { |
| 232 | /* avatar manipulation widget */ |
| 233 | priv->avatarmanipulation = avatar_manipulation_new(); |
AmarOk | 436bd9b | 2017-07-13 15:02:48 -0400 | [diff] [blame] | 234 | gtk_widget_set_halign(priv->box_profil_settings, GtkAlign::GTK_ALIGN_CENTER); |
Nicolas Jager | 6f5e04a | 2016-05-18 15:04:59 -0400 | [diff] [blame] | 235 | gtk_box_pack_start(GTK_BOX(priv->box_profil_settings), priv->avatarmanipulation, true, true, 0); |
| 236 | gtk_widget_set_visible(priv->avatarmanipulation, true); |
| 237 | |
| 238 | /* print the profile name. as long as we have only one profil, profil name = person name (a.k.a formatedName) */ |
| 239 | priv->profile_name = gtk_entry_new(); |
| 240 | gtk_entry_set_text (GTK_ENTRY(priv->profile_name), |
| 241 | ProfileModel::instance().selectedProfile()->person()->formattedName().toUtf8().constData()); |
| 242 | gtk_widget_set_visible(priv->profile_name, true); |
| 243 | gtk_entry_set_alignment(GTK_ENTRY(priv->profile_name), 0.5); |
| 244 | gtk_box_pack_start(GTK_BOX(priv->box_profil_settings), priv->profile_name, true, true, 0); |
| 245 | g_signal_connect(priv->profile_name, "changed", G_CALLBACK(change_profile_name), NULL); |
| 246 | } else { |
| 247 | if (priv->avatarmanipulation) { |
| 248 | gtk_container_remove(GTK_CONTAINER(priv->box_profil_settings), priv->avatarmanipulation); |
| 249 | priv->avatarmanipulation = nullptr; |
| 250 | } |
| 251 | if (priv->profile_name) { |
| 252 | gtk_container_remove(GTK_CONTAINER(priv->box_profil_settings), priv->profile_name); |
| 253 | priv->profile_name = nullptr; |
| 254 | } |
| 255 | } |
| 256 | } |