2010-04-01 01:11:45 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-04-01 01:11:45 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "groupbydialog.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "ui_groupbydialog.h"
|
2010-04-01 01:11:45 +02:00
|
|
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
2014-02-06 17:44:29 +01:00
|
|
|
// boost::multi_index still relies on these being in the global namespace.
|
|
|
|
using std::placeholders::_1;
|
|
|
|
using std::placeholders::_2;
|
|
|
|
|
|
|
|
#include <boost/multi_index_container.hpp>
|
|
|
|
#include <boost/multi_index/member.hpp>
|
|
|
|
#include <boost/multi_index/ordered_index.hpp>
|
|
|
|
|
|
|
|
using boost::multi_index_container;
|
|
|
|
using boost::multi_index::indexed_by;
|
|
|
|
using boost::multi_index::ordered_unique;
|
|
|
|
using boost::multi_index::tag;
|
|
|
|
using boost::multi_index::member;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct Mapping {
|
|
|
|
Mapping(LibraryModel::GroupBy g, int i) : group_by(g), combo_box_index(i) {}
|
|
|
|
|
|
|
|
LibraryModel::GroupBy group_by;
|
|
|
|
int combo_box_index;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tag_index {};
|
|
|
|
struct tag_group_by {};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class GroupByDialogPrivate {
|
|
|
|
private:
|
|
|
|
typedef multi_index_container<
|
2014-02-07 16:34:20 +01:00
|
|
|
Mapping,
|
|
|
|
indexed_by<
|
|
|
|
ordered_unique<tag<tag_index>,
|
|
|
|
member<Mapping, int, &Mapping::combo_box_index> >,
|
|
|
|
ordered_unique<tag<tag_group_by>,
|
|
|
|
member<Mapping, LibraryModel::GroupBy,
|
|
|
|
&Mapping::group_by> > > > MappingContainer;
|
2014-02-06 17:44:29 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
MappingContainer mapping_;
|
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
GroupByDialog::GroupByDialog(QWidget* parent)
|
|
|
|
: QDialog(parent), ui_(new Ui_GroupByDialog), p_(new GroupByDialogPrivate) {
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->setupUi(this);
|
2010-04-01 01:11:45 +02:00
|
|
|
Reset();
|
|
|
|
|
2014-02-06 17:44:29 +01:00
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_None, 0));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_Album, 1));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_Artist, 2));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_AlbumArtist, 3));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_Composer, 4));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_FileType, 5));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_Genre, 6));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_Year, 7));
|
2015-06-30 18:34:34 +02:00
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_OriginalYear, 8));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_YearAlbum, 9));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_OriginalYearAlbum, 10));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_Bitrate, 11));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_Disc, 12));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_Performer, 13));
|
|
|
|
p_->mapping_.insert(Mapping(LibraryModel::GroupBy_Grouping, 14));
|
2010-04-01 01:11:45 +02:00
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()),
|
2010-04-01 01:11:45 +02:00
|
|
|
SLOT(Reset()));
|
2010-05-17 02:47:43 +02:00
|
|
|
|
|
|
|
resize(sizeHint());
|
2010-04-01 01:11:45 +02:00
|
|
|
}
|
|
|
|
|
2014-02-06 17:44:29 +01:00
|
|
|
GroupByDialog::~GroupByDialog() {}
|
2010-05-10 23:50:31 +02:00
|
|
|
|
2010-04-01 01:11:45 +02:00
|
|
|
void GroupByDialog::Reset() {
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->first->setCurrentIndex(2); // Artist
|
|
|
|
ui_->second->setCurrentIndex(1); // Album
|
|
|
|
ui_->third->setCurrentIndex(0); // None
|
2010-04-01 01:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupByDialog::accept() {
|
2010-05-09 02:10:26 +02:00
|
|
|
emit Accepted(LibraryModel::Grouping(
|
2014-02-06 17:44:29 +01:00
|
|
|
p_->mapping_.get<tag_index>().find(ui_->first->currentIndex())->group_by,
|
|
|
|
p_->mapping_.get<tag_index>().find(ui_->second->currentIndex())->group_by,
|
2014-02-07 16:34:20 +01:00
|
|
|
p_->mapping_.get<tag_index>()
|
|
|
|
.find(ui_->third->currentIndex())
|
|
|
|
->group_by));
|
2010-04-01 01:11:45 +02:00
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
2010-05-09 02:10:26 +02:00
|
|
|
void GroupByDialog::LibraryGroupingChanged(const LibraryModel::Grouping& g) {
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->first->setCurrentIndex(
|
|
|
|
p_->mapping_.get<tag_group_by>().find(g[0])->combo_box_index);
|
|
|
|
ui_->second->setCurrentIndex(
|
|
|
|
p_->mapping_.get<tag_group_by>().find(g[1])->combo_box_index);
|
|
|
|
ui_->third->setCurrentIndex(
|
|
|
|
p_->mapping_.get<tag_group_by>().find(g[2])->combo_box_index);
|
2010-04-01 01:11:45 +02:00
|
|
|
}
|