~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kmix/control/mixconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *  mixconfig.cpp
 
3
 *
 
4
 *  Copyright (c) 2000 Stefan Schimanski <1Stein@gmx.de>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 */
 
20
 
 
21
#include <stdlib.h>
 
22
#include <stdio.h>
 
23
#include <unistd.h>
 
24
 
 
25
#include <qlayout.h>
 
26
#include <qvbox.h>
 
27
#include <qgroupbox.h>
 
28
#include <qcheckbox.h>
 
29
#include <qlistview.h>
 
30
#include <qpushbutton.h>
 
31
#include <kconfig.h>
 
32
#include <kglobal.h>
 
33
#include <kstddirs.h>
 
34
#include <klocale.h>
 
35
#include <kdialog.h>
 
36
#include <kdebug.h>
 
37
#include <kapp.h>
 
38
#include <kfile.h>
 
39
#include <qtextstream.h>
 
40
#include <kiconloader.h>
 
41
#include <kprocess.h>
 
42
#include <kmessagebox.h>
 
43
#include <knuminput.h>
 
44
#include <qwhatsthis.h>
 
45
#include <qprogressdialog.h>
 
46
 
 
47
#include "mixconfig.h"
 
48
 
 
49
KMixConfig::KMixConfig(QWidget *parent, const char *name)
 
50
  : KCModule(parent, name)
 
51
{
 
52
  QVBoxLayout *topLayout = new QVBoxLayout(this, 5);
 
53
 
 
54
  // Restore settings
 
55
  QGroupBox *restGrp = new QGroupBox( i18n("Default Volumes"), this );
 
56
  topLayout->addWidget( restGrp );
 
57
  QBoxLayout *restLayout =
 
58
     new QVBoxLayout( restGrp, KDialog::marginHint(), KDialog::spacingHint());
 
59
  restLayout->addSpacing( fontMetrics().lineSpacing() );
 
60
 
 
61
  // Save profile
 
62
  QHBoxLayout *profLayout = new QHBoxLayout( restLayout, 5 );
 
63
  QPushButton *saveProf = new QPushButton( i18n("Save current volumes"), restGrp );
 
64
  profLayout->addWidget( saveProf );
 
65
  connect( saveProf, SIGNAL(clicked()), this, SLOT(saveVolumes()) );
 
66
 
 
67
  // Load profile
 
68
  QPushButton *loadProf = new QPushButton( i18n("Load volumes"), restGrp );
 
69
  profLayout->addWidget( loadProf );
 
70
  connect( loadProf, SIGNAL(clicked()), this, SLOT(loadVolumes()) );
 
71
 
 
72
  // start in startkde?
 
73
  m_startkdeRestore = new QCheckBox( i18n("Load volumes on login"), restGrp );
 
74
  restLayout->addWidget( m_startkdeRestore );
 
75
  connect( m_startkdeRestore, SIGNAL(clicked()), this, SLOT(configChanged()) );
 
76
 
 
77
  // Hardware settings
 
78
  QGroupBox *hdwGrp = new QGroupBox( i18n("Hardware Settings"), this );
 
79
  topLayout->addWidget( hdwGrp );
 
80
  QBoxLayout *hdwLayout =
 
81
     new QVBoxLayout( hdwGrp, KDialog::marginHint(), KDialog::spacingHint());
 
82
  hdwLayout->addSpacing( fontMetrics().lineSpacing() );
 
83
 
 
84
  m_maxCards = new KIntNumInput( hdwGrp );
 
85
  m_maxCards->setLabel( i18n("Maximum number of probed mixers") );
 
86
  m_maxCards->setRange( 1, 16 );
 
87
  hdwLayout->addWidget( m_maxCards );
 
88
  connect( m_maxCards, SIGNAL(valueChanged(int)), this, SLOT(configChanged()) );
 
89
  QWhatsThis::add( m_maxCards, i18n("Change this value to optimize the startup time "
 
90
                                    "of kmix.\n"
 
91
                                    "High values mean that kmix probes for "
 
92
                                    "many soundcards. If you have more mixers "
 
93
                                    "installed than kmix detects, increase this "
 
94
                                    "value.") );
 
95
 
 
96
  m_maxDevices = new KIntNumInput( hdwGrp );
 
97
  m_maxDevices->setLabel( i18n("Maximum number of probed devices per mixer") );
 
98
  m_maxDevices->setRange( 1, 16 );
 
99
  hdwLayout->addWidget( m_maxDevices );
 
100
  connect( m_maxDevices, SIGNAL(valueChanged(int)), this, SLOT(configChanged()) );
 
101
  QWhatsThis::add( m_maxDevices,
 
102
                   i18n("Change this value to optimize the startup time "
 
103
                        "of kmix. High values mean that kmix probes for "
 
104
                        "many devices per soundcard driver.\n"
 
105
                        "If there are more mixer sub devices in a "
 
106
                        "driver than kmix detects, increase this value") );
 
107
 
 
108
  topLayout->addStretch( 1 );
 
109
 
 
110
  load();
 
111
}
 
