summaryrefslogtreecommitdiff
path: root/plugins/TabSRMM/src/contactcache.h
blob: 2dfa05670d70bfa2700a7b251314c073f7f0cdda (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/////////////////////////////////////////////////////////////////////////////////////////
// Miranda NG: the free IM client for Microsoft* Windows*
//
// Copyright (ñ) 2012-17 Miranda NG project,
// Copyright (c) 2000-09 Miranda ICQ/IM project,
// all portions of this codebase are copyrighted to the people
// listed in contributors.txt.
//
// 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.
//
// part of tabSRMM messaging plugin for Miranda.
//
// (C) 2005-2010 by silvercircle _at_ gmail _dot_ com and contributors
//
// the contact cache

#ifndef __CONTACTCACHE_H
#define __CONTACTCACHE_H

#define C_INVALID_ACCOUNT L"<account error>"
#define HISTORY_INITIAL_ALLOCSIZE 300

struct TInputHistory {
	wchar_t*	szText;
	size_t	lLen;
};

struct TSessionStats {
	enum {
		BYTES_RECEIVED = 1,
		BYTES_SENT = 2,
		FAILURE = 3,
		UPDATE_WITH_LAST_RCV = 4,
		SET_LAST_RCV = 5,
		INIT_TIMER = 6,
	};

	time_t   started;
	unsigned iSent, iReceived, iSentBytes, iReceivedBytes;
	unsigned messageCount;
	unsigned iFailures;
	unsigned lastReceivedChars;
	BOOL     bWritten;
};

struct CContactCache : public MZeroedObject
{
	CContactCache(MCONTACT hContact);
	~CContactCache()
	{
		releaseAlloced();
	}

	__forceinline bool     isValid() const { return m_isValid; }
	__forceinline int      getActiveStatus() const { return m_isMeta ? m_iMetaStatus : getStatus(); }
	__forceinline int      getOldStatus() const { return m_iOldStatus; }
	__forceinline LPCWSTR  getNick() const { return m_szNick; }
	__forceinline MCONTACT getContact() const { return m_hContact; }
	__forceinline MCONTACT getActiveContact() const { return (m_isMeta) ? m_hSub : m_hContact; }
	__forceinline DWORD    getIdleTS() const { return m_idleTS; }
	__forceinline LPCSTR   getProto() const { return cc->szProto; }
	__forceinline LPCSTR   getActiveProto() const { return m_isMeta ? (m_szMetaProto ? m_szMetaProto : cc->szProto) : cc->szProto; }
	
	__forceinline bool     isMeta() const { return m_isMeta; }
	__forceinline bool     isSubContact() const { return cc->IsSub(); }
	__forceinline bool     isFavorite() const { return m_isFavorite; }
	__forceinline bool     isRecent() const { return m_isRecent; }
	
	__forceinline LPCWSTR  getRealAccount() const { return m_szAccount ? m_szAccount : C_INVALID_ACCOUNT; }
	__forceinline LPCWSTR  getUIN() const { return m_szUIN; }
	__forceinline LPCWSTR  getStatusMsg() const { return m_szStatusMsg; }
	__forceinline LPCWSTR  getXStatusMsg() const { return m_xStatusMsg; }
	__forceinline LPCWSTR  getListeningInfo() const { return m_ListeningInfo; }
	__forceinline BYTE     getXStatusId() const { return m_xStatus; }
	__forceinline HWND     getWindowData(TWindowData*& dat) const { dat = m_dat; return m_hwnd; }
	__forceinline HWND     getHwnd() const { return m_hwnd; }

	__forceinline DWORD    getSessionStart() const { return m_stats->started; }
	__forceinline int      getSessionMsgCount() const { return (int)m_stats->messageCount; }

	__forceinline TWindowData* getDat() const { return m_dat; }

	int getStatus(void) const
	{
		return db_get_w(m_hContact, cc->szProto, "Status", ID_STATUS_OFFLINE);
	}

	size_t getMaxMessageLength();
	void   updateStats(int iType, size_t value = 0);

	////////////////////////////////////////////////////////////////////////////

	bool     updateStatus(int iStatus);
	bool     updateNick();
	void     updateMeta();
	bool     updateUIN();
	void     updateStatusMsg(const char *szKey = 0);
	void     setWindowData(const HWND hwnd = 0, TWindowData *dat = 0);
	void     resetMeta();
	void     closeWindow();
	void     deletedHandler();
	void     updateFavorite();
	wchar_t* getNormalizedStatusMsg(const wchar_t *src, bool fStripAll = false);
	HICON    getIcon(int& iSize) const;

	/*
	 * input history
	 */
	void     saveHistory(WPARAM wParam, LPARAM lParam);
	void     inputHistoryEvent(WPARAM wParam);

	static CContactCache* getContactCache(MCONTACT hContact);
	static int cacheUpdateMetaChanged(WPARAM wParam, LPARAM lParam);

private:
	void     allocStats();
	void     initPhaseTwo();
	void     allocHistory();
	void     releaseAlloced();

	MCONTACT m_hContact, m_hSub;
	int      m_iStatus, m_iOldStatus, m_iMetaStatus;
	char    *m_szMetaProto;
	wchar_t *m_szAccount;
	wchar_t  m_szNick[80], m_szUIN[80];
	wchar_t *m_szStatusMsg, *m_xStatusMsg, *m_ListeningInfo;
	BYTE     m_xStatus;
	DWORD    m_idleTS;
	bool     m_isMeta;
	bool     m_isValid;
	bool     m_isFavorite;
	bool     m_isRecent;
	HWND     m_hwnd;
	int      m_nMax;
	int      m_iHistoryCurrent, m_iHistoryTop, m_iHistorySize;

	TWindowData *m_dat;
	TSessionStats *m_stats;
	TInputHistory *m_history;
	DBCachedContact *cc;
};

#endif /* __CONTACTCACHE_H */