summaryrefslogtreecommitdiffstats
path: root/konversation/src/joinchanneldialog.cpp
blob: 4799da2691f24d1d79e465cd24a219b7aa021c2b (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
/*
  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 by Peter Simonsson <psn@linux.se>
*/

#include "joinchanneldialog.h"
#include "joinchannelui.h"
#include "server.h"
#include "channel.h"
#include "servergroupsettings.h"

#include <qlabel.h>

#include <klocale.h>
#include <kcombobox.h>
#include <klineedit.h>


namespace Konversation
{

    JoinChannelDialog::JoinChannelDialog(Server* server, QWidget *parent, const char *name)
        : KDialogBase(parent, name, true, i18n("Join Channel on %1").arg(server->getDisplayName()), Ok|Cancel, Ok)
    {
        m_server = server;
        m_widget = new JoinChannelUI(this);
        setMainWidget(m_widget);

        m_widget->serverLbl->setText(server->getDisplayName());

        if (m_server->getServerGroup())
        {
            ChannelList history = server->getServerGroup()->channelHistory();
            ChannelList::iterator endIt = history.end();
            const QPtrList<Channel> &channels = server->getChannelList();
            QPtrListIterator<Channel> chanIt(channels);
            Channel* chan = 0;
            bool joined = false;

            for(ChannelList::iterator it = history.begin(); it != endIt; ++it)
            {
                chan = chanIt.toFirst();
                joined = false;

                while(chan)
                {
                    if(chan->getName() == (*it).name())
                    {
                        joined = true;
                    }

                    ++chanIt;
                    chan = chanIt.current();
                }

                if(!joined)
                {
                    m_widget->channelCombo->addToHistory((*it).name());
                }
            }
        }

        m_widget->channelCombo->setCurrentText("");
    }

    JoinChannelDialog::~JoinChannelDialog()
    {
    }

    QString JoinChannelDialog::channel() const
    {
        QString channel = m_widget->channelCombo->currentText();

        if(!m_server->isAChannel(channel))
        {
            channel = '#' + channel;
        }

        return channel;
    }

    QString JoinChannelDialog::password() const
    {
        return m_widget->passwordEdit->text();
    }

    void JoinChannelDialog::slotOk()
    {
        // If the channel already exist in the history only the password will be updated.
        if (m_server->getServerGroup())
            m_server->getServerGroup()->appendChannelHistory(ChannelSettings(channel(), password()));

        accept();
    }

}

#include "joinchanneldialog.moc"