1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
/* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
#include "mc_sb_view.h"
#include <pobl/bl_str.h> /* strdup */
#include <pobl/bl_mem.h> /* free */
#include <pobl/bl_debug.h>
#include <pobl/bl_conf_io.h>
#include <pobl/bl_util.h> /* BL_ARRAY_SIZE */
#include <glib.h>
#include <c_intl.h>
#include <pobl/bl_types.h>
#include <dirent.h>
#include "mc_combo.h"
#include "mc_io.h"
#ifndef XDATADIR
#define SB_DIR "/usr/local/share/mlterm/scrollbars"
#else
#define SB_DIR XDATADIR "/mlterm/scrollbars"
#endif
#define MAX_SCROLLBARS 100
#if 0
#define __DEBUG
#endif
/* --- static variables --- */
static char *new_sb_view_name = NULL;
static char *old_sb_view_name = NULL;
static int is_changed;
/* --- static functions --- */
static void sb_view_name_selected(GtkWidget *widget, gpointer data) {
free(new_sb_view_name);
new_sb_view_name = gtk_editable_get_chars(GTK_EDITABLE(widget), 0, -1);
#ifdef __DEBUG
bl_debug_printf(BL_DEBUG_TAG " %s sb_view_name is selected.\n", new_sb_view_name);
#endif
}
static int has_rc_file(char *dirname, char *sbdirname) {
DIR *d;
struct dirent *e;
char path[PATH_MAX];
int result = 0;
snprintf(path, PATH_MAX, "%s/%s", dirname, sbdirname);
if (!(d = opendir(path))) return 0;
while ((e = readdir(d))) {
if (strcmp("rc", e->d_name) == 0) {
result = 1;
break;
}
}
closedir(d);
return result;
}
static int read_sb_names(char *dirname, char **sbnames, int n) {
int n0, j;
DIR *d;
struct dirent *e;
d = opendir(dirname);
if (!d) return n;
n0 = n;
while (n < MAX_SCROLLBARS) {
ignore:
e = readdir(d);
if (!e) break;
if (e->d_name[0] == '.' || !has_rc_file(dirname, e->d_name)) continue;
sbnames[n] = strdup(e->d_name);
if (!sbnames[n]) break;
for (j = 0; j < n0; j++) {
if (!strcmp(sbnames[n], sbnames[j])) goto ignore;
}
n++;
}
closedir(d);
return n;
}
/* --- global functions --- */
GtkWidget *mc_sb_view_config_widget_new(void) {
char *sb_view0[] = {"simple", "sample", "sample3", "athena", "motif", "mozmodern", "next"};
char *sb_view_names[MAX_SCROLLBARS];
char *userdir;
int n;
GtkWidget *combo;
GtkWidget *entry;
for (n = 0; n < BL_ARRAY_SIZE(sb_view0); n++) {
sb_view_names[n] = sb_view0[n];
}
userdir = bl_get_user_rc_path("mlterm/scrollbars");
if (userdir) {
n = read_sb_names(userdir, sb_view_names, n);
free(userdir);
}
n = read_sb_names(SB_DIR, sb_view_names, n);
new_sb_view_name = strdup(old_sb_view_name = mc_get_str_value("scrollbar_view_name"));
is_changed = 0;
combo = mc_combo_new(_("View"), sb_view_names, n, new_sb_view_name, 0, &entry);
g_signal_connect(entry, "changed", G_CALLBACK(sb_view_name_selected), NULL);
return combo;
}
void mc_update_sb_view_name(void) {
if (strcmp(new_sb_view_name, old_sb_view_name)) is_changed = 1;
if (is_changed) {
mc_set_str_value("scrollbar_view_name", new_sb_view_name);
free(old_sb_view_name);
old_sb_view_name = strdup(new_sb_view_name);
}
}
|