···11- __________ __ ___.
22- Open \______ \ ____ ____ | | _\_ |__ _______ ___
33- Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
44- Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
55- Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
66- \/ \/ \/ \/ \/
77-88-/----------------------------------------------------------------\
99-| Installation |
1010-\----------------------------------------------------------------/
1111-1212-To make a release version, change the value CONFIG in gui.pro and QPropertyEditor.pro from "debug" to "release".
1313-1414-1515-/----------------------------------------------------------------\
1616-| Windows |
1717-\----------------------------------------------------------------/
1818-1919- * make sure that you have properly installed MingW, Qt > 4.3.* and bin directories are set properly
2020- * if you want to debug wpseditor, you'll have to build Qt debug libraries
2121- * if you don't have qmake in your PATH environment, use the Qt command prompt
2222- * run 'qmake && make' in utils\wpseditor\
2323- * the binary is then in utils\wpseditor\gui\bin\wpseditor.exe
2424-2525-/----------------------------------------------------------------\
2626-| Linux |
2727-\----------------------------------------------------------------/
2828-2929- * make sure you have libqt4-dev installed and you have a working Rockbox environment
3030- * cd to utils/wpseditor/ and run 'qmake-qt4 && make'
3131- * cd to gui/bin/ and start WPS editor with './wpseditord'
-19
utils/wpseditor/TODO
···11-* Make better logging system
22-* Replace checkwps functionality
33-* Include 'screenshot utility' functionality
44-* Options
55-* Enable animation (timers, sliding lines, etc)
66-* Test on Mac OS
77-* Redesign GUI for more usability
88-* Make editing via gui
99-* Use native rockbox fonts
1010-* Replace shared libs as Qt Plugins
1111-* Edit wiki :-)
1212-1313-Partially solved
1414-* Enable ability in gui to load different targets on the fly [Not all targets are built yet]
1515-* Syntax highlight [Comments are done; enable for logEdit; tag highlight]
1616-1717-THE BUGZ ARE COMING!
1818-* While loading wps for the first time, gui doesn't show properties from editor properly
1919-* Strange text horizontal position in cabbiev2 (probably other themes too)
···11-// *************************************************************************************************
22-//
33-// QPropertyEditor v 0.1
44-//
55-// --------------------------------------
66-// Copyright (C) 2007 Volker Wiendl
77-//
88-//
99-// This library is free software; you can redistribute it and/or
1010-// modify it under the terms of the GNU Lesser General Public
1111-// License as published by the Free Software Foundation; either
1212-// version 2.1 of the License, or any later version.
1313-//
1414-// This library is distributed in the hope that it will be useful,
1515-// but WITHOUT ANY WARRANTY; without even the implied warranty of
1616-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1717-// Lesser General Public License for more details.
1818-//
1919-// You should have received a copy of the GNU Lesser General Public
2020-// License along with this library; if not, write to the Free Software
2121-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222-//
2323-//
2424-// This class is based on the Color Editor Factory Example by Trolltech
2525-//
2626-// *************************************************************************************************
2727-2828-#include "ColorCombo.h"
2929-3030-#include <Qt/qcolordialog.h>
3131-3232-ColorCombo::ColorCombo(QWidget* parent /*= 0*/) : QComboBox(parent) {
3333- QStringList colorNames = QColor::colorNames();
3434- for (int i = 0; i < colorNames.size(); ++i) {
3535- QColor color(colorNames[i]);
3636- insertItem(i, colorNames[i]);
3737- setItemData(i, color, Qt::DecorationRole);
3838- }
3939- addItem(tr("Custom"), QVariant((int)QVariant::UserType));
4040- connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(currentChanged(int)));
4141-}
4242-4343-4444-ColorCombo::~ColorCombo() {}
4545-4646-4747-QColor ColorCombo::color() const {
4848- return qVariantValue<QColor>(itemData(currentIndex(), Qt::DecorationRole));
4949-}
5050-5151-void ColorCombo::setColor(QColor color) {
5252- m_init = color;
5353- setCurrentIndex(findData(color, int(Qt::DecorationRole)));
5454- if (currentIndex() == -1) {
5555- addItem(color.name());
5656- setItemData(count()-1, color, Qt::DecorationRole);
5757- setCurrentIndex(count()-1);
5858- }
5959-}
6060-6161-void ColorCombo::currentChanged(int index) {
6262- if (itemData(index).isValid() && itemData(index) == QVariant((int)QVariant::UserType)) {
6363- QColor color = QColorDialog::getColor(m_init, this);
6464- if (color.isValid()) {
6565- if (findData(color, int(Qt::DecorationRole)) == -1) {
6666- addItem(color.name());
6767- setItemData(count()-1, color, Qt::DecorationRole);
6868- }
6969- setCurrentIndex(findData(color, int(Qt::DecorationRole)));
7070- } else
7171- setCurrentIndex(findData(m_init));
7272- }
7373-}
···11-// *************************************************************************************************
22-//
33-// QPropertyEditor v 0.1
44-//
55-// --------------------------------------
66-// Copyright (C) 2007 Volker Wiendl
77-//
88-//
99-// This library is free software; you can redistribute it and/or
1010-// modify it under the terms of the GNU Lesser General Public
1111-// License as published by the Free Software Foundation; either
1212-// version 2.1 of the License, or any later version.
1313-//
1414-// This library is distributed in the hope that it will be useful,
1515-// but WITHOUT ANY WARRANTY; without even the implied warranty of
1616-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1717-// Lesser General Public License for more details.
1818-//
1919-// You should have received a copy of the GNU Lesser General Public
2020-// License along with this library; if not, write to the Free Software
2121-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222-//
2323-//
2424-// This class is based on the Color Editor Factory Example by Trolltech
2525-//
2626-// *************************************************************************************************
2727-2828-#ifndef COLORCOMBO_H_
2929-#define COLORCOMBO_H_
3030-3131-#include <Qt/qcombobox.h>
3232-3333-class ColorCombo : public QComboBox {
3434- Q_OBJECT
3535-public:
3636- ColorCombo(QWidget* parent = 0);
3737- virtual ~ColorCombo();
3838-3939- QColor color() const;
4040- void setColor(QColor c);
4141-4242-private slots:
4343- void currentChanged(int index);
4444-4545-private:
4646- QColor m_init;
4747-4848-};
4949-#endif
···11-// ****************************************************************************************
22-//
33-// QPropertyEditor Library
44-// --------------------------------------
55-// Copyright (C) 2007 Volker Wiendl
66-//
77-// This file is part of the Horde3D Scene Editor.
88-//
99-// The QPropertyEditor Library is free software; you can redistribute it and/or modify
1010-// it under the terms of the GNU General Public License as published by
1111-// the Free Software Foundation version 3 of the License
1212-//
1313-// The Horde3D Scene Editor is distributed in the hope that it will be useful,
1414-// but WITHOUT ANY WARRANTY; without even the implied warranty of
1515-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616-// GNU General Public License for more details.
1717-//
1818-// You should have received a copy of the GNU General Public License
1919-// along with this program. If not, see <http://www.gnu.org/licenses/>.
2020-//
2121-// ****************************************************************************************
2222-2323-#include "Property.h"
2424-#include "ColorCombo.h"
2525-2626-#include <Qt/qmetaobject.h>
2727-#include <Qt/qspinbox.h>
2828-2929-#include <limits.h>
3030-3131-Property::Property(const QString& name /*= QString()*/, QObject* propertyObject /*= 0*/, QObject* parent /*= 0*/) : QObject(parent),
3232- m_propertyObject(propertyObject) {
3333- setObjectName(name);
3434-}
3535-3636-QVariant Property::value(int /*role = Qt::UserRole*/) const {
3737- if (m_propertyObject)
3838- return m_propertyObject->property(qPrintable(objectName()));
3939- else
4040- return QVariant();
4141-}
4242-4343-void Property::setValue(const QVariant &value) {
4444- if (m_propertyObject)
4545- m_propertyObject->setProperty(qPrintable(objectName()), value);
4646-}
4747-4848-bool Property::isReadOnly() {
4949- if (m_propertyObject && m_propertyObject->metaObject()->property(m_propertyObject->metaObject()->indexOfProperty(qPrintable(objectName()))).isWritable())
5050- return false;
5151- else
5252- return true;
5353-}
5454-5555-QWidget* Property::createEditor(QWidget *parent, const QStyleOptionViewItem &option) {
5656- (void)option;
5757- QWidget* editor = 0;
5858- switch (value().type()) {
5959- case QVariant::Color:
6060- editor = new ColorCombo(parent);
6161- break;
6262- case QVariant::Int:
6363- editor = new QSpinBox(parent);
6464- editor->setProperty("minimum", -INT_MAX);
6565- editor->setProperty("maximum", INT_MAX);
6666- connect(editor, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
6767- break;
6868- case QMetaType::Float:
6969- case QVariant::Double:
7070- editor = new QDoubleSpinBox(parent);
7171- editor->setProperty("minimum", -INT_MAX);
7272- editor->setProperty("maximum", INT_MAX);
7373- connect(editor, SIGNAL(valueChanged(double)), this, SLOT(setValue(double)));
7474- break;
7575- default:
7676- return editor;
7777- }
7878- return editor;
7979-}
8080-8181-bool Property::setEditorData(QWidget *editor, const QVariant &data) {
8282- switch (value().type()) {
8383- case QVariant::Color:
8484- static_cast<ColorCombo*>(editor)->setColor(data.value<QColor>());
8585- return true;
8686- ;
8787- case QVariant::Int:
8888- editor->blockSignals(true);
8989- static_cast<QSpinBox*>(editor)->setValue(data.toInt());
9090- editor->blockSignals(false);
9191- return true;
9292- case QMetaType::Float:
9393- case QVariant::Double:
9494- editor->blockSignals(true);
9595- static_cast<QDoubleSpinBox*>(editor)->setValue(data.toDouble());
9696- editor->blockSignals(false);
9797- return true;
9898- default:
9999- return false;
100100- }
101101- return false;
102102-}
103103-104104-QVariant Property::editorData(QWidget *editor) {
105105- switch (value().type()) {
106106- case QVariant::Color:
107107- return QVariant::fromValue(static_cast<ColorCombo*>(editor)->color());
108108- case QVariant::Int:
109109- return QVariant(static_cast<QSpinBox*>(editor)->value());
110110- case QMetaType::Float:
111111- case QVariant::Double:
112112- return QVariant(static_cast<QDoubleSpinBox*>(editor)->value());
113113- break;
114114- default:
115115- return QVariant();
116116- }
117117-}
118118-119119-Property* Property::findPropertyObject(QObject* propertyObject) {
120120- if (m_propertyObject == propertyObject)
121121- return this;
122122- for (int i=0; i<children().size(); ++i) {
123123- Property* child = static_cast<Property*>(children()[i])->findPropertyObject(propertyObject);
124124- if (child)
125125- return child;
126126- }
127127- return 0;
128128-}
129129-130130-void Property::setValue(double value) {
131131- setValue(QVariant(value));
132132-}
133133-134134-void Property::setValue(int value) {
135135- setValue(QVariant(value));
136136-}
···11-// *************************************************************************************************
22-//
33-// QPropertyEditor v 0.1
44-//
55-// --------------------------------------
66-// Copyright (C) 2007 Volker Wiendl
77-//
88-//
99-// This library is free software; you can redistribute it and/or
1010-// modify it under the terms of the GNU Lesser General Public
1111-// License as published by the Free Software Foundation; either
1212-// version 2.1 of the License, or any later version.
1313-//
1414-// This library is distributed in the hope that it will be useful,
1515-// but WITHOUT ANY WARRANTY; without even the implied warranty of
1616-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1717-// Lesser General Public License for more details.
1818-//
1919-// You should have received a copy of the GNU Lesser General Public
2020-// License along with this library; if not, write to the Free Software
2121-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222-//
2323-// *************************************************************************************************
2424-2525-#ifndef PROPERTY_H_
2626-#define PROPERTY_H_
2727-2828-#include <Qt/qwidget.h>
2929-#include <Qt/qstyleoption.h>
3030-#include <Qt/qvariant.h>
3131-3232-/**
3333- * The Property class is the base class for all properties in the QPropertyEditor
3434- * You can implement custom properties inherited from this class to further enhence the
3535- * functionality of the QPropertyEditor
3636- */
3737-class Property : public QObject {
3838- Q_OBJECT
3939-4040-public:
4141-4242- /**
4343- * Constructor
4444- *
4545- * @param name the name of the property within the propertyObject (will be used in the QPropertyEditorWidget view too)
4646- * @param propertyObject the object that contains the property
4747- * @param parent optional parent object
4848- */
4949- Property(const QString& name = QString(), QObject* propertyObject = 0, QObject* parent = 0);
5050-5151- /**
5252- * The value stored by this property
5353- * @return QVariant the data converted to a QVariant
5454- */
5555- virtual QVariant value(int role = Qt::UserRole) const;
5656- /**
5757- * Sets the value stored by this property
5858- * @param value the data converted to a QVariant
5959- */
6060- virtual void setValue(const QVariant& value);
6161-6262- /**
6363- * Returns the QObject which contains the property managed by this instance
6464- * @return QObject* pointer to the QObject that contains user defined properties
6565- */
6666- QObject* propertyObject() {
6767- return m_propertyObject;
6868- }
6969-7070- /**
7171- * Flag if property is used for indicating a group or really manages a property
7272- * @return bool true if this property is only used to display a category in the QPropertyEditorWidget
7373- */
7474- bool isRoot() {
7575- return m_propertyObject == 0;
7676- }
7777-7878- /**
7979- * Flag if the property can be set
8080- * @return bool true if this property has no set method
8181- */
8282- bool isReadOnly();
8383-8484- /**
8585- * Returns the row of this instance within the QPropertyModel
8686- * @return int row within the QPropertyModel
8787- */
8888- int row() {
8989- return parent()->children().indexOf(this);
9090- }
9191-9292- /**
9393- * returns optional settings for the editor widget that is used to manipulate the properties value
9494- * @return QString a string that contains property settings for the editor widget (e.g. "minimum=1.0;maximum=10.0;")
9595- */
9696- QString editorHints() {
9797- return m_hints;
9898- }
9999-100100- /**
101101- * Sets properties for the editor widget that is used to manipulate the data value managed by this instance
102102- * @param hints a string containing property settings for the editor widget that manipulates this property
103103- */
104104- virtual void setEditorHints(const QString& hints) {
105105- m_hints = hints;
106106- }
107107-108108- /**
109109- * Creates an editor for the data managed by this instance
110110- * @param parent widget the newly created editor widget will be child of
111111- * @param option currently not used
112112- * @return QWidget* pointer to the editor widget
113113- */
114114- virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option);
115115-116116- /**
117117- * Returns the data of the editor widget used to manipulate this instance
118118- * @return QVariant the data converted to a QVariant
119119- */
120120- virtual QVariant editorData(QWidget *editor);
121121-122122- /**
123123- * Changes the editor widget's data to a specific value
124124- * @param editor the editor widget
125125- * @param data the data to set in the editor widget
126126- * @return bool true if editor widget was set to the given data successfully, false if the data can not be set in the editor (e.g. wrong datatype)
127127- */
128128- virtual bool setEditorData(QWidget *editor, const QVariant& data);
129129-130130- /**
131131- * Tries to find the first property that manages the given propertyObject
132132- * @param propertyObject
133133- * @return Property
134134- */
135135- Property* findPropertyObject(QObject* propertyObject);
136136-137137-private slots:
138138- /**
139139- * This slot is used to immediately set the properties when the editor widget's value of a double or float
140140- * property has changed
141141- * @param value the new value
142142- */
143143- void setValue(double value);
144144- /**
145145- * This slot is used to immediately set the properties when the editor widget's value of an integer
146146- * property has changed
147147- * @param value the new value
148148- */
149149- void setValue(int value);
150150-151151-private:
152152- QObject* m_propertyObject;
153153- QString m_hints;
154154-155155-};
156156-157157-#endif
···11-// *************************************************************************************************
22-//
33-// QPropertyEditor v 0.1
44-//
55-// --------------------------------------
66-// Copyright (C) 2007 Volker Wiendl
77-//
88-//
99-// This library is free software; you can redistribute it and/or
1010-// modify it under the terms of the GNU Lesser General Public
1111-// License as published by the Free Software Foundation; either
1212-// version 2.1 of the License, or any later version.
1313-//
1414-// This library is distributed in the hope that it will be useful,
1515-// but WITHOUT ANY WARRANTY; without even the implied warranty of
1616-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1717-// Lesser General Public License for more details.
1818-//
1919-// You should have received a copy of the GNU Lesser General Public
2020-// License along with this library; if not, write to the Free Software
2121-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222-//
2323-// *************************************************************************************************
2424-2525-#include "QPropertyEditorWidget.h"
2626-#include "QPropertyModel.h"
2727-#include "QVariantDelegate.h"
2828-#include "Property.h"
2929-3030-QPropertyEditorWidget::QPropertyEditorWidget(QWidget* parent /*= 0*/) : QTreeView(parent) {
3131- m_model = new QPropertyModel(this);
3232- setModel(m_model);
3333- setItemDelegate(new QVariantDelegate(this));
3434-}
3535-3636-3737-QPropertyEditorWidget::~QPropertyEditorWidget() {}
3838-3939-void QPropertyEditorWidget::addObject(QObject* propertyObject) {
4040- m_model->addItem(propertyObject);
4141- expandToDepth(0);
4242-}
4343-4444-void QPropertyEditorWidget::setObject(QObject* propertyObject) {
4545- m_model->clear();
4646- if (propertyObject)
4747- addObject(propertyObject);
4848-}
4949-5050-void QPropertyEditorWidget::updateObject(QObject* propertyObject) {
5151- m_model->updateItem(propertyObject);
5252-}
5353-5454-void QPropertyEditorWidget::setCustomPropertyCB(UserTypeCB callback) {
5555- m_model->setCustomPropertyCB(callback);
5656-}
···11-// *************************************************************************************************
22-//
33-// QPropertyEditor v 0.1
44-//
55-// --------------------------------------
66-// Copyright (C) 2007 Volker Wiendl
77-//
88-//
99-// This library is free software; you can redistribute it and/or
1010-// modify it under the terms of the GNU Lesser General Public
1111-// License as published by the Free Software Foundation; either
1212-// version 2.1 of the License, or any later version.
1313-//
1414-// This library is distributed in the hope that it will be useful,
1515-// but WITHOUT ANY WARRANTY; without even the implied warranty of
1616-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1717-// Lesser General Public License for more details.
1818-//
1919-// You should have received a copy of the GNU Lesser General Public
2020-// License along with this library; if not, write to the Free Software
2121-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222-//
2323-// *************************************************************************************************
2424-2525-#ifndef QPROPERTYEDITORWIDGET_H_
2626-#define QPROPERTYEDITORWIDGET_H_
2727-2828-#include <Qt/qtreeview.h>
2929-3030-class QPropertyModel;
3131-class Property;
3232-3333-/**
3434- * \mainpage QPropertyEditor
3535- *
3636- * \section intro_sec Introduction
3737- *
3838- * The main purpose for the QPropertyEditor is the visualization and manipulation of properties defined via the Q_PROPERTY macro in
3939- * QObject based classes.
4040- */
4141-4242-/**
4343- * \brief The QPropertyEditorWidget offers an easy to use mechanism to visualize properties of a class inherited from QObject.
4444- *
4545- * Qt provides a nice way to define class properties by using the Q_PROPERTY macro. The purpose of the QPropertyEditor
4646- * is to visualize these properties in an easy way.
4747- *
4848- * To use the property editor, all you have to do is to create a class that defines it's properties by using Q_PROPERTY
4949- * and to add this class by using the addObject() method of this QPropertyEditorWidget class.
5050- * The QPropertyEditorWidget is inherited from QTreeView and will display the properties in a tree with two columns: Name and Value
5151- *
5252- * For basic data types the build in editor widgets of Qt will be used. The QPropertyEditor itself only defines an additional
5353- * editor for QColor (based on the Color Editor Factory Example from Trolltech). But it can easily be extended by yourself
5454- * either within the library or for special datatypes also outside of the library in your application.
5555- */
5656-class QPropertyEditorWidget : public QTreeView {
5757- Q_OBJECT
5858-public:
5959-6060- /**
6161- * A typedef for a callback used to create user defined properties for custom datatypes
6262- */
6363- typedef Property* (*UserTypeCB)(const QString& name, QObject* propertyObject, Property* parent);
6464-6565- /**
6666- * \brief Constructor
6767- *
6868- * Creates a new editor widget based on QTreeView
6969- * @param parent optional parent widget
7070- */
7171- QPropertyEditorWidget(QWidget* parent = 0);
7272-7373- /// Destructor
7474- virtual ~QPropertyEditorWidget();
7575-7676- /**
7777- * Adds the user properties of the given class to the QPropertyModel associated with this view
7878- *
7979- * @param propertyObject the class inherited from QObject that contains user properties that should be
8080- * managed by the QPropertyModel associated with this view
8181- */
8282- void addObject(QObject* propertyObject);
8383-8484- /**
8585- * Similar to the addObject() method this method adds the properties of the given class to the QPropertyModel
8686- * associated with this view. But in contrast to addObject() it will clear the model before, removing all
8787- * previously added objects.
8888- *
8989- * @param propertyObject the class inherited from QObject that contains user properties that should be
9090- * managed by the QPropertyModel associated with this view
9191- */
9292- void setObject(QObject* propertyObject);
9393-9494- /**
9595- * Updates the view for the given object. This can be usefull if a property was changed programmatically instead
9696- * of using the view. In this case the view normally will display the new property values only after the user clicked
9797- * on it. To overcome this problem you can call updateObject with the object whose property was changed.
9898- */
9999- void updateObject(QObject* propertyObject);
100100-101101- /**
102102- * If you define custom datatypes outside of this library the QPropertyModel will check if you
103103- * also defined a callback that is responsible to create custom property classes inherited from Property to handle
104104- * these datatypes. With this method you can set such a callback that will create custom properties for custom datatypes.
105105- */
106106- void setCustomPropertyCB(UserTypeCB callback);
107107-108108-private:
109109- /// The Model for this view
110110- QPropertyModel* m_model;
111111-112112-};
113113-#endif
···11-// *************************************************************************************************
22-//
33-// QPropertyEditor v 0.1
44-//
55-// --------------------------------------
66-// Copyright (C) 2007 Volker Wiendl
77-//
88-//
99-// This library is free software; you can redistribute it and/or
1010-// modify it under the terms of the GNU Lesser General Public
1111-// License as published by the Free Software Foundation; either
1212-// version 2.1 of the License, or any later version.
1313-//
1414-// This library is distributed in the hope that it will be useful,
1515-// but WITHOUT ANY WARRANTY; without even the implied warranty of
1616-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1717-// Lesser General Public License for more details.
1818-//
1919-// You should have received a copy of the GNU Lesser General Public
2020-// License along with this library; if not, write to the Free Software
2121-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222-//
2323-// *************************************************************************************************
2424-#ifndef QPROPERTYMODEL_H_
2525-#define QPROPERTYMODEL_H_
2626-2727-#include <Qt/qabstractitemmodel.h>
2828-#include <Qt/qmap.h>
2929-3030-#include "QPropertyEditorWidget.h"
3131-3232-class Property;
3333-3434-/**
3535- * The QPropertyModel handles the user defined properties of QObjects
3636- */
3737-class QPropertyModel : public QAbstractItemModel {
3838- Q_OBJECT
3939-public:
4040- /**
4141- * Constructor
4242- * @param parent optional parent object
4343- */
4444- QPropertyModel(QObject* parent = 0);
4545- /// Destructor
4646- virtual ~QPropertyModel();
4747-4848- /// QAbstractItemModel implementation
4949- QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
5050-5151- /// QAbstractItemModel implementation
5252- QModelIndex parent ( const QModelIndex & index ) const;
5353- /// QAbstractItemModel implementation
5454- int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
5555- /// QAbstractItemModel implementation
5656- int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
5757- /// QAbstractItemModel implementation
5858- QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
5959-6060- /// QAbstractItemModel implementation
6161- bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
6262- /// QAbstractItemModel implementation
6363- Qt::ItemFlags flags ( const QModelIndex & index ) const;
6464-6565- /// QAbstractItemModel implementation
6666- QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
6767-6868- /// QAbstractItemModel implementation
6969- QModelIndex buddy ( const QModelIndex & index ) const;
7070-7171- /**
7272- * Adds the user properties of the given class to the QPropertyModel instance
7373- *
7474- * @param propertyObject the class inherited from QObject that contains user properties that should be
7575- * managed by this instance
7676- */
7777- void addItem(QObject* propertyObject);
7878-7979- /**
8080- * Creates a dataChanged signal for the given object
8181- * @param propertyObject the instance of a QObject based class that should be updated
8282- * @param parent optional model index the propertyObject is child of
8383- */
8484- void updateItem ( QObject* propertyObject, const QModelIndex& parent = QModelIndex() ) ;
8585-8686- /**
8787- * Removes all objects from the model
8888- */
8989- void clear();
9090-9191- /**
9292- * Sets custom callback that will be used to create Property instances for custom datatypes
9393- */
9494- void setCustomPropertyCB(QPropertyEditorWidget::UserTypeCB callback);
9595-9696-private:
9797-9898- /// The Root Property for all objects
9999- Property* m_rootItem;
100100-101101- /// Custom callback
102102- QPropertyEditorWidget::UserTypeCB m_userCallback;
103103-104104-};
105105-#endif
···11-// *************************************************************************************************
22-//
33-// QPropertyEditor v 0.1
44-//
55-// --------------------------------------
66-// Copyright (C) 2007 Volker Wiendl
77-//
88-//
99-// This library is free software; you can redistribute it and/or
1010-// modify it under the terms of the GNU Lesser General Public
1111-// License as published by the Free Software Foundation; either
1212-// version 2.1 of the License, or any later version.
1313-//
1414-// This library is distributed in the hope that it will be useful,
1515-// but WITHOUT ANY WARRANTY; without even the implied warranty of
1616-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1717-// Lesser General Public License for more details.
1818-//
1919-// You should have received a copy of the GNU Lesser General Public
2020-// License along with this library; if not, write to the Free Software
2121-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222-//
2323-// *************************************************************************************************
2424-2525-#include "QVariantDelegate.h"
2626-2727-#include "Property.h"
2828-2929-#include <Qt/qabstractitemview.h>
3030-3131-3232-QVariantDelegate::QVariantDelegate(QObject* parent) : QItemDelegate(parent) {}
3333-3434-3535-QVariantDelegate::~QVariantDelegate() {}
3636-3737-QWidget *QVariantDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& option , const QModelIndex & index ) const {
3838- QWidget* editor = 0;
3939- Property* p = static_cast<Property*>(index.internalPointer());
4040- switch (p->value().type()) {
4141- case QVariant::Color:
4242- case QVariant::Int:
4343- case QMetaType::Float:
4444- case QVariant::Double:
4545- case QVariant::UserType:
4646- editor = p->createEditor(parent, option);
4747- if (editor) break; // if no editor could be created take default case
4848- default:
4949- editor = QItemDelegate::createEditor(parent, option, index);
5050- }
5151- parseEditorHints(editor, p->editorHints());
5252- return editor;
5353-}
5454-5555-void QVariantDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
5656- QVariant data = index.model()->data(index, Qt::EditRole);
5757- switch (data.type()) {
5858- case QVariant::Color:
5959- case QMetaType::Double:
6060- case QMetaType::Float:
6161- case QVariant::UserType:
6262- if (static_cast<Property*>(index.internalPointer())->setEditorData(editor, data)) // if editor couldn't be recognized use default
6363- break;
6464- default:
6565- QItemDelegate::setEditorData(editor, index);
6666- break;
6767- }
6868-}
6969-7070-void QVariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
7171- QVariant data = index.model()->data(index, Qt::EditRole);
7272- switch (data.type()) {
7373- case QVariant::Color:
7474- case QMetaType::Double:
7575- case QMetaType::Float:
7676- case QVariant::UserType: {
7777- QVariant data = static_cast<Property*>(index.internalPointer())->editorData(editor);
7878- if (data.isValid()) {
7979- model->setData(index, data , Qt::EditRole);
8080- break;
8181- }
8282- }
8383- default:
8484- QItemDelegate::setModelData(editor, model, index);
8585- break;
8686- }
8787-}
8888-8989-void QVariantDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index ) const {
9090- return QItemDelegate::updateEditorGeometry(editor, option, index);
9191-}
9292-9393-void QVariantDelegate::parseEditorHints(QWidget* editor, const QString& editorHints) const {
9494- if (editor && !editorHints.isEmpty()) {
9595- // Parse for property values
9696- QRegExp rx("(.*)(=\\s*)(.*)(;{1})");
9797- rx.setMinimal(true);
9898- int pos = 0;
9999- while ((pos = rx.indexIn(editorHints, pos)) != -1) {
100100- qDebug("Setting %s to %s", qPrintable(rx.cap(1)), qPrintable(rx.cap(3)));
101101- editor->setProperty(qPrintable(rx.cap(1).trimmed()), rx.cap(3).trimmed());
102102- pos += rx.matchedLength();
103103- }
104104- }
105105-}
···11-// *************************************************************************************************
22-//
33-// QPropertyEditor v 0.1
44-//
55-// --------------------------------------
66-// Copyright (C) 2007 Volker Wiendl
77-//
88-//
99-// This library is free software; you can redistribute it and/or
1010-// modify it under the terms of the GNU Lesser General Public
1111-// License as published by the Free Software Foundation; either
1212-// version 2.1 of the License, or any later version.
1313-//
1414-// This library is distributed in the hope that it will be useful,
1515-// but WITHOUT ANY WARRANTY; without even the implied warranty of
1616-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1717-// Lesser General Public License for more details.
1818-//
1919-// You should have received a copy of the GNU Lesser General Public
2020-// License along with this library; if not, write to the Free Software
2121-// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2222-//
2323-// *************************************************************************************************
2424-2525-#ifndef COLORSELECTIONBUTTON_H_
2626-#define COLORSELECTIONBUTTON_H_
2727-2828-#include <Qt/qitemdelegate.h>
2929-3030-3131-/**
3232- * This class is used to create the editor widgets for datatypes encapsulated in QVariant variables
3333- */
3434-class QVariantDelegate : public QItemDelegate {
3535- Q_OBJECT
3636-3737-public:
3838- /**
3939- * Constructor
4040- * @param parent optional parent object
4141- */
4242- QVariantDelegate(QObject* parent = 0);
4343- /// Destructor
4444- virtual ~QVariantDelegate();
4545-4646- /**
4747- * Creates an editor widget as child of a given widget for a specific QModelIndex
4848- *
4949- * @param parent the parent widget for the editor
5050- * @param option some style options that the editor should use
5151- * @param index the index of the item the editor will be created for
5252- * @return QWidget the editor widget
5353- */
5454- QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
5555-5656- /**
5757- * Tries to set the editor data based on the value stored at a specific QModelIndex
5858- * @param editor the editor widget
5959- * @param index the model index of the value that should be used in the editor
6060- */
6161- virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
6262-6363- /**
6464- * Sets the data of a specific QModelIndex to tha value of the editor widget
6565- * @param editor the editor widget that contains the new value
6666- * @param model the model that contains the index
6767- * @param index the index within the model whose data value should be set to the data value of the editor
6868- */
6969- virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
7070-7171- /// QItemDelegate implementation
7272- virtual void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
7373-7474-protected:
7575- void parseEditorHints(QWidget* editor, const QString& editorHints) const;
7676-7777-};
7878-#endif
-37
utils/wpseditor/gui/src/main.cpp
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#include <QApplication>
2323-#include "qwpseditorwindow.h"
2424-#include "utils.h"
2525-#include <QPointer>
2626-2727-QPointer<QWpsEditorWindow> win;
2828-2929-int main(int argc, char ** argv) {
3030- QApplication app( argc, argv );
3131-3232- win = new QWpsEditorWindow;
3333- win->show();
3434- app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
3535-3636- return app.exec();
3737-}
-181
utils/wpseditor/gui/src/numberedtextview.cpp
···11-/* This file is part of the KDE libraries
22- Copyright (C) 2005, 2006 KJSEmbed Authors
33- See included AUTHORS file.
44-55- This library is free software; you can redistribute it and/or
66- modify it under the terms of the GNU Library General Public
77- License as published by the Free Software Foundation; either
88- version 2 of the License, or (at your option) any later version.
99-1010- This library is distributed in the hope that it will be useful,
1111- but WITHOUT ANY WARRANTY; without even the implied warranty of
1212- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1313- Library General Public License for more details.
1414-1515- You should have received a copy of the GNU Library General Public License
1616- along with this library; see the file COPYING.LIB. If not, write to
1717- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1818- Boston, MA 02110-1301, USA.
1919-2020-2121- --------------------------------------------------------------------------------------
2222- Imported into the WPS editor and simplified by Dominik Wenger
2323-2424-*/
2525-2626-2727-#include <QTextDocument>
2828-#include <QTextBlock>
2929-#include <QTextEdit>
3030-#include <QHBoxLayout>
3131-#include <QScrollBar>
3232-#include <QPainter>
3333-#include <QAbstractTextDocumentLayout>
3434-#include <QDebug>
3535-3636-#include "numberedtextview.h"
3737-3838-NumberBar::NumberBar( QWidget *parent )
3939- : QWidget( parent ), edit(0), markedLine(-1)
4040-{
4141- // Make room for 4 digits and the breakpoint icon
4242- setFixedWidth( fontMetrics().width( QString("0000") + 10 + 32 ) );
4343- markerIcon = QPixmap( "images/marker.png" );
4444-}
4545-4646-NumberBar::~NumberBar()
4747-{
4848-}
4949-5050-5151-void NumberBar::markLine( int lineno )
5252-{
5353- markedLine = lineno;
5454-}
5555-5656-void NumberBar::setTextEdit( QTextEdit *edit )
5757-{
5858- this->edit = edit;
5959- connect( edit->document()->documentLayout(), SIGNAL( update(const QRectF &) ),
6060- this, SLOT( update() ) );
6161- connect( edit->verticalScrollBar(), SIGNAL(valueChanged(int) ),
6262- this, SLOT( update() ) );
6363-}
6464-6565-void NumberBar::paintEvent( QPaintEvent * )
6666-{
6767- QAbstractTextDocumentLayout *layout = edit->document()->documentLayout();
6868- int contentsY = edit->verticalScrollBar()->value();
6969- qreal pageBottom = contentsY + edit->viewport()->height();
7070- const QFontMetrics fm = fontMetrics();
7171- const int ascent = fontMetrics().ascent() + 1; // height = ascent + descent + 1
7272- int lineCount = 1;
7373-7474- QPainter p(this);
7575-7676- markedRect = QRect();
7777-7878- for ( QTextBlock block = edit->document()->begin();
7979- block.isValid(); block = block.next(), ++lineCount )
8080- {
8181-8282- const QRectF boundingRect = layout->blockBoundingRect( block );
8383-8484- QPointF position = boundingRect.topLeft();
8585- if ( position.y() + boundingRect.height() < contentsY )
8686- continue;
8787- if ( position.y() > pageBottom )
8888- break;
8989-9090- const QString txt = QString::number( lineCount );
9191- p.drawText( width() - fm.width(txt), qRound( position.y() ) - contentsY + ascent, txt );
9292-9393- // marker
9494- if ( markedLine == lineCount )
9595- {
9696- p.drawPixmap( 1, qRound( position.y() ) - contentsY, markerIcon );
9797- markedRect = QRect( 1, qRound( position.y() ) - contentsY, markerIcon.width(), markerIcon.height() );
9898- }
9999- }
100100-}
101101-102102-NumberedTextView::NumberedTextView( QWidget *parent )
103103- : QFrame( parent )
104104-{
105105- setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
106106- setLineWidth( 2 );
107107-108108- // Setup the main view
109109- view = new QTextEdit( this );
110110- //view->setFontFamily( "Courier" );
111111- view->setLineWrapMode( QTextEdit::NoWrap );
112112- view->setFrameStyle( QFrame::NoFrame );
113113-114114- connect( view->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(textChanged(int,int,int)) );
115115-116116- // Setup the line number pane
117117- numbers = new NumberBar( this );
118118- numbers->setTextEdit( view );
119119-120120- // Test
121121- markLine(2);
122122-123123- //setup layout
124124- box = new QHBoxLayout( this );
125125- box->setSpacing( 0 );
126126- box->setMargin( 0 );
127127- box->addWidget( numbers );
128128- box->addWidget( view );
129129-}
130130-131131-NumberedTextView::~NumberedTextView()
132132-{
133133-}
134134-135135-void NumberedTextView::markLine( int lineno )
136136-{
137137- markedLine = lineno;
138138- numbers->markLine( lineno );
139139- textChanged(1,1,1);
140140-}
141141-142142-void NumberedTextView::scrolltoLine( int lineno )
143143-{
144144- int max = view->verticalScrollBar()->maximum();
145145- int min = view->verticalScrollBar()->minimum();
146146- int lines = view->document()->blockCount();
147147- view->verticalScrollBar()->setValue( (max*lineno)/lines+min );
148148-}
149149-150150-void NumberedTextView::textChanged( int pos, int removed, int added )
151151-{
152152- Q_UNUSED( pos );
153153-154154- if ( removed == 0 && added == 0 )
155155- return;
156156-157157- QTextBlock block = highlight.block();
158158- QTextBlockFormat fmt = block.blockFormat();
159159- QColor bg = view->palette().base().color();
160160- fmt.setBackground( bg );
161161- highlight.setBlockFormat( fmt );
162162-163163- int lineCount = 1;
164164- for ( QTextBlock block = view->document()->begin();
165165- block.isValid(); block = block.next(), ++lineCount )
166166- {
167167- if ( lineCount == markedLine )
168168- {
169169- fmt = block.blockFormat();
170170- QColor bg = Qt::red;
171171- fmt.setBackground( bg.light(150) );
172172-173173- highlight = QTextCursor( block );
174174- highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
175175- highlight.setBlockFormat( fmt );
176176-177177- break;
178178- }
179179- }
180180-}
181181-
-87
utils/wpseditor/gui/src/numberedtextview.h
···11-/* This file is part of the KDE libraries
22- Copyright (C) 2005, 2006 KJSEmbed Authors
33- See included AUTHORS file.
44-55- This library is free software; you can redistribute it and/or
66- modify it under the terms of the GNU Library General Public
77- License as published by the Free Software Foundation; either
88- version 2 of the License, or (at your option) any later version.
99-1010- This library is distributed in the hope that it will be useful,
1111- but WITHOUT ANY WARRANTY; without even the implied warranty of
1212- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1313- Library General Public License for more details.
1414-1515- You should have received a copy of the GNU Library General Public License
1616- along with this library; see the file COPYING.LIB. If not, write to
1717- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1818- Boston, MA 02110-1301, USA.
1919-2020- --------------------------------------------------------------------------------------
2121- Imported into the WPS editor and simplified by Dominik Wenger
2222-2323-*/
2424-2525-2626-#ifndef NUMBERED_TEXT_VIEW_H
2727-#define NUMBERED_TEXT_VIEW_H
2828-2929-#include <QFrame>
3030-#include <QPixmap>
3131-#include <QTextCursor>
3232-3333-class QTextEdit;
3434-class QHBoxLayout;
3535-3636-// Shows the Line numbers
3737-class NumberBar : public QWidget
3838-{
3939- Q_OBJECT
4040-4141-public:
4242- NumberBar( QWidget *parent );
4343- ~NumberBar();
4444-4545- void markLine( int lineno );
4646-4747- void setTextEdit( QTextEdit *edit );
4848- void paintEvent( QPaintEvent *ev );
4949-5050-private:
5151- QTextEdit *edit;
5252- QPixmap markerIcon;
5353- int markedLine;
5454- QRect markedRect;
5555-};
5656-5757-// Shows a QTextEdit with Line numbers
5858-class NumberedTextView : public QFrame
5959-{
6060- Q_OBJECT
6161-6262-public:
6363- NumberedTextView( QWidget *parent = 0 );
6464- ~NumberedTextView();
6565-6666- /** Returns the QTextEdit of the main view. */
6767- QTextEdit *textEdit() const { return view; }
6868-6969- /* marks the line with a icon */
7070- void markLine( int lineno );
7171-7272- void scrolltoLine( int lineno );
7373-7474-private slots:
7575- void textChanged( int pos, int removed, int added );
7676-7777-private:
7878- QTextEdit *view;
7979- NumberBar *numbers;
8080- QHBoxLayout *box;
8181- QTextCursor highlight;
8282- int markedLine;
8383-};
8484-8585-8686-#endif // NUMBERED_TEXT_VIEW_H
8787-
-64
utils/wpseditor/gui/src/qsyntaxer.cpp
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#include <QTextCharFormat>
2323-2424-#include "qsyntaxer.h"
2525-2626-QSyntaxer::QSyntaxer(QTextDocument *parent)
2727- : QSyntaxHighlighter(parent) {
2828- HighlightingRule rule;
2929-3030- hrules[0].pattern = QRegExp("%[^\\| \n<\\?%]{1,2}");
3131- hrules[0].format.setFontWeight(QFont::Bold);
3232- hrules[0].format.setForeground(Qt::darkBlue);
3333-3434-3535- hrules[1].pattern = QRegExp("%[\\?]{1}[^<]{1,2}");
3636- hrules[1].format.setForeground(Qt::darkMagenta);
3737-3838- hrules[2].pattern = QRegExp("(<|>)");
3939- hrules[2].format.setForeground(Qt::red);
4040-4141- hrules[3].pattern = QRegExp("\\|");
4242- hrules[3].format.setForeground(Qt::darkRed);
4343-4444- hrules[4].pattern = QRegExp("#[^\n]*");
4545- hrules[4].format.setForeground(Qt::darkGreen);
4646- hrules[4].format.setFontItalic(true);
4747-}
4848-//
4949-void QSyntaxer::highlightBlock(const QString &text) {
5050- QTextCharFormat wholeText;
5151- wholeText.setFont(QFont("arial",11,QFont::Normal));
5252- setFormat(0,text.length(),wholeText);
5353-5454- foreach (HighlightingRule rule, hrules) {
5555- QRegExp expression(rule.pattern);
5656- int index = text.indexOf(expression);
5757- while (index >= 0) {
5858- int length = expression.matchedLength();
5959- setFormat(index, length, rule.format);
6060- index = text.indexOf(expression, index + length);
6161- }
6262- }
6363-6464-}
-42
utils/wpseditor/gui/src/qsyntaxer.h
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#ifndef QSYNTAXER_H
2323-#define QSYNTAXER_H
2424-//
2525-#include <QSyntaxHighlighter>
2626-2727-class QTextCharFormat;
2828-2929-class QSyntaxer : public QSyntaxHighlighter {
3030- Q_OBJECT
3131- struct HighlightingRule {
3232- QRegExp pattern;
3333- QTextCharFormat format;
3434- };
3535- QMap<int,HighlightingRule> hrules;
3636-public:
3737- QSyntaxer(QTextDocument *parent = 0);
3838-3939-protected:
4040- void highlightBlock(const QString &text);
4141-};
4242-#endif
-62
utils/wpseditor/gui/src/qtrackstate.cpp
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#include "qtrackstate.h"
2323-#include <stdlib.h>
2424-2525-//
2626-QTrackState::QTrackState( )
2727- : QObject() {
2828- memset(&state,0,sizeof(state));
2929- state.title = (char*)"title";
3030- state.artist = (char*)"artist";
3131- state.album = (char*)"album";
3232- state.length = 100;
3333- state.elapsed = 50;
3434-}
3535-3636-void QTrackState::setTitle(const QString& name) {
3737- state.title = new char[name.length()];
3838- strcpy(state.title,name.toAscii());
3939- emit stateChanged(state);
4040-}
4141-4242-void QTrackState::setArtist(const QString& name) {
4343- state.artist = new char[name.length()];
4444- strcpy(state.artist,name.toAscii());
4545- emit stateChanged(state);
4646-}
4747-4848-void QTrackState::setAlbum(const QString& name) {
4949- state.album = new char[name.length()];
5050- strcpy(state.album,name.toAscii());
5151- emit stateChanged(state);
5252-}
5353-5454-void QTrackState::setLength(int le) {
5555- state.length = le;
5656- emit stateChanged(state);
5757-}
5858-5959-void QTrackState::setElapsed(int le) {
6060- state.elapsed = le;
6161- emit stateChanged(state);
6262-}
-75
utils/wpseditor/gui/src/qtrackstate.h
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#ifndef __QTRACKSTATE_H__
2323-#define __QTRACKSTATE_H__
2424-2525-#include "wpsstate.h"
2626-#include <QObject>
2727-2828-class QTrackState : public QObject {
2929- Q_OBJECT
3030- Q_CLASSINFO ( "QTrackState", "Track State" );
3131- Q_PROPERTY ( QString Title READ title WRITE setTitle DESIGNABLE true USER true )
3232- Q_PROPERTY ( QString Artist READ artist WRITE setArtist DESIGNABLE true USER true )
3333- Q_PROPERTY ( QString Album READ album WRITE setAlbum DESIGNABLE true USER true )
3434- Q_PROPERTY ( int Length READ length WRITE setLength DESIGNABLE true USER true )
3535- Q_CLASSINFO("Length", "readOnly=true;value=100");
3636- Q_PROPERTY ( int Elapsed READ elapsed WRITE setElapsed DESIGNABLE true USER true )
3737- Q_CLASSINFO("Elapsed", "minimum=0;maximum=100;value=50");
3838-3939- trackstate state;
4040-4141-public:
4242- QTrackState();
4343-4444-public slots:
4545- QString title() const {
4646- return state.title;
4747- }
4848- void setTitle ( const QString& name );
4949-5050- QString artist() const {
5151- return state.artist;
5252- }
5353- void setArtist ( const QString& name );
5454-5555- QString album() const {
5656- return state.album;
5757- }
5858- void setAlbum ( const QString& name );
5959-6060- int length() const {
6161- return state.length;
6262- }
6363- void setLength ( int l );
6464-6565- int elapsed() const {
6666- return state.elapsed;
6767- }
6868- void setElapsed ( int l );
6969-7070-signals:
7171- void stateChanged ( trackstate state );
7272-7373-};
7474-7575-#endif // __QTRACKSTATE_H__
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#ifndef MAINWINDOWIMPL_H
2323-#define MAINWINDOWIMPL_H
2424-//
2525-#include <QMainWindow>
2626-#include <QActionGroup>
2727-#include <QSignalMapper>
2828-2929-#include "wpsstate.h"
3030-#include "ui_mainwindow.h"
3131-#include "wpsstate.h"
3232-#include "qwpsstate.h"
3333-#include "qtrackstate.h"
3434-#include "qwpsdrawer.h"
3535-3636-class QWpsEditorWindow : public QMainWindow, public Ui::MainWindow {
3737- Q_OBJECT
3838-3939- QWpsState wpsState;
4040- QTrackState trackState;
4141- QPointer<QWpsDrawer> drawer;
4242-4343- QHash<int, QAction*> actAudios;
4444- QActionGroup *actGroupAudios;
4545- QSignalMapper *audiosSignalMapper;
4646-4747- QHash<QString,QAction *> actTargets;
4848- QActionGroup *actGroupTargets;
4949- QSignalMapper *targetsSignalMapper;
5050-5151- int scrollingLine;
5252-protected:
5353- void connectActions();
5454- void postWpsUpdate();
5555-public:
5656- QWpsEditorWindow( QWidget * parent = 0, Qt::WFlags f = 0 );
5757- void logMsg(QString s);
5858-private slots:
5959- void slotOpenWps();
6060- void slotVerboseLevel();
6161- void slotWpsStateChanged(wpsstate);
6262- void slotTrackStateChanged(trackstate);
6363-6464- void slotUpdatePlainWps();
6565- void slotPlainDocModChanged(bool m);
6666- void slotSetTarget(const QString &);
6767-6868-signals:
6969- void signalAudioStatusChanged(int);
7070- void signalSetTarget(const QString &);
7171-7272-};
7373-#endif
7474-7575-7676-7777-7878-7979-
-50
utils/wpseditor/gui/src/qwpsstate.cpp
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#include "qwpsstate.h"
2323-2424-QWpsState::QWpsState(): QObject() {
2525- state.fontheight = 8;
2626- state.fontwidth = 5;
2727- state.volume = -30;
2828- state.battery_level = 50;
2929-3030-}
3131-3232-void QWpsState::setFontHeight(int val) {
3333- state.fontheight = val;
3434- emit stateChanged(state);
3535-}
3636-3737-void QWpsState::setFontWidth(int val) {
3838- state.fontwidth = val;
3939- emit stateChanged(state);
4040-}
4141-4242-void QWpsState::setVolume(int val) {
4343- state.volume = val;
4444- emit stateChanged(state);
4545-}
4646-4747-void QWpsState::setBattery(int val) {
4848- state.battery_level = val;
4949- emit stateChanged(state);
5050-}
-75
utils/wpseditor/gui/src/qwpsstate.h
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#ifndef __WPSSTATE_H__
2323-#define __WPSSTATE_H__
2424-2525-#include <QObject>
2626-#include "wpsstate.h"
2727-2828-class QWpsState : public QObject {
2929- Q_OBJECT
3030-3131-3232- Q_CLASSINFO("QWpsState", "WPS State");
3333- Q_PROPERTY(int FontHeight READ fontHeight WRITE setFontHeight DESIGNABLE true USER true)
3434- Q_CLASSINFO("FontHeight", "minimum=6;maximum=20;value=10");
3535- Q_PROPERTY(int FontWidth READ fontWidth WRITE setFontWidth DESIGNABLE true USER true)
3636- Q_CLASSINFO("FontWidth", "minimum=4;maximum=20;value=8");
3737- Q_PROPERTY(int Volume READ volume WRITE setVolume DESIGNABLE true USER true)
3838- Q_CLASSINFO("Volume", "minimum=-74;maximum=24;value=-15");
3939- Q_PROPERTY(int Battery READ battery WRITE setBattery DESIGNABLE true USER true)
4040- Q_CLASSINFO("Battery", "minimum=0;maximum=100;value=50");
4141-4242- wpsstate state;
4343-4444-public:
4545- QWpsState();
4646-4747- int fontHeight() const {
4848- return state.fontheight;
4949- }
5050- void setFontHeight(int val);
5151-5252- int fontWidth() const {
5353- return state.fontwidth;
5454- }
5555- void setFontWidth(int val);
5656-5757- int battery() const {
5858- return state.battery_level;
5959- }
6060- void setBattery(int val);
6161-6262- int volume() const {
6363- return state.volume;
6464- }
6565-public slots:
6666- void setVolume(int val);
6767-6868-6969-7070-7171-7272-signals:
7373- void stateChanged ( wpsstate state );
7474-};
7575-#endif // __WPSSTATE_H__
-42
utils/wpseditor/gui/src/slider.cpp
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#include "slider.h"
2323-#include <QDebug>
2424-//
2525-Slider::Slider(QWidget *parent, QString caption, int min, int max ):QDialog(parent),mCaption(caption) {
2626- setupUi ( this );
2727- connect(horslider, SIGNAL(valueChanged(int)), this, SIGNAL(valueChanged(int)));
2828- connect(this, SIGNAL(valueChanged(int)), this, SLOT(slotValueChanged(int)));
2929- setWindowTitle(mCaption);
3030- horslider->setMinimum(min);
3131- horslider->setMaximum(max);
3232-}
3333-//
3434-int Slider::value() {
3535- return horslider->value();
3636-}
3737-void Slider::slotValueChanged(int step) {
3838- setWindowTitle(tr("%1 = %2 ").arg(mCaption).arg(step));
3939-}
4040-4141-4242-
-43
utils/wpseditor/gui/src/slider.h
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#ifndef SLIDERIMPL_H
2323-#define SLIDERIMPL_H
2424-//
2525-#include <QWidget>
2626-#include <QDialog>
2727-#include "ui_slider.h"
2828-//
2929-class Slider : public QDialog , Ui::slider {
3030- Q_OBJECT
3131- QString mCaption;
3232-public slots:
3333- void slotValueChanged(int step);
3434-signals:
3535- void valueChanged(int);
3636-public:
3737- Slider(QWidget *parent, QString caption, int min, int max );
3838- int value();
3939-4040-4141-4242-};
4343-#endif
-48
utils/wpseditor/gui/src/utils.cpp
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#include "utils.h"
2323-#include <QPointer>
2424-#include <QtGlobal>
2525-#include "qwpseditorwindow.h"
2626-2727-extern QPointer<QWpsEditorWindow> win;
2828-2929-int qlogger(const char* fmt,...) {
3030- va_list ap;
3131- va_start(ap, fmt);
3232- QString s;
3333- s.vsprintf(fmt,ap);
3434- va_end(ap);
3535- s.replace("\n","");
3636- //qDebug()<<s;
3737- if (win==0)
3838- qDebug()<<s;
3939- if (s.indexOf("ERR")>=0)
4040- s = "<font color=red>"+s+"</font>";
4141- if (win!=0)
4242- win->logMsg(s);
4343- return s.length();
4444-}
4545-4646-int qlogger(const QString& s) {
4747- return qlogger(s.toAscii().data());
4848-}
-34
utils/wpseditor/gui/src/utils.h
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#ifndef __UTILS_H__
2323-#define __UTILS_H__
2424-2525-#include <QDebug>
2626-2727-#define DEBUGF1 qlogger
2828-#define DEBUGF2(...)
2929-#define DEBUGF3 qDebug
3030-3131-extern int qlogger(const char* fmt,...);
3232-extern int qlogger(const QString& s);
3333-3434-#endif // __UTILS_H__
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#define SYSFONT_HEIGHT 9
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#include <stdio.h>
2323-#include <stdlib.h>
2424-#include "dummies.h"
2525-#include "proxy.h"
2626-#include "api.h"
2727-#include "gwps.h"
2828-#include "gwps-common.h"
2929-#include <string.h>
3030-3131-struct screen screens[NB_SCREENS];
3232-struct wps_data wpsdata;
3333-struct gui_wps gwps;
3434-struct mp3entry id3;
3535-struct mp3entry nid3;
3636-3737-extern void test_api(struct proxy_api *api);
3838-3939-bool debug_wps = true;
4040-int wps_verbose_level = 0;
4141-int errno_;
4242-pfdebugf dbgf = 0;
4343-4444-static char pluginbuf[PLUGIN_BUFFER_SIZE];
4545-4646-const char* get_model_name(){
4747-#ifdef MODEL_NAME
4848- return MODEL_NAME;
4949-#else
5050- return "unknown";
5151-#endif
5252-}
5353-5454-int read_line(int fd, char* buffer, int buffer_size)
5555-{
5656- int count = 0;
5757- int num_read = 0;
5858-5959- errno_ = 0;
6060-6161- while (count < buffer_size)
6262- {
6363- unsigned char c;
6464-6565- if (1 != read(fd, &c, 1))
6666- break;
6767-6868- num_read++;
6969-7070- if ( c == '\n' )
7171- break;
7272-7373- if ( c == '\r' )
7474- continue;
7575-7676- buffer[count++] = c;
7777- }
7878-7979- buffer[MIN(count, buffer_size - 1)] = 0;
8080-8181- return errno_ ? -1 : num_read;
8282-}
8383-8484-void* plugin_get_buffer(size_t *buffer_size)
8585-{
8686- *buffer_size = PLUGIN_BUFFER_SIZE;
8787- return pluginbuf;
8888-}
8989-9090-int checkwps(const char *filename, int verbose){
9191- int res;
9292- int fd;
9393-9494- struct wps_data wps;
9595- wps_verbose_level = verbose;
9696-9797- fd = open(filename, O_RDONLY);
9898- if (fd < 0) {
9999- DEBUGF1("Failed to open %s\n",filename);
100100- return 2;
101101- }
102102- close(fd);
103103-104104- res = wps_data_load(&wps, &screens[0], filename, true);
105105-106106- if (!res) {
107107- DEBUGF1("WPS parsing failure\n");
108108- return 3;
109109- }
110110-111111- DEBUGF1("WPS parsed OK\n");
112112- return 0;
113113-}
114114-115115-int wps_init(const char* filename,struct proxy_api *api, bool isfile){
116116- int res;
117117- if (!api)
118118- return 4;
119119- dummies_init();
120120- test_api(api);
121121- set_api(api);
122122- wps_data_init(&wpsdata);
123123- wps_verbose_level = api->verbose;
124124- res = wps_data_load(&wpsdata, &screens[0], filename, isfile);
125125- if (!res)
126126- {
127127- DEBUGF1("ERR: WPS parsing failure\n");
128128- } else
129129- DEBUGF1("WPS parsed OK\n");
130130- DEBUGF1("\n-------------------------------------------------\n");
131131- wps_state.paused = true;
132132- gwps.data = &wpsdata;
133133- gwps.display = &screens[0];
134134- gwps.state = &wps_state;
135135- gwps.state->id3 = &id3;
136136- gwps.state->nid3 = &nid3;
137137- gui_wps[0] = gwps;
138138- return (res?res:3);
139139-}
140140-141141-int wps_display(){
142142- DEBUGF3("wps_display(): begin\n");
143143- int res = gui_wps_display();
144144- DEBUGF3("\nWPS %sdisplayed\n", (res ? "" : "not "));
145145- return res;
146146-}
147147-int wps_refresh(){
148148- DEBUGF3("-----------------<wps_refresh(): begin>-----------------\n");
149149- int res = gui_wps_refresh(&gwps, 0, WPS_REFRESH_ALL);
150150- DEBUGF3("\nWPS %srefreshed\n", (res ? "" : "not "));
151151- return res;
152152-}
-48
utils/wpseditor/libwps/src/proxy.h
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#ifndef PROXY_H
2323-#define PROXY_h
2424-2525-#include <stdio.h>
2626-2727-#include "screen_access.h"
2828-#include "api.h"
2929-#include "defs.h"
3030-3131-#define DEBUGF dbgf
3232-#define DEBUGF1 dbgf
3333-#define DEBUGF2(...)
3434-#define DEBUGF3(...)
3535-#define DEBUGF4(...)
3636-3737-EXPORT int checkwps(const char *filename, int verbose);
3838-EXPORT int wps_init(const char* filename,struct proxy_api *api,bool isfile);
3939-EXPORT int wps_display();
4040-EXPORT int wps_refresh();
4141-EXPORT const char* get_model_name();
4242-4343-extern struct screen screens[NB_SCREENS];
4444-extern bool debug_wps;
4545-extern int wps_verbose_level;
4646-4747-4848-#endif
-55
utils/wpseditor/libwps/src/wpsstate.h
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- *
99- * Copyright (C) 2007 by Rostilav Checkan
1010- * $Id$
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#ifndef STATES_H
2323-#define STATES_H
2424-//
2525-struct trackstate
2626-{
2727- char* title;
2828- char* artist;
2929- char* album;
3030- char* genre_string;
3131- char* disc_string;
3232- char* track_string;
3333- char* year_string;
3434- char* composer;
3535- char* comment;
3636- char* albumartist;
3737- char* grouping;
3838- int discnum;
3939- int tracknum;
4040- int version;
4141- int layer;
4242- int year;
4343-4444- int length;
4545- int elapsed;
4646-};
4747-4848-struct wpsstate{
4949- int volume;
5050- int fontheight;
5151- int fontwidth;
5252- int battery_level;
5353- int audio_status;
5454-};
5555-#endif
···11-/* $Id$ */
22-#ifdef __cplusplus
33-extern "C" {
44-#endif
55-66-/*
77- gd_bmp.c
88-99- Bitmap format support for libgd
1010-1111- * Written 2007, Scott MacVicar
1212- ---------------------------------------------------------------------------
1313-1414- Todo:
1515-1616- RLE4, RLE8 and Bitfield encoding
1717- Add full support for Windows v4 and Windows v5 header formats
1818-1919- ----------------------------------------------------------------------------
2020- */
2121-2222-#ifndef BMP_H
2323-#define BMP_H 1
2424-2525-#define BMP_PALETTE_3 1
2626-#define BMP_PALETTE_4 2
2727-2828-#define BMP_WINDOWS_V3 40
2929-#define BMP_OS2_V1 12
3030-#define BMP_OS2_V2 64
3131-#define BMP_WINDOWS_V4 108
3232-#define BMP_WINDOWS_V5 124
3333-3434-#define BMP_BI_RGB 0
3535-#define BMP_BI_RLE8 1
3636-#define BMP_BI_RLE4 2
3737-#define BMP_BI_BITFIELDS 3
3838-#define BMP_BI_JPEG 4
3939-#define BMP_BI_PNG 5
4040-4141-#define BMP_RLE_COMMAND 0
4242-#define BMP_RLE_ENDOFLINE 0
4343-#define BMP_RLE_ENDOFBITMAP 1
4444-#define BMP_RLE_DELTA 2
4545-4646-#define BMP_RLE_TYPE_RAW 0
4747-#define BMP_RLE_TYPE_RLE 1
4848-4949-/* BMP header. */
5050-typedef struct
5151-{
5252- /* 16 bit - header identifying the type */
5353- signed short int magic;
5454-5555- /* 32bit - size of the file */
5656- int size;
5757-5858- /* 16bit - these two are in the spec but "reserved" */
5959- signed short int reserved1;
6060- signed short int reserved2;
6161-6262- /* 32 bit - offset of the bitmap header from data in bytes */
6363- signed int off;
6464-6565-} bmp_hdr_t;
6666-6767-/* BMP info. */
6868-typedef struct
6969-{
7070- /* 16bit - Type, ie Windows or OS/2 for the palette info */
7171- signed short int type;
7272- /* 32bit - The length of the bitmap information header in bytes. */
7373- signed int len;
7474-7575- /* 32bit - The width of the bitmap in pixels. */
7676- signed int width;
7777-7878- /* 32bit - The height of the bitmap in pixels. */
7979- signed int height;
8080-8181- /* 8 bit - The bitmap data is specified in top-down order. */
8282- signed char topdown;
8383-8484- /* 16 bit - The number of planes. This must be set to a value of one. */
8585- signed short int numplanes;
8686-8787- /* 16 bit - The number of bits per pixel. */
8888- signed short int depth;
8989-9090- /* 32bit - The type of compression used. */
9191- signed int enctype;
9292-9393- /* 32bit - The size of the image in bytes. */
9494- signed int size;
9595-9696- /* 32bit - The horizontal resolution in pixels/metre. */
9797- signed int hres;
9898-9999- /* 32bit - The vertical resolution in pixels/metre. */
100100- signed int vres;
101101-102102- /* 32bit - The number of color indices used by the bitmap. */
103103- signed int numcolors;
104104-105105- /* 32bit - The number of color indices important for displaying the bitmap. */
106106- signed int mincolors;
107107-108108-} bmp_info_t;
109109-110110-#endif
111111-112112-#ifdef __cplusplus
113113-}
114114-#endif
-778
utils/wpseditor/screenshot/gd_bmp.c
···11-/*
22- Stolen from http://cvs.php.net/viewcvs.cgi/gd/playground/gdbmp/
33-*/
44-55-/*
66- gd_bmp.c
77-88- Bitmap format support for libgd
99-1010- * Written 2007, Scott MacVicar
1111- ---------------------------------------------------------------------------
1212-1313- Todo:
1414-1515- Bitfield encoding
1616-1717- ----------------------------------------------------------------------------
1818- */
1919-/* $Id$ */
2020-#ifdef HAVE_CONFIG_H
2121-#include "config.h"
2222-#endif
2323-2424-#include <stdio.h>
2525-#include <math.h>
2626-#include <string.h>
2727-#include <stdlib.h>
2828-#include "gd.h"
2929-#include "bmp.h"
3030-3131-extern void* gdCalloc (size_t nmemb, size_t size);
3232-3333-static int bmp_read_header(gdIOCtxPtr infile, bmp_hdr_t *hdr);
3434-static int bmp_read_info(gdIOCtxPtr infile, bmp_info_t *info);
3535-static int bmp_read_windows_v3_info(gdIOCtxPtr infile, bmp_info_t *info);
3636-static int bmp_read_os2_v1_info(gdIOCtxPtr infile, bmp_info_t *info);
3737-static int bmp_read_os2_v2_info(gdIOCtxPtr infile, bmp_info_t *info);
3838-3939-static int bmp_read_direct(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header);
4040-static int bmp_read_1bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header);
4141-static int bmp_read_4bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header);
4242-static int bmp_read_8bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header);
4343-static int bmp_read_rle(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info);
4444-4545-#if GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION < 1
4646-/* Byte helper functions, since added to GD 2.1 */
4747-static int gdGetIntLSB(signed int *result, gdIOCtx * ctx);
4848-static int gdGetWordLSB(signed short int *result, gdIOCtx * ctx);
4949-#endif
5050-5151-#define BMP_DEBUG(s)
5252-5353-gdImagePtr gdImageCreateFromBmpCtx(gdIOCtxPtr infile);
5454-5555-gdImagePtr gdImageCreateFromBmp(FILE * inFile)
5656-{
5757- gdImagePtr im = 0;
5858- gdIOCtx *in = gdNewFileCtx(inFile);
5959- im = gdImageCreateFromBmpCtx(in);
6060- in->gd_free(in);
6161- return im;
6262-}
6363-6464-gdImagePtr gdImageCreateFromBmpPtr(int size, void *data)
6565-{
6666- gdImagePtr im;
6767- gdIOCtx *in = gdNewDynamicCtxEx(size, data, 0);
6868- im = gdImageCreateFromBmpCtx(in);
6969- in->gd_free(in);
7070- return im;
7171-}
7272-7373-gdImagePtr gdImageCreateFromBmpCtx(gdIOCtxPtr infile)
7474-{
7575- bmp_hdr_t *hdr;
7676- bmp_info_t *info;
7777- gdImagePtr im = NULL;
7878- int error = 0;
7979-8080- if (!(hdr= (bmp_hdr_t *)gdCalloc(1, sizeof(bmp_hdr_t)))) {
8181- return NULL;
8282- }
8383-8484- if (bmp_read_header(infile, hdr)) {
8585- gdFree(hdr);
8686- return NULL;
8787- }
8888-8989- if (hdr->magic != 0x4d42) {
9090- gdFree(hdr);
9191- return NULL;
9292- }
9393-9494- if (!(info = (bmp_info_t *)gdCalloc(1, sizeof(bmp_info_t)))) {
9595- gdFree(hdr);
9696- return NULL;
9797- }
9898-9999- if (bmp_read_info(infile, info)) {
100100- gdFree(hdr);
101101- gdFree(info);
102102- return NULL;
103103- }
104104-105105- BMP_DEBUG(printf("Numcolours: %d\n", info->numcolors));
106106- BMP_DEBUG(printf("Width: %d\n", info->width));
107107- BMP_DEBUG(printf("Height: %d\n", info->height));
108108- BMP_DEBUG(printf("Planes: %d\n", info->numplanes));
109109- BMP_DEBUG(printf("Depth: %d\n", info->depth));
110110- BMP_DEBUG(printf("Offset: %d\n", hdr->off));
111111-112112- if (info->depth >= 16) {
113113- im = gdImageCreateTrueColor(info->width, info->height);
114114- } else {
115115- im = gdImageCreate(info->width, info->height);
116116- }
117117-118118- if (!im) {
119119- gdFree(hdr);
120120- gdFree(info);
121121- return NULL;
122122- }
123123-124124- switch (info->depth) {
125125- case 1:
126126- BMP_DEBUG(printf("1-bit image\n"));
127127- error = bmp_read_1bit(im, infile, info, hdr);
128128- break;
129129- case 4:
130130- BMP_DEBUG(printf("4-bit image\n"));
131131- error = bmp_read_4bit(im, infile, info, hdr);
132132- break;
133133- case 8:
134134- BMP_DEBUG(printf("8-bit image\n"));
135135- error = bmp_read_8bit(im, infile, info, hdr);
136136- break;
137137- case 16:
138138- case 24:
139139- case 32:
140140- BMP_DEBUG(printf("Direct BMP image\n"));
141141- error = bmp_read_direct(im, infile, info, hdr);
142142- break;
143143- default:
144144- BMP_DEBUG(printf("Unknown bit count\n"));
145145- error = 1;
146146- }
147147-148148- gdFree(hdr);
149149- gdFree(info);
150150-151151- if (error) {
152152- gdImageDestroy(im);
153153- return NULL;
154154- }
155155-156156- return im;
157157-}
158158-159159-static int bmp_read_header(gdIOCtx *infile, bmp_hdr_t *hdr)
160160-{
161161- if(
162162- !gdGetWordLSB(&hdr->magic, infile) ||
163163- !gdGetIntLSB(&hdr->size, infile) ||
164164- !gdGetWordLSB(&hdr->reserved1, infile) ||
165165- !gdGetWordLSB(&hdr->reserved2 , infile) ||
166166- !gdGetIntLSB(&hdr->off , infile)
167167- ) {
168168- return 1;
169169- }
170170- return 0;
171171-}
172172-173173-static int bmp_read_info(gdIOCtx *infile, bmp_info_t *info)
174174-{
175175- /* read BMP length so we can work out the version */
176176- if (!gdGetIntLSB(&info->len, infile)) {
177177- return 1;
178178- }
179179-180180- switch (info->len) {
181181- /* For now treat Windows v4 + v5 as v3 */
182182- case BMP_WINDOWS_V3:
183183- case BMP_WINDOWS_V4:
184184- case BMP_WINDOWS_V5:
185185- BMP_DEBUG(printf("Reading Windows Header\n"));
186186- if (bmp_read_windows_v3_info(infile, info)) {
187187- return 1;
188188- }
189189- break;
190190- case BMP_OS2_V1:
191191- if (bmp_read_os2_v1_info(infile, info)) {
192192- return 1;
193193- }
194194- break;
195195- case BMP_OS2_V2:
196196- if (bmp_read_os2_v2_info(infile, info)) {
197197- return 1;
198198- }
199199- break;
200200- default:
201201- BMP_DEBUG(printf("Unhandled bitmap\n"));
202202- return 1;
203203- }
204204- return 0;
205205-}
206206-207207-static int bmp_read_windows_v3_info(gdIOCtxPtr infile, bmp_info_t *info)
208208-{
209209- if (
210210- !gdGetIntLSB(&info->width, infile) ||
211211- !gdGetIntLSB(&info->height, infile) ||
212212- !gdGetWordLSB(&info->numplanes, infile) ||
213213- !gdGetWordLSB(&info->depth, infile) ||
214214- !gdGetIntLSB(&info->enctype, infile) ||
215215- !gdGetIntLSB(&info->size, infile) ||
216216- !gdGetIntLSB(&info->hres, infile) ||
217217- !gdGetIntLSB(&info->vres, infile) ||
218218- !gdGetIntLSB(&info->numcolors, infile) ||
219219- !gdGetIntLSB(&info->mincolors, infile)
220220- ) {
221221- return 1;
222222- }
223223-224224- if (info->height < 0) {
225225- info->topdown = 1;
226226- info->height = -info->height;
227227- } else {
228228- info->topdown = 0;
229229- }
230230-231231- info->type = BMP_PALETTE_4;
232232-233233- if (info->width <= 0 || info->height <= 0 || info->numplanes <= 0 ||
234234- info->depth <= 0 || info->numcolors < 0 || info->mincolors < 0) {
235235- return 1;
236236- }
237237-238238- return 0;
239239-}
240240-241241-static int bmp_read_os2_v1_info(gdIOCtxPtr infile, bmp_info_t *info)
242242-{
243243- if (
244244- !gdGetWordLSB((signed short int *)&info->width, infile) ||
245245- !gdGetWordLSB((signed short int *)&info->height, infile) ||
246246- !gdGetWordLSB(&info->numplanes, infile) ||
247247- !gdGetWordLSB(&info->depth, infile)
248248- ) {
249249- return 1;
250250- }
251251-252252- /* OS2 v1 doesn't support topdown */
253253- info->topdown = 0;
254254-255255- info->numcolors = 1 << info->depth;
256256- info->type = BMP_PALETTE_3;
257257-258258- if (info->width <= 0 || info->height <= 0 || info->numplanes <= 0 ||
259259- info->depth <= 0 || info->numcolors < 0) {
260260- return 1;
261261- }
262262-263263- return 0;
264264-}
265265-266266-static int bmp_read_os2_v2_info(gdIOCtxPtr infile, bmp_info_t *info)
267267-{
268268- char useless_bytes[24];
269269- if (
270270- !gdGetIntLSB(&info->width, infile) ||
271271- !gdGetIntLSB(&info->height, infile) ||
272272- !gdGetWordLSB(&info->numplanes, infile) ||
273273- !gdGetWordLSB(&info->depth, infile) ||
274274- !gdGetIntLSB(&info->enctype, infile) ||
275275- !gdGetIntLSB(&info->size, infile) ||
276276- !gdGetIntLSB(&info->hres, infile) ||
277277- !gdGetIntLSB(&info->vres, infile) ||
278278- !gdGetIntLSB(&info->numcolors, infile) ||
279279- !gdGetIntLSB(&info->mincolors, infile)
280280- ) {
281281- return 1;
282282- }
283283-284284- /* Lets seek the next 24 pointless bytes, we don't care too much about it */
285285- if (!gdGetBuf(useless_bytes, 24, infile)) {
286286- return 1;
287287- }
288288-289289- if (info->height < 0) {
290290- info->topdown = 1;
291291- info->height = -info->height;
292292- } else {
293293- info->topdown = 0;
294294- }
295295-296296- info->type = BMP_PALETTE_4;
297297-298298- if (info->width <= 0 || info->height <= 0 || info->numplanes <= 0 ||
299299- info->depth <= 0 || info->numcolors < 0 || info->mincolors < 0) {
300300- return 1;
301301- }
302302-303303-304304- return 0;
305305-}
306306-307307-static int bmp_read_direct(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header)
308308-{
309309- int ypos = 0, xpos = 0, row = 0;
310310- int padding = 0, alpha = 0, red = 0, green = 0, blue = 0;
311311- signed short int data = 0;
312312-313313- switch(info->enctype) {
314314- case BMP_BI_RGB:
315315- /* no-op */
316316- break;
317317-318318- case BMP_BI_BITFIELDS:
319319- if (info->depth == 24) {
320320- BMP_DEBUG(printf("Bitfield compression isn't supported for 24-bit\n"));
321321- return 1;
322322- }
323323- BMP_DEBUG(printf("Currently no bitfield support\n"));
324324- return 1;
325325- break;
326326-327327- case BMP_BI_RLE8:
328328- if (info->depth != 8) {
329329- BMP_DEBUG(printf("RLE is only valid for 8-bit images\n"));
330330- return 1;
331331- }
332332- case BMP_BI_RLE4:
333333- if (info->depth != 4) {
334334- BMP_DEBUG(printf("RLE is only valid for 4-bit images\n"));
335335- return 1;
336336- }
337337- case BMP_BI_JPEG:
338338- case BMP_BI_PNG:
339339- default:
340340- BMP_DEBUG(printf("Unsupported BMP compression format\n"));
341341- return 1;
342342- }
343343-344344- /* There is a chance the data isn't until later, would be wierd but it is possible */
345345- if (gdTell(infile) != header->off) {
346346- /* Should make sure we don't seek past the file size */
347347- gdSeek(infile, header->off);
348348- }
349349-350350- /* The line must be divisible by 4, else its padded with NULLs */
351351- padding = ((int)(info->depth / 8) * info->width) % 4;
352352- if (padding) {
353353- padding = 4 - padding;
354354- }
355355-356356-357357- for (ypos = 0; ypos < info->height; ++ypos) {
358358- if (info->topdown) {
359359- row = ypos;
360360- } else {
361361- row = info->height - ypos - 1;
362362- }
363363-364364- for (xpos = 0; xpos < info->width; xpos++) {
365365- if (info->depth == 16) {
366366- if (!gdGetWordLSB(&data, infile)) {
367367- return 1;
368368- }
369369- BMP_DEBUG(printf("Data: %X\n", data));
370370- red = ((data & 0x7C00) >> 10) << 3;
371371- green = ((data & 0x3E0) >> 5) << 3;
372372- blue = (data & 0x1F) << 3;
373373- BMP_DEBUG(printf("R: %d, G: %d, B: %d\n", red, green, blue));
374374- } else if (info->depth == 24) {
375375- if (!gdGetByte(&blue, infile) || !gdGetByte(&green, infile) || !gdGetByte(&red, infile)) {
376376- return 1;
377377- }
378378- } else {
379379- if (!gdGetByte(&blue, infile) || !gdGetByte(&green, infile) || !gdGetByte(&red, infile) || !gdGetByte(&alpha, infile)) {
380380- return 1;
381381- }
382382- }
383383- /*alpha = gdAlphaMax - (alpha >> 1);*/
384384- gdImageSetPixel(im, xpos, row, gdTrueColor(red, green, blue));
385385- }
386386- for (xpos = padding; xpos > 0; --xpos) {
387387- if (!gdGetByte(&red, infile)) {
388388- return 1;
389389- }
390390- }
391391- }
392392-393393- return 0;
394394-}
395395-396396-static int bmp_read_palette(gdImagePtr im, gdIOCtxPtr infile, int count, int read_four)
397397-{
398398- int i;
399399- int r, g, b, z;
400400-401401- for (i = 0; i < count; i++) {
402402- if (
403403- !gdGetByte(&r, infile) ||
404404- !gdGetByte(&g, infile) ||
405405- !gdGetByte(&b, infile) ||
406406- (read_four && !gdGetByte(&z, infile))
407407- ) {
408408- return 1;
409409- }
410410- im->red[i] = r;
411411- im->green[i] = g;
412412- im->blue[i] = b;
413413- im->open[i] = 1;
414414- }
415415- return 0;
416416-}
417417-418418-static int bmp_read_1bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header)
419419-{
420420- int ypos = 0, xpos = 0, row = 0, index = 0;
421421- int padding = 0, current_byte = 0, bit = 0;
422422-423423- if (info->enctype != BMP_BI_RGB) {
424424- return 1;
425425- }
426426-427427- if (!info->numcolors) {
428428- info->numcolors = 2;
429429- } else if (info->numcolors < 0 || info->numcolors > 2) {
430430- return 1;
431431- }
432432-433433- if (bmp_read_palette(im, infile, info->numcolors, (info->type == BMP_PALETTE_4))) {
434434- return 1;
435435- }
436436-437437- im->colorsTotal = info->numcolors;
438438-439439- /* There is a chance the data isn't until later, would be wierd but it is possible */
440440- if (gdTell(infile) != header->off) {
441441- /* Should make sure we don't seek past the file size */
442442- gdSeek(infile, header->off);
443443- }
444444-445445- /* The line must be divisible by 4, else its padded with NULLs */
446446- padding = ((int)ceill(0.1 * info->width)) % 4;
447447- if (padding) {
448448- padding = 4 - padding;
449449- }
450450-451451- for (ypos = 0; ypos < info->height; ++ypos) {
452452- if (info->topdown) {
453453- row = ypos;
454454- } else {
455455- row = info->height - ypos - 1;
456456- }
457457-458458- for (xpos = 0; xpos < info->width; xpos += 8) {
459459- /* Bitmaps are always aligned in bytes so we'll never overflow */
460460- if (!gdGetByte(¤t_byte, infile)) {
461461- return 1;
462462- }
463463-464464- for (bit = 0; bit < 8; bit++) {
465465- index = ((current_byte & (0x80 >> bit)) != 0 ? 0x01 : 0x00);
466466- if (im->open[index]) {
467467- im->open[index] = 0;
468468- }
469469- gdImageSetPixel(im, xpos + bit, row, index);
470470- /* No need to read anything extra */
471471- if ((xpos + bit) >= info->width) {
472472- break;
473473- }
474474- }
475475- }
476476-477477- for (xpos = padding; xpos > 0; --xpos) {
478478- if (!gdGetByte(&index, infile)) {
479479- return 1;
480480- }
481481- }
482482- }
483483- return 0;
484484-}
485485-486486-static int bmp_read_4bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header)
487487-{
488488- int ypos = 0, xpos = 0, row = 0, index = 0;
489489- int padding = 0, current_byte = 0;
490490-491491- if (info->enctype != BMP_BI_RGB && info->enctype != BMP_BI_RLE4) {
492492- return 1;
493493- }
494494-495495- if (!info->numcolors) {
496496- info->numcolors = 16;
497497- } else if (info->numcolors < 0 || info->numcolors > 16) {
498498- return 1;
499499- }
500500-501501- if (bmp_read_palette(im, infile, info->numcolors, (info->type == BMP_PALETTE_4))) {
502502- return 1;
503503- }
504504-505505- im->colorsTotal = info->numcolors;
506506-507507- /* There is a chance the data isn't until later, would be wierd but it is possible */
508508- if (gdTell(infile) != header->off) {
509509- /* Should make sure we don't seek past the file size */
510510- gdSeek(infile, header->off);
511511- }
512512-513513- /* The line must be divisible by 4, else its padded with NULLs */
514514- padding = ((int)ceil(0.5 * info->width)) % 4;
515515- if (padding) {
516516- padding = 4 - padding;
517517- }
518518-519519- switch (info->enctype) {
520520- case BMP_BI_RGB:
521521- for (ypos = 0; ypos < info->height; ++ypos) {
522522- if (info->topdown) {
523523- row = ypos;
524524- } else {
525525- row = info->height - ypos - 1;
526526- }
527527-528528- for (xpos = 0; xpos < info->width; xpos += 2) {
529529- if (!gdGetByte(¤t_byte, infile)) {
530530- return 1;
531531- }
532532-533533- index = (current_byte >> 4) & 0x0f;
534534- if (im->open[index]) {
535535- im->open[index] = 0;
536536- }
537537- gdImageSetPixel(im, xpos, row, index);
538538-539539- /* This condition may get called often, potential optimsations */
540540- if (xpos >= info->width) {
541541- break;
542542- }
543543-544544- index = current_byte & 0x0f;
545545- if (im->open[index]) {
546546- im->open[index] = 0;
547547- }
548548- gdImageSetPixel(im, xpos + 1, row, index);
549549- }
550550-551551- for (xpos = padding; xpos > 0; --xpos) {
552552- if (!gdGetByte(&index, infile)) {
553553- return 1;
554554- }
555555- }
556556- }
557557- break;
558558-559559- case BMP_BI_RLE4:
560560- if (bmp_read_rle(im, infile, info)) {
561561- return 1;
562562- }
563563- break;
564564-565565- default:
566566- return 1;
567567- }
568568- return 0;
569569-}
570570-571571-static int bmp_read_8bit(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info, bmp_hdr_t *header)
572572-{
573573- int ypos = 0, xpos = 0, row = 0, index = 0;
574574- int padding = 0;
575575-576576- if (info->enctype != BMP_BI_RGB && info->enctype != BMP_BI_RLE8) {
577577- return 1;
578578- }
579579-580580- if (!info->numcolors) {
581581- info->numcolors = 256;
582582- } else if (info->numcolors < 0 || info->numcolors > 256) {
583583- return 1;
584584- }
585585-586586- if (bmp_read_palette(im, infile, info->numcolors, (info->type == BMP_PALETTE_4))) {
587587- return 1;
588588- }
589589-590590- im->colorsTotal = info->numcolors;
591591-592592- /* There is a chance the data isn't until later, would be wierd but it is possible */
593593- if (gdTell(infile) != header->off) {
594594- /* Should make sure we don't seek past the file size */
595595- gdSeek(infile, header->off);
596596- }
597597-598598- /* The line must be divisible by 4, else its padded with NULLs */
599599- padding = (1 * info->width) % 4;
600600- if (padding) {
601601- padding = 4 - padding;
602602- }
603603-604604- switch (info->enctype) {
605605- case BMP_BI_RGB:
606606- for (ypos = 0; ypos < info->height; ++ypos) {
607607- if (info->topdown) {
608608- row = ypos;
609609- } else {
610610- row = info->height - ypos - 1;
611611- }
612612-613613- for (xpos = 0; xpos < info->width; ++xpos) {
614614- if (!gdGetByte(&index, infile)) {
615615- return 1;
616616- }
617617-618618- if (im->open[index]) {
619619- im->open[index] = 0;
620620- }
621621- gdImageSetPixel(im, xpos, row, index);
622622- }
623623- /* Could create a new variable, but it isn't really worth it */
624624- for (xpos = padding; xpos > 0; --xpos) {
625625- if (!gdGetByte(&index, infile)) {
626626- return 1;
627627- }
628628- }
629629- }
630630- break;
631631-632632- case BMP_BI_RLE8:
633633- if (bmp_read_rle(im, infile, info)) {
634634- return 1;
635635- }
636636- break;
637637-638638- default:
639639- return 1;
640640- }
641641- return 0;
642642-}
643643-644644-static int bmp_read_rle(gdImagePtr im, gdIOCtxPtr infile, bmp_info_t *info)
645645-{
646646- int ypos = 0, xpos = 0, row = 0, index = 0;
647647- int rle_length = 0, rle_data = 0;
648648- int padding = 0;
649649- int i = 0, j = 0;
650650- int pixels_per_byte = 8 / info->depth;
651651-652652- for (ypos = 0; ypos < info->height && xpos <= info->width;) {
653653- if (!gdGetByte(&rle_length, infile) || !gdGetByte(&rle_data, infile)) {
654654- return 1;
655655- }
656656- row = info->height - ypos - 1;
657657-658658- if (rle_length != BMP_RLE_COMMAND) {
659659- if (im->open[rle_data]) {
660660- im->open[rle_data] = 0;
661661- }
662662-663663- for (i = 0; (i < rle_length) && (xpos < info->width);) {
664664- for (j = 1; (j <= pixels_per_byte) && (xpos < info->width) && (i < rle_length); j++, xpos++, i++) {
665665- index = (rle_data & (((1 << info->depth) - 1) << (8 - (j * info->depth)))) >> (8 - (j * info->depth));
666666- if (im->open[index]) {
667667- im->open[index] = 0;
668668- }
669669- gdImageSetPixel(im, xpos, row, index);
670670- }
671671- }
672672- } else if (rle_length == BMP_RLE_COMMAND && rle_data > 2) {
673673- /* Uncompressed RLE needs to be even */
674674- padding = 0;
675675- for (i = 0; (i < rle_data) && (xpos < info->width); i += pixels_per_byte) {
676676- int max_pixels = pixels_per_byte;
677677-678678- if (!gdGetByte(&index, infile)) {
679679- return 1;
680680- }
681681- padding++;
682682-683683- if (rle_data - i < max_pixels) {
684684- max_pixels = rle_data - i;
685685- }
686686-687687- for (j = 1; (j <= max_pixels) && (xpos < info->width); j++, xpos++) {
688688- int temp = (index >> (8 - (j * info->depth))) & ((1 << info->depth) - 1);
689689- if (im->open[temp]) {
690690- im->open[temp] = 0;
691691- }
692692- gdImageSetPixel(im, xpos, row, temp);
693693- }
694694- }
695695-696696- /* Make sure the bytes read are even */
697697- if (padding % 2 && !gdGetByte(&index, infile)) {
698698- return 1;
699699- }
700700- } else if (rle_length == BMP_RLE_COMMAND && rle_data == BMP_RLE_ENDOFLINE) {
701701- /* Next Line */
702702- xpos = 0;
703703- ypos++;
704704- } else if (rle_length == BMP_RLE_COMMAND && rle_data == BMP_RLE_DELTA) {
705705- /* Delta Record, used for bmp files that contain other data*/
706706- if (!gdGetByte(&rle_length, infile) || !gdGetByte(&rle_data, infile)) {
707707- return 1;
708708- }
709709- xpos += rle_length;
710710- ypos += rle_data;
711711- } else if (rle_length == BMP_RLE_COMMAND && rle_data == BMP_RLE_ENDOFBITMAP) {
712712- /* End of bitmap */
713713- break;
714714- }
715715- }
716716- return 0;
717717-}
718718-719719-#if GD_MAJOR_VERSION == 2 && GD_MINOR_VERSION < 1
720720-static int gdGetWordLSB(signed short int *result, gdIOCtx * ctx)
721721-{
722722- unsigned int high = 0, low = 0;
723723- low = (ctx->getC) (ctx);
724724- if (low == EOF) {
725725- return 0;
726726- }
727727-728728- high = (ctx->getC) (ctx);
729729- if (high == EOF) {
730730- return 0;
731731- }
732732-733733- if (result) {
734734- *result = (high << 8) | low;
735735- }
736736-737737- return 1;
738738-}
739739-740740-static int gdGetIntLSB(signed int *result, gdIOCtx * ctx)
741741-{
742742- int c = 0;
743743- unsigned int r = 0;
744744-745745- c = (ctx->getC) (ctx);
746746- if (c == EOF) {
747747- return 0;
748748- }
749749- r |= (c << 24);
750750- r >>= 8;
751751-752752- c = (ctx->getC) (ctx);
753753- if (c == EOF) {
754754- return 0;
755755- }
756756- r |= (c << 24);
757757- r >>= 8;
758758-759759- c = (ctx->getC) (ctx);
760760- if (c == EOF) {
761761- return 0;
762762- }
763763- r |= (c << 24);
764764- r >>= 8;
765765-766766- c = (ctx->getC) (ctx);
767767- if (c == EOF) {
768768- return 0;
769769- }
770770- r |= (c << 24);
771771-772772- if (result) {
773773- *result = (signed int)r;
774774- }
775775-776776- return 1;
777777-}
778778-#endif
-377
utils/wpseditor/screenshot/main.c
···11-/***************************************************************************
22- * __________ __ ___.
33- * Open \______ \ ____ ____ | | _\_ |__ _______ ___
44- * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
55- * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
66- * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
77- * \/ \/ \/ \/ \/
88- * $Id$
99- *
1010- * Copyright (C) 2008 by Maurus Cuelenaere
1111- *
1212- * This program is free software; you can redistribute it and/or
1313- * modify it under the terms of the GNU General Public License
1414- * as published by the Free Software Foundation; either version 2
1515- * of the License, or (at your option) any later version.
1616- *
1717- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1818- * KIND, either express or implied.
1919- *
2020- ****************************************************************************/
2121-2222-#include <stdio.h>
2323-#include <stdarg.h>
2424-#include <string.h>
2525-#include <dlfcn.h>
2626-#include <unistd.h>
2727-#include "gd.h"
2828-#include "gdfonts.h"
2929-#include "api.h"
3030-3131-#define DEBUGF1 _debug
3232-#define DEBUGF2 if(verbose) _debug
3333-3434-#define getFont() gdFontGetSmall()
3535-3636-static struct trackstate mp3data =
3737-{
3838-(char*)"Test title",
3939-(char*)"Test artist",
4040-(char*)"Test album",
4141-(char*)"Test genre",
4242-(char*)"Test disc",
4343-(char*)"Test track",
4444-(char*)"Test year",
4545-(char*)"Test composer",
4646-(char*)"Test comment",
4747-(char*)"Test album artist",
4848-(char*)"Test grouping",
4949-1, /* int discnum */
5050-1, /* int tracknum */
5151-1, /* int version */
5252-1, /* int layer */
5353-2008, /* int year */
5454-5555-100, /* int length */
5656-70 /* int elapsed */
5757-};
5858-5959-static struct wpsstate wpsdata = {-20, -1, -1, 70, API_STATUS_FASTFORWARD};
6060- /* volume, fontheight, fontwidth, battery_level, audio_status */
6161-6262-static struct proxy_api api;
6363-static bool verbose = false;
6464-static int (*wps_init)(const char* buff, struct proxy_api *api, bool isfile);
6565-static int (*wps_display)();
6666-static int (*wps_refresh)();
6767-static gdImagePtr framebuffer;
6868-static gdImagePtr backdrop;
6969-7070-extern gdImagePtr gdImageCreateFromBmp(FILE * inFile);
7171-extern char *get_current_dir_name (void) __THROW;
7272-7373-static bool next_nl = false;
7474-7575-int _debug(const char* fmt,...)
7676-{
7777- va_list ap;
7878-7979- va_start(ap, fmt);
8080-8181- if(!next_nl)
8282- fprintf(stdout, "[DBG] ");
8383-8484- vfprintf(stdout, fmt, ap);
8585-8686- if(fmt[strlen(fmt)-1] != 0xa)
8787- next_nl = true;
8888- else
8989- next_nl = false;
9090-9191- va_end(ap);
9292-9393- return 0;
9494-}
9595-9696-void _putsxy(int x, int y, const unsigned char *str)
9797-{
9898- struct viewport_api avp;
9999- int black = gdImageColorAllocate(framebuffer, 0, 0, 0);
100100-101101- api.get_current_vp(&avp);
102102-103103- gdImageString(framebuffer, getFont(), x + avp.x, y + avp.y - avp.fontheight, (unsigned char*)str, black);
104104-}
105105-106106-void _transparent_bitmap_part(const void *src, int src_x, int src_y,
107107- int stride, int x, int y, int width, int height)
108108-{
109109- FILE *_image;
110110- gdImagePtr image;
111111- int pink;
112112-113113- DEBUGF2("transparent_bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d\n", (char*)src, src_x, src_y, stride, x, y, width, height);
114114-115115- _image = fopen(src, "rb");
116116- if(_image == NULL)
117117- return;
118118-119119- image = gdImageCreateFromBmp(_image);
120120- fclose(_image);
121121-122122- pink = gdTrueColor(255, 0, 255);
123123- gdImageColorTransparent(image, pink);
124124-125125- gdImageCopy(framebuffer, image, x, y, src_x, src_y, width, height);
126126-127127- gdImageDestroy(image);
128128-}
129129-130130-void _bitmap_part(const void *src, int src_x, int src_y,
131131- int stride, int x, int y, int width, int height)
132132-{
133133- FILE *_image;
134134- gdImagePtr image;
135135-136136- DEBUGF2("bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d\n", (char*)src, src_x, src_y, stride, x, y, width, height);
137137-138138- _image = fopen(src, "rb");
139139- if(_image == NULL)
140140- return;
141141-142142- image = gdImageCreateFromBmp(_image);
143143- fclose(_image);
144144-145145- gdImageCopy(framebuffer, image, x, y, src_x, src_y, width, height);
146146-147147- gdImageDestroy(image);
148148-}
149149-150150-void _drawpixel(int x, int y)
151151-{
152152- int black = gdImageColorAllocate(framebuffer, 0, 0, 0);
153153- gdImageSetPixel(framebuffer, x, y, black);
154154-}
155155-156156-void _fillrect(int x, int y, int width, int height)
157157-{
158158- /* Don't draw this as backdrop is used */
159159-#if 0
160160- int black = gdImageColorAllocate(framebuffer, 0, 0, 0);
161161- gdImageFilledRectangle(framebuffer, x, y, x+width, y+height, black);
162162-#endif
163163-}
164164-165165-void _hline(int x1, int x2, int y)
166166-{
167167- int black = gdImageColorAllocate(framebuffer, 0, 0, 0);
168168- gdImageLine(framebuffer, x1, y, x2, y, black);
169169-}
170170-171171-void _vline(int x, int y1, int y2)
172172-{
173173- int black = gdImageColorAllocate(framebuffer, 0, 0, 0);
174174- gdImageLine(framebuffer, x, y1, x, y2, black);
175175-}
176176-177177-void _clear_viewport(int x, int y, int w, int h, int color)
178178-{
179179- if(backdrop == NULL)
180180- return;
181181-182182- gdImageCopy(framebuffer, backdrop, x, y, x, y, w, h);
183183-}
184184-185185-static bool _load_wps_backdrop(char* filename)
186186-{
187187- FILE *image;
188188- if(backdrop != NULL)
189189- gdImageDestroy(backdrop);
190190-191191- DEBUGF2("load backdrop: %s", filename);
192192-193193- image = fopen(filename, "rb");
194194- if(image == NULL)
195195- return false;
196196-197197- backdrop = gdImageCreateFromBmp(image);
198198- fclose(image);
199199-200200- return true;
201201-}
202202-203203-int _read_bmp_file(const char* filename, int *width, int *height)
204204-{
205205- FILE *_image;
206206- gdImagePtr image;
207207-208208- DEBUGF2("load backdrop: %s", filename);
209209-210210- _image = fopen(filename, "rb");
211211- if(_image == NULL)
212212- return 0;
213213-214214- image = gdImageCreateFromBmp(_image);
215215- fclose(_image);
216216-217217- *width = image->sx;
218218- *height = image->sy;
219219-220220- gdImageDestroy(image);
221221-222222- return 1;
223223-}
224224-225225-static void _drawBackdrop()
226226-{
227227- if(backdrop == NULL)
228228- return;
229229-230230- gdImageCopy(framebuffer, backdrop, 0, 0, 0, 0, backdrop->sx, backdrop->sy);
231231-}
232232-233233-static int screenshot(char *model, char *wps, char *png)
234234-{
235235- char lib[255];
236236- void *handle;
237237- FILE *out, *in;
238238- int res;
239239-240240- in = fopen(wps, "rb");
241241- if(in == NULL)
242242- {
243243- fprintf(stderr, "[ERR] Cannot open WPS: %s\n", wps);
244244- return -1;
245245- }
246246- fclose(in);
247247-248248- out = fopen(png, "wb");
249249- if(out == NULL)
250250- {
251251- fprintf(stderr, "[ERR] Cannot open PNG: %s\n", png);
252252- return -2;
253253- }
254254-255255- snprintf(lib, 255, "%s/libwps_%s.so", (char*)get_current_dir_name(), (char*)model);
256256- handle = dlopen(lib, RTLD_LAZY);
257257- if (!handle)
258258- {
259259- fprintf(stderr, "[ERR] Cannot open library: %s\n", dlerror());
260260- fclose(out);
261261- return -3;
262262- }
263263-264264- wps_init = dlsym(handle, "wps_init");
265265- wps_display = dlsym(handle, "wps_display");
266266- wps_refresh = dlsym(handle, "wps_refresh");
267267-268268- if (!wps_init || !wps_display || !wps_refresh)
269269- {
270270- fprintf(stderr, "[ERR] Failed to resolve funcs!");
271271- dlclose(handle);
272272- fclose(out);
273273- return -4;
274274- }
275275-276276- memset(&api, 0, sizeof(struct proxy_api));
277277-278278- if(verbose)
279279- api.verbose = 3;
280280- else
281281- api.verbose = 0;
282282-283283- api.putsxy = &_putsxy;
284284- api.transparent_bitmap_part = &_transparent_bitmap_part;
285285- api.bitmap_part = &_bitmap_part;
286286- api.drawpixel = &_drawpixel;
287287- api.fillrect = &_fillrect;
288288- api.hline = &_hline;
289289- api.vline = &_vline;
290290- api.clear_viewport = &_clear_viewport;
291291- api.load_wps_backdrop = &_load_wps_backdrop;
292292- api.read_bmp_file = &_read_bmp_file;
293293- api.debugf = &_debug;
294294-295295- res = wps_init(wps, &api, true);
296296- if(res != 1)
297297- {
298298- fprintf(stderr, "[ERR] WPS wasn't correctly inited\n");
299299- dlclose(handle);
300300- fclose(out);
301301- return -5;
302302- }
303303-304304- framebuffer = gdImageCreateTrueColor(api.getwidth(), api.getheight());
305305-306306- _drawBackdrop();
307307-308308- fprintf(stdout, "[INFO] Model: %s\n", api.get_model_name());
309309-310310- wpsdata.fontheight = getFont()->h;
311311- wpsdata.fontwidth = getFont()->w;
312312- api.set_wpsstate(wpsdata);
313313- api.set_trackstate(mp3data);
314314- api.set_next_trackstate(mp3data);
315315-316316- _drawBackdrop();
317317- wps_refresh();
318318- gdImagePng(framebuffer, out);
319319-320320- fprintf(stdout, "[INFO] Image written\n");
321321-322322- dlclose(handle);
323323- fclose(out);
324324- gdImageDestroy(framebuffer);
325325- if(backdrop != NULL)
326326- gdImageDestroy(backdrop);
327327-328328- wps_init = NULL;
329329- wps_display = NULL;
330330- wps_refresh = NULL;
331331-332332- return 0;
333333-}
334334-335335-static void usage(void)
336336-{
337337- fprintf(stderr, "Rockbox WPS screenshot utility\n");
338338- fprintf(stderr, "Made by Maurus Cuelenaere\n");
339339- fprintf(stderr, "\n");
340340- fprintf(stderr, "Usage: screenshot [-V] <MODEL> <WPS> <OUT>.png\n");
341341- fprintf(stderr, " -> creates a PNG screenshot of the WPS for the specific MODEL\n");
342342- fprintf(stderr, " -> libwps_<MODEL>.so must be present in the same directory\n");
343343- fprintf(stderr, " -> -V sets verbose mode ON\n");
344344- fprintf(stderr, "\n");
345345- fprintf(stderr, "Example: screenshot IRIVER_H10_5GB iCatcher.wps out.png\n");
346346-}
347347-348348-int main(int argc, char ** argv)
349349-{
350350- if(argc < 4)
351351- {
352352- usage();
353353- return -1;
354354- }
355355-356356- if(argv[1] == NULL || argv[2] == NULL ||
357357- argv[3] == NULL ||
358358- (strcmp(argv[1], "-V") == 0 && argv[4] == NULL)
359359- )
360360- {
361361- usage();
362362- return -1;
363363- }
364364-365365- if(strcmp(argv[1], "-V") == 0)
366366- {
367367- verbose = true;
368368- return screenshot(argv[2], argv[3], argv[4]);
369369- }
370370- else
371371- {
372372- verbose = false;
373373- return screenshot(argv[1], argv[2], argv[3]);
374374- }
375375-376376- return 0;
377377-}