src/hbservers/hbsplashgenerator/hbsplashgenerator.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    64 HbSplashGenerator::HbSplashGenerator()
    64 HbSplashGenerator::HbSplashGenerator()
    65     : mMainWindowLocked(false),
    65     : mMainWindowLocked(false),
    66       mProcessQueuePending(false),
    66       mProcessQueuePending(false),
    67       mForceRegen(false),
    67       mForceRegen(false),
    68       mMainWindow(0),
    68       mMainWindow(0),
    69       mFirstRegenerate(true)
    69       mFirstRegenerate(true),
       
    70       mSaveSplFailed(false)
    70 {
    71 {
    71 #if defined(Q_OS_SYMBIAN)
    72 #if defined(Q_OS_SYMBIAN)
    72     CCoeEnv::Static()->FsSession().CreatePrivatePath(EDriveC);
    73     CCoeEnv::Static()->FsSession().CreatePrivatePath(EDriveC);
    73     QString iniFileName = QString("c:/private/%1/hbsplashgen.ini")
    74     QString iniFileName = QString("c:/private/%1/hbsplashgen.ini")
    74                           .arg(QString::number(hbsplash_server_uid3.iUid, 16));
    75                           .arg(QString::number(hbsplash_server_uid3.iUid, 16));
   212             // Queue the screenshot request for both orientations.
   213             // Queue the screenshot request for both orientations.
   213             mQueue.enqueue(QueueItem(themeName, Qt::Vertical));
   214             mQueue.enqueue(QueueItem(themeName, Qt::Vertical));
   214             mQueue.enqueue(QueueItem(themeName, Qt::Horizontal));
   215             mQueue.enqueue(QueueItem(themeName, Qt::Horizontal));
   215             queueAppSpecificItems(themeName, Qt::Vertical);
   216             queueAppSpecificItems(themeName, Qt::Vertical);
   216             queueAppSpecificItems(themeName, Qt::Horizontal);
   217             queueAppSpecificItems(themeName, Qt::Horizontal);
       
   218             mSaveSplFailed = false;
   217             qDebug() << PRE << "queue preparation time (ms):" << queuePrepTime.elapsed();
   219             qDebug() << PRE << "queue preparation time (ms):" << queuePrepTime.elapsed();
   218             QMetaObject::invokeMethod(this, "processQueue", Qt::QueuedConnection);
   220             QMetaObject::invokeMethod(this, "processQueue", Qt::QueuedConnection);
   219         } catch (const std::bad_alloc &) {
   221         } catch (const std::bad_alloc &) {
   220             cleanup();
   222             cleanup();
   221         }
   223         }
   222     }
   224     }
   223 }
   225 }
   224 
   226 
       
   227 // This function is for the splashviewer tool only, do not use from elsewhere.
   225 void HbSplashGenerator::regenerateOne(const QString &splashmlFileName, const QString &customTrDir)
   228 void HbSplashGenerator::regenerateOne(const QString &splashmlFileName, const QString &customTrDir)
   226 {
   229 {
   227     mQueue.clear();
   230     mQueue.clear();
   228     QueueItem item(hbInstance->theme()->name(), Qt::Vertical);
   231     QueueItem item(hbInstance->theme()->name(), Qt::Vertical);
   229     QString path = QFileInfo(splashmlFileName).path();
   232     QString path = QFileInfo(splashmlFileName).path();
   270     if (mQueue.isEmpty()) {
   273     if (mQueue.isEmpty()) {
   271         qDebug() << PRE << "queue is empty  regen finished";
   274         qDebug() << PRE << "queue is empty  regen finished";
   272         mSettings->setValue(last_theme_key, hbInstance->theme()->name());
   275         mSettings->setValue(last_theme_key, hbInstance->theme()->name());
   273         mSettings->setValue(last_lang_key, QLocale::system().name());
   276         mSettings->setValue(last_lang_key, QLocale::system().name());
   274         QString outDir = hbsplash_output_dir();
   277         QString outDir = hbsplash_output_dir();
   275         mSettings->setValue(last_file_count_key, updateOutputDirContents(outDir));
   278         // Notify the server and get the number of generated files...
       
   279         int fileCount = updateOutputDirContents(outDir);
       
   280         // ...but store zero if some file writing failed at some point
       
   281         // so there will be a regeneration on next boot at least.
       
   282         if (mSaveSplFailed) {
       
   283             fileCount = 0;
       
   284             qDebug() << PRE << "some files not ok, ignoring file count";
       
   285         } else {
       
   286             qDebug() << PRE << "all files ok";
       
   287         }
       
   288         mSettings->setValue(last_file_count_key, fileCount);
   276         mSettings->setValue(last_output_dir_key, outDir);
   289         mSettings->setValue(last_output_dir_key, outDir);
   277         emit finished();
   290         emit finished();
   278         qDebug() << PRE << "processQueue() over";
   291         qDebug() << PRE << "processQueue() over";
   279         return;
   292         return;
   280     }
   293     }
   296         qDebug() << PRE << "mainwindow init time (ms):" << mItemTime.elapsed();
   309         qDebug() << PRE << "mainwindow init time (ms):" << mItemTime.elapsed();
   297 
   310 
   298         QTime setupTime;
   311         QTime setupTime;
   299         setupTime.start();
   312         setupTime.start();
   300         setupAppSpecificWindow();
   313         setupAppSpecificWindow();
   301         finishWindow();
   314         qDebug() << PRE << "content setup time (ms):" << setupTime.elapsed();
   302         qDebug() << PRE << "content setup time(ms):" << setupTime.elapsed();
   315 
   303 
   316         // The async call chain goes like this:
   304         QMetaObject::invokeMethod(this, "processWindow", Qt::QueuedConnection);
   317         // processQueue -> finishWindow -> processWindow -> processQueue -> ...
       
   318         // finishWindow() cannot be called directly from here because that would
       
   319         // result in asserts in QGraphicsScene with certain Qt versions.
       
   320         QMetaObject::invokeMethod(this, "finishWindow", Qt::QueuedConnection);
   305 
   321 
   306     } catch (const std::bad_alloc &) {
   322     } catch (const std::bad_alloc &) {
   307         cleanup();
   323         cleanup();
   308     }
   324     }
   309     qDebug() << PRE << "processQueue() over";
   325     qDebug() << PRE << "processQueue() over";
   361 #if !defined(Q_OS_SYMBIAN) && defined(QT_DEBUG)
   377 #if !defined(Q_OS_SYMBIAN) && defined(QT_DEBUG)
   362             image.save(splashFile + QLatin1String(".png"));
   378             image.save(splashFile + QLatin1String(".png"));
   363 #endif
   379 #endif
   364         } else {
   380         } else {
   365             qWarning() << PRE << "file write failed for" << splashFile;
   381             qWarning() << PRE << "file write failed for" << splashFile;
       
   382             mSaveSplFailed = true;
   366         }
   383         }
   367         qDebug() << PRE << "save time (ms):" << t.elapsed();
   384         qDebug() << PRE << "save time (ms):" << t.elapsed();
   368         log("takeScreenshot() over", mItem.mThemeName, mItem.mOrientation);
   385         log("takeScreenshot() over", mItem.mThemeName, mItem.mOrientation);
   369     } catch (const std::bad_alloc &) {
   386     } catch (const std::bad_alloc &) {
   370         cleanup();
   387         cleanup();
   374 QString HbSplashGenerator::splashFileName()
   391 QString HbSplashGenerator::splashFileName()
   375 {
   392 {
   376     QString outDirName = hbsplash_output_dir();
   393     QString outDirName = hbsplash_output_dir();
   377     QDir dir(outDirName);
   394     QDir dir(outDirName);
   378     if (!dir.exists()) {
   395     if (!dir.exists()) {
   379         if (!QDir(".").mkdir(outDirName)) {
   396         if (!QDir(".").mkpath(outDirName)) {
   380             qWarning() << PRE << "mkdir failed for" << outDirName;
   397             qWarning() << PRE << "mkpath failed for" << outDirName;
   381         }
   398         }
   382     }
   399     }
   383     // "splash_<orientation>_<appid>_<screenid>"
   400     // "splash_<orientation>_<appid>_<screenid>"
   384     QString splashFile = dir.filePath("splash_");
   401     QString splashFile = dir.filePath("splash_");
   385     splashFile.append(orientationName(mItem.mOrientation));
   402     splashFile.append(orientationName(mItem.mOrientation));
   407         f.write((char *) &w, sizeof(quint32));
   424         f.write((char *) &w, sizeof(quint32));
   408         f.write((char *) &h, sizeof(quint32));
   425         f.write((char *) &h, sizeof(quint32));
   409         f.write((char *) &bpl, sizeof(quint32));
   426         f.write((char *) &bpl, sizeof(quint32));
   410         f.write((char *) &fmt, sizeof(qint32));
   427         f.write((char *) &fmt, sizeof(qint32));
   411         f.write((char *) &extra, sizeof(quint32));
   428         f.write((char *) &extra, sizeof(quint32));
   412         f.write((const char *) image.bits(), bpl * h);
   429         qint64 wcount = f.write((const char *) image.bits(), bpl * h);
   413         f.close();
   430         f.close();
   414         return true;
   431         return wcount == bpl * h;
   415     }
   432     }
   416     return false;
   433     return false;
   417 }
   434 }
   418 
   435 
   419 void HbSplashGenerator::cleanup()
   436 void HbSplashGenerator::cleanup()
   745     }
   762     }
   746 }
   763 }
   747 
   764 
   748 void HbSplashGenerator::finishWindow()
   765 void HbSplashGenerator::finishWindow()
   749 {
   766 {
       
   767     QTime prepTime;
       
   768     prepTime.start();
       
   769 
   750     // There must be a view always in order to support view-specific settings.
   770     // There must be a view always in order to support view-specific settings.
   751     if (mMainWindow->views().isEmpty()) {
   771     if (mMainWindow->views().isEmpty()) {
   752         mMainWindow->addView(new HbWidget);
   772         mMainWindow->addView(new HbWidget);
   753     }
   773     }
   754 
   774 
   824         }
   844         }
   825     }
   845     }
   826 
   846 
   827     // Hide dynamic content from status bar (clock, indicators).
   847     // Hide dynamic content from status bar (clock, indicators).
   828     setStatusBarElementsVisible(mMainWindow, false);
   848     setStatusBarElementsVisible(mMainWindow, false);
       
   849 
       
   850     qDebug() << PRE << "time spent in finishWindow() (ms):" << prepTime.elapsed();
       
   851 
       
   852     // Continue with rendering the graphics view in processWindow().
       
   853     QMetaObject::invokeMethod(this, "processWindow", Qt::QueuedConnection);
   829 }
   854 }
   830 
   855 
   831 void HbSplashGenerator::setStatusBarElementsVisible(HbMainWindow *mw, bool visible)
   856 void HbSplashGenerator::setStatusBarElementsVisible(HbMainWindow *mw, bool visible)
   832 {
   857 {
   833     HbMainWindowPrivate *mwd = HbMainWindowPrivate::d_ptr(mw);
   858     HbMainWindowPrivate *mwd = HbMainWindowPrivate::d_ptr(mw);