diff --git a/src/core/song.cpp b/src/core/song.cpp index 6e5467939..a04902047 100644 --- a/src/core/song.cpp +++ b/src/core/song.cpp @@ -131,6 +131,10 @@ const QStringList Song::kIntColumns = QStringList() << "track" const QStringList Song::kFloatColumns = QStringList() << "rating" << "bpm"; +const QStringList Song::kDateColumns = QStringList() << "lastplayed" + << "mtime" + << "ctime"; + const QString Song::kColumnSpec = Song::kColumns.join(", "); const QString Song::kBindSpec = Utilities::Prepend(":", Song::kColumns).join(", "); diff --git a/src/core/song.h b/src/core/song.h index 27c9c6a99..bc109a622 100644 --- a/src/core/song.h +++ b/src/core/song.h @@ -75,6 +75,7 @@ class Song { static const QStringList kIntColumns; static const QStringList kFloatColumns; + static const QStringList kDateColumns; static const QStringList kFtsColumns; static const QString kFtsColumnSpec; diff --git a/src/library/libraryfilterwidget.cpp b/src/library/libraryfilterwidget.cpp index c796e1d58..82380d3be 100644 --- a/src/library/libraryfilterwidget.cpp +++ b/src/library/libraryfilterwidget.cpp @@ -45,8 +45,10 @@ LibraryFilterWidget::LibraryFilterWidget(QWidget* parent) // Add the available fields to the tooltip here instead of the ui // file to prevent that they get translated by mistake. - QString available_fields = - Song::kFtsColumns.join(", ").replace(QRegExp("\\bfts"), ""); + QString available_fields = (Song::kFtsColumns + Song::kIntColumns + + Song::kFloatColumns + Song::kDateColumns) + .join(", ") + .replace(QRegExp("\\bfts"), ""); ui_->filter->setToolTip(ui_->filter->toolTip().arg(available_fields)); connect(ui_->filter, SIGNAL(returnPressed()), SIGNAL(ReturnPressed())); diff --git a/src/library/libraryfilterwidget.ui b/src/library/libraryfilterwidget.ui index 2a1a1467a..5d3df978f 100644 --- a/src/library/libraryfilterwidget.ui +++ b/src/library/libraryfilterwidget.ui @@ -17,13 +17,22 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 - <html><head/><body><p>Prefix a word with a field name to limit the search to that field, e.g. <span style=" font-weight:600;">artist:</span><span style=" font-style:italic;">Bode</span> searches the library for all artists that contain the word Bode.</p><p><span style=" font-weight:600;">Available fields: </span><span style=" font-style:italic;">%1</span>.</p></body></html> + <html><head/><body><p>Prefix a word with a field name to limit the search to that field, e.g. <span style=" font-weight:600;">artist:</span><span style=" font-style:italic;">Bode</span> searches the library for all artists that contain the word Bode, <span style=" font-weight:600;">playcount:</span><span style=" font-style:italic;">&gt;=2</span> searches the library for songs played at least twice, <span style=" font-weight:600;">lastplayed:</span>&lt;<span style=" font-style:italic;">1h30m</span> searches the library for songs played in the last 180 minutes.</p><p><span style=" font-weight:600;">Available fields: </span><span style=" font-style:italic;">%1</span>.</p></body></html> Enter search terms here @@ -99,14 +108,14 @@ - - Save current grouping - + + Save current grouping + - - Manage saved groupings - + + Manage saved groupings + diff --git a/src/library/libraryquery.cpp b/src/library/libraryquery.cpp index 8ceb366bc..45d22264c 100644 --- a/src/library/libraryquery.cpp +++ b/src/library/libraryquery.cpp @@ -105,6 +105,35 @@ LibraryQuery::LibraryQuery(const QueryOptions& options) } } 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; + } + } + } + } + if (seconds > 0) { + int now = QDateTime::currentDateTime().toTime_t(); + QString dt = QString("(%1-%2)").arg(now).arg(columntoken); + AddWhere(dt, seconds, op); + } } else { AddWhere(columntoken, val, op); }