From kde-commits Wed Apr 30 23:00:13 2008 From: Thomas McGuire Date: Wed, 30 Apr 2008 23:00:13 +0000 To: kde-commits Subject: KDE/kdepim/kmail Message-Id: <1209596413.917123.19577.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=120959643104182 SVN commit 802876 by tmcguire: Bug fixes: - Don't eat escape or enter keypresses, so that moving a message to a folder with the keyboard works again - actually return the correct folder, by setting the currentItem as well, instead of only selecting an item. Other stuff: - Add some consts - use QAction::setData instead of comparing the action names - //< => ///<, so that doxygen recognises those - some style fixes (identation, whitespace mainly) - remove the ifdef'd out styleDependantFrameWidth M +1 -1 folderselectiondialog.cpp M +1 -1 folderselectiondialog.h M +32 -31 folderselectiontreewidget.cpp M +10 -10 folderselectiontreewidget.h M +17 -63 kmmimeparttree.cpp M +4 -12 kmmimeparttree.h --- trunk/KDE/kdepim/kmail/folderselectiondialog.cpp #802875:802876 @@ -86,7 +86,7 @@ } -KMFolder * FolderSelectionDialog::folder( void ) +KMFolder * FolderSelectionDialog::folder( void ) const { return mTreeView->folder(); } --- trunk/KDE/kdepim/kmail/folderselectiondialog.h #802875:802876 @@ -78,7 +78,7 @@ /** * Returns the currently selected folder, or 0 if no folder is selected (yet) */ - virtual KMFolder * folder(); + KMFolder * folder() const; /** * Set the selected folder. Forwarded to FolderSelectionTreeWidget. --- trunk/KDE/kdepim/kmail/folderselectiontreewidget.cpp #802875:802876 @@ -44,7 +44,7 @@ void setFolder( KMFolder * folder ) { mFolder = folder; }; - KMFolder * folder() + KMFolder * folder() const { return mFolder; }; private: @@ -62,10 +62,8 @@ mPathColumnIndex = addColumn( i18n( "Path" ) ); setContextMenuPolicy( Qt::CustomContextMenu ); - connect( - this, SIGNAL( customContextMenuRequested( const QPoint & ) ), - this, SLOT( slotContextMenuRequested( const QPoint & ) ) - ); + connect( this, SIGNAL( customContextMenuRequested( const QPoint & ) ), + this, SLOT( slotContextMenuRequested( const QPoint & ) ) ); } void FolderSelectionTreeWidget::recursiveReload( KMFolderTreeItem *fti , FolderSelectionTreeWidgetItem *parent ) @@ -83,19 +81,20 @@ return; // top level - FolderSelectionTreeWidgetItem *item = parent ? new FolderSelectionTreeWidgetItem( parent ) : new FolderSelectionTreeWidgetItem( this ); + FolderSelectionTreeWidgetItem *item = parent ? new FolderSelectionTreeWidgetItem( parent ) + : new FolderSelectionTreeWidgetItem( this ); // Build the path (ParentItemPath/CurrentItemName) QString path; if( parent ) - path = parent->text( mPathColumnIndex ) + "/"; + path = parent->text( mPathColumnIndex ) + "/"; path += fti->text( 0 ); item->setText( mNameColumnIndex , fti->text( 0 ) ); item->setText( mPathColumnIndex , path ); - item->setProtocol( (KPIM::FolderTreeWidgetItem::Protocol)( fti->protocol() ) ); - item->setFolderType( (KPIM::FolderTreeWidgetItem::FolderType)( fti->type() ) ); - QPixmap pix = fti->normalIcon(KIconLoader::SizeSmall); + item->setProtocol( static_cast( fti->protocol() ) ); + item->setFolderType( static_cast( fti->type() ) ); + QPixmap pix = fti->normalIcon( KIconLoader::SizeSmall ); item->setIcon( mNameColumnIndex , pix.isNull() ? SmallIcon( "folder" ) : QIcon( pix ) ); item->setExpanded( true ); @@ -129,7 +128,7 @@ if ( selected.isEmpty() && folder() ) selected = folder()->idString(); - mFilter = ""; + mFilter = QString(); for ( KMFolderTreeItem * fti = static_cast( mFolderTree->firstChild() ) ; @@ -139,20 +138,21 @@ recursiveReload( fti , 0 ); if ( preSelection.isEmpty() ) - return; // nothing more to do + return; // nothing more to do QTreeWidgetItemIterator it( this ); while ( FolderSelectionTreeWidgetItem * fitem = static_cast( *it ) ) { - if ( fitem->folder() ) { - if ( fitem->folder()->idString() == preSelection ) { - // found - fitem->setSelected( true ); - scrollToItem( fitem ); - return; - } - } - ++it; + if ( fitem->folder() ) { + if ( fitem->folder()->idString() == preSelection ) { + // found + fitem->setSelected( true ); + scrollToItem( fitem ); + setCurrentItem( fitem ); + return; + } + } + ++it; } } @@ -200,7 +200,7 @@ { QTreeWidgetItem * lvi = itemAt( p ); - if (!lvi) + if ( !lvi ) return; setCurrentItem( lvi ); lvi->setSelected( true ); @@ -257,7 +257,7 @@ // Now search... QList lItems = findItems( mFilter , Qt::MatchContains | Qt::MatchRecursive , mPathColumnIndex ); - for( QList::Iterator it = lItems.begin(); it != lItems.end(); ++it) + for( QList::Iterator it = lItems.begin(); it != lItems.end(); ++it ) { ( *it )->setDisabled( false ); ( *it )->setHidden( false ); @@ -274,12 +274,13 @@ // Iterate through the list to find the first selectable item - QTreeWidgetItemIterator first ( this ); + QTreeWidgetItemIterator first( this ); while ( FolderSelectionTreeWidgetItem * item = static_cast< FolderSelectionTreeWidgetItem* >( *first ) ) { if ( ( !item->isHidden() ) && ( !item->isDisabled() ) && ( item->flags() & Qt::ItemIsSelectable ) ) { item->setSelected( true ); + setCurrentItem( item ); scrollToItem( item ); break; } @@ -303,7 +304,7 @@ QString s = e->text(); - switch(e->key()) + switch( e->key() ) { case Qt::Key_Backspace: if ( mFilter.length() > 0 ) @@ -317,12 +318,12 @@ return; break; default: - if ( !s.isEmpty() ) - { - mFilter += s; - applyFilter( mFilter ); - return; - } + int ch = s.isEmpty() ? 0 : s[0].toAscii(); + if ( !s.isEmpty() && ch >= 32 && ch <= 126 ) { + mFilter += s; + applyFilter( mFilter ); + return; + } break; } --- trunk/KDE/kdepim/kmail/folderselectiontreewidget.h #802875:802876 @@ -48,13 +48,13 @@ { Q_OBJECT private: - int mNameColumnIndex; //< The index of the folder name column - int mPathColumnIndex; //< The index of the path column - KMFolderTree* mFolderTree; //< The KMFolderTree to fetch the data from - QString mFilter; //< The current folder path filter string - bool mLastMustBeReadWrite; //< Internal state for reload() - bool mLastShowOutbox; //< Internal state for reload() - bool mLastShowImapFolders; //< Internal state for reload() + int mNameColumnIndex; ///< The index of the folder name column + int mPathColumnIndex; ///< The index of the path column + KMFolderTree* mFolderTree; ///< The KMFolderTree to fetch the data from + QString mFilter; ///< The current folder path filter string + bool mLastMustBeReadWrite; ///< Internal state for reload() + bool mLastShowOutbox; ///< Internal state for reload() + bool mLastShowImapFolders; ///< Internal state for reload() public: /** @@ -107,18 +107,18 @@ * Apply the given filter string. * Folders NOT matching the string are hidden and disabled (can't be selected). */ - void applyFilter( const QString& filter ); + void applyFilter( const QString &filter ); /** * Returns the folder name column logical index. */ - int nameColumnIndex() + int nameColumnIndex() const { return mNameColumnIndex; }; /** * Returns the folder path column logical index. */ - int pathColumnIndex() + int pathColumnIndex() const { return mPathColumnIndex; }; public slots: --- trunk/KDE/kdepim/kmail/kmmimeparttree.cpp #802875:802876 @@ -46,7 +46,6 @@ #include #include -#include #include @@ -55,17 +54,12 @@ : QTreeWidget( parent ), mReaderWin( readerWin ), mLayoutColumnsOnFirstShow( false ) { -#if 0 - /* FIXME: Remove this ifdefed code if nobody complains (2008.04.23) */ - setStyleDependantFrameWidth(); -#endif - // Setup the header QStringList headerNames; headerNames << i18n("Description") << i18n("Type") - << i18n("Encoding") << i18n("Size"); + << i18n("Encoding") << i18n("Size"); - QTreeWidgetItem * hitem = new QTreeWidgetItem( headerNames ); + QTreeWidgetItem * hitem = new QTreeWidgetItem( headerNames ); hitem->setTextAlignment( 3 , Qt::AlignRight ); setHeaderItem( hitem ); @@ -170,6 +164,7 @@ int cc = hitem->columnCount(); for ( int i = 1 ; i < cc; i++ ) { QAction * act = popup.addAction( hitem->text( i ) ); + act->setData( i ); act->setCheckable( true ); if ( !header()->isSectionHidden( i ) ) act->setChecked( true ); @@ -183,32 +178,21 @@ void KMMimePartTree::slotToggleColumn( QAction* a ) { + Q_ASSERT( a ); if ( !a ) return; // hm ? - // This is tricky: we actually trust translators to do the correct - // job and the user's language to have different words for each - // one of our column names :) - - QString columnName = a->text(); - QTreeWidgetItem * hitem = headerItem(); if ( !hitem ) return; // oops.. - int cc = hitem->columnCount(); - for ( int i = 1; i < cc; i++ ) { - if ( columnName == hitem->text( i ) ) { - // got the column to hide/show - if ( a->isChecked() ) - header()->showSection( i ); - else - header()->hideSection( i ); - return; - } - } - - // oops.. found no column to hide/show ? + int column = a->data().toInt(); + Q_ASSERT( column >= 0 && column < hitem->columnCount() ); + + if ( a->isChecked() ) + header()->showSection( column ); + else + header()->hideSection( column ); } void KMMimePartTree::slotContextMenuRequested( const QPoint& p ) @@ -222,12 +206,12 @@ KMenu popup; - popup.addAction( SmallIcon( "document-save-as" ),i18n( "Save &As..." ), + popup.addAction( SmallIcon( "document-save-as" ), i18n( "Save &As..." ), this, SLOT( slotSaveAs() ) ); if ( isAttachment ) { popup.addAction( SmallIcon( "document-open" ), i18nc( "to open", "Open" ), - this, SLOT( slotOpen() ) ); + this, SLOT( slotOpen() ) ); popup.addAction( i18n( "Open With..." ), this, SLOT( slotOpenWith() ) ); popup.addAction( i18nc( "to view something", "View" ), this, SLOT( slotView() ) ); } @@ -239,7 +223,7 @@ */ popup.addAction( i18n( "Save All Attachments..." ), this, - SLOT( slotSaveAll() ) ); + SLOT( slotSaveAll() ) ); // edit + delete only for attachments if ( isAttachment ) { @@ -303,40 +287,10 @@ command->start(); } -#if 0 - /* FIXME: Remove this ifdefed code if nobody complains (2008.04.23) */ - //----------------------------------------------------------------------------- -void KMMimePartTree::setStyleDependantFrameWidth() -{ - // FIXME: This seems to be hack...Is it still needed with Qt4/KDE4 ? - - // set the width of the frame to a reasonable value for the current GUI style - int frameWidth; -#if 0 // is this hack still needed with kde4? - if ( !qstrcmp( style()->metaObject()->className(), "KeramikStyle" ) ) - frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth ) - 1; - else -#endif - frameWidth = style()->pixelMetric( QStyle::PM_DefaultFrameWidth ); - if ( frameWidth < 0 ) - frameWidth = 0; - if ( frameWidth != lineWidth() ) - setLineWidth( frameWidth ); -} - -//----------------------------------------------------------------------------- -void KMMimePartTree::styleChange( QStyle& oldStyle ) -{ - setStyleDependantFrameWidth(); - QTreeWidget::styleChange( oldStyle ); -} -#endif - -//----------------------------------------------------------------------------- void KMMimePartTree::correctSize( QTreeWidgetItem * item ) { - if (!item) + if ( !item ) return; // Gather size for all the children @@ -351,7 +305,7 @@ } if ( totalSize > static_cast(item)->origSize() ) - item->setText( 3 , KIO::convertSize(totalSize) ); + item->setText( 3 , KIO::convertSize( totalSize ) ); if ( item->parent() ) correctSize( item->parent() ); @@ -445,7 +399,7 @@ : QTreeWidgetItem( parent ), mPartNode( node ), mOrigSize( size ) { - Q_ASSERT(parent); + Q_ASSERT( parent ); if ( node ) node->setMimePartTreeItem( this ); setText( 0 , description ); --- trunk/KDE/kdepim/kmail/kmmimeparttree.h #802875:802876 @@ -60,6 +60,7 @@ virtual ~KMMimePartTree(); public: + /** * Corrects the size displayed by the specified item * by accounting for its current children. @@ -85,21 +86,10 @@ void slotCopy(); protected: -#if 0 - /* FIXME: Remove this ifdefed code if nobody complains (2008.04.23) */ - /** reimplemented in order to update the frame width in case of a changed - GUI style FIXME: Still needed with Qt4 ? */ - virtual void styleChange( QStyle& oldStyle ); -#endif + virtual void startDrag( Qt::DropActions actions ); virtual void showEvent( QShowEvent* e ); -#if 0 - /* FIXME: Remove this ifdefed code if nobody complains (2008.04.23) */ - /** Set the width of the frame to a reasonable value for the current GUI - style */ - void setStyleDependantFrameWidth(); -#endif void restoreLayoutIfPresent(); void startHandleAttachmentCommand( int action ); void saveSelectedBodyParts( bool encoded ); @@ -140,10 +130,12 @@ * @returns a pointer to the partNode this item is displaying. */ partNode* node() const { return mPartNode; } + /** * @returns the initial size of the tree node data. */ KIO::filesize_t origSize() const { return mOrigSize; } + /** * Sets the initial size of the tree node data. */