diff -Nur hpoj-0.91.orig/apps/xojpanel/xojpanel.cpp hpoj-0.91/apps/xojpanel/xojpanel.cpp --- hpoj-0.91.orig/apps/xojpanel/xojpanel.cpp 2002-07-25 13:01:24 +0400 +++ hpoj-0.91/apps/xojpanel/xojpanel.cpp 2004-04-10 21:53:36 +0400 @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -96,6 +97,10 @@ // Prints the contents of the character map to stdout. // #define DISPLAY_CHARACTER_MAP // +// Default encoding used by device for LCD messages +//#define DEFAULT_DEVICE_ENCODING "ISO8859-1" +#define DEFAULT_DEVICE_ENCODING "ISO8859-5" +// // In a case where you are using KDE2 and you built xojpanel // with qt-2.0.x, you may see a message like this: // "XError: BadValue(...)2". If so, try uncommenting the next line. @@ -127,6 +132,7 @@ caption = ""; useCaption = false; ptalDeviceName = ""; + deviceEncoding = DEFAULT_DEVICE_ENCODING; bool deviceNameInTitle = true; bool displayHelp = false; bool isTranslationEnabled = true; @@ -157,6 +163,11 @@ useCaption = true; i++; } + + else if(qstrcmp(argv[i], "-devenc") == 0) { + deviceEncoding = argv[i+1]; + i++; + } else if( (!possibleDeviceNameFound) && argv[i][0] != '-' ) { // Assume first unidentified argument is ptalDeviceName @@ -188,14 +199,16 @@ "\nOptions:\n\n" - "\t-help\t\tPrint this information and exit.\n" + "\t-help\t\t\tPrint this information and exit.\n" + + "\t-caption \t\tOptional text to be displayed in titlebar.\n" - "\t-caption Optional text to be displayed in titlebar.\n" + "\t-notrans\t\tDisables 'special character' translation.\n" - "\t-notrans\tDisables 'special character' translation.\n" + "\t-devenc \tEncoding used by device for LCD messages.\n" - "\t-hidedevname\tPrevents PTAL device name from\n" - "\t\t\tbeing displayed in the titlebar.\n\n" + "\t-hidedevname\t\tPrevents PTAL device name from\n" + "\t\t\t\tbeing displayed in the titlebar.\n\n" "\tThe first option *not* prefixed with a dash ('-')\n" "\twill be be used as the PTAL device name. If a default\n" @@ -317,6 +330,7 @@ characterMap[0x11] = 0xbb; // Right arrow to '>>' characterMap[0x12] = 0xa3; // Large pound(?) to small pound characterMap[0x13] = 0xbb; // Right hollow triangle to '>>' + characterMap[0x15] = 0xbb; // Right hollow triangle to '>>' characterMap[0x80] = 0xab; // Left hollow triangle to '<<' characterMap[0x81] = 0xbb; // Right black triangle to '>>' characterMap[0x82] = 0x2a; // Hollow circle to '*' @@ -529,8 +543,10 @@ int length = strlen(string); int i = 0; - int spaces = 0; + int encFrom = 0; + unsigned int spaces = 0; QString tmpString; + QTextCodec *codec; #ifdef SHOW_LCD_MESSAGE_ASCII_CODES // Show contents of original string as sent from device. @@ -546,28 +562,40 @@ if ( string[0] != 0 ) printf("\nNew message:\n"); #endif + // Initialize the codec + codec = QTextCodec::codecForName(deviceEncoding); + if ( ! codec ) + codec = QTextCodec::codecForName(DEFAULT_DEVICE_ENCODING); + // Convert each character in string[] to corresponding - // character in characterTranslationMap[] - for ( int i = 0; i < length; i++ ) { - string[i] = characterTranslationMap[ (unsigned char)string[i] ]; + // character in characterTranslationMap[] and apply necessary encoding + // conversion + for ( i = 0; i < length; i++ ) { + if ((char)characterTranslationMap[ (unsigned char)string[i] ] + != string[i]) { + tmpString += codec->toUnicode(string + encFrom, i - encFrom); + tmpString += + QChar(characterTranslationMap[ (unsigned char)string[i] ]); + encFrom = i + 1; + } } + tmpString += codec->toUnicode(string + encFrom, i - encFrom); spaces = 0; - i = length - 1 ; + i = tmpString.length() - 1 ; // Count spaces on the trailing end of the string. - while( string[i] == 0x20 ) { + while( tmpString[i] == 0x20 ) { // printf("i is now= %d\n", i); spaces++; // printf("spaces= %d\n\n", spaces); // Don't cycle through again if the entire string // is counted for removal. It could result in a segfault. - if( spaces >= length ) break; + if( spaces >= tmpString.length() ) break; i--; } - tmpString = string; // printf("tmpString= %s\n",(const char*)tmpString ); // Remove trailing spaces and assign text to appropriate message line. diff -Nur hpoj-0.91.orig/apps/xojpanel/xojpanel.h hpoj-0.91/apps/xojpanel/xojpanel.h --- hpoj-0.91.orig/apps/xojpanel/xojpanel.h 2002-07-25 13:01:24 +0400 +++ hpoj-0.91/apps/xojpanel/xojpanel.h 2004-04-10 20:35:01 +0400 @@ -83,6 +83,7 @@ char* caption; char* ptalDeviceName; + char* deviceEncoding; bool useCaption;