Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 1 | /* |
Guillaume Roguez | 2a6150d | 2017-07-19 18:24:47 -0400 | [diff] [blame^] | 2 | * Copyright (C) 2015-2017 Savoir-faire Linux Inc. |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -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 | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 18 | */ |
| 19 | |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 20 | #include "mediasettingsview.h" |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 21 | |
| 22 | #include <gtk/gtk.h> |
| 23 | #include "models/gtkqtreemodel.h" |
| 24 | #include "video/video_widget.h" |
| 25 | #include <video/previewmanager.h> |
| 26 | #include <video/configurationproxy.h> |
| 27 | #include <QtCore/QItemSelectionModel> |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 28 | #include <audio/settings.h> |
| 29 | #include <audio/managermodel.h> |
| 30 | #include <audio/alsapluginmodel.h> |
| 31 | #include <audio/outputdevicemodel.h> |
| 32 | #include <audio/inputdevicemodel.h> |
| 33 | #include <audio/ringtonedevicemodel.h> |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 34 | |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 35 | struct _MediaSettingsView |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 36 | { |
Stepan Salenikovich | ab0f5be | 2016-02-05 15:16:35 -0500 | [diff] [blame] | 37 | GtkScrolledWindow parent; |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 38 | }; |
| 39 | |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 40 | struct _MediaSettingsViewClass |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 41 | { |
Stepan Salenikovich | ab0f5be | 2016-02-05 15:16:35 -0500 | [diff] [blame] | 42 | GtkScrolledWindowClass parent_class; |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 43 | }; |
| 44 | |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 45 | typedef struct _MediaSettingsViewPrivate MediaSettingsViewPrivate; |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 46 | |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 47 | struct _MediaSettingsViewPrivate |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 48 | { |
Stepan Salenikovich | 1118d7a | 2016-02-05 15:52:55 -0500 | [diff] [blame] | 49 | GtkWidget *vbox_main; |
| 50 | |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 51 | /* audio settings */ |
| 52 | GtkWidget *combobox_manager; |
| 53 | GtkWidget *combobox_ringtone; |
| 54 | GtkWidget *combobox_output; |
| 55 | GtkWidget *combobox_input; |
| 56 | |
| 57 | QMetaObject::Connection manager_selection; |
| 58 | QMetaObject::Connection ringtone_selection; |
| 59 | QMetaObject::Connection output_selection; |
| 60 | QMetaObject::Connection input_selection; |
| 61 | |
| 62 | /* camera settings */ |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 63 | GtkWidget *combobox_device; |
| 64 | GtkWidget *combobox_channel; |
| 65 | GtkWidget *combobox_resolution; |
| 66 | GtkWidget *combobox_framerate; |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 67 | GtkWidget *video_widget; |
| 68 | |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 69 | /* this is used to keep track of the state of the preview when the settings |
| 70 | * are opened; if a call is in progress, then the preview should already be |
| 71 | * started and we don't want to stop it when the settings are closed, in this |
| 72 | * case */ |
| 73 | gboolean video_started_by_settings; |
| 74 | |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 75 | QMetaObject::Connection local_renderer_connection; |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 76 | QMetaObject::Connection device_selection; |
| 77 | QMetaObject::Connection channel_selection; |
| 78 | QMetaObject::Connection resolution_selection; |
| 79 | QMetaObject::Connection rate_selection; |
philippegorley | e198ac6 | 2017-06-14 13:41:53 -0400 | [diff] [blame] | 80 | |
| 81 | /* hardware accel settings */ |
| 82 | GtkWidget *checkbutton_hardware_decoding; |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 83 | }; |
| 84 | |
Stepan Salenikovich | ab0f5be | 2016-02-05 15:16:35 -0500 | [diff] [blame] | 85 | G_DEFINE_TYPE_WITH_PRIVATE(MediaSettingsView, media_settings_view, GTK_TYPE_SCROLLED_WINDOW); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 86 | |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 87 | #define MEDIA_SETTINGS_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), MEDIA_SETTINGS_VIEW_TYPE, MediaSettingsViewPrivate)) |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 88 | |
| 89 | static void |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 90 | media_settings_view_dispose(GObject *object) |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 91 | { |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 92 | MediaSettingsView *view = MEDIA_SETTINGS_VIEW(object); |
| 93 | MediaSettingsViewPrivate *priv = MEDIA_SETTINGS_VIEW_GET_PRIVATE(view); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 94 | |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 95 | /* make sure to stop the preview if this view is getting destroyed */ |
| 96 | if (priv->video_started_by_settings) { |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 97 | Video::PreviewManager::instance().stopPreview(); |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 98 | priv->video_started_by_settings = FALSE; |
| 99 | } |
| 100 | |
| 101 | QObject::disconnect(priv->manager_selection); |
| 102 | QObject::disconnect(priv->ringtone_selection); |
| 103 | QObject::disconnect(priv->output_selection); |
| 104 | QObject::disconnect(priv->input_selection); |
| 105 | |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 106 | QObject::disconnect(priv->local_renderer_connection); |
| 107 | QObject::disconnect(priv->device_selection); |
| 108 | QObject::disconnect(priv->channel_selection); |
| 109 | QObject::disconnect(priv->resolution_selection); |
| 110 | QObject::disconnect(priv->rate_selection); |
| 111 | |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 112 | G_OBJECT_CLASS(media_settings_view_parent_class)->dispose(object); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 113 | } |
| 114 | |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 115 | static QModelIndex |
| 116 | get_index_from_combobox(GtkComboBox *box) |
| 117 | { |
| 118 | GtkTreeIter iter; |
| 119 | GtkTreeModel *model = gtk_combo_box_get_model(box); |
| 120 | if (gtk_combo_box_get_active_iter(box, &iter)) { |
| 121 | return gtk_q_tree_model_get_source_idx(GTK_Q_TREE_MODEL(model), &iter); |
| 122 | } else { |
| 123 | return QModelIndex(); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | static void |
| 128 | update_selection(GtkComboBox *box, QItemSelectionModel *selection_model) |
| 129 | { |
| 130 | QModelIndex idx = get_index_from_combobox(box); |
| 131 | if (idx.isValid()) |
| 132 | selection_model->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect); |
| 133 | } |
| 134 | |
| 135 | static QMetaObject::Connection |
| 136 | connect_combo_box_qmodel(GtkComboBox *box, QAbstractItemModel *qmodel, QItemSelectionModel *selection_model) |
| 137 | { |
| 138 | QMetaObject::Connection connection; |
| 139 | GtkCellRenderer *renderer; |
| 140 | GtkQTreeModel *model = gtk_q_tree_model_new(qmodel, |
| 141 | 1, |
aviau | 9bbb19b | 2016-05-16 15:53:44 -0400 | [diff] [blame] | 142 | 0, Qt::DisplayRole, G_TYPE_STRING); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 143 | |
| 144 | gtk_combo_box_set_model(box, GTK_TREE_MODEL(model)); |
| 145 | renderer = gtk_cell_renderer_text_new(); |
| 146 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(box), renderer, FALSE); |
| 147 | gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(box), renderer, |
| 148 | "text", 0, NULL); |
Stepan Salenikovich | ab0f5be | 2016-02-05 15:16:35 -0500 | [diff] [blame] | 149 | g_object_set(G_OBJECT(renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 150 | |
| 151 | /* connect signals to and from the selection model */ |
| 152 | connection = QObject::connect( |
| 153 | selection_model, |
| 154 | &QItemSelectionModel::currentChanged, |
| 155 | [=](const QModelIndex & current, G_GNUC_UNUSED const QModelIndex & previous) { |
| 156 | /* select the current */ |
| 157 | if (current.isValid()) { |
| 158 | GtkTreeIter new_iter; |
| 159 | GtkTreeModel *model = gtk_combo_box_get_model(box); |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 160 | g_return_if_fail(model); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 161 | if (gtk_q_tree_model_source_index_to_iter(GTK_Q_TREE_MODEL(model), current, &new_iter)) { |
| 162 | gtk_combo_box_set_active_iter(box, &new_iter); |
| 163 | } else { |
| 164 | g_warning("SelectionModel changed to invalid QModelIndex?"); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | ); |
| 169 | g_signal_connect(box, |
| 170 | "changed", |
| 171 | G_CALLBACK(update_selection), |
| 172 | selection_model); |
| 173 | |
| 174 | /* sync the initial selection */ |
| 175 | QModelIndex idx = selection_model->currentIndex(); |
| 176 | if (idx.isValid()) { |
| 177 | GtkTreeIter iter; |
| 178 | if (gtk_q_tree_model_source_index_to_iter(model, idx, &iter)) |
| 179 | gtk_combo_box_set_active_iter(box, &iter); |
| 180 | } |
| 181 | |
| 182 | return connection; |
| 183 | } |
| 184 | |
| 185 | static void |
philippegorley | e198ac6 | 2017-06-14 13:41:53 -0400 | [diff] [blame] | 186 | hardware_decoding_toggled(GtkToggleButton *toggle_button, MediaSettingsView *self) |
| 187 | { |
philippegorley | e198ac6 | 2017-06-14 13:41:53 -0400 | [diff] [blame] | 188 | gboolean hardware_decoding = gtk_toggle_button_get_active(toggle_button); |
| 189 | Video::ConfigurationProxy::setDecodingAccelerated(hardware_decoding); |
| 190 | } |
| 191 | |
| 192 | static void |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 193 | media_settings_view_init(MediaSettingsView *view) |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 194 | { |
| 195 | gtk_widget_init_template(GTK_WIDGET(view)); |
| 196 | |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 197 | MediaSettingsViewPrivate *priv = MEDIA_SETTINGS_VIEW_GET_PRIVATE(view); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 198 | |
Stepan Salenikovich | 13b7fa1 | 2016-03-04 14:45:17 -0500 | [diff] [blame] | 199 | /* video settings */ |
| 200 | /* TODO: this is a workaround for a possible LRC issue |
| 201 | * make sure all the models are instantiated before making a selection |
| 202 | */ |
| 203 | Video::ConfigurationProxy::rateModel(); |
| 204 | Video::ConfigurationProxy::resolutionModel(); |
| 205 | Video::ConfigurationProxy::channelModel(); |
| 206 | Video::ConfigurationProxy::deviceModel(); |
| 207 | |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 208 | priv->device_selection = connect_combo_box_qmodel(GTK_COMBO_BOX(priv->combobox_device), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 209 | &Video::ConfigurationProxy::deviceModel(), |
| 210 | &Video::ConfigurationProxy::deviceSelectionModel()); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 211 | priv->channel_selection = connect_combo_box_qmodel(GTK_COMBO_BOX(priv->combobox_channel), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 212 | &Video::ConfigurationProxy::channelModel(), |
| 213 | &Video::ConfigurationProxy::channelSelectionModel()); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 214 | priv->resolution_selection = connect_combo_box_qmodel(GTK_COMBO_BOX(priv->combobox_resolution), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 215 | &Video::ConfigurationProxy::resolutionModel(), |
| 216 | &Video::ConfigurationProxy::resolutionSelectionModel()); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 217 | priv->rate_selection = connect_combo_box_qmodel(GTK_COMBO_BOX(priv->combobox_framerate), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 218 | &Video::ConfigurationProxy::rateModel(), |
| 219 | &Video::ConfigurationProxy::rateSelectionModel()); |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 220 | |
| 221 | /* audio settings */ |
Stepan Salenikovich | 13b7fa1 | 2016-03-04 14:45:17 -0500 | [diff] [blame] | 222 | /* TODO: this is a workaround for a possible LRC issue |
| 223 | * make sure all the models are instantiated before making a selection |
| 224 | */ |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 225 | Audio::Settings::instance().alsaPluginModel(); |
| 226 | Audio::Settings::instance().ringtoneDeviceModel(); |
| 227 | Audio::Settings::instance().inputDeviceModel(); |
| 228 | Audio::Settings::instance().outputDeviceModel(); |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 229 | priv->manager_selection = connect_combo_box_qmodel(GTK_COMBO_BOX(priv->combobox_manager), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 230 | Audio::Settings::instance().managerModel(), |
| 231 | Audio::Settings::instance().managerModel()->selectionModel()); |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 232 | priv->ringtone_selection = connect_combo_box_qmodel(GTK_COMBO_BOX(priv->combobox_ringtone), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 233 | Audio::Settings::instance().ringtoneDeviceModel(), |
| 234 | Audio::Settings::instance().ringtoneDeviceModel()->selectionModel()); |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 235 | priv->input_selection = connect_combo_box_qmodel(GTK_COMBO_BOX(priv->combobox_input), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 236 | Audio::Settings::instance().inputDeviceModel(), |
| 237 | Audio::Settings::instance().inputDeviceModel()->selectionModel()); |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 238 | priv->output_selection = connect_combo_box_qmodel(GTK_COMBO_BOX(priv->combobox_output), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 239 | Audio::Settings::instance().outputDeviceModel(), |
| 240 | Audio::Settings::instance().outputDeviceModel()->selectionModel()); |
Stepan Salenikovich | 5d3506e | 2015-03-30 11:01:29 -0400 | [diff] [blame] | 241 | |
philippegorley | e198ac6 | 2017-06-14 13:41:53 -0400 | [diff] [blame] | 242 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->checkbutton_hardware_decoding), Video::ConfigurationProxy::getDecodingAccelerated()); |
| 243 | g_signal_connect(priv->checkbutton_hardware_decoding, "toggled", G_CALLBACK(hardware_decoding_toggled), view); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static void |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 247 | media_settings_view_class_init(MediaSettingsViewClass *klass) |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 248 | { |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 249 | G_OBJECT_CLASS(klass)->dispose = media_settings_view_dispose; |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 250 | |
| 251 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 252 | "/cx/ring/RingGnome/mediasettingsview.ui"); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 253 | |
Stepan Salenikovich | 1118d7a | 2016-02-05 15:52:55 -0500 | [diff] [blame] | 254 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), MediaSettingsView, vbox_main); |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 255 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), MediaSettingsView, combobox_manager); |
| 256 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), MediaSettingsView, combobox_ringtone); |
| 257 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), MediaSettingsView, combobox_output); |
| 258 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), MediaSettingsView, combobox_input); |
| 259 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), MediaSettingsView, combobox_device); |
| 260 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), MediaSettingsView, combobox_channel); |
| 261 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), MediaSettingsView, combobox_resolution); |
| 262 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), MediaSettingsView, combobox_framerate); |
philippegorley | e198ac6 | 2017-06-14 13:41:53 -0400 | [diff] [blame] | 263 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), MediaSettingsView, checkbutton_hardware_decoding); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | GtkWidget * |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 267 | media_settings_view_new() |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 268 | { |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 269 | gpointer view = g_object_new(MEDIA_SETTINGS_VIEW_TYPE, NULL); |
Stepan Salenikovich | f903d1b | 2015-03-25 14:51:45 -0400 | [diff] [blame] | 270 | |
| 271 | return (GtkWidget *)view; |
| 272 | } |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 273 | |
| 274 | void |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 275 | media_settings_view_show_preview(MediaSettingsView *self, gboolean show_preview) |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 276 | { |
Stepan Salenikovich | 0bd5349 | 2015-05-11 14:28:52 -0400 | [diff] [blame] | 277 | g_return_if_fail(IS_MEDIA_SETTINGS_VIEW(self)); |
| 278 | MediaSettingsViewPrivate *priv = MEDIA_SETTINGS_VIEW_GET_PRIVATE(self); |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 279 | |
| 280 | /* if TRUE, create a VideoWidget, then check if the preview has already been |
| 281 | * started (because a call was in progress); if not, then start it. |
| 282 | * if FALSE, check if the preview was started by this function, if so |
| 283 | * then stop the preview; then destroy the VideoWidget to make sure we don't |
| 284 | * get useless frame updates */ |
| 285 | |
| 286 | if (show_preview) { |
| 287 | /* put video widget in */ |
| 288 | priv->video_widget = video_widget_new(); |
| 289 | gtk_widget_show_all(priv->video_widget); |
Stepan Salenikovich | 1118d7a | 2016-02-05 15:52:55 -0500 | [diff] [blame] | 290 | gtk_box_pack_start(GTK_BOX(priv->vbox_main), priv->video_widget, TRUE, TRUE, 0); |
| 291 | // set minimum size for video so it doesn't shrink too much |
Adrien BĂ©raud | cf3e08c | 2016-03-03 22:55:21 -0500 | [diff] [blame] | 292 | gtk_widget_set_size_request(priv->video_widget, 400, -1); |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 293 | |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 294 | if (Video::PreviewManager::instance().isPreviewing()) { |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 295 | priv->video_started_by_settings = FALSE; |
| 296 | |
| 297 | /* local renderer, but set as "remote" so that it takes up the whole screen */ |
| 298 | video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget), |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 299 | Video::PreviewManager::instance().previewRenderer(), |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 300 | VIDEO_RENDERER_REMOTE); |
| 301 | } else { |
| 302 | priv->video_started_by_settings = TRUE; |
| 303 | priv->local_renderer_connection = QObject::connect( |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 304 | &Video::PreviewManager::instance(), |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 305 | &Video::PreviewManager::previewStarted, |
| 306 | [=](Video::Renderer *renderer) { |
| 307 | video_widget_push_new_renderer(VIDEO_WIDGET(priv->video_widget), |
| 308 | renderer, |
| 309 | VIDEO_RENDERER_REMOTE); |
| 310 | } |
| 311 | ); |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 312 | Video::PreviewManager::instance().startPreview(); |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 313 | } |
| 314 | } else { |
| 315 | if (priv->video_started_by_settings) { |
Guillaume Roguez | 5d1514b | 2015-10-22 15:55:31 -0400 | [diff] [blame] | 316 | Video::PreviewManager::instance().stopPreview(); |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 317 | QObject::disconnect(priv->local_renderer_connection); |
| 318 | priv->video_started_by_settings = FALSE; |
| 319 | } |
| 320 | |
| 321 | if (priv->video_widget && IS_VIDEO_WIDGET(priv->video_widget)) |
Stepan Salenikovich | 1118d7a | 2016-02-05 15:52:55 -0500 | [diff] [blame] | 322 | gtk_container_remove(GTK_CONTAINER(priv->vbox_main), priv->video_widget); |
Stepan Salenikovich | 4111891 | 2015-05-01 11:25:46 -0400 | [diff] [blame] | 323 | priv->video_widget = NULL; |
| 324 | } |
| 325 | |
| 326 | } |