pkiutilities/untrustedcertificatedialog/src/untrustedcertificatedialog.cpp
changeset 30 cc1cea6aabaf
parent 26 aad866c37519
equal deleted inserted replaced
26:aad866c37519 30:cc1cea6aabaf
    19 #include "untrustedcertificatedialog.h"
    19 #include "untrustedcertificatedialog.h"
    20 #include "untrustedcertificatedefinitions.h"
    20 #include "untrustedcertificatedefinitions.h"
    21 #include "untrustedcertificatewidget.h"
    21 #include "untrustedcertificatewidget.h"
    22 #include <hblabel.h>
    22 #include <hblabel.h>
    23 #include <hbaction.h>
    23 #include <hbaction.h>
       
    24 #include <hbmessagebox.h>
       
    25 #include <QGraphicsLinearLayout>
    24 
    26 
    25 const int KNoError = 0;             // KErrNone
    27 const int KNoError = 0;             // KErrNone
    26 const int KParameterError = -6;     // KErrArgument
    28 const int KParameterError = -6;     // KErrArgument
    27 
    29 
       
    30 // TODO: replace with OST tracing
       
    31 #ifdef _DEBUG
       
    32 #include <QDebug>
       
    33 #define TRACE(x)        qDebug() << x
       
    34 #define TRACE1(x,y)     qDebug() << x << y
       
    35 #else
       
    36 #define TRACE(x)
       
    37 #define TRACE1(x,y)
       
    38 #endif
       
    39 
    28 
    40 
    29 // ----------------------------------------------------------------------------
    41 // ----------------------------------------------------------------------------
    30 // UntrustedCertificateDialog::UntrustedCertificateDialog()
    42 // UntrustedCertificateDialog::UntrustedCertificateDialog()
    31 // ----------------------------------------------------------------------------
    43 // ----------------------------------------------------------------------------
    32 //
    44 //
    33 UntrustedCertificateDialog::UntrustedCertificateDialog(const QVariantMap &parameters) : HbDialog(),
    45 UntrustedCertificateDialog::UntrustedCertificateDialog(const QVariantMap &parameters) :
    34     mLastError(KNoError), mShowEventReceived(false), mContent(0)
    46     HbDialog(), mLastError(KNoError), mContent(0), mResultMap(),
       
    47     mShowEventReceived(false), mOkAction(0)
    35 {
    48 {
    36     constructDialog(parameters);
    49     constructDialog(parameters);
    37 }
    50 }
    38 
    51 
    39 // ----------------------------------------------------------------------------
    52 // ----------------------------------------------------------------------------
    67 // ----------------------------------------------------------------------------
    80 // ----------------------------------------------------------------------------
    68 //
    81 //
    69 void UntrustedCertificateDialog::closeDeviceDialog(bool byClient)
    82 void UntrustedCertificateDialog::closeDeviceDialog(bool byClient)
    70 {
    83 {
    71     Q_UNUSED(byClient);
    84     Q_UNUSED(byClient);
       
    85     TRACE("UntrustedCertificateDialog::closeDeviceDialog");
    72     close();
    86     close();
    73 
    87 
    74     // If show event has been received, close is signalled from hide event.
    88     // If show event has been received, close is signalled from hide event.
    75     // If not, hide event does not come and close is signalled from here.
    89     // If not, hide event does not come and close is signalled from here.
    76     if (!mShowEventReceived) {
    90     if (!mShowEventReceived) {
    91 // UntrustedCertificateDialog::hideEvent()
   105 // UntrustedCertificateDialog::hideEvent()
    92 // ----------------------------------------------------------------------------
   106 // ----------------------------------------------------------------------------
    93 //
   107 //
    94 void UntrustedCertificateDialog::hideEvent(QHideEvent *event)
   108 void UntrustedCertificateDialog::hideEvent(QHideEvent *event)
    95 {
   109 {
       
   110     TRACE("UntrustedCertificateDialog::hideEvent");
    96     HbDialog::hideEvent(event);
   111     HbDialog::hideEvent(event);
    97     emit deviceDialogClosed();
   112     emit deviceDialogClosed();
    98 }
   113 }
    99 
   114 
   100 // ----------------------------------------------------------------------------
   115 // ----------------------------------------------------------------------------
   101 // UntrustedCertificateDialog::showEvent()
   116 // UntrustedCertificateDialog::showEvent()
   102 // ----------------------------------------------------------------------------
   117 // ----------------------------------------------------------------------------
   103 //
   118 //
   104 void UntrustedCertificateDialog::showEvent(QShowEvent *event)
   119 void UntrustedCertificateDialog::showEvent(QShowEvent *event)
   105 {
   120 {
       
   121     TRACE("UntrustedCertificateDialog::showEvent");
   106     HbDialog::showEvent(event);
   122     HbDialog::showEvent(event);
   107     mShowEventReceived = true;
   123     mShowEventReceived = true;
   108 }
   124 }
   109 
   125 
   110 // ----------------------------------------------------------------------------
   126 // ----------------------------------------------------------------------------
   126 // UntrustedCertificateDialog::constructDialog()
   142 // UntrustedCertificateDialog::constructDialog()
   127 // ----------------------------------------------------------------------------
   143 // ----------------------------------------------------------------------------
   128 //
   144 //
   129 bool UntrustedCertificateDialog::constructDialog(const QVariantMap &parameters)
   145 bool UntrustedCertificateDialog::constructDialog(const QVariantMap &parameters)
   130 {
   146 {
       
   147     TRACE("UntrustedCertificateDialog::constructDialog");
   131     if (!isParametersValid(parameters)) {
   148     if (!isParametersValid(parameters)) {
   132         return false;
   149         return false;
   133     }
   150     }
   134 
   151 
   135     setTimeout(HbPopup::NoTimeout);
   152     setTimeout(HbPopup::NoTimeout);
   150     mContent = new UntrustedCertificateWidget(this);
   167     mContent = new UntrustedCertificateWidget(this);
   151     mContent->constructFromParameters(parameters);
   168     mContent->constructFromParameters(parameters);
   152     setContentWidget(mContent);
   169     setContentWidget(mContent);
   153 
   170 
   154     if (mContent->isCertificateValid()) {
   171     if (mContent->isCertificateValid()) {
   155         HbAction *okAction = new HbAction(qtTrId("txt_common_button_ok"), this);
   172         mOkAction = new HbAction(qtTrId("txt_common_button_ok"), this);
   156         connect(okAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
   173         addAction(mOkAction);
   157         addAction(okAction);
   174         disconnect(mOkAction, SIGNAL(triggered()), this, SLOT(close()));
       
   175         connect(mOkAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
   158 
   176 
   159         HbAction *cancelAction = new HbAction(qtTrId("txt_common_button_cancel"), this);
   177         HbAction *cancelAction = new HbAction(qtTrId("txt_common_button_cancel"), this);
       
   178         addAction(cancelAction);
       
   179         disconnect(cancelAction, SIGNAL(triggered()), this, SLOT(close()));
   160         connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleRejected()));
   180         connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleRejected()));
   161         addAction(cancelAction);
       
   162     } else {
   181     } else {
   163         HbAction *closeAction = new HbAction(qtTrId("txt_common_button_close"), this);
   182         HbAction *closeAction = new HbAction(qtTrId("txt_common_button_close"), this);
       
   183         addAction(closeAction);
       
   184         disconnect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
   164         connect(closeAction, SIGNAL(triggered()), this, SLOT(handleRejected()));
   185         connect(closeAction, SIGNAL(triggered()), this, SLOT(handleRejected()));
   165         addAction(closeAction);
       
   166     }
   186     }
   167 
   187 
   168     return true;
   188     return true;
   169 }
   189 }
   170 
   190 
   172 // UntrustedCertificateDialog::updateFromParameters()
   192 // UntrustedCertificateDialog::updateFromParameters()
   173 // ----------------------------------------------------------------------------
   193 // ----------------------------------------------------------------------------
   174 //
   194 //
   175 bool UntrustedCertificateDialog::updateFromParameters(const QVariantMap &parameters)
   195 bool UntrustedCertificateDialog::updateFromParameters(const QVariantMap &parameters)
   176 {
   196 {
       
   197     TRACE("UntrustedCertificateDialog::updateFromParameters");
   177     if (!isParametersValid(parameters)) {
   198     if (!isParametersValid(parameters)) {
   178         return false;
   199         return false;
   179     }
   200     }
   180 
   201 
   181     Q_ASSERT(mContent != 0);
   202     Q_ASSERT(mContent != 0);
   187 // UntrustedCertificateDialog::sendResult()
   208 // UntrustedCertificateDialog::sendResult()
   188 // ----------------------------------------------------------------------------
   209 // ----------------------------------------------------------------------------
   189 //
   210 //
   190 void UntrustedCertificateDialog::sendResult(int result)
   211 void UntrustedCertificateDialog::sendResult(int result)
   191 {
   212 {
       
   213     TRACE1("UntrustedCertificateDialog::sendResult", result);
   192     QVariant resultValue(result);
   214     QVariant resultValue(result);
   193     mResultMap.insert(KUntrustedCertificateDialogResult, resultValue);
   215     mResultMap.insert(KUntrustedCertificateDialogResult, resultValue);
   194     emit deviceDialogData(mResultMap);
   216     emit deviceDialogData(mResultMap);
   195 }
   217 }
   196 
   218 
   197 // ----------------------------------------------------------------------------
   219 // ----------------------------------------------------------------------------
       
   220 // UntrustedCertificateDialog::confirmPermanentAccept()
       
   221 // ----------------------------------------------------------------------------
       
   222 //
       
   223 void UntrustedCertificateDialog::confirmPermanentAccept()
       
   224 {
       
   225     TRACE("UntrustedCertificateDialog::confirmPermanentAccept");
       
   226 
       
   227     HbDialog *dialog = new HbDialog();
       
   228     dialog->setAttribute(Qt::WA_DeleteOnClose, true);
       
   229     dialog->setTimeout(HbPopup::NoTimeout);
       
   230     dialog->setDismissPolicy(HbDialog::NoDismiss);
       
   231     dialog->setModal(true);
       
   232 
       
   233     // TODO: localised UI string needed
       
   234     QString questionTitle = tr("Certificate access");
       
   235     dialog->setHeadingWidget(new HbLabel(questionTitle));
       
   236 
       
   237     HbWidget *widget = new HbWidget();
       
   238     QGraphicsLinearLayout* layout = new QGraphicsLinearLayout();
       
   239     // TODO: localized UI string needed
       
   240     QString questionText =
       
   241         tr("Connections to '%1' will be made without warnings. Continue?")
       
   242         .arg(mContent->serverName());
       
   243     HbLabel *textLabel = new HbLabel(questionText);
       
   244     textLabel->setTextWrapping(Hb::TextWordWrap);
       
   245     layout->addItem(textLabel);
       
   246     widget->setLayout(layout);
       
   247     dialog->setContentWidget(widget);
       
   248 
       
   249     HbAction *yesAction = new HbAction(hbTrId("txt_common_button_yes"));
       
   250     dialog->addAction(yesAction);
       
   251     disconnect(yesAction, SIGNAL(triggered()), this, SLOT(close()));
       
   252     connect(yesAction, SIGNAL(triggered()), this, SLOT(handlePermanentAcceptance()));
       
   253     dialog->addAction(new HbAction(hbTrId("txt_common_button_no")));
       
   254 
       
   255     dialog->show();
       
   256 }
       
   257 
       
   258 // ----------------------------------------------------------------------------
   198 // UntrustedCertificateDialog::handleAccepted()
   259 // UntrustedCertificateDialog::handleAccepted()
   199 // ----------------------------------------------------------------------------
   260 // ----------------------------------------------------------------------------
   200 //
   261 //
   201 void UntrustedCertificateDialog::handleAccepted()
   262 void UntrustedCertificateDialog::handleAccepted()
   202 {
   263 {
       
   264     TRACE("UntrustedCertificateDialog::handleAccepted");
   203     if (mContent->isPermanentAcceptChecked()) {
   265     if (mContent->isPermanentAcceptChecked()) {
   204         sendResult(KDialogAcceptedPermanently);
   266         confirmPermanentAccept();
   205     } else {
   267     } else {
   206         sendResult(KDialogAccepted);
   268         sendResult(KDialogAccepted);
       
   269 		close();
   207     }
   270     }
   208 }
   271 }
   209 
   272 
   210 // ----------------------------------------------------------------------------
   273 // ----------------------------------------------------------------------------
   211 // UntrustedCertificateDialog::handleRejected()
   274 // UntrustedCertificateDialog::handleRejected()
   212 // ----------------------------------------------------------------------------
   275 // ----------------------------------------------------------------------------
   213 //
   276 //
   214 void UntrustedCertificateDialog::handleRejected()
   277 void UntrustedCertificateDialog::handleRejected()
   215 {
   278 {
       
   279     TRACE("UntrustedCertificateDialog::handleRejected");
   216     sendResult(KDialogRejected);
   280     sendResult(KDialogRejected);
   217 }
   281     close();
   218 
   282 }
       
   283 
       
   284 // ----------------------------------------------------------------------------
       
   285 // UntrustedCertificateDialog::handlePermanentAcceptance()
       
   286 // ----------------------------------------------------------------------------
       
   287 //
       
   288 void UntrustedCertificateDialog::handlePermanentAcceptance()
       
   289 {
       
   290     TRACE("UntrustedCertificateDialog::handlePermanentAcceptance");
       
   291     sendResult(KDialogAcceptedPermanently);
       
   292     close();
       
   293 }
       
   294