summaryrefslogtreecommitdiffstats
path: root/konversation/src/serverdialog.cpp
blob: 51f3d56fd47441348481610e0d1ee0fa720ddfda (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
/*
  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
  email:     psn@linux.se
*/
#include "serverdialog.h"
#include "serversettings.h"

#include <tqlayout.h>
#include <tqframe.h>
#include <tqlabel.h>
#include <tqlineedit.h>
#include <tqspinbox.h>
#include <tqcheckbox.h>
#include <tqwhatsthis.h>

#include <tdelocale.h>
#include <tdemessagebox.h>


namespace Konversation
{

    ServerDialog::ServerDialog(const TQString& title, TQWidget *parent, const char *name)
        : KDialogBase(Plain, title, Ok|Cancel, Ok, parent, name)
    {
        TQFrame* mainWidget = plainPage();
        TQGridLayout* mainLayout = new TQGridLayout(mainWidget, 1, 4, 0, spacingHint());

        TQLabel* serverLbl = new TQLabel(i18n("&Server:"), mainWidget);
        m_serverEdit = new TQLineEdit(mainWidget);
        TQWhatsThis::add(m_serverEdit, i18n("The name or IP number of the server. irchelp.org maintains a list of servers."));
        serverLbl->setBuddy(m_serverEdit);

        TQLabel* portLbl = new TQLabel(i18n("&Port:"), mainWidget);

        m_portSBox = new TQSpinBox(1, 65535, 1, mainWidget);
        m_portSBox->setValue(6667);
        TQWhatsThis::add(m_portSBox, i18n("Enter the port number required to connect to the server. For most servers, this should be <b>6667</b>."));
        portLbl->setBuddy(m_portSBox);

        TQLabel* passwordLbl = new TQLabel(i18n("Pass&word:"), mainWidget);
        m_passwordEdit = new TQLineEdit(mainWidget);
        m_passwordEdit->setEchoMode(TQLineEdit::Password);
        passwordLbl->setBuddy(m_passwordEdit);

        m_sslChBox = new TQCheckBox(i18n("S&ecure connection (SSL)"), mainWidget);
        TQWhatsThis::add(m_sslChBox, i18n("Check if you want to use Secure Socket Layer (SSL) protocol to communicate with the server. This protects the privacy of your communications between your computer and the IRC server. The server must support SSL protocol for this to work. In most cases, if the server does not support SSL, the connection will fail."));

        mainLayout->addWidget(serverLbl, 0, 0);
        mainLayout->addWidget(m_serverEdit, 0, 1);
        mainLayout->addWidget(portLbl, 0, 2);
        mainLayout->addWidget(m_portSBox, 0, 3);
        mainLayout->addWidget(passwordLbl, 1, 0);
        mainLayout->addMultiCellWidget(m_passwordEdit, 1, 1, 1, 3);
        mainLayout->addMultiCellWidget(m_sslChBox, 2, 2, 0, 3);

        m_serverEdit->setFocus();
    }

    ServerDialog::~ServerDialog()
    {
    }

    void ServerDialog::setServerSettings(const ServerSettings& server)
    {
        m_serverEdit->setText(server.host());
        m_portSBox->setValue(server.port());
        m_passwordEdit->setText(server.password());
        m_sslChBox->setChecked(server.SSLEnabled());
    }

    ServerSettings ServerDialog::serverSettings()
    {
        ServerSettings server;
        server.setHost(m_serverEdit->text());
        server.setPort(m_portSBox->value());
        server.setPassword(m_passwordEdit->text());
        server.setSSLEnabled(m_sslChBox->isChecked());

        return server;
    }

    void ServerDialog::slotOk()
    {
        if (m_serverEdit->text().isEmpty())
        {
            KMessageBox::error(this, i18n("The server address is required."));
        }
        else
        {
            accept();
        }
    }
}

#include "serverdialog.moc"