From 079a559247244f16dfbe6aa67a130bb30ff5ca58 Mon Sep 17 00:00:00 2001 From: "Gavin D. Howard" Date: Sun, 22 Dec 2019 04:09:05 -0700 Subject: [PATCH] Make context title and summary changeable (#329) * Make context title and summary changeable Closes #30 * Fix checkboxes on context settings page So...I am new to Qt, and I forgot that checkboxes can have a label. Duh. Fixed. * Put context settings in a different place * Put ReplaceMessage and ReplaceVariable in Utilities --- src/CMakeLists.txt | 3 + src/context/contextview.cpp | 54 ++-- src/context/contextview.h | 4 +- src/context/contextviewcontainer.ui | 2 +- src/core/mainwindow.cpp | 1 + src/core/utilities.cpp | 74 ++++++ src/core/utilities.h | 5 + src/settings/contextsettingspage.cpp | 154 +++++++++++ src/settings/contextsettingspage.h | 75 ++++++ src/settings/contextsettingspage.ui | 374 +++++++++++++++++++++++++++ src/settings/settingsdialog.cpp | 2 + src/settings/settingsdialog.h | 1 + src/widgets/osd.cpp | 93 ++----- src/widgets/osd.h | 3 +- 14 files changed, 744 insertions(+), 101 deletions(-) create mode 100644 src/settings/contextsettingspage.cpp create mode 100644 src/settings/contextsettingspage.h create mode 100644 src/settings/contextsettingspage.ui diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 52dc502d..487d652f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -242,6 +242,7 @@ set(SOURCES settings/behavioursettingspage.cpp settings/collectionsettingspage.cpp settings/backendsettingspage.cpp + settings/contextsettingspage.cpp settings/playlistsettingspage.cpp settings/networkproxysettingspage.cpp settings/appearancesettingspage.cpp @@ -427,6 +428,7 @@ set(HEADERS settings/behavioursettingspage.h settings/collectionsettingspage.h settings/backendsettingspage.h + settings/contextsettingspage.h settings/playlistsettingspage.h settings/networkproxysettingspage.h settings/appearancesettingspage.h @@ -524,6 +526,7 @@ set(UI settings/behavioursettingspage.ui settings/collectionsettingspage.ui settings/backendsettingspage.ui + settings/contextsettingspage.ui settings/playlistsettingspage.ui settings/networkproxysettingspage.ui settings/appearancesettingspage.ui diff --git a/src/context/contextview.cpp b/src/context/contextview.cpp index a06812c9..968448fc 100644 --- a/src/context/contextview.cpp +++ b/src/context/contextview.cpp @@ -62,6 +62,8 @@ #include "covermanager/albumcoverloader.h" #include "covermanager/currentalbumcoverloader.h" #include "lyrics/lyricsfetcher.h" +#include "settings/contextsettingspage.h" +#include "widgets/osd.h" #include "contextview.h" #include "contextalbumsmodel.h" @@ -69,8 +71,6 @@ using std::unique_ptr; -const char *ContextView::kSettingsGroup = "ContextView"; - ContextView::ContextView(QWidget *parent) : QWidget(parent), ui_(new Ui_ContextViewContainer), @@ -152,13 +152,7 @@ void ContextView::AddActions() { menu_->addActions(cover_actions); menu_->addSeparator(); - QSettings s; - s.beginGroup(kSettingsGroup); - action_show_data_->setChecked(s.value("show_data", true).toBool()); - action_show_output_->setChecked(s.value("show_output", true).toBool()); - action_show_albums_->setChecked(s.value("show_albums", false).toBool()); - action_show_lyrics_->setChecked(s.value("show_lyrics", true).toBool()); - s.endGroup(); + ReloadSettings(); connect(action_show_data_, SIGNAL(triggered()), this, SLOT(ActionShowData())); connect(action_show_output_, SIGNAL(triggered()), this, SLOT(ActionShowOutput())); @@ -207,6 +201,26 @@ void ContextView::SongChanged(const Song &song) { } +void ContextView::ReloadSettings() { + + QSettings s; + s.beginGroup(ContextSettingsPage::kSettingsGroup); + title_fmt_ = s.value(ContextSettingsPage::kSettingsTitleFmt, "%title% - %artist%").toString(); + summary_fmt_ = s.value(ContextSettingsPage::kSettingsSummaryFmt, "%album%").toString(); + action_show_data_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::TECHNICAL_DATA], true).toBool()); + action_show_output_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ENGINE_AND_DEVICE], true).toBool()); + action_show_albums_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ALBUMS_BY_ARTIST], false).toBool()); + action_show_lyrics_->setChecked(s.value(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::SONG_LYRICS], true).toBool()); + s.endGroup(); + + if (song_.is_valid()) { + SetSong(song_); + } + else { + UpdateNoSong(); + } +} + void ContextView::SetLabelEnabled(QLabel *label) { label->setEnabled(true); label->setVisible(true); @@ -269,7 +283,7 @@ void ContextView::SetSong(const Song &song) { "font: 11pt;" "font-weight: regular;" ); - ui_->label_play_top->setText( QString("%1 - %2
%3").arg(song.PrettyTitle().toHtmlEscaped(), song.artist().toHtmlEscaped(), song.album().toHtmlEscaped())); + ui_->label_play_top->setText(QString("%1
%2").arg(Utilities::ReplaceMessage(title_fmt_, song, "
"), Utilities::ReplaceMessage(summary_fmt_, song, "
"))); if (action_show_data_->isChecked()) { ui_->layout_play_data->setEnabled(true); @@ -447,9 +461,7 @@ void ContextView::SetSong(const Song &song) { void ContextView::UpdateSong(const Song &song) { - if (song.artist() != song_playing_.artist() || song.album() != song_playing_.album() || song.title() != song_playing_.title()) { - ui_->label_play_top->setText( QString("%1 - %2
%3").arg(song.PrettyTitle().toHtmlEscaped(), song.artist().toHtmlEscaped(), song.album().toHtmlEscaped())); - } + ui_->label_play_top->setText(QString("%1
%2").arg(Utilities::ReplaceMessage(title_fmt_, song, "
"), Utilities::ReplaceMessage(summary_fmt_, song, "
"))); if (action_show_data_->isChecked()) { if (song.filetype() != song_playing_.filetype()) ui_->filetype->setText(song.TextForFiletype()); @@ -657,24 +669,24 @@ void ContextView::AutomaticCoverSearchDone() { void ContextView::ActionShowData() { QSettings s; - s.beginGroup(kSettingsGroup); - s.setValue("show_data", action_show_data_->isChecked()); + s.beginGroup(ContextSettingsPage::kSettingsGroup); + s.setValue(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::TECHNICAL_DATA], action_show_data_->isChecked()); s.endGroup(); SetSong(song_); } void ContextView::ActionShowOutput() { QSettings s; - s.beginGroup(kSettingsGroup); - s.setValue("show_output", action_show_output_->isChecked()); + s.beginGroup(ContextSettingsPage::kSettingsGroup); + s.setValue(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ENGINE_AND_DEVICE], action_show_output_->isChecked()); s.endGroup(); SetSong(song_); } void ContextView::ActionShowAlbums() { QSettings s; - s.beginGroup(kSettingsGroup); - s.setValue("show_albums", action_show_albums_->isChecked()); + s.beginGroup(ContextSettingsPage::kSettingsGroup); + s.setValue(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::ALBUMS_BY_ARTIST], action_show_albums_->isChecked()); s.endGroup(); song_prev_ = Song(); SetSong(song_); @@ -682,8 +694,8 @@ void ContextView::ActionShowAlbums() { void ContextView::ActionShowLyrics() { QSettings s; - s.beginGroup(kSettingsGroup); - s.setValue("show_lyrics", action_show_lyrics_->isChecked()); + s.beginGroup(ContextSettingsPage::kSettingsGroup); + s.setValue(ContextSettingsPage::kSettingsGroupEnable[ContextSettingsPage::ContextSettingsOrder::SONG_LYRICS], action_show_lyrics_->isChecked()); s.endGroup(); SetSong(song_); if (lyrics_.isEmpty() && action_show_lyrics_->isChecked() && !song_.artist().isEmpty() && !song_.title().isEmpty()) { diff --git a/src/context/contextview.h b/src/context/contextview.h index 58daaa68..2d870335 100644 --- a/src/context/contextview.h +++ b/src/context/contextview.h @@ -71,9 +71,9 @@ class ContextView : public QWidget { void Stopped(); void Error(); void SongChanged(const Song &song); + void ReloadSettings(); private: - static const char *kSettingsGroup; Ui_ContextViewContainer *ui_; Application *app_; @@ -103,6 +103,8 @@ class ContextView : public QWidget { std::unique_ptr spinner_animation_; qint64 lyrics_id_; QString lyrics_; + QString title_fmt_; + QString summary_fmt_; void AddActions(); void SetLabelEnabled(QLabel *label); diff --git a/src/context/contextviewcontainer.ui b/src/context/contextviewcontainer.ui index d90399ee..614373b4 100644 --- a/src/context/contextviewcontainer.ui +++ b/src/context/contextviewcontainer.ui @@ -191,7 +191,7 @@ 16777215 - 70 + 700 diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 961c73a7..83880df1 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -955,6 +955,7 @@ void MainWindow::ReloadAllSettings() { app_->album_cover_loader()->ReloadSettings(); album_cover_choice_controller_->ReloadSettings(); if (cover_manager_.get()) cover_manager_->ReloadSettings(); + context_view_->ReloadSettings(); #ifdef HAVE_TIDAL tidal_view_->ReloadSettings(); #endif diff --git a/src/core/utilities.cpp b/src/core/utilities.cpp index 1a837b7b..0267e1f4 100644 --- a/src/core/utilities.cpp +++ b/src/core/utilities.cpp @@ -88,6 +88,7 @@ #endif #include "core/logging.h" +#include "core/song.h" #include "utilities.h" #include "timeconstants.h" @@ -849,6 +850,79 @@ QString MacAddress() { } +QString ReplaceMessage(const QString &message, const Song &song, const QString &newline) { + + QRegExp variable_replacer("[%][a-z]+[%]"); + QString copy(message); + + // Replace the first line + int pos = 0; + variable_replacer.indexIn(message); + while ((pos = variable_replacer.indexIn(message, pos)) != -1) { + QStringList captured = variable_replacer.capturedTexts(); + copy.replace(captured[0], ReplaceVariable(captured[0], song, newline)); + pos += variable_replacer.matchedLength(); + } + + return copy; +} + +QString ReplaceVariable(const QString &variable, const Song &song, const QString &newline) { + + QString return_value; + if (variable == "%artist%") { + return song.artist().toHtmlEscaped(); + } + else if (variable == "%album%") { + return song.album().toHtmlEscaped(); + } + else if (variable == "%title%") { + return song.PrettyTitle().toHtmlEscaped(); + } + else if (variable == "%albumartist%") { + return song.effective_albumartist().toHtmlEscaped(); + } + else if (variable == "%year%") { + return song.PrettyYear().toHtmlEscaped(); + } + else if (variable == "%composer%") { + return song.composer().toHtmlEscaped(); + } + else if (variable == "%performer%") { + return song.performer().toHtmlEscaped(); + } + else if (variable == "%grouping%") { + return song.grouping().toHtmlEscaped(); + } + else if (variable == "%length%") { + return song.PrettyLength().toHtmlEscaped(); + } + else if (variable == "%disc%") { + return return_value.setNum(song.disc()).toHtmlEscaped(); + } + else if (variable == "%track%") { + return return_value.setNum(song.track()).toHtmlEscaped(); + } + else if (variable == "%genre%") { + return song.genre().toHtmlEscaped(); + } + else if (variable == "%playcount%") { + return return_value.setNum(song.playcount()).toHtmlEscaped(); + } + else if (variable == "%skipcount%") { + return return_value.setNum(song.skipcount()).toHtmlEscaped(); + } + else if (variable == "%filename%") { + return song.basefilename().toHtmlEscaped(); + } + else if (variable == "%newline%") { + return QString(newline); + } + + //if the variable is not recognized, just return it + return variable; +} + } // namespace Utilities ScopedWCharArray::ScopedWCharArray(const QString &str) diff --git a/src/core/utilities.h b/src/core/utilities.h index ef87f47d..58f19b1c 100644 --- a/src/core/utilities.h +++ b/src/core/utilities.h @@ -44,6 +44,8 @@ #include #include +#include "core/song.h" + namespace Utilities { QString PrettyTime(int seconds); QString PrettyTimeDelta(int seconds); @@ -156,6 +158,9 @@ QString UnicodeToAscii(const QString &unicode); QString MacAddress(); +QString ReplaceMessage(const QString &message, const Song &song, const QString &newline); +QString ReplaceVariable(const QString &variable, const Song &song, const QString &newline); + } // namespace class ScopedWCharArray { diff --git a/src/settings/contextsettingspage.cpp b/src/settings/contextsettingspage.cpp new file mode 100644 index 00000000..b063924d --- /dev/null +++ b/src/settings/contextsettingspage.cpp @@ -0,0 +1,154 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * Copyright 2018-2019, Jonas Kvinge + * + * Strawberry 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 3 of the License, or + * (at your option) any later version. + * + * Strawberry 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 Strawberry. If not, see . + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core/iconloader.h" +#include "settingspage.h" +#include "settingsdialog.h" +#include "contextsettingspage.h" +#include "ui_contextsettingspage.h" + +const char *ContextSettingsPage::kSettingsGroup = "Context"; +const char *ContextSettingsPage::kSettingsTitleFmt = "TitleFmt"; +const char *ContextSettingsPage::kSettingsSummaryFmt = "SummaryFmt"; +const char *ContextSettingsPage::kSettingsGroupLabels[ContextSettingsOrder::NELEMS] = { + "Technical Data", + "Engine and Device", + "Albums by Artist", + "Song Lyrics", +}; +const char *ContextSettingsPage::kSettingsGroupEnable[ContextSettingsOrder::NELEMS] = { + "TechnicalDataEnable", + "EngineAndDeviceEnable", + "AlbumsByArtistEnable", + "SongLyricsEnable", +}; + +ContextSettingsPage::ContextSettingsPage(SettingsDialog* dialog) + : SettingsPage(dialog), ui_(new Ui_ContextSettingsPage) { + ui_->setupUi(this); + setWindowIcon(IconLoader::Load("view-choose")); + + checkboxes[ContextSettingsOrder::TECHNICAL_DATA] = ui_->context_item1_enable; + checkboxes[ContextSettingsOrder::ENGINE_AND_DEVICE] = ui_->context_item2_enable; + checkboxes[ContextSettingsOrder::ALBUMS_BY_ARTIST] = ui_->context_item3_enable; + checkboxes[ContextSettingsOrder::SONG_LYRICS] = ui_->context_item4_enable; + + // Create and populate the helper menus + QMenu *menu = new QMenu(this); + menu->addAction(ui_->action_artist); + menu->addAction(ui_->action_album); + menu->addAction(ui_->action_title); + menu->addAction(ui_->action_albumartist); + menu->addAction(ui_->action_year); + menu->addAction(ui_->action_composer); + menu->addAction(ui_->action_performer); + menu->addAction(ui_->action_grouping); + menu->addAction(ui_->action_length); + menu->addAction(ui_->action_disc); + menu->addAction(ui_->action_track); + menu->addAction(ui_->action_genre); + menu->addAction(ui_->action_playcount); + menu->addAction(ui_->action_skipcount); + menu->addAction(ui_->action_filename); + menu->addAction(ui_->action_rating); + menu->addAction(ui_->action_score); + menu->addSeparator(); + menu->addAction(ui_->action_newline); + ui_->context_exp_chooser1->setMenu(menu); + ui_->context_exp_chooser2->setMenu(menu); + ui_->context_exp_chooser1->setPopupMode(QToolButton::InstantPopup); + ui_->context_exp_chooser2->setPopupMode(QToolButton::InstantPopup); + // We need this because by default menus don't show tooltips + connect(menu, SIGNAL(hovered(QAction*)), SLOT(ShowMenuTooltip(QAction*))); + + connect(ui_->context_exp_chooser1, SIGNAL(triggered(QAction*)), SLOT(InsertVariableFirstLine(QAction*))); + connect(ui_->context_exp_chooser2, SIGNAL(triggered(QAction*)), SLOT(InsertVariableSecondLine(QAction*))); + + // Icons + ui_->context_exp_chooser1->setIcon(IconLoader::Load("list-add")); + ui_->context_exp_chooser2->setIcon(IconLoader::Load("list-add")); + +} + +ContextSettingsPage::~ContextSettingsPage() +{ + delete ui_; +} + +void ContextSettingsPage::Load() { + + QSettings s; + + s.beginGroup(ContextSettingsPage::kSettingsGroup); + ui_->context_custom_text1->setText(s.value(kSettingsTitleFmt, "%title% - %artist%").toString()); + ui_->context_custom_text2->setText(s.value(kSettingsSummaryFmt, "%album%").toString()); + for (int i = 0; i < ContextSettingsOrder::NELEMS; ++i) { + checkboxes[i]->setChecked(s.value(kSettingsGroupEnable[i], i != ContextSettingsOrder::ALBUMS_BY_ARTIST).toBool()); + } + s.endGroup(); + +} + +void ContextSettingsPage::Save() { + + QSettings s; + + s.beginGroup(kSettingsGroup); + s.setValue(kSettingsTitleFmt, ui_->context_custom_text1->text()); + s.setValue(kSettingsSummaryFmt, ui_->context_custom_text2->text()); + for (int i = 0; i < ContextSettingsOrder::NELEMS; ++i) { + s.setValue(kSettingsGroupEnable[i], checkboxes[i]->isChecked()); + } + s.endGroup(); + +} + +void ContextSettingsPage::InsertVariableFirstLine(QAction* action) { + // We use action name, therefore those shouldn't be translatable + ui_->context_custom_text1->insert(action->text()); +} + +void ContextSettingsPage::InsertVariableSecondLine(QAction* action) { + // We use action name, therefore those shouldn't be translatable + ui_->context_custom_text2->insert(action->text()); +} + +void ContextSettingsPage::ShowMenuTooltip(QAction* action) { + QToolTip::showText(QCursor::pos(), action->toolTip()); +} diff --git a/src/settings/contextsettingspage.h b/src/settings/contextsettingspage.h new file mode 100644 index 00000000..c07c17ce --- /dev/null +++ b/src/settings/contextsettingspage.h @@ -0,0 +1,75 @@ +/* + * Strawberry Music Player + * This file was part of Clementine. + * Copyright 2010, David Sansome + * Copyright 2018-2019, Jonas Kvinge + * + * Strawberry 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 3 of the License, or + * (at your option) any later version. + * + * Strawberry 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 Strawberry. If not, see . + * + */ + +#ifndef CONTEXTSETTINGSPAGE_H +#define CONTEXTSETTINGSPAGE_H + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "settingspage.h" + +class SettingsDialog; +class Ui_ContextSettingsPage; + +class ContextSettingsPage : public SettingsPage +{ + Q_OBJECT + +public: + ContextSettingsPage(SettingsDialog *dialog); + ~ContextSettingsPage(); + + enum ContextSettingsOrder { + TECHNICAL_DATA, + ENGINE_AND_DEVICE, + ALBUMS_BY_ARTIST, + SONG_LYRICS, + NELEMS, + }; + + static const char *kSettingsGroup; + static const char *kSettingsTitleFmt; + static const char *kSettingsSummaryFmt; + static const char *kSettingsGroupLabels[ContextSettingsOrder::NELEMS]; + static const char *kSettingsGroupEnable[ContextSettingsOrder::NELEMS]; + + void Load(); + void Save(); + +private slots: + void InsertVariableFirstLine(QAction *action); + void InsertVariableSecondLine(QAction *action); + void ShowMenuTooltip(QAction *action); + +private: + Ui_ContextSettingsPage *ui_; + QCheckBox *checkboxes[ContextSettingsOrder::NELEMS]; +}; + +#endif // CONTEXTSETTINGSPAGE_H diff --git a/src/settings/contextsettingspage.ui b/src/settings/contextsettingspage.ui new file mode 100644 index 00000000..8e724fe7 --- /dev/null +++ b/src/settings/contextsettingspage.ui @@ -0,0 +1,374 @@ + + + ContextSettingsPage + + + + 0 + 0 + 526 + 733 + + + + Context + + + + + + Custom text settings + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + 0 + + + 0 + + + + + %title - %artist% + + + + + + + + + + + + + + Title + + + + + + + Summary + + + + + + + %album% + + + + + + + + + + + + + + + + + + + + Enable Items + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + 0 + + + 0 + + + + + Technical Data + + + true + + + + + + + Engine and Device + + + true + + + + + + + Albums by Artist + + + true + + + + + + + Song Lyrics + + + true + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 32 + + + + + + + + %artist% + + + Add song artist tag + + + + + %album% + + + Add song album tag + + + + + %title% + + + Add song title tag + + + + + %albumartist% + + + Add song albumartist tag + + + + + %year% + + + Add song year tag + + + + + %composer% + + + Add song composer tag + + + + + %performer% + + + Add song performer tag + + + + + %grouping% + + + Add song grouping tag + + + + + %disc% + + + Add song disc tag + + + + + %track% + + + Add song track tag + + + + + %genre% + + + Add song genre tag + + + + + %length% + + + Add song length tag + + + + + %playcount% + + + Add song play count + + + + + %skipcount% + + + Add song skip count + + + + + %rating% + + + Add song rating + + + + + %score% + + + Add song auto score + + + + + %newline% + + + Add a new line if supported by the notification type + + + + + %filename% + + + Add song filename + + + + + + diff --git a/src/settings/settingsdialog.cpp b/src/settings/settingsdialog.cpp index 4c89d6de..ed492356 100644 --- a/src/settings/settingsdialog.cpp +++ b/src/settings/settingsdialog.cpp @@ -49,6 +49,7 @@ #include "appearancesettingspage.h" #include "backendsettingspage.h" #include "behavioursettingspage.h" +#include "contextsettingspage.h" #include "collectionsettingspage.h" #include "notificationssettingspage.h" #include "playlistsettingspage.h" @@ -130,6 +131,7 @@ SettingsDialog::SettingsDialog(Application *app, QWidget *parent) QTreeWidgetItem *iface = AddCategory(tr("User interface")); AddPage(Page_Appearance, new AppearanceSettingsPage(this), iface); + AddPage(Page_Context, new ContextSettingsPage(this), iface); AddPage(Page_Notifications, new NotificationsSettingsPage(this), iface); #ifdef HAVE_GLOBALSHORTCUTS diff --git a/src/settings/settingsdialog.h b/src/settings/settingsdialog.h index a74ec000..356bcc6d 100644 --- a/src/settings/settingsdialog.h +++ b/src/settings/settingsdialog.h @@ -75,6 +75,7 @@ class SettingsDialog : public QDialog { Page_Playlist, Page_GlobalShortcuts, Page_Appearance, + Page_Context, Page_Notifications, Page_Transcoding, Page_Proxy, diff --git a/src/widgets/osd.cpp b/src/widgets/osd.cpp index dfcc562b..ba55f024 100644 --- a/src/widgets/osd.cpp +++ b/src/widgets/osd.cpp @@ -43,6 +43,7 @@ #include "core/application.h" #include "core/logging.h" #include "core/systemtrayicon.h" +#include "core/utilities.h" #include "covermanager/currentalbumcoverloader.h" const char *OSD::kSettingsGroup = "OSD"; @@ -141,28 +142,8 @@ void OSD::AlbumCoverLoaded(const Song &song, const QUrl &cover_url, const QImage message_parts << tr("track %1").arg(song.track()); } else { - QRegExp variable_replacer("[%][a-z]+[%]"); - summary = custom_text1_; - QString message(custom_text2_); - - // Replace the first line - int pos = 0; - variable_replacer.indexIn(custom_text1_); - while ((pos = variable_replacer.indexIn(custom_text1_, pos)) != -1) { - QStringList captured = variable_replacer.capturedTexts(); - summary.replace(captured[0], ReplaceVariable(captured[0], song)); - pos += variable_replacer.matchedLength(); - } - - // Replace the second line - pos = 0; - variable_replacer.indexIn(custom_text2_); - while ((pos = variable_replacer.indexIn(custom_text2_, pos)) != -1) { - QStringList captured = variable_replacer.capturedTexts(); - message.replace(captured[0], ReplaceVariable(captured[0], song)); - pos += variable_replacer.matchedLength(); - } - message_parts << message; + summary = ReplaceMessage(custom_text1_, song); + message_parts << ReplaceMessage(custom_text2_, song); } if (show_art_) { @@ -291,81 +272,39 @@ void OSD::RepeatModeChanged(PlaylistSequence::RepeatMode mode) { } } -QString OSD::ReplaceVariable(const QString &variable, const Song &song) { +QString OSD::ReplaceMessage(const QString &message, const Song &song) { - QString return_value; - if (variable == "%artist%") { - return song.artist(); - } - else if (variable == "%album%") { - return song.album(); - } - else if (variable == "%title%") { - return song.PrettyTitle(); - } - else if (variable == "%albumartist%") { - return song.effective_albumartist(); - } - else if (variable == "%year%") { - return song.PrettyYear(); - } - else if (variable == "%composer%") { - return song.composer(); - } - else if (variable == "%performer%") { - return song.performer(); - } - else if (variable == "%grouping%") { - return song.grouping(); - } - else if (variable == "%length%") { - return song.PrettyLength(); - } - else if (variable == "%disc%") { - return return_value.setNum(song.disc()); - } - else if (variable == "%track%") { - return return_value.setNum(song.track()); - } - else if (variable == "%genre%") { - return song.genre(); - } - else if (variable == "%playcount%") { - return return_value.setNum(song.playcount()); - } - else if (variable == "%skipcount%") { - return return_value.setNum(song.skipcount()); - } - else if (variable == "%filename%") { - return song.basefilename(); - } - else if (variable == "%newline%") { + QString newline = "
"; + + if (message.indexOf("%newline%") != -1) { // We need different strings depending on notification type switch (behaviour_) { case Native: #ifdef Q_OS_MACOS - return "\n"; + newline = "\n"; + break; #endif #ifdef Q_OS_LINUX - return "
"; + break; #endif #ifdef Q_OS_WIN32 // Other OS don't support native notifications qLog(Debug) << "New line not supported by this notification type under Windows"; - return ""; + newline = ""; + break; #endif case TrayPopup: qLog(Debug) << "New line not supported by this notification type"; - return ""; + newline = ""; + break; case Pretty: default: // When notifications are disabled, we force the PrettyOSD - return "
"; + break; } } - //if the variable is not recognized, just return it - return variable; + return Utilities::ReplaceMessage(message, song, newline); } void OSD::ShowPreview(const Behaviour type, const QString &line1, const QString &line2, const Song &song) { diff --git a/src/widgets/osd.h b/src/widgets/osd.h index 5c55bf31..b977e0e4 100644 --- a/src/widgets/osd.h +++ b/src/widgets/osd.h @@ -95,10 +95,11 @@ class OSD : public QObject { private: void ShowMessage(const QString &summary, const QString &message = QString(), const QString icon = QString("strawberry"), const QImage &image = QImage()); + QString ReplaceMessage(const QString &message, const Song &song); + // These are implemented in the OS-specific files void Init(); void ShowMessageNative(const QString &summary, const QString &message, const QString &icon = QString(), const QImage &image = QImage()); - QString ReplaceVariable(const QString &variable, const Song &song); private slots: #ifdef HAVE_DBUS