Skip to content

Commit

Permalink
Cleaning up some code
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcdorman committed Jun 30, 2011
1 parent ab274ee commit 90949af
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 102 deletions.
7 changes: 6 additions & 1 deletion build/ui/ui_MainWindow.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/********************************************************************************
** Form generated from reading UI file 'MainWindow.ui'
**
** Created: Wed Jun 29 09:40:50 2011
** Created: Thu Jun 30 10:57:36 2011
** by: Qt User Interface Compiler version 4.7.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
Expand Down Expand Up @@ -45,6 +45,7 @@ class Ui_MainWindow
QAction *actionNewProject;
QAction *actionManagePackages;
QAction *actionInstallLocalPackage;
QAction *actionHideErrors;
QWidget *ui_centralwidget;
QHBoxLayout *horizontalLayout;
QSplitter *splitter;
Expand Down Expand Up @@ -111,6 +112,8 @@ class Ui_MainWindow
actionManagePackages->setObjectName(QString::fromUtf8("actionManagePackages"));
actionInstallLocalPackage = new QAction(MainWindow);
actionInstallLocalPackage->setObjectName(QString::fromUtf8("actionInstallLocalPackage"));
actionHideErrors = new QAction(MainWindow);
actionHideErrors->setObjectName(QString::fromUtf8("actionHideErrors"));
ui_centralwidget = new QWidget(MainWindow);
ui_centralwidget->setObjectName(QString::fromUtf8("ui_centralwidget"));
horizontalLayout = new QHBoxLayout(ui_centralwidget);
Expand Down Expand Up @@ -170,6 +173,7 @@ class Ui_MainWindow

retranslateUi(MainWindow);
QObject::connect(actionQuit, SIGNAL(triggered()), MainWindow, SLOT(close()));
QObject::connect(actionHideErrors, SIGNAL(triggered()), ui_errorView, SLOT(hide()));

ui_tabWidget->setCurrentIndex(0);
ui_errorView->setCurrentIndex(0);
Expand Down Expand Up @@ -205,6 +209,7 @@ class Ui_MainWindow
actionNewProject->setShortcut(QApplication::translate("MainWindow", "Ctrl+N", 0, QApplication::UnicodeUTF8));
actionManagePackages->setText(QApplication::translate("MainWindow", "Manage Packages", 0, QApplication::UnicodeUTF8));
actionInstallLocalPackage->setText(QApplication::translate("MainWindow", "Install Local Package", 0, QApplication::UnicodeUTF8));
actionHideErrors->setText(QApplication::translate("MainWindow", "Hide Errors", 0, QApplication::UnicodeUTF8));
ui_tabWidget->setTabText(ui_tabWidget->indexOf(tab), QApplication::translate("MainWindow", "Tab 1", 0, QApplication::UnicodeUTF8));
ui_errorView->setTabText(ui_errorView->indexOf(tab_2), QApplication::translate("MainWindow", "Tab 1", 0, QApplication::UnicodeUTF8));
menuFile->setTitle(QApplication::translate("MainWindow", "File", 0, QApplication::UnicodeUTF8));
Expand Down
2 changes: 1 addition & 1 deletion include/EditorSettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Q_OBJECT

public:
// Constructor & Destructor
EditorSettingsDialog(QWidget *parent = 0);
EditorSettingsDialog(QWidget* parent = 0);
~EditorSettingsDialog();

// Show the dialog
Expand Down
6 changes: 3 additions & 3 deletions include/FindDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ Q_OBJECT

public:
// Constructor & Destructor
FindDialog(QWidget *parent = 0);
FindDialog(QWidget* parent = 0);
~FindDialog();

// Set the source file to run find on
void setSourceFile(SourceFile *sourceFile);
void setSourceFile(SourceFile* sourceFile);

bool isModified();

private:
SourceFile *m_currentSourceFile;
SourceFile* m_currentSourceFile;
bool m_isModified;

public slots:
Expand Down
8 changes: 8 additions & 0 deletions include/Kiss.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __KISS_H__
#define __KISS_H__

#define LEXER_FOLDER "lexers"
#define TARGET_FOLDER "targets"
#define TARGET_EXT "target"

#endif
3 changes: 1 addition & 2 deletions include/KissArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

struct KissReturn
{
KissReturn(bool error, const QString& message = "") : error(error), message(message) {}
KissReturn(const bool& error, const QString& message = "") : error(error), message(message) {}

bool error;
QString message;
Expand All @@ -43,7 +43,6 @@ class KissArchive
static KissReturn uninstall(const QString& name);
static const unsigned version(const QString& name);
static QStringList installed();
static QString osName();
private:
};

Expand Down
15 changes: 15 additions & 0 deletions include/Os.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef __OS_H__
#define __OS_H__

#ifdef Q_OS_WIN
#define OS_NAME "win"
#define OS_LIB_EXT "dll"
#elif defined(Q_OS_MAC)
#define OS_NAME "osx"
#define OS_LIB_EXT "dylib"
#else
#define OS_NAME "nix"
#define OS_LIB_EXT "so"
#endif

#endif
33 changes: 10 additions & 23 deletions src/KissArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
**************************************************************************/