112
 
 
113
KMixConfig::~KMixConfig() {}
 
114
 
 
115
void KMixConfig::configChanged()
 
116
{
 
117
  emit changed(true);
 
118
}
 
119
 
 
120
void KMixConfig::loadVolumes()
 
121
{
 
122
   QProgressDialog progress( i18n("Restoring default volumes"), i18n("Cancel"), 1, this );
 
123
   KProcess *ctrl = new KProcess;
 
124
   QString ctrlExe = KGlobal::dirs()->findExe("kmixctrl");
 
125
   if (!ctrlExe)
 
126
   {
 
127
      kdDebug() << "can't find kmixctrl" << endl;
 
128
 
 
129
      KMessageBox::sorry ( this, i18n("The kmixctrl executable can't be found.") );
 
130
      return;
 
131
   }
 
132
 
 
133
   *ctrl << ctrlExe;
 
134
   *ctrl << "--restore";
 
135
   ctrl->start();
 
136
 
 
137
   while ( ctrl->isRunning() )
 
138
   {
 
139
      if ( progress.wasCancelled() ) break;
 
140
      kapp->processEvents();
 
141
   }
 
142
   progress.setProgress( 1 );
 
143
 
 
144
   delete ctrl;
 
145
}
 
146
 
 
147
void KMixConfig::saveVolumes()
 
148
{
 
149
   QProgressDialog progress( i18n("Saving default volumes"), i18n("Cancel"), 1, this );
 
150
   KProcess *ctrl = new KProcess;
 
151
   QString ctrlExe = KGlobal::dirs()->findExe("kmixctrl");
 
152
   if (!ctrlExe)
 
153
   {
 
154
      kdDebug() << "can't find kmixctrl" << endl;
 
155
 
 
156
      KMessageBox::sorry ( this, i18n("The kmixctrl executable can't be found.") );
 
157
      return;
 
158
   }
 
159
 
 
160
   *ctrl << ctrlExe;
 
161
   *ctrl << "--save";
 
162
   ctrl->start();
 
163
 
 
164
   while ( ctrl->isRunning() )
 
165
   {
 
166
      if ( progress.wasCancelled() ) break;
 
167
      kapp->processEvents();
 
168
   }
 
169
   progress.setProgress( 1 );
 
170
 
 
171
   delete ctrl;
 
172
}
 
173
 
 
174
void KMixConfig::load()
 
175
{
 
176
  KConfig *config = new KConfig("kcmkmixrc", true);
 
177
 
 
178
  config->setGroup("Misc");
 
179
  m_startkdeRestore->setChecked( config->readBoolEntry( "startkdeRestore", true ) );
 
180
  m_maxCards->setValue( config->readNumEntry( "maxCards", 2 ) );
 
181
  m_maxDevices->setValue( config->readNumEntry( "maxDevices", 2 ) );
 
182
  delete config;
 
183
 
 
184
  emit changed(false);
 
185
}
 
186
 
 
187
void KMixConfig::save()
 
188
{
 
189
 
 
190
  KConfig *config= new KConfig("kcmkmixrc", false);
 
191
 
 
192
  config->setGroup("Misc");
 
193
  config->writeEntry( "startkdeRestore", m_startkdeRestore->isChecked() );
 
194
  config->writeEntry( "maxCards", m_maxCards->value() );
 
195
  config->writeEntry( "maxDevices", m_maxDevices->value() );
 
196
  config->sync();
 
197
  delete config;
 
198
 
 
199
  emit changed(false);
 
200
}
 
201
 
 
202
void KMixConfig::defaults()
 
203
{
 
204
  m_startkdeRestore->setChecked( true );
 
205
  m_maxCards->setValue( 2 );
 
206
  m_maxDevices->setValue( 2 );
 
207
  emit changed(true);
 
208
}
 
209
 
 
210
extern "C"
 
211
{
 
212
    KCModule *create_kmix(QWidget *parent, const char *name)
 
213
    {
 
214
      KGlobal::locale()->insertCatalogue("kcmkmix");
 
215
      return new KMixConfig(parent, name);
 
216
    }
 
217
 
 
218
    void init_kmix()
 
219
    {
 
220
        KConfig *config = new KConfig("kcmkmixrc", true, false);
 
221
 
 
222
        config->setGroup("Misc");
 
223
        bool start = config->readBoolEntry( "startkdeRestore", true );
 
224
        delete config;
 
225
 
 
226
        if ( start )
 
227
            kapp->startServiceByDesktopName( "kmixctrl_restore" );
 
228
    }
 
229
}
 
230
 
 
231
#include "mixconfig.moc"