2 This file is part of Jerboa.
4 Jerboa is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option), version 3 of the license.
9 Jerboa is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with Jerboa. If not, see <http://www.gnu.org/licenses/>.
23 #include <QCoreApplication>
25 #include <QDesktopServices>
32 #include <QStringList>
35 using Jerboa::SqlQuery
;
39 QString
simpleAlbum(QString album
)
41 return album
.replace(QRegExp("[[(<{].+"), "").trimmed();
46 return QDateTime::currentDateTime().toUTC().toTime_t();
49 unsigned int getArtistID(QString artist
, QString artistSort
)
52 query
.prepare("SELECT `ID` FROM `Artists` WHERE `Name` = :artist");
53 query
.bindValue(":artist", artist
);
54 query
.exec(); query
.first();
55 if ( query
.isValid() )
57 // We already have this artist
58 return query
.record().value(0).toUInt();
62 // Need a new artist - firstly, get a romanised form of their name from the sortkey
63 QStringList artistRomanisedBackward
= artistSort
.split(", ");
64 QStringList artistRomanisedForward
;
65 QStringListIterator
it(artistRomanisedBackward
);
67 while(it
.hasPrevious()) artistRomanisedForward
.append(it
.previous());
68 QString artistRomanised
= artistRomanisedForward
.join(" ");
70 // Now, insert it into the database
71 query
.prepare("INSERT INTO `Artists` (`Name`, `RomanisedName`, `SortKey`) VALUES (:name, :roman, :sort)");
72 query
.bindValue(":name", artist
);
73 query
.bindValue(":roman", artistRomanised
);
74 query
.bindValue(":sort", artistSort
);
76 return query
.lastInsertId().toUInt();
80 QString
artistName(unsigned int id
)
83 query
.prepare("SELECT `Name` FROM `Artists` WHERE `ID` = :id");
84 query
.bindValue(":id", id
);
85 query
.exec(); query
.first();
86 if ( query
.isValid() )
88 // We already have this artist
89 return query
.record().value(0).toString();
97 QString
dataLocation()
99 #ifdef EMBEDDED_USE_FIXED_PATHS
100 return EMBEDDED_FIXED_DATA_PATH
;
102 return QDesktopServices::storageLocation(QDesktopServices::DataLocation
);
106 QString
musicLocation()
108 #ifdef EMBEDDED_USE_FIXED_PATHS
109 return EMBEDDED_FIXED_MUSIC_PATH
;
111 return QDesktopServices::storageLocation(QDesktopServices::MusicLocation
);
115 QIcon
getIcon(QString name
)
118 QDir
images(":/images/");
119 Q_FOREACH(QString item
, images
.entryList(QDir::AllDirs
))
121 QFile
file(QString(":/images/%1/%2.png").arg(item
, name
));
124 icon
.addFile(file
.fileName());
126 QFile
svgz(QString(":/images/%1/%2.svg").arg(item
, name
));
129 icon
.addFile(svgz
.fileName());
135 QList
<QUrl
> walkDirectories(const QFileInfo
& fileinfo
)
137 if (fileinfo
.isDir())
140 QFileInfoList todo
= QDir(fileinfo
.absoluteFilePath()).entryInfoList(
141 QDir::NoDotAndDotDot
| QDir::Dirs
| QDir::Files
, QDir::Name
);
142 Q_FOREACH(QFileInfo info
, todo
)
145 list
<< walkDirectories(info
);
147 list
<< QUrl::fromLocalFile(info
.absoluteFilePath());
152 return QList
<QUrl
>() << QUrl::fromLocalFile(fileinfo
.absoluteFilePath());