summaryrefslogtreecommitdiffstats
path: root/konversation/src/identity.cpp
blob: 30fea936f176db4b9089f7bf58faa0a05438d7d5 (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
/*
  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.
*/

/*
  This class holds the various user identities
  begin: Son Feb 9 2003
  copyright: (C) 2003 by Dario Abatianni
  email: eisfuchs@tigress.com
*/

#include "identity.h"
#include "irccharsets.h"

#include <tqtextcodec.h>

#include <kdebug.h>
#include <kglobal.h>


int Identity::s_availableId = 0;

Identity::Identity() : KShared()
{
    m_id = s_availableId;
    s_availableId++;

    init();
}

Identity::Identity(int id) : KShared()
{
    if (id < 0)
    {
        m_id = s_availableId;
        s_availableId++;
    }
    else
    {
        m_id = id;
    }

    init();
}

Identity::Identity(const Identity& original) : KShared()
{
    copy(original);
    m_id = original.id();
}

Identity::~Identity()
{
}

void Identity::init()
{
    setCodecName(Konversation::IRCCharsets::self()->encodingForLocale());

    setInsertRememberLineOnAway(false);

    setQuitReason("Konversation terminated!");
    setPartReason("Konversation terminated!");
    setKickReason("User terminated!");

    setShowAwayMessage(false);
    setAwayMessage("/me is away: %s");
    setReturnMessage("/me is back.");

    setAutomaticAway(false);
    setAwayInactivity(10);
    setAutomaticUnaway(false);
}

void Identity::copy(const Identity& original)
{
    setName(original.getName());
    setRealName(original.getRealName());
    setIdent(original.getIdent());
    setNicknameList(original.getNicknameList());
    setBot(original.getBot());
    setPassword(original.getPassword());
    setQuitReason(original.getQuitReason());
    setPartReason(original.getPartReason());
    setKickReason(original.getKickReason());
    setInsertRememberLineOnAway(original.getInsertRememberLineOnAway());
    setShowAwayMessage(original.getShowAwayMessage());
    setAwayMessage(original.getAwayMessage());
    setAwayNick(original.getAwayNick());
    setReturnMessage(original.getReturnMessage());
    setAutomaticAway(original.getAutomaticAway());
    setAwayInactivity(original.getAwayInactivity());
    setAutomaticUnaway(original.getAutomaticUnaway());
    setShellCommand(original.getShellCommand());
    setCodecName(original.getCodecName());
}

void Identity::setName(const TQString& newName)          { name=newName; }
TQString Identity::getName() const                       { return name; }

void Identity::setRealName(const TQString& name)         { realName=name; }
TQString Identity::getRealName() const                   { return realName; }
void Identity::setIdent(const TQString& newIdent)        { ident=newIdent; }
TQString Identity::getIdent() const                      { return ident; }

void Identity::setNickname(uint index,const TQString& newName) { nicknameList[index]=newName; }

TQString Identity::getNickname(uint index) const 
{
  if(index < nicknameList.count())
    return nicknameList[index];
  else
    return TQString();
}

void Identity::setBot(const TQString& newBot)            { bot=newBot; }
TQString Identity::getBot() const                        { return bot; }

void Identity::setPassword(const TQString& newPassword)  { password=newPassword; }
TQString Identity::getPassword() const                   { return password; }

void Identity::setQuitReason(const TQString& reason)     { quitReason=reason; }
TQString Identity::getQuitReason() const                 { return quitReason; }
void Identity::setPartReason(const TQString& reason)     { partReason=reason; }
TQString Identity::getPartReason() const                 { return partReason; }
void Identity::setKickReason(const TQString& reason)     { kickReason=reason; }
TQString Identity::getKickReason() const                 { return kickReason; }

void Identity::setInsertRememberLineOnAway(bool state) { insertRememberLineOnAway = state; }
bool Identity::getInsertRememberLineOnAway() const { return insertRememberLineOnAway; }
void Identity::setShowAwayMessage(bool state)           { showAwayMessages=state; }
bool Identity::getShowAwayMessage() const               { return showAwayMessages; }

void Identity::setAwayMessage(const TQString& message)   { awayMessage=message; }
TQString Identity::getAwayMessage() const                { return awayMessage; }
void Identity::setReturnMessage(const TQString& message) { returnMessage=message; }
TQString Identity::getReturnMessage() const              { return returnMessage; }

void Identity::setAutomaticAway(bool automaticAway)     { m_automaticAway = automaticAway; }
bool Identity::getAutomaticAway() const                 { return m_automaticAway; }
void Identity::setAwayInactivity(int awayInactivity)   { m_awayInactivity = awayInactivity; }
int Identity::getAwayInactivity() const                { return m_awayInactivity; }
void Identity::setAutomaticUnaway(bool automaticUnaway) { m_automaticUnaway = automaticUnaway; }
bool Identity::getAutomaticUnaway() const               { return m_automaticUnaway; }

void Identity::setNicknameList(const TQStringList& newList)
{
    nicknameList.clear();
    nicknameList = newList;
}

TQStringList Identity::getNicknameList() const           { return nicknameList; }

TQString Identity::getShellCommand() const { return m_shellCommand;}
void Identity::setShellCommand(const TQString& command) { m_shellCommand=command;}

TQTextCodec* Identity::getCodec() const                  { return m_codec; }
TQString Identity::getCodecName() const                  { return m_codecName; }
void Identity::setCodecName(const TQString &newCodecName)
{
    // NOTE: codecName should be based on KCharsets::availableEncodingNames() / descriptiveEncodingNames()
    // We can get a TQTextCodec from TQString based on them, but can't do the reverse of that.

    // never set an empty or borked codec!
    TQString codecName=newCodecName.lower();
    if(!Konversation::IRCCharsets::self()->isValidEncoding(codecName))
        codecName=Konversation::IRCCharsets::self()->encodingForLocale();

    m_codecName=codecName;
    m_codec=Konversation::IRCCharsets::self()->codecForName(codecName);
}

TQString Identity::getAwayNick() const { return awayNick; }
void Identity::setAwayNick(const TQString& n) { awayNick = n; }