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

List:       kde-commits
Subject:    [kde-workspace/previewsoc13] kcontrol/keyboard: wraping up cleanup and tests
From:       shivam makkar <amourphious1992 () gmail ! com>
Date:       2013-09-13 18:42:20
Message-ID: E1VKYJw-00065l-PE () scm ! kde ! org
[Download RAW message or body]

Git commit e990bfdda7a991c1f3e867ed84710fd31d01975a by shivam makkar.
Committed on 13/09/2013 at 18:38.
Pushed by makkar into branch 'previewsoc13'.

wraping up cleanup and tests

M  +0    -1    kcontrol/keyboard/CMakeLists.txt
M  +32   -11   kcontrol/keyboard/preview/geometry_components.cpp
M  +18   -0    kcontrol/keyboard/preview/geometry_components.h
M  +72   -45   kcontrol/keyboard/preview/geometry_parser.cpp
M  +55   -3    kcontrol/keyboard/preview/geometry_parser.h
M  +8    -1    kcontrol/keyboard/preview/kbpreviewframe.cpp
M  +19   -1    kcontrol/keyboard/preview/keyboardlayout.cpp
M  +4    -4    kcontrol/keyboard/preview/keyboardpainter.cpp
D  +0    -37   kcontrol/keyboard/preview/keysymbols.h
M  +21   -6    kcontrol/keyboard/preview/symbol_parser.cpp
M  +19   -0    kcontrol/keyboard/preview/symbol_parser.h
M  +5    -0    kcontrol/keyboard/tests/CMakeLists.txt
M  +1    -0    kcontrol/keyboard/tests/geometry_parser_test.cpp
R  +28   -34   kcontrol/keyboard/tests/symbol_parser_test.cpp [from: \
kcontrol/keyboard/preview/keysymbols.cpp - 050% similarity]

http://commits.kde.org/kde-workspace/e990bfdda7a991c1f3e867ed84710fd31d01975a

diff --git a/kcontrol/keyboard/CMakeLists.txt b/kcontrol/keyboard/CMakeLists.txt
index 3a2e729..ad92fa3 100644
--- a/kcontrol/keyboard/CMakeLists.txt
+++ b/kcontrol/keyboard/CMakeLists.txt
@@ -116,7 +116,6 @@ if(Boost_FOUND)
     preview/keyaliases.cpp
     preview/keyboardlayout.cpp
     preview/keyboardpainter.cpp
-    preview/keysymbols.cpp
     preview/keysymhelper.cpp
     preview/keysym2ucs.cpp)
   
