00001
00002 #include <algorithm>
00003 using namespace std;
00004
00005
00006 #include <unistd.h>
00007
00008
00009 #include <qlineedit.h>
00010 #include <qhbox.h>
00011 #include <qvbox.h>
00012 #include <qlabel.h>
00013 #include <qslider.h>
00014 #include <qlcdnumber.h>
00015 #include <qbuttongroup.h>
00016 #include <qradiobutton.h>
00017
00018
00019 #include <qfile.h>
00020 #include <qdatetime.h>
00021 #include <qdir.h>
00022
00023
00024 #define MYTHCONFIG
00025 #include "settings.h"
00026 #include "mythconfiggroups.h"
00027 #undef MYTHCONFIG
00028
00029 #include "mythwidgets.h"
00030 #include "mythcontext.h"
00031 #include "DisplayRes.h"
00032
00043 QWidget* Configurable::configWidget(ConfigurationGroup *cg, QWidget* parent,
00044 const char* widgetName)
00045 {
00046 (void)cg;
00047 (void)parent;
00048 (void)widgetName;
00049 VERBOSE(VB_IMPORTANT, "BUG: Configurable is visible, but has no "
00050 "configWidget");
00051 return NULL;
00052 }
00053
00064 void Configurable::widgetDeleted(QObject *obj)
00065 {
00066 widgetInvalid(obj);
00067 }
00068
00074 void Configurable::enableOnSet(const QString &val)
00075 {
00076 setEnabled( val != "0" );
00077 }
00078
00084 void Configurable::enableOnUnset(const QString &val)
00085 {
00086 setEnabled( val == "0" );
00087 }
00088
00089 QString Setting::getValue(void) const
00090 {
00091 return QDeepCopy<QString>(settingValue);
00092 }
00093
00094 void Setting::setValue(const QString &newValue)
00095 {
00096 settingValue = QDeepCopy<QString>(newValue);
00097 SetChanged(true);
00098 emit valueChanged(QDeepCopy<QString>(settingValue));
00099 }
00100
00101 int SelectSetting::findSelection(const QString &label, QString value) const
00102 {
00103 value = (value.isEmpty()) ? label : value;
00104
00105 for (uint i = 0; i < values.size(); i++)
00106 {
00107 if ((values[i] == value) && (labels[i] == label))
00108 return i;
00109 }
00110
00111 return -1;
00112 }
00113
00114 void SelectSetting::addSelection(const QString &label, QString value,
00115 bool select)
00116 {
00117 value = (value.isEmpty()) ? label : value;
00118
00119 int found = findSelection(label, value);
00120 if (found < 0)
00121 {
00122 labels.push_back(QDeepCopy<QString>(label));
00123 values.push_back(QDeepCopy<QString>(value));
00124 emit selectionAdded(QDeepCopy<QString>(label),
00125 QDeepCopy<QString>(value));
00126 }
00127
00128 if (select || !isSet)
00129 setValue(value);
00130 }
00131
00132 bool SelectSetting::removeSelection(const QString &label, QString value)
00133 {
00134 value = (value.isEmpty()) ? label : value;
00135
00136 int found = findSelection(label, value);
00137 if (found < 0)
00138 return false;
00139
00140 bool wasSet = isSet;
00141 isSet = false;
00142
00143 labels.erase(labels.begin() + found);
00144 values.erase(values.begin() + found);
00145
00146 isSet = wasSet && labels.size();
00147 if (isSet)
00148 {
00149 current = (current > (uint)found) ? current - 1 : current;
00150 current = min(current, (uint) (labels.size() - 1));
00151 }
00152
00153 emit selectionRemoved(label, QDeepCopy<QString>(value));
00154
00155 return true;
00156 }
00157
00158 void SelectSetting::fillSelectionsFromDir(const QDir& dir, bool absPath) {
00159 const QFileInfoList *il = dir.entryInfoList();
00160 if (!il)
00161 return;
00162
00163 QFileInfoListIterator it( *il );
00164 QFileInfo *fi;
00165
00166 for(; (fi = it.current()) != 0; ++it)
00167 if (absPath)
00168 addSelection(fi->absFilePath());
00169 else
00170 addSelection(fi->fileName());
00171 }
00172
00173 void SelectSetting::clearSelections(void) {
00174 labels.clear();
00175 values.clear();
00176 isSet = false;
00177 emit selectionsCleared();
00178 }
00179
00180 void SelectSetting::setValue(const QString &newValue)
00181 {
00182 int found = getValueIndex(newValue);
00183 if (found < 0)
00184 {
00185 addSelection(QDeepCopy<QString>(newValue),
00186 QDeepCopy<QString>(newValue), true);
00187 }
00188 else
00189 {
00190 current = found;
00191 isSet = true;
00192 Setting::setValue(newValue);
00193 }
00194 }
00195
00196 void SelectSetting::setValue(int which)
00197 {
00198 if ((which >= ((int) values.size())) || (which < 0))
00199 {
00200 VERBOSE(VB_IMPORTANT, "SelectSetting::setValue(): "
00201 "invalid index: " << which << " size: "<<values.size());
00202 }
00203 else
00204 {
00205 current = which;
00206 isSet = true;
00207 Setting::setValue(values[current]);
00208 }
00209 }
00210
00211 QString SelectSetting::getSelectionLabel(void) const
00212 {
00213 if (!isSet || (current >= values.size()))
00214 return QString::null;
00215
00216 return QDeepCopy<QString>(labels[current]);
00217 }
00218
00222 int SelectSetting::getValueIndex(QString value)
00223 {
00224 int ret = 0;
00225
00226 selectionList::const_iterator it = values.begin();
00227 for (; it != values.end(); ++it, ++ret)
00228 {
00229 if (*it == value)
00230 return ret;
00231 }
00232
00233 return -1;
00234 }
00235
00236 QWidget* LabelSetting::configWidget(ConfigurationGroup *cg, QWidget* parent,
00237 const char* widgetName) {
00238 (void)cg;
00239
00240 QWidget* widget = new QHBox(parent, widgetName);
00241 widget->setBackgroundOrigin(QWidget::WindowOrigin);
00242
00243 if (getLabel() != "")
00244 {
00245 QLabel* label = new QLabel(widget);
00246 label->setText(getLabel() + ": ");
00247 label->setBackgroundOrigin(QWidget::WindowOrigin);
00248 }
00249
00250 QLabel* value = new QLabel(widget);
00251 value->setText(getValue());
00252 value->setBackgroundOrigin(QWidget::WindowOrigin);
00253
00254 connect(this, SIGNAL(valueChanged(const QString&)),
00255 value, SLOT(setText(const QString&)));
00256
00257 return widget;
00258 }
00259
00260 QWidget* LineEditSetting::configWidget(ConfigurationGroup *cg, QWidget* parent,
00261 const char *widgetName) {
00262 QHBox *widget;
00263
00264 if (labelAboveWidget)
00265 {
00266 widget = dynamic_cast<QHBox*>(new QVBox(parent, widgetName));
00267 widget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,
00268 QSizePolicy::Maximum));
00269 }
00270 else
00271 widget = new QHBox(parent, widgetName);
00272 widget->setBackgroundOrigin(QWidget::WindowOrigin);
00273
00274 if (getLabel() != "")
00275 {
00276 QLabel* label = new QLabel(widget);
00277 label->setText(getLabel() + ": ");
00278 label->setBackgroundOrigin(QWidget::WindowOrigin);
00279 }
00280
00281 bxwidget = widget;
00282 connect(bxwidget, SIGNAL(destroyed(QObject*)),
00283 this, SLOT(widgetDeleted(QObject*)));
00284
00285 edit = new MythLineEdit(settingValue, widget,
00286 QString(widgetName) + "-edit");
00287 edit->setHelpText(getHelpText());
00288 edit->setBackgroundOrigin(QWidget::WindowOrigin);
00289 edit->setText( getValue() );
00290
00291 connect(this, SIGNAL(valueChanged(const QString&)),
00292 edit, SLOT(setText(const QString&)));
00293 connect(edit, SIGNAL(textChanged(const QString&)),
00294 this, SLOT(setValue(const QString&)));
00295
00296 if (cg)
00297 connect(edit, SIGNAL(changeHelpText(QString)), cg,
00298 SIGNAL(changeHelpText(QString)));
00299
00300 setRW(rw);
00301 SetPasswordEcho(password_echo);
00302
00303 return bxwidget;
00304 }
00305
00306 void LineEditSetting::widgetInvalid(QObject *obj)
00307 {
00308 if (bxwidget == obj)
00309 {
00310 bxwidget = NULL;
00311 edit = NULL;
00312 }
00313 }
00314
00315 void LineEditSetting::setEnabled(bool b)
00316 {
00317 Configurable::setEnabled(b);
00318 if (edit)
00319 edit->setEnabled(b);
00320 }
00321
00322 void LineEditSetting::setVisible(bool b)
00323 {
00324 Configurable::setVisible(b);
00325 if (edit)
00326 {
00327
00328 if (b)
00329 edit->show();
00330 else
00331 edit->hide();
00332 }
00333 }
00334
00335 void LineEditSetting::SetPasswordEcho(bool b)
00336 {
00337 password_echo = b;
00338 if (edit)
00339 edit->setEchoMode(b ? QLineEdit::Password : QLineEdit::Normal);
00340 }
00341
00342 void LineEditSetting::setHelpText(const QString &str)
00343 {
00344 if (edit)
00345 edit->setHelpText(str);
00346 Setting::setHelpText(str);
00347 }
00348
00349 void BoundedIntegerSetting::setValue(int newValue)
00350 {
00351 newValue = std::max(std::min(newValue, max), min);
00352 IntegerSetting::setValue(newValue);
00353 }
00354
00355 QWidget* SliderSetting::configWidget(ConfigurationGroup *cg, QWidget* parent,
00356 const char* widgetName) {
00357 QHBox* widget;
00358 if (labelAboveWidget)
00359 {
00360 widget = dynamic_cast<QHBox*>(new QVBox(parent, widgetName));
00361 widget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,
00362 QSizePolicy::Maximum));
00363 }
00364 else
00365 widget = new QHBox(parent, widgetName);
00366
00367 widget->setBackgroundOrigin(QWidget::WindowOrigin);
00368
00369 if (getLabel() != "")
00370 {
00371 QLabel* label = new QLabel(widget, QString(widgetName) + "-label");
00372 label->setText(getLabel() + ": ");
00373 label->setBackgroundOrigin(QWidget::WindowOrigin);
00374 }
00375
00376 MythSlider* slider = new MythSlider(widget,
00377 QString(widgetName) + "-slider");
00378 slider->setHelpText(getHelpText());
00379 slider->setMinValue(min);
00380 slider->setMaxValue(max);
00381 slider->setOrientation(QSlider::Horizontal);
00382 slider->setLineStep(step);
00383 slider->setValue(intValue());
00384 slider->setBackgroundOrigin(QWidget::WindowOrigin);
00385
00386 QLCDNumber* lcd = new QLCDNumber(widget, QString(widgetName) + "-lcd");
00387 lcd->setMode(QLCDNumber::DEC);
00388 lcd->setSegmentStyle(QLCDNumber::Flat);
00389 lcd->display(intValue());
00390
00391 connect(slider, SIGNAL(valueChanged(int)), lcd, SLOT(display(int)));
00392 connect(slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
00393 connect(this, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
00394
00395 if (cg)
00396 connect(slider, SIGNAL(changeHelpText(QString)), cg,
00397 SIGNAL(changeHelpText(QString)));
00398
00399 return widget;
00400 }
00401
00402 SpinBoxSetting::SpinBoxSetting(
00403 Storage *_storage, int _min, int _max, int _step,
00404 bool _allow_single_step, QString _special_value_text) :
00405 BoundedIntegerSetting(_storage, _min, _max, _step),
00406 spinbox(NULL), relayEnabled(true),
00407 sstep(_allow_single_step), svtext("")
00408 {
00409 if (!_special_value_text.isEmpty())
00410 svtext = QDeepCopy<QString>(_special_value_text);
00411
00412 IntegerSetting *iset = (IntegerSetting *) this;
00413 connect(iset, SIGNAL(valueChanged( int)),
00414 this, SLOT( relayValueChanged(int)));
00415 }
00416
00417 QWidget* SpinBoxSetting::configWidget(ConfigurationGroup *cg, QWidget* parent,
00418 const char* widgetName) {
00419 QHBox* box;
00420 if (labelAboveWidget)
00421 {
00422 box = dynamic_cast<QHBox*>(new QVBox(parent, widgetName));
00423 box->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,
00424 QSizePolicy::Maximum));
00425 }
00426 else
00427 box = new QHBox(parent, widgetName);
00428 box->setBackgroundOrigin(QWidget::WindowOrigin);
00429
00430 if (getLabel() != "")
00431 {
00432 QLabel* label = new QLabel(box);
00433 label->setBackgroundOrigin(QWidget::WindowOrigin);
00434 label->setText(getLabel() + ": ");
00435 }
00436
00437 bxwidget = box;
00438 connect(bxwidget, SIGNAL(destroyed(QObject*)),
00439 this, SLOT(widgetDeleted(QObject*)));
00440
00441 spinbox = new MythSpinBox(box, QString(widgetName) + "MythSpinBox", sstep);
00442 spinbox->setHelpText(getHelpText());
00443 spinbox->setBackgroundOrigin(QWidget::WindowOrigin);
00444 spinbox->setMinValue(min);
00445 spinbox->setMaxValue(max);
00446
00447
00448 if (1 < step)
00449 spinbox->setLineStep(step);
00450 spinbox->setValue(intValue());
00451 if (!svtext.isEmpty())
00452 spinbox->setSpecialValueText(svtext);
00453
00454 connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
00455
00456 if (cg)
00457 connect(spinbox, SIGNAL(changeHelpText(QString)), cg,
00458 SIGNAL(changeHelpText(QString)));
00459
00460 return bxwidget;
00461 }
00462
00463 void SpinBoxSetting::widgetInvalid(QObject *obj)
00464 {
00465 if (bxwidget == obj)
00466 {
00467 bxwidget = NULL;
00468 spinbox = NULL;
00469 }
00470 }
00471
00472 void SpinBoxSetting::setValue(int newValue)
00473 {
00474 newValue = std::max(std::min(newValue, max), min);
00475 if (spinbox && (spinbox->value() != newValue))
00476 {
00477
00478 spinbox->setValue(newValue);
00479 }
00480 else if (intValue() != newValue)
00481 {
00482 BoundedIntegerSetting::setValue(newValue);
00483 }
00484 }
00485
00486 void SpinBoxSetting::setFocus(void)
00487 {
00488 if (spinbox)
00489 spinbox->setFocus();
00490 }
00491
00492 void SpinBoxSetting::clearFocus(void)
00493 {
00494 if (spinbox)
00495 spinbox->clearFocus();
00496 }
00497
00498 bool SpinBoxSetting::hasFocus(void) const
00499 {
00500 if (spinbox)
00501 return spinbox->hasFocus();
00502
00503 return false;
00504 }
00505
00506 void SpinBoxSetting::relayValueChanged(int newValue)
00507 {
00508 if (relayEnabled)
00509 emit valueChanged(configName, newValue);
00510 }
00511
00512 void SpinBoxSetting::setHelpText(const QString &str)
00513 {
00514 if (spinbox)
00515 spinbox->setHelpText(str);
00516 BoundedIntegerSetting::setHelpText(str);
00517 }
00518
00519 QWidget* SelectLabelSetting::configWidget(ConfigurationGroup *cg,
00520 QWidget* parent,
00521 const char* widgetName) {
00522 (void)cg;
00523
00524 QHBox* widget;
00525 if (labelAboveWidget)
00526 {
00527 widget = dynamic_cast<QHBox*>(new QVBox(parent, widgetName));
00528 widget->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,
00529 QSizePolicy::Maximum));
00530 }
00531 else
00532 widget = new QHBox(parent, widgetName);
00533
00534 widget->setBackgroundOrigin(QWidget::WindowOrigin);
00535
00536 if (getLabel() != "")
00537 {
00538 QLabel* label = new QLabel(widget);
00539 label->setText(getLabel() + ": ");
00540 label->setBackgroundOrigin(QWidget::WindowOrigin);
00541 }
00542
00543 QLabel* value = new QLabel(widget);
00544 value->setText(labels[current]);
00545 value->setBackgroundOrigin(QWidget::WindowOrigin);
00546
00547 connect(this, SIGNAL(valueChanged(const QString&)),
00548 value, SLOT(setText(const QString&)));
00549
00550 return widget;
00551 }
00552
00553 QWidget* ComboBoxSetting::configWidget(ConfigurationGroup *cg, QWidget* parent,
00554 const char* widgetName) {
00555 QHBox* box;
00556 if (labelAboveWidget)
00557 {
00558 box = dynamic_cast<QHBox*>(new QVBox(parent, widgetName));
00559 box->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,
00560 QSizePolicy::Maximum));
00561 }
00562 else
00563 box = new QHBox(parent, widgetName);
00564
00565 box->setBackgroundOrigin(QWidget::WindowOrigin);
00566
00567 if (getLabel() != "")
00568 {
00569 QLabel* label = new QLabel(box);
00570 label->setText(getLabel() + ": ");
00571 label->setBackgroundOrigin(QWidget::WindowOrigin);
00572 box->setStretchFactor(label, 0);
00573 }
00574
00575 bxwidget = box;
00576 connect(bxwidget, SIGNAL(destroyed(QObject*)),
00577 this, SLOT(widgetDeleted(QObject*)));
00578
00579 widget = new MythComboBox(rw, box);
00580 widget->setHelpText(getHelpText());
00581 widget->setBackgroundOrigin(QWidget::WindowOrigin);
00582 box->setStretchFactor(widget, 1);
00583
00584 for(unsigned int i = 0 ; i < labels.size() ; ++i)
00585 widget->insertItem(labels[i]);
00586
00587 if (isSet)
00588 widget->setCurrentItem(current);
00589
00590 if (1 < step)
00591 widget->setStep(step);
00592
00593 if (rw)
00594 connect(widget, SIGNAL(highlighted(const QString &)),
00595 this, SLOT(setValue(const QString &)));
00596 else
00597 connect(widget, SIGNAL(highlighted(int)),
00598 this, SLOT(setValue(int)));
00599
00600 connect(this, SIGNAL(selectionsCleared()),
00601 widget, SLOT(clear()));
00602
00603 if (cg)
00604 connect(widget, SIGNAL(changeHelpText(QString)), cg,
00605 SIGNAL(changeHelpText(QString)));
00606
00607 return bxwidget;
00608 }
00609
00610 void ComboBoxSetting::widgetInvalid(QObject *obj)
00611 {
00612 if (bxwidget == obj)
00613 {
00614 bxwidget = NULL;
00615 widget = NULL;
00616 }
00617 }
00618
00619 void ComboBoxSetting::setEnabled(bool b)
00620 {
00621 Configurable::setEnabled(b);
00622 if (widget)
00623 widget->setEnabled(b);
00624 }
00625
00626 void ComboBoxSetting::setVisible(bool b)
00627 {
00628 Configurable::setVisible(b);
00629 if (widget)
00630 {
00631
00632 if (b)
00633 widget->show();
00634 else
00635 widget->hide();
00636 }
00637 }
00638
00639 void ComboBoxSetting::setValue(QString newValue)
00640 {
00641 for (uint i = 0; i < values.size(); i++)
00642 {
00643 if (values[i] == newValue)
00644 {
00645 setValue(i);
00646 break;
00647 }
00648 }
00649
00650 if (rw)
00651 {
00652 Setting::setValue(newValue);
00653 if (widget)
00654 widget->setCurrentItem(current);
00655 }
00656 };
00657
00658 void ComboBoxSetting::setValue(int which)
00659 {
00660 if (widget)
00661 widget->setCurrentItem(which);
00662 SelectSetting::setValue(which);
00663 };
00664
00665 void ComboBoxSetting::addSelection(
00666 const QString &label, QString value, bool select)
00667 {
00668 if ((findSelection(label, value) < 0) && widget)
00669 {
00670 widget->insertItem(QDeepCopy<QString>(label));
00671 }
00672
00673 SelectSetting::addSelection(label, value, select);
00674
00675 if (widget && isSet)
00676 widget->setCurrentItem(current);
00677 }
00678
00679 bool ComboBoxSetting::removeSelection(const QString &label, QString value)
00680 {
00681 SelectSetting::removeSelection(label, value);
00682 if (!widget)
00683 return true;
00684
00685 for (uint i = 0; ((int) i) < widget->count(); i++)
00686 {
00687 if (widget->text(i) == label)
00688 {
00689 widget->removeItem(i);
00690 if (isSet)
00691 widget->setCurrentItem(current);
00692 return true;
00693 }
00694 }
00695
00696 return false;
00697 }
00698
00699 void ComboBoxSetting::setHelpText(const QString &str)
00700 {
00701 if (widget)
00702 widget->setHelpText(str);
00703 SelectSetting::setHelpText(str);
00704 }
00705
00706 void HostRefreshRateComboBox::ChangeResolution(const QString& resolution)
00707 {
00708 clearSelections();
00709
00710 const vector<short> list = GetRefreshRates(resolution);
00711 addSelection(QObject::tr("Any"), "0");
00712 int hz50 = -1, hz60 = -1;
00713 for (uint i=0; i<list.size(); ++i)
00714 {
00715 QString sel = QString::number(list[i]);
00716 addSelection(sel+" Hz", sel);
00717 hz50 = (50 == list[i]) ? i : hz50;
00718 hz60 = (60 == list[i]) ? i : hz60;
00719 }
00720
00721 setValue(0);
00722 if ("640x480" == resolution || "720x480" == resolution)
00723 setValue(hz60+1);
00724 if ("640x576" == resolution || "720x576" == resolution)
00725 setValue(hz50+1);
00726
00727 setEnabled(list.size());
00728 }
00729
00730 const vector<short> HostRefreshRateComboBox::GetRefreshRates(const QString &res)
00731 {
00732 QStringList slist = QStringList::split("x", res);
00733 int w = 0, h = 0;
00734 bool ok0 = false, ok1 = false;
00735 if (2 == slist.size())
00736 {
00737 w = slist[0].toInt(&ok0);
00738 h = slist[1].toInt(&ok1);
00739 }
00740
00741 DisplayRes *display_res = DisplayRes::GetDisplayRes();
00742 if (display_res && ok0 && ok1)
00743 return display_res->GetRefreshRates(w, h);
00744
00745 vector<short> list;
00746 return list;
00747 }
00748
00749 void PathSetting::addSelection(const QString& label,
00750 QString value,
00751 bool select) {
00752 QString pathname = label;
00753 if (value != QString::null)
00754 pathname = value;
00755
00756 if (mustexist && !QFile(pathname).exists())
00757 return;
00758
00759 ComboBoxSetting::addSelection(label, value, select);
00760 }
00761
00762 QTime TimeSetting::timeValue(void) const {
00763 return QTime::fromString(getValue(), Qt::ISODate);
00764 }
00765
00766 void TimeSetting::setValue(const QTime& newValue) {
00767 Setting::setValue(newValue.toString(Qt::ISODate));
00768 }
00769
00770 QDate DateSetting::dateValue(void) const {
00771 return QDate::fromString(getValue(), Qt::ISODate);
00772 }
00773
00774 void DateSetting::setValue(const QDate& newValue) {
00775 Setting::setValue(newValue.toString(Qt::ISODate));
00776 }
00777
00778 QWidget* RadioSetting::configWidget(ConfigurationGroup *cg, QWidget* parent,
00779 const char* widgetName) {
00780 QButtonGroup* widget = new QButtonGroup(parent, widgetName);
00781 widget->setBackgroundOrigin(QWidget::WindowOrigin);
00782 widget->setTitle(getLabel());
00783
00784 for( unsigned i = 0 ; i < labels.size() ; ++i ) {
00785 QRadioButton* button = new QRadioButton(widget, NULL);
00786 button->setBackgroundOrigin(QWidget::WindowOrigin);
00787 button->setText(labels[i]);
00788 if (isSet && i == current)
00789 button->setDown(true);
00790 }
00791
00792 cg = cg;
00793
00794 return widget;
00795 }
00796
00797 QWidget* CheckBoxSetting::configWidget(ConfigurationGroup *cg, QWidget* parent,
00798 const char* widgetName) {
00799 widget = new MythCheckBox(parent, widgetName);
00800 connect(widget, SIGNAL(destroyed(QObject*)),
00801 this, SLOT(widgetDeleted(QObject*)));
00802
00803 widget->setHelpText(getHelpText());
00804 widget->setBackgroundOrigin(QWidget::WindowOrigin);
00805 widget->setText(getLabel());
00806 widget->setChecked(boolValue());
00807
00808 connect(widget, SIGNAL(toggled(bool)),
00809 this, SLOT(setValue(bool)));
00810 connect(this, SIGNAL(valueChanged(bool)),
00811 widget, SLOT(setChecked(bool)));
00812
00813 if (cg)
00814 connect(widget, SIGNAL(changeHelpText(QString)), cg,
00815 SIGNAL(changeHelpText(QString)));
00816
00817 return widget;
00818 }
00819
00820 void CheckBoxSetting::widgetInvalid(QObject *obj)
00821 {
00822 widget = (widget == obj) ? NULL : widget;
00823 }
00824
00825 void CheckBoxSetting::setEnabled(bool fEnabled)
00826 {
00827 BooleanSetting::setEnabled(fEnabled);
00828 if (widget)
00829 widget->setEnabled(fEnabled);
00830 }
00831
00832 void CheckBoxSetting::setHelpText(const QString &str)
00833 {
00834 if (widget)
00835 widget->setHelpText(str);
00836 BooleanSetting::setHelpText(str);
00837 }
00838
00839 void AutoIncrementDBSetting::save(QString table)
00840 {
00841 if (intValue() == 0)
00842 {
00843
00844 QString querystr = QString("INSERT INTO " + table + " ("
00845 + column + ") VALUES (0);");
00846
00847 MSqlQuery query(MSqlQuery::InitCon());
00848 query.exec(querystr);
00849
00850 if (!query.isActive() || query.numRowsAffected() < 1)
00851 {
00852 MythContext::DBError("inserting row", query);
00853 return;
00854 }
00855 setValue(query.lastInsertId().toInt());
00856 }
00857 }
00858
00859 void AutoIncrementDBSetting::save()
00860 {
00861 save(table);
00862 }
00863
00864 void ListBoxSetting::setEnabled(bool b)
00865 {
00866 Configurable::setEnabled(b);
00867 if (widget)
00868 widget->setEnabled(b);
00869 }
00870
00871 void ListBoxSetting::clearSelections(void)
00872 {
00873 SelectSetting::clearSelections();
00874 if (widget)
00875 widget->clear();
00876 }
00877
00878 void ListBoxSetting::addSelection(
00879 const QString &label, QString value, bool select)
00880 {
00881 SelectSetting::addSelection(label, value, select);
00882 if (widget)
00883 {
00884 widget->insertItem(label);
00885
00886 }
00887 };
00888
00889 QWidget* ListBoxSetting::configWidget(ConfigurationGroup *cg, QWidget* parent,
00890 const char* widgetName)
00891 {
00892 QWidget* box = new QVBox(parent, widgetName);
00893 box->setBackgroundOrigin(QWidget::WindowOrigin);
00894
00895 if (getLabel() != "")
00896 {
00897 QLabel* label = new QLabel(box);
00898 label->setText(getLabel());
00899 label->setBackgroundOrigin(QWidget::WindowOrigin);
00900 }
00901
00902 bxwidget = box;
00903 connect(bxwidget, SIGNAL(destroyed(QObject*)),
00904 this, SLOT(widgetDeleted(QObject*)));
00905
00906 widget = new MythListBox(box);
00907 widget->setBackgroundOrigin(QWidget::WindowOrigin);
00908 widget->setHelpText(getHelpText());
00909
00910 for(unsigned int i = 0 ; i < labels.size() ; ++i) {
00911 widget->insertItem(labels[i]);
00912 if (isSet && current == i)
00913 widget->setCurrentItem(i);
00914 }
00915
00916 connect(this, SIGNAL(selectionsCleared()),
00917 widget, SLOT(clear()));
00918 connect(widget, SIGNAL(accepted(int)),
00919 this, SIGNAL(accepted(int)));
00920 connect(widget, SIGNAL(menuButtonPressed(int)),
00921 this, SIGNAL(menuButtonPressed(int)));
00922 connect(widget, SIGNAL(editButtonPressed(int)),
00923 this, SIGNAL(editButtonPressed(int)));
00924 connect(widget, SIGNAL(deleteButtonPressed(int)),
00925 this, SIGNAL(deleteButtonPressed(int)));
00926 connect(this, SIGNAL(valueChanged(const QString&)),
00927 widget, SLOT(setCurrentItem(const QString&)));
00928 connect(widget, SIGNAL(highlighted(int)),
00929 this, SLOT(setValueByIndex(int)));
00930
00931 if (cg)
00932 connect(widget, SIGNAL(changeHelpText(QString)), cg,
00933 SIGNAL(changeHelpText(QString)));
00934
00935 widget->setFocus();
00936 widget->setSelectionMode(selectionMode);
00937
00938 return bxwidget;
00939 }
00940
00941 void ListBoxSetting::widgetInvalid(QObject *obj)
00942 {
00943 if (bxwidget == obj)
00944 {
00945 bxwidget = NULL;
00946 widget = NULL;
00947 }
00948 }
00949
00950 void ListBoxSetting::setSelectionMode(MythListBox::SelectionMode mode)
00951 {
00952 selectionMode = mode;
00953 if (widget)
00954 widget->setSelectionMode(selectionMode);
00955 }
00956
00957 void ListBoxSetting::setValueByIndex(int index)
00958 {
00959 if (((uint)index) < values.size())
00960 setValue(values[index]);
00961 }
00962
00963 void ListBoxSetting::setHelpText(const QString &str)
00964 {
00965 if (widget)
00966 widget->setHelpText(str);
00967 SelectSetting::setHelpText(str);
00968 }
00969
00970 void ImageSelectSetting::addImageSelection(const QString& label,
00971 QImage* image,
00972 QString value,
00973 bool select) {
00974 images.push_back(image);
00975 addSelection(label, value, select);
00976 }
00977
00978 ImageSelectSetting::~ImageSelectSetting()
00979 {
00980 Teardown();
00981 }
00982
00983 void ImageSelectSetting::deleteLater(void)
00984 {
00985 Teardown();
00986 SelectSetting::deleteLater();
00987 }
00988
00989 void ImageSelectSetting::Teardown(void)
00990 {
00991 while (images.size())
00992 {
00993 QImage *tmp = images.back();
00994 images.pop_back();
00995 delete tmp;
00996 }
00997 bxwidget = NULL;
00998 imagelabel = NULL;
00999 combo = NULL;
01000 }
01001
01002 void ImageSelectSetting::imageSet(int num)
01003 {
01004 if (num >= (int)images.size())
01005 return;
01006
01007 if (!images[current])
01008 return;
01009
01010 QImage temp = *(images[current]);
01011 temp = temp.smoothScale((int)(184 * m_hmult), (int)(138 * m_hmult),
01012 QImage::ScaleMin);
01013
01014 QPixmap tmppix(temp);
01015 imagelabel->setPixmap(tmppix);
01016 }
01017
01018 QWidget* ImageSelectSetting::configWidget(ConfigurationGroup *cg,
01019 QWidget* parent,
01020 const char* widgetName)
01021 {
01022 int width = 0, height = 0;
01023
01024 gContext->GetScreenSettings(width, m_wmult, height, m_hmult);
01025
01026 QHBox* box;
01027 if (labelAboveWidget)
01028 {
01029 box = dynamic_cast<QHBox*>(new QVBox(parent, widgetName));
01030 box->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,
01031 QSizePolicy::Maximum));
01032 }
01033 else
01034 box = new QHBox(parent, widgetName);
01035
01036 box->setBackgroundOrigin(QWidget::WindowOrigin);
01037
01038 if (getLabel() != "")
01039 {
01040 QLabel* label = new QLabel(box);
01041 label->setText(getLabel() + ":");
01042 label->setBackgroundOrigin(QWidget::WindowOrigin);
01043 }
01044
01045 MythComboBox *widget = new MythComboBox(false, box);
01046 widget->setBackgroundOrigin(QWidget::WindowOrigin);
01047 combo = widget;
01048
01049 QLabel *testlabel = new QLabel(box);
01050 testlabel->setText(" ");
01051 testlabel->setBackgroundOrigin(QWidget::WindowOrigin);
01052
01053 bxwidget = box;
01054 connect(bxwidget, SIGNAL(destroyed(QObject*)),
01055 this, SLOT(widgetDeleted(QObject*)));
01056
01057 imagelabel = new QLabel(box);
01058 imagelabel->setBackgroundOrigin(QWidget::WindowOrigin);
01059
01060 for (unsigned int i = 0 ; i < images.size() ; ++i)
01061 widget->insertItem(labels[i]);
01062
01063 if (isSet)
01064 widget->setCurrentItem(current);
01065 else
01066 current = 0;
01067
01068 if (images.size() != 0 && current < images.size() && images[current])
01069 {
01070 QImage temp = *(images[current]);
01071 temp = temp.smoothScale((int)(184 * m_hmult), (int)(138 * m_hmult),
01072 QImage::ScaleMin);
01073
01074 QPixmap tmppix(temp);
01075 imagelabel->setPixmap(tmppix);
01076 }
01077 else
01078 {
01079 QPixmap tmppix((int)(184 * m_hmult), (int)(138 * m_hmult));
01080 tmppix.fill(black);
01081
01082 imagelabel->setPixmap(tmppix);
01083 }
01084
01085 connect(widget, SIGNAL(highlighted(int)), this, SLOT(setValue(int)));
01086 connect(widget, SIGNAL(highlighted(int)), this, SLOT(imageSet(int)));
01087
01088 connect(this, SIGNAL(selectionsCleared()),
01089 widget, SLOT(clear()));
01090
01091 if (cg)
01092 connect(widget, SIGNAL(changeHelpText(QString)), cg,
01093 SIGNAL(changeHelpText(QString)));
01094
01095 return bxwidget;
01096 }
01097
01098 void ImageSelectSetting::widgetInvalid(QObject *obj)
01099 {
01100 if (bxwidget == obj)
01101 {
01102 bxwidget = NULL;
01103 imagelabel = NULL;
01104 combo = NULL;
01105 }
01106 }
01107
01108 void ImageSelectSetting::setHelpText(const QString &str)
01109 {
01110 if (combo)
01111 combo->setHelpText(str);
01112 SelectSetting::setHelpText(str);
01113 }
01114
01115 HostnameSetting::HostnameSetting(Storage *storage) : Setting(storage)
01116 {
01117 setVisible(false);
01118
01119 setValue(gContext->GetHostName());
01120 }
01121
01122 void ChannelSetting::fillSelections(SelectSetting* setting) {
01123
01124
01125
01126
01127
01128 MSqlQuery query(MSqlQuery::InitCon());
01129 query.prepare("SELECT name, chanid FROM channel;");
01130 if (query.exec() && query.isActive() && query.size() > 0)
01131 while (query.next())
01132 setting->addSelection(query.value(0).toString(),
01133 QString::number(query.value(1).toInt()));
01134 }
01135
01136 QWidget* ButtonSetting::configWidget(ConfigurationGroup* cg, QWidget* parent,
01137 const char* widgetName)
01138 {
01139 (void) cg;
01140 button = new MythPushButton(parent, widgetName);
01141 connect(button, SIGNAL(destroyed(QObject*)),
01142 this, SLOT(widgetDeleted(QObject*)));
01143
01144 button->setText(getLabel());
01145 button->setHelpText(getHelpText());
01146
01147 connect(button, SIGNAL(pressed()), this, SIGNAL(pressed()));
01148 connect(button, SIGNAL(pressed()), this, SLOT(SendPressedString()));
01149
01150 if (cg)
01151 connect(button, SIGNAL(changeHelpText(QString)),
01152 cg, SIGNAL(changeHelpText(QString)));
01153
01154 return button;
01155 }
01156
01157 void ButtonSetting::widgetInvalid(QObject *obj)
01158 {
01159 button = (button == obj) ? NULL : button;
01160 }
01161
01162 void ButtonSetting::SendPressedString(void)
01163 {
01164 emit pressed(name);
01165 }
01166
01167 void ButtonSetting::setEnabled(bool fEnabled)
01168 {
01169 Configurable::setEnabled(fEnabled);
01170 if (button)
01171 button->setEnabled(fEnabled);
01172 }
01173
01174 void ButtonSetting::setHelpText(const QString &str)
01175 {
01176 if (button)
01177 button->setHelpText(str);
01178 Setting::setHelpText(str);
01179 }
01180
01181 QWidget* ProgressSetting::configWidget(ConfigurationGroup* cg, QWidget* parent,
01182 const char* widgetName) {
01183 (void)cg;
01184
01185 QHBox* widget = new QHBox(parent,widgetName);
01186 widget->setBackgroundOrigin(QWidget::WindowOrigin);
01187
01188 if (getLabel() != "")
01189 {
01190 QLabel* label = new QLabel(getLabel() + " :", widget, widgetName);
01191 label->setBackgroundOrigin(QWidget::WindowOrigin);
01192 }
01193
01194 QProgressBar* progress = new QProgressBar(totalSteps, widget, widgetName);
01195 progress->setBackgroundOrigin(QWidget::WindowOrigin);
01196
01197 connect(this, SIGNAL(valueChanged(int)), progress, SLOT(setProgress(int)));
01198 progress->setProgress(intValue());
01199 return widget;
01200 }