📄 fs.c
字号:
#endif err = TRUE; } a = (*(fs->launch_mount.command) != '\0'); b = (*(fs->launch_umount.command) != '\0'); if (mounting_supported && !_GK.client_mode && ((a && !b) || (!a && b))) { gkrellm_config_message_dialog(_("Entry Error"), _("Both mount and umount commands must be entered.")); err = TRUE; } if ( mounting_supported && !_GK.client_mode && fs->ejectable && !fs->fstab_mounting && !*fs->eject_device ) { gkrellm_config_message_dialog(_("Entry Error"), _("Missing ejectable device entry.")); err = TRUE; } if (err) { free_fsmon_strings(fs); g_free(fs); return; } model = gtk_tree_view_get_model(treeview); secondary = GTK_TOGGLE_BUTTON(secondary_button)->active; if (row_reference) { path = gtk_tree_row_reference_get_path(row_reference); gtk_tree_model_get_iter(model, &iter, path); indices = gtk_tree_path_get_indices(path); /* Have a row ref, but if user changed secondary button, remove the | row ref node and set path NULL so iter will be set as function of | secondary. row_ref will be invalidated below. */ if (indices[0] != secondary) { gtk_tree_store_remove(GTK_TREE_STORE(model), &iter); path = NULL; } } if (!path) { gtk_tree_model_iter_nth_child(model, &parent_iter, NULL, secondary); gtk_tree_store_append(GTK_TREE_STORE(model), &iter, &parent_iter); } set_tree_store_model_data(GTK_TREE_STORE(model), &iter, fs); if (!path) { /* If appending (not editing existing node) leave cursor at root level | and clear the entries anticipating another new entry. */ path = gtk_tree_path_new_from_string(secondary ? "1" : "0"); gtk_tree_view_set_cursor(treeview, path, NULL, FALSE); gtk_tree_path_free(path); reset_entries(secondary); } free_fsmon_strings(fs); g_free(fs); sync_fs_panels(); }static voidcb_delete(GtkWidget *widget) { GtkTreeModel *model; GtkTreePath *path; GtkTreeIter iter; FSmon *fs; if (!row_reference) return; model = gtk_tree_view_get_model(treeview); path = gtk_tree_row_reference_get_path(row_reference); gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get(model, &iter, FSMON_COLUMN, &fs, -1); gkrellm_alert_destroy(&fs->alert); gtk_tree_store_remove(GTK_TREE_STORE(model), &iter); reset_entries(FALSE); sync_fs_panels(); }static voidcb_data_format(GtkWidget *widget, gpointer data) { GList *list; gchar *s; s = gkrellm_gtk_entry_get_text(&(GTK_COMBO(data_format_combo)->entry)); /* In case Pango markup tags, don't accept line unless valid markup. | Ie, markup like <span ...> xxx </span> or <b> xxx </b> */ if ( strchr(s, '<') != NULL && !pango_parse_markup(s, -1, 0, NULL, NULL, NULL, NULL) ) return; if (gkrellm_locale_dup_string(&data_format, s, &data_format_locale)) for (list = fs_mon_list; list; list = list->next) ((FSmon *) list->data)->text_decal->value = -1; /* Force redraw */ }static voidcb_auto_eject(GtkWidget *button, gpointer data) { cdrom_auto_eject = GTK_TOGGLE_BUTTON(button)->active; }static voidcb_binary_units(GtkWidget *button, gpointer data) { binary_units = GTK_TOGGLE_BUTTON(button)->active; }static voidcb_check_interval(GtkWidget *widget, GtkSpinButton *spin) { fs_check_timeout = gtk_spin_button_get_value_as_int(spin); }static voidcb_nfs_check_interval(GtkWidget *widget, GtkSpinButton *spin) { nfs_check_timeout = gtk_spin_button_get_value_as_int(spin); } /* Allow desination drops only on depth 2 paths and don't allow drops from | source depths of 1 (top level nodes). Note: from some reason if I allow | drops on depth 3 nodes (destination is on top of a second level node) I | am not getting "drag_end" callbacks. */static gbooleanrow_drop_possible(GtkTreeDragDest *drag_dest, GtkTreePath *path, GtkSelectionData *selection_data) { GtkTreePath *src_path; gint *indices; if (!row_reference) return FALSE; src_path = gtk_tree_row_reference_get_path(row_reference); indices = gtk_tree_path_get_indices(path);// printf("drop path: indices=[%d,%d]:%d, path=%s\n",// indices[0], indices[1], gtk_tree_path_get_depth(path),// gtk_tree_path_to_string(path)); if ( gtk_tree_path_get_depth(src_path) == 1 || gtk_tree_path_get_depth(path) != 2 ) return FALSE; return (*original_row_drop_possible)(drag_dest, path, selection_data); } /* At each drag, divert the original Gtk row_drop_possible function to my | custom row_drop_possible so I can control tree structure. The original | row_drop_possible function must be restored at "drag_end" else other | monitors doing drag n' drop could get screwed. */static gbooleancb_drag_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) { GtkTreeModel *model; GtkTreeDragDestIface *dest_iface; model = gtk_tree_view_get_model(treeview); dest_iface = GTK_TREE_DRAG_DEST_GET_IFACE(GTK_TREE_DRAG_DEST(model)); if (!original_row_drop_possible) original_row_drop_possible = dest_iface->row_drop_possible; dest_iface->row_drop_possible = row_drop_possible; return FALSE; }static gbooleancb_drag_end(GtkWidget *widget, GdkDragContext *context, gpointer data) { GtkTreeModel *model; GtkTreeDragDestIface *dest_iface; model = gtk_tree_view_get_model(treeview); dest_iface = GTK_TREE_DRAG_DEST_GET_IFACE(GTK_TREE_DRAG_DEST(model)); dest_iface->row_drop_possible = original_row_drop_possible; reset_entries(FALSE); sync_fs_panels(); return FALSE; }static voidcreate_fs_panels_page(GtkWidget *vbox) { GtkWidget *table; GtkWidget *hbox, *hbox1, *vbox1; GtkWidget *label; GtkWidget *scrolled; GtkTreeModel *model; GtkCellRenderer *renderer; GList *list, *combo_list; hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); vbox1 = gkrellm_gtk_framed_vbox(hbox, NULL, 1, TRUE, 0, 2); table = gtk_table_new(2, 2, FALSE); gtk_box_pack_start(GTK_BOX(vbox1), table, FALSE, FALSE, 0); label = gtk_label_new(_("Label")); gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_SHRINK, GTK_SHRINK, 2, 1); label_entry = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(label_entry), 16); gtk_widget_set_size_request(label_entry, 100, -1); gtk_table_attach_defaults(GTK_TABLE(table), label_entry, 1, 2, 0, 1);#if !defined(WIN32) label = gtk_label_new(_("Mount Point"));#else label = gtk_label_new("Disk");#endif gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_SHRINK, GTK_SHRINK, 2, 1); dir_combo = gtk_combo_new(); gtk_table_attach_defaults(GTK_TABLE(table), dir_combo, 1, 2, 1, 2); combo_list = NULL; for (list = fstab_list; list; list = list->next) combo_list = g_list_append(combo_list, ((Mount *)list->data)->directory); gtk_combo_set_popdown_strings( GTK_COMBO(dir_combo), combo_list); gtk_combo_set_case_sensitive(GTK_COMBO(dir_combo), TRUE); g_list_free(combo_list); gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(dir_combo)->entry), ""); g_signal_connect(G_OBJECT(GTK_COMBO(dir_combo)->entry), "changed", GTK_SIGNAL_FUNC (cb_combo_changed), NULL); vbox1 = gtk_vbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), vbox1, FALSE, FALSE, 0); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox1), hbox, FALSE, FALSE, 0); gkrellm_gtk_check_button_connected(hbox, &secondary_button, 0, TRUE, TRUE, 2, cb_secondary_button_clicked, NULL, _("Secondary")); if (mounting_supported) { gkrellm_gtk_check_button_connected(hbox, &show_button, 0, TRUE, TRUE, 2, NULL, NULL, _("Show if mounted")); gtk_widget_set_sensitive(show_button, FALSE); if (!_GK.client_mode) { gkrellm_gtk_check_button_connected(vbox1, &mounting_button, 0, FALSE, FALSE, 2, cb_mount_button_clicked, NULL, _("Enable /etc/fstab mounting")); gtk_widget_set_sensitive(mounting_button, FALSE); } } hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); if (ejecting_supported && !_GK.client_mode) { vbox1 = gkrellm_gtk_framed_vbox(hbox, NULL, 1, FALSE, 0, 2); gkrellm_gtk_check_button_connected(vbox1, &ejectable_button, 0, FALSE, FALSE, 0, cb_ejectable_button_clicked, NULL, _("Ejectable")); if (mounting_supported) { hbox1 = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox1), hbox1, FALSE, FALSE, 0); label = gtk_label_new(_("Device")); gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 2); device_entry = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(device_entry), 64); gtk_widget_set_size_request(device_entry, 100, -1); gtk_box_pack_start(GTK_BOX(hbox1), device_entry, FALSE, FALSE, 2); } } if (mounting_supported && !_GK.client_mode) { vbox1 = gkrellm_gtk_framed_vbox(hbox, NULL, 1, TRUE, 0, 2); table = gkrellm_gtk_launcher_table_new(vbox1, 1); /* Won't have tooltip */ gkrellm_gtk_config_launcher(table, 0, &mount_entry, NULL, _("mount"), NULL); gkrellm_gtk_config_launcher(table, 1, &umount_entry, NULL, _("umount"), NULL); } hbox = gtk_hbox_new(FALSE, 2); gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); vbox1 = gtk_vbox_new(FALSE, 0); gtk_box_pack_end(GTK_BOX(hbox), vbox1, FALSE, FALSE, 5); gkrellm_gtk_button_connected(vbox1, &new_apply_button, FALSE, FALSE, 4, add_cb, NULL, GTK_STOCK_NEW); GTK_WIDGET_SET_FLAGS(new_apply_button, GTK_CAN_DEFAULT); gtk_widget_grab_default(new_apply_button); gkrellm_gtk_button_connected(vbox1, &delete_button, FALSE, FALSE, 4, cb_delete, NULL, GTK_STOCK_DELETE); gtk_widget_set_sensitive(delete_button, FALSE); gkrellm_gtk_alert_button(vbox1, &alert_button, FALSE, FALSE, 4, FALSE, cb_set_alert, NULL); gtk_widget_set_sensitive(alert_button, FALSE); scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_box_pack_end(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); model = create_model(); treeview = GTK_TREE_VIEW(gtk_tree_view_new_with_model(model)); g_object_unref(G_OBJECT(model)); gtk_tree_view_set_rules_hint(treeview, TRUE); gtk_tree_view_set_reorderable(treeview, TRUE); g_signal_connect(G_OBJECT(treeview), "drag_begin", G_CALLBACK(cb_drag_begin), NULL); g_signal_connect(G_OBJECT(treeview), "drag_end", G_CALLBACK(cb_drag_end), NULL); renderer = gtk_cell_renderer_text_new();// g_object_set(G_OBJECT(renderer), "xalign", 0.0, NULL); gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Label"), renderer, "text", NAME_COLUMN, NULL); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Mount Point"), renderer, "text", MOUNT_POINT_COLUMN,// "visible", VISIBLE_COLUMN, NULL); renderer = gtk_cell_renderer_pixbuf_new(); gtk_tree_view_insert_column_with_attributes(treeview, -1, "", renderer, "pixbuf", IMAGE_COLUMN, NULL); gtk_container_add(GTK_CONTAINER(scrolled), GTK_WIDGET(treeview)); selection = gtk_tree_view_get_selection(treeview); gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(cb_tree_selection_changed), NULL); }static gchar *fs_info_text0[] ={N_("<h>Mounting\n"),N_("Enter file system mount points to monitor and enter a label to describe\n""the mount point. The krell shows the ratio of blocks used to total blocks\n""available. Mounting commands can be enabled for mount points in one\n""of two ways:\n\n"),N_("<b>\t1) Mounting using /etc/fstab: "),N_("If a mount point is in your\n""\t/etc/fstab and you have mount permission then mount and umount\n""\tcommands can be enabled and executed for that mount point simply\n""\tby checking the \"Enable /etc/fstab mounting\" option.\n""\tMount table entries in /etc/fstab need the \"user\" or \"owner\" option\n""\tset to grant this permission unless GKrellM is run as root.\n""\tFor example, if you run GKrellM as a normal user and you want\n""\tto be able to mount your floppy, your /etc/fstab could have\n""\teither of:\n"),N_("<i>\t\t/dev/fd0 /mnt/floppy ext2 user,noauto,rw,exec 0 0\n"),N_("\tor\n"),N_("<i>\t\t/dev/fd0 /mnt/floppy ext2 user,defaults 0 0\n\n"),N_("<b>\t2) Mounting using custom commands: "),N_("If GKrellM is run as root or if\n""\tyou have sudo permission to run the mount commands, then a custom\n""\tmount command can be entered into the \"mount command\" entry\n""\tbox. A umount command must also be entered if you choose this\n""\tmethod. Example mount and umount entries using sudo:\n"),N_("<i>\t\tsudo /bin/mount -t msdos /dev/fd0 /mnt/A\n"),N_("<i>\t\tsudo /bin/umount /mnt/A\n"),N_("\tNotes: the mount point specified in a custom mount command\n" "\t(/mnt/A in this example) must be the same as entered in the\n" "\t\"Mount Point\" entry. You should have the NOPASSWD option set\n" "\tin /etc/sudoers if using sudo.\n\n"),N_("<h>Primary and Secondary Monitors\n"), /* xgettext:no-c-format */N_("File system monitors can be created as primary (always visible)\n" "or secondary which can be hidden and then shown when they are of\n" "interest. For example, you might make primary file system monitors\n" "for root, home, or user so they will be always visible, but make\n" "secondary monitors for less frequently used mount points such as\n" "floppy, zip, backup partitions, foreign file system types, etc.\n" "Secondary FS monitors can also be configured to always be visible if they\n" "are mounted by checking the \"Show if mounted\" option. Using this\n" "feature you can show the secondary group, mount a file system, and have\n" "that FS monitor remain visible even when the secondary group is hidden.\n" "A standard cdrom mount will show as 100% full but a monitor for it\n" "could be created with mounting enabled just to have the\n" "mount/umount convenience.\n\n")};static gchar *fs_info_text1[] ={N_("<h>Panel Labels\n"),N_("Substitution variables for the format string for file system panels:\n"),N_("\t$t total capacity\n"),N_("\t$u used space\n"),N_("\t$f free space\n"),N_("\t$U used %,\n"),N_("\t$F free %\n"),N_("\t$l the panel label\n"),#if !defined(WIN32)N_("\t$D the mount point\n"),#elseN_("\t$D the disk\n"),#endif"\n",N_("Substitution variables may be used in alert commands.\n"),"\n",N_("<h>Mouse Button Actions:\n"),N_("<b>\tLeft "),N_("click on a panel to scroll a programmable display\n"),N_("\t\tof file system capacities (default is total and free space).\n"),N_("<b>\tWheel "),N_("Shows and hides the secondary file system monitors.\n")};static voidcreate_fs_tab(GtkWidget *tab_vbox) { GtkWidget *tabs; GtkWidget *vbox, *vbox1, *hbox; GtkWidget *text; GtkWidget *label; GList *list; gint i; row_reference = NULL; refresh_fstab_list(); tabs = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs), GTK_POS_TOP); gtk_box_pack_start(GTK_BOX(tab_vbox), tabs, TRUE, TRUE, 0); vbox = gkrellm_gtk_framed_notebook_page(tabs, _("Panels")); create_fs_panels_page(vbox);// vbox = gkrellm_gtk_framed_notebook_page(tabs, _("Primary"));// fill_fs_tab(vbox, &primary_widgets);// vbox = gkrellm_gtk_framed_notebook_page(tabs, _("Secondary"));// fill_fs_tab(vbox, &secondary_widgets);/* --Setup tab */ vbox = gkrellm_gtk_framed_notebook_page(tabs, _("Setup")); vbox1 = gkrellm_gtk_framed_vbox(vbox, _("Options"), 4, FALSE, 0, 2); gkrellm_gtk_check_button_connected(vbox1, NULL, binary_units, FALSE, FALSE, 0, cb_binary_units, NULL, _("Use binary units (MiB, GiG) for reporting disk capacities.")); if (mounting_supported && ejecting_supported && !_GK.client_mode) gkrellm_gtk_check_button_connected(vbox1, NULL, cdrom_auto_eject, FALSE, FALSE, 0, cb_auto_eject, NULL, _("Auto eject when ejectable devices are unmounted")); if (!_GK.client_mode) { vbox1 = gkrellm_gtk_framed_vbox_end(vbox, NULL, 4, FALSE, 0, 2); gkrellm_gtk_spin_button(vbox1, NULL, (gfloat) fs_check_timeout, 2.0, 15.0, 1.0, 5.0, 0 /*digits*/, 0 /*wid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -