summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-09-22 22:26:35 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-09-22 22:26:35 +0300
commite3321caf2042aa1c539222ceb4998a9bc9926676 (patch)
treecde42b90c7ccffe9a83bd23d37da40933a4bca83
parent46d9640d6255be95f73a9fbc89f50c702928a241 (diff)
Jabber: major code cleaning for the vcard editing dialogs
-rw-r--r--protocols/JabberG/res/jabber.rc20
-rw-r--r--protocols/JabberG/src/jabber_proto.h1
-rw-r--r--protocols/JabberG/src/jabber_vcard.cpp254
-rw-r--r--protocols/JabberG/src/resource.h2
4 files changed, 137 insertions, 140 deletions
diff --git a/protocols/JabberG/res/jabber.rc b/protocols/JabberG/res/jabber.rc
index 63f0272ae6..034d758c03 100644
--- a/protocols/JabberG/res/jabber.rc
+++ b/protocols/JabberG/res/jabber.rc
@@ -218,7 +218,7 @@ BEGIN
LTEXT "ZIP:",IDC_STATIC,5,63,59,8
EDITTEXT IDC_ZIP,67,61,58,12,ES_AUTOHSCROLL
LTEXT "Country:",IDC_STATIC,5,77,59,8
- COMBOBOX IDC_COUNTRY,67,75,91,172,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
+ COMBOBOX IDC_COUNTRY,67,75,91,172,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
END
IDD_VCARD_PERSONAL DIALOGEX 0, 0, 222, 132
@@ -240,7 +240,7 @@ BEGIN
EDITTEXT IDC_BIRTH,58,61,62,12,ES_AUTOHSCROLL
LTEXT "YYYY-MM-DD",IDC_STATIC,124,63,90,8
LTEXT "Gender:",IDC_STATIC,5,77,51,8
- COMBOBOX IDC_GENDER,58,75,62,52,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
+ COMBOBOX IDC_GENDER,58,75,62,52,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Occupation:",IDC_STATIC,5,90,51,8
EDITTEXT IDC_OCCUPATION,58,89,159,12,ES_AUTOHSCROLL
LTEXT "Homepage:",IDC_STATIC,6,104,51,8
@@ -269,7 +269,7 @@ BEGIN
LTEXT "ZIP:",IDC_STATIC,5,103,60,8
EDITTEXT IDC_ZIP,67,101,58,12,ES_AUTOHSCROLL
LTEXT "Country:",IDC_STATIC,5,116,60,8
- COMBOBOX IDC_COUNTRY,67,115,91,172,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
+ COMBOBOX IDC_COUNTRY,67,115,91,172,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
END
IDD_VCARD_CONTACT DIALOGEX 0, 0, 222, 132
@@ -669,7 +669,7 @@ BEGIN
END
IDD_CONSOLE DIALOGEX 0, 0, 354, 225
-STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_CLIPCHILDREN
+STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_CONTROLPARENT
CAPTION "XML Console"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
@@ -748,6 +748,18 @@ BEGIN
HORZGUIDE, 56
END
+ IDD_VCARD_HOME, DIALOG
+ BEGIN
+ END
+
+ IDD_VCARD_PERSONAL, DIALOG
+ BEGIN
+ END
+
+ IDD_VCARD_WORK, DIALOG
+ BEGIN
+ END
+
IDD_INFO_OMEMO, DIALOG
BEGIN
BOTTOMMARGIN, 149
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index 0df9ff5ffc..48c2316d3b 100644
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -892,7 +892,6 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
void AppendVcardFromDB(TiXmlElement *n, char* tag, char* key);
void AppendPhotoToVcard(TiXmlElement *n, bool bPhotoChanged, const wchar_t *szPhotoFileName, MCONTACT hContact = 0);
void SetServerVcard(bool bPhotoChanged, wchar_t* szPhotoFileName);
- void SaveVcardToDB(HWND hwndPage, int iPage);
//---- jabber_voip.c -----------------------------------------------------------------
diff --git a/protocols/JabberG/src/jabber_vcard.cpp b/protocols/JabberG/src/jabber_vcard.cpp
index fea9f7b7e9..0d722aac37 100644
--- a/protocols/JabberG/src/jabber_vcard.cpp
+++ b/protocols/JabberG/src/jabber_vcard.cpp
@@ -58,15 +58,6 @@ int CJabberProto::SendGetVcard(MCONTACT hContact)
/////////////////////////////////////////////////////////////////////////////////////////
-static void SetDialogField(CJabberProto *ppro, HWND hwndDlg, int nDlgItem, char *key, bool bTranslate = false)
-{
- ptrW tszValue(ppro->getWStringA(key));
- if (tszValue != nullptr)
- SetDlgItemText(hwndDlg, nDlgItem, (bTranslate) ? TranslateW(tszValue) : tszValue);
- else
- SetDlgItemTextA(hwndDlg, nDlgItem, "");
-}
-
class JabberVcardBaseDlg : public CUserInfoPageDlg
{
int iPageId;
@@ -74,6 +65,22 @@ class JabberVcardBaseDlg : public CUserInfoPageDlg
protected:
CJabberProto *ppro;
+ void SetDialogField(int nDlgItem, char *key)
+ {
+ ptrW tszValue(ppro->getWStringA(key));
+ if (tszValue != nullptr)
+ SetDlgItemText(m_hwnd, nDlgItem, tszValue);
+ else
+ SetDlgItemTextA(m_hwnd, nDlgItem, "");
+ }
+
+ void SaveDialogField(int nDlgItem, char *key)
+ {
+ wchar_t text[2048];
+ GetDlgItemText(m_hwnd, nDlgItem, text, _countof(text));
+ ppro->setWString(key, text);
+ }
+
public:
JabberVcardBaseDlg(CJabberProto *_ppro, int dlgId, int pageId) :
CUserInfoPageDlg(g_plugin, dlgId),
@@ -83,14 +90,13 @@ public:
bool OnInitDialog() override
{
+ ppro->m_vCardUpdates |= (1UL << iPageId);
ppro->WindowSubscribe(m_hwnd);
return true;
}
bool OnApply() override
{
- ppro->SaveVcardToDB(m_hwnd, iPageId);
-
ppro->m_vCardUpdates &= ~(1UL << iPageId);
if (!ppro->m_vCardUpdates)
ppro->SetServerVcard(ppro->m_bPhotoChanged, ppro->m_szPhotoFileName);
@@ -113,25 +119,47 @@ struct JabberVcardPersonalDlg : public JabberVcardBaseDlg
bool OnInitDialog() override
{
- JabberVcardBaseDlg::OnInitDialog();
SendDlgItemMessage(m_hwnd, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)TranslateT("Male"));
SendDlgItemMessage(m_hwnd, IDC_GENDER, CB_ADDSTRING, 0, (LPARAM)TranslateT("Female"));
- return true;
+
+ return JabberVcardBaseDlg::OnInitDialog();
}
bool OnRefresh() override
{
- SetDialogField(ppro, m_hwnd, IDC_FULLNAME, "FullName");
- SetDialogField(ppro, m_hwnd, IDC_NICKNAME, "Nick");
- SetDialogField(ppro, m_hwnd, IDC_FIRSTNAME, "FirstName");
- SetDialogField(ppro, m_hwnd, IDC_MIDDLE, "MiddleName");
- SetDialogField(ppro, m_hwnd, IDC_LASTNAME, "LastName");
- SetDialogField(ppro, m_hwnd, IDC_BIRTH, "BirthDate");
- SetDialogField(ppro, m_hwnd, IDC_GENDER, "GenderString", true);
- SetDialogField(ppro, m_hwnd, IDC_OCCUPATION, "Role");
- SetDialogField(ppro, m_hwnd, IDC_HOMEPAGE, "Homepage");
+ SetDialogField(IDC_FULLNAME, "FullName");
+ SetDialogField(IDC_NICKNAME, "Nick");
+ SetDialogField(IDC_FIRSTNAME, "FirstName");
+ SetDialogField(IDC_MIDDLE, "MiddleName");
+ SetDialogField(IDC_LASTNAME, "LastName");
+ SetDialogField(IDC_BIRTH, "BirthDate");
+ SetDialogField(IDC_OCCUPATION, "Role");
+ SetDialogField(IDC_HOMEPAGE, "Homepage");
+
+ CMStringW wszGender(ppro->getMStringW("GenderString"));
+ SendDlgItemMessage(m_hwnd, IDC_GENDER, CB_SELECTSTRING, -1, LPARAM(TranslateW(wszGender.c_str())));
return false;
}
+
+ bool OnApply() override
+ {
+ SaveDialogField(IDC_FULLNAME, "FullName");
+ SaveDialogField(IDC_NICKNAME, "Nick");
+ SaveDialogField(IDC_FIRSTNAME, "FirstName");
+ SaveDialogField(IDC_MIDDLE, "MiddleName");
+ SaveDialogField(IDC_LASTNAME, "LastName");
+ SaveDialogField(IDC_BIRTH, "BirthDate");
+ SaveDialogField(IDC_OCCUPATION, "Role");
+ SaveDialogField(IDC_HOMEPAGE, "Homepage");
+
+ switch (SendDlgItemMessage(m_hwnd, IDC_GENDER, CB_GETCURSEL, 0, 0)) {
+ case 0: ppro->setString("GenderString", "Male"); break;
+ case 1: ppro->setString("GenderString", "Female"); break;
+ default: ppro->setString("GenderString", ""); break;
+ }
+
+ return JabberVcardBaseDlg::OnApply();
+ }
};
/////////////////////////////////////////////////////////////////////////////////////////
@@ -146,7 +174,6 @@ struct JabberVcardHomeDlg : public JabberVcardBaseDlg
bool OnInitDialog() override
{
- JabberVcardBaseDlg::OnInitDialog();
for (int i = 0; i < g_cbCountries; i++) {
if (g_countries[i].id != 0xFFFF && g_countries[i].id != 0) {
wchar_t *country = mir_a2u(g_countries[i].szName);
@@ -154,19 +181,38 @@ struct JabberVcardHomeDlg : public JabberVcardBaseDlg
mir_free(country);
}
}
- return true;
+
+ return JabberVcardBaseDlg::OnInitDialog();
}
bool OnRefresh() override
{
- SetDialogField(ppro, m_hwnd, IDC_ADDRESS1, "Street");
- SetDialogField(ppro, m_hwnd, IDC_ADDRESS2, "Street2");
- SetDialogField(ppro, m_hwnd, IDC_CITY, "City");
- SetDialogField(ppro, m_hwnd, IDC_STATE, "State");
- SetDialogField(ppro, m_hwnd, IDC_ZIP, "ZIP");
- SetDialogField(ppro, m_hwnd, IDC_COUNTRY, "Country", true);
+ SetDialogField(IDC_ADDRESS1, "Street");
+ SetDialogField(IDC_ADDRESS2, "Street2");
+ SetDialogField(IDC_CITY, "City");
+ SetDialogField(IDC_STATE, "State");
+ SetDialogField(IDC_ZIP, "ZIP");
+
+ CMStringW buf(ppro->getMStringW("Country"));
+ SendDlgItemMessage(m_hwnd, IDC_COUNTRY, CB_SELECTSTRING, -1, LPARAM(TranslateW(buf.c_str())));
return false;
}
+
+ bool OnApply() override
+ {
+ SaveDialogField(IDC_ADDRESS1, "Street");
+ SaveDialogField(IDC_ADDRESS2, "Street2");
+ SaveDialogField(IDC_CITY, "City");
+ SaveDialogField(IDC_STATE, "State");
+ SaveDialogField(IDC_ZIP, "ZIP");
+
+ int i = SendDlgItemMessage(m_hwnd, IDC_COUNTRY, CB_GETCURSEL, 0, 0);
+ wchar_t *country = mir_a2u((i) ? g_countries[i + 2].szName : g_countries[1].szName);
+ ppro->setWString("Country", country);
+ mir_free(country);
+
+ return JabberVcardBaseDlg::OnApply();
+ }
};
/////////////////////////////////////////////////////////////////////////////////////////
@@ -181,8 +227,6 @@ struct JabberVcardWorkDlg : public JabberVcardBaseDlg
bool OnInitDialog() override
{
- JabberVcardBaseDlg::OnInitDialog();
-
for (int i = 0; i < g_cbCountries; i++) {
if (g_countries[i].id != 0xFFFF && g_countries[i].id != 0) {
wchar_t *country = mir_a2u(g_countries[i].szName);
@@ -190,22 +234,44 @@ struct JabberVcardWorkDlg : public JabberVcardBaseDlg
mir_free(country);
}
}
- return true;
+
+ return JabberVcardBaseDlg::OnInitDialog();
}
bool OnRefresh() override
{
- SetDialogField(ppro, m_hwnd, IDC_COMPANY, "Company");
- SetDialogField(ppro, m_hwnd, IDC_DEPARTMENT, "CompanyDepartment");
- SetDialogField(ppro, m_hwnd, IDC_TITLE, "CompanyPosition");
- SetDialogField(ppro, m_hwnd, IDC_ADDRESS1, "CompanyStreet");
- SetDialogField(ppro, m_hwnd, IDC_ADDRESS2, "CompanyStreet2");
- SetDialogField(ppro, m_hwnd, IDC_CITY, "CompanyCity");
- SetDialogField(ppro, m_hwnd, IDC_STATE, "CompanyState");
- SetDialogField(ppro, m_hwnd, IDC_ZIP, "CompanyZIP");
- SetDialogField(ppro, m_hwnd, IDC_COUNTRY, "CompanyCountry", true);
+ SetDialogField(IDC_COMPANY, "Company");
+ SetDialogField(IDC_DEPARTMENT, "CompanyDepartment");
+ SetDialogField(IDC_TITLE, "CompanyPosition");
+ SetDialogField(IDC_ADDRESS1, "CompanyStreet");
+ SetDialogField(IDC_ADDRESS2, "CompanyStreet2");
+ SetDialogField(IDC_CITY, "CompanyCity");
+ SetDialogField(IDC_STATE, "CompanyState");
+ SetDialogField(IDC_ZIP, "CompanyZIP");
+
+ CMStringW buf(ppro->getMStringW("CompanyCountry"));
+ SendDlgItemMessage(m_hwnd, IDC_COUNTRY, CB_SELECTSTRING, -1, LPARAM(TranslateW(buf.c_str())));
return false;
}
+
+ bool OnApply() override
+ {
+ SaveDialogField(IDC_COMPANY, "Company");
+ SaveDialogField(IDC_DEPARTMENT, "CompanyDepartment");
+ SaveDialogField(IDC_TITLE, "CompanyPosition");
+ SaveDialogField(IDC_ADDRESS1, "CompanyStreet");
+ SaveDialogField(IDC_ADDRESS2, "CompanyStreet2");
+ SaveDialogField(IDC_CITY, "CompanyCity");
+ SaveDialogField(IDC_STATE, "CompanyState");
+ SaveDialogField(IDC_ZIP, "CompanyZIP");
+
+ int i = SendDlgItemMessage(m_hwnd, IDC_COUNTRY, CB_GETCURSEL, 0, 0);
+ wchar_t *country = mir_a2u((i) ? g_countries[i + 2].szName : g_countries[1].szName);
+ ppro->setWString("CompanyCountry", country);
+ mir_free(country);
+
+ return JabberVcardBaseDlg::OnApply();
+ }
};
/////////////////////////////////////////////////////////////////////////////////////////
@@ -232,12 +298,10 @@ public:
bool OnInitDialog() override
{
- JabberVcardBaseDlg::OnInitDialog();
-
ShowWindow(GetDlgItem(m_hwnd, IDC_SAVE), SW_HIDE);
-
ppro->m_bPhotoChanged = false;
- return true;
+
+ return JabberVcardBaseDlg::OnInitDialog();
}
void OnDestroy() override
@@ -433,9 +497,16 @@ struct JabberVcardNoteDlg : public JabberVcardBaseDlg
bool OnRefresh() override
{
- SetDialogField(ppro, m_hwnd, IDC_DESC, "About");
+ SetDialogField(IDC_DESC, "About");
return false;
}
+
+ bool OnApply() override
+ {
+ SaveDialogField(IDC_DESC, "About");
+
+ return JabberVcardBaseDlg::OnApply();
+ }
};
/////////////////////////////////////////////////////////////////////////////////////////
@@ -606,8 +677,6 @@ public:
bool OnInitDialog() override
{
- JabberVcardBaseDlg::OnInitDialog();
-
RECT rc;
GetClientRect(emails.GetHwnd(), &rc);
rc.right -= GetSystemMetrics(SM_CXVSCROLL);
@@ -625,7 +694,8 @@ public:
emails.InsertColumn(3, &lvc);
phones.InsertColumn(2, &lvc);
phones.InsertColumn(3, &lvc);
- return true;
+
+ return JabberVcardBaseDlg::OnInitDialog();
}
bool OnRefresh() override
@@ -787,90 +857,6 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////
-void CJabberProto::SaveVcardToDB(HWND hwndPage, int iPage)
-{
- wchar_t text[2048];
-
- // Page 0: Personal
- switch (iPage) {
- case 0:
- GetDlgItemText(hwndPage, IDC_FULLNAME, text, _countof(text));
- setWString("FullName", text);
- GetDlgItemText(hwndPage, IDC_NICKNAME, text, _countof(text));
- setWString("Nick", text);
- GetDlgItemText(hwndPage, IDC_FIRSTNAME, text, _countof(text));
- setWString("FirstName", text);
- GetDlgItemText(hwndPage, IDC_MIDDLE, text, _countof(text));
- setWString("MiddleName", text);
- GetDlgItemText(hwndPage, IDC_LASTNAME, text, _countof(text));
- setWString("LastName", text);
- GetDlgItemText(hwndPage, IDC_BIRTH, text, _countof(text));
- setWString("BirthDate", text);
- switch (SendDlgItemMessage(hwndPage, IDC_GENDER, CB_GETCURSEL, 0, 0)) {
- case 0: setString("GenderString", "Male"); break;
- case 1: setString("GenderString", "Female"); break;
- default: setString("GenderString", ""); break;
- }
- GetDlgItemText(hwndPage, IDC_OCCUPATION, text, _countof(text));
- setWString("Role", text);
- GetDlgItemText(hwndPage, IDC_HOMEPAGE, text, _countof(text));
- setWString("Homepage", text);
- break;
-
- case 1: // Page 1: Home
- GetDlgItemText(hwndPage, IDC_ADDRESS1, text, _countof(text));
- setWString("Street", text);
- GetDlgItemText(hwndPage, IDC_ADDRESS2, text, _countof(text));
- setWString("Street2", text);
- GetDlgItemText(hwndPage, IDC_CITY, text, _countof(text));
- setWString("City", text);
- GetDlgItemText(hwndPage, IDC_STATE, text, _countof(text));
- setWString("State", text);
- GetDlgItemText(hwndPage, IDC_ZIP, text, _countof(text));
- setWString("ZIP", text);
- {
- int i = SendDlgItemMessage(hwndPage, IDC_COUNTRY, CB_GETCURSEL, 0, 0);
- wchar_t *country = mir_a2u((i) ? g_countries[i + 2].szName : g_countries[1].szName);
- setWString("Country", country);
- mir_free(country);
- }
- break;
-
- case 2: // Page 2: Work
- GetDlgItemText(hwndPage, IDC_COMPANY, text, _countof(text));
- setWString("Company", text);
- GetDlgItemText(hwndPage, IDC_DEPARTMENT, text, _countof(text));
- setWString("CompanyDepartment", text);
- GetDlgItemText(hwndPage, IDC_TITLE, text, _countof(text));
- setWString("CompanyPosition", text);
- GetDlgItemText(hwndPage, IDC_ADDRESS1, text, _countof(text));
- setWString("CompanyStreet", text);
- GetDlgItemText(hwndPage, IDC_ADDRESS2, text, _countof(text));
- setWString("CompanyStreet2", text);
- GetDlgItemText(hwndPage, IDC_CITY, text, _countof(text));
- setWString("CompanyCity", text);
- GetDlgItemText(hwndPage, IDC_STATE, text, _countof(text));
- setWString("CompanyState", text);
- GetDlgItemText(hwndPage, IDC_ZIP, text, _countof(text));
- setWString("CompanyZIP", text);
- {
- int i = SendDlgItemMessage(hwndPage, IDC_COUNTRY, CB_GETCURSEL, 0, 0);
- wchar_t *country = mir_a2u((i) ? g_countries[i + 2].szName : g_countries[1].szName);
- setWString("CompanyCountry", country);
- mir_free(country);
- }
- break;
-
- // Page 3: Photo
- // not needed to be saved into db
-
- case 4: // Page 4: Note
- GetDlgItemText(hwndPage, IDC_DESC, text, _countof(text));
- setWString("About", text);
- break;
- }
-}
-
void CJabberProto::AppendVcardFromDB(TiXmlElement *n, char *tag, char *key)
{
if (n == nullptr || tag == nullptr || key == nullptr)
diff --git a/protocols/JabberG/src/resource.h b/protocols/JabberG/src/resource.h
index 76b592d449..9ea9e91990 100644
--- a/protocols/JabberG/src/resource.h
+++ b/protocols/JabberG/src/resource.h
@@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by C:\Users\georg\DiskW\miranda-ng\protocols\JabberG\res\jabber.rc
+// Used by W:\miranda-ng\protocols\JabberG\res\jabber.rc
//
#define IDD_OPT_JABBER 101
#define IDI_JABBER 102