[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/multimedia/amarok/src
From:       Sven Krohlas <sven () asbest-online ! de>
Date:       2008-09-08 20:34:50
Message-ID: 1220906090.528058.1508.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 858855 by krohlas:

Protect our users from metadata spam in streams.
Some streams resend their metadata every few seconds, so
everytime the OSD comes up, which is quite annoying. This
should fix those streams in all cases.

Streams trying to spread advertising messages between normal
metadata will only be able to show each message exactly one
time, as long as the distance between those is not larger
than 12 metadata changes.

This only protects the OSD, statusbar and current track
applet are not affected, as here those messages are by
far less annoying.

I hope App.cpp is the correct place for this, as the OSD
gets shown here.


 M  +27 -1     App.cpp  
 M  +4 -0      App.h  


--- trunk/extragear/multimedia/amarok/src/App.cpp #858854:858855
@@ -589,6 +589,8 @@
 
     handleCliArgs();
 
+    m_metaDataHistory = new QList<QHash<qint64, QString> >;
+
     delete m_splash;
     m_splash = 0;
     PERF_LOG( "App init done" )
@@ -647,12 +649,16 @@
     Meta::TrackPtr currentTrack = The::engineController()->currentTrack();
     if( !currentTrack )
         return;
-    Amarok::OSD::instance()->show( currentTrack );
+
     if( !trackChanged )
     {
         if ( !currentTrack->prettyName().isEmpty() )
            mainWindow()->setPlainCaption( i18n( "%1 - %2 -  %3", newMetaData.value( \
Meta::valArtist ), newMetaData.value( Meta::valTitle ), AMAROK_CAPTION ) ); +        \
if( !isMetaDataSpam( newMetaData ))// metadata spam protection from streams +         \
Amarok::OSD::instance()->show( currentTrack );  }
+    else
+        Amarok::OSD::instance()->show( currentTrack );
 
     TrackToolTip::instance()->setTrack( currentTrack );
 }
@@ -721,6 +727,26 @@
 //     }
 }
 
+/* Try to detect MetaData spam in Streams. */
+bool App::isMetaDataSpam( const QHash<qint64, QString> &newMetaData )
+{
+    // search for Metadata in history
+    for( int i = 0; i < m_metaDataHistory->size(); i++)
+    {
+        if( m_metaDataHistory->at( i ) == newMetaData ) // we already had that one \
-> spam! +        {
+            m_metaDataHistory->move( i, 0 ); // move spam to the beginning of the \
list +            return true;
+        }
+    }
+
+    if( m_metaDataHistory->size() == 12 )
+        m_metaDataHistory->removeLast();
+
+    m_metaDataHistory->insert( 0, newMetaData);
+    return false;
+}
+
 KIO::Job *App::trashFiles( const KUrl::List &files )
 {
     KIO::Job *job = KIO::trash( files );
--- trunk/extragear/multimedia/amarok/src/App.h #858854:858855
@@ -26,6 +26,8 @@
 #include <KUrl>
 
 #include <QByteArray>
+#include <QHash>
+#include <QString>
 
 namespace Amarok {
     class TrayIcon;
@@ -87,11 +89,13 @@
         void slotTrashResult( KJob *job );
 
     private:
+        bool isMetaDataSpam( const QHash<qint64, QString> &newMetaData );
         // ATTRIBUTES ------
         MainWindow          *m_mainWindow;
         Amarok::TrayIcon    *m_tray;
         MediaDeviceManager  *m_mediaDeviceManager;
         KSplashScreen       *m_splash;
+        QList<QHash<qint64, QString> >        *m_metaDataHistory;
 
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic