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

List:       amarok
Subject:    Patch for Bug #177403: "Amarok does not remove leading blanks in
From:       Nicholas Sinlock <isolatedincident () gmail ! com>
Date:       2009-01-11 16:12:16
Message-ID: 496A1A60.4090304 () gmail ! com
[Download RAW message or body]

In addition to stripping the leading blanks from podcast titles, I 
also implemented a function to remove any part of the channel title
that is also found at the start of the episode title, as in the case of 
Scientific American's 60 Second Science podcast, found
at http://www.sciam.com/podcast/sciam_podcast_r_d.xml.   I implemented 
that rather than using the decapitateString as the latter function
had the side effect of sometimes removing several characters from a 
word, effectively truncating a proper word into a non-proper word.

The .diff is attached.

["patch.diff" (text/plain)]

Index: browsers/playlistbrowser/PodcastModel.cpp
===================================================================
--- browsers/playlistbrowser/PodcastModel.cpp	(revision 906274)
+++ browsers/playlistbrowser/PodcastModel.cpp	(working copy)
@@ -60,9 +60,10 @@
     Meta::PodcastMetaCommon* pmc = static_cast<Meta::PodcastMetaCommon *>( \
index.internalPointer() );  
     bool isChannel = false;
-    QString title;
+    QString title, chTitle;
     QString description;
     KIcon icon;
+    int length;
     bool isOnDisk = false;
     if ( pmc->podcastType() == Meta::ChannelType )
     {
@@ -75,7 +76,34 @@
     else if ( pmc->podcastType() == Meta::EpisodeType )
     {
         Meta::PodcastEpisode *episode = static_cast<Meta::PodcastEpisode *>( \
                index.internalPointer() );
-        title = episode->title();
+	Meta::PodcastChannelPtr ptr = episode->channel();
+	title = episode->title();
+        chTitle = ptr->title();
+	if (!chTitle.isEmpty())   // ensure that there is a channel title
+	{
+	    if (title.startsWith(chTitle, Qt::CaseInsensitive))   // if the episode title \
begins with the channel title... +	        title = title.right(title.length() - \
(chTitle.length()));   // ...remove the channel title from the episode title +	    \
else   // otherwise search for any phrases which are common among the channel title \
and episode title and remove them from the episode title +	    {
+                for (length = chTitle.length()  - 1; length > 0; length--)
+                {
+                    if (chTitle[length].isSpace() && \
title.startsWith(chTitle.left(length), Qt::CaseInsensitive)) +		    {
+	                title = title.right(title.length() - (length)).trimmed();
+			break;
+	            }
+                }
+	    }
+	}
+ 
+	for (length = 0; length < title.length(); length++) // remove any extraneous \
characters from the beginning of the episode title such as extra punctuation symbols \
+	{ +	    if (title[length].isLetterOrNumber())
+	    {
+	        title = title.right(title.length() - (length - 1));
+		break;
+	    }
+	}
         description = episode->description();
         isChannel = false;
         isOnDisk = !episode->localUrl().isEmpty();
Index: podcasts/PodcastReader.cpp
===================================================================
--- podcasts/PodcastReader.cpp	(revision 906274)
+++ podcasts/PodcastReader.cpp	(working copy)
@@ -220,7 +220,7 @@
                 }
                 else if( QXmlStreamReader::name() == "title")
                 {
-                    m_current->setTitle( m_titleString );
+		    m_current->setTitle( m_titleString.trimmed() );
                     m_titleString.clear();
                 }
                 else if( QXmlStreamReader::name() == "description" )



_______________________________________________
Amarok mailing list
Amarok@kde.org
https://mail.kde.org/mailman/listinfo/amarok


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

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