Commit 75a3917f authored by Stepan Salenikovich's avatar Stepan Salenikovich

gnome: set display name for RING accounts

Setting the alias will also set the the display name to the same
value for a RING account.  All RING accounts with empty display
names have theirs set to the same as their alias.

Issue: #77367
Change-Id: Ie031f381f0b3bd272802746120a05c22b04f4fdc
parent f2d76c53
......@@ -233,6 +233,8 @@ SET( SRC_FILES
src/createcontactdialog.cpp
src/utils/menus.h
src/utils/menus.cpp
src/utils/accounts.h
src/utils/accounts.cpp
)
# compile glib resource files to c code
......
......@@ -93,6 +93,8 @@ account_alias_changed(GtkEditable *entry, AccountGeneralTab *view)
g_return_if_fail(IS_ACCOUNT_GENERAL_TAB(view));
AccountGeneralTabPrivate *priv = ACCOUNT_GENERAL_TAB_GET_PRIVATE(view);
priv->account->setAlias(QString(gtk_editable_get_chars(entry, 0, -1)));
if (priv->account->protocol() == Account::Protocol::RING)
priv->account->setDisplayName(gtk_entry_get_text(GTK_ENTRY(entry)));
}
static void
......
......@@ -301,7 +301,9 @@ add_account(G_GNUC_UNUSED GtkWidget *entry, AccountView *view)
GtkWidget *working = ring_dialog_working(GTK_WIDGET(view), NULL);
gtk_window_present(GTK_WINDOW(working));
AccountModel::instance()->add(QString("New Account"), protocol_idx);
auto account = AccountModel::instance()->add(QString("New Account"), protocol_idx);
if (account->protocol() == Account::Protocol::RING)
account->setDisplayName("New Account");
/* now save after a short timeout to make sure that
* the save doesn't happen before the "working" dialog is presented
......
......@@ -56,6 +56,7 @@
#include "config.h"
#include "utils/files.h"
#include "revision.h"
#include "utils/accounts.h"
struct _RingClientClass
{
......@@ -225,6 +226,11 @@ ring_client_startup(GApplication *app)
/* FIXME: put in smart pointer? */
new PixbufDelegate();
/* make sure all RING accounts have a display name... this basically makes sure
* that all accounts created before the display name patch have a display name
* set... a bit of a hack as this should maybe be done in LRC */
force_ring_display_name();
/* make sure basic number categories exist, in case user has no contacts
* from which these would be automatically created
*/
......
......@@ -61,6 +61,7 @@
#include "utils/models.h"
#include "generalsettingsview.h"
#include "callsview.h"
#include "utils/accounts.h"
#define CALL_VIEW_NAME "calls"
#define CREATE_ACCOUNT_1_VIEW_NAME "create1"
......@@ -484,21 +485,6 @@ show_general_settings(GtkToggleButton *navbutton, RingMainWindow *win)
}
}
static gboolean
has_ring_account()
{
/* check if a Ring account exists */
int a_count = AccountModel::instance()->rowCount();
for (int i = 0; i < a_count; ++i) {
QModelIndex idx = AccountModel::instance()->index(i, 0);
QVariant protocol = idx.data(static_cast<int>(Account::Role::Proto));
if ((Account::Protocol)protocol.toUInt() == Account::Protocol::RING)
return TRUE;
}
return FALSE;
}
static gboolean
create_ring_account(RingMainWindow *win)
{
......@@ -508,6 +494,7 @@ create_ring_account(RingMainWindow *win)
/* create account and set UPnP enabled, as its not by default in the daemon */
const gchar *alias = gtk_entry_get_text(GTK_ENTRY(priv->entry_alias));
Account *account = AccountModel::instance()->add(alias, Account::Protocol::RING);
account->setDisplayName(alias); // set the display name to the same as the alias
account->setUpnpEnabled(TRUE);
/* wait for hash to be generated to show the next view */
......
/*
* Copyright (C) 2015 Savoir-faire Linux Inc.
* Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include "accounts.h"
#include <accountmodel.h>
/**
* returns TRUE if a RING account exists; FALSE otherwise
*/
gboolean
has_ring_account()
{
return !AccountModel::instance()->getAccountsByProtocol(Account::Protocol::RING).isEmpty();
}
/**
* itterates through all existing accounts and make sure all RING accounts have
* a display name set; if a display name is empty, it is set to the alias of the
* account
*/
void
force_ring_display_name()
{
auto ringaccounts = AccountModel::instance()->getAccountsByProtocol(Account::Protocol::RING);
for (int i = 0; i < ringaccounts.size(); ++i) {
auto account = ringaccounts.at(i);
if (account->displayName().isEmpty()) {
g_debug("updating RING account display name to: %s", account->alias().toUtf8().constData());
account->setDisplayName(account->alias());
account << Account::EditAction::SAVE;
}
}
}
/*
* Copyright (C) 2015 Savoir-faire Linux Inc.
* Author: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef _ACCOUNTS_H
#define _ACCOUNTS_H
#include <gtk/gtk.h>
/**
* returns TRUE if a RING account exists; FALSE otherwise
*/
gboolean
has_ring_account();
/**
* itterates through all existing accounts and make sure all RING accounts have
* a display name set; if a display name is empty, it is set to the alias of the
* account
*/
void
force_ring_display_name();
#endif /* _ACCOUNTS_H */
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