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 <libmyth/mythcontext.h>
12 #include <libmythbase/stringutil.h>
14 #include <libmythui/mythuibutton.h>
17 #include <libmythui/mythuitext.h>
19 
20 // mytharchive
21 #include "archiveutil.h"
22 #include "exportnative.h"
23 #include "fileselector.h"
24 #include "selectdestination.h"
25 #include "themeselector.h"
26 
28 {
30 }
31 
32 
34 {
35  // Load the theme for this screen
36  bool foundtheme = LoadWindowFromXML("mytharchive-ui.xml", "selectdestination", this);
37  if (!foundtheme)
38  return false;
39 
40  bool err = false;
41  UIUtilE::Assign(this, m_createISOCheck, "makeisoimage_check", &err);
42  UIUtilE::Assign(this, m_doBurnCheck, "burntodvdr_check", &err);
43  UIUtilE::Assign(this, m_doBurnText, "burntodvdr_text", &err);
44  UIUtilE::Assign(this, m_eraseDvdRwCheck, "erasedvdrw_check", &err);
45  UIUtilE::Assign(this, m_eraseDvdRwText, "erasedvdrw_text", &err);
46  UIUtilE::Assign(this, m_nextButton, "next_button", &err);
47  UIUtilE::Assign(this, m_prevButton, "prev_button", &err);
48  UIUtilE::Assign(this, m_cancelButton, "cancel_button", &err);
49  UIUtilE::Assign(this, m_destinationSelector, "destination_selector", &err);
50  UIUtilE::Assign(this, m_destinationText, "destination_text", &err);
51  UIUtilE::Assign(this, m_findButton, "find_button", &err);
52  UIUtilE::Assign(this, m_filenameEdit, "filename_edit", &err);
53  UIUtilE::Assign(this, m_freespaceText, "freespace_text", &err);
54 
55  if (err)
56  {
57  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'selectdestination'");
58  return false;
59  }
60 
64 
67 
68  for (const auto & dest : ArchiveDestinations)
69  {
70  auto *item = new
72  item->SetData(QVariant::fromValue(dest.type));
73  }
75 
78 
80 
82 
84 
85  return true;
86 }
87 
88 bool SelectDestination::keyPressEvent(QKeyEvent *event)
89 {
90  if (GetFocusWidget()->keyPressEvent(event))
91  return true;
92 
93  QStringList actions;
94  bool handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
95 
96  for (int i = 0; i < actions.size() && !handled; i++)
97  {
98  const QString& action = actions[i];
99  handled = true;
100 
101  if (action == "MENU")
102  {
103  }
104  else
105  {
106  handled = false;
107  }
108  }
109 
110  if (!handled && MythScreenType::keyPressEvent(event))
111  handled = true;
112 
113  return handled;
114 }
115 
117 {
119 
121 
122  if (m_nativeMode)
123  {
124  auto *native = new ExportNative(mainStack, this, m_archiveDestination, "ExportNative");
125 
126  if (native->Create())
127  mainStack->AddScreen(native);
128  }
129  else
130  {
131  auto *theme = new DVDThemeSelector(mainStack, this, m_archiveDestination, "ThemeSelector");
132 
133  if (theme->Create())
134  mainStack->AddScreen(theme);
135  }
136 }
137 
139 {
140  Close();
141 }
142 
144 {
145  Close();
146 }
147 
149 {
150  bool bCreateISO = false;
151  bool bDoBurn = false;
152  bool bEraseDvdRw = false;
153  QString saveFilename = "";
154  int destinationType = 0;
155 
156  if (m_nativeMode)
157  {
158  bCreateISO = (gCoreContext->GetSetting("MythNativeCreateISO", "0") == "1");
159  bDoBurn = (gCoreContext->GetSetting("MythNativeBurnDVDr", "1") == "1");
160  bEraseDvdRw = (gCoreContext->GetSetting("MythNativeEraseDvdRw", "0") == "1");
161  saveFilename = gCoreContext->GetSetting("MythNativeSaveFilename", "");
162  destinationType = gCoreContext->GetNumSetting("MythNativeDestinationType", 0);
163  }
164  else
165  {
166  bCreateISO = (gCoreContext->GetSetting("MythBurnCreateISO", "0") == "1");
167  bDoBurn = (gCoreContext->GetSetting("MythBurnBurnDVDr", "1") == "1");
168  bEraseDvdRw = (gCoreContext->GetSetting("MythBurnEraseDvdRw", "0") == "1");
169  saveFilename = gCoreContext->GetSetting("MythBurnSaveFilename", "");
170  destinationType = gCoreContext->GetNumSetting("MythBurnDestinationType", 0);
171  }
172 
176  m_filenameEdit->SetText(saveFilename);
177 
178  if (destinationType < 0 || destinationType >= m_destinationSelector->GetCount())
179  destinationType = 0;
180  m_destinationSelector->SetItemCurrent(destinationType);
181 }
182 
184 {
185  if (m_nativeMode)
186  {
187  gCoreContext->SaveSetting("MythNativeCreateISO",
189  gCoreContext->SaveSetting("MythNativeBurnDVDr",
191  gCoreContext->SaveSetting("MythNativeEraseDvdRw",
193  gCoreContext->SaveSetting("MythNativeSaveFilename", m_filenameEdit->GetText());
194  gCoreContext->SaveSetting("MythNativeDestinationType", m_destinationSelector->GetCurrentPos());
195  }
196  else
197  {
198  gCoreContext->SaveSetting("MythBurnCreateISO",
200  gCoreContext->SaveSetting("MythBurnBurnDVDr",
202  gCoreContext->SaveSetting("MythBurnEraseDvdRw",
204  gCoreContext->SaveSetting("MythBurnSaveFilename", m_filenameEdit->GetText());
205  gCoreContext->SaveSetting("MythBurnDestinationType", m_destinationSelector->GetCurrentPos());
206  }
207 }
208 
210 {
211  if (!item)
212  return;
213 
214  size_t itemNo = item->GetData().value<ARCHIVEDESTINATION>();
215 
216  if (itemNo > ArchiveDestinations.size() - 1)
217  itemNo = 0;
218 
219  m_destinationText->SetText(tr(ArchiveDestinations[itemNo].description));
220 
222 
223  switch(itemNo)
224  {
225  case AD_DVD_SL:
226  case AD_DVD_DL:
227  m_filenameEdit->Hide();
228  m_findButton->Hide();
231  m_doBurnCheck->Show();
232  m_doBurnText->Show();
233  break;
234  case AD_DVD_RW:
235  m_filenameEdit->Hide();
236  m_findButton->Hide();
239  m_doBurnCheck->Show();
240  m_doBurnText->Show();
241  break;
242  case AD_FILE:
243  int64_t dummy = 0;
244  ArchiveDestinations[itemNo].freeSpace =
245  getDiskSpace(m_filenameEdit->GetText(), dummy, dummy);
246 
247  m_filenameEdit->Show();
248  m_findButton->Show();
251  m_doBurnCheck->Hide();
252  m_doBurnText->Hide();
253  break;
254  }
255 
256  // update free space
257  if (ArchiveDestinations[itemNo].freeSpace != -1)
258  {
260  m_freeSpace = ArchiveDestinations[itemNo].freeSpace / 1024;
261  }
262  else
263  {
264  m_freespaceText->SetText(tr("Unknown"));
265  m_freeSpace = 0;
266  }
267 
268  BuildFocusList();
269 }
270 
272 {
274 
275  auto *selector = new
276  FileSelector(mainStack, nullptr, FSTYPE_DIRECTORY, m_filenameEdit->GetText(), "*.*");
277 
278  connect(selector, qOverload<QString>(&FileSelector::haveResult),
280 
281  if (selector->Create())
282  mainStack->AddScreen(selector);
283 }
284 
286 {
287  if (filename != "")
288  {
291  }
292 }
293 
295 {
296  int64_t dummy = 0;
298 
299  // if we don't get a valid freespace value it probably means the file doesn't
300  // exist yet so try looking up the freespace for the parent directory
302  {
303  QString dir = m_filenameEdit->GetText();
304  int pos = dir.lastIndexOf('/');
305  if (pos > 0)
306  dir = dir.left(pos);
307  else
308  dir = "/";
309 
310  m_archiveDestination.freeSpace = getDiskSpace(dir, dummy, dummy);
311  }
312 
314  {
317  }
318  else
319  {
320  m_freespaceText->SetText(tr("Unknown"));
321  m_freeSpace = 0;
322  }
323 }
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:143
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:383
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:183
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:209
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:110
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
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:294
archiveutil.h
SelectDestination::m_findButton
MythUIButton * m_findButton
Definition: selectdestination.h:63
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:115
SelectDestination::loadConfiguration
void loadConfiguration(void)
Definition: selectdestination.cpp:148
SelectDestination::m_cancelButton
MythUIButton * m_cancelButton
Definition: selectdestination.h:55
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:203
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:55
SelectDestination::fileFinderClosed
void fileFinderClosed(const QString &filename)
Definition: selectdestination.cpp:285
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:916
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:401
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:138
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
mythcontext.h
SelectDestination::m_doBurnText
MythUIText * m_doBurnText
Definition: selectdestination.h:69
SelectDestination::handleFind
void handleFind(void)
Definition: selectdestination.cpp:271
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:116
FSTYPE_DIRECTORY
@ FSTYPE_DIRECTORY
Definition: fileselector.h:30
MythUIStateType::Full
@ Full
Definition: mythuistatetype.h:27
SelectDestination::~SelectDestination
~SelectDestination(void) override
Definition: selectdestination.cpp:27
SelectDestination::m_prevButton
MythUIButton * m_prevButton
Definition: selectdestination.h:54
SelectDestination::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: selectdestination.cpp:88
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:885
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:33
SelectDestination::m_createISOCheck
MythUICheckBox * m_createISOCheck
Definition: selectdestination.h:65
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:902