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

📄 mon-gnome.c

📁 distcc编译器的源代码.好像是readhat公司开发的.
💻 C
📖 第 1 页 / 共 2 页
字号:
        }      tree_valid = gtk_tree_model_iter_next (tree_model, tree_iter);    }  /* If we finished the tree before we finished the task list, then     just insert all the others at the end. */  for (;       task_iter != NULL;       task_iter = task_iter->next)    {      if (task_iter->curr_phase == DCC_PHASE_DONE)        continue;      if (task_iter->host[0] == '\0'          || task_iter->file[0] == '\0')        continue;/*       g_message ("append row for host %s, slot %d", *//*                task_iter->host, task_iter->slot); */      dcc_insert_row_from_task (chart_model, tree_iter,                                NULL, /* insert at end */                                task_iter);    }  /* If we finished the task list before we finished the rows, clear all     the others. */  for (;       tree_valid;       tree_valid = gtk_tree_model_iter_next (tree_model, tree_iter))    {/*       g_message ("clobber row"); */      dcc_set_row_idle (chart_model, tree_iter);    }}/** * Callback when the timer triggers, causing a refresh.  Loads the * current state from the state monitor and puts it into the table * model, which should then redraw itself. **/static gint dcc_gnome_update_cb (gpointer UNUSED(view_void)){  struct dcc_task_state *task_list;    if (dcc_mon_poll (&task_list))    {      rs_log_warning("poll failed");      return TRUE;    }  dcc_update_store_from_tasks (task_list);  dcc_task_state_free (task_list);    return TRUE;                  /* please call again */}static gchar *dcc_gnome_get_title (void){  char host[256];  const char *user;  struct passwd *pw;    if (gethostname(host, sizeof host) == -1)    strcpy (host, "localhost");  /* We need to look up from our pid rather than using $LOGIN or $USER because     that's consistent with the monitor routines.  Otherwise you might     get strange results from "sudo distccmon-gnome". */  user = NULL;  pw = getpwuid (getuid ());  if (pw)    user = pw->pw_name;  if (!user)    user = "";    return g_strdup_printf ("distcc Monitor - %s@%s",                          user, host);}static gint dcc_gnome_load_update_cb (gpointer data){  gchar message[200];  double loadavg[3];  guint context_id;  if (getloadavg (loadavg, 3) == -1)    {      rs_log_error ("getloadavg failed: %s", strerror (errno));      return FALSE;             /* give up */    }  snprintf (message, sizeof message,            "Load average: %.2f, %.2f, %.2f",            loadavg[0], loadavg[1], loadavg[2]);  context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR (data), "load");  gtk_statusbar_pop(GTK_STATUSBAR (data), context_id);  gtk_statusbar_push(GTK_STATUSBAR (data), context_id, message);  return TRUE;                  /* please call again */}/** * Initialize graphics context for drawing into a widget in the right * color for each state. **/static voiddcc_create_state_gcs (GtkWidget *widget){  enum dcc_phase i_state;    for (i_state = 0; i_state < DCC_PHASE_DONE; i_state++)    {      dcc_phase_gc[i_state] = gdk_gc_new (widget->window);      gdk_gc_set_rgb_fg_color (dcc_phase_gc[i_state],                               (GdkColor *) &task_color[i_state]);    }}/** * Configure GtkTreeView with the right columns bound to * renderers, and a data model. **/static void dcc_gnome_make_proc_view (GtkTreeModel *proc_model,                                      GtkWidget **align_return){  GtkCellRenderer *text_renderer, *chart_renderer;  GtkTreeSelection *selection;  GtkTreeViewColumn *column;  GtkWidget *align, *proc_scroll;  chart_treeview = gtk_tree_view_new_with_model (proc_model);  gtk_object_set (GTK_OBJECT (chart_treeview),                  "headers-visible", TRUE,                  NULL);  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (chart_treeview));  gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);  /* we can't create the gcs until the widget is first realized */  g_signal_connect_after (chart_treeview, "realize",                          G_CALLBACK (dcc_create_state_gcs), NULL);  text_renderer = gtk_cell_renderer_text_new ();  chart_renderer = dcc_cell_renderer_chart_new ();  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (chart_treeview));  gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE);  /* Host */  column = gtk_tree_view_column_new_with_attributes    ("Host", text_renderer,     "text", COLUMN_HOST,     NULL);  gtk_tree_view_column_set_resizable (column, TRUE);  gtk_tree_view_append_column (GTK_TREE_VIEW (chart_treeview), column);/*   gtk_tree_view_column_set_sort_column_id (column, COLUMN_HOST); */  column = gtk_tree_view_column_new_with_attributes    ("Slot", text_renderer,     "text", COLUMN_SLOT,     NULL);  gtk_tree_view_column_set_resizable (column, TRUE);  gtk_tree_view_append_column (GTK_TREE_VIEW (chart_treeview), column);   /* File */  column = gtk_tree_view_column_new_with_attributes    ("File", text_renderer,     "text", COLUMN_FILE,     NULL);  gtk_tree_view_column_set_resizable (column, TRUE);  gtk_tree_view_append_column (GTK_TREE_VIEW (chart_treeview), column);    column = gtk_tree_view_column_new_with_attributes    ("State", text_renderer,     "text", COLUMN_STATE,     NULL);  gtk_tree_view_column_set_resizable (column, TRUE);  gtk_tree_view_append_column (GTK_TREE_VIEW (chart_treeview), column);    /* Tasks - for each cell, rebind the stock-id property onto that     value from the table model */  column = gtk_tree_view_column_new_with_attributes    ("Tasks", chart_renderer,     "history", COLUMN_HISTORY,     NULL);  gtk_tree_view_column_set_resizable (column, TRUE);  gtk_tree_view_append_column (GTK_TREE_VIEW (chart_treeview), column);  proc_scroll = gtk_scrolled_window_new (NULL, NULL);  /* no horizontal scrolling; let the table stretch */  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (proc_scroll),                                  GTK_POLICY_NEVER,                                  GTK_POLICY_AUTOMATIC);  gtk_container_add (GTK_CONTAINER (proc_scroll), chart_treeview);  /* Expands to fill all space */  align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);  gtk_container_add (GTK_CONTAINER (align), proc_scroll);  *align_return = align;}static GtkWidget * dcc_gnome_make_load_bar (void){  GtkWidget *bar;  gint context_id;  bar = gtk_statusbar_new ();  context_id = gtk_statusbar_get_context_id(GTK_STATUSBAR (bar), "load");  gtk_statusbar_push(GTK_STATUSBAR (bar), context_id, "Load: ");  g_timeout_add (2000,          /* ms */                 dcc_gnome_load_update_cb,                 bar);  dcc_gnome_load_update_cb (bar);  return bar;}static GtkWidget * dcc_gnome_make_mainwin (void){  GtkWidget *mainwin;  mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);  {    char *title;    title = dcc_gnome_get_title ();    gtk_window_set_title (GTK_WINDOW (mainwin),                          title);    free (title);  }    /* Set a reasonable default size that allows all columns and a few     rows to be seen with a typical theme */  gtk_window_set_default_size (GTK_WINDOW (mainwin), 500, 300);  /* Quit when it's closed */  g_signal_connect (GTK_OBJECT(mainwin), "delete-event",                     G_CALLBACK (gtk_main_quit), NULL);  g_signal_connect (GTK_OBJECT(mainwin), "destroy",                     G_CALLBACK (gtk_main_quit), NULL);#if GTK_CHECK_VERSION(2,2,0)  gtk_window_set_icon_from_file (GTK_WINDOW (mainwin),                                 PKGDATADIR "/distccmon-gnome-icon.png",                                 NULL);#endif  return mainwin;}static int dcc_gnome_make_app (void){  GtkWidget *topbox, *proc_align, *load_bar;  GtkWidget *mainwin;  /* Create the main window */  mainwin = dcc_gnome_make_mainwin ();  /* Create a vbox for the contents */  topbox = gtk_vbox_new (FALSE, 0);  gtk_container_add (GTK_CONTAINER (mainwin),                     topbox);  load_bar = dcc_gnome_make_load_bar ();      dcc_setup_tree_model ();  dcc_gnome_make_proc_view (GTK_TREE_MODEL (chart_model),                            &proc_align);  gtk_container_add (GTK_CONTAINER (topbox),                     proc_align);  gtk_box_pack_end (GTK_BOX (topbox),                    load_bar,                    FALSE, /* expand */                    FALSE,                    0);      g_timeout_add_full (G_PRIORITY_HIGH_IDLE,                      500, /* ms */                      dcc_gnome_update_cb,                      NULL,                      NULL);  /* Show the application window */  gtk_widget_show_all (mainwin);  return 0;}int main(int argc, char **argv){  /* We don't want to take too much time away from the real work of   * compilation */  nice(5);#if defined(WITH_GNOME)  gnome_program_init ("distccmon-gnome", PACKAGE_VERSION,		      LIBGNOMEUI_MODULE,		      argc, argv, NULL);#elif defined(WITH_GTK)  gtk_init (&argc, &argv);#else#  error This program must be built with either WITH_GTK or WITH_GNOME#endif  /* do our own initialization */  dcc_gnome_make_app ();  /* Keep running until quit */  gtk_main ();  return 0;}

⌨️ 快捷键说明

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