⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ngconf.c

📁 GNUnet是一个安全的点对点网络框架
💻 C
📖 第 1 页 / 共 2 页
字号:
/*     This file is part of GNUnet.     (C) 2005, 2006, 2007 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.*//** * @brief GNUnet Setup * @file setup/gtk/ngconf.c * @author Nils Durner * @author Christian Grothoff */#include "platform.h"#include "gnunet_setup_lib.h"#include "glade_support.h"#include "gconf.h"static GtkListStore *no_model;static struct GNUNET_GC_Configuration *cfg;static struct GNUNET_GE_Context *ectx;static const char *cfg_filename;struct P2W{  struct P2W *next;  struct GNUNET_GNS_TreeNode *pos;  GtkWidget *w;};/** * Maping of GNS_tree positions to widgets * (used for visibility updates). */static struct P2W *pws;#if GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 12#elsestatic GtkTooltips *tips;#endifstatic voidtooltip (GtkWidget * w, const char *text){#if GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 12  gtk_widget_set_tooltip_text (w, text);#else  gtk_tooltips_set_tip (tips, w, text, NULL);#endif}static voidupdate_visibility (){  struct P2W *pos;  pos = pws;  while (pos != NULL)    {      if (pos->pos->visible)        gtk_widget_show (pos->w);      else        gtk_widget_hide (pos->w);      pos = pos->next;    }}static voidlink_visibility (struct GNUNET_GNS_TreeNode *pos, GtkWidget * w){  struct P2W *pw;  pw = GNUNET_malloc (sizeof (struct P2W));  pw->pos = pos;  pw->w = w;  pw->next = pws;  pws = pw;}static voidboolean_toggled (GtkToggleButton * togglebutton, gpointer user_data){  struct GNUNET_GNS_TreeNode *pos = user_data;  GNUNET_GC_set_configuration_value_string (cfg,                                            ectx,                                            pos->section,                                            pos->option,                                            gtk_toggle_button_get_active                                            (togglebutton) ? "YES" : "NO");  update_visibility ();}static voidradio_update (GtkRadioButton * button, gpointer user_data){  struct GNUNET_GNS_TreeNode *pos = user_data;  const char *opt;  opt = g_object_get_data (G_OBJECT (button), "SC-value");  GNUNET_GC_set_configuration_value_string (cfg,                                            ectx, pos->section, pos->option,                                            opt);  update_visibility ();}static voidmulti_update (GtkToggleButton * button, gpointer user_data){  struct GNUNET_GNS_TreeNode *pos = user_data;  char *val;  char *opt;  char *ret;  char *v;  char *s;  val = NULL;  GNUNET_GC_get_configuration_value_string (cfg,                                            pos->section, pos->option, NULL,                                            &val);  GNUNET_GE_ASSERT (ectx, val != NULL);  opt = g_object_get_data (G_OBJECT (button), "MC-value");  if (gtk_toggle_button_get_active (button))    {      ret = GNUNET_malloc (strlen (val) + strlen (opt) + 2);      strcpy (ret, val);      strcat (ret, " ");      strcat (ret, opt);    }  else    {      v = val;      while ((NULL != (s = strstr (v, opt))) &&             (((s[strlen (opt)] != '\0') &&               (s[strlen (opt)] != ' ')) || ((s != val) && (s[-1] != ' '))))        v = s + 1;      GNUNET_GE_ASSERT (NULL, s != NULL);      ret = GNUNET_malloc (strlen (val) + 1);      s[0] = '\0';      if (s != val)        s[-1] = '\0';           /* kill space */      strcpy (ret, val);      strcat (ret, &s[strlen (opt)]);    }  GNUNET_GC_set_configuration_value_string (cfg,                                            ectx, pos->section, pos->option,                                            ret);  GNUNET_free (ret);  GNUNET_free (val);  update_visibility ();}static voidstring_update (GtkEntry * entry, gpointer user_data){  struct GNUNET_GNS_TreeNode *pos = user_data;  GNUNET_GC_set_configuration_value_string (cfg,                                            ectx,                                            pos->section,                                            pos->option,                                            gtk_entry_get_text (entry));  update_visibility ();}static intaddLeafToTree (GtkWidget * parent, struct GNUNET_GNS_TreeNode *pos){  GtkWidget *ebox;  GtkWidget *childBox;  GtkWidget *box;  GtkWidget *w;  GtkWidget *choice;  GtkWidget *label;  int i;  char defStr[128];  const char *lri;  box = gtk_hbox_new (FALSE, 0);  link_visibility (pos, box);  switch (pos->type & GNUNET_GNS_TYPE_MASK)    {    case GNUNET_GNS_TYPE_BOOLEAN:      w = gtk_check_button_new_with_label (pos->description);      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w),                                    pos->value.Boolean.val);      tooltip (w, pos->help);      g_signal_connect (w, "toggled", G_CALLBACK (&boolean_toggled), pos);      gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 10);      break;    case GNUNET_GNS_TYPE_STRING:      ebox = gtk_vbox_new (FALSE, 5);      w = gtk_entry_new ();      label = gtk_label_new (pos->description);      gtk_label_set_mnemonic_widget (GTK_LABEL (label), w);      gtk_box_pack_start (GTK_BOX (ebox), label, FALSE, FALSE, 5);      gtk_entry_set_text (GTK_ENTRY (w), pos->value.String.val);      g_signal_connect (w, "changed", G_CALLBACK (&string_update), pos);      tooltip (w, pos->help);      gtk_box_pack_start (GTK_BOX (ebox), w, TRUE, TRUE, 5);      gtk_box_pack_start (GTK_BOX (box), ebox, TRUE, TRUE, 0);      break;    case GNUNET_GNS_TYPE_MULTIPLE_CHOICE:      i = 0;      ebox = gtk_vbox_new (FALSE, 5);      childBox = gtk_hbox_new (FALSE, 5);      label = gtk_label_new (pos->description);      gtk_box_pack_start (GTK_BOX (ebox), label, FALSE, FALSE, 5);      while (NULL != (lri = pos->value.String.legalRange[i]))        {          w = gtk_check_button_new_with_label (lri);          tooltip (w, pos->help);          g_object_set_data (G_OBJECT (w), "MC-value", (void *) lri);          if ((NULL != strstr (pos->value.String.val,                               lri)) &&              ((' ' == strstr (pos->value.String.val,                               lri)[strlen (lri)])               || ('\0' ==                   strstr (pos->value.String.val,                           lri)[strlen (lri)]))              &&              ((pos->value.String.val ==                strstr (pos->value.String.val,                        lri))               || (' ' == strstr (pos->value.String.val, lri)[-1])))            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE);          g_signal_connect (w, "toggled", G_CALLBACK (&multi_update), pos);          gtk_box_pack_start (GTK_BOX (childBox), w, FALSE, FALSE, 5);          i++;        }      gtk_box_pack_start (GTK_BOX (ebox), childBox, FALSE, FALSE, 5);      gtk_box_pack_start (GTK_BOX (box), ebox, FALSE, FALSE, 0);      break;    case GNUNET_GNS_TYPE_SINGLE_CHOICE:      w = NULL;      i = 0;      choice = NULL;      label = gtk_label_new (pos->description);      gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 10);      while (NULL != (lri = pos->value.String.legalRange[i]))        {          if (w != NULL)            w =              gtk_radio_button_new_with_label_from_widget              (GTK_RADIO_BUTTON (w), lri);          else            w = gtk_radio_button_new_with_label (NULL, lri);          tooltip (w, pos->help);          g_object_set_data (G_OBJECT (w), "SC-value", (void *) lri);          gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0);          if (0 == strcmp (lri, pos->value.String.val))            choice = w;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -