From 0ffa05b536ad907e63d34a1ab7244ce159354269 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Tue, 17 Feb 2009 11:17:47 +0000 Subject: fixed proxy support, fixed xspf version git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@790 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/lyrics/lyricswindow.cpp | 8 ++++- src/plugins/General/scrobbler/scrobbler.cpp | 20 ++++------- src/plugins/PlaylistFormats/xspf/CMakeLists.txt | 3 +- src/plugins/PlaylistFormats/xspf/xspf.pro | 2 +- .../PlaylistFormats/xspf/xspfplaylistformat.cpp | 6 ++-- src/qmmp/downloader.cpp | 12 +++---- src/qmmp/qmmp.cpp | 39 +++++++++++++++++++++- src/qmmp/qmmp.h | 11 +++++- src/ui/addurldialog.cpp | 19 ++++------- src/ui/configdialog.cpp | 33 +++++++++--------- 10 files changed, 96 insertions(+), 57 deletions(-) diff --git a/src/plugins/General/lyrics/lyricswindow.cpp b/src/plugins/General/lyrics/lyricswindow.cpp index 744ad07f0..dc781bcc4 100644 --- a/src/plugins/General/lyrics/lyricswindow.cpp +++ b/src/plugins/General/lyrics/lyricswindow.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "lyricswindow.h" @@ -30,8 +31,13 @@ LyricsWindow::LyricsWindow(const QString &artist, const QString &title, QWidget setWindowFlags(Qt::Dialog); setAttribute(Qt::WA_DeleteOnClose); setWindowTitle(QString(tr("Lyrics: %1 - %2")).arg(artist).arg(title)); - //TODO proxy support m_http = new QHttp(this); + //load global proxy settings + if (Qmmp::useProxy()) + m_http->setProxy(Qmmp::proxy().host(), + Qmmp::proxy().port(), + Qmmp::useProxyAuth() ? Qmmp::proxy().userName() : QString(), + Qmmp::useProxyAuth() ? Qmmp::proxy().password() : QString()); connect(m_http, SIGNAL(done(bool)), SLOT(showText(bool))); connect(m_http, SIGNAL(stateChanged(int)), SLOT(showState (int))); m_http->setHost("lyricwiki.org"); diff --git a/src/plugins/General/scrobbler/scrobbler.cpp b/src/plugins/General/scrobbler/scrobbler.cpp index af0ecd40b..8cf79d4c6 100644 --- a/src/plugins/General/scrobbler/scrobbler.cpp +++ b/src/plugins/General/scrobbler/scrobbler.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "scrobbler.h" @@ -47,19 +48,12 @@ Scrobbler::Scrobbler(QObject *parent) m_login = settings.value("login").toString(); m_passw = settings.value("password").toString(); settings.endGroup(); - //use global proxy settings - if (settings.value ("Proxy/use_proxy", FALSE).toBool()) - { - - if (settings.value ("Proxy/authentication", FALSE).toBool()) - m_http->setProxy(settings.value("Proxy/host").toString(), - settings.value("Proxy/port").toInt(), - settings.value("Proxy/user").toString(), - settings.value("Proxy/passw").toString()); - else - m_http->setProxy(settings.value("Proxy/host").toString(), - settings.value("Proxy/port").toInt()); - } + //load global proxy settings + if (Qmmp::useProxy()) + m_http->setProxy(Qmmp::proxy().host(), + Qmmp::proxy().port(), + Qmmp::useProxyAuth() ? Qmmp::proxy().userName() : QString(), + Qmmp::useProxyAuth() ? Qmmp::proxy().password() : QString()); m_disabled = m_login.isEmpty() || m_passw.isEmpty(); m_passw = QString(QCryptographicHash::hash(m_passw.toAscii(), QCryptographicHash::Md5).toHex()); diff --git a/src/plugins/PlaylistFormats/xspf/CMakeLists.txt b/src/plugins/PlaylistFormats/xspf/CMakeLists.txt index f71e09782..a084ba897 100644 --- a/src/plugins/PlaylistFormats/xspf/CMakeLists.txt +++ b/src/plugins/PlaylistFormats/xspf/CMakeLists.txt @@ -29,6 +29,7 @@ SET(QT_INCLUDES # libqmmpui include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../) link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmpui) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmp) SET(libxspfplaylistformat_SRCS xspfplaylistformat.cpp @@ -49,5 +50,5 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) ADD_LIBRARY(xspfplaylistformat SHARED ${libxspfplaylistformat_SRCS} ${libxspfplaylistformat_MOC_SRCS}) add_dependencies(xspfplaylistformat qmmpui) -target_link_libraries(xspfplaylistformat ${QT_LIBRARIES} -lqmmpui) +target_link_libraries(xspfplaylistformat ${QT_LIBRARIES} -lqmmpui -lqmmp) install(TARGETS xspfplaylistformat DESTINATION ${LIB_DIR}/qmmp/PlaylistFormats) diff --git a/src/plugins/PlaylistFormats/xspf/xspf.pro b/src/plugins/PlaylistFormats/xspf/xspf.pro index 1e5716f58..784f15c79 100644 --- a/src/plugins/PlaylistFormats/xspf/xspf.pro +++ b/src/plugins/PlaylistFormats/xspf/xspf.pro @@ -19,7 +19,7 @@ INSTALLS += target INCLUDEPATH += ../../../../src -LIBS += -lqmmpui +LIBS += -lqmmpui -lqmmp QT += xml SOURCES += xspfplaylistformat.cpp diff --git a/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp b/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp index 997867caa..602864043 100644 --- a/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp +++ b/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp @@ -24,9 +24,7 @@ #include #include -#ifndef QMMP_STR_VERSION -#define QMMP_STR_VERSION "0.2.0" -#endif +#include #include "xspfplaylistformat.h" @@ -78,7 +76,7 @@ QString XSPFPlaylistFormat::encode(const QList & files) root.setAttribute("xmlns",QString("http://xspf.org/ns/0/")); QDomElement creator = doc.createElement("creator"); - QDomText text = doc.createTextNode("qmmp-" + QString(QMMP_STR_VERSION)); + QDomText text = doc.createTextNode("qmmp-" + Qmmp::strVersion()); creator.appendChild(text); root.appendChild(creator); diff --git a/src/qmmp/downloader.cpp b/src/qmmp/downloader.cpp index 29a907b84..ecd7b2414 100644 --- a/src/qmmp/downloader.cpp +++ b/src/qmmp/downloader.cpp @@ -218,16 +218,16 @@ void Downloader::run() m_handle = curl_easy_init(); //proxy QSettings settings ( Qmmp::configFile(), QSettings::IniFormat ); - if (settings.value ("Proxy/use_proxy", FALSE).toBool()) + if (Qmmp::useProxy()) curl_easy_setopt(m_handle, CURLOPT_PROXY, - strdup((settings.value("Proxy/host").toString()+":"+ - settings.value("Proxy/port").toString()). + strdup((Qmmp::proxy().host() + ":" + + QString("%1").arg(Qmmp::proxy().port())). toLatin1 ().constData ())); - if (settings.value ("Proxy/authentication", FALSE).toBool()) + if (Qmmp::useProxyAuth()) curl_easy_setopt(m_handle, CURLOPT_PROXYUSERPWD, - strdup((settings.value("Proxy/user").toString()+":"+ - settings.value("Proxy/passw").toString()). + strdup((Qmmp::proxy().userName() + ":" + + Qmmp::proxy().password()). toLatin1 ().constData ())); // Set url to download diff --git a/src/qmmp/qmmp.cpp b/src/qmmp/qmmp.cpp index a3e3d9613..56638e33e 100644 --- a/src/qmmp/qmmp.cpp +++ b/src/qmmp/qmmp.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Ilya Kotov * + * Copyright (C) 2088-2009 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -19,6 +19,7 @@ ***************************************************************************/ #include +#include #ifndef QMMP_VERSION_STR #define QMMP_VERSION_STR "0.3.0" @@ -39,3 +40,39 @@ QString Qmmp::strVersion() return QMMP_VERSION_STR; #endif } + +bool Qmmp::useProxy() +{ + QSettings settings(configFile(), QSettings::IniFormat); + return settings.value("Proxy/use_proxy", FALSE).toBool(); +} + +bool Qmmp::useProxyAuth() +{ + QSettings settings(configFile(), QSettings::IniFormat); + return settings.value("Proxy/authentication", FALSE).toBool(); +} + +QUrl Qmmp::proxy() +{ + QSettings settings(configFile(), QSettings::IniFormat); + return settings.value("Proxy/url").toUrl(); +} + +void Qmmp::setProxyEnabled(bool yes) +{ + QSettings settings(configFile(), QSettings::IniFormat); + settings.setValue("Proxy/use_proxy", yes); +} + +void Qmmp::setProxyAuthEnabled(bool yes) +{ + QSettings settings(configFile(), QSettings::IniFormat); + settings.setValue("Proxy/authentication", yes); +} + +void Qmmp::setProxy (const QUrl &proxy) +{ + QSettings settings(configFile(), QSettings::IniFormat); + settings.setValue("Proxy/url", proxy); +} diff --git a/src/qmmp/qmmp.h b/src/qmmp/qmmp.h index 4e6b03e2c..0fb0c065e 100644 --- a/src/qmmp/qmmp.h +++ b/src/qmmp/qmmp.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Ilya Kotov * + * Copyright (C) 2008-2009 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -20,6 +20,8 @@ #ifndef QMMP_H #define QMMP_H +#include + /** @author Ilya Kotov */ @@ -30,6 +32,13 @@ public: enum MetaData {TITLE = 0, ARTIST, ALBUM, COMMENT, GENRE, YEAR, TRACK, URL}; static QString configFile(); static QString strVersion(); + //global proxy + static bool useProxy(); + static bool useProxyAuth(); + static QUrl proxy(); + static void setProxyEnabled(bool yes); + static void setProxyAuthEnabled(bool yes); + static void setProxy (const QUrl &proxy); }; diff --git a/src/ui/addurldialog.cpp b/src/ui/addurldialog.cpp index 92aae7820..404c08d06 100644 --- a/src/ui/addurldialog.cpp +++ b/src/ui/addurldialog.cpp @@ -42,19 +42,12 @@ AddUrlDialog::AddUrlDialog( QWidget * parent, Qt::WindowFlags f) : QDialog(paren m_http = new QHttp(this); connect(m_http, SIGNAL(done (bool)), SLOT(readResponse(bool))); - //use global proxy settings - if (settings.value ("Proxy/use_proxy", FALSE).toBool()) - { - - if (settings.value ("Proxy/authentication", FALSE).toBool()) - m_http->setProxy(settings.value("Proxy/host").toString(), - settings.value("Proxy/port").toInt(), - settings.value("Proxy/user").toString(), - settings.value("Proxy/passw").toString()); - else - m_http->setProxy(settings.value("Proxy/host").toString(), - settings.value("Proxy/port").toInt()); - } + //load global proxy settings + if (Qmmp::useProxy()) + m_http->setProxy(Qmmp::proxy().host(), + Qmmp::proxy().port(), + Qmmp::useProxyAuth() ? Qmmp::proxy().userName() : QString(), + Qmmp::useProxyAuth() ? Qmmp::proxy().password() : QString()); } AddUrlDialog::~AddUrlDialog() diff --git a/src/ui/configdialog.cpp b/src/ui/configdialog.cpp index 4a6cc687e..a474e61a0 100644 --- a/src/ui/configdialog.cpp +++ b/src/ui/configdialog.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2008 by Ilya Kotov * + * Copyright (C) 2007-2009 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -107,15 +107,13 @@ void ConfigDialog::readSettings() ui.protocolCheckBox->setChecked(settings.value ("PlayList/show_protocol", FALSE).toBool()); //proxy settings - ui.enableProxyCheckBox->setChecked( - settings.value ("Proxy/use_proxy", FALSE).toBool()); - ui.authProxyCheckBox->setChecked( - settings.value ("Proxy/authentication", FALSE).toBool()); - - ui.hostLineEdit->setText(settings.value("Proxy/host").toString()); - ui.portLineEdit->setText(settings.value("Proxy/port").toString()); - ui.proxyUserLineEdit->setText(settings.value("Proxy/user").toString()); - ui.proxyPasswLineEdit->setText(settings.value("Proxy/passw").toString()); + ui.enableProxyCheckBox->setChecked(Qmmp::useProxy()); + ui.authProxyCheckBox->setChecked(Qmmp::useProxyAuth()); + ui.hostLineEdit->setText(Qmmp::proxy().host()); + if (Qmmp::proxy().port(0)) + ui.portLineEdit->setText(QString::number(Qmmp::proxy().port(0))); + ui.proxyUserLineEdit->setText(Qmmp::proxy().userName()); + ui.proxyPasswLineEdit->setText(Qmmp::proxy().password()); ui.hostLineEdit->setEnabled(ui.enableProxyCheckBox->isChecked()); ui.portLineEdit->setEnabled(ui.enableProxyCheckBox->isChecked()); @@ -550,12 +548,15 @@ void ConfigDialog::saveSettings() settings.setValue ("PlayList/full_stream_path", ui.fullPathCheckBox->isChecked()); settings.setValue ("PlayList/show_protocol", ui.protocolCheckBox->isChecked()); FileDialog::setEnabled(FileDialog::registeredFactories().at(ui.fileDialogComboBox->currentIndex())); - settings.setValue ("Proxy/use_proxy", ui.enableProxyCheckBox->isChecked()); - settings.setValue ("Proxy/authentication", ui.authProxyCheckBox->isChecked()); - settings.setValue ("Proxy/host",ui.hostLineEdit->text()); - settings.setValue ("Proxy/port",ui.portLineEdit->text()); - settings.setValue ("Proxy/user",ui.proxyUserLineEdit->text()); - settings.setValue ("Proxy/passw",ui.proxyPasswLineEdit->text()); + + Qmmp::setProxyEnabled(ui.enableProxyCheckBox->isChecked()); + Qmmp::setProxyAuthEnabled(ui.authProxyCheckBox->isChecked()); + QUrl proxyUrl; + proxyUrl.setHost(ui.hostLineEdit->text()); + proxyUrl.setPort(ui.portLineEdit->text().toUInt()); + proxyUrl.setUserName(ui.proxyUserLineEdit->text()); + proxyUrl.setPassword(ui.proxyPasswLineEdit->text()); + Qmmp::setProxy(proxyUrl); settings.setValue ("MainWindow/start_hidden", ui.hiddenCheckBox->isChecked()); settings.setValue ("MainWindow/hide_on_close", ui.hideOnCloseCheckBox->isChecked()); settings.setValue ("MainWindow/opacity", 1.0 - (double)ui.mwTransparencySlider->value()/100); -- cgit v1.2.3-13-gbd6f