ui/commandhandlers/commoncommandhandlers/src/glxcommandhandlerrename.cpp
author hgs
Thu, 14 Oct 2010 17:54:23 +0530
changeset 72 0a8e959402e5
parent 62 36d93b4dc635
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
62
hgs
parents: 45
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents: 45
diff changeset
     3
 * All rights reserved.
hgs
parents: 45
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents: 45
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents: 45
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents: 45
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents: 45
diff changeset
     8
 *
hgs
parents: 45
diff changeset
     9
 * Initial Contributors:
hgs
parents: 45
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents: 45
diff changeset
    11
 *
hgs
parents: 45
diff changeset
    12
 * Contributors:
hgs
parents: 45
diff changeset
    13
 *
hgs
parents: 45
diff changeset
    14
 * Description: 
hgs
parents: 45
diff changeset
    15
 *
hgs
parents: 45
diff changeset
    16
 */
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
62
hgs
parents: 45
diff changeset
    18
//Includes Qt/Symbian
hgs
parents: 45
diff changeset
    19
#include <QFile>
hgs
parents: 45
diff changeset
    20
#include <caf/manager.h>
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
62
hgs
parents: 45
diff changeset
    22
//Includes Orbit
hgs
parents: 45
diff changeset
    23
#include <hblabel.h>
hgs
parents: 45
diff changeset
    24
#include <hbmessagebox.h>
hgs
parents: 45
diff changeset
    25
hgs
parents: 45
diff changeset
    26
//User Includes
hgs
parents: 45
diff changeset
    27
#include <mglxmedialist.h>
hgs
parents: 45
diff changeset
    28
#include <glxcommondialogs.h>
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
#include <mpxcollectionpath.h>
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
#include <glxcommandfactory.h>
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
#include <glxattributecontext.h>
62
hgs
parents: 45
diff changeset
    32
#include <glxcommandhandlers.hrh>
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
#include <glxattributeretriever.h>
62
hgs
parents: 45
diff changeset
    34
#include "glxlocalisationstrings.h"
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
#include <glxfetchcontextremover.h>
62
hgs
parents: 45
diff changeset
    36
