Changeset View
Changeset View
Standalone View
Standalone View
plugins/appwizard/projectselectionpage.cpp
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright 2007 Alexander Dymo <adymo@kdevelop.org> * | 2 | * Copyright 2007 Alexander Dymo <adymo@kdevelop.org> * | ||
3 | * Copyright 2011 Aleix Pol Gonzalez <aleixpol@kde.org> * | 3 | * Copyright 2011 Aleix Pol Gonzalez <aleixpol@kde.org> * | ||
4 | * * | 4 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | 5 | * This program is free software; you can redistribute it and/or modify * | ||
6 | * it under the terms of the GNU General Public License as published by * | 6 | * it under the terms of the GNU General Public License as published by * | ||
7 | * the Free Software Foundation; either version 2 of the License, or * | 7 | * the Free Software Foundation; either version 2 of the License, or * | ||
8 | * (at your option) any later version. * | 8 | * (at your option) any later version. * | ||
9 | * * | 9 | * * | ||
10 | ***************************************************************************/ | 10 | ***************************************************************************/ | ||
11 | #include "projectselectionpage.h" | 11 | #include "projectselectionpage.h" | ||
12 | #include "debug.h" | 12 | #include "debug.h" | ||
13 | 13 | | |||
14 | #include <QDir> | 14 | #include <QDir> | ||
15 | #include <QFileDialog> | 15 | #include <QFileDialog> | ||
16 | #include <QPointer> | ||||
16 | 17 | | |||
17 | #include <KConfig> | 18 | #include <KConfig> | ||
18 | #include <KConfigGroup> | 19 | #include <KConfigGroup> | ||
19 | #include <KLineEdit> | 20 | #include <KLineEdit> | ||
20 | #include <KLocalizedString> | 21 | #include <KLocalizedString> | ||
21 | #include <KMessageBox> | 22 | #include <KMessageBox> | ||
22 | #include <KNS3/DownloadDialog> | 23 | #include <KNS3/DownloadDialog> | ||
23 | 24 | | |||
▲ Show 20 Lines • Show All 276 Lines • ▼ Show 20 Line(s) | |||||
300 | 301 | | |||
301 | void ProjectSelectionPage::loadFileClicked() | 302 | void ProjectSelectionPage::loadFileClicked() | ||
302 | { | 303 | { | ||
303 | const QStringList supportedMimeTypes { | 304 | const QStringList supportedMimeTypes { | ||
304 | QStringLiteral("application/x-desktop"), | 305 | QStringLiteral("application/x-desktop"), | ||
305 | QStringLiteral("application/x-bzip-compressed-tar"), | 306 | QStringLiteral("application/x-bzip-compressed-tar"), | ||
306 | QStringLiteral("application/zip") | 307 | QStringLiteral("application/zip") | ||
307 | }; | 308 | }; | ||
308 | QFileDialog fileDialog(this, i18n("Load Template From File")); | 309 | QPointer<QFileDialog> fileDialog = new QFileDialog(this, i18n("Load Template From File")); | ||
309 | fileDialog.setMimeTypeFilters(supportedMimeTypes); | 310 | fileDialog->setMimeTypeFilters(supportedMimeTypes); | ||
310 | fileDialog.setFileMode(QFileDialog::ExistingFiles); | 311 | fileDialog->setFileMode(QFileDialog::ExistingFiles); | ||
311 | 312 | | |||
312 | if (!fileDialog.exec()) { | 313 | if (!fileDialog->exec()) { | ||
314 | delete fileDialog; | ||||
313 | return; | 315 | return; | ||
314 | } | 316 | } | ||
315 | 317 | | |||
316 | for (const auto& fileName : fileDialog.selectedFiles()) { | 318 | for (const auto& fileName : fileDialog->selectedFiles()) { | ||
317 | QString destination = m_templatesModel->loadTemplateFile(fileName); | 319 | QString destination = m_templatesModel->loadTemplateFile(fileName); | ||
318 | QModelIndexList indexes = m_templatesModel->templateIndexes(destination); | 320 | QModelIndexList indexes = m_templatesModel->templateIndexes(destination); | ||
319 | if (indexes.size() > 2) | 321 | if (indexes.size() > 2) | ||
320 | { | 322 | { | ||
321 | m_listView->setCurrentIndex(indexes.at(1)); | 323 | m_listView->setCurrentIndex(indexes.at(1)); | ||
322 | ui->templateType->setCurrentIndex(indexes.at(2).row()); | 324 | ui->templateType->setCurrentIndex(indexes.at(2).row()); | ||
323 | } | 325 | } | ||
324 | } | 326 | } | ||
327 | | ||||
328 | delete fileDialog; | ||||
325 | } | 329 | } | ||
326 | 330 | | |||
327 | void ProjectSelectionPage::moreTemplatesClicked() | 331 | void ProjectSelectionPage::moreTemplatesClicked() | ||
328 | { | 332 | { | ||
329 | KNS3::DownloadDialog dialog(QStringLiteral("kdevappwizard.knsrc"), this); | 333 | QPointer<KNS3::DownloadDialog> dialog = | ||
330 | dialog.exec(); | 334 | new KNS3::DownloadDialog(QStringLiteral("kdevappwizard.knsrc"), this); | ||
335 | dialog->exec(); | ||||
anthonyfieroni: Check should be done on every exec afterwards dialog is used, cause potentially it can be… | |||||
Do you mean like this? DownloadDialog does not delete itself, so I'm wondering what could go wrong, since changedEntries will just be empty. croick: Do you mean like this? DownloadDialog does not delete itself, so I'm wondering what could go… | |||||
331 | 336 | | |||
332 | auto entries = dialog.changedEntries(); | 337 | auto entries = dialog->changedEntries(); | ||
338 | delete dialog; | ||||
333 | if (entries.isEmpty()) { | 339 | if (entries.isEmpty()) { | ||
334 | return; | 340 | return; | ||
335 | } | 341 | } | ||
336 | 342 | | |||
337 | m_templatesModel->refresh(); | 343 | m_templatesModel->refresh(); | ||
338 | bool updated = false; | 344 | bool updated = false; | ||
339 | 345 | | |||
340 | foreach (const KNS3::Entry& entry, entries) | 346 | foreach (const KNS3::Entry& entry, entries) | ||
Show All 27 Lines |
Check should be done on every exec afterwards dialog is used, cause potentially it can be deleted