mirror of https://github.com/PCSX2/pcsx2.git
cdvdgigaherz:linux: Add config and GUI code
This commit is contained in:
parent
747f4dc3fe
commit
16b6cc41a4
|
@ -99,6 +99,8 @@ void ReadSettings();
|
|||
void WriteSettings();
|
||||
#if defined(_WIN32)
|
||||
std::wstring GetValidDrive();
|
||||
#else
|
||||
std::string GetValidDrive();
|
||||
#endif
|
||||
|
||||
extern Settings g_settings;
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "CDVD.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
std::vector<std::string> GetOpticalDriveList();
|
||||
|
||||
static void ComboboxCallback(GtkComboBoxText *combobox, gpointer data)
|
||||
{
|
||||
Settings *settings = reinterpret_cast<Settings *>(data);
|
||||
settings->Set("drive", gtk_combo_box_text_get_active_text(combobox));
|
||||
}
|
||||
|
||||
void configure()
|
||||
{
|
||||
ReadSettings();
|
||||
|
||||
GtkDialogFlags flags = static_cast<GtkDialogFlags>(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);
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "CDVD.h"
|
||||
#include <libudev.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/cdrom.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
std::vector<std::string> GetOpticalDriveList()
|
||||
{
|
||||
udev *udev_context = udev_new();
|
||||
if (!udev_context)
|
||||
return {};
|
||||
|
||||
std::vector<std::string> 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;
|
||||
}
|
|
@ -54,6 +54,12 @@
|
|||
<ItemGroup>
|
||||
<ClCompile Include="..\CDVD.cpp" />
|
||||
<ClCompile Include="..\Settings.cpp" />
|
||||
<ClCompile Include="..\Unix\GtkGui.cpp">
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Unix\LinuxConfig.cpp">
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Unix\LinuxIOCtlSrc.cpp">
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
<Filter Include="Source Files\Linux">
|
||||
<UniqueIdentifier>{102507ff-fef0-4989-9bcb-4fa14a0b7595}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\GTK">
|
||||
<UniqueIdentifier>{2054202d-299a-4cbf-8f4f-282bfe79a98e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\CDVD.cpp">
|
||||
|
@ -42,6 +45,12 @@
|
|||
<ClCompile Include="config.cpp">
|
||||
<Filter>Source Files\Windows</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Unix\LinuxConfig.cpp">
|
||||
<Filter>Source Files\Linux</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Unix\GtkGui.cpp">
|
||||
<Filter>Source Files\GTK</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\CDVD.h">
|
||||
|
|
Loading…
Reference in New Issue