#include <glxcommandhandlerrename.h>   
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
GlxCommandHandlerRename::GlxCommandHandlerRename()
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
    {
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    40
    }
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
GlxCommandHandlerRename::~GlxCommandHandlerRename()
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
    {
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
    }
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
CMPXCommand* GlxCommandHandlerRename::CreateCommandL(TInt aCommandId,
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
        MGlxMediaList& aMediaList, TBool& aConsume) const
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
    {
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
    Q_UNUSED(aCommandId);
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
    Q_UNUSED(aConsume);
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    51
    
62
hgs
parents: 45
diff changeset
    52
    bool ok = false;
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
    CMPXCommand* command = NULL;
62
hgs
parents: 45
diff changeset
    54
    CMPXCollectionPath* path = NULL;
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
    QString mainPane = GetName(aMediaList);
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
    GlxTextInputDialog* dlg = new GlxTextInputDialog();
62
hgs
parents: 45
diff changeset
    57
hgs
parents: 45
diff changeset
    58
    if (aCommandId == EGlxCmdRenameFile)
hgs
parents: 45
diff changeset
    59
        {
hgs
parents: 45
diff changeset
    60
        mMediaTitle = dlg->getText(GLX_DIALOG_NAME_PROMPT, mainPane, &ok);
hgs
parents: 45
diff changeset
    61
        }
hgs
parents: 45
diff changeset
    62
    else
hgs
parents: 45
diff changeset
    63
        {
hgs
parents: 45
diff changeset
    64
        mMediaTitle = dlg->getText(GLX_DIALOG_ALBUM_PROMPT, mainPane, &ok);
hgs
parents: 45
diff changeset
    65
        }
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
    delete dlg;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
    if(ok == true)
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
        {
62
hgs
parents: 45
diff changeset
    70
        TPtrC16 newMediaItemTitleDes =
hgs
parents: 45
diff changeset
    71
                (reinterpret_cast<const TUint16*> (mMediaTitle.utf16()));
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
        HBufC* newMediaItemTitle = newMediaItemTitleDes.Alloc();
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    73
        CleanupStack::PushL(newMediaItemTitle);
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    74
62
hgs
parents: 45
diff changeset
    75
        if (aCommandId == EGlxCmdRenameFile)
hgs
parents: 45
diff changeset
    76
            {
hgs
parents: 45
diff changeset
    77
            TDesC& aTitleText = *newMediaItemTitle;
hgs
parents: 45
diff changeset
    78
            TInt index = aMediaList.FocusIndex();
hgs
parents: 45
diff changeset
    79
            const TGlxMedia& media = aMediaList.Item(index);
hgs
parents: 45
diff changeset
    80
            TParsePtrC parsePtr(media.Uri());
hgs
parents: 45
diff changeset
    81
hgs
parents: 45
diff changeset
    82
            //Constructs the File Name with complete Path
hgs
parents: 45
diff changeset
    83
            TFileName destinationFileName;
hgs
parents: 45
diff changeset
    84
            destinationFileName.Append(parsePtr.DriveAndPath());
hgs
parents: 45
diff changeset
    85
            destinationFileName.Append(aTitleText);
hgs
parents: 45
diff changeset
    86
            destinationFileName.Append(parsePtr.Ext());
hgs
parents: 45
diff changeset
    87
hgs
parents: 45
diff changeset
    88
            HBufC* modifiedName = destinationFileName.AllocLC();
hgs
parents: 45
diff changeset
    89
            QString fileName = QString::fromUtf16(modifiedName->Ptr(),
hgs
parents: 45
diff changeset
    90
                    modifiedName->Length());
hgs
parents: 45
diff changeset
    91
hgs
parents: 45
diff changeset
    92
            ContentAccess::CManager *manager =
hgs
parents: 45
diff changeset
    93
                    ContentAccess::CManager::NewL();
hgs
parents: 45
diff changeset
    94
            CleanupStack::PushL(manager);
hgs
parents: 45
diff changeset
    95
hgs
parents: 45
diff changeset
    96
            QFile filePath(fileName);
hgs
parents: 45
diff changeset
    97
            bool isFileExist = filePath.exists();
hgs
parents: 45
diff changeset
    98
hgs
parents: 45
diff changeset
    99
            if (!isFileExist)
hgs
parents: 45
diff changeset
   100
                {
hgs
parents: 45
diff changeset
   101
                //rename the media
hgs
parents: 45
diff changeset
   102
                TInt error = manager->RenameFile(media.Uri(), *modifiedName);
72
hgs
parents: 62
diff changeset
   103
				//reset the flag to 'false'!
hgs
parents: 62
diff changeset
   104
                iIsCmdActive = false;
hgs
parents: 62
diff changeset
   105
                
hgs
parents: 62
diff changeset
   106
				/*
hgs
parents: 62
diff changeset
   107
				1. Photos renames the file with file system services
hgs
parents: 62
diff changeset
   108
                2. Photos tries to update the title of the renamed images
hgs
parents: 62
diff changeset
   109
                -> Image object is opened for modifications
hgs
parents: 62
diff changeset
   110
                3. MDS gets notification from the file server that the image has been renamed
hgs
parents: 62
diff changeset
   111
                -> Handling this fails with -22 KErrLocked as the same object is opened
hgs
parents: 62
diff changeset
   112
                by Photos for changing the title
hgs
parents: 62
diff changeset
   113
                -> MDS cannot update the the URI or Title for locked object
hgs
parents: 62
diff changeset
   114
                4. Photos completes updating the title
hgs
parents: 62
diff changeset
   115
                -> title for xxx.jpg is set as A, but the uri is still xxx.jpg in
hgs
parents: 62
diff changeset
   116
                MDS DB as MDS could not modify the object--
hgs
parents: 62
diff changeset
   117
				So Removing the manually changing of the title completely.
hgs
parents: 62
diff changeset
   118
				As MDS will update the title field automatically if it was originally
hgs
parents: 62
diff changeset
   119
				populated from the uri, changing the title manually after rename is complitely
hgs
parents: 62
diff changeset
   120
				unnecessary anyway. So let MDS do the updating by itself as it should,
hgs
parents: 62
diff changeset
   121
				and you will still get modified event from MDS when the update, including
hgs
parents: 62
diff changeset
   122
				the title, is complete
hgs
parents: 62
diff changeset
   123
                */
hgs
parents: 62
diff changeset
   124
				/*
hgs
parents: 62
diff changeset
   125
				if (error == KErrNone)
62
hgs
parents: 45
diff changeset
   126
                    {
hgs
parents: 45
diff changeset
   127
                    path = aMediaList.PathLC(
hgs
parents: 45
diff changeset
   128
                            NGlxListDefs::EPathFocusOrSelection);
hgs
parents: 45
diff changeset
   129
                    command = TGlxCommandFactory::RenameCommandLC(
hgs
parents: 45
diff changeset
   130
                            *newMediaItemTitle, *path);
hgs
parents: 45
diff changeset
   131
                    CleanupStack::Pop(command);
hgs
parents: 45
diff changeset
   132
                    CleanupStack::PopAndDestroy(path);
72
hgs
parents: 62
diff changeset
   133
                    }*/
62
hgs
parents: 45
diff changeset
   134
                }
hgs
parents: 45
diff changeset
   135
            else
hgs
parents: 45
diff changeset
   136
                {
hgs
parents: 45
diff changeset
   137
                //The Name of the file name already exists, display an message .
hgs
parents: 45
diff changeset
   138
                HandleErrorL(KErrAlreadyExists);
hgs
parents: 45
diff changeset
   139
                }
hgs
parents: 45
diff changeset
   140
            CleanupStack::PopAndDestroy(manager);
hgs
parents: 45
diff changeset
   141
            CleanupStack::PopAndDestroy(modifiedName);
hgs
parents: 45
diff changeset
   142
            CleanupStack::PopAndDestroy(newMediaItemTitle);
hgs
parents: 45
diff changeset
   143
            }
hgs
parents: 45
diff changeset
   144
        else
hgs
parents: 45
diff changeset
   145
            {
hgs
parents: 45
diff changeset
   146
            //Rename of Album
hgs
parents: 45
diff changeset
   147
            CMPXCollectionPath* path = aMediaList.PathLC(
hgs
parents: 45
diff changeset
   148
                    NGlxListDefs::EPathFocusOrSelection);
hgs
parents: 45
diff changeset
   149
            command = TGlxCommandFactory::RenameCommandLC(*newMediaItemTitle,
hgs
parents: 45
diff changeset
   150
                    *path);
hgs
parents: 45
diff changeset
   151
            CleanupStack::Pop(command);
hgs
parents: 45
diff changeset
   152
            CleanupStack::PopAndDestroy(path);
hgs
parents: 45
diff changeset
   153
            CleanupStack::PopAndDestroy(newMediaItemTitle);
hgs
parents: 45
diff changeset
   154
            }
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   155
        }
72
hgs
parents: 62
diff changeset
   156
    else
hgs
parents: 62
diff changeset
   157
        {
hgs
parents: 62
diff changeset
   158
		// If cancel is pressed, reset the flag!!
hgs
parents: 62
diff changeset
   159
        iIsCmdActive = false;
hgs
parents: 62
diff changeset
   160
        }
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   161
    return command;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   162
    }
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   163
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
QString GlxCommandHandlerRename::CompletionTextL() const
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   165
    {
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
	//return command completion text
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
	return QString();
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   168
    }
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   169
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   170
QString GlxCommandHandlerRename::GetName(MGlxMediaList& aMediaList) const
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
    {
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   172
        // Create an iterator to retrieve the relevant attribute
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   173
    TGlxSelectionIterator iterator;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   174
    // only want the title of one item
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   175
	iterator.SetRange( 1 );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   176
    CGlxAttributeContext* context = new( ELeave )
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   177
        CGlxAttributeContext( &iterator );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   178
	CleanupStack::PushL( context );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   179
        
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   180
	// Want to read the title attribute    
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   181
    // Configure the context
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   182
	context->AddAttributeL( KMPXMediaGeneralTitle );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   183
	
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   184
	// Add the context to the media list
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   185
	aMediaList.AddContextL( context, KGlxFetchContextPriorityBlocking );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   186
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   187
    // TGlxContextRemover will remove the context when it goes out of scope
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   188
    // Used here to avoid a trap and still have safe cleanup    
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   189
    TGlxFetchContextRemover contextRemover( context, aMediaList );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   190
    // put to cleanupstack as cleanupstack is emptied before stack objects
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   191
    // are deleted
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   192
    CleanupClosePushL( contextRemover );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   193
	// Yuck - a leave and a return code!
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   194
	// EFalse => don't show a progress dialog
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   195
    TInt err = GlxAttributeRetriever::RetrieveL( *context, aMediaList, EFalse );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   196
    // Using a distinct error value as "LeaveIfError( FuncL() );" looks bad
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   197
    User::LeaveIfError( err );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   198
    // context off the list
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   199
    CleanupStack::PopAndDestroy( &contextRemover );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   200
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   201
    // Now get the title of the relevant item: if *an* item is selected use its
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   202
    // title, otherwise use the item with focus
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   203
	// Get the index of the item to rename
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   204
    TInt index = KErrNotFound;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   205
    QString title = NULL;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   206
	// first see if there's a selected item...
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   207
    if ( aMediaList.SelectionCount() == 1 )
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   208
    	{
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   209
        // Find the index of the selected item
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   210
    	index = aMediaList.Count();
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   211
    	do
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   212
            {
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   213
            --index;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   214
            }
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   215
        while ( !aMediaList.IsSelected( index ) && index > 0 );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   216
    	}
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   217
    else
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
    	{
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
    	// Use the index of the item with focus
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   220
       	index = aMediaList.FocusIndex();
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   221
    	}
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   222
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   223
	if ( index != KErrNotFound )
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   224
		{
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   225
        // use iterator to get the right item
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   226
        iterator.SetToFirst( &aMediaList );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   227
        const CGlxMedia* media = aMediaList.Item( iterator++ ).Properties();
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   228
		if( media )
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   229
			{
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   230
			// found the item's media properties, extract the title
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   231
            const TDesC& titleDesc = media->ValueText(KMPXMediaGeneralTitle);
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   232
            title = QString::fromUtf16(titleDesc.Ptr(),
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   233
                    titleDesc.Length());
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   234
			}
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   235
		}
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   236
    CleanupStack::PopAndDestroy( context );
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   237
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   238
    return title;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   239
    }
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   240
62
hgs
parents: 45
diff changeset
   241
void GlxCommandHandlerRename::HandleErrorL(TInt aErrorCode) const
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   242
	{
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   243
    if(aErrorCode == KErrAlreadyExists)
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   244
        {
62
hgs
parents: 45
diff changeset
   245
        QString stringToDisplay = hbTrId(GLX_NAME_ALREADY_EXIST).arg(
hgs
parents: 45
diff changeset
   246
                mMediaTitle);
hgs
parents: 45
diff changeset
   247
        HbMessageBox::warning(stringToDisplay);
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   248
        }
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   249
	else{
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   250
		GlxMpxCommandHandler::HandleErrorL(aErrorCode);
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   251
		}	
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   252
	}
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   253