#include "KissArchive.h"
#include "Os.h"

#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QDebug>
#include <QSettings>
#include <QString>

#define INSTALLED_VERSION_STRING "/version"
#define INSTALLED_DIRS_STRING "/dirs"
Expand Down Expand Up @@ -80,7 +83,7 @@ KissReturn KissArchive::create(const QString& name, unsigned pVersion, const QSt
foreach(const QString& file, noBlanks) {
if(file.isEmpty()) continue;
QFile f(file);
if (!f.open(QIODevice::ReadOnly)) return KissReturn(true, "Unable to open " + file + " for reading.");
if (!f.open(QIODevice::ReadOnly)) return KissReturn(true, QObject::tr("Unable to open ") + file + QObject::tr(" for reading."));

unsigned strLength = file.length();
out->write((char*)&strLength, sizeof(unsigned));
Expand All @@ -107,21 +110,21 @@ KissReturn KissArchive::install(QIODevice* in)
in->read(magic, 2);
if(magic[0] != kissMagic[0] || magic[1] != kissMagic[1]) {
qWarning() << "Bad Magic";
return KissReturn(true, "Bad Magic. Probably not a KISS Archive");
return KissReturn(true, QObject::tr("Bad Magic. Probably not a KISS Archive"));
}

// Read platforms, halt if current platform not detected
unsigned numPlatforms = 0;
in->read((char*)&numPlatforms, sizeof(unsigned));
bool match = false;
for(unsigned i = 0; i < numPlatforms; ++i) {
if(QString(in->read(3).data()) == osName()) {
if(QString(in->read(3).data()) == OS_NAME) {
match = true;
}
}
if(!match) {
qWarning() << "Incorrect OS";
return KissReturn(true, "This OS is not supported by the archive");
return KissReturn(true, QObject::tr("This OS is not supported by the archive"));
}

// Checks the Kiss Archive Specification version, so we know how to extract
Expand All @@ -141,7 +144,7 @@ KissReturn KissArchive::install(QIODevice* in)

if(KissArchive::version(name) >= pVersion) {
qWarning() << "Higher version already installed. Skipping.";
return KissReturn(true, "Higher version of same archive already installed");
return KissReturn(true, QObject::tr("Higher version of same archive already installed"));
} else if(KissArchive::version(name) < pVersion) {
uninstall(name);
}
Expand All @@ -160,6 +163,7 @@ KissReturn KissArchive::install(QIODevice* in)
in->read((char*)&dataLength, sizeof(unsigned));
const QByteArray& data = qUncompress(in->read(dataLength));

if(str.isEmpty()) continue;

QFile f(str);
const QString& filePath = QFileInfo(str).path();
Expand All @@ -170,7 +174,6 @@ KissReturn KissArchive::install(QIODevice* in)
}
if(!f.open(QIODevice::WriteOnly)) {
qWarning() << "Unable to open" << str << "for writing.";
return KissReturn(true, "Unable to open " + str + " for writing");
}
f.write(data);
}
Expand All @@ -191,7 +194,7 @@ KissReturn KissArchive::install(QIODevice* in)
KissReturn KissArchive::uninstall(const QString& name)
{
QSettings installed(KISS_ARCHIVE_FILE, QSettings::IniFormat);
if(!installed.childGroups().contains(name)) return KissReturn(true, "No such archive installed");
if(!installed.childGroups().contains(name)) return KissReturn(true, QObject::tr("No such archive installed"));

const QStringList& files = installed.value(name + INSTALLED_FILES_STRING).toStringList();
foreach(const QString& file, files) {
Expand Down Expand Up @@ -225,19 +228,3 @@ QStringList KissArchive::installed()
{
return QSettings(KISS_ARCHIVE_FILE, QSettings::IniFormat).childGroups();
}

/**
* Fetch 3 char OS Name
*/
QString KissArchive::osName()
{
return
#ifdef Q_OS_WIN
"win"
#elif defined(Q_OS_MAC)
"osx"
#else
"nix"
#endif
;
}
43 changes: 13 additions & 30 deletions src/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include "LexerSpec.h"

// Ugly constructor which initializes all of the local member variables
Lexer::Lexer(LexerSpec* spec, QString api) : QsciLexer(0), m_lexerSpec(spec), m_apis(this)
{
m_apis.clear();
Expand Down Expand Up @@ -59,23 +58,18 @@ QStringList Lexer::autoCompletionWordSeparators() const
const char *Lexer::blockStartKeyword(int* style) const
{
if (style) *style = m_lexerSpec->blockStartKeywordStyle;

return m_lexerSpec->blockStartKeyword.toLocal8Bit().data();
}

const char *Lexer::blockStart(int* style) const
{
if (style)
*style = m_lexerSpec->blockStartStyle;

if (style) *style = m_lexerSpec->blockStartStyle;
return m_lexerSpec->blockStart.toLocal8Bit().data();
}

const char *Lexer::blockEnd(int* style) const
{
if (style)
*style = m_lexerSpec->blockEndStyle;

if (style) *style = m_lexerSpec->blockEndStyle;
return m_lexerSpec->blockEnd.toLocal8Bit().data();
}

Expand All @@ -88,49 +82,38 @@ const char *Lexer::wordCharacters() const

QColor Lexer::defaultColor(int style) const
{
if(m_lexerSpec->defaultColor.contains(style)) {
return m_lexerSpec->defaultColor[style];
}

return QsciLexer::defaultColor(style);
return m_lexerSpec->defaultColor.contains(style) ? m_lexerSpec->defaultColor[style]
: QsciLexer::defaultColor(style);
}

bool Lexer::defaultEolFill(int style) const
{
if (m_lexerSpec->defaultEolFill.contains(style))
return true;

return QsciLexer::defaultEolFill(style);
return m_lexerSpec->defaultEolFill.contains(style) ? true
: QsciLexer::defaultEolFill(style);
}

QFont Lexer::defaultFont(int style) const
{
QFont f;

if(m_lexerSpec->defaultFont.contains(style)) {
QFont f;
f = m_lexerSpec->defaultFont[style];
f.setFamily(QsciLexer::defaultFont(style).family());
f.setPointSize(QsciLexer::defaultFont(style).pointSize());
return f;
}
else f = QsciLexer::defaultFont(style);

return f;

return QsciLexer::defaultFont(style);
}

const char* Lexer::keywords(int set) const
{
if(m_lexerSpec->keywords.contains(set))
return m_lexerSpec->keywords[set].toLocal8Bit();

return 0;
return m_lexerSpec->keywords.contains(set) ? (const char*)m_lexerSpec->keywords[set].toAscii() : 0;
}

QColor Lexer::defaultPaper(int style) const
{
if(m_lexerSpec->defaultPaper.contains(style))
return m_lexerSpec->defaultPaper[style];

return QsciLexer::defaultPaper(style);
return m_lexerSpec->defaultPaper.contains(style) ? m_lexerSpec->defaultPaper[style]
: QsciLexer::defaultPaper(style);
}

QString Lexer::description(int) const { return " "; }
19 changes: 6 additions & 13 deletions src/LexerSpecManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "LexerSpecManager.h"
#include "LexerSpec.h"
#include "LexerSpecProvider.h"
#include "Os.h"
#include "Kiss.h"

#include <QSettings>
#include <QDir>
#include <QDebug>
Expand Down Expand Up @@ -49,16 +52,8 @@ LexerSpecManager::~LexerSpecManager()
}

void LexerSpecManager::loadLexers()
{
QStringList exts;
#ifdef Q_OS_WIN
exts << "*.dll";
#elif defined(Q_OS_MAC)
exts << "*.dylib";
#else
exts << ".so";
#endif
QStringList lexers = QDir("lexers").entryList(exts);
{
QStringList lexers = QDir(LEXER_FOLDER).entryList(QStringList() << (QString("*.") + OS_LIB_EXT));
qWarning() << "Lexers:" << lexers;
foreach(const QString& str, lexers) {
qWarning() << str;
Expand All @@ -73,7 +68,7 @@ void LexerSpecManager::loadLexer(const QString& lexer)
// Create the QPluginLoader and start constructing the file name
QPluginLoader* plugin = new QPluginLoader();

QDir pluginPath(QDir::currentPath() + "/lexers");
QDir pluginPath(QDir::currentPath() + "/" + LEXER_FOLDER);
QString pluginPathString;

pluginPathString = pluginPath.absoluteFilePath(lexer);
Expand All @@ -93,8 +88,6 @@ void LexerSpecManager::loadLexer(const QString& lexer)
return;
}

qWarning() << "Loaded" << lexer;

LexerSpecProvider* provider = qobject_cast<LexerSpecProvider*>(plugin->instance());
provider->init();

Expand Down
4 changes: 3 additions & 1 deletion src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_currentTab(0),
/* Destructor */
MainWindow::~MainWindow()
{
ui_toolBar->clear();
while(ui_tabWidget->count() > 0) deleteTab(0);
}

Expand Down Expand Up @@ -137,6 +138,7 @@ void MainWindow::initMenus(Tab* tab)
menuFile->addAction(actionNew);
menuFile->addAction(actionOpen);
menuFile->addAction(actionInstallLocalPackage);
menuFile->addAction(actionHideErrors);
if(tab) tab->addActionsFile(menuFile);
menuFile->addSeparator();
menuFile->addAction(actionNext);
Expand Down Expand Up @@ -217,7 +219,7 @@ void MainWindow::closeEvent(QCloseEvent *e)
e->ignore();
return;
}
widgetCount--;
--widgetCount;
}

//Close all other windows
Expand Down
Loading

0 comments on commit 90949af

Please sign in to comment.