-
Notifications
You must be signed in to change notification settings - Fork 0
/
talkwindow.c
907 lines (744 loc) · 27.3 KB
/
talkwindow.c
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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
/*
* Copyright (c) 2012-2022 Filip "widelec-BB" Maryjanski, BlaBla group.
* All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <proto/exec.h>
#include <proto/utility.h>
#include <libvstring.h>
#include <libraries/magicbeacon.h>
#include "locale.h"
#include "globaldefines.h"
#include "application.h"
#include "contactslist.h"
#include "title_class.h"
#include "prefswindow.h"
#include "talktab.h"
#include "talkwindow.h"
#include "tabtitle.h"
#include "smallsbar.h"
#include "support.h"
#include "kwakwa_api/defs.h"
struct MUI_CustomClass *TalkWindowClass;
static IPTR TalkWindowDispatcher(VOID);
const struct EmulLibEntry TalkWindowGate = {TRAP_LIB, 0, (VOID(*)(VOID))TalkWindowDispatcher};
struct TabEntry
{
ULONG tab_id;
LONG tab_unique_id;
struct ContactEntry *list_entry;
struct ContactEntry entry;
Object *title;
Object *tab;
struct TabEntry *next;
};
static struct TabEntry* AddTabEntry(Class *cl, Object *obj, struct ContactEntry *contact, Object *title, Object *group);
static VOID DeleteTabsList(Class *cl, Object *obj);
static struct TabEntry* FindTabEntryByEntryData(Class *cl, Object *obj, STRPTR entryid, LONG pluginid);
struct TKWP_ShowMessage {ULONG MethodID; STRPTR entryid; LONG pluginid; STRPTR message; ULONG timestamp; ULONG flag;};
struct TKWP_DeleteTab {ULONG MethodID; Object *title;};
struct TKWP_ActivateTab {ULONG MethodID; ULONG tab_id;};
struct TKWP_OpenOnTab {ULONG MethodID; struct TabEntry *tab;};
struct TKWP_OpenOnTabById {ULONG MethodID; ULONG tab_id;};
struct TKWP_UpdateTabContact {ULONG MethodID; STRPTR entryid; LONG pluginid;};
struct TKWP_UpdateTabContactStatus {ULONG MethodID; STRPTR entryid; LONG pluginid;};
struct TKWP_UpdateTabWriteLamp {ULONG MethodID; STRPTR entryid; LONG pluginid; ULONG length;};
struct TKWP_AcceptBeacon {ULONG MethodID; ULONG notify_result; LONG tab_unique_id;};
struct TKWP_ShowPicture {ULONG MethodID; STRPTR entryid; LONG pluginid; ULONG timestamp; ULONG flag; APTR pic; ULONG pic_size;};
struct TKWP_GetTab {ULONG MethodID; ULONG position; Object **entry;};
struct TKWP_SendMessage {ULONG MethodID; STRPTR entryid; LONG pluginid; STRPTR message;};
struct TKWP_ShowInvite {ULONG MethodID; STRPTR entryid; LONG pluginid; ULONG timestamp;};
struct TKWP_DeleteTabByObject {ULONG MethodID; Object *tab;};
struct TalkWindowData
{
Object *title;
Object *page_group;
struct TabEntry *tabs_list_start;
struct TabEntry *tabs_list_end;
ULONG tabs_list_entries;
STRPTR win_title;
};
struct MUI_CustomClass *CreateTalkWindowClass(VOID)
{
struct MUI_CustomClass *cl;
cl = MUI_CreateCustomClass(NULL, MUIC_Window, NULL, sizeof(struct TalkWindowData), (APTR)&TalkWindowGate);
TalkWindowClass = cl;
return cl;
}
VOID DeleteTalkWindowClass(VOID)
{
if (TalkWindowClass) MUI_DeleteCustomClass(TalkWindowClass);
}
static IPTR TalkWindowNew(Class *cl, Object *obj, struct opSet *msg)
{
Object *title, *page_group;
obj = DoSuperNew(cl, obj,
MUIA_UserData, USD_TALKWINDOW_WINDOW,
MUIA_Window_ID, USD_TALKWINDOW_WINDOW,
MUIA_Background, MUII_WindowBack,
MUIA_Window_Title, GetString(MSG_TALKWINDOW_TITLE),
MUIA_Window_ScreenTitle, APP_SCREEN_TITLE,
MUIA_Window_UseRightBorderScroller, TRUE,
MUIA_Window_RootObject, MUI_NewObject(MUIC_Group,
MUIA_Group_Child, (page_group = MUI_NewObject(MUIC_Group,
MUIA_Background, MUII_RegisterBack,
MUIA_Frame, MUIV_Frame_Register,
MUIA_Group_Horiz, TRUE,
MUIA_Group_PageMode, TRUE,
MUIA_Group_Child, (title = NewObject(TitleClass->mcc_Class, NULL,
MUIA_CycleChain, 1,
MUIA_Title_Closable, TRUE,
/* here add first tab contents */
TAG_END)),
TAG_END)),
TAG_END),
TAG_MORE, msg->ops_AttrList);
if(obj)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
if((d->win_title = Utf8ToSystem((STRPTR)xget(obj, MUIA_Window_Title))))
set(obj, MUIA_Window_Title, (IPTR)d->win_title);
d->title = title;
d->page_group = page_group;
DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Self, 3,
MUIM_Set, MUIA_Window_Open, FALSE);
DoMethod(title, MUIM_Notify, TITA_Deleted, MUIV_EveryTime, obj, 2,
TKWM_DeleteTab, MUIV_TriggerValue);
DoMethod(page_group, MUIM_Notify, MUIA_Group_ActivePage, MUIV_EveryTime, obj, 2,
TKWM_ActivateTab, MUIV_TriggerValue);
DoMethod(obj, MUIM_Notify, MUIA_Window_Activate, TRUE, MUIV_Notify_Self, 2,
TKWM_ActivateTab, -1);
DoMethod(obj, MUIM_Setup, NULL);
return (IPTR)obj;
}
CoerceMethod(cl, obj, OM_DISPOSE);
return (IPTR)0;
}
static IPTR TalkWindowDispose(Class *cl, Object *obj, Msg msg)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
ENTER();
DeleteTabsList(cl, obj);
if(d->win_title)
StrFree(d->win_title);
LEAVE();
return DoSuperMethodA(cl, obj, msg);
}
static struct TabEntry* AddTabEntry(Class *cl, Object *obj, struct ContactEntry *contact, Object *title, Object *tab)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *new = AllocMem(sizeof(struct TabEntry), MEMF_ANY | MEMF_CLEAR);
ENTER();
if(new && (new->entry.entryid = StrNew(contact->entryid)))
{
new->tab_id = d->tabs_list_entries++;
new->tab_unique_id = GetUniqueID();
/* make copy of contacts list entry */
new->entry.pluginid = contact->pluginid;
new->entry.name = StrNew(contact->name);
new->entry.nickname = StrNew(contact->nickname);
new->entry.firstname = StrNew(contact->firstname);
new->entry.lastname = StrNew(contact->lastname);
new->entry.groupname = StrNew(contact->groupname);
new->entry.birthyear = StrNew(contact->birthyear);
new->entry.city = StrNew(contact->city);
new->entry.statusdesc = StrNew(contact->statusdesc);
new->entry.status = contact->status;
new->entry.gender = contact->gender;
new->entry.unread = contact->unread;
new->entry.avatar = CopyPicture(contact->avatar);
new->list_entry = contact;
new->title = title;
new->tab = tab;
new->next = NULL;
if(d->tabs_list_start == NULL)
{
d->tabs_list_start = new;
d->tabs_list_end = new;
}
else
{
d->tabs_list_end->next = new;
d->tabs_list_end = new;
}
}
LEAVE();
return new;
}
static struct TabEntry* FindTabEntryByEntryData(Class *cl, Object *obj, STRPTR entryid, LONG pluginid)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *temp = d->tabs_list_start;
while(temp != NULL)
{
if(StrEqu(temp->entry.entryid, entryid) && temp->entry.pluginid == pluginid)
break;
temp = temp->next;
}
return temp;
}
static struct TabEntry* FindTabEntryById(Class *cl, Object *obj, ULONG id)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *temp = d->tabs_list_start;
while(temp != NULL && temp->tab_id != id)
temp = temp->next;
return temp;
}
static struct TabEntry* FindTabEntryByUniqueId(Class *cl, Object *obj, LONG id)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *temp = d->tabs_list_start;
while(temp != NULL && temp->tab_unique_id != id)
temp = temp->next;
return temp;
}
static VOID DeleteTabsList(Class *cl, Object *obj)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *temp = d->tabs_list_start, *to_free;
while(temp)
{
to_free = temp;
temp = temp->next;
FreeMem(to_free, sizeof(struct TabEntry));
}
}
static IPTR TalkWindowCreateNewTab(Class *cl, Object *obj, ULONG pluginid, STRPTR entryid, BOOL incoming)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct ContactEntry *entry;
Object *parent = (Object*)xget(d->title, MUIA_Parent);
Object *new_group = NewObject(TalkTabClass->mcc_Class, NULL, TAG_END);
Object *new_title = NULL, *contacts_list = findobj(USD_CONTACTS_LIST, _app(obj));
struct TabEntry *new_tab = NULL;
ULONG i;
for(i=0;;i++)
{
DoMethod(contacts_list, CLSM_GetEntry, i, &entry);
if(entry == NULL || (entry->pluginid == pluginid && StrEqu(entry->entryid, entryid)))
break;
}
if(entry != NULL)
{
tprintf("%ls 0x%lX %ls %ls %ls %ls %ls %ls %ls 0x%lX %ls %ld %ls %lp\n", strd(entry->entryid), entry->pluginid, strd(entry->name),
strd(entry->nickname), strd(entry->firstname), strd(entry->lastname), strd(entry->groupname), strd(entry->birthyear), strd(entry->city),
entry->status, strd(entry->statusdesc), (LONG)entry->gender, entry->unread ? "TRUE" : "FALSE", entry->avatar);
new_title = NewObject(TabTitleClass->mcc_Class, NULL,
TTA_ContactName, ContactName(entry),
TTA_Status, entry->status,
TTA_Unread, incoming,
TTA_ShowStatusImage, xget(prefs_object(USD_PREFS_TW_TABTITLE_IMAGE_ONOFF), MUIA_Selected),
TAG_END);
new_tab = AddTabEntry(cl, obj, entry, new_title, new_group);
DoMethod(new_group, TTBM_Init, &new_tab->entry);
}
else
{
struct ContactEntry ce = {0};
tprintf("contact unknown.\n");
ce.pluginid = pluginid;
if((ce.name = entryid))
{
ce.entryid = entryid;
new_title = NewObject(TabTitleClass->mcc_Class, NULL,
TTA_ContactName, ce.name,
TTA_Status, ce.status,
TTA_Unread, incoming,
TTA_ShowStatusImage, xget(prefs_object(USD_PREFS_TW_TABTITLE_IMAGE_ONOFF), MUIA_Selected),
TAG_END);
new_tab = AddTabEntry(cl, obj, &ce, new_title, new_group);
new_tab->list_entry = (struct ContactEntry*) DoMethod(contacts_list, CLSM_InsertSingle, &ce, CLSV_Insert_Top); /* insert him to list */
if(incoming) /* ok, we got message from someone unknow */
{
DoMethod(_app(obj), APPM_AddNotify, ce.pluginid, ce.entryid, ce.status); /* check his status */
DoMethod(_app(obj), APPM_PubDirRequest, ce.pluginid, ce.entryid, new_tab->tab, TTBM_PubdirParseResponse); /* and find out who the fuck he is */
}
DoMethod(new_group, TTBM_Init, &new_tab->entry);
}
}
tprintf("adding tab to window...\n");
/*
** NOTE: Inserting new tab in MUIC_Title in background (without
** setting it as active) causes trashing MUIC_Title background.
** To fix this one have to call MUIM_Group_InitChange and
** (after inserting) MUIM_Group_ExitChange on *parent of parent*
** of MUIC_Title.
*/
DoMethod((Object*)xget(parent, MUIA_Parent), MUIM_Group_InitChange);
DoMethod(parent, MUIM_Group_InitChange);
DoMethod(d->title, MUIM_Group_InitChange);
DoMethod(d->title, OM_ADDMEMBER, new_title);
DoMethod(parent, OM_ADDMEMBER, new_group);
DoMethod(d->title, MUIM_Group_ExitChange);
DoMethod(parent, MUIM_Group_ExitChange);
DoMethod((Object*)xget(parent, MUIA_Parent), MUIM_Group_ExitChange);
DoMethod(new_group, TTBM_InsertLastMessages);
if(incoming == FALSE) /* if user double clicked on contact in list we need to set tab to active */
set(parent, MUIA_Group_ActivePage, d->tabs_list_entries);
return (IPTR)new_tab;
}
static IPTR TalkWindowShowMessage(Class *cl, Object *obj, struct TKWP_ShowMessage *msg)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *tab;
ENTER();
if((tab = FindTabEntryByEntryData(cl, obj, msg->entryid, msg->pluginid)))
{
tprintf("tab exist, found %lp\n", tab);
}
else
{
tprintf("tab not found, creating new...\n");
tab = (struct TabEntry*) TalkWindowCreateNewTab(cl, obj, msg->pluginid, msg->entryid, msg->message != NULL);
}
if(tab != NULL)
{
if(msg->message == NULL) /* FALSE when we got a message, TRUE if user double clicked on contacts list */
{
/* user double clicked on contact in list, so we set tab to active */
set(obj, MUIA_Window_Open, TRUE);
set((Object*)xget(d->title, MUIA_Parent), MUIA_Group_ActivePage, tab->tab_id);
DoMethod(tab->tab, TTBM_Activate);
DoMethod(tab->tab, TTBM_ShowEnd);
if(tab->list_entry != NULL)
{
if(tab->list_entry->unread == TRUE)
{
tab->list_entry->unread = FALSE;
DoMethod(obj, TKWM_UpdateTabContact, tab->list_entry->entryid, tab->list_entry->pluginid);
DoMethod(findobj(USD_CONTACTS_LIST, _app(obj)), CLSM_Sort);
set(_app(obj), APPA_ScreenbarUnread, FALSE); /* have to be after sort! APPM_ScreenbarUnread rely on sorting... */
set(tab->title, TTA_Unread, FALSE);
}
}
}
else
{
/* got new message, put it to tab, no fight for attention */
switch(msg->flag)
{
case MSG_FLAG_NORMAL:
DoMethod(tab->tab, TTBM_PutMessage, ContactNameLoc(tab->entry), msg->message, msg->timestamp);
break;
case MSG_FLAG_MULTILOGON:
DoMethod(tab->tab, TTBM_SendMessage, msg->message, FALSE);
break;
default:
tprintf("APPM_GGReciveMessage: unrecognized flag!\n");
break;
}
/* if window is not active at all or we are in other tab set unread flag */
if((tab->list_entry != NULL && (xget(obj, MUIA_Window_Activate) != TRUE || (xget(d->page_group, MUIA_Group_ActivePage) != tab->tab_id))))
{
if(msg->flag != MSG_FLAG_MULTILOGON) /* we don't want to notify when it's our meesage (but from other client) */
{
/* set unread state on list and screenbar */
if(tab->list_entry->unread == FALSE)
{
tab->list_entry->unread = TRUE;
DoMethod(obj, TKWM_UpdateTabContact, tab->entry.entryid, tab->entry.pluginid);
DoMethod(findobj(USD_CONTACTS_LIST, _app(obj)), CLSM_Sort);
set(_app(obj), APPA_ScreenbarUnread, TRUE); /* have to be after sort! APPM_ScreenbarUnread rely on sorting... */
}
DoMethod(_app(obj), APPM_NotifyBeacon, BEACON_MESSAGE, ContactNameLoc(tab->entry), TRUE, obj, TKWM_AcceptBeacon, tab->tab_unique_id);
set(tab->title, TTA_Unread, TRUE);
}
else if(tab->list_entry->unread == TRUE) /* after receive multilogon message set unread to false (we read this on other session) */
{
tab->list_entry->unread = FALSE;
DoMethod(obj, TKWM_UpdateTabContact, tab->entry.entryid, tab->entry.pluginid);
DoMethod(findobj(USD_CONTACTS_LIST, _app(obj)), CLSM_Sort);
set(_app(obj), APPA_ScreenbarUnread, TRUE); /* have to be after sort! APPM_ScreenbarUnread rely on sorting... */
set(tab->title, TTA_Unread, FALSE);
}
}
}
}
LEAVE();
return (IPTR)1;
}
static IPTR TalkWindowDeleteTab(Class *cl, Object *obj, struct TKWP_DeleteTab *msg)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *temp_back = NULL, *temp = d->tabs_list_start, *temp_next;
while(temp != NULL)
{
if(temp->title == msg->title) break;
temp_back = temp;
temp = temp->next;
}
if(temp != NULL)
{
if(d->tabs_list_start == temp) /* we will try to remove first tab in the list */
{
d->tabs_list_start = temp->next;
}
else
{
if(d->tabs_list_end == temp) /* we will try to remove last tab in the list */
{
d->tabs_list_end = temp_back;
d->tabs_list_end->next = NULL;
}
else /* we will try to remove tab in middle of list */
{
temp_back->next = temp->next;
}
}
temp_next = temp->next;
d->tabs_list_entries--;
FreeMem(temp, sizeof(struct TabEntry));
temp = temp_next;
while(temp != NULL) /* and for every next tab decrement tab_id */
{
temp->tab_id--;
temp_back = temp;
temp = temp->next;
}
if(d->tabs_list_entries == 0)
set(obj, MUIA_Window_Open, FALSE);
}
return (IPTR)1;
}
static IPTR TalkWindowActivateTab(Class *cl, Object *obj, struct TKWP_ActivateTab *msg)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *tab = d->tabs_list_start;
ULONG tab_id;
if(msg->tab_id == -1)
tab_id = xget(d->page_group, MUIA_Group_ActivePage);
else
tab_id = msg->tab_id;
if(tab_id > d->tabs_list_entries) /* check params */
return (IPTR)0;
while(tab != NULL && tab->tab_id != tab_id)
tab = tab->next;
if(tab != NULL)
{
if(xget(obj, MUIA_Window_Open) == TRUE)
{
DoMethod(tab->tab, TTBM_Activate);
if(tab->list_entry)
{
if(tab->list_entry->unread == TRUE)
{
tab->list_entry->unread = FALSE;
DoMethod(obj, TKWM_UpdateTabContact, tab->entry.entryid, tab->entry.pluginid);
DoMethod(findobj(USD_CONTACTS_LIST, _app(obj)), CLSM_Sort);
set(_app(obj), APPA_ScreenbarUnread, FALSE); /* have to be after sort! APPM_ScreenbarUnread rely on sorting... */
set(tab->title, TTA_Unread, FALSE);
}
}
}
if(ContactName(tab->list_entry))
{
STRPTR contact_name_sys = Utf8ToSystem(ContactName(tab->list_entry));
if(contact_name_sys)
{
STRPTR old_title = d->win_title;
if((d->win_title = FmtNew(APP_NAME": %s", contact_name_sys)))
{
set(obj, MUIA_Window_Title, d->win_title);
StrFree(old_title);
}
else
d->win_title = old_title;
StrFree(contact_name_sys);
}
}
}
return (IPTR)1;
}
static IPTR TalkWindowOpenOnTab(Class *cl, Object *obj, struct TKWP_OpenOnTab *msg)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
ENTER();
if(msg->tab)
{
set(obj, MUIA_Window_Open, TRUE);
set(d->page_group, MUIA_Group_ActivePage, msg->tab->tab_id);
if(msg->tab->list_entry != NULL && msg->tab->list_entry->unread == TRUE)
{
msg->tab->list_entry->unread = FALSE;
DoMethod(obj, TKWM_UpdateTabContact, msg->tab->list_entry->entryid, msg->tab->list_entry->pluginid);
DoMethod(findobj(USD_CONTACTS_LIST, _app(obj)), CLSM_Sort);
set(_app(obj), APPA_ScreenbarUnread, FALSE); /* have to be after sort! APPM_ScreenbarUnread rely on sorting... */
set(msg->tab->title, TTA_Unread, FALSE);
}
DoMethod(obj, MUIM_Window_ScreenToFront);
DoMethod(msg->tab->tab, TTBM_Activate);
DoMethod(msg->tab->tab, TTBM_ShowEnd);
}
LEAVE();
return (IPTR)1;
}
static IPTR TalkWindowOpenOnTabById(Class *cl, Object *obj, struct TKWP_OpenOnTabById *msg)
{
DoMethod(obj, TKWM_OpenOnTab, FindTabEntryById(cl, obj, msg->tab_id));
return (IPTR)1;
}
static IPTR TalkWindowCreateTabsMenuStrip(Class *cl, Object *obj)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
Object *result = NULL, *item;
struct TabEntry *tab = d->tabs_list_start;
UBYTE buffer[512];
if(d->tabs_list_entries > 0)
{
result = MUI_NewObject(MUIC_Menuitem,
MUIA_Menuitem_Title, GetString(MSG_TALKWINDOW_TABS_MENU_TITLE),
TAG_END);
DoMethod(result, MUIM_Group_InitChange);
while(tab != NULL)
{
if(tab->entry.unread)
FmtNPut(buffer, "\33b%s", sizeof(buffer), ContactNameLoc(tab->entry));
item = MUI_NewObject(MUIC_Menuitem,
MUIA_UserData, SBR_MENU_TALK_TAB + tab->tab_id,
MUIA_Menuitem_CopyStrings, TRUE,
MUIA_Menuitem_Title, tab->entry.unread == TRUE ? (STRPTR)buffer : ContactNameLoc(tab->entry),
TAG_END);
DoMethod(result, OM_ADDMEMBER, item);
tab = tab->next;
}
DoMethod(result, MUIM_Group_ExitChange);
}
return (IPTR)result;
}
static IPTR TalkWindowUpdateTabContact(Class *cl, Object *obj, struct TKWP_UpdateTabContact *msg)
{
struct TabEntry *tab;
if((tab = FindTabEntryByEntryData(cl, obj, msg->entryid, msg->pluginid)))
{
if(tab->list_entry != NULL)
{
STRPTR temp = NULL;
struct Picture *av_temp = NULL;
temp = tab->entry.name;
tab->entry.name = StrNew(tab->list_entry->name);
if(temp) StrFree(temp);
temp = tab->entry.nickname;
tab->entry.nickname = StrNew(tab->list_entry->nickname);
if(temp) StrFree(temp);
temp = tab->entry.firstname;
tab->entry.firstname = StrNew(tab->list_entry->firstname);
if(temp) StrFree(temp);
temp = tab->entry.lastname;
tab->entry.lastname = StrNew(tab->list_entry->lastname);
if(temp) StrFree(temp);
temp = tab->entry.groupname;
tab->entry.groupname = StrNew(tab->list_entry->groupname);
if(temp) StrFree(temp);
temp = tab->entry.statusdesc;
tab->entry.statusdesc = StrNew(tab->list_entry->statusdesc);
if(temp) StrFree(temp);
temp = tab->entry.city;
tab->entry.city = StrNew(tab->list_entry->city);
if(temp) StrFree(temp);
temp = tab->entry.birthyear;
tab->entry.birthyear = StrNew(tab->list_entry->birthyear);
if(temp) StrFree(temp);
av_temp = tab->entry.avatar;
tab->entry.avatar = CopyPicture(tab->list_entry->avatar);
if(av_temp) FreePicture(av_temp);
tab->entry.gender = tab->list_entry->gender;
tab->entry.unread = tab->list_entry->unread;
tab->entry.status = tab->list_entry->status;
}
set(tab->title, TTA_ContactName, ContactNameLoc(tab->entry));
set(tab->title, TTA_Status, tab->entry.status);
DoMethod(tab->tab, TTBM_RedrawInfoBlock);
}
return (IPTR)tab;
}
static IPTR TalkWindowUpdateTabContactStatus(Class *cl, Object *obj, struct TKWP_UpdateTabContactStatus *msg)
{
struct TabEntry *tab;
if((tab = (struct TabEntry*) DoMethod(obj, TKWM_UpdateTabContact, msg->entryid, msg->pluginid)))
return (IPTR)DoMethod(tab->tab, TTBM_NewStatus);
return (IPTR)0;
}
static IPTR TalkWindowUpdateTabWriteLamp(Class *cl, Object *obj, struct TKWP_UpdateTabWriteLamp *msg)
{
struct TabEntry *tab;
if((tab = FindTabEntryByEntryData(cl, obj, msg->entryid, msg->pluginid)))
{
if(msg->length == 0)
return (IPTR) DoMethod(tab->tab, TTBM_CleanLampState);
else
return (IPTR) DoMethod(tab->tab, TTBM_SetLampState);
}
return (IPTR)0;
}
static IPTR TalkWindowAcceptBeacon(Class *cl, Object *obj, struct TKWP_AcceptBeacon *msg)
{
if(msg->notify_result == NOTIFICATIONRESULT_CONFIRMED)
DoMethod(obj, TKWM_OpenOnTab, FindTabEntryByUniqueId(cl, obj, msg->tab_unique_id));
return (IPTR)0;
}
static IPTR TalkWindowShowPicture(Class *cl, Object *obj, struct TKWP_ShowPicture *msg)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *tab;
ENTER();
if(msg->pic == NULL)
return (IPTR)0;
if(!(tab = FindTabEntryByEntryData(cl, obj, msg->entryid, msg->pluginid)))
tab = (struct TabEntry*) TalkWindowCreateNewTab(cl, obj, msg->pluginid, msg->entryid, TRUE);
if(tab != NULL)
{
/* got new picture, put it to tab, no fight for attention */
switch(msg->flag)
{
case MSG_FLAG_NORMAL:
DoMethod(tab->tab, TTBM_PutPicture, ContactNameLoc(tab->entry), msg->timestamp, msg->pic, msg->pic_size);
break;
case MSG_FLAG_MULTILOGON:
DoMethod(tab->tab, TTBM_PutPicture, NULL, msg->timestamp, msg->pic, msg->pic_size);
break;
}
/* if window is not active at all or we are in other tab set unread flag */
if((tab->list_entry != NULL && (xget(obj, MUIA_Window_Activate) != TRUE || (xget(d->page_group, MUIA_Group_ActivePage) != tab->tab_id))))
{
if(msg->flag != MSG_FLAG_MULTILOGON) /* we don't want to notify when it's our meesage (but from other client) */
{
/* set unread state on list and screenbar */
if(tab->list_entry->unread == FALSE)
{
tab->list_entry->unread = TRUE;
DoMethod(obj, TKWM_UpdateTabContact, tab->entry.entryid, tab->entry.pluginid);
DoMethod(findobj(USD_CONTACTS_LIST, _app(obj)), CLSM_Sort);
set(_app(obj), APPA_ScreenbarUnread, TRUE); /* have to be after sort! APPM_ScreenbarUnread rely on sorting... */
}
DoMethod(_app(obj), APPM_NotifyBeacon, BEACON_PICTURE, ContactNameLoc(tab->entry), TRUE, obj, TKWM_AcceptBeacon, tab->tab_unique_id);
set(tab->title, TTA_Unread, TRUE);
}
else if(tab->list_entry->unread == TRUE) /* after receive multilogon message set unread to false (we read this on other session) */
{
tab->list_entry->unread = FALSE;
DoMethod(obj, TKWM_UpdateTabContact, tab->entry.entryid, tab->entry.pluginid);
DoMethod(findobj(USD_CONTACTS_LIST, _app(obj)), CLSM_Sort);
set(_app(obj), APPA_ScreenbarUnread, TRUE); /* have to be after sort! APPM_ScreenbarUnread rely on sorting... */
set(tab->title, TTA_Unread, FALSE);
}
}
}
LEAVE();
return (IPTR)1;
}
static IPTR TalkWindowGetTab(Class *cl, Object *obj, struct TKWP_GetTab *msg)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *e;
*msg->entry = NULL;
if(msg->position == TKWV_ActiveTab)
msg->position = xget(d->page_group, MUIA_Group_ActivePage);
if((e = FindTabEntryById(cl, obj, msg->position)))
{
if(msg->entry)
*msg->entry = e->tab;
}
return (IPTR)0;
}
static IPTR TalkWindowSendMessage(Class *cl, Object *obj, struct TKWP_SendMessage *msg)
{
struct TabEntry *tab;
ENTER();
if(msg->message == NULL)
return (IPTR)0;
if(!(tab = FindTabEntryByEntryData(cl, obj, msg->entryid, msg->pluginid)))
tab = (struct TabEntry*) TalkWindowCreateNewTab(cl, obj, msg->pluginid, msg->entryid, TRUE);
if(tab != NULL)
{
DoMethod(tab->tab, TTBM_SendMessage, msg->message, TRUE, NULL);
}
LEAVE();
return (IPTR)1;
}
static IPTR TalkWindowShowInvite(Class *cl, Object *obj, struct TKWP_ShowInvite *msg)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
struct TabEntry *tab;
ENTER();
if((tab = FindTabEntryByEntryData(cl, obj, msg->entryid, msg->pluginid)))
{
tprintf("tab exist, found %lp\n", tab);
}
else
{
tprintf("tab not found, creating new...\n");
tab = (struct TabEntry*) TalkWindowCreateNewTab(cl, obj, msg->pluginid, msg->entryid, FALSE);
}
if(tab != NULL)
{
DoMethod(tab->tab, TTBM_PutInvite, msg->pluginid, msg->entryid, msg->timestamp);
/* if window is not active at all or we are in other tab set unread flag */
if((tab->list_entry != NULL && (xget(obj, MUIA_Window_Activate) != TRUE || (xget(d->page_group, MUIA_Group_ActivePage) != tab->tab_id))))
{
/* set unread state on list and screenbar */
if(tab->list_entry->unread == FALSE)
{
tab->list_entry->unread = TRUE;
DoMethod(obj, TKWM_UpdateTabContact, tab->entry.entryid, tab->entry.pluginid);
DoMethod(findobj(USD_CONTACTS_LIST, _app(obj)), CLSM_Sort);
set(_app(obj), APPA_ScreenbarUnread, TRUE); /* have to be after sort! APPM_ScreenbarUnread rely on sorting... */
}
DoMethod(_app(obj), APPM_NotifyBeacon, BEACON_INVITE, ContactNameLoc(tab->entry), TRUE, obj, TKWM_AcceptBeacon, tab->tab_unique_id);
set(tab->title, TTA_Unread, TRUE);
}
}
LEAVE();
return (IPTR)1;
}
static IPTR TalkWindowDeleteTabByObject(Class *cl, Object *obj, struct TKWP_DeleteTabByObject *msg)
{
struct TalkWindowData *d = INST_DATA(cl, obj);
Object *parent = (Object*)xget(d->title, MUIA_Parent);
struct TabEntry *temp = d->tabs_list_start;
ENTER();
while(temp != NULL)
{
if(temp->tab == msg->tab) break;
temp = temp->next;
}
if(temp != NULL)
{
DoMethod(parent, MUIM_Group_InitChange);
DoMethod(d->title, MUIM_Group_InitChange);
DoMethod(d->title, OM_REMMEMBER, temp->title);
DoMethod(parent, OM_REMMEMBER, temp->tab);
DoMethod(d->title, MUIM_Group_ExitChange);
DoMethod(parent, MUIM_Group_ExitChange);
DoMethod(obj, TKWM_DeleteTab, temp->title);
}
LEAVE();
return (IPTR)1;
}
static IPTR TalkWindowDispatcher(VOID)
{
Class *cl = (Class*)REG_A0;
Object *obj = (Object*)REG_A2;
Msg msg = (Msg)REG_A1;
switch (msg->MethodID)
{
case OM_NEW: return (TalkWindowNew(cl, obj, (struct opSet*)msg));
case OM_DISPOSE: return (TalkWindowDispose(cl, obj, msg));
case TKWM_ShowMessage: return (TalkWindowShowMessage(cl, obj, (struct TKWP_ShowMessage*)msg));
case TKWM_DeleteTab: return(TalkWindowDeleteTab(cl, obj, (struct TKWP_DeleteTab*)msg));
case TKWM_ActivateTab: return(TalkWindowActivateTab(cl, obj, (struct TKWP_ActivateTab*)msg));
case TKWM_OpenOnTab: return(TalkWindowOpenOnTab(cl, obj, (struct TKWP_OpenOnTab*)msg));
case TKWM_OpenOnTabById: return(TalkWindowOpenOnTabById(cl, obj, (struct TKWP_OpenOnTabById*)msg));
case TKWM_CreateTabsMenuStrip: return(TalkWindowCreateTabsMenuStrip(cl, obj));
case TKWM_UpdateTabContact: return(TalkWindowUpdateTabContact(cl, obj, (struct TKWP_UpdateTabContact*)msg));
case TKWM_UpdateTabContactStatus: return(TalkWindowUpdateTabContactStatus(cl, obj, (struct TKWP_UpdateTabContactStatus*)msg));
case TKWM_UpdateTabWriteLamp: return(TalkWindowUpdateTabWriteLamp(cl, obj, (struct TKWP_UpdateTabWriteLamp*)msg));
case TKWM_AcceptBeacon: return(TalkWindowAcceptBeacon(cl, obj, (struct TKWP_AcceptBeacon*)msg));
case TKWM_ShowPicture: return(TalkWindowShowPicture(cl, obj, (struct TKWP_ShowPicture*)msg));
case TKWM_GetTab: return(TalkWindowGetTab(cl, obj, (struct TKWP_GetTab*)msg));
case TKWM_SendMessage: return(TalkWindowSendMessage(cl, obj, (struct TKWP_SendMessage*)msg));
case TKWM_ShowInvite: return(TalkWindowShowInvite(cl, obj, (struct TKWP_ShowInvite*)msg));
case TKWM_DeleteTabByObject: return(TalkWindowDeleteTabByObject(cl, obj, (struct TKWP_DeleteTabByObject*)msg));
default: return (DoSuperMethodA(cl, obj, msg));
}
}