From 9fb9c160af65c07aa797d3feb79152422ba668a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 29 Oct 2009 13:55:47 +0000 Subject: [PATCH] * TRoster now actually stores its settings, ie. the recent file list now survives a reboot. * The target directory is now created if needed. * Relocated/renamed the settings file to ~/config/settings/system/registrar/RosterSettings. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33827 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/registrar/TRoster.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/servers/registrar/TRoster.cpp b/src/servers/registrar/TRoster.cpp index 9f17f84a1c..5b4fb01cdc 100644 --- a/src/servers/registrar/TRoster.cpp +++ b/src/servers/registrar/TRoster.cpp @@ -3,10 +3,12 @@ * Distributed under the terms of the MIT License. */ + /*! TRoster is the incarnation of The Roster. It manages the running applications. */ + #include "TRoster.h" #include @@ -16,14 +18,16 @@ #include #include -#include #include #include +#include #include #include +#include + +#include #include #include -#include #include #include @@ -76,21 +80,23 @@ static const char* const kSystemServerPath = "/boot/system/servers"; /*! \brief Returns the path to the default roster settings. + \param path BPath to be set to the roster settings path. + \param createDirectory makes sure the target directory exists if \c true. + \return the settings path as C string (\code path.Path() \endcode). */ static const char* -get_default_roster_settings_file(BPath& path) +get_default_roster_settings_path(BPath& path, bool createDirectory) { // get the path of the settings dir and append the subpath of our file status_t error = find_directory(B_USER_SETTINGS_DIRECTORY, &path); if (error == B_OK) - error = path.Append("Roster/HaikuRosterSettings"); - - // If some error occurred, set the standard path (can only fail, if there's - // insufficient memory, which can't be helped anyway). - if (error != B_OK) - path.SetTo("/boot/home/config/settings/Roster/HaikuRosterSettings"); + error = path.Append("system/registrar"); + if (error == B_OK && createDirectory) + error = create_directory(path.Path(), 0777); + if (error == B_OK) + error = path.Append("RosterSettings"); return path.Path(); } @@ -1343,6 +1349,9 @@ TRoster::SetShuttingDown(bool shuttingDown) BAutolock _(fLock); fShuttingDown = shuttingDown; + + if (shuttingDown) + _SaveRosterSettings(); } @@ -1816,7 +1825,7 @@ TRoster::_LoadRosterSettings(const char* path) { BPath _path; const char* settingsPath - = path ? path : get_default_roster_settings_file(_path); + = path ? path : get_default_roster_settings_path(_path, false); RosterSettingsCharStream stream; status_t error; @@ -1984,7 +1993,7 @@ TRoster::_SaveRosterSettings(const char* path) { BPath _path; const char* settingsPath - = path != NULL ? path : get_default_roster_settings_file(_path); + = path != NULL ? path : get_default_roster_settings_path(_path, true); status_t error; FILE* file;