void Settings::save_settings(Glib::RefPtr<Gio::File> file) { Glib::KeyFile cfg; for (uint i = 0; i < G_N_ELEMENTS (settings); i++) { Glib::ustring group, key; if (!get_group_and_key (i, group, key)) continue; switch (settings[i].type) { case T_BOOL: cfg.set_boolean (group, key, *PTR_BOOL(this, i)); break; case T_INT: cfg.set_integer (group, key, *PTR_INT(this, i)); break; case T_FLOAT: case T_COLOUR_MEMBER: cfg.set_double (group, key, *PTR_FLOAT(this, i)); break; case T_STRING: cfg.set_string (group, key, *PTR_STRING(this, i)); break; default: std::cerr << "Can't save setting of unknown type\n"; break; }; } GCode.m_impl->saveSettings (cfg); Glib::ustring contents = cfg.to_data(); Glib::file_set_contents (file->get_path(), contents); }
bool dialog_localsettings::save() { string settingsfile = Glib::get_home_dir() + "/.gutorrent"; Glib::KeyFile kf; kf.set_string("gutorrent", "host", eHost->get_text()); kf.set_string("gutorrent", "username", eUserName->get_text()); kf.set_string("gutorrent", "password", ePassword->get_text()); kf.set_integer("gutorrent", "update_interval", sUpdateInterval->get_value_as_int()); ofstream file; file.open(settingsfile.c_str(), ios::out | ios::trunc); file << kf.to_data(); file.close(); return true; }