~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to kmix/kmix.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * KMix -- KDE's full featured mini mixer
3
3
 *
4
 
 * $Id: kmix.cpp,v 1.111.2.1 2001/10/25 22:36:36 waba Exp $
 
4
 * $Id: kmix.cpp,v 1.197 2005/02/08 20:36:58 esken Exp $
5
5
 *
6
6
 * Copyright (C) 2000 Stefan Schimanski <schimmi@kde.org>
7
7
 * Copyright (C) 2001 Preston Brown <pbrown@kde.org>
8
 
 *
 
8
 * Copyright (C) 2003 Sven Leiber <s.leiber@web.de>
9
9
 * This program is free software; you can redistribute it and/or
10
10
 * modify it under the terms of the GNU Library General Public
11
11
 * License as published by the Free Software Foundation; either
18
18
 *
19
19
 * You should have received a copy of the GNU Library General Public
20
20
 * License along with this program; if not, write to the Free
21
 
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
22
 */
23
23
 
24
 
#include <iostream.h>
25
 
 
26
24
// include files for QT
27
 
#include <qdir.h>
28
 
#include <qapplication.h>
29
 
#include <qpopupmenu.h>
30
 
#include <qtabbar.h>
31
 
#include <qinputdialog.h>
32
 
#include <qtimer.h>
33
25
#include <qmap.h>
 
26
#include <qhbox.h>
 
27
#include <qcheckbox.h>
 
28
#include <qradiobutton.h>
 
29
#include <qwidgetstack.h>
 
30
#include <qlayout.h>
 
31
#include <qtooltip.h>
34
32
 
35
33
// include files for KDE
 
34
#include <kcombobox.h>
36
35
#include <kiconloader.h>
37
36
#include <kmessagebox.h>
38
37
#include <kmenubar.h>
 
38
#include <klineeditdlg.h>
39
39
#include <klocale.h>
40
40
#include <kconfig.h>
41
41
#include <kaction.h>
 
42
#include <kapplication.h>
42
43
#include <kstdaction.h>
43
44
#include <kpanelapplet.h>
44
45
#include <kpopupmenu.h>
45
46
#include <khelpmenu.h>
46
 
#include <kiconloader.h>
47
47
#include <kdebug.h>
48
48
#include <kaccel.h>
 
49
#include <kpopupmenu.h>
49
50
 
50
51
// application specific includes
 
52
#include "mixertoolbox.h"
51
53
#include "kmix.h"
52
54
#include "kmixerwidget.h"
53
55
#include "kmixprefdlg.h"
54
56
#include "kmixdockwidget.h"
55
 
 
56
 
 
57
 
KMixApp::KMixApp()
58
 
    : KUniqueApplication(), m_kmix( 0 )
59
 
{
60
 
}
61
 
 
62
 
 
63
 
KMixApp::~KMixApp()
64
 
{
65
 
    delete m_kmix;
66
 
}
67
 
 
68
 
 
69
 
int KMixApp::newInstance()
70
 
{
71
 
    if ( m_kmix )
72
 
        m_kmix->show();
73
 
    else {
74
 
        m_kmix = new KMixWindow;
75
 
        if ( isRestored() && KMainWindow::canBeRestored(0) )
76
 
            m_kmix->restore(0, FALSE);
77
 
    }
78
 
 
79
 
    return 0;
80
 
}
81
 
 
82
 
 
 
57
#include "kmixtoolbox.h"
 
58
 
 
59
 
 
60
/**
 
61
 * Constructs a mixer window (KMix main window)
 
62
 */
83
63
KMixWindow::KMixWindow()
84
 
   : KMainWindow(0, 0, 0 ), m_maxId( 0 ), m_visibleTabs( 0 ), m_dockWidget( 0L )
 
64
        : KMainWindow(0, 0, 0 ), m_showTicks( true ),
 
65
        m_lockedLayout(0),
 
66
        m_dockWidget( 0L )
