• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

mailcommon

  • sources
  • kde-4.12
  • kdepim
  • mailcommon
  • folder
folderrequester.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004 Carsten Burghardt <burghardt@kde.org>
3  * Copyright (c) 2009 Montel Laurent <montel@kde.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; version 2 of the License
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * In addition, as a special exception, the copyright holders give
19  * permission to link the code of this program with any edition of
20  * the Qt library by Trolltech AS, Norway (or with modified versions
21  * of Qt that use the same license as Qt), and distribute linked
22  * combinations including the two. You must obey the GNU General
23  * Public License in all respects for all of the code used other than
24  * Qt. If you modify this file, you may extend this exception to
25  * your version of the file, but you are not obligated to do so. If
26  * you do not wish to do so, delete this exception statement from
27  * your version.
28  */
29 
30 #include "folderrequester.h"
31 #include "folderselectiondialog.h"
32 #include "util/mailutil.h"
33 #include "kernel/mailkernel.h"
34 
35 #include <messageviewer/utils/autoqpointer.h>
36 
37 #include <Akonadi/CollectionFetchJob>
38 
39 #include <KDialog>
40 #include <KIconLoader>
41 #include <KLineEdit>
42 #include <KLocale>
43 
44 #include <QHBoxLayout>
45 #include <QKeyEvent>
46 #include <QToolButton>
47 
48 namespace MailCommon {
49 
50 FolderRequester::FolderRequester( QWidget *parent )
51  : QWidget( parent ),
52  mMustBeReadWrite( true ), mShowOutbox( true ), mNotCreateNewFolder( false )
53 {
54  QHBoxLayout *hlay = new QHBoxLayout( this );
55  hlay->setSpacing( KDialog::spacingHint() );
56  hlay->setContentsMargins( 0, 0, 0, 0 );
57 
58  mEdit = new KLineEdit( this );
59  mEdit->setClickMessage( i18n( "Select Folder" ) );
60  mEdit->setTrapReturnKey(true);
61  mEdit->setReadOnly( true );
62  hlay->addWidget( mEdit );
63 
64  QToolButton *button = new QToolButton( this );
65  button->setIcon( KIcon( QLatin1String("folder") ) );
66  button->setIconSize( QSize( KIconLoader::SizeSmall, KIconLoader::SizeSmall ) );
67  hlay->addWidget( button );
68  connect( button, SIGNAL(clicked()), this, SLOT(slotOpenDialog()) );
69 
70  setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding,
71  QSizePolicy::Fixed ) );
72  setFocusPolicy( Qt::StrongFocus );
73 }
74 
75 //-----------------------------------------------------------------------------
76 void FolderRequester::slotOpenDialog()
77 {
78  FolderSelectionDialog::SelectionFolderOptions options = FolderSelectionDialog::EnableCheck ;
79  options |= FolderSelectionDialog::HideVirtualFolder;
80  options |= FolderSelectionDialog::NotUseGlobalSettings;
81  if ( mNotCreateNewFolder ) {
82  options |= FolderSelectionDialog::NotAllowToCreateNewFolder;
83  }
84  if ( !mShowOutbox ) {
85  options |= FolderSelectionDialog::HideOutboxFolder;
86  }
87 
88  MessageViewer::AutoQPointer<FolderSelectionDialog> dlg(
89  new FolderSelectionDialog( this, options ) );
90 
91  dlg->setCaption( i18n( "Select Folder" ) );
92  dlg->setModal( false );
93  dlg->setSelectedCollection( mCollection );
94 
95  if ( dlg->exec() && dlg ) {
96  setCollection( dlg->selectedCollection(), false );
97  }
98 }
99 
100 //-----------------------------------------------------------------------------
101 FolderRequester::~FolderRequester()
102 {
103 }
104 
105 Akonadi::Collection FolderRequester::collection() const
106 {
107  return mCollection;
108 }
109 
110 void FolderRequester::setCollectionFullPath( const Akonadi::Collection &col )
111 {
112  if ( KernelIf->collectionModel() ) {
113  mEdit->setText( Util::fullCollectionPath( col ) );
114  } else {
115  mEdit->clear();
116  }
117 }
118 
119 //-----------------------------------------------------------------------------
120 void FolderRequester::setCollection( const Akonadi::Collection &collection, bool fetchCollection )
121 {
122  mCollection = collection;
123  if ( mCollection.isValid() ) {
124  if ( fetchCollection ) {
125  Akonadi::CollectionFetchJob *job =
126  new Akonadi::CollectionFetchJob( mCollection, Akonadi::CollectionFetchJob::Base, this );
127 
128  connect( job, SIGNAL(result(KJob*)),
129  this, SLOT(slotCollectionsReceived(KJob*)) );
130  } else {
131  setCollectionFullPath( mCollection );
132  }
133  } else if ( !mMustBeReadWrite ) { // the Local Folders root node was selected
134  mEdit->setText( i18n( "Local Folders" ) );
135  }
136 
137  emit folderChanged( mCollection );
138 }
139 
140 void FolderRequester::slotCollectionsReceived( KJob *job )
141 {
142  if ( job->error() ) {
143  mCollection = Akonadi::Collection();
144  mEdit->setText( i18n( "Please select a folder" ) );
145  return;
146  }
147 
148  const Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob*>( job );
149  const Akonadi::Collection::List collections = fetchJob->collections();
150 
151  if ( !collections.isEmpty() ) {
152  const Akonadi::Collection collection = collections.first();
153  // in case this is still the collection we are interested in, update
154  if ( collection.id() == mCollection.id() ) {
155  mCollection = collection;
156  setCollectionFullPath( collection );
157  }
158  } else {
159  // the requested collection doesn't exists anymore
160  mCollection = Akonadi::Collection();
161  mEdit->setText( i18n( "Please select a folder" ) );
162  }
163 }
164 
165 bool FolderRequester::hasCollection() const
166 {
167  return mCollection.isValid();
168 }
169 
170 //-----------------------------------------------------------------------------
171 void FolderRequester::keyPressEvent( QKeyEvent *e )
172 {
173  if ( e->key() == Qt::Key_Space ) {
174  slotOpenDialog();
175  } else {
176  e->ignore();
177  }
178 }
179 
180 void FolderRequester::setMustBeReadWrite( bool readwrite )
181 {
182  mMustBeReadWrite = readwrite;
183 }
184 
185 void FolderRequester::setShowOutbox( bool show )
186 {
187  mShowOutbox = show;
188 }
189 
190 void FolderRequester::setNotAllowToCreateNewFolder( bool notCreateNewFolder )
191 {
192  mNotCreateNewFolder = notCreateNewFolder;
193 }
194 
195 
196 } // namespace MailCommon
197 
198 #include "folderrequester.moc"
MailCommon::FolderRequester::mCollection
Akonadi::Collection mCollection
Definition: folderrequester.h:121
folderrequester.h
KernelIf
#define KernelIf
Definition: mailkernel.h:186
MailCommon::FolderRequester::~FolderRequester
virtual ~FolderRequester()
Definition: folderrequester.cpp:101
QWidget
MailCommon::FolderSelectionDialog::HideOutboxFolder
Definition: folderselectiondialog.h:49
MailCommon::FolderSelectionDialog::NotUseGlobalSettings
Definition: folderselectiondialog.h:50
MailCommon::FolderRequester::collection
Akonadi::Collection collection() const
Returns the selected collection.
Definition: folderrequester.cpp:105
MailCommon::FolderRequester::setShowOutbox
void setShowOutbox(bool show)
Definition: folderrequester.cpp:185
MailCommon::FolderSelectionDialog::NotAllowToCreateNewFolder
Definition: folderselectiondialog.h:48
MailCommon::FolderRequester::FolderRequester
FolderRequester(QWidget *parent=0)
Constructor.
Definition: folderrequester.cpp:50
MailCommon::FolderSelectionDialog::EnableCheck
Definition: folderselectiondialog.h:45
MailCommon::FolderRequester::setCollectionFullPath
void setCollectionFullPath(const Akonadi::Collection &col)
Definition: folderrequester.cpp:110
MailCommon::FolderRequester::setMustBeReadWrite
void setMustBeReadWrite(bool readwrite)
Sets if readonly folders should be disabled.
Definition: folderrequester.cpp:180
MailCommon::FolderSelectionDialog
A dialog that lets the user select a folder.
Definition: folderselectiondialog.h:38
MailCommon::FolderRequester::folderChanged
void folderChanged(const Akonadi::Collection &)
Emitted when the folder changed.
MailCommon::FolderRequester::hasCollection
bool hasCollection() const
Returns true if there's a valid collection set on this widget.
Definition: folderrequester.cpp:165
MailCommon::FolderRequester::slotOpenDialog
void slotOpenDialog()
Opens the folder dialog.
Definition: folderrequester.cpp:76
MailCommon::FolderRequester::setNotAllowToCreateNewFolder
void setNotAllowToCreateNewFolder(bool notCreateNewFolder)
Definition: folderrequester.cpp:190
MailCommon::FolderSelectionDialog::HideVirtualFolder
Definition: folderselectiondialog.h:47
folderselectiondialog.h
MailCommon::FolderRequester::mNotCreateNewFolder
bool mNotCreateNewFolder
Definition: folderrequester.h:125
MailCommon::FolderRequester::mMustBeReadWrite
bool mMustBeReadWrite
Definition: folderrequester.h:123
mailkernel.h
MailCommon::Util::fullCollectionPath
MAILCOMMON_EXPORT QString fullCollectionPath(const Akonadi::Collection &collection)
Definition: mailutil.cpp:117
MailCommon::FolderRequester::slotCollectionsReceived
void slotCollectionsReceived(KJob *)
Updates the information we have about the current folder.
Definition: folderrequester.cpp:140
MailCommon::FolderRequester::setCollection
void setCollection(const Akonadi::Collection &collection, bool fetchCollection=true)
Presets the folder to the collection collection.
Definition: folderrequester.cpp:120
mailutil.h
MailCommon::FolderRequester::mShowOutbox
bool mShowOutbox
Definition: folderrequester.h:124
MailCommon::FolderRequester::keyPressEvent
void keyPressEvent(QKeyEvent *e)
Capture space key to open the dialog.
Definition: folderrequester.cpp:171
MailCommon::FolderRequester::mEdit
KLineEdit * mEdit
Definition: folderrequester.h:122
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



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