MythTV  master
selectdestination.cpp
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <iostream>
3 #include <unistd.h>
4 
5 // qt
6 #include <QDir>
7 #include <QKeyEvent>
8 
9 // myth
10 #include <mythcontext.h>
11 #include <mythcoreutil.h>
12 #include <mythuitext.h>
13 #include <mythuibutton.h>
14 #include <mythuicheckbox.h>
15 #include <mythuibuttonlist.h>
16 #include <mythuitextedit.h>
17 #include <mythmainwindow.h>
18 
19 // mytharchive
20 #include "selectdestination.h"
21 #include "fileselector.h"
22 #include "archiveutil.h"
23 #include "exportnative.h"
24 #include "themeselector.h"
25 
27 {
29 }
30 
31 
33 {
34  // Load the theme for this screen
35  bool foundtheme = LoadWindowFromXML("mytharchive-ui.xml", "selectdestination", this);
36  if (!foundtheme)
37  return false;
38 
39  bool err = false;
40  UIUtilE::Assign(this, m_createISOCheck, "makeisoimage_check", &err);
41  UIUtilE::Assign(this, m_doBurnCheck, "burntodvdr_check", &err);
42  UIUtilE::Assign(this, m_doBurnText, "burntodvdr_text", &err);
43  UIUtilE::Assign(this, m_eraseDvdRwCheck, "erasedvdrw_check", &err);
44  UIUtilE::Assign(this, m_eraseDvdRwText, "erasedvdrw_text", &err);
45  UIUtilE::Assign(this, m_nextButton, "next_button", &err);
46  UIUtilE::Assign(this, m_prevButton, "prev_button", &err);
47  UIUtilE::Assign(this, m_cancelButton, "cancel_button", &err);
48  UIUtilE::Assign(this, m_destinationSelector, "destination_selector", &err);
49  UIUtilE::Assign(this, m_destinationText, "destination_text", &err);
50  UIUtilE::Assign(this, m_findButton, "find_button", &err);
51  UIUtilE::Assign(this, m_filenameEdit, "filename_edit", &err);
52  UIUtilE::Assign(this, m_freespaceText, "freespace_text", &err);
53 
54  if (err)
55  {
56  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'selectdestination'");
57  return false;
58  }
59 
60  connect(m_nextButton, SIGNAL(Clicked()), this, SLOT(handleNextPage()));
61  connect(m_prevButton, SIGNAL(Clicked()), this, SLOT(handlePrevPage()));
62  connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(handleCancel()));
63 
64  connect(m_destinationSelector, SIGNAL(itemSelected(MythUIButtonListItem*)),
65  this, SLOT(setDestination(MythUIButtonListItem*)));
66 
67  for (int x = 0; x < ArchiveDestinationsCount; x++)
68  {
69  auto *item = new
71  item->SetData(qVariantFromValue(ArchiveDestinations[x].type));
72  }
73  connect(m_findButton, SIGNAL(Clicked()), this, SLOT(handleFind()));
74 
75  connect(m_filenameEdit, SIGNAL(LosingFocus()), this,
76  SLOT(filenameEditLostFocus()));
77 
79 
81 
83 
84  return true;
85 }
86 
87 bool SelectDestination::keyPressEvent(QKeyEvent *event)
88 {
89  if (GetFocusWidget()->keyPressEvent(event))
90  return true;
91 
92  QStringList actions;
93  bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
94 
95  for (int i = 0; i < actions.size() && !handled; i++)
96  {
97  QString action = actions[i];
98  handled = true;
99 
100  if (action == "MENU")
101  {
102  }
103  else
104  handled = false;
105  }
106 
107  if (!handled && MythScreenType::keyPressEvent(event))
108  handled = true;
109 
110  return handled;
111 }
112 
114 {
116 
118 
119  if (m_nativeMode)
120  {
121  auto *native = new ExportNative(mainStack, this, m_archiveDestination, "ExportNative");
122 
123  if (native->Create())
124  mainStack->AddScreen(native);
125  }
126  else
127  {
128  auto *theme = new DVDThemeSelector(mainStack, this, m_archiveDestination, "ThemeSelector");
129 
130  if (theme->Create())
131  mainStack->AddScreen(theme);
132  }
133 }
134 
136 {
137  Close();
138 }
139 
141 {
142  Close();
143 }
144 
146 {
147  bool bCreateISO = false;
148  bool bDoBurn = false;
149  bool bEraseDvdRw = false;
150  QString saveFilename = "";
151  int destinationType = 0;
152 
153  if (m_nativeMode)
154  {
155  bCreateISO = (gCoreContext->GetSetting("MythNativeCreateISO", "0") == "1");
156  bDoBurn = (gCoreContext->GetSetting("MythNativeBurnDVDr", "1") == "1");
157  bEraseDvdRw = (gCoreContext->GetSetting("MythNativeEraseDvdRw", "0") == "1");
158  saveFilename = gCoreContext->GetSetting("MythNativeSaveFilename", "");
159  destinationType = gCoreContext->GetNumSetting("MythNativeDestinationType", 0);
160  }
161  else
162  {
163  bCreateISO = (gCoreContext->GetSetting("MythBurnCreateISO", "0") == "1");
164  bDoBurn = (gCoreContext->GetSetting("MythBurnBurnDVDr", "1") == "1");
165  bEraseDvdRw = (gCoreContext->GetSetting("MythBurnEraseDvdRw", "0") == "1");
166  saveFilename = gCoreContext->GetSetting("MythBurnSaveFilename", "");
167  destinationType = gCoreContext->GetNumSetting("MythBurnDestinationType", 0);
168  }
169 
173  m_filenameEdit->SetText(saveFilename);
174 
175  if (destinationType < 0 || destinationType >= m_destinationSelector->GetCount())
176  destinationType = 0;
177  m_destinationSelector->SetItemCurrent(destinationType);
178 }
179 
181 {
182  if (m_nativeMode)
183  {
184  gCoreContext->SaveSetting("MythNativeCreateISO",
186  gCoreContext->SaveSetting("MythNativeBurnDVDr",
188  gCoreContext->SaveSetting("MythNativeEraseDvdRw",
190  gCoreContext->SaveSetting("MythNativeSaveFilename", m_filenameEdit->GetText());
191  gCoreContext->SaveSetting("MythNativeDestinationType", m_destinationSelector->GetCurrentPos());
192  }
193  else
194  {
195  gCoreContext->SaveSetting("MythBurnCreateISO",
197  gCoreContext->SaveSetting("MythBurnBurnDVDr",
199  gCoreContext->SaveSetting("MythBurnEraseDvdRw",
201  gCoreContext->SaveSetting("MythBurnSaveFilename", m_filenameEdit->GetText());
202  gCoreContext->SaveSetting("MythBurnDestinationType", m_destinationSelector->GetCurrentPos());
203  }
204 }
205 
207 {
208  if (!item)
209  return;
210 
211  int itemNo = item->GetData().value<ARCHIVEDESTINATION>();
212 
213  if (itemNo < 0 || itemNo > ArchiveDestinationsCount - 1)
214  itemNo = 0;
215 
216  m_destinationText->SetText(tr(ArchiveDestinations[itemNo].description));
217 
219 
220  switch(itemNo)
221  {
222  case AD_DVD_SL:
223  case AD_DVD_DL:
224  m_filenameEdit->Hide();
225  m_findButton->Hide();
228  m_doBurnCheck->Show();
229  m_doBurnText->Show();
230  break;
231  case AD_DVD_RW:
232  m_filenameEdit->Hide();
233  m_findButton->Hide();
236  m_doBurnCheck->Show();
237  m_doBurnText->Show();
238  break;
239  case AD_FILE:
240  int64_t dummy = 0;
241  ArchiveDestinations[itemNo].freeSpace =
242  getDiskSpace(m_filenameEdit->GetText(), dummy, dummy);
243 
244  m_filenameEdit->Show();
245  m_findButton->Show();
248  m_doBurnCheck->Hide();
249  m_doBurnText->Hide();
250  break;
251  }
252 
253  // update free space
254  if (ArchiveDestinations[itemNo].freeSpace != -1)
255  {
256  m_freespaceText->SetText(formatSize(ArchiveDestinations[itemNo].freeSpace, 2));
257  m_freeSpace = ArchiveDestinations[itemNo].freeSpace / 1024;
258  }
259  else
260  {
261  m_freespaceText->SetText(tr("Unknown"));
262  m_freeSpace = 0;
263  }
264 
265  BuildFocusList();
266 }
267 
269 {
271 
272  auto *selector = new
273  FileSelector(mainStack, nullptr, FSTYPE_DIRECTORY, m_filenameEdit->GetText(), "*.*");
274 
275  connect(selector, SIGNAL(haveResult(QString)),
276  this, SLOT(fileFinderClosed(QString)));
277 
278  if (selector->Create())
279  mainStack->AddScreen(selector);
280 }
281 
283 {
284  if (filename != "")
285  {
288  }
289 }
290 
292 {
293  int64_t dummy = 0;
295 
296  // if we don't get a valid freespace value it probably means the file doesn't
297  // exist yet so try looking up the freespace for the parent directory
299  {
300  QString dir = m_filenameEdit->GetText();
301  int pos = dir.lastIndexOf('/');
302  if (pos > 0)
303  dir = dir.left(pos);
304  else
305  dir = "/";
306 
307  m_archiveDestination.freeSpace = getDiskSpace(dir, dummy, dummy);
308  }
309 
311  {
314  }
315  else
316  {
317  m_freespaceText->SetText(tr("Unknown"));
318  m_freeSpace = 0;
319  }
320 }
int ArchiveDestinationsCount
Definition: archiveutil.cpp:48
ARCHIVEDESTINATION
Definition: archiveutil.h:16
void Show(void)
MythUIStateType::StateType GetCheckState() const
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
void LosingFocus()
void SaveSetting(const QString &key, int newValue)
void setDestination(MythUIButtonListItem *item)
MythUITextEdit * m_filenameEdit
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:135
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythScreenStack * GetMainStack()
void filenameEditLostFocus(void)
MythUIButton * m_cancelButton
void BuildFocusList(void)
MythUIText * m_eraseDvdRwText
bool keyPressEvent(QKeyEvent *) override
Key event handler.
MythUIButton * m_nextButton
void Hide(void)
virtual void Close()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString GetSetting(const QString &key, const QString &defaultval="")
MythUIText * m_destinationText
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
MythUIButton * m_findButton
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
void SetText(const QString &text, bool moveCursor=true)
MythUIType * GetFocusWidget(void) const
int64_t getDiskSpace(const QString &file_on_disk, int64_t &total, int64_t &used)
MythMainWindow * GetMythMainWindow(void)
void fileFinderClosed(const QString &filename)
MythUIText * m_freespaceText
static QString formatSize(int64_t sizeKB, int prec)
int GetNumSetting(const QString &key, int defaultval=0)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
ArchiveDestination m_archiveDestination
struct ArchiveDestination ArchiveDestinations[]
Definition: archiveutil.cpp:28
MythUIText * m_doBurnText
bool Create(void) override
void SetCheckState(MythUIStateType::StateType state)
MythUICheckBox * m_createISOCheck
MythUIButton * m_prevButton
void SetItemCurrent(MythUIButtonListItem *item)
MythUICheckBox * m_eraseDvdRwCheck
bool SetFocusWidget(MythUIType *widget=nullptr)
int GetCurrentPos() const
MythUICheckBox * m_doBurnCheck
QString GetText(void) const
MythUIButtonList * m_destinationSelector