added few qt sources
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 8 Jul 2007 13:08:52 +0000 (13:08 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 8 Jul 2007 13:08:52 +0000 (13:08 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@8 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

src/keygen.cpp [new file with mode: 0644]
src/keygen.h [new file with mode: 0644]
src/main.cpp [new file with mode: 0644]
src/mainwindow.h [new file with mode: 0644]
src/smoke.pro [new file with mode: 0644]
src/smoke_de.ts [new file with mode: 0644]
src/smoke_de_SAX.ts [new file with mode: 0644]

diff --git a/src/keygen.cpp b/src/keygen.cpp
new file mode 100644 (file)
index 0000000..3353dae
--- /dev/null
@@ -0,0 +1,164 @@
+//
+// C++ Implementation: keygen
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2007
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include "keygen.h"
+
+#include <QLabel>
+#include <QBoxLayout>
+#include <QKeyEvent>
+#include <QMouseEvent>
+#include <QTime>
+#include <QPalette>
+#include <QColor>
+#include <QCryptographicHash>
+#include <QPushButton>
+
+//enable linux to read /dev/random
+#ifdef __linux__
+#include <unistd.h>
+#include <fcntl.h>
+#endif
+
+//amount of random bits needed:
+#define RANDNEED 160
+
+MKeyGen::MKeyGen()
+{
+       setWindowTitle(tr("Magic Smoke Key Generator"));
+       
+       //pre-init random buffer
+       randstat=-1;
+       randent=0;
+       //make sure all mouse events arrive
+       setMouseTracking(true);
+       QVBoxLayout*vl;
+       setLayout(vl=new QVBoxLayout);
+       QLabel*lab;
+       //main explanation
+       vl->addWidget(lab=new QLabel(tr("<html><h1>Key Generation</h1>\nI am currently collecting random bits in order to generate a host key for this installation. Please use mouse and keyboard to generate more random. Alternatively you can load a key from an external medium.<p>\nAt least %1 Bits of random are required.").arg(RANDNEED)),0);
+       lab->setWordWrap(true);
+       lab->setMouseTracking(true);
+       //buffer display
+       vl->addWidget(randlab=new QLabel(tr("Current random buffer: %1 Bits").arg(randent)),0);
+       randlab->setMouseTracking(true);
+       randlab->setFrameShape(QFrame::Box);
+       randlab->setAutoFillBackground(true);
+       
+       vl->addStretch(1);
+       
+       //buttons
+       QHBoxLayout*hl;
+       vl->addLayout(hl=new QHBoxLayout,0);
+       hl->addStretch(1);
+       hl->addWidget(okbtn=new QPushButton(tr("&OK")),0);
+       connect(okbtn,SIGNAL(clicked()),this,SLOT(accept()));
+       hl->addWidget(ccbtn=new QPushButton(tr("&Cancel")),0);
+       connect(ccbtn,SIGNAL(clicked()),this,SLOT(reject()));
+       
+       //if Linux: try to pre-load some random
+#ifdef __linux__
+       int fd=::open("/dev/random",O_RDONLY|O_NONBLOCK);
+       if(fd>=0){
+               char buf[RANDNEED/8];
+               int rd=::read(fd,buf,sizeof(buf));
+               if(rd>0){
+                       randbuf.append(QByteArray(buf,rd));
+                       randent=rd*8;
+               }
+               ::close(fd);
+       }
+#endif
+
+       //make sure widgets look right
+       updateProps();
+       
+       //make window really big
+       showMaximized();
+}
+MKeyGen::~MKeyGen(){}
+bool MKeyGen::event(QEvent*e)
+{
+       //add to random buffer for key and mouse events
+       switch(e->type()){
+               case QEvent::KeyPress:case QEvent::KeyRelease:
+               {
+                       QKeyEvent*ke=(QKeyEvent*)e;
+                       addBit(ke->key()+(int)ke->modifiers());
+                       break;
+               }
+               case QEvent::MouseButtonPress:case QEvent::MouseButtonRelease:
+               case QEvent::MouseMove:
+               {
+                       QMouseEvent*me=(QMouseEvent*)e;
+                       addBit((int)me->buttons()+me->x()+me->y());
+                       break;
+               }
+               default:
+                       //ignore
+                       break;
+       }
+       return QDialog::event(e);
+}
+
+void MKeyGen::addBit(int b)
+{
+       //add bit to buffer
+       randbuf.append((b>>24)&0xff);
+       randbuf.append((b>>16)&0xff);
+       randbuf.append((b>>8)&0xff);
+       randbuf.append(b&0xff);
+       randent++;
+       //add time info as another bit
+       QTime ct=QTime::currentTime();
+       if(ct.msec()!=0){ //don't use it if platform has no msecs
+               int t=ct.msec()+ct.second()+ct.minute();
+               randbuf.append((t>>24)&0xff);
+               randbuf.append((t>>16)&0xff);
+               randbuf.append((t>>8)&0xff);
+               randbuf.append(t&0xff);
+               randent++;
+       }
+       //update display
+       updateProps();
+       randlab->setText(tr("Current random buffer: %1 Bits").arg(randent));
+}
+
+void MKeyGen::updateProps()
+{
+       if(randent<RANDNEED){
+               //check whether we need to set it
+               if(randstat==0)return;
+               randstat=0;
+               //set label color
+               QPalette pal=randlab->palette();
+               pal.setColor(QPalette::Window,QColor("#ff8080"));
+               randlab->setPalette(pal);
+               //set button
+               okbtn->setEnabled(false);
+       }else{
+               //check whether we need to set it
+               if(randstat==1)return;
+               randstat=1;
+               //set label color
+               QPalette pal=randlab->palette();
+               pal.setColor(QPalette::Window,QColor("#80ff80"));
+               randlab->setPalette(pal);
+               //set button
+               okbtn->setEnabled(true);
+       }
+}
+
+QString MKeyGen::getKey()
+{
+       if(randent<RANDNEED)return "";
+       return QCryptographicHash::hash(randbuf,QCryptographicHash::Sha1).toHex();
+}
diff --git a/src/keygen.h b/src/keygen.h
new file mode 100644 (file)
index 0000000..3f9809e
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// C++ Interface: keygen
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2007
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_KEYGEN_H
+#define MAGICSMOKE_KEYGEN_H
+
+#include <QDialog>
+#include <QByteArray>
+
+class QLabel;
+class QPushButton;
+
+class MKeyGen:public QDialog
+{
+       Q_OBJECT
+       public:
+               MKeyGen();
+               ~MKeyGen();
+               
+               QString getKey();
+               
+       protected:
+               bool event(QEvent*);
+       private:
+               QByteArray randbuf;
+               int randent;
+               QLabel*randlab;
+               int randstat;
+               
+               QPushButton *okbtn,*ccbtn;
+               
+               void addBit(int);
+               void updateProps();
+};
+
+#endif
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644 (file)
index 0000000..832005f
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// C++ Implementation: main
+//
+// Description: Main Program
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2007
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#include <QApplication>
+#include <QSettings>
+#include <QTranslator>
+#include <QLocale>
+
+#include "keygen.h"
+#include "mainwindow.h"
+
+int main(int argc,char**argv)
+{
+       QApplication app(argc,argv);
+       
+       app.setOrganizationName("MagicSmoke");
+       app.setApplicationName("MagicSmoke");
+       
+       //try to find appropriate locale
+       QString lang=QSettings().value("lang","C").toString();
+       if(lang=="C")lang=QLocale::system().name();
+       
+       qDebug("Loading language %s",lang.toAscii().data());
+       QTranslator qttrans;
+       qttrans.load("qt_"+lang);
+       app.installTranslator(&qttrans);
+       QTranslator mstrans;
+       mstrans.load("smoke_"+lang);
+       app.installTranslator(&mstrans);
+       
+       if(!QSettings().contains("hostkey")){
+               MKeyGen mkg;
+               if(mkg.exec()==QDialog::Accepted)
+                       QSettings().setValue("hostkey",mkg.getKey());
+       }
+       if(!QSettings().contains("profiles")){
+       }
+       
+       MMainWindow mmw;
+       mmw.show();
+       
+       return app.exec();
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h
new file mode 100644 (file)
index 0000000..b453951
--- /dev/null
@@ -0,0 +1,22 @@
+//
+// C++ Interface: mainwindow
+//
+// Description: 
+//
+//
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2007
+//
+// Copyright: See README/COPYING files that come with this distribution
+//
+//
+
+#ifndef MAGICSMOKE_MAINWINDOW_H
+#define MAGICSMOKE_MAINWINDOW_H
+
+#include <QMainWindow>
+
+class MMainWindow:public QMainWindow
+{
+};
+
+#endif
diff --git a/src/smoke.pro b/src/smoke.pro
new file mode 100644 (file)
index 0000000..ca731a1
--- /dev/null
@@ -0,0 +1,26 @@
+TEMPLATE = app
+TARGET = msmoke
+
+#build for debug or release?
+CONFIG += release
+#CONFIG += debug
+
+CONFIG += qt thread
+QT += xml network
+MSVERSION = "0.1 alpha"
+
+#win32-* {
+# #RC-File containing the icon:
+# RC_FILE += win.rc
+#}
+
+SOURCES = \
+       main.cpp \
+       keygen.cpp
+HEADERS = \
+       keygen.h \
+       mainwindow.h
+
+TRANSLATIONS = \
+       smoke_de.ts \
+       smoke_de_SAX.ts 
\ No newline at end of file
diff --git a/src/smoke_de.ts b/src/smoke_de.ts
new file mode 100644 (file)
index 0000000..4f562b9
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS><TS version="1.1" language="de">
+<context>
+    <name>MKeyGen</name>
+    <message>
+        <location filename="keygen.cpp" line="132"/>
+        <source>Current random buffer: %1 Bits</source>
+        <translation>Aktueller Zufallspuffer: %1 Bits</translation>
+    </message>
+    <message>
+        <location filename="keygen.cpp" line="36"/>
+        <source>Magic Smoke Key Generator</source>
+        <translation>Magic Smoke Schlüsselgenerator</translation>
+    </message>
+    <message>
+        <location filename="keygen.cpp" line="47"/>
+        <source>&lt;html&gt;&lt;h1&gt;Key Generation&lt;/h1&gt;
+I am currently collecting random bits in order to generate a host key for this installation. Please use mouse and keyboard to generate more random. Alternatively you can load a key from an external medium.&lt;p&gt;
+At least %1 Bits of random are required.</source>
+        <translation>&lt;html&gt;&lt;h1&gt;Schlüsselgenerierung&lt;/h1&gt;Das Programm sammelt gerade Zufallsbits für diese Installation. Bitte benutzen Sie Maus und Tastatur, um mehr Zufall zu generieren. Alternativ können Sie auch einen fertigen Schlüssel von einem externen Medium laden.&lt;p&gt;Mindestens %1 Zufallsbits werden gebraucht.</translation>
+    </message>
+    <message>
+        <location filename="keygen.cpp" line="62"/>
+        <source>&amp;OK</source>
+        <translation>&amp;Ok</translation>
+    </message>
+    <message>
+        <location filename="keygen.cpp" line="64"/>
+        <source>&amp;Cancel</source>
+        <translation>&amp;Abbrechen</translation>
+    </message>
+</context>
+</TS>
diff --git a/src/smoke_de_SAX.ts b/src/smoke_de_SAX.ts
new file mode 100644 (file)
index 0000000..abb570d
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS><TS version="1.1" language="de">
+<defaultcodec></defaultcodec>
+<context>
+    <name>MKeyGen</name>
+    <message>
+        <location filename="keygen.cpp" line="132"/>
+        <source>Current random buffer: %1 Bits</source>
+        <translation>Aktueller Füllschdand vom dem Zufallsbuffer: %1 Bids</translation>
+    </message>
+    <message>
+        <location filename="keygen.cpp" line="36"/>
+        <source>Magic Smoke Key Generator</source>
+        <translation>Mädschig Schmohg Schlüsselgenerador</translation>
+    </message>
+    <message>
+        <location filename="keygen.cpp" line="47"/>
+        <source>&lt;html&gt;&lt;h1&gt;Key Generation&lt;/h1&gt;
+I am currently collecting random bits in order to generate a host key for this installation. Please use mouse and keyboard to generate more random. Alternatively you can load a key from an external medium.&lt;p&gt;
+At least %1 Bits of random are required.</source>
+        <translation>&lt;html&gt;&lt;h1&gt;Schlüsselgenerierung&lt;/h1&gt;Das Brogramm sammeld grade Zufallsbids für diese Inschdalladsion. &lt;br&gt;Das iss im Grunde ne&apos; ganz eefache Sache. Basse off: Du waggelsd ä bissl an dor Maus und hämmerst wie ä Beglobbder off de Dasdadur. Dann wenn&apos;s Brogramm genug Zufall had wird de rode Leisde unden grün. Das heesd Du gannst offhörn und Disch wiedor wie&apos;n normaler Mensch benehm&apos;.Wenn Dir das nich bassd gannsde och jemand andres den Schrodd machn&apos; lassn&apos; und &apos;ne Schlüsseldadei laden.&lt;p&gt;Mindeschdens %1 Zufallsbids brauchsde. Geene Sorsche das gehd fix.</translation>
+    </message>
+    <message>
+        <location filename="keygen.cpp" line="62"/>
+        <source>&amp;OK</source>
+        <translation>Nu &amp;glar! Nehm&apos;sch.</translation>
+    </message>
+    <message>
+        <location filename="keygen.cpp" line="64"/>
+        <source>&amp;Cancel</source>
+        <translation>&amp;Nee lass mal.</translation>
+    </message>
+</context>
+</TS>