1 /* This file is part of the KDE libraries
2     Copyright (C) 2004,2005,2006 Ian Reinhart Geiser <geiseri@kde.org>
3     Copyright (C) 2004,2005,2006 Matt Broadstone <mbroadst@gmail.com>
4     Copyright (C) 2004,2005,2006 Richard J. Moore <rich@kde.org>
5     Copyright (C) 2004,2005,2006 Erik L. Bunce <kde@bunce.us>
6 
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Library General Public
9     License as published by the Free Software Foundation; either
10     version 2 of the License, or (at your option) any later version.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Library General Public License for more details.
16 
17     You should have received a copy of the GNU Library General Public License
18     along with this library; see the file COPYING.LIB.  If not, write to
19     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20     Boston, MA 02110-1301, USA.
21 */
22 
23 #ifndef KJSEGLOBAL_H
24 #define KJSEGLOBAL_H
25 
26 #include <kjsembed_export.h>
27 #include <qglobal.h>
28 
29 #if !defined(Q_OS_WIN)
30 #include <stdlib.h>
31 #include <ctype.h>
32 
33 namespace KJSEmbed
34 {
35 KJSEMBED_EXPORT void RedirectIOToConsole();
36 }
37 
38 #endif
39 
40 #include <QTextStream>
41 namespace KJSEmbed
42 {
43 KJSEMBED_EXPORT QTextStream *conin();
44 KJSEMBED_EXPORT QTextStream *conout();
45 KJSEMBED_EXPORT QTextStream *conerr();
46 }
47 
48 #include <kjs/ustring.h>
49 #include <kjs/identifier.h>
50 #include <kjs/value.h>
51 
52 namespace KJSEmbed
53 {
toQString(const KJS::UString & u)54 inline QString toQString(const KJS::UString &u)
55 {
56     return QString((QChar *)u.data(), u.size());
57 }
toQString(const KJS::Identifier & i)58 inline QString toQString(const KJS::Identifier &i)
59 {
60     return QString((QChar *)i.data(), i.size());
61 }
toUString(const QString & qs)62 inline KJS::UString toUString(const QString &qs)
63 {
64     return KJS::UString((KJS::UChar *)qs.data(), qs.size());
65 }
66 }
67 
68 namespace KJS
69 {
jsString(const QString & s)70 inline KJS::JSCell *jsString(const QString &s)
71 {
72     return jsString(KJSEmbed::toUString(s));
73 }
74 }
75 
76 #ifndef QT_ONLY
77 
78 /*
79  * These are the normal definitions used when KDE is available.
80  */
81 
82 #include <QDebug>
83 #include <klocalizedstring.h>
84 
85 #else // QT_ONLY
86 
87 /*
88  * These are the custom definitions used when we only have Qt.
89  */
90 
91 KJSEMBED_EXPORT QTextStream &kdDebug(int area = 0);
92 KJSEMBED_EXPORT QTextStream &kdWarning(int area = 0);
93 
94 #ifndef NO_I18N
95 KJSEMBED_EXPORT QString i18n(const char *string);
96 #else
97 #define i18n(x) QString(x)
98 #endif // NO_I18N
99 
i18n(const QString & string,const QString & comment)100 inline KJSEMBED_EXPORT QString i18n(const QString &string, const QString &comment)
101 {
102     return i18n(string.toUtf8().data(), comment.toUtf8().data());
103 }
104 template <typename A1>
i18n(const char * text,const A1 & a1)105 inline QString i18n(const char *text, const A1 &a1)
106 {
107     return i18n(text).arg(a1);
108 }
109 template <typename A1, typename A2>
i18n(const char * text,const A1 & a1,const A2 & a2)110 inline QString i18n(const char *text, const A1 &a1, const A2 &a2)
111 {
112     return i18n(text).arg(a1).arg(a2);
113 }
114 template <typename A1, typename A2, typename A3>
i18n(const char * text,const A1 & a1,const A2 & a2,const A3 & a3)115 inline QString i18n(const char *text, const A1 &a1, const A2 &a2, const A3 &a3)
116 {
117     return i18n(text).arg(a1).arg(a2).arg(a3);
118 }
119 template <typename A1, typename A2, typename A3, typename A4>
i18n(const char * text,const A1 & a1,const A2 & a2,const A3 & a3,const A4 & a4)120 inline QString i18n(const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
121 {
122     return i18n(text).arg(a1).arg(a2).arg(a3).arg(a4);
123 }
124 
125 #endif // QT_ONLY
126 
127 #endif // KJSEGLOBAL_H
128 
129