1 /*
2 * KCemu -- The emulator for the KC85 homecomputer series and much more.
3 * Copyright (C) 1997-2010 Torsten Paul
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <stdio.h>
21 #include <pango-1.0/pango/pango-layout.h>
22
23 #include "kc/system.h"
24
25 #include "cmd/cmd.h"
26
27 #include "ui/gtk/disk.h"
28 #include "ui/gtk/cmd.h"
29
30 #include "libdbg/dbg.h"
31
32 class CMD_ui_disk_window_toggle : public CMD
33 {
34 private:
35 DiskWindow *_w;
36
37 public:
CMD_ui_disk_window_toggle(DiskWindow * w)38 CMD_ui_disk_window_toggle(DiskWindow *w) : CMD("ui-disk-window-toggle")
39 {
40 _w = w;
41 register_cmd("ui-disk-window-toggle");
42 }
43
execute(CMD_Args * args,CMD_Context context)44 void execute(CMD_Args *args, CMD_Context context)
45 {
46 _w->toggle();
47 }
48 };
49
50 class CMD_ui_disk_update : public CMD
51 {
52 private:
53 DiskWindow *_w;
54 public:
CMD_ui_disk_update(DiskWindow * w)55 CMD_ui_disk_update(DiskWindow *w) : CMD("ui-disk-update")
56 {
57 _w = w;
58 register_cmd("ui-disk-update-MSG");
59 }
60
execute(CMD_Args * args,CMD_Context context)61 void execute(CMD_Args *args, CMD_Context context)
62 {
63 int disk_no;
64
65 DBG(2, form("KCemu/Disk/update",
66 "got disk-update message\n"));
67
68 disk_no = args->get_long_arg("disk");
69 if ((disk_no < 0) || (disk_no > 3))
70 return;
71
72 _w->set_name(disk_no, args->get_string_arg("filename"));
73 }
74 };
75
76 class CMD_ui_disk_attach : public CMD
77 {
78 private:
79 DiskWindow *_w;
80 public:
CMD_ui_disk_attach(DiskWindow * w)81 CMD_ui_disk_attach(DiskWindow *w) : CMD("ui-disk-attach")
82 {
83 _w = w;
84 register_cmd("ui-disk-attach-1", 0);
85 register_cmd("ui-disk-attach-2", 1);
86 register_cmd("ui-disk-attach-3", 2);
87 register_cmd("ui-disk-attach-4", 3);
88 register_cmd("ui-disk-detach-1", 4);
89 register_cmd("ui-disk-detach-2", 5);
90 register_cmd("ui-disk-detach-3", 6);
91 register_cmd("ui-disk-detach-4", 7);
92 }
93
execute(CMD_Args * args,CMD_Context context)94 void execute(CMD_Args *args, CMD_Context context)
95 {
96 const char *filename;
97
98 if (!args)
99 args = new CMD_Args();
100
101 filename = NULL;
102 switch (context)
103 {
104 case 0:
105 case 1:
106 case 2:
107 case 3:
108 args->set_long_arg("disk", context);
109 CMD_EXEC_ARGS("disk-attach", args);
110 break;
111 case 4:
112 case 5:
113 case 6:
114 case 7:
115 args->set_long_arg("disk", context & 3);
116 CMD_EXEC_ARGS("disk-detach", args);
117 break;
118 }
119 }
120 };
121
DiskWindow(const char * ui_xml_file)122 DiskWindow::DiskWindow(const char *ui_xml_file) : UI_Gtk_Window(ui_xml_file)
123 {
124 init();
125
126 _cmd_attach = new CMD_ui_disk_attach(this);
127 _cmd_update = new CMD_ui_disk_update(this);
128 _cmd_window_toggle = new CMD_ui_disk_window_toggle(this);
129 }
130
~DiskWindow(void)131 DiskWindow::~DiskWindow(void)
132 {
133 delete _cmd_attach;
134 delete _cmd_update;
135 delete _cmd_window_toggle;
136 }
137
138 void
set_name(int idx,const char * name)139 DiskWindow::set_name(int idx, const char *name)
140 {
141 GtkEntry *entry = GTK_ENTRY(GTK_BIN(_w.combo[idx])->child);
142
143 if (!name)
144 name = "";
145
146 gtk_signal_handler_block(GTK_OBJECT(_w.combo[idx]), _w.combo_signal_id[idx]);
147 gtk_entry_set_text(entry, name);
148 gtk_signal_handler_unblock(GTK_OBJECT(_w.combo[idx]), _w.combo_signal_id[idx]);
149 }
150
151 void
sf_disk_attach(GtkWidget * widget,gpointer data)152 DiskWindow::sf_disk_attach(GtkWidget *widget, gpointer data)
153 {
154 long nr = (long)data;
155 GtkEntry *entry = GTK_ENTRY(GTK_BIN(widget)->child);
156 const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry));
157
158 if (text == NULL)
159 return;
160 if (strlen(text) == 0)
161 return;
162
163 CMD_Args *args = new CMD_Args();
164 args->set_long_arg("disk", nr);
165 args->set_string_arg("filename", text);
166 CMD_EXEC_ARGS("disk-attach", args);
167 }
168
169 void
init(void)170 DiskWindow::init(void)
171 {
172 static const char * attach_cmd[4] = {
173 "ui-disk-attach-1",
174 "ui-disk-attach-2",
175 "ui-disk-attach-3",
176 "ui-disk-attach-4",
177 };
178 static const char * detach_cmd[4] = {
179 "ui-disk-detach-1",
180 "ui-disk-detach-2",
181 "ui-disk-detach-3",
182 "ui-disk-detach-4",
183 };
184 static const char * disk_files[] = {
185 "a5105sys.dump",
186 "caos.dump",
187 "cpmz9.dump",
188 "microdos.dump",
189 "tools.dump",
190 "z1013cpm.dump",
191 "z1013gdc.dump",
192 NULL
193 };
194
195 GtkTreeIter iter;
196 GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
197 // for (int a = 0;disk_files[a] != NULL;a++)
198 // {
199 // gtk_list_store_append(store, &iter);
200 // gtk_list_store_set(store, &iter, 0, disk_files[a], -1);
201 // }
202
203 /*
204 * disk window
205 */
206 _window = get_widget("disk_window");
207 gtk_signal_connect(GTK_OBJECT(_window), "delete_event",
208 GTK_SIGNAL_FUNC(cmd_exec_sft),
209 (char *)"ui-disk-window-toggle"); // FIXME:
210
211
212 _w.combo[0] = get_widget("disk_comboboxentry_1");
213 _w.combo[1] = get_widget("disk_comboboxentry_2");
214 _w.combo[2] = get_widget("disk_comboboxentry_3");
215 _w.combo[3] = get_widget("disk_comboboxentry_4");
216
217 for (int a = 0;a < 4;a++)
218 {
219 gtk_combo_box_set_model(GTK_COMBO_BOX(_w.combo[a]), GTK_TREE_MODEL(store));
220 GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
221 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(_w.combo[a]), renderer, TRUE);
222 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(_w.combo[a]), renderer, "text", 0, NULL);
223 }
224
225 _w.browse[0] = get_widget("disk_button_open_1");
226 _w.browse[1] = get_widget("disk_button_open_2");
227 _w.browse[2] = get_widget("disk_button_open_3");
228 _w.browse[3] = get_widget("disk_button_open_4");
229
230 _w.eject[0] = get_widget("disk_button_close_1");
231 _w.eject[1] = get_widget("disk_button_close_2");
232 _w.eject[2] = get_widget("disk_button_close_3");
233 _w.eject[3] = get_widget("disk_button_close_4");
234
235 for (int a = 0;a < NR_OF_DISKS;a++) {
236 _w.combo_signal_id[a] = gtk_signal_connect(GTK_OBJECT(GTK_COMBO_BOX(_w.combo[a])),
237 "changed",
238 GTK_SIGNAL_FUNC(sf_disk_attach),
239 (gpointer)a);
240
241 gtk_signal_connect(GTK_OBJECT(_w.browse[a]), "clicked",
242 GTK_SIGNAL_FUNC(cmd_exec_sf),
243 (char *)attach_cmd[a]); // FIXME:
244 gtk_signal_connect(GTK_OBJECT(_w.eject[a]), "clicked",
245 GTK_SIGNAL_FUNC(cmd_exec_sf),
246 (char *)detach_cmd[a]); // FIXME:
247 }
248
249 init_dialog("ui-disk-window-toggle", "window-disk");
250 }
251