diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-03-09 21:25:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-03-09 21:25:10 +0000 |
commit | 33a587e38df10dc5a8168ff1fa5d0ef1b328454e (patch) | |
tree | 4db54c3c4ba02cc68a0fdd4898acc60561c2ed14 | |
parent | b94f48844921120496cabc01922d2bf2d3df4ebd (diff) | |
download | gnunet-gtk-33a587e38df10dc5a8168ff1fa5d0ef1b328454e.tar.gz gnunet-gtk-33a587e38df10dc5a8168ff1fa5d0ef1b328454e.zip |
implementing listing of indexed files and unindexing from gnunet-fs-gtk (#1945)
-rw-r--r-- | contrib/Makefile.am | 1 | ||||
-rw-r--r-- | contrib/gnunet_fs_gtk_main_window.glade | 8 | ||||
-rw-r--r-- | contrib/gnunet_fs_gtk_unindex.glade | 154 | ||||
-rw-r--r-- | src/fs/Makefile.am | 1 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk_event-handler.c | 40 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk_unindex.c | 584 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk_unindex.h | 99 |
7 files changed, 869 insertions, 18 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 2f87c8ec..f862f77c 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am | |||
@@ -27,6 +27,7 @@ pkgdata_DATA = \ | |||
27 | gnunet_fs_gtk_publish_tab.glade \ | 27 | gnunet_fs_gtk_publish_tab.glade \ |
28 | gnunet_fs_gtk_search_tab.glade \ | 28 | gnunet_fs_gtk_search_tab.glade \ |
29 | gnunet_fs_gtk_select_pseudonym_dialog.glade \ | 29 | gnunet_fs_gtk_select_pseudonym_dialog.glade \ |
30 | gnunet_fs_gtk_unindex.glade \ | ||
30 | gnunet_fs_gtk_progress_dialog.glade \ | 31 | gnunet_fs_gtk_progress_dialog.glade \ |
31 | gnunet_gns_gtk_about_window.glade \ | 32 | gnunet_gns_gtk_about_window.glade \ |
32 | gnunet_gns_gtk_main_window.glade \ | 33 | gnunet_gns_gtk_main_window.glade \ |
diff --git a/contrib/gnunet_fs_gtk_main_window.glade b/contrib/gnunet_fs_gtk_main_window.glade index 3186c010..3b4f615d 100644 --- a/contrib/gnunet_fs_gtk_main_window.glade +++ b/contrib/gnunet_fs_gtk_main_window.glade | |||
@@ -192,6 +192,14 @@ | |||
192 | </object> | 192 | </object> |
193 | </child> | 193 | </child> |
194 | <child> | 194 | <child> |
195 | <object class="GtkMenuItem" id="GNUNET_GTK_main_menu_unindex"> | ||
196 | <property name="visible">True</property> | ||
197 | <property name="label" translatable="yes">_List indexed files</property> | ||
198 | <property name="use_underline">True</property> | ||
199 | <signal name="activate" handler="GNUNET_GTK_main_menu_unindex_activate_cb"/> | ||
200 | </object> | ||
201 | </child> | ||
202 | <child> | ||
195 | <object class="GtkSeparatorMenuItem" id="GNUNET_GTK_main_menu_file_sep1"> | 203 | <object class="GtkSeparatorMenuItem" id="GNUNET_GTK_main_menu_file_sep1"> |
196 | <property name="visible">True</property> | 204 | <property name="visible">True</property> |
197 | </object> | 205 | </object> |
diff --git a/contrib/gnunet_fs_gtk_unindex.glade b/contrib/gnunet_fs_gtk_unindex.glade new file mode 100644 index 00000000..90d6cab5 --- /dev/null +++ b/contrib/gnunet_fs_gtk_unindex.glade | |||
@@ -0,0 +1,154 @@ | |||
1 | <?xml version="1.0"?> | ||
2 | <interface> | ||
3 | <requires lib="gtk+" version="2.16"/> | ||
4 | <!-- interface-naming-policy project-wide --> | ||
5 | <object class="GtkListStore" id="GNUNET_FS_GTK_unindex_liststore"> | ||
6 | <columns> | ||
7 | <!-- column-name filename --> | ||
8 | <column type="gchararray"/> | ||
9 | <!-- column-name filesize --> | ||
10 | <column type="guint64"/> | ||
11 | <!-- column-name background_color --> | ||
12 | <column type="gchararray"/> | ||
13 | <!-- column-name unindex_context --> | ||
14 | <column type="gpointer"/> | ||
15 | <!-- column-name unindex_progress --> | ||
16 | <column type="gint"/> | ||
17 | <!-- column-name progress_visible --> | ||
18 | <column type="gboolean"/> | ||
19 | <!-- column-name error_message --> | ||
20 | <column type="gchararray"/> | ||
21 | </columns> | ||
22 | </object> | ||
23 | <object class="GtkDialog" id="GNUNET_FS_GTK_unindex_dialog"> | ||
24 | <property name="width_request">600</property> | ||
25 | <property name="height_request">300</property> | ||
26 | <property name="border_width">5</property> | ||
27 | <property name="title" translatable="yes">Indexed files</property> | ||
28 | <property name="icon_name">folder</property> | ||
29 | <property name="type_hint">normal</property> | ||
30 | <property name="has_separator">False</property> | ||
31 | <child internal-child="vbox"> | ||
32 | <object class="GtkVBox" id="GNUNET_FS_GTK_unindex_dialog-vbox"> | ||
33 | <property name="visible">True</property> | ||
34 | <property name="orientation">vertical</property> | ||
35 | <property name="spacing">2</property> | ||
36 | <child> | ||
37 | <object class="GtkScrolledWindow" id="GNUNET_FS_GTK_unindex_scrolledwindow"> | ||
38 | <property name="visible">True</property> | ||
39 | <property name="can_focus">True</property> | ||
40 | <property name="hscrollbar_policy">automatic</property> | ||
41 | <property name="vscrollbar_policy">automatic</property> | ||
42 | <child> | ||
43 | <object class="GtkTreeView" id="GNUNET_FS_GTK_unindex_treeview"> | ||
44 | <property name="visible">True</property> | ||
45 | <property name="can_focus">True</property> | ||
46 | <property name="model">GNUNET_FS_GTK_unindex_liststore</property> | ||
47 | <child> | ||
48 | <object class="GtkTreeViewColumn" id="GNUNET_FS_GTK_unindex_filesize_treeviewcolumn"> | ||
49 | <property name="sizing">autosize</property> | ||
50 | <property name="title">Size</property> | ||
51 | <property name="reorderable">True</property> | ||
52 | <property name="sort_indicator">True</property> | ||
53 | <property name="sort_column_id">1</property> | ||
54 | <child> | ||
55 | <object class="GtkCellRendererText" id="GNUNET_FS_GTK_unindex_cellrenderertext"/> | ||
56 | <attributes> | ||
57 | <attribute name="background">2</attribute> | ||
58 | <attribute name="text">1</attribute> | ||
59 | </attributes> | ||
60 | </child> | ||
61 | </object> | ||
62 | </child> | ||
63 | <child> | ||
64 | <object class="GtkTreeViewColumn" id="GNUNET_FS_GTK_unindex_filename_treeviewcolumn"> | ||
65 | <property name="title">Filename</property> | ||
66 | <property name="reorderable">True</property> | ||
67 | <property name="sort_indicator">True</property> | ||
68 | <property name="sort_column_id">0</property> | ||
69 | <child> | ||
70 | <object class="GtkCellRendererText" id="GNUNET_FS_GTK_unindex_filename_cellrenderertext"/> | ||
71 | <attributes> | ||
72 | <attribute name="background">2</attribute> | ||
73 | <attribute name="text">0</attribute> | ||
74 | </attributes> | ||
75 | </child> | ||
76 | </object> | ||
77 | </child> | ||
78 | <child> | ||
79 | <object class="GtkTreeViewColumn" id="GNUNET_FS_GTK_unindex_progress_treeviewcolumn"> | ||
80 | <property name="min_width">9</property> | ||
81 | <property name="title">Unindex progress</property> | ||
82 | <child> | ||
83 | <object class="GtkCellRendererProgress" id="GNUNET_FS_GTK_unindex_progress_cellrendererprogress"/> | ||
84 | <attributes> | ||
85 | <attribute name="visible">5</attribute> | ||
86 | <attribute name="text">6</attribute> | ||
87 | <attribute name="value">4</attribute> | ||
88 | </attributes> | ||
89 | </child> | ||
90 | </object> | ||
91 | </child> | ||
92 | </object> | ||
93 | </child> | ||
94 | </object> | ||
95 | <packing> | ||
96 | <property name="position">1</property> | ||
97 | </packing> | ||
98 | </child> | ||
99 | <child internal-child="action_area"> | ||
100 | <object class="GtkHButtonBox" id="GNUNET_FS_GTK_unindex_dialog-action_area"> | ||
101 | <property name="visible">True</property> | ||
102 | <property name="layout_style">end</property> | ||
103 | <child> | ||
104 | <object class="GtkButton" id="GNUNET_FS_GTK_unindex_button"> | ||
105 | <property name="label">_Unindex</property> | ||
106 | <property name="visible">True</property> | ||
107 | <property name="sensitive">False</property> | ||
108 | <property name="can_focus">True</property> | ||
109 | <property name="receives_default">True</property> | ||
110 | <property name="tooltip_text" translatable="yes">Unindex the selected indexed file.</property> | ||
111 | <property name="image">GNUNET_FS_GTK_unindex_delete_image</property> | ||
112 | <property name="use_underline">True</property> | ||
113 | <signal name="clicked" handler="GNUNET_FS_GTK_unindex_button_clicked_cb"/> | ||
114 | </object> | ||
115 | <packing> | ||
116 | <property name="expand">False</property> | ||
117 | <property name="fill">False</property> | ||
118 | <property name="position">0</property> | ||
119 | </packing> | ||
120 | </child> | ||
121 | <child> | ||
122 | <object class="GtkButton" id="GNUNET_FS_GTK_unindex_close_button"> | ||
123 | <property name="label">gtk-close</property> | ||
124 | <property name="visible">True</property> | ||
125 | <property name="can_focus">True</property> | ||
126 | <property name="receives_default">True</property> | ||
127 | <property name="use_stock">True</property> | ||
128 | <signal name="clicked" handler="GNUNET_FS_GTK_unindex_close_button_clicked_cb"/> | ||
129 | </object> | ||
130 | <packing> | ||
131 | <property name="expand">False</property> | ||
132 | <property name="fill">False</property> | ||
133 | <property name="position">1</property> | ||
134 | </packing> | ||
135 | </child> | ||
136 | </object> | ||
137 | <packing> | ||
138 | <property name="expand">False</property> | ||
139 | <property name="pack_type">end</property> | ||
140 | <property name="position">0</property> | ||
141 | </packing> | ||
142 | </child> | ||
143 | </object> | ||
144 | </child> | ||
145 | <action-widgets> | ||
146 | <action-widget response="0">GNUNET_FS_GTK_unindex_button</action-widget> | ||
147 | <action-widget response="0">GNUNET_FS_GTK_unindex_close_button</action-widget> | ||
148 | </action-widgets> | ||
149 | </object> | ||
150 | <object class="GtkImage" id="GNUNET_FS_GTK_unindex_delete_image"> | ||
151 | <property name="visible">True</property> | ||
152 | <property name="stock">gtk-delete</property> | ||
153 | </object> | ||
154 | </interface> | ||
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am index 8949063f..a4d590c7 100644 --- a/src/fs/Makefile.am +++ b/src/fs/Makefile.am | |||
@@ -24,6 +24,7 @@ gnunet_fs_gtk_SOURCES = \ | |||
24 | gnunet-fs-gtk_main-window-view-toggles.c \ | 24 | gnunet-fs-gtk_main-window-view-toggles.c \ |
25 | gnunet-fs-gtk_open-directory.c \ | 25 | gnunet-fs-gtk_open-directory.c \ |
26 | gnunet-fs-gtk_open-uri.c \ | 26 | gnunet-fs-gtk_open-uri.c \ |
27 | gnunet-fs-gtk_unindex.c gnunet-fs-gtk_unindex.h \ | ||
27 | gnunet-fs-gtk_publish-dialog.c \ | 28 | gnunet-fs-gtk_publish-dialog.c \ |
28 | gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \ | 29 | gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \ |
29 | gnunet-fs-gtk_namespace_manager.c | 30 | gnunet-fs-gtk_namespace_manager.c |
diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c index 49483158..3643d379 100644 --- a/src/fs/gnunet-fs-gtk_event-handler.c +++ b/src/fs/gnunet-fs-gtk_event-handler.c | |||
@@ -27,7 +27,7 @@ | |||
27 | #include "gnunet-fs-gtk_common.h" | 27 | #include "gnunet-fs-gtk_common.h" |
28 | #include "gnunet-fs-gtk_download-save-as.h" | 28 | #include "gnunet-fs-gtk_download-save-as.h" |
29 | #include "gnunet-fs-gtk_event-handler.h" | 29 | #include "gnunet-fs-gtk_event-handler.h" |
30 | 30 | #include "gnunet-fs-gtk_unindex.h" | |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * We have a single tab where we display publishing operations. | 33 | * We have a single tab where we display publishing operations. |
@@ -1366,7 +1366,7 @@ GNUNET_FS_GTK_search_result_clear_button_clicked (GtkButton * button, gpointer u | |||
1366 | GtkTreeIter iter; | 1366 | GtkTreeIter iter; |
1367 | 1367 | ||
1368 | tm = GTK_TREE_MODEL (tab->ts); | 1368 | tm = GTK_TREE_MODEL (tab->ts); |
1369 | if (TRUE != gtk_tree_model_get_iter_first (tm, &iter)) | 1369 | if (! gtk_tree_model_get_iter_first (tm, &iter)) |
1370 | return; | 1370 | return; |
1371 | do | 1371 | do |
1372 | { | 1372 | { |
@@ -1386,11 +1386,11 @@ GNUNET_FS_GTK_search_result_clear_button_clicked (GtkButton * button, gpointer u | |||
1386 | directory; clean it up */ | 1386 | directory; clean it up */ |
1387 | free_search_result (sr); | 1387 | free_search_result (sr); |
1388 | /* the above call clobbered our 'iter', restart from the beginning... */ | 1388 | /* the above call clobbered our 'iter', restart from the beginning... */ |
1389 | if (TRUE != gtk_tree_model_get_iter_first (tm, &iter)) | 1389 | if (! gtk_tree_model_get_iter_first (tm, &iter)) |
1390 | return; | 1390 | return; |
1391 | } | 1391 | } |
1392 | } | 1392 | } |
1393 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | 1393 | while (gtk_tree_model_iter_next (tm, &iter)); |
1394 | } | 1394 | } |
1395 | 1395 | ||
1396 | 1396 | ||
@@ -3001,26 +3001,30 @@ GNUNET_GTK_fs_event_handler (void *cls, | |||
3001 | close_search_tab (info->value.search.cctx); | 3001 | close_search_tab (info->value.search.cctx); |
3002 | return NULL; | 3002 | return NULL; |
3003 | case GNUNET_FS_STATUS_UNINDEX_START: | 3003 | case GNUNET_FS_STATUS_UNINDEX_START: |
3004 | GNUNET_break (0); | 3004 | return info->value.unindex.cctx; |
3005 | break; | ||
3006 | case GNUNET_FS_STATUS_UNINDEX_RESUME: | 3005 | case GNUNET_FS_STATUS_UNINDEX_RESUME: |
3007 | GNUNET_break (0); | 3006 | return GNUNET_FS_GTK_unindex_handle_resume_ (info->value.unindex.uc, |
3008 | break; | 3007 | info->value.unindex.filename, |
3008 | info->value.unindex.size, | ||
3009 | info->value.unindex.completed, | ||
3010 | info->value.unindex.specifics.resume.message); | ||
3009 | case GNUNET_FS_STATUS_UNINDEX_SUSPEND: | 3011 | case GNUNET_FS_STATUS_UNINDEX_SUSPEND: |
3010 | GNUNET_break (0); | 3012 | GNUNET_FS_GTK_unindex_handle_stop_ (info->value.unindex.cctx); |
3011 | break; | 3013 | return NULL; |
3012 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | 3014 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: |
3013 | GNUNET_break (0); | 3015 | GNUNET_FS_GTK_unindex_handle_progress_ (info->value.unindex.cctx, |
3014 | break; | 3016 | info->value.unindex.completed); |
3017 | return info->value.unindex.cctx; | ||
3015 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | 3018 | case GNUNET_FS_STATUS_UNINDEX_ERROR: |
3016 | GNUNET_break (0); | 3019 | GNUNET_FS_GTK_unindex_handle_error_ (info->value.unindex.cctx, |
3017 | break; | 3020 | info->value.unindex.specifics.error.message); |
3021 | return info->value.unindex.cctx; | ||
3018 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | 3022 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: |
3019 | GNUNET_break (0); | 3023 | GNUNET_FS_GTK_unindex_handle_completed_ (info->value.unindex.cctx); |
3020 | break; | 3024 | return info->value.unindex.cctx; |
3021 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | 3025 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: |
3022 | GNUNET_break (0); | 3026 | GNUNET_FS_GTK_unindex_handle_stop_ (info->value.unindex.cctx); |
3023 | break; | 3027 | return NULL; |
3024 | default: | 3028 | default: |
3025 | GNUNET_break (0); | 3029 | GNUNET_break (0); |
3026 | break; | 3030 | break; |
diff --git a/src/fs/gnunet-fs-gtk_unindex.c b/src/fs/gnunet-fs-gtk_unindex.c new file mode 100644 index 00000000..1c49747a --- /dev/null +++ b/src/fs/gnunet-fs-gtk_unindex.c | |||
@@ -0,0 +1,584 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file src/fs/gnunet-fs-gtk_unindex.c | ||
23 | * @author Christian Grothoff | ||
24 | * @brief operations to display and unindex indexed files | ||
25 | */ | ||
26 | #include "gnunet-fs-gtk.h" | ||
27 | #include "gnunet-fs-gtk_common.h" | ||
28 | #include "gnunet-fs-gtk_event-handler.h" | ||
29 | #include "gnunet-fs-gtk_unindex.h" | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Columns in the unindex model. | ||
34 | */ | ||
35 | enum UNINDEX_ModelColumns | ||
36 | { | ||
37 | /** | ||
38 | * A gchararray. | ||
39 | */ | ||
40 | UNINDEX_MC_FILENAME = 0, | ||
41 | |||
42 | /** | ||
43 | * A guint64. | ||
44 | */ | ||
45 | UNINDEX_MC_FILESIZE = 1, | ||
46 | |||
47 | /** | ||
48 | * A gchararray representing a color. | ||
49 | */ | ||
50 | UNINDEX_MC_BACKGROUND_COLOR = 2, | ||
51 | |||
52 | /** | ||
53 | * A 'struct UnindexEntry' (gpointer) | ||
54 | */ | ||
55 | UNINDEX_MC_UNINDEX_CONTEXT = 3, | ||
56 | |||
57 | /** | ||
58 | * A gfloat. | ||
59 | */ | ||
60 | UNINDEX_MC_UNINDEX_PROGRESS = 4, | ||
61 | |||
62 | /** | ||
63 | * A boolean. | ||
64 | */ | ||
65 | UNINDEX_MC_PROGRESS_VISIBLE = 5, | ||
66 | |||
67 | /** | ||
68 | * A gchararray. | ||
69 | */ | ||
70 | UNINDEX_MC_ERROR = 6 | ||
71 | }; | ||
72 | |||
73 | |||
74 | /** | ||
75 | * Overall context for the dialog. | ||
76 | */ | ||
77 | struct UnindexDialogContext | ||
78 | { | ||
79 | GtkBuilder *builder; | ||
80 | |||
81 | /** | ||
82 | * The dialog object. | ||
83 | */ | ||
84 | GtkWidget *dialog; | ||
85 | |||
86 | /** | ||
87 | * The unindex button. | ||
88 | */ | ||
89 | GtkWidget *unindex_button; | ||
90 | |||
91 | /** | ||
92 | * Main treeview object. | ||
93 | */ | ||
94 | GtkTreeView *treeview; | ||
95 | |||
96 | /** | ||
97 | * Selection of our treeview. | ||
98 | */ | ||
99 | GtkTreeSelection *selection; | ||
100 | |||
101 | /** | ||
102 | * Unindex data model. | ||
103 | */ | ||
104 | GtkTreeModel *model; | ||
105 | |||
106 | /** | ||
107 | * Context for initial listing of indexed files. | ||
108 | */ | ||
109 | struct GNUNET_FS_GetIndexedContext *gic; | ||
110 | }; | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Information for a specific unindex operation. | ||
115 | */ | ||
116 | struct UnindexEntry | ||
117 | { | ||
118 | |||
119 | /** | ||
120 | * Kept in a DLL. | ||
121 | */ | ||
122 | struct UnindexEntry *next; | ||
123 | |||
124 | /** | ||
125 | * Next entry. | ||
126 | */ | ||
127 | struct UnindexEntry *prev; | ||
128 | |||
129 | /** | ||
130 | * Name of the file being unindexed. | ||
131 | */ | ||
132 | char *filename; | ||
133 | |||
134 | /** | ||
135 | * Error description, NULL if no error | ||
136 | */ | ||
137 | char *emsg; | ||
138 | |||
139 | /** | ||
140 | * Handle with FS. | ||
141 | */ | ||
142 | struct GNUNET_FS_UnindexContext *uc; | ||
143 | |||
144 | /** | ||
145 | * Row reference, NULL if the dialog is not open. | ||
146 | */ | ||
147 | GtkTreeRowReference *rr; | ||
148 | |||
149 | /** | ||
150 | * Size of the file. | ||
151 | */ | ||
152 | uint64_t filesize; | ||
153 | |||
154 | /** | ||
155 | * Percentage progress made so far. | ||
156 | */ | ||
157 | gint progress; | ||
158 | }; | ||
159 | |||
160 | |||
161 | /** | ||
162 | * There can only be one. | ||
163 | */ | ||
164 | static struct UnindexDialogContext *master_udc; | ||
165 | |||
166 | /** | ||
167 | * Head of linked list. | ||
168 | */ | ||
169 | static struct UnindexEntry *ue_head; | ||
170 | |||
171 | /** | ||
172 | * Tail of linked list. | ||
173 | */ | ||
174 | static struct UnindexEntry *ue_tail; | ||
175 | |||
176 | |||
177 | /** | ||
178 | * User has clicked on the 'delete/unindex' button for the dialog. | ||
179 | * Unindex the selected file. | ||
180 | * | ||
181 | * @param dummy the button | ||
182 | * @param user_data the unindex context | ||
183 | */ | ||
184 | void | ||
185 | GNUNET_FS_GTK_unindex_button_clicked_cb (GtkWidget * dummy, | ||
186 | gpointer user_data) | ||
187 | { | ||
188 | struct UnindexDialogContext *udc = user_data; | ||
189 | GtkTreeIter iter; | ||
190 | char *filename; | ||
191 | struct UnindexEntry *ue; | ||
192 | GtkTreePath *path; | ||
193 | guint64 filesize; | ||
194 | |||
195 | /* find out if a file is selected */ | ||
196 | if (! gtk_tree_selection_get_selected (udc->selection, NULL, &iter)) | ||
197 | { | ||
198 | GNUNET_break (0); | ||
199 | return; | ||
200 | } | ||
201 | gtk_tree_model_get (udc->model, &iter, | ||
202 | UNINDEX_MC_FILENAME, &filename, | ||
203 | UNINDEX_MC_FILESIZE, &filesize, | ||
204 | UNINDEX_MC_UNINDEX_CONTEXT, &ue, | ||
205 | -1); | ||
206 | if (NULL != ue) | ||
207 | { | ||
208 | GNUNET_break (0); | ||
209 | g_free (filename); | ||
210 | return; | ||
211 | } | ||
212 | ue = GNUNET_malloc (sizeof (struct UnindexEntry)); | ||
213 | ue->filesize = filesize; | ||
214 | GNUNET_CONTAINER_DLL_insert (ue_head, ue_tail, ue); | ||
215 | ue->filename = GNUNET_strdup (filename); | ||
216 | path = gtk_tree_model_get_path (udc->model, &iter); | ||
217 | ue->rr = gtk_tree_row_reference_new (udc->model, path); | ||
218 | gtk_tree_path_free (path); | ||
219 | ue->uc = GNUNET_FS_unindex_start (GNUNET_FS_GTK_get_fs_handle (), | ||
220 | filename, ue); | ||
221 | gtk_list_store_set (GTK_LIST_STORE (udc->model), | ||
222 | &iter, | ||
223 | UNINDEX_MC_BACKGROUND_COLOR, "yellow", | ||
224 | UNINDEX_MC_UNINDEX_CONTEXT, ue, | ||
225 | UNINDEX_MC_UNINDEX_PROGRESS, 0, | ||
226 | UNINDEX_MC_PROGRESS_VISIBLE, TRUE, | ||
227 | -1); | ||
228 | gtk_widget_set_sensitive (udc->unindex_button, FALSE); | ||
229 | } | ||
230 | |||
231 | |||
232 | /** | ||
233 | * User has clicked on the 'close' button for the dialog. Close it. | ||
234 | * | ||
235 | * @param dummy the button | ||
236 | * @param user_data the unindex context | ||
237 | */ | ||
238 | void | ||
239 | GNUNET_FS_GTK_unindex_close_button_clicked_cb (GtkWidget * dummy, | ||
240 | gpointer user_data) | ||
241 | { | ||
242 | struct UnindexDialogContext *udc = user_data; | ||
243 | GtkTreeIter iter; | ||
244 | struct UnindexEntry *ue; | ||
245 | |||
246 | if (NULL != udc->gic) | ||
247 | { | ||
248 | GNUNET_FS_get_indexed_files_cancel (udc->gic); | ||
249 | udc->gic = NULL; | ||
250 | } | ||
251 | if (gtk_tree_model_get_iter_first (udc->model, &iter)) | ||
252 | do | ||
253 | { | ||
254 | gtk_tree_model_get (udc->model, &iter, | ||
255 | UNINDEX_MC_UNINDEX_CONTEXT, &ue, | ||
256 | -1); | ||
257 | if (NULL != ue) | ||
258 | { | ||
259 | gtk_tree_row_reference_free (ue->rr); | ||
260 | ue->rr = NULL; | ||
261 | } | ||
262 | } | ||
263 | while (TRUE == gtk_tree_model_iter_next (udc->model, &iter)); | ||
264 | gtk_widget_destroy (udc->dialog); | ||
265 | g_object_unref (G_OBJECT (udc->builder)); | ||
266 | GNUNET_free (udc); | ||
267 | master_udc = NULL; | ||
268 | } | ||
269 | |||
270 | |||
271 | /** | ||
272 | * The selection in the tree view changed; update the button sensitivity. | ||
273 | * | ||
274 | * @param ts the changed selection | ||
275 | * @param user_data our unindex context | ||
276 | */ | ||
277 | static void | ||
278 | selection_changed_cb (GtkTreeSelection * ts, | ||
279 | gpointer user_data) | ||
280 | { | ||
281 | struct UnindexDialogContext *udc = user_data; | ||
282 | GtkTreeIter iter; | ||
283 | struct UnindexEntry *ue; | ||
284 | |||
285 | /* find out if a file is selected */ | ||
286 | if (gtk_tree_selection_get_selected (udc->selection, NULL, &iter)) | ||
287 | { | ||
288 | gtk_tree_model_get (udc->model, &iter, | ||
289 | UNINDEX_MC_UNINDEX_CONTEXT, &ue, | ||
290 | -1); | ||
291 | if (NULL == ue) | ||
292 | { | ||
293 | /* selected file not already being unindexed, enable button! */ | ||
294 | gtk_widget_set_sensitive (udc->unindex_button, TRUE); | ||
295 | return; | ||
296 | } | ||
297 | } | ||
298 | gtk_widget_set_sensitive (udc->unindex_button, FALSE); | ||
299 | } | ||
300 | |||
301 | |||
302 | /** | ||
303 | * Type of a function called by "GNUNET_FS_get_indexed_files". | ||
304 | * | ||
305 | * @param cls closure | ||
306 | * @param filename the name of the file, NULL for end of list | ||
307 | * @param file_id hash of the contents of the indexed file | ||
308 | * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort | ||
309 | */ | ||
310 | static int | ||
311 | add_indexed_file (void *cls, const char *filename, | ||
312 | const GNUNET_HashCode * file_id) | ||
313 | { | ||
314 | struct UnindexDialogContext *udc = cls; | ||
315 | GtkTreeIter iter; | ||
316 | uint64_t filesize; | ||
317 | struct UnindexEntry *ue; | ||
318 | GtkTreePath *path; | ||
319 | |||
320 | if (NULL == filename) | ||
321 | { | ||
322 | /* end of list */ | ||
323 | udc->gic = NULL; | ||
324 | return GNUNET_OK; | ||
325 | } | ||
326 | if (GNUNET_OK != | ||
327 | GNUNET_DISK_file_size (filename, | ||
328 | &filesize, | ||
329 | GNUNET_YES)) | ||
330 | { | ||
331 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
332 | _("Could not access indexed file `%s'\n"), | ||
333 | filename); | ||
334 | return GNUNET_OK; | ||
335 | } | ||
336 | for (ue = ue_head; ue != NULL; ue = ue->next) | ||
337 | if (0 == strcmp (ue->filename, filename)) | ||
338 | break; | ||
339 | if (NULL == ue) | ||
340 | { | ||
341 | gtk_list_store_insert_with_values (GTK_LIST_STORE (udc->model), | ||
342 | &iter, G_MAXINT, | ||
343 | UNINDEX_MC_FILENAME, filename, | ||
344 | UNINDEX_MC_FILESIZE, (guint64) filesize, | ||
345 | UNINDEX_MC_BACKGROUND_COLOR, "white", | ||
346 | UNINDEX_MC_PROGRESS_VISIBLE, FALSE, | ||
347 | -1); | ||
348 | } | ||
349 | else | ||
350 | { | ||
351 | if (NULL != ue->rr) | ||
352 | { | ||
353 | GNUNET_break (0); | ||
354 | return GNUNET_OK; | ||
355 | } | ||
356 | gtk_list_store_insert_with_values (GTK_LIST_STORE (udc->model), | ||
357 | &iter, G_MAXINT, | ||
358 | UNINDEX_MC_FILENAME, filename, | ||
359 | UNINDEX_MC_FILESIZE, (guint64) filesize, | ||
360 | UNINDEX_MC_BACKGROUND_COLOR, (NULL == ue->emsg) ? "yellow" : "red", | ||
361 | UNINDEX_MC_UNINDEX_CONTEXT, ue, | ||
362 | UNINDEX_MC_UNINDEX_PROGRESS, ue->progress, | ||
363 | UNINDEX_MC_PROGRESS_VISIBLE, TRUE, | ||
364 | UNINDEX_MC_ERROR, ue->emsg, | ||
365 | -1); | ||
366 | path = gtk_tree_model_get_path (udc->model, &iter); | ||
367 | ue->rr = gtk_tree_row_reference_new (udc->model, path); | ||
368 | } | ||
369 | return GNUNET_OK; | ||
370 | } | ||
371 | |||
372 | |||
373 | /** | ||
374 | * User selected "List indexed files..." in menu. Display dialog. | ||
375 | * | ||
376 | * @param dummy the menu entry | ||
377 | * @param user_data the main dialog builder, unused | ||
378 | */ | ||
379 | void | ||
380 | GNUNET_GTK_main_menu_unindex_activate_cb (GtkWidget * dummy, | ||
381 | gpointer data) | ||
382 | { | ||
383 | GtkWidget *toplevel; | ||
384 | struct UnindexDialogContext *udc; | ||
385 | |||
386 | if (NULL != master_udc) | ||
387 | { | ||
388 | /* window already exists, raise focus */ | ||
389 | gtk_window_present (GTK_WINDOW (master_udc->dialog)); | ||
390 | return; | ||
391 | } | ||
392 | udc = GNUNET_malloc (sizeof (struct UnindexDialogContext)); | ||
393 | udc->builder = | ||
394 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_unindex.glade", udc); | ||
395 | if (NULL == udc->builder) | ||
396 | { | ||
397 | GNUNET_break (0); | ||
398 | GNUNET_free (udc); | ||
399 | return; | ||
400 | } | ||
401 | udc->dialog = GTK_WIDGET (gtk_builder_get_object | ||
402 | (udc->builder, "GNUNET_FS_GTK_unindex_dialog")); | ||
403 | udc->treeview = GTK_TREE_VIEW (gtk_builder_get_object | ||
404 | (udc->builder, "GNUNET_FS_GTK_unindex_treeview")); | ||
405 | udc->selection = gtk_tree_view_get_selection (udc->treeview); | ||
406 | udc->unindex_button = GTK_WIDGET (gtk_builder_get_object | ||
407 | (udc->builder, "GNUNET_FS_GTK_unindex_button")); | ||
408 | udc->model = GTK_TREE_MODEL (gtk_builder_get_object | ||
409 | (udc->builder, "GNUNET_FS_GTK_unindex_liststore")); | ||
410 | udc->gic = GNUNET_FS_get_indexed_files (GNUNET_FS_GTK_get_fs_handle (), | ||
411 | &add_indexed_file, | ||
412 | udc); | ||
413 | toplevel = gtk_widget_get_toplevel (dummy); | ||
414 | if (GTK_IS_WINDOW (toplevel)) | ||
415 | gtk_window_set_transient_for (GTK_WINDOW (udc->dialog), GTK_WINDOW (toplevel)); | ||
416 | /* connect signals; FIXME-GTK3: these could be connected with (modern) Glade */ | ||
417 | g_signal_connect (G_OBJECT (udc->selection), "changed", | ||
418 | G_CALLBACK (selection_changed_cb), udc); | ||
419 | gtk_window_present (GTK_WINDOW (udc->dialog)); | ||
420 | master_udc = udc; | ||
421 | } | ||
422 | |||
423 | |||
424 | /** | ||
425 | * An unindex operation resumed. Setup the | ||
426 | * internal context for Gtk. | ||
427 | * | ||
428 | * @param fs unindex context with the FS library | ||
429 | * @param filename name of file being unindexed | ||
430 | * @param filesize size of the file | ||
431 | * @param completed how many bytes were done so far | ||
432 | * @param emsg NULL if everything is fine, otherwise error message | ||
433 | */ | ||
434 | struct UnindexEntry * | ||
435 | GNUNET_FS_GTK_unindex_handle_resume_ (struct GNUNET_FS_UnindexContext *uc, | ||
436 | const char *filename, | ||
437 | uint64_t filesize, | ||
438 | uint64_t completed, | ||
439 | const char *emsg) | ||
440 | { | ||
441 | struct UnindexEntry *ue; | ||
442 | |||
443 | ue = GNUNET_malloc (sizeof (struct UnindexEntry)); | ||
444 | ue->filename = GNUNET_strdup (filename); | ||
445 | if (NULL != emsg) | ||
446 | ue->emsg = GNUNET_strdup (emsg); | ||
447 | ue->filesize = filesize; | ||
448 | ue->uc = uc; | ||
449 | ue->progress = (gint) ((100LL * completed) / filesize); | ||
450 | GNUNET_CONTAINER_DLL_insert (ue_head, | ||
451 | ue_tail, | ||
452 | ue); | ||
453 | return ue; | ||
454 | } | ||
455 | |||
456 | |||
457 | /** | ||
458 | * FS notified us that our undex operation was stopped. | ||
459 | * | ||
460 | * @param ue operation that stopped | ||
461 | */ | ||
462 | void | ||
463 | GNUNET_FS_GTK_unindex_handle_stop_ (struct UnindexEntry *ue) | ||
464 | { | ||
465 | GtkTreePath *path; | ||
466 | GtkTreeIter iter; | ||
467 | GtkTreeModel *model; | ||
468 | |||
469 | if (NULL != ue->rr) | ||
470 | { | ||
471 | path = gtk_tree_row_reference_get_path (ue->rr); | ||
472 | model = gtk_tree_row_reference_get_model (ue->rr); | ||
473 | gtk_tree_row_reference_free (ue->rr); | ||
474 | ue->rr = NULL; | ||
475 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (model, | ||
476 | &iter, | ||
477 | path)); | ||
478 | gtk_tree_path_free (path); | ||
479 | gtk_list_store_set (GTK_LIST_STORE (model), | ||
480 | &iter, | ||
481 | UNINDEX_MC_UNINDEX_CONTEXT, NULL, | ||
482 | -1); | ||
483 | } | ||
484 | GNUNET_CONTAINER_DLL_remove (ue_head, | ||
485 | ue_tail, | ||
486 | ue); | ||
487 | GNUNET_free_non_null (ue->emsg); | ||
488 | GNUNET_free (ue->filename); | ||
489 | GNUNET_free (ue); | ||
490 | } | ||
491 | |||
492 | |||
493 | /** | ||
494 | * FS notified us that our undex operation had an error. | ||
495 | * | ||
496 | * @param ue operation that had an error | ||
497 | * @param emsg error message | ||
498 | */ | ||
499 | void | ||
500 | GNUNET_FS_GTK_unindex_handle_error_ (struct UnindexEntry *ue, | ||
501 | const char *emsg) | ||
502 | { | ||
503 | GtkTreePath *path; | ||
504 | GtkTreeIter iter; | ||
505 | GtkTreeModel *model; | ||
506 | |||
507 | ue->emsg = GNUNET_strdup (emsg); | ||
508 | if (NULL == ue->rr) | ||
509 | return; | ||
510 | path = gtk_tree_row_reference_get_path (ue->rr); | ||
511 | model = gtk_tree_row_reference_get_model (ue->rr); | ||
512 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (model, | ||
513 | &iter, | ||
514 | path)); | ||
515 | gtk_tree_path_free (path); | ||
516 | gtk_list_store_set (GTK_LIST_STORE (model), | ||
517 | &iter, | ||
518 | UNINDEX_MC_BACKGROUND_COLOR, "red", | ||
519 | UNINDEX_MC_ERROR, emsg, | ||
520 | -1); | ||
521 | } | ||
522 | |||
523 | |||
524 | /** | ||
525 | * FS notified us that our undex operation made progress | ||
526 | * | ||
527 | * @param ue operation that made progress | ||
528 | * @param completed number of bytes completed now | ||
529 | */ | ||
530 | void | ||
531 | GNUNET_FS_GTK_unindex_handle_progress_ (struct UnindexEntry *ue, | ||
532 | uint64_t completed) | ||
533 | { | ||
534 | GtkTreePath *path; | ||
535 | GtkTreeIter iter; | ||
536 | GtkTreeModel *model; | ||
537 | |||
538 | ue->progress = (gint) ((100LL * completed) / ue->filesize); | ||
539 | if (NULL == ue->rr) | ||
540 | return; | ||
541 | path = gtk_tree_row_reference_get_path (ue->rr); | ||
542 | model = gtk_tree_row_reference_get_model (ue->rr); | ||
543 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (model, | ||
544 | &iter, | ||
545 | path)); | ||
546 | gtk_tree_path_free (path); | ||
547 | gtk_list_store_set (GTK_LIST_STORE (model), | ||
548 | &iter, | ||
549 | UNINDEX_MC_UNINDEX_PROGRESS, ue->progress, | ||
550 | -1); | ||
551 | } | ||
552 | |||
553 | |||
554 | /** | ||
555 | * FS notified us that our undex operation completed | ||
556 | * | ||
557 | * @param ue operation that completed | ||
558 | */ | ||
559 | void | ||
560 | GNUNET_FS_GTK_unindex_handle_completed_ (struct UnindexEntry *ue) | ||
561 | { | ||
562 | GtkTreePath *path; | ||
563 | GtkTreeIter iter; | ||
564 | GtkTreeModel *model; | ||
565 | |||
566 | if (NULL != ue->rr) | ||
567 | { | ||
568 | path = gtk_tree_row_reference_get_path (ue->rr); | ||
569 | model = gtk_tree_row_reference_get_model (ue->rr); | ||
570 | GNUNET_assert (TRUE == gtk_tree_model_get_iter (model, | ||
571 | &iter, | ||
572 | path)); | ||
573 | gtk_tree_path_free (path); | ||
574 | gtk_list_store_remove (GTK_LIST_STORE (model), | ||
575 | &iter); | ||
576 | gtk_tree_row_reference_free (ue->rr); | ||
577 | ue->rr = NULL; | ||
578 | } | ||
579 | GNUNET_FS_unindex_stop (ue->uc); | ||
580 | } | ||
581 | |||
582 | |||
583 | |||
584 | /* end of gnunet-fs-gtk_unindex.c */ | ||
diff --git a/src/fs/gnunet-fs-gtk_unindex.h b/src/fs/gnunet-fs-gtk_unindex.h new file mode 100644 index 00000000..d21425a5 --- /dev/null +++ b/src/fs/gnunet-fs-gtk_unindex.h | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file src/fs/gnunet-fs-gtk_unindex.h | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #ifndef GNUNET_FS_GTK_UNINDEX_H | ||
26 | #define GNUNET_FS_GTK_UNINDEX_H | ||
27 | |||
28 | #include "gnunet-fs-gtk.h" | ||
29 | #include "gnunet-fs-gtk_common.h" | ||
30 | #include "gnunet-fs-gtk_event-handler.h" | ||
31 | |||
32 | |||
33 | /** | ||
34 | * Information for a specific unindex operation. | ||
35 | */ | ||
36 | struct UnindexEntry; | ||
37 | |||
38 | |||
39 | /** | ||
40 | * An unindex operation resumed. Setup the | ||
41 | * internal context for Gtk. | ||
42 | * | ||
43 | * @param fs unindex context with the FS library | ||
44 | * @param filename name of file being unindexed | ||
45 | * @param filesize size of the file | ||
46 | * @param completed how many bytes were done so far | ||
47 | * @param emsg NULL if everything is fine, otherwise error message | ||
48 | */ | ||
49 | struct UnindexEntry * | ||
50 | GNUNET_FS_GTK_unindex_handle_resume_ (struct GNUNET_FS_UnindexContext *uc, | ||
51 | const char *filename, | ||
52 | uint64_t filesize, | ||
53 | uint64_t completed, | ||
54 | const char *emsg); | ||
55 | |||
56 | |||
57 | /** | ||
58 | * FS notified us that our undex operation was stopped. | ||
59 | * | ||
60 | * @param ue operation that stopped | ||
61 | */ | ||
62 | void | ||
63 | GNUNET_FS_GTK_unindex_handle_stop_ (struct UnindexEntry *ue); | ||
64 | |||
65 | |||
66 | /** | ||
67 | * FS notified us that our undex operation had an error. | ||
68 | * | ||
69 | * @param ue operation that | ||
70 | * @param emsg error message | ||
71 | */ | ||
72 | void | ||
73 | GNUNET_FS_GTK_unindex_handle_error_ (struct UnindexEntry *ue, | ||
74 | const char *emsg); | ||
75 | |||
76 | |||
77 | /** | ||
78 | * FS notified us that our undex operation made progress | ||
79 | * | ||
80 | * @param ue operation that made progress | ||
81 | * @param completed number of bytes completed now | ||
82 | */ | ||
83 | void | ||
84 | GNUNET_FS_GTK_unindex_handle_progress_ (struct UnindexEntry *ue, | ||
85 | uint64_t completed); | ||
86 | |||
87 | |||
88 | /** | ||
89 | * FS notified us that our undex operation completed | ||
90 | * | ||
91 | * @param ue operation that completed | ||
92 | */ | ||
93 | void | ||
94 | GNUNET_FS_GTK_unindex_handle_completed_ (struct UnindexEntry *ue); | ||
95 | |||
96 | |||
97 | |||
98 | |||
99 | #endif | ||