1 #include "profildialog.h"
2 #include "ui_profildialog.h"
4 #include <QMaemo5ValueButton>
5 #include <QMaemo5ListPickSelector>
6 #include <QMaemo5InformationBox>
8 #include <QtCore/QDebug> //Debug pro informace
9 #include <QtGui/QStandardItemModel>
10 #include <QtCore/QStringList>
11 #include <QtCore/QFileInfo>
12 #include <QtGui/QFileDialog>
13 #include <QtGui/QListView>
14 #include <QtCore/QModelIndex>
15 #include <QtCore/QVariant>
17 #include <QtCore/QString>
20 Setup ui and create new objects for item model and maemo5
21 value button and setup slider, check boxes atc. if dialog is use
24 ProfilDialog::ProfilDialog(QStringList list_of_profiles_n, QWidget *parent, Profil * profil, QStandardItemModel * model) :
26 ui(new Ui::ProfilDialog)
30 list_of_profiles_names = list_of_profiles_n; // save pointer
31 model_of_files = model;
33 //edit profile or new profile
34 if(profil->GetName().isEmpty()) {
36 setWindowTitle(tr("New profile"));
37 ui->slider_ringing_volume->setValue(0);
38 ui->slider_sms_volume->setValue(0);
39 ui->slider_im_volume->setValue(0);
40 ui->slider_email_volume->setValue(0);
43 setWindowTitle(tr("Edit profile"));
44 ui->lineEdit_nameprofile->setText(profile->GetName());
45 ui->lineEdit_nameprofile->setDisabled(true);
46 ui->slider_ringing_volume->setValue(profile->GetRingingAlertVolume().toInt());
47 ui->slider_sms_volume->setValue(profile->GetSmsAlertVolume().toInt());
48 ui->slider_im_volume->setValue(profile->GetImAlertVolume().toInt());
49 ui->slider_email_volume->setValue(profile->GetEmailAlertVolume().toInt());
58 ProfilDialog::~ProfilDialog()
63 /** createMeamoButtons()
64 Method will create Meamo5 buttons and sets
65 pick selector for them
67 void ProfilDialog::createMeamoButtons()
69 selModelMobil = new QItemSelectionModel(model_of_files); //create new selection model
70 QListView * list_view = createListView(selModelMobil); //method will create QListview
71 QMaemo5ListPickSelector *listpicker1 = createMeamoListPick(list_view); //method will create QMaemo5ListPickSelector
72 if(update) //if update then select ringtone
74 setSelectedItem(listpicker1,selModelMobil,profile->GetRingingAlertTone().toString());
76 v1 = new QMaemo5ValueButton(tr("Ringing tone"), this); //create button
77 // v1->setIcon(QIcon::fromTheme("chat_smiley_happy"));
78 v1->setValueLayout(QMaemo5ValueButton::ValueUnderText);
79 v1->setPickSelector(listpicker1);//set list pick
80 ui->gridLayout->addWidget(v1,13,0,1,-1); // add to layout
81 //===========================================================================================================================
82 selModelSMS = new QItemSelectionModel(model_of_files);
83 list_view = createListView(selModelSMS);
84 QMaemo5ListPickSelector *listpicker2 = createMeamoListPick(list_view);
87 setSelectedItem(listpicker2,selModelSMS,profile->GetSmsAlertTone().toString());
89 v2 = new QMaemo5ValueButton(tr("SMS tone"), this);
90 // v2->setIcon(QIcon::fromTheme("chat_smiley_happy"));
91 v2->setValueLayout(QMaemo5ValueButton::ValueUnderText);
92 v2->setPickSelector(listpicker2);
93 ui->gridLayout->addWidget(v2,14,0,1,-1);
94 //===========================================================================================================================
95 selModelIM = new QItemSelectionModel(model_of_files);
96 list_view = createListView(selModelIM);
97 QMaemo5ListPickSelector *listpicker3 = createMeamoListPick(list_view);
100 setSelectedItem(listpicker3,selModelIM,profile->GetImAlertTone().toString());
102 v3 = new QMaemo5ValueButton(tr("IM tone"), this);
103 // v3->setIcon(QIcon::fromTheme("chat_smiley_happy"));
104 v3->setValueLayout(QMaemo5ValueButton::ValueUnderText);
105 v3->setPickSelector(listpicker3);
106 ui->gridLayout->addWidget(v3,15,0,1,-1);
107 //===========================================================================
108 selModelEmail = new QItemSelectionModel(model_of_files);
109 list_view = createListView(selModelEmail);
110 QMaemo5ListPickSelector *listpicker4 = createMeamoListPick(list_view);
113 setSelectedItem(listpicker4,selModelEmail,profile->GetEmailAlertTone().toString());
115 v4 = new QMaemo5ValueButton(tr("E-mail tone"), this);
116 // v4->setIcon(QIcon::fromTheme("chat_smiley_happy"));
117 v4->setValueLayout(QMaemo5ValueButton::ValueUnderText);
118 v4->setPickSelector(listpicker4);
119 ui->gridLayout->addWidget(v4,16,0,1,-1);
123 Method will create QListView and set edit triggers to NoEditTriggers,
124 selection model, selection behavior to select rows and selection mode to single selection
126 QListView * ProfilDialog::createListView(QItemSelectionModel * select_model)
128 QListView * list_view = new QListView(this); //QListView::selectedItem() will return the selected QListViewItem*.
129 list_view->setEditTriggers(QAbstractItemView::NoEditTriggers);
132 QList<QStandardItem *> QStandardItemModel::findItems ( const QString & text, Qt::MatchFlags flags = Qt::MatchExactly, int column = 0 ) const
135 QModelIndex QStandardItem::index () const
138 void QItemSelectionModel::select ( const QModelIndex & index, QItemSelectionModel::SelectionFlags command ) [virtual slot]
141 list_view->setModel(model_of_files);
142 list_view->setSelectionModel(select_model);
143 list_view->setSelectionBehavior(QAbstractItemView::SelectRows);
144 list_view->setSelectionMode(QAbstractItemView::SingleSelection);
148 /** createMeamoListPick
149 Method will create QMaemo5ListPickSelector and set list pick model, model column and view
151 QMaemo5ListPickSelector * ProfilDialog::createMeamoListPick(QListView * list_view)
153 QMaemo5ListPickSelector *listpicker = new QMaemo5ListPickSelector(this);
154 listpicker->setModel(model_of_files);
155 listpicker->setModelColumn(0);
156 listpicker->setView(list_view);
161 Method will select right row for selction model and list picker
163 void ProfilDialog::setSelectedItem(QMaemo5ListPickSelector * listpicker, QItemSelectionModel * selModel, QString find )
165 QList<QStandardItem *> seznam_nalezenych;
166 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " co ma najit " << find;
167 seznam_nalezenych = model_of_files->findItems(find, Qt::MatchExactly, 1);//find itemm
168 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " Co nasel" << seznam_nalezenych;
169 if(!seznam_nalezenych.empty()){
170 selModel->select(seznam_nalezenych.at(0)->index(),QItemSelectionModel::Select | QItemSelectionModel::Rows);
171 listpicker->setCurrentIndex(seznam_nalezenych.at(0)->row());
176 Slot for signal when user click on save button.
177 Check is everyting is OK and save values into profile object
179 void ProfilDialog::accept()
181 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " tisk všech dat";
183 if(ui->lineEdit_nameprofile->text().isEmpty()){
184 QMaemo5InformationBox::information(this, tr("Profile must have name"), QMaemo5InformationBox::DefaultTimeout);
188 if(list_of_profiles_names.contains(ui->lineEdit_nameprofile->text()))
190 QMaemo5InformationBox::information(this, tr("This profile elready exist"), QMaemo5InformationBox::DefaultTimeout);
195 if(ui->lineEdit_nameprofile->text().split(QRegExp("\\s+"),QString::SkipEmptyParts).size() > 1)
197 QMaemo5InformationBox::information(this, tr("One word name please"), QMaemo5InformationBox::DefaultTimeout);
201 if(ui->lineEdit_nameprofile->text().contains(QRegExp("^\\d\\D*")))
203 QMaemo5InformationBox::information(this, tr("You can't start name with digit"), QMaemo5InformationBox::DefaultTimeout);
207 QModelIndexList list_of_Mobil_tone = selModelMobil->selectedIndexes();
208 if(list_of_Mobil_tone.empty())
210 QMaemo5InformationBox::information(this, tr("Select ringtone for mobile"), QMaemo5InformationBox::DefaultTimeout);
214 QModelIndexList list_of_SMS_tone = selModelSMS->selectedIndexes();
215 if(list_of_SMS_tone.empty())
217 QMaemo5InformationBox::information(this, tr("Select ringtone for SMS"), QMaemo5InformationBox::DefaultTimeout);
221 QModelIndexList list_of_IM_tone = selModelIM->selectedIndexes();
222 if(list_of_IM_tone.empty())
224 QMaemo5InformationBox::information(this, tr("Select ringtone for IM"), QMaemo5InformationBox::DefaultTimeout);
228 QModelIndexList list_of_Email_tone = selModelEmail->selectedIndexes();
229 if(list_of_Email_tone.empty())
231 QMaemo5InformationBox::information(this, tr("Select ringtone for E-mail"), QMaemo5InformationBox::DefaultTimeout);
235 // QModelIndexList list = selModelMobil->selectedIndexes();
237 // for(int i = 0; i < list.size(); i++) {
238 // //qDebug() << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << list.at(i).data().toString();
241 // //qDebug() << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << " tisk dat z dialogu";
242 // //qDebug() << "text je " << ui->lineEdit_nameprofile->text();
243 // //qDebug() << "email volume je " << ui->slider_email_volume->value();
244 // //qDebug() << "im volume je " << ui->slider_im_volume->value();
245 // //qDebug() << "ring volume je " << ui->slider_ringing_volume->value();
246 // //qDebug() << "sms volume je " << ui->slider_sms_volume->value();
247 // //qDebug() << "key board je " << ui->buttonGroup_keyboard->checkedId();
248 // //qDebug() << "screen je " << ui->buttonGroup_screen->checkedId();
249 // //qDebug() << "system je " << ui->buttonGroup_system->checkedId();
250 // //qDebug() << list_of_Mobil_tone.at(1).data().toString() ;
251 // //qDebug() << "zvuk SMS " << list_of_SMS_tone.at(1).data().toString() ;
252 // //qDebug() << "zvuk Im " << list_of_IM_tone.at(1).data().toString() ;
253 // //qDebug() << "zvuk email " << list_of_Email_tone.at(1).data().toString() ;
254 // //qDebug() << __FILE__ << ":" << __LINE__ << " " << __FUNCTION__ << "konec tisku dat z dialogu";
255 //m_settings->setValue("Settings/rememberGeometry", geometryCb->isChecked());
257 profile->SetName(ui->lineEdit_nameprofile->text());
259 profile->SetRingingAlertVolume(QVariant(ui->slider_ringing_volume->value()));
260 profile->SetSmsAlertVolume(QVariant(ui->slider_im_volume->value()));
261 profile->SetImAlertVolume(QVariant(ui->slider_im_volume->value()));
262 profile->SetEmailAlertVolume(QVariant(ui->slider_email_volume->value()));
264 profile->SetKeypadSoundLevel(QVariant(ui->buttonGroup_keyboard->checkedId()));
265 profile->SetTouchscreenSoundLevel(QVariant(ui->buttonGroup_screen->checkedId()));
266 profile->SetSystemSoundLevel(QVariant(ui->buttonGroup_system->checkedId()));
268 profile->SetRingingAlertTone(list_of_Mobil_tone.at(1).data());
269 profile->SetSmsAlertTone(list_of_SMS_tone.at(1).data());
270 profile->SetImAlertTone(list_of_IM_tone.at(1).data());
271 profile->SetEmailAlertTone(list_of_Email_tone.at(1).data());
273 profile->SetVibratingAlertEnabled(QVariant((int)ui->check_vibration->isChecked()));
274 profile->SetRingingAlertType(QVariant(QString("ringing")));
276 switch (ui->buttonGroup_ringing->checkedId())
279 profile->SetRingingAlertType(QVariant(QString("ringing")));
282 profile->SetRingingAlertType(QVariant(QString("silent")));
285 profile->SetRingingAlertType(QVariant(QString("ringing")));
288 profile->SetCalendarAlarmEnabled(QVariant((int)ui->checkCalendarAlarm->isChecked()));
289 profile->SetClockAlarmEnabled(QVariant((int)ui->checkClockAlarm->isChecked()));
291 done(QDialog::Accepted);
295 Method setup Radio buttons
296 If updating profile setradio buttons to profile values
298 void ProfilDialog::createRadioID()
300 ui->buttonGroup_system->setId(ui->radioB_system1, 0);
301 ui->buttonGroup_system->setId(ui->radioB_system2, 1);
302 ui->buttonGroup_system->setId(ui->radioB_system3, 2);
304 ui->buttonGroup_keyboard->setId(ui->radioB_keyboard_1,0);
305 ui->buttonGroup_keyboard->setId(ui->radioB_keyboard_2,1);
306 ui->buttonGroup_keyboard->setId(ui->radioB_keyboard_3,2);
308 ui->buttonGroup_screen->setId(ui->radioB_screen_1,0);
309 ui->buttonGroup_screen->setId(ui->radioB_screen_2,1);
310 ui->buttonGroup_screen->setId(ui->radioB_screen_3,2);
312 ui->buttonGroup_ringing->setId(ui->radioButton_ringing,0);
313 ui->buttonGroup_ringing->setId(ui->radioButton_silent,1);
317 if(profile->GetRingingAlertType().toString().contains(QString("ringing")))
319 ui->radioButton_ringing->setChecked(true);
321 ui->radioButton_silent->setChecked(true);
323 ui->check_vibration->setChecked(profile->GetVibratingAlertEnabled().toBool());
324 ui->checkCalendarAlarm->setChecked(profile->GetCalendarAlarmEnabled().toBool());
325 ui->checkClockAlarm->setChecked(profile->GetClockAlarmEnabled().toBool());
327 ui->radioButton_ringing->setChecked(true);
330 switch (profile->GetSystemSoundLevel().toInt())
333 ui->radioB_system1->setChecked(true);
336 ui->radioB_system2->setChecked(true);
339 ui->radioB_system3->setChecked(true);
342 ui->radioB_system1->setChecked(true);
345 switch (profile->GetKeypadSoundLevel().toInt())
348 ui->radioB_keyboard_1->setChecked(true);
351 ui->radioB_keyboard_2->setChecked(true);
354 ui->radioB_keyboard_3->setChecked(true);
357 ui->radioB_keyboard_1->setChecked(true);
360 switch (profile->GetKeypadSoundLevel().toInt())
363 ui->radioB_screen_1->setChecked(true);
366 ui->radioB_screen_2->setChecked(true);
369 ui->radioB_screen_3->setChecked(true);
372 ui->radioB_screen_1->setChecked(true);
376 /** on_ButtonLoadSound_clicked()
377 Slot for loading music files
379 void ProfilDialog::on_ButtonLoadSound_clicked()
381 QString fileName = QFileDialog::getOpenFileName(this, tr("Choose sound file"),"/home/user",tr("Sound files (*.wav *.mp3 *.AAC *.eAAC* *.acc *.wma *.m4a)"));
383 if (fileName.isEmpty())
386 QFileInfo file(fileName);
388 QList<QStandardItem *> items;
390 if(model_of_files != NULL)
391 if(checkFileInModelAndExist(file)){
392 //qDebug() << "In file:" << __FILE__ << ":" << "on line:" << __LINE__ << " in function:" << __FUNCTION__ << "text::" << " bude se pridavat do modelu toto" << file.absoluteFilePath();
393 items.append(new QStandardItem(file.fileName()));
394 items.append(new QStandardItem(file.absoluteFilePath()));
395 model_of_files->appendRow(items);
399 /** checkFileInModelAndExist()
400 Check if this audio file is already added
402 bool ProfilDialog::checkFileInModelAndExist(QFileInfo inf)
404 if(!inf.exists()) return false;
405 if(!model_of_files->findItems(inf.absoluteFilePath(),Qt::MatchExactly, 1).empty()) return false;
409 /** on_slider_ringing_volume_valueChanged
410 Slot for changing volume in text label
412 void ProfilDialog::on_slider_ringing_volume_valueChanged(int value)
416 ui->label_ringing_volume->setText(str.arg(tr("Ringing:"),QString().setNum(value)));
419 /** on_slider_sms_volume_valueChanged
420 Slot for changing volume in text label
422 void ProfilDialog::on_slider_sms_volume_valueChanged(int value)
426 ui->label_sms_volume->setText(str.arg(QString("SMS:"),QString().setNum(value)));
429 /** on_slider_im_volume_valueChanged
430 Slot for changing volume in text label
432 void ProfilDialog::on_slider_im_volume_valueChanged(int value)
436 ui->label_im_volume->setText( str.arg(QString("IM:"),QString().setNum(value)));
439 /** on_slider_email_volume_valueChanged
440 Slot for changing volume in text label
442 void ProfilDialog::on_slider_email_volume_valueChanged(int value)
446 ui->label_email_volume->setText( str.arg(QString("E-mail:"),QString().setNum(value)));
449 /** changeEvent(QEvent *e)
452 void ProfilDialog::changeEvent(QEvent *e)
454 QDialog::changeEvent(e);
456 case QEvent::LanguageChange:
457 ui->retranslateUi(this);