aboutsummaryrefslogtreecommitdiff
path: root/lumina-desktop/desktop-plugins
diff options
context:
space:
mode:
authorKen Moore <ken@pcbsd.org>2015-01-16 18:00:31 -0500
committerKen Moore <ken@pcbsd.org>2015-01-16 18:00:31 -0500
commit0c91fd6dc5a8ed7e0571335d2ce6dd9b76e76dc9 (patch)
tree40f0b31c62440abd6ce501e5fae4325a7ee8ef45 /lumina-desktop/desktop-plugins
parentHave the user button automatically perform the long application listings in t... (diff)
downloadlumina-0c91fd6dc5a8ed7e0571335d2ce6dd9b76e76dc9.tar.gz
lumina-0c91fd6dc5a8ed7e0571335d2ce6dd9b76e76dc9.tar.bz2
lumina-0c91fd6dc5a8ed7e0571335d2ce6dd9b76e76dc9.zip
Add a new desktop plugin: audioplayer
Diffstat (limited to 'lumina-desktop/desktop-plugins')
-rw-r--r--lumina-desktop/desktop-plugins/NewDP.h3
-rw-r--r--lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.cpp213
-rw-r--r--lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.h79
-rw-r--r--lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.ui157
4 files changed, 452 insertions, 0 deletions
diff --git a/lumina-desktop/desktop-plugins/NewDP.h b/lumina-desktop/desktop-plugins/NewDP.h
index 6490af00..43d8e8f8 100644
--- a/lumina-desktop/desktop-plugins/NewDP.h
+++ b/lumina-desktop/desktop-plugins/NewDP.h
@@ -18,6 +18,7 @@
#include "applauncher/AppLauncherPlugin.h"
#include "desktopview/DesktopViewPlugin.h"
#include "notepad/NotepadPlugin.h"
+#include "audioplayer/PlayerWidget.h"
class NewDP{
public:
@@ -34,6 +35,8 @@ public:
plug = new DesktopViewPlugin(parent, plugin);
}else if(plugin.section("---",0,0)=="notepad"){
plug = new NotePadPlugin(parent, plugin);
+ }else if(plugin.section("---",0,0)=="audioplayer"){
+ plug = new AudioPlayerPlugin(parent, plugin);
}else{
qWarning() << "Invalid Desktop Plugin:"<<plugin << " -- Ignored";
}
diff --git a/lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.cpp b/lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.cpp
new file mode 100644
index 00000000..9cd16440
--- /dev/null
+++ b/lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.cpp
@@ -0,0 +1,213 @@
+//===========================================
+// Lumina-DE source code
+// Copyright (c) 2015, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#include "PlayerWidget.h"
+#include "ui_PlayerWidget.h"
+
+#include <QDir>
+#include <QUrl>
+#include <QInputDialog>
+#include <QFileDialog>
+#include <LuminaXDG.h>
+
+PlayerWidget::PlayerWidget(QWidget *parent) : QWidget(parent), ui(new Ui::PlayerWidget()){
+ ui->setupUi(this); //load the designer form
+ PLAYER = new QMediaPlayer(this);
+ PLAYER->setVolume(100);
+ 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);
+
+ //infoTimer = new QTimer(this);
+ //infoTimer->setInterval(30000); //every 30 seconds
+
+ updatinglists = false; //start off as false
+
+ LoadIcons();
+ playerStateChanged(); //update button visibility
+ currentSongChanged();
+ //Connect all the signals/slots
+ //connect(infoTimer, SIGNAL(timeout()), this, SLOT(rotateTrackInfo()) );
+ 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()) );
+
+}
+
+PlayerWidget::~PlayerWidget(){
+
+}
+
+void PlayerWidget::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 PlayerWidget::playClicked(){
+ PLAYER->play();
+}
+
+void PlayerWidget::pauseClicked(){
+ PLAYER->pause();
+}
+
+void PlayerWidget::stopClicked(){
+ PLAYER->stop();
+}
+
+void PlayerWidget::nextClicked(){
+ PLAYLIST->next();
+}
+
+void PlayerWidget::prevClicked(){
+ PLAYLIST->previous();
+}
+
+void PlayerWidget::AddFilesToPlaylist(){
+ //Prompt the user to select multimedia files
+ //Make this use show/processEvents later
+ QList<QUrl> files = QFileDialog::getOpenFileUrls(0, tr("Select Multimedia Files"), QDir::homePath(), "Multimedia Files ("+LXDG::findAVFileExtensions().join(" ")+")");
+ if(files.isEmpty()){ return; } //cancelled
+ QList<QMediaContent> urls;
+ for(int i=0; i<files.length(); i++){
+ urls << QMediaContent(files[i]);
+ }
+ PLAYLIST->addMedia(urls);
+ playlistChanged();
+}
+
+void PlayerWidget::AddDirToPlaylist(){
+ QString dirpath = 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 PlayerWidget::AddURLToPlaylist(){
+ 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 PlayerWidget::ClearPlaylist(){
+ PLAYER->stop();
+ PLAYLIST->clear();
+ playlistChanged();
+}
+
+void PlayerWidget::ShufflePlaylist(){
+ PLAYLIST->shuffle();
+}
+
+
+void PlayerWidget::userlistSelectionChanged(){ //front-end combobox was changed by the user
+ if(updatinglists){ return; }
+ PLAYLIST->setCurrentIndex( ui->combo_playlist->currentIndex() );
+}
+
+void PlayerWidget::playerStateChanged(){
+ switch( PLAYER->state() ){
+ case QMediaPlayer::StoppedState:
+ ui->tool_stop->setVisible(false);
+ ui->tool_play->setVisible(true);
+ ui->tool_pause->setVisible(false);
+ //infoTimer->stop();
+ break;
+ case QMediaPlayer::PausedState:
+ ui->tool_stop->setVisible(true);
+ ui->tool_play->setVisible(true);
+ ui->tool_pause->setVisible(false);
+ //infoTimer->stop();
+ break;
+ case QMediaPlayer::PlayingState:
+ ui->tool_stop->setVisible(true);
+ ui->tool_play->setVisible(false);
+ ui->tool_pause->setVisible(true);
+ //infoTimer->start();
+ break;
+ }
+
+}
+
+void PlayerWidget::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 PlayerWidget::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);
+ //rotateTrackInfo();
+}
+
+/*void PlayerWidget::rotateTrackInfo(){ //on a timer to rotate the visible information about the track
+ //NOTE: QMediaPlayer is a type of QMediaObject - so just pull the current info straight out of the player
+ ui->label_info->clear();
+}*/
+
+
+AudioPlayerPlugin::AudioPlayerPlugin(QWidget *parent, QString ID) : LDPlugin(parent, ID){
+ player = new PlayerWidget(this);
+ this->setLayout( new QVBoxLayout() );
+ this->layout()->setContentsMargins(0,0,0,0);
+ this->layout()->addWidget(player);
+
+ this->setInitialSize(300,100);
+}
+
+AudioPlayerPlugin::~AudioPlayerPlugin(){
+} \ No newline at end of file
diff --git a/lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.h b/lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.h
new file mode 100644
index 00000000..d50f8c26
--- /dev/null
+++ b/lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.h
@@ -0,0 +1,79 @@
+//===========================================
+// 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_DESKTOP_PLUGIN_AUDIO_PLAYER_WIDGET_H
+#define _LUMINA_DESKTOP_PLUGIN_AUDIO_PLAYER_WIDGET_H
+
+#include <QMediaPlaylist>
+#include <QMediaPlayer>
+#include <QTimer>
+#include <QWidget>
+#include <QMenu>
+
+#include "../LDPlugin.h"
+
+namespace Ui{
+ class PlayerWidget;
+};
+
+class PlayerWidget : public QWidget{
+ Q_OBJECT
+public:
+ PlayerWidget(QWidget *parent = 0);
+ ~PlayerWidget();
+
+public slots:
+ void LoadIcons();
+
+private:
+ Ui::PlayerWidget *ui;
+ QMediaPlaylist *PLAYLIST;
+ QMediaPlayer *PLAYER;
+ //QTimer *infoTimer;
+ 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 rotateTrackInfo(); //on a timer to rotate the visible information about the track
+};
+
+// Wrapper class to put this into a desktop plugin container
+class AudioPlayerPlugin : public LDPlugin{
+ Q_OBJECT
+public:
+ AudioPlayerPlugin(QWidget* parent, QString ID);
+ ~AudioPlayerPlugin();
+
+private:
+ PlayerWidget *player;
+
+public slots:
+ void LocaleChange(){
+ QTimer::singleShot(0,player, SLOT(LoadIcons()));
+ }
+ void ThemeChange(){
+ QTimer::singleShot(0,player, SLOT(LoadIcons()));
+ }
+};
+
+#endif
diff --git a/lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.ui b/lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.ui
new file mode 100644
index 00000000..40ad11b5
--- /dev/null
+++ b/lumina-desktop/desktop-plugins/audioplayer/PlayerWidget.ui
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PlayerWidget</class>
+ <widget class="QWidget" name="PlayerWidget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>262</width>
+ <height>111</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="spacing">
+ <number>0</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>
+ <widget class="QFrame" name="frame">
+ <property name="styleSheet">
+ <string notr="true">QFrame{ background: rgba(255,255,255,200); border-radius: 3px; }
+QToolButton::menu-indicator{ image: none; }</string>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::StyledPanel</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>QFrame::Raised</enum>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <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>
+ </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>
+ </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>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="tool_next">
+ <property name="text">
+ <string notr="true">next</string>
+ </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>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="tool_pause">
+ <property name="text">
+ <string notr="true">Pause</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="tool_stop">
+ <property name="text">
+ <string notr="true">Stop</string>
+ </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>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </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>
bgstack15