Commit af55ee4a authored by Philippe Gorley's avatar Philippe Gorley Committed by Philippe Gorley

add recording preferences

Change-Id: I2156beef926180bbf5513a597e8163f1530390cd
parent 86d4fb2a
......@@ -24,10 +24,17 @@
#include <glib/gi18n.h>
#include <glib.h>
// LRC
#include <api/avmodel.h>
// Ring client
#include "utils/files.h"
#include "avatarmanipulation.h"
namespace { namespace details {
class CppImpl;
}}
enum
{
PROP_RING_MAIN_WIN_PNT = 1,
......@@ -49,7 +56,7 @@ struct _GeneralSettingsViewPrivate
{
GSettings *settings;
/* Rint settings */
/* Jami settings */
GtkWidget *at_startup_button;
GtkWidget *systray_button;
GtkWidget *incoming_open_button;
......@@ -64,14 +71,58 @@ struct _GeneralSettingsViewPrivate
GtkWidget *adjustment_history_duration;
GtkWidget *button_clear_history;
/* Call recording settings */
GtkWidget *record_preview_button;
GtkWidget *always_record_button;
GtkWidget *adjustment_record_quality;
GtkWidget *filechooserbutton_record_path;
/* ring main window pointer */
GtkWidget* ring_main_window_pnt;
details::CppImpl* cpp; ///< Non-UI and C++ only code
};
G_DEFINE_TYPE_WITH_PRIVATE(GeneralSettingsView, general_settings_view, GTK_TYPE_SCROLLED_WINDOW);
#define GENERAL_SETTINGS_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GENERAL_SETTINGS_VIEW_TYPE, GeneralSettingsViewPrivate))
namespace { namespace details {
class CppImpl
{
public:
explicit CppImpl(GeneralSettingsView& widget, lrc::api::AVModel& avModel);
lrc::api::AVModel* avModel_ = nullptr;
GeneralSettingsView* self = nullptr; // The GTK widget itself
GeneralSettingsViewPrivate* widgets = nullptr;
};
CppImpl::CppImpl(GeneralSettingsView& widget, lrc::api::AVModel& avModel)
: self(&widget)
, widgets(GENERAL_SETTINGS_VIEW_GET_PRIVATE(&widget))
, avModel_(&avModel)
{
gtk_switch_set_active(
GTK_SWITCH(widgets->record_preview_button),
avModel_->getRecordPreview());
gtk_switch_set_active(
GTK_SWITCH(widgets->always_record_button),
avModel_->getAlwaysRecord());
gtk_file_chooser_set_action(
GTK_FILE_CHOOSER(widgets->filechooserbutton_record_path),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
gtk_file_chooser_set_filename(
GTK_FILE_CHOOSER(widgets->filechooserbutton_record_path),
avModel_->getRecordPath().c_str());
gtk_adjustment_set_value(
GTK_ADJUSTMENT(widgets->adjustment_record_quality),
avModel_->getRecordQuality());
}
}} // namespace details
enum {
CLEAR_ALL_HISTORY,
UPDATE_DOWNLOAD_FOLDER,
......@@ -142,14 +193,14 @@ update_downloads_button_label(GeneralSettingsView *self)
}
static void
change_prefered_directory (gchar * directory, GeneralSettingsView *self)
change_prefered_directory (gchar * directory, GeneralSettingsView *self, gchar * id, void (*cb)(GeneralSettingsView*))
{
g_return_if_fail(IS_GENERAL_SETTINGS_VIEW(self));
GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(self);
priv->settings = g_settings_new_full(get_ring_schema(), NULL, NULL);
g_settings_set_value(priv->settings, "download-folder", g_variant_new("s", directory));
update_downloads_button_label(self);
g_settings_set_value(priv->settings, id, g_variant_new("s", directory));
cb(self);
}
static void
......@@ -187,11 +238,52 @@ choose_downloads_directory(GeneralSettingsView *self)
if (!filename) return;
// set download folder
change_prefered_directory(filename, self);
change_prefered_directory(filename, self, "download-folder", update_downloads_button_label);
g_signal_emit(G_OBJECT(self), general_settings_view_signals[UPDATE_DOWNLOAD_FOLDER], 0, filename);
}
static void
preview_toggled(GtkSwitch *button, GParamSpec* /*spec*/, GeneralSettingsView *self)
{
g_return_if_fail(IS_GENERAL_SETTINGS_VIEW(self));
GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(self);
gboolean preview = gtk_switch_get_active(button);
if (priv && priv->cpp && priv->cpp->avModel_)
priv->cpp->avModel_->setRecordPreview(preview);
}
static void
always_record_toggled(GtkSwitch *button, GParamSpec* /*spec*/, GeneralSettingsView *self)
{
g_return_if_fail(IS_GENERAL_SETTINGS_VIEW(self));
GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(self);
gboolean rec = gtk_switch_get_active(button);
if (priv && priv->cpp && priv->cpp->avModel_)
priv->cpp->avModel_->setAlwaysRecord(rec);
}
static void
record_quality_changed(GtkAdjustment *adjustment, GeneralSettingsView *self)
{
g_return_if_fail(IS_GENERAL_SETTINGS_VIEW(self));
GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(self);
gdouble qual = gtk_adjustment_get_value(adjustment);
if (priv && priv->cpp && priv->cpp->avModel_)
priv->cpp->avModel_->setRecordQuality(qual);
}
static void
update_record_path(GtkFileChooser *file_chooser, GeneralSettingsView* self)
{
g_return_if_fail(IS_GENERAL_SETTINGS_VIEW(self));
GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(self);
auto* filename = gtk_file_chooser_get_filename(file_chooser);
if (filename != priv->cpp->avModel_->getRecordPath())
priv->cpp->avModel_->setRecordPath(filename);
g_free(filename);
}
static void
general_settings_view_init(GeneralSettingsView *self)
{
......@@ -253,6 +345,12 @@ general_settings_view_init(GeneralSettingsView *self)
/* clear history */
g_signal_connect(priv->button_clear_history, "clicked", G_CALLBACK(clear_history), self);
/* Recording callbacks */
g_signal_connect(priv->record_preview_button, "notify::active", G_CALLBACK(preview_toggled), self);
g_signal_connect(priv->always_record_button, "notify::active", G_CALLBACK(always_record_toggled), self);
g_signal_connect(priv->adjustment_record_quality, "value-changed", G_CALLBACK(record_quality_changed), self);
g_signal_connect(priv->filechooserbutton_record_path, "file-set", G_CALLBACK(update_record_path), self);
}
......@@ -319,6 +417,10 @@ general_settings_view_class_init(GeneralSettingsViewClass *klass)
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, adjustment_history_duration);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, button_clear_history);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, button_choose_downloads_directory);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, record_preview_button);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, always_record_button);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, adjustment_record_quality);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, filechooserbutton_record_path);
general_settings_view_signals[CLEAR_ALL_HISTORY] = g_signal_new (
"clear-all-history",
......@@ -353,19 +455,22 @@ general_settings_view_class_init(GeneralSettingsViewClass *klass)
}
GtkWidget *
general_settings_view_new(GtkWidget* ring_main_window_pointer)
general_settings_view_new(GtkWidget* ring_main_window_pointer, lrc::api::AVModel& avModel)
{
gpointer view = g_object_new(GENERAL_SETTINGS_VIEW_TYPE, NULL);
auto self = g_object_new(GENERAL_SETTINGS_VIEW_TYPE, NULL);
auto* priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(GENERAL_SETTINGS_VIEW (self));
priv->cpp = new details::CppImpl(
*(reinterpret_cast<GeneralSettingsView*>(self)), avModel
);
// set_up ring main window pointer (needed by modal dialogs)
GValue val = G_VALUE_INIT;
g_value_init (&val, G_TYPE_POINTER);
g_value_set_pointer (&val, ring_main_window_pointer);
g_object_set_property (G_OBJECT (view), "ring_main_window_pnt", &val);
g_object_set_property (G_OBJECT (self), "ring_main_window_pnt", &val);
g_value_unset (&val);
GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(GENERAL_SETTINGS_VIEW (view));
g_signal_connect_swapped(priv->button_choose_downloads_directory, "clicked", G_CALLBACK(choose_downloads_directory), view);
g_signal_connect_swapped(priv->button_choose_downloads_directory, "clicked", G_CALLBACK(choose_downloads_directory), self);
// CSS styles
auto provider = gtk_css_provider_new();
......@@ -375,5 +480,5 @@ general_settings_view_new(GtkWidget* ring_main_window_pointer)
gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()),
GTK_STYLE_PROVIDER(provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
return (GtkWidget *)view;
return (GtkWidget *)self;
}
......@@ -22,6 +22,10 @@
#include <gtk/gtk.h>
namespace lrc { namespace api {
class AVModel;
}}
G_BEGIN_DECLS
#define GENERAL_SETTINGS_VIEW_TYPE (general_settings_view_get_type ())
......@@ -34,7 +38,7 @@ typedef struct _GeneralSettingsView GeneralSettingsView;
typedef struct _GeneralSettingsViewClass GeneralSettingsViewClass;
GType general_settings_view_get_type (void) G_GNUC_CONST;
GtkWidget *general_settings_view_new (GtkWidget* ring_main_window_pnt);
GtkWidget *general_settings_view_new (GtkWidget* ring_main_window_pnt, lrc::api::AVModel& avModel);
G_END_DECLS
......
......@@ -1157,7 +1157,7 @@ CppImpl::init()
NEW_ACCOUNT_SETTINGS_VIEW_NAME);
}
widgets->general_settings_view = general_settings_view_new(GTK_WIDGET(self));
widgets->general_settings_view = general_settings_view_new(GTK_WIDGET(self), lrc_->getAVModel());
widgets->update_download_folder = g_signal_connect_swapped(
widgets->general_settings_view,
"update-download-folder",
......
......@@ -17,6 +17,14 @@
<property name="upper">65535</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment_record_quality">
<property name="value">0</property>
<property name="lower">0</property>
<!-- 0 to 50 MB/s -->
<property name="upper">50000</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<template class="GeneralSettingsView" parent="GtkScrolledWindow">
<property name="visible">True</property>
......@@ -565,6 +573,191 @@
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<!-- Call recording settings -->
<child>
<object class="GtkBox" id="box_recorder_settings">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="halign">fill</property>
<property name="spacing">8</property>
<!-- Title -->
<child>
<object class="GtkLabel" id="label_recorder_settings">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Call Recording</property>
<property name="halign">start</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkListBox" id="recorder_settings">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">fill</property>
<property name="selection_mode">none</property>
<child>
<!-- Record video preview -->
<object class="GtkListBoxRow" id="record_preview_row">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">fill</property>
<child>
<object class="GtkBox" id="record_preview_box">
<property name="visible">True</property>
<property name="halign">fill</property>
<property name="orientation">horizontal</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel" id="label_record_preview">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Record local video</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="record_preview_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<!-- Always record -->
<object class="GtkListBoxRow" id="always_record_row">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">fill</property>
<child>
<object class="GtkBox" id="always_record_box">
<property name="visible">True</property>
<property name="halign">fill</property>
<property name="orientation">horizontal</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel" id="label_always_record">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Always record calls</property>
</object>
</child>
<child>
<object class="GtkSwitch" id="always_record_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<!-- Record folder -->
<object class="GtkListBoxRow" id="record_path_row">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">fill</property>
<child>
<object class="GtkBox" id="record_path_box">
<property name="visible">True</property>
<property name="halign">fill</property>
<property name="orientation">horizontal</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="spacing">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel" id="label_record_path">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Record folder</property>
</object>
</child>
<child>
<object class="GtkFileChooserButton" id="filechooserbutton_record_path">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="create_folders">False</property>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child>
<!-- Record bitrate/quality -->
<object class="GtkListBoxRow" id="record_quality_row">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">fill</property>
<child>
<object class="GtkBox" id="record_quality_box">
<property name="visible">True</property>
<property name="halign">fill</property>
<property name="orientation">horizontal</property>
<property name="margin_left">12</property>
<property name="margin_right">12</property>
<property name="margin_top">12</property>
<property name="margin_bottom">12</property>
<child>
<object class="GtkLabel" id="label_record_quality">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Bitrate for call recordings (kb/s)</property>
</object>
</child>
<child>
<object class="GtkSpinButton" id="spinbutton_record_quality">
<property name="visible">True</property>
<property name="value">0</property>
<property name="adjustment">adjustment_record_quality</property>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment