Changeset 262


Ignore:
Timestamp:
07/13/09 20:46:26 (3 years ago)
Author:
antonbatenev.ya.ru
Message:

Начало работы над проверкой орфографии

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/dev/avalon.mysql.000.sql

    r214 r262  
    4343( 
    4444        'version', 
    45         'v1.0rc1, patch avalon.000.sql' 
     45        'v1.0rc2, patch avalon.000.sql' 
    4646); 
    4747 
  • trunk/dev/build.sh

    r248 r262  
    5555        fi 
    5656 
    57         ${QT_PATH}/bin/qmake -project -recursive -Wall -o ${PROJECT_NAME}.pro "QT += network sql webkit" "CONFIG += debug" 
     57        ${QT_PATH}/bin/qmake -project -recursive -Wall -o ${PROJECT_NAME}.pro "QT += network sql webkit" "CONFIG += debug" "LIBS += -laspell" 
    5858 
    5959        touch "debug.out" 
     
    6666        fi 
    6767 
    68         ${QT_PATH}/bin/qmake -project -recursive -Wall -o ${PROJECT_NAME}.pro "QT += network sql webkit" 
     68        ${QT_PATH}/bin/qmake -project -recursive -Wall -o ${PROJECT_NAME}.pro "QT += network sql webkit" "LIBS += -laspell" 
    6969 
    7070        touch "release.out" 
  • trunk/form_message.cpp

    r247 r262  
    1414FormMessage::FormMessage (QWidget* parent, bool is_reply, const AMessageInfoGUI& info, int edit_id) :  FormMessageUI (parent) 
    1515{ 
     16        #ifdef AVALON_USE_ASPELL 
     17 
     18        m_aspell_speller_en = NULL; 
     19        m_aspell_speller_ru = NULL; 
     20 
     21        m_aspell_config_en = new_aspell_config(); 
     22        m_aspell_config_ru = NULL; 
     23 
     24        if (m_aspell_config_en != NULL) 
     25        { 
     26                // 
     27                // спеллер английского языка 
     28                // 
     29 
     30                bool fail = false; 
     31 
     32                if (aspell_config_replace(m_aspell_config_en, "lang", "en_US") == FALSE) 
     33                { 
     34                        QMessageBox::critical(parent, QString::fromUtf8("Ошибка!"), QString("Aspell error: ") + QString(aspell_config_error_message(m_aspell_config_en))); 
     35                        fail = true; 
     36                } 
     37 
     38                if (fail == false && aspell_config_replace(m_aspell_config_en, "encoding", "utf-8") == FALSE) 
     39                { 
     40                        QMessageBox::critical(parent, QString::fromUtf8("Ошибка!"), QString("Aspell error: ") + QString(aspell_config_error_message(m_aspell_config_en))); 
     41                        fail = true; 
     42                } 
     43 
     44                if (fail == false) 
     45                { 
     46                        AspellCanHaveError* possible_err = new_aspell_speller(m_aspell_config_en); 
     47 
     48                        if (aspell_error_number(possible_err) != 0) 
     49                        { 
     50                                QMessageBox::critical(parent, QString::fromUtf8("Ошибка!"), QString("Aspell error: ") + QString(aspell_error_message(possible_err))); 
     51                                fail = true; 
     52                        } 
     53                        else 
     54                                m_aspell_speller_en = to_aspell_speller(possible_err); 
     55                } 
     56 
     57                // 
     58                // Спеллер русского языка 
     59                // 
     60 
     61                if (fail == false) 
     62                { 
     63                        m_aspell_config_ru = aspell_config_clone(m_aspell_config_en); 
     64 
     65                        if (m_aspell_config_ru != NULL) 
     66                        { 
     67                                if (aspell_config_replace(m_aspell_config_ru, "lang", "ru_RU") == FALSE) 
     68                                { 
     69                                        QMessageBox::critical(parent, QString::fromUtf8("Ошибка!"), QString("Aspell error: ") + QString(aspell_config_error_message(m_aspell_config_ru))); 
     70                                        fail = true; 
     71                                } 
     72 
     73                                if (fail == false && aspell_config_replace(m_aspell_config_ru, "encoding", "utf-8") == FALSE) 
     74                                { 
     75                                        QMessageBox::critical(parent, QString::fromUtf8("Ошибка!"), QString("Aspell error: ") + QString(aspell_config_error_message(m_aspell_config_ru))); 
     76                                        fail = true; 
     77                                } 
     78 
     79                                if (fail == false) 
     80                                { 
     81                                        AspellCanHaveError* possible_err = new_aspell_speller(m_aspell_config_ru); 
     82 
     83                                        if (aspell_error_number(possible_err) != 0) 
     84                                        { 
     85                                                QMessageBox::critical(parent, QString::fromUtf8("Ошибка!"), QString("Aspell error: ") + QString(aspell_error_message(possible_err))); 
     86                                                fail = true; 
     87                                        } 
     88                                        else 
     89                                                m_aspell_speller_ru = to_aspell_speller(possible_err); 
     90                                } 
     91 
     92                        }   // if (m_aspell_config_ru != NULL) 
     93 
     94                }   // if (fail == false) 
     95 
     96        }   // if (m_aspell_config_en != NULL) 
     97 
     98        #endif   // #ifdef AVALON_USE_ASPELL 
     99 
    16100        if (edit_id != 0) 
    17101                is_reply = false; 
     
    147231        connect(m_text_subject, SIGNAL(textChanged(const QString&)), this, SLOT(text_subject_text_changed(const QString&))); 
    148232        connect(m_tab_message,  SIGNAL(currentChanged(int)),         this, SLOT(tab_changed(int))); 
     233 
     234        #ifdef AVALON_USE_ASPELL 
     235 
     236        m_aspell_timer = NULL; 
     237 
     238        if (m_aspell_speller_en != NULL && m_aspell_speller_ru != NULL) 
     239        { 
     240                m_aspell_timer = new QTimer(this); 
     241                m_aspell_timer->setInterval(1000); 
     242                m_aspell_timer->setSingleShot(true); 
     243 
     244                connect(m_aspell_timer, SIGNAL(timeout()),     this, SLOT(aspell_timer_on_timer())); 
     245                connect(m_text_source,  SIGNAL(textChanged()), this, SLOT(text_source_text_changed())); 
     246        } 
     247 
     248        #endif 
    149249} 
    150250//---------------------------------------------------------------------------------------------- 
     
    152252FormMessage::~FormMessage () 
    153253{ 
     254        #ifdef AVALON_USE_ASPELL 
     255        delete_aspell_speller(m_aspell_speller_en); 
     256        delete_aspell_speller(m_aspell_speller_ru); 
     257        delete_aspell_config(m_aspell_config_en); 
     258        delete_aspell_config(m_aspell_config_ru); 
     259        #endif 
    154260} 
    155261//---------------------------------------------------------------------------------------------- 
     
    307413} 
    308414//---------------------------------------------------------------------------------------------- 
     415 
     416#ifdef AVALON_USE_ASPELL 
     417void FormMessage::text_source_text_changed () 
     418{ 
     419        if (m_aspell_timer != NULL) 
     420        { 
     421                m_aspell_timer->stop(); 
     422                m_aspell_timer->start(); 
     423        } 
     424} 
     425#endif 
     426//---------------------------------------------------------------------------------------------- 
     427 
     428#ifdef AVALON_USE_ASPELL 
     429void FormMessage::aspell_timer_on_timer () 
     430{ 
     431/* 
     432        QString text = m_text_source->toPlainText(); 
     433 
     434        QRegExp word_regexp("(\\c+|(\\c+\\-\\c+))"); 
     435 
     436        int pos = 0; 
     437 
     438        while ((pos = word_regexp.indexIn(text, pos)) != -1) 
     439        { 
     440                int len = word_regexp.matchedLength(); 
     441                QString word = text.mid(pos, len); 
     442                pos += len; 
     443 
     444                DEBUG_MSG(word); 
     445        } 
     446*/ 
     447 
     448/* 
     449        QString text = m_text_source->toPlainText(); 
     450        QString word = ""; 
     451 
     452        for (int i = 0; i < text.length(); i++) 
     453        { 
     454                QChar ch = text[i]; 
     455 
     456                if (ch == ' ' || ch == '\n') 
     457                { 
     458                        if (word.length() > 0) 
     459                        { 
     460                                QByteArray data = word.toUtf8(); 
     461 
     462                                int correct = aspell_speller_check(m_aspell_speller, data.data(), data.length()); 
     463 
     464                                if (correct == -1) 
     465                                { 
     466                                        unsigned int err_num = aspell_speller_error_number(m_aspell_speller); 
     467                                        const char*  err_msg = aspell_speller_error_message(m_aspell_speller); 
     468 
     469                                        QString error = QString("Aspell error: [") + QString::number(err_num) + "] " + QString(err_msg); 
     470 
     471                                        QMessageBox::critical(this, QString::fromUtf8("Ошибка!"), error); 
     472                                } 
     473                                else 
     474                                { 
     475                                        QString result; 
     476                                        if (correct == 1) 
     477                                                result = word + " - OK"; 
     478                                        else 
     479                                                result = word + " - Error"; 
     480                                        DEBUG_MSG(result); 
     481                                        //QTextCursor cursor = 
     482                                } 
     483 
     484                                word = ""; 
     485                        } 
     486                } 
     487                else 
     488                        word = word + ch; 
     489        } 
     490 
     491        QTextCharFormat char_format = m_text_source->currentCharFormat(); 
     492        char_format.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline); 
     493        char_format.setUnderlineColor(Qt::red); 
     494        m_text_source->setCurrentCharFormat(char_format); 
     495*/ 
     496} 
     497#endif 
     498//---------------------------------------------------------------------------------------------- 
  • trunk/form_message.h

    r207 r262  
    6767                int m_edit_id; 
    6868 
     69                #ifdef AVALON_USE_ASPELL 
     70 
     71                AspellConfig*  m_aspell_config_en;  /*!< \brief Конфиг aspell для проверки английского  */ 
     72                AspellConfig*  m_aspell_config_ru;  /*!< \brief Конфиг aspell для проверки русского     */ 
     73 
     74                AspellSpeller* m_aspell_speller_en; /*!< \brief Спеллер aspell для проверки английского */ 
     75                AspellSpeller* m_aspell_speller_ru; /*!< \brief Спеллер aspell для проверки русского    */ 
     76 
     77                QTimer*        m_aspell_timer;      /*!< \brief Таймер для проверки (чтобы не грузить)  */ 
     78 
     79                #endif 
     80 
    6981                /*! 
    7082                 * \brief Событие закрытия формы (см. Qt::QDialog). 
     
    100112                void text_subject_text_changed (const QString& text); 
    101113 
     114                #ifdef AVALON_USE_ASPELL 
     115                /*! 
     116                 * \brief Смена текста 
     117                 */ 
     118                void text_source_text_changed (); 
     119 
     120                /*! 
     121                 * \brief Таймер проверки 
     122                 */ 
     123                void aspell_timer_on_timer (); 
     124                #endif 
     125 
    102126                /*! 
    103127                 * \brief Событие клика по линку 
  • trunk/sysheaders.h

    r258 r262  
    8080// возможность сжатия тел сообщений 
    8181#define AVALON_USE_ZLIB 
    82  
    8382#ifdef AVALON_USE_ZLIB 
    8483        #include <zlib.h> 
    8584#endif 
    8685 
     86// проверка орфографии 
     87#define AVALON_USE_ASPELL 
     88#ifdef AVALON_USE_ASPELL 
     89        #include <aspell.h> 
     90#endif 
     91 
    8792/*! 
    8893 * \brief Получение строки версии (см. version.cpp) 
    89  * \return Строка версии вида "avalon 1.0b rev NNN" 
     94 * \return Строка версии вида "avalon 1.0rc2 rev NNN" 
    9095 */ 
    9196QString getVersionString (); 
  • trunk/version.h

    r261 r262  
    2020 * \brief Дата билда (заменяется автоматически при каждом билде в version.h, что и приводит к смене номера ревизии) 
    2121 */ 
    22 #define AVALON_DATE "Пнд Июл 13 16:37:12 MSD 2009" 
     22#define AVALON_DATE "Пнд Июл 13 20:44:51 MSD 2009" 
    2323 
    2424#endif 
Note: See TracChangeset for help on using the changeset viewer.