Commit 35061dad authored by Harald Hvaal's avatar Harald Hvaal
Browse files

Added a passwordneededquery class. Moved password code from part to the...

Added a passwordneededquery class. Moved password code from part to the kerfuffle library, so that password querying will have to be handled individually by the plugins.

svn path=/trunk/KDE/kdeutils/ark/; revision=876021
parent 1d9df4a5
......@@ -23,6 +23,7 @@
#include <QMessageBox>
#include <KLocale>
#include <KPasswordDialog>
#include <kio/renamedialog.h>
......@@ -101,4 +102,40 @@ namespace Kerfuffle
return m_data.value("newFilename").toString();
}
PasswordNeededQuery::PasswordNeededQuery(QString archiveFilename, bool incorrectTryAgain)
{
m_data["archiveFilename"] = archiveFilename;
m_data["incorrectTryAgain"] = incorrectTryAgain;
}
void PasswordNeededQuery::execute()
{
KPasswordDialog dlg( NULL );
dlg.setPrompt( i18n("The archive '%1'is password protected. Please enter the password to extract the file.",
m_data.value("archiveFilename").toString()));
if (m_data.value("incorrectTryAgain").toBool()) {
dlg.showErrorMessage(i18n("Incorrect password, please try again."), KPasswordDialog::PasswordError);
}
if( !dlg.exec() )
{
setResponse(false);
return;
}
m_data["password"] = dlg.password();
setResponse(true);
}
QString PasswordNeededQuery::password()
{
return m_data.value("password").toString();
}
bool PasswordNeededQuery::responseCancelled()
{
return !m_data.value("response").toBool();
}
}
......@@ -84,6 +84,16 @@ namespace Kerfuffle
QString newFilename();
};
class KERFUFFLE_EXPORT PasswordNeededQuery : public Query
{
public:
PasswordNeededQuery(QString archiveFilename, bool incorrectTryAgain = false);
void execute();
bool responseCancelled();
QString password();
};
}
#endif /* ifndef _QUERIES_H_ */
......@@ -43,10 +43,8 @@
#include <KRun>
#include <KFileDialog>
#include <KConfigGroup>
#include <KPasswordDialog>
#include <KStandardDirs>
#include <QCursor>
#include <QAction>
#include <QSplitter>
......@@ -402,15 +400,6 @@ void Part::slotPreview( const QModelIndex & index )
const ArchiveEntry& entry = m_model->entryForIndex( index );
if ( !entry.isEmpty() )
{
if (entry.contains(IsPasswordProtected) && entry[IsPasswordProtected].toBool())
{
KPasswordDialog dlg( NULL );
dlg.setPrompt( i18n("This file is password protected. Please enter the password to extract the file."));
if( !dlg.exec() )
return; //the user canceled
m_model->archive()->setPassword(dlg.password());
}
m_previewDir = new KTempDir();
ExtractJob *job = m_model->extractFile( entry[ InternalID ], m_previewDir->name(), Archive::CopyFlags() );
registerJob( job );
......@@ -501,15 +490,6 @@ void Part::slotExtractFiles()
//this is done to update the quick extract menu
updateActions();
if (m_model->archive()->isPasswordProtected()) {
KPasswordDialog dlg( NULL );
dlg.setPrompt( i18n("This archive contains one or more password protected files. Please enter the password to extract these."));
if( !dlg.exec() )
return; //the user canceled
m_model->archive()->setPassword(dlg.password());
}
QString destinationDirectory;
if (dialog.extractToSubfolder())
{
......
......@@ -152,6 +152,8 @@ bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & des
if (flags & Archive::TruncateCommonBase)
commonBase = findCommonBase(files);
startprocess:
KProcess kp;
kp.setOutputChannelMode(KProcess::MergedChannels);
if (!m_unrarpath.isNull()) kp << m_unrarpath;
......@@ -177,6 +179,7 @@ bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & des
}
//kp << destinationDirectory;
kp.start();
if (!kp.waitForStarted()){
kDebug( 1601 ) << "Rar did not start";
......@@ -184,8 +187,9 @@ bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & des
}
while (kp.waitForReadyRead()) {
QStringList lines = QString(kp.readAll()).split("\n");
foreach(const QString &line, lines) {
while (kp.canReadLine()) {
const QString line = kp.readLine();
//read the percentage
int pos = line.indexOf('%');
......@@ -208,7 +212,30 @@ bool RARInterface::copyFiles( const QList<QVariant> & files, const QString & des
else if (query.responseOverwrite())
kp.write("y\n");
}
if (line.contains("password incorrect")) {
QString filename = line.right(line.count() - line.indexOf(" for "));
filename.chop(1);
kDebug( 1601 ) << "Password protected file detected: " << filename;
Kerfuffle::PasswordNeededQuery query(filename, !password().isEmpty());
emit userQuery(&query);
query.waitForResponse();
kp.terminate();
kp.waitForFinished();
if (query.responseCancelled()) {
error(i18n("Password input cancelled by user."));
return false;
}
kDebug( 1601 ) << "Restarting process...";
setPassword(query.password());
goto startprocess;
}
}
}
if (kp.state() != QProcess::NotRunning) {
......
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