ui/commandhandlers/commoncommandhandlers/src/glxcommandhandlereditimage.cpp
author hgs
Sat, 04 Sep 2010 11:36:24 +0530
changeset 62 36d93b4dc635
parent 54 0f0f3f26f787
child 72 0a8e959402e5
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: Handles command related to mediaeditors in fullscreen 
hgs
parents:
diff changeset
    15
* for image Rotate, Crop & Set as Wallpaper
hgs
parents:
diff changeset
    16
*
hgs
parents:
diff changeset
    17
*/
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
#include <glxcommandfactory.h>
52
hgs
parents: 50
diff changeset
    22
hgs
parents: 50
diff changeset
    23
hgs
parents: 50
diff changeset
    24
#ifdef FF_IMAGE_EDITOR
hgs
parents: 50
diff changeset
    25
    #include <photoeditor_highway.hrh>
hgs
parents: 50
diff changeset
    26
#endif //FF_IMAGE_EDITOR
hgs
parents: 50
diff changeset
    27
50
hgs
parents:
diff changeset
    28
#include "glxcommandhandlereditimage.h"
hgs
parents:
diff changeset
    29
#include <glxcommandhandlers.hrh>
hgs
parents:
diff changeset
    30
#include <glxmodelparm.h>
hgs
parents:
diff changeset
    31
#include <glxmediamodel.h>
hgs
parents:
diff changeset
    32
#include <XQServiceRequest.h>
hgs
parents:
diff changeset
    33
#include <XQAiwRequest.h>
hgs
parents:
diff changeset
    34
54
hgs
parents: 52
diff changeset
    35
GlxCommandHandlerEditImage::GlxCommandHandlerEditImage() :
hgs
parents: 52
diff changeset
    36
    mReq(NULL), mMediaModel(NULL)
50
hgs
parents:
diff changeset
    37
    {
hgs
parents:
diff changeset
    38
    //Nothing to do here
hgs
parents:
diff changeset
    39
    }
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
GlxCommandHandlerEditImage::~GlxCommandHandlerEditImage()
hgs
parents:
diff changeset
    42
    {
hgs
parents:
diff changeset
    43
    delete mReq;
hgs
parents:
diff changeset
    44
    mReq = NULL;
54
hgs
parents: 52
diff changeset
    45
    clearMediaModel();
50
hgs
parents:
diff changeset
    46
    }
hgs
parents:
diff changeset
    47
54
hgs
parents: 52
diff changeset
    48
void GlxCommandHandlerEditImage::executeCommand(int commandId,
hgs
parents: 52
diff changeset
    49
        int collectionId, QList<QModelIndex> /*indexList*/)
