Commit 15a8b90f authored by Nicolas Jager's avatar Nicolas Jager

RingMainWindow : add account selector

- a new combo box is added to ringmainwindow, allowing to select an
account. It's required for the management of the upcoming contact
request implementation.

- Discretize informations shown on the the welcome page by account
protocols.

- Close views when the user swap between accounts.

Change-Id: I8b3f2ca75f8c532fcef0505d920bc662c096b705
Reviewed-by: default avatarStepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
parent cbc8dcc4
......@@ -126,6 +126,7 @@ struct _RingMainWindowPrivate
GtkWidget *account_creation_wizard;
GtkWidget *account_migration_view;
GtkWidget *spinner_lookup;
GtkWidget *combobox_account_selector;
/* Pending ring usernames lookup for the search entry */
QMetaObject::Connection username_lookup;
......@@ -761,6 +762,12 @@ on_account_creation_completed(RingMainWindow *win)
/* show the settings button*/
gtk_widget_show(priv->ring_settings);
/* show the account selector */
gtk_widget_show(priv->combobox_account_selector);
/* init the selection for the account selector */
gtk_combo_box_set_active(GTK_COMBO_BOX(priv->combobox_account_selector), 0);
}
static void
......@@ -781,6 +788,7 @@ show_account_creation_wizard(RingMainWindow *win)
/* hide settings button until account creation is complete */
gtk_widget_hide(priv->ring_settings);
gtk_widget_hide(priv->combobox_account_selector);
gtk_widget_show(priv->account_creation_wizard);
......@@ -1058,6 +1066,7 @@ handle_account_migrations(RingMainWindow *win)
g_signal_connect_swapped(priv->account_migration_view, "account-migration-failed", G_CALLBACK(handle_account_migrations), win);
gtk_widget_hide(priv->ring_settings);
gtk_widget_hide(priv->combobox_account_selector);
gtk_widget_show(priv->account_migration_view);
gtk_stack_add_named(
GTK_STACK(priv->stack_main_view),
......@@ -1072,9 +1081,27 @@ handle_account_migrations(RingMainWindow *win)
else
{
gtk_widget_show(priv->ring_settings);
gtk_widget_show(priv->combobox_account_selector);
/* init the selection for the account selector */
gtk_combo_box_set_active(GTK_COMBO_BOX(priv->combobox_account_selector), 0);
}
}
static void
selected_account_changed(GtkComboBox *gtk_combo_box, RingMainWindow *self)
{
int nbr = gtk_combo_box_get_active(gtk_combo_box);
QModelIndex idx = AccountModel::instance().userSelectionModel()->model()->index(nbr, 0);
auto account = AccountModel::instance().getAccountByModelIndex(idx);
AccountModel::instance().setUserChosenAccount(account);
// we closing any view opened to avoid confusion (especially between SIP and Ring protocols).
hide_view_clicked(nullptr, self);
}
static void
ring_main_window_init(RingMainWindow *win)
{
......@@ -1158,6 +1185,17 @@ ring_main_window_init(RingMainWindow *win)
priv->treeview_history = history_view_new();
gtk_container_add(GTK_CONTAINER(priv->scrolled_window_history), priv->treeview_history);
/* use this event to refresh the treeview_conversations when account selection changed */
QObject::connect(AccountModel::instance().userSelectionModel(), &QItemSelectionModel::currentChanged, [priv](const QModelIndex& idx){
// next line will refresh the recentmodel so the treeview will do
RecentModel::instance().peopleProxy()->setFilterRegExp("");
// set the good index to the combox. Required when the selected account changed by different way than selecting
// from the combo box.
gtk_combo_box_set_active(GTK_COMBO_BOX(priv->combobox_account_selector), idx.row());
});
/* welcome/default view */
priv->welcome_view = ring_welcome_view_new();
g_object_ref(priv->welcome_view); // increase ref because don't want it to be destroyed when not displayed
......@@ -1213,6 +1251,26 @@ ring_main_window_init(RingMainWindow *win)
/* user has to create the ring account */
show_account_creation_wizard(win);
}
/* model for the combobox for Account chooser */
auto account_model = gtk_q_tree_model_new(AccountModel::instance().userSelectionModel()->model(), 1,
0, Account::Role::Alias, G_TYPE_STRING);
gtk_combo_box_set_model(GTK_COMBO_BOX(priv->combobox_account_selector), GTK_TREE_MODEL(account_model));
auto *renderer = gtk_cell_renderer_text_new();
/* layout */
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(priv->combobox_account_selector), renderer, FALSE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(priv->combobox_account_selector), renderer, "text", 0, NULL);
g_signal_connect(priv->combobox_account_selector, "changed", G_CALLBACK(selected_account_changed), win);
/* init the selection for the account selector */
selected_account_changed(GTK_COMBO_BOX(priv->combobox_account_selector), win);
g_object_unref(account_model);
}
static void
......@@ -1272,6 +1330,7 @@ ring_main_window_class_init(RingMainWindowClass *klass)
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_media_settings);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, radiobutton_account_settings);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, spinner_lookup);
gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), RingMainWindow, combobox_account_selector);
}
GtkWidget *
......
......@@ -26,6 +26,10 @@
#include <accountmodel.h>
#include <qrencode.h>
// Qt
#include <QObject>
#include <QItemSelectionModel>
struct _RingWelcomeView
{
GtkScrolledWindow parent;
......@@ -60,8 +64,7 @@ static void
update_view(RingWelcomeView *self) {
auto priv = RING_WELCOME_VIEW_GET_PRIVATE(self);
auto account = get_active_ring_account();
if (account != nullptr) {
if (auto account = get_active_ring_account()) {
gchar *ring_id = nullptr;
if(!account->registeredName().isEmpty()){
gtk_label_set_text(
......@@ -84,15 +87,18 @@ update_view(RingWelcomeView *self) {
_("fetching RingID..."));
}
gtk_label_set_markup(GTK_LABEL(priv->label_ringid), ring_id);
g_free(ring_id);
}
gtk_widget_show(priv->label_explanation);
gtk_widget_show(priv->label_ringid);
gtk_widget_show(priv->button_qrcode);
gtk_widget_show(priv->revealer_qrcode);
gtk_widget_set_visible(priv->label_ringid, account != nullptr);
gtk_widget_set_visible(priv->label_explanation, account != nullptr);
gtk_widget_set_visible(priv->button_qrcode, account != nullptr);
gtk_widget_set_visible(priv->revealer_qrcode, account != nullptr);
g_free(ring_id);
if (!account) {
} else { // any other protocols
gtk_widget_hide(priv->label_explanation);
gtk_widget_hide(priv->label_ringid);
gtk_widget_hide(priv->button_qrcode);
gtk_widget_hide(priv->revealer_qrcode);
gtk_revealer_set_reveal_child(GTK_REVEALER(priv->revealer_qrcode), FALSE);
gtk_widget_set_opacity(priv->box_overlay, 1.0);
}
......@@ -190,14 +196,19 @@ ring_welcome_view_init(RingWelcomeView *self)
gtk_widget_set_visible(priv->button_qrcode, FALSE);
gtk_box_pack_start(GTK_BOX(box_main), priv->button_qrcode, TRUE, TRUE, 0);
update_view(self);
priv->account_model_data_changed = QObject::connect(
&AccountModel::instance(),
&AccountModel::dataChanged,
[self] (const QModelIndex&, const QModelIndex&) { update_view(self); }
);
/* connect to the next signal to update in terms of the account selected */
QObject::connect(AccountModel::instance().userSelectionModel(), &QItemSelectionModel::currentChanged,
[self](const QModelIndex& idx){
Q_UNUSED(idx)
update_view(self);
});
gtk_widget_show_all(GTK_WIDGET(self));
}
......
......@@ -21,6 +21,9 @@
#include <accountmodel.h>
// LRC
#include <QItemSelectionModel>
/**
* returns TRUE if a RING account exists; FALSE otherwise
*/
......@@ -50,52 +53,11 @@ force_ring_display_name()
}
/**
* Finds and returns the first RING account, in order of priority:
* 1. registered
* 2. enabled
* 3. existing
*
* Returns a nullptr if no RING acconts exist
* Returns the the user chosen account if it's a ring account, nullptr otherwise.
*/
Account*
get_active_ring_account()
{
/* get the users Ring account
* if multiple accounts exist, get the first one which is registered,
* if none, then the first one which is enabled,
* if none, then the first one in the list of ring accounts
*/
Account *registered_account = nullptr;
Account *enabled_account = nullptr;
Account *ring_account = nullptr;
int a_count = AccountModel::instance().rowCount();
for (int i = 0; i < a_count && !registered_account; ++i) {
QModelIndex idx = AccountModel::instance().index(i, 0);
Account *account = AccountModel::instance().getAccountByModelIndex(idx);
if (account->protocol() == Account::Protocol::RING) {
/* got RING account, check if active */
if (account->isEnabled()) {
/* got enabled account, check if connected */
if (account->registrationState() == Account::RegistrationState::READY) {
/* got registered account, use this one */
registered_account = enabled_account = ring_account = account;
// g_debug("got registered account: %s", ring_account->alias().toUtf8().constData());
} else {
/* not registered, but enabled, use if its the first one */
if (!enabled_account) {
enabled_account = ring_account = account;
// g_debug("got enabled ring accout: %s", ring_account->alias().toUtf8().constData());
}
}
} else {
/* not enabled, but a Ring account, use if its the first one */
if (!ring_account) {
ring_account = account;
// g_debug("got ring account: %s", ring_account->alias().toUtf8().constData());
}
}
}
}
return ring_account;
auto account = AccountModel::instance().userChosenAccount();
return (account && account->protocol() == Account::Protocol::RING) ? account : nullptr;
}
......@@ -83,6 +83,20 @@
</object>
</child>
<!-- end titel box with search or settings -->
<!-- choose account -->
<child>
<object class="GtkComboBox" id="combobox_account_selector">
<property name="width_request">230</property>
<property name="visible">True</property>
<property name="popup-fixed-width">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
</packing>
</child>
<!-- end choose account -->
<!-- button settings -->
<child>
<object class="GtkButton" id="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