aboutsummaryrefslogtreecommitdiff
path: root/src/common/helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/helper.c')
-rw-r--r--src/common/helper.c192
1 files changed, 29 insertions, 163 deletions
diff --git a/src/common/helper.c b/src/common/helper.c
index 90c817b5..558d8f3f 100644
--- a/src/common/helper.c
+++ b/src/common/helper.c
@@ -89,11 +89,6 @@ static struct GE_Context * ectx;
89 89
90static struct GC_Configuration * cfg; 90static struct GC_Configuration * cfg;
91 91
92#ifdef WINDOWS
93static void CALLBACK sigalrmHandler(DWORD sig) {
94}
95#endif
96
97static gboolean saveCallWrapper(gpointer data) { 92static gboolean saveCallWrapper(gpointer data) {
98 SaveCall * call = data; 93 SaveCall * call = data;
99 int i; 94 int i;
@@ -155,94 +150,6 @@ void * gtkSaveCall(PThreadMain func,
155} 150}
156 151
157/** 152/**
158 * Closure for doInfoMessage.
159 */
160typedef struct {
161 int doPopup;
162 char * note;
163} InfoMessage;
164
165/**
166 * Callback for infoMessage()
167 */
168static void * doInfoMessage(void * args) {
169 const InfoMessage * info = args;
170 GtkTextIter iter;
171 GtkTextBuffer * buffer;
172
173 if (info->doPopup==YES)
174 gtk_widget_show(infoWindow);
175 buffer
176 = gtk_text_view_get_buffer(GTK_TEXT_VIEW(infoWindowTextView));
177 gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1);
178 gtk_text_buffer_insert(buffer,
179 &iter,
180 info->note,
181 -1);
182 return NULL;
183}
184
185/**
186 * Appends a message to the info window
187 *
188 * @param doPopup do we open the window, YES or NO
189 */
190void infoMessage(int doPopup,
191 const char * format,
192 ...) {
193 va_list args;
194 InfoMessage info;
195
196 va_start(args, format);
197 info.note = g_strdup_vprintf(format, args);
198 va_end(args);
199 info.doPopup = doPopup;
200 gtkSaveCall(&doInfoMessage,
201 &info);
202 g_free(info.note);
203}
204
205static void * saveAddLogEntry(void * args) {
206 static GtkWidget * s = NULL;
207 static int once = 1;
208 static guint id;
209
210 if (once) {
211 once = 0;
212 s = glade_xml_get_widget(mainXML,
213 "statusbar");
214 id = gtk_statusbar_get_context_id(GTK_STATUSBAR(s),
215 "LOG");
216 } else
217 gtk_statusbar_pop(GTK_STATUSBAR(s),
218 id);
219 gtk_statusbar_push(GTK_STATUSBAR(s),
220 id,
221 (const char*) args);
222 return NULL;
223}
224
225/**
226 * Appends a log entry to the info window
227 *
228 * @param txt the log entry
229 *
230 */
231void addLogEntry(const char * txt,
232 ...) {
233 va_list args;
234 gchar * note;
235
236 va_start(args, txt);
237 note = g_strdup_vprintf(txt, args);
238 va_end(args);
239 infoMessage(NO, note);
240 gtkSaveCall(&saveAddLogEntry,
241 (void*) note);
242 g_free(note);
243}
244
245/**
246 * Simple accessor method. 153 * Simple accessor method.
247 */ 154 */
248const char * getGladeFileName() { 155const char * getGladeFileName() {
@@ -653,89 +560,48 @@ GdkWindowState getMainWindowState() {
653 * Start gnunet-setup, asking for a password if needed 560 * Start gnunet-setup, asking for a password if needed
654 */ 561 */
655gboolean startGNUnetSetup (gboolean run_wizard) { 562gboolean startGNUnetSetup (gboolean run_wizard) {
563 GtkWidget * mainWindow;
564 GtkWidget * messageDialog;
656 int code; 565 int code;
657 char *error_message; 566 char *error_message;
658#ifdef WITH_LIBGKSU2 567#ifdef WITH_LIBGKSU2
659 GError *gerror = NULL; 568 GError *gerror = NULL;
660 if(run_wizard) { 569 if(run_wizard) {
661 code = gksu_run("gnunet-setup -d wizard-gtk", &gerror); } 570 code = gksu_run("gnunet-setup -d wizard-gtk",
662 else { 571 &gerror);
663 code = gksu_run("gnunet-setup -d", &gerror); } 572 } else {
664 if(code && !gerror) { 573 code = gksu_run("gnunet-setup -d",
665 error_message = STRDUP(_("GKSu encountered an unknown error running the configuration tool (gnunet-setup).")); } 574 &gerror);
666 else if(code && gerror) { 575 }
667 error_message = g_strdup_printf(_("GKSu returned:\n%s"), gerror->message); 576 if (code && !gerror) {
668 g_error_free(gerror); } 577 error_message = STRDUP(_("GKSu encountered an unknown error running the configuration tool (gnunet-setup)."));
669 else { 578 } else if (code && gerror) {
670 error_message = NULL; } 579 error_message = g_strdup_printf(_("GKSu returned:\n%s"),
580 gerror->message);
581 g_error_free(gerror);
582 } else {
583 error_message = NULL;
584 }
671#elif defined(WINDOWS) 585#elif defined(WINDOWS)
672/* FIXME: run gnunet-setup, assuming we can get the needed rights */ 586/* FIXME: run gnunet-setup, assuming we can get the needed rights */
673 error_message = STRDUP("Not implemented yet !"); 587 error_message = STRDUP(_("Not implemented yet!"));
674 return TRUE; 588 code = TRUE;
675#else 589#else
676 error_message = STRDUP(_("GKSu support is not enabled, impossible to get the needed rights. You should build gnunet-gtk with the --enable-libgksu2 option, or get the right binary package. Note you can still start the configuration tool (gnunet-setup) manually.")); 590 error_message = STRDUP(_("GKSu support is not enabled, impossible to get the needed rights. You should build gnunet-gtk with the --enable-libgksu2 option, or get the right binary package. Note you can still start the configuration tool (gnunet-setup) manually."));
677 return TRUE; 591 code = TRUE;
678#endif 592#endif
679 GtkWidget *mainWindow, *messageDialog; 593 mainWindow = glade_xml_get_widget(getMainXML(),
680 mainWindow = glade_xml_get_widget(getMainXML(), "mainWindow"); 594 "mainWindow");
681 messageDialog = gtk_message_dialog_new (GTK_WINDOW(mainWindow), 595 messageDialog = gtk_message_dialog_new(GTK_WINDOW(mainWindow),
682 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, 596 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
683 GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, 597 GTK_MESSAGE_WARNING,
684 _("Failed to run the configuration tool (gnunet-setup): %s"), 598 GTK_BUTTONS_CLOSE,
685 error_message); 599 _("Failed to run the configuration tool (gnunet-setup): %s"),
600 error_message);
686 gtk_dialog_run(GTK_DIALOG(messageDialog)); 601 gtk_dialog_run(GTK_DIALOG(messageDialog));
687 gtk_widget_destroy (messageDialog); 602 gtk_widget_destroy(messageDialog);
688 FREE(error_message); 603 FREE(error_message);
689 return code; 604 return code;
690} 605}
691 606
692/**
693 * Identical to "gtk_tree_selection_selected_foreach",
694 * except that modifications of the underlying model
695 * during the iteration are tolerated.
696 */
697void ggc_tree_selection_selected_foreach(GtkTreeSelection *selection,
698 GtkTreeSelectionForeachFunc func,
699 gpointer data) {
700 unsigned int i;
701 unsigned int size;
702 GList * selected;
703 GtkTreeRowReference ** refs;
704 GtkTreeModel * model;
705 GtkTreePath * path;
706 GtkTreeIter iter;
707
708 selected = gtk_tree_selection_get_selected_rows(selection,
709 &model);
710
711 i = g_list_length(selected);
712 size = 0;
713 refs = NULL;
714 GROW(refs,
715 size,
716 i);
717 for (i=0;i<size;i++)
718 refs[i] = gtk_tree_row_reference_new(model,
719 g_list_nth_data(selected, i));
720 g_list_foreach(selected,
721 (GFunc) &gtk_tree_path_free,
722 NULL);
723 g_list_free(selected);
724 for (i=0;i<size;i++) {
725 path = gtk_tree_row_reference_get_path(refs[i]);
726 gtk_tree_row_reference_free(refs[i]);
727 if (TRUE == gtk_tree_model_get_iter(model,
728 &iter,
729 path))
730 func(model,
731 path,
732 &iter,
733 data);
734 gtk_tree_path_free(path);
735 }
736 GROW(refs,
737 size,
738 0);
739}
740
741/* end of helper.c */ 607/* end of helper.c */