1 /* 2 SPDX-License-Identifier: GPL-2.0-or-later 3 4 SPDX-FileCopyrightText: 2003 Dario Abatianni <eisfuchs@tigress.com> 5 */ 6 7 #include "identity.h" 8 #include "irccharsets.h" 9 10 #include <QTextCodec> 11 12 13 int Identity::s_availableId = 0; 14 Identity()15Identity::Identity() : QSharedData() 16 { 17 m_id = s_availableId; 18 s_availableId++; 19 20 init(); 21 } 22 Identity(int id)23Identity::Identity(int id) : QSharedData() 24 { 25 if (id < 0) 26 { 27 m_id = s_availableId; 28 s_availableId++; 29 } 30 else 31 { 32 m_id = id; 33 } 34 35 init(); 36 } 37 Identity(const Identity & original)38Identity::Identity(const Identity& original) : QSharedData() 39 { 40 copy(original); 41 m_id = original.id(); 42 } 43 ~Identity()44Identity::~Identity() 45 { 46 } 47 init()48void Identity::init() 49 { 50 setAuthType(QStringLiteral("saslplain")); 51 setNickservNickname(QStringLiteral("nickserv")); 52 setNickservCommand(QStringLiteral("identify")); 53 54 setCodecName(Konversation::IRCCharsets::self()->encodingForLocale()); 55 56 setInsertRememberLineOnAway(false); 57 58 setQuitReason(QStringLiteral("Konversation terminated!")); 59 setPartReason(QStringLiteral("Konversation terminated!")); 60 setKickReason(QStringLiteral("User terminated!")); 61 62 setAwayMessage(QStringLiteral("Gone away for now")); 63 64 setRunAwayCommands(false); 65 66 setAutomaticAway(false); 67 setAwayInactivity(10); 68 setAutomaticUnaway(false); 69 } 70 copy(const Identity & original)71void Identity::copy(const Identity& original) 72 { 73 setName(original.getName()); 74 setRealName(original.getRealName()); 75 setIdent(original.getIdent()); 76 setNicknameList(original.getNicknameList()); 77 setAuthType(original.getAuthType()); 78 setAuthPassword(original.getAuthPassword()); 79 setNickservNickname(original.getNickservNickname()); 80 setNickservCommand(original.getNickservCommand()); 81 setSaslAccount(original.getSaslAccount()); 82 setPemClientCertFile(original.getPemClientCertFile()); 83 setQuitReason(original.getQuitReason()); 84 setPartReason(original.getPartReason()); 85 setKickReason(original.getKickReason()); 86 setInsertRememberLineOnAway(original.getInsertRememberLineOnAway()); 87 setRunAwayCommands(original.getRunAwayCommands()); 88 setAwayCommand(original.getAwayCommand()); 89 setAwayMessage(original.getAwayMessage()); 90 setAwayNickname(original.getAwayNickname()); 91 setReturnCommand(original.getReturnCommand()); 92 setAutomaticAway(original.getAutomaticAway()); 93 setAwayInactivity(original.getAwayInactivity()); 94 setAutomaticUnaway(original.getAutomaticUnaway()); 95 setShellCommand(original.getShellCommand()); 96 setCodecName(original.getCodecName()); 97 } 98 setName(const QString & newName)99void Identity::setName(const QString& newName) { name=newName; } getName() const100QString Identity::getName() const { return name; } 101 setRealName(const QString & name)102void Identity::setRealName(const QString& name) { realName=name; } getRealName() const103QString Identity::getRealName() const { return realName; } setIdent(const QString & newIdent)104void Identity::setIdent(const QString& newIdent) { ident=newIdent; } getIdent() const105QString Identity::getIdent() const { return ident; } 106 setNickname(uint index,const QString & newName)107void Identity::setNickname(uint index,const QString& newName) { nicknameList[index]=newName; } 108 getNickname(int index) const109QString Identity::getNickname(int index) const 110 { 111 return nicknameList.value(index); 112 } 113 setAuthType(const QString & authType)114void Identity::setAuthType(const QString& authType) { m_authType = authType; } getAuthType() const115QString Identity::getAuthType() const { return m_authType; } setAuthPassword(const QString & authPassword)116void Identity::setAuthPassword(const QString& authPassword) { m_authPassword = authPassword; } getAuthPassword() const117QString Identity::getAuthPassword() const { return m_authPassword; } setNickservNickname(const QString & nickservNickname)118void Identity::setNickservNickname(const QString& nickservNickname) { m_nickservNickname = nickservNickname; } getNickservNickname() const119QString Identity::getNickservNickname() const { return m_nickservNickname; } setNickservCommand(const QString & nickservCommand)120void Identity::setNickservCommand(const QString& nickservCommand) { m_nickservCommand = nickservCommand; } getNickservCommand() const121QString Identity::getNickservCommand() const { return m_nickservCommand; } setSaslAccount(const QString & saslAccount)122void Identity::setSaslAccount(const QString& saslAccount) { m_saslAccount = saslAccount; } getSaslAccount() const123QString Identity::getSaslAccount() const { return m_saslAccount; } setPemClientCertFile(const QUrl & url)124void Identity::setPemClientCertFile(const QUrl &url) { m_pemClientCertFile = url; } getPemClientCertFile() const125QUrl Identity::getPemClientCertFile() const { return m_pemClientCertFile; } 126 setQuitReason(const QString & reason)127void Identity::setQuitReason(const QString& reason) { quitReason=reason; } getQuitReason() const128QString Identity::getQuitReason() const { return quitReason; } setPartReason(const QString & reason)129void Identity::setPartReason(const QString& reason) { partReason=reason; } getPartReason() const130QString Identity::getPartReason() const { return partReason; } setKickReason(const QString & reason)131void Identity::setKickReason(const QString& reason) { kickReason=reason; } getKickReason() const132QString Identity::getKickReason() const { return kickReason; } 133 setInsertRememberLineOnAway(bool state)134void Identity::setInsertRememberLineOnAway(bool state) { insertRememberLineOnAway = state; } getInsertRememberLineOnAway() const135bool Identity::getInsertRememberLineOnAway() const { return insertRememberLineOnAway; } 136 setRunAwayCommands(bool run)137void Identity::setRunAwayCommands(bool run) { runAwayCommands = run; } getRunAwayCommands() const138bool Identity::getRunAwayCommands() const { return runAwayCommands; } setAwayCommand(const QString & command)139void Identity::setAwayCommand(const QString& command) { awayCommand = command; } getAwayCommand() const140QString Identity::getAwayCommand() const { return awayCommand; } setReturnCommand(const QString & command)141void Identity::setReturnCommand(const QString& command) { returnCommand = command; } getReturnCommand() const142QString Identity::getReturnCommand() const { return returnCommand; } 143 setAutomaticAway(bool automaticAway)144void Identity::setAutomaticAway(bool automaticAway) { m_automaticAway = automaticAway; } getAutomaticAway() const145bool Identity::getAutomaticAway() const { return m_automaticAway; } setAwayInactivity(int awayInactivity)146void Identity::setAwayInactivity(int awayInactivity) { m_awayInactivity = awayInactivity; } getAwayInactivity() const147int Identity::getAwayInactivity() const { return m_awayInactivity; } setAutomaticUnaway(bool automaticUnaway)148void Identity::setAutomaticUnaway(bool automaticUnaway) { m_automaticUnaway = automaticUnaway; } getAutomaticUnaway() const149bool Identity::getAutomaticUnaway() const { return m_automaticUnaway; } 150 setNicknameList(const QStringList & newList)151void Identity::setNicknameList(const QStringList& newList) 152 { 153 nicknameList.clear(); 154 nicknameList = newList; 155 } 156 getNicknameList() const157QStringList Identity::getNicknameList() const { return nicknameList; } 158 getShellCommand() const159QString Identity::getShellCommand() const { return m_shellCommand;} setShellCommand(const QString & command)160void Identity::setShellCommand(const QString& command) { m_shellCommand=command;} 161 getCodec() const162QTextCodec* Identity::getCodec() const { return m_codec; } getCodecName() const163QString Identity::getCodecName() const { return m_codecName; } setCodecName(const QString & newCodecName)164void Identity::setCodecName(const QString &newCodecName) 165 { 166 // NOTE: codecName should be based on KCharsets::availableEncodingNames() / descriptiveEncodingNames() 167 // We can get a QTextCodec from QString based on them, but can't do the reverse of that. 168 169 // never set an empty or borked codec! 170 QString codecName = newCodecName; 171 if (!Konversation::IRCCharsets::self()->isValidEncoding(codecName)) 172 codecName = Konversation::IRCCharsets::self()->encodingForLocale(); 173 174 m_codecName = codecName; 175 m_codec = Konversation::IRCCharsets::self()->codecForName(codecName); 176 177 if (!m_codec) { 178 setCodecName(QStringLiteral("UTF-8")); 179 } 180 } 181 setAwayMessage(const QString & message)182void Identity::setAwayMessage(const QString& message) { awayMessage = message; } getAwayMessage() const183QString Identity::getAwayMessage() const { return awayMessage; } 184 setAwayNickname(const QString & nickname)185void Identity::setAwayNickname(const QString& nickname) { awayNickname = nickname; } getAwayNickname() const186QString Identity::getAwayNickname() const { return awayNickname; } 187