mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-02 12:26:48 +01:00
Date columns for use in library search queries. (#6135)
* Mention numeric columns in tooltip * Add date filters in search queries * Show filter usage in tooltip * Fix code formatting
This commit is contained in:
parent
68d473cfb1
commit
a65dabcf0a
@ -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(", ");
|
||||
|
@ -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;
|
||||
|
@ -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()));
|
||||
|
@ -17,13 +17,22 @@
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QSearchField" name="filter" native="true">
|
||||
<property name="toolTip">
|
||||
<string><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></string>
|
||||
<string><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></string>
|
||||
</property>
|
||||
<property name="placeholderText" stdset="0">
|
||||
<string>Enter search terms here</string>
|
||||
@ -99,14 +108,14 @@
|
||||
</property>
|
||||
</action>
|
||||
<action name="save_grouping">
|
||||
<property name="text">
|
||||
<string>Save current grouping</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save current grouping</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="manage_groupings">
|
||||
<property name="text">
|
||||
<string>Manage saved groupings</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Manage saved groupings</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user