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  QString action = actions[i];
99  handled = true;
100 
101  if (action == "MENU")
102  {
103  }
104  else
105  handled = false;
106  }
107 
108  if (!handled && MythScreenType::keyPressEvent(event))
109  handled = true;
110 
111  return handled;
112 }
113 
115 {
117 
119 
120  if (m_nativeMode)
121  {
122  auto *native = new ExportNative(mainStack, this, m_archiveDestination, "ExportNative");
123 
124  if (native->Create())
125  mainStack->AddScreen(native);
126  }
127  else
128  {
129  auto *theme = new DVDThemeSelector(mainStack, this, m_archiveDestination, "ThemeSelector");
130 
131  if (theme->Create())
132  mainStack->AddScreen(theme);
133  }
134 }
135 
137 {
138  Close();
139 }
140 
142 {
143  Close();
144 }
145 
147 {
148  bool bCreateISO = false;
149  bool bDoBurn = false;
150  bool bEraseDvdRw = false;
151  QString saveFilename = "";
152  int destinationType = 0;
153 
154  if (m_nativeMode)
155  {
156  bCreateISO = (gCoreContext->GetSetting("MythNativeCreateISO", "0") == "1");
157  bDoBurn = (gCoreContext->GetSetting("MythNativeBurnDVDr", "1") == "1");
158  bEraseDvdRw = (gCoreContext->GetSetting("MythNativeEraseDvdRw", "0") == "1");
159  saveFilename = gCoreContext->GetSetting("MythNativeSaveFilename", "");
160  destinationType = gCoreContext->GetNumSetting("MythNativeDestinationType", 0);
161  }
162  else
163  {
164  bCreateISO = (gCoreContext->GetSetting("MythBurnCreateISO", "0") == "1");
165  bDoBurn = (gCoreContext->GetSetting("MythBurnBurnDVDr", "1") == "1");
166  bEraseDvdRw = (gCoreContext->GetSetting("MythBurnEraseDvdRw", "0") == "1");
167  saveFilename = gCoreContext->GetSetting("MythBurnSaveFilename", "");
168  destinationType = gCoreContext->GetNumSetting("MythBurnDestinationType", 0);
169  }
170 
174  m_filenameEdit->SetText(saveFilename);
175 
176  if (destinationType < 0 || destinationType >= m_destinationSelector->GetCount())
177  destinationType = 0;
178  m_destinationSelector->SetItemCurrent(destinationType);
179 }
180 
182 {
183  if (m_nativeMode)
184  {
185  gCoreContext->SaveSetting("MythNativeCreateISO",
187  gCoreContext->SaveSetting("MythNativeBurnDVDr",
189  gCoreContext->SaveSetting("MythNativeEraseDvdRw",
191  gCoreContext->SaveSetting("MythNativeSaveFilename", m_filenameEdit->GetText());
192  gCoreContext->SaveSetting("MythNativeDestinationType", m_destinationSelector->GetCurrentPos());
193  }
194  else
195  {
196  gCoreContext->SaveSetting("MythBurnCreateISO",
198  gCoreContext->SaveSetting("MythBurnBurnDVDr",
200  gCoreContext->SaveSetting("MythBurnEraseDvdRw",
202  gCoreContext->SaveSetting("MythBurnSaveFilename", m_filenameEdit->GetText());
203  gCoreContext->SaveSetting("MythBurnDestinationType", m_destinationSelector->GetCurrentPos());
204  }
205 }
206 
208 {
209  if (!item)
210  return;
211 
212  size_t itemNo = item->GetData().value<ARCHIVEDESTINATION>();
213 
214  if (itemNo > ArchiveDestinations.size() - 1)
215  itemNo = 0;
216 
217  m_destinationText->SetText(tr(ArchiveDestinations[itemNo].description));
218 
220 
221  switch(itemNo)
222  {
223  case AD_DVD_SL:
224  case AD_DVD_DL:
225  m_filenameEdit->Hide();
226  m_findButton->Hide();
229  m_doBurnCheck->Show();
230  m_doBurnText->Show();
231  break;
232  case AD_DVD_RW:
233  m_filenameEdit->Hide();
234  m_findButton->Hide();
237  m_doBurnCheck->Show();
238  m_doBurnText->Show();
239  break;
240  case AD_FILE:
241  int64_t dummy = 0;
242  ArchiveDestinations[itemNo].freeSpace =
243  getDiskSpace(m_filenameEdit->GetText(), dummy, dummy);
244 
245  m_filenameEdit->Show();
246  m_findButton->Show();
249  m_doBurnCheck->Hide();
250  m_doBurnText->Hide();
251  break;
252  }
253 
254  // update free space
255  if (ArchiveDestinations[itemNo].freeSpace != -1)
256  {
258  m_freeSpace = ArchiveDestinations[itemNo].freeSpace / 1024;
259  }
260  else
261  {
262  m_freespaceText->SetText(tr("Unknown"));
263  m_freeSpace = 0;
264  }
265 
266  BuildFocusList();
267 }
268 
270 {
272 
273  auto *selector = new
274  FileSelector(mainStack, nullptr, FSTYPE_DIRECTORY, m_filenameEdit->GetText(), "*.*");
275 
276  connect(selector, qOverload<QString>(&FileSelector::haveResult),
278 
279  if (selector->Create())
280  mainStack->AddScreen(selector);
281 }
282 
284 {
285  if (filename != "")
286  {
289  }
290 }
291 
293 {
294  int64_t dummy = 0;
296 
297  // if we don't get a valid freespace value it probably means the file doesn't
298  // exist yet so try looking up the freespace for the parent directory
300  {
301  QString dir = m_filenameEdit->GetText();
302  int pos = dir.lastIndexOf('/');
303  if (pos > 0)
304  dir = dir.left(pos);
305  else
306  dir = "/";
307 
308  m_archiveDestination.freeSpace = getDiskSpace(dir, dummy, dummy);
309  }
310 
312  {
315  }
316  else
317  {
318  m_freespaceText->SetText(tr("Unknown"));
319  m_freeSpace = 0;
320  }
321 }
MythUIButton::Clicked
void Clicked()
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:318
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:141
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:386
SelectDestination::m_destinationSelector
MythUIButtonList * m_destinationSelector
Definition: selectdestination.h:57
AD_DVD_SL
@ AD_DVD_SL
Definition: archiveutil.h:18
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:181
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:207
MythUIButtonList::GetCount
int GetCount() const
Definition: mythuibuttonlist.cpp:1652
DVDThemeSelector
Definition: themeselector.h:19
FSTYPE_DIRECTORY
@ FSTYPE_DIRECTORY
Definition: fileselector.h:30
selectdestination.h
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:113
ARCHIVEDESTINATION
ARCHIVEDESTINATION
Definition: archiveutil.h:16
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
MythUITextEdit::SetText
void SetText(const QString &text, bool moveCursor=true)
Definition: mythuitextedit.cpp:197
FileSelector
Definition: fileselector.h:39
MythUIType::Show
void Show(void)
Definition: mythuitype.cpp:1147
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:238
AD_DVD_RW
@ AD_DVD_RW
Definition: archiveutil.h:20
SelectDestination::filenameEditLostFocus
void filenameEditLostFocus(void)
Definition: selectdestination.cpp:292
archiveutil.h
SelectDestination::m_findButton
MythUIButton * m_findButton
Definition: selectdestination.h:63
MythScreenType::SetFocusWidget
bool SetFocusWidget(MythUIType *widget=nullptr)
Definition: mythscreentype.cpp:118
SelectDestination::loadConfiguration
void loadConfiguration(void)
Definition: selectdestination.cpp:146
SelectDestination::m_cancelButton
MythUIButton * m_cancelButton
Definition: selectdestination.h:55
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:206
SelectDestination::m_eraseDvdRwText
MythUIText * m_eraseDvdRwText
Definition: selectdestination.h:70
stringutil.h
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:3665
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:283
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:911
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:1142
StringUtil::formatKBytes
MBASE_PUBLIC QString formatKBytes(int64_t sizeKB, int prec=1)
Definition: stringutil.cpp:357
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:404
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:695
SelectDestination::handlePrevPage
void handlePrevPage(void)
Definition: selectdestination.cpp:136
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:132
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:269
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythUIButtonList::SetItemCurrent
void SetItemCurrent(MythUIButtonListItem *item)
Definition: mythuibuttonlist.cpp:1554
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
SelectDestination::handleNextPage
void handleNextPage(void)
Definition: selectdestination.cpp:114
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:880
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:897