Sophie

Sophie

distrib > Mandriva > 2009.1 > x86_64 > media > contrib-release-src > by-pkgid > a3a9b692ad9677f55cdf3960410addc8 > files > 2

lastfm-player-1.5.1.31879-3mdv2009.1.src.rpm

--- a/src/RestStateWidget.cpp
+++ b/src/RestStateWidget.cpp
@@ -30,6 +30,8 @@
 
 #include "lastfmapplication.h"
 
+#include "CustomOpen.h"
+
 #include <QKeyEvent>
 #include <QDesktopServices>
 #include <QPainter>
@@ -310,6 +312,6 @@
 {
     // 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
@@ -41,6 +41,7 @@
 #include "MetaDataWidget.h"
 #include "playerlistener.h"
 #include "Radio.h"
+#include "CustomOpen.h"
 #include "ShareDialog.h"
 #include "settingsdialog.h"
 #include "DiagnosticsDialog.h"
@@ -933,14 +934,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/" );
 }
 
 
@@ -948,7 +949,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/" );
 }
 
 
@@ -1357,7 +1358,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 );
 }
 
 
@@ -1628,7 +1629,7 @@
         QString file = QString::fromStdWString( Logger::GetLogger().GetFilePath() );
         ShellExecuteW( 0, 0, (TCHAR*)file.utf16(), 0, 0, SW_SHOWNORMAL );
     #else
-        QDesktopServices::openUrl( QUrl::fromLocalFile( QString::fromStdString( Logger::GetLogger().GetFilePath() ) ) );
+        new CustomOpen( QUrl::fromLocalFile( QString::fromStdString( Logger::GetLogger().GetFilePath() ) ) );
     #endif
 }
 
@@ -1641,7 +1642,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 <QApplication>
 #include <QMouseEvent>
@@ -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 <QApplication>
 #include <QEvent>
@@ -813,9 +814,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 <QDesktopServices>
 #include <QIcon>
@@ -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 <QDropEvent>
 #include <QHeaderView>
@@ -437,7 +438,7 @@
     switch (i.type())
     {
         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( i.icon(), PLAY_THIS_STATION );
@@ -719,35 +720,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( i.track().artist() ) + "/_/" +
                                        UnicornUtils::urlEncodeItem( i.track().title() ) + "/" );
             break;
--- /dev/null
+++ b/src/libUnicorn/CustomOpen.h
@@ -0,0 +1,40 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by                                                 *
+ *      John Stamp <jstamp@users.sourceforge.net>                          *
+ *                                                                         *
+ *   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 <QMutex>
+#include <QUrl>
+#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 <jstamp@users.sourceforge.net>                          *
+ *                                                                         *
+ *   Most of this is taken from browserthread.cpp                          *
+ *   Copyright (C) 2005 - 2007 by                                          *
+ *      Christian Muehlhaeuser, Last.fm Ltd <chris@last.fm>                *
+ *      Erik Jaelevik, Last.fm Ltd <erik@last.fm>                          *
+ *                                                                         *
+ *   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 <QDebug>
+#include <QDesktopServices>
+#include <QProcess>
+
+#ifndef WIN32
+#include <fcntl.h>
+#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
@@ -245,6 +248,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
 }
 
 
@@ -269,6 +276,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();
@@ -427,6 +437,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
 }
 
 
@@ -620,11 +633,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 @@
     </widget>
    </item>
    <item>
+    <widget class="QGroupBox" name="browserBox" >
+     <property name="title" >
+      <string>Web Browser</string>
+     </property>
+     <layout class="QVBoxLayout" >
+      <property name="margin" >
+       <number>9</number>
+      </property>
+      <property name="spacing" >
+       <number>6</number>
+      </property>
+      <item>
+       <layout class="QHBoxLayout" >
+        <property name="margin" >
+         <number>0</number>
+        </property>
+        <property name="spacing" >
+         <number>6</number>
+        </property>
+        <item>
+         <widget class="QLabel" name="label" >
+          <property name="text" >
+           <string>Browser</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="browserCommandEdit" />
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
     <widget class="QGroupBox" name="groupBox" >
      <property name="title" >
       <string>Bandwidth Usage</string>
--- a/src/libMoose/LastFmSettings.h
+++ b/src/libMoose/LastFmSettings.h
@@ -270,8 +270,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 );
 }