[Pkg-owncloud-commits] [owncloud-client] 190/332: SocketAPI: Use QTcpSocket all over, rather than QLocalSocket.

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Aug 14 21:06:58 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 bdb95982271532c7ab9991d93d5abe45a782e371
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Thu Jul 10 15:50:24 2014 +0200

    SocketAPI: Use QTcpSocket all over, rather than QLocalSocket.
---
 src/mirall/socketapi.cpp | 36 +++++++++++++++---------------------
 src/mirall/socketapi.h   | 17 +++++++++--------
 2 files changed, 24 insertions(+), 29 deletions(-)

diff --git a/src/mirall/socketapi.cpp b/src/mirall/socketapi.cpp
index f88b942..8a0b7c6 100644
--- a/src/mirall/socketapi.cpp
+++ b/src/mirall/socketapi.cpp
@@ -12,19 +12,18 @@
  * for more details.
  */
 
-#include "socketapi.h"
+#include "mirall/socketapi.h"
 
 #include "mirall/mirallconfigfile.h"
 #include "mirall/folderman.h"
 #include "mirall/folder.h"
 #include "mirall/utility.h"
 #include "mirall/theme.h"
-#include "syncjournalfilerecord.h"
+#include "mirall/syncjournalfilerecord.h"
+#include "mirall/syncfileitem.h"
 
 #include <QDebug>
 #include <QUrl>
-#include <QLocalSocket>
-#include <QLocalServer>
 #include <QMetaObject>
 #include <QStringList>
 #include <QScopedPointer>
@@ -171,13 +170,8 @@ SocketApi::SocketApi(QObject* parent, const QUrl& localFile)
     }
 
     // setup socket
-    _localServer = new QLocalServer(this);
-    QLocalServer::removeServer(socketPath);
-    if(!_localServer->listen(socketPath)) {
-        DEBUG << "can't start server" << socketPath;
-    } else {
-        DEBUG << "server started, listening at " << socketPath;
-    }
+    _localServer = new QTcpServer(this);
+    _localServer->listen( QHostAddress::LocalHost, 33001);
     connect(_localServer, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
 
     // folder watcher
@@ -193,7 +187,8 @@ SocketApi::~SocketApi()
 
 void SocketApi::slotNewConnection()
 {
-    QLocalSocket* socket = _localServer->nextPendingConnection();
+    QTcpSocket* socket = _localServer->nextPendingConnection();
+
     if( ! socket ) {
         return;
     }
@@ -209,14 +204,14 @@ void SocketApi::onLostConnection()
 {
     DEBUG << "Lost connection " << sender();
 
-    QLocalSocket* socket = qobject_cast< QLocalSocket* >(sender());
+    QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
     _listeners.removeAll(socket);
 }
 
 
 void SocketApi::slotReadSocket()
 {
-    QLocalSocket* socket = qobject_cast<QLocalSocket*>(sender());
+    QTcpSocket* socket = qobject_cast<QTcpSocket*>(sender());
     Q_ASSERT(socket);
 
     while(socket->canReadLine()) {
@@ -224,12 +219,12 @@ void SocketApi::slotReadSocket()
         QString command = line.split(":").first();
         QString function = QString(QLatin1String("command_")).append(command);
 
-        QString functionWithArguments = function + QLatin1String("(QString,QLocalSocket*)");
+        QString functionWithArguments = function + QLatin1String("(QString,QTcpSocket*)");
         int indexOfMethod = this->metaObject()->indexOfMethod(functionWithArguments.toAscii());
 
         QString argument = line.remove(0, command.length()+1).trimmed();
         if(indexOfMethod != -1) {
-            QMetaObject::invokeMethod(this, function.toAscii(), Q_ARG(QString, argument), Q_ARG(QLocalSocket*, socket));
+            QMetaObject::invokeMethod(this, function.toAscii(), Q_ARG(QString, argument), Q_ARG(QTcpSocket*, socket));
         } else {
             DEBUG << "The command is not supported by this version of the client:" << command << "with argument:" << argument;
         }
@@ -259,7 +254,7 @@ void SocketApi::slotJobCompleted(const QString &folder, const SyncFileItem &item
 
 
 
-void SocketApi::sendMessage(QLocalSocket* socket, const QString& message)
+void SocketApi::sendMessage(QTcpSocket *socket, const QString& message)
 {
     DEBUG << "Sending message: " << message;
     QString localMessage = message;
@@ -269,13 +264,12 @@ void SocketApi::sendMessage(QLocalSocket* socket, const QString& message)
 void SocketApi::broadcastMessage(const QString& message)
 {
     DEBUG << "Broadcasting to" << _listeners.count() << "listeners: " << message;
-    foreach(QLocalSocket* current, _listeners)
-    {
+    foreach(QTcpSocket* current, _listeners) {
         sendMessage(current, message);
     }
 }
 
-void SocketApi::command_RETRIEVE_FOLDER_STATUS(const QString& argument, QLocalSocket* socket)
+void SocketApi::command_RETRIEVE_FOLDER_STATUS(const QString& argument, QTcpSocket* socket)
 {
     // This command is the same as RETRIEVE_FILE_STATUS
 
@@ -283,7 +277,7 @@ void SocketApi::command_RETRIEVE_FOLDER_STATUS(const QString& argument, QLocalSo
     command_RETRIEVE_FILE_STATUS(argument, socket);
 }
 
-void SocketApi::command_RETRIEVE_FILE_STATUS(const QString& argument, QLocalSocket* socket)
+void SocketApi::command_RETRIEVE_FILE_STATUS(const QString& argument, QTcpSocket* socket)
 {
     if( !socket ) {
         qDebug() << "No valid socket object.";
diff --git a/src/mirall/socketapi.h b/src/mirall/socketapi.h
index 3e3f90f..6bf28bb 100644
--- a/src/mirall/socketapi.h
+++ b/src/mirall/socketapi.h
@@ -17,16 +17,17 @@
 #define SOCKETAPI_H
 
 #include <QWeakPointer>
+#include <QTcpSocket>
+#include <QTcpServer>
+
+#include "mirall/syncfileitem.h"
 
 class QUrl;
 class QLocalSocket;
-class QLocalServer;
 class QStringList;
 
 namespace Mirall {
 
-class SyncFileItem;
-
 class SocketApi : public QObject
 {
 Q_OBJECT
@@ -43,15 +44,15 @@ private slots:
     void slotJobCompleted(const QString &, const SyncFileItem &);
 
 private:
-    void sendMessage(QLocalSocket* socket, const QString& message);
+    void sendMessage(QTcpSocket* socket, const QString& message);
     void broadcastMessage(const QString& message);
 
-    Q_INVOKABLE void command_RETRIEVE_FOLDER_STATUS(const QString& argument, QLocalSocket* socket);
-    Q_INVOKABLE void command_RETRIEVE_FILE_STATUS(const QString& argument, QLocalSocket* socket);
+    Q_INVOKABLE void command_RETRIEVE_FOLDER_STATUS(const QString& argument, QTcpSocket* socket);
+    Q_INVOKABLE void command_RETRIEVE_FILE_STATUS(const QString& argument, QTcpSocket* socket);
 
 private:
-    QLocalServer* _localServer;
-    QList< QLocalSocket* > _listeners;
+    QTcpServer *_localServer;
+    QList<QTcpSocket*> _listeners;
 };
 
 }

-- 
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