src/hbcore/utils/hbthetestwidget_p.cpp
changeset 6 c3690ec91ef8
parent 5 627c4a0fd0e7
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    48 #include <QGraphicsWidget>
    48 #include <QGraphicsWidget>
    49 #include <QTextStream>
    49 #include <QTextStream>
    50 #include <QFile>
    50 #include <QFile>
    51 #include <QDir>
    51 #include <QDir>
    52 #include <QTimer>
    52 #include <QTimer>
       
    53 #include <QProcess>
    53 #include <hbaction.h>
    54 #include <hbaction.h>
    54 
    55 
    55 #include <QDebug> // for qWarning
    56 #include <QDebug> // for qWarning
    56 
    57 
    57 #ifdef HB_TEXT_MEASUREMENT_UTILITY
    58 #ifdef HB_TEXT_MEASUREMENT_UTILITY
    65 
    66 
    66 const int KWidth = 140; // container size, button width is KWidth/2
    67 const int KWidth = 140; // container size, button width is KWidth/2
    67 const int KHeight = 140; // container size, button height is KHeight/2
    68 const int KHeight = 140; // container size, button height is KHeight/2
    68 // how much must button be dragged before it is actually moved
    69 // how much must button be dragged before it is actually moved
    69 const int KThreshold = 16;
    70 const int KThreshold = 16;
       
    71 
       
    72 const QString KDriveFPath("F:\\data\\log\\");
       
    73 const QString KDriveEPath("E:\\data\\log\\");
       
    74 const QString KDriveCPath("C:\\data\\log\\");
       
    75 const QString KTheAppLaunchConfigureFile("app_launch_config.txt");
    70 
    76 
    71 HbTheTestButton::HbTheTestButton(QGraphicsItem *parent)
    77 HbTheTestButton::HbTheTestButton(QGraphicsItem *parent)
    72 : HbToolButton(parent),
    78 : HbToolButton(parent),
    73   mPressedDown(false)
    79   mPressedDown(false)
    74 {
    80 {
   394 #ifdef HB_THEME_SERVER_MEMORY_REPORT
   400 #ifdef HB_THEME_SERVER_MEMORY_REPORT
   395     HbThemeClient::global()->createMemoryReport();
   401     HbThemeClient::global()->createMemoryReport();
   396 #endif
   402 #endif
   397 }
   403 }
   398 
   404 
       
   405 void HbTheTestWidget::launchThemeChanger()
       
   406 {
       
   407     QProcess::startDetached("hbthemechanger.exe");
       
   408 }
       
   409 
       
   410 void HbTheTestWidget::launchApplications()
       
   411 {
       
   412     // Find config file
       
   413     QString filePath = findAppLaunchConfigFile();
       
   414 
       
   415     QStringList commandLines;
       
   416 
       
   417     if (!filePath.isEmpty()) {
       
   418         // Try to read file
       
   419         QFile file(filePath);
       
   420         if (file.open(QIODevice::ReadOnly)) {
       
   421             QString line;
       
   422 
       
   423             while (!file.atEnd()) {
       
   424                 QByteArray dirtyLine = file.readLine();
       
   425                 line = QString(dirtyLine).trimmed();
       
   426                 // Skip empty lines and comment lines
       
   427                 if (line.isEmpty() || line.at(0) == '#') {
       
   428                     continue;
       
   429                 }
       
   430                 commandLines.append(line);
       
   431             }
       
   432         }
       
   433     }
       
   434 
       
   435     for (int i=0; i<commandLines.count(); i++) {
       
   436         int index = 0;
       
   437         // Parse program name and arguments from the command line
       
   438         QString cmdLine = commandLines.at(i);
       
   439         QStringList args;
       
   440         
       
   441         while (index < cmdLine.count()) {
       
   442             int startIndex = index;
       
   443             // Find empty space
       
   444             while (index < cmdLine.count() && !cmdLine[index].isSpace()) index++;
       
   445             args.append(cmdLine.mid(startIndex, index-startIndex));
       
   446             // Find non-empty space
       
   447             while (index < cmdLine.count() && cmdLine[index].isSpace()) index++;
       
   448         }
       
   449 
       
   450         if (!args.count()) {
       
   451             continue;
       
   452         }
       
   453 
       
   454         QString program = args.at(0);
       
   455         args.removeFirst();
       
   456 
       
   457         QProcess::startDetached(program, args);
       
   458     }
       
   459 }
       
   460 
   399 void HbTheTestWidget::screenCapture()
   461 void HbTheTestWidget::screenCapture()
   400 {
   462 {
   401     setVisible(false);
   463     setVisible(false);
   402     QTimer::singleShot(1000, this, SLOT(doScreenCapture()));
   464     QTimer::singleShot(1000, this, SLOT(doScreenCapture()));
   403 }
   465 }
   430     QDir dir(filePath);
   492     QDir dir(filePath);
   431     if (!dir.exists()) {
   493     if (!dir.exists()) {
   432         dir.mkpath(filePath);
   494         dir.mkpath(filePath);
   433     }
   495     }
   434 
   496 
       
   497     filePath.append(QDir::separator());
   435     if (!HbApplication::applicationName().isEmpty()) {
   498     if (!HbApplication::applicationName().isEmpty()) {
   436         filePath.append(HbApplication::applicationName());
   499         filePath.append(HbApplication::applicationName());
   437     } else {
   500     } else {
   438         filePath.append("unknown_application");
   501         filePath.append("unknown_application");
   439     }
   502     }
   440     filePath.append(".png");
   503     filePath.append(".png");
   441 
   504 
   442 //#ifdef Q_OS_SYMBIAN
       
   443     // todo: not fail-safe code
       
   444 //    TSize screenSize = CCoeEnv::Static()->ScreenDevice()->SizeInPixels();
       
   445 //    TDisplayMode displayMode = CCoeEnv::Static()->ScreenDevice()->DisplayMode();
       
   446 
       
   447 //    CFbsBitmap *bitmap = new (ELeave) CFbsBitmap();
       
   448 //    User::LeaveIfError(bitmap->Create(screenSize, displayMode));
       
   449 
       
   450 //    CCoeEnv::Static()->ScreenDevice()->CopyScreenToBitmap(bitmap);
       
   451 //    QPixmap screenPixmap = QPixmap::fromSymbianCFbsBitmap(bitmap);
       
   452 //#else
       
   453     QPixmap screenPixmap = QPixmap::grabWindow(
   505     QPixmap screenPixmap = QPixmap::grabWindow(
   454         QApplication::activeWindow()->winId()); //krazy:exclude=qclasses
   506         QApplication::activeWindow()->winId()); //krazy:exclude=qclasses
   455 //#endif
   507 
   456     QString format = "png";
   508     QString format = "png";
   457     screenPixmap.save(filePath.toLatin1(), format.toLatin1());
   509     screenPixmap.save(filePath.toLatin1(), format.toLatin1());
   458     setVisible(true);
   510     setVisible(true);
   459 }
   511 }
   460 
   512 
   470     dialog->setContentWidget(textItem);
   522     dialog->setContentWidget(textItem);
   471     dialog->setContentsMargins(5,15,5,15);
   523     dialog->setContentsMargins(5,15,5,15);
   472     dialog->show();
   524     dialog->show();
   473 }
   525 }
   474 
   526 
   475 
   527 QString HbTheTestWidget::findAppLaunchConfigFile()
       
   528 {
       
   529     QString filePath;
       
   530 
       
   531 #if defined (Q_OS_SYMBIAN)
       
   532     if (QFile::exists(KDriveFPath + KTheAppLaunchConfigureFile)) {
       
   533         filePath = KDriveFPath + KTheAppLaunchConfigureFile;
       
   534     } else if (QFile::exists(KDriveEPath + KTheAppLaunchConfigureFile)) {
       
   535         filePath = KDriveEPath + KTheAppLaunchConfigureFile;
       
   536     } else if (QFile::exists(KDriveCPath + KTheAppLaunchConfigureFile)) {
       
   537         filePath = KDriveCPath + KTheAppLaunchConfigureFile;
       
   538     }
       
   539 #elif defined (Q_OS_WIN32)
       
   540     if (QFile::exists(KDriveCPath + KTheAppLaunchConfigureFile)) {
       
   541         filePath = KDriveCPath + KTheAppLaunchConfigureFile;
       
   542     }
       
   543     // only Symbian and Windows are supported
       
   544 #endif
       
   545 
       
   546     return filePath;
       
   547 }
       
   548