"Fossies" - the Fresh Open Source Software Archive

Member "kydpdict-0.9.5/src/kydpconfig.cpp" (3 Nov 2007, 7876 Bytes) of package /linux/privat/old/kydpdict-0.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "kydpconfig.cpp" see the Fossies "Dox" file reference documentation.

    1 /***************************************************************************
    2  *                                                                         *
    3  *   This program is free software; you can redistribute it and/or modify  *
    4  *   it under the terms of the GNU General Public License as published by  *
    5  *   the Free Software Foundation; either version 2 of the License, or     *
    6  *   (at your option) any later version.                                   *
    7  *                                                                         *
    8  ***************************************************************************/
    9 
   10 #include <stdlib.h>
   11 
   12 #include <qdir.h>
   13 #include <qfile.h>
   14 #include <qstring.h>
   15 #include <qfont.h>
   16 #include <qsettings.h>
   17 
   18 #include "kydpconfig.h"
   19 #include "engine_ydp.h"
   20 
   21 // for those qmake stubborns...
   22 #ifndef KYDPDATADIR
   23 # define KYDPDATADIR "/usr/share/kydpdict/"
   24 #endif
   25 
   26 kydpConfig::kydpConfig()
   27 {
   28     QDir dir;
   29     QFile f;
   30 
   31     cfgname = getenv("HOME_ETC");
   32     if (cfgname == "") {
   33         cfgname = getenv("HOME");
   34         cfgname += "/";
   35         cfgname += getenv("CONFIG_DIR");
   36     }
   37     cfgname += "/.kydpdict";
   38 
   39     // get rid of old config file (otherwise stuff would go to ~/.qt
   40         f.setName(cfgname);
   41         if (f.exists())
   42         f.remove();
   43 
   44     // create the directory if it doesn't exist
   45     dir.setPath(cfgname);
   46     if (!dir.exists()) {
   47         dir.mkdir(cfgname);
   48         topPath="xyz";  // notify loader to try import config
   49     }
   50     load();
   51 }
   52 
   53 kydpConfig::~kydpConfig()
   54 {
   55 
   56 }
   57 
   58 
   59 void kydpConfig::load(void)
   60 {
   61     QString transFont;
   62         int defaultEngine = ENGINE_SAP;
   63 
   64     if (topPath=="xyz") {
   65         topPath = KYDPDATADIR;
   66         cdPath = "/mnt/cdrom";
   67         player = "/usr/bin/play";
   68         if (readYDPConfig()) {
   69 
   70             // if the path was read from the config, test if it's of any use
   71                 ConvertYDP *testConvert = new ConvertYDP();
   72                 EngineYDP *testDict = new EngineYDP(this,NULL,testConvert);
   73 
   74         // if the YDP dict is not there, go back to package default
   75                 if (testDict->GetDictionaryInfo() == 0)
   76                     topPath = KYDPDATADIR;
   77         else
   78                     defaultEngine = ENGINE_YDP;
   79                 delete testDict;
   80         delete testConvert;
   81             }
   82     }
   83 
   84     QSettings settings;
   85     settings.setPath("ytm","kydpdict");
   86     settings.insertSearchPath(QSettings::Unix, cfgname);
   87 
   88     settings.beginGroup("/kydpdict");
   89     settings.beginGroup("/paths");
   90     topPath = settings.readEntry("/dictpath", topPath);
   91     cdPath  = settings.readEntry("/cd1path", cdPath);
   92     cd2Path = settings.readEntry("/cd2path", "/mnt/cdrom");
   93     player  = settings.readEntry("/player", player);
   94     engine  = settings.readNumEntry("/engine", defaultEngine);
   95     settings.endGroup();
   96     settings.beginGroup("/language");
   97     toPolish= settings.readBoolEntry("/toPolish", TRUE );
   98     language= settings.readNumEntry("/language", LANG_ENGLISH );
   99     settings.endGroup();
  100     settings.beginGroup("/visual");
  101     kGeometryX = settings.readNumEntry("/x", 1);
  102     kGeometryY = settings.readNumEntry("/y", 1);
  103     kGeometryW = settings.readNumEntry("/w", 500);
  104     kGeometryH = settings.readNumEntry("/h", 300);
  105     kMaximized = settings.readBoolEntry("/maximized", FALSE);
  106     kFontKolor1 = fixColour(settings.readEntry("/translation_text", "#C00000"));
  107     kFontKolor2 = fixColour(settings.readEntry("/describe_text", "#0000FF"));
  108     kFontKolor3 = fixColour(settings.readEntry("/example_text", "#736324"));
  109     kFontKolor4 = fixColour(settings.readEntry("/plain_text", "#000001"));
  110     kBckgrndPix = settings.readEntry("/background", "NoBackground");
  111     kBckgrndKol = fixColour(settings.readEntry("/background_colour", "#FFFFFF"));
  112     spH1 = settings.readNumEntry("/splitterH_1", 200);
  113     spH2 = settings.readNumEntry("/splitterH_2", 300);
  114     spV1 = settings.readNumEntry("/splitterV_1", 30);
  115     spV2 = settings.readNumEntry("/splitterV_2", 236);
  116     transFont = settings.readEntry("/translation_font", "Helvetica");
  117     unicodeFont = settings.readBoolEntry("/unicode_font", FALSE);
  118     toolBarVisible = settings.readBoolEntry("/toolbar_visible", TRUE);
  119     settings.endGroup();
  120     settings.beginGroup("/behavior");
  121     clipTracking = settings.readBoolEntry("/clip_tracking", TRUE);
  122     italicFont   = settings.readBoolEntry("/italic_font", FALSE);
  123     toolTips     = settings.readBoolEntry("/tool_tips", TRUE);
  124     autoPlay     = settings.readBoolEntry("/auto_play", FALSE);
  125     ignoreOwnSelection = settings.readBoolEntry("/ignore_own_selection", FALSE);
  126     dock = settings.readBoolEntry("/dock", TRUE);
  127     setFocusOnSelf = settings.readBoolEntry("/set_focus_on_self", TRUE);
  128     fuzzyDistance = settings.readNumEntry("/fuzzy_distance", 2);
  129     startHidden = settings.readBoolEntry("/start_hidden", FALSE);
  130     settings.endGroup();
  131     settings.endGroup();
  132 
  133     fontTransFont.fromString(transFont);
  134     transFont = fontTransFont.toString();
  135 }
  136 
  137 void kydpConfig::save(void)
  138 {
  139     QSettings settings;
  140     settings.setPath("ytm","kydpdict");
  141     settings.insertSearchPath(QSettings::Unix, cfgname);
  142     settings.beginGroup("/kydpdict");
  143     settings.beginGroup("/paths");
  144     settings.writeEntry("/dictpath", topPath);
  145     settings.writeEntry("/cd1path", cdPath);
  146     settings.writeEntry("/cd2path", cd2Path);
  147     settings.writeEntry("/player", player);
  148     settings.writeEntry("/engine", engine);
  149     settings.endGroup();
  150     settings.beginGroup("/language");
  151     settings.writeEntry("/toPolish", toPolish);
  152     settings.writeEntry("/language", language);
  153     settings.endGroup();
  154     settings.beginGroup("/visual");
  155     settings.writeEntry("/x", kGeometryX);
  156     settings.writeEntry("/y", kGeometryY);
  157     settings.writeEntry("/w", kGeometryW);
  158     settings.writeEntry("/h", kGeometryH);
  159     settings.writeEntry("/maximized", kMaximized);
  160     settings.writeEntry("/translation_text", fixColour(kFontKolor1));
  161     settings.writeEntry("/describe_text", fixColour(kFontKolor2));
  162     settings.writeEntry("/example_text", fixColour(kFontKolor3));
  163     settings.writeEntry("/plain_text", fixColour(kFontKolor4));
  164     settings.writeEntry("/background", kBckgrndPix);
  165     settings.writeEntry("/background_colour", fixColour(kBckgrndKol));
  166     settings.writeEntry("/splitterH_1", spH1);
  167     settings.writeEntry("/splitterH_2", spH2);
  168     settings.writeEntry("/splitterV_1", spV1);
  169     settings.writeEntry("/splitterV_2", spV2);
  170     settings.writeEntry("/translation_font", fontTransFont.toString());
  171     settings.writeEntry("/unicode_font", unicodeFont);
  172     settings.writeEntry("/toolbar_visible", toolBarVisible);
  173     settings.endGroup();
  174     settings.beginGroup("/behavior");
  175     settings.writeEntry("/clip_tracking", clipTracking);
  176     settings.writeEntry("/italic_font", italicFont);
  177     settings.writeEntry("/tool_tips", toolTips);
  178     settings.writeEntry("/auto_play", autoPlay);
  179     settings.writeEntry("/ignore_own_selection", ignoreOwnSelection);
  180     settings.writeEntry("/dock", dock);
  181     settings.writeEntry("/set_focus_on_self", setFocusOnSelf);
  182     settings.writeEntry("/fuzzy_distance", fuzzyDistance);
  183     settings.writeEntry("/start_hidden", startHidden);
  184     settings.endGroup();
  185     settings.endGroup();
  186 }
  187 
  188 bool kydpConfig::readYDPConfig(void)
  189 {
  190     QFile fd;
  191     QString line, value;
  192     int pos;
  193     bool ret = false;
  194 
  195     fd.setName("/etc/ydpdict.conf");
  196     if (!fd.exists())
  197         return ret;
  198     fd.open(IO_ReadOnly);
  199     while (!fd.atEnd()) {
  200         fd.readLine(line,128);
  201         line = line.simplifyWhiteSpace();
  202         line.truncate(line.find('#',0));
  203         if (!line.isEmpty()) {
  204             pos = line.find("CDPath");
  205             if (pos>=0) {
  206                 value = line.mid(pos+6);
  207                 cdPath = value.stripWhiteSpace();
  208             } else {
  209                 pos = line.find("Path");
  210                 if (pos>=0) {
  211                     value = line.mid(pos+4);
  212                     topPath = value.stripWhiteSpace();
  213                     ret = true;
  214                 }
  215             }
  216             pos = line.find("Player");
  217             if (pos>=0) {
  218                 value = line.mid(pos+6);
  219                 player = value.stripWhiteSpace();
  220             }
  221         }
  222     }
  223     fd.close();
  224     return ret;
  225 }
  226 
  227 // this is here due to fact that if link's colour is set to black, Qt ignores that
  228 // and uses default blue instead
  229 QString kydpConfig::fixColour(const QString colour)
  230 {
  231     if (colour == "#000000") {
  232     return "#000001";
  233     }
  234     else
  235     return colour;
  236 }