MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
selectdestination.cpp
Go to the documentation of this file.
1 #include <unistd.h>
2 
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <iostream>
6 #include <cstdlib>
7 
8 // qt
9 #include <QDir>
10 #include <QKeyEvent>
11 
12 // myth
13 #include <mythcontext.h>
14 #include <mythcoreutil.h>
15 #include <mythuitext.h>
16 #include <mythuibutton.h>
17 #include <mythuicheckbox.h>
18 #include <mythuibuttonlist.h>
19 #include <mythuitextedit.h>
20 #include <mythmainwindow.h>
21 
22 // mytharchive
23 #include "selectdestination.h"
24 #include "fileselector.h"
25 #include "archiveutil.h"
26 #include "exportnative.h"
27 #include "themeselector.h"
28 
30  MythScreenStack *parent, bool nativeMode, QString name) :
31  MythScreenType(parent, name),
32  m_nativeMode(nativeMode),
33  m_freeSpace(0),
34  m_nextButton(NULL),
35  m_prevButton(NULL),
36  m_cancelButton(NULL),
37  m_destinationSelector(NULL),
38  m_destinationText(NULL),
39  m_freespaceText(NULL),
40  m_filenameEdit(NULL),
41  m_findButton(NULL),
42  m_createISOCheck(NULL),
43  m_doBurnCheck(NULL),
44  m_eraseDvdRwCheck(NULL),
45  m_createISOText(NULL),
46  m_doBurnText(NULL),
47  m_eraseDvdRwText(NULL)
48 {
53 }
54 
56 {
58 }
59 
60 
62 {
63  bool foundtheme = false;
64 
65  // Load the theme for this screen
66  foundtheme = LoadWindowFromXML("mytharchive-ui.xml", "selectdestination", this);
67 
68  if (!foundtheme)
69  return false;
70 
71  bool err = false;
72  UIUtilE::Assign(this, m_createISOCheck, "makeisoimage_check", &err);
73  UIUtilE::Assign(this, m_doBurnCheck, "burntodvdr_check", &err);
74  UIUtilE::Assign(this, m_doBurnText, "burntodvdr_text", &err);
75  UIUtilE::Assign(this, m_eraseDvdRwCheck, "erasedvdrw_check", &err);
76  UIUtilE::Assign(this, m_eraseDvdRwText, "erasedvdrw_text", &err);
77  UIUtilE::Assign(this, m_nextButton, "next_button", &err);
78  UIUtilE::Assign(this, m_prevButton, "prev_button", &err);
79  UIUtilE::Assign(this, m_cancelButton, "cancel_button", &err);
80  UIUtilE::Assign(this, m_destinationSelector, "destination_selector", &err);
81  UIUtilE::Assign(this, m_destinationText, "destination_text", &err);
82  UIUtilE::Assign(this, m_findButton, "find_button", &err);
83  UIUtilE::Assign(this, m_filenameEdit, "filename_edit", &err);
84  UIUtilE::Assign(this, m_freespaceText, "freespace_text", &err);
85 
86  if (err)
87  {
88  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'selectdestination'");
89  return false;
90  }
91 
92  connect(m_nextButton, SIGNAL(Clicked()), this, SLOT(handleNextPage()));
93  connect(m_prevButton, SIGNAL(Clicked()), this, SLOT(handlePrevPage()));
94  connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(handleCancel()));
95 
96  connect(m_destinationSelector, SIGNAL(itemSelected(MythUIButtonListItem*)),
97  this, SLOT(setDestination(MythUIButtonListItem*)));
98 
99  for (int x = 0; x < ArchiveDestinationsCount; x++)
100  {
101  MythUIButtonListItem *item = new
103  item->SetData(qVariantFromValue(ArchiveDestinations[x].type));
104  }
105  connect(m_findButton, SIGNAL(Clicked()), this, SLOT(handleFind()));
106 
107  connect(m_filenameEdit, SIGNAL(LosingFocus()), this,
108  SLOT(filenameEditLostFocus()));
109 
110  BuildFocusList();
111 
113 
115 
116  return true;
117 }
118 
119 bool SelectDestination::keyPressEvent(QKeyEvent *event)
120 {
121  if (GetFocusWidget()->keyPressEvent(event))
122  return true;
123 
124  bool handled = false;
125  QStringList actions;
126  handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
127 
128  for (int i = 0; i < actions.size() && !handled; i++)
129  {
130  QString action = actions[i];
131  handled = true;
132 
133  if (action == "MENU")
134  {
135  }
136  else
137  handled = false;
138  }
139 
140  if (!handled && MythScreenType::keyPressEvent(event))
141  handled = true;
142 
143  return handled;
144 }
145 
147 {
149 
151 
152  if (m_nativeMode)
153  {
154  ExportNative *native = new ExportNative(mainStack, this, m_archiveDestination, "ExportNative");
155 
156  if (native->Create())
157  mainStack->AddScreen(native);
158  }
159  else
160  {
161  DVDThemeSelector *theme = new DVDThemeSelector(mainStack, this, m_archiveDestination, "ThemeSelector");
162 
163  if (theme->Create())
164  mainStack->AddScreen(theme);
165  }
166 }
167 
169 {
170  Close();
171 }
172 
174 {
175  Close();
176 }
177 
179 {
180  bool bCreateISO = false;
181  bool bDoBurn = false;
182  bool bEraseDvdRw = false;
183  QString saveFilename = "";
184  int destinationType = 0;
185 
186  if (m_nativeMode)
187  {
188  bCreateISO = (gCoreContext->GetSetting("MythNativeCreateISO", "0") == "1");
189  bDoBurn = (gCoreContext->GetSetting("MythNativeBurnDVDr", "1") == "1");
190  bEraseDvdRw = (gCoreContext->GetSetting("MythNativeEraseDvdRw", "0") == "1");
191  saveFilename = gCoreContext->GetSetting("MythNativeSaveFilename", "");
192  destinationType = gCoreContext->GetNumSetting("MythNativeDestinationType", 0);
193  }
194  else
195  {
196  bCreateISO = (gCoreContext->GetSetting("MythBurnCreateISO", "0") == "1");
197  bDoBurn = (gCoreContext->GetSetting("MythBurnBurnDVDr", "1") == "1");
198  bEraseDvdRw = (gCoreContext->GetSetting("MythBurnEraseDvdRw", "0") == "1");
199  saveFilename = gCoreContext->GetSetting("MythBurnSaveFilename", "");
200  destinationType = gCoreContext->GetNumSetting("MythBurnDestinationType", 0);
201  }
202 
204  m_doBurnCheck->SetCheckState((bDoBurn ? MythUIStateType::Full : MythUIStateType::Off));
205  m_eraseDvdRwCheck->SetCheckState((bEraseDvdRw ? MythUIStateType::Full : MythUIStateType::Off));
206  m_filenameEdit->SetText(saveFilename);
207 
208  if (destinationType < 0 || destinationType >= m_destinationSelector->GetCount())
209  destinationType = 0;
210  m_destinationSelector->SetItemCurrent(destinationType);
211 }
212 
214 {
215  if (m_nativeMode)
216  {
217  gCoreContext->SaveSetting("MythNativeCreateISO",
219  gCoreContext->SaveSetting("MythNativeBurnDVDr",
221  gCoreContext->SaveSetting("MythNativeEraseDvdRw",
223  gCoreContext->SaveSetting("MythNativeSaveFilename", m_filenameEdit->GetText());
224  gCoreContext->SaveSetting("MythNativeDestinationType", m_destinationSelector->GetCurrentPos());
225  }
226  else
227  {
228  gCoreContext->SaveSetting("MythBurnCreateISO",
230  gCoreContext->SaveSetting("MythBurnBurnDVDr",
232  gCoreContext->SaveSetting("MythBurnEraseDvdRw",
234  gCoreContext->SaveSetting("MythBurnSaveFilename", m_filenameEdit->GetText());
235  gCoreContext->SaveSetting("MythBurnDestinationType", m_destinationSelector->GetCurrentPos());
236  }
237 }
238 
240 {
241  if (!item)
242  return;
243 
244  int itemNo = item->GetData().value<ARCHIVEDESTINATION>();
245 
246  if (itemNo < 0 || itemNo > ArchiveDestinationsCount - 1)
247  itemNo = 0;
248 
250 
252 
253  switch(itemNo)
254  {
255  case AD_DVD_SL:
256  case AD_DVD_DL:
257  m_filenameEdit->Hide();
258  m_findButton->Hide();
261  m_doBurnCheck->Show();
262  m_doBurnText->Show();
263  break;
264  case AD_DVD_RW:
265  m_filenameEdit->Hide();
266  m_findButton->Hide();
269  m_doBurnCheck->Show();
270  m_doBurnText->Show();
271  break;
272  case AD_FILE:
273  int64_t dummy;
274  ArchiveDestinations[itemNo].freeSpace =
276 
277  m_filenameEdit->Show();
278  m_findButton->Show();
281  m_doBurnCheck->Hide();
282  m_doBurnText->Hide();
283  break;
284  }
285 
286  // update free space
287  if (ArchiveDestinations[itemNo].freeSpace != -1)
288  {
289  m_freespaceText->SetText(formatSize(ArchiveDestinations[itemNo].freeSpace, 2));
290  m_freeSpace = ArchiveDestinations[itemNo].freeSpace / 1024;
291  }
292  else
293  {
294  m_freespaceText->SetText(tr("Unknown"));
295  m_freeSpace = 0;
296  }
297 
298  BuildFocusList();
299 }
300 
302 {
304 
305  FileSelector *selector = new
306  FileSelector(mainStack, NULL, FSTYPE_DIRECTORY, m_filenameEdit->GetText(), "*.*");
307 
308  connect(selector, SIGNAL(haveResult(QString)),
309  this, SLOT(fileFinderClosed(QString)));
310 
311  if (selector->Create())
312  mainStack->AddScreen(selector);
313 }
314 
316 {
317  if (filename != "")
318  {
319  m_filenameEdit->SetText(filename);
321  }
322 }
323 
325 {
326  int64_t dummy;
328 
329  // if we don't get a valid freespace value it probably means the file doesn't
330  // exist yet so try looking up the freespace for the parent directory
332  {
333  QString dir = m_filenameEdit->GetText();
334  int pos = dir.lastIndexOf('/');
335  if (pos > 0)
336  dir = dir.left(pos);
337  else
338  dir = "/";
339 
340  m_archiveDestination.freeSpace = getDiskSpace(dir, dummy, dummy);
341  }
342 
344  {
347  }
348  else
349  {
350  m_freespaceText->SetText(tr("Unknown"));
351  m_freeSpace = 0;
352  }
353 }