summaryrefslogtreecommitdiff
path: root/plugins/UserInfoEx/src/psp_origin.cpp
blob: 771bc54d2785a22227ae0df80eddcff64819d581 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
UserinfoEx plugin for Miranda IM

Copyright:
© 2006-2010 DeathAxe, Yasnovidyashii, Merlin, K. Romanov, Kreol

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 2
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "stdafx.h"

class PSPOriginDlg : public PSPBaseDlg
{
	CTimer timer;
	CCtrlCombo cmbCountry;

public:
	PSPOriginDlg() :
		PSPBaseDlg(IDD_CONTACT_ORIGIN),
		timer(this, 1),
		cmbCountry(this, EDIT_COUNTRY)
	{
		timer.OnEvent = Callback(this, &PSPOriginDlg::onTimer);
		cmbCountry.OnSelChanged = Callback(this, &PSPOriginDlg::onSelChanged_Country);
	}

	bool OnInitDialog() override
	{
		PSPBaseDlg::OnInitDialog();

		timer.Start(5000);

		m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_STREET, SET_CONTACT_ORIGIN_STREET, DBVT_WCHAR));
		m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_ZIP, SET_CONTACT_ORIGIN_ZIP, DBVT_WCHAR));
		m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_CITY, SET_CONTACT_ORIGIN_CITY, DBVT_WCHAR));
		m_ctrlList->insert(CEditCtrl::CreateObj(m_hwnd, EDIT_STATE, SET_CONTACT_ORIGIN_STATE, DBVT_WCHAR));

		UINT nList;
		LPIDSTRLIST pList;
		GetCountryList(&nList, &pList);
		m_ctrlList->insert(CCombo::CreateObj(m_hwnd, EDIT_COUNTRY, SET_CONTACT_ORIGIN_COUNTRY, DBVT_WORD, pList, nList));

		m_ctrlList->insert(CTzCombo::CreateObj(m_hwnd, EDIT_TIMEZONE, nullptr));
		return true;
	}

	bool OnRefresh() override
	{
		auto *pszProto = GetBaseProto();
		if (!pszProto || !m_hContact)
			return false;

		MTime mt;
		if (mt.DBGetStamp(m_hContact, USERINFO, SET_CONTACT_ADDEDTIME) && strstr(pszProto, "ICQ")) {
			uint32_t dwStamp;

			dwStamp = DB::Contact::WhenAdded(db_get_dw(m_hContact, pszProto, "UIN", 0), pszProto);
			if (dwStamp > 0)
				mt.FromStampAsUTC(dwStamp);
		}
		if (mt.IsValid()) {
			wchar_t szTime[MAX_PATH];
			LPTSTR ptr;

			mt.UTCToLocal();
			mt.DateFormatLong(szTime, _countof(szTime));

			mir_wstrcat(szTime, L" - ");
			ptr = szTime + mir_wstrlen(szTime);
			mt.TimeFormat(ptr, _countof(szTime) - (ptr - szTime));
			SetDlgItemText(m_hwnd, TXT_DATEADDED, szTime);
		}
		
		return PSPBaseDlg::OnRefresh();
	}

	void OnIconsChanged() override
	{
		const ICONCTRL idIcon[] = {
			{ IDI_TREE_ADDRESS, STM_SETIMAGE, ICO_ADDRESS },
			{ IDI_CLOCK,        STM_SETIMAGE, ICO_CLOCK },
		};

		IcoLib_SetCtrlIcons(m_hwnd, idIcon, _countof(idIcon));
	}

	void onTimer(CTimer *)
	{
		wchar_t szTime[32];
		CTzCombo::GetObj(m_hwnd, EDIT_TIMEZONE)->GetTime(szTime, _countof(szTime));
		SetDlgItemText(m_hwnd, TXT_TIME, szTime);
	}

	void onSelChanged_Country(CCtrlCombo *)
	{
		UpdateCountryIcon(cmbCountry);
	}
};

void InitOriginDlg(WPARAM wParam, USERINFOPAGE &uip)
{
	uip.position = 0x8000002;
	uip.pDialog = new PSPOriginDlg();
	uip.dwInitParam = ICONINDEX(IDI_TREE_ADVANCED);
	uip.szTitle.w = LPGENW("General") L"\\" LPGENW("Origin");
	g_plugin.addUserInfo(wParam, &uip);
}