diff options
| author | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2009-11-28 10:58:17 +0000 |
|---|---|---|
| committer | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2009-11-28 10:58:17 +0000 |
| commit | 78d783281d5381facf626b4adad4509bd276b843 (patch) | |
| tree | cc75f5a17cad81dac6544a2203f34882e86021bb /gui | |
| parent | 555d07b089f1893a3ae9534dcad7397f1fd6eedf (diff) | |
| download | pcsxr-78d783281d5381facf626b4adad4509bd276b843.tar.gz | |
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@38376 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'gui')
| -rw-r--r-- | gui/Cheat.c | 4 | ||||
| -rw-r--r-- | gui/Gtk2Gui.c | 567 | ||||
| -rw-r--r-- | gui/Makefile.am | 1 | ||||
| -rw-r--r-- | gui/Makefile.in | 4 | ||||
| -rw-r--r-- | gui/MemcardDlg.c | 723 | ||||
| -rw-r--r-- | gui/MemcardDlg.h | 24 |
6 files changed, 757 insertions, 566 deletions
diff --git a/gui/Cheat.c b/gui/Cheat.c index 0bd9bcae..0bec52a3 100644 --- a/gui/Cheat.c +++ b/gui/Cheat.c @@ -85,6 +85,7 @@ static void CheatList_TreeSelectionChanged(GtkTreeSelection *selection, gpointer if (selected) { path = gtk_tree_model_get_path(model, &iter); i = *gtk_tree_path_get_indices(path); + gtk_tree_path_free(path); // If a row was selected, and the row is not blank, we can now enable // some of the disabled widgets @@ -189,6 +190,7 @@ static void OnCheatListDlg_EditClicked(GtkWidget *widget, gpointer user_data) { path = gtk_tree_model_get_path(model, &iter); index = *gtk_tree_path_get_indices(path); + gtk_tree_path_free(path); dlg = gtk_dialog_new_with_buttons(_("Edit Cheat"), GTK_WINDOW(CheatListDlg), GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, @@ -277,6 +279,7 @@ static void OnCheatListDlg_DelClicked(GtkWidget *widget, gpointer user_data) { if (selected) { path = gtk_tree_model_get_path(model, &iter); i = *gtk_tree_path_get_indices(path); + gtk_tree_path_free(path); RemoveCheat(i); } @@ -610,6 +613,7 @@ static int GetSelectedResultIndex() { path = gtk_tree_model_get_path(model, &iter); i = *gtk_tree_path_get_indices(path); + gtk_tree_path_free(path); assert(i < NumSearchResults); return i; diff --git a/gui/Gtk2Gui.c b/gui/Gtk2Gui.c index 0ae4ccc7..f023a7c4 100644 --- a/gui/Gtk2Gui.c +++ b/gui/Gtk2Gui.c @@ -36,6 +36,8 @@ #include "../libpcsxcore/sio.h" #include "../libpcsxcore/cheat.h" +#include "MemcardDlg.h" + extern int UseGui; PSEgetLibType PSE_getLibType = NULL; @@ -46,13 +48,11 @@ PSEgetLibName PSE_getLibName = NULL; void UpdatePluginsBIOS(); void UpdatePluginsBIOS_UpdateGUI(GladeXML *xml); void FindNetPlugin(GladeXML *xml); -void copy_memcard_data (char *from, char *to, gint *i, gchar *str); void OnNet_Conf(GtkWidget *widget, gpointer user_data); void OnNet_About(GtkWidget *widget, gpointer user_data); // Functions Callbacks -/*make them getting the right params, will be used later*/ void OnFile_RunCd(); void OnFile_RunBios(); void OnFile_RunExe(); @@ -64,7 +64,6 @@ void OnConf_Graphics(); void OnConf_Sound(); void OnConf_CdRom(); void OnConf_Pad(); -void OnConf_Mcds(); void OnConf_Cpu(); void OnConf_Net(); void OnHelp_Help(); @@ -98,7 +97,6 @@ GtkWidget *controlwidget; int destroy = 0; #define MAX_SLOTS 5 -#define MAX_MEMCARD_BLOCKS 15 #define FindComboText(combo, list, conf) \ if (strlen(conf) > 0) { \ @@ -1038,457 +1036,6 @@ void OnConf_Net() { GTK_SIGNAL_FUNC(OnNet_About), xml, NULL, G_CONNECT_AFTER); } -McdBlock Blocks[2][MAX_MEMCARD_BLOCKS]; /* Assuming 2 cards, 15 blocks? */ -int IconC[2][MAX_MEMCARD_BLOCKS]; -enum { - CL_ICON, - CL_TITLE, - CL_STAT, - CL_ID, - CL_NAME, - NUM_CL -}; - -GtkWidget *GtkCList_McdList1, *GtkCList_McdList2; -GtkTreeSelection *sel1, *sel2; -gint mcd1_row, mcd2_row; - -static void add_columns (GtkTreeView *treeview) { - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; - - /* column for icon */ - renderer = gtk_cell_renderer_pixbuf_new (); - column = gtk_tree_view_column_new_with_attributes (_("Icon"), - renderer, "pixbuf", CL_ICON, NULL); - gtk_tree_view_append_column (treeview, column); - - /* column for title */ - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("Title"), - renderer, "text", CL_TITLE, NULL); - gtk_tree_view_append_column (treeview, column); - - /* column for status */ - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("Status"), - renderer, "text", CL_STAT, NULL); - gtk_tree_view_append_column (treeview, column); - - /* column for id */ - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("ID"), - renderer, "text", CL_ID, NULL); - gtk_tree_view_append_column (treeview, column); - - /* column for Name */ - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (_("Name"), - renderer, "text", CL_NAME, NULL); - gtk_tree_view_append_column (treeview, column); -} - -GdkPixbuf *SetIcon(GtkWidget *dialog, short *icon, int i) { - GdkPixmap *pixmap; - GdkImage *image; - GdkVisual *visual; - GdkGC *gc; - int x, y, c; - - visual = gdk_window_get_visual(dialog->window); - - if (visual->depth == 8) return NULL; - - image = gdk_image_new(GDK_IMAGE_NORMAL, visual, 16, 16); - - for (y=0; y<16; y++) { - for (x=0; x<16; x++) { - c = icon[y*16+x]; - c = ((c&0x001f) << 10) | ((c&0x7c00) >> 10) | (c&0x03e0); - if (visual->depth == 16) - c = (c&0x001f) | ((c&0x7c00) << 1) | ((c&0x03e0) << 1); - else if (visual->depth == 24 || visual->depth == 32) - c = ((c&0x001f) << 3) | ((c&0x03e0) << 6) | ((c&0x7c00) << 9); - - gdk_image_put_pixel(image, x, y, c); - } - } - - pixmap = gdk_pixmap_new(dialog->window, 16, 16, visual->depth); - - gc = gdk_gc_new(pixmap); - gdk_draw_image(pixmap, gc, image, 0, 0, 0, 0, 16, 16); - gdk_gc_destroy(gc); - gdk_image_destroy(image); - - return gdk_pixbuf_get_from_drawable (NULL, - GDK_PIXMAP (pixmap), - NULL, - 0,0,0,0,-1,-1); -} - -void LoadListItems(int mcd, GtkWidget *List, GtkWidget *dialog) { - int i; - - GtkListStore *store= gtk_list_store_new (NUM_CL,GDK_TYPE_PIXBUF, G_TYPE_STRING, - G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING); - GtkTreeIter iter; - GdkPixbuf *pixbuf; - - for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) { - McdBlock *Info; - gchar *state; - - Info = &Blocks[mcd-1][i]; - IconC[mcd-1][i] = 0; - - if ((Info->Flags & 0xF0) == 0xA0) { - if ((Info->Flags & 0xF) >= 1 && - (Info->Flags & 0xF) <= 3) { - state = _("Deleted"); - } else - state = _("Free"); - } else if ((Info->Flags & 0xF0) == 0x50) - state = _("Used"); - else - state = _("Free"); - -// if (Info->IconCount == 0) continue; - - pixbuf = SetIcon(dialog, Info->Icon, i+1); - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - CL_ICON, pixbuf, - CL_TITLE, Info->Title, - CL_STAT, state, - CL_NAME, Info->Name, - CL_ID, Info->ID, - -1); - } - - gtk_tree_view_set_model (GTK_TREE_VIEW (List), GTK_TREE_MODEL (store)); - g_object_unref (G_OBJECT (store)); - gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (List), TRUE); - gtk_widget_show(List); -} - -void UpdateMcdDlg(GtkWidget *widget) { - int i; - GladeXML *xml; - GtkWidget *list1, *list2, *dialog; - - for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) { - GetMcdBlockInfo(1, i+1, &Blocks[0][i]); - GetMcdBlockInfo(2, i+1, &Blocks[1][i]); - } - - xml = glade_get_widget_tree (widget); - list1 = glade_xml_get_widget (xml, "GtkCList_McdList1"); - list2 = glade_xml_get_widget (xml, "GtkCList_McdList2"); - dialog = glade_xml_get_widget (xml, "McdsDlg"); - LoadListItems(1, list1, dialog); - LoadListItems(2, list2, dialog); -} - -void OnMcd_Clicked (GtkDialog *dialog, gint arg1, gpointer user_data) { - GladeXML *xml = user_data; - - if (arg1 == GTK_RESPONSE_OK) { - gchar *tmp; - GtkWidget *widget; - - widget = glade_xml_get_widget (xml, "GtkMcd1FSButton"); - if ((tmp = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget))) != NULL) { - strcpy(Config.Mcd1, tmp); - g_free (tmp); - } - - widget = glade_xml_get_widget (xml, "GtkMcd2FSButton"); - if ((tmp = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget))) != NULL) { - strcpy(Config.Mcd2, tmp); - g_free (tmp); - } - - SaveConfig(); - } - - LoadMcds(Config.Mcd1, Config.Mcd2); - gtk_widget_destroy(GTK_WIDGET (dialog)); -} - -void on_memcard_file_changed (GtkWidget *widget, gpointer user_data) { - gint memcard = (int) user_data; - gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget)); - - if (filename != NULL) { - LoadMcd(memcard, filename); - UpdateMcdDlg(widget); - gtk_widget_set_sensitive (widget, TRUE); - } - - g_free (filename); -} - -void OnMcd_Format(GtkWidget *widget, gpointer user_data) { - GladeXML *xml; - GtkWidget *memcard_fs; - GtkWidget *message_dialog; - gint result; - gchar *str; - - gint memcard = (int) user_data; - - /* TODO Check if the memory card actually has data on it before displaying this */ - - message_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, - GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, - _("Format this Memory Card?")); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message_dialog), - _("If you format the memory card, the card will be empty, and any existing data overwritten.")); - gtk_dialog_add_buttons (GTK_DIALOG (message_dialog), - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - _("Format card"), GTK_RESPONSE_YES, - NULL); - - result = gtk_dialog_run (GTK_DIALOG (message_dialog)); - gtk_widget_destroy (message_dialog); - - if (result == GTK_RESPONSE_YES) { - xml = glade_get_widget_tree (widget); - if (memcard == 1) - memcard_fs = glade_xml_get_widget (xml, "GtkMcd1FSButton"); - else - memcard_fs = glade_xml_get_widget (xml, "GtkMcd2FSButton"); - - str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (memcard_fs)); - - CreateMcd(str); - LoadMcd(memcard, str); - UpdateMcdDlg(widget); - g_free (str); - } -} - -void OnMcd_Reload (GtkWidget *widget, gpointer user_data) { - GladeXML *xml; - GtkWidget *memcard_fs; - gchar *str; - - gint memcard = (int) user_data; - - xml = glade_get_widget_tree (widget); - - if (memcard == 1) { - memcard_fs = glade_xml_get_widget (xml, "GtkMcd1FSButton"); - str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (memcard_fs)); - } else { - memcard_fs = glade_xml_get_widget (xml, "GtkMcd2FSButton"); - str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (memcard_fs)); - } - - LoadMcd (memcard, str); - UpdateMcdDlg(widget); - - g_free (str); -} - -static int copy = 0, copymcd = 0; - -static int get_free_memcard_slot (int target_card) { - McdBlock *Info; - gboolean found = FALSE; - - int i = 0; - while (i < 15 && found == FALSE) { - Info = &Blocks[target_card][i]; - if (g_ascii_strcasecmp (Info->Title, "") == 0) { - found = TRUE; - } else { - i++; - } - } - - if (found == TRUE) - return i; - - // no free slots, try to find a deleted one - i = 0; - while (i < 15 && found == FALSE) { - Info = &Blocks[target_card][i]; - if ((Info->Flags & 0xF0) != 0x50) { - found = TRUE; - } else { - i++; - } - } - - if (found == TRUE) - return i; - - return -1; -} - -void OnMcd_CopyTo(GtkWidget *widget, gpointer user_data) { - gint mcd = (gint)user_data; - - GtkTreeIter iter; - GtkTreeModel *model; - GtkTreePath *path; - gint *i; - GladeXML *xml; - GtkTreeSelection *treesel; - gchar *str; - char *source, *destination; - - int first_free_slot; - - xml = glade_get_widget_tree(widget); - - if (mcd == 1) - treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(GtkCList_McdList1)); - else - treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(GtkCList_McdList2)); - - /* If the item selected is not reported as a 'Free' slot */ - if (gtk_tree_selection_get_selected(treesel, &model, &iter)) { - path = gtk_tree_model_get_path(model, &iter); - i = gtk_tree_path_get_indices(path); - copy = *i; - copymcd = mcd; - gtk_tree_path_free(path); - } - - /* Determine the first free slot in the target memory card */ - first_free_slot = get_free_memcard_slot(mcd - 1); - if (first_free_slot == -1) { - /* No free slots available on the destination card */ - SysMessage(_("No space available in the target memory card!")); - return; - } - xml = glade_get_widget_tree (GtkCList_McdList1); - - if (mcd == 1) { - str = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(glade_xml_get_widget (xml, "GtkMcd1FSButton"))); - source = Mcd2Data; - copy = mcd2_row; - destination = Mcd1Data; - } else { - str = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(glade_xml_get_widget (xml, "GtkMcd2FSButton"))); - source = Mcd1Data; - copy = mcd1_row; - destination = Mcd2Data; - } - - copy_memcard_data (source, destination, &first_free_slot, str); - UpdateMcdDlg(widget); -} - -void copy_memcard_data (char *from, char *to, gint *i, gchar *str) { - memcpy(to + (*i+1) * 128, from + (copy+1) * 128, 128); - SaveMcd((char*)str, to, (*i+1) * 128, 128); - memcpy(to + (*i+1) * 1024 * 8, from + (copy+1) * 1024 * 8, 1024 * 8); - SaveMcd((char*)str, to, (*i+1) * 1024 * 8, 1024 * 8); -} - -void tree_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data) { - GladeXML *xml; - GtkTreeIter iter; - GtkTreeModel *model; - GtkTreePath *path; - - gboolean selected; - int i; - char *data; - - gint memcard = (int) user_data; - - if (memcard == 1) { - selected = gtk_tree_selection_get_selected (selection, &model, &iter); - data = Mcd1Data; - } else { - selected = gtk_tree_selection_get_selected (selection, &model, &iter); - data = Mcd2Data; - } - - if (selected) { - path = gtk_tree_model_get_path (model, &iter); - i = *gtk_tree_path_get_indices (path); - - /* If a row was selected, and the row is not blank, we can now enable - some of the disabled widgets */ - /* Check LoadListItems for determining state */ - xml = glade_get_widget_tree (GtkCList_McdList1); - GtkWidget *disable, *enable; - if (memcard == 1) { - mcd1_row = i; - enable = glade_xml_get_widget (xml, "GtkButton_CopyTo2"); - disable = glade_xml_get_widget (xml, "GtkButton_CopyTo1"); - } else { - mcd2_row = i; - enable = glade_xml_get_widget (xml, "GtkButton_CopyTo1"); - disable = glade_xml_get_widget (xml, "GtkButton_CopyTo2"); - } - gtk_widget_set_sensitive (enable, TRUE); - gtk_widget_set_sensitive (disable, FALSE); - } -} - -void on_memcard_delete (GtkWidget *widget, gpointer user_data) { - McdBlock *Info; - int i, xor = 0, j; - char *data, *ptr; - GtkTreeIter iter; - GtkTreeModel *model; - GtkTreePath *path; - gchar *filename; - GladeXML *xml; - gboolean selected; - GtkWidget *tree; - GtkTreeSelection *sel; - - gint memcard = (int) user_data; - - xml = glade_get_widget_tree (widget); - if (memcard == 1) { - tree = glade_xml_get_widget (xml, "GtkCList_McdList1"); - sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree)); - selected = gtk_tree_selection_get_selected (sel, &model, &iter); - data = Mcd1Data; - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (glade_xml_get_widget (xml, "GtkMcd1FSButton"))); - } else { - tree = glade_xml_get_widget (xml, "GtkCList_McdList2"); - sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree)); - selected = gtk_tree_selection_get_selected (sel, &model, &iter); - data = Mcd2Data; - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (glade_xml_get_widget (xml, "GtkMcd2FSButton"))); - } - - if (selected) { - path = gtk_tree_model_get_path (model, &iter); - i = *gtk_tree_path_get_indices (path); - - i++; - ptr = data + i * 128; - Info = &Blocks[memcard-1][i-1]; - - if ((Info->Flags & 0xF0) == 0xA0) { - if ((Info->Flags & 0xF) >= 1 && - (Info->Flags & 0xF) <= 3) { // deleted - *ptr = 0x50 | (Info->Flags & 0xF); - } else return; - } else if ((Info->Flags & 0xF0) == 0x50) { // used - *ptr = 0xA0 | (Info->Flags & 0xF); - } else { return; } - - for (j=0; j<127; j++) xor^=*ptr++; - *ptr = xor; - - SaveMcd((char*)filename, data, i * 128, 128); - UpdateMcdDlg(widget); - } -} - void OnConf_Graphics() { void *drv; GPUconfigure conf; @@ -1588,116 +1135,6 @@ void OnConf_Pad() { } } -void OnConf_Mcds() { - GladeXML *xml; - GtkWidget *dialog; - GtkWidget *widget; - GtkTreeSelection *treesel1, *treesel2; - gchar *str; - int i; - - xml = glade_xml_new(PACKAGE_DATA_DIR "pcsx.glade2", "McdsDlg", NULL); - - if (!xml) { - g_warning("We could not load the interface!"); - return; - } - - dialog = glade_xml_get_widget(xml, "McdsDlg"); - - gtk_window_set_title(GTK_WINDOW(dialog), _("Memory Card Manager")); - - /* Assign default memory cards */ - if (!strlen(Config.Mcd1)) { - str = g_strconcat (getenv("HOME"), DEFAULT_MEM_CARD_1, NULL); - strcpy(Config.Mcd1, str); - g_free (str); - } - - if (!strlen(Config.Mcd2)) { - str = g_strconcat (getenv("HOME"), DEFAULT_MEM_CARD_2, NULL); - strcpy(Config.Mcd2, str); - g_free (str); - } - - GtkCList_McdList1 = glade_xml_get_widget(xml, "GtkCList_McdList1"); - add_columns(GTK_TREE_VIEW (GtkCList_McdList1)); - GtkCList_McdList2 = glade_xml_get_widget(xml, "GtkCList_McdList2"); - add_columns(GTK_TREE_VIEW (GtkCList_McdList2)); - - treesel1 = gtk_tree_view_get_selection (GTK_TREE_VIEW (GtkCList_McdList1)); - gtk_tree_selection_set_mode (treesel1, GTK_SELECTION_SINGLE); - g_signal_connect_data (G_OBJECT (treesel1), "changed", - G_CALLBACK (tree_selection_changed_cb), - (gpointer) 1, NULL, - G_CONNECT_AFTER); - - treesel2 = gtk_tree_view_get_selection (GTK_TREE_VIEW (GtkCList_McdList2)); - gtk_tree_selection_set_mode (treesel2, GTK_SELECTION_SINGLE); - g_signal_connect_data (G_OBJECT (treesel2), "changed", - G_CALLBACK (tree_selection_changed_cb), - (gpointer) 2, NULL, - G_CONNECT_AFTER); - - for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) { - GetMcdBlockInfo (1, i+1, &Blocks[0][i]); - GetMcdBlockInfo (2, i+1, &Blocks[1][i]); - } - - LoadListItems(1, GtkCList_McdList1, dialog); - LoadListItems(2, GtkCList_McdList2, dialog); - - /* Setup a handler for when Close or Cancel is clicked */ - g_signal_connect_data(GTK_OBJECT(dialog), "response", - GTK_SIGNAL_FUNC(OnMcd_Clicked), xml, (GClosureNotify)g_object_unref, G_CONNECT_AFTER); - - widget = glade_xml_get_widget(xml, "GtkButton_Format1"); - g_signal_connect_data(GTK_OBJECT(widget), "clicked", - GTK_SIGNAL_FUNC(OnMcd_Format), (gpointer) 1, NULL, G_CONNECT_AFTER); - - widget = glade_xml_get_widget(xml, "GtkButton_Format2"); - g_signal_connect_data(GTK_OBJECT(widget), "clicked", - GTK_SIGNAL_FUNC(OnMcd_Format), (gpointer) 2, NULL, G_CONNECT_AFTER); - - widget = glade_xml_get_widget(xml, "GtkMcd1FSButton"); - g_signal_connect_data(GTK_OBJECT(widget), "selection-changed", - GTK_SIGNAL_FUNC(on_memcard_file_changed), (gpointer) 1, NULL, G_CONNECT_AFTER); - gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (widget), Config.Mcd1); - - widget = glade_xml_get_widget(xml, "GtkMcd2FSButton"); - g_signal_connect_data(GTK_OBJECT(widget), "selection-changed", - GTK_SIGNAL_FUNC(on_memcard_file_changed), (gpointer) 2, NULL, G_CONNECT_AFTER); - gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (widget), Config.Mcd2); - - widget = glade_xml_get_widget(xml, "GtkButton_Reload1"); - g_signal_connect_data(GTK_OBJECT(widget), "clicked", - GTK_SIGNAL_FUNC(OnMcd_Reload), (gpointer) 1, NULL, G_CONNECT_AFTER); - - widget = glade_xml_get_widget(xml, "GtkButton_Reload2"); - g_signal_connect_data(GTK_OBJECT(widget), "clicked", - GTK_SIGNAL_FUNC(OnMcd_Reload), (gpointer) 2, NULL, G_CONNECT_AFTER); - - widget = glade_xml_get_widget(xml, "GtkButton_CopyTo1"); - g_signal_connect_data(GTK_OBJECT(widget), "clicked", - GTK_SIGNAL_FUNC(OnMcd_CopyTo), (gpointer) 1, NULL, G_CONNECT_AFTER); - gtk_widget_set_sensitive (GTK_WIDGET (widget), FALSE); - - widget = glade_xml_get_widget(xml, "GtkButton_CopyTo2"); - g_signal_connect_data(GTK_OBJECT(widget), "clicked", - GTK_SIGNAL_FUNC(OnMcd_CopyTo), (gpointer) 2, NULL, G_CONNECT_AFTER); - gtk_widget_set_sensitive (GTK_WIDGET (widget), FALSE); - - widget = glade_xml_get_widget(xml, "GtkButton_Delete1"); - g_signal_connect_data (GTK_OBJECT (widget), "clicked", - GTK_SIGNAL_FUNC (on_memcard_delete), (gpointer) 1, NULL, G_CONNECT_AFTER); - - widget = glade_xml_get_widget(xml, "GtkButton_Delete2"); - g_signal_connect_data (GTK_OBJECT (widget), "clicked", - GTK_SIGNAL_FUNC (on_memcard_delete), (gpointer) 2, NULL, G_CONNECT_AFTER); - - while (gtk_events_pending()) gtk_main_iteration(); -} - GtkWidget *CpuDlg; GtkWidget *PsxCombo; GList *psxglist; diff --git a/gui/Makefile.am b/gui/Makefile.am index 77c0c46b..c649e4f2 100644 --- a/gui/Makefile.am +++ b/gui/Makefile.am @@ -13,6 +13,7 @@ pcsx_SOURCES = \ Plugin.c \ Config.c \ Gtk2Gui.c \ + MemcardDlg.c \ Cheat.c pcsx_LDADD = \ diff --git a/gui/Makefile.in b/gui/Makefile.in index 0c29fe75..db624692 100644 --- a/gui/Makefile.in +++ b/gui/Makefile.in @@ -47,7 +47,7 @@ am__installdirs = "$(DESTDIR)$(bindir)" binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) am_pcsx_OBJECTS = LnxMain.$(OBJEXT) Plugin.$(OBJEXT) Config.$(OBJEXT) \ - Gtk2Gui.$(OBJEXT) Cheat.$(OBJEXT) + Gtk2Gui.$(OBJEXT) MemcardDlg.$(OBJEXT) Cheat.$(OBJEXT) pcsx_OBJECTS = $(am_pcsx_OBJECTS) am__DEPENDENCIES_1 = pcsx_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ @@ -231,6 +231,7 @@ pcsx_SOURCES = \ Plugin.c \ Config.c \ Gtk2Gui.c \ + MemcardDlg.c \ Cheat.c pcsx_LDADD = \ @@ -312,6 +313,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Config.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Gtk2Gui.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LnxMain.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MemcardDlg.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Plugin.Po@am__quote@ .c.o: diff --git a/gui/MemcardDlg.c b/gui/MemcardDlg.c new file mode 100644 index 00000000..255838d0 --- /dev/null +++ b/gui/MemcardDlg.c @@ -0,0 +1,723 @@ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307 USA + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <gdk/gdkkeysyms.h> +#include <gtk/gtk.h> +#include <glade/glade.h> +#include <signal.h> +#include <sys/time.h> + +#include "Linux.h" +#include "../libpcsxcore/sio.h" + +#define MAX_MEMCARD_BLOCKS 15 + +McdBlock Blocks[2][MAX_MEMCARD_BLOCKS]; // Assuming 2 cards, 15 blocks? +int IconC[2][MAX_MEMCARD_BLOCKS]; +enum { + CL_ICON, + CL_TITLE, + CL_STAT, + CL_ID, + CL_NAME, + NUM_CL +}; + +GtkWidget *GtkCList_McdList1, *GtkCList_McdList2; + +static void AddColumns(GtkTreeView *treeview) { + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + + // column for icon + renderer = gtk_cell_renderer_pixbuf_new (); + column = gtk_tree_view_column_new_with_attributes(_("Icon"), + renderer, "pixbuf", CL_ICON, NULL); + gtk_tree_view_append_column(treeview, column); + + // column for title + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes(_("Title"), + renderer, "text", CL_TITLE, NULL); + gtk_tree_view_append_column(treeview, column); + + // column for status + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes(_("Status"), + renderer, "text", CL_STAT, NULL); + gtk_tree_view_append_column(treeview, column); + + // column for id + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes(_("ID"), + renderer, "text", CL_ID, NULL); + gtk_tree_view_append_column(treeview, column); + + // column for Name + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes(_("Name"), + renderer, "text", CL_NAME, NULL); + gtk_tree_view_append_column(treeview, column); +} + +static GdkPixbuf *SetIcon(GtkWidget *dialog, short *icon, int i) { + GdkPixmap *pixmap; + GdkImage *image; + GdkVisual *visual; + GdkGC *gc; + int x, y, c; + + visual = gdk_window_get_visual(dialog->window); + + if (visual->depth == 8) return NULL; + + image = gdk_image_new(GDK_IMAGE_NORMAL, visual, 16, 16); + + for (y = 0; y < 16; y++) { + for (x = 0; x < 16; x++) { + c = icon[y * 16 + x]; + c = ((c & 0x001f) << 10) | ((c & 0x7c00) >> 10) | (c & 0x03e0); + if (visual->depth == 16) + c = (c & 0x001f) | ((c & 0x7c00) << 1) | ((c & 0x03e0) << 1); + else if (visual->depth == 24 || visual->depth == 32) + c = ((c & 0x001f) << 3) | ((c & 0x03e0) << 6) | ((c & 0x7c00) << 9); + + gdk_image_put_pixel(image, x, y, c); + } + } + + pixmap = gdk_pixmap_new(dialog->window, 16, 16, visual->depth); + + gc = gdk_gc_new(pixmap); + gdk_draw_image(pixmap, gc, image, 0, 0, 0, 0, 16, 16); + gdk_gc_destroy(gc); + gdk_image_destroy(image); + + return gdk_pixbuf_get_from_drawable(NULL, GDK_PIXMAP (pixmap), NULL, + 0, 0, 0, 0, -1, -1); +} + +static int GetSelection(int memcard) { + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeSelection *selection; + int r; + + gboolean selected; + + if (memcard == 1) + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(GtkCList_McdList1)); + else + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(GtkCList_McdList2)); + + selected = gtk_tree_selection_get_selected(selection, &model, &iter); + + if (selected) { + path = gtk_tree_model_get_path(model, &iter); + r = *gtk_tree_path_get_indices(path); + gtk_tree_path_free(path); + return r; + } + + return -1; +} + +static void LoadListItems(int mcd, GtkWidget *widget) { + int i; + GladeXML *xml; + GtkWidget *List; + GtkWidget *dialog; + GtkListStore *store; + GtkTreeIter iter; + GdkPixbuf *pixbuf; + + store = gtk_list_store_new(NUM_CL, GDK_TYPE_PIXBUF, G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + + xml = glade_get_widget_tree(widget); + dialog = glade_xml_get_widget(xml, "McdsDlg"); + + if (mcd == 1) List = glade_xml_get_widget(xml, "GtkCList_McdList1"); + else List = glade_xml_get_widget(xml, "GtkCList_McdList2"); + + for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) { + McdBlock *Info; + gchar *state; + + Info = &Blocks[mcd - 1][i]; + IconC[mcd - 1][i] = 0; + + if ((Info->Flags & 0xF0) == 0xA0) { + if ((Info->Flags & 0xF) >= 1 && + (Info->Flags & 0xF) <= 3) { + state = _("Deleted"); + } else + state = _("Free"); + } else if ((Info->Flags & 0xF0) == 0x50) + state = _("Used"); + else + state = _("Free"); + +// if (Info->IconCount == 0) continue; + + pixbuf = SetIcon(dialog, Info->Icon, i + 1); + + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, + CL_ICON, pixbuf, + CL_TITLE, Info->Title, + CL_STAT, state, + CL_NAME, Info->Name, + CL_ID, Info->ID, + -1); + } + + gtk_tree_view_set_model(GTK_TREE_VIEW(List), GTK_TREE_MODEL(store)); + g_object_unref(G_OBJECT(store)); + gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(List), TRUE); + gtk_widget_show(List); +} + +static void LoadMcdDlg(GtkWidget *widget) { + int i; + + for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) { + GetMcdBlockInfo(1, i + 1, &Blocks[0][i]); + GetMcdBlockInfo(2, i + 1, &Blocks[1][i]); + } + + LoadListItems(1, widget); + LoadListItems(2, widget); +} + +static void OnTreeSelectionChanged(GtkTreeSelection *selection, gpointer user_data); + +static void UpdateListItems(int mcd, GtkWidget *widget) { + GladeXML *xml; + GtkWidget *List; + GtkWidget *dialog; + GtkListStore *store; + GtkTreeIter iter; + GdkPixbuf *pixbuf; + int i; + + xml = glade_get_widget_tree(widget); + dialog = glade_xml_get_widget(xml, "McdsDlg"); + + if (mcd == 1) List = glade_xml_get_widget(xml, "GtkCList_McdList1"); + else List = glade_xml_get_widget(xml, "GtkCList_McdList2"); + + store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(List))); + gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); + + for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) { + McdBlock *Info; + gchar *state; + + Info = &Blocks[mcd - 1][i]; + IconC[mcd - 1][i] = 0; + + if ((Info->Flags & 0xF0) == 0xA0) { + if ((Info->Flags & 0xF) >= 1 && + (Info->Flags & 0xF) <= 3) { + state = _("Deleted"); + } else + state = _("Free"); + } else if ((Info->Flags & 0xF0) == 0x50) + state = _("Used"); + else + state = _("Free"); + +// if (Info->IconCount == 0) continue; + + pixbuf = SetIcon(dialog, Info->Icon, i + 1); + + gtk_list_store_set(store, &iter, + CL_ICON, pixbuf, + CL_TITLE, Info->Title, + CL_STAT, state, + CL_NAME, Info->Name, + CL_ID, Info->ID, + -1); + + gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); + } + + gtk_widget_show(List); + + OnTreeSelectionChanged(gtk_tree_view_get_selection(GTK_TREE_VIEW(List)), (gpointer)mcd); +} + +static void UpdateMcdDlg(GtkWidget *widget) { + int i; + + for (i = 0; i < MAX_MEMCARD_BLOCKS; i++) { + GetMcdBlockInfo(1, i + 1, &Blocks[0][i]); + GetMcdBlockInfo(2, i + 1, &Blocks[1][i]); + } + + UpdateListItems(1, widget); + UpdateListItems(2, widget); +} + +static void OnMcd_Clicked(GtkDialog *dialog, gint arg1, gpointer user_data) { + GladeXML *xml = user_data; + + if (arg1 == GTK_RESPONSE_OK) { + gchar *tmp; + GtkWidget *widget; + + widget = glade_xml_get_widget(xml, "GtkMcd1FSButton"); + if ((tmp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget))) != NULL) { + strcpy(Config.Mcd1, tmp); + g_free(tmp); + } + + widget = glade_xml_get_widget(xml, "GtkMcd2FSButton"); + if ((tmp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (widget))) != NULL) { + strcpy(Config.Mcd2, tmp); + g_free(tmp); + } + + SaveConfig(); + LoadMcds(Config.Mcd1, Config.Mcd2); + } + + gtk_widget_destroy(GTK_WIDGET(dialog)); +} + +static void OnMemcardFileChanged(GtkWidget *widget, gpointer user_data) { + gint memcard = (int) user_data; + gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget)); + + if (filename != NULL) { + LoadMcd(memcard, filename); + UpdateMcdDlg(widget); + gtk_widget_set_sensitive(widget, TRUE); + } + + g_free(filename); +} + +// create a new, formatted memory card +static void OnMcd_Format(GtkWidget *widget, gpointer user_data) { + GladeXML *xml; + GtkWidget *memcard_fs; + GtkWidget *message_dialog; + gint result; + gchar *str; + + gint memcard = (int)user_data; + + message_dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, + GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, + _("Format this Memory Card?")); + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(message_dialog), + _("If you format the memory card, the card will be empty, and any existing data overwritten.")); + gtk_dialog_add_buttons(GTK_DIALOG (message_dialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + _("Format card"), GTK_RESPONSE_YES, NULL); + + result = gtk_dialog_run(GTK_DIALOG(message_dialog)); + gtk_widget_destroy(message_dialog); + + if (result == GTK_RESPONSE_YES) { + xml = glade_get_widget_tree(widget); + if (memcard == 1) + memcard_fs = glade_xml_get_widget(xml, "GtkMcd1FSButton"); + else + memcard_fs = glade_xml_get_widget(xml, "GtkMcd2FSButton"); + + str = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(memcard_fs)); + + CreateMcd(str); + LoadMcd(memcard, str); + UpdateMcdDlg(widget); + g_free(str); + } +} + +static void OnMcd_New(GtkWidget *widget, gpointer user_data) { + GtkWidget *chooser; + gchar *path; + + // Ask for name of new memory card + chooser = gtk_file_chooser_dialog_new(_("Create a new Memory Card"), + NULL, GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_OK, + NULL); + + // Card should be put into $HOME/.pcsx/memcards + path = g_build_filename(g_get_home_dir(), ".pcsx", "memcards", NULL); + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), path); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(chooser), "new.mcd"); + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(chooser), TRUE); + + if (gtk_dialog_run(GTK_DIALOG(chooser)) == GTK_RESPONSE_OK) { + gchar *name; + gchar *widget_name; + GladeXML *xml; + + gtk_widget_hide(chooser); + + name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)); + + CreateMcd(name); + + // Set the name on the FileChooserButton - this will trigger the + // callback to load the card and update the dialog + widget_name = g_strdup_printf("GtkMcd%dFSButton", (int)user_data); + + xml = glade_get_widget_tree(widget); + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(glade_xml_get_widget(xml, widget_name)), name); + + g_free(widget_name); + g_free(name); + + UpdateMcdDlg(widget); + } + + gtk_widget_destroy(chooser); + g_free(path); +} + +static int copy = 0, copymcd = 0; + +static int GetFreeMemcardSlot(int target_card) { + McdBlock *Info; + gboolean found = FALSE; + + int i = 0; + while (i < 15 && found == FALSE) { + Info = &Blocks[target_card][i]; + if (g_ascii_strcasecmp(Info->Title, "") == 0) { + found = TRUE; + } else { + i++; + } + } + + if (found == TRUE) + return i; + + // no free slots, try to find a deleted one + i = 0; + while (i < 15 && found == FALSE) { + Info = &Blocks[target_card][i]; + if ((Info->Flags & 0xF0) != 0x50) { + found = TRUE; + } else { + i++; + } + } + + if (found == TRUE) + return i; + + return -1; +} + +static void CopyMemcardData(char *from, char *to, gint *i, gchar *str) { + memcpy(to + (*i + 1) * 128, from + (copy + 1) * 128, 128); + SaveMcd((char *)str, to, (*i + 1) * 128, 128); + memcpy(to + (*i + 1) * 1024 * 8, from + (copy+1) * 1024 * 8, 1024 * 8); + SaveMcd((char *)str, to, (*i + 1) * 1024 * 8, 1024 * 8); +} + +static void OnMcd_CopyTo(GtkWidget *widget, gpointer user_data) { + gint mcd = (gint)user_data; + + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreePath *path; + gint *i; + GladeXML *xml; + GtkTreeSelection *treesel; + gchar *str; + char *source, *destination; + + int first_free_slot; + + xml = glade_get_widget_tree(widget); + + if (mcd == 1) + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(GtkCList_McdList2)); + else + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(GtkCList_McdList1)); + + // If the item selected is not reported as a 'Free' slot + if (gtk_tree_selection_get_selected(treesel, &model, &iter)) { + path = gtk_tree_model_get_path(model, &iter); + i = gtk_tree_path_get_indices(path); + copy = *i; + copymcd = mcd; + gtk_tree_path_free(path); + } + + // Determine the first free slot in the target memory card + first_free_slot = GetFreeMemcardSlot(mcd - 1); + if (first_free_slot == -1) { + // No free slots available on the destination card + SysErrorMessage(_("No free space on memory card"), + _("There are no free slots available on the target memory card. Please delete a slot first.")); + return; + } + + xml = glade_get_widget_tree(GtkCList_McdList1); + + if (mcd == 1) { + str = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "GtkMcd1FSButton"))); + source = Mcd2Data; + destination = Mcd1Data; + } else { + str = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "GtkMcd2FSButton"))); + source = Mcd1Data; + destination = Mcd2Data; + } + + CopyMemcardData(source, destination, &first_free_slot, str); + UpdateMcdDlg(widget); +} + +static void OnMemcardDelete(GtkWidget *widget, gpointer user_data) { + McdBlock *Info; + int i, xor = 0, j; + char *data, *ptr; + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreePath *path; + gchar *filename; + GladeXML *xml; + gboolean selected; + GtkWidget *tree; + GtkTreeSelection *sel; + + gint memcard = (int)user_data; + + xml = glade_get_widget_tree(widget); + + if (memcard == 1) { + tree = glade_xml_get_widget(xml, "GtkCList_McdList1"); + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW (tree)); + selected = gtk_tree_selection_get_selected (sel, &model, &iter); + data = Mcd1Data; + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "GtkMcd1FSButton"))); + } else { + tree = glade_xml_get_widget(xml, "GtkCList_McdList2"); + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW (tree)); + selected = gtk_tree_selection_get_selected(sel, &model, &iter); + data = Mcd2Data; + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(glade_xml_get_widget(xml, "GtkMcd2FSButton"))); + } + + if (selected) { + path = gtk_tree_model_get_path(model, &iter); + i = *gtk_tree_path_get_indices(path); + + i++; + ptr = data + i * 128; + Info = &Blocks[memcard - 1][i - 1]; + + if ((Info->Flags & 0xF0) == 0xA0) { + if ((Info->Flags & 0xF) >= 1 && + (Info->Flags & 0xF) <= 3) { // deleted + *ptr = 0x50 | (Info->Flags & 0xF); + } else return; + } else if ((Info->Flags & 0xF0) == 0x50) { // used + *ptr = 0xA0 | (Info->Flags & 0xF); + } else { return; } + + for (j = 0; j < 127; j++) xor ^= *ptr++; + *ptr = xor; + + SaveMcd((char *)filename, data, i * 128, 128); + UpdateMcdDlg(widget); + } +} + +static void OnTreeSelectionChanged(GtkTreeSelection *selection, gpointer user_data) { + GladeXML *xml; + GtkTreeIter iter; + GtkTreeModel *model; + GtkTreePath *path; + + gboolean selected; + int i; + McdBlock b; + + gint memcard = (int)user_data; + + xml = glade_get_widget_tree(GtkCList_McdList1); + selected = gtk_tree_selection_get_selected(selection, &model, &iter); + + if (selected) { + path = gtk_tree_model_get_path(model, &iter); + i = *gtk_tree_path_get_indices(path); + gtk_tree_path_free(path); + + // If a row was selected, and the row is not blank, we can now enable + // some of the disabled widgets + if (memcard == 1) { + GetMcdBlockInfo(1, i + 1, &b); + + if ((b.Flags >= 0xA1 && b.Flags <= 0xA3) || ((b.Flags & 0xF0) == 0x50)) { + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_Delete1"), TRUE); + } else { + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_Delete1"), FALSE); + } + + if ((b.Flags & 0xF0) == 0x50) { + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_CopyTo2"), TRUE); + } else { + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_CopyTo2"), FALSE); + } + } else { + GetMcdBlockInfo(2, i + 1, &b); + + if ((b.Flags >= 0xA0 && b.Flags <= 0xA3) || ((b.Flags & 0xF0) == 0x50)) { + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_Delete2"), TRUE); + } else { + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_Delete2"), FALSE); + } + + if ((b.Flags & 0xF0) == 0x50) { + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_CopyTo1"), TRUE); + } else { + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_CopyTo1"), FALSE); + } + } + } else { + if (memcard == 1) { + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_CopyTo2"), FALSE); + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_Delete1"), FALSE); + } else { + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_CopyTo1"), FALSE); + gtk_widget_set_sensitive(glade_xml_get_widget(xml, "GtkButton_Delete2"), FALSE); + } + } +} + +void OnConf_Mcds() { + GladeXML *xml; + GtkWidget *dialog; + GtkWidget *widget; + GtkTreeSelection *treesel1, *treesel2; + gchar *str; + int i; + + xml = glade_xml_new(PACKAGE_DATA_DIR "pcsx.glade2", "McdsDlg", NULL); + + if (!xml) { + g_warning("We could not load the interface!"); + return; + } + + dialog = glade_xml_get_widget(xml, "McdsDlg"); + + gtk_window_set_title(GTK_WINDOW(dialog), _("Memory Card Manager")); + + // Assign default memory cards + if (!strlen(Config.Mcd1)) { + str = g_strconcat(getenv("HOME"), DEFAULT_MEM_CARD_1, NULL); + strcpy(Config.Mcd1, str); + g_free(str); + } + + if (!strlen(Config.Mcd2)) { + str = g_strconcat(getenv("HOME"), DEFAULT_MEM_CARD_2, NULL); + strcpy(Config.Mcd2, str); + g_free(str); + } + + GtkCList_McdList1 = glade_xml_get_widget(xml, "GtkCList_McdList1"); + AddColumns(GTK_TREE_VIEW(GtkCList_McdList1)); + GtkCList_McdList2 = glade_xml_get_widget(xml, "GtkCList_McdList2"); + AddColumns(GTK_TREE_VIEW(GtkCList_McdList2)); + + treesel1 = gtk_tree_view_get_selection(GTK_TREE_VIEW (GtkCList_McdList1)); + gtk_tree_selection_set_mode(treesel1, GTK_SELECTION_SINGLE); + g_signal_connect_data(G_OBJECT(treesel1), "changed", + G_CALLBACK(OnTreeSelectionChanged), + (gpointer)1, NULL, G_CONNECT_AFTER); + + treesel2 = gtk_tree_view_get_selection(GTK_TREE_VIEW (GtkCList_McdList2)); + gtk_tree_selection_set_mode(treesel2, GTK_SELECTION_SINGLE); + g_signal_connect_data(G_OBJECT(treesel2), "changed", + G_CALLBACK(OnTreeSelectionChanged), + (gpointer)2, NULL, G_CONNECT_AFTER); + + LoadMcdDlg(dialog); + + // Setup a handler for when Close or Cancel is clicked + g_signal_connect_data(GTK_OBJECT(dialog), "response", + GTK_SIGNAL_FUNC(OnMcd_Clicked), xml, (GClosureNotify)g_object_unref, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "GtkButton_Format1"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnMcd_Format), (gpointer)1, NULL, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "GtkButton_Format2"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnMcd_Format), (gpointer)2, NULL, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "GtkMcd1FSButton"); + g_signal_connect_data(GTK_OBJECT(widget), "selection-changed", + GTK_SIGNAL_FUNC(OnMemcardFileChanged), (gpointer)1, NULL, G_CONNECT_AFTER); + gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(widget), Config.Mcd1); + + widget = glade_xml_get_widget(xml, "GtkMcd2FSButton"); + g_signal_connect_data(GTK_OBJECT(widget), "selection-changed", + GTK_SIGNAL_FUNC(OnMemcardFileChanged), (gpointer) 2, NULL, G_CONNECT_AFTER); + gtk_file_chooser_select_filename(GTK_FILE_CHOOSER(widget), Config.Mcd2); + + widget = glade_xml_get_widget(xml, "GtkButton_New1"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnMcd_New), (gpointer)1, NULL, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "GtkButton_New2"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnMcd_New), (gpointer)2, NULL, G_CONNECT_AFTER); + + widget = glade_xml_get_widget(xml, "GtkButton_CopyTo1"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnMcd_CopyTo), (gpointer)1, NULL, G_CONNECT_AFTER); + gtk_widget_set_sensitive(GTK_WIDGET(widget), FALSE); + + widget = glade_xml_get_widget(xml, "GtkButton_CopyTo2"); + g_signal_connect_data(GTK_OBJECT(widget), "clicked", + GTK_SIGNAL_FUNC(OnMcd_CopyTo), (gpointer)2, NULL, G_CONNECT_AFTER); + gtk_widget_set_sensitive(GTK_WIDGET(widget), FALSE); + + widget = glade_xml_get_widget(xml, "GtkButton_Delete1"); + g_signal_connect_data (GTK_OBJECT (widget), "clicked", + GTK_SIGNAL_FUNC(OnMemcardDelete), (gpointer)1, NULL, G_CONNECT_AFTER); + gtk_widget_set_sensitive(GTK_WIDGET(widget), FALSE); + + widget = glade_xml_get_widget(xml, "GtkButton_Delete2"); + g_signal_connect_data (GTK_OBJECT (widget), "clicked", + GTK_SIGNAL_FUNC(OnMemcardDelete), (gpointer)2, NULL, G_CONNECT_AFTER); + gtk_widget_set_sensitive(GTK_WIDGET(widget), FALSE); + + while (gtk_events_pending()) gtk_main_iteration(); +} diff --git a/gui/MemcardDlg.h b/gui/MemcardDlg.h new file mode 100644 index 00000000..ae583d6d --- /dev/null +++ b/gui/MemcardDlg.h @@ -0,0 +1,24 @@ +/* Pcsx - Pc Psx Emulator + * Copyright (C) 1999-2002 Pcsx Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307 USA + */ + +#ifndef MEMCARDDLG_H +#define MEMCARDDLG_H + +void OnConf_Mcds(); + +#endif |
