MythTV  master
importsettings.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QString>
3 
4 // MythTV
5 #include <mythcorecontext.h>
6 
7 #include "importsettings.h"
8 
10 {
11  bool err = false;
12 
13  // Load the theme for this screen
14  if (!LoadWindowFromXML("musicsettings-ui.xml", "importsettings", this))
15  return false;
16 
17  UIUtilE::Assign(this, m_paranoiaLevel, "paranoialevel", &err);
18  UIUtilE::Assign(this, m_filenameTemplate, "filenametemplate", &err);
19  UIUtilE::Assign(this, m_noWhitespace, "nowhitespace", &err);
20  UIUtilE::Assign(this, m_postCDRipScript, "postcdripscript", &err);
21  UIUtilE::Assign(this, m_ejectCD, "ejectcd", &err);
22  UIUtilE::Assign(this, m_encoderType, "encodertype", &err);
23  UIUtilE::Assign(this, m_defaultRipQuality, "defaultripquality", &err);
24  UIUtilE::Assign(this, m_mp3UseVBR, "mp3usevbr", &err);
25  UIUtilE::Assign(this, m_saveButton, "save", &err);
26  UIUtilE::Assign(this, m_cancelButton, "cancel", &err);
27 
28  if (err)
29  {
30  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'importsettings'");
31  return false;
32  }
33 
34  new MythUIButtonListItem(m_paranoiaLevel, tr("Full"), qVariantFromValue(QString("Full")));
35  new MythUIButtonListItem(m_paranoiaLevel, tr("Faster"), qVariantFromValue(QString("Faster")));
37 
38  m_filenameTemplate->SetText(gCoreContext->GetSetting("FilenameTemplate"));
39 
40  int loadNoWhitespace = gCoreContext->GetNumSetting("NoWhitespace", 0);
41  if (loadNoWhitespace == 1)
43 
44  m_postCDRipScript->SetText(gCoreContext->GetSetting("PostCDRipScript"));
45 
46  int loadEjectCD = gCoreContext->GetNumSetting("EjectCDAfterRipping", 0);
47  if (loadEjectCD == 1)
49 
50  new MythUIButtonListItem(m_encoderType, tr("Ogg Vorbis"), qVariantFromValue(QString("ogg")));
51  new MythUIButtonListItem(m_encoderType, tr("Lame (MP3)"), qVariantFromValue(QString("mp3")));
53 
54  new MythUIButtonListItem(m_defaultRipQuality, tr("Low"), qVariantFromValue(0));
55  new MythUIButtonListItem(m_defaultRipQuality, tr("Medium"), qVariantFromValue(1));
56  new MythUIButtonListItem(m_defaultRipQuality, tr("High"), qVariantFromValue(2));
57  new MythUIButtonListItem(m_defaultRipQuality, tr("Perfect"), qVariantFromValue(3));
59 
60  int loadMp3UseVBR = gCoreContext->GetNumSetting("Mp3UseVBR", 0);
61  if (loadMp3UseVBR == 1)
63 
64  connect(m_saveButton, SIGNAL(Clicked()), this, SLOT(slotSave()));
65  connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Close()));
66 
67  m_paranoiaLevel->SetHelpText(tr("Paranoia level of the CD ripper. Set to "
68  "faster if you're not concerned about "
69  "possible errors in the audio."));
70  m_filenameTemplate->SetHelpText(tr("Defines the location/name for new "
71  "songs. Valid tokens are:\n"
72  "GENRE, ARTIST, ALBUM, TRACK, TITLE, YEAR"));
73  m_noWhitespace->SetHelpText(tr("If set, whitespace characters in filenames "
74  "will be replaced with underscore characters."));
75  m_postCDRipScript->SetHelpText(tr("If present this script will be executed "
76  "after a CD Rip is completed."));
77  m_ejectCD->SetHelpText(tr("If set, the CD tray will automatically open "
78  "after the CD has been ripped."));
79  m_encoderType->SetHelpText(tr("Audio encoder to use for CD ripping. "
80  "Note that the quality level 'Perfect' "
81  "will use the FLAC encoder."));
82  m_defaultRipQuality->SetHelpText(tr("Default quality for new CD rips."));
83  m_mp3UseVBR->SetHelpText(tr("If set, the MP3 encoder will use variable "
84  "bitrates (VBR) except for the low quality setting. "
85  "The Ogg encoder will always use variable bitrates."));
86  m_cancelButton->SetHelpText(tr("Exit without saving settings"));
87  m_saveButton->SetHelpText(tr("Save settings and Exit"));
88 
90 
92 
93  return true;
94 }
95 
96 bool ImportSettings::keyPressEvent(QKeyEvent *event)
97 {
98  if (GetFocusWidget()->keyPressEvent(event))
99  return true;
100 
101  return MythScreenType::keyPressEvent(event);
102 }
103 
105 {
106  gCoreContext->SaveSetting("ParanoiaLevel", m_paranoiaLevel->GetDataValue().toString());
107  gCoreContext->SaveSetting("FilenameTemplate", m_filenameTemplate->GetText());
108  gCoreContext->SaveSetting("PostCDRipScript", m_postCDRipScript->GetText());
109  gCoreContext->SaveSetting("EncoderType", m_encoderType->GetDataValue().toString());
110  gCoreContext->SaveSetting("DefaultRipQuality", m_defaultRipQuality->GetDataValue().toString());
111 
112  int saveNoWhitespace = (m_noWhitespace->GetCheckState() == MythUIStateType::Full) ? 1 : 0;
113  gCoreContext->SaveSetting("Ignore_ID3", saveNoWhitespace);
114 
115  int saveEjectCD = (m_ejectCD->GetCheckState() == MythUIStateType::Full) ? 1 : 0;
116  gCoreContext->SaveSetting("EjectCDAfterRipping", saveEjectCD);
117 
118  int saveMp3UseVBR = (m_mp3UseVBR->GetCheckState() == MythUIStateType::Full) ? 1 : 0;
119  gCoreContext->SaveSetting("Mp3UseVBR", saveMp3UseVBR);
120 
121  gCoreContext->dispatch(MythEvent(QString("MUSIC_SETTINGS_CHANGED IMPORT_SETTINGS")));
122 
123  Close();
124 }
MythUIButtonList * m_paranoiaLevel
MythUIStateType::StateType GetCheckState() const
MythUIButtonList * m_defaultRipQuality
void SaveSetting(const QString &key, int newValue)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
MythUICheckBox * m_noWhitespace
void slotSave(void)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythUIButton * m_cancelButton
void BuildFocusList(void)
MythUITextEdit * m_postCDRipScript
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
QString GetSetting(const QString &key, const QString &defaultval="")
QVariant GetDataValue() const
MythUITextEdit * m_filenameTemplate
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
bool Create(void) override
MythUIButton * m_saveButton
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
void SetText(const QString &text, bool moveCursor=true)
MythUIType * GetFocusWidget(void) const
void dispatch(const MythEvent &event)
MythUIButtonList * m_encoderType
int GetNumSetting(const QString &key, int defaultval=0)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void SetCheckState(MythUIStateType::StateType state)
bool SetFocusWidget(MythUIType *widget=nullptr)
MythUICheckBox * m_ejectCD
MythUICheckBox * m_mp3UseVBR
QString GetText(void) const
void SetValueByData(const QVariant &data)