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
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
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:
234 break;
235 case AD_DVD_RW:
242 break;
243 case AD_FILE:
244 ArchiveDestinations[itemNo].freeSpace =
246
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
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 auto fsInfo = FileSystemInfo(QString(), m_filenameEdit->GetText());
297
298 // if we don't get a valid freespace value it probably means the file doesn't
299 // exist yet so try looking up the freespace for the parent directory
300 if (!fsInfo.refresh())
301 {
302 QString dir = m_filenameEdit->GetText();
303 int pos = dir.lastIndexOf('/');
304 if (pos > 0)
305 dir = dir.left(pos);
306 else
307 dir = "/";
308
309 fsInfo = FileSystemInfo(QString(), dir);
310 }
311
312 if (fsInfo.refresh())
313 {
314 m_archiveDestination.freeSpace = fsInfo.getFreeSpace();
317 }
318 else
319 {
321 m_freespaceText->SetText(tr("Unknown"));
322 m_freeSpace = 0;
323 }
324}
std::vector< ArchiveDestination > ArchiveDestinations
Definition: archiveutil.cpp:27
ARCHIVEDESTINATION
Definition: archiveutil.h:17
@ AD_DVD_SL
Definition: archiveutil.h:18
@ AD_FILE
Definition: archiveutil.h:21
@ AD_DVD_DL
Definition: archiveutil.h:19
@ AD_DVD_RW
Definition: archiveutil.h:20
void haveResult(bool ok)
int64_t getFreeSpace() const
void SaveSetting(const QString &key, int newValue)
QString GetSetting(const QString &key, const QString &defaultval="")
int GetNumSetting(const QString &key, int defaultval=0)
MythScreenStack * GetMainStack()
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void BuildFocusList(void)
MythUIType * GetFocusWidget(void) const
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
bool SetFocusWidget(MythUIType *widget=nullptr)
virtual void Close()
void SetItemCurrent(MythUIButtonListItem *item)
int GetCurrentPos() const
void itemSelected(MythUIButtonListItem *item)
void Clicked()
void SetCheckState(MythUIStateType::StateType state)
MythUIStateType::StateType GetCheckState() const
QString GetText(void) const
void SetText(const QString &text, bool moveCursor=true)
virtual void SetText(const QString &text)
Definition: mythuitext.cpp:115
void Hide(void)
void Show(void)
void LosingFocus(void)
MythUIText * m_freespaceText
void filenameEditLostFocus(void)
MythUIButton * m_prevButton
MythUIText * m_eraseDvdRwText
MythUICheckBox * m_doBurnCheck
void fileFinderClosed(const QString &filename)
bool Create(void) override
MythUIButton * m_findButton
MythUIText * m_destinationText
MythUIButton * m_nextButton
MythUIButtonList * m_destinationSelector
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
MythUIText * m_doBurnText
MythUICheckBox * m_createISOCheck
MythUICheckBox * m_eraseDvdRwCheck
~SelectDestination(void) override
MythUITextEdit * m_filenameEdit
ArchiveDestination m_archiveDestination
void setDestination(MythUIButtonListItem *item)
MythUIButton * m_cancelButton
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
@ FSTYPE_DIRECTORY
Definition: fileselector.h:30
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
MBASE_PUBLIC QString formatKBytes(int64_t sizeKB, int prec=1)
Definition: stringutil.cpp:357
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
Definition: mythuiutils.h:27