1
#include "opt_status.h"
3
#include "iconwidget.h"
5
#include <qbuttongroup.h>
6
#include <qwhatsthis.h>
8
#include <qradiobutton.h>
10
#include <qlineedit.h>
12
#include <qtextedit.h>
13
#include <qinputdialog.h>
15
#include "opt_status-ui.h"
17
//----------------------------------------------------------------------------
19
//----------------------------------------------------------------------------
21
OptionsTabStatus::OptionsTabStatus(QObject *parent)
22
: OptionsTab(parent, "status", "", tr("Status"), tr("Status preferences"), "status/online")
28
OptionsTabStatus::~OptionsTabStatus()
33
QWidget *OptionsTabStatus::widget()
38
w = new OptStatusUI();
39
OptStatusUI *d = (OptStatusUI *)w;
41
QString s = tr("Makes Psi automatically set your status to \"away\" if your"
42
" computer is idle for the specified amount of time.");
43
QWhatsThis::add(d->ck_asAway, s);
44
QWhatsThis::add(d->sb_asAway, s);
45
s = tr("Makes Psi automatically set your status to \"extended away\" if your"
46
" computer is idle for the specified amount of time.");
47
QWhatsThis::add(d->ck_asXa, s);
48
QWhatsThis::add(d->sb_asXa, s);
49
s = tr("Makes Psi automatically set your status to \"offline\" if your"
50
" computer is idle for the specified amount of time."
51
" This will disconnect you from the Jabber server.");
52
QWhatsThis::add(d->ck_asOffline, s);
53
QWhatsThis::add(d->sb_asOffline, s);
55
QWhatsThis::add(d->te_asMessage,
56
tr("Specifies an extended message to use if you allow Psi"
57
" to set your status automatically. See options above."));
59
d->pb_spNew->setEnabled(TRUE);
60
d->pb_spDelete->setEnabled(FALSE);
61
d->te_sp->setEnabled(FALSE);
62
connect(d->pb_spNew, SIGNAL(clicked()), SLOT(newStatusPreset()));
63
connect(d->pb_spDelete, SIGNAL(clicked()), SLOT(removeStatusPreset()));
64
connect(d->lb_sp, SIGNAL(highlighted(int)), SLOT(selectStatusPreset(int)));
65
connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
67
QWhatsThis::add(d->pb_spNew,
68
tr("Press this button to create a new status message preset."));
69
QWhatsThis::add(d->pb_spDelete,
70
tr("Press this button to delete a status message preset."));
71
QWhatsThis::add(d->lb_sp,
72
tr("Use this list to select a status message preset"
73
" to view or edit in the box to the bottom."));
74
QWhatsThis::add(d->te_sp,
75
tr("You may edit the message here for the currently selected"
76
" status message preset in the list to the above."));
78
QWhatsThis::add(d->ck_askOnline,
79
tr("Jabber allows you to put extended status messages on"
80
" all status types. Normally, Psi does not prompt you for"
81
" an extended message when you set your status to \"online\"."
82
" Check this option if you want to have this prompt."));
87
void OptionsTabStatus::applyOptions(Options *opt)
92
OptStatusUI *d = (OptStatusUI *)w;
94
opt->asAway = d->sb_asAway->value();
95
opt->asXa = d->sb_asXa->value();
96
opt->asOffline = d->sb_asOffline->value();
97
opt->use_asAway = d->ck_asAway->isChecked();
98
opt->use_asXa = d->ck_asXa->isChecked();
99
opt->use_asOffline = d->ck_asOffline->isChecked();
100
opt->asMessage = d->te_asMessage->text();
104
opt->askOnline = d->ck_askOnline->isChecked();
105
opt->askOffline = d->ck_askOffline->isChecked();
108
void OptionsTabStatus::restoreOptions(const Options *opt)
113
OptStatusUI *d = (OptStatusUI *)w;
115
d->sb_asAway->setMinValue(0);
116
d->sb_asAway->setValue( opt->asAway );
117
d->sb_asXa->setMinValue(0);
118
d->sb_asXa->setValue( opt->asXa );
119
d->sb_asOffline->setMinValue(0);
120
d->sb_asOffline->setValue( opt->asOffline );
121
/*if (opt->asAway <= 0 )
122
opt->use_asAway = FALSE;
124
opt->use_asXa = FALSE;
125
if(d->opt.asOffline <= 0)
126
opt->use_asOffline = FALSE;*/
127
d->ck_asAway->setChecked( opt->use_asAway );
128
d->ck_asXa->setChecked( opt->use_asXa );
129
d->ck_asOffline->setChecked( opt->use_asOffline );
130
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);
138
d->ck_askOnline->setChecked( opt->askOnline );
139
d->ck_askOffline->setChecked( opt->askOffline );
142
void OptionsTabStatus::setData(PsiCon *, QWidget *parentDialog)
144
parentWidget = parentDialog;
147
void OptionsTabStatus::selectStatusPreset(int x)
149
OptStatusUI *d = (OptStatusUI *)w;
152
disconnect(d->te_sp, SIGNAL(textChanged()), 0, 0);
154
d->pb_spDelete->setEnabled(false);
155
d->te_sp->setText("");
156
d->te_sp->setEnabled(false);
159
connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
163
d->pb_spDelete->setEnabled(true);
165
d->te_sp->setText( o->sp.get( d->lb_sp->text(x)) );
166
d->te_sp->setEnabled(true);
169
connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
172
void OptionsTabStatus::newStatusPreset()
174
OptStatusUI *d = (OptStatusUI *)w;
180
text = QInputDialog::getText(
181
CAP(tr("New Status Preset")),
182
tr("Please enter a name for the new status preset:"),
183
QLineEdit::Normal, text, &ok, parentWidget);
188
QMessageBox::information(parentWidget, tr("Error"), tr("Can't create a blank preset!"));
189
else if(o->sp.findByKey(text) != o->sp.end())
190
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);
198
d->te_sp->setFocus();
203
void OptionsTabStatus::removeStatusPreset()
205
OptStatusUI *d = (OptStatusUI *)w;
206
int id = d->lb_sp->currentItem();
212
o->sp.unset(d->lb_sp->text(id));
213
d->lb_sp->removeItem(id);
215
// select a new entry if possible
216
if(d->lb_sp->count() == 0) {
217
selectStatusPreset(-1);
221
if(id >= (int)d->lb_sp->count())
222
id = d->lb_sp->count()-1;
224
d->lb_sp->setSelected(id, TRUE);
225
selectStatusPreset(id);
228
void OptionsTabStatus::changeStatusPreset()
230
OptStatusUI *d = (OptStatusUI *)w;
231
int id = d->lb_sp->currentItem();
235
o->sp.set(d->lb_sp->text(id), d->te_sp->text());