@ -17,29 +17,52 @@
*/
# include "folderselectiontreeviewdialog.h"
# include <QVBoxLayout>
# include "folderselectiontreeview.h"
# include <akonadi/collection.h>
# include <akonadi/entitytreemodel.h>
# include <KLocale>
FolderSelectionTreeViewDialog : : FolderSelectionTreeViewDialog ( QWidget * parent )
: KDialog ( parent )
{
setButtons ( Ok | Cancel | User1 ) ;
setObjectName ( " folder dialog " ) ;
setButtonGuiItem ( User1 , KGuiItem ( i18n ( " &New Subfolder... " ) , " folder-new " ,
i18n ( " Create a new subfolder under the currently selected folder " ) ) ) ;
QWidget * widget = mainWidget ( ) ;
QVBoxLayout * layout = new QVBoxLayout ( widget ) ;
treeview = new FolderSelectionTreeView ( this ) ;
layout - > addWidget ( treeview ) ;
enableButton ( KDialog : : Ok , false ) ;
enableButton ( KDialog : : User1 , false ) ;
connect ( treeview - > selectionModel ( ) , SIGNAL ( selectionChanged ( QItemSelection , QItemSelection ) ) , this , SLOT ( slotSelectionChanged ( ) ) ) ;
connect ( this , SIGNAL ( user1Clicked ( ) ) , this , SLOT ( slotAddChildFolder ( ) ) ) ;
readConfig ( ) ;
}
FolderSelectionTreeViewDialog : : ~ FolderSelectionTreeViewDialog ( )
{
writeConfig ( ) ;
}
void FolderSelectionTreeViewDialog : : slotAddChildFolder ( )
{
//TODO implement it.
}
void FolderSelectionTreeViewDialog : : slotSelectionChanged ( )
{
enableButton ( KDialog : : Ok , treeview - > selectionModel ( ) - > selectedIndexes ( ) . count ( ) > 0 ) ;
const bool enablebuttons = ( treeview - > selectionModel ( ) - > selectedIndexes ( ) . count ( ) > 0 ) ;
enableButton ( KDialog : : Ok , enablebuttons ) ;
enableButton ( KDialog : : User1 , enablebuttons ) ;
}
void FolderSelectionTreeViewDialog : : setSelectionMode ( QAbstractItemView : : SelectionMode mode )
@ -55,29 +78,33 @@ QAbstractItemView::SelectionMode FolderSelectionTreeViewDialog::selectionMode()
Akonadi : : Collection FolderSelectionTreeViewDialog : : selectedCollection ( ) const
{
if ( treeview - > selectionMode ( ) = = QAbstractItemView : : SingleSelection ) {
const QModelIndex index = treeview - > currentIndex ( ) ;
if ( index . isValid ( ) )
return index . model ( ) - > data ( index , Akonadi : : EntityTreeModel : : CollectionRole ) . value < Akonadi : : Collection > ( ) ;
}
return Akonadi : : Collection ( ) ;
return treeview - > selectedCollection ( ) ;
}
Akonadi : : Collection : : List FolderSelectionTreeViewDialog : : selectedCollections ( ) const
{
Akonadi : : Collection : : List collections ;
const QItemSelectionModel * selectionModel = treeview - > selectionModel ( ) ;
const QModelIndexList selectedIndexes = selectionModel - > selectedIndexes ( ) ;
foreach ( const QModelIndex & index , selectedIndexes ) {
if ( index . isValid ( ) ) {
const Akonadi : : Collection collection = index . model ( ) - > data ( index , Akonadi : : EntityTreeModel : : CollectionRole ) . value < Akonadi : : Collection > ( ) ;
if ( collection . isValid ( ) )
collections . append ( collection ) ;
}
}
return collections ;
return treeview - > selectedCollections ( ) ;
}
static const char * myConfigGroupName = " FolderSelectionDialog " ;
void FolderSelectionTreeViewDialog : : readConfig ( )
{
KSharedConfigPtr config = KGlobal : : config ( ) ;
KConfigGroup group ( config , myConfigGroupName ) ;
QSize size = group . readEntry ( " Size " , QSize ( ) ) ;
if ( ! size . isEmpty ( ) )
resize ( size ) ;
else
resize ( 500 , 300 ) ;
}
void FolderSelectionTreeViewDialog : : writeConfig ( )
{
KSharedConfig : : Ptr config = KGlobal : : config ( ) ;
KConfigGroup group ( config , myConfigGroupName ) ;
group . writeEntry ( " Size " , size ( ) ) ;
}
# include "folderselectiontreeviewdialog.moc"