• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.8.3 API Reference
  • KDE Home
  • Contact Us
 

akonadi

collectionrequester.cpp
00001 /*
00002     Copyright 2008 Ingo Klöcker <kloecker@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
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     // slots
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->setCaption( i18n( "Select a collection" ) );
00090   collectionDialog->setSelectionMode( QAbstractItemView::SingleSelection );
00091 }
00092 
00093 void CollectionRequester::Private::_k_slotOpenDialog()
00094 {
00095   CollectionDialog *dlg = collectionDialog;
00096 
00097   if ( dlg->exec() != QDialog::Accepted )
00098     return;
00099 
00100   const Akonadi::Collection collection = dlg->selectedCollection();
00101   q->setCollection( collection );
00102   emit q->collectionChanged( collection );
00103 }
00104 
00105 CollectionRequester::CollectionRequester( QWidget *parent )
00106   : KHBox( parent ),
00107     d( new Private( this ) )
00108 {
00109   d->init();
00110 }
00111 
00112 
00113 CollectionRequester::CollectionRequester( const Akonadi::Collection &collection, QWidget *parent )
00114   : KHBox( parent ),
00115     d( new Private( this ) )
00116 {
00117   d->init();
00118   setCollection( collection );
00119 }
00120 
00121 
00122 CollectionRequester::~CollectionRequester()
00123 {
00124   delete d;
00125 }
00126 
00127 
00128 Collection CollectionRequester::collection() const
00129 {
00130   return d->collection;
00131 }
00132 
00133 
00134 void CollectionRequester::setCollection( const Collection& collection )
00135 {
00136   d->collection = collection;
00137   d->edit->setText( collection.isValid() ? collection.name() : i18n( "No Folder" ) );
00138   emit collectionChanged( collection );
00139 }
00140 
00141 void CollectionRequester::setMimeTypeFilter( const QStringList &mimeTypes )
00142 {
00143   if ( d->collectionDialog )
00144     d->collectionDialog->setMimeTypeFilter( mimeTypes );
00145 }
00146 
00147 QStringList CollectionRequester::mimeTypeFilter() const
00148 {
00149   if ( d->collectionDialog )
00150     return d->collectionDialog->mimeTypeFilter();
00151   else
00152     return QStringList();
00153 }
00154 
00155 void CollectionRequester::setAccessRightsFilter( Collection::Rights rights )
00156 {
00157   if ( d->collectionDialog )
00158     d->collectionDialog->setAccessRightsFilter( rights );
00159 }
00160 
00161 Collection::Rights CollectionRequester::accessRightsFilter() const
00162 {
00163   if ( d->collectionDialog )
00164     return d->collectionDialog->accessRightsFilter();
00165   else
00166     return Akonadi::Collection::ReadOnly;
00167 }
00168 
00169 void CollectionRequester::changeCollectionDialogOptions( CollectionDialog::CollectionDialogOptions options )
00170 {
00171   if ( d->collectionDialog )
00172     d->collectionDialog->changeCollectionDialogOptions( options );
00173 }
00174 
00175 #include "collectionrequester.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:15 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal