deviceupdatesui/deviceupdates/src/serversettingsview.cpp
branchRCL_3
changeset 57 6757f1e2efd2
equal deleted inserted replaced
55:c4687ff85147 57:6757f1e2efd2
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Methods for ServerSettingsView
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hblineedit.h>
       
    19 #include <hbmessagebox.h>
       
    20 #include <hbnamespace.h>
       
    21 #include "serversettingsview.h"
       
    22 #include "dmadvancedview.h"
       
    23 #include "settingsdataformcustomitem.h"
       
    24 
       
    25 ServerSettingsView::ServerSettingsView(HbMainWindow* mainWindow, DmAdvancedView* serversview, QString& header, QGraphicsItem* parent): HbView(parent), iMainWindow(mainWindow),
       
    26  form(NULL),dataformmodel(NULL),serversView(serversview),backbehaviorset(false)
       
    27     {    
       
    28     constructview(header);
       
    29     viewspecificmenu = new HbMenu();
       
    30     help = viewspecificmenu->addAction(hbTrId("txt_common_menu_help"));
       
    31     exit = viewspecificmenu->addAction(hbTrId("txt_common_menu_exit"));
       
    32     connect(exit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit()));    
       
    33     setMenu(viewspecificmenu);
       
    34     iPort = 0;
       
    35     }
       
    36 ServerSettingsView::~ServerSettingsView()
       
    37     {
       
    38     
       
    39     }  
       
    40 
       
    41 void ServerSettingsView::constructview(QString& header)
       
    42     {
       
    43     if(!form)
       
    44         {
       
    45         //custom prototype    
       
    46         form = new HbDataForm();
       
    47         QList <HbAbstractViewItem*> protos = form->itemPrototypes();
       
    48         customPrototype = new SettingsDataFormCustomItem(form);
       
    49         protos.append(customPrototype);
       
    50         form->setItemPrototypes(protos);
       
    51         dataformmodel =  new HbDataFormModel();    
       
    52         makeviewItemsVisible(header);
       
    53         form->setModel(dataformmodel); 
       
    54         setWidget(form);    
       
    55         iMainWindow->addView(this);    
       
    56         }    
       
    57     else //form already created
       
    58         {   
       
    59         }        
       
    60     }
       
    61 
       
    62 int ServerSettingsView::setProfileValues(QStringList& settingdatalist,
       
    63 				bool& sessiontype, QStringList& apdata, int& currentap
       
    64         					   ,  int& portnum, bool& networkauthval)
       
    65     {
       
    66     Q_UNUSED(sessiontype);
       
    67     Q_UNUSED(networkauthval);	
       
    68     int count =  settingdatalist.count();
       
    69     apnameslist = apdata;
       
    70     if(count > 0)
       
    71         {
       
    72         servername->setContentWidgetData(QString("text"), settingdatalist.first());
       
    73         serverid->setContentWidgetData(QString("text"), settingdatalist[1]);         
       
    74         serverpwd->setContentWidgetData(QString("echoMode"),HbLineEdit::Password );
       
    75         serverpwd->setContentWidgetData(QString("text"), settingdatalist[2]);                
       
    76         QStringList sList;
       
    77         sList <<hbTrId("txt_deviceupdate_setlabel_to_update_your_val_inter");
       
    78         sList<<hbTrId("txt_deviceupdate_setlabel_to_update_your_val_bluet");        
       
    79         sessionmode->setContentWidgetData(QString("text"), sList[0]);//Internet selected
       
    80         sessionmode->setContentWidgetData(QString("additionalText"), sList[1]);
       
    81         
       
    82         apdata.append(hbTrId("txt_deviceupdate_setlabel_access_point_val_default"));
       
    83         accesspoint->setContentWidgetData(QString("items"), apdata);
       
    84         currentiapindex = currentap;
       
    85         if(currentap >= 0)
       
    86         accesspoint->setContentWidgetData(QString("currentIndex"), currentap); 
       
    87         else
       
    88             accesspoint->setContentWidgetData(QString("currentIndex"), apdata.count()-1); 
       
    89         form->addConnection(accesspoint, SIGNAL(currentIndexChanged  (int  ) ),this, SLOT(accessPointItemChanged(int)));                
       
    90         hostaddress->setContentWidgetData(QString("text"),settingdatalist[3]);  
       
    91         iPort = portnum;
       
    92         port->setContentWidgetData(QString("text"),iPort);//Integer only setting needs to be done    
       
    93         form->addConnection(port, SIGNAL(textChanged  (QString) ),this, SLOT(portItemChanged(QString)));
       
    94         username->setContentWidgetData(QString("text"),settingdatalist[4]);        
       
    95         userpwd->setContentWidgetData(QString("echoMode"),HbLineEdit::Password );
       
    96         userpwd->setContentWidgetData(QString("text"),settingdatalist[5]);                
       
    97         QStringList yesnoList;
       
    98         yesnoList <<hbTrId("txt_deviceupdate_setlabel_network_auth_val_yes");
       
    99         yesnoList<<hbTrId("txt_deviceupdate_setlabel_network_auth_val_no");
       
   100         networkauth->setContentWidgetData(QString("text"), yesnoList[0]);
       
   101         networkauth->setContentWidgetData(QString("additionalText"), yesnoList[1]);        
       
   102         networkusername->setContentWidgetData(QString("text"),settingdatalist[6]);
       
   103         networkpwd->setContentWidgetData(QString("echoMode"),HbLineEdit::Password );
       
   104         networkpwd->setContentWidgetData(QString("text"),settingdatalist[7]);                
       
   105         return 0;
       
   106         }
       
   107     else 
       
   108         return -1;
       
   109     }
       
   110 
       
   111 
       
   112 void ServerSettingsView::backButtonClicked()
       
   113     {   
       
   114     qDebug("OMADM server settings back button clicked");
       
   115     //Trigger main view
       
   116     //Send data back to servers view and save the profile
       
   117     QStringList itemlist;
       
   118     itemlist << servername->contentWidgetData(QString("text")).toString();
       
   119     itemlist << serverid->contentWidgetData(QString("text")).toString();
       
   120     itemlist << serverpwd->contentWidgetData(QString("text")).toString();
       
   121 
       
   122     itemlist << hostaddress->contentWidgetData(QString("text")).toString();
       
   123 
       
   124     itemlist << username->contentWidgetData(QString("text")).toString();
       
   125 
       
   126     itemlist << userpwd->contentWidgetData(QString("text")).toString();
       
   127 
       
   128     itemlist
       
   129             << networkusername->contentWidgetData(QString("text")).toString();
       
   130 
       
   131     itemlist << networkpwd->contentWidgetData(QString("text")).toString();
       
   132     QString sesstype =
       
   133             sessionmode->contentWidgetData(QString("text")).toString();
       
   134     bool sessmode = false;
       
   135     if (sesstype.compare("Internet"))
       
   136         sessmode = true;
       
   137     //Map this current iap with iap array
       
   138     QString curriap;
       
   139     if (currentiapindex >= 0 && currentiapindex < apnameslist.count())
       
   140         curriap = apnameslist[currentiapindex];//accesspoint->contentWidgetData(QString("currentText")).toString();
       
   141     else
       
   142         curriap.clear();
       
   143     unsigned int portval = port->contentWidgetData(QString("text")).toInt();
       
   144     QString netauthdata =
       
   145             sessionmode->contentWidgetData(QString("text")).toString();
       
   146     bool netauthval = false;
       
   147     if (netauthdata.compare(hbTrId("txt_deviceupdate_setlabel_network_auth_val_yes")))
       
   148         netauthval = true;
       
   149     //check server name , server id, host addr & usrname        
       
   150     if ((itemlist[0].length() > 0) && (itemlist[1].length() > 0)
       
   151             && (itemlist[3].length() > 0) && (itemlist[4].length() > 0))
       
   152         {
       
   153         serversView->saveProfile(itemlist, sessmode, curriap, iPort,
       
   154                 netauthval);        
       
   155         form->removeConnection(accesspoint,
       
   156                 SIGNAL(currentIndexChanged (int ) ), this,
       
   157                 SLOT(accessPointItemChanged(int)));        
       
   158         iMainWindow->setCurrentView(serversView);
       
   159         //Form wk08 soft key owned by view
       
   160         //iMainWindow->removeSoftKeyAction(Hb::SecondarySoftKey,backaction);
       
   161         dataformmodel->clear();
       
   162         }
       
   163     else
       
   164         {
       
   165         TInt x = itemlist.count();
       
   166         TInt valSet=0;
       
   167         int i=0;
       
   168         for(i=0;i<x;i++)
       
   169             {
       
   170             if(itemlist[i].length()>0)
       
   171                 {
       
   172                 valSet=1;
       
   173                 break;
       
   174                 }
       
   175             }
       
   176         if(valSet==1)
       
   177             {
       
   178         HbMessageBox *note = new HbMessageBox(HbMessageBox::MessageTypeInformation);
       
   179         note->setText(hbTrId(
       
   180                 "txt_device_update_dialog_enter_mandatory_field_values"));
       
   181         note->setAttribute( Qt::WA_DeleteOnClose);         
       
   182         note->setTimeout(HbPopup::NoTimeout);
       
   183         note->open();
       
   184             }
       
   185         else
       
   186             {
       
   187             form->removeConnection(accesspoint,SIGNAL(currentIndexChanged (int ) ), this,SLOT(accessPointItemChanged(int)));
       
   188             iMainWindow->setCurrentView(serversView);
       
   189         //Form wk08 soft key owned by view
       
   190         //iMainWindow->removeSoftKeyAction(Hb::SecondarySoftKey,backaction);
       
   191             dataformmodel->clear();   
       
   192             }
       
   193         
       
   194         }        
       
   195     }
       
   196 
       
   197 void ServerSettingsView::checkServerIdvalue()
       
   198     {
       
   199     QString srvid = serverid->contentWidgetData(QString("text")).toString();
       
   200     if(serversView->checkServerId(srvid))
       
   201         {
       
   202     serverid->setContentWidgetData(QString("text"), QString("")); 
       
   203     HbMessageBox *note= new HbMessageBox(HbMessageBox::MessageTypeInformation);
       
   204            note->setText(hbTrId("txt_device_update_dialog_invalid_server_id")); 
       
   205            note->setAttribute( Qt::WA_DeleteOnClose);                   
       
   206            note->setTimeout(HbPopup::NoTimeout);
       
   207            note->open();         
       
   208         }          
       
   209     }
       
   210 
       
   211 void ServerSettingsView::setBackButtonBehavior()
       
   212     {    
       
   213     if (!backbehaviorset)
       
   214         {
       
   215         qDebug("OMADM server settings view back behavior setting");
       
   216         backaction = new HbAction(Hb::BackNaviAction, this);        
       
   217         connect(backaction, SIGNAL(triggered()), this,
       
   218                 SLOT(backButtonClicked()));                
       
   219         setNavigationAction(backaction);        
       
   220         backbehaviorset = true;
       
   221         }
       
   222     qDebug("OMADM server settings view back behavior setting done");
       
   223     }
       
   224 
       
   225 void ServerSettingsView::makeviewItemsVisible(QString& formtitle)
       
   226     {    
       
   227     setBackButtonBehavior();
       
   228     form->setHeading(hbTrId("txt_device_update_subhead_advanced_device_updates"));
       
   229     form->setDescription(formtitle);    
       
   230     if(dataformmodel->rowCount() <= 0)
       
   231         {
       
   232         QString itemname(hbTrId("txt_device_update_formlabel_server_name"));
       
   233         servername = dataformmodel->appendDataFormItem(HbDataFormModelItem::TextItem , itemname);
       
   234         
       
   235         itemname = hbTrId("txt_device_update_formlabel_server_id");
       
   236         serverid = dataformmodel->appendDataFormItem(HbDataFormModelItem::TextItem , itemname);
       
   237     
       
   238         form->addConnection(serverid, SIGNAL(editingFinished ()), 
       
   239                 this, SLOT(checkServerIdvalue()));
       
   240         itemname = hbTrId("txt_device_update_formlabel_server_password");
       
   241         serverpwd = dataformmodel->appendDataFormItem(HbDataFormModelItem::TextItem, itemname);
       
   242         
       
   243         itemname = hbTrId("txt_device_update_setlabel_session_mode");
       
   244         sessionmode = dataformmodel->appendDataFormItem(HbDataFormModelItem::ToggleValueItem, itemname);
       
   245         
       
   246         itemname = hbTrId("txt_device_update_setlabel_access_point");
       
   247         accesspoint = dataformmodel->appendDataFormItem(HbDataFormModelItem::ComboBoxItem , itemname);
       
   248         
       
   249         itemname = hbTrId("txt_device_update_formlabel_host_address");
       
   250         hostaddress = dataformmodel->appendDataFormItem(HbDataFormModelItem::TextItem, itemname);
       
   251         
       
   252         itemname = hbTrId("txt_device_update_formlabel_port");
       
   253         port = dataformmodel->appendDataFormItem(HbDataFormModelItem::CustomItemBase, itemname);
       
   254     
       
   255         itemname = hbTrId("txt_device_update_formlabel_user_name");
       
   256         username = dataformmodel->appendDataFormItem(HbDataFormModelItem::TextItem, itemname);
       
   257         
       
   258         itemname = hbTrId("txt_device_update_formlabel_password");
       
   259         userpwd = dataformmodel->appendDataFormItem(HbDataFormModelItem::TextItem, itemname);
       
   260         
       
   261         itemname = hbTrId("txt_device_update_formlabel_network_authentication");
       
   262         networkauth = dataformmodel->appendDataFormItem(HbDataFormModelItem::ToggleValueItem, itemname);
       
   263         
       
   264         itemname = hbTrId("txt_device_update_formlabel_network_username");
       
   265         networkusername = dataformmodel->appendDataFormItem(HbDataFormModelItem::TextItem, itemname);
       
   266         
       
   267         itemname = hbTrId("txt_device_update_setlabel_network_password");
       
   268         networkpwd = dataformmodel->appendDataFormItem(HbDataFormModelItem::TextItem, itemname);
       
   269         }
       
   270     }
       
   271 
       
   272 void ServerSettingsView::accessPointItemChanged(int apindex)
       
   273     {
       
   274     currentiapindex = apindex;
       
   275     qDebug("omadm iap changed");        
       
   276     }
       
   277 
       
   278 void ServerSettingsView::portItemChanged(QString port)
       
   279     {    
       
   280     iPort = port.toInt();
       
   281     qDebug("omadm new port value is %d ",iPort);
       
   282     }