summaryrefslogtreecommitdiff
path: root/noncore/settings/sound/soundsettings.cpp
blob: c1918de419fc92c850dfb697b0bf113c87c6f99b (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
/**********************************************************************
** Copyright (C) 2000 Trolltech AS.  All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "soundsettings.h"

#include <qpe/config.h>
#include <qpe/qcopenvelope_qws.h>
#include <qpe/storage.h>

#include <qapplication.h>
#include <qslider.h>
#include <qcheckbox.h>
#include <qlineedit.h>
#include <qcombobox.h>


SoundSettings::SoundSettings( QWidget* parent,  const char* name, WFlags fl )
    : SoundSettingsBase( parent, name, TRUE, fl )
{
    Config config( "Sound" );
    config.setGroup( "System" );
    volume->setValue(100-config.readNumEntry("Volume"));
    mic->setValue(100-config.readNumEntry("Mic"));
    touchsound->setChecked(config.readBoolEntry("Touch"));
    keysound->setChecked(config.readBoolEntry("Key"));
    AlertCheckBox->setChecked(config.readBoolEntry("Alert"));
    
    config.setGroup("Record");
    int rate=config.readNumEntry("SampleRate", 22050);
    if(rate == 11025)
        sampleRate->setCurrentItem(0);
    else if(rate == 22050)
        sampleRate->setCurrentItem(1);
    else if(rate == 32000)
        sampleRate->setCurrentItem(2);
    else if(rate==44100)
        sampleRate->setCurrentItem(2);

    stereoCheckBox->setChecked(config.readNumEntry("Stereo", 0));
    sixteenBitCheckBox->setChecked(config.readNumEntry("SixteenBit", 1));

    updateStorageCombo();
    connect(volume, SIGNAL(valueChanged(int)), this, SLOT(setVolume(int)));
    connect(mic, SIGNAL(valueChanged(int)), this, SLOT(setMic(int)));
    connect(qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( volumeChanged(bool) ) );
    connect(qApp, SIGNAL( micChanged(bool) ), this, SLOT ( micChanged(bool) ) );
    connect( LocationComboBox,SIGNAL(activated(const QString &)),this,SLOT( setLocation(const QString &)));
//     connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
}

void SoundSettings::reject()
{
    Config config( "Sound" );
    config.setGroup( "System" );

    setVolume(100-config.readNumEntry("Volume"));
    setMic(100-config.readNumEntry("Mic"));

//   config.setGroup("Record");
//     int rate=config.readNumEntry("SampleRate", 11025);
//     if(rate == 11025)
//         sampleRate->setCurrentItem(0);
//     else if(rate == 22050)
//         sampleRate->setCurrentItem(1);
//     else if(rate == 32000)
//         sampleRate->setCurrentItem(2);
//     else if(rate==44100)
//         sampleRate->setCurrentItem(3);
//   stereoCheckBox->setChecked(config.readNumEntry("Stereo", 0));
//   sixteenBitCheckBox->setChecked(config.readNumEntry("SixteenBit", 0));

    QDialog::reject();
}

void SoundSettings::accept()
{
    Config config( "Sound" );
    config.setGroup( "System" );
    config.writeEntry("Volume",100-volume->value());
    config.writeEntry("Mic",100-mic->value());
    config.writeEntry("Touch",touchsound->isChecked());
    config.writeEntry("Key",keysound->isChecked());
    config.writeEntry("Alert",AlertCheckBox->isChecked());
    setVolume(volume->value());
    setMic(mic->value());

    config.setGroup("Record");
    config.writeEntry("SampleRate",sampleRate->currentText());
    config.writeEntry("Stereo",stereoCheckBox->isChecked());
    config.writeEntry("SixteenBit",sixteenBitCheckBox->isChecked());
  
    QDialog::accept();
}

void SoundSettings::setVolume(int v)
{
    Config config( "Sound" );
    config.setGroup( "System" );
    config.writeEntry("Volume",100-v);
#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
  QCopEnvelope( "QPE/System", "volumeChange(bool)" ) << FALSE;
#endif
}

void SoundSettings::setMic(int m)
{
    Config config( "Sound" );
    config.setGroup( "System" );
    config.writeEntry("Mic",100-m);
#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
    QCopEnvelope( "QPE/System", "micChange(bool)" ) << FALSE;
#endif
}

void SoundSettings::volumeChanged( bool )
{
  Config config( "Sound" );
  config.setGroup( "System" );
  volume->setValue(100-config.readNumEntry("Volume"));
}

void SoundSettings::micChanged( bool )
{
  Config config( "Sound" );
  config.setGroup( "System" );
  mic->setValue(100-config.readNumEntry("Mic"));
}

void SoundSettings::updateStorageCombo() {

   StorageInfo storageInfo;
   QString sName, sPath;
   QStringList list;
   const QList<FileSystem> &fs = storageInfo.fileSystems();
    QListIterator<FileSystem> it ( fs );
        for( ; it.current(); ++it ){
            const QString name = (*it)->name();
            const QString path = (*it)->path();
            qDebug("storage name "+name +" storage path is "+path);
            list << name + ": " +path;
//             if(dit.current()->file().find(path) != -1 ) storage=name;
        }
        LocationComboBox->insertStringList(list);
}

void SoundSettings::setLocation(const QString & string) {
   Config config( "Sound" );
   config.setGroup( "System" );
   config.writeEntry("RecLocation",string);

}