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