RhythmDBQueryModel

RhythmDBQueryModel — a GtkTreeModel containing RhythmDBEntry items

Synopsis

struct              RhythmDBQueryModel;
struct              RhythmDBQueryModelClass;
enum                RhythmDBQueryModelLimitType;
#define             RHYTHMDB_QUERY_MODEL_SUGGESTED_UPDATE_CHUNK
RhythmDBQueryModel * rhythmdb_query_model_new           (RhythmDB *db,
                                                         GPtrArray *query,
                                                         GCompareDataFunc sort_func,
                                                         gpointer sort_data,
                                                         GDestroyNotify sort_data_destroy,
                                                         gboolean sort_reverse);
RhythmDBQueryModel * rhythmdb_query_model_new_empty     (RhythmDB *db);
void                rhythmdb_query_model_copy_contents  (RhythmDBQueryModel *dest,
                                                         RhythmDBQueryModel *src);
void                rhythmdb_query_model_chain          (RhythmDBQueryModel *model,
                                                         RhythmDBQueryModel *base,
                                                         gboolean import_entries);
void                rhythmdb_query_model_add_entry      (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry,
                                                         gint index);
gboolean            rhythmdb_query_model_remove_entry   (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry);
void                rhythmdb_query_model_shuffle_entries
                                                        (RhythmDBQueryModel *model);
void                rhythmdb_query_model_move_entry     (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry,
                                                         gint index);
guint64             rhythmdb_query_model_get_size       (RhythmDBQueryModel *model);
long                rhythmdb_query_model_get_duration   (RhythmDBQueryModel *model);
gboolean            rhythmdb_query_model_entry_to_iter  (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry,
                                                         GtkTreeIter *iter);
gboolean            rhythmdb_query_model_has_pending_changes
                                                        (RhythmDBQueryModel *model);
RhythmDBEntry *     rhythmdb_query_model_tree_path_to_entry
                                                        (RhythmDBQueryModel *model,
                                                         GtkTreePath *path);
RhythmDBEntry *     rhythmdb_query_model_iter_to_entry  (RhythmDBQueryModel *model,
                                                         GtkTreeIter *entry_iter);
RhythmDBEntry *     rhythmdb_query_model_get_next_from_entry
                                                        (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry);
RhythmDBEntry *     rhythmdb_query_model_get_previous_from_entry
                                                        (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry);
char *              rhythmdb_query_model_compute_status_normal
                                                        (RhythmDBQueryModel *model,
                                                         const char *singular,
                                                         const char *plural);
void                rhythmdb_query_model_set_sort_order (RhythmDBQueryModel *model,
                                                         GCompareDataFunc sort_func,
                                                         gpointer sort_data,
                                                         GDestroyNotify sort_data_destroy,
                                                         gboolean sort_reverse);
void                rhythmdb_query_model_reapply_query  (RhythmDBQueryModel *model,
                                                         gboolean filter);
