28 #include "kernel/mailkernel.h"
32 #include "kdepim-version.h"
33 #include <kpimutils/email.h>
39 #include "mailcommon/mdn/sendmdnhandler.h"
40 #include <QVBoxLayout>
41 #include "messageviewer/header/headerstrategy.h"
42 #include "messageviewer/header/headerstyle.h"
43 #include "messageviewer/viewer/mailwebview.h"
44 #include "messageviewer/utils/markmessagereadhandler.h"
45 #include "messageviewer/settings/globalsettings.h"
46 #include "messageviewer/viewer/csshelper.h"
47 using MessageViewer::CSSHelper;
49 #include "utils/stringutil.h"
51 #include <kmime/kmime_mdn.h>
52 #include <akonadi/kmime/messageflags.h>
54 #include "messageviewer/viewer/viewer.h"
55 using namespace MessageViewer;
56 #include <messagecore/settings/globalsettings.h>
58 #include "messageviewer/viewer/attachmentstrategy.h"
59 #include "messagecomposer/sender/messagesender.h"
60 #include "messagecomposer/helper/messagefactory.h"
61 #include "messagecomposer/composer/composer.h"
62 #include "messagecomposer/part/textpart.h"
63 #include "messagecomposer/part/infopart.h"
65 #include <KIO/JobUiDelegate>
66 using MessageComposer::MessageFactory;
68 #include "messagecore/helpers/messagehelpers.h"
70 #include <Akonadi/Contact/ContactEditorDialog>
78 #include <ktoggleaction.h>
80 #include <KActionCollection>
81 #include <KMessageBox>
96 #include <util/mailutil.h>
98 using namespace KMail;
99 using namespace MailCommon;
104 KActionCollection* actionCollection,
107 mMainWindow( mainWindow ),
108 mActionCollection( actionCollection ),
109 mMailToComposeAction( 0 ),
110 mMailToReplyAction( 0 ),
111 mMailToForwardAction( 0 ),
112 mAddAddrBookAction( 0 ),
113 mOpenAddrBookAction( 0 ),
114 mUrlSaveAsAction( 0 ),
115 mAddBookmarksAction( 0 ),
116 mAddEmailToExistingContactAction( 0 )
121 mViewer =
new Viewer(
this, mainWindow, mActionCollection );
122 mViewer->setExternalWindow(
true );
126 connect( mViewer, SIGNAL(requestConfigSync()),
kmkernel, SLOT(slotRequestConfigSync()), Qt::QueuedConnection );
127 connect( mViewer, SIGNAL(makeResourceOnline(MessageViewer::Viewer::ResourceOnlineMode)),
kmkernel, SLOT(makeResourceOnline(MessageViewer::Viewer::ResourceOnlineMode)));
128 connect( mViewer, SIGNAL(showReader(KMime::Content*,
bool,
QString)),
130 connect( mViewer, SIGNAL(showMessage(KMime::Message::Ptr,
QString)),
134 connect( mViewer, SIGNAL(deleteMessage(Akonadi::Item)),
137 mViewer->addMessageLoadedHandler(
new MessageViewer::MarkMessageReadHandler(
this ) );
138 mViewer->addMessageLoadedHandler(
new MailCommon::SendMdnHandler(
kmkernel,
this ) );
145 void KMReaderWin::createActions()
147 KActionCollection *ac = mActionCollection;
155 mMailToComposeAction =
new KAction( KIcon(
QLatin1String(
"mail-message-new") ),
156 i18n(
"New Message To..." ),
this );
157 ac->addAction(
QLatin1String(
"mail_new"), mMailToComposeAction );
158 mMailToComposeAction->setShortcutConfigurable(
false );
159 connect( mMailToComposeAction, SIGNAL(triggered(
bool)),
163 mMailToReplyAction =
new KAction( KIcon(
QLatin1String(
"mail-reply-sender") ),
164 i18n(
"Reply To..." ),
this );
165 ac->addAction(
QLatin1String(
"mailto_reply"), mMailToReplyAction );
166 mMailToReplyAction->setShortcutConfigurable(
false );
167 connect( mMailToReplyAction, SIGNAL(triggered(
bool)),
171 mMailToForwardAction =
new KAction( KIcon(
QLatin1String(
"mail-forward" )),
172 i18n(
"Forward To..." ),
this );
173 mMailToForwardAction->setShortcutConfigurable(
false );
174 ac->addAction(
QLatin1String(
"mailto_forward"), mMailToForwardAction );
175 connect( mMailToForwardAction, SIGNAL(triggered(
bool)),
180 mAddAddrBookAction =
new KAction( KIcon(
QLatin1String(
"contact-new") ),
181 i18n(
"Add to Address Book" ),
this );
182 mAddAddrBookAction->setShortcutConfigurable(
false );
183 ac->addAction(
QLatin1String(
"add_addr_book"), mAddAddrBookAction );
184 connect( mAddAddrBookAction, SIGNAL(triggered(
bool)),
187 mAddEmailToExistingContactAction =
new KAction( KIcon(
QLatin1String(
"contact-new") ),
188 i18n(
"Add to Existing Contact" ),
this );
189 mAddEmailToExistingContactAction->setShortcutConfigurable(
false );
190 ac->addAction(
QLatin1String(
"add_to_existing_contact"), mAddAddrBookAction );
191 connect( mAddEmailToExistingContactAction, SIGNAL(triggered(
bool)),
196 mOpenAddrBookAction =
new KAction( KIcon(
QLatin1String(
"view-pim-contacts") ),
197 i18n(
"Open in Address Book" ),
this );
198 mOpenAddrBookAction->setShortcutConfigurable(
false );
199 ac->addAction(
QLatin1String(
"openin_addr_book"), mOpenAddrBookAction );
200 connect( mOpenAddrBookAction, SIGNAL(triggered(
bool)),
203 mAddBookmarksAction =
new KAction( KIcon(
QLatin1String(
"bookmark-new") ), i18n(
"Bookmark This Link" ),
this );
204 mAddBookmarksAction->setShortcutConfigurable(
false );
205 ac->addAction(
QLatin1String(
"add_bookmarks"), mAddBookmarksAction );
206 connect( mAddBookmarksAction, SIGNAL(triggered(
bool)),
209 mEditContactAction =
new KAction( KIcon(
QLatin1String(
"view-pim-contacts") ),
210 i18n(
"Edit contact..." ),
this );
211 mEditContactAction->setShortcutConfigurable(
false );
212 ac->addAction(
QLatin1String(
"edit_contact"), mOpenAddrBookAction );
213 connect( mEditContactAction, SIGNAL(triggered(
bool)),
217 mUrlSaveAsAction =
new KAction( i18n(
"Save Link As..." ),
this );
218 ac->addAction(
QLatin1String(
"saveas_url"), mUrlSaveAsAction );
219 mUrlSaveAsAction->setShortcutConfigurable(
false );
223 KAction *action =
new KAction(KIcon(
QLatin1String(
"edit-find")), i18n(
"&Find in Message..."),
this);
226 action->setShortcut(KStandardShortcut::find());
229 mImageUrlSaveAsAction =
new KAction( i18n(
"Save Image On Disk..." ),
this );
230 ac->addAction(
QLatin1String(
"saveas_imageurl"), mImageUrlSaveAsAction );
231 mImageUrlSaveAsAction->setShortcutConfigurable(
false );
235 mViewHtmlOptions =
new KMenu(i18n(
"Show HTML Format"));
236 mViewAsHtml =
new KAction( i18n(
"Show HTML format when mail comes from this contact"), mViewHtmlOptions);
237 mViewAsHtml->setShortcutConfigurable(
false );
239 mViewAsHtml->setCheckable(
true);
240 mViewHtmlOptions->addAction(mViewAsHtml);
242 mLoadExternalReference =
new KAction( i18n(
"Load external reference when mail comes for this contact"), mViewHtmlOptions);
243 mLoadExternalReference->setShortcutConfigurable(
false );
245 mLoadExternalReference->setCheckable(
true);
246 mViewHtmlOptions->addAction(mLoadExternalReference);
249 mShareImage =
new KAction(i18n(
"Share image..."),
this);
250 ac->addAction(
QLatin1String(
"share_imageurl"), mShareImage );
251 mShareImage->setShortcutConfigurable(
false );
259 mViewer->setUseFixedFont( useFixedFont );
264 return mViewer->isFixedFont();
276 mViewer->readConfig();
280 mViewer->setAttachmentStrategy( strategy );
284 HeaderStrategy * strategy ) {
285 mViewer->setHeaderStyleAndStrategy( style, strategy );
290 mViewer->setOverrideEncoding( encoding );
301 I18N_NOOP(
"KMail is now based on the Akonadi Personal Information Management framework, which brings many "
302 "changes all around.")
312 I18N_NOOP(
"Push email (IMAP IDLE)" ),
313 I18N_NOOP(
"Improved virtual folders" ),
314 I18N_NOOP(
"Improved searches" ),
315 I18N_NOOP(
"Support for adding notes (annotations) to mails" ),
316 I18N_NOOP(
"Tag folders" ),
317 I18N_NOOP(
"Less GUI freezes, mail checks happen in the background" )
339 mViewer->displaySplashPage( info );
345 i18n(
"<h2 style='margin-top: 0px;'>Retrieving Folder Contents</h2><p>Please wait . . .</p> " );
353 i18n(
"<h2 style='margin-top: 0px;'>Offline</h2><p>KMail is currently in offline mode. "
354 "Click <a href=\"kmail:goOnline\">here</a> to go online . . .</p> " );
362 i18n(
"<h2 style='margin-top: 0px;'>Offline</h2><p>Account is currently in offline mode. "
363 "Click <a href=\"kmail:goResourceOnline\">here</a> to go online . . .</p> " );
372 KLocalizedString info =
373 ki18nc(
"%1: KMail version; %2: help:// URL; "
374 "%3: generated list of new features; "
375 "%4: First-time user text (only shown on first start); "
376 "%5: generated list of important changes; "
377 "--- end of comment ---",
378 "<h2 style='margin-top: 0px;'>Welcome to KMail %1</h2><p>KMail is the email client by KDE. "
379 "It is designed to be fully compatible with "
380 "Internet mailing standards including MIME, SMTP, POP3, and IMAP."
382 "<ul><li>KMail has many powerful features which are described in the "
383 "<a href=\"%2\">documentation</a></li>\n"
387 "<p>We hope that you will enjoy KMail.</p>\n"
388 "<p>Thank you,</p>\n"
389 "<p style='margin-bottom: 0px'> The KMail Team</p>")
395 i18n(
"<p>Some of the new features in this release of KMail include "
396 "(compared to KMail %1, which is part of KDE Software Compilation %2):</p>\n",
402 info = info.subs( featuresText );
408 info = info.subs( i18n(
"<p>Please take a moment to fill in the KMail "
409 "configuration panel at Settings->Configure "
411 "You need to create at least a default identity and "
412 "an incoming as well as outgoing mail account."
420 i18n(
"<p><span style='font-size:125%; font-weight:bold;'>"
421 "Important changes</span> (compared to KMail %1):</p>\n",
425 changesText += i18n(
"<li>%1</li>\n", i18n(
kmailChanges[i] ) );
427 info = info.subs( changesText );
443 QString selection = mViewer->selectedText();
451 mViewer->setMessagePart( aMsgPart );
457 return mViewer->selectedText();
463 return mViewer->displayFormatMessageOverwrite();
468 mViewer->setDisplayFormatMessageOverwrite(format);
475 mViewer->setHtmlLoadExtOverride(
override );
481 return mViewer->htmlMail();
487 return mViewer->htmlLoadExternal();
493 return mViewer->messageItem();
517 const QString emailString = KPIMUtils::decodeMailtoUrl( url );
528 const QString emailString = KPIMUtils::decodeMailtoUrl( url );
531 Akonadi::Item item = dlg->selectedContact();
532 if (item.isValid()) {
546 const QString emailString = KPIMUtils::decodeMailtoUrl( url ).
toLower();
591 return mViewer->cssHelper();
596 return mViewer->htmlLoadExtOverride();
600 mViewer->setDecryptMessageOverwrite( overwrite );
604 return mViewer->attachmentStrategy();
609 return mViewer->overrideEncoding();
614 return mViewer->toggleFixFontAction();
619 return mViewer->mimePartTreeIsEmpty();
624 return mViewer->toggleMimePartTreeAction();
629 return mViewer->selectAllAction();
634 return mViewer->headerStrategy();
639 return mViewer->headerStyle();
644 return mViewer->copyURLAction();
649 return mViewer->copyImageLocation();
654 return mViewer->copyAction();
659 return mViewer->viewSourceAction();
664 return mViewer->saveAsAction();
669 return mViewer->findInMessageAction();
674 return mViewer->urlOpenAction();
678 mViewer->setPrinting( enable );
683 return mViewer->speakTextAction();
688 return mImageUrlSaveAsAction;
693 return mViewer->translateAction();
698 mViewer->clear( force ? Viewer::Force : Viewer::Delayed );
704 mViewer->setMessageItem( item, updateMode );
709 mViewer->setMessage( message );
715 return mViewer->urlClicked();
720 return mViewer->imageUrlClicked();
725 mViewer->update( force ? Viewer::Force : Viewer::Delayed );
730 if ( item.isValid() && item.parentCollection().isValid() ) {
732 MailCommon::Util::updatedCollection( item.parentCollection() ),
false );
742 const MessageViewer::Viewer::DisplayFormatMessage format = html ? MessageViewer::Viewer::Html : MessageViewer::Viewer::Text;
756 if ( !item.isValid() )
764 const QString str = mViewer->selectedText();
767 ::MessageComposer::Composer* composer = new ::MessageComposer::Composer;
768 composer->textPart()->setCleanPlainText(str);
769 composer->textPart()->setWrappedPlainText(str);
770 KMime::Message::Ptr messagePtr =
message().payload<KMime::Message::Ptr>();
771 composer->infoPart()->setFrom(messagePtr->from()->asUnicodeString());
772 composer->infoPart()->setTo(
QStringList()<<messagePtr->to()->asUnicodeString());
773 composer->infoPart()->setCc(
QStringList()<<messagePtr->cc()->asUnicodeString());
774 composer->infoPart()->setSubject(messagePtr->subject()->asUnicodeString());
775 composer->setProperty(
"preview",preview);
784 const bool preview = job->property(
"preview").toBool();
785 Q_ASSERT( dynamic_cast< ::MessageComposer::Composer* >( job ) );
787 ::MessageComposer::Composer* composer =
dynamic_cast< ::MessageComposer::Composer*
>( job );
788 if( composer->error() == ::MessageComposer::Composer::NoError ) {
790 Q_ASSERT( composer->resultMessages().size() == 1 );
791 Akonadi::Item printItem;
792 printItem.setPayload<KMime::Message::Ptr>( composer->resultMessages().first() );
793 Akonadi::MessageFlags::copyMessageFlags(*(composer->resultMessages().first()), printItem);
794 const bool useFixedFont = MessageViewer::GlobalSettings::self()->useFixedFont();
798 , mViewer->displayFormatMessageOverwrite(), mViewer->htmlLoadExternal() ,useFixedFont,
overrideEncoding );
802 if ( static_cast<KIO::Job*>(job)->ui() ) {
803 static_cast<KIO::Job*
>(job)->ui()->showErrorMessage();
805 kWarning() <<
"Composer for printing failed:" << composer->errorString();
813 mSearchedContact = Akonadi::Item();
814 mSearchedAddress = KABC::Addressee();
815 mLoadExternalReference->setChecked(
false);
816 mViewAsHtml->setChecked(
false);
821 mSearchedContact = contact;
822 mSearchedAddress = address;
826 void KMReaderWin::updateHtmlActions()
828 if (!mSearchedContact.isValid()) {
829 mLoadExternalReference->setChecked(
false);
830 mViewAsHtml->setChecked(
false);
832 const QStringList customs = mSearchedAddress.customs();
833 Q_FOREACH (
const QString& custom, customs ) {
839 mLoadExternalReference->setChecked(( value ==
QLatin1String(
"TRUE" ) ));
850 const QString emailString = KPIMUtils::decodeMailtoUrl( url ).
toLower();
861 if( mSearchedContact.isValid() ) {
863 new Akonadi::ContactEditorDialog( Akonadi::ContactEditorDialog::EditMode,
this );
868 dlg->setContact( mSearchedContact );
876 KMessageBox::error(
this, i18n(
"Contact cannot be stored: %1", error), i18n(
"Failed to store contact"));
887 return mViewer->saveMessageDisplayFormatAction();
892 return mViewer->resetMessageDisplayFormatAction();
897 return mViewer->blockImage();
902 return mViewer->adblockEnabled();
907 return mViewer->openBlockableItems();
919 return mViewer->isAShortUrl(url);
924 return mViewer->expandShortUrlAction();
929 return mViewer->createTodoAction();
934 return mViewer->createEventAction();
static const char *const kmailChanges[]
const MessageViewer::HeaderStrategy * headerStrategy() const
Getthe message header strategy.
const MessageViewer::AttachmentStrategy * attachmentStrategy() const
Get/set the message attachment strategy.
void showMessage(const QString &encoding, const Akonadi::Item &msg, const Akonadi::Collection &parentCollection=Akonadi::Collection())
take ownership of and show
MessageViewer::Viewer::DisplayFormatMessage displayFormatMessageOverwrite() const
void slotPrintComposeResult(KJob *job)
void slotFind()
The user selected "Find" from the menu.
KAction * urlOpenAction() const
static BroadcastStatus * instance()
KAction * blockImage() const
KAction * copyURLAction() const
bool handleClickedURL(const KUrl &url, const QSharedPointer< MailCommon::FolderCollection > &folder=QSharedPointer< MailCommon::FolderCollection >())
Handles a clicked URL, but only in case the viewer didn't handle it.
void slotUrlSave()
Save the page to a file.
static const int numKMailNewFeatures
bool isAShortUrl(const KUrl &url) const
KAction * saveAsAction() const
KAction * createEventAction() const
void contactStored(const Akonadi::Item &item)
void setHeaderStyleAndStrategy(MessageViewer::HeaderStyle *style, MessageViewer::HeaderStrategy *strategy)
Set the header style and strategy.
MessageViewer::HeaderStyle * headerStyle() const
void slotShowReader(KMime::Content *, bool html, const QString &)
Akonadi::Item message() const
void displayResourceOfflinePage()
void setOverrideEncoding(const QString &encoding)
Set the override character encoding.
void setStatusMsg(const QString &message)
void setContactItem(const Akonadi::Item &contact, const KABC::Addressee &address)
virtual void setPrinting(bool enable)
MessageViewer::CSSHelper * cssHelper() const
KAction * expandShortUrlAction() const
KAction * copyImageLocation() const
KAction * createTodoAction() const
static const char *const kmailNewFeatures[]
Small helper structure which encapsulates the KMMessage created when creating a reply, and.
void setDecryptMessageOverwrite(bool overwrite=true)
Enforce message decryption.
void setDisplayFormatMessageOverwrite(MessageViewer::Viewer::DisplayFormatMessage format)
void slotMailtoAddAddrBook()
KMReaderWin(QWidget *parent, QWidget *mainWindow, KActionCollection *actionCollection, Qt::WindowFlags f=0)
KAction * viewSourceAction() const
KUrl imageUrlClicked() const
void setMsgPart(KMime::Content *aMsgPart)
Instead of settings a message to be shown sets a message part to be shown.
KAction * translateAction() const
void displayBusyPage()
Display the 'please wait' page instead of a message.
void setAttachmentStrategy(const MessageViewer::AttachmentStrategy *strategy)
static const int numKMailChanges
void setHtmlLoadExtOverride(bool override)
void setMessage(const Akonadi::Item &item, MessageViewer::Viewer::UpdateMode updateMode=MessageViewer::Viewer::Delayed)
bool htmlMail() const
Is html mail to be supported? Takes into account override.
void clear(bool force=false)
Clear the reader and discard the current message.
void slotSaveImageOnDisk()
void displayOfflinePage()
Display the 'we are currently in offline mode' page instead of a message.
void setMargin(int margin)
KAction * resetMessageDisplayFormatAction() const
KAction * downloadImageToDiskAction() const
bool adblockEnabled() const
bool contains(QChar ch, Qt::CaseSensitivity cs) const
void slotDeleteMessage(const Akonadi::Item &)
KAction * saveMessageDisplayFormatAction() const
KAction * copyAction() const
void setContact(const Akonadi::Item &contact)
void showStatusBarMessage(const QString &message)
static QString newFeaturesMD5()
Returns the MD5 hash for the list of new features.
void slotContactEditorError(const QString &error)
void slotContactHtmlOptions()
QString & replace(int position, int n, QChar after)
KToggleAction * toggleFixFontAction() const
void slotMailtoOpenAddrBook()
void slotMailtoReply()
Operations on mailto: URLs.
void setPrintPreview(bool preview)
QString copyText() const
Return selected text.
QString overrideEncoding() const
Get selected override character encoding.
bool htmlLoadExtOverride() const
Override default load external references setting.
KAction * openBlockableItems() const
KAction * findInMessageAction() const
bool htmlLoadExternal()
Is loading ext.
KAction * toggleMimePartTreeAction() const
void displayAboutPage()
Display the about page instead of a message.
bool printSelectedText(bool preview)
void setRemoteContent(bool b)
void slotMailToAddToExistingContact()
void setShowAsHTML(bool html)
void slotUrlClicked(const Akonadi::Item &, const KUrl &)
void setText(const QString &text, Mode mode)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void slotShowMessage(KMime::Message::Ptr message, const QString &encoding)
void setUseFixedFont(bool useFixedFont)
KAction * selectAllAction() const
void slotCopySelectedText()
Copy the selected text to the clipboard.
bool mimePartTreeIsEmpty() const
void displaySplashPage(const QString &info)
Display a generic HTML splash page instead of a message.
void clearCache()
Force update even if message is the same.
KAction * speakTextAction() const
void readConfig()
Read settings from app's config file.