85
67
{
86
 
   initMixer();
87
 
   initActions();
88
 
   initWidgets();
89
 
 
90
 
   loadConfig();
91
 
 
92
 
   // create mixer widgets for unused mixers
93
 
   for (Mixer *mixer=m_mixers.first(); mixer!=0; mixer=m_mixers.next()) {
94
 
 
95
 
       // search for mixer widget with current mixer
96
 
       KMixerWidget *widget;
97
 
       for ( widget=m_mixerWidgets.first(); widget!=0; widget=m_mixerWidgets.next() )
98
 
           if ( widget->mixer()==mixer ) break;
99
 
 
100
 
       // create new widget
101
 
       if ( widget==0 ) {
102
 
 
103
 
           KMixerWidget *mw = new KMixerWidget( m_maxId, mixer,
104
 
                                                mixer->mixerName(),
105
 
                                                mixer->mixerNum(),
106
 
                                                false, KPanelApplet::Up,
107
 
                                                this );
108
 
           mw->setName( mixer->mixerName() );
109
 
           insertMixerWidget( mw );
110
 
 
111
 
           m_maxId++;
112
 
       }
113
 
   }
114
 
 
115
 
   initPrefDlg();
116
 
 
117
 
   updateDocking();
118
 
 
119
 
   if ( m_startVisible )
120
 
       show();
121
 
   else
122
 
       hide();
 
68
        m_visibilityUpdateAllowed       = true;
 
69
        m_multiDriverMode               = false; // -<- I never-ever want the multi-drivermode to be activated by accident
 
70
        m_surroundView                  = false; // -<- The same is true for the experimental surround View (3D)
 
71
        // As long as we do not know better, we assume to start hidden. We need
 
72
        // to initialize this variable here, as we don't trigger a hideEvent().
 
73
        m_isVisible = false;
 
74
        m_mixerWidgets.setAutoDelete(true);
 
75
        loadConfig(); // Need to load config before initMixer(), due to "MultiDriver" keyword
 
76
        MixerToolBox::initMixer(m_mixers, m_multiDriverMode, m_hwInfoString);
 
77
        initActions();
 
78
        initWidgets();
 
79
        initMixerWidgets();
 
80
 
 
81
        initPrefDlg();
 
82
        updateDocking();
 
83
 
 
84
        if ( m_startVisible )
 
85
        {
 
86
                 /* Started visible: We should do probably do:
 
87
                  *   m_isVisible = true;
 
88
                  * But as a showEvent() is triggered by show() we don't need it.
 
89
                  */
 
90
                 show();
 
91
        }
 
92
        else
 
93
        {
 
94
                hide();
 
95
        }
 
96
        connect( kapp, SIGNAL( aboutToQuit()), SLOT( saveSettings()) );
123
97
}
124
98
 
125
99
 
126
100
KMixWindow::~KMixWindow()
127
101
{
 
102
}
 
103
 
 
104
 
 
105
void
 
106
KMixWindow::initActions()
 
107
{
 
108
        // file menu
 
109
        KStdAction::quit( this, SLOT(quit()), actionCollection());
 
110
 
 
111
        // settings menu
 
112
        KStdAction::showMenubar( this, SLOT(toggleMenuBar()), actionCollection());
 
113
        KStdAction::preferences( this, SLOT(showSettings()), actionCollection());
 
114
        KStdAction::keyBindings( guiFactory(), SLOT(configureShortcuts()), actionCollection());
 
115
 
 
116
/* Belongs in KMixDockWidget
 
117
        (void)new KToggleAction( i18n( "M&ute" ), 0, this, SLOT( dockMute() ),
 
118
                                 actionCollection(), "dock_mute" );
 
119
*/
 
120
        (void) new KAction( i18n( "Hardware &Information" ), 0, this, SLOT( slotHWInfo() ), actionCollection(), "hwinfo" );
 
121
        (void) new KAction( i18n( "Hide Mixer Window" ), Key_Escape, this, SLOT(hide()), actionCollection(), "hide_kmixwindow" );
 
122
        createGUI( "kmixui.rc" );
 
123
}
 
124
 
 
125
 
 
126
void
 
127
KMixWindow::initPrefDlg()
 
128
{
 
129
        m_prefDlg = new KMixPrefDlg( this );
 
130
        connect( m_prefDlg, SIGNAL(signalApplied(KMixPrefDlg *)),
 
131
                        this, SLOT(applyPrefs(KMixPrefDlg *)) );
 
132
}
 
133
 
 
134
 
 
135
void
 
136
KMixWindow::initWidgets()
 
137
{
 
138
        // Main widget and layout
 
139
        setCentralWidget( new QWidget(  this, "qt_central_widget" ) );
 
140
 
 
141
        // Widgets layout
 
142
        widgetsLayout = new QVBoxLayout(   centralWidget(), 0, 0, "widgetsLayout" );
 
143
        widgetsLayout->setResizeMode(QLayout::Minimum); // works fine
 
144
 
 
145
 
 
146
        // Mixer widget line
 
147
        mixerNameLayout = new QHBox( centralWidget(), "mixerNameLayout" );
 
148
        widgetsLayout->setStretchFactor( mixerNameLayout, 0 );
 
149
        QSizePolicy qsp( QSizePolicy::Ignored, QSizePolicy::Maximum);
 
150
        mixerNameLayout->setSizePolicy(qsp);
 
151
        mixerNameLayout->setSpacing(KDialog::spacingHint());
 
152
        QLabel *qlbl = new QLabel( i18n(" Current mixer:"), mixerNameLayout );
 
153
        qlbl->setFixedHeight(qlbl->sizeHint().height());
 
154
        m_cMixer = new KComboBox( FALSE, mixerNameLayout, "mixerCombo" );
 
155
        m_cMixer->setFixedHeight(m_cMixer->sizeHint().height());
 
156
        connect( m_cMixer, SIGNAL( activated( int ) ), this, SLOT( showSelectedMixer( int ) ) );
 
157
        QToolTip::add( m_cMixer, i18n("Current mixer" ) );
 
158
 
 
159
        // Add first layout to widgets
 
160
        widgetsLayout->addWidget( mixerNameLayout );
 
161
 
 
162
        m_wsMixers = new QWidgetStack( centralWidget(), "MixerWidgetStack" );
 
163
        widgetsLayout->setStretchFactor( m_wsMixers, 10 );
 
164
        widgetsLayout->addWidget( m_wsMixers );
 
165
 
 
166
        if ( m_showMenubar )
 
167
                menuBar()->show();
 
168
        else
 
169
                menuBar()->hide();
 
170
 
 
171
        widgetsLayout->activate();
 
172
}
 
