You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@openoffice.apache.org by "Steele, Raymond" <ra...@lmco.com> on 2013/05/06 22:14:17 UTC

RE: EXTERNAL: Re: soffice process still running

Ariel, 

 I am having a case were the process continues to run. I appears the the EnumerationAccess does have elements, causing the desktop not to terminate. Is there a way to terminate a specific desktop that was not last open, and not close other desktops?

Raymond

-----Original Message-----
From: Steele, Raymond 
Sent: Monday, February 04, 2013 1:45 PM
To: 'api@openoffice.apache.org'
Subject: RE: EXTERNAL: Re: soffice process still running

Ariel, 

I am not sure I understand why the following causes only the last opened document to close, but it seems to be the solution.

if (!xEnumerationAccess.hasElements()) {
    xDesktop.terminate();

Thanks!

Raymond

-----Original Message-----
From: Ariel Constenla-Haile [mailto:arielch@apache.org]
Sent: Friday, February 01, 2013 5:24 AM
To: api@openoffice.apache.org
Subject: Re: EXTERNAL: Re: soffice process still running

On Thu, Jan 31, 2013 at 05:48:11PM +0000, Steele, Raymond wrote:
> Thanks for the feedback. 
> 
> I implemented the following, but the method kills off any other 
> instance of soffice that is running.
> 
> Desktop_obj
> =
> component_factory.createInstanceWithContext("com.sun.star.frame.Deskto
> p", context); XDesktop desktop =
> UnoRuntime.queryInterface(XDesktop.class,
> desktop_obj); desktop.terminate();
> 
> Any way that I can close the instance without killing off other 
> soffice instances?

What do you mean by "instance"? There is only one instance of soffice.bin per application using the same user installation directory.

If you mean that it closes all other documents, then you can check if this document is the last opened document, and if true, terminate the
desktop:
http://www.openoffice.org/api/docs/common/ref/com/sun/star/frame/XDesktop.html#getComponents

XComponentLoader xComponentLoader = UnoRuntime.queryInterface(
    XComponentLoader.class,
    xContext.getServiceManager().createInstanceWithContext(
        "com.sun.star.frame.Desktop", xContext)); XTextDocument xTextDocument = UnoRuntime.queryInterface(
     XTextDocument.class,
     xComponentLoader.loadComponentFromURL(
        "private:factory/swriter",
        "_default",
        FrameSearchFlag.ALL,
        new PropertyValue[]{}));
xTextDocument.getText().setString("Dummy text.");

XCloseable xCloseable = UnoRuntime.queryInterface(
    XCloseable.class, xTextDocument);
xCloseable.close(true);

XDesktop xDesktop = UnoRuntime.queryInterface(
    XDesktop.class, xComponentLoader);
XEnumerationAccess xEnumerationAccess = xDesktop.getComponents();

if (!xEnumerationAccess.hasElements()) {
    xDesktop.terminate();
}


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org


Re: EXTERNAL: Re: soffice process still running

Posted by jg <we...@jgoettgens.de>.
You can dispose the component in question 
(http://www.openoffice.org/api/docs/common/ref/com/sun/star/lang/XComponent.html).

jg

---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org


RE: EXTERNAL: Re: soffice process still running

Posted by "Steele, Raymond" <ra...@lmco.com>.
Thanks for the recommendation and insight.

Raymond

-----Original Message-----
From: Ariel Constenla-Haile [mailto:arielch@apache.org] 
Sent: Tuesday, May 07, 2013 10:16 AM
To: api@openoffice.apache.org
Subject: Re: EXTERNAL: Re: soffice process still running

Hi Raymond,

On Tue, May 07, 2013 at 04:25:57PM +0000, Steele, Raymond wrote:
> Ariel,
> 
> Thank you for the quick response.   I have narrowed the continued
> process down to a component.  However, the behavior is strange because 
> I am not really opening the component in my code. My code opens a 
> document using XComponentLoader::loadComponentFromURL(). I set the
> "Hidden" property to true so the user cannot see it.   The document
> that is open contains Dynamic Data Exchange (DDE) links to another 
> closed document. The code then uses XRefreshable interface to refresh 
> all the DDE links found in XIndexAccess.  Lastly, I export the 
> document using the "ODF Spreadsheet" / "calc8" filter name using 
> XStore::storeToURL(). For some reason, this whole process opens
> (hidden) the other document to which the document I am refreshing 
> contains DDE links to, even though I do not explicitly open it.
> Strange. 

It sounds logical that if you are refreshing the links, the application opens documents that are linked; what sounds like a bug is that the linked document isn't closed after the document containing the link is closed. This might be worth a bug report.

> In my original query, I did not want to close documents that were not 
> opened by my application. (i.e. the user opens it by clicking on the
> OpenOffice desktop icon).   My solution to this point for this issue
> is: if XEnumeration does have more elements, I create an enumeration 
> from XEnumerationAccess, loop through it,  get the XComponent 
> interface and XModel for each element, and XClose::close() the 
> component if the XModel::getURL() matches a specific URL to the 
> implicitly opened document. Lastly, if the enumeration does not have 
> any more elements, I terminate the desktop. All of this prevents my 
> application from inadvertently closing any documents that were not 
> opened by my application.
> 
> Do you have any insight to this behavior or recommendations?

May be you can asume that hidden documents were not opened by the user, and close them:

if the enumeration has elements
    if all remaining documents are hidden
        close the all

You can know if a document was loaded with Hidden set to true in the media descriptor by looping through css.frame.XModel.getArgs()

REM  *****  BASIC  *****
Option Explicit

Sub Main
    Dim aArgs(0) as new com.sun.star.beans.PropertyValue
    aArgs(0).Name = "Hidden"
    aArgs(0).Value = TRUE

    Dim oDoc as Object
    oDoc = StarDesktop.loadComponentFromURL(_
        "private:factory/swriter",_
        "_default",_
        com.sun.star.frame.FrameSearchFlag.ALL,_
        aArgs)
    
    Dim aLoadArgs()
    aLoadArgs = oDoc.getArgs()
    Dim aPropVal
    Dim bHidden as Boolean
    bHidden = FALSE
    For Each aPropVal In aLoadArgs
        If aPropVal.Name = "Hidden" Then
            bHidden = aPropVal.Value
            Exit For
        End If
    Next
    If bHidden Then
        oDoc.close(TRUE)
    End If
End Sub


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org


Re: EXTERNAL: Re: soffice process still running

Posted by Ariel Constenla-Haile <ar...@apache.org>.
Hi Raymond,

On Tue, May 07, 2013 at 04:25:57PM +0000, Steele, Raymond wrote:
> Ariel, 
> 
> Thank you for the quick response.   I have narrowed the continued
> process down to a component.  However, the behavior is strange because
> I am not really opening the component in my code. My code opens
> a document using XComponentLoader::loadComponentFromURL(). I set the
> "Hidden" property to true so the user cannot see it.   The document
> that is open contains Dynamic Data Exchange (DDE) links to another
> closed document. The code then uses XRefreshable interface to refresh
> all the DDE links found in XIndexAccess.  Lastly, I export the
> document using the "ODF Spreadsheet" / "calc8" filter name using
> XStore::storeToURL(). For some reason, this whole process opens
> (hidden) the other document to which the document I am refreshing
> contains DDE links to, even though I do not explicitly open it.
> Strange. 

It sounds logical that if you are refreshing the links, the application
opens documents that are linked; what sounds like a bug is that the
linked document isn't closed after the document containing the link is
closed. This might be worth a bug report.

> In my original query, I did not want to close documents that were not
> opened by my application. (i.e. the user opens it by clicking on the
> OpenOffice desktop icon).   My solution to this point for this issue
> is: if XEnumeration does have more elements, I create an enumeration
> from XEnumerationAccess, loop through it,  get the XComponent
> interface and XModel for each element, and XClose::close() the
> component if the XModel::getURL() matches a specific URL to the
> implicitly opened document. Lastly, if the enumeration does not have
> any more elements, I terminate the desktop. All of this prevents my
> application from inadvertently closing any documents that were not
> opened by my application.  
> 
> Do you have any insight to this behavior or recommendations?

May be you can asume that hidden documents were not opened by the user,
and close them:

if the enumeration has elements
    if all remaining documents are hidden
        close the all

You can know if a document was loaded with Hidden set to true in the
media descriptor by looping through css.frame.XModel.getArgs()

REM  *****  BASIC  *****
Option Explicit

Sub Main
    Dim aArgs(0) as new com.sun.star.beans.PropertyValue
    aArgs(0).Name = "Hidden"
    aArgs(0).Value = TRUE

    Dim oDoc as Object
    oDoc = StarDesktop.loadComponentFromURL(_
        "private:factory/swriter",_
        "_default",_
        com.sun.star.frame.FrameSearchFlag.ALL,_
        aArgs)
    
    Dim aLoadArgs()
    aLoadArgs = oDoc.getArgs()
    Dim aPropVal
    Dim bHidden as Boolean
    bHidden = FALSE
    For Each aPropVal In aLoadArgs
        If aPropVal.Name = "Hidden" Then
            bHidden = aPropVal.Value
            Exit For
        End If
    Next
    If bHidden Then
        oDoc.close(TRUE)
    End If
End Sub


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina

RE: EXTERNAL: Re: soffice process still running

Posted by "Steele, Raymond" <ra...@lmco.com>.
Ariel, 

Thank you for the quick response.   I have narrowed the continued process down to a component.  However, the behavior is strange because I am not really opening the component in my code. My code opens a document using XComponentLoader::loadComponentFromURL(). I set the "Hidden" property to true so the user cannot see it.   The document that is open contains Dynamic Data Exchange (DDE) links to another closed document. The code then uses XRefreshable interface to refresh all the DDE links found in XIndexAccess.  Lastly, I export the document using the "ODF Spreadsheet" / "calc8" filter name using XStore::storeToURL(). For some reason, this whole process opens (hidden) the other document to which the document I am refreshing contains DDE links to, even though I do not explicitly open it. Strange. 

In my original query, I did not want to close documents that were not opened by my application. (i.e. the user opens it by clicking on the OpenOffice desktop icon).   My solution to this point for this issue is: if XEnumeration does have more elements, I create an enumeration from XEnumerationAccess, loop through it,  get the XComponent interface and XModel for each element, and XClose::close() the component if the XModel::getURL() matches a specific URL to the implicitly opened document. Lastly, if the enumeration does not have any more elements, I terminate the desktop. All of this prevents my application from inadvertently closing any documents that were not opened by my application.  

Do you have any insight to this behavior or recommendations?

Thanks Again!

Raymond

-----Original Message-----
From: Ariel Constenla-Haile [mailto:arielch@apache.org] 
Sent: Monday, May 06, 2013 5:17 PM
To: api@openoffice.apache.org
Subject: Re: EXTERNAL: Re: soffice process still running

Hi Raymond,

On Mon, May 06, 2013 at 08:14:17PM +0000, Steele, Raymond wrote:
> Ariel,
> 
>  I am having a case were the process continues to run. I appears the  
> the EnumerationAccess does have elements, causing the desktop not to  
> terminate. Is there a way to terminate a specific desktop that was  
> not last open, and not close other desktops?

Do you know what component is still alive? If I recall clearly, you didn't want to close all other documents in the first time, but simply terminate the office when all documents have been closed.

This enumeration contains all components that where opened using the application framework, if this component is keeping the desktop alive, you have to close/dispose it. But then, you face your original problem:
you don't want to close documents that are still open. So, first, investigate which is the component that is keeping the office alive:

> if (!xEnumerationAccess.hasElements()) {
>     xDesktop.terminate();

Replace this with an if ... else ...
If the enumeration has elements, iterate over them, see if they support css.lang.XServiceInfo, and print information about the component; this may get you some hint about that last component.


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org


Re: EXTERNAL: Re: soffice process still running

Posted by Ariel Constenla-Haile <ar...@apache.org>.
Hi Raymond,

On Mon, May 06, 2013 at 08:14:17PM +0000, Steele, Raymond wrote:
> Ariel, 
> 
>  I am having a case were the process continues to run. I appears the
>  the EnumerationAccess does have elements, causing the desktop not to
>  terminate. Is there a way to terminate a specific desktop that was
>  not last open, and not close other desktops?

Do you know what component is still alive? If I recall clearly, you
didn't want to close all other documents in the first time, but simply
terminate the office when all documents have been closed.

This enumeration contains all components that where opened using the
application framework, if this component is keeping the desktop alive,
you have to close/dispose it. But then, you face your original problem:
you don't want to close documents that are still open. So, first,
investigate which is the component that is keeping the office alive:

> if (!xEnumerationAccess.hasElements()) {
>     xDesktop.terminate();

Replace this with an if ... else ...
If the enumeration has elements, iterate over them, see if they support
css.lang.XServiceInfo, and print information about the component; this
may get you some hint about that last component.


Regards
-- 
Ariel Constenla-Haile
La Plata, Argentina