/* * 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 "controlpanel.h" #include "mpd.h" #include "mpdconnection.h" #include "mpdsong.h" #include "richtext.h" #include ControlPanel::ControlPanel(QWidget *parent) : QWidget(parent), m_mpd(MPD::instance()) { Q_ASSERT(m_mpd); setupUi(this); connect(prevButton, SIGNAL(clicked()), m_mpd, SLOT(prev())); connect(playButton, SIGNAL(clicked()), m_mpd, SLOT(play())); connect(pauseButton, SIGNAL(clicked()), m_mpd, SLOT(pause())); connect(stopButton, SIGNAL(clicked()), m_mpd, SLOT(stop())); connect(nextButton, SIGNAL(clicked()), m_mpd, SLOT(next())); connect(volumeSlider, SIGNAL(valueChanged(int)), m_mpd, SLOT(setVolume(int))); connect(timeSlider, SIGNAL(timeChanged(int)), m_mpd, SLOT(seek(int))); connect(timeSlider, SIGNAL(valueChanged(int)), elapsedLabel, SLOT(setTime(int))); connect(m_mpd, SIGNAL(volumeUpdated(int)), volumeSlider, SLOT(setValue(int))); connect(m_mpd, SIGNAL(timeUpdated(int, int)), elapsedLabel, SLOT(setTime(int, int))); connect(m_mpd, SIGNAL(timeUpdated(int, int)), totalLabel, SLOT(setTime(int, int))); connect(m_mpd, SIGNAL(timeUpdated(int, int)), timeSlider, SLOT(setTime(int, int))); connect(m_mpd, SIGNAL(playingSongUpdated(const MPDSong &)), this, SLOT(setSong(const MPDSong &))); // Short cuts m_fwdKey = new QShortcut(Qt::CTRL | Qt::Key_Right, this); m_rwdKey = new QShortcut(Qt::CTRL | Qt::Key_Left, this); m_volUpKey = new QShortcut(Qt::CTRL | Qt::Key_Up, this); m_volDnKey = new QShortcut(Qt::CTRL | Qt::Key_Down, this); m_fwdKey->setObjectName("nextSongKey"); m_rwdKey->setObjectName("prevSongKey"); m_volUpKey->setObjectName("volumeUpKey"); m_volDnKey->setObjectName("volumeDownKey"); connect(m_fwdKey, SIGNAL(activated()), m_mpd, SLOT(seekForward())); connect(m_rwdKey, SIGNAL(activated()), m_mpd, SLOT(seekBackward())); connect(m_volUpKey, SIGNAL(activated()), m_mpd, SLOT(volumeUp())); connect(m_volDnKey, SIGNAL(activated()), m_mpd, SLOT(volumeDown())); setSong(MPDSong()); } void ControlPanel::updateTranslation() { retranslateUi(this); m_fwdKey->setWhatsThis(tr("Seek forward")); m_rwdKey->setWhatsThis(tr("Seek backward")); m_volUpKey->setWhatsThis(tr("Increase volume")); m_volDnKey->setWhatsThis(tr("Decrease volume")); } void ControlPanel::setSong(const MPDSong &s) { if (s.isNull()) { titleLabel->setText(MPDConnection::instance()->isConnected() ? "" : QString("

%1

").arg(tr("Not connected", "qmpdclient is not connected to MPD"))); artistLabel->setText(""); timeSlider->setEnabled(true); return; } // Disable time counting for streams timeSlider->setEnabled(s.type() != MPDSong::PLAYLISTSTREAM); // Ensure labels are not too small if window is hidden const int titleWidth = isVisible() ? titleLabel->width() : width() - 200; const int artistWidth = isVisible() ? artistLabel->width() : width() - 200; QString title = elideRichText("

", s.title() , "

", titleWidth); QString artist = s.artist(); QString album = s.album(); if (!artist.isEmpty() && !album.isEmpty()) artist = elideRichText("", QString("%1 - %2").arg(artist).arg(album), "", artistWidth); else if (!artist.isEmpty()) artist = elideRichText("", artist, "", artistWidth); else if (!album.isEmpty()) artist += elideRichText("", album, "", artistWidth); titleLabel->setText(title); artistLabel->setText(artist); }