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
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
|
/*
aimaccount.cpp - Oscar Protocol Plugin, AIM part
Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* 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. *
* *
*************************************************************************
*/
#include <tqdom.h>
#include <tqfile.h>
#include <kdebug.h>
#include <tdeconfig.h>
#include <kdialogbase.h>
#include <klocale.h>
#include <tdepopupmenu.h>
#include <kmessagebox.h>
#include <kmdcodec.h>
#include "kopeteawayaction.h"
#include "kopetepassword.h"
#include "kopetestdaction.h"
#include "kopeteuiglobal.h"
#include "kopetecontactlist.h"
#include "kopetemetacontact.h"
#include "kopeteprotocol.h"
#include "kopetechatsessionmanager.h"
#include "kopeteview.h"
#include <kopeteuiglobal.h>
#include "aimprotocol.h"
#include "aimaccount.h"
#include "aimchatsession.h"
#include "aimcontact.h"
#include "aimuserinfo.h"
#include "aimjoinchat.h"
#include "oscarmyselfcontact.h"
#include "oscarvisibilitydialog.h"
#include "oscarutils.h"
#include "client.h"
#include "ssimanager.h"
const DWORD AIM_ONLINE = 0x0;
const DWORD AIM_AWAY = 0x1;
namespace Kopete { class MetaContact; }
AIMMyselfContact::AIMMyselfContact( AIMAccount *acct )
: OscarMyselfContact( acct )
{
m_acct = acct;
}
void AIMMyselfContact::userInfoUpdated()
{
if ( ( details().userClass() & 32 ) == 0 )
setOnlineStatus( static_cast<AIMProtocol*>( protocol() )->statusOnline ); //we're online
else
setOnlineStatus( static_cast<AIMProtocol*>( protocol() )->statusAway ); //we're away
}
void AIMMyselfContact::setOwnProfile( const TQString& newProfile )
{
m_profileString = newProfile;
if ( m_acct->isConnected() )
m_acct->engine()->updateProfile( newProfile );
}
TQString AIMMyselfContact::userProfile()
{
return m_profileString;
}
Kopete::ChatSession* AIMMyselfContact::manager( Kopete::Contact::CanCreateFlags canCreate,
Oscar::WORD exchange, const TQString& room )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << endl;
Kopete::ContactPtrList chatMembers;
chatMembers.append( this );
Kopete::ChatSession* genericManager = 0L;
genericManager = Kopete::ChatSessionManager::self()->findChatSession( account()->myself(), chatMembers, protocol() );
AIMChatSession* session = dynamic_cast<AIMChatSession*>( genericManager );
if ( !session && canCreate == Contact::CanCreate )
{
session = new AIMChatSession( this, chatMembers, account()->protocol(), exchange, room );
session->setEngine( m_acct->engine() );
connect( session, TQT_SIGNAL( messageSent( Kopete::Message&, Kopete::ChatSession* ) ),
this, TQT_SLOT( sendMessage( Kopete::Message&, Kopete::ChatSession* ) ) );
m_chatRoomSessions.append( session );
}
return session;
}
void AIMMyselfContact::chatSessionDestroyed( Kopete::ChatSession* session )
{
m_chatRoomSessions.remove( session );
}
void AIMMyselfContact::sendMessage( Kopete::Message& message, Kopete::ChatSession* session )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "sending a message" << endl;
//TODO: remove duplication - factor into a message utils class or something
Oscar::Message msg;
TQString s;
if (message.plainBody().isEmpty()) // no text, do nothing
return;
//okay, now we need to change the message.escapedBody from real HTML to aimhtml.
//looking right now for docs on that "format".
//looks like everything except for alignment codes comes in the format of spans
//font-style:italic -> <i>
//font-weight:600 -> <b> (anything > 400 should be <b>, 400 is not bold)
//text-decoration:underline -> <u>
//font-family: -> <font face="">
//font-size:xxpt -> <font ptsize=xx>
s=message.escapedBody();
s.replace ( TQRegExp( TQString::fromLatin1("<span style=\"([^\"]*)\">([^<]*)</span>")),
TQString::fromLatin1("<style>\\1;\"\\2</style>"));
s.replace ( TQRegExp( TQString::fromLatin1("<style>([^\"]*)font-style:italic;([^\"]*)\"([^<]*)</style>")),
TQString::fromLatin1("<i><style>\\1\\2\"\\3</style></i>"));
s.replace ( TQRegExp( TQString::fromLatin1("<style>([^\"]*)font-weight:600;([^\"]*)\"([^<]*)</style>")),
TQString::fromLatin1("<b><style>\\1\\2\"\\3</style></b>"));
s.replace ( TQRegExp( TQString::fromLatin1("<style>([^\"]*)text-decoration:underline;([^\"]*)\"([^<]*)</style>")),
TQString::fromLatin1("<u><style>\\1\\2\"\\3</style></u>"));
s.replace ( TQRegExp( TQString::fromLatin1("<style>([^\"]*)font-family:([^;]*);([^\"]*)\"([^<]*)</style>")),
TQString::fromLatin1("<font face=\"\\2\"><style>\\1\\3\"\\4</style></font>"));
s.replace ( TQRegExp( TQString::fromLatin1("<style>([^\"]*)font-size:([^p]*)pt;([^\"]*)\"([^<]*)</style>")),
TQString::fromLatin1("<font ptsize=\"\\2\"><style>\\1\\3\"\\4</style></font>"));
s.replace ( TQRegExp( TQString::fromLatin1("<style>([^\"]*)color:([^;]*);([^\"]*)\"([^<]*)</style>")),
TQString::fromLatin1("<font color=\"\\2\"><style>\\1\\3\"\\4</style></font>"));
s.replace ( TQRegExp( TQString::fromLatin1("<style>([^\"]*)\"([^<]*)</style>")),
TQString::fromLatin1("\\2"));
//okay now change the <font ptsize="xx"> to <font size="xx">
//0-9 are size 1
s.replace ( TQRegExp ( TQString::fromLatin1("<font ptsize=\"\\d\">")),
TQString::fromLatin1("<font size=\"1\">"));
//10-11 are size 2
s.replace ( TQRegExp ( TQString::fromLatin1("<font ptsize=\"1[01]\">")),
TQString::fromLatin1("<font size=\"2\">"));
//12-13 are size 3
s.replace ( TQRegExp ( TQString::fromLatin1("<font ptsize=\"1[23]\">")),
TQString::fromLatin1("<font size=\"3\">"));
//14-16 are size 4
s.replace ( TQRegExp ( TQString::fromLatin1("<font ptsize=\"1[456]\">")),
TQString::fromLatin1("<font size=\"4\">"));
//17-22 are size 5
s.replace ( TQRegExp ( TQString::fromLatin1("<font ptsize=\"(?:1[789]|2[012])\">")),
TQString::fromLatin1("<font size=\"5\">"));
//23-29 are size 6
s.replace ( TQRegExp ( TQString::fromLatin1("<font ptsize=\"2[3456789]\">")),TQString::fromLatin1("<font size=\"6\">"));
//30- (and any I missed) are size 7
s.replace ( TQRegExp ( TQString::fromLatin1("<font ptsize=\"[^\"]*\">")),TQString::fromLatin1("<font size=\"7\">"));
s.replace ( TQRegExp ( TQString::fromLatin1("<br[ /]*>")), TQString::fromLatin1("<br>") );
kdDebug(14190) << k_funcinfo << "sending "
<< s << endl;
msg.setSender( contactId() );
msg.setText( Oscar::Message::UserDefined, s, m_acct->defaultCodec() );
msg.setTimestamp(message.timestamp());
msg.setType(0x03);
msg.addProperty( Oscar::Message::ChatRoom );
AIMChatSession* aimSession = dynamic_cast<AIMChatSession*>( session );
if ( !aimSession )
{
kdWarning(OSCAR_AIM_DEBUG) << "couldn't convert to AIM chat room session!" << endl;
session->messageSucceeded();
return;
}
msg.setExchange( aimSession->exchange() );
msg.setChatRoom( aimSession->roomName() );
m_acct->engine()->sendMessage( msg );
//session->appendMessage( message );
session->messageSucceeded();
}
AIMAccount::AIMAccount(Kopete::Protocol *parent, TQString accountID, const char *name)
: OscarAccount(parent, accountID, name, false)
{
kdDebug(14152) << k_funcinfo << accountID << ": Called."<< endl;
AIMMyselfContact* mc = new AIMMyselfContact( this );
setMyself( mc );
myself()->setOnlineStatus( static_cast<AIMProtocol*>( parent )->statusOffline );
TQString profile = configGroup()->readEntry( "Profile",
i18n( "Visit the Kopete website at <a href=\"http://kopete.kde.org\">http://kopete.kde.org</a>") );
mc->setOwnProfile( profile );
m_joinChatDialog = 0;
m_visibilityDialog = 0;
TQObject::connect( Kopete::ContactList::self(),
TQT_SIGNAL( globalIdentityChanged( const TQString&, const TQVariant& ) ),
this,
TQT_SLOT( slotGlobalIdentityChanged( const TQString&, const TQVariant& ) ) );
TQObject::connect( engine(), TQT_SIGNAL( chatRoomConnected( WORD, const TQString& ) ),
this, TQT_SLOT( connectedToChatRoom( WORD, const TQString& ) ) );
TQObject::connect( engine(), TQT_SIGNAL( userJoinedChat( Oscar::WORD, const TQString&, const TQString& ) ),
this, TQT_SLOT( userJoinedChat( Oscar::WORD, const TQString&, const TQString& ) ) );
TQObject::connect( engine(), TQT_SIGNAL( userLeftChat( Oscar::WORD, const TQString&, const TQString& ) ),
this, TQT_SLOT( userLeftChat( Oscar::WORD, const TQString&, const TQString& ) ) );
TQObject::connect( this, TQT_SIGNAL( buddyIconChanged() ), this, TQT_SLOT( slotBuddyIconChanged() ) );
}
AIMAccount::~AIMAccount()
{
}
OscarContact *AIMAccount::createNewContact( const TQString &contactId, Kopete::MetaContact *parentContact, const SSI& ssiItem )
{
AIMContact* contact = new AIMContact( this, contactId, parentContact, TQString(), ssiItem );
if ( !ssiItem.alias().isEmpty() )
contact->setProperty( Kopete::Global::Properties::self()->nickName(), ssiItem.alias() );
return contact;
}
TQString AIMAccount::sanitizedMessage( const TQString& message )
{
TQDomDocument doc;
TQString domError;
int errLine = 0, errCol = 0;
doc.setContent( message, false, &domError, &errLine, &errCol );
if ( !domError.isEmpty() ) //error parsing, do nothing
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "error from dom document conversion: "
<< domError << endl;
return message;
}
else
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "conversion to dom document successful."
<< "looking for font tags" << endl;
TQDomNodeList fontTagList = doc.elementsByTagName( "font" );
if ( fontTagList.count() == 0 )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "No font tags found. Returning normal message" << endl;
return message;
}
else
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "Found font tags. Attempting replacement" << endl;
uint numFontTags = fontTagList.count();
for ( uint i = 0; i < numFontTags; i++ )
{
TQDomNode fontNode = fontTagList.item(i);
TQDomElement fontEl;
if ( !fontNode.isNull() && fontNode.isElement() )
fontEl = fontTagList.item(i).toElement();
else
continue;
if ( fontEl.hasAttribute( "back" ) )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "Found attribute to replace. Doing replacement" << endl;
TQString backgroundColor = fontEl.attribute( "back" );
backgroundColor.insert( 0, "background-color: " );
backgroundColor.append( ';' );
fontEl.setAttribute( "style", backgroundColor );
fontEl.removeAttribute( "back" );
}
}
}
}
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "sanitized message is " << doc.toString();
return doc.toString();
}
TDEActionMenu* AIMAccount::actionMenu()
{
// kdDebug(14152) << k_funcinfo << accountId() << ": Called." << endl;
// mActionMenu is managed by Kopete::Account. It is deleted when
// it is no longer shown, so we can (safely) just make a new one here.
TDEActionMenu *mActionMenu = new TDEActionMenu(accountId(),
myself()->onlineStatus().iconFor( this ), this, "AIMAccount::mActionMenu");
AIMProtocol *p = AIMProtocol::protocol();
TQString accountNick = myself()->property( Kopete::Global::Properties::self()->nickName() ).value().toString();
mActionMenu->popupMenu()->insertTitle( myself()->onlineStatus().iconFor( myself() ),
i18n( "%2 <%1>" ).arg( accountId(), accountNick ));
mActionMenu->insert( new TDEAction( i18n("Online"), p->statusOnline.iconFor( this ), 0, this,
TQT_SLOT( slotGoOnline() ), mActionMenu, "AIMAccount::mActionOnline") );
TDEAction* mActionAway = new Kopete::AwayAction(i18n("Away"), p->statusAway.iconFor( this ), 0, this,
TQT_SLOT(slotGoAway( const TQString & )), this, "AIMAccount::mActionNA" );
mActionAway->setEnabled( isConnected() );
mActionMenu->insert( mActionAway );
TDEAction* mActionOffline = new TDEAction( i18n("Offline"), p->statusOffline.iconFor(this), 0, this,
TQT_SLOT( slotGoOffline() ), mActionMenu, "AIMAccount::mActionOffline");
mActionMenu->insert( mActionOffline );
mActionMenu->popupMenu()->insertSeparator();
TDEAction* m_joinChatAction = new TDEAction( i18n( "Join Chat..." ), TQString(), 0, this,
TQT_SLOT( slotJoinChat() ), mActionMenu, "join_a_chat" );
mActionMenu->insert( new TDEToggleAction( i18n( "Set Visibility..." ), 0, 0,
this, TQT_SLOT( slotSetVisiblility() ), this,
"AIMAccount::mActionSetVisibility") );
mActionMenu->insert( m_joinChatAction );
TDEAction* m_editInfoAction = new TDEAction( i18n( "Edit User Info..." ), "identity", 0,
this, TQT_SLOT( slotEditInfo() ), mActionMenu, "actionEditInfo");
mActionMenu->insert( m_editInfoAction );
return mActionMenu;
}
void AIMAccount::setAway(bool away, const TQString &awayReason)
{
// kdDebug(14152) << k_funcinfo << accountId() << "reason is " << awayReason << endl;
if ( away )
{
engine()->setStatus( Client::Away, awayReason );
AIMMyselfContact* me = static_cast<AIMMyselfContact *> ( myself() );
me->setLastAwayMessage(awayReason);
me->setProperty( Kopete::Global::Properties::self()->awayMessage(), awayReason );
}
else
{
engine()->setStatus( Client::Online );
AIMMyselfContact* me = static_cast<AIMMyselfContact *> ( myself() );
me->setLastAwayMessage(TQString());
me->removeProperty( Kopete::Global::Properties::self()->awayMessage() );
}
}
void AIMAccount::setOnlineStatus( const Kopete::OnlineStatus& status, const TQString& reason )
{
kdDebug(14152) << k_funcinfo << "called with reason = " << reason <<" status = "<< status.status() << endl;;
if ( status.status() == Kopete::OnlineStatus::Online )
setAway( false );
if ( status.status() == Kopete::OnlineStatus::Away )
setAway( true, reason );
}
void AIMAccount::setUserProfile(const TQString &profile)
{
kdDebug(14152) << k_funcinfo << "called." << endl;
AIMMyselfContact* aimmc = dynamic_cast<AIMMyselfContact*>( myself() );
if ( aimmc )
aimmc->setOwnProfile( profile );
configGroup()->writeEntry( TQString::fromLatin1( "Profile" ), profile );
}
void AIMAccount::slotEditInfo()
{
if ( !isConnected() )
{
KMessageBox::sorry( Kopete::UI::Global::mainWidget(),
i18n( "Editing your user info is not possible because "
"you are not connected." ),
i18n( "Unable to edit user info" ) );
return;
}
AIMUserInfoDialog *myInfo = new AIMUserInfoDialog(static_cast<AIMContact *>( myself() ), this, true, 0L, "myInfo");
myInfo->exec(); // This is a modal dialog
}
void AIMAccount::slotGlobalIdentityChanged( const TQString& key, const TQVariant& value )
{
//do something with the photo
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "Global identity changed" << endl;
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "key: " << key << endl;
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "value: " << value << endl;
if( !configGroup()->readBoolEntry("ExcludeGlobalIdentity", false) )
{
if ( key == Kopete::Global::Properties::self()->nickName().key() )
{
//edit ssi item to change alias (if possible)
}
if ( key == Kopete::Global::Properties::self()->photo().key() )
{
setBuddyIcon( value.toString() );
}
}
}
void AIMAccount::slotBuddyIconChanged()
{
// need to disconnect because we could end up with many connections
TQObject::disconnect( engine(), TQT_SIGNAL( iconServerConnected() ), this, TQT_SLOT( slotBuddyIconChanged() ) );
if ( !engine()->isActive() )
{
TQObject::connect( engine(), TQT_SIGNAL( iconServerConnected() ), this, TQT_SLOT( slotBuddyIconChanged() ) );
return;
}
TQString photoPath = myself()->property( Kopete::Global::Properties::self()->photo() ).value().toString();
SSIManager* ssi = engine()->ssiManager();
Oscar::SSI item = ssi->findItemForIconByRef( 1 );
if ( photoPath.isEmpty() )
{
if ( item )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "Removing icon hash item from ssi" << endl;
Oscar::SSI s(item);
//remove hash and alias
TQValueList<TLV> tList( item.tlvList() );
TLV t = Oscar::findTLV( tList, 0x00D5 );
if ( t )
tList.remove( t );
item.setTLVList( tList );
//s is old, item is new. modification will occur
engine()->modifySSIItem( s, item );
}
}
else
{
TQFile iconFile( photoPath );
iconFile.open( IO_ReadOnly );
KMD5 iconHash;
iconHash.update( *TQT_TQIODEVICE(&iconFile) );
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "hash is :" << iconHash.hexDigest() << endl;
//find old item, create updated item
if ( !item )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "no existing icon hash item in ssi. creating new" << endl;
TLV t;
t.type = 0x00D5;
t.data.resize( 18 );
t.data[0] = 0x00;
t.data[1] = 0x10;
memcpy(t.data.data() + 2, iconHash.rawDigest(), 16);
t.length = t.data.size();
TQValueList<Oscar::TLV> list;
list.append( t );
Oscar::SSI s( "1", 0, ssi->nextContactId(), ROSTER_BUDDYICONS, list );
//item is a non-valid ssi item, so the function will add an item
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "setting new icon item" << endl;
engine()->modifySSIItem( item, s );
}
else
{ //found an item
Oscar::SSI s(item);
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "modifying old item in ssi." << endl;
TQValueList<TLV> tList( item.tlvList() );
TLV t = Oscar::findTLV( tList, 0x00D5 );
if ( t )
tList.remove( t );
else
t.type = 0x00D5;
t.data.resize( 18 );
t.data[0] = 0x00;
t.data[1] = 0x10;
memcpy(t.data.data() + 2, iconHash.rawDigest(), 16);
t.length = t.data.size();
tList.append( t );
item.setTLVList( tList );
//s is old, item is new. modification will occur
engine()->modifySSIItem( s, item );
}
iconFile.close();
}
}
void AIMAccount::slotJoinChat()
{
if ( !isConnected() )
{
KMessageBox::sorry( Kopete::UI::Global::mainWidget(),
i18n( "Joining an AIM chat room is not possible because "
"you are not connected." ),
i18n( "Unable to Join AIM Chat Room" ) );
return;
}
//get the exchange info
//create the dialog
//join the chat room
if ( !m_joinChatDialog )
{
m_joinChatDialog = new AIMJoinChatUI( this, false, Kopete::UI::Global::mainWidget() );
TQObject::connect( m_joinChatDialog, TQT_SIGNAL( closing( int ) ),
this, TQT_SLOT( joinChatDialogClosed( int ) ) );
TQValueList<int> list = engine()->chatExchangeList();
m_joinChatDialog->setExchangeList( list );
m_joinChatDialog->show();
}
else
m_joinChatDialog->raise();
}
void AIMAccount::slotGoOnline()
{
if ( myself()->onlineStatus().status() == Kopete::OnlineStatus::Away )
{
kdDebug(14152) << k_funcinfo << accountId() << " was away. welcome back." << endl;
engine()->setStatus( Client::Online );
myself()->removeProperty( Kopete::Global::Properties::self()->awayMessage() );
}
else if ( myself()->onlineStatus().status() == Kopete::OnlineStatus::Offline )
{
kdDebug(14152) << k_funcinfo << accountId() << " was offline. time to connect" << endl;
OscarAccount::connect();
}
else
{
kdDebug(14152) << k_funcinfo << accountId() << " is already online, doing nothing" << endl;
}
}
void AIMAccount::slotGoAway(const TQString &message)
{
kdDebug(14152) << k_funcinfo << message << endl;
setAway(true, message);
}
void AIMAccount::joinChatDialogClosed( int code )
{
if ( code == TQDialog::Accepted )
{
//join the chat
kdDebug(14152) << k_funcinfo << "chat accepted." << endl;
engine()->joinChatRoom( m_joinChatDialog->roomName(),
m_joinChatDialog->exchange().toInt() );
}
m_joinChatDialog->delayedDestruct();
m_joinChatDialog = 0L;
}
void AIMAccount::loginActions()
{
OscarAccount::loginActions();
using namespace AIM::PrivacySettings;
int privacySetting = this->configGroup()->readNumEntry( "PrivacySetting", AllowAll );
this->setPrivacySettings( privacySetting );
}
void AIMAccount::disconnected( DisconnectReason reason )
{
kdDebug( OSCAR_AIM_DEBUG ) << k_funcinfo << "Attempting to set status offline" << endl;
myself()->setOnlineStatus( static_cast<AIMProtocol*>( protocol() )->statusOffline );
TQDictIterator<Kopete::Contact> it( contacts() );
for( ; it.current(); ++it )
{
OscarContact* oc = dynamic_cast<OscarContact*>( it.current() );
if ( oc )
oc->setOnlineStatus( static_cast<AIMProtocol*>( protocol() )->statusOffline );
}
OscarAccount::disconnected( reason );
}
void AIMAccount::messageReceived( const Oscar::Message& message )
{
kdDebug(14152) << k_funcinfo << " Got a message, calling OscarAccount::messageReceived" << endl;
// Want to call the parent to do everything else
if ( message.type() != 0x0003 )
{
OscarAccount::messageReceived(message);
// Check to see if our status is away, and send an away message
// Might be duplicate code from the parent class to get some needed information
// Perhaps a refactoring is needed.
kdDebug(14152) << k_funcinfo << "Checking to see if I'm online.." << endl;
if( myself()->onlineStatus().status() == Kopete::OnlineStatus::Away )
{
TQString sender = Oscar::normalize( message.sender() );
AIMContact* aimSender = static_cast<AIMContact *> ( contacts()[sender] ); //should exist now
if ( !aimSender )
{
kdWarning(OSCAR_RAW_DEBUG) << "For some reason, could not get the contact "
<< "That this message is from: " << message.sender() << ", Discarding message" << endl;
return;
}
// Create, or get, a chat session with the contact
Kopete::ChatSession* chatSession = aimSender->manager( Kopete::Contact::CanCreate );
// get the away message we have set
AIMMyselfContact* myContact = static_cast<AIMMyselfContact *> ( myself() );
TQString msg = myContact->lastAwayMessage();
kdDebug(14152) << k_funcinfo << "Got away message: " << msg << endl;
// Create the message
Kopete::Message chatMessage( myself(), aimSender, msg, Kopete::Message::Outbound,
Kopete::Message::RichText );
kdDebug(14152) << k_funcinfo << "Sending autoresponse" << endl;
// Send the message
aimSender->sendAutoResponse( chatMessage );
}
}
if ( message.type() == 0x0003 )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "have chat message" << endl;
//handle chat room messages seperately
TQValueList<Kopete::ChatSession*> chats = Kopete::ChatSessionManager::self()->sessions();
TQValueList<Kopete::ChatSession*>::iterator it, itEnd = chats.end();
for ( it = chats.begin(); it != itEnd; ++it )
{
Kopete::ChatSession* kcs = ( *it );
AIMChatSession* session = dynamic_cast<AIMChatSession*>( kcs );
if ( !session )
continue;
if ( session->exchange() == message.exchange() &&
Oscar::normalize( session->roomName() ) ==
Oscar::normalize( message.chatRoom() ) )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "found chat session for chat room" << endl;
Kopete::Contact* ocSender = contacts()[Oscar::normalize( message.sender() )];
//sanitize;
TQString sanitizedMsg = sanitizedMessage( message.text( defaultCodec() ) );
Kopete::ContactPtrList me;
me.append( myself() );
Kopete::Message chatMessage( message.timestamp(), ocSender, me, sanitizedMsg,
Kopete::Message::Inbound, Kopete::Message::RichText );
session->appendMessage( chatMessage );
}
}
}
}
void AIMAccount::connectedToChatRoom( WORD exchange, const TQString& room )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "Creating chat room session" << endl;
Kopete::ContactPtrList emptyList;
AIMMyselfContact* me = static_cast<AIMMyselfContact*>( myself() );
AIMChatSession* session = dynamic_cast<AIMChatSession*>( me->manager( Kopete::Contact::CanCreate,
exchange, room ) );
session->setDisplayName( room );
if ( session->view( true ) )
session->raiseView();
}
void AIMAccount::userJoinedChat( WORD exchange, const TQString& room, const TQString& contact )
{
if ( Oscar::normalize( contact ) == Oscar::normalize( myself()->contactId() ) )
return;
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "user " << contact << " has joined the chat" << endl;
TQValueList<Kopete::ChatSession*> chats = Kopete::ChatSessionManager::self()->sessions();
TQValueList<Kopete::ChatSession*>::iterator it, itEnd = chats.end();
for ( it = chats.begin(); it != itEnd; ++it )
{
Kopete::ChatSession* kcs = ( *it );
AIMChatSession* session = dynamic_cast<AIMChatSession*>( kcs );
if ( !session )
continue;
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << session->exchange() << " " << exchange << endl;
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << session->roomName() << " " << room << endl;
if ( session->exchange() == exchange && session->roomName() == room )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "found correct chat session" << endl;
Kopete::Contact* c;
if ( contacts()[Oscar::normalize( contact )] )
c = contacts()[Oscar::normalize( contact )];
else
{
Kopete::MetaContact* mc = addContact( Oscar::normalize( contact ),
contact, 0, Kopete::Account::Temporary );
if ( !mc )
kdWarning(OSCAR_AIM_DEBUG) << "Unable to add contact for chat room" << endl;
c = mc->contacts().first();
c->setNickName( contact );
}
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "adding contact" << endl;
session->addContact( c, static_cast<AIMProtocol*>( protocol() )->statusOnline, true /* suppress */ );
}
}
}
void AIMAccount::userLeftChat( WORD exchange, const TQString& room, const TQString& contact )
{
if ( Oscar::normalize( contact ) == Oscar::normalize( myself()->contactId() ) )
return;
TQValueList<Kopete::ChatSession*> chats = Kopete::ChatSessionManager::self()->sessions();
TQValueList<Kopete::ChatSession*>::iterator it, itEnd = chats.end();
for ( it = chats.begin(); it != itEnd; ++it )
{
Kopete::ChatSession* kcs = ( *it );
AIMChatSession* session = dynamic_cast<AIMChatSession*>( kcs );
if ( !session )
continue;
if ( session->exchange() == exchange && session->roomName() == room )
{
//delete temp contact
Kopete::Contact* c = contacts()[Oscar::normalize( contact )];
if ( !c )
{
kdWarning(OSCAR_AIM_DEBUG) << k_funcinfo << "couldn't find the contact that's left the chat!" << endl;
continue;
}
session->removeContact( c );
Kopete::MetaContact* mc = c->metaContact();
if ( mc->isTemporary() )
{
mc->removeContact( c );
delete c;
delete mc;
}
}
}
}
void AIMAccount::connectWithPassword( const TQString & )
{
kdDebug(14152) << k_funcinfo << "accountId='" << accountId() << "'" << endl;
// Get the screen name for this account
TQString screenName = accountId();
TQString server = configGroup()->readEntry( "Server", TQString::fromLatin1( "login.oscar.aol.com" ) );
uint port = configGroup()->readNumEntry( "Port", 5190 );
Connection* c = setupConnection( server, port );
TQString _password = password().cachedValue();
if ( _password.isEmpty() )
{
kdDebug(14150) << "Kopete is unable to attempt to sign-on to the "
<< "AIM network because no password was specified in the "
<< "preferences." << endl;
}
else if ( myself()->onlineStatus() == static_cast<AIMProtocol*>( protocol() )->statusOffline )
{
kdDebug(14152) << k_funcinfo << "Logging in as " << accountId() << endl ;
updateVersionUpdaterStamp();
engine()->start( server, port, accountId(), _password );
engine()->connectToServer( c, server, true /* doAuth */ );
myself()->setOnlineStatus( static_cast<AIMProtocol*>( protocol() )->statusConnecting );
}
}
void AIMAccount::slotSetVisiblility()
{
if( !isConnected() )
{
KMessageBox::sorry( Kopete::UI::Global::mainWidget(),
i18n("You must be online to set users visibility."),
i18n("ICQ Plugin") );
return;
}
if ( !m_visibilityDialog )
{
m_visibilityDialog = new OscarVisibilityDialog( engine(), Kopete::UI::Global::mainWidget() );
TQObject::connect( m_visibilityDialog, TQT_SIGNAL( closing() ),
this, TQT_SLOT( slotVisibilityDialogClosed() ) );
//add all contacts;
OscarVisibilityDialog::ContactMap contactMap;
TQMap<TQString, TQString> revContactMap;
TQValueList<Oscar::SSI> contactList = engine()->ssiManager()->contactList();
TQValueList<Oscar::SSI>::const_iterator it, cEnd = contactList.constEnd();
for ( it = contactList.constBegin(); it != cEnd; ++it )
{
TQString contactId = ( *it ).name();
OscarContact* oc = dynamic_cast<OscarContact*>( contacts()[( *it ).name()] );
if ( oc )
{
contactMap.insert( oc->nickName(), contactId );
revContactMap.insert( contactId, oc->nickName() );
}
else
{
contactMap.insert( contactId, contactId );
revContactMap.insert( contactId, contactId );
}
}
m_visibilityDialog->addContacts( contactMap );
//add contacts from visible list
TQStringList tmpList;
contactList = engine()->ssiManager()->visibleList();
cEnd = contactList.constEnd();
for ( it = contactList.constBegin(); it != cEnd; ++it )
tmpList.append( revContactMap[( *it ).name()] );
m_visibilityDialog->addVisibleContacts( tmpList );
//add contacts from invisible list
tmpList.clear();
contactList = engine()->ssiManager()->invisibleList();
cEnd = contactList.constEnd();
for ( it = contactList.constBegin(); it != cEnd; ++it )
tmpList.append( revContactMap[( *it ).name()] );
m_visibilityDialog->addInvisibleContacts( tmpList );
m_visibilityDialog->resize( 550, 350 );
m_visibilityDialog->show();
}
else
{
m_visibilityDialog->raise();
}
}
void AIMAccount::slotVisibilityDialogClosed()
{
m_visibilityDialog->delayedDestruct();
m_visibilityDialog = 0L;
}
void AIMAccount::setPrivacySettings( int privacy )
{
using namespace AIM::PrivacySettings;
BYTE privacyByte = 0x01;
DWORD userClasses = 0xFFFFFFFF;
switch ( privacy )
{
case AllowAll:
privacyByte = 0x01;
break;
case BlockAll:
privacyByte = 0x02;
break;
case AllowPremitList:
privacyByte = 0x03;
break;
case BlockDenyList:
privacyByte = 0x04;
break;
case AllowMyContacts:
privacyByte = 0x05;
break;
case BlockAIM:
privacyByte = 0x01;
userClasses = 0x00000004;
break;
}
this->setPrivacyTLVs( privacyByte, userClasses );
}
void AIMAccount::setPrivacyTLVs( BYTE privacy, DWORD userClasses )
{
SSIManager* ssi = engine()->ssiManager();
Oscar::SSI item = ssi->findItem( TQString(), ROSTER_VISIBILITY );
TQValueList<Oscar::TLV> tList;
tList.append( TLV( 0x00CA, 1, (char *)&privacy ) );
tList.append( TLV( 0x00CB, sizeof(userClasses), (char *)&userClasses ) );
if ( !item )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "Adding new privacy TLV item" << endl;
Oscar::SSI s( TQString(), 0, ssi->nextContactId(), ROSTER_VISIBILITY, tList );
engine()->modifySSIItem( item, s );
}
else
{ //found an item
Oscar::SSI s(item);
if ( Oscar::uptateTLVs( s, tList ) == true )
{
kdDebug(OSCAR_AIM_DEBUG) << k_funcinfo << "Updating privacy TLV item" << endl;
engine()->modifySSIItem( item, s );
}
}
}
#include "aimaccount.moc"
//kate: tab-width 4; indent-mode csands;
|