Changeset View
Changeset View
Standalone View
Standalone View
src/dialog_installer.cpp
Show All 40 Lines | |||||
41 | 41 | | |||
42 | DialogInstaller::DialogInstaller(QWidget *parent) | 42 | DialogInstaller::DialogInstaller(QWidget *parent) | ||
43 | : QDialog(parent), ui(new Ui::dialog_installer) | 43 | : QDialog(parent), ui(new Ui::dialog_installer) | ||
44 | { | 44 | { | ||
45 | ui->setupUi(this); | 45 | ui->setupUi(this); | ||
46 | 46 | | |||
47 | //TODO: make sure it's a good idea to have the threads always instanciated | 47 | //TODO: make sure it's a good idea to have the threads always instanciated | ||
48 | threadForTheme = new Thread("theme"); | 48 | threadForTheme = new Thread("theme"); | ||
49 | threadForIcon = new Thread("icon"); | | |||
50 | threadAnalisysTheme = new ThreadAnalisysTheme; | 49 | threadAnalisysTheme = new ThreadAnalisysTheme; | ||
51 | threadAnalisysThemeIcon = new ThreadAnalisysThemeIcon; | | |||
52 | 50 | | |||
53 | //installation ui | 51 | //installation ui | ||
54 | connect(ui->theme_file, &KUrlRequester::textChanged, this, &DialogInstaller::themeAnalisys); | 52 | connect(ui->theme_file, &KUrlRequester::textChanged, this, &DialogInstaller::themeAnalisys); | ||
55 | connect(ui->icon_file, &KUrlRequester::textChanged, this, &DialogInstaller::themeIconAnalisys); | | |||
56 | 53 | | |||
57 | connect(ui->but_icon_install, &QAbstractButton::clicked, this, &DialogInstaller::installThemeIcon); | | |||
58 | connect(ui->but_theme_install, &QAbstractButton::clicked, this, &DialogInstaller::installTheme); | 54 | connect(ui->but_theme_install, &QAbstractButton::clicked, this, &DialogInstaller::installTheme); | ||
59 | 55 | | |||
60 | connect(threadAnalisysTheme, &KJob::finished, this, &DialogInstaller::checkThemeAnalisys); | 56 | connect(threadAnalisysTheme, &KJob::finished, this, &DialogInstaller::checkThemeAnalisys); | ||
61 | connect(threadAnalisysThemeIcon, &KJob::finished, this, &DialogInstaller::checkThemeIconAnalisys); | | |||
62 | 57 | | |||
63 | connect(threadForTheme, &Thread::started, this, &DialogInstaller::disableGUIThemeInstaller); | 58 | connect(threadForTheme, &Thread::started, this, &DialogInstaller::disableGUIThemeInstaller); | ||
64 | connect(threadForIcon, &Thread::started, this, &DialogInstaller::disableGUIThemeIconInstaller); | | |||
65 | connect(threadForTheme, &KJob::finished, this, &DialogInstaller::enableGUIThemeInstaller); | 59 | connect(threadForTheme, &KJob::finished, this, &DialogInstaller::enableGUIThemeInstaller); | ||
66 | connect(threadForIcon, &KJob::finished, this, &DialogInstaller::enableGUIThemeIconInstaller); | | |||
67 | 60 | | |||
68 | //ui refresh | 61 | //ui refresh | ||
69 | connect(threadForTheme, &KJob::finished, this, &DialogInstaller::refreshGUITheme); | 62 | connect(threadForTheme, &KJob::finished, this, &DialogInstaller::refreshGUITheme); | ||
70 | connect(threadForIcon, &KJob::finished, this, &DialogInstaller::refreshGUIIconTheme); | | |||
71 | | ||||
72 | } | 63 | } | ||
73 | 64 | | |||
74 | DialogInstaller::~DialogInstaller() | 65 | DialogInstaller::~DialogInstaller() | ||
75 | { | 66 | { | ||
76 | 67 | | |||
77 | disconnect(threadAnalisysTheme, nullptr, this, nullptr); | 68 | disconnect(threadAnalisysTheme, nullptr, this, nullptr); | ||
78 | disconnect(threadAnalisysThemeIcon, nullptr, this, nullptr); | | |||
79 | disconnect(threadForTheme, nullptr, this, nullptr); | 69 | disconnect(threadForTheme, nullptr, this, nullptr); | ||
80 | disconnect(threadForIcon, nullptr, this, nullptr); | | |||
81 | disconnect(threadForTheme, nullptr, this, nullptr); | 70 | disconnect(threadForTheme, nullptr, this, nullptr); | ||
82 | disconnect(threadForIcon, nullptr, this, nullptr); | | |||
83 | 71 | | |||
84 | delete threadAnalisysTheme; | 72 | delete threadAnalisysTheme; | ||
85 | delete threadAnalisysThemeIcon; | | |||
86 | delete threadForIcon; | | |||
87 | delete threadForTheme; | 73 | delete threadForTheme; | ||
88 | delete ui; | 74 | delete ui; | ||
89 | } | 75 | } | ||
90 | 76 | | |||
91 | void DialogInstaller::installTheme() | 77 | void DialogInstaller::installTheme() | ||
92 | { | 78 | { | ||
93 | QString file = ui->theme_file->text(); | 79 | QString file = ui->theme_file->text(); | ||
94 | 80 | | |||
95 | // qDebug()<< "File to install" << file; | 81 | // qDebug()<< "File to install" << file; | ||
96 | if(!fileIsTar(file)) { | 82 | if(!fileIsTar(file)) { | ||
97 | KMessageBox::error(this, i18n("Could not install the %1 theme.", file), i18n("Cannot install theme")); | 83 | KMessageBox::error(this, i18n("Could not install the %1 theme.", file), i18n("Cannot install theme")); | ||
98 | return; | 84 | return; | ||
99 | } | 85 | } | ||
100 | 86 | | |||
101 | threadForTheme->setUrlPackage(file); | 87 | threadForTheme->setUrlPackage(file); | ||
102 | threadForTheme->start(); | 88 | threadForTheme->start(); | ||
103 | } | 89 | } | ||
104 | 90 | | |||
105 | void DialogInstaller::installThemeIcon() | | |||
106 | { | | |||
107 | QString file = ui->icon_file->text(); | | |||
108 | | ||||
109 | // qDebug()<< "File to install" << file; | | |||
110 | if(!fileIsTar(file)) { | | |||
111 | KMessageBox::error(this, i18n("Could not install the %1 theme.", file), i18n("Cannot install theme")); | | |||
112 | return; | | |||
113 | } | | |||
114 | | ||||
115 | threadForIcon->setUrlPackage(file); | | |||
116 | threadForIcon->start(); | | |||
117 | } | | |||
118 | | ||||
119 | void DialogInstaller::themeAnalisys() | 91 | void DialogInstaller::themeAnalisys() | ||
120 | { | 92 | { | ||
121 | ui->lb_theme_notice->setText(i18n("Parsing theme...")); | 93 | ui->lb_theme_notice->setText(i18n("Parsing theme...")); | ||
122 | 94 | | |||
123 | ui->theme_file->setEnabled(false); | 95 | ui->theme_file->setEnabled(false); | ||
124 | ui->but_icon_install->setEnabled(false); | | |||
125 | 96 | | |||
126 | QString archivo = ui->theme_file->text(); | 97 | QString archivo = ui->theme_file->text(); | ||
127 | threadAnalisysTheme->setPackageTheme(archivo); | 98 | threadAnalisysTheme->setPackageTheme(archivo); | ||
128 | threadAnalisysTheme->start(); | 99 | threadAnalisysTheme->start(); | ||
129 | } | 100 | } | ||
130 | 101 | | |||
131 | void DialogInstaller::checkThemeAnalisys() | 102 | void DialogInstaller::checkThemeAnalisys() | ||
132 | { | 103 | { | ||
133 | ui->theme_file->setEnabled(true); | 104 | ui->theme_file->setEnabled(true); | ||
134 | 105 | | |||
135 | if(threadAnalisysTheme->isSuccess()) { | 106 | if(threadAnalisysTheme->isSuccess()) { | ||
136 | ui->lb_theme_notice->setText(i18n("This GTK theme can be installed")); | 107 | ui->lb_theme_notice->setText(i18n("This GTK theme can be installed")); | ||
137 | ui->but_theme_install->setEnabled(true); | 108 | ui->but_theme_install->setEnabled(true); | ||
138 | } else { | 109 | } else { | ||
139 | ui->lb_theme_notice->setText(i18n("This GTK theme cannot be installed")); | 110 | ui->lb_theme_notice->setText(i18n("This GTK theme cannot be installed")); | ||
140 | ui->but_theme_install->setEnabled(false); | 111 | ui->but_theme_install->setEnabled(false); | ||
141 | } | 112 | } | ||
142 | 113 | | |||
143 | } | 114 | } | ||
144 | 115 | | |||
145 | void DialogInstaller::themeIconAnalisys() | | |||
146 | { | | |||
147 | ui->lb_icon_notice->setText(i18n("Parsing theme...")); | | |||
148 | | ||||
149 | ui->icon_file->setEnabled(false); | | |||
150 | ui->but_icon_install->setEnabled(false); | | |||
151 | | ||||
152 | QString archivo = ui->icon_file->text(); | | |||
153 | threadAnalisysThemeIcon->setPackageTheme(archivo); | | |||
154 | threadAnalisysThemeIcon->start(); | | |||
155 | } | | |||
156 | | ||||
157 | void DialogInstaller::checkThemeIconAnalisys() | | |||
158 | { | | |||
159 | ui->icon_file->setEnabled(true); | | |||
160 | | ||||
161 | if(threadAnalisysThemeIcon->isSuccess()) { | | |||
162 | ui->lb_icon_notice->setText(i18n("This icons theme can be installed")); | | |||
163 | ui->but_icon_install->setEnabled(true); | | |||
164 | } else { | | |||
165 | ui->lb_icon_notice->setText(i18n("This icons theme cannot be installed")); | | |||
166 | ui->but_icon_install->setEnabled(false); | | |||
167 | } | | |||
168 | } | | |||
169 | | ||||
170 | void DialogInstaller::enableGUIThemeInstaller() | 116 | void DialogInstaller::enableGUIThemeInstaller() | ||
171 | { | 117 | { | ||
172 | ui->but_theme_install->setEnabled(true); | 118 | ui->but_theme_install->setEnabled(true); | ||
173 | ui->theme_file->setEnabled(true); | 119 | ui->theme_file->setEnabled(true); | ||
174 | } | 120 | } | ||
175 | 121 | | |||
176 | void DialogInstaller::enableGUIThemeIconInstaller() | | |||
177 | { | | |||
178 | ui->but_icon_install->setEnabled(true); | | |||
179 | ui->icon_file->setEnabled(true); | | |||
180 | ui->buttonBox->button(QDialogButtonBox::Close)->setEnabled(true); | | |||
181 | } | | |||
182 | | ||||
183 | void DialogInstaller::disableGUIThemeInstaller() | 122 | void DialogInstaller::disableGUIThemeInstaller() | ||
184 | { | 123 | { | ||
185 | ui->lb_theme_notice->setText(i18n("Installing GTK theme...")); | 124 | ui->lb_theme_notice->setText(i18n("Installing GTK theme...")); | ||
186 | ui->but_theme_install->setEnabled(false); | 125 | ui->but_theme_install->setEnabled(false); | ||
187 | ui->theme_file->setEnabled(false); | 126 | ui->theme_file->setEnabled(false); | ||
188 | } | 127 | } | ||
189 | void DialogInstaller::disableGUIThemeIconInstaller() | | |||
190 | { | | |||
191 | ui->lb_icon_notice->setText(i18n("Installing icons...")); | | |||
192 | ui->but_icon_install->setEnabled(false); | | |||
193 | ui->icon_file->setEnabled(false); | | |||
194 | ui->buttonBox->button(QDialogButtonBox::Close)->setEnabled(false); | | |||
195 | } | | |||
196 | 128 | | |||
197 | void DialogInstaller::refreshGUIIconTheme() | | |||
198 | { | | |||
199 | if(threadForIcon->isSuccess()) { | | |||
200 | ui->lb_icon_notice->setText(i18n("Icons Successfully Installed")); | | |||
201 | ui->icon_file->clear(); | | |||
202 | emit themeInstalled(); | | |||
203 | } else { | | |||
204 | ui->lb_icon_notice->setText(i18n("The icons theme cannot be installed")); | | |||
205 | ui->icon_file->clear(); | | |||
206 | } | | |||
207 | } | | |||
208 | 129 | | |||
209 | // Esto se ejecuta cuando un tema es tratado a instalar | 130 | // Esto se ejecuta cuando un tema es tratado a instalar | ||
210 | void DialogInstaller::refreshGUITheme() | 131 | void DialogInstaller::refreshGUITheme() | ||
211 | { | 132 | { | ||
212 | if(threadForTheme->isSuccess()) { | 133 | if(threadForTheme->isSuccess()) { | ||
213 | ui->lb_theme_notice->setText(i18n("GTK Theme Successfully Installed")); | 134 | ui->lb_theme_notice->setText(i18n("GTK Theme Successfully Installed")); | ||
214 | emit themeInstalled(); | 135 | emit themeInstalled(); | ||
215 | } else { | 136 | } else { | ||
216 | ui->lb_theme_notice->setText(i18n("The GTK theme cannot be installed")); | 137 | ui->lb_theme_notice->setText(i18n("The GTK theme cannot be installed")); | ||
217 | } | 138 | } | ||
218 | ui->theme_file->clear(); | 139 | ui->theme_file->clear(); | ||
219 | } | 140 | } |