• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • 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( KDialog::spacingHint() );
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   q->setCollection( dlg->selectedCollection() );
00100 }
00101 
00102 CollectionRequester::CollectionRequester( QWidget *parent )
00103   : KHBox( parent ),
00104     d( new Private( this ) )
00105 {
00106   d->init();
00107 }
00108 
00109 
00110 CollectionRequester::CollectionRequester( const Akonadi::Collection &collection, QWidget *parent )
00111   : KHBox( parent ),
00112     d( new Private( this ) )
00113 {
00114   d->init();
00115   setCollection( collection );
00116 }
00117 
00118 
00119 CollectionRequester::~CollectionRequester()
00120 {
00121   delete d;
00122 }
00123 
00124 
00125 Collection CollectionRequester::collection() const
00126 {
00127   return d->collection;
00128 }
00129 
00130 
00131 void CollectionRequester::setCollection( const Collection& collection )
00132 {
00133   d->collection = collection;
00134   d->edit->setText( collection.isValid() ? collection.name() : i18n( "no collection" ) );
00135 }
00136 
00137 void CollectionRequester::setMimeTypeFilter( const QStringList &mimeTypes )
00138 {
00139   if ( d->collectionDialog )
00140     d->collectionDialog->setMimeTypeFilter( mimeTypes );
00141 }
00142 
00143 QStringList CollectionRequester::mimeTypeFilter() const
00144 {
00145   if ( d->collectionDialog )
00146     return d->collectionDialog->mimeTypeFilter();
00147   else
00148     return QStringList();
00149 }
00150 
00151 #include "collectionrequester.moc"

akonadi

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal