Handle language change events in widgets.
[maemo-rb.git] / rbutil / rbutilqt / base / uninstall.cpp
blobef6eb61ca5aeb212c9dc5f0f1455b7482a493817
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
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 "uninstall.h"
21 #include "utils.h"
23 Uninstaller::Uninstaller(QObject* parent,QString mountpoint): QObject(parent)
25 m_mountpoint = mountpoint;
28 void Uninstaller::deleteAll(void)
30 QString rbdir(m_mountpoint + ".rockbox/");
31 emit logItem(tr("Starting Uninstallation"), LOGINFO);
32 emit logProgress(0, 0);
33 Utils::recursiveRmdir(rbdir);
34 emit logProgress(1, 1);
35 emit logItem(tr("Finished Uninstallation"), LOGOK);
36 emit logFinished();
39 void Uninstaller::uninstall(void)
41 emit logProgress(0, 0);
42 emit logItem(tr("Starting Uninstallation"), LOGINFO);
44 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
46 for(int i=0; i< uninstallSections.size() ; i++)
48 emit logItem(tr("Uninstalling %1...").arg(uninstallSections.at(i)), LOGINFO);
49 QCoreApplication::processEvents();
50 // create list of all other install sections
51 QStringList sections = installlog.childGroups();
52 sections.removeAt(sections.indexOf(uninstallSections.at(i)));
53 installlog.beginGroup(uninstallSections.at(i));
54 QStringList toDeleteList = installlog.allKeys();
55 QStringList dirList;
56 installlog.endGroup();
58 // iterate over all entries
59 for(int j =0; j < toDeleteList.size(); j++ )
61 // check if current file is in use by another section
62 bool deleteFile = true;
63 for(int s = 0; s < sections.size(); s++)
65 installlog.beginGroup(sections.at(s));
66 if(installlog.contains(toDeleteList.at(j)))
68 deleteFile = false;
69 qDebug() << "[Uninstaller] file still in use:" << toDeleteList.at(j);
71 installlog.endGroup();
74 installlog.beginGroup(uninstallSections.at(i));
75 QFileInfo toDelete(m_mountpoint + "/" + toDeleteList.at(j));
76 if(toDelete.isFile()) // if it is a file remove it
78 if(deleteFile && !QFile::remove(toDelete.filePath()))
79 emit logItem(tr("Could not delete %1")
80 .arg(toDelete.filePath()), LOGWARNING);
81 installlog.remove(toDeleteList.at(j));
82 qDebug() << "[Uninstaller] deleted:" << toDelete.filePath();
84 else // if it is a dir, remember it for later deletion
86 // no need to keep track on folders still in use -- only empty
87 // folders will be rm'ed.
88 dirList << toDeleteList.at(j);
90 installlog.endGroup();
91 QCoreApplication::processEvents();
93 // delete the dirs
94 installlog.beginGroup(uninstallSections.at(i));
95 for(int j=0; j < dirList.size(); j++ )
97 installlog.remove(dirList.at(j));
98 QDir dir(m_mountpoint);
99 dir.rmdir(dirList.at(j)); // rm works only on empty folders
102 installlog.endGroup();
103 //installlog.removeGroup(uninstallSections.at(i))
105 uninstallSections.clear();
106 installlog.sync();
107 emit logProgress(1, 1);
108 emit logItem(tr("Uninstallation finished"), LOGOK);
109 emit logFinished();
112 QStringList Uninstaller::getAllSections()
114 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
115 QStringList allSections = installlog.childGroups();
116 allSections.removeAt(allSections.lastIndexOf("Bootloader"));
117 return allSections;
121 bool Uninstaller::uninstallPossible()
123 return QFileInfo(m_mountpoint +"/.rockbox/rbutil.log").exists();