From cf9a9af6a8c3606e8d1e1372ea78332f4b69309e Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 18 Jan 2013 14:36:02 -0600 Subject: Properly restore icon positions on login --- kdesktop/kdiconview.cc | 85 ++++++++++++++++++++++++++++++++++++++++++----- ksmserver/shutdowndlg.cpp | 6 ++-- 2 files changed, 80 insertions(+), 11 deletions(-) diff --git a/kdesktop/kdiconview.cc b/kdesktop/kdiconview.cc index 8a9a896df..1590443d8 100644 --- a/kdesktop/kdiconview.cc +++ b/kdesktop/kdiconview.cc @@ -489,7 +489,17 @@ void KDIconView::setAutoAlign( bool b ) // Auto line-up icons if ( b ) { - if (!KRootWm::self()->startup) lineupIcons(); else KRootWm::self()->startup = false; + // set maxItemWidth to ensure sane initial icon layout before the auto align code is fully activated + int sz = iconSize() ? iconSize() : KGlobal::iconLoader()->currentSize( KIcon::Desktop ); + setMaxItemWidth( QMAX( QMAX( sz, previewIconSize( iconSize() ) ), KonqFMSettings::settings()->iconTextWidth() ) ); + setFont( font() ); // Force calcRect() + + if (!KRootWm::self()->startup) { + lineupIcons(); + } + else { + KRootWm::self()->startup = false; + } connect( this, TQT_SIGNAL( iconMoved() ), this, TQT_SLOT( lineupIcons() ) ); } @@ -1061,6 +1071,9 @@ void KDIconView::slotNewItems( const KFileItemList & entries ) KFileItemListIterator it(entries); KFileIVI* fileIVI = 0L; + typedef TQValueList KFileIVIList; + KFileIVIList newItemsList; + // Ensure that the saved positions had a chance to be loaded if (!m_dotDirectory) { initDotDirectories(); @@ -1131,14 +1144,56 @@ void KDIconView::slotNewItems( const KFileItemList & entries ) fileIVI->move( x, y ); if ( (!firstRun) && (!isFreePosition( fileIVI )) && (!m_needDesktopAlign) ) // if we can't put it there, then let TQIconView decide { - kdDebug(1214)<<"slotNewItems() pos was not free :-("<move( oldPos.x(), oldPos.y() ); - m_dotDirectory->deleteGroup( group ); - m_bNeedSave = true; + if (!isFreePosition( fileIVI )) + { + // Find the offending icon and move it out of the way; saved positions have precedence! + TQRect r = fileIVI->rect(); + TQIconViewItem *it = firstItem(); + for (; it; it = it->nextItem() ) + { + if ( !it->rect().isValid() || it == fileIVI ) + { + continue; + } + + if ( it->intersects( r ) ) + { + moveToFreePosition(it); + } + } + } + else { + kdDebug(1214)<<"slotNewItems() pos was not free :-("<move( oldPos.x(), oldPos.y() ); + m_dotDirectory->deleteGroup( group ); + m_bNeedSave = true; + } } else { - kdDebug(1214)<<"Using saved position"<rect(); + TQIconViewItem *it = firstItem(); + for (; it; it = it->nextItem() ) + { + if ( !it->rect().isValid() || it == fileIVI ) + { + continue; + } + + if ( it->intersects( r ) ) + { + moveToFreePosition(it); + } + } + } + else + { + kdDebug(1214)<<"Using saved position"<nextItem() ) { if ( !it->rect().isValid() || it == item ) + { continue; + } if ( it->intersects( r ) ) + { return false; + } } return true; diff --git a/ksmserver/shutdowndlg.cpp b/ksmserver/shutdowndlg.cpp index 3b1e27f68..5be3f70a2 100644 --- a/ksmserver/shutdowndlg.cpp +++ b/ksmserver/shutdowndlg.cpp @@ -792,15 +792,17 @@ KSMShutdownDlg::KSMShutdownDlg( TQWidget* parent, TQValueList params; params << TQT_DBusData::fromString(upowerProperties.interface()) << TQT_DBusData::fromString("CanSuspend"); TQT_DBusMessage reply = upowerProperties.sendWithReply("Get", params); - if(reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) + if(reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { canSuspend = reply[0].toVariant().value.toBool(); + } // can hibernate? params.clear(); params << TQT_DBusData::fromString(upowerProperties.interface()) << TQT_DBusData::fromString("CanHibernate"); reply = upowerProperties.sendWithReply("Get", params); - if(reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) + if(reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) { canHibernate = reply[0].toVariant().value.toBool(); + } #else #ifdef COMPILE_HALBACKEND // Query HAL for suspend/resume support -- cgit v1.2.3