--- a/src/RestStateWidget.cpp +++ b/src/RestStateWidget.cpp @@ -31,6 +31,8 @@ #include "lastfmapplication.h" +#include "CustomOpen.h" + #include #include #include @@ -353,7 +355,7 @@ { // TODO: might wanna link to the actual bootstrapping category in the faq // disabled for now as we don't have wanna hack on localized urls just one day before release - QDesktopServices::openUrl( + new CustomOpen( QUrl( "http://" + UnicornUtils::localizedHostName( The::settings().appLanguage() ) + "/help/faq/" ) ); // ?category=Listening History Importing" ) ); } --- a/src/container.cpp +++ b/src/container.cpp @@ -44,6 +44,7 @@ #include "MetaDataWidget.h" #include "playerlistener.h" #include "Radio.h" +#include "CustomOpen.h" #include "ShareDialog.h" #include "settingsdialog.h" #include "DiagnosticsDialog.h" @@ -980,14 +981,14 @@ void Container::showFAQ() { - QDesktopServices::openUrl( "http://" + UnicornUtils::localizedHostName( The::settings().appLanguage() ) + "/help/faq/" ); + new CustomOpen( "http://" + UnicornUtils::localizedHostName( The::settings().appLanguage() ) + "/help/faq/" ); } void Container::showForums() { - QDesktopServices::openUrl( "http://" + UnicornUtils::localizedHostName( The::settings().appLanguage() ) + "/forum/34905/" ); + new CustomOpen( "http://" + UnicornUtils::localizedHostName( The::settings().appLanguage() ) + "/forum/34905/" ); } @@ -995,7 +996,7 @@ Container::inviteAFriend() { QByteArray user = QUrl::toPercentEncoding( The::settings().currentUsername() ); - QDesktopServices::openUrl( "http://" + UnicornUtils::localizedHostName( The::settings().appLanguage() ) + "/user/" + user + "/inviteafriend/" ); + new CustomOpen( "http://" + UnicornUtils::localizedHostName( The::settings().appLanguage() ) + "/user/" + user + "/inviteafriend/" ); } @@ -1404,7 +1405,7 @@ Container::gotoProfile() { QByteArray user = QUrl::toPercentEncoding( The::settings().currentUsername() ); - QDesktopServices::openUrl( "http://" + UnicornUtils::localizedHostName( The::settings().appLanguage() ) + "/user/" + user ); + new CustomOpen( "http://" + UnicornUtils::localizedHostName( The::settings().appLanguage() ) + "/user/" + user ); } @@ -1678,7 +1679,7 @@ QString file = QString::fromStdWString( thelog->GetFilePath() ); ShellExecuteW( 0, 0, (TCHAR*)file.utf16(), 0, 0, SW_SHOWNORMAL ); #else - QDesktopServices::openUrl( QUrl::fromLocalFile( QString::fromStdString( thelog->GetFilePath() ) ) ); + new CustomOpen( QUrl::fromLocalFile( QString::fromStdString( thelog->GetFilePath() ) ) ); #endif } @@ -1691,7 +1692,7 @@ QString file = MooseUtils::logPath( "" ); ShellExecuteW( 0, 0, (TCHAR*)file.utf16(), 0, 0, SW_SHOWNORMAL ); #else - QDesktopServices::openUrl( QUrl::fromLocalFile( MooseUtils::logPath( "" ) ) ); + new CustomOpen( QUrl::fromLocalFile( MooseUtils::logPath( "" ) ) ); #endif } --- a/src/libUnicorn/URLLabel.cpp +++ b/src/libUnicorn/URLLabel.cpp @@ -31,6 +31,7 @@ **********************************************************************/ #include "URLLabel.h" +#include "CustomOpen.h" #include #include @@ -399,7 +400,7 @@ #ifndef Q_WS_WIN QDesktopServices::openUrl( QUrl::fromEncoded( url.toString().toUtf8() ) ); #else - QDesktopServices::openUrl( url ); + new CustomOpen( url ); #endif } } --- a/src/libUnicorn/draglabel.cpp +++ b/src/libUnicorn/draglabel.cpp @@ -21,6 +21,7 @@ #include "draglabel.h" #include "UnicornCommon.h" +#include "CustomOpen.h" #include #include @@ -818,9 +819,9 @@ if ( !m_items[m_hoverIndex].m_url.isEmpty() ) { #ifndef Q_WS_WIN - QDesktopServices::openUrl( QUrl::fromEncoded( m_items[m_hoverIndex].m_url.toString().toUtf8() ) ); + new CustomOpen( QUrl::fromEncoded( m_items[m_hoverIndex].m_url.toString().toUtf8() ) ); #else - QDesktopServices::openUrl( m_items[m_hoverIndex].m_url ); + new CustomOpen( m_items[m_hoverIndex].m_url ); #endif } } --- a/src/libUnicorn/imagebutton.cpp +++ b/src/libUnicorn/imagebutton.cpp @@ -20,6 +20,7 @@ ***************************************************************************/ #include "imagebutton.h" +#include "CustomOpen.h" #include #include @@ -84,9 +85,9 @@ if ( !m_url.isEmpty() ) { #ifndef Q_WS_WIN - QDesktopServices::openUrl( QUrl::fromEncoded( m_url.toString().toUtf8() ) ); + new CustomOpen( QUrl::fromEncoded( m_url.toString().toUtf8() ) ); #else - QDesktopServices::openUrl( m_url ); + new CustomOpen( m_url ); #endif } } --- a/src/SideBarView.cpp +++ b/src/SideBarView.cpp @@ -40,6 +40,7 @@ #include "LastMessageBox.h" #include "lastfmapplication.h" #include "User.h" +#include "CustomOpen.h" #include #include @@ -440,7 +441,7 @@ switch (itemType) { case SideBar::MyProfile: - QDesktopServices::openUrl( "http://" + localizedHost + "/user/" + QUrl::toPercentEncoding( The::settings().currentUsername() ) ); + new CustomOpen( "http://" + localizedHost + "/user/" + QUrl::toPercentEncoding( The::settings().currentUsername() ) ); break; case SideBar::HistoryStation: map[PlayStation] = menu.addAction( ICON_OF( index ), PLAY_THIS_STATION ); @@ -726,35 +727,35 @@ { QString const tag = index.data().toString().remove( QRegExp(" \\(\\d*\\)$") ); - QDesktopServices::openUrl( "http://" + localizedHost + "/tag/" + + new CustomOpen( "http://" + localizedHost + "/tag/" + UnicornUtils::urlEncodeItem( tag ) ); break; } case GoToUserPage: - QDesktopServices::openUrl( "http://" + localizedHost + "/user/" + + new CustomOpen( "http://" + localizedHost + "/user/" + UnicornUtils::urlEncodeItem( display_role ) ); break; case GoToFriendsPage: - QDesktopServices::openUrl( "http://" + localizedHost + "/user/" + + new CustomOpen( "http://" + localizedHost + "/user/" + UnicornUtils::urlEncodeItem( The::currentUsername() ) + "/friends/" ); break; case GoToNeighboursPage: - QDesktopServices::openUrl( "http://" + localizedHost + "/user/" + + new CustomOpen( "http://" + localizedHost + "/user/" + UnicornUtils::urlEncodeItem( The::currentUsername() ) + "/neighbours/" ); break; case GoToTagsPage: { - QDesktopServices::openUrl( "http://" + localizedHost + "/user/" + + new CustomOpen( "http://" + localizedHost + "/user/" + UnicornUtils::urlEncodeItem( The::currentUsername() ) + "/tags/" ); break; } case GoToTrackPage: - QDesktopServices::openUrl( "http://" + localizedHost + "/music/" + + new CustomOpen( "http://" + localizedHost + "/music/" + UnicornUtils::urlEncodeItem( m_model->trackAtIndex(index).artist() ) + "/_/" + UnicornUtils::urlEncodeItem( m_model->trackAtIndex(index).title() ) + "/" ); break; --- /dev/null +++ b/src/libUnicorn/CustomOpen.h @@ -0,0 +1,40 @@ +/*************************************************************************** + * Copyright (C) 2007 by * + * John Stamp * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + + +#ifndef LAST_FM_CustomOpen_H +#define LAST_FM_CustomOpen_H + +#include +#include +#include "UnicornDllExportMacro.h" + +class UNICORN_DLLEXPORT CustomOpen : QObject +{ + Q_OBJECT + + public: + CustomOpen( const QUrl url ); + private: + QMutex m_mutex; + void launchBrowser( const QUrl url ); +}; + +#endif // CustomOpen_H --- a/src/libUnicorn/libUnicorn.pro +++ b/src/libUnicorn/libUnicorn.pro @@ -53,6 +53,7 @@ WebService/XmlRpc.h \ WebService/FrikkinNormanRequest.h \ LastMessageBox.h \ + CustomOpen.h \ StationUrl.h \ StopWatch.h \ UnicornCommon.h \ @@ -76,6 +77,7 @@ TrackInfo.cpp \ watermarkwidget.cpp \ logger.cpp \ + CustomOpen.cpp \ Settings.cpp \ WebService.cpp \ WebService/Request.cpp \ --- /dev/null +++ b/src/libUnicorn/CustomOpen.cpp @@ -0,0 +1,99 @@ +/*************************************************************************** + * Copyright (C) 2007 by * + * John Stamp * + * * + * Most of this is taken from browserthread.cpp * + * Copyright (C) 2005 - 2007 by * + * Christian Muehlhaeuser, Last.fm Ltd * + * Erik Jaelevik, Last.fm Ltd * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "CustomOpen.h" +#include "Settings.h" +#include +#include +#include + +#ifndef WIN32 +#include +#endif + +CustomOpen::CustomOpen( const QUrl url ) +{ + if ( url.scheme() == QLatin1String( "file" ) ) + QDesktopServices::openUrl( url ); + else + launchBrowser( url ); + + deleteLater(); +} + + +void CustomOpen::launchBrowser( const QUrl url ) +{ + #ifdef WIN32 + WCHAR val[1024]; + memset( val, 0, 1024 ); + MultiByteToWideChar( CP_UTF8, 0, m_url.toAscii(), m_url.length(), val, 1024 ); + ShellExecute( 0, 0, val, NULL, NULL, SW_SHOW ); + #endif + + #ifdef Q_WS_MAC + ICInstance icInstance; + OSType psiSignature = 'Psi '; + OSStatus error = ICStart( &icInstance, psiSignature ); + + ConstStr255Param hint( 0x0 ); + const char* data = m_url.toLocal8Bit().data(); + long length = m_url.length(); + long start( 0 ); + long end( length ); + + ICLaunchURL( icInstance, hint, data, length, &start, &end ); + ICStop( icInstance ); + #endif + + #ifdef Q_WS_X11 + SharedSettings* settings = SharedSettings::instance(); + QString browser = settings->browser(); + QStringList params; + params.append( url.toEncoded() ); + + QStringList options; + + if ( browser.trimmed() == "" ) + { + QDesktopServices::openUrl( url ); + goto _end; + } + + options = browser.split( " " ); + if ( options.size() == 0 ) + options.append( browser ); + + for ( int i = 1; i < options.size(); i++ ) + { + qDebug() << QString( "param: " + options.at( i ) ).toLocal8Bit(); + params.append( "\"" + options.at( i ) + "\"" ); + } + + QProcess::startDetached( options.at( 0 ), params ); + _end: + return; + #endif +} --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -85,6 +85,9 @@ QWidget* connWidget = new QWidget(); ui_connection.setupUi( connWidget ); +#ifndef Q_WS_X11 + ui_connection.browserBox->hide(); +#endif ui.pageStack->addWidget( connWidget ); #ifndef Q_WS_X11 @@ -247,6 +250,10 @@ connect( ui_scrobbling.launchWithMediaPlayerCheck, SIGNAL( toggled( bool ) ), this, SLOT( configChanged() ) ); connect( ui_account.showInDockCheck, SIGNAL( toggled( bool ) ), this, SLOT( configChanged() ) ); #endif + + #ifdef Q_WS_X11 + connect( ui_connection.browserCommandEdit, SIGNAL( textChanged( QString ) ), this, SLOT( configChanged() ) ); + #endif } @@ -271,6 +278,9 @@ m_loginWidget->resetWidget( The::settings().currentUsername() ); +#ifdef Q_WS_X11 + originalBrowserCommand = The::settings().browser(); +#endif originalUsername = The::settings().currentUser().username(); originalPassword = The::settings().currentUser().password(); originalProxyHost = The::settings().getProxyHost(); @@ -429,6 +439,9 @@ ui_connection.crashReportCheck->setChecked( The::settings().currentUser().crashReportingEnabled() ); #endif ui_connection.manualProxyButton->setChecked( The::settings().isUseProxy() ); +#ifdef Q_WS_X11 + ui_connection.browserCommandEdit->setText( The::settings().browser() ); +#endif } @@ -622,11 +635,18 @@ The::settings().currentUser().setCrashReportingEnabled( ui_connection.crashReportCheck->isChecked() ); #endif +#ifdef Q_WS_X11 + The::settings().setBrowser( ui_connection.browserCommandEdit->text() ); +#endif + m_reconnect = ui_connection.proxyHostEdit->text() != originalProxyHost || ui_connection.proxyUsernameEdit->text() != originalProxyUsername || ui_connection.proxyPasswordEdit->text() != originalProxyPassword || ui_connection.proxyPortEdit->text().toInt() != originalProxyPort || ui_connection.manualProxyButton->isChecked() != originalProxyUsage || + #ifdef Q_WS_X11 + ui_connection.browserCommandEdit->text() != originalBrowserCommand || + #endif m_reconnect; pageSaved( 3 ); --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -92,6 +92,8 @@ QString originalUsername; QString originalPassword; + QString originalBrowserCommand; + QString originalProxyHost; QString originalProxyUsername; QString originalProxyPassword; --- a/src/settingsdialog_connection.ui +++ b/src/settingsdialog_connection.ui @@ -209,6 +209,41 @@ + + + Web Browser + + + + 9 + + + 6 + + + + + 0 + + + 6 + + + + + Browser + + + + + + + + + + + + Bandwidth Usage --- a/src/libMoose/LastFmSettings.h +++ b/src/libMoose/LastFmSettings.h @@ -285,8 +285,8 @@ int externalSoundSystem(); - QString browser() const { return QSettings().value( "Browser" ).toString(); } - void setBrowser( QString browser ) { QSettings().setValue( "Browser", browser ); } + //QString browser() const { return QSettings().value( "Browser" ).toString(); } + //void setBrowser( QString browser ) { QSettings().setValue( "Browser", browser ); } int musicProxyPort() const { return QSettings().value( "MusicProxyPort" ).toInt(); } void setMusicProxyPort( int v ) { QSettings().setValue( "MusicProxyPort", v ); } --- a/src/libUnicorn/Settings.h +++ b/src/libUnicorn/Settings.h @@ -142,6 +142,9 @@ QString getProxyPassword() const { return SharedQSettings().value( "ProxyPassword" ).toString(); } void setProxyPassword( QString v ) { SharedQSettings().setValue( "ProxyPassword", v ); } + QString browser() const { return SharedQSettings().value( "Browser" ).toString(); } + void setBrowser( QString browser ) { SharedQSettings().setValue( "Browser", browser ); } + protected: /// This must be initialised with an instance of the relevant subclass @@ -168,6 +171,7 @@ friend class CachedHttp; friend class WebService; + friend class CustomOpen; }; --- a/src/TagListWidget.cpp +++ b/src/TagListWidget.cpp @@ -19,6 +19,7 @@ ***************************************************************************/ #include "TagListWidget.h" +#include "CustomOpen.h" #include "libMoose/LastFmSettings.h" @@ -161,5 +162,5 @@ "/tag/" + UnicornUtils::urlEncodeItem( currentItem()->text( 0 ) ); - QDesktopServices::openUrl( url ); + new CustomOpen( url ); }