ui/commandhandlers/commoncommandhandlers/src/glxcommandhandleraddtocontainer.cpp
changeset 50 a0f57508af73
parent 45 863223ea6961
child 54 0f0f3f26f787
equal deleted inserted replaced
45:863223ea6961 50:a0f57508af73
    33 
    33 
    34 #include <hblistwidget.h>
    34 #include <hblistwidget.h>
    35 #include <hbview.h>
    35 #include <hbview.h>
    36 #include <hbpushbutton.h>
    36 #include <hbpushbutton.h>
    37 #include <QGraphicsGridLayout>
    37 #include <QGraphicsGridLayout>
    38 #include <hbdialog.h>
    38 #include <hbselectiondialog.h>
       
    39 
    39 #include <hbmessagebox.h>
    40 #include <hbmessagebox.h>
    40 
    41 
    41 #include <glxcommandhandlers.hrh>
    42 #include <glxcommandhandlers.hrh>
    42 #include "glxlocalisationstrings.h"
    43 #include "glxlocalisationstrings.h"
    43 
    44 
    45 #ifdef OST_TRACE_COMPILER_IN_USE
    46 #ifdef OST_TRACE_COMPILER_IN_USE
    46 #include "glxcommandhandleraddtocontainerTraces.h"
    47 #include "glxcommandhandleraddtocontainerTraces.h"
    47 #endif
    48 #endif
    48 
    49 
    49 
    50 
    50 TInt GlxCommandHandlerAddToContainer::iSelectionCount = 0;
       
    51 
       
    52 const TInt KSelectionPopupListHierarchy = 5;
    51 const TInt KSelectionPopupListHierarchy = 5;
    53 const TInt KListPrefferedHeight = 400;
       
    54 
    52 
    55 GlxAlbumSelectionPopup::GlxAlbumSelectionPopup() 
    53 GlxAlbumSelectionPopup::GlxAlbumSelectionPopup() 
    56     : mPopupDlg( 0 ), 
    54     : mSelectionModel( 0 ),
    57       mSelectionModel( 0 ),
       
    58       mEventLoop( 0 ),
    55       mEventLoop( 0 ),
    59       mResult( false )
    56       mResult( false )
    60 {
    57 {
    61 }
    58 }
    62 
    59 
    64 {
    61 {
    65 }
    62 }
    66 
    63 
    67 QModelIndexList GlxAlbumSelectionPopup::GetSelectionList(GlxAlbumModel *model, bool *ok) 
    64 QModelIndexList GlxAlbumSelectionPopup::GetSelectionList(GlxAlbumModel *model, bool *ok) 
    68 {
    65 {
    69     // Create a popup
    66     HbSelectionDialog *dlg = new HbSelectionDialog;
    70     HbDialog popup;
    67 	dlg->setHeadingWidget(new HbLabel(GLX_ALBUM_SELECTION_TITLE));
       
    68     dlg->setSelectionMode(HbAbstractItemView::SingleSelection);
       
    69     dlg->setModel(model);
       
    70     dlg->setAttribute(Qt::WA_DeleteOnClose);
       
    71     dlg->clearActions();
       
    72     HbAction *action;
       
    73     action= new HbAction(GLX_BUTTON_NEW);
       
    74     action->setObjectName( "ch_new_album_button" );
       
    75     dlg->addAction(action);
       
    76     action= new HbAction(GLX_BUTTON_CANCEL);
       
    77     action->setObjectName( "ch_cancel_album_button" );
       
    78     dlg->addAction(action);
       
    79     dlg->open(this, SLOT(dialogClosed(HbAction*)));
       
    80     
    71     QEventLoop eventLoop;
    81     QEventLoop eventLoop;
    72     mEventLoop = &eventLoop;
    82     mEventLoop = &eventLoop;
    73     
    83   
    74     popup.setPreferredHeight( KListPrefferedHeight );
       
    75     // Set dismiss policy that determines what tap events will cause the popup
       
    76     // to be dismissed
       
    77     popup.setDismissPolicy(HbDialog::NoDismiss);
       
    78 
       
    79     // Set timeout to zero to wait user to either click Ok or Cancel
       
    80     popup.setTimeout(HbDialog::NoTimeout);
       
    81     popup.setHeadingWidget( new HbLabel("Select Album") );      
       
    82     
       
    83     mPopupDlg = &popup;
       
    84     HbListView *listview = new HbListView();
       
    85     listview->setSelectionMode(HbAbstractItemView::MultiSelection);
       
    86     listview->setModel(model);
       
    87     mSelectionModel = listview->selectionModel() ;
       
    88     connect( mSelectionModel, SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection& ) ), this, SLOT( changeButtonText() ) );
       
    89     
       
    90     HbAction *primary = new HbAction( "New" );
       
    91     primary->setObjectName( "Cmd New" );
       
    92     popup.addAction( primary ) ;
       
    93 
       
    94     HbAction *secondary = new HbAction( GLX_BUTTON_CANCEL );
       
    95     secondary->setObjectName( "Cmd Cancel" );
       
    96     popup.addAction( secondary );
       
    97     
       
    98     popup.setContentWidget( listview ); //ownership transfer
       
    99     listview->show();
       
   100     
       
   101     popup.open( this, SLOT( dialogClosed( HbAction* ) ) ); 
       
   102     eventLoop.exec( );
    84     eventLoop.exec( );
   103     mEventLoop = 0 ;
    85     mEventLoop = 0 ;
   104     if ( ok ) {
    86     if ( ok ) {
   105         *ok = mResult ;
    87         *ok = mResult ;
   106     }
    88     }
   107     QModelIndexList selectedIndexes = mSelectionModel->selectedIndexes();       
    89 
   108     disconnect( mSelectionModel, SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection& ) ), this, SLOT( changeButtonText() ) );
    90     QModelIndexList selectedIndexes = dlg->selectedModelIndexes();
   109     delete primary;
       
   110     delete secondary;
       
   111 
       
   112     return selectedIndexes;
    91     return selectedIndexes;
   113 }
    92 }
   114 
    93 
   115 void GlxAlbumSelectionPopup::changeButtonText()
    94 
   116 {
    95 void GlxAlbumSelectionPopup::dialogClosed(HbAction *action)
   117     if ( mSelectionModel->selectedIndexes().count() ) {
    96 {
   118         mPopupDlg->actions().first()->setText( GLX_BUTTON_OK );
    97     HbSelectionDialog *dlg = (HbSelectionDialog*)(sender());
       
    98 
       
    99     if( action == dlg->actions().at(1) ) {
       
   100         mResult = false ;
   119     }
   101     }
   120     else {
   102     else {
   121         mPopupDlg->actions().first()->setText("New");
       
   122     }    
       
   123 }
       
   124 
       
   125 
       
   126 void GlxAlbumSelectionPopup::dialogClosed(HbAction *action)
       
   127 {
       
   128     HbDialog *dlg = static_cast<HbDialog*>(sender());
       
   129     if( action == dlg->actions().first() ) {
       
   130         mResult = true ;
   103         mResult = true ;
   131     }
       
   132     else {
       
   133         mResult = false ;
       
   134     }
   104     }
   135     if ( mEventLoop && mEventLoop->isRunning( ) ) {
   105     if ( mEventLoop && mEventLoop->isRunning( ) ) {
   136         mEventLoop->exit( 0 );
   106         mEventLoop->exit( 0 );
   137     }
   107     }
   138 }
   108 }
   139 
   109 
   140 GlxCommandHandlerAddToContainer::GlxCommandHandlerAddToContainer() :
   110 GlxCommandHandlerAddToContainer::GlxCommandHandlerAddToContainer() :
   141     mNewMediaAdded(false)
   111     mNewMediaAdded(false),mAlbumName(QString())
   142     {
   112     {
   143     OstTraceFunctionEntry0( GLXCOMMANDHANDLERADDTOCONTAINER_GLXCOMMANDHANDLERADDTOCONTAINER_ENTRY );
   113     OstTraceFunctionEntry0( GLXCOMMANDHANDLERADDTOCONTAINER_GLXCOMMANDHANDLERADDTOCONTAINER_ENTRY );
   144     mTargetContainers = NULL;
   114     mTargetContainers = NULL;
   145     OstTraceFunctionExit0( GLXCOMMANDHANDLERADDTOCONTAINER_GLXCOMMANDHANDLERADDTOCONTAINER_EXIT );
   115     OstTraceFunctionExit0( GLXCOMMANDHANDLERADDTOCONTAINER_GLXCOMMANDHANDLERADDTOCONTAINER_EXIT );
   146     }
   116     }
   154 
   124 
   155 CMPXCommand* GlxCommandHandlerAddToContainer::CreateCommandL(TInt aCommandId,
   125 CMPXCommand* GlxCommandHandlerAddToContainer::CreateCommandL(TInt aCommandId,
   156         MGlxMediaList& aMediaList, TBool& /*aConsume*/) const
   126         MGlxMediaList& aMediaList, TBool& /*aConsume*/) const
   157     {
   127     {
   158     OstTraceFunctionEntry0( GLXCOMMANDHANDLERADDTOCONTAINER_CREATECOMMANDL_ENTRY );
   128     OstTraceFunctionEntry0( GLXCOMMANDHANDLERADDTOCONTAINER_CREATECOMMANDL_ENTRY );
   159     iSelectionCount = 0;
       
   160     CMPXCommand* command = NULL;
   129     CMPXCommand* command = NULL;
   161 
   130     mAlbumName.clear();
   162     if(aCommandId == EGlxCmdAddToFav)
   131     if(aCommandId == EGlxCmdAddToFav)
   163         {
   132         {
       
   133 		   mAlbumName = GLX_SUBTITLE_MYFAV_GRIDVIEW;
   164            CMPXCollectionPath* targetCollection = CMPXCollectionPath::NewL();
   134            CMPXCollectionPath* targetCollection = CMPXCollectionPath::NewL();
   165            CleanupStack::PushL(targetCollection);
   135            CleanupStack::PushL(targetCollection);
   166            // The target collection has to be appeneded with the albums plugin id
   136            // The target collection has to be appeneded with the albums plugin id
   167            targetCollection->AppendL(KGlxCollectionPluginAlbumsImplementationUid);
   137            targetCollection->AppendL(KGlxCollectionPluginAlbumsImplementationUid);
   168            // The target collection has also to be appeneded with the the relation id.
   138            // The target collection has also to be appeneded with the the relation id.
   233                             NGlxListDefs::EPathFocusOrSelection);
   203                             NGlxListDefs::EPathFocusOrSelection);
   234                     CleanupStack::Pop(targetContainers);
   204                     CleanupStack::Pop(targetContainers);
   235                     delete mTargetContainers;
   205                     delete mTargetContainers;
   236                     mTargetContainers = NULL;
   206                     mTargetContainers = NULL;
   237                     mTargetContainers = targetContainers;
   207                     mTargetContainers = targetContainers;
       
   208 
       
   209 					const TGlxMedia& item = targetMediaList->Item(targetMediaList->SelectedItemIndex(0));
       
   210 					const TDesC& title = item.Title();
       
   211 					mAlbumName = QString::fromUtf16(title.Ptr(),title.Length());
   238                     }
   212                     }
   239     
   213     
   240                 command = TGlxCommandFactory::AddToContainerCommandLC(*sourceItems,
   214                 command = TGlxCommandFactory::AddToContainerCommandLC(*sourceItems,
   241                         *mTargetContainers);
   215                         *mTargetContainers);
   242                 CleanupStack::Pop(command);
   216                 CleanupStack::Pop(command);
   260     {
   234     {
   261     OstTraceFunctionEntry0( GLXCOMMANDHANDLERADDTOCONTAINER_CREATENEWMEDIA_ENTRY );
   235     OstTraceFunctionEntry0( GLXCOMMANDHANDLERADDTOCONTAINER_CREATENEWMEDIA_ENTRY );
   262     GlxCommandHandlerNewMedia* commandHandlerNewMedia =
   236     GlxCommandHandlerNewMedia* commandHandlerNewMedia =
   263             new GlxCommandHandlerNewMedia();
   237             new GlxCommandHandlerNewMedia();
   264     TGlxMediaId newMediaId;
   238     TGlxMediaId newMediaId;
   265     TInt error = commandHandlerNewMedia->ExecuteLD(newMediaId);
   239     QString newTitle;
       
   240     TInt error = commandHandlerNewMedia->ExecuteLD(newMediaId,newTitle);
   266 
   241 
   267     while (error == KErrAlreadyExists)
   242     while (error == KErrAlreadyExists)
   268         {
   243         {
   269         HbMessageBox::warning("Name Already Exist!!!", new HbLabel(
   244         HbMessageBox::warning("Name Already Exist!!!", new HbLabel(
   270                 "New Album"));
   245                 "New Album"));
   271         error = KErrNone;
   246         error = KErrNone;
   272         error = commandHandlerNewMedia->ExecuteLD(newMediaId);
   247         error = commandHandlerNewMedia->ExecuteLD(newMediaId,newTitle);
   273         }
   248         }
   274 
   249 
   275     if (error == KErrNone)
   250     if (error == KErrNone)
   276         {
   251         {
   277         CMPXCollectionPath* path = CMPXCollectionPath::NewL();
   252         CMPXCollectionPath* path = CMPXCollectionPath::NewL();
   280         path->AppendL(newMediaId.Value());
   255         path->AppendL(newMediaId.Value());
   281         CleanupStack::Pop(path);
   256         CleanupStack::Pop(path);
   282         delete mTargetContainers;
   257         delete mTargetContainers;
   283         mTargetContainers = NULL;
   258         mTargetContainers = NULL;
   284         mTargetContainers = path;
   259         mTargetContainers = path;
       
   260         mAlbumName = newTitle;
   285         mNewMediaAdded = true;
   261         mNewMediaAdded = true;
   286         }
   262         }
   287     OstTraceFunctionExit0( GLXCOMMANDHANDLERADDTOCONTAINER_CREATENEWMEDIA_EXIT );
   263     OstTraceFunctionExit0( GLXCOMMANDHANDLERADDTOCONTAINER_CREATENEWMEDIA_EXIT );
   288     }
   264     }
   289 
   265 
   290 QString GlxCommandHandlerAddToContainer::CompletionTextL() const
   266 QString GlxCommandHandlerAddToContainer::CompletionTextL() const
   291     {
   267     {
   292 	return QString();	
   268     if(!mAlbumName.isNull()){
       
   269         return QString("Added to %1").arg(mAlbumName);
       
   270         }
       
   271 	return 	QString();
   293     }
   272     }
   294 
   273 
   295 QString GlxCommandHandlerAddToContainer::ProgressTextL() const
   274 QString GlxCommandHandlerAddToContainer::ProgressTextL() const
   296     {
   275     {
   297     return QString("Adding album...");
   276     return QString("Adding Images...");
   298     }
   277     }