## RhythmDBQueryModel RhythmDBQueryModel — a GtkTreeModel containing RhythmDBEntry items |

## Functions

RhythmDBQueryModel * | rhythmdb_query_model_new ()
RhythmDBQueryModel * | rhythmdb_query_model_new_empty ()
void | rhythmdb_query_model_copy_contents ()
void | rhythmdb_query_model_chain ()
void | rhythmdb_query_model_add_entry ()
gboolean | rhythmdb_query_model_remove_entry ()
void | rhythmdb_query_model_shuffle_entries ()
void | rhythmdb_query_model_move_entry ()
guint64 | rhythmdb_query_model_get_size ()
long | rhythmdb_query_model_get_duration ()
gboolean | rhythmdb_query_model_entry_to_iter ()
gboolean | rhythmdb_query_model_has_pending_changes ()
RhythmDBEntry * | rhythmdb_query_model_tree_path_to_entry ()
RhythmDBEntry * | rhythmdb_query_model_iter_to_entry ()
RhythmDBEntry * | rhythmdb_query_model_get_next_from_entry ()
RhythmDBEntry * | rhythmdb_query_model_get_previous_from_entry ()
char * | rhythmdb_query_model_compute_status_normal ()
void | rhythmdb_query_model_set_sort_order ()
void | rhythmdb_query_model_reapply_query ()
gint | rhythmdb_query_model_location_sort_func ()
gint | rhythmdb_query_model_string_sort_func ()
gint | rhythmdb_query_model_title_sort_func ()
gint | rhythmdb_query_model_album_sort_func ()
gint | rhythmdb_query_model_artist_sort_func ()
gint | rhythmdb_query_model_genre_sort_func ()
gint | rhythmdb_query_model_track_sort_func ()
gint | rhythmdb_query_model_double_ceiling_sort_func ()
gint | rhythmdb_query_model_ulong_sort_func ()
gint | rhythmdb_query_model_bitrate_sort_func ()
gint | rhythmdb_query_model_date_sort_func ()

## Properties

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

## Signals

void | complete | Run Last
void | entry-prop-changed | Run Last
void | entry-removed | Run Last
gboolean | filter-entry-drop | Run Last
void | non-entry-dropped | Run Last
void | post-entry-delete | Run Last

## Types and Values

enum | RhythmDBQueryModelLimitType
#define | RHYTHMDB_QUERY_MODEL_SUGGESTED_UPDATE_CHUNK
struct | RhythmDBQueryModel
struct | RhythmDBQueryModelClass

## Object Hierarchy

        GEnum
        ╰── RhythmDBQueryModelLimitType
        GObject
        ╰── RhythmDBQueryModel

## Implemented Interfaces

RhythmDBQueryModel implements RhythmDBQueryResults, GtkTreeModel, RbTreeDragSource and RbTreeDragDest.

## 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.

## Functions

### 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.

[skip]

#### 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.

#### Parameters

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` .

#### Parameters

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.

#### Parameters

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).

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

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.

#### Parameters

a | a RhythmDBEntry |
b | a RhythmDBEntry |
data | property to sort on |

#### Returns

result of sort comparison between a and b.

### rhythmdb_query_model_bitrate_sort_func ()

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

Sort function for sorting by bitrate. Lossless encodings (as identified by media type) are considered to have the highest possible bitrate. Falls back to sorting by location for equal bitrates.

#### Parameters

a | a RhythmDBEntry |
b | a RhythmDBEntry |
data | nothing |

#### 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.

#### Parameters

a | a RhythmDBEntry |
b | a RhythmDBEntry |
data | nothing |

#### Returns

result of sort comparison between a and b.

## Types and Values

### enum RhythmDBQueryModelLimitType

#### Members

RHYTHMDB_QUERY_MODEL_LIMIT_NONE |  |
RHYTHMDB_QUERY_MODEL_LIMIT_COUNT |  |
RHYTHMDB_QUERY_MODEL_LIMIT_SIZE |  |
RHYTHMDB_QUERY_MODEL_LIMIT_TIME |  |

### RHYTHMDB_QUERY_MODEL_SUGGESTED_UPDATE_CHUNK

    #define RHYTHMDB_QUERY_MODEL_SUGGESTED_UPDATE_CHUNK 1024

### 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);
    };

## Property Details

### The `“base-model”` property

      “base-model”               RhythmDBQueryModel *

base RhythmDBQueryModel.

Flags: Read / Write / Construct

### The `“db”` property

      “db”                       RhythmDB *

RhythmDB object.

Flags: Read / Write / Construct Only

### The `“limit-type”` property

      “limit-type”               RhythmDBQueryModelLimitType

type of limit.

Flags: Read / Write / Construct Only

Default value: RHYTHMDB_QUERY_MODEL_LIMIT_NONE

### The `“limit-value”` property

      “limit-value”              GVariant *

value of limit.

Flags: Read / Write / Construct Only

Allowed values: GVariant<t>

Default value: NULL

### The `“query”` property

      “query”                    gpointer

RhythmDBQuery.

Flags: Read / Write

### The `“show-hidden”` property

      “show-hidden”              gboolean

if TRUE, include entries that are ordinarily hidden.

Flags: Read / Write / Construct

Default value: FALSE

### The `“sort-data”` property

      “sort-data”                gpointer

Sort data.

Flags: Read / Write

### The `“sort-data-destroy”` property

      “sort-data-destroy”        gpointer

Sort data destroy function.

Flags: Read / Write

### The `“sort-func”` property

      “sort-func”                gpointer

Sort function.

Flags: Read / Write

### The `“sort-reverse”` property

      “sort-reverse”             gboolean

Reverse sort order flag.

Flags: Read / Write

Default value: FALSE

## Signal Details

### The `“complete”` signal

    void
    user_function (RhythmDBQueryModel *model,
                   gpointer            user_data)

Emitted when the database query populating the model is complete.

#### Parameters

model | the RhythmDBQueryModel |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“entry-prop-changed”` signal

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

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.

#### Parameters

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. |

Flags: Run Last

### The `“entry-removed”` signal

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

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.

#### Parameters

model | the RhythmDBQueryModel |
entry | the RhythmDBEntry that was removed |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“filter-entry-drop”` signal

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

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.

#### Parameters

model | the RhythmDBQueryModel |
entry | the RhythmDBEntry being dropped |
user_data | user data set when the signal handler was connected. |

Flags: Run Last

### The `“non-entry-dropped”` signal

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

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

#### Parameters

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. |

Flags: Run Last

### The `“post-entry-delete”` signal

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

Emitted after an entry has been removed from the model.

#### Parameters

model | the RhythmDBQueryModel |
entry | the RhythmDBEntry that was removed |
user_data | user data set when the signal handler was connected. |

Flags: Run Last