summaryrefslogtreecommitdiffstats
path: root/src/modules/options/optw_sound.cpp
blob: 72f527a7d1f48fab200bfeab7609342092519d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
//=============================================================================
//
//   File : optw_sound.cpp
//   Creation date : Fri Sep  6 02:18:23 2002 GMT by Szymon Stefanek
//
//   This file is part of the KVsound sound client distribution
//   Copyright (C) 2002-2006 Szymon Stefanek (pragma at kvsound dot net)
//
//   This program is FREE software. You can redistribute it and/or
//   modify it under the terms of the GNU General Public License
//   as published by the Free Software Foundation; either version 2
//   of the License, or (at your opinion) any later version.
//
//   This program is distributed in the HOPE that it will be USEFUL,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//   See the GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program. If not, write to the Free Software Foundation,
//   Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
//=============================================================================

#include "optw_sound.h"

#include "kvi_settings.h"
#include "kvi_locale.h"
#include "kvi_options.h"
#include "kvi_modulemanager.h"
#include "kvi_pointerlist.h"
#include "kvi_string.h"

#include <tqlabel.h>
#include <tqpushbutton.h>
#include "kvi_tal_hbox.h"

#ifdef COMPILE_INFO_TIPS
	#include "kvi_tal_tooltip.h"
#endif

// FIXME: This module doesn't Cancel properly when auto-detection is performed!



KviSoundOptionsWidget::KviSoundOptionsWidget(TQWidget * pParent)
: KviOptionsWidget(pParent)
{
}

KviSoundOptionsWidget::~KviSoundOptionsWidget()
{
}


KviSoundGeneralOptionsWidget::KviSoundGeneralOptionsWidget(TQWidget * parent)
: KviOptionsWidget(parent,"sound_system_options_widget")
{
#ifdef COMPILE_ON_WINDOWS
	createLayout(4,1);
#else
	createLayout(3,1);
#endif
	KviTalGroupBox * g = addGroupBox(0,0,0,0,1,TQt::Horizontal,__tr2qs_ctx("Sound System","options"),true);

	KviTalToolTip::add(g,__tr2qs_ctx("This allows you to select the sound system to be used with KVIrc.","options"));

	KviTalHBox * h = new KviTalHBox(g);

	m_pSoundSystemBox = new TQComboBox(false,h);

	m_pSoundAutoDetectButton = new TQPushButton(__tr2qs_ctx("Auto-detect","options"),h);
	connect(m_pSoundAutoDetectButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(soundAutoDetect()));

	m_pSoundTestButton = new TQPushButton(__tr2qs_ctx("Test","options"),h);
	connect(m_pSoundTestButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(soundTest()));


	g = addGroupBox(0,1,0,1,1,TQt::Horizontal,__tr2qs_ctx("Media Player","options"),true);

	KviTalToolTip::add(g,__tr2qs_ctx("This allows you to select the preferred media player to be used with " \
		"the mediaplayer.* module commands and functions.","options"));

	h = new KviTalHBox(g);

	m_pMediaPlayerBox = new TQComboBox(false,h);

	m_pMediaAutoDetectButton = new TQPushButton(__tr2qs_ctx("Auto-detect","options"),h);
	connect(m_pMediaAutoDetectButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(mediaAutoDetect()));

	m_pMediaTestButton = new TQPushButton(__tr2qs_ctx("Test","options"),h);
	connect(m_pMediaTestButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(mediaTest()));

	addRowSpacer(0,2,0,2);

	soundFillBox();
	mediaFillBox();
	// FIXME!
	m_pSoundTestButton->setEnabled(false);
	m_pMediaTestButton->setEnabled(false);

	g = addGroupBox(0,2,0,2,1,TQt::Horizontal,__tr2qs_ctx("ID3 tags' encoding","options"),true);

	KviTalToolTip::add(g,__tr2qs_ctx("This allows you to select encoding of mp3 tags.","options"));

	h = new KviTalHBox(g);

	m_pTagsEncodingCombo = new TQComboBox(false,h);
	m_pTagsEncodingCombo->insertItem(__tr2qs_ctx("Use Language Encoding","options"));

	int i = 0;
	int iMatch = 0;
	
	KviLocale::EncodingDescription * d = KviLocale::encodingDescription(i);
	while(d->szName)
	{
		if(KviTQString::equalCI(d->szName,KVI_OPTION_STRING(KviOption_stringMp3TagsEncoding)))iMatch = i + 1;
		m_pTagsEncodingCombo->insertItem(d->szName);
		i++;
		d = KviLocale::encodingDescription(i);
	}
	m_pTagsEncodingCombo->setCurrentItem(iMatch);

#ifdef COMPILE_ON_WINDOWS
	g = addGroupBox(0,3,0,3,1,TQt::Horizontal,__tr2qs_ctx("Winamp messages ecoding","options"),true);

	KviTalToolTip::add(g,__tr2qs_ctx("This allows you to select encoding of winamp messages.","options"));

	h = new KviTalHBox(g);

	m_pWinampEncodingCombo = new TQComboBox(false,h);
	
	m_pWinampEncodingCombo->insertItem(__tr2qs_ctx("Use Language Encoding","options"));
	i = 0;
	iMatch = 0;
	
	d = KviLocale::encodingDescription(i);
	while(d->szName)
	{
		if(KviTQString::equalCI(d->szName,KVI_OPTION_STRING(KviOption_stringWinampTextEncoding)))iMatch = i + 1;
		m_pWinampEncodingCombo->insertItem(d->szName);
		i++;
		d = KviLocale::encodingDescription(i);
	}
	m_pWinampEncodingCombo->setCurrentItem(iMatch);
#endif
}


