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
This commit is contained in:
Gavin D. Howard 2019-12-22 04:09:05 -07:00 committed by Jonas Kvinge
parent a19ea8fdba
commit 079a559247
14 changed files with 744 additions and 101 deletions

View File

@ -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

View File

@ -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("<b>%1 - %2</b><br/>%3").arg(song.PrettyTitle().toHtmlEscaped(), song.artist().toHtmlEscaped(), song.album().toHtmlEscaped()));
ui_->label_play_top->setText(QString("<b>%1</b><br/>%2").arg(Utilities::ReplaceMessage(title_fmt_, song, "<br/>"), Utilities::ReplaceMessage(summary_fmt_, song, "<br/>")));
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("<b>%1 - %2</b><br/>%3").arg(song.PrettyTitle().toHtmlEscaped(), song.artist().toHtmlEscaped(), song.album().toHtmlEscaped()));
}
ui_->label_play_top->setText(QString("<b>%1</b><br/>%2").arg(Utilities::ReplaceMessage(title_fmt_, song, "<br/>"), Utilities::ReplaceMessage(summary_fmt_, song, "<br/>")));
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()) {

View File

@ -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<QMovie> spinner_animation_;
qint64 lyrics_id_;
QString lyrics_;
QString title_fmt_;
QString summary_fmt_;
void AddActions();
void SetLabelEnabled(QLabel *label);

View File

@ -191,7 +191,7 @@
<property name="maximumSize">
<size>
<width>16777215</width>
<height>70</height>
<height>700</height>
</size>
</property>
<property name="text">

View File

@ -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

View File

@ -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)

View File

@ -44,6 +44,8 @@
#include <QXmlStreamReader>
#include <QtEvents>
#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 {

View File

@ -0,0 +1,154 @@
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2018-2019, Jonas Kvinge <jonas@jkvinge.net>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QtGlobal>
#include <QAction>
#include <QVariant>
#include <QImage>
#include <QMenu>
#include <QCursor>
#include <QGroupBox>
#include <QLabel>
#include <QCheckBox>
#include <QPushButton>
#include <QSpinBox>
#include <QToolButton>
#include <QToolTip>
#include <QtEvents>
#include <QSettings>
#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());
}

View File

@ -0,0 +1,75 @@
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2018-2019, Jonas Kvinge <jonas@jkvinge.net>
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#ifndef CONTEXTSETTINGSPAGE_H
#define CONTEXTSETTINGSPAGE_H
#include "config.h"
#include <stdbool.h>
#include <QObject>
#include <QString>
#include <QAction>
#include <QtEvents>
#include <QCheckBox>
#include <QLabel>
#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

View File

@ -0,0 +1,374 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ContextSettingsPage</class>
<widget class="QWidget" name="ContextSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>526</width>
<height>733</height>
</rect>
</property>
<property name="windowTitle">
<string>Context</string>
</property>
<layout class="QVBoxLayout" name="layout_contextsettingspage">
<item>
<widget class="QGroupBox" name="context_custom_text_group">
<property name="title">
<string>Custom text settings</string>
</property>
<layout class="QVBoxLayout" name="layout_context_custom_text_group">
<item>
<widget class="QFrame" name="frame_custom_context1">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<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>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame1">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout1">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QLineEdit" name="context_custom_text1">
<property name="text">
<string>%title - %artist%</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="context_exp_chooser1">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_title">
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_summary">
<property name="text">
<string>Summary</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="context_custom_text2">
<property name="text">
<string>%album%</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="context_exp_chooser2">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="context_order_group">
<property name="title">
<string>Enable Items</string>
</property>
<layout class="QVBoxLayout" name="layout_context_order_group">
<item>
<widget class="QFrame" name="frame_custom_context2">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_17">
<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>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame2">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout2">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QCheckBox" name="context_item1_enable">
<property name="text">
<string>Technical Data</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="context_item2_enable">
<property name="text">
<string>Engine and Device</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="context_item3_enable">
<property name="text">
<string>Albums by Artist</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="context_item4_enable">
<property name="text">
<string>Song Lyrics</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="spacer_bottom">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>32</height>
</size>
</property>
</spacer>
</item>
</layout>
<action name="action_artist">
<property name="text">
<string notr="true">%artist%</string>
</property>
<property name="toolTip">
<string>Add song artist tag</string>
</property>
</action>
<action name="action_album">
<property name="text">
<string notr="true">%album%</string>
</property>
<property name="toolTip">
<string>Add song album tag</string>
</property>
</action>
<action name="action_title">
<property name="text">
<string notr="true">%title%</string>
</property>
<property name="toolTip">
<string>Add song title tag</string>
</property>
</action>
<action name="action_albumartist">
<property name="text">
<string notr="true">%albumartist%</string>
</property>
<property name="toolTip">
<string>Add song albumartist tag</string>
</property>
</action>
<action name="action_year">
<property name="text">
<string notr="true">%year%</string>
</property>
<property name="toolTip">
<string>Add song year tag</string>
</property>
</action>
<action name="action_composer">
<property name="text">
<string notr="true">%composer%</string>
</property>
<property name="toolTip">
<string>Add song composer tag</string>
</property>
</action>
<action name="action_performer">
<property name="text">
<string notr="true">%performer%</string>
</property>
<property name="toolTip">
<string>Add song performer tag</string>
</property>
</action>
<action name="action_grouping">
<property name="text">
<string notr="true">%grouping%</string>
</property>
<property name="toolTip">
<string>Add song grouping tag</string>
</property>
</action>
<action name="action_disc">
<property name="text">
<string notr="true">%disc%</string>
</property>
<property name="toolTip">
<string>Add song disc tag</string>
</property>
</action>
<action name="action_track">
<property name="text">
<string notr="true">%track%</string>
</property>
<property name="toolTip">
<string>Add song track tag</string>
</property>
</action>
<action name="action_genre">
<property name="text">
<string notr="true">%genre%</string>
</property>
<property name="toolTip">
<string>Add song genre tag</string>
</property>
</action>
<action name="action_length">
<property name="text">
<string notr="true">%length%</string>
</property>
<property name="toolTip">
<string>Add song length tag</string>
</property>
</action>
<action name="action_playcount">
<property name="text">
<string notr="true">%playcount%</string>
</property>
<property name="toolTip">
<string>Add song play count</string>
</property>
</action>
<action name="action_skipcount">
<property name="text">
<string notr="true">%skipcount%</string>
</property>
<property name="toolTip">
<string>Add song skip count</string>
</property>
</action>
<action name="action_rating">
<property name="text">
<string notr="true">%rating%</string>
</property>
<property name="toolTip">
<string>Add song rating</string>
</property>
</action>
<action name="action_score">
<property name="text">
<string notr="true">%score%</string>
</property>
<property name="toolTip">
<string>Add song auto score</string>
</property>
</action>
<action name="action_newline">
<property name="text">
<string notr="true">%newline%</string>
</property>
<property name="toolTip">
<string>Add a new line if supported by the notification type</string>
</property>
</action>
<action name="action_filename">
<property name="text">
<string>%filename%</string>
</property>
<property name="toolTip">
<string>Add song filename</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -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

View File

@ -75,6 +75,7 @@ class SettingsDialog : public QDialog {
Page_Playlist,
Page_GlobalShortcuts,
Page_Appearance,
Page_Context,
Page_Notifications,
Page_Transcoding,
Page_Proxy,

View File

@ -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 = "<br/>";
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 "<br/>";
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 "<br/>";
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) {

View File

@ -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