Пример #1
0
/**
 * @brief Restores a note on the server
 */
void OwnCloudService::restoreTrashedNoteOnServer(QString notesPath,
                                                 QString fileName,
                                                 int timestamp,
                                                 MainWindow *mainWindow) {
    this->mainWindow = mainWindow;

    QUrl url(serverUrl + restoreTrashedNotePath);
    QString serverNotesPath = NoteFolder::currentRemotePath();

    url.setUserName(userName);
    url.setPassword(password);

    QUrlQuery q;
    q.addQueryItem("format", format);
    q.addQueryItem("file_name", serverNotesPath + fileName);
    q.addQueryItem("timestamp", QString::number(timestamp));
    url.setQuery(q);

    qDebug() << url;

    QNetworkRequest r(url);
    addAuthHeader(&r);

    QNetworkReply *reply = networkManager->get(r);
    ignoreSslErrorsIfAllowed(reply);
}
Пример #2
0
/**
 * @brief Restores a note on the server
 */
void OwnCloudService::restoreTrashedNoteOnServer(QString notesPath,
                                                 QString fileName,
                                                 int timestamp,
                                                 MainWindow *mainWindow) {
    this->mainWindow = mainWindow;

    QUrl url(serverUrl + restoreTrashedNotePath);
    QString serverNotesPath = getServerNotesPath(notesPath);

    url.setUserName(userName);
    url.setPassword(password);

    QUrlQuery q;
    q.addQueryItem("format", format);
    q.addQueryItem("file_name", serverNotesPath + fileName);
    q.addQueryItem("timestamp", QString::number(timestamp));
    url.setQuery(q);

    qDebug() << url;

    QNetworkRequest r(url);
    addAuthHeader(&r);

    QNetworkReply *reply = networkManager->get(r);
    QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply,
                     SLOT(ignoreSslErrors()));
}
Пример #3
0
/**
 * Gets the calendar list from the ownCloud server
 * for the settings dialog
 */
void OwnCloudService::settingsGetCalendarList(SettingsDialog *dialog) {
    settingsDialog = dialog;

    QUrl url(serverUrl + calendarPath);
    QNetworkRequest r(url);
    addAuthHeader(&r);

    // build the request body
    QString body = "<d:propfind xmlns:d=\"DAV:\" "
            "xmlns:cs=\"http://sabredav.org/ns\" xmlns:c=\"urn:ietf:params:xml:ns:caldav\"> \
            <d:prop> \
               <d:resourcetype /> \
               <d:displayname /> \
               <cs:getctag /> \
               <c:supported-calendar-component-set /> \
            </d:prop> \
          </d:propfind>";

    QByteArray *dataToSend = new QByteArray(body.toLatin1());
    r.setHeader(QNetworkRequest::ContentLengthHeader, dataToSend->size());
    QBuffer *buffer = new QBuffer(dataToSend);

    QNetworkReply *reply = networkManager->sendCustomRequest(r, "PROPFIND",
                                                             buffer);
    ignoreSslErrorsIfAllowed(reply);
}
Пример #4
0
/**
 * @brief Gets the todo list from the ownCloud server for the todo list dialog
 */