50
hgs
parents:
diff changeset
    50
    {
hgs
parents:
diff changeset
    51
    const QString service = QLatin1String("PhotoEditor");
hgs
parents:
diff changeset
    52
    const QString interface = QLatin1String("com.nokia.symbian.imageeditor");
hgs
parents:
diff changeset
    53
    const QString operation = QLatin1String("view(QString,int)");
hgs
parents:
diff changeset
    54
    
hgs
parents:
diff changeset
    55
    //Connect to service provider
hgs
parents:
diff changeset
    56
    if(mReq == NULL)
hgs
parents:
diff changeset
    57
        {
hgs
parents:
diff changeset
    58
        mReq = mAppmgr.create(service, interface, operation, true);
hgs
parents:
diff changeset
    59
        mReq->setEmbedded(true);
54
hgs
parents: 52
diff changeset
    60
        mReq->setSynchronous(false);
50
hgs
parents:
diff changeset
    61
        }
hgs
parents:
diff changeset
    62
    
hgs
parents:
diff changeset
    63
    if(mReq == NULL)
hgs
parents:
diff changeset
    64
        {
hgs
parents:
diff changeset
    65
        return;
54
hgs
parents: 52
diff changeset
    66
        } 
hgs
parents: 52
diff changeset
    67
    
hgs
parents: 52
diff changeset
    68
    connect(mReq, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
hgs
parents: 52
diff changeset
    69
    connect(mReq, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
hgs
parents: 52
diff changeset
    70
hgs
parents: 52
diff changeset
    71
    GlxModelParm modelParm(collectionId, 0);
hgs
parents: 52
diff changeset
    72
    clearMediaModel();
hgs
parents: 52
diff changeset
    73
    mMediaModel = new GlxMediaModel(modelParm);
hgs
parents: 52
diff changeset
    74
    if (!mMediaModel)
hgs
parents: 52
diff changeset
    75
        {
hgs
parents: 52
diff changeset
    76
        return;
50
hgs
parents:
diff changeset
    77
        }
hgs
parents:
diff changeset
    78
54
hgs
parents: 52
diff changeset
    79
    connect( mMediaModel, SIGNAL( rowsInserted( QModelIndex, int, int ) ), this, SLOT( storeItems( QModelIndex, int, int ) ) );
hgs
parents: 52
diff changeset
    80
50
hgs
parents:
diff changeset
    81
    //Get the file path for the item selected
54
hgs
parents: 52
diff changeset
    82
    QString imagePath = (mMediaModel->data(
hgs
parents: 52
diff changeset
    83
            mMediaModel->index(mMediaModel->data(mMediaModel->index(0, 0),
hgs
parents: 52
diff changeset
    84
                    GlxFocusIndexRole).value<int> (), 0), GlxUriRole)).value<
hgs
parents: 52
diff changeset
    85
            QString> ();
hgs
parents: 52
diff changeset
    86
    //delete mediaModel;
hgs
parents: 52
diff changeset
    87
50
hgs
parents:
diff changeset
    88
    QList<QVariant> args;
hgs
parents:
diff changeset
    89
    args << imagePath;
52
hgs
parents: 50
diff changeset
    90
#ifdef FF_IMAGE_EDITOR    
54
hgs
parents: 52
diff changeset
    91
    if(EGlxCmdSetWallpaper == commandId)
hgs
parents: 52
diff changeset
    92
        {
hgs
parents: 52
diff changeset
    93
        args << EEditorHighwayWallpaperCrop;
hgs
parents: 52
diff changeset
    94
        }
hgs
parents: 52
diff changeset
    95
    else if(EGlxCmdRotateImgCrop == commandId)
50
hgs
parents:
diff changeset
    96
        {
hgs
parents:
diff changeset
    97
        args << EEditorHighwayFreeCrop;
hgs
parents:
diff changeset
    98
        }
hgs
parents:
diff changeset
    99
    else if(EGlxCmdRotateImgCW == commandId)
hgs
parents:
diff changeset
   100
        {
hgs
parents:
diff changeset
   101
        args << EEditorHighwayRotateCW;
hgs
parents:
diff changeset
   102
        }
hgs
parents:
diff changeset
   103
    else // if(EGlxCmdRotateImgCCW == aCommandId)
54
hgs
parents: 52
diff changeset
   104
50
hgs
parents:
diff changeset
   105
        {
hgs
parents:
diff changeset
   106
        args << EEditorHighwayRotateCCW;
hgs
parents:
diff changeset
   107
        }
hgs
parents:
diff changeset
   108
    mReq->setArguments(args);
52
hgs
parents: 50
diff changeset
   109
#endif //FF_IMAGE_EDITOR
50
hgs
parents:
diff changeset
   110
    // Send the request
hgs
parents:
diff changeset
   111
    bool res = mReq->send();
54
hgs
parents: 52
diff changeset
   112
    if (!res)
50
hgs
parents:
diff changeset
   113
        {
54
hgs
parents: 52
diff changeset
   114
        // Request failed. 
50
hgs
parents:
diff changeset
   115
        }
hgs
parents:
diff changeset
   116
    }
hgs
parents:
diff changeset
   117
54
hgs
parents: 52
diff changeset
   118
void GlxCommandHandlerEditImage::doHandleUserAction(GlxMediaModel* /*model*/,
hgs
parents: 52
diff changeset
   119
        QList<QModelIndex> /*indexList*/) const
hgs
parents: 52
diff changeset
   120
    {
hgs
parents: 52
diff changeset
   121
    //Dummy, to keepup with compiler error
hgs
parents: 52
diff changeset
   122
    }
hgs
parents: 52
diff changeset
   123
hgs
parents: 52
diff changeset
   124
void GlxCommandHandlerEditImage::handleOk(const QVariant& result)
hgs
parents: 52
diff changeset
   125
    {
hgs
parents: 52
diff changeset
   126
    //Nothing to do for - Needs further implementation to refine setting 
hgs
parents: 52
diff changeset
   127
    //default image in fullscreen view
hgs
parents: 52
diff changeset
   128
    }
hgs
parents: 52
diff changeset
   129
hgs
parents: 52
diff changeset
   130
void GlxCommandHandlerEditImage::handleError(int errorCode,
hgs
parents: 52
diff changeset
   131
        const QString& errorMessage)
50
hgs
parents:
diff changeset
   132
    {
54
hgs
parents: 52
diff changeset
   133
    clearMediaModel();
50
hgs
parents:
diff changeset
   134
    }
54
hgs
parents: 52
diff changeset
   135
hgs
parents: 52
diff changeset
   136
void GlxCommandHandlerEditImage::storeItems(const QModelIndex &parent,
hgs
parents: 52
diff changeset
   137
        int aStartRow, int aEndRow)
hgs
parents: 52
diff changeset
   138
    {
hgs
parents: 52
diff changeset
   139
    //This implementation assumes that we will be getting only one new 
hgs
parents: 52
diff changeset
   140
    //image creation notification. Needs refined implementation 
hgs
parents: 52
diff changeset
   141
    if (mMediaModel)
hgs
parents: 52
diff changeset
   142
        {
hgs
parents: 52
diff changeset
   143
        QModelIndex modelIndex = mMediaModel->index(aStartRow, 0);
hgs
parents: 52
diff changeset
   144
        mMediaModel->setData(modelIndex, modelIndex.row(), GlxFocusIndexRole);
hgs
parents: 52
diff changeset
   145
        }
hgs
parents: 52
diff changeset
   146
    }
hgs
parents: 52
diff changeset
   147
hgs
parents: 52
diff changeset
   148
void GlxCommandHandlerEditImage::clearMediaModel()
hgs
parents: 52
diff changeset
   149
    {
hgs
parents: 52
diff changeset
   150
    if (mMediaModel)
hgs
parents: 52
diff changeset
   151
        {
hgs
parents: 52
diff changeset
   152
        disconnect(mMediaModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(storeItems(QModelIndex,int,int)));
hgs
parents: 52
diff changeset
   153
        delete mMediaModel;
hgs
parents: 52
diff changeset
   154
        mMediaModel = NULL;
hgs
parents: 52
diff changeset
   155
        }
hgs
parents: 52
diff changeset
   156
    }