mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-23 18:32:51 +00:00
khash: multi-source UI
see https://ibb.co/xDTWRbq, flexible isn't it? Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
8103af05de
commit
3d717a2b4a
3 changed files with 52 additions and 76 deletions
|
@ -25,11 +25,6 @@ install(TARGETS khash ${INSTALL_TARGETS_DEFAULT_ARGS})
|
||||||
|
|
||||||
########### install files ###############
|
########### install files ###############
|
||||||
|
|
||||||
install(
|
|
||||||
PROGRAMS khash.desktop
|
|
||||||
DESTINATION ${KDE4_XDG_APPS_INSTALL_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
install(
|
||||||
FILES khash_checksum.desktop DESTINATION
|
FILES khash_checksum.desktop DESTINATION
|
||||||
${KDE4_SERVICES_INSTALL_DIR}/ServiceMenus
|
${KDE4_SERVICES_INSTALL_DIR}/ServiceMenus
|
||||||
|
|
100
khash/khash.cpp
100
khash/khash.cpp
|
@ -32,6 +32,7 @@
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QGroupBox>
|
||||||
|
|
||||||
class KHashDialog : public KDialog
|
class KHashDialog : public KDialog
|
||||||
{
|
{
|
||||||
|
@ -41,37 +42,29 @@ public:
|
||||||
~KHashDialog();
|
~KHashDialog();
|
||||||
|
|
||||||
void setAlgorithm(const QCryptographicHash::Algorithm algorithm);
|
void setAlgorithm(const QCryptographicHash::Algorithm algorithm);
|
||||||
void setSource(const KUrl &source);
|
void addSource(const KUrl &source);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QCryptographicHash::Algorithm m_algorithm;
|
QCryptographicHash::Algorithm m_algorithm;
|
||||||
KUrl m_source;
|
QList<KUrl> m_sources;
|
||||||
QGridLayout* m_dialoglayout;
|
QWidget* m_dialogwidget;
|
||||||
KLineEdit* m_checksumedit;
|
QVBoxLayout* m_dialoglayout;
|
||||||
|
QList<KLineEdit*> m_checksumedits;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
KHashDialog::KHashDialog(QWidget *parent)
|
KHashDialog::KHashDialog(QWidget *parent)
|
||||||
: KDialog(parent),
|
: KDialog(parent),
|
||||||
m_algorithm(QCryptographicHash::Sha1),
|
m_algorithm(QCryptographicHash::Sha1),
|
||||||
m_dialoglayout(nullptr),
|
m_dialogwidget(nullptr),
|
||||||
m_checksumedit(nullptr)
|
m_dialoglayout(nullptr)
|
||||||
{
|
{
|
||||||
QWidget* dialogwidget = new QWidget(this);
|
m_dialogwidget = new QWidget(this);
|
||||||
m_dialoglayout = new QGridLayout(dialogwidget);
|
m_dialoglayout = new QVBoxLayout(m_dialogwidget);
|
||||||
|
|
||||||
QLabel* checksumlabel = new QLabel(i18n("Checksum:"), dialogwidget);
|
setMainWidget(m_dialogwidget);
|
||||||
m_dialoglayout->addWidget(checksumlabel, 0, 0);
|
|
||||||
|
|
||||||
m_checksumedit = new KLineEdit(dialogwidget);
|
|
||||||
m_checksumedit->setReadOnly(true);
|
|
||||||
m_dialoglayout->addWidget(m_checksumedit, 0, 1);
|
|
||||||
|
|
||||||
// TODO: progress bar and threading
|
|
||||||
|
|
||||||
setMainWidget(dialogwidget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KHashDialog::~KHashDialog()
|
KHashDialog::~KHashDialog()
|
||||||
|
@ -81,52 +74,53 @@ KHashDialog::~KHashDialog()
|
||||||
void KHashDialog::setAlgorithm(const QCryptographicHash::Algorithm algorithm)
|
void KHashDialog::setAlgorithm(const QCryptographicHash::Algorithm algorithm)
|
||||||
{
|
{
|
||||||
m_algorithm = algorithm;
|
m_algorithm = algorithm;
|
||||||
QFontMetrics dialoglinemetric(m_checksumedit->font());
|
|
||||||
switch (algorithm) {
|
|
||||||
case QCryptographicHash::Md5: {
|
|
||||||
m_dialoglayout->setColumnMinimumWidth(1, 32 * dialoglinemetric.width('x'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QCryptographicHash::Sha1: {
|
|
||||||
m_dialoglayout->setColumnMinimumWidth(1, 40 * dialoglinemetric.width('x'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QCryptographicHash::Sha256: {
|
|
||||||
m_dialoglayout->setColumnMinimumWidth(1, 64 * dialoglinemetric.width('x'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QCryptographicHash::Sha512: {
|
|
||||||
// NOTE: it is 128 long but don't want it to extend too much (small screens)
|
|
||||||
m_dialoglayout->setColumnMinimumWidth(1, 64 * dialoglinemetric.width('x'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QCryptographicHash::KAT: {
|
|
||||||
m_dialoglayout->setColumnMinimumWidth(1, 64 * dialoglinemetric.width('x'));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KHashDialog::setSource(const KUrl &source)
|
void KHashDialog::addSource(const KUrl &source)
|
||||||
{
|
{
|
||||||
m_source = source;
|
m_sources.append(source);
|
||||||
setCaption(KDialog::makeStandardCaption(QFileInfo(source.prettyUrl()).fileName(), this));
|
const QString sourcefilename = QFileInfo(source.prettyUrl()).fileName();
|
||||||
|
setCaption(KDialog::makeStandardCaption(sourcefilename, this));
|
||||||
|
|
||||||
|
QGroupBox* checksumgroup = new QGroupBox(m_dialogwidget);
|
||||||
|
QGridLayout* checksumlayout = new QGridLayout(checksumgroup);
|
||||||
|
|
||||||
|
checksumgroup->setTitle(sourcefilename);
|
||||||
|
QLabel* checksumlabel = new QLabel(i18n("Checksum:"), checksumgroup);
|
||||||
|
checksumlayout->addWidget(checksumlabel, 0, 0);
|
||||||
|
|
||||||
|
KLineEdit* checksumedit = new KLineEdit(checksumgroup);
|
||||||
|
checksumedit->setReadOnly(true);
|
||||||
|
checksumedit->setText(i18n("Queued.."));
|
||||||
|
checksumlayout->addWidget(checksumedit, 0, 1);
|
||||||
|
m_checksumedits.append(checksumedit);
|
||||||
|
|
||||||
|
m_dialoglayout->addWidget(checksumgroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KHashDialog::start()
|
void KHashDialog::start()
|
||||||
{
|
{
|
||||||
QFile checksumfile(m_source.toLocalFile());
|
int sourcerow = 0;
|
||||||
|
foreach (const KUrl &source, m_sources) {
|
||||||
|
KLineEdit* checksumedit = m_checksumedits.at(sourcerow);
|
||||||
|
checksumedit->setText(i18n("Calculating.."));
|
||||||
|
// TODO: threading
|
||||||
|
QFile checksumfile(source.toLocalFile());
|
||||||
if (!checksumfile.open(QFile::ReadOnly)) {
|
if (!checksumfile.open(QFile::ReadOnly)) {
|
||||||
m_checksumedit->setText(checksumfile.errorString());
|
checksumedit->setText(checksumfile.errorString());
|
||||||
return;
|
sourcerow++;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
QCryptographicHash checksumer(m_algorithm);
|
QCryptographicHash checksumer(m_algorithm);
|
||||||
if (!checksumer.addData(&checksumfile)) {
|
if (!checksumer.addData(&checksumfile)) {
|
||||||
m_checksumedit->setText(i18n("Checksummer error"));
|
checksumedit->setText(i18n("Checksumer error"));
|
||||||
return;
|
sourcerow++;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
const QByteArray checksumhex = checksumer.result().toHex();
|
const QByteArray checksumhex = checksumer.result().toHex();
|
||||||
m_checksumedit->setText(checksumhex);
|
checksumedit->setText(checksumhex);
|
||||||
|
sourcerow++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,12 +162,12 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
bool shouldstart = false;
|
bool shouldstart = false;
|
||||||
for (int pos = 0; pos < args->count(); ++pos) {
|
for (int pos = 0; pos < args->count(); ++pos) {
|
||||||
khashdialog.setSource(args->url(pos));
|
khashdialog.addSource(args->url(pos));
|
||||||
shouldstart = true;
|
shouldstart = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
khashdialog.show();
|
khashdialog.show();
|
||||||
khashdialog.setButtons(KDialog::Ok | KDialog::Close | KDialog::Help);
|
khashdialog.setButtons(KDialog::Close | KDialog::Help);
|
||||||
KHelpMenu khelpmenu(&khashdialog, &aboutData, true);
|
KHelpMenu khelpmenu(&khashdialog, &aboutData, true);
|
||||||
khashdialog.setButtonMenu(KDialog::Help, (QMenu*)khelpmenu.menu());
|
khashdialog.setButtonMenu(KDialog::Help, (QMenu*)khelpmenu.menu());
|
||||||
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
[Desktop Entry]
|
|
||||||
Name=KHash
|
|
||||||
GenericName=Checksum calculation utility
|
|
||||||
MimeType=all/allfiles;
|
|
||||||
Exec=khash --icon '%i' --caption '%c' %U
|
|
||||||
Icon=security-high
|
|
||||||
Type=Application
|
|
||||||
Terminal=false
|
|
||||||
StartupNotify=false
|
|
||||||
X-DocPath=khash/index.html
|
|
||||||
X-KDE-StartupNotify=false
|
|
||||||
X-DBUS-StartupType=Multi
|
|
||||||
Categories=Qt;KDE;Utility;
|
|
Loading…
Add table
Reference in a new issue