kutils: drop unused KPasswdRouletteDialog class

was experimental

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-18 23:21:24 +03:00
parent 7f593b37ef
commit 9fb18a72e5
4 changed files with 0 additions and 290 deletions

View file

@ -12,8 +12,6 @@ add_definitions(-DKDE_DEFAULT_DEBUG_AREA=51004)
set(kpasswdstore_LIB_SRCS
kpasswdstore.cpp
kpasswdroulettedialog.cpp
kpasswdroulettedialog.ui
)
add_library(kpasswdstore SHARED ${kpasswdstore_LIB_SRCS})
@ -35,7 +33,6 @@ install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/kpasswdstore_export.h
kpasswdstore.h
kpasswdroulettedialog.h
DESTINATION ${KDE4_INCLUDE_INSTALL_DIR}
)

View file

@ -1,118 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kpasswdroulettedialog.h"
#include "krandom.h"
#include "klocale.h"
#include "kdebug.h"
#include "ui_kpasswdroulettedialog.h"
#include <QProcess>
class KPasswdRouletteDialogPrivate
{
public:
KPasswdRouletteDialogPrivate();
bool isvalid;
QString validpasswd;
QMap<QString, QString> passwdmap;
Ui::KPasswdRouletteDialogUI ui;
};
KPasswdRouletteDialogPrivate::KPasswdRouletteDialogPrivate()
: isvalid(false)
{
}
KPasswdRouletteDialog::KPasswdRouletteDialog(QWidget *parent)
: KDialog(parent),
d(new KPasswdRouletteDialogPrivate())
{
KDialog::setButtons(KDialog::Ok | KDialog::Cancel);
d->ui.setupUi(mainWidget());
d->ui.ksqueezedtextlabel->setText(i18n("Enter password:"));
d->ui.klineedit->setFocus();
}
KPasswdRouletteDialog::~KPasswdRouletteDialog()
{
delete d;
}
bool KPasswdRouletteDialog::fortunate(const uint max)
{
QMap<QString, QString> passwordsmap;
while (passwordsmap.size() < max) {
QProcess fortuneproc(this);
fortuneproc.start("fortune");
if (!fortuneproc.waitForStarted() || !fortuneproc.waitForFinished()) {
kWarning() << "Fortune process failed";
return false;
}
const QByteArray fortunedata = fortuneproc.readAllStandardOutput();
QString question;
QString answer;
foreach (const QByteArray &fortuneline, fortunedata.split('\n')) {
const QByteArray trimmedfortuneline = fortuneline.trimmed();
if (trimmedfortuneline.startsWith("Q:")) {
question = QString::fromLocal8Bit(trimmedfortuneline.constData(), trimmedfortuneline.size());
question = question.mid(2).trimmed();
} else if (trimmedfortuneline.startsWith("A:")) {
answer = QString::fromLocal8Bit(trimmedfortuneline.constData(), trimmedfortuneline.size());
answer = answer.mid(2).trimmed();
}
if (!question.isEmpty() && !answer.isEmpty()) {
passwordsmap.insert(question, answer);
break;
}
}
}
foreach (const QString &question, passwordsmap.keys()) {
addPasswd(question, passwordsmap.value(question));
}
return true;
}
void KPasswdRouletteDialog::addPasswd(const QString &label, const QString &passwd)
{
d->passwdmap.insert(label, passwd);
const int randomrange = KRandom::randomMax(d->passwdmap.size());
const QList<QString> labelslist = d->passwdmap.keys();
const QString randomkey = labelslist.at(randomrange);
d->validpasswd = d->passwdmap.value(randomkey);
d->ui.ksqueezedtextlabel->setText(randomkey);
d->ui.klineedit->clear();
}
bool KPasswdRouletteDialog::isValid() const
{
return d->isvalid;
}
void KPasswdRouletteDialog::accept()
{
d->isvalid = (d->ui.klineedit->text() == d->validpasswd);
KDialog::accept();
}

View file

@ -1,101 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KPASSWDROULETTEDIALOG_H
#define KPASSWDROULETTEDIALOG_H
#include "kpasswdstore_export.h"
#include <kdialog.h>
#include <QWidget>
class KPasswdRouletteDialogPrivate;
/*!
Class to ask for password from a choice of several passwords. The choice is not for the user
to make however, it is up to RNG which of the added choices will to be presented.
@code
KPasswdRouletteDialog kpasswdroulettedialog;
kpasswdroulettedialog.addPasswd("Is foo in the bar?", "no");
kpasswdroulettedialog.addPasswd("Can I haz a password?", "yes");
if (kpasswdroulettedialog.exec() != KPasswdRouletteDialog::Accepted) {
qDebug() << "password dialog not accepted";
} else if (kpasswdroulettedialog.isValid()) {
qDebug() << "password is valid";
} else {
qWarning() << "password is not valid";
}
@endcode
Alternatively, if you have fortune installed:
@code
KPasswdRouletteDialog kpasswdroulettedialog;
if (kpasswdroulettedialog.fortunate()) {
if (kpasswdroulettedialog.exec() != KPasswdRouletteDialog::Accepted) {
qDebug() << "password dialog not accepted";
} else if (kpasswdroulettedialog.isValid()) {
qDebug() << "password is valid";
} else {
qWarning() << "password is not valid";
}
} else {
qWarning() << "fortune not available";
}
@endcode
@since 4.21
*/
class KPASSWDSTORE_EXPORT KPasswdRouletteDialog : public KDialog
{
Q_OBJECT
public:
/*!
@brief Contructs object with @p parent
*/
KPasswdRouletteDialog(QWidget *parent = nullptr);
~KPasswdRouletteDialog();
/*!
@brief Adds answers from `fortune` as valid choices, not more than @p max
@warning This can take a lot of time depending on the available fortunes
and RNG, may never end actually. The answer to pretty much every question
`fortune` can output must also be known
*/
bool fortunate(const uint max = 4);
/*!
@brief Adds @p passwd as valid choice with the given @p label
*/
void addPasswd(const QString &label, const QString &passwd);
/*!
@brief Returns @p true if valid password was entered, @p false
otherwise
*/
bool isValid() const;
public Q_SLOTS:
virtual void accept();
private:
Q_DISABLE_COPY(KPasswdRouletteDialog);
KPasswdRouletteDialogPrivate *const d;
};
#endif // KPASSWDROULETTEDIALOG_H

View file

@ -1,68 +0,0 @@
<?xml version="1.0" encoding="System"?>
<ui version="4.0">
<class>KPasswdRouletteDialogUI</class>
<widget class="QWidget" name="KPasswdRouletteDialogUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>385</width>
<height>80</height>
</rect>
</property>
<property name="windowTitle">
<string>KPasswdRouletteDialogUI</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="KSqueezedTextLabel" name="ksqueezedtextlabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>KSqueezedTextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KLineEdit" name="klineedit">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KLineEdit</class>
<extends></extends>
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>KSqueezedTextLabel</class>
<extends></extends>
<header>ksqueezedtextlabel.h</header>
</customwidget>
</customwidgets>
<connections/>
</ui>