Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 37 additions & 23 deletions src/library/libraryquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const QMap<QString, Song::FileType> kFiletypeId = QMap<QString, Song::FileType>(
{"stream", Song::Type_Stream},
{"unknown", Song::Type_Unknown}});

const int kNsecsPerSec = 1e9;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants already exist somewhere in Clementine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info, I did not find it, because it is kNsecPerSec, but could not find kAllowedChars or anything else that defines a value of smhd.

const QString kAllowedChars = "smhd";
const int kSecsPerDay = 60 * 60 * 24;

LibraryQuery::LibraryQuery(const QueryOptions& options)
: include_unavailable_(false), join_with_fts_(false), limit_(-1) {
if (!options.filter().isEmpty()) {
Expand Down Expand Up @@ -105,32 +109,16 @@ LibraryQuery::LibraryQuery(const QueryOptions& options)
if (ok) {
AddWhere(columntoken, doubleVal, op);
}
} else if (columntoken == "length") {
double seconds = GetSecondsFromToken(val);
if (seconds > 0) {
double nanoseconds = seconds * kNsecsPerSec;
AddWhere(columntoken, nanoseconds, op);
}
} else if (columntoken == "filetype") {
AddWhere(columntoken, kFiletypeId[val]);
} else if (Song::kDateColumns.contains(columntoken)) {
int seconds = 0;
QString tmp = "";
QString allowedChars = "smhd";
for (QChar c : val) {
if (c.isDigit()) {
tmp.append(c);
} else if (allowedChars.contains(c)) {
bool ok;
int intVal = tmp.toInt(&ok);
tmp = "";
if (ok) {
if (c == 's') {
seconds += intVal;
} else if (c == 'm') {
seconds += intVal * 60;
} else if (c == 'h') {
seconds += intVal * 60 * 60;
} else if (c == 'd') {
seconds += intVal * 60 * 60 * 24;
}
}
}
}
int seconds = GetSecondsFromToken(val);
if (seconds > 0) {
int now = QDateTime::currentDateTime().toTime_t();
QString dt = QString("(%1-%2)").arg(now).arg(columntoken);
Expand Down Expand Up @@ -181,6 +169,32 @@ LibraryQuery::LibraryQuery(const QueryOptions& options)
}
}

int LibraryQuery::GetSecondsFromToken(QString& val) const {
int seconds = 0;
QString tmp = "";
for (QChar c : val) {
if (c.isDigit()) {
tmp.append(c);
} else if (kAllowedChars.contains(c)) {
bool ok = false;
int intVal = tmp.toInt(&ok);
tmp = "";
if (ok) {
if (c == 's') {
seconds += intVal;
} else if (c == 'm') {
seconds += intVal * 60;
} else if (c == 'h') {
seconds += intVal * 60 * 60;
} else if (c == 'd') {
seconds += intVal * kSecsPerDay;
}
}
}
}
return seconds;
}

QString LibraryQuery::GetInnerQuery() {
return duplicates_only_
? QString(
Expand Down
1 change: 1 addition & 0 deletions src/library/libraryquery.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class LibraryQuery {
static const QStringList kNumericCompOperators;

private:
int GetSecondsFromToken(QString& val) const;
QString GetInnerQuery();

bool include_unavailable_;
Expand Down