[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kde-workspace/previewsoc13] kcontrol/keyboard: base file parser added, cleanup, levels now shown pr
From:       shivam makkar <amourphious1992 () gmail ! com>
Date:       2013-09-20 21:52:16
Message-ID: E1VN8ca-0003OF-1k () scm ! kde ! org
[Download RAW message or body]

Git commit 260a2517a2d84dc50f74b848a346c4424fa734b9 by shivam makkar.
Committed on 20/09/2013 at 21:51.
Pushed by makkar into branch 'previewsoc13'.

base file parser added, cleanup, levels now shown properly

M  +85   -66   kcontrol/keyboard/preview/geometry_parser.cpp
M  +3    -4    kcontrol/keyboard/preview/geometry_parser.h
M  +2    -1    kcontrol/keyboard/preview/kbpreviewframe.cpp
M  +1    -1    kcontrol/keyboard/preview/keyboardpainter.cpp
M  +132  -17   kcontrol/keyboard/preview/model_to_geometry.cpp
M  +12   -2    kcontrol/keyboard/preview/model_to_geometry.h
M  +31   -31   kcontrol/keyboard/preview/symbol_parser.cpp
M  +1    -1    kcontrol/keyboard/preview/symbol_parser.h
M  +1    -1    kcontrol/keyboard/tests/CMakeLists.txt

http://commits.kde.org/kde-workspace/260a2517a2d84dc50f74b848a346c4424fa734b9

diff --git a/kcontrol/keyboard/preview/geometry_parser.cpp \
b/kcontrol/keyboard/preview/geometry_parser.cpp index 7a2df28..92f2af6 100644
--- a/kcontrol/keyboard/preview/geometry_parser.cpp
+++ b/kcontrol/keyboard/preview/geometry_parser.cpp
@@ -18,7 +18,8 @@
 
 #include "geometry_parser.h"
 #include "geometry_components.h"
-#include "x11_helper.h"
+#include "../x11_helper.h"
+#include "model_to_geometry.h"
 
 #include <QtCore/QString>
 #include <QtCore/QDebug>
