ocarina/include/gui/model.h

100 lines
2.4 KiB
C

/*
* Copyright 2016 (c) Anna Schumaker.
*/
#ifndef OCARINA_GUI_MODEL_H
#define OCARINA_GUI_MODEL_H
#include <core/playlist.h>
#include <gui/builder.h>
#include <gtk/gtk.h>
#define GUI_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
gui_model_get_type(), GuiModel))
enum gui_model_columns {
GUI_MODEL_TRACK_NR,
GUI_MODEL_TITLE,
GUI_MODEL_LENGTH,
GUI_MODEL_ARTIST,
GUI_MODEL_ALBUM,
GUI_MODEL_YEAR,
GUI_MODEL_GENRE,
GUI_MODEL_COUNT,
GUI_MODEL_LAST_PLAY,
GUI_MODEL_FILE_PATH,
GUI_MODEL_FONT,
GUI_MODEL_N_COLUMNS,
};
struct gui_model {
GObject gm_parent; /* This MUST be the first member. */
gint gm_stamp; /* This is used to check iter validity. */
};
typedef struct gui_model GuiModel;
struct gui_model_class {
GObjectClass parent_class;
};
typedef struct gui_model_class GuiModelClass;
struct gui_model_drag_data {
unsigned int drag_row;
struct track *drag_track;
};
#define GUI_DRAG_DATA "GUI_DRAG_DATA"
extern const GtkTargetEntry gui_model_drag_targets[];
extern const unsigned int gui_model_n_targets;
/* Called to initialize the GuiModel */
void gui_model_init(void);
/* Called to deinitialize the GuiModel */
void gui_model_deinit(void);
/* Called to get the GuiModel */
GuiModel *gui_model_get(void);
/* Called to find the GType of the GuiModel */
GType gui_model_get_type();
/* Called to add a row to the model */
void gui_model_add(struct playlist *, struct track *);
/* Called to remove a row from the model */
void gui_model_remove(struct playlist *, struct track *, unsigned int);
/*
* Called to update a row in the model
* If track is NULL, then all rows will be updated
*/
void gui_model_update(struct playlist *, struct track *);
/* Called to change the queue represented by the model. */
void gui_model_set_playlist(struct playlist *);
/* Called to get the queue currently attached to the model. */
struct playlist *gui_model_get_playlist(void);
/* Called to convert a GtkTreeIter into a struct track */
static inline struct track *gui_model_iter_get_track(GtkTreeIter *iter)
{
g_return_val_if_fail(iter != NULL, NULL);
g_return_val_if_fail(iter->user_data != NULL, NULL);
return playlist_iter_track(iter->user_data);
}
/* Called to convert a GtkTreePath into a struct track */
struct track *gui_model_path_get_track(GtkTreePath *);
/* Called to get the runtime label. */
static inline GtkLabel *gui_model_runtime()
{
return GTK_LABEL(gui_builder_widget("runtime"));
}
#endif /* OCARINA_GUI_MODEL_H */