summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2014-04-24 20:25:29 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2014-04-24 20:33:12 +0200
commit56e326946159407a13eda62e894e11be5a824a4c (patch)
tree0b9e34c9a72ea41bcc0f49a83388aa91c9e487c3 /src
parentd7ce137c11ca63eebe816eedcda1fb1f058ad8bb (diff)
Merge TargetDirectoryPage and TargetDirectoryPageImpl.
Change-Id: I613dbcb431452729bb672b5546e4108c0f613299 Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/libs/installer/packagemanagergui.cpp164
-rw-r--r--src/libs/installer/packagemanagergui.h8
-rw-r--r--src/sdk/installerbasecommons.cpp155
-rw-r--r--src/sdk/installerbasecommons.h20
4 files changed, 141 insertions, 206 deletions
diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp
index 14388776a..f31ade6aa 100644
--- a/src/libs/installer/packagemanagergui.cpp
+++ b/src/libs/installer/packagemanagergui.cpp
@@ -77,6 +77,10 @@
#include <QVBoxLayout>
#include <QShowEvent>
+#ifdef Q_OS_WIN
+# include <qt_windows.h>
+#endif
+
using namespace KDUpdater;
using namespace QInstaller;
@@ -1351,6 +1355,16 @@ TargetDirectoryPage::TargetDirectoryPage(PackageManagerCore *core)
hlayout->addWidget(browseButton);
layout->addLayout(hlayout);
+
+ QPalette palette;
+ palette.setColor(QPalette::WindowText, Qt::red);
+
+ m_warningLabel = new QLabel(this);
+ m_warningLabel->setPalette(palette);
+ m_warningLabel->setWordWrap(true);
+ m_warningLabel->setObjectName(QLatin1String("WarningLabel"));
+ layout->addWidget(m_warningLabel);
+
setLayout(layout);
}
@@ -1381,38 +1395,42 @@ void TargetDirectoryPage::initializePage()
bool TargetDirectoryPage::validatePage()
{
- if (targetDir().isEmpty()) {
- MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
- QLatin1String("EmptyTargetDirectoryMessage"), tr("Error"), tr("The install directory "
- "cannot be empty, please specify a valid folder."), QMessageBox::Ok);
- return false;
- }
+ if (!isVisible())
+ return true;
- const QDir dir(targetDir());
- // it exists, but is empty (might be created by the Browse button (getExistingDirectory)
- if (dir.exists() && dir.entryList(QDir::NoDotAndDotDot).isEmpty())
+ const QString remove = packageManagerCore()->value(QLatin1String("RemoveTargetDir"));
+ if (!QVariant(remove).toBool())
return true;
- if (dir.exists() && dir.isReadable()) {
- // it exists, but is not empty
- if (dir == QDir::root()) {
- MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
- QLatin1String("ForbiddenTargetDirectoryMessage"), tr("Error"), tr("As the install "
- "directory is completely deleted on uninstall, installing in %1 is forbidden.")
- .arg(QDir::rootPath()),
- QMessageBox::Ok);
- return false;
- }
+ const QString targetDir = this->targetDir();
+ const QDir dir(targetDir);
+ // the directory exists and is empty...
+ if (dir.exists() && dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty())
+ return true;
- if (!QVariant(packageManagerCore()->value(scRemoveTargetDir)).toBool())
- return true;
+ const QFileInfo fi(targetDir);
+ if (fi.isDir()) {
+ QString fileName = packageManagerCore()->settings().uninstallerName();
+#if defined(Q_OS_MAC)
+ if (QFileInfo(QCoreApplication::applicationDirPath() + QLatin1String("/../..")).isBundle())
+ fileName += QLatin1String(".app/Contents/MacOS/") + fileName;
+#elif defined(Q_OS_WIN)
+ fileName += QLatin1String(".exe");
+#endif
- return MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(),
- QLatin1String("OverwriteTargetDirectoryMessage"), tr("Warning"), tr("You have "
- "selected an existing, non-empty folder for installation. Note that it will be "
- "completely wiped on uninstallation of this application. It is not advisable to "
- "install into this folder as installation might fail. Do you want to continue?"),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
+ QFileInfo fi2(targetDir + QDir::separator() + fileName);
+ if (fi2.exists()) {
+ return failWithError(QLatin1String("TargetDirectoryInUse"), tr("The folder you selected already "
+ "exists and contains an installation. Choose a different target for installation."));
+ }
+
+ return askQuestion(QLatin1String("OverwriteTargetDirectory"),
+ tr("You have selected an existing, non-empty folder for installation.\nNote that it will be "
+ "completely wiped on uninstallation of this application.\nIt is not advisable to install into "
+ "this folder as installation might fail.\nDo you want to continue?"));
+ } else if (fi.isFile() || fi.isSymLink()) {
+ return failWithError(QLatin1String("WrongTargetDirectory"), tr("You have selected an existing file "
+ "or symlink, please choose a different target for installation."));
}
return true;
}
@@ -1430,10 +1448,6 @@ void TargetDirectoryPage::leaving()
packageManagerCore()->setValue(scTargetDir, targetDir());
}
-void TargetDirectoryPage::targetDirSelected()
-{
-}
-
void TargetDirectoryPage::dirRequested()
{
const QString newDirName = QFileDialog::getExistingDirectory(this,
@@ -1443,6 +1457,94 @@ void TargetDirectoryPage::dirRequested()
m_lineEdit->setText(QDir::toNativeSeparators(newDirName));
}
+bool TargetDirectoryPage::isComplete() const
+{
+ m_warningLabel->setText(targetDirWarning());
+ return m_warningLabel->text().isEmpty();
+}
+
+QString TargetDirectoryPage::targetDirWarning() const
+{
+ if (targetDir().isEmpty()) {
+ return tr("The installation path cannot be empty, please specify a valid "
+ "folder.");
+ }
+
+ if (QDir(targetDir()).isRelative()) {
+ return tr("The installation path cannot be relative, please specify an "
+ "absolute path.");
+ }
+
+ QDir target(targetDir());
+ target = target.canonicalPath();
+
+ if (target.isRoot()) {
+ return tr("As the install directory is completely deleted, installing "
+ "in %1 is forbidden.").arg(QDir::toNativeSeparators(QDir::rootPath()));
+ }
+
+ if (target == QDir::home()) {
+ return tr("As the install directory is completely deleted, installing "
+ "in %1 is forbidden.").arg(QDir::toNativeSeparators(QDir::homePath()));
+ }
+
+ QString dir = QDir::toNativeSeparators(targetDir());
+#ifdef Q_OS_WIN
+ // folder length (set by user) + maintenance tool name length (no extension) + extra padding
+ if ((dir.length() + packageManagerCore()->settings().uninstallerName().length() + 20) >= MAX_PATH) {
+ return tr("The path you have entered is too long, please make sure to "
+ "specify a valid path.");
+ }
+
+ if (dir.count() >= 3 && dir.indexOf(QRegExp(QLatin1String("[a-zA-Z]:"))) == 0
+ && dir.at(2) != QLatin1Char('\\')) {
+ return tr("The path you have entered is not valid, please make sure to "
+ "specify a valid drive.");
+ }
+
+ // remove e.g. "c:"
+ dir = dir.mid(2);
+#endif
+
+ QString ambiguousChars = QLatin1String("[~<>|?*!@#$%^&:,; ]");
+ if (packageManagerCore()->settings().allowSpaceInPath())
+ ambiguousChars.remove(QLatin1Char(' '));
+
+ // check if there are not allowed characters in the target path
+ if (dir.contains(QRegExp(ambiguousChars))) {
+ return tr("The installation path must not contain %1, "
+ "please specify a valid folder.").arg(ambiguousChars);
+ }
+
+ dir = targetDir();
+ if (!packageManagerCore()->settings().allowNonAsciiCharacters()) {
+ for (int i = 0; i < dir.length(); ++i) {
+ if (dir.at(i).unicode() & 0xff80) {
+ return tr("The path or installation directory contains non ASCII "
+ "characters. This is currently not supported! Please choose a different path or "
+ "installation directory.");
+ }
+ }
+ }
+
+ return QString();
+}
+
+bool TargetDirectoryPage::askQuestion(const QString &identifier, const QString &message)
+{
+ QMessageBox::StandardButton bt =
+ MessageBoxHandler::warning(MessageBoxHandler::currentBestSuitParent(), identifier,
+ tr("Warning"), message, QMessageBox::Yes | QMessageBox::No);
+ return bt == QMessageBox::Yes;
+}
+
+bool TargetDirectoryPage::failWithError(const QString &identifier, const QString &message)
+{
+ MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), identifier,
+ tr("Error"), message);
+ return false;
+}
+
// -- StartMenuDirectoryPage
diff --git a/src/libs/installer/packagemanagergui.h b/src/libs/installer/packagemanagergui.h
index 906f3530d..e1544306a 100644
--- a/src/libs/installer/packagemanagergui.h
+++ b/src/libs/installer/packagemanagergui.h
@@ -299,17 +299,23 @@ public:
void initializePage();
bool validatePage();
+ bool isComplete() const;
protected:
void entering();
void leaving();
private Q_SLOTS:
- void targetDirSelected();
void dirRequested();
private:
+ QString targetDirWarning() const;
+ bool askQuestion(const QString &identifier, const QString &message);
+ bool failWithError(const QString &identifier, const QString &message);
+
+private:
QLineEdit *m_lineEdit;
+ QLabel *m_warningLabel;
};
diff --git a/src/sdk/installerbasecommons.cpp b/src/sdk/installerbasecommons.cpp
index 263eb5767..8bf6ca449 100644
--- a/src/sdk/installerbasecommons.cpp
+++ b/src/sdk/installerbasecommons.cpp
@@ -58,10 +58,6 @@
#include <QStackedWidget>
#include <QVBoxLayout>
-#ifdef Q_OS_WIN
-#include <qt_windows.h>
-#endif
-
using namespace QInstaller;
@@ -369,155 +365,6 @@ void IntroductionPageImpl::showWidgets(bool show)
}
-// -- TargetDirectoryPageImpl
-
-/*!
- A custom target directory selection based due to the no-space restriction...
-*/
-TargetDirectoryPageImpl::TargetDirectoryPageImpl(PackageManagerCore *core)
- : TargetDirectoryPage(core)
-{
- QPalette palette;
- palette.setColor(QPalette::WindowText, Qt::red);
-
- m_warningLabel = new QLabel(this);
- m_warningLabel->setPalette(palette);
- m_warningLabel->setWordWrap(true);
-
- insertWidget(m_warningLabel, QLatin1String("MessageLabel"), 2);
-}
-
-QString TargetDirectoryPageImpl::targetDirWarning() const
-{
- if (targetDir().isEmpty()) {
- return TargetDirectoryPageImpl::tr("The installation path cannot be empty, please specify a valid "
- "folder.");
- }
-
- if (QDir(targetDir()).isRelative()) {
- return TargetDirectoryPageImpl::tr("The installation path cannot be relative, please specify an "
- "absolute path.");
- }
-
- QDir target(targetDir());
- target = target.canonicalPath();
-
- if (target.isRoot()) {
- return TargetDirectoryPageImpl::tr("As the install directory is completely deleted, installing "
- "in %1 is forbidden.").arg(QDir::toNativeSeparators(QDir::rootPath()));
- }
-
- if (target == QDir::home()) {
- return TargetDirectoryPageImpl::tr("As the install directory is completely deleted, installing "
- "in %1 is forbidden.").arg(QDir::toNativeSeparators(QDir::homePath()));
- }
-
- QString dir = QDir::toNativeSeparators(targetDir());
-#ifdef Q_OS_WIN
- // folder length (set by user) + maintenance tool name length (no extension) + extra padding
- if ((dir.length() + packageManagerCore()->settings().uninstallerName().length() + 20) >= MAX_PATH) {
- return TargetDirectoryPageImpl::tr("The path you have entered is too long, please make sure to "
- "specify a valid path.");
- }
-
- if (dir.count() >= 3 && dir.indexOf(QRegExp(QLatin1String("[a-zA-Z]:"))) == 0
- && dir.at(2) != QLatin1Char('\\')) {
- return TargetDirectoryPageImpl::tr("The path you have entered is not valid, please make sure to "
- "specify a valid drive.");
- }
-
- // remove e.g. "c:"
- dir = dir.mid(2);
-#endif
-
- QString ambiguousChars = QLatin1String("[~<>|?*!@#$%^&:,; ]");
- if (packageManagerCore()->settings().allowSpaceInPath())
- ambiguousChars.remove(QLatin1Char(' '));
-
- // check if there are not allowed characters in the target path
- if (dir.contains(QRegExp(ambiguousChars))) {
- return TargetDirectoryPageImpl::tr("The installation path must not contain %1, "
- "please specify a valid folder.").arg(ambiguousChars);
- }
-
- dir = targetDir();
- if (!packageManagerCore()->settings().allowNonAsciiCharacters()) {
- for (int i = 0; i < dir.length(); ++i) {
- if (dir.at(i).unicode() & 0xff80) {
- return TargetDirectoryPageImpl::tr("The path or installation directory contains non ASCII "
- "characters. This is currently not supported! Please choose a different path or "
- "installation directory.");
- }
- }
- }
-
- return QString();
-}
-
-bool TargetDirectoryPageImpl::isComplete() const
-{
- m_warningLabel->setText(targetDirWarning());
- return m_warningLabel->text().isEmpty();
-}
-
-bool TargetDirectoryPageImpl::askQuestion(const QString &identifier, const QString &message)
-{
- QMessageBox::StandardButton bt =
- MessageBoxHandler::warning(MessageBoxHandler::currentBestSuitParent(), identifier,
- TargetDirectoryPageImpl::tr("Warning"), message, QMessageBox::Yes | QMessageBox::No);
- return bt == QMessageBox::Yes;
-}
-
-bool TargetDirectoryPageImpl::failWithError(const QString &identifier, const QString &message)
-{
- MessageBoxHandler::critical(MessageBoxHandler::currentBestSuitParent(), identifier,
- TargetDirectoryPageImpl::tr("Error"), message);
- return false;
-}
-
-bool TargetDirectoryPageImpl::validatePage()
-{
- if (!isVisible())
- return true;
-
- const QString remove = packageManagerCore()->value(QLatin1String("RemoveTargetDir"));
- if (!QVariant(remove).toBool())
- return true;
-
- const QString targetDir = this->targetDir();
- const QDir dir(targetDir);
- // the directory exists and is empty...
- if (dir.exists() && dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty())
- return true;
-
- const QFileInfo fi(targetDir);
- if (fi.isDir()) {
- QString fileName = packageManagerCore()->settings().uninstallerName();
-#if defined(Q_OS_MAC)
- if (QFileInfo(QCoreApplication::applicationDirPath() + QLatin1String("/../..")).isBundle())
- fileName += QLatin1String(".app/Contents/MacOS/") + fileName;
-#elif defined(Q_OS_WIN)
- fileName += QLatin1String(".exe");
-#endif
-
- QFileInfo fi2(targetDir + QDir::separator() + fileName);
- if (fi2.exists()) {
- return failWithError(QLatin1String("TargetDirectoryInUse"), tr("The folder you selected already "
- "exists and contains an installation. Choose a different target for installation."));
- }
-
- return askQuestion(QLatin1String("OverwriteTargetDirectory"),
- tr("You have selected an existing, non-empty folder for installation.\nNote that it will be "
- "completely wiped on uninstallation of this application.\nIt is not advisable to install into "
- "this folder as installation might fail.\nDo you want to continue?"));
- } else if (fi.isFile() || fi.isSymLink()) {
- return failWithError(QLatin1String("WrongTargetDirectory"), tr("You have selected an existing file "
- "or symlink, please choose a different target for installation."));
- }
- return true;
-}
-
-
// -- InstallerGui
InstallerGui::InstallerGui(PackageManagerCore *core)
@@ -531,7 +378,7 @@ InstallerGui::InstallerGui(PackageManagerCore *core)
setPage(id, page);
}
setPage(PackageManagerCore::Introduction, new IntroductionPageImpl(core));
- setPage(PackageManagerCore::TargetDirectory, new TargetDirectoryPageImpl(core));
+ setPage(PackageManagerCore::TargetDirectory, new TargetDirectoryPage(core));
setPage(PackageManagerCore::ComponentSelection, new ComponentSelectionPage(core));
setPage(PackageManagerCore::LicenseCheck, new LicenseAgreementPage(core));
#ifdef Q_OS_WIN
diff --git a/src/sdk/installerbasecommons.h b/src/sdk/installerbasecommons.h
index 79330eaf7..8103145dd 100644
--- a/src/sdk/installerbasecommons.h
+++ b/src/sdk/installerbasecommons.h
@@ -106,26 +106,6 @@ private:
};
-// --TargetDirectoryPageImpl
-
-class TargetDirectoryPageImpl : public QInstaller::TargetDirectoryPage
-{
- Q_OBJECT
-
-public:
- explicit TargetDirectoryPageImpl(QInstaller::PackageManagerCore *core);
-
- QString targetDirWarning() const;
- bool isComplete() const;
- bool askQuestion(const QString &identifier, const QString &message);
- bool failWithError(const QString &identifier, const QString &message);
- bool validatePage();
-
-private:
- QLabel *m_warningLabel;
-};
-
-
// -- InstallerGui
class InstallerGui : public QInstaller::PackageManagerGui