173
 
 
174
 
 
175
void
 
176
KMixWindow::updateDocking()
 
177
{
 
178
        // delete old dock widget
 
179
        if (m_dockWidget)
 
180
        {
 
181
                delete m_dockWidget;
 
182
                m_dockWidget = 0L;
 
183
        }
 
184
 
 
185
        if (m_showDockWidget)
 
186
        {
 
187
 
 
188
                // create dock widget
 
189
                // !! This should be a View in the future
 
190
                m_dockWidget = new KMixDockWidget( m_mixers.first(), this, "mainDockWidget", m_volumeWidget );
 
191
 
 
192
/* Belongs in KMixDockWidget
 
193
                // create RMB menu
 
194
                KPopupMenu *menu = m_dockWidget->contextMenu();
 
195
 
 
196
                // !! check this
 
197
                KAction *a = actionCollection()->action( "dock_mute" );
 
198
                if ( a ) a->plug( menu );
 
199
*/
 
200
 
 
201
                /*
 
202
                 * Mail from 31.1.2005: "make sure your features are at least string complete"
 
203
                 * Preparation for fixing Bug #55078 - scheduled for KDE3.4.1 .
 
204
                 * This text will be plugged into the dock-icon popup menu.
 
205
                 */
 
206
                QString selectChannel = i18n("Select Channel"); // This text will be used in KDE3.4.1 !!!
 
207
 
 
208
                m_dockWidget->show();
 
209
        }
 
210
}
 
211
 
 
212
void
 
213
KMixWindow::saveSettings()
 
214
{
128
215
    saveConfig();
129
 
}
130
 
 
131
 
 
132
 
void KMixWindow::initActions()
133
 
{
134
 
    // file menu
135
 
    (void)new KAction( i18n("&New mixer tab"), "filenew", 0, this,
136
 
                       SLOT(newMixer()), actionCollection(), "file_new_tab" );
137
 
    (void)new KAction( i18n("&Close mixer tab"), "fileclose", 0, this,
138
 
                       SLOT(closeMixer()), actionCollection(), "file_close_tab" );
139
 
    (void)new KAction( i18n("&Restore default volumes"), 0, this, SLOT(loadVolumes()),
140
 
                       actionCollection(), "file_load_volume" );
141
 
    (void)new KAction( i18n("&Save current volumes as default"), 0, this, SLOT(saveVolumes()),
142
 
                       actionCollection(), "file_save_volume" );
143
 
    KStdAction::quit( this, SLOT(quit()), actionCollection());
144
 
 
145
 
    // settings menu
146
 
    KAction *a = KStdAction::showMenubar( this, SLOT(toggleMenuBar()), actionCollection());
147
 
    a->setAccel( CTRL+Key_M );
148
 
    a->plugAccel( new KAccel(this) ); // to make action working without visible menubar
149
 
    KStdAction::preferences( this, SLOT(showSettings()), actionCollection());
150
 
 
151
 
    createGUI( "kmixui.rc" );
152
 
}
153
 
 
154
 
 
155
 
void KMixWindow::initMixer()
156
 
{
157
 
   QTimer *timer = new QTimer( this );
158
 
   timer->start( 500 );
159
 
 
160
 
   // get maximum values
161
 
   KConfig *config= new KConfig("kcmkmixrc", false);
162
 
   config->setGroup("Misc");
163
 
   int maxCards = config->readNumEntry( "maxCards", 2 );
164
 
   int maxDevices = config->readNumEntry( "maxDevices", 2 );
165
 
   delete config;
166
 
 
167
 
   // poll for mixers
168
 
   QMap<QString,int> mixerNums;
169
 
   int drvNum = Mixer::getDriverNum();
170
 
   for( int drv=0; drv<drvNum && m_mixers.count()==0; drv++ )
171
 
       for( int dev=0; dev<maxDevices; dev++ )
172
 
           for( int card=0; card<maxCards; card++ ){
173
 
 
174
 
               Mixer *mixer = Mixer::getMixer( drv, dev, card );
175
 
               int mixerError = mixer->grab();
176
 
               if ( mixerError!=0 )
177
 
                   delete mixer;
178
 
               else {
179
 
                   connect( timer, SIGNAL(timeout()), mixer, SLOT(readSetFromHW()));
180
 
                   m_mixers.append( mixer );
181
 
 
182
 
                   // count mixer nums for every mixer name to identify mixers with equal names
183
 
                   mixerNums[mixer->mixerName()]++;
184
 
                   mixer->setMixerNum( mixerNums[mixer->mixerName()] );
185
 
               }
186
 
 
187
 
           }
188
 
}
189
 
 
190
 
 
191
 
void KMixWindow::initPrefDlg()
192
 
{
193
 
   m_prefDlg = new KMixPrefDlg;
194
 
   connect( m_prefDlg, SIGNAL(signalApplied(KMixPrefDlg *)),
195
 
            this, SLOT(applyPrefs(KMixPrefDlg *)) );
196
 
}
197
 
 
198
 
 
199
 
void KMixWindow::initWidgets()
200
 
{
201
 
   m_tab = new QTabWidget( this );
202
 
   setCentralWidget( m_tab );
203
 
}
204
 
 
205
 
 
206
 
void KMixWindow::updateDocking()
207
 
{
208
 
    // delete old dock widget
209
 
    if (m_dockWidget) {
210
 
        delete m_dockWidget;
211
 
        m_dockWidget = 0L;
212
 
    }
213
 
 
214
 
    if (m_showDockWidget) {
215
 
 
216
 
        // create dock widget
217
 
        m_dockWidget = new KMixDockWidget( m_mixers.first(), this );
218
 
        m_dockWidget->setPixmap( BarIcon("kmixdocked") );
219
 
 
220
 
        // create RMB menu
221
 
        QPopupMenu *menu = m_dockWidget->contextMenu();
222
 
 
223
 
        KAction *a = actionCollection()->action("options_configure");
224
 
        if (a) a->plug( menu );
225
 
 
226
 
        menu->insertSeparator();
227
 
 
228
 
        a = actionCollection()->action("help_about_app");
229
 
        if (a) a->plug( menu );
230
 
 
231
 
        a = actionCollection()->action("help");
232
 
        if (a) a->plug( menu );
233
 
 
234
 
        m_dockWidget->show();
235
 
    }
236
 
}
237
 
 
238
 
 
239
 
void KMixWindow::saveConfig()
240
 
{
241
 
   KConfig *config = kapp->config();
242
 
   config->setGroup(0);
 
216
    saveVolumes();
 
217
}
 
218
 
 
219
void
 
220
KMixWindow::saveConfig()
 
221
{
 
222
    KConfig *config = kapp->config();
 
223
    config->setGroup(0);
 
224
 
 
225
   // make sure we don't start without any UI
 
226
   // can happen e.g. when not docked and kmix closed via 'X' button
 
227
   bool startVisible = m_isVisible;
 
228
   if ( !m_showDockWidget )
 
229
       startVisible = true;
243
230
 
244
231
   config->writeEntry( "Size", size() );
245
232
   config->writeEntry( "Position", pos() );
246
 
   config->writeEntry( "Visible", isVisible() );
 
233
   // Cannot use isVisible() here, as in the "aboutToQuit()" case this widget is already hidden.
 
234
   // (Please note that the problem was only there when quitting via Systray - esken).
 
235
   config->writeEntry( "Visible", startVisible );
247
236
   config->writeEntry( "Menubar", m_showMenubar );
248
237
   config->writeEntry( "AllowDocking", m_showDockWidget );
249
238
   config->writeEntry( "TrayVolumeControl", m_volumeWidget );
250
 
// commented out for usability. nolden
251
 
//   config->writeEntry( "HideOnClose", m_hideOnClose );
252
239
   config->writeEntry( "Tickmarks", m_showTicks );
253
240
   config->writeEntry( "Labels", m_showLabels );
 
241
   config->writeEntry( "startkdeRestore", m_onLogin );
 
242
   if ( m_toplevelOrientation  == Qt::Vertical )
 
243
      config->writeEntry( "Orientation","Vertical" );
 
244
   else
 
245
      config->writeEntry( "Orientation","Horizontal" );
254
246
 
255
247
   // save mixer widgets
256
 
   QStringList tabs;
257
 
   for (KMixerWidget *mw=m_mixerWidgets.first(); mw!=0; mw=m_mixerWidgets.next())
 
248
   for ( KMixerWidget *mw = m_mixerWidgets.first(); mw != 0; mw = m_mixerWidgets.next() )
258
249
   {
259
 
      QString grp;
260
 
      grp.sprintf( "%i", mw->id() );
261
 
      tabs << grp;
262
 
 
263
 
      config->setGroup( grp );
264
 
      config->writeEntry( "Mixer", mw->mixerNum() );
265
 
      config->writeEntry( "MixerName", mw->mixerName() );
266
 
      config->writeEntry( "Name", mw->name() );
267
 
 
268
 
      mw->saveConfig( config, grp );
 
250
                QString grp;
 
251
                grp.sprintf( "%i", mw->id() );
 
252
                mw->saveConfig( config, grp );
269
253
   }
270
254
 
271
255
   config->setGroup(0);
272
 
   config->writeEntry( "Tabs", tabs );
273
256
}
274
257
 
275
 
 
276
 
