messagingapp/shareui/src/shareuiprivate.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Offers message creation and sending services.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "shareuiprivate.h"
       
    20 #include <QVariant>
       
    21 #include <QDir>
       
    22 #include <HbPushButton>
       
    23 #include <HbListWidget>
       
    24 #include <HbMainWindow>
       
    25 #include <HbNotificationDialog>
       
    26 #include <xqserviceglobal.h>
       
    27 
       
    28 //Localized Constants
       
    29 #define LOC_SEND_SELECTED_ITEM hbTrId("txt_messaging_title_send_selected_item")
       
    30 #define LOC_BUTTON_CANCEL hbTrId("txt_common_button_cancel")
       
    31 
       
    32 ShareUiPrivate::ShareUiPrivate()
       
    33     {
       
    34     
       
    35     }
       
    36 
       
    37 /**
       
    38  * Destructor.
       
    39  */
       
    40 ShareUiPrivate::~ShareUiPrivate()
       
    41     {
       
    42     if(mContentItemModel)
       
    43         {
       
    44         delete mContentItemModel;
       
    45         }
       
    46     if(mContentListView)
       
    47         {
       
    48         delete mContentListView;
       
    49         }
       
    50     if(mSharePopup)
       
    51         {
       
    52         delete mSharePopup;
       
    53         }
       
    54     mIndexActionMap.clear();
       
    55     mAiwRequestList.clear();
       
    56     mFileList.clear();
       
    57     }
       
    58 
       
    59 /**
       
    60  * initialize and start the dialog
       
    61  * 
       
    62  * @param fileList list of tokens that would allow file manipulation
       
    63  * @return bool error false if dialog initialization failed, true otherwise.
       
    64  * 
       
    65  */
       
    66 bool ShareUiPrivate::init(QStringList& fileList, bool embedded)
       
    67     {    
       
    68     bool retval = false;
       
    69     mFileList.clear();
       
    70     
       
    71     if(fileList.count())
       
    72         {
       
    73         for(int i = 0; i < fileList.count(); i++)
       
    74             {
       
    75             mFileList.append(QDir::toNativeSeparators(fileList[i]));
       
    76             }
       
    77         
       
    78         mIsEmbedded = embedded;
       
    79     
       
    80         initializeUi();
       
    81     
       
    82         QList<XQAiwInterfaceDescriptor> serviceDescriptorList;
       
    83         mIndexActionMap.clear();
       
    84         mAiwRequestList.clear();
       
    85         if(fetchServiceDescriptors(serviceDescriptorList))
       
    86             {
       
    87             
       
    88             HbAction* action;
       
    89             
       
    90             for(int i = 0; i < serviceDescriptorList.count() ; i++)
       
    91                 {
       
    92 
       
    93                 if((action = fetchServiceAction(serviceDescriptorList[i])) != NULL)
       
    94                     {
       
    95                     updateShareUiDialogList(action);
       
    96                     }
       
    97                 }
       
    98             retval = true;
       
    99             }
       
   100         else
       
   101             {
       
   102             updateShareUiDialogList(NULL);
       
   103             }
       
   104     
       
   105         enableUi();
       
   106         }
       
   107     return retval;
       
   108     }
       
   109 
       
   110 /**
       
   111   * Creates the view for the sendui dialog.
       
   112   *  
       
   113   * @return bool true if initialization was successful, false otherwise.
       
   114   */
       
   115 
       
   116 void ShareUiPrivate::initializeUi()
       
   117     {
       
   118     mSharePopup = new HbDialog();
       
   119     mSharePopup->setHeadingWidget(new HbLabel(LOC_SEND_SELECTED_ITEM));
       
   120     mSharePopup->setTimeout(HbDialog::NoTimeout);  
       
   121     mContentListView = new HbListView(mSharePopup);
       
   122 
       
   123     mContentItemModel = new QStandardItemModel(mSharePopup); 
       
   124     mContentListView->setModel(mContentItemModel);
       
   125     mSharePopup->setContentWidget(mContentListView);
       
   126     mSharePopup->setFrameType(HbDialog::Strong);
       
   127     mSharePopup->setPrimaryAction(new HbAction(LOC_BUTTON_CANCEL));
       
   128     
       
   129     connect(mContentListView, SIGNAL(activated(QModelIndex)),this,SLOT(itemActivated(QModelIndex)));
       
   130     
       
   131     }
       
   132 
       
   133 /**
       
   134  * fetchServiceDescriptors
       
   135  * 
       
   136  * Fetches the service descriptors using the Application Manager api. 
       
   137  * This function is in progress and will change.
       
   138  * 
       
   139  * @return error boolean true if successfully fetched.
       
   140  */
       
   141 
       
   142 bool ShareUiPrivate::fetchServiceDescriptors(QList<XQAiwInterfaceDescriptor>& serviceDescriptorList)
       
   143     {
       
   144     bool retval = false;
       
   145     
       
   146     serviceDescriptorList = mAppManager.list(SERVICE_INTERFACE, SHARE_OP);
       
   147     
       
   148     if(serviceDescriptorList.size() > 0)
       
   149         {
       
   150         retval = true;
       
   151         }
       
   152     return retval;
       
   153     }
       
   154 
       
   155 
       
   156 /**
       
   157  * fetchServiceAction fetches the action associated with a specified interface descriptor.
       
   158  * This is used after the fetchServiceDescriptors is called, and 
       
   159  * 
       
   160  * @param serviceDescriptor ServiceDescriptor fetched using fetchServiceDescriptors
       
   161  * @return error boolean true if successfully fetched.
       
   162  */
       
   163 
       
   164 HbAction* ShareUiPrivate::fetchServiceAction(XQAiwInterfaceDescriptor interfaceDescriptor)
       
   165     {
       
   166     
       
   167     XQAiwRequest* request = mAppManager.create(interfaceDescriptor,SHARE_OP,mIsEmbedded);
       
   168     mAiwRequestList.append(request);
       
   169     HbAction* action = convertAction(request->createAction());
       
   170     if(action)
       
   171         {
       
   172         connect(request, SIGNAL(triggered()), this, SLOT(onTriggered()));
       
   173         connect(request, SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
       
   174         connect(request, SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
       
   175         }
       
   176     return action;
       
   177     }
       
   178 
       
   179 
       
   180 /**
       
   181  * Update the SendUi Dialog (and associated list items) once the required
       
   182  * information has been fetched.
       
   183  * 
       
   184  * @params action HbAction* The action that must be associated with the entry at that point in the list.
       
   185  */
       
   186 
       
   187 
       
   188 bool ShareUiPrivate::updateShareUiDialogList(HbAction* action)
       
   189     {
       
   190     
       
   191     bool retval = false;
       
   192     QStandardItem* item = NULL;
       
   193     if(action != NULL)
       
   194         {
       
   195         item = new QStandardItem(action->icon().qicon(),action->text());
       
   196         mContentItemModel->appendRow(item);
       
   197         QModelIndex index = item->index();
       
   198         mIndexActionMap[index] = action;
       
   199         retval = true;
       
   200         }
       
   201     else
       
   202         {
       
   203         item = new QStandardItem(QString("No Services Found"));
       
   204         mContentItemModel->appendRow(item);
       
   205         }
       
   206     return retval;
       
   207     
       
   208     }
       
   209 
       
   210 
       
   211 /**
       
   212  * 
       
   213  * Enable the UI and show it on the screen.
       
   214  * 
       
   215  * 
       
   216  */
       
   217 
       
   218 void ShareUiPrivate::enableUi()
       
   219     {
       
   220     mSharePopup->exec();
       
   221     }
       
   222 
       
   223 /**
       
   224  * Slot for handling send service selection on the UI
       
   225  * 
       
   226  */
       
   227 
       
   228 
       
   229 void ShareUiPrivate::onTriggered(void)
       
   230     {
       
   231     
       
   232     XQAiwRequest* request = 0;
       
   233     request = qobject_cast<XQAiwRequest*>(sender());
       
   234     if(request)
       
   235         {
       
   236         request->setArguments(mFileList);
       
   237         }
       
   238     }
       
   239 
       
   240 /**
       
   241  * Slot for handling valid returns from the framework.
       
   242  * 
       
   243  * @param result const QVariant&
       
   244  */
       
   245 
       
   246 void ShareUiPrivate::handleOk(const QVariant& result)
       
   247     {
       
   248     Q_UNUSED(result)
       
   249     }
       
   250 
       
   251 /**
       
   252  * Slot for handling errors. Error ids are provided as 
       
   253  * 32-bit integers. These are 
       
   254  * 
       
   255  * @param errorCode qint32
       
   256  * 
       
   257  * 
       
   258  */
       
   259 void ShareUiPrivate::handleError(int errorCode, const QString& errorMessage)
       
   260     {
       
   261     Q_UNUSED(errorMessage)
       
   262     QString errText("IPC Error: ");
       
   263     HbNotificationDialog* dlg = new HbNotificationDialog();
       
   264     dlg->setFocusPolicy(Qt::NoFocus);
       
   265     dlg->setAttribute(Qt::WA_DeleteOnClose, true);
       
   266 
       
   267     
       
   268     switch(errorCode)
       
   269         {
       
   270         case XQService::EConnectionError:
       
   271             errText.append(QString("EConnectionError: "));
       
   272             break;
       
   273         case XQService::EConnectionClosed:
       
   274             errText.append(QString("EConnectionClosed: "));
       
   275             break;
       
   276         case XQService::EServerNotFound:
       
   277             errText.append(QString("EServerNotFound: "));
       
   278             break;
       
   279         case XQService::EIPCError:
       
   280             errText.append(QString("EIPCError: "));
       
   281             break;
       
   282         case XQService::EUnknownError:
       
   283             errText.append(QString("EUnknownError: "));
       
   284             break;
       
   285         case XQService::ERequestPending:
       
   286             errText.append(QString("ERequestPending: "));
       
   287             break;
       
   288         }
       
   289     errText.append(errorMessage);
       
   290     dlg->setText(errText);
       
   291     dlg->show();
       
   292     }
       
   293 
       
   294 
       
   295 
       
   296 /** 
       
   297  * When a list box item is pressed, this slot should be invoked. The action
       
   298  * corresponding to the clicked list item should be invoked with the stored lis
       
   299  * of files.
       
   300  * 
       
   301  * @param index QModelIndex
       
   302  * 
       
   303  */
       
   304 
       
   305 void ShareUiPrivate::itemActivated(QModelIndex index)
       
   306     {
       
   307 
       
   308     HbAction* action = mIndexActionMap[index];
       
   309     
       
   310     if(action)
       
   311         {
       
   312         action->setEnabled(true);
       
   313         action->activate(HbAction::Trigger);
       
   314         }    
       
   315     mSharePopup->close();
       
   316 
       
   317     }
       
   318 
       
   319 
       
   320 /**
       
   321  * Convert a qaction to hbaction.
       
   322  * 
       
   323  * @param action QAction*
       
   324  * @return HbAction* 
       
   325  */
       
   326 
       
   327 HbAction* ShareUiPrivate::convertAction(QAction *action)
       
   328     {
       
   329     HbAction *actionHb = 0;
       
   330     if (action) 
       
   331         {
       
   332         actionHb = new HbAction(HbIcon(action->icon()), action->text());
       
   333         actionHb->setVisible(action->isVisible());
       
   334         actionHb->setCheckable(action->isCheckable());
       
   335         actionHb->setEnabled(action->isEnabled());
       
   336 
       
   337         connect(actionHb, SIGNAL(triggered()), action, SIGNAL(triggered()));
       
   338         connect(actionHb, SIGNAL(changed()), action, SIGNAL(changed()));
       
   339         connect(actionHb, SIGNAL(hovered()), action, SIGNAL(hovered()));
       
   340         connect(actionHb, SIGNAL(toggled(bool)), action, SIGNAL(toggled(bool)));
       
   341         
       
   342         action->setParent(actionHb); 
       
   343         }
       
   344     
       
   345     return actionHb;
       
   346     }