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

📄 gui_tree.c

📁 网络爬虫程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*    This code is part of WWW grabber called pavuk                        *//*    Copyright (c) 1997 - 2001 Stefan Ondrejicka                          *//*    Distributed under GPL 2 or later                                     *//***************************************************************************/#include "config.h"#ifdef WITH_TREE#ifdef GTK_FACE#include <gdk/gdkkeysyms.h>#include <stdio.h>#include <unistd.h>#include "form.h"#include "gaccel.h"#include "gprop.h"#include "gui_api.h"#include "gui.h"#include "recurse.h"#include "icons/save.xpm"#include "icons/cancel.xpm"#define TREE_GET_URL \  ((url *) gtk_ctree_node_get_row_data(GTK_CTREE(gui_cfg.tree_widget) , \  (GtkCTreeNode *)(GTK_CLIST(gui_cfg.tree_widget)->selection->data)))#define TEST_URL_NODE \  (GTK_CLIST(gui_cfg.tree_widget)->selection && TREE_GET_URL)static gint no_destroy(GtkWidget * widget, GdkEvent * event, gpointer data){  if(!gui_cfg._go_bg)  {    gtk_widget_hide(GTK_WIDGET(data));    return (TRUE);  }  else    return (FALSE);}void gui_SelectTreeNode(GtkObject * object, gpointer func_data){  gtk_label_set(GTK_LABEL(gui_cfg.tree_help), " ");}static void LaunchBrowser(GtkObject * object, gpointer func_data){  char pom[2048];  char *p;  url *urlp;  if(!cfg.browser || !TEST_URL_NODE)  {    gdk_beep();    return;  }  urlp = TREE_GET_URL;  p = tl_strdup(url_to_filename(urlp, TRUE));  if(access(p, R_OK))  {    free(p);    p = url_to_urlstr(urlp, FALSE);  }  snprintf(pom, sizeof(pom), "%s %s &", cfg.browser, p);  tl_system(pom);  free(p);}static void Propert(GtkObject * object, gpointer func_data){  char pom[4096];  url_prop *prp;  url *urlp;  char *p;  char *p1;  if(!TEST_URL_NODE)  {    gdk_beep();    return;  }  urlp = TREE_GET_URL;  prp = urlp->prop;  p = url_to_urlstr(urlp, FALSE);  snprintf(pom, sizeof(pom), gettext("URL: %s\n"), p);  _free(p);  p = g_strdup(pom);  if(urlp->type == URLT_HTTP || urlp->type == URLT_HTTPS)  {    if(urlp->status & URL_FORM_ACTION)    {      form_info *fi = (form_info *) urlp->extension;      dllist *ptr;      if(fi->method == FORM_M_GET)      {        p1 = g_strconcat(p, gettext("Request type: "), "GET\n", NULL);        _free(p);        p = p1;      }      else      {        p1 = g_strconcat(p, gettext("Request type: "), "POST\n", NULL);        _free(p);        p = p1;        p1 = g_strconcat(p, gettext("Request encoding: "),          (fi->encoding == FORM_E_MULTIPART) ?          "form/multipart\n" : "application/x-www-urlencoded\n", NULL);        _free(p);        p = p1;      }      ptr = fi->infos;      if(ptr)      {        p1 = g_strconcat(p, gettext("Query values:\n"), NULL);        _free(p);        p = p1;      }      while(ptr)      {        form_field *ff = (form_field *) ptr->data;        char *name, *value;        name = form_encode_urlencoded_str(ff->name);        value = form_encode_urlencoded_str(ff->value);        p1 = g_strconcat(p, "    ", name, " = ", value, "\n", NULL);        _free(p);        p = p1;        _free(name);        _free(value);        ptr = ptr->next;      }    }    else    {      p1 = g_strconcat(p, gettext("Request type: "), "GET\n", NULL);      _free(p);      p = p1;    }  }  p1 = g_strconcat(p, gettext("Status: "), NULL);  _free(p);  p = p1;  if(!(urlp->status & URL_PROCESSED))  {    p1 = g_strconcat(p, gettext("not processed yet\n"), NULL);    _free(p);    p = p1;  }  else if(urlp->status & URL_INNSCACHE)  {    p1 = g_strconcat(p, gettext("loaded from NS cache\n"), NULL);    _free(p);    p = p1;  }  else if(urlp->status & URL_REDIRECT)  {    p1 = g_strconcat(p, gettext("loaded from local URL tree\n"), NULL);    _free(p);    p = p1;  }  else if(urlp->status & URL_MOVED)  {    p1 = g_strconcat(p, gettext("moved to another URL\n"), NULL);    _free(p);    p = p1;  }  else if(urlp->status & URL_NOT_FOUND)  {    p1 = g_strconcat(p, gettext("URL not found on remote server\n"), NULL);    _free(p);    p = p1;  }  else if(urlp->status & URL_TRUNCATED)  {    p1 = g_strconcat(p, gettext("truncated\n"), NULL);    _free(p);    p = p1;  }  else if(urlp->status & URL_DOWNLOADED)  {    p1 = g_strconcat(p, gettext("downloaded OK\n"), NULL);    _free(p);    p = p1;  }  else if(urlp->status & URL_REJECTED)  {    p1 = g_strconcat(p, gettext("rejected by rules\n"), NULL);    _free(p);    p = p1;  }  else if(urlp->status & URL_USER_DISABLED)  {    p1 = g_strconcat(p, gettext("disabled by user\n"), NULL);    _free(p);    p = p1;  }  else if(urlp->status & URL_ERR_REC)  {    p1 = g_strconcat(p, gettext("probably recoverable error\n"), NULL);    _free(p);    p = p1;  }  else if(urlp->status & URL_ERR_UNREC)  {    p1 = g_strconcat(p, gettext("unrecoverable error\n"), NULL);    _free(p);    p = p1;  }  else  {    p1 = g_strconcat(p, gettext("unknown\n"), NULL);    _free(p);    p = p1;  }  if(urlp->moved_to)  {    char *ps = url_to_urlstr(urlp->moved_to, FALSE);    snprintf(pom, sizeof(pom), gettext("Moved to URL: %s\n"), ps);    _free(ps);    p1 = g_strconcat(p, pom, NULL);    _free(p);    p = p1;  }  if(prp)  {    if(prp->type)      snprintf(pom, sizeof(pom), gettext("Type: %s\n"), gettext(prp->type));    else      snprintf(pom, sizeof(pom), gettext("Type: unknown\n"));    p1 = g_strconcat(p, pom, NULL);    _free(p);    p = p1;    sprintf(pom, gettext("Size: %d\n"), prp->size);    p1 = g_strconcat(p, pom, NULL);    _free(p);    p = p1;    if(prp->mdtm)    {      LOCK_TIME;      strftime(pom, sizeof(pom),        gettext("Modification time: %a, %d %b %Y %H:%M:%S %Z\n"),        localtime(&prp->mdtm));      UNLOCK_TIME;      p1 = g_strconcat(p, pom, NULL);      _free(p);      p = p1;    }  }  if(urlp->local_name)  {    snprintf(pom, sizeof(pom), gettext("Local filename: %s\n"), urlp->local_name);    p1 = g_strconcat(p, pom, NULL);    _free(p);    p = p1;  }  if(urlp->ref_cnt)  {    dllist *ptr;    char *us;    p1 = g_strconcat(p, gettext("Parent URLs:\n"), NULL);    _free(p);    p = p1;    LOCK_URL(urlp);    for(ptr = urlp->parent_url; ptr; ptr = ptr->next)    {      url *pomurl = (url *) ptr->data;      us = url_to_urlstr(pomurl, FALSE);      snprintf(pom, sizeof(pom), "      %s\n", us);      free(us);      p1 = g_strconcat(p, pom, NULL);      _free(p);      p = p1;    }    UNLOCK_URL(urlp);  }  if(!p)    p = "";  gtk_label_set(GTK_LABEL(gui_cfg.tree_help), p);  g_free(p);}static void item_set_disabled(GtkCTreeNode * widget, gboolean disabled){  static GtkStyle *disabled_style = NULL;  static GtkStyle *normal_style = NULL;  LOCK_GTKTREE;  if(!disabled_style)  {    normal_style =      gtk_ctree_node_get_cell_style(GTK_CTREE(gui_cfg.tree_widget), widget,      0);    if(!normal_style)      normal_style = gtk_widget_get_style(gui_cfg.tree_widget);    disabled_style = normal_style ? gtk_style_copy(normal_style) :      gtk_style_new();    disabled_style->fg[GTK_STATE_NORMAL] =      disabled_style->fg[GTK_STATE_INSENSITIVE];    disabled_style->bg[GTK_STATE_NORMAL] =      disabled_style->bg[GTK_STATE_INSENSITIVE];    disabled_style->base[GTK_STATE_NORMAL] =      disabled_style->base[GTK_STATE_INSENSITIVE];  }  gtk_ctree_node_set_cell_style(GTK_CTREE(gui_cfg.tree_widget), widget, 0,    disabled ? disabled_style : normal_style);  UNLOCK_GTKTREE;}static void DisableURL(GtkObject * object, gpointer func_data){  url *urlp;  int i;  if(!TEST_URL_NODE)  {    gdk_beep();    return;  }  urlp = TREE_GET_URL;  urlp->status |= URL_USER_DISABLED;  LOCK_URL(urlp);  for(i = 0; i < urlp->ref_cnt; i++)    item_set_disabled(urlp->tree_nfo[i], TRUE);  UNLOCK_URL(urlp);}static void EnableURL(GtkObject * object, gpointer func_data){  url *urlp;  int i;  if(!TEST_URL_NODE)  {    gdk_beep();    return;  }  urlp = TREE_GET_URL;  urlp->status &= ~URL_USER_DISABLED;  LOCK_URL(urlp);  for(i = 0; i < urlp->ref_cnt; i++)    item_set_disabled(urlp->tree_nfo[i], FALSE);  UNLOCK_URL(urlp);  if(urlp->status & URL_PROCESSED)  {    urlp->status &= ~URL_PROCESSED;    LOCK_CFG_URLSTACK;    cfg.urlstack = dllist_append(cfg.urlstack, (dllist_t) urlp);    cfg.total_cnt++;    UNLOCK_CFG_URLSTACK;  }}

⌨️ 快捷键说明

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