diff options
author | Weblate <noreply@weblate.org> | 2016-12-14 21:54:31 +0000 |
---|---|---|
committer | Weblate <noreply@weblate.org> | 2016-12-14 21:54:31 +0000 |
commit | b965af1625a4296f8ff6d3a1663cae23b73d334f (patch) | |
tree | 459685dd1da8c75f67772762aa062d80dfc148f0 /src-qt5/core/lumina-desktop/panel-plugins/audioplayer | |
parent | Translated using Weblate (lumina_DESKTOP@fr (generated)) (diff) | |
parent | Merge branch 'master' of github.com:trueos/lumina (diff) | |
download | lumina-b965af1625a4296f8ff6d3a1663cae23b73d334f.tar.gz lumina-b965af1625a4296f8ff6d3a1663cae23b73d334f.tar.bz2 lumina-b965af1625a4296f8ff6d3a1663cae23b73d334f.zip |
Merge branch 'master' of github.com:trueos/lumina
Diffstat (limited to 'src-qt5/core/lumina-desktop/panel-plugins/audioplayer')
5 files changed, 578 insertions, 0 deletions
diff --git a/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/LPAudioPlayer.cpp b/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/LPAudioPlayer.cpp new file mode 100644 index 00000000..5669aaf5 --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/LPAudioPlayer.cpp @@ -0,0 +1,30 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2014, Susanne Jaeckel +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "LPAudioPlayer.h" +#include "LSession.h" + +LPAudioPlayer::LPAudioPlayer(QWidget *parent, QString id, bool horizontal) : LPPlugin(parent, id, horizontal){ + //Setup the button + button = new QToolButton(this); + button->setAutoRaise(true); + button->setToolButtonStyle(Qt::ToolButtonIconOnly); + button->setPopupMode(QToolButton::InstantPopup); //make sure it runs the update routine first + //connect(button, SIGNAL(clicked()), this, SLOT(openMenu())); + this->layout()->setContentsMargins(0,0,0,0); + this->layout()->addWidget(button); + wact = new QWidgetAction(this); + aplayer = new PPlayerWidget(this); + button ->setMenu(new QMenu(this) ); + wact->setDefaultWidget(aplayer); + button->menu()->addAction(wact); + //Now start up the widgets + button->setIcon( LXDG::findIcon("audio-volume-high","") ); + QTimer::singleShot(0,this,SLOT(OrientationChange()) ); //update the sizing/icon +} + +LPAudioPlayer::~LPAudioPlayer(){ +} diff --git a/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/LPAudioPlayer.h b/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/LPAudioPlayer.h new file mode 100644 index 00000000..e5132b1f --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/LPAudioPlayer.h @@ -0,0 +1,49 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_PANEL_AUDIO_PLAYER_PLUGIN_H +#define _LUMINA_PANEL_AUDIO_PLAYER_PLUGIN_H + +#include "../../Globals.h" +#include "../LTBWidget.h" +#include "../LPPlugin.h" +#include "PPlayerWidget.h" + +class LPAudioPlayer : public LPPlugin{ + Q_OBJECT +public: + LPAudioPlayer(QWidget *parent = 0, QString id = "audioplayer", bool horizontal=true); + ~LPAudioPlayer(); + +private: + QToolButton *button; + QWidgetAction *wact; + PPlayerWidget *aplayer; + + //int iconOld; + +private slots: + //void updateBattery(bool force = false); + //QString getRemainingTime(); + +public slots: + void LocaleChange(){ + //updateBattery(true); + } + + void OrientationChange(){ + if(this->layout()->direction()==QBoxLayout::LeftToRight){ + this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); + button->setIconSize( QSize(this->height(), this->height()) ); + }else{ + this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); + button->setIconSize( QSize(this->width(), this->width()) ); + } + this->layout()->update(); + } +}; + +#endif diff --git a/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/PPlayerWidget.cpp b/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/PPlayerWidget.cpp new file mode 100644 index 00000000..023e20c7 --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/PPlayerWidget.cpp @@ -0,0 +1,258 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "PPlayerWidget.h" +#include "ui_PPlayerWidget.h" + +#include <QDir> +#include <QUrl> +#include <QInputDialog> +#include <QFileDialog> +#include <LuminaXDG.h> +#include <QDebug> +#include <QDesktopWidget> + +PPlayerWidget::PPlayerWidget(QWidget *parent) : QWidget(parent), ui(new Ui::PPlayerWidget()){ + ui->setupUi(this); //load the designer form + PLAYER = new QMediaPlayer(this); + PLAYER->setVolume(100); + PLAYER->setNotifyInterval(1000); //1 second interval (just needs to be a rough estimate) + PLAYLIST = new QMediaPlaylist(this); + PLAYLIST->setPlaybackMode(QMediaPlaylist::Sequential); + PLAYER->setPlaylist(PLAYLIST); + + configMenu = new QMenu(this); + ui->tool_config->setMenu(configMenu); + addMenu = new QMenu(this); + ui->tool_add->setMenu(addMenu); + + updatinglists = false; //start off as false + + ui->combo_playlist->setContextMenuPolicy(Qt::NoContextMenu); + + LoadIcons(); + playerStateChanged(); //update button visibility + currentSongChanged(); + //Connect all the signals/slots + //connect(infoTimer, SIGNAL(timeout()), this, SLOT(rotateTrackInfo()) ); + connect(PLAYER, SIGNAL(positionChanged(qint64)),this, SLOT(updateProgress(qint64)) ); + connect(PLAYER, SIGNAL(durationChanged(qint64)), this, SLOT(updateMaxProgress(qint64)) ); + connect(PLAYLIST, SIGNAL(mediaChanged(int, int)), this, SLOT(playlistChanged()) ); + connect(PLAYER, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(playerStateChanged()) ); + connect(PLAYLIST, SIGNAL(currentMediaChanged(const QMediaContent&)), this, SLOT(currentSongChanged()) ); + connect(ui->combo_playlist, SIGNAL(currentIndexChanged(int)), this, SLOT(userlistSelectionChanged()) ); + connect(ui->tool_play, SIGNAL(clicked()), this, SLOT(playClicked()) ); + connect(ui->tool_pause, SIGNAL(clicked()), this, SLOT(pauseClicked()) ); + connect(ui->tool_stop, SIGNAL(clicked()), this, SLOT(stopClicked()) ); + connect(ui->tool_next, SIGNAL(clicked()), this, SLOT(nextClicked()) ); + connect(ui->tool_prev, SIGNAL(clicked()), this, SLOT(prevClicked()) ); + +} + +PPlayerWidget::~PPlayerWidget(){ + //qDebug() << "Removing PPlayerWidget"; +} + +void PPlayerWidget::LoadIcons(){ + ui->tool_stop->setIcon( LXDG::findIcon("media-playback-stop","") ); + ui->tool_play->setIcon( LXDG::findIcon("media-playback-start","") ); + ui->tool_pause->setIcon( LXDG::findIcon("media-playback-pause","") ); + ui->tool_next->setIcon( LXDG::findIcon("media-skip-forward","") ); + ui->tool_prev->setIcon( LXDG::findIcon("media-skip-backward","") ); + ui->tool_add->setIcon( LXDG::findIcon("list-add","") ); + ui->tool_config->setIcon( LXDG::findIcon("configure","") ); + //Now re-assemble the menus as well + configMenu->clear(); + configMenu->addAction(LXDG::findIcon("media-eject",""), tr("Clear Playlist"), this, SLOT(ClearPlaylist())); + configMenu->addAction(LXDG::findIcon("roll",""), tr("Shuffle Playlist"), this, SLOT(ShufflePlaylist())); + addMenu->clear(); + addMenu->addAction(LXDG::findIcon("document-new",""), tr("Add Files"), this, SLOT(AddFilesToPlaylist())); + addMenu->addAction(LXDG::findIcon("folder-new",""), tr("Add Directory"), this, SLOT(AddDirToPlaylist())); + addMenu->addAction(LXDG::findIcon("download",""), tr("Add URL"), this, SLOT(AddURLToPlaylist())); +} + +void PPlayerWidget::playClicked(){ + PLAYER->play(); +} + +void PPlayerWidget::pauseClicked(){ + PLAYER->pause(); +} + +void PPlayerWidget::stopClicked(){ + PLAYER->stop(); +} + +void PPlayerWidget::nextClicked(){ + PLAYLIST->next(); +} + +void PPlayerWidget::prevClicked(){ + PLAYLIST->previous(); +} + +void PPlayerWidget::AddFilesToPlaylist(){ + //Prompt the user to select multimedia files + QFileDialog dlg(0, Qt::Dialog | Qt::WindowStaysOnTopHint ); + dlg.setFileMode(QFileDialog::ExistingFiles); + dlg.setAcceptMode(QFileDialog::AcceptOpen); + dlg.setNameFilter( tr("Multimedia Files")+" ("+LXDG::findAVFileExtensions().join(" ")+")"); + dlg.setWindowTitle(tr("Select Multimedia Files")); + dlg.setWindowIcon( LXDG::findIcon("file-open","") ); + dlg.setDirectory(QDir::homePath()); //start in the home directory + //ensure it is centered on the current screen + QPoint center = QApplication::desktop()->screenGeometry(this).center(); + dlg.move( center.x()-(dlg.width()/2), center.y()-(dlg.height()/2) ); + dlg.show(); + while( dlg.isVisible() ){ + QApplication::processEvents(); + } + QList<QUrl> files = dlg.selectedUrls(); + if(files.isEmpty() || dlg.result()!=QDialog::Accepted){ return; } //cancelled + //Make this use show/processEvents later + //QList<QUrl> files = QFileDialog::getOpenFileUrls(0, tr("Select Multimedia Files"), QDir::homePath(), "Multimedia Files ("+LXDG::findAVFileExtensions().join(" ")+")"); + QList<QMediaContent> urls; + for(int i=0; i<files.length(); i++){ + urls << QMediaContent(files[i]); + } + PLAYLIST->addMedia(urls); + playlistChanged(); +} + +void PPlayerWidget::AddDirToPlaylist(){ + QFileDialog dlg(0, Qt::Dialog | Qt::WindowStaysOnTopHint ); + dlg.setFileMode(QFileDialog::Directory); + dlg.setOption(QFileDialog::ShowDirsOnly, true); + dlg.setAcceptMode(QFileDialog::AcceptOpen); + dlg.setWindowTitle(tr("Select Multimedia Directory")); + dlg.setWindowIcon( LXDG::findIcon("folder-open","") ); + dlg.setDirectory(QDir::homePath()); //start in the home directory + //ensure it is centered on the current screen + QPoint center = QApplication::desktop()->screenGeometry(this).center(); + dlg.move( center.x()-(dlg.width()/2), center.y()-(dlg.height()/2) ); + dlg.show(); + while( dlg.isVisible() ){ + QApplication::processEvents(); + } + if(dlg.result() != QDialog::Accepted){ return; } //cancelled + QStringList sel = dlg.selectedFiles(); + if(sel.isEmpty()){ return; } //cancelled + QString dirpath = sel.first(); //QFileDialog::getExistingDirectory(0, tr("Select a Multimedia Directory"), QDir::homePath() ); + if(dirpath.isEmpty()){ return; } //cancelled + QDir dir(dirpath); + QFileInfoList files = dir.entryInfoList(LXDG::findAVFileExtensions(), QDir::Files | QDir::NoDotAndDotDot, QDir::Name); + if(files.isEmpty()){ return; } //nothing in this directory + QList<QMediaContent> urls; + for(int i=0; i<files.length(); i++){ + urls << QMediaContent(QUrl::fromLocalFile(files[i].absoluteFilePath()) ); + } + PLAYLIST->addMedia(urls); + playlistChanged(); +} + +void PPlayerWidget::AddURLToPlaylist(){ + QInputDialog dlg(0, Qt::Dialog | Qt::WindowStaysOnTopHint ); + dlg.setInputMode(QInputDialog::TextInput); + dlg.setLabelText(tr("Enter a valid URL for a multimedia file or stream:")); + dlg.setTextEchoMode(QLineEdit::Normal); + dlg.setWindowTitle(tr("Multimedia URL")); + dlg.setWindowIcon( LXDG::findIcon("download","") ); + //ensure it is centered on the current screen + QPoint center = QApplication::desktop()->screenGeometry(this).center(); + dlg.move( center.x()-(dlg.width()/2), center.y()-(dlg.height()/2) ); + dlg.show(); + while( dlg.isVisible() ){ + QApplication::processEvents(); + } + QString url = dlg.textValue(); + if(url.isEmpty() || dlg.result()!=QDialog::Accepted){ return; } //cancelled + + //QString url = QInputDialog::getText(0, tr("Multimedia URL"), tr("Enter a valid URL for a multimedia file or stream"), QLineEdit::Normal); + //if(url.isEmpty()){ return; } + QUrl newurl(url); + if(!newurl.isValid()){ return; } //invalid URL + PLAYLIST->addMedia(newurl); + playlistChanged(); +} + +void PPlayerWidget::ClearPlaylist(){ + PLAYER->stop(); + PLAYLIST->clear(); + playlistChanged(); +} + +void PPlayerWidget::ShufflePlaylist(){ + PLAYLIST->shuffle(); +} + + +void PPlayerWidget::userlistSelectionChanged(){ //front-end combobox was changed by the user + if(updatinglists){ return; } + PLAYLIST->setCurrentIndex( ui->combo_playlist->currentIndex() ); +} + +void PPlayerWidget::playerStateChanged(){ + switch( PLAYER->state() ){ + case QMediaPlayer::StoppedState: + ui->tool_stop->setVisible(false); + ui->tool_play->setVisible(true); + ui->tool_pause->setVisible(false); + ui->progressBar->setVisible(false); + break; + case QMediaPlayer::PausedState: + ui->tool_stop->setVisible(true); + ui->tool_play->setVisible(true); + ui->tool_pause->setVisible(false); + ui->progressBar->setVisible(true); + break; + case QMediaPlayer::PlayingState: + ui->tool_stop->setVisible(true); + ui->tool_play->setVisible(false); + ui->tool_pause->setVisible(true); + ui->progressBar->setVisible(true); + break; + } + +} + +void PPlayerWidget::playlistChanged(){ + updatinglists = true; + ui->combo_playlist->clear(); + for(int i=0; i<PLAYLIST->mediaCount(); i++){ + QUrl url = PLAYLIST->media(i).canonicalUrl(); + if(url.isLocalFile()){ + ui->combo_playlist->addItem(LXDG::findMimeIcon(url.fileName().section(".",-1)), url.fileName() ); + }else{ + ui->combo_playlist->addItem(LXDG::findIcon("download",""), url.toString() ); + } + } + if(PLAYLIST->currentIndex()<0 && PLAYLIST->mediaCount()>0){ PLAYLIST->setCurrentIndex(0); } + ui->combo_playlist->setCurrentIndex(PLAYLIST->currentIndex()); + + updatinglists = false; +} + +void PPlayerWidget::currentSongChanged(){ + if(PLAYLIST->currentIndex() != ui->combo_playlist->currentIndex()){ + updatinglists = true; + ui->combo_playlist->setCurrentIndex(PLAYLIST->currentIndex()); + updatinglists = false; + } + ui->tool_next->setEnabled( PLAYLIST->nextIndex() >= 0 ); + ui->tool_prev->setEnabled( PLAYLIST->previousIndex() >= 0); + ui->label_num->setText( QString::number( PLAYLIST->currentIndex()+1)+"/"+QString::number(PLAYLIST->mediaCount()) ); + ui->progressBar->setRange(0, PLAYER->duration() ); + ui->progressBar->setValue(0); +} + +void PPlayerWidget::updateProgress(qint64 val){ + //qDebug() << "Update Progress Bar:" << val; + ui->progressBar->setValue(val); +} + +void PPlayerWidget::updateMaxProgress(qint64 val){ + ui->progressBar->setRange(0,val); +} diff --git a/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/PPlayerWidget.h b/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/PPlayerWidget.h new file mode 100644 index 00000000..a551d74f --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/PPlayerWidget.h @@ -0,0 +1,59 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +// This plugin is a simple audio player on the desktop +//=========================================== +#ifndef _LUMINA_PANEL_PLUGIN_AUDIO_PLAYER_WIDGET_H +#define _LUMINA_PANEL_PLUGIN_AUDIO_PLAYER_WIDGET_H + +#include <QMediaPlaylist> +#include <QMediaPlayer> +#include <QTimer> +#include <QWidget> +#include <QMenu> + + +namespace Ui{ + class PPlayerWidget; +}; + +class PPlayerWidget : public QWidget{ + Q_OBJECT +public: + PPlayerWidget(QWidget *parent = 0); + ~PPlayerWidget(); + +public slots: + void LoadIcons(); + +private: + Ui::PPlayerWidget *ui; + QMediaPlaylist *PLAYLIST; + QMediaPlayer *PLAYER; + QMenu *configMenu, *addMenu; + bool updatinglists; + +private slots: + void playClicked(); + void pauseClicked(); + void stopClicked(); + void nextClicked(); + void prevClicked(); + + void AddFilesToPlaylist(); + void AddDirToPlaylist(); + void AddURLToPlaylist(); + void ClearPlaylist(); + void ShufflePlaylist(); + void userlistSelectionChanged(); //front-end combobox was changed by the user + void playerStateChanged(); + void playlistChanged(); //list of items changed + void currentSongChanged(); + void updateProgress(qint64 val); + void updateMaxProgress(qint64 val); +}; + +#endif diff --git a/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/PPlayerWidget.ui b/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/PPlayerWidget.ui new file mode 100644 index 00000000..2d2450be --- /dev/null +++ b/src-qt5/core/lumina-desktop/panel-plugins/audioplayer/PPlayerWidget.ui @@ -0,0 +1,182 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PPlayerWidget</class> + <widget class="QWidget" name="PPlayerWidget"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>346</width> + <height>90</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <property name="styleSheet"> + <string notr="true">QToolButton::menu-indicator{ image: none; }</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>4</number> + </property> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QToolButton" name="tool_config"> + <property name="text"> + <string notr="true">Config</string> + </property> + <property name="popupMode"> + <enum>QToolButton::InstantPopup</enum> + </property> + <property name="autoRaise"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="tool_add"> + <property name="text"> + <string notr="true">Add</string> + </property> + <property name="popupMode"> + <enum>QToolButton::InstantPopup</enum> + </property> + <property name="autoRaise"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QToolButton" name="tool_prev"> + <property name="text"> + <string notr="true">prev</string> + </property> + <property name="autoRaise"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label_num"> + <property name="text"> + <string notr="true">1/10</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="tool_next"> + <property name="text"> + <string notr="true">next</string> + </property> + <property name="autoRaise"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QComboBox" name="combo_playlist"/> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QToolButton" name="tool_play"> + <property name="text"> + <string notr="true">Play</string> + </property> + <property name="autoRaise"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="tool_pause"> + <property name="text"> + <string notr="true">Pause</string> + </property> + <property name="autoRaise"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="tool_stop"> + <property name="text"> + <string notr="true">Stop</string> + </property> + <property name="autoRaise"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QProgressBar" name="progressBar"> + <property name="value"> + <number>24</number> + </property> + <property name="textVisible"> + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> |