~ubuntu-branches/ubuntu/jaunty/psi/jaunty

« back to all changes in this revision

Viewing changes to src/optionsdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2002-04-19 02:28:44 UTC
  • Revision ID: james.westby@ubuntu.com-20020419022844-za7xgai5qyfd9xv6
Tags: upstream-0.8.5
ImportĀ upstreamĀ versionĀ 0.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** optionsdlg.cpp - the preferences dialog
 
3
** Copyright (C) 2001, 2002  Justin Karneges
 
4
**
 
5
** This program is free software; you can redistribute it and/or
 
6
** modify it under the terms of the GNU General Public License
 
7
** as published by the Free Software Foundation; either version 2
 
8
** of the License, or (at your option) any later version.
 
9
**
 
10
** This program is distributed in the hope that it will be useful,
 
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
** GNU General Public License for more details.
 
14
**
 
15
** You should have received a copy of the GNU General Public License
 
16
** along with this program; if not, write to the Free Software
 
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
 
18
**
 
19
****************************************************************************/
 
20
 
 
21
// default cvlist font?  "Helvetica,10,5,50,0,0,0,0,0"
 
22
 
 
23
#include"optionsdlg.h"
 
24
#include"common.h"
 
25
#include"idle.h"
 
26
 
 
27
#include<qcolordialog.h>
 
28
#include<qfontdialog.h>
 
29
#include<qcheckbox.h>
 
30
#include<qcombobox.h>
 
31
#include<qlineedit.h>
 
32
#include<qlistbox.h>
 
33
#include<qinputdialog.h>
 
34
#include<qspinbox.h>
 
35
#include<qfiledialog.h>
 
36
#include<qdir.h>
 
37
#include<qlabel.h>
 
38
 
 
39
#include"eventdlg.h"
 
40
#include"chatdlg.h"
 
41
 
 
42
 
 
43
static OptionsDlg *options_ptr = 0;
 
44
 
 
45
OptionsDlg::OptionsDlg(const Options &_opt, QWidget *parent, const char *name)
 
46
:OptionsUI(parent, name, FALSE, WDestructiveClose)
 