KviSoundGeneralOptionsWidget::~KviSoundGeneralOptionsWidget()
{
}

void KviSoundGeneralOptionsWidget::soundTest()
{
}

void KviSoundGeneralOptionsWidget::mediaTest()
{
}


void KviSoundGeneralOptionsWidget::soundAutoDetect()
{
	KviModule * m = g_pModuleManager->getModule("snd");
	if(!m)return;
	m->ctrl("detectSoundSystem",0);
	soundFillBox();
}

void KviSoundGeneralOptionsWidget::mediaAutoDetect()
{
	KviModule * m = g_pModuleManager->getModule("mediaplayer");
	if(!m)return;
	m->ctrl("detectMediaPlayer",0);
	mediaFillBox();
}


void KviSoundGeneralOptionsWidget::soundFillBox()
{

	TQStringList l;
	TQStringList::Iterator it;
	int cnt;
	int i;
	KviModule * m = g_pModuleManager->getModule("snd");


	if(!m)goto disable;


	if(!m->ctrl("getAvailableSoundSystems",&l))goto disable;

	m_pSoundSystemBox->clear();

	for ( it = l.begin(); it != l.end(); ++it )
	{
		m_pSoundSystemBox->insertItem(*it);
	}

	cnt = m_pSoundSystemBox->count();

	for(i=0;i<cnt;i++)
	{
		TQString t = m_pSoundSystemBox->text(i);
		if(KviTQString::equalCI(t,KVI_OPTION_STRING(KviOption_stringSoundSystem)))
		{
			m_pSoundSystemBox->setCurrentItem(i);
			break;
		}
	}

	return;
disable:
	m_pSoundSystemBox->clear();
	m_pSoundSystemBox->setEnabled(false);
	m_pSoundTestButton->setEnabled(false);
	m_pSoundAutoDetectButton->setEnabled(false);
}

void KviSoundGeneralOptionsWidget::mediaFillBox()
{
	TQStringList l;
	TQStringList::Iterator it;
	int cnt;
	int i;
	KviModule * m = g_pModuleManager->getModule("mediaplayer");

	if(!m)goto disable;
	if(!m->ctrl("getAvailableMediaPlayers",&l))goto disable;
	m_pMediaPlayerBox->clear();
	for ( it = l.begin(); it != l.end(); ++it )
	{
		m_pMediaPlayerBox->insertItem(*it);
	}
	cnt = m_pMediaPlayerBox->count();

	for(i=0;i<cnt;i++)
	{
		TQString t = m_pMediaPlayerBox->text(i);
		if(KviTQString::equalCI(t,KVI_OPTION_STRING(KviOption_stringPreferredMediaPlayer)))
		{
			m_pMediaPlayerBox->setCurrentItem(i);
			break;
		}
	}

	return;
disable:
	m_pMediaPlayerBox->clear();
	m_pMediaPlayerBox->setEnabled(false);
	m_pMediaTestButton->setEnabled(false);
	m_pMediaAutoDetectButton->setEnabled(false);
}


void KviSoundGeneralOptionsWidget::commit()
{
	KviOptionsWidget::commit();
	KVI_OPTION_STRING(KviOption_stringSoundSystem) = m_pSoundSystemBox->currentText();
	KVI_OPTION_STRING(KviOption_stringPreferredMediaPlayer) = m_pMediaPlayerBox->currentText();
	
	int idx = m_pTagsEncodingCombo->currentItem();
	if(idx <= 0)
	{
		// guess from locale
		KVI_OPTION_STRING(KviOption_stringMp3TagsEncoding) = "";
	} else {
		KVI_OPTION_STRING(KviOption_stringMp3TagsEncoding) = m_pTagsEncodingCombo->text(idx);
	}


#ifdef COMPILE_ON_WINDOWS
	idx = m_pWinampEncodingCombo->currentItem();
	if(idx <= 0)
	{
		// guess from locale
		KVI_OPTION_STRING(KviOption_stringWinampTextEncoding) = "";
	} else {
		KVI_OPTION_STRING(KviOption_stringWinampTextEncoding) = m_pWinampEncodingCombo->text(idx);
	}
#endif
}

KviSoundsOptionsWidget::KviSoundsOptionsWidget(TQWidget * parent)
: KviOptionsWidget(parent,"sound_options_widget")
{
	createLayout(5,2);
	addLabel(0,0,0,0,__tr2qs_ctx("New Query opened","options"));
	addSoundSelector(1,0,1,0,"",KviOption_stringOnNewQueryOpenedSound);
	
	addLabel(0,1,0,1,__tr2qs_ctx("New message in inactive query","options"));
	addSoundSelector(1,1,1,1,"",KviOption_stringOnQueryMessageSound);
	
	addLabel(0,2,0,2,__tr2qs_ctx("Highlighted message in inactive window","options"));
	addSoundSelector(1,2,1,2,"",KviOption_stringOnHighlightedMessageSound);
	
	addLabel(0,3,0,3,__tr2qs_ctx("Me have been kicked","options"));
	addSoundSelector(1,3,1,3,"",KviOption_stringOnMeKickedSound);
	
	addRowSpacer(0,4,1,4);
	
}

KviSoundsOptionsWidget::~KviSoundsOptionsWidget()
{
}

#include "m_optw_sound.moc"