[PC-BSD Commits] r18356 - pcbsd-projects/PCDM

svn at pcbsd.org svn at pcbsd.org
Wed Aug 8 11:38:16 PDT 2012


Author: kenmoore
Date: 2012-08-08 18:38:16 +0000 (Wed, 08 Aug 2012)
New Revision: 18356

Added:
   pcbsd-projects/PCDM/dialogKeyboard.cpp
   pcbsd-projects/PCDM/dialogKeyboard.h
   pcbsd-projects/PCDM/dialogKeyboard.ui
Modified:
   pcbsd-projects/PCDM/PCDM.pro
   pcbsd-projects/PCDM/pcdm-backend.cpp
   pcbsd-projects/PCDM/pcdm-backend.h
   pcbsd-projects/PCDM/pcdm-gui.cpp
   pcbsd-projects/PCDM/pcdm-gui.h
Log:
Add the keyboard Layout switching capability into PCDM



Modified: pcbsd-projects/PCDM/PCDM.pro
===================================================================
--- pcbsd-projects/PCDM/PCDM.pro	2012-08-08 17:04:34 UTC (rev 18355)
+++ pcbsd-projects/PCDM/PCDM.pro	2012-08-08 18:38:16 UTC (rev 18356)
@@ -8,13 +8,17 @@
     	   pcdm-backend.cpp \
     	   pcdm-themes.cpp \
            pcdm-config.cpp \
-           fancySwitcher.cpp
+           fancySwitcher.cpp \
+           dialogKeyboard.cpp
 
 HEADERS += pcdm-gui.h \
     	   pcdm-backend.h \
 	   pcdm-themes.h \
            pcdm-config.h \
-           fancySwitcher.h
+           fancySwitcher.h \
+           dialogKeyboard.h
+           
+FORMS += dialogKeyboard.ui
 
 TRANSLATIONS =  i18n/PCDM_af.ts \
 		i18n/PCDM_ar.ts \

Index: pcbsd-projects/PCDM/dialogKeyboard.ui
===================================================================
--- pcbsd-projects/PCDM/dialogKeyboard.ui	2012-08-08 17:04:34 UTC (rev 18355)
+++ pcbsd-projects/PCDM/dialogKeyboard.ui	2012-08-08 18:38:16 UTC (rev 18356)

Property changes on: pcbsd-projects/PCDM/dialogKeyboard.ui
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/xml
Modified: pcbsd-projects/PCDM/pcdm-backend.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-backend.cpp	2012-08-08 17:04:34 UTC (rev 18355)
+++ pcbsd-projects/PCDM/pcdm-backend.cpp	2012-08-08 18:38:16 UTC (rev 18356)
@@ -1,5 +1,3 @@
-//#include <sys/param.h>
-//#include <sys/wait.h>
 #include <sys/types.h>
 #include <security/pam_appl.h>
 
@@ -83,6 +81,89 @@
   return usernameList[i];
 }
 
