MythTV master
themeselector.cpp
Go to the documentation of this file.
1// c++
2#include <cstdlib>
3#include <unistd.h>
4
5// qt
6#include <QDir>
7#include <QFile>
8#include <QFileInfo>
9#include <QKeyEvent>
10#include <QTextStream>
11#include <QCoreApplication>
12
13// myth
23
24// mytharchive
25#include "mythburn.h"
26#include "themeselector.h"
27
29 MythScreenStack *parent, MythScreenType *destinationScreen,
30 const ArchiveDestination& archiveDestination, const QString& name) :
31 MythScreenType(parent, name, true),
32 m_destinationScreen(destinationScreen),
33 m_archiveDestination(archiveDestination),
34 m_themeDir(GetShareDir() + "mytharchive/themes/")
35{
36}
37
39{
41}
42
44{
45 // Load the theme for this screen
46 bool foundtheme = LoadWindowFromXML("mythburn-ui.xml", "themeselector", this);
47 if (!foundtheme)
48 return false;
49
50 bool err = false;
51 UIUtilE::Assign(this, m_nextButton, "next_button", &err);
52 UIUtilE::Assign(this, m_prevButton, "prev_button", &err);
53 UIUtilE::Assign(this, m_cancelButton, "cancel_button", &err);
54
55 // theme preview images
56 UIUtilE::Assign(this, m_introImage, "intro_image", &err);
57 UIUtilE::Assign(this, m_mainmenuImage, "mainmenu_image", &err);
58 UIUtilE::Assign(this, m_chapterImage, "chapter_image", &err);
59 UIUtilE::Assign(this, m_detailsImage, "details_image", &err);
60
61 // menu theme
62 UIUtilE::Assign(this, m_themedescText, "themedescription", &err);
63 UIUtilE::Assign(this, m_themeImage, "theme_image", &err);
64 UIUtilE::Assign(this, m_themeSelector, "theme_selector", &err);
65
66 if (err)
67 {
68 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'themeselector'");
69 return false;
70 }
71
75
77
80
82
84
86
87 return true;
88}
89
90bool DVDThemeSelector::keyPressEvent(QKeyEvent *event)
91{
92 if (GetFocusWidget()->keyPressEvent(event))
93 return true;
94
96 return true;
97
98 return false;
99}
100
102{
104
105 // show next page
107
108 auto *burn = new MythBurn(mainStack, m_destinationScreen, this,
109 m_archiveDestination, "MythBurn");
110
111 if (burn->Create())
112 mainStack->AddScreen(burn);
113}
114
116{
117 Close();
118}
119
121{
123 Close();
124}
125
127{
128 m_themeList.clear();
129 QDir d;
130
131 d.setPath(m_themeDir);
132 if (d.exists())
133 {
134 QStringList filters;
135 filters << "*";
136 QFileInfoList list = d.entryInfoList(filters, QDir::Dirs, QDir::Name);
137
138 for (const auto & fi : std::as_const(list))
139 {
140 if (QFile::exists(m_themeDir + fi.fileName() + "/preview.png"))
141 {
142 m_themeList.append(fi.fileName());
143 QString filename = fi.fileName().replace(QString("_"), QString(" "));
145 }
146 }
147 }
148 else
149 {
150 LOG(VB_GENERAL, LOG_ERR,
151 "MythArchive: Theme directory does not exist!");
152 }
153}
154
156{
157 if (!item)
158 return;
159
160 int itemNo = m_themeSelector->GetCurrentPos();
161
162 if (itemNo < 0 || itemNo > m_themeList.size() - 1)
163 itemNo = 0;
164
165 m_themeNo = itemNo;
166
167 if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/preview.png"))
168 m_themeImage->SetFilename(m_themeDir + m_themeList[itemNo] + "/preview.png");
169 else
170 m_themeImage->SetFilename("blank.png");
172
173 if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/intro_preview.png"))
174 m_introImage->SetFilename(m_themeDir + m_themeList[itemNo] + "/intro_preview.png");
175 else
176 m_introImage->SetFilename("blank.png");
178
179 if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/mainmenu_preview.png"))
180 m_mainmenuImage->SetFilename(m_themeDir + m_themeList[itemNo] + "/mainmenu_preview.png");
181 else
182 m_mainmenuImage->SetFilename("blank.png");
184
185 if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/chaptermenu_preview.png"))
186 m_chapterImage->SetFilename(m_themeDir + m_themeList[itemNo] + "/chaptermenu_preview.png");
187 else
188 m_chapterImage->SetFilename("blank.png");
190
191 if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/details_preview.png"))
192 m_detailsImage->SetFilename(m_themeDir + m_themeList[itemNo] + "/details_preview.png");
193 else
194 m_detailsImage->SetFilename("blank.png");
196
197 if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/description.txt"))
198 {
199 QString desc = loadFile(m_themeDir + m_themeList[itemNo] + "/description.txt");
200 m_themedescText->SetText(QCoreApplication::translate("BurnThemeUI",
201 desc.toUtf8().constData()));
202 }
203 else
204 {
205 m_themedescText->SetText(tr("No theme description file found!"));
206 }
207}
208
210{
211 QString res = "";
212
213 QFile file(filename);
214
215 if (!file.exists())
216 {
217 res = tr("No theme description file found!");
218 }
219 else {
220 if (file.open(QIODevice::ReadOnly))
221 {
222 QTextStream stream(&file);
223
224 if (!stream.atEnd())
225 {
226 res = stream.readAll();
227 res = res.replace("\n", " ").trimmed();
228 }
229 else {
230 res = tr("Empty theme description!");
231 }
232 file.close();
233 }
234 else {
235 res = tr("Unable to open theme description file!");
236 }
237 }
238
239 return res;
240}
241
243{
244 QString theme = gCoreContext->GetSetting("MythBurnMenuTheme", "");
245 theme = theme.replace(QString("_"), QString(" "));
247}
248
250{
251 QString theme = m_themeSelector->GetValue();
252 theme = theme.replace(QString(" "), QString("_"));
253 gCoreContext->SaveSetting("MythBurnMenuTheme", theme);
254}
MythUIImage * m_detailsImage
Definition: themeselector.h:58
void handlePrevPage(void)
MythUIButton * m_prevButton
Definition: themeselector.h:62
MythUIText * m_themedescText
Definition: themeselector.h:59
void handleNextPage(void)
void handleCancel(void)
MythUIButtonList * m_themeSelector
Definition: themeselector.h:50
MythUIImage * m_chapterImage
Definition: themeselector.h:57
MythUIButton * m_cancelButton
Definition: themeselector.h:63
DVDThemeSelector(MythScreenStack *parent, MythScreenType *destinationScreen, const ArchiveDestination &archiveDestination, const QString &name)
MythScreenType * m_destinationScreen
Definition: themeselector.h:45
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
bool Create(void) override
void getThemeList(void)
static QString loadFile(const QString &filename)
void themeChanged(MythUIButtonListItem *item)
QStringList m_themeList
Definition: themeselector.h:53
ArchiveDestination m_archiveDestination
Definition: themeselector.h:46
MythUIImage * m_mainmenuImage
Definition: themeselector.h:56
MythUIButton * m_nextButton
Definition: themeselector.h:61
void loadConfiguration(void)
MythUIImage * m_themeImage
Definition: themeselector.h:51
~DVDThemeSelector(void) override
MythUIImage * m_introImage
Definition: themeselector.h:55
void saveConfiguration(void)
void SaveSetting(const QString &key, int newValue)
QString GetSetting(const QString &key, const QString &defaultval="")
MythScreenStack * GetMainStack()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Screen in which all other widgets are contained and rendered.
void BuildFocusList(void)
MythUIType * GetFocusWidget(void) const
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
bool SetFocusWidget(MythUIType *widget=nullptr)
virtual void Close()
virtual QString GetValue() const
int GetCurrentPos() const
bool MoveToNamedPosition(const QString &position_name)
void itemSelected(MythUIButtonListItem *item)
void Clicked()
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
static const iso6937table * d
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
QString GetShareDir(void)
Definition: mythdirs.cpp:261
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
bool exists(str path)
Definition: xbmcvfs.py:51
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:95