svn path=/branches/work/akonadi-ports/kdepim/; revision=1033298
wilder-work
Laurent Montel 17 years ago
parent 1e84f37f8e
commit fbf0ee0f4d
  1. 3
      antispamwizard.cpp
  2. 458
      folderselectiontreewidget.cpp
  3. 187
      folderselectiontreewidget.h
  4. 4
      kmmainwidget.cpp

@ -35,9 +35,6 @@
#include "kmfilteraction.h"
#include "kmfiltermgr.h"
#include "kmkernel.h"
#ifdef OLD_FOLDERVIEW
#include "folderselectiontreewidget.h"
#endif
#include "kmmainwin.h"
#include "networkaccount.h"
#include "folderrequester.h"

@ -1,458 +0,0 @@
/******************************************************************************
*
* KMail Folder Selection Tree Widget
*
* Copyright (c) 1997-1998 Stefan Taferner <taferner@kde.org>
* Copyright (c) 2004-2005 Carsten Burghardt <burghardt@kde.org>
* Copyright (c) 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*****************************************************************************/
#include "folderselectiontreewidget.h"
#include "kmfolder.h"
#include "kmfoldermgr.h"
#include "util.h"
#include <kaction.h>
#include <kmenu.h>
#include <kiconloader.h>
#include <kconfiggroup.h>
#include <QKeyEvent>
using namespace KMail::Util;
namespace KMail {
class FolderSelectionTreeWidgetItem : public KPIM::FolderTreeWidgetItem
{
public:
FolderSelectionTreeWidgetItem(
KPIM::FolderTreeWidget * listView,
const FolderViewItem * srcItem
)
: KPIM::FolderTreeWidgetItem(
listView, srcItem->labelText(),
srcItem->protocol(), srcItem->folderType()
), mFolder( 0 ) {};
FolderSelectionTreeWidgetItem(
KPIM::FolderTreeWidgetItem * listViewItem,
const FolderViewItem * srcItem
)
: KPIM::FolderTreeWidgetItem(
listViewItem, srcItem->labelText(),
srcItem->protocol(), srcItem->folderType()
), mFolder( 0 ) {};
public:
void setFolder( KMFolder * folder )
{ mFolder = folder; };
KMFolder * folder() const
{ return mFolder; };
bool isReadOnly() const
{
return folder() && folder()->isReadOnly();
}
bool noContent() const
{
return folder() && folder()->noContent();
}
private:
KMFolder * mFolder;
};
FolderSelectionTreeWidget::FolderSelectionTreeWidget( QWidget * parent
#ifdef OLD_FOLDERVIEW
, ::KMail::MainFolderView * folderTree
#endif
)
: KPIM::FolderTreeWidget( parent )
#ifdef OLD_FOLDERVIEW
, mFolderTree( folderTree )
#endif
{
setSelectionMode( QTreeWidget::SingleSelection );
mNameColumnIndex = addColumn( i18n( "Folder" ) );
mPathColumnIndex = addColumn( i18n( "Path" ) );
setContextMenuPolicy( Qt::CustomContextMenu );
connect( this, SIGNAL( customContextMenuRequested( const QPoint & ) ),
this, SLOT( slotContextMenuRequested( const QPoint & ) ) );
connect( this, SIGNAL( itemSelectionChanged() ),
this, SLOT( slotItemSelectionChanged() ) );
mCreateFolderAction = new KAction( KIcon( "folder-new" ),
i18n("&New Subfolder..."), this );
connect( mCreateFolderAction, SIGNAL( triggered() ),
this, SLOT( addChildFolder() ) );
}
bool FolderSelectionTreeWidget::itemSelectable( const FolderSelectionTreeWidgetItem *item ) const
{
return !( ( mLastMustBeReadWrite && item->isReadOnly() ) ||
( item->noContent() ) );
}
void FolderSelectionTreeWidget::recursiveReload( FolderViewItem *fti, FolderSelectionTreeWidgetItem *parent )
{
// hidden folders are not shown (that is a surprise, right?)
if ( fti->folder() && fti->folder()->hideInSelectionDialog() )
return;
// search folders are only shown when they are read-only
if ( fti->protocol() == KPIM::FolderTreeWidgetItem::Search && mLastMustBeReadWrite )
return;
// imap folders?
if ( fti->protocol() == KPIM::FolderTreeWidgetItem::Imap && !mLastShowImapFolders )
return;
// the outbox?
if ( fti->folderType() == KPIM::FolderTreeWidgetItem::Outbox && !mLastShowOutbox )
return;
// top level
FolderSelectionTreeWidgetItem *item = parent ? new FolderSelectionTreeWidgetItem( parent, fti )
: new FolderSelectionTreeWidgetItem( this, fti );
item->setText( mNameColumnIndex, fti->labelText() );
item->setIcon( 0, fti->icon( 0 ) );
// Build the path (ParentItemPath/CurrentItemName)
QString path;
if( parent )
path = parent->text( mPathColumnIndex ) + '/';
path += fti->labelText();
item->setText( mPathColumnIndex, path );
// Make readonly and nocoontent items unselectable, if we're told so
if ( !itemSelectable( item ) ) {
item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
} else {
item->setFolder( fti->folder() );
}
int cc = fti->childCount();
int i = 0;
#ifdef OLD_FOLDERVIEW
while ( i < cc )
{
FolderViewItem *child = dynamic_cast<FolderViewItem *>( ( ( QTreeWidgetItem * )fti)->child( i ) );
if ( child )
recursiveReload( child, item );
i++;
}
#endif
}
void FolderSelectionTreeWidget::reload( bool mustBeReadWrite, bool showOutbox,
bool showImapFolders, const QString& preSelection )
{
mLastMustBeReadWrite = mustBeReadWrite;
mLastShowOutbox = showOutbox;
mLastShowImapFolders = showImapFolders;
clear();
QString selected = preSelection;
if ( selected.isEmpty() && folder() )
selected = folder()->idString();
mFilter.clear();
#ifdef OLD_FOLDERVIEW
int cc = mFolderTree->topLevelItemCount();
#else
int cc = 0;
#endif
int i = 0;
// Calling setUpdatesEnabled() here causes weird effects (including crashes)
// in the folder requester (used by the filtering dialog).
// So disable it for now, this makes the folderselection dialog appear much
// slower though :(
//setUpdatesEnabled( false );
#ifdef OLD_FOLDERVIEW
while ( i < cc )
{
FolderViewItem *child = dynamic_cast<FolderViewItem *>( mFolderTree->topLevelItem( i ) );
if ( child )
recursiveReload( child, 0 );
i++;
}
#endif
// we do this here in one go after all items have been created, as that is
// faster than expanding each item, which triggers a lot of updates
expandAll();
if ( !preSelection.isEmpty() )
setFolder( preSelection );
}
KMFolder * FolderSelectionTreeWidget::folder() const
{
QTreeWidgetItem * item = currentItem();
if ( item ) {
if ( item->flags() & Qt::ItemIsSelectable )
return static_cast<FolderSelectionTreeWidgetItem *>( item )->folder();
}
return 0;
}
void FolderSelectionTreeWidget::setFolder( KMFolder *folder )
{
for ( QTreeWidgetItemIterator it( this ) ; *it ; ++it )
{
const KMFolder *fld = static_cast<FolderSelectionTreeWidgetItem *>( *it )->folder();
if ( fld == folder )
{
( *it )->setSelected( true );
scrollToItem( *it );
setCurrentItem( *it );
return;
}
}
}
void FolderSelectionTreeWidget::setFolder( const QString& idString )
{
setFolder( kmkernel->findFolderById( idString ) );
}
void FolderSelectionTreeWidget::addChildFolder()
{
reconnectSignalSlotPair( kmkernel->folderMgr(), SIGNAL( folderAdded(KMFolder*) ),
this, SLOT( slotFolderAdded(KMFolder*) ) );
reconnectSignalSlotPair( kmkernel->imapFolderMgr(), SIGNAL( folderAdded(KMFolder*) ),
this, SLOT( slotFolderAdded(KMFolder*) ) );
reconnectSignalSlotPair( kmkernel->dimapFolderMgr(), SIGNAL( folderAdded(KMFolder*) ),
this, SLOT( slotFolderAdded(KMFolder*) ) );
#ifdef OLD_FOLDERVIEW
mFolderTree->addChildFolder( folder(), parentWidget() );
#endif
}
void FolderSelectionTreeWidget::slotContextMenuRequested( const QPoint &p )
{
QTreeWidgetItem * lvi = itemAt( p );
if ( !lvi )
return;
setCurrentItem( lvi );
lvi->setSelected( true );
KMenu *folderMenu = new KMenu;
folderMenu->addTitle( static_cast<FolderSelectionTreeWidgetItem *>( lvi )->labelText() );
folderMenu->addAction( mCreateFolderAction );
kmkernel->setContextMenuShown( true );
folderMenu->exec ( viewport()->mapToGlobal( p ), 0);
kmkernel->setContextMenuShown( false );
delete folderMenu;
folderMenu = 0;
}
void FolderSelectionTreeWidget::slotFolderAdded( KMFolder *addedFolder )
{
reload( mLastMustBeReadWrite, mLastShowOutbox, mLastShowImapFolders );
setFolder( addedFolder );
disconnect( kmkernel->folderMgr(), SIGNAL( folderAdded(KMFolder*) ),
this, SLOT( slotFolderAdded(KMFolder*) ) );
disconnect( kmkernel->imapFolderMgr(), SIGNAL( folderAdded(KMFolder*) ),
this, SLOT( slotFolderAdded(KMFolder*) ) );
disconnect( kmkernel->dimapFolderMgr(), SIGNAL( folderAdded(KMFolder*) ),
this, SLOT( slotFolderAdded(KMFolder*) ) );
}
void FolderSelectionTreeWidget::slotItemSelectionChanged()
{
bool allowOk = true;
bool allowCreate = true;
const QList<QTreeWidgetItem *> selItems = selectedItems();
if ( selItems.isEmpty() ) // no selection
allowOk = allowCreate = false;
else
{
const KMFolder *fld = static_cast<FolderSelectionTreeWidgetItem *>( selectedItems().first() )->folder();
if ( !fld ) // "Local Folders" root
allowOk = !mLastMustBeReadWrite;
else // any other folder
{
allowCreate = !fld->noChildren() && !fld->isReadOnly();
if ( mLastMustBeReadWrite )
allowOk = !fld->noContent() && !fld->isReadOnly();
}
}
mCreateFolderAction->setEnabled( allowCreate );
emit actionsAllowed( allowOk, allowCreate );
}
void FolderSelectionTreeWidget::applyFilter( const QString& filter )
{
// We would like to set items that do not match the filter to disabled,
// but that also disables all the children of that item (qt bug 181410,
// closed as WONTFIX).
// So instead, we mark the items as not selectable. That unfortunalty does not
// give us visual feedback, though.
// In keyPressEvent(), we change the behavior of the up/down arrow to skip
// non-selectable items.
if ( filter.isEmpty() )
{
// Empty filter:
// reset all items to enabled, visible, expanded and not selected
QTreeWidgetItemIterator clean( this );
while ( QTreeWidgetItem *item = *clean )
{
item->setHidden( false );
item->setSelected( false );
if ( itemSelectable( static_cast< FolderSelectionTreeWidgetItem* >( item ) ) )
item->setFlags( item->flags() | Qt::ItemIsSelectable );
else
item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
++clean;
}
setColumnText( mPathColumnIndex, i18n("Path") );
return;
}
// Not empty filter.
// Reset all items to disabled, hidden, closed and not selected
QTreeWidgetItemIterator clean( this );
while ( QTreeWidgetItem *item = *clean )
{
item->setHidden( true );
item->setSelected( false );
item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
++clean;
}
// Now search...
QList<QTreeWidgetItem *> lItems = findItems( mFilter, Qt::MatchContains | Qt::MatchRecursive, mPathColumnIndex );
foreach( QTreeWidgetItem *item, lItems )
{
if ( !itemSelectable( static_cast<FolderSelectionTreeWidgetItem*>( item ) ) )
continue;
item->setFlags( item->flags() | Qt::ItemIsSelectable );
item->setHidden( false );
// Open all the parents up to this item
QTreeWidgetItem * p = item->parent();
while( p )
{
p->setHidden( false );
p = p->parent();
}
}
// Iterate through the list to find the first selectable item
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;
}
++first;
}
// Display and save the current filter
if ( filter.length() > 0 )
setColumnText( mPathColumnIndex, i18n("Path") + " ( " + filter + " )" );
else
setColumnText( mPathColumnIndex, i18n("Path") );
}
void FolderSelectionTreeWidget::keyPressEvent( QKeyEvent *e )
{
// Handle keyboard filtering.
// Each key with text is appended to our search filter (which gets displayed
// in the header for the Path column). Backpace removes text from the filter
// while the del button clears the filter completely.
switch( e->key() )
{
case Qt::Key_Backspace:
if ( mFilter.length() > 0 )
mFilter.truncate( mFilter.length()-1 );
applyFilter( mFilter );
return;
break;
case Qt::Key_Delete:
mFilter = "";
applyFilter( mFilter);
return;
break;
// Reimplement up/down arrow handling to skip non-selectable items
case Qt::Key_Up:
{
QTreeWidgetItem *newCurrent = currentItem();
do {
newCurrent = itemAbove( newCurrent );
} while ( newCurrent && !( newCurrent->flags() & Qt::ItemIsSelectable ) );
if ( newCurrent )
setCurrentItem( newCurrent );
return;
}
break;
case Qt::Key_Down:
{
QTreeWidgetItem *newCurrent = currentItem();
do {
newCurrent = itemBelow( newCurrent );
} while ( newCurrent && !( newCurrent->flags() & Qt::ItemIsSelectable ) );
if ( newCurrent )
setCurrentItem( newCurrent );
return;
}
break;
default:
{
QString s = e->text();
if ( !s.isEmpty() && s.at( 0 ).isPrint() ) {
mFilter += s;
applyFilter( mFilter );
return;
}
}
break;
}
KPIM::FolderTreeWidget::keyPressEvent( e );
}
} // namespace KMail
#include "folderselectiontreewidget.moc"

