[Pkg-owncloud-commits] [owncloud-client] 161/332: Socket API: Add test client
Sandro Knauß
hefee-guest at moszumanska.debian.org
Thu Aug 14 21:06:54 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 623dfc028678cbbfc1cefa69630fab8a2e7be870
Author: Daniel Molkentin <danimo at owncloud.com>
Date: Wed Jul 2 10:10:22 2014 +0200
Socket API: Add test client
---
CMakeLists.txt | 1 +
shell_integration/CMakeLists.txt | 1 +
shell_integration/testclient/CMakeLists.txt | 9 +++
shell_integration/testclient/main.cpp | 27 +++++++
shell_integration/testclient/socketclient.cpp | 22 ++++++
shell_integration/testclient/socketclient.h | 21 ++++++
shell_integration/testclient/window.cpp | 101 ++++++++++++++++++++++++++
shell_integration/testclient/window.h | 32 ++++++++
shell_integration/testclient/window.ui | 31 ++++++++
9 files changed, 245 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d373084..670759d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -140,6 +140,7 @@ set(TRANSLATIONS ${TRANS_FILES})
add_subdirectory(csync)
add_subdirectory(src)
+add_subdirectory(shell_integration)
add_subdirectory(doc)
if(UNIT_TESTING)
diff --git a/shell_integration/CMakeLists.txt b/shell_integration/CMakeLists.txt
new file mode 100644
index 0000000..8f561fb
--- /dev/null
+++ b/shell_integration/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(testclient)
diff --git a/shell_integration/testclient/CMakeLists.txt b/shell_integration/testclient/CMakeLists.txt
new file mode 100644
index 0000000..0b171ef
--- /dev/null
+++ b/shell_integration/testclient/CMakeLists.txt
@@ -0,0 +1,9 @@
+cmake_minimum_required(VERSION 2.6)
+project(testclient)
+set(testclient_SOURCES main.cpp window.cpp)
+set(testclient_HEADERS window.h)
+qt_wrap_ui(testclient_UI_SRCS window.ui)
+add_executable(testclient ${testclient_SOURCES} ${testclient_HEADERS} ${testclient_UI_SRCS})
+target_link_libraries(testclient ${QT_LIBRARIES})
+set_target_properties(testclient PROPERTIES AUTOMOC TRUE)
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
diff --git a/shell_integration/testclient/main.cpp b/shell_integration/testclient/main.cpp
new file mode 100644
index 0000000..901767d
--- /dev/null
+++ b/shell_integration/testclient/main.cpp
@@ -0,0 +1,27 @@
+#include <QApplication>
+#include <QLocalSocket>
+#include <QDir>
+
+#include "window.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+ QLocalSocket sock;
+ QString sockAddr;
+#ifdef Q_OS_UNIX
+ sockAddr = QDir::homePath() + QLatin1String("/.local/share/data/ownCloud/socket");
+#else
+ sockAddr = QLatin1String("\\\\.\\pipe\\ownCloud");
+#endif
+ Window win(&sock);
+ QObject::connect(&sock, SIGNAL(readyRead()), &win, SLOT(receive()));
+ QObject::connect(&sock, SIGNAL(error(QLocalSocket::LocalSocketError)),
+ &win, SLOT(receiveError(QLocalSocket::LocalSocketError)));
+
+ win.show();
+ sock.connectToServer(sockAddr, QIODevice::ReadWrite);
+ qDebug() << "Connecting to" << sockAddr;
+
+ return app.exec();
+}
diff --git a/shell_integration/testclient/socketclient.cpp b/shell_integration/testclient/socketclient.cpp
new file mode 100644
index 0000000..dbe8bdf
--- /dev/null
+++ b/shell_integration/testclient/socketclient.cpp
@@ -0,0 +1,22 @@
+
+#include "socketclient.h"
+
+SocketClient::SocketClient(QObject *parent) :
+ QObject(parent)
+ , sock(new QLocalSocket(this))
+{
+ QString sockAddr;
+#ifdef Q_OS_UNIX
+ sockAddr = QDir::homePath() + QLatin1String("/.local/share/data/ownCloud/");
+#else
+ sockAddr = QLatin1String("\\\\.\\pipe\\ownCloud");
+#endif
+ sock->connectToServer(sockAddr);
+ sock->open(QIODevice::ReadWrite);
+ connect(sock, SIGNAL(readyRead()), SLOT(writeData()));
+}
+
+void SocketClient::writeData()
+{
+ qDebug() << sock->readAll();
+}
diff --git a/shell_integration/testclient/socketclient.h b/shell_integration/testclient/socketclient.h
new file mode 100644
index 0000000..59bb088
--- /dev/null
+++ b/shell_integration/testclient/socketclient.h
@@ -0,0 +1,21 @@
+#ifndef SOCKETCLIENT_H
+#define SOCKETCLIENT_H
+
+#include <QObject>
+
+class QLocalSocket;
+
+class SocketClient : public QObject
+{
+ Q_OBJECT
+public:
+ explicit SocketClient(QObject *parent = 0);
+
+public slots:
+ void writeData();
+
+private:
+ QLocalSocket *sock;
+};
+
+#endif // SOCKETCLIENT_H
diff --git a/shell_integration/testclient/window.cpp b/shell_integration/testclient/window.cpp
new file mode 100644
index 0000000..a3f185b
--- /dev/null
+++ b/shell_integration/testclient/window.cpp
@@ -0,0 +1,101 @@
+#include "window.h"
+#include "ui_window.h"
+
+#include <QLineEdit>
+#include <QSyntaxHighlighter>
+
+class LogWindowHighlighter : public QSyntaxHighlighter
+{
+public:
+ LogWindowHighlighter(QTextDocument *parent = 0);
+
+protected:
+ void highlightBlock(const QString &text);
+ void highlightHelper(const QString& text, const QTextCharFormat &format, const QString &exp);
+};
+
+Window::Window(QIODevice *dev, QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::Window)
+ , device(dev)
+{
+ ui->setupUi(this);
+ connect(ui->inputEdit->lineEdit(), SIGNAL(returnPressed()), SLOT(handleReturn()));
+ addDefaultItems();
+ QFont f("Courier");
+ f.setStyleHint(QFont::Monospace);
+ ui->outputs->setFont(f);
+ new LogWindowHighlighter(ui->outputs->document());
+}
+
+Window::~Window()
+{
+ delete ui;
+}
+
+void Window::receive()
+{
+ QByteArray ba = device->readAll();
+ ui->outputs->insertPlainText(QString::fromLatin1(ba));
+}
+
+void Window::receiveError(QLocalSocket::LocalSocketError error)
+{
+ qDebug() << "Error connecting to socket:" << error;
+}
+
+void Window::handleReturn()
+{
+ QString cmd = ui->inputEdit->currentText()+QLatin1Char('\n');
+ ui->outputs->insertPlainText(cmd);
+ device->write(cmd.toLatin1());
+ ui->inputEdit->lineEdit()->clear();
+}
+
+void Window::addDefaultItems()
+{
+ QStringList commands;
+ commands << "RETRIEVE_FOLDER_STATUS:" << "RETRIEVE_FILE_STATUS:";
+ ui->inputEdit->addItems(commands);
+}
+
+
+LogWindowHighlighter::LogWindowHighlighter(QTextDocument *parent)
+ : QSyntaxHighlighter(parent)
+{
+
+}
+
+void LogWindowHighlighter::highlightBlock(const QString &text)
+{
+ QTextCharFormat responseKeywordFormat;
+ responseKeywordFormat.setFontWeight(QFont::Bold);
+ responseKeywordFormat.setForeground(Qt::darkMagenta);
+ QString responsePattern = "(UPDATE_VIEW|BROADCAST:|STATUS:)";
+ highlightHelper(text, responseKeywordFormat, responsePattern);
+
+ QTextCharFormat messageKeywordFormat;
+ messageKeywordFormat.setFontWeight(QFont::Bold);
+ messageKeywordFormat.setForeground(Qt::darkYellow);
+ QString messagePattern = "(RETRIEVE_(FOLDER|FILE)_STATUS):";
+ highlightHelper(text, messageKeywordFormat, messagePattern);
+}
+
+void LogWindowHighlighter::highlightHelper(const QString& text, const QTextCharFormat &format,
+ const QString &pattern)
+{
+ QRegExp rex(pattern);
+ int index = text.indexOf(rex);
+ if (index >= 0) {
+ int len = rex.matchedLength();
+ setFormat(index, len, format);
+ int lastMatchedEnd=index+len;
+ int secondDoubleDotIndex = text.indexOf(':', lastMatchedEnd);
+ if (secondDoubleDotIndex >= 0) {
+ QTextCharFormat boldFormat;
+ boldFormat.setFontWeight(QFont::Bold);
+ setFormat(lastMatchedEnd, secondDoubleDotIndex-lastMatchedEnd, boldFormat);
+ }
+ }
+
+}
diff --git a/shell_integration/testclient/window.h b/shell_integration/testclient/window.h
new file mode 100644
index 0000000..ec37d21
--- /dev/null
+++ b/shell_integration/testclient/window.h
@@ -0,0 +1,32 @@
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+#include <QLocalSocket>
+
+namespace Ui {
+class Window;
+}
+
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit Window(QIODevice *dev, QWidget *parent = 0);
+ ~Window();
+
+public slots:
+ void receive();
+ void receiveError(QLocalSocket::LocalSocketError);
+
+private slots:
+ void handleReturn();
+
+private:
+ void addDefaultItems();
+ Ui::Window *ui;
+ QIODevice *device;
+};
+
+#endif // WINDOW_H
diff --git a/shell_integration/testclient/window.ui b/shell_integration/testclient/window.ui
new file mode 100644
index 0000000..82ce2a9
--- /dev/null
+++ b/shell_integration/testclient/window.ui
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Window</class>
+ <widget class="QWidget" name="Window">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>SocketAPI Test Client</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QComboBox" name="inputEdit">
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPlainTextEdit" name="outputs"/>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
--
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