Added saving of alerts - unstable!!!
[kitchenalert] / src / selectsounddialog.cpp
1 /**************************************************************************
2         KitchenAlert
3
4         Copyright (C) 2010  Heli Hyvättinen
5         
6         This file is part of KitchenAlert.
7
8         Kitchen Alert is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 3 of the License, or
11         (at your option) any later version.
12
13         This program is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 **************************************************************************/
22
23
24
25
26
27 #include "selectsounddialog.h"
28 #include "ui_selectsounddialog.h"
29 #include <QFileDialog>
30 #include <QSettings>
31 #include <QDebug>
32 #include <Phonon>
33
34 SelectSoundDialog::SelectSoundDialog(QWidget *parent) :
35     QDialog(parent),
36     ui(new Ui::SelectSoundDialog)
37 {
38     ui->setupUi(this);
39     connect(ui->browseButton,SIGNAL(clicked()),this,SLOT(browse()));
40
41     QSettings settings("KitchenAlert","KitchenAlert");
42     QString filename = settings.value("soundfile").toString();
43     ui->lineEdit->setText(filename);
44
45     bool useDefaultSoundFile = settings.value("UseDefaultSound",true).toBool();
46     if (useDefaultSoundFile == true)
47     {
48         ui->DefaultSoundRadioButton->setChecked(true);
49         ui->browseButton->setDisabled(true);
50         ui->lineEdit->setDisabled(true);
51     }
52     else ui->CustomSoundRadioButton->setChecked(true);
53     qDebug() << "UseDefaultSoundfile is " << useDefaultSoundFile;
54
55     connect(ui->testButton,SIGNAL(clicked()),this,SLOT(testSound()));
56     pSound_ = Phonon::createPlayer(Phonon::NoCategory, Phonon::MediaSource(ui->lineEdit->displayText()));
57
58
59 }
60
61 SelectSoundDialog::~SelectSoundDialog()
62 {
63     delete ui;
64 }
65
66 void SelectSoundDialog::browse()
67 {
68     QString filename = QFileDialog::getOpenFileName(this, tr("Choose a sound file"),"/home/user/"); //Filters: to use or not...? //MAEMO specific dir here...
69     if (!filename.isEmpty()) //Empty string returned by the dialog if user pressed cancel...
70     {
71         ui->lineEdit->setText(filename);
72     }
73 }
74
75 QString SelectSoundDialog::getSoundFileName()
76 {
77     if (ui->CustomSoundRadioButton->isChecked() == true)
78         return ui->lineEdit->displayText();
79     else return QString();
80 }
81
82 bool SelectSoundDialog::isDefaultSoundChecked()
83 {
84     return ui->DefaultSoundRadioButton->isChecked();
85 }
86
87 void SelectSoundDialog::testSound( )
88 {
89     pSound_->setCurrentSource(ui->lineEdit->displayText());
90     pSound_->play();
91 }