~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/options/opt_status.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-04-14 18:57:30 UTC
  • mfrom: (2.1.9 hardy)
  • Revision ID: james.westby@ubuntu.com-20080414185730-528re3zp0m2hdlhi
Tags: 0.11-8
* added CONFIG -= link_prl to .pro files and removed dependencies
  which are made unnecessary by this change
* Fix segfault when closing last chat tab with qt4.4
  (This is from upstream svn, rev. 1101) (Closes: Bug#476122)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#include "iconwidget.h"
4
4
 
5
5
#include <qbuttongroup.h>
 
6
#include <QMessageBox>
6
7
#include <qwhatsthis.h>
7
8
#include <qcheckbox.h>
8
9
#include <qradiobutton.h>
12
13
#include <qtextedit.h>
13
14
#include <qinputdialog.h>
14
15
 
15
 
#include "opt_status-ui.h"
 
16
#include "ui_opt_status.h"
 
17
 
 
18
class OptStatusUI : public QWidget, public Ui::OptStatus
 
19
{
 
20
public:
 
21
        OptStatusUI() : QWidget() { setupUi(this); }
 
22
};
16
23
 
17
24
//----------------------------------------------------------------------------
18
25
// OptionsTabStatus
19
26
//----------------------------------------------------------------------------
20
27
 
 
28
static XMPP::Status::Type combomap[7] = { STATUS_CHAT, STATUS_ONLINE, STATUS_AWAY, STATUS_XA, STATUS_DND, STATUS_INVISIBLE, STATUS_OFFLINE };
 
29
 
21
30
OptionsTabStatus::OptionsTabStatus(QObject *parent)
22
31
: OptionsTab(parent, "status", "", tr("Status"), tr("Status preferences"), "psi/status")
23
32
{
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()));
 
77
        
 
78
        int n;
 
79
        for(n = 0; n < 7; ++n)
 
80
                d->cb_sp_status->insertItem(status2txt(combomap[n]));
66
81
 
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."));
77
97
 
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 );
131
151
 
132
152
        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);
 
153
        d->cb_preset->clear();
 
154
        QStringList presets;
 
155
        foreach(StatusPreset p, option.sp) {
 
156
                presets += p.name();
 
157
        }
 
158
        d->cb_preset->insertStringList(presets);
 
159
 
 
160
        if(d->cb_preset->count() >= 1) {
 
161
                d->cb_preset->setCurrentIndex(0);
 
162
                selectStatusPreset(0);
 
163
        }
137
164
 
138
165
        d->ck_askOnline->setChecked( opt->askOnline );
139
166
        d->ck_askOffline->setChecked( opt->askOffline );
150
177
 
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);
153
181
        if ( x == -1 ) {
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);
157
188
 
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()));
160
192
                return;
161
193
        }
162
194
 
163
195
        d->pb_spDelete->setEnabled(true);
164
196
 
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()));
 
202
        else
 
203
                d->le_sp_priority->clear();
 
204
        d->le_sp_priority->setEnabled(true);
 
205
        int n;
 
206
        for(n = 0; n < 7; ++n) {
 
207
                if(preset.status() == combomap[n]) {
 
208
                        d->cb_sp_status->setCurrentItem(n);
 
209
                        break;
 
210
                }
 
211
        }
 
212
        d->cb_sp_status->setEnabled(true);
167
213
 
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()));
170
217
}
171
218
 
172
219
void OptionsTabStatus::newStatusPreset()
186
233
 
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!"));
191
238
                else
192
239
                        break;
193
240
        }
194
241
 
195
 
        o->sp.set(text, "");
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();
199
247
 
200
248
        emit dataChanged();
203
251
void OptionsTabStatus::removeStatusPreset()
204
252
{
205
253
        OptStatusUI *d = (OptStatusUI *)w;
206
 
        int id = d->lb_sp->currentItem();
 
254
        int id = d->cb_preset->currentItem();
207
255
        if(id == -1)
208
256
                return;
209
257
 
210
258
        emit dataChanged();
211
259
 
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);
214
262
 
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);
218
266
                return;
219
267
        }
220
268
 
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;
223
271
 
224
 
        d->lb_sp->setSelected(id, TRUE);
 
272
        d->cb_preset->setCurrentIndex(id);
225
273
        selectStatusPreset(id);
226
274
}
227
275
 
228
276
void OptionsTabStatus::changeStatusPreset()
229
277
{
230
278
        OptStatusUI *d = (OptStatusUI *)w;
231
 
        int id = d->lb_sp->currentItem();
 
279
        int id = d->cb_preset->currentItem();
232
280
        if(id == -1)
233
281
                return;
234
282
 
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();
 
286
        else
 
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()]);
 
289
 
236
290
        emit dataChanged();
237
291
}