[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r20422 - in gnunet-gtk: contrib src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r20422 - in gnunet-gtk: contrib src/fs |
Date: |
Fri, 9 Mar 2012 22:25:10 +0100 |
Author: grothoff
Date: 2012-03-09 22:25:10 +0100 (Fri, 09 Mar 2012)
New Revision: 20422
Added:
gnunet-gtk/contrib/gnunet_fs_gtk_unindex.glade
gnunet-gtk/src/fs/gnunet-fs-gtk_unindex.c
gnunet-gtk/src/fs/gnunet-fs-gtk_unindex.h
Modified:
gnunet-gtk/contrib/Makefile.am
gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade
gnunet-gtk/src/fs/Makefile.am
gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
Log:
implementing listing of indexed files and unindexing from gnunet-fs-gtk (#1945)
Modified: gnunet-gtk/contrib/Makefile.am
===================================================================
--- gnunet-gtk/contrib/Makefile.am 2012-03-09 21:15:42 UTC (rev 20421)
+++ gnunet-gtk/contrib/Makefile.am 2012-03-09 21:25:10 UTC (rev 20422)
@@ -27,6 +27,7 @@
gnunet_fs_gtk_publish_tab.glade \
gnunet_fs_gtk_search_tab.glade \
gnunet_fs_gtk_select_pseudonym_dialog.glade \
+ gnunet_fs_gtk_unindex.glade \
gnunet_fs_gtk_progress_dialog.glade \
gnunet_gns_gtk_about_window.glade \
gnunet_gns_gtk_main_window.glade \
Modified: gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade 2012-03-09 21:15:42 UTC
(rev 20421)
+++ gnunet-gtk/contrib/gnunet_fs_gtk_main_window.glade 2012-03-09 21:25:10 UTC
(rev 20422)
@@ -192,6 +192,14 @@
</object>
</child>
<child>
+ <object class="GtkMenuItem"
id="GNUNET_GTK_main_menu_unindex">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_List
indexed files</property>
+ <property name="use_underline">True</property>
+ <signal name="activate"
handler="GNUNET_GTK_main_menu_unindex_activate_cb"/>
+ </object>
+ </child>
+ <child>
<object class="GtkSeparatorMenuItem"
id="GNUNET_GTK_main_menu_file_sep1">
<property name="visible">True</property>
</object>
Added: gnunet-gtk/contrib/gnunet_fs_gtk_unindex.glade
===================================================================
--- gnunet-gtk/contrib/gnunet_fs_gtk_unindex.glade
(rev 0)
+++ gnunet-gtk/contrib/gnunet_fs_gtk_unindex.glade 2012-03-09 21:25:10 UTC
(rev 20422)
@@ -0,0 +1,154 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkListStore" id="GNUNET_FS_GTK_unindex_liststore">
+ <columns>
+ <!-- column-name filename -->
+ <column type="gchararray"/>
+ <!-- column-name filesize -->
+ <column type="guint64"/>
+ <!-- column-name background_color -->
+ <column type="gchararray"/>
+ <!-- column-name unindex_context -->
+ <column type="gpointer"/>
+ <!-- column-name unindex_progress -->
+ <column type="gint"/>
+ <!-- column-name progress_visible -->
+ <column type="gboolean"/>
+ <!-- column-name error_message -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
+ <object class="GtkDialog" id="GNUNET_FS_GTK_unindex_dialog">
+ <property name="width_request">600</property>
+ <property name="height_request">300</property>
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Indexed files</property>
+ <property name="icon_name">folder</property>
+ <property name="type_hint">normal</property>
+ <property name="has_separator">False</property>
+ <child internal-child="vbox">
+ <object class="GtkVBox" id="GNUNET_FS_GTK_unindex_dialog-vbox">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkScrolledWindow"
id="GNUNET_FS_GTK_unindex_scrolledwindow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
+ <child>
+ <object class="GtkTreeView" id="GNUNET_FS_GTK_unindex_treeview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property
name="model">GNUNET_FS_GTK_unindex_liststore</property>
+ <child>
+ <object class="GtkTreeViewColumn"
id="GNUNET_FS_GTK_unindex_filesize_treeviewcolumn">
+ <property name="sizing">autosize</property>
+ <property name="title">Size</property>
+ <property name="reorderable">True</property>
+ <property name="sort_indicator">True</property>
+ <property name="sort_column_id">1</property>
+ <child>
+ <object class="GtkCellRendererText"
id="GNUNET_FS_GTK_unindex_cellrenderertext"/>
+ <attributes>
+ <attribute name="background">2</attribute>
+ <attribute name="text">1</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn"
id="GNUNET_FS_GTK_unindex_filename_treeviewcolumn">
+ <property name="title">Filename</property>
+ <property name="reorderable">True</property>
+ <property name="sort_indicator">True</property>
+ <property name="sort_column_id">0</property>
+ <child>
+ <object class="GtkCellRendererText"
id="GNUNET_FS_GTK_unindex_filename_cellrenderertext"/>
+ <attributes>
+ <attribute name="background">2</attribute>
+ <attribute name="text">0</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkTreeViewColumn"
id="GNUNET_FS_GTK_unindex_progress_treeviewcolumn">
+ <property name="min_width">9</property>
+ <property name="title">Unindex progress</property>
+ <child>
+ <object class="GtkCellRendererProgress"
id="GNUNET_FS_GTK_unindex_progress_cellrendererprogress"/>
+ <attributes>
+ <attribute name="visible">5</attribute>
+ <attribute name="text">6</attribute>
+ <attribute name="value">4</attribute>
+ </attributes>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <object class="GtkHButtonBox"
id="GNUNET_FS_GTK_unindex_dialog-action_area">
+ <property name="visible">True</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="GNUNET_FS_GTK_unindex_button">
+ <property name="label">_Unindex</property>
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="tooltip_text" translatable="yes">Unindex the
selected indexed file.</property>
+ <property
name="image">GNUNET_FS_GTK_unindex_delete_image</property>
+ <property name="use_underline">True</property>
+ <signal name="clicked"
handler="GNUNET_FS_GTK_unindex_button_clicked_cb"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton"
id="GNUNET_FS_GTK_unindex_close_button">
+ <property name="label">gtk-close</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ <signal name="clicked"
handler="GNUNET_FS_GTK_unindex_close_button_clicked_cb"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">GNUNET_FS_GTK_unindex_button</action-widget>
+ <action-widget
response="0">GNUNET_FS_GTK_unindex_close_button</action-widget>
+ </action-widgets>
+ </object>
+ <object class="GtkImage" id="GNUNET_FS_GTK_unindex_delete_image">
+ <property name="visible">True</property>
+ <property name="stock">gtk-delete</property>
+ </object>
+</interface>
Modified: gnunet-gtk/src/fs/Makefile.am
===================================================================
--- gnunet-gtk/src/fs/Makefile.am 2012-03-09 21:15:42 UTC (rev 20421)
+++ gnunet-gtk/src/fs/Makefile.am 2012-03-09 21:25:10 UTC (rev 20422)
@@ -24,6 +24,7 @@
gnunet-fs-gtk_main-window-view-toggles.c \
gnunet-fs-gtk_open-directory.c \
gnunet-fs-gtk_open-uri.c \
+ gnunet-fs-gtk_unindex.c gnunet-fs-gtk_unindex.h \
gnunet-fs-gtk_publish-dialog.c \
gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \
gnunet-fs-gtk_namespace_manager.c
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c 2012-03-09 21:15:42 UTC
(rev 20421)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c 2012-03-09 21:25:10 UTC
(rev 20422)
@@ -27,8 +27,8 @@
#include "gnunet-fs-gtk_common.h"
#include "gnunet-fs-gtk_download-save-as.h"
#include "gnunet-fs-gtk_event-handler.h"
+#include "gnunet-fs-gtk_unindex.h"
-
/**
* We have a single tab where we display publishing operations.
* So there is only one instance of this struct.
@@ -1366,7 +1366,7 @@
GtkTreeIter iter;
tm = GTK_TREE_MODEL (tab->ts);
- if (TRUE != gtk_tree_model_get_iter_first (tm, &iter))
+ if (! gtk_tree_model_get_iter_first (tm, &iter))
return;
do
{
@@ -1386,11 +1386,11 @@
directory; clean it up */
free_search_result (sr);
/* the above call clobbered our 'iter', restart from the beginning... */
- if (TRUE != gtk_tree_model_get_iter_first (tm, &iter))
+ if (! gtk_tree_model_get_iter_first (tm, &iter))
return;
}
}
- while (TRUE == gtk_tree_model_iter_next (tm, &iter));
+ while (gtk_tree_model_iter_next (tm, &iter));
}
@@ -3001,26 +3001,30 @@
close_search_tab (info->value.search.cctx);
return NULL;
case GNUNET_FS_STATUS_UNINDEX_START:
- GNUNET_break (0);
- break;
+ return info->value.unindex.cctx;
case GNUNET_FS_STATUS_UNINDEX_RESUME:
- GNUNET_break (0);
- break;
+ return GNUNET_FS_GTK_unindex_handle_resume_ (info->value.unindex.uc,
+ info->value.unindex.filename,
+ info->value.unindex.size,
+ info->value.unindex.completed,
+
info->value.unindex.specifics.resume.message);
case GNUNET_FS_STATUS_UNINDEX_SUSPEND:
- GNUNET_break (0);
- break;
+ GNUNET_FS_GTK_unindex_handle_stop_ (info->value.unindex.cctx);
+ return NULL;
case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
- GNUNET_break (0);
- break;
+ GNUNET_FS_GTK_unindex_handle_progress_ (info->value.unindex.cctx,
+ info->value.unindex.completed);
+ return info->value.unindex.cctx;
case GNUNET_FS_STATUS_UNINDEX_ERROR:
- GNUNET_break (0);
- break;
+ GNUNET_FS_GTK_unindex_handle_error_ (info->value.unindex.cctx,
+
info->value.unindex.specifics.error.message);
+ return info->value.unindex.cctx;
case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
- GNUNET_break (0);
- break;
+ GNUNET_FS_GTK_unindex_handle_completed_ (info->value.unindex.cctx);
+ return info->value.unindex.cctx;
case GNUNET_FS_STATUS_UNINDEX_STOPPED:
- GNUNET_break (0);
- break;
+ GNUNET_FS_GTK_unindex_handle_stop_ (info->value.unindex.cctx);
+ return NULL;
default:
GNUNET_break (0);
break;
Added: gnunet-gtk/src/fs/gnunet-fs-gtk_unindex.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_unindex.c (rev 0)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_unindex.c 2012-03-09 21:25:10 UTC (rev
20422)
@@ -0,0 +1,584 @@
+/*
+ This file is part of GNUnet
+ (C) 2012 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/fs/gnunet-fs-gtk_unindex.c
+ * @author Christian Grothoff
+ * @brief operations to display and unindex indexed files
+ */
+#include "gnunet-fs-gtk.h"
+#include "gnunet-fs-gtk_common.h"
+#include "gnunet-fs-gtk_event-handler.h"
+#include "gnunet-fs-gtk_unindex.h"
+
+
+/**
+ * Columns in the unindex model.
+ */
+enum UNINDEX_ModelColumns
+ {
+ /**
+ * A gchararray.
+ */
+ UNINDEX_MC_FILENAME = 0,
+
+ /**
+ * A guint64.
+ */
+ UNINDEX_MC_FILESIZE = 1,
+
+ /**
+ * A gchararray representing a color.
+ */
+ UNINDEX_MC_BACKGROUND_COLOR = 2,
+
+ /**
+ * A 'struct UnindexEntry' (gpointer)
+ */
+ UNINDEX_MC_UNINDEX_CONTEXT = 3,
+
+ /**
+ * A gfloat.
+ */
+ UNINDEX_MC_UNINDEX_PROGRESS = 4,
+
+ /**
+ * A boolean.
+ */
+ UNINDEX_MC_PROGRESS_VISIBLE = 5,
+
+ /**
+ * A gchararray.
+ */
+ UNINDEX_MC_ERROR = 6
+ };
+
+
+/**
+ * Overall context for the dialog.
+ */
+struct UnindexDialogContext
+{
+ GtkBuilder *builder;
+
+ /**
+ * The dialog object.
+ */
+ GtkWidget *dialog;
+
+ /**
+ * The unindex button.
+ */
+ GtkWidget *unindex_button;
+
+ /**
+ * Main treeview object.
+ */
+ GtkTreeView *treeview;
+
+ /**
+ * Selection of our treeview.
+ */
+ GtkTreeSelection *selection;
+
+ /**
+ * Unindex data model.
+ */
+ GtkTreeModel *model;
+
+ /**
+ * Context for initial listing of indexed files.
+ */
+ struct GNUNET_FS_GetIndexedContext *gic;
+};
+
+
+/**
+ * Information for a specific unindex operation.
+ */
+struct UnindexEntry
+{
+
+ /**
+ * Kept in a DLL.
+ */
+ struct UnindexEntry *next;
+
+ /**
+ * Next entry.
+ */
+ struct UnindexEntry *prev;
+
+ /**
+ * Name of the file being unindexed.
+ */
+ char *filename;
+
+ /**
+ * Error description, NULL if no error
+ */
+ char *emsg;
+
+ /**
+ * Handle with FS.
+ */
+ struct GNUNET_FS_UnindexContext *uc;
+
+ /**
+ * Row reference, NULL if the dialog is not open.
+ */
+ GtkTreeRowReference *rr;
+
+ /**
+ * Size of the file.
+ */
+ uint64_t filesize;
+
+ /**
+ * Percentage progress made so far.
+ */
+ gint progress;
+};
+
+
+/**
+ * There can only be one.
+ */
+static struct UnindexDialogContext *master_udc;
+
+/**
+ * Head of linked list.
+ */
+static struct UnindexEntry *ue_head;
+
+/**
+ * Tail of linked list.
+ */
+static struct UnindexEntry *ue_tail;
+
+
+/**
+ * User has clicked on the 'delete/unindex' button for the dialog.
+ * Unindex the selected file.
+ *
+ * @param dummy the button
+ * @param user_data the unindex context
+ */
+void
+GNUNET_FS_GTK_unindex_button_clicked_cb (GtkWidget * dummy,
+ gpointer user_data)
+{
+ struct UnindexDialogContext *udc = user_data;
+ GtkTreeIter iter;
+ char *filename;
+ struct UnindexEntry *ue;
+ GtkTreePath *path;
+ guint64 filesize;
+
+ /* find out if a file is selected */
+ if (! gtk_tree_selection_get_selected (udc->selection, NULL, &iter))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ gtk_tree_model_get (udc->model, &iter,
+ UNINDEX_MC_FILENAME, &filename,
+ UNINDEX_MC_FILESIZE, &filesize,
+ UNINDEX_MC_UNINDEX_CONTEXT, &ue,
+ -1);
+ if (NULL != ue)
+ {
+ GNUNET_break (0);
+ g_free (filename);
+ return;
+ }
+ ue = GNUNET_malloc (sizeof (struct UnindexEntry));
+ ue->filesize = filesize;
+ GNUNET_CONTAINER_DLL_insert (ue_head, ue_tail, ue);
+ ue->filename = GNUNET_strdup (filename);
+ path = gtk_tree_model_get_path (udc->model, &iter);
+ ue->rr = gtk_tree_row_reference_new (udc->model, path);
+ gtk_tree_path_free (path);
+ ue->uc = GNUNET_FS_unindex_start (GNUNET_FS_GTK_get_fs_handle (),
+ filename, ue);
+ gtk_list_store_set (GTK_LIST_STORE (udc->model),
+ &iter,
+ UNINDEX_MC_BACKGROUND_COLOR, "yellow",
+ UNINDEX_MC_UNINDEX_CONTEXT, ue,
+ UNINDEX_MC_UNINDEX_PROGRESS, 0,
+ UNINDEX_MC_PROGRESS_VISIBLE, TRUE,
+ -1);
+ gtk_widget_set_sensitive (udc->unindex_button, FALSE);
+}
+
+
+/**
+ * User has clicked on the 'close' button for the dialog. Close it.
+ *
+ * @param dummy the button
+ * @param user_data the unindex context
+ */
+void
+GNUNET_FS_GTK_unindex_close_button_clicked_cb (GtkWidget * dummy,
+ gpointer user_data)
+{
+ struct UnindexDialogContext *udc = user_data;
+ GtkTreeIter iter;
+ struct UnindexEntry *ue;
+
+ if (NULL != udc->gic)
+ {
+ GNUNET_FS_get_indexed_files_cancel (udc->gic);
+ udc->gic = NULL;
+ }
+ if (gtk_tree_model_get_iter_first (udc->model, &iter))
+ do
+ {
+ gtk_tree_model_get (udc->model, &iter,
+ UNINDEX_MC_UNINDEX_CONTEXT, &ue,
+ -1);
+ if (NULL != ue)
+ {
+ gtk_tree_row_reference_free (ue->rr);
+ ue->rr = NULL;
+ }
+ }
+ while (TRUE == gtk_tree_model_iter_next (udc->model, &iter));
+ gtk_widget_destroy (udc->dialog);
+ g_object_unref (G_OBJECT (udc->builder));
+ GNUNET_free (udc);
+ master_udc = NULL;
+}
+
+
+/**
+ * The selection in the tree view changed; update the button sensitivity.
+ *
+ * @param ts the changed selection
+ * @param user_data our unindex context
+ */
+static void
+selection_changed_cb (GtkTreeSelection * ts,
+ gpointer user_data)
+{
+ struct UnindexDialogContext *udc = user_data;
+ GtkTreeIter iter;
+ struct UnindexEntry *ue;
+
+ /* find out if a file is selected */
+ if (gtk_tree_selection_get_selected (udc->selection, NULL, &iter))
+ {
+ gtk_tree_model_get (udc->model, &iter,
+ UNINDEX_MC_UNINDEX_CONTEXT, &ue,
+ -1);
+ if (NULL == ue)
+ {
+ /* selected file not already being unindexed, enable button! */
+ gtk_widget_set_sensitive (udc->unindex_button, TRUE);
+ return;
+ }
+ }
+ gtk_widget_set_sensitive (udc->unindex_button, FALSE);
+}
+
+
+/**
+ * Type of a function called by "GNUNET_FS_get_indexed_files".
+ *
+ * @param cls closure
+ * @param filename the name of the file, NULL for end of list
+ * @param file_id hash of the contents of the indexed file
+ * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
+ */
+static int
+add_indexed_file (void *cls, const char *filename,
+ const GNUNET_HashCode * file_id)
+{
+ struct UnindexDialogContext *udc = cls;
+ GtkTreeIter iter;
+ uint64_t filesize;
+ struct UnindexEntry *ue;
+ GtkTreePath *path;
+
+ if (NULL == filename)
+ {
+ /* end of list */
+ udc->gic = NULL;
+ return GNUNET_OK;
+ }
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename,
+ &filesize,
+ GNUNET_YES))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Could not access indexed file `%s'\n"),
+ filename);
+ return GNUNET_OK;
+ }
+ for (ue = ue_head; ue != NULL; ue = ue->next)
+ if (0 == strcmp (ue->filename, filename))
+ break;
+ if (NULL == ue)
+ {
+ gtk_list_store_insert_with_values (GTK_LIST_STORE (udc->model),
+ &iter, G_MAXINT,
+ UNINDEX_MC_FILENAME, filename,
+ UNINDEX_MC_FILESIZE, (guint64) filesize,
+ UNINDEX_MC_BACKGROUND_COLOR, "white",
+ UNINDEX_MC_PROGRESS_VISIBLE, FALSE,
+ -1);
+ }
+ else
+ {
+ if (NULL != ue->rr)
+ {
+ GNUNET_break (0);
+ return GNUNET_OK;
+ }
+ gtk_list_store_insert_with_values (GTK_LIST_STORE (udc->model),
+ &iter, G_MAXINT,
+ UNINDEX_MC_FILENAME, filename,
+ UNINDEX_MC_FILESIZE, (guint64) filesize,
+ UNINDEX_MC_BACKGROUND_COLOR, (NULL ==
ue->emsg) ? "yellow" : "red",
+ UNINDEX_MC_UNINDEX_CONTEXT, ue,
+ UNINDEX_MC_UNINDEX_PROGRESS,
ue->progress,
+ UNINDEX_MC_PROGRESS_VISIBLE, TRUE,
+ UNINDEX_MC_ERROR, ue->emsg,
+ -1);
+ path = gtk_tree_model_get_path (udc->model, &iter);
+ ue->rr = gtk_tree_row_reference_new (udc->model, path);
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * User selected "List indexed files..." in menu. Display dialog.
+ *
+ * @param dummy the menu entry
+ * @param user_data the main dialog builder, unused
+ */
+void
+GNUNET_GTK_main_menu_unindex_activate_cb (GtkWidget * dummy,
+ gpointer data)
+{
+ GtkWidget *toplevel;
+ struct UnindexDialogContext *udc;
+
+ if (NULL != master_udc)
+ {
+ /* window already exists, raise focus */
+ gtk_window_present (GTK_WINDOW (master_udc->dialog));
+ return;
+ }
+ udc = GNUNET_malloc (sizeof (struct UnindexDialogContext));
+ udc->builder =
+ GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_unindex.glade", udc);
+ if (NULL == udc->builder)
+ {
+ GNUNET_break (0);
+ GNUNET_free (udc);
+ return;
+ }
+ udc->dialog = GTK_WIDGET (gtk_builder_get_object
+ (udc->builder, "GNUNET_FS_GTK_unindex_dialog"));
+ udc->treeview = GTK_TREE_VIEW (gtk_builder_get_object
+ (udc->builder,
"GNUNET_FS_GTK_unindex_treeview"));
+ udc->selection = gtk_tree_view_get_selection (udc->treeview);
+ udc->unindex_button = GTK_WIDGET (gtk_builder_get_object
+ (udc->builder,
"GNUNET_FS_GTK_unindex_button"));
+ udc->model = GTK_TREE_MODEL (gtk_builder_get_object
+ (udc->builder,
"GNUNET_FS_GTK_unindex_liststore"));
+ udc->gic = GNUNET_FS_get_indexed_files (GNUNET_FS_GTK_get_fs_handle (),
+ &add_indexed_file,
+ udc);
+ toplevel = gtk_widget_get_toplevel (dummy);
+ if (GTK_IS_WINDOW (toplevel))
+ gtk_window_set_transient_for (GTK_WINDOW (udc->dialog), GTK_WINDOW
(toplevel));
+ /* connect signals; FIXME-GTK3: these could be connected with (modern) Glade
*/
+ g_signal_connect (G_OBJECT (udc->selection), "changed",
+ G_CALLBACK (selection_changed_cb), udc);
+ gtk_window_present (GTK_WINDOW (udc->dialog));
+ master_udc = udc;
+}
+
+
+/**
+ * An unindex operation resumed. Setup the
+ * internal context for Gtk.
+ *
+ * @param fs unindex context with the FS library
+ * @param filename name of file being unindexed
+ * @param filesize size of the file
+ * @param completed how many bytes were done so far
+ * @param emsg NULL if everything is fine, otherwise error message
+ */
+struct UnindexEntry *
+GNUNET_FS_GTK_unindex_handle_resume_ (struct GNUNET_FS_UnindexContext *uc,
+ const char *filename,
+ uint64_t filesize,
+ uint64_t completed,
+ const char *emsg)
+{
+ struct UnindexEntry *ue;
+
+ ue = GNUNET_malloc (sizeof (struct UnindexEntry));
+ ue->filename = GNUNET_strdup (filename);
+ if (NULL != emsg)
+ ue->emsg = GNUNET_strdup (emsg);
+ ue->filesize = filesize;
+ ue->uc = uc;
+ ue->progress = (gint) ((100LL * completed) / filesize);
+ GNUNET_CONTAINER_DLL_insert (ue_head,
+ ue_tail,
+ ue);
+ return ue;
+}
+
+
+/**
+ * FS notified us that our undex operation was stopped.
+ *
+ * @param ue operation that stopped
+ */
+void
+GNUNET_FS_GTK_unindex_handle_stop_ (struct UnindexEntry *ue)
+{
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+
+ if (NULL != ue->rr)
+ {
+ path = gtk_tree_row_reference_get_path (ue->rr);
+ model = gtk_tree_row_reference_get_model (ue->rr);
+ gtk_tree_row_reference_free (ue->rr);
+ ue->rr = NULL;
+ GNUNET_assert (TRUE == gtk_tree_model_get_iter (model,
+ &iter,
+ path));
+ gtk_tree_path_free (path);
+ gtk_list_store_set (GTK_LIST_STORE (model),
+ &iter,
+ UNINDEX_MC_UNINDEX_CONTEXT, NULL,
+ -1);
+ }
+ GNUNET_CONTAINER_DLL_remove (ue_head,
+ ue_tail,
+ ue);
+ GNUNET_free_non_null (ue->emsg);
+ GNUNET_free (ue->filename);
+ GNUNET_free (ue);
+}
+
+
+/**
+ * FS notified us that our undex operation had an error.
+ *
+ * @param ue operation that had an error
+ * @param emsg error message
+ */
+void
+GNUNET_FS_GTK_unindex_handle_error_ (struct UnindexEntry *ue,
+ const char *emsg)
+{
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+
+ ue->emsg = GNUNET_strdup (emsg);
+ if (NULL == ue->rr)
+ return;
+ path = gtk_tree_row_reference_get_path (ue->rr);
+ model = gtk_tree_row_reference_get_model (ue->rr);
+ GNUNET_assert (TRUE == gtk_tree_model_get_iter (model,
+ &iter,
+ path));
+ gtk_tree_path_free (path);
+ gtk_list_store_set (GTK_LIST_STORE (model),
+ &iter,
+ UNINDEX_MC_BACKGROUND_COLOR, "red",
+ UNINDEX_MC_ERROR, emsg,
+ -1);
+}
+
+
+/**
+ * FS notified us that our undex operation made progress
+ *
+ * @param ue operation that made progress
+ * @param completed number of bytes completed now
+ */
+void
+GNUNET_FS_GTK_unindex_handle_progress_ (struct UnindexEntry *ue,
+ uint64_t completed)
+{
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+
+ ue->progress = (gint) ((100LL * completed) / ue->filesize);
+ if (NULL == ue->rr)
+ return;
+ path = gtk_tree_row_reference_get_path (ue->rr);
+ model = gtk_tree_row_reference_get_model (ue->rr);
+ GNUNET_assert (TRUE == gtk_tree_model_get_iter (model,
+ &iter,
+ path));
+ gtk_tree_path_free (path);
+ gtk_list_store_set (GTK_LIST_STORE (model),
+ &iter,
+ UNINDEX_MC_UNINDEX_PROGRESS, ue->progress,
+ -1);
+}
+
+
+/**
+ * FS notified us that our undex operation completed
+ *
+ * @param ue operation that completed
+ */
+void
+GNUNET_FS_GTK_unindex_handle_completed_ (struct UnindexEntry *ue)
+{
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+
+ if (NULL != ue->rr)
+ {
+ path = gtk_tree_row_reference_get_path (ue->rr);
+ model = gtk_tree_row_reference_get_model (ue->rr);
+ GNUNET_assert (TRUE == gtk_tree_model_get_iter (model,
+ &iter,
+ path));
+ gtk_tree_path_free (path);
+ gtk_list_store_remove (GTK_LIST_STORE (model),
+ &iter);
+ gtk_tree_row_reference_free (ue->rr);
+ ue->rr = NULL;
+ }
+ GNUNET_FS_unindex_stop (ue->uc);
+}
+
+
+
+/* end of gnunet-fs-gtk_unindex.c */
Added: gnunet-gtk/src/fs/gnunet-fs-gtk_unindex.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_unindex.h (rev 0)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_unindex.h 2012-03-09 21:25:10 UTC (rev
20422)
@@ -0,0 +1,99 @@
+/*
+ This file is part of GNUnet
+ (C) 2012 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/fs/gnunet-fs-gtk_unindex.h
+ * @author Christian Grothoff
+ */
+#ifndef GNUNET_FS_GTK_UNINDEX_H
+#define GNUNET_FS_GTK_UNINDEX_H
+
+#include "gnunet-fs-gtk.h"
+#include "gnunet-fs-gtk_common.h"
+#include "gnunet-fs-gtk_event-handler.h"
+
+
+/**
+ * Information for a specific unindex operation.
+ */
+struct UnindexEntry;
+
+
+/**
+ * An unindex operation resumed. Setup the
+ * internal context for Gtk.
+ *
+ * @param fs unindex context with the FS library
+ * @param filename name of file being unindexed
+ * @param filesize size of the file
+ * @param completed how many bytes were done so far
+ * @param emsg NULL if everything is fine, otherwise error message
+ */
+struct UnindexEntry *
+GNUNET_FS_GTK_unindex_handle_resume_ (struct GNUNET_FS_UnindexContext *uc,
+ const char *filename,
+ uint64_t filesize,
+ uint64_t completed,
+ const char *emsg);
+
+
+/**
+ * FS notified us that our undex operation was stopped.
+ *
+ * @param ue operation that stopped
+ */
+void
+GNUNET_FS_GTK_unindex_handle_stop_ (struct UnindexEntry *ue);
+
+
+/**
+ * FS notified us that our undex operation had an error.
+ *
+ * @param ue operation that
+ * @param emsg error message
+ */
+void
+GNUNET_FS_GTK_unindex_handle_error_ (struct UnindexEntry *ue,
+ const char *emsg);
+
+
+/**
+ * FS notified us that our undex operation made progress
+ *
+ * @param ue operation that made progress
+ * @param completed number of bytes completed now
+ */
+void
+GNUNET_FS_GTK_unindex_handle_progress_ (struct UnindexEntry *ue,
+ uint64_t completed);
+
+
+/**
+ * FS notified us that our undex operation completed
+ *
+ * @param ue operation that completed
+ */
+void
+GNUNET_FS_GTK_unindex_handle_completed_ (struct UnindexEntry *ue);
+
+
+
+
+#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r20422 - in gnunet-gtk: contrib src/fs,
gnunet <=