toolbar settings

Benjamin Meyer ben at meyerhome.net
Fri Jul 30 01:37:57 BST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 28 July 2004 3:39 pm, Andras Mantia wrote:
> On Wednesday 28 July 2004 07:00, Jens Herden wrote:
> > Hi!
> >
> > I noticed that Quanta has a problem to remember which toolbar is
> > visible. I can disable them but if I restart Quanta they are all
> > visible again. I know that this did work.
> > More strange is that the same code compiled on KDE 3.2 does it
> > correct.
> >
> > Was there a recent change that might have caused this?
>
> Seems to be so. The problem is in KMainWindow::saveMainWindowSettings
> combined with KToolBar::saveSettings.
>
> In the first method there is an iteration through the toolbars. The
> iterators is requested with KMainWindow::toolBarIterator(), which
> rebuilds the list of toolbars and returns an iterator. The problem is
> that in the  KToolBar::saveSettings a new iterator is requested with
> KMainWindow::toolBarIterator() and this invalidates the first iterator
> in saveMainWindowSettings and only the settings for the first toolbar
> are saved. All applications that have more than one toolbar are
> affected. I think the offending code was introduced recently and it is:
>
>     // don't save if there's only one toolbar
>     if ( !kmw || kmw->toolBarIterator().count() > 1 )
>       config->writeEntry("Index", index);
>     else
>       config->revertToDefault("Index");
>
> This either should be removed or the toolbarcounting should be done in
> another way. For example add either a method to get access to the
> toolbar list
> QPtrList<KToolBar> KMainWindow::toolBarList() const
> or just the number of toolbars
> uint KMainWindoww::toolBarCount()
>
> or the dirty way without API changes: in
> KMainWindow::saveMainWindowSettings copy the list and use an iterator
> over the copy.
>
> Andras
>
> > Jens

To not add a new function how about this?  Down the line if this probably will 
always occur it would make sense not to have a function to return the 
iterator.

- -Benjamin Meyer

Index: ktoolbar.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/ktoolbar.cpp,v
retrieving revision 1.384
diff -u -3 -p -r1.384 ktoolbar.cpp
- --- ktoolbar.cpp        19 Jul 2004 15:00:55 -0000      1.384
+++ ktoolbar.cpp        30 Jul 2004 00:36:08 -0000
@@ -1097,10 +1097,24 @@ void KToolBar::saveSettings(KConfig *con
     //kdDebug(220) << name() << "                writing index " << index << 
endl;
     KMainWindow *kmw = dynamic_cast<KMainWindow *>(mainWindow());
     // don't save if there's only one toolbar
- -    if ( !kmw || kmw->toolBarIterator().count() > 1 )
- -      config->writeEntry("Index", index);
+
+    // Don't use kmw->toolBarIterator() because you might
+    // mess up someone else's iterator.  Make the list on your own
+    QPtrList<KToolBar> toolbarList;
+    QPtrList<QToolBar> lst;
+    for ( int i = (int)QMainWindow::DockUnmanaged; i <= (int)DockMinimized; 
++i ) {
+        lst = kmw->toolBars( (ToolBarDock)i );
+        for ( QToolBar *tb = lst.first(); tb; tb = lst.next() ) {
+            if ( !tb->inherits( "KToolBar" ) )
+                continue;
+            toolbarList.append( (KToolBar*)tb );
+        }
+    }
+    QPtrListIterator<KToolBar> toolbarIterator( toolbarList );
+    if ( !kmw || toolbarIterator.count() > 1 )
+        config->writeEntry("Index", index);
     else
- -      config->revertToDefault("Index");
+        config->revertToDefault("Index");

     if(!config->hasDefault("Offset") && offset() == d->OffsetDefault )
       config->revertToDefault("Offset");

- -- 
aka icefox
Public Key: http://www.csh.rit.edu/~benjamin/public_key.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBCZho1rZ3LTw38vIRAn2ZAJ9hDg2D3Q/aoRDPJz2x9eSjTpbLpgCgvj6L
KbQRg2u2AAN5qRTnY7ohPok=
=JfZ9
-----END PGP SIGNATURE-----




More information about the kde-core-devel mailing list