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 | |
| 22 | #include <gtk/gtk.h> |
Stepan Salenikovich | a1b8cb3 | 2015-09-11 14:58:35 -0400 | [diff] [blame] | 23 | #include <glib/gi18n.h> |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 24 | #include <categorizedhistorymodel.h> |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 25 | #include "utils/files.h" |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 26 | |
| 27 | struct _GeneralSettingsView |
| 28 | { |
Stepan Salenikovich | ab0f5be | 2016-02-05 15:16:35 -0500 | [diff] [blame] | 29 | GtkScrolledWindow parent; |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | struct _GeneralSettingsViewClass |
| 33 | { |
Stepan Salenikovich | ab0f5be | 2016-02-05 15:16:35 -0500 | [diff] [blame] | 34 | GtkScrolledWindowClass parent_class; |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | typedef struct _GeneralSettingsViewPrivate GeneralSettingsViewPrivate; |
| 38 | |
| 39 | struct _GeneralSettingsViewPrivate |
| 40 | { |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 41 | GSettings *settings; |
| 42 | |
| 43 | /* Rint settings */ |
| 44 | GtkWidget *checkbutton_autostart; |
Stepan Salenikovich | bc6c4be | 2015-07-31 16:07:54 -0400 | [diff] [blame] | 45 | GtkWidget *checkbutton_hideonclose; |
| 46 | GtkWidget *checkbutton_bringtofront; |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 47 | GtkWidget *radiobutton_chatright; |
| 48 | GtkWidget *radiobutton_chatbottom; |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 49 | |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 50 | /* history settings */ |
| 51 | GtkWidget *adjustment_history_duration; |
| 52 | GtkWidget *button_clear_history; |
| 53 | }; |
| 54 | |
Stepan Salenikovich | ab0f5be | 2016-02-05 15:16:35 -0500 | [diff] [blame] | 55 | 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] | 56 | |
| 57 | #define GENERAL_SETTINGS_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GENERAL_SETTINGS_VIEW_TYPE, GeneralSettingsViewPrivate)) |
| 58 | |
| 59 | static void |
| 60 | general_settings_view_dispose(GObject *object) |
| 61 | { |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 62 | GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(object); |
| 63 | |
| 64 | g_clear_object(&priv->settings); |
| 65 | |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 66 | G_OBJECT_CLASS(general_settings_view_parent_class)->dispose(object); |
| 67 | } |
| 68 | |
| 69 | static void |
| 70 | history_limit_changed(GtkAdjustment *adjustment, G_GNUC_UNUSED gpointer user_data) |
| 71 | { |
| 72 | int limit = (int)gtk_adjustment_get_value(GTK_ADJUSTMENT(adjustment)); |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 73 | CategorizedHistoryModel::instance().setHistoryLimit(limit); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static gboolean |
| 77 | clear_history_dialog(GeneralSettingsView *self) |
| 78 | { |
| 79 | gboolean response = FALSE; |
| 80 | GtkWidget *dialog = gtk_message_dialog_new(NULL, |
| 81 | (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), |
| 82 | GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, |
Stepan Salenikovich | a1b8cb3 | 2015-09-11 14:58:35 -0400 | [diff] [blame] | 83 | _("Are you sure you want to clear all your history?\nThis operation will also reset the Frequent Contacts list")); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 84 | |
| 85 | gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); |
| 86 | |
| 87 | /* get parent window so we can center on it */ |
| 88 | GtkWidget *parent = gtk_widget_get_toplevel(GTK_WIDGET(self)); |
| 89 | if (gtk_widget_is_toplevel(parent)) { |
| 90 | gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent)); |
| 91 | gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT); |
| 92 | } |
| 93 | |
| 94 | switch (gtk_dialog_run(GTK_DIALOG(dialog))) { |
| 95 | case GTK_RESPONSE_OK: |
| 96 | response = TRUE; |
| 97 | break; |
| 98 | default: |
| 99 | response = FALSE; |
| 100 | break; |
| 101 | } |
| 102 | |
| 103 | gtk_widget_destroy(dialog); |
| 104 | |
| 105 | return response; |
| 106 | } |
| 107 | |
| 108 | static void |
| 109 | clear_history(G_GNUC_UNUSED GtkWidget *button, GeneralSettingsView *self) |
| 110 | { |
| 111 | g_return_if_fail(IS_GENERAL_SETTINGS_VIEW(self)); |
| 112 | |
| 113 | if (clear_history_dialog(self) ) |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 114 | CategorizedHistoryModel::instance().clearAllCollections(); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static void |
| 118 | general_settings_view_init(GeneralSettingsView *self) |
| 119 | { |
| 120 | gtk_widget_init_template(GTK_WIDGET(self)); |
| 121 | |
| 122 | GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(self); |
| 123 | |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 124 | priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL); |
| 125 | |
Stepan Salenikovich | bc6c4be | 2015-07-31 16:07:54 -0400 | [diff] [blame] | 126 | /* bind client option to gsettings */ |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 127 | g_settings_bind(priv->settings, "start-on-login", |
| 128 | priv->checkbutton_autostart, "active", |
| 129 | G_SETTINGS_BIND_DEFAULT); |
Stepan Salenikovich | bc6c4be | 2015-07-31 16:07:54 -0400 | [diff] [blame] | 130 | g_settings_bind(priv->settings, "hide-on-close", |
| 131 | priv->checkbutton_hideonclose, "active", |
| 132 | G_SETTINGS_BIND_DEFAULT); |
| 133 | g_settings_bind(priv->settings, "bring-window-to-front", |
| 134 | priv->checkbutton_bringtofront, "active", |
| 135 | G_SETTINGS_BIND_DEFAULT); |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 136 | g_settings_bind(priv->settings, "chat-pane-horizontal", |
| 137 | priv->radiobutton_chatright, "active", |
| 138 | G_SETTINGS_BIND_DEFAULT); |
| 139 | g_settings_bind(priv->settings, "chat-pane-horizontal", |
| 140 | priv->radiobutton_chatbottom, "active", |
| 141 | (GSettingsBindFlags) (G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN)); |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 142 | |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 143 | /* history limit */ |
| 144 | gtk_adjustment_set_value(GTK_ADJUSTMENT(priv->adjustment_history_duration), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 145 | CategorizedHistoryModel::instance().historyLimit()); |
Stepan Salenikovich | de89611 | 2015-05-11 16:46:33 -0400 | [diff] [blame] | 146 | g_signal_connect(priv->adjustment_history_duration, |
| 147 | "value-changed", G_CALLBACK(history_limit_changed), NULL); |
| 148 | |
| 149 | /* clear history */ |
| 150 | g_signal_connect(priv->button_clear_history, "clicked", G_CALLBACK(clear_history), self); |
| 151 | } |
| 152 | |
| 153 | static void |
| 154 | general_settings_view_class_init(GeneralSettingsViewClass *klass) |
| 155 | { |
| 156 | G_OBJECT_CLASS(klass)->dispose = general_settings_view_dispose; |
| 157 | |
| 158 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
| 159 | "/cx/ring/RingGnome/generalsettingsview.ui"); |
| 160 | |
Stepan Salenikovich | fb7f295 | 2015-05-25 16:44:19 -0400 | [diff] [blame] | 161 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_autostart); |
Stepan Salenikovich | bc6c4be | 2015-07-31 16:07:54 -0400 | [diff] [blame] | 162 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_hideonclose); |
| 163 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, checkbutton_bringtofront); |
Stepan Salenikovich | a5e8e36 | 2015-11-05 16:50:48 -0500 | [diff] [blame] | 164 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, radiobutton_chatright); |
| 165 | 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] | 166 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, adjustment_history_duration); |
| 167 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, button_clear_history); |
| 168 | } |
| 169 | |
| 170 | GtkWidget * |
| 171 | general_settings_view_new() |
| 172 | { |
| 173 | gpointer view = g_object_new(GENERAL_SETTINGS_VIEW_TYPE, NULL); |
| 174 | |
| 175 | return (GtkWidget *)view; |
| 176 | } |