[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepimlibs/akonadi
From: Tobias Koenig <tokoe () kde ! org>
Date: 2010-12-22 13:08:30
Message-ID: 20101222130830.219E3AC8AA () svn ! kde ! org
[Download RAW message or body]
SVN commit 1208592 by tokoe:
Port the Akonadi::CollectionDialog to QML for the MOBILE_UI profile.
M +5 -0 CMakeLists.txt
A CollectionDialogMobile.qml [License: UNKNOWN]
M +161 -59 collectiondialog_mobile.cpp
A collectiondialog_mobile.qrc
A collectiondialog_mobile_p.h [License: UNKNOWN]
--- trunk/KDE/kdepimlibs/akonadi/CMakeLists.txt #1208591:1208592
@@ -233,6 +233,7 @@
kde4_add_ui_files( akonadikde_LIB_SRC
collectiongeneralpropertiespage_mobile.ui
)
+ qt4_add_resources( akonadikde_LIB_SRC collectiondialog_mobile.qrc )
else(KDEPIM_MOBILE_UI)
kde4_add_ui_files( akonadikde_LIB_SRC
collectiongeneralpropertiespage.ui
@@ -246,6 +247,10 @@
target_link_libraries( akonadi-kde ${QT_QTNETWORK_LIBRARY} ${QT_QTDBUS_LIBRARY} \
${QT_QTSQL_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${KDE4_SOLID_LIBS} \
${AKONADI_COMMON_LIBRARIES} ) set( AKONADI_KDE_DEPS ${KDE4_KDEUI_LIBS} \
${QT_QTDBUS_LIBRARY} ${QT_QTCORE_LIBRARY} )
+if (KDEPIM_MOBILE_UI)
+target_link_libraries( akonadi-kde ${QT_QTDECLARATIVE_LIBRARY} )
+endif(KDEPIM_MOBILE_UI)
+
if(KDE_IS_AT_LEAST_42)
target_link_libraries( akonadi-kde LINK_INTERFACE_LIBRARIES ${AKONADI_KDE_DEPS})
else(KDE_IS_AT_LEAST_42)
--- trunk/KDE/kdepimlibs/akonadi/collectiondialog_mobile.cpp #1208591:1208592
@@ -18,97 +18,131 @@
*/
#include "collectiondialog.h"
+#include "collectiondialog_mobile_p.h"
-#include <akonadi/collectioncombobox.h>
+#include "asyncselectionhandler_p.h"
+#include "kdescendantsproxymodel_p.h"
+
+#include <akonadi/changerecorder.h>
#include <akonadi/collectioncreatejob.h>
+#include <akonadi/collectionfilterproxymodel.h>
#include <akonadi/collectionutils_p.h>
+#include <akonadi/entityrightsfiltermodel.h>
+#include <akonadi/entitytreemodel.h>
-#include <QtGui/QLabel>
-#include <QtGui/QVBoxLayout>
-
#include <KLocale>
#include <KInputDialog>
#include <KMessageBox>
+#include <KStandardDirs>
+#include <QtDeclarative/QDeclarativeContext>
+#include <QtDeclarative/QDeclarativeEngine>
+#include <QtDeclarative/QDeclarativeView>
+
using namespace Akonadi;
-class CollectionDialog::Private
+CollectionDialog::Private::Private( QAbstractItemModel *customModel, \
CollectionDialog *parent, CollectionDialogOptions options ) + : QObject( parent ),
+ mParent( parent ),
+ mSelectionMode( QAbstractItemView::SingleSelection ),
+ mOkButtonEnabled( false ),
+ mCancelButtonEnabled( true ),
+ mCreateButtonEnabled( false )
{
- public:
- Private( QAbstractItemModel *customModel, CollectionDialog *parent, \
CollectionDialogOptions options )
- : mParent( parent ),
- mSelectionMode( QAbstractItemView::SingleSelection )
- {
// setup GUI
- QWidget *widget = mParent->mainWidget();
- QVBoxLayout *layout = new QVBoxLayout( widget );
+ mView = new QDeclarativeView( mParent );
+ mParent->setMainWidget( mView );
+ mParent->setButtons( KDialog::None );
+
changeCollectionDialogOptions( options );
- mTextLabel = new QLabel;
- layout->addWidget( mTextLabel );
- mTextLabel->hide();
+ QAbstractItemModel *baseModel;
- mCollectionComboBox = new CollectionComboBox( customModel, widget );
- layout->addWidget( mCollectionComboBox );
- mParent->connect( mCollectionComboBox, SIGNAL( currentIndexChanged( int ) ), \
SLOT( slotSelectionChanged() ) ); + if ( customModel ) {
+ baseModel = customModel;
+ } else {
+ mMonitor = new Akonadi::ChangeRecorder( mParent );
+ mMonitor->fetchCollection( true );
+ mMonitor->setCollectionMonitored( Akonadi::Collection::root() );
- mParent->enableButton( KDialog::Ok, false );
+ mModel = new EntityTreeModel( mMonitor, mParent );
+ mModel->setItemPopulationStrategy( EntityTreeModel::NoItemPopulation );
+
+ baseModel = mModel;
}
- ~Private()
+ KDescendantsProxyModel *proxyModel = new KDescendantsProxyModel( parent );
+ proxyModel->setDisplayAncestorData( true );
+ proxyModel->setSourceModel( baseModel );
+
+ mMimeTypeFilterModel = new CollectionFilterProxyModel( parent );
+ mMimeTypeFilterModel->setSourceModel( proxyModel );
+
+ mRightsFilterModel = new EntityRightsFilterModel( parent );
+ mRightsFilterModel->setSourceModel( mMimeTypeFilterModel );
+
+ mFilterModel = new QSortFilterProxyModel( parent );
+ mFilterModel->setFilterCaseSensitivity( Qt::CaseInsensitive );
+ mFilterModel->setSourceModel( mRightsFilterModel );
+
+ mSelectionModel = new QItemSelectionModel( mFilterModel );
+ mParent->connect( mSelectionModel, SIGNAL( selectionChanged( const \
QItemSelection&, const QItemSelection& ) ), + SLOT( \
slotSelectionChanged() ) ); + mParent->connect( mSelectionModel, SIGNAL( \
selectionChanged( const QItemSelection&, const QItemSelection& ) ), + \
this, SLOT( selectionChanged( const QItemSelection&, const QItemSelection& ) ) ); +
+ mSelectionHandler = new AsyncSelectionHandler( mFilterModel, mParent );
+ mParent->connect( mSelectionHandler, SIGNAL( collectionAvailable( const \
QModelIndex& ) ), + SLOT( slotCollectionAvailable( const \
QModelIndex& ) ) ); +
+ foreach ( const QString &importPath, KGlobal::dirs()->findDirs( "module", \
QLatin1String( "imports" ) ) ) + mView->engine()->addImportPath( importPath );
+
+ mView->rootContext()->setContextProperty( QLatin1String( "dialogController" ), \
this ); + mView->rootContext()->setContextProperty( QLatin1String( "collectionModel" \
), mFilterModel ); +
+ // QUICKHACK: since we have no KDE integration plugin available in kdelibs, we \
have to do the translation in C++ space + mView->rootContext()->setContextProperty( \
QLatin1String( "okButtonText" ), KStandardGuiItem::ok().text().remove( QLatin1Char( \
'&' ) ) ); + mView->rootContext()->setContextProperty( QLatin1String( \
"cancelButtonText" ), KStandardGuiItem::cancel().text().remove( QLatin1Char( '&' ) ) \
); + mView->rootContext()->setContextProperty( QLatin1String( "createButtonText" ), \
i18n( "&New Subfolder..." ).remove( QLatin1Char( '&' ) ) ); +
+ mView->setSource( QUrl( QLatin1String( "qrc:/CollectionDialogMobile.qml" ) ) );
+}
+
+CollectionDialog::Private::~Private()
{
}
- void slotCollectionAvailable( const QModelIndex& )
+void CollectionDialog::Private::slotCollectionAvailable( const QModelIndex &index )
{
+ mSelectionModel->setCurrentIndex( index, QItemSelectionModel::ClearAndSelect );
}
- CollectionDialog *mParent;
-
- QLabel *mTextLabel;
- CollectionComboBox *mCollectionComboBox;
- QAbstractItemView::SelectionMode mSelectionMode;
- bool mAllowToCreateNewChildCollection;
-
- void slotSelectionChanged();
- void slotAddChildCollection();
- void slotCollectionCreationResult( KJob* job );
- bool canCreateCollection( const Akonadi::Collection &parentCollection ) const;
- void changeCollectionDialogOptions( CollectionDialogOptions options );
-
-};
-
void CollectionDialog::Private::slotSelectionChanged()
{
- mParent->enableButton( KDialog::Ok, mCollectionComboBox->count() > 0 );
+ mOkButtonEnabled = mSelectionModel->hasSelection();
if ( mAllowToCreateNewChildCollection ) {
const Akonadi::Collection parentCollection = mParent->selectedCollection();
const bool canCreateChildCollections = canCreateCollection( parentCollection );
const bool isVirtual = Akonadi::CollectionUtils::isVirtual( parentCollection );
- mParent->enableButton( KDialog::User1, (canCreateChildCollections && !isVirtual) \
); + mCreateButtonEnabled = (canCreateChildCollections && !isVirtual);
if ( parentCollection.isValid() ) {
const bool canCreateItems = (parentCollection.rights() & \
Akonadi::Collection::CanCreateItem);
- mParent->enableButton( KDialog::Ok, canCreateItems );
+ mOkButtonEnabled = canCreateItems;
}
}
+
+ emit buttonStatusChanged();
}
void CollectionDialog::Private::changeCollectionDialogOptions( \
CollectionDialogOptions options ) {
mAllowToCreateNewChildCollection = ( options & AllowToCreateNewChildCollection );
- if ( mAllowToCreateNewChildCollection ) {
- mParent->setButtons( Ok | Cancel | User1 );
- mParent->setButtonGuiItem( User1, KGuiItem( i18n( "&New Subfolder..." ), \
QLatin1String( "folder-new" ),
- i18n( "Create a new subfolder under \
the currently selected folder" ) ) );
- mParent->enableButton( KDialog::User1, false );
- connect( mParent, SIGNAL( user1Clicked() ), mParent, SLOT( \
slotAddChildCollection() ) ); + emit buttonStatusChanged();
}
-}
-
-
bool CollectionDialog::Private::canCreateCollection( const Akonadi::Collection \
&parentCollection ) const {
if ( !parentCollection.isValid() )
@@ -126,7 +160,6 @@
return false;
}
-
void CollectionDialog::Private::slotAddChildCollection()
{
const Akonadi::Collection parentCollection = mParent->selectedCollection();
@@ -153,8 +186,71 @@
}
}
+void CollectionDialog::Private::setDescriptionText( const QString &text )
+{
+ mDescriptionText = text;
+ emit descriptionTextChanged();
+}
+QString CollectionDialog::Private::descriptionText() const
+{
+ return mDescriptionText;
+}
+bool CollectionDialog::Private::okButtonEnabled() const
+{
+ return mOkButtonEnabled;
+}
+
+bool CollectionDialog::Private::cancelButtonEnabled() const
+{
+ return mCancelButtonEnabled;
+}
+
+bool CollectionDialog::Private::createButtonEnabled() const
+{
+ return mCreateButtonEnabled;
+}
+
+bool CollectionDialog::Private::createButtonVisible() const
+{
+ return mAllowToCreateNewChildCollection;
+}
+
+void CollectionDialog::Private::okClicked()
+{
+ mParent->accept();
+}
+
+void CollectionDialog::Private::cancelClicked()
+{
+ mParent->reject();
+}
+
+void CollectionDialog::Private::createClicked()
+{
+ slotAddChildCollection();
+}
+
+void CollectionDialog::Private::setCurrentIndex( int row )
+{
+ const QModelIndex index = mSelectionModel->model()->index( row, 0 );
+ mSelectionModel->select( index, QItemSelectionModel::ClearAndSelect );
+}
+
+void CollectionDialog::Private::setFilterText( const QString &text )
+{
+ mFilterModel->setFilterFixedString( text );
+}
+
+void CollectionDialog::Private::selectionChanged( const QItemSelection &selection, \
const QItemSelection& ) +{
+ if ( selection.isEmpty() )
+ return;
+
+ emit selectionChanged( selection.indexes().first().row() );
+}
+
CollectionDialog::CollectionDialog( QWidget *parent )
: KDialog( parent ),
d( new Private( 0, this, CollectionDialog::None ) )
@@ -176,48 +272,53 @@
CollectionDialog::~CollectionDialog()
{
- delete d;
}
Akonadi::Collection CollectionDialog::selectedCollection() const
{
- return d->mCollectionComboBox->currentCollection();
+ if ( !d->mSelectionModel->hasSelection() )
+ return Akonadi::Collection();
+
+ return d->mSelectionModel->selectedRows().first().data( \
Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>(); }
Akonadi::Collection::List CollectionDialog::selectedCollections() const
{
- return (Collection::List() << d->mCollectionComboBox->currentCollection());
+ if ( !d->mSelectionModel->hasSelection() )
+ return Akonadi::Collection::List();
+
+ return (Akonadi::Collection::List() << \
d->mSelectionModel->selectedRows().first().data( \
Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>()); }
void CollectionDialog::setMimeTypeFilter( const QStringList &mimeTypes )
{
- d->mCollectionComboBox->setMimeTypeFilter( mimeTypes );
+ d->mMimeTypeFilterModel->clearFilters();
+ d->mMimeTypeFilterModel->addMimeTypeFilters( mimeTypes );
}
QStringList CollectionDialog::mimeTypeFilter() const
{
- return d->mCollectionComboBox->mimeTypeFilter();
+ return d->mMimeTypeFilterModel->mimeTypes();
}
void CollectionDialog::setAccessRightsFilter( Collection::Rights rights )
{
- d->mCollectionComboBox->setAccessRightsFilter( rights );
+ d->mRightsFilterModel->setAccessRights( rights );
}
Collection::Rights CollectionDialog::accessRightsFilter() const
{
- return d->mCollectionComboBox->accessRightsFilter();
+ return d->mRightsFilterModel->accessRights();
}
void CollectionDialog::setDescription( const QString &text )
{
- d->mTextLabel->setText( text );
- d->mTextLabel->show();
+ d->setDescriptionText( text );
}
void CollectionDialog::setDefaultCollection( const Collection &collection )
{
- d->mCollectionComboBox->setDefaultCollection( collection );
+ d->mSelectionHandler->waitForCollection( collection );
}
void CollectionDialog::setSelectionMode( QAbstractItemView::SelectionMode mode )
@@ -236,3 +337,4 @@
}
#include "collectiondialog.moc"
+#include "collectiondialog_mobile_p.moc"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic