Allow a new top-level local folder to be created in the folder selection

dialogue (used, e.g, when configuring a filter rule with the "Move into Folder"
action).

Also make it obvious where the selected folder is not valid, by disabling
the "OK" button.

BUG:128796

svn path=/trunk/KDE/kdepim/; revision=927934
wilder-work
Jonathan Marten 17 years ago
parent d235d3c401
commit d4115f52ec
  1. 10
      folderselectiondialog.cpp
  2. 2
      folderselectiondialog.h
  3. 67
      folderselectiontreewidget.cpp
  4. 35
      folderselectiontreewidget.h

@ -71,8 +71,8 @@ void FolderSelectionDialog::init( MainFolderView *tree, bool mustBeReadWrite )
mTreeView->setFocus();
connect( mTreeView, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ),
this, SLOT( slotSelect() ) );
connect( mTreeView, SIGNAL( itemSelectionChanged() ),
this, SLOT( slotUpdateBtnStatus() ) );
connect( mTreeView, SIGNAL( actionsAllowed( bool, bool ) ),
this, SLOT( slotUpdateBtnStatus( bool, bool ) ) );
connect(this, SIGNAL( user1Clicked() ), mTreeView, SLOT( addChildFolder() ) );
readConfig();
mTreeView->resizeColumnToContents(0);
@ -106,10 +106,10 @@ void FolderSelectionDialog::slotSelect()
accept();
}
void FolderSelectionDialog::slotUpdateBtnStatus()
void FolderSelectionDialog::slotUpdateBtnStatus( bool allowOk, bool allowCreate )
{
enableButton( User1, folder() &&
( !folder()->noContent() && !folder()->noChildren() ) );
enableButton( Ok, allowOk );
enableButton( User1, allowCreate );
}
void FolderSelectionDialog::setFlags( bool mustBeReadWrite, bool showOutbox,

@ -101,7 +101,7 @@ protected slots:
* Called when selection in the tree view changes in order
* to update the enabled/disabled state of the dialog buttons.
*/
void slotUpdateBtnStatus();
void slotUpdateBtnStatus( bool allowOk, bool allowCreate );
protected:
/**

@ -27,6 +27,7 @@
#include "kmfoldermgr.h"
#include "util.h"
#include <kaction.h>
#include <kmenu.h>
#include <kiconloader.h>
#include <kconfiggroup.h>
@ -82,6 +83,13 @@ FolderSelectionTreeWidget::FolderSelectionTreeWidget( QWidget * parent, ::KMail:
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() ) );
}
void FolderSelectionTreeWidget::recursiveReload( FolderViewItem *fti, FolderSelectionTreeWidgetItem *parent )
@ -113,9 +121,8 @@ void FolderSelectionTreeWidget::recursiveReload( FolderViewItem *fti, FolderSele
QPixmap pix = fti->normalIcon();
item->setIcon( mNameColumnIndex, pix.isNull() ? SmallIcon( "folder" ) : QIcon( pix ) );
// Make items without folders and readonly items unselectable
// if we're told so
if ( mLastMustBeReadWrite && ( !fti->folder() || fti->folder()->isReadOnly() ) ) {
// Make readonly items unselectable, if we're told so
if ( mLastMustBeReadWrite && ( fti->folder() && fti->folder()->isReadOnly() ) ) {
item->setFlags( item->flags() & ~Qt::ItemIsSelectable );
} else {
item->setFolder( fti->folder() );
@ -206,16 +213,13 @@ void FolderSelectionTreeWidget::setFolder( const QString& idString )
void FolderSelectionTreeWidget::addChildFolder()
{
const KMFolder *fld = folder();
if ( fld ) {
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*) ) );
mFolderTree->addChildFolder( (KMFolder *) fld, parentWidget() );
}
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*) ) );
mFolderTree->addChildFolder( folder(), parentWidget() );
}
void FolderSelectionTreeWidget::slotContextMenuRequested( const QPoint &p )
@ -227,16 +231,10 @@ void FolderSelectionTreeWidget::slotContextMenuRequested( const QPoint &p )
setCurrentItem( lvi );
lvi->setSelected( true );
const KMFolder * folder = static_cast<FolderSelectionTreeWidgetItem *>( lvi )->folder();
if ( !folder || folder->noContent() || folder->noChildren() )
return;
KMenu *folderMenu = new KMenu;
folderMenu->addTitle( folder->label() );
folderMenu->addSeparator();
folderMenu->addAction( KIcon("folder-new"),
i18n("&New Subfolder..."), this,
SLOT(addChildFolder()) );
folderMenu->addTitle( static_cast<FolderSelectionTreeWidgetItem *>( lvi )->labelText() );
folderMenu->addAction( mCreateFolderAction );
kmkernel->setContextMenuShown( true );
folderMenu->exec ( viewport()->mapToGlobal( p ), 0);
kmkernel->setContextMenuShown( false );
@ -256,6 +254,31 @@ void FolderSelectionTreeWidget::slotFolderAdded( KMFolder *addedFolder )
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,

@ -27,6 +27,7 @@
#include <libkdepim/foldertreewidget.h>
class KMFolder;
class KAction;
namespace KMail {
@ -47,14 +48,6 @@ class FolderSelectionTreeWidgetItem;
class FolderSelectionTreeWidget : public KPIM::FolderTreeWidget
{
Q_OBJECT
private:
int mNameColumnIndex; ///< The index of the folder name column
int mPathColumnIndex; ///< The index of the path column
KMail::MainFolderView* mFolderTree; ///< The MainFolderView 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:
/**
@ -142,6 +135,11 @@ protected slots:
*/
void slotFolderAdded( KMFolder *addedFolder );
/**
* Called when the selection changes.
* See documentation for QTreeWidget::itemSelectionChanged()
*/
void slotItemSelectionChanged();
protected:
/**
@ -155,6 +153,27 @@ protected:
*/
void recursiveReload( FolderViewItem *fti, FolderSelectionTreeWidgetItem *parent );
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
KMail::MainFolderView* mFolderTree; ///< The MainFolderView 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()
KAction *mCreateFolderAction; ///< "New Subfolder" action for popup menu
};
} // namespace KMail

Loading…
Cancel
Save