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  LOG(VB_GENERAL, LOG_ERR,
149  "MythArchive: Theme directory does not exist!");
150 }
151 
153 {
154  if (!item)
155  return;
156 
157  int itemNo = m_themeSelector->GetCurrentPos();
158 
159  if (itemNo < 0 || itemNo > m_themeList.size() - 1)
160  itemNo = 0;
161 
162  m_themeNo = itemNo;
163 
164  if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/preview.png"))
165  m_themeImage->SetFilename(m_themeDir + m_themeList[itemNo] + "/preview.png");
166  else
167  m_themeImage->SetFilename("blank.png");
168  m_themeImage->Load();
169 
170  if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/intro_preview.png"))
171  m_introImage->SetFilename(m_themeDir + m_themeList[itemNo] + "/intro_preview.png");
172  else
173  m_introImage->SetFilename("blank.png");
174  m_introImage->Load();
175 
176  if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/mainmenu_preview.png"))
177  m_mainmenuImage->SetFilename(m_themeDir + m_themeList[itemNo] + "/mainmenu_preview.png");
178  else
179  m_mainmenuImage->SetFilename("blank.png");
181 
182  if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/chaptermenu_preview.png"))
183  m_chapterImage->SetFilename(m_themeDir + m_themeList[itemNo] + "/chaptermenu_preview.png");
184  else
185  m_chapterImage->SetFilename("blank.png");
186  m_chapterImage->Load();
187 
188  if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/details_preview.png"))
189  m_detailsImage->SetFilename(m_themeDir + m_themeList[itemNo] + "/details_preview.png");
190  else
191  m_detailsImage->SetFilename("blank.png");
192  m_detailsImage->Load();
193 
194  if (QFile::exists(m_themeDir + m_themeList[itemNo] + "/description.txt"))
195  {
196  QString desc = loadFile(m_themeDir + m_themeList[itemNo] + "/description.txt");
197  m_themedescText->SetText(QCoreApplication::translate("BurnThemeUI",
198  desc.toUtf8().constData()));
199  }
200  else
201  m_themedescText->SetText(tr("No theme description file found!"));
202 }
203 
204 QString DVDThemeSelector::loadFile(const QString &filename)
205 {
206  QString res = "";
207 
208  QFile file(filename);
209 
210  if (!file.exists())
211  {
212  res = tr("No theme description file found!");
213  }
214  else {
215  if (file.open(QIODevice::ReadOnly))
216  {
217  QTextStream stream(&file);
218 
219  if (!stream.atEnd())
220  {
221  res = stream.readAll();
222  res = res.replace("\n", " ").trimmed();
223  }
224  else {
225  res = tr("Empty theme description!");
226  }
227  file.close();
228  }
229  else {
230  res = tr("Unable to open theme description file!");
231  }
232  }
233 
234  return res;
235 }
236 
238 {
239  QString theme = gCoreContext->GetSetting("MythBurnMenuTheme", "");
240  theme = theme.replace(QString("_"), QString(" "));
242 }
243 
245 {
246  QString theme = m_themeSelector->GetValue();
247  theme = theme.replace(QString(" "), QString("_"));
248  gCoreContext->SaveSetting("MythBurnMenuTheme", theme);
249 }
MythUIButton::Clicked
void Clicked()
DVDThemeSelector::m_themeNo
int m_themeNo
Definition: themeselector.h:52
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:318
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:386
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:966
MythUIButtonList::itemSelected
void itemSelected(MythUIButtonListItem *item)
DVDThemeSelector::loadFile
static QString loadFile(const QString &filename)
Definition: themeselector.cpp:204
DVDThemeSelector::Create
bool Create(void) override
Definition: themeselector.cpp:42
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:113
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
DVDThemeSelector::m_themeImage
MythUIImage * m_themeImage
Definition: themeselector.h:51
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:238
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:118
GetShareDir
QString GetShareDir(void)
Definition: mythdirs.cpp:254
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:206
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:237
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:404
mythburn.h
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:687
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:1610
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:132
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythUIButtonList::MoveToNamedPosition
bool MoveToNamedPosition(const QString &position_name)
Definition: mythuibuttonlist.cpp:2283
mythuibutton.h
d
static const iso6937table * d
Definition: iso6937tables.cpp:1025
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:881
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:674
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:244
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:152
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:898
DVDThemeSelector::m_themeList
QStringList m_themeList
Definition: themeselector.h:53