+QStringList Backend::keyModels()
+{
+    QStringList _models;
+    QString code, desc, line;
+
+    Process p(QStringList() << "xkeyboard-models");
+
+    if (p.waitForFinished()) {
+        while (p.canReadLine()) {
+            line = p.readLine();
+            code = line;
+            code.truncate(line.indexOf(" "));
+            desc = line.remove(0, line.indexOf(" "));
+            _models.append(desc.simplified() + " - (" + code.simplified() + ")");
+        }
+    }
+    return _models;
+}
+
+QStringList Backend::keyLayouts()
+{
+    QStringList _layouts;
+    QString code, desc, line;
+
+    Process p(QStringList() << "xkeyboard-layouts");
+
+    if (p.waitForFinished()) {
+        while (p.canReadLine()) {
+            line = p.readLine();
+            code = line;
+            code.truncate(line.indexOf(" "));
+            desc = line.remove(0, line.indexOf(" "));
+            _layouts.append(desc.simplified() + " - (" + code.simplified() + ")");
+        }
+    }
+    return _layouts;
+}
+
+// Function which gets the key Variants for the target layout
+QStringList Backend::keyVariants(const QString &layout, QStringList &savedKeyVariants)
+{
+    QStringList _variants;
+    QString code, desc, line;
+
+    if ( savedKeyVariants.empty() )
+    {
+      Process p(QStringList() << "xkeyboard-variants");
+      if (p.waitForFinished()) {
+        while (p.canReadLine()) {
+            line = p.readLine();
+            savedKeyVariants << line;
+        }
+      }
+    }
+
+    for (int i = 0; i < savedKeyVariants.size(); ++i) {
+       // Look for variants for this particular layout
+       line = savedKeyVariants.at(i);
+       if ( line.indexOf(" " + layout + ":") != -1 )
+       {
+         code = line.simplified();
+         code.truncate(code.indexOf(" "));
+         desc = line.remove(0, line.indexOf(": ") + 1);
+         _variants.append(desc.simplified() + " - (" + code.simplified() + ")");
+       }
+    }
+
+    return _variants;
+}
+
+// Function which lets us run setxkbmap
+void Backend::changeKbMap(QString model, QString layout, QString variant)
+{
+   QProcess kbp;
+   QStringList args;
+   QString prog;
+   prog = "setxkbmap"; 
+   args << "-model" << model << "-layout" << layout << "-variant" << variant;
+   qDebug() << "setxkbmap:" << args;
+   kbp.start(prog, args);
+   kbp.waitForFinished();
+}
+
 //****** PRIVATE FUNCTIONS ******
 
 void Backend::loadXSessionsData(){

Modified: pcbsd-projects/PCDM/pcdm-backend.h
===================================================================
--- pcbsd-projects/PCDM/pcdm-backend.h	2012-08-08 17:04:34 UTC (rev 18355)
+++ pcbsd-projects/PCDM/pcdm-backend.h	2012-08-08 18:38:16 UTC (rev 18356)
@@ -5,6 +5,7 @@
 #include <QString>
 #include <QDebug>
 #include <QDir>
+#include <QProcess>
 
 #include <sys/types.h>
 #include <security/pam_appl.h>
@@ -14,6 +15,16 @@
 #include "pcbsd-utils.h"
 #include "pcdm-themes.h"
 
+#define PCSYSINSTALL    QString("/usr/sbin/pc-sysinstall")
+
+class Process : public QProcess {
+public:
+    Process(const QStringList &args) {
+        setReadChannel(QProcess::StandardOutput);
+        start(PCSYSINSTALL, args);
+    }
+};
+
 class Backend {
 public:
     static QStringList getAvailableDesktops();
@@ -23,6 +34,10 @@
     static QStringList getSystemUsers();
     static bool startUserLogin(QString, QString, QString);
     static QString getUsernameFromDisplayname(QString);
+    static QStringList keyModels();
+    static QStringList keyLayouts();
+    static QStringList keyVariants(const QString &layout, QStringList &savedKeyVariants);
+    static void changeKbMap(QString model, QString layout, QString variant);
     
 private:	
     static void loadXSessionsData();

Modified: pcbsd-projects/PCDM/pcdm-gui.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-gui.cpp	2012-08-08 17:04:34 UTC (rev 18355)
+++ pcbsd-projects/PCDM/pcdm-gui.cpp	2012-08-08 18:38:16 UTC (rev 18356)
@@ -23,6 +23,9 @@
 
 void PCDMgui::createGUIfromTheme(){
   QString style;
+  //Fill a couple global variables
+  kModels = Backend::keyModels();
+  kLayouts = Backend::keyLayouts();
   //Set the background image
   if(Theme::customBackground()){
     //use "border-image" instead of "background-image" to stretch rather than tile the image
@@ -285,10 +288,34 @@
 
 void PCDMgui::slotChangeLocale(){
   qDebug() << "PCDM: Changing of Locale is not implemented yet";
+  /*
+  if ( comboLanguage->currentIndex() == -1 )
+    return;
+
+  // Figure out the language code
+  QString langCode = languages.at(comboLanguage->currentIndex());
+    
+  // Grab the language code
+  langCode.truncate(langCode.lastIndexOf(")"));
+  langCode.remove(0, langCode.lastIndexOf("(") + 1); 
+
+  // Now write out the lang code and close
+  QFile lfile( TMPLANGFILE );
+  if ( lfile.open( QIODevice::WriteOnly ) ) {
+    QTextStream stream( &lfile );
+      stream <<  langCode;
+    lfile.close();
+  }
+  close();
+  */
 }
 
 void PCDMgui::slotChangeKeyboardLayout(){
-  qDebug() << "PCDM: Changing the keyboard layout is not implemented yet";
+  wKey = new widgetKeyboard();
+  wKey->programInit(kModels, kLayouts);
+  wKey->setWindowModality(Qt::ApplicationModal);
+  wKey->show();
+  wKey->raise();
 }
 
 // Start xvkbd

Modified: pcbsd-projects/PCDM/pcdm-gui.h
===================================================================
--- pcbsd-projects/PCDM/pcdm-gui.h	2012-08-08 17:04:34 UTC (rev 18355)
+++ pcbsd-projects/PCDM/pcdm-gui.h	2012-08-08 18:38:16 UTC (rev 18356)
@@ -20,7 +20,10 @@
 #include "pcdm-backend.h"
 #include "pcdm-themes.h"
 #include "fancySwitcher.h"
+#include "dialogKeyboard.h"
 
+#define TMPLANGFILE QString("/tmp/.PCDMLang")
+
 class PCDMgui : public QMainWindow
 {
     Q_OBJECT
@@ -42,13 +45,15 @@
 
 private:
     //Objects
+    widgetKeyboard* wKey;
     QToolBar* toolbar;
     QMenu* systemMenu;
-    QComboBox* unameline;//,deSwitcher;
+    QComboBox* unameline;
     FancySwitcher* deSwitcher;
     QLineEdit* pwline;
     QX11EmbedContainer* container;
     QProcess* vkbd;
+    QStringList kModels, kLayouts;
 
     //Functions
     void createGUIfromTheme();



More information about the Commits mailing list