diff --git a/kmail/kmkernel.cpp b/kmail/kmkernel.cpp index 6270a607ab..c8da600e7d 100644 --- a/kmail/kmkernel.cpp +++ b/kmail/kmkernel.cpp @@ -1,2130 +1,2130 @@ /* -*- mode: C++; c-file-style: "gnu" -*- */ #include "kmkernel.h" #include "settings/globalsettings.h" #include "misc/broadcaststatus.h" using KPIM::BroadcastStatus; #include "kmstartup.h" #include "kmmainwin.h" #include "editor/composer.h" #include "kmreadermainwin.h" #include "undostack.h" #include #include "kmreaderwin.h" #include "kmmainwidget.h" #include "addressline/recentaddresses.h" using KPIM::RecentAddresses; #include "configuredialog/configuredialog.h" #include "kmcommands.h" #include "kmsystemtray.h" #include "utils/stringutil.h" #include "util/mailutil.h" #include "mailcommon/pop3settings.h" #include "mailcommon/folder/foldertreeview.h" #include "mailcommon/filter/kmfilterdialog.h" #include "mailcommon/mailcommonsettings_base.h" #include "pimcommon/util/pimutil.h" #include "folderarchive/folderarchivemanager.h" #include "pimcommon/storageservice/storageservicemanager.h" #include "pimcommon/storageservice/storageservicejobconfig.h" #include "storageservice/storageservicesettingsjob.h" // kdepim includes #include "kdepim-version.h" // kdepimlibs includes #include #include #include #include #include #include #include #include #include "mailserviceimpl.h" using KMail::MailServiceImpl; #include "job/jobscheduler.h" #include "messagecore/settings/globalsettings.h" #include "messagelist/core/settings.h" #include "messagelist/messagelistutil.h" #include "messageviewer/settings/globalsettings.h" #include "messagecomposer/sender/akonadisender.h" #include "settings/messagecomposersettings.h" #include "messagecomposer/helper/messagehelper.h" #include "messagecomposer/settings/messagecomposersettings.h" #include "pimcommon/settings/pimcommonsettings.h" #include "pimcommon/autocorrection/autocorrection.h" #include "templateparser/templateparser.h" #include "templateparser/globalsettings_base.h" #include "templateparser/templatesutil.h" #include "foldercollection.h" #include "editor/codecmanager.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kmailinterface.h" #include "foldercollectionmonitor.h" #include "imapresourcesettings.h" #include "util.h" #include "mailcommon/kernel/mailkernel.h" #include "searchdialog/searchdescriptionattribute.h" using namespace MailCommon; static KMKernel * mySelf = 0; static bool s_askingToGoOnline = false; /********************************************************************/ /* Constructor and destructor */ /********************************************************************/ KMKernel::KMKernel (QObject *parent) : QObject(parent), mIdentityManager(0), mConfigureDialog(0), mMailService(0), mSystemNetworkStatus ( Solid::Networking::status() ), mSystemTray(0) { Akonadi::AttributeFactory::registerAttribute(); QDBusConnection::sessionBus().registerService(QLatin1String("org.kde.kmail")); KMail::Util::migrateFromKMail1(); kDebug() << "Starting up..."; mySelf = this; the_startingUp = true; the_firstInstance = true; the_undoStack = 0; the_msgSender = 0; mFilterEditDialog = 0; mWin = 0; mWrapCol = 80; // make sure that we check for config updates before doing anything else KMKernel::config(); // this shares the kmailrc parsing too (via KSharedConfig), and reads values from it // so better do it here, than in some code where changing the group of config() // would be unexpected GlobalSettings::self(); mJobScheduler = new JobScheduler( this ); mXmlGuiInstance = KComponentData(); mAutoCorrection = new PimCommon::AutoCorrection(); KMime::setFallbackCharEncoding( MessageCore::GlobalSettings::self()->fallbackCharacterEncoding() ); KMime::setUseOutlookAttachmentEncoding( MessageComposer::MessageComposerSettings::self()->outlookCompatibleAttachments() ); // cberzan: this crap moved to CodecManager ====================== netCodec = QTextCodec::codecForName( KGlobal::locale()->encoding() ); // In the case of Japan. Japanese locale name is "eucjp" but // The Japanese mail systems normally used "iso-2022-jp" of locale name. // We want to change locale name from eucjp to iso-2022-jp at KMail only. // (Introduction to i18n, 6.6 Limit of Locale technology): // EUC-JP is the de-facto standard for UNIX systems, ISO 2022-JP // is the standard for Internet, and Shift-JIS is the encoding // for Windows and Macintosh. if ( netCodec->name().toLower() == "eucjp" #if defined Q_WS_WIN || defined Q_WS_MACX || netCodec->name().toLower() == "shift-jis" // OK? #endif ) { netCodec = QTextCodec::codecForName("jis7"); // QTextCodec *cdc = QTextCodec::codecForName("jis7"); // QTextCodec::setCodecForLocale(cdc); // KGlobal::locale()->setEncoding(cdc->mibEnum()); } // until here ================================================ Akonadi::Session *session = new Akonadi::Session( "KMail Kernel ETM", this ); mFolderCollectionMonitor = new FolderCollectionMonitor( session, this ); connect( mFolderCollectionMonitor->monitor(), SIGNAL(collectionRemoved(Akonadi::Collection)), SLOT(slotCollectionRemoved(Akonadi::Collection))); mEntityTreeModel = new Akonadi::EntityTreeModel( folderCollectionMonitor(), this ); mEntityTreeModel->setIncludeUnsubscribed( false ); mEntityTreeModel->setItemPopulationStrategy( Akonadi::EntityTreeModel::LazyPopulation ); mCollectionModel = new Akonadi::EntityMimeTypeFilterModel( this ); mCollectionModel->setSourceModel( mEntityTreeModel ); mCollectionModel->addMimeTypeInclusionFilter( Akonadi::Collection::mimeType() ); mCollectionModel->setHeaderGroup( Akonadi::EntityTreeModel::CollectionTreeHeaders ); mCollectionModel->setDynamicSortFilter( true ); mCollectionModel->setSortCaseSensitivity( Qt::CaseInsensitive ); connect( folderCollectionMonitor(), SIGNAL(collectionChanged(Akonadi::Collection,QSet)), SLOT(slotCollectionChanged(Akonadi::Collection,QSet)) ); connect( MailTransport::TransportManager::self(), SIGNAL(transportRemoved(int,QString)), SLOT(transportRemoved(int,QString)) ); connect( MailTransport::TransportManager::self(), SIGNAL(transportRenamed(int,QString,QString)), SLOT(transportRenamed(int,QString,QString)) ); QDBusConnection::sessionBus().connect(QString(), QLatin1String( "/MailDispatcherAgent" ), QLatin1String("org.freedesktop.Akonadi.MailDispatcherAgent"), QLatin1String("itemDispatchStarted"),this, SLOT(itemDispatchStarted()) ); connect( Akonadi::AgentManager::self(), SIGNAL(instanceStatusChanged(Akonadi::AgentInstance)), this, SLOT(instanceStatusChanged(Akonadi::AgentInstance)) ); connect( Akonadi::AgentManager::self(), SIGNAL(instanceError(Akonadi::AgentInstance,QString)), this, SLOT(slotInstanceError(Akonadi::AgentInstance,QString)) ); connect( Akonadi::AgentManager::self(), SIGNAL(instanceWarning(Akonadi::AgentInstance,QString)), SLOT(slotInstanceWarning(Akonadi::AgentInstance,QString)) ); connect( Akonadi::AgentManager::self(), SIGNAL(instanceRemoved(Akonadi::AgentInstance)), this, SLOT(slotInstanceRemoved(Akonadi::AgentInstance)) ); connect ( Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status)), this, SLOT(slotSystemNetworkStatusChanged(Solid::Networking::Status)) ); connect( KPIM::ProgressManager::instance(), SIGNAL(progressItemCompleted(KPIM::ProgressItem*)), this, SLOT(slotProgressItemCompletedOrCanceled(KPIM::ProgressItem*)) ); connect( KPIM::ProgressManager::instance(), SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), this, SLOT(slotProgressItemCompletedOrCanceled(KPIM::ProgressItem*)) ); connect( identityManager(), SIGNAL(deleted(uint)), this, SLOT(slotDeleteIdentity(uint)) ); CommonKernel->registerKernelIf( this ); CommonKernel->registerSettingsIf( this ); CommonKernel->registerFilterIf( this ); mFolderArchiveManager = new FolderArchiveManager(this); mStorageManager = new PimCommon::StorageServiceManager(this); StorageServiceSettingsJob *settingsJob = new StorageServiceSettingsJob(this); PimCommon::StorageServiceJobConfig *configJob = PimCommon::StorageServiceJobConfig::self(); configJob->registerConfigIf(settingsJob); } KMKernel::~KMKernel () { delete mMailService; mMailService = 0; mSystemTray = 0; stopAgentInstance(); slotSyncConfig(); delete mAutoCorrection; mySelf = 0; kDebug(); } Akonadi::ChangeRecorder * KMKernel::folderCollectionMonitor() const { return mFolderCollectionMonitor->monitor(); } Akonadi::EntityTreeModel * KMKernel::entityTreeModel() const { return mEntityTreeModel; } Akonadi::EntityMimeTypeFilterModel * KMKernel::collectionModel() const { return mCollectionModel; } void KMKernel::setupDBus() { (void) new KmailAdaptor( this ); QDBusConnection::sessionBus().registerObject( QLatin1String("/KMail"), this ); mMailService = new MailServiceImpl(); } static KUrl makeAbsoluteUrl( const QString& str ) { KUrl url( str ); if ( url.protocol().isEmpty() ) { const QString newUrl = KCmdLineArgs::cwd() + QLatin1Char('/') + url.fileName(); return KUrl( newUrl ); } else { return url; } } bool KMKernel::handleCommandLine( bool noArgsOpensReader ) { QString to, cc, bcc, subj, body, inReplyTo, replyTo; QStringList customHeaders; KUrl messageFile; KUrl::List attachURLs; bool mailto = false; bool checkMail = false; bool viewOnly = false; bool calledWithSession = false; // for ignoring '-session foo' // process args: KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->isSet("subject")) { subj = args->getOption("subject"); // if kmail is called with 'kmail -session abc' then this doesn't mean // that the user wants to send a message with subject "ession" but // (most likely) that the user clicked on KMail's system tray applet // which results in KMKernel::raise() calling "kmail kmail newInstance" // via D-Bus which apparently executes the application with the original // command line arguments and those include "-session ..." if // kmail/kontact was restored by session management if ( subj == QLatin1String("ession") ) { subj.clear(); calledWithSession = true; } else mailto = true; } if (args->isSet("cc")) { mailto = true; cc = args->getOption("cc"); } if (args->isSet("bcc")) { mailto = true; bcc = args->getOption("bcc"); } if (args->isSet("replyTo")) { mailto = true; replyTo = args->getOption("replyTo"); } if (args->isSet("msg")) { mailto = true; const QString file = args->getOption("msg"); messageFile = makeAbsoluteUrl(file); } if (args->isSet("body")) { mailto = true; body = args->getOption("body"); } const QStringList attachList = args->getOptionList("attach"); if ( !attachList.isEmpty() ) { mailto = true; QStringList::ConstIterator end = attachList.constEnd(); for ( QStringList::ConstIterator it = attachList.constBegin(); it != end; ++it ) { if ( !(*it).isEmpty() ) { attachURLs.append( makeAbsoluteUrl( *it ) ); } } } customHeaders = args->getOptionList("header"); if (args->isSet("composer")) mailto = true; if (args->isSet("check")) checkMail = true; if ( args->isSet( "view" ) ) { viewOnly = true; const QString filename = args->getOption( "view" ); messageFile = KUrl( filename ); if ( !messageFile.isValid() ) { messageFile = KUrl(); messageFile.setPath( filename ); } } if ( !calledWithSession ) { // only read additional command line arguments if kmail/kontact is // not called with "-session foo" const int nbArgs = args->count(); for (int i= 0; i < nbArgs; ++i) { if ( args->arg(i).startsWith( QLatin1String( "mailto:" ), Qt::CaseInsensitive ) ) { QMap values = MessageCore::StringUtil::parseMailtoUrl( args->url( i ) ); if ( !values.value( QLatin1String("to") ).isEmpty() ) to += values.value( QLatin1String("to") ) + QLatin1String(", "); if ( !values.value( QLatin1String("cc") ).isEmpty() ) cc += values.value( QLatin1String("cc") ) + QLatin1String(", "); if ( !values.value( QLatin1String("subject") ).isEmpty() ) subj = values.value( QLatin1String("subject") ); if ( !values.value( QLatin1String("body") ).isEmpty() ) body = values.value(QLatin1String( "body") ); if ( !values.value( QLatin1String("in-reply-to") ).isEmpty() ) { inReplyTo = values.value( QLatin1String("in-reply-to") ); } const QString attach = values.value( QLatin1String("attachment") ); if ( !attach.isEmpty() ) { attachURLs << makeAbsoluteUrl( attach ); } } else { QString tmpArg = args->arg(i); KUrl url( tmpArg ); if (url.isValid() && !url.protocol().isEmpty()) attachURLs += url; else to += tmpArg + QLatin1String(", "); } mailto = true; } if ( !to.isEmpty() ) { // cut off the superfluous trailing ", " to.truncate( to.length() - 2 ); } } if ( !calledWithSession ) args->clear(); if ( !noArgsOpensReader && !mailto && !checkMail && !viewOnly ) return false; if ( viewOnly ) viewMessage( messageFile.url() ); else action( mailto, checkMail, to, cc, bcc, subj, body, messageFile, attachURLs, customHeaders, replyTo, inReplyTo ); return true; } /********************************************************************/ /* D-Bus-callable, and command line actions */ /********************************************************************/ void KMKernel::checkMail () //might create a new reader but won't show!! { if ( !kmkernel->askToGoOnline() ) return; const QString resourceGroupPattern( QLatin1String("Resource %1") ); const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances(); foreach( Akonadi::AgentInstance type, lst ) { const QString id = type.identifier(); KConfigGroup group( KMKernel::config(), resourceGroupPattern.arg( id ) ); if ( group.readEntry( "IncludeInManualChecks", true ) ) { if ( !type.isOnline() ) type.setIsOnline( true ); if ( mResourcesBeingChecked.isEmpty() ) { kDebug() << "Starting manual mail check"; emit startCheckMail(); } if ( !mResourcesBeingChecked.contains( id ) ) { mResourcesBeingChecked.append( id ); } type.synchronize(); } } } void KMKernel::setSystrayIconNotificationsEnabled( bool enabled ) { if ( mSystemTray ) { mSystemTray->setSystrayIconNotificationsEnabled( enabled ); } } QStringList KMKernel::accounts() { QStringList accountLst; const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances(); foreach ( const Akonadi::AgentInstance& type, lst ) { // Explicitly make a copy, as we're not changing values of the list but only // the local copy which is passed to action. accountLst<instance( account ); if ( agent.isValid() ) agent.synchronize(); else kDebug() << "- account with name '" << account <<"' not found"; } } void KMKernel::openReader( bool onlyCheck ) { mWin = 0; KMainWindow *ktmw = 0; kDebug(); foreach ( KMainWindow *window, KMainWindow::memberList() ) { if ( ::qobject_cast( window ) ) { ktmw = window; break; } } bool activate; if (ktmw) { mWin = static_cast(ktmw); activate = !onlyCheck; // existing window: only activate if not --check if ( activate ) mWin->show(); } else { mWin = new KMMainWin; mWin->show(); activate = false; // new window: no explicit activation (#73591) } if ( activate ) { // Activate window - doing this instead of KWindowSystem::activateWindow(mWin->winId()); // so that it also works when called from KMailApplication::newInstance() #if defined Q_WS_X11 && ! defined K_WS_QTONLY KStartupInfo::setNewStartupId( mWin, kapp->startupId() ); #endif } } int KMKernel::openComposer(const QString &to, const QString &cc, const QString &bcc, const QString &subject, const QString &body, bool hidden, const QString &messageFile, const QStringList &attachmentPaths, const QStringList &customHeaders, const QString &replyTo, const QString &inReplyTo) { kDebug(); KMail::Composer::TemplateContext context = KMail::Composer::New; KMime::Message::Ptr msg( new KMime::Message ); MessageHelper::initHeader( msg, identityManager() ); msg->contentType()->setCharset("utf-8"); if ( !to.isEmpty() ) msg->to()->fromUnicodeString( to, "utf-8" ); if ( !cc.isEmpty() ) msg->cc()->fromUnicodeString( cc, "utf-8" ); if ( !bcc.isEmpty() ) msg->bcc()->fromUnicodeString( bcc, "utf-8" ); if ( !subject.isEmpty() ) msg->subject()->fromUnicodeString( subject, "utf-8" ); KUrl messageUrl = KUrl( messageFile ); if ( !messageUrl.isEmpty() && messageUrl.isLocalFile() ) { const QByteArray str = KPIMUtils::kFileToByteArray( messageUrl.toLocalFile(), true, false ); if( !str.isEmpty() ) { context = KMail::Composer::NoTemplate; msg->setBody( QString::fromLocal8Bit( str.data(), str.size() ).toUtf8() ); } else { TemplateParser::TemplateParser parser( msg, TemplateParser::TemplateParser::NewMessage ); parser.setIdentityManager( KMKernel::self()->identityManager() ); parser.process( msg ); } } else if ( !body.isEmpty() ) { context = KMail::Composer::NoTemplate; msg->setBody( body.toUtf8() ); } else { TemplateParser::TemplateParser parser( msg, TemplateParser::TemplateParser::NewMessage ); parser.setIdentityManager( KMKernel::self()->identityManager() ); parser.process( msg ); } if (!inReplyTo.isEmpty()) { KMime::Headers::InReplyTo *header = new KMime::Headers::InReplyTo( msg.get(), inReplyTo, "utf-8" ); msg->setHeader( header ); } msg->assemble(); KMail::Composer * cWin = KMail::makeComposer( msg, false, false, context ); if (!to.isEmpty()) cWin->setFocusToSubject(); KUrl::List attachURLs = KUrl::List( attachmentPaths ); KUrl::List::ConstIterator endAttachment(attachURLs.constEnd()); for ( KUrl::List::ConstIterator it = attachURLs.constBegin() ; it != endAttachment; ++it ) { if( KMimeType::findByUrl( *it )->name() == QLatin1String( "inode/directory" ) ) { if(KMessageBox::questionYesNo(0, i18n("Do you want to attach this folder \"%1\"?",(*it).prettyUrl()), i18n("Attach Folder")) == KMessageBox::No ) { continue; } } cWin->addAttachment( (*it), QString() ); } if (!replyTo.isEmpty()) { cWin->setCurrentReplyTo(replyTo); } if (!customHeaders.isEmpty()) { QMap extraCustomHeaders; QStringList::ConstIterator end = customHeaders.constEnd(); for ( QStringList::ConstIterator it = customHeaders.constBegin() ; it != end ; ++it ) { if ( !(*it).isEmpty() ) { const int pos = (*it).indexOf( QLatin1Char(':') ); if ( pos > 0 ) { const QString header = (*it).left( pos ).trimmed(); const QString value = (*it).mid( pos+1 ).trimmed(); if ( !header.isEmpty() && !value.isEmpty() ) { extraCustomHeaders.insert(header.toUtf8(), value); } } } } if (!extraCustomHeaders.isEmpty()) cWin->addExtraCustomHeaders(extraCustomHeaders); } if ( !hidden ) { cWin->show(); // Activate window - doing this instead of KWindowSystem::activateWindow(cWin->winId()); // so that it also works when called from KMailApplication::newInstance() #if defined Q_WS_X11 && ! defined K_WS_QTONLY KStartupInfo::setNewStartupId( cWin, kapp->startupId() ); #endif } return 1; } int KMKernel::openComposer(const QString &to, const QString &cc, const QString &bcc, const QString &subject, const QString &body, bool hidden, const QString &attachName, const QByteArray &attachCte, const QByteArray &attachData, const QByteArray &attachType, const QByteArray &attachSubType, const QByteArray &attachParamAttr, const QString &attachParamValue, const QByteArray &attachContDisp, const QByteArray &attachCharset, unsigned int identity) { KMail::Composer *cWin; bool iCalAutoSend = fillComposer(cWin, to, cc, bcc, subject, body, attachName, attachCte, attachData, attachType, attachSubType, attachParamAttr, attachParamValue, attachContDisp, attachCharset, identity); if ( !hidden && !iCalAutoSend ) { cWin->show(); // Activate window - doing this instead of KWin::activateWindow(cWin->winId()); // so that it also works when called from KMailApplication::newInstance() #if defined Q_WS_X11 && ! defined K_WS_QTONLY KStartupInfo::setNewStartupId( cWin, kapp->startupId() ); #endif } else { // Always disable word wrap when we don't show the composer, since otherwise QTextEdit // gets the widget size wrong and wraps much too early. cWin->disableWordWrap(); cWin->slotSendNow(); } return 1; } int KMKernel::openComposer(const QString &to, const QString &cc, const QString &bcc, const QString &subject, const QString &body, const QString &attachName, const QByteArray &attachCte, const QByteArray &attachData, const QByteArray &attachType, const QByteArray &attachSubType, const QByteArray &attachParamAttr, const QString &attachParamValue, const QByteArray &attachContDisp, const QByteArray &attachCharset, unsigned int identity) { KMail::Composer *cWin; fillComposer(cWin, to, cc, bcc, subject, body, attachName, attachCte, attachData, attachType, attachSubType, attachParamAttr, attachParamValue, attachContDisp, attachCharset, identity); cWin->show(); // Activate window - doing this instead of KWin::activateWindow(cWin->winId()); // so that it also works when called from KMailApplication::newInstance() #if defined Q_WS_X11 && ! defined K_WS_QTONLY KStartupInfo::setNewStartupId( cWin, kapp->startupId() ); #endif return 1; } bool KMKernel::fillComposer (KMail::Composer *&cWin, const QString &to, const QString &cc, const QString &bcc, const QString &subject, const QString &body, const QString &attachName, const QByteArray &attachCte, const QByteArray &attachData, const QByteArray &attachType, const QByteArray &attachSubType, const QByteArray &attachParamAttr, const QString &attachParamValue, const QByteArray &attachContDisp, const QByteArray &attachCharset, unsigned int identity) { KMail::Composer::TemplateContext context = KMail::Composer::New; KMime::Message::Ptr msg( new KMime::Message ); KMime::Content *msgPart = 0; MessageHelper::initHeader( msg, identityManager() ); msg->contentType()->setCharset( "utf-8" ); if ( !cc.isEmpty() ) msg->cc()->fromUnicodeString( cc, "utf-8" ); if ( !bcc.isEmpty() ) msg->bcc()->fromUnicodeString( bcc, "utf-8" ); if ( !subject.isEmpty() ) msg->subject()->fromUnicodeString( subject, "utf-8" ); if ( !to.isEmpty() ) msg->to()->fromUnicodeString( to, "utf-8" ); if ( identity > 0 ) { KMime::Headers::Generic *h = new KMime::Headers::Generic("X-KMail-Identity", msg.get(), QByteArray::number( identity ) ); msg->setHeader( h ); } if ( !body.isEmpty() ) { msg->setBody(body.toUtf8()); } else { TemplateParser::TemplateParser parser( msg, TemplateParser::TemplateParser::NewMessage ); parser.setIdentityManager( KMKernel::self()->identityManager() ); parser.process( KMime::Message::Ptr() ); } bool iCalAutoSend = false; bool noWordWrap = false; bool isICalInvitation = false; if ( !attachData.isEmpty() ) { isICalInvitation = (attachName ==QLatin1String("cal.ics")) && attachType == "text" && attachSubType == "calendar" && attachParamAttr == "method"; // Remove BCC from identity on ical invitations (https://intevation.de/roundup/kolab/issue474) if ( isICalInvitation && bcc.isEmpty() ) msg->bcc()->clear(); if ( isICalInvitation && MessageViewer::GlobalSettings::self()->legacyBodyInvites() ) { // KOrganizer invitation caught and to be sent as body instead msg->setBody( attachData ); msg->contentType()->from7BitString( QString::fromLatin1("text/calendar; method=%1; " "charset=\"utf-8\"" ). arg( attachParamValue ).toLatin1() ); iCalAutoSend = true; // no point in editing raw ICAL noWordWrap = true; // we shant word wrap inline invitations } else { // Just do what we're told to do msgPart = new KMime::Content; msgPart->contentTransferEncoding()->fromUnicodeString(QLatin1String(attachCte), "utf-8" ); msgPart->setBody( attachData ); //TODO: check if was setBodyEncoded msgPart->contentType()->setMimeType( attachType + '/' + attachSubType ); msgPart->contentType()->setParameter( QLatin1String(attachParamAttr), attachParamValue ); //TODO: Check if the content disposition parameter needs to be set! if( ! MessageViewer::GlobalSettings::self()->exchangeCompatibleInvitations() ) { msgPart->contentDisposition()->fromUnicodeString(QLatin1String(attachContDisp), "utf-8" ); } if( !attachCharset.isEmpty() ) { // kDebug() << "Set attachCharset to" << attachCharset; msgPart->contentType()->setCharset( attachCharset ); } msgPart->contentType()->setName( attachName, "utf-8" ); msgPart->assemble(); // Don't show the composer window if the automatic sending is checked iCalAutoSend = MessageViewer::GlobalSettings::self()->automaticSending(); } } msg->assemble(); if (!msg->body().isEmpty()) { context = KMail::Composer::NoTemplate; } cWin = KMail::makeComposer( KMime::Message::Ptr(), false, false, context); cWin->setMessage( msg, false, false, !isICalInvitation /* mayAutoSign */ ); cWin->setSigningAndEncryptionDisabled( isICalInvitation && MessageViewer::GlobalSettings::self()->legacyBodyInvites() ); if ( noWordWrap ) cWin->disableWordWrap(); if ( msgPart ) cWin->addAttach( msgPart ); if ( isICalInvitation ) { cWin->disableWordWrap(); cWin->forceDisableHtml(); //cWin->disableRecipientNumberCheck(); cWin->disableForgottenAttachmentsCheck(); } return iCalAutoSend; } QDBusObjectPath KMKernel::openComposer( const QString &to, const QString &cc, const QString &bcc, const QString &subject, const QString &body, bool hidden ) { KMime::Message::Ptr msg( new KMime::Message ); MessageHelper::initHeader( msg, identityManager() ); msg->contentType()->setCharset("utf-8"); if ( !cc.isEmpty() ) msg->cc()->fromUnicodeString( cc, "utf-8" ); if ( !bcc.isEmpty() ) msg->bcc()->fromUnicodeString( bcc, "utf-8" ); if ( !subject.isEmpty() ) msg->subject()->fromUnicodeString( subject, "utf-8" ); if ( !to.isEmpty() ) msg->to()->fromUnicodeString( to, "utf-8" ); if ( !body.isEmpty() ) { msg->setBody( body.toUtf8() ); } else { TemplateParser::TemplateParser parser( msg, TemplateParser::TemplateParser::NewMessage ); parser.setIdentityManager( KMKernel::self()->identityManager() ); parser.process( KMime::Message::Ptr() ); } msg->assemble(); const KMail::Composer::TemplateContext context = body.isEmpty() ? KMail::Composer::New : KMail::Composer::NoTemplate; KMail::Composer * cWin = KMail::makeComposer( msg, false, false, context ); if ( !hidden ) { cWin->show(); // Activate window - doing this instead of KWindowSystem::activateWindow(cWin->winId()); // so that it also works when called from KMailApplication::newInstance() #if defined Q_WS_X11 && ! defined K_WS_QTONLY KStartupInfo::setNewStartupId( cWin, kapp->startupId() ); #endif } else { // Always disable word wrap when we don't show the composer; otherwise, // QTextEdit gets the widget size wrong and wraps much too early. cWin->disableWordWrap(); cWin->slotSendNow(); } return QDBusObjectPath(cWin->dbusObjectPath()); } QDBusObjectPath KMKernel::newMessage( const QString &to, const QString &cc, const QString &bcc, bool hidden, bool useFolderId, const QString & /*messageFile*/, const QString &_attachURL) { KUrl attachURL( _attachURL ); KMime::Message::Ptr msg( new KMime::Message ); QSharedPointer folder; uint id = 0; if ( useFolderId ) { //create message with required folder identity folder = currentFolderCollection(); id = folder ? folder->identity() : 0; } MessageHelper::initHeader( msg, identityManager(), id ); msg->contentType()->setCharset( "utf-8" ); //set basic headers if ( !cc.isEmpty() ) msg->cc()->fromUnicodeString( cc, "utf-8" ); if ( !bcc.isEmpty() ) msg->bcc()->fromUnicodeString( bcc, "utf-8" ); if ( !to.isEmpty() ) msg->to()->fromUnicodeString( to, "utf-8" ); msg->assemble(); TemplateParser::TemplateParser parser( msg, TemplateParser::TemplateParser::NewMessage ); parser.setIdentityManager( identityManager() ); Akonadi::Collection col = folder ? folder->collection() : Akonadi::Collection(); parser.process( msg, col ); KMail::Composer *win = makeComposer( msg, false, false, KMail::Composer::New, id ); win->setCollectionForNewMessage(col); //Add the attachment if we have one if ( !attachURL.isEmpty() && attachURL.isValid() ) { win->addAttachment( attachURL, QString() ); } //only show window when required if ( !hidden ) { win->show(); } return QDBusObjectPath( win->dbusObjectPath() ); } int KMKernel::viewMessage( const QString & messageFile ) { KMOpenMsgCommand *openCommand = new KMOpenMsgCommand( 0, KUrl( messageFile ) ); openCommand->start(); return 1; } void KMKernel::raise() { QDBusInterface iface( QLatin1String("org.kde.kmail"), QLatin1String("/MainApplication"), QLatin1String("org.kde.KUniqueApplication"), QDBusConnection::sessionBus()); QDBusReply reply; if ( !iface.isValid() || !( reply = iface.call( QLatin1String("newInstance") ) ).isValid() ) { QDBusError err = iface.lastError(); kError() << "Communication problem with KMail. " << "Error message was:" << err.name() << ": \"" << err.message() << "\""; } } bool KMKernel::showMail(qint64 serialNumber) { KMMainWidget *mainWidget = 0; // First look for a KMainWindow. foreach ( KMainWindow* window, KMainWindow::memberList() ) { // Then look for a KMMainWidget. QList l = window->findChildren(); if ( !l.isEmpty() && l.first() ) { mainWidget = l.first(); if ( window->isActiveWindow() ) break; } } if ( mainWidget ) { Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( Akonadi::Item(serialNumber ),this ); job->fetchScope().fetchFullPayload(); if ( job->exec() ) { if ( job->items().count() >= 1 ) { KMReaderMainWin *win = new KMReaderMainWin( false, false ); win->showMessage( MessageCore::GlobalSettings::self()->overrideCharacterEncoding(), job->items().at( 0 ) ); win->show(); return true; } } } return false; } void KMKernel::pauseBackgroundJobs() { mBackgroundTasksTimer->stop(); mJobScheduler->pause(); } void KMKernel::resumeBackgroundJobs() { mJobScheduler->resume(); mBackgroundTasksTimer->start( 4 * 60 * 60 * 1000 ); } void KMKernel::stopNetworkJobs() { if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Offline ) return; setAccountStatus(false); GlobalSettings::setNetworkState( GlobalSettings::EnumNetworkState::Offline ); BroadcastStatus::instance()->setStatusMsg( i18n("KMail is set to be offline; all network jobs are suspended")); emit onlineStatusChanged( (GlobalSettings::EnumNetworkState::type)GlobalSettings::networkState() ); } void KMKernel::setAccountStatus(bool goOnline) { const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances(false); foreach ( Akonadi::AgentInstance type, lst ) { const QString identifier( type.identifier() ); if ( identifier.contains( IMAP_RESOURCE_IDENTIFIER ) || identifier.contains( POP3_RESOURCE_IDENTIFIER ) || identifier.contains( KOLAB_RESOURCE_IDENTIFIER ) || identifier.contains( QLatin1String("akonadi_maildispatcher_agent") ) ) { type.setIsOnline( goOnline ); } } if ( goOnline && MessageComposer::MessageComposerSettings::self()->sendImmediate() ) { const qint64 nbMsgOutboxCollection = MailCommon::Util::updatedCollection( CommonKernel->outboxCollectionFolder() ).statistics().count(); if(nbMsgOutboxCollection > 0) { kmkernel->msgSender()->sendQueued(); } } } void KMKernel::resumeNetworkJobs() { if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Online ) return; if ( ( mSystemNetworkStatus == Solid::Networking::Connected ) || ( mSystemNetworkStatus == Solid::Networking::Unknown ) ) { setAccountStatus(true); BroadcastStatus::instance()->setStatusMsg( i18n("KMail is set to be online; all network jobs resumed")); } else { BroadcastStatus::instance()->setStatusMsg( i18n ( "KMail is set to be online; all network jobs will resume when a network connection is detected" ) ); } GlobalSettings::setNetworkState( GlobalSettings::EnumNetworkState::Online ); emit onlineStatusChanged( (GlobalSettings::EnumNetworkState::type)GlobalSettings::networkState() ); KMMainWidget *widget = getKMMainWidget(); if ( widget ) { widget->clearViewer(); } } bool KMKernel::isOffline() { Solid::Networking::Status networkStatus = Solid::Networking::status(); if ( ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Offline ) || ( networkStatus == Solid::Networking::Unconnected ) || ( networkStatus == Solid::Networking::Disconnecting ) || ( networkStatus == Solid::Networking::Connecting )) return true; else return false; } void KMKernel::checkMailOnStartup() { if ( !kmkernel->askToGoOnline() ) return; const QString resourceGroupPattern( QLatin1String("Resource %1") ); const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances(); foreach( Akonadi::AgentInstance type, lst ) { KConfigGroup group( KMKernel::config(), resourceGroupPattern.arg( type.identifier() ) ); if ( group.readEntry( "CheckOnStartup", false ) ) { if ( !type.isOnline() ) type.setIsOnline( true ); type.synchronize(); } // "false" is also hardcoded in ConfigureDialog, don't forget to change there. if ( group.readEntry( "OfflineOnShutdown", false ) ) { if ( !type.isOnline() ) type.setIsOnline( true ); } } } bool KMKernel::askToGoOnline() { // already asking means we are offline and need to wait anyhow if ( s_askingToGoOnline ) { return false; } if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Offline ) { s_askingToGoOnline = true; int rc = KMessageBox::questionYesNo( KMKernel::self()->mainWin(), i18n("KMail is currently in offline mode. " "How do you want to proceed?"), i18n("Online/Offline"), KGuiItem(i18n("Work Online")), KGuiItem(i18n("Work Offline"))); s_askingToGoOnline = false; if( rc == KMessageBox::No ) { return false; } else { kmkernel->resumeNetworkJobs(); } } if( kmkernel->isOffline() ) return false; return true; } void KMKernel::slotSystemNetworkStatusChanged( Solid::Networking::Status status ) { mSystemNetworkStatus = status; if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Offline ) return; if ( status == Solid::Networking::Connected || status == Solid::Networking::Unknown) { BroadcastStatus::instance()->setStatusMsg( i18n( "Network connection detected, all network jobs resumed") ); kmkernel->setAccountStatus( true ); } else { BroadcastStatus::instance()->setStatusMsg( i18n( "No network connection detected, all network jobs are suspended")); kmkernel->setAccountStatus( false ); } } /********************************************************************/ /* Kernel methods */ /********************************************************************/ void KMKernel::quit() { // Called when all windows are closed. Will take care of compacting, // sending... should handle session management too!! } /* TODO later: Asuming that: - msgsender is nonblocking (our own, QSocketNotifier based. Pops up errors and sends signal senderFinished when done) o If we are getting mail, stop it (but don't lose something!) [Done already, see mailCheckAborted] o If we are sending mail, go on UNLESS this was called by SM, in which case stop ASAP that too (can we warn? should we continue on next start?) o If we are compacting, or expunging, go on UNLESS this was SM call. In that case stop compacting ASAP and continue on next start, before touching any folders. [Not needed anymore with CompactionJob] KMKernel::quit () { SM call? if compacting, stop; if sending, stop; if receiving, stop; Windows will take care of themselves (composer should dump its messages, if any but not in deadMail) declare us ready for the End of the Session No, normal quit call All windows are off. Anything to do, should compact or sender sends? Yes, maybe put an icon in panel as a sign of life if sender sending, connect us to his finished slot, declare us ready for quit and wait for senderFinished if not, Folder manager, go compact sent-mail and outbox } (= call slotFinished()) void KMKernel::slotSenderFinished() { good, Folder manager go compact sent-mail and outbox clean up stage1 (release folders and config, unregister from dcop) -- another kmail may start now --- qApp->quit(); } */ /********************************************************************/ /* Init, Exit, and handler methods */ /********************************************************************/ //----------------------------------------------------------------------------- // Open a composer for each message found in the dead.letter folder void KMKernel::recoverDeadLetters() { const QString pathName = localDataPath(); QDir dir( pathName ); if ( !dir.exists( QLatin1String("autosave") ) ) return; dir.cd( localDataPath() + QLatin1String("autosave") ); const QFileInfoList autoSaveFiles = dir.entryInfoList(); foreach( const QFileInfo &file, autoSaveFiles ) { // Disregard the '.' and '..' folders const QString filename = file.fileName(); if( filename == QLatin1String( "." ) || filename == QLatin1String( ".." ) || file.isDir() ) continue; kDebug() << "Opening autosave file:" << file.absoluteFilePath(); QFile autoSaveFile( file.absoluteFilePath() ); if( autoSaveFile.open( QIODevice::ReadOnly ) ) { const KMime::Message::Ptr autoSaveMessage( new KMime::Message() ); const QByteArray msgData = autoSaveFile.readAll(); autoSaveMessage->setContent( msgData ); autoSaveMessage->parse(); // Show the a new composer dialog for the message KMail::Composer * autoSaveWin = KMail::makeComposer(); autoSaveWin->setMessage( autoSaveMessage, false, false, false ); autoSaveWin->setAutoSaveFileName( filename ); autoSaveWin->show(); autoSaveFile.close(); } else { KMessageBox::sorry( 0, i18n( "Failed to open autosave file at %1.\nReason: %2" , file.absoluteFilePath(), autoSaveFile.errorString() ), i18n( "Opening Autosave File Failed" ) ); } } } void KMKernel::akonadiStateChanged( Akonadi::ServerManager::State state ) { kDebug() << "KMKernel has akonadi state changed to:" << int( state ); if( state == Akonadi::ServerManager::Running ) { CommonKernel->initFolders(); } } static void kmCrashHandler( int sigId ) { fprintf( stderr, "*** KMail got signal %d (Exiting)\n", sigId ); // try to cleanup all windows if ( kmkernel ) { kmkernel->dumpDeadLetters(); fprintf( stderr, "*** Dead letters dumped.\n" ); kmkernel->stopAgentInstance(); } } void KMKernel::init() { the_shuttingDown = false; the_firstStart = GlobalSettings::self()->firstStart(); GlobalSettings::self()->setFirstStart( false ); the_previousVersion = GlobalSettings::self()->previousVersion(); GlobalSettings::self()->setPreviousVersion( QLatin1String(KDEPIM_VERSION) ); readConfig(); the_undoStack = new UndoStack(20); the_msgSender = new MessageComposer::AkonadiSender; readConfig(); // filterMgr->dump(); mBackgroundTasksTimer = new QTimer( this ); mBackgroundTasksTimer->setSingleShot( true ); connect( mBackgroundTasksTimer, SIGNAL(timeout()), this, SLOT(slotRunBackgroundTasks()) ); #ifdef DEBUG_SCHEDULER // for debugging, see jobscheduler.h mBackgroundTasksTimer->start( 10000 ); // 10s, singleshot #else mBackgroundTasksTimer->start( 5 * 60000 ); // 5 minutes, singleshot #endif KCrash::setEmergencySaveFunction( kmCrashHandler ); kDebug() << "KMail init with akonadi server state:" << int( Akonadi::ServerManager::state() ); if( Akonadi::ServerManager::state() == Akonadi::ServerManager::Running ) { CommonKernel->initFolders(); } connect( Akonadi::ServerManager::self(), SIGNAL(stateChanged(Akonadi::ServerManager::State)), this, SLOT(akonadiStateChanged(Akonadi::ServerManager::State)) ); connect( folderCollectionMonitor(), SIGNAL(itemRemoved(Akonadi::Item)), the_undoStack, SLOT(msgDestroyed(Akonadi::Item)) ); } void KMKernel::readConfig() { mWrapCol = MessageComposer::MessageComposerSettings::self()->lineWrapWidth(); if ((mWrapCol == 0) || (mWrapCol > 78)) mWrapCol = 78; else if (mWrapCol < 30) mWrapCol = 30; } bool KMKernel::doSessionManagement() { // Do session management if (kapp->isSessionRestored()){ int n = 1; while (KMMainWin::canBeRestored(n)){ //only restore main windows! (Matthias); if (KMMainWin::classNameOfToplevel(n) == QLatin1String("KMMainWin")) (new KMMainWin)->restoreDockedState(n); ++n; } return true; // we were restored by SM } return false; // no, we were not restored } void KMKernel::closeAllKMailWindows() { QList windowsToDelete; foreach ( KMainWindow* window, KMainWindow::memberList() ) { if ( ::qobject_cast(window) || ::qobject_cast(window) ) { // close and delete the window window->setAttribute(Qt::WA_DeleteOnClose); window->close(); windowsToDelete.append( window ); } } // We delete all main windows here. Above we called close(), but that calls // deleteLater() internally, therefore does not delete it immediately. // This would lead to problems when closing Kontact when a composer window // is open, because the destruction order is: // // 1. destructor of the Kontact mainwinow // 2. delete all parts // 3. the KMail part destructor calls KMKernel::cleanup(), which calls // this function // 4. delete all other mainwindows // // Deleting the composer windows here will make sure that step 4 will not delete // any composer window, which would fail because the kernel is already deleted. qDeleteAll( windowsToDelete ); windowsToDelete.clear(); } void KMKernel::cleanup(void) { disconnect( Akonadi::AgentManager::self(), SIGNAL(instanceStatusChanged(Akonadi::AgentInstance))); disconnect( Akonadi::AgentManager::self(), SIGNAL(instanceError(Akonadi::AgentInstance,QString))); disconnect( Akonadi::AgentManager::self(), SIGNAL(instanceWarning(Akonadi::AgentInstance,QString))); disconnect( Akonadi::AgentManager::self(), SIGNAL(instanceRemoved(Akonadi::AgentInstance))); disconnect ( Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status))); disconnect( KPIM::ProgressManager::instance(), SIGNAL(progressItemCompleted(KPIM::ProgressItem*))); disconnect( KPIM::ProgressManager::instance(), SIGNAL(progressItemCanceled(KPIM::ProgressItem*))); dumpDeadLetters(); the_shuttingDown = true; closeAllKMailWindows(); // Flush the cache of foldercollection objects. This results // in configuration writes, so we need to do it early enough. MailCommon::FolderCollection::clearCache(); // Write the config while all other managers are alive delete the_msgSender; the_msgSender = 0; delete the_undoStack; the_undoStack = 0; KSharedConfig::Ptr config = KMKernel::config(); Akonadi::Collection trashCollection = CommonKernel->trashCollectionFolder(); if ( trashCollection.isValid() ) { if ( GlobalSettings::self()->emptyTrashOnExit() ) { Akonadi::CollectionStatisticsJob *jobStatistics = new Akonadi::CollectionStatisticsJob( trashCollection ); if ( jobStatistics->exec() ) { if ( jobStatistics->statistics().count() > 0 ) { mFolderCollectionMonitor->expunge( trashCollection, true /*sync*/ ); } } } } delete mConfigureDialog; mConfigureDialog = 0; // do not delete, because mWin may point to an existing window // delete mWin; mWin = 0; if ( RecentAddresses::exists() ) RecentAddresses::self( config.data() )->save( config.data() ); } void KMKernel::dumpDeadLetters() { if ( shuttingDown() ) return; //All documents should be saved before shutting down is set! // make all composer windows autosave their contents foreach ( KMainWindow* window, KMainWindow::memberList() ) { if ( KMail::Composer * win = ::qobject_cast( window ) ) { win->autoSaveMessage(true); while ( win->isComposing() ) { kWarning() << "Danger, using an event loop, this should no longer be happening!"; qApp->processEvents(); } } } } void KMKernel::action( bool mailto, bool check, const QString &to, const QString &cc, const QString &bcc, const QString &subj, const QString &body, const KUrl &messageFile, const KUrl::List &attachURLs, const QStringList &customHeaders, const QString &replyTo, const QString &inReplyTo) { if ( mailto ) { openComposer( to, cc, bcc, subj, body, 0, messageFile.pathOrUrl(), attachURLs.toStringList(), customHeaders, replyTo, inReplyTo ); } else openReader( check ); if ( check ) checkMail(); //Anything else? } void KMKernel::slotRequestConfigSync() { // ### FIXME: delay as promised in the kdoc of this function ;-) slotSyncConfig(); } void KMKernel::slotSyncConfig() { PimCommon::PimCommonSettings::self()->writeConfig(); MessageCore::GlobalSettings::self()->writeConfig(); MessageViewer::GlobalSettings::self()->writeConfig(); MessageComposer::MessageComposerSettings::self()->writeConfig(); TemplateParser::GlobalSettings::self()->writeConfig(); MessageList::Core::Settings::self()->writeConfig(); MailCommon::MailCommonSettings::self()->writeConfig(); GlobalSettings::self()->writeConfig(); KMKernel::config()->sync(); } void KMKernel::updateConfig() { slotConfigChanged(); } void KMKernel::slotShowConfigurationDialog() { if( KMKernel::getKMMainWidget() == 0 ) { // ensure that there is a main widget available // as parts of the configure dialog (identity) rely on this // and this slot can be called when there is only a KMComposeWin showing KMMainWin *win = new KMMainWin; win->show(); } if( !mConfigureDialog ) { mConfigureDialog = new ConfigureDialog( 0, false ); mConfigureDialog->setObjectName( QLatin1String("configure") ); connect( mConfigureDialog, SIGNAL(configChanged()), this, SLOT(slotConfigChanged()) ); } // Save all current settings. if( getKMMainWidget() ) getKMMainWidget()->writeReaderConfig(); if( mConfigureDialog->isHidden() ) { mConfigureDialog->show(); } else { mConfigureDialog->raise(); } } void KMKernel::slotConfigChanged() { readConfig(); CodecManager::self()->updatePreferredCharsets(); emit configChanged(); } //------------------------------------------------------------------------------- //static QString KMKernel::localDataPath() { return KStandardDirs::locateLocal( "data", QLatin1String("kmail2/") ); } //------------------------------------------------------------------------------- bool KMKernel::haveSystemTrayApplet() const { return (mSystemTray!=0); } void KMKernel::updateSystemTray() { if ( mSystemTray && !the_shuttingDown ) { mSystemTray->updateSystemTray(); } } KPIMIdentities::IdentityManager * KMKernel::identityManager() { if ( !mIdentityManager ) { kDebug(); mIdentityManager = new KPIMIdentities::IdentityManager( false, this, "mIdentityManager" ); } return mIdentityManager; } KMainWindow* KMKernel::mainWin() { // First look for a KMMainWin. foreach ( KMainWindow* window, KMainWindow::memberList() ) if ( ::qobject_cast(window) ) return window; // There is no KMMainWin. Use any other KMainWindow instead (e.g. in // case we are running inside Kontact) because we anyway only need // it for modal message boxes and for KNotify events. if ( !KMainWindow::memberList().isEmpty() ) { KMainWindow *kmWin = KMainWindow::memberList().first(); if ( kmWin ) return kmWin; } // There's not a single KMainWindow. Create a KMMainWin. // This could happen if we want to pop up an error message // while we are still doing the startup wizard and no other // KMainWindow is running. mWin = new KMMainWin; return mWin; } KMKernel* KMKernel::self() { return mySelf; } KSharedConfig::Ptr KMKernel::config() { assert( mySelf ); if ( !mySelf->mConfig ) { mySelf->mConfig = KSharedConfig::openConfig( QLatin1String("kmail2rc") ); // Check that all updates have been run on the config file: KMail::checkConfigUpdates(); MessageList::Core::Settings::self()->setSharedConfig( mySelf->mConfig ); MessageList::Core::Settings::self()->readConfig(); TemplateParser::GlobalSettings::self()->setSharedConfig( mySelf->mConfig ); TemplateParser::GlobalSettings::self()->readConfig(); MessageComposer::MessageComposerSettings::self()->setSharedConfig( mySelf->mConfig ); MessageComposer::MessageComposerSettings::self()->readConfig(); MessageCore::GlobalSettings::self()->setSharedConfig( mySelf->mConfig ); MessageCore::GlobalSettings::self()->readConfig(); MessageViewer::GlobalSettings::self()->setSharedConfig( mySelf->mConfig ); MessageViewer::GlobalSettings::self()->readConfig(); MailCommon::MailCommonSettings::self()->setSharedConfig( mySelf->mConfig ); MailCommon::MailCommonSettings::self()->readConfig(); PimCommon::PimCommonSettings::self()->setSharedConfig( mySelf->mConfig ); PimCommon::PimCommonSettings::self()->readConfig(); } return mySelf->mConfig; } void KMKernel::syncConfig() { slotRequestConfigSync(); } void KMKernel::selectCollectionFromId( const Akonadi::Collection::Id id) { KMMainWidget *widget = getKMMainWidget(); Q_ASSERT( widget ); if ( !widget ) return; Akonadi::Collection colFolder = CommonKernel->collectionFromId( id ); if( colFolder.isValid() ) widget->slotSelectCollectionFolder( colFolder ); } bool KMKernel::selectFolder( const QString &folder ) { KMMainWidget *widget = getKMMainWidget(); Q_ASSERT( widget ); if ( !widget ) return false; const Akonadi::Collection colFolder = CommonKernel->collectionFromId( folder.toLongLong() ); if( colFolder.isValid() ) { widget->slotSelectCollectionFolder( colFolder ); return true; } return false; } KMMainWidget *KMKernel::getKMMainWidget() { //This could definitely use a speadup QWidgetList l = QApplication::topLevelWidgets(); QWidget *wid; Q_FOREACH( wid, l ) { QList l2 = wid->window()->findChildren(); if ( !l2.isEmpty() && l2.first() ) return l2.first(); } return 0; } void KMKernel::slotRunBackgroundTasks() // called regularly by timer { // Hidden KConfig keys. Not meant to be used, but a nice fallback in case // a stable kmail release goes out with a nasty bug in CompactionJob... if ( GlobalSettings::self()->autoExpiring() ) { mFolderCollectionMonitor->expireAllFolders( false /*scheduled, not immediate*/, entityTreeModel() ); } #ifdef DEBUG_SCHEDULER // for debugging, see jobscheduler.h mBackgroundTasksTimer->start( 60 * 1000 ); // check again in 1 minute #else mBackgroundTasksTimer->start( 4 * 60 * 60 * 1000 ); // check again in 4 hours #endif } static Akonadi::Collection::List collect_collections( const QAbstractItemModel *model, const QModelIndex &parent ) { Akonadi::Collection::List collections; const int numberOfCollection( model->rowCount( parent ) ); for ( int i = 0; i < numberOfCollection; ++i ) { const QModelIndex child = model->index( i, 0, parent ); Akonadi::Collection collection = model->data( child, Akonadi::EntityTreeModel::CollectionRole ).value(); if ( collection.isValid() ) { collections << collection; } collections += collect_collections( model, child ); } return collections; } Akonadi::Collection::List KMKernel::allFolders() const { return collect_collections( collectionModel(), QModelIndex() ); } void KMKernel::expireAllFoldersNow() // called by the GUI { mFolderCollectionMonitor->expireAllFolders( true /*immediate*/, entityTreeModel() ); } bool KMKernel::canQueryClose() { if ( KMMainWidget::mainWidgetList() && KMMainWidget::mainWidgetList()->count() > 1 ) return true; if ( !mSystemTray || GlobalSettings::closeDespiteSystemTray() ) return true; if ( mSystemTray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowAlways ) { mSystemTray->hideKMail(); return false; } else if ( ( mSystemTray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowOnUnread ) ) { if( mSystemTray->hasUnreadMail() ) mSystemTray->setStatus( KStatusNotifierItem::Active ); mSystemTray->hideKMail(); return false; } return true; } QSharedPointer KMKernel::currentFolderCollection() { KMMainWidget *widget = getKMMainWidget(); QSharedPointer folder; if ( widget ) { folder = widget->currentFolder(); } return folder; } // can't be inline, since KMSender isn't known to implement // KMail::MessageSender outside this .cpp file MessageComposer::MessageSender * KMKernel::msgSender() { return the_msgSender; } void KMKernel::transportRemoved(int id, const QString & name) { Q_UNUSED( id ); // reset all identities using the deleted transport QStringList changedIdents; KPIMIdentities::IdentityManager * im = identityManager(); KPIMIdentities::IdentityManager::Iterator end = im->modifyEnd(); for ( KPIMIdentities::IdentityManager::Iterator it = im->modifyBegin(); it != end; ++it ) { if ( name == (*it).transport() ) { (*it).setTransport( QString() ); changedIdents += (*it).identityName(); } } // if the deleted transport is the currently used transport reset it to default const QString& currentTransport = GlobalSettings::self()->currentTransport(); if ( name == currentTransport ) GlobalSettings::self()->setCurrentTransport( QString() ); if ( !changedIdents.isEmpty() ) { QString information = i18np( "This identity has been changed to use the default transport:", "These %1 identities have been changed to use the default transport:", changedIdents.count() ); //Don't set parent otherwise we will swith to current KMail and we configure it. So not good KMessageBox::informationList( 0, information, changedIdents ); im->commit(); } } void KMKernel::transportRenamed(int id, const QString & oldName, const QString & newName) { Q_UNUSED( id ); QStringList changedIdents; KPIMIdentities::IdentityManager * im = identityManager(); KPIMIdentities::IdentityManager::Iterator end = im->modifyEnd(); for ( KPIMIdentities::IdentityManager::Iterator it = im->modifyBegin(); it != end; ++it ) { if ( oldName == (*it).transport() ) { (*it).setTransport( newName ); changedIdents << (*it).identityName(); } } if ( !changedIdents.isEmpty() ) { const QString information = i18np( "This identity has been changed to use the modified transport:", "These %1 identities have been changed to use the modified transport:", changedIdents.count() ); //Don't set parent otherwise we will swith to current KMail and we configure it. So not good KMessageBox::informationList( 0, information, changedIdents ); im->commit(); } } void KMKernel::itemDispatchStarted() { // Watch progress of the MDA. KPIM::ProgressManager::createProgressItem( 0, MailTransport::DispatcherInterface().dispatcherInstance(), QString::fromLatin1( "Sender" ), i18n( "Sending messages" ), i18n( "Initiating sending process..." ), true ); } void KMKernel::instanceStatusChanged( const Akonadi::AgentInstance &instance ) { if (instance.identifier() == QLatin1String( "akonadi_mailfilter_agent" ) ) { // Creating a progress item twice is ok, it will simply return the already existing // item KPIM::ProgressItem *progress = KPIM::ProgressManager::createProgressItem( 0, instance, instance.identifier(), instance.name(), instance.statusMessage(), false, KPIM::ProgressItem::Encrypted ); progress->setProperty( "AgentIdentifier", instance.identifier() ); return; } if ( MailCommon::Util::agentInstances(true).contains( instance ) ) { if ( instance.status() == Akonadi::AgentInstance::Running ) { if ( mResourcesBeingChecked.isEmpty() ) { kDebug() << "A Resource started to synchronize, starting a mail check."; emit startCheckMail(); } const QString identifier(instance.identifier()); if ( !mResourcesBeingChecked.contains( identifier ) ) { mResourcesBeingChecked.append( identifier ); } KPIM::ProgressItem::CryptoStatus cryptoStatus = KPIM::ProgressItem::Unencrypted; if(mResourceCryptoSettingCache.contains(identifier)) { cryptoStatus = mResourceCryptoSettingCache.value(identifier); } else { if ( identifier.contains( IMAP_RESOURCE_IDENTIFIER ) || identifier.contains( KOLAB_RESOURCE_IDENTIFIER )) { OrgKdeAkonadiImapSettingsInterface *iface = PimCommon::Util::createImapSettingsInterface( identifier ); if ( iface->isValid() ) { const QString imapSafety = iface->safety(); if (( imapSafety == QLatin1String( "SSL" ) || imapSafety == QLatin1String( "STARTTLS" ) )) cryptoStatus = KPIM::ProgressItem::Encrypted; mResourceCryptoSettingCache.insert(identifier,cryptoStatus); } delete iface; } else if ( identifier.contains( POP3_RESOURCE_IDENTIFIER ) ) { OrgKdeAkonadiPOP3SettingsInterface *iface = MailCommon::Util::createPop3SettingsInterface( identifier ); if ( iface->isValid() ) { if (( iface->useSSL() || iface->useTLS() )) cryptoStatus = KPIM::ProgressItem::Encrypted; mResourceCryptoSettingCache.insert(identifier, cryptoStatus); } delete iface; } } // Creating a progress item twice is ok, it will simply return the already existing // item KPIM::ProgressItem *progress = KPIM::ProgressManager::createProgressItem( 0, instance, instance.identifier(), instance.name(), instance.statusMessage(), true, cryptoStatus ); progress->setProperty( "AgentIdentifier", instance.identifier() ); } else if ( instance.status() == Akonadi::AgentInstance::Broken ) { agentInstanceBroken( instance ); } } } void KMKernel::agentInstanceBroken( const Akonadi::AgentInstance &instance ) { const QString summary = i18n( "Resource %1 is broken. This resource is now %2", instance.name(), instance.isOnline() ? i18n( "online" ) : i18n( "offline" ) ); if( xmlGuiInstance().isValid() ) { KNotification::event( QLatin1String("akonadi-resource-broken"), summary, QPixmap(), 0, KNotification::CloseOnTimeout, xmlGuiInstance() ); } else { KNotification::event( QLatin1String("akonadi-resource-broken"), summary, QPixmap(), 0, KNotification::CloseOnTimeout ); } } void KMKernel::slotProgressItemCompletedOrCanceled( KPIM::ProgressItem *item ) { const QString identifier = item->property( "AgentIdentifier" ).toString(); const Akonadi::AgentInstance agent = Akonadi::AgentManager::self()->instance( identifier ); if ( agent.isValid() ) { mResourcesBeingChecked.removeAll( identifier ); if ( mResourcesBeingChecked.isEmpty() ) { kDebug() << "Last resource finished syncing, mail check done"; emit endCheckMail(); } } } void KMKernel::updatedTemplates() { emit customTemplatesChanged(); } bool KMKernel::isImapFolder( const Akonadi::Collection &col, bool &isOnline ) const { const Akonadi::AgentInstance agentInstance = Akonadi::AgentManager::self()->instance( col.resource() ); isOnline = agentInstance.isOnline(); - return (agentInstance.type().identifier() == IMAP_RESOURCE_IDENTIFIER); + return ((agentInstance.type().identifier() == IMAP_RESOURCE_IDENTIFIER) || (agentInstance.type().identifier() == KOLAB_RESOURCE_IDENTIFIER)); } void KMKernel::stopAgentInstance() { const QString resourceGroupPattern( QLatin1String("Resource %1") ); const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances(); foreach( Akonadi::AgentInstance type, lst ) { const QString identifier = type.identifier(); KConfigGroup group( KMKernel::config(), resourceGroupPattern.arg( identifier ) ); // Keep sync in ConfigureDialog, don't forget to change there. if ( group.readEntry( "OfflineOnShutdown", identifier.startsWith(QLatin1String("akonadi_pop3_resource")) ? true : false ) ) type.setIsOnline( false ); } } void KMKernel::slotCollectionRemoved(const Akonadi::Collection &col) { KConfigGroup group( KMKernel::config(), MailCommon::FolderCollection::configGroupName( col ) ); group.deleteGroup(); group.sync(); const QString colStr = QString::number( col.id() ); TemplateParser::Util::deleteTemplate( colStr ); MessageList::Util::deleteConfig( colStr ); } void KMKernel::slotDeleteIdentity( uint identity) { TemplateParser::Util::deleteTemplate( QString::fromLatin1( "IDENTITY_%1" ).arg( identity ) ); } bool KMKernel::showPopupAfterDnD() { return GlobalSettings::self()->showPopupAfterDnD(); } bool KMKernel::excludeImportantMailFromExpiry() { return GlobalSettings::self()->excludeImportantMailFromExpiry(); } qreal KMKernel::closeToQuotaThreshold() { return GlobalSettings::self()->closeToQuotaThreshold(); } Akonadi::Entity::Id KMKernel::lastSelectedFolder() { return GlobalSettings::self()->lastSelectedFolder(); } void KMKernel::setLastSelectedFolder(const Akonadi::Entity::Id& col) { GlobalSettings::self()->setLastSelectedFolder( col ); } QStringList KMKernel::customTemplates() { return GlobalSettingsBase::self()->customTemplates(); } void KMKernel::openFilterDialog(bool createDummyFilter) { if ( !mFilterEditDialog ) { mFilterEditDialog = new MailCommon::KMFilterDialog( getKMMainWidget()->actionCollections(), 0, createDummyFilter ); mFilterEditDialog->setObjectName( QLatin1String("filterdialog") ); } mFilterEditDialog->show(); mFilterEditDialog->raise(); mFilterEditDialog->activateWindow(); } void KMKernel::createFilter(const QByteArray& field, const QString& value) { mFilterEditDialog->createFilter( field, value ); } void KMKernel::checkFolderFromResources( const Akonadi::Collection::List &collectionList ) { const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances(); foreach( const Akonadi::AgentInstance& type, lst ) { if ( type.status() == Akonadi::AgentInstance::Broken ) continue; if ( type.identifier().contains( IMAP_RESOURCE_IDENTIFIER ) ) { OrgKdeAkonadiImapSettingsInterface *iface = PimCommon::Util::createImapSettingsInterface( type.identifier() ); if ( iface->isValid() ) { foreach( const Akonadi::Collection& collection, collectionList ) { const Akonadi::Collection::Id collectionId = collection.id(); if ( iface->trashCollection() == collectionId ) { //Use default trash iface->setTrashCollection( CommonKernel->trashCollectionFolder().id() ); iface->writeConfig(); break; } } } delete iface; } else if ( type.identifier().contains( POP3_RESOURCE_IDENTIFIER ) ) { OrgKdeAkonadiPOP3SettingsInterface *iface = MailCommon::Util::createPop3SettingsInterface( type.identifier() ); if ( iface->isValid() ) { foreach( const Akonadi::Collection& collection, collectionList ) { const Akonadi::Collection::Id collectionId = collection.id(); if ( iface->targetCollection() == collectionId ) { //Use default inbox iface->setTargetCollection( CommonKernel->inboxCollectionFolder().id() ); iface->writeConfig(); break; } } } delete iface; } } } const QAbstractItemModel* KMKernel::treeviewModelSelection() { if ( getKMMainWidget() ) return getKMMainWidget()->folderTreeView()->selectionModel()->model(); else return entityTreeModel(); } void KMKernel::slotInstanceWarning(const Akonadi::AgentInstance &instance , const QString &message) { const QString summary = i18nc( ": ", "%1: %2", instance.name(), message ); if( xmlGuiInstance().isValid() ) { KNotification::event( QLatin1String("akonadi-instance-warning"), summary, QPixmap(), 0, KNotification::CloseOnTimeout, xmlGuiInstance() ); } else { KNotification::event( QLatin1String("akonadi-instance-warning"), summary, QPixmap(), 0, KNotification::CloseOnTimeout ); } } void KMKernel::slotInstanceError(const Akonadi::AgentInstance &instance, const QString &message) { const QString summary = i18nc( ": ", "%1: %2", instance.name(), message ); if( xmlGuiInstance().isValid() ) { KNotification::event( QLatin1String("akonadi-instance-error"), summary, QPixmap(), 0, KNotification::CloseOnTimeout, xmlGuiInstance() ); } else { KNotification::event( QLatin1String("akonadi-instance-error"), summary, QPixmap(), 0, KNotification::CloseOnTimeout ); } } void KMKernel::slotInstanceRemoved(const Akonadi::AgentInstance& instance) { const QString identifier(instance.identifier()); const QString resourceGroup = QString::fromLatin1( "Resource %1" ).arg( identifier ); if ( KMKernel::config()->hasGroup( resourceGroup ) ) { KConfigGroup group( KMKernel::config(), resourceGroup ); group.deleteGroup(); group.sync(); } if(mResourceCryptoSettingCache.contains(identifier)) { mResourceCryptoSettingCache.remove(identifier); } mFolderArchiveManager->slotInstanceRemoved(instance); } void KMKernel::savePaneSelection() { KMMainWidget *widget = getKMMainWidget(); if ( widget ) { widget->savePaneSelection(); } } void KMKernel::updatePaneTagComboBox() { KMMainWidget *widget = getKMMainWidget(); if ( widget ) { widget->updatePaneTagComboBox(); } } void KMKernel::resourceGoOnLine() { KMMainWidget *widget = getKMMainWidget(); if ( widget ) { if(widget->currentFolder()) { Akonadi::Collection collection = widget->currentFolder()->collection(); Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance( collection.resource() ); instance.setIsOnline( true ); widget->clearViewer(); } } } void KMKernel::makeResourceOnline(MessageViewer::Viewer::ResourceOnlineMode mode) { switch(mode) { case MessageViewer::Viewer::AllResources: resumeNetworkJobs(); break; case MessageViewer::Viewer::SelectedResource: resourceGoOnLine(); break; } } PimCommon::AutoCorrection *KMKernel::composerAutoCorrection() { return mAutoCorrection; } void KMKernel::toggleSystemTray() { KMMainWidget *widget = getKMMainWidget(); if ( widget ) { if ( !mSystemTray && GlobalSettings::self()->systemTrayEnabled() ) { mSystemTray = new KMail::KMSystemTray(widget); } else if ( mSystemTray && !GlobalSettings::self()->systemTrayEnabled() ) { // Get rid of system tray on user's request kDebug() << "deleting systray"; delete mSystemTray; mSystemTray = 0; } // Set mode of systemtray. If mode has changed, tray will handle this. if ( mSystemTray ) { mSystemTray->setMode( GlobalSettings::self()->systemTrayPolicy() ); mSystemTray->setShowUnreadCount( GlobalSettings::self()->systemTrayShowUnread() ); } } } void KMKernel::showFolder(const QString &collectionId) { if (!collectionId.isEmpty()) { const Akonadi::Collection::Id id = collectionId.toLongLong(); selectCollectionFromId(id); } } void KMKernel::slotCollectionChanged(const Akonadi::Collection &, const QSet &set) { if(set.contains("newmailnotifierattribute")) { if ( mSystemTray ) { mSystemTray->updateSystemTray(); } } } FolderArchiveManager *KMKernel::folderArchiveManager() const { return mFolderArchiveManager; } PimCommon::StorageServiceManager *KMKernel::storageServiceManager() const { return mStorageManager; } diff --git a/kmail/kmmainwidget.cpp b/kmail/kmmainwidget.cpp index db3137ddfa..c943887a6a 100644 --- a/kmail/kmmainwidget.cpp +++ b/kmail/kmmainwidget.cpp @@ -1,4864 +1,4864 @@ /* -*- mode: C++; c-file-style: "gnu" -*- This file is part of KMail, the KDE mail client. Copyright (c) 2002 Don Sanders Copyright (c) 2009, 2010, 2011, 2012 Montel Laurent Based on the work of Stefan Taferner KMail is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. KMail is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ // KMail includes #include "kmreadermainwin.h" #include "editor/composer.h" #include "searchdialog/searchwindow.h" #include "antispam-virus/antispamwizard.h" #include "widgets/vacationscriptindicatorwidget.h" #include "undostack.h" #include "kmcommands.h" #include "kmmainwin.h" #include "kmsystemtray.h" #include "customtemplatesmenu.h" #include "folderselectiondialog.h" #include "foldertreewidget.h" #include "util.h" #include "util/mailutil.h" #include "kernel/mailkernel.h" #include "dialog/archivefolderdialog.h" #include "settings/globalsettings.h" #include "foldertreeview.h" #include "tag/tagactionmanager.h" #include "foldershortcutactionmanager.h" #include "widgets/collectionpane.h" #if !defined(NDEBUG) #include using KSieveUi::SieveDebugDialog; #endif #include "collectionpage/collectionmaintenancepage.h" #include "collectionpage/collectionquotapage.h" #include "collectionpage/collectiontemplatespage.h" #include "collectionpage/collectionshortcutpage.h" #include "collectionpage/collectionviewpage.h" #include "collectionpage/collectionmailinglistpage.h" #include "tag/tagselectdialog.h" #include "archivemailagentinterface.h" #include "job/createnewcontactjob.h" #include "sendlateragentinterface.h" #include "folderarchive/folderarchiveutil.h" #include "folderarchive/folderarchivemanager.h" #include "pimcommon/acl/collectionaclpage.h" #include "mailcommon/collectionpage/collectiongeneralpage.h" #include "mailcommon/collectionpage/collectionexpirypage.h" #include "mailcommon/collectionpage/expirecollectionattribute.h" #include "mailcommon/filter/filtermanager.h" #include "mailcommon/filter/mailfilter.h" #include "mailcommon/widgets/favoritecollectionwidget.h" #include "mailcommon/folder/foldertreewidget.h" #include "mailcommon/folder/foldertreeview.h" #include "mailcommon/mailcommonsettings_base.h" #include "kmmainwidget.h" // Other PIM includes #include "kdepim-version.h" #include "messageviewer/utils/autoqpointer.h" #include "messageviewer/settings/globalsettings.h" #include "messageviewer/viewer/viewer.h" #include "messageviewer/viewer/attachmentstrategy.h" #include "messageviewer/header/headerstrategy.h" #include "messageviewer/header/headerstyle.h" #ifndef QT_NO_CURSOR #include "messageviewer/utils/kcursorsaver.h" #endif #include "messagecomposer/sender/messagesender.h" #include "messagecomposer/helper/messagehelper.h" #include "templateparser/templateparser.h" #include "messagecore/settings/globalsettings.h" #include "messagecore/misc/mailinglist.h" #include "messagecore/helpers/messagehelpers.h" #include "dialog/kmknotify.h" #include "ksieveui/vacation/vacationmanager.h" // LIBKDEPIM includes #include "progresswidget/progressmanager.h" #include "misc/broadcaststatus.h" // KDEPIMLIBS includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // KDELIBS includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Qt includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // System includes #include #include // ugh #include using namespace KMime; using namespace Akonadi; using namespace MailCommon; using KPIM::ProgressManager; using KPIM::BroadcastStatus; using KMail::SearchWindow; using KMail::AntiSpamWizard; using KMime::Types::AddrSpecList; using MessageViewer::AttachmentStrategy; Q_DECLARE_METATYPE(KPIM::ProgressItem*) Q_DECLARE_METATYPE(Akonadi::Job*) Q_DECLARE_METATYPE(QPointer) K_GLOBAL_STATIC( KMMainWidget::PtrList, theMainWidgetList ) //----------------------------------------------------------------------------- KMMainWidget::KMMainWidget( QWidget *parent, KXMLGUIClient *aGUIClient, KActionCollection *actionCollection, KSharedConfig::Ptr config ) : QWidget( parent ), mMoveMsgToFolderAction(0), mCollectionProperties( 0 ), mFavoriteCollectionsView( 0 ), mMsgView( 0 ), mSplitter1( 0 ), mSplitter2( 0 ), mFolderViewSplitter( 0 ), mArchiveFolderAction( 0 ), mShowBusySplashTimer( 0 ), mMsgActions( 0 ), mCurrentFolder( 0 ), mVacationIndicatorActive( false ), mGoToFirstUnreadMessageInSelectedFolder( false ) { // must be the first line of the constructor: mStartupDone = false; mWasEverShown = false; mReaderWindowActive = true; mReaderWindowBelow = true; mFolderHtmlPref = false; mFolderHtmlLoadExtPref = false; mDestructed = false; mActionCollection = actionCollection; mTopLayout = new QVBoxLayout( this ); mTopLayout->setMargin( 0 ); mConfig = config; mGUIClient = aGUIClient; mFolderTreeWidget = 0; mPreferHtmlAction = 0; mPreferHtmlLoadExtAction = 0; Akonadi::Control::widgetNeedsAkonadi( this ); mFavoritesModel = 0; mVacationManager = new KSieveUi::VacationManager(this); // FIXME This should become a line separator as soon as the API // is extended in kdelibs. mToolbarActionSeparator = new QAction( this ); mToolbarActionSeparator->setSeparator( true ); theMainWidgetList->append( this ); readPreConfig(); createWidgets(); setupActions(); readConfig(); if ( !kmkernel->isOffline() ) { //kmail is set to online mode, make sure the agents are also online kmkernel->setAccountStatus(true); } QTimer::singleShot( 0, this, SLOT(slotShowStartupFolder())); connect( kmkernel, SIGNAL(startCheckMail()), this, SLOT(slotStartCheckMail()) ); connect( kmkernel, SIGNAL(endCheckMail()), this, SLOT(slotEndCheckMail()) ); connect( kmkernel, SIGNAL(configChanged()), this, SLOT(slotConfigChanged()) ); connect( kmkernel, SIGNAL(onlineStatusChanged(GlobalSettings::EnumNetworkState::type)), this, SLOT(slotUpdateOnlineStatus(GlobalSettings::EnumNetworkState::type)) ); connect( mTagActionManager, SIGNAL(tagActionTriggered(Akonadi::Tag)), this, SLOT(slotUpdateMessageTagList(Akonadi::Tag)) ); connect( mTagActionManager, SIGNAL(tagMoreActionClicked()), this, SLOT(slotSelectMoreMessageTagList()) ); kmkernel->toggleSystemTray(); { // make sure the pages are registered only once, since there can be multiple instances of KMMainWidget static bool pagesRegistered = false; if ( !pagesRegistered ) { Akonadi::CollectionPropertiesDialog::registerPage( new PimCommon::CollectionAclPageFactory ); Akonadi::CollectionPropertiesDialog::registerPage( new MailCommon::CollectionGeneralPageFactory ); Akonadi::CollectionPropertiesDialog::registerPage( new CollectionMaintenancePageFactory ); Akonadi::CollectionPropertiesDialog::registerPage( new CollectionQuotaPageFactory ); Akonadi::CollectionPropertiesDialog::registerPage( new CollectionTemplatesPageFactory ); Akonadi::CollectionPropertiesDialog::registerPage( new MailCommon::CollectionExpiryPageFactory ); Akonadi::CollectionPropertiesDialog::registerPage( new CollectionViewPageFactory ); Akonadi::CollectionPropertiesDialog::registerPage( new CollectionMailingListPageFactory ); Akonadi::CollectionPropertiesDialog::registerPage( new CollectionShortcutPageFactory ); pagesRegistered = true; } } KMainWindow *mainWin = dynamic_cast(window()); KStatusBar *sb = mainWin ? mainWin->statusBar() : 0; mVacationScriptIndicator = new KMail::VacationScriptIndicatorWidget( sb ); mVacationScriptIndicator->hide(); connect( mVacationScriptIndicator, SIGNAL(clicked(QString)), SLOT(slotEditVacation(QString)) ); if ( KSieveUi::Util::checkOutOfOfficeOnStartup() ) QTimer::singleShot( 0, this, SLOT(slotCheckVacation()) ); connect( mFolderTreeWidget->folderTreeView()->model(), SIGNAL(modelReset()), this, SLOT(restoreCollectionFolderViewConfig()) ); restoreCollectionFolderViewConfig(); if ( kmkernel->firstStart() ) { if (MailCommon::Util::foundMailer()) { if (KMessageBox::questionYesNo(this,i18n("Another mailer was found on system. Do you want to import data from it?")) == KMessageBox::Yes) { const QString path = KStandardDirs::findExe( QLatin1String("importwizard" ) ); if ( !QProcess::startDetached( path ) ) { KMessageBox::error( this, i18n( "Could not start the import wizard. " "Please check your installation." ), i18n( "Unable to start import wizard" ) ); } } else { KMail::Util::launchAccountWizard( this ); } } else { KMail::Util::launchAccountWizard( this ); } } // must be the last line of the constructor: mStartupDone = true; mCheckMailTimer.setInterval( 3 * 1000 ); mCheckMailTimer.setSingleShot( true ); connect( &mCheckMailTimer, SIGNAL(timeout()), SLOT(slotUpdateActionsAfterMailChecking()) ); } void KMMainWidget::restoreCollectionFolderViewConfig() { ETMViewStateSaver *saver = new ETMViewStateSaver; saver->setView( mFolderTreeWidget->folderTreeView() ); const KConfigGroup cfg( KMKernel::self()->config(), "CollectionFolderView" ); mFolderTreeWidget->restoreHeaderState( cfg.readEntry( "HeaderState", QByteArray() ) ); saver->restoreState( cfg ); //Restore startup folder Akonadi::Collection::Id id = -1; if (mCurrentFolder && mCurrentFolder->collection().isValid() ) { id = mCurrentFolder->collection().id(); } if (id == -1) { if (GlobalSettings::self()->startSpecificFolderAtStartup()) { Akonadi::Collection::Id startupFolder = GlobalSettings::self()->startupFolder(); if ( startupFolder > 0 ) saver->restoreCurrentItem( QString::fromLatin1("c%1").arg(startupFolder) ); } } else { saver->restoreCurrentItem( QString::fromLatin1("c%1").arg(id) ); } } //----------------------------------------------------------------------------- //The kernel may have already been deleted when this method is called, //perform all cleanup that requires the kernel in destruct() KMMainWidget::~KMMainWidget() { theMainWidgetList->removeAll( this ); qDeleteAll( mFilterCommands ); destruct(); } //----------------------------------------------------------------------------- //This method performs all cleanup that requires the kernel to exist. void KMMainWidget::destruct() { if ( mDestructed ) return; if ( mSearchWin ) mSearchWin->close(); writeConfig(false); /* don't force kmkernel sync when close BUG: 289287 */ writeFolderConfig(); deleteWidgets(); mCurrentFolder.clear(); delete mMoveOrCopyToDialog; delete mSelectFromAllFoldersDialog; disconnect( kmkernel->folderCollectionMonitor(), SIGNAL(itemAdded(Akonadi::Item,Akonadi::Collection)), this, 0); disconnect( kmkernel->folderCollectionMonitor(), SIGNAL(itemRemoved(Akonadi::Item)), this, 0); disconnect( kmkernel->folderCollectionMonitor(), SIGNAL(itemMoved(Akonadi::Item,Akonadi::Collection,Akonadi::Collection)), this, 0); disconnect( kmkernel->folderCollectionMonitor(), SIGNAL(collectionChanged(Akonadi::Collection,QSet)), this, 0); disconnect( kmkernel->folderCollectionMonitor(), SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)), this, 0); mDestructed = true; } void KMMainWidget::slotStartCheckMail() { if ( mCheckMailTimer.isActive() ) mCheckMailTimer.stop(); } void KMMainWidget::slotEndCheckMail() { if ( !mCheckMailTimer.isActive() ) mCheckMailTimer.start(); } void KMMainWidget::slotUpdateActionsAfterMailChecking() { const bool sendOnAll = GlobalSettings::self()->sendOnCheck() == GlobalSettings::EnumSendOnCheck::SendOnAllChecks; const bool sendOnManual = GlobalSettings::self()->sendOnCheck() == GlobalSettings::EnumSendOnCheck::SendOnManualChecks; if ( !kmkernel->isOffline() && ( sendOnAll || (sendOnManual /*&& sendOnCheck*/ ) ) ) { slotSendQueued(); } // update folder menus in case some mail got filtered to trash/current folder // and we can enable "empty trash/move all to trash" action etc. updateFolderMenu(); } void KMMainWidget::slotCollectionFetched( int collectionId ) { // Called when a collection is fetched for the first time by the ETM. // This is the right time to update the caption (which still says "Loading...") // and to update the actions that depend on the number of mails in the folder. if ( mCurrentFolder && collectionId == mCurrentFolder->collection().id() ) { mCurrentFolder->setCollection( MailCommon::Util::updatedCollection( mCurrentFolder->collection() ) ); updateMessageActions(); updateFolderMenu(); } // We call this for any collection, it could be one of our parents... if ( mCurrentFolder ) { emit captionChangeRequest( MailCommon::Util::fullCollectionPath( mCurrentFolder->collection() ) ); } } void KMMainWidget::slotFolderChanged( const Akonadi::Collection& collection ) { folderSelected( collection ); if (collection.cachePolicy().syncOnDemand()) AgentManager::self()->synchronizeCollection( collection, false ); mMsgActions->setCurrentMessage( Akonadi::Item() ); emit captionChangeRequest( MailCommon::Util::fullCollectionPath( collection ) ); } void KMMainWidget::folderSelected( const Akonadi::Collection & col ) { // This is connected to the MainFolderView signal triggering when a folder is selected if ( mGoToFirstUnreadMessageInSelectedFolder ) { // the default action has been overridden from outside mPreSelectionMode = MessageList::Core::PreSelectFirstUnreadCentered; } else { // use the default action switch ( GlobalSettings::self()->actionEnterFolder() ) { case GlobalSettings::EnumActionEnterFolder::SelectFirstUnread: mPreSelectionMode = MessageList::Core::PreSelectFirstUnreadCentered; break; case GlobalSettings::EnumActionEnterFolder::SelectLastSelected: mPreSelectionMode = MessageList::Core::PreSelectLastSelected; break; case GlobalSettings::EnumActionEnterFolder::SelectNewest: mPreSelectionMode = MessageList::Core::PreSelectNewestCentered; break; case GlobalSettings::EnumActionEnterFolder::SelectOldest: mPreSelectionMode = MessageList::Core::PreSelectOldestCentered; break; default: mPreSelectionMode = MessageList::Core::PreSelectNone; break; } } mGoToFirstUnreadMessageInSelectedFolder = false; #ifndef QT_NO_CURSOR MessageViewer::KCursorSaver busy( MessageViewer::KBusyPtr::busy() ); #endif if (mMsgView) mMsgView->clear(true); const bool newFolder = mCurrentFolder && ( mCurrentFolder->collection() != col ); // Delete any pending timer, if needed it will be recreated below delete mShowBusySplashTimer; mShowBusySplashTimer = 0; if ( newFolder ) { // We're changing folder: write configuration for the old one writeFolderConfig(); } mCurrentFolder = FolderCollection::forCollection( col ); readFolderConfig(); if (mMsgView) { mMsgView->setHtmlOverride(mFolderHtmlPref); mMsgView->setHtmlLoadExtOverride(mFolderHtmlLoadExtPref); } if ( !mCurrentFolder->isValid() && ( mMessagePane->count() < 2 ) ) slotIntro(); updateMessageActions(); updateFolderMenu(); // The message pane uses the selection model of the folder view to load the correct aggregation model and theme // settings. At this point the selection model hasn't been updated yet to the user's new choice, so it would load // the old folder settings instead. QTimer::singleShot( 0, this, SLOT(slotShowSelectedFolderInPane()) ); } void KMMainWidget::slotShowSelectedFolderInPane() { if ( mCurrentFolder && mCurrentFolder->collection().isValid() ) { mMessagePane->setCurrentFolder( mCurrentFolder->collection(), false , mPreSelectionMode ); } } void KMMainWidget::clearViewer() { if (mMsgView) { mMsgView->clear( true ); mMsgView->displayAboutPage(); } } //----------------------------------------------------------------------------- void KMMainWidget::readPreConfig() { mLongFolderList = GlobalSettings::self()->folderList() == GlobalSettings::EnumFolderList::longlist; mReaderWindowActive = GlobalSettings::self()->readerWindowMode() != GlobalSettings::EnumReaderWindowMode::hide; mReaderWindowBelow = GlobalSettings::self()->readerWindowMode() == GlobalSettings::EnumReaderWindowMode::below; mHtmlPref = MessageViewer::GlobalSettings::self()->htmlMail(); mHtmlLoadExtPref = MessageViewer::GlobalSettings::self()->htmlLoadExternal(); mEnableFavoriteFolderView = ( MailCommon::MailCommonSettings::self()->favoriteCollectionViewMode() != MailCommon::MailCommonSettings::EnumFavoriteCollectionViewMode::HiddenMode ); mEnableFolderQuickSearch = GlobalSettings::self()->enableFolderQuickSearch(); updateHtmlMenuEntry(); } //----------------------------------------------------------------------------- void KMMainWidget::readFolderConfig() { if ( !mCurrentFolder || !mCurrentFolder->isValid() ) return; KSharedConfig::Ptr config = KMKernel::self()->config(); KConfigGroup group( config, MailCommon::FolderCollection::configGroupName( mCurrentFolder->collection() ) ); mFolderHtmlPref = group.readEntry( "htmlMailOverride", false ); mFolderHtmlLoadExtPref = group.readEntry( "htmlLoadExternalOverride", false ); } //----------------------------------------------------------------------------- void KMMainWidget::writeFolderConfig() { if ( mCurrentFolder && mCurrentFolder->isValid() ) { KSharedConfig::Ptr config = KMKernel::self()->config(); KConfigGroup group( config, MailCommon::FolderCollection::configGroupName( mCurrentFolder->collection() ) ); group.writeEntry( "htmlMailOverride", mFolderHtmlPref ); group.writeEntry( "htmlLoadExternalOverride", mFolderHtmlLoadExtPref ); } } //----------------------------------------------------------------------------- void KMMainWidget::layoutSplitters() { // This function can only be called when the old splitters are already deleted assert( !mSplitter1 ); assert( !mSplitter2 ); // For some reason, this is necessary here so that the copy action still // works after changing the folder layout. if ( mMsgView ) disconnect( mMsgView->copyAction(), SIGNAL(triggered(bool)), mMsgView, SLOT(slotCopySelectedText()) ); // If long folder list is enabled, the splitters are: // Splitter 1: FolderView vs (HeaderAndSearch vs MessageViewer) // Splitter 2: HeaderAndSearch vs MessageViewer // // If long folder list is disabled, the splitters are: // Splitter 1: (FolderView vs HeaderAndSearch) vs MessageViewer // Splitter 2: FolderView vs HeaderAndSearch // The folder view is both the folder tree and the favorite folder view, if // enabled const bool opaqueResize = KGlobalSettings::opaqueResize(); const bool readerWindowAtSide = !mReaderWindowBelow && mReaderWindowActive; const bool readerWindowBelow = mReaderWindowBelow && mReaderWindowActive; mSplitter1 = new QSplitter( this ); mSplitter2 = new QSplitter( mSplitter1 ); QWidget * folderTreeWidget = mSearchAndTree; if ( mFavoriteCollectionsView ) { mFolderViewSplitter = new QSplitter( Qt::Vertical ); mFolderViewSplitter->setOpaqueResize( opaqueResize ); //mFolderViewSplitter->setChildrenCollapsible( false ); mFolderViewSplitter->addWidget( mFavoriteCollectionsView ); mFavoriteCollectionsView->setParent( mFolderViewSplitter ); mFolderViewSplitter->addWidget( mSearchAndTree ); folderTreeWidget = mFolderViewSplitter; } if ( mLongFolderList ) { // add folder tree mSplitter1->setOrientation( Qt::Horizontal ); mSplitter1->addWidget( folderTreeWidget ); // and the rest to the right mSplitter1->addWidget( mSplitter2 ); // add the message list to the right or below if ( readerWindowAtSide ) { mSplitter2->setOrientation( Qt::Horizontal ); } else { mSplitter2->setOrientation( Qt::Vertical ); } mSplitter2->addWidget( mMessagePane ); // add the preview window, if there is one if ( mMsgView ) { mSplitter2->addWidget( mMsgView ); } } else { // short folder list if ( mReaderWindowBelow ) { mSplitter1->setOrientation( Qt::Vertical ); mSplitter2->setOrientation( Qt::Horizontal ); } else { // at side or none mSplitter1->setOrientation( Qt::Horizontal ); mSplitter2->setOrientation( Qt::Vertical ); } mSplitter1->addWidget( mSplitter2 ); // add folder tree mSplitter2->addWidget( folderTreeWidget ); // add message list to splitter 2 mSplitter2->addWidget( mMessagePane ); // add the preview window, if there is one if ( mMsgView ) mSplitter1->addWidget( mMsgView ); } // // Set splitter properties // mSplitter1->setObjectName( QLatin1String("splitter1") ); mSplitter1->setOpaqueResize( opaqueResize ); //mSplitter1->setChildrenCollapsible( false ); mSplitter2->setObjectName( QLatin1String("splitter2") ); mSplitter2->setOpaqueResize( opaqueResize ); //mSplitter2->setChildrenCollapsible( false ); // // Set the stretch factors // mSplitter1->setStretchFactor( 0, 0 ); mSplitter2->setStretchFactor( 0, 0 ); mSplitter1->setStretchFactor( 1, 1 ); mSplitter2->setStretchFactor( 1, 1 ); if ( mFavoriteCollectionsView ) { mFolderViewSplitter->setStretchFactor( 0, 0 ); mFolderViewSplitter->setStretchFactor( 1, 1 ); } // Because the reader windows's width increases a tiny bit after each // restart in short folder list mode with message window at side, disable // the stretching as a workaround here if ( readerWindowAtSide && !mLongFolderList ) { mSplitter1->setStretchFactor( 0, 1 ); mSplitter1->setStretchFactor( 1, 0 ); } // // Set the sizes of the splitters to the values stored in the config // QList splitter1Sizes; QList splitter2Sizes; const int folderViewWidth = GlobalSettings::self()->folderViewWidth(); int ftHeight = GlobalSettings::self()->folderTreeHeight(); int headerHeight = GlobalSettings::self()->searchAndHeaderHeight(); const int messageViewerWidth = GlobalSettings::self()->readerWindowWidth(); int headerWidth = GlobalSettings::self()->searchAndHeaderWidth(); int messageViewerHeight = GlobalSettings::self()->readerWindowHeight(); int ffvHeight = mFolderViewSplitter ? MailCommon::MailCommonSettings::self()->favoriteCollectionViewHeight() : 0; // If the message viewer was hidden before, make sure it is not zero height if ( messageViewerHeight < 10 && readerWindowBelow ) { headerHeight /= 2; messageViewerHeight = headerHeight; } if ( mLongFolderList ) { if ( !readerWindowAtSide ) { splitter1Sizes << folderViewWidth << headerWidth; splitter2Sizes << headerHeight << messageViewerHeight; } else { splitter1Sizes << folderViewWidth << ( headerWidth + messageViewerWidth ); splitter2Sizes << headerWidth << messageViewerWidth; } } else { if ( !readerWindowAtSide ) { splitter1Sizes << headerHeight << messageViewerHeight; splitter2Sizes << folderViewWidth << headerWidth; } else { splitter1Sizes << headerWidth << messageViewerWidth; splitter2Sizes << ftHeight + ffvHeight << messageViewerHeight; } } mSplitter1->setSizes( splitter1Sizes ); mSplitter2->setSizes( splitter2Sizes ); if ( mFolderViewSplitter ) { QList splitterSizes; splitterSizes << ffvHeight << ftHeight; mFolderViewSplitter->setSizes( splitterSizes ); } // // Now add the splitters to the main layout // mTopLayout->addWidget( mSplitter1 ); // Make sure the focus is on the view, and not on the quick search line edit, because otherwise // shortcuts like + or j go to the wrong place. // This would normally be done in the message list itself, but apparently something resets the focus // again, probably all the reparenting we do here. mMessagePane->focusView(); // By default hide th unread and size columns on first run. if ( kmkernel->firstStart() ) { mFolderTreeWidget->folderTreeView()->hideColumn( 1 ); mFolderTreeWidget->folderTreeView()->hideColumn( 3 ); mFolderTreeWidget->folderTreeView()->header()->resizeSection( 0, folderViewWidth * 0.8 ); } // Make the copy action work, see disconnect comment above if ( mMsgView ) connect( mMsgView->copyAction(), SIGNAL(triggered(bool)), mMsgView, SLOT(slotCopySelectedText()) ); } //----------------------------------------------------------------------------- void KMMainWidget::refreshFavoriteFoldersViewProperties() { if ( mFavoriteCollectionsView ) { if ( MailCommon::MailCommonSettings::self()->favoriteCollectionViewMode() == MailCommon::MailCommonSettings::EnumFavoriteCollectionViewMode::IconMode ) mFavoriteCollectionsView->setViewMode( QListView::IconMode ); else if ( MailCommon::MailCommonSettings::self()->favoriteCollectionViewMode() == MailCommon::MailCommonSettings::EnumFavoriteCollectionViewMode::ListMode ) mFavoriteCollectionsView->setViewMode( QListView::ListMode ); else Q_ASSERT(false); // we should never get here in hidden mode mFavoriteCollectionsView->setDropActionMenuEnabled( kmkernel->showPopupAfterDnD() ); mFavoriteCollectionsView->setWordWrap( true ); mFavoriteCollectionsView->updateMode(); } } //----------------------------------------------------------------------------- void KMMainWidget::readConfig() { const bool oldLongFolderList = mLongFolderList; const bool oldReaderWindowActive = mReaderWindowActive; const bool oldReaderWindowBelow = mReaderWindowBelow; const bool oldFavoriteFolderView = mEnableFavoriteFolderView; const bool oldFolderQuickSearch = mEnableFolderQuickSearch; // on startup, the layout is always new and we need to relayout the widgets bool layoutChanged = !mStartupDone; if ( mStartupDone ) { readPreConfig(); layoutChanged = ( oldLongFolderList != mLongFolderList ) || ( oldReaderWindowActive != mReaderWindowActive ) || ( oldReaderWindowBelow != mReaderWindowBelow ) || ( oldFavoriteFolderView != mEnableFavoriteFolderView ); if ( layoutChanged ) { deleteWidgets(); createWidgets(); restoreCollectionFolderViewConfig(); emit recreateGui(); } else if ( oldFolderQuickSearch != mEnableFolderQuickSearch ) { if ( mEnableFolderQuickSearch ) mFolderTreeWidget->filterFolderLineEdit()->show(); else mFolderTreeWidget->filterFolderLineEdit()->hide(); } } { // Read the config of the folder views and the header if ( mMsgView ) { mMsgView->readConfig(); } mMessagePane->reloadGlobalConfiguration(); mFolderTreeWidget->readConfig(); if ( mFavoriteCollectionsView ) { mFavoriteCollectionsView->readConfig(); } refreshFavoriteFoldersViewProperties(); } { // area for config group "General" if ( !mStartupDone ) { // check mail on startup // do it after building the kmmainwin, so that the progressdialog is available QTimer::singleShot( 0, this, SLOT(slotCheckMailOnStartup()) ); } } if ( layoutChanged ) { layoutSplitters(); } updateMessageMenu(); updateFileMenu(); kmkernel->toggleSystemTray(); connect( Akonadi::AgentManager::self(), SIGNAL(instanceAdded(Akonadi::AgentInstance)), this, SLOT(updateFileMenu()) ); connect( Akonadi::AgentManager::self(), SIGNAL(instanceRemoved(Akonadi::AgentInstance)), this, SLOT(updateFileMenu()) ); } //----------------------------------------------------------------------------- void KMMainWidget::writeConfig(bool force) { // Don't save the sizes of all the widgets when we were never shown. // This can happen in Kontact, where the KMail plugin is automatically // loaded, but not necessarily shown. // This prevents invalid sizes from being saved if ( mWasEverShown ) { // The height of the header widget can be 0, this happens when the user // did not switch to the header widget onced and the "Welcome to KMail" // HTML widget was shown the whole time int headersHeight = mMessagePane->height(); if ( headersHeight == 0 ) headersHeight = height() / 2; GlobalSettings::self()->setSearchAndHeaderHeight( headersHeight ); GlobalSettings::self()->setSearchAndHeaderWidth( mMessagePane->width() ); if ( mFavoriteCollectionsView ) { MailCommon::MailCommonSettings::self()->setFavoriteCollectionViewHeight( mFavoriteCollectionsView->height() ); GlobalSettings::self()->setFolderTreeHeight( mFolderTreeWidget->height() ); if ( !mLongFolderList ) { GlobalSettings::self()->setFolderViewHeight( mFolderViewSplitter->height() ); } } else if ( !mLongFolderList && mFolderTreeWidget ) { GlobalSettings::self()->setFolderTreeHeight( mFolderTreeWidget->height() ); } if ( mFolderTreeWidget ) { GlobalSettings::self()->setFolderViewWidth( mFolderTreeWidget->width() ); KSharedConfig::Ptr config = KMKernel::self()->config(); KConfigGroup group(config, "CollectionFolderView"); ETMViewStateSaver saver; saver.setView( mFolderTreeWidget->folderTreeView() ); saver.saveState( group ); group.writeEntry( "HeaderState", mFolderTreeWidget->folderTreeView()->header()->saveState() ); //Work around from startup folder group.deleteEntry( "Selection" ); #if 0 if (!GlobalSettings::self()->startSpecificFolderAtStartup()) { group.deleteEntry( "Current" ); } #endif group.sync(); } if ( mMsgView ) { if ( !mReaderWindowBelow ) GlobalSettings::self()->setReaderWindowWidth( mMsgView->width() ); mMsgView->viewer()->writeConfig(force); GlobalSettings::self()->setReaderWindowHeight( mMsgView->height() ); } } } void KMMainWidget::writeReaderConfig() { if ( mWasEverShown ) { if ( mMsgView ) { mMsgView->viewer()->writeConfig(); } } } //----------------------------------------------------------------------------- void KMMainWidget::deleteWidgets() { // Simply delete the top splitter, which always is mSplitter1, regardless // of the layout. This deletes all children. // akonadi action manager is created in createWidgets(), parented to this // so not autocleaned up. delete mAkonadiStandardActionManager; mAkonadiStandardActionManager = 0; delete mSplitter1; mMsgView = 0; mSearchAndTree = 0; mFolderViewSplitter = 0; mFavoriteCollectionsView = 0; mSplitter1 = 0; mSplitter2 = 0; mFavoritesModel = 0; } //----------------------------------------------------------------------------- void KMMainWidget::createWidgets() { // Note that all widgets we create in this function have the parent 'this'. // They will be properly reparented in layoutSplitters() // // Create header view and search bar // FolderTreeWidget::TreeViewOptions opt = FolderTreeWidget::ShowUnreadCount; opt |= FolderTreeWidget::UseLineEditForFiltering; opt |= FolderTreeWidget::ShowCollectionStatisticAnimation; opt |= FolderTreeWidget::DontKeyFilter; mFolderTreeWidget = new FolderTreeWidget( this, mGUIClient, opt ); connect( mFolderTreeWidget->folderTreeView(), SIGNAL(currentChanged(Akonadi::Collection)), this, SLOT(slotFolderChanged(Akonadi::Collection)) ); connect( mFolderTreeWidget->folderTreeView()->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateFolderMenu()) ); connect( mFolderTreeWidget->folderTreeView(), SIGNAL(prefereCreateNewTab(bool)), this, SLOT(slotCreateNewTab(bool)) ); mFolderTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection ); mMessagePane = new CollectionPane( !GlobalSettings::self()->startSpecificFolderAtStartup(), KMKernel::self()->entityTreeModel(), mFolderTreeWidget->folderTreeView()->selectionModel(), this ); connect( KMKernel::self()->entityTreeModel(), SIGNAL(collectionFetched(int)), this, SLOT(slotCollectionFetched(int))); mMessagePane->setXmlGuiClient( mGUIClient ); connect( mMessagePane, SIGNAL(messageSelected(Akonadi::Item)), this, SLOT(slotMessageSelected(Akonadi::Item)) ); connect( mMessagePane, SIGNAL(selectionChanged()), SLOT(startUpdateMessageActionsTimer()) ); connect( mMessagePane, SIGNAL(currentTabChanged()), this, SLOT(refreshMessageListSelection()) ); connect( mMessagePane, SIGNAL(messageActivated(Akonadi::Item)), this, SLOT(slotMessageActivated(Akonadi::Item)) ); connect( mMessagePane, SIGNAL(messageStatusChangeRequest(Akonadi::Item,Akonadi::MessageStatus,Akonadi::MessageStatus)), SLOT(slotMessageStatusChangeRequest(Akonadi::Item,Akonadi::MessageStatus,Akonadi::MessageStatus)) ); connect( mMessagePane, SIGNAL(statusMessage(QString)), BroadcastStatus::instance(), SLOT(setStatusMsg(QString)) ); // // Create the reader window // if ( mReaderWindowActive ) { mMsgView = new KMReaderWin( this, this, actionCollection(), 0 ); if ( mMsgActions ) { mMsgActions->setMessageView( mMsgView ); } connect( mMsgView->viewer(), SIGNAL(replaceMsgByUnencryptedVersion()), this, SLOT(slotReplaceMsgByUnencryptedVersion()) ); connect( mMsgView->viewer(), SIGNAL(popupMenu(Akonadi::Item,KUrl,KUrl,QPoint)), this, SLOT(slotMessagePopup(Akonadi::Item,KUrl,KUrl,QPoint)) ); connect( mMsgView->viewer(), SIGNAL(moveMessageToTrash()), this, SLOT(slotMoveMessageToTrash()) ); } else { if ( mMsgActions ) { mMsgActions->setMessageView( 0 ); } } // // Create the folder tree // the "folder tree" consists of a quicksearch input field and the tree itself // mSearchAndTree = new QWidget( this ); QVBoxLayout *vboxlayout = new QVBoxLayout; vboxlayout->setMargin(0); mSearchAndTree->setLayout( vboxlayout ); vboxlayout->addWidget( mFolderTreeWidget ); if ( !GlobalSettings::self()->enableFolderQuickSearch() ) { mFolderTreeWidget->filterFolderLineEdit()->hide(); } // // Create the favorite folder view // mAkonadiStandardActionManager = new Akonadi::StandardMailActionManager( mGUIClient->actionCollection(), this ); connect( mAkonadiStandardActionManager, SIGNAL(actionStateUpdated()), this, SLOT(slotAkonadiStandardActionUpdated()) ); mAkonadiStandardActionManager->setCollectionSelectionModel( mFolderTreeWidget->folderTreeView()->selectionModel() ); mAkonadiStandardActionManager->setItemSelectionModel( mMessagePane->currentItemSelectionModel() ); if ( mEnableFavoriteFolderView ) { mFavoriteCollectionsView = new FavoriteCollectionWidget( mGUIClient, this ); refreshFavoriteFoldersViewProperties(); connect( mFavoriteCollectionsView, SIGNAL(currentChanged(Akonadi::Collection)), this, SLOT(slotFolderChanged(Akonadi::Collection)) ); mFavoritesModel = new Akonadi::FavoriteCollectionsModel( mFolderTreeWidget->folderTreeView()->model(), KMKernel::self()->config()->group( "FavoriteCollections" ), this ); mFavoriteCollectionsView->setModel( mFavoritesModel ); Akonadi::CollectionStatisticsDelegate *delegate = new Akonadi::CollectionStatisticsDelegate( mFavoriteCollectionsView ); delegate->setProgressAnimationEnabled( true ); mFavoriteCollectionsView->setItemDelegate(delegate); delegate->setUnreadCountShown( true ); mAkonadiStandardActionManager->setFavoriteCollectionsModel( mFavoritesModel ); mAkonadiStandardActionManager->setFavoriteSelectionModel( mFavoriteCollectionsView->selectionModel() ); } //Don't use mMailActionManager->createAllActions() to save memory by not //creating actions that doesn't make sense. QList standardActions; standardActions << StandardActionManager::CreateCollection << StandardActionManager::CopyCollections << StandardActionManager::DeleteCollections << StandardActionManager::SynchronizeCollections << StandardActionManager::CollectionProperties << StandardActionManager::CopyItems << StandardActionManager::Paste << StandardActionManager::DeleteItems << StandardActionManager::ManageLocalSubscriptions << StandardActionManager::CopyCollectionToMenu << StandardActionManager::CopyItemToMenu << StandardActionManager::MoveItemToMenu << StandardActionManager::MoveCollectionToMenu << StandardActionManager::CutItems << StandardActionManager::CutCollections << StandardActionManager::CreateResource << StandardActionManager::DeleteResources << StandardActionManager::ResourceProperties << StandardActionManager::SynchronizeResources << StandardActionManager::ToggleWorkOffline << StandardActionManager::SynchronizeCollectionsRecursive; Q_FOREACH( StandardActionManager::Type standardAction, standardActions ) { mAkonadiStandardActionManager->createAction( standardAction ); } if (mEnableFavoriteFolderView) { QList favoriteActions; favoriteActions << StandardActionManager::AddToFavoriteCollections << StandardActionManager::RemoveFromFavoriteCollections << StandardActionManager::RenameFavoriteCollection << StandardActionManager::SynchronizeFavoriteCollections; Q_FOREACH( StandardActionManager::Type favoriteAction, favoriteActions) { mAkonadiStandardActionManager->createAction( favoriteAction ); } } QList mailActions; mailActions << StandardMailActionManager::MarkAllMailAsRead << StandardMailActionManager::MoveToTrash << StandardMailActionManager::MoveAllToTrash << StandardMailActionManager::RemoveDuplicates << StandardMailActionManager::EmptyAllTrash << StandardMailActionManager::MarkMailAsRead << StandardMailActionManager::MarkMailAsUnread << StandardMailActionManager::MarkMailAsImportant << StandardMailActionManager::MarkMailAsActionItem; Q_FOREACH( StandardMailActionManager::Type mailAction, mailActions ) { mAkonadiStandardActionManager->createAction( mailAction ); } mAkonadiStandardActionManager->interceptAction( Akonadi::StandardActionManager::CollectionProperties ); connect( mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::CollectionProperties ), SIGNAL(triggered(bool)), this, SLOT(slotCollectionProperties()) ); // // Create all kinds of actions // mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::RemoveDuplicates )->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_Asterisk ) ); mAkonadiStandardActionManager->interceptAction( Akonadi::StandardMailActionManager::RemoveDuplicates ); connect( mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::RemoveDuplicates ), SIGNAL(triggered(bool)), this, SLOT(slotRemoveDuplicates()) ); { mCollectionProperties = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::CollectionProperties ); } connect( kmkernel->folderCollectionMonitor(), SIGNAL(itemAdded(Akonadi::Item,Akonadi::Collection)), SLOT(slotItemAdded(Akonadi::Item,Akonadi::Collection)) ); connect( kmkernel->folderCollectionMonitor(), SIGNAL(itemRemoved(Akonadi::Item)), SLOT(slotItemRemoved(Akonadi::Item)) ); connect( kmkernel->folderCollectionMonitor(), SIGNAL(itemMoved(Akonadi::Item,Akonadi::Collection,Akonadi::Collection)), SLOT(slotItemMoved(Akonadi::Item,Akonadi::Collection,Akonadi::Collection)) ); connect( kmkernel->folderCollectionMonitor(), SIGNAL(collectionChanged(Akonadi::Collection,QSet)), SLOT(slotCollectionChanged(Akonadi::Collection,QSet)) ); connect( kmkernel->folderCollectionMonitor(), SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)), SLOT(slotCollectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)) ); } void KMMainWidget::updateMoveAction( const Akonadi::CollectionStatistics& statistic ) { const bool hasUnreadMails = (statistic.unreadCount() > 0); const bool hasMails = (statistic.count()>0); updateMoveAction(hasUnreadMails,hasMails); } void KMMainWidget::updateMoveAction( bool hasUnreadMails, bool hasMails ) { const bool enable_goto_unread = hasUnreadMails || (GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInAllFolders) || (GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInAllMarkedFolders); actionCollection()->action( QLatin1String("go_next_message") )->setEnabled( hasMails ); actionCollection()->action( QLatin1String("go_next_unread_message") )->setEnabled( enable_goto_unread ); actionCollection()->action( QLatin1String("go_prev_message") )->setEnabled( hasMails ); actionCollection()->action( QLatin1String("go_prev_unread_message") )->setEnabled( enable_goto_unread ); if ( mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::MarkAllMailAsRead ) ) { mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::MarkAllMailAsRead )->setEnabled(hasUnreadMails); } } void KMMainWidget::updateAllToTrashAction(int statistics) { bool multiFolder = false; if ( mFolderTreeWidget ) { multiFolder = mFolderTreeWidget->selectedCollections().count() > 1; } if ( mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::MoveAllToTrash ) ) { const bool folderWithContent = mCurrentFolder && !mCurrentFolder->isStructural(); mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::MoveAllToTrash )->setEnabled( folderWithContent && ( statistics > 0 ) && mCurrentFolder->canDeleteMessages() && !multiFolder ); } } void KMMainWidget::slotCollectionStatisticsChanged( const Akonadi::Collection::Id id, const Akonadi::CollectionStatistics& statistic ) { if ( id == CommonKernel->outboxCollectionFolder().id() ) { const qint64 nbMsgOutboxCollection = statistic.count(); mSendQueued->setEnabled( nbMsgOutboxCollection > 0 ); mSendActionMenu->setEnabled( nbMsgOutboxCollection > 0 ); } else if ( mCurrentFolder && ( id == mCurrentFolder->collection().id() ) ) { updateMoveAction( statistic ); updateAllToTrashAction(statistic.count()); mCurrentFolder->setCollection(MailCommon::Util::updatedCollection( mCurrentFolder->collection() )); } } void KMMainWidget::slotCreateNewTab( bool preferNewTab ) { mMessagePane->setPreferEmptyTab( preferNewTab ); } void KMMainWidget::slotCollectionChanged( const Akonadi::Collection&collection, const QSet&set ) { if ( mCurrentFolder && ( collection == mCurrentFolder->collection() ) && ( set.contains( "MESSAGEFOLDER" ) || set.contains( "expirationcollectionattribute" ) ) ) { if ( set.contains( "MESSAGEFOLDER" ) ) mMessagePane->resetModelStorage(); else { mCurrentFolder->setCollection( collection ); } } else if ( set.contains( "ENTITYDISPLAY" ) || set.contains( "NAME" ) ) { QIcon icon = KIcon( QLatin1String( "folder" ) ); QString text; const QModelIndex idx = Akonadi::EntityTreeModel::modelIndexForCollection( KMKernel::self()->collectionModel(), collection ); if ( idx.isValid() ) { text = idx.data().toString(); icon = idx.data( Qt::DecorationRole ).value(); mMessagePane->updateTabIconText( collection, text,icon ); } } } void KMMainWidget::slotItemAdded( const Akonadi::Item &msg, const Akonadi::Collection &col ) { if ( col.isValid() ) { if ( col == CommonKernel->outboxCollectionFolder() ) { startUpdateMessageActionsTimer(); } } } void KMMainWidget::slotItemRemoved( const Akonadi::Item & item) { if ( item.isValid() && item.parentCollection().isValid() && ( item.parentCollection() == CommonKernel->outboxCollectionFolder() ) ) { startUpdateMessageActionsTimer(); } } void KMMainWidget::slotItemMoved( const Akonadi::Item &item, const Akonadi::Collection &from, const Akonadi::Collection &to ) { if ( item.isValid() && ( ( from.id() == CommonKernel->outboxCollectionFolder().id() ) || to.id() == CommonKernel->outboxCollectionFolder().id() ) ) { startUpdateMessageActionsTimer(); } } //------------------------------------------------------------------------- void KMMainWidget::slotFocusQuickSearch() { mMessagePane->focusQuickSearch(); } //------------------------------------------------------------------------- bool KMMainWidget::slotSearch() { if (!mSearchWin) { mSearchWin = new SearchWindow(this, mCurrentFolder ? mCurrentFolder->collection() : Akonadi::Collection()); mSearchWin->setModal( false ); mSearchWin->setObjectName( QLatin1String("Search") ); } else { mSearchWin->activateFolder(mCurrentFolder ? mCurrentFolder->collection() : Akonadi::Collection()); } mSearchWin->show(); KWindowSystem::activateWindow( mSearchWin->winId() ); return true; } //----------------------------------------------------------------------------- void KMMainWidget::slotHelp() { KToolInvocation::invokeHelp(); } //----------------------------------------------------------------------------- void KMMainWidget::slotFilter() { FilterIf->openFilterDialog( true ); } void KMMainWidget::slotManageSieveScripts() { if ( !kmkernel->askToGoOnline() ) { return; } if (mManageSieveDialog) return; mManageSieveDialog = new KSieveUi::ManageSieveScriptsDialog( this ); mManageSieveDialog->show(); } //----------------------------------------------------------------------------- void KMMainWidget::slotAddrBook() { KRun::runCommand(QLatin1String("kaddressbook"), window()); } //----------------------------------------------------------------------------- void KMMainWidget::slotImport() { KRun::runCommand(QLatin1String("kmailcvt"), window()); } //----------------------------------------------------------------------------- void KMMainWidget::slotCheckMail() { kmkernel->checkMail(); } //----------------------------------------------------------------------------- void KMMainWidget::slotCheckMailOnStartup() { kmkernel->checkMailOnStartup(); } //----------------------------------------------------------------------------- void KMMainWidget::slotCheckOneAccount( QAction* item ) { if ( !item ) { return; } Akonadi::AgentInstance agent = Akonadi::AgentManager::self()->instance( item->data().toString() ); if ( agent.isValid() ) { if ( !agent.isOnline() ) { agent.setIsOnline( true ); } agent.synchronize(); } else { kDebug() << "account with identifier" << item->data().toString() << "not found"; } } //----------------------------------------------------------------------------- void KMMainWidget::slotCompose() { KMail::Composer * win; KMime::Message::Ptr msg( new KMime::Message() ); bool forceCursorPosition = false; if ( mCurrentFolder ) { MessageHelper::initHeader( msg, KMKernel::self()->identityManager(), mCurrentFolder->identity() ); //Laurent: bug 289905 /* if ( mCurrentFolder->collection().isValid() && mCurrentFolder->putRepliesInSameFolder() ) { KMime::Headers::Generic *header = new KMime::Headers::Generic( "X-KMail-Fcc", msg.get(), QString::number( mCurrentFolder->collection().id() ), "utf-8" ); msg->setHeader( header ); } */ TemplateParser::TemplateParser parser( msg, TemplateParser::TemplateParser::NewMessage ); parser.setIdentityManager( KMKernel::self()->identityManager() ); parser.process( msg, mCurrentFolder->collection() ); win = KMail::makeComposer( msg, false, false, KMail::Composer::New, mCurrentFolder->identity() ); win->setCollectionForNewMessage( mCurrentFolder->collection() ); forceCursorPosition = parser.cursorPositionWasSet(); } else { MessageHelper::initHeader( msg, KMKernel::self()->identityManager() ); TemplateParser::TemplateParser parser( msg, TemplateParser::TemplateParser::NewMessage ); parser.setIdentityManager( KMKernel::self()->identityManager() ); parser.process( KMime::Message::Ptr(), Akonadi::Collection() ); win = KMail::makeComposer( msg, false, false, KMail::Composer::New ); forceCursorPosition = parser.cursorPositionWasSet(); } if (forceCursorPosition) { win->setFocusToEditor(); } win->show(); } //----------------------------------------------------------------------------- // TODO: do we want the list sorted alphabetically? void KMMainWidget::slotShowNewFromTemplate() { if ( mCurrentFolder ) { const KPIMIdentities::Identity & ident = kmkernel->identityManager()->identityForUoidOrDefault( mCurrentFolder->identity() ); mTemplateFolder = CommonKernel->collectionFromId( ident.templates().toLongLong() ); } if ( !mTemplateFolder.isValid() ) { mTemplateFolder = CommonKernel->templatesCollectionFolder(); } if ( !mTemplateFolder.isValid() ) return; mTemplateMenu->menu()->clear(); Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( mTemplateFolder ); job->fetchScope().setAncestorRetrieval( ItemFetchScope::Parent ); job->fetchScope().fetchFullPayload(); connect( job, SIGNAL(result(KJob*)), SLOT(slotDelayedShowNewFromTemplate(KJob*)) ); } void KMMainWidget::slotDelayedShowNewFromTemplate( KJob *job ) { Akonadi::ItemFetchJob *fetchJob = qobject_cast( job ); const Akonadi::Item::List items = fetchJob->items(); const int numberOfItems = items.count(); for ( int idx = 0; idx < numberOfItems; ++idx ) { KMime::Message::Ptr msg = MessageCore::Util::message( items.at( idx ) ); if ( msg ) { QString subj = msg->subject()->asUnicodeString(); if ( subj.isEmpty() ) subj = i18n("No Subject"); QAction *templateAction = mTemplateMenu->menu()->addAction(KStringHandler::rsqueeze( subj.replace( QLatin1Char('&'), QLatin1String("&&") ) ) ); QVariant var; var.setValue( items.at( idx ) ); templateAction->setData( var ); } } // If there are no templates available, add a menu entry which informs // the user about this. if ( mTemplateMenu->menu()->actions().isEmpty() ) { QAction *noAction = mTemplateMenu->menu()->addAction( i18n( "(no templates)" ) ); noAction->setEnabled( false ); } } //----------------------------------------------------------------------------- void KMMainWidget::slotNewFromTemplate( QAction *action ) { if ( !mTemplateFolder.isValid() ) return; const Akonadi::Item item = action->data().value(); newFromTemplate( item ); } //----------------------------------------------------------------------------- void KMMainWidget::newFromTemplate( const Akonadi::Item &msg ) { if ( !msg.isValid() ) return; KMCommand *command = new KMUseTemplateCommand( this, msg ); command->start(); } //----------------------------------------------------------------------------- void KMMainWidget::slotPostToML() { if ( mCurrentFolder && mCurrentFolder->isMailingListEnabled() ) { if (KMail::Util::mailingListPost( mCurrentFolder )) { return; } } slotCompose(); } //----------------------------------------------------------------------------- void KMMainWidget::slotFolderMailingListProperties() { showCollectionProperties( QLatin1String( "KMail::CollectionMailingListPage" ) ); } //----------------------------------------------------------------------------- void KMMainWidget::slotShowFolderShortcutDialog() { showCollectionProperties( QLatin1String( "KMail::CollectionShortcutPage" ) ); } //----------------------------------------------------------------------------- void KMMainWidget::slotExpireFolder() { if ( !mCurrentFolder ) return; bool mustDeleteExpirationAttribute = false; MailCommon::ExpireCollectionAttribute *attr = MailCommon::ExpireCollectionAttribute::expirationCollectionAttribute( mCurrentFolder->collection(), mustDeleteExpirationAttribute ); ; bool canBeExpired = true; if ( !attr->isAutoExpire() ) { canBeExpired = false; } else if ( attr->unreadExpireUnits() == MailCommon::ExpireCollectionAttribute::ExpireNever && attr->readExpireUnits() == MailCommon::ExpireCollectionAttribute::ExpireNever ) { canBeExpired = false; } if ( !canBeExpired ) { const QString message = i18n( "This folder does not have any expiry options set" ); KMessageBox::information( this, message ); if ( mustDeleteExpirationAttribute ) delete attr; return; } if ( GlobalSettings::self()->warnBeforeExpire() ) { const QString message = i18n( "Are you sure you want to expire the folder %1?", Qt::escape( mCurrentFolder->name() ) ); if ( KMessageBox::warningContinueCancel( this, message, i18n( "Expire Folder" ), KGuiItem( i18n( "&Expire" ) ) ) != KMessageBox::Continue ) { if ( mustDeleteExpirationAttribute ) delete attr; return; } } MailCommon::Util::expireOldMessages( mCurrentFolder->collection(), true /*immediate*/ ); if ( mustDeleteExpirationAttribute ) delete attr; } //----------------------------------------------------------------------------- void KMMainWidget::slotEmptyFolder() { if (!mCurrentFolder) return; const bool isTrash = CommonKernel->folderIsTrash( mCurrentFolder->collection() ); if ( GlobalSettings::self()->confirmBeforeEmpty() ) { const QString title = (isTrash) ? i18n("Empty Trash") : i18n("Move to Trash"); const QString text = (isTrash) ? i18n("Are you sure you want to empty the trash folder?") : i18n("Are you sure you want to move all messages from " "folder %1 to the trash?", Qt::escape( mCurrentFolder->name() ) ); if (KMessageBox::warningContinueCancel(this, text, title, KGuiItem( title, QLatin1String("user-trash"))) != KMessageBox::Continue) return; } #ifndef QT_NO_CURSOR MessageViewer::KCursorSaver busy( MessageViewer::KBusyPtr::busy() ); #endif slotMarkAll(); if (isTrash) { /* Don't ask for confirmation again when deleting, the user has already confirmed. */ slotDeleteMsg( false ); } else slotTrashSelectedMessages(); if (mMsgView) mMsgView->clearCache(); if ( !isTrash ) BroadcastStatus::instance()->setStatusMsg(i18n("Moved all messages to the trash")); updateMessageActions(); // Disable empty trash/move all to trash action - we've just deleted/moved // all folder contents. mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::MoveAllToTrash )->setEnabled( false ); } //----------------------------------------------------------------------------- void KMMainWidget::slotArchiveFolder() { if ( mCurrentFolder && mCurrentFolder->collection().isValid() ) { KMail::ArchiveFolderDialog archiveDialog; archiveDialog.setFolder( mCurrentFolder->collection() ); archiveDialog.exec(); } } //----------------------------------------------------------------------------- void KMMainWidget::slotRemoveFolder() { if ( !mCurrentFolder ) return; if ( !mCurrentFolder->collection().isValid() ) return; if ( mCurrentFolder->isSystemFolder() ) return; if ( mCurrentFolder->isReadOnly() ) return; Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob( mCurrentFolder->collection(), CollectionFetchJob::FirstLevel, this ); job->fetchScope().setContentMimeTypes( QStringList() << KMime::Message::mimeType() ); job->setProperty( "collectionId", mCurrentFolder->collection().id() ); connect( job, SIGNAL(result(KJob*)), SLOT(slotDelayedRemoveFolder(KJob*)) ); } void KMMainWidget::slotDelayedRemoveFolder( KJob *job ) { const Akonadi::CollectionFetchJob *fetchJob = qobject_cast( job ); Akonadi::Collection::List listOfCollection = fetchJob->collections(); const bool hasNotSubDirectory = listOfCollection.isEmpty(); const Akonadi::Collection::Id id = fetchJob->property( "collectionId" ).toLongLong(); Akonadi::Collection col = MailCommon::Util::updatedCollection(CommonKernel->collectionFromId( id )); QDir dir; QString str; QString title; QString buttonLabel; if ( col.resource() == QLatin1String( "akonadi_search_resource" ) ) { title = i18n("Delete Search"); str = i18n("Are you sure you want to delete the search %1?
" "Any messages it shows will still be available in their original folder.
", Qt::escape( col.name() ) ); buttonLabel = i18nc("@action:button Delete search", "&Delete"); } else { title = i18n("Delete Folder"); if ( col.statistics().count() == 0 ) { if ( hasNotSubDirectory ) { str = i18n("Are you sure you want to delete the empty folder " "%1?", Qt::escape( col.name() ) ); } else { str = i18n("Are you sure you want to delete the empty folder " "%1 and all its subfolders? Those subfolders might " "not be empty and their contents will be discarded as well. " "

