00001
00002 #include <QString>
00003 #include <QDir>
00004
00005
00006 #include <mythcorecontext.h>
00007
00008 #include "generalsettings.h"
00009
00010 GeneralSettings::GeneralSettings(MythScreenStack *parent, const char *name)
00011 : MythScreenType(parent, name),
00012 m_musicLocation(NULL), m_musicAudioDevice(NULL),
00013 m_musicDefaultUpmix(NULL), m_musicCDDevice(NULL),
00014 m_nonID3FileNameFormat(NULL), m_ignoreID3Tags(NULL),
00015 m_tagEncoding(NULL), m_allowTagWriting(NULL),
00016 m_saveButton(NULL), m_cancelButton(NULL)
00017 {
00018 }
00019
00020 GeneralSettings::~GeneralSettings()
00021 {
00022
00023 }
00024
00025 bool GeneralSettings::Create()
00026 {
00027 bool err = false;
00028
00029
00030 if (!LoadWindowFromXML("musicsettings-ui.xml", "generalsettings", this))
00031 return false;
00032
00033 UIUtilE::Assign(this, m_musicLocation, "musiclocation", &err);
00034 UIUtilE::Assign(this, m_musicAudioDevice, "musicaudiodevice", &err);
00035 UIUtilE::Assign(this, m_musicDefaultUpmix, "musicdefaultupmix", &err);
00036 UIUtilE::Assign(this, m_musicCDDevice, "musiccddevice", &err);
00037 UIUtilE::Assign(this, m_nonID3FileNameFormat, "nonid3filenameformat", &err);
00038 UIUtilE::Assign(this, m_ignoreID3Tags, "ignoreid3tags", &err);
00039 UIUtilE::Assign(this, m_tagEncoding, "tagencoding", &err);
00040 UIUtilE::Assign(this, m_allowTagWriting, "allowtagwriting", &err);
00041 UIUtilE::Assign(this, m_saveButton, "save", &err);
00042 UIUtilE::Assign(this, m_cancelButton, "cancel", &err);
00043
00044 if (err)
00045 {
00046 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'generalsettings'");
00047 return false;
00048 }
00049
00050 m_musicLocation->SetText(gCoreContext->GetSetting("MusicLocation"));
00051 m_musicAudioDevice->SetText(gCoreContext->GetSetting("MusicAudioDevice"));
00052
00053 int loadMusicDefaultUpmix = gCoreContext->GetNumSetting("MusicDefaultUpmix", 0);
00054 if (loadMusicDefaultUpmix == 1)
00055 m_musicDefaultUpmix->SetCheckState(MythUIStateType::Full);
00056
00057 m_musicCDDevice->SetText(gCoreContext->GetSetting("CDDevice"));
00058
00059 m_nonID3FileNameFormat->SetText(gCoreContext->GetSetting("NonID3FileNameFormat"));
00060
00061 int loadIgnoreTags = gCoreContext->GetNumSetting("Ignore_ID3", 0);
00062 if (loadIgnoreTags == 1)
00063 m_ignoreID3Tags->SetCheckState(MythUIStateType::Full);
00064
00065 new MythUIButtonListItem(m_tagEncoding, tr("UTF-16"), qVariantFromValue(QString("utf16")));
00066 new MythUIButtonListItem(m_tagEncoding, tr("UTF-8"), qVariantFromValue(QString("utf8")));
00067 new MythUIButtonListItem(m_tagEncoding, tr("ASCII"), qVariantFromValue(QString("ascii")));
00068 m_tagEncoding->SetValueByData(gCoreContext->GetSetting("MusicTagEncoding"));
00069
00070 int allowTagWriting = gCoreContext->GetNumSetting("AllowTagWriting", 1);
00071 if (allowTagWriting == 1)
00072 m_allowTagWriting->SetCheckState(MythUIStateType::Full);
00073
00074 connect(m_saveButton, SIGNAL(Clicked()), this, SLOT(slotSave()));
00075 connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(Close()));
00076
00077 m_musicLocation->SetHelpText(tr("This directory must exist, and the user "
00078 "running MythMusic needs to have write permission "
00079 "to the directory."));
00080 m_musicAudioDevice->SetHelpText(tr("Audio Device used for playback. 'default' "
00081 "will use the device specified in MythTV"));
00082 m_musicDefaultUpmix->SetHelpText(tr("MythTV can upconvert stereo tracks to 5.1 audio. "
00083 "Set this option to enable it by default. "
00084 "You can enable or disable the upconversion "
00085 "during playback at anytime."));
00086 m_musicCDDevice->SetHelpText(tr("CD-ROM device used for ripping/playback."));
00087 m_nonID3FileNameFormat->SetHelpText(tr("Directory and filename format used to grab "
00088 "information if no ID3 information is found. Accepts "
00089 "GENRE, ARTIST, ALBUM, TITLE, ARTIST_TITLE and "
00090 "TRACK_TITLE."));
00091 m_ignoreID3Tags->SetHelpText(tr("If set, MythMusic will skip checking ID3 tags "
00092 "in files and just try to determine Genre, Artist, "
00093 "Album, and Track number and title from the "
00094 "filename."));
00095 m_tagEncoding->SetHelpText(tr("Some MP3 players don't understand tags encoded in UTF-8 "
00096 "or UTF-16, this setting allows you to change the encoding "
00097 "format used. Currently applies only to ID3 tags."));
00098 m_allowTagWriting->SetHelpText(tr("If set, MythMusic will be allowed to update the "
00099 "metadata in the file (e.g. ID3) to match the "
00100 "database. This means allowing MythTV to write "
00101 "to the file and permissions must be set "
00102 "accordingly. Features such as ID3 playcounts "
00103 "and ratings depend on this being enabled."));
00104 m_cancelButton->SetHelpText(tr("Exit without saving settings"));
00105 m_saveButton->SetHelpText(tr("Save settings and Exit"));
00106
00107 BuildFocusList();
00108
00109 SetFocusWidget(m_musicLocation);
00110
00111 return true;
00112 }
00113
00114 void GeneralSettings::slotSave(void)
00115 {
00116
00117
00118 QString dir = m_musicLocation->GetText();
00119
00120 if (!dir.isEmpty())
00121 {
00122 dir = QDir::cleanPath(dir);
00123 if (!dir.endsWith("/"))
00124 dir += "/";
00125 }
00126
00127 gCoreContext->SaveSetting("MusicLocation", dir);
00128 gCoreContext->SaveSetting("CDDevice", m_musicCDDevice->GetText());
00129 gCoreContext->SaveSetting("MusicAudioDevice", m_musicAudioDevice->GetText());
00130 gCoreContext->SaveSetting("NonID3FileNameFormat", m_nonID3FileNameFormat->GetText());
00131 gCoreContext->SaveSetting("MusicTagEncoding", m_tagEncoding->GetValue());
00132
00133 int saveMusicDefaultUpmix = (m_musicDefaultUpmix->GetCheckState() == MythUIStateType::Full) ? 1 : 0;
00134 gCoreContext->SaveSetting("MusicDefaultUpmix", saveMusicDefaultUpmix);
00135
00136 int saveIgnoreTags = (m_ignoreID3Tags->GetCheckState() == MythUIStateType::Full) ? 1 : 0;
00137 gCoreContext->SaveSetting("Ignore_ID3", saveIgnoreTags);
00138
00139 int allowTagWriting = (m_allowTagWriting->GetCheckState() == MythUIStateType::Full) ? 1 : 0;
00140 gCoreContext->SaveSetting("AllowTagWriting", allowTagWriting);
00141
00142 gCoreContext->dispatch(MythEvent(QString("MUSIC_SETTINGS_CHANGED GENERAL_SETTINGS")));
00143
00144 Close();
00145 }