summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r--protocols/Telegram/src/add_phone.cpp96
-rw-r--r--protocols/Telegram/src/options.cpp8
-rw-r--r--protocols/Telegram/src/proto.cpp17
-rw-r--r--protocols/Telegram/src/proto.h11
-rw-r--r--protocols/Telegram/src/resource.h7
-rw-r--r--protocols/Telegram/src/stdafx.h1
6 files changed, 133 insertions, 7 deletions
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"