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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/*
* $Id$
*/
#include "mc_sb_view.h"
#include <kiklib/kik_str.h>
#include <kiklib/kik_mem.h> /* free */
#include <kiklib/kik_debug.h>
#include <kiklib/kik_conf_io.h>
#include <glib.h>
#include <c_intl.h>
#include <kiklib/kik_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 gint
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
kik_debug_printf( KIK_DEBUG_TAG " %s sb_view_name is selected.\n" , new_sb_view_name) ;
#endif
return 1 ;
}
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" ,
"sample2" ,
"sample3" ,
"athena" ,
"motif" ,
"mozmodern" ,
"next"
} ;
char *sb_view_names[MAX_SCROLLBARS];
char *userdir;
int n;
for (n=0; n<sizeof(sb_view0)/sizeof(sb_view0[0]); n++) {
sb_view_names[n] = sb_view0[n];
}
userdir = kik_get_user_rc_path("mlterm/scrollbars");
if (userdir) n = read_sb_names(userdir, sb_view_names, n);
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;
return mc_combo_new( _("View") , sb_view_names , n,
new_sb_view_name , 0 , sb_view_name_selected , NULL) ;
}
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) ;
}
}
|