~blue-shell/accounts/stable

« back to all changes in this revision

Viewing changes to src/owncloud/jobs/ocreatefile.cpp

  • Committer: Àlex Fiestas
  • Date: 2013-04-29 13:48:22 UTC
  • Revision ID: git-v1:81c2051ef8208dcc49c28e5079814f50fcc10a30
Try to fetch the realm from owncloud server, if we can't use the schema

This fixes kio asking for the password again

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <KDirNotify>
28
28
#include <KStandardDirs>
29
29
#include <KWallet/Wallet>
 
30
#include <kio/job.h>
30
31
#include <KDebug>
31
32
 
32
33
using namespace KWallet;
45
46
 
46
47
void OCreateFile::start()
47
48
{
48
 
    QMetaObject::invokeMethod(this, "createNetAttach", Qt::QueuedConnection);
 
49
    QMetaObject::invokeMethod(this, "getRealm", Qt::QueuedConnection);
 
50
}
 
51
 
 
52
void OCreateFile::getRealm()
 
53
{
 
54
    kDebug();
 
55
    KUrl url(m_config.readEntry("server", ""));
 
56
    url.setUser(m_config.name());
 
57
    url.setScheme("webdav");
 
58
    url.addPath("files/webdav.php/");
 
59
 
 
60
    KIO::TransferJob* job = KIO::get(url , KIO::NoReload, KIO::HideProgressInfo);
 
61
    connect(job, SIGNAL(finished(KJob*)), SLOT(gotRealm(KJob*)));
 
62
    KIO::MetaData data;
 
63
    data.insert("PropagateHttpHeader", "true");
 
64
    job->setMetaData(data);
 
65
    job->setUiDelegate(0);
 
66
    job->start();
 
67
}
 
68
 
 
69
void OCreateFile::gotRealm(KJob* job)
 
70
{
 
71
    KIO::TransferJob* hJob = qobject_cast<KIO::TransferJob*>(job);
 
72
    QRegExp rx("www-authenticate: Basic realm=\"(\\S+)\"\n");
 
73
    QString headers = hJob->metaData().value("HTTP-Headers");
 
74
    if (rx.indexIn(headers) != -1) {
 
75
        m_realm = rx.cap(1);
 
76
    }
 
77
 
 
78
    createNetAttach();
49
79
}
50
80
 
51
81
void OCreateFile::createNetAttach()
101
131
    walletUrl.append("@");
102
132
    walletUrl.append(url.host());
103
133
    walletUrl.append(":-1");//Overwrite the first option
 
134
    if (!m_realm.isEmpty()) {
 
135
        walletUrl.append(m_realm);
 
136
    } else {
 
137
        walletUrl.append("webdav");
 
138
    }
104
139
 
105
140
    WId windowId = 0;
106
141
    if (qApp->activeWindow()) {