Commit 3807d983 authored by Nicolas Jager's avatar Nicolas Jager Committed by Guillaume Roguez

fix clear_history button with new lrc api

- call clearAllHistory over all accounts enabled.

Change-Id: Ia8ef8b8f0c944e371a7d26394e6c3b9ee2537b40
Reviewed-by: Guillaume Roguez's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent baf20c86
......@@ -73,6 +73,13 @@ G_DEFINE_TYPE_WITH_PRIVATE(GeneralSettingsView, general_settings_view, GTK_TYPE_
#define GENERAL_SETTINGS_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GENERAL_SETTINGS_VIEW_TYPE, GeneralSettingsViewPrivate))
enum {
CLEAR_ALL_HISTORY,
LAST_SIGNAL
};
static guint general_settings_view_signals[LAST_SIGNAL] = { 0 };
static void
general_settings_view_dispose(GObject *object)
{
......@@ -123,10 +130,8 @@ clear_history(G_GNUC_UNUSED GtkWidget *button, GeneralSettingsView *self)
{
g_return_if_fail(IS_GENERAL_SETTINGS_VIEW(self));
if (clear_history_dialog(self) ) {
CategorizedHistoryModel::instance().clear();
Media::RecordingModel::instance().clear();
}
if (clear_history_dialog(self) )
g_signal_emit(G_OBJECT(self), general_settings_view_signals[CLEAR_ALL_HISTORY], 0);
}
static void
......@@ -194,6 +199,18 @@ 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, box_profil_settings);
general_settings_view_signals[CLEAR_ALL_HISTORY] = g_signal_new (
"clear-all-history",
G_TYPE_FROM_CLASS(klass),
(GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION),
0,
nullptr,
nullptr,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
GtkWidget *
......
......@@ -204,6 +204,7 @@ public:
lrc::api::profile::Type currentTypeFilter_;
bool show_settings = false;
bool is_fullscreen = false;
bool has_cleared_all_history = false;
int smartviewPageNum = 0;
int contactRequestsPageNum = 0;
......@@ -560,6 +561,35 @@ CppImpl::chatNotifications()
);
}
static gboolean
on_clear_all_history_foreach(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer self)
{
g_return_val_if_fail(IS_RING_MAIN_WINDOW(self), TRUE);
auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
const gchar* account_id;
gtk_tree_model_get(model, iter, 0 /* col# */, &account_id /* data */, -1);
auto& accountInfo = priv->cpp->lrc_->getAccountModel().getAccountInfo(account_id);
accountInfo.conversationModel->clearAllHistory();
return FALSE;
}
static void
on_clear_all_history_clicked(RingMainWindow* self)
{
g_return_if_fail(IS_RING_MAIN_WINDOW(self));
auto* priv = RING_MAIN_WINDOW_GET_PRIVATE(RING_MAIN_WINDOW(self));
auto accountComboBox = GTK_COMBO_BOX(priv->combobox_account_selector);
auto model = gtk_combo_box_get_model(accountComboBox);
gtk_tree_model_foreach (model, on_clear_all_history_foreach, self);
priv->cpp->has_cleared_all_history = true;
}
void
CppImpl::init()
{
......@@ -666,6 +696,8 @@ CppImpl::init()
widgets->general_settings_view = general_settings_view_new();
gtk_stack_add_named(GTK_STACK(widgets->stack_main_view), widgets->general_settings_view,
GENERAL_SETTINGS_VIEW_NAME);
g_signal_connect_swapped(widgets->general_settings_view, "clear-all-history", G_CALLBACK(on_clear_all_history_clicked), self);
/* make the setting we will show first the active one */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widgets->radiobutton_general_settings), TRUE);
......@@ -1097,7 +1129,15 @@ CppImpl::leaveSettingsView()
gtk_stack_set_visible_child_name(GTK_STACK(widgets->stack_main_view), CALL_VIEW_NAME);
/* show the view which was selected previously */
/* return to the welcome view if has_cleared_all_history. The reason is you can have been in a chatview before you
* opened the settings view and did a clear all history. So without the code below, you'll see the chatview with
* obsolete messages. It will also ensure to refresh last interaction printed in the conversations list.
*/
if (has_cleared_all_history) {
onAccountSelectionChange(accountContainer_->info.id);
resetToWelcome();
has_cleared_all_history = false;
}
}
void
......
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