📄 fs.c
字号:
set_tree_store_model_data(GtkTreeStore *tree, GtkTreeIter *iter, FSmon *fs) { gtk_tree_store_set(tree, iter, NAME_COLUMN, fs->label, MOUNT_POINT_COLUMN, fs->mount.directory, SHOW_COLUMN, fs->show_if_mounted, FSTAB_COLUMN, fs->fstab_mounting, MOUNT_COMMAND_COLUMN, fs->launch_mount.command, UMOUNT_COMMAND_COLUMN, fs->launch_umount.command, EJECTABLE_COLUMN, fs->ejectable, DEVICE_COLUMN, fs->eject_device, FSMON_COLUMN, fs, ALERT_COLUMN, fs->alert, SHOW_DATA_COLUMN, fs->label_is_data, VISIBLE_COLUMN, TRUE, -1); if (fs->alert) gtk_tree_store_set(tree, iter, IMAGE_COLUMN, gkrellm_alert_pixbuf(), -1); }static GtkTreeModel *create_model(void) { GtkTreeStore *tree; GtkTreeIter iter, citer; GList *list; FSmon *fs; tree = gtk_tree_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF); gtk_tree_store_append(tree, &iter, NULL); gtk_tree_store_set(tree, &iter, NAME_COLUMN, _("Primary"), VISIBLE_COLUMN, FALSE, -1); for (list = fs_mon_list; list; list = list->next) { fs = (FSmon *) list->data; if (fs->secondary) continue; gtk_tree_store_append(tree, &citer, &iter); set_tree_store_model_data(tree, &citer, fs); } gtk_tree_store_append(tree, &iter, NULL); gtk_tree_store_set(tree, &iter, NAME_COLUMN, _("Secondary"), VISIBLE_COLUMN, FALSE, -1); for (list = fs_mon_list; list; list = list->next) { fs = (FSmon *) list->data; if (!fs->secondary) continue; gtk_tree_store_append(tree, &citer, &iter); set_tree_store_model_data(tree, &citer, fs); } return GTK_TREE_MODEL(tree); }static voidchange_row_reference(GtkTreeModel *model, GtkTreePath *path) { gtk_tree_row_reference_free(row_reference); if (model && path) row_reference = gtk_tree_row_reference_new(model, path); else row_reference = NULL; }static voidcb_set_alert(GtkWidget *button, gpointer data) { 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); if (!fs->alert) create_alert(fs); gkrellm_alert_config_window(&fs->alert); gtk_tree_store_set(GTK_TREE_STORE(model), &iter, ALERT_COLUMN, fs->alert, -1); }static gbooleanget_child_iter(GtkTreeModel *model, gchar *parent_node, GtkTreeIter *citer) { GtkTreePath *path; GtkTreeIter iter; path = gtk_tree_path_new_from_string(parent_node); gtk_tree_model_get_iter(model, &iter, path); gtk_tree_path_free(path); return gtk_tree_model_iter_children(model, citer, &iter); } /* Callback for a created or destroyed alert. Find the sensor in the model | and set the IMAGE_COLUMN. */static voidcb_alert_config(GkrellmAlert *ap, FSmon *fs) { GtkTreeModel *model; GtkTreeIter iter; FSmon *fs_test; GdkPixbuf *pixbuf; gchar node[2]; gint i; if (!gkrellm_config_window_shown()) return; model = gtk_tree_view_get_model(treeview); pixbuf = ap->activated ? gkrellm_alert_pixbuf() : NULL; for (i = 0; i < 2; ++i) { node[0] = '0' + i; /* toplevel Primary or Secondary node */ node[1] = '\0'; if (get_child_iter(model, node, &iter)) do { gtk_tree_model_get(model, &iter, FSMON_COLUMN, &fs_test, -1); if (fs != fs_test) continue; gtk_tree_store_set(GTK_TREE_STORE(model), &iter, IMAGE_COLUMN, pixbuf, -1); return; } while (gtk_tree_model_iter_next(model, &iter)); } } /* Watch what is going into the directory combo entry, compare it to | fstab entries and accordingly set sensitivity of the mounting_button. */static voidcb_combo_changed(GtkWidget *widget) { Mount *m; gchar *s; if (!mounting_supported || _GK.client_mode) return; s = gkrellm_gtk_entry_get_text(&(GTK_COMBO(dir_combo)->entry)); m = in_fstab_list(s); if (m && (fstab_user_permission(m) || uid == 0)) { gtk_widget_set_sensitive(mounting_button, TRUE); if (GTK_TOGGLE_BUTTON(mounting_button)->active) { gtk_entry_set_text(GTK_ENTRY(mount_entry), ""); gtk_entry_set_text(GTK_ENTRY(umount_entry), ""); gtk_widget_set_sensitive(mount_entry, FALSE); gtk_widget_set_sensitive(umount_entry, FALSE); } } else { if (GTK_TOGGLE_BUTTON(mounting_button)->active) gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(mounting_button), FALSE); else { gtk_widget_set_sensitive(mount_entry, TRUE); gtk_widget_set_sensitive(umount_entry, TRUE); } gtk_widget_set_sensitive(mounting_button, FALSE); } }static voidcb_mount_button_clicked(GtkWidget *widget) { if (!mounting_supported || _GK.client_mode) return; if (GTK_TOGGLE_BUTTON(mounting_button)->active) { gtk_entry_set_text(GTK_ENTRY(mount_entry), ""); gtk_entry_set_text(GTK_ENTRY(umount_entry), ""); gtk_widget_set_sensitive(mount_entry, FALSE); gtk_widget_set_sensitive(umount_entry, FALSE); if (device_entry) { gtk_entry_set_text(GTK_ENTRY(device_entry), ""); gtk_widget_set_sensitive(device_entry, FALSE); } } else { gtk_widget_set_sensitive(mount_entry, TRUE); gtk_widget_set_sensitive(umount_entry, TRUE); if ( ejectable_button && GTK_TOGGLE_BUTTON(ejectable_button)->active ) gtk_widget_set_sensitive(device_entry, TRUE); } }static voidcb_ejectable_button_clicked(GtkWidget *widget) { gboolean fstab_mounting; if (!mounting_supported || _GK.client_mode) return; fstab_mounting = GTK_TOGGLE_BUTTON(mounting_button)->active; if (GTK_TOGGLE_BUTTON(ejectable_button)->active) { gtk_widget_set_sensitive(device_entry, !fstab_mounting); } else { gtk_entry_set_text(GTK_ENTRY(device_entry), ""); gtk_widget_set_sensitive(device_entry, FALSE); } }static voidcb_secondary_button_clicked(GtkWidget *widget) { if (!mounting_supported) /* Show button is in client mode */ return; if (GTK_TOGGLE_BUTTON(secondary_button)->active) gtk_widget_set_sensitive(show_button, TRUE); else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_button), FALSE); gtk_widget_set_sensitive(show_button, FALSE); } }static voidreset_entries(gboolean level0) { gtk_entry_set_text(GTK_ENTRY(label_entry), ""); gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(dir_combo)->entry), ""); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(secondary_button), level0); if (mounting_button) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mounting_button),FALSE); if (show_button) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_button), FALSE); if (ejectable_button) { gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(ejectable_button), FALSE); if (device_entry) gtk_entry_set_text(GTK_ENTRY(device_entry), ""); } if (mount_entry) { gtk_entry_set_text(GTK_ENTRY(mount_entry), ""); gtk_entry_set_text(GTK_ENTRY(umount_entry), ""); } change_row_reference(NULL, NULL); gtk_tree_selection_unselect_all(selection); }static FSmon *fs_new_from_model(GtkTreeModel *model, GtkTreeIter *iter) { FSmon *fs; gchar *label; fs = g_new0(FSmon, 1); gtk_tree_model_get(model, iter, NAME_COLUMN, &label, MOUNT_POINT_COLUMN, &fs->mount.directory, SHOW_COLUMN, &fs->show_if_mounted, FSTAB_COLUMN, &fs->fstab_mounting, MOUNT_COMMAND_COLUMN, &fs->launch_mount.command, UMOUNT_COMMAND_COLUMN, &fs->launch_umount.command, EJECTABLE_COLUMN, &fs->ejectable, DEVICE_COLUMN, &fs->eject_device, ALERT_COLUMN, &fs->alert, SHOW_DATA_COLUMN, &fs->label_is_data, -1); gkrellm_locale_dup_string(&fs->label, label, &fs->label_shadow); g_free(label); return fs; }static voidcb_tree_selection_changed(GtkTreeSelection *selection, gpointer data) { GtkTreeIter iter; GtkTreeModel *model; GtkTreePath *path; FSmon *fs; gint *indices, depth, secondary; if (!gtk_tree_selection_get_selected(selection, &model, &iter)) { reset_entries(FALSE); gtk_button_set_label(GTK_BUTTON(new_apply_button), GTK_STOCK_NEW); gtk_widget_set_sensitive(delete_button, FALSE); gtk_widget_set_sensitive(alert_button, FALSE); return; } path = gtk_tree_model_get_path(model, &iter); indices = gtk_tree_path_get_indices(path); secondary = indices[0]; depth = gtk_tree_path_get_depth(path);// printf("selection: indices=[%d,%d]:%d, path=%s\n",// indices[0], indices[1], gtk_tree_path_get_depth(path),// gtk_tree_path_to_string(path)); change_row_reference(model, path); gtk_tree_path_free(path); if (depth == 1) { reset_entries(secondary); gtk_button_set_label(GTK_BUTTON(new_apply_button), GTK_STOCK_NEW); gtk_widget_set_sensitive(delete_button, FALSE); gtk_widget_set_sensitive(alert_button, FALSE); return; } gtk_button_set_label(GTK_BUTTON(new_apply_button), GTK_STOCK_APPLY); gtk_widget_set_sensitive(delete_button, TRUE); gtk_widget_set_sensitive(alert_button, TRUE); fs = fs_new_from_model(model, &iter); if (!secondary) fs->show_if_mounted = FALSE; /* in case dragged secondary->primary*/ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(secondary_button), secondary); gtk_entry_set_text(GTK_ENTRY(label_entry), fs->label); gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(dir_combo)->entry), fs->mount.directory); if (show_button) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_button), fs->show_if_mounted); if (mounting_button) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mounting_button), fs->fstab_mounting); if (ejectable_button) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ejectable_button), fs->ejectable); if (device_entry) { gtk_entry_set_text(GTK_ENTRY(device_entry), fs->eject_device); if (!fs->ejectable) gtk_widget_set_sensitive(device_entry, FALSE); } } if (mount_entry) { gtk_entry_set_text(GTK_ENTRY(mount_entry), fs->launch_mount.command); gtk_entry_set_text(GTK_ENTRY(umount_entry), fs->launch_umount.command); } free_fsmon_strings(fs); g_free(fs); }static voidsync_fs_panels(void) { GtkTreeModel *model; GtkTreePath *path; GtkTreeIter iter0, iter1, iter; GList *list; FSmon *fs; model = gtk_tree_view_get_model(treeview); path = gtk_tree_path_new_from_string("0"); gtk_tree_model_get_iter(model, &iter0, path); gtk_tree_path_free(path); path = gtk_tree_path_new_from_string("1"); gtk_tree_model_get_iter(model, &iter1, path); gtk_tree_path_free(path); if ( gtk_tree_model_iter_has_child(model, &iter1) && !gtk_tree_model_iter_has_child(model, &iter0) ) { gkrellm_config_message_dialog(_("Entry Error"),N_("At least one primary fs monitor must exist to click on in order to show\n""secondary ones.\n")); } for (list = fs_mon_list; list; list = list->next) destroy_fs_monitor((FSmon *) list->data); g_list_free(fs_mon_list); fs_mon_list = NULL; n_fs_monitors = 0; have_secondary_panels = gtk_tree_model_iter_has_child(model, &iter1); if (gtk_tree_model_iter_children(model, &iter, &iter0)) { do { fs = fs_new_from_model(model, &iter); fs->secondary = FALSE; fs->show_if_mounted = FALSE; fs_mon_list = g_list_append(fs_mon_list, fs); create_fs_monitor(fs_main_vbox, fs, n_fs_monitors, TRUE); gtk_tree_store_set(GTK_TREE_STORE(model), &iter, FSMON_COLUMN, fs, -1); gkrellm_alert_trigger_connect(fs->alert, cb_alert_trigger, fs); gkrellm_alert_config_connect(fs->alert, cb_alert_config, fs); } while (gtk_tree_model_iter_next(model, &iter)); } if (gtk_tree_model_iter_children(model, &iter, &iter1)) { do { fs = fs_new_from_model(model, &iter); fs->secondary = TRUE; fs_mon_list = g_list_append(fs_mon_list, fs); create_fs_monitor(fs_secondary_vbox, fs, n_fs_monitors, TRUE); gtk_tree_store_set(GTK_TREE_STORE(model), &iter, FSMON_COLUMN, fs, -1); gkrellm_alert_trigger_connect(fs->alert, cb_alert_trigger, fs); gkrellm_alert_config_connect(fs->alert, cb_alert_config, fs); } while (gtk_tree_model_iter_next(model, &iter)); } else secondary_monitors_shown = FALSE; force_fs_check = FORCE_UPDATE; if (g_list_length(fs_mon_list) > 0) gkrellm_spacers_show(mon_fs); else gkrellm_spacers_hide(mon_fs); }static voidadd_cb(GtkWidget *widget) { GtkTreeModel *model; GtkTreePath *path = NULL; GtkTreeIter iter, parent_iter; FSmon *fs; gchar *label; gint secondary, *indices; gboolean a, b, err = FALSE; fs = g_new0(FSmon, 1); fs->launch_mount.command = g_strdup(""); fs->launch_umount.command = g_strdup(""); fs->eject_device = g_strdup(""); label = gkrellm_gtk_entry_get_text(&label_entry); gkrellm_locale_dup_string(&fs->label, label, &fs->label_shadow); fs->mount.directory = g_strdup(gkrellm_gtk_entry_get_text(&(GTK_COMBO(dir_combo)->entry))); if (show_button) fs->show_if_mounted = GTK_TOGGLE_BUTTON(show_button)->active; if (mounting_button) fs->fstab_mounting = GTK_TOGGLE_BUTTON(mounting_button)->active; if (mount_entry) { gkrellm_dup_string(&(fs->launch_mount.command), gkrellm_gtk_entry_get_text(&mount_entry)); gkrellm_dup_string(&(fs->launch_umount.command), gkrellm_gtk_entry_get_text(&umount_entry)); } if (ejectable_button) { fs->ejectable = GTK_TOGGLE_BUTTON(ejectable_button)->active; if (fs->ejectable && !fs->fstab_mounting && device_entry) gkrellm_dup_string(&(fs->eject_device), gkrellm_gtk_entry_get_text(&device_entry)); } if (!*(fs->label) || !*(fs->mount.directory)) { gkrellm_config_message_dialog(_("Entry Error"),#if !defined(WIN32) _("Both a label and a mount point must be entered."));#else "Both a label and a disk must be entered.");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -