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

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