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 <mythcontext.h>
15 #include <mythdirs.h>
16 #include <mythuihelper.h>
17 #include <mythuitext.h>
18 #include <mythuibutton.h>
19 #include <mythuiimage.h>
20 #include <mythuibuttonlist.h>
21 #include <mythmainwindow.h>
22 
23 // mytharchive
24 #include "mythburn.h"
25 #include "themeselector.h"
26 
28  MythScreenStack *parent, MythScreenType *destinationScreen,
29  ArchiveDestination archiveDestination, const QString& name) :
30  MythScreenType(parent, name, true),
31  m_destinationScreen(destinationScreen),
32  m_archiveDestination(archiveDestination),
33  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, intro_image, "intro_image", &err);
56  UIUtilE::Assign(this, mainmenu_image, "mainmenu_image", &err);
57  UIUtilE::Assign(this, chapter_image, "chapter_image", &err);
58  UIUtilE::Assign(this, details_image, "details_image", &err);
59 
60  // menu theme
61  UIUtilE::Assign(this, themedesc_text, "themedescription", &err);
62  UIUtilE::Assign(this, theme_image, "theme_image", &err);
63  UIUtilE::Assign(this, theme_selector, "theme_selector", &err);
64 
65  if (err)
66  {
67  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'themeselector'");
68  return false;
69  }
70 
71  connect(m_nextButton, SIGNAL(Clicked()), this, SLOT(handleNextPage()));
72  connect(m_prevButton, SIGNAL(Clicked()), this, SLOT(handlePrevPage()));
73  connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(handleCancel()));
74 
75  getThemeList();
76 
77  connect(theme_selector, SIGNAL(itemSelected(MythUIButtonListItem*)),
78  this, SLOT(themeChanged(MythUIButtonListItem*)));
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  theme_list.clear();
128  QDir d;
129 
130  d.setPath(themeDir);
131  if (d.exists())
132  {
133  QStringList filters;
134  filters << "*";
135  QFileInfoList list = d.entryInfoList(filters, QDir::Dirs, QDir::Name);
136 
137  for (int x = 0; x < list.size(); x++)
138  {
139  const QFileInfo& fi = list.at(x);
140  if (QFile::exists(themeDir + fi.fileName() + "/preview.png"))
141  {
142  theme_list.append(fi.fileName());
143  QString filename = fi.fileName().replace(QString("_"), QString(" "));
145  }
146  }
147  }
148  else
149  LOG(VB_GENERAL, LOG_ERR,
150  "MythArchive: Theme directory does not exist!");
151 }
152 
154 {
155  if (!item)
156  return;
157 
158  int itemNo = theme_selector->GetCurrentPos();
159 
160  if (itemNo < 0 || itemNo > theme_list.size() - 1)
161  itemNo = 0;
162 
163  theme_no = itemNo;
164 
165  if (QFile::exists(themeDir + theme_list[itemNo] + "/preview.png"))
166  theme_image->SetFilename(themeDir + theme_list[itemNo] + "/preview.png");
167  else
168  theme_image->SetFilename("blank.png");
169  theme_image->Load();
170 
171  if (QFile::exists(themeDir + theme_list[itemNo] + "/intro_preview.png"))
172  intro_image->SetFilename(themeDir + theme_list[itemNo] + "/intro_preview.png");
173  else
174  intro_image->SetFilename("blank.png");
175  intro_image->Load();
176 
177  if (QFile::exists(themeDir + theme_list[itemNo] + "/mainmenu_preview.png"))
178  mainmenu_image->SetFilename(themeDir + theme_list[itemNo] + "/mainmenu_preview.png");
179  else
180  mainmenu_image->SetFilename("blank.png");
181  mainmenu_image->Load();
182 
183  if (QFile::exists(themeDir + theme_list[itemNo] + "/chaptermenu_preview.png"))
184  chapter_image->SetFilename(themeDir + theme_list[itemNo] + "/chaptermenu_preview.png");
185  else
186  chapter_image->SetFilename("blank.png");
187  chapter_image->Load();
188 
189  if (QFile::exists(themeDir + theme_list[itemNo] + "/details_preview.png"))
190  details_image->SetFilename(themeDir + theme_list[itemNo] + "/details_preview.png");
191  else
192  details_image->SetFilename("blank.png");
193  details_image->Load();
194 
195  if (QFile::exists(themeDir + theme_list[itemNo] + "/description.txt"))
196  {
197  QString desc = loadFile(themeDir + theme_list[itemNo] + "/description.txt");
198  themedesc_text->SetText(QCoreApplication::translate("BurnThemeUI",
199  desc.toUtf8().constData()));
200  }
201  else
202  themedesc_text->SetText(tr("No theme description file found!"));
203 }
204 
205 QString DVDThemeSelector::loadFile(const QString &filename)
206 {
207  QString res = "";
208 
209  QFile file(filename);
210 
211  if (!file.exists())
212  {
213  res = tr("No theme description file found!");
214  }
215  else {
216  if (file.open(QIODevice::ReadOnly))
217  {
218  QTextStream stream(&file);
219 
220  if (!stream.atEnd())
221  {
222  res = stream.readAll();
223  res = res.replace("\n", " ").trimmed();
224  }
225  else {
226  res = tr("Empty theme description!");
227  }
228  file.close();
229  }
230  else {
231  res = tr("Unable to open theme description file!");
232  }
233  }
234 
235  return res;
236 }
237 
239 {
240  QString theme = gCoreContext->GetSetting("MythBurnMenuTheme", "");
241  theme = theme.replace(QString("_"), QString(" "));
243 }
244 
246 {
247  QString theme = theme_selector->GetValue();
248  theme = theme.replace(QString(" "), QString("_"));
249  gCoreContext->SaveSetting("MythBurnMenuTheme", theme);
250 }
MythUIButton * m_prevButton
Definition: themeselector.h:62
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
MythScreenType * m_destinationScreen
Definition: themeselector.h:45
void SaveSetting(const QString &key, int newValue)
MythUIButtonList * theme_selector
Definition: themeselector.h:50
void loadConfiguration(void)
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:135
MythUIImage * chapter_image
Definition: themeselector.h:57
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythScreenStack * GetMainStack()
void saveConfiguration(void)
void themeChanged(MythUIButtonListItem *item)
MythUIButton * m_cancelButton
Definition: themeselector.h:63
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
void BuildFocusList(void)
bool MoveToNamedPosition(const QString &position_name)
ArchiveDestination m_archiveDestination
Definition: themeselector.h:46
virtual void Close()
MythUIImage * intro_image
Definition: themeselector.h:55
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void getThemeList(void)
static const uint16_t * d
QString GetSetting(const QString &key, const QString &defaultval="")
DVDThemeSelector(MythScreenStack *parent, MythScreenType *destinationScreen, ArchiveDestination archiveDestination, const QString &name)
QString GetShareDir(void)
Definition: mythdirs.cpp:222
static QString loadFile(const QString &filename)
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
MythUIType * GetFocusWidget(void) const
MythMainWindow * GetMythMainWindow(void)
virtual QString GetValue() const
void handleNextPage(void)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void handlePrevPage(void)
MythUIButton * m_nextButton
Definition: themeselector.h:61
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
MythUIText * themedesc_text
Definition: themeselector.h:59
bool SetFocusWidget(MythUIType *widget=nullptr)
bool Create(void) override
bool keyPressEvent(QKeyEvent *) override
Key event handler.
Screen in which all other widgets are contained and rendered.
int GetCurrentPos() const
MythUIImage * mainmenu_image
Definition: themeselector.h:56
QStringList theme_list
Definition: themeselector.h:53
void handleCancel(void)
MythUIImage * details_image
Definition: themeselector.h:58
MythUIImage * theme_image
Definition: themeselector.h:51