deviceupdatesui/cpqtsp/src/CpQtSpView.cpp
changeset 18 7d11f9a6646f
equal deleted inserted replaced
4:75a71fdb4c92 18:7d11f9a6646f
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *     Bio control for Provisioning documents.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <hbapplication.h>
       
    20 #include <hbtoolbar.h>
       
    21 #include <hbaction.h>
       
    22 #include <hbmenu.h>
       
    23 #include <HbTextItem>
       
    24 #include <HbFontSpec>
       
    25 #include <HbMessageBox>
       
    26 #include <QGraphicsLinearLayout>
       
    27 #include <xqserviceprovider.h>
       
    28 #include <xqservicerequest.h>
       
    29 #include <xqserviceutil.h>
       
    30 #include <e32base.h>
       
    31 #include <flogger.h>
       
    32 #include <CWPNameValue.h>
       
    33 #include <CWPEngine.h>
       
    34 #include <CpQtSpView.h>
       
    35 #include <CpQtSpMainWindow.h>
       
    36 
       
    37 
       
    38 CpQtSpView::CpQtSpView(CpQtSp* service,QGraphicsItem *parent)
       
    39     : HbView(parent), iServiceProvider(service)
       
    40 { 
       
    41     setTitle(tr("Messaging"));
       
    42     HbToolBar* toolBar = this->toolBar(); 
       
    43     HbMenu* menu = this->menu();       
       
    44     HbAction* saveAction = new HbAction("Save");     
       
    45     connect(saveAction, SIGNAL(triggered()), this, SLOT(saveProvisoningMessage()));        
       
    46     HbAction* DeleteAction = new HbAction("Delete");
       
    47     
       
    48     toolBar->addAction(saveAction);
       
    49     toolBar->addAction(DeleteAction);
       
    50     toolBar->setOrientation(Qt::Horizontal);
       
    51     iPrimaryFont = new HbFontSpec(HbFontSpec::Primary);
       
    52     iSecondaryFont = new HbFontSpec(HbFontSpec::Secondary);
       
    53     
       
    54     layout = new QGraphicsLinearLayout(Qt::Vertical, this);
       
    55     
       
    56     QString str = hbTrId("txt_device_update_dblist_configuration_message");
       
    57     QString str1 = hbTrId("txt_device_update_dblist_product_code_val_save_to");
       
    58     HbTextItem* mPrimaryItem = new HbTextItem(str, this);
       
    59     HbTextItem* mSecondaryItem = new HbTextItem(str1, this);
       
    60        
       
    61     QFont font = iPrimaryFont->font();
       
    62     mPrimaryItem->setFont(font);
       
    63         
       
    64     font = iSecondaryFont->font();
       
    65     mSecondaryItem->setFont(font);
       
    66     
       
    67     layout->addItem(mPrimaryItem);
       
    68     layout->addItem(mSecondaryItem);
       
    69    
       
    70     setLayout(layout);     
       
    71     }
       
    72 
       
    73 void CpQtSpView::constructView()
       
    74 {
       
    75     iBio = CWPBioControl::NewL(iServiceProvider->returnSession(),iServiceProvider->returnId());
       
    76     RPointerArray<CWPNameValue>* iArray = iBio->CollectItemsLC();    
       
    77     TBufC<200> Name;
       
    78     TBufC<200> Value;    
       
    79     HbTextItem* mPrimaryItem[100];
       
    80     HbTextItem* mSecondaryItem[100];
       
    81     HbTextItem* mSecondaryItemBlank = new HbTextItem("", this);
       
    82     QFont pfont = iPrimaryFont->font();
       
    83     QFont sfont = iSecondaryFont->font();      
       
    84    
       
    85 	TBuf<200> currentTitle(KNullDesC);
       
    86 	
       
    87     for( TInt item = 0; item < iArray->Count(); item++ )
       
    88     {  	
       
    89     	CWPNameValue* pair = ((*iArray)[item]);
       
    90     	Name = pair->Name();
       
    91     	if(Name.Compare(currentTitle) !=0 )
       
    92     	{
       
    93     	QString qname((QChar*)Name.Ptr(),Name.Length());
       
    94     	mPrimaryItem[item] = new HbTextItem(qname);    	
       
    95     	mPrimaryItem[item]->setFont(pfont);    	
       
    96     	layout->addItem(mSecondaryItemBlank);
       
    97     	layout->addItem(mPrimaryItem[item]);
       
    98     	currentTitle.Copy(Name);
       
    99     	}
       
   100     	    	
       
   101     	Value = pair->Value();
       
   102     	QString qvalue((QChar*)Value.Ptr(),Value.Length());   
       
   103     	mSecondaryItem[item] = new HbTextItem(qvalue);
       
   104     	mSecondaryItem[item]->setFont(sfont);
       
   105     	layout->addItem(mSecondaryItem[item]);  
       
   106    }
       
   107     CleanupStack::PopAndDestroy();
       
   108 
       
   109 }
       
   110 
       
   111 void CpQtSpView::saveProvisoningMessage()
       
   112 {
       
   113   CWPEngine* engine = iBio->returnEngine();
       
   114   int errSave = KErrNone;
       
   115   
       
   116   for(TInt i=0; i < engine->ItemCount(); i++)
       
   117   {
       
   118    TRAP( errSave, engine->SaveL(i) );
       
   119   } 
       
   120   
       
   121   if( errSave == KErrNone )
       
   122   {
       
   123   	//For testing purpose. Will be removed in future.
       
   124     //HbMessageBox::launchInformationMessageBox("Message Saved");
       
   125   }
       
   126 }
       
   127 
       
   128 CpQtSpView::~CpQtSpView()
       
   129 {
       
   130     delete iBio;
       
   131 }
       
   132 
       
   133 void CpQtSpView::requestCompleted(const QVariant& value)
       
   134 {
       
   135 }
       
   136 
       
   137 
       
   138 CpQtSp::CpQtSp(QObject* parent)
       
   139 : XQServiceProvider("com.nokia.services.MDM.Provisioning",parent)
       
   140 {  
       
   141     publishAll();
       
   142 }
       
   143 
       
   144 CpQtSp::~CpQtSp()
       
   145 {
       
   146 	delete iObserver;
       
   147 	delete iSession;
       
   148 }
       
   149 
       
   150 void CpQtSp::complete()
       
   151 {
       
   152    QString retvalue ="";
       
   153    completeRequest(1,retvalue);
       
   154 }
       
   155 
       
   156 QString CpQtSp::ProcessMessage(const QString& tmsvid)
       
   157 {
       
   158     iId = tmsvid.toInt();	
       
   159     TMsvSelectionOrdering sort;    
       
   160     sort.SetShowInvisibleEntries(ETrue); 
       
   161     iObserver = new(ELeave) CObserver;
       
   162     iSession = CMsvSession::OpenSyncL(*iObserver);    
       
   163     emit showView();
       
   164     setCurrentRequestAsync();
       
   165     return "";    
       
   166     }
       
   167 
       
   168 TMsvId CpQtSp::returnId()
       
   169 {
       
   170 	return iId;
       
   171 }
       
   172 
       
   173 CMsvSession* CpQtSp::returnSession()
       
   174 {
       
   175   return iSession;
       
   176 }