void KMixWindow::loadConfig()
 
258
void
 
259
KMixWindow::loadConfig()
277
260
{
278
 
   KConfig *config = kapp->config();
279
 
   config->setGroup(0);
 
261
    KConfig *config = kapp->config();
 
262
    config->setGroup(0);
280
263
 
281
264
   m_showDockWidget = config->readBoolEntry("AllowDocking", true);
282
265
   m_volumeWidget = config->readBoolEntry("TrayVolumeControl", true);
283
 
  //hide on close has to stay true for usability. KMixPrefDlg option commented out. nolden
 
266
        //hide on close has to stay true for usability. KMixPrefDlg option commented out. nolden
284
267
   m_hideOnClose = config->readBoolEntry("HideOnClose", true);
285
 
   m_showTicks = config->readBoolEntry("Tickmarks", false);
286
 
   m_showLabels = config->readBoolEntry("Labels", false);
 
268
   m_showTicks = config->readBoolEntry("Tickmarks", true);
 
269
   m_showLabels = config->readBoolEntry("Labels", true);
 
270
   m_onLogin = config->readBoolEntry("startkdeRestore", true );
287
271
   m_startVisible = config->readBoolEntry("Visible", true);
 
272
   m_multiDriverMode = config->readBoolEntry("MultiDriver", false);
 
273
   m_surroundView    = config->readBoolEntry("Experimental-ViewSurround", false );
 
274
   const QString& orientationString = config->readEntry("Orientation", "Horizontal");
 
275
   if ( orientationString == "Vertical" )
 
276
       m_toplevelOrientation  = Qt::Vertical;
 
277
   else
 
278
       m_toplevelOrientation = Qt::Horizontal;
288
279
 
289
280
   // show/hide menu bar
290
281
   m_showMenubar = config->readBoolEntry("Menubar", true);
291
 
   if ( m_showMenubar )
292
 
      menuBar()->show();
293
 
   else
294
 
      menuBar()->hide();
295
282
 
296
283
   KToggleAction *a = static_cast<KToggleAction*>(actionCollection()->action("options_show_menubar"));
297
284
   if (a) a->setChecked( m_showMenubar );
298
285
 
299
 
   // load mixer widgets
300
 
   QString tabsStr = config->readEntry( "Tabs" );
301
 
   QStringList tabs = QStringList::split( ',', tabsStr );
302
 
   m_mixerWidgets.clear();
303
 
   for ( QStringList::Iterator tab=tabs.begin(); tab!=tabs.end(); ++tab )
304
 
   {
305
 
       // set config group
306
 
       config->setGroup(*tab);
307
 
 
308
 
       // get id
309
 
       int id = (*tab).toInt();
310
 
       if ( id>=m_maxId ) m_maxId = id+1;
311
 
 
312
 
       // find mixer
313
 
       int mixerNum = config->readNumEntry( "Mixer", -1 );
314
 
       QString mixerName = config->readEntry( "MixerName", QString::null );
315
 
       QString name = config->readEntry( "Name", mixerName );
316
 
       Mixer *mixer = 0;
317
 
 
318
 
       if ( mixerNum>=0 ) {
319
 
 
320
 
           for ( mixer=m_mixers.first(); mixer!=0; mixer=m_mixers.next() ) {
321
 
               if ( mixer->mixerName()==mixerName && mixer->mixerNum()==mixerNum ) break;
322
 
           }
323
 
 
324
 
       }
325
 
 
326
 
       KMixerWidget *mw = new KMixerWidget( id, mixer, mixerName, mixerNum, 
327
 
                                            false, KPanelApplet::Up, this );
328
 
       mw->setName( name );
329
 
       mw->loadConfig( config, *tab );
330
 
       insertMixerWidget( mw );
331
 
   }
332
 
 
333
286
   // restore window size and position
334
287
   if ( !kapp->isRestored() ) // done by the session manager otherwise
335
288
   {
336
 
       QSize defSize( minimumWidth(), height() );
337
 
       QSize size = config->readSizeEntry("Size", &defSize );
338
 
       if(!size.isEmpty()) resize(size);
339
 
 
340
 
       QPoint defPos = pos();
341
 
       QPoint pos = config->readPointEntry("Position", &defPos);
342
 
       move(pos);
343
 
   }
344
 
}
345
 
 
346
 
 
347
 
void KMixWindow::insertMixerWidget( KMixerWidget *mw )
348
 
{
349
 
   m_mixerWidgets.append( mw );
350
 
 
351
 
   m_visibleTabs++;
352
 
   m_tab->addTab( mw, mw->name() );
353
 
   mw->setTicks( m_showTicks );
354
 
   mw->setLabels( m_showLabels );
355
 
   mw->show();
356
 
   connect( mw, SIGNAL(updateLayout()), this, SLOT(updateLayout()) );
357
 
 
358
 
   KAction *a = actionCollection()->action( "file_close_tab" );
359
 
   if ( a ) a->setEnabled( m_visibleTabs>1 );
360
 
 
361
 
   updateLayout();
362
 
}
363
 
 
364
 
 
365
 
