1
#ifndef DROPBOXCLIENT_H
2
#define DROPBOXCLIENT_H
5
#include <QLocalSocket>
10
#include <QStringList>
13
#include "notification.h"
14
#include "configuration.h"
15
#include "configurationdbdriver.h"
17
class SynchronousDropboxConnection;
19
enum DropboxStatus {DropboxUnkown, DropboxIdle, DropboxBussy, DropboxError, DropboxUploading, DropboxDownloading,
20
DropboxSaving, DropboxIndexing, DropboxStopped, DropboxDisconnected};
21
class DropboxClient : public QObject
24
Q_ENUMS(DropboxStatus)
26
explicit DropboxClient(QObject* parent = 0);
29
void updateSharedFolders(const QString& to);
30
QStringList getSharedFolders();
32
//! This functions not strongly related to this class..
34
void hideGtkUi(bool hide);
35
bool static isInstalled();
38
inline QString getAuthUrl() const {return m_authUrl;}
39
QStringList getRecentlyChangedFiles();
46
QString m_dropboxDir; // from kfilebox config
47
DropboxStatus prev_status;
48
QStringList recently_changed;
50
SynchronousDropboxConnection* dc;
51
ConfigurationDBDriver* dropbox_db;
53
QString fixUnicodeChars(const QString &value);
54
QString resolveFileName(const QString& filename);
55
void updateRecentlyChangedFiles();
61
QString sendCommand(const QString& command);
63
QString getPublicLink(const QString& file) {
64
return sendCommand(QString("get_public_link\npath\t%1").arg(file)).remove("link\t");
67
QString getFolderTag(const QString& command) {
68
return sendCommand(QString("get_folder_tag\npath\t%1").arg(command)).remove("tag\t");
71
DropboxStatus getStatus() const {return prev_status;}
73
QString getStatusMessage() const {return m_message;}
76
void readDaemonOutput();
77
void getDropboxStatus();
80
void updateStatus(DropboxStatus status, const QString& message);
81
void newFileAdded(const QString filename);
85
class SynchronousDropboxConnection : public QObject
89
explicit SynchronousDropboxConnection(QObject* parent = 0) :
91
m_socket(new QLocalSocket(this))
93
m_socketpath = QDir::toNativeSeparators(QDir::homePath().append("/.dropbox/command_socket"));
94
m_socket->connectToServer(m_socketpath);
96
virtual ~SynchronousDropboxConnection() {}
99
QString sendCommand(const QString& command)
103
if(!m_socket->isOpen())
105
m_socket->connectToServer(m_socketpath);
106
if(!m_socket->waitForConnected(waitTime))
110
m_socket->write(command.toUtf8());
111
m_socket->write(QString("\ndone\n").toUtf8());
117
if(!m_socket->waitForReadyRead(waitTime))
119
//If we have to wait this long, the m_socket probably isn't open anymore (dropbox died or closed)
124
reply.append(m_socket->readAll());
126
if(reply.endsWith("done\n")) break;
129
//! @todo if(reply.stripTONotEmptyStrings().count()==3) {reply.stripped().remove(1) AND remove(3)}
130
//Strip out \ndone\n and ok\n
131
reply = reply.remove("\ndone\n");
132
reply = reply.remove("notok\n");
133
reply = reply.remove("ok\n");
135
if (reply == "status")
137
else if (reply.startsWith("status"))
138
reply = reply.mid(7);
144
QLocalSocket* m_socket;
145
QString m_socketpath;
149
#endif //DROPBOXCLIENT_H