Add option to save current library grouping
- Adds saved groupings to the Group by menu - Currently missing a way to manage saved groupings - Saved groupings are in a new section of the config file as "GroupingName"->ByteArray serialization
This commit is contained in:
parent
d50cfd5293
commit
5c256f349a
|
@ -25,6 +25,7 @@
|
|||
#include "ui/settingsdialog.h"
|
||||
|
||||
#include <QActionGroup>
|
||||
#include <QInputDialog>
|
||||
#include <QKeyEvent>
|
||||
#include <QMenu>
|
||||
#include <QRegExp>
|
||||
|
@ -100,11 +101,14 @@ LibraryFilterWidget::LibraryFilterWidget(QWidget* parent)
|
|||
connect(group_by_group_, SIGNAL(triggered(QAction*)),
|
||||
SLOT(GroupByClicked(QAction*)));
|
||||
|
||||
connect(ui_->save_grouping, SIGNAL(triggered()), this, SLOT(SaveGroupBy()));
|
||||
|
||||
// Library config menu
|
||||
library_menu_ = new QMenu(tr("Display options"), this);
|
||||
library_menu_->setIcon(ui_->options->icon());
|
||||
library_menu_->addMenu(filter_age_menu_);
|
||||
library_menu_->addMenu(group_by_menu_);
|
||||
library_menu_->addAction(ui_->save_grouping);
|
||||
library_menu_->addSeparator();
|
||||
ui_->options->setMenu(library_menu_);
|
||||
|
||||
|
@ -139,6 +143,27 @@ QActionGroup* LibraryFilterWidget::CreateGroupByActions(QObject* parent) {
|
|||
LibraryModel::Grouping(LibraryModel::GroupBy_Genre,
|
||||
LibraryModel::GroupBy_Artist,
|
||||
LibraryModel::GroupBy_Album)));
|
||||
|
||||
QAction* sep1 = new QAction(parent);
|
||||
sep1->setSeparator(true);
|
||||
ret->addAction(sep1);
|
||||
|
||||
// read saved groupings
|
||||
QSettings s;
|
||||
s.beginGroup(LibraryModel::kSavedGroupingsSettingsGroup);
|
||||
QStringList saved = s.childKeys();
|
||||
for (int i = 0; i < saved.size(); ++i) {
|
||||
QByteArray bytes = s.value(saved.at(i)).toByteArray();
|
||||
QDataStream ds(&bytes, QIODevice::ReadOnly);
|
||||
LibraryModel::Grouping g;
|
||||
ds >> g;
|
||||
ret->addAction(CreateGroupByAction(saved.at(i), parent, g));
|
||||
}
|
||||
|
||||
QAction* sep2 = new QAction(parent);
|
||||
sep2->setSeparator(true);
|
||||
ret->addAction(sep2);
|
||||
|
||||
ret->addAction(CreateGroupByAction(tr("Advanced grouping..."), parent,
|
||||
LibraryModel::Grouping()));
|
||||
|
||||
|
@ -158,6 +183,14 @@ QAction* LibraryFilterWidget::CreateGroupByAction(
|
|||
return ret;
|
||||
}
|
||||
|
||||
void LibraryFilterWidget::SaveGroupBy() {
|
||||
QString text =
|
||||
QInputDialog::getText(this, tr("Grouping Name"), tr("Grouping name:"));
|
||||
if (!text.isEmpty() && model_) {
|
||||
model_->SaveGrouping(text);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryFilterWidget::FocusOnFilter(QKeyEvent* event) {
|
||||
ui_->filter->setFocus();
|
||||
QApplication::sendEvent(ui_->filter, event);
|
||||
|
|
|
@ -84,6 +84,7 @@ signals:
|
|||
private slots:
|
||||
void GroupingChanged(const LibraryModel::Grouping& g);
|
||||
void GroupByClicked(QAction* action);
|
||||
void SaveGroupBy();
|
||||
|
||||
void FilterTextChanged(const QString& text);
|
||||
void FilterDelayTimeout();
|
||||
|
|
|
@ -98,6 +98,11 @@
|
|||
<string>Added this month</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="save_grouping">
|
||||
<property name="text">
|
||||
<string>Save current grouping</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
@ -59,6 +59,7 @@ const char* LibraryModel::kSmartPlaylistsMimeType =
|
|||
"application/x-clementine-smart-playlist-generator";
|
||||
const char* LibraryModel::kSmartPlaylistsSettingsGroup =
|
||||
"SerialisedSmartPlaylists";
|
||||
const char* LibraryModel::kSavedGroupingsSettingsGroup = "SavedGroupings";
|
||||
const int LibraryModel::kSmartPlaylistsVersion = 4;
|
||||
const int LibraryModel::kPrettyCoverSize = 32;
|
||||
const qint64 LibraryModel::kIconCacheSize = 100000000; //~100MB
|
||||
|
@ -141,6 +142,18 @@ void LibraryModel::set_show_dividers(bool show_dividers) {
|
|||
}
|
||||
}
|
||||
|
||||
void LibraryModel::SaveGrouping(QString name) {
|
||||
qLog(Debug) << "Model, save to: " << name;
|
||||
|
||||
QByteArray buffer;
|
||||
QDataStream ds(&buffer, QIODevice::WriteOnly);
|
||||
ds << group_by_;
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSavedGroupingsSettingsGroup);
|
||||
s.setValue(name, buffer);
|
||||
}
|
||||
|
||||
void LibraryModel::Init(bool async) {
|
||||
if (async) {
|
||||
// Show a loading indicator in the model.
|
||||
|
@ -1490,3 +1503,19 @@ void LibraryModel::TotalSongCountUpdatedSlot(int count) {
|
|||
total_song_count_ = count;
|
||||
emit TotalSongCountUpdated(count);
|
||||
}
|
||||
|
||||
QDataStream& operator<<(QDataStream& s, const LibraryModel::Grouping& g) {
|
||||
s << quint32(g.first) << quint32(g.second) << quint32(g.third);
|
||||
return s;
|
||||
}
|
||||
|
||||
QDataStream& operator>>(QDataStream& s, LibraryModel::Grouping& g) {
|
||||
quint32 buf;
|
||||
s >> buf;
|
||||
g.first = LibraryModel::GroupBy(buf);
|
||||
s >> buf;
|
||||
g.second = LibraryModel::GroupBy(buf);
|
||||
s >> buf;
|
||||
g.third = LibraryModel::GroupBy(buf);
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ class LibraryModel : public SimpleTreeModel<LibraryItem> {
|
|||
static const char* kSmartPlaylistsMimeType;
|
||||
static const char* kSmartPlaylistsSettingsGroup;
|
||||
static const char* kSmartPlaylistsArray;
|
||||
static const char* kSavedGroupingsSettingsGroup;
|
||||
static const int kSmartPlaylistsVersion;
|
||||
static const int kPrettyCoverSize;
|
||||
static const qint64 kIconCacheSize;
|
||||
|
@ -161,6 +162,9 @@ class LibraryModel : public SimpleTreeModel<LibraryItem> {
|
|||
// Whether or not to show letters heading in the library view
|
||||
void set_show_dividers(bool show_dividers);
|
||||
|
||||
// Save the current grouping
|
||||
void SaveGrouping(QString name);
|
||||
|
||||
// Utility functions for manipulating text
|
||||
static QString TextOrUnknown(const QString& text);
|
||||
static QString PrettyYearAlbum(int year, const QString& album);
|
||||
|
@ -300,4 +304,7 @@ signals:
|
|||
|
||||
Q_DECLARE_METATYPE(LibraryModel::Grouping);
|
||||
|
||||
QDataStream& operator<<(QDataStream& s, const LibraryModel::Grouping& g);
|
||||
QDataStream& operator>>(QDataStream& s, LibraryModel::Grouping& g);
|
||||
|
||||
#endif // LIBRARYMODEL_H
|
||||
|
|
Loading…
Reference in New Issue