47
{
 
48
        int n;
 
49
 
 
50
        setCaption(CAP(tr("Options")));
 
51
 
 
52
        opt = _opt;
 
53
        options_ptr = this;
 
54
 
 
55
        // General : Roster
 
56
        ck_useleft->setChecked(opt.useleft);
 
57
        ck_singleclick->setChecked(opt.singleclick);
 
58
 
 
59
        bg_defAct = new QButtonGroup;
 
60
        bg_defAct->setRadioButtonExclusive(TRUE);
 
61
        bg_defAct->insert(rb_defActMsg, 0);
 
62
        bg_defAct->insert(rb_defActChat, 1);
 
63
        bg_defAct->setButton(opt.defaultAction);
 
64
 
 
65
        // General : Misc
 
66
#ifdef Q_WS_MAC
 
67
        ck_alwaysOnTop->setEnabled(FALSE);
 
68
#else
 
69
        ck_alwaysOnTop->setChecked(opt.alwaysOnTop);
 
70
#endif
 
71
 
 
72
        bg_delChats = new QButtonGroup;
 
73
        bg_delChats->setRadioButtonExclusive(TRUE);
 
74
        bg_delChats->insert(rb_delChatsClose, 0);
 
75
        bg_delChats->insert(rb_delChatsHour, 1);
 
76
        bg_delChats->insert(rb_delChatsDay, 2);
 
77
        bg_delChats->insert(rb_delChatsNever, 3);
 
78
        bg_delChats->setButton(opt.delChats);
 
79
 
 
80
        ck_keepSizes->setChecked(opt.keepSizes);
 
81
 
 
82
        // General : Links
 
83
#ifdef Q_WS_WIN
 
84
        cb_link->insertItem(tr("Windows Default Browser/Mail"));
 
85
#endif
 
86
#ifdef Q_WS_X11
 
87
        cb_link->insertItem(tr("KDE Default Browser/Mail"));
 
88
#endif
 
89
#ifdef Q_WS_MAC
 
90
        cb_link->insertItem(tr("MacOS Default Browser/Mail"));
 
91
#endif
 
92
#if !defined(Q_WS_MAC)
 
93
        cb_link->insertItem(tr("Custom"));
 
94
#endif
 
95
        connect(cb_link, SIGNAL(activated(int)), this, SLOT(selectBrowser(int)));
 
96
        cb_link->setCurrentItem(opt.browser);
 
97
        selectBrowser(opt.browser);
 
98
        le_linkBrowser->setText(opt.customBrowser);
 
99
        le_linkMailer->setText(opt.customMailer);
 
100
 
 
101
        // General : Docking
 
102
        ck_docklet->setChecked(opt.useDock);
 
103
        ck_dockDCstyle->setChecked(opt.dockDCstyle);
 
104
        connect(ck_docklet, SIGNAL(toggled(bool)), ck_dockDCstyle, SLOT(setEnabled(bool)));
 
105
        if(!ck_docklet->isChecked())
 
106
                ck_dockDCstyle->setEnabled(FALSE);
 
107
 
 
108
#ifdef Q_WS_MAC
 
109
        gb_docking->setEnabled(FALSE);
 
110
#endif
 
111
 
 
112
        // Look and Feel : Colors
 
113
        bg_color = new QButtonGroup;
 
114
        bg_color->insert(pb_cOnline, 0);
 
115
        bg_color->insert(pb_cOffline, 1);
 
116
        bg_color->insert(pb_cAway, 2);
 
117
        bg_color->insert(pb_cDND, 3);
 
118
        bg_color->insert(pb_cGroupFore, 4);
 
119
        bg_color->insert(pb_cGroupBack, 5);
 
120
        bg_color->insert(pb_cListBack, 6);
 
121
        for(n = 0; n < 7; ++n) {
 
122
                showColor((QPushButton *)bg_color->find(n), opt.color[n]);
 
123
        }
 
124
        connect(bg_color, SIGNAL(clicked(int)), this, SLOT(chooseColor(int)));
 
125
 
 
126
        // Look and Feel : Fonts
 
127
        le_font[0] = le_fRoster;
 
128
        le_font[1] = le_fMessage;
 
129
        le_font[2] = le_fChat;
 
130
        for(n = 0; n < 3; ++n) {
 
131
                le_font[n]->setText(opt.font[n]);
 
132
        }
 
133
        bg_font = new QButtonGroup;
 
134
        bg_font->insert(pb_fRoster, 0);
 
135
        bg_font->insert(pb_fMessage, 1);
 
136
        bg_font->insert(pb_fChat, 2);
 
137
        connect(bg_font, SIGNAL(clicked(int)), this, SLOT(chooseFont(int)));
 
138
 
 
139
        // Look and Feel : Icon Set
 
140
        QStringList descriptions;
 
141
        getPsiIconSets(iconsets, descriptions);
 
142
        cb_iconset->insertStringList(descriptions);
 
143
        n = qstringlistmatch(iconsets, opt.iconset);
 
144
        cb_iconset->setCurrentItem(n);
 
145
        connect(cb_iconset, SIGNAL(activated(int)), this, SLOT(selectIconSet(int)));
 
146
 
 
147
        // Events : Receive
 
148
        ck_popupMsgs->setChecked(opt.popupMsgs);
 
149
        ck_popupChats->setChecked(opt.popupChats);
 
150
        ck_raise->setChecked(opt.raise);
 
151
        cb_incomingAs->setCurrentItem(opt.incomingAs);
 
152
 
 
153
        // Events : Send
 
154
        cb_outgoingAs->setCurrentItem(opt.outgoingAs);
 
155
 
 
156
        // Events : Alerts
 
157
        bg_alerts->setButton(opt.alertStyle);
 
158
        connect(bg_alerts, SIGNAL(clicked(int)), this, SLOT(selectAlertStyle(int)));
 
159
 
 
160
        // Events : Misc
 
161
        ck_ignoreHeadline->setChecked(opt.ignoreHeadline);
 
162
        ck_scrollTo->setChecked(opt.scrollTo);
 
163
 
 
164
        // Presence : Misc
 
165
        ck_askOnline->setChecked(opt.askOnline);
 
166
        ck_rosterAnim->setChecked(opt.rosterAnim);
 
167
 
 
168
        // Presence : Auto Status
 
169
        sb_asAway->setMinValue(0);
 
170
        sb_asAway->setValue(opt.asAway);
 
171
        sb_asXa->setMinValue(0);
 
172
        sb_asXa->setValue(opt.asXa);
 
173
        sb_asOffline->setMinValue(0);
 
174
        sb_asOffline->setValue(opt.asOffline);
 
175
        if(!Idle::isSupported())
 
176
                gb_autoStatus->setEnabled(FALSE);
 
177
 
 
178
        // Presence : Status Presets
 
179
        pb_spNew->setEnabled(TRUE);
 
180
        pb_spDelete->setEnabled(FALSE);
 
181
        te_sp->setEnabled(FALSE);
 
182
        connect(pb_spNew, SIGNAL(clicked()), this, SLOT(newStatusPreset()));
 
183
        connect(pb_spDelete, SIGNAL(clicked()), this, SLOT(removeStatusPreset()));
 
184
        connect(te_sp, SIGNAL(textChanged()), this, SLOT(changeStatusPreset()));
 
185
        connect(lb_sp, SIGNAL(highlighted(int)), this, SLOT(selectStatusPreset(int)));
 
186
        lb_sp->insertStringList(opt.sp.varsToStringList());
 
187
        if(lb_sp->count() >= 1)
 
188
                lb_sp->setSelected(0, TRUE);
 
189
 
 
190
        // Sound : Preferences
 
191
#if defined(Q_WS_WIN)
 
192
        lb_player->setEnabled(FALSE);
 
193
        le_player->setText(tr("Windows Sound"));
 
194
        le_player->setEnabled(FALSE);
 
195
#elif defined(Q_WS_MAC)
 
196
        lb_player->setEnabled(FALSE);
 
197
        le_player->setText(tr("MacOS Sound"));
 
198
        le_player->setEnabled(FALSE);
 
199
#else
 
200
        le_player->setText(opt.player);
 
201
#endif
 
202
        ck_noAwaySound->setChecked(opt.noAwaySound);
 
203
 
 
204
        // Sound : Events
 
205
        le_oe[0] = le_oeMessage;
 
206
        le_oe[1] = le_oeChat1;
 
207
        le_oe[2] = le_oeChat2;
 
208
        le_oe[3] = le_oeSystem;
 
209
        le_oe[4] = le_oeOnline;
 
210
        le_oe[5] = le_oeOffline;
 
211
        le_oe[6] = le_oeSend;
 
212
        for(n = 0; n < 7; ++n)
 
213
                le_oe[n]->setText(opt.onevent[n]);
 
214
        bg_oe = new QButtonGroup;
 
215
        bg_oe->insert(pb_oeMessage, 0);
 
216
        bg_oe->insert(pb_oeChat1, 1);
 
217
        bg_oe->insert(pb_oeChat2, 2);
 
218
        bg_oe->insert(pb_oeSystem, 3);
 
219
        bg_oe->insert(pb_oeOnline, 4);
 
220
        bg_oe->insert(pb_oeOffline, 5);
 
221
        bg_oe->insert(pb_oeSend, 6);
 
222
        connect(bg_oe, SIGNAL(clicked(int)), this, SLOT(chooseOnEvent(int)));
 
223
 
 
224
        connect(pb_soundReset, SIGNAL(clicked()), this, SLOT(soundReset()));
 
225
 
 
226
        connect(buttonApply, SIGNAL(clicked()), this, SLOT(apply()));
 
227
        buttonApply->setEnabled(FALSE);
 
228
        dirty = FALSE;
 
229
        noDirty = FALSE;
 
230
 
 
231
        resize(sizeHint());
 
232
}
 
