PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 8ms RepoModel.GetById 52ms app.codeStats 0ms

/src/libtomahawk/infosystem/infoplugins/unix/fdonotifyplugin.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 99 lines | 53 code | 10 blank | 36 comment | 6 complexity | fb96ca9bc1442a15a9bbe7291ba074ef MD5 | raw file
 1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 2 *
 3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
 4 *
 5 *   Tomahawk is free software: you can redistribute it and/or modify
 6 *   it under the terms of the GNU General Public License as published by
 7 *   the Free Software Foundation, either version 3 of the License, or
 8 *   (at your option) any later version.
 9 *
10 *   Tomahawk is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19// Marked portions of this file are subject to the following copyright:
20/*
21 * Copyright (C) 2009 by Aurélien Gâteau <aurelien.gateau@canonical.com>
22 *
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2, or (at your option)
26 * any later version.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
36 *
37 */
38
39#include "fdonotifyplugin.h"
40#include "utils/tomahawkutils.h"
41#include "imageconverter.h"
42
43#include <QtDBus/QDBusConnection>
44#include <QtDBus/QDBusMessage>
45#include <QtGui/QImage>
46
47#include "utils/logger.h"
48
49using namespace Tomahawk::InfoSystem;
50
51
52FdoNotifyPlugin::FdoNotifyPlugin()
53    : InfoPlugin()
54{
55    qDebug() << Q_FUNC_INFO;
56    m_supportedPushTypes << Tomahawk::InfoSystem::InfoNotifyUser;
57}
58
59FdoNotifyPlugin::~FdoNotifyPlugin()
60{
61    qDebug() << Q_FUNC_INFO;
62}
63
64void
65FdoNotifyPlugin::pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant pushData )
66{
67    Q_UNUSED( caller );
68    qDebug() << Q_FUNC_INFO;
69    if ( type != Tomahawk::InfoSystem::InfoNotifyUser || !pushData.canConvert< QVariantMap >() )
70    {
71        qDebug() << Q_FUNC_INFO << " not the right type or could not convert the hash";
72        return;
73    }
74    QVariantMap hash = pushData.value< QVariantMap >();
75    if ( !hash.contains( "message" ) )
76    {
77        qDebug() << Q_FUNC_INFO << " hash did not contain a message";
78        return;
79    }
80
81    QDBusMessage message = QDBusMessage::createMethodCall( "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify" );
82    QList<QVariant> arguments;
83    arguments << QString( "Tomahawk" ); //app_name
84    arguments << quint32( 0 ); //notification_id
85    arguments << QString(); //app_icon
86    arguments << QString( "Tomahawk" ); //summary
87    arguments << hash[ "message" ].toString(); //body
88    arguments << QStringList(); //actions
89    QVariantMap dict;
90    dict["desktop-entry"] = QString( "tomahawk" );
91    if ( hash.contains( "image" ) && hash[ "image" ].canConvert< QImage >() )
92        dict[ "image_data" ] = ImageConverter::variantForImage( hash[ "image" ].value< QImage >() );
93    else
94        dict[ "image_data" ] = ImageConverter::variantForImage( QImage( RESPATH "icons/tomahawk-icon-128x128.png" ) );
95    arguments << dict; //hints
96    arguments << qint32( -1 ); //expire_timeout
97    message.setArguments( arguments );
98    QDBusConnection::sessionBus().send( message );
99}