File indexing completed on 2024-04-28 04:54:34

0001 /*
0002     SPDX-FileCopyrightText: 2002 Rik Hemsley (rikkus) <rik@kde.org>
0003     SPDX-FileCopyrightText: 2002 Benjamin Meyer <ben-devel@meyerhome.net>
0004     SPDX-FileCopyrightText: 2004 Richard Lärkäng <nouseforaname@home.se>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #include "cddbconfigwidget.h"
0010 #include "kcmcddbi18n.h"
0011 
0012 #include "config-musicbrainz.h"
0013 
0014 #include "libkcddb/sites.h"
0015 #include "libkcddb/lookup.h"
0016 
0017 #include <KUrlRequester>
0018 #include <KMessageBox>
0019 #include <KEditListWidget>
0020 
0021 #include <QList>
0022 #include <QCheckBox>
0023 #include <QInputDialog>
0024 
0025 CDDBConfigWidget::CDDBConfigWidget(QWidget * parent)
0026   : QWidget(parent)
0027 {
0028   setupUi(this);
0029 
0030 #ifndef HAVE_MUSICBRAINZ5
0031   kcfg_MusicBrainzLookupEnabled->hide();
0032 #endif
0033 
0034   // Connections from widgets are made in designer.
0035 
0036   KUrlRequester* urlReq = new KUrlRequester(this);
0037   urlReq->setMode(KFile::Directory);
0038 
0039   QGroupBox* groupBox = new QGroupBox(cacheLocationsParent);
0040   groupBox->setTitle(i18n("Cache Locations"));
0041   QVBoxLayout* gbLayout = new QVBoxLayout(groupBox);
0042   gbLayout->setContentsMargins(0, 0, 0, 0);
0043 
0044   KEditListWidget* editListWidget = new KEditListWidget(groupBox);
0045   editListWidget->setCustomEditor(urlReq->customEditor());
0046   editListWidget->setObjectName(QString::fromLatin1("kcfg_cacheLocations"));
0047   gbLayout->addWidget(editListWidget);
0048 
0049   QHBoxLayout *layout = new QHBoxLayout(cacheLocationsParent);
0050   layout->setContentsMargins(0, 0, 0, 0);
0051   layout->addWidget(groupBox);
0052 
0053   connect(kcfg_FreedbLookupTransport,QOverload<int>::of(&QComboBox::activated),this, &CDDBConfigWidget::protocolChanged);
0054   connect(kcfg_FreedbLookupEnabled,&QAbstractButton::toggled,freedbServerBox,&QWidget::setEnabled);
0055   connect(mirrorListButton,&QAbstractButton::clicked,this, &CDDBConfigWidget::showMirrorList);
0056 }
0057 
0058 void CDDBConfigWidget::showMirrorList()
0059 {
0060     KCDDB::Sites s;
0061 
0062     const QList<KCDDB::Mirror> sites = s.siteList();
0063     QMap<QString, KCDDB::Mirror> keys;
0064     for (QList<KCDDB::Mirror>::ConstIterator it = sites.begin(); it != sites.end(); ++it)
0065       if ((*it).transport == KCDDB::Lookup::CDDBP)
0066         keys[(*it).address + QLatin1String( "(CDDBP, " ) + QString::number((*it).port) + QLatin1String( ") " ) + (*it).description] = *it;
0067       else
0068         keys[(*it).address + QLatin1String( "(HTTP, " ) + QString::number((*it).port) + QLatin1String( ") " ) + (*it).description] = *it;
0069 
0070     bool ok;
0071 
0072     if (keys.isEmpty())
0073     {
0074       KMessageBox::information(this, i18n("Could not fetch mirror list."), i18n("Could Not Fetch"));
0075       return;
0076     }
0077 
0078     QString result = QInputDialog::getItem(this, i18n("Select mirror"),
0079       i18n("Select one of these mirrors"), keys.keys(),
0080       0, false, &ok);
0081 
0082     if (ok)
0083     {
0084       KCDDB::Mirror m = keys[result];
0085 
0086       kcfg_FreedbLookupTransport->setCurrentIndex(m.transport == KCDDB::Lookup::CDDBP ? 0 : 1);
0087       kcfg_hostname->setText(m.address);
0088       kcfg_port->setValue(m.port);
0089     }
0090 }
0091 
0092 void CDDBConfigWidget::protocolChanged()
0093 {
0094     // Change the port if the port is the default-value for the old protocol
0095 
0096     if (kcfg_FreedbLookupTransport->currentText() == i18n("HTTP") && kcfg_port->value() == 8880)
0097       kcfg_port->setValue(80);
0098     else if (kcfg_FreedbLookupTransport->currentText() == i18n("CDDB") && kcfg_port->value() == 80)
0099       kcfg_port->setValue(8880);
0100 }
0101 
0102 #include "moc_cddbconfigwidget.cpp"
0103 
0104 // vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1