searchui/stateproviders/searchstateprovider/src/settingswidget.cpp
changeset 16 e918432ddd92
parent 15 df6898e696c6
child 21 708468d5143e
equal deleted inserted replaced
15:df6898e696c6 16:e918432ddd92
    13  *
    13  *
    14  * Description:  Implementation of the settings widget
    14  * Description:  Implementation of the settings widget
    15  *
    15  *
    16  */
    16  */
    17 #include "settingswidget.h"
    17 #include "settingswidget.h"
       
    18 #include "onlinehandler.h"
    18 #include <hbdialog.h>
    19 #include <hbdialog.h>
    19 #include <hbcheckbox.h>
    20 #include <hbcheckbox.h>
    20 #include <qgraphicslinearlayout.h>
    21 #include <qgraphicslinearlayout.h>
    21 #include <hbaction.h>
    22 #include <hbaction.h>
    22 #include <hblabel.h>
    23 #include <hblabel.h>
    36 #include <qdir.h>
    37 #include <qdir.h>
    37 #include <qsql.h>
    38 #include <qsql.h>
    38 #include <qsqldatabase.h>
    39 #include <qsqldatabase.h>
    39 #include <qsqlquery.h>
    40 #include <qsqlquery.h>
    40 #include <cpixcontentinfocommon.h>
    41 #include <cpixcontentinfocommon.h>
    41 #include "onlinehandler.h"
    42 
    42 const char *DELIMETER_DOCML = ":/xml/delimeterscreen.docml";
    43 const char *DELIMETER_DOCML = ":/xml/delimeterscreen.docml";
    43 const char *DIALOG = "dialog";
    44 const char *DIALOG = "dialog";
    44 const char *DATAFORM = "dataForm";
    45 const char *DATAFORM = "dataForm";
    45 
    46 
    46 //----------------------------------------------------------------------------------------------------------------------------
    47 //----------------------------------------------------------------------------------------------------------------------------
    54     {
    55     {
    55     for (int i = 0; i < 8; i++)
    56     for (int i = 0; i < 8; i++)
    56         {
    57         {
    57         mDeviceMapping.append(false);
    58         mDeviceMapping.append(false);
    58         }
    59         }
    59 
       
    60     mDeviceCategoryRefList = (QStringList() << "first" << "second" << "third"
    60     mDeviceCategoryRefList = (QStringList() << "first" << "second" << "third"
    61             << "fourth" << "fifth" << "sixth" << "seventh" << "eigth");
    61             << "fourth" << "fifth" << "sixth" << "seventh" << "eigth");
    62 
    62 
    63     mchangestate = true;
    63     mchangestate = true;
    64     mInstialize = true;
    64     mInstialize = true;
    65     isInternetSelected = false;
    65     isInternetSelected = false;
    66 
       
    67     storeDefaultSettings();
    66     storeDefaultSettings();
    68     }
    67     }
    69 //----------------------------------------------------------------------------------------------------------------------------
    68 //----------------------------------------------------------------------------------------------------------------------------
    70 //SettingsWidget::intialize()
    69 //SettingsWidget::intialize()
    71 //
    70 //
    81     QGraphicsWidget *widget = NULL;
    80     QGraphicsWidget *widget = NULL;
    82     if (!popup)
    81     if (!popup)
    83         {
    82         {
    84         widget = mDocumentLoader->findWidget(DIALOG);
    83         widget = mDocumentLoader->findWidget(DIALOG);
    85         Q_ASSERT_X(ok && (widget != 0), "DIALOG", "invalid view");
    84         Q_ASSERT_X(ok && (widget != 0), "DIALOG", "invalid view");
    86 
       
    87         popup = qobject_cast<HbDialog*> (widget);
    85         popup = qobject_cast<HbDialog*> (widget);
    88         }
    86         }
    89     if (!dataform)
    87     if (!dataform)
    90         {
    88         {
    91         widget = mDocumentLoader->findWidget(DATAFORM);
    89         widget = mDocumentLoader->findWidget(DATAFORM);
    98         }
    96         }
    99     if (!signalMapper)
    97     if (!signalMapper)
   100         {
    98         {
   101         signalMapper = new QSignalMapper(this);
    99         signalMapper = new QSignalMapper(this);
   102         }
   100         }
   103 
       
   104     createGui();
   101     createGui();
   105     }
   102     }
   106 //----------------------------------------------------------------------------------------------------------------------------
   103 //----------------------------------------------------------------------------------------------------------------------------
   107 //SettingsWidget::createGui()
   104 //SettingsWidget::createGui()
   108 //
   105 //
   234                 = static_cast<HbRadioButtonList*> (formItem->dataItemContentWidget());
   231                 = static_cast<HbRadioButtonList*> (formItem->dataItemContentWidget());
   235 
   232 
   236         connect(mradiolist, SIGNAL(itemSelected(int)), this,
   233         connect(mradiolist, SIGNAL(itemSelected(int)), this,
   237                 SLOT(slotitemSelected(int)));
   234                 SLOT(slotitemSelected(int)));
   238         }
   235         }
       
   236     setActionVisibility();
   239     }
   237     }
   240 //----------------------------------------------------------------------------------------------------------------------------
   238 //----------------------------------------------------------------------------------------------------------------------------
   241 //SettingsWidget::preparecategories()
   239 //SettingsWidget::preparecategories()
   242 //
   240 //
   243 //----------------------------------------------------------------------------------------------------------------------------
   241 //----------------------------------------------------------------------------------------------------------------------------
   244 void SettingsWidget::preparecategories()
   242 void SettingsWidget::preparecategories()
   245     {
   243     {
   246     // read form database
   244     // read form database
   247     QString mConnectionName("cpixcontentinfo.sq");
   245 
   248     QString mDatabaseName("c:\\Private\\2001f6fb\\cpixcontentinfo.sq");
   246     mDeviceListDisplay.clear();
       
   247     mCategoryList.clear();
       
   248     mDeviceMapping.clear();
       
   249     for (int i = 0; i < 8; i++)
       
   250         {
       
   251         mDeviceMapping.append(false);
       
   252         }
       
   253     mCategoryDbMapping.clear();
       
   254 
       
   255     QString mConnectionName(QString::fromUtf16(KContentInfoFileName().Ptr(),
       
   256             KContentInfoFileName().Length()));
       
   257     QString mDatabaseName(QString::fromUtf16(KCIDBPath().Ptr(),
       
   258             KCIDBPath().Length()) + "\\" + mConnectionName);
   249 
   259 
   250     QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", mConnectionName);
   260     QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", mConnectionName);
   251     db.setDatabaseName(mDatabaseName);
   261     db.setDatabaseName(mDatabaseName);
   252 
   262 
   253     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   263     QSqlQuery query(QSqlDatabase::database(mConnectionName));
   254     QString statement = "SELECT NAME FROM table1";
   264     QString statement = QString("SELECT * FROM ") + QString::fromUtf16(
   255 
   265             KContentInfoTableName().Ptr(), KContentInfoTableName().Length());
   256     query.prepare(statement);
   266     query.prepare(statement);
   257     query.exec();
   267     query.exec();
   258     while (query.next())
   268     while (query.next())
   259         {
   269         {
   260         QString category_name = query.value(0).toString();
   270         QString category_name = query.value(0).toString();
   265             }
   275             }
   266         else
   276         else
   267             {
   277             {
   268             mCategoryDbMapping.insert(category_name, true);
   278             mCategoryDbMapping.insert(category_name, true);
   269             }
   279             }
   270         qDebug() << "string db= " << category_name;
       
   271         }
   280         }
   272     db.close();
   281     db.close();
   273 
   282 
   274     /*  mCategoryDbMapping.insert("Contacts", true); 
   283     /*  mCategoryDbMapping.insert("Contacts", true); 
   275      mCategoryDbMapping.insert("Audios", true); 
   284      mCategoryDbMapping.insert("Audios", true); 
   281      mCategoryDbMapping.insert("Notes", true); 
   290      mCategoryDbMapping.insert("Notes", true); 
   282      mCategoryDbMapping.insert("Applications", true); 
   291      mCategoryDbMapping.insert("Applications", true); 
   283      mCategoryDbMapping.insert("Bookmarks", true); 
   292      mCategoryDbMapping.insert("Bookmarks", true); 
   284      mCategoryDbMapping.insert("Files", true); */
   293      mCategoryDbMapping.insert("Files", true); */
   285 
   294 
   286     // mCategoryDbMapping.insert("email", true); // to remove once email starts working
       
   287 
       
   288     mDeviceListDisplay.append(hbTrId("txt_search_list_select_all"));
   295     mDeviceListDisplay.append(hbTrId("txt_search_list_select_all"));
   289     mDeviceMapping.insert(0, true);
   296     mDeviceMapping.insert(0, true);
   290 
   297 
   291     if (mCategoryDbMapping.value("Contacts"))
   298     if (mCategoryDbMapping.value("Contacts"))
   292         {
   299         {
   293         mDeviceMapping.insert(1, true);
   300         mDeviceMapping.insert(1, true);
   294         mDeviceListDisplay.append(hbTrId("txt_search_list_contatcs"));
   301         mDeviceListDisplay.append(hbTrId("txt_search_list_contatcs"));
   295         }
   302         }
   296 
       
   297     if (mCategoryDbMapping.value("Audios") || mCategoryDbMapping.value(
   303     if (mCategoryDbMapping.value("Audios") || mCategoryDbMapping.value(
   298             "Images") || mCategoryDbMapping.value("Videos"))
   304             "Images") || mCategoryDbMapping.value("Videos"))
   299         {
   305         {
   300         mDeviceListDisplay.append(hbTrId("txt_search_list_media"));
   306         mDeviceListDisplay.append(hbTrId("txt_search_list_media"));
   301         mDeviceMapping.insert(2, true);
   307         mDeviceMapping.insert(2, true);
   302         }
   308         }
   303 
       
   304     if (mCategoryDbMapping.value("Messages") || mCategoryDbMapping.value(
   309     if (mCategoryDbMapping.value("Messages") || mCategoryDbMapping.value(
   305             "email"))
   310             "email"))
   306         {
   311         {
   307         mDeviceListDisplay.append(hbTrId("txt_search_list_messagemail"));
   312         mDeviceListDisplay.append(hbTrId("txt_search_list_messagemail"));
   308         mDeviceMapping.insert(3, true);
   313         mDeviceMapping.insert(3, true);
   309         }
   314         }
   310 
       
   311     if (mCategoryDbMapping.value("Calendar") || mCategoryDbMapping.value(
   315     if (mCategoryDbMapping.value("Calendar") || mCategoryDbMapping.value(
   312             "Notes"))
   316             "Notes"))
   313         {
   317         {
   314         mDeviceListDisplay.append(hbTrId("txt_search_list_calendarnotes"));
   318         mDeviceListDisplay.append(hbTrId("txt_search_list_calendarnotes"));
   315         mDeviceMapping.insert(4, true);
   319         mDeviceMapping.insert(4, true);
   316         }
   320         }
   317 
       
   318     if (mCategoryDbMapping.value("Applications"))
   321     if (mCategoryDbMapping.value("Applications"))
   319         {
   322         {
   320         mDeviceListDisplay.append(hbTrId("txt_search_list_applications"));
   323         mDeviceListDisplay.append(hbTrId("txt_search_list_applications"));
   321         mDeviceMapping.insert(5, true);
   324         mDeviceMapping.insert(5, true);
   322         }
   325         }
   323 
       
   324     if (mCategoryDbMapping.value("Bookmarks"))
   326     if (mCategoryDbMapping.value("Bookmarks"))
   325         {
   327         {
   326         mDeviceListDisplay.append(hbTrId("txt_search_list_bookmarks"));
   328         mDeviceListDisplay.append(hbTrId("txt_search_list_bookmarks"));
   327         mDeviceMapping.insert(6, true);
   329         mDeviceMapping.insert(6, true);
   328         }
   330         }
   329 
       
   330     if (mCategoryDbMapping.value("Files"))
   331     if (mCategoryDbMapping.value("Files"))
   331         {
   332         {
   332         mDeviceListDisplay.append(hbTrId("txt_search_list_all_other_files"));
   333         mDeviceListDisplay.append(hbTrId("txt_search_list_all_other_files"));
   333         mDeviceMapping.insert(7, true);
   334         mDeviceMapping.insert(7, true);
   334         }
   335         }
   335     // internetCategoryList = (QStringList() << "Google" << "Bing" << "Yahoo");
       
   336 
   336 
   337     if (mServiceProviders.count())
   337     if (mServiceProviders.count())
   338         {
   338         {
   339         mCategoryList = (QStringList() << hbTrId("txt_search_list_device")
   339         mCategoryList = (QStringList() << hbTrId("txt_search_list_device")
   340                 << hbTrId("txt_search_list_internet"));
   340                 << hbTrId("txt_search_list_internet"));
   342     else
   342     else
   343         {
   343         {
   344         mCategoryList = (QStringList() << hbTrId("txt_search_list_device"));
   344         mCategoryList = (QStringList() << hbTrId("txt_search_list_device"));
   345         }
   345         }
   346     }
   346     }
   347 
       
   348 //----------------------------------------------------------------------------------------------------------------------------
   347 //----------------------------------------------------------------------------------------------------------------------------
   349 //SettingsWidget::~SettingsWidget()
   348 //SettingsWidget::~SettingsWidget()
   350 //
   349 //
   351 //----------------------------------------------------------------------------------------------------------------------------
   350 //----------------------------------------------------------------------------------------------------------------------------
   352 SettingsWidget::~SettingsWidget()
   351 SettingsWidget::~SettingsWidget()
   353     {
   352     {
   354     delete signalMapper;
   353     delete signalMapper;
   355     //delete popup;
       
   356     //delete dataform;
       
   357     delete mModel;
   354     delete mModel;
   358     //delete mradiolist;
       
   359     mDeviceCheckBoxList.clear();
   355     mDeviceCheckBoxList.clear();
   360     mInternetCheckBoxList.clear();
   356     mInternetCheckBoxList.clear();
   361     mModelItemList.clear();
   357     mModelItemList.clear();
   362     mActions.clear();
   358     mActions.clear();
   363     delete mDocumentLoader;
   359     delete mDocumentLoader;
   364     delete mInternetHandler;
   360     delete mInternetHandler;
   365     //delete popup;
       
   366     }
   361     }
   367 //----------------------------------------------------------------------------------------------------------------------------
   362 //----------------------------------------------------------------------------------------------------------------------------
   368 //SettingsWidget::launchSettingWidget()
   363 //SettingsWidget::launchSettingWidget()
   369 //
   364 //
   370 //----------------------------------------------------------------------------------------------------------------------------
   365 //----------------------------------------------------------------------------------------------------------------------------
   373     if (mInstialize)
   368     if (mInstialize)
   374         {
   369         {
   375         initialize();
   370         initialize();
   376         mInstialize = false;
   371         mInstialize = false;
   377         }
   372         }
       
   373     if (mDeviceListDisplay.count() != 7)
       
   374         {
       
   375         preparecategories();
       
   376         q_currentIndexChanged(mSelectedScope);
       
   377         QDir dir;
       
   378         dir.remove(SETTINGS_INI_PATH);
       
   379         storeDefaultSettings();
       
   380         }
       
   381     // refresh the screen to top     
       
   382     QModelIndex index = mModel->index(0, 0);
       
   383     dataform->scrollTo(index);
   378     comboBox->setCurrentIndex(mSelectedScope);
   384     comboBox->setCurrentIndex(mSelectedScope);
   379     loadDeviceSettings();
   385     loadDeviceSettings();
   380     setActionVisibility();
   386     setActionVisibility();
   381     popup->show();
   387     popup->show();
   382     }
   388     }
   390     for (int i = 0; i < mDeviceCheckBoxList.count(); i++)
   396     for (int i = 0; i < mDeviceCheckBoxList.count(); i++)
   391         {
   397         {
   392         if (mDeviceCheckBoxList.at(i)->checkState() == Qt::Checked)
   398         if (mDeviceCheckBoxList.at(i)->checkState() == Qt::Checked)
   393             {
   399             {
   394             noItemSelected = false;
   400             noItemSelected = false;
       
   401             break;
   395             }
   402             }
   396         }
   403         }
   397     if (!isInternetSelected)
   404     if (!isInternetSelected)
   398         {
   405         {
   399         mActions.at(0)->setVisible(true);
   406         mActions.at(0)->setVisible(true);
   400 
       
   401         if (noItemSelected)
   407         if (noItemSelected)
   402             {
   408             {
   403             mActions.at(0)->setVisible(false);
   409             mActions.at(0)->setVisible(false);
   404             }
   410             }
       
   411         }
       
   412     else
       
   413         {
       
   414         mActions.at(0)->setVisible(true);
   405         }
   415         }
   406     }
   416     }
   407 //----------------------------------------------------------------------------------------------------------------------------
   417 //----------------------------------------------------------------------------------------------------------------------------
   408 //SettingsWidget::itemChecked( int selectedIndex)
   418 //SettingsWidget::itemChecked( int selectedIndex)
   409 //
   419 //
   513             else
   523             else
   514                 {
   524                 {
   515                 appSettings.setValue(mDeviceCategoryRefList.at(i), 0);
   525                 appSettings.setValue(mDeviceCategoryRefList.at(i), 0);
   516                 emit selectedItemCategory(i, false);
   526                 emit selectedItemCategory(i, false);
   517                 }
   527                 }
   518 
   528             }
   519             }
   529         }
   520         }
       
   521 
       
   522     }
   530     }
   523 //----------------------------------------------------------------------------------------------------------------------------
   531 //----------------------------------------------------------------------------------------------------------------------------
   524 //void SettingsWidget::loadBaseSettings()
   532 //void SettingsWidget::loadBaseSettings()
   525 //
   533 //
   526 //----------------------------------------------------------------------------------------------------------------------------
   534 //----------------------------------------------------------------------------------------------------------------------------
   545         int j = 0;
   553         int j = 0;
   546         for (int i = 0; i < mDeviceCategoryRefList.count(); i++)
   554         for (int i = 0; i < mDeviceCategoryRefList.count(); i++)
   547             {
   555             {
   548             value
   556             value
   549                     = appSettings.value(mDeviceCategoryRefList.at(i), 1).toInt();
   557                     = appSettings.value(mDeviceCategoryRefList.at(i), 1).toInt();
   550 
       
   551             if (mDeviceMapping.count() && mDeviceCheckBoxList.count()
   558             if (mDeviceMapping.count() && mDeviceCheckBoxList.count()
   552                     && mDeviceMapping.at(i))
   559                     && mDeviceMapping.at(i))
   553                 {
   560                 {
   554                 if (value)
   561                 if (value)
   555                     {
   562                     {
   562                 j++;
   569                 j++;
   563                 }
   570                 }
   564             value
   571             value
   565                   ? (emit selectedItemCategory(i, true))
   572                   ? (emit selectedItemCategory(i, true))
   566                      : (emit selectedItemCategory(i, false));
   573                      : (emit selectedItemCategory(i, false));
   567 
       
   568             }
   574             }
   569         }
   575         }
   570     }
   576     }
   571 //----------------------------------------------------------------------------------------------------------------------------
   577 //----------------------------------------------------------------------------------------------------------------------------
   572 //SettingsWidget::isInternetSearchOptionSelected()
   578 //SettingsWidget::isInternetSearchOptionSelected()
   575 bool SettingsWidget::isInternetSearchOptionSelected()
   581 bool SettingsWidget::isInternetSearchOptionSelected()
   576     {
   582     {
   577     loadBaseSettings();
   583     loadBaseSettings();
   578     return isInternetSelected;
   584     return isInternetSelected;
   579     }
   585     }
   580 
       
   581 //----------------------------------------------------------------------------------------------------------------------------
   586 //----------------------------------------------------------------------------------------------------------------------------
   582 //void SettingsWidget::storeDefaultSettings()
   587 //void SettingsWidget::storeDefaultSettings()
   583 //
   588 //
   584 //----------------------------------------------------------------------------------------------------------------------------
   589 //----------------------------------------------------------------------------------------------------------------------------
   585 void SettingsWidget::storeDefaultSettings()
   590 void SettingsWidget::storeDefaultSettings()
   592         appSettings.setValue("devicecount", mDeviceCategoryRefList.count());
   597         appSettings.setValue("devicecount", mDeviceCategoryRefList.count());
   593         for (int i = 0; i < mDeviceCategoryRefList.count(); i++)
   598         for (int i = 0; i < mDeviceCategoryRefList.count(); i++)
   594             appSettings.setValue(mDeviceCategoryRefList.at(i), 1);
   599             appSettings.setValue(mDeviceCategoryRefList.at(i), 1);
   595         }
   600         }
   596     }
   601     }
       
   602 //----------------------------------------------------------------------------------------------------------------------------
       
   603 //void SettingsWidget::slotproviderDetails()
       
   604 //
       
   605 //----------------------------------------------------------------------------------------------------------------------------
   597 void SettingsWidget::slotproviderDetails(QString name, HbIcon icon, int id)
   606 void SettingsWidget::slotproviderDetails(QString name, HbIcon icon, int id)
   598     {
   607     {
   599     mServiceProviders.insert(id, name);
   608     mServiceProviders.insert(id, name);
   600     emit ISProvidersIcon(icon, id);
   609     emit ISProvidersIcon(icon, id);
   601     }
   610     }
       
   611 //----------------------------------------------------------------------------------------------------------------------------
       
   612 //void SettingsWidget::slotdefaultProvider()
       
   613 //
       
   614 //----------------------------------------------------------------------------------------------------------------------------
   602 void SettingsWidget::slotdefaultProvider(const int value)
   615 void SettingsWidget::slotdefaultProvider(const int value)
   603     {
   616     {
   604     mSelectedProvider = value;
   617     mSelectedProvider = value;
   605     }
   618     }
       
   619 //----------------------------------------------------------------------------------------------------------------------------
       
   620 //void SettingsWidget::slotitemSelected()
       
   621 //
       
   622 //----------------------------------------------------------------------------------------------------------------------------
   606 void SettingsWidget::slotitemSelected(int value)
   623 void SettingsWidget::slotitemSelected(int value)
   607     {
   624     {
   608     QMapIterator<int, QString> i(mServiceProviders);
   625     QMapIterator<int, QString> i(mServiceProviders);
   609     int selectedindex = 0;
   626     int selectedindex = 0;
   610     while (i.hasNext())
   627     while (i.hasNext())
   616             break;
   633             break;
   617             }
   634             }
   618         selectedindex++;
   635         selectedindex++;
   619         }
   636         }
   620     }
   637     }
       
   638 //----------------------------------------------------------------------------------------------------------------------------
       
   639 //void SettingsWidget::loadIS()
       
   640 //
       
   641 //----------------------------------------------------------------------------------------------------------------------------
   621 void SettingsWidget::loadIS()
   642 void SettingsWidget::loadIS()
   622     {
   643     {
   623     if (!mInternetHandler)
   644     if (!mInternetHandler)
   624         {
   645         {
   625         mInternetHandler = new OnlineHandler();
   646         mInternetHandler = new OnlineHandler();