diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Telegram/Telegram.vcxproj | 1 | ||||
-rw-r--r-- | protocols/Telegram/Telegram.vcxproj.filters | 3 | ||||
-rw-r--r-- | protocols/Telegram/res/resource.rc | 28 | ||||
-rw-r--r-- | protocols/Telegram/src/add_phone.cpp | 96 | ||||
-rw-r--r-- | protocols/Telegram/src/options.cpp | 8 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.cpp | 17 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 11 | ||||
-rw-r--r-- | protocols/Telegram/src/resource.h | 7 | ||||
-rw-r--r-- | protocols/Telegram/src/stdafx.h | 1 |
9 files changed, 165 insertions, 7 deletions
diff --git a/protocols/Telegram/Telegram.vcxproj b/protocols/Telegram/Telegram.vcxproj index 6261b8acdf..e0fe0f08de 100644 --- a/protocols/Telegram/Telegram.vcxproj +++ b/protocols/Telegram/Telegram.vcxproj @@ -26,6 +26,7 @@ <Import Project="$(ProjectDir)..\..\build\vc.common\plugin.props" />
</ImportGroup>
<ItemGroup>
+ <ClCompile Include="src\add_phone.cpp" />
<ClCompile Include="src\auth.cpp" />
<ClCompile Include="src\avatars.cpp" />
<ClCompile Include="src\groupchat.cpp" />
diff --git a/protocols/Telegram/Telegram.vcxproj.filters b/protocols/Telegram/Telegram.vcxproj.filters index 948f34d1af..ee6b78ba70 100644 --- a/protocols/Telegram/Telegram.vcxproj.filters +++ b/protocols/Telegram/Telegram.vcxproj.filters @@ -26,6 +26,9 @@ <ClCompile Include="src\groupchat.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\add_phone.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\stdafx.cxx">
diff --git a/protocols/Telegram/res/resource.rc b/protocols/Telegram/res/resource.rc index 14b23f0c05..b27f08a877 100644 --- a/protocols/Telegram/res/resource.rc +++ b/protocols/Telegram/res/resource.rc @@ -111,6 +111,24 @@ BEGIN COMBOBOX IDC_STATUS2,221,61,81,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
END
+IDD_ADD_PHONE DIALOGEX 0, 0, 343, 99
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
+CAPTION "Add phone contact"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ LTEXT "First name:",IDC_STATIC,7,10,141,8
+ EDITTEXT IDC_FIRST_NAME,151,7,185,14,ES_AUTOHSCROLL
+ LTEXT "Last name:",IDC_STATIC,7,28,141,8
+ EDITTEXT IDC_LAST_NAME,151,25,185,14,ES_AUTOHSCROLL
+ LTEXT "Country:",IDC_STATIC,7,46,141,8
+ COMBOBOX IDC_COUNTRY,151,44,185,12,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+ LTEXT "Phone:",IDC_STATIC,7,65,141,8
+ RTEXT "",IDC_CODE,152,62,32,14,0,WS_EX_CLIENTEDGE
+ EDITTEXT IDC_PHONE,189,62,147,14,ES_AUTOHSCROLL
+ DEFPUSHBUTTON "OK",IDOK,230,85,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,284,85,50,14
+END
+
/////////////////////////////////////////////////////////////////////////////
//
@@ -139,6 +157,11 @@ BEGIN IDD_OPTIONS, DIALOG
BEGIN
END
+
+ IDD_ADD_PHONE, DIALOG
+ BEGIN
+ BOTTOMMARGIN, 84
+ END
END
#endif // APSTUDIO_INVOKED
@@ -158,6 +181,11 @@ BEGIN 0
END
+IDD_ADD_PHONE AFX_DIALOG_LAYOUT
+BEGIN
+ 0
+END
+
#endif // English (Neutral) resources
/////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Telegram/src/add_phone.cpp b/protocols/Telegram/src/add_phone.cpp new file mode 100644 index 0000000000..f2c0edf17d --- /dev/null +++ b/protocols/Telegram/src/add_phone.cpp @@ -0,0 +1,96 @@ +/* +Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org) + +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 version 2 +of the License. + +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, see <http://www.gnu.org/licenses/>. +*/ + +#include "stdafx.h" + +class CAddPhoneContactDlg : public CTelegramDlgBase +{ + CCtrlEdit edtFirstName, edtLastName, edtPhone; + CCtrlCombo cmbCountry; + CCtrlButton btnOk; + +public: + CAddPhoneContactDlg(CTelegramProto *ppro) : + CTelegramDlgBase(ppro, IDD_ADD_PHONE), + btnOk(this, IDOK), + edtPhone(this, IDC_PHONE), + cmbCountry(this, IDC_COUNTRY), + edtLastName(this, IDC_LAST_NAME), + edtFirstName(this, IDC_FIRST_NAME) + { + cmbCountry.OnChange = Callback(this, &CAddPhoneContactDlg::onChange_Country); + } + + bool OnInitDialog() override + { + int iCount; + CountryListEntry *pList; + CallService(MS_UTILS_GETCOUNTRYLIST, (WPARAM)&iCount, (LPARAM)&pList); + + for (int i = 0; i < iCount; i++) { + unsigned countryCode = pList[i].id; + int idx = cmbCountry.AddString(TranslateW(_A2T(pList[i].szName).get()), countryCode); + if (countryCode == m_proto->m_iCountry) + cmbCountry.SetCurSel(idx); + } + + onChange_Country(0); + return true; + } + + bool OnApply() override + { + CMStringW wszCountry(FORMAT, L"+%d%s", (int)cmbCountry.GetCurData(), ptrW(edtPhone.GetText()).get()); + + auto *cc = new TD::contact; + cc->first_name_ = T2Utf(ptrW(edtFirstName.GetText())); + cc->last_name_ = T2Utf(ptrW(edtLastName.GetText())); + cc->phone_number_ = T2Utf(wszCountry); + + TD::array<TD::object_ptr<TD::contact>> contacts; + contacts.push_back(TD::object_ptr<TD::contact>(cc)); + + m_proto->SendQuery(new TD::importContacts(std::move(contacts))); + return true; + } + + void OnChange() override + { + ptrW wszFirstName(edtFirstName.GetText()), wszPhone(edtPhone.GetText()); + btnOk.Enable(mir_wstrlen(wszFirstName) && mir_wstrlen(wszPhone) && cmbCountry.GetCurData() != 9999); + } + + void onChange_Country(CCtrlCombo *) + { + CMStringA buf; + switch (int iCode = cmbCountry.GetCurData()) { + case 9999: + case -1: + buf = "---"; + break; + default: + buf.Format("+%d", iCode); + } + SetDlgItemTextA(m_hwnd, IDC_CODE, buf); + } +}; + +INT_PTR CTelegramProto::AddByPhone(WPARAM, LPARAM) +{ + (new CAddPhoneContactDlg(this))->Show(); + return 0; +} diff --git a/protocols/Telegram/src/options.cpp b/protocols/Telegram/src/options.cpp index 6a9b917109..38946fac9f 100644 --- a/protocols/Telegram/src/options.cpp +++ b/protocols/Telegram/src/options.cpp @@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /////////////////////////////////////////////////////////////////////////////////////////
-class COptionsDlg : public CProtoDlgBase<CTelegramProto>
+class COptionsDlg : public CTelegramDlgBase
{
CCtrlCheck chkHideChats, chkUsePopups;
CCtrlCombo cmbCountry;
@@ -28,7 +28,7 @@ class COptionsDlg : public CProtoDlgBase<CTelegramProto> public:
COptionsDlg(CTelegramProto *ppro, int iDlgID, bool bFullDlg) :
- CProtoDlgBase<CTelegramProto>(ppro, iDlgID),
+ CTelegramDlgBase(ppro, iDlgID),
cmbCountry(this, IDC_COUNTRY),
chkUsePopups(this, IDC_POPUPS),
chkHideChats(this, IDC_HIDECHATS),
@@ -98,7 +98,7 @@ public: /////////////////////////////////////////////////////////////////////////////////////////
// Advanced options
-class CAdvOptionsDlg : public CProtoDlgBase<CTelegramProto>
+class CAdvOptionsDlg : public CTelegramDlgBase
{
CCtrlEdit edtDiff1, edtDiff2;
CCtrlSpin spin1, spin2;
@@ -106,7 +106,7 @@ class CAdvOptionsDlg : public CProtoDlgBase<CTelegramProto> public:
CAdvOptionsDlg(CTelegramProto *ppro) :
- CProtoDlgBase<CTelegramProto>(ppro, IDD_OPTIONS_ADV),
+ CTelegramDlgBase(ppro, IDD_OPTIONS_ADV),
spin1(this, IDC_SPIN1, 32000),
spin2(this, IDC_SPIN2, 32000),
edtDiff1(this, IDC_DIFF1),
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index b265ccea6c..dcf61279c1 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -146,6 +146,23 @@ void CTelegramProto::OnShutdown() m_bTerminated = true; } +///////////////////////////////////////////////////////////////////////////////////////// + +void CTelegramProto::OnBuildProtoMenu() +{ + CMenuItem mi(&g_plugin); + mi.root = Menu_GetProtocolRoot(this); + mi.flags = CMIF_UNMOVABLE; + + // Groups uploader + mi.pszService = "/UploadGroups"; + CreateProtoService(mi.pszService, &CTelegramProto::AddByPhone); + mi.name.a = LPGEN("Add phone contact"); + mi.position = 200001; + mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_ADDCONTACT); + Menu_AddProtoMenuItem(&mi, m_szModuleName); +} + void CTelegramProto::OnErase() { m_bUnregister = true; diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index f4635d44f6..8dd9ca1fa9 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -117,6 +117,8 @@ struct TG_BASIC_GROUP class CTelegramProto : public PROTO<CTelegramProto> { + friend class CAddPhoneContactDlg; + class CProtoImpl { friend class CTelegramProto; @@ -262,7 +264,8 @@ public: HANDLE SearchByName(const wchar_t *nick, const wchar_t *firstName, const wchar_t *lastName) override; int SendMsg(MCONTACT hContact, int flags, const char *pszMessage) override; int SetStatus(int iNewStatus) override; - + + void OnBuildProtoMenu() override; void OnContactDeleted(MCONTACT hContact) override; MWindow OnCreateAccMgrUI(MWindow hwndParent) override; void OnMarkRead(MCONTACT, MEVENT) override; @@ -277,6 +280,10 @@ public: int __cdecl GcMenuHook(WPARAM, LPARAM); int __cdecl GcEventHook(WPARAM, LPARAM); + // Services ////////////////////////////////////////////////////////////////////////// + + INT_PTR __cdecl AddByPhone(WPARAM, LPARAM); + // Options /////////////////////////////////////////////////////////////////////////// CMOption<uint32_t> m_iCountry; // set this status to m_iStatus1 after this interval of secs @@ -294,3 +301,5 @@ public: void __cdecl ServerThread(void *); }; + +typedef CProtoDlgBase<CTelegramProto> CTelegramDlgBase;
\ No newline at end of file diff --git a/protocols/Telegram/src/resource.h b/protocols/Telegram/src/resource.h index 5e63e34081..ad609319ce 100644 --- a/protocols/Telegram/src/resource.h +++ b/protocols/Telegram/src/resource.h @@ -7,6 +7,7 @@ #define IDD_OPTIONS 102
#define IDI_PREMIUM 103
#define IDD_OPTIONS_ADV 104
+#define IDD_ADD_PHONE 107
#define IDC_PHONE 1001
#define IDC_DEFGROUP 1002
#define IDC_HIDECHATS 1003
@@ -21,14 +22,16 @@ #define IDC_STATUS2 1011
#define IDC_COUNTRY 1012
#define IDC_CODE 1013
+#define IDC_FIRST_NAME 1014
+#define IDC_LAST_NAME 1015
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 106
+#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1014
+#define _APS_NEXT_CONTROL_VALUE 1016
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/protocols/Telegram/src/stdafx.h b/protocols/Telegram/src/stdafx.h index f2a60d704e..1e5a33925a 100644 --- a/protocols/Telegram/src/stdafx.h +++ b/protocols/Telegram/src/stdafx.h @@ -25,6 +25,7 @@ #include <m_netlib.h>
#include <m_options.h>
#include <m_popup.h>
+#include <m_skin.h>
#include <m_smileyadd.h>
#include "../../libs/freeimage/src/FreeImage.h"
|