@@ -67,17 +68,17 @@ Geometry_parser<Iterator>::Geometry_parser():Geometry_parser::base_type(start){
             ||lit("indicator")>>*(char_-';'-'{')>>';'||'{'>>*(char_-lit("};"))>>lit("};")
             ||lit("indicator")>>'.'>>lit("shape")>>'='>>name>>';';
 
-    comments =lexeme[ \
lit("//")>>*(char_-eol||kw-eol)>>eol||lit("/*")>>*(char_-lit("*/")||kw-lit("*/"))>>lit("*/") ]; +    \
comments =lexeme[ lit("//")>>*(char_-eol||keyword-eol)>>eol||lit("/*")>>*(char_-lit("*/")||keyword-lit("*/"))>>lit("*/") \
];  
     cordinates = ('['
-            >>double_[phx::ref(x)=_1]
+            >>double_[phx::ref(shapeLenX)=_1]
             >>','
-            >>double_[phx::ref(y)=_1]
+            >>double_[phx::ref(shapeLenY)=_1]
             >>']')
             ||'['>>double_>>",">>double_>>']'
             ;
 
-    cordinatea = '['>>double_[phx::ref(ax)=_1]>>",">>double_[phx::ref(ay)=_1]>>']';
+    cordinatea = '['>>double_[phx::ref(approxLenX)=_1]>>",">>double_[phx::ref(approxLenY)=_1]>>']';
 
     set = '{'>>cordinates>>*(','>>cordinates)>>'}';
 
@@ -109,7 +110,7 @@ Geometry_parser<Iterator>::Geometry_parser():Geometry_parser::base_type(start){
 
     keyColor = lit("color")>>'='>>name;
 
-    keygap = lit("gap")>>'='>>double_[phx::ref(off)=_1]||double_[phx::ref(off)=_1];
+    keygap = lit("gap")>>'='>>double_[phx::ref(KeyOffset)=_1]||double_[phx::ref(KeyOffset)=_1];
 
     keyDesc = keyName[phx::bind(&Geometry_parser::setKeyNameandShape,this,_1)]
             ||'{'>>(keyName[phx::bind(&Geometry_parser::setKeyNameandShape,this,_1)]||keyShape
@@ -180,13 +181,13 @@ Geometry_parser<Iterator>::Geometry_parser():Geometry_parser::base_type(start){
     shape = shapeDef||shapeC;
 
 
-    in = '{'
+    input = '{'
           >>+(width
           ||height
           ||comments
           ||ignore
           ||description
-          ||(char_-kw-'}'
+          ||(char_-keyword-'}'
           ||shape[phx::bind(&Geometry::addShape,&geom)]
           ||section[phx::bind(&Geometry::addSection,&geom)]
           ||geomAtt
@@ -197,20 +198,16 @@ Geometry_parser<Iterator>::Geometry_parser():Geometry_parser::base_type(start){
           width = lit("width")>>'='>>double_[phx::bind(&Geometry::setWidth,&geom,_1)]>>";";
           height = lit("height")>>'='>>double_[phx::bind(&Geometry::setHeight,&geom,_1)]>>";";
 
-
-          info = in;
-
-
           start %= *(lit("default"))
                  >>lit("xkb_geometry")
                  >>name[phx::bind(&Geometry_parser::getName,this,_1)]
-                 >>info
+                 >>input
                  >>';'>>*(comments||char_-lit("xkb_geometry"));
 }
 
 template<typename Iterator>
     void Geometry_parser<Iterator>::setCord(){
-        geom.setShapeCord(x, y);
+        geom.setShapeCord(shapeLenX, shapeLenY);
     }
 
 
@@ -246,13 +243,15 @@ template<typename Iterator>
 
 template<typename Iterator>
 void Geometry_parser<Iterator>::setRowShape(std::string n){
-    geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].setShapeName(QString::fromUtf8(n.data(), \
n.size() )); +    int secn = geom.getSectionCount();
+    int rown = geom.sectionList[secn].getRowCount();
+    geom.sectionList[secn].rowList[rown].setShapeName(QString::fromUtf8(n.data(), n.size() ));
 }
 
 
 template<typename Iterator>
     void Geometry_parser<Iterator>::setApprox(){
-        geom.setShapeApprox(ax, ay);
+        geom.setShapeApprox(approxLenX, approxLenY);
 }
 
 
@@ -270,53 +269,67 @@ template<typename Iterator>
 
 template<typename Iterator>
     void Geometry_parser<Iterator>::rowinit(){
-        geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].setTop(geom.sectionList[geom.getSectionCount()].getTop());
                
-        geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].setLeft(geom.sectionList[geom.getSectionCount()].getLeft());
                
-        geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].setShapeName(geom.sectionList[geom.getSectionCount()].getShapeName());
                
-        cx = geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].getLeft();
                
-        cy = geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].getTop();
                
-        geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].setVertical(geom.sectionList[geom.getSectionCount()].getVertical());
 +        int secn = geom.getSectionCount();
+        int rown = geom.sectionList[secn].getRowCount();
+        double tempTop = geom.sectionList[secn].getTop();
+        QString tempShape = geom.sectionList[secn].getShapeName();
+        geom.sectionList[secn].rowList[rown].setTop(tempTop);
+        geom.sectionList[secn].rowList[rown].setLeft(geom.sectionList[secn].getLeft());
+        geom.sectionList[secn].rowList[rown].setShapeName(tempShape);
+        keyCordiX = geom.sectionList[secn].rowList[rown].getLeft();
+        keyCordiY = geom.sectionList[secn].rowList[rown].getTop();
+        tempTop = geom.sectionList[secn].getVertical();
+        geom.sectionList[secn].rowList[rown].setVertical(tempTop);
     }
 
 
 template<typename Iterator>
     void Geometry_parser<Iterator>::sectioninit(){
-        geom.sectionList[geom.getSectionCount()].setTop(geom.sectionTop);
-        geom.sectionList[geom.getSectionCount()].setLeft(geom.sectionLeft);
-        cx = geom.sectionList[geom.getSectionCount()].getLeft();
-        cy = geom.sectionList[geom.getSectionCount()].getTop();
-        geom.sectionList[geom.getSectionCount()].setShapeName(geom.getKeyShape());
-        geom.sectionList[geom.getSectionCount()].setVertical(geom.getVertical());
+        int secn = geom.getSectionCount();
+        geom.sectionList[secn].setTop(geom.sectionTop);
+        geom.sectionList[secn].setLeft(geom.sectionLeft);
+        keyCordiX = geom.sectionList[secn].getLeft();
+        keyCordiY = geom.sectionList[secn].getTop();
+        geom.sectionList[secn].setShapeName(geom.getKeyShape());
+        geom.sectionList[secn].setVertical(geom.getVertical());
     }
 
 
 template<typename Iterator>
     void Geometry_parser<Iterator>::setRowTop(double a){
-        geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].setTop(a \
                + geom.sectionList[geom.getSectionCount()].getTop());
-        cy = geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].getTop();
 +        int secn = geom.getSectionCount();
+        int rown = geom.sectionList[secn].getRowCount();
+        double tempTop = geom.sectionList[secn].getTop();
+        geom.sectionList[secn].rowList[rown].setTop(a + tempTop);
+        keyCordiY = geom.sectionList[secn].rowList[rown].getTop();
     }
 
 
 template<typename Iterator>
     void Geometry_parser<Iterator>::setRowLeft(double a){
-        geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].setLeft(a \
                + geom.sectionList[geom.getSectionCount()].getLeft());
-        cx = geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].getLeft();
 +        int secn = geom.getSectionCount();
+        int rown = geom.sectionList[secn].getRowCount();
+        double tempLeft = geom.sectionList[secn].getLeft();
+        geom.sectionList[secn].rowList[rown].setTop(a + tempLeft);
+        keyCordiX = geom.sectionList[secn].rowList[rown].getLeft();
     }
 
 
 template<typename Iterator>
     void Geometry_parser<Iterator>::setSectionTop(double a){
         //qDebug()<<"\nsectionCount"<<geom.sectionCount;
-        geom.sectionList[geom.getSectionCount()].setTop(a + geom.sectionTop);
-        cy = geom.sectionList[geom.getSectionCount()].getTop();
+        int secn = geom.getSectionCount();
+        geom.sectionList[secn].setTop(a + geom.sectionTop);
+        keyCordiY = geom.sectionList[secn].getTop();
     }
 
 
 template<typename Iterator>
     void Geometry_parser<Iterator>::setSectionLeft(double a){
         //qDebug()<<"\nsectionCount"<<geom.sectionCount;
-        geom.sectionList[geom.getSectionCount()].setLeft(a + geom.sectionLeft);
-        cx = geom.sectionList[geom.getSectionCount()].getLeft();
+        int secn = geom.getSectionCount();
+        geom.sectionList[secn].setLeft(a + geom.sectionLeft);
+        keyCordiX = geom.sectionList[secn].getLeft();
 
     }
 
@@ -324,19 +337,23 @@ template<typename Iterator>
 template<typename Iterator>
     void Geometry_parser<Iterator>::setSectionAngle(double a){
         //qDebug()<<"\nsectionCount"<<geom.sectionCount;
-        geom.sectionList[geom.getSectionCount()].setAngle(a);
+        int secn = geom.getSectionCount();
+        geom.sectionList[secn].setAngle(a);
     }
 
 
 template<typename Iterator>
     void Geometry_parser<Iterator>::setVerticalRow(){
-        geom.sectionList[geom.getSectionCount()].rowList[geom.sectionList[geom.getSectionCount()].getRowCount()].setVertical(1);
 +        int secn = geom.getSectionCount();
+        int rown = geom.sectionList[secn].getRowCount();
+        geom.sectionList[secn].rowList[rown].setVertical(1);
     }
 
 
 template<typename Iterator>
     void Geometry_parser<Iterator>::setVerticalSection(){
-        geom.sectionList[geom.getSectionCount()].setVertical(1);
+        int secn = geom.getSectionCount();
+        geom.sectionList[secn].setVertical(1);
     }
 
 
@@ -382,7 +399,7 @@ template<typename Iterator>
         int rown = geom.sectionList[secn].getRowCount();
         int keyn = geom.sectionList[secn].rowList[rown].getKeyCount();
         //qDebug()<<"\nsC: "<<secn<<"\trC: "<<rown<<"\tkn: "<<keyn;
-        geom.sectionList[secn].rowList[rown].keyList[keyn].setOffset(off);
+        geom.sectionList[secn].rowList[rown].keyList[keyn].setOffset(KeyOffset);
     }
 
 
@@ -393,24 +410,26 @@ template<typename Iterator>
         int keyn = geom.sectionList[secn].rowList[rown].getKeyCount();
         int vertical = geom.sectionList[secn].rowList[rown].getVertical();
 
+        Key key = geom.sectionList[secn].rowList[rown].keyList[keyn];
+
         if(vertical == 0)
-            cx+=geom.sectionList[secn].rowList[rown].keyList[keyn].getOffset();
+            keyCordiX+= key.getOffset();
         else
-            cy+=geom.sectionList[secn].rowList[rown].keyList[keyn].getOffset();
+            keyCordiY+= key.getOffset();
 
-        geom.sectionList[secn].rowList[rown].keyList[keyn].setKeyPosition(cx, cy);
+        geom.sectionList[secn].rowList[rown].keyList[keyn].setKeyPosition(keyCordiX, keyCordiY);
 
