Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
fix column resizing behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpp committed Nov 6, 2013
1 parent bc7db3b commit f54a4e8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
/Debug
/build
/gtk-2.12
/Test
54 changes: 34 additions & 20 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ on_search_target_changed (GtkWidget *widget, gpointer *data) {
vk_search_opts.search_target = gtk_combo_box_get_active( GTK_COMBO_BOX (widget));
}

static GtkCellRenderer *
vk_gtk_cell_renderer_text_new_with_ellipsis () {
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
return renderer;
}

static
GtkWidget *
vk_create_browser_widget_content () {
Expand All @@ -239,8 +246,6 @@ vk_create_browser_widget_content () {
GtkWidget *search_target;
GtkWidget *search_results;
GtkListStore *list_store;
GtkCellRenderer *artist_cell;
GtkCellRenderer *title_cell;
GtkWidget *bottom_hbox;
GtkWidget *my_music_button;
GtkWidget *filter_duplicates;
Expand Down Expand Up @@ -275,36 +280,45 @@ vk_create_browser_widget_content () {
g_signal_connect (search_target, "changed", G_CALLBACK (on_search_target_changed), NULL);
gtk_box_pack_start (GTK_BOX (search_hbox), search_target, FALSE, FALSE, 0);

GtkCellRenderer *duration_cell;
search_results = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
artist_cell = gtk_cell_renderer_text_new ();
title_cell = gtk_cell_renderer_text_new ();
duration_cell = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search_results), -1, "Artist",
artist_cell, "text", ARTIST_COLUMN, NULL);
vk_gtk_cell_renderer_text_new_with_ellipsis (),
"text", ARTIST_COLUMN, NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search_results), -1, "Title",
title_cell, "text", TITLE_COLUMN, NULL);
vk_gtk_cell_renderer_text_new_with_ellipsis (),
"text", TITLE_COLUMN, NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (search_results), -1, "Duration",
duration_cell, "text", DURATION_FORMATTED_COLUMN, NULL);
gtk_cell_renderer_text_new (),
"text", DURATION_FORMATTED_COLUMN, NULL);

//// Setup columns
GtkTreeViewColumn *col;
// artist col is resizeable and sortable
col = gtk_tree_view_get_column (GTK_TREE_VIEW (search_results), 0);
gtk_tree_view_column_set_resizable (col, TRUE);
gtk_tree_view_column_set_sort_column_id (col, 0);
g_object_set (col,
"sizing", GTK_TREE_VIEW_COLUMN_FIXED,
"resizable", TRUE,
"expand", TRUE,
"sort-column-id", 0,
NULL);
// title col is resizeable, sortable and expanded
col = gtk_tree_view_get_column (GTK_TREE_VIEW (search_results), 1);
gtk_tree_view_column_set_resizable (col, TRUE);
gtk_tree_view_column_set_expand (col, TRUE);
gtk_tree_view_column_set_sort_column_id (col, 1);
g_object_set (col,
"sizing", GTK_TREE_VIEW_COLUMN_FIXED,
"resizable", TRUE,
"expand", TRUE,
"sort-column-id", 1,
NULL);
// duration col is sortable and fixed width
col = gtk_tree_view_get_column (GTK_TREE_VIEW (search_results), 2);
gtk_tree_view_column_set_min_width(col, 10);
gtk_tree_view_column_set_max_width(col, 70);
gtk_tree_view_column_set_fixed_width (col, 50);
gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
gtk_tree_view_column_set_sort_column_id (col, 2);
g_object_set (col,
"sizing", GTK_TREE_VIEW_COLUMN_FIXED,
"resizable", TRUE,
"min-width", 20,
"max-width", 70,
"fixed-width", 50,
"sort-column-id", 2,
NULL);


gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (search_results)),
Expand All @@ -315,7 +329,7 @@ vk_create_browser_widget_content () {
g_signal_connect(search_results, "button-press-event", G_CALLBACK(on_search_results_button_press), NULL);

scroll_window = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_can_focus ( scroll_window, FALSE); // TODO ??
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scroll_window), search_results);
gtk_box_pack_start (GTK_BOX (dlg_vbox), scroll_window, TRUE, TRUE, 12);

Expand Down
21 changes: 12 additions & 9 deletions vkontakte.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct {
"&response_type=token"

// URL formatting strings
#define VK_URL_LEN 300
#define MAX_URL_LEN 300
#define VK_AUDIO_GET VK_API_METHOD_AUDIO_GET "?access_token=%s"
#define VK_AUDIO_GET_BY_ID VK_API_METHOD_AUDIO_GET_BY_ID "?access_token=%s&audios=%d_%d"
#define VK_AUDIO_SEARCH VK_API_METHOD_AUDIO_SEARCH "?access_token=%s&count=%d&offset=%d&q=%s"
Expand All @@ -49,18 +49,19 @@ typedef struct {
// util.c
gchar * http_get_string(const gchar *url, GError **error);

int
vk_vfs_format_track_url(char *url,
int aid,
int owner_id) {

static int
vk_vfs_format_track_url (char *url,
int aid,
int owner_id) {
return sprintf (url, "vk://%d_%d", owner_id, aid);
}

/**
* Simple deduplication.
* @return TRUE if given track already exists, FALSE otherwise.
*/
gboolean
static gboolean
vk_tree_model_has_track (GtkTreeModel *treemodel, VkAudioTrack *track) {
// if no need to filter duplicates return FALSE immediately
if (!vk_search_opts.filter_duplicates) {
Expand Down Expand Up @@ -255,7 +256,7 @@ vk_search_audio_thread_func (SearchQuery *query) {
char *escaped_search_str = curl_easy_escape (curl, query->query, 0);

do {
char method_url[VK_URL_LEN];
char method_url[MAX_URL_LEN];

rows_added = gtk_tree_model_iter_n_children (query->store, NULL);
sprintf (method_url,
Expand All @@ -268,6 +269,8 @@ vk_search_audio_thread_func (SearchQuery *query) {
rows_added = gtk_tree_model_iter_n_children (query->store, NULL) - rows_added;
} while (++iteration < 10 && rows_added > 0);

trace ("INFO: Did %d iterations and stopped discovering new tracks\n", iteration);

g_free (escaped_search_str);
curl_easy_cleanup (curl);
g_free ((gchar *) query->query);
Expand All @@ -278,7 +281,7 @@ vk_search_audio_thread_func (SearchQuery *query) {
static void
vk_get_my_music_thread_func (void *ctx) {
SearchQuery query;
char method_url[VK_URL_LEN];
char method_url[MAX_URL_LEN];

query.query = NULL,
query.store = GTK_TREE_MODEL (ctx);
Expand Down Expand Up @@ -389,7 +392,7 @@ vk_ddb_vfs_open (const char *fname) {
GError *error;
DB_FILE *f = 0;
char *audio_resp;
char get_audio_url[VK_URL_LEN];
char get_audio_url[MAX_URL_LEN];

if (!vk_auth_data || !vk_auth_data->access_token) {
trace ("Not authenticated? Visit VK.com\n");
Expand Down

0 comments on commit f54a4e8

Please sign in to comment.