phonebookui/cntcommonui/views/cntimportsview.cpp
changeset 81 640d30f4fb64
parent 72 6abfb1094884
equal deleted inserted replaced
77:c18f9fa7f42e 81:640d30f4fb64
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  
    14 * Description:  
    15 *
    15 *
    16 */
    16 */
    17 
       
    18 #include <QString.h>
       
    19 
       
    20 #include "cntimportsview.h"
    17 #include "cntimportsview.h"
       
    18 #include "cntsimengine.h"
       
    19 
    21 #include "cntglobal.h"
    20 #include "cntglobal.h"
    22 
    21 #include <cntdebug.h>
    23 #include "cntsimengine.h"
    22 
    24 
       
    25 #include <hbpushbutton.h>
       
    26 #include <hbaction.h>
    23 #include <hbaction.h>
    27 #include <hbview.h>
    24 #include <hbview.h>
    28 #include <hbmenu.h>
       
    29 #include <hbframebackground.h>
    25 #include <hbframebackground.h>
    30 #include <QStandardItemModel>
       
    31 #include <hbmainwindow.h>
       
    32 #include <hblabel.h>
       
    33 #include <hblistview.h>
    26 #include <hblistview.h>
    34 #include <QTimer>
       
    35 #include <hbnotificationdialog.h>
       
    36 #include <hbmessagebox.h>
       
    37 #include <hbprogressbar.h>
       
    38 #include <QGraphicsLinearLayout>
       
    39 #include <hbframebackground.h>
       
    40 #include <hbabstractviewitem.h>
       
    41 #include <hbextendedlocale.h>
    27 #include <hbextendedlocale.h>
    42 #include <hbparameterlengthlimiter.h>
    28 #include <hbparameterlengthlimiter.h>
    43 #include <hblistviewitem.h>
    29 #include <hblistviewitem.h>
    44 #include <hbstringutil.h>
    30 #include <hbdevicenotificationdialog.h>
       
    31 #include <hbprogressdialog.h>
       
    32 
       
    33 #include <QTimer>
       
    34 #include <QStandardItemModel>
    45 #include <QCoreApplication>
    35 #include <QCoreApplication>
    46 #include <hbdevicenotificationdialog.h>
       
    47 #include <cntdebug.h>
       
    48 
    36 
    49 const char *CNT_IMPORT_UI_XML = ":/xml/contacts_sim.docml";
    37 const char *CNT_IMPORT_UI_XML = ":/xml/contacts_sim.docml";
    50 
    38 
    51 CntImportsView::CntImportsView() : mViewManager(0),
    39 /*!
    52     mSimEngine(0),
    40 Constructor
    53     mListView(0),
    41 */
    54     mView(0),
    42 CntImportsView::CntImportsView() :
    55     mSoftkey(0),
    43     mViewManager(NULL),
    56     mModel(0),
    44     mSimEngine(NULL),
    57     mImportSimPopup(0),
    45     mListView(NULL),
    58     mEngine(0)
    46     mView(NULL),
    59 {
    47     mSoftkey(NULL),
    60     CNT_ENTRY
    48     mModel(NULL),
    61     CNT_LOG_ARGS(QString("All bools reset"));
    49     mImportSimPopup(NULL),
       
    50     mEngine(NULL)
       
    51 {
       
    52     CNT_ENTRY
       
    53 
    62     bool ok = false;
    54     bool ok = false;
    63     mDocumentLoader.load(CNT_IMPORT_UI_XML, &ok);
    55     mDocumentLoader.load(CNT_IMPORT_UI_XML, &ok);
    64 
    56 
    65     if (ok)
    57     if (ok)
    66     {
    58     {
    70     {
    62     {
    71         qFatal("Unable to read :/xml/contacts_sim.docml");
    63         qFatal("Unable to read :/xml/contacts_sim.docml");
    72     }
    64     }
    73     
    65     
    74     mSimEngine = new CntSimEngine(*this, *mView);
    66     mSimEngine = new CntSimEngine(*this, *mView);
       
    67     connect(mSimEngine, SIGNAL(showNamesView()), this, SLOT(showPreviousView()));
       
    68     connect(mSimEngine, SIGNAL(closePopup()), this, SLOT(closeImportPopup()));
    75 
    69 
    76     //back button
    70     //back button
    77     mSoftkey = new HbAction(Hb::BackNaviAction, mView);
    71     mSoftkey = new HbAction(Hb::BackNaviAction, mView);
    78     connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
    72     connect(mSoftkey, SIGNAL(triggered()), this, SLOT(showPreviousView()));
    79     connect(mSimEngine, SIGNAL(showNamesView()), this, SLOT(showPreviousView()));
    73 
    80     connect(mSimEngine, SIGNAL(closePopup()), this, SLOT(closeImportPopup()));
    74     CNT_EXIT
    81     CNT_EXIT
    75 }
    82       
    76 
    83 }
    77 /*!
    84 
    78 Destructor
    85 void CntImportsView::deactivate()
    79 */
    86 {
       
    87 }
       
    88 
       
    89    
       
    90 CntImportsView::~CntImportsView()
    80 CntImportsView::~CntImportsView()
    91 {
    81 {
    92     CNT_ENTRY
    82     CNT_ENTRY
       
    83     
    93     mView->deleteLater();
    84     mView->deleteLater();
    94     delete mModel;
    85     delete mModel;
    95     delete mSimEngine;
    86     delete mSimEngine;
    96     CNT_EXIT
    87     
    97 }
       
    98 
       
    99 /*!
       
   100 Activates a previous view
       
   101 */
       
   102 void CntImportsView::showPreviousView()
       
   103 {
       
   104     CNT_ENTRY
       
   105     CntViewParameters args;
       
   106     mViewManager->back(args);
       
   107     CNT_EXIT
       
   108 }
       
   109 
       
   110 void CntImportsView::closeImportPopup()
       
   111 {
       
   112     CNT_ENTRY
       
   113     if (mImportSimPopup != NULL)
       
   114     {
       
   115         mImportSimPopup->close();
       
   116         mImportSimPopup = NULL;     // Dilaog is deleted on close()
       
   117     }
       
   118     CNT_EXIT
    88     CNT_EXIT
   119 }
    89 }
   120 
    90 
   121 /*
    91 /*
   122 Activates a default view
    92 Activates a default view
   166     mListView->setSelectionMode(HbAbstractItemView::NoSelection);
   136     mListView->setSelectionMode(HbAbstractItemView::NoSelection);
   167     connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(userCancelsImport()));
   137     connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(userCancelsImport()));
   168     CNT_EXIT
   138     CNT_EXIT
   169 }
   139 }
   170 
   140 
   171 
   141 void CntImportsView::deactivate()
       
   142 {
       
   143     
       
   144 }
       
   145 
       
   146 /*!
       
   147 Returns the contact manager
       
   148 */
       
   149 QContactManager *CntImportsView::contactSymbianManager()
       
   150 {
       
   151     if (mSimEngine)
       
   152     {
       
   153         return mSimEngine->contactSymbianManager();
       
   154     }
       
   155     
       
   156     return NULL;
       
   157 }
       
   158 
       
   159 /*!
       
   160 Activates a previous view
       
   161 */
       
   162 void CntImportsView::showPreviousView()
       
   163 {
       
   164     CNT_ENTRY
       
   165     
       
   166     CntViewParameters args;
       
   167     mViewManager->back(args);
       
   168     
       
   169     CNT_EXIT
       
   170 }
       
   171 
       
   172 /*!
       
   173 Close the import popup
       
   174 */
       
   175 void CntImportsView::closeImportPopup()
       
   176 {
       
   177     CNT_ENTRY
       
   178     
       
   179     if (mImportSimPopup != NULL)
       
   180     {
       
   181         mImportSimPopup->close();
       
   182         mImportSimPopup = NULL;
       
   183     }
       
   184     
       
   185     CNT_EXIT
       
   186 }
       
   187 
       
   188 /*!
       
   189 Called when list item is activated
       
   190 */
   172 void CntImportsView::onListViewActivated(const QModelIndex &index)
   191 void CntImportsView::onListViewActivated(const QModelIndex &index)
   173 {
   192 {
   174     CNT_ENTRY
   193     CNT_ENTRY
       
   194     
   175     int row = index.row();
   195     int row = index.row();
   176     if ( row == 0 ) // row 0 has "Imports from SIM" 
   196     if ( row == 0 ) // row 0 has "Imports from SIM" 
   177     {
   197     {
   178        if (!mSimEngine->startSimImport())
   198         if (!mSimEngine->startSimImport())
   179        {
   199         {
   180            //show error note
   200             //show error note
   181            mSimEngine->simInfoErrorMessage(KErrAccessDenied);
   201             mSimEngine->simInfoErrorMessage(KErrAccessDenied);
   182        }
   202         }
   183        else
   203         else
   184        {
   204         {
   185            //start popup and progress
   205             //start popup and progress
   186            showWaitNote();
   206             showWaitNote();
   187        }
   207         }
   188     }        
   208     }
   189     CNT_EXIT
   209 
   190     
   210     CNT_EXIT
   191  }
   211 }
   192 
   212 
       
   213 /*!
       
   214 Called when importing is cancelled
       
   215 */
       
   216 void CntImportsView::userCancelsImport()
       
   217 {   
       
   218     CNT_ENTRY
       
   219     
       
   220     QString results;
       
   221     
       
   222     if(mSimEngine->userCancelsImport(results))
       
   223     {
       
   224         HbDeviceNotificationDialog::notification(QString(),results);
       
   225     }
       
   226     
       
   227     CNT_EXIT
       
   228 }
       
   229 
       
   230 /*!
       
   231 Display the wait note
       
   232 */
   193 void CntImportsView::showWaitNote()
   233 void CntImportsView::showWaitNote()
   194 {
   234 {
   195     CNT_ENTRY
   235     CNT_ENTRY
   196     mImportSimPopup = new HbDialog();    
   236     
       
   237     mImportSimPopup = new HbProgressDialog(HbProgressDialog::WaitDialog);    
   197     mImportSimPopup->setDismissPolicy(HbPopup::NoDismiss);
   238     mImportSimPopup->setDismissPolicy(HbPopup::NoDismiss);
   198     mImportSimPopup->setTimeout(HbPopup::NoTimeout);
   239     mImportSimPopup->setTimeout(HbPopup::NoTimeout);
   199     mImportSimPopup->setBackgroundFaded(true);
   240     mImportSimPopup->setBackgroundFaded(true);
   200     mImportSimPopup->setAttribute(Qt::WA_DeleteOnClose, true);
   241     mImportSimPopup->setAttribute(Qt::WA_DeleteOnClose, true);
   201     
   242     
   202     HbLabel *headingLabel = new HbLabel(mImportSimPopup);
   243     mImportSimPopup->setHeadingText(hbTrId("txt_phob_title_import_contacts"));
   203     headingLabel->setPlainText(hbTrId("txt_phob_title_import_contacts")); 
   244     mImportSimPopup->setIcon(HbIcon("qtg_large_sim"));
   204     mImportSimPopup->setHeadingWidget(headingLabel);
   245     mImportSimPopup->setText(hbTrId("txt_phob_info_importing_contacts_from_sim"));
   205     
   246     
   206     QGraphicsLinearLayout *containerLayout = new QGraphicsLinearLayout(Qt::Vertical);
   247     connect(mImportSimPopup, SIGNAL(cancelled()), mSimEngine, SLOT(stopSimImport()));
   207     containerLayout->setContentsMargins(0, 0, 0, 0);
   248 
   208     containerLayout->setSpacing(10);
   249     mImportSimPopup->show();
   209     
   250     
   210     HbLabel *icon = new HbLabel(mImportSimPopup);
   251     CNT_EXIT
   211     icon->setIcon(HbIcon("qtg_large_sim"));  
   252 }
   212     
   253 
   213     HbLabel *simText= new HbLabel(mImportSimPopup);
   254 /*!
   214     simText->setPlainText(hbTrId("txt_phob_info_importing_contacts_from_sim")); 
   255 Set preferred details for the given contact
   215     simText->setTextWrapping(Hb::TextWordWrap);
   256 */
   216     simText->setElideMode(Qt::ElideNone);
       
   217     
       
   218     HbProgressBar *progressBar = new HbProgressBar(mImportSimPopup);
       
   219     progressBar->setRange(0,0); 
       
   220     
       
   221     HbPushButton *stopButton = new HbPushButton(mImportSimPopup);
       
   222     stopButton->setText(hbTrId("txt_phob_button_cancel"));
       
   223     connect(stopButton, SIGNAL(clicked()), mSimEngine, SLOT(stopSimImport()));
       
   224     
       
   225     QGraphicsLinearLayout *containerLayout1 = new QGraphicsLinearLayout(Qt::Horizontal);
       
   226     containerLayout1->addItem(icon);
       
   227     containerLayout1->addItem(simText);
       
   228     
       
   229     QGraphicsWidget *containerWidget = new QGraphicsWidget;    
       
   230     containerLayout->addItem(containerLayout1);
       
   231     containerLayout->addItem(progressBar);
       
   232     containerLayout->addItem(stopButton);  
       
   233     containerWidget->setLayout(containerLayout);
       
   234     mImportSimPopup->setContentWidget(containerWidget);
       
   235     mImportSimPopup->open();
       
   236     CNT_EXIT
       
   237 }
       
   238 
       
   239 void CntImportsView::setPreferredDetails( QContact *aContact )
   257 void CntImportsView::setPreferredDetails( QContact *aContact )
   240 {
   258 {
   241     CNT_ENTRY
   259     CNT_ENTRY
       
   260     
   242     mSimEngine->setPreferredDetails(*aContact);
   261     mSimEngine->setPreferredDetails(*aContact);
   243     CNT_EXIT
   262     
   244 }
   263     CNT_EXIT
   245 
   264 }
   246 
       
   247 void CntImportsView::userCancelsImport()
       
   248 {   
       
   249     CNT_ENTRY
       
   250     QString results;
       
   251     
       
   252     if(mSimEngine->userCancelsImport(results))
       
   253     {
       
   254         HbDeviceNotificationDialog::notification(QString(),results);
       
   255     }
       
   256     CNT_EXIT
       
   257 }
       
   258 
       
   259 
   265 
   260 void CntImportsView::setListBoxItemText(QString& aPrimary, QString& aSecondary)
   266 void CntImportsView::setListBoxItemText(QString& aPrimary, QString& aSecondary)
   261 {
   267 {
   262     CNT_ENTRY
   268     CNT_ENTRY
       
   269     
   263     QList<QStandardItem*> importItems = mModel->takeRow(0);
   270     QList<QStandardItem*> importItems = mModel->takeRow(0);
   264     QStandardItem* importItem = NULL;
   271     QStandardItem* importItem = NULL;
   265     if (importItems.count() > 0) {
   272     
       
   273     if (importItems.count() > 0)
       
   274     {
   266         importItem = importItems.at(0);
   275         importItem = importItems.at(0);
   267     }
   276     }
   268     
   277     
   269     if (importItem != NULL)
   278     if (importItem != NULL)
   270     {
   279     {
   276         importItem->setData(simList, Qt::DisplayRole);
   285         importItem->setData(simList, Qt::DisplayRole);
   277         importItem->setData(HbIcon("qtg_large_sim"), Qt::DecorationRole);
   286         importItem->setData(HbIcon("qtg_large_sim"), Qt::DecorationRole);
   278         mModel->insertRow(0, importItem);
   287         mModel->insertRow(0, importItem);
   279         mListView->reset();
   288         mListView->reset();
   280     }
   289     }
       
   290     
   281     CNT_EXIT
   291     CNT_EXIT
   282 }
   292 }
   283 
   293 
   284 void CntImportsView::setListBoxItemEnabled(bool aEnabled)
   294 void CntImportsView::setListBoxItemEnabled(bool aEnabled)
   285 {
   295 {
   286     CNT_ENTRY
   296     CNT_ENTRY
       
   297     
   287     QList<QStandardItem*> importItems = mModel->takeRow(0);
   298     QList<QStandardItem*> importItems = mModel->takeRow(0);
   288     QStandardItem* importItem = NULL;
   299     QStandardItem* importItem = NULL;
       
   300     
   289     if ( !importItems.isEmpty() )
   301     if ( !importItems.isEmpty() )
   290     {
   302     {
   291        importItem = importItems.first();
   303        importItem = importItems.first();
   292     }
   304     }
   293     
   305     
   294     if (importItem != NULL)
   306     if (importItem != NULL)
   295     {
   307     {
   296        importItem->setEnabled(aEnabled);
   308        importItem->setEnabled(aEnabled);
   297     }
   309     }
   298     CNT_EXIT
   310     
   299 }
   311     CNT_EXIT
   300 
       
   301 QContactManager *CntImportsView::contactSymbianManager()
       
   302 {
       
   303     if (mSimEngine)
       
   304     {
       
   305         return mSimEngine->contactSymbianManager();
       
   306     }
       
   307     
       
   308     return NULL;
       
   309 }
   312 }
   310 
   313 
   311 // EOF
   314 // EOF