]> git.sesse.net Git - mlt/blobdiff - src/modules/qt/qimage_wrapper.cpp
Refactor QApplication creation and fix lifetime of its args.
[mlt] / src / modules / qt / qimage_wrapper.cpp
index 4fb645455f9d36e7e77d1ff74d5eb6605a6922ef..ee5db0b13dd0d0aab0af3b9741a8c88d7d52bee9 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include "qimage_wrapper.h"
+#include "common.h"
 
 #ifdef USE_KDE4
 #include <kcomponentdata.h>
 
 #include <QImage>
 #include <QSysInfo>
-#include <QApplication>
 #include <QMutex>
 #include <QtEndian>
 #include <QTemporaryFile>
-#include <QLocale>
 
 #ifdef USE_EXIF
 #include <libexif/exif-data.h>
@@ -51,8 +50,6 @@ extern "C" {
 static KComponentData *instance = 0L;
 #endif
 
-static QApplication *app = NULL;
-
 static void qimage_delete( void *data )
 {
        QImage *image = ( QImage * )data;
@@ -163,31 +160,9 @@ int refresh_qimage( producer_qimage self, mlt_frame frame )
        sprintf( image_key, "%d", image_idx );
 
        int disable_exif = mlt_properties_get_int( producer_props, "disable_exif" );
-       
-       
-       if ( app == NULL ) 
-       {
-               if ( qApp ) 
-               {
-                       app = qApp;
-               }
-               else 
-               {
-#ifdef linux
-                       if ( getenv("DISPLAY") == 0 )
-                       {
-                               mlt_log_panic( MLT_PRODUCER_SERVICE( producer ), "Error, cannot render titles without an X11 environment.\nPlease either run melt from an X session or use a fake X server like xvfb:\nxvfb-run -a melt (...)\n" );
-                               return -1;
-                       }
-#endif
-                       int argc = 1;
-                       char* argv[1];
-                       argv[0] = (char*) "xxx";
-                       app = new QApplication( argc, argv );
-                       const char *localename = mlt_properties_get_lcnumeric( MLT_SERVICE_PROPERTIES( MLT_PRODUCER_SERVICE( producer ) ) );
-                       QLocale::setDefault( QLocale( localename ) );
-               }
-       }
+
+       if ( !createQApplicationIfNeeded( MLT_PRODUCER_SERVICE(producer) ) )
+               return -1;
 
        if ( image_idx != self->qimage_idx )
                self->qimage = NULL;