diff --git a/kcontrol/keyboard/preview/geometry_components.cpp \
b/kcontrol/keyboard/preview/geometry_components.cpp index 4ce3f87..3ce015a 100644
--- a/kcontrol/keyboard/preview/geometry_components.cpp
+++ b/kcontrol/keyboard/preview/geometry_components.cpp
@@ -1,3 +1,22 @@
+/*
+ *  Copyright (C) 2012 Shivam Makkar (amourphious1992@gmail.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+
 #include "geometry_components.h"
 
 #include <QtCore/QString>
@@ -36,19 +55,21 @@ void GShape::display(){
 }
 
 double GShape::size(int vertical) const{
-    if(vertical == 0){
-        if (approx.x() == 0 && approx.y() == 0)
-            return cordii[0].x();
-        else
-            return approx.x();
-    }
+    if( !cordii.isEmpty() ){
+        if(vertical == 0){
+            if (approx.x() == 0 && approx.y() == 0)
+                return cordii[0].x();
+            else
+                return approx.x();
+        }
 
-    else
-        if (approx.x() == 0 && approx.y() == 0)
-            return cordii[0].y();
         else
-            return approx.y();
-
+            if (approx.x() == 0 && approx.y() == 0)
+                return cordii[0].y();
+            else
+                return approx.y();
+    }
+    return 0;
 }
 
 
diff --git a/kcontrol/keyboard/preview/geometry_components.h \
b/kcontrol/keyboard/preview/geometry_components.h index e686302..d8e3ae8 100644
--- a/kcontrol/keyboard/preview/geometry_components.h
+++ b/kcontrol/keyboard/preview/geometry_components.h
@@ -1,3 +1,21 @@
+/*
+ *  Copyright (C) 2012 Shivam Makkar (amourphious1992@gmail.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
 #ifndef GEOMETRY_COMPONENTS_H
 #define GEOMETRY_COMPONENTS_H
 
diff --git a/kcontrol/keyboard/preview/geometry_parser.cpp \
b/kcontrol/keyboard/preview/geometry_parser.cpp index 7a255be..06a51a1 100644
--- a/kcontrol/keyboard/preview/geometry_parser.cpp
+++ b/kcontrol/keyboard/preview/geometry_parser.cpp
@@ -21,7 +21,6 @@
 #include "x11_helper.h"
 
 #include <QtCore/QString>
-#include <QtCore/QStringList>
 #include <QtCore/QDebug>
 #include <QFileDialog>
 #include <QFile>
@@ -476,7 +475,7 @@ template<typename Iterator>
             cy+=geom.sectionList[secn].rowList[rown].keyList[keyn].getOffset();
         geom.sectionList[secn].rowList[rown].keyList[keyn].setKeyPosition(cx, cy);
         QString s = geom.sectionList[secn].rowList[rown].keyList[keyn].getShapeName();
-        if (s=="")
+        if ( s.isEmpty() )
             s = geom.getKeyShape();
         GShape t = geom.findShape(s);
         int a = t.size(vertical);
@@ -488,84 +487,108 @@ template<typename Iterator>
     }
 
 
-    QPair <QString, QString> mapModelToGeometry(QString model){
-        QStringList pcmodels;
-        QStringList msmodels;
-        QStringList nokiamodels;
-        QStringList pcgeometries;
-        QStringList macbooks;
-        QStringList applealu;
-        QStringList macs;
-        pcmodels << "pc101" << "pc102" << "pc104" << "pc105";
-        msmodels << "microsoft" << "microsoft4000" << "microsoft7000" << "microsoftpro" << \
                "microsoftprousb" << "microsoftprose";
-        nokiamodels << "nokiasu8w" << "nokiarx44" << "nokiarx51";
-        pcgeometries << "latitude";
-        macbooks << "macbook78" << "macbook79";
-        applealu << "applealu_ansi" << "applealu_iso" << "applealu_jis";
-        macs << "macintosh" << "macintosh_old" << "ibook" << "powerbook" << "macbook78" << "macbook79";
-
-        if (model == "thinkpad     us"){
-            return(QPair<QString, QString> ("thinkpad", "us"));
-        }
+    QStringList ModelToGeometry :: pcmodels = QStringList() << "pc101" << "pc102" << "pc104" << "pc105" \
; +    QStringList ModelToGeometry :: msmodels = QStringList() << "microsoft"<< "microsoft4000"<< \
"microsoft7000"<< "microsoftpro"<< "microsoftprousb"<< "microsoftprose"; +    QStringList ModelToGeometry \
:: nokiamodels = QStringList() << "nokiasu8w" << "nokiarx44"<< "nokiarx51" ; +    QStringList \
ModelToGeometry :: pcgeometries = QStringList() << "latitude" ; +    QStringList ModelToGeometry :: \
macbooks = QStringList() << "macbook78" << "macbook79"; +    QStringList ModelToGeometry :: applealu = \
QStringList() << "applealu_ansi" << "applealu_iso" << "applealu_jis"; +    QStringList ModelToGeometry :: \
macs = QStringList() << "macintosh" << "macintosh_old" << "ibook" << "powerbook" << "macbook78" << \
"macbook79"; +
+    ModelToGeometry :: ModelToGeometry(QString model){
+
+        geometryFile = "pc";
+        geometryName = "pc104";
+        kbModel = model;
+
         if (model == "microsoftelite"){
-            return(QPair<QString, QString> ("microsoft", "elite"));
+            geometryFile = "microsoft";
+            geometryName = "elite";
         }
+
         if (msmodels.contains(model)){
-            return(QPair<QString, QString> ("microsoft", "natural"));
+            geometryFile = "microsoft";
+            geometryName = "natural";
         }
+
         if (model == "dell101"){
-            return(QPair<QString, QString> ("dell", "dell101"));
+            geometryFile = "dell";
+            geometryName = "dell101";
         }
+
         if (model == "dellm65"){
-            return(QPair<QString, QString> ("dell", "dellm65"));
+            geometryFile = "dell";
+            geometryName = "dellm65";
         }
         if (model == "latitude"){
-            return(QPair<QString, QString> ("dell", "latitude"));
+            geometryFile = "dell";
+            geometryName = "latitude";
         }
         if (model == "flexpro"){
-            return(QPair<QString, QString> ("keytronic", "FlexPro"));
+            geometryFile = "keytronic";
+            geometryName = "FlexPro";
         }
         if(model == "hp6000" || model == "hpmini110"){
-            return(QPair<QString, QString> ("hp", "mini110"));
+            geometryFile = "hp";
+            geometryName = "mini110";
         }
         if(model == "hpdv5"){
-            return(QPair<QString, QString> ("hp", "dv5"));
+            geometryFile = "hp";
+            geometryName = "dv5";
         }
         if(model == "omnikey101"){
-            return(QPair<QString, QString> ("northgate", "omnikey101"));
+            geometryFile = "northgate";
+            geometryName = "omnikey101";
         }
         if(model == "sanwaskbkg3"){
-            return(QPair<QString, QString> ("sanwa", "sanwaskbkg3"));
+            geometryFile = "sanwa";
+            geometryName = "sanwaskbkg3";
         }
         if(pcmodels.contains(model) || pcgeometries.contains(model)){
-            return(QPair<QString, QString> ("pc", model));
+            geometryFile = "pc";
+            geometryName = model;
         }
         if(model == "everex"){
-            return(QPair<QString, QString> ("everex", "STEPnote"));
+            geometryFile = "everex";
+            geometryName = "STEPnote";
         }
         if(model.contains("thinkpad")){
-            return(QPair<QString, QString> ("thinkpad", "60"));
+            geometryFile = "thinkpad";
+            geometryName = "60";
         }
         if(model == "winbook"){
-            return(QPair<QString, QString> ("winbook", "XP5"));
+            geometryFile = "winbook";
+            geometryName = "XP5";
         }
         if(model == "pc98"){
-            return(QPair<QString, QString> ("nec", "pc98"));
+            geometryFile = "nec";
+            geometryName = "pc98";
         }
         if(model == "hhk"){
-            return(QPair<QString, QString> ("hhk", "basic"));
+            geometryFile = "hhk";
+            geometryName = "basic";
         }
         if(model == "kinesis"){
-            return(QPair<QString, QString> ("kinesis", "model100"));
+            geometryFile = "kinesis";
+            geometryName = "model100";
         }
         if(nokiamodels.contains(model)){
-            return(QPair<QString, QString> ("nokia", "+model"));
+            geometryFile = "nokia";
+            geometryName = model;
         }
         if(macs.contains(model) || macbooks.contains(model) || applealu.contains(model)){
-            return(QPair<QString, QString> ("macintosh", "+model"));
+            geometryFile = "macintosh";
+            geometryName = model;
         }
 
-        return(QPair<QString, QString> ("pc", "pc104"));
+    }
+
+
+
+    ModelToGeometry :: ModelToGeometry(){
+        geometryFile = "pc";
+        geometryName = "pc104";
+        kbModel = "pc104";
     }
 
 
@@ -575,12 +598,13 @@ template<typename Iterator>
         typedef std::string::const_iterator iterator_type;
         typedef grammar::Geometry_parser<iterator_type> Geometry_parser;
         Geometry_parser g;
+        ModelToGeometry m2g = ModelToGeometry(model);
 
-        QPair<QString, QString> geometry = mapModelToGeometry(model);
         //qDebug()<<geometry;
-        QString geometryFile = geometry.first;
-        QString geometryName = geometry.second;
+        QString geometryFile = m2g.getGeometryFile();
+        QString geometryName = m2g.getGeometryName();
         //qDebug()<< geometryFile << geometryName;
+
         QString xkbParentDir = findGeometryBaseDir();
         geometryFile.prepend(xkbParentDir);
         QFile gfile(geometryFile);
@@ -588,11 +612,14 @@ template<typename Iterator>
              qDebug()<<"unable to open the file";
              return g.geom;
         }
+
         QString gcontent = gfile.readAll();
         gfile.close();
+
         QStringList gcontentList = gcontent.split("xkb_geometry");
+
         int i = 1;
-        while(g.geom.getName()!=geometryName){
+        while(g.geom.getName()!=geometryName && i < gcontentList.size() ){
             g.geom = Geometry();
             QString input = gcontentList.at(i);
             input.prepend("xkb_geometry");
diff --git a/kcontrol/keyboard/preview/geometry_parser.h b/kcontrol/keyboard/preview/geometry_parser.h
index e6bdf7a..20a9159 100644
--- a/kcontrol/keyboard/preview/geometry_parser.h
+++ b/kcontrol/keyboard/preview/geometry_parser.h
@@ -1,3 +1,22 @@
+/*
+ *  Copyright (C) 2012 Shivam Makkar (amourphious1992@gmail.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+
 #ifndef GEOMETRY_PARSER_H
 #define GEOMETRY_PARSER_H
 
@@ -16,6 +35,7 @@
 
 #include <iostream>
 #include <QtCore/QDebug>
+#include <QtCore/QStringList>
 
 #include "geometry_components.h"
 
@@ -91,7 +111,7 @@ namespace grammar{
     double x, y, ax, ay, cx, cy, off;
     Geometry_parser();
 
-    //funcions for shape
+    //functions for shape
     void getShapeName(std::string n);
     void setCord();
     void setApprox();
@@ -104,7 +124,7 @@ namespace grammar{
     void setSectionAngle(double a);
     void sectioninit();
 
-    //funtions for row
+    //functions for row
     void setRowShape(std::string n);
     void setRowTop(double a);
     void setRowLeft(double a);
@@ -129,10 +149,42 @@ namespace grammar{
     void setVerticalGeometry();
 		
   };
+
+  class ModelToGeometry{
+
+      static QStringList pcmodels;
+      static QStringList msmodels;
+      static QStringList nokiamodels;
+      static QStringList pcgeometries;
+      static QStringList macbooks;
+      static QStringList applealu;
+      static QStringList macs;
+
+      QString geometryName;
+      QString geometryFile;
+      QString kbModel;
+
+  public :
+
+      ModelToGeometry();
+      ModelToGeometry(QString model);
+
+      QString getGeometryFile(){
+          return geometryFile;
+      }
+
+      QString getGeometryName(){
+          return geometryName;
+      }
+
+      QString getModel(){
+          return kbModel;
+      }
+
+  };
   
   Geometry parseGeometry(QString model);
 
-  QPair<QString, QString> mapModelToGeometry(QString model);
 
   QString findGeometryBaseDir();
   
diff --git a/kcontrol/keyboard/preview/kbpreviewframe.cpp b/kcontrol/keyboard/preview/kbpreviewframe.cpp
index a7c8565..6e13ed3 100644
--- a/kcontrol/keyboard/preview/kbpreviewframe.cpp
+++ b/kcontrol/keyboard/preview/kbpreviewframe.cpp
@@ -65,6 +65,8 @@ int KbPreviewFrame::getWidth() const { return geometry.width; }
 int KbPreviewFrame::getHeight() const { return geometry.height; }
 
 
+
+//writes text on the keys call only by paintevent
 void KbPreviewFrame::drawKeySymbols(QPainter &painter,QPoint temp[], const GShape& s, const QString& \
name)  {
     int keyindex = keyboardLayout.findKey(name);
@@ -130,6 +132,7 @@ void KbPreviewFrame::drawKeySymbols(QPainter &painter,QPoint temp[], const GShap
 }
 
 
+//draws key shape on QFrame called only by paint event
 void KbPreviewFrame::drawShape(QPainter &painter, const GShape& s, int x, int y, int i, const QString& \
name){  painter.setPen(Qt::black);
     int cordi_count = s.getCordi_count();
@@ -228,6 +231,8 @@ void KbPreviewFrame::drawShape(QPainter &painter, const GShape& s, int x, int y,
 
 }
 
+
+//event handling for tooltip
 bool KbPreviewFrame::event(QEvent* event){
 
     if (event->type() == QEvent::ToolTip) {
@@ -312,7 +317,7 @@ void KbPreviewFrame::paintEvent(QPaintEvent *)
 
 }
 
-
+// this function draws the keyboard preview on a QFrame
 void KbPreviewFrame :: generateKeyboardLayout(const QString& layout, const QString& layoutVariant, const \
QString& model)  {
 
@@ -322,6 +327,8 @@ void KbPreviewFrame :: generateKeyboardLayout(const QString& layout, const QStri
 
 }
 
+
+//this functions give the index of the tooltip over which mouse hovers
 int KbPreviewFrame::itemAt(const QPoint& pos){
     int distance =  10000;
     int closest = 0;
diff --git a/kcontrol/keyboard/preview/keyboardlayout.cpp b/kcontrol/keyboard/preview/keyboardlayout.cpp
index ae72bd0..5a7898a 100644
--- a/kcontrol/keyboard/preview/keyboardlayout.cpp
+++ b/kcontrol/keyboard/preview/keyboardlayout.cpp
@@ -1,4 +1,22 @@
- 
+/*
+ *  Copyright (C) 2013 Shivam Makkar (amourphious1992@gmail.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+
 #include "keyboardlayout.h"
 
 #include <QDebug>
diff --git a/kcontrol/keyboard/preview/keyboardpainter.cpp \
b/kcontrol/keyboard/preview/keyboardpainter.cpp index a2cfcce..87beec8 100644
--- a/kcontrol/keyboard/preview/keyboardpainter.cpp
+++ b/kcontrol/keyboard/preview/keyboardpainter.cpp
@@ -23,7 +23,7 @@
 #include <QtGui/QVBoxLayout>
 #include <QtGui/QPushButton>
 #include <QtGui/QComboBox>
-#include <QtGui/QHBoxLayout>
+
 
 #include <KLocale>
 
@@ -67,10 +67,10 @@ void KeyboardPainter::generateKeyboardLayout(const QString& layout, const QStrin
     int level = kbframe->getLevel();
 
     if(level > 4){
-        levelBox->addItem( i18n("Level 3, 4") );
-        levelBox->addItem( i18n("Level 5, 6") );
+        levelBox->addItem( "Level 3, 4" );
+        levelBox->addItem( "Level 5, 6" );
         if(level > 6)
-            levelBox->addItem( i18n("Level 7,8") );
+            levelBox->addItem( "Level 7,8" );
     }
     else
         levelBox->setVisible(false);
diff --git a/kcontrol/keyboard/preview/keysymbols.h b/kcontrol/keyboard/preview/keysymbols.h
deleted file mode 100644
index 8dfaee7..0000000
--- a/kcontrol/keyboard/preview/keysymbols.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *  Copyright (C) 2012 Shivam Makkar (amourphious1992@gmail.com)
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
- 
-
-#ifndef KEYSYMBOLS_H
-#define KEYSYMBOLS_H
-
-#include <QtGui/QApplication>
-#include <QtCore/QList>
-
-class KeySymbols
-{
-public:
-	KeySymbols();
-
-    QString keyname;
-    QList<QString> symbols;
-
-    void setKey(const QString& opton);
-};
-
-#endif // KEYSYMBOLS_H
diff --git a/kcontrol/keyboard/preview/symbol_parser.cpp b/kcontrol/keyboard/preview/symbol_parser.cpp
index 184c4d1..9eabd91 100644
--- a/kcontrol/keyboard/preview/symbol_parser.cpp
+++ b/kcontrol/keyboard/preview/symbol_parser.cpp
@@ -1,7 +1,22 @@
+/*
+ *  Copyright (C) 2013 Shivam Makkar (amourphious1992@gmail.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
 #include "symbol_parser.h"
-#include "keyboardlayout.h"
-#include "keyaliases.h"
-#include "x11_helper.h"
 
 #include <QtCore/QString>
 #include <QtCore/QStringList>
@@ -10,7 +25,6 @@
 #include <QFile>
 
 
-
 namespace grammar{
 
 symbol_keywords :: symbol_keywords(){
@@ -244,7 +258,8 @@ KbLayout parseSymbols(const QString& layout, const QString& layoutVariant){
         }
 
         else{
-            QString a = QString();
+            QString a;
+            a.clear();
             input = findLayout(includeFile.at(0),a);
         }
 
@@ -268,7 +283,7 @@ KbLayout parseSymbols(const QString& layout, const QString& layoutVariant){
         }*/
     }
 
