This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KAccount.cpp
636 lines (538 loc) · 20.5 KB
/
KAccount.cpp
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
#include "stdafx.h"
#include "actio.h"
#include "actio_main.h"
#include <Stamina\PhonoLogic\CallOutgoing.h>
#include <Stamina\PhonoLogic\CallIncoming.h>
#include <Stamina\Internet.h>
#include <Stamina\MD5.h>
#include <Stamina\RegEx.h>
using namespace Actio;
namespace Stamina { namespace PhonoLogic {
std::stack <unsigned int> callNotifies;
uintptr_t konnektBeginThread (const char* name, void * sec, unsigned stack, cCtrl::fBeginThread cb, void * args, unsigned flag, unsigned * addr) {
unsigned int id;
int handle = (uintptr_t)Ctrl->BeginThread(name, sec, stack, cb, args, flag, &id);
if (addr) *addr = id;
// Ctrl->BeginThread siê tym zajmie...
/* if (name && *name) {
Thread::setName(name, id);
}*/
return handle;
}
KAccount::KAccount() {
this->logFile = Stamina::expandEnvironmentStrings("%KonnektLog%\\actio.log").c_str();
this->_threadRunner->setRunner(konnektBeginThread);
//sipxConfigSetBeginThread(konnektBeginThread);
this->stunHost = Ctrl->DTgetInt(DTCFG, 0, Actio::CFG::useSTUN) ? stunHost : "";
PhoneUrl::defaultHost = serverHost;
keepOneSession = true;
_balance = 0;
_gotBalance = false;
_isFetchingInfo = false;
setVisibleStatus(ST_OFFLINE);
}
KAccount::~KAccount() {
this->finish();
}
std::string KAccount::getUserAgent() {
int v = ICMessage(IMC_PLUG_VERSION, ICMessage(IMC_PLUGID_POS, Ctrl->ID()));
return "Konnekt.Actio (" + Version(v).getString() + ")";
}
void KAccount::createWindow() {
IMDEBUG(DBG_FUNC, "createWindow()");
Account::createWindow();
SetWindowText(this->_window->getHwnd(), "Actio");
}
CallEntry* KAccount::createCallEntry(const oCall& call) {
return new KCallEntry(call);
}
void KAccount::connect(bool byUser) {
if (this->isConfigured()) {
CStdString url = GETSTR(CFG::userName);
url += "@" + serverHost;
account->setSipUrl(url /* Ctrl->DTgetStr(DTCFG, 0, "Actio/sipUrl")*/);
account->setSipUser(GETSTR(CFG::userName));
account->setSipPass(GETSTR(CFG::userPass));
Account::publicAddress = GETSTR(CFG::publicAddress);
if (this->_mainThread.isCurrent()) {
IMDEBUG(DBG_FUNC, "connect(url=%s, user=%s, pub=%s)",url.c_str() , GETSTR(CFG::userName), GETSTR(CFG::publicAddress));
}
Account::connect(byUser);
} else {
if (Ctrl->IMessage(&sIMessage_msgBox(IMI_CONFIRM, "Zanim bêdziesz móg³ wykonywaæ po³¹czenia musisz najpierw za³o¿yc lub ustawiæ swoje konto.\r\nCzy chcesz przejœæ do okna ustawieñ?", "Actio"))) {
this->onButtonPressed(buttonOptions);
}
}
}
void KAccount::disconnect() {
Account::disconnect();
}
void KAccount::onInitialize() {
Account::onInitialize();
if (_sxInst) {
sipxFieldWatchAdd(_sxInst, "PortaBilling");
}
}
void KAccount::onTapiHeaderWatchEvent(SIPX_HEADERWATCH_INFO* info) {
Account::onTapiHeaderWatchEvent(info);
if (stricmp(info->field, "PortaBilling") == 0) {
// Wyci¹gamy informacjê o stanie konta
// PortaBilling: available-funds:3.45 currency:PLN
RegEx regex;
if (regex.match("/available-funds:([\\d]+(?:[,.][\\d]+)?)/", info->newValue)) {
IMDEBUG(DBG_DEBUG, "WatchPortaBilling - ");
CStdString v = regex[1];
v.Replace(".", localeconv()->decimal_point);
v.Replace(",", localeconv()->decimal_point);
this->_balance = strtod(v.c_str(), 0);
this->_gotBalance = true;
if (this->windowExists()) {
this->getWindow()->refreshAccountInfo();
}
}
}
Stamina::log(logDebug, "KAccount", "onTapiLineEvent::HEADER_VALUE_CHANGE", "\"%s\" = \"%s\" -> \"%s\"", info->field, info->oldValue, info->newValue);
}
void KAccount::onConnected() {
if (this->getStatus() == accountOnline) return;
IMDEBUG(DBG_FUNC, "onConnected()");
ICMessage(IMC_SETCONNECT, 0);
this->setVisibleStatus(ST_ONLINE);
Account::onConnected();
}
void KAccount::onDisconnected() {
if (this->getStatus() == accountOffline) return;
IMDEBUG(DBG_FUNC, "onDisconnected()");
this->setVisibleStatus(ST_OFFLINE);
Account::onDisconnected();
}
void KAccount::onConnectionFailure() {
if (GETINT(CFG_RETRY))
ICMessage(IMC_SETCONNECT, 1);
IMDEBUG(DBG_FUNC, "onConnectionFailure()");
if (this->_connectionByUser) return;
Account::onConnectionFailure();
}
void KAccount::onConnecting() {
IMDEBUG(DBG_FUNC, "onConnecting()");
this->setVisibleStatus(ST_CONNECTING);
Account::onConnecting();
}
void KAccount::onNewIncomingCall(const oCall& call) {
if (!this->getMainThread().isCurrent()) {
threadInvokeObject(this->getMainThread(), call.get()
, boost::bind(&KAccount::onNewIncomingCall, this, call), true);
return;
}
IMDEBUG(DBG_FUNC, "onNewIncomingCall(%s)", call->getPhoneUrl().getUrl().c_str());
int cnt = numbersMap.getContact(call->getPhoneUrl());
if (cnt == -1) { // dorzucamy kontakt...
cnt = numbersMap.createContact(call->getPhoneUrl(), false);
}
if (account && account->windowExists() && account->getWindow()->isActive())
return;
Konnekt::UI::CFG::enMsgPopup popup = (Konnekt::UI::CFG::enMsgPopup) GETINT(Actio::CFG::callPopup);
if (popup == -1) {
popup = (Konnekt::UI::CFG::enMsgPopup) GETINT(CFG_UIMSGPOPUP);
}
if (popup == Konnekt::UI::CFG::mpFocused) {
account->getWindow()->show(true, true);
} else if (popup == Konnekt::UI::CFG::mpBackground) {
account->getWindow()->show(false, true);
} else if (popup == Konnekt::UI::CFG::mpMinimized) {
account->getWindow()->show(false, false);
}
if (GETINT(CFG_UIMSGFLASH)) {
FLASHWINFO fwi;
memset(&fwi , 0 , sizeof(fwi));
fwi.cbSize=sizeof(fwi);
fwi.hwnd=account->getWindow()->getHwnd();
fwi.dwFlags = FLASHW_TRAY | FLASHW_TIMERNOFG;
fwi.uCount = 1;
fwi.dwTimeout = 0;
FlashWindowEx(&fwi);
}
cMessage m;
CStdString body;
body.Format("%s", numbersMap.getDisplay(call->getPhoneUrl()).c_str());
m.body = (char*)body.c_str();
// CStdString ext = SetExtParam("", MEX_TITLE, body);
// m.ext = (char*)ext.c_str();
m.flag = MF_NOSAVE;
m.net = NET_NONE;
char buff [16];
itoa(cnt, buff, 10);
m.fromUid = buff;
m.type = mtypePhoneCall;
m.time = _time64(0);
m.action = sUIAction(Actio::ACT::statusGroup, Actio::ACT::answerCall, cnt);
m.notify = UIIcon(IT_MESSAGE, Actio::net, MT_SPECIAL, 0);
sMESSAGESELECT ms;
ms.id = ICMessage(IMC_NEWMESSAGE, (int)&m);
if (ms.id >=0)
ICMessage(IMC_MESSAGEQUEUE, (int)&ms);
if (IMessage(IM_PLUG_NET, KNotify::net)) { // je¿eli jest KNotify...
body = body + " dzwoni do Ciebie!";
KNotify::sIMessage_notify sin (body , m.notify,KNotify::sIMessage_notify::tInform, 0);
sin._action = m.action;
sin._clickable = true;
callNotifies.push(Ctrl->IMessage(&sin));
}
}
void KAccount::onCriticalError(const CStdString& title, const CStdString& msg) {
if (IMessage(IM_PLUG_NET, KNotify::net)) { // je¿eli jest KNotify...
CStdString txt = "Actio - " + title + "\r\n" + msg;
Ctrl->IMessage(&KNotify::sIMessage_notify(txt , (HICON)0,KNotify::sIMessage_notify::tError,3));
} else {
Account::onCriticalError(title, msg);
}
}
void KAccount::onUnauthorized() {
if (Ctrl->IMessage(& sIMessage_msgBox(IMI_CONFIRM, "Poda³eœ z³y login i/lub has³o!\r\nUpewnij siê czy wpisa³eœ je poprawnie...", "Konnekt-Actio - autoryzacja", MB_ICONERROR | MB_OKCANCEL)) == IDOK) {
ICMessage(IMI_CONFIG, Actio::ACT::configGroup);
}
}
void KAccount::onButtonPressed(PhoneButton button) {
switch (button) {
case buttonInfoConfigure:
case buttonOptions:
ICMessage(IMI_CONFIG, Actio::ACT::configGroup);
return;
case buttonBanner:
case buttonInfo:
ShellExecute(0, "open", urlInformation, "", "", SW_SHOW);
return;
case buttonHelp:
ShellExecute(0, "open", Stamina::expandEnvironmentStrings(urlHelp).c_str(), "", "", SW_SHOW);
return;
case buttonAccount:
if (this->isConfigured()) {
ShellExecute(0, "open", urlSelfCare, "", "", SW_SHOW);
} else {
ICMessage(IMI_CONFIG, Actio::ACT::configGroup);
}
return;
case buttonInfoMic:
ShellExecute(0, "open", urlProblemMic, "", "", SW_SHOW);
return;
case buttonInfoQuality:
ShellExecute(0, "open", urlProblemQuality, "", "", SW_SHOW);
return;
case buttonInfoSound:
ShellExecute(0, "open", urlProblemSound, "", "", SW_SHOW);
return;
case buttonBalance:
//this->refreshAccountInfo();
ShellExecute(0, "open", urlAccountBalance, "", "", SW_SHOW);
return;
}
Account::onButtonPressed(button);
}
void KAccount::onConfigChanged() {
Account::onConfigChanged();
}
void KAccount::onWindowActivated() {
// while (notifyMessages.empty() == false) {
sMESSAGESELECT ms;
ms.type = mtypePhoneCall;
ICMessage(IMC_MESSAGEREMOVE, (int)&ms);
// }
while (callNotifies.empty() == false) {
IMessage(KNotify::IM::hide, KNotify::net, IMT_ALL, callNotifies.top());
callNotifies.pop();
}
}
CStdString KAccount::getSoundFile(const oCall& call, const CStdString& file) {
bool ksound = IMessage(IM_PLUG_NET, NET_SOUND, IMT_CONFIG) != 0;
if (file.compare(0, 4, "test") == 0) {
if (file == "testSpeaker") {
return Stamina::expandEnvironmentStrings("%KonnektData%\\Actio\\test.wav").c_str();
} else if (file == "testRinger") {
const char* path = SAFECHAR(kSound::GetSoundFile(Ctrl, "phoneAlert", 0));
return *path ? path : "sounds\\phonealert.wav";
}
} else {
bool mute = ksound && GETINT(kSound::Cfg::mute)!=0;
if (!mute) {
if (file == "alert") {
return ksound ? SAFECHAR(kSound::GetSoundFile(Ctrl, "phoneAlert", call ? numbersMap.getContact(call->getPhoneUrl()) : 0)) : "sounds\\phonealert.wav";
} else if (file == "failed") {
return ksound ? SAFECHAR(kSound::GetSoundFile(Ctrl, "phoneFailed")) : "sounds\\phonefailed.wav";
} else {
return Stamina::expandEnvironmentStrings("%KonnektData%\\Actio\\" + file + ".wav").c_str();
}
}
}
return "";
}
/*
void KAccount::playFile(const oCall& call, const CStdString& file, bool loop) {
IMDEBUG(DBG_FUNC, "KAccount::playFile(%s, %d)", file.c_str(), loop);
bool ksound = IMessage(IM_PLUG_NET, NET_SOUND, IMT_CONFIG) != 0;
bool mute = ksound && GETINT(kSound::Cfg::mute)!=0;
if (file.empty() == false && !mute) {
if (call && loop) {
call->_playingFile = true;
if (file == "alert" && !mute) {
const char* path = ksound ? kSound::GetSoundFile(Ctrl, "phoneAlert", numbersMap.getContact(call->getPhoneUrl())) : "sounds\\phonealert.wav";
if (path) {
// call->playFile(path, loop);
playFileOnRinger(path, loop);
}
}
} else {
if (file == "failed" && ksound && !mute)
kSound::SoundPlay(Ctrl, "phoneFailed");
}
} else // wy³¹czamy...
Account::playFile(call, "", loop);
}
*/
bool KAccount::isConfigured() {
return *GETSTR(Actio::CFG::userName) != 0;
}
CStdString KAccount::phoneToDisplay(const PhoneUrl& url) {
return numbersMap.getDisplay(url);
}
void KAccount::callToHistory(const oCall& call) {
Tables::oTable dt;
if (call->getClass() <= PhonoLogic::CallIncoming::staticClassInfo()) {
// jest incoming...
dt = Actio::dtIncoming;
} else {
// jest outgoing...
dt = Actio::dtOutgoing;
}
dt->lateSave(false);
tRowId id = dt->addRow();
dt->setStr(id, DTArchive::phone, call->getPhoneUrl().getUrl());
dt->setInt(id, DTArchive::type, call->isUnanswered() ? CallArchiveEntry::typeUnanswered : CallArchiveEntry::typeSuccessfull);
dt->setInt64(id, DTArchive::start, call->isUnanswered() ? _time64(0) : call->getCallStart());
dt->setInt(id, DTArchive::duration, call->getCallDuration());
// Account doda samodzielnie do ew. otwartej listy historii...
dt->lateSave();
Account::callToHistory(call);
}
void KAccount::rejectedCallToHistory(const PhoneUrl& url, CallArchiveEntry::Type type) {
Tables::oTable dt;
dt = Actio::dtIncoming;
dt->lateSave(false);
tRowId id = dt->addRow();
dt->setStr(id, DTArchive::phone, url.getUrl());
dt->setInt(id, DTArchive::type, type);
dt->setInt64(id, DTArchive::start, _time64(0));
dt->setInt(id, DTArchive::duration, 0);
// Account doda samodzielnie do ew. otwartej listy historii...
dt->lateSave();
Account::rejectedCallToHistory(url, type);
}
void KAccount::markPhoneAsUsed(const PhoneUrl& url) {
if (url.isValid() == false)
return;
if (!this->getMainThread().isCurrent()) {
threadInvokeWait(this->getMainThread(), boost::bind(&KAccount::markPhoneAsUsed, this, url), false);
return;
}
Tables::oTable dt = dtNumbers; // dla wygody...
ObjLocker lock1(this->_window->getPhoneBook());
ObjLocker lock2(dt.get());
dt->lateSave(false);
// szukamy elementu...
tRowId id = Tables::rowNotFound;
tRowId oldId = Tables::rowNotFound;
for (int i=0; i < dt->getCount(); i++) {
if (url == dt->getStr(i, DTNumbers::phone)) {
oldId = dt->getRowId(i);
break;
}
}
// ¿eby nowe by³y zawsze na koñcu...
// if (id == Tables::rowNotFound) {
id = dt->addRow();
dt->setStr(id, DTNumbers::phone, url.getUrl());
// }
dt->setInt64(id, DTNumbers::last, _time64(0));
if (this->_window->getPhoneBook()->getCollBook()->getExpanded() == PBCollectionEntry::expandedLess) {
this->_window->getPhoneBook()->addPhoneNumber(new PhoneEntryDT(id), true);
}
if (oldId != Tables::rowNotFound) {
dt->removeRow(oldId);
}
dt->lateSave();
}
bool KAccount::updateCollectionBook(PBCollectionBook* entry, PBCollectionItem* item) {
// wype³niamy listê zawartoœci¹ ksi¹¿ki adresowej...
PhoneBook* pb = this->_window->getPhoneBook();
pb->lockRefresh();
item->removeAll(pb);
if (entry->getExpanded() == PBCollectionEntry::expandedLess) {
// 50 ostatnich
Tables::oTable dt = dtNumbers;
if (dt->getCount() > 0) {
for (int i=dt->getCount() - 1; i > dt->getCount() - 51; i--) {
this->_window->getPhoneBook()->addPhoneNumber(new PhoneEntryDT(dt->getRowId(i)), false);
}
}
} else if (entry->getExpanded() == PBCollectionEntry::expandedMore) {
// wszystkie istniej¹ce na "mapie numerów"
for (NumbersMap::iterator it = numbersMap.begin(); it != numbersMap.end(); ++it) {
this->_window->getPhoneBook()->addPhoneNumber(new PhoneEntryCnt(it->first, it->second), false);
}
}
pb->unlockRefresh();
return true;
}
bool KAccount::updateCollectionArchive(PBCollectionArchive* entry, PBCollectionItem* item) {
PhoneBook* pb = this->_window->getPhoneBook();
bool outgoing = (pb->getCollOutgoing().get() == item);
Tables::oTable dt = (outgoing) ? dtOutgoing : dtIncoming;
pb->lockRefresh();
item->removeAll(pb);
if (entry->getExpanded() == PBCollectionEntry::expandedLess) {
// po³¹czenia z ostatniej doby
__time64_t limit = _time64(0) - 60*60*24;
if (dt->getCount() > 0) {
for (int i=dt->getCount() - 1; i >= 0; i--) {
if (dt->getInt64(i, DTArchive::start) < limit)
break;
this->_window->getPhoneBook()->addCallArchive(new CallArchiveEntryDT(dt->getRowId(i), outgoing));
}
}
} if (entry->getExpanded() == PBCollectionEntry::expandedMore) {
// wszystkie po³¹czenia
for (int i=0; i < dt->getCount(); i++) {
this->_window->getPhoneBook()->addCallArchive(new CallArchiveEntryDT(dt->getRowId(i), outgoing));
}
}
pb->unlockRefresh();
return true;
}
bool KAccount::isCalling(tCntId cnt) {
for (CallList::iterator it = _calls.begin(); it != _calls.end(); ++it) {
if ((*it)->isIncoming() && numbersMap.getContact((*it)->getPhoneUrl()) == cnt)
return true;
}
return false;
}
void KAccount::setVisibleStatus(int status) {
if (status == _visibleStatus) return;
_visibleStatus = status;
IMessage(&sIMessage_StatusChange(IMC_STATUSCHANGE , 0 , _visibleStatus , 0));
}
void KAccount::refreshAccountInfoThread() {
_isFetchingInfo = true;
bool success = false;
try {
CStdString ua;
ICMessage(IMC_PLUG_VERSION, Ctrl->ID(), (int)ua.GetBuffer(20));
ua.ReleaseBuffer();
ua = "Konnekt-Actio " + ua;
Stamina::oInternet internet = new Stamina::Internet((HINTERNET) ICMessage(IMC_HINTERNET_OPEN, (int)ua.c_str()));
CStdString url;
url.Format("%sversion=%x&user=%s&digest=%s", accountServer, ICMessage(IMC_PLUG_VERSION, Ctrl->ID()), urlEncode(this->_sipUser).c_str(), MD5Hex( "account" + this->_sipPass ).c_str() );
Stamina::oRequest request = new Stamina::Request(new Stamina::Connection(internet, url), url, Stamina::Request::typeGet, 0, 0, 0, INTERNET_FLAG_RELOAD);
request->sendThrowable();
Stamina::RegEx response;
response.setSubject( request->getResponse() );
if (response.match("#<account>.*?<balance>([\\d,.]+)</balance>#")) {
_gotBalance = true;
_balance = atof(response[1].c_str());
success = true;
Stamina::log(logLog, "Actio", "refreshAccountInfoThread", "Stan konta: %f", _balance);
} else {
Stamina::log(logError, "Actio", "refreshAccountInfoThread", "OdpowiedŸ nie zawiera informacji o stanie konta! [%.200s] ", response.getSubjectRef().c_str());
}
} catch (Exception& e) {
Stamina::log(logError, "Actio", "refreshAccountInfoThread", "Wyst¹pi³ b³¹d podczas pobierania stanu konta: " + e.getReason());
}
_isFetchingInfo = false;
if (success && this->windowExists()) {
//this->getWindow()->enableButton(buttonBalance, true);
this->getWindow()->refreshAccountInfo();
}
}
void KAccount::refreshAccountInfo() {
if (_isFetchingInfo || !this->isConfigured()) return;
//this->_threadRunner->run(boost::bind(KAccount::refreshAccountInfoThread, this), "RefreshAccountInfo");
}
bool KAccount::getBalance(double& balance) {
balance = _balance;
return _gotBalance;
}
// ----------------------------------------------------------------------
PhoneEntryDT::PhoneEntryDT(tRowId row):PhoneEntry(Actio::dtNumbers->getInt64(row, Actio::DTNumbers::last)),_row(row) {
}
const PhoneUrl PhoneEntryDT::getPhoneUrl() {
return PhoneUrl::createAuto(Actio::dtNumbers->getStr(_row, Actio::DTNumbers::phone));
}
CStdString PhoneEntryDT::getName() {
return numbersMap.getDisplay(this->getPhoneUrl());
}
bool PhoneEntryDT::onContextMenu(ListWnd::ListView* lv, const ListWnd::oItem& li, int level, int vkey, const Point& pos, const oMenu& menu) {
PhoneEntry::onContextMenu(lv, li, level, vkey, pos, menu);
return phoneEntryContextMenu(this, lv, li, level, vkey, pos, menu);
}
void PhoneEntryDT::removePBEntry(PhoneBook* pb) {
dtNumbers->removeRow(this->_row);
dtNumbers->lateSave(true);
PhoneEntry::removePBEntry(pb);
}
// ----------------------------------------------------------------------
PhoneEntryCnt::PhoneEntryCnt(const PhoneUrl& url, tColId cnt):PhoneEntry(0) {
if (cnt == -1)
_cnt = numbersMap.getContact(url);
else
_cnt = cnt;
_url = url;
}
const PhoneUrl PhoneEntryCnt::getPhoneUrl() {
return _url;
}
CStdString PhoneEntryCnt::getName() {
return numbersMap.getDisplay(this->getPhoneUrl());
}
bool PhoneEntryCnt::onContextMenu(ListWnd::ListView* lv, const ListWnd::oItem& li, int level, int vkey, const Point& pos, const oMenu& menu) {
PhoneEntry::onContextMenu(lv, li, level, vkey, pos, menu);
phoneEntryContextMenu(this, lv, li, level, vkey, pos, menu);
return true;
}
void PhoneEntryCnt::removePBEntry(PhoneBook* pb) {
// this->getTable()->removeRow(this->_row);
PhoneEntry::removePBEntry(pb);
}
// ----------------------------------------------------------------
CStdString CallArchiveEntryDT::getName() {
return numbersMap.getDisplay(this->getPhoneUrl());
}
Tables::oTable CallArchiveEntryDT::getTable() {
return _outgoing ? dtOutgoing : dtIncoming;
}
bool CallArchiveEntryDT::onContextMenu(ListWnd::ListView* lv, const ListWnd::oItem& li, int level, int vkey, const Point& pos, const oMenu& menu) {
CallArchiveEntry::onContextMenu(lv, li, level, vkey, pos, menu);
phoneEntryContextMenu(this, lv, li, level, vkey, pos, menu);
return true;
}
void CallArchiveEntryDT::removePBEntry(PhoneBook* pb) {
this->getTable()->removeRow(this->_row);
this->getTable()->lateSave(true);
CallArchiveEntry::removePBEntry(pb);
}
// ---------------
bool KCallEntry::onContextMenu(ListWnd::ListView* lv, const ListWnd::oItem& li, int level, int vkey, const Point& pos, const oMenu& menu) {
CallEntry::onContextMenu(lv, li, level, vkey, pos, menu);
phoneEntryContextMenu(this, lv, li, level, vkey, pos, menu);
return true;
}
void KCallEntry::removePBEntry(PhoneBook* pb) {
this->getCall()->callDrop();
this->getCall()->callDestroy();
}
// ---------------
bool phoneEntryContextMenu(PBEntry* entry, ListWnd::ListView* lv, const ListWnd::oItem& li, int level, int vkey, const Point& pos, const oMenu& menu) {
if (numbersMap.getContact(entry->getPhoneUrl()) == -1) {
bool onList = true;
menu->insertItem(new MenuItemW32_label("Dodaj do listy kontaktów", boost::bind(NumbersMap::createContact, &numbersMap, entry->getPhoneUrl(), onList)), 1);
}
return true;
}
}}