/[svn]/gigedit/trunk/src/gigedit/Settings.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/Settings.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2891 by schoenebeck, Tue Apr 26 17:42:26 2016 UTC revision 2893 by schoenebeck, Fri Apr 29 14:19:53 2016 UTC
# Line 11  Line 11 
11  #include <glibmm/keyfile.h>  #include <glibmm/keyfile.h>
12  #include <iostream>  #include <iostream>
13  #include <stdio.h>  #include <stdio.h>
14    #include <fstream>
15    
16    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 40) || GTKMM_MAJOR_VERSION < 2
17    # define HAS_GLIB_KEYFILE_SAVE_TO_FILE 0
18    #else
19    # define HAS_GLIB_KEYFILE_SAVE_TO_FILE 1
20    #endif
21    
22  static std::string configDir() {  static std::string configDir() {
23      //printf("configDir '%s'\n", g_get_user_config_dir());      //printf("configDir '%s'\n", g_get_user_config_dir());
# Line 27  static std::string configFile() { Line 34  static std::string configFile() {
34  }  }
35    
36  static std::string groupName(Settings::Group_t group) {  static std::string groupName(Settings::Group_t group) {
37        switch (group) {
38            case Settings::GLOBAL: return "Global";
39            case Settings::MAIN_WINDOW: return "MainWindow";
40            case Settings::SCRIPT_EDITOR: return "ScriptEditor";
41        }
42      return "Global";      return "Global";
43  }  }
44    
45    #if !HAS_GLIB_KEYFILE_SAVE_TO_FILE
46    
47    static bool saveToFile(Glib::KeyFile* keyfile, std::string filename) {
48        Glib::ustring s = keyfile->to_data();
49        std::ofstream out;
50        out.open(filename.c_str(), std::ios_base::out | std::ios_base::trunc);
51        out << s;
52        out.close();
53        return true;
54    }
55    
56    #endif // ! HAS_GLIB_KEYFILE_SAVE_TO_FILE
57    
58  static Settings* _instance = NULL;  static Settings* _instance = NULL;
59            
60  Settings* Settings::singleton() {  Settings* Settings::singleton() {
# Line 44  Settings::Settings() : Glib::ObjectBase( Line 69  Settings::Settings() : Glib::ObjectBase(
69      warnUserOnExtensions(*this, GLOBAL, "warnUserOnExtensions", true),      warnUserOnExtensions(*this, GLOBAL, "warnUserOnExtensions", true),
70      syncSamplerInstrumentSelection(*this, GLOBAL, "syncSamplerInstrumentSelection", true),      syncSamplerInstrumentSelection(*this, GLOBAL, "syncSamplerInstrumentSelection", true),
71      moveRootNoteWithRegionMoved(*this, GLOBAL, "moveRootNoteWithRegionMoved", true),      moveRootNoteWithRegionMoved(*this, GLOBAL, "moveRootNoteWithRegionMoved", true),
72        mainWindowX(*this, MAIN_WINDOW, "x", -1),
73        mainWindowY(*this, MAIN_WINDOW, "y", -1),
74        mainWindowW(*this, MAIN_WINDOW, "w", -1),
75        mainWindowH(*this, MAIN_WINDOW, "h", -1),
76        scriptEditorWindowX(*this, SCRIPT_EDITOR, "x", -1),
77        scriptEditorWindowY(*this, SCRIPT_EDITOR, "y", -1),
78        scriptEditorWindowW(*this, SCRIPT_EDITOR, "w", -1),
79        scriptEditorWindowH(*this, SCRIPT_EDITOR, "h", -1),
80      m_ignoreNotifies(false)      m_ignoreNotifies(false)
81  {  {
82      m_boolProps.push_back(&warnUserOnExtensions);      m_boolProps.push_back(&warnUserOnExtensions);
83      m_boolProps.push_back(&syncSamplerInstrumentSelection);      m_boolProps.push_back(&syncSamplerInstrumentSelection);
84      m_boolProps.push_back(&moveRootNoteWithRegionMoved);      m_boolProps.push_back(&moveRootNoteWithRegionMoved);
85        m_intProps.push_back(&mainWindowX);
86        m_intProps.push_back(&mainWindowY);
87        m_intProps.push_back(&mainWindowW);
88        m_intProps.push_back(&mainWindowH);
89        m_intProps.push_back(&scriptEditorWindowX);
90        m_intProps.push_back(&scriptEditorWindowY);
91        m_intProps.push_back(&scriptEditorWindowW);
92        m_intProps.push_back(&scriptEditorWindowH);
93  }  }
94    
95  void Settings::onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group) {  void Settings::onPropertyChanged(Glib::PropertyBase* pProperty, RawValueType_t type, Group_t group) {
# Line 85  void Settings::onPropertyChanged(Glib::P Line 126  void Settings::onPropertyChanged(Glib::P
126      }      }
127    
128      try {      try {
129    #if HAS_GLIB_KEYFILE_SAVE_TO_FILE
130          bool ok = file.save_to_file(configFile());          bool ok = file.save_to_file(configFile());
131    #else
132            bool ok = saveToFile(&file, configFile());
133    #endif
134          if (!ok) {          if (!ok) {
135              std::cerr << "Failed saving gigedit config to '" << configFile() << "'\n" << std::flush;              std::cerr << "Failed saving gigedit config to '" << configFile() << "'\n" << std::flush;
136          } else {          } else {

Legend:
Removed from v.2891  
changed lines
  Added in v.2893

  ViewVC Help
Powered by ViewVC