summaryrefslogtreecommitdiffstats
path: root/ktalkd/kcmktalkd/forwmachpage.cpp
blob: 6475927f2173b9ee7dc7fe6cd72d6fafa774da12 (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
/*
 * forwmachpage.cpp - Forwarding machine settings for KTalkd
 *
 * Copyright (C) 1998 David Faure, faure@kde.org
 *
 * Requires the Qt widget libraries, available at no cost at
 * http://www.troll.no/
 *
 *  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 program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "forwmachpage.h"

#include <ksimpleconfig.h>
#include <klocale.h>

KForwmachPageConfig::KForwmachPageConfig( QWidget *parent, const char* name,
	KSimpleConfig *_config) 
    : KCModule (parent, name)
{
    if (!_config) {
		delete_config = true;
		config = new KSimpleConfig("ktalkdrc");
	}
	else {
		delete_config = false;
		config = _config;
	}                                                                           
    forwmach_cb = new QCheckBox(i18n("Activate &forward"), this);
    forwmach_cb->adjustSize();
    address_edit = new QLineEdit(this);
    address_edit->adjustSize();
    address_edit->setMinimumWidth(150);
    address_label = new QLabel(address_edit,i18n("&Destination (user or user@host):"),this);
    address_label->adjustSize();
    address_label->setAlignment( ShowPrefix | AlignVCenter );

    method_combo = new QComboBox(this);
    method_combo->insertItem("FWA");
    method_combo->insertItem("FWR");
    method_combo->insertItem("FWT");
    method_combo->adjustSize();
    method_combo->setMinimumWidth(80);
    method_label = new QLabel(method_combo, i18n("Forward &method:"),this);
    method_label->adjustSize();
    method_label->setAlignment( ShowPrefix | AlignVCenter );

    expl_label = new QLabel(i18n(
"FWA: Forward announcement only. Direct connection. Not recommended.\n\
FWR: Forward all requests, changing info when necessary. Direct connection.\n\
FWT: Forward all requests and handle the talk request. No direct connection.\n\
\n\
Recommended use: FWT if you want to use it behind a firewall (and if ktalkd\n\
can access both networks). Otherwise choose FWR.\n\
\n\
See Help for further explanation.\n\
"),this);
    expl_label->adjustSize();

    int h = 10 + forwmach_cb->height() + address_edit->height() +
        method_combo->height()+expl_label->height()+30;
    setMinimumSize(400, h); // 400: otherwise, buttons may overlap

    load();

    connect(forwmach_cb, SIGNAL(clicked()), this, SLOT(forwmachOnOff()));

	// emit changed(true) on changes
	connect(forwmach_cb, SIGNAL(clicked()), this, SLOT(slotChanged()));
	connect(address_edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotChanged()));
	connect(method_combo, SIGNAL(activated(int)), this, SLOT(slotChanged()));
}

KForwmachPageConfig::~KForwmachPageConfig( ) {
	if (delete_config) delete config;
	
    /* I've been told that this is not necessary as 
       they will be deleted by Qt. But, well... */
    delete forwmach_cb;
    delete address_label;
    delete address_edit;
    delete method_label;
    delete method_combo;
    delete expl_label;
}

void KForwmachPageConfig::slotChanged() {
	emit changed(true);
}

void KForwmachPageConfig::resizeEvent(QResizeEvent *) {
    int h_txt = forwmach_cb->height(); // taken for the general label height
    int h_edt = address_edit->height();   // taken for the general QLineEdit height
    int spc = h_txt / 3;
    int w = rect().width();

    int h = 10 + spc*2;
    forwmach_cb->move(10, h);
    h += h_txt+spc;
    address_label->setFixedHeight(h_edt); // same size -> vertical center aligned
    address_label->move(10, h);
    int w_label = address_label->width()+20;
    address_edit->setGeometry(w_label, h, w-w_label-10, h_edt);
    h += h_edt+spc;

    method_label->setFixedHeight(h_edt); // same size -> vertical center aligned
    method_label->move(10, h);
    method_combo->move(w_label, h);
    h += h_edt+spc;

    expl_label->move(10,h);
    
}

void KForwmachPageConfig::forwmachOnOff() {
    bool b = forwmach_cb->isChecked();
    address_label->setEnabled(b);
    address_edit->setEnabled(b);
    method_label->setEnabled(b);
    method_combo->setEnabled(b);
    expl_label->setEnabled(b);
}

void KForwmachPageConfig::defaults() {

    forwmach_cb->setChecked(false);
    method_combo->setCurrentItem(1);
    address_edit->setText("");

    // Activate things according to configuration
    forwmachOnOff();

}

void KForwmachPageConfig::load() {
   
    config->setGroup("ktalkd");

    QString forward = config->readEntry("Forward","unset");
    forwmach_cb->setChecked(forward!="unset");
    if (forward != "unset" ) 
        address_edit->setText(forward);
    else
        address_edit->setText("");

    QString forwardMethod = config->readEntry("ForwardMethod","FWR");
    for (int i=0; i<method_combo->count(); i++)
        if (forwardMethod == method_combo->text(i))
            method_combo->setCurrentItem(i);

    // Activate things according to configuration
    forwmachOnOff();

    emit changed(false);
}

void KForwmachPageConfig::save() {

    config->setGroup("ktalkd");

    if (forwmach_cb->isChecked())
    {
        config->writeEntry("Forward",address_edit->text());
    } else
        config->deleteEntry("Forward", false /*non localized*/);
    config->writeEntry("ForwardMethod",method_combo->currentText());
    
    config->sync();
}

#include "forwmachpage.moc"