Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 9dc8e0ba73990c996e0cedf3622be3896467a3c9 0 parents
@bmcdorman bmcdorman authored
3  .gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+build
+deploy
67 CMakeLists.txt
@@ -0,0 +1,67 @@
+PROJECT(computer)
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
+
+FIND_PACKAGE(Qt4 REQUIRED)
+
+SET(INCLUDE ${computer_SOURCE_DIR}/include)
+SET(RC ${computer_SOURCE_DIR}/rc)
+SET(SRC ${computer_SOURCE_DIR}/src)
+SET(UI ${computer_SOURCE_DIR}/ui)
+
+INCLUDE_DIRECTORIES(${computer_BINARY_DIR})
+INCLUDE_DIRECTORIES(${INCLUDE})
+
+SET(QT_USE_QTNETWORK TRUE)
+
+INCLUDE(${QT_USE_FILE})
+
+FILE(GLOB INCLUDES ${INCLUDE}/*.h)
+FILE(GLOB SOURCES ${SRC}/*)
+FILE(GLOB UIS ${UI}/*)
+
+SET(computer_SRCS_CXX ${SOURCES})
+SET(computer_UI ${UIS})
+SET(computer_MOC_SRCS ${INCLUDES})
+
+SET(computer_QRC_FILES ${RC}/rc.qrc)
+
+QT4_WRAP_CPP(computer_SRCS_CXX ${computer_MOC_SRCS})
+QT4_WRAP_UI(computer_SRCS_CXX ${computer_UI})
+QT4_ADD_RESOURCES(computer_SRCS_CXX ${computer_QRC_FILES})
+
+SET(CMAKE_CXX_FLAGS "-Wall")
+
+IF(APPLE)
+ SET(CMAKE_OSX_SYSROOT "${OSX_DEVELOPER_ROOT}/SDKs/MacOSX10.6.sdk")
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch x86_64 -g")
+ LINK_DIRECTORIES(/Library/Frameworks/)
+ ADD_EXECUTABLE(computer MACOSX_BUNDLE ${computer_SRCS_CXX})
+ELSEIF(UNIX)
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
+ ADD_EXECUTABLE(computer ${computer_SRCS_CXX})
+ELSEIF(WIN32)
+ SET(CMAKE_CXX_FLAGS "-Wl,--enable-auto-import")
+ ADD_EXECUTABLE(computer WIN32 ${computer_SRCS_CXX} rc/logos/kiss.rc)
+ENDIF()
+
+SET(EXECUTABLE_OUTPUT_PATH ${computer_SOURCE_DIR}/deploy)
+SET(LIBRARY_OUTPUT_PATH ${computer_SOURCE_DIR}/lib)
+TARGET_LINK_LIBRARIES(computer ${QT_LIBRARIES} qscintilla2 kiss-compiler easydevice tinyarchive z)
+
+IF(APPLE)
+ ADD_CUSTOM_TARGET(computer_MacDeployQt ALL
+ COMMAND ${QT_BINARY_DIR}/macdeployqt ${computer_SOURCE_DIR}/deploy/computer.app -verbose=0
+ WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+ DEPENDS computer)
+
+# ADD_CUSTOM_TARGET(Info.plist ALL
+# COMMAND ${CMAKE_COMMAND} -E copy ${RC}/Info.plist ${computer_SOURCE_DIR}/deploy/computer.app/Contents
+# WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+# DEPENDS computer)
+#
+# ADD_CUSTOM_TARGET(Icons ALL
+# COMMAND ${CMAKE_COMMAND} -E copy ${RC}/logos/mac_icon.icns ${computer_SOURCE_DIR}/deploy/computer.app/Contents/Resources
+# WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+# DEPENDS computer Info.plist MacDeployQt)
+ENDIF()
37 include/ConsoleWidget.h
@@ -0,0 +1,37 @@
+#ifndef _CONSOLEWIDGET_H_
+#define _CONSOLEWIDGET_H_
+
+#include <QTextEdit>
+#include <QProcess>
+
+class ConsoleWidget : public QTextEdit
+{
+Q_OBJECT
+public:
+ ConsoleWidget(QWidget *parent = 0);
+ ~ConsoleWidget();
+
+ void setProcess(QProcess *process);
+ QProcess *process() const;
+
+protected:
+ void keyPressEvent(QKeyEvent * event);
+ void changeDir(const QString & dir);
+
+private slots:
+ void readStandardOut();
+ void readStandardErr();
+
+private:
+ void printPrompt();
+
+ int inputCharCount;
+ QTextCursor curCursorLoc;
+ QString cmdStr;
+ QStringList cmdHistory;
+ int histLocation;
+ QString tempCmd;
+ QProcess *m_process;
+};
+
+#endif
46 include/MainWindow.h
@@ -0,0 +1,46 @@
+#ifndef _MAINWINDOW_H_
+#define _MAINWINDOW_H_
+
+#include <QMainWindow>
+
+#include <easydevice/Server.h>
+#include <easydevice/DiscoveryClient.h>
+#include <easydevice/ServerDelegate.h>
+#include <easydevice/Filesystem.h>
+#include <kiss-compiler/Compilation.h>
+
+namespace Ui
+{
+ class MainWindow;
+}
+
+class QProcess;
+
+class MainWindow : public QMainWindow, public EasyDevice::ServerDelegate
+{
+Q_OBJECT
+public:
+ MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+ const bool run(const QString& name);
+ CompilationPtr compile(const QString& name);
+ const bool download(const QString& name, TinyArchive *archive);
+ EasyDevice::Filesystem *filesystem();
+
+private:
+ void killProcess();
+
+ EasyDevice::Server m_server;
+ EasyDevice::DiscoveryClient m_discovery;
+
+ EasyDevice::Filesystem m_filesystem;
+ QMap<QString, QStringList> m_compileResults;
+
+ QDir m_workingDirectory;
+
+ QProcess *m_process;
+ Ui::MainWindow *ui;
+};
+
+#endif
BIN  rc/disk.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  rc/folder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  rc/printer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 rc/rc.qrc
@@ -0,0 +1,8 @@
+<RCC>
+ <qresource prefix="/">
+ <file>disk.png</file>
+ <file>folder.png</file>
+ <file>printer.png</file>
+ <file>stop.png</file>
+ </qresource>
+</RCC>
BIN  rc/stop.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 src/ConsoleWidget.cpp
@@ -0,0 +1,157 @@
+#include "ConsoleWidget.h"
+
+#include <QApplication>
+#include <QKeyEvent>
+
+ConsoleWidget::ConsoleWidget(QWidget *parent)
+ : QTextEdit(parent), m_process(0)
+{
+ cmdStr = "";
+ curCursorLoc = this->textCursor();
+ inputCharCount = 0;
+ histLocation = -1;
+ tempCmd = "";
+ setProcess(0);
+}
+
+ConsoleWidget::~ConsoleWidget()
+{
+ setProcess(0);
+}
+
+void ConsoleWidget::setProcess(QProcess *process)
+{
+ if(m_process) m_process->disconnect(this);
+ m_process = process;
+ setReadOnly(!m_process);
+ if(!m_process) return;
+ clear();
+ m_process->setProcessChannelMode(QProcess::MergedChannels);
+ connect(m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandardOut()));
+ connect(m_process, SIGNAL(readyReadStandardError()), this, SLOT(readStandardErr()));
+}
+
+QProcess *ConsoleWidget::process() const
+{
+ return m_process;
+}
+
+void ConsoleWidget::readStandardOut()
+{
+ insertPlainText(m_process->readAllStandardOutput());
+ moveCursor(QTextCursor::End, QTextCursor::KeepAnchor);
+}
+
+void ConsoleWidget::readStandardErr()
+{
+ insertPlainText(m_process->readAllStandardError());
+ moveCursor(QTextCursor::End, QTextCursor::KeepAnchor);
+}
+
+void ConsoleWidget::changeDir(const QString & dir)
+{
+ QString theDir = QString(dir);
+ theDir = theDir.replace(QChar('/'), "\\");
+ m_process->write("cd ", 3);
+ m_process->write(theDir.toAscii().data(), theDir.length());
+ m_process->write("\r\n", 2);
+}
+
+void ConsoleWidget::keyPressEvent(QKeyEvent * event)
+{
+ int key = event->key();
+
+ setTextCursor(curCursorLoc);
+
+ if (key != Qt::Key_Backspace) {
+ if (key == Qt::Key_Return || key == Qt::Key_Enter) {
+ inputCharCount = 0;
+ } else if (key == Qt::Key_Up) {
+ if (cmdHistory.size()) {
+ if (histLocation == -1) {
+ histLocation = cmdHistory.size() - 1;
+ tempCmd = cmdStr;
+ } else if (histLocation == 0) {
+ QApplication::beep();
+ event->ignore();
+ return;
+ } else {
+ --histLocation;
+ }
+
+ for (int i = 0; i < inputCharCount; ++i) {
+ QTextEdit::keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier));
+ }
+
+ inputCharCount = cmdHistory.at(histLocation).length();
+ this->insertPlainText(cmdHistory.at(histLocation));
+ cmdStr = cmdHistory.at(histLocation);
+ }
+
+ event->ignore();
+ return;
+ } else if (key == Qt::Key_Down) {
+ QString str = "";
+ if (histLocation == -1) {
+ QApplication::beep();
+ event->ignore();
+ return;
+ } else if (histLocation == cmdHistory.size() - 1) {
+ histLocation = -1;
+ str = tempCmd;
+ } else {
+ ++histLocation;
+ str = cmdHistory.at(histLocation);
+ }
+
+ for (int i = 0; i < inputCharCount; ++i) {
+ QTextEdit::keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier));
+ }
+
+ inputCharCount = str.length();
+ this->insertPlainText(str);
+ cmdStr = str;
+ } else if (key == Qt::Key_Left) {
+ if (inputCharCount) {
+ --inputCharCount;
+ QTextEdit::keyPressEvent(event);
+ } else QApplication::beep();
+ } else if (key == Qt::Key_Right) {
+ QTextCursor cursor = this->textCursor();
+ if (cursor.movePosition(QTextCursor::Right)) {
+ ++inputCharCount;
+ this->setTextCursor(cursor);
+ } else QApplication::beep();
+ } else if (key == Qt::Key_Tab) {
+ } else {
+ QString text = event->text();
+ for (int i = 0; i < text.length(); ++i) {
+ if (text.at(i).isPrint()) ++inputCharCount;
+ }
+ QTextEdit::keyPressEvent(event);
+ }
+ } else {
+ if (inputCharCount) {
+ --inputCharCount;
+ QTextEdit::keyPressEvent(event);
+ cmdStr.remove(inputCharCount, 1);
+ } else QApplication::beep();
+ }
+
+ if (key == Qt::Key_Return || key == Qt::Key_Enter) {
+ moveCursor(QTextCursor::End);
+ m_process->write(cmdStr.toAscii().data(), cmdStr.length());
+ m_process->write("\r\n", 2);
+ QTextEdit::keyPressEvent(event);
+ cmdHistory.push_back(cmdStr);
+ histLocation = -1;
+ cmdStr = "";
+ tempCmd = "";
+ } else {
+ QString input = event->text();
+ for (int i = 0; i < input.length(); ++i) {
+ if (input.at(i).isPrint()) cmdStr.insert(inputCharCount - 1, input.at(i));
+ }
+ }
+ curCursorLoc = textCursor();
+}
107 src/MainWindow.cpp
@@ -0,0 +1,107 @@
+#include "MainWindow.h"
+#include "ui_MainWindow.h"
+
+#include <easydevice/DiscoveryConstants.h>
+
+#include <kiss-compiler/ArchiveWriter.h>
+#include <kiss-compiler/Temporary.h>
+#include <kiss-compiler/CompilerManager.h>
+
+using namespace EasyDevice;
+
+MainWindow::MainWindow(QWidget *parent)
+ : QMainWindow(parent),
+ m_server(this),
+ m_discovery(this),
+ m_process(0),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+
+ DeviceInfo deviceInfo;
+ deviceInfo.setDeviceType("computer");
+ deviceInfo.setDisplayName("beta's comp");
+ deviceInfo.setSerialNumber("N/A");
+
+ m_discovery.setDeviceInfo(deviceInfo);
+
+ if(!m_discovery.setup()) {
+ qDebug() << "Failed to setup ohaiyo listener";
+ }
+ if(!m_server.listen(QHostAddress::Any, 8075)) {
+ qDebug() << "Failed to listen";
+ }
+}
+
+MainWindow::~MainWindow()
+{
+ killProcess();
+ delete ui;
+}
+
+const bool MainWindow::run(const QString& name)
+{
+ if(!m_filesystem.program(name)) return false;
+
+ qDebug() << name << "has the following results avail for running:" << m_compileResults.value(name);
+ if(!m_compileResults.value(name).size()) {
+ compile(name);
+ }
+ if(!m_compileResults.value(name).size()) {
+ qCritical() << "Cannot run" << name << ". No results.";
+ return false;
+ }
+
+ killProcess();
+ m_process = new QProcess();
+ m_process->setWorkingDirectory(m_workingDirectory.path());
+ ui->console->setProcess(m_process);
+ m_process->start(m_compileResults.value(name)[0], QStringList());
+
+ return true;
+}
+
+CompilationPtr MainWindow::compile(const QString& name)
+{
+ TinyArchive *archive = m_filesystem.program(name);
+ if(!archive) return CompilationPtr();
+
+ ArchiveWriter writer(archive, Temporary::subdir(name));
+ QMap<QString, QString> settings;
+ QByteArray rawSettings = QTinyNode::data(archive->lookup("settings:"));
+ QDataStream stream(rawSettings);
+ stream >> settings;
+
+ CompilationPtr compilation(new Compilation(CompilerManager::ref().compilers(), name, writer.files(), settings, "kovan"));
+ bool success = compilation->start();
+ qDebug() << "Results:" << compilation->compileResults();
+
+ qDebug() << (success ? "Compile Succeeded" : "Compile Failed");
+
+ if(success) m_compileResults[name] = compilation->compileResults();
+ else m_compileResults.remove(name);
+
+ return compilation;
+}
+
+const bool MainWindow::download(const QString& name, TinyArchive *archive)
+{
+ m_filesystem.setProgram(name, archive);
+ m_compileResults.remove(name);
+ return true;
+}
+
+Filesystem *MainWindow::filesystem()
+{
+ return &m_filesystem;
+}
+
+void MainWindow::killProcess()
+{
+ if(!m_process) return;
+ m_process->kill();
+ m_process->waitForFinished();
+ ui->console->setProcess(0);
+ delete m_process;
+ m_process = 0;
+}
23 src/main.cpp
@@ -0,0 +1,23 @@
+#include "MainWindow.h"
+
+#include <QApplication>
+#include <kiss-compiler/CompilerPluginManager.h>
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+#ifdef Q_OS_MAC
+ QDir::setCurrent(QApplication::applicationDirPath() + "/../");
+#else
+ QDir::setCurrent(QApplication::applicationDirPath());
+#endif
+
+ CompilerPluginManager::ref().loadAll(); // Load all available compilers
+
+ MainWindow mainWindow;
+ mainWindow.show();
+ mainWindow.raise();
+
+ return app.exec();
+}
141 ui/MainWindow.ui
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>600</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Computer</string>
+ </property>
+ <widget class="QWidget" name="centralwidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="margin">
+ <number>12</number>
+ </property>
+ <item>
+ <widget class="ConsoleWidget" name="console"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menubar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>800</width>
+ <height>22</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile">
+ <property name="title">
+ <string>File</string>
+ </property>
+ </widget>
+ <widget class="QMenu" name="menuEdit">
+ <property name="title">
+ <string>Edit</string>
+ </property>
+ <addaction name="separator"/>
+ <addaction name="actionSettings"/>
+ </widget>
+ <widget class="QMenu" name="menuHelp">
+ <property name="title">
+ <string>Help</string>
+ </property>
+ </widget>
+ <addaction name="menuFile"/>
+ <addaction name="menuEdit"/>
+ <addaction name="menuHelp"/>
+ </widget>
+ <widget class="QStatusBar" name="statusbar"/>
+ <widget class="QToolBar" name="toolBar">
+ <property name="windowTitle">
+ <string>toolBar</string>
+ </property>
+ <property name="iconSize">
+ <size>
+ <width>16</width>
+ <height>16</height>
+ </size>
+ </property>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextBesideIcon</enum>
+ </property>
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionSave"/>
+ <addaction name="actionPrint"/>
+ <addaction name="separator"/>
+ <addaction name="actionStop"/>
+ <addaction name="actionOpenWorkingDirectory"/>
+ </widget>
+ <action name="actionSettings">
+ <property name="text">
+ <string>Settings</string>
+ </property>
+ <property name="menuRole">
+ <enum>QAction::PreferencesRole</enum>
+ </property>
+ </action>
+ <action name="actionStop">
+ <property name="icon">
+ <iconset resource="../rc/rc.qrc">
+ <normaloff>:/stop.png</normaloff>:/stop.png</iconset>
+ </property>
+ <property name="text">
+ <string>Stop</string>
+ </property>
+ </action>
+ <action name="actionOpenWorkingDirectory">
+ <property name="icon">
+ <iconset resource="../rc/rc.qrc">
+ <normaloff>:/folder.png</normaloff>:/folder.png</iconset>
+ </property>
+ <property name="text">
+ <string>Open Working Directory</string>
+ </property>
+ </action>
+ <action name="actionPrint">
+ <property name="icon">
+ <iconset resource="../rc/rc.qrc">
+ <normaloff>:/printer.png</normaloff>:/printer.png</iconset>
+ </property>
+ <property name="text">
+ <string>Print</string>
+ </property>
+ </action>
+ <action name="actionSave">
+ <property name="icon">
+ <iconset resource="../rc/rc.qrc">
+ <normaloff>:/disk.png</normaloff>:/disk.png</iconset>
+ </property>
+ <property name="text">
+ <string>Save Output</string>
+ </property>
+ </action>
+ </widget>
+ <customwidgets>
+ <customwidget>
+ <class>ConsoleWidget</class>
+ <extends>QTextEdit</extends>
+ <header>ConsoleWidget.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources>
+ <include location="../rc/rc.qrc"/>
+ </resources>
+ <connections/>
+</ui>
Please sign in to comment.
Something went wrong with that request. Please try again.