void OwnCloudService::todoGetTodoList(QString calendarName,
                                      TodoDialog *dialog) {
    this->todoDialog = dialog;
    this->calendarName = calendarName;

    QSettings settings;
    QStringList todoCalendarEnabledList = settings.value(
            "ownCloud/todoCalendarEnabledList").toStringList();
    int index = todoCalendarEnabledList.indexOf(calendarName);

    // return if we did't find the calendar, this should not happen
    if (index == -1) {
        return;
    }

    QStringList todoCalendarEnabledUrlList = settings.value(
            "ownCloud/todoCalendarEnabledUrlList").toStringList();

    // return if there are to few items in the url list
    if (todoCalendarEnabledUrlList.size() < todoCalendarEnabledList.size()) {
        return;
    }

    QString calendarUrl = settings.value(
            "ownCloud/todoCalendarEnabledUrlList").toStringList().at(index);

    QUrl url(calendarUrl);
    QNetworkRequest r(url);
    addAuthHeader(&r);

    // ownCloud needs depth to be set to 1
    r.setRawHeader(QByteArray("DEPTH"), QByteArray("1"));

    // build the request body, we only want VTODO items
    QString body = "<c:calendar-query xmlns:d=\"DAV:\" "
            "xmlns:c=\"urn:ietf:params:xml:ns:caldav\"> \
            <d:prop> \
                <d:getetag /> \
                <d:getlastmodified /> \
            </d:prop> \
            <c:filter> \
                <c:comp-filter name=\"VCALENDAR\"> \
                    <c:comp-filter name=\"VTODO\" /> \
                </c:comp-filter> \
            </c:filter> \
        </c:calendar-query>";

    QByteArray *dataToSend = new QByteArray(body.toLatin1());
    r.setHeader(QNetworkRequest::ContentLengthHeader, dataToSend->size());
    QBuffer *buffer = new QBuffer(dataToSend);

    QNetworkReply *reply = networkManager->sendCustomRequest(r, "REPORT",
                                                             buffer);
    QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply,
                     SLOT(ignoreSslErrors()));
}
Пример #5
0
void DigitallyImported::login()
{
    if (job) {
        job->deleteLater();
        job=0;
    }
    QNetworkRequest req(constAuthUrl);
    addAuthHeader(req);
    job=NetworkAccessManager::self()->postFormData(req, "username="******"&password="+QUrl::toPercentEncoding(password));
    connect(job, SIGNAL(finished()), SLOT(loginResponse()));
}
Пример #6
0
/**
 * @brief Removes a todo list item from the ownCloud server
 */
void OwnCloudService::removeCalendarItem(CalendarItem calItem,
                                         TodoDialog *dialog) {
    this->todoDialog = dialog;
    this->calendarName = calendarName;

    QUrl url(calItem.getUrl());
    QNetworkRequest r(url);
    addAuthHeader(&r);

    QNetworkReply *reply = networkManager->sendCustomRequest(r, "DELETE");
    ignoreSslErrorsIfAllowed(reply);
}
Пример #7
0
/**
 * @brief Removes a todo list item from the ownCloud server
 */
void OwnCloudService::removeCalendarItem(CalendarItem calItem,
                                         TodoDialog *dialog) {
    this->todoDialog = dialog;
    this->calendarName = calendarName;

    QUrl url(calItem.getUrl());
    QNetworkRequest r(url);
    addAuthHeader(&r);

    QNetworkReply *reply = networkManager->sendCustomRequest(r, "DELETE");
    QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply,
                     SLOT(ignoreSslErrors()));
}
Пример #8
0
/**
 * @brief Loads and updates the icsData of a calendar item with data from the calendar server
 * @return
 */
bool OwnCloudService::updateICSDataOfCalendarItem(CalendarItem *calItem) {
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);

    QUrl url(calItem->getUrl());
    QNetworkRequest r;

    addAuthHeader(&r);
    r.setUrl(url);

    QEventLoop loop;
    QTimer timer;

    timer.setSingleShot(true);
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    connect(manager, SIGNAL(finished(QNetworkReply *)), &loop, SLOT(quit()));

    // 5 sec timeout for the request
    timer.start(5000);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
    r.setAttribute(QNetworkRequest::FollowRedirectsAttribute,
                                true);
#endif

    QNetworkReply *reply = manager->get(r);
    ignoreSslErrorsIfAllowed(reply);

    loop.exec();

    if (timer.isActive()) {
        // get the text from the network reply
        QString icsData = reply->readAll();

        // set the new ics data
        calItem->setICSData(icsData);

        return true;
    }

    // timer elapsed, no reply from network request
    return false;
}
Пример #9
0
/**
 * @brief OwnCloudService::loadVersions
 */
void OwnCloudService::loadVersions(QString fileName, MainWindow *mainWindow) {
    this->mainWindow = mainWindow;

    QUrl url(serverUrl + versionListPath);
    QString serverNotesPath = NoteFolder::currentRemotePath();

    url.setUserName(userName);
    url.setPassword(password);

    QUrlQuery q;
    q.addQueryItem("format", format);
    q.addQueryItem("file_name", serverNotesPath + fileName);
    url.setQuery(q);

    QNetworkRequest r(url);
    addAuthHeader(&r);

    QNetworkReply *reply = networkManager->get(r);
    ignoreSslErrorsIfAllowed(reply);
}
Пример #10
0
void OwnCloudService::postCalendarItemToServer(CalendarItem calendarItem,
                                               TodoDialog *dialog) {
    this->todoDialog = dialog;

    calendarItem.generateNewICSData();

    QUrl url(calendarItem.getUrl());
    QNetworkRequest r;
    addAuthHeader(&r);
    r.setUrl(url);

    // build the request body
    QString body = calendarItem.getICSData();

    QByteArray *dataToSend = new QByteArray(body.toLatin1());
    r.setHeader(QNetworkRequest::ContentLengthHeader, dataToSend->size());
    QBuffer *buffer = new QBuffer(dataToSend);

    QNetworkReply *reply = networkManager->sendCustomRequest(r, "PUT", buffer);
    ignoreSslErrorsIfAllowed(reply);
}
Пример #11
0
/**
 * @brief OwnCloudService::loadVersions
 */
void OwnCloudService::loadVersions(QString notesPath, QString fileName,
                                   MainWindow *mainWindow) {
    this->mainWindow = mainWindow;

    QUrl url(serverUrl + versionListPath);
    QString serverNotesPath = getServerNotesPath(notesPath);

    url.setUserName(userName);
    url.setPassword(password);

    QUrlQuery q;
    q.addQueryItem("format", format);
    q.addQueryItem("file_name", serverNotesPath + fileName);
    url.setQuery(q);

    QNetworkRequest r(url);
    addAuthHeader(&r);

    QNetworkReply *reply = networkManager->get(r);
    QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply,
                     SLOT(ignoreSslErrors()));
}
Пример #12
0
/**
 * @brief OwnCloudService::connectionTest
 */
void OwnCloudService::settingsConnectionTest(SettingsDialog *dialog) {
    settingsDialog = dialog;

    // qDebug() << serverUrl;
    // qDebug() << userName;
    // qDebug() << password;

    QUrl url(serverUrl);
    QNetworkRequest r(url);

    // direct server url request without auth header
    QNetworkReply *reply = networkManager->get(r);
    ignoreSslErrorsIfAllowed(reply);

    QUrlQuery q;
    q.addQueryItem("format", format);
    url.setQuery(q);

    addAuthHeader(&r);

    url.setUrl(serverUrl + capabilitiesPath);
    r.setUrl(url);
    reply = networkManager->get(r);
    ignoreSslErrorsIfAllowed(reply);

    url.setUrl(serverUrl + ownCloudTestPath);
    r.setUrl(url);
    reply = networkManager->get(r);
    ignoreSslErrorsIfAllowed(reply);

    url.setUrl(serverUrl + appInfoPath);
    QString serverNotesPath = NoteFolder::currentRemotePath();
    q.addQueryItem("notes_path", serverNotesPath);
    url.setQuery(q);
    r.setUrl(url);
    reply = networkManager->get(r);
    ignoreSslErrorsIfAllowed(reply);
}
Пример #13
0
/**
 * Gets the file list from the ownCloud server
 * for the settings dialog
 */
void OwnCloudService::settingsGetFileList(
        SettingsDialog *dialog, QString path) {
    settingsDialog = dialog;

    QUrl url(serverUrl + webdavPath + "/" + path);
    QNetworkRequest r(url);
    addAuthHeader(&r);

    // build the request body
    QString body = "<?xml version=\"1.0\"?>"
            "<a:propfind xmlns:a=\"DAV:\">"
                "<a:prop><a:resourcetype />"
                "</a:prop>"
            "</a:propfind>";

    QByteArray *dataToSend = new QByteArray(body.toLatin1());
    r.setHeader(QNetworkRequest::ContentLengthHeader, dataToSend->size());
    QBuffer *buffer = new QBuffer(dataToSend);

    QNetworkReply *reply = networkManager->sendCustomRequest(
            r, "PROPFIND", buffer);
    ignoreSslErrorsIfAllowed(reply);
}
Пример #14
0
/**
 * @brief Loads and updates the icsData of a calendar item with data from the calendar server
 * @return
 */
