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