source: psi/trunk/src/options/opt_status.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: 6.3 KB
Line 
1#include "opt_status.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_status-ui.h"
16
17//----------------------------------------------------------------------------
18// OptionsTabStatus
19//----------------------------------------------------------------------------
20
21OptionsTabStatus::OptionsTabStatus(QObject *parent)
22: OptionsTab(parent, "status", "", tr("Status"), tr("Status preferences"), "psi/status")
23{
24 w = 0;
25 o = new Options;
26}
27
28OptionsTabStatus::~OptionsTabStatus()
29{
30 delete o;
31}
32
33QWidget *OptionsTabStatus::widget()
34{
35 if ( w )
36 return 0;
37
38 w = new OptStatusUI();
39 OptStatusUI *d = (OptStatusUI *)w;
40
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);
54
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."));
58
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()));
66
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."));
77
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."));
83
84 return w;
85}
86
87void OptionsTabStatus::applyOptions(Options *opt)
88{
89 if ( !w )
90 return;
91
92 OptStatusUI *d = (OptStatusUI *)w;
93
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();
101
102 opt->sp = o->sp;
103
104 opt->askOnline = d->ck_askOnline->isChecked();
105 opt->askOffline = d->ck_askOffline->isChecked();
106}
107
108void OptionsTabStatus::restoreOptions(const Options *opt)
109{
110 if ( !w )
111 return;
112
113 OptStatusUI *d = (OptStatusUI *)w;
114
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;
123 if (opt->asXa <= 0 )
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 );
131
132 o->sp = opt->sp;
133 d->lb_sp->clear();
134 d->lb_sp->insertStringList(o->sp.varsToStringList());
135 if(d->lb_sp->count() >= 1)
136 d->lb_sp->setSelected(0, TRUE);
137
138 d->ck_askOnline->setChecked( opt->askOnline );
139 d->ck_askOffline->setChecked( opt->askOffline );
140}
141
142void OptionsTabStatus::setData(PsiCon *, QWidget *parentDialog)
143{
144 parentWidget = parentDialog;
145}
146
147void OptionsTabStatus::selectStatusPreset(int x)
148{
149 OptStatusUI *d = (OptStatusUI *)w;
150
151 //noDirty = TRUE;
152 disconnect(d->te_sp, SIGNAL(textChanged()), 0, 0);
153 if ( x == -1 ) {
154 d->pb_spDelete->setEnabled(false);
155 d->te_sp->setText("");
156 d->te_sp->setEnabled(false);
157
158 //noDirty = FALSE;
159 connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
160 return;
161 }
162
163 d->pb_spDelete->setEnabled(true);
164
165 d->te_sp->setText( o->sp.get( d->lb_sp->text(x)) );
166 d->te_sp->setEnabled(true);
167
168 //noDirty = FALSE;
169 connect(d->te_sp, SIGNAL(textChanged()), SLOT(changeStatusPreset()));
170}
171
172void OptionsTabStatus::newStatusPreset()
173{
174 OptStatusUI *d = (OptStatusUI *)w;
175
176 QString text;
177
178 while(1) {
179 bool ok = FALSE;
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);
184 if(!ok)
185 return;
186
187 if(text.isEmpty())
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!"));
191 else
192 break;
193 }
194
195 o->sp.set(text, "");
196 d->lb_sp->insertItem(text);
197 d->lb_sp->setSelected(d->lb_sp->count()-1, TRUE);
198 d->te_sp->setFocus();
199
200 emit dataChanged();
201}
202
203void OptionsTabStatus::removeStatusPreset()
204{
205 OptStatusUI *d = (OptStatusUI *)w;
206 int id = d->lb_sp->currentItem();
207 if(id == -1)
208 return;
209
210 emit dataChanged();
211
212 o->sp.unset(d->lb_sp->text(id));
213 d->lb_sp->removeItem(id);
214
215 // select a new entry if possible
216 if(d->lb_sp->count() == 0) {
217 selectStatusPreset(-1);
218 return;
219 }
220
221 if(id >= (int)d->lb_sp->count())
222 id = d->lb_sp->count()-1;
223
224 d->lb_sp->setSelected(id, TRUE);
225 selectStatusPreset(id);
226}
227
228void OptionsTabStatus::changeStatusPreset()
229{
230 OptStatusUI *d = (OptStatusUI *)w;
231 int id = d->lb_sp->currentItem();
232 if(id == -1)
233 return;
234
235 o->sp.set(d->lb_sp->text(id), d->te_sp->text());
236 emit dataChanged();
237}
Note: See TracBrowser for help on using the repository browser.