bool OwnCloudService::updateICSDataOfCalendarItem(CalendarItem *calItem) {
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);

    QUrl url(calItem->getUrl());
    QNetworkRequest r;

    addAuthHeader(&r);
    r.setUrl(url);

    QEventLoop loop;
    QTimer timer;

    timer.setSingleShot(true);
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    connect(manager, SIGNAL(finished(QNetworkReply * )), &loop, SLOT(quit()));

    // 5 sec timeout for the request
    timer.start(5000);

    QNetworkReply *reply = manager->get(r);
    QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply,
                     SLOT(ignoreSslErrors()));
    loop.exec();

    if (timer.isActive()) {
        // get the text from the network reply
        QString icsData = reply->readAll();

        // set the new ics data
        calItem->setICSData(icsData);

        return true;
    }

    // timer elapsed, no reply from network request
    return false;
}
Пример #15
0
void OwnCloudClient::auth()
{
	m_username = SettingsManager::instance()->getUserName();
	m_password = SettingsManager::instance()->getUserPassword();

	QUrl url(SettingsManager::instance()->getOwnCloudHost());
	url.setPort(SettingsManager::instance()->getOwnCloudPort().toInt());

	QString path = SettingsManager::instance()->getOwnCloudPath() +
				   SettingsManager::instance()->getApiMusicCollection();
	url.setPath(path);

	url.setUserName(SettingsManager::instance()->getUserName());
	url.setPassword(SettingsManager::instance()->getUserPassword());

	qDebug() << url;

	QNetworkRequest request(url);
	addAuthHeader(&request);

	QNetworkReply* reply = m_networkManager.get(request);
	connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
			reply, SLOT(ignoreSslErrors()));
}
Пример #16
0
void OwnCloudService::loadTodoItems(QString &data) {
    QDomDocument doc;
    doc.setContent(data, true);

    // fetch all urls that are currently in the calendar
    QList<QUrl> calendarItemUrlRemoveList =
            CalendarItem::fetchAllUrlsByCalendar(calendarName);

    QDomNodeList responseNodes = doc.elementsByTagNameNS(NS_DAV, "response");
    int responseNodesCount = responseNodes.length();
    int requestCount = 0;

    // set the preliminary maximum of the progress bar
    this->todoDialog->todoItemLoadingProgressBarSetMaximum(responseNodesCount);

    // loop all response blocks
    for (int i = 0; i < responseNodesCount; ++i) {
        QDomNode responseNode = responseNodes.at(i);
        if (responseNode.isElement()) {
            QDomElement elem = responseNode.toElement();

            // check if we have an url
            QDomNodeList urlPartNodes = elem.elementsByTagNameNS(NS_DAV,
                                                                 "href");
            if (urlPartNodes.length()) {
                QString urlPart = urlPartNodes.at(0).toElement().text();

                if (urlPart == "") {
                    continue;
                }

                QUrl calendarItemUrl = QUrl(serverUrlWithoutPath + urlPart);

                // check if we have an etag
                QDomNodeList etagNodes = elem.elementsByTagNameNS(NS_DAV,
                                                                  "getetag");
                if (etagNodes.length()) {
                    QString etag = etagNodes.at(0).toElement().text();
                    etag.replace("\"", "");
                    qDebug() << __func__ << " - 'etag': " << etag;

                    // check if we have a last modified date
                    QDomNodeList lastModifiedNodes = elem.elementsByTagNameNS(
                            NS_DAV, "getlastmodified");
                    if (lastModifiedNodes.length()) {
                        const QString lastModified = lastModifiedNodes.at(
                                0).toElement().text();
                        bool fetchItem = false;

                        // try to fetch the calendar item by url
                        CalendarItem calItem = CalendarItem::fetchByUrl(
                                calendarItemUrl);
                        if (calItem.isFetched()) {
                            // check if calendar item was modified
                            if (calItem.getETag() != etag) {
                                // store etag and last modified date
                                calItem.setETag(etag);
                                calItem.setLastModifiedString(lastModified);
                                calItem.store();

                                // we want to update the item from server
                                fetchItem = true;
                            }
                        } else {
                            // calendar item was not found
                            // create calendar item for fetching
                            CalendarItem::addCalendarItemForRequest(
                                    calendarName, calendarItemUrl, etag,
                                    lastModified);
                            fetchItem = true;
                        }

                        // remove the url from the list of calendar item urls
                        // to remove
                        if (calendarItemUrlRemoveList.contains(
                                calendarItemUrl)) {
                            calendarItemUrlRemoveList.removeAll(
                                    calendarItemUrl);
                        }

                        // fetch the calendar item
                        if (fetchItem) {
                            QNetworkRequest r(calendarItemUrl);
                            addAuthHeader(&r);

                            QNetworkReply *reply = networkManager->get(r);
                            ignoreSslErrorsIfAllowed(reply);

                            requestCount++;
                        }
                    }
                }
            }
        }
    }

    // set the real maximum of the progress bar
    this->todoDialog->todoItemLoadingProgressBarSetMaximum(requestCount);

    // hide progress bar if there were no updates
    if (requestCount == 0) {
        this->todoDialog->todoItemLoadingProgressBarHide();
    }

    // remove all not found items
    for (int i = 0; i < calendarItemUrlRemoveList.length(); ++i) {
        QUrl url = calendarItemUrlRemoveList.at(i);
        CalendarItem calItem = CalendarItem::fetchByUrl(url);

        if (calItem.isFetched()) {
            calItem.remove();
        }
    }

    // reload the existing items
    this->todoDialog->reloadTodoListItems();

    qDebug() << CalendarItem::fetchAllByCalendar(calendarName);
}
Пример #17
0
/**
 * @brief OwnCloudService::connectionTest
 */
