• 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
  • configuredialog
configureaccountpage.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2013-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 "configureaccountpage.h"
19 #include "dialog/kmknotify.h"
20 #include "newmailnotifierinterface.h"
21 #include "kmkernel.h"
22 #include "settings/globalsettings.h"
23 #include "configagentdelegate.h"
24 #include "messagecomposer/settings/messagecomposersettings.h"
25 #include "mailcommon/folder/accountconfigorderdialog.h"
26 #include "pimcommon/widgets/configureimmutablewidgetutils.h"
27 using namespace PimCommon::ConfigureImmutableWidgetUtils;
28 #include <mailtransport/transportmanagementwidget.h>
29 using MailTransport::TransportManagementWidget;
30 #include "ui_accountspagereceivingtab.h"
31 #include "mailcommon/util/mailutil.h"
32 
33 #include <akonadi/agentfilterproxymodel.h>
34 #include <akonadi/agentinstancemodel.h>
35 #include <akonadi/agenttype.h>
36 #include <akonadi/agentmanager.h>
37 #include <akonadi/agenttypedialog.h>
38 #include <akonadi/agentinstancecreatejob.h>
39 
40 
41 #include <KLocalizedString>
42 #include <KMessageBox>
43 #include <KComboBox>
44 #include <KWindowSystem>
45 #include <KLineEdit>
46 
47 #include <QVBoxLayout>
48 #include <QGridLayout>
49 #include <QGroupBox>
50 #include <QHostInfo>
51 #include <QMenu>
52 #include <QLabel>
53 
54 QString AccountsPage::helpAnchor() const
55 {
56  return QString::fromLatin1("configure-accounts");
57 }
58 
59 AccountsPage::AccountsPage( const KComponentData &instance, QWidget *parent )
60  : ConfigModuleWithTabs( instance, parent )
61 {
62  //
63  // "Receiving" tab:
64  //
65  mReceivingTab = new ReceivingTab();
66  addTab( mReceivingTab, i18nc( "@title:tab Tab page where the user configures accounts to receive mail", "Receiving" ) );
67  connect( mReceivingTab, SIGNAL(accountListChanged(QStringList)),
68  this, SIGNAL(accountListChanged(QStringList)) );
69 
70  //
71  // "Sending" tab:
72  //
73  mSendingTab = new SendingTab();
74  addTab( mSendingTab, i18nc( "@title:tab Tab page where the user configures accounts to send mail", "Sending" ) );
75 }
76 
77 AccountsPageSendingTab::~AccountsPageSendingTab()
78 {
79 }
80 
81 QString AccountsPage::SendingTab::helpAnchor() const
82 {
83  return QString::fromLatin1("configure-accounts-sending");
84 }
85 
86 AccountsPageSendingTab::AccountsPageSendingTab( QWidget * parent )
87  : ConfigModuleTab( parent )
88 {
89  QVBoxLayout *vlay = new QVBoxLayout( this );
90  vlay->setSpacing( KDialog::spacingHint() );
91  vlay->setMargin( KDialog::marginHint() );
92  // label: zero stretch ### FIXME more
93  vlay->addWidget( new QLabel( i18n("Outgoing accounts (add at least one):"), this ) );
94 
95  TransportManagementWidget *tmw = new TransportManagementWidget( this );
96  tmw->layout()->setContentsMargins( 0, 0, 0, 0 );
97  vlay->addWidget( tmw );
98 
99  // "Common options" groupbox:
100  QGroupBox *group = new QGroupBox( i18n("Common Options"), this );
101  vlay->addWidget(group);
102 
103  // a grid layout for the contents of the "common options" group box
104  QGridLayout *glay = new QGridLayout();
105  group->setLayout( glay );
106  glay->setSpacing( KDialog::spacingHint() );
107  glay->setColumnStretch( 2, 10 );
108 
109  // "confirm before send" check box:
110  mConfirmSendCheck = new QCheckBox( i18n("Confirm &before send"), group );
111  glay->addWidget( mConfirmSendCheck, 0, 0, 1, 2 );
112  connect( mConfirmSendCheck, SIGNAL(stateChanged(int)),
113  this, SLOT(slotEmitChanged()) );
114 
115  mCheckSpellingBeforeSending = new QCheckBox( i18n("Check spelling before sending"), group );
116  glay->addWidget( mCheckSpellingBeforeSending, 1, 0, 1, 2 );
117  connect( mCheckSpellingBeforeSending, SIGNAL(stateChanged(int)),
118  this, SLOT(slotEmitChanged()) );
119 
120  // "send on check" combo:
121  mSendOnCheckCombo = new KComboBox( group );
122  mSendOnCheckCombo->setEditable( false );
123  mSendOnCheckCombo->addItems( QStringList()
124  << i18n("Never Automatically")
125  << i18n("On Manual Mail Checks")
126  << i18n("On All Mail Checks") );
127  glay->addWidget( mSendOnCheckCombo, 2, 1 );
128  connect( mSendOnCheckCombo, SIGNAL(activated(int)),
129  this, SLOT(slotEmitChanged()) );
130 
131  // "default send method" combo:
132  mSendMethodCombo = new KComboBox( group );
133  mSendMethodCombo->setEditable( false );
134  mSendMethodCombo->addItems( QStringList()
135  << i18n("Send Now")
136  << i18n("Send Later") );
137  glay->addWidget( mSendMethodCombo, 3, 1 );
138  connect( mSendMethodCombo, SIGNAL(activated(int)),
139  this, SLOT(slotEmitChanged()) );
140 
141  // labels:
142  QLabel *l = new QLabel( i18n("Send &messages in outbox folder:"), group );
143  l->setBuddy( mSendOnCheckCombo );
144  glay->addWidget( l, 2, 0 );
145 
146  QString msg = i18n( GlobalSettings::self()->sendOnCheckItem()->whatsThis().toUtf8() );
147  l->setWhatsThis( msg );
148  mSendOnCheckCombo->setWhatsThis( msg );
149 
150  l = new QLabel( i18n("Defa&ult send method:"), group );
151  l->setBuddy( mSendMethodCombo );
152  glay->addWidget( l, 3, 0 );
153 }
154 
155 void AccountsPage::SendingTab::doLoadFromGlobalSettings()
156 {
157  mSendOnCheckCombo->setCurrentIndex( GlobalSettings::self()->sendOnCheck() );
158 }
159 
160 void AccountsPage::SendingTab::doLoadOther()
161 {
162  mSendMethodCombo->setCurrentIndex( MessageComposer::MessageComposerSettings::self()->sendImmediate() ? 0 : 1 );
163  loadWidget(mConfirmSendCheck, GlobalSettings::self()->confirmBeforeSendItem() );
164  loadWidget(mCheckSpellingBeforeSending,GlobalSettings::self()->checkSpellingBeforeSendItem());
165 }
166 
167 void AccountsPage::SendingTab::save()
168 {
169  GlobalSettings::self()->setSendOnCheck( mSendOnCheckCombo->currentIndex() );
170  saveCheckBox(mConfirmSendCheck, GlobalSettings::self()->confirmBeforeSendItem() );
171  saveCheckBox(mCheckSpellingBeforeSending,GlobalSettings::self()->checkSpellingBeforeSendItem());
172  MessageComposer::MessageComposerSettings::self()->setSendImmediate( mSendMethodCombo->currentIndex() == 0 );
173 }
174 
175 QString AccountsPage::ReceivingTab::helpAnchor() const
176 {
177  return QString::fromLatin1("configure-accounts-receiving");
178 }
179 
180 AccountsPageReceivingTab::AccountsPageReceivingTab( QWidget * parent )
181  : ConfigModuleTab( parent )
182 {
183  mNewMailNotifierInterface = new OrgFreedesktopAkonadiNewMailNotifierInterface(QLatin1String("org.freedesktop.Akonadi.NewMailNotifierAgent"), QLatin1String("/NewMailNotifierAgent"), QDBusConnection::sessionBus(), this);
184  if (!mNewMailNotifierInterface->isValid()) {
185  kDebug()<<" org.freedesktop.Akonadi.NewMailNotifierAgent not found. Please verify your installation";
186  }
187  mAccountsReceiving.setupUi( this );
188 
189  mAccountsReceiving.vlay->setSpacing( KDialog::spacingHint() );
190  mAccountsReceiving.vlay->setMargin( KDialog::marginHint() );
191  mAccountsReceiving.mAccountsReceiving->setMimeTypeFilter(QStringList() << KMime::Message::mimeType() );
192  mAccountsReceiving.mAccountsReceiving->setCapabilityFilter(QStringList() << QLatin1String("Resource"));
193  mAccountsReceiving.mAccountsReceiving->setExcludeCapabilities(QStringList() << QLatin1String("MailTransport") << QLatin1String("Notes"));
194 
195  KConfig specialMailCollection(QLatin1String("specialmailcollectionsrc"));
196  if(specialMailCollection.hasGroup(QLatin1String("SpecialCollections"))) {
197  KConfigGroup grp = specialMailCollection.group(QLatin1String("SpecialCollections"));
198  mAccountsReceiving.mAccountsReceiving->setSpecialCollectionIdentifier(grp.readEntry(QLatin1String("DefaultResourceId")));
199  }
200  ConfigAgentDelegate *configDelegate = new ConfigAgentDelegate( mAccountsReceiving.mAccountsReceiving->view() );
201  mAccountsReceiving.mAccountsReceiving->setItemDelegate(configDelegate);
202  connect( configDelegate, SIGNAL(optionsClicked(QString,QPoint)), this, SLOT(slotShowMailCheckMenu(QString,QPoint)) );
203 
204  mAccountsReceiving.group->layout()->setMargin( KDialog::marginHint() );
205  mAccountsReceiving.group->layout()->setSpacing( KDialog::spacingHint() );
206 
207  connect( mAccountsReceiving.mBeepNewMailCheck, SIGNAL(stateChanged(int)),
208  this, SLOT(slotEmitChanged()) );
209 
210  connect( mAccountsReceiving.mVerboseNotificationCheck, SIGNAL(stateChanged(int)),
211  this, SLOT(slotEmitChanged()) );
212 
213  connect( mAccountsReceiving.mOtherNewMailActionsButton, SIGNAL(clicked()),
214  this, SLOT(slotEditNotifications()) );
215  connect( mAccountsReceiving.customizeAccountOrder,SIGNAL(clicked()),this,SLOT(slotCustomizeAccountOrder()));
216 }
217 
218 AccountsPageReceivingTab::~AccountsPageReceivingTab()
219 {
220  delete mNewMailNotifierInterface;
221  mRetrievalHash.clear();
222 }
223 
224 void AccountsPageReceivingTab::slotCustomizeAccountOrder()
225 {
226  MailCommon::AccountConfigOrderDialog dlg(this);
227  dlg.exec();
228 }
229 
230 void AccountsPageReceivingTab::slotShowMailCheckMenu( const QString &ident, const QPoint & pos )
231 {
232  QMenu *menu = new QMenu( this );
233 
234  bool IncludeInManualChecks;
235  bool OfflineOnShutdown;
236  bool CheckOnStartup;
237  if( !mRetrievalHash.contains( ident ) ) {
238  const QString resourceGroupPattern( QLatin1String("Resource %1") );
239 
240  KConfigGroup group;
241  KConfig *conf = 0;
242  if (KMKernel::self()) {
243  group = KConfigGroup( KMKernel::self()->config(), resourceGroupPattern.arg( ident ) );
244  } else {
245  conf = new KConfig(QLatin1String("kmail2rc"));
246  group = KConfigGroup( conf, resourceGroupPattern.arg( ident ) );
247  }
248 
249  IncludeInManualChecks = group.readEntry( "IncludeInManualChecks", true );
250 
251  // Keep sync with kmkernel, don't forget to change there.
252  OfflineOnShutdown = group.readEntry( "OfflineOnShutdown", ident.startsWith(QLatin1String("akonadi_pop3_resource")) ? true : false );
253 
254  CheckOnStartup = group.readEntry( "CheckOnStartup", false );
255  QSharedPointer<RetrievalOptions> opts( new RetrievalOptions( IncludeInManualChecks, OfflineOnShutdown, CheckOnStartup ) );
256  mRetrievalHash.insert( ident, opts );
257  delete conf;
258  } else {
259  QSharedPointer<RetrievalOptions> opts = mRetrievalHash.value( ident );
260  IncludeInManualChecks = opts->IncludeInManualChecks;
261  OfflineOnShutdown = opts->OfflineOnShutdown;
262  CheckOnStartup = opts->CheckOnStartup;
263  }
264 
265  if ( !MailCommon::Util::isVirtualCollection( ident ) ) {
266  QAction *manualMailCheck = new QAction( i18nc( "Label to a checkbox, so is either checked/unchecked", "Include in Manual Mail Check" ), menu );
267  manualMailCheck->setCheckable( true );
268  manualMailCheck->setChecked( IncludeInManualChecks );
269  manualMailCheck->setData( ident );
270  menu->addAction( manualMailCheck );
271  connect( manualMailCheck, SIGNAL(toggled(bool)), this, SLOT(slotIncludeInCheckChanged(bool)) );
272  }
273 
274  if( !MailCommon::Util::isLocalCollection( ident ) ) {
275  QAction *switchOffline = new QAction( i18nc( "Label to a checkbox, so is either checked/unchecked", "Switch offline on KMail Shutdown" ), menu );
276  switchOffline->setCheckable( true );
277  switchOffline->setChecked( OfflineOnShutdown );
278  switchOffline->setData( ident );
279  menu->addAction( switchOffline );
280  connect( switchOffline, SIGNAL(toggled(bool)), this, SLOT(slotOfflineOnShutdownChanged(bool)) );
281  }
282 
283 
284  QAction *checkOnStartup = new QAction( i18n( "Check mail on startup" ), menu );
285  checkOnStartup->setCheckable( true );
286  checkOnStartup->setChecked( CheckOnStartup );
287  checkOnStartup->setData( ident );
288  menu->addAction( checkOnStartup );
289 
290  connect( checkOnStartup, SIGNAL(toggled(bool)), this, SLOT(slotCheckOnStatupChanged(bool)) );
291 
292  menu->exec( mAccountsReceiving.mAccountsReceiving->view()->mapToGlobal( pos ) );
293  delete menu;
294 }
295 
296 void AccountsPageReceivingTab::slotCheckOnStatupChanged( bool checked )
297 {
298  QAction* action = qobject_cast< QAction* >( sender() );
299  const QString ident = action->data().toString();
300 
301  QSharedPointer<RetrievalOptions> opts = mRetrievalHash.value( ident );
302  opts->CheckOnStartup = checked;
303  slotEmitChanged();
304 }
305 
306 
307 void AccountsPageReceivingTab::slotIncludeInCheckChanged( bool checked )
308 {
309  QAction* action = qobject_cast< QAction* >( sender() );
310  const QString ident = action->data().toString();
311 
312  QSharedPointer<RetrievalOptions> opts = mRetrievalHash.value( ident );
313  opts->IncludeInManualChecks = checked;
314  slotEmitChanged();
315 }
316 
317 void AccountsPageReceivingTab::slotOfflineOnShutdownChanged( bool checked )
318 {
319  QAction* action = qobject_cast< QAction* >( sender() );
320  QString ident = action->data().toString();
321 
322  QSharedPointer<RetrievalOptions> opts = mRetrievalHash.value( ident );
323  opts->OfflineOnShutdown = checked;
324  slotEmitChanged();
325 }
326 
327 void AccountsPage::ReceivingTab::slotEditNotifications()
328 {
329  QDBusInterface interface( QLatin1String("org.freedesktop.Akonadi.Agent.akonadi_newmailnotifier_agent"), QLatin1String("/NewMailNotifierAgent") );
330  if (interface.isValid()) {
331  interface.call(QLatin1String("showConfigureDialog"), (qlonglong)winId());
332  } else {
333  KMessageBox::error(this, i18n("New Mail Notifier Agent not registered. Please contact your administrator."));
334  }
335 }
336 
337 void AccountsPage::ReceivingTab::doLoadFromGlobalSettings()
338 {
339  mAccountsReceiving.mVerboseNotificationCheck->setChecked( mNewMailNotifierInterface->verboseMailNotification() );
340 }
341 
342 void AccountsPage::ReceivingTab::doLoadOther()
343 {
344  mAccountsReceiving.mBeepNewMailCheck->setChecked( mNewMailNotifierInterface->beepOnNewMails() );
345 }
346 
347 void AccountsPage::ReceivingTab::save()
348 {
349  // Save Mail notification settings
350  mNewMailNotifierInterface->setBeepOnNewMails( mAccountsReceiving.mBeepNewMailCheck->isChecked() );
351  mNewMailNotifierInterface->setVerboseMailNotification( mAccountsReceiving.mVerboseNotificationCheck->isChecked() );
352 
353  const QString resourceGroupPattern( QLatin1String("Resource %1") );
354  QHashIterator<QString, QSharedPointer<RetrievalOptions> > it( mRetrievalHash );
355  while( it.hasNext() ) {
356  it.next();
357  KConfigGroup group;
358  KConfig *conf = 0;
359  if (KMKernel::self()) {
360  group = KConfigGroup( KMKernel::self()->config(), resourceGroupPattern.arg( it.key() ) );
361  } else {
362  conf = new KConfig(QLatin1String("kmail2rc"));
363  group = KConfigGroup( conf, resourceGroupPattern.arg( it.key() ) );
364  }
365  QSharedPointer<RetrievalOptions> opts = it.value();
366  group.writeEntry( "IncludeInManualChecks", opts->IncludeInManualChecks);
367  group.writeEntry( "OfflineOnShutdown", opts->OfflineOnShutdown);
368  group.writeEntry( "CheckOnStartup", opts->CheckOnStartup);
369  delete conf;
370  }
371 }
372 
globalsettings.h
QWidget
QHash::insert
iterator insert(const Key &key, const T &value)
ConfigModuleTab
Definition: configuredialog_p.h:19
QGridLayout::addWidget
void addWidget(QWidget *widget, int row, int column, QFlags< Qt::AlignmentFlag > alignment)
QHashIterator::key
const Key & key() const
QObject::sender
QObject * sender() const
QAction::setChecked
void setChecked(bool)
QHashIterator::hasNext
bool hasNext() const
QAction::data
QVariant data() const
QMenu::addAction
void addAction(QAction *action)
kmknotify.h
QDBusConnection::sessionBus
QDBusConnection sessionBus()
QGridLayout
QPoint
AccountsPageSendingTab::AccountsPageSendingTab
AccountsPageSendingTab(QWidget *parent=0)
Definition: configureaccountpage.cpp:86
AccountsPage::accountListChanged
void accountListChanged(const QStringList &)
KMKernel::self
static KMKernel * self()
normal control stuff
Definition: kmkernel.cpp:1471
QGridLayout::setSpacing
void setSpacing(int spacing)
ConfigAgentDelegate
A delegate for listing the accounts in the account list with kmail specific options.
Definition: configagentdelegate.h:35
AccountsPageReceivingTab::save
void save()
Definition: configureaccountpage.cpp:347
QLabel::setBuddy
void setBuddy(QWidget *buddy)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QWidget::setLayout
void setLayout(QLayout *layout)
QGroupBox
QSharedPointer
Definition: collectionmailinglistpage.h:34
AccountsPage::AccountsPage
AccountsPage(const KComponentData &instance, QWidget *parent=0)
Definition: configureaccountpage.cpp:59
QCheckBox
QHashIterator
AccountsPageSendingTab::~AccountsPageSendingTab
virtual ~AccountsPageSendingTab()
Definition: configureaccountpage.cpp:77
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
ConfigModuleTab::slotEmitChanged
void slotEmitChanged()
QVBoxLayout
AccountsPage::helpAnchor
QString helpAnchor() const
Should return the help anchor for this page or tab.
Definition: configureaccountpage.cpp:54
ConfigModuleWithTabs::addTab
void addTab(ConfigModuleTab *tab, const QString &title)
QWidget::winId
WId winId() const
QString
AccountsPageReceivingTab::~AccountsPageReceivingTab
~AccountsPageReceivingTab()
Definition: configureaccountpage.cpp:218
QLayout::setMargin
void setMargin(int margin)
AccountsPageReceivingTab::AccountsPageReceivingTab
AccountsPageReceivingTab(QWidget *parent=0)
Definition: configureaccountpage.cpp:180
QMenu::exec
QAction * exec()
QStringList
QDBusInterface
QAction::setData
void setData(const QVariant &userData)
QHash::clear
void clear()
QHash::value
const T value(const Key &key) const
QMenu
QHashIterator::next
Item next()
QAction::setCheckable
void setCheckable(bool)
GlobalSettings::self
static GlobalSettings * self()
Definition: globalsettings.cpp:30
kmkernel.h
configureaccountpage.h
QWidget::whatsThis
QString whatsThis() const
QLatin1String
QGridLayout::setColumnStretch
void setColumnStretch(int column, int stretch)
AccountsPageSendingTab::save
void save()
Definition: configureaccountpage.cpp:167
configagentdelegate.h
QAction
AccountsPageSendingTab::helpAnchor
QString helpAnchor() const
Definition: configureaccountpage.cpp:81
KComboBox
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QHash::contains
bool contains(const Key &key) const
ConfigModuleWithTabs
Definition: configuredialog_p.h:54
QHashIterator::value
const T & value() const
AccountsPage::ReceivingTab
AccountsPageReceivingTab ReceivingTab
Definition: configureaccountpage.h:102
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
AccountsPageReceivingTab::helpAnchor
QString helpAnchor() const
Definition: configureaccountpage.cpp:175
QLabel
AccountsPage::SendingTab
AccountsPageSendingTab SendingTab
Definition: configureaccountpage.h:101
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QVariant::toString
QString toString() const
QBoxLayout::setSpacing
void setSpacing(int spacing)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:32 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