diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-12-23 21:13:34 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-12-23 21:13:34 +0000 |
| commit | fedd13511bbf91914a0250b43c440f43e6d1e8c5 (patch) | |
| tree | 03cca77aab98ce8c8c2b261f345655d64ae8e172 | |
| parent | ac7a7dffc31afe8a20a51db4ab7749bf4fdea67c (diff) | |
| download | qmmp-fedd13511bbf91914a0250b43c440f43e6d1e8c5.tar.gz qmmp-fedd13511bbf91914a0250b43c440f43e6d1e8c5.tar.bz2 qmmp-fedd13511bbf91914a0250b43c440f43e6d1e8c5.zip | |
full mpris support; new options: "repeat track", "show protocol"
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@698 90c681e8-e032-0410-971d-27865f9a5e38
| -rw-r--r-- | src/plugins/General/mpris/playerobject.cpp | 8 | ||||
| -rw-r--r-- | src/plugins/General/mpris/playerobject.h | 2 | ||||
| -rw-r--r-- | src/plugins/General/mpris/tracklistobject.cpp | 23 | ||||
| -rw-r--r-- | src/plugins/General/mpris/tracklistobject.h | 4 | ||||
| -rw-r--r-- | src/qmmpui/mediaplayer.cpp | 22 | ||||
| -rw-r--r-- | src/qmmpui/mediaplayer.h | 6 | ||||
| -rw-r--r-- | src/qmmpui/playlistmodel.cpp | 35 | ||||
| -rw-r--r-- | src/qmmpui/playlistmodel.h | 4 | ||||
| -rw-r--r-- | src/ui/configdialog.cpp | 2 | ||||
| -rw-r--r-- | src/ui/forms/configdialog.ui | 20 | ||||
| -rw-r--r-- | src/ui/listwidget.cpp | 55 | ||||
| -rw-r--r-- | src/ui/listwidget.h | 49 | ||||
| -rw-r--r-- | src/ui/mainwindow.cpp | 19 |
13 files changed, 186 insertions, 63 deletions
diff --git a/src/plugins/General/mpris/playerobject.cpp b/src/plugins/General/mpris/playerobject.cpp index 3c9d374d1..160d32e56 100644 --- a/src/plugins/General/mpris/playerobject.cpp +++ b/src/plugins/General/mpris/playerobject.cpp @@ -64,6 +64,7 @@ PlayerObject::PlayerObject(QObject *parent) connect(m_core, SIGNAL(stateChanged (Qmmp::State)), SLOT(updateStatus())); connect(m_model, SIGNAL(repeatableListChanged(bool)), SLOT(updateStatus())); connect(m_model, SIGNAL(shuffleChanged(bool)), SLOT(updateStatus())); + connect(m_player, SIGNAL(repeatableChanged(bool)), SLOT(updateStatus())); } PlayerObject::~PlayerObject() @@ -94,6 +95,11 @@ void PlayerObject::Play() m_player->play(); } +void PlayerObject::Repeat(bool in0) +{ + m_player->setRepeatable(in0); +} + PlayerStatus PlayerObject::GetStatus() { PlayerStatus st; @@ -112,7 +118,7 @@ PlayerStatus PlayerObject::GetStatus() st.state = 1; }; st.random = int(m_model->isShuffle()); - st.repeat = 0; //TODO add suppot for this + st.repeat = int(m_player->isRepeatable()); st.repeatPlayList = int(m_model->isRepeatableList()); return st; } diff --git a/src/plugins/General/mpris/playerobject.h b/src/plugins/General/mpris/playerobject.h index ea8cbe1c1..dbd7e771c 100644 --- a/src/plugins/General/mpris/playerobject.h +++ b/src/plugins/General/mpris/playerobject.h @@ -72,7 +72,7 @@ public slots: void Pause(); void Stop(); void Play(); - //void Repeat(); + void Repeat(bool in0); PlayerStatus GetStatus(); QVariantMap GetMetadata(); int GetCaps(); diff --git a/src/plugins/General/mpris/tracklistobject.cpp b/src/plugins/General/mpris/tracklistobject.cpp index dfce2d8af..6b3699a0c 100644 --- a/src/plugins/General/mpris/tracklistobject.cpp +++ b/src/plugins/General/mpris/tracklistobject.cpp @@ -19,6 +19,7 @@ ***************************************************************************/ #include <QFile> +#include <QUrl> #include <qmmpui/playlistmodel.h> #include <qmmpui/mediaplayer.h> @@ -39,15 +40,29 @@ TrackListObject::~TrackListObject() { } -/*int TrackListObject::AddTrack(const QString &in0, bool in1) +int TrackListObject::AddTrack(const QString &in0, bool in1) { - m_model->addFile(in0); + int old_count = m_model->count(); + if(in0.startsWith("file://")) + m_model->addFile(QUrl(in0).toLocalFile ()); //converts url to local file path + else + m_model->addFile(in0); + int new_count = m_model->count(); + if(new_count == old_count) + return 0; if(in1) { - m_model->set + m_model->setCurrent(new_count-1); + m_player->stop(); + m_player->play(); } return 1; -}*/ +} + +void TrackListObject::DelTrack(int in0) +{ + m_model->removeAt(in0); +} int TrackListObject::GetCurrentTrack() { diff --git a/src/plugins/General/mpris/tracklistobject.h b/src/plugins/General/mpris/tracklistobject.h index c1ff169b1..856ebd5df 100644 --- a/src/plugins/General/mpris/tracklistobject.h +++ b/src/plugins/General/mpris/tracklistobject.h @@ -41,8 +41,8 @@ public: ~TrackListObject(); public slots: - //int AddTrack(const QString &in0, bool in1); - /*void DelTrack(int in0);*/ + int AddTrack(const QString &in0, bool in1); + void DelTrack(int in0); int GetCurrentTrack(); int GetLength(); QVariantMap GetMetadata(int in0); diff --git a/src/qmmpui/mediaplayer.cpp b/src/qmmpui/mediaplayer.cpp index 311b195b9..f0e7c54ae 100644 --- a/src/qmmpui/mediaplayer.cpp +++ b/src/qmmpui/mediaplayer.cpp @@ -35,6 +35,7 @@ MediaPlayer::MediaPlayer(QObject *parent) m_instance = this; m_model = 0; m_core = 0; + m_repeat = FALSE; } @@ -53,6 +54,7 @@ void MediaPlayer::initialize(SoundCore *core, PlayListModel *model) Q_CHECK_PTR(model); m_core = core; m_model = model; + m_repeat = FALSE; connect(m_core, SIGNAL(finished()), SLOT(next())); } @@ -61,6 +63,11 @@ PlayListModel *MediaPlayer::playListModel() return m_model; } +bool MediaPlayer::isRepeatable() const +{ + return m_repeat; +} + void MediaPlayer::play() { m_model->doCurrentVisibleRequest(); @@ -155,3 +162,18 @@ void MediaPlayer::previous() display->hideTimeDisplay();*/ } +void MediaPlayer::setRepeatable(bool r) +{ + if (r != m_repeat && !r) + { + disconnect(m_core, SIGNAL(finished()), this, SLOT(play())); + connect(m_core, SIGNAL(finished()), SLOT(next())); + } + else if (r != m_repeat && r) + { + disconnect(m_core, SIGNAL(finished()), this, SLOT(next())); + connect(m_core, SIGNAL(finished()), SLOT(play())); + } + m_repeat = r; + emit repeatableChanged(r); +} diff --git a/src/qmmpui/mediaplayer.h b/src/qmmpui/mediaplayer.h index fefc42978..920ef6908 100644 --- a/src/qmmpui/mediaplayer.h +++ b/src/qmmpui/mediaplayer.h @@ -40,17 +40,23 @@ public: void initialize(SoundCore *core, PlayListModel *model); PlayListModel *playListModel(); + bool isRepeatable() const; public slots: void play(); void stop(); void next(); void previous(); + void setRepeatable(bool); + +signals: + void repeatableChanged(bool); private: PlayListModel *m_model; SoundCore *m_core; static MediaPlayer* m_instance; + bool m_repeat; }; diff --git a/src/qmmpui/playlistmodel.cpp b/src/qmmpui/playlistmodel.cpp index 812ae51b2..2f00568f9 100644 --- a/src/qmmpui/playlistmodel.cpp +++ b/src/qmmpui/playlistmodel.cpp @@ -72,6 +72,7 @@ PlayListModel::PlayListModel(QObject *parent) : QObject(parent) , m_selection() { qsrand(time(0)); + m_shuffle = 0; m_total_length = 0; m_current = 0; m_block_update_signals = false; @@ -240,6 +241,34 @@ void PlayListModel::removeUnselected() removeSelection(true); } +void PlayListModel::removeAt (int i) +{ + if ((i < count()) && (i >= 0)) + { + PlayListItem* f = m_items.takeAt(i); + m_total_length -= f->length(); + if (m_total_length < 0) + m_total_length = qMin(0, m_total_length); + + if (f->flag() == PlayListItem::FREE) + { + delete f; + f = NULL; + } + else if (f->flag() == PlayListItem::EDITING) + f->setFlag(PlayListItem::SCHEDULED_FOR_DELETION); + + if (m_current >= i && m_current != 0) + m_current--; + + if (!m_items.isEmpty()) + m_currentItem = m_items.at(m_current); + + m_play_state->prepare(); + emit listChanged(); + } +} + void PlayListModel::removeSelection(bool inverted) { int i = 0; @@ -826,7 +855,9 @@ void PlayListModel::prepareForShufflePlaying(bool val) else m_play_state = new NormalPlayState(this); - emit shuffleChanged(val); + m_shuffle = val; + + emit shuffleChanged(val); } void PlayListModel::prepareForRepeatablePlaying(bool val) @@ -904,7 +935,7 @@ bool PlayListModel::isRepeatableList() const bool PlayListModel::isShuffle() const { - return FALSE; //TODO fix this + return m_shuffle; } bool PlayListModel::isFileLoaderRunning() const diff --git a/src/qmmpui/playlistmodel.h b/src/qmmpui/playlistmodel.h index c0a4e1168..3c2ca50f7 100644 --- a/src/qmmpui/playlistmodel.h +++ b/src/qmmpui/playlistmodel.h @@ -129,7 +129,7 @@ public: /*! * Returns index of \b f file in queue.e */ - int queuedIndex(PlayListItem* item)const + int queuedIndex(PlayListItem* item) const { return m_queued_songs.indexOf(item); } @@ -206,6 +206,7 @@ public slots: void clearSelection(); void removeSelected(); void removeUnselected(); + void removeAt (int i); void invertSelection(); void selectAll(); void showDetails(); @@ -346,6 +347,7 @@ private: * when finished. */ QVector<GuardedFileLoader> m_running_loaders; + bool m_shuffle; }; diff --git a/src/ui/configdialog.cpp b/src/ui/configdialog.cpp index 8b7a82591..d1a25ef1f 100644 --- a/src/ui/configdialog.cpp +++ b/src/ui/configdialog.cpp @@ -104,6 +104,7 @@ void ConfigDialog::readSettings() ui.underscoresCheckBox->setChecked(settings.value ("PlayList/convert_underscore", TRUE).toBool()); ui.per20CheckBox->setChecked(settings.value ("PlayList/convert_twenty", TRUE).toBool()); ui.fullPathCheckBox->setChecked(settings.value ("PlayList/full_stream_path", FALSE).toBool()); + ui.protocolCheckBox->setChecked(settings.value ("PlayList/show_protocol", FALSE).toBool()); //proxy settings ui.enableProxyCheckBox->setChecked( @@ -543,6 +544,7 @@ void ConfigDialog::saveSettings() settings.setValue ("PlayList/convert_underscore", ui.underscoresCheckBox->isChecked()); settings.setValue ("PlayList/convert_twenty", ui.per20CheckBox->isChecked()); settings.setValue ("PlayList/full_stream_path", ui.fullPathCheckBox->isChecked()); + settings.setValue ("PlayList/show_protocol", ui.protocolCheckBox->isChecked()); FileDialog::setEnabled(FileDialog::registeredFactories().at(ui.fileDialogComboBox->currentIndex())); settings.setValue ("Proxy/use_proxy", ui.enableProxyCheckBox->isChecked()); settings.setValue ("Proxy/authentication", ui.authProxyCheckBox->isChecked()); diff --git a/src/ui/forms/configdialog.ui b/src/ui/forms/configdialog.ui index 15d1a5d7b..0f1132569 100644 --- a/src/ui/forms/configdialog.ui +++ b/src/ui/forms/configdialog.ui @@ -299,16 +299,7 @@ </layout> </widget> <widget class="QWidget" name="page" > - <layout class="QVBoxLayout" > - <property name="topMargin" > - <number>5</number> - </property> - <property name="rightMargin" > - <number>0</number> - </property> - <property name="bottomMargin" > - <number>0</number> - </property> + <layout class="QVBoxLayout" name="verticalLayout" > <item> <widget class="QGroupBox" name="groupBox_3" > <property name="title" > @@ -336,7 +327,7 @@ <property name="title" > <string>Song Display</string> </property> - <layout class="QGridLayout" > + <layout class="QGridLayout" name="gridLayout_3" > <item row="0" column="0" > <widget class="QLabel" name="label_4" > <property name="text" > @@ -378,6 +369,13 @@ </property> </widget> </item> + <item row="4" column="0" colspan="2" > + <widget class="QCheckBox" name="protocolCheckBox" > + <property name="text" > + <string>Show protocol</string> + </property> + </widget> + </item> </layout> </widget> </item> diff --git a/src/ui/listwidget.cpp b/src/ui/listwidget.cpp index 3219611f1..8590a1b2a 100644 --- a/src/ui/listwidget.cpp +++ b/src/ui/listwidget.cpp @@ -29,6 +29,7 @@ #include <qmmpui/playlistitem.h> #include <qmmpui/playlistmodel.h> +#include <qmmpui/mediaplayer.h> #include "textscroller.h" #include "listwidget.h" @@ -48,7 +49,8 @@ ListWidget::ListWidget(QWidget *parent) m_scroll_direction = NONE; m_prev_y = 0; m_anchor_row = INVALID_ROW; - + m_player = MediaPlayer::instance(); + connect (m_player, SIGNAL(repeatableChanged(bool)), SLOT(updateList())); m_first = 0; m_rows = 0; m_scroll = FALSE; @@ -67,6 +69,7 @@ void ListWidget::readSettings() QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); QString fontname = settings.value("PlayList/Font","").toString(); m_font.fromString(fontname); + m_show_protocol = settings.value ("PlayList/show_protocol", FALSE).toBool(); if (m_update) { @@ -118,31 +121,24 @@ void ListWidget::paintEvent(QPaintEvent *) m_painter.drawText(10,14+i*m_metrics->ascent(),m_titles.at(i)); - if (m_model->isQueued(m_model->item(i + m_first))) + if (m_model->isQueued(m_model->item(i + m_first)) || + (m_player->isRepeatable() && (m_model->currentRow() == m_first + i)) || m_show_protocol) { - QString queue_string = "|" + - QString::number(1 + m_model->queuedIndex(m_model->item(m_first + i))) + "|"; + QString extra_string = getExtraString(m_first + i); int old_size = m_font.pointSize(); m_font.setPointSize(old_size - 1 ); m_painter.setFont(m_font); - m_painter.drawText(width() - 10 - m_metrics->width(queue_string) - m_metrics->width(m_times.at(i)), 12+i*m_metrics->ascent (), queue_string); - + m_painter.drawText(width() - 10 - m_metrics->width(extra_string) - m_metrics->width(m_times.at(i)), + 12+i*m_metrics->ascent (), extra_string); m_font.setPointSize(old_size); m_painter.setFont(m_font); - - - m_painter.setBrush(QBrush(Qt::transparent)); - //m_painter.drawRect(width() - 10 - m_metrics->width(queue_string) - m_metrics->width(m_times.at(i)), - // /*14+*/i*m_metrics->ascent () + 3,10,12); m_painter.setBrush(QBrush(m_normal_bg)); } - m_painter.drawText(width() - 7 - m_metrics->width(m_times.at(i)), 14+i*m_metrics->ascent (), m_times.at(i)); - } } @@ -338,24 +334,16 @@ void ListWidget::cut() QString name; cut = FALSE; - int queue_number_space = 0; - if (m_model->isQueued(m_model->item(i + m_first))) - { - int index = m_model->queuedIndex(m_model->item(m_first + i)); - QString queue_string = "|"+QString::number(index)+"|"; - queue_number_space = m_metrics->width(queue_string); - } - while ( m_metrics->width(m_titles.at(i)) > (this->width() - 54 - queue_number_space)) + QString extra_string = getExtraString(m_first + i); + int extra_string_space = extra_string.isEmpty() ? 0 : m_metrics->width(extra_string); + while (m_metrics->width(m_titles.at(i)) > (this->width() - 54 - extra_string_space)) { cut = TRUE; name = m_titles.at(i); m_titles.replace(i, name.left(name.length()-1) ); } if (cut) - { m_titles.replace(i, name.left(name.length()-3).trimmed()+"..."); - - } } } @@ -403,6 +391,25 @@ void ListWidget::processFileInfo(const QFileInfo& info) } } +const QString ListWidget::getExtraString(int i) +{ + QString extra_string; + + if (m_show_protocol && m_model->item(i)->url().contains("://")) + extra_string = "[" + m_model->item(i)->url().split("://").at(0) + "]"; + + if (m_player->isRepeatable() && (m_model->currentRow() == i)) + extra_string += " |R|"; + + if (m_model->isQueued(m_model->item(i))) + { + int index = m_model->queuedIndex(m_model->item(i)); + extra_string += " |"+QString::number(index + 1)+"|"; + } + extra_string = extra_string.trimmed(); //remove white space + return extra_string; +} + void ListWidget::mouseMoveEvent(QMouseEvent *e) { m_scroll = true; diff --git a/src/ui/listwidget.h b/src/ui/listwidget.h index 6b012a930..b34e8b8ac 100644 --- a/src/ui/listwidget.h +++ b/src/ui/listwidget.h @@ -36,6 +36,7 @@ class PlayList; class PlayListModel; class Skin; class PlayListItem; +class MediaPlayer; class ListWidget : public QWidget { @@ -47,19 +48,31 @@ public: void setModel(PlayListModel *); void readSettings(); - /*! - * Returns count of currently visible rows. - */ - int visibleRows()const{return m_rows;} - - /*! - * Returns number of first visible row. - */ - int firstVisibleRow()const{return m_first;} - - int getAnchorRow()const{return m_anchor_row;} - - void setAnchorRow(int r){m_anchor_row = r;} + /*! + * Returns count of currently visible rows. + */ + int visibleRows()const + { + return m_rows; + } + + /*! + * Returns number of first visible row. + */ + int firstVisibleRow()const + { + return m_first; + } + + int getAnchorRow()const + { + return m_anchor_row; + } + + void setAnchorRow(int r) + { + m_anchor_row = r; + } public slots: void updateList(); @@ -100,6 +113,10 @@ private: int m_pressed_row; QMenu *m_menu; PlayListModel *m_model; + /*! + * Returns string with queue number or(and) repeate flag for the item number \b i. + */ + const QString getExtraString(int i); int m_rows, m_first; QList <QString> m_titles; QList <QString> m_times; @@ -108,7 +125,7 @@ private: QFontMetrics *m_metrics; Skin *m_skin; QColor m_normal, m_current, m_normal_bg, m_selected_bg; - int m_anchor_row; + int m_anchor_row; enum ScrollDirection { @@ -120,7 +137,9 @@ private: */ ScrollDirection m_scroll_direction; int m_prev_y; - bool m_select_on_release; + bool m_select_on_release; + bool m_show_protocol; + MediaPlayer *m_player; }; #endif diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index d9a45249d..475c5e110 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -202,7 +202,7 @@ void MainWindow::stop() void MainWindow::next() { - m_player->next(); + m_player->next(); } void MainWindow::previous() @@ -417,11 +417,26 @@ void MainWindow::createActions() m_mainMenu->addAction(tr("&Next"),this, SLOT(next()), tr("B")); m_mainMenu->addAction(tr("&Play/Pause"),this, SLOT(playPause()), tr("Space")); m_mainMenu->addSeparator(); + QAction *repeateAllAction = m_mainMenu->addAction(tr("&Repeat All")); + QAction *repeateTrackAction = m_mainMenu->addAction(tr("&Repeat Track")); + QAction *shuffleAction = m_mainMenu->addAction(tr("&Shuffle")); + repeateAllAction->setCheckable (TRUE); + repeateTrackAction->setCheckable (TRUE); + shuffleAction->setCheckable (TRUE); + repeateAllAction->setShortcut(tr("R")) ; + repeateTrackAction->setShortcut(tr("Ctrl+R")) ; + shuffleAction->setShortcut(tr("S")) ; + connect(repeateAllAction, SIGNAL(triggered (bool)), m_playListModel, SLOT(prepareForRepeatablePlaying(bool))); + connect(repeateTrackAction, SIGNAL(triggered (bool)), m_player, SLOT(setRepeatable(bool))); + connect(shuffleAction, SIGNAL(triggered (bool)), m_playListModel, SLOT(prepareForShufflePlaying(bool))); + connect(m_playListModel, SIGNAL(repeatableListChanged(bool)), repeateAllAction, SLOT(setChecked(bool))); + connect(m_player, SIGNAL (repeatableChanged(bool)), repeateTrackAction, SLOT(setChecked(bool))); + connect(m_playListModel, SIGNAL(shuffleChanged(bool)), shuffleAction, SLOT(setChecked(bool))); + m_mainMenu->addSeparator(); m_mainMenu->addAction(tr("&Jump To File"),this, SLOT(jumpToFile()), tr("J")); m_mainMenu->addSeparator(); m_visMenu = new VisualMenu(this); m_mainMenu->addMenu(m_visMenu); - m_mainMenu->addSeparator(); m_mainMenu->addAction(tr("&Settings"), this, SLOT(showSettings()), tr("Ctrl+P")); m_mainMenu->addSeparator(); |
