Access MediaDescriptor properties in loaded document

Hello all,

I have the below sub assigned to a button on a switchboard .odt document for my database. When clicked, it opens a document called “AddTransaction.odt”, which contains some forms.

Sub OpenAddTransDoc_

Globalscope.BasicLibraries.LoadLibrary( "MRILib" )

REM Define properties for MediaDescriptor service
Dim DocProperties(2) As New
DocProperties(0).Name = "ReadOnly"
DocProperties(0).Value = True
DocProperties(1).Name = "Referer"
DocProperties(1).Value = ThisComponent.URL
DocProperties(2).Name = "MacroExecutionMode"
DocProperties(2).Value = 4

Dim DocURL As String
DocURL = ConvertToURL("F:\Mattias Durnez\Documents HDD\Business\Finances_database\frontend\forms\AddTransaction.odt")

ThisDoc = StarDesktop.loadComponentFromURL(DocURL,"_default",0,DocProperties)

End Sub

After opening the “AddTransaction.odt” document, I inspect its model using MRI. When I retrieve the .Args property of the model with getArgs() I can see the values that I set for MacroExecutionMode (4) and ReadOnly (True). However, I can’t see the URL that I specified for the Referer property. I failed to locate the Referer URL even after manually stepping through all properties/methods using MRI.

My question is: how can I access the Referer property, if even possible at all?

Also, when I add the following additional property …

DocProperties(3).Name = "DocumentTitle"
DocProperties(3).Value = "NewTestTitle"

… it appears correctly in .Args as “DocumentTitle” with value “NewTestTitle” BUT the actual title displayed in the loaded document has NOT changed. In fact, .Args contains another property called “Title” which contains the title displayed by the document. This seems odd behaviour or am I missing something?

Many thanks for any help/insights!

I always like to look into things I don’t understand and this is one I hadn’t looked at before, so take this with a grain of salt.

I found little on the subject anywhere. Service Reference and some sparse info in OOME (pdf here) on page 314 (document page 317). I also added the following code to yours after ThisDoc... and just before the MRI inspection:

	On Error Resume Next
Dim vArgs 	'Media descriptor as an array of'
Dim s$		'Display string'
Dim i%		'Index variable'
REM Obtain the media descriptor. It turns out that this
REM can be represented as an array of PropertyValue services.
vArgs = ThisComponent.getArgs()
For i = 0 To UBound(vArgs)			'For each property'
	s = s & vArgs(i).Name & " = "		'Add the property name and an equals sign'
	s = s & vArgs(i).Value				'Obtaining the value may fail!'
	s = s & CHR$(10)					'Add a new-line character'
MsgBox s,0, "Args"

Code is from OOME book. Display 1:

image description

Notice DocumentTitle. Although my code specified “NewTestTitle”, “Form1” was the actual sending document AND when args was viewed in MRI it showed “NewTestTitle”. Other items like “ReadOnly” set to “False” didn’t do anything.

Based on the limited information available the most important item was from the noted OOME:

If you know how to open a document using the GUI, but are uncertain how the arguments must be set to
load the document using loadComponentFromURL, then first load the document using the GUI, then
inspect the document’s media descriptor. Hint: look at FilterOptions.

From what I can see, arguments sent are only what is necessary to open the document. There seem to be a select few as optional (such as “ReadOnly” and “MacroExecutionMode”) but I haven’t tried them all.

This doesn’t answer all your questions (nor mine) but hopefully a bit more understanding and maybe direction.

Thanks for your reply! I actually have the same code from OOME in my sub, but left it out to keep the question simple. FYI: you displayed the Args from the sending document with your code, because you referred to ThisComponent. To display the Args from the loaded document, you should replace it with ThisDoc. That’s why setting the “DocumentTitle” or “ReadOnly” didn’t ‘seem’ to do anything for you. Here is the output from my code: (didn’t set readonly).

@Durre Thanks, I missed that. However upon changing, if “ReadOnly” is set to “True” it appears, “False” does not. And still can’t figure “Referer” - nothing there no matter the entry. I’ll continue as time permits, may even try the source code at some point.

@Ratslinger Yes indeed, to me it feels like inconsistent behaviour. I can’t for the life of me figure out why “Referer” does not appear in the list and how/why “DocumentTitle” is any different from “Title”. You talk about trying the source code. Do you know where to find it/how to access it? All I’ve found so far is mediadescriptor.cxx but that wasn’t too helpful. I can’t seem to find anything with regards to the implementation of loadcomponentfromurl().

@Durre Downloaded & compiled using method found here. Be aware you can spend the better part of a day completing a first compiled version but it drastically improves after that. For an IDE I’m using KDevelop. Using Eclipse for other things. Until last year, hadn’t used C++ for 15 years so still rusty at it.

@Ratslinger Thanks a lot for the help, I appreciate it :slight_smile:

@Durre Just as I was about to go to the source, I discover this link from the LO MediaDescriptor page:click here. Of particular note is the second paragraph: If a media descriptor is used, only a few of the members are specified. The others assume default values. Strings default to empty strings in general and interface references default to empty references. For all other properties..... !

@Durre Found code on-line so you don’t have to download. See the following: MediaDescriptor & the Cross Reference but I see you already have the last one.