/* * QMPDClient - An MPD client written in Qt 4. * Copyright (C) 2005-2007 Håvard Tautra Knutsen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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. */ #include "config.h" #include "mpdsong.h" #include "notifications.h" #include "passivepopup.h" #include "richtext.h" #include #include QString Notifications::name(Type t) { switch (t) { case FREEDESKTOP: return "Freedesktop"; default: return "Custom"; } } QString Notifications::makeTitle(const MPDSong &s) { int desktopWidth = QApplication::desktop()->width(); QString title = elideRichText("", s.title(), "", desktopWidth / 2) + "\n"; QString artist = elideRichText("", s.artist(), "", desktopWidth / 4); QString album = elideRichText("", s.album(), "", desktopWidth / 4); title += artist; if (!artist.isEmpty() && !album.isEmpty()) title += " - "; if (!album.isEmpty()) title += album; return title; } void Notifications::notify(const QString &text) { if (m_config->notifier() == FREEDESKTOP && m_dbus) { m_dbus = notifyDBus(text); if (m_dbus) // DBus notify succeeded return; qWarning("DBus notify failed, falling back to custom notifier."); } PassivePopup::Position pos = static_cast(m_config->notificationsPosition()); new PassivePopup("QMPDClient", text, QPixmap(":/icons/qmpdclient22.png"), pos, m_config->notificationsTimeout()); } void Notifications::setSong(const MPDSong &s) { Q_ASSERT(m_config); if (s.isNull()) { m_previousUrl = QString(); return; } if (m_previousUrl == s.url() || !m_config->notificationsEnabled() || m_config->notificationsTimeout() < 1) { m_previousUrl = s.url(); return; } notify(makeTitle(s)); m_previousUrl = s.url(); }