summaryrefslogtreecommitdiffstats
path: root/src/common/common
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
commitf508189682b6fba62e08feeb1596f682bad5fff9 (patch)
tree28aeb0e6c19386c385c1ce5edf8a92c1bca15281 /src/common/common
downloadpiklab-f508189682b6fba62e08feeb1596f682bad5fff9.tar.gz
piklab-f508189682b6fba62e08feeb1596f682bad5fff9.zip
Added KDE3 version of PikLab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/common/common')
-rw-r--r--src/common/common/Makefile.am9
-rw-r--r--src/common/common/bitvalue.cpp30
-rw-r--r--src/common/common/bitvalue.h129
-rw-r--r--src/common/common/common.pro6
-rw-r--r--src/common/common/group.cpp71
-rw-r--r--src/common/common/group.h82
-rw-r--r--src/common/common/key_enum.h107
-rw-r--r--src/common/common/lister.h71
-rw-r--r--src/common/common/misc.cpp72
-rw-r--r--src/common/common/misc.h39
-rw-r--r--src/common/common/number.cpp201
-rw-r--r--src/common/common/number.h92
-rw-r--r--src/common/common/purl_base.cpp133
-rw-r--r--src/common/common/purl_base.h79
-rw-r--r--src/common/common/qflags.h81
-rw-r--r--src/common/common/range.h61
-rw-r--r--src/common/common/storage.cpp42
-rw-r--r--src/common/common/storage.h85
-rw-r--r--src/common/common/streamer.h59
-rw-r--r--src/common/common/synchronous.cpp58
-rw-r--r--src/common/common/synchronous.h32
-rw-r--r--src/common/common/version_data.cpp55
-rw-r--r--src/common/common/version_data.h47
23 files changed, 1641 insertions, 0 deletions
diff --git a/src/common/common/Makefile.am b/src/common/common/Makefile.am
new file mode 100644
index 0000000..0f68067
--- /dev/null
+++ b/src/common/common/Makefile.am
@@ -0,0 +1,9 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_LTLIBRARIES = libcommon.la
+libcommon_la_SOURCES = bitvalue.cpp group.cpp misc.cpp number.cpp purl_base.cpp \
+ storage.cpp synchronous.cpp version_data.cpp
+libcommon_la_LDFLAGS = $(all_libraries)
+
+
diff --git a/src/common/common/bitvalue.cpp b/src/common/common/bitvalue.cpp
new file mode 100644
index 0000000..16d5ef0
--- /dev/null
+++ b/src/common/common/bitvalue.cpp
@@ -0,0 +1,30 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "bitvalue.h"
+
+const uint GenericValue::INVALID = 0xFFFFFFFFU;
+
+BitValue BitValue::XORn(uint n) const
+{
+ uint nb = nbBits(_value);
+ uint mask = maxValue(NumberBase::Bin, n);
+ uint res = 0x0;
+ for (uint i=0; i<nb; i +=n) {
+ res ^= (_value >> i) & mask;
+ //qDebug("%i %s %s", i, toHexLabel((value>>i) & mask, 4).latin1(), toHexLabel(res, 4).latin1());
+ }
+ return res;
+}
+
+BitValue BitValue::XNORn(uint n) const
+{
+ BitValue res = XORn(n);
+ BitValue mask = maxValue(NumberBase::Bin, n);
+ return res.complementInMask(mask);
+}
diff --git a/src/common/common/bitvalue.h b/src/common/common/bitvalue.h
new file mode 100644
index 0000000..d3ef9fe
--- /dev/null
+++ b/src/common/common/bitvalue.h
@@ -0,0 +1,129 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef BITVALUE_H
+#define BITVALUE_H
+
+#include "number.h"
+#include "range.h"
+
+//----------------------------------------------------------------------------
+class GenericValue
+{
+public:
+ GenericValue(uint value) : _value(value) {}
+
+ bool operator <(GenericValue v) const { CRASH_ASSERT(_value!=INVALID); return _value<v._value; }
+ bool operator >(GenericValue v) const { CRASH_ASSERT(_value!=INVALID); return _value>v._value; }
+ bool operator <=(GenericValue v) const { CRASH_ASSERT(_value!=INVALID); return _value<=v._value; }
+ bool operator >=(GenericValue v) const { CRASH_ASSERT(_value!=INVALID); return _value>=v._value; }
+ bool operator ==(GenericValue v) const { return _value==v._value; }
+ bool operator !=(GenericValue v) const { return _value!=v._value; }
+
+ bool bit(uint index) const { return (_value >> index) & 0x1; }
+ uchar nybble(uint index) const { return (_value >> (4*index)) & 0xF; }
+ uchar byte(uint index) const { return (_value >> (8*index)) & 0xFF; }
+ uint toUInt() const { return _value; }
+
+protected:
+ static const uint INVALID;
+ uint _value;
+
+private:
+ friend QDataStream &operator <<(QDataStream &s, GenericValue v);
+ friend QDataStream &operator >>(QDataStream &s, GenericValue &v);
+};
+
+inline QDataStream &operator <<(QDataStream &s, GenericValue v) { s << v._value; return s; }
+inline QDataStream &operator >>(QDataStream &s, GenericValue &v) { s >> v._value; return s; }
+
+inline QString toLabel(GenericValue v) { return QString::number(v.toUInt()); }
+inline QString toLabel(NumberBase base, GenericValue v, uint nbChars) { return toLabel(base, v.toUInt(), nbChars); }
+inline QString toHexLabel(GenericValue v, uint nbChars) { return toHexLabel(v.toUInt(), nbChars); }
+inline QString toHex(GenericValue v, uint nbChars) { return toHex(v.toUInt(), nbChars); }
+inline QString toHexLabelAbs(GenericValue v) { return ::toHexLabelAbs(v.toUInt()); }
+
+//----------------------------------------------------------------------------
+class Address : public GenericValue
+{
+public:
+ Address(uint value = INVALID) : GenericValue(value) {}
+ bool isValid() const { return ( _value!=INVALID ); }
+
+ Address &operator ++() { CRASH_ASSERT(_value!=INVALID); _value++; return *this; }
+ Address &operator ++(int) { CRASH_ASSERT(_value!=INVALID); _value++; return *this; }
+ Address operator +(int dec) const { CRASH_ASSERT(_value!=INVALID); return _value + dec; }
+ Address &operator +=(int dec) { CRASH_ASSERT(_value!=INVALID);_value += dec; return *this; }
+ Address &operator --() { CRASH_ASSERT(_value!=INVALID); _value--; return *this; }
+ Address &operator --(int) { CRASH_ASSERT(_value!=INVALID); _value--; return *this; }
+ Address operator -(int dec) const { CRASH_ASSERT(_value!=INVALID);return _value - dec; }
+ Address &operator -=(int dec) { CRASH_ASSERT(_value!=INVALID);_value -= dec; return *this; }
+ int operator -(Address a) const { CRASH_ASSERT(_value!=INVALID && a._value!=INVALID); return _value - a._value; }
+};
+
+class AddressRange : public GenericRange<Address>
+{
+public:
+ AddressRange() {}
+ AddressRange(Address s, Address e) { start = s; end = e; }
+ virtual bool isEmpty() const { return !start.isValid() || !end.isValid() || end<=start; }
+};
+
+typedef GenericRangeVector<Address, AddressRange> AddressRangeVector;
+
+//----------------------------------------------------------------------------
+class BitValue : public GenericValue
+{
+public:
+ BitValue(uint value = INVALID) : GenericValue(value) {}
+ bool isInitialized() const { return ( _value!=INVALID ); }
+
+ BitValue operator |(BitValue v) const { return _value | v._value; }
+ BitValue operator <<(uint shift) const { return _value << shift; }
+ BitValue operator >>(uint shift) const { return _value >> shift; }
+ BitValue operator +(BitValue v) const { return _value + v._value; }
+
+ BitValue &operator |=(BitValue v) { _value |= v._value; return *this; }
+ BitValue &operator <<=(uint shift) { _value <<= shift; return *this; }
+ BitValue &operator >>=(uint shift) { _value >>= shift; return *this; }
+ BitValue &operator +=(BitValue v) { _value += v._value; return *this; }
+
+ BitValue XORn(uint n) const; // XOR between groups of n bits inside value
+ BitValue XNORn(uint n) const; // XORn then NOT on n bits
+
+ BitValue maskWith(BitValue mask) const { return _value & mask._value; }
+ bool isInside(BitValue v) const { return ( (_value & v._value)==_value ); }
+ BitValue complementInMask(BitValue mask) const { return mask._value & ~_value; }
+ BitValue twoComplement() const { return -_value; }
+ BitValue clearMaskBits(BitValue mask) const { return _value & ~mask._value; }
+ bool isOverlapping(BitValue v) const { return ( _value & v._value ); }
+
+ class const_iterator {
+ public:
+ const_iterator() {}
+ bool operator !=(const_iterator it) const { return ( _current!=it._current ); }
+ BitValue operator *() const { return BitValue(_current); }
+ const_iterator &operator ++() {
+ do {
+ if ( _current==_value+1 ) _current = INVALID;
+ if ( _current==INVALID ) break;
+ _current++;
+ } while ( (_current & _value)!=_current );
+ return *this;
+ }
+ private:
+ const_iterator(uint value, uint current) : _value(value), _current(current) {}
+ uint _value, _current;
+ friend class BitValue;
+ };
+ const_iterator begin() const { return const_iterator(_value, 0); }
+ const_iterator end() const { return const_iterator(_value, INVALID); }
+
+};
+
+#endif
diff --git a/src/common/common/common.pro b/src/common/common/common.pro
new file mode 100644
index 0000000..3451c92
--- /dev/null
+++ b/src/common/common/common.pro
@@ -0,0 +1,6 @@
+STOPDIR = ../../..
+include($${STOPDIR}/lib.pro)
+
+TARGET = common
+HEADERS += qflags.h misc.h group.h storage.h synchronous.h purl_base.h number.h bitvalue.h key_enum.h version_data.h
+SOURCES += misc.cpp group.cpp storage.cpp synchronous.cpp purl_base.cpp number.cpp bitvalue.cpp version_data.cpp
diff --git a/src/common/common/group.cpp b/src/common/common/group.cpp
new file mode 100644
index 0000000..2a0610f
--- /dev/null
+++ b/src/common/common/group.cpp
@@ -0,0 +1,71 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "group.h"
+
+//-----------------------------------------------------------------------------
+const Group::Support::Data Group::Support::DATA[Nb_Types] = {
+ { "not_supported", I18N_NOOP("Not Supported") },
+ { "untested", I18N_NOOP("Untested") },
+ { "tested", I18N_NOOP("Tested") }
+};
+
+Group::Base::Base()
+ : _gui(0), _initialized(false)
+{}
+
+Group::Base::ConstIterator Group::Base::begin() const
+{
+ const_cast<Base &>(*this).checkInitSupported();
+ return _devices.begin();
+}
+
+Group::Base::ConstIterator Group::Base::end() const
+{
+ const_cast<Base &>(*this).checkInitSupported();
+ return _devices.end();
+}
+
+void Group::Base::addDevice(const QString &name, const Device::Data *data, Support support)
+{
+ _devices[name].data = data;
+ _devices[name].support = support;
+}
+
+Group::Base::Data Group::Base::deviceData(const QString &device) const
+{
+ const_cast<Base &>(*this).checkInitSupported();
+ return _devices[device];
+}
+
+QValueVector<QString> Group::Base::supportedDevices() const
+{
+ const_cast<Base &>(*this).checkInitSupported();
+ QValueVector<QString> names;
+ for (ConstIterator it=begin(); it!=end(); ++it) names.append(it.key());
+ return names;
+}
+
+uint Group::Base::count() const
+{
+ const_cast<Base &>(*this).checkInitSupported();
+ return _devices.count();
+}
+
+void Group::Base::init()
+{
+ _initialized = false;
+}
+
+void Group::Base::checkInitSupported()
+{
+ if (_initialized) return;
+ _initialized = true;
+ _devices.clear();
+ initSupported();
+}
diff --git a/src/common/common/group.h b/src/common/common/group.h
new file mode 100644
index 0000000..2a87674
--- /dev/null
+++ b/src/common/common/group.h
@@ -0,0 +1,82 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef GROUP_H
+#define GROUP_H
+
+#include <qstringlist.h>
+#include <qmap.h>
+
+#include "common/global/global.h"
+#include "key_enum.h"
+namespace Device { class Data; }
+
+namespace Group
+{
+//-----------------------------------------------------------------------------
+class BaseGui;
+BEGIN_DECLARE_ENUM(Support)
+ None = 0, Untested, Tested
+END_DECLARE_ENUM_STD(Support)
+
+//-----------------------------------------------------------------------------
+class Base
+{
+public:
+ class Data {
+ public:
+ Data() : data(0), support(Support::None) {}
+ const Device::Data *data;
+ Support support;
+ };
+ typedef QMap<QString, Data>::ConstIterator ConstIterator;
+
+ Base();
+ virtual ~Base() {}
+ virtual QString name() const = 0;
+ virtual QString label() const = 0;
+ ConstIterator begin() const;
+ ConstIterator end() const;
+ Data deviceData(const QString &device) const;
+ bool isSupported(const QString &device) const { return deviceData(device).support!=Support::None; }
+ QValueVector<QString> supportedDevices() const;
+ uint count() const;
+ const BaseGui *gui() const { return _gui; }
+ void checkInitSupported();
+
+protected:
+ virtual void init();
+ virtual void addDevice(const QString &name, const Device::Data *data, Support support);
+ virtual void initSupported() = 0;
+
+ QMap<QString, Data> _devices;
+
+private:
+ const BaseGui *_gui;
+ bool _initialized;
+
+ template <class GroupType> friend class Lister;
+};
+
+//-----------------------------------------------------------------------------
+class BaseGui
+{
+public:
+ BaseGui() : _group(0) {}
+ virtual ~BaseGui() {}
+ const Base &group() const { return *_group; }
+
+private:
+ const Base *_group;
+
+ template <class GroupType> friend class Lister;
+};
+
+} // namespace
+
+#endif
diff --git a/src/common/common/key_enum.h b/src/common/common/key_enum.h
new file mode 100644
index 0000000..504ca56
--- /dev/null
+++ b/src/common/common/key_enum.h
@@ -0,0 +1,107 @@
+/***************************************************************************
+ * Copyright (C) 2007 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef KEY_ENUM_H
+#define KEY_ENUM_H
+
+#include <qdatastream.h>
+
+#include "misc.h"
+#include "common/global/global.h"
+
+class GenericEnum
+{
+public:
+ GenericEnum(uint value) : _value(value) {}
+ bool operator ==(GenericEnum e) const { return _value==e._value; }
+ bool operator !=(GenericEnum e) const { return _value!=e._value; }
+ bool operator <(GenericEnum e) const { return _value<e._value; }
+ bool operator <=(GenericEnum e) const { return _value<=e._value; }
+ bool operator >(GenericEnum e) const { return _value>e._value; }
+ bool operator >=(GenericEnum e) const { return _value>=e._value; }
+ GenericEnum &operator ++() { _value++; return *this; }
+
+protected:
+ uint _value;
+
+private:
+ friend QDataStream &operator >>(QDataStream &s, GenericEnum &e);
+ friend QDataStream &operator <<(QDataStream &s, const GenericEnum &e);
+};
+
+inline QDataStream &operator <<(QDataStream &s, const GenericEnum &e)
+{
+ s << e._value;
+ return s;
+}
+inline QDataStream &operator >>(QDataStream &s, GenericEnum &e)
+{
+ s >> e._value;
+ return s;
+}
+
+#define BEGIN_DECLARE_ENUM(Enum) \
+class Enum : public GenericEnum \
+{ \
+public: \
+ enum Type {
+
+#define DECLARE_DATA \
+public: \
+ static Type fromKey(const QString &key) { \
+ for (uint i=0; i<Nb_Types; i++) \
+ if ( key==DATA[i].key ) return Type(i); \
+ return Type(Nb_Types); \
+ } \
+ const Data &data() const { \
+ CRASH_ASSERT( _value!=Nb_Types ); \
+ return DATA[_value]; \
+ } \
+ const char *key() const { \
+ if ( _value==Nb_Types ) return 0; \
+ Q_ASSERT(DATA[_value].key); \
+ return DATA[_value].key; \
+ } \
+ QString label() const { \
+ CRASH_ASSERT( _value!=Nb_Types ); \
+ Q_ASSERT(DATA[_value].label); \
+ return i18n(DATA[_value].label); \
+ } \
+ private: \
+ static const Data DATA[Nb_Types]; \
+
+#define DECLARE_ENUM_CLASS(Enum) \
+public: \
+ Enum(Type value = Type(0)) : GenericEnum(value) { Q_ASSERT( value>=0 && value<=Type(Nb_Types)); } \
+ Type type() const { return Type(_value); } \
+};
+
+#define END_DECLARE_ENUM(Enum, EnumData) \
+ , Nb_Types \
+ }; \
+ typedef EnumData Data; \
+ DECLARE_DATA \
+ DECLARE_ENUM_CLASS(Enum) \
+
+#define END_DECLARE_ENUM_STD(Enum) \
+ , Nb_Types \
+ }; \
+ struct Data { \
+ const char *key, *label; \
+ }; \
+ DECLARE_DATA \
+ DECLARE_ENUM_CLASS(Enum)
+
+#define END_DECLARE_ENUM_NO_DATA(Enum) \
+ , Nb_Types \
+ }; \
+ DECLARE_ENUM_CLASS(Enum)
+
+#define FOR_EACH(Enum, e) for(Enum e; e<Enum::Type(Enum::Nb_Types); ++e)
+
+#endif
diff --git a/src/common/common/lister.h b/src/common/common/lister.h
new file mode 100644
index 0000000..35413e8
--- /dev/null
+++ b/src/common/common/lister.h
@@ -0,0 +1,71 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef LISTER_H
+#define LISTER_H
+
+#include "group.h"
+
+namespace Group
+{
+//-----------------------------------------------------------------------------
+template <class GroupType>
+class Lister
+{
+public:
+ typedef typename QMap<QString, const GroupType *>::ConstIterator ConstIterator;
+ ConstIterator begin() const { return ConstIterator(_groups.begin()); }
+ ConstIterator end() const { return ConstIterator(_groups.end()); }
+
+ virtual ~Lister() {
+ for (ConstIterator it=begin(); it!=end(); ++it) delete it.data();
+ }
+
+ QValueVector<QString> supportedDevices() const {
+ QValueVector<QString> names;
+ for (ConstIterator it=begin(); it!=end(); ++it) {
+ QValueVector<QString> gnames = it.data()->supportedDevices();
+ for (uint k=0; k<uint(gnames.count()); k++) names.append(gnames[k]);
+ }
+ return names;
+ }
+
+ uint count() const {
+ uint nb = 0;
+ for (ConstIterator it=begin(); it!=end(); ++it) nb += it.data()->count();
+ return nb;
+ }
+
+ bool isSupported(const QString &device) const {
+ for (ConstIterator it=begin(); it!=end(); ++it)
+ if ( it.data()->isSupported(device) ) return true;
+ return false;
+ }
+
+ const GroupType *group(const QString &name) const {
+ if ( _groups.contains(name) ) return _groups[name];
+ return 0;
+ }
+
+protected:
+ void addGroup(GroupType *group, BaseGui *gui) {
+ Q_ASSERT(group);
+ group->_gui = gui;
+ if (gui) gui->_group = group;
+ group->init();
+ Q_ASSERT( !_groups.contains(group->name()) );
+ _groups.insert(group->name(), group);
+ }
+
+private:
+ QMap<QString, const GroupType *> _groups;
+};
+
+} // namespace
+
+#endif
diff --git a/src/common/common/misc.cpp b/src/common/common/misc.cpp
new file mode 100644
index 0000000..1974024
--- /dev/null
+++ b/src/common/common/misc.cpp
@@ -0,0 +1,72 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "misc.h"
+
+#include <unistd.h>
+
+#include <qregexp.h>
+#include <qtimer.h>
+
+#include "number.h"
+
+//-----------------------------------------------------------------------------
+uchar bin2bcd(uchar bin)
+{
+ char h = bin / 10;
+ char l = bin % 10;
+ return (h*16) + l;
+}
+
+uchar bcd2bin(uchar bcd)
+{
+ char h = bcd / 16;
+ char l = bcd % 16;
+ return (h*10) + l;
+}
+
+QString escapeXml(const QString &cs)
+{
+ QString s;
+ for (uint i=0; i<uint(cs.length()); i++) {
+ if ( cs[i]=='<' ) s += "&lt;";
+ else if ( cs[i]=='>' ) s += "&gt;";
+ else s += cs[i];
+ }
+ return s;
+}
+
+QString htmlTableRow(const QString &title, const QString &value)
+{
+ return "<tr><td>" + title + ":</td><td>" + value + "</td></tr>";
+}
+
+void crash(const char *assert, const char *file, int line)
+{
+ qDebug("CRASH_ASSERT: \"%s\" in %s (%d)", assert, file, line);
+ int * ptr = 0;
+ (*ptr)++;
+}
+
+bool checkAvailable(const QByteArray &data, uint offset, uint nbBytes)
+{
+ return ( offset+nbBytes<=uint(data.size()) );
+}
+
+Q_UINT32 getULong(const QByteArray &data, uint offset, uint nbBytes, bool *ok)
+{
+ Q_ASSERT( nbBytes<=8 );
+ if ( !checkAvailable(data, offset, nbBytes) ) {
+ if (ok) *ok = false;
+ return 0;
+ }
+ if (ok) *ok = true;
+ Q_UINT32 r = 0;
+ for (uint i=0; i<nbBytes; i++) r += Q_UINT8(data[offset+i]) << (8*i);
+ return r;
+}
diff --git a/src/common/common/misc.h b/src/common/common/misc.h
new file mode 100644
index 0000000..f8f92f6
--- /dev/null
+++ b/src/common/common/misc.h
@@ -0,0 +1,39 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef MISC_H
+#define MISC_H
+
+#include <qstring.h>
+
+inline QString repeat(const char *r, uint nb)
+{
+ QString s;
+ for (uint i=0; i<nb; i++) s += r;
+ return s;
+}
+
+inline QString stripEndingWhiteSpaces(const QString &s) {
+ int k = s.length()-1;
+ for (; k>=0; k--) if ( s[k]!=' ' ) break;
+ return s.mid(0, k+1);
+}
+
+extern uchar bin2bcd(uchar bin);
+extern uchar bcd2bin(uchar bcd);
+inline bool XOR(bool b1, bool b2) { return ( (!b1 && b2) || (b1 && !b2) ); }
+
+extern bool checkAvailable(const QByteArray &data, uint offset, uint nbBytes);
+extern Q_UINT32 getULong(const QByteArray &data, uint offset, uint nbBytes, bool *ok);
+
+extern QString escapeXml(const QString &s);
+extern QString htmlTableRow(const QString &title, const QString &value);
+extern void crash(const char *assert, const char *file, int line);
+#define CRASH_ASSERT(x) ((x) ? void(0) : crash(#x, __FILE__, __LINE__))
+
+#endif
diff --git a/src/common/common/number.cpp b/src/common/common/number.cpp
new file mode 100644
index 0000000..12fcac0
--- /dev/null
+++ b/src/common/common/number.cpp
@@ -0,0 +1,201 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "number.h"
+
+#include "common/global/global.h"
+#include "misc.h"
+#if !defined(NO_KDE)
+# include <kglobal.h>
+#endif
+
+//-----------------------------------------------------------------------------
+const NumberBase::Data NumberBase::DATA[Nb_Types] = {
+ { 10, "", I18N_NOOP("Decimal"), "dec" },
+ { 16, "0x", I18N_NOOP("Hexadecimal"), "hex" },
+ { 2, "0b", I18N_NOOP("Binary"), "bin" },
+ { 8, "o", I18N_NOOP("Octal"), "oct" },
+ { 256, "", I18N_NOOP("String"), "str" }
+};
+
+char toChar(NumberBase base, uint value)
+{
+ Q_ASSERT( value<base.data().base );
+ if ( value>=base.data().base ) qDebug("toChar %u (%u)", value, base.data().base);
+ if ( base==NumberBase::String ) {
+ if ( !isprint(value) ) return '.';
+ return value;
+ }
+ if ( value<=9 ) return '0' + value;
+ return 'A' + value - 10;
+}
+
+QString toString(NumberBase base, ulong value, uint nbChars)
+{
+ ulong tmp = value;
+ QString s;
+ s.fill(0, nbChars);
+ for (uint i=0; i<nbChars; i++) {
+ s[nbChars-i-1] = toChar(base, uint(value % base.data().base));
+ value /= base.data().base;
+ }
+ Q_ASSERT( value==0 );
+ if ( value!=0 ) qDebug("toString %s nbChars=%u", toLabel(base, tmp, ::nbChars(base, tmp)).latin1(), nbChars);
+ return s;
+}
+
+QString toLabel(NumberBase base, ulong value, uint nbChars)
+{
+ if ( base==NumberBase::String ) return "\'" + toString(base, value, nbChars) + "\'";
+ return base.data().prefix + toString(base, value, nbChars);
+}
+
+uint nbChars(NumberBase base, ulong value)
+{
+ uint nb = 1;
+ for (;;) {
+ value /= base.data().base;
+ if ( value==0 ) break;
+ nb++;
+ }
+ return nb;
+}
+
+ulong maxValue(NumberBase base, uint nbChars)
+{
+ uint v = 1;
+ for (uint i=0; i<nbChars; i++) v *= base.data().base;
+ return v - 1;
+}
+
+ulong fromString(NumberBase base, const QCString &s, bool *ok)
+{
+ return fromString(base, s.data(), s.length(), ok);
+}
+ulong fromString(NumberBase base, const QString &s, bool *ok)
+{
+#if QT_VERSION<0x040000
+ return fromString(base, s.latin1(), s.length(), ok);
+#else
+ QByteArray a = s.toLatin1();
+ return fromString(base, a.data(), a.count(), ok);
+#endif
+}
+
+ulong fromLabel(NumberBase base, const QString &s, bool *ok)
+{
+#if QT_VERSION<0x040000
+ return fromLabel(base, s.latin1(), s.length(), ok);
+#else
+ QByteArray a = s.toLatin1();
+ return fromLabel(base, a.data(), a.count(), ok);
+#endif
+}
+
+ulong fromLabel(NumberBase base, const QString &s, uint nbChars, bool *ok)
+{
+ if ( uint(s.length())!=nbChars+strlen(base.data().prefix) ) {
+ if (ok) *ok = false;
+ return 0;
+ }
+ return fromLabel(base, s, ok);
+}
+
+ulong fromLabel(NumberBase base, const char *s, uint size, bool *ok)
+{
+ if (ok) *ok = false;
+ if ( s==0 ) return 0;
+ uint psize = (base==NumberBase::String ? 1 : strlen(base.data().prefix));
+ uint ssize = (base==NumberBase::String ? 1 : 0);
+ if ( size<=(psize+ssize) ) return 0;
+ if ( base==NumberBase::String ) {
+ if ( s[0]=='"' ) {
+ if ( s[size-1]!='"' ) return 0;
+ } else if ( s[0]=='\'' ) {
+ if ( s[size-1]!='\'' ) return 0;
+ } else return 0;
+ } else for (uint i=0; i<psize; i++) if ( s[i]!=base.data().prefix[i] ) return 0;
+ return fromString(base, s+psize, size-psize-ssize, ok);
+}
+
+ulong fromAnyLabel(const QString &s, bool *ok)
+{
+ uint v = 0;
+ bool bok = false;
+ FOR_EACH(NumberBase, base) {
+ v = fromLabel(base, s.lower(), &bok);
+ if (bok) break;
+ }
+ if ( !bok ) v = fromString(NumberBase::Dec, s, &bok);
+ if ( !bok ) {
+ if (ok) *ok = false;
+ return 0;
+ }
+ if (ok) *ok = true;
+ return v;
+}
+
+uint fromChar(NumberBase base, char c, bool *ok)
+{
+ uint v = 0;
+ if ( base==NumberBase::String ) {
+ if (ok) *ok = true;
+ return c;
+ }
+ if ( c>='0' && c<='9' ) v = c - '0';
+ else if ( c>='A' && c<'Z' ) v = 10 + c - 'A';
+ else if ( c>='a' && c<'z' ) v = 10 + c - 'a';
+ else {
+ if (ok) *ok = false;
+ return 0;
+ }
+ if (ok) *ok = ( v<base.data().base );
+ return v;
+}
+
+ulong fromString(NumberBase base, const char *s, uint size, bool *ok)
+{
+ if (ok) *ok = false;
+ if ( s==0 || size==0 ) return 0;
+ ulong v = 0;
+ for (uint i=0; i<size; i++) {
+ v *= base.data().base;
+ bool bok;
+ v += fromChar(base, s[i], &bok);
+ if ( !bok ) return 0;
+ }
+ if (ok) *ok = true;
+ return v;
+}
+
+QString toLabels(NumberBase base, const QMemArray<uint> &values, uint nbChars)
+{
+ QString s = "[";
+ for (uint i=0; i<values.count(); i++) {
+ if ( i!=0 ) s += ' ';
+ s += toLabel(base, values[i], nbChars);
+ }
+ s += "]";
+ return s;
+}
+
+QString formatNumber(ulong v)
+{
+#if defined(NO_KDE)
+ return QString::number(v);
+#else
+ return KGlobal::locale()->formatNumber(v, 0);
+#endif
+}
+
+QByteArray toAscii(const QString &s)
+{
+ QByteArray a(s.length());
+ for (uint i=0; i<uint(s.length()); i++) a[i] = s[i].latin1();
+ return a;
+}
diff --git a/src/common/common/number.h b/src/common/common/number.h
new file mode 100644
index 0000000..f4dae79
--- /dev/null
+++ b/src/common/common/number.h
@@ -0,0 +1,92 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef NUMBER_H
+#define NUMBER_H
+
+#include <ctype.h>
+
+#include "common/global/global.h"
+#include "key_enum.h"
+
+//----------------------------------------------------------------------------
+struct NumberBaseData {
+ uint base;
+ const char *prefix, *label,* key;
+};
+
+BEGIN_DECLARE_ENUM(NumberBase)
+ Dec = 0, Hex, Bin, Oct, String
+END_DECLARE_ENUM(NumberBase, NumberBaseData)
+
+extern uint nbChars(NumberBase base, ulong value);
+extern ulong maxValue(NumberBase base, uint nbChars);
+inline uint convertNbChars(uint nb, NumberBase from, NumberBase to) { return nbChars(to, maxValue(from, nb)); }
+
+extern char toChar(NumberBase base, uint value);
+extern QString toString(NumberBase base, ulong value, uint nbChars);
+extern QString toLabel(NumberBase base, ulong value, uint nbChars);
+extern QString toLabels(NumberBase base, const QMemArray<ulong> &values, uint nbChars);
+
+extern uint fromChar(NumberBase base, char c, bool *ok);
+extern ulong fromString(NumberBase base, const char *s, uint size, bool *ok);
+extern ulong fromString(NumberBase base, const QString &s, bool *ok);
+extern ulong fromLabel(NumberBase base, const QString &s, bool *ok);
+extern ulong fromLabel(NumberBase base, const QString &s, uint nbChars, bool *ok);
+extern ulong fromLabel(NumberBase base, const char *s, uint size, bool *ok);
+
+extern ulong fromAnyLabel(const QString &s, bool *ok);
+
+//----------------------------------------------------------------------------
+inline QString toHex(ulong value, uint nbChars) { return toString(NumberBase::Hex, value, nbChars); }
+inline QString toHexLabel(ulong value, uint nbChars) { return toLabel(NumberBase::Hex, value, nbChars); }
+inline QString toHexLabelAbs(ulong value) { return toLabel(NumberBase::Hex, value, nbChars(NumberBase::Hex, value)); }
+
+inline uint fromHex(char c, bool *ok) { return fromChar(NumberBase::Hex, c, ok); }
+inline uint fromHex(QChar c, bool *ok) { return fromChar(NumberBase::Hex, c.latin1(), ok); }
+inline ulong fromHex(const char *s, uint size, bool *ok) { return fromString(NumberBase::Hex, s, size, ok); }
+inline ulong fromHex(const QString &s, bool *ok) { return fromString(NumberBase::Hex, s, ok); }
+inline ulong fromHexLabel(const QString &s, bool *ok) { return fromLabel(NumberBase::Hex, s, ok); }
+inline ulong fromHexLabel(const QString &s, uint nbChars, bool *ok) { return fromLabel(NumberBase::Hex, s, nbChars, ok); }
+inline ulong fromHexLabel(const char *s, uint size, bool *ok) { return fromLabel(NumberBase::Hex, s, size, ok); }
+
+//----------------------------------------------------------------------------
+inline uint nbBits(ulong value) { return nbChars(NumberBase::Bin, value); }
+inline uint nbBitsToNbChars(uint nbBits) { return nbBits/4 + (nbBits%4 ? 1 : 0); }
+inline uint nbBitsToNbBytes(uint nbBits) { return nbBits/8 + (nbBits%8 ? 1 : 0); }
+inline uint nbChars(ulong value) { return nbBitsToNbChars(nbBits(value)); }
+inline uint nbBytes(ulong value) { return nbBitsToNbBytes(nbBits(value)); }
+
+//----------------------------------------------------------------------------
+extern QString formatNumber(ulong v);
+extern QByteArray toAscii(const QString &s);
+
+//----------------------------------------------------------------------------
+enum PrintMode { PrintAlphaNum, PrintEscapeAll };
+inline QString toPrintable(char c, PrintMode mode)
+{
+ if ( mode==PrintAlphaNum && isalnum(c) ) return QChar(c);
+ return "\\" + toHex(uchar(c), 2);
+}
+inline QString toPrintable(const char *data, uint size, PrintMode mode)
+{
+ QString s;
+ for (uint i=0; i<size; i++) s += toPrintable(data[i], mode);
+ return s;
+}
+inline QString toPrintable(const QString &s, PrintMode mode)
+{
+ QByteArray a = toAscii(s);
+ return toPrintable(a.data(), a.count(), mode);
+}
+inline QString toPrintable(const QMemArray<uchar> &data, PrintMode mode)
+{
+ return toPrintable((const char *)data.data(), data.size(), mode);
+}
+
+#endif
diff --git a/src/common/common/purl_base.cpp b/src/common/common/purl_base.cpp
new file mode 100644
index 0000000..2493322
--- /dev/null
+++ b/src/common/common/purl_base.cpp
@@ -0,0 +1,133 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "purl_base.h"
+
+#include "common/global/global.h"
+#include <qfileinfo.h>
+
+#include "data/xpms/project.xpm"
+#include "data/xpms/sourcefile.xpm"
+#include "data/xpms/includefile.xpm"
+#include "data/xpms/objectfile.xpm"
+
+const PURL::ToolType::Data PURL::ToolType::DATA[Nb_Types] = {
+ { "assembler", I18N_NOOP("Assembler") },
+ { "compiler", I18N_NOOP("Compiler") }
+};
+
+const PURL::SourceFamily::Data PURL::SourceFamily::DATA[Nb_Types] = {
+ { ToolType::Assembler, "asm", I18N_NOOP("Assembler"), Inc },
+ { ToolType::Compiler, "c", I18N_NOOP("C Compiler"), CHeader },
+ { ToolType::Compiler, "jal", I18N_NOOP("JAL Compiler"), Nb_FileTypes },
+ { ToolType::Compiler, "cpp", I18N_NOOP("C++ Compiler"), CHeader },
+ { ToolType::Compiler, "basic", I18N_NOOP("Basic Compiler"), Nb_FileTypes }
+};
+
+const PURL::FileType::Data PURL::FileType::DATA[Nb_Types] = {
+ { "AsmGPAsm", Source, Editable, SourceFamily::Asm, I18N_NOOP("Assembler File"), { "asm", "src", "pic", 0 }, sourcefile_xpm, 0, "XPicAsm" },
+ { "AsmPIC30", Source, Editable, SourceFamily::Asm, I18N_NOOP("Assembler File for PIC30"), { "s", 0 }, sourcefile_xpm, 0, "XPicAsm" },
+ { "AsmPICC", Source, Editable, SourceFamily::Asm, I18N_NOOP("Assembler File for PICC"), { "as", 0 }, sourcefile_xpm, 0, "XPicAsm" },
+ { "Inc", Header, Editable, SourceFamily::Asm, I18N_NOOP("Include File"), { "inc", 0 }, includefile_xpm, 0, "XPicAsm" },
+ { "CSource", Source, Editable, SourceFamily::C, I18N_NOOP("C Source File"), { "c", 0 }, 0, "text/x-csrc", "C" },
+ { "CppSource", Source, Editable, SourceFamily::C, I18N_NOOP("C++ Source File"), { "cpp", "cxx", 0 }, 0, "text/x-c++src", "C++" },
+ { "CHeader", Header, Editable, SourceFamily::C, I18N_NOOP("C Header File"), { "h", 0 }, 0, "text/x-chdr", "C" },
+ { "JalSource", Source, Editable, SourceFamily::JAL, I18N_NOOP("JAL File"), { "jal", 0}, sourcefile_xpm, 0, "XPicJal" },
+ { "BasicSource", Source, Editable, SourceFamily::Basic, I18N_NOOP("Basic Source File"), { "bas", 0 }, sourcefile_xpm, 0, "FreeBASIC" },
+
+ { "Object", LinkerObject, Editable | ReadOnly, SourceFamily::Nb_Types, I18N_NOOP("Object File"), { "o", "obj", 0 }, objectfile_xpm, 0, 0 },
+ { "Library", LinkerObject, Editable | ReadOnly, SourceFamily::Nb_Types, I18N_NOOP("Library File"), { "a", "lib", 0 }, objectfile_xpm, 0, 0 },
+
+ { "Lkr", LinkerScript, Editable, SourceFamily::Nb_Types, I18N_NOOP("Linker Script"), { "lkr", 0 }, includefile_xpm, 0, 0 },
+ { "Gld", LinkerScript, Editable, SourceFamily::Nb_Types, I18N_NOOP("Linker Script for PIC30"), { "gld", 0 }, includefile_xpm, 0, 0 },
+
+ { "Hex", Nb_FileGroups, Editable, SourceFamily::Nb_Types, I18N_NOOP("Hex File"), { "hex", 0 }, 0, "text/x-hex", 0 },
+ { "Elf", Nb_FileGroups, ReadOnly, SourceFamily::Nb_Types, I18N_NOOP("Elf File"), { "elf", 0 }, 0, 0, 0 },
+ { "Project", Nb_FileGroups, NoProperty, SourceFamily::Nb_Types, I18N_NOOP("Project File"), { "piklab", 0 }, project_xpm, 0, 0 },
+ { "Lst", Nb_FileGroups, Editable | ReadOnly, SourceFamily::Nb_Types, I18N_NOOP("List File"), { "lst", 0 }, 0, "text/plain", 0 },
+ { "Map", Nb_FileGroups, Editable | ReadOnly, SourceFamily::Nb_Types, I18N_NOOP("Map File"), { "map", 0 }, 0, "text/plain", 0 },
+ { "Cod", Nb_FileGroups, ReadOnly, SourceFamily::Nb_Types, I18N_NOOP("COD File"), { "cod", 0 }, 0, 0, 0 },
+ { "Coff", Nb_FileGroups, Editable | ReadOnly, SourceFamily::Nb_Types, I18N_NOOP("COFF File"), { "cof", 0 }, 0, "application/x-object", "XCoffDisasm" },
+
+ { "", Nb_FileGroups, NoProperty, SourceFamily::Nb_Types, I18N_NOOP("Unknown File"), { 0 }, 0, 0, 0 },
+ { "", Nb_FileGroups, NoProperty, SourceFamily::Nb_Types, I18N_NOOP("Pikdev Project File"), { "pikprj", 0 }, 0, 0, 0 }
+};
+
+QString PURL::addExtension(const QString &filename, FileType type)
+{
+ QFileInfo info(filename);
+ if ( !info.extension().isEmpty() ) return filename;
+ return filename + '.' + extension(type);
+}
+
+QString PURL::extension(FileType type)
+{
+ return type.data().extensions[0];
+}
+
+QString PURL::extensions(FileType type)
+{
+ Q_ASSERT( type!=PURL::Nb_FileTypes );
+ QString s;
+ for (uint i=0; type.data().extensions[i]; i++) {
+ if ( i!=0 ) s += ' ';
+ s += QString("*.") + type.data().extensions[i];
+ }
+ return s;
+}
+
+QString PURL::filter(FileType type)
+{
+ //if ( hasMimetype(type) ) return DATA[type].mimetype; // #### we cannot mix mimetype and regular filters in KFileDialog...
+ QString s = extensions(type);
+ return s + ' ' + s.upper() + '|' + type.label() + " (" + s + ")";
+}
+
+QString PURL::extensions(FileGroup group)
+{
+ QString e;
+ FOR_EACH(FileType, type) {
+ if ( type.data().group!=group ) continue;
+ if ( type!=FileType::Type(0) ) e += ' ';
+ QString s = extensions(type);
+ e += s + ' ' + s.upper();
+ }
+ return e;
+}
+
+QString PURL::sourceFilter(FilterType type)
+{
+ QString f = extensions(Source) + ' ' + extensions(Header) + '|' + i18n("All Source Files");
+ if ( type==CompleteFilter) {
+ FOR_EACH(FileType, type) {
+ if ( !(type.data().properties & (Source | Header)) ) continue;
+ f += '\n' + filter(type);
+ }
+ }
+ return f;
+}
+
+QString PURL::objectFilter(FilterType type)
+{
+ QString f = extensions(Object) + ' ' + extensions(Library) + '|' + i18n("All Object Files");
+ if ( type==CompleteFilter ) {
+ f += '\n' + filter(Object);
+ f += '\n' + filter(Library);
+ }
+ return f;
+}
+
+QString PURL::projectFilter(FilterType type)
+{
+ QString f = extensions(Project) + ' ' + extensions(PikdevProject) + '|' + i18n("Project Files");
+ if ( type==CompleteFilter ) {
+ f += '\n' + filter(Project);
+ f += '\n' + filter(PikdevProject);
+ }
+ return f;
+}
diff --git a/src/common/common/purl_base.h b/src/common/common/purl_base.h
new file mode 100644
index 0000000..7a7e4ea
--- /dev/null
+++ b/src/common/common/purl_base.h
@@ -0,0 +1,79 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef PURL_BASE_H
+#define PURL_BASE_H
+
+#include "common/global/global.h"
+#include "common/common/key_enum.h"
+
+//----------------------------------------------------------------------------
+namespace PURL
+{
+BEGIN_DECLARE_ENUM(ToolType)
+ Assembler = 0, Compiler
+END_DECLARE_ENUM_STD(ToolType)
+
+enum FileTypeEnum {
+ AsmGPAsm = 0, AsmPIC30, AsmPICC, Inc, CSource, CppSource, CHeader, JalSource, BasicSource,
+ Object, Library, Lkr, Gld, Hex, Elf, Project, Lst, Map, Cod, Coff,
+ Unknown, PikdevProject,
+ Nb_FileTypes
+};
+
+struct SourceFamilyData {
+ ToolType toolType;
+ const char *key, *label;
+ FileTypeEnum headerType;
+};
+BEGIN_DECLARE_ENUM(SourceFamily)
+ Asm = 0, C, JAL, Cpp, Basic
+END_DECLARE_ENUM(SourceFamily, SourceFamilyData)
+
+enum FileGroup { Source = 0, Header, LinkerScript, LinkerObject, Nb_FileGroups };
+
+enum FileProperty { NoProperty = 0, Editable = 1, ReadOnly = 2 };
+Q_DECLARE_FLAGS(FileProperties, FileProperty)
+Q_DECLARE_OPERATORS_FOR_FLAGS(FileProperties)
+
+struct FileTypeData {
+ const char *key;
+ FileGroup group;
+ FileProperties properties;
+ SourceFamily sourceFamily;
+ const char *label;
+ const char *extensions[10];
+ const char **xpm_icon;
+ const char *mimetype;
+ const char *highlightModeName;
+};
+#ifndef Q_MOC_RUN // needed because MOC does not expand defines...
+class FileType : public GenericEnum
+{
+public:
+ typedef FileTypeEnum Type;
+ enum { Nb_Types = Nb_FileTypes };
+ typedef FileTypeData Data;
+DECLARE_DATA
+DECLARE_ENUM_CLASS(FileType)
+#endif
+
+// add correct extension if filename has no extension
+extern QString addExtension(const QString &filename, FileType type);
+extern QString extension(FileType type);
+extern QString extensions(FileType type);
+extern QString filter(FileType type);
+enum FilterType { SimpleFilter, CompleteFilter };
+extern QString sourceFilter(FilterType type);
+extern QString objectFilter(FilterType type);
+extern QString projectFilter(FilterType type);
+extern QString extensions(FileGroup group);
+
+} // namespace
+
+#endif
diff --git a/src/common/common/qflags.h b/src/common/common/qflags.h
new file mode 100644
index 0000000..4858ce4
--- /dev/null
+++ b/src/common/common/qflags.h
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** This file may be used under the terms of the GNU General Public
+** License version 2.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of
+** this file. Please review the following information to ensure GNU
+** General Public Licensing requirements will be met:
+** http://www.trolltech.com/products/qt/opensource.html
+**
+** If you are unsure which license is appropriate for your use, please
+** review the following information:
+** http://www.trolltech.com/products/qt/licensing.html or contact the
+** sales department at sales@trolltech.com.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+****************************************************************************/
+#ifndef QFLAGS_H
+#define QFLAGS_H
+
+#include <qglobal.h>
+
+class QFlag
+{
+ int i;
+public:
+ inline QFlag(int i);
+ inline operator int() const { return i; }
+};
+
+inline QFlag::QFlag(int ai) : i(ai) {}
+
+template<typename Enum>
+class QFlags
+{
+ typedef void **Zero;
+ int i;
+public:
+ typedef Enum enum_type;
+ inline QFlags(const QFlags &f) : i(f.i) {}
+ inline QFlags(Enum f) : i(f) {}
+ inline QFlags(Zero = 0) : i(0) {}
+ inline QFlags(QFlag f) : i(f) {}
+
+ inline QFlags &operator=(const QFlags &f) { i = f.i; return *this; }
+ inline QFlags &operator&=(int mask) { i &= mask; return *this; }
+ inline QFlags &operator&=(uint mask) { i &= mask; return *this; }
+ inline QFlags &operator|=(QFlags f) { i |= f.i; return *this; }
+ inline QFlags &operator|=(Enum f) { i |= f; return *this; }
+ inline QFlags &operator^=(QFlags f) { i ^= f.i; return *this; }
+ inline QFlags &operator^=(Enum f) { i ^= f; return *this; }
+
+
+ inline operator int() const { return i;}
+
+ inline QFlags operator|(QFlags f) const { QFlags g; g.i = i | f.i; return g; }
+ inline QFlags operator|(Enum f) const { QFlags g; g.i = i | f; return g; }
+ inline QFlags operator^(QFlags f) const { QFlags g; g.i = i ^ f.i; return g; }
+ inline QFlags operator^(Enum f) const { QFlags g; g.i = i ^ f; return g; }
+ inline QFlags operator&(int mask) const { QFlags g; g.i = i & mask; return g; }
+ inline QFlags operator&(uint mask) const { QFlags g; g.i = i & mask; return g; }
+ inline QFlags operator&(Enum f) const { QFlags g; g.i = i & f; return g; }
+ inline QFlags operator~() const { QFlags g; g.i = ~i; return g; }
+
+ inline bool operator!() const { return !i; }
+};
+
+#define Q_DECLARE_FLAGS(Flags, Enum)\
+typedef QFlags<Enum> Flags;
+#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags) \
+inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, Flags::enum_type f2) \
+{ return QFlags<Flags::enum_type>(f1) | f2; } \
+inline QFlags<Flags::enum_type> operator|(Flags::enum_type f1, QFlags<Flags::enum_type> f2) \
+{ return f2 | f1; }
+
+#endif
diff --git a/src/common/common/range.h b/src/common/common/range.h
new file mode 100644
index 0000000..e07cb68
--- /dev/null
+++ b/src/common/common/range.h
@@ -0,0 +1,61 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef RANGE_H
+#define RANGE_H
+
+#include "common/global/global.h"
+
+//-----------------------------------------------------------------------------
+template <typename Type>
+class GenericRange
+{
+public:
+ virtual ~GenericRange() {}
+ virtual bool isEmpty() const = 0;
+ bool contains(Type v) const { return !isEmpty() && v>=start && v<=end; }
+
+ Type start, end;
+};
+
+class Range : public GenericRange<uint>
+{
+public:
+ Range() { start = 0; end = 0; }
+ Range(uint s, uint e) { start = s; end = e; }
+ virtual bool isEmpty() const { return end<=start; }
+};
+
+template <typename Type>
+inline QDataStream &operator >>(QDataStream &s, GenericRange<Type> &r) { s >> r.start >> r.end; return s; }
+template <typename Type>
+inline QDataStream &operator <<(QDataStream &s, const GenericRange<Type> &r) { s << r.start << r.end; return s; }
+template <typename Type>
+inline bool operator ==(const GenericRange<Type> &r1, const GenericRange<Type> &r2) { return ( r1.start==r2.start && r1.end==r2.end ); }
+
+template <typename Type, typename RangeType>
+class GenericRangeVector : public QValueVector<RangeType>
+{
+public:
+ GenericRangeVector() {}
+ GenericRangeVector(const RangeType &range) { append(range); }
+ bool isEmpty() const {
+ uint nb = this->count();
+ for (uint i=0; i<nb; i++) if ( !this->at(i).isEmpty() ) return false;
+ return true;
+ }
+ bool contains(Type v) const {
+ uint nb = this->count();
+ for (uint i=0; i<nb; i++) if ( this->at(i).contains(v) ) return true;
+ return false;
+ }
+};
+
+typedef GenericRangeVector<uint, Range> RangeVector;
+
+#endif
diff --git a/src/common/common/storage.cpp b/src/common/common/storage.cpp
new file mode 100644
index 0000000..00137b8
--- /dev/null
+++ b/src/common/common/storage.cpp
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "storage.h"
+
+#include <qtimer.h>
+
+//----------------------------------------------------------------------------
+void GenericStorage::delayedChanged()
+{
+ if (_dirty) return;
+ _dirty = true;
+ QTimer::singleShot(0, this, SLOT(changedSlot()));
+}
+
+void GenericStorage::changedSlot()
+{
+ _dirty = false;
+ emit changed();
+}
+
+//----------------------------------------------------------------------------
+void GenericViewProxy::addStorage(GenericStorage &storage)
+{
+ connect(&storage, SIGNAL(changed()), SLOT(changed()));
+}
+
+void GenericViewProxy::changed()
+{
+ _view.updateView();
+}
+
+GenericView::GenericView(GenericStorage &storage)
+{
+ _proxy = new GenericViewProxy(*this);
+ _proxy->addStorage(storage);
+}
diff --git a/src/common/common/storage.h b/src/common/common/storage.h
new file mode 100644
index 0000000..b61123a
--- /dev/null
+++ b/src/common/common/storage.h
@@ -0,0 +1,85 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef STORAGE_H
+#define STORAGE_H
+
+#include "common/global/global.h"
+#include <qobject.h>
+
+//-----------------------------------------------------------------------------
+template <class Type>
+class Fifo
+{
+public:
+ Fifo() {}
+ void clear() { _list.clear(); }
+ uint count() const { return _list.count(); }
+ void put(Type type) { _list.append(type); }
+ Type get() {
+ Type t = _list.first();
+ _list.pop_front();
+ return t;
+ }
+
+private:
+ QValueList<Type> _list;
+};
+
+//----------------------------------------------------------------------------
+class GenericStorage : public QObject
+{
+Q_OBJECT
+public:
+ GenericStorage(QObject *parent = 0, const char *name = 0) : QObject(parent, name), _dirty(false) {}
+
+signals:
+ void changed();
+
+protected:
+ // emit changed() only after a return to the GUI loop and only one time
+ void delayedChanged();
+
+private slots:
+ void changedSlot();
+
+private:
+ bool _dirty;
+};
+
+//----------------------------------------------------------------------------
+class GenericView;
+
+class GenericViewProxy : public QObject
+{
+Q_OBJECT
+public:
+ GenericViewProxy(GenericView &view) : _view(view) {}
+ void addStorage(GenericStorage &storage);
+
+private slots:
+ void changed();
+
+private:
+ GenericView &_view;
+};
+
+class GenericView
+{
+public:
+ GenericView(GenericStorage &storage);
+ virtual ~GenericView() { delete _proxy; }
+ virtual void updateView() = 0;
+
+private:
+ GenericViewProxy *_proxy;
+
+ friend class GenericViewProxy;
+};
+
+#endif
diff --git a/src/common/common/streamer.h b/src/common/common/streamer.h
new file mode 100644
index 0000000..93d1421
--- /dev/null
+++ b/src/common/common/streamer.h
@@ -0,0 +1,59 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef STREAMER_H
+#define STREAMER_H
+
+#include <qdatastream.h>
+#include <qtextstream.h>
+
+#include "common/global/global.h"
+#include "common/common/number.h"
+
+template <class DataType>
+class DataStreamer
+{
+public:
+ uint toCppString(const QValueList<DataType *> &list, QTextStream &s) {
+ QByteArray a;
+#if QT_VERSION<0x040000
+ QDataStream ds(a, IO_WriteOnly);
+#else
+ QDataStream ds(&a, QIODevice::WriteOnly);
+#endif
+ for (uint i=0; i<uint(list.count()); i++) ds << *list[i];
+ s << "\"";
+ for (uint i=0; i<uint(a.count()); i++) {
+ if ( i!=0 && (i%40)==0 ) s << "\"" << endl << "\"";
+ s << "\\x" << toChar(NumberBase::Hex, uchar(a[i])/16) << toChar(NumberBase::Hex, uchar(a[i])%16);
+ }
+ s << "\"";
+ return a.count();
+ }
+
+ QValueList<DataType *> fromCppString(const char *data, uint size) {
+ QByteArray a;
+ a.setRawData(data, size);
+#if QT_VERSION<0x040000
+ QDataStream ds(a, IO_ReadOnly);
+#else
+ QDataStream ds(&a, QIODevice::ReadOnly);
+#endif
+ QValueList<DataType *> list;
+ for (;;) {
+ if ( ds.atEnd() ) break;
+ DataType *data = new DataType;
+ ds >> *data;
+ list.append(data);
+ }
+ a.resetRawData(data, size);
+ return list;
+ }
+};
+
+#endif
diff --git a/src/common/common/synchronous.cpp b/src/common/common/synchronous.cpp
new file mode 100644
index 0000000..f392103
--- /dev/null
+++ b/src/common/common/synchronous.cpp
@@ -0,0 +1,58 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "synchronous.h"
+
+#include "common/global/global.h"
+#if QT_VERSION<0x040000
+# include <qwidget.h>
+#endif
+
+Synchronous::Synchronous(uint timeout)
+{
+ connect(&_timer, SIGNAL(timeout()), SLOT(done()));
+ if (timeout) _timer.start(timeout, true);
+#if QT_VERSION>=0x040000
+ _loop = new QEventLoop(this);
+#endif
+}
+
+#if QT_VERSION<0x040000
+// uplifted from kdelibs...
+void qt_enter_modal(QWidget *widget);
+void qt_leave_modal(QWidget *widget);
+#endif
+
+bool Synchronous::enterLoop()
+{
+#if QT_VERSION<0x040000
+ QWidget *dummy = 0;
+ if ( qApp->type()!=QApplication::Tty ) {
+ dummy = new QWidget(0, 0, WType_Dialog | WShowModal);
+ dummy->setFocusPolicy(QWidget::NoFocus);
+ qt_enter_modal(dummy);
+ }
+ QApplication::eventLoop()->enterLoop();
+ if ( qApp->type()!=QApplication::Tty ) {
+ qt_leave_modal(dummy);
+ delete dummy;
+ }
+#else
+ _loop->exec();
+#endif
+ return _timer.isActive();
+}
+
+void Synchronous::done()
+{
+#if QT_VERSION<0x040000
+ QApplication::eventLoop()->exitLoop();
+#else
+ _loop->exit();
+#endif
+}
diff --git a/src/common/common/synchronous.h b/src/common/common/synchronous.h
new file mode 100644
index 0000000..e855e38
--- /dev/null
+++ b/src/common/common/synchronous.h
@@ -0,0 +1,32 @@
+/***************************************************************************
+ * Copyright (C) 2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef SYNCHRONOUS_H
+#define SYNCHRONOUS_H
+
+#include <qtimer.h>
+#include <qeventloop.h>
+
+class Synchronous : public QObject
+{
+Q_OBJECT
+public:
+ Synchronous(uint timeout = 0); // timeout is ms (0 == no timeout)
+ bool enterLoop(); // return false on timeout
+
+public slots:
+ void done();
+
+private:
+ QTimer _timer;
+#if QT_VERSION>=0x040000
+ QEventLoop *_loop;
+#endif
+};
+
+#endif
diff --git a/src/common/common/version_data.cpp b/src/common/common/version_data.cpp
new file mode 100644
index 0000000..481ba1a
--- /dev/null
+++ b/src/common/common/version_data.cpp
@@ -0,0 +1,55 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "version_data.h"
+
+#include <qregexp.h>
+
+#include "number.h"
+
+VersionData VersionData::fromString(const QString &s)
+{
+ VersionData vd;
+ QRegExp re("([0-9]+)\\.([0-9]+)\\.([0-9]+)(.*)");
+ if ( !re.exactMatch(s) ) return vd;
+ vd._valid = true;
+ vd._majorNum = re.cap(1).toUInt();
+ vd._minorNum = re.cap(2).toUInt();
+ vd._dotNum = re.cap(3).toUInt();
+ vd._sub = re.cap(4);
+ return vd;
+}
+
+VersionData VersionData::fromHexString(const QString &s)
+{
+ VersionData vd;
+ if ( s.length()!=6 ) return vd;
+ vd._valid = true;
+ vd._majorNum = ::fromString(NumberBase::Hex, s.mid(0, 2), 0);
+ vd._minorNum = ::fromString(NumberBase::Hex, s.mid(2, 2), 0);
+ vd._dotNum = ::fromString(NumberBase::Hex, s.mid(4, 2), 0);
+ return vd;
+}
+
+QString VersionData::pretty() const
+{
+ if ( !isValid() ) return "---";
+ return QString::number(_majorNum) + '.' + QString::number(_minorNum) + '.' + QString::number(_dotNum) + _sub;
+}
+
+QString VersionData::prettyWithoutDot() const
+{
+ if ( !isValid() ) return "---";
+ return QString::number(_majorNum) + '.' + QString::number(_minorNum);
+}
+
+uint VersionData::toUInt() const
+{
+ Q_ASSERT(_valid);
+ return (_majorNum << 16) | (_minorNum << 8) | _dotNum;
+}
diff --git a/src/common/common/version_data.h b/src/common/common/version_data.h
new file mode 100644
index 0000000..2571631
--- /dev/null
+++ b/src/common/common/version_data.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#ifndef VERSION_DATA_H
+#define VERSION_DATA_H
+
+#include "common/global/global.h"
+
+class VersionData
+{
+public:
+ static VersionData fromString(const QString &s);
+ static VersionData fromHexString(const QString &s);
+
+public:
+ VersionData() : _valid(false) {}
+ VersionData(uchar majorNum, uchar minorNum, uchar dotNum)
+ : _valid(true), _majorNum(majorNum), _minorNum(minorNum), _dotNum(dotNum) {}
+ bool isValid() const { return _valid; }
+ void clear() { _valid = false; }
+ uchar majorNum() const { return _majorNum; }
+ uchar minorNum() const { return _minorNum; }
+ uchar dotNum() const { return _dotNum; }
+ QString sub() const { return _sub; }
+ VersionData toWithoutDot() const { return VersionData(_majorNum, _minorNum, 0); }
+ QString pretty() const;
+ QString prettyWithoutDot() const;
+ uint toUInt() const;
+ bool operator <(const VersionData &vd) const { return toUInt()<vd.toUInt(); }
+ bool operator <=(const VersionData &vd) const { return toUInt()<=vd.toUInt(); }
+ bool operator >(const VersionData &vd) const { return toUInt()>vd.toUInt(); }
+ bool operator >=(const VersionData &vd) const { return toUInt()>=vd.toUInt(); }
+ bool operator ==(const VersionData &vd) const { return toUInt()==vd.toUInt(); }
+ bool operator !=(const VersionData &vd) const { return toUInt()!=vd.toUInt(); }
+
+private:
+ bool _valid;
+ uchar _majorNum, _minorNum, _dotNum;
+ QString _sub;
+};
+
+#endif