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 
63 
66 
67  for (const auto & dest : ArchiveDestinations)
68  {
69  auto *item = new
71  item->SetData(QVariant::fromValue(dest.type));
72  }
74 
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  size_t itemNo = item->GetData().value<ARCHIVEDESTINATION>();
212 
213  if (itemNo > ArchiveDestinations.size() - 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, qOverload<QString>(&FileSelector::haveResult),
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 
308  }
309 
311  {
314  }
315  else
316  {
317  m_freespaceText->SetText(tr("Unknown"));
318  m_freeSpace = 0;
319  }
320 }
MythUIButton::Clicked
void Clicked()
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:324
build_compdb.dest
dest
Definition: build_compdb.py:9
exportnative.h
mythuitext.h
fileselector.h
SelectDestination::m_nativeMode
bool m_nativeMode
Definition: selectdestination.h:48
SelectDestination::handleCancel
void handleCancel(void)
Definition: selectdestination.cpp:140
getDiskSpace
int64_t getDiskSpace(const QString &file_on_disk, int64_t &total, int64_t &used)
Definition: mythcoreutil.cpp:43
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:402
SelectDestination::m_destinationSelector
MythUIButtonList * m_destinationSelector
Definition: selectdestination.h:57
AD_DVD_SL
@ AD_DVD_SL
Definition: archiveutil.h:18
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1142
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
MythScreenStack
Definition: mythscreenstack.h:16
SelectDestination::saveConfiguration
void saveConfiguration(void)
Definition: selectdestination.cpp:180
ExportNative
Definition: exportnative.h:30
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythUITextEdit::GetText
QString GetText(void) const
Definition: mythuitextedit.h:47
SelectDestination::m_freeSpace
int m_freeSpace
Definition: selectdestination.h:51
mythuibuttonlist.h
SelectDestination::setDestination
void setDestination(MythUIButtonListItem *item)
Definition: selectdestination.cpp:206
MythUIButtonList::GetCount
int GetCount() const
Definition: mythuibuttonlist.cpp:1655
DVDThemeSelector
Definition: themeselector.h:20
FSTYPE_DIRECTORY
@ FSTYPE_DIRECTORY
Definition: fileselector.h:30
selectdestination.h
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:112
ARCHIVEDESTINATION
ARCHIVEDESTINATION
Definition: archiveutil.h:17
MythUIButtonListItem
Definition: mythuibuttonlist.h:28
MythUITextEdit::SetText
void SetText(const QString &text, bool moveCursor=true)
Definition: mythuitextedit.cpp:216
FileSelector
Definition: fileselector.h:40
MythUIType::Show
void Show(void)
Definition: mythuitype.cpp:1125
MythUIButtonList::GetCurrentPos
int GetCurrentPos() const
Definition: mythuibuttonlist.h:198
AD_DVD_RW
@ AD_DVD_RW
Definition: archiveutil.h:20
SelectDestination::filenameEditLostFocus
void filenameEditLostFocus(void)
Definition: selectdestination.cpp:291
archiveutil.h
SelectDestination::m_findButton
MythUIButton * m_findButton
Definition: selectdestination.h:63
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:117
SelectDestination::loadConfiguration
void loadConfiguration(void)
Definition: selectdestination.cpp:145
SelectDestination::m_cancelButton
MythUIButton * m_cancelButton
Definition: selectdestination.h:55
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:222
SelectDestination::m_eraseDvdRwText
MythUIText * m_eraseDvdRwText
Definition: selectdestination.h:70
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:637
SelectDestination::m_nextButton
MythUIButton * m_nextButton
Definition: selectdestination.h:53
SelectDestination::m_archiveDestination
ArchiveDestination m_archiveDestination
Definition: selectdestination.h:50
MythUIStateType::Full
@ Full
Definition: mythuistatetype.h:25
MythUIButtonListItem::GetData
QVariant GetData()
Definition: mythuibuttonlist.cpp:3580
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
SelectDestination::fileFinderClosed
void fileFinderClosed(const QString &filename)
Definition: selectdestination.cpp:282
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:933
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:1120
SelectDestination::m_destinationText
MythUIText * m_destinationText
Definition: selectdestination.h:58
MythUIStateType::Off
@ Off
Definition: mythuistatetype.h:25
themeselector.h
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:414
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:692
dir
QDir dir
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1174
SelectDestination::handlePrevPage
void handlePrevPage(void)
Definition: selectdestination.cpp:135
FileSelector::haveResult
void haveResult(bool ok)
ArchiveDestinations
std::vector< ArchiveDestination > ArchiveDestinations
Definition: archiveutil.cpp:28
SelectDestination::m_eraseDvdRwCheck
MythUICheckBox * m_eraseDvdRwCheck
Definition: selectdestination.h:67
MythUIText::SetText
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:134
mythcontext.h
AD_DVD_DL
@ AD_DVD_DL
Definition: archiveutil.h:19
SelectDestination::m_doBurnText
MythUIText * m_doBurnText
Definition: selectdestination.h:69
SelectDestination::handleFind
void handleFind(void)
Definition: selectdestination.cpp:268
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:108
MythUIButtonList::SetItemCurrent
void SetItemCurrent(MythUIButtonListItem *item)
Definition: mythuibuttonlist.cpp:1557
build_compdb.action
action
Definition: build_compdb.py:9
AD_FILE
@ AD_FILE
Definition: archiveutil.h:21
SelectDestination::m_freespaceText
MythUIText * m_freespaceText
Definition: selectdestination.h:60
mythuibutton.h
formatSize
static QString formatSize(int64_t sizeKB, int prec)
Definition: recordingutils.cpp:22
SelectDestination::handleNextPage
void handleNextPage(void)
Definition: selectdestination.cpp:113
SelectDestination::~SelectDestination
~SelectDestination(void) override
Definition: selectdestination.cpp:26
SelectDestination::m_prevButton
MythUIButton * m_prevButton
Definition: selectdestination.h:54
SelectDestination::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: selectdestination.cpp:87
MythCoreContext::SaveSetting
void SaveSetting(const QString &key, int newValue)
Definition: mythcorecontext.cpp:902
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
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:32
SelectDestination::m_createISOCheck
MythUICheckBox * m_createISOCheck
Definition: selectdestination.h:65
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:919