From 1d24af25719f3b19fe9520e23862b9dd0f321d69 Mon Sep 17 00:00:00 2001 From: assimil8or Date: Mon, 6 Sep 2004 20:15:13 +0000 Subject: [PATCH] my first commit: makes it possible to load R5 terminal setting files via the command line (Option -p) git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8865 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/MYOB/Coding.h | 7 ++- src/apps/terminal/MYOB/PrefHandler.cpp | 83 ++++++++++++++++++++++++-- src/apps/terminal/MYOB/PrefHandler.h | 26 ++++++++ src/apps/terminal/MYOB/TermApp.cpp | 73 ++++------------------ src/apps/terminal/MYOB/TermWindow.cpp | 2 +- 5 files changed, 120 insertions(+), 71 deletions(-) diff --git a/src/apps/terminal/MYOB/Coding.h b/src/apps/terminal/MYOB/Coding.h index bb50512082..1f3c9ec1c0 100644 --- a/src/apps/terminal/MYOB/Coding.h +++ b/src/apps/terminal/MYOB/Coding.h @@ -34,6 +34,7 @@ #include enum { + M_UTF8, /* UTF-8 */ M_ISO_8859_1, /* ISO-8859 */ M_ISO_8859_2, M_ISO_8859_3, @@ -50,7 +51,7 @@ enum { M_ISO_2022_JP, M_SJIS, /* Japanese */ M_EUC_JP, - M_EUC_KR, + M_EUC_KR // M_EUC_TW, /* Chinese */ // M_BIG5, @@ -59,10 +60,10 @@ enum { // M_EUC_KR, /* Koeran */ // M_ISO_2022_KR, - M_UTF8 /* UTF-8 */ }; const uint32 coding_translation_table[] = { + 0, B_ISO1_CONVERSION, /* ISO 8859-1 */ B_ISO2_CONVERSION, /* ISO 8859-2 */ B_ISO3_CONVERSION, /* ISO 8859-3 */ @@ -93,6 +94,7 @@ struct etable */ const etable encoding_table[]= { + {"UTF-8", "UTF8", 'U', M_UTF8}, {"ISO-8859-1", "8859-1", '1', M_ISO_8859_1}, {"ISO-8859-2", "8859-2", '2', M_ISO_8859_2}, {"ISO-8859-3", "8859-3", '3', M_ISO_8859_3}, @@ -108,7 +110,6 @@ const etable encoding_table[]= {"Shift-JIS", "SJIS", 'S', M_SJIS}, {"EUC-jp", "EUCJ", 'E', M_EUC_JP}, {"EUC-kr", "EUCK", 'K', M_EUC_KR}, - {"UTF-8", "UTF8", 'U', M_UTF8}, /* Not Implement. {"EUC-tw", "EUCT", "T", M_EUC_TW}, diff --git a/src/apps/terminal/MYOB/PrefHandler.cpp b/src/apps/terminal/MYOB/PrefHandler.cpp index 144ead9cf2..6c4852f4c5 100644 --- a/src/apps/terminal/MYOB/PrefHandler.cpp +++ b/src/apps/terminal/MYOB/PrefHandler.cpp @@ -38,7 +38,48 @@ #include #include +#include "Coding.h" #include "PrefHandler.h" +#include "TermConst.h" + +/* + * Startup preference settings. + */ +const prefDefaults termDefaults[] ={ + { PREF_COLS, "80" }, + { PREF_ROWS, "25" }, + + { PREF_HALF_FONT_FAMILY, "Courier10 BT" }, + { PREF_HALF_FONT_SIZE, "12" }, + { PREF_FULL_FONT_FAMILY, "Haru Tohaba" }, + { PREF_FULL_FONT_SIZE, "12" }, + + { PREF_TEXT_FORE_COLOR, " 0, 0, 0" }, + { PREF_TEXT_BACK_COLOR, "255, 255, 255" }, + { PREF_SELECT_FORE_COLOR, "255, 255, 255" }, + { PREF_SELECT_BACK_COLOR, " 0, 0, 0" }, + { PREF_CURSOR_FORE_COLOR, "255, 255, 255" }, + { PREF_CURSOR_BACK_COLOR, " 0, 0, 0" }, + + { PREF_IM_FORE_COLOR, " 0, 0, 0" }, + { PREF_IM_BACK_COLOR, "152, 203, 255" }, + { PREF_IM_SELECT_COLOR, "255, 152, 152" }, + + { PREF_SHELL, "/bin/sh -login" }, + { PREF_HISTORY_SIZE, "500" }, + + { PREF_TEXT_ENCODING, "UTF-8" }, + + { PREF_SELECT_MBUTTON, "Button 1"}, + { PREF_PASTE_MBUTTON, "Button 2"}, + { PREF_SUBMENU_MBUTTON, "Button 3"}, + { PREF_MOUSE_IMAGE, "Hand cursor"}, + { PREF_DRAGN_COPY, "0"}, + + { PREF_GUI_LANGUAGE, "English"}, + { PREF_IM_AWARE, "0"}, + { NULL, NULL}, +}; ///////////////////////////////////////////////////////////////////////////// // @@ -47,6 +88,7 @@ PrefHandler::PrefHandler() { mPrefContainer.what = 'Pref'; + OpenText(TERM_PREF, termDefaults); } ///////////////////////////////////////////////////////////////////////////// // @@ -155,12 +197,11 @@ PrefHandler::getString(const char *key) { const char *buf; - buf = mPrefContainer.FindString(key); - if (buf == NULL) + if (mPrefContainer.FindString(key, &buf) != B_OK) buf = "Error!"; + //printf("%x GET %s: %s\n", this, key, buf); return buf; - } ///////////////////////////////////////////////////////////////////////////// // @@ -232,6 +273,7 @@ PrefHandler::setBool(const char *key, bool data) void PrefHandler::setString(const char *key, const char *data) { + //printf("%x SET %s: %s\n", this, key, data); mPrefContainer.RemoveName(key); mPrefContainer.AddString(key, data); } @@ -263,9 +305,40 @@ PrefHandler::IsEmpty() const status_t PrefHandler::loadFromFile(BEntry *ent) { + // Future: It would be nice if we could simply use a flatened BMessage to + // save the settings. (Who cares about compatibility in this case anyway?) + BFile file (ent, B_READ_ONLY); - mPrefContainer.MakeEmpty(); - return mPrefContainer.Unflatten(&file); + //mPrefContainer.MakeEmpty(); + //mPrefContainer.Unflatten(&file); + off_t size; + if (file.GetSize(&size) != B_OK || size != sizeof(struct termprefs)) + return B_ERROR; + + struct termprefs prefs; + file.Read(&prefs, size); + if (prefs.magic != TP_MAGIC || prefs.version != TP_VERSION) + return B_ERROR; + + //Valid settings file! + setInt32(PREF_COLS, prefs.cols); + setInt32(PREF_ROWS, prefs.rows); + setInt32(PREF_HALF_FONT_SIZE, prefs.font_size); + setInt32(PREF_FULL_FONT_SIZE, prefs.font_size); + char *font_family = strtok(prefs.font, "/"); + char *font_style = strtok(NULL, ""); + setString(PREF_FULL_FONT_FAMILY, font_family); + setString(PREF_FULL_FONT_STYLE, font_style); + setString(PREF_HALF_FONT_FAMILY, font_family); + setString(PREF_HALF_FONT_STYLE, font_style); + setRGB(PREF_TEXT_BACK_COLOR, prefs.bg); + setRGB(PREF_TEXT_FORE_COLOR, prefs.fg); + setRGB(PREF_CURSOR_BACK_COLOR, prefs.curbg); + setRGB(PREF_CURSOR_FORE_COLOR, prefs.curfg); + setRGB(PREF_SELECT_BACK_COLOR, prefs.selbg); + setRGB(PREF_SELECT_FORE_COLOR, prefs.selfg); + setString(PREF_TEXT_ENCODING, encoding_table[prefs.encoding].name); + return B_OK; } ///////////////////////////////////////////////////////////////////////////// // diff --git a/src/apps/terminal/MYOB/PrefHandler.h b/src/apps/terminal/MYOB/PrefHandler.h index 744fa7f4bc..89f69724d5 100644 --- a/src/apps/terminal/MYOB/PrefHandler.h +++ b/src/apps/terminal/MYOB/PrefHandler.h @@ -35,6 +35,32 @@ #include #include +#define TP_MAGIC 0xf1f2f3f4 +#define TP_VERSION 0x02 +#define TP_FONT_NAME_SZ 128 + +struct termprefs { + uint32 magic; + uint32 version; + float x; + float y; + uint32 cols; + uint32 rows; + uint32 tab_width; + uint32 font_size; + char font[TP_FONT_NAME_SZ]; // "Family/Style" + uint32 cursor_blink_rate; // blinktime in µs = 1000000 + uint32 refresh_rate; // ??? = 0 + rgb_color bg; + rgb_color fg; + rgb_color curbg; + rgb_color curfg; + rgb_color selbg; + rgb_color selfg; + char encoding; // index in the menu (0 = UTF-8) + char unknown[3]; +}; + struct prefDefaults { const char *key; diff --git a/src/apps/terminal/MYOB/TermApp.cpp b/src/apps/terminal/MYOB/TermApp.cpp index d4c352e40b..0e8d8a8e3f 100644 --- a/src/apps/terminal/MYOB/TermApp.cpp +++ b/src/apps/terminal/MYOB/TermApp.cpp @@ -89,7 +89,7 @@ TermApp::TermApp (void) fAboutPanel = NULL; fTermFrame.Set(k, l, k + 50, k + 50); - gTermPref = new PrefHandler (); + gTermPref = new PrefHandler(); } //////////////////////////////////////////////////////////////////////////// @@ -102,45 +102,7 @@ TermApp::~TermApp (void) } -/* - * Startup preference settings. - */ -const prefDefaults termDefaults[] ={ - { PREF_COLS, "80" }, - { PREF_ROWS, "25" }, - { PREF_HALF_FONT_FAMILY, "Courier10 BT" }, - { PREF_HALF_FONT_SIZE, "12" }, - { PREF_FULL_FONT_FAMILY, "Haru Tohaba" }, - { PREF_FULL_FONT_SIZE, "12" }, - - { PREF_TEXT_FORE_COLOR, " 0, 0, 0" }, - { PREF_TEXT_BACK_COLOR, "255, 255, 255" }, - { PREF_SELECT_FORE_COLOR, "255, 255, 255" }, - { PREF_SELECT_BACK_COLOR, " 0, 0, 0" }, - { PREF_CURSOR_FORE_COLOR, "255, 255, 255" }, - { PREF_CURSOR_BACK_COLOR, " 0, 0, 0" }, - - { PREF_IM_FORE_COLOR, " 0, 0, 0" }, - { PREF_IM_BACK_COLOR, "152, 203, 255" }, - { PREF_IM_SELECT_COLOR, "255, 152, 152" }, - - { PREF_SHELL, "/bin/sh -login" }, - { PREF_HISTORY_SIZE, "500" }, - - { PREF_TEXT_ENCODING, "UTF-8" }, - - { PREF_SELECT_MBUTTON, "Button 1"}, - { PREF_PASTE_MBUTTON, "Button 2"}, - { PREF_SUBMENU_MBUTTON, "Button 3"}, - { PREF_MOUSE_IMAGE, "Hand cursor"}, - { PREF_DRAGN_COPY, "0"}, - - { PREF_GUI_LANGUAGE, "English"}, - { PREF_IM_AWARE, "0"}, - { NULL, NULL}, -}; - //////////////////////////////////////////////////////////////////////////// // // @@ -155,11 +117,6 @@ TermApp::ReadyToRun (void) const char *encoding; int rows, cols; - // gTermPref is not empty when App opened by pref file - if (gTermPref->IsEmpty()){ - gTermPref->OpenText(TERM_PREF, termDefaults); - } - encoding = gTermPref->getString (PREF_TEXT_ENCODING); /* Get encoding name (setenv TTYPE in spawn_shell functions). */ @@ -178,11 +135,6 @@ TermApp::ReadyToRun (void) command = gTermPref->getString (PREF_SHELL); } - if (geometry_requested) { - gTermPref->setInt32 (PREF_ROWS, fRows); - gTermPref->setInt32 (PREF_COLS, fCols); - } - rows = gTermPref->getInt32 (PREF_ROWS); cols = gTermPref->getInt32 (PREF_COLS); @@ -226,7 +178,7 @@ TermApp::MessageReceived (BMessage* msg) { switch(msg->what) { case MENU_NEW_TREM: - this->RunNewTerm (); + this->RunNewTerm(); break; case MENU_SWITCH_TERM: @@ -303,7 +255,7 @@ TermApp::ArgvReceived(int32 argc, char **argv) /* Load preference file. */ if (argmatch (argv, argc, "-p", "--preference", 4, &value, &skip_args)) { - gTermPref->OpenText(value); + gTermPref->Open(value); } @@ -325,8 +277,9 @@ TermApp::ArgvReceived(int32 argc, char **argv) usage_requested = true; this->PostMessage (B_QUIT_REQUESTED); } - fCols = width; - fRows = height; + gTermPref->setInt32 (PREF_COLS, width); + gTermPref->setInt32 (PREF_ROWS, height); + fTermFrame.Set(xpos, ypos, xpos + 50, ypos + 50); geometry_requested = true; } @@ -354,15 +307,11 @@ TermApp::ArgvReceived(int32 argc, char **argv) standard_args[i].longname, 9, &value, &skip_args)) { - if (text_to_rgb (value, &color, buffer)) { - if (gTermPref->IsEmpty()){ - gTermPref->OpenText(TERM_PREF, termDefaults); - } - gTermPref->setRGB (standard_args[i].prefname, color); - } - else { - fprintf (stderr, "%s: invalid color string -- %s\n", argv[0], value); - } + if (text_to_rgb (value, &color, buffer)) { + gTermPref->setRGB (standard_args[i].prefname, color); + } else { + fprintf (stderr, "%s: invalid color string -- %s\n", argv[0], value); + } } } diff --git a/src/apps/terminal/MYOB/TermWindow.cpp b/src/apps/terminal/MYOB/TermWindow.cpp index 7d6da3dac9..2ade7b59a6 100644 --- a/src/apps/terminal/MYOB/TermWindow.cpp +++ b/src/apps/terminal/MYOB/TermWindow.cpp @@ -62,7 +62,7 @@ #include "ColorWindow.h" #include "AboutWindow.h" -// Gloval Preference Handler +// Global Preference Handler extern PrefHandler *gTermPref; // // help and GPL URL