Commit 7e259ac4 authored by Hugo Lefeuvre's avatar Hugo Lefeuvre Committed by Sébastien Blin

refresh popupmenu/chatview on account state change

Better UI reactivity on account state change:

+ Do not show audio and video call options in the conversationsview's
  popup menu when account is disabled (this doesn't make sense,
  account is not able to place a call)
+ Refresh popup menu on account state change (list of options
  has to be updated)
+ Refresh chatview on account state change (some elements of the
  chatview require update, e.g. message bar)
+ Fix broken display property update in hideControls()

Misc code cleanup, add a few helpers to avoid code duplication.

Change-Id: I212a47566bd65687e5ed61ec56087a4e1f3166bd
Gitlab: #929Reviewed-by: Sébastien Blin's avatarSebastien Blin <sebastien.blin@savoirfairelinux.com>
parent b5a082c9
......@@ -645,7 +645,7 @@ chat_view_new (WebKitChatContainer* webkit_chat_container,
}
void
chat_view_update_temporary(ChatView* self, bool showAddButton, bool showInvitation)
chat_view_update_temporary(ChatView* self)
{
g_return_if_fail(IS_CHAT_VIEW(self));
update_chatview_frame(self);
......
......@@ -57,7 +57,7 @@ GtkWidget *chat_view_new (WebKitChatContainer* view,
AccountInfoPointer const & accountInfo,
lrc::api::conversation::Info* conversation);
lrc::api::conversation::Info chat_view_get_conversation(ChatView*);
void chat_view_update_temporary(ChatView*, bool, bool);
void chat_view_update_temporary(ChatView*);
void chat_view_set_header_visible(ChatView*, gboolean);
G_END_DECLS
/****************************************************************************
* Copyright (C) 2017-2018 Savoir-faire Linux *
* Copyright (C) 2017-2018 Savoir-faire Linux *
* Author: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> *
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com> *
* *
......@@ -210,7 +210,7 @@ update(GtkTreeSelection *selection, ConversationPopupMenu *self)
auto callId = conversation.confId.empty() ? conversation.callId : conversation.confId;
// Not in call
if (!contactInfo.isBanned) {
if (!contactInfo.isBanned && (*priv->accountInfo_)->enabled) {
auto place_video_call_conversation = gtk_menu_item_new_with_mnemonic(_("Place _video call"));
gtk_menu_shell_append(GTK_MENU_SHELL(self), place_video_call_conversation);
g_signal_connect(place_video_call_conversation, "activate", G_CALLBACK(place_video_call), priv);
......
......@@ -355,9 +355,8 @@ call_conversation(GtkTreeView *self,
}
static void
select_conversation(GtkTreeSelection *selection, ConversationsView *self)
refresh_popup_menu(ConversationsView *self)
{
// Update popupMenu_
auto priv = CONVERSATIONS_VIEW_GET_PRIVATE(self);
if (priv->popupMenu_) {
// Because popup menu is not up to date, we need to update it.
......@@ -372,6 +371,13 @@ select_conversation(GtkTreeSelection *selection, ConversationsView *self)
if (isVisible && nbItems > 0)
gtk_menu_popup(GTK_MENU(priv->popupMenu_), nullptr, nullptr, nullptr, nullptr, 0, gtk_get_current_event_time());
}
}
static void
select_conversation(GtkTreeSelection *selection, ConversationsView *self)
{
auto priv = CONVERSATIONS_VIEW_GET_PRIVATE(self);
refresh_popup_menu(self);
GtkTreeIter iter;
GtkTreeModel *model = nullptr;
gchar *conversationUid = nullptr;
......@@ -748,6 +754,7 @@ conversations_view_select_conversation(ConversationsView *self, const std::strin
if(std::string(ringId) == uid) {
auto selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(self));
gtk_tree_selection_select_iter(selection, &iter);
refresh_popup_menu(self);
g_free(ringId);
return;
}
......
......@@ -306,6 +306,8 @@ public:
void enterSettingsView();
void leaveSettingsView();
lrc::api::conversation::Info getCurrentConversation(GtkWidget* frame_call);
void showAccountSelectorWidget(bool show = true);
std::size_t refreshAccountSelectorWidget(int selection_row = -1, const std::string& selected = "");
......@@ -1204,10 +1206,7 @@ CppImpl::displayCurrentCallView(lrc::api::conversation::Info conversation)
auto contactUri = chatViewConversation_->participants.front();
auto contactInfo = accountInfo_->contactModel->getContact(contactUri);
if (auto chat_view = current_call_view_get_chat_view(CURRENT_CALL_VIEW(new_view))) {
auto isPending = contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING;
chat_view_update_temporary(CHAT_VIEW(chat_view),
isPending || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY,
isPending);
chat_view_update_temporary(CHAT_VIEW(chat_view));
}
} catch(...) { }
......@@ -1734,6 +1733,22 @@ CppImpl::slotInvalidAccountFromLrc(const std::string& id)
}
}
lrc::api::conversation::Info
CppImpl::getCurrentConversation(GtkWidget* frame_call)
{
lrc::api::conversation::Info current_item;
current_item.uid = "-1";
if (IS_CHAT_VIEW(frame_call)) {
current_item = chat_view_get_conversation(CHAT_VIEW(frame_call));
} else if (IS_CURRENT_CALL_VIEW(frame_call)) {
current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(frame_call));
} else if (IS_INCOMING_CALL_VIEW(frame_call)) {
current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(frame_call));
}
return current_item;
}
void
CppImpl::slotAccountStatusChanged(const std::string& id)
{
......@@ -1741,12 +1756,19 @@ CppImpl::slotAccountStatusChanged(const std::string& id)
updateLrc(id);
ring_welcome_update_view(RING_WELCOME_VIEW(widgets->welcome_view));
return;
} else {
new_account_settings_view_update(NEW_ACCOUNT_SETTINGS_VIEW(widgets->new_account_settings_view), false);
auto currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
if (currentIdx == -1)
currentIdx = 0; // If no account selected, select the first account
refreshAccountSelectorWidget(currentIdx, id);
}
new_account_settings_view_update(NEW_ACCOUNT_SETTINGS_VIEW(widgets->new_account_settings_view), false);
auto currentIdx = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets->combobox_account_selector));
if (currentIdx == -1)
currentIdx = 0; // If no account selected, select the first account
refreshAccountSelectorWidget(currentIdx, id);
auto* frame_call = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), getCurrentConversation(frame_call).uid);
if (IS_CHAT_VIEW(frame_call)) {
chat_view_update_temporary(CHAT_VIEW(frame_call));
}
}
......@@ -1755,13 +1777,10 @@ CppImpl::slotConversationCleared(const std::string& uid)
{
// Change the view when the history is cleared.
auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
lrc::api::conversation::Info current_item;
current_item.uid = "-1"; // Because the Searching item has an empty uid
if (IS_CHAT_VIEW(old_view))
current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
else
// if incoming or call view we don't want to change the view
return;
g_return_if_fail(IS_CHAT_VIEW(old_view));
lrc::api::conversation::Info current_item = getCurrentConversation(old_view);
if (current_item.uid == uid) {
// We are on the conversation cleared.
// Go to welcome view because user doesn't want this conversation
......@@ -1774,16 +1793,8 @@ void
CppImpl::slotModelSorted()
{
// Synchronize selection when sorted and update pending icon
auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
lrc::api::conversation::Info current_item;
current_item.uid = "-1";
if (IS_CHAT_VIEW(old_view))
current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
else if (IS_CURRENT_CALL_VIEW(old_view))
current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
else if (IS_INCOMING_CALL_VIEW(old_view))
current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid);
auto* frame_call = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), getCurrentConversation(frame_call).uid);
refreshPendingContactRequestTab();
}
......@@ -1863,15 +1874,9 @@ CppImpl::slotFilterChanged()
{
// Synchronize selection when filter changes
auto* old_view = gtk_bin_get_child(GTK_BIN(widgets->frame_call));
lrc::api::conversation::Info current_item;
current_item.uid = "-1";
if (IS_CHAT_VIEW(old_view))
current_item = chat_view_get_conversation(CHAT_VIEW(old_view));
else if (IS_CURRENT_CALL_VIEW(old_view))
current_item = current_call_view_get_conversation(CURRENT_CALL_VIEW(old_view));
else if (IS_INCOMING_CALL_VIEW(old_view))
current_item = incoming_call_view_get_conversation(INCOMING_CALL_VIEW(old_view));
auto current_item = getCurrentConversation(old_view);
conversations_view_select_conversation(CONVERSATIONS_VIEW(widgets->treeview_conversations), current_item.uid);
// Get if conversation still exists.
auto& conversationModel = accountInfo_->conversationModel;
auto conversations = conversationModel->allFilteredConversations();
......@@ -1907,10 +1912,7 @@ CppImpl::slotNewConversation(const std::string& uid)
try {
auto contactUri = chatViewConversation_->participants.front();
auto contactInfo = accountInfo_->contactModel->getContact(contactUri);
auto isPending = contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING;
chat_view_update_temporary(CHAT_VIEW(gtk_bin_get_child(GTK_BIN(widgets->frame_call))),
isPending || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY,
isPending);
chat_view_update_temporary(CHAT_VIEW(gtk_bin_get_child(GTK_BIN(widgets->frame_call))));
} catch(...) { }
}
}
......@@ -1949,10 +1951,7 @@ CppImpl::slotShowChatView(const std::string& id, lrc::api::conversation::Info or
if (current_item.uid != origin.uid) {
changeView(CHAT_VIEW_TYPE, origin);
} else {
auto isPending = contactInfo.profileInfo.type == lrc::api::profile::Type::PENDING;
chat_view_update_temporary(CHAT_VIEW(old_view),
isPending || contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY,
isPending);
chat_view_update_temporary(CHAT_VIEW(old_view));
}
}
......
......@@ -635,9 +635,9 @@ function humanFileSize(bytes) {
*/
function hideControls(accountEnabled) {
if (!accountEnabled) {
callButtons.display = "none"
callButtons.style.display = "none"
} else {
callButtons.display = ""
callButtons.style.display = ""
}
}
......
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