~ubuntu-branches/ubuntu/karmic/psi/karmic

« back to all changes in this revision

Viewing changes to src/statusdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "common.h"
40
40
#include "msgmle.h"
41
41
#include "statuspreset.h"
 
42
#include "statuscombobox.h"
42
43
#include "shortcutmanager.h"
43
44
 
44
45
 
86
87
        PsiAccount *pa;
87
88
        Status s;
88
89
        ChatView *te;
89
 
        QComboBox *cb_type, *cb_preset;
 
90
        StatusComboBox *cb_type;
 
91
        QComboBox *cb_preset;
90
92
        QLineEdit *le_priority;
91
93
        QCheckBox *save;
92
94
};
131
133
        QLabel *l;
132
134
        l = new QLabel(tr("Status:"), this);
133
135
        hb1->addWidget(l);
134
 
        d->cb_type = new QComboBox(this);
135
 
 
136
 
        QList<XMPP::Status::Type> statuses;
137
 
        statuses << STATUS_CHAT << STATUS_ONLINE << STATUS_AWAY << STATUS_XA << STATUS_DND;
138
 
        if (PsiOptions::instance()->getOption("options.ui.menu.status.invisible").toBool()) {
139
 
                statuses << STATUS_INVISIBLE;
140
 
        }
141
 
        statuses << STATUS_OFFLINE;
142
 
        
143
 
        foreach(XMPP::Status::Type status, statuses) {
144
 
                d->cb_type->addItem(status2txt(status), status);
145
 
        }
146
 
        for(int i = 0; i < d->cb_type->count(); i++) {
147
 
                if (d->cb_type->itemData(i).toInt() == type) {
148
 
                        d->cb_type->setCurrentItem(i);
149
 
                        break;
150
 
                }
151
 
        }
 
136
        d->cb_type = new StatusComboBox(this, static_cast<XMPP::Status::Type>(type));
152
137
        hb1->addWidget(d->cb_type,3);
153
138
 
154
139
        // Priority
157
142
        d->le_priority = new QLineEdit(this);
158
143
        d->le_priority->setMinimumWidth(30);
159
144
        hb1->addWidget(d->le_priority,1);
160
 
        
 
145
 
161
146
        // Status preset
162
147
        l = new QLabel(tr("Preset:"), this);
163
148
        hb1->addWidget(l);
164
149
        d->cb_preset = new QComboBox(this);
165
150
        d->cb_preset->insertItem(tr("<None>"));
166
151
        QStringList presets;
167
 
        foreach(StatusPreset p, option.sp) {
168
 
                presets += p.name();
 
152
        foreach(QVariant name, PsiOptions::instance()->mapKeyList("options.status.presets")) {
 
153
                presets += name.toString();
169
154
        }
170
155
        presets.sort();
171
156
        d->cb_preset->insertStringList(presets);
172
 
        connect(d->cb_preset, SIGNAL(highlighted(int)), SLOT(chooseStatusPreset(int)));
 
157
        connect(d->cb_preset, SIGNAL(currentIndexChanged(int)), SLOT(chooseStatusPreset(int)));
173
158
        hb1->addWidget(d->cb_preset,3);
174
159
 
175
160
        d->te = new ChatView(this);
216
201
 
217
202
void StatusSetDlg::doButton()
218
203
{
 
204
        // Trim whitespace
 
205
        d->te->setText(d->te->text().trimmed());
 
206
 
219
207
        // Save preset
220
208
        if (d->save->isChecked()) {
221
209
                QString text;
234
222
                                QMessageBox::information(this, tr("Error"), 
235
223
                                        tr("Can't create a blank preset!"));
236
224
                        }
237
 
                        else if(option.sp.contains(text)) {
 
225
                        else if(PsiOptions::instance()->mapKeyList("options.status.presets").contains(text)) {
238
226
                                QMessageBox::information(this, tr("Error"), 
239
227
                                        tr("You already have a preset with that name!"));
240
228
                        }
242
230
                                break;
243
231
                }
244
232
                // Store preset
245
 
                option.sp[text] = StatusPreset(text,d->te->text());
246
 
                if (!d->le_priority->text().isEmpty()) 
247
 
                        option.sp[text].setPriority(d->le_priority->text().toInt());
248
 
                option.sp[text].setStatus((XMPP::Status::Type) d->cb_type->itemData(d->cb_type->currentIndex()).toInt());
 
233
                StatusPreset sp(text, d->te->text(), XMPP::Status(d->cb_type->status()).type());
 
234
                if (!d->le_priority->text().isEmpty()) {
 
235
                        sp.setPriority(d->le_priority->text().toInt());
 
236
                }
 
237
                
 
238
                sp.toOptions(PsiOptions::instance());
 
239
                QString base = PsiOptions::instance()->mapPut("options.status.presets", text);
249
240
        } 
250
241
 
251
242
        // Set status
252
 
        int type = d->cb_type->itemData(d->cb_type->currentIndex()).toInt();
 
243
        int type = d->cb_type->status();
253
244
        QString str = d->te->text();
254
245
 
255
246
        if (d->le_priority->text().isEmpty())
265
256
        if(x < 1)
266
257
                return;
267
258
        
268
 
        StatusPreset preset = option.sp[d->cb_preset->text(x)];
269
 
        d->te->setText(preset.message());
270
 
        if (preset.priority().hasValue()) 
271
 
                d->le_priority->setText(QString::number(preset.priority().value()));
272
 
        else
 
259
        QString base = PsiOptions::instance()->mapLookup("options.status.presets", d->cb_preset->text(x));
 
260
        d->te->setText(PsiOptions::instance()->getOption(base+".message").toString());
 
261
        if (PsiOptions::instance()->getOption(base+".force-priority").toBool()) {
 
262
                d->le_priority->setText(QString::number(PsiOptions::instance()->getOption(base+".priority").toInt()));
 
263
        } else {
273
264
                d->le_priority->clear();
274
 
 
275
 
        int n;
276
 
        for(n = 0; n < d->cb_type->count(); ++n) {
277
 
                if(preset.status() == d->cb_type->itemData(n).toInt()) {
278
 
                        d->cb_type->setCurrentItem(n);
279
 
                        break;
280
 
                }
281
265
        }
 
266
 
 
267
        XMPP::Status status;
 
268
        status.setType(PsiOptions::instance()->getOption(base+".status").toString());
 
269
        d->cb_type->setStatus(status.type());
282
270
}
283
271
 
284
272
void StatusSetDlg::cancel()