Replaygain pre-amp can be set in 0.5 dB steps.
[kugel-rb.git] / rbutil / rbutilqt / base / bootloaderinstallbase.cpp
blob6a2db76392d4a43d6d0137173e14385b691ed2a5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2008 by Dominik Riebeling
10 * $Id$
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 ****************************************************************************/
21 #include <QtCore>
23 #include "bootloaderinstallbase.h"
24 #include "utils.h"
26 #if defined(Q_OS_MACX)
27 #include <sys/param.h>
28 #include <sys/ucred.h>
29 #include <sys/mount.h>
30 #endif
32 BootloaderInstallBase::BootloaderType BootloaderInstallBase::installed(void)
34 return BootloaderUnknown;
38 BootloaderInstallBase::Capabilities BootloaderInstallBase::capabilities(void)
40 return 0;
44 void BootloaderInstallBase::downloadBlStart(QUrl source)
46 m_http.setFile(&m_tempfile);
47 m_http.setCache(true);
48 connect(&m_http, SIGNAL(done(bool)), this, SLOT(downloadBlFinish(bool)));
49 // connect the http read signal to our logProgess *signal*
50 // to immediately emit it without any helper function.
51 connect(&m_http, SIGNAL(dataReadProgress(int, int)),
52 this, SIGNAL(logProgress(int, int)));
53 m_http.getFile(source);
57 void BootloaderInstallBase::downloadReqFinished(int id, bool error)
59 qDebug() << "[BootloaderInstallBase] Download Request" << id
60 << "finished, error:" << m_http.errorString();
62 downloadBlFinish(error);
66 void BootloaderInstallBase::downloadBlFinish(bool error)
68 qDebug() << "[BootloaderInstallBase] Downloading bootloader finished, error:"
69 << error;
71 // update progress bar
72 emit logProgress(100, 100);
74 if(m_http.httpResponse() != 200) {
75 emit logItem(tr("Download error: received HTTP error %1.")
76 .arg(m_http.errorString()), LOGERROR);
77 emit done(true);
78 return;
80 if(error) {
81 emit logItem(tr("Download error: %1")
82 .arg(m_http.error()), LOGERROR);
83 emit done(true);
84 return;
86 else if(m_http.isCached())
87 emit logItem(tr("Download finished (cache used)."), LOGOK);
88 else
89 emit logItem(tr("Download finished."), LOGOK);
91 QCoreApplication::processEvents();
92 m_blversion = m_http.timestamp();
93 emit downloadDone();
96 void BootloaderInstallBase::installBlfile(void)
98 qDebug() << "[BootloaderInstallBase]" << __func__;
102 //! @brief backup OF file.
103 //! @param to folder to write backup file to. Folder will get created.
104 //! @return true on success, false on error.
106 bool BootloaderInstallBase::backup(QString to)
108 qDebug() << "[BootloaderInstallBase] Backing up bootloader file";
109 QDir targetDir(".");
110 emit logItem(tr("Creating backup of original firmware file."), LOGINFO);
111 if(!targetDir.mkpath(to)) {
112 emit logItem(tr("Creating backup folder failed"), LOGERROR);
113 return false;
115 QString tofile = to + "/" + QFileInfo(m_blfile).fileName();
116 qDebug() << "[BootloaderInstallBase] trying to backup" << m_blfile << "to" << tofile;
117 if(!QFile::copy(Utils::resolvePathCase(m_blfile), tofile)) {
118 emit logItem(tr("Creating backup copy failed."), LOGERROR);
119 return false;
121 emit logItem(tr("Backup created."), LOGOK);
122 return true;
126 //! @brief log installation to logfile.
127 //! @param mode action to perform. 0: add to log, 1: remove from log.
128 //! @return 0 on success
129 int BootloaderInstallBase::logInstall(LogMode mode)
131 int result = 0;
132 QString section = m_blurl.path().section('/', -1);
133 QSettings s(m_logfile, QSettings::IniFormat, this);
134 emit logItem(tr("Creating installation log"), LOGINFO);
136 if(mode == LogAdd) {
137 s.setValue("Bootloader/" + section, m_blversion.toString(Qt::ISODate));
138 qDebug() << "[BootloaderInstallBase] Writing log, version:"
139 << m_blversion.toString(Qt::ISODate);
141 else {
142 s.remove("Bootloader/" + section);
144 s.sync();
146 emit logItem(tr("Installation log created"), LOGOK);
148 return result;
152 //! @brief Return post install hints string.
153 //! @param model model string
154 //! @return hints.
155 QString BootloaderInstallBase::postinstallHints(QString model)
157 bool hint = false;
158 QString msg = tr("Bootloader installation is almost complete. "
159 "Installation <b>requires</b> you to perform the "
160 "following steps manually:");
162 msg += "<ol>";
163 msg += tr("<li>Safely remove your player.</li>");
164 if(model == "h100" || model == "h120" || model == "h300" ||
165 model == "ondavx747") {
166 hint = true;
167 msg += tr("<li>Reboot your player into the original firmware.</li>"
168 "<li>Perform a firmware upgrade using the update functionality "
169 "of the original firmware. Please refer to your player's manual "
170 "on details.</li>"
171 "<li>After the firmware has been updated reboot your player.</li>");
173 if(model == "iaudiox5" || model == "iaudiom5"
174 || model == "iaudiox5v" || model == "iaudiom3") {
175 hint = true;
176 msg += tr("<li>Turn the player off</li>"
177 "<li>Insert the charger</li>");
179 if(model == "gigabeatf") {
180 hint = true;
181 msg += tr("<li>Unplug USB and power adaptors</li>"
182 "<li>Hold <i>Power</i> to turn the player off</li>"
183 "<li>Toggle the battery switch on the player</li>"
184 "<li>Hold <i>Power</i> to boot into Rockbox</li>");
187 msg += "</ol>";
188 msg += tr("<p><b>Note:</b> You can safely install other parts first, but "
189 "the above steps are <b>required</b> to finish the installation!</p>");
191 if(hint)
192 return msg;
193 else
194 return QString("");
198 #if defined(Q_OS_MACX)
199 void BootloaderInstallBase::waitRemount()
201 m_remountTries = 600;
202 emit logItem(tr("Waiting for system to remount player"), LOGINFO);
204 QTimer::singleShot(100, this, SLOT(checkRemount()));
206 #endif
209 void BootloaderInstallBase::checkRemount()
211 #if defined(Q_OS_MACX)
212 if(m_remountTries--) {
213 int status = 0;
214 // check if device has been remounted
215 QCoreApplication::processEvents();
216 int num;
217 struct statfs *mntinf;
219 num = getmntinfo(&mntinf, MNT_WAIT);
220 while(num--) {
221 if(QString(mntinf->f_mntfromname).startsWith(m_remountDevice)
222 && QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive))
223 status = 1;
224 mntinf++;
226 if(!status) {
227 // still not remounted, restart timer.
228 QTimer::singleShot(500, this, SLOT(checkRemount()));
229 qDebug() << "[BootloaderInstallBase] Player not remounted yet" << m_remountDevice;
231 else {
232 emit logItem(tr("Player remounted"), LOGINFO);
233 emit remounted(true);
236 else {
237 emit logItem(tr("Timeout on remount"), LOGERROR);
238 emit remounted(false);
240 #endif
244 //! @brief set list of possible bootloader files and pick the existing one.
245 //! @param sl list of possible bootloader files.
246 void BootloaderInstallBase::setBlFile(QStringList sl)
248 // figue which of the possible bootloader filenames is correct.
249 for(int a = 0; a < sl.size(); a++) {
250 if(!Utils::resolvePathCase(sl.at(a)).isEmpty()) {
251 m_blfile = sl.at(a);
254 if(m_blfile.isEmpty()) {
255 m_blfile = sl.at(0);