emailuis/nmsettingui/src/nmsettingsviewfactory.cpp
changeset 51 d845db10c0d4
parent 48 10eaf342f539
child 66 084b5b1f02a7
equal deleted inserted replaced
49:00c7ae862740 51:d845db10c0d4
    63  : CpSettingFormEntryItemData(itemDataHelper, text, description, icon, parent),
    63  : CpSettingFormEntryItemData(itemDataHelper, text, description, icon, parent),
    64    mSettingsManager(new NmMailboxSettingsManager()), mSettingsViewLauncher(0),mPrevView(0),
    64    mSettingsManager(new NmMailboxSettingsManager()), mSettingsViewLauncher(0),mPrevView(0),
    65    mMessageBox(0)
    65    mMessageBox(0)
    66 {
    66 {
    67     NM_FUNCTION;
    67     NM_FUNCTION;
    68     
    68 
    69     createMessageBox();
    69     createMessageBox();
    70 }
    70 }
    71 
    71 
    72 
    72 
    73 /*!
    73 /*!
    91  : CpSettingFormEntryItemData(itemDataHelper, text, description, icon, parent),
    91  : CpSettingFormEntryItemData(itemDataHelper, text, description, icon, parent),
    92      mSettingsManager(new NmMailboxSettingsManager()), mSettingsViewLauncher(viewLauncher),
    92      mSettingsManager(new NmMailboxSettingsManager()), mSettingsViewLauncher(viewLauncher),
    93      mPrevView(0), mMessageBox(0)
    93      mPrevView(0), mMessageBox(0)
    94 {
    94 {
    95     NM_FUNCTION;
    95     NM_FUNCTION;
    96     
    96 
    97     createMessageBox();
    97     createMessageBox();
    98 }
    98 }
    99 
    99 
   100 
   100 
   101 /*!
   101 /*!
   102     Destructor of NmSettingsViewFactory.
   102     Destructor of NmSettingsViewFactory.
   103 */
   103 */
   104 NmSettingsViewFactory::~NmSettingsViewFactory()
   104 NmSettingsViewFactory::~NmSettingsViewFactory()
   105 {
   105 {
   106     NM_FUNCTION;
   106     NM_FUNCTION;
   107     
   107 
   108     delete mSettingsManager;
   108     delete mSettingsManager;
   109     delete mMessageBox;
   109     delete mMessageBox;
   110 }
   110 }
   111 
   111 
   112 
   112 
   118     \return A newly constructed setting view instance.
   118     \return A newly constructed setting view instance.
   119 */
   119 */
   120 CpBaseSettingView *NmSettingsViewFactory::createSettingView() const
   120 CpBaseSettingView *NmSettingsViewFactory::createSettingView() const
   121 {
   121 {
   122     NM_FUNCTION;
   122     NM_FUNCTION;
   123     
   123 
   124     CpBaseSettingView *view = 0;
   124     CpBaseSettingView *view = 0;
   125     QList<NmMailbox *> mailboxList;
   125     QList<NmMailbox *> mailboxList;
   126     mSettingsManager->listMailboxes(mailboxList);
   126     mSettingsManager->listMailboxes(mailboxList);
   127     const int mailboxCount(mailboxList.count());
   127     const int mailboxCount(mailboxList.count());
   128 
   128 
   159 
   159 
   160         connect(mSettingsManager,
   160         connect(mSettingsManager,
   161                 SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)),
   161                 SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)),
   162                 view, SLOT(mailboxPropertyChanged(const NmId &, QVariant, QVariant)));
   162                 view, SLOT(mailboxPropertyChanged(const NmId &, QVariant, QVariant)));
   163     }
   163     }
   164     
   164 
   165     return view;
   165     return view;
   166 }
   166 }
   167 
   167 
   168 
   168 
   169 /*!
   169 /*!
   174 */
   174 */
   175 void NmSettingsViewFactory::launchSettingView(const NmId &mailboxId,
   175 void NmSettingsViewFactory::launchSettingView(const NmId &mailboxId,
   176                                               const QString &mailboxName) const
   176                                               const QString &mailboxName) const
   177 {
   177 {
   178     NM_FUNCTION;
   178     NM_FUNCTION;
   179     
   179 
   180     // There's always at least one valid main window available.
   180     // There's always at least one valid main window available.
   181     HbMainWindow *mainWindow = hbInstance->allMainWindows().takeFirst();
   181     HbMainWindow *mainWindow = hbInstance->allMainWindows().takeFirst();
   182 
   182 
   183     NmMailboxSettingView *currentSettingsView = 
   183     NmMailboxSettingView *currentSettingsView =
   184         qobject_cast<NmMailboxSettingView*>(mainWindow->currentView());
   184         qobject_cast<NmMailboxSettingView*>(mainWindow->currentView());
   185     
   185 
   186     // Let's have only one same settings view at a time open, 
   186     // Let's have only one same settings view at a time open,
   187     // but if some other mailboxes settings view want's to open while 
   187     // but if some other mailboxes settings view want's to open while
   188     // there is a settings view open let's open it also.
   188     // there is a settings view open let's open it also.
   189     if (!currentSettingsView || (currentSettingsView->mailboxId().id() != mailboxId.id())) {
   189     if (!currentSettingsView || (currentSettingsView->mailboxId().id() != mailboxId.id())) {
   190         CpBaseSettingView *view =
   190         CpBaseSettingView *view =
   191              new NmMailboxSettingView(mailboxId, mailboxName, *mSettingsManager);
   191              new NmMailboxSettingView(mailboxId, mailboxName, *mSettingsManager);
   192          
   192 
   193          connect(mSettingsManager,
   193          connect(mSettingsManager,
   194                  SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)),
   194                  SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)),
   195                  view, SLOT(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)));
   195                  view, SLOT(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)));
   196      
   196 
   197          connect(mSettingsManager,
   197          connect(mSettingsManager,
   198                  SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)),
   198                  SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)),
   199                  view, SLOT(mailboxPropertyChanged(const NmId &, QVariant, QVariant)));
   199                  view, SLOT(mailboxPropertyChanged(const NmId &, QVariant, QVariant)));
   200      
   200 
   201          // Disconnect mSettingsViewLauncher's previous connections to 
   201          // Disconnect mSettingsViewLauncher's previous connections to
   202          // be sure that signals which are offered out will be sent last.
   202          // be sure that signals which are offered out will be sent last.
   203          mSettingsManager->disconnect(
   203          mSettingsManager->disconnect(
   204              SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)),
   204              SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)),
   205              mSettingsViewLauncher,
   205              mSettingsViewLauncher,
   206              SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)));
   206              SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)));
   207      
   207 
   208          mSettingsManager->disconnect(
   208          mSettingsManager->disconnect(
   209              SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)),
   209              SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)),
   210              mSettingsViewLauncher,
   210              mSettingsViewLauncher,
   211              SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)));
   211              SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)));
   212      
   212 
   213          // Reconnect mSettingsViewLauncher.
   213          // Reconnect mSettingsViewLauncher.
   214          connect(mSettingsManager,
   214          connect(mSettingsManager,
   215                  SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)),
   215                  SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)),
   216                  mSettingsViewLauncher,
   216                  mSettingsViewLauncher,
   217                  SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)));
   217                  SIGNAL(mailboxListChanged(const NmId &, NmSettings::MailboxEventType)));
   218      
   218 
   219          connect(mSettingsManager,
   219          connect(mSettingsManager,
   220                  SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)),
   220                  SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)),
   221                  mSettingsViewLauncher,
   221                  mSettingsViewLauncher,
   222                  SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)));
   222                  SIGNAL(mailboxPropertyChanged(const NmId &, QVariant, QVariant)));
   223      
   223 
   224          connect(mSettingsManager,
   224          connect(mSettingsManager,
   225                  SIGNAL(goOnline(const NmId &)),
   225                  SIGNAL(goOnline(const NmId &)),
   226                  mSettingsViewLauncher,
   226                  mSettingsViewLauncher,
   227                  SIGNAL(goOnline(const NmId &)), Qt::UniqueConnection);
   227                  SIGNAL(goOnline(const NmId &)), Qt::UniqueConnection);
   228      
   228 
   229          connect(mSettingsManager,
   229          connect(mSettingsManager,
   230                  SIGNAL(goOffline(const NmId &)),
   230                  SIGNAL(goOffline(const NmId &)),
   231                  mSettingsViewLauncher,
   231                  mSettingsViewLauncher,
   232                  SIGNAL(goOffline(const NmId &)), Qt::UniqueConnection);
   232                  SIGNAL(goOffline(const NmId &)), Qt::UniqueConnection);
   233      
   233 
   234          connect(this,
   234          connect(this,
   235                  SIGNAL(aboutToClose()),
   235                  SIGNAL(aboutToClose()),
   236                  mSettingsManager,
   236                  mSettingsManager,
   237                  SIGNAL(aboutToClose()), Qt::UniqueConnection);
   237                  SIGNAL(aboutToClose()), Qt::UniqueConnection);
   238      
   238 
   239          // Create back navigation action for a view.
   239          // Create back navigation action for a view.
   240          HbAction *action = new HbAction(Hb::BackNaviAction, view);
   240          HbAction *action = new HbAction(Hb::BackNaviAction, view);
   241          connect(action, SIGNAL(triggered()), this, SLOT(backPress()));
   241          connect(action, SIGNAL(triggered()), this, SLOT(backPress()));
   242          view->setNavigationAction(action);
   242          view->setNavigationAction(action);
   243          mPrevView = mainWindow->currentView();
   243          mPrevView = mainWindow->currentView();
   244          mainWindow->addView(view);
   244          mainWindow->addView(view);
   245          mainWindow->setCurrentView(view);
   245          mainWindow->setCurrentView(view);
   246     }    
   246     }
   247 }
   247 }
   248 
   248 
   249 /*!
   249 /*!
   250    Handels back button press.
   250    Handels back button press.
   251    Removes the current view from the main window and activates the previous view.
   251    Removes the current view from the main window and activates the previous view.
   252    Destroys removed view.
   252    Destroys removed view.
   253 */
   253 */
   254 void NmSettingsViewFactory::backPress()
   254 void NmSettingsViewFactory::backPress()
   255 {
   255 {
   256     NM_FUNCTION;
   256     NM_FUNCTION;
   257     
   257 
   258     emit aboutToClose();
   258     emit aboutToClose();
   259     HbMainWindow *mainWindow = hbInstance->allMainWindows().takeFirst();
   259     HbMainWindow *mainWindow = hbInstance->allMainWindows().takeFirst();
   260     QList<HbView *> views = mainWindow->views();
   260     QList<HbView *> views = mainWindow->views();
   261     if (views.count() > 1) {
   261     if (views.count() > 1) {
   262         HbView *currentView = mainWindow->currentView();
   262         HbView *currentView = mainWindow->currentView();
   276     \param action. Action selected by the user.
   276     \param action. Action selected by the user.
   277 */
   277 */
   278 void NmSettingsViewFactory::launchWizard(HbAction *action)
   278 void NmSettingsViewFactory::launchWizard(HbAction *action)
   279 {
   279 {
   280     NM_FUNCTION;
   280     NM_FUNCTION;
   281     
   281 
   282     if (action == mMessageBox->primaryAction()) {
   282     if (action == mMessageBox->primaryAction()) {
   283         // Launch mail wizard.
   283         // Launch mail wizard.
   284         NM_COMMENT(QString("NmSettingsViewFactory::launchWizard(): launching the mail wizard"));
   284         NM_COMMENT(QString("NmSettingsViewFactory::launchWizard(): launching the mail wizard"));
   285         QStringList args;
   285         QStringList args;
   286         args << mailWizardStartArgs;
   286         args << mailWizardStartArgs;
   292     Creates the "No mailboxes defined" dialog. Called from the constructors.
   292     Creates the "No mailboxes defined" dialog. Called from the constructors.
   293 */
   293 */
   294 void NmSettingsViewFactory::createMessageBox()
   294 void NmSettingsViewFactory::createMessageBox()
   295 {
   295 {
   296     NM_FUNCTION;
   296     NM_FUNCTION;
   297     
   297 
   298     mMessageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   298     mMessageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   299     mMessageBox->setText(hbTrId("txt_mail_dialog_no_mailboxes_create_new"));
   299     mMessageBox->setText(hbTrId("txt_mail_dialog_no_mailboxes_create_new"));
   300     mMessageBox->setTimeout(HbMessageBox::NoTimeout);
   300     mMessageBox->setTimeout(HbMessageBox::NoTimeout);
       
   301     mMessageBox->setStandardButtons(HbMessageBox::Yes | HbMessageBox::No);
   301 }
   302 }
   302 
   303 
   303 
   304 
   304 // End of file.
   305 // End of file.