1 /*
2 * s39init.c System39.ini read
3 *
4 * Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
5 * 1998- <masaki-c@is.aist-nara.ac.jp>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22 /* $Id: s39init.c,v 1.2 2003/04/27 11:00:36 chikama Exp $ */
23
24 #include "config.h"
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <glib.h>
29 #include <gtk/gtk.h>
30 #include "portab.h"
31 #include "system.h"
32 #include "nact.h"
33 #include "s39init.h"
34 #include "eucsjis.h"
35 #include "music_client.h"
36
37 // Volume Valancer �ǰ�����������ͥ��
38 #define MAXVOLCH 16
39
40 static int vval_max; // ��������ͥ��ֹ�
41 struct _volval {
42 char *label;
43 int vol;
44 boolean mute;
45 };
46 static struct _volval vval[MAXVOLCH];
47 static GtkWidget *vval_win;
48
49 #include "menu_gui_volval.c"
50
51 // �����
s39ini_init(void)52 int s39ini_init(void) {
53 FILE *fp;
54 char s[256], s1[256];
55 int i, vol[MAXVOLCH] = {0};
56 char fn[256];
57
58 if (nact->files.init == NULL) return NG;
59
60 if (NULL == (fp = fopen(nact->files.init, "r"))) return NG;
61
62 while (fgets(s, 255, fp) != NULL) {
63 s1[0] = '\0';
64 sscanf(s, "VolumeValancer[%d] = \"%s", &i, s1);
65 if (s1[0] == '\0') continue;
66 if (i >= MAXVOLCH || i < 0) continue;
67 s1[strlen(s1)-1] = '\0'; // remove last '"'
68 vval[i].label = sjis2lang(s1);
69 vval_max = MAX(vval_max, i);
70 //WARNING("VolumeValancer[%d] = %s\n", i, vval[i].label);
71 }
72
73 if (vval_max <= 0) return NG;
74
75 // Volume.sav ������Ф�����ɤ߹���
76 g_snprintf(fn, sizeof(fn) -1, "%s/Volume.sav", nact->files.savedir);
77 if (NULL == (fp = fopen(fn, "r"))) {
78 // �Ȥꤢ����������ܥ�塼��� 100
79 for (i = 0; i < MAXVOLCH; i++) {
80 vol[i] = vval[i].vol = 100;
81 }
82 } else {
83 fread(vol, sizeof(int), MAXVOLCH, fp);
84 fclose(fp);
85 for (i = 0; i < MAXVOLCH; i++) {
86 vval[i].vol = vol[i];
87 }
88 }
89 // �ɤ���ˤ��Ƥ� music server ������
90 mus_vol_set_valance(vol, MAXVOLCH);
91
92 // System39.ini �� VolumeValancer ��̵���ä���ʤ�
93 if (vval_max > 0) {
94 vval_win = vval_win_open(vval, vval_max);
95 }
96
97 return OK;
98 }
99
100 // PopupMenu����ƤФ��
s39ini_winopen()101 int s39ini_winopen() {
102 if (vval_win) {
103 gtk_widget_show(vval_win);
104 nact->popupmenu_opened = TRUE;
105 }
106 return OK;
107 }
108
109 // �ܥ�塼������Window���Ĥ���줿�Ȥ��˸ƤФ��
s39ini_winclose()110 int s39ini_winclose() {
111 if (vval_win) {
112 gtk_widget_hide(vval_win);
113 nact->popupmenu_opened = FALSE;
114 }
115 return OK;
116 }
117
118 // �ܥ�塼������ǥ��������ư�������Ӥ˸ƤФ��
s39ini_setvol()119 int s39ini_setvol() {
120 int vol[MAXVOLCH] = {0};
121 int i;
122
123 if (vval_win == NULL) return OK;
124
125 for (i = 0; i < MAXVOLCH; i++) {
126 vol[i] = vval[i].mute ? 0 : vval[i].vol;
127 }
128
129 mus_vol_set_valance(vol, MAXVOLCH);
130 return OK;
131 }
132
133 // Volume Valance ����
s39ini_remove()134 int s39ini_remove() {
135 int vol[MAXVOLCH] = {0};
136 FILE *fp;
137 char fn[256];
138 int i;
139
140 if (vval_win == NULL) return OK;
141
142 for (i = 0; i < MAXVOLCH; i++) {
143 vol[i] = vval[i].vol;
144 }
145
146 g_snprintf(fn, sizeof(fn) -1, "%s/Volume.sav", nact->files.savedir);
147 if (NULL == (fp = fopen(fn, "w"))) {
148 WARNING("Fail to save Volume.save\n");
149 return NG;
150 }
151
152 fwrite(vol, sizeof(int), MAXVOLCH, fp);
153 fclose(fp);
154
155 return OK;
156
157 }
158