Bug 72827 - cannot insert picture in kword documents: "ok" button disabled
Summary: cannot insert picture in kword documents: "ok" button disabled
Status: RESOLVED FIXED
Alias: None
Product: kword
Classification: Miscellaneous
Component: general (show other bugs)
Version: 1.5 or before
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Thomas Zander
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-01-17 17:04 UTC by Amit Shah
Modified: 2004-10-19 21:08 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Amit Shah 2004-01-17 17:04:32 UTC
Version:           1.2.94 (using KDE 3.1.94 (3.2 Beta 2), compiled sources)
Compiler:          gcc version 3.3.2 (Debian)
OS:          Linux (i686) release 2.6.1

insert->picture, select a .gif file. In the next dialog box, the "ok" button is disabled, so I can't add the picture there.
Comment 1 Kai Lahmann 2004-01-17 17:10:42 UTC
works for me - who made something wrong?
Comment 2 Nicolas Goutte 2004-01-18 01:17:17 UTC
Does the picture show in the dialog box?

Can the picture be displayed at all? (Be it in Konqueror, KWView, Kuickshow.)

Have a nice day!
Comment 3 Amit Shah 2004-01-19 08:53:36 UTC
Subject: Re:  cannot insert picture in kword documents: "ok" button disabled

On Sunday 18 Jan 2004 05:47, Nicolas Goutte wrote:
> ------- Does the picture show in the dialog box?

yes, it does

> Can the picture be displayed at all? (Be it in Konqueror, KWView,
> Kuickshow.)

yes..

Comment 4 Nicolas Goutte 2004-01-20 19:31:47 UTC
As this bug report is marked as "compiled source" can you attach to this bug the revelant part of the debug messages? (It might be perhaps easier to start KWord from a Konsole to do this.)

Have a nice day!
Comment 5 Amit Shah 2004-01-21 10:46:55 UTC
Subject: Re:  cannot insert picture in kword documents: "ok" button disabled

On Wednesday 21 Jan 2004 00:01, Nicolas Goutte wrote:
> ------- As this bug report is marked as "compiled source" can you attach to
> this bug the revelant part of the debug messages? (It might be perhaps
> easier to start KWord from a Konsole to do this.)

I tried it again, and here's how to reproduce it: insert->picture, select some 
pic. The "OK" button is active. Click "choose picture" and click cancel in 
the file selection dialog box. The picture selected earlier appears in the 
thumbnail view, but the "OK" button is disabled.

Comment 6 Nicolas Goutte 2004-01-22 21:10:35 UTC
Sorry, I cannot reproduce it. (I hope that it is not a bug of KDE 3.2.)

Have a nice day!
Comment 7 Nicolas Goutte 2004-01-22 22:33:13 UTC
I have looked in the code.

I have found a few potential problems if the picture loaded is a remote file (for example floppy: or http:) but if your case is with a local file, then I have not found anything.

Have a nice day!
Comment 8 Nicolas Goutte 2004-01-22 22:38:49 UTC
Subject: koffice/lib/kofficecore

CVS commit by goutte: 

Be more careful with remote pictures:
- add GIF magic (if Qt does not know GIF, a conversion to PNG will fail too
  anyway.)
- when doing the conversion of an unknow file type to PNG, be careful not to
  use QBuffer and QByteArray simultaneously (so use QByteArray::copy and
  QBuffer::buffer.)
- be careful that QBuffer::open(IO_WriteOnly) does *not* truncate
  (So there are potential problems if the converted file is smaller than
  the original.)

(This probably should be ported back... when it will be tested.)
CCMAIL:72827@bugs.kde.org


  M +19 -3     koPictureShared.cc   1.27


