ui/commandhandlers/commoncommandhandlers/src/glxcommandhandlerrename.cpp
changeset 62 36d93b4dc635
parent 45 863223ea6961
child 72 0a8e959402e5
equal deleted inserted replaced
58:383b67fbdb11 62:36d93b4dc635
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description: 
    14  * Description: 
    15 *
    15  *
    16 */
    16  */
    17 
    17 
       
    18 //Includes Qt/Symbian
       
    19 #include <QFile>
       
    20 #include <caf/manager.h>
       
    21 
       
    22 //Includes Orbit
       
    23 #include <hblabel.h>
    18 #include <hbmessagebox.h>
    24 #include <hbmessagebox.h>
    19 #include <hblabel.h>
    25 
    20 
    26 //User Includes
       
    27 #include <mglxmedialist.h>
       
    28 #include <glxcommondialogs.h>
    21 #include <mpxcollectionpath.h>
    29 #include <mpxcollectionpath.h>
    22 #include <mglxmedialist.h>
       
    23 #include <glxcommandfactory.h>
    30 #include <glxcommandfactory.h>
    24 #include <glxcommandhandlerrename.h>
       
    25 #include <glxattributecontext.h>
    31 #include <glxattributecontext.h>
       
    32 #include <glxcommandhandlers.hrh>
    26 #include <glxattributeretriever.h>
    33 #include <glxattributeretriever.h>
       
    34 #include "glxlocalisationstrings.h"
    27 #include <glxfetchcontextremover.h>
    35 #include <glxfetchcontextremover.h>
    28 #include <glxcommondialogs.h>
    36 #include <glxcommandhandlerrename.h>   
    29 #include "glxlocalisationstrings.h"
       
    30 
    37 
    31 GlxCommandHandlerRename::GlxCommandHandlerRename()
    38 GlxCommandHandlerRename::GlxCommandHandlerRename()
    32     {
    39     {
    33     }
    40     }
    34 
    41 
    40         MGlxMediaList& aMediaList, TBool& aConsume) const
    47         MGlxMediaList& aMediaList, TBool& aConsume) const
    41     {
    48     {
    42     Q_UNUSED(aCommandId);
    49     Q_UNUSED(aCommandId);
    43     Q_UNUSED(aConsume);
    50     Q_UNUSED(aConsume);
    44     
    51     
       
    52     bool ok = false;
    45     CMPXCommand* command = NULL;
    53     CMPXCommand* command = NULL;
       
    54     CMPXCollectionPath* path = NULL;
    46     QString mainPane = GetName(aMediaList);
    55     QString mainPane = GetName(aMediaList);
    47     QString mediaTitle = NULL;
       
    48     bool ok = false;    
       
    49     GlxTextInputDialog* dlg = new GlxTextInputDialog();
    56     GlxTextInputDialog* dlg = new GlxTextInputDialog();
    50     mediaTitle = dlg->getText(GLX_DIALOG_NAME_PROMPT, mainPane, &ok);
    57 
       
    58     if (aCommandId == EGlxCmdRenameFile)
       
    59         {
       
    60         mMediaTitle = dlg->getText(GLX_DIALOG_NAME_PROMPT, mainPane, &ok);
       
    61         }
       
    62     else
       
    63         {
       
    64         mMediaTitle = dlg->getText(GLX_DIALOG_ALBUM_PROMPT, mainPane, &ok);
       
    65         }
    51     delete dlg;
    66     delete dlg;
    52 
    67 
    53     if(ok == true)
    68     if(ok == true)
    54         {
    69         {
    55         TPtrC16 newMediaItemTitleDes
    70         TPtrC16 newMediaItemTitleDes =
    56             = (reinterpret_cast<const TUint16*> (mediaTitle.utf16()));
    71                 (reinterpret_cast<const TUint16*> (mMediaTitle.utf16()));
    57 
       
    58         HBufC* newMediaItemTitle = newMediaItemTitleDes.Alloc();
    72         HBufC* newMediaItemTitle = newMediaItemTitleDes.Alloc();
    59         CleanupStack::PushL(newMediaItemTitle);
    73         CleanupStack::PushL(newMediaItemTitle);
    60 
    74 
    61         CMPXCollectionPath* path = aMediaList.PathLC(
    75         if (aCommandId == EGlxCmdRenameFile)
    62                 NGlxListDefs::EPathFocusOrSelection);
    76             {
    63         command = 
    77             TDesC& aTitleText = *newMediaItemTitle;
    64             TGlxCommandFactory::RenameCommandLC(*newMediaItemTitle,*path);
    78             TInt index = aMediaList.FocusIndex();
    65         CleanupStack::Pop(command);
    79             const TGlxMedia& media = aMediaList.Item(index);
    66         CleanupStack::PopAndDestroy(path);
    80             TParsePtrC parsePtr(media.Uri());
    67         CleanupStack::PopAndDestroy(newMediaItemTitle);
    81 
       
    82             //Constructs the File Name with complete Path
       
    83             TFileName destinationFileName;
       
    84             destinationFileName.Append(parsePtr.DriveAndPath());
       
    85             destinationFileName.Append(aTitleText);
       
    86             destinationFileName.Append(parsePtr.Ext());
       
    87 
       
    88             HBufC* modifiedName = destinationFileName.AllocLC();
       
    89             QString fileName = QString::fromUtf16(modifiedName->Ptr(),
       
    90                     modifiedName->Length());
       
    91 
       
    92             ContentAccess::CManager *manager =
       
    93                     ContentAccess::CManager::NewL();
       
    94             CleanupStack::PushL(manager);
       
    95 
       
    96             QFile filePath(fileName);
       
    97             bool isFileExist = filePath.exists();
       
    98 
       
    99             if (!isFileExist)
       
   100                 {
       
   101                 //rename the media
       
   102                 TInt error = manager->RenameFile(media.Uri(), *modifiedName);
       
   103 
       
   104                 if (error == KErrNone)
       
   105                     {
       
   106                     path = aMediaList.PathLC(
       
   107                             NGlxListDefs::EPathFocusOrSelection);
       
   108                     command = TGlxCommandFactory::RenameCommandLC(
       
   109                             *newMediaItemTitle, *path);
       
   110                     CleanupStack::Pop(command);
       
   111                     CleanupStack::PopAndDestroy(path);
       
   112                     }
       
   113                 }
       
   114             else
       
   115                 {
       
   116                 //The Name of the file name already exists, display an message .
       
   117                 HandleErrorL(KErrAlreadyExists);
       
   118                 }
       
   119             CleanupStack::PopAndDestroy(manager);
       
   120             CleanupStack::PopAndDestroy(modifiedName);
       
   121             CleanupStack::PopAndDestroy(newMediaItemTitle);
       
   122             }
       
   123         else
       
   124             {
       
   125             //Rename of Album
       
   126             CMPXCollectionPath* path = aMediaList.PathLC(
       
   127                     NGlxListDefs::EPathFocusOrSelection);
       
   128             command = TGlxCommandFactory::RenameCommandLC(*newMediaItemTitle,
       
   129                     *path);
       
   130             CleanupStack::Pop(command);
       
   131             CleanupStack::PopAndDestroy(path);
       
   132             CleanupStack::PopAndDestroy(newMediaItemTitle);
       
   133             }
    68         }
   134         }
    69     return command;
   135     return command;
    70     }
   136     }
    71 
   137 
    72 QString GlxCommandHandlerRename::CompletionTextL() const
   138 QString GlxCommandHandlerRename::CompletionTextL() const
   144     CleanupStack::PopAndDestroy( context );
   210     CleanupStack::PopAndDestroy( context );
   145 
   211 
   146     return title;
   212     return title;
   147     }
   213     }
   148 
   214 
   149 void GlxCommandHandlerRename::HandleErrorL(TInt aErrorCode)
   215 void GlxCommandHandlerRename::HandleErrorL(TInt aErrorCode) const
   150 	{
   216 	{
   151     if(aErrorCode == KErrAlreadyExists)
   217     if(aErrorCode == KErrAlreadyExists)
   152         {
   218         {
   153         HbMessageBox::warning("Name Already Exist!!!", new HbLabel(
   219         QString stringToDisplay = hbTrId(GLX_NAME_ALREADY_EXIST).arg(
   154                 "Rename"));
   220                 mMediaTitle);
       
   221         HbMessageBox::warning(stringToDisplay);
   155         }
   222         }
   156 	else{
   223 	else{
   157 		GlxMpxCommandHandler::HandleErrorL(aErrorCode);
   224 		GlxMpxCommandHandler::HandleErrorL(aErrorCode);
   158 		}	
   225 		}	
   159 	}
   226 	}