2004-08-29 19:20:34 +04:00
|
|
|
/*
|
2006-02-13 20:35:05 +03:00
|
|
|
** Copyright 2004-2006, the Haiku project. All rights reserved.
|
2004-08-29 19:20:34 +04:00
|
|
|
** Distributed under the terms of the Haiku License.
|
|
|
|
**
|
2006-02-13 20:35:05 +03:00
|
|
|
** Authors in chronological order:
|
|
|
|
** mccall@digitalparadise.co.uk
|
|
|
|
** Jérôme Duval
|
|
|
|
** Marcus Overhagen
|
2004-08-29 19:20:34 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <FindDirectory.h>
|
|
|
|
#include <File.h>
|
|
|
|
#include <Path.h>
|
|
|
|
#include "KeyboardSettings.h"
|
|
|
|
|
|
|
|
KeyboardSettings::KeyboardSettings()
|
|
|
|
{
|
|
|
|
BPath path;
|
2006-02-13 20:35:05 +03:00
|
|
|
BFile file;
|
2004-08-29 19:20:34 +04:00
|
|
|
|
2006-02-13 20:35:05 +03:00
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
|
|
|
|
goto err;
|
|
|
|
if (path.Append(kb_settings_file) < B_OK)
|
|
|
|
goto err;
|
|
|
|
if (file.SetTo(path.Path(), B_READ_ONLY) < B_OK)
|
|
|
|
goto err;
|
|
|
|
if (file.Read(&fSettings, sizeof(kb_settings)) != sizeof(kb_settings))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return;
|
|
|
|
err:
|
|
|
|
fSettings.key_repeat_delay = kb_default_key_repeat_delay;
|
|
|
|
fSettings.key_repeat_rate = kb_default_key_repeat_rate;
|
2004-08-29 19:20:34 +04:00
|
|
|
}
|
|
|
|
|
2006-02-13 20:35:05 +03:00
|
|
|
|
2004-08-29 19:20:34 +04:00
|
|
|
KeyboardSettings::~KeyboardSettings()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyboardSettings::SetKeyboardRepeatRate(int32 rate)
|
|
|
|
{
|
|
|
|
fSettings.key_repeat_rate = rate;
|
2006-02-13 20:35:05 +03:00
|
|
|
Save();
|
2004-08-29 19:20:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-02-13 20:35:05 +03:00
|
|
|
KeyboardSettings::SetKeyboardRepeatDelay(bigtime_t delay)
|
2004-08-29 19:20:34 +04:00
|
|
|
{
|
2006-02-13 20:35:05 +03:00
|
|
|
fSettings.key_repeat_delay = delay;
|
|
|
|
Save();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyboardSettings::Save()
|
|
|
|
{
|
|
|
|
BPath path;
|
|
|
|
BFile file;
|
|
|
|
|
|
|
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
|
|
|
|
return;
|
|
|
|
if (path.Append(kb_settings_file) < B_OK)
|
|
|
|
return;
|
|
|
|
if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE) < B_OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
file.Write(&fSettings, sizeof(kb_settings));
|
2004-08-29 19:20:34 +04:00
|
|
|
}
|