Handle language change events in widgets.
[maemo-rb.git] / rbutil / rbutilqt / base / bootloaderinstallfile.cpp
blobfc293e54ebd6391cad76cc5dd8504e2fee9ecbfe
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2008 by Dominik Riebeling
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include <QtCore>
20 #include <QtDebug>
21 #include "bootloaderinstallfile.h"
22 #include "utils.h"
25 BootloaderInstallFile::BootloaderInstallFile(QObject *parent)
26 : BootloaderInstallBase(parent)
31 bool BootloaderInstallFile::install(void)
33 emit logItem(tr("Downloading bootloader"), LOGINFO);
34 qDebug() << "[BootloaderInstallFile] installing bootloader";
35 downloadBlStart(m_blurl);
36 connect(this, SIGNAL(downloadDone()), this, SLOT(installStage2()));
37 return true;
40 void BootloaderInstallFile::installStage2(void)
42 emit logItem(tr("Installing Rockbox bootloader"), LOGINFO);
43 QCoreApplication::processEvents();
45 // if an old bootloader is present (Gigabeat) move it out of the way.
46 QString fwfile(Utils::resolvePathCase(m_blfile));
47 if(!fwfile.isEmpty()) {
48 QString moved = Utils::resolvePathCase(m_blfile) + ".ORIG";
49 qDebug() << "[BootloaderInstallFile] renaming" << fwfile << "to" << moved;
50 QFile::rename(fwfile, moved);
53 // if no old file found resolve path without basename
54 QFileInfo fi(m_blfile);
55 QString absPath = Utils::resolvePathCase(fi.absolutePath());
57 // if it's not possible to locate the base path try to create it
58 if(absPath.isEmpty()) {
59 QStringList pathElements = m_blfile.split("/");
60 // remove filename from list and save last path element
61 pathElements.removeLast();
62 QString lastElement = pathElements.last();
63 // remove last path element for base
64 pathElements.removeLast();
65 QString basePath = pathElements.join("/");
67 // check for base and bail out if not found. Otherwise create folder.
68 absPath = Utils::resolvePathCase(basePath);
69 QDir d(absPath);
70 d.mkpath(lastElement);
71 absPath = Utils::resolvePathCase(fi.absolutePath());
73 if(absPath.isEmpty()) {
74 emit logItem(tr("Error accessing output folder"), LOGERROR);
75 emit done(true);
76 return;
79 fwfile = absPath + "/" + fi.fileName();
81 // place (new) bootloader
82 m_tempfile.open();
83 qDebug() << "[BootloaderInstallFile] renaming" << m_tempfile.fileName()
84 << "to" << fwfile;
85 m_tempfile.close();
87 if(!Utils::resolvePathCase(fwfile).isEmpty()) {
88 emit logItem(tr("A firmware file is already present on player"), LOGERROR);
89 emit done(true);
90 return;
92 if(m_tempfile.copy(fwfile)) {
93 emit logItem(tr("Bootloader successful installed"), LOGOK);
95 else {
96 emit logItem(tr("Copying modified firmware file failed"), LOGERROR);
97 emit done(true);
98 return;
101 logInstall(LogAdd);
103 emit done(false);
107 bool BootloaderInstallFile::uninstall(void)
109 qDebug() << "[BootloaderInstallFile] Uninstalling bootloader";
110 emit logItem(tr("Removing Rockbox bootloader"), LOGINFO);
111 // check if a .ORIG file is present, and allow moving it back.
112 QString origbl = Utils::resolvePathCase(m_blfile + ".ORIG");
113 if(origbl.isEmpty()) {
114 emit logItem(tr("No original firmware file found."), LOGERROR);
115 emit done(true);
116 return false;
118 QString fwfile = Utils::resolvePathCase(m_blfile);
119 if(!QFile::remove(fwfile)) {
120 emit logItem(tr("Can't remove Rockbox bootloader file."), LOGERROR);
121 emit done(true);
122 return false;
124 if(!QFile::rename(origbl, fwfile)) {
125 emit logItem(tr("Can't restore bootloader file."), LOGERROR);
126 emit done(true);
127 return false;
129 emit logItem(tr("Original bootloader restored successfully."), LOGOK);
130 logInstall(LogRemove);
131 emit done(false);
133 return true;
137 //! @brief check if bootloader is installed.
138 //! @return BootloaderRockbox, BootloaderOther or BootloaderUnknown.
139 BootloaderInstallBase::BootloaderType BootloaderInstallFile::installed(void)
141 qDebug() << "[BootloaderInstallFile] checking installed bootloader";
142 if(!Utils::resolvePathCase(m_blfile).isEmpty()
143 && !Utils::resolvePathCase(m_blfile + ".ORIG").isEmpty())
144 return BootloaderRockbox;
145 else if(!Utils::resolvePathCase(m_blfile).isEmpty())
146 return BootloaderOther;
147 else
148 return BootloaderUnknown;
152 BootloaderInstallBase::Capabilities BootloaderInstallFile::capabilities(void)
154 qDebug() << "[BootloaderInstallFile] getting capabilities";
155 return Install | Uninstall | IsFile | CanCheckInstalled | Backup;