don't try to find the given file in the browser dialog if it doesn't exist.
[Rockbox.git] / rbutil / rbutilqt / installbl.cpp
blob9d9dba4760548e039a69c1c888788557600a8a70
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: installbl.cpp 14027 2007-07-27 17:42:49Z domonoky $
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "installbl.h"
21 #include "ui_installprogressfrm.h"
24 InstallBl::InstallBl(QWidget *parent) : QDialog(parent)
26 ui.setupUi(this);
27 connect(ui.buttonBrowse, SIGNAL(clicked()), this, SLOT(browseFolder()));
28 connect(ui.buttonBrowseOF, SIGNAL(clicked()), this, SLOT(browseOF()));
32 void InstallBl::setProxy(QUrl proxy_url)
34 proxy = proxy_url;
35 qDebug() << "Install::setProxy" << proxy;
38 void InstallBl::setMountPoint(QString mount)
40 QFileInfo m(mount);
41 if(m.isDir()) {
42 ui.lineMountPoint->clear();
43 ui.lineMountPoint->insert(mount);
47 void InstallBl::setOFPath(QString path)
49 QFileInfo m(path);
50 if(m.exists()) {
51 ui.lineOriginalFirmware->clear();
52 ui.lineOriginalFirmware->insert(path);
56 void InstallBl::browseFolder()
58 QFileDialog browser(this);
59 if(QFileInfo(ui.lineMountPoint->text()).isDir())
60 browser.setDirectory(ui.lineMountPoint->text());
61 else
62 browser.setDirectory("/media");
63 browser.setReadOnly(true);
64 browser.setFileMode(QFileDialog::DirectoryOnly);
65 browser.setAcceptMode(QFileDialog::AcceptOpen);
66 if(browser.exec()) {
67 qDebug() << browser.directory();
68 QStringList files = browser.selectedFiles();
69 setMountPoint(files.at(0));
73 void InstallBl::browseOF()
75 QFileDialog browser(this);
76 if(QFileInfo(ui.lineOriginalFirmware->text()).exists())
77 browser.setDirectory(ui.lineOriginalFirmware->text());
78 else
79 browser.setDirectory("/media");
80 browser.setReadOnly(true);
81 browser.setAcceptMode(QFileDialog::AcceptOpen);
82 if(browser.exec()) {
83 qDebug() << browser.directory();
84 QStringList files = browser.selectedFiles();
85 setOFPath(files.at(0));
89 void InstallBl::accept()
91 // create logger
92 logger = new ProgressLoggerGui(this);
93 logger->show();
95 // show dialog with error if mount point is wrong
96 if(QFileInfo(ui.lineMountPoint->text()).isDir()) {
97 mountPoint = ui.lineMountPoint->text();
98 userSettings->setValue("defaults/mountpoint", mountPoint);
100 else {
101 logger->addItem(tr("Mount point is wrong!"),LOGERROR);
102 logger->abort();
103 return;
106 if(QFileInfo(ui.lineOriginalFirmware->text()).exists())
108 m_OrigFirmware = ui.lineOriginalFirmware->text();
110 else if(needextrafile)
112 logger->addItem(tr("Original Firmware Path is wrong!"),LOGERROR);
113 logger->abort();
114 return;
116 userSettings->sync();
118 binstaller = new BootloaderInstaller(this);
120 binstaller->setMountPoint(mountPoint);
121 binstaller->setProxy(proxy);
122 QString plattform = userSettings->value("defaults/platform").toString();
124 binstaller->setDevice(plattform);
125 binstaller->setBootloaderMethod(devices->value(plattform + "/bootloadermethod").toString());
126 binstaller->setBootloaderName(devices->value(plattform + "/bootloadername").toString());
127 binstaller->setBootloaderBaseUrl(devices->value("bootloader_url").toString());
128 binstaller->setOrigFirmwarePath(m_OrigFirmware);
130 binstaller->install(logger);
132 connect(binstaller, SIGNAL(done(bool)), this, SLOT(done(bool)));
137 void InstallBl::done(bool error)
139 qDebug() << "Install::done, error:" << error;
141 if(error)
143 logger->abort();
144 return;
147 // no error, close the window, when the logger is closed
148 connect(logger,SIGNAL(closed()),this,SLOT(close()));
152 void InstallBl::setDeviceSettings(QSettings *dev)
154 devices = dev;
155 qDebug() << "Install::setDeviceSettings:" << devices;
158 void InstallBl::setUserSettings(QSettings *user)
160 userSettings = user;
161 if(userSettings->value("defaults/platform").toString() == "h100" ||
162 userSettings->value("defaults/platform").toString() == "h120" ||
163 userSettings->value("defaults/platform").toString() == "h300")
165 ui.buttonBrowseOF->show();
166 ui.lineOriginalFirmware->show();
167 ui.label_3->show();
168 needextrafile = true;
170 else
172 ui.buttonBrowseOF->hide();
173 ui.lineOriginalFirmware->hide();
174 ui.label_3->hide();
175 needextrafile = false;