gint                rhythmdb_query_model_location_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);
gint                rhythmdb_query_model_string_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);
gint                rhythmdb_query_model_title_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);
gint                rhythmdb_query_model_album_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);
gint                rhythmdb_query_model_artist_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);
gint                rhythmdb_query_model_genre_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);
gint                rhythmdb_query_model_track_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);
gint                rhythmdb_query_model_double_ceiling_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);
gint                rhythmdb_query_model_ulong_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);
gint                rhythmdb_query_model_date_sort_func (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Object Hierarchy

  GObject
   +----RhythmDBQueryModel
  GEnum
   +----RhythmDBQueryModelLimitType

Implemented Interfaces

RhythmDBQueryModel implements RhythmDBQueryResults, GtkTreeModel, RbTreeDragSource and RbTreeDragDest.

Properties

  "base-model"               RhythmDBQueryModel*   : Read / Write / Construct
  "db"                       RhythmDB*             : Read / Write / Construct Only
  "limit-type"               RhythmDBQueryModelLimitType  : Read / Write / Construct Only
  "limit-value"              GArray*               : Read / Write / Construct Only
  "query"                    gpointer              : Read / Write
  "show-hidden"              gboolean              : Read / Write / Construct
  "sort-data"                gpointer              : Read / Write
  "sort-data-destroy"        gpointer              : Read / Write
  "sort-func"                gpointer              : Read / Write
  "sort-reverse"             gboolean              : Read / Write

Signals

  "complete"                                       : Run Last
  "entry-prop-changed"                             : Run Last
  "entry-removed"                                  : Run Last
  "filter-entry-drop"                              : Run Last
  "non-entry-dropped"                              : Run Last
  "post-entry-delete"                              : Run Last

Description

A RhythmDBQueryModel contains an ordered set of RhythmDBEntry items, either generated by running a query against the database, or populated by adding individual entries.

All sources use a RhythmDBQueryModel to provide their track listing. Since most sources provide a search or filtering capacity, there is usually a distinction between the source's base query model, which contains all entries for the source, and its current query model, which reflects the current search terms and filter selections.

A RhythmDBQueryModel can be populated directly from the RhythmDB, or it can be chained to another query model. Chained query models inherit the set of entries from the query model they chain to and then restrict the set using a query.

The query model consists of a GSequence, which provides ordering of entries, and a GHashTable, which allows efficient checks to see if a given entry is in the model. A side effect of this is that an entry can only be placed into a query model in one location.

In addition to the query, a RhythmDBQueryModel can have a sort order and a limit, specified in terms of file size, duration, or number of entries. A query model can only have a limit if it also has a sort order, as the sort order is required to determine which entries fall inside the limit. When a limit is applied, entries that match the query but fall outside the limit are maintained in a separate GSequence and GHashTable inside the query model.

Details

struct RhythmDBQueryModel

struct RhythmDBQueryModel;


struct RhythmDBQueryModelClass

struct RhythmDBQueryModelClass {
	GObjectClass parent;

	/* signals */
	void (*complete)		(RhythmDBQueryModel *model);
	void (*entry_prop_changed) (RhythmDBQueryModel *model,
					 RhythmDBEntry *entry,
					 RhythmDBPropType prop,
					 const GValue *old,
					 const GValue *new_value);
	void    (*non_entry_dropped)    (RhythmDBQueryModel *model,
					 const char *uri,
					 int position);
	void    (*entry_removed)        (RhythmDBQueryModel *model,
					 RhythmDBEntry *entry);
	void (*post_entry_delete) (RhythmDBQueryModel *model,
					 RhythmDBEntry *entry);
	gboolean (*filter_entry_drop) (RhythmDBQueryModel *model,
					 RhythmDBEntry *entry);
};


enum RhythmDBQueryModelLimitType

typedef enum {
	RHYTHMDB_QUERY_MODEL_LIMIT_NONE,
	RHYTHMDB_QUERY_MODEL_LIMIT_COUNT,
	RHYTHMDB_QUERY_MODEL_LIMIT_SIZE,
	RHYTHMDB_QUERY_MODEL_LIMIT_TIME,
} RhythmDBQueryModelLimitType;


RHYTHMDB_QUERY_MODEL_SUGGESTED_UPDATE_CHUNK

#define RHYTHMDB_QUERY_MODEL_SUGGESTED_UPDATE_CHUNK 1024


rhythmdb_query_model_new ()

RhythmDBQueryModel * rhythmdb_query_model_new           (RhythmDB *db,
                                                         GPtrArray *query,
                                                         GCompareDataFunc sort_func,
                                                         gpointer sort_data,
                                                         GDestroyNotify sort_data_destroy,
                                                         gboolean sort_reverse);

Constructs a new RhythmDBQueryModel with the specified query and sorting parameters.

db :

the RhythmDB

query :

the query for the new model

sort_func :

the sort function for the new model

sort_data :

data to pass to the sort function

sort_data_destroy :

function to call when destroying the sort data

sort_reverse :

if TRUE, reverse the sort order

Returns :

the newly constructed query model

rhythmdb_query_model_new_empty ()

RhythmDBQueryModel * rhythmdb_query_model_new_empty     (RhythmDB *db);

Constructs a new empty query model with no query or sorting parameters. This should only be used when the query model will be populated by explicitly adding entries.

db :

the RhythmDB

Returns :

the newly constructed query model

rhythmdb_query_model_copy_contents ()

void                rhythmdb_query_model_copy_contents  (RhythmDBQueryModel *dest,
                                                         RhythmDBQueryModel *src);

Copies all entries from src to dest.

dest :

destination RhythmDBQueryModel

src :

source RhythmDBQueryModel

rhythmdb_query_model_chain ()

void                rhythmdb_query_model_chain          (RhythmDBQueryModel *model,
                                                         RhythmDBQueryModel *base,
                                                         gboolean import_entries);

Chains model to base. All changes made to the base model will be reflected in the child model, and all changes made to the child model will be passed on to the base model.

model :

the RhythmDBQueryModel to chain

base :

the RhythmDBQueryModel to chain it to

import_entries :

if TRUE, copy all existing entries from base to model

rhythmdb_query_model_add_entry ()

void                rhythmdb_query_model_add_entry      (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry,
                                                         gint index);

Adds an entry to the query model at the specified position. Does not check if the entry matches the query (if any).

model :

a RhythmDBQueryModel

entry :

a RhythmDBEntry to add

index :

position at which to add it, or -1 to add at the end

rhythmdb_query_model_remove_entry ()

gboolean            rhythmdb_query_model_remove_entry   (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry);

Removes an entry from the query model.

model :

a RhythmDBQueryModel

entry :

the RhythmDBEntry to remove

Returns :

TRUE if the entry was removed

rhythmdb_query_model_shuffle_entries ()

void                rhythmdb_query_model_shuffle_entries
                                                        (RhythmDBQueryModel *model);

Shuffles the entries in the model into a new random order.

model :

a RhythmDBQueryModel

rhythmdb_query_model_move_entry ()

void                rhythmdb_query_model_move_entry     (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry,
                                                         gint index);

Moves an entry to a new position in the query model. The position must be a between 0 and the number of entries in the model. Specifying -1 does not move the entry to the end of the model.

model :

a RhythmDBQueryModel

entry :

the RhythmDBEntry to move

index :

position to move to

rhythmdb_query_model_get_size ()

guint64             rhythmdb_query_model_get_size       (RhythmDBQueryModel *model);

Returns the total size of all entries in the model.

model :

the RhythmDBQueryModel

Returns :

the total size (in bytes) of all entries in the model

rhythmdb_query_model_get_duration ()

long                rhythmdb_query_model_get_duration   (RhythmDBQueryModel *model);

Returns the total duration of all entries in the model.

model :

the RhythmDBQueryModel

Returns :

the total duration (in seconds) of all entries in the model

rhythmdb_query_model_entry_to_iter ()

gboolean            rhythmdb_query_model_entry_to_iter  (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry,
                                                         GtkTreeIter *iter);

Creates a GtkTreeIter pointing to the specified entry in the model.

model :

a RhythmDBQueryModel

entry :

the RhythmDBEntry to look up

iter :

holds the returned GtkTreeIter

Returns :

TRUE if the iterator now points to the entry

rhythmdb_query_model_has_pending_changes ()

gboolean            rhythmdb_query_model_has_pending_changes
                                                        (RhythmDBQueryModel *model);

Checks if a RhythmDBQueryModel has any outstanding changes that are yet to be processed. This is not very useful.

model :

a RhythmDBQueryModel

Returns :

TRUE if there are outstanding changes to the model

rhythmdb_query_model_tree_path_to_entry ()

RhythmDBEntry *     rhythmdb_query_model_tree_path_to_entry
                                                        (RhythmDBQueryModel *model,
                                                         GtkTreePath *path);

Locates the RhythmDBEntry identified by the specified path in the model. The caller owns a reference to the returned entry.

model :

a RhythmDBQueryModel

path :

a GtkTreePath

Returns :

the RhythmDBEntry, if any

rhythmdb_query_model_iter_to_entry ()

RhythmDBEntry *     rhythmdb_query_model_iter_to_entry  (RhythmDBQueryModel *model,
                                                         GtkTreeIter *entry_iter);

Locates and returns the RhythmDBEntry pointed to by the specified iterator in the model. The caller owns a reference to the returned entry.

model :

a RhythmDBQueryModel

entry_iter :

a GtkTreeIter to dereference

Returns :

the RhythmDBEntry, if any

rhythmdb_query_model_get_next_from_entry ()

RhythmDBEntry *     rhythmdb_query_model_get_next_from_entry
                                                        (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry);

Locates and returns the next RhythmDBEntry in the model after the specified entry. The caller owns a reference to the returned entry.

model :

a RhythmDBQueryModel

entry :

a RhythmDBEntry

Returns :

the next RhythmDBEntry in the model, if any

rhythmdb_query_model_get_previous_from_entry ()

RhythmDBEntry *     rhythmdb_query_model_get_previous_from_entry
                                                        (RhythmDBQueryModel *model,
                                                         RhythmDBEntry *entry);

Locates and returns the RhythmDBEntry in the model before the specified entry. The caller owns a reference to the returned entry.

model :

a RhythmDBQueryModel

entry :

a RhythmDBEntry

Returns :

the previous RhythmDBEntry in the model, if any

rhythmdb_query_model_compute_status_normal ()

char *              rhythmdb_query_model_compute_status_normal
                                                        (RhythmDBQueryModel *model,
                                                         const char *singular,
                                                         const char *plural);

Constructs a status string describing the contents of the model.

model :

a RhythmDBQueryModel

singular :

singular form of the pattern describing the number of entries ("d song")

plural :

plural form of the pattern describing the number of entries ("d songs")

Returns :

allocated status string, to be freed by the caller.

rhythmdb_query_model_set_sort_order ()

void                rhythmdb_query_model_set_sort_order (RhythmDBQueryModel *model,
                                                         GCompareDataFunc sort_func,
                                                         gpointer sort_data,
                                                         GDestroyNotify sort_data_destroy,
                                                         gboolean sort_reverse);

Sets a new sort order on the model. This reorders the entries in the model to match the new sort order.

model :

a RhythmDBQueryModel

sort_func :

new sort function

sort_data :

data to pass to the new sort function

sort_data_destroy :

function to call to free the sort data

sort_reverse :

if TRUE, reverse the sort order

rhythmdb_query_model_reapply_query ()

void                rhythmdb_query_model_reapply_query  (RhythmDBQueryModel *model,
                                                         gboolean filter);

Reapplies the existing query to the entries in the model. This is mostly useful when the query contains relative time criteria (such as 'not played in the last hour'). This will only remove entries that are already in the model, it will not find entries that previously did not match the query.

The 'filter' parameter should be set to TRUE when the query is being used as a filter, rather than to define a base set of entries.

model :

a RhythmDBQueryModel

filter :

if FALSE, emit entry-removed signals

rhythmdb_query_model_location_sort_func ()

gint                rhythmdb_query_model_location_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Sort function for sorting by location.

a :

a RhythmDBEntry

b :

a RhythmDBEntry

data :

nothing

Returns :

result of sort comparison between a and b.

rhythmdb_query_model_string_sort_func ()

gint                rhythmdb_query_model_string_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Sort function for sorting by a single string property Falls back to location sort order if the strings are equal.

a :

a RhythmDBEntry

b :

a RhythmDBEntry

data :

property to sort on

Returns :

result of sort comparison between a and b.

rhythmdb_query_model_title_sort_func ()

gint                rhythmdb_query_model_title_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Sort function for sorting by title. Falls back to sorting by location if the titles are the same.

a :

a RhythmDBEntry

b :

a RhythmDBEntry

data :

nothing

Returns :

result of sort comparison between a and b.

rhythmdb_query_model_album_sort_func ()

gint                rhythmdb_query_model_album_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Sort function for sorting by album. Sorts by album, then disc number, then track number, then title.

a :

a RhythmDBEntry

b :

a RhythmDBEntry

data :

nothing

Returns :

result of sort comparison between a and b.

rhythmdb_query_model_artist_sort_func ()

gint                rhythmdb_query_model_artist_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Sort function for sorting by artist. Sorts by artist, then album, then disc number, then track number, then title.

a :

a RhythmDBEntry

b :

a RhythmDBEntry

data :

nothing

Returns :

result of sort comparison between a and b.

rhythmdb_query_model_genre_sort_func ()

gint                rhythmdb_query_model_genre_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Sort function for sorting by genre. Sorts by genre, then artist, then album, then disc number, then track number, then title.

a :

a RhythmDBEntry

b :

a RhythmDBEntry

data :

nothing

Returns :

result of sort comparison between a and b.

rhythmdb_query_model_track_sort_func ()

gint                rhythmdb_query_model_track_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Sort function for sorting by track. Sorts by artist, then album, then disc number, then track number, then title.

a :

a RhythmDBEntry

b :

a RhythmDBEntry

data :

nothing

Returns :

result of sort comparison between a and b.

rhythmdb_query_model_double_ceiling_sort_func ()

gint                rhythmdb_query_model_double_ceiling_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Sort function for sorting by a rounded floating point value. The property value is rounded up to an integer value for sorting. If the values are the same, falls back to sorting by location.

a :

a RhythmDBEntry

b :

a RhythmDBEntry

data :

property to sort on

Returns :

result of sort comparison between a and b.

rhythmdb_query_model_ulong_sort_func ()

gint                rhythmdb_query_model_ulong_sort_func
                                                        (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Sort function for sorting by an unsigned integer property value. If the values are the same, falls back to sorting by location.

a :

a RhythmDBEntry

b :

a RhythmDBEntry

data :

property to sort on

Returns :

result of sort comparison between a and b.

rhythmdb_query_model_date_sort_func ()

gint                rhythmdb_query_model_date_sort_func (RhythmDBEntry *a,
                                                         RhythmDBEntry *b,
                                                         gpointer data);

Sort function for sorting by release date. Falls back to album sort order for equal dates.

a :

a RhythmDBEntry

b :

a RhythmDBEntry

data :

nothing

Returns :

result of sort comparison between a and b.

Property Details

The "base-model" property

  "base-model"               RhythmDBQueryModel*   : Read / Write / Construct

base RhythmDBQueryModel.


The "db" property

  "db"                       RhythmDB*             : Read / Write / Construct Only

RhythmDB object.


The "limit-type" property

  "limit-type"               RhythmDBQueryModelLimitType  : Read / Write / Construct Only

type of limit.

Default value: RHYTHMDB_QUERY_MODEL_LIMIT_NONE


The "limit-value" property

  "limit-value"              GArray*               : Read / Write / Construct Only

value of limit.


The "query" property

  "query"                    gpointer              : Read / Write

RhythmDBQuery.


The "show-hidden" property

  "show-hidden"              gboolean              : Read / Write / Construct

if TRUE, include entries that are ordinarily hidden.

Default value: FALSE


The "sort-data" property

  "sort-data"                gpointer              : Read / Write

Sort data.


The "sort-data-destroy" property

  "sort-data-destroy"        gpointer              : Read / Write

Sort data destroy function.


The "sort-func" property

  "sort-func"                gpointer              : Read / Write

Sort function.


The "sort-reverse" property

  "sort-reverse"             gboolean              : Read / Write

Reverse sort order flag.

Default value: FALSE

Signal Details

The "complete" signal

void                user_function                      (RhythmDBQueryModel *model,
                                                        gpointer            user_data)      : Run Last

Emitted when the database query populating the model is complete.

model :

the RhythmDBQueryModel

user_data :

user data set when the signal handler was connected.

The "entry-prop-changed" signal

void                user_function                      (RhythmDBQueryModel *model,
                                                        RhythmDBEntry      *entry,
                                                        gint                prop,
                                                        gpointer            old,
                                                        gpointer            new_value,
                                                        gpointer            user_data)      : Run Last

Emitted when an entry in the query model is changed. When multiple properties are changed, the entry-prop-changed signals will be emitted in the order that the changes were made. At the point that the signal is emitted, all changes have already been applied to the RhythmDBEntry.

model :

the RhythmDBQueryModel

entry :

the RhythmDBEntry that changed

prop :

the RhythmDBPropType that was changed

old :

the previous value for the property

new_value :

the new value for the property

user_data :

user data set when the signal handler was connected.

The "entry-removed" signal

void                user_function                      (RhythmDBQueryModel *model,
                                                        RhythmDBEntry      *entry,
                                                        gpointer            user_data)      : Run Last

Emitted when an entry is removed from the model. There is some difference between this and the GtkTreeModel row-removed signal but I don't know what it is right now.

model :

the RhythmDBQueryModel

entry :

the RhythmDBEntry that was removed

user_data :

user data set when the signal handler was connected.

The "filter-entry-drop" signal

gboolean            user_function                      (RhythmDBQueryModel *model,
                                                        RhythmDBEntry      *entry,
                                                        gpointer            user_data)      : Run Last

Emitted when an entry is being added to a model by drag-and-drop. This allows the owner of the model to filter out entries that should not be added to the model (based on entry type, for instance). If the signal handler returns FALSE, the entry will not be added.

model :

the RhythmDBQueryModel

entry :

the RhythmDBEntry being dropped

user_data :

user data set when the signal handler was connected.

The "non-entry-dropped" signal

void                user_function                      (RhythmDBQueryModel *model,
                                                        gchar              *uri,
                                                        gint                position,
                                                        gpointer            user_data)      : Run Last

Emitted when a URI that does not match an existing RhythmDBEntry is dropped into the query model.

model :

the RhythmDBQueryModel

uri :

the URI that was dropped

position :

the position in the query model at which it was dropped

user_data :

user data set when the signal handler was connected.

The "post-entry-delete" signal

void                user_function                      (RhythmDBQueryModel *model,
                                                        RhythmDBEntry      *entry,
                                                        gpointer            user_data)      : Run Last

Emitted after an entry has been removed from the model.

model :

the RhythmDBQueryModel

entry :

the RhythmDBEntry that was removed

user_data :

user data set when the signal handler was connected.