remotemgmt_plat/syncml_ds_customization_api/tsrc/SyncFwCustomizer/customlistview.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 25 b183ec05bd8c
child 27 5cc2995847ea
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
     1 /*
       
     2 * Copyright (c) 2009 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 *
       
    16 */
       
    17 
       
    18 #include "customlistview.h"
       
    19 #include <hbmenu.h>
       
    20 #include <hbaction.h>
       
    21 #include <hblistwidgetitem.h>
       
    22 #include <hblistwidget.h>
       
    23 #include <QAbstractItemModel>
       
    24 #include <xqsettingsmanager.h>
       
    25 #include <nsmloperatordatacrkeys.h>
       
    26 #include <hbinputdialog.h>
       
    27 #include <syncmlclient.h>
       
    28 #include <syncmlclientds.h>
       
    29 #include <hbmessagebox.h>
       
    30 #include <centralrepository.h>
       
    31 
       
    32 CustomListView::CustomListView( QGraphicsItem *parent )
       
    33     : HbView( parent )
       
    34     {
       
    35     setTitle(tr("SyncFwCustomizer"));
       
    36     populateModel();
       
    37     createMenu();
       
    38     }
       
    39 
       
    40 void CustomListView::editItem()
       
    41     {
       
    42     HbListWidgetItem* item( mWidget->currentItem() );
       
    43     QString text = item->text();
       
    44     QString content = item->secondaryText();
       
    45 
       
    46 	HbInputDialog *dialog = new HbInputDialog();
       
    47 	dialog->setAttribute(Qt::WA_DeleteOnClose, true); 
       
    48 	dialog->setPromptText(text);
       
    49 	dialog->setPrimaryAction(new HbAction("Ok"));
       
    50 	dialog->setSecondaryAction(new HbAction("Cancel"));
       
    51 	dialog->setInputMode(HbInputDialog::TextInput);
       
    52 	dialog->setValue(content);
       
    53 	dialog->open(this, SLOT(handleEditItem(HbAction*)));
       
    54 	}
       
    55 
       
    56 void CustomListView::handleEditItem(HbAction* action)
       
    57     {
       
    58     HbInputDialog *dialog = static_cast<HbInputDialog*>(sender());
       
    59     
       
    60     if (dialog && action == dialog->actions().first())
       
    61         {
       
    62         QString text = dialog->value().toString();
       
    63         HbListWidgetItem* item(mWidget->currentItem());
       
    64         item->setSecondaryText(text);
       
    65         mWidget->setCurrentItem(item);
       
    66         saveKeyItems();
       
    67         }
       
    68     }
       
    69 
       
    70 void CustomListView::saveKeyItems()
       
    71     {
       
    72     QString notDefined = tr("Not defined");
       
    73     XQSettingsManager* manager = new XQSettingsManager( this );
       
    74     XQSettingsKey key1( XQSettingsKey::TargetCentralRepository, 
       
    75         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsOperatorSyncServerURL );
       
    76     QVariant url = mWidget->item( 0 )->secondaryText();
       
    77     bool err = false;
       
    78     if( url.toString().compare( notDefined ) )
       
    79         {
       
    80         err = manager->writeItemValue( key1, url );
       
    81         }
       
    82     XQSettingsKey key2( XQSettingsKey::TargetCentralRepository, 
       
    83         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsOperatorAdapterUid );
       
    84     QVariant adapter = mWidget->item( 1 )->secondaryText();
       
    85     if( adapter.toString().compare( notDefined ) )
       
    86         {
       
    87         bool ok;
       
    88         int value = adapter.toString().toInt( &ok, 10 );
       
    89         if( !ok )
       
    90             {
       
    91             value = adapter.toString().toInt( &ok, 16 );
       
    92             }
       
    93         if( ok )
       
    94             {
       
    95             QVariant var( value );
       
    96             err = manager->writeItemValue( key2, var );
       
    97             }
       
    98         }
       
    99     XQSettingsKey key3( XQSettingsKey::TargetCentralRepository, 
       
   100         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsProfileAdapterUid );
       
   101     QVariant profile = mWidget->item( 2 )->secondaryText();
       
   102     if( profile.toString().compare( notDefined ) )
       
   103         {
       
   104         bool ok;
       
   105         int value = profile.toString().toInt( &ok, 10 );
       
   106         if( !ok )
       
   107             {
       
   108             value = profile.toString().toInt( &ok, 16 );
       
   109             }
       
   110         if( ok )
       
   111             {
       
   112             QVariant var( value );
       
   113             err = manager->writeItemValue( key3, var );
       
   114             }
       
   115         }
       
   116     XQSettingsKey key4( XQSettingsKey::TargetCentralRepository, 
       
   117         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsDevInfoSwVValue );
       
   118     QVariant swv = mWidget->item( 3 )->secondaryText();
       
   119     if( swv.toString().compare( notDefined ) )
       
   120         {
       
   121         err = manager->writeItemValue( key4, swv.toByteArray() );
       
   122         }
       
   123     XQSettingsKey key5( XQSettingsKey::TargetCentralRepository, 
       
   124         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsDevInfoModValue );
       
   125     QVariant mod = mWidget->item( 4 )->secondaryText();
       
   126     if( mod.toString().compare(notDefined) )
       
   127         {
       
   128         err = manager->writeItemValue( key5, mod.toByteArray() );
       
   129         }
       
   130     XQSettingsKey key6( XQSettingsKey::TargetCentralRepository, 
       
   131         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsSyncProfileVisibility );
       
   132     QVariant visibility = mWidget->item( 5 )->secondaryText();
       
   133     if( visibility.toString().compare( notDefined ) )
       
   134         {
       
   135         bool ok;
       
   136         int value = visibility.toString().toInt( &ok, 10 );
       
   137         if( !ok )
       
   138             {
       
   139             value = visibility.toString().toInt( &ok, 16 );
       
   140             }
       
   141         if( ok )
       
   142             {
       
   143             QVariant var( value );
       
   144             err = manager->writeItemValue( key6, var );
       
   145             }
       
   146         }
       
   147     XQSettingsKey key7( XQSettingsKey::TargetCentralRepository, 
       
   148         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsOperatorSyncServerId );
       
   149     QVariant serverId = mWidget->item( 6 )->secondaryText();
       
   150     if( serverId.toString().compare( notDefined ) )
       
   151         {
       
   152         err = manager->writeItemValue( key7, serverId.toByteArray() );
       
   153         }
       
   154     XQSettingsKey key8( XQSettingsKey::TargetCentralRepository, 
       
   155         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsSyncMLStatusCodeList );
       
   156     QVariant syncmlStatus = mWidget->item( 7 )->secondaryText();
       
   157     if( syncmlStatus.toString().compare( notDefined ) )
       
   158         {
       
   159         err = manager->writeItemValue( key8, syncmlStatus );
       
   160         }
       
   161     XQSettingsKey key9( XQSettingsKey::TargetCentralRepository, 
       
   162         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsDevInfoManValue );
       
   163     QVariant man = mWidget->item( 8 )->secondaryText();
       
   164     if( man.toString().compare(notDefined) )
       
   165         {
       
   166         err = manager->writeItemValue( key9, man.toByteArray() );
       
   167         }
       
   168     XQSettingsKey key10( XQSettingsKey::TargetCentralRepository, 
       
   169         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsHttpErrorReporting );
       
   170     QVariant httpErrorReporting = mWidget->item( 9 )->secondaryText();
       
   171     if( httpErrorReporting.toString().compare( notDefined ) )
       
   172         {
       
   173         bool ok;
       
   174         int value = httpErrorReporting.toString().toInt( &ok, 10 );
       
   175         if( !ok )
       
   176             {
       
   177             value = httpErrorReporting.toString().toInt( &ok, 16 );
       
   178             }
       
   179         if( ok )
       
   180             {
       
   181             QVariant var( value );
       
   182             err = manager->writeItemValue( key10, var );
       
   183             }
       
   184         } 
       
   185     XQSettingsKey key11( XQSettingsKey::TargetCentralRepository, 
       
   186         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsSyncMLErrorReporting );
       
   187     QVariant syncMLErrorReporting = mWidget->item( 10 )->secondaryText();
       
   188     if( syncMLErrorReporting.toString().compare( notDefined ) )
       
   189         {
       
   190         bool ok;
       
   191         int value = syncMLErrorReporting.toString().toInt( &ok, 10 );
       
   192         if( !ok )
       
   193             {
       
   194             value = syncMLErrorReporting.toString().toInt( &ok, 16 );
       
   195             }
       
   196         if( ok )
       
   197             {
       
   198             QVariant var( value );
       
   199             err = manager->writeItemValue( key11, var );
       
   200             }
       
   201         }
       
   202     delete manager;
       
   203     }
       
   204 
       
   205 void CustomListView::syncNow()
       
   206     {
       
   207     HbInputDialog *dialog = new HbInputDialog();
       
   208     dialog->setAttribute(Qt::WA_DeleteOnClose, true); 
       
   209     dialog->setPromptText(tr("Profile ID"));
       
   210     dialog->setPrimaryAction(new HbAction("Ok"));
       
   211     dialog->setSecondaryAction(new HbAction("Cancel"));
       
   212     dialog->setInputMode(HbInputDialog::TextInput);
       
   213     dialog->open(this, SLOT(startSync(HbAction*)));
       
   214     }
       
   215 
       
   216 void CustomListView::startSync(HbAction* action)
       
   217     {
       
   218     HbInputDialog *dialog = static_cast<HbInputDialog*>(sender());
       
   219         
       
   220     if (dialog && action == dialog->actions().first())
       
   221         {
       
   222         QString text = dialog->value().toString();
       
   223         bool ok = false;
       
   224         int profileId = text.toInt(&ok, 10);
       
   225         if (ok)
       
   226             {
       
   227             // Open syncML session
       
   228             RSyncMLSession syncMLSession;
       
   229             RSyncMLDataSyncJob job;
       
   230             CleanupClosePushL( syncMLSession );
       
   231             CleanupClosePushL( job );
       
   232             syncMLSession.OpenL();
       
   233             
       
   234             // Need instance of data sync class
       
   235             // For creating a data sync job, need to specify id of the profile used for synchronization
       
   236             // If profile selected is PCSuite, it searches for the bluetooth device to sync with
       
   237             
       
   238             job.CreateL( syncMLSession, profileId );
       
   239             // close the job
       
   240             job.Close();
       
   241             // close the syncML session
       
   242             CleanupStack::PopAndDestroy( &job );
       
   243             CleanupStack::PopAndDestroy( &syncMLSession );
       
   244             }
       
   245         }
       
   246     }
       
   247 
       
   248 void CustomListView::listSyncProfiles()
       
   249     {
       
   250     // Open syncML session
       
   251     RSyncMLSession syncMLSession;
       
   252     syncMLSession.OpenL();
       
   253     CleanupClosePushL( syncMLSession );
       
   254 
       
   255     RArray<TSmlProfileId> profiles;
       
   256     // Get the list of available profiles into an array
       
   257     syncMLSession.ListProfilesL( profiles, ESmlDataSync );
       
   258     QString text = NULL;
       
   259     for( TInt i = 0; i < profiles.Count(); i++ )
       
   260         {
       
   261         RSyncMLDataSyncProfile profile;         
       
   262         profile.OpenL( syncMLSession,profiles[i], ESmlOpenReadWrite );
       
   263         CleanupClosePushL( profile );
       
   264         text.append( QString::number( profiles[i] ) );
       
   265         text.append( tr(" ") );
       
   266         QString qname( (QChar*)profile.DisplayName().Ptr(), profile.DisplayName().Length() );
       
   267         text.append( qname );
       
   268         if( profiles.Count() != ( i + 1 ) )
       
   269             {
       
   270             text.append( tr("; ") );
       
   271             }
       
   272         CleanupStack::PopAndDestroy(& profile );      
       
   273         }
       
   274     profiles.Close();
       
   275     HbMessageBox::information(text);
       
   276     CleanupStack::PopAndDestroy( &syncMLSession );    
       
   277     }
       
   278 
       
   279 void CustomListView::resetItem()
       
   280     {
       
   281     //HbListWidgetItem* item( mWidget->currentItem() );
       
   282     CRepository* rep = CRepository::NewLC( KCRUidOperatorDatasyncInternalKeys );
       
   283     rep->Reset( mWidget->currentRow() + 1 );
       
   284     CleanupStack::PopAndDestroy( rep );
       
   285     populateModel();
       
   286     }
       
   287 
       
   288 void CustomListView::resetAll()
       
   289     {
       
   290     CRepository* rep = CRepository::NewLC( KCRUidOperatorDatasyncInternalKeys );
       
   291     rep->Reset();
       
   292     CleanupStack::PopAndDestroy( rep );  
       
   293     populateModel();
       
   294     }
       
   295 
       
   296 void CustomListView::populateModel()
       
   297     {
       
   298     HbListWidget* widget = new HbListWidget;
       
   299     XQSettingsManager* manager = new XQSettingsManager( this );
       
   300     XQSettingsKey key1( XQSettingsKey::TargetCentralRepository, 
       
   301         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsOperatorSyncServerURL );
       
   302     QString url = manager->readItemValue( key1, XQSettingsManager::TypeString ).toString();
       
   303     XQSettingsKey key2( XQSettingsKey::TargetCentralRepository, 
       
   304         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsOperatorAdapterUid );
       
   305     QString adapter = manager->readItemValue( key2, XQSettingsManager::TypeInt ).toString();
       
   306     XQSettingsKey key3( XQSettingsKey::TargetCentralRepository, 
       
   307         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsProfileAdapterUid );
       
   308     QString profile = manager->readItemValue( key3, XQSettingsManager::TypeInt ).toString();
       
   309     XQSettingsKey key4( XQSettingsKey::TargetCentralRepository, 
       
   310         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsDevInfoSwVValue );
       
   311     QString swv = manager->readItemValue( key4 ).toString();
       
   312     XQSettingsKey key5( XQSettingsKey::TargetCentralRepository, 
       
   313         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsDevInfoModValue );
       
   314     QString mod = manager->readItemValue( key5 ).toString();
       
   315     XQSettingsKey key6( XQSettingsKey::TargetCentralRepository, 
       
   316         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsSyncProfileVisibility );
       
   317     QString visibility = manager->readItemValue( key6, XQSettingsManager::TypeInt ).toString();
       
   318     XQSettingsKey key7( XQSettingsKey::TargetCentralRepository, 
       
   319         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsOperatorSyncServerId );
       
   320     QString serverId = manager->readItemValue( key7 ).toString();
       
   321     XQSettingsKey key8( XQSettingsKey::TargetCentralRepository, 
       
   322         KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsSyncMLStatusCodeList );
       
   323     QString status = manager->readItemValue( key8, XQSettingsManager::TypeString ).toString();
       
   324     XQSettingsKey key9( XQSettingsKey::TargetCentralRepository, 
       
   325           KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsDevInfoManValue );
       
   326     QString man = manager->readItemValue( key9 ).toString();
       
   327     XQSettingsKey key10( XQSettingsKey::TargetCentralRepository, 
       
   328           KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsHttpErrorReporting );
       
   329     QString httpErrorReporting = manager->readItemValue( key10 ).toString();
       
   330     XQSettingsKey key11( XQSettingsKey::TargetCentralRepository, 
       
   331               KCRUidOperatorDatasyncInternalKeys.iUid, KNsmlOpDsSyncMLErrorReporting );
       
   332     QString syncMLErrorReporting = manager->readItemValue( key11 ).toString();
       
   333     
       
   334     delete manager;
       
   335     HbListWidgetItem* result1 = new HbListWidgetItem();
       
   336     result1->setText( tr("Operator server URL") );
       
   337     if( !url.isEmpty() )
       
   338         {
       
   339         result1->setSecondaryText( url );
       
   340         }
       
   341     else
       
   342         {
       
   343         result1->setSecondaryText( tr("Not defined") );
       
   344         }
       
   345     HbListWidgetItem* result2 = new HbListWidgetItem();
       
   346     result2->setText( tr("Sync adapter UID") );
       
   347     if( !adapter.isEmpty() )
       
   348         {
       
   349         result2->setSecondaryText( adapter );
       
   350         }
       
   351     else
       
   352         {
       
   353         result2->setSecondaryText( tr("Not defined") );
       
   354         }
       
   355     HbListWidgetItem* result3 = new HbListWidgetItem();
       
   356     result3->setText( tr("Profile adapter UID") );
       
   357     if( !profile.isEmpty() )
       
   358         {
       
   359         result3->setSecondaryText( profile );
       
   360         }
       
   361     else
       
   362         {
       
   363         result3->setSecondaryText( tr("Not defined") );
       
   364         }
       
   365     HbListWidgetItem* result4 = new HbListWidgetItem();
       
   366     result4->setText( tr("Customized SwV") );
       
   367     if( !swv.isEmpty() )
       
   368         {
       
   369         result4->setSecondaryText( swv );
       
   370         }
       
   371     else
       
   372         {
       
   373         result4->setSecondaryText( tr("Not defined") );
       
   374         }
       
   375     HbListWidgetItem* result5 = new HbListWidgetItem;
       
   376     result5->setText( tr("Customized Mod") );
       
   377     if( !mod.isEmpty() )
       
   378         {
       
   379         result5->setSecondaryText( mod );
       
   380         }
       
   381     else
       
   382         {
       
   383         result5->setSecondaryText( tr("Not defined") );
       
   384         }
       
   385     HbListWidgetItem* result6 = new HbListWidgetItem;
       
   386     result6->setText( tr("Sync profile visibility") );
       
   387     if( !visibility.isEmpty() )
       
   388         {
       
   389         result6->setSecondaryText( visibility );
       
   390         }
       
   391     else
       
   392         {
       
   393         result6->setSecondaryText( tr("Not defined") );
       
   394         }
       
   395     HbListWidgetItem* result7 = new HbListWidgetItem;
       
   396     result7->setText( tr("Sync server ID") );
       
   397     if( !serverId.isEmpty() )
       
   398         {
       
   399         result7->setSecondaryText( serverId );
       
   400         }
       
   401     else
       
   402         {
       
   403         result7->setSecondaryText( tr("Not defined") );
       
   404         }
       
   405     HbListWidgetItem* result8 = new HbListWidgetItem;
       
   406     result8->setText( tr("SyncML status codes") );
       
   407     if( !status.isEmpty() )
       
   408         {
       
   409         result8->setSecondaryText( status );
       
   410         }
       
   411     else
       
   412         {
       
   413         result8->setSecondaryText( tr("Not defined") );
       
   414         }
       
   415     HbListWidgetItem* result9 = new HbListWidgetItem;
       
   416     result9->setText( tr("Customized Man") );
       
   417     if( !man.isEmpty() )
       
   418         {
       
   419         result9->setSecondaryText( man );
       
   420         }
       
   421     else
       
   422         {
       
   423         result9->setSecondaryText( tr("Not defined") );
       
   424         }
       
   425     HbListWidgetItem* result10 = new HbListWidgetItem;
       
   426     result10->setText( tr("Http error reporting") );
       
   427     if( !httpErrorReporting.isEmpty() )
       
   428         {
       
   429         result10->setSecondaryText( httpErrorReporting );
       
   430         }
       
   431     else
       
   432         {
       
   433         result10->setSecondaryText( tr("Not defined") );
       
   434         }
       
   435     HbListWidgetItem* result11 = new HbListWidgetItem;
       
   436     result11->setText( tr("SyncML error reporting") );
       
   437     if( !syncMLErrorReporting.isEmpty() )
       
   438         {
       
   439         result11->setSecondaryText( syncMLErrorReporting );
       
   440         }
       
   441     else
       
   442         {
       
   443         result11->setSecondaryText( tr("Not defined") );
       
   444         }
       
   445     widget->addItem( result1 );
       
   446     widget->addItem( result2 );
       
   447     widget->addItem( result3 );
       
   448     widget->addItem( result4 );
       
   449     widget->addItem( result5 );
       
   450     widget->addItem( result6 );
       
   451     widget->addItem( result7 );
       
   452     widget->addItem( result8 );
       
   453     widget->addItem( result9 );
       
   454     widget->addItem( result10 );
       
   455     widget->addItem( result11 );
       
   456     
       
   457     connect( widget,
       
   458     SIGNAL( activated(HbListWidgetItem*) ),
       
   459     SLOT( handleItem(HbListWidgetItem*) ) );
       
   460     connect(widget,
       
   461     SIGNAL( longPressed(HbListWidgetItem*, const QPointF&) ),
       
   462     SLOT( editItem()) );
       
   463     mWidget = widget;
       
   464     setWidget( widget );  
       
   465     }
       
   466 
       
   467 void CustomListView::createMenu()
       
   468     {
       
   469     HbMenu* theMenu = menu();
       
   470     connect( theMenu->addAction( tr("Edit")), SIGNAL( triggered() ), SLOT( editItem() ) );
       
   471     //connect( theMenu->addAction( tr("Save")), SIGNAL( triggered() ), SLOT( saveKeyItems() ) );
       
   472     connect( theMenu->addAction( tr("List profiles")), SIGNAL( triggered() ), SLOT( listSyncProfiles() ) );
       
   473     connect( theMenu->addAction( tr("Sync now")), SIGNAL( triggered() ), SLOT( syncNow() ) );
       
   474     HbMenu* subMenu = theMenu->addMenu(tr("Reset"));
       
   475     connect( subMenu->addAction( tr("Reset item")), SIGNAL( triggered() ), SLOT( resetItem() ) );
       
   476     connect( subMenu->addAction( tr("Reset All")), SIGNAL( triggered() ), SLOT( resetAll() ) );
       
   477     }
       
   478