summaryrefslogtreecommitdiffstats
path: root/ksirc/messageReceiver.cpp
blob: f2ac6ee0dc26d504afad4f8efa1cde7e92c7d52b (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
#include "messageReceiver.h"

#include <qtextcodec.h>
#include <kcharsets.h>
#include <kglobal.h>
#include <kdebug.h>
#include <assert.h>

KSircMessageReceiver::KSircMessageReceiver( KSircProcess * _proc )
{
    proc = _proc;
    broadcast = TRUE;
}

KSircMessageReceiver::~KSircMessageReceiver()
{
}

void KSircMessageReceiver::setBroadcast(bool bd)
{
  broadcast = bd;
}

bool KSircMessageReceiver::getBroadcast()
{
  return broadcast;
}

filterRuleList *KSircMessageReceiver::defaultRules()
{
  return new filterRuleList();
}

UnicodeMessageReceiver::UnicodeMessageReceiver( KSircProcess *process )
    : KSircMessageReceiver( process ), m_encoder( 0 )
{
}

void UnicodeMessageReceiver::sirc_receive( QCString str, bool broadcast )
{
    assert( encoder() );
    //kdDebug(5008) << "Encoder: " << encoder()->name() << endl;
    //kdDebug(5008) << "It gives us: " << encoder()->toUnicode( str ).utf8() << endl;
    sirc_receive( encoder()->toUnicode( str ), broadcast );
}

void UnicodeMessageReceiver::setEncoding( const QString &encoding )
{
    m_encoding = encoding;
    m_encoder = 0;
}

QString UnicodeMessageReceiver::encoding() const
{
    if ( m_encoding.isEmpty() )
	return QTextCodec::codecForLocale()->mimeName();
    return m_encoding;
}

QTextCodec *UnicodeMessageReceiver::encoder() const
{
    if ( m_encoding.isEmpty() ) {
	return QTextCodec::codecForLocale();
    }

    if ( !m_encoder ) {
	const_cast<UnicodeMessageReceiver *>( this )->m_encoder = KGlobal::charsets()->codecForName( m_encoding );
	assert( m_encoder );
    }

    return m_encoder;
}