diff --git a/CMakeLists.txt b/CMakeLists.txt index 14cb424..0c5ee12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,158 +1,178 @@ project(kscd) cmake_minimum_required(VERSION 2.8.12) find_package(ECM REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH "${ECM_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake") add_definitions(-fexceptions) include(FeatureSummary) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMInstallIcons) # Handle build type if(CMAKE_BUILD_TYPE MATCHES [Dd]ebug) message(STATUS "Debug build") add_definitions(-DKSCD_DEBUG) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0") else() message(STATUS "Release build") add_definitions(-DNDEBUG) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2") endif() find_package(Qt5 REQUIRED COMPONENTS Widgets Svg) -find_package(KF5 REQUIRED Config I18n Solid KIO KDELibs4Support GlobalAccel DBusAddons) +find_package(KF5 REQUIRED + Config + ConfigWidgets + CoreAddons + DBusAddons + GlobalAccel + I18n + IconThemes + KDELibs4Support + KIO + Service + Solid + WidgetsAddons + XmlGui +) find_package(Phonon4Qt5 REQUIRED) find_package(MusicBrainz5 REQUIRED) find_package(DiscId REQUIRED) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/gui ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${PHONON_INCLUDE_DIR} ${MUSICBRAINZ5_INCLUDE_DIR} ${DISCID_INCLUDE_DIR} ) if(BUILD_TESTING) find_package(Qt5Test REQUIRED) add_subdirectory(tests) endif() ########### next target ############### set(kscd_SRCS ########## # Main ########## kscd.cpp ############### # Solid/Phonon ############### hwcontroler.cpp audiocd.cpp ######################### # Music Brainz ######################### mbmanager.cpp #################### # Graphics / SVG #################### gui/kscdwindow.cpp gui/kscdwidget.cpp gui/ejectbutton.cpp gui/stopbutton.cpp gui/playbutton.cpp gui/nextbutton.cpp gui/previousbutton.cpp gui/mutebutton.cpp gui/randombutton.cpp gui/loopbutton.cpp gui/tracklistbutton.cpp gui/volumebutton.cpp gui/panel.cpp gui/titlePopUp.cpp gui/tracklistdlg.cpp gui/background.cpp gui/closebutton.cpp gui/minimizebutton.cpp #gui/seekslider.cpp gui/seekcursor.cpp gui/seekbar.cpp #################### # DBus Connection #################### dbus/PlayerDBusHandler.cpp dbus/RootDBusHandler.cpp dbus/TracklistDBusHandler.cpp ) ################################## # DBUS LINKING # ################################## qt5_add_dbus_adaptor(kscd_SRCS org.kde.kscd.cdplayer.xml kscd.h KSCD) qt5_add_dbus_adaptor( kscd_SRCS dbus/org.freedesktop.MediaPlayer.root.xml dbus/RootDBusHandler.h KsCD::RootDBusHandler RootAdaptor RootAdaptor) qt5_add_dbus_adaptor( kscd_SRCS dbus/org.freedesktop.MediaPlayer.player.xml dbus/PlayerDBusHandler.h KsCD::PlayerDBusHandler PlayerAdaptor PlayerAdaptor) qt5_add_dbus_adaptor( kscd_SRCS dbus/org.freedesktop.MediaPlayer.tracklist.xml dbus/TracklistDBusHandler.h KsCD::TracklistDBusHandler TracklistAdaptor TracklistAdaptor) ################################## # Graphics Setting # ################################## file(GLOB resource_svg "gui/skin/*.svg") ki18n_wrap_ui(kscd_SRCS gui/trackListDlgUI.ui generalSettings.ui interfaceSettings.ui) ################################## # KsCD Executable # ################################## kconfig_add_kcfg_files(kscd_SRCS prefs.kcfgc) add_executable(kscd ${kscd_SRCS}) ################################## # Libraries Linking # ################################## target_link_libraries(kscd - Qt5::Widgets Qt5::Svg - KF5::Solid + Qt5::Widgets KF5::ConfigGui + KF5::ConfigWidgets + KF5::CoreAddons + KF5::DBusAddons + KF5::GlobalAccel KF5::I18n + KF5::IconThemes KF5::KDELibs4Support - KF5::GlobalAccel - KF5::DBusAddons + KF5::Service + KF5::Solid + KF5::WidgetsAddons + KF5::XmlGui ${PHONON_LIBRARIES} ${MUSICBRAINZ5_LIBRARIES} ${DISCID_LIBRARIES} ) ########### install files ############### install(TARGETS kscd ${INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES ${resource_svg} DESTINATION ${DATA_INSTALL_DIR}/kscd/skin) install(PROGRAMS org.kde.kscd.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) install(FILES kscd.kcfg DESTINATION ${KCFG_INSTALL_DIR}) install(FILES kscd-play-audiocd.desktop DESTINATION ${DATA_INSTALL_DIR}/solid/actions) install(FILES org.kde.kscd.cdplayer.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR}) add_subdirectory(pics) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/dbus/TracklistDBusHandler.cpp b/dbus/TracklistDBusHandler.cpp index 48b70d0..463d5b9 100644 --- a/dbus/TracklistDBusHandler.cpp +++ b/dbus/TracklistDBusHandler.cpp @@ -1,79 +1,78 @@ /****************************************************************************** * Copyright (C) 2008 Amine Bouchikhi * * * * 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, see . * ******************************************************************************/ #include "TracklistDBusHandler.h" #include "TracklistAdaptor.h" #include "dbus/PlayerDBusHandler.h" -#include #include namespace KsCD { TracklistDBusHandler::TracklistDBusHandler(KSCD *kscd) : QObject() { player = kscd; new TracklistAdaptor( this ); QDBusConnection::sessionBus().registerObject( QLatin1String( "/Player" ), this); setObjectName( QLatin1String("TracklistDBusHandler" )); } int TracklistDBusHandler::AddTrack( const QString& url, bool playImmediately ) { return 0; } void TracklistDBusHandler::DelTrack( int index ) { } int TracklistDBusHandler::GetCurrentTrack() { return 0; } int TracklistDBusHandler::GetLength() { return 0; } QVariantMap TracklistDBusHandler::GetMetadata( int position ) { return QVariantMap(); } void TracklistDBusHandler::SetLoop(bool enable) { } void TracklistDBusHandler::SetRandom( bool enable ) { } void TracklistDBusHandler::slotTrackListChange() { } } diff --git a/gui/volumebutton.cpp b/gui/volumebutton.cpp index dc34912..1edf291 100644 --- a/gui/volumebutton.cpp +++ b/gui/volumebutton.cpp @@ -1,202 +1,202 @@ /* * Kscd - A simple cd player for the KDE Project * * Copyright (c) 1997 Bernd Johannes wuebben@math.cornell.edu * Copyright (c) 2002-2003 Aaron J. Seigo * Copyright (c) 2004 Alexander Kern * Copyright (c) 2003-2006 Richard Lärkäng * * -------------- * ISI KsCD Team : * -------------- * Stanislas KRZYWDA * Sovanramy Var * Bouchikhi Mohamed-Amine * Gastellu Sylvain * ----------------------------------------------------------------------------- * * 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, 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 "volumebutton.h" #include -#include +#include VolumeButton::VolumeButton(QWidget * parent, qreal value):KscdWidget(QLatin1String("volume"),parent) { m_vValue = value; m_angle = valueToAngle(m_vValue); m_centerX = width()/2; m_centerY = height()/2; m_move = false; } VolumeButton::~VolumeButton() { } /* change skin path and refresh */ void VolumeButton::changeSkin(const QString& newPathSkin) { if (m_renderer->elementExists(m_id)) { loadSkin(newPathSkin); emit(changePicture()); emit(needRepaint()); m_centerX = width()/2; m_centerY = height()/2; } } void VolumeButton::mousePressEvent(QMouseEvent *event) { if(m_bounds->contains(event->pos()+(m_bounds->boundingRect()).topLeft())) { event->accept(); m_posX = event->x(); m_posY = event->y(); m_move =true; grabMouse(Qt::ClosedHandCursor); } else { event->ignore(); } } // void VolumeButton::mouseMoveEvent(QMouseEvent *event) { if(m_bounds->contains(event->pos()+(m_bounds->boundingRect()).topLeft()) && m_move == true){ event->accept(); //find the angle //find three triangle side's length qreal b=(qreal)sqrt((m_centerX - m_posX)*(m_centerX - m_posX) + (m_centerY - m_posY)*(m_centerY - m_posY)); qreal a=(qreal)sqrt((event->x() - m_posX)*(event->x() - m_posX) + (event->y()- m_posY)*(event->y()- m_posY)); qreal c=(qreal)sqrt((m_centerX - event->x())*(m_centerX - event->x()) + (m_centerY - event->y())*(m_centerY - event->y())); //find angle in radian between last point, center point and the new point qreal A=(qreal)acos((b*b+c*c-a*a)/(2*b*c)); //sound must be higher if((event->x()>m_centerX && event->y()< m_posY) || (event->x()< m_centerX && event->y()>m_posY) || (event->y()y()==m_posY && event->x()y()>m_centerY && event->y()==m_posY && event->x()>m_posX)){ if((m_angle - (180 * (A))/3.1415)>=0){ rotation(m_angle - (180 * (A))/3.1415); //change m_angle m_vValue=angleToValue(m_angle); //change m_vValue emit(volumeChange(m_vValue)); // change sound volume } //sound must be lower }else if((event->x()<=m_centerX && event->y()< m_posY) || (event->x()>= m_centerX && event->y()>m_posY) || (event->y()y()==m_posY && event->x()>m_posX) || (event->y()>m_centerY && event->y()==m_posY && event->x()x(); m_posY = event->y(); }else{ event->ignore(); } } void VolumeButton::mouseReleaseEvent(QMouseEvent *event) { releaseMouse(); m_move = false; } void VolumeButton::wheelEvent(QWheelEvent *event) { qreal step = valueToAngle((event->delta()/120)*wheelStep); if((m_angle + step)>=0 && (m_angle + step)<=250) { // event->accept(); m_angle += step; m_vValue += (event->delta()/120)*wheelStep; emit(volumeChange(m_vValue)); rotation(m_angle); } else { event->ignore(); } } void VolumeButton::rotation (qreal angle) { m_angle = angle; emit(update()); } qreal VolumeButton::angleToValue(qreal angle) { return angle/wheelStep ; } qreal VolumeButton::valueToAngle(qreal value) { return value*wheelStep ; } void VolumeButton::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.translate((m_renderer->boundsOnElement(m_id).width())/2, (m_renderer->boundsOnElement(m_id).height())/2); painter.rotate(m_angle); painter.translate(-(m_renderer->boundsOnElement(m_id).width())/2, -(m_renderer->boundsOnElement(m_id).height())/2); m_renderer->render(&painter,m_id); } void VolumeButton::enterEvent (QEvent * event ) { event->accept(); setToolTip( i18n( qPrintable( m_name ) ) ); } void VolumeButton::leaveEvent (QEvent * event ) { event->accept(); } void VolumeButton::volumeShortcut(qreal value) { if (m_vValue<=100 && m_vValue>=0) { qreal angle = valueToAngle(value); rotation (m_angle + angle); m_vValue+=value; emit(volumeChange(m_vValue)); } } diff --git a/kscd.cpp b/kscd.cpp index 258a1b3..f25f4de 100644 --- a/kscd.cpp +++ b/kscd.cpp @@ -1,884 +1,885 @@ /* vim: noexpandtab * Kscd - A simple cd player for the KDE Project * * Copyright (c) 1997 Bernd Johannes wuebben@math.cornell.edu * Copyright (c) 2002-2003 Aaron J. Seigo * Copyright (c) 2004 Alexander Kern * Copyright (c) 2003-2006 Richard Lärkäng * Copyright (c) 2008 Amine Bouchikhi * Copyright (c) 2008 Laurent Montel * * 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, 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 "kscd.h" #include "dbus/PlayerDBusHandler.h" #include "dbus/RootDBusHandler.h" #include "dbus/TracklistDBusHandler.h" +#include #include #include #include #include #include #include #include #include #include #include #include "cdplayeradaptor.h" using namespace Phonon; bool stoppedByUser = true; KSCD::KSCD( QWidget *parent ) : KscdWindow(parent) { /** Hourglass */ setHourglass(); new CDPlayerAdaptor( this ); QDBusConnection::sessionBus().registerObject(QLatin1String( "/CDPlayer" ), this); devices = new HWControler(); new KsCD::PlayerDBusHandler(this); new KsCD::RootDBusHandler(this); new KsCD::TracklistDBusHandler(this); sslider = new Phonon::SeekSlider(devices->getMedia(),this); // sslider->setMediaObject(devices->getMedia()); sslider->move(m_bar->x(),m_bar->y()); sslider->setMaximumWidth(m_bar->width()); sslider->setMinimumWidth(m_bar->width()); sslider->show(); loadSettings(); /** Music Brainz initialisation */ m_MBManager = new MBManager(); if (devices->getMedia()) { m_MBManager->discLookup(devices->getMedia()->currentSource().deviceName()); } setupActions(); setupContextMenu(); } KSCD::~KSCD() { delete devices; delete m_MBManager; } void KSCD::setupActions() { m_actions = new KActionCollection(this); m_actions->setConfigGroup(QLatin1String( "Configuration" )); m_configureShortcutsAction = m_actions->addAction(i18n("Configure Shortcuts...")); m_configureShortcutsAction->setText(i18n("Configure Shortcuts...")); addAction(m_configureShortcutsAction); //m_configureShortcutsAction->setShortcut(Qt::Key_C); connect(m_configureShortcutsAction, SIGNAL(triggered()), this, SLOT(configureShortcuts())); m_configureAction = m_actions->addAction(i18n("Configure...")); m_configureAction->setText(i18n("Configure...")); addAction(m_configureAction); connect(m_configureAction, SIGNAL(triggered()), this, SLOT(optionsPreferences())); //download info m_downloadAction = m_actions->addAction(i18n("Download Info")); m_downloadAction->setText(i18n("Download Info")); addAction(m_downloadAction); connect(m_downloadAction, SIGNAL(triggered()), this, SLOT(discLookup())); //upload info m_uploadAction = m_actions->addAction( QLatin1String( "Upload Info" )); m_uploadAction->setText(i18n("Upload Info")); addAction(m_uploadAction); connect(m_uploadAction, SIGNAL(triggered()), this, SLOT(discUpload())); //play/pause m_playPauseAction = m_actions->addAction( QLatin1String( "Play/Pause" )); m_playPauseAction->setText(i18n("Play/Pause")); m_playPauseAction->setShortcut(Qt::Key_Space); connect(m_playPauseAction, SIGNAL(triggered()), this, SLOT(playShortcut())); addAction(m_playPauseAction); //stop m_stopAction = m_actions->addAction( QLatin1String( "Stop" )); m_stopAction->setText(i18n("Stop")); addAction(m_stopAction); m_stopAction->setShortcut(Qt::CTRL + Qt::ALT + Qt::Key_V); connect(m_stopAction, SIGNAL(triggered()), devices, SLOT(stop())); //next m_nextAction = m_actions->addAction( QLatin1String( "next" )); m_nextAction->setText(i18nc( "This action allow user to pass to the following track","Next" )); addAction(m_nextAction); m_nextAction->setShortcut(Qt::Key_Right); connect(m_nextAction, SIGNAL(triggered()), devices, SLOT(nextTrack())); //previous m_previousAction = m_actions->addAction( QLatin1String( "previous" )); m_previousAction->setText(i18nc( "This action allow the user to pass to the preceding track", "Previous" ) ); addAction(m_previousAction); m_previousAction->setShortcut(Qt::Key_Left); connect(m_previousAction, SIGNAL(triggered()), devices, SLOT(prevTrack())); //eject m_ejectAction = m_actions->addAction( QLatin1String( "eject" )); m_ejectAction->setText(i18nc( " This action allow to eject the inserted disc", "Eject")); addAction(m_ejectAction); m_ejectAction->setShortcut(Qt::CTRL + Qt::ALT + Qt::Key_E); connect(m_ejectAction, SIGNAL(triggered()), this, SLOT(ejectShortcut())); //volume up m_volumeUpAction = m_actions->addAction( QLatin1String( "volume_up" )); m_volumeUpAction->setText(i18n("Volume Up")); addAction(m_volumeUpAction); m_volumeUpAction->setShortcut(Qt::Key_Up); connect(m_volumeUpAction, SIGNAL(triggered()), this, SLOT(volumeUpShortcut())); //volume down m_volumeDownAction = m_actions->addAction( QLatin1String( "volume_down" )); m_volumeDownAction->setText(i18n("Volume Down")); addAction(m_volumeDownAction); m_volumeDownAction->setShortcut(Qt::Key_Down); connect(m_volumeDownAction, SIGNAL(triggered()), this, SLOT(volumeDownShortcut())); //random m_randomAction = m_actions->addAction( QLatin1String( "random" )); m_randomAction->setText(i18nc("This action allow the user to listen a random track list","Random")); addAction(m_randomAction); m_randomAction->setShortcut(Qt::CTRL + Qt:: Key_H); connect(m_randomAction, SIGNAL(triggered()), this, SLOT(randomShortcut())); //looptrack m_looptrackAction = m_actions->addAction( QLatin1String( "looptrack" )); m_looptrackAction->setText(i18n("Repeat Track")); addAction(m_looptrackAction); m_looptrackAction->setShortcut(Qt::CTRL + Qt::Key_T); connect(m_looptrackAction, SIGNAL(triggered()), this, SLOT(looptrackShortcut())); //loopdisc m_loopdiscAction = m_actions->addAction( QLatin1String( "loopdisc" )); m_loopdiscAction->setText(i18n("Repeat Album")); addAction(m_loopdiscAction); m_loopdiscAction->setShortcut(Qt::CTRL + Qt::Key_D); connect(m_loopdiscAction, SIGNAL(triggered()), this, SLOT(loopdiscShortcut())); //tracklist m_tracklistAction = m_actions->addAction( QLatin1String( "tracklist" )); m_tracklistAction->setText(i18n("Show Tracklist")); addAction(m_tracklistAction); connect(m_tracklistAction, SIGNAL(triggered()), this, SLOT(tracklistShortcut())); //mute m_muteAction = m_actions->addAction( QLatin1String( "mute" )); m_muteAction->setText(i18n("Mute/Unmute")); addAction(m_muteAction); connect(m_muteAction, SIGNAL(triggered()), this, SLOT(muteShortcut())); //minimize m_minimizeAction = m_actions->addAction( QLatin1String( "Minimize" )); m_minimizeAction->setText(i18n("Minimize")); addAction(m_minimizeAction); connect(m_minimizeAction, SIGNAL(triggered()), this, SLOT(minimizeShortcut())); //quit m_quitAction = KStandardAction::quit(this,SLOT(quitShortcut()),this); setContextMenuPolicy(Qt::CustomContextMenu); //Read saved settings m_actions->readSettings(); mute = false; play = false; random = false; looptrack = false; loopdisc = false; /** * General */ // Connects UI with actions triggering connect(this,SIGNAL(actionClicked(QString)), this, SLOT(actionButton(QString))); connect(this,SIGNAL(picture(QString,QString)), this, SLOT(changePicture(QString,QString))); // General connects connect(this,SIGNAL(trackClicked(int)), this, SLOT(playTrack(int))); connect(this,SIGNAL(actionVolume(qreal)), this, SLOT(changeVolume(qreal))); connect(devices,SIGNAL(currentTime(qint64)),this,SLOT(catchtime(qint64))); connect(this,SIGNAL(infoPanel(QString)),this,SLOT(panelInfo(QString))); // MB connect(m_MBManager, SIGNAL(showArtistLabel(QString&)), this, SLOT(showArtistLabel(QString&))); connect(m_MBManager, SIGNAL(discLookupFinished()), this, SLOT(discLookupFinished())); connect(devices,SIGNAL(trackChanged()),this,SLOT(restoreTrackinfoLabel())); connect(devices,SIGNAL(cdLoaded(QString)),m_MBManager,SLOT(discLookup(QString))); connect( this , SIGNAL(customContextMenuRequested(QPoint)) , SLOT(showContextMenu(QPoint)) ); } void KSCD::discLookup() { m_MBManager->discLookup(devices->getMedia()->currentSource().deviceName()); } void KSCD::discUpload() { m_MBManager->discUpload(devices->getMedia()->currentSource().deviceName()); } void KSCD::discLookupFinished() { // If the track dialog is open, refresh it if(m_stateTrackDialog) { createTrackDialog(m_MBManager->getTrackList(), m_MBManager->getDiscInfo().Title); } } void KSCD::setupContextMenu() { contextMenu = new QMenu( this ); contextMenu->addAction(m_configureShortcutsAction); contextMenu->addAction(m_configureAction); contextMenu->addSeparator(); contextMenu->addAction(m_minimizeAction); contextMenu->addAction(m_quitAction); } void KSCD::showContextMenu( const QPoint &p) { contextMenu->popup( mapToGlobal ( p ) ); } /** * CDDB Management */ void KSCD::restoreArtistLabel() { if( devices->getCD()->isCdInserted() && devices->isDiscValid() ) { QString artist, title; artist = m_MBManager->getDiscInfo().Artist; title = m_MBManager->getDiscInfo().Title; showArtistLabel(artist); showArtistAlbum(title); } else { QString empty; showArtistLabel(empty); } } void KSCD::restoreTrackinfoLabel() { QString title, length ; // If disc is inserted int currentTrack = devices->getCurrentTrack(); if (devices->getCD()->isCdInserted() && currentTrack > 0 ) { title = QString::fromLatin1("%1 - ").arg(currentTrack, 2, 10, QLatin1Char('0')) ; if (m_MBManager->getTrackList().size() >= (currentTrack)) { title.append(m_MBManager->getTrackList()[currentTrack-1].Title); length.append(m_MBManager->getTrackList()[currentTrack-1].Duration); } showTrackinfoLabel(title); m_popup = new TitlePopUp(this, QLatin1String( "popup" )); } else { showTrackinfoLabel(title); } } void KSCD::changeVolume(qreal value) { //qDebug()<<"changeVolume enter "<setVolume(value); } void KSCD::configureShortcuts() { KShortcutsDialog::configure(m_actions, KShortcutsEditor::LetterShortcutsAllowed, this, true); } void KSCD::ejectShortcut() { QString result = QLatin1String( "eject" ); actionButton(result); } void KSCD::quitShortcut() { QString result = QLatin1String( "close" ); actionButton(result); } void KSCD::minimizeShortcut() { QString result = QLatin1String( "minimize" ); actionButton(result); } void KSCD::tracklistShortcut() { QString result = QLatin1String( "tracklist" ); actionButton(result); } void KSCD::muteShortcut() { QString def = QLatin1String( "default" ); if (!mute) { QString result = QLatin1String( "unmute" ); actionButton(result); emit(picture(result,def)); //mute = !mute; } else { QString result = QLatin1String( "mute" ); actionButton(result); emit(picture(result,def)); //mute = !mute; } } void KSCD::playShortcut() { QString def = QLatin1String( "default" ); if (!play) { QString result = QLatin1String( "play" ); actionButton(result); emit(picture(result,def)); //play = !play; } else { QString result = QLatin1String( "pause" ); actionButton(result); emit(picture(result,def)); //play = !play; } } void KSCD::randomShortcut() { QString def = QLatin1String( "default" ); if (!random) { QString result = QLatin1String( "p_random" ); actionButton(result); emit(picture(result,def)); emit(infoPanel(result)); //random = !random; } else { QString result = QLatin1String( "random" ); actionButton(result); emit(picture(result,def)); emit(infoPanel(result)); //random = !random; } } void KSCD::looptrackShortcut() { QString def = QLatin1String( "default" ); if (!looptrack) { QString result = QLatin1String( "looptrack" ); actionButton(result); emit(picture(result,def)); emit(infoPanel(result)); //looptrack = !looptrack; } else { QString result = QLatin1String( "loop" ); actionButton(result); emit(picture(result,def)); emit(infoPanel(result)); //looptrack = !looptrack; } } void KSCD::loopdiscShortcut() { QString def = QLatin1String( "default" ); if (!loopdisc) { QString result = QLatin1String( "loopdisc" ); actionButton(result); emit(picture(result,def)); emit(infoPanel(result)); //loopdisc = !loopdisc; } else { QString result = QLatin1String( "loop" ); actionButton(result); emit(picture(result,def)); emit(infoPanel(result)); //loopdisc = !loopdisc; } } void KSCD::volumeUpShortcut() { if (devices->getVolume()<=0.95) { m_volumeB->volumeShortcut(5.0); } } void KSCD::volumeDownShortcut() { if (devices->getVolume()>=0.05) { m_volumeB->volumeShortcut(-5.0); } } void KSCD::playTrack(int track) { QString result = QLatin1String( "play" ); QString def = QLatin1String( "default" ); qDebug()<<"playtrack enter "<play(track); emit(picture(result,def)); restoreArtistLabel(); } /** * Link IHM with actions */ void KSCD::actionButton(const QString & name) { QString state = QLatin1String( "over" ); QString result; if (name == QLatin1String( "play" )) { if (!devices->getCD()) return; if( !devices->isDiscValid() || !devices->getCD()->isCdInserted()) { QString result; if(!devices->getCD()->isCdInserted()){ result = i18n("No disc"); showArtistLabel(result); } else{ result = i18n("Invalid disc"); showArtistLabel(result); } QTimer::singleShot(2000, this, SLOT(restoreArtistLabel())); } else { if((devices->getState() == StoppedState) || (devices->getState()) == PausedState) { qDebug()<<"time total"<getTotalTime(); devices->play(); // m_slider->stop(); // m_slider->setTotalTime(devices->getTotalTime()); // m_slider->setStep(devices->getTotalTime()); restoreTrackinfoLabel(); restoreArtistLabel(); } } emit(picture(name,state)); play = !play; } else if (name == QLatin1String( "pause" )) { /*if( !devices->isDiscValid() || !devices->getCD()->isCdInserted()) { if(!devices->getCD()->isCdInserted()) showArtistLabel(i18n("No disc")); else showArtistLabel(i18n("Invalid disc")); QTimer::singleShot(2000, this, SLOT(restoreArtistLabel())); } else{*/ if(devices->getState() == PlayingState) { devices->pause(); } /*}*/ emit(picture(name,state)); play = !play; } else if (name == QLatin1String( "next" )) { if( !devices->isDiscValid() || !devices->getCD()->isCdInserted()) { QString result; if(!devices->getCD()->isCdInserted()){ result = i18n("No disc"); showArtistLabel(result); } else{ result = i18n("Invalid disc"); showArtistLabel(result); } QTimer::singleShot(2000, this, SLOT(restoreArtistLabel())); } else { devices->nextTrack(); restoreTrackinfoLabel(); if((devices->getState() == StoppedState) || (devices->getState() == PausedState)) { devices->stop(false); // m_slider->stop(); } if ((devices->getState() == PlayingState)) { // m_slider->stop(); // m_slider->start(devices->getTotalTime()); devices->play(); } } emit(picture(name,state)); } else if(name == QLatin1String( "previous" )) { if( !devices->isDiscValid() || !devices->getCD()->isCdInserted()) { QString result; if(!devices->getCD()->isCdInserted()){ result = i18n("No disc"); showArtistLabel(result); } else{ result = i18n("Invalid disc"); showArtistLabel(result); } QTimer::singleShot(2000, this, SLOT(restoreArtistLabel())); } else { devices->prevTrack(); restoreTrackinfoLabel(); if((devices->getState() == StoppedState) || (devices->getState() == PausedState)) { devices->stop(false); // m_slider->stop(); } if ((devices->getState() == PlayingState)) { // m_slider->stop(); devices->play(); // m_slider->start(devices->getTotalTime()); } } emit(picture(name,state)); } else if(name == QLatin1String( "stop" )) { if ((devices->getState() == PlayingState)|| (devices->getState() == PausedState)) { devices->stop(); // m_slider->stop(); } emit(picture(name,state)); } else if (name == QLatin1String( "eject" )) { m_trackDlg->removeRowsTrackTable(); devices->eject(); emit(picture(name,state)); if ((devices->getState() == PlayingState)|| (devices->getState() == PausedState)) { devices->stop(); // m_slider->stop(); } } else if (name == QLatin1String( "mute" )) { devices->mute(false); emit(picture(name,state)); mute = !mute; } else if (name == QLatin1String( "unmute" )) { devices->mute(true); emit(picture(name,state)); mute = !mute; } else if (name == QLatin1String( "random" )) { devices->setRandom(false); emit(picture(name,state)); result = QLatin1String( "random" ); emit(infoPanel(result)); random = !random; } else if (name == QLatin1String( "p_random" )) { devices->setRandom(true); emit(picture(name,state)); result = QLatin1String( "p_random" ); emit(infoPanel(result)); random = !random; } else if (name == QLatin1String( "loop" )) { devices->setLoopMode(NoLoop); emit(picture(name,state)); result = QLatin1String( "loop" ); emit(infoPanel(result)); looptrack = false; loopdisc = false; } else if (name == QLatin1String( "looptrack" )) { devices->setLoopMode(LoopOne); emit(picture(name,state)); result = QLatin1String( "looptrack" ); emit(infoPanel(result)); looptrack = true; loopdisc = false; } else if (name == QLatin1String( "loopdisc" )) { devices->setLoopMode(LoopAll); emit(picture(name,state)); emit(infoPanel(name)); loopdisc = true; looptrack = false; } else if (name == QLatin1String( "minimize" )) { showMinimized (); emit(picture(name,state)); } else if (name == QLatin1String( "close" )) { close(); emit(picture(name,state)); } else if (name == QLatin1String( "tracklist" )) { if(m_stateTrackDialog == true) { qDebug()<<"close track window"; closeTrackDialog(); } else { //createTrackDialog(m_cddbManager->getTrackList(),m_cddbManager->getDiscTitle()); QList list = m_MBManager->getTrackList(); QString title(m_MBManager->getDiscInfo().Title); createTrackDialog(list,title); qDebug()<<"open track window"; } QString def = QLatin1String( "default" ); emit(picture(name,def)); } else if (name == QLatin1String( "configure" )) { optionsPreferences(); } } /** * Hourglass */ void KSCD::setHourglass() { this->setCursor(Qt::WaitCursor); QTimer::singleShot(8000, this, SLOT(unsetHourglass())); } void KSCD::unsetHourglass() { this->unsetCursor(); } /** * Configuration */ void KSCD::writeSettings() { // Prefs::self()->writeConfig(); } void KSCD::configureKeys() { KShortcutsDialog::configure(m_actions, KShortcutsEditor::LetterShortcutsAllowed, this, true); } /** * Accessors */ HWControler* KSCD::getDevices() const { return devices; } /** * Save state on session termination */ bool KSCD::saveState(QSessionManager& /*sm*/) { writeSettings(); - KConfigGroup config(KApplication::kApplication()->sessionConfig(), i18nc("General option in the configuration dialog","General")); + KConfigGroup config(KConfigGui::sessionConfig(), i18nc("General option in the configuration dialog","General")); //config.writeEntry(i18n("Show"), isVisible()); return true; } void KSCD::optionsPreferences() { if ( KConfigDialog::showDialog( i18n("Settings") ) ) { return; } //KConfigDialog didn't find an instance of this dialog, so lets create it : KConfigDialog* dialog = new KConfigDialog( this, i18n("Settings"), Prefs::self() ); // Add the General Settings page QWidget *generalSettingsDlg = new QWidget; ui_general.setupUi(generalSettingsDlg); dialog->addPage(generalSettingsDlg, i18nc("General option in the configuration dialog","General"), QLatin1String( "kscd" )); QWidget *interfaceSettingsDlg = new QWidget; ui_interface.setupUi(interfaceSettingsDlg); //Filter on the skin url combo box QString pathSkins=QStandardPaths::standardLocations(QStandardPaths::DataLocation).last() + QLatin1String( "/kscd/skin/" ); QDir directory(pathSkins); QStringList filter; filter << QLatin1String( "*.svg" ); directory.setNameFilters(filter); QStringList list = directory.entryList(); ui_interface.kcfg_url->addItems(list); dialog->addPage(interfaceSettingsDlg, i18n("Appearance"), QLatin1String( "fill-color" )); connect(dialog, SIGNAL(settingsChanged(QString)), this, SLOT(updateSettings())); dialog->setAttribute( Qt::WA_DeleteOnClose ); //dialog->setHelp(QString(),QLatin1String( "kscd" )); dialog->show(); } void KSCD::updateSettings() { m_panel->setTextColor(Prefs::textColor()); //qDebug()<<"color config:"<setTextSizeFont(Prefs::textFont()); //qDebug()<<"font config:"<setEjectActivated(Prefs::ejectOnFinish()); //qDebug()<<"eject setting:"<setEjectAct( Prefs::ejectOnFinish() ); QString skin; if(Prefs::url().startsWith(QLatin1Char( '/' ))) skin = Prefs::url(); else skin = QStandardPaths::standardLocations(QStandardPaths::DataLocation).last() + QLatin1String( "kscd/skin/" ) + Prefs::url(); setNewSkin( skin ); } void KSCD::loadSettings() { //setNewSkin( QStandardPaths::standardLocations(QStandardPaths::DataLocation).last() + "kscd/skin/" + Prefs::url() ); m_panel->setTextColor(Prefs::textColor()); m_panel->setTextSizeFont(Prefs::textFont()); m_panel->setEjectAct(Prefs::ejectOnFinish()); devices->setEjectActivated(Prefs::ejectOnFinish()); } void KSCD::catchtime(qint64 pos){ setTime(pos); } /** * main() */ int main( int argc, char *argv[] ) { QApplication a(argc, argv); KLocalizedString::setApplicationDomain("kscd"); KAboutData aboutData("kscd", i18n("KsCD"), "2.0", i18n("KDE CD player"), KAboutLicense::GPL, i18n("(c) 2001, Dirk Försterling\n(c) 2003, Aaron J. Seigo"), QString(), i18n("http://www.kde.org")); aboutData.addCredit(i18n("Amine Bouchikhi"), i18n("Current maintainer, Solid/Phonon Upgrade, QDBus connection"),"bouchikhi.amine@gmail.com"); aboutData.addAuthor(i18n("Aaron J. Seigo"), i18n("Previous maintainer"), "aseigo@kde.org"); aboutData.addAuthor(i18n("Alexander Kern"),i18n("Workman library update, CDTEXT, CDDA"), "kernalex@kde.org"); aboutData.addAuthor(i18n("Bernd Johannes Wuebben"), QString(), "wuebben@kde.org"); aboutData.addAuthor(i18n("Dirk Försterling"), i18n("Workman library, previous maintainer"), "milliByte@gmx.net"); aboutData.addCredit(i18n("Wilfried Huss"), i18n("Patches galore")); aboutData.addCredit(i18n("Steven Grimm"), i18n("Workman library")); aboutData.addCredit(i18n("Sven Lueppken"), i18n("UI Work")); aboutData.addCredit(i18n("freedb.org"), i18n("Special thanks to freedb.org for providing a free CDDB-like CD database"), 0, "http://freedb.org"); QCommandLineParser* parser = new QCommandLineParser; parser->addHelpOption(); parser->addVersionOption(); parser->addOption(QCommandLineOption("s", QString())); parser->addOption(QCommandLineOption("start", i18n("Start playing"))); aboutData.setupCommandLine(parser); KDBusService service(KDBusService::Unique); KSCD *k = new KSCD(); k->setWindowTitle("KSCD"); k->show(); return a.exec(); } diff --git a/kscd.h b/kscd.h index 0bf1741..f48387d 100644 --- a/kscd.h +++ b/kscd.h @@ -1,180 +1,175 @@ /* Kscd - A simple cd player for the KDE Project $Id: kscd.h 818722 2008-06-09 12:01:16Z krzywda $ Copyright (c) 1997 Bernd Johannes Wuebben Copyright (c) 2002 Aaron J. Seigo Copyright (c) 2004 Alexander Kern Copyright (c) 2008 Amine Bouchikhi 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, 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. */ #ifndef KSCD_H #define KSCD_H -// Solid implementation -#include -#include -#include -#include -#include +#include #include -#include +#include #include +#include +#include #include +#include +#include + // Phonon libs #include #include #include "gui/kscdwindow.h" #include "hwcontroler.h" #include "mbmanager.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "panel.h" #include "prefs.h" #include "ui_generalSettings.h" #include "ui_interfaceSettings.h" -#include - class KSCD : public KscdWindow, public KSessionManager { Q_OBJECT public: explicit KSCD(QWidget *parent = 0); ~KSCD(); virtual bool saveState(QSessionManager& sm); void writeSettings(); HWControler * getDevices() const; protected: void setupActions(); void setupContextMenu(); signals: void picture(const QString&,const QString&); void infoPanel(const QString&); public slots: void showContextMenu( const QPoint & ); void restoreArtistLabel(); void restoreTrackinfoLabel(); void changeVolume(qreal); void playTrack(int); void ejectShortcut(); void tracklistShortcut(); void muteShortcut(); void playShortcut(); void randomShortcut(); void looptrackShortcut(); void loopdiscShortcut(); void volumeUpShortcut(); void volumeDownShortcut(); void quitShortcut(); void minimizeShortcut(); void actionButton(const QString&); void catchtime(qint64 pos); //void setNewSkin(QString); void unsetHourglass(); void configureShortcuts(); /** * Open the config window */ void optionsPreferences(); void updateSettings(); void configureKeys(); void discLookup(); void discUpload(); void discLookupFinished(); private: HWControler* devices; MBManager* m_MBManager; bool mute; bool play; bool random; bool looptrack; bool loopdisc; QMenu *contextMenu; QAction* m_configureShortcutsAction; QAction* m_configureAction; QAction* m_playPauseAction; QAction* m_stopAction; QAction* m_nextAction; QAction* m_previousAction; QAction* m_ejectAction; QAction* m_randomAction; QAction* m_looptrackAction; QAction* m_loopdiscAction; QAction* m_tracklistAction; QAction* m_muteAction; QAction* m_downloadAction; QAction* m_uploadAction; QAction* m_CDDBWindowAction; QAction* m_volumeUpAction; QAction* m_volumeDownAction; QAction* m_quitAction; QAction* m_minimizeAction; KActionCollection * m_actions; void setHourglass(); // Settings. Ui::generalSettings ui_general; Ui::interfaceSettings ui_interface; /** * Load the last settings */ void loadSettings(); }; #endif diff --git a/mbmanager.cpp b/mbmanager.cpp index 8a085df..63ffd26 100644 --- a/mbmanager.cpp +++ b/mbmanager.cpp @@ -1,333 +1,332 @@ /* * Kscd - A simple cd player for the KDE Project * * Copyright (c) 1997 Bernd Johannes wuebben@math.cornell.edu * Copyright (c) 2002-2003 Aaron J. Seigo * Copyright (c) 2004 Alexander Kern * Copyright (c) 2003-2006 Richard Lärkäng * * -------------- * ISI KsCD Team : * -------------- * Stanislas KRZYWDA * Sovanramy Var * Bouchikhi Mohamed-Amine * Gastellu Sylvain * ----------------------------------------------------------------------------- * * 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, 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 "mbmanager.h" #include -#include -#include +#include #include #include #include #include #include #include #include #include #include #include #include MBManager::MBManager():m_validInfo(true) { m_discid = discid_new(); } MBManager::~MBManager() { discid_free(m_discid); } static QString getTitle(MusicBrainz5::CRelease *release, MusicBrainz5::CMedium *medium) { QString title; if (!release) { return title; } title = QString::fromUtf8(release->Title().c_str()); if (medium && release->MediumList()->NumItems() > 1) { title = i18n("%1 (disc %2)", title, medium->Position()); } return title; } static QString getArtistFromArtistCredit(MusicBrainz5::CArtistCredit *artistCredit) { QString artist; MusicBrainz5::CNameCreditList *artistList = artistCredit->NameCreditList(); if (!artistList) { return artist; } for (int i = 0; i < artistList->NumItems(); i++) { MusicBrainz5::CNameCredit* name = artistList->Item(i); MusicBrainz5::CArtist* itemArtist = name->Artist(); if (!name->Name().empty()) { artist += QString::fromUtf8(name->Name().c_str()); } else { artist += QString::fromUtf8(itemArtist->Name().c_str()); } artist += QString::fromUtf8(name->JoinPhrase().c_str()); } return artist; } static QString getArtist(MusicBrainz5::CRelease *release) { QString artist; if (!release) { return artist; } MusicBrainz5::CArtistCredit *artistCredit = release->ArtistCredit(); return getArtistFromArtistCredit(artistCredit); } static QList unknownTracks(QString &discArtist, DiscId *m_discid) { QList tracks; MBTrackInfo track; for (int j = 1; j < discid_get_first_track_num(m_discid); j++) { track.Title = i18n("Unknown title"); track.Artist = discArtist; // Not an audio track track.Duration = 0; tracks << track; } for (int j = discid_get_first_track_num(m_discid); j <= discid_get_last_track_num(m_discid); j++) { track.Title = i18n("Unknown title"); track.Artist = discArtist; // time from mb library in sectors, 75 sectors = 1 second track.Duration = discid_get_track_length(m_discid, j) * 1000 / 75; tracks << track; } return tracks; } static QList getTracks(MusicBrainz5::CMedium *medium, QString &discArtist, DiscId *m_discid) { QList tracks; if (!medium) { return tracks; } MusicBrainz5::CTrackList *trackList = medium->TrackList(); if (!trackList) { return unknownTracks(discArtist, m_discid); } MBTrackInfo track; for (int i = 0; i < trackList->NumItems(); i++) { MusicBrainz5::CTrack *itemTrack = trackList->Item(i); MusicBrainz5::CRecording *recording = itemTrack->Recording(); if (recording && !itemTrack->ArtistCredit()) { track.Artist = getArtistFromArtistCredit(recording->ArtistCredit()); } else { track.Artist = getArtistFromArtistCredit(itemTrack->ArtistCredit()); } if(recording && itemTrack->Title().empty()) { track.Title = QString::fromUtf8(recording->Title().c_str()); } else { track.Title = QString::fromUtf8(itemTrack->Title().c_str()); } track.Duration = itemTrack->Length(); tracks << track; } return tracks; } static MusicBrainz5::CRelease *getRelease(MusicBrainz5::CQuery &query, std::string &discId, MusicBrainz5::CMetadata &metadata, MusicBrainz5::CMetadata &fullMetadata) { metadata = query.Query("discid", discId); // Check to see how many items were returned from the server if (!metadata.Disc() || !metadata.Disc()->ReleaseList()) { return 0; } MusicBrainz5::CReleaseList *results = metadata.Disc()->ReleaseList(); // TODO if multiple entries found if (results->NumItems() > 1) { qDebug() << results->NumItems() << " entries found"; } MusicBrainz5::CRelease *release; for (int i = 0; i < results->NumItems(); i++) { MusicBrainz5::CRelease *result = results->Item(i); MusicBrainz5::CQuery::tParamMap params; params["inc"] = "artists labels recordings release-groups url-rels " "discids artist-credits"; fullMetadata = query.Query("release", result->ID(), "", params); release = fullMetadata.Release(); if (release) { break; } } return release; } static MusicBrainz5::CMedium *getMedium(MusicBrainz5::CRelease *release, std::string &discId, MusicBrainz5::CMediumList &mediaList) { if (!release) { return 0; } // Find the specific media in the release mediaList = release->MediaMatchingDiscID(discId); MusicBrainz5::CMedium* medium = 0; for (int i = 0; i < mediaList.NumItems(); i++) { medium = mediaList.Item(i); if (medium) { break; } } return medium; } void MBManager::discLookup(const QString &device) { m_validInfo = true; MusicBrainz5::CQuery query("kscd"); int discid_ok = discid_read_sparse(m_discid, qPrintable(device), 0); if (discid_ok) { std::string discId(discid_get_id(m_discid)); try { MusicBrainz5::CMetadata metadata, fullMetadata; MusicBrainz5::CMediumList mediaList; MusicBrainz5::CRelease *release = getRelease(query, discId, metadata, fullMetadata); MusicBrainz5::CMedium *medium = getMedium(release, discId, mediaList); if (release && medium) { // Sets info m_discInfo.Title = getTitle(release, medium); m_discInfo.Artist = getArtist(release); m_trackList = getTracks(medium, m_discInfo.Artist, m_discid); } else { qDebug() << "This CD was not found."; m_validInfo = false; } } catch (MusicBrainz5::CExceptionBase& error) { qDebug() << "Connection Exception: '" << error.what() << "'"; qDebug() << "LastResult: " << query.LastResult(); qDebug() << "LastHTTPCode: " << query.LastHTTPCode(); qDebug() << "LastErrorMessage: " << QString::fromUtf8(query.LastErrorMessage().c_str()); m_validInfo = false; } catch (...) { qDebug() << "Caught Unknown Exception:"; m_validInfo = false; } } else { m_validInfo = false; } if (!m_validInfo) { // If invalid data, fill the information with something // Sets info m_discInfo.Title = i18n("Unknown album"); m_discInfo.Artist = i18n("Unknown artist"); m_trackList.clear(); if (discid_ok) { m_trackList = unknownTracks(m_discInfo.Artist, m_discid); } } emit discLookupFinished(); } void MBManager::discUpload(const QString &device) { showArtistLabel(m_discInfo.Artist); const char *discid_device = device.isEmpty()? NULL : qPrintable(device); int ok = discid_read_sparse(m_discid, discid_device, 0); if (ok) { QString url = QString::fromUtf8(discid_get_submission_url(m_discid)); KToolInvocation::invokeBrowser(url); } else { qDebug() << "Error: " << discid_get_error_msg(m_discid); } }