homescreenapp/hsapplication/src/hshomescreenclientserviceprovider.cpp
changeset 60 30f14686fb04
parent 51 4785f57bf3d4
child 61 2b1b11a301d2
equal deleted inserted replaced
55:03646e8da489 60:30f14686fb04
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <QDir>
       
    19 #include <QFileInfo>
       
    20 
       
    21 #include "hshomescreenclientserviceprovider.h"
    18 #include "hshomescreenclientserviceprovider.h"
    22 #include "hswidgetcomponentdescriptor.h"
    19 #include "hswidgetcomponentdescriptor.h"
    23 #include "hscontentservice.h"
    20 #include "hscontentservice.h"
    24 
       
    25 #include "hsscene.h"
    21 #include "hsscene.h"
    26 #include "hsdomainmodeldatastructures.h"
    22 #include "hspage.h"
    27 #include "hswallpaper.h"
    23 #include "hswallpaper.h"
    28 #include "hsdatabase.h"
       
    29 #include "hswallpaperhelper.h"
       
    30 #include "hswidgetcomponentregistry.h"
    24 #include "hswidgetcomponentregistry.h"
    31 #include "hsconfiguration.h"
    25 #include "hsconfiguration.h"
       
    26 #include "hsspinnerdialog.h"
    32 
    27 
    33 namespace
    28 namespace
    34 {
    29 {
    35     const char gInterfaceName[] = "com.nokia.services.hsapplication.IHomeScreenClient";
    30     const char gInterfaceName[] = "com.nokia.symbian.IHomeScreenClient";
    36 }
    31 }
       
    32 
       
    33 
       
    34 /*!
       
    35     \class HsHomeScreenClientServiceProvider
       
    36     \ingroup group_hsapplication
       
    37     \brief TODO
       
    38 */
    37 
    39 
    38 /*!
    40 /*!
    39     Constructor.
    41     Constructor.
    40 */
    42 */
    41 HsHomeScreenClientServiceProvider::HsHomeScreenClientServiceProvider(QObject *parent)
    43 HsHomeScreenClientServiceProvider::HsHomeScreenClientServiceProvider(QObject *parent)
    42   : XQServiceProvider(gInterfaceName, parent)
    44   : XQServiceProvider(gInterfaceName, parent),
       
    45     mWaitDialog(0),
       
    46     mShowAnimation(false),
       
    47     mAsyncRequestIndex(0),    
       
    48     mReturnValue(false),
       
    49     mWallpaper(0)
    43 {
    50 {
    44     publishAll();
    51     publishAll();
    45 }
    52 }
    46 
    53 
    47 /*!
    54 /*!
    54 #ifdef COVERAGE_MEASUREMENT
    61 #ifdef COVERAGE_MEASUREMENT
    55 #pragma CTC SKIP
    62 #pragma CTC SKIP
    56 #endif //COVERAGE_MEASUREMENT
    63 #endif //COVERAGE_MEASUREMENT
    57 
    64 
    58 /*!
    65 /*!
    59     Adds new widget, with the give \a uri and \a preferences, 
    66     Adds new widget, with the give \a uri and \a preferences,
    60     to the active home screen page.
    67     to the active home screen page.
    61 */
    68 */
    62 bool HsHomeScreenClientServiceProvider::addWidget(const QString &uri, const QVariantHash &preferences)
    69 bool HsHomeScreenClientServiceProvider::addWidget(const QString &uri, const QVariantHash &preferences)
    63 {
    70 {
    64     return HsContentService::instance()->addWidget(uri, preferences);
    71     return HsContentService::instance()->addWidget(uri, preferences);
    65 }
    72 }
    66 
    73 
    67 /*!
    74 /*!
    68     Changes \a fileName image to the active home screen page's wallpaper.
    75     Changes \a fileName image to the active home screen page's wallpaper.
    69 */
    76 */
    70 bool HsHomeScreenClientServiceProvider::setWallpaper(const QString &fileName)
    77 void HsHomeScreenClientServiceProvider::setWallpaper(const QString &fileName)
    71 {
    78 {
    72     HsScene *scene = HsScene::instance();
    79 #ifndef HOMESCREEN_TEST //We can't use QtHighway at unit tests due to missing service client connection
    73         
    80     mAsyncRequestIndex = setCurrentRequestAsync();
    74     HsDatabase *db = HsDatabase::instance();
    81 #endif
    75     Q_ASSERT(db);
    82     if ( !mWaitDialog ) {
    76     
    83         mWaitDialog = new HsSpinnerDialog();
    77     HsSceneData sceneData;
    84         }
    78     if (!db->scene(sceneData)) {
    85     mWaitDialog->start();
    79         return false;
    86     mShowAnimation = true;
       
    87     if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) {
       
    88         mWallpaper = HsScene::instance()->activePage()->wallpaper();
       
    89     } else {
       
    90         mWallpaper = HsScene::instance()->wallpaper();
    80     }
    91     }
    81 
    92     connect(mWallpaper, SIGNAL(imageSet()), SLOT(onImageSet()));
    82     QFileInfo fileInfo(fileName);
    93     connect(mWallpaper, SIGNAL(imageSetFailed()),
    83     QString fileExtension("");
    94             SLOT(onImageSetFailed()));
    84     if (!fileInfo.suffix().isEmpty()) {
    95     mWallpaper->setImage(fileName);
    85         fileExtension = fileInfo.suffix();
       
    86     }
       
    87     
       
    88     QFile::remove(sceneData.portraitWallpaper);
       
    89     QFile::remove(sceneData.landscapeWallpaper); 
       
    90     
       
    91     QString wallpaperDir = HsWallpaper::wallpaperDirectory();            
       
    92     QDir dir(wallpaperDir);
       
    93     if (!dir.exists()) {
       
    94         dir.mkpath(wallpaperDir);
       
    95     }
       
    96     
       
    97     QString portraitPath = HsWallpaper::wallpaperPath(
       
    98         Qt::Vertical, QString(), fileExtension);
       
    99     QString landscapePath = HsWallpaper::wallpaperPath(
       
   100         Qt::Horizontal, QString(), fileExtension);
       
   101     
       
   102     int bounceEffect = HsConfiguration::bounceEffect();
       
   103 
       
   104     QRect portraitRect = QRect(0, 0, (2 * 360) + bounceEffect, 640);
       
   105     QRect landscapeRect = QRect(0, 0, (2 * 640) + bounceEffect, 360);
       
   106     QRect sourceRect; // left empty to signal we want to use full size image as source
       
   107     
       
   108     QImage portraitImage = HsWallpaperHelper::processImage(fileName,
       
   109             portraitRect, sourceRect);
       
   110 
       
   111     QImage landscapeImage = HsWallpaperHelper::processImage(fileName,
       
   112             landscapeRect, sourceRect);
       
   113 
       
   114     if (!portraitImage.isNull() && !landscapeImage.isNull()) {
       
   115         portraitImage.save(portraitPath);
       
   116         sceneData.portraitWallpaper = portraitPath;
       
   117         
       
   118         landscapeImage.save(landscapePath);
       
   119         sceneData.landscapeWallpaper = landscapePath;
       
   120         
       
   121         if (db->updateScene(sceneData)) {
       
   122             scene->wallpaper()->setImagesById(QString(), fileInfo.suffix());
       
   123         }
       
   124     }
       
   125     else {
       
   126         // display some error note here
       
   127     }
       
   128     return true;
       
   129 }
    96 }
   130 
    97 
       
    98 /*!
       
    99     \internal
       
   100     Called when wallpaper image has been set successfully  
       
   101 */
       
   102 void HsHomeScreenClientServiceProvider::onImageSet()
       
   103 {
       
   104     mWallpaper->disconnect(this);
       
   105     stopAnimation();
       
   106 #ifndef HOMESCREEN_TEST //We can't use QtHighway at unit tests due to missing service client connection
       
   107     completeRequest(mAsyncRequestIndex, QVariant(true));
       
   108 #endif
       
   109 }
   131 
   110 
       
   111 /*!
       
   112     \internal
       
   113     Called when error has happened in wallpaper image setting
       
   114 */
       
   115 void HsHomeScreenClientServiceProvider::onImageSetFailed()
       
   116 {
       
   117     mWallpaper->disconnect(this);
       
   118     stopAnimation();
       
   119 #ifndef HOMESCREEN_TEST //We can't use QtHighway at unit tests due to missing service client connection
       
   120     completeRequest(mAsyncRequestIndex, QVariant(false));
       
   121 #endif
       
   122 }
   132 
   123 
       
   124 /*!
       
   125     Stops progress animation
       
   126 */
       
   127 void HsHomeScreenClientServiceProvider::stopAnimation()
       
   128 {
       
   129     if (mShowAnimation) {
       
   130         mWaitDialog->stop();
       
   131         mWaitDialog=0;
       
   132     }
       
   133 }
       
   134 
       
   135 /*!
       
   136 
       
   137 */
   133 bool HsHomeScreenClientServiceProvider::widgetUninstalled(const QVariantHash &widgetDescriptor)
   138 bool HsHomeScreenClientServiceProvider::widgetUninstalled(const QVariantHash &widgetDescriptor)
   134 {
   139 {
   135     HsWidgetComponentDescriptor widgetComponent = widgetComponentDescriptor(widgetDescriptor);
   140     HsWidgetComponentDescriptor widgetComponent = widgetComponentDescriptor(widgetDescriptor);
   136     HsWidgetComponentRegistry* widgetRegistry = HsWidgetComponentRegistry::instance();
   141     HsWidgetComponentRegistry* widgetRegistry = HsWidgetComponentRegistry::instance();
   137     widgetRegistry->uninstallComponent(widgetComponent);
   142     widgetRegistry->uninstallComponent(widgetComponent);
   141 
   146 
   142 #ifdef COVERAGE_MEASUREMENT
   147 #ifdef COVERAGE_MEASUREMENT
   143 #pragma CTC ENDSKIP
   148 #pragma CTC ENDSKIP
   144 #endif //COVERAGE_MEASUREMENT
   149 #endif //COVERAGE_MEASUREMENT
   145 
   150 
       
   151 /*!
       
   152 
       
   153 */
   146 HsWidgetComponentDescriptor HsHomeScreenClientServiceProvider::widgetComponentDescriptor(const QVariantHash& widgetDescriptor)
   154 HsWidgetComponentDescriptor HsHomeScreenClientServiceProvider::widgetComponentDescriptor(const QVariantHash& widgetDescriptor)
   147 {
   155 {
   148     HsWidgetComponentDescriptor widget;
   156     HsWidgetComponentDescriptor widget;
   149     widget.installationPath = widgetDescriptor["installationPath"].toString(); 
   157     widget.installationPath = widgetDescriptor["installationPath"].toString();
   150     widget.uri = widgetDescriptor["uri"].toString(); 
   158     widget.uri = widgetDescriptor["uri"].toString();
   151     widget.title = widgetDescriptor["title"].toString(); 
   159     widget.title = widgetDescriptor["title"].toString();
   152     widget.description = widgetDescriptor["description"].toString(); 
   160     widget.description = widgetDescriptor["description"].toString();
   153     widget.iconUri = widgetDescriptor["iconUri"].toString(); 
   161     widget.iconUri = widgetDescriptor["iconUri"].toString();
   154     widget.hidden = widgetDescriptor["hidden"].toString(); 
   162     widget.hidden = widgetDescriptor["hidden"].toString();
   155     widget.serviceXml = widgetDescriptor["serviceXml"].toString(); 
   163     widget.serviceXml = widgetDescriptor["serviceXml"].toString();
   156     widget.version = widgetDescriptor["version"].toString(); 
   164     widget.version = widgetDescriptor["version"].toString();
   157     return widget;
   165     return widget;
   158 }
   166 }