Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Calamares
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osak
Calamares
Commits
3bef0b83
Commit
3bef0b83
authored
Aug 25, 2014
by
Teo Mrnjavac
Browse files
Options
Downloads
Patches
Plain Diff
Check for mains power in prepare viewmodule.
parent
26419f2c
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/modules/prepare/PrepareViewStep.cpp
+59
-3
59 additions, 3 deletions
src/modules/prepare/PrepareViewStep.cpp
src/modules/prepare/PrepareViewStep.h
+1
-0
1 addition, 0 deletions
src/modules/prepare/PrepareViewStep.h
with
60 additions
and
3 deletions
src/modules/prepare/PrepareViewStep.cpp
+
59
−
3
View file @
3bef0b83
...
@@ -28,6 +28,8 @@
...
@@ -28,6 +28,8 @@
#include
<QBoxLayout>
#include
<QBoxLayout>
#include
<QDBusConnection>
#include
<QDBusConnection>
#include
<QDBusInterface>
#include
<QDBusInterface>
#include
<QDir>
#include
<QFileInfo>
#include
<QLabel>
#include
<QLabel>
#include
<QProcess>
#include
<QProcess>
...
@@ -231,22 +233,76 @@ PrepareViewStep::checkEnoughRam( qint64 requiredRam )
...
@@ -231,22 +233,76 @@ PrepareViewStep::checkEnoughRam( qint64 requiredRam )
bool
bool
PrepareViewStep
::
check
HasPower
()
PrepareViewStep
::
check
BatteryExists
()
{
{
const
QFileInfo
basePath
(
"/sys/class/power_supply"
);
if
(
!
(
basePath
.
exists
()
&&
basePath
.
isDir
()
)
)
return
false
;
QDir
baseDir
(
basePath
.
absoluteFilePath
()
);
foreach
(
auto
item
,
baseDir
.
entryList
(
QDir
::
AllDirs
|
QDir
::
Readable
|
QDir
::
NoDotAndDotDot
)
)
{
QFileInfo
typePath
(
baseDir
.
absoluteFilePath
(
QString
(
"%1/type"
)
.
arg
(
item
)
)
);
QFile
typeFile
(
typePath
.
absoluteFilePath
()
);
if
(
typeFile
.
open
(
QIODevice
::
ReadOnly
|
QIODevice
::
Text
)
)
{
if
(
typeFile
.
readAll
().
startsWith
(
"Battery"
)
)
return
true
;
}
}
return
false
;
return
false
;
}
}
bool
PrepareViewStep
::
checkHasPower
()
{
const
QString
UPOWER_SVC_NAME
(
"org.freedesktop.UPower"
);
const
QString
UPOWER_INTF_NAME
(
"org.freedesktop.UPower"
);
const
QString
UPOWER_PATH
(
"/org/freedesktop/UPower"
);
if
(
!
checkBatteryExists
()
)
return
true
;
cDebug
()
<<
"A battery exists, checking for mains power."
;
QDBusInterface
upowerIntf
(
UPOWER_SVC_NAME
,
UPOWER_PATH
,
UPOWER_INTF_NAME
,
QDBusConnection
::
systemBus
(),
0
);
bool
onBattery
=
upowerIntf
.
property
(
"OnBattery"
).
toBool
();
if
(
!
upowerIntf
.
isValid
()
)
{
// We can't talk to upower but we're obviously up and running
// so I guess we got that going for us, which is nice...
return
true
;
}
// If a battery exists but we're not using it, means we got mains
// power.
return
!
onBattery
;
}
bool
bool
PrepareViewStep
::
checkHasInternet
()
PrepareViewStep
::
checkHasInternet
()
{
{
const
QString
NM_SVC_NAME
(
"org.freedesktop.NetworkManager"
);
const
QString
NM_INTF_NAME
(
"org.freedesktop.NetworkManager"
);
const
QString
NM_INTF_NAME
(
"org.freedesktop.NetworkManager"
);
const
QString
NM_PATH
(
"/org/freedesktop/NetworkManager"
);
const
int
NM_STATE_CONNECTED_GLOBAL
=
70
;
const
int
NM_STATE_CONNECTED_GLOBAL
=
70
;
QDBusInterface
nmIntf
(
"org.freedesktop.NetworkManager"
,
QDBusInterface
nmIntf
(
NM_SVC_NAME
,
"/org/freedesktop/NetworkManager"
,
NM_PATH
,
NM_INTF_NAME
,
NM_INTF_NAME
,
QDBusConnection
::
systemBus
(),
0
);
QDBusConnection
::
systemBus
(),
0
);
bool
ok
=
false
;
bool
ok
=
false
;
int
nmState
=
nmIntf
.
property
(
"state"
).
toInt
(
&
ok
);
int
nmState
=
nmIntf
.
property
(
"state"
).
toInt
(
&
ok
);
...
...
This diff is collapsed.
Click to expand it.
src/modules/prepare/PrepareViewStep.h
+
1
−
0
View file @
3bef0b83
...
@@ -58,6 +58,7 @@ public:
...
@@ -58,6 +58,7 @@ public:
private:
private:
bool
checkEnoughStorage
(
qint64
requiredSpace
);
bool
checkEnoughStorage
(
qint64
requiredSpace
);
bool
checkEnoughRam
(
qint64
requiredRam
);
bool
checkEnoughRam
(
qint64
requiredRam
);
bool
checkBatteryExists
();
bool
checkHasPower
();
bool
checkHasPower
();
bool
checkHasInternet
();
bool
checkHasInternet
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment