Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VLMC
Manage
Activity
Members
Labels
Plan
Issues
26
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoLAN
VLMC
Commits
8a4f348c
Commit
8a4f348c
authored
8 years ago
by
luyikei
Committed by
Hugo Beauzée-Luyssen
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Have very basic Settings
Signed-off-by:
Hugo Beauzée-Luyssen
<
hugo@beauzee.fr
>
parent
d5ca0316
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Settings/Settings.cpp
+22
-34
22 additions, 34 deletions
src/Settings/Settings.cpp
src/Settings/Settings.h
+3
-3
3 additions, 3 deletions
src/Settings/Settings.h
with
25 additions
and
37 deletions
src/Settings/Settings.cpp
+
22
−
34
View file @
8a4f348c
...
...
@@ -33,7 +33,8 @@
#include
<QFileInfo>
#include
<QDir>
#include
<QDomElement>
#include
<QJsonDocument>
#include
<QJsonObject>
Settings
::
Settings
(
const
QString
&
settingsFile
)
...
...
@@ -68,53 +69,40 @@ Settings::setSettingsFile(const QString &settingsFile)
}
bool
Settings
::
save
(
Q
XmlStreamWriter
&
project
)
Settings
::
save
(
Q
JsonDocument
&
doc
)
{
QReadLocker
lock
(
&
m_rwLock
);
SettingMap
::
const_iterator
it
=
m_settings
.
begin
();
SettingMap
::
const_iterator
end
=
m_settings
.
end
();
project
.
writeStartElement
(
"settings"
)
;
QJsonObject
top
;
for
(
;
it
!=
end
;
++
it
)
{
if
(
(
(
*
it
)
->
flags
()
&
SettingValue
::
Runtime
)
!=
0
)
continue
;
project
.
writeStartElement
(
"setting"
);
project
.
writeAttribute
(
"key"
,
(
*
it
)
->
key
()
);
if
(
(
*
it
)
->
get
().
canConvert
<
QString
>
()
==
false
)
vlmcWarning
()
<<
"Can't serialize"
<<
(
*
it
)
->
key
();
project
.
writeAttribute
(
"value"
,
(
*
it
)
->
get
().
toString
()
);
project
.
writeEndElement
();
if
(
top
.
insert
(
(
*
it
)
->
key
(),
QJsonValue
::
fromVariant
(
(
*
it
)
->
get
()
)
)
==
top
.
end
()
)
vlmcWarning
()
<<
"Failed to set:"
<<
(
*
it
)
->
key
();
}
project
.
writeEndElement
(
);
doc
.
setObject
(
top
);
return
true
;
}
bool
Settings
::
load
(
const
Q
Dom
Document
&
doc
ument
)
Settings
::
load
(
const
Q
Json
Document
&
doc
)
{
QDomElement
element
=
document
.
firstChildElement
(
"settings"
);
if
(
element
.
isNull
()
==
true
)
if
(
doc
.
isNull
()
==
true
)
{
vlmcWarning
()
<<
"Invalid settings node"
;
return
false
;
}
QDomElement
s
=
element
.
firstChildElement
(
"setting"
);
while
(
s
.
isNull
()
==
false
)
for
(
auto
it
=
doc
.
object
().
constBegin
();
it
!=
doc
.
object
().
constEnd
();
++
it
)
{
QString
key
=
s
.
attribute
(
"key"
);
QString
value
=
s
.
attribute
(
"value"
);
if
(
key
.
isEmpty
()
==
true
)
vlmcWarning
()
<<
"Invalid setting node."
;
else
{
vlmcDebug
()
<<
"Loading"
<<
key
<<
"=>"
<<
value
;
if
(
setValue
(
key
,
value
)
==
false
)
vlmcWarning
()
<<
"Loaded invalid project setting:"
<<
key
;
}
s
=
s
.
nextSiblingElement
();
if
(
setValue
(
it
.
key
(),
(
*
it
).
toVariant
()
)
==
false
)
vlmcWarning
()
<<
"Loaded invalid project setting:"
<<
it
.
key
();
}
return
true
;
}
...
...
@@ -122,15 +110,17 @@ Settings::load( const QDomDocument& document )
bool
Settings
::
load
()
{
QDomDocument
doc
(
"root"
);
if
(
m_settingsFile
->
open
(
QFile
::
ReadOnly
)
==
false
)
{
vlmcWarning
()
<<
"Failed to open settings file"
<<
m_settingsFile
->
fileName
();
return
false
;
}
if
(
doc
.
setContent
(
m_settingsFile
)
==
false
)
QJsonParseError
error
;
QJsonDocument
doc
=
QJsonDocument
::
fromJson
(
m_settingsFile
->
readAll
(),
&
error
);
if
(
error
.
error
!=
QJsonParseError
::
NoError
)
{
vlmcWarning
()
<<
"Failed to load settings file"
<<
m_settingsFile
->
fileName
();
vlmcWarning
()
<<
error
.
errorString
();
return
false
;
}
bool
res
=
load
(
doc
);
...
...
@@ -143,12 +133,10 @@ Settings::save()
{
if
(
m_settingsFile
==
nullptr
)
return
false
;
QByteArray
settingsContent
;
QXmlStreamWriter
streamWriter
(
&
settingsContent
);
streamWriter
.
setAutoFormatting
(
true
);
save
(
streamWriter
);
QJsonDocument
doc
;
save
(
doc
);
m_settingsFile
->
open
(
QFile
::
WriteOnly
);
m_settingsFile
->
write
(
settingsContent
);
m_settingsFile
->
write
(
doc
.
toJson
(
QJsonDocument
::
Compact
)
);
m_settingsFile
->
close
();
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
src/Settings/Settings.h
+
3
−
3
View file @
8a4f348c
...
...
@@ -37,7 +37,7 @@
class
SettingValue
;
class
QFile
;
class
Q
DomEle
ment
;
class
Q
JsonDocu
ment
;
//Var helpers :
...
...
@@ -113,11 +113,11 @@ class Settings
SettingList
group
(
const
QString
&
groupName
)
const
;
bool
load
();
bool
save
();
bool
save
(
Q
XmlStreamWriter
&
project
);
bool
save
(
Q
JsonDocument
&
project
);
void
restoreDefaultValues
();
void
setSettingsFile
(
const
QString
&
settingsFile
);
bool
load
(
const
Q
Dom
Document
&
document
);
bool
load
(
const
Q
Json
Document
&
document
);
private:
SettingMap
m_settings
;
...
...
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