Changeset View
Changeset View
Standalone View
Standalone View
src/dialog_uninstaller.cpp
Show All 16 Lines | |||||
17 | * Lesser General Public License for more details. | 17 | * Lesser General Public License for more details. | ||
18 | * | 18 | * | ||
19 | * You should have received a copy of the GNU Lesser General Public | 19 | * You should have received a copy of the GNU Lesser General Public | ||
20 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | 20 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "dialog_uninstaller.h" | 23 | #include "dialog_uninstaller.h" | ||
24 | #include "abstractappearance.h" | 24 | #include "abstractappearance.h" | ||
25 | #include "iconthemesmodel.h" | | |||
26 | #include "ui_dialog_uninstaller.h" | 25 | #include "ui_dialog_uninstaller.h" | ||
27 | #include "thread.h" | 26 | #include "thread.h" | ||
28 | #include "appearencegtk.h" | 27 | #include "appearencegtk.h" | ||
29 | #include <QDir> | 28 | #include <QDir> | ||
30 | #include <QDebug> | 29 | #include <QDebug> | ||
31 | #include <KLocalizedString> | 30 | #include <KLocalizedString> | ||
32 | 31 | | |||
33 | DialogUninstaller::DialogUninstaller(QWidget* parent, AppearenceGTK *app) | 32 | DialogUninstaller::DialogUninstaller(QWidget* parent, AppearenceGTK *app) | ||
34 | : QDialog(parent) | 33 | : QDialog(parent) | ||
35 | , ui(new Ui::dialog_uninstaller) | 34 | , ui(new Ui::dialog_uninstaller) | ||
36 | , appareance(app) | 35 | , appareance(app) | ||
37 | { | 36 | { | ||
38 | ui->setupUi(this); | 37 | ui->setupUi(this); | ||
39 | 38 | | |||
40 | refreshListsForUninstall(); | 39 | refreshListsForUninstall(); | ||
41 | 40 | | |||
42 | connect(ui->but_uninstall_theme, &QAbstractButton::clicked, this, &DialogUninstaller::uninstallTheme); | 41 | connect(ui->but_uninstall_theme, &QAbstractButton::clicked, this, &DialogUninstaller::uninstallTheme); | ||
43 | connect(ui->but_uninstall_icon, &QAbstractButton::clicked, this, &DialogUninstaller::uninstallIcon); | | |||
44 | } | 42 | } | ||
45 | 43 | | |||
46 | DialogUninstaller::~DialogUninstaller() | 44 | DialogUninstaller::~DialogUninstaller() | ||
47 | { | 45 | { | ||
48 | delete ui; | 46 | delete ui; | ||
49 | } | 47 | } | ||
50 | 48 | | |||
51 | void DialogUninstaller::refreshListsForUninstall() | 49 | void DialogUninstaller::refreshListsForUninstall() | ||
52 | { | 50 | { | ||
53 | ui->lb_notice_uninstall_icon->clear(); | | |||
54 | ui->lb_notice_uninstall_theme->clear(); | 51 | ui->lb_notice_uninstall_theme->clear(); | ||
55 | 52 | | |||
56 | QStringList themes = appareance->gtk2Appearance()->installedThemes(); | 53 | QStringList themes = appareance->gtk2Appearance()->installedThemes(); | ||
57 | themes = themes.filter(QDir::homePath()); //we only one the locally installed themes | 54 | themes = themes.filter(QDir::homePath()); //we only one the locally installed themes | ||
58 | 55 | | |||
59 | //Just leave the theme name | 56 | //Just leave the theme name | ||
60 | for(QStringList::iterator it=themes.begin(); it!=themes.end(); ++it) | 57 | for(QStringList::iterator it=themes.begin(); it!=themes.end(); ++it) | ||
61 | *it = QDir(*it).dirName(); | 58 | *it = QDir(*it).dirName(); | ||
62 | 59 | | |||
63 | ui->cb_uninstall_theme->clear(); | 60 | ui->cb_uninstall_theme->clear(); | ||
64 | ui->cb_uninstall_theme->addItems(themes); | 61 | ui->cb_uninstall_theme->addItems(themes); | ||
65 | | ||||
66 | ui->cb_uninstall_icon->setModel(new IconThemesModel(true)); | | |||
67 | } | 62 | } | ||
68 | 63 | | |||
69 | void DialogUninstaller::uninstallTheme() | 64 | void DialogUninstaller::uninstallTheme() | ||
70 | { | 65 | { | ||
71 | if(ui->cb_uninstall_theme->currentIndex() < 0) | 66 | if(ui->cb_uninstall_theme->currentIndex() < 0) | ||
72 | return; | 67 | return; | ||
73 | 68 | | |||
74 | QString tema = ui->cb_uninstall_theme->currentText(); | 69 | QString tema = ui->cb_uninstall_theme->currentText(); | ||
Show All 9 Lines | |||||
84 | ui->lb_notice_uninstall_theme->setText(i18n("Uninstalling GTK theme...")); | 79 | ui->lb_notice_uninstall_theme->setText(i18n("Uninstalling GTK theme...")); | ||
85 | 80 | | |||
86 | ThreadErase* threadEraseTheme = new ThreadErase; | 81 | ThreadErase* threadEraseTheme = new ThreadErase; | ||
87 | threadEraseTheme->setThemeForErase(themes.first()); | 82 | threadEraseTheme->setThemeForErase(themes.first()); | ||
88 | connect(threadEraseTheme, &KJob::finished, this, &DialogUninstaller::threadUninstalledThemeFinished); | 83 | connect(threadEraseTheme, &KJob::finished, this, &DialogUninstaller::threadUninstalledThemeFinished); | ||
89 | threadEraseTheme->start(); | 84 | threadEraseTheme->start(); | ||
90 | } | 85 | } | ||
91 | 86 | | |||
92 | void DialogUninstaller::uninstallIcon() | | |||
93 | { | | |||
94 | int themeIndex = ui->cb_uninstall_icon->currentIndex(); | | |||
95 | if(themeIndex<0) | | |||
96 | return; | | |||
97 | | ||||
98 | QAbstractItemModel* model = ui->cb_uninstall_icon->model(); | | |||
99 | QString theme = model->data(model->index(themeIndex, 0), IconThemesModel::PathRole).toString(); | | |||
100 | | ||||
101 | ui->cb_uninstall_icon->setEnabled(false); | | |||
102 | ui->but_uninstall_icon->setEnabled(false); | | |||
103 | | ||||
104 | ui->lb_notice_uninstall_icon->setText(i18n("Uninstalling icons...")); | | |||
105 | | ||||
106 | ThreadErase* threadEraseIcon = new ThreadErase; | | |||
107 | threadEraseIcon->setThemeForErase(theme); | | |||
108 | connect(threadEraseIcon, &KJob::finished, this, &DialogUninstaller::threadUninstalledThemeIconFinished); | | |||
109 | threadEraseIcon->start(); | | |||
110 | } | | |||
111 | | ||||
112 | void DialogUninstaller::threadUninstalledThemeFinished(KJob* job) | 87 | void DialogUninstaller::threadUninstalledThemeFinished(KJob* job) | ||
113 | { | 88 | { | ||
114 | if(job->error()==0) { | 89 | if(job->error()==0) { | ||
115 | ui->lb_notice_uninstall_theme->setText(i18n("GTK theme successfully uninstalled.")); | 90 | ui->lb_notice_uninstall_theme->setText(i18n("GTK theme successfully uninstalled.")); | ||
116 | emit(themeUninstalled()); | 91 | emit(themeUninstalled()); | ||
117 | } else { | 92 | } else { | ||
118 | ui->lb_notice_uninstall_theme->setText(i18n("Could not uninstall the GTK theme.")); | 93 | ui->lb_notice_uninstall_theme->setText(i18n("Could not uninstall the GTK theme.")); | ||
119 | } | 94 | } | ||
120 | 95 | | |||
121 | ui->cb_uninstall_theme->setEnabled(true); | 96 | ui->cb_uninstall_theme->setEnabled(true); | ||
122 | ui->but_uninstall_theme->setEnabled(true); | 97 | ui->but_uninstall_theme->setEnabled(true); | ||
123 | 98 | | |||
124 | refreshListsForUninstall(); | 99 | refreshListsForUninstall(); | ||
125 | } | 100 | } | ||
126 | | ||||
127 | void DialogUninstaller::threadUninstalledThemeIconFinished(KJob* job) | | |||
128 | { | | |||
129 | if(job->error()==0) { | | |||
130 | ui->lb_notice_uninstall_icon->setText(i18n("Icons successfully uninstalled.")); | | |||
131 | emit(themeUninstalled()); | | |||
132 | } else { | | |||
133 | ui->lb_notice_uninstall_icon->setText(i18n("Could not uninstall the icon theme.")); | | |||
134 | } | | |||
135 | | ||||
136 | ui->cb_uninstall_icon->setEnabled(true); | | |||
137 | ui->but_uninstall_icon->setEnabled(true); | | |||
138 | | ||||
139 | refreshListsForUninstall(); | | |||
140 | } | |