Commit 2bd1806d authored by Ingemar Ceicer's avatar Ingemar Ceicer

Opens new window and displays checksum if there are multiple files


Former-commit-id: 6d9e64f0
parent 13bed748
......@@ -2494,6 +2494,58 @@ bool Hash::doChecksum(QString in)
return true;
}
bool Hash::doChecksum(QString in, QStringList *lista)
{
QString conf_file_name = QDir::toNativeSeparators("/" APPLICATION_NAME ".conf");
k = new Config(conf_file_name);
std::string s = k->getConf("algorithm");
delete k;
QByteArray ba;
QFile f(in);
if (f.open(QFile::ReadOnly))
{
ba = f.readAll();
f.close();
}
else
return false;
int pos = in.lastIndexOf("/");
QString filnamnet = in.mid(pos+1,-1);
QByteArray sum;
if (s=="md4")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Md4);
else if (s=="md5")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Md5);
else if (s=="sha1")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Sha1);
else if (s=="sha224")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Sha224);
else if (s=="sha256")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Sha256);
else if (s=="sha384")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Sha384);
else if (s=="sha512")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Sha512);
else if (s=="sha3_224")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Sha3_224);
else if (s=="sha3_256")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Sha3_256);
else if (s=="sha3_384")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Sha3_384);
else if (s=="sha3_512")
sum = QCryptographicHash::hash ( ba,QCryptographicHash::Sha3_512);
sum = sum.toHex();
/*
ui->progressLabel->setText("\""+filnamnet +tr("\" has hash sum")+" ("+tr("Algorithm: ")+QString::fromStdString(s)+")");
ui->progressLabel->setToolTip(QDir::toNativeSeparators(in));
ui->actionCopyPath->setEnabled(true);
ui->actionCopyHashSum->setEnabled(true);
ui->lineEdit->setText(sum);
*/
lista->append(sum);
return true;
}
bool Hash::doChecksumText(const QString in)
{
QString conf_file_name = QDir::toNativeSeparators("/" APPLICATION_NAME ".conf");
......@@ -3188,28 +3240,66 @@ QString Hash::getSystem()
/* draganddrop */
void Hash::dropEvent(QDropEvent *ev)
{
QString surl;
int hitta;
lista = new QStringList;
QStringList fillista;
QString surl, spath;
QList<QUrl> urls = ev->mimeData()->urls();
int antalfiler = urls.size();
foreach(QUrl url, urls)
{
qDebug()<<url;
surl = url.toString();
qDebug()<<surl;
QFileInfo fileInfo(url.fileName());
QString filename(fileInfo.fileName());
//qDebug() << filename;
// qDebug() << nyurl;
// surl = url.toString();
surl = url.toString(QUrl::PreferLocalFile);
spath = url.toString(QUrl::RemoveFilename);
/*
hitta = surl.lastIndexOf("//");
qDebug()<<hitta;
#ifdef Q_OS_LINUX
#ifdef Q_OS_LINUX
surl = surl.remove(0,hitta+1);
#endif // Q_OS_LINUX
#ifdef Q_OS_WIN32
#endif // Q_OS_LINUX
#ifdef Q_OS_WIN32
surl = surl.remove(0,hitta+2);
#endif // Q_OS_WIN32
qDebug()<<surl;
#endif // Q_OS_WIN32
*/
surl = QDir::toNativeSeparators(surl);
qDebug()<<surl;
bool lyckades = doChecksum(surl);
if ( lyckades == false )
QMessageBox::critical(this, APPLICATION_NAME " " VERSION,tr("No hash sum could be calculated"));
if (antalfiler > 1)
{
bool lyckades = doChecksum(surl, lista);
if ( lyckades == false )
QMessageBox::critical(this, APPLICATION_NAME " " VERSION,tr("No hash sum could be calculated"));
fillista.append(filename);
}
else
{
bool lyckades = doChecksum(surl);
if ( lyckades == false )
QMessageBox::critical(this, APPLICATION_NAME " " VERSION,tr("No hash sum could be calculated"));
}
}
if (antalfiler > 1)
{
d = new QDialog;
Ui::Lic *ui2 = new Ui::Lic;
ui2->setupUi(d);
const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
ui2->textBrowser->setFont(fixedFont);
ui2->textBrowser->append(tr("Path: ")+spath+"<br>");
for (int i=0; i<lista->size(); i++)
{
ui2->textBrowser->append(lista->at(i)+" "+fillista.at(i));
// ui2->textBrowser->moveCursor (QTextCursor::End);
}
ui2->pbOpenFile->hide();
ui2->pbClose->setGeometry(450,570,100,24);
// d->setWindowFlags(Qt::CustomizeWindowHint);
d->setWindowFlags(Qt::WindowSystemMenuHint);
d->setWindowTitle(APPLICATION_NAME " " VERSION);
// QIcon ikon("/images/hashsum.ico");
// d->setWindowIcon(ikon);
connect(ui2->pbClose, SIGNAL(clicked()), this, SLOT(stang()));
d->show();
}
}
......
......@@ -93,6 +93,7 @@ private:
void setStartConfig();
void setEndConfig();
bool doChecksum(QString);
bool doChecksum(QString, QStringList *lista);
bool doChecksumText(const QString);
bool doChecksumList(QString, QString &, std::string);
bool doCompare(QString, QString);
......@@ -115,6 +116,7 @@ private:
int MAX_RECENT_FILES;
// const QStringList algoritmer = (QStringList() << "md4" << "md5" << "sh1");
QStringList algoritmer;
QStringList *lista;
private slots:
......
......@@ -9,20 +9,20 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>500</height>
<width>1000</width>
<height>600</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>400</width>
<height>500</height>
<width>1000</width>
<height>600</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>400</width>
<height>500</height>
<width>1000</width>
<height>600</height>
</size>
</property>
<property name="contextMenuPolicy">
......@@ -43,16 +43,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>461</height>
<width>1000</width>
<height>561</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<widget class="QPushButton" name="pbClose">
<property name="geometry">
<rect>
<x>130</x>
<y>470</y>
<x>260</x>
<y>460</y>
<width>100</width>
<height>24</height>
</rect>
......@@ -64,12 +70,18 @@
<widget class="QPushButton" name="pbOpenFile">
<property name="geometry">
<rect>
<x>240</x>
<y>470</y>
<x>410</x>
<y>460</y>
<width>100</width>
<height>24</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Open File</string>
</property>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment