spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit 0c08e68c5fe503590b624eccb5d9d3cc93fb3290
parent 92dd6a8bbfa73b914e6dabd8033afd836394c7e0
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Mon,  6 Aug 2012 22:55:30 -0700

spek_platform_config_dir()

Diffstat:
Msrc/spek-platform.c | 76----------------------------------------------------------------------------
Msrc/spek-platform.cc | 14++++++++++++++
Msrc/spek-platform.h | 6+++++-
3 files changed, 19 insertions(+), 77 deletions(-)

diff --git a/src/spek-platform.c b/src/spek-platform.c @@ -32,82 +32,6 @@ #include "spek-platform.h" -void spek_platform_init () { -#ifdef G_OS_DARWIN - g_object_new (GTK_TYPE_OSX_APPLICATION, NULL); -#endif -} - -void spek_platform_fix_args (gchar **argv, gint argc) { -#ifdef G_OS_WIN32 - /* Because MinGW does not support Unicode arguments we are going to - * get them using Windows API. In addition, GLib's option parser - * doesn't work well with utf-8 strings on Windows, converting - * them to URIs works around this problem. - */ - int i; - gchar *s, *t; - wchar_t **wargv; - int wargc; - wargv = CommandLineToArgvW (GetCommandLineW (), &wargc); - for (i = 0; i < argc; i++) { - s = g_utf16_to_utf8 (wargv[i], -1, NULL, NULL, NULL); - if (s) { - t = g_filename_to_uri (s, NULL, NULL); - g_free (s); - if (t) { - g_free (argv[i]); - argv[i] = t; - } - } - } - LocalFree (wargv); -#endif -} - -#ifdef G_OS_DARWIN -static void accel_map_foreach (gpointer data, const gchar *accel_path, guint accel_key, GdkModifierType -accel_mods, gboolean changed) -{ - if (accel_mods & GDK_CONTROL_MASK) { - accel_mods &= ~GDK_CONTROL_MASK; - accel_mods |= GDK_META_MASK; - gtk_accel_map_change_entry (accel_path, accel_key, accel_mods, FALSE); - } -} -#endif - -void spek_platform_fix_ui (GtkUIManager *ui) -{ -#ifdef G_OS_DARWIN - GtkOSXApplication *app = NULL; - GtkOSXApplicationMenuGroup *group = NULL; - GtkWidget *menubar = NULL; - GtkWidget *file_quit = NULL; - GtkWidget *edit_preferences = NULL; - GtkWidget *help_about = NULL; - - app = g_object_new (GTK_TYPE_OSX_APPLICATION, NULL); - menubar = gtk_ui_manager_get_widget (ui, "/MenuBar"); - file_quit = gtk_ui_manager_get_widget (ui, "/MenuBar/File/FileQuit"); - edit_preferences = gtk_ui_manager_get_widget (ui, "/MenuBar/Edit/EditPreferences"); - help_about = gtk_ui_manager_get_widget (ui, "/MenuBar/Help/HelpAbout"); - - gtk_widget_hide (menubar); - gtk_widget_hide (file_quit); - gtk_osxapplication_set_menu_bar (app, GTK_MENU_SHELL (menubar)); - - group = gtk_osxapplication_add_app_menu_group (app); - gtk_osxapplication_add_app_menu_item (app, group, GTK_MENU_ITEM (help_about)); - group = gtk_osxapplication_add_app_menu_group (app); - gtk_osxapplication_add_app_menu_item (app, group, GTK_MENU_ITEM (edit_preferences)); - - gtk_accel_map_foreach (NULL, accel_map_foreach); - - gtk_osxapplication_ready (app); -#endif -} - gchar *spek_platform_locale_dir () { static gchar *locale_dir = NULL; diff --git a/src/spek-platform.cc b/src/spek-platform.cc @@ -19,6 +19,8 @@ #include <cstring> #include <wx/filename.h> +#include <wx/stdpaths.h> +#include <wx/utils.h> #include "spek-platform.h" @@ -31,3 +33,15 @@ char * spek_platform_short_path(const char *path) return NULL; } +char * spek_platform_config_dir(const char *app_name) +{ +#ifdef OS_WIN + wxFileName file_name(wxStandardPaths::Get().GetUserConfigDir()); +#else + wxFileName file_name(wxGetHomeDir()); + file_name.AppendDir(wxT(".config")); +#endif + file_name.AppendDir(wxString(app_name, wxConvUTF8)); + file_name.SetFullName(wxT("preferences")); + return strdup(file_name.GetFullPath().char_str(wxConvUTF8)); +} diff --git a/src/spek-platform.h b/src/spek-platform.h @@ -24,7 +24,11 @@ extern "C" { #endif // Returns a 8.3 version of the UTF8-encoded path on Windows and NULL on other platforms. -char * spek_platform_short_path (const char *path); +char * spek_platform_short_path(const char *path); + +// Not quite XDG-compatible, but close enough. +// TODO: implement XDG spec in wxWidgets. +char * spek_platform_config_dir(const char *app_name); #ifdef __cplusplus }