-        QString s = geom.sectionList[secn].rowList[rown].keyList[keyn].getShapeName();
-        if ( s.isEmpty() )
-            s = geom.getKeyShape();
+        QString shapeStr = key.getShapeName();
+        if ( shapeStr.isEmpty() )
+            shapeStr = geom.getKeyShape();
 
-        GShape t = geom.findShape(s);
-        int a = t.size(vertical);
+        GShape shapeObj = geom.findShape(shapeStr);
+        int a = shapeObj.size(vertical);
 
         if(vertical == 0)
-            cx+=a+geom.keyGap;
+            keyCordiX+=a+geom.keyGap;
         else
-            cy+=a+geom.keyGap;
+            keyCordiY+=a+geom.keyGap;
 
         geom.sectionList[secn].rowList[rown].addKey();
     }
@@ -422,12 +441,12 @@ template<typename Iterator>
         using boost::spirit::iso8859_1::space;
         typedef std::string::const_iterator iterator_type;
         typedef grammar::Geometry_parser<iterator_type> Geometry_parser;
-        Geometry_parser g;
-        ModelToGeometry m2g = ModelToGeometry(model);
+        Geometry_parser geomertyParser;
+        ModelToGeometryTable m2g = ModelToGeometryTable();
 
-        //qDebug()<<geometry;
-        QString geometryFile = m2g.getGeometryFile();
-        QString geometryName = m2g.getGeometryName();
+        m2g.createTable();
+        QString geometryFile = m2g.getGeometryFile(model);
+        QString geometryName = m2g.getGeometryName(model);
         //qDebug()<< geometryFile << geometryName;
 
         QString xkbParentDir = findGeometryBaseDir();
@@ -435,7 +454,7 @@ template<typename Iterator>
         QFile gfile(geometryFile);
          if (!gfile.open(QIODevice::ReadOnly | QIODevice::Text)){
              qDebug()<<"unable to open the file";
-             return g.geom;
+             return geomertyParser.geom;
         }
 
         QString gcontent = gfile.readAll();
@@ -443,18 +462,18 @@ template<typename Iterator>
 
         QStringList gcontentList = gcontent.split("xkb_geometry");
 
-        int i = 1;
-        while(g.geom.getName()!=geometryName && i < gcontentList.size() ){
-            g.geom = Geometry();
-            QString input = gcontentList.at(i);
+        int current = 1;
+        while(geomertyParser.geom.getName()!=geometryName && current < gcontentList.size() ){
+            geomertyParser.geom = Geometry();
+            QString input = gcontentList.at(current);
             input.prepend("xkb_geometry");
             //qDebug()<<input;
-            std::string xyz = input.toUtf8().constData();
+            std::string parserInput = input.toUtf8().constData();
 
-            std::string::const_iterator iter = xyz.begin();
-            std::string::const_iterator end = xyz.end();
+            std::string::const_iterator iter = parserInput.begin();
+            std::string::const_iterator end = parserInput.end();
 
-            bool r = phrase_parse(iter, end, g, space);
+            bool r = phrase_parse(iter, end, geomertyParser, space);
             /*if (r && iter == end){
                 std::cout << "-------------------------\n";
                 std::cout << "Parsing succeeded\n";
@@ -465,11 +484,11 @@ template<typename Iterator>
                 std::cout << "Parsing failed\n";
                 std::cout << "-------------------------\n";
             }*/
-            i++;
+            current++;
 
         }
         //g.geom.display();
-        return g.geom;
+        return geomertyParser.geom;
     }
 
     QString findGeometryBaseDir()
