Removed all global preferences path constants.
PrefHandler now exports a static method GetDefaultPath() which gets the path to the default settings file (using find_directory(), of course). Disabled locale support; should be easy to reenable when needed again, though. Made all the PrefHandler getters a lot more robust (could easily crash when asking for an unknown item). Some cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13853 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -42,37 +42,35 @@
|
|||||||
|
|
||||||
extern PrefHandler *gTermPref;
|
extern PrefHandler *gTermPref;
|
||||||
|
|
||||||
#define LOCALE_FILE_DIR PREF_FOLDER"menu/"
|
//#define LOCALE_FILE_DIR PREF_FOLDER"menu/"
|
||||||
|
|
||||||
|
|
||||||
BPopUpMenu *
|
BPopUpMenu *
|
||||||
MakeMenu(ulong msg, const char **items, const char *defaultItemName)
|
MakeMenu(ulong msg, const char **items, const char *defaultItemName)
|
||||||
{
|
{
|
||||||
BPopUpMenu *menu = new BPopUpMenu("");
|
BPopUpMenu *menu = new BPopUpMenu("");
|
||||||
|
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
while(*items)
|
while (*items) {
|
||||||
{
|
|
||||||
menu->AddItem(new BMenuItem(*items, new BMessage(msg)));
|
menu->AddItem(new BMenuItem(*items, new BMessage(msg)));
|
||||||
if(!strcmp(*items, defaultItemName))
|
if (!strcmp(*items, defaultItemName))
|
||||||
{
|
menu->ItemAt(i)->SetMarked(true);
|
||||||
(menu->ItemAt(i))->SetMarked(true);
|
|
||||||
}
|
|
||||||
items++;
|
items++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
longname2op(const char *longname)
|
longname2op(const char *longname)
|
||||||
{
|
{
|
||||||
int op = M_UTF8;
|
int op = M_UTF8;
|
||||||
const etable *s = encoding_table;
|
const etable *s = encoding_table;
|
||||||
|
|
||||||
for (int i = 0; s->name; s++, i++)
|
for (int i = 0; s->name; s++, i++) {
|
||||||
{
|
if (!strcmp(s->name, longname)) {
|
||||||
if(!strcmp(s->name, longname))
|
|
||||||
{
|
|
||||||
op = s->op;
|
op = s->op;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -80,47 +78,47 @@ longname2op(const char *longname)
|
|||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
op2longname(int op)
|
op2longname(int op)
|
||||||
{
|
{
|
||||||
return encoding_table[op].name;
|
return encoding_table[op].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MakeEncodingMenu(BMenu *eMenu, int coding, bool flag)
|
MakeEncodingMenu(BMenu *eMenu, int coding, bool flag)
|
||||||
{
|
{
|
||||||
const etable *e = encoding_table;
|
const etable *e = encoding_table;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(e->name)
|
while (e->name) {
|
||||||
{
|
|
||||||
BMessage *msg = new BMessage(MENU_ENCODING);
|
BMessage *msg = new BMessage(MENU_ENCODING);
|
||||||
msg->AddInt32("op", (int32)e->op);
|
msg->AddInt32("op", (int32)e->op);
|
||||||
if (flag)
|
if (flag)
|
||||||
eMenu->AddItem(new BMenuItem(e->name, msg, e->shortcut));
|
eMenu->AddItem(new BMenuItem(e->name, msg, e->shortcut));
|
||||||
else
|
else
|
||||||
eMenu->AddItem(new BMenuItem(e->name, msg));
|
eMenu->AddItem(new BMenuItem(e->name, msg));
|
||||||
|
|
||||||
if ( i == coding)
|
if (i == coding)
|
||||||
{
|
eMenu->ItemAt(i)->SetMarked(true);
|
||||||
(eMenu->ItemAt(i))->SetMarked(true);
|
|
||||||
}
|
|
||||||
e++;
|
e++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LoadLocaleFile(PrefHandler *pref)
|
LoadLocaleFile(PrefHandler *pref)
|
||||||
{
|
{
|
||||||
|
char name[B_PATH_NAME_LENGTH];
|
||||||
const char *locale;
|
const char *locale;
|
||||||
char buf[B_PATH_NAME_LENGTH];
|
|
||||||
status_t sts;
|
locale = gTermPref->getString(PREF_GUI_LANGUAGE);
|
||||||
|
// TODO: this effectively disables any locale support - which is okay for now
|
||||||
locale = gTermPref->getString (PREF_GUI_LANGUAGE);
|
sprintf(name, "%s%s", /*LOCALE_FILE_DIR*/"", locale);
|
||||||
sprintf (buf, "%s%s", LOCALE_FILE_DIR, locale);
|
|
||||||
|
//if (pref->OpenText(name) < B_OK)
|
||||||
sts = pref->OpenText (buf);
|
// pref->OpenText(LOCALE_FILE_DEFAULT);
|
||||||
|
|
||||||
if (sts == B_ERROR)
|
|
||||||
pref->OpenText (LOCALE_FILE_DEFAULT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -158,40 +158,44 @@ PrefDlg::SaveRequested(BMessage *msg)
|
|||||||
{
|
{
|
||||||
entry_ref dirref;
|
entry_ref dirref;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
|
|
||||||
msg->FindRef("directory", &dirref);
|
msg->FindRef("directory", &dirref);
|
||||||
msg->FindString("name", &filename);
|
msg->FindString("name", &filename);
|
||||||
|
|
||||||
BDirectory dir(&dirref);
|
BDirectory dir(&dirref);
|
||||||
BPath path(&dir, filename);
|
BPath path(&dir, filename);
|
||||||
|
|
||||||
gTermPref->SaveAsText (path.Path(), PREFFILE_MIMETYPE, TERM_SIGNATURE);
|
gTermPref->SaveAsText(path.Path(), PREFFILE_MIMETYPE, TERM_SIGNATURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PrefDlg::doSave (void)
|
PrefDlg::doSave()
|
||||||
{
|
{
|
||||||
delete fPrefTemp;
|
delete fPrefTemp;
|
||||||
fPrefTemp = new PrefHandler (gTermPref);
|
fPrefTemp = new PrefHandler(gTermPref);
|
||||||
|
|
||||||
gTermPref->SaveAsText (TERM_PREF, PREFFILE_MIMETYPE);
|
BPath path;
|
||||||
|
if (PrefHandler::GetDefaultPath(path) == B_OK) {
|
||||||
fDirty = false;
|
gTermPref->SaveAsText(path.Path(), PREFFILE_MIMETYPE);
|
||||||
|
fDirty = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PrefDlg::doRevert (void)
|
PrefDlg::doRevert()
|
||||||
{
|
{
|
||||||
BMessenger messenger (fTermWindow);
|
BMessenger messenger (fTermWindow);
|
||||||
|
|
||||||
delete gTermPref;
|
delete gTermPref;
|
||||||
gTermPref = new PrefHandler (fPrefTemp);
|
gTermPref = new PrefHandler(fPrefTemp);
|
||||||
|
|
||||||
messenger.SendMessage (MSG_HALF_FONT_CHANGED);
|
messenger.SendMessage(MSG_HALF_FONT_CHANGED);
|
||||||
messenger.SendMessage (MSG_COLOR_CHANGED);
|
messenger.SendMessage(MSG_COLOR_CHANGED);
|
||||||
messenger.SendMessage (MSG_ROWS_CHANGED);
|
messenger.SendMessage(MSG_ROWS_CHANGED);
|
||||||
messenger.SendMessage (MSG_INPUT_METHOD_CHANGED);
|
messenger.SendMessage(MSG_INPUT_METHOD_CHANGED);
|
||||||
|
|
||||||
fDirty = false;
|
fDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+201
-191
@@ -26,286 +26,296 @@
|
|||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
#include "Coding.h"
|
||||||
#include <stdlib.h>
|
#include "PrefHandler.h"
|
||||||
#include <string.h>
|
#include "TermConst.h"
|
||||||
|
|
||||||
#include <GraphicsDefs.h>
|
#include <GraphicsDefs.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <NodeInfo.h>
|
#include <NodeInfo.h>
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <FindDirectory.h>
|
||||||
|
#include <Path.h>
|
||||||
|
|
||||||
#include "Coding.h"
|
#include <stdio.h>
|
||||||
#include "PrefHandler.h"
|
#include <unistd.h>
|
||||||
#include "TermConst.h"
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Startup preference settings.
|
* Startup preference settings.
|
||||||
*/
|
*/
|
||||||
const prefDefaults termDefaults[] ={
|
const prefDefaults termDefaults[] ={
|
||||||
{ PREF_COLS, "80" },
|
{ PREF_COLS, "80" },
|
||||||
{ PREF_ROWS, "25" },
|
{ PREF_ROWS, "25" },
|
||||||
|
|
||||||
{ PREF_HALF_FONT_FAMILY, "Courier10 BT" },
|
{ PREF_HALF_FONT_FAMILY, "Courier10 BT" },
|
||||||
{ PREF_HALF_FONT_SIZE, "12" },
|
{ PREF_HALF_FONT_SIZE, "12" },
|
||||||
{ PREF_FULL_FONT_FAMILY, "Haru Tohaba" },
|
{ PREF_FULL_FONT_FAMILY, "Haru Tohaba" },
|
||||||
{ PREF_FULL_FONT_SIZE, "12" },
|
{ PREF_FULL_FONT_SIZE, "12" },
|
||||||
|
|
||||||
{ PREF_TEXT_FORE_COLOR, " 0, 0, 0" },
|
{ PREF_TEXT_FORE_COLOR, " 0, 0, 0" },
|
||||||
{ PREF_TEXT_BACK_COLOR, "255, 255, 255" },
|
{ PREF_TEXT_BACK_COLOR, "255, 255, 255" },
|
||||||
{ PREF_SELECT_FORE_COLOR, "255, 255, 255" },
|
{ PREF_SELECT_FORE_COLOR, "255, 255, 255" },
|
||||||
{ PREF_SELECT_BACK_COLOR, " 0, 0, 0" },
|
{ PREF_SELECT_BACK_COLOR, " 0, 0, 0" },
|
||||||
{ PREF_CURSOR_FORE_COLOR, "255, 255, 255" },
|
{ PREF_CURSOR_FORE_COLOR, "255, 255, 255" },
|
||||||
{ PREF_CURSOR_BACK_COLOR, " 0, 0, 0" },
|
{ PREF_CURSOR_BACK_COLOR, " 0, 0, 0" },
|
||||||
|
|
||||||
{ PREF_IM_FORE_COLOR, " 0, 0, 0" },
|
{ PREF_IM_FORE_COLOR, " 0, 0, 0" },
|
||||||
{ PREF_IM_BACK_COLOR, "152, 203, 255" },
|
{ PREF_IM_BACK_COLOR, "152, 203, 255" },
|
||||||
{ PREF_IM_SELECT_COLOR, "255, 152, 152" },
|
{ PREF_IM_SELECT_COLOR, "255, 152, 152" },
|
||||||
|
|
||||||
{ PREF_SHELL, "/bin/sh -login" },
|
{ PREF_SHELL, "/bin/sh -login" },
|
||||||
{ PREF_HISTORY_SIZE, "500" },
|
{ PREF_HISTORY_SIZE, "500" },
|
||||||
|
|
||||||
{ PREF_TEXT_ENCODING, "UTF-8" },
|
{ PREF_TEXT_ENCODING, "UTF-8" },
|
||||||
|
|
||||||
{ PREF_SELECT_MBUTTON, "Button 1"},
|
{ PREF_SELECT_MBUTTON, "Button 1"},
|
||||||
{ PREF_PASTE_MBUTTON, "Button 2"},
|
{ PREF_PASTE_MBUTTON, "Button 2"},
|
||||||
{ PREF_SUBMENU_MBUTTON, "Button 3"},
|
{ PREF_SUBMENU_MBUTTON, "Button 3"},
|
||||||
{ PREF_MOUSE_IMAGE, "Hand cursor"},
|
{ PREF_MOUSE_IMAGE, "Hand cursor"},
|
||||||
{ PREF_DRAGN_COPY, "0"},
|
{ PREF_DRAGN_COPY, "0"},
|
||||||
|
|
||||||
{ PREF_GUI_LANGUAGE, "English"},
|
{ PREF_GUI_LANGUAGE, "English"},
|
||||||
{ PREF_IM_AWARE, "0"},
|
{ PREF_IM_AWARE, "0"},
|
||||||
{ NULL, NULL},
|
{ NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
PrefHandler::PrefHandler()
|
PrefHandler::PrefHandler()
|
||||||
{
|
{
|
||||||
mPrefContainer.what = 'Pref';
|
fContainer.what = 'Pref';
|
||||||
OpenText(TERM_PREF, termDefaults);
|
|
||||||
|
BPath path;
|
||||||
|
GetDefaultPath(path);
|
||||||
|
OpenText(path.Path(), termDefaults);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
PrefHandler::PrefHandler(const PrefHandler* p)
|
PrefHandler::PrefHandler(const PrefHandler* p)
|
||||||
{
|
{
|
||||||
mPrefContainer = p->mPrefContainer;
|
fContainer = p->fContainer;
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
PrefHandler::~PrefHandler()
|
PrefHandler::~PrefHandler()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
/* static */
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
status_t
|
||||||
|
PrefHandler::GetDefaultPath(BPath& path)
|
||||||
|
{
|
||||||
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
// TODO: maybe just "Terminal"? (but this collides with the R5 Terminal settings file)
|
||||||
|
path.Append("HaikuTerminal");
|
||||||
|
path.Append("settings");
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PrefHandler::Open(const char *path, const prefDefaults *defaults)
|
PrefHandler::Open(const char *path, const prefDefaults *defaults)
|
||||||
{
|
{
|
||||||
BEntry ent(path);
|
BEntry entry(path);
|
||||||
if(ent.Exists()){
|
if (entry.Exists())
|
||||||
return loadFromFile(&ent);
|
return loadFromFile(&entry);
|
||||||
}else{
|
|
||||||
return loadFromDefault(defaults);
|
return loadFromDefault(defaults);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
status_t
|
status_t
|
||||||
PrefHandler::OpenText(const char *path, const prefDefaults *defaults)
|
PrefHandler::OpenText(const char *path, const prefDefaults *defaults)
|
||||||
{
|
{
|
||||||
BEntry ent(path);
|
BEntry entry(path);
|
||||||
if(ent.Exists()){
|
if (entry.Exists())
|
||||||
return loadFromTextFile(path);
|
return loadFromTextFile(path);
|
||||||
}else{
|
|
||||||
return loadFromDefault(defaults);
|
return loadFromDefault(defaults);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
status_t
|
status_t
|
||||||
PrefHandler::Save(const char *path)
|
PrefHandler::Save(const char *path)
|
||||||
{
|
{
|
||||||
status_t sts;
|
// make sure the target path exists
|
||||||
BFile file(path, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
BPath directoryPath(path);
|
||||||
sts = mPrefContainer.Flatten(&file);
|
if (directoryPath.GetParent(&directoryPath) == B_OK)
|
||||||
return sts;
|
create_directory(directoryPath.Path(), 0755);
|
||||||
|
|
||||||
|
BFile file(path, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
|
return fContainer.Flatten(&file);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
void
|
void
|
||||||
PrefHandler::SaveAsText(const char *path, const char *mimetype,
|
PrefHandler::SaveAsText(const char *path, const char *mimetype,
|
||||||
const char *signature)
|
const char *signature)
|
||||||
{
|
{
|
||||||
BFile file(path, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
// make sure the target path exists
|
||||||
type_code type;
|
BPath directoryPath(path);
|
||||||
char *key;
|
if (directoryPath.GetParent(&directoryPath) == B_OK)
|
||||||
char buf[256];
|
create_directory(directoryPath.Path(), 0755);
|
||||||
|
|
||||||
for (int32 i = 0; mPrefContainer.GetInfo(B_STRING_TYPE, i, &key, &type) == B_OK; i++){
|
BFile file(path, B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
int len = sprintf(buf, "\"%s\" , \"%s\"\n", key, this->getString(key));
|
char buffer[512];
|
||||||
file.Write(buf, len);
|
type_code type;
|
||||||
}
|
char *key;
|
||||||
|
|
||||||
if(mimetype != NULL){
|
for (int32 i = 0; fContainer.GetInfo(B_STRING_TYPE, i, &key, &type) == B_OK; i++) {
|
||||||
BNodeInfo info(&file);
|
int len = snprintf(buffer, sizeof(buffer), "\"%s\" , \"%s\"\n", key, getString(key));
|
||||||
info.SetType(mimetype);
|
file.Write(buffer, len);
|
||||||
info.SetPreferredApp (signature);
|
}
|
||||||
}
|
|
||||||
|
if (mimetype != NULL){
|
||||||
|
BNodeInfo info(&file);
|
||||||
|
info.SetType(mimetype);
|
||||||
|
info.SetPreferredApp(signature);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
int32
|
int32
|
||||||
PrefHandler::getInt32(const char *key)
|
PrefHandler::getInt32(const char *key)
|
||||||
{
|
{
|
||||||
return atoi(mPrefContainer.FindString(key));
|
const char *value = fContainer.FindString(key);
|
||||||
|
if (value == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return atoi(value);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
float
|
float
|
||||||
PrefHandler::getFloat(const char *key)
|
PrefHandler::getFloat(const char *key)
|
||||||
{
|
{
|
||||||
return atof(mPrefContainer.FindString(key));
|
const char *value = fContainer.FindString(key);
|
||||||
|
if (value == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return atof(value);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
const char*
|
const char*
|
||||||
PrefHandler::getString(const char *key)
|
PrefHandler::getString(const char *key)
|
||||||
{
|
{
|
||||||
const char *buf;
|
const char *buffer;
|
||||||
|
if (fContainer.FindString(key, &buffer) != B_OK)
|
||||||
|
buffer = "Error!";
|
||||||
|
|
||||||
if (mPrefContainer.FindString(key, &buf) != B_OK)
|
//printf("%x GET %s: %s\n", this, key, buf);
|
||||||
buf = "Error!";
|
return buffer;
|
||||||
|
|
||||||
//printf("%x GET %s: %s\n", this, key, buf);
|
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool
|
bool
|
||||||
PrefHandler::getBool(const char *key)
|
PrefHandler::getBool(const char *key)
|
||||||
{
|
{
|
||||||
const char *s = mPrefContainer.FindString(key);
|
const char *value = fContainer.FindString(key);
|
||||||
if (!strcmp(s, PREF_TRUE)) return true;
|
if (value == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
return !strcmp(value, PREF_TRUE);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// getRGB
|
|
||||||
// Returns RGB data from given key.
|
/** Returns RGB data from given key. */
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
rgb_color
|
rgb_color
|
||||||
PrefHandler::getRGB(const char *key)
|
PrefHandler::getRGB(const char *key)
|
||||||
{
|
{
|
||||||
int r, g, b;
|
rgb_color col;
|
||||||
rgb_color col;
|
int r, g, b;
|
||||||
if (const char *s = mPrefContainer.FindString(key)) {
|
|
||||||
sscanf(s, "%d, %d, %d", &r, &g, &b);
|
if (const char *s = fContainer.FindString(key)) {
|
||||||
} else {
|
sscanf(s, "%d, %d, %d", &r, &g, &b);
|
||||||
fprintf(stderr, "PrefHandler::getRGB(%s) - key not found\n", key);
|
} else {
|
||||||
r = g = b = 0;
|
fprintf(stderr, "PrefHandler::getRGB(%s) - key not found\n", key);
|
||||||
}
|
r = g = b = 0;
|
||||||
col.red = r;
|
}
|
||||||
col.green = g;
|
|
||||||
col.blue = b;
|
col.red = r;
|
||||||
col.alpha = 255;
|
col.green = g;
|
||||||
return col;
|
col.blue = b;
|
||||||
|
col.alpha = 255;
|
||||||
|
return col;
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// setInt32
|
|
||||||
// Setting Int32 data with key.
|
/** Setting Int32 data with key. */
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
void
|
void
|
||||||
PrefHandler::setInt32(const char *key, int32 data)
|
PrefHandler::setInt32(const char *key, int32 data)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buffer[32];
|
||||||
sprintf(buf, "%d", (int)data);
|
snprintf(buffer, sizeof(buffer), "%d", (int)data);
|
||||||
this->setString(key, buf);
|
setString(key, buffer);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// setFloat
|
|
||||||
// Setting Float data with key
|
/** Setting Float data with key */
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
void
|
void
|
||||||
PrefHandler::setFloat(const char *key, float data)
|
PrefHandler::setFloat(const char *key, float data)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buffer[32];
|
||||||
sprintf(buf, "%g", data);
|
snprintf(buffer, sizeof(buffer), "%g", data);
|
||||||
this->setString(key, buf);
|
setString(key, buffer);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// setBool
|
|
||||||
// Setting Bool data with key
|
/** Setting Bool data with key */
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
void
|
void
|
||||||
PrefHandler::setBool(const char *key, bool data)
|
PrefHandler::setBool(const char *key, bool data)
|
||||||
{
|
{
|
||||||
if(data){
|
if (data)
|
||||||
this->setString(key, PREF_TRUE);
|
setString(key, PREF_TRUE);
|
||||||
}else{
|
else
|
||||||
this->setString(key, PREF_FALSE);
|
setString(key, PREF_FALSE);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// this->setString
|
|
||||||
// Setting CString data with key
|
/** Setting CString data with key */
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
void
|
void
|
||||||
PrefHandler::setString(const char *key, const char *data)
|
PrefHandler::setString(const char *key, const char *data)
|
||||||
{
|
{
|
||||||
//printf("%x SET %s: %s\n", this, key, data);
|
//printf("%x SET %s: %s\n", this, key, data);
|
||||||
mPrefContainer.RemoveName(key);
|
fContainer.RemoveName(key);
|
||||||
mPrefContainer.AddString(key, data);
|
fContainer.AddString(key, data);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// setRGB
|
|
||||||
// Setting RGB data with key
|
/** Setting RGB data with key */
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
void
|
void
|
||||||
PrefHandler::setRGB(const char *key, const rgb_color data)
|
PrefHandler::setRGB(const char *key, const rgb_color data)
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buffer[32];
|
||||||
sprintf(buf, "%d, %d, %d", data.red, data.green, data.blue);
|
snprintf(buffer, sizeof(buffer), "%d, %d, %d", data.red, data.green, data.blue);
|
||||||
this->setString(key, buf);
|
setString(key, buffer);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// IsEmpty
|
|
||||||
// Check any peference stored or not.
|
/** Check any peference stored or not. */
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool
|
bool
|
||||||
PrefHandler::IsEmpty() const
|
PrefHandler::IsEmpty() const
|
||||||
{
|
{
|
||||||
return mPrefContainer.IsEmpty();
|
return fContainer.IsEmpty();
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
PrefHandler::loadFromFile(BEntry *ent)
|
PrefHandler::loadFromFile(BEntry *ent)
|
||||||
@@ -314,8 +324,8 @@ PrefHandler::loadFromFile(BEntry *ent)
|
|||||||
// save the settings. (Who cares about compatibility in this case anyway?)
|
// save the settings. (Who cares about compatibility in this case anyway?)
|
||||||
|
|
||||||
BFile file (ent, B_READ_ONLY);
|
BFile file (ent, B_READ_ONLY);
|
||||||
//mPrefContainer.MakeEmpty();
|
//fContainer.MakeEmpty();
|
||||||
//mPrefContainer.Unflatten(&file);
|
//fContainer.Unflatten(&file);
|
||||||
off_t size;
|
off_t size;
|
||||||
if (file.GetSize(&size) != B_OK || size != sizeof(struct termprefs))
|
if (file.GetSize(&size) != B_OK || size != sizeof(struct termprefs))
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
||||||
* Copyright (c) 2004 Daniel Furrer <[email protected]>
|
* Copyright (c) 2004 Daniel Furrer <[email protected]>
|
||||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
* Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files or portions
|
* a copy of this software and associated documentation files or portions
|
||||||
@@ -41,31 +41,30 @@
|
|||||||
#define TP_FONT_NAME_SZ 128
|
#define TP_FONT_NAME_SZ 128
|
||||||
|
|
||||||
struct termprefs {
|
struct termprefs {
|
||||||
uint32 magic;
|
uint32 magic;
|
||||||
uint32 version;
|
uint32 version;
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
uint32 cols;
|
uint32 cols;
|
||||||
uint32 rows;
|
uint32 rows;
|
||||||
uint32 tab_width;
|
uint32 tab_width;
|
||||||
uint32 font_size;
|
uint32 font_size;
|
||||||
char font[TP_FONT_NAME_SZ]; // "Family/Style"
|
char font[TP_FONT_NAME_SZ]; // "Family/Style"
|
||||||
uint32 cursor_blink_rate; // blinktime in µs = 1000000
|
uint32 cursor_blink_rate; // blinktime in µs = 1000000
|
||||||
uint32 refresh_rate; // ??? = 0
|
uint32 refresh_rate; // ??? = 0
|
||||||
rgb_color bg;
|
rgb_color bg;
|
||||||
rgb_color fg;
|
rgb_color fg;
|
||||||
rgb_color curbg;
|
rgb_color curbg;
|
||||||
rgb_color curfg;
|
rgb_color curfg;
|
||||||
rgb_color selbg;
|
rgb_color selbg;
|
||||||
rgb_color selfg;
|
rgb_color selfg;
|
||||||
char encoding; // index in the menu (0 = UTF-8)
|
char encoding; // index in the menu (0 = UTF-8)
|
||||||
char unknown[3];
|
char unknown[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct prefDefaults
|
struct prefDefaults {
|
||||||
{
|
const char *key;
|
||||||
const char *key;
|
char *item;
|
||||||
char *item;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define PREF_TRUE "true"
|
#define PREF_TRUE "true"
|
||||||
@@ -74,42 +73,40 @@ struct prefDefaults
|
|||||||
class BMessage;
|
class BMessage;
|
||||||
class BEntry;
|
class BEntry;
|
||||||
|
|
||||||
class PrefHandler{
|
class PrefHandler {
|
||||||
public:
|
public:
|
||||||
PrefHandler();
|
PrefHandler(const PrefHandler* p);
|
||||||
PrefHandler(const PrefHandler* p);
|
PrefHandler();
|
||||||
|
~PrefHandler();
|
||||||
|
|
||||||
~PrefHandler();
|
status_t Open(const char *name, const prefDefaults *defaults = NULL);
|
||||||
|
status_t OpenText(const char *path, const prefDefaults *defaults = NULL);
|
||||||
|
status_t Save(const char *name);
|
||||||
|
void SaveAsText(const char *path, const char *minmtype = NULL,
|
||||||
|
const char *signature = NULL);
|
||||||
|
|
||||||
status_t Open(const char *name, const prefDefaults *defaults = NULL);
|
int32 getInt32(const char *key);
|
||||||
status_t OpenText(const char *path, const prefDefaults *defaults = NULL);
|
float getFloat(const char *key);
|
||||||
status_t Save(const char *name);
|
const char* getString(const char *key);
|
||||||
void SaveAsText(const char *path, const char *minmtype = NULL,
|
bool getBool(const char *key);
|
||||||
const char *signature = NULL);
|
rgb_color getRGB(const char *key);
|
||||||
|
|
||||||
int32 getInt32(const char *key);
|
void setInt32(const char *key, int32 data);
|
||||||
float getFloat(const char *key);
|
void setFloat(const char *key, float data);
|
||||||
const char* getString(const char *key);
|
void setString(const char *key, const char *data);
|
||||||
bool getBool(const char *key);
|
void setBool(const char *key, bool data);
|
||||||
rgb_color getRGB(const char *key);
|
void setRGB(const char *key, const rgb_color data);
|
||||||
|
|
||||||
void setInt32(const char *key, int32 data);
|
bool IsEmpty() const;
|
||||||
void setFloat(const char *key, float data);
|
|
||||||
void setString(const char *key, const char *data);
|
|
||||||
void setBool(const char *key, bool data);
|
|
||||||
void setRGB(const char *key, const rgb_color data);
|
|
||||||
|
|
||||||
bool IsEmpty() const;
|
static status_t GetDefaultPath(BPath& path);
|
||||||
|
|
||||||
private:
|
|
||||||
status_t loadFromFile(BEntry *ent);
|
|
||||||
status_t loadFromDefault(const prefDefaults* defaluts = NULL);
|
|
||||||
status_t loadFromTextFile(const char * path);
|
|
||||||
|
|
||||||
|
|
||||||
BMessage mPrefContainer;
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
status_t loadFromFile(BEntry *ent);
|
||||||
|
status_t loadFromDefault(const prefDefaults* defaluts = NULL);
|
||||||
|
status_t loadFromTextFile(const char * path);
|
||||||
|
|
||||||
|
BMessage fContainer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //PREFHANDLER_H_INCLUDED
|
#endif // PREFHANDLER_H_INCLUDED
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
* Copyright (c) 2003-4 Kian Duffy <[email protected]>
|
||||||
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
* Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files or portions
|
* a copy of this software and associated documentation files or portions
|
||||||
@@ -147,9 +147,6 @@ enum {
|
|||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
// Preference Folder and setting path
|
// Preference Folder and setting path
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
#define PREF_FOLDER "/boot/home/config/settings/MuTerminal/"
|
|
||||||
const char * const TERM_PREF = PREF_FOLDER "setting.mp";
|
|
||||||
const char * const LOCALE_FILE_DEFAULT = PREF_FOLDER "menu/en";
|
|
||||||
|
|
||||||
const int32 DEFAULT = -1;
|
const int32 DEFAULT = -1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user