• 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
  • filter
filteractionsetidentity.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
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  */
19 
20 #include "filteractionsetidentity.h"
21 #include "messagecore/utils/stringutil.h"
22 
23 #include "kernel/mailkernel.h"
24 #include "dialog/filteractionmissingargumentdialog.h"
25 
26 #include <KDE/KPIMIdentities/Identity>
27 #include <KDE/KPIMIdentities/IdentityCombo>
28 #include <KDE/KPIMIdentities/IdentityManager>
29 
30 #include <KDE/KLocale>
31 #include <QPointer>
32 
33 using namespace MailCommon;
34 
35 FilterAction* FilterActionSetIdentity::newAction()
36 {
37  return new FilterActionSetIdentity;
38 }
39 
40 FilterActionSetIdentity::FilterActionSetIdentity( QObject *parent )
41  : FilterActionWithUOID( QLatin1String("set identity"), i18n( "Set Identity To" ), parent )
42 {
43  mParameter = KernelIf->identityManager()->defaultIdentity().uoid();
44 }
45 
46 bool FilterActionSetIdentity::argsFromStringInteractive( const QString &argsStr, const QString &filterName )
47 {
48  bool needUpdate = false;
49  argsFromString( argsStr );
50  if ( KernelIf->identityManager()->identityForUoid( mParameter ).isNull() )
51  {
52  QPointer<FilterActionMissingIdentityDialog> dlg = new FilterActionMissingIdentityDialog( filterName );
53  if ( dlg->exec() ) {
54  mParameter = dlg->selectedIdentity();
55  needUpdate = true;
56  }
57  else
58  mParameter = -1;
59  delete dlg;
60  }
61  return needUpdate;
62 }
63 
64 FilterAction::ReturnCode FilterActionSetIdentity::process(ItemContext &context , bool applyOnOutbound) const
65 {
66  const KPIMIdentities::Identity & ident =
67  KernelIf->identityManager()->identityForUoid( mParameter );
68 
69  if ( ident.isNull() )
70  return ErrorButGoOn;
71 
72  const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
73  const uint currentId = msg->headerByType( "X-KMail-Identity" ) ? msg->headerByType( "X-KMail-Identity" )->asUnicodeString().trimmed().toUInt() : 0;
74  if (currentId != mParameter) {
75  KMime::Headers::Generic *header = new KMime::Headers::Generic( "X-KMail-Identity", msg.get(), QString::number( mParameter ), "utf-8" );
76  if (applyOnOutbound) {
77  msg->from()->fromUnicodeString( ident.fullEmailAddr(), "utf-8" );
78  if (!ident.bcc().isEmpty()) {
79  const KMime::Types::Mailbox::List mailboxes = MessageCore::StringUtil::mailboxListFromUnicodeString( ident.bcc() );
80  foreach ( const KMime::Types::Mailbox &mailbox, mailboxes )
81  msg->bcc()->addAddress( mailbox );
82  }
83  }
84  msg->setHeader( header );
85  msg->assemble();
86 
87  context.setNeedsPayloadStore();
88  }
89 
90  return GoOn;
91 }
92 
93 SearchRule::RequiredPart FilterActionSetIdentity::requiredPart() const
94 {
95  return SearchRule::CompleteMessage;
96 }
97 
98 
99 QWidget* FilterActionSetIdentity::createParamWidget( QWidget *parent ) const
100 {
101  KPIMIdentities::IdentityCombo *comboBox = new KPIMIdentities::IdentityCombo( KernelIf->identityManager(), parent );
102  comboBox->setCurrentIdentity( mParameter );
103 
104  connect( comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(filterActionModified()) );
105 
106  return comboBox;
107 }
108 
109 void FilterActionSetIdentity::applyParamWidgetValue( QWidget *paramWidget )
110 {
111  const KPIMIdentities::IdentityCombo *comboBox = dynamic_cast<KPIMIdentities::IdentityCombo*>( paramWidget );
112  Q_ASSERT( comboBox );
113 
114  mParameter = comboBox->currentIdentity();
115 }
116 
117 void FilterActionSetIdentity::clearParamWidget( QWidget *paramWidget ) const
118 {
119  KPIMIdentities::IdentityCombo *comboBox = dynamic_cast<KPIMIdentities::IdentityCombo*>( paramWidget );
120  Q_ASSERT( comboBox );
121 
122  comboBox->setCurrentIndex( 0 );
123 }
124 
125 void FilterActionSetIdentity::setParamWidgetValue( QWidget *paramWidget ) const
126 {
127  KPIMIdentities::IdentityCombo *comboBox = dynamic_cast<KPIMIdentities::IdentityCombo*>( paramWidget );
128  Q_ASSERT( comboBox );
129 
130  comboBox->setCurrentIdentity( mParameter );
131 }
132 
133 
134 
135 #include "filteractionsetidentity.moc"
MailCommon::FilterActionSetIdentity::applyParamWidgetValue
void applyParamWidgetValue(QWidget *parent)
The filter action shall set it's parameter from the widget's contents.
Definition: filteractionsetidentity.cpp:109
MailCommon::FilterActionSetIdentity::requiredPart
SearchRule::RequiredPart requiredPart() const
Returns the required part from the item that is needed for the action to operate. ...
Definition: filteractionsetidentity.cpp:93
MailCommon::FilterAction::GoOn
Go on with applying filter actions.
Definition: filteraction.h:62
KernelIf
#define KernelIf
Definition: mailkernel.h:186
MailCommon::FilterActionWithUOID::argsFromString
virtual void argsFromString(const QString &argsStr)
Read extra arguments from given string.
Definition: filteractionwithuoid.cpp:36
MailCommon::FilterActionWithUOID
Abstract base class for filter actions with a free-form string as parameter.
Definition: filteractionwithuoid.h:41
QWidget
MailCommon::ItemContext::setNeedsPayloadStore
void setNeedsPayloadStore()
Marks that the item's payload has been changed and needs to be written back.
Definition: itemcontext.cpp:45
filteractionmissingargumentdialog.h
QObject
MailCommon::SearchRule::CompleteMessage
Definition: searchpattern.h:107
MailCommon::FilterActionSetIdentity::setParamWidgetValue
void setParamWidgetValue(QWidget *parent) const
The filter action shall set it's widget's contents from it's parameter.
Definition: filteractionsetidentity.cpp:125
MailCommon::FilterAction
Abstract base class for mail filter actions.
Definition: filteraction.h:52
MailCommon::FilterActionSetIdentity::newAction
static FilterAction * newAction()
Definition: filteractionsetidentity.cpp:35
MailCommon::FilterActionSetIdentity::argsFromStringInteractive
bool argsFromStringInteractive(const QString &argsStr, const QString &filterName)
Read extra arguments from given string.
Definition: filteractionsetidentity.cpp:46
MailCommon::FilterAction::ErrorButGoOn
A non-critical error occurred.
Definition: filteraction.h:63
MailCommon::FilterActionSetIdentity::process
ReturnCode process(ItemContext &context, bool applyOnOutbound) const
Execute action on given message (inside the item context).
Definition: filteractionsetidentity.cpp:64
MailCommon::FilterActionSetIdentity::createParamWidget
QWidget * createParamWidget(QWidget *parent) const
Creates a widget for setting the filter action parameter.
Definition: filteractionsetidentity.cpp:99
MailCommon::FilterActionSetIdentity::clearParamWidget
void clearParamWidget(QWidget *param) const
The filter action shall clear it's parameter widget's contents.
Definition: filteractionsetidentity.cpp:117
MailCommon::SearchRule::RequiredPart
RequiredPart
Definition: searchpattern.h:104
MailCommon::FilterActionWithUOID::mParameter
uint mParameter
Definition: filteractionwithuoid.h:72
MailCommon::FilterAction::ReturnCode
ReturnCode
Describes the possible return codes of filter processing:
Definition: filteraction.h:60
MailCommon::ItemContext::item
Akonadi::Item & item()
Returns the item of the context.
Definition: itemcontext.cpp:30
mailkernel.h
FilterActionMissingIdentityDialog
Definition: filteractionmissingargumentdialog.h:84
MailCommon::FilterAction::filterActionModified
void filterActionModified()
Called to notify that the current FilterAction has had some value modification.
context
const char * context
Definition: searchpatternedit.cpp:54
MailCommon::ItemContext
A helper class for the filtering process.
Definition: itemcontext.h:39
MailCommon::FilterActionSetIdentity::FilterActionSetIdentity
FilterActionSetIdentity(QObject *parent=0)
Definition: filteractionsetidentity.cpp:40
filteractionsetidentity.h
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