Simplify user name option GUI: Just a single "name" field
See https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/
And it makes the code simpler. Win-win.
It is just a single full name that is stored in ODF and OOXML anyway.
Take care of migrating separate given names, father's names and
surnames from older user profiles if modifying the data. Handle the
"Eastern" (as the code calls it) case, too.
Change-Id: Iebf59f224995f722669f844d03053a55c088bc6e
diff --git a/cui/source/inc/cuioptgenrl.hxx b/cui/source/inc/cuioptgenrl.hxx
index 0b93ebd..ee5cf82 100644
--- a/cui/source/inc/cuioptgenrl.hxx
+++ b/cui/source/inc/cuioptgenrl.hxx
@@ -47,7 +47,6 @@ private:
struct Field;
std::vector<std::shared_ptr<Field> > vFields;
// "name" fields
unsigned nNameRow;
unsigned nShortNameField;
DECL_LINK_TYPED( ModifyHdl_Impl, Edit&, void );
diff --git a/cui/source/options/optgenrl.cxx b/cui/source/options/optgenrl.cxx
index 33b7624..bccdb88 100644
--- a/cui/source/options/optgenrl.cxx
+++ b/cui/source/options/optgenrl.cxx
@@ -41,8 +41,6 @@ enum RowType
{
Row_Company,
Row_Name,
Row_Name_Russian,
Row_Name_Eastern,
Row_Street,
Row_Street_Russian,
Row_City,
@@ -60,7 +58,6 @@ namespace Lang
{
unsigned const Others = 1;
unsigned const Russian = 2;
unsigned const Eastern = 4;
unsigned const US = 8;
unsigned const All = static_cast<unsigned>(-1);
}
@@ -80,9 +77,7 @@ struct
const vRowInfo[] =
{
{ "companyft", Lang::All },
{ "nameft", Lang::All & ~Lang::Russian & ~Lang::Eastern },
{ "rusnameft", Lang::Russian },
{ "eastnameft", Lang::Eastern },
{ "nameft", Lang::All },
{ "streetft", Lang::All & ~Lang::Russian },
{ "russtreetft", Lang::Russian },
{ "icityft", Lang::All & ~Lang::US },
@@ -113,18 +108,8 @@ const vFieldInfo[] =
// Company
{ Row_Company, "company", UserOptToken::Company, EditPosition::COMPANY },
// Name
{ Row_Name, "firstname", UserOptToken::FirstName, EditPosition::FIRSTNAME },
{ Row_Name, "lastname", UserOptToken::LastName, EditPosition::LASTNAME },
{ Row_Name, "shortname", UserOptToken::ID, EditPosition::SHORTNAME },
// Name (russian)
{ Row_Name_Russian, "ruslastname", UserOptToken::LastName, EditPosition::LASTNAME },
{ Row_Name_Russian, "rusfirstname", UserOptToken::FirstName, EditPosition::FIRSTNAME },
{ Row_Name_Russian, "rusfathersname", UserOptToken::FathersName, EditPosition::UNKNOWN },
{ Row_Name_Russian, "russhortname", UserOptToken::ID, EditPosition::SHORTNAME },
// Name (eastern: reversed name ord
{ Row_Name_Eastern, "eastlastname", UserOptToken::LastName, EditPosition::LASTNAME },
{ Row_Name_Eastern, "eastfirstname", UserOptToken::FirstName, EditPosition::FIRSTNAME },
{ Row_Name_Eastern, "eastshortname", UserOptToken::ID, EditPosition::SHORTNAME },
// Street
{ Row_Street, "street", UserOptToken::Street, EditPosition::STREET },
// Street (russian)
@@ -235,10 +220,7 @@ void SvxGeneralTabPage::InitControls ()
LangBit = Lang::Russian;
break;
default:
if (MsLangId::isFamilyNameFirst(eLang))
LangBit = Lang::Eastern;
else
LangBit = Lang::Others;
LangBit = Lang::Others;
break;
}
@@ -269,7 +251,6 @@ void SvxGeneralTabPage::InitControls ()
// "short name" field?
if (vFieldInfo[iField].nUserOptionsId == UserOptToken::ID)
{
nNameRow = vRows.size() - 1;
nShortNameField = vFields.size() - 1;
}
}
@@ -282,7 +263,7 @@ void SvxGeneralTabPage::SetLinks ()
{
// link for updating the initials
Link<Edit&,void> aLink = LINK( this, SvxGeneralTabPage, ModifyHdl_Impl );
Row& rNameRow = *vRows[nNameRow];
Row& rNameRow = *vRows[Row_Name];
for (unsigned i = rNameRow.nFirstField; i != rNameRow.nLastField - 1; ++i)
vFields[i]->pEdit->SetModifyHdl(aLink);
}
@@ -335,36 +316,22 @@ void SvxGeneralTabPage::Reset( const SfxItemSet* rSet )
// ModifyHdl_Impl()
// This handler updates the initials (short name)
// when one of the name fields was updated.
// when the name field was updated.
IMPL_LINK_TYPED( SvxGeneralTabPage, ModifyHdl_Impl, Edit&, rEdit, void )
{
// short name field and row
Field& rShortName = *vFields[nShortNameField];
Row& rNameRow = *vRows[nNameRow];
// number of initials
unsigned const nInits = rNameRow.nLastField - rNameRow.nFirstField - 1;
// which field was updated? (in rNameRow)
unsigned nField = nInits;
for (unsigned i = 0; i != nInits; ++i)
if (rShortName.pEdit->IsEnabled())
{
if (vFields[rNameRow.nFirstField + i]->pEdit == &rEdit)
nField = i;
}
// updating the initial
if (nField < nInits && rShortName.pEdit->IsEnabled())
{
OUString sShortName = rShortName.pEdit->GetText();
// clear short name if it contains more characters than the number of initials
if ((unsigned)sShortName.getLength() > nInits)
{
rShortName.pEdit->SetText(OUString());
}
while ((unsigned)sShortName.getLength() < nInits)
sShortName += " ";
sal_Int32 nIndex = 0;
OUString sName = rEdit.GetText();
OUString sLetter = sName.isEmpty()
? OUString(sal_Unicode(' ')) : sName.copy(0, 1);
rShortName.pEdit->SetText(sShortName.replaceAt(nField, 1, sLetter).trim());
OUString sShortName;
do {
OUString sToken = sName.getToken(0, ' ', nIndex);
if (!sToken.isEmpty())
sShortName += sToken.copy(0, 1);
} while (nIndex != -1);
rShortName.pEdit->SetText(sShortName);
}
}
@@ -374,10 +341,18 @@ bool SvxGeneralTabPage::GetData_Impl()
// updating
SvtUserOptions aUserOpt;
for (unsigned i = 0; i != vFields.size(); ++i)
{
aUserOpt.SetToken(
vFieldInfo[vFields[i]->iField].nUserOptionsId,
vFields[i]->pEdit->GetText()
);
// Blank out first name and father's name which aren't kept separately any longer
if (vFieldInfo[vFields[i]->iField].nUserOptionsId == UserOptToken::LastName)
{
aUserOpt.SetToken(UserOptToken::FirstName, "");
aUserOpt.SetToken(UserOptToken::FathersName, "");
}
}
// modified?
for (unsigned i = 0; i != vFields.size(); ++i)
@@ -401,7 +376,40 @@ void SvxGeneralTabPage::SetData_Impl()
Field& rField = *vFields[iField];
// updating content
UserOptToken const nToken = vFieldInfo[rField.iField].nUserOptionsId;
rField.pEdit->SetText(aUserOpt.GetToken(nToken));
if (nToken == UserOptToken::LastName)
{
// When using old-style data (with separated name), if
// "family name" comes first in the locale, use that
// order. If Russian, use also father's name if
// present.
OUString sName;
if (MsLangId::isFamilyNameFirst(Application::GetSettings().GetUILanguageTag().getLanguageType()))
{
sName += aUserOpt.GetToken(UserOptToken::LastName);
OUString sFirstName = aUserOpt.GetToken(UserOptToken::FirstName);
if (!sName.isEmpty() && !sFirstName.isEmpty())
sName += " ";
sName += sFirstName;
}
else
{
sName += aUserOpt.GetToken(UserOptToken::FirstName);
OUString sFathersName;
if (Application::GetSettings().GetUILanguageTag().getLanguageType() == LANGUAGE_RUSSIAN)
sFathersName = aUserOpt.GetToken(UserOptToken::FathersName);
if (!sName.isEmpty() && !sFathersName.isEmpty())
sName += " ";
sName += sFathersName;
OUString sLastName = aUserOpt.GetToken(UserOptToken::LastName);
if (!sName.isEmpty() && !sLastName.isEmpty())
sName += " ";
sName += sLastName;
}
rField.pEdit->SetText(sName);
}
else
rField.pEdit->SetText(aUserOpt.GetToken(nToken));
// is enabled?
bool const bEnableEdit = !aUserOpt.IsTokenReadonly(nToken);
rField.pEdit->Enable(bEnableEdit);
diff --git a/cui/uiconfig/ui/optuserpage.ui b/cui/uiconfig/ui/optuserpage.ui
index 93a7db4..009ec6e 100644
--- a/cui/uiconfig/ui/optuserpage.ui
+++ b/cui/uiconfig/ui/optuserpage.ui
@@ -39,9 +39,9 @@
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="halign">end</property>
<property name="label" translatable="yes">First/last _name/initials:</property>
<property name="label" translatable="yes">Name/initials:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">firstname</property>
<property name="mnemonic_widget">lastname</property>
</object>
<packing>
<property name="left_attach">0</property>
@@ -143,24 +143,6 @@
<property name="no_show_all">True</property>
<property name="column_spacing">6</property>
<child>
<object class="GtkEntry" id="firstname">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="invisible_char">•</property>
<child internal-child="accessible">
<object class="AtkObject" id="firstname-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">First name</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="lastname">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
@@ -169,12 +151,12 @@
<property name="invisible_char">•</property>
<child internal-child="accessible">
<object class="AtkObject" id="lastname-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Last name</property>
<property name="AtkObject::accessible-name" translatable="yes">Name</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
@@ -192,7 +174,7 @@
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
@@ -425,182 +407,6 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="rusnameft">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Last name/first _name/father’s name/initials:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">ruslastname</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid8">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="column_spacing">6</property>
<child>
<object class="GtkEntry" id="ruslastname">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="invisible_char">•</property>
<child internal-child="accessible">
<object class="AtkObject" id="ruslastname-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Last name</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="rusfathersname">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="invisible_char">•</property>
<child internal-child="accessible">
<object class="AtkObject" id="rusfathersname-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Father's name</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="russhortname">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
<property name="valign">center</property>
<property name="invisible_char">•</property>
<property name="width_chars">7</property>
<child internal-child="accessible">
<object class="AtkObject" id="russhortname-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Initials</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="rusfirstname">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="invisible_char">•</property>
<child internal-child="accessible">
<object class="AtkObject" id="rusfirstname-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">First name</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="eastnameft">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Last/first _name/initials:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">eastlastname</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid9">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="column_spacing">6</property>
<child>
<object class="GtkEntry" id="eastlastname">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="invisible_char">•</property>
<child internal-child="accessible">
<object class="AtkObject" id="eastlastname-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Last name</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="eastfirstname">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
<property name="valign">center</property>
<property name="hexpand">True</property>
<property name="invisible_char">•</property>
<child internal-child="accessible">
<object class="AtkObject" id="eastfirstname-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">First name</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="eastshortname">
<property name="can_focus">True</property>
<property name="no_show_all">True</property>
<property name="valign">center</property>
<property name="invisible_char">•</property>
<property name="width_chars">7</property>
<child internal-child="accessible">
<object class="AtkObject" id="eastshortname-atkobject">
<property name="AtkObject::accessible-name" translatable="yes">Initials</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="russtreetft">
<property name="can_focus">False</property>
<property name="no_show_all">True</property>