preferences.cpp revision 4852f347df5405e934e2ccd5b30597d196f3949c
/** @file
* @brief Singleton class to access the preferences file - implementation
*
* Authors:
* Krzysztof KosiĆski <tweenk.pl@gmail.com>
*
* Copyright (C) 2008 Authors
*
* Released under GNU GPL. Read the file 'COPYING' for more information.
*/
#include "preferences.h"
#include "preferences-skeleton.h"
#include "inkscape.h"
#include "xml/node-observer.h"
#include <glibmm/fileutils.h>
#include <glib.h>
#include <gtkmm/messagedialog.h>
#define PREFERENCES_FILE_NAME "preferences.xml"
namespace Inkscape {
Preferences::Preferences() :
_prefs_dir(""),
_prefs_filename(""),
_writable(false),
{
// profile_path essentailly returns the argument prefixed by the profile directory.
_prefs_dir = path;
_load();
}
{
// when the preferences are unloaded, save them
save();
}
/**
* @brief Load internal defaults
*
* In the future this will try to load the system-wide file before falling
* back to the internal defaults.
*/
void Preferences::_loadDefaults()
{
}
/**
* @brief Load the user's customized preferences
*
* Tries to load the user's preferences.xml file. If there is none, creates it.
* Displays dialog boxes on any errors.
*/
void Preferences::_load()
{
"and new settings will not be saved. ");
// 1. Does the file exist?
// No - we need to create one.
// Does the profile directory exist?
// No - create the profile directory
// the creation failed
return;
}
// create some subdirectories for user stuff
for(int i=0; user_dirs[i]; ++i) {
}
// The profile dir is not actually a directory
return;
}
// The profile dir exists and is valid.
if (!g_file_set_contents(_prefs_filename.data(), preferences_skeleton, PREFERENCES_SKELETON_SIZE, NULL)) {
// The write failed.
return;
}
// The prefs file was just created.
// We can return now and skip the rest of the load process.
_writable = true;
return;
}
// Yes, the pref file exists.
// 2. Is it a regular file?
return;
}
// 3. Is the file readable?
return;
}
// 4. Is it valid XML?
if (!prefs_read) {
return;
}
// 5. Basic sanity check: does the root element have a correct name?
return;
}
// Merge the loaded prefs with defaults.
_writable = true;
}
/**
* @brief Flush all pref changes to the XML file
*/
void Preferences::save()
{
if (!_writable) return; // no-op if the prefs file is not writable
// sp_repr_save_file uses utf-8 instead of the glib filename encoding.
// I don't know why filenames are kept in utf-8 in Inkscape and then
// converted to filename encoding when necessary through sepcial functions
// - wouldn't it be easier to keep things in the encoding they are supposed
// to be in?
}
{
}
// Now for the meat.
// Most of the logic is similar to former prefs-utils.cpp
/**
* @brief Check for the existence of a given pref key
* @param pref_key Preference key to check
* @return True if the key exists, false otherwise
*/
{
}
/**
* @brief Get the number of sub-preferences of a given pref
* @param pref_key Preference key to check
* @return Number of sub-preferences
*
* Note: This does not count attributes, only child preferences.
*/
{
}
/**
* @brief Get the key of the n-th sub-preference of the specified pref
* @param father_key Parent key
* @param n The zero-based index of the pref key to retrieve
* @return The key of the n-th sub-preference
*/
{
if (!node) return "";
if (!child) return "";
child_key += '.';
return child_key;
}
return "";
}
/**
* @brief Create the preference with the specified key
* @return True if the node was created, false if it already existed
*
* This method is redundant, because the setters automatically create prefs
* if they don't already exist. It is only left to accomodate some legacy code
* which manipulates the DOM of the preferences file directly.
*/
{
return true;
}
// getter methods
/**
* @brief Get a boolean attribute of a preference
* @param pref_key Key of he preference to retrieve
* @param attr Attribute to retrieve
* @param def The default value to return if the preference is not set
* @return The retrieved value
*/
{
// This is to handle legacy preferences using ints as booleans
return false;
}
/**
* @brief Get an integer attribute of a preference
* @param pref_key Key of he preference to retrieve
* @param attr Attribute to retrieve
* @param def The default value to return if the preference is not set
* @return The retrieved value
*/
{
// Protection against leftover getInt calls when the value is in fact a boolean
if (str == "false") return 0;
}
int Preferences::getIntLimited(Glib::ustring const &pref_key, Glib::ustring const &attr, int def, int min, int max)
{
}
/**
* @brief Get a floating point attribute of a preference
* @param pref_key Key of he preference to retrieve
* @param attr Attribute to retrieve
* @param def The default value to return if the preference is not set
* @return The retrieved value
*/
{
}
double Preferences::getDoubleLimited(Glib::ustring const &pref_key, Glib::ustring const &attr, double def, double min, double max)
{
}
/**
* @brief Get a string attribute of a preference
* @param pref_key Key of he preference to retrieve
* @param attr Attribute to retrieve
* @param def The default value to return if the preference is not set
* @return The retrieved value
*/
{
if (!node) return "";
if (!str) return "";
}
// setter methods
/**
* @brief Set a boolean attribute of a preference
* @param pref_key Key of the preference to modify
* @param attr Attribute to set
* @param value The new value of the pref attribute
*/
{
}
/**
* @brief Set an integer attribute of a preference
* @param pref_key Key of the preference to modify
* @param attr Attribute to set
* @param value The new value of the pref attribute
*/
{
}
/**
* @brief Set a floating point attribute of a preference
* @param pref_key Key of the preference to modify
* @param attr Attribute to set
* @param value The new value of the pref attribute
*/
{
/*
gchar dblstr[32];
g_snprintf(dblstr, 32, "%g", value);
node->setAttribute(attr, dblstr);
*/
}
/**
* @brief Set a string attribute of a preference
* @param pref_key Key of the preference to modify
* @param attr Attribute to set
* @param value The new value of the pref attribute
*/
void Preferences::setString(Glib::ustring const &pref_key, Glib::ustring const &attr, Glib::ustring const &value)
{
}
/**
* @brief Get the XML node corresponding to the given pref key
* @param pref_key Preference key (path) to get
* @param create Whether to create the corresponding node if it doesn't exist
* @return XML node corresponding to the specified key
*
* The separator for key components is '.' (a dot). Derived from former
* inkscape_get_repr().
*/
{
int part_i = 0;
// If the previous loop found a matching key, child now contains the node
// matching the processed key part. If no node was found then it is NULL.
if (!child) {
if (create) {
// create the rest of the key
++part_i;
}
return node;
} else {
return NULL;
}
}
++part_i;
}
return node;
}
{
if (Preferences::use_gui) {
} else {
}
}
bool Preferences::use_gui = true;
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0))
indent-tabs-mode:nil
fill-column:75
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :