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
13 #include <libmythbase/stringutil.h>
15 #include <libmythui/mythuibutton.h>
18 #include <libmythui/mythuitext.h>
20 
21 // mytharchive
22 #include "archiveutil.h"
23 #include "exportnative.h"
24 #include "fileselector.h"
25 #include "selectdestination.h"
26 #include "themeselector.h"
27 
29 {
31 }
32 
33 
35 {
36  // Load the theme for this screen
37  bool foundtheme = LoadWindowFromXML("mytharchive-ui.xml", "selectdestination", this);
38  if (!foundtheme)
39  return false;
40 
41  bool err = false;
42  UIUtilE::Assign(this, m_createISOCheck, "makeisoimage_check", &err);
43  UIUtilE::Assign(this, m_doBurnCheck, "burntodvdr_check", &err);
44  UIUtilE::Assign(this, m_doBurnText, "burntodvdr_text", &err);
45  UIUtilE::Assign(this, m_eraseDvdRwCheck, "erasedvdrw_check", &err);
46  UIUtilE::Assign(this, m_eraseDvdRwText, "erasedvdrw_text", &err);
47  UIUtilE::Assign(this, m_nextButton, "next_button", &err);
48  UIUtilE::Assign(this, m_prevButton, "prev_button", &err);
49  UIUtilE::Assign(this, m_cancelButton, "cancel_button", &err);
50  UIUtilE::Assign(this, m_destinationSelector, "destination_selector", &err);
51  UIUtilE::Assign(this, m_destinationText, "destination_text", &err);
52  UIUtilE::Assign(this, m_findButton, "find_button", &err);
53  UIUtilE::Assign(this, m_filenameEdit, "filename_edit", &err);
54  UIUtilE::Assign(this, m_freespaceText, "freespace_text", &err);
55 
56  if (err)
57  {
58  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'selectdestination'");
59  return false;
60  }
61 
65 
68 
69  for (const auto & dest : ArchiveDestinations)
70  {
71  auto *item = new
73  item->SetData(QVariant::fromValue(dest.type));
74  }
76 
79 
81 
83 
85 
86  return true;
87 }
88 
89 bool SelectDestination::keyPressEvent(QKeyEvent *event)
90 {
91  if (GetFocusWidget()->keyPressEvent(event))
92  return true;
93 
94  QStringList actions;
95  bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
96 
97  for (int i = 0; i < actions.size() && !handled; i++)
98  {
99  const QString& action = actions[i];
100  handled = true;
101 
102  if (action == "MENU")
103  {
104  }
105  else
106  {
107  handled = false;
108  }
109  }
110 
111  if (!handled && MythScreenType::keyPressEvent(event))
112  handled = true;
113 
114  return handled;
115 }
116 
118 {
120 
122 
123  if (m_nativeMode)
124  {
125  auto *native = new ExportNative(mainStack, this, m_archiveDestination, "ExportNative");
126 
127  if (native->Create())
128  mainStack->AddScreen(native);
129  }
130  else
131  {
132  auto *theme = new DVDThemeSelector(mainStack, this, m_archiveDestination, "ThemeSelector");
133 
134  if (theme->Create())
135  mainStack->AddScreen(theme);
136  }
137 }
138 
140 {
141  Close();
142 }
143 
145 {
146  Close();
147 }
148 
150 {
151  bool bCreateISO = false;
152  bool bDoBurn = false;
153  bool bEraseDvdRw = false;
154  QString saveFilename = "";
155  int destinationType = 0;
156 
157  if (m_nativeMode)
158  {
159  bCreateISO = (gCoreContext->GetSetting("MythNativeCreateISO", "0") == "1");
160  bDoBurn = (gCoreContext->GetSetting("MythNativeBurnDVDr", "1") == "1");
161  bEraseDvdRw = (gCoreContext->GetSetting("MythNativeEraseDvdRw", "0") == "1");
162  saveFilename = gCoreContext->GetSetting("MythNativeSaveFilename", "");
163  destinationType = gCoreContext->GetNumSetting("MythNativeDestinationType", 0);
164  }
165  else
166  {
167  bCreateISO = (gCoreContext->GetSetting("MythBurnCreateISO", "0") == "1");
168  bDoBurn = (gCoreContext->GetSetting("MythBurnBurnDVDr", "1") == "1");
169  bEraseDvdRw = (gCoreContext->GetSetting("MythBurnEraseDvdRw", "0") == "1");
170  saveFilename = gCoreContext->GetSetting("MythBurnSaveFilename", "");
171  destinationType = gCoreContext->GetNumSetting("MythBurnDestinationType", 0);
172  }
173 
177  m_filenameEdit->SetText(saveFilename);
178 
179  if (destinationType < 0 || destinationType >= m_destinationSelector->GetCount())
180  destinationType = 0;
181  m_destinationSelector->SetItemCurrent(destinationType);
182 }
183 
185 {
186  if (m_nativeMode)
187  {
188  gCoreContext->SaveSetting("MythNativeCreateISO",
190  gCoreContext->SaveSetting("MythNativeBurnDVDr",
192  gCoreContext->SaveSetting("MythNativeEraseDvdRw",
194  gCoreContext->SaveSetting("MythNativeSaveFilename", m_filenameEdit->GetText());
195  gCoreContext->SaveSetting("MythNativeDestinationType", m_destinationSelector->GetCurrentPos());
196  }
197  else
198  {
199  gCoreContext->SaveSetting("MythBurnCreateISO",
201  gCoreContext->SaveSetting("MythBurnBurnDVDr",
203  gCoreContext->SaveSetting("MythBurnEraseDvdRw",
205  gCoreContext->SaveSetting("MythBurnSaveFilename", m_filenameEdit->GetText());
206  gCoreContext->SaveSetting("MythBurnDestinationType", m_destinationSelector->GetCurrentPos());
207  }
208 }
209 
211 {
212  if (!item)
213  return;
214 
215  size_t itemNo = item->GetData().value<ARCHIVEDESTINATION>();
216 
217  if (itemNo > ArchiveDestinations.size() - 1)
218  itemNo = 0;
219 
220  m_destinationText->SetText(tr(ArchiveDestinations[itemNo].description));
221 
223 
224  switch(itemNo)
225  {
226  case AD_DVD_SL:
227  case AD_DVD_DL:
228  m_filenameEdit->Hide();
229  m_findButton->Hide();
232  m_doBurnCheck->Show();
233  m_doBurnText->Show();
234  break;
235  case AD_DVD_RW:
236  m_filenameEdit->Hide();
237  m_findButton->Hide();
240  m_doBurnCheck->Show();
241  m_doBurnText->Show();
242  break;
243  case AD_FILE:
244  int64_t dummy = 0;
245  ArchiveDestinations[itemNo].freeSpace =
246  getDiskSpace(m_filenameEdit->GetText(), dummy, dummy);
247 
248  m_filenameEdit->Show();
249  m_findButton->Show();
252  m_doBurnCheck->Hide();
253  m_doBurnText->Hide();
254  break;
255  }
256 
257  // update free space
258  if (ArchiveDestinations[itemNo].freeSpace != -1)
259  {
261  m_freeSpace = ArchiveDestinations[itemNo].freeSpace / 1024;
262  }
263  else
264  {
265  m_freespaceText->SetText(tr("Unknown"));
266  m_freeSpace = 0;
267  }
268 
269  BuildFocusList();
270 }
271 
273 {
275 
276  auto *selector = new
277  FileSelector(mainStack, nullptr, FSTYPE_DIRECTORY, m_filenameEdit->GetText(), "*.*");
278 
279  connect(selector, qOverload<QString>(&FileSelector::haveResult),
281 
282  if (selector->Create())
283  mainStack->AddScreen(selector);
284 }
285 
287 {
288  if (filename != "")
289  {
292  }
293 }
294 
296 {
297  int64_t dummy = 0;
299 
300  // if we don't get a valid freespace value it probably means the file doesn't
301  // exist yet so try looking up the freespace for the parent directory
303  {
304  QString dir = m_filenameEdit->GetText();
305  int pos = dir.lastIndexOf('/');
306  if (pos > 0)
307  dir = dir.left(pos);
308  else
309  dir = "/";
310 
311  m_archiveDestination.freeSpace = getDiskSpace(dir, dummy, dummy);
312  }
313 
315  {
318  }
319  else
320  {
321  m_freespaceText->SetText(tr("Unknown"));
322  m_freeSpace = 0;
323  }
324 }
MythUIButton::Clicked
void Clicked()
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:317
build_compdb.dest
dest
Definition: build_compdb.py:9
AD_FILE
@ AD_FILE
Definition: archiveutil.h:21
exportnative.h
mythuitext.h
fileselector.h
SelectDestination::m_nativeMode
bool m_nativeMode
Definition: selectdestination.h:48
SelectDestination::handleCancel
void handleCancel(void)
Definition: selectdestination.cpp:144
getDiskSpace
int64_t getDiskSpace(const QString &file_on_disk, int64_t &total, int64_t &used)
Definition: mythcoreutil.cpp:33
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:384
SelectDestination::m_destinationSelector
MythUIButtonList * m_destinationSelector
Definition: selectdestination.h:57
SelectDestination::m_filenameEdit
MythUITextEdit * m_filenameEdit
Definition: selectdestination.h:62
ArchiveDestination::freeSpace
int64_t freeSpace
Definition: archiveutil.h:31
MythUIButtonList::itemSelected
void itemSelected(MythUIButtonListItem *item)
mythcoreutil.h
AD_DVD_RW
@ AD_DVD_RW
Definition: archiveutil.h:20
MythScreenStack
Definition: mythscreenstack.h:16
SelectDestination::saveConfiguration
void saveConfiguration(void)
Definition: selectdestination.cpp:184
ExportNative
Definition: exportnative.h:29
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythUITextEdit::GetText
QString GetText(void) const
Definition: mythuitextedit.h:50
SelectDestination::m_freeSpace
int m_freeSpace
Definition: selectdestination.h:51
mythuibuttonlist.h
SelectDestination::setDestination
void setDestination(MythUIButtonListItem *item)
Definition: selectdestination.cpp:210
MythUIButtonList::GetCount
int GetCount() const
Definition: mythuibuttonlist.cpp:1679
DVDThemeSelector
Definition: themeselector.h:19
selectdestination.h
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:111
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
MythUITextEdit::SetText
void SetText(const QString &text, bool moveCursor=true)
Definition: mythuitextedit.cpp:198
ARCHIVEDESTINATION
ARCHIVEDESTINATION
Definition: archiveutil.h:16
FileSelector
Definition: fileselector.h:39
MythUIType::Show
void Show(void)
Definition: mythuitype.cpp:1144
mythlogging.h
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1111
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:240
SelectDestination::filenameEditLostFocus
void filenameEditLostFocus(void)
Definition: selectdestination.cpp:295
archiveutil.h
SelectDestination::m_findButton
MythUIButton * m_findButton
Definition: selectdestination.h:63
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:116
SelectDestination::loadConfiguration
void loadConfiguration(void)
Definition: selectdestination.cpp:149
SelectDestination::m_cancelButton
MythUIButton * m_cancelButton
Definition: selectdestination.h:55
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:204
SelectDestination::m_eraseDvdRwText
MythUIText * m_eraseDvdRwText
Definition: selectdestination.h:70
stringutil.h
SelectDestination::m_nextButton
MythUIButton * m_nextButton
Definition: selectdestination.h:53
MythUIStateType::Off
@ Off
Definition: mythuistatetype.h:27
SelectDestination::m_archiveDestination
ArchiveDestination m_archiveDestination
Definition: selectdestination.h:50
MythUIButtonListItem::GetData
QVariant GetData()
Definition: mythuibuttonlist.cpp:3715
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
SelectDestination::fileFinderClosed
void fileFinderClosed(const QString &filename)
Definition: selectdestination.cpp:286
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:918
UIUtilDisp::Assign
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27
MythUIType::Hide
void Hide(void)
Definition: mythuitype.cpp:1139
StringUtil::formatKBytes
MBASE_PUBLIC QString formatKBytes(int64_t sizeKB, int prec=1)
Definition: stringutil.cpp:357
AD_DVD_SL
@ AD_DVD_SL
Definition: archiveutil.h:18
AD_DVD_DL
@ AD_DVD_DL
Definition: archiveutil.h:19
SelectDestination::m_destinationText
MythUIText * m_destinationText
Definition: selectdestination.h:58
themeselector.h
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:402
mythcorecontext.h
mythuitextedit.h
MythUICheckBox::SetCheckState
void SetCheckState(MythUIStateType::StateType state)
Definition: mythuicheckbox.cpp:66
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:701
SelectDestination::handlePrevPage
void handlePrevPage(void)
Definition: selectdestination.cpp:139
FileSelector::haveResult
void haveResult(bool ok)
ArchiveDestinations
std::vector< ArchiveDestination > ArchiveDestinations
Definition: archiveutil.cpp:27
SelectDestination::m_eraseDvdRwCheck
MythUICheckBox * m_eraseDvdRwCheck
Definition: selectdestination.h:67
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
SelectDestination::m_doBurnText
MythUIText * m_doBurnText
Definition: selectdestination.h:69
SelectDestination::handleFind
void handleFind(void)
Definition: selectdestination.cpp:272
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythUIButtonList::SetItemCurrent
void SetItemCurrent(MythUIButtonListItem *item)
Definition: mythuibuttonlist.cpp:1581
build_compdb.action
action
Definition: build_compdb.py:9
SelectDestination::m_freespaceText
MythUIText * m_freespaceText
Definition: selectdestination.h:60
mythuibutton.h
SelectDestination::handleNextPage
void handleNextPage(void)
Definition: selectdestination.cpp:117
FSTYPE_DIRECTORY
@ FSTYPE_DIRECTORY
Definition: fileselector.h:30
MythUIStateType::Full
@ Full
Definition: mythuistatetype.h:27
SelectDestination::~SelectDestination
~SelectDestination(void) override
Definition: selectdestination.cpp:28
SelectDestination::m_prevButton
MythUIButton * m_prevButton
Definition: selectdestination.h:54
SelectDestination::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: selectdestination.cpp:89
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:887
mythuicheckbox.h
MythUICheckBox::GetCheckState
MythUIStateType::StateType GetCheckState() const
Definition: mythuicheckbox.cpp:98
MythUIType::LosingFocus
void LosingFocus()
SelectDestination::m_doBurnCheck
MythUICheckBox * m_doBurnCheck
Definition: selectdestination.h:66
build_compdb.filename
filename
Definition: build_compdb.py:21
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
SelectDestination::Create
bool Create(void) override
Definition: selectdestination.cpp:34
SelectDestination::m_createISOCheck
MythUICheckBox * m_createISOCheck
Definition: selectdestination.h:65
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:904