void FileModel::initDav(const QString &davUrl, const QString &davUser, const QString &davPassword) { mDavUrl = davUrl; if (!mDavUrl.endsWith("/")) mDavUrl += "/"; mDavUrl = mDavUrl + "remote.php/webdav"; mAuthUrl = mDavUrl; if (mAuthUrl.startsWith("http://")) mAuthUrl = mAuthUrl.replace("http://", "http://" + davUser + ":" + davPassword + "@"); else if (mAuthUrl.startsWith("https://")) mAuthUrl = mAuthUrl.replace("https://", "https://" + davUser + ":" + davPassword + "@"); // parse Url to get parts QUrl qtUrl(mDavUrl); mDavClient = new QWebDAV(); connect(mDavClient, SIGNAL(directoryListingReady(QList<QWebDAV::FileInfo>)), this, SLOT(addDavFiles(QList<QWebDAV::FileInfo>))); mDavClient->initialize(mDavUrl, davUser, davPassword, qtUrl.path()); emit davSettingsChanged(); }
void QWebDAV::processDirList(QByteArray xml, QString url) { syncDebug() << "\n\n\n" << xml; QList<QWebDAV::FileInfo> list; QDomDocument domDocument; QString errorStr; int errorLine; int errorColumn; if (!domDocument.setContent(xml, true, &errorStr, &errorLine, &errorColumn)) { syncDebug() << "Error at line " << errorLine << " column " << errorColumn; syncDebug() << errorStr; emit directoryListingError(url); return; } QDomElement root = domDocument.documentElement(); if( root.tagName() != "multistatus" ) { syncDebug() << "Badly formatted XML!" << xml; emit directoryListingError(url); return; } QString name; QString size; QString last; QString type; QString available; bool locked; QDomElement response = root.firstChildElement("response"); while (!response.isNull()) { // Parse first response QDomElement child = response.firstChildElement(); while (!child.isNull()) { //syncDebug() << "ChildName: " << child.tagName(); if ( child.tagName() == "href" ) { name = child.text(); } else if ( child.tagName() == "propstat") { QDomElement prop = child.firstChildElement("prop") .firstChildElement(); while(!prop.isNull()) { //syncDebug() << "PropName: " << prop.tagName(); if( prop.tagName() == "getlastmodified") { last = prop.text(); } else if ( prop.tagName() == "getcontentlength" || prop.tagName() == "quota-used-bytes") { size = prop.text(); } else if ( prop.tagName() == "quota-available-bytes") { available = prop.text(); } else if ( prop.tagName() == "resourcetype") { QDomElement resourseType = prop.firstChildElement(""); type = resourseType.tagName(); } else if ( prop.tagName() == "lockdiscovery") { if(prop.text() == "" ) { // Not locked locked = false; } else { // Locked QDomElement lock = prop.firstChildElement("activelock"); while(!lock.isNull()) { if( prop.tagName() == "lockscope" && prop.text() == "exclusive" ) { locked = true; } lock = lock.nextSiblingElement(); } } } prop = prop.nextSiblingElement(); } } child = child.nextSiblingElement(); } // syncDebug() << "Name: " << name << "\nSize: " << size << "\nLastModified: " // << last << "\nSizeAvailable: " << available << "\nType: " // << type << "\n"; // Filter out the requested directory from this list //syncDebug() << "Type: " << type << "Name: " << name << " URL: " << url; name = QUrl::fromPercentEncoding(name.toLatin1()); if( !(type == "collection" && name == url) ) { // Filter out the pathname from the filename and decode URL name.replace(mPathFilter,""); // Store lastmodified as an EPOCH format last.replace(" +0000",""); last.replace(",",""); QDateTime date = QDateTime::fromString(last, "ddd dd MMM yyyy HH:mm:ss"); date.setTimeSpec(Qt::UTC); last = QString("%1").arg(date.toMSecsSinceEpoch()); list.append(QWebDAV::FileInfo(name,last,size.toLongLong(), available.toLongLong(),type)); } name = size = last = type = available = ""; response = response.nextSiblingElement(); } //for(int i = 0; i < list.size(); i++ ) { // list[i].print(); //} // Let whoever is listening know that we have their stuff ready! emit directoryListingReady(list); }