emailuis/nmsettingui/src/nmsettingsviewfactory.cpp
changeset 66 084b5b1f02a7
parent 51 d845db10c0d4
child 68 83cc6bae1de8
equal deleted inserted replaced
62:a8c646b56683 66:084b5b1f02a7
    18 #include <QProcess>
    18 #include <QProcess>
    19 #include <QTranslator>
    19 #include <QTranslator>
    20 #include <QCoreApplication>
    20 #include <QCoreApplication>
    21 #include <HbInstance>
    21 #include <HbInstance>
    22 #include <HbAction>
    22 #include <HbAction>
    23 #include <HbMessageBox>
       
    24 
    23 
    25 #include "nmsettingsviewfactory.h"
    24 #include "nmsettingsviewfactory.h"
    26 #include "nmmailboxsettingsmanager.h"
    25 #include "nmmailboxsettingsmanager.h"
    27 #include "nmmailboxsettingview.h"
    26 #include "nmmailboxsettingview.h"
    28 #include "nmmailboxselectionview.h"
    27 #include "nmmailboxselectionview.h"
    29 #include "nmmailbox.h"
    28 #include "nmmailbox.h"
    30 #include "nmcommon.h"
    29 #include "nmcommon.h"
    31 #include "nmsettingsviewlauncher.h"
    30 #include "nmsettingsviewlauncher.h"
    32 #include "nmsettingscommon.h"
    31 #include "nmsettingscommon.h"
    33 
    32 
    34 static const QString mailWizardStartExe = "mailwizard.exe";
       
    35 static const QString mailWizardStartArgs = "from:controlpanel";
       
    36 
       
    37 
    33 
    38 /*!
    34 /*!
    39     \class NmSettingsViewFactory
    35     \class NmSettingsViewFactory
    40     \brief Constructs and displays settings views.
    36     \brief Constructs and displays settings views.
    41 
    37 
    59     const QString &text,
    55     const QString &text,
    60     const QString &description,
    56     const QString &description,
    61     const HbIcon &icon,
    57     const HbIcon &icon,
    62     const HbDataFormModelItem *parent)
    58     const HbDataFormModelItem *parent)
    63  : CpSettingFormEntryItemData(itemDataHelper, text, description, icon, parent),
    59  : CpSettingFormEntryItemData(itemDataHelper, text, description, icon, parent),
    64    mSettingsManager(new NmMailboxSettingsManager()), mSettingsViewLauncher(0),mPrevView(0),
    60    mSettingsManager(new NmMailboxSettingsManager()), mSettingsViewLauncher(0),mPrevView(0)
    65    mMessageBox(0)
    61 {
    66 {
    62     NM_FUNCTION;
    67     NM_FUNCTION;
       
    68 
       
    69     createMessageBox();
       
    70 }
    63 }
    71 
    64 
    72 
    65 
    73 /*!
    66 /*!
    74     Constructor of NmSettingsViewFactory.
    67     Constructor of NmSettingsViewFactory.
    88     const QString &description,
    81     const QString &description,
    89     const HbIcon &icon,
    82     const HbIcon &icon,
    90     const HbDataFormModelItem *parent)
    83     const HbDataFormModelItem *parent)
    91  : CpSettingFormEntryItemData(itemDataHelper, text, description, icon, parent),
    84  : CpSettingFormEntryItemData(itemDataHelper, text, description, icon, parent),
    92      mSettingsManager(new NmMailboxSettingsManager()), mSettingsViewLauncher(viewLauncher),
    85      mSettingsManager(new NmMailboxSettingsManager()), mSettingsViewLauncher(viewLauncher),
    93      mPrevView(0), mMessageBox(0)
    86      mPrevView(0)
    94 {
    87 {
    95     NM_FUNCTION;
    88     NM_FUNCTION;
    96 
       
    97     createMessageBox();
       
    98 }
    89 }
    99 
    90 
   100 
    91 
   101 /*!
    92 /*!
   102     Destructor of NmSettingsViewFactory.
    93     Destructor of NmSettingsViewFactory.
   104 NmSettingsViewFactory::~NmSettingsViewFactory()
    95 NmSettingsViewFactory::~NmSettingsViewFactory()
   105 {
    96 {
   106     NM_FUNCTION;
    97     NM_FUNCTION;
   107 
    98 
   108     delete mSettingsManager;
    99     delete mSettingsManager;
   109     delete mMessageBox;
       
   110 }
   100 }
   111 
   101 
   112 
   102 
   113 /*!
   103 /*!
   114     Constructs a setting view. The type of the view depends on the number of
   104     Constructs a setting view. The type of the view depends on the number of
   129     // Log the number of mailboxes.
   119     // Log the number of mailboxes.
   130     NM_COMMENT(QString("NmSettingsViewFactory::createSettingView(): mailbox count is %1").arg(mailboxCount));
   120     NM_COMMENT(QString("NmSettingsViewFactory::createSettingView(): mailbox count is %1").arg(mailboxCount));
   131 
   121 
   132     switch(mailboxCount) {
   122     switch(mailboxCount) {
   133         case 0: {
   123         case 0: {
   134             // Query the user whether to launch the wizard or not.
   124             // Mailbox doesn't exist, we can't open settings
   135             mMessageBox->open(const_cast<NmSettingsViewFactory *>(this),
       
   136                               SLOT(launchWizard(HbAction *)));
       
   137             break;
   125             break;
   138         }
   126         }
   139         case 1: {
   127         case 1: {
   140             // Construct setting view for the only available mailbox
   128             // Construct setting view for the only available mailbox
   141             NmMailbox *mailbox = mailboxList.at(0);
   129             NmMailbox *mailbox = mailboxList.at(0);
   268         }
   256         }
   269         mPrevView = 0;
   257         mPrevView = 0;
   270     }
   258     }
   271 }
   259 }
   272 
   260 
   273 /*!
       
   274     Handles user selection from "No mailboxes defined" dialog. Launches the Mail Wizard if \a action
       
   275     is the dialog's primary action ("Yes"). Otherwise does nothing.
       
   276     \param action. Action selected by the user.
       
   277 */
       
   278 void NmSettingsViewFactory::launchWizard(HbAction *action)
       
   279 {
       
   280     NM_FUNCTION;
       
   281 
       
   282     if (action == mMessageBox->primaryAction()) {
       
   283         // Launch mail wizard.
       
   284         NM_COMMENT(QString("NmSettingsViewFactory::launchWizard(): launching the mail wizard"));
       
   285         QStringList args;
       
   286         args << mailWizardStartArgs;
       
   287         QProcess::startDetached(mailWizardStartExe, args);
       
   288     }
       
   289 }
       
   290 
       
   291 /*!
       
   292     Creates the "No mailboxes defined" dialog. Called from the constructors.
       
   293 */
       
   294 void NmSettingsViewFactory::createMessageBox()
       
   295 {
       
   296     NM_FUNCTION;
       
   297 
       
   298     mMessageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   299     mMessageBox->setText(hbTrId("txt_mail_dialog_no_mailboxes_create_new"));
       
   300     mMessageBox->setTimeout(HbMessageBox::NoTimeout);
       
   301     mMessageBox->setStandardButtons(HbMessageBox::Yes | HbMessageBox::No);
       
   302 }
       
   303 
       
   304 
   261 
   305 // End of file.
   262 // End of file.