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

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
manageshowcollectionproperties.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "manageshowcollectionproperties.h"
19 #include "kmmainwidget.h"
20 #include <KLocalizedString>
21 #include <KMessageBox>
22 #include <akonadi/collectionattributessynchronizationjob.h>
23 #include <Solid/Networking>
24 
25 
26 #include <akonadi/collectionfetchjob.h>
27 #include <akonadi/collectionpropertiesdialog.h>
28 #include <Akonadi/CollectionFetchScope>
29 #include <Akonadi/AgentInstance>
30 #include <Akonadi/AgentManager>
31 
32 Q_DECLARE_METATYPE(KPIM::ProgressItem*)
33 Q_DECLARE_METATYPE(Akonadi::Job*)
34 Q_DECLARE_METATYPE(QPointer<KPIM::ProgressItem>)
35 
36 ManageShowCollectionProperties::ManageShowCollectionProperties(KMMainWidget *mainWidget, QObject *parent)
37  : QObject(parent),
38  mMainWidget(mainWidget)
39 {
40  mPages = QStringList() << QLatin1String( "MailCommon::CollectionGeneralPage" )
41  << QLatin1String( "KMail::CollectionViewPage" )
42  << QLatin1String( "Akonadi::CachePolicyPage" )
43  << QLatin1String( "KMail::CollectionTemplatesPage" )
44  << QLatin1String( "MailCommon::CollectionExpiryPage" )
45  << QLatin1String( "PimCommon::CollectionAclPage" )
46  << QLatin1String( "KMail::CollectionMailingListPage" )
47  << QLatin1String( "KMail::CollectionQuotaPage" )
48  << QLatin1String( "KMail::CollectionShortcutPage" )
49  << QLatin1String( "KMail::CollectionMaintenancePage" );
50 
51 }
52 
53 ManageShowCollectionProperties::~ManageShowCollectionProperties()
54 {
55 
56 }
57 
58 void ManageShowCollectionProperties::slotCollectionProperties()
59 {
60  showCollectionProperties( QString() );
61 }
62 
63 void ManageShowCollectionProperties::slotShowExpiryProperties()
64 {
65  showCollectionProperties( QLatin1String( "MailCommon::CollectionExpiryPage" ) );
66 }
67 
68 void ManageShowCollectionProperties::slotFolderMailingListProperties()
69 {
70  showCollectionProperties( QLatin1String( "KMail::CollectionMailingListPage" ) );
71 }
72 
73 void ManageShowCollectionProperties::slotShowFolderShortcutDialog()
74 {
75  showCollectionProperties( QLatin1String( "KMail::CollectionShortcutPage" ) );
76 }
77 
78 
79 void ManageShowCollectionProperties::showCollectionProperties( const QString &pageToShow )
80 {
81  if ( !mMainWidget->currentFolder() )
82  return;
83  const Akonadi::Collection::Id id = mMainWidget->currentFolder()->collection().id();
84  QPointer<Akonadi::CollectionPropertiesDialog> dlg = mHashDialogBox.value(id);
85  if (dlg) {
86  if ( !pageToShow.isEmpty() ) {
87  dlg->setCurrentPage( pageToShow );
88  }
89  dlg->activateWindow();
90  dlg->raise();
91  return;
92  }
93  if ( Solid::Networking::status() == Solid::Networking::Connected || Solid::Networking::status() == Solid::Networking::Unknown) {
94  const Akonadi::AgentInstance agentInstance = Akonadi::AgentManager::self()->instance( mMainWidget->currentFolder()->collection().resource() );
95  bool isOnline = agentInstance.isOnline();
96  if (!isOnline) {
97  showCollectionPropertiesContinued( pageToShow, QPointer<KPIM::ProgressItem>() );
98  } else {
99  QPointer<KPIM::ProgressItem> progressItem( KPIM::ProgressManager::createProgressItem( i18n( "Retrieving folder properties" ) ) );
100  progressItem->setUsesBusyIndicator( true );
101  progressItem->setCryptoStatus(KPIM::ProgressItem::Unknown);
102 
103  Akonadi::CollectionAttributesSynchronizationJob *sync
104  = new Akonadi::CollectionAttributesSynchronizationJob( mMainWidget->currentFolder()->collection() );
105  sync->setProperty( "collectionId", id );
106  sync->setProperty( "pageToShow", pageToShow ); // note for dialog later
107  sync->setProperty( "progressItem", QVariant::fromValue( progressItem ) );
108  connect( sync, SIGNAL(result(KJob*)),
109  this, SLOT(slotCollectionPropertiesContinued(KJob*)) );
110  connect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
111  sync, SLOT(kill()) );
112  connect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
113  KPIM::ProgressManager::instance(), SLOT(slotStandardCancelHandler(KPIM::ProgressItem*)) );
114  sync->start();
115  }
116  } else {
117  KMessageBox::information(
118  mMainWidget,
119  i18n( "Network is unconnected. Folder information cannot be updated." ) );
120  showCollectionPropertiesContinued( pageToShow, QPointer<KPIM::ProgressItem>() );
121  }
122 }
123 
124 void ManageShowCollectionProperties::slotCollectionPropertiesContinued( KJob* job )
125 {
126  QString pageToShow;
127  QPointer<KPIM::ProgressItem> progressItem;
128 
129  if ( job ) {
130  Akonadi::CollectionAttributesSynchronizationJob *sync
131  = dynamic_cast<Akonadi::CollectionAttributesSynchronizationJob *>( job );
132  Q_ASSERT( sync );
133  if ( sync->property( "collectionId" ) != mMainWidget->currentFolder()->collection().id() )
134  return;
135  pageToShow = sync->property( "pageToShow" ).toString();
136  progressItem = sync->property( "progressItem" ).value< QPointer<KPIM::ProgressItem> >();
137  if ( progressItem ) {
138  disconnect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
139  sync, SLOT(kill()) );
140  } else {
141  // progressItem does not exist anymore, operation has been canceled
142  return;
143  }
144  }
145 
146  showCollectionPropertiesContinued( pageToShow, progressItem );
147 }
148 
149 void ManageShowCollectionProperties::showCollectionPropertiesContinued( const QString &pageToShow, QPointer<KPIM::ProgressItem> progressItem )
150 {
151  if ( !progressItem ) {
152  progressItem = KPIM::ProgressManager::createProgressItem( i18n( "Retrieving folder properties" ) );
153  progressItem->setUsesBusyIndicator( true );
154  progressItem->setCryptoStatus(KPIM::ProgressItem::Unknown);
155  connect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
156  KPIM::ProgressManager::instance(), SLOT(slotStandardCancelHandler(KPIM::ProgressItem*)) );
157  }
158 
159  Akonadi::CollectionFetchJob *fetch = new Akonadi::CollectionFetchJob( mMainWidget->currentFolder()->collection(),
160  Akonadi::CollectionFetchJob::Base );
161  connect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), fetch, SLOT(kill()) );
162  fetch->fetchScope().setIncludeStatistics( true );
163  fetch->setProperty( "pageToShow", pageToShow );
164  fetch->setProperty( "progressItem", QVariant::fromValue( progressItem ) );
165  connect( fetch, SIGNAL(result(KJob*)),
166  this, SLOT(slotCollectionPropertiesFinished(KJob*)) );
167  connect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
168  fetch, SLOT(kill()) );
169 }
170 
171 void ManageShowCollectionProperties::slotCollectionPropertiesFinished( KJob *job )
172 {
173  if ( !job )
174  return;
175 
176  QPointer<KPIM::ProgressItem> progressItem = job->property( "progressItem" ).value< QPointer<KPIM::ProgressItem> >();
177  // progressItem does not exist anymore, operation has been canceled
178  if ( !progressItem ) {
179  return;
180  }
181 
182  progressItem->setComplete();
183  progressItem->setStatus( i18n( "Done" ) );
184 
185  Akonadi::CollectionFetchJob *fetch = dynamic_cast<Akonadi::CollectionFetchJob *>( job );
186  Q_ASSERT( fetch );
187  if ( fetch->collections().isEmpty() )
188  {
189  kWarning() << "no collection";
190  return;
191  }
192 
193  const Akonadi::Collection collection = fetch->collections().first();
194 
195  QPointer<Akonadi::CollectionPropertiesDialog> dlg = new Akonadi::CollectionPropertiesDialog( collection, mPages, mMainWidget );
196  dlg->setCaption( i18nc( "@title:window", "Properties of Folder %1", collection.name() ) );
197 
198 
199  const QString pageToShow = fetch->property( "pageToShow" ).toString();
200  if ( !pageToShow.isEmpty() ) { // show a specific page
201  dlg->setCurrentPage( pageToShow );
202  }
203  dlg->show();
204  mHashDialogBox.insert(collection.id(), dlg);
205 }
KPIM::ProgressManager::instance
static ProgressManager * instance()
QHash::insert
iterator insert(const Key &key, const T &value)
kmmainwidget.h
ManageShowCollectionProperties::~ManageShowCollectionProperties
~ManageShowCollectionProperties()
Definition: manageshowcollectionproperties.cpp:53
KPIM::ProgressItem::Unknown
QPointer
KMMainWidget::currentFolder
QSharedPointer< MailCommon::FolderCollection > currentFolder() const
Definition: kmmainwidget.cpp:4161
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
manageshowcollectionproperties.h
ManageShowCollectionProperties::slotShowFolderShortcutDialog
void slotShowFolderShortcutDialog()
Definition: manageshowcollectionproperties.cpp:73
ManageShowCollectionProperties::slotShowExpiryProperties
void slotShowExpiryProperties()
Definition: manageshowcollectionproperties.cpp:63
QObject
QString::isEmpty
bool isEmpty() const
ManageShowCollectionProperties::slotFolderMailingListProperties
void slotFolderMailingListProperties()
Definition: manageshowcollectionproperties.cpp:68
KMMainWidget
Definition: kmmainwidget.h:91
QString
QStringList
QHash::value
const T value(const Key &key) const
ManageShowCollectionProperties
Definition: manageshowcollectionproperties.h:33
QVariant::fromValue
QVariant fromValue(const T &value)
QLatin1String
KPIM::ProgressItem
ManageShowCollectionProperties::slotCollectionProperties
void slotCollectionProperties()
Definition: manageshowcollectionproperties.cpp:58
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KJob
KPIM::ProgressManager::createProgressItem
static ProgressItem * createProgressItem(unsigned int progressType, const QString &label)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:33 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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
  • pimprint

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