aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fs/fs.c
blob: 8733efc15da74c6c42ac8a950c8c2c510bde1dfd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
     This file is part of GNUnet.
     (C) 2005 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/fs.c
 * @brief main file-sharing code of gnunet-gtk
 * @author Christian Grothoff
 */

#include "platform.h"
#include "gnunetgtk_common.h"
#include "fs.h"
#include "download.h"
#include "search.h"
#include "upload.h"
#include "collection.h"
#include "namespace.h"
#include <GNUnet/gnunet_fsui_lib.h>

struct FSUI_Context * ctx;

static void saveEventProcessor(void * arg) {
  const FSUI_Event * event = arg;

  switch (event->type) {
  case FSUI_search_result:
    displaySearchResult(&event->data.SearchResult.fi,
			event->data.SearchResult.searchURI,
			NULL);
    break;
  case FSUI_search_error:
    LOG(LOG_ERROR,
	_("Error while searching: %s\n"),
	event->data.message);
    break;
  case FSUI_download_aborted:
    /* ignore for now */
    break;
  case FSUI_download_progress:
    displayDownloadUpdate(event->data.DownloadProgress.uri,
			  event->data.DownloadProgress.completed,
			  event->data.DownloadProgress.last_block,
			  event->data.DownloadProgress.last_size);
    break;
  case FSUI_download_complete:
    displayDownloadComplete(event->data.DownloadProgress.uri,
			    event->data.DownloadProgress.filename);
    addLogEntry(_("Download `%s' complete"), event->data.DownloadProgress.filename);	/* here or in download.c ? or call notify directly ? */
    break;
  case FSUI_download_error:
    BREAK();
    LOG(LOG_ERROR,
	_("Error while downloading: %s\n"),
	event->data.message);
    break;
  case FSUI_upload_progress:
    displayUploadUpdate(event->data.UploadProgress.main_filename,
			event->data.UploadProgress.filename,
			event->data.UploadProgress.completed,
			event->data.UploadProgress.total);
    displayUploadUpdate(event->data.UploadProgress.main_filename,
			event->data.UploadProgress.main_filename,
			event->data.UploadProgress.main_completed,
			event->data.UploadProgress.main_total);
    break;
  case FSUI_upload_complete:
    displayUploadComplete(event->data.UploadComplete.main_filename,
			  event->data.UploadComplete.filename,
			  event->data.UploadComplete.uri);
    addLogEntry(_("Upload `%s' complete"), event->data.UploadComplete.main_filename);	/* here or in upload.c ? or call notify directly ? */
    break;
  case FSUI_upload_error:
    LOG(LOG_ERROR,
	_("Error while uploading: %s\n"),
	event->data.message);
    addLogEntry(_("Error while uploading `%s'"), event->data.message);	/* here or in upload.c ? */
    break;
  case FSUI_gnunetd_connected:
    LOG(LOG_MESSAGE,
	_("Connected to gnunetd.\n"));
    break;
  case FSUI_gnunetd_disconnected:
    LOG(LOG_MESSAGE,
	_("Disconnected from gnunetd.\n"));
    addLogEntry(_("Disconnected from gnunetd.\n"));	/* here or ? or call notify directly ? */
    break;
  default:
    BREAK();
    LOG(LOG_ERROR,
	_("Unhandled (unknown) FSUI event: %u.\n"),
	event->type);
    break;
  }
}

/**
 * FSUI event handler.
 */
static void eventProcessor(void * cls,
			   const FSUI_Event * event) {
  gtkSaveCall(&saveEventProcessor,
	      (void*) event);
}

void init_fs() {
  GtkWidget * tab;
  GtkWidget * book;
  gint num;

  tab
    = glade_xml_get_widget(getMainXML(),
			   "fsnotebook");
  gtk_widget_show(tab);
  book
    = glade_xml_get_widget(getMainXML(), "mainnotebook");
  num = gtk_notebook_get_current_page(GTK_NOTEBOOK(book));
  gtk_notebook_set_current_page(GTK_NOTEBOOK(book), 1);
  gtk_notebook_set_current_page(GTK_NOTEBOOK(book), num);

  ctx = FSUI_start("gnunet-gtk",
		   YES,
		   &eventProcessor,
		   NULL);
  fs_collection_start();
  fs_search_start();
  fs_download_start();
  fs_upload_start();
  fs_namespace_start();
}

void done_fs() {
  fs_download_stop();
  fs_search_stop();
  fs_collection_stop();
  fs_namespace_stop();
  fs_upload_stop();
  FSUI_stop(ctx);
}

/* end of fs.c */