OSDN Git Service

[UI][Qt] Not liking config, using_flags directly.
[csp-qt/common_source_project-fm7.git] / source / src / qt / common / util_bubble2.cpp
1 #include "vm.h"
2 #include "mainwidget.h"
3 #include "commonclasses.h"
4 #include "menu_bubble.h"
5
6 #include "qt_dialogs.h"
7 #include "emu.h"
8 #include "agar_logger.h"
9
10 #if defined(USE_BUBBLE1)
11 extern EMU *emu;
12
13 #ifndef UPDATE_B77_LIST
14 #define UPDATE_B77_LIST(__d, lst) { \
15         lst.clear(); \
16         QString __tmps; \
17         for(int iii = 0; iii < MAX_B77_BANKS; iii++) { \
18                 __tmps = QString::fromUtf8(""); \
19                 if(iii < emu->b77_file[__d].bank_num) { \
20                         __tmps = QString::fromUtf8(emu->b77_file[__d].bubble_name[iii]); \
21                 } \
22         lst << __tmps; \
23         } \
24 }
25 #endif
26
27 int Ui_MainWindow::set_b77_slot(int drive, int num)
28 {
29         QString path;
30         if((num < 0) || (num >= using_flags->get_max_b77_banks())) return -1;
31         path = QString::fromUtf8(emu->b77_file[drive].path);
32         menu_bubbles[drive]->do_select_inner_media(num);
33
34         if(emu && emu->b77_file[drive].cur_bank != num) {
35                 emit sig_open_bubble(drive, path, num);
36                 if(emu->is_bubble_casette_protected(drive)) {
37                         menu_bubbles[drive]->do_set_write_protect(true);
38                 } else {
39                         menu_bubbles[drive]->do_set_write_protect(false);
40                 }
41         }
42         return 0;
43 }
44
45 void Ui_MainWindow::do_update_recent_bubble(int drv)
46 {
47         int i;
48         if(emu == NULL) return;
49         menu_bubbles[drv]->do_update_histories(listBubbles[drv]);
50         menu_bubbles[drv]->do_set_initialize_directory(p_config->initial_bubble_casette_dir);
51         if(emu->is_bubble_casette_protected(drv)) {
52                 menu_bubbles[drv]->do_write_protect_media();
53         } else {
54                 menu_bubbles[drv]->do_write_unprotect_media();
55         }
56 }
57
58
59 int Ui_MainWindow::set_recent_bubble(int drv, int num) 
60 {
61         QString s_path;
62         char path_shadow[PATH_MAX];
63         int i;
64         if((num < 0) || (num >= MAX_HISTORY)) return -1;
65         s_path = QString::fromLocal8Bit(p_config->recent_bubble_casette_path[drv][num]);
66         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX);
67         UPDATE_HISTORY(path_shadow, p_config->recent_bubble_casette_path[drv], listBubbles[drv]);
68         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX);
69    
70         get_parent_dir(path_shadow);
71         strcpy(p_config->initial_bubble_casette_dir, path_shadow);
72         strncpy(path_shadow, s_path.toLocal8Bit().constData(), PATH_MAX);
73
74         if(emu) {
75                 emit sig_close_bubble(drv);
76                 emit sig_open_bubble(drv, s_path, 0);
77                 menu_bubbles[drv]->do_update_histories(listBubbles[drv]);
78                 menu_bubbles[drv]->do_set_initialize_directory(p_config->initial_bubble_casette_dir);
79                 if(check_file_extension(path_shadow, ".b77")) {
80                         UPDATE_B77_LIST(drv, listB77[drv]);
81                         menu_bubbles[drv]->do_update_inner_media_bubble(listB77[drv], 0);
82                 } else {
83                         menu_bubbles[drv]->do_clear_inner_media();
84                 }
85         }
86         return 0;
87 }
88
89 void Ui_MainWindow::_open_bubble(int drv, const QString fname)
90 {
91         char path_shadow[PATH_MAX];
92         int i;
93
94         if(fname.length() <= 0) return;
95         drv = drv & 7;
96         strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX);
97         UPDATE_HISTORY(path_shadow, p_config->recent_bubble_casette_path[drv], listBubbles[drv]);
98         get_parent_dir(path_shadow);
99         strcpy(p_config->initial_bubble_casette_dir, path_shadow);
100         // Update List
101         strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX);
102         if(emu) {
103                 emit sig_close_bubble(drv);
104                 //emu->LockVM();
105                 emit sig_open_bubble(drv, fname, 0);
106                 menu_bubbles[drv]->do_update_histories(listBubbles[drv]);
107                 menu_bubbles[drv]->do_set_initialize_directory(p_config->initial_bubble_casette_dir);
108                 if(check_file_extension(path_shadow, ".b77")) {
109                         UPDATE_B77_LIST(drv, listB77[drv]);
110                         menu_bubbles[drv]->do_update_inner_media_bubble(listB77[drv], 0);
111                 } else {
112                         menu_bubbles[drv]->do_clear_inner_media();
113                 }
114         }
115 }
116
117 void Ui_MainWindow::eject_bubble(int drv) 
118 {
119         int i;
120         emit sig_close_bubble(drv);
121         menu_bubbles[drv]->do_clear_inner_media();
122 }
123 #endif