source: psi/trunk/src/options/opt_presence.cpp

Last change on this file was 2, checked in by dmik, 19 years ago

Imported original Psi 0.10 sources from Affinix

File size: 9.2 KB
Line 
1#include "opt_presence.h"
2#include "common.h"
3#include "iconwidget.h"
4
5#include <qbuttongroup.h>
6#include <qwhatsthis.h>
7#include <qcheckbox.h>
8#include <qradiobutton.h>
9#include <qcombobox.h>
10#include <qlineedit.h>
11#include <qspinbox.h>
12#include <qtextedit.h>
13#include <qinputdialog.h>
14
15#include "opt_presence_auto.h"
16#include "opt_presence_presets.h"
17#include "opt_presence_misc.h"
18
19//----------------------------------------------------------------------------
20// OptionsTabPresence
21//----------------------------------------------------------------------------
22
23OptionsTabPresence::OptionsTabPresence(QObject *parent)
24: MetaOptionsTab(parent, "presence", "", tr("Presence"), tr("Configure the presence options"), "status/online")
25{
26 addTab( new OptionsTabPresenceAuto(this) );
27 addTab( new OptionsTabPresencePresets(this) );
28 addTab( new OptionsTabPresenceMisc(this) );
29}
30
31//----------------------------------------------------------------------------
32// OptionsTabPresenceAuto
33//----------------------------------------------------------------------------
34
35OptionsTabPresenceAuto::OptionsTabPresenceAuto(QObject *parent)
36: OptionsTab(parent, "presence_auto", "presence", tr("Auto status"), tr("Configure your auto-idle status"))
37{
38 w = 0;
39}
40
41QWidget *OptionsTabPresenceAuto::widget()
42{
43 if ( w )
44 return 0;
45
46 w = new PresenceAutoUI;
47 PresenceAutoUI *d = (PresenceAutoUI *)w;
48
49 QString s = tr("Makes Psi automatically set your status to \"away\" if your"
50 " computer is idle for the specified amount of time.");
51 QWhatsThis::add(d->ck_asAway, s);
52 QWhatsThis::add(d->sb_asAway, s);
53 s = tr("Makes Psi automatically set your status to \"extended away\" if your"
54 " computer is idle for the specified amount of time.");
55 QWhatsThis::add(d->ck_asXa, s);
56 QWhatsThis::add(d->sb_asXa, s);
57 s = tr("Makes Psi automatically set your status to \"offline\" if your"
58 " computer is idle for the specified amount of time."
59 " This will disconnect you from the Jabber server.");
60 QWhatsThis::add(d->ck_asOffline, s);
61 QWhatsThis::add(d->sb_asOffline, s);
62
63 QWhatsThis::add(d->te_asMessage,
64 tr("Specifies an extended message to use if you allow Psi"
65 " to set your status automatically. See options above."));
66
67 return w;
68}
69
70void OptionsTabPresenceAuto::applyOptions(Options *opt)
71{
72 if ( !w )
73 return;
74
75 PresenceAutoUI *d = (PresenceAutoUI *)w;
76 opt->asAway = d->sb_asAway->value();
77 opt->asXa = d->sb_asXa->value();
78 opt->asOffline = d->sb_asOffline->value();
79 opt->use_asAway = d->ck_asAway->isChecked();
80 opt->use_asXa = d->ck_asXa->isChecked();
81 opt->use_asOffline = d->ck_asOffline->isChecked();
82 opt->asMessage = d->te_asMessage->text();
83}
84
85void OptionsTabPresenceAuto::restoreOptions(const Options *opt)
86{
87 if ( !w )
88 return;
89
90 PresenceAutoUI *d = (PresenceAutoUI *)w;
91 d->sb_asAway->setMinValue(0);
92 d->sb_asAway->setValue( opt->asAway );
93 d->sb_asXa->setMinValue(0);
94 d->sb_asXa->setValue( opt->asXa );
95 d->sb_asOffline->setMinValue(0);
96 d->sb_asOffline->setValue( opt->asOffline );
97 /*if (opt->asAway <= 0 )
98 opt->use_asAway = FALSE;
99 if (opt->asXa <= 0 )
100 opt->use_asXa = FALSE;
101 if(d->opt.asOffline <= 0)
102 opt->use_asOffline = FALSE;*/
103 d->ck_asAway->setChecked( opt->use_asAway );
104 d->ck_asXa->setChecked( opt->use_asXa );
105 d->ck_asOffline->setChecked( opt->use_asOffline );
106 d->te_asMessage->setText( opt->asMessage );
107}
108
109//----------------------------------------------------------------------------
110// OptionsTabPresencePresets
111//----------------------------------------------------------------------------
112
113OptionsTabPresencePresets::OptionsTabPresencePresets(QObject *parent)
114: OptionsTab(parent, "presence_presets", "presence", tr("Presets"), tr("Set up custom status presets"))
115{
116 w = 0;
117 o = new Options;
118}
119
120OptionsTabPresencePresets::~OptionsTabPresencePresets()
121{
122 delete o;
123}
124
125QWidget *OptionsTabPresencePresets::widget()
126{
127 if ( w )
128 return 0;
129
130 w = new PresencePresetsUI;
131 PresencePresetsUI *d = (PresencePresetsUI *)w;
132
133 d->pb_spNew->setEnabled(TRUE);
134 d->pb_spDelete->setEnabled(FALSE);
135 d->te_sp->setEnabled(FALSE);
136 connect(d->pb_spNew, SIGNAL(clicked()), SLOT(newStatusPreset()));
137 connect(d->pb_spDelete, SIGNAL(clicked()), SLOT(removeStatusPreset()));
138 connect(d->lb_sp, SIGNAL(highlighted(int)), SLOT(selectStatusPreset(int)));
139 connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
140
141 QWhatsThis::add(d->pb_spNew,
142 tr("Press this button to create a new status message preset."));
143 QWhatsThis::add(d->pb_spDelete,
144 tr("Press this button to delete a status message preset."));
145 QWhatsThis::add(d->lb_sp,
146 tr("Use this list to select a status message preset"
147 " to view or edit in the box to the right."));
148 QWhatsThis::add(d->te_sp,
149 tr("You may edit the message here for the currently selected"
150 " status message preset in the list to the left."));
151
152 return w;
153}
154
155void OptionsTabPresencePresets::setData(PsiCon *, QWidget *parentDialog)
156{
157 parentWidget = parentDialog;
158}
159
160void OptionsTabPresencePresets::applyOptions(Options *opt)
161{
162 if ( !w )
163 return;
164
165 opt->sp = o->sp;
166}
167
168void OptionsTabPresencePresets::restoreOptions(const Options *opt)
169{
170 if ( !w )
171 return;
172
173 PresencePresetsUI *d = (PresencePresetsUI *)w;
174
175 o->sp = opt->sp;
176 d->lb_sp->insertStringList(o->sp.varsToStringList());
177 if(d->lb_sp->count() >= 1)
178 d->lb_sp->setSelected(0, TRUE);
179}
180
181void OptionsTabPresencePresets::selectStatusPreset(int x)
182{
183 PresencePresetsUI *d = (PresencePresetsUI *)w;
184
185 //noDirty = TRUE;
186 disconnect(d->te_sp, SIGNAL(textChanged()), 0, 0);
187 if ( x == -1 ) {
188 d->pb_spDelete->setEnabled(false);
189 d->te_sp->setText("");
190 d->te_sp->setEnabled(false);
191
192 //noDirty = FALSE;
193 connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
194 return;
195 }
196
197 d->pb_spDelete->setEnabled(true);
198
199 d->te_sp->setText( o->sp.get( d->lb_sp->text(x)) );
200 d->te_sp->setEnabled(true);
201
202 //noDirty = FALSE;
203 connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
204}
205
206void OptionsTabPresencePresets::newStatusPreset()
207{
208 PresencePresetsUI *d = (PresencePresetsUI *)w;
209
210 QString text;
211
212 while(1) {
213 bool ok = FALSE;
214 text = QInputDialog::getText(
215 CAP(tr("New Status Preset")),
216 tr("Please enter a name for the new status preset:"),
217 QLineEdit::Normal, text, &ok, parentWidget);
218 if(!ok)
219 return;
220
221 if(text.isEmpty())
222 QMessageBox::information(parentWidget, tr("Error"), tr("Can't create a blank preset!"));
223 else if(o->sp.findByKey(text) != o->sp.end())
224 QMessageBox::information(parentWidget, tr("Error"), tr("You already have a preset with that name!"));
225 else
226 break;
227 }
228
229 o->sp.set(text, "");
230 d->lb_sp->insertItem(text);
231 d->lb_sp->setSelected(d->lb_sp->count()-1, TRUE);
232 d->te_sp->setFocus();
233
234 emit dataChanged();
235}
236
237void OptionsTabPresencePresets::removeStatusPreset()
238{
239 PresencePresetsUI *d = (PresencePresetsUI *)w;
240 int id = d->lb_sp->currentItem();
241 if(id == -1)
242 return;
243
244 emit dataChanged();
245
246 o->sp.unset(d->lb_sp->text(id));
247 d->lb_sp->removeItem(id);
248
249 // select a new entry if possible
250 if(d->lb_sp->count() == 0) {
251 selectStatusPreset(-1);
252 return;
253 }
254
255 if(id >= (int)d->lb_sp->count())
256 id = d->lb_sp->count()-1;
257
258 d->lb_sp->setSelected(id, TRUE);
259 selectStatusPreset(id);
260}
261
262void OptionsTabPresencePresets::changeStatusPreset()
263{
264 PresencePresetsUI *d = (PresencePresetsUI *)w;
265 int id = d->lb_sp->currentItem();
266 if(id == -1)
267 return;
268
269 o->sp.set(d->lb_sp->text(id), d->te_sp->text());
270 emit dataChanged();
271}
272
273//----------------------------------------------------------------------------
274// OptionsTabPresenceMisc
275//----------------------------------------------------------------------------
276
277OptionsTabPresenceMisc::OptionsTabPresenceMisc(QObject *parent)
278: OptionsTab(parent, "presence_misc", "presence", tr("Misc"), tr("Miscellaneous settings"))
279{
280 w = 0;
281}
282
283QWidget *OptionsTabPresenceMisc::widget()
284{
285 if ( w )
286 return 0;
287
288 w = new PresenceMiscUI;
289 PresenceMiscUI *d = (PresenceMiscUI *)w;
290
291 QWhatsThis::add(d->ck_askOnline,
292 tr("Jabber allows you to put extended status messages on"
293 " all status types. Normally, Psi does not prompt you for"
294 " an extended message when you set your status to \"online\"."
295 " Check this option if you want to have this prompt."));
296 QWhatsThis::add(d->ck_rosterAnim,
297 tr("Makes Psi animate contact names in the main window when they come online."));
298 QWhatsThis::add(d->ck_autoVersion,
299 tr("Automatically sends iq:version query to contact when he becomes online. This allows you to determine what clien he is using to get online. Note: results in increased traffic."));
300 QWhatsThis::add(d->ck_autoVCardOnLogin,
301 tr("By default, Psi always checks your vCard on login. If you want to save some traffic, you can uncheck this option."));
302
303 return w;
304}
305
306void OptionsTabPresenceMisc::applyOptions(Options *opt)
307{
308 if ( !w )
309 return;
310
311 PresenceMiscUI *d = (PresenceMiscUI *)w;
312 opt->askOnline = d->ck_askOnline->isChecked();
313 opt->rosterAnim = d->ck_rosterAnim->isChecked();
314 opt->autoVersion = d->ck_autoVersion->isChecked();
315 opt->autoVCardOnLogin = d->ck_autoVCardOnLogin->isChecked();
316}
317
318void OptionsTabPresenceMisc::restoreOptions(const Options *opt)
319{
320 if ( !w )
321 return;
322
323 PresenceMiscUI *d = (PresenceMiscUI *)w;
324 d->ck_askOnline->setChecked( opt->askOnline );
325 d->ck_rosterAnim->setChecked( opt->rosterAnim );
326 d->ck_autoVersion->setChecked( opt->autoVersion );
327 d->ck_autoVCardOnLogin->setChecked( opt->autoVCardOnLogin );
328}
Note: See TracBrowser for help on using the repository browser.