/* * This file part of gsopcast - A gtk front-end of p2p tv sopcast. * http://lianwei3.googlepages.com/home2 * Copyright (C) 2006 Wei Lian * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // //070502 changed by hesperus //changed item:list xml func channel_list_update(temp) // #include "header.h" #include "channel.h" char *title; guint title_len; char tree_state[64]; char channels_url_header[64]; extern GtkTreeView *tree_channel; //----------------------------------------------------- /////////////store tree state to variable tree_state void tree_search_key(gchar * key) { GtkTreeModel *model; model = gtk_tree_view_get_model(tree_channel); if (model != NULL) ///on program initialization, model will equal 0 { gboolean valid; GtkTreeIter iter, iter2; valid = gtk_tree_model_get_iter_first(model, &iter); ///first root row GtkTreePath *path; gchar *str; gboolean flag; ////get original focus gboolean flag_first = TRUE, flag_match = TRUE; GtkTreePath *path0, *path1 = NULL; gtk_tree_view_get_cursor(tree_channel, &path0, NULL); while (valid) { gtk_tree_model_iter_children(model, &iter2, &iter); ///get child ////tranverse child flag = FALSE; do { gtk_tree_model_get(model, &iter2, NAME_COLUMN, &str, -1); if (strcasestr(str, key)) { flag = TRUE; gtk_tree_store_set(GTK_TREE_STORE(model), &iter2, CARD_COLUMN, -1, -1); ///mark as -1 /////////find focus if (flag_first || flag_match) { path = gtk_tree_model_get_path(model, &iter2); if (flag_first) { path1 = path; flag_first = FALSE; } if (flag_match) { if (path0 == NULL) { if (path != path1) gtk_tree_path_free(path1); path1 = path; flag_match = FALSE; } else if (gtk_tree_path_compare(path, path0) == 1) { if (path != path1) gtk_tree_path_free(path1); path1 = path; flag_match = FALSE; } else { if (path != path1) gtk_tree_path_free(path); } } } } else gtk_tree_store_set(GTK_TREE_STORE(model), &iter2, CARD_COLUMN, 0, -1); ///mark as 0 ///next channel valid = gtk_tree_model_iter_next(model, &iter2); } while (valid); path = gtk_tree_model_get_path(model, &iter); ////expand or collapse group if (flag && !gtk_tree_view_row_expanded(tree_channel, path)) { gtk_tree_view_expand_row(tree_channel, path, FALSE); } else if (!flag && gtk_tree_view_row_expanded(tree_channel, path)) { gtk_tree_view_collapse_row(tree_channel, path); } gtk_tree_path_free(path); ////next group valid = gtk_tree_model_iter_next(model, &iter); } /////set focus if (path1) { gtk_tree_view_set_cursor(tree_channel, path1, NULL, FALSE); gtk_tree_path_free(path1); } if (path0) gtk_tree_path_free(path0); } } //----------------------------------------------------- void store_tree_state() { GtkTreeModel *model; model = gtk_tree_view_get_model(tree_channel); if (model != NULL) ///on program initialization, model will equal 0 { ////sort tree in default way gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), NUM_COLUMN, GTK_SORT_ASCENDING); gboolean valid; GtkTreeIter iter; valid = gtk_tree_model_get_iter_first(model, &iter); GtkTreePath *path; // memset (tree_state, 0, sizeof (tree_state)); for (guint i = 0; i < sizeof(tree_state); i++) { if (!valid) break; path = gtk_tree_model_get_path(model, &iter); if (gtk_tree_view_row_expanded(tree_channel, path)) { tree_state[i] = '1'; } else { tree_state[i] = '0'; } gtk_tree_path_free(path); valid = gtk_tree_model_iter_next(model, &iter); } } } //----------------------------------------------------- void channel_list_update(char *buf) { /////////////////store previous tree state to variable tree_state store_tree_state(); ///////////////////load channel list int row = 0; //char *channel_info[11]; char *channel_info[15]; guint i; //for (i = 0; i < 11; i++) for (i = 0; i < 15; i++) channel_info[i] = NULL; regex_t re3, re4; regmatch_t subs[1]; // Should just care about <> since those only valid as tag boundary for xml. regcomp(&re3, "<[^<>]*>", REG_EXTENDED); regcomp(&re4, "<\\/[^<>]*>", REG_EXTENDED); GtkTreeStore *store = GTK_TREE_STORE(gtk_tree_view_get_model(tree_channel)); gtk_tree_store_clear(store); GtkTreeIter iter, iter2; ////definition of store should be consist with the enum char null = '\0'; int card; ////number of channels in a group int max_user = 0, max_visit = 0; ////////////// gboolean found; char *group_end; char *buf_pt = strstr(buf, ""); channel_info[1] = buf_pt + 1; buf_pt = strstr(buf_pt, ""); while (buf_pt && buf_pt < group_end) { buf_pt = strstr(buf_pt, "type=\""); buf_pt += strlen("type=\""); found = FALSE; if (*buf_pt != '0') ///filter found = TRUE; /////////////statistics //for (i = 0; i < 9; i++) { for (i = 0; i < 12; i++) { ///head if (regexec(&re3, buf_pt, (size_t) 1, subs, 0) == 0) buf_pt += subs[0].rm_eo; channel_info[i + 1] = buf_pt; ///tail if (regexec(&re4, buf_pt, (size_t) 1, subs, 0) == 0) { *(buf_pt + subs[0].rm_so) = '\0'; buf_pt += subs[0].rm_eo; } } /////sop address buf_pt = strstr(buf_pt, ""); buf_pt += strlen(""); if (strncmp (buf_pt, channels_url_header, strlen(channels_url_header)) == 0 && found == FALSE) { //channel_info[10] = buf_pt; channel_info[13] = buf_pt; buf_pt = strstr(buf_pt, ""); *(buf_pt) = '\0'; buf_pt++; // Search for channel description tag. buf_pt = strstr(buf_pt, " atoi(channel_info[5]) ? max_user : atoi(channel_info[5]); max_visit = max_visit > atoi(channel_info[7]) ? max_visit : atoi(channel_info[7]); ///////////adjust title length if (channel_info[1] != NULL) { title_len = (title_len < strlen(channel_info[1])) ? strlen(channel_info[1]) : title_len; } } ////update buf_pt buf_pt = strstr(buf_pt, "