Commit c24b67e2 authored by Fathi Boudra's avatar Fathi Boudra
Browse files

Fix potential crashy code using QPointer

parent 073f342a
......@@ -45,7 +45,9 @@
KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd)
{
KUrlRequesterDialog *dlg = new KUrlRequesterDialog(vfs::pathOrUrl(url, KUrl::AddTrailingSlash), text, krApp);
QPointer<KUrlRequesterDialog> dlg = new KUrlRequesterDialog(vfs::pathOrUrl(url, KUrl::AddTrailingSlash),
text,
krApp);
dlg->urlRequester()->completionObject()->setDir(cwd.url());
KUrl u;
if (dlg->exec() == QDialog::Accepted) {
......@@ -57,8 +59,9 @@ KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd)
u.addPath(temp.path());
u.cleanPath();
if (u.protocol() == "zip" || u.protocol() == "krarc" || u.protocol() == "tar" || u.protocol() == "iso") {
if (QDir(u.path()).exists())
if (QDir(u.path()).exists()) {
u.setProtocol("file");
}
}
}
}
......@@ -68,7 +71,10 @@ KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd)
KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd, bool &queue)
{
KUrlRequesterDlgForCopy *dlg = new KUrlRequesterDlgForCopy(vfs::pathOrUrl(url, KUrl::AddTrailingSlash), text, false, krApp);
QPointer<KUrlRequesterDlgForCopy> dlg = new KUrlRequesterDlgForCopy(vfs::pathOrUrl(url, KUrl::AddTrailingSlash),
text,
false,
krApp);
dlg->hidePreserveAttrs();
dlg->urlRequester()->completionObject()->setDir(cwd.url());
KUrl u;
......@@ -81,8 +87,9 @@ KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd, bool &qu
u.addPath(temp.path());
u.cleanPath();
if (u.protocol() == "zip" || u.protocol() == "krarc" || u.protocol() == "tar" || u.protocol() == "iso") {
if (QDir(u.path()).exists())
if (QDir(u.path()).exists()) {
u.setProtocol("file");
}
}
}
}
......@@ -93,7 +100,10 @@ KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd, bool &qu
KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd, bool &queue, bool &preserveAttrs)
{
KUrlRequesterDlgForCopy *dlg = new KUrlRequesterDlgForCopy(vfs::pathOrUrl(url, KUrl::AddTrailingSlash), text, preserveAttrs, krApp);
QPointer<KUrlRequesterDlgForCopy> dlg = new KUrlRequesterDlgForCopy(vfs::pathOrUrl(url, KUrl::AddTrailingSlash),
text,
preserveAttrs,
krApp);
dlg->urlRequester()->completionObject()->setDir(cwd.url());
KUrl u;
if (dlg->exec() == QDialog::Accepted) {
......@@ -105,8 +115,9 @@ KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd, bool &qu
u.addPath(temp.path());
u.cleanPath();
if (u.protocol() == "zip" || u.protocol() == "krarc" || u.protocol() == "tar" || u.protocol() == "iso") {
if (QDir(u.path()).exists())
if (QDir(u.path()).exists()) {
u.setProtocol("file");
}
}
}
}
......@@ -118,7 +129,12 @@ KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd, bool &qu
KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd, bool &queue, bool &preserveAttrs, KUrl &baseURL)
{
KUrlRequesterDlgForCopy *dlg = new KUrlRequesterDlgForCopy(vfs::pathOrUrl(url, KUrl::AddTrailingSlash), text, preserveAttrs, krApp, true, baseURL);
QPointer<KUrlRequesterDlgForCopy> dlg = new KUrlRequesterDlgForCopy(vfs::pathOrUrl(url, KUrl::AddTrailingSlash),
text,
preserveAttrs,
krApp,
true,
baseURL);
dlg->urlRequester()->completionObject()->setDir(cwd.url());
KUrl u;
if (dlg->exec() == QDialog::Accepted) {
......@@ -130,8 +146,9 @@ KUrl KChooseDir::getDir(QString text, const KUrl& url, const KUrl& cwd, bool &qu
u.addPath(temp.path());
u.cleanPath();
if (u.protocol() == "zip" || u.protocol() == "krarc" || u.protocol() == "tar" || u.protocol() == "iso") {
if (QDir(u.path()).exists())
if (QDir(u.path()).exists()) {
u.setProtocol("file");
}
}
}
......
......@@ -65,48 +65,58 @@ KRQuery KRSpWidgets::getMask(QString caption, bool nameOnly, QWidget * parent)
if (!nameOnly) {
return FilterTabs::getQuery(parent);
} else {
KRMaskChoiceSub *p = new KRMaskChoiceSub(parent);
QPointer<KRMaskChoiceSub> p = new KRMaskChoiceSub(parent);
p->setWindowTitle(caption);
p->exec();
if (p->selection->currentText() == "") return KRQuery();
else return KRQuery(p->selection->currentText());
QString selection = p->selection->currentText();
delete p;
if (selection.isEmpty()) {
return KRQuery();
} else {
return KRQuery(selection);
}
}
}
/////////////////////////// newFTP ////////////////////////////////////////
KUrl KRSpWidgets::newFTP()
{
newFTPSub *p = new newFTPSub();
QPointer<newFTPSub> p = new newFTPSub();
p->exec();
if (p->url->currentText() == "") return KUrl(); // empty url
KUrl url;
QString uri = p->url->currentText();
if (uri.isEmpty()) {
delete p;
return KUrl(); // empty url
}
QString protocol = p->prefix->currentText();
protocol.truncate(protocol.length() - 3); // remove the trailing ://
QString username = p->username->text().simplified();
QString password = p->password->text().simplified();
QString uri = p->url->currentText();
int uriStart = uri.lastIndexOf('@'); /* lets the user enter user and password in the URI field */
int uriStart = uri.lastIndexOf('@'); /* lets the user enter user and password in the URI field */
if (uriStart != -1) {
QString uriUser = uri.left(uriStart);
QString uriPsw = QString();
uri = uri.mid(uriStart + 1);
int pswStart = uriUser.indexOf(':'); /* getting the password name from the URL */
int pswStart = uriUser.indexOf(':'); /* getting the password name from the URL */
if (pswStart != -1) {
uriPsw = uriUser.mid(pswStart + 1);
uriUser = uriUser.left(pswStart);
}
if (!uriUser.isEmpty()) /* handling the ftp proxy username and password also */
if (!uriUser.isEmpty()) { /* handling the ftp proxy username and password also */
username = username.isEmpty() ? uriUser : username + '@' + uriUser;
}
if (!uriPsw.isEmpty()) /* handling the ftp proxy username and password also */
if (!uriPsw.isEmpty()) { /* handling the ftp proxy username and password also */
password = password.isEmpty() ? uriPsw : password + '@' + uriPsw;
}
}
QString host = uri; /* separating the hostname and path from the uri */
QString host = uri; /* separating the hostname and path from the uri */
QString path = QString();
int pathStart = uri.indexOf("/");
if (pathStart != -1) {
......@@ -115,16 +125,21 @@ KUrl KRSpWidgets::newFTP()
}
/* setting the parameters of the URL */
KUrl url;
url.setProtocol(protocol);
url.setHost(host);
url.setPath(path);
if (protocol == "ftp" || protocol == "fish" || protocol == "sftp")
if (protocol == "ftp" || protocol == "fish" || protocol == "sftp") {
url.setPort(p->port->cleanText().toInt());
if (!username.isEmpty())
}
if (!username.isEmpty()) {
url.setUser(username);
if (!password.isEmpty())
}
if (!password.isEmpty()) {
url.setPass(password);
}
delete p;
return url;
}
......
......@@ -29,6 +29,7 @@ class KHistoryComboBox;
class newFTPGUI : public QDialog
{
Q_OBJECT
public:
newFTPGUI(QWidget* parent = 0);
~newFTPGUI();
......
......@@ -319,11 +319,12 @@ void AbstractJobThread::run()
{
QTimer::singleShot(0, this, SLOT(slotStart()));
QEventLoop threadLoop(this);
_loop = &threadLoop;
threadLoop.exec();
QPointer<QEventLoop> threadLoop = new QEventLoop(this);
_loop = threadLoop;
threadLoop->exec();
_loop = 0;
delete threadLoop;
}
void AbstractJobThread::terminate()
......
......@@ -613,11 +613,12 @@ QString KRarcHandler::getPassword(QString path)
bool keep = true;
QString user = "archive";
KIO::PasswordDialog passDlg(i18n("This archive is encrypted, please supply the password:"),
user, true);
passDlg.setPassword(password);
if (passDlg.exec() == KIO::PasswordDialog::Accepted) {
password = passDlg.password();
QPointer<KIO::PasswordDialog> passDlg = new KIO::PasswordDialog(i18n("This archive is encrypted, please supply the password:"),
user,
true);
passDlg->setPassword(password);
if (passDlg->exec() == KIO::PasswordDialog::Accepted) {
password = passDlg->password();
if (keep) {
if (!KWallet::Wallet::isOpen(KWallet::Wallet::NetworkWallet()) && wallet != 0) {
delete wallet;
......@@ -644,6 +645,7 @@ QString KRarcHandler::getPassword(QString path)
}
return password;
}
delete passDlg;
return "";
}
......
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