Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

dingwidget.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002    application:             : ODict
00003 
00004    begin                    : December 2002
00005    copyright                : ( C ) 2002, 2003 by Carsten Niehaus
00006    email                    : cniehaus@handhelds.org
00007  **************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  * This program is free software; you can redistribute it and/or modify    *
00012  * it under the terms of the GNU General Public License as published by    *
00013  * the Free Software Foundation; either version 2 of the License, or       *
00014  * ( at your option ) any later version.                                   *
00015  *                                                                         *
00016  **************************************************************************/
00017 #include "dingwidget.h"
00018 
00019 #include <qfile.h>
00020 #include <qpe/config.h>
00021 #include <qtextstream.h>
00022 
00023 DingWidget::DingWidget( )
00024 {
00025         methodname = QString::null;
00026         trenner = QString::null;
00027         lines = 0L;
00028 }
00029 
00030 void DingWidget::loadDict( QString name )
00031 {
00032         lines.clear(); //as we will load a new list we have to
00033                        //remove the old one
00034         
00035         Config cfg(  "odict" );
00036         cfg.setGroup( "Method_" + name );
00037         QFile file( cfg.readEntry( "file" )  );
00038 
00039         if(  file.open(  IO_ReadOnly ) )
00040         {
00041                 QTextStream stream(  &file );
00042                 stream.setEncoding(QTextStream::UnicodeUTF8);           
00043                 while ( !stream.eof() )
00044                 {
00045                         lines.append(  stream.readLine() );
00046                 }
00047                 file.close();
00048         }
00049 
00050         setDict( name );
00051 
00052         loadValues();
00053 }
00054 
00055 QString DingWidget::loadedDict() const
00056 { 
00057         return dictName;
00058 }
00059 
00060 void DingWidget::setCaseSensitive( bool caseS )
00061 {
00062         isCaseSensitive = caseS;
00063 }
00064 
00065 void DingWidget::setDict( QString dict )
00066 {
00067         methodname = dict;
00068 }
00069 
00070 void DingWidget::setQueryWord( QString qword )
00071 {
00072         queryword = qword;
00073 }
00074 
00075 
00076 void DingWidget::loadValues()
00077 {
00078         if ( !methodname ) return;
00079         Config cfg(  "odict" );
00080         cfg.setGroup( "Method_" + methodname );
00081         trenner = cfg.readEntry( "Seperator" );
00082         
00083         lang1_name = cfg.readEntry( "Lang1" );
00084         lang2_name = cfg.readEntry( "Lang2" );
00085 }
00086 
00087 BroswerContent DingWidget::setText( QString word )
00088 {
00089         queryword = word;
00090         return parseInfo();
00091 }
00092 
00093 
00094 BroswerContent DingWidget::parseInfo()
00095 {
00096         QStringList search = lines.grep( queryword , isCaseSensitive );
00097 
00098         QString current;
00099         QString left;
00100         QString right;
00101         QRegExp reg_div( trenner );
00102         QRegExp reg_word( queryword );
00103         reg_word.setCaseSensitive( isCaseSensitive );
00104         QStringList toplist, bottomlist;
00105         QString substitute = "<strong>"+queryword+"</strong>";
00106 
00107         for( QStringList::Iterator it = search.begin() ; it != search.end() ; ++it )
00108         {
00109                 current = *it;
00110                 left = current.left( current.find( trenner ) );
00111         
00112                 right = current.right( current.length() - current.find(trenner) - trenner.length() );
00113 
00114                 if ( left.contains( queryword , isCaseSensitive ) )
00115                 {
00116                         left.replace( queryword, substitute );
00117                         left = left + " --> " + right;
00118                         toplist.append( left );
00119                 }
00120                 else if( right.contains( queryword , isCaseSensitive ) )
00121                 {
00122                         right.replace( queryword, substitute );
00123                         right = right + " --> " + left;
00124                         bottomlist.append( right );
00125                 }
00126         }
00127 
00128         s_strings.top = toplist.join( "<br>" );
00129         s_strings.bottom = bottomlist.join( "<br>" );
00130         
00131         return s_strings;
00132 }
00133 

Generated on Sat Nov 5 16:16:48 2005 for OPIE by  doxygen 1.4.2