00001 #include <unistd.h>
00002
00003 #include <stdlib.h>
00004 #include <unistd.h>
00005 #include <iostream>
00006 #include <cstdlib>
00007
00008
00009 #include <QDir>
00010 #include <QKeyEvent>
00011
00012
00013 #include <mythcontext.h>
00014 #include <mythcoreutil.h>
00015 #include <mythuitext.h>
00016 #include <mythuibutton.h>
00017 #include <mythuicheckbox.h>
00018 #include <mythuibuttonlist.h>
00019 #include <mythuitextedit.h>
00020 #include <mythmainwindow.h>
00021
00022
00023 #include "selectdestination.h"
00024 #include "fileselector.h"
00025 #include "archiveutil.h"
00026 #include "exportnative.h"
00027 #include "themeselector.h"
00028
00029 SelectDestination::SelectDestination(
00030 MythScreenStack *parent, bool nativeMode, QString name) :
00031 MythScreenType(parent, name),
00032 m_nativeMode(nativeMode),
00033 m_freeSpace(0),
00034 m_nextButton(NULL),
00035 m_prevButton(NULL),
00036 m_cancelButton(NULL),
00037 m_destinationSelector(NULL),
00038 m_destinationText(NULL),
00039 m_freespaceText(NULL),
00040 m_filenameEdit(NULL),
00041 m_findButton(NULL),
00042 m_createISOCheck(NULL),
00043 m_doBurnCheck(NULL),
00044 m_eraseDvdRwCheck(NULL),
00045 m_createISOText(NULL),
00046 m_doBurnText(NULL),
00047 m_eraseDvdRwText(NULL)
00048 {
00049 m_archiveDestination.type = AD_FILE;
00050 m_archiveDestination.name = NULL;
00051 m_archiveDestination.description = NULL;
00052 m_archiveDestination.freeSpace = 0LL;
00053 }
00054
00055 SelectDestination::~SelectDestination(void)
00056 {
00057 saveConfiguration();
00058 }
00059
00060
00061 bool SelectDestination::Create(void)
00062 {
00063 bool foundtheme = false;
00064
00065
00066 foundtheme = LoadWindowFromXML("mytharchive-ui.xml", "selectdestination", this);
00067
00068 if (!foundtheme)
00069 return false;
00070
00071 bool err = false;
00072 UIUtilE::Assign(this, m_createISOCheck, "makeisoimage_check", &err);
00073 UIUtilE::Assign(this, m_doBurnCheck, "burntodvdr_check", &err);
00074 UIUtilE::Assign(this, m_doBurnText, "burntodvdr_text", &err);
00075 UIUtilE::Assign(this, m_eraseDvdRwCheck, "erasedvdrw_check", &err);
00076 UIUtilE::Assign(this, m_eraseDvdRwText, "erasedvdrw_text", &err);
00077 UIUtilE::Assign(this, m_nextButton, "next_button", &err);
00078 UIUtilE::Assign(this, m_prevButton, "prev_button", &err);
00079 UIUtilE::Assign(this, m_cancelButton, "cancel_button", &err);
00080 UIUtilE::Assign(this, m_destinationSelector, "destination_selector", &err);
00081 UIUtilE::Assign(this, m_destinationText, "destination_text", &err);
00082 UIUtilE::Assign(this, m_findButton, "find_button", &err);
00083 UIUtilE::Assign(this, m_filenameEdit, "filename_edit", &err);
00084 UIUtilE::Assign(this, m_freespaceText, "freespace_text", &err);
00085
00086 if (err)
00087 {
00088 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'selectdestination'");
00089 return false;
00090 }
00091
00092 connect(m_nextButton, SIGNAL(Clicked()), this, SLOT(handleNextPage()));
00093 connect(m_prevButton, SIGNAL(Clicked()), this, SLOT(handlePrevPage()));
00094 connect(m_cancelButton, SIGNAL(Clicked()), this, SLOT(handleCancel()));
00095
00096 connect(m_destinationSelector, SIGNAL(itemSelected(MythUIButtonListItem*)),
00097 this, SLOT(setDestination(MythUIButtonListItem*)));
00098
00099 for (int x = 0; x < ArchiveDestinationsCount; x++)
00100 {
00101 MythUIButtonListItem *item = new
00102 MythUIButtonListItem(m_destinationSelector, tr(ArchiveDestinations[x].name));
00103 item->SetData(qVariantFromValue(ArchiveDestinations[x].type));
00104 }
00105 connect(m_findButton, SIGNAL(Clicked()), this, SLOT(handleFind()));
00106
00107 connect(m_filenameEdit, SIGNAL(LosingFocus()), this,
00108 SLOT(filenameEditLostFocus()));
00109
00110 BuildFocusList();
00111
00112 SetFocusWidget(m_nextButton);
00113
00114 loadConfiguration();
00115
00116 return true;
00117 }
00118
00119 bool SelectDestination::keyPressEvent(QKeyEvent *event)
00120 {
00121 if (GetFocusWidget()->keyPressEvent(event))
00122 return true;
00123
00124 bool handled = false;
00125 QStringList actions;
00126 handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions);
00127
00128 for (int i = 0; i < actions.size() && !handled; i++)
00129 {
00130 QString action = actions[i];
00131 handled = true;
00132
00133 if (action == "MENU")
00134 {
00135 }
00136 else
00137 handled = false;
00138 }
00139
00140 if (!handled && MythScreenType::keyPressEvent(event))
00141 handled = true;
00142
00143 return handled;
00144 }
00145
00146 void SelectDestination::handleNextPage()
00147 {
00148 saveConfiguration();
00149
00150 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00151
00152 if (m_nativeMode)
00153 {
00154 ExportNative *native = new ExportNative(mainStack, this, m_archiveDestination, "ExportNative");
00155
00156 if (native->Create())
00157 mainStack->AddScreen(native);
00158 }
00159 else
00160 {
00161 DVDThemeSelector *theme = new DVDThemeSelector(mainStack, this, m_archiveDestination, "ThemeSelector");
00162
00163 if (theme->Create())
00164 mainStack->AddScreen(theme);
00165 }
00166 }
00167
00168 void SelectDestination::handlePrevPage()
00169 {
00170 Close();
00171 }
00172
00173 void SelectDestination::handleCancel()
00174 {
00175 Close();
00176 }
00177
00178 void SelectDestination::loadConfiguration(void)
00179 {
00180 bool bCreateISO = false;
00181 bool bDoBurn = false;
00182 bool bEraseDvdRw = false;
00183 QString saveFilename = "";
00184 int destinationType = 0;
00185
00186 if (m_nativeMode)
00187 {
00188 bCreateISO = (gCoreContext->GetSetting("MythNativeCreateISO", "0") == "1");
00189 bDoBurn = (gCoreContext->GetSetting("MythNativeBurnDVDr", "1") == "1");
00190 bEraseDvdRw = (gCoreContext->GetSetting("MythNativeEraseDvdRw", "0") == "1");
00191 saveFilename = gCoreContext->GetSetting("MythNativeSaveFilename", "");
00192 destinationType = gCoreContext->GetNumSetting("MythNativeDestinationType", 0);
00193 }
00194 else
00195 {
00196 bCreateISO = (gCoreContext->GetSetting("MythBurnCreateISO", "0") == "1");
00197 bDoBurn = (gCoreContext->GetSetting("MythBurnBurnDVDr", "1") == "1");
00198 bEraseDvdRw = (gCoreContext->GetSetting("MythBurnEraseDvdRw", "0") == "1");
00199 saveFilename = gCoreContext->GetSetting("MythBurnSaveFilename", "");
00200 destinationType = gCoreContext->GetNumSetting("MythBurnDestinationType", 0);
00201 }
00202
00203 m_createISOCheck->SetCheckState((bCreateISO ? MythUIStateType::Full : MythUIStateType::Off));
00204 m_doBurnCheck->SetCheckState((bDoBurn ? MythUIStateType::Full : MythUIStateType::Off));
00205 m_eraseDvdRwCheck->SetCheckState((bEraseDvdRw ? MythUIStateType::Full : MythUIStateType::Off));
00206 m_filenameEdit->SetText(saveFilename);
00207
00208 if (destinationType < 0 || destinationType >= m_destinationSelector->GetCount())
00209 destinationType = 0;
00210 m_destinationSelector->SetItemCurrent(destinationType);
00211 }
00212
00213 void SelectDestination::saveConfiguration(void)
00214 {
00215 if (m_nativeMode)
00216 {
00217 gCoreContext->SaveSetting("MythNativeCreateISO",
00218 (m_createISOCheck->GetCheckState() == MythUIStateType::Full ? "1" : "0"));
00219 gCoreContext->SaveSetting("MythNativeBurnDVDr",
00220 (m_doBurnCheck->GetCheckState() == MythUIStateType::Full ? "1" : "0"));
00221 gCoreContext->SaveSetting("MythNativeEraseDvdRw",
00222 (m_eraseDvdRwCheck->GetCheckState() == MythUIStateType::Full ? "1" : "0"));
00223 gCoreContext->SaveSetting("MythNativeSaveFilename", m_filenameEdit->GetText());
00224 gCoreContext->SaveSetting("MythNativeDestinationType", m_destinationSelector->GetCurrentPos());
00225 }
00226 else
00227 {
00228 gCoreContext->SaveSetting("MythBurnCreateISO",
00229 (m_createISOCheck->GetCheckState() == MythUIStateType::Full ? "1" : "0"));
00230 gCoreContext->SaveSetting("MythBurnBurnDVDr",
00231 (m_doBurnCheck->GetCheckState() == MythUIStateType::Full ? "1" : "0"));
00232 gCoreContext->SaveSetting("MythBurnEraseDvdRw",
00233 (m_eraseDvdRwCheck->GetCheckState() == MythUIStateType::Full ? "1" : "0"));
00234 gCoreContext->SaveSetting("MythBurnSaveFilename", m_filenameEdit->GetText());
00235 gCoreContext->SaveSetting("MythBurnDestinationType", m_destinationSelector->GetCurrentPos());
00236 }
00237 }
00238
00239 void SelectDestination::setDestination(MythUIButtonListItem* item)
00240 {
00241 if (!item)
00242 return;
00243
00244 int itemNo = item->GetData().value<ARCHIVEDESTINATION>();
00245
00246 if (itemNo < 0 || itemNo > ArchiveDestinationsCount - 1)
00247 itemNo = 0;
00248
00249 m_destinationText->SetText(tr(ArchiveDestinations[itemNo].description));
00250
00251 m_archiveDestination = ArchiveDestinations[itemNo];
00252
00253 switch(itemNo)
00254 {
00255 case AD_DVD_SL:
00256 case AD_DVD_DL:
00257 m_filenameEdit->Hide();
00258 m_findButton->Hide();
00259 m_eraseDvdRwCheck->Hide();
00260 m_eraseDvdRwText->Hide();
00261 m_doBurnCheck->Show();
00262 m_doBurnText->Show();
00263 break;
00264 case AD_DVD_RW:
00265 m_filenameEdit->Hide();
00266 m_findButton->Hide();
00267 m_eraseDvdRwCheck->Show();
00268 m_eraseDvdRwText->Show();
00269 m_doBurnCheck->Show();
00270 m_doBurnText->Show();
00271 break;
00272 case AD_FILE:
00273 int64_t dummy;
00274 ArchiveDestinations[itemNo].freeSpace =
00275 getDiskSpace(m_filenameEdit->GetText(), dummy, dummy);
00276
00277 m_filenameEdit->Show();
00278 m_findButton->Show();
00279 m_eraseDvdRwCheck->Hide();
00280 m_eraseDvdRwText->Hide();
00281 m_doBurnCheck->Hide();
00282 m_doBurnText->Hide();
00283 break;
00284 }
00285
00286
00287 if (ArchiveDestinations[itemNo].freeSpace != -1)
00288 {
00289 m_freespaceText->SetText(formatSize(ArchiveDestinations[itemNo].freeSpace, 2));
00290 m_freeSpace = ArchiveDestinations[itemNo].freeSpace / 1024;
00291 }
00292 else
00293 {
00294 m_freespaceText->SetText(tr("Unknown"));
00295 m_freeSpace = 0;
00296 }
00297
00298 BuildFocusList();
00299 }
00300
00301 void SelectDestination::handleFind(void)
00302 {
00303 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00304
00305 FileSelector *selector = new
00306 FileSelector(mainStack, NULL, FSTYPE_DIRECTORY, m_filenameEdit->GetText(), "*.*");
00307
00308 connect(selector, SIGNAL(haveResult(QString)),
00309 this, SLOT(fileFinderClosed(QString)));
00310
00311 if (selector->Create())
00312 mainStack->AddScreen(selector);
00313 }
00314
00315 void SelectDestination::fileFinderClosed(QString filename)
00316 {
00317 if (filename != "")
00318 {
00319 m_filenameEdit->SetText(filename);
00320 filenameEditLostFocus();
00321 }
00322 }
00323
00324 void SelectDestination::filenameEditLostFocus()
00325 {
00326 int64_t dummy;
00327 m_archiveDestination.freeSpace = getDiskSpace(m_filenameEdit->GetText(), dummy, dummy);
00328
00329
00330
00331 if (m_archiveDestination.freeSpace == -1)
00332 {
00333 QString dir = m_filenameEdit->GetText();
00334 int pos = dir.lastIndexOf('/');
00335 if (pos > 0)
00336 dir = dir.left(pos);
00337 else
00338 dir = "/";
00339
00340 m_archiveDestination.freeSpace = getDiskSpace(dir, dummy, dummy);
00341 }
00342
00343 if (m_archiveDestination.freeSpace != -1)
00344 {
00345 m_freespaceText->SetText(formatSize(m_archiveDestination.freeSpace, 2));
00346 m_freeSpace = m_archiveDestination.freeSpace;
00347 }
00348 else
00349 {
00350 m_freespaceText->SetText(tr("Unknown"));
00351 m_freeSpace = 0;
00352 }
00353 }