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