diff --git a/kcontrol/keyboard/preview/geometry_parser.h b/kcontrol/keyboard/preview/geometry_parser.h
index e67b5c2..f704ed1 100644
--- a/kcontrol/keyboard/preview/geometry_parser.h
+++ b/kcontrol/keyboard/preview/geometry_parser.h
@@ -61,8 +61,7 @@ namespace grammar{
     //general non-temrminals
     qi::rule<Iterator, std::string(), iso::space_type>name;
     qi::rule<Iterator, std::string(), iso::space_type>description;
-    qi::rule<Iterator, std::string(), iso::space_type>in;
-    qi::rule<Iterator, std::string(), iso::space_type>info;
+    qi::rule<Iterator, std::string(), iso::space_type>input;
 
     //non-teminals for shape
     qi::rule<Iterator, int(), iso::space_type>shape;
@@ -107,8 +106,8 @@ namespace grammar{
 
     qi::rule<Iterator, iso::space_type>start;
     Geometry geom;
-    keywords kw;
-    double x, y, ax, ay, cx, cy, off;
+    keywords keyword;
+    double shapeLenX, shapeLenY, approxLenX, approxLenY, keyCordiX, keyCordiY, KeyOffset;
     Geometry_parser();
 
     //functions for shape
diff --git a/kcontrol/keyboard/preview/kbpreviewframe.cpp b/kcontrol/keyboard/preview/kbpreviewframe.cpp
index 4b9ab3d..8fe8f03 100644
--- a/kcontrol/keyboard/preview/kbpreviewframe.cpp
+++ b/kcontrol/keyboard/preview/kbpreviewframe.cpp
@@ -23,6 +23,7 @@
 #include "geometry_components.h"
 #include "keyboardlayout.h"
 #include "symbol_parser.h"
+#include "model_to_geometry.h"
 
 #include <QtCore/QFile>
 #include <QtGui/QFont>
@@ -42,7 +43,7 @@ static const QColor unknownSymbolColor("#FF3300");
 static const int xOffset[] = {10, 10, -15, -15 };
 static const int yOffset[] = {5, -20, 5, -20 };
 static const QColor color[] = { lev12color, lev12color, lev34color, lev34color };
-static const int keyLevel[3][4] = { { 0, 1, 2, 3}, { 0, 1, 4, 5}, { 0, 1, 6, 7} };
+static const int keyLevel[3][4] = { { 1, 0, 2, 3}, { 1, 0, 4, 5}, { 1, 0, 6, 7} };
 
 
 KbPreviewFrame::KbPreviewFrame(QWidget *parent) :
diff --git a/kcontrol/keyboard/preview/keyboardpainter.cpp \
b/kcontrol/keyboard/preview/keyboardpainter.cpp index 437906b..a740d44 100644
--- a/kcontrol/keyboard/preview/keyboardpainter.cpp
+++ b/kcontrol/keyboard/preview/keyboardpainter.cpp
@@ -41,7 +41,7 @@ KeyboardPainter::KeyboardPainter():
     levelBox->setFixedSize( 360, 30 );
 
     QVBoxLayout* vLayout = new QVBoxLayout( this );
-    QHBoxLayout* hLayout = new QHBoxLayout( this );
+    QHBoxLayout* hLayout = new QHBoxLayout();
 
     hLayout->addWidget(exitButton, 0, Qt::AlignLeft);
     hLayout->addWidget(levelBox, 0, Qt::AlignRight);
diff --git a/kcontrol/keyboard/preview/model_to_geometry.cpp \
b/kcontrol/keyboard/preview/model_to_geometry.cpp index a99addb..800bc9b 100644
--- a/kcontrol/keyboard/preview/model_to_geometry.cpp
+++ b/kcontrol/keyboard/preview/model_to_geometry.cpp
@@ -1,17 +1,19 @@
 
 #include "model_to_geometry.h"
+#include "../x11_helper.h"
 
+#include <QFile>
+#include <QDebug>
 
 ModelGroup :: ModelGroup(){
     modelCount = 0;
-    groupModels << QString();
 }
 
 void ModelGroup :: addGroupModel(QString model){
-    if( !groupModels.contain(model) ){
+    if( !groupModels.contains(model) ){
         groupModels << model;
         modelCount++;
-        groupModels << QString;
+        qDebug()<<modelCount;
     }
 }
 
@@ -20,29 +22,39 @@ QString ModelGroup :: getGroupModel( int i ){
         return groupModels.at(i);
     }
     else
-        return -1;
+        return QString();
 }
 
 
-QString ModelGroup :: containsModel(QSting model){
+int ModelGroup :: containsModel(QString model){
     for(int i = 0 ; i < modelCount; i++){
         if (model == groupModels.at(i)){
             return i;
         }
     }
-    else
-        return -1;
+    return -1;
+}
+
+void ModelGroup :: display(){
+    qDebug()<<groupName<<"\t"<<modelCount<<"\t"<<groupModels;
+}
+
+ModelToGeometry :: ModelToGeometry(){
 }
 
 ModelToGeometryTable :: ModelToGeometryTable(){
 
-    table << ModelToGeometry();
     modelGroups << ModelGroup();
     entryCount = 0;
     modelGroupCount = 0;
 
 }
 
+void ModelToGeometryTable :: addEntry(ModelToGeometry entry){
+    table << entry;
+    entryCount++;
+}
+
 QString ModelToGeometryTable :: getGeometryFile(QString model){
 
     for (int i = 0; i < entryCount ; i++){
@@ -53,7 +65,7 @@ QString ModelToGeometryTable :: getGeometryFile(QString model){
         if(tempModel.startsWith('$')){
             for ( int j = 0; j < modelGroupCount; j++){
                 ModelGroup temp = modelGroups.at(j);
-                if (temp.containsModel(model) > -1){
+                if (temp.groupName == tempModel && temp.containsModel(model) > -1){
                     return entry.getGeometryFile();
                 }
             }
@@ -63,35 +75,138 @@ QString ModelToGeometryTable :: getGeometryFile(QString model){
                 return entry.getGeometryFile();
             }
         }
-        return defaultGeometryFile;
-    }
 
+    }
+    return defaultGeometryFile;
 }
 
 
 QString ModelToGeometryTable :: getGeometryName(QString model){
-
     for (int i = 0; i < entryCount ; i++){
 
         ModelToGeometry entry = table.at(i);
         QString tempModel = entry.getModel();
-
         if(tempModel.startsWith('$')){
             for ( int j = 0; j < modelGroupCount; j++){
                 ModelGroup temp = modelGroups.at(j);
-                if (temp.containsModel(model) > -1){
-                    return entry.getGeometryName();
+                if (temp.groupName == tempModel && temp.containsModel(model) > -1){
+                    if(! (entry.getGeometryName() == "%m") ){
+                        return entry.getGeometryName();
+                    }
+                    else{
+                        return model;
+                    }
                 }
             }
         }
         else{
             if (tempModel == model){
-                return entry.getGeometryFile();
+                return entry.getGeometryName();
+           }
+        }
+    }
+    return defaultGeometryName;
+}
+
+void ModelToGeometryTable :: addModelGroup(){
+    modelGroups << ModelGroup();
+    modelGroupCount++;
+}
+
+void ModelToGeometryTable :: createTable(){
+
+    QString xkbDir = X11Helper::findXkbDir();
+    QString xkbRulesDir = QString("%1/rules/base").arg(xkbDir);
+    QFile baseFile(xkbRulesDir);
+    if (!baseFile.open(QIODevice::ReadOnly | QIODevice::Text)){
+        qDebug()<<"unable to open the file";
+    }
+
+    QString baseContent = baseFile.readAll();
+    baseFile.close();
+
+    QString tableStr = baseContent;
+    int index = tableStr.indexOf("! model		=	geometry");
+    tableStr = tableStr.mid(index);
+    tableStr = tableStr.left(tableStr.indexOf("!",1));
+    QStringList entries = tableStr.split("\n");
+
+    bool defaultEntry = false;
+
+    for (int i = 1 ; i < entries.size() - 1; i++){
+        QString tupple = entries.at(i);
+        ModelToGeometry currentEntry;
+        tupple.remove(" ");
+        tupple.remove("\t");
+        QStringList tuppleElements = tupple.split("=");
+        if(tuppleElements.size() == 2){
+            QString kbModel = tuppleElements.at(0);
+            currentEntry.setKbModel(kbModel);
+
+            if( kbModel == "*"){
+                defaultEntry = true;
+                qDebug()<<"here";
+            }
+            if(kbModel.startsWith("$")){
+                modelGroups.at(modelGroupCount).setGroupName(kbModel);
+                addModelGroup();
+            }
+
+            QString geomInfo = tuppleElements.at(1);
+            QStringList geometryFileinfo = geomInfo.split("(");
+            if(geometryFileinfo.size() == 2){
+                QString geometryFile = geometryFileinfo.at(0);
+                currentEntry.setGeometryFile(geometryFile);
+                QString geometryName = geometryFileinfo.at(1);
+                geometryName.remove(")");
+                if(geometryName == "intl")
+                    geometryName = "60";
+                currentEntry.setGeometryName(geometryName);
+                addEntry(currentEntry);
+                if(defaultEntry){
+                    defaultGeometryFile = geometryFile;
+                    defaultGeometryName = geometryName;
+                    defaultEntry = false;
+                }
             }
         }
-        return defaultGeometryName;
     }
+    createModelGroups(baseContent);
+    //display();
+}
+
+void ModelToGeometryTable :: createModelGroups(QString content){
+
+    QString groupStr = content;
+
+    for(int i = 0 ; i < modelGroupCount; i++){
+        QString input = groupStr;
+        QString gname = modelGroups.at(i).groupName;
+        int index = input.indexOf(gname);
+        input = input.mid(index);
+        input = input.left(input.indexOf("\n"));
+        //qDebug()<<"input: "<<input;
+        QString modelList = input.split("=").at(1);
+        QStringList models = modelList.split(" ");
+        ModelGroup temp =  modelGroups.at(i);
+        for(int j = 1; j < models.size(); j++){
+            qDebug()<<"model At"<<j<<":"<<models.at(j);
+            QString model = models.at(j);
+            temp.addGroupModel(model);
+        }
+        modelGroups.replace(i, temp);
 
+    }
 }
 
+void ModelToGeometryTable :: display(){
+    for(int i = 0 ; i < entryCount; i++){
+        ModelToGeometry temp = table.at(i);
+        qDebug() << temp.getModel() << "\t"<<temp.getGeometryFile()<<"\t"<<temp.getGeometryName();
+    }
+    for (int i = 0; i < modelGroupCount; i ++){
+        ModelGroup temp = modelGroups.at(i);
+        temp.display();
+    }
+}
 
diff --git a/kcontrol/keyboard/preview/model_to_geometry.h \
b/kcontrol/keyboard/preview/model_to_geometry.h index 07f8ae2..a706ad9 100644
--- a/kcontrol/keyboard/preview/model_to_geometry.h
+++ b/kcontrol/keyboard/preview/model_to_geometry.h
@@ -36,14 +36,19 @@ class ModelGroup {
 
     void addGroupModel( QString model );
 
+    void setGroupName(QString name){
+        groupName = name;
+    }
+
     QString getGroupModel(int i);
 
-    int getmodelCount(){
+    int getModelCount(){
         return modelCount;
     }
 
-    int containsModel(QSting model);
+    int containsModel(QString model);
 
+    void display();
 };
 
 
@@ -98,6 +103,11 @@ public:
 
     QString getGeometryName(QString model);
     QString getGeometryFile(QString model);
+    void createTable();
+    void addEntry(ModelToGeometry currentEntry);
+    void display();
+    void createModelGroups(QString content);
+    void addModelGroup();
 
 };
 
diff --git a/kcontrol/keyboard/preview/symbol_parser.cpp b/kcontrol/keyboard/preview/symbol_parser.cpp
index 9eabd91..6a76fb8 100644
--- a/kcontrol/keyboard/preview/symbol_parser.cpp
+++ b/kcontrol/keyboard/preview/symbol_parser.cpp
@@ -66,7 +66,7 @@ Symbol_parser<Iterator>::Symbol_parser():Symbol_parser::base_type(start){
 
     group = lit("Group")>>int_;
 
-    comments =lexeme[ \
lit("//")>>*(char_-eol||skw-eol)>>eol||lit("/*")>>*(char_-lit("*/")||skw-lit("*/"))>>lit("*/") ]; +    \
comments =lexeme[ lit("//")>>*(char_-eol||symbolKeyword-eol)>>eol||lit("/*")>>*(char_-lit("*/")||symbolKeyword-lit("*/"))>>lit("*/") \
];  
     include = lit("include")>>name[phx::bind(&Symbol_parser::getInclude,this,_1)];
 
@@ -88,7 +88,7 @@ Symbol_parser<Iterator>::Symbol_parser():Symbol_parser::base_type(start){
        >>lit("};"))
        ||lit("key")>>lit(".")>>type>>lit(";");
 
-    ee = *(char_ - skw - '{')>>'{'>>*(char_-'}'-';')>>lit("};");
+    ee = *(char_ - symbolKeyword - '{')>>'{'>>*(char_-'}'-';')>>lit("};");
 
 
     start = *(char_ - lit("xkb_symbols")||comments)
@@ -98,7 +98,7 @@ Symbol_parser<Iterator>::Symbol_parser():Symbol_parser::base_type(start){
         >>*(key[phx::bind(&Symbol_parser::addKey,this)]
         ||include
         ||ee
-        ||char_-'}'-skw
+        ||char_-'}'-symbolKeyword
         ||comments)
         >>lit("};")
         >>*(comments||char_);
@@ -193,22 +193,22 @@ QString findLayout(const QString& layout, const QString& layoutVariant){
     }
 
     else{
-        int i = 1;
+        int current = 1;
 
-        while (layoutVariant != variant && i < scontentList.size()) {
-            input = scontentList.at(i);
+        while (layoutVariant != variant && current < scontentList.size()) {
+            input = scontentList.at(current);
 
-            QString h = scontentList.at(i);
+            QString symbolCont = scontentList.at(current);
 
-            int k = h.indexOf("\"");
-            h = h.mid(k);
-            k = h.indexOf("{");
-            h = h.left(k);
-            h = h.remove(" ");
-            variant = h.remove("\"");
+            int index = symbolCont.indexOf("\"");
+            symbolCont = symbolCont.mid(index);
+            index = symbolCont.indexOf("{");
+            symbolCont = symbolCont.left(index);
+            symbolCont = symbolCont.remove(" ");
+            variant = symbolCont.remove("\"");
 
             input.prepend("xkb_symbols");
-            i++;
+            current++;
         }
     }
 
@@ -221,17 +221,17 @@ KbLayout parseSymbols(const QString& layout, const QString& layoutVariant){
     typedef std::string::const_iterator iterator_type;
     typedef grammar::Symbol_parser<iterator_type> Symbol_parser;
 
-    Symbol_parser s;
+    Symbol_parser symbolParser;
 
-    s.layout.country = layout;
+    symbolParser.layout.country = layout;
     QString input = findLayout(layout, layoutVariant);
 
-    std::string xyz = input.toUtf8().constData();
+    std::string parserInput = input.toUtf8().constData();
 
-    std::string::const_iterator iter = xyz.begin();
-    std::string::const_iterator end = xyz.end();
+    std::string::const_iterator iter = parserInput.begin();
+    std::string::const_iterator end = parserInput.end();
 
-    bool r = phrase_parse(iter, end, s, space);
+    bool success = phrase_parse(iter, end, symbolParser, space);
 
     /*if (r && iter == end){
         std::cout << "-------------------------\n";
@@ -246,14 +246,14 @@ KbLayout parseSymbols(const QString& layout, const QString& layoutVariant){
     }*/
 
 
-    for(int j = 0; j < s.layout.getIncludeCount(); j++){
-        QString include = s.layout.getInclude(j);
+    for(int currentInclude = 0; currentInclude < symbolParser.layout.getIncludeCount(); \
currentInclude++){ +        QString include = symbolParser.layout.getInclude(currentInclude);
         QStringList includeFile = include.split("(");
         if(includeFile.size() == 2){
-            QString l = includeFile.at(0);
-            QString lv = includeFile.at(1);
-            lv.remove(")");
-            input = findLayout(l,lv);
+            QString file = includeFile.at(0);
+            QString layout = includeFile.at(1);
+            layout.remove(")");
+            input = findLayout(file, layout);
 
         }
 
@@ -263,12 +263,12 @@ KbLayout parseSymbols(const QString& layout, const QString& layoutVariant){
             input = findLayout(includeFile.at(0),a);
         }
 
-        xyz = input.toUtf8().constData();
+        parserInput = input.toUtf8().constData();
 
-        std::string::const_iterator iter = xyz.begin();
-        std::string::const_iterator end = xyz.end();
+        std::string::const_iterator iter = parserInput.begin();
+        std::string::const_iterator end = parserInput.end();
 
-        bool r = phrase_parse(iter, end, s, space);
+        bool success = phrase_parse(iter, end, symbolParser, space);
 
         /*if (r && iter == end){
             std::cout << "-------------------------\n";
@@ -285,7 +285,7 @@ KbLayout parseSymbols(const QString& layout, const QString& layoutVariant){
 
     //s.layout.display();
 
-    return s.layout;
+    return symbolParser.layout;
 }
 
 }
diff --git a/kcontrol/keyboard/preview/symbol_parser.h b/kcontrol/keyboard/preview/symbol_parser.h
index 4e4ada2..1d8a24e 100644
--- a/kcontrol/keyboard/preview/symbol_parser.h
+++ b/kcontrol/keyboard/preview/symbol_parser.h
@@ -74,7 +74,7 @@ namespace grammar {
 
         KbLayout layout;
         int keyIndex, newKey;
-        symbol_keywords skw;
+        symbol_keywords symbolKeyword;
         levels lvl;
         Aliases alias;
 
diff --git a/kcontrol/keyboard/tests/CMakeLists.txt b/kcontrol/keyboard/tests/CMakeLists.txt
index 102b50e..b818a18 100644
--- a/kcontrol/keyboard/tests/CMakeLists.txt
+++ b/kcontrol/keyboard/tests/CMakeLists.txt
@@ -23,7 +23,7 @@ if(Boost_FOUND)
     ADD_DEFINITIONS(-DNEW_GEOMETRY=1)
     include_directories(..)
 
-    kde4_add_unit_test(geometry_parser_test TESTNAME geometry_parser NOGUI \
../preview/geometry_parser.cpp ../preview/geometry_components.cpp geometry_parser_test.cpp \
../x11_helper.cpp) +    kde4_add_unit_test(geometry_parser_test TESTNAME geometry_parser NOGUI \
../preview/geometry_parser.cpp ../preview/geometry_components.cpp geometry_parser_test.cpp \
../x11_helper.cpp ../preview/model_to_geometry.cpp)  
     kde4_add_unit_test(symbol_parser_test TESTNAME symbol_parser NOGUI ../preview/symbol_parser.cpp \
../preview/keyboardlayout.cpp symbol_parser_test.cpp ../x11_helper.cpp ../preview/keyaliases.cpp)  


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic