Bug 244583 - Amarok layout resets when the application is closed minimized in the tray
Summary: Amarok layout resets when the application is closed minimized in the tray
Status: RESOLVED FIXED
Alias: None
Product: amarok
Classification: Applications
Component: general (show other bugs)
Version: 2.3.1-GIT
Platform: Unlisted Binaries Linux
: NOR normal
Target Milestone: ---
Assignee: Amarok Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-14 10:18 UTC by Jan F.
Modified: 2010-11-09 12:56 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 2.4


Attachments
Layout not saved if Amarok closed while minimized (223.19 KB, image/png)
2010-07-14 10:28 UTC, Valorie Zimmerman
Details
My normal layout, saved if Amarok is not closed while minimized (240.75 KB, image/png)
2010-07-14 10:30 UTC, Valorie Zimmerman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan F. 2010-07-14 10:18:44 UTC
Version:           2.3.1-GIT (using KDE 4.4.4) 
OS:                Linux

When you quit Amarok and have it minimized in the tray, it changes the layout.

Reproducible: Always

Steps to Reproduce:
Minimize the Amarok to the tray and then quit it. After running again, the layout has changed.


Expected Results:  
The layout should remain the same as before closing the application.

OS: Linux (i686) release 2.6.31.12-0.2-desktop
Compiler: gcc
Comment 1 Valorie Zimmerman 2010-07-14 10:28:13 UTC
Created attachment 49142 [details]
Layout not saved if Amarok closed while minimized

I tried this both with and without locking the layout. 

Another attachment follows with my normal layout, which is saved if I quit while Amarok is not minimized, whether via Control Q, from the main menu, or right-clicking on the systray icon.
Comment 2 Valorie Zimmerman 2010-07-14 10:30:11 UTC
Created attachment 49143 [details]
My normal layout, saved if Amarok is not closed while minimized

Layout is not usually locked. Newest GIT, built today.
Comment 3 Myriam Schweingruber 2010-07-14 10:37:23 UTC
Confirmed by second reporter.
Comment 4 Maxime Corteel 2010-07-24 20:20:57 UTC
I've been having the exact same bug, I think since 2.3.
Comment 5 Myriam Schweingruber 2010-07-26 23:46:00 UTC
Could be related to bug 215221
Comment 6 Kevin Funk 2010-07-28 14:44:00 UTC
commit a9d58934229ffa5e3d87319b11b334ccd81bb6c7
Author: Kevin Funk <krf@electrostorm.net>
Date:   Wed Jul 28 12:52:12 2010 +0200

    Fix MainWindow layout saving if window is hidden
    
    Qt restoreState() and saveState() methods require a valid layouting when
    loading/saving the state of the DockWidgets.
    On "Minimize to tray" the MainWindow is hidden which destroys this.
    Saving the state then gives us an invalid layout.
    Same goes for restoring, the state must be restored while the MainWindow
    is visible.
    
    BUG: 244583

diff --git a/ChangeLog b/ChangeLog
index 7f4ff3e..48e29b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -41,9 +41,10 @@ VERSION 2.3.2-Beta 1
       Patch by Richard Longland <rlongland@hotmail.com>.
 
   BUGFIXES:
+    * Fixed Amarok layout saving when minized to tray. (BR 244583)
     * Make "No other participants" in the events applet translatable.
       Patch by Jan Janssen. (BR 235311)
-    * Fix track number on DAAP shares. Patch by Silvio Frischknecht. (BR 235030)
+    * Fixed track number on DAAP shares. Patch by Silvio Frischknecht. (BR 235030)
     * Fixed filtering by rating in the playlist. (BR 240293)
     * The scripts categories are now translatable. (BR 240563)
     * Fixed Amarok 1.4 Database Importer not importing statistics and lyrics of
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index c25ef10..a34fe7c 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -131,6 +131,7 @@ MainWindow::MainWindow()
     : KMainWindow( 0 )
     , Engine::EngineObserver( The::engineController() )
     , m_lastBrowser( 0 )
+    , m_layoutEverRestored( false )
     , m_waitingForCd( false )
     , m_mouseDown( false )
     , m_LH_initialized( false )
@@ -196,8 +197,6 @@ MainWindow::~MainWindow()
     //foreach( int a, m_splitter->saveState() )
     //    sPanels.append( a );
 
-    saveLayout();
-
     //AmarokConfig::setPanelsSavedState( sPanels );
 
     //delete m_splitter;
@@ -347,9 +346,9 @@ MainWindow::init()
     // we must filter ourself to get mouseevents on the "splitter" - what is us, but filtered by the layouter
     installEventFilter( this );
 
-    //restore the layout
+    // restore the layout on app start
     restoreLayout();
-    saveLayout();
+
     // wait for the eventloop
     QTimer::singleShot( 0, this, SLOT( initLayoutHack() ) );
 }
