Skip to content

Latest commit

 

History

History
143 lines (117 loc) · 4.14 KB

declarativetransfermodel.h

File metadata and controls

143 lines (117 loc) · 4.14 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/****************************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: Marko Mattila <marko.mattila@jolla.com>
** All rights reserved.
**
** This file is part of Nemo Transfer Engine package.
**
** You may use this file under the terms of the GNU Lesser General
** Public License version 2.1 as published by the Free Software Foundation
** and appearing in the file license.lgpl included in the packaging
** of this file.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file license.lgpl included in the packaging
** of this file.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
****************************************************************************************/
#ifndef DECLARATIVETRANSFERMODEL_HH
#define DECLARATIVETRANSFERMODEL_HH
#include <QAbstractListModel>
#include <QJSValue>
#include <QMutex>
#include <QQmlParserStatus>
#include <QRunnable>
#include <QStringList>
#include <QWaitCondition>
#include <QSqlDatabase>
#include "transferengineinterface.h"
#include "transfertypes.h"
class TransferModel
: public QAbstractListModel
, public QQmlParserStatus
, private QRunnable
{
Q_OBJECT
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(int transfersInProgress READ transfersInProgress NOTIFY transfersInProgressChanged)
Q_ENUMS(Status)
Q_ENUMS(TransferStatus)
Q_ENUMS(TransferType)
Q_INTERFACES(QQmlParserStatus)
public:
enum Status {
Null,
Querying,
Finished,
Error
};
enum TransferStatus {
NotStarted = TransferEngineData::NotStarted,
TransferStarted = TransferEngineData::TransferStarted,
TransferCanceled = TransferEngineData::TransferCanceled,
TransferFinished = TransferEngineData::TransferFinished,
TransferInterrupted = TransferEngineData::TransferInterrupted
};
enum TransferType {
Upload = TransferEngineData::Upload,
Download = TransferEngineData::Download,
Sync = TransferEngineData::Sync
};
TransferModel(QObject *parent = 0);
~TransferModel();
Status status() const;
Q_INVOKABLE QJSValue get(int index) const;
Q_INVOKABLE void clearTransfers();
QHash<int, QByteArray> roleNames() const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QModelIndex index(int row, int column, const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
void classBegin();
void componentComplete();
void insertRange(int index, int count, const QVector<TransferDBRecord> &source, int sourceIndex);
void updateRange(int index, int count, const QVector<TransferDBRecord> &source, int sourceIndex);
void removeRange(int index, int count);
bool event(QEvent *event);
int transfersInProgress() const;
public slots:
void refresh();
signals:
void queryChanged();
void classNamesChanged();
void statusChanged();
void countChanged();
void transfersInProgressChanged();
private:
void run();
bool executeQuery(QVector<TransferDBRecord> *rows, int *activeTransfers, QString *errorString);
QSqlDatabase database();
QString m_asyncErrorString;
QVector<TransferDBRecord> m_asyncRows;
QVector<TransferDBRecord> *m_rows;
QHash<int, QByteArray> m_roles;
QMutex m_mutex;
QWaitCondition m_condition;
int m_rowsIndex;
int m_asyncIndex;
int m_asyncTransfersInProgress;
int m_transfersInProgress;
Status m_status;
Status m_asyncStatus;
bool m_asyncPending;
bool m_asyncRunning;
bool m_notified;
bool m_complete;
bool m_rowsChanges;
TransferEngineInterface *m_client;
};
#endif