creator/src/notifications.cpp
changeset 28 4cc0d1a608c1
parent 27 271e901a9423
child 29 1c71b77fbc93
equal deleted inserted replaced
27:271e901a9423 28:4cc0d1a608c1
    73 HbProgressDialog* Notifications::showProgressBar(const QString& text, int max)
    73 HbProgressDialog* Notifications::showProgressBar(const QString& text, int max)
    74 {
    74 {
    75 	HbProgressDialog *note = new HbProgressDialog(HbProgressDialog::ProgressDialog);
    75 	HbProgressDialog *note = new HbProgressDialog(HbProgressDialog::ProgressDialog);
    76     note->setText(text);
    76     note->setText(text);
    77     note->setMaximum(max);
    77     note->setMaximum(max);
       
    78     note->setAutoClose(false);
    78     note->show();
    79     note->show();
    79     return note;
    80     return note;
    80 
    81 
    81 }
    82 }
    82 
    83 
    85 void Notifications::showGlobalNote(const QString& text, HbMessageBox::MessageBoxType type, HbPopup::DefaultTimeout timeout)
    86 void Notifications::showGlobalNote(const QString& text, HbMessageBox::MessageBoxType type, HbPopup::DefaultTimeout timeout)
    86 {
    87 {
    87     showMessageBox(type, text, QString("Creator"), timeout);
    88     showMessageBox(type, text, QString("Creator"), timeout);
    88 }
    89 }
    89 
    90 
    90 // ---------------------------------------------------------------------------
       
    91 
       
    92 bool Notifications::directoryQueryDialog(const QString& text, QString& directory)
       
    93 {
       
    94 	bool err = false;
       
    95     HbDialog *popup = new HbDialog();
       
    96     popup->setDismissPolicy(HbPopup::TapOutside);
       
    97     popup->setTimeout(HbPopup::NoTimeout);
       
    98 	
       
    99 	HbLabel *title = new HbLabel();
       
   100     HbLineEdit *edit = new HbLineEdit();
       
   101 	HbAction *actionOk = new HbAction("Ok");
       
   102 	HbAction *actionCancel = new HbAction("Cancel");
       
   103 	
       
   104 	title->setPlainText(text);
       
   105 	popup->setHeadingWidget(title);
       
   106 	popup->setContentWidget(edit);
       
   107 	edit->setMaxLength(256);
       
   108 	edit->setText(directory);
       
   109 	edit->setSelection(0, directory.length());
       
   110 	
       
   111 	popup->setPrimaryAction(actionOk);
       
   112     popup->setSecondaryAction(actionCancel);
       
   113 
       
   114     // Launch popup syncronously
       
   115     popup->setAttribute(Qt::WA_DeleteOnClose);
       
   116     // TODO: handle dialog close & user input
       
   117     popup->open();
       
   118 
       
   119 	// continue if ok selected and valid user input exists in line editor
       
   120     /*if (action && action->text() == "Ok" && edit->text() != "") {
       
   121 		directory = edit->text();
       
   122 		err = true;
       
   123 	}*/
       
   124 	return err;
       
   125 }
       
   126 
    91 
   127 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
   128 
    93 
   129 CreatorYesNoDialog::CreatorYesNoDialog(MUIObserver* observer, int userData) : 
    94 CreatorYesNoDialog::CreatorYesNoDialog(MUIObserver* observer, int userData) : 
   130     HbMessageBox(HbMessageBox::MessageTypeQuestion, NULL),
    95     HbMessageBox(HbMessageBox::MessageTypeQuestion, NULL),
   153 }
   118 }
   154 
   119 
   155 CreatorInputDialog::CreatorInputDialog(int* value, MUIObserver* module, int userData) : 
   120 CreatorInputDialog::CreatorInputDialog(int* value, MUIObserver* module, int userData) : 
   156     HbInputDialog(NULL),
   121     HbInputDialog(NULL),
   157     CreatorDialog(module, userData),
   122     CreatorDialog(module, userData),
   158     mValue(value)
   123     mIntValue(value), 
       
   124     mStrValue(mDummy)// will not be used
   159 {
   125 {
   160     if(!value)
   126     if(!value)
   161         throw std::invalid_argument("value cannot be the null!");
   127         throw std::invalid_argument("value cannot be the null!");
       
   128 }
       
   129 
       
   130 CreatorInputDialog::CreatorInputDialog(TDes& value, MUIObserver* module, int userData) : 
       
   131     HbInputDialog(NULL),
       
   132     CreatorDialog(module, userData),
       
   133     mIntValue(NULL),
       
   134     mStrValue(value)
       
   135 {
   162 }
   136 }
   163 
   137 
   164 void CreatorInputDialog::launch(const QString& label, int* value, bool acceptsZero, MUIObserver* observer, int userData) throw( std::exception )
   138 void CreatorInputDialog::launch(const QString& label, int* value, bool acceptsZero, MUIObserver* observer, int userData) throw( std::exception )
   165 {
   139 {
   166     CreatorInputDialog* dlg = new CreatorInputDialog(value, observer, userData);
   140     CreatorInputDialog* dlg = new CreatorInputDialog(value, observer, userData);
   182     dlg->lineEdit()->setSelection(0, dlg->value().toString().length());
   156     dlg->lineEdit()->setSelection(0, dlg->value().toString().length());
   183     dlg->setAttribute(Qt::WA_DeleteOnClose);
   157     dlg->setAttribute(Qt::WA_DeleteOnClose);
   184     dlg->open(dlg, SLOT(DialogClosed(HbAction*)));
   158     dlg->open(dlg, SLOT(DialogClosed(HbAction*)));
   185 }
   159 }
   186 
   160 
       
   161 void CreatorInputDialog::launch(const QString& label, TDes& value, MUIObserver* observer, int userData) throw( std::exception )
       
   162 {
       
   163     CreatorInputDialog* dlg = new CreatorInputDialog(value, observer, userData);
       
   164     dlg->setPromptText(label);
       
   165     dlg->lineEdit()->setMaxLength(value.MaxLength());
       
   166     dlg->setValue(QString::fromUtf16(value.Ptr(), value.Length()));
       
   167     dlg->lineEdit()->setSelection(0, dlg->value().toString().length());
       
   168     dlg->setInputMode(TextInput);
       
   169     dlg->setAttribute(Qt::WA_DeleteOnClose);
       
   170     dlg->open(dlg, SLOT(DialogClosed(HbAction*)));
       
   171 }
       
   172 
   187 void CreatorInputDialog::DialogClosed(HbAction *action)
   173 void CreatorInputDialog::DialogClosed(HbAction *action)
   188 {
   174 {
   189     TBool PositiveAction(EFalse);
   175     TBool PositiveAction(EFalse);
   190     if(action && (action->softKeyRole()==QAction::PositiveSoftKey || !action->text().compare("ok", Qt::CaseInsensitive))){
   176     if(action && (action->softKeyRole()==QAction::PositiveSoftKey || !action->text().compare("ok", Qt::CaseInsensitive))){
   191         bool ok = false;
   177         bool ok = true;
   192         *mValue = value().toInt(&ok);
   178         if( inputMode() == IntInput )
       
   179             *mIntValue = value().toInt(&ok);
       
   180         else if( inputMode() == TextInput && mStrValue.MaxLength() >= value().toString().length() )
       
   181             mStrValue.Copy(value().toString().utf16());
       
   182         else
       
   183             ok = false;
   193         PositiveAction = ok ? ETrue : EFalse;
   184         PositiveAction = ok ? ETrue : EFalse;
   194     }
   185     }
   195     NotifyObserver(PositiveAction);
   186     NotifyObserver(PositiveAction);
   196 }
   187 }
   197 
   188