messagingapp/shareui/src/shareuiprivate.cpp
changeset 52 12db4185673b
parent 44 36f374c67aa8
child 70 a15d9966050f
equal deleted inserted replaced
44:36f374c67aa8 52:12db4185673b
    29 #include <HbListView>
    29 #include <HbListView>
    30 #include <HbListViewItem>
    30 #include <HbListViewItem>
    31 #include <HbNotificationDialog>
    31 #include <HbNotificationDialog>
    32 #include <HbIconItem>
    32 #include <HbIconItem>
    33 #include <HbTextItem>
    33 #include <HbTextItem>
    34 
    34 #include <HbColorScheme>
    35 #include <xqserviceglobal.h>
    35 #include <xqserviceglobal.h>
    36 #include <xqaiwrequest.h>
    36 #include <xqaiwrequest.h>
    37 #include <xqaiwinterfacedescriptor.h>
    37 #include <xqaiwinterfacedescriptor.h>
    38 
    38 
    39 // USER INCLUDES
    39 // USER INCLUDES
    52 #define LOC_NO_SERVICES         hbTrId("No services found.")
    52 #define LOC_NO_SERVICES         hbTrId("No services found.")
    53 #define LOC_NO_FILES            hbTrId("No files found.")
    53 #define LOC_NO_FILES            hbTrId("No files found.")
    54 #define LOC_SERVICE_ERROR       hbTrId("Service error.")
    54 #define LOC_SERVICE_ERROR       hbTrId("Service error.")
    55 #define LOC_PROTECTED_CONTENT   hbTrId("Protected content.")
    55 #define LOC_PROTECTED_CONTENT   hbTrId("Protected content.")
    56 
    56 
       
    57 const QString LIST_ITEM_TITLE("qtc_list_item_title_normal");
       
    58 
    57 /**
    59 /**
    58  * Constructor.
    60  * Constructor.
    59  */
    61  */
    60 ShareUiPrivate::ShareUiPrivate()
    62 ShareUiPrivate::ShareUiPrivate()
    61     {
    63     {
    82     foreach(XQAiwRequest* request,mAiwRequestList)
    84     foreach(XQAiwRequest* request,mAiwRequestList)
    83     {
    85     {
    84         delete request;
    86         delete request;
    85     }
    87     }
    86     mAiwRequestList.clear();
    88     mAiwRequestList.clear();
    87 
       
    88     }
    89     }
    89 
    90 
    90 /**
    91 /**
    91  * Initialize and start the dialog
    92  * Initialize and start the dialog
    92  * 
    93  * 
    93  * @param fileList list of tokens that would allow file manipulation.
    94  * @param fileList list of tokens that would allow file manipulation.
    94  * @return bool error false if dialog initialization failed, true otherwise.
    95  * @return bool error false if dialog initialization failed, true otherwise.
    95  * 
    96  * 
    96  */
    97  */
    97 bool ShareUiPrivate::init(QStringList& fileList, bool embedded)
    98 bool ShareUiPrivate::init(QStringList& fileList, bool embedded)
    98     {    
    99     {
    99     reset();
   100     reset();
   100     mIsEmbedded = embedded;
   101     mIsEmbedded = embedded;
   101     // No input files
   102     // No input files
   102     if ( fileList.count() == 0 )
   103     if (fileList.count() == 0) {
   103         {
       
   104         showNote(LOC_NO_FILES);
   104         showNote(LOC_NO_FILES);
   105         return true;       
   105         return true;
   106         }
   106     }
   107 
   107 
   108 #ifdef __SHAREUI_MIME_HANDLING__   
   108 #ifdef __SHAREUI_MIME_HANDLING__   
   109     // Get the file attributes (MIME and forward lock)
   109     // Get the file attributes (MIME and forward lock)
   110     QStringList mimeTypeList;
   110     QStringList mimeTypeList;
   111     QStringList forwardStatusList;
   111     QStringList forwardStatusList;
   112     getFileAttributes(fileList, mimeTypeList, forwardStatusList);
   112     getFileAttributes(fileList, mimeTypeList, forwardStatusList);
   113     
   113 
   114     // Ignore protected files
   114     // Ignore protected files
   115     QStringList filteredFileList;
   115     QStringList filteredFileList;
   116     QStringList filteredMimeList;
   116     QStringList filteredMimeList;
   117     for ( int i = 0; i < forwardStatusList.count(); i++ )
   117     for (int i = 0; i < forwardStatusList.count(); i++) {
   118         {
   118         if (forwardStatusList[i].toInt()) {
   119         if ( forwardStatusList[i].toInt() )
       
   120             {
       
   121             filteredFileList << fileList[i];
   119             filteredFileList << fileList[i];
   122             filteredMimeList << mimeTypeList[i];
   120             filteredMimeList << mimeTypeList[i];
   123             }
   121         }
   124         }
   122     }
   125     filteredMimeList.removeDuplicates();    
   123     filteredMimeList.removeDuplicates();
   126     
   124 
   127     // Some protected content
   125     // Some protected content
   128     if ( fileList.count() != filteredFileList.count() )
   126     if (fileList.count() != filteredFileList.count()) {
   129         {
   127         showNote(LOC_PROTECTED_CONTENT);
   130         showNote(LOC_PROTECTED_CONTENT);      
       
   131         return true;
   128         return true;
   132         }
   129     }
   133     
   130 
   134     // Only protected content
   131     // Only protected content
   135     if ( filteredFileList.count() == 0 )
   132     if (filteredFileList.count() == 0) {
   136         {
       
   137         showNote(LOC_NO_FILES);
   133         showNote(LOC_NO_FILES);
   138         return true;       
   134         return true;
   139         }
   135     }
   140 #endif
   136 #endif
   141 
   137 
   142 #ifdef __SHAREUI_MIME_HANDLING__ 
   138 #ifdef __SHAREUI_MIME_HANDLING__ 
   143     for ( int i = 0; i < filteredFileList.count(); i++ )
   139     for (int i = 0; i < filteredFileList.count(); i++) {
   144         {     
       
   145         mFileList.append(QDir::toNativeSeparators(filteredFileList[i]));
   140         mFileList.append(QDir::toNativeSeparators(filteredFileList[i]));
   146         }
   141     }
   147 #else
   142 #else
   148     for ( int i = 0; i < fileList.count(); i++ )
   143     for ( int i = 0; i < fileList.count(); i++ )
   149         {     
   144     {
   150         mFileList.append(QDir::toNativeSeparators(fileList[i]));
   145         mFileList.append(QDir::toNativeSeparators(fileList[i]));
   151         }
   146     }
   152 #endif
   147 #endif
   153     
   148 
   154     QList<XQAiwInterfaceDescriptor> serviceDescriptorList = 
   149     QList<XQAiwInterfaceDescriptor> serviceDescriptorList = mAppManager.list(SERVICE_INTERFACE,
   155             mAppManager.list(SERVICE_INTERFACE, SHARE_OP);
   150         SHARE_OP);
   156     if ( serviceDescriptorList.size() > 0 )
   151 
   157         {          
   152     if (serviceDescriptorList.size() > 0) {
   158         initializeUi();
   153         initializeUi();
   159 
   154         //sorting the services based on service names,
   160         for ( int i = 0; i < serviceDescriptorList.count() ; i++ )
   155         QMap<QString,XQAiwInterfaceDescriptor > serviceInterfaceMap;
   161             { 
   156         for (int i = 0; i < serviceDescriptorList.count(); i++) {
       
   157             serviceInterfaceMap.insert(serviceDescriptorList[i].serviceName(),
       
   158                 serviceDescriptorList[i]);
       
   159         }
       
   160         QStringList serviceNames = serviceInterfaceMap.keys();
       
   161         serviceDescriptorList.clear();
       
   162         
       
   163         for (int i = 0; i < serviceNames.count(); i++) {
   162 #ifdef __SHAREUI_MIME_HANDLING__          
   164 #ifdef __SHAREUI_MIME_HANDLING__          
   163             // Filter services based on content type
   165             // Filter services based on content type
   164             QString allowedTypes = serviceDescriptorList[i].customProperty
   166             QString allowedTypes = serviceInterfaceMap[serviceNames.at(i)].customProperty(QString(
   165                     (QString("allowed_mime_types"));              
   167                 "allowed_mime_types"));
   166             QString blockedTypes = serviceDescriptorList[i].customProperty
   168             QString blockedTypes = serviceInterfaceMap[serviceNames.at(i)].customProperty(QString(
   167                     (QString("blocked_mime_types"));
   169                 "blocked_mime_types"));
   168             
   170 
   169             // Check against MIME filters
   171             // Check against MIME filters
   170             if ( ! isContentAllowed( filteredMimeList, allowedTypes ) )
   172             if (!isContentAllowed(filteredMimeList, allowedTypes))
   171                 continue;
   173                 continue;
   172             
   174 
   173             if ( isContentBlocked( filteredMimeList, blockedTypes ) )
   175             if (isContentBlocked(filteredMimeList, blockedTypes))
   174                 continue;                     
   176                 continue;
   175 #endif            
   177 #endif            
   176             HbAction* action = fetchServiceAction(serviceDescriptorList[i]);
   178             HbAction* action = fetchServiceAction(serviceInterfaceMap[serviceNames.at(i)]);
   177             QString iconName = serviceDescriptorList[i].customProperty
   179             QString iconName = serviceInterfaceMap[serviceNames.at(i)].customProperty(QString("aiw_action_icon"));
   178                     (QString("aiw_action_icon"));
   180             if (action) {
   179             if ( action )
       
   180                 {
       
   181                 updateShareUiDialogList(action, iconName);
   181                 updateShareUiDialogList(action, iconName);
   182                 }
   182             }
   183             }
   183         }
   184         
   184         serviceInterfaceMap.clear();
   185         if ( mContentItemModel->rowCount() == 0 )
   185         if (mContentItemModel->rowCount() == 0) {
   186             {
       
   187             showNote(LOC_NO_SERVICES);
   186             showNote(LOC_NO_SERVICES);
   188             return true;
   187             return true;
   189             }
   188         }
   190 
   189 
   191         mSharePopup->show();
   190         mSharePopup->show();
   192         }
   191     }
   193     else
   192     else {
   194         {
       
   195         showNote(LOC_NO_SERVICES);
   193         showNote(LOC_NO_SERVICES);
   196         }
   194     }
   197     
   195 
   198     return true;
   196     return true;
   199     }
   197     }
   200 
   198 
   201 /**
   199 /**
   202   * Creates the view for the share ui.
   200   * Creates the view for the share ui.
   206     // Dialog
   204     // Dialog
   207     mSharePopup = new HbDialog();
   205     mSharePopup = new HbDialog();
   208     // make it delete itself on close
   206     // make it delete itself on close
   209     mSharePopup->setAttribute( Qt::WA_DeleteOnClose, true );
   207     mSharePopup->setAttribute( Qt::WA_DeleteOnClose, true );
   210     HbTextItem* heading = new HbTextItem(LOC_SEND_SELECTED_ITEM, mSharePopup);
   208     HbTextItem* heading = new HbTextItem(LOC_SEND_SELECTED_ITEM, mSharePopup);
       
   209     QColor color = HbColorScheme::color( LIST_ITEM_TITLE );
       
   210     heading->setTextColor( color );
   211     heading->setAlignment(Qt::AlignCenter);
   211     heading->setAlignment(Qt::AlignCenter);
   212     mSharePopup->setDismissPolicy(HbDialog::TapAnywhere);
   212     mSharePopup->setDismissPolicy(HbDialog::TapAnywhere);
   213     mSharePopup->setHeadingWidget(heading);
   213     mSharePopup->setHeadingWidget(heading);
   214     mSharePopup->setFrameType(HbDialog::Strong);
   214     mSharePopup->setFrameType(HbDialog::Strong);
   215     connect(mSharePopup, SIGNAL(aboutToClose()), this, SLOT(reset()));
   215     connect(mSharePopup, SIGNAL(aboutToClose()), this, SLOT(reset()));
   484 void ShareUiPrivate::showNote(QString text)
   484 void ShareUiPrivate::showNote(QString text)
   485     {
   485     {
   486     HbNotificationDialog* dlg = new HbNotificationDialog();
   486     HbNotificationDialog* dlg = new HbNotificationDialog();
   487     dlg->setFocusPolicy(Qt::NoFocus);
   487     dlg->setFocusPolicy(Qt::NoFocus);
   488     dlg->setAttribute(Qt::WA_DeleteOnClose, true);
   488     dlg->setAttribute(Qt::WA_DeleteOnClose, true);
   489     dlg->setText(text);
   489     dlg->setTitle(text);
   490     dlg->show();
   490     dlg->show();
   491     }
   491     }
   492 
   492 
   493 /**
   493 /**
   494  * List item prototype constructor.
   494  * List item prototype constructor.