Bug 77574 - koshell sets the wrong URL (the temporary converted file!!) for imported documents
Summary: koshell sets the wrong URL (the temporary converted file!!) for imported docu...
Status: RESOLVED FIXED
Alias: None
Product: koshell
Classification: Unmaintained
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Sven Lueppken
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-14 14:15 UTC by Raphael Langerhorst
Modified: 2004-03-25 20:48 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
this patch sets the correct URL for the document after loading the temporary converted file (1.23 KB, patch)
2004-03-14 15:24 UTC, Raphael Langerhorst
Details
koshell_correct_URL_version2_kodocument.patch (1.24 KB, text/x-diff)
2004-03-25 20:28 UTC, Raphael Langerhorst
Details
koshell_correct_URL_version2_koshell.patch (1.39 KB, text/x-diff)
2004-03-25 20:28 UTC, Raphael Langerhorst
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Raphael Langerhorst 2004-03-14 14:15:31 UTC
Version:           1.3post (using KDE 3.2.0, compiled sources)
Compiler:          gcc version 3.2.3
OS:          Linux (i686) release 2.6.0

If one works in koshell and opens a non-native document, then koshell first converts it using the KoFilterManager and saves the converted file in a temporary file (somewhere under "/tmp/...". THEN a new document is generated and asked to load the temporary file (which is now in a native format). This obviously results in a wrong URL for the document - as seen in the caption of the main window.

Only tested with KWord. Don't know if that occurs with other components.

Also, if you don't use koshell the problem does not exist, so it's obviously a bug of koshell.

Strangely this doesn't happen with all files(?). Importing an rtf worked fine all the time while importing any .sxw file resulted in the described bug.

I have fixed the problem and will attach a patch after posting the bug. The patch is tested - again only with koshell/kword, but it shouldn't do any harm.
Comment 1 Raphael Langerhorst 2004-03-14 15:24:05 UTC
Created attachment 5217 [details]
this patch sets the correct URL for the document after loading the temporary converted file

The patch applies to $KOFFICE_SRC/koshell/koshell_shell.cc

At the end of the open method a check for a temporary file is made which
indicates a conversion from a non-native format. In this case we set the URL
and file (the same??) for the document to the original file and correct the
mimetype to the non-native type.

I also tried to make KOffice show a warning when saving because it's in
non-native type but these two calls don't seem to have any effekt - someone
with more knowledge might have a look at it. So CURRENTLY THE USER IS NOT
WARNED when (s)he again saves the document in the non-native format!! Apart
from that the patch is tested and solves the observed bug(s) (that is, the
settings correction of the imported document).

Regards,
Raphael
Comment 2 David Faure 2004-03-15 19:30:31 UTC
The code in KoMainWindow changed indeed - did you compare with the code there?
The duplication is unfortunate (but hard to avoid), but basically both should behave the same... (I just wonder if the answer to the FIXME:... is there).
Hmm, adding Clarence do the CC, who is responsible for the koMainWindow changes.
Comment 3 Clarence Dang 2004-03-16 09:06:10 UTC
On Tue, 16 Mar 2004 05:30 am, David Faure wrote:
> ------- Additional Comments From faure kde org  2004-03-15 19:30 -------
> The code in KoMainWindow changed indeed - did you compare with the code
> there? The duplication is unfortunate (but hard to avoid), but basically
> both should behave the same... (I just wonder if the answer to the
> FIXME:... is there). Hmm, adding Clarence do the CC, who is responsible for
> the koMainWindow changes.
Sorry about the bug.  I'll try to reproduce and fix on the weekend when I'm 
not completely busy.

Clarence

Comment 4 Clarence Dang 2004-03-20 10:16:13 UTC
Ok, I've had a look into it:

This bug has been uncovered due to another bug:

The line "m_documentEntry = KoDocumentEntry::queryByMimeType( mimeType->name().latin1() )" in KoShellWindow::openDocumentInternal() complains:

koffice (lib kofficecore): WARNING: Got no results with [X-KDE-NativeMimeType] == 'application/vnd.sun.xml.writer'
koffice (lib kofficecore): ERROR: Found no KOffice part able to handle application/vnd.sun.xml.writer!
koffice (lib kofficecore): ERROR: Check your installation (does the desktop file have X-KDE-NativeMimeType and KOfficePart, did you install KOffice in a different prefix than KDE, without adding the prefix to /etc/kderc ?)

which forces m_documentEntry to be empty.  This should be fixed first?  Something wrong with the oowriter mimetype, I guess.

The comment "// non-native" in the code is misleading because e.g. if you open an mswrite file, it gives a documentEntry which is not empty.


Your patch looks right but you need to change KoDocument's mimeType, not just outputMimeType (press File/Save As after opening to see what I mean).

Hmm, looks like remote documents don't work at all (not caused by your patch though).

The setConfirmNonNativeSave() calls are correct and seem to work for me.  Are you sure you didn't click that DontAskAgain?
Comment 5 Raphael Langerhorst 2004-03-20 13:14:16 UTC
On Saturday 20 March 2004 10:16, Clarence Dang wrote:
> Ok, I've had a look into it:

thanks!!

>
> This bug has been uncovered due to another bug:
>
> The line "m_documentEntry = KoDocumentEntry::queryByMimeType(
> mimeType->name().latin1() )" in KoShellWindow::openDocumentInternal()
> complains:
>
> koffice (lib kofficecore): WARNING: Got no results with
> [X-KDE-NativeMimeType] == 'application/vnd.sun.xml.writer' koffice (lib
> kofficecore): ERROR: Found no KOffice part able to handle
> application/vnd.sun.xml.writer! koffice (lib kofficecore): ERROR: Check
> your installation (does the desktop file have X-KDE-NativeMimeType and
> KOfficePart, did you install KOffice in a different prefix than KDE,
> without adding the prefix to /etc/kderc ?)
>
> which forces m_documentEntry to be empty.  This should be fixed first? 
> Something wrong with the oowriter mimetype, I guess.

I'm not familiar with this, but it surely needs to be fixed one way or the 
other.

>
> The comment "// non-native" in the code is misleading because e.g. if you
> open an mswrite file, it gives a documentEntry which is not empty.

what do you propose?

>
>
> Your patch looks right but you need to change KoDocument's mimeType, not
> just outputMimeType (press File/Save As after opening to see what I mean).

I had a quick look at the classes... how "can" the mimetype of an open 
document be changed? For me it works - the saving works correctly into the 
original mime type of the file.

>
> Hmm, looks like remote documents don't work at all (not caused by your
> patch though).
>
> The setConfirmNonNativeSave() calls are correct and seem to work for me. 
> Are you sure you didn't click that DontAskAgain?

You're right, just manually checked the koshellrc file. Updated and tested 
again. It works :-)

concluding: still open stuff (todos):
* fix mime type settings for oowriter (external bug)
* change document's mime type (should be fixed in this bug hunting)
* fix remote files (external bug)
* provide a better comment (see above, should also be fixed in this bug 
hunting)

PS: thanks for having a look, apart from providing some answers I can't do 
much more (mostly a "not enough time" problem), the bug - IMHO - is 
(partially) fixed and has no regressions (AFAIK), so it could be used. If you 
know for a better comment ("non-native") then please go ahead, I'm no expert 
and would appreciate every help.

Regards,
Raphael

Comment 6 Clarence Dang 2004-03-22 10:53:43 UTC
On Sat, 20 Mar 2004 11:14 pm, Raphael Langerhorst wrote:
> > This bug has been uncovered due to another bug:
> >
> > The line "m_documentEntry = KoDocumentEntry::queryByMimeType(
> > mimeType->name().latin1() )" in KoShellWindow::openDocumentInternal()
> > complains:
> >
> > koffice (lib kofficecore): WARNING: Got no results with
> > [X-KDE-NativeMimeType] == 'application/vnd.sun.xml.writer' koffice (lib
> > kofficecore): ERROR: Found no KOffice part able to handle
> > application/vnd.sun.xml.writer! koffice (lib kofficecore): ERROR: Check
> > your installation (does the desktop file have X-KDE-NativeMimeType and
> > KOfficePart, did you install KOffice in a different prefix than KDE,
> > without adding the prefix to /etc/kderc ?)
> >
> > which forces m_documentEntry to be empty.  This should be fixed first?
> > Something wrong with the oowriter mimetype, I guess.
>
> I'm not familiar with this, but it surely needs to be fixed one way or the
> other.
>
> > The comment "// non-native" in the code is misleading because e.g. if you
> > open an mswrite file, it gives a documentEntry which is not empty.
>
> what do you propose?
>

   ^
   |
   |
dfaure :)

> > Your patch looks right but you need to change KoDocument's mimeType, not
> > just outputMimeType (press File/Save As after opening to see what I
> > mean).
>
> I had a quick look at the classes... how "can" the mimetype of an open
> document be changed? 
By adding a setMimeType() method to KoDocument to go with the setFile() hack 
:)  Actually, the setFile() hack won't be needed once KOffice requires KDE 
3.3 but that's another matter.

