File: medialibview.cpp

package info (click to toggle)
esperanza 0.2.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 600 kB
  • ctags: 536
  • sloc: cpp: 4,533; sh: 63; makefile: 4
file content (79 lines) | stat: -rw-r--r-- 1,887 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "medialibview.h"
#include "medialibsearchmodel.h"
#include <QSettings>
#include <QHeaderView>

MedialibView::MedialibView (QWidget *parent, XClient *client) : QTreeView (parent)
{
	m_client = client;
	m_model = new MedialibSearchModel (this, client);
	setModel (m_model);

	setIndentation (0);
	setAlternatingRowColors (true);
	setItemsExpandable (false);
	setRootIsDecorated (false);

    setSelectionMode (QAbstractItemView::ExtendedSelection);
    setSelectionBehavior (QAbstractItemView::SelectRows);

    m_selections = new QItemSelectionModel (m_model);
	setSelectionModel (m_selections);

	QHeaderView *head = header ();
	QSettings s;

	head->resizeSection (0, s.value ("medialib/section0", 150).toInt ());
	head->resizeSection (1, s.value ("medialib/section1", 150).toInt ());
	connect (head, SIGNAL (sectionResized (int, int, int)), this, SLOT (head_size (int, int, int)));

	setIconSize (QSize (75, 75));

	connect (m_model, SIGNAL (searchDone ()), this, SLOT (search_done ()));

	connect (this, SIGNAL (doubleClicked (const QModelIndex &)),
			 this, SLOT (add_id (const QModelIndex &)));
}

void
MedialibView::head_size (int c, int o, int n)
{
	QSettings s;
	s.setValue (QString ("medialib/section%1").arg (c), n);
}

void
MedialibView::add_id (const QModelIndex &idx)
{
	uint32_t id = idx.data (MedialibSearchModel::MedialibIdRole).toUInt ();
	m_client->playlist.addId (id, &XClient::log);
}

void
MedialibView::search_done ()
{
	emit searchDone ();
}

QList<uint32_t>
MedialibView::get_selection ()
{
	QList<uint32_t> ret;

	QModelIndexList lst = m_selections->selectedIndexes ();
	for (int i = 0; i < lst.size (); i++) {
		QModelIndex idx = lst.at (i);
		if (idx.column () != 0)
			continue;

		ret.append (idx.data (MedialibSearchModel::MedialibIdRole).toUInt ());
	}

	return ret;
}

QList<uint32_t>
MedialibView::get_all ()
{
	return m_model->get_all_id ();
}