Example #1
0
void library_view_destroy(library_view_t* view)
{
  // first store the column widths
  playlist_column_enum e;
  for(e = PLAYLIST_MODEL_COL_NR; e < PLAYLIST_MODEL_N_COLUMNS; ++e) {
    char path [500];
    sprintf(path, "library.column.%s.width", column_id(e));
    int w = gtk_tree_view_column_get_width(view->cols[e]);
    log_debug3("%s = %d", path, w);
    el_config_set_int(btb_config(view->btb), path, w);
    g_object_unref(view->cols[e]);
  }
  mc_free(view->cols);
  
  if (view->run_timeout) {
    log_error("timeout has not been stopped before destroying!");
    library_view_stop_info_updater(view);
  }
  
  playlist_model_destroy(view->playlist_model);
  string_model_destroy(view->genre_model);
  string_model_destroy(view->artist_model);
  string_model_destroy(view->album_model);
  playlists_model_destroy(view->playlists_model);
  
  if (view->current_lyric_track_id != NULL) { 
    mc_free(view->current_lyric_track_id);
  }
  
  mc_free(view);
}
Example #2
0
/// Type-checked version of column_text.
///
/// \param name The name of the column to retrieve.
///
/// \return The same as column_text if the value can be retrieved.
///
/// \throw error If the type of the cell to retrieve is invalid.
/// \throw invalid_column_error If name is invalid.
std::string
sqlite::statement::safe_column_text(const char* name)
{
    const int column = column_id(name);
    if (column_type(column) != sqlite::type_text)
        throw sqlite::error(F("Column '%s' is not a string") % name);
    return column_text(column);
}
Example #3
0
/// Type-checked version of column_int64.
///
/// \param name The name of the column to retrieve.
///
/// \return The same as column_int64 if the value can be retrieved.
///
/// \throw error If the type of the cell to retrieve is invalid.
/// \throw invalid_column_error If name is invalid.
int64_t
sqlite::statement::safe_column_int64(const char* name)
{
    const int column = column_id(name);
    if (column_type(column) != sqlite::type_integer)
        throw sqlite::error(F("Column '%s' is not an integer") % name);
    return column_int64(column);
}
Example #4
0
/// Type-checked version of column_double.
///
/// \param name The name of the column to retrieve.
///
/// \return The same as column_double if the value can be retrieved.
///
/// \throw error If the type of the cell to retrieve is invalid.
/// \throw invalid_column_error If name is invalid.
double
sqlite::statement::safe_column_double(const char* name)
{
    const int column = column_id(name);
    if (column_type(column) != sqlite::type_float)
        throw sqlite::error(F("Column '%s' is not a float") % name);
    return column_double(column);
}
Example #5
0
/// Type-checked version of column_blob.
///
/// \param name The name of the column to retrieve.
///
/// \return The same as column_blob if the value can be retrieved.
///
/// \throw error If the type of the cell to retrieve is invalid.
/// \throw invalid_column_error If name is invalid.
sqlite::blob
sqlite::statement::safe_column_blob(const char* name)
{
    const int column = column_id(name);
    if (column_type(column) != sqlite::type_blob)
        throw sqlite::error(F("Column '%s' is not a blob") % name);
    return column_blob(column);
}
Example #6
0
/// Type-checked version of column_int.
///
/// \param name The name of the column to retrieve.
///
/// \return The same as column_int if the value can be retrieved.
///
/// \throw error If the type of the cell to retrieve is invalid.
/// \throw invalid_column_error If name is invalid.
int
sqlite::statement::safe_column_int(const char* name)
{
    const int column = column_id(name);
    if (column_type(column) != sqlite::type_integer)
        throw sqlite::error(_pimpl->db.db_filename(),
                            F("Column '%s' is not an integer") % name);
    return column_int(column);
}
Example #7
0
/// Type-checked version of column_bytes.
///
/// \param name The name of the column to retrieve the size of.
///
/// \return The same as column_bytes if the value can be retrieved.
///
/// \throw error If the type of the cell to retrieve the size of is invalid.
/// \throw invalid_column_error If name is invalid.
int
sqlite::statement::safe_column_bytes(const char* name)
{
    const int column = column_id(name);
    if (column_type(column) != sqlite::type_blob &&
        column_type(column) != sqlite::type_text)
        throw sqlite::error(_pimpl->db.db_filename(),
                            F("Column '%s' is not a blob or a string") % name);
    return column_bytes(column);
}
Example #8
0
static void library_view_col_width_set(GtkTreeViewColumn* col, GParamSpec* spec, library_view_t* view)
{
  //log_debug2("changing %d", view->column_layout_changing);
  if (view->column_layout_changing) {
    return;
  }

  long long hash = playlist_model_tracks_hash(view->playlist_model);

  int i;
  const char* name = g_object_get_data(G_OBJECT(col), "column_id"); 
  for(i = 0; strcmp(name, column_id(i)) != 0; ++i);
  //log_debug4("i = %d, name = %s, colid = %s", i, name, column_id(i));
  
  if (column_id(i) != NULL) {
    char cfgitem[200];
    sprintf(cfgitem,"library.cols.hash_%lld.%s.width", hash, column_id(i));
    int width = gtk_tree_view_column_get_width(view->cols[i]);
    
    el_config_set_int(btb_config(view->btb), cfgitem, width);
  }
}
Example #9
0
void library_view_init(library_view_t* view)
{
  // library view.
  GObject* object = gtk_builder_get_object(view->builder,"view_library");
  g_object_set_data(object, "library_view_t", (gpointer) view);
  
  // playlists (initially not viewed)
  //GtkWidget* scw_playlists = GTK_WIDGET(gtk_builder_get_object(view->builder,"scw_playlists"));
  //gtk_widget_hide(scw_playlists);

  // library list
  GtkTreeView* tview = GTK_TREE_VIEW(gtk_builder_get_object(view->builder, "tv_library"));
  view->tview = tview;
  GtkTreeViewColumn *col;
  GtkCellRenderer* renderer;
  
  renderer = gtk_cell_renderer_text_new();
  
  view->cols = (GtkTreeViewColumn**) mc_malloc(sizeof(GtkTreeViewColumn*) * PLAYLIST_MODEL_N_COLUMNS);
  playlist_column_enum e;
  for(e = PLAYLIST_MODEL_COL_NR; e < PLAYLIST_MODEL_N_COLUMNS; ++e) {
    col = gtk_tree_view_column_new_with_attributes(i18n_column_name(e), renderer, "text", e, NULL);
    gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
    char path [500];
    sprintf(path, "library.column.%s.width", column_id(e));
    int width = el_config_get_int(btb_config(view->btb), path, 100);
    if (width < 10) { width = 100; }
    g_object_set_data(G_OBJECT(col), "column_id", (gpointer) column_id(e));
    gtk_tree_view_column_set_fixed_width(col, width);
    gtk_tree_view_column_set_reorderable(col, TRUE);
    gtk_tree_view_column_set_resizable(col, TRUE);
    gtk_tree_view_column_set_clickable(col, TRUE);
    g_signal_connect(col, "clicked", (GCallback) library_view_library_col_sort, view);
    g_signal_connect (col, "notify::width", G_CALLBACK (library_view_col_width_set), view);
    view->cols[e] = col;
    g_object_ref(view->cols[e]);
    gtk_tree_view_append_column(tview, col);
  }
  
  gtk_tree_view_set_model(tview, GTK_TREE_MODEL(playlist_model_gtk_model(view->playlist_model)));
  
  // Aspect lists
  int width;
  
  // Genres
  tview = GTK_TREE_VIEW(gtk_builder_get_object(view->builder, "tv_genre_aspect"));
  col = gtk_tree_view_column_new_with_attributes(_("Genre"), renderer, "text", 0, NULL);
  gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
  //width = el_config_get_int(btb_config(view->btb), "library.aspects.column_width", 200);
  //gtk_tree_view_column_set_fixed_width(col, width);
  gtk_tree_view_append_column(tview, col);
  gtk_tree_view_set_model(tview, string_model_gtk_model(view->genre_model));
  
  // Artists
  tview = GTK_TREE_VIEW(gtk_builder_get_object(view->builder, "tv_artist_aspect"));
  col = gtk_tree_view_column_new_with_attributes(_("Artists"), renderer, "text", 0, NULL);
  gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
  //width = el_config_get_int(btb_config(view->btb), "library.aspects.column_width", 200);
  //gtk_tree_view_column_set_fixed_width(col, width);
  gtk_tree_view_append_column(tview, col);
  gtk_tree_view_set_model(tview, string_model_gtk_model(view->artist_model));
  
  // Albums
  tview = GTK_TREE_VIEW(gtk_builder_get_object(view->builder, "tv_album_aspect"));
  col = gtk_tree_view_column_new_with_attributes(_("Artists"), renderer, "text", 0, NULL);
  gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
  //width = el_config_get_int(btb_config(view->btb), "library.aspects.column_width", 200);
  //gtk_tree_view_column_set_fixed_width(col, width);
  gtk_tree_view_append_column(tview, col);
  gtk_tree_view_set_model(tview, string_model_gtk_model(view->album_model));
  
  // Activate genres
  library_view_aspect_page(view, GENRE_ASPECT);
  GtkToggleToolButton* g_btn = GTK_TOGGLE_TOOL_BUTTON(gtk_builder_get_object(view->builder, "tbtn_genres"));
  gtk_toggle_tool_button_set_active(g_btn, TRUE);
  
  // playback scale, song info
  GtkScale* sc_playback = GTK_SCALE(gtk_builder_get_object(view->builder, "sc_library_playback"));
  gtk_range_set_range(GTK_RANGE(sc_playback), 0.0, 100.0);
  { 
    char ss[300];
    sprintf(ss,"<span size=\"x-small\"><i><b> </b></i></span>");
    GtkLabel* lbl = GTK_LABEL(gtk_builder_get_object(view->builder, "lbl_song_info"));
    gtk_label_set_markup(lbl, ss);
  }
  
  // Set logo
  {
    char *path = backtobasics_logo(view->btb); 
    file_info_t* info = file_info_new(path);
    mc_free(path);
    if (file_info_is_file(info)) {
      GError *err = NULL;
      GdkPixbuf* pb = gdk_pixbuf_new_from_file_at_scale(file_info_path(info),
                                                        view->img_w, view->img_h,
                                                        TRUE,
                                                        &err
                                                        );
      GtkImage* img = GTK_IMAGE(gtk_builder_get_object(view->builder, "img_art"));
      gtk_widget_set_size_request(GTK_WIDGET(img), view->img_w, view->img_h);
      if (pb != NULL) {
        gtk_image_set_from_pixbuf(img, pb);
        g_object_unref(pb);
      } else {
        log_error3("error loading image art: %d, %s", err->code, err->message);
        //g_free(err);
      }
    }
    file_info_destroy(info);
  }
  
  // Playlists
  tview = GTK_TREE_VIEW(gtk_builder_get_object(view->builder, "tv_playlists"));
  col = gtk_tree_view_column_new_with_attributes(_("Playlist"), renderer, "text", 0, NULL);
  gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
  width = el_config_get_int(btb_config(view->btb), "library.playlists.column_width", 200);
  gtk_tree_view_column_set_fixed_width(col, width);
  gtk_tree_view_append_column(tview, col);
  
  gtk_tree_view_set_model(tview, playlists_model_gtk_model(view->playlists_model));
  
  // Lyric view
  view->lyric_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
  view->lbl_lyric_track = GTK_LABEL(gtk_builder_get_object(view->builder, "lbl_lyric_track"));
  GtkScrolledWindow* scw_lyric = GTK_SCROLLED_WINDOW(gtk_builder_get_object(view->builder, "scw_lyric"));
  gtk_container_add(GTK_CONTAINER(scw_lyric), GTK_WIDGET(view->lyric_view));
  
  // visibility of columns
  {
    const char* names[] = {
      "chk_col_nr", "chk_col_title", "chk_col_artist", "chk_col_composer",
      "chk_col_piece", "chk_col_album", "chk_col_albumartist", "chk_col_genre",
      "chk_col_year", "chk_col_length", NULL
    };
    
    const playlist_column_enum es[] = {
      PLAYLIST_MODEL_COL_NR, PLAYLIST_MODEL_COL_TITLE, PLAYLIST_MODEL_COL_ARTIST,
      PLAYLIST_MODEL_COL_COMPOSER, PLAYLIST_MODEL_COL_PIECE, 
      PLAYLIST_MODEL_COL_ALBUM_TITLE, PLAYLIST_MODEL_COL_ALBUM_ARTIST,
      PLAYLIST_MODEL_COL_GENRE, PLAYLIST_MODEL_COL_YEAR, PLAYLIST_MODEL_COL_LENGTH,
      PLAYLIST_MODEL_N_COLUMNS
    };
    
    int i;
    for(i = 0;names[i] != NULL; ++i) {
      GtkCheckMenuItem* item = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(view->builder, names[i]));
      gtk_widget_set_name(GTK_WIDGET(item), names[i]);
      char cfgitem[100];
      sprintf(cfgitem, "library.cols.%s", names[i]);
      int yes = el_config_get_int(btb_config(view->btb), cfgitem, 1);
      gtk_check_menu_item_set_active(item, yes);
      gtk_tree_view_column_set_visible(view->cols[es[i]], yes);
    }
  }
  
  // Start timeout every 250 ms
  g_timeout_add(250, (GSourceFunc) library_view_update_info, view); 
}