/*************************************************************************** main.cpp - description ------------------- begin : Wed Jan 1 19:06:46 GMT+4 2003 copyright : (C) 2003 - 2005 by Alex Shaduri email : ashaduri '@' gmail.com ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #ifdef _WIN32 #include "win32util.h" #include #else #include #endif #ifdef HAVE_UNISTD_H #include #endif #include "interface.h" #include "callbacks.h" #include "support.h" #include "main.h" // ------------------------------------------------------ GtkWidget* g_main_window = 0; // GtkWidget* g_fontsel_dialog = 0; static std::string s_tmp_file; // ------------------------------------------------------ static std::string gchar_to_string(gchar* gstr) { std::string str = (gstr ? gstr : ""); g_free(gstr); return str; } std::string get_home_dir() { std::string dir; if (g_get_home_dir()) dir = g_get_home_dir(); #ifdef _WIN32 if (dir == "") { dir = win32_get_registry_value_string(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Personal"); } if (dir == "") { dir = win32_get_registry_value_string(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "User"); } #endif return dir; } // ------------------------------------------------------ static std::string s_orig_theme; static std::string s_orig_font; std::string& get_orig_theme() { return s_orig_theme; } std::string& get_orig_font() { return s_orig_font; } // ------------------------------------------------------ std::string get_current_theme() { GtkSettings* settings = gtk_settings_get_default(); gchar* theme; g_object_get(settings, "gtk-theme-name", &theme, NULL); return gchar_to_string(theme); } std::string get_current_font() { return gchar_to_string(pango_font_description_to_string(gtk_rc_get_style(g_main_window)->font_desc)); } // ------------------------------------------------------ std::string get_selected_theme() { GtkTreeView* treeview = GTK_TREE_VIEW(lookup_widget(g_main_window, "main_themelist")); GtkTreeModel* model = gtk_tree_view_get_model(treeview); GtkTreeSelection* selection = gtk_tree_view_get_selection(treeview); GtkTreeIter iter; gtk_tree_selection_get_selected(selection, 0, &iter); gchar* theme_name; gtk_tree_model_get(model, &iter, 0, &theme_name, -1); // std::cout << theme_name << "\n"; return gchar_to_string(theme_name); } std::string get_selected_font() { // GtkWidget* fontentry = lookup_widget(g_main_window, "main_fontentry"); // return gtk_entry_get_text(GTK_ENTRY(fontentry)); bool default_font = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(g_main_window, "main_use_default_font_radio"))); if (default_font) return ""; GtkWidget* fontbutton = lookup_widget(g_main_window, "main_font_selector_button"); return gtk_font_button_get_font_name(GTK_FONT_BUTTON(fontbutton)); } // ------------------------------------------------------ static void themelist_selection_changed_cb(GtkTreeSelection* selection, gpointer data) { if (gtk_tree_selection_get_selected (selection, 0, 0)) apply_theme(get_selected_theme(), get_current_font()); } // ------------------------------------------------------ static void populate_with_themes(GtkWidget* w) { std::string search_path = gchar_to_string(gtk_rc_get_theme_dir()); //std::string search_path = gchar_to_string(g_build_filename("lib", "gtk-2.0", "2.10.0", "engines", NULL)); if (search_path.size() && search_path[search_path.size() -1] != G_DIR_SEPARATOR) search_path += G_DIR_SEPARATOR_S; GDir* gdir = g_dir_open(search_path.c_str(), 0, NULL); if (gdir == NULL) return; char* name; GList* glist = 0; while ( (name = const_cast(g_dir_read_name(gdir))) != NULL ) { std::string filename = name; // if (g_ascii_strup(fname.c_str(), -1) == "Default") // continue; std::string fullname = search_path + filename; std::string rc = fullname; rc += G_DIR_SEPARATOR_S; rc += "gtk-2.0"; rc += G_DIR_SEPARATOR_S; rc += "gtkrc"; bool is_dir = 0; if (g_file_test(fullname.c_str(), G_FILE_TEST_IS_DIR)) is_dir = 1; if (is_dir && g_file_test(rc.c_str(), G_FILE_TEST_IS_REGULAR)) { glist = g_list_insert_sorted(glist, g_strdup(filename.c_str()), (GCompareFunc)strcmp); } } g_dir_close(gdir); // ---------------- tree GtkTreeView* treeview = GTK_TREE_VIEW(w); GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING); gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(store)); GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes ( "Theme", gtk_cell_renderer_text_new(), "text", 0, NULL); gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column); GtkTreeIter iter; int i =0, curr=0; while (char* theme = (char*)g_list_nth_data(glist, i)) { gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, 0, theme, -1); if (strcmp(theme, get_current_theme().c_str()) == 0) { curr = i; } ++i; } GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); // set the default theme // THIS IS IMPORTANT!!! gtk_widget_grab_focus(w); std::stringstream str; str << curr; GtkTreePath* selpath = gtk_tree_path_new_from_string (str.str().c_str()); if (selpath) { gtk_tree_selection_select_path(selection, selpath); gtk_tree_view_scroll_to_cell(treeview, selpath, NULL, true, 0.5, 0.0); gtk_tree_path_free(selpath); } g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (themelist_selection_changed_cb), NULL); g_object_unref (G_OBJECT (store)); // ---------------- font // GtkWidget* fontentry = lookup_widget(g_main_window, "main_fontentry"); // gtk_entry_set_text(GTK_ENTRY(fontentry), get_current_font().c_str()); GtkWidget* fontbutton = lookup_widget(g_main_window, "main_font_selector_button"); gtk_font_button_set_font_name(GTK_FONT_BUTTON(fontbutton), get_current_font().c_str()); } // ------------------------------------------------------ #ifdef _WIN32 static void redirect_to_file (const gchar* log_domain, GLogLevelFlags log_level, const gchar* message, gpointer user_data) { /* only write logs if running in portable mode, otherwise we would get a permission error in program files */ if ((_access( "portable-mode", 0 )) != -1) { std::fstream f; f.open("gtk2-prefs.log", std::ios::app); f << message << "\n"; f.close(); } } #endif // ------------------------------------------------------ int main(int argc, char *argv[]) { // work around pango weirdness #ifdef _WIN32 // no longer needed as of pango 1.2.5, but won't do any harm // putenv("PANGO_WIN32_NO_UNISCRIBE=1"); #endif std::string user = g_get_user_name(); std::string tmp = g_get_tmp_dir(); std::string tmp_file = tmp + G_DIR_SEPARATOR_S + "gtk_prefs_tmprc_" + user; s_tmp_file = tmp_file; gtk_rc_add_default_file(tmp_file.c_str()); gtk_init (&argc, &argv); // redirect gtk warnings to file when in win32 #if defined _WIN32 && !defined DEBUG g_log_set_handler ("GLib", GLogLevelFlags(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), redirect_to_file, NULL); g_log_set_handler ("GModule", GLogLevelFlags(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), redirect_to_file, NULL); g_log_set_handler ("GLib-GObject", GLogLevelFlags(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), redirect_to_file, NULL); g_log_set_handler ("GThread", GLogLevelFlags(
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Label="Configuration">
    <PlatformToolset>v110</PlatformToolset>
  </PropertyGroup>
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{3024CF36-85E5-4E00-9608-7002E2C7EF14}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>hextray</RootNamespace>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</CharacterSet>
  &