-    s.layout.display();
+    //s.layout.display();
 
     return s.layout;
 }
diff --git a/kcontrol/keyboard/preview/symbol_parser.h b/kcontrol/keyboard/preview/symbol_parser.h
index 8148e08..3d3690a 100644
--- a/kcontrol/keyboard/preview/symbol_parser.h
+++ b/kcontrol/keyboard/preview/symbol_parser.h
@@ -1,3 +1,21 @@
+/*
+ *  Copyright (C) 2013 Shivam Makkar (amourphious1992@gmail.com)
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
 #ifndef SYMBOL_PARSER_H
 #define SYMBOL_PARSER_H
 
@@ -18,6 +36,7 @@
 
 #include "keyboardlayout.h"
 #include "keyaliases.h"
+#include "x11_helper.h"
 
 namespace qi = boost::spirit::qi;
 namespace ascii = boost::spirit::ascii;
diff --git a/kcontrol/keyboard/tests/CMakeLists.txt b/kcontrol/keyboard/tests/CMakeLists.txt
index eb0dd1e..102b50e 100644
--- a/kcontrol/keyboard/tests/CMakeLists.txt
+++ b/kcontrol/keyboard/tests/CMakeLists.txt
@@ -24,7 +24,12 @@ if(Boost_FOUND)
     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(symbol_parser_test TESTNAME symbol_parser NOGUI ../preview/symbol_parser.cpp \
../preview/keyboardlayout.cpp symbol_parser_test.cpp ../x11_helper.cpp ../preview/keyaliases.cpp) +    
     target_link_libraries(geometry_parser_test ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY} ${X11_LIBRARIES})
+    target_link_libraries(symbol_parser_test ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY} ${X11_LIBRARIES})
+    
 endif(Boost_FOUND)
 
 kde4_add_unit_test(flags_test TESTNAME kcm-keyboard-flags_test NOGUI flags_test.cpp ../flags.cpp \
                ../x11_helper.cpp ../keyboard_config.cpp ../xkb_rules.cpp)
diff --git a/kcontrol/keyboard/tests/geometry_parser_test.cpp \
b/kcontrol/keyboard/tests/geometry_parser_test.cpp index c1eff3b..938198c 100644
--- a/kcontrol/keyboard/tests/geometry_parser_test.cpp
+++ b/kcontrol/keyboard/tests/geometry_parser_test.cpp
@@ -43,6 +43,7 @@ private Q_SLOTS:
         QVERIFY( geometry.getWidth() > 0 );
         QVERIFY( geometry.getShapeCount() > 0 );
 //        QVERIFY( ! geometry.getName().isEmpty() );
+        QVERIFY( !geometry.getDescription().isEmpty() );
 
         QCOMPARE( geometry.getName(), QString("pc104") );
     }
diff --git a/kcontrol/keyboard/preview/keysymbols.cpp b/kcontrol/keyboard/tests/symbol_parser_test.cpp
similarity index 50%
rename from kcontrol/keyboard/preview/keysymbols.cpp
rename to kcontrol/keyboard/tests/symbol_parser_test.cpp
index dc54e33..8bc4124 100644
--- a/kcontrol/keyboard/preview/keysymbols.cpp
+++ b/kcontrol/keyboard/tests/symbol_parser_test.cpp
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2012 Shivam Makkar (amourphious1992@gmail.com)
+ *  Copyright (C) 2011 Andriy Rysin (rysin@kde.org), Shivam Makkar (amourphious1992@gmail.com)
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -16,46 +16,40 @@
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
-
-#include "keysymbols.h"
-
+#include <kdebug.h>
 #include <QtGui/QApplication>
-#include <QtCore/QStringList>
+#include <qtest_kde.h>
 
+#include "symbol_parser.h"
 
-static const int MAX_GROUPS_SUPPORTED = 4;
 
-KeySymbols::KeySymbols()
+class SymbolParserTest : public QObject
 {
-}
+    Q_OBJECT
 
+    KbLayout kblayout;
 
-void KeySymbols::setKey(const QString& a)
-{
-    int i=a.indexOf("<");
-    i++;
-    keyname=a.mid(i,4);
-    keyname.remove(" ");
-    i=a.indexOf("[");
-    i++;
-
-    QString str=a.mid(i);
-    i=str.indexOf("]");
-
-    QString st=str.left(i);
-    st=st.remove(" ");
-    //QStringList klst;
-    symbols=st.split(",");
-
-    if( symbols.size() > MAX_GROUPS_SUPPORTED ) {
-    	symbols = symbols.mid(0, MAX_GROUPS_SUPPORTED);
+private Q_SLOTS:
+    void initTestCase() {
+    QString layout("us");
+    QString variant("basic");
+    kblayout = grammar::parseSymbols(layout, variant);
+    }
+
+    void cleanupTestCase() {
+//    	delete kblayout;
     }
 
-    for(int k=0; k<symbols.size(); k++){
-        QString du=symbols.at(k);
-        du.remove(" ");
-        du.remove("\t");
-        du.remove("\n");
-        symbols[k]=du;
+    void testSymbolParser() {
+        QVERIFY( kblayout.getKeyCount() > 0 );
+        QVERIFY( !kblayout.getLayoutName().isEmpty() );
+        QCOMPARE( kblayout.country, QString("us") );
     }
-}
+
+};
+
+//TODO: something lighter than KDEMAIN ?
+QTEST_KDEMAIN( SymbolParserTest, NoGUI )
+
+#include "symbol_parser_test.moc"
+


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

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