Beware that discarded messages are not saved " "into your Trash folder and are permanently deleted.

", Qt::escape( col.name() ) ); } } else { if ( hasNotSubDirectory ) { str = i18n("Are you sure you want to delete the folder " "%1, discarding its contents? " "

Beware that discarded messages are not saved " "into your Trash folder and are permanently deleted.

", Qt::escape( col.name() ) ); }else { str = i18n("Are you sure you want to delete the folder %1 " "and all its subfolders, discarding their contents? " "

Beware that discarded messages are not saved " "into your Trash folder and are permanently deleted.

", Qt::escape( col.name() ) ); } } buttonLabel = i18nc("@action:button Delete folder", "&Delete"); } if ( KMessageBox::warningContinueCancel( this, str, title, KGuiItem( buttonLabel, QLatin1String("edit-delete" )), KStandardGuiItem::cancel(), QString(), KMessageBox::Notify | KMessageBox::Dangerous ) == KMessageBox::Continue ) { kmkernel->checkFolderFromResources( listOfCollection<collection().id()) mCurrentFolder.clear(); Akonadi::CollectionDeleteJob *job = new Akonadi::CollectionDeleteJob( col ); connect( job, SIGNAL(result(KJob*)), this, SLOT(slotDeletionCollectionResult(KJob*)) ); } } void KMMainWidget::slotDeletionCollectionResult(KJob* job) { if ( job ) { if (Util::showJobErrorMessage( job )) { return; } } } //----------------------------------------------------------------------------- void KMMainWidget::slotExpireAll() { if ( GlobalSettings::self()->warnBeforeExpire() ) { const int ret = KMessageBox::warningContinueCancel(KMainWindow::memberList().first(), i18n("Are you sure you want to expire all old messages?"), i18n("Expire Old Messages?"), KGuiItem(i18n("Expire"))); if (ret != KMessageBox::Continue) { return; } } kmkernel->expireAllFoldersNow(); } //----------------------------------------------------------------------------- void KMMainWidget::slotOverrideHtml() { if ( mHtmlPref == mFolderHtmlPref ) { int result = KMessageBox::warningContinueCancel( this, // the warning text is taken from configuredialog.cpp: i18n( "Use of HTML in mail will make you more vulnerable to " "\"spam\" and may increase the likelihood that your system will be " "compromised by other present and anticipated security exploits." ), i18n( "Security Warning" ), KGuiItem(i18n( "Use HTML" )), KStandardGuiItem::cancel(), QLatin1String("OverrideHtmlWarning"), 0); if ( result == KMessageBox::Cancel ) { mPreferHtmlAction->setChecked( false ); return; } } mFolderHtmlPref = !mFolderHtmlPref; //Update mPrefererHtmlLoadExtAction mPreferHtmlLoadExtAction->setEnabled( mCurrentFolder && (mHtmlPref ? !mFolderHtmlPref : mFolderHtmlPref) ? true : false ); if (mMsgView) { mMsgView->setHtmlOverride(mFolderHtmlPref); mMsgView->update( true ); } } //----------------------------------------------------------------------------- void KMMainWidget::slotOverrideHtmlLoadExt() { if ( mHtmlLoadExtPref == mFolderHtmlLoadExtPref ) { int result = KMessageBox::warningContinueCancel( this, // the warning text is taken from configuredialog.cpp: i18n( "Loading external references in html mail will make you more vulnerable to " "\"spam\" and may increase the likelihood that your system will be " "compromised by other present and anticipated security exploits." ), i18n( "Security Warning" ), KGuiItem(i18n( "Load External References" )), KStandardGuiItem::cancel(), QLatin1String("OverrideHtmlLoadExtWarning"), 0); if ( result == KMessageBox::Cancel ) { mPreferHtmlLoadExtAction->setChecked( false ); return; } } mFolderHtmlLoadExtPref = !mFolderHtmlLoadExtPref; if (mMsgView) { mMsgView->setHtmlLoadExtOverride(mFolderHtmlLoadExtPref); mMsgView->update( true ); } } //----------------------------------------------------------------------------- void KMMainWidget::slotMessageQueuedOrDrafted() { if (!CommonKernel->folderIsDraftOrOutbox(mCurrentFolder->collection())) return; if (mMsgView) mMsgView->update(true); } //----------------------------------------------------------------------------- void KMMainWidget::slotForwardInlineMsg() { if ( !mCurrentFolder ) { return; } const QList selectedMessages = mMessagePane->selectionAsMessageItemList(); if ( selectedMessages.isEmpty() ) return; KMForwardCommand * command = new KMForwardCommand( this, selectedMessages, mCurrentFolder->identity() ); command->start(); } //----------------------------------------------------------------------------- void KMMainWidget::slotForwardAttachedMsg() { if ( !mCurrentFolder ) { return; } const QList selectedMessages = mMessagePane->selectionAsMessageItemList(); if ( selectedMessages.isEmpty() ) return; KMForwardAttachedCommand * command = new KMForwardAttachedCommand( this, selectedMessages, mCurrentFolder->identity() ); command->start(); } //----------------------------------------------------------------------------- void KMMainWidget::slotUseTemplate() { newFromTemplate( mMessagePane->currentItem() ); } //----------------------------------------------------------------------------- void KMMainWidget::slotResendMsg() { const Akonadi::Item msg = mMessagePane->currentItem(); if ( !msg.isValid() ) return; KMCommand *command = new KMResendMessageCommand( this, msg ); command->start(); } //----------------------------------------------------------------------------- // Message moving and permanent deletion // void KMMainWidget::moveMessageSelected( MessageList::Core::MessageItemSetReference ref, const Akonadi::Collection &dest, bool confirmOnDeletion ) { QList selectMsg = mMessagePane->itemListFromPersistentSet( ref ); // If this is a deletion, ask for confirmation if ( !dest.isValid() && confirmOnDeletion ) { int ret = KMessageBox::warningContinueCancel( this, i18np( "Do you really want to delete the selected message?
" "Once deleted, it cannot be restored.
", "Do you really want to delete the %1 selected messages?
" "Once deleted, they cannot be restored.
", selectMsg.count() ), selectMsg.count() > 1 ? i18n( "Delete Messages" ) : i18n( "Delete Message" ), KStandardGuiItem::del(), KStandardGuiItem::cancel(), QLatin1String("NoConfirmDelete") ); if ( ret == KMessageBox::Cancel ) { mMessagePane->deletePersistentSet( ref ); return; // user canceled the action } } mMessagePane->markMessageItemsAsAboutToBeRemoved( ref, true ); // And stuff them into a KMMoveCommand :) KMMoveCommand *command = new KMMoveCommand( dest, selectMsg,ref ); QObject::connect( command, SIGNAL(moveDone(KMMoveCommand*)), this, SLOT(slotMoveMessagesCompleted(KMMoveCommand*)) ); command->start(); if ( dest.isValid() ) BroadcastStatus::instance()->setStatusMsg( i18n( "Moving messages..." ) ); else BroadcastStatus::instance()->setStatusMsg( i18n( "Deleting messages..." ) ); } void KMMainWidget::slotMoveMessagesCompleted( KMMoveCommand *command ) { Q_ASSERT( command ); mMessagePane->markMessageItemsAsAboutToBeRemoved( command->refSet(), false ); mMessagePane->deletePersistentSet( command->refSet() ); // Bleah :D const bool moveWasReallyADelete = !command->destFolder().isValid(); if ( command->result() == KMCommand::OK ) { if ( moveWasReallyADelete ) BroadcastStatus::instance()->setStatusMsg( i18n( "Messages deleted successfully." ) ); else BroadcastStatus::instance()->setStatusMsg( i18n( "Messages moved successfully." ) ); } else { if ( moveWasReallyADelete ) { if ( command->result() == KMCommand::Failed ) BroadcastStatus::instance()->setStatusMsg( i18n( "Deleting messages failed." ) ); else BroadcastStatus::instance()->setStatusMsg( i18n( "Deleting messages canceled." ) ); } else { if ( command->result() == KMCommand::Failed ) BroadcastStatus::instance()->setStatusMsg( i18n( "Moving messages failed." ) ); else BroadcastStatus::instance()->setStatusMsg( i18n( "Moving messages canceled." ) ); } } // The command will autodelete itself and will also kill the set. } void KMMainWidget::slotDeleteMsg( bool confirmDelete ) { // Create a persistent message set from the current selection MessageList::Core::MessageItemSetReference ref = mMessagePane->selectionAsPersistentSet(); if ( ref != -1 ) moveMessageSelected( ref, Akonadi::Collection(), confirmDelete ); } void KMMainWidget::slotDeleteThread( bool confirmDelete ) { // Create a persistent set from the current thread. MessageList::Core::MessageItemSetReference ref = mMessagePane->currentThreadAsPersistentSet(); if ( ref != -1 ) moveMessageSelected( ref, Akonadi::Collection(), confirmDelete ); } FolderSelectionDialog* KMMainWidget::moveOrCopyToDialog() { if ( !mMoveOrCopyToDialog ) { FolderSelectionDialog::SelectionFolderOption options = FolderSelectionDialog::HideVirtualFolder; mMoveOrCopyToDialog = new FolderSelectionDialog( this, options ); mMoveOrCopyToDialog->setModal( true ); } return mMoveOrCopyToDialog; } FolderSelectionDialog* KMMainWidget::selectFromAllFoldersDialog() { if ( !mSelectFromAllFoldersDialog ) { FolderSelectionDialog::SelectionFolderOptions options = FolderSelectionDialog::None; options |= FolderSelectionDialog::NotAllowToCreateNewFolder; mSelectFromAllFoldersDialog = new FolderSelectionDialog( this, options ); mSelectFromAllFoldersDialog->setModal( true ); } return mSelectFromAllFoldersDialog; } void KMMainWidget::slotMoveSelectedMessageToFolder() { QPointer dialog( moveOrCopyToDialog() ); dialog->setCaption( i18n( "Move Messages to Folder" ) ); if ( dialog->exec() && dialog ) { const Akonadi::Collection dest = dialog->selectedCollection(); if ( dest.isValid() ) { moveSelectedMessagesToFolder( dest ); } } } void KMMainWidget::moveSelectedMessagesToFolder( const Akonadi::Collection & dest ) { MessageList::Core::MessageItemSetReference ref = mMessagePane->selectionAsPersistentSet(); if ( ref != -1 ) { //Need to verify if dest == src ??? akonadi do it for us. moveMessageSelected( ref, dest, false ); } } void KMMainWidget::copyMessageSelected( const QList &selectMsg, const Akonadi::Collection &dest ) { if ( selectMsg.isEmpty() ) return; // And stuff them into a KMCopyCommand :) KMCommand *command = new KMCopyCommand( dest, selectMsg ); QObject::connect( command, SIGNAL(completed(KMCommand*)), this, SLOT(slotCopyMessagesCompleted(KMCommand*)) ); command->start(); BroadcastStatus::instance()->setStatusMsg( i18n( "Copying messages..." ) ); } void KMMainWidget::slotCopyMessagesCompleted( KMCommand *command ) { Q_ASSERT( command ); if ( command->result() == KMCommand::OK ) { BroadcastStatus::instance()->setStatusMsg( i18n( "Messages copied successfully." ) ); } else { if ( command->result() == KMCommand::Failed ) BroadcastStatus::instance()->setStatusMsg( i18n( "Copying messages failed." ) ); else BroadcastStatus::instance()->setStatusMsg( i18n( "Copying messages canceled." ) ); } // The command will autodelete itself and will also kill the set. } void KMMainWidget::slotCopySelectedMessagesToFolder() { QPointer dialog( moveOrCopyToDialog() ); dialog->setCaption( i18n( "Copy Messages to Folder" ) ); if ( dialog->exec() && dialog ) { const Akonadi::Collection dest = dialog->selectedCollection(); if ( dest.isValid() ) { copySelectedMessagesToFolder( dest ); } } } void KMMainWidget::copySelectedMessagesToFolder( const Akonadi::Collection& dest ) { const QList lstMsg = mMessagePane->selectionAsMessageItemList(); if ( !lstMsg.isEmpty() ) { copyMessageSelected( lstMsg, dest ); } } //----------------------------------------------------------------------------- // Message trashing // void KMMainWidget::trashMessageSelected( MessageList::Core::MessageItemSetReference ref ) { if ( !mCurrentFolder ) { return; } const QList select = mMessagePane->itemListFromPersistentSet( ref ); mMessagePane->markMessageItemsAsAboutToBeRemoved( ref, true ); // FIXME: Why we don't use KMMoveCommand( trashFolder(), selectedMessages ); ? // And stuff them into a KMTrashMsgCommand :) KMCommand *command = new KMTrashMsgCommand( mCurrentFolder->collection(), select,ref ); QObject::connect( command, SIGNAL(moveDone(KMMoveCommand*)), this, SLOT(slotTrashMessagesCompleted(KMMoveCommand*)) ); command->start(); BroadcastStatus::instance()->setStatusMsg( i18n( "Moving messages to trash..." ) ); } void KMMainWidget::slotTrashMessagesCompleted( KMMoveCommand *command ) { Q_ASSERT( command ); mMessagePane->markMessageItemsAsAboutToBeRemoved( command->refSet(), false ); mMessagePane->deletePersistentSet( command->refSet() ); if ( command->result() == KMCommand::OK ) { BroadcastStatus::instance()->setStatusMsg( i18n( "Messages moved to trash successfully." ) ); } else { if ( command->result() == KMCommand::Failed ) { BroadcastStatus::instance()->setStatusMsg( i18n( "Moving messages to trash failed." ) ); } else BroadcastStatus::instance()->setStatusMsg( i18n( "Moving messages to trash canceled." ) ); } // The command will autodelete itself and will also kill the set. } void KMMainWidget::slotTrashSelectedMessages() { MessageList::Core::MessageItemSetReference ref = mMessagePane->selectionAsPersistentSet(); if ( ref != -1 ) { trashMessageSelected( ref ); } } void KMMainWidget::slotTrashThread() { MessageList::Core::MessageItemSetReference ref = mMessagePane->currentThreadAsPersistentSet(); if ( ref != -1 ) trashMessageSelected( ref ); } //----------------------------------------------------------------------------- // Message tag setting for messages // // FIXME: The "selection" version of these functions is in MessageActions. // We should probably move everything there.... void KMMainWidget::toggleMessageSetTag( const QList &select, const Akonadi::Tag &tag ) { if ( select.isEmpty() ) return; KMCommand *command = new KMSetTagCommand( Akonadi::Tag::List() << tag, select, KMSetTagCommand::Toggle ); command->start(); } void KMMainWidget::slotSelectMoreMessageTagList() { const QList selectedMessages = mMessagePane->selectionAsMessageItemList(); if ( selectedMessages.isEmpty() ) return; TagSelectDialog dlg( this, selectedMessages.count(), selectedMessages.first() ); if ( dlg.exec() ) { const Akonadi::Tag::List lst = dlg.selectedTag(); KMCommand *command = new KMSetTagCommand( lst, selectedMessages, KMSetTagCommand::CleanExistingAndAddNew ); command->start(); } } void KMMainWidget::slotUpdateMessageTagList( const Akonadi::Tag &tag ) { // Create a persistent set from the current thread. const QList selectedMessages = mMessagePane->selectionAsMessageItemList(); if ( selectedMessages.isEmpty() ) return; toggleMessageSetTag( selectedMessages, tag ); } void KMMainWidget::refreshMessageListSelection() { mAkonadiStandardActionManager->setItemSelectionModel( mMessagePane->currentItemSelectionModel() ); slotMessageSelected(mMessagePane->currentItem()); } //----------------------------------------------------------------------------- // Status setting for threads // // FIXME: The "selection" version of these functions is in MessageActions. // We should probably move everything there.... void KMMainWidget::setMessageSetStatus( const QList &select, const Akonadi::MessageStatus &status, bool toggle ) { KMCommand *command = new KMSetStatusCommand( status, select, toggle ); command->start(); } void KMMainWidget::setCurrentThreadStatus( const Akonadi::MessageStatus &status, bool toggle ) { const QList select = mMessagePane->currentThreadAsMessageList(); if ( select.isEmpty() ) return; setMessageSetStatus( select, status, toggle ); } void KMMainWidget::slotSetThreadStatusUnread() { setCurrentThreadStatus( MessageStatus::statusRead(), true ); } void KMMainWidget::slotSetThreadStatusImportant() { setCurrentThreadStatus( MessageStatus::statusImportant(), true ); } void KMMainWidget::slotSetThreadStatusRead() { setCurrentThreadStatus( MessageStatus::statusRead(), false ); } void KMMainWidget::slotSetThreadStatusToAct() { setCurrentThreadStatus( MessageStatus::statusToAct(), true ); } void KMMainWidget::slotSetThreadStatusWatched() { setCurrentThreadStatus( MessageStatus::statusWatched(), true ); if ( mWatchThreadAction->isChecked() ) mIgnoreThreadAction->setChecked(false); } void KMMainWidget::slotSetThreadStatusIgnored() { setCurrentThreadStatus( MessageStatus::statusIgnored(), true ); if ( mIgnoreThreadAction->isChecked() ) mWatchThreadAction->setChecked(false); } //----------------------------------------------------------------------------- void KMMainWidget::slotRedirectMsg() { const QList selectedMessages = mMessagePane->selectionAsMessageItemList(); if ( selectedMessages.isEmpty() ) return; KMCommand *command = new KMRedirectCommand( this, selectedMessages ); command->start(); } //----------------------------------------------------------------------------- void KMMainWidget::slotCustomReplyToMsg( const QString &tmpl ) { const Akonadi::Item msg = mMessagePane->currentItem(); if ( !msg.isValid() ) return; const QString text = mMsgView ? mMsgView->copyText() : QString(); kDebug() << "Reply with template:" << tmpl; KMCommand *command = new KMReplyCommand( this, msg, MessageComposer::ReplySmart, text, false, tmpl ); command->start(); } //----------------------------------------------------------------------------- void KMMainWidget::slotCustomReplyAllToMsg( const QString &tmpl ) { const Akonadi::Item msg = mMessagePane->currentItem(); if ( !msg.isValid() ) return; const QString text = mMsgView? mMsgView->copyText() : QString(); kDebug() << "Reply to All with template:" << tmpl; KMCommand *command = new KMReplyCommand(this, msg, MessageComposer::ReplyAll, text, false, tmpl ); command->start(); } //----------------------------------------------------------------------------- void KMMainWidget::slotCustomForwardMsg( const QString &tmpl ) { if ( !mCurrentFolder ) { return; } const QList selectedMessages = mMessagePane->selectionAsMessageItemList(); if ( selectedMessages.isEmpty() ) return; kDebug() << "Forward with template:" << tmpl; KMForwardCommand * command = new KMForwardCommand( this, selectedMessages, mCurrentFolder->identity(), tmpl ); command->start(); } void KMMainWidget::openFilterDialog(const QByteArray &field, const QString &value) { FilterIf->openFilterDialog( false ); FilterIf->createFilter( field, value ); } //----------------------------------------------------------------------------- void KMMainWidget::slotSubjectFilter() { const KMime::Message::Ptr msg = mMessagePane->currentMessage(); if ( !msg ) return; openFilterDialog("Subject", msg->subject()->asUnicodeString()); } //----------------------------------------------------------------------------- void KMMainWidget::slotFromFilter() { KMime::Message::Ptr msg = mMessagePane->currentMessage(); if ( !msg ) return; AddrSpecList al = MessageHelper::extractAddrSpecs( msg, "From" ); if ( al.empty() ) openFilterDialog("From", msg->from()->asUnicodeString()); else openFilterDialog("From", al.front().asString()); } //----------------------------------------------------------------------------- void KMMainWidget::slotToFilter() { KMime::Message::Ptr msg = mMessagePane->currentMessage(); if ( !msg ) return; openFilterDialog("To", msg->to()->asUnicodeString()); } //----------------------------------------------------------------------------- void KMMainWidget::slotUndo() { kmkernel->undoStack()->undo(); updateMessageActions(); updateFolderMenu(); } //----------------------------------------------------------------------------- void KMMainWidget::slotJumpToFolder() { QPointer dialog( selectFromAllFoldersDialog() ); dialog->setCaption( i18n( "Jump to Folder") ); if ( dialog->exec() && dialog ) { Akonadi::Collection collection = dialog->selectedCollection(); if ( collection.isValid() ) { slotSelectCollectionFolder( collection ); } } } void KMMainWidget::slotSelectCollectionFolder( const Akonadi::Collection & col ) { if ( mFolderTreeWidget ) { mFolderTreeWidget->selectCollectionFolder( col ); slotFolderChanged( col ); } } void KMMainWidget::slotApplyFilters() { const QList selectedMessages = mMessagePane->selectionAsMessageItemList(); if ( selectedMessages.isEmpty() ) return; applyFilters( selectedMessages ); } void KMMainWidget::slotApplyFiltersOnFolder() { if ( mCurrentFolder && mCurrentFolder->collection().isValid() ) { Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( mCurrentFolder->collection(), this ); connect( job, SIGNAL(result(KJob*)), this, SLOT(slotFetchItemsForFolderDone(KJob*)) ); } } void KMMainWidget::slotFetchItemsForFolderDone(KJob*job) { Akonadi::ItemFetchJob *fjob = dynamic_cast( job ); Q_ASSERT( fjob ); Akonadi::Item::List items = fjob->items(); applyFilters( items ); } void KMMainWidget::applyFilters( const QList& selectedMessages ) { #ifndef QT_NO_CURSOR MessageViewer::KCursorSaver busy( MessageViewer::KBusyPtr::busy() ); #endif MailCommon::FilterManager::instance()->filter( selectedMessages ); } //----------------------------------------------------------------------------- void KMMainWidget::slotCheckVacation() { updateVacationScriptStatus( false ); if ( !kmkernel->askToGoOnline() ) return; mVacationManager->checkVacation(); connect(mVacationManager, SIGNAL(updateVacationScriptStatus(bool,QString)), SLOT(updateVacationScriptStatus(bool,QString)) ); connect(mVacationManager, SIGNAL(editVacation()), SLOT(slotEditVacation()) ); } void KMMainWidget::slotEditVacation(const QString &serverName) { if ( !kmkernel->askToGoOnline() ) { return; } mVacationManager->slotEditVacation(serverName); } //----------------------------------------------------------------------------- void KMMainWidget::slotDebugSieve() { #if !defined(NDEBUG) if ( mSieveDebugDialog ) return; mSieveDebugDialog = new KSieveUi::SieveDebugDialog( this ); mSieveDebugDialog->exec(); delete mSieveDebugDialog; #endif } //----------------------------------------------------------------------------- void KMMainWidget::slotStartCertManager() { if ( !QProcess::startDetached(QLatin1String("kleopatra") ) ) KMessageBox::error( this, i18n( "Could not start certificate manager; " "please check your installation." ), i18n( "KMail Error" ) ); else kDebug() << "\nslotStartCertManager(): certificate manager started."; } //----------------------------------------------------------------------------- void KMMainWidget::slotStartWatchGnuPG() { if ( !QProcess::startDetached(QLatin1String("kwatchgnupg")) ) KMessageBox::error( this, i18n( "Could not start GnuPG LogViewer (kwatchgnupg); " "please check your installation." ), i18n( "KMail Error" ) ); } //----------------------------------------------------------------------------- void KMMainWidget::slotConfigChanged() { readConfig(); mMsgActions->setupForwardActions(); mMsgActions->setupForwardingActionsList( mGUIClient ); } //----------------------------------------------------------------------------- void KMMainWidget::slotSaveMsg() { const QList selectedMessages = mMessagePane->selectionAsMessageItemList(); if ( selectedMessages.isEmpty() ) return; KMSaveMsgCommand *saveCommand = new KMSaveMsgCommand( this, selectedMessages ); saveCommand->start(); } //----------------------------------------------------------------------------- void KMMainWidget::slotOpenMsg() { KMOpenMsgCommand *openCommand = new KMOpenMsgCommand( this, KUrl(), overrideEncoding(), this ); openCommand->start(); } //----------------------------------------------------------------------------- void KMMainWidget::slotSaveAttachments() { const QList selectedMessages = mMessagePane->selectionAsMessageItemList(); if ( selectedMessages.isEmpty() ) return; // Avoid re-downloading in the common case that only one message is selected, and the message // is also displayed in the viewer. For this, create a dummy item without a parent collection / item id, // so that KMCommand doesn't download it. KMSaveAttachmentsCommand *saveCommand = 0; if ( mMsgView && selectedMessages.size() == 1 && mMsgView->message().hasPayload() && selectedMessages.first().id() == mMsgView->message().id() ) { Akonadi::Item dummyItem; dummyItem.setPayload( mMsgView->message().payload() ); saveCommand = new KMSaveAttachmentsCommand( this, dummyItem ); } else { saveCommand = new KMSaveAttachmentsCommand( this, selectedMessages ); } saveCommand->start(); } void KMMainWidget::slotOnlineStatus() { // KMKernel will emit a signal when we toggle the network state that is caught by // KMMainWidget::slotUpdateOnlineStatus to update our GUI if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Online ) { // if online; then toggle and set it offline. kmkernel->stopNetworkJobs(); } else { kmkernel->resumeNetworkJobs(); slotCheckVacation(); } } void KMMainWidget::slotUpdateOnlineStatus( GlobalSettings::EnumNetworkState::type ) { if ( !mAkonadiStandardActionManager ) { return; } KAction * action = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::ToggleWorkOffline ); if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Online ) { action->setText( i18n("Work Offline") ); action->setIcon( KIcon(QLatin1String("user-offline")) ); } else { action->setText( i18n("Work Online") ); action->setIcon( KIcon(QLatin1String("user-online")) ); } } //----------------------------------------------------------------------------- void KMMainWidget::slotSendQueued() { if ( kmkernel->msgSender() ) { kmkernel->msgSender()->sendQueued(); } } //----------------------------------------------------------------------------- void KMMainWidget::slotSendQueuedVia( QAction *item ) { const QStringList availTransports = MailTransport::TransportManager::self()->transportNames(); if ( !availTransports.isEmpty() && availTransports.contains( item->text() ) ) { if ( kmkernel->msgSender() ) { kmkernel->msgSender()->sendQueued( item->text() ); } } } //----------------------------------------------------------------------------- void KMMainWidget::slotShowBusySplash() { if ( mReaderWindowActive ) { mMsgView->displayBusyPage(); } } void KMMainWidget::showOfflinePage() { if ( !mReaderWindowActive ) return; mMsgView->displayOfflinePage(); } void KMMainWidget::showResourceOfflinePage() { if ( !mReaderWindowActive ) return; mMsgView->displayResourceOfflinePage(); } //----------------------------------------------------------------------------- void KMMainWidget::slotReplaceMsgByUnencryptedVersion() { kDebug(); Akonadi::Item oldMsg = mMessagePane->currentItem(); if ( oldMsg.isValid() ) { #if 0 kDebug() << "Old message found"; if ( oldMsg->hasUnencryptedMsg() ) { kDebug() << "Extra unencrypted message found"; KMime::Message* newMsg = oldMsg->unencryptedMsg(); // adjust the message id { QString msgId( oldMsg->msgId() ); QString prefix("DecryptedMsg."); int oldIdx = msgId.indexOf(prefix, 0, Qt::CaseInsensitive); if ( -1 == oldIdx ) { int leftAngle = msgId.lastIndexOf( '<' ); msgId = msgId.insert( (-1 == leftAngle) ? 0 : ++leftAngle, prefix ); } else { // toggle between "DecryptedMsg." and "DeCryptedMsg." // to avoid same message id QCharRef c = msgId[ oldIdx+2 ]; if ( 'C' == c ) c = 'c'; else c = 'C'; } newMsg->setMsgId( msgId ); mMsgView->setIdOfLastViewedMessage( msgId ); } // insert the unencrypted message kDebug() << "Adding unencrypted message to folder"; mFolder->addMsg( newMsg ); /* Figure out its index in the folder for selecting. This must be count()-1, * since we append. Be safe and do find, though, just in case. */ int newMsgIdx = mFolder->find( newMsg ); Q_ASSERT( newMsgIdx != -1 ); /* we need this unget, to have the message displayed correctly initially */ mFolder->unGetMsg( newMsgIdx ); int idx = mFolder->find( oldMsg ); Q_ASSERT( idx != -1 ); /* only select here, so the old one is not un-Gotten before, which would * render the pointer we hold invalid so that find would fail */ #if 0 // FIXME (Pragma) mHeaders->setCurrentItemByIndex( newMsgIdx ); #endif // remove the old one if ( idx != -1 ) { kDebug() << "Deleting encrypted message"; mFolder->take( idx ); } kDebug() << "Updating message actions"; updateMessageActions(); kDebug() << "Done."; } else kDebug() << "NO EXTRA UNENCRYPTED MESSAGE FOUND"; #else kDebug() << "AKONADI PORT: Disabled code in " << Q_FUNC_INFO; #endif } else kDebug() << "PANIC: NO OLD MESSAGE FOUND"; } void KMMainWidget::slotFocusOnNextMessage() { mMessagePane->focusNextMessageItem(MessageList::Core::MessageTypeAny, true,false ); } void KMMainWidget::slotFocusOnPrevMessage() { mMessagePane->focusPreviousMessageItem( MessageList::Core::MessageTypeAny, true, false ); } void KMMainWidget::slotSelectFirstMessage() { mMessagePane->selectFirstMessageItem( MessageList::Core::MessageTypeAny, true ); } void KMMainWidget::slotSelectLastMessage() { mMessagePane->selectLastMessageItem( MessageList::Core::MessageTypeAny, true ); } void KMMainWidget::slotSelectFocusedMessage() { mMessagePane->selectFocusedMessageItem(true ); } void KMMainWidget::slotSelectNextMessage() { mMessagePane->selectNextMessageItem( MessageList::Core::MessageTypeAny, MessageList::Core::ClearExistingSelection, true, false ); } void KMMainWidget::slotExtendSelectionToNextMessage() { mMessagePane->selectNextMessageItem( MessageList::Core::MessageTypeAny, MessageList::Core::GrowOrShrinkExistingSelection, true, // center item false // don't loop in folder ); } void KMMainWidget::slotSelectNextUnreadMessage() { // The looping logic is: "Don't loop" just never loops, "Loop in current folder" // loops just in current folder, "Loop in all folders" loops in the current folder // first and then after confirmation jumps to the next folder. // A bad point here is that if you answer "No, and don't ask me again" to the confirmation // dialog then you have "Loop in current folder" and "Loop in all folders" that do // the same thing and no way to get the old behaviour. However, after a consultation on #kontact, // for bug-to-bug backward compatibility, the masters decided to keep it b0rken :D // If nobody complains, it stays like it is: if you complain enough maybe the masters will // decide to reconsider :) if ( !mMessagePane->selectNextMessageItem( MessageList::Core::MessageTypeUnreadOnly, MessageList::Core::ClearExistingSelection, true, // center item /*GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInCurrentFolder*/ GlobalSettings::self()->loopOnGotoUnread() != GlobalSettings::EnumLoopOnGotoUnread::DontLoop ) ) { // no next unread message was found in the current folder if ( ( GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInAllFolders ) || ( GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInAllMarkedFolders ) ) { mGoToFirstUnreadMessageInSelectedFolder = true; mFolderTreeWidget->folderTreeView()->selectNextUnreadFolder( true ); mGoToFirstUnreadMessageInSelectedFolder = false; } } } void KMMainWidget::slotSelectPreviousMessage() { mMessagePane->selectPreviousMessageItem( MessageList::Core::MessageTypeAny, MessageList::Core::ClearExistingSelection, true, false ); } void KMMainWidget::slotExtendSelectionToPreviousMessage() { mMessagePane->selectPreviousMessageItem( MessageList::Core::MessageTypeAny, MessageList::Core::GrowOrShrinkExistingSelection, true, // center item false // don't loop in folder ); } void KMMainWidget::slotSelectPreviousUnreadMessage() { if ( !mMessagePane->selectPreviousMessageItem( MessageList::Core::MessageTypeUnreadOnly, MessageList::Core::ClearExistingSelection, true, // center item GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInCurrentFolder ) ) { // no next unread message was found in the current folder if ( ( GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInAllFolders ) || ( GlobalSettings::self()->loopOnGotoUnread() == GlobalSettings::EnumLoopOnGotoUnread::LoopInAllMarkedFolders ) ) { mGoToFirstUnreadMessageInSelectedFolder = true; mFolderTreeWidget->folderTreeView()->selectPrevUnreadFolder(); mGoToFirstUnreadMessageInSelectedFolder = false; } } } void KMMainWidget::slotDisplayCurrentMessage() { if ( mMessagePane->currentItem().isValid() && !mMessagePane->searchEditHasFocus() ) slotMessageActivated( mMessagePane->currentItem() ); } // Called by double-clicked or 'Enter' in the messagelist -> pop up reader window void KMMainWidget::slotMessageActivated( const Akonadi::Item &msg ) { if ( !mCurrentFolder || !msg.isValid() ) return; if ( CommonKernel->folderIsDraftOrOutbox( mCurrentFolder->collection() ) ) { mMsgActions->setCurrentMessage( msg ); mMsgActions->editCurrentMessage(); return; } if ( CommonKernel->folderIsTemplates( mCurrentFolder->collection() ) ) { slotUseTemplate(); return; } // Try to fetch the mail, even in offline mode, it might be cached ItemFetchJob *itemFetchJob = MessageViewer::Viewer::createFetchJob( msg ); connect( itemFetchJob, SIGNAL(itemsReceived(Akonadi::Item::List)), SLOT(slotItemsFetchedForActivation(Akonadi::Item::List)) ); connect( itemFetchJob, SIGNAL(result(KJob*)), SLOT(itemsFetchForActivationDone(KJob*)) ); } void KMMainWidget::slotItemsFetchedForActivation( const Akonadi::Item::List &list ) { Q_ASSERT( list.size() == 1 ); const Item msg = list.first(); KMReaderMainWin *win = new KMReaderMainWin( mFolderHtmlPref, mFolderHtmlLoadExtPref ); const bool useFixedFont = mMsgView ? mMsgView->isFixedFont() : MessageViewer::GlobalSettings::self()->useFixedFont(); win->setUseFixedFont( useFixedFont ); const Akonadi::Collection parentCollection = MailCommon::Util::parentCollectionFromItem(msg); win->showMessage( overrideEncoding(), msg, parentCollection ); win->show(); } void KMMainWidget::itemsFetchForActivationDone( KJob * job ) { if ( job->error() ) { kDebug() << job->error() << job->errorString(); BroadcastStatus::instance()->setStatusMsg( job->errorString() ); } } void KMMainWidget::slotMessageStatusChangeRequest( const Akonadi::Item &item, const Akonadi::MessageStatus & set, const Akonadi::MessageStatus &clear ) { if ( !item.isValid() ) return; if ( clear.toQInt32() != Akonadi::MessageStatus().toQInt32() ) { KMCommand *command = new KMSetStatusCommand( clear, Akonadi::Item::List() << item, true ); command->start(); } if ( set.toQInt32() != Akonadi::MessageStatus().toQInt32() ) { KMCommand *command = new KMSetStatusCommand( set, Akonadi::Item::List() << item, false ); command->start(); } } //----------------------------------------------------------------------------- void KMMainWidget::slotMarkAll() { mMessagePane->selectAll(); updateMessageActions(); } void KMMainWidget::slotMessagePopup(const Akonadi::Item&msg ,const KUrl&aUrl,const KUrl &imageUrl,const QPoint& aPoint) { updateMessageMenu(); const QString email = KPIMUtils::firstEmailAddress( aUrl.path() ).toLower(); if ( aUrl.protocol() == QLatin1String("mailto") && !email.isEmpty()) { Akonadi::ContactSearchJob *job = new Akonadi::ContactSearchJob( this ); job->setLimit( 1 ); job->setQuery( Akonadi::ContactSearchJob::Email, email, Akonadi::ContactSearchJob::ExactMatch ); job->setProperty( "msg", QVariant::fromValue( msg ) ); job->setProperty( "point", aPoint ); job->setProperty( "imageUrl", imageUrl ); job->setProperty( "url", aUrl ); connect( job, SIGNAL(result(KJob*)), SLOT(slotContactSearchJobForMessagePopupDone(KJob*)) ); } else { showMessagePopup(msg, aUrl, imageUrl, aPoint, false, false); } } void KMMainWidget::slotContactSearchJobForMessagePopupDone( KJob *job ) { const Akonadi::ContactSearchJob *searchJob = qobject_cast( job ); const bool contactAlreadyExists = !searchJob->contacts().isEmpty(); const QList listContact = searchJob->items(); const bool uniqueContactFound = (listContact.count() == 1); if (uniqueContactFound) { mMsgView->setContactItem(listContact.first(), searchJob->contacts().at(0)); } else { mMsgView->clearContactItem(); } const Akonadi::Item msg = job->property( "msg" ).value(); const QPoint aPoint = job->property( "point" ).toPoint(); const KUrl imageUrl = job->property("imageUrl").value(); const KUrl url = job->property( "url" ).value(); showMessagePopup(msg, url, imageUrl, aPoint, contactAlreadyExists, uniqueContactFound); } void KMMainWidget::showMessagePopup(const Akonadi::Item&msg ,const KUrl&url,const KUrl &imageUrl,const QPoint& aPoint, bool contactAlreadyExists, bool uniqueContactFound) { KMenu *menu = new KMenu; bool urlMenuAdded = false; if ( !url.isEmpty() ) { if ( url.protocol() == QLatin1String( "mailto" ) ) { // popup on a mailto URL menu->addAction( mMsgView->mailToComposeAction() ); menu->addAction( mMsgView->mailToReplyAction() ); menu->addAction( mMsgView->mailToForwardAction() ); menu->addSeparator(); if ( contactAlreadyExists ) { if (uniqueContactFound) { menu->addAction( mMsgView->editContactAction() ); } else { menu->addAction( mMsgView->openAddrBookAction() ); } } else { menu->addAction( mMsgView->addAddrBookAction() ); menu->addAction( mMsgView->addToExistingContactAction() ); } menu->addSeparator(); menu->addMenu(mMsgView->viewHtmlOption()); menu->addSeparator(); menu->addAction( mMsgView->copyURLAction() ); urlMenuAdded = true; } else if ( url.protocol() != QLatin1String( "attachment" ) ) { // popup on a not-mailto URL menu->addAction( mMsgView->urlOpenAction() ); menu->addAction( mMsgView->addBookmarksAction() ); menu->addAction( mMsgView->urlSaveAsAction() ); menu->addAction( mMsgView->copyURLAction() ); if (mMsgView->isAShortUrl(url)) { menu->addSeparator(); menu->addAction( mMsgView->expandShortUrlAction() ); } if (!imageUrl.isEmpty()) { menu->addSeparator(); menu->addAction( mMsgView->copyImageLocation()); menu->addAction( mMsgView->downloadImageToDiskAction()); menu->addAction( mMsgView->shareImage()); if (mMsgView->adblockEnabled()) { menu->addSeparator(); menu->addAction( mMsgView->blockImage()); } } urlMenuAdded = true; } kDebug() << "URL is:" << url; } const QString selectedText = mMsgView ? mMsgView->copyText() : QString(); if ( mMsgView && !selectedText.isEmpty() ) { if ( urlMenuAdded ) { menu->addSeparator(); } menu->addAction( mMsgActions->replyMenu() ); menu->addSeparator(); menu->addAction( mMsgView->copyAction() ); menu->addAction( mMsgView->selectAllAction() ); menu->addSeparator(); mMsgActions->addWebShortcutsMenu(menu,selectedText); menu->addSeparator(); menu->addAction(mMsgView->translateAction()); menu->addSeparator(); menu->addAction( mMsgView->speakTextAction()); } else if ( !urlMenuAdded ) { // popup somewhere else (i.e., not a URL) on the message if (!mMessagePane->currentMessage()) { // no messages delete menu; return; } Akonadi::Collection parentCol = msg.parentCollection(); if ( parentCol.isValid() && CommonKernel->folderIsTemplates( parentCol) ) { menu->addAction( mUseAction ); } else { menu->addAction( mMsgActions->replyMenu() ); menu->addAction( mMsgActions->forwardMenu() ); } if ( parentCol.isValid() && CommonKernel->folderIsSentMailFolder( parentCol ) ) { menu->addAction( sendAgainAction() ); } else { menu->addAction( editAction() ); } menu->addAction( mailingListActionMenu() ); menu->addSeparator(); menu->addAction( mCopyActionMenu ); menu->addAction( mMoveActionMenu ); menu->addSeparator(); menu->addAction( mMsgActions->messageStatusMenu() ); menu->addSeparator(); if ( mMsgView ) { if (!imageUrl.isEmpty()) { menu->addSeparator(); menu->addAction( mMsgView->copyImageLocation()); menu->addAction( mMsgView->downloadImageToDiskAction()); menu->addAction( mMsgView->shareImage()); menu->addSeparator(); if (mMsgView->adblockEnabled()) { menu->addAction( mMsgView->blockImage() ); menu->addSeparator(); } } menu->addAction( mMsgView->viewSourceAction() ); menu->addAction( mMsgView->toggleFixFontAction() ); menu->addAction( mMsgView->toggleMimePartTreeAction() ); } menu->addSeparator(); menu->addAction( mMsgActions->printPreviewAction() ); menu->addAction( mMsgActions->printAction() ); menu->addAction( mSaveAsAction ); menu->addAction( mSaveAttachmentsAction ); menu->addSeparator(); if ( parentCol.isValid() && CommonKernel->folderIsTrash(parentCol) ) { menu->addAction( mDeleteAction ); } else { menu->addAction( akonadiStandardAction( Akonadi::StandardMailActionManager::MoveToTrash ) ); } menu->addSeparator(); menu->addAction( mMsgView->createTodoAction() ); menu->addAction( mMsgView->createEventAction() ); menu->addAction( mMsgView->createNoteAction() ); menu->addSeparator(); if (mMsgView) { menu->addAction( mMsgView->saveMessageDisplayFormatAction() ); menu->addAction( mMsgView->resetMessageDisplayFormatAction() ); menu->addSeparator(); } if (mMsgView && mMsgView->adblockEnabled()) { menu->addSeparator(); menu->addAction( mMsgView->openBlockableItems()); } } KAcceleratorManager::manage(menu); menu->exec( aPoint, 0 ); delete menu; } //----------------------------------------------------------------------------- void KMMainWidget::getAccountMenu() { mActMenu->clear(); const Akonadi::AgentInstance::List lst = MailCommon::Util::agentInstances(); foreach ( const Akonadi::AgentInstance& type, lst ) { // Explicitly make a copy, as we're not changing values of the list but only // the local copy which is passed to action. QAction* action = mActMenu->addAction( QString( type.name() ).replace(QLatin1Char('&'), QLatin1String("&&")) ); action->setData( type.identifier() ); } } //----------------------------------------------------------------------------- void KMMainWidget::getTransportMenu() { mSendMenu->clear(); QStringList availTransports = MailTransport::TransportManager::self()->transportNames(); QStringList::Iterator it; QStringList::Iterator end( availTransports.end() ); for (it = availTransports.begin(); it != end ; ++it) mSendMenu->addAction((*it).replace(QLatin1Char('&'), QLatin1String("&&"))); } //----------------------------------------------------------------------------- void KMMainWidget::setupActions() { mMsgActions = new KMail::MessageActions( actionCollection(), this ); mMsgActions->setMessageView( mMsgView ); //----- File Menu mSaveAsAction = new KAction(KIcon(QLatin1String("document-save")), i18n("Save &As..."), this); actionCollection()->addAction(QLatin1String("file_save_as"), mSaveAsAction ); connect(mSaveAsAction, SIGNAL(triggered(bool)), SLOT(slotSaveMsg())); mSaveAsAction->setShortcut(KStandardShortcut::save()); mOpenAction = KStandardAction::open( this, SLOT(slotOpenMsg()), actionCollection() ); mOpenRecentAction = KStandardAction::openRecent( this, SLOT(slotOpenRecentMsg(KUrl)), actionCollection() ); KConfigGroup grp = mConfig->group(QLatin1String("Recent Files")); mOpenRecentAction->loadEntries(grp); { KAction *action = new KAction(i18n("&Expire All Folders"), this); actionCollection()->addAction(QLatin1String("expire_all_folders"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotExpireAll())); } { KAction *action = new KAction(KIcon(QLatin1String("mail-receive")), i18n("Check &Mail"), this); actionCollection()->addAction(QLatin1String("check_mail"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotCheckMail())); action->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_L)); } KActionMenu *actActionMenu = new KActionMenu(KIcon(QLatin1String("mail-receive")), i18n("Check Mail In"), this); actActionMenu->setIconText( i18n("Check Mail") ); actActionMenu->setToolTip( i18n("Check Mail") ); actionCollection()->addAction(QLatin1String("check_mail_in"), actActionMenu ); actActionMenu->setDelayed(true); //needed for checking "all accounts" connect(actActionMenu, SIGNAL(triggered(bool)), this, SLOT(slotCheckMail())); mActMenu = actActionMenu->menu(); connect(mActMenu, SIGNAL(triggered(QAction*)), SLOT(slotCheckOneAccount(QAction*))); connect(mActMenu, SIGNAL(aboutToShow()), SLOT(getAccountMenu())); mSendQueued = new KAction(KIcon(QLatin1String("mail-send")), i18n("&Send Queued Messages"), this); actionCollection()->addAction(QLatin1String("send_queued"), mSendQueued ); connect(mSendQueued, SIGNAL(triggered(bool)), SLOT(slotSendQueued())); { KAction * action = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::ToggleWorkOffline ); mAkonadiStandardActionManager->interceptAction( Akonadi::StandardActionManager::ToggleWorkOffline ); action->setCheckable(false); connect( action, SIGNAL(triggered(bool)), this, SLOT(slotOnlineStatus()) ); action->setText( i18n("Online status (unknown)") ); } mSendActionMenu = new KActionMenu(KIcon(QLatin1String("mail-send-via")), i18n("Send Queued Messages Via"), this); actionCollection()->addAction(QLatin1String("send_queued_via"), mSendActionMenu ); mSendActionMenu->setDelayed(true); mSendMenu = mSendActionMenu->menu(); connect(mSendMenu,SIGNAL(triggered(QAction*)), SLOT(slotSendQueuedVia(QAction*))); connect(mSendMenu,SIGNAL(aboutToShow()),SLOT(getTransportMenu())); //----- Tools menu if (parent()->inherits("KMMainWin")) { KAction *action = new KAction(KIcon(QLatin1String("x-office-address-book")), i18n("&Address Book"), this); actionCollection()->addAction(QLatin1String("addressbook"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotAddrBook())); if (KStandardDirs::findExe(QLatin1String("kaddressbook")).isEmpty()) action->setEnabled(false); } { KAction *action = new KAction(KIcon(QLatin1String("pgp-keys")), i18n("Certificate Manager"), this); actionCollection()->addAction(QLatin1String("tools_start_certman"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotStartCertManager())); // disable action if no certman binary is around if (KStandardDirs::findExe(QLatin1String("kleopatra")).isEmpty()) action->setEnabled(false); } { KAction *action = new KAction(KIcon(QLatin1String("pgp-keys")), i18n("GnuPG Log Viewer"), this); actionCollection()->addAction(QLatin1String("tools_start_kwatchgnupg"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotStartWatchGnuPG())); #ifdef Q_OS_WIN32 // not ported yet, underlying infrastructure missing on Windows const bool usableKWatchGnupg = false; #else // disable action if no kwatchgnupg binary is around bool usableKWatchGnupg = !KStandardDirs::findExe(QLatin1String("kwatchgnupg")).isEmpty(); #endif action->setEnabled(usableKWatchGnupg); } { KAction *action = new KAction(KIcon(QLatin1String("document-import")), i18n("&Import Messages..."), this); actionCollection()->addAction(QLatin1String("import"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotImport())); if (KStandardDirs::findExe(QLatin1String("kmailcvt")).isEmpty()) action->setEnabled(false); } #if !defined(NDEBUG) { KAction *action = new KAction(i18n("&Debug Sieve..."), this); actionCollection()->addAction(QLatin1String("tools_debug_sieve"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotDebugSieve())); } #endif { KAction *action = new KAction(i18n("Filter &Log Viewer..."), this); actionCollection()->addAction(QLatin1String("filter_log_viewer"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotFilterLogViewer())); } { KAction *action = new KAction(i18n("&Anti-Spam Wizard..."), this); actionCollection()->addAction(QLatin1String("antiSpamWizard"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotAntiSpamWizard())); } { KAction *action = new KAction(i18n("&Anti-Virus Wizard..."), this); actionCollection()->addAction(QLatin1String("antiVirusWizard"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotAntiVirusWizard())); } { KAction *action = new KAction( i18n("&Account Wizard..."), this ); actionCollection()->addAction( QLatin1String("accountWizard"), action ); connect( action, SIGNAL(triggered(bool)), SLOT(slotAccountWizard()) ); } { KAction *action = new KAction( i18n("&Import Wizard..."), this ); actionCollection()->addAction( QLatin1String("importWizard"), action ); connect( action, SIGNAL(triggered(bool)), SLOT(slotImportWizard()) ); } if ( KSieveUi::Util::allowOutOfOfficeSettings() ) { KAction *action = new KAction( i18n("Edit \"Out of Office\" Replies..."), this ); actionCollection()->addAction( QLatin1String("tools_edit_vacation"), action ); connect( action, SIGNAL(triggered(bool)), SLOT(slotEditVacation()) ); } { KAction *action = new KAction(i18n("&Configure Automatic Archiving..."), this); actionCollection()->addAction(QLatin1String("tools_automatic_archiving"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotConfigureAutomaticArchiving())); } { KAction *action = new KAction(i18n("Message Delayed..."), this); actionCollection()->addAction(QLatin1String("message_delayed"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotConfigureSendLater())); } // Disable the standard action delete key sortcut. KAction* const standardDelAction = akonadiStandardAction( Akonadi::StandardActionManager::DeleteItems ); standardDelAction->setShortcut( QKeySequence() ); //----- Edit Menu /* The delete action is nowhere in the gui, by default, so we need to make * sure it is plugged into the KAccel now, since that won't happen on * XMLGui construction or manual ->plug(). This is only a problem when run * as a part, though. */ mDeleteAction = new KAction(KIcon(QLatin1String("edit-delete")), i18nc("@action Hard delete, bypassing trash", "&Delete"), this); actionCollection()->addAction(QLatin1String("delete"), mDeleteAction ); connect(mDeleteAction, SIGNAL(triggered(bool)), SLOT(slotDeleteMsg())); mDeleteAction->setShortcut(QKeySequence(Qt::SHIFT+Qt::Key_Delete)); mTrashThreadAction = new KAction(i18n("M&ove Thread to Trash"), this); actionCollection()->addAction(QLatin1String("move_thread_to_trash"), mTrashThreadAction ); mTrashThreadAction->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_Delete)); mTrashThreadAction->setIcon(KIcon(QLatin1String("user-trash"))); mTrashThreadAction->setHelpText(i18n("Move thread to trashcan") ); connect(mTrashThreadAction, SIGNAL(triggered(bool)), SLOT(slotTrashThread())); mDeleteThreadAction = new KAction(KIcon(QLatin1String("edit-delete")), i18n("Delete T&hread"), this); actionCollection()->addAction(QLatin1String("delete_thread"), mDeleteThreadAction ); connect(mDeleteThreadAction, SIGNAL(triggered(bool)), SLOT(slotDeleteThread())); mDeleteThreadAction->setShortcut(QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Delete)); { KAction *action = new KAction(KIcon(QLatin1String("edit-find-mail")), i18n("&Find Messages..."), this); actionCollection()->addAction(QLatin1String("search_messages"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotRequestFullSearchFromQuickSearch())); action->setShortcut(QKeySequence(Qt::Key_S)); } { KAction *action = new KAction(i18n("Select &All Messages"), this); actionCollection()->addAction(QLatin1String("mark_all_messages"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotMarkAll())); action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_A ) ); } //----- Folder Menu mFolderMailingListPropertiesAction = new KAction(i18n("&Mailing List Management..."), this); actionCollection()->addAction(QLatin1String("folder_mailinglist_properties"), mFolderMailingListPropertiesAction ); connect(mFolderMailingListPropertiesAction, SIGNAL(triggered(bool)), SLOT(slotFolderMailingListProperties())); // mFolderMailingListPropertiesAction->setIcon(KIcon("document-properties-mailing-list")); mShowFolderShortcutDialogAction = new KAction(KIcon(QLatin1String("configure-shortcuts")), i18n("&Assign Shortcut..."), this); actionCollection()->addAction(QLatin1String("folder_shortcut_command"), mShowFolderShortcutDialogAction ); connect( mShowFolderShortcutDialogAction, SIGNAL(triggered(bool)), SLOT(slotShowFolderShortcutDialog()) ); // FIXME: this action is not currently enabled in the rc file, but even if // it were there is inconsistency between the action name and action. // "Expiration Settings" implies that this will lead to a settings dialogue // and it should be followed by a "...", but slotExpireFolder() performs // an immediate expiry. // // TODO: expire action should be disabled if there is no content or if // the folder can't delete messages. // // Leaving the action here for the moment, it and the "Expire" option in the // folder popup menu should be combined or at least made consistent. Same for // slotExpireFolder() and FolderViewItem::slotShowExpiryProperties(). mExpireFolderAction = new KAction(i18n("&Expiration Settings"), this); actionCollection()->addAction(QLatin1String("expire"), mExpireFolderAction ); connect(mExpireFolderAction, SIGNAL(triggered(bool)), SLOT(slotExpireFolder())); mAkonadiStandardActionManager->interceptAction( Akonadi::StandardMailActionManager::MoveToTrash ); connect( mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::MoveToTrash ), SIGNAL(triggered(bool)), this, SLOT(slotTrashSelectedMessages()) ); mAkonadiStandardActionManager->interceptAction( Akonadi::StandardMailActionManager::MoveAllToTrash ); connect( mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::MoveAllToTrash ), SIGNAL(triggered(bool)), this, SLOT(slotEmptyFolder()) ); mAkonadiStandardActionManager->interceptAction( Akonadi::StandardActionManager::DeleteCollections ); connect( mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::DeleteCollections ), SIGNAL(triggered(bool)), this, SLOT(slotRemoveFolder()) ); // ### PORT ME: Add this to the context menu. Not possible right now because // the context menu uses XMLGUI, and that would add the entry to // all collection context menus mArchiveFolderAction = new KAction( i18n( "&Archive Folder..." ), this ); actionCollection()->addAction( QLatin1String("archive_folder"), mArchiveFolderAction ); connect( mArchiveFolderAction, SIGNAL(triggered(bool)), SLOT(slotArchiveFolder()) ); mPreferHtmlAction = new KToggleAction(i18n("Prefer &HTML to Plain Text"), this); actionCollection()->addAction(QLatin1String("prefer_html"), mPreferHtmlAction ); connect(mPreferHtmlAction, SIGNAL(triggered(bool)), SLOT(slotOverrideHtml())); mPreferHtmlLoadExtAction = new KToggleAction(i18n("Load E&xternal References"), this); actionCollection()->addAction(QLatin1String("prefer_html_external_refs"), mPreferHtmlLoadExtAction ); connect(mPreferHtmlLoadExtAction, SIGNAL(triggered(bool)), SLOT(slotOverrideHtmlLoadExt())); { KAction *action = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::CopyCollections); action->setShortcut(QKeySequence(Qt::SHIFT+Qt::CTRL+Qt::Key_C)); } { KAction *action = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::Paste); action->setShortcut(QKeySequence(Qt::SHIFT+Qt::CTRL+Qt::Key_V)); } { KAction *action = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::CopyItems); action->setShortcut(QKeySequence(Qt::ALT+Qt::CTRL+Qt::Key_C)); } { KAction *action = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::CutItems ); action->setShortcut(QKeySequence(Qt::ALT+Qt::CTRL+Qt::Key_X)); } { KAction *action = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::CopyItemToMenu ); action->setText(i18n("Copy Message To...") ); action = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::MoveItemToMenu ); action->setText(i18n("Move Message To...") ); } //----- Message Menu { KAction *action = new KAction(KIcon(QLatin1String("mail-message-new")), i18n("&New Message..."), this); actionCollection()->addAction(QLatin1String("new_message"), action ); action->setIconText( i18nc("@action:intoolbar New Empty Message", "New" ) ); connect(action, SIGNAL(triggered(bool)), SLOT(slotCompose())); // do not set a New shortcut if kmail is a component if ( !kmkernel->xmlGuiInstance().isValid() ) { action->setShortcut(KStandardShortcut::openNew()); } } mTemplateMenu = new KActionMenu( KIcon( QLatin1String("document-new") ), i18n("Message From &Template"), actionCollection() ); mTemplateMenu->setDelayed( true ); actionCollection()->addAction(QLatin1String("new_from_template"), mTemplateMenu ); connect( mTemplateMenu->menu(), SIGNAL(aboutToShow()), this, SLOT(slotShowNewFromTemplate()) ); connect( mTemplateMenu->menu(), SIGNAL(triggered(QAction*)), this, SLOT(slotNewFromTemplate(QAction*)) ); mMessageNewList = new KAction( KIcon( QLatin1String("mail-message-new-list") ), i18n( "New Message t&o Mailing-List..." ), this ); actionCollection()->addAction(QLatin1String("post_message"), mMessageNewList); connect( mMessageNewList, SIGNAL(triggered(bool)), SLOT(slotPostToML()) ); mMessageNewList->setShortcut( QKeySequence( Qt::CTRL + Qt::SHIFT + Qt::Key_N ) ); mSendAgainAction = new KAction(i18n("Send A&gain..."), this); actionCollection()->addAction(QLatin1String("send_again"), mSendAgainAction ); connect(mSendAgainAction, SIGNAL(triggered(bool)), SLOT(slotResendMsg())); //----- Create filter actions mFilterMenu = new KActionMenu(KIcon(QLatin1String("view-filter")), i18n("&Create Filter"), this); actionCollection()->addAction(QLatin1String("create_filter"), mFilterMenu ); connect( mFilterMenu, SIGNAL(triggered(bool)), this, SLOT(slotFilter()) ); { KAction *action = new KAction(i18n("Filter on &Subject..."), this); actionCollection()->addAction(QLatin1String("subject_filter"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotSubjectFilter())); mFilterMenu->addAction( action ); } { KAction *action = new KAction(i18n("Filter on &From..."), this); actionCollection()->addAction(QLatin1String("from_filter"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotFromFilter())); mFilterMenu->addAction( action ); } { KAction *action = new KAction(i18n("Filter on &To..."), this); actionCollection()->addAction(QLatin1String("to_filter"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotToFilter())); mFilterMenu->addAction( action ); } mFilterMenu->addAction( mMsgActions->listFilterAction() ); mUseAction = new KAction( KIcon(QLatin1String("document-new")), i18n("New Message From &Template"), this ); actionCollection()->addAction(QLatin1String("use_template"), mUseAction); connect(mUseAction, SIGNAL(triggered(bool)), SLOT(slotUseTemplate())); mUseAction->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_N)); //----- "Mark Thread" submenu mThreadStatusMenu = new KActionMenu(i18n("Mark &Thread"), this); actionCollection()->addAction(QLatin1String("thread_status"), mThreadStatusMenu ); mMarkThreadAsReadAction = new KAction(KIcon(QLatin1String("mail-mark-read")), i18n("Mark Thread as &Read"), this); actionCollection()->addAction(QLatin1String("thread_read"), mMarkThreadAsReadAction ); connect(mMarkThreadAsReadAction, SIGNAL(triggered(bool)), SLOT(slotSetThreadStatusRead())); mMarkThreadAsReadAction->setHelpText(i18n("Mark all messages in the selected thread as read")); mThreadStatusMenu->addAction( mMarkThreadAsReadAction ); mMarkThreadAsUnreadAction = new KAction(KIcon(QLatin1String("mail-mark-unread")), i18n("Mark Thread as &Unread"), this); actionCollection()->addAction(QLatin1String("thread_unread"), mMarkThreadAsUnreadAction ); connect(mMarkThreadAsUnreadAction, SIGNAL(triggered(bool)), SLOT(slotSetThreadStatusUnread())); mMarkThreadAsUnreadAction->setHelpText(i18n("Mark all messages in the selected thread as unread")); mThreadStatusMenu->addAction( mMarkThreadAsUnreadAction ); mThreadStatusMenu->addSeparator(); //----- "Mark Thread" toggle actions mToggleThreadImportantAction = new KToggleAction(KIcon(QLatin1String("mail-mark-important")), i18n("Mark Thread as &Important"), this); actionCollection()->addAction(QLatin1String("thread_flag"), mToggleThreadImportantAction ); connect(mToggleThreadImportantAction, SIGNAL(triggered(bool)), SLOT(slotSetThreadStatusImportant())); mToggleThreadImportantAction->setCheckedState( KGuiItem(i18n("Remove &Important Thread Mark")) ); mThreadStatusMenu->addAction( mToggleThreadImportantAction ); mToggleThreadToActAction = new KToggleAction(KIcon(QLatin1String("mail-mark-task")), i18n("Mark Thread as &Action Item"), this); actionCollection()->addAction(QLatin1String("thread_toact"), mToggleThreadToActAction ); connect(mToggleThreadToActAction, SIGNAL(triggered(bool)), SLOT(slotSetThreadStatusToAct())); mToggleThreadToActAction->setCheckedState( KGuiItem(i18n("Remove &Action Item Thread Mark")) ); mThreadStatusMenu->addAction( mToggleThreadToActAction ); //------- "Watch and ignore thread" actions mWatchThreadAction = new KToggleAction(KIcon(QLatin1String("mail-thread-watch")), i18n("&Watch Thread"), this); actionCollection()->addAction(QLatin1String("thread_watched"), mWatchThreadAction ); connect(mWatchThreadAction, SIGNAL(triggered(bool)), SLOT(slotSetThreadStatusWatched())); mIgnoreThreadAction = new KToggleAction(KIcon(QLatin1String("mail-thread-ignored")), i18n("&Ignore Thread"), this); actionCollection()->addAction(QLatin1String("thread_ignored"), mIgnoreThreadAction ); connect(mIgnoreThreadAction, SIGNAL(triggered(bool)), SLOT(slotSetThreadStatusIgnored())); mThreadStatusMenu->addSeparator(); mThreadStatusMenu->addAction( mWatchThreadAction ); mThreadStatusMenu->addAction( mIgnoreThreadAction ); mSaveAttachmentsAction = new KAction(KIcon(QLatin1String("mail-attachment")), i18n("Save A&ttachments..."), this); actionCollection()->addAction(QLatin1String("file_save_attachments"), mSaveAttachmentsAction ); connect(mSaveAttachmentsAction, SIGNAL(triggered(bool)), SLOT(slotSaveAttachments())); mMoveActionMenu = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::MoveItemToMenu); mCopyActionMenu = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::CopyItemToMenu); mApplyAllFiltersAction = new KAction( KIcon( QLatin1String("view-filter") ), i18n( "Appl&y All Filters" ), this ); actionCollection()->addAction( QLatin1String("apply_filters"), mApplyAllFiltersAction ); connect( mApplyAllFiltersAction, SIGNAL(triggered(bool)), SLOT(slotApplyFilters()) ); mApplyAllFiltersAction->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_J ) ); mApplyFilterActionsMenu = new KActionMenu( i18n( "A&pply Filter" ), this ); actionCollection()->addAction( QLatin1String("apply_filter_actions"), mApplyFilterActionsMenu ); { KAction *action = new KAction(i18nc("View->","&Expand Thread / Group"), this); actionCollection()->addAction(QLatin1String("expand_thread"), action ); action->setShortcut(QKeySequence(Qt::Key_Period)); action->setHelpText(i18n("Expand the current thread or group")); connect(action, SIGNAL(triggered(bool)), SLOT(slotExpandThread())); } { KAction *action = new KAction(i18nc("View->","&Collapse Thread / Group"), this); actionCollection()->addAction(QLatin1String("collapse_thread"), action ); action->setShortcut(QKeySequence(Qt::Key_Comma)); action->setHelpText( i18n("Collapse the current thread or group")); connect(action, SIGNAL(triggered(bool)), SLOT(slotCollapseThread())); } { KAction *action = new KAction(i18nc("View->","Ex&pand All Threads"), this); actionCollection()->addAction(QLatin1String("expand_all_threads"), action ); action->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_Period)); action->setHelpText( i18n("Expand all threads in the current folder")); connect(action, SIGNAL(triggered(bool)), SLOT(slotExpandAllThreads())); } { KAction *action = new KAction(i18nc("View->","C&ollapse All Threads"), this); actionCollection()->addAction(QLatin1String("collapse_all_threads"), action ); action->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_Comma)); action->setHelpText( i18n("Collapse all threads in the current folder")); connect(action, SIGNAL(triggered(bool)), SLOT(slotCollapseAllThreads())); } KAction *dukeOfMonmoth = new KAction(i18n("&Display Message"), this); actionCollection()->addAction(QLatin1String("display_message"), dukeOfMonmoth ); connect(dukeOfMonmoth, SIGNAL(triggered(bool)), SLOT(slotDisplayCurrentMessage())); KShortcut shortcut = KShortcut(QKeySequence( Qt::Key_Enter )); shortcut.setAlternate( QKeySequence( Qt::Key_Return ) ); dukeOfMonmoth->setShortcuts( shortcut ); //----- Go Menu { KAction *action = new KAction(i18n("&Next Message"), this); actionCollection()->addAction(QLatin1String("go_next_message"), action ); action->setShortcuts(KShortcut( QLatin1String("N; Right") )); action->setHelpText(i18n("Go to the next message")); connect(action, SIGNAL(triggered(bool)), SLOT(slotSelectNextMessage())); } { KAction *action = new KAction(i18n("Next &Unread Message"), this); actionCollection()->addAction(QLatin1String("go_next_unread_message"), action ); action->setShortcut(QKeySequence(Qt::Key_Plus)); if ( QApplication::isRightToLeft() ) { action->setIcon( KIcon( QLatin1String("go-previous") ) ); } else { action->setIcon( KIcon( QLatin1String("go-next") ) ); } action->setIconText( i18nc( "@action:inmenu Goto next unread message", "Next" ) ); action->setHelpText(i18n("Go to the next unread message")); connect(action, SIGNAL(triggered(bool)), SLOT(slotSelectNextUnreadMessage())); } { KAction *action = new KAction(i18n("&Previous Message"), this); actionCollection()->addAction(QLatin1String("go_prev_message"), action ); action->setHelpText(i18n("Go to the previous message")); action->setShortcuts(KShortcut( QLatin1String("P; Left") )); connect(action, SIGNAL(triggered(bool)), SLOT(slotSelectPreviousMessage())); } { KAction *action = new KAction(i18n("Previous Unread &Message"), this); actionCollection()->addAction(QLatin1String("go_prev_unread_message"), action ); action->setShortcut(QKeySequence(Qt::Key_Minus)); if ( QApplication::isRightToLeft() ) { action->setIcon( KIcon( QLatin1String("go-next") ) ); } else { action->setIcon( KIcon( QLatin1String("go-previous") ) ); } action->setIconText( i18nc( "@action:inmenu Goto previous unread message.","Previous" ) ); action->setHelpText(i18n("Go to the previous unread message")); connect(action, SIGNAL(triggered(bool)), SLOT(slotSelectPreviousUnreadMessage())); } { KAction *action = new KAction(i18n("Next Unread &Folder"), this); actionCollection()->addAction(QLatin1String("go_next_unread_folder"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotNextUnreadFolder())); action->setShortcut(QKeySequence(Qt::ALT+Qt::Key_Plus)); action->setHelpText(i18n("Go to the next folder with unread messages")); } { KAction *action = new KAction(i18n("Previous Unread F&older"), this); actionCollection()->addAction(QLatin1String("go_prev_unread_folder"), action ); action->setShortcut(QKeySequence(Qt::ALT+Qt::Key_Minus)); action->setHelpText(i18n("Go to the previous folder with unread messages")); connect(action, SIGNAL(triggered(bool)), SLOT(slotPrevUnreadFolder())); } { KAction *action = new KAction(i18nc("Go->","Next Unread &Text"), this); actionCollection()->addAction(QLatin1String("go_next_unread_text"), action ); action->setShortcut(QKeySequence(Qt::Key_Space)); action->setHelpText(i18n("Go to the next unread text")); action->setWhatsThis( i18n("Scroll down current message. " "If at end of current message, " "go to next unread message.")); connect(action, SIGNAL(triggered(bool)), SLOT(slotReadOn())); } //----- Settings Menu { KAction *action = new KAction(i18n("Configure &Filters..."), this); action->setMenuRole( QAction::NoRole ); // do not move to application menu on OS X actionCollection()->addAction(QLatin1String("filter"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotFilter())); } { KAction *action = new KAction(i18n("Manage &Sieve Scripts..."), this); actionCollection()->addAction(QLatin1String("sieveFilters"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotManageSieveScripts())); } { KAction *action = new KAction(KIcon(QLatin1String("kmail")), i18n("KMail &Introduction"), this); actionCollection()->addAction(QLatin1String("help_kmail_welcomepage"), action ); action->setHelpText( i18n("Display KMail's Welcome Page") ); connect(action, SIGNAL(triggered(bool)), SLOT(slotIntro())); } // ----- Standard Actions // KStandardAction::configureNotifications(this, SLOT(slotEditNotifications()), actionCollection()); { KAction *action = new KAction( KIcon(QLatin1String("preferences-desktop-notification")), i18n("Configure &Notifications..."), this ); action->setMenuRole( QAction::NoRole ); // do not move to application menu on OS X actionCollection()->addAction( QLatin1String("kmail_configure_notifications"), action ); connect(action, SIGNAL(triggered(bool)), SLOT(slotEditNotifications())); } { KAction *action = new KAction(KIcon(QLatin1String("configure")), i18n("&Configure KMail..."), this); actionCollection()->addAction(QLatin1String("kmail_configure_kmail"), action ); connect(action, SIGNAL(triggered(bool)), kmkernel, SLOT(slotShowConfigurationDialog())); } { mExpireConfigAction = new KAction( i18n( "Expire..." ), this ); actionCollection()->addAction( QLatin1String("expire_settings"),mExpireConfigAction ); connect( mExpireConfigAction, SIGNAL(triggered(bool)), this, SLOT(slotShowExpiryProperties()) ); } { KAction *action = new KAction( KIcon( QLatin1String("bookmark-new" )), i18n( "Add Favorite Folder..." ), this ); actionCollection()->addAction( QLatin1String("add_favorite_folder"), action ); connect( action, SIGNAL(triggered(bool)), this, SLOT(slotAddFavoriteFolder()) ); } { mServerSideSubscription = new KAction( KIcon( QLatin1String("folder-bookmarks") ), i18n( "Serverside Subscription..." ), this); actionCollection()->addAction( QLatin1String("serverside_subscription"), mServerSideSubscription); connect( mServerSideSubscription, SIGNAL(triggered(bool)), this, SLOT(slotServerSideSubscription()) ); } { mApplyFiltersOnFolder = new KAction( KIcon( QLatin1String("view-filter") ), i18n( "Appl&y All Filters On Folder" ), this ); actionCollection()->addAction( QLatin1String("apply_filters_on_folder"), mApplyFiltersOnFolder ); connect( mApplyFiltersOnFolder, SIGNAL(triggered(bool)), SLOT(slotApplyFiltersOnFolder()) ); } { KAction *action = new KAction(KIcon(QLatin1String("kmail")), i18n("&Export KMail Data..."), this); actionCollection()->addAction(QLatin1String("kmail_export_data"), action ); connect(action, SIGNAL(triggered(bool)), this, SLOT(slotExportData())); } { KAction *action = new KAction(KIcon( QLatin1String( "contact-new" ) ),i18n("New AddressBook Contact..."),this); actionCollection()->addAction(QLatin1String("kmail_new_addressbook_contact"), action ); connect(action, SIGNAL(triggered(bool)), this, SLOT(slotCreateAddressBookContact())); } actionCollection()->addAction(KStandardAction::Undo, QLatin1String("kmail_undo"), this, SLOT(slotUndo())); KStandardAction::tipOfDay( this, SLOT(slotShowTip()), actionCollection() ); menutimer = new QTimer( this ); menutimer->setObjectName( QLatin1String("menutimer") ); menutimer->setSingleShot( true ); connect( menutimer, SIGNAL(timeout()), SLOT(updateMessageActionsDelayed()) ); connect( kmkernel->undoStack(), SIGNAL(undoStackChanged()), this, SLOT(slotUpdateUndo())); updateMessageActions(); updateFolderMenu(); mTagActionManager = new KMail::TagActionManager( this, actionCollection(), mMsgActions, mGUIClient ); mFolderShortcutActionManager = new KMail::FolderShortcutActionManager( this, actionCollection() ); { KAction *action = new KAction( i18n("Copy Message to Folder"), this ); actionCollection()->addAction(QLatin1String( "copy_message_to_folder"), action ); connect( action, SIGNAL(triggered(bool)), SLOT(slotCopySelectedMessagesToFolder()) ); action->setShortcut( QKeySequence( Qt::Key_C ) ); } { KAction *action = new KAction( i18n("Jump to Folder..."), this ); actionCollection()->addAction( QLatin1String("jump_to_folder"), action ); connect( action, SIGNAL(triggered(bool)), SLOT(slotJumpToFolder()) ); action->setShortcut( QKeySequence( Qt::Key_J ) ); } { KAction *action = new KAction(i18n("Abort Current Operation"), this); actionCollection()->addAction(QLatin1String("cancel"), action ); connect( action, SIGNAL(triggered(bool)), ProgressManager::instance(), SLOT(slotAbortAll()) ); action->setShortcut( QKeySequence( Qt::Key_Escape ) ); } { KAction *action = new KAction(i18n("Focus on Next Folder"), this); actionCollection()->addAction(QLatin1String("inc_current_folder"), action ); connect( action, SIGNAL(triggered(bool)), mFolderTreeWidget->folderTreeView(), SLOT(slotFocusNextFolder()) ); action->setShortcut( QKeySequence( Qt::CTRL+Qt::Key_Right ) ); } { KAction *action = new KAction(i18n("Focus on Previous Folder"), this); actionCollection()->addAction(QLatin1String("dec_current_folder"), action ); connect( action, SIGNAL(triggered(bool)), mFolderTreeWidget->folderTreeView(), SLOT(slotFocusPrevFolder()) ); action->setShortcut( QKeySequence( Qt::CTRL+Qt::Key_Left ) ); } { KAction *action = new KAction(i18n("Select Folder with Focus"), this); actionCollection()->addAction(QLatin1String("select_current_folder"), action ); connect( action, SIGNAL(triggered(bool)), mFolderTreeWidget->folderTreeView(), SLOT(slotSelectFocusFolder()) ); action->setShortcut( QKeySequence( Qt::CTRL+Qt::Key_Space ) ); } { KAction *action = new KAction(i18n("Focus on First Folder"), this); actionCollection()->addAction(QLatin1String("focus_first_folder"), action ); connect( action, SIGNAL(triggered(bool)), mFolderTreeWidget->folderTreeView(), SLOT(slotFocusFirstFolder()) ); action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_Home ) ); } { KAction *action = new KAction(i18n("Focus on Last Folder"), this); actionCollection()->addAction(QLatin1String("focus_last_folder"), action ); connect( action, SIGNAL(triggered(bool)), mFolderTreeWidget->folderTreeView(), SLOT(slotFocusLastFolder()) ); action->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_End ) ); } { KAction *action = new KAction(i18n("Focus on Next Message"), this); actionCollection()->addAction(QLatin1String("inc_current_message"), action ); connect( action, SIGNAL(triggered(bool)), this, SLOT(slotFocusOnNextMessage()) ); action->setShortcut( QKeySequence( Qt::ALT+Qt::Key_Right ) ); } { KAction *action = new KAction(i18n("Focus on Previous Message"), this); actionCollection()->addAction(QLatin1String("dec_current_message"), action ); connect( action, SIGNAL(triggered(bool)), this, SLOT(slotFocusOnPrevMessage()) ); action->setShortcut( QKeySequence( Qt::ALT+Qt::Key_Left ) ); } { KAction *action = new KAction(i18n("Select First Message"), this); actionCollection()->addAction(QLatin1String("select_first_message"), action ); connect ( action, SIGNAL(triggered(bool)), this, SLOT(slotSelectFirstMessage()) ); action->setShortcut( QKeySequence( Qt::ALT + Qt::Key_Home ) ); } { KAction *action = new KAction(i18n("Select Last Message"), this); actionCollection()->addAction(QLatin1String("select_last_message"), action ); connect ( action, SIGNAL(triggered(bool)), this, SLOT(slotSelectLastMessage()) ); action->setShortcut( QKeySequence( Qt::ALT + Qt::Key_End ) ); } { KAction *action = new KAction(i18n("Select Message with Focus"), this); actionCollection()->addAction( QLatin1String("select_current_message"), action ); connect( action, SIGNAL(triggered(bool)), this, SLOT(slotSelectFocusedMessage()) ); action->setShortcut( QKeySequence( Qt::ALT+Qt::Key_Space ) ); } { mQuickSearchAction = new KAction( i18n("Set Focus to Quick Search"), this ); //If change shortcut change Panel::setQuickSearchClickMessage(...) message mQuickSearchAction->setShortcut( QKeySequence( Qt::ALT + Qt::Key_Q ) ); actionCollection()->addAction( QLatin1String("focus_to_quickseach"), mQuickSearchAction ); connect( mQuickSearchAction, SIGNAL(triggered(bool)), SLOT(slotFocusQuickSearch()) ); updateQuickSearchLineText(); } { KAction *action = new KAction( i18n( "Extend Selection to Previous Message" ), this ); action->setShortcut( QKeySequence( Qt::SHIFT + Qt::Key_Left ) ); actionCollection()->addAction( QLatin1String("previous_message"), action ); connect( action, SIGNAL(triggered(bool)), this, SLOT(slotExtendSelectionToPreviousMessage()) ); } { KAction *action = new KAction( i18n( "Extend Selection to Next Message" ), this ); action->setShortcut( QKeySequence( Qt::SHIFT + Qt::Key_Right ) ); actionCollection()->addAction( QLatin1String("next_message"), action ); connect( action, SIGNAL(triggered(bool)), this, SLOT(slotExtendSelectionToNextMessage()) ); } { mMoveMsgToFolderAction = new KAction( i18n("Move Message to Folder"), this ); mMoveMsgToFolderAction->setShortcut( QKeySequence( Qt::Key_M ) ); actionCollection()->addAction( QLatin1String("move_message_to_folder"), mMoveMsgToFolderAction ); connect( mMoveMsgToFolderAction, SIGNAL(triggered(bool)), SLOT(slotMoveSelectedMessageToFolder()) ); } mArchiveAction = new KAction( i18nc("@action", "Archive"), this); actionCollection()->addAction( QLatin1String("archive_mails"), mArchiveAction ); connect( mArchiveAction, SIGNAL(triggered(bool)), SLOT(slotArchiveMails()) ); } void KMMainWidget::slotAddFavoriteFolder() { if (!mFavoritesModel) return; QPointer dialog( selectFromAllFoldersDialog() ); dialog->setCaption( i18n("Add Favorite Folder") ); if ( dialog->exec() && dialog ) { const Akonadi::Collection collection = dialog->selectedCollection(); if ( collection.isValid() ) { mFavoritesModel->addCollection( collection ); } } } //----------------------------------------------------------------------------- void KMMainWidget::slotEditNotifications() { KMail::KMKnotify notifyDlg( this ); notifyDlg.exec(); } void KMMainWidget::slotShowExpiryProperties() { showCollectionProperties( QLatin1String( "MailCommon::CollectionExpiryPage" ) ); } //----------------------------------------------------------------------------- void KMMainWidget::slotReadOn() { if ( !mMsgView ) return; if ( !mMsgView->viewer()->atBottom() ) { mMsgView->viewer()->slotJumpDown(); return; } slotSelectNextUnreadMessage(); } void KMMainWidget::slotNextUnreadFolder() { if ( !mFolderTreeWidget ) return; mGoToFirstUnreadMessageInSelectedFolder = true; mFolderTreeWidget->folderTreeView()->selectNextUnreadFolder(); mGoToFirstUnreadMessageInSelectedFolder = false; } void KMMainWidget::slotPrevUnreadFolder() { if ( !mFolderTreeWidget ) return; mGoToFirstUnreadMessageInSelectedFolder = true; mFolderTreeWidget->folderTreeView()->selectPrevUnreadFolder(); mGoToFirstUnreadMessageInSelectedFolder = false; } void KMMainWidget::slotExpandThread() { mMessagePane->setCurrentThreadExpanded( true ); } void KMMainWidget::slotCollapseThread() { mMessagePane->setCurrentThreadExpanded( false ); } void KMMainWidget::slotExpandAllThreads() { // TODO: Make this asynchronous ? (if there is enough demand) #ifndef QT_NO_CURSOR MessageViewer::KCursorSaver busy( MessageViewer::KBusyPtr::busy() ); #endif mMessagePane->setAllThreadsExpanded( true ); } void KMMainWidget::slotCollapseAllThreads() { // TODO: Make this asynchronous ? (if there is enough demand) #ifndef QT_NO_CURSOR MessageViewer::KCursorSaver busy( MessageViewer::KBusyPtr::busy() ); #endif mMessagePane->setAllThreadsExpanded( false ); } //----------------------------------------------------------------------------- void KMMainWidget::updateMessageMenu() { updateMessageActions(); } void KMMainWidget::startUpdateMessageActionsTimer() { // FIXME: This delay effectively CAN make the actions to be in an incoherent state // Maybe we should mark actions as "dirty" here and check it in every action handler... updateMessageActions( true ); menutimer->stop(); menutimer->start( 500 ); } void KMMainWidget::updateMessageActions( bool fast ) { Akonadi::Item::List selectedItems; Akonadi::Item::List selectedVisibleItems; bool allSelectedBelongToSameThread = false; if (mCurrentFolder && mCurrentFolder->isValid() && mMessagePane->getSelectionStats( selectedItems, selectedVisibleItems, &allSelectedBelongToSameThread ) ) { mMsgActions->setCurrentMessage( mMessagePane->currentItem(), selectedVisibleItems ); } else { mMsgActions->setCurrentMessage( Akonadi::Item() ); } if ( !fast ) updateMessageActionsDelayed(); } void KMMainWidget::updateMessageActionsDelayed() { int count; Akonadi::Item::List selectedItems; Akonadi::Item::List selectedVisibleItems; bool allSelectedBelongToSameThread = false; Akonadi::Item currentMessage; if (mCurrentFolder && mCurrentFolder->isValid() && mMessagePane->getSelectionStats( selectedItems, selectedVisibleItems, &allSelectedBelongToSameThread ) ) { count = selectedItems.count(); currentMessage = mMessagePane->currentItem(); } else { count = 0; currentMessage = Akonadi::Item(); } mApplyFiltersOnFolder->setEnabled( mCurrentFolder && mCurrentFolder->isValid() ); // // Here we have: // // - A list of selected messages stored in selectedSernums. // The selected messages might contain some invisible ones as a selected // collapsed node "includes" all the children in the selection. // - A list of selected AND visible messages stored in selectedVisibleSernums. // This list does not contain children of selected and collapsed nodes. // // Now, actions can operate on: // - Any set of messages // These are called "mass actions" and are enabled whenever we have a message selected. // In fact we should differentiate between actions that operate on visible selection // and those that operate on the selection as a whole (without considering visibility)... // - A single thread // These are called "thread actions" and are enabled whenever all the selected messages belong // to the same thread. If the selection doesn't cover the whole thread then the action // will act on the whole thread anyway (thus will silently extend the selection) // - A single message // And we have two sub-cases: // - The selection must contain exactly one message // These actions can't ignore the hidden messages and thus must be disabled if // the selection contains any. // - The selection must contain exactly one visible message // These actions will ignore the hidden message and thus can be enabled if // the selection contains any. // bool readOnly = mCurrentFolder && mCurrentFolder->isValid() && ( mCurrentFolder->rights() & Akonadi::Collection::ReadOnly ); // can we apply strictly single message actions ? (this is false if the whole selection contains more than one message) bool single_actions = count == 1; // can we apply loosely single message actions ? (this is false if the VISIBLE selection contains more than one message) bool singleVisibleMessageSelected = selectedVisibleItems.count() == 1; // can we apply "mass" actions to the selection ? (this is actually always true if the selection is non-empty) bool mass_actions = count >= 1; // does the selection identify a single thread ? bool thread_actions = mass_actions && allSelectedBelongToSameThread && mMessagePane->isThreaded(); // can we apply flags to the selected messages ? bool flags_available = GlobalSettings::self()->allowLocalFlags() || !(mCurrentFolder && mCurrentFolder->isValid() ? readOnly : true); mThreadStatusMenu->setEnabled( thread_actions ); // these need to be handled individually, the user might have them // in the toolbar mWatchThreadAction->setEnabled( thread_actions && flags_available ); mIgnoreThreadAction->setEnabled( thread_actions && flags_available ); mMarkThreadAsReadAction->setEnabled( thread_actions ); mMarkThreadAsUnreadAction->setEnabled( thread_actions ); mToggleThreadToActAction->setEnabled( thread_actions && flags_available ); mToggleThreadImportantAction->setEnabled( thread_actions && flags_available ); bool canDeleteMessages = mCurrentFolder && mCurrentFolder->isValid() && ( mCurrentFolder->rights() & Akonadi::Collection::CanDeleteItem ); mTrashThreadAction->setEnabled( thread_actions && canDeleteMessages ); mDeleteThreadAction->setEnabled( thread_actions && canDeleteMessages ); if ( currentMessage.isValid() ) { MessageStatus status; status.setStatusFromFlags( currentMessage.flags() ); mTagActionManager->updateActionStates ( count, mMessagePane->currentItem() ); if (thread_actions) { mToggleThreadToActAction->setChecked( status.isToAct() ); mToggleThreadImportantAction->setChecked( status.isImportant() ); mWatchThreadAction->setChecked( status.isWatched() ); mIgnoreThreadAction->setChecked( status.isIgnored() ); } } mMoveActionMenu->setEnabled( mass_actions && canDeleteMessages ); if (mMoveMsgToFolderAction) mMoveMsgToFolderAction->setEnabled( mass_actions && canDeleteMessages ); //mCopyActionMenu->setEnabled( mass_actions ); mDeleteAction->setEnabled( mass_actions && canDeleteMessages ); mExpireConfigAction->setEnabled( canDeleteMessages ); if ( mMsgView ) { mMsgView->findInMessageAction()->setEnabled( mass_actions && !CommonKernel->folderIsTemplates( mCurrentFolder->collection() ) ); } mMsgActions->forwardInlineAction()->setEnabled( mass_actions && !CommonKernel->folderIsTemplates( mCurrentFolder->collection() ) ); mMsgActions->forwardAttachedAction()->setEnabled( mass_actions && !CommonKernel->folderIsTemplates( mCurrentFolder->collection() ) ); mMsgActions->forwardMenu()->setEnabled( mass_actions && !CommonKernel->folderIsTemplates( mCurrentFolder->collection() ) ); mMsgActions->editAction()->setEnabled( single_actions ); mUseAction->setEnabled( single_actions && CommonKernel->folderIsTemplates( mCurrentFolder->collection() ) ); filterMenu()->setEnabled( single_actions ); mMsgActions->redirectAction()->setEnabled( /*single_actions &&*/mass_actions && !CommonKernel->folderIsTemplates( mCurrentFolder->collection() ) ); if ( mMsgActions->customTemplatesMenu() ) { mMsgActions->customTemplatesMenu()->forwardActionMenu()->setEnabled( mass_actions ); mMsgActions->customTemplatesMenu()->replyActionMenu()->setEnabled( single_actions ); mMsgActions->customTemplatesMenu()->replyAllActionMenu()->setEnabled( single_actions ); } // "Print" will act on the current message: it will ignore any hidden selection mMsgActions->printAction()->setEnabled( singleVisibleMessageSelected ); // "Print preview" will act on the current message: it will ignore any hidden selection KAction *printPreviewAction = mMsgActions->printPreviewAction(); if (printPreviewAction) printPreviewAction->setEnabled( singleVisibleMessageSelected ); // "View Source" will act on the current message: it will ignore any hidden selection if (mMsgView) { mMsgView->viewSourceAction()->setEnabled( singleVisibleMessageSelected ); } MessageStatus status; status.setStatusFromFlags( currentMessage.flags() ); QList< QAction *> actionList; bool statusSendAgain = single_actions && ( ( currentMessage.isValid() && status.isSent() ) || ( currentMessage.isValid() && CommonKernel->folderIsSentMailFolder( mCurrentFolder->collection() ) ) ); if ( statusSendAgain ) { actionList << mSendAgainAction; } else if ( single_actions ) { actionList << messageActions()->editAction(); } actionList << mSaveAttachmentsAction; if (mCurrentFolder && FolderArchive::FolderArchiveUtil::resourceSupportArchiving(mCurrentFolder->collection().resource())) actionList << mArchiveAction; mGUIClient->unplugActionList( QLatin1String( "messagelist_actionlist" ) ); mGUIClient->plugActionList( QLatin1String( "messagelist_actionlist" ), actionList ); mSendAgainAction->setEnabled( statusSendAgain ); mSaveAsAction->setEnabled( mass_actions ); if ((mCurrentFolder&& mCurrentFolder->isValid())) { updateMoveAction( mCurrentFolder->statistics() ); } else { updateMoveAction(false,false); } const qint64 nbMsgOutboxCollection = MailCommon::Util::updatedCollection( CommonKernel->outboxCollectionFolder() ).statistics().count(); mSendQueued->setEnabled( nbMsgOutboxCollection > 0 ); mSendActionMenu->setEnabled( nbMsgOutboxCollection > 0 ); const bool newPostToMailingList = mCurrentFolder && mCurrentFolder->isMailingListEnabled(); mMessageNewList->setEnabled(newPostToMailingList); slotUpdateOnlineStatus( static_cast( GlobalSettings::self()->networkState() ) ); if (action( QLatin1String("kmail_undo") )) action( QLatin1String("kmail_undo") )->setEnabled( kmkernel->undoStack()->size() > 0 ); // Enable / disable all filters. foreach ( QAction *filterAction, mFilterMenuActions ) { filterAction->setEnabled( count > 0 ); } mApplyAllFiltersAction->setEnabled( count); mApplyFilterActionsMenu->setEnabled( count ); } void KMMainWidget::slotAkonadiStandardActionUpdated() { bool multiFolder = false; if ( mFolderTreeWidget ) { multiFolder = mFolderTreeWidget->selectedCollections().count() > 1; } if ( mCollectionProperties ) { if ( mCurrentFolder && mCurrentFolder->collection().isValid() ) { const Akonadi::AgentInstance instance = Akonadi::AgentManager::self()->instance( mCurrentFolder->collection().resource() ); mCollectionProperties->setEnabled( !multiFolder && !mCurrentFolder->isStructural() && (instance.status()!=Akonadi::AgentInstance::Broken) ); } else { mCollectionProperties->setEnabled(false); } QList< QAction* > collectionProperties; if ( mCollectionProperties->isEnabled() ) collectionProperties << mCollectionProperties; mGUIClient->unplugActionList( QLatin1String("akonadi_collection_collectionproperties_actionlist") ); mGUIClient->plugActionList( QLatin1String("akonadi_collection_collectionproperties_actionlist"), collectionProperties ); } const bool folderWithContent = mCurrentFolder && !mCurrentFolder->isStructural(); if ( mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::DeleteCollections ) ) { mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::DeleteCollections )->setEnabled( mCurrentFolder && !multiFolder && ( mCurrentFolder->collection().rights() & Collection::CanDeleteCollection ) && !mCurrentFolder->isSystemFolder() && folderWithContent); } if ( mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::MoveAllToTrash ) ) { mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::MoveAllToTrash )->setEnabled( folderWithContent && ( mCurrentFolder->count() > 0 ) && mCurrentFolder->canDeleteMessages() && !multiFolder ); mAkonadiStandardActionManager->action( Akonadi::StandardMailActionManager::MoveAllToTrash )->setText( (mCurrentFolder && CommonKernel->folderIsTrash(mCurrentFolder->collection())) ? i18n("E&mpty Trash") : i18n("&Move All Messages to Trash") ); } QList< QAction* > addToFavorite; QAction *actionAddToFavoriteCollections = akonadiStandardAction( Akonadi::StandardActionManager::AddToFavoriteCollections ); if ( actionAddToFavoriteCollections ) { if ( mEnableFavoriteFolderView && actionAddToFavoriteCollections->isEnabled() ) addToFavorite << actionAddToFavoriteCollections; mGUIClient->unplugActionList( QLatin1String("akonadi_collection_add_to_favorites_actionlist") ); mGUIClient->plugActionList( QLatin1String("akonadi_collection_add_to_favorites_actionlist"), addToFavorite ); } QList< QAction* > syncActionList; QAction *actionSync = akonadiStandardAction( Akonadi::StandardActionManager::SynchronizeCollections ); if ( actionSync && actionSync->isEnabled() ) { syncActionList << actionSync; } actionSync = akonadiStandardAction( Akonadi::StandardActionManager::SynchronizeCollectionsRecursive ); if ( actionSync && actionSync->isEnabled() ) { syncActionList << actionSync; } mGUIClient->unplugActionList( QLatin1String("akonadi_collection_sync_actionlist") ); mGUIClient->plugActionList( QLatin1String("akonadi_collection_sync_actionlist"), syncActionList ); QList< QAction* > actionList; QAction *action = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::CreateCollection ); if ( action && action->isEnabled() ) { actionList << action; } action = mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::MoveCollectionToMenu ); if ( action && action->isEnabled() ) { actionList <action( Akonadi::StandardActionManager::CopyCollectionToMenu); if ( action && action->isEnabled() ) { actionList <unplugActionList( QLatin1String("akonadi_collection_move_copy_menu_actionlist") ); mGUIClient->plugActionList( QLatin1String("akonadi_collection_move_copy_menu_actionlist"), actionList ); } void KMMainWidget::updateHtmlMenuEntry() { if (mPreferHtmlAction && mPreferHtmlLoadExtAction) { bool multiFolder = false; if ( mFolderTreeWidget ) { multiFolder = mFolderTreeWidget->selectedCollections().count() > 1; } // the visual ones only make sense if we are showing a message list mPreferHtmlAction->setEnabled( mFolderTreeWidget && mFolderTreeWidget->folderTreeView()->currentFolder().isValid() && !multiFolder ); mPreferHtmlLoadExtAction->setEnabled( mFolderTreeWidget && mFolderTreeWidget->folderTreeView()->currentFolder().isValid() && !multiFolder && (mHtmlPref ? !mFolderHtmlPref : mFolderHtmlPref) ? true : false ); mPreferHtmlAction->setChecked( !multiFolder && ( mHtmlPref ? !mFolderHtmlPref : mFolderHtmlPref ) ); mPreferHtmlLoadExtAction->setChecked( !multiFolder && ( mHtmlLoadExtPref ? !mFolderHtmlLoadExtPref : mFolderHtmlLoadExtPref ) ); } } //----------------------------------------------------------------------------- void KMMainWidget::updateFolderMenu() { if (!CommonKernel->outboxCollectionFolder().isValid()) { QTimer::singleShot(1000,this,SLOT(updateFolderMenu())); return; } const bool folderWithContent = mCurrentFolder && !mCurrentFolder->isStructural(); bool multiFolder = false; if ( mFolderTreeWidget ) { multiFolder = mFolderTreeWidget->selectedCollections().count() > 1; } mFolderMailingListPropertiesAction->setEnabled( folderWithContent && !multiFolder && !mCurrentFolder->isSystemFolder() ); QList< QAction* > actionlist; if ( mCurrentFolder && mCurrentFolder->collection().id() == CommonKernel->outboxCollectionFolder().id() && (mCurrentFolder->collection()).statistics().count() > 0) { kDebug() << "Enabling send queued"; mSendQueued->setEnabled(true); actionlist << mSendQueued; } // if ( mCurrentFolder && mCurrentFolder->collection().id() != CommonKernel->trashCollectionFolder().id() ) { // actionlist << mTrashAction; // } mGUIClient->unplugActionList( QLatin1String( "outbox_folder_actionlist" ) ); mGUIClient->plugActionList( QLatin1String( "outbox_folder_actionlist" ), actionlist ); actionlist.clear(); const bool isASearchFolder = mCurrentFolder && mCurrentFolder->collection().resource() == QLatin1String( "akonadi_search_resource" ); if (isASearchFolder) mAkonadiStandardActionManager->action( Akonadi::StandardActionManager::DeleteCollections )->setText( i18n("&Delete Search") ); mArchiveFolderAction->setEnabled( mCurrentFolder && !multiFolder && folderWithContent ); bool isInTrashFolder = (mCurrentFolder && CommonKernel->folderIsTrash(mCurrentFolder->collection())); akonadiStandardAction( Akonadi::StandardMailActionManager::MoveToTrash )->setText( isInTrashFolder ? i18nc("@action Hard delete, bypassing trash", "&Delete"): i18n("&Move to Trash") ); mTrashThreadAction->setText(isInTrashFolder ?i18n("Delete T&hread"): i18n("M&ove Thread to Trash")); mExpireConfigAction->setEnabled( mCurrentFolder && !mCurrentFolder->isStructural() && !multiFolder && mCurrentFolder->canDeleteMessages() && folderWithContent && !MailCommon::Util::isVirtualCollection( mCurrentFolder->collection() ) ); updateHtmlMenuEntry(); mShowFolderShortcutDialogAction->setEnabled( !multiFolder && folderWithContent ); actionlist << akonadiStandardAction( Akonadi::StandardActionManager::ManageLocalSubscriptions ); bool imapFolderIsOnline = false; if (mCurrentFolder && kmkernel->isImapFolder( mCurrentFolder->collection(),imapFolderIsOnline )) { if (imapFolderIsOnline) { actionlist << mServerSideSubscription; } } mGUIClient->unplugActionList( QLatin1String( "collectionview_actionlist" ) ); mGUIClient->plugActionList( QLatin1String( "collectionview_actionlist" ), actionlist ); } //----------------------------------------------------------------------------- void KMMainWidget::slotIntro() { if ( !mMsgView ) return; mMsgView->clear( true ); // hide widgets that are in the way: if ( mMessagePane && mLongFolderList ) mMessagePane->hide(); mMsgView->displayAboutPage(); mCurrentFolder.clear(); } void KMMainWidget::slotShowStartupFolder() { connect( MailCommon::FilterManager::instance(), SIGNAL(filtersChanged()), this, SLOT(initializeFilterActions()) ); // Plug various action lists. This can't be done in the constructor, as that is called before // the main window or Kontact calls createGUI(). // This function however is called with a single shot timer. checkAkonadiServerManagerState(); mFolderShortcutActionManager->createActions(); mTagActionManager->createActions(); messageActions()->setupForwardingActionsList( mGUIClient ); QString newFeaturesMD5 = KMReaderWin::newFeaturesMD5(); if ( kmkernel->firstStart() || GlobalSettings::self()->previousNewFeaturesMD5() != newFeaturesMD5 ) { GlobalSettings::self()->setPreviousNewFeaturesMD5( newFeaturesMD5 ); slotIntro(); return; } } void KMMainWidget::checkAkonadiServerManagerState() { Akonadi::ServerManager::State state = Akonadi::ServerManager::self()->state(); if (state == Akonadi::ServerManager::Running) { initializeFilterActions(); } else { connect( Akonadi::ServerManager::self(), SIGNAL(stateChanged(Akonadi::ServerManager::State)), SLOT(slotServerStateChanged(Akonadi::ServerManager::State)) ); } } void KMMainWidget::slotServerStateChanged(Akonadi::ServerManager::State state) { if (state == Akonadi::ServerManager::Running) { initializeFilterActions(); disconnect( Akonadi::ServerManager::self(), SIGNAL(stateChanged(Akonadi::ServerManager::State))); } } void KMMainWidget::slotShowTip() { KTipDialog::showTip( this, QString(), true ); } QList KMMainWidget::actionCollections() const { return QList() << actionCollection(); } //----------------------------------------------------------------------------- void KMMainWidget::slotUpdateUndo() { if ( actionCollection()->action( QLatin1String("kmail_undo") ) ) { actionCollection()->action( QLatin1String("kmail_undo") )->setEnabled( kmkernel->undoStack()->size()>0 ); } } //----------------------------------------------------------------------------- void KMMainWidget::clearFilterActions() { if ( !mFilterTBarActions.isEmpty() ) if ( mGUIClient->factory() ) mGUIClient->unplugActionList( QLatin1String("toolbar_filter_actions") ); if ( !mFilterMenuActions.isEmpty() ) if ( mGUIClient->factory() ) mGUIClient->unplugActionList( QLatin1String("menu_filter_actions") ); foreach ( QAction *a, mFilterMenuActions ) actionCollection()->removeAction( a ); mApplyFilterActionsMenu->menu()->clear(); mFilterTBarActions.clear(); mFilterMenuActions.clear(); qDeleteAll( mFilterCommands ); mFilterCommands.clear(); } //----------------------------------------------------------------------------- void KMMainWidget::initializeFilterActions() { clearFilterActions(); mApplyFilterActionsMenu->menu()->addAction( mApplyAllFiltersAction ); bool addedSeparator = false; foreach ( MailFilter *filter, MailCommon::FilterManager::instance()->filters() ) { if ( !filter->isEmpty() && filter->configureShortcut() && filter->isEnabled() ) { QString filterName = QString::fromLatin1( "Filter %1").arg( filter->name() ); QString normalizedName = filterName.replace(QLatin1Char(' '), QLatin1Char('_')); if ( action( normalizedName ) ) { continue; } KMMetaFilterActionCommand *filterCommand = new KMMetaFilterActionCommand( filter->identifier(), this ); mFilterCommands.append( filterCommand ); QString displayText = i18n( "Filter %1", filter->name() ); QString icon = filter->icon(); if ( icon.isEmpty() ) { icon = QLatin1String("system-run"); } KAction *filterAction = new KAction( KIcon( icon ), displayText, actionCollection() ); filterAction->setIconText( filter->toolbarName() ); // The shortcut configuration is done in the filter dialog. // The shortcut set in the shortcut dialog would not be saved back to // the filter settings correctly. filterAction->setShortcutConfigurable( false ); actionCollection()->addAction( normalizedName, filterAction ); connect( filterAction, SIGNAL(triggered(bool)), filterCommand, SLOT(start()) ); filterAction->setShortcuts( filter->shortcut() ); if ( !addedSeparator ) { QAction *a = mApplyFilterActionsMenu->menu()->addSeparator(); mFilterMenuActions.append( a ); addedSeparator = true; } mApplyFilterActionsMenu->menu()->addAction( filterAction ); mFilterMenuActions.append( filterAction ); if ( filter->configureToolbar() ) { mFilterTBarActions.append( filterAction ); } } } if ( !mFilterMenuActions.isEmpty() && mGUIClient->factory() ) mGUIClient->plugActionList( QLatin1String("menu_filter_actions"), mFilterMenuActions ); if ( !mFilterTBarActions.isEmpty() && mGUIClient->factory() ) { mFilterTBarActions.prepend( mToolbarActionSeparator ); mGUIClient->plugActionList( QLatin1String("toolbar_filter_actions"), mFilterTBarActions ); } // Our filters have changed, now enable/disable them updateMessageActions(); } //----------------------------------------------------------------------------- void KMMainWidget::slotAntiSpamWizard() { AntiSpamWizard wiz( AntiSpamWizard::AntiSpam, this ); wiz.exec(); } //----------------------------------------------------------------------------- void KMMainWidget::slotAntiVirusWizard() { AntiSpamWizard wiz( AntiSpamWizard::AntiVirus, this); wiz.exec(); } //----------------------------------------------------------------------------- void KMMainWidget::slotAccountWizard() { KMail::Util::launchAccountWizard( this ); } void KMMainWidget::slotImportWizard() { const QString path = KStandardDirs::findExe( QLatin1String("importwizard" ) ); if ( !QProcess::startDetached( path ) ) KMessageBox::error( this, i18n( "Could not start the import wizard. " "Please check your installation." ), i18n( "Unable to start import wizard" ) ); } //----------------------------------------------------------------------------- void KMMainWidget::slotFilterLogViewer() { MailCommon::FilterManager::instance()->showFilterLogDialog( (qlonglong)winId() ); } //----------------------------------------------------------------------------- void KMMainWidget::updateFileMenu() { const bool isEmpty = MailCommon::Util::agentInstances().isEmpty(); actionCollection()->action(QLatin1String("check_mail"))->setEnabled( !isEmpty ); actionCollection()->action(QLatin1String("check_mail_in"))->setEnabled( !isEmpty ); } //----------------------------------------------------------------------------- const KMMainWidget::PtrList * KMMainWidget::mainWidgetList() { // better safe than sorry; check whether the global static has already been destroyed if ( theMainWidgetList.isDestroyed() ) { return 0; } return theMainWidgetList; } QSharedPointer KMMainWidget::currentFolder() const { return mCurrentFolder; } //----------------------------------------------------------------------------- QString KMMainWidget::overrideEncoding() const { if ( mMsgView ) return mMsgView->overrideEncoding(); else return MessageCore::GlobalSettings::self()->overrideCharacterEncoding(); } void KMMainWidget::showEvent( QShowEvent *event ) { QWidget::showEvent( event ); mWasEverShown = true; } void KMMainWidget::slotRequestFullSearchFromQuickSearch() { // First, open the search window. If we are currently on a search folder, // the search associated with that will be loaded. if ( !slotSearch() ) return; assert( mSearchWin ); // Now we look at the current state of the quick search, and if there's // something in there, we add the criteria to the existing search for // the search folder, if applicable, or make a new one from it. SearchPattern pattern; const QString searchString = mMessagePane->currentFilterSearchString(); if ( !searchString.isEmpty() ) pattern.append( SearchRule::createInstance( "", SearchRule::FuncContains, searchString ) ); #if 0 //PORT IT QList status = mMessagePane->currentFilterStatus(); if ( status.hasAttachment() ) { pattern.append( SearchRule::createInstance( "", SearchRule::FuncHasAttachment ) ); status.setHasAttachment( false ); } if ( !status.isOfUnknownStatus() ) { pattern.append( SearchRule::Ptr( new SearchRuleStatus( status ) ) ); } #endif if ( !pattern.isEmpty() ) mSearchWin->addRulesToSearchPattern( pattern ); } void KMMainWidget::updateVacationScriptStatus( bool active, const QString &serverName ) { mVacationScriptIndicator->setVacationScriptActive(active, serverName); mVacationIndicatorActive = mVacationScriptIndicator->hasVacationScriptActive(); } QWidget * KMMainWidget::vacationScriptIndicator() const { return mVacationScriptIndicator; } void KMMainWidget::updateVacationScriptStatus() { updateVacationScriptStatus( mVacationIndicatorActive ); } KMail::TagActionManager *KMMainWidget::tagActionManager() const { return mTagActionManager; } KMail::FolderShortcutActionManager *KMMainWidget::folderShortcutActionManager() const { return mFolderShortcutActionManager; } void KMMainWidget::slotMessageSelected(const Akonadi::Item &item) { delete mShowBusySplashTimer; mShowBusySplashTimer = 0; if ( mMsgView ) { // The current selection was cleared, so we'll remove the previously // selected message from the preview pane if ( !item.isValid() ) { mMsgView->clear(); } else { mShowBusySplashTimer = new QTimer( this ); mShowBusySplashTimer->setSingleShot( true ); connect( mShowBusySplashTimer, SIGNAL(timeout()), this, SLOT(slotShowBusySplash()) ); mShowBusySplashTimer->start( GlobalSettings::self()->folderLoadingTimeout() ); //TODO: check if we need a different timeout setting for this Akonadi::ItemFetchJob *itemFetchJob = MessageViewer::Viewer::createFetchJob( item ); const QString resource = mCurrentFolder->collection().resource(); itemFetchJob->setProperty( "_resource", QVariant::fromValue(resource) ); connect( itemFetchJob, SIGNAL(itemsReceived(Akonadi::Item::List)), SLOT(itemsReceived(Akonadi::Item::List)) ); connect( itemFetchJob, SIGNAL(result(KJob*)), SLOT(itemsFetchDone(KJob*)) ); } } } void KMMainWidget::itemsReceived(const Akonadi::Item::List &list ) { Q_ASSERT( list.size() == 1 ); delete mShowBusySplashTimer; mShowBusySplashTimer = 0; if ( !mMsgView ) return; Item item = list.first(); if ( mMessagePane ) { mMessagePane->show(); if ( mMessagePane->currentItem() != item ) { // The user has selected another email already, so don't render this one. // Mark it as read, though, if the user settings say so. if ( MessageViewer::GlobalSettings::self()->delayedMarkAsRead() && MessageViewer::GlobalSettings::self()->delayedMarkTime() == 0 ) { item.setFlag( Akonadi::MessageFlags::Seen ); Akonadi::ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob( item, this ); modifyJob->disableRevisionCheck(); modifyJob->setIgnorePayload( true ); } return; } } mMsgView->setMessage( item ); // reset HTML override to the folder setting mMsgView->setHtmlOverride(mFolderHtmlPref); mMsgView->setHtmlLoadExtOverride(mFolderHtmlLoadExtPref); mMsgView->setDecryptMessageOverwrite( false ); mMsgActions->setCurrentMessage( item ); } void KMMainWidget::itemsFetchDone( KJob *job ) { delete mShowBusySplashTimer; mShowBusySplashTimer = 0; if ( job->error() ) { // Unfortunately job->error() is Job::Unknown in many cases. // (see JobPrivate::handleResponse in akonadi/job.cpp) // So we show the "offline" page after checking the resource status. kDebug() << job->error() << job->errorString(); const QString resource = job->property("_resource").toString(); const Akonadi::AgentInstance agentInstance = Akonadi::AgentManager::self()->instance( resource ); if ( !agentInstance.isOnline() ) { // The resource is offline if ( mMsgView ) { mMsgView->viewer()->enableMessageDisplay(); mMsgView->clear( true ); } mMessagePane->show(); if (kmkernel->isOffline()) showOfflinePage(); else showResourceOfflinePage(); } else { // Some other error BroadcastStatus::instance()->setStatusMsg( job->errorString() ); } } } KAction *KMMainWidget::akonadiStandardAction( Akonadi::StandardActionManager::Type type ) { return mAkonadiStandardActionManager->action( type ); } KAction *KMMainWidget::akonadiStandardAction( Akonadi::StandardMailActionManager::Type type ) { return mAkonadiStandardActionManager->action( type ); } void KMMainWidget::slotCollectionProperties() { showCollectionProperties( QString() ); } void KMMainWidget::showCollectionProperties( const QString &pageToShow ) { if ( !mCurrentFolder ) return; if ( Solid::Networking::status() == Solid::Networking::Unconnected ) { KMessageBox::information( this, i18n( "Network is unconnected. Folder information cannot be updated." ) ); showCollectionPropertiesContinued( pageToShow, QPointer() ); } else { const Akonadi::AgentInstance agentInstance = Akonadi::AgentManager::self()->instance( mCurrentFolder->collection().resource() ); bool isOnline = agentInstance.isOnline(); if (!isOnline) { showCollectionPropertiesContinued( pageToShow, QPointer() ); } else { QPointer progressItem( KPIM::ProgressManager::createProgressItem( i18n( "Retrieving folder properties" ) ) ); progressItem->setUsesBusyIndicator( true ); progressItem->setCryptoStatus(KPIM::ProgressItem::Unknown); Akonadi::CollectionAttributesSynchronizationJob *sync = new Akonadi::CollectionAttributesSynchronizationJob( mCurrentFolder->collection() ); sync->setProperty( "collectionId", mCurrentFolder->collection().id() ); sync->setProperty( "pageToShow", pageToShow ); // note for dialog later sync->setProperty( "progressItem", QVariant::fromValue( progressItem ) ); connect( sync, SIGNAL(result(KJob*)), this, SLOT(slotCollectionPropertiesContinued(KJob*)) ); connect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), sync, SLOT(kill()) ); connect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), KPIM::ProgressManager::instance(), SLOT(slotStandardCancelHandler(KPIM::ProgressItem*)) ); sync->start(); } } } void KMMainWidget::slotCollectionPropertiesContinued( KJob* job ) { QString pageToShow; QPointer progressItem; if ( job ) { Akonadi::CollectionAttributesSynchronizationJob *sync = dynamic_cast( job ); Q_ASSERT( sync ); if ( sync->property( "collectionId" ) != mCurrentFolder->collection().id() ) return; pageToShow = sync->property( "pageToShow" ).toString(); progressItem = sync->property( "progressItem" ).value< QPointer >(); if ( progressItem ) { disconnect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), sync, SLOT(kill()) ); } else { // progressItem does not exist anymore, operation has been canceled return; } } showCollectionPropertiesContinued( pageToShow, progressItem ); } void KMMainWidget::showCollectionPropertiesContinued( const QString &pageToShow, QPointer progressItem ) { if ( !progressItem ) { progressItem = KPIM::ProgressManager::createProgressItem( i18n( "Retrieving folder properties" ) ); progressItem->setUsesBusyIndicator( true ); progressItem->setCryptoStatus(KPIM::ProgressItem::Unknown); connect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), KPIM::ProgressManager::instance(), SLOT(slotStandardCancelHandler(KPIM::ProgressItem*)) ); } Akonadi::CollectionFetchJob *fetch = new Akonadi::CollectionFetchJob( mCurrentFolder->collection(), Akonadi::CollectionFetchJob::Base ); connect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), fetch, SLOT(kill()) ); fetch->fetchScope().setIncludeStatistics( true ); fetch->setProperty( "pageToShow", pageToShow ); fetch->setProperty( "progressItem", QVariant::fromValue( progressItem ) ); connect( fetch, SIGNAL(result(KJob*)), this, SLOT(slotCollectionPropertiesFinished(KJob*)) ); connect( progressItem, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), fetch, SLOT(kill()) ); } void KMMainWidget::slotCollectionPropertiesFinished( KJob *job ) { if ( !job ) return; QPointer progressItem = job->property( "progressItem" ).value< QPointer >(); // progressItem does not exist anymore, operation has been canceled if ( !progressItem ) { return; } progressItem->setComplete(); progressItem->setStatus( i18n( "Done" ) ); Akonadi::CollectionFetchJob *fetch = dynamic_cast( job ); Q_ASSERT( fetch ); if ( fetch->collections().isEmpty() ) { kWarning() << "no collection"; return; } const Akonadi::Collection collection = fetch->collections().first(); const QStringList pages = QStringList() << QLatin1String( "MailCommon::CollectionGeneralPage" ) << QLatin1String( "KMail::CollectionViewPage" ) << QLatin1String( "Akonadi::CachePolicyPage" ) << QLatin1String( "KMail::CollectionTemplatesPage" ) << QLatin1String( "MailCommon::CollectionExpiryPage" ) << QLatin1String( "PimCommon::CollectionAclPage" ) << QLatin1String( "KMail::CollectionMailingListPage" ) << QLatin1String( "KMail::CollectionQuotaPage" ) << QLatin1String( "KMail::CollectionShortcutPage" ) << QLatin1String( "KMail::CollectionMaintenancePage" ); Akonadi::CollectionPropertiesDialog *dlg = new Akonadi::CollectionPropertiesDialog( collection, pages, this ); dlg->setCaption( i18nc( "@title:window", "Properties of Folder %1", collection.name() ) ); const QString pageToShow = fetch->property( "pageToShow" ).toString(); if ( !pageToShow.isEmpty() ) { // show a specific page dlg->setCurrentPage( pageToShow ); } dlg->show(); } void KMMainWidget::slotRemoveDuplicates() { KPIM::ProgressItem *item = KPIM::ProgressManager::createProgressItem( i18n( "Removing duplicates" ) ); item->setUsesBusyIndicator( true ); item->setCryptoStatus(KPIM::ProgressItem::Unknown); QItemSelectionModel *selectionModel = mFolderTreeWidget->folderTreeView()->selectionModel(); QModelIndexList indexes = selectionModel->selectedIndexes(); Akonadi::Collection::List collections; Q_FOREACH (const QModelIndex &index, indexes) { Akonadi::Collection collection = index.data(Akonadi::EntityTreeModel::CollectionRole).value(); if ( collection.isValid() ) { collections << collection; } } Akonadi::RemoveDuplicatesJob *job = new RemoveDuplicatesJob( collections, this ); job->setProperty( "ProgressItem", QVariant::fromValue ( item ) ); item->setProperty( "RemoveDuplicatesJob", QVariant::fromValue( qobject_cast( job ) ) ); connect( job, SIGNAL(finished(KJob*)), this, SLOT(slotRemoveDuplicatesDone(KJob*)) ); connect( job, SIGNAL(description(KJob*,QString,QPair,QPair)), this, SLOT(slotRemoveDuplicatesUpdate(KJob*,QString)) ); connect( item, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), this, SLOT(slotRemoveDuplicatesCanceled(KPIM::ProgressItem*)) ); } void KMMainWidget::slotRemoveDuplicatesDone( KJob *job ) { if ( job->error() && job->error() != KJob::KilledJobError ) { KMessageBox::error( this, job->errorText(), i18n( "Error while removing duplicates" ) ); } KPIM::ProgressItem *item = job->property( "ProgressItem" ).value(); if ( item ) { item->setComplete(); item->setStatus( i18n( "Done" ) ); item = 0; } } void KMMainWidget::slotRemoveDuplicatesCanceled( KPIM::ProgressItem *item ) { Akonadi::Job *job = item->property( "RemoveDuplicatesJob" ).value(); if ( job ) { job->kill( KJob::Quietly ); } item->setComplete(); item = 0; } void KMMainWidget::slotRemoveDuplicatesUpdate( KJob* job, const QString& description ) { KPIM::ProgressItem *item = job->property( "ProgressItem" ).value(); if ( item ) { item->setStatus( description ); } } void KMMainWidget::slotServerSideSubscription() { if ( !mCurrentFolder ) return; bool isImapOnline = false; if ( kmkernel->isImapFolder( mCurrentFolder->collection(), isImapOnline ) ) { QDBusInterface iface( QLatin1String( "org.freedesktop.Akonadi.Resource.")+mCurrentFolder->collection().resource(), - QLatin1String( "/" ), QLatin1String( "org.kde.Akonadi.Imap.Resource" ), + QLatin1String( "/" ), QLatin1String( "org.kde.Akonadi.ImapResourceBase" ), DBusConnectionPool::threadConnection(), this ); if ( !iface.isValid() ) { kDebug()<<"Cannot create imap dbus interface"; return; } QDBusPendingCall call = iface.asyncCall( QLatin1String( "configureSubscription" ), (qlonglong)winId() ); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(slotConfigureSubscriptionFinished(QDBusPendingCallWatcher*))); } } void KMMainWidget::slotConfigureSubscriptionFinished(QDBusPendingCallWatcher* watcher) { QDBusPendingReply reply = *watcher; if ( !reply.isValid() ) { return; } if (reply == -2 ){ KMessageBox::error(this,i18n("IMAP server not configured yet. Please configure the server in the IMAP account before setting up server-side subscription.")); } else if (reply == -1) { KMessageBox::error(this,i18n("Log in failed, please configure the IMAP account before setting up server-side subscription.")); } watcher->deleteLater(); } void KMMainWidget::savePaneSelection() { if (mMessagePane) { mMessagePane->saveCurrentSelection(); } } void KMMainWidget::slotConfigureAutomaticArchiving() { OrgFreedesktopAkonadiArchiveMailAgentInterface archiveMailInterface(QLatin1String("org.freedesktop.Akonadi.ArchiveMailAgent"), QLatin1String("/ArchiveMailAgent"),QDBusConnection::sessionBus(), this); if (archiveMailInterface.isValid()) { archiveMailInterface.showConfigureDialog( (qlonglong)winId() ); } else { KMessageBox::error(this,i18n("Archive Mail Agent was not registered.")); } } void KMMainWidget::slotConfigureSendLater() { OrgFreedesktopAkonadiSendLaterAgentInterface sendLaterInterface(QLatin1String("org.freedesktop.Akonadi.SendLaterAgent"), QLatin1String("/SendLaterAgent"),QDBusConnection::sessionBus(), this); if (sendLaterInterface.isValid()) { sendLaterInterface.showConfigureDialog( (qlonglong)winId() ); } else { KMessageBox::error(this,i18n("Send Later Agent was not registered.")); } } void KMMainWidget::updatePaneTagComboBox() { if (mMessagePane) { mMessagePane->updateTagComboBox(); } } void KMMainWidget::slotExportData() { const QString path = KStandardDirs::findExe( QLatin1String("pimsettingexporter" ) ); if ( !QProcess::startDetached( path ) ) KMessageBox::error( this, i18n( "Could not start \"PIM Setting Exporter\" program. " "Please check your installation." ), i18n( "Unable to start \"PIM Setting Exporter\" program" ) ); } void KMMainWidget::slotCreateAddressBookContact() { CreateNewContactJob *job = new CreateNewContactJob( this, this ); job->start(); } void KMMainWidget::slotOpenRecentMsg(const KUrl& url) { KMOpenMsgCommand *openCommand = new KMOpenMsgCommand( this, url, overrideEncoding(), this ); openCommand->start(); } void KMMainWidget::addRecentFile(const KUrl& mUrl) { mOpenRecentAction->addUrl(mUrl); KConfigGroup grp = mConfig->group(QLatin1String("Recent Files")); mOpenRecentAction->saveEntries(grp); grp.sync(); } void KMMainWidget::slotMoveMessageToTrash() { if (messageView() && messageView()->viewer()) { KMTrashMsgCommand *command = new KMTrashMsgCommand( mCurrentFolder->collection(), messageView()->viewer()->messageItem(), -1 ); command->start(); } } void KMMainWidget::slotArchiveMails() { const QList selectedMessages = mMessagePane->selectionAsMessageItemList(); KMKernel::self()->folderArchiveManager()->setArchiveItems(selectedMessages, mCurrentFolder->collection().resource()); } void KMMainWidget::updateQuickSearchLineText() { //If change change shortcut mMessagePane->setQuickSearchClickMessage(i18nc("Show shortcut for focus quick search. Don't change it", "Search...<%1>",mQuickSearchAction->shortcut().toString())); }