> For me it works - the saving works correctly into the
> original mime type of the file.
Look at the default output format when you click File / Save As.  File / Save 
is ok though.

> * fix remote files (external bug)
I'll look at this one on the weekend unless someone else beats me to it :)

Clarence

Comment 7 Raphael Langerhorst 2004-03-25 20:28:47 UTC
On Monday 22 March 2004 10:53, Clarence Dang wrote:
>  [...]

ok, attached are my final versions for the problem. I modified KoDocument to 
have a setMimeType member to allow setting the mime type during loading in 
koshell. (Now the correct mime type is selected by default when choosing 
"save as")

All works, no (experienced) regressions, problem solved, please review and 
apply.

Also note: since I changed the KoDocument class this breaks binary 
compatibility(!!)

Regards,
Raphael


Created an attachment (id=5393)
koshell_correct_URL_version2_kodocument.patch

Created an attachment (id=5394)
koshell_correct_URL_version2_koshell.patch
Comment 8 David Faure 2004-03-25 20:37:25 UTC
On Thursday 25 March 2004 20:28, Raphael Langerhorst wrote:
> All works, no (experienced) regressions, problem solved, please review and 
> apply.

Great, thanks much.

> Also note: since I changed the KoDocument class this breaks binary 
> compatibility(!!)
Not at all, a new non-virtual method keeps BC. The change is fine.

I'll apply to head and branch.

Comment 9 David Faure 2004-03-25 20:48:18 UTC
CVS commit by faure: 

Applying patch by Raphael Langerhorst to fix
[Bug 77574] koshell sets the wrong URL (the temporary converted file!!) for imported documents

CCMAIL: 77574-done@bugs.kde.org


  M +24 -0     koshell/koshell_shell.cc   1.72.2.1
  M +3 -0      lib/CHANGES   1.17.2.15
  M +5 -0      lib/kofficecore/koDocument.cc   1.287.2.7
  M +7 -0      lib/kofficecore/koDocument.h   1.147.2.2


--- koffice/koshell/koshell_shell.cc  #1.72:1.72.2.1
@@ -190,4 +190,28 @@ bool KoShellWindow::openDocumentInternal
 
   if ( tmpFile ) {
+    //if the laoded file has been a temporary file
+    //we need to correct a few document settings
+    //see description of bug #77574 for additional information
+  
+    //correct (output) mime type: we need to set it to the non-native format
+    //to make sure the user knows about saving to a non-native mime type
+    //setConfirmNonNativeSave is set to true below
+    newdoc->setMimeType( mimeType->name().latin1() );
+    newdoc->setOutputMimeType( mimeType->name().latin1() );
+    
+    //the next time the user saves the document he should be warned
+    //because of mime type settings done above;
+    newdoc->setConfirmNonNativeSave(true,true); //exporting,warn_on
+    newdoc->setConfirmNonNativeSave(false,true); //save/save as,warn_on
+    
+    //correct document file (should point to URL)
+    newdoc->setFile( url.path() );
+    
+    //correct document URL
+    newdoc->setURL( url );
+    
+    //update caption to represent the correct URL in the window titlebar
+    updateCaption();
+  
     tmpFile->unlink();
     delete tmpFile;

--- koffice/lib/CHANGES  #1.17.2.14:1.17.2.15
@@ -36,4 +36,7 @@
 - Fixed infinite loop on invalid WMF file
 
+KoShell:
+- Fixed problems (wrong URL etc.) after importing non-native documents (#77574)
+
 Changes after KOffice-1.3-rc1
 =============================

--- koffice/lib/kofficecore/koDocument.cc  #1.287.2.6:1.287.2.7
@@ -462,4 +462,9 @@ QCString KoDocument::mimeType() const
 }
 
+void KoDocument::setMimeType( const QCString & mimeType )
+{
+    d->mimeType = mimeType;
+}
+
 void KoDocument::setOutputMimeType( const QCString & mimeType, int specialOutputFlag )
 {

--- koffice/lib/kofficecore/koDocument.h  #1.147.2.1:1.147.2.2
@@ -199,4 +199,11 @@ public:
 
     /**
+     * Sets the mime type for the document.
+     * When choosing "save as" this is also the mime type
+     * selected by default.
+     */
+    void setMimeType( const QCString & mimeType );
+
+    /**
      * Set the format in which the document should be saved.
      * This is called on loading, and in "save as", so you shouldn't