28 #include "kernel/mailkernel.h"
30 #include "kdepim-version.h"
31 #include <kpimutils/email.h>
37 #include "mailcommon/mdn/sendmdnhandler.h"
38 #include <QVBoxLayout>
39 #include "messageviewer/header/headerstrategy.h"
40 #include "messageviewer/header/headerstyle.h"
41 #include "messageviewer/viewer/mailwebview.h"
42 #include "messageviewer/utils/markmessagereadhandler.h"
43 #include "messageviewer/settings/globalsettings.h"
44 #include "messageviewer/viewer/csshelper.h"
45 using MessageViewer::CSSHelper;
47 #include "utils/stringutil.h"
49 #include <kmime/kmime_mdn.h>
51 #include "messageviewer/viewer/viewer.h"
52 using namespace MessageViewer;
53 #include <messagecore/settings/globalsettings.h>
55 #include "messageviewer/viewer/attachmentstrategy.h"
56 #include "messagecomposer/sender/messagesender.h"
57 #include "messagecomposer/helper/messagefactory.h"
58 #include "messagecomposer/composer/composer.h"
59 #include "messagecomposer/part/textpart.h"
60 #include "messagecomposer/part/infopart.h"
62 #include <KIO/JobUiDelegate>
63 using MessageComposer::MessageFactory;
65 #include "messagecore/helpers/messagehelpers.h"
67 #include <Akonadi/Contact/ContactEditorDialog>
75 #include <ktoggleaction.h>
77 #include <KActionCollection>
78 #include <KMessageBox>
93 #include <util/mailutil.h>
95 using namespace KMail;
96 using namespace MailCommon;
101 KActionCollection* actionCollection,
102 Qt::WindowFlags aFlags )
104 mMainWindow( mainWindow ),
105 mActionCollection( actionCollection ),
106 mMailToComposeAction( 0 ),
107 mMailToReplyAction( 0 ),
108 mMailToForwardAction( 0 ),
109 mAddAddrBookAction( 0 ),
110 mOpenAddrBookAction( 0 ),
111 mUrlSaveAsAction( 0 ),
112 mAddBookmarksAction( 0 )
115 QVBoxLayout * vlay =
new QVBoxLayout(
this );
116 vlay->setMargin( 0 );
117 mViewer =
new Viewer(
this, mainWindow, mActionCollection );
118 mViewer->setExternalWindow(
true );
119 mViewer->setAppName( QLatin1String(
"KMail") );
120 connect( mViewer, SIGNAL(
urlClicked(Akonadi::Item,KUrl)),
122 connect( mViewer, SIGNAL(requestConfigSync()),
kmkernel, SLOT(slotRequestConfigSync()), Qt::QueuedConnection );
123 connect( mViewer, SIGNAL(makeResourceOnline(MessageViewer::Viewer::ResourceOnlineMode)),
kmkernel, SLOT(makeResourceOnline(MessageViewer::Viewer::ResourceOnlineMode)));
124 connect( mViewer, SIGNAL(showReader(KMime::Content*,
bool,QString)),
126 connect( mViewer, SIGNAL(showMessage(KMime::Message::Ptr,QString)),
130 connect( mViewer, SIGNAL(deleteMessage(Akonadi::Item)),
133 mViewer->addMessageLoadedHandler(
new MessageViewer::MarkMessageReadHandler(
this ) );
134 mViewer->addMessageLoadedHandler(
new MailCommon::SendMdnHandler(
kmkernel,
this ) );
136 vlay->addWidget( mViewer );
141 void KMReaderWin::createActions()
143 KActionCollection *ac = mActionCollection;
151 mMailToComposeAction =
new KAction( KIcon( QLatin1String(
"mail-message-new") ),
152 i18n(
"New Message To..." ),
this );
153 ac->addAction(QLatin1String(
"mail_new"), mMailToComposeAction );
154 mMailToComposeAction->setShortcutConfigurable(
false );
155 connect( mMailToComposeAction, SIGNAL(triggered(
bool)),
159 mMailToReplyAction =
new KAction( KIcon( QLatin1String(
"mail-reply-sender") ),
160 i18n(
"Reply To..." ),
this );
161 ac->addAction( QLatin1String(
"mailto_reply"), mMailToReplyAction );
162 mMailToReplyAction->setShortcutConfigurable(
false );
163 connect( mMailToReplyAction, SIGNAL(triggered(
bool)),
167 mMailToForwardAction =
new KAction( KIcon( QLatin1String(
"mail-forward" )),
168 i18n(
"Forward To..." ),
this );
169 mMailToForwardAction->setShortcutConfigurable(
false );
170 ac->addAction( QLatin1String(
"mailto_forward"), mMailToForwardAction );
171 connect( mMailToForwardAction, SIGNAL(triggered(
bool)),
176 mAddAddrBookAction =
new KAction( KIcon(QLatin1String(
"contact-new") ),
177 i18n(
"Add to Address Book" ),
this );
178 mAddAddrBookAction->setShortcutConfigurable(
false );
179 ac->addAction( QLatin1String(
"add_addr_book"), mAddAddrBookAction );
180 connect( mAddAddrBookAction, SIGNAL(triggered(
bool)),
184 mOpenAddrBookAction =
new KAction( KIcon( QLatin1String(
"view-pim-contacts") ),
185 i18n(
"Open in Address Book" ),
this );
186 mOpenAddrBookAction->setShortcutConfigurable(
false );
187 ac->addAction( QLatin1String(
"openin_addr_book"), mOpenAddrBookAction );
188 connect( mOpenAddrBookAction, SIGNAL(triggered(
bool)),
191 mAddBookmarksAction =
new KAction( KIcon( QLatin1String(
"bookmark-new") ), i18n(
"Bookmark This Link" ),
this );
192 mAddBookmarksAction->setShortcutConfigurable(
false );
193 ac->addAction( QLatin1String(
"add_bookmarks"), mAddBookmarksAction );
194 connect( mAddBookmarksAction, SIGNAL(triggered(
bool)),
197 mEditContactAction =
new KAction( KIcon( QLatin1String(
"view-pim-contacts") ),
198 i18n(
"Edit contact..." ),
this );
199 mEditContactAction->setShortcutConfigurable(
false );
200 ac->addAction( QLatin1String(
"edit_contact"), mOpenAddrBookAction );
201 connect( mEditContactAction, SIGNAL(triggered(
bool)),
205 mUrlSaveAsAction =
new KAction( i18n(
"Save Link As..." ),
this );
206 ac->addAction( QLatin1String(
"saveas_url"), mUrlSaveAsAction );
207 mUrlSaveAsAction->setShortcutConfigurable(
false );
208 connect( mUrlSaveAsAction, SIGNAL(triggered(
bool)), SLOT(
slotUrlSave()) );
211 KAction *action =
new KAction(KIcon(QLatin1String(
"edit-find")), i18n(
"&Find in Message..."),
this);
212 ac->addAction(QLatin1String(
"find_in_messages"), action );
213 connect(action, SIGNAL(triggered(
bool)), SLOT(
slotFind()));
214 action->setShortcut(KStandardShortcut::find());
217 mImageUrlSaveAsAction =
new KAction( i18n(
"Save Image On Disk..." ),
this );
218 ac->addAction( QLatin1String(
"saveas_imageurl"), mImageUrlSaveAsAction );
219 mImageUrlSaveAsAction->setShortcutConfigurable(
false );
223 mViewHtmlOptions =
new KMenu(i18n(
"Show HTML Format"));
224 mViewAsHtml =
new KAction( i18n(
"Show HTML format when mail comes from this contact"), mViewHtmlOptions);
225 mViewAsHtml->setShortcutConfigurable(
false );
227 mViewAsHtml->setCheckable(
true);
228 mViewHtmlOptions->addAction(mViewAsHtml);
230 mLoadExternalReference =
new KAction( i18n(
"Load external reference when mail comes for this contact"), mViewHtmlOptions);
231 mLoadExternalReference->setShortcutConfigurable(
false );
233 mLoadExternalReference->setCheckable(
true);
234 mViewHtmlOptions->addAction(mLoadExternalReference);
237 mShareImage =
new KAction(i18n(
"Share image..."),
this);
238 ac->addAction( QLatin1String(
"share_imageurl"), mShareImage );
239 mShareImage->setShortcutConfigurable(
false );
240 connect(mShareImage, SIGNAL(triggered(
bool)), SLOT(
slotShareImage()));
247 mViewer->setUseFixedFont( useFixedFont );
252 return mViewer->isFixedFont();
264 mViewer->readConfig();
268 mViewer->setAttachmentStrategy( strategy );
272 HeaderStrategy * strategy ) {
273 mViewer->setHeaderStyleAndStrategy( style, strategy );
278 mViewer->setOverrideEncoding( encoding );
289 I18N_NOOP(
"KMail is now based on the Akonadi Personal Information Management framework, which brings many "
290 "changes all around.")
300 I18N_NOOP(
"Push email (IMAP IDLE)" ),
301 I18N_NOOP(
"Improved virtual folders" ),
302 I18N_NOOP(
"Improved searches" ),
303 I18N_NOOP(
"Support for adding notes (annotations) to mails" ),
304 I18N_NOOP(
"Tag folders" ),
305 I18N_NOOP(
"Less GUI freezes, mail checks happen in the background" )
321 return QLatin1String(md5.base64Digest());
327 mViewer->displaySplashPage( info );
333 i18n(
"<h2 style='margin-top: 0px;'>Retrieving Folder Contents</h2><p>Please wait . . .</p> " );
341 i18n(
"<h2 style='margin-top: 0px;'>Offline</h2><p>KMail is currently in offline mode. "
342 "Click <a href=\"kmail:goOnline\">here</a> to go online . . .</p> " );
350 i18n(
"<h2 style='margin-top: 0px;'>Offline</h2><p>Account is currently in offline mode. "
351 "Click <a href=\"kmail:goResourceOnline\">here</a> to go online . . .</p> " );
360 KLocalizedString info =
361 ki18nc(
"%1: KMail version; %2: help:// URL; "
362 "%3: generated list of new features; "
363 "%4: First-time user text (only shown on first start); "
364 "%5: generated list of important changes; "
365 "--- end of comment ---",
366 "<h2 style='margin-top: 0px;'>Welcome to KMail %1</h2><p>KMail is the email client by KDE. "
367 "It is designed to be fully compatible with "
368 "Internet mailing standards including MIME, SMTP, POP3, and IMAP."
370 "<ul><li>KMail has many powerful features which are described in the "
371 "<a href=\"%2\">documentation</a></li>\n"
375 "<p>We hope that you will enjoy KMail.</p>\n"
376 "<p>Thank you,</p>\n"
377 "<p style='margin-bottom: 0px'> The KMail Team</p>")
378 .subs( QLatin1String(KDEPIM_VERSION) )
379 .subs( QLatin1String(
"help:/kmail/index.html") );
382 QString featuresText =
383 i18n(
"<p>Some of the new features in this release of KMail include "
384 "(compared to KMail %1, which is part of KDE Software Compilation %2):</p>\n",
385 QLatin1String(
"1.13"), QLatin1String(KDE::versionString()) );
386 featuresText += QLatin1String(
"<ul>\n");
388 featuresText += QLatin1String(
"<li>") + i18n(
kmailNewFeatures[i] ) + QLatin1String(
"</li>\n");
389 featuresText += QLatin1String(
"</ul>\n");
390 info = info.subs( featuresText );
393 info = info.subs( QString() );
396 info = info.subs( i18n(
"<p>Please take a moment to fill in the KMail "
397 "configuration panel at Settings->Configure "
399 "You need to create at least a default identity and "
400 "an incoming as well as outgoing mail account."
403 info = info.subs( QString() );
407 QString changesText =
408 i18n(
"<p><span style='font-size:125%; font-weight:bold;'>"
409 "Important changes</span> (compared to KMail %1):</p>\n",
410 QLatin1String(
"1.13"));
411 changesText += QLatin1String(
"<ul>\n");
413 changesText += i18n(
"<li>%1</li>\n", i18n(
kmailChanges[i] ) );
414 changesText += QLatin1String(
"</ul>\n");
415 info = info.subs( changesText );
418 info = info.subs( QString() );
431 QString selection = mViewer->selectedText();
432 selection.replace( QChar::Nbsp, QLatin1Char(
' ') );
433 QApplication::clipboard()->setText( selection );
439 mViewer->setMessagePart( aMsgPart );
445 return mViewer->selectedText();
451 mViewer->setHtmlOverride(
override );
456 return mViewer->htmlOverride();
462 mViewer->setHtmlLoadExtOverride(
override );
468 return mViewer->htmlMail();
474 return mViewer->htmlLoadExternal();
480 return mViewer->messageItem();
504 const QString emailString = KPIMUtils::decodeMailtoUrl( url );
516 const QString emailString = KPIMUtils::decodeMailtoUrl( url ).toLower();
561 return mViewer->cssHelper();
566 return mViewer->htmlLoadExtOverride();
570 mViewer->setDecryptMessageOverwrite( overwrite );
574 return mViewer->attachmentStrategy();
579 return mViewer->overrideEncoding();
584 return mViewer->toggleFixFontAction();
589 return mViewer->toggleMimePartTreeAction();
594 return mViewer->selectAllAction();
599 return mViewer->headerStrategy();
604 return mViewer->headerStyle();
609 return mViewer->copyURLAction();
614 return mViewer->copyImageLocation();
619 return mViewer->copyAction();
624 return mViewer->viewSourceAction();
629 return mViewer->saveAsAction();
634 return mViewer->findInMessageAction();
639 return mViewer->urlOpenAction();
643 mViewer->setPrinting( enable );
648 return mViewer->speakTextAction();
653 return mImageUrlSaveAsAction;
658 return mViewer->translateAction();
663 mViewer->clear( force ? Viewer::Force : Viewer::Delayed );
668 kDebug() << Q_FUNC_INFO << parentWidget();
669 mViewer->setMessageItem( item, updateMode );
674 mViewer->setMessage( message );
680 return mViewer->urlClicked();
685 return mViewer->imageUrlClicked();
690 mViewer->update( force ? Viewer::Force : Viewer::Delayed );
695 if ( item.isValid() && item.parentCollection().isValid() ) {
697 MailCommon::Util::updatedCollection( item.parentCollection() ),
false );
720 if ( !item.isValid() )
728 const QString str = mViewer->selectedText();
731 ::MessageComposer::Composer* composer = new ::MessageComposer::Composer;
732 composer->textPart()->setCleanPlainText(str);
733 composer->textPart()->setWrappedPlainText(str);
734 KMime::Message::Ptr messagePtr =
message().payload<KMime::Message::Ptr>();
735 composer->infoPart()->setFrom(messagePtr->from()->asUnicodeString());
736 composer->infoPart()->setTo(QStringList()<<messagePtr->to()->asUnicodeString());
737 composer->infoPart()->setCc(QStringList()<<messagePtr->cc()->asUnicodeString());
738 composer->infoPart()->setSubject(messagePtr->subject()->asUnicodeString());
739 composer->setProperty(
"preview",preview);
740 connect( composer, SIGNAL(result(
KJob*)),
748 const bool preview = job->property(
"preview").toBool();
749 Q_ASSERT( dynamic_cast< ::MessageComposer::Composer* >( job ) );
751 ::MessageComposer::Composer* composer =
dynamic_cast< ::MessageComposer::Composer*
>( job );
752 if( composer->error() == ::MessageComposer::Composer::NoError ) {
754 Q_ASSERT( composer->resultMessages().size() == 1 );
755 Akonadi::Item printItem;
756 printItem.setPayload<KMime::Message::Ptr>( composer->resultMessages().first() );
757 const bool useFixedFont = MessageViewer::GlobalSettings::self()->useFixedFont();
758 const QString
overrideEncoding = MessageCore::GlobalSettings::self()->overrideCharacterEncoding();
761 , mViewer->htmlOverride(), mViewer->htmlLoadExternal() ,useFixedFont,
overrideEncoding );
765 if ( static_cast<KIO::Job*>(job)->ui() ) {
766 static_cast<KIO::Job*
>(job)->ui()->showErrorMessage();
768 kWarning() <<
"Composer for printing failed:" << composer->errorString();
776 mSearchedContact = Akonadi::Item();
777 mSearchedAddress = KABC::Addressee();
778 mLoadExternalReference->setChecked(
false);
779 mViewAsHtml->setChecked(
false);
784 mSearchedContact = contact;
785 mSearchedAddress = address;
789 void KMReaderWin::updateHtmlActions()
791 if (!mSearchedContact.isValid()) {
792 mLoadExternalReference->setChecked(
false);
793 mViewAsHtml->setChecked(
false);
795 const QStringList customs = mSearchedAddress.customs();
796 Q_FOREACH (
const QString& custom, customs ) {
797 if ( custom.contains(QLatin1String(
"MailPreferedFormatting")) ) {
798 const QString value = mSearchedAddress.custom( QLatin1String(
"KADDRESSBOOK" ), QLatin1String(
"MailPreferedFormatting" ) );
799 mViewAsHtml->setChecked(value == QLatin1String(
"HTML" ));
800 }
else if ( custom.contains(QLatin1String(
"MailAllowToRemoteContent")) ) {
801 const QString value = mSearchedAddress.custom( QLatin1String(
"KADDRESSBOOK" ), QLatin1String(
"MailAllowToRemoteContent" ) );
802 mLoadExternalReference->setChecked(( value == QLatin1String(
"TRUE" ) ));
813 const QString emailString = KPIMUtils::decodeMailtoUrl( url ).toLower();
824 if( mSearchedContact.isValid() ) {
825 QPointer<Akonadi::ContactEditorDialog> dlg =
826 new Akonadi::ContactEditorDialog( Akonadi::ContactEditorDialog::EditMode,
this );
829 connect( dlg, SIGNAL(error(QString)),
831 dlg->setContact( mSearchedContact );
839 KMessageBox::error(
this, i18n(
"Contact cannot be stored: %1", error), i18n(
"Failed to store contact"));
850 return mViewer->saveMessageDisplayFormatAction();
855 return mViewer->resetMessageDisplayFormatAction();
860 return mViewer->blockImage();
865 return mViewer->adblockEnabled();
870 return mViewer->openBlockableItems();
882 return mViewer->isAShortUrl(url);
887 return mViewer->expandShortUrlAction();
890 #include "kmreaderwin.moc"
bool htmlOverride() const
Override default html mail setting.
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
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
void contactStored(const Akonadi::Item &item)
void setHeaderStyleAndStrategy(MessageViewer::HeaderStyle *style, MessageViewer::HeaderStrategy *strategy)
Set the header style and strategy.
MessageViewer::HeaderStyle * headerStyle() const
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
void update(bool force=false)
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 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)
void setHtmlOverride(bool override)
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.
KAction * resetMessageDisplayFormatAction() const
KAction * downloadImageToDiskAction() const
bool adblockEnabled() 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()
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 setShowAsHTML(bool html)
void slotUrlClicked(const Akonadi::Item &, const KUrl &)
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.
void slotShowReader(KMime::Content *, bool, const QString &)
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.