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  MythScreenStack *parent, bool nativeMode, const QString& name) :
28  MythScreenType(parent, name),
29  m_nativeMode(nativeMode)
30 {
32  m_archiveDestination.name = nullptr;
35 }
36 
38 {
40 }
41 
42 
44 {
45  // Load the theme for this screen
46  bool foundtheme = LoadWindowFromXML("mytharchive-ui.xml", "selectdestination", this);
47  if (!foundtheme)
48  return false;
49 
50  bool err = false;
51  UIUtilE::Assign(this, m_createISOCheck, "makeisoimage_check", &err);
52  UIUtilE::Assign(this, m_doBurnCheck, "burntodvdr_check", &err);
53  UIUtilE::Assign(this, m_doBurnText, "burntodvdr_text", &err);
54  UIUtilE::Assign(this, m_eraseDvdRwCheck, "erasedvdrw_check", &err);
55  UIUtilE::Assign(this, m_eraseDvdRwText, "erasedvdrw_text", &err);
56  UIUtilE::Assign(this, m_nextButton, "next_button", &err);
57  UIUtilE::Assign(this, m_prevButton, "prev_button", &err);
58  UIUtilE::Assign(this, m_cancelButton, "cancel_button", &err);
59  UIUtilE::Assign(this, m_destinationSelector, "destination_selector", &err);
60  UIUtilE::Assign(this, m_destinationText, "destination_text", &err);
61  UIUtilE::Assign(this, m_findButton, "find_button", &err);
62  UIUtilE::Assign(this, m_filenameEdit, "filename_edit", &err);
63  UIUtilE::Assign(this, m_freespaceText, "freespace_text", &err);
64 
65  if (err)
66  {
67  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'selectdestination'");
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  connect(m_destinationSelector, SIGNAL(itemSelected(MythUIButtonListItem*)),
76  this, SLOT(setDestination(MythUIButtonListItem*)));
77 
78  for (int x = 0; x < ArchiveDestinationsCount; x++)
79  {
80  MythUIButtonListItem *item = new
82  item->SetData(qVariantFromValue(ArchiveDestinations[x].type));
83  }
84  connect(m_findButton, SIGNAL(Clicked()), this, SLOT(handleFind()));
85 
86  connect(m_filenameEdit, SIGNAL(LosingFocus()), this,
87  SLOT(filenameEditLostFocus()));
88 
90 
92 
94 
95  return true;
96 }
97 
98 bool SelectDestination::keyPressEvent(QKeyEvent *event)
99 {
100  if (GetFocusWidget()->keyPressEvent(event))
101  return true;
102 
103  QStringList actions;
104  bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
105 
106  for (int i = 0; i < actions.size() && !handled; i++)
107  {
108  QString action = actions[i];
109  handled = true;
110 
111  if (action == "MENU")
112  {
113  }
114  else
115  handled = false;
116  }
117 
118  if (!handled && MythScreenType::keyPressEvent(event))
119  handled = true;
120 
121  return handled;
122 }
123 
125 {
127 
129 
130  if (m_nativeMode)
131  {
132  ExportNative *native = new ExportNative(mainStack, this, m_archiveDestination, "ExportNative");
133 
134  if (native->Create())
135  mainStack->AddScreen(native);
136  }
137  else
138  {
139  DVDThemeSelector *theme = new DVDThemeSelector(mainStack, this, m_archiveDestination, "ThemeSelector");
140 
141  if (theme->Create())
142  mainStack->AddScreen(theme);
143  }
144 }
145 
147 {
148  Close();
149 }
150 
152 {
153  Close();
154 }
155 
157 {
158  bool bCreateISO = false;
159  bool bDoBurn = false;
160  bool bEraseDvdRw = false;
161  QString saveFilename = "";
162  int destinationType = 0;
163 
164  if (m_nativeMode)
165  {
166  bCreateISO = (gCoreContext->GetSetting("MythNativeCreateISO", "0") == "1");
167  bDoBurn = (gCoreContext->GetSetting("MythNativeBurnDVDr", "1") == "1");
168  bEraseDvdRw = (gCoreContext->GetSetting("MythNativeEraseDvdRw", "0") == "1");
169  saveFilename = gCoreContext->GetSetting("MythNativeSaveFilename", "");
170  destinationType = gCoreContext->GetNumSetting("MythNativeDestinationType", 0);
171  }
172  else
173  {
174  bCreateISO = (gCoreContext->GetSetting("MythBurnCreateISO", "0") == "1");
175  bDoBurn = (gCoreContext->GetSetting("MythBurnBurnDVDr", "1") == "1");
176  bEraseDvdRw = (gCoreContext->GetSetting("MythBurnEraseDvdRw", "0") == "1");
177  saveFilename = gCoreContext->GetSetting("MythBurnSaveFilename", "");
178  destinationType = gCoreContext->GetNumSetting("MythBurnDestinationType", 0);
179  }
180 
184  m_filenameEdit->SetText(saveFilename);
185 
186  if (destinationType < 0 || destinationType >= m_destinationSelector->GetCount())
187  destinationType = 0;
188  m_destinationSelector->SetItemCurrent(destinationType);
189 }
190 
192 {
193  if (m_nativeMode)
194  {
195  gCoreContext->SaveSetting("MythNativeCreateISO",
197  gCoreContext->SaveSetting("MythNativeBurnDVDr",
199  gCoreContext->SaveSetting("MythNativeEraseDvdRw",
201  gCoreContext->SaveSetting("MythNativeSaveFilename", m_filenameEdit->GetText());
202  gCoreContext->SaveSetting("MythNativeDestinationType", m_destinationSelector->GetCurrentPos());
203  }
204  else
205  {
206  gCoreContext->SaveSetting("MythBurnCreateISO",
208  gCoreContext->SaveSetting("MythBurnBurnDVDr",
210  gCoreContext->SaveSetting("MythBurnEraseDvdRw",
212  gCoreContext->SaveSetting("MythBurnSaveFilename", m_filenameEdit->GetText());
213  gCoreContext->SaveSetting("MythBurnDestinationType", m_destinationSelector->GetCurrentPos());
214  }
215 }
216 
218 {
219  if (!item)
220  return;
221 
222  int itemNo = item->GetData().value<ARCHIVEDESTINATION>();
223 
224  if (itemNo < 0 || itemNo > ArchiveDestinationsCount - 1)
225  itemNo = 0;
226 
227  m_destinationText->SetText(tr(ArchiveDestinations[itemNo].description));
228 
230 
231  switch(itemNo)
232  {
233  case AD_DVD_SL:
234  case AD_DVD_DL:
235  m_filenameEdit->Hide();
236  m_findButton->Hide();
239  m_doBurnCheck->Show();
240  m_doBurnText->Show();
241  break;
242  case AD_DVD_RW:
243  m_filenameEdit->Hide();
244  m_findButton->Hide();
247  m_doBurnCheck->Show();
248  m_doBurnText->Show();
249  break;
250  case AD_FILE:
251  int64_t dummy;
252  ArchiveDestinations[itemNo].freeSpace =
253  getDiskSpace(m_filenameEdit->GetText(), dummy, dummy);
254 
255  m_filenameEdit->Show();
256  m_findButton->Show();
259  m_doBurnCheck->Hide();
260  m_doBurnText->Hide();
261  break;
262  }
263 
264  // update free space
265  if (ArchiveDestinations[itemNo].freeSpace != -1)
266  {
267  m_freespaceText->SetText(formatSize(ArchiveDestinations[itemNo].freeSpace, 2));
268  m_freeSpace = ArchiveDestinations[itemNo].freeSpace / 1024;
269  }
270  else
271  {
272  m_freespaceText->SetText(tr("Unknown"));
273  m_freeSpace = 0;
274  }
275 
276  BuildFocusList();
277 }
278 
280 {
282 
283  FileSelector *selector = new
284  FileSelector(mainStack, nullptr, FSTYPE_DIRECTORY, m_filenameEdit->GetText(), "*.*");
285 
286  connect(selector, SIGNAL(haveResult(QString)),
287  this, SLOT(fileFinderClosed(QString)));
288 
289  if (selector->Create())
290  mainStack->AddScreen(selector);
291 }
292 
293 void SelectDestination::fileFinderClosed(const QString& filename)
294 {
295  if (filename != "")
296  {
297  m_filenameEdit->SetText(filename);
299  }
300 }
301 
303 {
304  int64_t dummy;
306 
307  // if we don't get a valid freespace value it probably means the file doesn't
308  // exist yet so try looking up the freespace for the parent directory
310  {
311  QString dir = m_filenameEdit->GetText();
312  int pos = dir.lastIndexOf('/');
313  if (pos > 0)
314  dir = dir.left(pos);
315  else
316  dir = "/";
317 
318  m_archiveDestination.freeSpace = getDiskSpace(dir, dummy, dummy);
319  }
320 
322  {
325  }
326  else
327  {
328  m_freespaceText->SetText(tr("Unknown"));
329  m_freeSpace = 0;
330  }
331 }
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 SetData(QVariant data)
void SaveSetting(const QString &key, int newValue)
void setDestination(MythUIButtonListItem *item)
const char * description
Definition: archiveutil.h:30
MythUITextEdit * m_filenameEdit
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:136
SelectDestination(MythScreenStack *parent, bool nativeMode, const QString &name)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythScreenStack * GetMainStack()
void filenameEditLostFocus(void)
MythUIButton * m_cancelButton
bool Create(void) override
void BuildFocusList(void)
MythUIText * m_eraseDvdRwText
bool keyPressEvent(QKeyEvent *) override
Key event handler.
ARCHIVEDESTINATION type
Definition: archiveutil.h:28
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
const char * name
Definition: archiveutil.h:29
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
const char * name
Definition: ParseText.cpp:328
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)
bool Create(void) override
bool Create(void) override
Screen in which all other widgets are contained and rendered.
int GetCurrentPos() const
MythUICheckBox * m_doBurnCheck
QString GetText(void) const
MythUIButtonList * m_destinationSelector