Changeset View
Changeset View
Standalone View
Standalone View
krusader/Archive/krarchandler.cpp
Show All 29 Lines | |||||
30 | 30 | | |||
31 | #include <KArchive/KTar> | 31 | #include <KArchive/KTar> | ||
32 | #include <KConfigCore/KSharedConfig> | 32 | #include <KConfigCore/KSharedConfig> | ||
33 | #include <KI18n/KLocalizedString> | 33 | #include <KI18n/KLocalizedString> | ||
34 | #include <KIO/Global> | 34 | #include <KIO/Global> | ||
35 | #include <KWallet/KWallet> | 35 | #include <KWallet/KWallet> | ||
36 | #include <KWidgetsAddons/KMessageBox> | 36 | #include <KWidgetsAddons/KMessageBox> | ||
37 | #include <KWidgetsAddons/KPasswordDialog> | 37 | #include <KWidgetsAddons/KPasswordDialog> | ||
38 | #include <utility> | ||||
38 | 39 | | |||
39 | #include "kr7zencryptionchecker.h" | 40 | #include "kr7zencryptionchecker.h" | ||
40 | #include "../krglobal.h" | 41 | #include "../krglobal.h" | ||
41 | #include "../defaults.h" | 42 | #include "../defaults.h" | ||
42 | #include "../krservices.h" | 43 | #include "../krservices.h" | ||
43 | #include "../Dialogs/krpleasewait.h" | 44 | #include "../Dialogs/krpleasewait.h" | ||
44 | #include "../../krArc/krlinecountingprocess.h" | 45 | #include "../../krArc/krlinecountingprocess.h" | ||
45 | 46 | | |||
Show All 32 Lines | 50 | public: | |||
78 | virtual void incrementProgress(int c) Q_DECL_OVERRIDE { | 79 | virtual void incrementProgress(int c) Q_DECL_OVERRIDE { | ||
79 | krApp->plzWait->incProgress(c); | 80 | krApp->plzWait->incProgress(c); | ||
80 | } | 81 | } | ||
81 | }; | 82 | }; | ||
82 | #endif | 83 | #endif | ||
83 | 84 | | |||
84 | static QStringList arcProtocols = QString("tar;bzip;bzip2;lzma;xz;gzip;krarc;zip").split(';'); | 85 | static QStringList arcProtocols = QString("tar;bzip;bzip2;lzma;xz;gzip;krarc;zip").split(';'); | ||
85 | 86 | | |||
86 | KWallet::Wallet * KRarcHandler::wallet = 0; | 87 | KWallet::Wallet * KRarcHandler::wallet = nullptr; | ||
87 | 88 | | |||
88 | QStringList KRarcHandler::supportedPackers() | 89 | QStringList KRarcHandler::supportedPackers() | ||
89 | { | 90 | { | ||
90 | QStringList packers; | 91 | QStringList packers; | ||
91 | 92 | | |||
92 | // we will simply try to find the packers here.. | 93 | // we will simply try to find the packers here.. | ||
93 | if (KrServices::cmdExist("tar")) packers.append("tar"); | 94 | if (KrServices::cmdExist("tar")) packers.append("tar"); | ||
94 | if (KrServices::cmdExist("gzip")) packers.append("gzip"); | 95 | if (KrServices::cmdExist("gzip")) packers.append("gzip"); | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 135 | return (type == "zip" && lst.contains("unzip")) | |||
147 | || (type == "rpm" && lst.contains("cpio")) | 148 | || (type == "rpm" && lst.contains("cpio")) | ||
148 | || (type == "cpio" && lst.contains("cpio")) | 149 | || (type == "cpio" && lst.contains("cpio")) | ||
149 | || (type == "rar" && (lst.contains("unrar") || lst.contains("rar"))) | 150 | || (type == "rar" && (lst.contains("unrar") || lst.contains("rar"))) | ||
150 | || (type == "arj" && (lst.contains("unarj") || lst.contains("arj"))) | 151 | || (type == "arj" && (lst.contains("unarj") || lst.contains("arj"))) | ||
151 | || (type == "deb" && (lst.contains("dpkg") && lst.contains("tar"))) | 152 | || (type == "deb" && (lst.contains("dpkg") && lst.contains("tar"))) | ||
152 | || (type == "7z" && lst.contains("7z")); | 153 | || (type == "7z" && lst.contains("7z")); | ||
153 | } | 154 | } | ||
154 | 155 | | |||
155 | long KRarcHandler::arcFileCount(QString archive, QString type, QString password, KRarcObserver *observer) | 156 | long KRarcHandler::arcFileCount(const QString& archive, const QString& type, const QString& password, KRarcObserver *observer) | ||
156 | { | 157 | { | ||
157 | int divideWith = 1; | 158 | int divideWith = 1; | ||
158 | 159 | | |||
159 | // first check if supported | 160 | // first check if supported | ||
160 | if (!arcSupported(type)) | 161 | if (!arcSupported(type)) | ||
161 | return 0; | 162 | return 0; | ||
162 | 163 | | |||
163 | // bzip2, gzip, etc. archives contain only one file | 164 | // bzip2, gzip, etc. archives contain only one file | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
226 | count = list.readAllStandardOutput().count('\n'); | 227 | count = list.readAllStandardOutput().count('\n'); | ||
227 | 228 | | |||
228 | //make sure you call stopWait after this function return... | 229 | //make sure you call stopWait after this function return... | ||
229 | // observer->subJobStopped(); | 230 | // observer->subJobStopped(); | ||
230 | 231 | | |||
231 | return count / divideWith; | 232 | return count / divideWith; | ||
232 | } | 233 | } | ||
233 | 234 | | |||
234 | bool KRarcHandler::unpack(QString archive, QString type, QString password, QString dest, KRarcObserver *observer) | 235 | bool KRarcHandler::unpack(QString archive, const QString& type, const QString& password, const QString& dest, KRarcObserver *observer) | ||
235 | { | 236 | { | ||
236 | KConfigGroup group(krConfig, "Archives"); | 237 | KConfigGroup group(krConfig, "Archives"); | ||
237 | if (group.readEntry("Test Before Unpack", _TestBeforeUnpack)) { | 238 | if (group.readEntry("Test Before Unpack", _TestBeforeUnpack)) { | ||
238 | // test first - or be sorry later... | 239 | // test first - or be sorry later... | ||
239 | if (type != "rpm" && type != "deb" && !test(archive, type, password, observer, 0)) { | 240 | if (type != "rpm" && type != "deb" && !test(archive, type, password, observer, 0)) { | ||
240 | observer->error(i18n("Failed to unpack %1.", archive)); | 241 | observer->error(i18n("Failed to unpack %1.", archive)); | ||
241 | return false; | 242 | return false; | ||
242 | } | 243 | } | ||
▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Line(s) | |||||
358 | if (proc.exitStatus() != QProcess::NormalExit || !checkStatus(type, proc.exitCode())) { | 359 | if (proc.exitStatus() != QProcess::NormalExit || !checkStatus(type, proc.exitCode())) { | ||
359 | observer->detailedError(i18n("Failed to unpack %1.", archive), | 360 | observer->detailedError(i18n("Failed to unpack %1.", archive), | ||
360 | observer->wasCancelled() ? i18n("User cancelled.") : proc.getErrorMsg()); | 361 | observer->wasCancelled() ? i18n("User cancelled.") : proc.getErrorMsg()); | ||
361 | return false; | 362 | return false; | ||
362 | } | 363 | } | ||
363 | return true; // SUCCESS | 364 | return true; // SUCCESS | ||
364 | } | 365 | } | ||
365 | 366 | | |||
366 | bool KRarcHandler::test(QString archive, QString type, QString password, KRarcObserver *observer, long count) | 367 | bool KRarcHandler::test(const QString& archive, const QString& type, const QString& password, KRarcObserver *observer, long count) | ||
367 | { | 368 | { | ||
368 | // choose the right packer for the job | 369 | // choose the right packer for the job | ||
369 | QStringList packer; | 370 | QStringList packer; | ||
370 | 371 | | |||
371 | // set the right packer to do the job | 372 | // set the right packer to do the job | ||
372 | if (type == "zip") packer << KrServices::fullPathName("unzip") << "-t"; | 373 | if (type == "zip") packer << KrServices::fullPathName("unzip") << "-t"; | ||
373 | else if (type == "tar") packer << KrServices::fullPathName("tar") << "-tvf"; | 374 | else if (type == "tar") packer << KrServices::fullPathName("tar") << "-tvf"; | ||
374 | else if (type == "tgz") packer << KrServices::fullPathName("tar") << "-tvzf"; | 375 | else if (type == "tgz") packer << KrServices::fullPathName("tar") << "-tvzf"; | ||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
425 | 426 | | |||
426 | // check the return value | 427 | // check the return value | ||
427 | if (proc.exitStatus() != QProcess::NormalExit || !checkStatus(type, proc.exitCode())) | 428 | if (proc.exitStatus() != QProcess::NormalExit || !checkStatus(type, proc.exitCode())) | ||
428 | return false; | 429 | return false; | ||
429 | 430 | | |||
430 | return true; // SUCCESS | 431 | return true; // SUCCESS | ||
431 | } | 432 | } | ||
432 | 433 | | |||
433 | bool KRarcHandler::pack(QStringList fileNames, QString type, QString dest, long count, QMap<QString, QString> extraProps, KRarcObserver *observer) | 434 | bool KRarcHandler::pack(QStringList fileNames, QString type, const QString& dest, long count, QMap<QString, QString> extraProps, KRarcObserver *observer) | ||
434 | { | 435 | { | ||
435 | // set the right packer to do the job | 436 | // set the right packer to do the job | ||
436 | QStringList packer; | 437 | QStringList packer; | ||
437 | 438 | | |||
438 | if (type == "zip") { | 439 | if (type == "zip") { | ||
439 | packer << KrServices::fullPathName("zip") << "-ry"; | 440 | packer << KrServices::fullPathName("zip") << "-ry"; | ||
440 | } else if (type == "cbz") { | 441 | } else if (type == "cbz") { | ||
441 | packer << KrServices::fullPathName("zip") << "-ry"; | 442 | packer << KrServices::fullPathName("zip") << "-ry"; | ||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | |||||
523 | 524 | | |||
524 | if (extraProps.count("CommandLineSwitches") > 0) | 525 | if (extraProps.count("CommandLineSwitches") > 0) | ||
525 | packer << QString("%1").arg(extraProps[ "CommandLineSwitches" ]); | 526 | packer << QString("%1").arg(extraProps[ "CommandLineSwitches" ]); | ||
526 | 527 | | |||
527 | // prepare to pack | 528 | // prepare to pack | ||
528 | KrLinecountingProcess proc; | 529 | KrLinecountingProcess proc; | ||
529 | proc << packer << dest; | 530 | proc << packer << dest; | ||
530 | 531 | | |||
531 | for (QStringList::Iterator file = fileNames.begin(); file != fileNames.end(); ++file) { | 532 | for (auto & fileName : fileNames) { | ||
532 | proc << *file; | 533 | proc << fileName; | ||
533 | } | 534 | } | ||
534 | 535 | | |||
535 | // tell the user to wait | 536 | // tell the user to wait | ||
536 | observer->subJobStarted(i18n("Packing File(s)"), count); | 537 | observer->subJobStarted(i18n("Packing File(s)"), count); | ||
537 | if (count != 0) | 538 | if (count != 0) | ||
538 | connect(&proc, SIGNAL(newOutputLines(int)), | 539 | connect(&proc, SIGNAL(newOutputLines(int)), | ||
539 | observer, SLOT(incrementProgress(int))); | 540 | observer, SLOT(incrementProgress(int))); | ||
540 | 541 | | |||
Show All 31 Lines | 572 | { | |||
572 | if (!wallet) { | 573 | if (!wallet) { | ||
573 | // find a suitable parent window | 574 | // find a suitable parent window | ||
574 | QWidget *actWindow = QApplication::activeWindow(); | 575 | QWidget *actWindow = QApplication::activeWindow(); | ||
575 | if (!actWindow) | 576 | if (!actWindow) | ||
576 | actWindow = (QWidget*) QApplication::desktop(); | 577 | actWindow = (QWidget*) QApplication::desktop(); | ||
577 | 578 | | |||
578 | wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), actWindow->effectiveWinId()); | 579 | wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), actWindow->effectiveWinId()); | ||
579 | } | 580 | } | ||
580 | return (wallet != 0); | 581 | return (wallet != nullptr); | ||
581 | } | 582 | } | ||
582 | 583 | | |||
583 | QString KRarcHandler::getPassword(QString path) | 584 | QString KRarcHandler::getPassword(const QString& path) | ||
584 | { | 585 | { | ||
585 | QString password; | 586 | QString password; | ||
586 | 587 | | |||
587 | QString key = "krarc-" + path; | 588 | QString key = "krarc-" + path; | ||
588 | 589 | | |||
589 | if (!KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::PasswordFolder(), key)) { | 590 | if (!KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::NetworkWallet(), KWallet::Wallet::PasswordFolder(), key)) { | ||
590 | if (!KWallet::Wallet::isOpen(KWallet::Wallet::NetworkWallet()) && wallet != 0) { | 591 | if (!KWallet::Wallet::isOpen(KWallet::Wallet::NetworkWallet()) && wallet != nullptr) { | ||
591 | delete wallet; | 592 | delete wallet; | ||
592 | wallet = 0; | 593 | wallet = nullptr; | ||
593 | } | 594 | } | ||
594 | if (openWallet() && wallet->hasFolder(KWallet::Wallet::PasswordFolder())) { | 595 | if (openWallet() && wallet->hasFolder(KWallet::Wallet::PasswordFolder())) { | ||
595 | wallet->setFolder(KWallet::Wallet::PasswordFolder()); | 596 | wallet->setFolder(KWallet::Wallet::PasswordFolder()); | ||
596 | QMap<QString, QString> map; | 597 | QMap<QString, QString> map; | ||
597 | if (wallet->readMap(key, map) == 0) { | 598 | if (wallet->readMap(key, map) == 0) { | ||
598 | QMap<QString, QString>::const_iterator it = map.constFind("password"); | 599 | QMap<QString, QString>::const_iterator it = map.constFind("password"); | ||
599 | if (it != map.constEnd()) | 600 | if (it != map.constEnd()) | ||
600 | password = it.value(); | 601 | password = it.value(); | ||
601 | } | 602 | } | ||
602 | } | 603 | } | ||
603 | } | 604 | } | ||
604 | 605 | | |||
605 | bool keep = true; | 606 | bool keep = true; | ||
606 | QString user = "archive"; | 607 | QString user = "archive"; | ||
607 | QPointer<KPasswordDialog> passDlg = new KPasswordDialog(0L, KPasswordDialog::ShowKeepPassword); | 608 | QPointer<KPasswordDialog> passDlg = new KPasswordDialog(nullptr, KPasswordDialog::ShowKeepPassword); | ||
608 | passDlg->setPrompt(i18n("This archive is encrypted, please supply the password:") ), | 609 | passDlg->setPrompt(i18n("This archive is encrypted, please supply the password:") ), | ||
609 | passDlg->setUsername(user); | 610 | passDlg->setUsername(user); | ||
610 | passDlg->setPassword(password); | 611 | passDlg->setPassword(password); | ||
611 | if (passDlg->exec() == KPasswordDialog::Accepted) { | 612 | if (passDlg->exec() == KPasswordDialog::Accepted) { | ||
612 | password = passDlg->password(); | 613 | password = passDlg->password(); | ||
613 | if (keep) { | 614 | if (keep) { | ||
614 | if (!KWallet::Wallet::isOpen(KWallet::Wallet::NetworkWallet()) && wallet != 0) { | 615 | if (!KWallet::Wallet::isOpen(KWallet::Wallet::NetworkWallet()) && wallet != nullptr) { | ||
615 | delete wallet; | 616 | delete wallet; | ||
616 | wallet = 0; | 617 | wallet = nullptr; | ||
617 | } | 618 | } | ||
618 | if (openWallet()) { | 619 | if (openWallet()) { | ||
619 | bool ok = true; | 620 | bool ok = true; | ||
620 | if (!wallet->hasFolder(KWallet::Wallet::PasswordFolder())) | 621 | if (!wallet->hasFolder(KWallet::Wallet::PasswordFolder())) | ||
621 | ok = wallet->createFolder(KWallet::Wallet::PasswordFolder()); | 622 | ok = wallet->createFolder(KWallet::Wallet::PasswordFolder()); | ||
622 | if (ok) { | 623 | if (ok) { | ||
623 | wallet->setFolder(KWallet::Wallet::PasswordFolder()); | 624 | wallet->setFolder(KWallet::Wallet::PasswordFolder()); | ||
624 | QMap<QString, QString> map; | 625 | QMap<QString, QString> map; | ||
Show All 14 Lines | |||||
639 | bool KRarcHandler::isArchive(const QUrl &url) | 640 | bool KRarcHandler::isArchive(const QUrl &url) | ||
640 | { | 641 | { | ||
641 | QString protocol = url.scheme(); | 642 | QString protocol = url.scheme(); | ||
642 | if (arcProtocols.indexOf(protocol) != -1) | 643 | if (arcProtocols.indexOf(protocol) != -1) | ||
643 | return true; | 644 | return true; | ||
644 | else return false; | 645 | else return false; | ||
645 | } | 646 | } | ||
646 | 647 | | |||
647 | QString KRarcHandler::getType(bool &encrypted, QString fileName, QString mime, bool checkEncrypted, bool fast) | 648 | QString KRarcHandler::getType(bool &encrypted, QString fileName, const QString& mime, bool checkEncrypted, bool fast) | ||
648 | { | 649 | { | ||
649 | QString result = detectArchive(encrypted, fileName, checkEncrypted, fast); | 650 | QString result = detectArchive(encrypted, std::move(fileName), checkEncrypted, fast); | ||
650 | if (result.isNull()) { | 651 | if (result.isNull()) { | ||
651 | // Then the type is based on the mime type | 652 | // Then the type is based on the mime type | ||
652 | return getShortTypeFromMime(mime); | 653 | return getShortTypeFromMime(mime); | ||
653 | } | 654 | } | ||
654 | return result; | 655 | return result; | ||
655 | } | 656 | } | ||
656 | 657 | | |||
657 | bool KRarcHandler::checkStatus(QString type, int exitCode) | 658 | bool KRarcHandler::checkStatus(const QString& type, int exitCode) | ||
658 | { | 659 | { | ||
659 | return KrArcBaseManager::checkStatus(type, exitCode); | 660 | return KrArcBaseManager::checkStatus(type, exitCode); | ||
660 | } | 661 | } | ||
661 | 662 | | |||
662 | void KRarcHandler::checkIf7zIsEncrypted(bool &encrypted, QString fileName) | 663 | void KRarcHandler::checkIf7zIsEncrypted(bool &encrypted, QString fileName) | ||
663 | { | 664 | { | ||
664 | Kr7zEncryptionChecker proc; | 665 | Kr7zEncryptionChecker proc; | ||
665 | // TODO incorporate all this in Kr7zEncryptionChecker | 666 | // TODO incorporate all this in Kr7zEncryptionChecker | ||
666 | proc << KrServices::fullPathName("7z") << "-y" << "t"; | 667 | proc << KrServices::fullPathName("7z") << "-y" << "t"; | ||
667 | proc << fileName; | 668 | proc << fileName; | ||
668 | proc.start(); | 669 | proc.start(); | ||
669 | proc.waitForFinished(); | 670 | proc.waitForFinished(); | ||
670 | encrypted = proc.isEncrypted(); | 671 | encrypted = proc.isEncrypted(); | ||
671 | } | 672 | } | ||
672 | 673 | |