summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/component_p.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/installer/component_p.cpp')
-rw-r--r--src/libs/installer/component_p.cpp176
1 files changed, 32 insertions, 144 deletions
diff --git a/src/libs/installer/component_p.cpp b/src/libs/installer/component_p.cpp
index 162b62c54..ae4a149a5 100644
--- a/src/libs/installer/component_p.cpp
+++ b/src/libs/installer/component_p.cpp
@@ -59,17 +59,16 @@ namespace QInstaller {
// -- ComponentPrivate
ComponentPrivate::ComponentPrivate(PackageManagerCore *core, Component *qq)
- : q(qq),
- m_core(core),
- m_parentComponent(0),
- m_licenseOperation(0),
- m_minimumProgressOperation(0),
- m_newlyInstalled (false),
- m_operationsCreated(false),
- m_autoCreateOperations(true),
- m_operationsCreatedSuccessfully(true),
- m_updateIsAvailable(false),
- m_scriptEngine(0)
+ : q(qq)
+ , m_core(core)
+ , m_parentComponent(0)
+ , m_licenseOperation(0)
+ , m_minimumProgressOperation(0)
+ , m_newlyInstalled (false)
+ , m_operationsCreated(false)
+ , m_autoCreateOperations(true)
+ , m_operationsCreatedSuccessfully(true)
+ , m_updateIsAvailable(false)
{
}
@@ -88,111 +87,11 @@ ComponentPrivate::~ComponentPrivate()
delete widget.data();
}
-QScriptEngine *ComponentPrivate::scriptEngine()
+ScriptEngine *ComponentPrivate::scriptEngine() const
{
- if (m_scriptEngine != 0)
- return m_scriptEngine;
-
-
- m_scriptEngine = new QScriptEngine(q);
-
- // register translation stuff
- m_scriptEngine->installTranslatorFunctions();
-
- // register QMessageBox::StandardButton enum in the script connection
- registerMessageBox(m_scriptEngine);
-
- // register ::WizardPage enum in the script connection
- QScriptValue qinstaller = m_scriptEngine->newArray();
- setProperty(qinstaller, QLatin1String("Introduction"), PackageManagerCore::Introduction);
- setProperty(qinstaller, QLatin1String("LicenseCheck"), PackageManagerCore::LicenseCheck);
- setProperty(qinstaller, QLatin1String("TargetDirectory"), PackageManagerCore::TargetDirectory);
- setProperty(qinstaller, QLatin1String("ComponentSelection"), PackageManagerCore::ComponentSelection);
- setProperty(qinstaller, QLatin1String("StartMenuSelection"), PackageManagerCore::StartMenuSelection);
- setProperty(qinstaller, QLatin1String("ReadyForInstallation"), PackageManagerCore::ReadyForInstallation);
- setProperty(qinstaller, QLatin1String("PerformInstallation"), PackageManagerCore::PerformInstallation);
- setProperty(qinstaller, QLatin1String("InstallationFinished"), PackageManagerCore::InstallationFinished);
- setProperty(qinstaller, QLatin1String("End"), PackageManagerCore::End);
-
- // register ::Status enum in the script connection
- setProperty(qinstaller, QLatin1String("Success"), PackageManagerCore::Success);
- setProperty(qinstaller, QLatin1String("Failure"), PackageManagerCore::Failure);
- setProperty(qinstaller, QLatin1String("Running"), PackageManagerCore::Running);
- setProperty(qinstaller, QLatin1String("Canceled"), PackageManagerCore::Canceled);
-
- // maybe used by old scripts
- setProperty(qinstaller, QLatin1String("InstallerFailed"), PackageManagerCore::Failure);
- setProperty(qinstaller, QLatin1String("InstallerSucceeded"), PackageManagerCore::Success);
- setProperty(qinstaller, QLatin1String("InstallerUnfinished"), PackageManagerCore::Unfinished);
- setProperty(qinstaller, QLatin1String("InstallerCanceledByUser"), PackageManagerCore::Canceled);
-
- QScriptValue installerObject = m_scriptEngine->newQObject(m_core);
- installerObject.setProperty(QLatin1String("componentByName"), m_scriptEngine
- ->newFunction(qInstallerComponentByName, 1));
-
- m_scriptEngine->globalObject().setProperty(QLatin1String("QInstaller"), qinstaller);
- m_scriptEngine->globalObject().setProperty(QLatin1String("installer"), installerObject);
-
- // register QDesktopServices in the script connection
- m_scriptEngine->globalObject().setProperty(QLatin1String("QDesktopServices"), getDesktopServices());
- m_scriptEngine->globalObject().setProperty(QLatin1String("component"), m_scriptEngine->newQObject(q));
-
- QScriptValue fileDialog = m_scriptEngine->newArray();
- fileDialog.setProperty(QLatin1String("getExistingDirectory"),
- m_scriptEngine->newFunction(qFileDialogGetExistingDirectory));
- m_scriptEngine->globalObject().setProperty(QLatin1String("QFileDialog"), fileDialog);
-
- return m_scriptEngine;
+ return m_core->componentScriptEngine();
}
-void ComponentPrivate::setProperty(QScriptValue &scriptValue, const QString &propertyName, int value)
-{
- scriptValue.setProperty(propertyName, m_scriptEngine->newVariant(value));
-}
-
-// -- private
-
-QScriptValue ComponentPrivate::getDesktopServices()
-{
- QScriptValue desktopServices = m_scriptEngine->newArray();
-#if QT_VERSION < 0x050000
- setProperty(desktopServices, QLatin1String("DesktopLocation"), QDesktopServices::DesktopLocation);
- setProperty(desktopServices, QLatin1String("DesktopLocation"), QDesktopServices::DesktopLocation);
- setProperty(desktopServices, QLatin1String("DocumentsLocation"), QDesktopServices::DocumentsLocation);
- setProperty(desktopServices, QLatin1String("FontsLocation"), QDesktopServices::FontsLocation);
- setProperty(desktopServices, QLatin1String("ApplicationsLocation"), QDesktopServices::ApplicationsLocation);
- setProperty(desktopServices, QLatin1String("MusicLocation"), QDesktopServices::MusicLocation);
- setProperty(desktopServices, QLatin1String("MoviesLocation"), QDesktopServices::MoviesLocation);
- setProperty(desktopServices, QLatin1String("PicturesLocation"), QDesktopServices::PicturesLocation);
- setProperty(desktopServices, QLatin1String("TempLocation"), QDesktopServices::TempLocation);
- setProperty(desktopServices, QLatin1String("HomeLocation"), QDesktopServices::HomeLocation);
- setProperty(desktopServices, QLatin1String("DataLocation"), QDesktopServices::DataLocation);
- setProperty(desktopServices, QLatin1String("CacheLocation"), QDesktopServices::CacheLocation);
-#else
- setProperty(desktopServices, QLatin1String("DesktopLocation"), QStandardPaths::DesktopLocation);
- setProperty(desktopServices, QLatin1String("DesktopLocation"), QStandardPaths::DesktopLocation);
- setProperty(desktopServices, QLatin1String("DocumentsLocation"), QStandardPaths::DocumentsLocation);
- setProperty(desktopServices, QLatin1String("FontsLocation"), QStandardPaths::FontsLocation);
- setProperty(desktopServices, QLatin1String("ApplicationsLocation"), QStandardPaths::ApplicationsLocation);
- setProperty(desktopServices, QLatin1String("MusicLocation"), QStandardPaths::MusicLocation);
- setProperty(desktopServices, QLatin1String("MoviesLocation"), QStandardPaths::MoviesLocation);
- setProperty(desktopServices, QLatin1String("PicturesLocation"), QStandardPaths::PicturesLocation);
- setProperty(desktopServices, QLatin1String("TempLocation"), QStandardPaths::TempLocation);
- setProperty(desktopServices, QLatin1String("HomeLocation"), QStandardPaths::HomeLocation);
- setProperty(desktopServices, QLatin1String("DataLocation"), QStandardPaths::DataLocation);
- setProperty(desktopServices, QLatin1String("CacheLocation"), QStandardPaths::CacheLocation);
-#endif
-
- desktopServices.setProperty(QLatin1String("openUrl"),
- m_scriptEngine->newFunction(qDesktopServicesOpenUrl));
- desktopServices.setProperty(QLatin1String("displayName"),
- m_scriptEngine->newFunction(qDesktopServicesDisplayName));
- desktopServices.setProperty(QLatin1String("storageLocation"),
- m_scriptEngine->newFunction(qDesktopServicesStorageLocation));
- return desktopServices;
-}
-
-
// -- ComponentModelHelper
ComponentModelHelper::ComponentModelHelper()
@@ -202,8 +101,8 @@ ComponentModelHelper::ComponentModelHelper()
}
/*!
- Returns the number of child components. Depending if virtual components are visible or not the count might
- differ from what one will get if calling Component::childComponents(...).count().
+ Returns the number of child components. Depending if virtual components are visible or not,
+ the count might differ from what one will get if calling Component::childComponents(...).count().
*/
int ComponentModelHelper::childCount() const
{
@@ -213,49 +112,38 @@ int ComponentModelHelper::childCount() const
}
/*!
- Returns the index of this component as seen from it's parent.
+ Returns the component at index position in the list. Index must be a valid position in
+ the list (i.e., index >= 0 && index < childCount()). Otherwise it returns 0.
*/
-int ComponentModelHelper::indexInParent() const
+Component *ComponentModelHelper::childAt(int index) const
{
- int index = 0;
- if (Component *parent = m_componentPrivate->m_parentComponent->parentComponent())
- index = parent->childComponents(false, AllMode).indexOf(m_componentPrivate->m_parentComponent);
- return (index >= 0 ? index : 0);
+ if (index < 0 && index >= childCount())
+ return 0;
+
+ if (m_componentPrivate->m_core->virtualComponentsVisible())
+ return m_componentPrivate->m_allChildComponents.value(index, 0);
+ return m_componentPrivate->m_childComponents.value(index, 0);
}
/*!
- Returns all children and whose children depending if virtual components are visible or not.
+ Returns all descendants of this component depending if virtual components are visible or not.
*/
-QList<Component*> ComponentModelHelper::childs() const
+QList<Component*> ComponentModelHelper::childItems() const
{
QList<Component*> *components = &m_componentPrivate->m_childComponents;
if (m_componentPrivate->m_core->virtualComponentsVisible())
components = &m_componentPrivate->m_allChildComponents;
QList<Component*> result;
- foreach (Component *component, *components) {
+ foreach (Component *const component, *components) {
result.append(component);
- result += component->childs();
+ result += component->childItems();
}
return result;
}
/*!
- Returns the component at index position in the list. Index must be a valid position in
- the list (i.e., index >= 0 && index < childCount()). Otherwise it returns 0.
-*/
-Component *ComponentModelHelper::childAt(int index) const
-{
- if (index >= 0 && index < childCount()) {
- if (m_componentPrivate->m_core->virtualComponentsVisible())
- return m_componentPrivate->m_allChildComponents.value(index, 0);
- return m_componentPrivate->m_childComponents.value(index, 0);
- }
- return 0;
-}
-
-/*!
- Determines if the components installations status can be changed. The default value is true.
+ Determines if the installation status of the component can be changed. The default value is true.
*/
bool ComponentModelHelper::isEnabled() const
{
@@ -263,7 +151,7 @@ bool ComponentModelHelper::isEnabled() const
}
/*!
- Enables oder disables ability to change the components installations status.
+ Enables or disables the ability to change the installation status of the components.
*/
void ComponentModelHelper::setEnabled(bool enabled)
{
@@ -271,7 +159,7 @@ void ComponentModelHelper::setEnabled(bool enabled)
}
/*!
- Returns whether the component is tristate; that is, if it's checkable with three separate states.
+ Returns whether the component is tri-state; that is, if it's checkable with three separate states.
The default value is false.
*/
bool ComponentModelHelper::isTristate() const
@@ -280,10 +168,10 @@ bool ComponentModelHelper::isTristate() const
}
/*!
- Sets whether the component is tristate. If tristate is true, the component is checkable with three
+ Sets whether the component is tri-state. If tri-state is true, the component is checkable with three
separate states; otherwise, the component is checkable with two states.
- (Note that this also requires that the component is checkable; see isCheckable().)
+ Note: this also requires that the component is checkable. \sa isCheckable()
*/
void ComponentModelHelper::setTristate(bool tristate)
{