aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadia Holmquist Pedersen <nadia@nhp.sh>2020-04-30 03:20:18 +0200
committerNadia Holmquist Pedersen <nadia@nhp.sh>2020-05-06 02:39:50 +0200
commitffe20c1236d4f8140d25c7548ab452e7b35064bd (patch)
tree52d82e0747cd39a6b6842827126daef478a78468
parent9432a9f3822f024e97185ac4b0a9df5c07987dd1 (diff)
Use Qt abstractions instead of glib's for paths on Linux
-rw-r--r--src/frontend/qt_sdl/CMakeLists.txt18
-rw-r--r--src/frontend/qt_sdl/Platform.cpp53
-rw-r--r--src/frontend/qt_sdl/main.cpp9
3 files changed, 27 insertions, 53 deletions
diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt
index 05a4029..f03cad2 100644
--- a/src/frontend/qt_sdl/CMakeLists.txt
+++ b/src/frontend/qt_sdl/CMakeLists.txt
@@ -35,27 +35,9 @@ if (UNIX)
add_definitions(-DUNIX_PORTABLE)
endif()
- find_package(PkgConfig REQUIRED)
- pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
-
- target_include_directories(melonDS PRIVATE ${GTK3_INCLUDE_DIRS})
- target_link_libraries(melonDS ${GTK3_LIBRARIES})
-
- ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER})
-
- add_custom_command(OUTPUT melon_grc.c
- COMMAND glib-compile-resources --sourcedir=${CMAKE_SOURCE_DIR}
- --target=${CMAKE_CURRENT_BINARY_DIR}/melon_grc.c
- --generate-source "${CMAKE_SOURCE_DIR}/melon_grc.xml"
- COMMAND glib-compile-resources --sourcedir=${CMAKE_SOURCE_DIR}
- --target=${CMAKE_CURRENT_BINARY_DIR}/melon_grc.h
- --generate-header "${CMAKE_SOURCE_DIR}/melon_grc.xml")
-
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
target_link_libraries(melonDS dl Qt5::Core Qt5::Gui Qt5::Widgets)
endif ()
-
- target_sources(melonDS PUBLIC melon_grc.c)
elseif (WIN32)
target_sources(melonDS PUBLIC "${CMAKE_SOURCE_DIR}/melon.rc")
target_link_libraries(melonDS comctl32 d2d1 dwrite uxtheme ws2_32 iphlpapi gdi32 Qt5::Core Qt5::Gui Qt5::Widgets)
diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp
index 31b5277..de8db93 100644
--- a/src/frontend/qt_sdl/Platform.cpp
+++ b/src/frontend/qt_sdl/Platform.cpp
@@ -37,7 +37,8 @@
#define socket_t SOCKET
#define sockaddr_t SOCKADDR
#else
- #include <glib.h>
+ #include <QStandardPaths>
+ #include <QDir>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
@@ -139,6 +140,7 @@ FILE* OpenFile(const char* path, const char* mode, bool mustexist)
FILE* OpenLocalFile(const char* path, const char* mode)
{
std::string fullpath;
+
if (path[0] == '/')
{
// If it's an absolute path, just open that.
@@ -147,9 +149,10 @@ FILE* OpenLocalFile(const char* path, const char* mode)
else
{
// Check user configuration directory
- std::string confpath = std::string(g_get_user_config_dir()) + "/melonDS/";
- g_mkdir_with_parents(confpath.c_str(), 0755);
- fullpath = confpath + path;
+ QString confpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/melonDS/";
+ confpath.append(path);
+
+ fullpath = confpath.toStdString();
}
return OpenFile(fullpath.c_str(), mode, mode[0] != 'w');
@@ -157,37 +160,27 @@ FILE* OpenLocalFile(const char* path, const char* mode)
FILE* OpenDataFile(const char* path)
{
- const char* melondir = "melonDS";
- const char* const* sys_dirs = g_get_system_data_dirs();
- const char* user_dir = g_get_user_data_dir();
+ QString melondir = "melonDS";
+ QStringList sys_dirs = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
+ QString sep = QDir::separator();
- // First check the user's data directory
- char* fullpath = g_build_path("/", user_dir, melondir, path, NULL);
- if (access(fullpath, R_OK) == 0)
- {
- FILE* f = fopen(fullpath, "r");
- g_free(fullpath);
- return f;
- }
- free(fullpath);
+ const char* found = NULL;
- // Then check the system data directories
- for (size_t i = 0; sys_dirs[i] != NULL; i++)
- {
- const char* dir = sys_dirs[i];
- char* fullpath = g_build_path("/", dir, melondir, path, NULL);
+ for (int i = 0; i < sys_dirs.size(); i++) {
+ QString f = sys_dirs.at(i) + sep + melondir + sep + QString(path);
- if (access(fullpath, R_OK) == 0)
- {
- FILE* f = fopen(fullpath, "r");
- g_free(fullpath);
- return f;
+ if (QFile::exists(f)) {
+ found = f.toStdString().c_str();
+ break;
}
- free(fullpath);
}
- FILE* f = fopen(path, "rb");
- if (f) return f;
+ if (found == NULL)
+ return NULL;
+
+ FILE* f = fopen(found, "rb");
+ if (f)
+ return f;
return NULL;
}
@@ -299,7 +292,7 @@ FILE* OpenLocalFile(const char* path, const char* mode)
{
// Now check XDG_CONFIG_HOME
// TODO: check for memory leak there
- std::string fullpath = std::string(g_get_user_config_dir()) + "/melonDS/" + path;
+ std::string fullpath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).toStdString() + "/melonDS/" + path;
f = OpenFile(fullpath.c_str(), mode, true);
if (f) { delete[] emudirpath; return f; }
}
diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp
index 643cf90..81fa16f 100644
--- a/src/frontend/qt_sdl/main.cpp
+++ b/src/frontend/qt_sdl/main.cpp
@@ -27,6 +27,7 @@
#include <QFileDialog>
#include <QPaintEvent>
#include <QPainter>
+#include <QStandardPaths>
#include <SDL2/SDL.h>
@@ -824,11 +825,9 @@ int main(int argc, char** argv)
strcpy(EmuDirectory, ".");
}
#else
- const char* confdir = g_get_user_config_dir();
- const char* confname = "/melonDS";
- EmuDirectory = new char[strlen(confdir) + strlen(confname) + 1];
- strcat(EmuDirectory, confdir);
- strcat(EmuDirectory, confname);
+ QString confdir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/melonDS";
+ EmuDirectory = new char[confdir.length() + 1];
+ strcat(EmuDirectory, confdir.toStdString().c_str());
#endif
QApplication melon(argc, argv);