25 #include <tqtooltip.h>
29 #include <tqwhatsthis.h>
31 #include <tdeglobal.h>
32 #include <tdelocale.h>
33 #include <tdefiledialog.h>
34 #include <kstandarddirs.h>
35 #include <kiconloader.h>
37 #include <arts/kplayobjectfactory.h>
44 #include "pushbutton.h"
46 #include "soundpicker.moc"
51 TQString SoundPicker::i18n_Sound() {
return i18n(
"An audio sound",
"Sound"); }
52 TQString SoundPicker::i18n_None() {
return i18n(
"None"); }
53 TQString SoundPicker::i18n_Beep() {
return i18n(
"Beep"); }
54 TQString SoundPicker::i18n_Speak() {
return i18n(
"Speak"); }
55 TQString SoundPicker::i18n_File() {
return i18n(
"Sound file"); }
58 SoundPicker::SoundPicker(TQWidget* parent,
const char* name)
59 : TQFrame(parent, name)
61 setFrameStyle(TQFrame::NoFrame);
62 TQHBoxLayout* soundLayout =
new TQHBoxLayout(
this, 0, KDialog::spacingHint());
63 mTypeBox =
new TQHBox(
this);
64 mTypeBox->setSpacing(KDialog::spacingHint());
66 TQLabel* label =
new TQLabel(i18n(
"An audio sound",
"&Sound:"), mTypeBox);
67 label->setFixedSize(label->sizeHint());
71 mTypeCombo =
new ComboBox(
false, mTypeBox);
72 mTypeCombo->insertItem(i18n_None());
73 mTypeCombo->insertItem(i18n_Beep());
74 mTypeCombo->insertItem(i18n_File());
75 mSpeakShowing = !theApp()->speechEnabled();
76 showSpeak(!mSpeakShowing);
77 connect(mTypeCombo, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotTypeSelected(
int)));
78 label->setBuddy(mTypeCombo);
79 soundLayout->addWidget(mTypeBox);
82 mFilePicker =
new PushButton(
this);
83 mFilePicker->setPixmap(SmallIcon(
"playsound"));
84 mFilePicker->setFixedSize(mFilePicker->sizeHint());
85 connect(mFilePicker, TQ_SIGNAL(clicked()), TQ_SLOT(slotPickFile()));
86 TQToolTip::add(mFilePicker, i18n(
"Configure sound file"));
87 TQWhatsThis::add(mFilePicker, i18n(
"Configure a sound file to play when the alarm is displayed."));
88 soundLayout->addWidget(mFilePicker);
91 mTypeCombo->setCurrentItem(NONE);
92 mFilePicker->setEnabled(
false);
98 void SoundPicker::setReadOnly(
bool readOnly)
100 mTypeCombo->setReadOnly(readOnly);
102 mFilePicker->setReadOnly(readOnly);
104 mReadOnly = readOnly;
110 void SoundPicker::showSpeak(
bool show)
112 if (!theApp()->speechEnabled())
114 if (show == mSpeakShowing)
116 TQString whatsThis =
"<p>" + i18n(
"Choose a sound to play when the message is displayed.")
117 +
"<br>" + i18n(
"%1: the message is displayed silently.").arg(
"<b>" + i18n_None() +
"</b>")
118 +
"<br>" + i18n(
"%1: a simple beep is sounded.").arg(
"<b>" + i18n_Beep() +
"</b>")
119 +
"<br>" + i18n(
"%1: an audio file is played. You will be prompted to choose the file and set play options.").arg(
"<b>" + i18n_File() +
"</b>");
120 if (!show && mTypeCombo->currentItem() == SPEAK)
121 mTypeCombo->setCurrentItem(NONE);
122 if (mTypeCombo->count() == SPEAK+1)
123 mTypeCombo->removeItem(SPEAK);
126 mTypeCombo->insertItem(i18n_Speak());
127 whatsThis +=
"<br>" + i18n(
"%1: the message text is spoken.").arg(
"<b>" + i18n_Speak() +
"</b>") +
"</p>";
129 TQWhatsThis::add(mTypeBox, whatsThis +
"</p>");
130 mSpeakShowing = show;
136 SoundPicker::Type SoundPicker::sound()
const
138 return static_cast<SoundPicker::Type
>(mTypeCombo->currentItem());
145 TQString SoundPicker::file()
const
147 return (mTypeCombo->currentItem() == PLAY_FILE) ? mFile : TQString();
154 float SoundPicker::volume(
float& fadeVolume,
int& fadeSeconds)
const
156 if (mTypeCombo->currentItem() == PLAY_FILE && !mFile.isEmpty())
158 fadeVolume = mFadeVolume;
159 fadeSeconds = mFadeSeconds;
174 bool SoundPicker::repeat()
const
176 return mTypeCombo->currentItem() == PLAY_FILE && !mFile.isEmpty() && mRepeat;
182 void SoundPicker::set(SoundPicker::Type type,
const TQString& f,
float volume,
float fadeVolume,
int fadeSeconds,
bool repeat)
184 if (type == PLAY_FILE && f.isEmpty())
188 mFadeVolume = fadeVolume;
189 mFadeSeconds = fadeSeconds;
191 mTypeCombo->setCurrentItem(type);
192 mFilePicker->setEnabled(type == PLAY_FILE);
193 if (type == PLAY_FILE)
194 TQToolTip::add(mTypeCombo, mFile);
196 TQToolTip::remove(mTypeCombo);
203 void SoundPicker::slotTypeSelected(
int id)
205 Type newType =
static_cast<Type
>(id);
206 if (newType == mLastType)
209 if (mLastType == PLAY_FILE)
211 mFilePicker->setEnabled(
false);
212 TQToolTip::remove(mTypeCombo);
214 else if (newType == PLAY_FILE)
222 mFilePicker->setEnabled(
true);
223 TQToolTip::add(mTypeCombo, mFile);
231 void SoundPicker::slotPickFile()
234 TQString url = browseFile(mDefaultDir, mFile);
238 TQString file = mFile;
239 SoundDlg dlg(mFile, mVolume, mFadeVolume, mFadeSeconds, mRepeat, i18n(
"Sound File"),
this,
"soundDlg");
240 dlg.setReadOnly(mReadOnly);
241 bool accepted = (dlg.exec() == TQDialog::Accepted);
246 float volume, fadeVolume;
248 file = dlg.getFile();
249 mRepeat = dlg.getSettings(volume, fadeVolume, fadeTime);
251 mFadeVolume = fadeVolume;
252 mFadeSeconds = fadeTime;
257 mDefaultDir = dlg.defaultDir();
263 mTypeCombo->setCurrentItem(mLastType);
264 TQToolTip::remove(mTypeCombo);
267 TQToolTip::add(mTypeCombo, mFile);
276 TQString SoundPicker::browseFile(TQString& defaultDir,
const TQString& initialFile)
278 static TQString kdeSoundDir;
279 if (defaultDir.isEmpty())
281 if (kdeSoundDir.isNull())
282 kdeSoundDir = TDEGlobal::dirs()->findResourceDir(
"sound",
"KDE_Notify.wav");
283 defaultDir = kdeSoundDir;
286 TQString filter = TQString::fromLatin1(
"*.wav *.mp3 *.ogg|%1\n*|%2").arg(i18n(
"Sound Files")).arg(i18n(
"All Files"));
288 TQStringList filters = KDE::PlayObjectFactory::mimeTypes();
289 TQString filter = filters.join(
" ");
291 return KAlarm::browseFile(i18n(
"Choose Sound File"), defaultDir, initialFile, filter, KFile::ExistingOnly, 0,
"pickSoundFile");
the KAlarm application object