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

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

UI: Misc changes:

  • Added OS/2-related definitions.
  • On all platforms but Mac, the main (roster) window will be minimized (instead of closing) when Esc is pressed, but the doclet window is disabled.
File size: 5.2 KB
Line 
1#include "opt_sound.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 <qfiledialog.h>
12#include <qlabel.h>
13
14#include "opt_sound-ui.h"
15
16//----------------------------------------------------------------------------
17// OptionsTabSound
18//----------------------------------------------------------------------------
19
20OptionsTabSound::OptionsTabSound(QObject *parent)
21: OptionsTab(parent, "sound", "", tr("Sound"), tr("Configure how Psi sounds"), "psi/playSounds")
22{
23 w = 0;
24 bg_se = bg_sePlay = 0;
25}
26
27OptionsTabSound::~OptionsTabSound()
28{
29 if ( bg_se )
30 delete bg_se;
31 if ( bg_sePlay )
32 delete bg_sePlay;
33}
34
35QWidget *OptionsTabSound::widget()
36{
37 if ( w )
38 return 0;
39
40 w = new OptSoundUI();
41 OptSoundUI *d = (OptSoundUI *)w;
42
43 le_oe[0] = d->le_oeMessage;
44 le_oe[1] = d->le_oeChat1;
45 le_oe[2] = d->le_oeChat2;
46 le_oe[3] = d->le_oeHeadline;
47 le_oe[4] = d->le_oeSystem;
48 le_oe[5] = d->le_oeOnline;
49 le_oe[6] = d->le_oeOffline;
50 le_oe[7] = d->le_oeSend;
51 le_oe[8] = d->le_oeIncomingFT;
52 le_oe[9] = d->le_oeFTComplete;
53
54 bg_se = new QButtonGroup;
55 bg_se->insert(d->tb_seMessage, 0);
56 bg_se->insert(d->tb_seChat1, 1);
57 bg_se->insert(d->tb_seChat2, 2);
58 bg_se->insert(d->tb_seHeadline, 3);
59 bg_se->insert(d->tb_seSystem, 4);
60 bg_se->insert(d->tb_seOnline, 5);
61 bg_se->insert(d->tb_seOffline, 6);
62 bg_se->insert(d->tb_seSend, 7);
63 bg_se->insert(d->tb_seIncomingFT, 8);
64 bg_se->insert(d->tb_seFTComplete, 9);
65 connect(bg_se, SIGNAL(clicked(int)), SLOT(chooseSoundEvent(int)));
66
67 bg_sePlay = new QButtonGroup;
68 bg_sePlay->insert(d->tb_seMessagePlay, 0);
69 bg_sePlay->insert(d->tb_seChat1Play, 1);
70 bg_sePlay->insert(d->tb_seChat2Play, 2);
71 bg_sePlay->insert(d->tb_seHeadlinePlay, 3);
72 bg_sePlay->insert(d->tb_seSystemPlay, 4);
73 bg_sePlay->insert(d->tb_seOnlinePlay, 5);
74 bg_sePlay->insert(d->tb_seOfflinePlay, 6);
75 bg_sePlay->insert(d->tb_seSendPlay, 7);
76 bg_sePlay->insert(d->tb_seIncomingFTPlay, 8);
77 bg_sePlay->insert(d->tb_seFTCompletePlay, 9);
78 connect(bg_sePlay, SIGNAL(clicked(int)), SLOT(previewSoundEvent(int)));
79
80 connect(d->pb_soundReset, SIGNAL(clicked()), SLOT(soundReset()));
81
82 // set up proper tool button icons
83 int n;
84 for (n = 0; n < 10; n++) {
85 IconToolButton *tb = (IconToolButton *)bg_se->find(n);
86 tb->setIcon( IconsetFactory::iconPtr("psi/browse") );
87 tb = (IconToolButton *)bg_sePlay->find(n);
88 tb->setIcon( IconsetFactory::iconPtr("psi/play") );
89 }
90
91 // TODO: add QWhatsThis for all widgets
92
93 QWhatsThis::add(d->le_player,
94 tr("If your system supports multiple sound players, you may"
95 " choose your preferred sound player application here."));
96 QWhatsThis::add(d->ck_awaySound,
97 tr("Enable this option if you wish to hear sound alerts when your status is \"away\" or \"extended away\"."));
98 QWhatsThis::add(d->ck_gcSound,
99 tr("Play sounds for all events in groupchat, not only for mentioning of your nick."));
100
101#if defined(Q_WS_WIN)
102 d->lb_player->hide();
103 d->le_player->hide();
104#elif defined(Q_WS_PM)
105 d->lb_player->hide();
106 d->le_player->hide();
107#elif defined(Q_WS_MAC)
108 d->lb_player->hide();
109 d->le_player->hide();
110#endif
111
112 return w;
113}
114
115void OptionsTabSound::applyOptions(Options *opt)
116{
117 if ( !w )
118 return;
119
120 OptSoundUI *d = (OptSoundUI *)w;
121 opt->player = d->le_player->text();
122 opt->noAwaySound = !d->ck_awaySound->isChecked();
123 opt->noGCSound = !d->ck_gcSound->isChecked();
124
125 for(int n = 0; n < 10; ++n)
126 opt->onevent[n] = le_oe[n]->text();
127}
128
129void OptionsTabSound::restoreOptions(const Options *opt)
130{
131 if ( !w )
132 return;
133
134 OptSoundUI *d = (OptSoundUI *)w;
135
136#if defined(Q_WS_WIN)
137 d->le_player->setText(tr("Windows Sound"));
138#elif defined(Q_WS_PM)
139 d->le_player->setText(tr("OS/2 MMPM Sound"));
140#elif defined(Q_WS_MAC)
141 d->le_player->setText(tr("Mac OS Sound"));
142#else
143 d->le_player->setText( opt->player );
144#endif
145
146 d->ck_awaySound->setChecked( !opt->noAwaySound );
147 d->ck_gcSound->setChecked( !opt->noGCSound );
148
149 for(int n = 0; n < 10; ++n)
150 le_oe[n]->setText(opt->onevent[n]);
151}
152
153void OptionsTabSound::setData(PsiCon *, QWidget *p)
154{
155 parentWidget = p;
156}
157
158void OptionsTabSound::chooseSoundEvent(int x)
159{
160 if(option.lastPath.isEmpty())
161 option.lastPath = QDir::homeDirPath();
162 QString str = QFileDialog::getOpenFileName(option.lastPath, tr("Sound (*.wav)"), parentWidget, "", tr("Choose a sound file"));
163 if(!str.isEmpty()) {
164 QFileInfo fi(str);
165 option.lastPath = fi.dirPath();
166 le_oe[x]->setText(str);
167 emit dataChanged();
168 }
169}
170
171void OptionsTabSound::previewSoundEvent(int x)
172{
173 soundPlay(le_oe[x]->text());
174}
175
176void OptionsTabSound::soundReset()
177{
178 Options opt;
179 opt.onevent[eMessage] = g.pathBase + "/sound/chat2.wav";
180 opt.onevent[eChat1] = g.pathBase + "/sound/chat1.wav";
181 opt.onevent[eChat2] = g.pathBase + "/sound/chat2.wav";
182 opt.onevent[eHeadline] = g.pathBase + "/sound/chat2.wav";
183 opt.onevent[eSystem] = g.pathBase + "/sound/chat2.wav";
184 opt.onevent[eOnline] = g.pathBase + "/sound/online.wav";
185 opt.onevent[eOffline] = g.pathBase + "/sound/offline.wav";
186 opt.onevent[eSend] = g.pathBase + "/sound/send.wav";
187 opt.onevent[eIncomingFT] = g.pathBase + "/sound/ft_incoming.wav";
188 opt.onevent[eFTComplete] = g.pathBase + "/sound/ft_complete.wav";
189
190 for(int n = 0; n < 10; ++n)
191 le_oe[n]->setText(opt.onevent[n]);
192
193 emit dataChanged();
194}
Note: See TracBrowser for help on using the repository browser.