1 /***************************************************************************
2 * Copyright (C) 2005-2006 by Tarek Saidi *
3 * tarek.saidi@arcor.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; version 2 of the License. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include "CollectEntropyDlg.h"
25 CollectEntropyDlg::CollectEntropyDlg(QWidget* parent):QDialog(parent){
27 resize(layout()->closestAcceptableSize(this,QSize(0,0)));
28 setMinimumSize(size());
29 setMaximumSize(size());
30 createBanner(&BannerPixmap,getPixmap("dice"),tr("Entropy Collection"),width());
31 KeyEntropyBuffer=new unsigned char[105];
32 MouseEntropyBuffer=new quint16[210];
35 QTimer* timer=new QTimer(this);
36 connect(timer,SIGNAL(timeout()),this,SLOT(trackMousePos()));
37 timer->setInterval(50);
42 CollectEntropyDlg::~CollectEntropyDlg(){
43 delete [] KeyEntropyBuffer;
44 delete [] MouseEntropyBuffer;
47 void CollectEntropyDlg::paintEvent(QPaintEvent *event){
48 QDialog::paintEvent(event);
49 QPainter painter(this);
50 painter.setClipRegion(event->region());
51 painter.drawPixmap(QPoint(0,0),BannerPixmap);
54 void CollectEntropyDlg::trackMousePos(){
55 QPoint p=QCursor::pos();
56 if(LastPos-p==QPoint(0,0))return;
58 if(MouseCounter==105 || ReseedDone)return;
59 MouseEntropyBuffer[2*MouseCounter]=p.x();
60 MouseEntropyBuffer[2*MouseCounter+1]=p.y();
65 void CollectEntropyDlg::keyReleaseEvent(QKeyEvent* event ){
66 QDialog::keyReleaseEvent(event);
67 if(KeyCounter==105 || ReseedDone)return;
68 KeyEntropyBuffer[KeyCounter]=event->key();
73 void CollectEntropyDlg::updateProgress(){
74 if(4*KeyCounter+4*MouseCounter>=420){
75 progressBar->setValue(420);
77 reseedStrongPool((quint8*)MouseEntropyBuffer,4*MouseCounter,KeyEntropyBuffer,KeyCounter);
79 stackedWidget->setCurrentIndex(1);
82 progressBar->setValue(4*KeyCounter+4*MouseCounter);
86 void CollectEntropyDlg::showEvent(QShowEvent* event){
87 if(!event->spontaneous()){