--Boundary-00=_YmEGDyAiI19vJBN
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

this patch cleans up the implementation of KGlobal by removing all Qt3
dependencies from kglobal.cpp. It also cleans up KDE4 comments in kglobal.h.

--Boundary-00=_YmEGDyAiI19vJBN
Content-Type: text/x-diff;
charset="us-ascii";
name="kdelibs-kglobal.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="kdelibs-kglobal.patch"

Index: kdecore/kglobal.h
================================================== =================
--- kdecore/kglobal.h (revision 456066)
+++ kdecore/kglobal.h (working copy)
@@ -19,8 +19,8 @@
#define _KGLOBAL_H

#include "kdelibs_export.h"
-#include // KDE4: class KInstance is enough here

+class KInstance;
class KCharsets;
class KConfig;
class KSharedConfig;
@@ -93,39 +93,39 @@
* Creates a static QString.
*
* To be used inside functions(!) like:
- * \code
+ * @code
* static const QString &myString = KGlobal::staticQString("myText");
- * \endcode
+ * @endcode
*
- * !!! Do _NOT_ use: !!!
- * \code
+ * @attention Do @b NOT use code such as:
+ * @code
* static QString myString = KGlobal::staticQString("myText");
- * \endcode
+ * @endcode
* This creates a static object (instead of a static reference)
* and as you know static objects are EVIL.
* @param str the string to create
* @return the static string
*/
- static const QString &staticQString(const char *str);
+ static const QString& staticQString(const char *str);

/**
* Creates a static QString.
*
* To be used inside functions(!) like:
- * \code
+ * @code
* static const QString &myString = KGlobal::staticQString(i18n("My Text"));
- * \endcode
+ * @endcode
*
- * !!! Do _NOT_ use: !!!
- * \code
+ * @attention Do @b NOT use code such as:
+ * @code
* static QString myString = KGlobal::staticQString(i18n("myText"));
- * \endcode
+ * @endcode
* This creates a static object (instead of a static reference)
* and as you know static objects are EVIL.
* @param str the string to create
* @return the static string
*/
- static const QString &staticQString(const QString &str);
+ static const QString& staticQString(const QString &str);

/**
* Registers a static deleter.
@@ -172,12 +172,12 @@

/**
* \relates KGlobal
- * A typesafe function to find the minimum of the two arguments.
+ * A typesafe function to find the smaller of the two arguments.
*/
#define KMIN(a,b) kMin(a,b)
/**
* \relates KGlobal
- * A typesafe function to find the maximum of the two arguments.
+ * A typesafe function to find the larger of the two arguments.
*/
#define KMAX(a,b) kMax(a,b)
/**
@@ -188,26 +188,25 @@
/**
* \relates KGlobal
* A typesafe function that returns x if it's between low and high values.
- * low if x is smaller than then low and high if x is bigger than high.
+ * low if x is smaller than low and high if x is bigger than high.
*/
#define KCLAMP(x,low,high) kClamp(x,low,high)

-// XXX KDE4: Make kMin, kMax and kClamp return "T" instead of "const T &"!
template
-inline const T& kMin (const T& a, const T& b) { return a < b ? a : b; }
+inline T kMin (const T& a, const T& b) { return a < b ? a : b; }

template
-inline const T& kMax (const T& a, const T& b) { return b < a ? a : b; }
+inline T kMax (const T& a, const T& b) { return b < a ? a : b; }

template
inline T kAbs (const T& a) { return a < 0 ? -a : a; }

template
-inline const T& kClamp( const T& x, const T& low, const T& high )
+inline T kClamp( const T& x, const T& low, const T& high )
{
if ( x < low ) return low;
else if ( high < x ) return high;
- else return x;
+ return x;
}

/**
Index: kdecore/kglobal.cpp
================================================== =================
--- kdecore/kglobal.cpp (revision 456066)
+++ kdecore/kglobal.cpp (working copy)
@@ -23,8 +23,8 @@
*/

#include
-#include
-#include
+#include
+#include
#include
#include
#include "kglobal.h"
@@ -134,12 +134,21 @@
return staticQString(QString::fromLatin1(str));
}

-class KStringDict : public Q3Dict
+struct KStringDict : protected QHash
{
-public:
- KStringDict() : Q3Dict(139) { };
+ KStringDict() : QHash() { };
+ const QString& add(const QString& str);
};

+const QString& KStringDict::add(const QString& str)
+{
+ uint hash = qHash(str);
+ KStringDict::iterator result = find(hash);
+ if (result == end())
+ result = insert(hash, str);
+ return *result;
+}
+
/**
* Create a static QString
*
@@ -151,51 +160,47 @@
{
if (!_stringDict) {
_stringDict = new KStringDict;
- _stringDict->setAutoDelete( true );
kglobal_init();
}
- QString *result = _stringDict->find(str);
- if (!result)
- {
- result = new QString(str);
- _stringDict->insert(str, result);
- }
- return *result;
+
+ return _stringDict->add(str);
}

-class KStaticDeleterList: public Q3PtrList
+struct KStaticDeleterList: protected QList
{
-public:
KStaticDeleterList() { }
+ ~KStaticDeleterList();
+ void add(KStaticDeleterBase *obj) { if (!contains(obj)) append(obj); }
+ void erase(KStaticDeleterBase *obj) { removeAll(obj); }
};

+KStaticDeleterList::~KStaticDeleterList()
+{
+ while ( !isEmpty() ) {
+ KStaticDeleterBase *ksd = takeFirst();
+ ksd->destructObject();
+ delete ksd;
+ }
+}
+
void
KGlobal::registerStaticDeleter(KStaticDeleterBase *obj)
{
if (!_staticDeleters)
kglobal_init();
- if (_staticDeleters->find(obj) == -1)
- _staticDeleters->append(obj);
+ _staticDeleters->add(obj);
}

void
KGlobal::unregisterStaticDeleter(KStaticDeleterBas e *obj)
{
if (_staticDeleters)
- _staticDeleters->removeRef(obj);
+ _staticDeleters->erase(obj);
}

void
KGlobal::deleteStaticDeleters()
{
- if (!KGlobal::_staticDeleters)
- return;
-
- for(;_staticDeleters->count()
- {
- _staticDeleters->take(0)->destructObject();
- }
-
delete KGlobal::_staticDeleters;
KGlobal::_staticDeleters = 0;
}

--Boundary-00=_YmEGDyAiI19vJBN
Content-Type: text/plain; charset="iso-8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

=

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscrib=

e <<

--Boundary-00=_YmEGDyAiI19vJBN--