void KMixWindow::removeMixerWidget( KMixerWidget *mw )
366
 
{
367
 
    m_visibleTabs--;
368
 
    m_tab->removePage( mw );
369
 
    m_mixerWidgets.remove( mw );
370
 
 
371
 
    KAction *a = actionCollection()->action( "file_close_tab" );
372
 
    if ( a ) a->setEnabled( m_visibleTabs>1 );
373
 
 
374
 
    updateLayout();
375
 
}
376
 
 
377
 
 
378
 
void KMixWindow::updateLayout()
379
 
{
380
 
    m_tab->setMinimumSize( m_tab->minimumSizeHint() );
381
 
}
382
 
 
383
 
void KMixWindow::closeEvent ( QCloseEvent * e )
384
 
{
385
 
    if ( /*m_hideOnClose &&*/ m_showDockWidget )
 
289
                QSize defSize( minimumWidth(), height() );
 
290
                QSize size = config->readSizeEntry("Size", &defSize );
 
291
                if(!size.isEmpty()) resize(size);
 
292
 
 
293
                QPoint defPos = pos();
 
294
                QPoint pos = config->readPointEntry("Position", &defPos);
 
295
                move(pos);
 
296
        }
 
297
}
 
298
 
 
299
 
 
300
void
 
301
KMixWindow::initMixerWidgets()
 
302
{
 
303
   m_mixerWidgets.clear();
 
304
 
 
305
        int id=0;
 
306
        Mixer *mixer;
 
307
 
 
308
        // Attention!! If m_mixers is empty, we behave stupid. We don't show nothing and there
 
309
        //             is not even a context menu.
 
310
        for ( mixer=m_mixers.first(),id=0; mixer!=0; mixer=m_mixers.next(),id++ )
 
311
        {
 
312
            //kdDebug(67100) << "Mixer number: " << id << " Name: " << mixer->mixerName() << endl ;
 
313
 
 
314
 
 
315
                ViewBase::ViewFlags vflags = ViewBase::HasMenuBar;
 
316
                if ( m_showMenubar ) {
 
317
                    vflags |= ViewBase::MenuBarVisible;
 
318
                }
 
319
                if (  m_surroundView ) {
 
320
                    vflags |= ViewBase::Experimental_SurroundView;
 
321
                }
 
322
                if ( m_toplevelOrientation == Qt::Vertical ) {
 
323
                    vflags |= ViewBase::Vertical;
 
324
                }
 
325
                else {
 
326
                    vflags |= ViewBase::Horizontal;
 
327
                }
 
328
 
 
329
        
 
330
                KMixerWidget *mw = new KMixerWidget( id, mixer, mixer->mixerName(), mixer->mixerNum(),
 
331
                                                     MixDevice::ALL, this, "KMixerWidget", vflags );
 
332
 
 
333
                //mw->setName( mixer->mixerName() );
 
334
 
 
335
                m_mixerWidgets.append( mw );
 
336
 
 
337
                // Add to Combo
 
338
                m_cMixer->insertItem( mixer->mixerName() );
 
339
 
 
340
                // Add to Stack
 
341
                //kdDebug(67100) << "Inserted mixer " << id << ":" << mw->name() << endl;
 
342
                m_wsMixers->addWidget( mw, id );
 
343
 
 
344
                QString grp;
 
345
                grp.sprintf( "%i", mw->id() );
 
346
                mw->loadConfig( kapp->config(), grp );
 
347
 
 
348
                mw->setTicks( m_showTicks );
 
349
                mw->setLabels( m_showLabels );
 
350
                // !! I am still not sure whether this works 100% reliably - chris
 
351
                mw->show();
 
352
        }
 
353
 
 
354
        if (id == 1)
 
355
        {
 
356
                // don't show the Current Mixer bit unless we have multiple mixers
 
357
                mixerNameLayout->hide();
 
358
        }
 
359
}
 
360
 
 
361
bool
 
362
KMixWindow::queryClose ( )
 
363
{
 
364
    if ( m_showDockWidget && !kapp->sessionSaving() )
386
365
    {
387
 
        // <evil>
388
 
        kapp->ref(); // prevent KMainWindow from closing the app
389
 
        // </evil>
390
 
    } else
391
 
        kapp->quit(); // force the application to quit
392
 
 
393
 
    KMainWindow::closeEvent( e );
 
366
        hide();
 
367
        return false;
 
368
    }
 
369
    return true;
394
370
}
395
371
 
396
372
 
397
 
void KMixWindow::quit()
 
373
void
 
374
KMixWindow::quit()
398
375
{
399
 
   kapp->quit();
 
376
        kapp->quit();
400
377
}
401
378
 
402
379
 
403
 
void KMixWindow::showSettings()
 
380
void
 
