~ubuntu-branches/ubuntu/natty/kdemultimedia/natty-proposed

« back to all changes in this revision

Viewing changes to kmix/apps/KMixApp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers
  • Date: 2011-05-26 02:41:36 UTC
  • mfrom: (0.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 108.
  • Revision ID: james.westby@ubuntu.com-20110526024136-jjwsigfy402jhupm
Tags: upstream-4.6.3
ImportĀ upstreamĀ versionĀ 4.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * KMix -- KDE's full featured mini mixer
 
3
 *
 
4
 * Copyright (C) 2000 Stefan Schimanski <schimmi@kde.org>
 
5
 * Copyright (C) 2001 Preston Brown <pbrown@kde.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Library General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2 of the License, or (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Library General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU Library General Public
 
18
 * License along with this program; if not, write to the Free
 
19
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
20
 */
 
21
 
 
22
#include "KMixApp.h"
 
23
#include "apps/kmix.h"
 
24
#include <kdebug.h>
 
25
 
 
26
 
 
27
bool KMixApp::_keepVisibility = false;
 
28
 
 
29
KMixApp::KMixApp()
 
30
    : KUniqueApplication(), m_kmix( 0 )
 
31
{
 
32
    // We must disable QuitOnLastWindowClosed. Rationale:
 
33
    // 1) The normal state of KMix is to only have the dock icon shown.
 
34
    // 2a) The dock icon gets reconstructed, whenever a soundcard is hotplugged or unplugged.
 
35
    // 2b) The dock icon gets reconstructed, when the user selects a new master.
 
36
    // 3) During the reconstruction, it can easily happen that no window is present => KMix would quit
 
37
    // => disable QuitOnLastWindowClosed
 
38
    setQuitOnLastWindowClosed ( false );
 
39
}
 
40
 
 
41
 
 
42
KMixApp::~KMixApp()
 
43
{
 
44
   delete m_kmix;
 
45
}
 
46
 
 
47
 
 
48
int
 
49
KMixApp::newInstance()
 
50
{
 
51
        // There are 3 cases for a new instance
 
52
 
 
53
        //kDebug(67100) <<  "KMixApp::newInstance() isRestored()=" << isRestored() << "_keepVisibility=" << _keepVisibility;
 
54
        static bool first = true;
 
55
        if ( !first )
 
56
        {       // There already exists an instance/window
 
57
 
 
58
                /* !!! @bug : _keepVisibilty has the wrong value here.
 
59
                    It is supposed to have the value set by the command line
 
60
                    arg, and the keepVisibilty() method.
 
61
                    All looks fine, BUT(!!!) THIS code is NEVER entered in
 
62
                    the just started process.
 
63
                    KDE IPC (DBUS) has instead notified the already running
 
64
                    KMix process, about a newInstance(). So _keepVisibilty
 
65
                    has always the value of the first started KMix process.
 
66
                    This is a bug in KMix and  must be fixed.
 
67
                    cesken, 2008-11-01
 
68
                 */
 
69
                 
 
70
                kDebug(67100) <<  "KMixApp::newInstance() Instance exists";
 
71
 
 
72
                if ( ! _keepVisibility && !isSessionRestored() ) {
 
73
                        kDebug(67100) <<  "KMixApp::newInstance() SHOW WINDOW (_keepVisibility=" << _keepVisibility << ", isSessionRestored=" << isSessionRestored();
 
74
                        // CASE 1: If KMix is running AND the *USER*
 
75
                        // starts it again, the KMix main window will be shown.
 
76
                        // If KMix is restored by SM or the --keepvisibilty is used, KMix will NOT
 
77
                        // explicitly be shown.
 
78
                        KUniqueApplication::newInstance();
 
79
//                      if ( !m_kmix ) {
 
80
//                              m_kmix->show();
 
81
//                      } else {
 
82
//                              kWarning(67100) << "KMixApp::newInstance() Window has not finished constructing yet so ignoring the show() request.";
 
83
//                      }
 
84
                }
 
85
                else {
 
86
                        // CASE 2: If KMix is running, AND  ( session gets restored OR keepvisibilty command line switch )
 
87
                        kDebug(67100) <<  "KMixApp::newInstance() REGULAR_START _keepVisibility=" << _keepVisibility;
 
88
                        // Special case: Command line arg --keepVisibility was used:
 
89
                        // We don't want to change the visibiliy, thus we don't call show() here.
 
90
                        //
 
91
                        //  Hint: --keepVisibility is a special option for applications that
 
92
                        //    want to start a mixer service, but don't need to show the KMix
 
93
                        //    GUI (like KMilo , KAlarm, ...).
 
94
                        //    See (e.g.) Bug 58901 for deeper insight.
 
95
                }
 
96
        }
 
97
        else
 
98
        {
 
99
                // CASE 3: KMix was not running yet => instanciate a new one
 
100
                //kDebug(67100) <<  "KMixApp::newInstance() Instanciate: _keepVisibility=" << _keepVisibility ;
 
101
                first = false;  // NB See https://qa.mandriva.com/show_bug.cgi?id=56893#c3
 
102
                                // It is important to track this via a separate variable and not
 
103
                                // based on m_kmix to handle this race condition.
 
104
                                // Specific protection for the activation-prior-to-full-construction
 
105
                                // case exists above in the 'already running case'
 
106
                m_kmix = new KMixWindow(_keepVisibility);
 
107
                //connect(this, SIGNAL(stopUpdatesOnVisibility()), m_kmix, SLOT(stopVisibilityUpdates()));
 
108
                if ( isSessionRestored() && KMainWindow::canBeRestored(0) )
 
109
                {
 
110
                        m_kmix->restore(0, false);
 
111
                }
 
112
        }
 
113
 
 
114
        return 0;
 
115
}
 
116
 
 
117
void KMixApp::keepVisibility(bool val_keepVisibility) {
 
118
   _keepVisibility = val_keepVisibility;
 
119
}
 
120
 
 
121
/*
 
122
void
 
123
KMixApp::quitExtended()
 
124
{
 
125
    // This method is here to quit hold from the dock icon: When directly calling
 
126
    // quit(), the main window will be hidden before saving the configuration.
 
127
    // isVisible() would return on quit always false (which would be bad).
 
128
    kDebug(67100) <<  "quitExtended ENTER";
 
129
    emit stopUpdatesOnVisibility();
 
130
    quit();
 
131
}
 
132
*/
 
133