[Pkg-owncloud-commits] [owncloud-client] 239/332: SocketAPI: Added REGISTER_PATH and UNREGISTER_PATH

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Aug 14 21:07:05 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 8b93678e3d93fdcb92dc0e5d0dc15c6066bc5c54
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Jul 25 12:10:45 2014 +0200

    SocketAPI: Added REGISTER_PATH and UNREGISTER_PATH
    
    to inform the plugins about the top sync directories.
    
    Also cleaned the code a bit.
---
 src/mirall/socketapi.cpp | 61 +++++++++++++++++++++++++++++++++++++-----------
 src/mirall/socketapi.h   |  4 +++-
 2 files changed, 51 insertions(+), 14 deletions(-)

diff --git a/src/mirall/socketapi.cpp b/src/mirall/socketapi.cpp
index e34f86d..cbd796b 100644
--- a/src/mirall/socketapi.cpp
+++ b/src/mirall/socketapi.cpp
@@ -208,7 +208,7 @@ void SocketApi::slotNewConnection()
     _listeners.append(socket);
 
     foreach( QString alias, FolderMan::instance()->map().keys() ) {
-       slotUpdateFolderView(alias);
+       slotRegisterPath(alias);
     }
 }
 
@@ -243,17 +243,35 @@ void SocketApi::slotReadSocket()
     }
 }
 
-void SocketApi::slotUpdateFolderView(const QString& alias)
+void SocketApi::slotRegisterPath( const QString& alias )
 {
-    QString msg = QLatin1String("UPDATE_VIEW");
+    Folder *f = FolderMan::instance()->folder(alias);
+    if (f) {
+        broadcastMessage(QLatin1String("REGISTER_PATH"), f->path() );
+    }
+}
 
+void SocketApi::slotUnregisterPath( const QString& alias )
+{
     Folder *f = FolderMan::instance()->folder(alias);
     if (f) {
-        msg.append(QLatin1String(":"));
-        msg.append(QDir::toNativeSeparators(QDir::cleanPath(f->path())));
+        broadcastMessage(QLatin1String("UNREGISTER_PATH"), f->path() );
     }
+}
 
-    broadcastMessage(msg);
+void SocketApi::slotUpdateFolderView(const QString& alias)
+{
+    Folder *f = FolderMan::instance()->folder(alias);
+    if (f) {
+        // do only send UPDATE_VIEW for a couple of status
+        if( f->syncResult().status() == SyncResult::SyncPrepare ||
+                f->syncResult().status() == SyncResult::Success ||
+                f->syncResult().status() == SyncResult::Problem ||
+                f->syncResult().status() == SyncResult::Error   ||
+                f->syncResult().status() == SyncResult::SetupError ) {
+            broadcastMessage(QLatin1String("UPDATE_VIEW"), f->path() );
+        }
+    }
 }
 
 void SocketApi::slotJobCompleted(const QString &folder, const SyncFileItem &item)
@@ -269,8 +287,7 @@ void SocketApi::slotJobCompleted(const QString &folder, const SyncFileItem &item
         command = QLatin1String("ERROR");
     }
 
-    broadcastMessage(QLatin1String("BROADCAST:") + command + QLatin1Char(':')
-                     + QDir::toNativeSeparators(path));
+    broadcastMessage(QLatin1String("BROADCAST:"), path, command);
 }
 
 
@@ -279,14 +296,32 @@ void SocketApi::sendMessage(QTcpSocket *socket, const QString& message)
 {
     DEBUG << "Sending message: " << message;
     QString localMessage = message;
-    socket->write(localMessage.append("\n").toUtf8());
+    if( ! localMessage.endsWith(QLatin1Char('\n'))) {
+        localMessage.append(QLatin1Char('\n'));
+    }
+    qint64 sent = socket->write(localMessage.toUtf8());
+    if( sent != localMessage.toUtf8().length() ) {
+        qDebug() << "WARN: Could not send all data on socket for " << localMessage;
+    }
+
 }
 
-void SocketApi::broadcastMessage(const QString& message)
+void SocketApi::broadcastMessage( const QString& verb, const QString& path, const QString& status )
 {
-    DEBUG << "Broadcasting to" << _listeners.count() << "listeners: " << message;
-    foreach(QTcpSocket* current, _listeners) {
-        sendMessage(current, message);
+    QString msg(verb);
+
+    if( !status.isEmpty() ) {
+        msg.append(QLatin1Char(':'));
+        msg.append(status);
+    }
+    if( !path.isEmpty() ) {
+        msg.append(QLatin1Char(':'));
+        msg.append(QDir::toNativeSeparators(path));
+    }
+
+    DEBUG << "Broadcasting to" << _listeners.count() << "listeners: " << msg;
+    foreach(QTcpSocket *socket, _listeners) {
+        sendMessage(socket, msg);
     }
 }
 
diff --git a/src/mirall/socketapi.h b/src/mirall/socketapi.h
index 52a07c4..a365d1b 100644
--- a/src/mirall/socketapi.h
+++ b/src/mirall/socketapi.h
@@ -44,10 +44,12 @@ private slots:
     void onLostConnection();
     void slotReadSocket();
     void slotJobCompleted(const QString &, const SyncFileItem &);
+    void slotUnregisterPath( const QString& alias );
+    void slotRegisterPath( const QString& alias );
 
 private:
     void sendMessage(QTcpSocket* socket, const QString& message);
-    void broadcastMessage(const QString& message);
+    void broadcastMessage(const QString& verb, const QString &path, const QString &status = QString::null);
 
     Q_INVOKABLE void command_RETRIEVE_FOLDER_STATUS(const QString& argument, QTcpSocket* socket);
     Q_INVOKABLE void command_RETRIEVE_FILE_STATUS(const QString& argument, QTcpSocket* socket);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list