homescreenapp/stateplugins/hsmenuworkerstateplugin/tsrc/t_hsmenuworkerstateplugin/src/hswallpaper_mock.cpp
changeset 90 3ac3aaebaee5
child 97 66b5fe3c07fd
equal deleted inserted replaced
86:e4f038c420f7 90:3ac3aaebaee5
       
     1 /*
       
     2 * Copyright (c) 2010 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 
       
    18 #include <QDir>
       
    19 #include <QFile>
       
    20 #include <QVariantHash>
       
    21 #include <QGraphicsLinearLayout>
       
    22 
       
    23 #include <HbMainWindow>
       
    24 #include <HbIconItem>
       
    25 
       
    26 #include "hswallpaper.h"
       
    27 #include "hsscene.h"
       
    28 #include "hspage.h"
       
    29 #include "hswallpaperloader.h"
       
    30 #include "hsconfiguration.h"
       
    31 #include "hsgui.h"
       
    32 /*!
       
    33 
       
    34 */
       
    35 
       
    36 /*!
       
    37 
       
    38 */
       
    39 HsWallpaper::HsWallpaper(QGraphicsItem *parent)
       
    40   : HbWidget(parent),
       
    41     mIsDefaultImage(false),
       
    42     mIconItem(0)/*,
       
    43     mLoader(0)*/
       
    44 {
       
    45     setFlag(ItemHasNoContents);
       
    46     setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
       
    47 
       
    48     /*
       
    49     mLoader = new HsWallpaperLoader(this);
       
    50     connect(mLoader, SIGNAL(finished()), SLOT(onLoaderFinished()), Qt::UniqueConnection);
       
    51     connect(mLoader, SIGNAL(failed()), SLOT(onLoaderFailed()), Qt::UniqueConnection);
       
    52     */
       
    53 
       
    54     mIconItem = new HbIconItem();
       
    55     QGraphicsLinearLayout *layout = new QGraphicsLinearLayout;
       
    56     layout->setContentsMargins(0, 0, 0, 0);
       
    57     layout->addItem(mIconItem);
       
    58     setLayout(layout);
       
    59 
       
    60     connect(HsGui::instance(),
       
    61         SIGNAL(orientationChanged(Qt::Orientation)),
       
    62         SLOT(updateIconItem(Qt::Orientation)));
       
    63 }
       
    64 
       
    65 /*!
       
    66 
       
    67 */
       
    68 HsWallpaper::~HsWallpaper()
       
    69 {
       
    70 }
       
    71 
       
    72 /*!
       
    73 
       
    74 */
       
    75 void HsWallpaper::setImage(const QString &path)
       
    76 {
       
    77     Q_UNUSED(path);
       
    78 }
       
    79 
       
    80 void HsWallpaper::setImages(const QString &portraitFileName, const QString &landscapeFileName)
       
    81 {
       
    82     Q_UNUSED(portraitFileName)
       
    83     Q_UNUSED(landscapeFileName)
       
    84     emit imageSet();
       
    85 }
       
    86 
       
    87 /*!
       
    88 
       
    89 */
       
    90 void HsWallpaper::setDefaultImage()
       
    91 {
       
    92     if (mIsDefaultImage) {
       
    93         return;
       
    94     }
       
    95 
       
    96     QDir dir(wallpaperDirectory());
       
    97     QStringList filters;
       
    98     filters << "default_portrait.*";
       
    99     filters << "default_landscape.*";
       
   100     QFileInfoList infos = dir.entryInfoList(
       
   101         filters, QDir::Files, QDir::Name | QDir::IgnoreCase);
       
   102 
       
   103     Q_ASSERT(infos.count() == 2);
       
   104 
       
   105     mIsDefaultImage = true;
       
   106     mLandscapeImagePath = infos.first().absoluteFilePath();
       
   107     mPortraitImagePath = infos.last().absoluteFilePath();
       
   108 
       
   109     updateIconItem(HsGui::instance()->orientation());
       
   110 }
       
   111 
       
   112 /*!
       
   113 
       
   114 */
       
   115 void HsWallpaper::remove()
       
   116 {
       
   117     if (mIsDefaultImage) {
       
   118         mIsDefaultImage = false;
       
   119     } else {
       
   120         QFile::remove(mPortraitImagePath);
       
   121         QFile::remove(mLandscapeImagePath);
       
   122     }
       
   123     mPortraitImagePath.clear();
       
   124     mLandscapeImagePath.clear();
       
   125 }
       
   126 
       
   127 /*!
       
   128 
       
   129 */
       
   130 bool HsWallpaper::setExistingImage()
       
   131 {
       
   132     QDir dir(wallpaperDirectory());
       
   133     QStringList filters;
       
   134     filters << QString("%1_portrait.*").arg(mId);
       
   135     filters << QString("%1_landscape.*").arg(mId);
       
   136     QFileInfoList infos = dir.entryInfoList(
       
   137         filters, QDir::Files, QDir::Name | QDir::IgnoreCase);
       
   138 
       
   139     Q_ASSERT(infos.isEmpty() || infos.count() == 2);
       
   140 
       
   141     if (infos.isEmpty()) {
       
   142         return false;
       
   143     }
       
   144 
       
   145     mIsDefaultImage = false;
       
   146     mLandscapeImagePath = infos.first().absoluteFilePath();
       
   147     mPortraitImagePath = infos.last().absoluteFilePath();
       
   148 
       
   149     updateIconItem(HsGui::instance()->orientation());
       
   150     return true;
       
   151 }
       
   152 
       
   153 QString HsWallpaper::rootDirectory() const
       
   154 {
       
   155 #ifdef Q_OS_SYMBIAN
       
   156     QString directory("c:/private/20022f35/wallpapers/");
       
   157 #else
       
   158     QString directory(QDir::currentPath() + "/private/20022f35/wallpapers/");
       
   159 #endif
       
   160 
       
   161 #ifdef HSDOMAINMODEL_TEST
       
   162     directory = QDir::currentPath() + "/wallpapers/";
       
   163 #endif
       
   164     return directory;
       
   165 }
       
   166 
       
   167 /*!
       
   168 
       
   169 */
       
   170 void HsWallpaper::onLoaderFinished()
       
   171 {
       
   172     if (mIsDefaultImage) {
       
   173         mIsDefaultImage = false;
       
   174     } else {
       
   175         QFile::remove(mPortraitImagePath);
       
   176         QFile::remove(mLandscapeImagePath);
       
   177     }
       
   178     foreach (QString path, mLoader->targets().keys()) {
       
   179         QString newName = path; newName.remove("temp");
       
   180         QFile::rename(path, newName);
       
   181     }
       
   182     setExistingImage();
       
   183     emit imageSet();
       
   184 }
       
   185 
       
   186 /*!
       
   187 
       
   188 */
       
   189 void HsWallpaper::onLoaderFailed()
       
   190 {
       
   191     foreach (QString path, mLoader->targets().keys()) {
       
   192         QFile::remove(path);
       
   193     }
       
   194     emit imageSetFailed();
       
   195 }
       
   196 
       
   197 /*!
       
   198 
       
   199 */
       
   200 void HsWallpaper::updateIconItem(Qt::Orientation orientation)
       
   201 {
       
   202     if (orientation == Qt::Vertical) {
       
   203         mIconItem->setIcon(HbIcon(QIcon(mPortraitImagePath)));
       
   204     } else {
       
   205         mIconItem->setIcon(HbIcon(QIcon(mLandscapeImagePath)));
       
   206     }
       
   207 }
       
   208 
       
   209 /*!
       
   210 
       
   211 */
       
   212 HsSceneWallpaper::HsSceneWallpaper(HsScene *scene, QGraphicsItem *parent)
       
   213   : HsWallpaper(parent),
       
   214     mScene(0)
       
   215 {
       
   216     setScene(scene);
       
   217 }
       
   218 
       
   219 /*!
       
   220 
       
   221 */
       
   222 HsSceneWallpaper::~HsSceneWallpaper()
       
   223 {
       
   224 }
       
   225 
       
   226 /*!
       
   227 
       
   228 */
       
   229 void HsSceneWallpaper::setScene(HsScene *scene)
       
   230 {
       
   231     if (!scene) {
       
   232         return;
       
   233     }
       
   234 
       
   235     mScene = scene;
       
   236     mId = scene->databaseId();
       
   237     if (!setExistingImage()) {
       
   238         setDefaultImage();
       
   239     }
       
   240 }
       
   241 
       
   242 /*!
       
   243 
       
   244 */
       
   245 QString HsSceneWallpaper::wallpaperDirectory() const
       
   246 {
       
   247     return QDir::toNativeSeparators(rootDirectory() + "scene/");
       
   248 }
       
   249 
       
   250 /*!
       
   251 
       
   252 */
       
   253 QVariantHash HsSceneWallpaper::createTargets(const QString &sourcePath)
       
   254 {
       
   255     QVariantHash targets;
       
   256 
       
   257     QString path = wallpaperDirectory()
       
   258                    + QString("temp%1_").arg(mId)
       
   259                    + QString("%1.")
       
   260                    + QFileInfo(sourcePath).suffix();
       
   261 
       
   262     targets.insert(path.arg("portrait"), QSize((2 * 360) + HSCONFIGURATION_GET(bounceEffect), 640));
       
   263     targets.insert(path.arg("landscape"), QSize((2 * 640) + HSCONFIGURATION_GET(bounceEffect), 360));
       
   264     return targets;
       
   265 }
       
   266 
       
   267 /*!
       
   268  PAGE
       
   269 */
       
   270 HsPageWallpaper::HsPageWallpaper(HsPage *page, QGraphicsItem *parent)
       
   271   : HsWallpaper(parent),
       
   272     mPage(0)
       
   273 {
       
   274     setPage(page);
       
   275 }
       
   276 
       
   277 /*!
       
   278 
       
   279 */
       
   280 HsPageWallpaper::~HsPageWallpaper()
       
   281 {
       
   282 }
       
   283 
       
   284 /*!
       
   285 
       
   286 */
       
   287 void HsPageWallpaper::setPage(HsPage *page)
       
   288 {
       
   289     if (!page) {
       
   290         return;
       
   291     }
       
   292 
       
   293     mPage = page;
       
   294     mId = page->databaseId();
       
   295     if (!setExistingImage()) {
       
   296         setDefaultImage();
       
   297     }
       
   298 }
       
   299 
       
   300 /*!
       
   301 
       
   302 */
       
   303 QString HsPageWallpaper::wallpaperDirectory() const
       
   304 {
       
   305     return QDir::toNativeSeparators(rootDirectory() + "page/");
       
   306 }
       
   307 
       
   308 /*!
       
   309 
       
   310 */
       
   311 QVariantHash HsPageWallpaper::createTargets(const QString &sourcePath)
       
   312 {
       
   313     QVariantHash targets;
       
   314 
       
   315     QString path = wallpaperDirectory()
       
   316                    + QString("temp%1_").arg(mId)
       
   317                    + QString("%1.")
       
   318                    + QFileInfo(sourcePath).suffix();
       
   319 
       
   320     targets.insert(path.arg("portrait"), QSize(360, 640));
       
   321     targets.insert(path.arg("landscape"), QSize(640, 360));
       
   322     return targets;
       
   323 }
       
   324