/* This file is part of GNUnet. (C) 2005, 2006 Christian Grothoff (and other contributing authors) GNUnet 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, or (at your option) any later version. GNUnet 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 General Public License for more details. You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * @file src/plugins/fs/content_tracking.c * @brief code for tracking available content * @author Christian Grothoff */ #include "platform.h" #include "gnunetgtk_common.h" #include "fs.h" #include "helper.h" #include "meta.h" #include "namespace.h" #include "content_tracking.h" #include #include #include #include static void * clearContentList (void *mdl) { GtkTreeModel *model = GTK_TREE_MODEL (mdl); struct ECRS_URI *uri; struct ECRS_MetaData *meta; GtkTreeIter iter; DEBUG_BEGIN (); if (gtk_tree_model_get_iter_first (model, &iter)) { do { gtk_tree_model_get (model, &iter, NAMESPACE_URI, &uri, NAMESPACE_META, &meta, -1); ECRS_freeUri (uri); ECRS_freeMetaData (meta); gtk_list_store_set (GTK_LIST_STORE (model), &iter, NAMESPACE_URI, NULL, NAMESPACE_META, NULL, -1); } while (gtk_list_store_remove (GTK_LIST_STORE (model), &iter)); } DEBUG_END (); return NULL; } void on_clearAvailableContentButton_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2) { GtkWidget *contentList; GtkTreeModel *model; DEBUG_BEGIN (); contentList = glade_xml_get_widget (getMainXML (), "availableContentList"); model = gtk_tree_view_get_model (GTK_TREE_VIEW (contentList)); URITRACK_clearTrackedURIS (ectx, cfg); gtkSaveCall (&clearContentList, model); DEBUG_END (); } void on_trackingCheckButton_toggled_fs (GtkWidget * dummy1, GtkWidget * dummy2) { GtkWidget *trackCheckButton; trackCheckButton = glade_xml_get_widget (getMainXML (), "trackingCheckButton"); URITRACK_trackURIS (ectx, cfg, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (trackCheckButton)) == TRUE ? YES : NO); } /** * Add the given content to the globally available * content model. Check that it is not already * present! */ static void * updateView (void *cls) { const ECRS_FileInfo *fi = cls; GtkTreeIter iter; char *filename; char *uriString; unsigned long long size; char *size_h; GtkWidget *contentList; GtkTreeModel *model; contentList = glade_xml_get_widget (getMainXML (), "availableContentList"); model = gtk_tree_view_get_model (GTK_TREE_VIEW (contentList)); filename = ECRS_getFirstFromMetaData (fi->meta, EXTRACTOR_FILENAME, EXTRACTOR_TITLE, EXTRACTOR_DESCRIPTION, EXTRACTOR_SUBJECT, EXTRACTOR_ARTIST, EXTRACTOR_AUTHOR, EXTRACTOR_PUBLISHER, EXTRACTOR_CREATOR, EXTRACTOR_PRODUCER, EXTRACTOR_UNKNOWN, -1); if (filename == NULL) { filename = STRDUP (_("no name given")); } else { char *dotdot; while (NULL != (dotdot = strstr (filename, ".."))) dotdot[0] = dotdot[1] = '_'; filename = validate_utf8 (filename); } if (ECRS_isFileUri (fi->uri)) size = ECRS_fileSize (fi->uri); else size = 0; uriString = ECRS_uriToString (fi->uri); gtk_list_store_append (GTK_LIST_STORE (model), &iter); size_h = string_get_fancy_byte_size (size); gtk_list_store_set (GTK_LIST_STORE (model), &iter, NAMESPACE_FILENAME, filename, NAMESPACE_SIZE, size, NAMESPACE_HSIZE, size_h, NAMESPACE_URISTRING, uriString, NAMESPACE_URI, ECRS_dupUri (fi->uri), NAMESPACE_META, ECRS_dupMetaData (fi->meta), -1); FREE (size_h); FREE (filename); FREE (uriString); return NULL; } /** * Add the given content to the globally available * content model. Check that it is not already * present! */ int updateViewSave (const ECRS_FileInfo * fi, const HashCode512 * key, int isRoot, void *closure) { gtkSaveCall (&updateView, (void *) fi); return OK; }