--- koffice/lib/kofficecore/koPictureShared.cc  #1.26:1.27
@@ -135,9 +135,17 @@ bool KoPictureShared::loadTmp(QIODevice*
     // For an extern file or in the storage, .wmf can mean a real Windows Meta File.
 
-    QByteArray array=io->readAll();
+    QByteArray array ( io->readAll() );
+
+    if ( array.size() < 5 )
+    {
+        kdError(30003) << "Picture is less than 5 bytes long!" << endl;
+        return false;
+    }
+
     QString strExtension;
     bool flag=false;
 
     // Try to find the file type by comparing magic on the first few bytes!
+    // ### TODO: could not QImageIO::imageFormat do it too? (At least most of them?)
     if ((array[0]==char(0x89)) && (array[1]=='P') &&(array[2]=='N') && (array[3]=='G'))
     {
@@ -173,4 +181,9 @@ bool KoPictureShared::loadTmp(QIODevice*
         strExtension="eps";
     }
+    else if ((array[0]=='G') && (array[1]=='I') && (array[2]=='F') && (array[3]=='8'))
+    {
+        // GIF (87a or 89a)
+        strExtension="gif";
+    }
     else
     {
@@ -178,5 +191,6 @@ bool KoPictureShared::loadTmp(QIODevice*
             << " Trying to convert to PNG! (in KoPictureShared::loadTmp" << endl;
 
-        QBuffer buf(array);
+        // Do not trust QBuffer and do not work directly on the QByteArray array
+        QBuffer buf( array.copy() );
         if (!buf.open(IO_ReadOnly))
         {
@@ -195,5 +209,5 @@ bool KoPictureShared::loadTmp(QIODevice*
         buf.close();
 
-        if (!buf.open(IO_WriteOnly))
+        if ( !buf.open( IO_WriteOnly | IO_Truncate ) )
         {
             kdError(30003) << "Could not open write buffer!" << endl;
@@ -211,4 +225,6 @@ bool KoPictureShared::loadTmp(QIODevice*
         buf.close();
 
+        array = buf.buffer();
+
         strExtension="png";
     }


Comment 9 Amit Shah 2004-01-24 16:42:53 UTC
Subject: Re:  cannot insert picture in kword documents: "ok" button disabled

On Friday 23 Jan 2004 03:08, Nicolas Goutte wrote:
> CVS commit by goutte:

... sorry, can't test it, 'cos compiling koffice from konstruct (for 
kde3.2-rc) gives me the following error. How do I resolve it?

kspread_condition.cc:40: error: invalid conversion from `int' to `Conditional'
In file included from /usr/include/c++/3.3/backward/iostream.h:31,
                 from kspread_format.cc:42,
                 from libkspreadpart_la.all_cc.cc:82:
/usr/include/c++/3.3/backward/backward_warning.h:32:2: warning: #warning This 
file includes at least one deprecated or antiquated header. Please consider 
using one of the 32 headers found in section 17.4.1.2 of the C++ standard. 
Examples include substituting the <X> header for the <X.h> header for C++ 
includes, or <sstream> instead of the deprecated header <strstream.h>. To 
disable this warning use -Wno-deprecated.
In file included from libkspreadpart_la.all_cc.cc:83:
kspread_sheetprint.cc: In member function `void
   KSpreadSheetPrint::printHeaderFooter(QPainter&, int)':
kspread_sheetprint.cc:551: warning: passing `double' for argument 1 of `void
   QPainter::drawText(int, int, const QString&, int, QPainter::TextDirection)'
kspread_sheetprint.cc:558: warning: passing `double' for argument 1 of `void
   QPainter::drawText(int, int, const QString&, int, QPainter::TextDirection)'
kspread_sheetprint.cc:573: warning: passing `double' for argument 1 of `void
   QPainter::drawText(int, int, const QString&, int, QPainter::TextDirection)'
kspread_sheetprint.cc:581: warning: passing `double' for argument 1 of `void
   QPainter::drawText(int, int, const QString&, int, QPainter::TextDirection)'
make[4]: *** [libkspreadpart_la.all_cc.lo] Error 1
make[4]: Leaving directory 
`/home/Amit/sources/konstruct/apps/koffice/work/koffice-1.2.95/kspread'

Comment 10 Nicolas Goutte 2004-01-24 17:42:21 UTC
Subject: Re:  cannot insert picture in kword documents: "ok" button disabled

Try to remove --enable-final in kspread/Makefile (all if there is more than 
once.)

Have a nice day!

On Saturday 24 January 2004 16:42, Amit Shah wrote:
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug, or are watching someone who is.
>
> http://bugs.kde.org/show_bug.cgi?id=72827
>
>
>
>
> ------- Additional Comments From amitshah@gmx.net  2004-01-24 16:42 -------
> Subject: Re:  cannot insert picture in kword documents: "ok" button
> disabled
>
> On Friday 23 Jan 2004 03:08, Nicolas Goutte wrote:
> > CVS commit by goutte:
>
> ... sorry, can't test it, 'cos compiling koffice from konstruct (for
> kde3.2-rc) gives me the following error. How do I resolve it?
>
(...)

Comment 11 Amit Shah 2004-07-03 15:55:10 UTC
I'm using kde-cvs, compiled from sources. I still get this bug, steps to reproduce same as in comment #5:

1. insert->picture
2. select some picture, click ok in the file dialog box
3. The insert picture dialog pops up
4. click on 'choose picture...'
5. click cancel in the file selection dialog box
6. in the insert picture dialog, the 'ok' button is disabled, but the image preview shows the picture previously selected.
Comment 12 David Faure 2004-10-19 21:08:47 UTC
CVS commit by faure: 

Patch by Sven Langkamp <longamp reallygood de> to fix
BUG: 72827


  M +3 -1      kwinsertpicdia.cc   1.34.2.1


--- koffice/kword/kwinsertpicdia.cc  #1.34:1.34.2.1
@@ -132,5 +132,7 @@ bool KWInsertPicDia::keepRatio() const
 void KWInsertPicDia::slotChooseImage()
 {
-    m_picture = KWInsertPicDia::selectPictureDia( m_doc->picturePath() ) ;
+    KoPicture tmppicture = KWInsertPicDia::selectPictureDia( m_doc->picturePath() );
+    if ( !tmppicture.isNull() ) // if canceled, keep current picture (#72827)
+        m_picture = tmppicture;
     if ( m_picture.isNull() && m_bFirst)
     {