12
13
#include <qtextedit.h>
13
14
#include <qinputdialog.h>
15
#include "opt_status-ui.h"
16
#include "ui_opt_status.h"
18
class OptStatusUI : public QWidget, public Ui::OptStatus
21
OptStatusUI() : QWidget() { setupUi(this); }
17
24
//----------------------------------------------------------------------------
18
25
// OptionsTabStatus
19
26
//----------------------------------------------------------------------------
28
static XMPP::Status::Type combomap[7] = { STATUS_CHAT, STATUS_ONLINE, STATUS_AWAY, STATUS_XA, STATUS_DND, STATUS_INVISIBLE, STATUS_OFFLINE };
21
30
OptionsTabStatus::OptionsTabStatus(QObject *parent)
22
31
: OptionsTab(parent, "status", "", tr("Status"), tr("Status preferences"), "psi/status")
61
70
d->te_sp->setEnabled(FALSE);
62
71
connect(d->pb_spNew, SIGNAL(clicked()), SLOT(newStatusPreset()));
63
72
connect(d->pb_spDelete, SIGNAL(clicked()), SLOT(removeStatusPreset()));
64
connect(d->lb_sp, SIGNAL(highlighted(int)), SLOT(selectStatusPreset(int)));
73
connect(d->cb_preset, SIGNAL(highlighted(int)), SLOT(selectStatusPreset(int)));
65
74
connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
75
connect(d->le_sp_priority, SIGNAL(textChanged(const QString&)), SLOT(changeStatusPreset()));
76
connect(d->cb_sp_status, SIGNAL(activated(int)), SLOT(changeStatusPreset()));
79
for(n = 0; n < 7; ++n)
80
d->cb_sp_status->insertItem(status2txt(combomap[n]));
67
82
QWhatsThis::add(d->pb_spNew,
68
83
tr("Press this button to create a new status message preset."));
69
84
QWhatsThis::add(d->pb_spDelete,
70
85
tr("Press this button to delete a status message preset."));
71
QWhatsThis::add(d->lb_sp,
86
QWhatsThis::add(d->cb_preset,
72
87
tr("Use this list to select a status message preset"
73
88
" to view or edit in the box to the bottom."));
74
89
QWhatsThis::add(d->te_sp,
75
90
tr("You may edit the message here for the currently selected"
76
91
" status message preset in the list to the above."));
92
QWhatsThis::add(d->cb_sp_status,
93
tr("Use this to choose the status that will be assigned to this preset"));
94
QWhatsThis::add(d->le_sp_priority,
95
tr("Fill in the priority that will be assigned to this preset."
96
" If no priority is given, the default account priority will be used."));
78
98
QWhatsThis::add(d->ck_askOnline,
79
99
tr("Jabber allows you to put extended status messages on"
130
150
d->te_asMessage->setText( opt->asMessage );
134
d->lb_sp->insertStringList(o->sp.varsToStringList());
135
if(d->lb_sp->count() >= 1)
136
d->lb_sp->setSelected(0, TRUE);
153
d->cb_preset->clear();
155
foreach(StatusPreset p, option.sp) {
158
d->cb_preset->insertStringList(presets);
160
if(d->cb_preset->count() >= 1) {
161
d->cb_preset->setCurrentIndex(0);
162
selectStatusPreset(0);
138
165
d->ck_askOnline->setChecked( opt->askOnline );
139
166
d->ck_askOffline->setChecked( opt->askOffline );
151
178
//noDirty = TRUE;
152
179
disconnect(d->te_sp, SIGNAL(textChanged()), 0, 0);
180
disconnect(d->le_sp_priority, SIGNAL(textChanged(const QString&)), 0, 0);
154
182
d->pb_spDelete->setEnabled(false);
155
183
d->te_sp->setText("");
156
184
d->te_sp->setEnabled(false);
185
d->le_sp_priority->clear();
186
d->le_sp_priority->setEnabled(false);
187
d->cb_sp_status->setEnabled(false);
158
189
//noDirty = FALSE;
159
190
connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
191
connect(d->le_sp_priority, SIGNAL(textChanged(const QString&)), SLOT(changeStatusPreset()));
163
195
d->pb_spDelete->setEnabled(true);
165
d->te_sp->setText( o->sp.get( d->lb_sp->text(x)) );
197
StatusPreset preset = o->sp[d->cb_preset->text(x)];
198
d->te_sp->setText(preset.message());
166
199
d->te_sp->setEnabled(true);
200
if (preset.priority().hasValue())
201
d->le_sp_priority->setText(QString::number(preset.priority().value()));
203
d->le_sp_priority->clear();
204
d->le_sp_priority->setEnabled(true);
206
for(n = 0; n < 7; ++n) {
207
if(preset.status() == combomap[n]) {
208
d->cb_sp_status->setCurrentItem(n);
212
d->cb_sp_status->setEnabled(true);
168
214
//noDirty = FALSE;
169
215
connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
216
connect(d->le_sp_priority, SIGNAL(textChanged(const QString&)), SLOT(changeStatusPreset()));
172
219
void OptionsTabStatus::newStatusPreset()
187
234
if(text.isEmpty())
188
235
QMessageBox::information(parentWidget, tr("Error"), tr("Can't create a blank preset!"));
189
else if(o->sp.findByKey(text) != o->sp.end())
236
else if(o->sp.contains(text))
190
237
QMessageBox::information(parentWidget, tr("Error"), tr("You already have a preset with that name!"));
196
d->lb_sp->insertItem(text);
197
d->lb_sp->setSelected(d->lb_sp->count()-1, TRUE);
242
o->sp[text].setName(text);
243
d->cb_preset->insertItem(text);
244
d->cb_preset->setCurrentItem(d->cb_preset->count()-1);
245
selectStatusPreset(d->cb_preset->count()-1);
198
246
d->te_sp->setFocus();
200
248
emit dataChanged();
203
251
void OptionsTabStatus::removeStatusPreset()
205
253
OptStatusUI *d = (OptStatusUI *)w;
206
int id = d->lb_sp->currentItem();
254
int id = d->cb_preset->currentItem();
210
258
emit dataChanged();
212
o->sp.unset(d->lb_sp->text(id));
213
d->lb_sp->removeItem(id);
260
o->sp.remove(d->cb_preset->text(id));
261
d->cb_preset->removeItem(id);
215
263
// select a new entry if possible
216
if(d->lb_sp->count() == 0) {
264
if(d->cb_preset->count() == 0) {
217
265
selectStatusPreset(-1);
221
if(id >= (int)d->lb_sp->count())
222
id = d->lb_sp->count()-1;
269
if(id >= (int)d->cb_preset->count())
270
id = d->cb_preset->count()-1;
224
d->lb_sp->setSelected(id, TRUE);
272
d->cb_preset->setCurrentIndex(id);
225
273
selectStatusPreset(id);
228
276
void OptionsTabStatus::changeStatusPreset()
230
278
OptStatusUI *d = (OptStatusUI *)w;
231
int id = d->lb_sp->currentItem();
279
int id = d->cb_preset->currentItem();
235
o->sp.set(d->lb_sp->text(id), d->te_sp->text());
283
o->sp[d->cb_preset->text(id)].setMessage(d->te_sp->text());
284
if (d->le_sp_priority->text().isEmpty())
285
o->sp[d->cb_preset->text(id)].clearPriority();
287
o->sp[d->cb_preset->text(id)].setPriority(d->le_sp_priority->text().toInt());
288
o->sp[d->cb_preset->text(id)].setStatus(combomap[d->cb_sp_status->currentItem()]);
236
290
emit dataChanged();