void OwnCloudService::settingsConnectionTest(SettingsDialog *dialog) {
    settingsDialog = dialog;

    // qDebug() << serverUrl;
    // qDebug() << userName;
    // qDebug() << password;

    QSettings settings;
    QString notesPath = settings.value("notesPath").toString();

    QUrl url(serverUrl);
    QNetworkRequest r(url);

    // direct server url request without auth header
    QNetworkReply *reply = networkManager->get(r);
    QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), reply,
                     SLOT(ignoreSslErrors()));

    QUrlQuery q;
    q.addQueryItem("format", format);
    url.setQuery(q);

    addAuthHeader(&r);

    url.setUrl(serverUrl + capabilitiesPath);
    r.setUrl(url);
    reply = networkManager->get(r);

    url.setUrl(serverUrl + ownCloudTestPath);
    r.setUrl(url);
    reply = networkManager->get(r);

    url.setUrl(serverUrl + appInfoPath);
    QString serverNotesPath = getServerNotesPath(notesPath);
    q.addQueryItem("notes_path", serverNotesPath);
    url.setQuery(q);
    r.setUrl(url);
    reply = networkManager->get(r);

    QString localOwnCloudPath = settings.value(
            "ownCloud/localOwnCloudPath").toString();

    if (localOwnCloudPath != "") {
        QDir d = QDir(localOwnCloudPath);
        if (d.exists()) {
            if (notesPath.startsWith(localOwnCloudPath)) {
                if (notesPath != localOwnCloudPath) {
                    settingsDialog->setOKLabelData(5, "ok", SettingsDialog::OK);
                } else {
                    settingsDialog->setOKLabelData(
                            5,
                            QString("note path and ownCloud path are equal")
                                    .arg(notesPath),
                            SettingsDialog::Warning);
                }
            }
            else {
                settingsDialog->setOKLabelData(5,
                                               QString("note path\n(%1)\nnot in ownCloud path").arg(
                                                       notesPath).arg(
                                                       localOwnCloudPath),
                                               SettingsDialog::Failure);
            }
        }
        else {
            settingsDialog->setOKLabelData(5, "does not exist",
                                           SettingsDialog::Failure);
        }
    }
    else {
        settingsDialog->setOKLabelData(5, "empty", SettingsDialog::Failure);
    }
}