deviceupdatesui/deviceupdatesplugin/src/deviceupdatesdata.cpp
changeset 67 fdbfe0a95492
parent 43 88e14c3d4c4f
equal deleted inserted replaced
62:03849bd79877 67:fdbfe0a95492
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Device updates data for control panel
    14 * Description:  Device updates data for control panel
    15 *
    15 *
    16 */
    16 */
    17 
       
    18 #include <QtCore/QProcess>
       
    19 #include <QtCore/QDir>
       
    20 #include <QtCore/QLibraryInfo>
       
    21 #include <cpsettingformitemdata.h>
    17 #include <cpsettingformitemdata.h>
    22 #include <apgtask.h>
    18 #include <apgtask.h>
    23 #include "deviceupdatesdata.h"
    19 #include "deviceupdatesdata.h"
    24 
    20 #include <xqserviceutil.h>
    25 
       
    26 DeviceUpdateData::DeviceUpdateData(CpItemDataHelper &itemDataHelper,
    21 DeviceUpdateData::DeviceUpdateData(CpItemDataHelper &itemDataHelper,
    27 													   const QString &text /*= QString()*/,
    22 													   const QString &text,
    28 													   const QString &description /*= QString()*/,
    23 													   const QString &description,
    29 													   const HbIcon &icon /*= HbIcon()*/,
    24 													   const HbIcon &icon,
    30 													   const HbDataFormModelItem *parent /*= 0*/)
    25 													   const HbDataFormModelItem *parent)
    31 													   : CpSettingFormEntryItemData(itemDataHelper,
    26 													   : CpSettingFormEntryItemData(itemDataHelper,
    32 													   text,
    27 													   text,
    33 													   description,
    28 													   description,
    34 													   icon,
    29 													   icon,
    35 													   parent)
    30 													   parent)
    36 {
    31 {
    37 	mproc = NULL;
       
    38 }
    32 }
    39 
    33 
    40 DeviceUpdateData::~DeviceUpdateData()
    34 DeviceUpdateData::~DeviceUpdateData()
    41 {
    35 {
    42 	CloseDeviceUpdatesUi();
    36 	CloseDeviceUpdatesUi();
    43 	if (mproc)
       
    44 	{
       
    45 		delete mproc;
       
    46 		mproc = NULL;
       
    47 	}
       
    48 }
    37 }
    49 
    38 
    50 // -----------------------------------------------------------------------------
    39 // -----------------------------------------------------------------------------
    51 // DeviceUpdateData::OpenDmAppL()
    40 // DeviceUpdateData::OpenDmAppL()
    52 // -----------------------------------------------------------------------------
    41 // -----------------------------------------------------------------------------
    53 //
    42 //
    54 void DeviceUpdateData::LaunchDeviceUpdatesUi()
    43 void DeviceUpdateData::LaunchDeviceUpdatesUi()
    55 	{	
    44 	{
    56 		
    45     qDebug("DeviceUpdateData::LaunchDeviceUpdatesUi >>");
    57 		RWsSession ws;
    46     RWsSession ws;
    58     User::LeaveIfError( ws.Connect() );
    47     qt_symbian_throwIfError( ws.Connect() );
    59     CleanupClosePushL( ws );
    48     CleanupClosePushL( ws );
    60     // Find the task with uid
    49     // Find the task with uid
    61     TApaTaskList taskList(ws);
    50     TApaTaskList taskList(ws);
    62     TApaTask task = taskList.FindApp( KUidSmlSyncApp );    
    51     TApaTask task = taskList.FindApp( KUidSmlSyncApp );    
    63     if ( task.Exists() )
    52     if ( task.Exists() )
    64     {    	    
    53     {    	    
    65         task.BringToForeground();        
    54         task.BringToForeground();        
    66     }
    55     }
    67     else
    56     else
    68     {
    57     {
    69  				// Create DM UI Process
    58         qDebug("DeviceUpdateData::LaunchDeviceUpdatesUi >> embedding");
    70     		if(!mproc)
    59         QScopedPointer<XQAiwRequest> requester (mRequestManager.create(KService,KInterface,KMethod,true)); //false for NON-EMBEDDED 
    71     			mproc = new QProcess();
    60         qDebug("DeviceUpdateData::LaunchDeviceUpdatesUi >> embed end");
    72     		if(mproc->state() != QProcess::Running)
    61         connect(requester.data(), SIGNAL(requestOk(const QVariant&)), this, SLOT(handleOk(const QVariant&)));
    73     		{
    62         connect(requester.data(), SIGNAL(requestError(int,const QString&)), this, SLOT(handleError(int,const QString&)));
    74     			QString app = QLatin1String("deviceupdates");
    63         if (!(requester.isNull())) 
    75     			QStringList args;
    64             {
    76     			args<< QLatin1String("-cp");
    65             m_currentRequest = requester.data();
    77     			mproc->start(app, args);
    66             requester->setSynchronous(false);
    78     			mproc->waitForStarted();
    67             bool serviceRequestOk = requester->send();
    79     		}     
    68             if (serviceRequestOk)
    80     }
    69                 {
    81     CleanupStack::PopAndDestroy();  // ws    		
    70                 m_currentRequest = requester.take();
       
    71                 }
       
    72             else
       
    73                 {
       
    74                 // On a controlled error Qt Highway should call requestError,
       
    75                 // so clean scoped pointer here.
       
    76                 requester.take();
       
    77                 }
       
    78             }  
       
    79         }
       
    80     CleanupStack::PopAndDestroy();  // ws    
       
    81     qDebug("DeviceUpdateData::LaunchDeviceUpdatesUi >> end");	
    82 	}
    82 	}
    83 
    83 
    84 // ---------------------------------------------------------------------------------------------
    84 // ---------------------------------------------------------------------------------------------
    85 // DeviceUpdateData::CloseDmUi
    85 // DeviceUpdateData::CloseDeviceUpdatesUi
    86 // closes DM Ui
    86 // closes DM Ui
    87 // ---------------------------------------------------------------------------------------------	
    87 // ---------------------------------------------------------------------------------------------	
    88 void DeviceUpdateData:: CloseDeviceUpdatesUi()
    88 void DeviceUpdateData:: CloseDeviceUpdatesUi()
    89 {
    89 {
    90 	if(( mproc )&&(mproc->state() == QProcess::Running))
    90     if(m_currentRequest)
    91   	{
    91         {
    92     			mproc->close();
    92         delete m_currentRequest;
    93     }
    93         m_currentRequest = NULL;
    94 
    94         }
    95 }	
    95 }	
    96 
    96 
       
    97 // ---------------------------------------------------------------------------------------------
       
    98 // DeviceUpdateData::onLaunchView
       
    99 // ---------------------------------------------------------------------------------------------
    97 void DeviceUpdateData::onLaunchView()
   100 void DeviceUpdateData::onLaunchView()
    98 {
   101 {
    99 	LaunchDeviceUpdatesUi();
   102 	LaunchDeviceUpdatesUi();
   100 }
   103 }
   101 
   104 
       
   105 // ---------------------------------------------------------------------------------------------
       
   106 // DeviceUpdateData::createSettingView
       
   107 // ---------------------------------------------------------------------------------------------
   102 CpBaseSettingView *DeviceUpdateData::createSettingView() const
   108 CpBaseSettingView *DeviceUpdateData::createSettingView() const
   103 {
   109 {
   104 		return 0;
   110 		return NULL;
   105 }
   111 }
       
   112 
       
   113 // ---------------------------------------------------------------------------------------------
       
   114 // DeviceUpdateData::handleOk
       
   115 // Handles when request completes successfully
       
   116 // ---------------------------------------------------------------------------------------------
       
   117 void DeviceUpdateData::handleOk(const QVariant &returnValue)
       
   118 {
       
   119     if(m_currentRequest)
       
   120         {
       
   121         delete m_currentRequest;
       
   122         m_currentRequest = NULL;
       
   123         }
       
   124 }
       
   125 
       
   126 // ---------------------------------------------------------------------------------------------
       
   127 // DeviceUpdateData::handleError
       
   128 // Handles when request returns with an error
       
   129 // ---------------------------------------------------------------------------------------------
       
   130 void DeviceUpdateData::handleError(int error, const QString& errorMessage)
       
   131 {   
       
   132     if(m_currentRequest)
       
   133         {
       
   134         delete m_currentRequest;
       
   135         m_currentRequest = NULL;
       
   136         }
       
   137 }