summaryrefslogtreecommitdiffstats
path: root/konversation/src/servergroupsettings.cpp
blob: 567edfcf25f03f4b5d05ae63af66c9b9ae91d271 (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
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
/*
  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.
*/

/*
  Copyright (C) 2004, 2007 Peter Simonsson <psn@linux.se>
  Copyright (C) 2006-2008 Eike Hein <hein@kde.org>
*/

#include "servergroupsettings.h"
#include "konversationapplication.h"


namespace Konversation
{

    int ServerGroupSettings::s_availableId = 0;

    ServerGroupSettings::ServerGroupSettings()
        : KShared()
    {
        m_id = s_availableId;
        s_availableId++;
        m_sortIndex = m_id;
        m_autoConnect = false;
        m_identityId = 0;
        m_enableNotifications = true;
    }

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

        m_sortIndex = m_id;
        m_autoConnect = false;
        m_identityId = 0;
        m_enableNotifications = true;
    }

    ServerGroupSettings::ServerGroupSettings(const ServerGroupSettings& settings)
        : KShared()
    {
        setName(settings.name());
        setServerList(settings.serverList());
        setIdentityId(settings.identityId());
        setChannelList(settings.channelList());
        setConnectCommands(settings.connectCommands());
        setAutoConnectEnabled(settings.autoConnectEnabled());
        setNotificationsEnabled(settings.enableNotifications());
        m_id = settings.id();
        m_sortIndex = settings.sortIndex();
    }

    ServerGroupSettings::ServerGroupSettings(const TQString& name)
        : KShared()
    {
        setName(name);
        m_id = s_availableId;
        s_availableId++;
        m_sortIndex = m_id;
        m_autoConnect = false;
        m_identityId = 0;
        m_enableNotifications = true;
    }

    ServerGroupSettings::~ServerGroupSettings()
    {
    }

    void ServerGroupSettings::setServerList(const ServerList& list)
    {
        m_serverList.clear();
        m_serverList = list;
    }

    void ServerGroupSettings::removeServer(const ServerSettings settings)
    {
        Konversation::ServerList::iterator it;

        for (it = m_serverList.begin(); it != m_serverList.end(); ++it)
        {
            if ((*it)==settings)
            {
                m_serverList.remove((*it));

                return;
            }
        }
    }

    ServerSettings ServerGroupSettings::serverByIndex(unsigned int index) const
    {
        ServerList servers = serverList();

        if(index < servers.count())
        {
            return servers[index];
        }

        return ServerSettings();
    }

    void ServerGroupSettings::setChannelList(const ChannelList& list)
    {
        m_channelList.clear();
        m_channelList = list;
    }

    ChannelSettings ServerGroupSettings::channelByIndex(unsigned int index) const
    {
        if(index < m_channelList.count())
        {
            return m_channelList[index];
        }

        return ChannelSettings();
    }

    void ServerGroupSettings::addChannel(const ChannelSettings& channel, const ChannelSettings& before)
    {
        if (before.name().isEmpty())
            m_channelList.append(channel);
        else
            m_channelList.insert(m_channelList.find(before), channel);
    }

    void ServerGroupSettings::removeChannel(const ChannelSettings& channel)
    {
        m_channelList.remove(channel);
    }

    IdentityPtr ServerGroupSettings::identity() const
    {
        return Preferences::identityById(m_identityId);
    }

    void ServerGroupSettings::appendChannelHistory(const ChannelSettings& channel)
    {
        ChannelList::iterator endIt = m_channelHistory.end();

        for(ChannelList::iterator it = m_channelHistory.begin(); it != endIt; ++it)
        {
            if(channel.name() == (*it).name())
            {
                (*it).setPassword(channel.password());
                (*it).setNotificationsEnabled(channel.enableNotifications());
                return;
            }
        }

        m_channelHistory.append(channel);
    }

    ChannelSettings ServerGroupSettings::channelByNameFromHistory(const TQString& channelName)
    {
        ChannelList::iterator endIt = m_channelHistory.end();

        for(ChannelList::iterator it = m_channelHistory.begin(); it != endIt; ++it)
        {
            if(channelName == (*it).name())
            {
                return (*it);
            }
        }

        return ChannelSettings(channelName);
    }

    //
    // ChannelSettings
    //

    ChannelSettings::ChannelSettings()
    {
        setNotificationsEnabled(true);
    }

    ChannelSettings::ChannelSettings(const ChannelSettings& settings)
    {
        setName(settings.name());
        setPassword(settings.password());
        setNotificationsEnabled(settings.enableNotifications());
    }

    ChannelSettings::ChannelSettings(const TQString& name)
    {
        setName(name);
        setNotificationsEnabled(true);
    }

    ChannelSettings::ChannelSettings(const TQString& name, const TQString& password)
    {
        setName(name);
        setPassword(password);
        setNotificationsEnabled(true);
    }

    ChannelSettings::ChannelSettings(const TQString& name, const TQString& password, bool enableNotifications)
    {
        setName(name);
        setPassword(password);
        setNotificationsEnabled(enableNotifications);
    }

    bool ChannelSettings::operator== (const ChannelSettings& channel) const
    {
        if (m_name.lower() == channel.name().lower())
            return true;
        else
            return false;
    }

    ChannelSettings::~ChannelSettings()
    {
    }

}