diff options
Diffstat (limited to 'linden/indra/newview')
-rw-r--r-- | linden/indra/newview/lgghunspell_wrapper.cpp | 327 | ||||
-rw-r--r-- | linden/indra/newview/lgghunspell_wrapper.h | 6 |
2 files changed, 210 insertions, 123 deletions
diff --git a/linden/indra/newview/lgghunspell_wrapper.cpp b/linden/indra/newview/lgghunspell_wrapper.cpp index 5879bac..632c117 100644 --- a/linden/indra/newview/lgghunspell_wrapper.cpp +++ b/linden/indra/newview/lgghunspell_wrapper.cpp | |||
@@ -468,53 +468,64 @@ static char * languageCodesraw[]={ | |||
468 | }; | 468 | }; |
469 | //#define LANGUAGE_CODES_RAW_SIZE ((__LINE__ - 1 - LANGUAGE_CODES_RAW_START_LINE) * 2) | 469 | //#define LANGUAGE_CODES_RAW_SIZE ((__LINE__ - 1 - LANGUAGE_CODES_RAW_START_LINE) * 2) |
470 | #define LANGUAGE_CODES_RAW_SIZE 368 | 470 | #define LANGUAGE_CODES_RAW_SIZE 368 |
471 | |||
471 | lggHunSpell_Wrapper::lggHunSpell_Wrapper() | 472 | lggHunSpell_Wrapper::lggHunSpell_Wrapper() |
473 | : | ||
474 | mSpellCheckHighlight(false) | ||
472 | { | 475 | { |
473 | highlightInRed=false; | ||
474 | //languageCodes(begin(languageCodesraw), end(languageCodesraw)); | 476 | //languageCodes(begin(languageCodesraw), end(languageCodesraw)); |
475 | } | 477 | } |
476 | lggHunSpell_Wrapper::~lggHunSpell_Wrapper(){} | 478 | |
479 | lggHunSpell_Wrapper::~lggHunSpell_Wrapper() | ||
480 | { | ||
481 | } | ||
482 | |||
477 | std::string lggHunSpell_Wrapper::getCorrectPath(std::string file) | 483 | std::string lggHunSpell_Wrapper::getCorrectPath(std::string file) |
478 | { | 484 | { |
479 | //finds out if it is in user dir, if not, takes it from app dir | 485 | //finds out if it is in user dir, if not, takes it from app dir |
480 | std::string dicpath1(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", file).c_str()); | 486 | std::string dicpath1(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", file).c_str()); |
481 | if(!gDirUtilp->fileExists(dicpath1)) | 487 | if (!gDirUtilp->fileExists(dicpath1)) |
488 | { | ||
482 | dicpath1=gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "dictionaries", file).c_str(); | 489 | dicpath1=gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "dictionaries", file).c_str(); |
483 | 490 | } | |
484 | return dicpath1; | 491 | return dicpath1; |
485 | } | 492 | } |
493 | |||
486 | void lggHunSpell_Wrapper::setNewDictionary(std::string newDict) | 494 | void lggHunSpell_Wrapper::setNewDictionary(std::string newDict) |
487 | { | 495 | { |
488 | 496 | ||
489 | llinfos << "Setting new base dictionary long name is-> " << newDict.c_str() << llendl; | 497 | llinfos << "Setting new base dictionary long name is-> " << newDict.c_str() << llendl; |
490 | 498 | ||
491 | currentBaseDic=newDict; | 499 | currentBaseDic = newDict; |
492 | 500 | ||
493 | //expecting a full name comming in | 501 | //expecting a full name comming in |
494 | newDict = fullName2DictName(newDict); | 502 | newDict = fullName2DictName(newDict); |
495 | 503 | ||
496 | if(myHunspell)delete myHunspell; | 504 | if (myHunspell) |
505 | { | ||
506 | delete myHunspell; | ||
507 | } | ||
497 | 508 | ||
498 | std::string dicaffpath=getCorrectPath(newDict+".aff"); | 509 | std::string dicaffpath = getCorrectPath(newDict+".aff"); |
499 | std::string dicdicpath=getCorrectPath(newDict+".dic"); | 510 | std::string dicdicpath = getCorrectPath(newDict+".dic"); |
500 | 511 | ||
501 | llinfos << "Setting new base dictionary -> " << dicaffpath.c_str() << llendl; | 512 | llinfos << "Setting new base dictionary -> " << dicaffpath.c_str() << llendl; |
502 | 513 | ||
503 | myHunspell = new Hunspell(dicaffpath.c_str(),dicdicpath.c_str()); | 514 | myHunspell = new Hunspell(dicaffpath.c_str(), dicdicpath.c_str()); |
504 | llinfos << "Adding custom dictionary " << llendl; | 515 | llinfos << "Adding custom dictionary " << llendl; |
505 | createCustomDic(); | 516 | createCustomDic(); |
506 | addDictionary("custom"); | 517 | addDictionary("custom"); |
507 | std::vector<std::string> toInstall = getInstalledDicts(); | 518 | std::vector<std::string> toInstall = getInstalledDicts(); |
508 | for(int i =0;i<(int)toInstall.size();i++) | 519 | for (int i = 0; i < (int)toInstall.size(); i++) |
520 | { | ||
509 | addDictionary(toInstall[i]); | 521 | addDictionary(toInstall[i]); |
510 | 522 | } | |
511 | |||
512 | } | 523 | } |
524 | |||
513 | void lggHunSpell_Wrapper::createCustomDic() | 525 | void lggHunSpell_Wrapper::createCustomDic() |
514 | { | 526 | { |
515 | std::string filename(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, | 527 | std::string filename(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", "custom.dic")); |
516 | "dictionaries", "custom.dic")); | 528 | if (!gDirUtilp->fileExists(filename)) |
517 | if(!gDirUtilp->fileExists(filename)) | ||
518 | { | 529 | { |
519 | llofstream export_file; | 530 | llofstream export_file; |
520 | export_file.open(filename); | 531 | export_file.open(filename); |
@@ -523,49 +534,67 @@ void lggHunSpell_Wrapper::createCustomDic() | |||
523 | export_file.close(); | 534 | export_file.close(); |
524 | } | 535 | } |
525 | } | 536 | } |
537 | |||
526 | void lggHunSpell_Wrapper::addWordToCustomDictionary(std::string wordToAdd) | 538 | void lggHunSpell_Wrapper::addWordToCustomDictionary(std::string wordToAdd) |
527 | { | 539 | { |
528 | if(!myHunspell)return; | 540 | if (!myHunspell) |
541 | { | ||
542 | return; | ||
543 | } | ||
544 | |||
529 | myHunspell->add(wordToAdd.c_str()); | 545 | myHunspell->add(wordToAdd.c_str()); |
530 | std::string filename(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", "custom.dic")); | 546 | std::string filename(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", "custom.dic")); |
531 | std::vector<std::string> lines; | 547 | std::vector<std::string> lines; |
532 | if(gDirUtilp->fileExists(filename)) | 548 | if (gDirUtilp->fileExists(filename)) |
533 | { | 549 | { |
534 | //get words already there.. | 550 | //get words already there.. |
535 | llifstream importer(filename); | 551 | llifstream importer(filename); |
536 | std::string line; | 552 | std::string line; |
537 | if(getline( importer, line ))//ignored the size | 553 | if (getline( importer, line ))//ignored the size |
538 | { | 554 | { |
539 | while( getline( importer, line ) ) lines.push_back(line); | 555 | while ( getline( importer, line ) ) lines.push_back(line); |
540 | } | 556 | } |
541 | importer.close(); | 557 | importer.close(); |
542 | } | 558 | } |
559 | |||
543 | llofstream export_file; | 560 | llofstream export_file; |
544 | export_file.open(filename); | 561 | export_file.open(filename); |
545 | std::string sizePart(llformat("%i",(int)(lines.size()+1))+"\n"); | 562 | std::string sizePart(llformat("%i", (int)(lines.size()+1)) + "\n"); |
546 | export_file.write(sizePart.c_str(),sizePart.length()); | 563 | export_file.write(sizePart.c_str(), sizePart.length()); |
547 | for(int i=0;i<(int)lines.size();i++) | 564 | for (int i = 0; i < (int)lines.size() ;i++) |
565 | { | ||
548 | export_file.write(std::string(lines[i]+"\n").c_str(),lines[i].length()+1); | 566 | export_file.write(std::string(lines[i]+"\n").c_str(),lines[i].length()+1); |
567 | } | ||
549 | //LLStringUtil::toLower(wordToAdd); | 568 | //LLStringUtil::toLower(wordToAdd); |
550 | wordToAdd=wordToAdd+std::string("\n"); | 569 | wordToAdd = wordToAdd+std::string("\n"); |
551 | export_file.write(wordToAdd.c_str(),wordToAdd.length()); | 570 | export_file.write(wordToAdd.c_str(), wordToAdd.length()); |
552 | //export_file << std::hex << 10 ; | 571 | //export_file << std::hex << 10 ; |
553 | export_file.close(); | 572 | export_file.close(); |
554 | } | 573 | } |
574 | |||
555 | BOOL lggHunSpell_Wrapper::isSpelledRight(std::string wordToCheck) | 575 | BOOL lggHunSpell_Wrapper::isSpelledRight(std::string wordToCheck) |
556 | { | 576 | { |
557 | if(!myHunspell)return TRUE; | 577 | if (!myHunspell || wordToCheck.length() < 3) |
558 | if(wordToCheck.length()<3)return TRUE; | 578 | { |
579 | return TRUE; | ||
580 | } | ||
559 | return myHunspell->spell(wordToCheck.c_str()); | 581 | return myHunspell->spell(wordToCheck.c_str()); |
560 | } | 582 | } |
583 | |||
561 | std::vector<std::string> lggHunSpell_Wrapper::getSuggestionList(std::string badWord) | 584 | std::vector<std::string> lggHunSpell_Wrapper::getSuggestionList(std::string badWord) |
562 | { | 585 | { |
563 | std::vector<std::string> toReturn; | 586 | std::vector<std::string> toReturn; |
564 | if(!myHunspell)return toReturn; | 587 | if (!myHunspell) |
565 | char ** suggestionList; | 588 | { |
589 | return toReturn; | ||
590 | } | ||
591 | |||
592 | char** suggestionList; | ||
566 | int numberOfSuggestions = myHunspell->suggest(&suggestionList, badWord.c_str()); | 593 | int numberOfSuggestions = myHunspell->suggest(&suggestionList, badWord.c_str()); |
567 | if(numberOfSuggestions <= 0) | 594 | if (numberOfSuggestions <= 0) |
568 | return toReturn; | 595 | { |
596 | return toReturn; | ||
597 | } | ||
569 | for (int i = 0; i < numberOfSuggestions; i++) | 598 | for (int i = 0; i < numberOfSuggestions; i++) |
570 | { | 599 | { |
571 | std::string tempSugg(suggestionList[i]); | 600 | std::string tempSugg(suggestionList[i]); |
@@ -574,14 +603,16 @@ std::vector<std::string> lggHunSpell_Wrapper::getSuggestionList(std::string badW | |||
574 | myHunspell->free_list(&suggestionList,numberOfSuggestions); | 603 | myHunspell->free_list(&suggestionList,numberOfSuggestions); |
575 | return toReturn; | 604 | return toReturn; |
576 | } | 605 | } |
606 | |||
577 | void lggHunSpell_Wrapper::debugTest(std::string testWord) | 607 | void lggHunSpell_Wrapper::debugTest(std::string testWord) |
578 | { | 608 | { |
579 | llinfos << "Testing to see if " << testWord.c_str() << " is spelled correct" << llendl; | 609 | llinfos << "Testing to see if " << testWord.c_str() << " is spelled correct" << llendl; |
580 | 610 | ||
581 | if( isSpelledRight(testWord)) | 611 | if (isSpelledRight(testWord)) |
582 | { | 612 | { |
583 | llinfos << testWord.c_str() << " is spelled correctly" << llendl; | 613 | llinfos << testWord.c_str() << " is spelled correctly" << llendl; |
584 | }else | 614 | } |
615 | else | ||
585 | { | 616 | { |
586 | llinfos << testWord.c_str() << " is not spelled correctly, getting suggestions" << llendl; | 617 | llinfos << testWord.c_str() << " is not spelled correctly, getting suggestions" << llendl; |
587 | std::vector<std::string> suggList; | 618 | std::vector<std::string> suggList; |
@@ -589,148 +620,167 @@ void lggHunSpell_Wrapper::debugTest(std::string testWord) | |||
589 | suggList = getSuggestionList(testWord); | 620 | suggList = getSuggestionList(testWord); |
590 | llinfos << "Got suggestions.. " << llendl; | 621 | llinfos << "Got suggestions.. " << llendl; |
591 | 622 | ||
592 | for(int i = 0; i<(int)suggList.size();i++) | 623 | for (int i = 0; i < (int)suggList.size(); i++) |
593 | { | 624 | { |
594 | llinfos << "Suggestion for " << testWord.c_str() << ":" << suggList[i].c_str() << llendl; | 625 | llinfos << "Suggestion for " << testWord.c_str() << ":" << suggList[i].c_str() << llendl; |
595 | } | 626 | } |
596 | |||
597 | } | 627 | } |
598 | |||
599 | } | 628 | } |
629 | |||
600 | void lggHunSpell_Wrapper::initSettings() | 630 | void lggHunSpell_Wrapper::initSettings() |
601 | { | 631 | { |
602 | glggHunSpell = new lggHunSpell_Wrapper(); | 632 | glggHunSpell = new lggHunSpell_Wrapper(); |
603 | glggHunSpell->processSettings(); | 633 | glggHunSpell->processSettings(); |
604 | } | 634 | } |
635 | |||
605 | void lggHunSpell_Wrapper::processSettings() | 636 | void lggHunSpell_Wrapper::processSettings() |
606 | { | 637 | { |
607 | //expects everything to already be in saved settings | 638 | //expects everything to already be in saved settings |
608 | //this will also reload and read the installed dicts | 639 | //this will also reload and read the installed dicts |
609 | setNewDictionary(gSavedSettings.getString("EmeraldSpellBase")); | 640 | setNewDictionary(gSavedSettings.getString("EmeraldSpellBase")); |
610 | highlightInRed= gSavedSettings.getBOOL("EmeraldSpellDisplay"); | 641 | mSpellCheckHighlight = gSavedSettings.getBOOL("EmeraldSpellDisplay"); |
611 | 642 | ||
612 | } | 643 | } |
644 | |||
613 | void lggHunSpell_Wrapper::addDictionary(std::string additionalDictionary) | 645 | void lggHunSpell_Wrapper::addDictionary(std::string additionalDictionary) |
614 | { | 646 | { |
615 | if(!myHunspell)return; | 647 | if (!myHunspell || additionalDictionary.empty()) |
616 | if(additionalDictionary=="")return; | 648 | { |
649 | return; | ||
650 | } | ||
651 | |||
617 | //expecting a full name here | 652 | //expecting a full name here |
618 | std::string dicpath=getCorrectPath(fullName2DictName(additionalDictionary)+".dic"); | 653 | std::string dicpath = getCorrectPath(fullName2DictName(additionalDictionary)+".dic"); |
619 | if(gDirUtilp->fileExists(dicpath)) | 654 | if (gDirUtilp->fileExists(dicpath)) |
620 | { | 655 | { |
621 | llinfos << "Adding additional dictionary -> " << dicpath.c_str() << llendl; | 656 | llinfos << "Adding additional dictionary -> " << dicpath.c_str() << llendl; |
622 | myHunspell->add_dic(dicpath.c_str()); | 657 | myHunspell->add_dic(dicpath.c_str()); |
623 | } | 658 | } |
624 | } | 659 | } |
660 | |||
625 | std::string lggHunSpell_Wrapper::dictName2FullName(std::string dictName) | 661 | std::string lggHunSpell_Wrapper::dictName2FullName(std::string dictName) |
626 | { | 662 | { |
627 | if(dictName==std::string(""))return std::string(""); | 663 | if (dictName.empty()) |
628 | std::string countryCode=""; | 664 | { |
629 | std::string languageCode=""; | 665 | return dictName; |
666 | } | ||
667 | |||
668 | std::string countryCode(""); | ||
669 | std::string languageCode(""); | ||
670 | |||
630 | //remove extension | 671 | //remove extension |
631 | dictName = dictName.substr(0,dictName.find(".")); | 672 | dictName = dictName.substr(0,dictName.find(".")); |
673 | |||
632 | //break it up by - or _ | 674 | //break it up by - or _ |
633 | S32 breakPoint = dictName.find("-"); | 675 | S32 breakPoint = dictName.find("-"); |
634 | if(breakPoint==std::string::npos) | 676 | if (breakPoint == std::string::npos) |
677 | { | ||
635 | breakPoint = dictName.find("_"); | 678 | breakPoint = dictName.find("_"); |
636 | if(breakPoint==std::string::npos) | 679 | } |
680 | if (breakPoint == std::string::npos) | ||
637 | { | 681 | { |
638 | //no country code given | 682 | //no country code given |
639 | languageCode=dictName; | 683 | languageCode = dictName; |
640 | }else | 684 | } |
685 | else | ||
641 | { | 686 | { |
642 | languageCode=dictName.substr(0,breakPoint); | 687 | languageCode = dictName.substr(0,breakPoint); |
643 | countryCode=dictName.substr(breakPoint+1); | 688 | countryCode = dictName.substr(breakPoint+1); |
644 | } | 689 | } |
690 | |||
645 | //get long language code | 691 | //get long language code |
646 | for(int i =0;i<LANGUAGE_CODES_RAW_SIZE;i++) | 692 | for (int i = 0; i<LANGUAGE_CODES_RAW_SIZE; i++) |
647 | { | 693 | { |
648 | if(0==LLStringUtil::compareInsensitive(languageCode,std::string(languageCodesraw[i]))) | 694 | if (0 == LLStringUtil::compareInsensitive(languageCode, std::string(languageCodesraw[i]))) |
649 | { | 695 | { |
650 | languageCode=languageCodesraw[i+1]; | 696 | languageCode = languageCodesraw[i+1]; |
651 | break; | 697 | break; |
652 | } | 698 | } |
653 | } | 699 | } |
700 | |||
654 | //get long country code | 701 | //get long country code |
655 | if(countryCode!="") | 702 | if (!countryCode.empty()) |
656 | { | 703 | { |
657 | for(int i =0;i<COUNTRY_CODES_RAW_SIZE;i++) | 704 | for (int i =0; i<COUNTRY_CODES_RAW_SIZE; i++) |
658 | { | 705 | { |
659 | //llinfos << i << llendl; | 706 | //llinfos << i << llendl; |
660 | if(0==LLStringUtil::compareInsensitive(countryCode,std::string(countryCodesraw[i]))) | 707 | if (0 == LLStringUtil::compareInsensitive(countryCode, std::string(countryCodesraw[i]))) |
661 | { | 708 | { |
662 | countryCode=countryCodesraw[i+1]; | 709 | countryCode = countryCodesraw[i+1]; |
663 | break; | 710 | break; |
664 | } | 711 | } |
665 | } | 712 | } |
666 | countryCode=" ("+countryCode+")"; | 713 | countryCode = " (" + countryCode + ")"; |
667 | } | 714 | } |
668 | 715 | ||
669 | return std::string(languageCode+countryCode); | 716 | return std::string(languageCode+countryCode); |
670 | } | 717 | } |
718 | |||
671 | std::string lggHunSpell_Wrapper::fullName2DictName(std::string fullName) | 719 | std::string lggHunSpell_Wrapper::fullName2DictName(std::string fullName) |
672 | { | 720 | { |
673 | std::string countryCode(""); | 721 | std::string countryCode(""); |
674 | std::string languageCode(""); | 722 | std::string languageCode(""); |
675 | S32 breakPoint = fullName.find(" ("); | 723 | S32 breakPoint = fullName.find(" ("); |
676 | if(breakPoint==std::string::npos) | 724 | if (breakPoint == std::string::npos) |
677 | { | 725 | { |
678 | languageCode=fullName; | 726 | languageCode = fullName; |
679 | }else | 727 | } |
728 | else | ||
680 | { | 729 | { |
681 | languageCode=fullName.substr(0,breakPoint); | 730 | languageCode = fullName.substr(0, breakPoint); |
682 | countryCode=fullName.substr(breakPoint+2,fullName.length()-3-breakPoint); | 731 | countryCode = fullName.substr(breakPoint+2, fullName.length()-3-breakPoint); |
683 | } | 732 | } |
684 | //get long language code | 733 | //get long language code |
685 | for(int i =1;i<LANGUAGE_CODES_RAW_SIZE;i+=2) | 734 | for (int i = 1; i<LANGUAGE_CODES_RAW_SIZE; i+=2) |
686 | { | 735 | { |
687 | //llinfos << i << llendl; | 736 | //llinfos << i << llendl; |
688 | if(0==LLStringUtil::compareInsensitive(languageCode,std::string(languageCodesraw[i]))) | 737 | if (0 == LLStringUtil::compareInsensitive(languageCode, std::string(languageCodesraw[i]))) |
689 | { | 738 | { |
690 | languageCode=std::string(languageCodesraw[i-1]); | 739 | languageCode = std::string(languageCodesraw[i-1]); |
691 | break; | 740 | break; |
692 | } | 741 | } |
693 | } | 742 | } |
694 | //get long country code | 743 | //get long country code |
695 | if(countryCode!="") | 744 | std::string toReturn = languageCode; |
696 | for(int i =1;i<COUNTRY_CODES_RAW_SIZE;i+=2) | 745 | if (!countryCode.empty()) |
746 | { | ||
747 | for (int i = 1; i<COUNTRY_CODES_RAW_SIZE; i+=2) | ||
697 | { | 748 | { |
698 | //llinfos << i << " comparing " <<countryCode<<" and "<<std::string(countryCodesraw[i]).c_str()<< llendl; | 749 | //llinfos << i << " comparing " <<countryCode<<" and "<<std::string(countryCodesraw[i]).c_str()<< llendl; |
699 | if(0==LLStringUtil::compareInsensitive(countryCode,std::string(countryCodesraw[i]))) | 750 | if (0 == LLStringUtil::compareInsensitive(countryCode, std::string(countryCodesraw[i]))) |
700 | { | 751 | { |
701 | countryCode=std::string(countryCodesraw[i-1]); | 752 | countryCode = std::string(countryCodesraw[i-1]); |
702 | break; | 753 | break; |
703 | } | 754 | } |
704 | } | 755 | } |
705 | std::string toReturn = languageCode; | 756 | toReturn += "_" + countryCode; |
706 | if(countryCode!="") | 757 | } |
707 | { | 758 | |
708 | toReturn+="_"+countryCode; | 759 | LLStringUtil::toLower(toReturn); |
709 | } | 760 | return toReturn; |
710 | LLStringUtil::toLower(toReturn); | ||
711 | return toReturn; | ||
712 | } | 761 | } |
762 | |||
713 | std::vector <std::string> lggHunSpell_Wrapper::getDicts() | 763 | std::vector <std::string> lggHunSpell_Wrapper::getDicts() |
714 | { | 764 | { |
715 | std::vector<std::string> names; | 765 | std::vector<std::string> names; |
716 | std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "dictionaries", "")); | 766 | std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "dictionaries", "")); |
717 | bool found = true; | 767 | bool found = true; |
718 | while(found) | 768 | while (found) |
719 | { | 769 | { |
720 | std::string name; | 770 | std::string name; |
721 | found = gDirUtilp->getNextFileInDir(path_name, "*.aff", name, false); | 771 | found = gDirUtilp->getNextFileInDir(path_name, "*.aff", name, false); |
722 | if(found) | 772 | if (found) |
723 | { | 773 | { |
724 | names.push_back(dictName2FullName(name)); | 774 | names.push_back(dictName2FullName(name)); |
725 | } | 775 | } |
726 | } | 776 | } |
727 | path_name=gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", ""); | 777 | path_name = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", ""); |
728 | found=true; | 778 | found = true; |
729 | while(found) | 779 | while (found) |
730 | { | 780 | { |
731 | std::string name; | 781 | std::string name; |
732 | found = gDirUtilp->getNextFileInDir(path_name, "*.aff", name, false); | 782 | found = gDirUtilp->getNextFileInDir(path_name, "*.aff", name, false); |
733 | if(found) | 783 | if (found) |
734 | { | 784 | { |
735 | names.push_back(dictName2FullName(name)); | 785 | names.push_back(dictName2FullName(name)); |
736 | } | 786 | } |
@@ -738,123 +788,159 @@ std::vector <std::string> lggHunSpell_Wrapper::getDicts() | |||
738 | 788 | ||
739 | return names; | 789 | return names; |
740 | } | 790 | } |
791 | |||
741 | std::vector <std::string> lggHunSpell_Wrapper::getExtraDicts() | 792 | std::vector <std::string> lggHunSpell_Wrapper::getExtraDicts() |
742 | { | 793 | { |
743 | std::vector<std::string> names; | 794 | std::vector<std::string> names; |
744 | std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "dictionaries", "")); | 795 | std::string path_name(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "dictionaries", "")); |
745 | bool found = true; | 796 | bool found = true; |
746 | while(found) | 797 | while (found) |
747 | { | 798 | { |
748 | std::string name; | 799 | std::string name; |
749 | found = gDirUtilp->getNextFileInDir(path_name, "*.dic", name, false); | 800 | found = gDirUtilp->getNextFileInDir(path_name, "*.dic", name, false); |
750 | if(found) | 801 | if (found) |
751 | { | 802 | { |
752 | names.push_back(dictName2FullName(name)); | 803 | names.push_back(dictName2FullName(name)); |
753 | } | 804 | } |
754 | } | 805 | } |
755 | path_name=gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", ""); | 806 | path_name = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", ""); |
756 | found=true; | 807 | found = true; |
757 | while(found) | 808 | while (found) |
758 | { | 809 | { |
759 | std::string name; | 810 | std::string name; |
760 | found = gDirUtilp->getNextFileInDir(path_name, "*.dic", name, false); | 811 | found = gDirUtilp->getNextFileInDir(path_name, "*.dic", name, false); |
761 | if(found) | 812 | if (found) |
762 | { | 813 | { |
763 | names.push_back(dictName2FullName(name)); | 814 | names.push_back(dictName2FullName(name)); |
764 | } | 815 | } |
765 | } | 816 | } |
766 | return names; | 817 | return names; |
767 | } | 818 | } |
819 | |||
768 | std::vector<std::string> lggHunSpell_Wrapper::getInstalledDicts() | 820 | std::vector<std::string> lggHunSpell_Wrapper::getInstalledDicts() |
769 | { | 821 | { |
770 | std::vector<std::string> toReturn; | 822 | std::vector<std::string> toReturn; |
771 | //expecting short names to be stored... | 823 | //expecting short names to be stored... |
772 | std::vector<std::string> shortNames = CSV2VEC(gSavedSettings.getString("EmeraldSpellInstalled")); | 824 | std::vector<std::string> shortNames = CSV2VEC(gSavedSettings.getString("EmeraldSpellInstalled")); |
773 | for(int i =0;i<(int)shortNames.size();i++) | 825 | for (int i =0; i < (int)shortNames.size(); i++) |
826 | { | ||
774 | toReturn.push_back(dictName2FullName(shortNames[i])); | 827 | toReturn.push_back(dictName2FullName(shortNames[i])); |
828 | } | ||
775 | return toReturn; | 829 | return toReturn; |
776 | } | 830 | } |
831 | |||
777 | std::vector<std::string> lggHunSpell_Wrapper::getAvailDicts() | 832 | std::vector<std::string> lggHunSpell_Wrapper::getAvailDicts() |
778 | { | 833 | { |
779 | std::vector<std::string> toReturn; | 834 | std::vector<std::string> toReturn; |
780 | std::vector<std::string> dics = getExtraDicts(); | 835 | std::vector<std::string> dics = getExtraDicts(); |
781 | std::vector<std::string> installedDics = getInstalledDicts(); | 836 | std::vector<std::string> installedDics = getInstalledDicts(); |
782 | for(int i =0;i<(int)dics.size();i++) | 837 | for (int i = 0; i < (int)dics.size(); i++) |
783 | { | 838 | { |
784 | bool found = false; | 839 | bool found = false; |
785 | for(int j=0;j<(int)installedDics.size();j++) | 840 | for (int j = 0; j < (int)installedDics.size(); j++) |
841 | { | ||
842 | if (0 == LLStringUtil::compareInsensitive(dics[i], installedDics[j])) | ||
843 | { | ||
844 | found = true;//this dic is already installed | ||
845 | } | ||
846 | } | ||
847 | if (0 == LLStringUtil::compareInsensitive(dics[i], currentBaseDic)) | ||
786 | { | 848 | { |
787 | if(0==LLStringUtil::compareInsensitive(dics[i],installedDics[j])) | 849 | found = true; |
788 | found=true;//this dic is already installed | 850 | } |
851 | if (0 == LLStringUtil::compareInsensitive(dics[i], "Emerald (CUSTOM)")) | ||
852 | { | ||
853 | found = true; | ||
854 | } | ||
855 | if (!found) | ||
856 | { | ||
857 | toReturn.push_back(dics[i]); | ||
789 | } | 858 | } |
790 | if(0==LLStringUtil::compareInsensitive(dics[i],currentBaseDic)) | ||
791 | found=true; | ||
792 | if(0==LLStringUtil::compareInsensitive(dics[i],"Emerald (CUSTOM)")) | ||
793 | found=true; | ||
794 | if(!found)toReturn.push_back(dics[i]); | ||
795 | } | 859 | } |
796 | return toReturn; | 860 | return toReturn; |
797 | } | 861 | } |
862 | |||
798 | std::vector<std::string> lggHunSpell_Wrapper::CSV2VEC(std::string csv) | 863 | std::vector<std::string> lggHunSpell_Wrapper::CSV2VEC(std::string csv) |
799 | { | 864 | { |
800 | std::vector<std::string> toReturn; | 865 | std::vector<std::string> toReturn; |
801 | boost::regex re(","); | 866 | boost::regex re(","); |
802 | boost::sregex_token_iterator i(csv.begin(), csv.end(), re, -1); | 867 | boost::sregex_token_iterator i(csv.begin(), csv.end(), re, -1); |
803 | boost::sregex_token_iterator j; | 868 | boost::sregex_token_iterator j; |
804 | while(i != j) | 869 | while (i != j) |
870 | { | ||
805 | toReturn.push_back(*i++); | 871 | toReturn.push_back(*i++); |
872 | } | ||
806 | return toReturn; | 873 | return toReturn; |
807 | } | 874 | } |
875 | |||
808 | std::string lggHunSpell_Wrapper::VEC2CSV(std::vector<std::string> vec) | 876 | std::string lggHunSpell_Wrapper::VEC2CSV(std::vector<std::string> vec) |
809 | { | 877 | { |
810 | std::string toReturn=""; | 878 | std::string toReturn(""); |
811 | if(vec.size()<1)return toReturn; | 879 | if (vec.size() < 1) |
812 | for(int i = 0;i<(int)vec.size();i++) | 880 | { |
813 | toReturn+=vec[i]+","; | 881 | return toReturn; |
882 | } | ||
883 | |||
884 | for (int i = 0;i < (int)vec.size() ;i++) | ||
885 | { | ||
886 | toReturn += vec[i] + ","; | ||
887 | } | ||
814 | return toReturn.erase(toReturn.length()-1); | 888 | return toReturn.erase(toReturn.length()-1); |
815 | } | 889 | } |
890 | |||
816 | void lggHunSpell_Wrapper::addButton(std::string selection) | 891 | void lggHunSpell_Wrapper::addButton(std::string selection) |
817 | { | 892 | { |
818 | if(selection=="")return; | 893 | if (selection.empty()) |
894 | { | ||
895 | return; | ||
896 | } | ||
819 | addDictionary(selection); | 897 | addDictionary(selection); |
820 | std::vector<std::string> alreadyInstalled = CSV2VEC(gSavedSettings.getString("EmeraldSpellInstalled")); | 898 | std::vector<std::string> alreadyInstalled = CSV2VEC(gSavedSettings.getString("EmeraldSpellInstalled")); |
821 | alreadyInstalled.push_back(fullName2DictName(selection)); | 899 | alreadyInstalled.push_back(fullName2DictName(selection)); |
822 | gSavedSettings.setString("EmeraldSpellInstalled",VEC2CSV(alreadyInstalled)); | 900 | gSavedSettings.setString("EmeraldSpellInstalled", VEC2CSV(alreadyInstalled)); |
823 | } | 901 | } |
902 | |||
824 | void lggHunSpell_Wrapper::removeButton(std::string selection) | 903 | void lggHunSpell_Wrapper::removeButton(std::string selection) |
825 | { | 904 | { |
826 | if(selection=="")return; | 905 | if (selection.empty()) |
906 | { | ||
907 | return; | ||
908 | } | ||
827 | std::vector<std::string> newInstalledDics; | 909 | std::vector<std::string> newInstalledDics; |
828 | std::vector<std::string> currentlyInstalled = getInstalledDicts(); | 910 | std::vector<std::string> currentlyInstalled = getInstalledDicts(); |
829 | for(int i =0;i<(int)currentlyInstalled.size();i++) | 911 | for (int i = 0; i < (int)currentlyInstalled.size(); i++) |
830 | { | 912 | { |
831 | if(0!=LLStringUtil::compareInsensitive(selection,currentlyInstalled[i])) | 913 | if (0 != LLStringUtil::compareInsensitive(selection, currentlyInstalled[i])) |
914 | { | ||
832 | newInstalledDics.push_back(fullName2DictName(currentlyInstalled[i])); | 915 | newInstalledDics.push_back(fullName2DictName(currentlyInstalled[i])); |
916 | } | ||
833 | } | 917 | } |
834 | gSavedSettings.setString("EmeraldSpellInstalled",VEC2CSV(newInstalledDics)); | 918 | gSavedSettings.setString("EmeraldSpellInstalled", VEC2CSV(newInstalledDics)); |
835 | processSettings(); | 919 | processSettings(); |
836 | } | 920 | } |
921 | |||
837 | void lggHunSpell_Wrapper::newDictSelection(std::string selection) | 922 | void lggHunSpell_Wrapper::newDictSelection(std::string selection) |
838 | { | 923 | { |
839 | currentBaseDic=selection; | 924 | currentBaseDic = selection; |
840 | gSavedSettings.setString("EmeraldSpellBase",selection); | 925 | gSavedSettings.setString("EmeraldSpellBase", selection); |
841 | //better way to do this would be to check and see if there is a installed conflict | 926 | //better way to do this would be to check and see if there is a installed conflict |
842 | //and then only remove that one.. messy | 927 | //and then only remove that one.. messy |
843 | gSavedSettings.setString("EmeraldSpellInstalled","en_sl"); | 928 | gSavedSettings.setString("EmeraldSpellInstalled", "en_sl"); |
844 | processSettings(); | 929 | processSettings(); |
845 | } | 930 | } |
846 | void lggHunSpell_Wrapper::getMoreButton(void * data) | 931 | |
932 | void lggHunSpell_Wrapper::getMoreButton(void* data) | ||
847 | { | 933 | { |
848 | std::vector<std::string> shortNames; | 934 | std::vector<std::string> shortNames; |
849 | std::vector<std::string> longNames; | 935 | std::vector<std::string> longNames; |
850 | LLSD response = LLHTTPClient::blockingGet(gSavedSettings.getString("DicDownloadBaseURL")+"dic_list.xml"); | 936 | LLSD response = LLHTTPClient::blockingGet(gSavedSettings.getString("DicDownloadBaseURL")+"dic_list.xml"); |
851 | if(response.has("body")) | 937 | if (response.has("body")) |
852 | { | 938 | { |
853 | const LLSD &dict_list = response["body"]; | 939 | const LLSD &dict_list = response["body"]; |
854 | if(dict_list.has("isComplete")) | 940 | if (dict_list.has("isComplete")) |
855 | { | 941 | { |
856 | LLSD dics = dict_list["data"]; | 942 | LLSD dics = dict_list["data"]; |
857 | for(int i = 0; i < dics.size(); i++) | 943 | for (int i = 0; i < dics.size(); i++) |
858 | { | 944 | { |
859 | std::string dicFullName = dictName2FullName(dics[i].asString()); | 945 | std::string dicFullName = dictName2FullName(dics[i].asString()); |
860 | longNames.push_back(dicFullName); | 946 | longNames.push_back(dicFullName); |
@@ -864,11 +950,12 @@ void lggHunSpell_Wrapper::getMoreButton(void * data) | |||
864 | } | 950 | } |
865 | } | 951 | } |
866 | } | 952 | } |
953 | |||
867 | void lggHunSpell_Wrapper::editCustomButton() | 954 | void lggHunSpell_Wrapper::editCustomButton() |
868 | { | 955 | { |
869 | std::string dicdicpath(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", std::string("custom.dic")).c_str()); | 956 | std::string dicdicpath(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries", std::string("custom.dic")).c_str()); |
870 | 957 | ||
871 | if(!gDirUtilp->fileExists(dicdicpath)) | 958 | if (!gDirUtilp->fileExists(dicdicpath)) |
872 | { | 959 | { |
873 | createCustomDic(); | 960 | createCustomDic(); |
874 | //glggHunSpell->addWordToCustomDictionary("temp"); | 961 | //glggHunSpell->addWordToCustomDictionary("temp"); |
@@ -877,7 +964,7 @@ void lggHunSpell_Wrapper::editCustomButton() | |||
877 | gViewerWindow->getWindow()->ShellEx(dicdicpath); | 964 | gViewerWindow->getWindow()->ShellEx(dicdicpath); |
878 | } | 965 | } |
879 | 966 | ||
880 | void lggHunSpell_Wrapper::setNewHighlightSetting( BOOL highlight ) | 967 | void lggHunSpell_Wrapper::setNewHighlightSetting(BOOL highlight) |
881 | { | 968 | { |
882 | highlightInRed=highlight; | 969 | mSpellCheckHighlight = highlight; |
883 | } | 970 | } |
diff --git a/linden/indra/newview/lgghunspell_wrapper.h b/linden/indra/newview/lgghunspell_wrapper.h index 348f479..4d07ff8 100644 --- a/linden/indra/newview/lgghunspell_wrapper.h +++ b/linden/indra/newview/lgghunspell_wrapper.h | |||
@@ -28,9 +28,9 @@ class lggHunSpell_Wrapper | |||
28 | { | 28 | { |
29 | 29 | ||
30 | public: | 30 | public: |
31 | static Hunspell * myHunspell; | 31 | static Hunspell* myHunspell; |
32 | 32 | ||
33 | BOOL highlightInRed; | 33 | BOOL mSpellCheckHighlight; |
34 | 34 | ||
35 | static void initSettings(); | 35 | static void initSettings(); |
36 | void processSettings(); | 36 | void processSettings(); |
@@ -69,6 +69,6 @@ private: | |||
69 | //std::vector<std::string> countryCodes; | 69 | //std::vector<std::string> countryCodes; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | extern lggHunSpell_Wrapper *glggHunSpell; // the singleton hunspell wrapper | 72 | extern lggHunSpell_Wrapper* glggHunSpell; // the singleton hunspell wrapper |
73 | 73 | ||
74 | #endif | 74 | #endif |