~jamesh/storage-provider-webdav/error-on-list-file

« back to all changes in this revision

Viewing changes to src/DeleteHandler.cpp

  • Committer: Tarmac
  • Author(s): James Henstridge
  • Date: 2016-11-11 09:39:03 UTC
  • mfrom: (14.1.5 delete-item)
  • Revision ID: tarmac-20161111093903-b9wrr227fdtcbxlg
Implemente the delete_item D-Bus operation.

Approved by unity-api-1-bot, Michi Henning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "DeleteHandler.h"
 
2
 
 
3
#include <unity/storage/provider/Exceptions.h>
 
4
 
 
5
#include "DavProvider.h"
 
6
#include "item_id.h"
 
7
 
 
8
using namespace std;
 
9
using namespace unity::storage::provider;
 
10
 
 
11
DeleteHandler::DeleteHandler(DavProvider const& provider,
 
12
                             string const& item_id,
 
13
                             Context const& ctx)
 
14
    : provider_(provider), item_id_(item_id)
 
15
{
 
16
    QUrl const base_url = provider.base_url(ctx);
 
17
    QNetworkRequest request(id_to_url(item_id_, base_url));
 
18
    reply_.reset(provider.send_request(request, QByteArrayLiteral("DELETE"),
 
19
                                       nullptr, ctx));
 
20
    connect(reply_.get(), &QNetworkReply::finished,
 
21
            this, &DeleteHandler::onFinished);
 
22
}
 
23
 
 
24
DeleteHandler::~DeleteHandler() = default;
 
25
 
 
26
boost::future<void> DeleteHandler::get_future()
 
27
{
 
28
    return promise_.get_future();
 
29
}
 
30
 
 
31
void DeleteHandler::onFinished()
 
32
{
 
33
    auto status = reply_->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
 
34
 
 
35
    if (status / 100 == 2)
 
36
    {
 
37
        promise_.set_value();
 
38
    }
 
39
    else
 
40
    {
 
41
        promise_.set_exception(RemoteCommsException("Error from DELETE: " + to_string(status)));
 
42
    }
 
43
 
 
44
    deleteLater();
 
45
}