MythTV  master
generalsettings.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QString>
3 #include <QDir>
4 
5 // MythTV
6 #include <mythcorecontext.h>
7 #include <mythdialogbox.h>
8 
9 // MythMusic
10 #include "musicplayer.h"
11 #include "generalsettings.h"
12 #include "musicdata.h"
13 
15 {
16  bool err = false;
17 
18  // Load the theme for this screen
19  if (!LoadWindowFromXML("musicsettings-ui.xml", "generalsettings", this))
20  return false;
21 
22  UIUtilE::Assign(this, m_musicAudioDevice, "musicaudiodevice", &err);
23  UIUtilE::Assign(this, m_musicDefaultUpmix, "musicdefaultupmix", &err);
24  UIUtilE::Assign(this, m_musicCDDevice, "musiccddevice", &err);
25  UIUtilE::Assign(this, m_nonID3FileNameFormat, "nonid3filenameformat", &err);
26  UIUtilE::Assign(this, m_ignoreID3Tags, "ignoreid3tags", &err);
27  UIUtilE::Assign(this, m_allowTagWriting, "allowtagwriting", &err);
28  UIUtilW::Assign(this, m_resetDBButton, "resetdatabase", &err);
29  UIUtilE::Assign(this, m_saveButton, "save", &err);
30  UIUtilE::Assign(this, m_cancelButton, "cancel", &err);
31 
32  if (err)
33  {
34  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'generalsettings'");
35  return false;
36  }
37 
38  m_musicAudioDevice->SetText(gCoreContext->GetSetting("MusicAudioDevice"));
39 
40  int loadMusicDefaultUpmix = gCoreContext->GetNumSetting("MusicDefaultUpmix", 0);
41  if (loadMusicDefaultUpmix == 1)
43 
45 
46  m_nonID3FileNameFormat->SetText(gCoreContext->GetSetting("NonID3FileNameFormat"));
47 
48  int loadIgnoreTags = gCoreContext->GetNumSetting("Ignore_ID3", 0);
49  if (loadIgnoreTags == 1)
51 
52  int allowTagWriting = gCoreContext->GetNumSetting("AllowTagWriting", 0);
53  if (allowTagWriting == 1)
55 
56  if (m_resetDBButton)
57  connect(m_resetDBButton, SIGNAL(Clicked()), this, SLOT(slotResetDB()));
58 
59  connect(m_saveButton, SIGNAL(Clicked()), this, SLOT(slotSave()));
60  connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Close()));
61 
62  m_musicAudioDevice->SetHelpText(tr("Audio Device used for playback. 'default' "
63  "will use the device specified in MythTV"));
64  m_musicDefaultUpmix->SetHelpText(tr("MythTV can upconvert stereo tracks to 5.1 audio. "
65  "Set this option to enable it by default. "
66  "You can enable or disable the upconversion "
67  "during playback at anytime."));
68  m_musicCDDevice->SetHelpText(tr("CD-ROM device used for ripping/playback."));
69  m_nonID3FileNameFormat->SetHelpText(tr("Directory and filename format used to grab "
70  "information if no ID3 information is found. Accepts "
71  "GENRE, ARTIST, ALBUM, TITLE, ARTIST_TITLE and "
72  "TRACK_TITLE."));
73  m_ignoreID3Tags->SetHelpText(tr("If set, MythMusic will skip checking ID3 tags "
74  "in files and just try to determine Genre, Artist, "
75  "Album, and Track number and title from the "
76  "filename."));
77  m_allowTagWriting->SetHelpText(tr("If set, MythMusic will be allowed to update the "
78  "metadata in the file (e.g. ID3) to match the "
79  "database. This means allowing MythTV to write "
80  "to the file and permissions must be set "
81  "accordingly. Features such as ID3 playcounts "
82  "and ratings depend on this being enabled."));
83  if (m_resetDBButton)
84  m_resetDBButton->SetHelpText(tr("This will clear all the MythMusic database tables allowing "
85  "for a fresh start. NOTE: You may lose any manual or automatic changes made to "
86  "a tracks metadata like rating or playcount unless you told MythMusic to "
87  "write those to the tag."));
88  m_cancelButton->SetHelpText(tr("Exit without saving settings"));
89  m_saveButton->SetHelpText(tr("Save settings and Exit"));
90 
92 
94 
95  return true;
96 }
97 
99 {
100  ShowOkPopup(tr("Are you sure you want to reset the music database?"),
101  this, SLOT(slotDoResetDB(bool)), true);
102 }
103 
105 {
106  if (ok)
107  {
108  gPlayer->stop(true);
109 
110  MSqlQuery query(MSqlQuery::InitCon());
111 
112  query.prepare("TRUNCATE music_albumart");
113  if (!query.exec())
114  MythDB::DBError("resetting music_albumart table", query);
115 
116  query.prepare("TRUNCATE music_albums");
117  if (!query.exec())
118  MythDB::DBError("resetting music_albums table", query);
119 
120  query.prepare("TRUNCATE music_artists");
121  if (!query.exec())
122  MythDB::DBError("resetting music_artists table", query);
123 
124  query.prepare("TRUNCATE music_directories");
125  if (!query.exec())
126  MythDB::DBError("resetting music_directories table", query);
127 
128  query.prepare("TRUNCATE music_genres");
129  if (!query.exec())
130  MythDB::DBError("resetting music_genres table", query);
131 
132  query.prepare("TRUNCATE music_playlists");
133  if (!query.exec())
134  MythDB::DBError("resetting music_playlists table", query);
135 
136  query.prepare("TRUNCATE music_songs");
137  if (!query.exec())
138  MythDB::DBError("resetting music_songs table", query);
139 
140  query.prepare("TRUNCATE music_stats");
141  if (!query.exec())
142  MythDB::DBError("resetting music_stats table", query);
143 
145 
146  ShowOkPopup(tr("Music database has been cleared.\n"
147  "You must now scan, rip or import some tracks."));
148  }
149 }
150 
152 {
154  gCoreContext->SaveSetting("MusicAudioDevice", m_musicAudioDevice->GetText());
155  gCoreContext->SaveSetting("NonID3FileNameFormat", m_nonID3FileNameFormat->GetText());
156 
157  int saveMusicDefaultUpmix = (m_musicDefaultUpmix->GetCheckState() == MythUIStateType::Full) ? 1 : 0;
158  gCoreContext->SaveSetting("MusicDefaultUpmix", saveMusicDefaultUpmix);
159 
160  int saveIgnoreTags = (m_ignoreID3Tags->GetCheckState() == MythUIStateType::Full) ? 1 : 0;
161  gCoreContext->SaveSetting("Ignore_ID3", saveIgnoreTags);
162 
163  int allowTagWriting = (m_allowTagWriting->GetCheckState() == MythUIStateType::Full) ? 1 : 0;
164  gCoreContext->SaveSetting("AllowTagWriting", allowTagWriting);
165 
166  gCoreContext->dispatch(MythEvent(QString("MUSIC_SETTINGS_CHANGED GENERAL_SETTINGS")));
167 
168  Close();
169 }
MusicPlayer * gPlayer
Definition: musicplayer.cpp:35
MythUIStateType::StateType GetCheckState() const
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
MythUICheckBox * m_musicDefaultUpmix
void SaveSetting(const QString &key, int newValue)
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythUIButton * m_resetDBButton
void BuildFocusList(void)
virtual void Close()
This class is used as a container for messages.
Definition: mythevent.h:16
void SetHelpText(const QString &text)
Definition: mythuitype.h:150
MythUITextEdit * m_musicAudioDevice
QString GetSetting(const QString &key, const QString &defaultval="")
MythUICheckBox * m_allowTagWriting
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:534
void slotResetDB(void)
void stop(bool stopAll=false)
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
void SetText(const QString &text, bool moveCursor=true)
void dispatch(const MythEvent &event)
MythUIButton * m_cancelButton
MythUITextEdit * m_nonID3FileNameFormat
int GetNumSetting(const QString &key, int defaultval=0)
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:806
bool Create(void) override
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
MythUICheckBox * m_ignoreID3Tags
MusicData * gMusicData
Definition: musicdata.cpp:20
void SetCheckState(MythUIStateType::StateType state)
bool SetFocusWidget(MythUIType *widget=nullptr)
static void slotDoResetDB(bool ok)
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:602
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
void reloadMusic(void)
reload music after a scan, rip or import
Definition: musicdata.cpp:57
MythUITextEdit * m_musicCDDevice
QString GetText(void) const
MythUIButton * m_saveButton