@@ -421,6 +420,12 @@ MainWindow::saveLayout()  //SLOT
 {
     DEBUG_BLOCK
 
+    // Do not save the layout if the main window is hidden
+    // Qt takes widgets out of the layout if they're not visible.
+    // So this is not going to work. Also see bug 244583
+    if (!isVisible())
+        return;
+
     //save layout to file. Does not go into to rc as it is binary data.
     QFile file( Amarok::saveLocation() + "layout" );
 
@@ -465,13 +470,16 @@ MainWindow::closeEvent( QCloseEvent *e )
 {
     DEBUG_BLOCK
 
+    debug() << "Saving layout before minimizing the MainWindow";
+    saveLayout();
+
 #ifdef Q_WS_MAC
     Q_UNUSED( e );
     hide();
 #else
+
     //KDE policy states we should hide to tray and not quit() when the
     //close window button is pushed for the main widget
-
     if( AmarokConfig::showTrayIcon() && e->spontaneous() && !kapp->sessionSaving() )
     {
         KMessageBox::information( this,
@@ -490,6 +498,31 @@ MainWindow::closeEvent( QCloseEvent *e )
 }
 
 void
+MainWindow::showEvent(QShowEvent* e)
+{
+    DEBUG_BLOCK
+
+    // restore layout on first maximize request after start. See bug 244583
+    if (!m_layoutEverRestored)
+        restoreLayout();
+
+    QWidget::showEvent(e);
+}
+
+
+bool
+MainWindow::queryExit()
+{
+    DEBUG_BLOCK
+
+    // save layout on app exit
+    saveLayout();
+    
+    return true; // KMainWindow API expects us to always return true
+}
+
+
+void
 MainWindow::exportPlaylist() const //SLOT
 {
     DEBUG_BLOCK
@@ -1412,7 +1445,10 @@ bool MainWindow::eventFilter( QObject *o, QEvent *e )
             if( me->button() == Qt::LeftButton )
                 m_mouseDown = ( e->type() == QEvent::MouseButtonPress );
         }
+
         return false;
+
+
     }
 
     if( ( ( e->type() == QEvent::Resize && m_mouseDown ) || // only when resized by the splitter :)
@@ -1557,6 +1593,12 @@ MainWindow::restoreLayout()
 {
     DEBUG_BLOCK
 
+    // Do not restore the layout if the main window is hidden
+    // Qt takes widgets out of the layout if they're not visible.
+    // So this is not going to work. Also see bug 244583
+    if (!isVisible())
+        return;
+
     QFile file( Amarok::saveLocation() + "layout" );
     QByteArray layout;
     if( file.open( QIODevice::ReadOnly ) )
@@ -1608,6 +1650,8 @@ MainWindow::restoreLayout()
     // Ensure that we don't end up without any toolbar (can happen after upgrading)
     if( m_mainToolbar->isHidden() && m_slimToolbar->isHidden() )
         m_mainToolbar->show();
+
+    m_layoutEverRestored = true;
 }
 
 
diff --git a/src/MainWindow.h b/src/MainWindow.h
index 4c45a2c..2ba1bda 100644
--- a/src/MainWindow.h
+++ b/src/MainWindow.h
@@ -166,9 +166,11 @@ class AMAROK_EXPORT MainWindow : public KMainWindow, public Engine::EngineObserv
     protected:
         bool eventFilter(QObject *, QEvent *);
         virtual void closeEvent( QCloseEvent* );
+        virtual void showEvent( QShowEvent* event );
         virtual void keyPressEvent( QKeyEvent* );
         virtual void resizeEvent ( QResizeEvent * event );
         virtual void paletteChange( const QPalette & oldPalette );
+        virtual bool queryExit(); 
 
     private slots:
         void setRating1() { setRating( 1 ); }
@@ -217,6 +219,7 @@ class AMAROK_EXPORT MainWindow : public KMainWindow, public Engine::EngineObserv
         static QPointer<MainWindow> s_instance;
 
         bool m_layoutLocked;
+        bool m_layoutEverRestored;
 
         bool m_waitingForCd;
Comment 7 Jan F. 2010-10-20 14:06:39 UTC
Hello,
after the GIT commit 7dbec1171386f182be77942ae43dc3684a96cfc4 from Sat, 2 Oct 2010 by Mark Kretschmann, this bug appeared again.
Comment 8 Maxime Corteel 2010-10-20 14:11:53 UTC
I confirm, the bug is still there...
Comment 9 Myriam Schweingruber 2010-10-20 14:40:21 UTC
Confirming with current 2.4-git
Comment 10 Jan F. 2010-11-04 09:42:24 UTC
Looks like repaired in latest GIT by commit 12e71c4ae98554d44a03b005b864031f53bbc981 from Wed, 27 Oct 2010 05:21:25 +0000 (18:21 +1300) by Rick W. Chen.
Please confirm.
Comment 11 Myriam Schweingruber 2010-11-09 12:56:51 UTC
Confirmed in current git, this is indeed fixed now.