fix clear_history button with new lrc api
- call clearAllHistory over all accounts enabled.
Change-Id: Ia8ef8b8f0c944e371a7d26394e6c3b9ee2537b40
Reviewed-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
diff --git a/src/generalsettingsview.cpp b/src/generalsettingsview.cpp
index 6e09a1d..31ec6b3 100644
--- a/src/generalsettingsview.cpp
+++ b/src/generalsettingsview.cpp
@@ -73,6 +73,13 @@
#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 @@
{
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 @@
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 *
diff --git a/src/ringmainwindow.cpp b/src/ringmainwindow.cpp
index 14ee8a4..6ee39f9 100644
--- a/src/ringmainwindow.cpp
+++ b/src/ringmainwindow.cpp
@@ -204,6 +204,7 @@
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 @@
);
}
+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 @@
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 @@
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