Permalink
Browse files

Initial commit

  • Loading branch information...
bmcdorman committed Jul 6, 2012
0 parents commit 9dc8e0ba73990c996e0cedf3622be3896467a3c9
@@ -0,0 +1,3 @@
+.DS_Store
+build
+deploy
@@ -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()
@@ -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
@@ -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
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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>
Binary file not shown.
@@ -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();
+}
Oops, something went wrong.

0 comments on commit 9dc8e0b

Please sign in to comment.