00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "collectionrequester.h"
00021 #include "collectiondialog.h"
00022
00023 #include <klineedit.h>
00024 #include <klocale.h>
00025 #include <kpushbutton.h>
00026 #include <kstandardshortcut.h>
00027
00028 #include <QtCore/QEvent>
00029 #include <QtGui/QAction>
00030 #include <QtGui/QApplication>
00031
00032 using namespace Akonadi;
00033
00034 class CollectionRequester::Private
00035 {
00036 public:
00037 Private( CollectionRequester *parent )
00038 : q( parent ),
00039 edit( 0 ),
00040 button( 0 ),
00041 collectionDialog( 0 )
00042 {
00043 }
00044
00045 ~Private()
00046 {
00047 }
00048
00049 void init();
00050
00051
00052 void _k_slotOpenDialog();
00053
00054 CollectionRequester *q;
00055 Collection collection;
00056 KLineEdit *edit;
00057 KPushButton *button;
00058 CollectionDialog *collectionDialog;
00059 };
00060
00061
00062 void CollectionRequester::Private::init()
00063 {
00064 q->setMargin( 0 );
00065
00066 edit = new KLineEdit( q );
00067 edit->setReadOnly( true );
00068 edit->setClearButtonShown( false );
00069
00070 button = new KPushButton( q );
00071 button->setIcon( KIcon( QLatin1String( "document-open" ) ) );
00072 const int buttonSize = edit->sizeHint().height();
00073 button->setFixedSize( buttonSize, buttonSize );
00074 button->setToolTip( i18n( "Open collection dialog" ) );
00075
00076 q->setSpacing( -1 );
00077
00078 edit->installEventFilter( q );
00079 q->setFocusProxy( edit );
00080 q->setFocusPolicy( Qt::StrongFocus );
00081
00082 q->connect( button, SIGNAL( clicked() ), q, SLOT( _k_slotOpenDialog() ) );
00083
00084 QAction *openAction = new QAction( q );
00085 openAction->setShortcut( KStandardShortcut::Open );
00086 q->connect( openAction, SIGNAL( triggered( bool ) ), q, SLOT( _k_slotOpenDialog() ) );
00087
00088 collectionDialog = new CollectionDialog( q );
00089 collectionDialog->setSelectionMode( QAbstractItemView::SingleSelection );
00090 }
00091
00092 void CollectionRequester::Private::_k_slotOpenDialog()
00093 {
00094 CollectionDialog *dlg = collectionDialog;
00095
00096 if ( dlg->exec() != QDialog::Accepted )
00097 return;
00098
00099 const Akonadi::Collection collection = dlg->selectedCollection();
00100 q->setCollection( collection );
00101 emit q->collectionChanged( collection );
00102 }
00103
00104 CollectionRequester::CollectionRequester( QWidget *parent )
00105 : KHBox( parent ),
00106 d( new Private( this ) )
00107 {
00108 d->init();
00109 }
00110
00111
00112 CollectionRequester::CollectionRequester( const Akonadi::Collection &collection, QWidget *parent )
00113 : KHBox( parent ),
00114 d( new Private( this ) )
00115 {
00116 d->init();
00117 setCollection( collection );
00118 }
00119
00120
00121 CollectionRequester::~CollectionRequester()
00122 {
00123 delete d;
00124 }
00125
00126
00127 Collection CollectionRequester::collection() const
00128 {
00129 return d->collection;
00130 }
00131
00132
00133 void CollectionRequester::setCollection( const Collection& collection )
00134 {
00135 d->collection = collection;
00136 d->edit->setText( collection.isValid() ? collection.name() : i18n( "No Folder" ) );
00137 emit collectionChanged( collection );
00138 }
00139
00140 void CollectionRequester::setMimeTypeFilter( const QStringList &mimeTypes )
00141 {
00142 if ( d->collectionDialog )
00143 d->collectionDialog->setMimeTypeFilter( mimeTypes );
00144 }
00145
00146 QStringList CollectionRequester::mimeTypeFilter() const
00147 {
00148 if ( d->collectionDialog )
00149 return d->collectionDialog->mimeTypeFilter();
00150 else
00151 return QStringList();
00152 }
00153
00154 void CollectionRequester::setAccessRightsFilter( Collection::Rights rights )
00155 {
00156 if ( d->collectionDialog )
00157 d->collectionDialog->setAccessRightsFilter( rights );
00158 }
00159
00160 Collection::Rights CollectionRequester::accessRightsFilter() const
00161 {
00162 if ( d->collectionDialog )
00163 return d->collectionDialog->accessRightsFilter();
00164 else
00165 return Akonadi::Collection::ReadOnly;
00166 }
00167
00168 #include "collectionrequester.moc"