233
 
 
234
OptionsDlg::~OptionsDlg()
 
235
{
 
236
        delete bg_defAct;
 
237
        delete bg_color;
 
238
        delete bg_font;
 
239
        delete bg_oe;
 
240
 
 
241
        options_ptr = 0;
 
242
}
 
243
 
 
244
/* static */ OptionsDlg *OptionsDlg::find()
 
245
{
 
246
        return options_ptr;
 
247
}
 
248
 
 
249
void OptionsDlg::accept()
 
250
{
 
251
        doApplyOptions();
 
252
 
 
253
        QDialog::accept();
 
254
}
 
255
 
 
256
void OptionsDlg::doApplyOptions()
 
257
{
 
258
        opt.useleft = ck_useleft->isChecked();
 
259
        opt.singleclick = ck_singleclick->isChecked();
 
260
        opt.defaultAction = bg_defAct->id(bg_defAct->selected());
 
261
        opt.delChats = bg_delChats->id(bg_delChats->selected());
 
262
        opt.browser = cb_link->currentItem();
 
263
        opt.alwaysOnTop = ck_alwaysOnTop->isChecked();
 
264
        opt.rosterAnim = ck_rosterAnim->isChecked();
 
265
 
 
266
        opt.useDock = ck_docklet->isChecked();
 
267
        opt.dockDCstyle = ck_dockDCstyle->isChecked();
 
268
 
 
269
        opt.customBrowser = le_linkBrowser->text();
 
270
        opt.customMailer = le_linkMailer->text();
 
271
 
 
272
        opt.popupMsgs = ck_popupMsgs->isChecked();
 
273
        opt.popupChats = ck_popupChats->isChecked();
 
274
        opt.raise = ck_raise->isChecked();
 
275
        opt.incomingAs = cb_incomingAs->currentItem();
 
276
        opt.outgoingAs = cb_outgoingAs->currentItem();
 
277
 
 
278
        opt.askOnline = ck_askOnline->isChecked();
 
279
 
 
280
        opt.asAway = sb_asAway->value();
 
281
        opt.asXa = sb_asXa->value();
 
282
        opt.asOffline = sb_asOffline->value();
 
283
 
 
284
        opt.player = le_player->text();
 
285
        opt.noAwaySound = ck_noAwaySound->isChecked();
 
286
 
 
287
        opt.keepSizes = ck_keepSizes->isChecked();
 
288
        opt.ignoreHeadline = ck_ignoreHeadline->isChecked();
 
289
        opt.scrollTo = ck_scrollTo->isChecked();
 
290
 
 
291
        // restore the default sizes
 
292
        if(!opt.keepSizes) {
 
293
                opt.sizeEventDlg = EventDlg::defaultSize();
 
294
                opt.sizeChatDlg = ChatDlg::defaultSize();
 
295
        }
 
296
 
 
297
        for(int n = 0; n < 7; ++n)
 
298
                opt.onevent[n] = le_oe[n]->text();
 
299
 
 
300
        applyOptions(opt);
 
301
}
 
302
 
 
303
void OptionsDlg::showColor(QPushButton *pb, QColor c)
 
304
{
 
305
        QPixmap p(22, 10);
 
306
        p.fill(c);
 
307
        pb->setPixmap(p);
 
308
}
 
309
 
 
310
void OptionsDlg::chooseFont(int x)
 
311
{
 
312
        bool ok;
 
313
        QFont font;
 
314
        font.fromString(opt.font[x]);
 
315
 
 
316
        opt.font[x] = QFontDialog::getFont(&ok, font, this).toString();
 
317
        le_font[x]->setText(opt.font[x]);
 
318
 
 
319
        if(ok)
 
320
                dataChanged();
 
321
}
 
322
 
 
323
void OptionsDlg::chooseColor(int x)
 
324
{
 
325
        QColor c = opt.color[x];
 
326
 
 
327
        c = QColorDialog::getColor(c, this);
 
328
        if(c.isValid()) {
 
329
                opt.color[x] = c;
 
330
                showColor((QPushButton *)bg_color->find(x), opt.color[x]);
 
331
 
 
332
                dataChanged();
 
333
        }
 
334
}
 
335
 
 
336
void OptionsDlg::selectIconSet(int x)
 
337
{
 
338
        opt.iconset = qstringlistlookup(iconsets, x);
 
339
}
 
340
 
 
341
void OptionsDlg::selectAlertStyle(int x)
 
342
{
 
343
        opt.alertStyle = x;
 
344
}
 
345
 
 
346
void OptionsDlg::selectStatusPreset(int x)
 
347
{
 
348
        if(x == -1) {
 
349
                pb_spDelete->setEnabled(FALSE);
 
350
                noDirty = TRUE;
 
351
                te_sp->setText("");
 
352
                te_sp->setEnabled(FALSE);
 
353
                noDirty = FALSE;
 
354
                return;
 
355
        }
 
356
 
 
357
        noDirty = TRUE;
 
358
 
 
359
        pb_spDelete->setEnabled(TRUE);
 
360
 
 
361
        te_sp->setText(opt.sp.get(lb_sp->text(x)));
 
362
        te_sp->setEnabled(TRUE);
 
363
 
 
364
        noDirty = FALSE;
 
365
}
 
366
 
 
367
void OptionsDlg::newStatusPreset()
 
