Commit 6f5e04a8 authored by Nicolas Jager's avatar Nicolas Jager Committed by Stepan Salenikovich

profile : allows to edit profile in the settings

allows to edit the avatar and the name in settings.

Tuleap: #717
Change-Id: I9fcb3606087f2e5a6680a2ea5ba9c7c5cc23d1b1
parent b413b300
......@@ -23,6 +23,12 @@
#include <glib/gi18n.h>
#include <categorizedhistorymodel.h>
#include "utils/files.h"
#include "avatarmanipulation.h"
/* lrc */
#include <person.h>
#include <profile.h>
#include <profilemodel.h>
struct _GeneralSettingsView
{
......@@ -46,6 +52,9 @@ struct _GeneralSettingsViewPrivate
GtkWidget *checkbutton_bringtofront;
GtkWidget *radiobutton_chatright;
GtkWidget *radiobutton_chatbottom;
GtkWidget *box_profil_settings;
GtkWidget *avatarmanipulation;
GtkWidget *profile_name;
/* history settings */
GtkWidget *adjustment_history_duration;
......@@ -63,6 +72,9 @@ general_settings_view_dispose(GObject *object)
g_clear_object(&priv->settings);
//make sure the VideoWidget is destroyed
general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(object), FALSE);
G_OBJECT_CLASS(general_settings_view_parent_class)->dispose(object);
}
......@@ -165,6 +177,7 @@ general_settings_view_class_init(GeneralSettingsViewClass *klass)
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), GeneralSettingsView, radiobutton_chatbottom);
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, box_profil_settings);
}
GtkWidget *
......@@ -174,3 +187,48 @@ general_settings_view_new()
return (GtkWidget *)view;
}
static void
change_profile_name(GtkEntry *entry)
{
auto profile = ProfileModel::instance().selectedProfile();
profile->person()->setFormattedName(gtk_entry_get_text(entry));
profile->save();
}
void
general_settings_view_show_profile(GeneralSettingsView *self, gboolean show_profile)
{
g_return_if_fail(GENERAL_SETTINGS_VIEW(self));
GeneralSettingsViewPrivate *priv = GENERAL_SETTINGS_VIEW_GET_PRIVATE(self);
/* We will construct and destroy the profile (AvatarManipulation widget) each time the profile
* should be visible and hidden, respectively. It is not the "prettiest" way of doing things,
* but this way we ensure 1. that the profile is updated correctly when it is shown and 2. that
* the VideoWidget inside is destroyed when it is not being shown.
*/
if (show_profile) {
/* avatar manipulation widget */
priv->avatarmanipulation = avatar_manipulation_new();
gtk_box_pack_start(GTK_BOX(priv->box_profil_settings), priv->avatarmanipulation, true, true, 0);
gtk_widget_set_visible(priv->avatarmanipulation, true);
/* print the profile name. as long as we have only one profil, profil name = person name (a.k.a formatedName) */
priv->profile_name = gtk_entry_new();
gtk_entry_set_text (GTK_ENTRY(priv->profile_name),
ProfileModel::instance().selectedProfile()->person()->formattedName().toUtf8().constData());
gtk_widget_set_visible(priv->profile_name, true);
gtk_entry_set_alignment(GTK_ENTRY(priv->profile_name), 0.5);
gtk_box_pack_start(GTK_BOX(priv->box_profil_settings), priv->profile_name, true, true, 0);
g_signal_connect(priv->profile_name, "changed", G_CALLBACK(change_profile_name), NULL);
} else {
if (priv->avatarmanipulation) {
gtk_container_remove(GTK_CONTAINER(priv->box_profil_settings), priv->avatarmanipulation);
priv->avatarmanipulation = nullptr;
}
if (priv->profile_name) {
gtk_container_remove(GTK_CONTAINER(priv->box_profil_settings), priv->profile_name);
priv->profile_name = nullptr;
}
}
}
......@@ -35,6 +35,7 @@ typedef struct _GeneralSettingsViewClass GeneralSettingsViewClass;
GType general_settings_view_get_type (void) G_GNUC_CONST;
GtkWidget *general_settings_view_new (void);
void general_settings_view_show_profile (GeneralSettingsView *self, gboolean show_profile);
G_END_DECLS
......
......@@ -423,6 +423,10 @@ settings_clicked(G_GNUC_UNUSED GtkButton *button, RingMainWindow *win)
if (priv->last_settings_view == priv->media_settings_view)
media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), TRUE);
/* make sure to show the profile if we're showing the general settings */
if (priv->last_settings_view == priv->general_settings_view)
general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), TRUE);
gtk_stack_set_transition_type(GTK_STACK(priv->stack_main_view), GTK_STACK_TRANSITION_TYPE_SLIDE_UP);
gtk_stack_set_visible_child(GTK_STACK(priv->stack_main_view), priv->last_settings_view);
......@@ -448,6 +452,7 @@ settings_clicked(G_GNUC_UNUSED GtkButton *button, RingMainWindow *win)
/* make sure video preview is stopped, in case it was started */
media_settings_view_show_preview(MEDIA_SETTINGS_VIEW(priv->media_settings_view), FALSE);
general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), FALSE);
gtk_stack_set_transition_type(GTK_STACK(priv->stack_main_view), GTK_STACK_TRANSITION_TYPE_SLIDE_DOWN);
gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), CALL_VIEW_NAME);
......@@ -493,9 +498,12 @@ show_general_settings(GtkToggleButton *navbutton, RingMainWindow *win)
RingMainWindowPrivate *priv = RING_MAIN_WINDOW_GET_PRIVATE(win);
if (gtk_toggle_button_get_active(navbutton)) {
general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), TRUE);
gtk_stack_set_transition_type(GTK_STACK(priv->stack_main_view), GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT);
gtk_stack_set_visible_child_name(GTK_STACK(priv->stack_main_view), GENERAL_SETTINGS_VIEW_NAME);
priv->last_settings_view = priv->general_settings_view;
} else {
general_settings_view_show_profile(GENERAL_SETTINGS_VIEW(priv->general_settings_view), FALSE);
}
}
......
......@@ -17,6 +17,36 @@
<property name="orientation">vertical</property>
<property name="spacing">10</property>
<property name="border_width">10</property>
<!-- start profil settings -->
<child>
<object class="GtkFrame" id="frame_profile_settings">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<!-- start frame label -->
<child type="label">
<object class="GtkLabel" id="label_profile_settings">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Profile Settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
<!-- end frame label -->
<!-- start box ring settings-->
<child>
<object class="GtkBox" id="box_profil_settings">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">end</property>
<property name="halign">start</property>
<property name="orientation">vertical</property>
<property name="spacing">10</property>
</object>
</child>
<!-- end box ring settings-->
<!-- end profil settings -->
</object>
</child>
<!-- start ring settings -->
<child>
<object class="GtkFrame" id="frame_ring_settings">
......
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