OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Invoking documentcompare (Diff-Viewer) via UNO/C++

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
oopit
General User
General User


Joined: 22 Mar 2005
Posts: 7

PostPosted: Sun Jun 12, 2005 3:16 am    Post subject: Invoking documentcompare (Diff-Viewer) via UNO/C++ Reply with quote

Hi,

I have the code below to invoke a view of the differences of two documents
via UNO. This code works, but onlz about 60% of the time.
Often, only the First Document is opened and the second is not loaded an the compare function is not invoked. When i don't use that strange CompareEventListener(),
the success rate is down to somwthing like 40%.

Anyone has a sound solution/idea to fix that issue?

Thanks,

/ pit

Code:


class CompareEventListener : public cppu::WeakImplHelper1<com::sun::star::document::XEventListener>
{
public:
  CompareEventListener()
  {
  }

  virtual ~CompareEventListener()
  {
  }

  void notifyEvent(const com::sun::star::document::EventObject &evt)
    throw (com::sun::star::uno::RuntimeException)
  {
    EE("CompareEventListener:notifyEvent: %s\n", OU2Ascii(evt.EventName));
  }

  void disposing(const com::sun::star::lang::EventObject& evt)
    throw (com::sun::star::uno::RuntimeException)
  {
    EE("CompareEventListener:disposing\n");
  }
};


// function snippet that actually invokes comparison functionality:
    Reference<XDesktop> desk(m_servicefactory->createInstance(Ascii2OU("com.sun.star.frame.Desktop")), UNO_QUERY);
    Reference<XComponentLoader> loader(desk, UNO_QUERY);

    // load first document
    Sequence<PropertyValue> loadproperties(3);
    loadproperties[0].Name = Ascii2OU("Hidden");
    loadproperties[0].Value <<= sal_False;
    loadproperties[1].Name = Ascii2OU("Silent");
    loadproperties[1].Value <<= sal_True;
    loadproperties[2].Name = Ascii2OU("ReadOnly"); // neccessary!
    loadproperties[2].Value <<= sal_False;

    Reference<XComponent> comp = loader->loadComponentFromURL(Ascii2OU(doc1url), Ascii2OU("_blank"), 0, loadproperties);

    // event listener
    Reference<com::sun::star::document::XEventBroadcaster> xeb(comp, UNO_QUERY);
    xeb->addEventListener(static_cast<com::sun::star::document::XEventListener *>(new CompareEventListener));

    // prepare call
    Sequence<PropertyValue> compprops(2);
    compprops[0].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("URL"));
    compprops[0].Value <<= Ascii2OU(doc2url);
    compprops[1].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("CompareDocuments"));
    compprops[1].Value <<= sal_True;

    // dispatch call
    Reference<XDispatchHelper> disphlp(m_servicefactory->createInstance(
                  Ascii2OU("com.sun.star.frame.DispatchHelper")), UNO_QUERY);
    Reference<XDispatchProvider> currentframe(desk->getCurrentFrame(), UNO_QUERY);

    disphlp->executeDispatch(currentframe,
                             Ascii2OU(".uno:CompareDocuments"),
                             Ascii2OU(""), 0, compprops);




Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Mon Jun 13, 2005 8:39 am    Post subject: Reply with quote

I am not familiar with dispatcher commands. I don't see where do you load the second document.
Are you sure "uno:comparedocuments" load the document ? If yes I don't know where this dispatch command knows it has to use the first loaded document to do comparison ?
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
oopit
General User
General User


Joined: 22 Mar 2005
Posts: 7

PostPosted: Wed Jun 15, 2005 5:27 am    Post subject: Reply with quote

the 2. document is loaded after

// prepare call

-----
compprops[0].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("URL"));
compprops[0].Value <<= Ascii2OU(doc2url);
-----

where doc2url is something like file:///path/to/file.sxw

As stated, it works, but not always, which is the strange thing i want fixed.
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Wed Jun 15, 2005 10:38 am    Post subject: Reply with quote

I can beter explain what i want to say with the shematic above. Your program is like :
Code:

   +--------+
   | loader |
   +--------+
        |
 loadComponentFromURL
        |
        V
   +--------+
   |  comp  |
   +--------+
        |
      UNO_QUERY
        |
        V
    +-------+
    | xeb   |
    +-------+
        |
 addEventListener
        |
        V

With your program only comp know where is the first document you first load. And it will be never used again. Then I don't see the link between both documents to compare. How is your program knowing the first document ? Perhaps it works only when it is the default document ! Or perhaps you don't give us the entire code ?
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
oopit
General User
General User


Joined: 22 Mar 2005
Posts: 7

PostPosted: Thu Jun 23, 2005 2:04 am    Post subject: Reply with quote

that event listener think is just pure specualtion, it could be the cause of the problem,
because i thought the dispatch won't succeed if the 1st document is not loaded fully.

but the issue seems more random, somehow.

functionality basically is, that the first document is simply loaded with
'loadComponentFromURL' then the ".uno:CompareDocuments" with a parameter containing the 2nd document is dispatched against the current frame.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group