Skip to content
Browse files

Work

  • Loading branch information...
1 parent cdf083a commit e69323ab82e69c7aa883b621e7aebe958ef37b5f @bmcdorman bmcdorman committed
View
8 include/Kiss.h
@@ -42,10 +42,10 @@
#define OS_LIB_EXT "so"
#endif
-#define KISS_C_VERSION_MAJOR 4
-#define KISS_C_VERSION_MINOR 0
-#define KISS_C_VERSION_BUILD 0
+#define KISS_IDE_VERSION_MAJOR 4
+#define KISS_IDE_VERSION_MINOR 0
+#define KISS_IDE_VERSION_BUILD 0
-#define KISS_C_VERSION_CODENAME "Oxygen"
+#define KISS_IDE_VERSION_CODENAME "Oxygen"
#endif
View
4 include/PluginManager.h
@@ -79,7 +79,7 @@ class PluginManager : public Singleton<M>
const QString& pluginPathString = pluginPath.absoluteFilePath("lib" + name + "." + OS_LIB_EXT);
- qWarning() << "Path:" << pluginPathString;
+ qDebug() << "\tPath:" << pluginPathString;
plugin->setFileName(pluginPathString);
if(!plugin->load()) {
@@ -98,8 +98,6 @@ class PluginManager : public Singleton<M>
}
m_plugins[name] = plugin;
-
- qWarning() << "Calling pluginLoaded";
pluginLoaded(instance);
return true;
}
View
19 include/TemplateManager.h
@@ -23,20 +23,27 @@
#include <QString>
#include <QIcon>
+#include <QMap>
+#include <tinyarchive.hpp>
#include "Kiss.h"
#include "Singleton.h"
+#define KISS_TEMPLATE_PACK_EXT "ktp"
+#define KISS_TEMPLATE_PACK_FILTER ("KISS Template Pack (*." KISS_TEMPLATE_PACK_EXT ")")
+
class TemplateManager : public Singleton<TemplateManager>
{
public:
+ TemplateManager();
+ ~TemplateManager();
+
QStringList types() const;
QStringList templateFolders(const QString& type, const QString& _template);
QStringList templates(const QString& type, const QString& _template);
QIcon templateIcon(const QString& type, const QString& _template);
-
bool addUserTemplate(const QString& type, const QString& name, const QString& content);
bool deleteUserTemplate(const QString& type, const QString& name);
@@ -44,15 +51,25 @@ class TemplateManager : public Singleton<TemplateManager>
QStringList userTemplates(const QString& type);
QString pathForUserTemplate(const QString& type, const QString& _template);
+ QStringList packs() const;
+ QStringList packTemplates(const QString& pack) const;
+ QIcon packTemplateIcon(const QString& pack, const QString& _template) const;
+ QByteArray packTemplateData(const QString& pack, const QString& _template) const;
+ bool installPack(const QString& name, const TinyArchive *archive);
+
QString pathForTemplate(const QString& type, const QString& _template);
bool isTemplateDirectory(const QString& type, const QString& _template);
bool isTemplateDirectory(const QString& path);
static const QString& defaultTemplateName();
+
private:
void ensureUserTemplateDirExists(const QString& type);
+ QString packPath() const;
+
+ QMap<QString, TinyArchive *> m_packs;
static QString m_defaultName;
};
View
20 include/dialogs/TargetDialog.h
@@ -1,3 +1,23 @@
+/**************************************************************************
+ * Copyright 2007-2012 KISS Institute for Practical Robotics *
+ * *
+ * This file is part of KISS (Kipr's Instructional Software System). *
+ * *
+ * KISS is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * KISS is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with KISS. Check the LICENSE file in the project root. *
+ * If not, see <http://www.gnu.org/licenses/>. *
+ **************************************************************************/
+
#ifndef _TARGETDIALOG_H_
#define _TARGETDIALOG_H_
View
7 include/dialogs/TemplateDialog.h
@@ -1,5 +1,5 @@
/**************************************************************************
- * Copyright 2007-2011 KISS Institute for Practical Robotics *
+ * Copyright 2007-2012 KISS Institute for Practical Robotics *
* *
* This file is part of KISS (Kipr's Instructional Software System). *
* *
@@ -36,7 +36,8 @@ class TemplateDialog : public QDialog, private Ui::TemplateDialog
// Returns to the path of the target file for the selected target
QString selectedTypeName() const;
- QString templateFile();
+ QString templateFile() const;
+ QByteArray templateData() const;
private slots:
void on_ui_types_currentItemChanged(QListWidgetItem* current, QListWidgetItem* prev);
@@ -44,10 +45,12 @@ private slots:
void on_ui_templates_currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem*);
void on_ui_remove_clicked();
+ void on_ui_install_clicked();
private:
void addTemplates(const QString& target, QTreeWidgetItem* parentItem, const QString& parent);
void addUserTemplates(const QString& target);
+ void addPackTemplates(const QString& pack);
};
#endif
View
20 include/dialogs/ThemeSettingsDialog.h
@@ -1,3 +1,23 @@
+/**************************************************************************
+ * Copyright 2007-2012 KISS Institute for Practical Robotics *
+ * *
+ * This file is part of KISS (Kipr's Instructional Software System). *
+ * *
+ * KISS is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * KISS is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with KISS. Check the LICENSE file in the project root. *
+ * If not, see <http://www.gnu.org/licenses/>. *
+ **************************************************************************/
+
#ifndef _THEMESETTINGSDIALOG_H_
#define _THEMESETTINGSDIALOG_H_
View
5 src/DocumentationManager.cpp
@@ -8,7 +8,10 @@
DocumentationLocation::DocumentationLocation(const QString& name, const QString& location,
const QString& description, const QString& decoration)
- : m_name(name), m_location(location), m_description(description), m_decoration(decoration)
+ : m_name(name),
+ m_location(location),
+ m_description(description),
+ m_decoration(decoration)
{
}
View
10 src/KissStandardEnvironment.cpp
@@ -39,11 +39,11 @@ void KissStandardEnvironment::createStandardEnvironment()
qInstallMsgHandler(debugLogHandler);
// Setup QApplication
- #ifdef Q_OS_MAC
- QDir::setCurrent(QApplication::applicationDirPath() + "/../");
- #else
- QDir::setCurrent(QApplication::applicationDirPath());
- #endif
+#ifdef Q_OS_MAC
+ QDir::setCurrent(QApplication::applicationDirPath() + "/../");
+#else
+ QDir::setCurrent(QApplication::applicationDirPath());
+#endif
qRegisterMetaType<TargetPtr>("TargetPtr");
View
8 src/MainWindow.cpp
@@ -470,10 +470,10 @@ bool MainWindow::closeNode(const TinyNode* node)
void MainWindow::about()
{
MessageDialog::showMessage(this, "About KISS IDE", "about_kiss", QStringList()
- << QString::number(KISS_C_VERSION_MAJOR)
- << QString::number(KISS_C_VERSION_MINOR)
- << QString::number(KISS_C_VERSION_BUILD)
- << KISS_C_VERSION_CODENAME);
+ << QString::number(KISS_IDE_VERSION_MAJOR)
+ << QString::number(KISS_IDE_VERSION_MINOR)
+ << QString::number(KISS_IDE_VERSION_BUILD)
+ << KISS_IDE_VERSION_CODENAME);
}
void MainWindow::settings()
View
25 src/SourceFile.cpp
@@ -50,6 +50,7 @@
#include <Qsci/qscilexercpp.h>
#include <QFile>
+#include <QBuffer>
#include <QTextStream>
#include <QFileDialog>
#include <QMessageBox>
@@ -914,38 +915,30 @@ void SourceFile::updateErrors(const CompileResult& compileResult)
const bool SourceFile::selectTemplate()
{
- QString targetPath;
- QString templateFile;
-
TemplateDialog tDialog(this);
if(tDialog.exec() == QDialog::Rejected) return false;
- templateFile = tDialog.templateFile();
-
+
+ QByteArray templateData = tDialog.templateData();
Lexer::Constructor* constructor = 0;
- QFile tFile(templateFile);
- if(!tFile.open(QIODevice::ReadOnly)) {
- MessageDialog::showError(this, "simple_error_with_action", QStringList() <<
- tr("Error loading template file ") + templateFile <<
- tr("Unable to open file for reading.") <<
- tr("Continuing without selected template."));
- return true;
- }
- QTextStream stream(&tFile);
+ QBuffer buffer(&templateData);
+ buffer.open(QIODevice::ReadOnly);
+ QTextStream stream(&buffer);
TemplateFormatReader templateReader(&stream);
if(templateReader.hasLexerName()) {
QString lex = templateReader.lexerName();
- Log::ref().debug(QString("Template Lexer specified: %1").arg(lex));
+ qDebug() << "Template Lexer specified:" << lex;
constructor = Lexer::Factory::ref().constructor(lex);
m_templateExt = lex;
}
ui_editor->setText(templateReader.content());
- tFile.close();
Log::ref().info("Template selected");
+ buffer.close();
+
// m_lexAPI = QString(targetPath).replace(QString(".") + TARGET_EXT, ".api");
if(constructor) setLexer(constructor);
View
99 src/TemplateManager.cpp
@@ -24,11 +24,45 @@
#include <QFile>
#include <QTextStream>
#include <QDebug>
+#include <kiss-compiler/QTinyArchiveStream.h>
#define TEMPLATE_EXT_WILDCARD (QString("*.") + TEMPLATE_EXT)
QString TemplateManager::m_defaultName = "Default";
+TemplateManager::TemplateManager()
+{
+ qDebug() << "Scanning" << packPath() << "for packs.";
+ QFileInfoList entries = QDir(packPath()).entryInfoList(QStringList() << ("*." KISS_TEMPLATE_PACK_EXT), QDir::NoDot | QDir::NoDotDot | QDir::Files);
+ foreach(const QFileInfo& entry, entries) {
+ qDebug() << "Reading" << entry.canonicalFilePath();
+ QFile file(entry.canonicalFilePath());
+ if(!file.open(QIODevice::ReadOnly)) {
+ qWarning() << "Template pack" << entry.completeBaseName() << "cannot be opened. Ignoring.";
+ continue;
+ }
+
+ QTinyArchiveStream in(&file);
+ TinyArchive *archive = TinyArchive::read(&in);
+ file.close();
+
+ if(!archive) {
+ qWarning() << "Template pack" << entry.completeBaseName() << "is malformed. Ignoring.";
+ continue;
+ }
+ // Assuming this is null terminated
+ m_packs[entry.completeBaseName()] = archive;
+ }
+}
+
+TemplateManager::~TemplateManager()
+{
+ QList<TinyArchive *>::iterator it = m_packs.values().begin();
+ for(; it != m_packs.values().end(); ++it) {
+ delete *it;
+ }
+}
+
QStringList TemplateManager::types() const
{
QDir typeDir(QDir::currentPath() + "/" + TEMPLATES_FOLDER);
@@ -108,9 +142,67 @@ QString TemplateManager::pathForUserTemplate(const QString& type, const QString&
return QDir::currentPath() + "/" + USER_FOLDER + "/" + TEMPLATES_FOLDER + "/" + type + (_template.isEmpty() ? "" : "/" + _template);
}
+QStringList TemplateManager::packs() const
+{
+ return QStringList(m_packs.keys());
+}
+
+QStringList TemplateManager::packTemplates(const QString& pack) const
+{
+ QStringList ret;
+ TinyArchive *archive = m_packs.value(pack, 0);
+ if(!archive) {
+ qWarning() << "Failed to lookup template pack" << pack;
+ return ret;
+ }
+
+ QVector<TinyNode *> children = QVector<TinyNode *>::fromStdVector(archive->lookup("/")->children());
+ QVector<TinyNode *>::const_iterator it = children.begin();
+ for(; it != children.end(); ++it) {
+ TinyNode *child = *it;
+ if(!child->name()) {
+ qWarning() << "TinyNode::name null during template pack lookup for" << pack;
+ continue;
+ }
+ qDebug() << "Found pack template" << child->name();
+ ret << child->name();
+ }
+
+ return ret;
+}
+
+QIcon TemplateManager::packTemplateIcon(const QString& pack, const QString& _template) const
+{
+ return QIcon();
+}
+
+QByteArray TemplateManager::packTemplateData(const QString& pack, const QString& _template) const
+{
+ TinyArchive *archive = m_packs.value(pack, 0);
+ if(!archive) return QByteArray();
+
+ const TinyNode *node = archive->lookup(_template.toStdString());
+
+ return QByteArray(reinterpret_cast<const char *>(node->data()), node->length());
+}
+
+bool TemplateManager::installPack(const QString& name, const TinyArchive *archive)
+{
+ QFile file(QDir(packPath()).filePath(name + ("." KISS_TEMPLATE_PACK_EXT)));
+ if(file.exists()) return false;
+ if(!file.open(QIODevice::WriteOnly)) return false;
+
+ QTinyArchiveStream stream(&file);
+ archive->write(&stream);
+
+ file.close();
+
+ return true;
+}
+
QString TemplateManager::pathForTemplate(const QString& type, const QString& _template)
{
- return QDir::currentPath() + "/" + TEMPLATES_FOLDER + "/" + type + "/" + (_template.isEmpty() ? "" : "/" + _template);
+ return QDir::currentPath() + "/" + TEMPLATES_FOLDER + "/" + type + (_template.isEmpty() ? "" : "/" + _template);
}
bool TemplateManager::isTemplateDirectory(const QString& type, const QString& _template)
@@ -124,4 +216,9 @@ const QString& TemplateManager::defaultTemplateName() { return m_defaultName; }
void TemplateManager::ensureUserTemplateDirExists(const QString& type)
{
QDir().mkpath(pathForUserTemplate(type, ""));
+}
+
+QString TemplateManager::packPath() const
+{
+ return QDir::currentPath() + "/" + USER_FOLDER + "/" + TEMPLATES_FOLDER;
}
View
20 src/dialogs/TargetDialog.cpp
@@ -1,3 +1,23 @@
+/**************************************************************************
+ * Copyright 2007-2012 KISS Institute for Practical Robotics *
+ * *
+ * This file is part of KISS (Kipr's Instructional Software System). *
+ * *
+ * KISS is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * KISS is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with KISS. Check the LICENSE file in the project root. *
+ * If not, see <http://www.gnu.org/licenses/>. *
+ **************************************************************************/
+
#include "TargetDialog.h"
#include "Interface.h"
View
96 src/dialogs/TemplateDialog.cpp
@@ -29,6 +29,11 @@
#include <QListWidgetItem>
#include <QDebug>
#include <QFileInfo>
+#include <QDir>
+#include <QFileDialog>
+
+#define DEPRECATED_TEMPLATE_ROLE (Qt::UserRole)
+#define TEMPLATE_ROLE (Qt::UserRole + 1)
TemplateDialog::TemplateDialog(QWidget* parent) : QDialog(parent) { setupUi(this); }
@@ -41,7 +46,19 @@ int TemplateDialog::exec()
foreach(const QString& type, types) {
QListWidgetItem* item = new QListWidgetItem(type);
- item->setData(Qt::UserRole, type);
+ item->setData(DEPRECATED_TEMPLATE_ROLE, type);
+ ui_types->addItem(item);
+ if(first) {
+ ui_types->setCurrentItem(item);
+ first = false;
+ }
+ }
+
+ const QStringList& packs = TemplateManager::ref().packs();
+ foreach(const QString& pack, packs) {
+ QListWidgetItem* item = new QListWidgetItem(pack);
+
+ item->setData(TEMPLATE_ROLE, pack);
ui_types->addItem(item);
if(first) {
ui_types->setCurrentItem(item);
@@ -57,21 +74,55 @@ QString TemplateDialog::selectedTypeName() const
return ui_types->currentItem() ? ui_types->currentItem()->data(Qt::UserRole).toString() : QString();
}
-QString TemplateDialog::templateFile()
+// Deprecated
+QString TemplateDialog::templateFile() const
{
if(!ui_types->currentItem()) return QString();
- const QString& type = ui_types->currentItem()->data(Qt::UserRole).toString();
+ const QString& type = ui_types->currentItem()->data(DEPRECATED_TEMPLATE_ROLE).toString();
+ if(type.isEmpty()) return QString();
return ui_templates->currentItem() ?
- ui_templates->currentItem()->data(0, Qt::UserRole).toString() :
+ ui_templates->currentItem()->data(0, DEPRECATED_TEMPLATE_ROLE).toString() :
TemplateManager::ref().pathForTemplate(type, "Default");
}
+QByteArray TemplateDialog::templateData() const
+{
+ QString path = templateFile();
+
+ // Deprecated
+ if(!path.isEmpty()) {
+ QFile file(path);
+ if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ qWarning() << "Failed to open template" << path << "for reading";
+ return QByteArray();
+ }
+ QByteArray ret(file.readAll());
+ file.close();
+ qDebug() << "Read" << ret << "from template" << path;
+ return ret;
+ }
+
+ QString pack = ui_types->currentItem()->data(TEMPLATE_ROLE).toString();
+ if(!ui_templates->currentItem()) return QByteArray();
+ QString _template = ui_templates->currentItem()->data(0, TEMPLATE_ROLE).toString();
+ return TemplateManager::ref().packTemplateData(pack, _template);
+}
+
void TemplateDialog::on_ui_types_currentItemChanged(QListWidgetItem* current, QListWidgetItem*)
{
- const QString& type = current->data(Qt::UserRole).toString();
+ QString type = current->data(DEPRECATED_TEMPLATE_ROLE).toString();
+ // DEPRECATED
+ if(!type.isEmpty()) {
+ ui_templates->clear();
+ addTemplates(type, 0, "");
+ addUserTemplates(type);
+ ui_templates->setCurrentItem(ui_templates->topLevelItem(0));
+ return;
+ }
+
+ QString pack = current->data(TEMPLATE_ROLE).toString();
ui_templates->clear();
- addTemplates(type, 0, "");
- addUserTemplates(type);
+ addPackTemplates(pack);
ui_templates->setCurrentItem(ui_templates->topLevelItem(0));
}
@@ -103,6 +154,18 @@ void TemplateDialog::on_ui_remove_clicked()
on_ui_types_currentItemChanged(ui_types->currentItem(), 0);
}
+void TemplateDialog::on_ui_install_clicked()
+{
+ QString path = QFileDialog::getExistingFile(this, "Install Template Pack", QDir::homePath(), KISS_TEMPLATE_PACK_FILTER);
+ if(path.isEmpty()) return;
+ QString name = QFileInfo(path).completeBaseName();
+ TinyArchiveFile file(path.toStdString());
+ TinyArchive *pack = TinyArchive::read(&file);
+ if(!pack) return;
+ TemplateManager::ref().installPack(name, pack);
+ delete pack;
+}
+
void TemplateDialog::addTemplates(const QString& target, QTreeWidgetItem* parentItem, const QString& parent = "")
{
const QStringList& templates = TemplateManager::ref().templates(target, parent);
@@ -111,7 +174,7 @@ void TemplateDialog::addTemplates(const QString& target, QTreeWidgetItem* parent
QTreeWidgetItem* item = !parentItem ? new QTreeWidgetItem(ui_templates) : new QTreeWidgetItem(parentItem);
item->setText(0, templateName);
item->setIcon(0, TemplateManager::ref().templateIcon(target, _template));
- item->setData(0, Qt::UserRole, TemplateManager::ref().pathForTemplate(target, _template));
+ item->setData(0, DEPRECATED_TEMPLATE_ROLE, TemplateManager::ref().pathForTemplate(target, _template));
}
const QStringList& folders = TemplateManager::ref().templateFolders(target, parent);
@@ -140,6 +203,21 @@ void TemplateDialog::addUserTemplates(const QString& target)
QTreeWidgetItem* item = new QTreeWidgetItem(parent);
item->setText(0, templateName);
item->setIcon(0, QIcon(":/icon_set/icons/empty.png"));
- item->setData(0, Qt::UserRole, TemplateManager::ref().pathForUserTemplate(target, _template));
+ item->setData(0, DEPRECATED_TEMPLATE_ROLE, TemplateManager::ref().pathForUserTemplate(target, _template));
+ }
+}
+
+void TemplateDialog::addPackTemplates(const QString& pack)
+{
+ const QStringList& templates = TemplateManager::ref().packTemplates(pack);
+ qDebug() << "Pack templates" << templates;
+ if(templates.isEmpty()) return;
+
+ foreach(const QString& _template, templates) {
+ const QString& templateName = _template.section(".", 0, 0).section("/", -1);
+ QTreeWidgetItem* item = new QTreeWidgetItem(ui_templates);
+ item->setText(0, templateName);
+ item->setIcon(0, QIcon(":/icon_set/icons/empty.png"));
+ item->setData(0, TEMPLATE_ROLE, _template);
}
}
View
20 src/dialogs/ThemeSettingsDialog.cpp
@@ -1,3 +1,23 @@
+/**************************************************************************
+ * Copyright 2007-2012 KISS Institute for Practical Robotics *
+ * *
+ * This file is part of KISS (Kipr's Instructional Software System). *
+ * *
+ * KISS is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation, either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * KISS is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with KISS. Check the LICENSE file in the project root. *
+ * If not, see <http://www.gnu.org/licenses/>. *
+ **************************************************************************/
+
#include "ThemeSettingsDialog.h"
#include "ui_ThemeSettingsDialog.h"
View
2 src/main.cpp
@@ -1,5 +1,5 @@
/**************************************************************************
- * Copyright 2007,2008,2009 KISS Institute for Practical Robotics *
+ * Copyright 2007-2012 KISS Institute for Practical Robotics *
* *
* This file is part of KISS (Kipr's Instructional Software System). *
* *
View
7 ui/TemplateDialog.ui
@@ -42,6 +42,13 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
+ <widget class="QPushButton" name="ui_install">
+ <property name="text">
+ <string>Install Template Pack...</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QPushButton" name="ui_remove">
<property name="enabled">
<bool>false</bool>

0 comments on commit e69323a

Please sign in to comment.
Something went wrong with that request. Please try again.