368
{
 
369
        QString text;
 
370
 
 
371
        while(1) {
 
372
                bool ok = FALSE;
 
373
                text = QInputDialog::getText(
 
374
                        CAP(tr("New Status Preset")),
 
375
                        tr("Please enter a name for the new status preset:"),
 
376
                        QLineEdit::Normal, text, &ok, this);
 
377
                if(!ok)
 
378
                        return;
 
379
 
 
380
                if(text.isEmpty())
 
381
                        QMessageBox::information(this, tr("Error"), tr("Can't create a blank preset!"));
 
382
                else if(opt.sp.findByKey(text) != opt.sp.end())
 
383
                        QMessageBox::information(this, tr("Error"), tr("You already have a preset with that name!"));
 
384
                else
 
385
                        break;
 
386
        }
 
387
 
 
388
        opt.sp.set(text, "");
 
389
        lb_sp->insertItem(text);
 
390
        lb_sp->setSelected(lb_sp->count()-1, TRUE);
 
391
        te_sp->setFocus();
 
392
 
 
393
        dataChanged();
 
394
}
 
395
 
 
396
void OptionsDlg::removeStatusPreset()
 
397
{
 
398
        int id = lb_sp->currentItem();
 
399
        if(id == -1)
 
400
                return;
 
401
 
 
402
        dataChanged();
 
403
 
 
404
        opt.sp.unset(lb_sp->text(id));
 
405
        lb_sp->removeItem(id);
 
406
 
 
407
        // select a new entry if possible
 
408
        if(lb_sp->count() == 0) {
 
409
                selectStatusPreset(-1);
 
410
                return;
 
411
        }
 
412
 
 
413
        if(id >= (int)lb_sp->count())
 
414
                id = lb_sp->count()-1;
 
415
 
 
416
        lb_sp->setSelected(id, TRUE);
 
417
        selectStatusPreset(id);
 
418
}
 
419
 
 
420
void OptionsDlg::changeStatusPreset()
 
421
{
 
422
        int id = lb_sp->currentItem();
 
423
        if(id == -1)
 
424
                return;
 
425
 
 
426
        opt.sp.set(lb_sp->text(id), te_sp->text());
 
427
        dataChanged();
 
428
}
 
429
 
 
430
void OptionsDlg::chooseOnEvent(int x)
 
431
{
 
432
        QString str = QFileDialog::getOpenFileName(QDir::homeDirPath(), "Sound (*.wav)", this, "", "Choose a sound file");
 
433
        if(!str.isEmpty()) {
 
434
                le_oe[x]->setText(str);
 
435
                dataChanged();
 
436
        }
 
437
}
 
438
 
 
439
void OptionsDlg::soundReset()
 
440
{
 
441
        opt.onevent[eMessage] = g.pathBase + "/sound/chat2.wav";
 
442
        opt.onevent[eChat1]   = g.pathBase + "/sound/chat1.wav";
 
443
        opt.onevent[eChat2]   = g.pathBase + "/sound/chat2.wav";
 
444
        opt.onevent[eSystem]  = g.pathBase + "/sound/chat2.wav";
 
445
        opt.onevent[eOnline]  = g.pathBase + "/sound/online.wav";
 
446
        opt.onevent[eOffline] = g.pathBase + "/sound/offline.wav";
 
447
        opt.onevent[eSend]    = g.pathBase + "/sound/send.wav";
 
448
 
 
449
        for(int n = 0; n < 7; ++n)
 
450
                le_oe[n]->setText(opt.onevent[n]);
 
451
 
 
452
        dataChanged();
 
453
}
 
454
 
 
455
void OptionsDlg::dataChanged()
 
456
{
 
457
        if(noDirty)
 
458
                return;
 
459
 
 
460
        dirty = TRUE;
 
461
        buttonApply->setEnabled(TRUE);
 
462
}
 
463
 
 
464
void OptionsDlg::apply()
 
465
{
 
466
        doApplyOptions();
 
467
 
 
468
        dirty = FALSE;
 
469
        buttonApply->setEnabled(FALSE);
 
470
}
 
471
 
 
472
void OptionsDlg::selectBrowser(int x)
 
473
{
 
474
        bool enableCustom = TRUE;
 
475
 
 
476
#ifdef Q_WS_WIN
 
477
        if(x == 0)
 
478
                enableCustom = FALSE;
 
479
#endif
 
480
#ifdef Q_WS_X11
 
481
        if(x == 0)
 
482
                enableCustom = FALSE;
 
483
#endif
 
484
#ifdef Q_WS_MAC
 
485
        if(x == 0)
 
486
                enableCustom = FALSE;
 
487
#endif
 
488
 
 
489
        gb_linkCustom->setEnabled(enableCustom);
 
490
}
 
491