From f47ffd072d8467de07bab924eb874ab32f2234d4 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Thu, 5 Jun 2008 11:56:13 +0200 Subject: [PATCH] Initial commit of musik, my KDE4 simplest (and hopefully faster..) musik player. This is a music player with very simple features that can be used for "click and listen to" (music, of course). --- CMakeLists.txt | 28 +++++++++ main.cpp | 25 ++++++++ musik.png | Bin 0 -> 3241 bytes musikclass.cpp | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ musikclass.h | 52 ++++++++++++++++ musikedit.cpp | 115 +++++++++++++++++++++++++++++++++++ musikedit.h | 43 +++++++++++++ 7 files changed, 451 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 main.cpp create mode 100644 musik.png create mode 100644 musikclass.cpp create mode 100644 musikclass.h create mode 100644 musikedit.cpp create mode 100644 musikedit.h diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a914712 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,28 @@ +PROJECT(musik) + +CMAKE_MINIMUM_REQUIRED(VERSION 2.4.6) + +FIND_PACKAGE(KDE4 REQUIRED) + +INCLUDE_DIRECTORIES( ${KDE4_INCLUDES} ) +#INCLUDE(KDE4Defaults) +#INCLUDE(MacroLibrary) + +#SET( KDE4_AUTOMOC_EXECUTABLE "/DATI/future/kde/bin/automoc4" ) + +SET ( MY_SOURCES main.cpp musikclass.cpp musikedit.cpp ) +MESSAGE ( STATUS "my sources: ${MY_SOURCES}" ) + +INCLUDE_DIRECTORIES ( + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ) + + +KDE4_ADD_EXECUTABLE( musik ${MY_SOURCES} ) + +TARGET_LINK_LIBRARIES( musik ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS} ${KDE4_PHONON_LIBS} ) + + +#INSTALL ( TARGETS musik DESTINATION ${MY_SRC_DIR} ) + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..20c32ac --- /dev/null +++ b/main.cpp @@ -0,0 +1,25 @@ +// andrea diamantini - adjam7@gmail.com +// musik - simplest KDE4 audio player + +#include +#include +#include + +#include "musikclass.h" + +int main (int argc, char *argv[]) +{ + KAboutData aboutData( "musik", "simplest (and hopefully faster) kde4 audio player", + ki18n("musik"), "0.0.1", + ki18n("simplest (and hopefully faster) kde4 audio player"), + KAboutData::License_GPL, + ki18n("Copyright (c) 2008 Andrea Diamantini") ); + + KCmdLineArgs::init( argc, argv, &aboutData ); + KApplication app; + + Musik *window = new Musik(); + window->show(); + + return app.exec(); +} diff --git a/musik.png b/musik.png new file mode 100644 index 0000000000000000000000000000000000000000..c8bf92bcf8eb95f838ac6d0ce1aa4aeb531d27d0 GIT binary patch literal 3241 zcwPai3|8}rP)V#Rsm)UpwX+qYt;}8dO$_kbn)7{ zNZtOb&_Dn5n&Ykd3$c0tK6+XHwg3wDZWy|K)X1!B#=7%tLx534gzq->G*#DCbS>1?l5N+ z^D=aJ{Fyi!Y=y|o%!1G7BjY9}g92bMK>uHiYiZOmX_UX&jIcUa0UXCc=-dRs`5d(7 zAT;S__yelYx-G#EfAfsfW(jJG#%*i$tW4yT+dV2sc;PHD^ z>z;ZQ!0c%A{MIF)ig zblsYMNkN#L55SmG4^65T)iq+xo%h)vxzH-@B7dD%3XnQ<0G5C7x^Z!SfesO*;-ft} zY}`2-4o4eHBW9d|Fp+V6m-%GACnL|sgn8kjcyK%iPQ|e_0u+ci1Cm4uCjTo)Rd0qd zSB-`y*cL2xK6>PMcs-rtyAl93fLm59RjpdONK+8wvOyaLtayDQMI;33bS&zL=#yyF z85ls)e0Sa_%>QTf82}juNQr~mGAnTA!@n1~SdH{z6`IIcT| z0Cd*_K`5beR{D`Om2?1yIxl zAW0IaAu@1pdkgY})fhR>hd_vn+;zWW(e^#Tx9QyQjHGrKNElC=*J*X|b#|hm`8=B;jYi8%ilWHUs<0p*1NskO5NrmL0E|FR z05AwqRsz7T;dPuuS@v2C8x=);16rrdX}zW08?E|UfCNM)fZK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@ zQ`4|*>o)2tZLHOmmi9wlejdwbG1vqta28pHMvN{OQJ5t|ZOVo=dn$yKQb;i;Lf#{A zdpvAq@8~qZ>(|3#@}O_74SBgin2i!R9%NjB)L{K)NqlluXae%eB1E224iRu&Jd4WCTy1*=a8mtz>tz4veN;9 z(!-il2}^n&^acxnV3*_$ihMhnY6nQRHW5d@;IQ?Rc+1w^@pl6uYy$8pd5-lAAPJF6 z{r=9`b7n8f&(AMWrr%<*AQTGWaMfWno^N0)FrA}p1sGsjdKye7BZHA64#+VwCk4r9 z7(@o13nE1yg4raJKy{*m+sjF +#include + +#include "musikclass.h" +#include "musikedit.h" + + +Musik::Musik() +{ + audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); + mediaObject = new Phonon::MediaObject(this); + + connect( mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)), + this, SLOT(changeState(Phonon::State, Phonon::State))); + + Phonon::createPath(mediaObject, audioOutput); + + setupActions(); + setupUi(); +}; + +Musik::~Musik() +{}; + + +void Musik::setupActions() +{ + playAction = new QAction(style()->standardIcon(QStyle::SP_MediaPlay), + tr("Play"), this); + playAction->setShortcut(tr("Crl+P")); + playAction->setDisabled(true); + + + pauseAction = new QAction(style()->standardIcon(QStyle::SP_MediaPause), + tr("Pause"), this); + pauseAction->setShortcut(tr("Space")); + pauseAction->setDisabled(true); + + + stopAction = new QAction(style()->standardIcon(QStyle::SP_MediaStop), + tr("Stop"), this); + stopAction->setShortcut(tr("Ctrl+S")); + stopAction->setDisabled(true); + + + openFileAction = new QAction(style()->standardIcon(QStyle::SP_FileDialogStart), + tr("Add &Files"), this); + openFileAction->setShortcut(tr("Ctrl+F")); + + + editTagAction = new QAction(style()->standardIcon(QStyle::SP_FileDialogContentsView), + tr("Edit Tag"), this); + editTagAction->setShortcut(tr("Crl+E")); + editTagAction->setDisabled(true); + + + connect ( playAction, SIGNAL( triggered() ), mediaObject, SLOT( play() ) ); + connect ( pauseAction, SIGNAL( triggered() ), mediaObject, SLOT( pause() ) ); + connect ( stopAction, SIGNAL( triggered() ), mediaObject, SLOT( stop() ) ); + connect ( openFileAction, SIGNAL( triggered() ), this, SLOT( chooseFile() ) ); + connect ( editTagAction, SIGNAL( triggered() ), this, SLOT( editTag() ) ); +} + + +void Musik::setupUi() +{ + line = new QLineEdit; + line->setReadOnly(true); + + QToolBar *bar = new QToolBar; + bar->addAction(playAction); + bar->addAction(pauseAction); + bar->addAction(stopAction); + bar->addAction(openFileAction); + bar->addAction(editTagAction); + + seekSlider = new Phonon::SeekSlider(this); + seekSlider->setMediaObject(mediaObject); + + volumeSlider = new Phonon::VolumeSlider(this); + volumeSlider->setAudioOutput(audioOutput); + volumeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + + QLabel *volumeLabel = new QLabel; + volumeLabel->setPixmap(QPixmap("images/volume.png")); + + QHBoxLayout *seekerLayout = new QHBoxLayout; + seekerLayout->addWidget(seekSlider); + + QVBoxLayout *upperLayout = new QVBoxLayout; + upperLayout->addWidget(line); + upperLayout->addLayout(seekerLayout); + + QHBoxLayout *playbackLayout = new QHBoxLayout; + playbackLayout->addWidget(bar); + playbackLayout->addStretch(); + playbackLayout->addWidget(volumeLabel); + playbackLayout->addWidget(volumeSlider); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(upperLayout); + mainLayout->addLayout(playbackLayout); + + setLayout(mainLayout); + setWindowTitle("Musik"); + setWindowIcon( QIcon("/DATI/future/kde/src/musik/musik.png") ); // FIXME +} + +// ---------------------------------------------------------------------- + +void Musik::chooseFile() +{ + filePath = KFileDialog::getOpenFileName(KUrl(), + "Audio ( *.mp3 , *.wav , *.ogg )", + this, + tr("Open audio file") ); + + if( !filePath.isEmpty() ) + { + mediaObject->setCurrentSource(filePath); + playAction->setDisabled(false); + } + + mediaObject->play(); +}; + + +void Musik::changeState(Phonon::State newState, Phonon::State /* oldState */ ) +{ + switch (newState) { + case Phonon::ErrorState: + if (mediaObject->errorType() == Phonon::FatalError) { + QMessageBox::warning(this, tr("Fatal Error"), + mediaObject->errorString()); + } else { + QMessageBox::warning(this, tr("Error"), + mediaObject->errorString()); + } + break; + case Phonon::PlayingState: + playAction->setEnabled(false); + pauseAction->setEnabled(true); + stopAction->setEnabled(true); + editTagAction->setEnabled(true); + setInfo(); + break; + case Phonon::StoppedState: + stopAction->setEnabled(false); + playAction->setEnabled(true); + pauseAction->setEnabled(false); + break; + case Phonon::PausedState: + pauseAction->setEnabled(false); + stopAction->setEnabled(true); + playAction->setEnabled(true); + break; + case Phonon::BufferingState: + break; + default: + ; + } +} + + +void Musik::setInfo() +{ + metaData = mediaObject->metaData(); + + QString info; + QString author = metaData.value("ARTIST"); + QString title = metaData.value("TITLE"); + if (author == "" || title == "") + info = mediaObject->currentSource().fileName(); + else + info = author + QString(" - ") + title; + + line->setText(info); +} + +void Musik::editTag() +{ + MusikEdit *win = new MusikEdit(*mediaObject); + win->show(); +}; diff --git a/musikclass.h b/musikclass.h new file mode 100644 index 0000000..aaf24ce --- /dev/null +++ b/musikclass.h @@ -0,0 +1,52 @@ +// andrea diamantini - adjam7@gmail.com +// musik - simplest KDE4 audio player +// file musikui.h + +#ifndef MUSIK_UI_H +#define MUSIK_UI_H + +#include + +#include +#include +#include +#include +#include + +class Musik : public QWidget +{ + Q_OBJECT +public: + Musik(); + + ~Musik(); + +private slots: + void chooseFile(); + void editTag(); + + void changeState(Phonon::State, Phonon::State); + +private: + void setupActions(); + void setupUi(); + void setInfo(); + + QString filePath; + QMap metaData; + + Phonon::SeekSlider *seekSlider; + Phonon::MediaObject *mediaObject; + Phonon::AudioOutput *audioOutput; + Phonon::VolumeSlider *volumeSlider; + Phonon::MediaSource *source; + + QLineEdit *line; + QAction *playAction; + QAction *pauseAction; + QAction *stopAction; + QAction *editTagAction; + QAction *openFileAction; +}; + +#endif diff --git a/musikedit.cpp b/musikedit.cpp new file mode 100644 index 0000000..6cc1946 --- /dev/null +++ b/musikedit.cpp @@ -0,0 +1,115 @@ +// andrea diamantini - adjam7@gmail.com +// musik - simplest KDE4 audio player +// file musikedit.cpp + +#include "musikedit.h" + + +MusikEdit::MusikEdit(Phonon::MediaObject & mo) +{ + setupUi(); + setSongInfo(mo); + + connect( okButton , SIGNAL( clicked() ), this , SLOT( ok() ) ); + connect( clearButton , SIGNAL( clicked() ), this , SLOT( clear() ) ); + connect( cancelButton , SIGNAL( clicked() ), this , SLOT( cancel() ) ); +}; + + + +MusikEdit::~MusikEdit() +{}; + + +void MusikEdit::setupUi() +{ + QLabel *artistLabel = new QLabel( tr("artist") ); + QLabel *albumLabel = new QLabel( tr("album") ); + QLabel *titleLabel = new QLabel( tr("title") ); + QLabel *dateLabel = new QLabel( tr("date") ); + QLabel *genreLabel = new QLabel( tr("genre") ); + QLabel *trackNumberLabel = new QLabel( tr("track number") ); + QLabel *descLabel = new QLabel( tr("description") ); + + QVBoxLayout *labelLayout = new QVBoxLayout; + labelLayout->addWidget(artistLabel); + labelLayout->addWidget(albumLabel); + labelLayout->addWidget(titleLabel); + labelLayout->addWidget(dateLabel); + labelLayout->addWidget(genreLabel); + labelLayout->addWidget(trackNumberLabel); + labelLayout->addWidget(descLabel); + + artistLine = new QLineEdit(); + albumLine = new QLineEdit(); + titleLine = new QLineEdit(); + dateLine = new QLineEdit(); + genreLine = new QLineEdit(); + trackNumberLine = new QLineEdit(); + descLine = new QLineEdit(); + + QVBoxLayout *lineLayout = new QVBoxLayout; + lineLayout->addWidget(artistLine); + lineLayout->addWidget(albumLine); + lineLayout->addWidget(titleLine); + lineLayout->addWidget(dateLine); + lineLayout->addWidget(genreLine); + lineLayout->addWidget(trackNumberLine); + lineLayout->addWidget(descLine); + + + okButton = new QPushButton( tr("ok") ); + clearButton = new QPushButton( tr("clear") ); + cancelButton = new QPushButton( tr("cancel") ); + QHBoxLayout *buttonLayout = new QHBoxLayout; + buttonLayout->addWidget(okButton); + buttonLayout->addWidget(clearButton); + buttonLayout->addWidget(cancelButton); + + QHBoxLayout *infoLayout = new QHBoxLayout; + infoLayout->addLayout(labelLayout); + infoLayout->addLayout(lineLayout); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addLayout(infoLayout); + mainLayout->addLayout(buttonLayout); + + setLayout(mainLayout); + setWindowTitle("Musik Tag Editor"); +}; + + +void MusikEdit::setSongInfo(Phonon::MediaObject & mo) +{ + artistLine->setText( mo.metaData("ARTIST").at(0) ); + albumLine->setText( mo.metaData("ALBUM").at(0) ); + titleLine->setText( mo.metaData("TITLE").at(0) ); + dateLine->setText( mo.metaData("DATE").at(0) ); + genreLine->setText( mo.metaData("GENRE").at(0) ); + trackNumberLine->setText( mo.metaData("TRACKNUMBER").at(0) ); + descLine->setText( mo.metaData("DESCRIPTION").at(0) ); +}; + + +void MusikEdit::ok() +{ + // FIXME!! +}; + + +void MusikEdit::clear() +{ + artistLine->clear(); + albumLine->clear(); + titleLine->clear(); + dateLine->clear(); + genreLine->clear(); + trackNumberLine->clear(); + descLine->clear(); +}; + + +void MusikEdit::cancel() +{ + this->close(); +}; diff --git a/musikedit.h b/musikedit.h new file mode 100644 index 0000000..df13bf4 --- /dev/null +++ b/musikedit.h @@ -0,0 +1,43 @@ +// andrea diamantini - adjam7@gmail.com +// musik - simplest KDE4 audio player +// file musikedit.h + +#ifndef MUSIK_EDIT_H +#define MUSIK_EDIT_H + +#include + +#include + +class MusikEdit : public QWidget +{ + Q_OBJECT + +public: + MusikEdit(Phonon::MediaObject &); + ~MusikEdit(); + +private: + void setSongInfo(Phonon::MediaObject &); + void setupUi(); + + QLineEdit *artistLine; + QLineEdit *albumLine; + QLineEdit *titleLine; + QLineEdit *dateLine; + QLineEdit *genreLine; + QLineEdit *trackNumberLine; + QLineEdit *descLine; + + QPushButton *okButton; + QPushButton *clearButton; + QPushButton *cancelButton; + +private slots: + void ok(); + void clear(); + void cancel(); + +}; + +#endif -- 2.11.4.GIT