* Separate the Settings class from the locale preflet a little (it can be reused in other parts of the OS)
* Improve the settings class so it is able to handle a revert * Re-enable the revert button in the preflet and make it work. This fixes #5897. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37400 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,6 +7,7 @@ UsePrivateHeaders shared ;
|
|||||||
Preference Locale :
|
Preference Locale :
|
||||||
LanguageListView.cpp
|
LanguageListView.cpp
|
||||||
Locale.cpp
|
Locale.cpp
|
||||||
|
LocaleSettings.cpp
|
||||||
LocaleWindow.cpp
|
LocaleWindow.cpp
|
||||||
TimeFormatSettingsView.cpp
|
TimeFormatSettingsView.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2005, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2005, Axel Dörfler, [email protected]. All rights reserved.
|
||||||
|
* Copyright 2010, Adrien Destugues <[email protected]>. All rightts reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "Locale.h"
|
#include "Locale.h"
|
||||||
|
#include "LocaleSettings.h"
|
||||||
#include "LocaleWindow.h"
|
#include "LocaleWindow.h"
|
||||||
|
|
||||||
#include <AboutWindow.h>
|
#include <AboutWindow.h>
|
||||||
@@ -12,10 +14,7 @@
|
|||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
#include <FindDirectory.h>
|
|
||||||
#include <File.h>
|
|
||||||
#include <Locale.h>
|
#include <Locale.h>
|
||||||
#include <Path.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -27,24 +26,6 @@
|
|||||||
|
|
||||||
const char* kSignature = "application/x-vnd.Haiku-Locale";
|
const char* kSignature = "application/x-vnd.Haiku-Locale";
|
||||||
|
|
||||||
static const uint32 kMsgLocaleSettings = 'LCst';
|
|
||||||
|
|
||||||
|
|
||||||
class Settings {
|
|
||||||
public:
|
|
||||||
Settings();
|
|
||||||
~Settings();
|
|
||||||
|
|
||||||
const BMessage& Message() const { return fMessage; }
|
|
||||||
void UpdateFrom(BMessage* message);
|
|
||||||
|
|
||||||
private:
|
|
||||||
status_t _Open(BFile* file, int32 mode);
|
|
||||||
|
|
||||||
BMessage fMessage;
|
|
||||||
bool fUpdated;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class LocalePreflet : public BApplication {
|
class LocalePreflet : public BApplication {
|
||||||
public:
|
public:
|
||||||
@@ -55,83 +36,12 @@ public:
|
|||||||
virtual void AboutRequested();
|
virtual void AboutRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Settings fSettings;
|
LocaleSettings fSettings;
|
||||||
|
LocaleSettings fOriginalSettings;
|
||||||
LocaleWindow* fLocaleWindow;
|
LocaleWindow* fLocaleWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//-----------------
|
|
||||||
|
|
||||||
|
|
||||||
Settings::Settings()
|
|
||||||
:
|
|
||||||
fMessage(kMsgLocaleSettings),
|
|
||||||
fUpdated(false)
|
|
||||||
{
|
|
||||||
BFile file;
|
|
||||||
if (_Open(&file, B_READ_ONLY) != B_OK
|
|
||||||
|| fMessage.Unflatten(&file) != B_OK) {
|
|
||||||
// set default prefs
|
|
||||||
fMessage.AddString("language", "en");
|
|
||||||
fMessage.AddString("country", "en_US");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Settings::~Settings()
|
|
||||||
{
|
|
||||||
if (!fUpdated)
|
|
||||||
return;
|
|
||||||
|
|
||||||
BFile file;
|
|
||||||
if (_Open(&file, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fMessage.Flatten(&file);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
Settings::_Open(BFile* file, int32 mode)
|
|
||||||
{
|
|
||||||
BPath path;
|
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
path.Append("Locale settings");
|
|
||||||
|
|
||||||
return file->SetTo(path.Path(), mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Settings::UpdateFrom(BMessage* message)
|
|
||||||
{
|
|
||||||
BPoint point;
|
|
||||||
if (message->FindPoint("window_location", &point) == B_OK)
|
|
||||||
fMessage.ReplacePoint("window_location", point);
|
|
||||||
|
|
||||||
BString langName;
|
|
||||||
// We make sure there is at least one string before erasing the previous
|
|
||||||
// settings, then we add the remaining ones, if any
|
|
||||||
if (message->FindString("language", &langName) == B_OK) {
|
|
||||||
// Remove any old data as we know we have newer one to replace it
|
|
||||||
fMessage.RemoveName("language");
|
|
||||||
for (int i = 0;; i++) {
|
|
||||||
if (message->FindString("language", i, &langName) != B_OK)
|
|
||||||
break;
|
|
||||||
fMessage.AddString("language", langName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message->FindString("country", &langName) == B_OK)
|
|
||||||
fMessage.ReplaceString("country", langName);
|
|
||||||
|
|
||||||
fUpdated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -141,10 +51,15 @@ LocalePreflet::LocalePreflet()
|
|||||||
{
|
{
|
||||||
fLocaleWindow = new LocaleWindow();
|
fLocaleWindow = new LocaleWindow();
|
||||||
|
|
||||||
|
fOriginalSettings.Load();
|
||||||
|
fSettings = fOriginalSettings;
|
||||||
|
|
||||||
|
/*
|
||||||
if (fSettings.Message().HasPoint("window_location")) {
|
if (fSettings.Message().HasPoint("window_location")) {
|
||||||
BPoint point = fSettings.Message().FindPoint("window_location");
|
BPoint point = fSettings.Message().FindPoint("window_location");
|
||||||
fLocaleWindow->MoveTo(point);
|
fLocaleWindow->MoveTo(point);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
fLocaleWindow->Show();
|
fLocaleWindow->Show();
|
||||||
}
|
}
|
||||||
@@ -152,6 +67,7 @@ LocalePreflet::LocalePreflet()
|
|||||||
|
|
||||||
LocalePreflet::~LocalePreflet()
|
LocalePreflet::~LocalePreflet()
|
||||||
{
|
{
|
||||||
|
fSettings.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -163,6 +79,10 @@ LocalePreflet::MessageReceived(BMessage* message)
|
|||||||
fSettings.UpdateFrom(message);
|
fSettings.UpdateFrom(message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case kMsgRevert:
|
||||||
|
fSettings = fOriginalSettings;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BApplication::MessageReceived(message);
|
BApplication::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Adrien Destugues <[email protected]>.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "LocaleSettings.h"
|
||||||
|
|
||||||
|
#include <FindDirectory.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <String.h>
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const uint32 kMsgLocaleSettings = 'LCst';
|
||||||
|
|
||||||
|
|
||||||
|
LocaleSettings::LocaleSettings()
|
||||||
|
:
|
||||||
|
fMessage(kMsgLocaleSettings),
|
||||||
|
fSaved(false)
|
||||||
|
{
|
||||||
|
// Set default preferences
|
||||||
|
fMessage.AddString("language", "en");
|
||||||
|
fMessage.AddString("country", "en_US");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
LocaleSettings::Load()
|
||||||
|
{
|
||||||
|
BFile file;
|
||||||
|
status_t err;
|
||||||
|
err = _Open(&file, B_READ_ONLY);
|
||||||
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
err = fMessage.Unflatten(&file);
|
||||||
|
if (err == B_OK)
|
||||||
|
fSaved = true;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
LocaleSettings::Save()
|
||||||
|
{
|
||||||
|
BFile file;
|
||||||
|
status_t err;
|
||||||
|
err = _Open(&file, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
|
||||||
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
err = fMessage.Flatten(&file);
|
||||||
|
if (err == B_OK)
|
||||||
|
fSaved = true;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
LocaleSettings::_Open(BFile* file, int32 mode)
|
||||||
|
{
|
||||||
|
BPath path;
|
||||||
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
path.Append("Locale settings");
|
||||||
|
|
||||||
|
return file->SetTo(path.Path(), mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LocaleSettings::UpdateFrom(BMessage* message)
|
||||||
|
{
|
||||||
|
BString langName;
|
||||||
|
|
||||||
|
if (message->FindString("language", &langName) == B_OK) {
|
||||||
|
fMessage.RemoveName("language");
|
||||||
|
|
||||||
|
for (int i = 0;; i++) {
|
||||||
|
if (message->FindString("language", i, &langName) != B_OK)
|
||||||
|
break;
|
||||||
|
fMessage.AddString("language", langName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message->FindString("country", &langName) == B_OK)
|
||||||
|
fMessage.ReplaceString("country", langName);
|
||||||
|
|
||||||
|
fSaved = false;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Adrien Destugues <[email protected]>.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __LOCALE_SETTINGS_H__
|
||||||
|
#define __LOCALE_SETTINGS_H__
|
||||||
|
|
||||||
|
|
||||||
|
#include <File.h>
|
||||||
|
#include <Message.h>
|
||||||
|
|
||||||
|
|
||||||
|
class LocaleSettings {
|
||||||
|
public:
|
||||||
|
LocaleSettings();
|
||||||
|
|
||||||
|
status_t Load();
|
||||||
|
status_t Save();
|
||||||
|
|
||||||
|
bool Saved();
|
||||||
|
bool operator==(const LocaleSettings& other);
|
||||||
|
|
||||||
|
void UpdateFrom(BMessage* message);
|
||||||
|
|
||||||
|
/*
|
||||||
|
void SetPreferredLanguages();
|
||||||
|
void GetPreferredLanguages();
|
||||||
|
void SetCountry();
|
||||||
|
void GetCountry();
|
||||||
|
|
||||||
|
void SetDateFormat();
|
||||||
|
void GetDateFormat();
|
||||||
|
void SetTimeFormat();
|
||||||
|
void GetTimeFormat();
|
||||||
|
void SetNumberFormat();
|
||||||
|
void GetNumberFormat();
|
||||||
|
void SetMoneyFormat();
|
||||||
|
void GetMoneyFormat();
|
||||||
|
*/
|
||||||
|
|
||||||
|
private:
|
||||||
|
status_t _Open(BFile* file, int32 mode);
|
||||||
|
|
||||||
|
BMessage fMessage;
|
||||||
|
bool fSaved;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -45,7 +45,6 @@ static const uint32 kMsgPreferredLanguageDragged = 'PLDr';
|
|||||||
static const uint32 kMsgPreferredLanguageDeleted = 'PLDl';
|
static const uint32 kMsgPreferredLanguageDeleted = 'PLDl';
|
||||||
static const uint32 kMsgCountrySelection = 'csel';
|
static const uint32 kMsgCountrySelection = 'csel';
|
||||||
static const uint32 kMsgDefaults = 'dflt';
|
static const uint32 kMsgDefaults = 'dflt';
|
||||||
static const uint32 kMsgRevert = 'revt';
|
|
||||||
|
|
||||||
static const uint32 kMsgPreferredLanguagesChanged = 'lang';
|
static const uint32 kMsgPreferredLanguagesChanged = 'lang';
|
||||||
|
|
||||||
@@ -215,23 +214,23 @@ LocaleWindow::LocaleWindow()
|
|||||||
|
|
||||||
BButton* button = new BButton(B_TRANSLATE("Defaults"),
|
BButton* button = new BButton(B_TRANSLATE("Defaults"),
|
||||||
new BMessage(kMsgDefaults));
|
new BMessage(kMsgDefaults));
|
||||||
#if 0
|
|
||||||
fRevertButton = new BButton(B_TRANSLATE("Revert"),
|
fRevertButton = new BButton(B_TRANSLATE("Revert"),
|
||||||
new BMessage(kMsgRevert));
|
new BMessage(kMsgRevert));
|
||||||
fRevertButton->SetEnabled(false);
|
fRevertButton->SetEnabled(false);
|
||||||
#endif
|
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL, spacing)
|
BLayoutBuilder::Group<>(this, B_VERTICAL, spacing)
|
||||||
.Add(tabView)
|
.Add(tabView)
|
||||||
.AddGroup(B_HORIZONTAL, spacing)
|
.AddGroup(B_HORIZONTAL, spacing)
|
||||||
.Add(button)
|
.Add(button)
|
||||||
// .Add(fRevertButton)
|
.Add(fRevertButton)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.End()
|
.End()
|
||||||
.SetInsets(spacing, spacing, spacing, spacing)
|
.SetInsets(spacing, spacing, spacing, spacing)
|
||||||
.End();
|
.End();
|
||||||
|
|
||||||
_UpdatePreferredFromLocaleRoster();
|
_UpdatePreferredFromLocaleRoster();
|
||||||
|
SettingsReverted();
|
||||||
CenterOnScreen();
|
CenterOnScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,7 +249,8 @@ LocaleWindow::MessageReceived(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgRevert:
|
case kMsgRevert:
|
||||||
// TODO
|
be_app_messenger.SendMessage(message);
|
||||||
|
_UpdatePreferredFromLocaleRoster();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgLanguageDragged:
|
case kMsgLanguageDragged:
|
||||||
@@ -345,6 +345,7 @@ LocaleWindow::MessageReceived(BMessage* message)
|
|||||||
BMessage newMessage(kMsgSettingsChanged);
|
BMessage newMessage(kMsgSettingsChanged);
|
||||||
newMessage.AddString("country", item->ID());
|
newMessage.AddString("country", item->ID());
|
||||||
be_app_messenger.SendMessage(&newMessage);
|
be_app_messenger.SendMessage(&newMessage);
|
||||||
|
SettingsChanged();
|
||||||
|
|
||||||
BCountry* country = new BCountry(item->ID());
|
BCountry* country = new BCountry(item->ID());
|
||||||
fFormatView->SetCountry(country);
|
fFormatView->SetCountry(country);
|
||||||
@@ -361,14 +362,24 @@ LocaleWindow::MessageReceived(BMessage* message)
|
|||||||
bool
|
bool
|
||||||
LocaleWindow::QuitRequested()
|
LocaleWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
BMessage update(kMsgSettingsChanged);
|
|
||||||
update.AddPoint("window_location", Frame().LeftTop());
|
|
||||||
be_app_messenger.SendMessage(&update);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LocaleWindow::SettingsChanged()
|
||||||
|
{
|
||||||
|
fRevertButton->SetEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LocaleWindow::SettingsReverted()
|
||||||
|
{
|
||||||
|
fRevertButton->SetEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LocaleWindow::_PreferredLanguagesChanged()
|
LocaleWindow::_PreferredLanguagesChanged()
|
||||||
{
|
{
|
||||||
@@ -412,6 +423,8 @@ LocaleWindow::_EnableDisableLanguages()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsChanged();
|
||||||
|
|
||||||
EnableUpdates();
|
EnableUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,5 +508,7 @@ LocaleWindow::_Defaults()
|
|||||||
update.AddString("language", "en");
|
update.AddString("language", "en");
|
||||||
|
|
||||||
be_app_messenger.SendMessage(&update);
|
be_app_messenger.SendMessage(&update);
|
||||||
|
SettingsChanged();
|
||||||
_UpdatePreferredFromLocaleRoster();
|
_UpdatePreferredFromLocaleRoster();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const uint32 kMsgRevert = 'revt';
|
||||||
|
|
||||||
|
|
||||||
class BButton;
|
class BButton;
|
||||||
class BListView;
|
class BListView;
|
||||||
class FormatView;
|
class FormatView;
|
||||||
@@ -24,6 +27,9 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
|
void SettingsChanged();
|
||||||
|
void SettingsReverted();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _PreferredLanguagesChanged();
|
void _PreferredLanguagesChanged();
|
||||||
void _EnableDisableLanguages();
|
void _EnableDisableLanguages();
|
||||||
@@ -32,7 +38,6 @@ private:
|
|||||||
int32 atIndex = -1);
|
int32 atIndex = -1);
|
||||||
void _Defaults();
|
void _Defaults();
|
||||||
|
|
||||||
private:
|
|
||||||
BButton* fRevertButton;
|
BButton* fRevertButton;
|
||||||
LanguageListView* fLanguageListView;
|
LanguageListView* fLanguageListView;
|
||||||
LanguageListView* fPreferredListView;
|
LanguageListView* fPreferredListView;
|
||||||
|
|||||||
Reference in New Issue
Block a user