summaryrefslogtreecommitdiff
path: root/plugins/MirandaG15/src/CContactlistScreen.cpp
blob: b1b0b962b4b93d34b330292117abbf91cea7e198 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#include "stdafx.h"
#include "CContactlistScreen.h"
#include "CConfig.h"
#include "CAppletManager.h"

//************************************************************************
// Constructor
//************************************************************************
CContactlistScreen::CContactlistScreen()
{
}

//************************************************************************
// Destructor
//************************************************************************
CContactlistScreen::~CContactlistScreen()
{
}

//************************************************************************
// Initializes the screen 
//************************************************************************
bool CContactlistScreen::Initialize()
{
	if(!CScreen::Initialize())
		return false;

	m_ContactList.Initialize();
	m_ContactList.SetOrigin(0, 0);
	m_ContactList.SetSize(GetWidth()-5, GetHeight()-(CConfig::GetBoolSetting(SHOW_LABELS)?6:0));
	m_ContactList.SetFont(CConfig::GetFont(FONT_CLIST));
	m_ContactList.SetDrawTreeLines(CConfig::GetBoolSetting(CLIST_DRAWLINES));
	m_ContactList.SetColumns(CConfig::GetBoolSetting(CLIST_COLUMNS)?2:1);

	AddObject(&m_ContactList);

	m_Scrollbar.Initialize();
	m_Scrollbar.SetOrigin(GetWidth()-4,0);
	m_Scrollbar.SetSize(4,GetHeight()-(CConfig::GetBoolSetting(SHOW_LABELS)?5:0));
	m_ContactList.SetScrollbar(&m_Scrollbar);

	AddObject(&m_Scrollbar);

	SetButtonBitmap(0,IDB_UP);
	SetButtonBitmap(1,IDB_DOWN);
	SetButtonBitmap(2,IDB_HISTORY);
	SetButtonBitmap(3,IDB_CHAT);

	return true;
}

//************************************************************************
// Shutdown the screen
//************************************************************************
bool CContactlistScreen::Shutdown()
{
	if(!CScreen::Shutdown())
		return false;

	return true;
}

//************************************************************************
// Updates the screen
//************************************************************************
bool CContactlistScreen::Update()
{
	if(!CScreen::Update())
		return false;

	return true;
}

//************************************************************************
// Draws the screen
//************************************************************************
bool CContactlistScreen::Draw(CLCDGfx *pGfx)
{
	if(!CScreen::Draw(pGfx))
		return false;

	return true;
}

//************************************************************************
// returns the online status of the specified contact
//************************************************************************
int CContactlistScreen::GetContactStatus(MCONTACT hContact)
{
	return m_ContactList.GetContactStatus(hContact);
}

//************************************************************************
// resets the position of the contactlist
//************************************************************************
void CContactlistScreen::ResetPosition()
{
	// collapse all groups if setting is active
	switch(CConfig::GetIntSetting(CLIST_GA))
	{
	case CLIST_GA_COLLAPSE:
		m_ContactList.CollapseAll();
		break;
	case CLIST_GA_EXPAND:
		m_ContactList.ExpandAll();
		break;
	}
	
	// select the first item if setting is active
	if(CConfig::GetBoolSetting(CLIST_POSITION))
		m_ContactList.SetPosition(m_ContactList.GetFirstEntry());

	UpdateUseSoftkeyLabel();
}

//************************************************************************
// Called when the screen size has changed
//************************************************************************
void CContactlistScreen::OnSizeChanged()
{
	CScreen::OnSizeChanged();

	m_ContactList.OnConfigChanged();
	m_ContactList.SetSize(GetWidth()-5, GetHeight()-(CConfig::GetBoolSetting(SHOW_LABELS)?6:0));
	
	m_Scrollbar.SetOrigin(GetWidth()-4,0);
	m_Scrollbar.SetSize(4,GetHeight()-(CConfig::GetBoolSetting(SHOW_LABELS)?5:0));
}

//************************************************************************
// Called when the configuration has changed
//************************************************************************
void CContactlistScreen::OnConfigChanged()
{
	CScreen::OnConfigChanged();

	m_ContactList.OnConfigChanged();
	m_ContactList.SetDrawTreeLines(CConfig::GetBoolSetting(CLIST_DRAWLINES));
	m_ContactList.SetSize(GetWidth()-5, GetHeight()-(CConfig::GetBoolSetting(SHOW_LABELS)?6:0));
	m_ContactList.SetFont(CConfig::GetFont(FONT_CLIST));
	m_ContactList.SetColumns(CConfig::GetBoolSetting(CLIST_COLUMNS)?2:1);
	
	m_Scrollbar.SetOrigin(GetWidth()-4,0);
	m_Scrollbar.SetSize(4,GetHeight()-(CConfig::GetBoolSetting(SHOW_LABELS)?5:0));
}

//************************************************************************
// Called when an event is received
//************************************************************************
void CContactlistScreen::OnEventReceived(CEvent *pEvent)
{
	int iStatus = 0;
	switch(pEvent->eType)
	{
	case EVENT_SIGNED_ON:
	case EVENT_SIGNED_OFF:
	case EVENT_STATUS:
		m_ContactList.OnStatusChange(pEvent->hContact,pEvent->iValue);
		break;
	case EVENT_CONTACT_NICK:
		m_ContactList.OnContactNickChanged(pEvent->hContact,pEvent->strValue);
		break;
	case EVENT_CONTACT_ADDED:
		m_ContactList.OnContactAdded(pEvent->hContact);
		break;
	case EVENT_CONTACT_DELETED:
		m_ContactList.OnContactDeleted(pEvent->hContact);
		break;
	case EVENT_MSG_RECEIVED:
	case EVENT_MESSAGEWINDOW:
		m_ContactList.OnMessageCountChanged(pEvent->hContact);
		break;
	case EVENT_CONTACT_HIDDEN:
		m_ContactList.OnContactHiddenChanged(pEvent->hContact,pEvent->iValue != 0);
		break;
	case EVENT_CONTACT_GROUP:
		m_ContactList.OnContactGroupChanged(pEvent->hContact,pEvent->strValue);
		break;
	}
}

//************************************************************************
// Called when a chat session was opened
//************************************************************************
void CContactlistScreen::OnSessionOpened(MCONTACT hContact)
{
	m_ContactList.OnMessageCountChanged(hContact);
}

//************************************************************************
// Called when an LCD-button is pressed
//************************************************************************
void CContactlistScreen::OnLCDButtonDown(int iButton)
{
	m_bLongPress = false;
	if(iButton == LGLCDBUTTON_CANCEL) {
		CAppletManager::GetInstance()->ActivatePreviousScreen();
	} else if(iButton == LGLCDBUTTON_BUTTON1 || iButton == LGLCDBUTTON_DOWN) {
		m_ContactList.ScrollDown();
	} else if(iButton == LGLCDBUTTON_BUTTON0 || iButton == LGLCDBUTTON_UP) {
		m_ContactList.ScrollUp();
	} else if(iButton == LGLCDBUTTON_BUTTON2 || iButton == LGLCDBUTTON_MENU) {
		CAppletManager::GetInstance()->ActivateEventScreen();
		return;
	} else if(iButton == LGLCDBUTTON_BUTTON3 || iButton == LGLCDBUTTON_OK) {
		CListEntry<CContactListEntry*,CContactListGroup*> *pEntry = m_ContactList.GetSelectedEntry();
		if(!pEntry)
			return;
		if(pEntry->GetType() == CONTAINER) {
			CListContainer<CContactListEntry*,CContactListGroup*> *pContainer = (CListContainer<CContactListEntry*,CContactListGroup*>*)pEntry;
			if(pContainer->GetGroupData()->hMetaContact == NULL) {
				pContainer->ToggleOpen();
			}
		} else if(pEntry->GetType() == ITEM)
		{
			CContactListEntry *pContact = ((CListItem<CContactListEntry*,CContactListGroup*>*)pEntry)->GetItemData();
			if(!pContact->hHandle)
				return;
			CAppletManager::GetInstance()->ActivateChatScreen(pContact->hHandle);
			return;
		}
	}

	UpdateUseSoftkeyLabel();
}

//************************************************************************
// Called when an LCD-button event is repeated
//************************************************************************
void CContactlistScreen::OnLCDButtonRepeated(int iButton)
{
	m_bLongPress = true;
	if(iButton == LGLCDBUTTON_BUTTON1 || iButton == LGLCDBUTTON_DOWN) {
		m_ContactList.ScrollDown();
	} else if(iButton == LGLCDBUTTON_BUTTON0 || iButton == LGLCDBUTTON_UP) {
		m_ContactList.ScrollUp();
	} else if(iButton == LGLCDBUTTON_BUTTON3 || iButton == LGLCDBUTTON_OK) {
		UpdateUseSoftkeyLabel();
	} 
}

//************************************************************************
// Called when an LCD-button is released
//************************************************************************
void CContactlistScreen::OnLCDButtonUp(int iButton)
{
	if(iButton == LGLCDBUTTON_BUTTON3 || iButton == LGLCDBUTTON_OK) {
		m_ContactList.ShowSelection();

		CListEntry<CContactListEntry*,CContactListGroup*> *pEntry = m_ContactList.GetSelectedEntry();
		if(!pEntry)
			return;
		if(pEntry->GetType() == CONTAINER) {
			CListContainer<CContactListEntry*,CContactListGroup*> *pContainer = (CListContainer<CContactListEntry*,CContactListGroup*>*)pEntry;
			if(pContainer->GetGroupData()->hMetaContact != NULL) {
				if(m_bLongPress)
					pContainer->ToggleOpen();
				else
					CAppletManager::GetInstance()->ActivateChatScreen(pContainer->GetGroupData()->hMetaContact);
			}
		}
	}
	m_bLongPress = false;
	UpdateUseSoftkeyLabel();
}

//************************************************************************
// Called when the screen is activated
//************************************************************************
void CContactlistScreen::OnActivation()
{

}

//************************************************************************
// Called when the screen is deactivated
//************************************************************************
void CContactlistScreen::OnDeactivation()
{
}

//************************************************************************
// Called when the screen has expired
//************************************************************************
void CContactlistScreen::OnExpiration()
{
}

//************************************************************************
// updates the use softkey label
//************************************************************************
void CContactlistScreen::UpdateUseSoftkeyLabel()
{
	CListEntry<CContactListEntry*,CContactListGroup*> *pEntry = m_ContactList.GetSelectedEntry();
	if(!pEntry)
		return;

	if(pEntry->GetType() == CONTAINER)
	{
		CListContainer<CContactListEntry*,CContactListGroup*> *pContainer = (CListContainer<CContactListEntry*,CContactListGroup*>*)pEntry;
		if(pContainer->GetGroupData()->hMetaContact == NULL || m_bLongPress) {
			if(((CListContainer<CContactListEntry*,CContactListGroup*>*)pEntry)->IsOpen())	
				SetButtonBitmap(3,IDB_MINUS);
			else
				SetButtonBitmap(3,IDB_PLUS);
		} else {
			SetButtonBitmap(3,IDB_CHAT);
		}
	}
	else
	{
		SetButtonBitmap(3,IDB_CHAT);
	}
}