Commit 32b55e81 authored by Frerich Raabe's avatar Frerich Raabe

- Capitalize the first letter of each word in the title, artist and album

  fields. That looks better to me.
  I think the regexp for matching the start of a word is not perfect but
  for some reason \b\w (I think \b is word-boundary) did not work. Oh well,
  this is good enough for now.

svn path=/trunk/kdemultimedia/juk/; revision=217361
parent faab9df3
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <kapplication.h> #include <kapplication.h>
#include <kconfig.h> #include <kconfig.h>
#include <kdebug.h>
#include <kdeversion.h> #include <kdeversion.h>
#if KDE_IS_VERSION(3,1,90) #if KDE_IS_VERSION(3,1,90)
# include <kmacroexpander.h> # include <kmacroexpander.h>
...@@ -95,13 +96,13 @@ QString FileNameScheme::composeRegExp(const QString &s) const ...@@ -95,13 +96,13 @@ QString FileNameScheme::composeRegExp(const QString &s) const
KConfig *cfg = kapp->config(); KConfig *cfg = kapp->config();
{ {
KConfigGroupSaver(cfg, "TagGuesser"); KConfigGroupSaver(cfg, "TagGuesser");
substitutions[ 't' ] = cfg->readEntry("Title regexp", "([\\w\\s'&]+)"); substitutions[ 't' ] = cfg->readEntry("Title regexp", "([\\w\\s'&]+)");
substitutions[ 'a' ] = cfg->readEntry("Artist regexp", "([\\w\\s'&]+)"); substitutions[ 'a' ] = cfg->readEntry("Artist regexp", "([\\w\\s'&]+)");
substitutions[ 'A' ] = cfg->readEntry("Album regexp", "([\\w\\s'&]+)"); substitutions[ 'A' ] = cfg->readEntry("Album regexp", "([\\w\\s'&]+)");
substitutions[ 'T' ] = cfg->readEntry("Track regexp", "(\\d+)"); substitutions[ 'T' ] = cfg->readEntry("Track regexp", "(\\d+)");
substitutions[ 'c' ] = cfg->readEntry("Comment regexp", "([\\w\\s]+)"); substitutions[ 'c' ] = cfg->readEntry("Comment regexp", "([\\w\\s]+)");
} }
QString regExp = QRegExp::escape(s.simplifyWhiteSpace()); QString regExp = QRegExp::escape(s.simplifyWhiteSpace());
...@@ -164,8 +165,8 @@ void TagGuesser::setSchemeStrings(const QStringList &schemes) ...@@ -164,8 +165,8 @@ void TagGuesser::setSchemeStrings(const QStringList &schemes)
{ {
KConfig *cfg = kapp->config(); KConfig *cfg = kapp->config();
{ {
KConfigGroupSaver(cfg, "TagGuesser"); KConfigGroupSaver(cfg, "TagGuesser");
cfg->writeEntry("Filename schemes", schemes); cfg->writeEntry("Filename schemes", schemes);
} }
cfg->sync(); cfg->sync();
} }
...@@ -199,9 +200,9 @@ void TagGuesser::guess(const QString &absFileName) ...@@ -199,9 +200,9 @@ void TagGuesser::guess(const QString &absFileName)
for (; it != end; ++it) { for (; it != end; ++it) {
const FileNameScheme schema(*it); const FileNameScheme schema(*it);
if(schema.matches(absFileName)) { if(schema.matches(absFileName)) {
m_title = schema.title(); m_title = capitalizeWords(schema.title());
m_artist = schema.artist(); m_artist = capitalizeWords(schema.artist());
m_album = schema.album(); m_album = capitalizeWords(schema.album());
m_track = schema.track(); m_track = schema.track();
m_comment = schema.comment(); m_comment = schema.comment();
break; break;
...@@ -209,4 +210,22 @@ void TagGuesser::guess(const QString &absFileName) ...@@ -209,4 +210,22 @@ void TagGuesser::guess(const QString &absFileName)
} }
} }
QString TagGuesser::capitalizeWords(const QString &s)
{
if(s.isEmpty())
return s;
QString result = s;
result[ 0 ] = result[ 0 ].upper();
const QRegExp wordRegExp("\\s\\w");
int i = result.find( wordRegExp );
while ( i > -1 ) {
result[ i + 1 ] = result[ i + 1 ].upper();
i = result.find( wordRegExp, ++i );
}
return result;
}
// vim:ts=4:sw=4:noet // vim:ts=4:sw=4:noet
...@@ -58,6 +58,7 @@ class TagGuesser ...@@ -58,6 +58,7 @@ class TagGuesser
private: private:
void loadSchemes(); void loadSchemes();
QString capitalizeWords(const QString &s);
FileNameScheme::List m_schemes; FileNameScheme::List m_schemes;
QString m_title; QString m_title;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment