Re: [Libreoffice] Storage of user's configuration

2012-01-31 Thread Martin Richard
Thank you for following up this thread, it worked !

Martin

2012/1/31 Stephan Bergmann sberg...@redhat.com

 On 01/24/2012 09:38 PM, Stephan Bergmann wrote:

 One thing that's already there, though, is that if you can indeed go
 with a single string-list property (lets assume you add it as
 org.openoffice.Office.Common/**Misc/FilePickerBookmarks), you can

 #include officecfg/Office/Common.hxx

 and read the list (as a com::sun::star::uno::Sequence**rtl::OUString)
 with

 officecfg::Office::Common::**Misc::FilePickerBookmarks::**get(context)


 Martin, for this to keep working please add a nillable=false attribute
 to your new property in Common.xcs, see http://cgit.freedesktop.org/**
 libreoffice/core/commit/?id=**e8bb827571f540ac4af2247cb11239**bb96876669http://cgit.freedesktop.org/libreoffice/core/commit/?id=e8bb827571f540ac4af2247cb11239bb96876669
 Fixed cppheader.xsl nillable treatment.  (In addition to adding an empty
 default value/ so that the get() above does not throw an exception upon a
 void Any, as discussed on IRC the other day.)


 Stephan
 __**_
 LibreOffice mailing list
 LibreOffice@lists.freedesktop.**org LibreOffice@lists.freedesktop.org
 http://lists.freedesktop.org/**mailman/listinfo/libreofficehttp://lists.freedesktop.org/mailman/listinfo/libreoffice




-- 
Martin http://www.martiusweb.net Richard
www.martiusweb.net http://www.martiuweb.net
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] Storage of user's configuration

2012-01-30 Thread Stephan Bergmann

On 01/24/2012 09:38 PM, Stephan Bergmann wrote:

One thing that's already there, though, is that if you can indeed go
with a single string-list property (lets assume you add it as
org.openoffice.Office.Common/Misc/FilePickerBookmarks), you can

#include officecfg/Office/Common.hxx

and read the list (as a com::sun::star::uno::Sequencertl::OUString) with

officecfg::Office::Common::Misc::FilePickerBookmarks::get(context)


Martin, for this to keep working please add a nillable=false attribute 
to your new property in Common.xcs, see 
http://cgit.freedesktop.org/libreoffice/core/commit/?id=e8bb827571f540ac4af2247cb11239bb96876669 
Fixed cppheader.xsl nillable treatment.  (In addition to adding an 
empty default value/ so that the get() above does not throw an 
exception upon a void Any, as discussed on IRC the other day.)


Stephan
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


[Libreoffice] Storage of user's configuration

2012-01-24 Thread Martin Richard
Hi everybody,

I'm hacking the cross-platform filepicker (in fpicker/source/office). I
added a Places (bookmarks) list on the left and I would like to save the
entries that the user bookmarked .

Cedric Bosdonnat told me to look at xcu and xcs files, but I'm a bit lost.
I'm looking for a code sample where user's persistent configuration is
manipulated (read and written) and/or anything that can be usefull, like
search keywords, links to old threads in the mailing list, which would help
me to identify some good practices (naming conventions, for instance).

Cheers,
Martin Richard
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] Storage of user's configuration

2012-01-24 Thread Fernand Vanrie

Martin ,

i use folowed BASIC code to make a path consitent , maybe  it helps ?

public sElementnaam , sfotopath as string
public oParameter as object

sub addFotoPath()
sRegisterPath = /org.openoffice.OpmaakMacro.FotoPath/Parameters/
CreateRegistrySchemaPathIfNotPresent(sRegisterPath)
aSettings = GetConfigSettings(sRegisterPath)
sElementNaam = FOTO
sParaNaam = FotoPath
sParameter = c:\test

call addParameter(aSettings, sParaNaam, sParaMeter)

end sub
sub getFotoPath
sRegisterPath = /org.openoffice.OpmaakMacro.FotoPath/Parameters/
aSettings = GetConfigSettings(sRegisterPath)
asElNames = aSettings.ElementNames
if aSettings.hasByName(FOTO) then
oParameter = aSettings.getByName(FOTO)

   sFOTOpath = oParameter.getByName(ParameterString)
   else
   sFOTOpath = 
   endif
end sub


function GetConfigSettings(sRegisterPath as String) as Object 'Taken 
from DannyB

Dim args(1) As new com.sun.star.beans.PropertyValue
aConfProv = 
createUnoService(com.sun.star.configuration.ConfigurationProvider)

args(1).Name = nodepath
args(1).Value = sRegisterPath
args(0).Name = EnableAsync
args(0).Value = false
GetConfigSettings = 
aConfProv.createInstanceWithArguments(com.sun.star.configuration.ConfigurationUpdateAccess, 
args())

end function

sub CreateRegistrySchemaPathIfNotPresent(sRegisterPath as String)
oPathSettings = CreateUnoService( com.sun.star.util.PathSettings )
xray oPathSettings
sPathConfig = oPathSettings.Work 'Config

asPath1 = split(sRegisterPath, /)
sFullDotPath = asPath1(1)
asPath2 = Split(sFullDotPath,.)
sFolder = join(asPath2,/)


sRegistrySchemaPath = file:///H:/  sFolder  .xcs

sFileName = asPath2(UBound(asPath2))
sPackage = left(sFullDotPath, len(sFullDotPath)-len(sFileName)-1)

oSFA = createUNOService (com.sun.star.ucb.SimpleFileAccess)
if not oSFA.exists(sRegistrySchemaPath) then 'See the chapter 15 of the 
dev guide for some explanation

print sRegistrySchemaPath
  oOutStream = oSFA.openFileWrite(sRegistrySchemaPath)
  oOutText = createUNOService (com.sun.star.io.TextOutputStream)
  oOutText.setOutputStream(oOutStream)

  oOutText.WriteString(?xml version='1.0' encoding='UTF-8'?  Chr(10))

  oOutText.WriteString(oor:component-schema oor:name=  sFileName 
  oor:package=  sPackage)
  oOutText.WriteString(xml:lang=en-US 
xmlns:oor=http://openoffice.org/2001/registry;  )

  oOutText.WriteString(xmlns:xs=http://www.w3.org/2001/XMLSchema;  )
  
oOutText.WriteString(xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; 
 Chr(10))


  oOutText.WriteString(templates  Chr(10))
  oOutText.WriteString( group oor:name=Parameter  Chr(10))
  oOutText.WriteString( prop oor:name=ParameterName 
oor:type=xs:string/  Chr(10))
  oOutText.WriteString( prop oor:name=ParameterString 
oor:type=xs:string/  Chr(10))

  oOutText.WriteString( /group  Chr(10))
  oOutText.WriteString(/templates  Chr(10))

  oOutText.WriteString(component  Chr(10))
  oOutText.WriteString( set oor:name=Parameters 
oor:node-type=Parameter/  Chr(10))

  oOutText.WriteString(/component  Chr(10))

  oOutText.WriteString(/oor:component-schema  Chr(10))

  oOutText.closeOutput()
  oOutStream.closeOutput
  endif

end sub

sub addParameter(aSettings as Object, ParameterName as String, 
ParameterString as String)


  Dim arParameters1(0) As new com.sun.star.beans.PropertyValue
  arParameters1(0).Name = ParameterName
  arParameters1(0).Value = ParameterString
  call setParameters(aSettings, arParameters1(0))

end sub

function getParameterCount(aSettings as Object) as long
getParameterCount = UBound(aSettings.ElementNames)+1
end function



sub setParameters(aSettings as Object, aNewValue as Object)
  if aSettings.hasbyName(sElementnaam) then
'print aNewvalue.name
   oParameter = aSettings.createInstance()
  oParameter.ParameterName = aNewValue.Name
  oParameter.ParameterString = aNewValue.Value

  aSettings.ReplaceByName(sElementNaam , oParameter)

  aSettings.commitChanges()
  else
   oParameter =  aSettings.createInstance()
  oParameter.ParameterName = aNewValue.Name
  oParameter.ParameterString = aNewValue.Value

  aSettings.insertByName(sElementNaam , oParameter)
   aSettings.commitChanges()
   endif

end sub

Hi everybody,

I'm hacking the cross-platform filepicker (in fpicker/source/office). 
I added a Places (bookmarks) list on the left and I would like to 
save the entries that the user bookmarked .


Cedric Bosdonnat told me to look at xcu and xcs files, but I'm a bit 
lost. I'm looking for a code sample where user's persistent 
configuration is manipulated (read and written) and/or anything that 
can be usefull, like search keywords, links to old threads in the 
mailing list, which would help me to identify some good practices 
(naming conventions, for instance).


Cheers,
Martin Richard


___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice



___
LibreOffice mailing 

Re: [Libreoffice] Storage of user's configuration

2012-01-24 Thread Martin Richard
Hi Fernand,

Thank you for your response, it may help indeed.

It seems that you create your own xcs file from scratch and store it in a
custom location. I think that in my case, I will need to find a way to make
it cross platform and environment independent.

Cheers

2012/1/24 Fernand Vanrie s...@pmgroup.be

  Martin ,

 i use folowed BASIC code to make a path consitent , maybe  it helps ?

 public sElementnaam , sfotopath as string
 public oParameter as object

 sub addFotoPath()
 sRegisterPath = /org.openoffice.OpmaakMacro.FotoPath/Parameters/
 CreateRegistrySchemaPathIfNotPresent(sRegisterPath)
 aSettings = GetConfigSettings(sRegisterPath)
 sElementNaam = FOTO
 sParaNaam = FotoPath
 sParameter = c:\test

 call addParameter(aSettings, sParaNaam, sParaMeter)

 end sub
 sub getFotoPath
 sRegisterPath = /org.openoffice.OpmaakMacro.FotoPath/Parameters/
 aSettings = GetConfigSettings(sRegisterPath)
 asElNames = aSettings.ElementNames
 if aSettings.hasByName(FOTO) then
 oParameter = aSettings.getByName(FOTO)

sFOTOpath = oParameter.getByName(ParameterString)
else
sFOTOpath = 
endif
 end sub


 function GetConfigSettings(sRegisterPath as String) as Object 'Taken from
 DannyB
 Dim args(1) As new com.sun.star.beans.PropertyValue
 aConfProv =
 createUnoService(com.sun.star.configuration.ConfigurationProvider)
 args(1).Name = nodepath
 args(1).Value = sRegisterPath
 args(0).Name = EnableAsync
 args(0).Value = false
 GetConfigSettings =
 aConfProv.createInstanceWithArguments(com.sun.star.configuration.ConfigurationUpdateAccess,
 args())
 end function

 sub CreateRegistrySchemaPathIfNotPresent(sRegisterPath as String)
 oPathSettings = CreateUnoService( com.sun.star.util.PathSettings )
 xray oPathSettings
 sPathConfig = oPathSettings.Work 'Config

 asPath1 = split(sRegisterPath, /)
 sFullDotPath = asPath1(1)
 asPath2 = Split(sFullDotPath,.)
 sFolder = join(asPath2,/)


 sRegistrySchemaPath = file:///H:/  sFolder  .xcs

 sFileName = asPath2(UBound(asPath2))
 sPackage = left(sFullDotPath, len(sFullDotPath)-len(sFileName)-1)

 oSFA = createUNOService (com.sun.star.ucb.SimpleFileAccess)
 if not oSFA.exists(sRegistrySchemaPath) then 'See the chapter 15 of the
 dev guide for some explanation
 print sRegistrySchemaPath
   oOutStream = oSFA.openFileWrite(sRegistrySchemaPath)
   oOutText = createUNOService (com.sun.star.io.TextOutputStream)
   oOutText.setOutputStream(oOutStream)

   oOutText.WriteString(?xml version='1.0' encoding='UTF-8'?  Chr(10))

   oOutText.WriteString(oor:component-schema oor:name=  sFileName 
  oor:package=  sPackage)
   oOutText.WriteString(xml:lang=en-US xmlns:oor=
 http://openoffice.org/2001/registry;http://openoffice.org/2001/registry
  )
   
 oOutText.WriteString(xmlns:xs=http://www.w3.org/2001/XMLSchema;http://www.w3.org/2001/XMLSchema
  )
   oOutText.WriteString(xmlns:xsi=
 http://www.w3.org/2001/XMLSchema-instance;http://www.w3.org/2001/XMLSchema-instance
  Chr(10))

   oOutText.WriteString(templates  Chr(10))
   oOutText.WriteString(  group oor:name=Parameter  Chr(10))
   oOutText.WriteString(prop oor:name=ParameterName
 oor:type=xs:string/  Chr(10))
   oOutText.WriteString(prop oor:name=ParameterString
 oor:type=xs:string/  Chr(10))
   oOutText.WriteString(  /group  Chr(10))
   oOutText.WriteString(/templates  Chr(10))

   oOutText.WriteString(component  Chr(10))
   oOutText.WriteString(  set oor:name=Parameters
 oor:node-type=Parameter/  Chr(10))
   oOutText.WriteString(/component  Chr(10))

   oOutText.WriteString(/oor:component-schema  Chr(10))

   oOutText.closeOutput()
   oOutStream.closeOutput
   endif

 end sub

 sub addParameter(aSettings as Object, ParameterName as String,
 ParameterString as String)

   Dim arParameters1(0) As new com.sun.star.beans.PropertyValue
   arParameters1(0).Name = ParameterName
   arParameters1(0).Value = ParameterString
   call setParameters(aSettings, arParameters1(0))

 end sub

 function getParameterCount(aSettings as Object) as long
 getParameterCount = UBound(aSettings.ElementNames)+1
 end function



 sub setParameters(aSettings as Object, aNewValue as Object)
   if aSettings.hasbyName(sElementnaam) then
 'print aNewvalue.name
oParameter = aSettings.createInstance()
   oParameter.ParameterName = aNewValue.Name
   oParameter.ParameterString = aNewValue.Value

   aSettings.ReplaceByName(sElementNaam , oParameter)

   aSettings.commitChanges()
   else
oParameter =  aSettings.createInstance()
   oParameter.ParameterName = aNewValue.Name
   oParameter.ParameterString = aNewValue.Value

   aSettings.insertByName(sElementNaam , oParameter)
aSettings.commitChanges()
endif

 end sub

 Hi everybody,


 I'm hacking the cross-platform filepicker (in fpicker/source/office). I
 added a Places (bookmarks) list on the left and I would like to save the
 entries that the user bookmarked .

 Cedric Bosdonnat told me to look at xcu and xcs files, but I'm a bit lost.
 I'm looking for a code sample where 

Re: [Libreoffice] Storage of user's configuration

2012-01-24 Thread Michael Meeks
Hi Martin,

On Tue, 2012-01-24 at 16:22 +0100, Martin Richard wrote:
 I'm hacking the cross-platform filepicker (in fpicker/source/office).
 I added a Places (bookmarks) list on the left and I would like to
 save the entries that the user bookmarked .

Great.

 Cedric Bosdonnat told me to look at xcu and xcs files, but I'm a bit
 lost. I'm looking for a code sample where user's persistent
 configuration is manipulated (read and written) and/or anything that
 can be usefull, like search keywords, links to old threads in the
 mailing list, which would help me to identify some good practices
 (naming conventions, for instance).

Naming conventions is a suck  see :-) look for something that seems
related, and put it next to it.

The schemas (XML description of settings and their defaults) live in
officecfg/

If you do:

git grep -3 ExperimentalMode

you should get a manageable set of hits for a single config setting. I
don't think you'll easily be able to use the nice new syntax that
Stephan created:

if (officecfg::Office::Common::Misc::ExperimentalMode::get( 
comphelper::getProcessComponentContext() ))

style - since you want a list of items: which is (I'm afraid) harder to
do, you'll most likely have to use a twistier UNO API to access the
configmgr/ implementation, and may have more fun with the schemas :-)

Hope that helps,

Michael.

-- 
michael.me...@suse.com  , Pseudo Engineer, itinerant idiot

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] Storage of user's configuration

2012-01-24 Thread Fernand Vanrie

Martin,

I supose it is already cross platform and environment independent, neve 
tested it but interesting to know.




Hi Fernand,

Thank you for your response, it may help indeed.

It seems that you create your own xcs file from scratch and store it 
in a custom location. I think that in my case, I will need to find a 
way to make it cross platform and environment independent.


Cheers

2012/1/24 Fernand Vanrie s...@pmgroup.be mailto:s...@pmgroup.be

Martin ,

i use folowed BASIC code to make a path consitent , maybe  it
helps ?

public sElementnaam , sfotopath as string
public oParameter as object

sub addFotoPath()
sRegisterPath = /org.openoffice.OpmaakMacro.FotoPath/Parameters/
CreateRegistrySchemaPathIfNotPresent(sRegisterPath)
aSettings = GetConfigSettings(sRegisterPath)
sElementNaam = FOTO
sParaNaam = FotoPath
sParameter = c:\test

call addParameter(aSettings, sParaNaam, sParaMeter)

end sub
sub getFotoPath
sRegisterPath =
/org.openoffice.OpmaakMacro.FotoPath/Parameters/
aSettings = GetConfigSettings(sRegisterPath)
asElNames = aSettings.ElementNames
if aSettings.hasByName(FOTO) then
oParameter = aSettings.getByName(FOTO)

   sFOTOpath = oParameter.getByName(ParameterString)
   else
   sFOTOpath = 
   endif
end sub


function GetConfigSettings(sRegisterPath as String) as Object
'Taken from DannyB
Dim args(1) As new com.sun.star.beans.PropertyValue
aConfProv =
createUnoService(com.sun.star.configuration.ConfigurationProvider)
args(1).Name = nodepath
args(1).Value = sRegisterPath
args(0).Name = EnableAsync
args(0).Value = false
GetConfigSettings =

aConfProv.createInstanceWithArguments(com.sun.star.configuration.ConfigurationUpdateAccess,
args())
end function

sub CreateRegistrySchemaPathIfNotPresent(sRegisterPath as String)
oPathSettings = CreateUnoService( com.sun.star.util.PathSettings )
xray oPathSettings
sPathConfig = oPathSettings.Work 'Config

asPath1 = split(sRegisterPath, /)
sFullDotPath = asPath1(1)
asPath2 = Split(sFullDotPath,.)
sFolder = join(asPath2,/)


sRegistrySchemaPath = file:///H:/  sFolder  .xcs

sFileName = asPath2(UBound(asPath2))
sPackage = left(sFullDotPath, len(sFullDotPath)-len(sFileName)-1)

oSFA = createUNOService (com.sun.star.ucb.SimpleFileAccess)
if not oSFA.exists(sRegistrySchemaPath) then 'See the chapter 15
of the dev guide for some explanation
print sRegistrySchemaPath
  oOutStream = oSFA.openFileWrite(sRegistrySchemaPath)
  oOutText = createUNOService (com.sun.star.io.TextOutputStream)
  oOutText.setOutputStream(oOutStream)

  oOutText.WriteString(?xml version='1.0' encoding='UTF-8'? 
Chr(10))

  oOutText.WriteString(oor:component-schema oor:name= 
sFileName   oor:package=  sPackage)
  oOutText.WriteString(xml:lang=en-US
xmlns:oor=http://openoffice.org/2001/registry;
http://openoffice.org/2001/registry  )
 
oOutText.WriteString(xmlns:xs=http://www.w3.org/2001/XMLSchema;

http://www.w3.org/2001/XMLSchema  )
 
oOutText.WriteString(xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;

http://www.w3.org/2001/XMLSchema-instance  Chr(10))

  oOutText.WriteString(templates  Chr(10))
  oOutText.WriteString( group oor:name=Parameter  Chr(10))
  oOutText.WriteString( prop oor:name=ParameterName
oor:type=xs:string/  Chr(10))
  oOutText.WriteString( prop oor:name=ParameterString
oor:type=xs:string/  Chr(10))
  oOutText.WriteString( /group  Chr(10))
  oOutText.WriteString(/templates  Chr(10))

  oOutText.WriteString(component  Chr(10))
  oOutText.WriteString( set oor:name=Parameters
oor:node-type=Parameter/  Chr(10))
  oOutText.WriteString(/component  Chr(10))

  oOutText.WriteString(/oor:component-schema  Chr(10))

  oOutText.closeOutput()
  oOutStream.closeOutput
  endif

end sub

sub addParameter(aSettings as Object, ParameterName as String,
ParameterString as String)

  Dim arParameters1(0) As new com.sun.star.beans.PropertyValue
  arParameters1(0).Name = ParameterName
  arParameters1(0).Value = ParameterString
  call setParameters(aSettings, arParameters1(0))

end sub

function getParameterCount(aSettings as Object) as long
getParameterCount = UBound(aSettings.ElementNames)+1
end function



sub setParameters(aSettings as Object, aNewValue as Object)
  if aSettings.hasbyName(sElementnaam) then
'print aNewvalue.name
   oParameter = aSettings.createInstance()
  oParameter.ParameterName = aNewValue.Name
  oParameter.ParameterString = aNewValue.Value

  aSettings.ReplaceByName(sElementNaam , oParameter)

  aSettings.commitChanges()
  else
   oParameter =  aSettings.createInstance()
  oParameter.ParameterName = aNewValue.Name
  

Re: [Libreoffice] Storage of user's configuration

2012-01-24 Thread Stephan Bergmann

On 01/24/2012 04:22 PM, Martin Richard wrote:

I'm hacking the cross-platform filepicker (in fpicker/source/office). I
added a Places (bookmarks) list on the left and I would like to save
the entries that the user bookmarked .

Cedric Bosdonnat told me to look at xcu and xcs files, but I'm a bit
lost. I'm looking for a code sample where user's persistent
configuration is manipulated (read and written) and/or anything that can
be usefull, like search keywords, links to old threads in the mailing
list, which would help me to identify some good practices (naming
conventions, for instance).


The configuration data is stored into a hierarchy of groups (think 
structs) and typed properties, plus homogeneous sets (where a set is 
somewhat like an array with members of one kind of group, but the order 
is not defined and the members have arbitrary names rather than 
numerical indices).  The static structure of that hierarchy is at 
officecfg/registry/data/ and the actual initial data at 
officecfg/registry/schema/.


For file paths, there is already something looking over-engineered at 
org.openoffice.Office.Paths, but if all you need is an (ordered?) list 
of bookmarks (just URIs?) that does not grow unbounded, you might get 
away with a single property of type oor:string-list. 
org.openoffice.Office.Common is a kind of catch-all file for various 
configuration settings that do not fit any of the other, more 
specialized ones.  Maybe you find a fitting group node there, or add a 
new one.


Accessing the configuration at runtime to read/write the data is 
something of a disaster.  The configuration is UNO based, but tries to 
re-use each and every of the existing UNO interfaces, so that getting an 
idea of how it actually works is rather difficult.  Plus, various people 
thought it a good idea to add various wrappers on top of it, adding even 
more confusion.  I'm trying to clean up that mess over time, but it is 
no easy feat.


One thing that's already there, though, is that if you can indeed go 
with a single string-list property (lets assume you add it as 
org.openoffice.Office.Common/Misc/FilePickerBookmarks), you can


  #include officecfg/Office/Common.hxx

and read the list (as a com::sun::star::uno::Sequencertl::OUString) with

  officecfg::Office::Common::Misc::FilePickerBookmarks::get(context)

where context is the UNO component context (use 
comphelper::getProcessComponentContext() for now if you have none 
around).  Writing is always done in batch mode:


  unotools::ConfigurationChanges batch(
unotools::ConfigurationChanges::create(context));
  officecfg::Office::Common::Misc::FilePickerBookmarks::set(
context, batch, value);
  batch.commit();

svl/source/config/asiancfg.cxx is one of the few examples that are 
already converted to this new, simplified approach.


Don't hesitate to come back with any further questions (I'm sberg on IRC).

Stephan
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice