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

odict.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 "odict.h"
00018 #include "configdlg.h"
00019 #include "dingwidget.h"
00020 
00021 #include <opie2/oresource.h>
00022 
00023 #include <qpe/config.h>
00024 
00025 #include <qmenubar.h>
00026 #include <qmessagebox.h>
00027 #include <qvbox.h>
00028 #include <qlabel.h>
00029 #include <qpushbutton.h>
00030 #include <qlineedit.h>
00031 #include <qaction.h>
00032 #include <qtextbrowser.h>
00033 #include <qcombobox.h>
00034 
00035 ODict::ODict(QWidget* parent, const char* name, WFlags fl ) : QMainWindow(parent,  name, fl )
00036 {
00037         activated_name = QString::null;
00038 
00039         vbox = new QVBox( this );
00040         setCaption( tr( "Opie-Dictionary" ) );
00041         setupMenus();
00042 
00043         QHBox *hbox = new QHBox( vbox );
00044         QLabel* query_label = new QLabel( tr( "Query:" ) , hbox );
00045         query_label->show();
00046         query_le = new QLineEdit( hbox );
00047         query_co = new QComboBox( hbox );
00048         connect( query_co , SIGNAL( activated(const QString&) ), this, SLOT( slotMethodChanged(const QString&) ) );
00049         ok_button = new QPushButton( tr( "&Ok" ), hbox );
00050         connect( ok_button, SIGNAL( released() ), this, SLOT( slotStartQuery() ) );
00051 
00052         top_name = new QLabel( vbox );
00053         top_name->setAlignment( AlignHCenter );
00054         browser_top = new QTextBrowser( vbox );
00055         bottom_name = new QLabel( vbox );
00056         bottom_name->setAlignment( AlignHCenter );
00057         browser_bottom = new QTextBrowser( vbox );
00058 
00059         ding = new DingWidget();
00060 
00061         loadConfig();
00062         setCentralWidget( vbox );
00063 }
00064 
00065 void ODict::loadConfig()
00066 {
00067         /*
00068          * the name of the last used dictionary
00069          */
00070         QString lastname;
00071 
00072         Config cfg ( "odict" );
00073         cfg.setGroup( "generalsettings" );
00074         casesens = cfg.readEntry( "casesens" ).toInt();
00075 
00076         QString lastDict = cfg.readEntry( "lastdict" );
00077         int i = 0, e = 0;
00078 
00079         QStringList groupListCfg = cfg.groupList().grep( "Method_" );
00080         query_co->clear();
00081         for ( QStringList::Iterator it = groupListCfg.begin() ; it != groupListCfg.end() ; ++it )
00082         {
00083                 QString name;
00084                 cfg.setGroup( *it );
00085                 name = cfg.readEntry( "Name" );
00086                 if ( name != QString::null ) {
00087                         query_co->insertItem( name );
00088                 }
00089 
00090                 /*
00091                  * this check is to look up what dictionary has been used the
00092                  * last time
00093                  */
00094                 if ( lastDict == name )
00095                 {
00096                         e = i;
00097                         lastname = name;
00098                 }
00099                 i++;
00100         }
00101         /*
00102          * now set the two names of the dictionary and the correct QComboBox-Entry
00103          */
00104 
00105         lookupLanguageNames( lastname );
00106         ding->loadDict( lastname );
00107         ding->loadValues();
00108 
00109         query_co->setCurrentItem( e );
00110         top_name->setText( top_name_content );
00111         bottom_name->setText( bottom_name_content );
00112 }
00113 
00114 void ODict::lookupLanguageNames( QString dictname )
00115 {
00116         Config cfg ( "odict" );
00117         cfg.setGroup( "Method_"+dictname );
00118         top_name_content = cfg.readEntry( "Lang1" );
00119         bottom_name_content = cfg.readEntry( "Lang2" );
00120 }
00121 
00122 void ODict::saveConfig()
00123 {
00124         Config cfg ( "odict" );
00125         cfg.setGroup( "generalsettings" );
00126         cfg.writeEntry( "casesens" , casesens );
00127         cfg.writeEntry( "lastdict" , query_co->currentText() );
00128 }
00129 
00130 void ODict::slotStartQuery()
00131 {
00132         QString querystring = query_le->text();
00133         if ( !querystring.isEmpty() )
00134         {
00135                 /*
00136                  * if the user has not yet defined a dictionary
00137                  */
00138                 if ( !query_co->currentText() )
00139                 {
00140                         switch (  QMessageBox::information(  this, tr( "OPIE-Dictionary" ),
00141                                                 tr( "No dictionary defined" ),
00142                                                 tr( "&Define one" ),
00143                                                 tr( "&Cancel" ),
00144                                                 0,      // Define a dict
00145                                                 1 ) )   // Cancel choosen
00146                         {
00147                                 case 0:
00148                                         slotSettings();
00149                                         break;
00150                                 case 1: // stop here
00151                                         return;
00152                         }
00153                 }
00154 
00155                 /*
00156                  * ok, the user has defined a dict
00157                  */
00158                 ding->setCaseSensitive( casesens );
00159 
00160                 BroswerContent test = ding->setText( querystring );
00161 
00162                 browser_top->setText( test.top );
00163                 browser_bottom->setText( test.bottom );
00164         }
00165 }
00166 
00167 void ODict::slotSettings()
00168 {
00169         ConfigDlg dlg( this, "Config" , true);
00170         if ( dlg.exec() == QDialog::Accepted )
00171                 saveConfig();
00172 }
00173 
00174 void ODict::slotSetParameter( int count )
00175 {
00176         if ( count == 0 )
00177         {
00178                 if ( casesens )
00179                         casesens = false;
00180                 else
00181                         casesens = true;
00182         }
00183 
00184         saveConfig();
00185 }
00186 
00187 void ODict::slotMethodChanged( const QString& methodnumber )
00188 {
00189         activated_name =  methodnumber;
00190 
00191         if ( activated_name != ding->loadedDict() )
00192         {
00193                 ding->loadDict(activated_name);
00194 
00195                 lookupLanguageNames( activated_name );
00196                 top_name->setText( top_name_content );
00197                 bottom_name->setText( bottom_name_content );
00198         }
00199 }
00200 
00201 void ODict::setupMenus()
00202 {
00203         menu = new QMenuBar( this );
00204 
00205         settings = new QPopupMenu( menu );
00206     setting_a = new QAction( tr( "Configuration" ),
00207                              Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ),
00208                              QString::null, 0, this, 0 );
00209         connect( setting_a, SIGNAL( activated() ), this, SLOT( slotSettings() ) );
00210         setting_a->addTo( settings );
00211         setting_b = new QAction( tr( "Search methods" ),
00212                              Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ),
00213                              QString::null, 0, this, 0 );
00214 
00215         parameter = new QPopupMenu( menu );
00216         connect(  parameter, SIGNAL( activated(int) ), this, SLOT( slotSetParameter(int) ) );
00217         parameter->insertItem( tr( "Case sensitive" ), 0 ,0 );
00218 
00219         menu->insertItem( tr( "Settings" ) , settings );
00220         menu->insertItem( tr( "Parameter" ) , parameter );
00221 }

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