Commit 93827ef5 authored by Volker Krause's avatar Volker Krause
Browse files

Add new mail notifier for WinCE.

svn path=/trunk/KDE/kdepim/runtime/; revision=1202327
parent 35b6607a
......@@ -10,6 +10,7 @@ macro(kdepim_add_agent _target)
endmacro(kdepim_add_agent)
add_subdirectory( maildispatcher )
add_subdirectory( newmailnotifier )
if( STRIGI_FOUND )
add_subdirectory( strigifeeder )
......
include_directories(
${kdepim-runtime_SOURCE_DIR}
${Boost_INCLUDE_DIR}
)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" )
option(BUILD_NEW_MAIL_NOTIFIER_AGENT FALSE "Build mobile new mail notification agent")
if (BUILD_NEW_MAIL_NOTIFIER_AGENT)
set(newmailnotifieragent_SRCS
newmailnotifieragent.cpp
)
if (NOT WINCE)
kde4_add_plugin(newmailnotifieragent ${newmailnotifieragent_SRCS})
else ()
kde4_add_plugin(newmailnotifieragent ${newmailnotifieragent_SRCS})
endif ()
target_link_libraries(newmailnotifieragent
${KDEPIMLIBS_AKONADI_LIBS}
${KDEPIMLIBS_KMIME_LIBS}
${KDEPIMLIBS_AKONADI_KMIME_LIBS}
${QT_QTCORE_LIBRARY}
${QT_QTDBUS_LIBRARY}
)
install(TARGETS newmailnotifieragent DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES newmailnotifieragent.desktop DESTINATION "${CMAKE_INSTALL_PREFIX}/share/akonadi/agents")
endif ()
/*
Copyright (c) 2010 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "newmailnotifieragent.h"
#include <akonadi/agentfactory.h>
#include <akonadi/changerecorder.h>
#include <KMime/Message>
#include <akonadi/itemfetchscope.h>
#include <KNotification>
#include <KLocalizedString>
#include <akonadi/kmime/messagestatus.h>
#include <akonadi/entitydisplayattribute.h>
NewMailNotifierAgent::NewMailNotifierAgent(const QString& id) : AgentBase(id)
{
changeRecorder()->setMimeTypeMonitored( KMime::Message::mimeType() );
changeRecorder()->itemFetchScope().setCacheOnly( true );
changeRecorder()->itemFetchScope().setFetchModificationTime( false );
changeRecorder()->fetchCollection( true );
changeRecorder()->setChangeRecordingEnabled( false );
m_timer.setInterval( 30 * 1000 );
m_timer.setSingleShot( true );
connect( &m_timer, SIGNAL(timeout()), SLOT(showNotifications()) );
}
void NewMailNotifierAgent::itemAdded(const Akonadi::Item& item, const Akonadi::Collection& collection)
{
Akonadi::MessageStatus status;
status.setStatusFromFlags( item.flags() );
if ( status.isRead() )
return;
if ( !m_timer.isActive() )
m_timer.start();
m_newMails[collection]++;
}
void NewMailNotifierAgent::showNotifications()
{
QStringList texts;
for ( QHash< Akonadi::Collection, int >::const_iterator it = m_newMails.constBegin(); it != m_newMails.constEnd(); ++it ) {
Akonadi::EntityDisplayAttribute *attr = it.key().attribute<Akonadi::EntityDisplayAttribute>();
QString displayName;
if ( attr && !attr->displayName().isEmpty() )
displayName = attr->displayName();
else
displayName = it.key().name();
texts.append( i18np( "One new email in %2", "%1 new emails in %2", it.value(), displayName ) );
}
kDebug() << texts;
KNotification *notify = new KNotification( "new-email", 0L, KNotification::Persistent );
notify->setText( texts.join( "\n" ) );
notify->sendEvent();
m_newMails.clear();
}
AKONADI_AGENT_FACTORY( NewMailNotifierAgent, newmailnotifier );
#include "newmailnotifieragent.moc"
[Desktop Entry]
Name=New Email Notfier
Comment=Notifications about newly received emails
Icon=mail-unread-new
Type=AkonadiAgent
Exec=newmailnotifieragent
X-Akonadi-MimeTypes=message/rfc822
X-Akonadi-Capabilities=Unique,Autostart,NoConfig
X-Akonadi-Identifier=akonadi_newmailnotifier_agent
X-Akonadi-LaunchMethod=AgentServer
/*
Copyright (c) 2010 Volker Krause <vkrause@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library 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 Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef NEWMAILNOTIFIERAGENT_H
#define NEWMAILNOTIFIERAGENT_H
#include <Akonadi/Collection>
#include <akonadi/agentbase.h>
#include <QtCore/QTimer>
class NewMailNotifierAgent : public Akonadi::AgentBase, public Akonadi::AgentBase::ObserverV2
{
Q_OBJECT
public:
NewMailNotifierAgent(const QString& id);
void itemAdded(const Akonadi::Item& item, const Akonadi::Collection& collection);
private slots:
void showNotifications();
private:
QHash<Akonadi::Collection, int> m_newMails;
QTimer m_timer;
};
#endif
......@@ -16,6 +16,7 @@ target_link_libraries(akonadi_agent_server
akonadi_akonotes_resource
akonadi_contacts_resource
korgac
newmailnotifieragent
akonadi_serializer_mail
akonadi_serializer_kcalcore
......
......@@ -25,6 +25,7 @@ Q_IMPORT_PLUGIN(akonadi_maildir_resource)
Q_IMPORT_PLUGIN(akonadi_akonotes_resource)
Q_IMPORT_PLUGIN(akonadi_contacts_resource)
Q_IMPORT_PLUGIN(korgac)
Q_IMPORT_PLUGIN(newmailnotifieragent)
Q_IMPORT_PLUGIN(akonadi_serializer_mail)
Q_IMPORT_PLUGIN(akonadi_serializer_addressee)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment