1
/*
2
 * Copyright 2008-2011 Various Authors
3
 * Copyright 2006 Timo Hirvonen
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as
7
 * published by the Free Software Foundation; either version 2 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
#ifndef EDITABLE_H
20
#define EDITABLE_H
21
22
#include "window.h"
23
#include "list.h"
24
#include "rbtree.h"
25
#include "track.h"
26
#include "locking.h"
27
28
struct editable {
29
	struct window *win;
30
	struct list_head head;
31
	struct rb_root tree_root;
32
	unsigned int nr_tracks;
33
	unsigned int nr_marked;
34
	unsigned int total_time;
35
	sort_key_t *sort_keys;
36
	char sort_str[128];
37
	struct searchable *searchable;
38
39
	void (*free_track)(struct list_head *item);
40
};
41
42
extern pthread_mutex_t editable_mutex;
43
44
void editable_init(struct editable *e, void (*free_track)(struct list_head *item));
45
void editable_add(struct editable *e, struct simple_track *track);
46
void editable_add_before(struct editable *e, struct simple_track *track);
47
void editable_remove_track(struct editable *e, struct simple_track *track);
48
void editable_remove_sel(struct editable *e);
49
void editable_sort(struct editable *e);
50
void editable_set_sort_keys(struct editable *e, sort_key_t *keys);
51
void editable_toggle_mark(struct editable *e);
52
void editable_move_after(struct editable *e);
53
void editable_move_before(struct editable *e);
54
void editable_clear(struct editable *e);
55
void editable_remove_matching_tracks(struct editable *e,
56
		int (*cb)(void *data, struct track_info *ti), void *data);
57
void editable_mark(struct editable *e, const char *filter);
58
void editable_unmark(struct editable *e);
59
void editable_invert_marks(struct editable *e);
60
int __editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct track_info *ti),
61
		void *data, int reverse);
62
int editable_for_each_sel(struct editable *e, int (*cb)(void *data, struct track_info *ti),
63
		void *data, int reverse);
64
void editable_update_track(struct editable *e, struct track_info *old, struct track_info *new);
65
66
static inline void editable_track_to_iter(struct editable *e, struct simple_track *track, struct iter *iter)
67
{
68
	iter->data0 = &e->head;
69
	iter->data1 = track;
70
	iter->data2 = NULL;
71
}
72
73
#define editable_lock() cmus_mutex_lock(&editable_mutex)
74
#define editable_unlock() cmus_mutex_unlock(&editable_mutex)
75
76
#endif