@ -1,187 +0,0 @@
#ifndef __FOLDERSELECTIONTREEWIDGET_H__
#define __FOLDERSELECTIONTREEWIDGET_H__
/******************************************************************************
*
* KMail Folder Selection Tree Widget
*
* Copyright (c) 1997-1998 Stefan Taferner <taferner@kde.org>
* Copyright (c) 2004-2005 Carsten Burghardt <burghardt@kde.org>
* Copyright (c) 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*****************************************************************************/
#include <libkdepim/foldertreewidget.h>
class KMFolder;
class KAction;
namespace KMail {
class FolderViewItem;
class FolderSelectionTreeWidgetItem;
/**
* @brief A simple tree of folders useful for a "quick selection"
*
* This widget displays a two column tree of folders with the folder
* name on the left and its full path on the right. The tree is filled
* by fetching data from a FolderTreeWiget.
*
* Items can be filtered by typing in a string to be matched in the
* folder path.
*/
class FolderSelectionTreeWidget : public KPIM::FolderTreeWidget
{
Q_OBJECT
public:
/**
* Construct the simple folder tree.
* Note that the widget is initially empty and you must call reload()
* to fill it up.
*
* @param parent The parent widget
* @param folderTree The folder tree to fetch the hierarchy of folders from
*/
FolderSelectionTreeWidget(
QWidget *parent,
::KMail::MainFolderView *folderTree
);
public:
/**
* Reload the tree and select which folders to show and which not
*
* @param mustBeReadWrite If true, the read-only folders become non selectable
* @param showOutbox If trye, the otbox folder is shown
* @param showImapFolders Whether to show the IMAP folder hierarchy
* @param preSelection The initial folder to select
*/
void reload(
bool mustBeReadWrite,
bool showOutbox,
bool showImapFolders,
const QString &preSelection = QString()
);
/**
* Return the currently selected folder, or 0 if no folder is selected (yet)
*/
KMFolder * folder() const;
/**
* Set the current folder.
* The folder parameter must come from the KMFolderTree specified in the
* constructor.
*/
void setFolder( KMFolder *folder );
/**
* Set the current folder.
* This is an overload that first lookups the folder by id in kmkernel.
*/
void setFolder( const QString &idString );
/**
* Apply the given filter string.
* Folders NOT matching the string are hidden and disabled (can't be selected).
*/
void applyFilter( const QString &filter );
/**
* Returns the folder name column logical index.
*/
int nameColumnIndex() const
{ return mNameColumnIndex; };
/**
* Returns the folder path column logical index.
*/
int pathColumnIndex() const
{ return mPathColumnIndex; };
public slots:
/**
* Invokes the child folder creation dialog on the currently selected
* folder in the widget. Nothing happens if there is no current folder.
*/
void addChildFolder();
protected slots:
/**
* Pops up a contextual menu for the currently selected folder.
* At the moment of writing the menu allows to invoke the addChildFolder()
* method.
*/
void slotContextMenuRequested( const QPoint & );
/**
* Selects the folder that was added. Connected to the folderAdded signal
* when creating a new subfolder.
*/
void slotFolderAdded( KMFolder *addedFolder );
/**
* Called when the selection changes.
* See documentation for QTreeWidget::itemSelectionChanged()
*/
void slotItemSelectionChanged();
protected:
/**
* Handles key presses for the purpose of filtering.
*/
virtual void keyPressEvent( QKeyEvent *e );
/**
* Recursively fetches folder items from the FolderTreeWiget
* by starting at fti (as root). This is internal api: use reload() instead.
*/
void recursiveReload( FolderViewItem *fti, FolderSelectionTreeWidgetItem *parent );
/**
* Returns false if the item is read-only and we need write access or has no content.
*/
bool itemSelectable( const FolderSelectionTreeWidgetItem *item ) const;
signals:
/**
* Emitted when the tree widget selection changes, to inform the parent dialogue
* of the actions that are allowed for the selected folder.
*
* @param allowOk if true, the OK action (accepting the selected folder) is allowed.
* @param allowCreate if true, the "New Subfolder" action is allowed.
*/
void actionsAllowed( bool allowOk, bool allowCreate );
private:
int mNameColumnIndex; ///< The index of the folder name column
int mPathColumnIndex; ///< The index of the path column
#ifdef OLD_FOLDERVIEW
KMail::MainFolderView* mFolderTree; ///< The MainFolderView to fetch the data from
#endif
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()
KAction *mCreateFolderAction; ///< "New Subfolder" action for popup menu
};
} // namespace KMail
#endif /*!__FOLDERSELECTIONTREEWIDGET_H__*/

@ -2540,7 +2540,9 @@ void KMMainWidget::slotJumpToFolder()
dlg->setCaption( i18n( "Jump to Folder") );
if ( dlg->exec() && dlg ) {
Akonadi::Collection collection = dlg->selectedCollection();
//TODO fix me
if ( collection.isValid() ) {
kDebug()<<" collection.name() :"<<collection.name();
}
//mCollectionFolderView->setCurrentIndex( mEntityModel->indexForCollection( collection ) );
}
}

Loading…
Cancel
Save