| | 1 | #include "standardsettings.h" |
| | 2 | #include <QCoreApplication> |
| | 3 | |
| | 4 | #include <mythcontext.h> |
| | 5 | #include <mythmainwindow.h> |
| | 6 | #include <mythdialogbox.h> |
| | 7 | #include <mythuispinbox.h> |
| | 8 | #include <mythuitext.h> |
| | 9 | #include <mythuibutton.h> |
| | 10 | #include <mythuifilebrowser.h> |
| | 11 | #include "mythlogging.h" |
| | 12 | |
| | 13 | void MythUIButtonListItemSetting::ShouldUpdate(StandardSetting *setting) |
| | 14 | { |
| | 15 | if (setting) //??? |
| | 16 | LOG(VB_GENERAL, LOG_ERR, QString("MythUIButtonListItemSetting::ShouldUpdate(%1)=>%2") |
| | 17 | .arg(setting->getLabel()) |
| | 18 | .arg(setting->getValue())); |
| | 19 | setting->updateButton(this); |
| | 20 | } |
| | 21 | |
| | 22 | StandardSetting::StandardSetting(Storage *_storage) : |
| | 23 | m_enabled(true), m_label(""), m_helptext(""), m_visible(true), |
| | 24 | m_haveChanged(false), |
| | 25 | m_storage(_storage), |
| | 26 | |
| | 27 | |
| | 28 | m_parent(NULL) |
| | 29 | |
| | 30 | { |
| | 31 | } |
| | 32 | |
| | 33 | StandardSetting::~StandardSetting() |
| | 34 | { |
| | 35 | QList<StandardSetting *>::const_iterator i; |
| | 36 | for (i = m_children.constBegin(); i != m_children.constEnd(); ++i) |
| | 37 | delete *i; |
| | 38 | m_children.clear(); |
| | 39 | |
| | 40 | QMap<QString, QList<StandardSetting *> >::const_iterator iMap; |
| | 41 | for (iMap = m_targets.constBegin(); iMap != m_targets.constEnd(); ++iMap) |
| | 42 | { |
| | 43 | for (i = (*iMap).constBegin(); i != (*iMap).constEnd(); ++i) |
| | 44 | delete *i; |
| | 45 | } |
| | 46 | m_targets.clear(); |
| | 47 | } |
| | 48 | |
| | 49 | MythUIButtonListItem * StandardSetting::createButton(MythUIButtonList * list) |
| | 50 | { |
| | 51 | MythUIButtonListItemSetting *item = new MythUIButtonListItemSetting(list, m_label); |
| | 52 | item->SetData(qVariantFromValue(this)); |
| | 53 | connect(this, SIGNAL(ShouldRedraw(StandardSetting *)), item, SLOT(ShouldUpdate(StandardSetting *))); |
| | 54 | updateButton(item); |
| | 55 | return item; |
| | 56 | } |
| | 57 | |
| | 58 | void StandardSetting::setEnabled(bool b) |
| | 59 | { |
| | 60 | m_enabled = b; |
| | 61 | emit ShouldRedraw(this); |
| | 62 | } |
| | 63 | |
| | 64 | void StandardSetting::setParent(StandardSetting *parent) |
| | 65 | { |
| | 66 | m_parent = parent; |
| | 67 | } |
| | 68 | |
| | 69 | void StandardSetting::addChild(StandardSetting *child) |
| | 70 | { |
| | 71 | if (!child)return; |
| | 72 | m_children.append(child); |
| | 73 | child->setParent(this); |
| | 74 | } |
| | 75 | |
| | 76 | bool StandardSetting::keyPressEvent(QKeyEvent *) |
| | 77 | { |
| | 78 | return false; |
| | 79 | } |
| | 80 | |
| | 81 | /** |
| | 82 | * This method is called whenever the UI need to reflect a change |
| | 83 | * Reimplement this If you widget need a custom look |
| | 84 | * \param item is the associated MythUIButtonListItem to be updated |
| | 85 | */ |
| | 86 | void StandardSetting::updateButton(MythUIButtonListItem *item) |
| | 87 | { |
| | 88 | item->DisplayState("standard", "widgettype"); |
| | 89 | item->setEnabled(isEnabled()); |
| | 90 | item->SetText(m_label); |
| | 91 | item->SetText(m_settingValue,"value"); |
| | 92 | item->SetText(getHelpText(),"description"); |
| | 93 | item->setDrawArrow (haveSubSettings()); |
| | 94 | } |
| | 95 | |
| | 96 | void StandardSetting::addTargetedChild(const QString &value, StandardSetting * setting) |
| | 97 | { |
| | 98 | m_targets[value].append(setting); |
| | 99 | setting->setParent(this); |
| | 100 | } |
| | 101 | |
| | 102 | |
| | 103 | QList<StandardSetting *> *StandardSetting::getSubSettings() |
| | 104 | { |
| | 105 | if (m_targets.contains(m_settingValue) && m_targets[m_settingValue].size()>0) |
| | 106 | return &m_targets[m_settingValue]; |
| | 107 | return &m_children; |
| | 108 | } |
| | 109 | |
| | 110 | bool StandardSetting::haveSubSettings() |
| | 111 | { |
| | 112 | QList<StandardSetting *> * subSettings=getSubSettings(); |
| | 113 | return (subSettings!=NULL && subSettings->size()>0); |
| | 114 | } |
| | 115 | |
| | 116 | void StandardSetting::clearSettings() |
| | 117 | { |
| | 118 | m_children.clear(); |
| | 119 | } |
| | 120 | |
| | 121 | void StandardSetting::setValue(const QString &newValue) |
| | 122 | { |
| | 123 | m_settingValue = newValue; |
| | 124 | m_haveChanged=true; |
| | 125 | emit valueChanged(newValue); |
| | 126 | emit valueChanged(this); |
| | 127 | emit ShouldRedraw(this); |
| | 128 | } |
| | 129 | |
| | 130 | |
| | 131 | /** |
| | 132 | * Return true if the setting have changed or any of its children |
| | 133 | */ |
| | 134 | bool StandardSetting::haveChanged() |
| | 135 | { |
| | 136 | if (m_haveChanged) |
| | 137 | { |
| | 138 | LOG(VB_GENERAL, LOG_ERR, QString("Is changed %1").arg(getLabel())); |
| | 139 | return true; |
| | 140 | } |
| | 141 | //else |
| | 142 | //LOG(VB_GENERAL, LOG_ERR, QString("Is not changed %1").arg(getLabel())); |
| | 143 | |
| | 144 | //we check only the relevant children |
| | 145 | QList<StandardSetting *> *children = getSubSettings(); |
| | 146 | if (children==NULL) return false; |
| | 147 | QList<StandardSetting *>::const_iterator i; |
| | 148 | bool haveChanged = false; |
| | 149 | for (i = children->constBegin(); !haveChanged && i != children->constEnd(); ++i) |
| | 150 | haveChanged=(*i)->haveChanged(); |
| | 151 | |
| | 152 | return haveChanged; |
| | 153 | } |
| | 154 | |
| | 155 | void StandardSetting::Load(void) |
| | 156 | { |
| | 157 | m_haveChanged=false; |
| | 158 | |
| | 159 | QList<StandardSetting *>::const_iterator i; |
| | 160 | for (i = m_children.constBegin(); i != m_children.constEnd(); ++i) |
| | 161 | (*i)->Load(); |
| | 162 | |
| | 163 | QMap<QString, QList<StandardSetting *> >::const_iterator iMap; |
| | 164 | for (iMap = m_targets.constBegin(); iMap != m_targets.constEnd(); ++iMap) |
| | 165 | { |
| | 166 | for (i = (*iMap).constBegin(); i != (*iMap).constEnd(); ++i) |
| | 167 | (*i)->Load(); |
| | 168 | } |
| | 169 | } |
| | 170 | |
| | 171 | void StandardSetting::Save(void) |
| | 172 | { |
| | 173 | m_haveChanged=false; |
| | 174 | |
| | 175 | //we save only the relevant children |
| | 176 | QList<StandardSetting *> *children = getSubSettings(); |
| | 177 | if (children==NULL) return; |
| | 178 | QList<StandardSetting *>::const_iterator i; |
| | 179 | for (i = children->constBegin(); i != children->constEnd(); ++i) |
| | 180 | (*i)->Save(); |
| | 181 | } |
| | 182 | |
| | 183 | /******************************************************************************* |
| | 184 | Group Setting |
| | 185 | ********************************************************************************/ |
| | 186 | GroupSetting::GroupSetting(): |
| | 187 | StandardSetting(this), TransientStorage() |
| | 188 | { |
| | 189 | } |
| | 190 | |
| | 191 | void GroupSetting::edit(MythScreenType * screen) |
| | 192 | { |
| | 193 | if (!isEnabled())return; |
| | 194 | DialogCompletionEvent *dce = |
| | 195 | new DialogCompletionEvent("leveldown", 0, "", ""); |
| | 196 | QCoreApplication::postEvent(screen, dce); |
| | 197 | } |
| | 198 | |
| | 199 | void GroupSetting::updateButton(MythUIButtonListItem *item) |
| | 200 | { |
| | 201 | item->DisplayState("group", "widgettype"); |
| | 202 | item->setEnabled(isEnabled()); |
| | 203 | item->SetText(m_label); |
| | 204 | item->SetText(m_settingValue,"value"); |
| | 205 | item->SetText(getHelpText(),"description"); |
| | 206 | item->setDrawArrow (haveSubSettings()); |
| | 207 | } |
| | 208 | |
| | 209 | |
| | 210 | ButtonStandardSetting::ButtonStandardSetting(const QString &): |
| | 211 | StandardSetting(this), TransientStorage() |
| | 212 | { |
| | 213 | } |
| | 214 | |
| | 215 | void ButtonStandardSetting::edit(MythScreenType * screen) |
| | 216 | { |
| | 217 | emit clicked(); |
| | 218 | } |
| | 219 | |
| | 220 | |
| | 221 | /******************************************************************************* |
| | 222 | Text Setting |
| | 223 | ********************************************************************************/ |
| | 224 | |
| | 225 | MythUITextEditSetting::MythUITextEditSetting(Storage *_storage): |
| | 226 | StandardSetting(_storage) |
| | 227 | { |
| | 228 | } |
| | 229 | |
| | 230 | void MythUITextEditSetting::edit(MythScreenType * screen) |
| | 231 | { |
| | 232 | if (!isEnabled())return; |
| | 233 | MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); |
| | 234 | |
| | 235 | MythTextInputDialog *settingdialog = |
| | 236 | new MythTextInputDialog(popupStack, |
| | 237 | getLabel(),FilterNone, false,m_settingValue); |
| | 238 | |
| | 239 | if (settingdialog->Create()) |
| | 240 | { |
| | 241 | settingdialog->SetReturnEvent(screen, "editsetting"); |
| | 242 | popupStack->AddScreen(settingdialog); |
| | 243 | } |
| | 244 | }; |
| | 245 | |
| | 246 | void MythUITextEditSetting::resultEdit(DialogCompletionEvent *dce) |
| | 247 | { |
| | 248 | if (m_settingValue!=dce->GetResultText()) |
| | 249 | { |
| | 250 | setValue(dce->GetResultText()); |
| | 251 | } |
| | 252 | } |
| | 253 | |
| | 254 | |
| | 255 | void MythUITextEditSetting::updateButton(MythUIButtonListItem *item) |
| | 256 | { |
| | 257 | StandardSetting::updateButton(item); |
| | 258 | item->DisplayState("textedit", "widgettype"); |
| | 259 | } |
| | 260 | |
| | 261 | |
| | 262 | /******************************************************************************* |
| | 263 | Directory Setting |
| | 264 | ********************************************************************************/ |
| | 265 | |
| | 266 | MythUIFileBrowserSetting::MythUIFileBrowserSetting(Storage *_storage): |
| | 267 | StandardSetting(_storage) |
| | 268 | { |
| | 269 | m_typeFilter = (QDir::AllDirs | QDir::Drives | QDir::Files | |
| | 270 | QDir::Readable | QDir::Writable | QDir::Executable); |
| | 271 | m_nameFilter.clear(); |
| | 272 | m_nameFilter << "*"; |
| | 273 | } |
| | 274 | |
| | 275 | void MythUIFileBrowserSetting::edit(MythScreenType * screen) |
| | 276 | { |
| | 277 | if (!isEnabled())return; |
| | 278 | MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); |
| | 279 | |
| | 280 | MythUIFileBrowser *settingdialog = |
| | 281 | new MythUIFileBrowser(popupStack, |
| | 282 | m_settingValue); |
| | 283 | settingdialog->SetTypeFilter(m_typeFilter); |
| | 284 | settingdialog->SetNameFilter(m_nameFilter); |
| | 285 | |
| | 286 | if (settingdialog->Create()) |
| | 287 | { |
| | 288 | settingdialog->SetReturnEvent(screen, "editsetting"); |
| | 289 | popupStack->AddScreen(settingdialog); |
| | 290 | } |
| | 291 | }; |
| | 292 | |
| | 293 | void MythUIFileBrowserSetting::resultEdit(DialogCompletionEvent *dce) |
| | 294 | { |
| | 295 | if (m_settingValue!=dce->GetResultText()) |
| | 296 | { |
| | 297 | setValue(dce->GetResultText()); |
| | 298 | } |
| | 299 | } |
| | 300 | |
| | 301 | void MythUIFileBrowserSetting::updateButton(MythUIButtonListItem *item) |
| | 302 | { |
| | 303 | StandardSetting::updateButton(item); |
| | 304 | item->DisplayState("filebrowser", "widgettype"); |
| | 305 | } |
| | 306 | |
| | 307 | |
| | 308 | /******************************************************************************* |
| | 309 | ComboBoxSetting |
| | 310 | ********************************************************************************/ |
| | 311 | /** |
| | 312 | * Create a Setting Widget to select the value from a list |
| | 313 | * \param rw if set to true, the user can input it's own value |
| | 314 | */ |
| | 315 | MythUIComboBoxSetting::MythUIComboBoxSetting(Storage *_storage, bool rw): |
| | 316 | StandardSetting(_storage), |
| | 317 | m_rewrite(rw), |
| | 318 | m_isSet(false) |
| | 319 | { |
| | 320 | } |
| | 321 | |
| | 322 | MythUIComboBoxSetting::~MythUIComboBoxSetting() |
| | 323 | { |
| | 324 | m_labels.clear(); |
| | 325 | m_values.clear(); |
| | 326 | } |
| | 327 | |
| | 328 | void MythUIComboBoxSetting::setValue(int value) |
| | 329 | { |
| | 330 | if (value>=0 && value < m_values.size()) |
| | 331 | StandardSetting::setValue(m_values.at(value)); |
| | 332 | } |
| | 333 | |
| | 334 | void MythUIComboBoxSetting::addSelection(const QString &label, QString value, |
| | 335 | bool select) |
| | 336 | { |
| | 337 | value = (value.isEmpty()) ? label : value; |
| | 338 | m_labels.push_back(label); |
| | 339 | m_values.push_back(value); |
| | 340 | |
| | 341 | if (select || !m_isSet) |
| | 342 | { |
| | 343 | StandardSetting::setValue(value); |
| | 344 | if (!m_isSet) m_isSet = true; |
| | 345 | } |
| | 346 | } |
| | 347 | |
| | 348 | void MythUIComboBoxSetting::clearSelections() |
| | 349 | { |
| | 350 | m_labels.clear(); |
| | 351 | m_values.clear(); |
| | 352 | } |
| | 353 | |
| | 354 | void MythUIComboBoxSetting::updateButton(MythUIButtonListItem *item) |
| | 355 | { |
| | 356 | LOG(VB_GENERAL, LOG_ERR, QString("MythUIComboBoxSetting::updateButton(%1)").arg(getLabel())); |
| | 357 | item->DisplayState("combobox", "widgettype"); |
| | 358 | item->setEnabled(isEnabled()); |
| | 359 | item->SetText(m_label); |
| | 360 | int indexValue = m_values.indexOf(m_settingValue); |
| | 361 | if (indexValue >=0) |
| | 362 | item->SetText(m_labels.value(indexValue),"value"); |
| | 363 | else |
| | 364 | item->SetText(m_settingValue,"value"); |
| | 365 | item->SetText(getHelpText(),"description"); |
| | 366 | item->setDrawArrow (haveSubSettings()); |
| | 367 | } |
| | 368 | |
| | 369 | void MythUIComboBoxSetting::edit(MythScreenType * screen) |
| | 370 | { |
| | 371 | if (!isEnabled())return; |
| | 372 | MythScreenStack *popupStack = |
| | 373 | GetMythMainWindow()->GetStack("popup stack"); |
| | 374 | |
| | 375 | MythDialogBox * m_menuPopup = |
| | 376 | new MythDialogBox(getLabel(), popupStack, "optionmenu"); |
| | 377 | |
| | 378 | if (m_menuPopup->Create()) |
| | 379 | popupStack->AddScreen(m_menuPopup); |
| | 380 | |
| | 381 | // connect(m_menuPopup,SIGNAL(haveResult(QString)), this, SLOT(setValue(QString))); |
| | 382 | |
| | 383 | m_menuPopup->SetReturnEvent(screen, "editsetting"); |
| | 384 | |
| | 385 | if (m_rewrite) |
| | 386 | //FIXME This look like a hack to me, what if the list a a NEWENTRY value ? |
| | 387 | m_menuPopup->AddButton(QObject::tr("New entry"),QString("NEWENTRY"),false,m_settingValue==""); |
| | 388 | for (int i = 0; i < m_labels.size() && m_values.size(); ++i) |
| | 389 | { |
| | 390 | QString value = m_values.at(i); |
| | 391 | m_menuPopup->AddButton(m_labels.at(i),value,false,value==m_settingValue); |
| | 392 | } |
| | 393 | } |
| | 394 | |
| | 395 | void MythUIComboBoxSetting::setValue(const QString& newValue) |
| | 396 | { |
| | 397 | LOG(VB_GENERAL, LOG_ERR, QString("MythUIComboBoxSetting::setValue(%1)").arg(newValue)); |
| | 398 | StandardSetting::setValue(newValue); |
| | 399 | } |
| | 400 | |
| | 401 | void MythUIComboBoxSetting::resultEdit(DialogCompletionEvent *dce) |
| | 402 | { |
| | 403 | if (dce->GetResult()!=-1) |
| | 404 | { |
| | 405 | if ( m_rewrite && dce->GetData().toString()=="NEWENTRY") |
| | 406 | { |
| | 407 | MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); |
| | 408 | |
| | 409 | MythTextInputDialog *settingdialog = |
| | 410 | new MythTextInputDialog(popupStack, |
| | 411 | getLabel(),FilterNone, false,m_settingValue); |
| | 412 | |
| | 413 | if (settingdialog->Create()) |
| | 414 | { |
| | 415 | connect(settingdialog,SIGNAL(haveResult(QString)), |
| | 416 | this, SLOT(setValue(const QString&))); |
| | 417 | // settingdialog->SetReturnEvent(screen, "editsetting"); |
| | 418 | popupStack->AddScreen(settingdialog); |
| | 419 | } |
| | 420 | } |
| | 421 | else if ( m_settingValue!=dce->GetData().toString()) |
| | 422 | { |
| | 423 | StandardSetting::setValue(dce->GetData().toString()); |
| | 424 | } |
| | 425 | } |
| | 426 | } |
| | 427 | void MythUIComboBoxSetting::Load() |
| | 428 | { |
| | 429 | if (m_rewrite) |
| | 430 | LOG(VB_GENERAL, LOG_ERR, QString("MythUIComboBoxSetting::MythUIComboBoxSetting: need to implement rewrite for %1").arg(getLabel())); |
| | 431 | StandardSetting::Load(); |
| | 432 | } |
| | 433 | |
| | 434 | /******************************************************************************* |
| | 435 | SpinBox Setting |
| | 436 | ********************************************************************************/ |
| | 437 | MythUISpinBoxSetting::MythUISpinBoxSetting(Storage *_storage, int min, int max, int step, bool allow_single_step): |
| | 438 | MythUIComboBoxSetting(_storage, false), |
| | 439 | m_min(min), |
| | 440 | m_max(max), |
| | 441 | m_step(step), |
| | 442 | m_allow_single_step(allow_single_step) |
| | 443 | { |
| | 444 | //we default to 0 unless 0 is out of range |
| | 445 | if (m_min >0 || m_max < 0)m_settingValue=m_min; |
| | 446 | } |
| | 447 | |
| | 448 | void MythUISpinBoxSetting::updateButton(MythUIButtonListItem *item) |
| | 449 | { |
| | 450 | LOG(VB_GENERAL, LOG_ERR, QString("MythUISpinBoxSetting::updateButton(%1)").arg(getLabel())); |
| | 451 | item->DisplayState("spinbox", "widgettype"); |
| | 452 | item->setEnabled(isEnabled()); |
| | 453 | item->SetText(m_label); |
| | 454 | int indexValue = m_values.indexOf(m_settingValue); |
| | 455 | if (indexValue >=0) |
| | 456 | item->SetText(m_labels.value(indexValue),"value"); |
| | 457 | else |
| | 458 | item->SetText(m_settingValue,"value"); |
| | 459 | item->SetText(getHelpText(),"description"); |
| | 460 | item->setDrawArrow (haveSubSettings()); |
| | 461 | } |
| | 462 | |
| | 463 | int MythUISpinBoxSetting::intValue() |
| | 464 | { |
| | 465 | return m_settingValue.toInt(); |
| | 466 | } |
| | 467 | |
| | 468 | void MythUISpinBoxSetting::edit(MythScreenType * screen) |
| | 469 | { |
| | 470 | if (!isEnabled())return; |
| | 471 | |
| | 472 | MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); |
| | 473 | |
| | 474 | MythSpinBoxDialog *settingdialog = |
| | 475 | new MythSpinBoxDialog(popupStack, |
| | 476 | getLabel()); |
| | 477 | |
| | 478 | if (settingdialog->Create()) |
| | 479 | { |
| | 480 | settingdialog->SetRange(m_min, m_max, m_step); |
| | 481 | //Add custom values |
| | 482 | for (int i = 0; i < m_labels.size() && m_values.size(); ++i) |
| | 483 | { |
| | 484 | QString value = m_values.at(i); |
| | 485 | settingdialog->AddSelection(m_labels.at(i),value.toInt()); |
| | 486 | } |
| | 487 | LOG(VB_GENERAL, LOG_ERR, QString("MythUISpinBoxSetting::edit(%1) SetValue(%2)").arg(getLabel()).arg(m_settingValue)); |
| | 488 | settingdialog->SetValue(m_settingValue); |
| | 489 | settingdialog->SetReturnEvent(screen, "editsetting"); |
| | 490 | popupStack->AddScreen(settingdialog); |
| | 491 | } |
| | 492 | }; |
| | 493 | |
| | 494 | void MythUISpinBoxSetting::resultEdit(DialogCompletionEvent *dce) |
| | 495 | { |
| | 496 | LOG(VB_GENERAL, LOG_ERR, QString("MythUISpinBoxSetting::resultEdit(DialogCompletionEvent *dce) START")); |
| | 497 | if (m_settingValue!=dce->GetResultText()) |
| | 498 | { |
| | 499 | MythUIComboBoxSetting::setValue(dce->GetResultText()); |
| | 500 | } |
| | 501 | LOG(VB_GENERAL, LOG_ERR, QString("MythUISpinBoxSetting::resultEdit(DialogCompletionEvent *dce) END")); |
| | 502 | } |
| | 503 | |
| | 504 | /******************************************************************************* |
| | 505 | MythUICheckBoxSetting |
| | 506 | ********************************************************************************/ |
| | 507 | |
| | 508 | MythUICheckBoxSetting::MythUICheckBoxSetting(Storage *_storage): |
| | 509 | StandardSetting(_storage) |
| | 510 | { |
| | 511 | } |
| | 512 | |
| | 513 | bool MythUICheckBoxSetting::boolValue() |
| | 514 | { |
| | 515 | return m_settingValue=="1"; |
| | 516 | } |
| | 517 | |
| | 518 | void MythUICheckBoxSetting::setValue(const QString &value) |
| | 519 | { |
| | 520 | StandardSetting::setValue(value); |
| | 521 | emit valueChanged(value=="1"); |
| | 522 | } |
| | 523 | |
| | 524 | void MythUICheckBoxSetting::setValue(bool value) |
| | 525 | { |
| | 526 | StandardSetting::setValue(value?"1":"0"); |
| | 527 | emit valueChanged(value); |
| | 528 | } |
| | 529 | |
| | 530 | void MythUICheckBoxSetting::updateButton(MythUIButtonListItem *item) |
| | 531 | { |
| | 532 | StandardSetting::updateButton(item); |
| | 533 | item->DisplayState("checkbox", "widgettype"); |
| | 534 | item->setCheckable (true); |
| | 535 | item->SetText("","value"); |
| | 536 | if (m_settingValue=="1") |
| | 537 | item->setChecked(MythUIButtonListItem::FullChecked); |
| | 538 | else |
| | 539 | item->setChecked(MythUIButtonListItem::NotChecked); |
| | 540 | } |
| | 541 | |
| | 542 | void MythUICheckBoxSetting::edit(MythScreenType * screen) |
| | 543 | { |
| | 544 | if (!isEnabled())return; |
| | 545 | DialogCompletionEvent *dce = |
| | 546 | new DialogCompletionEvent("editsetting", 0, "", ""); |
| | 547 | QCoreApplication::postEvent(screen, dce); |
| | 548 | } |
| | 549 | |
| | 550 | void MythUICheckBoxSetting::resultEdit(DialogCompletionEvent *dce) |
| | 551 | { |
| | 552 | setValue(!boolValue()); |
| | 553 | } |
| | 554 | |
| | 555 | /******************************************************************************* |
| | 556 | Standard setting dialog |
| | 557 | ********************************************************************************/ |
| | 558 | |
| | 559 | StandardSettingDialog::StandardSettingDialog(MythScreenStack *parent, const char *name) : |
| | 560 | MythScreenType(parent, name), |
| | 561 | m_buttonList(0), |
| | 562 | m_title(0), |
| | 563 | m_groupHelp(0), |
| | 564 | m_selectedSettingHelp(0), |
| | 565 | m_menuPopup(0), |
| | 566 | m_settingsTree(0), |
| | 567 | m_currentGroupSetting(0) |
| | 568 | { |
| | 569 | } |
| | 570 | |
| | 571 | StandardSettingDialog::~StandardSettingDialog() |
| | 572 | { |
| | 573 | //LOG(VB_GENERAL, LOG_ERR, "StandardSettingDialog::~StandardSettingDialog()"); |
| | 574 | if (m_settingsTree!=0) |
| | 575 | m_settingsTree->deleteLater(); |
| | 576 | } |
| | 577 | |
| | 578 | bool StandardSettingDialog::Create(void) |
| | 579 | { |
| | 580 | if (!LoadWindowFromXML("standardsetting-ui.xml", "settingssetup", this)) |
| | 581 | return false; |
| | 582 | |
| | 583 | bool error=false; |
| | 584 | UIUtilE::Assign(this, m_title, "title",&error); |
| | 585 | UIUtilW::Assign(this, m_groupHelp, "grouphelp",&error); |
| | 586 | UIUtilE::Assign(this, m_buttonList,"settingslist",&error); |
| | 587 | |
| | 588 | UIUtilW::Assign(this, m_selectedSettingHelp, "selectedsettinghelp"); |
| | 589 | |
| | 590 | connect(m_buttonList,SIGNAL(itemSelected(MythUIButtonListItem*)), |
| | 591 | this,SLOT(settingSelected(MythUIButtonListItem*))); |
| | 592 | connect(m_buttonList,SIGNAL(itemClicked(MythUIButtonListItem*)), |
| | 593 | this,SLOT(settingClicked(MythUIButtonListItem*))); |
| | 594 | |
| | 595 | if (error) |
| | 596 | { |
| | 597 | LOG(VB_GENERAL, LOG_ERR, "error."); |
| | 598 | return false; |
| | 599 | } |
| | 600 | BuildFocusList(); |
| | 601 | |
| | 602 | return true; |
| | 603 | } |
| | 604 | |
| | 605 | void StandardSettingDialog::settingSelected(MythUIButtonListItem *item) |
| | 606 | { |
| | 607 | if (!item)return; |
| | 608 | |
| | 609 | StandardSetting * setting = qVariantValue<StandardSetting*>(item->GetData()); |
| | 610 | if (setting && m_selectedSettingHelp) |
| | 611 | { |
| | 612 | m_selectedSettingHelp->SetText(setting->getHelpText()); |
| | 613 | if (m_selectedSettingHelp->GetText().isEmpty()) m_selectedSettingHelp->SetText("This setting need a description"); |
| | 614 | } |
| | 615 | } |
| | 616 | |
| | 617 | void StandardSettingDialog::settingClicked(MythUIButtonListItem *item) |
| | 618 | { |
| | 619 | StandardSetting* setting = item->GetData().value<StandardSetting*>(); |
| | 620 | if (setting) |
| | 621 | { |
| | 622 | setting->edit(this); |
| | 623 | } |
| | 624 | } |
| | 625 | |
| | 626 | void StandardSettingDialog::customEvent(QEvent *event) |
| | 627 | { |
| | 628 | if (event->type() == DialogCompletionEvent::kEventType) |
| | 629 | { |
| | 630 | DialogCompletionEvent *dce = (DialogCompletionEvent*)(event); |
| | 631 | QString resultid = dce->GetId(); |
| | 632 | |
| | 633 | if (resultid == "leveldown") |
| | 634 | { |
| | 635 | //a GroupSetting have been clicked |
| | 636 | LevelDown(); |
| | 637 | } |
| | 638 | else if (resultid == "editsetting") |
| | 639 | { |
| | 640 | MythUIButtonListItem * item = m_buttonList->GetItemCurrent(); |
| | 641 | if (item) |
| | 642 | { |
| | 643 | StandardSetting * ss = item->GetData().value<StandardSetting*>(); |
| | 644 | if (ss) |
| | 645 | { |
| | 646 | ss->resultEdit(dce); |
| | 647 | } |
| | 648 | } |
| | 649 | } |
| | 650 | else if (resultid == "exit") |
| | 651 | { |
| | 652 | int buttonnum = dce->GetResult(); |
| | 653 | if (buttonnum == 0) |
| | 654 | { |
| | 655 | Save(); |
| | 656 | MythScreenType::Close(); |
| | 657 | if (m_settingsTree) |
| | 658 | m_settingsTree->applyChange(); |
| | 659 | } |
| | 660 | else if (buttonnum == 1) |
| | 661 | MythScreenType::Close(); |
| | 662 | } |
| | 663 | } |
| | 664 | } |
| | 665 | |
| | 666 | void StandardSettingDialog::loadSettings(GroupSetting * groupSettings) |
| | 667 | { |
| | 668 | //TODO I probably should do this in the background ? |
| | 669 | m_settingsTree=groupSettings; |
| | 670 | if (m_settingsTree) |
| | 671 | m_settingsTree->Load(); |
| | 672 | |
| | 673 | setCurrentGroupSetting(m_settingsTree); |
| | 674 | } |
| | 675 | |
| | 676 | void StandardSettingDialog::setCurrentGroupSetting(StandardSetting * groupSettings, |
| | 677 | StandardSetting * selectedSetting ) |
| | 678 | { |
| | 679 | if (!groupSettings) return; |
| | 680 | |
| | 681 | if (m_currentGroupSetting) |
| | 682 | { |
| | 683 | disconnect(m_currentGroupSetting, SIGNAL(settingsChanged(StandardSetting *)), 0, 0); |
| | 684 | m_currentGroupSetting->Close(); |
| | 685 | } |
| | 686 | |
| | 687 | m_currentGroupSetting=groupSettings; |
| | 688 | |
| | 689 | m_currentGroupSetting->Open(); |
| | 690 | |
| | 691 | |
| | 692 | m_title->SetText(m_currentGroupSetting->getLabel()); |
| | 693 | if (m_title->GetText().isEmpty()) m_title->SetText("This group need a title"); |
| | 694 | if (m_groupHelp) |
| | 695 | { |
| | 696 | m_groupHelp->SetText(m_currentGroupSetting->getHelpText()); |
| | 697 | if (m_groupHelp->GetText().isEmpty()) m_groupHelp->SetText("This group need a description"); |
| | 698 | } |
| | 699 | updateSettings(selectedSetting); |
| | 700 | connect(m_currentGroupSetting, SIGNAL(settingsChanged(StandardSetting *)), this, SLOT(updateSettings(StandardSetting *))); |
| | 701 | |
| | 702 | } |
| | 703 | |
| | 704 | void StandardSettingDialog::updateSettings(StandardSetting * selectedSetting) |
| | 705 | { |
| | 706 | m_buttonList->Reset(); |
| | 707 | if (!m_currentGroupSetting->haveSubSettings())return; |
| | 708 | QList<StandardSetting *> * settings = m_currentGroupSetting->getSubSettings(); |
| | 709 | if (settings==NULL ) return; |
| | 710 | QList<StandardSetting *>::const_iterator i; |
| | 711 | MythUIButtonListItem *selectedItem=0; |
| | 712 | for (i = settings->constBegin(); i != settings->constEnd(); ++i) |
| | 713 | { |
| | 714 | if (selectedSetting == (*i)) |
| | 715 | selectedItem =(*i)->createButton(m_buttonList); |
| | 716 | else |
| | 717 | (*i)->createButton(m_buttonList); |
| | 718 | } |
| | 719 | if (selectedItem) |
| | 720 | m_buttonList->SetItemCurrent(selectedItem); |
| | 721 | settingSelected(m_buttonList->GetItemCurrent()); |
| | 722 | } |
| | 723 | |
| | 724 | void StandardSettingDialog::Save() |
| | 725 | { |
| | 726 | if (m_settingsTree) |
| | 727 | m_settingsTree->Save(); |
| | 728 | } |
| | 729 | |
| | 730 | void StandardSettingDialog::LevelUp() |
| | 731 | { |
| | 732 | if (!m_currentGroupSetting) return; |
| | 733 | if (m_currentGroupSetting->getParent()) |
| | 734 | { |
| | 735 | setCurrentGroupSetting(m_currentGroupSetting->getParent(), |
| | 736 | m_currentGroupSetting); |
| | 737 | } |
| | 738 | } |
| | 739 | |
| | 740 | void StandardSettingDialog::LevelDown() |
| | 741 | { |
| | 742 | MythUIButtonListItem * item = m_buttonList->GetItemCurrent(); |
| | 743 | if (item) |
| | 744 | { |
| | 745 | StandardSetting * ss = item->GetData().value<StandardSetting*>(); |
| | 746 | if (ss && ss->haveSubSettings() && ss->isEnabled()) |
| | 747 | setCurrentGroupSetting(ss); |
| | 748 | } |
| | 749 | } |
| | 750 | |
| | 751 | void StandardSettingDialog::Close(void) |
| | 752 | { |
| | 753 | if (m_settingsTree->haveChanged()) |
| | 754 | { |
| | 755 | QString label = tr("Exit ?"); |
| | 756 | |
| | 757 | MythScreenStack *popupStack = |
| | 758 | GetMythMainWindow()->GetStack("popup stack"); |
| | 759 | |
| | 760 | MythDialogBox * m_menuPopup = |
| | 761 | new MythDialogBox(label, popupStack, "exitmenu"); |
| | 762 | |
| | 763 | if (m_menuPopup->Create()) |
| | 764 | popupStack->AddScreen(m_menuPopup); |
| | 765 | |
| | 766 | m_menuPopup->SetReturnEvent(this, "exit"); |
| | 767 | |
| | 768 | m_menuPopup->AddButton(tr("Save then Exit")); |
| | 769 | m_menuPopup->AddButton(tr("Exit without saving changes")); |
| | 770 | m_menuPopup->AddButton(tr("Cancel")); |
| | 771 | } |
| | 772 | else |
| | 773 | MythScreenType::Close(); |
| | 774 | } |
| | 775 | |
| | 776 | |
| | 777 | bool StandardSettingDialog::keyPressEvent(QKeyEvent *e) |
| | 778 | { |
| | 779 | QStringList actions; |
| | 780 | bool handled = m_buttonList->keyPressEvent(e); |
| | 781 | if (handled) return true; |
| | 782 | handled = GetMythMainWindow()->TranslateKeyPress("Global", e, actions); |
| | 783 | |
| | 784 | //send the key to the selected Item first |
| | 785 | MythUIButtonListItem * item = m_buttonList->GetItemCurrent(); |
| | 786 | if (item) |
| | 787 | { |
| | 788 | StandardSetting * ss = item->GetData().value<StandardSetting*>(); |
| | 789 | if (ss) |
| | 790 | { |
| | 791 | handled = ss->keyPressEvent(e); |
| | 792 | } |
| | 793 | } |
| | 794 | if (handled) return true; |
| | 795 | |
| | 796 | for (int i = 0; i < actions.size() && !handled; i++) |
| | 797 | { |
| | 798 | QString action = actions[i]; |
| | 799 | handled = true; |
| | 800 | |
| | 801 | if (action == "LEFT") |
| | 802 | { |
| | 803 | if (m_currentGroupSetting |
| | 804 | && m_currentGroupSetting==m_settingsTree) |
| | 805 | Close(); |
| | 806 | else |
| | 807 | LevelUp(); |
| | 808 | } |
| | 809 | else if (action == "RIGHT") |
| | 810 | LevelDown(); |
| | 811 | else |
| | 812 | handled = MythScreenType::keyPressEvent(e); |
| | 813 | } |
| | 814 | |
| | 815 | return handled; |
| | 816 | } |
| | 817 | |
| | 818 | |
| | 819 | |
| | 820 | |
| | 821 | |