381
KMixWindow::showSettings()
404
382
{
405
383
   if (!m_prefDlg->isVisible())
406
384
   {
407
385
      m_prefDlg->m_dockingChk->setChecked( m_showDockWidget );
408
386
      m_prefDlg->m_volumeChk->setChecked(m_volumeWidget);
409
 
//      m_prefDlg->m_hideOnCloseChk->setChecked( m_hideOnClose );
410
387
      m_prefDlg->m_showTicks->setChecked( m_showTicks );
411
388
      m_prefDlg->m_showLabels->setChecked( m_showLabels );
 
389
      m_prefDlg->m_onLogin->setChecked( m_onLogin );
 
390
      m_prefDlg->_rbVertical  ->setChecked( m_toplevelOrientation == Qt::Vertical );
 
391
      m_prefDlg->_rbHorizontal->setChecked( m_toplevelOrientation == Qt::Horizontal );
412
392
 
413
393
      m_prefDlg->show();
414
394
   }
415
395
}
416
396
 
417
397
 
418
 
void KMixWindow::showHelp()
 
398
void
 
399
KMixWindow::showHelp()
419
400
{
420
 
   actionCollection()->action( "help_contents" )->activate();
 
401
        actionCollection()->action( "help_contents" )->activate();
421
402
}
422
403
 
423
404
 
424
 
void KMixWindow::showAbout()
 
405
void
 
406
KMixWindow::showAbout()
425
407
{
426
408
   actionCollection()->action( "help_about_app" )->activate();
427
409
}
428
410
 
429
 
 
430
 
void KMixWindow::closeMixer()
431
 
{
432
 
   if (m_mixerWidgets.count()<=1) return;
433
 
   removeMixerWidget( (KMixerWidget *)m_tab->currentPage() );
434
 
}
435
 
 
436
 
 
437
 
void KMixWindow::newMixer()
438
 
{
439
 
   QStringList lst;
440
 
 
441
 
   int n=1;
442
 
   for (Mixer *mixer=m_mixers.first(); mixer!=0; mixer=m_mixers.next())
443
 
   {
444
 
      QString s;
445
 
      s.sprintf("%i. %s", n, mixer->mixerName().ascii());
446
 
      lst << s;
447
 
      n++;
448
 
   }
449
 
 
450
 
   bool ok = FALSE;
451
 
   QString res = QInputDialog::getItem( i18n("Mixers"),
452
 
                                        i18n( "Available mixers" ), lst,
453
 
                                        1, TRUE, &ok, this );
454
 
   if ( ok )
455
 
   {
456
 
       // valid mixer?
457
 
       Mixer *mixer = m_mixers.at( lst.findIndex( res ) );
458
 
       if (!mixer) {
459
 
           KMessageBox::sorry( this, i18n("Invalid mixer entered.") );
460
 
           return;
461
 
       }
462
 
 
463
 
       // ask for description
464
 
       QString name = QInputDialog::getText( i18n("Description"), i18n( "Description" ),
465
 
                                             mixer->mixerName(), &ok, this );
466
 
      if ( ok ) {
467
 
 
468
 
          // create mixer widget
469
 
          KMixerWidget *mw = new KMixerWidget( m_maxId, mixer, mixer->mixerName(), mixer->mixerNum(),
470
 
                                               false, KPanelApplet::Up, this );
471
 
          m_maxId++;
472
 
          mw->setName( name );
473
 
          insertMixerWidget( mw );
474
 
      }
475
 
   }
476
 
}
477
 
 
478
 
 
479
 
void KMixWindow::loadVolumes()
480
 
{
481
 
   KConfig *cfg = new KConfig( "kmixctrlrc", true );
482
 
   for (Mixer *mixer=m_mixers.first(); mixer!=0; mixer=m_mixers.next())
483
 
      mixer->volumeLoad( cfg );
484
 
   delete cfg;
485
 
}
486
 
 
487
 
 
488
 
void KMixWindow::saveVolumes()
489
 
{
490
 
   KConfig *cfg = new KConfig( "kmixctrlrc", false );
491
 
   for (Mixer *mixer=m_mixers.first(); mixer!=0; mixer=m_mixers.next())
492
 
      mixer->volumeSave( cfg );
493
 
   delete cfg;
494
 
}
495
 
 
496
 
 
497
 
void KMixWindow::applyPrefs( KMixPrefDlg *prefDlg )
 
411
/**
 
412
 * Loads the volumes of all mixers from kmixctrlrc.
 
413
 * In other words:
 
414
 * Restores the default voumes as stored via saveVolumes() or the
 
415
 * execution of "kmixctrl --save"
 
416
 */
 
417
/* Currently this is not in use
 
418
void
 
419
KMixWindow::loadVolumes()
 
420
{
 
421
        KConfig *cfg = new KConfig( "kmixctrlrc", true );
 
422
        for (Mixer *mixer=m_mixers.first(); mixer!=0; mixer=m_mixers.next())
 
423
        {
 
424
                mixer->volumeLoad( cfg );
 
425
        }
 
426
        delete cfg;
 
427
}
 
428
*/
 
429
 
 
430
/**
 
431
 * Stores the volumes of all mixers  Can be restored via loadVolumes() or
 
432
 * the kmixctrl application.
 
433
 */
 
