From c6fddfa577e3a390e25bbc237b9ce596bf7b9fb6 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 8 Jul 2007 13:08:52 +0000 Subject: [PATCH] added few qt sources git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@8 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/keygen.cpp | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/keygen.h | 45 ++++++++++++++ src/main.cpp | 52 ++++++++++++++++ src/mainwindow.h | 22 +++++++ src/smoke.pro | 26 ++++++++ src/smoke_de.ts | 33 ++++++++++ src/smoke_de_SAX.ts | 34 +++++++++++ 7 files changed, 376 insertions(+), 0 deletions(-) create mode 100644 src/keygen.cpp create mode 100644 src/keygen.h create mode 100644 src/main.cpp create mode 100644 src/mainwindow.h create mode 100644 src/smoke.pro create mode 100644 src/smoke_de.ts create mode 100644 src/smoke_de_SAX.ts diff --git a/src/keygen.cpp b/src/keygen.cpp new file mode 100644 index 0000000..3353dae --- /dev/null +++ b/src/keygen.cpp @@ -0,0 +1,164 @@ +// +// C++ Implementation: keygen +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2007 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "keygen.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//enable linux to read /dev/random +#ifdef __linux__ +#include +#include +#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("

Key Generation

\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.

\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(randentpalette(); + 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, (C) 2007 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_KEYGEN_H +#define MAGICSMOKE_KEYGEN_H + +#include +#include + +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 index 0000000..832005f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,52 @@ +// +// C++ Implementation: main +// +// Description: Main Program +// +// +// Author: Konrad Rosenbaum , (C) 2007 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include +#include +#include +#include + +#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 index 0000000..b453951 --- /dev/null +++ b/src/mainwindow.h @@ -0,0 +1,22 @@ +// +// C++ Interface: mainwindow +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2007 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef MAGICSMOKE_MAINWINDOW_H +#define MAGICSMOKE_MAINWINDOW_H + +#include + +class MMainWindow:public QMainWindow +{ +}; + +#endif diff --git a/src/smoke.pro b/src/smoke.pro new file mode 100644 index 0000000..ca731a1 --- /dev/null +++ b/src/smoke.pro @@ -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 index 0000000..4f562b9 --- /dev/null +++ b/src/smoke_de.ts @@ -0,0 +1,33 @@ + + + + MKeyGen + + + Current random buffer: %1 Bits + Aktueller Zufallspuffer: %1 Bits + + + + Magic Smoke Key Generator + Magic Smoke Schlüsselgenerator + + + + <html><h1>Key Generation</h1> +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.<p> +At least %1 Bits of random are required. + <html><h1>Schlüsselgenerierung</h1>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.<p>Mindestens %1 Zufallsbits werden gebraucht. + + + + &OK + &Ok + + + + &Cancel + &Abbrechen + + + diff --git a/src/smoke_de_SAX.ts b/src/smoke_de_SAX.ts new file mode 100644 index 0000000..abb570d --- /dev/null +++ b/src/smoke_de_SAX.ts @@ -0,0 +1,34 @@ + + + + + MKeyGen + + + Current random buffer: %1 Bits + Aktueller Füllschdand vom dem Zufallsbuffer: %1 Bids + + + + Magic Smoke Key Generator + Mädschig Schmohg Schlüsselgenerador + + + + <html><h1>Key Generation</h1> +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.<p> +At least %1 Bits of random are required. + <html><h1>Schlüsselgenerierung</h1>Das Brogramm sammeld grade Zufallsbids für diese Inschdalladsion. <br>Das iss im Grunde ne' ganz eefache Sache. Basse off: Du waggelsd ä bissl an dor Maus und hämmerst wie ä Beglobbder off de Dasdadur. Dann wenn's Brogramm genug Zufall had wird de rode Leisde unden grün. Das heesd Du gannst offhörn und Disch wiedor wie'n normaler Mensch benehm'.Wenn Dir das nich bassd gannsde och jemand andres den Schrodd machn' lassn' und 'ne Schlüsseldadei laden.<p>Mindeschdens %1 Zufallsbids brauchsde. Geene Sorsche das gehd fix. + + + + &OK + Nu &glar! Nehm'sch. + + + + &Cancel + &Nee lass mal. + + + -- 1.7.2.5