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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
/*
* answmachpage.cpp - Answering 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 "answmachpage.h"
#include <ksimpleconfig.h>
#include <stdlib.h>
#include <klocale.h> // for getenv
KAnswmachPageConfig::KAnswmachPageConfig( TQWidget *parent, const char* name,
KSimpleConfig *_config)
: KCModule (parent, name)
{
if (!_config) {
delete_config = true;
config = new KSimpleConfig("ktalkdrc");
}
else {
delete_config = false;
config = _config;
}
answmach_cb = new TQCheckBox(i18n("&Activate answering machine"), this);
answmach_cb->adjustSize();
mail_edit = new TQLineEdit(this);
mail_edit->adjustSize();
mail_edit->setMinimumWidth(150);
mail_label = new TQLabel(mail_edit,i18n("&Mail address:"),this);
mail_label->adjustSize();
mail_label->setAlignment( ShowPrefix | AlignVCenter );
subj_edit = new TQLineEdit(this);
subj_edit->adjustSize();
subj_edit->setMinimumWidth(150);
subj_label = new TQLabel(subj_edit, i18n("Mail s&ubject:"),this);
subj_label->adjustSize();
subj_label->setAlignment( ShowPrefix | AlignVCenter );
subj_tip = new TQLabel(i18n("Use %s for the caller name"),this);
subj_tip->setAlignment( ShowPrefix );
head_edit = new TQLineEdit(this);
head_edit->adjustSize();
head_edit->setMinimumWidth(150);
head_label = new TQLabel(head_edit, i18n("Mail &first line:"),this);
head_label->adjustSize();
head_label->setAlignment( ShowPrefix | AlignVCenter );
head_tip = new TQLabel(
i18n("Use first %s for caller name, and second %s for caller hostname"),
this);
head_tip->setAlignment( ShowPrefix );
emptymail_cb = new TQCheckBox(i18n("&Receive a mail even if no message left"), this);
emptymail_cb->adjustSize();
msg_ml = new TQMultiLineEdit(this);
msg_ml->adjustSize();
msg_ml->setMinimumWidth(150);
msg_label = new TQLabel(msg_ml, i18n("&Banner displayed on answering machine startup:"),this);
msg_label->adjustSize();
msg_label->setAlignment( ShowPrefix | AlignVCenter );
int h = 10 + answmach_cb->height() + mail_edit->height() +
subj_edit->height() + subj_tip->height() + head_edit->height()
+ head_tip->height() + emptymail_cb->height() +
msg_label->height() + msg_ml->height() + 30;
setMinimumSize(400, h); // 400 : otherwise, buttons may overlap
msg_default = new TQString(i18n("The person you are asking to talk with is not answering.\n"
"Please leave a message to be delivered via email.\n"
"Just start typing and when you have finished, exit normally."));
load();
connect(answmach_cb, TQT_SIGNAL(clicked()), this, TQT_SLOT(answmachOnOff()));
// Emit changed(true) when anything changes
connect(answmach_cb, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotChanged()));
connect(mail_edit, TQT_SIGNAL(textChanged(const TQString&)),
this, TQT_SLOT(slotChanged()));
connect(subj_edit, TQT_SIGNAL(textChanged(const TQString&)),
this, TQT_SLOT(slotChanged()));
connect(head_edit, TQT_SIGNAL(textChanged(const TQString&)),
this, TQT_SLOT(slotChanged()));
connect(emptymail_cb, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotChanged()));
connect(msg_ml, TQT_SIGNAL(textChanged()), this, TQT_SLOT(slotChanged()));
}
KAnswmachPageConfig::~KAnswmachPageConfig( ) {
if (delete_config) delete config;
delete answmach_cb;
delete mail_label;
delete mail_edit;
delete subj_label;
delete subj_edit;
delete subj_tip;
delete head_label;
delete head_edit;
delete head_tip;
delete emptymail_cb;
delete msg_label;
delete msg_ml;
delete msg_default;
}
void KAnswmachPageConfig::slotChanged() {
emit changed(true);
}
void KAnswmachPageConfig::resizeEvent(TQResizeEvent *) {
int h_txt = answmach_cb->height(); // taken for the general label height
int h_edt = mail_edit->height(); // taken for the general TQLineEdit height
int spc = h_txt / 3;
int w = rect().width();
int leftedits = mail_label->width();
if ( subj_label->width() > leftedits )
leftedits = subj_label->width();
if ( head_label->width() > leftedits )
leftedits = head_label->width();
leftedits += 20;
int h = 10 + spc*2;
answmach_cb->move(10, h);
h += h_txt+spc;
mail_label->setFixedHeight(h_edt); // same size -> vertical center aligned
mail_label->move(10, h);
mail_edit->setGeometry(leftedits, h, w-leftedits-10, h_edt);
h += h_edt+spc;
subj_label->setFixedHeight(h_edt); // same size -> vertical center aligned
subj_label->move(10, h);
subj_edit->setGeometry(leftedits, h, w-leftedits-10, h_edt);
h += h_edt+spc;
subj_tip->setFixedWidth(w-20);
subj_tip->move(leftedits, h);
h += h_txt+spc;
head_label->setFixedHeight(h_edt); // same size -> vertical center aligned
head_label->move(10, h);
head_edit->setGeometry(leftedits, h, w-leftedits-10, h_edt);
h += h_edt+spc;
head_tip->setFixedWidth(w-20);
head_tip->move(leftedits, h);
h += h_txt+spc;
emptymail_cb->move(10,h);
h += h_txt+spc;
msg_label->move(10, h);
h += h_txt+spc;
msg_ml->setGeometry(10, h, w-20, height() - h - 10);
h += h_edt+spc;
}
void KAnswmachPageConfig::answmachOnOff()
{
bool b = answmach_cb->isChecked();
mail_label->setEnabled(b);
mail_edit->setEnabled(b);
subj_label->setEnabled(b);
subj_edit->setEnabled(b);
subj_tip->setEnabled(b);
head_label->setEnabled(b);
head_edit->setEnabled(b);
head_tip->setEnabled(b);
emptymail_cb->setEnabled(b);
msg_label->setEnabled(b);
msg_ml->setEnabled(b);
}
void KAnswmachPageConfig::defaults() {
answmach_cb->setChecked(true);
mail_edit->setText(getenv("REPLYTO"));
subj_edit->setText(i18n("Message from %s"));
head_edit->setText(i18n("Message left on the answering machine, by %s@%s"));
emptymail_cb->setChecked(true);
msg_ml->setText(*msg_default);
// Activate things according to configuration
answmachOnOff();
}
void KAnswmachPageConfig::load() {
config->setGroup("ktalkd");
answmach_cb->setChecked(config->readBoolEntry("Answmach",true));
mail_edit->setText(config->readEntry("Mail",getenv("REPLYTO")));
subj_edit->setText(config->readEntry("Subj",i18n("Message from %s")));
head_edit->setText(config->readEntry("Head",
i18n("Message left on the answering machine, by %s@%s")));
emptymail_cb->setChecked(config->readBoolEntry("EmptyMail",true));
msg_ml->clear();
char m[]="Msg1"; // used as key to read configuration
TQString msg;
while (!(msg=config->readEntry(m)).isNull())
{
msg_ml->append(msg);
++m[3];
}
if (m[3]=='1') // nothing in the config file
msg_ml->setText(*msg_default);
// Activate things according to configuration
answmachOnOff();
emit changed(false);
}
void KAnswmachPageConfig::save() {
config->setGroup("ktalkd");
config->writeEntry("Answmach", answmach_cb->isChecked());
config->writeEntry("Mail",mail_edit->text());
config->writeEntry("Subj",subj_edit->text());
config->writeEntry("Head",head_edit->text());
config->writeEntry("EmptyMail", emptymail_cb->isChecked());
char m[]="Msg1"; // used as key to read configuration
int linenr=0;
TQString msg;
while ((linenr<8) && (linenr<msg_ml->numLines()))
{
config->writeEntry(m,msg_ml->textLine(linenr));
++m[3]; ++linenr;
}
config->deleteEntry(m,false/*non localized*/);
// necessary to avoid old msg lines to reappear after
// deleting some.
config->sync();
}
#include "answmachpage.moc"
|