diff --git a/src/plugins/qtapplicationmanager/appmanagercreatepackagestep.cpp b/src/plugins/qtapplicationmanager/appmanagercreatepackagestep.cpp index 4df49e2818e..92c46fb677a 100644 --- a/src/plugins/qtapplicationmanager/appmanagercreatepackagestep.cpp +++ b/src/plugins/qtapplicationmanager/appmanagercreatepackagestep.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include using namespace ProjectExplorer; @@ -37,42 +38,33 @@ public: { setDisplayName(Tr::tr("Create Application Manager package")); - executable.setSettingsKey(SETTINGSPREFIX "Executable"); - executable.setHistoryCompleter(SETTINGSPREFIX "Executable.History"); - executable.setExpectedKind(PathChooser::ExistingCommand); - executable.setLabelText(Tr::tr("Executable:")); - executable.setPromptDialogFilter(getToolNameByDevice(Constants::APPMAN_PACKAGER)); + packager.setSettingsKey(SETTINGSPREFIX "Executable"); arguments.setSettingsKey(SETTINGSPREFIX "Arguments"); - arguments.setHistoryCompleter(SETTINGSPREFIX "Arguments.History"); - arguments.setDisplayStyle(StringAspect::LineEditDisplay); - arguments.setLabelText(Tr::tr("Arguments:")); sourceDirectory.setSettingsKey(SETTINGSPREFIX "SourceDirectory"); - sourceDirectory.setHistoryCompleter(SETTINGSPREFIX "SourceDirectory.History"); - sourceDirectory.setExpectedKind(PathChooser::Directory); sourceDirectory.setLabelText(Tr::tr("Source directory:")); + sourceDirectory.setExpectedKind(Utils::PathChooser::ExistingDirectory); - buildDirectory.setSettingsKey(SETTINGSPREFIX "BuildDirectory"); - buildDirectory.setHistoryCompleter(SETTINGSPREFIX "BuildDirectory.History"); - buildDirectory.setExpectedKind(PathChooser::Directory); - buildDirectory.setLabelText(Tr::tr("Build directory:")); - - packageFileName.setSettingsKey(SETTINGSPREFIX "FileName"); - packageFileName.setHistoryCompleter(SETTINGSPREFIX "FileName.History"); - packageFileName.setDisplayStyle(StringAspect::LineEditDisplay); - packageFileName.setLabelText(Tr::tr("Package file name:")); + packageFile.setSettingsKey(SETTINGSPREFIX "FileName"); + packageFile.setLabelText(Tr::tr("Package file:")); + packageFile.setExpectedKind(Utils::PathChooser::SaveFile); const auto updateAspects = [this] { const auto targetInformation = TargetInformation(target()); - executable.setPlaceHolderPath(getToolFilePath(Constants::APPMAN_PACKAGER, target()->kit(), nullptr)); - arguments.setPlaceHolderText(ArgumentsDefault); - sourceDirectory.setPlaceHolderPath(targetInformation.packageSourcesDirectory.absolutePath()); - buildDirectory.setPlaceHolderPath(targetInformation.buildDirectory.absolutePath()); - packageFileName.setPlaceHolderText(targetInformation.packageFile.fileName()); + packager.setValue(FilePath::fromString(getToolFilePath(Constants::APPMAN_PACKAGER, + target()->kit(), + targetInformation.device))); + packager.setDefaultValue(packager.value()); + arguments.setArguments(ArgumentsDefault); + arguments.setResetter([] { return QLatin1String(ArgumentsDefault); }); - setEnabled(!targetInformation.isBuiltin); + packageFile.setValue(targetInformation.packageFile.absoluteFilePath()); + packageFile.setDefaultValue(packageFile.value()); + + sourceDirectory.setValue(targetInformation.packageSourcesDirectory.absolutePath()); + sourceDirectory.setDefaultValue(sourceDirectory.value()); }; connect(target(), &Target::activeRunConfigurationChanged, this, updateAspects); @@ -88,31 +80,31 @@ public: if (!AbstractProcessStep::init()) return false; - const auto targetInformation = TargetInformation(target()); - if (!targetInformation.isValid()) - return false; + const FilePath packagerPath = packager().isEmpty() ? + FilePath::fromString(packager.defaultValue()) : + packager(); + const QString packagerArguments = arguments(); + const FilePath sourceDirectoryPath = sourceDirectory().isEmpty() ? + FilePath::fromString(sourceDirectory.defaultValue()) : + sourceDirectory(); + const FilePath packageFilePath = packageFile().isEmpty() ? + FilePath::fromString(packageFile.defaultValue()) : + packageFile(); - const FilePath packager = executable.valueOrDefault(getToolFilePath(Constants::APPMAN_PACKAGER, target()->kit(), nullptr)); - const QString packagerArguments = arguments.valueOrDefault(ArgumentsDefault); - const FilePath packageSourcesDirectory = sourceDirectory.valueOrDefault(targetInformation.packageSourcesDirectory.absolutePath()); - const FilePath packageDirectory = buildDirectory.valueOrDefault(targetInformation.buildDirectory.absolutePath()); - const QString packageFile = packageFileName.valueOrDefault(targetInformation.packageFile.fileName()); - CommandLine cmd(packager); + CommandLine cmd(packagerPath); cmd.addArgs(packagerArguments, CommandLine::Raw); - cmd.addArgs({packageFile, packageSourcesDirectory.path()}); - processParameters()->setWorkingDirectory(packageDirectory); + cmd.addArgs({packageFilePath.nativePath(), sourceDirectoryPath.nativePath()}); processParameters()->setCommandLine(cmd); return true; } private: - AppManagerFilePathAspect executable{this}; - AppManagerStringAspect arguments{this}; - AppManagerFilePathAspect sourceDirectory{this}; - AppManagerFilePathAspect buildDirectory{this}; - AppManagerStringAspect packageFileName{this}; + AppManagerPackagerAspect packager{this}; + ProjectExplorer::ArgumentsAspect arguments{this}; + FilePathAspect sourceDirectory{this}; + FilePathAspect packageFile{this}; }; // Factory diff --git a/src/plugins/qtapplicationmanager/appmanagerdeploypackagestep.cpp b/src/plugins/qtapplicationmanager/appmanagerdeploypackagestep.cpp index 697b9366bf0..bba35318fc0 100644 --- a/src/plugins/qtapplicationmanager/appmanagerdeploypackagestep.cpp +++ b/src/plugins/qtapplicationmanager/appmanagerdeploypackagestep.cpp @@ -39,21 +39,19 @@ public: setDisplayName(Tr::tr("Deploy Application Manager package")); packageFilePath.setSettingsKey(SETTINGSPREFIX "FilePath"); - packageFilePath.setHistoryCompleter(SETTINGSPREFIX "FilePath.History"); - packageFilePath.setExpectedKind(PathChooser::File); - packageFilePath.setLabelText(Tr::tr("Package file path:")); + packageFilePath.setLabelText(Tr::tr("Package file:")); targetDirectory.setSettingsKey(SETTINGSPREFIX "TargetDirectory"); - targetDirectory.setHistoryCompleter(SETTINGSPREFIX "TargetDirectory.History"); - targetDirectory.setExpectedKind(PathChooser::Directory); targetDirectory.setLabelText(Tr::tr("Target directory:")); - targetDirectory.setButtonsVisible(false); const auto updateAspects = [this] { const TargetInformation targetInformation(target()); - packageFilePath.setPlaceHolderPath(targetInformation.packageFile.absoluteFilePath()); - targetDirectory.setPlaceHolderPath(targetInformation.runDirectory.absolutePath()); + packageFilePath.setValue(targetInformation.packageFile.absoluteFilePath()); + packageFilePath.setDefaultValue(packageFilePath.value()); + + targetDirectory.setValue(targetInformation.runDirectory.absolutePath()); + targetDirectory.setDefaultValue(targetDirectory.value()); setEnabled(!targetInformation.isBuiltin); }; @@ -77,10 +75,12 @@ private: { const auto onSetup = [this](FileStreamer &streamer) { const TargetInformation targetInformation(target()); - const FilePath source = packageFilePath.valueOrDefault( - targetInformation.packageFile.absoluteFilePath()); - const FilePath targetDir = targetDirectory.valueOrDefault( - targetInformation.runDirectory.absolutePath()); + const FilePath source = packageFilePath().isEmpty() ? + FilePath::fromString(packageFilePath.defaultValue()) : + packageFilePath(); + const FilePath targetDir = targetDirectory().isEmpty() ? + FilePath::fromString(targetDirectory.defaultValue()) : + targetDirectory(); const FilePath target = targetInformation.device->filePath(targetDir.path()) .pathAppended(source.fileName()); streamer.setSource(source); @@ -96,8 +96,8 @@ private: return FileStreamerTask(onSetup, onDone); } - AppManagerFilePathAspect packageFilePath{this}; - AppManagerFilePathAspect targetDirectory{this}; + FilePathAspect packageFilePath{this}; + FilePathAspect targetDirectory{this}; }; // Factory diff --git a/src/plugins/qtapplicationmanager/appmanagerinstallpackagestep.cpp b/src/plugins/qtapplicationmanager/appmanagerinstallpackagestep.cpp index 79895da02aa..82d63cc2c66 100644 --- a/src/plugins/qtapplicationmanager/appmanagerinstallpackagestep.cpp +++ b/src/plugins/qtapplicationmanager/appmanagerinstallpackagestep.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -30,8 +31,6 @@ const char ArgumentsDefault[] = "install-package -a"; class AppManagerInstallPackageStep final : public AbstractProcessStep { - Q_DECLARE_TR_FUNCTIONS(AppManager::Internal::AppManagerInstallPackageStep) - public: AppManagerInstallPackageStep(BuildStepList *bsl, Id id); @@ -39,10 +38,9 @@ protected: bool init() final; private: - AppManagerFilePathAspect executable{this}; - AppManagerStringAspect arguments{this}; - AppManagerStringAspect packageFileName{this}; - AppManagerFilePathAspect packageDirectory{this}; + AppManagerControllerAspect controller{this}; + ProjectExplorer::ArgumentsAspect arguments{this}; + FilePathAspect packageFile{this}; }; AppManagerInstallPackageStep::AppManagerInstallPackageStep(BuildStepList *bsl, Id id) @@ -50,39 +48,22 @@ AppManagerInstallPackageStep::AppManagerInstallPackageStep(BuildStepList *bsl, I { setDisplayName(Tr::tr("Install Application Manager package")); - executable.setSettingsKey(SETTINGSPREFIX "Executable"); - executable.setHistoryCompleter(SETTINGSPREFIX "Executable.History"); - executable.setLabelText(Tr::tr("Executable:")); - arguments.setSettingsKey(SETTINGSPREFIX "Arguments"); - arguments.setHistoryCompleter(SETTINGSPREFIX "Arguments.History"); - arguments.setDisplayStyle(StringAspect::LineEditDisplay); - arguments.setLabelText(Tr::tr("Arguments:")); - packageFileName.setSettingsKey(SETTINGSPREFIX "FileName"); - packageFileName.setHistoryCompleter(SETTINGSPREFIX "FileName.History"); - packageFileName.setDisplayStyle(StringAspect::LineEditDisplay); - packageFileName.setLabelText(Tr::tr("File name:")); - - packageDirectory.setSettingsKey(SETTINGSPREFIX "Directory"); - packageDirectory.setHistoryCompleter(SETTINGSPREFIX "Directory.History"); - packageDirectory.setExpectedKind(PathChooser::Directory); - packageDirectory.setLabelText(Tr::tr("Directory:")); + packageFile.setSettingsKey(SETTINGSPREFIX "FileName"); + packageFile.setLabelText(Tr::tr("Package file:")); const auto updateAspects = [this] { const TargetInformation targetInformation(target()); - executable.setPromptDialogFilter(getToolNameByDevice(Constants::APPMAN_CONTROLLER, targetInformation.device)); - executable.setButtonsVisible(!targetInformation.remote); - executable.setExpectedKind(targetInformation.remote ? PathChooser::Command : PathChooser::ExistingCommand); - executable.setPlaceHolderPath(getToolFilePath(Constants::APPMAN_CONTROLLER, target()->kit(), targetInformation.device)); - arguments.setPlaceHolderText(ArgumentsDefault); - packageFileName.setPlaceHolderText(targetInformation.packageFile.fileName()); - auto device = DeviceKitAspect::device(target()->kit()); - bool remote = device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; - QDir packageDirectoryPath = remote ? QDir(Constants::REMOTE_DEFAULT_TMP_PATH) : targetInformation.packageFile.absolutePath(); - packageDirectory.setPlaceHolderPath(packageDirectoryPath.absolutePath()); - packageDirectory.setButtonsVisible(!targetInformation.remote); + controller.setValue(FilePath::fromString(getToolFilePath(Constants::APPMAN_CONTROLLER, + target()->kit(), + targetInformation.device))); + controller.setDefaultValue(controller.value()); + arguments.setArguments(ArgumentsDefault); + arguments.setResetter([] { return QLatin1String(ArgumentsDefault); }); + + packageFile.setValue(targetInformation.packageFile.absoluteFilePath()); setEnabled(!targetInformation.isBuiltin); }; @@ -100,22 +81,17 @@ bool AppManagerInstallPackageStep::init() if (!AbstractProcessStep::init()) return false; - const TargetInformation targetInformation(target()); - if (!targetInformation.isValid()) - return false; + const FilePath controllerPath = controller().isEmpty() ? + FilePath::fromString(controller.defaultValue()) : + controller(); + const QString controllerArguments = arguments(); + const FilePath packageFilePath = packageFile().isEmpty() ? + FilePath::fromString(packageFile.defaultValue()) : + packageFile(); - const FilePath controller = executable.valueOrDefault(getToolFilePath(Constants::APPMAN_CONTROLLER, target()->kit(), targetInformation.device)); - const QString controllerArguments = arguments.valueOrDefault(ArgumentsDefault); - const QString packageFile = packageFileName.valueOrDefault(targetInformation.packageFile.fileName()); - auto device = DeviceKitAspect::device(target()->kit()); - bool remote = device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; - QDir packageDirectoryPath = remote ? QDir(Constants::REMOTE_DEFAULT_TMP_PATH) : targetInformation.packageFile.absolutePath(); - const FilePath packageDir = packageDirectory.valueOrDefault(packageDirectoryPath.absolutePath()); - - CommandLine cmd(targetInformation.device->filePath(controller.path())); + CommandLine cmd(controllerPath); cmd.addArgs(controllerArguments, CommandLine::Raw); - cmd.addArg(packageFile); - processParameters()->setWorkingDirectory(packageDir); + cmd.addArg(packageFilePath.nativePath()); processParameters()->setCommandLine(cmd); return true; diff --git a/src/plugins/qtapplicationmanager/appmanagerremoteinstallpackagestep.cpp b/src/plugins/qtapplicationmanager/appmanagerremoteinstallpackagestep.cpp index d36045f9d90..3a44508513d 100644 --- a/src/plugins/qtapplicationmanager/appmanagerremoteinstallpackagestep.cpp +++ b/src/plugins/qtapplicationmanager/appmanagerremoteinstallpackagestep.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -35,8 +36,6 @@ const char ArgumentsDefault[] = "install-package -a"; class AppManagerRemoteInstallPackageStep final : public RemoteLinux::AbstractRemoteLinuxDeployStep { - Q_DECLARE_TR_FUNCTIONS(AppManager::Internal::AppManagerInstallPackageStep) - public: AppManagerRemoteInstallPackageStep(BuildStepList *bsl, Id id); @@ -44,10 +43,9 @@ private: GroupItem deployRecipe() final; private: - AppManagerFilePathAspect executable{this}; - AppManagerStringAspect arguments{this}; - AppManagerStringAspect packageFileName{this}; - AppManagerFilePathAspect packageDirectory{this}; + AppManagerControllerAspect controller{this}; + ProjectExplorer::ArgumentsAspect arguments{this}; + FilePathAspect packageFile{this}; }; AppManagerRemoteInstallPackageStep::AppManagerRemoteInstallPackageStep(BuildStepList *bsl, Id id) @@ -55,41 +53,25 @@ AppManagerRemoteInstallPackageStep::AppManagerRemoteInstallPackageStep(BuildStep { setDisplayName(tr("Remote Install Application Manager package")); - executable.setSettingsKey(SETTINGSPREFIX "Executable"); - executable.setHistoryCompleter(SETTINGSPREFIX "Executable.History"); - executable.setLabelText(tr("Executable:")); - arguments.setSettingsKey(SETTINGSPREFIX "Arguments"); - arguments.setHistoryCompleter(SETTINGSPREFIX "Arguments.History"); - arguments.setDisplayStyle(StringAspect::LineEditDisplay); - arguments.setLabelText(tr("Arguments:")); - packageFileName.setSettingsKey(SETTINGSPREFIX "FileName"); - packageFileName.setHistoryCompleter(SETTINGSPREFIX "FileName.History"); - packageFileName.setDisplayStyle(StringAspect::LineEditDisplay); - packageFileName.setLabelText(tr("File name:")); - - packageDirectory.setSettingsKey(SETTINGSPREFIX "Directory"); - packageDirectory.setHistoryCompleter(SETTINGSPREFIX "Directory.History"); - packageDirectory.setExpectedKind(PathChooser::Directory); - packageDirectory.setLabelText(tr("Directory:")); + packageFile.setSettingsKey(SETTINGSPREFIX "FileName"); + packageFile.setLabelText(Tr::tr("Package file:")); setInternalInitializer([this] { return isDeploymentPossible(); }); const auto updateAspects = [this] { const TargetInformation targetInformation(target()); - executable.setPromptDialogFilter(getToolNameByDevice(Constants::APPMAN_CONTROLLER, targetInformation.device)); - executable.setButtonsVisible(!targetInformation.remote); - executable.setExpectedKind(targetInformation.remote ? PathChooser::Command : PathChooser::ExistingCommand); - executable.setPlaceHolderPath(getToolFilePath(Constants::APPMAN_CONTROLLER, target()->kit(), targetInformation.device)); - arguments.setPlaceHolderText(ArgumentsDefault); - packageFileName.setPlaceHolderText(targetInformation.packageFile.fileName()); - auto device = DeviceKitAspect::device(target()->kit()); - bool remote = device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; - QDir packageDirectoryPath = remote ? QDir(Constants::REMOTE_DEFAULT_TMP_PATH) : targetInformation.packageFile.absolutePath(); - packageDirectory.setPlaceHolderPath(packageDirectoryPath.absolutePath()); - packageDirectory.setButtonsVisible(!targetInformation.remote); + controller.setValue(FilePath::fromString(getToolFilePath(Constants::APPMAN_CONTROLLER, + target()->kit(), + targetInformation.device))); + controller.setDefaultValue(controller.value()); + arguments.setArguments(ArgumentsDefault); + arguments.setResetter([](){ return QLatin1String(ArgumentsDefault); }); + + packageFile.setValue(targetInformation.packageFile.absoluteFilePath()); + packageFile.setDefaultValue(packageFile.value()); setEnabled(!targetInformation.isBuiltin); }; @@ -106,18 +88,18 @@ GroupItem AppManagerRemoteInstallPackageStep::deployRecipe() { const TargetInformation targetInformation(target()); - const FilePath controller = executable.valueOrDefault(getToolFilePath(Constants::APPMAN_CONTROLLER, target()->kit(), targetInformation.device)); - const QString controllerArguments = arguments.valueOrDefault(ArgumentsDefault); - const QString packageFile = packageFileName.valueOrDefault(targetInformation.packageFile.fileName()); - auto device = DeviceKitAspect::device(target()->kit()); - bool remote = device && device->type() != ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE; - QDir packageDirectoryPath = remote ? QDir(Constants::REMOTE_DEFAULT_TMP_PATH) : targetInformation.packageFile.absolutePath(); - const FilePath packageDir = packageDirectory.valueOrDefault(packageDirectoryPath.absolutePath()); + const FilePath controllerPath = controller().isEmpty() ? + FilePath::fromString(controller.defaultValue()) : + controller(); + const QString controllerArguments = arguments(); + const FilePath packageFilePath = packageFile().isEmpty() ? + FilePath::fromString(packageFile.defaultValue()) : + packageFile(); const auto setupHandler = [=](Process &process) { - CommandLine remoteCmd(controller); + CommandLine remoteCmd(controllerPath); remoteCmd.addArgs(controllerArguments, CommandLine::Raw); - remoteCmd.addArg(packageDir.toString() + '/' + packageFile); + remoteCmd.addArg(packageFilePath.nativePath()); CommandLine cmd(deviceConfiguration()->filePath("/bin/sh")); cmd.addArg("-c"); diff --git a/src/plugins/qtapplicationmanager/appmanagerstringaspect.cpp b/src/plugins/qtapplicationmanager/appmanagerstringaspect.cpp index 5a4d26c332e..3a2ba607b35 100644 --- a/src/plugins/qtapplicationmanager/appmanagerstringaspect.cpp +++ b/src/plugins/qtapplicationmanager/appmanagerstringaspect.cpp @@ -22,7 +22,7 @@ AppManagerIdAspect::AppManagerIdAspect(Utils::AspectContainer *container) { setSettingsKey("ApplicationManagerPlugin.ApplicationId"); setDisplayStyle(StringAspect::LineEditDisplay); - setLabelText(Tr::tr("Application Id:")); + setLabelText(Tr::tr("Application id:")); // setReadOnly(true); } @@ -31,7 +31,18 @@ AppManagerInstanceIdAspect::AppManagerInstanceIdAspect(Utils::AspectContainer *c { setSettingsKey("ApplicationManagerPlugin.InstanceId"); setDisplayStyle(StringAspect::LineEditDisplay); - setLabelText(Tr::tr("AppMan Instance Id:")); + setLabelText(Tr::tr("AppMan instance id:")); + + makeCheckable(Utils::CheckBoxPlacement::Right, Tr::tr("Default Instance"), + "ApplicationManagerPlugin.InstanceIdDefault"); + setChecked(true); + + addDataExtractor(this, &AppManagerInstanceIdAspect::operator(), &Data::value); +} + +QString AppManagerInstanceIdAspect::operator()() const +{ + return !isChecked() ? value() : QString(); } AppManagerDocumentUrlAspect::AppManagerDocumentUrlAspect(Utils::AspectContainer *container) @@ -39,130 +50,25 @@ AppManagerDocumentUrlAspect::AppManagerDocumentUrlAspect(Utils::AspectContainer { setSettingsKey("ApplicationManagerPlugin.DocumentUrl"); setDisplayStyle(StringAspect::LineEditDisplay); - setLabelText(Tr::tr("Document Url:")); + setLabelText(Tr::tr("Document url:")); } AppManagerControllerAspect::AppManagerControllerAspect(Utils::AspectContainer *container) : FilePathAspect(container) { setSettingsKey("ApplicationManagerPlugin.AppControllerPath"); + setExpectedKind(Utils::PathChooser::ExistingCommand); setLabelText(Tr::tr("Controller:")); - setPlaceHolderText(Tr::tr("-")); } -AppManagerStringAspect::AppManagerStringAspect(AspectContainer *container) - : StringAspect(container) -{ -} - -QString AppManagerStringAspect::valueOrDefault(const QString &defaultValue) const -{ - return value().isEmpty() ? defaultValue : value(); -} - -// FilePath - -AppManagerFilePathAspect::AppManagerFilePathAspect(AspectContainer *container) +AppManagerPackagerAspect::AppManagerPackagerAspect(Utils::AspectContainer *container) : FilePathAspect(container) { + setSettingsKey("ApplicationManagerPlugin.AppPackagerPath"); + setExpectedKind(Utils::PathChooser::ExistingCommand); + setLabelText(Tr::tr("Packager:")); } -void AppManagerFilePathAspect::setButtonsVisible(bool visible) -{ - if (m_buttonsVisibile != visible) { - m_buttonsVisibile = visible; - updateWidgets(); - } -} - -void AppManagerFilePathAspect::setPlaceHolderPath(const QString &value) -{ - if (m_placeHolderPath != value) { - m_placeHolderPath = value; - updateWidgets(); - } -} - -void AppManagerFilePathAspect::setPromptDialogFilter(const QString &value) -{ - if (m_promptDialogFilter != value) { - m_promptDialogFilter = value; - updateWidgets(); - } -} - -void AppManagerFilePathAspect::addToLayout(Layouting::LayoutItem &parent) -{ - FilePathAspect::addToLayout(parent); - updateWidgets(); -} - -FilePath AppManagerFilePathAspect::valueOrDefault(const FilePath &defaultValue) const -{ - return operator()().isEmpty() ? defaultValue : operator()(); -} - -FilePath AppManagerFilePathAspect::valueOrDefault(const QString &defaultValue) const -{ - return operator()().isEmpty() ? FilePath::fromUserInput(defaultValue) : operator()(); -} - -static bool callValidationFunction(const FancyLineEdit::ValidationFunction &f, FancyLineEdit *lineEdit, QString *errorMessage) -{ - if (f.index() == 0) { - QString oldText = lineEdit->text(); - auto future = std::get<0>(f)(oldText); - future.waitForFinished(); - auto res = future.result(); - if (res) { - if (oldText != *res && lineEdit->text() == *res) - lineEdit->setText(*res); - return true; - } - - if (errorMessage) - *errorMessage = res.error(); - - return false; - } - return std::get<1>(f)(lineEdit, errorMessage); -} - -bool AppManagerFilePathAspect::validatePathWithPlaceHolder(FancyLineEdit *lineEdit, QString *errorMessage) const -{ - if (!lineEdit) - return false; - if (auto pathChooser = qobject_cast(lineEdit->parent())) { - if (lineEdit->text().isEmpty() && !lineEdit->placeholderText().isEmpty()) { - FancyLineEdit temporaryLineEdit; - temporaryLineEdit.setText(lineEdit->placeholderText()); - PathChooser temporaryPathChooser; - temporaryPathChooser.setExpectedKind(pathChooser->expectedKind()); - return callValidationFunction(temporaryPathChooser.defaultValidationFunction(), &temporaryLineEdit, errorMessage); - } - return callValidationFunction(pathChooser->defaultValidationFunction(), lineEdit, errorMessage); - } - return callValidationFunction(lineEdit->defaultValidationFunction(), lineEdit, errorMessage); -} - -void AppManagerFilePathAspect::updateWidgets() -{ - const auto pathChooser = this->pathChooser(); - if (!pathChooser) - return; - for (auto button : pathChooser->findChildren()) - button->setVisible(m_buttonsVisibile); - for (auto fancyLineEdit : pathChooser->findChildren()) - fancyLineEdit->setPlaceholderText(m_placeHolderPath); - QFileInfo initialBrowsePath(m_placeHolderPath); - while (!initialBrowsePath.path().isEmpty() && !initialBrowsePath.isDir()) - initialBrowsePath.setFile(initialBrowsePath.path()); - if (initialBrowsePath.isDir()) - pathChooser->setInitialBrowsePathBackup(FilePath::fromString(initialBrowsePath.absoluteFilePath())); - pathChooser->setPromptDialogFilter(m_promptDialogFilter); - pathChooser->setValidationFunction( - [&](FancyLineEdit *edit, QString *error) { return validatePathWithPlaceHolder(edit, error); }); -} } // namespace Internal } // namespace AppManager diff --git a/src/plugins/qtapplicationmanager/appmanagerstringaspect.h b/src/plugins/qtapplicationmanager/appmanagerstringaspect.h index a340b9fa724..dfd7fcbd1f5 100644 --- a/src/plugins/qtapplicationmanager/appmanagerstringaspect.h +++ b/src/plugins/qtapplicationmanager/appmanagerstringaspect.h @@ -28,7 +28,11 @@ class AppManagerInstanceIdAspect final : public Utils::StringAspect public: AppManagerInstanceIdAspect(Utils::AspectContainer *container = nullptr); - ~AppManagerInstanceIdAspect() final = default; + QString operator()() const; + + struct Data : StringAspect::Data { QString value; }; + + ~AppManagerInstanceIdAspect() override = default; }; class AppManagerDocumentUrlAspect final : public Utils::StringAspect @@ -51,35 +55,14 @@ public: ~AppManagerControllerAspect() final = default; }; -class AppManagerStringAspect : public Utils::StringAspect +class AppManagerPackagerAspect final : public Utils::FilePathAspect { + Q_OBJECT + public: - AppManagerStringAspect(Utils::AspectContainer *container); + AppManagerPackagerAspect(Utils::AspectContainer *container = nullptr); - QString valueOrDefault(const QString &defaultValue) const; -}; - -class AppManagerFilePathAspect : public Utils::FilePathAspect -{ -public: - AppManagerFilePathAspect(Utils::AspectContainer *container); - - void setButtonsVisible(bool visible); - void setPlaceHolderPath(const QString &value); - void setPromptDialogFilter(const QString &value); - - void addToLayout(Layouting::LayoutItem &parent) override; - - Utils::FilePath valueOrDefault(const Utils::FilePath &defaultValue) const; - Utils::FilePath valueOrDefault(const QString &defaultValue) const; - -private: - bool validatePathWithPlaceHolder(Utils::FancyLineEdit *lineEdit, QString *errorMessage) const; - void updateWidgets(); - - QString m_placeHolderPath; - QString m_promptDialogFilter; - bool m_buttonsVisibile = true; + ~AppManagerPackagerAspect() final = default; }; } // AppManager::Internal