"Fossies" - the Fresh Open Source Software Archive

Member "tipograf-0.5/src/tipografImplConfig.cc" (13 Dec 2003, 27545 Bytes) of package /linux/privat/old/tipograf-0.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.

    1 #include <stdlib.h>
    2 #include <stdio.h>
    3 
    4 #include <qcombobox.h>
    5 #include <qlabel.h>
    6 #include <qlineedit.h>
    7 #include <qcheckbox.h>
    8 #include <qradiobutton.h>
    9 #include <qspinbox.h>
   10 #include <qfiledialog.h>
   11 #include <qmessagebox.h>
   12 #include <qslider.h>
   13 #include <qgroupbox.h>
   14 #include <qtabwidget.h>
   15 #include <qtextbrowser.h>
   16 #include <qbuttongroup.h>
   17 #include <qfile.h>
   18 #include <qtextstream.h>
   19 #include <qstylefactory.h>
   20 
   21 #include <config.h>
   22 
   23 #include "tipografImpl.h"
   24 #include "init.h"
   25 
   26 // ============================================================
   27 // Config file functions.
   28 // These relate to config files that hold printing
   29 // control values like font size and so on. They save / load
   30 // the values of all but the Tipo tab.
   31 // See loadTipo / saveTipo for I/O to ~/.tipografrc.
   32 // ============================================================
   33 
   34 void tipografImpl::loadConfig()
   35 {
   36   // Prepare file and error objects.
   37   QFile configFile(leConfig->text());
   38   QString parseErrIntro = tr("The following errors occured:\n\n");
   39   QString parseErr      = "";
   40 
   41   // Check config file.
   42   if(!configFile.exists()) {
   43     QMessageBox::warning(this,
   44              tr("Load configuration"),
   45              tr("The configuration file you are\n"
   46                 "trying to load does not exist."),
   47              QMessageBox::Ok,
   48              0);
   49     return;
   50   }
   51   
   52   if(!configFile.open(IO_ReadOnly)) {
   53     QMessageBox::warning(this,
   54              tr("Load configuration"),
   55              tr("Unable to open file for reading."),
   56              QMessageBox::Ok,
   57              0);
   58     return;
   59   }
   60   
   61   // Read in configuration.
   62   QTextStream s(&configFile);
   63   QString l;
   64   int equalPos = 0;
   65   int convInt = 0;
   66   bool convOk = false;
   67 
   68   while(!s.eof()) {
   69     l = s.readLine();
   70     if(l.contains("=")) {
   71       equalPos = l.find("=");
   72 
   73       // Input / output tab.
   74       if(l.contains("leInput")) {
   75     l = l.remove(0, equalPos+1);
   76     leInput->setText(l);
   77       }
   78       if(l.contains("leOutput")) {
   79     l = l.remove(0, equalPos+1);
   80     leOutput->setText(l);
   81       }
   82       if(l.contains("cbStdStyle")) {
   83     l = l.remove(0, equalPos+1);
   84     convInt = l.toInt(&convOk, 10);
   85     if(convOk == true) {
   86       if(cbStdStyle->count() > convInt && convInt >= 0) {
   87         cbStdStyle->setCurrentItem(convInt);
   88       } else {
   89         parseErr += tr("Standard style index is out of range.\n");
   90       }
   91     } else {
   92       parseErr += tr("Standard style index is not a number.\n");
   93     }
   94       }
   95       if(l.contains("cbOutputTo")) {
   96     l = l.remove(0, equalPos+1);
   97     convInt = l.toInt(&convOk, 10);
   98     if(convOk == true) {
   99       if(cbOutputTo->count() > convInt && convInt >= 0) {
  100         cbOutputTo->setCurrentItem(convInt);
  101       } else {
  102         parseErr += tr("Output to index is out of range.\n");
  103       }
  104     } else {
  105       parseErr += tr("Output to index is not a number.\n");
  106     }
  107       }
  108       if(l.contains("cbPrinter")) {
  109     l = l.remove(0, equalPos+1);
  110     convInt = l.toInt(&convOk, 10);
  111     if(convOk == true) {
  112       if(cbPrinter->count() > convInt && convInt >= 0) {
  113         cbPrinter->setCurrentItem(convInt);
  114       } else {
  115         parseErr += tr("Printer index is out of range.\n");
  116       }
  117     } else {
  118       parseErr += tr("Printer index is not a number.\n");
  119     }
  120       }
  121       if(l.contains("cbSimpleOptionsDisable")) {
  122     l = l.remove(0, equalPos+1);
  123     convInt = l.toInt(&convOk, 10);
  124     if(convOk == true) {
  125       switch(convInt) {
  126       case 0:
  127         cbSimpleOptionsDisable->setChecked(false);
  128         break;
  129       case 1:
  130         cbSimpleOptionsDisable->setChecked(true);
  131         break;
  132       default:
  133         parseErr += tr("Simple options disable value needs to be either one or zero.\n");
  134       }
  135     } else {
  136       parseErr += tr("Simple options disable value is not a number.\n");
  137     }
  138       }
  139       if(l.contains("rbSimpleOptionPortrait")) {
  140     l = l.remove(0, equalPos+1);
  141     convInt = l.toInt(&convOk, 10);
  142     if(convOk == true) {
  143       switch(convInt) {
  144       case 0:
  145         rbSimpleOptionPortrait->setChecked(false);
  146         break;
  147       case 1:
  148         rbSimpleOptionPortrait->setChecked(true);
  149         break;
  150       default:
  151         parseErr += tr("Simple option portrait value needs to be either one or zero.\n");
  152       }
  153     } else {
  154       parseErr += tr("Simple option portrait value is not a number.\n");
  155     }
  156       }
  157       if(l.contains("rbSimpleOptionLandscape")) {
  158     l = l.remove(0, equalPos+1);
  159     convInt = l.toInt(&convOk, 10);
  160     if(convOk == true) {
  161       switch(convInt) {
  162       case 0:
  163         rbSimpleOptionLandscape->setChecked(false);
  164         break;
  165       case 1:
  166         rbSimpleOptionLandscape->setChecked(true);
  167         break;
  168       default:
  169         parseErr += tr("Simple option landscape value needs to be either one or zero.\n");
  170       }
  171     } else {
  172       parseErr += tr("Simple option landscape value is not a number.\n");
  173     }
  174       }
  175       if(l.contains("cbSimpleOptionLineNumbers")) {
  176     l = l.remove(0, equalPos+1);
  177     convInt = l.toInt(&convOk, 10);
  178     if(convOk == true) {
  179       switch(convInt) {
  180       case 0:
  181         cbSimpleOptionLineNumbers->setChecked(false);
  182         break;
  183       case 1:
  184         cbSimpleOptionLineNumbers->setChecked(true);
  185         break;
  186       default:
  187         parseErr += tr("Simple option line numbers value needs to be either one or zero.\n");
  188       }
  189     } else {
  190       parseErr += tr("Simple option line numbers value is not a number.\n");
  191     }
  192       }
  193       if(l.contains("cbSimpleOptionColored")) {
  194     l = l.remove(0, equalPos+1);
  195     convInt = l.toInt(&convOk, 10);
  196     if(convOk == true) {
  197       switch(convInt) {
  198       case 0:
  199         cbSimpleOptionColored->setChecked(false);
  200         break;
  201       case 1:
  202         cbSimpleOptionColored->setChecked(true);
  203         break;
  204       default:
  205         parseErr += tr("Simple option colored value needs to be either one or zero.\n");
  206       }
  207     } else {
  208       parseErr += tr("Simple option colored value is not a number.\n");
  209     }
  210       }
  211       if(l.contains("sbSimpleOptionFontSize")) {
  212     l = l.remove(0, equalPos+1);
  213     convInt = l.toInt(&convOk, 10);
  214     if(convOk == true) {
  215       if(sbSimpleOptionFontSize->minValue() <= convInt && convInt <= sbSimpleOptionFontSize->maxValue()) {
  216         sbSimpleOptionFontSize->setValue(convInt);
  217       } else {
  218         parseErr += tr("Simple option font size value is out of range.\n");
  219       }
  220     } else {
  221       parseErr += tr("Simple option font size value is not a number.\n");
  222     }
  223       }
  224 
  225       // Paper tab.
  226       if(l.contains("cbOrientation")) {
  227     l = l.remove(0, equalPos+1);
  228     convInt = l.toInt(&convOk, 10);
  229     if(convOk == true) {
  230       if(cbOrientation->count() > convInt && convInt >= 0) {
  231         cbOrientation->setCurrentItem(convInt);
  232       } else {
  233         parseErr += tr("Orientation index is out of range.\n");
  234       }
  235     } else {
  236       parseErr += tr("Orientation index is not a number.\n");
  237     }
  238       }
  239       if(l.contains("cbFormat")) {
  240     l = l.remove(0, equalPos+1);
  241     convInt = l.toInt(&convOk, 10);
  242     if(convOk == true) {
  243       if(cbFormat->count() > convInt && convInt >= 0) {
  244         cbFormat->setCurrentItem(convInt);
  245       } else {
  246         parseErr += tr("Format index is out of range.\n");
  247       }
  248     } else {
  249       parseErr += tr("Format index is not a number.\n");
  250     }
  251       }
  252       if(l.contains("cbDirection")) {
  253     l = l.remove(0, equalPos+1);
  254     convInt = l.toInt(&convOk, 10);
  255     if(convOk == true) {
  256       if(cbDirection->count() > convInt && convInt >= 0) {
  257         cbDirection->setCurrentItem(convInt);
  258       } else {
  259         parseErr += tr("Direction index is out of range.\n");
  260       }
  261     } else {
  262       parseErr += tr("Direction index is not a number.\n");
  263     }
  264       }
  265       if(l.contains("cbDuplex")) {
  266     l = l.remove(0, equalPos+1);
  267     convInt = l.toInt(&convOk, 10);
  268     if(convOk == true) {
  269       if(cbDuplex->count() > convInt && convInt >= 0) {
  270         cbDuplex->setCurrentItem(convInt);
  271       } else {
  272         parseErr += tr("Duplex index is out of range.\n");
  273       }
  274     } else {
  275       parseErr += tr("Duplex index is not a number.\n");
  276     }
  277       }
  278       if(l.contains("sbRows")) {
  279     l = l.remove(0, equalPos+1);
  280     convInt = l.toInt(&convOk, 10);
  281     if(convOk == true) {
  282       if(sbRows->minValue() <= convInt && convInt <= sbRows->maxValue()) {
  283         sbRows->setValue(convInt);
  284       } else {
  285         parseErr += tr("Rows value is out of range.\n");
  286       }
  287     } else {
  288       parseErr += tr("Rows value is not a number.\n");
  289     }
  290       }
  291       if(l.contains("sbColumns")) {
  292     l = l.remove(0, equalPos+1);
  293     convInt = l.toInt(&convOk, 10);
  294     if(convOk == true) {
  295       if(sbColumns->minValue() <= convInt && convInt <= sbColumns->maxValue()) {
  296         sbColumns->setValue(convInt);
  297       } else {
  298         parseErr += tr("Columns value is out of range.\n");
  299       }
  300     } else {
  301       parseErr += tr("Columns value is not a number.\n");
  302     }
  303       }
  304       if(l.contains("sbMargin")) {
  305     l = l.remove(0, equalPos+1);
  306     convInt = l.toInt(&convOk, 10);
  307     if(convOk == true) {
  308       if(sbMargin->minValue() <= convInt && convInt <= sbMargin->maxValue()) {
  309         sbMargin->setValue(convInt);
  310       } else {
  311         parseErr += tr("Margin value is out of range.\n");
  312       }
  313     } else {
  314       parseErr += tr("Margin value is not a number.\n");
  315     }
  316       }
  317       if(l.contains("cbVirtualBorder")) {
  318     l = l.remove(0, equalPos+1);
  319     convInt = l.toInt(&convOk, 10);
  320     if(convOk == true) {
  321       switch(convInt) {
  322       case 0:
  323         cbVirtualBorder->setChecked(false);
  324         break;
  325       case 1:
  326         cbVirtualBorder->setChecked(true);
  327         break;
  328       default:
  329         parseErr += tr("Virtual border value needs to be either one or zero.\n");
  330       }
  331     } else {
  332       parseErr += tr("Virtual border value is not a number.\n");
  333     }
  334       }
  335 
  336       // Title tab.
  337       if(l.contains("lePSTitle")) {
  338     l = l.remove(0, equalPos+1);
  339     lePSTitle->setText(l);
  340       }
  341       if(l.contains("cbHeadersEnable")) {
  342     l = l.remove(0, equalPos+1);
  343     convInt = l.toInt(&convOk, 10);
  344     if(convOk == true) {
  345       switch(convInt) {
  346       case 0:
  347         cbHeadersEnable->setChecked(false);
  348         break;
  349       case 1:
  350         cbHeadersEnable->setChecked(true);
  351         break;
  352       default:
  353         parseErr += tr("Headers enable value needs to be either one or zero.\n");
  354       }
  355     } else {
  356       parseErr += tr("Headers enable value is not a number.\n");
  357     }
  358       }
  359       if(l.contains("leHeadLeft")) {
  360     l = l.remove(0, equalPos+1);
  361     leHeadLeft->setText(l);
  362       }
  363       if(l.contains("leHeadCenter")) {
  364     l = l.remove(0, equalPos+1);
  365     leHeadCenter->setText(l);
  366       }
  367       if(l.contains("leHeadRight")) {
  368     l = l.remove(0, equalPos+1);
  369     leHeadRight->setText(l);
  370       }
  371       if(l.contains("leWatermark")) {
  372     l = l.remove(0, equalPos+1);
  373     leWatermark->setText(l);
  374       }
  375       if(l.contains("leFootLeft")) {
  376     l = l.remove(0, equalPos+1);
  377     leFootLeft->setText(l);
  378       }
  379       if(l.contains("leFootCenter")) {
  380     l = l.remove(0, equalPos+1);
  381     leFootCenter->setText(l);
  382       }
  383       if(l.contains("leFootRight")) {
  384     l = l.remove(0, equalPos+1);
  385     leFootRight->setText(l);
  386       }
  387 
  388       // Layout tab.
  389       if(l.contains("slOrder")) {
  390     l = l.remove(0, equalPos+1);
  391     convInt = l.toInt(&convOk, 10);
  392     if(convOk == true) {
  393       if(slOrder->minValue() <= convInt && convInt <= slOrder->maxValue()) {
  394         slOrder->setValue(convInt);
  395       } else {
  396         parseErr += tr("Order value is out of range.\n");
  397       }
  398     } else {
  399       parseErr += tr("Order value is not a number.\n");
  400     }
  401       }
  402       if(l.contains("sbFontSize")) {
  403     l = l.remove(0, equalPos+1);
  404     convInt = l.toInt(&convOk, 10);
  405     if(convOk == true) {
  406       if(sbFontSize->minValue() <= convInt && convInt <= sbFontSize->maxValue()) {
  407         sbFontSize->setValue(convInt);
  408       } else {
  409         parseErr += tr("Font size value is out of range.\n");
  410       }
  411     } else {
  412       parseErr += tr("Font size value is not a number.\n");
  413     }
  414       }
  415       if(l.contains("sbRowsPerPage")) {
  416     l = l.remove(0, equalPos+1);
  417     convInt = l.toInt(&convOk, 10);
  418     if(convOk == true) {
  419       if(sbRowsPerPage->minValue() <= convInt && convInt <= sbRowsPerPage->maxValue()) {
  420         sbRowsPerPage->setValue(convInt);
  421       } else {
  422         parseErr += tr("Rows per page value is out of range.\n");
  423       }
  424     } else {
  425       parseErr += tr("Rows per page value is not a number.\n");
  426     }
  427       }
  428       if(l.contains("sbCharsPerRow")) {
  429     l = l.remove(0, equalPos+1);
  430     convInt = l.toInt(&convOk, 10);
  431     if(convOk == true) {
  432       if(sbCharsPerRow->minValue() <= convInt && convInt <= sbCharsPerRow->maxValue()) {
  433         sbCharsPerRow->setValue(convInt);
  434       } else {
  435         parseErr += tr("Chars per row value is out of range.\n");
  436       }
  437     } else {
  438       parseErr += tr("Chars per row value is not a number.\n");
  439     }
  440       }
  441       if(l.contains("cbColorLevel")) {
  442     l = l.remove(0, equalPos+1);
  443     convInt = l.toInt(&convOk, 10);
  444     if(convOk == true) {
  445       if(cbColorLevel->count() > convInt && convInt >= 0) {
  446         cbColorLevel->setCurrentItem(convInt);
  447       } else {
  448         parseErr += tr("Color level index is out of range.\n");
  449       }
  450     } else {
  451       parseErr += tr("Color level index is not a number.\n");
  452     }
  453       }
  454       if(l.contains("cbComments")) {
  455     l = l.remove(0, equalPos+1);
  456     convInt = l.toInt(&convOk, 10);
  457     if(convOk == true) {
  458       if(cbComments->count() > convInt && convInt >= 0) {
  459         cbComments->setCurrentItem(convInt);
  460       } else {
  461         parseErr += tr("Comments index is out of range.\n");
  462       }
  463     } else {
  464       parseErr += tr("Comments index is not a number.\n");
  465     }
  466       }
  467       if(l.contains("cbLanguage")) {
  468     l = l.remove(0, equalPos+1);
  469     convInt = l.toInt(&convOk, 10);
  470     if(convOk == true) {
  471       if(cbLanguage->count() > convInt && convInt >= 0) {
  472         cbLanguage->setCurrentItem(convInt);
  473       } else {
  474         parseErr += tr("Language index is out of range.\n");
  475       }
  476     } else {
  477       parseErr += tr("Language index is not a number.\n");
  478     }
  479       }
  480       if(l.contains("cbUnprintables")) {
  481     l = l.remove(0, equalPos+1);
  482     convInt = l.toInt(&convOk, 10);
  483     if(convOk == true) {
  484       if(cbUnprintables->count() > convInt && convInt >= 0) {
  485         cbUnprintables->setCurrentItem(convInt);
  486       } else {
  487         parseErr += tr("Unprintables index is out of range.\n");
  488       }
  489     } else {
  490       parseErr += tr("Unprintables index is not a number.\n");
  491     }
  492       }
  493       if(l.contains("cbPostScript")) {
  494     l = l.remove(0, equalPos+1);
  495     convInt = l.toInt(&convOk, 10);
  496     if(convOk == true) {
  497       if(cbPostScript->count() > convInt && convInt >= 0) {
  498         cbPostScript->setCurrentItem(convInt);
  499       } else {
  500         parseErr += tr("PostScript index is out of range.\n");
  501       }
  502     } else {
  503       parseErr += tr("PostScript index is not a number.\n");
  504     }
  505       }
  506       if(l.contains("sbTabSize")) {
  507     l = l.remove(0, equalPos+1);
  508     convInt = l.toInt(&convOk, 10);
  509     if(convOk == true) {
  510       if(sbTabSize->minValue() <= convInt && convInt <= sbTabSize->maxValue()) {
  511         sbTabSize->setValue(convInt);
  512       } else {
  513         parseErr += tr("Tab size value is out of range.\n");
  514       }
  515     } else {
  516       parseErr += tr("Tab size value is not a number.\n");
  517     }
  518       }
  519       if(l.contains("sbLineNumbers")) {
  520     l = l.remove(0, equalPos+1);
  521     convInt = l.toInt(&convOk, 10);
  522     if(convOk == true) {
  523       if(sbLineNumbers->minValue() <= convInt && convInt <= sbLineNumbers->maxValue()) {
  524         sbLineNumbers->setValue(convInt);
  525       } else {
  526         parseErr += tr("Line numbers value is out of range.\n");
  527       }
  528     } else {
  529       parseErr += tr("Line numbers value is not a number.\n");
  530     }
  531       }
  532       if(l.contains("cbTOC")) {
  533     l = l.remove(0, equalPos+1);
  534     convInt = l.toInt(&convOk, 10);
  535     if(convOk == true) {
  536       switch(convInt) {
  537       case 0:
  538         cbTOC->setChecked(false);
  539         break;
  540       case 1:
  541         cbTOC->setChecked(true);
  542         break;
  543       default:
  544         parseErr += tr("TOC value needs to be either one or zero.\n");
  545       }
  546     } else {
  547       parseErr += tr("TOC value is not a number.\n");
  548     }
  549       }
  550       if(l.contains("cbTruncate")) {
  551     l = l.remove(0, equalPos+1);
  552     convInt = l.toInt(&convOk, 10);
  553     if(convOk == true) {
  554       switch(convInt) {
  555       case 0:
  556         cbTruncate->setChecked(false);
  557         break;
  558       case 1:
  559         cbTruncate->setChecked(true);
  560         break;
  561       default:
  562         parseErr += tr("Truncate value needs to be either one or zero.\n");
  563       }
  564     } else {
  565       parseErr += tr("Truncate value is not a number.\n");
  566     }
  567       }
  568 
  569       // Processing tab.
  570       if(l.contains("cbEncoding")) {
  571     l = l.remove(0, equalPos+1);
  572     convInt = l.toInt(&convOk, 10);
  573     if(convOk == true) {
  574       if(cbEncoding->count() > convInt && convInt >= 0) {
  575         cbEncoding->setCurrentItem(convInt);
  576       } else {
  577         parseErr += tr("Encoding index is out of range.\n");
  578       }
  579     } else {
  580       parseErr += tr("Encoding index is not a number.\n");
  581     }
  582       }
  583       if(l.contains("cbDelegate")) {
  584     l = l.remove(0, equalPos+1);
  585     convInt = l.toInt(&convOk, 10);
  586     if(convOk == true) {
  587       switch(convInt) {
  588       case 0:
  589         cbDelegate->setChecked(false);
  590         break;
  591       case 1:
  592         cbDelegate->setChecked(true);
  593         break;
  594       default:
  595         parseErr += tr("Delegate value needs to be either one or zero.\n");
  596       }
  597     } else {
  598       parseErr += tr("Delegate value is not a number.\n");
  599     }
  600       }
  601       if(l.contains("cbPrefeed")) {
  602     l = l.remove(0, equalPos+1);
  603     convInt = l.toInt(&convOk, 10);
  604     if(convOk == true) {
  605       switch(convInt) {
  606       case 0:
  607         cbPrefeed->setChecked(false);
  608         break;
  609       case 1:
  610         cbPrefeed->setChecked(true);
  611         break;
  612       default:
  613         parseErr += tr("Prefeed value needs to be either one or zero.\n");
  614       }
  615     } else {
  616       parseErr += tr("Prefeed value is not a number.\n");
  617     }
  618       }
  619       if(l.contains("sbCopies")) {
  620     l = l.remove(0, equalPos+1);
  621     convInt = l.toInt(&convOk, 10);
  622     if(convOk == true) {
  623       if(sbCopies->minValue() <= convInt && convInt <= sbCopies->maxValue()) {
  624         sbCopies->setValue(convInt);
  625       } else {
  626         parseErr += tr("Copies value is out of range.\n");
  627       }
  628     } else {
  629       parseErr += tr("Copies value is not a number.\n");
  630     }
  631       }
  632       if(l.contains("leOptions")) {
  633     l = l.remove(0, equalPos+1);
  634     leOptions->setText(l);
  635       }
  636 
  637       // Tipo tab.
  638       if(l.contains("cbTipoLanguage")) {
  639     l = l.remove(0, equalPos+1);
  640     convInt = l.toInt(&convOk, 10);
  641     if(convOk == true) {
  642       if(cbTipoLanguage->count() > convInt && convInt >= 0) {
  643         cbTipoLanguage->setCurrentItem(convInt);
  644       } else {
  645         parseErr += tr("Tipo language index is out of range.\n");
  646       }
  647     } else {
  648       parseErr += tr("Tipo language index is not a number.\n");
  649     }
  650       }
  651       if(l.contains("cbGUIStyle")) {
  652     l = l.remove(0, equalPos+1);
  653     convInt = l.toInt(&convOk, 10);
  654     if(convOk == true) {
  655       if(cbGUIStyle->count() > convInt && convInt >= 0) {
  656         cbGUIStyle->setCurrentItem(convInt);
  657       } else {
  658         parseErr += tr("GUI style index is out of range.\n");
  659       }
  660     } else {
  661       parseErr += tr("GUI style index is not a number.\n");
  662     }
  663       }
  664       if(l.contains("lePathA2ps")) {
  665     l = l.remove(0, equalPos+1);
  666     lePathA2ps->setText(l);
  667       }
  668       if(l.contains("lePathGv")) {
  669     l = l.remove(0, equalPos+1);
  670     lePathGv->setText(l);
  671       }
  672       if(l.contains("leConfig")) {
  673     l = l.remove(0, equalPos+1);
  674     leConfig->setText(l);
  675       }
  676     } // end if contains "="
  677   } // end while
  678   
  679   configFile.close();
  680 
  681   // Check for errors.
  682   if(parseErr != "") {
  683     QMessageBox::warning(this,
  684              tr("Load configuration"),
  685              parseErrIntro + parseErr,
  686              QMessageBox::Ok,
  687              0);
  688   }
  689 }
  690 
  691 void tipografImpl::saveConfig()
  692 {
  693   QString configFileComment =
  694     tr("# Tipograf V" VERSION " configuration file\n"
  695        "#\n"
  696        "# This file contains values of all controls related\n"
  697        "# to printing. It does not contain settings specific\n"
  698        "# to Tipografs GUI. Those are stored in ~/.tipografrc.\n"
  699        "# This file is not intended to be edited by hand.\n"
  700        "#\n"
  701        "\n");
  702   
  703   QFile configFile(leConfig->text());
  704 
  705   // Check config file.
  706   if(configFile.exists()) {
  707     if(QMessageBox::information(this,
  708                 tr("Save configuration"),
  709                 tr("You are about to overwrite\n"
  710                    "an existing file.\n"),
  711                 tr("Continue"), tr("Cancel")) == 1) {
  712       return;
  713     }
  714   }
  715 
  716   if(!configFile.open(IO_WriteOnly)) {
  717     QMessageBox::warning(this,
  718              tr("Save configuration"),
  719              tr("Unable to open file for writing."),
  720              QMessageBox::Ok,
  721              0);
  722     return;
  723   }
  724 
  725   QTextStream s(&configFile);
  726 
  727   // Write comment.
  728   s << configFileComment;
  729 
  730   // Save input / output tab.
  731   s << tr("\n# Input / Output tab\n");
  732 
  733   s << "leInput="    << leInput->text() << "\n";
  734   s << "leOutput="   << leInput->text() << "\n";
  735   s << "cbStdStyle=" << cbStdStyle->currentItem() << "\n";
  736   s << "cbOutputTo=" << cbOutputTo->currentItem() << "\n";
  737   s << "cbPrinter="  << cbPrinter->currentItem()  << "\n";
  738   if(cbSimpleOptionsDisable->isChecked()) {
  739     s << "cbSimpleOptionsDisable=" << "1" << "\n";
  740   } else {
  741     s << "cbSimpleOptionsDisable=" << "0" << "\n";
  742   }
  743   if(rbSimpleOptionPortrait->isChecked()) {
  744     s << "rbSimpleOptionPortrait=" << "1" << "\n";
  745   } else {
  746     s << "rbSimpleOptionPortrait=" << "0" << "\n";
  747   }
  748   if(rbSimpleOptionLandscape->isChecked()) {
  749     s << "rbSimpleOptionLandscape=" << "1" << "\n";
  750   } else {
  751     s << "rbSimpleOptionLandscape=" << "0" << "\n";
  752   }
  753   if(cbSimpleOptionLineNumbers->isChecked()) {
  754     s << "cbSimpleOptionLineNumbers=" << "1" << "\n";
  755   } else {
  756     s << "cbSimpleOptionLineNumbers=" << "0" << "\n";
  757   }
  758   if(cbSimpleOptionColored->isChecked()) {
  759     s << "cbSimpleOptionColored=" << "1" << "\n";
  760   } else {
  761     s << "cbSimpleOptionColored=" << "0" << "\n";
  762   }
  763   s << "sbSimpleOptionFontSize=" << sbSimpleOptionFontSize->value() << "\n";
  764 
  765   // Save paper tab.
  766   s << tr("\n# Paper tab\n");
  767 
  768   s << "cbOrientation=" << cbOrientation->currentItem() << "\n";
  769   s << "cbFormat="      << cbFormat->currentItem()      << "\n";
  770   s << "cbDirection="   << cbDirection->currentItem()   << "\n";
  771   s << "cbDuplex="      << cbDuplex->currentItem()      << "\n";
  772   s << "sbRows="        << sbRows->value()              << "\n";
  773   s << "sbColumns="     << sbColumns->value()           << "\n";
  774   s << "sbMargin="      << sbMargin->value()            << "\n";
  775   if(cbVirtualBorder->isChecked()) {
  776     s << "cbVirtualBorder=" << "1" << "\n";
  777   } else {
  778     s << "cbVirtualBorder=" << "0" << "\n";
  779   }
  780 
  781   // Save title tab.
  782   s << tr("\n# Title tab\n");
  783 
  784   s << "lePSTitle=" << lePSTitle->text() << "\n";
  785   if(cbHeadersEnable->isChecked()) {
  786     s << "cbHeadersEnable=" << "1" << "\n";
  787   } else {
  788     s << "cbHeadersEnable=" << "0" << "\n";
  789   }
  790   s << "leHeadLeft="   << leHeadLeft->text()   << "\n";
  791   s << "leHeadCenter=" << leHeadCenter->text() << "\n";
  792   s << "leHeadRight="  << leHeadRight->text()  << "\n";
  793   s << "leWatermark="  << leWatermark->text()  << "\n";
  794   s << "leFootLeft="   << leFootLeft->text()   << "\n";
  795   s << "leFootCenter=" << leFootCenter->text() << "\n";
  796   s << "leFootRight="  << leFootRight->text()  << "\n";
  797   
  798   // Save layout tab.
  799   s << tr("\n# Layout tab\n");
  800 
  801   s << "slOrder="        << slOrder->value()              << "\n";
  802   s << "sbFontSize="     << sbFontSize->value()           << "\n";
  803   s << "sbRowsPerPage="  << sbRowsPerPage->value()        << "\n";
  804   s << "sbCharsPerRow="  << sbCharsPerRow->value()        << "\n";
  805   s << "cbColorLevel="   << cbColorLevel->currentItem()   << "\n";
  806   s << "cbComments="     << cbComments->currentItem()     << "\n";
  807   s << "cbLanguage="     << cbLanguage->currentItem()     << "\n";
  808   s << "cbUnprintables=" << cbUnprintables->currentItem() << "\n";
  809   s << "cbPostScript="   << cbPostScript->currentItem()   << "\n";
  810   s << "sbTabSize="      << sbTabSize->value()            << "\n";
  811   s << "sbLineNumbers="  << sbLineNumbers->value()        << "\n";
  812   if(cbTOC->isChecked()) {
  813     s << "cbTOC=" << "1" << "\n";
  814   } else {
  815     s << "cbTOC=" << "0" << "\n";
  816   }
  817   if(cbTruncate->isChecked()) {
  818     s << "cbTruncate=" << "1" << "\n";
  819   } else {
  820     s << "cbTruncate=" << "0" << "\n";
  821   }
  822 
  823   // Save processing tab.
  824   s << tr("\n# Processing tab\n");
  825 
  826   s << "cbEncoding="   << cbEncoding->currentItem() << "\n";
  827   if(cbDelegate->isChecked()) {
  828     s << "cbDelegate=" << "1" << "\n";
  829   } else {
  830     s << "cbDelegate=" << "0" << "\n";
  831   }
  832   if(cbPrefeed->isChecked()) {
  833     s << "cbPrefeed=" << "1" << "\n";
  834   } else {
  835     s << "cbPrefeed=" << "0" << "\n";
  836   }
  837   s << "sbCopies="    << sbCopies->value() << "\n";
  838   s << "leOptions="   << leOptions->text() << "\n";
  839 
  840   // Save Tipo tab.
  841   s << tr("\n# Tipo tab\n");
  842 
  843   s << "cbTipoLanguage=" << cbTipoLanguage->currentItem() << "\n";
  844   s << "cbGUIStyle="     << cbGUIStyle->currentItem()     << "\n";
  845   s << "lePathA2ps="     << lePathA2ps->text()            << "\n";
  846   s << "lePathGv="       << lePathGv->text()              << "\n";
  847   s << "leConfig="       << leConfig->text()              << "\n";
  848   
  849   // Close config file.
  850   configFile.close();
  851 
  852 }
  853 
  854 // ============================================================
  855 // Tipo load/save
  856 // These functions do the I/O to ~/.tipografrc.
  857 // They only save/load the Tipo tab values 
  858 //     - TipoLanguage
  859 //     - GUIStyle
  860 //     - PathA2ps
  861 //     - PathGv
  862 // ============================================================
  863 
  864 void tipografImpl::loadTipo()
  865 {
  866   // Prepare file and error objects.
  867   QFile configFile(resolveConfigFileName());
  868   QString parseErrIntro = tr("The following errors occured:\n\n");
  869   QString parseErr      = "";
  870 
  871   // Check config file.
  872   if(!configFile.exists()) {
  873     QMessageBox::warning(this,
  874              tr("Load Tipo configuration"),
  875              tr("The configuration file ~/.tipografrc\n"
  876                 "does not exist."),
  877              QMessageBox::Ok,
  878              0);
  879     return;
  880   }
  881   
  882   if(!configFile.open(IO_ReadOnly)) {
  883     QMessageBox::warning(this,
  884              tr("Load Tipo configuration"),
  885              tr("Unable to open file ~/.tipografrc for reading."),
  886              QMessageBox::Ok,
  887              0);
  888     return;
  889   }
  890   
  891   // Read in configuration.
  892   QTextStream s(&configFile);
  893   QString l;
  894   int equalPos = 0;
  895   int convInt = 0;
  896   bool convOk = false;
  897 
  898   while(!s.eof()) {
  899     l = s.readLine();
  900     if(l.contains("=")) {
  901       equalPos = l.find("=");
  902 
  903       // Tipo tab.
  904       if(l.contains("cbTipoLanguage")) {
  905     l = l.remove(0, equalPos+1);
  906     convInt = l.toInt(&convOk, 10);
  907     if(convOk == true) {
  908       if(cbTipoLanguage->count() > convInt && convInt >= 0) {
  909         cbTipoLanguage->setCurrentItem(convInt);
  910       } else {
  911         parseErr += tr("Tipo language index is out of range.\n");
  912       }
  913     } else {
  914       parseErr += tr("Tipo language index is not a number.\n");
  915     }
  916       }
  917       if(l.contains("cbGUIStyle")) {
  918     l = l.remove(0, equalPos+1);
  919     convInt = l.toInt(&convOk, 10);
  920     if(convOk == true) {
  921       if(cbGUIStyle->count() > convInt && convInt >= 0) {
  922         cbGUIStyle->setCurrentItem(convInt);
  923         QApplication::setStyle(QStyleFactory::create(cbGUIStyle->currentText()));
  924       } else {
  925         parseErr += tr("GUI style index is out of range.\n");
  926       }
  927     } else {
  928       parseErr += tr("GUI style index is not a number.\n");
  929     }
  930       }
  931       if(l.contains("lePathA2ps")) {
  932     l = l.remove(0, equalPos+1);
  933     lePathA2ps->setText(l);
  934       }
  935       if(l.contains("lePathGv")) {
  936     l = l.remove(0, equalPos+1);
  937     lePathGv->setText(l);
  938       }
  939     } // end if contains "="
  940   } // end while
  941   
  942   configFile.close();
  943 
  944   // Check for errors.
  945   if(parseErr != "") {
  946     QMessageBox::warning(this,
  947              tr("Load Tipo configuration"),
  948              parseErrIntro + parseErr,
  949              QMessageBox::Ok,
  950              0);
  951     return;
  952   }
  953 
  954 }
  955 
  956 void tipografImpl::saveTipo()
  957 {
  958   QString configFileComment =
  959     tr("# Tipograf V" VERSION " configuration file\n"
  960        "#\n"
  961        "# This file only contains settings related to\n"
  962        "# Tipograf's GUI.\n"
  963        "# This file is not intended to be edited by hand.\n"
  964        "#\n"
  965        "\n");
  966   
  967   QFile configFile(resolveConfigFileName());
  968 
  969   // Check config file.
  970   if(!configFile.open(IO_WriteOnly)) {
  971     QMessageBox::warning(this,
  972              tr("Save Tipo configuration"),
  973              tr("Unable to open file for writing."),
  974              QMessageBox::Ok,
  975              0);
  976     return;
  977   }
  978 
  979   QTextStream s(&configFile);
  980 
  981   // Write comment.
  982   s << configFileComment;
  983 
  984   // Save Tipo tab.
  985   s << tr("\n# Tipo tab\n");
  986 
  987   s << "cbTipoLanguage=" << cbTipoLanguage->currentItem() << "\n";
  988   s << "cbGUIStyle="     << cbGUIStyle->currentItem()     << "\n";
  989   s << "lePathA2ps="     << lePathA2ps->text()            << "\n";
  990   s << "lePathGv="       << lePathGv->text()              << "\n";
  991   
  992   // Close config file.
  993   configFile.close();
  994 
  995 }