activityfw/testapplications/nftapps/lptapp/thumbwidget.cpp
changeset 117 c63ee96dbe5f
equal deleted inserted replaced
115:3ab5c078b490 117:c63ee96dbe5f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include "thumbwidget.h"
       
    18 
       
    19 
       
    20 
       
    21 thumbwidget::thumbwidget(QObject* activityStorage, QObject* activityManager, QTextStream* stream, QGraphicsItem *parent)
       
    22     : basewidget(activityStorage, activityManager, stream, parent)
       
    23 {
       
    24     mTestCheckBox->setText("Prepare data");
       
    25     mKBytesEdid->setText("1");
       
    26     mStartTestButton->setText("Thumb");
       
    27 }
       
    28 
       
    29 thumbwidget::~thumbwidget()
       
    30 {
       
    31 }
       
    32 
       
    33 
       
    34 void thumbwidget::timeout()
       
    35 {
       
    36     if(mAction == "predel") {
       
    37         if(mItemsCounter<mItems) {
       
    38             QString name = mActivities.at(mItemsCounter);
       
    39             bool ok = removeActivity(name);
       
    40             mItemsCounter++;
       
    41             if(!ok) {                
       
    42                 setError("remove activity");
       
    43                 return;
       
    44             }            
       
    45             updateItemLabel(mItemsCounter);
       
    46         }
       
    47         else {
       
    48             mItems=Items();
       
    49             mItemsCounter = 0;
       
    50             mAction = "presave";
       
    51             updateActionLabel();
       
    52             //updateItemLabel(mItemsCounter);
       
    53             prepareSave();
       
    54         }
       
    55     }
       
    56     else if(mAction == "presave") {
       
    57         if(mItemsCounter<mItems) {
       
    58             bool ok = saveActivity(mItemsCounter);
       
    59             mItemsCounter++;
       
    60             if(!ok) {                
       
    61                 setError("save activity");
       
    62                 return;
       
    63             }            
       
    64             updateItemLabel(mItemsCounter);
       
    65         }
       
    66         else {
       
    67             mItems=Items();
       
    68             mTimes=Times();
       
    69             mItemsCounter = 0;
       
    70             mAction = "thumb";
       
    71             updateActionLabel();
       
    72             //updateItemLabel(mItemsCounter);
       
    73             updateTimeLabel(mTimesCounter);
       
    74             clearSaveData();
       
    75             logFirst();
       
    76             connect( mActivityManager, SIGNAL(thumbnailReady(QPixmap, void *)), this, SLOT(thumbnailReady(QPixmap, void *)) );
       
    77             bool ok = activities();
       
    78             if(!ok) {
       
    79                 setError("get activities list");
       
    80                 return;
       
    81             }
       
    82         }
       
    83     }
       
    84     else if(mAction == "thumb") {
       
    85         if(mTimesCounter==mTimes) {
       
    86             endNormally();
       
    87             return;
       
    88         }
       
    89         if(mItemsCounter<mItems) {
       
    90             QString name = mActivities.at(mItemsCounter);
       
    91             bool ok = getThumbnail(name);
       
    92             mItemsCounter++;
       
    93             if(!ok) {                
       
    94                 setError("get thumbnail");
       
    95                 return;
       
    96             }            
       
    97             updateItemLabel(mItemsCounter);
       
    98             mTimer->stop();
       
    99         }
       
   100         else {
       
   101             mTimesCounter++;
       
   102             mItemsCounter = 0;
       
   103             //updateItemLabel(mItemsCounter);
       
   104             updateTimeLabel(mTimesCounter);
       
   105         }
       
   106     }
       
   107     else {
       
   108         setError("unexpected state");
       
   109     }
       
   110 }
       
   111 
       
   112 void thumbwidget::test()
       
   113 {
       
   114     mTimesCounter = 0;
       
   115     mStatusValueLabel->setPlainText("Pending");
       
   116     enableControls(false);
       
   117     *mStream<<tr("*Get thumbnail*\n");
       
   118     mStream->flush();
       
   119     logSettings();
       
   120     bool ok = activities();
       
   121     if(!ok) {
       
   122         setError("get activities list");
       
   123         return;
       
   124     }
       
   125     if (TestCheckBoxChecked()) {
       
   126         mAction = "predel"; 
       
   127         mItems = mActivities.count();        
       
   128     }
       
   129     else {
       
   130         mAction = "thumb";
       
   131         ok = checkActNum();
       
   132          if(!ok) {
       
   133              setError("unexpected act number");
       
   134              return;
       
   135          }
       
   136          mItems=Items();
       
   137          mTimes=Times();
       
   138          mItemsCounter = 0;
       
   139          updateItemLabel(mItemsCounter);
       
   140          updateTimeLabel(mTimesCounter);
       
   141          logFirst();
       
   142          connect( mActivityManager, SIGNAL(thumbnailReady(QPixmap, void *)), this, SLOT(thumbnailReady(QPixmap, void *)) );
       
   143     }
       
   144     basewidget::test();      
       
   145 }
       
   146 
       
   147 void thumbwidget::thumbnailReady(QPixmap pixmap, void* ptr)
       
   148 {
       
   149     if(pixmap.isNull()) {
       
   150         setError("Null pixmap");
       
   151         return;
       
   152     }
       
   153     mTimer->start(1);
       
   154 }
       
   155 
       
   156 void thumbwidget::endTest(int reason)
       
   157 {
       
   158     disconnect( mActivityManager, SIGNAL(thumbnailReady(QPixmap, void *)), this, SLOT(thumbnailReady(QPixmap, void *)) );
       
   159     basewidget::endTest(reason);
       
   160 }