434
void
 
435
KMixWindow::saveVolumes()
 
436
{
 
437
    KConfig *cfg = new KConfig( "kmixctrlrc", false );
 
438
    for (Mixer *mixer=m_mixers.first(); mixer!=0; mixer=m_mixers.next()) {
 
439
        //kdDebug(67100) << "KMixWindow::saveConfig()" << endl;
 
440
        mixer->volumeSave( cfg );
 
441
    }
 
442
    delete cfg;
 
443
}
 
444
 
 
445
 
 
446
void
 
447
KMixWindow::applyPrefs( KMixPrefDlg *prefDlg )
498
448
{
499
449
   m_showDockWidget = prefDlg->m_dockingChk->isChecked();
500
450
   m_volumeWidget = prefDlg->m_volumeChk->isChecked();
501
 
//   m_hideOnClose = prefDlg->m_hideOnCloseChk->isChecked();
502
451
   m_showTicks = prefDlg->m_showTicks->isChecked();
503
452
   m_showLabels = prefDlg->m_showLabels->isChecked();
 
453
   m_onLogin = prefDlg->m_onLogin->isChecked();
 
454
   if ( prefDlg->_rbVertical->isChecked() ) {
 
455
      kdDebug(67100) << "KMix should change to Vertical layout\n";
 
456
      m_toplevelOrientation = Qt::Vertical;
 
457
   }
 
458
   else if ( prefDlg->_rbHorizontal->isChecked() ) {
 
459
     kdDebug(67100) << "KMix should change to Horizontal layout\n";
 
460
     m_toplevelOrientation = Qt::Horizontal;
 
461
   }
 
462
 
 
463
 
 
464
   this->setUpdatesEnabled(false);
 
465
   updateDocking();
504
466
 
505
467
   for (KMixerWidget *mw=m_mixerWidgets.first(); mw!=0; mw=m_mixerWidgets.next())
506
468
   {
507
469
      mw->setTicks( m_showTicks );
508
470
      mw->setLabels( m_showLabels );
 
471
      mw->mixer()->readSetFromHWforceUpdate(); // needed, as updateDocking() has reconstructed the DockWidget
509
472
   }
510
473
 
511
 
   updateDocking();
 
474
   this->setUpdatesEnabled(false);
512
475
 
513
476
   // avoid invisible and unaccessible main window
514
477
   if( !m_showDockWidget && !isVisible() )
515
 
      show();
 
478
   {
 
479
       show();
 
480
   }
516
481
 
 
482
   this->repaint(); // make KMix look fast (saveConfig() often uses several seconds)
 
483
   kapp->processEvents();
517
484
   saveConfig();
518
485
}
519
486
 
520
487
 
521
 
void KMixWindow::toggleMenuBar()
 
488
void
 
489
KMixWindow::toggleMenuBar()
522
490
{
523
 
    m_showMenubar = !m_showMenubar;
524
 
   if( m_showMenubar )
525
 
      menuBar()->show();
 
491
        m_showMenubar = !m_showMenubar;
 
492
        if( m_showMenubar )
 
493
        {
 
494
                menuBar()->show();
 
495
        }
526
496
   else
527
 
      menuBar()->hide();
528
 
}
529
 
 
530
 
 
531
 
void KMixWindow::toggleVisibility()
532
 
{
533
 
   if ( isVisible() ) hide(); else show();
 
497
        {
 
498
                menuBar()->hide();
 
499
        }
 
500
}
 
501
 
 
502
void
 
503
KMixWindow::showEvent( QShowEvent * )
 
504
{
 
505
    if ( m_visibilityUpdateAllowed )
 
506
        m_isVisible = isVisible();
 
507
    // !! could possibly start polling now (idea: use someting like ref() and unref() on Mixer instance
 
508
}
 
509
 
 
510
void
 
511
KMixWindow::hideEvent( QHideEvent * )
 
512
{
 
513
    if ( m_visibilityUpdateAllowed )
 
514
    {
 
515
        m_isVisible = isVisible();
 
516
    }
 
517
    // !! could possibly stop polling now (idea: use someting like ref() and unref() on Mixer instance
 
518
    //    Update: This is a stupid idea, because now the views are responsible for updating. So it will be done in the Views.
 
519
    //    But the dock icon is currently no View, so that must be done first.
 
520
}
 
521
 
 
522
 
 
523
void
 
524
KMixWindow::stopVisibilityUpdates() {
 
525
    m_visibilityUpdateAllowed = false;
 
526
}
 
527
 
 
528
void
 
529
KMixWindow::slotHWInfo() {
 
530
        KMessageBox::information( 0, m_hwInfoString, i18n("Mixer Hardware Information") );
 
531
}
 
532
 
 
533
void
 
534
KMixWindow::showSelectedMixer( int mixer )
 
535
{
 
536
        m_wsMixers->raiseWidget( mixer );
534
537
}
535
538
 
536
539
#include "kmix.moc"
 
540