Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# QtDropbox2
# QtDropbox2 - QML Implementation
A C++ Qt-based framework for accessing Dropbox using APIv2

## Fork Information (CMGeorge repo)
The role of this fork is to extend the library to QML

For more informations see [QMLDropBox](https://github.com/CMGeorge/QMLDropBox)

**Supported features:**
1. List directoryes
2. Rename File / Directory
3. Download file


## Summary
QtDropbox2 is a Qt-based framework for accessing the cloud storage service
[Dropbox](http://www.dropbox.com) using its new APIv2 protocols.
Expand Down
4 changes: 4 additions & 0 deletions qtdropbox2.pri
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
INCLUDEPATH += $$PWD/src

SOURCES += \
$$PWD/src/FoldersModel.cpp \
$$PWD/src/qdropbox2.cpp \
$$PWD/src/qdropbox2account.cpp \
$$PWD/src/qdropbox2file.cpp \
$$PWD/src/qdropbox2folder.cpp \
$$PWD/src/qdropbox2entityinfo.cpp \

HEADERS += \
$$PWD/src/FoldersModel.h \
$$PWD/src/qdropbox2global.h \
$$PWD/src/qdropbox2common.h \
$$PWD/src/qdropbox2.h \
Expand Down
2 changes: 1 addition & 1 deletion qtdropbox2.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TEMPLATE = lib
#CONFIG += dll

CONFIG += C++11
QT += network xml
QT += network xml qml quick
QT -= gui

TARGET = QtDropbox2
Expand Down
65 changes: 65 additions & 0 deletions src/FoldersModel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "FoldersModel.h"

FoldersModel::FoldersModel(QAbstractListModel *parent): QAbstractListModel(parent)
{

}

FoldersModel::~FoldersModel()
{

}

QVariant FoldersModel::data(const QModelIndex &index, int role) const
{
qDebug()<<" Data asked for "<<index.row()<<" and role "<<role<<"from "<<m_contentList.count();
// should be unreachable code
// return m_contentList.at(index.row();
if (index.row()<m_contentList.count()){
switch (role) {
case NameRole: return m_contentList.at(index.row())->filename();
case DirectoryRole: return m_contentList.at(index.row())->isDirectory();
case PathRole:return m_contentList.at(index.row())->path();
}
}
return QVariant();
}

int FoldersModel::rowCount(const QModelIndex &parent) const
{
return m_contentList.count();
}

int FoldersModel::count()
{
return m_contentList.count();
}

QDropbox2EntityInfo *FoldersModel::at(const int index)
{
return m_contentList.at(index);
}

QHash<int, QByteArray> FoldersModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[IdRole] = "fileId";
roles[NameRole] = "name";
roles[DirectoryRole] = "isDirectory";
roles[PathRole] = "path";
return roles;
}

void FoldersModel::append(QDropbox2EntityInfo *item)
{
beginInsertRows(QModelIndex(), count(),count());
m_contentList.append(item);
endInsertRows();
}

void FoldersModel::clear()
{
beginResetModel();
m_contentList.clear();
endResetModel();
}
41 changes: 41 additions & 0 deletions src/FoldersModel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef FOLDERSMODEL_H
#define FOLDERSMODEL_H

#include <QObject>
#include <QAbstractListModel>

#include "qdropbox2entityinfo.h"

class FoldersModel : public QAbstractListModel
{
Q_OBJECT

public:
enum FolderListRole {
IdRole = Qt::UserRole, // 256
NameRole,
DirectoryRole,
PathRole
};
//TODO: Change to no QDropbox2EntityInfo pointer as soon as a qml test exists
typedef QList<QDropbox2EntityInfo*> ContentsList;

public:
FoldersModel(QAbstractListModel *parent=nullptr);
~FoldersModel();
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const ;
int count();
QDropbox2EntityInfo *at(const int index);
QHash<int, QByteArray> roleNames() const;

void append(QDropbox2EntityInfo* item);
void clear();
private:
ContentsList m_contentList;
signals:

public slots:
};

#endif // FOLDERSMODEL_H
9 changes: 6 additions & 3 deletions src/qdropbox2.cpp
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "qdropbox2.h"
#include <QCoreApplication>

QDropbox2::QDropbox2(QObject *parent)
: QObject(parent),
Expand Down Expand Up @@ -108,7 +109,7 @@ void QDropbox2::slot_networkRequestFinished(QNetworkReply *reply)
qDebug() << "response: " << reply->bytesAvailable() << "bytes" << endl;
qDebug() << "status code: " << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString() << endl;
qDebug() << "== begin response ==" << endl << lastResponse << endl << "== end response ==" << endl;
qDebug() << "req#" << nr << " is of type " << requestMap[nr].type << endl;
// qDebug() << "req#" << nr << " is of type " << requestMap[nr].type << endl;
#endif

lastErrorCode = reply->error();
Expand Down Expand Up @@ -192,7 +193,7 @@ bool QDropbox2::createAPIv2Reqeust(QUrl request, QNetworkRequest& req, bool incl
QNetworkReply* QDropbox2::sendPOST(QNetworkRequest& rq, QByteArray postdata)
{
#ifdef QTDROPBOX_DEBUG
qDebug() << "sendPOST() host = " << host << endl;
// qDebug() << "sendPOST() host = " << host << endl;
#endif

return QNAM.post(rq, postdata);
Expand All @@ -201,7 +202,7 @@ QNetworkReply* QDropbox2::sendPOST(QNetworkRequest& rq, QByteArray postdata)
QNetworkReply* QDropbox2::sendGET(QNetworkRequest& rq)
{
#ifdef QTDROPBOX_DEBUG
qDebug() << "sendGET() host = " << host << endl;
// qDebug() << "sendGET() host = " << host << endl;
#endif

return QNAM.get(rq);
Expand Down Expand Up @@ -605,3 +606,5 @@ void QDropbox2::stopEventLoop()
#endif
eventLoop->exit();
}

Q_COREAPP_STARTUP_FUNCTION(registerQDropbox2Types);
24 changes: 23 additions & 1 deletion src/qdropbox2.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include "qdropbox2account.h"
#include "qdropbox2entityinfo.h"

#include "FoldersModel.h"

#include <QQmlEngine>

/*! The main entry point of QDropbox2, a heavily re-factored version of Daniel Eder's QtDropbox
to support the new Dropbox APIv2 interface.
*/
Expand Down Expand Up @@ -175,7 +179,7 @@ class QDROPBOXSHARED_EXPORT QDropbox2 : public QObject

\param t token string
*/
void setAccessToken(const QString& token);
Q_INVOKABLE void setAccessToken(const QString& token);

/*!
Returns the current access token in use.
Expand Down Expand Up @@ -372,3 +376,21 @@ private slots:
};

Q_DECLARE_METATYPE(QDropbox2::Error);

//Q_DECLARE_METATYPE(QDropbox2);
static void registerQDropbox2Types() {
// qmlRegisterSingletonType<DropBoxCPP>("QtDropBox2",
// 1,0,
// "DropBoxCPP",
// DropBoxCPP::registerComponent);
qmlRegisterType<QDropbox2>("QtDropBox2",
1,0,
"QDropbox2");
qmlRegisterType<FoldersModel>("QtDropBox2",
1,0,
"FoldersModel");
// qmlRegisterType<QDropbox2EntityInfo>("QtDropBox2",
// 1,0,
// "QDropbox2EntityInfo");
}

Empty file modified src/qdropbox2account.cpp
100644 → 100755
Empty file.
Empty file modified src/qdropbox2account.h
100644 → 100755
Empty file.
Empty file modified src/qdropbox2common.h
100644 → 100755
Empty file.
Empty file modified src/qdropbox2entity.h
100644 → 100755
Empty file.
Empty file modified src/qdropbox2entityinfo.cpp
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions src/qdropbox2entityinfo.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class QDROPBOXSHARED_EXPORT QDropbox2EntityInfo : public QObject
*/
QDropbox2EntityInfo& operator=(const QDropbox2EntityInfo& other);

public slots:
/*!
Raw Dropbox file identifier.
*/
Expand Down
Loading