From 16b6cc41a49044c9e436669c952bee252b935f8a Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 26 Oct 2016 17:36:03 +0100 Subject: [PATCH] cdvdgigaherz:linux: Add config and GUI code --- plugins/cdvdGigaherz/src/CDVD.h | 2 + plugins/cdvdGigaherz/src/Unix/GtkGui.cpp | 71 +++++++++++++++++ plugins/cdvdGigaherz/src/Unix/LinuxConfig.cpp | 77 +++++++++++++++++++ .../src/Windows/cdvdGigaherz.vcxproj | 6 ++ .../src/Windows/cdvdGigaherz.vcxproj.filters | 9 +++ 5 files changed, 165 insertions(+) create mode 100644 plugins/cdvdGigaherz/src/Unix/GtkGui.cpp create mode 100644 plugins/cdvdGigaherz/src/Unix/LinuxConfig.cpp diff --git a/plugins/cdvdGigaherz/src/CDVD.h b/plugins/cdvdGigaherz/src/CDVD.h index 9a36e5e4e2..e035631a37 100644 --- a/plugins/cdvdGigaherz/src/CDVD.h +++ b/plugins/cdvdGigaherz/src/CDVD.h @@ -99,6 +99,8 @@ void ReadSettings(); void WriteSettings(); #if defined(_WIN32) std::wstring GetValidDrive(); +#else +std::string GetValidDrive(); #endif extern Settings g_settings; diff --git a/plugins/cdvdGigaherz/src/Unix/GtkGui.cpp b/plugins/cdvdGigaherz/src/Unix/GtkGui.cpp new file mode 100644 index 0000000000..792f76d1b1 --- /dev/null +++ b/plugins/cdvdGigaherz/src/Unix/GtkGui.cpp @@ -0,0 +1,71 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2016 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 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 PCSX2. + * If not, see . + */ + +#include "CDVD.h" +#include + +std::vector GetOpticalDriveList(); + +static void ComboboxCallback(GtkComboBoxText *combobox, gpointer data) +{ + Settings *settings = reinterpret_cast(data); + settings->Set("drive", gtk_combo_box_text_get_active_text(combobox)); +} + +void configure() +{ + ReadSettings(); + + GtkDialogFlags flags = static_cast(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT); + GtkWidget *dialog = gtk_dialog_new_with_buttons("Config", nullptr, + flags, + "Ok", GTK_RESPONSE_ACCEPT, + "Cancel", GTK_RESPONSE_REJECT, + nullptr); + + GtkWidget *label = gtk_label_new("Device:"); + GtkWidget *combobox = gtk_combo_box_text_new(); + + auto drives = GetOpticalDriveList(); + std::string drive; + g_settings.Get("drive", drive); + for (size_t n = 0; n < drives.size(); ++n) { + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), drives[n].c_str()); + if (drive == drives[n]) + gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), n); + } + +#if GTK_MAJOR_VERSION >= 3 + GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); +#else + GtkWidget *box = gtk_vbox_new(0, 10); +#endif + gtk_box_pack_start(GTK_BOX(box), label, 0, 0, 0); + gtk_box_pack_start(GTK_BOX(box), combobox, 0, 0, 10); + + GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + gtk_container_add(GTK_CONTAINER(content_area), box); + + Settings settings_copy = g_settings; + g_signal_connect(combobox, "changed", G_CALLBACK(ComboboxCallback), &settings_copy); + + gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ALWAYS); + gtk_widget_show_all(dialog); + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + g_settings = settings_copy; + WriteSettings(); + } + gtk_widget_destroy(dialog); +} diff --git a/plugins/cdvdGigaherz/src/Unix/LinuxConfig.cpp b/plugins/cdvdGigaherz/src/Unix/LinuxConfig.cpp new file mode 100644 index 0000000000..3fe321876d --- /dev/null +++ b/plugins/cdvdGigaherz/src/Unix/LinuxConfig.cpp @@ -0,0 +1,77 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2016 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 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 PCSX2. + * If not, see . + */ + +#include "CDVD.h" +#include +#include +#include +#include +#include + +std::vector GetOpticalDriveList() +{ + udev *udev_context = udev_new(); + if (!udev_context) + return {}; + + std::vector drives; + udev_enumerate *enumerate = udev_enumerate_new(udev_context); + if (enumerate) { + udev_enumerate_add_match_subsystem(enumerate, "block"); + udev_enumerate_add_match_property(enumerate, "ID_CDROM_DVD", "1"); + udev_enumerate_scan_devices(enumerate); + udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate); + + udev_list_entry *dev_list_entry; + udev_list_entry_foreach(dev_list_entry, devices) + { + const char *path = udev_list_entry_get_name(dev_list_entry); + udev_device *device = udev_device_new_from_syspath(udev_context, path); + const char *devnode = udev_device_get_devnode(device); + if (devnode) + drives.push_back(devnode); + udev_device_unref(device); + } + udev_enumerate_unref(enumerate); + } + udev_unref(udev_context); + + return drives; +} + +std::string GetValidDrive() +{ + std::string drive; + g_settings.Get("drive", drive); + if (!drive.empty()) { + int fd = open(drive.c_str(), O_RDONLY | O_NONBLOCK); + if (fd != -1) { + if (ioctl(fd, CDROM_GET_CAPABILITY, 0) == -1) + drive.clear(); + close(fd); + } else { + drive.clear(); + } + } + if (drive.empty()) { + auto drives = GetOpticalDriveList(); + if (!drives.empty()) + drive = drives.front(); + } + if (!drive.empty()) + printf(" * CDVD: Opening drive '%s'...\n", drive.c_str()); + + return drive; +} diff --git a/plugins/cdvdGigaherz/src/Windows/cdvdGigaherz.vcxproj b/plugins/cdvdGigaherz/src/Windows/cdvdGigaherz.vcxproj index 81741d1893..d4a42bf148 100644 --- a/plugins/cdvdGigaherz/src/Windows/cdvdGigaherz.vcxproj +++ b/plugins/cdvdGigaherz/src/Windows/cdvdGigaherz.vcxproj @@ -54,6 +54,12 @@ + + true + + + true + true diff --git a/plugins/cdvdGigaherz/src/Windows/cdvdGigaherz.vcxproj.filters b/plugins/cdvdGigaherz/src/Windows/cdvdGigaherz.vcxproj.filters index 7da2253510..78ef4c372a 100644 --- a/plugins/cdvdGigaherz/src/Windows/cdvdGigaherz.vcxproj.filters +++ b/plugins/cdvdGigaherz/src/Windows/cdvdGigaherz.vcxproj.filters @@ -19,6 +19,9 @@ {102507ff-fef0-4989-9bcb-4fa14a0b7595} + + {2054202d-299a-4cbf-8f4f-282bfe79a98e} + @@ -42,6 +45,12 @@ Source Files\Windows + + Source Files\Linux + + + Source Files\GTK +