[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/graphics/kpovmodeler
From:       Christoph Feck <christoph () maxiom ! de>
Date:       2010-10-09 15:55:55
Message-ID: 20101009155555.35A27AC892 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1184253 by cfeck:

Use KImageIO::typeForMime to detect format

Fall back to PNG format, like in KSnapshot.
BUG: 238981


 M  +6 -32     pmpovraywidget.cpp  
 M  +0 -1      pmpovraywidget.h  


--- trunk/extragear/graphics/kpovmodeler/pmpovraywidget.cpp #1184252:1184253
@@ -40,7 +40,6 @@
 #include <QVBoxLayout>
 #include <QImageWriter>
 const int timerIntervall = 1000;
-bool PMPovrayWidget::s_imageFormatsRegistered = false;
 
 PMPovrayWidget::PMPovrayWidget( QWidget* parent )
       : KDialog( parent )
@@ -237,12 +236,6 @@
    QFile* file = 0;
    bool ok = true;
 
-   if( !s_imageFormatsRegistered )
-   {
-
-      s_imageFormatsRegistered = true;
-   }
-
    KUrl url = KFileDialog::getSaveUrl( KUrl( ), KImageIO::pattern( KImageIO::Writing ) );
    if( url.isEmpty( ) )
       return;
@@ -255,31 +248,12 @@
       return;
    }
 
-#ifdef __GNUC__
-#warning is this really needed?
-#endif
-   QString suffix = url.fileName().toUpper();
-   if (suffix.lastIndexOf('.') >= 0)
-     suffix = suffix.mid(suffix.lastIndexOf('.'));
+   QByteArray format = "PNG";
+   QString mimeType = KMimeType::findByUrl( url.fileName( ), 0, url.isLocalFile( ), true )->name( );
+   QStringList formats = KImageIO::typeForMime( mimeType );
+   if ( !formats.isEmpty( ) )
+      format = formats.first( ).toLatin1( );
 
-   QString format;
-
-   if (QImageWriter::supportedImageFormats().contains(suffix.toLatin1()))
-      format = suffix;
-
-   if( format.isEmpty( ) )
-   {
-      KMessageBox::error( this, i18n( "Unknown image format.\n"
-                                      "Please enter a valid suffix." ) );
-      return;
-   }
-
-   if( !KImageIO::types( ).contains(format) )
-   {
-      KMessageBox::error( this, i18n( "Format is not supported for writing." ) );
-      return;
-   }
-
    if( url.isLocalFile( ) )
    {
       // Local file
@@ -300,7 +274,7 @@
 
    if( ok )
    {
-      QImageWriter iio( file, format.toLatin1() );
+      QImageWriter iio( file, format );
       ok = iio.write(m_pRenderWidget->image( )  );
 
       if( ok )
--- trunk/extragear/graphics/kpovmodeler/pmpovraywidget.h #1184252:1184253
@@ -96,7 +96,6 @@
    float m_speed;
    int m_line;
    bool m_stopped;
-   static bool s_imageFormatsRegistered;
 };
 
 #endif
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic