mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-02 04:16:47 +01:00
Option to group the library by file type
This commit is contained in:
parent
7ca3612bea
commit
a236861dfa
@ -97,6 +97,28 @@ QString Song::JoinSpec(const QString& table) {
|
|||||||
return Prepend(table + ".", kColumns).join(", ");
|
return Prepend(table + ".", kColumns).join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Song::TextForFiletype(FileType type) {
|
||||||
|
switch (type) {
|
||||||
|
case Song::Type_Asf: return QObject::tr("ASF");
|
||||||
|
case Song::Type_Flac: return QObject::tr("FLAC");
|
||||||
|
case Song::Type_Mp4: return QObject::tr("MP4");
|
||||||
|
case Song::Type_Mpc: return QObject::tr("MPC");
|
||||||
|
case Song::Type_Mpeg: return QObject::tr("MP3"); // Not technically correct
|
||||||
|
case Song::Type_OggFlac: return QObject::tr("Ogg FLAC");
|
||||||
|
case Song::Type_OggSpeex: return QObject::tr("Ogg Speex");
|
||||||
|
case Song::Type_OggVorbis: return QObject::tr("Ogg Vorbis");
|
||||||
|
case Song::Type_Aiff: return QObject::tr("AIFF");
|
||||||
|
case Song::Type_Wav: return QObject::tr("WAV");
|
||||||
|
case Song::Type_TrueAudio: return QObject::tr("TrueAudio");
|
||||||
|
|
||||||
|
case Song::Type_Stream: return QObject::tr("Stream");
|
||||||
|
|
||||||
|
case Song::Type_Unknown:
|
||||||
|
default:
|
||||||
|
return QObject::tr("Unknown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static TagLib::String QStringToTaglibString(const QString& s);
|
static TagLib::String QStringToTaglibString(const QString& s);
|
||||||
|
|
||||||
|
@ -117,6 +117,8 @@ class Song {
|
|||||||
|
|
||||||
Type_Stream = 99,
|
Type_Stream = 99,
|
||||||
};
|
};
|
||||||
|
static QString TextForFiletype(FileType type);
|
||||||
|
QString TextForFiletype() const { return TextForFiletype(filetype()); }
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
void Init(const QString& title, const QString& artist, const QString& album, int length);
|
void Init(const QString& title, const QString& artist, const QString& album, int length);
|
||||||
|
@ -31,9 +31,10 @@ GroupByDialog::GroupByDialog(QWidget *parent)
|
|||||||
mapping_.insert(Mapping(LibraryModel::GroupBy_Artist, 2));
|
mapping_.insert(Mapping(LibraryModel::GroupBy_Artist, 2));
|
||||||
mapping_.insert(Mapping(LibraryModel::GroupBy_AlbumArtist, 3));
|
mapping_.insert(Mapping(LibraryModel::GroupBy_AlbumArtist, 3));
|
||||||
mapping_.insert(Mapping(LibraryModel::GroupBy_Composer, 4));
|
mapping_.insert(Mapping(LibraryModel::GroupBy_Composer, 4));
|
||||||
mapping_.insert(Mapping(LibraryModel::GroupBy_Genre, 5));
|
mapping_.insert(Mapping(LibraryModel::GroupBy_FileType, 5));
|
||||||
mapping_.insert(Mapping(LibraryModel::GroupBy_Year, 6));
|
mapping_.insert(Mapping(LibraryModel::GroupBy_Genre, 6));
|
||||||
mapping_.insert(Mapping(LibraryModel::GroupBy_YearAlbum, 7));
|
mapping_.insert(Mapping(LibraryModel::GroupBy_Year, 7));
|
||||||
|
mapping_.insert(Mapping(LibraryModel::GroupBy_YearAlbum, 8));
|
||||||
|
|
||||||
connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
|
connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
|
||||||
SLOT(Reset()));
|
SLOT(Reset()));
|
||||||
|
@ -68,6 +68,11 @@
|
|||||||
<string>Composer</string>
|
<string>Composer</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>File type</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Genre</string>
|
<string>Genre</string>
|
||||||
@ -119,6 +124,11 @@
|
|||||||
<string>Composer</string>
|
<string>Composer</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>File type</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Genre</string>
|
<string>Genre</string>
|
||||||
@ -170,6 +180,11 @@
|
|||||||
<string>Composer</string>
|
<string>Composer</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>File type</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Genre</string>
|
<string>Genre</string>
|
||||||
|
@ -101,6 +101,7 @@ void LibraryModel::SongsDiscovered(const SongList& songs) {
|
|||||||
key = QString::number(qMax(0, song.year())); break;
|
key = QString::number(qMax(0, song.year())); break;
|
||||||
case GroupBy_YearAlbum:
|
case GroupBy_YearAlbum:
|
||||||
key = PrettyYearAlbum(qMax(0, song.year()), song.album()); break;
|
key = PrettyYearAlbum(qMax(0, song.year()), song.album()); break;
|
||||||
|
case GroupBy_FileType: key = song.filetype();
|
||||||
case GroupBy_None: Q_ASSERT(0); break;
|
case GroupBy_None: Q_ASSERT(0); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,6 +159,7 @@ QString LibraryModel::DividerKey(GroupBy type, LibraryItem* item) const {
|
|||||||
case GroupBy_Composer:
|
case GroupBy_Composer:
|
||||||
case GroupBy_Genre:
|
case GroupBy_Genre:
|
||||||
case GroupBy_AlbumArtist:
|
case GroupBy_AlbumArtist:
|
||||||
|
case GroupBy_FileType:
|
||||||
if (item->sort_text[0].isDigit())
|
if (item->sort_text[0].isDigit())
|
||||||
return "0";
|
return "0";
|
||||||
if (item->sort_text[0] == ' ')
|
if (item->sort_text[0] == ' ')
|
||||||
@ -171,10 +173,11 @@ QString LibraryModel::DividerKey(GroupBy type, LibraryItem* item) const {
|
|||||||
return SortTextForYear(item->metadata.year());
|
return SortTextForYear(item->metadata.year());
|
||||||
|
|
||||||
case GroupBy_None:
|
case GroupBy_None:
|
||||||
default:
|
// fallthrough
|
||||||
|
;
|
||||||
|
}
|
||||||
Q_ASSERT(0);
|
Q_ASSERT(0);
|
||||||
return QString();
|
return QString();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LibraryModel::DividerDisplayText(GroupBy type, const QString& key) const {
|
QString LibraryModel::DividerDisplayText(GroupBy type, const QString& key) const {
|
||||||
@ -186,6 +189,7 @@ QString LibraryModel::DividerDisplayText(GroupBy type, const QString& key) const
|
|||||||
case GroupBy_Composer:
|
case GroupBy_Composer:
|
||||||
case GroupBy_Genre:
|
case GroupBy_Genre:
|
||||||
case GroupBy_AlbumArtist:
|
case GroupBy_AlbumArtist:
|
||||||
|
case GroupBy_FileType:
|
||||||
if (key == "0")
|
if (key == "0")
|
||||||
return "0-9";
|
return "0-9";
|
||||||
return key.toUpper();
|
return key.toUpper();
|
||||||
@ -201,10 +205,11 @@ QString LibraryModel::DividerDisplayText(GroupBy type, const QString& key) const
|
|||||||
return QString::number(key.toInt()); // To remove leading 0s
|
return QString::number(key.toInt()); // To remove leading 0s
|
||||||
|
|
||||||
case GroupBy_None:
|
case GroupBy_None:
|
||||||
default:
|
// fallthrough
|
||||||
|
;
|
||||||
|
}
|
||||||
Q_ASSERT(0);
|
Q_ASSERT(0);
|
||||||
return QString();
|
return QString();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryModel::SongsDeleted(const SongList& songs) {
|
void LibraryModel::SongsDeleted(const SongList& songs) {
|
||||||
@ -433,6 +438,9 @@ void LibraryModel::InitQuery(GroupBy type, LibraryQuery* q) {
|
|||||||
case GroupBy_None:
|
case GroupBy_None:
|
||||||
q->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec);
|
q->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec);
|
||||||
break;
|
break;
|
||||||
|
case GroupBy_FileType:
|
||||||
|
q->SetColumnSpec("DISTINCT filetype");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,6 +477,9 @@ void LibraryModel::FilterQuery(GroupBy type, LibraryItem* item, LibraryQuery* q)
|
|||||||
case GroupBy_AlbumArtist:
|
case GroupBy_AlbumArtist:
|
||||||
q->AddWhere("albumartist", item->key);
|
q->AddWhere("albumartist", item->key);
|
||||||
break;
|
break;
|
||||||
|
case GroupBy_FileType:
|
||||||
|
q->AddWhere("filetype", item->metadata.filetype());
|
||||||
|
break;
|
||||||
case GroupBy_None:
|
case GroupBy_None:
|
||||||
Q_ASSERT(0);
|
Q_ASSERT(0);
|
||||||
break;
|
break;
|
||||||
@ -528,6 +539,11 @@ LibraryItem* LibraryModel::ItemFromQuery(GroupBy type,
|
|||||||
item->sort_text = SortTextForArtist(item->key);
|
item->sort_text = SortTextForArtist(item->key);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GroupBy_FileType:
|
||||||
|
item->metadata.set_filetype(Song::FileType(q.Value(0).toInt()));
|
||||||
|
item->key = item->metadata.TextForFiletype();
|
||||||
|
break;
|
||||||
|
|
||||||
case GroupBy_None:
|
case GroupBy_None:
|
||||||
item->metadata.InitFromQuery(q);
|
item->metadata.InitFromQuery(q);
|
||||||
item->key = item->metadata.title();
|
item->key = item->metadata.title();
|
||||||
@ -576,6 +592,11 @@ LibraryItem* LibraryModel::ItemFromSong(GroupBy type,
|
|||||||
item->sort_text = SortTextForArtist(item->key);
|
item->sort_text = SortTextForArtist(item->key);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GroupBy_FileType:
|
||||||
|
item->metadata.set_filetype(s.filetype());
|
||||||
|
item->key = s.TextForFiletype();
|
||||||
|
break;
|
||||||
|
|
||||||
case GroupBy_None:
|
case GroupBy_None:
|
||||||
item->metadata = s;
|
item->metadata = s;
|
||||||
item->key = s.title();
|
item->key = s.title();
|
||||||
|
@ -61,6 +61,7 @@ class LibraryModel : public SimpleTreeModel<LibraryItem> {
|
|||||||
GroupBy_Composer = 5,
|
GroupBy_Composer = 5,
|
||||||
GroupBy_Genre = 6,
|
GroupBy_Genre = 6,
|
||||||
GroupBy_AlbumArtist = 7,
|
GroupBy_AlbumArtist = 7,
|
||||||
|
GroupBy_FileType = 8,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Grouping {
|
struct Grouping {
|
||||||
|
@ -262,25 +262,7 @@ QString FileTypeItemDelegate::displayText(const QVariant &value, const QLocale &
|
|||||||
if (!ok)
|
if (!ok)
|
||||||
return tr("Unknown");
|
return tr("Unknown");
|
||||||
|
|
||||||
switch (type) {
|
return Song::TextForFiletype(type);
|
||||||
case Song::Type_Asf: return tr("ASF");
|
|
||||||
case Song::Type_Flac: return tr("FLAC");
|
|
||||||
case Song::Type_Mp4: return tr("MP4");
|
|
||||||
case Song::Type_Mpc: return tr("MPC");
|
|
||||||
case Song::Type_Mpeg: return tr("MP3"); // Not technically correct
|
|
||||||
case Song::Type_OggFlac: return tr("Ogg FLAC");
|
|
||||||
case Song::Type_OggSpeex: return tr("Ogg Speex");
|
|
||||||
case Song::Type_OggVorbis: return tr("Ogg Vorbis");
|
|
||||||
case Song::Type_Aiff: return tr("AIFF");
|
|
||||||
case Song::Type_Wav: return tr("WAV");
|
|
||||||
case Song::Type_TrueAudio: return tr("TrueAudio");
|
|
||||||
|
|
||||||
case Song::Type_Stream: return tr("Stream");
|
|
||||||
|
|
||||||
case Song::Type_Unknown:
|
|
||||||
default:
|
|
||||||
return tr("Unknown");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* TextItemDelegate::createEditor(
|
QWidget* TextItemDelegate::createEditor(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user