Add remote button definitions for the gigabeat remote in preparation for
[kugel-rb.git] / rbutil / rbutilqt / base / uninstall.cpp
blobb7a63edcd53ca0603226a2a8a134d08d24a11318
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
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 ****************************************************************************/
20 #include <QtCore>
21 #include "uninstall.h"
22 #include "utils.h"
24 Uninstaller::Uninstaller(QObject* parent,QString mountpoint): QObject(parent)
26 m_mountpoint = mountpoint;
29 void Uninstaller::deleteAll(ProgressloggerInterface* dp)
31 m_dp = dp;
32 QString rbdir(m_mountpoint + ".rockbox/");
33 m_dp->addItem(tr("Starting Uninstallation"),LOGINFO);
34 m_dp->setProgressMax(0);
35 recRmdir(rbdir);
36 m_dp->setProgressMax(1);
37 m_dp->setProgressValue(1);
38 m_dp->addItem(tr("Finished Uninstallation"),LOGOK);
39 m_dp->setFinished();
42 void Uninstaller::uninstall(ProgressloggerInterface* dp)
44 m_dp = dp;
45 m_dp->setProgressMax(0);
46 m_dp->addItem(tr("Starting Uninstallation"),LOGINFO);
48 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, this);
50 for(int i=0; i< uninstallSections.size() ; i++)
52 m_dp->addItem(tr("Uninstalling ") + uninstallSections.at(i) + " ...",LOGINFO);
53 QCoreApplication::processEvents();
54 // create list of all other install sections
55 QStringList sections = installlog.childGroups();
56 sections.removeAt(sections.indexOf(uninstallSections.at(i)));
57 installlog.beginGroup(uninstallSections.at(i));
58 QStringList toDeleteList = installlog.allKeys();
59 QStringList dirList;
60 installlog.endGroup();
62 // iterate over all entries
63 for(int j =0; j < toDeleteList.size(); j++ )
65 // check if current file is in use by another section
66 bool deleteFile = true;
67 for(int s = 0; s < sections.size(); s++)
69 installlog.beginGroup(sections.at(s));
70 if(installlog.contains(toDeleteList.at(j)))
72 deleteFile = false;
73 qDebug() << "file still in use:" << toDeleteList.at(j);
75 installlog.endGroup();
78 installlog.beginGroup(uninstallSections.at(i));
79 QFileInfo toDelete(m_mountpoint + "/" + toDeleteList.at(j));
80 if(toDelete.isFile()) // if it is a file remove it
82 if(deleteFile && !QFile::remove(toDelete.filePath()))
83 m_dp->addItem(tr("Could not delete: ")+ toDelete.filePath(),LOGWARNING);
84 installlog.remove(toDeleteList.at(j));
85 qDebug() << "deleted: " << toDelete.filePath() ;
87 else // if it is a dir, remember it for later deletion
89 // no need to keep track on folders still in use -- only empty
90 // folders will be rm'ed.
91 dirList << toDeleteList.at(j);
93 installlog.endGroup();
94 QCoreApplication::processEvents();
96 // delete the dirs
97 installlog.beginGroup(uninstallSections.at(i));
98 for(int j=0; j < dirList.size(); j++ )
100 installlog.remove(dirList.at(j));
101 QDir dir(m_mountpoint);
102 dir.rmdir(dirList.at(j)); // rm works only on empty folders
105 installlog.endGroup();
106 //installlog.removeGroup(uninstallSections.at(i))
108 uninstallSections.clear();
109 installlog.sync();
110 m_dp->setProgressMax(1);
111 m_dp->setProgressValue(1);
112 m_dp->addItem(tr("Uninstallation finished"),LOGOK);
113 m_dp->setFinished();
116 QStringList Uninstaller::getAllSections()
118 QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
119 QStringList allSections = installlog.childGroups();
120 allSections.removeAt(allSections.lastIndexOf("Bootloader"));
121 return allSections;
125 bool Uninstaller::uninstallPossible()
127 return QFileInfo(m_mountpoint +"/.rockbox/rbutil.log").exists();