author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /microkde/kdecore | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | microkde/kdecore/kcatalogue.cpp | 4 | ||||
-rw-r--r-- | microkde/kdecore/kconfigbase.h | 4 | ||||
-rw-r--r-- | microkde/kdecore/klibloader.cpp | 29 | ||||
-rw-r--r-- | microkde/kdecore/klibloader.h | 10 | ||||
-rw-r--r-- | microkde/kdecore/klocale.cpp | 23 | ||||
-rw-r--r-- | microkde/kdecore/klocale.h | 4 | ||||
-rw-r--r-- | microkde/kdecore/kmdcodec.cpp | 139 | ||||
-rw-r--r-- | microkde/kdecore/kmdcodec.h | 38 | ||||
-rw-r--r-- | microkde/kdecore/kprefs.cpp | 16 | ||||
-rw-r--r-- | microkde/kdecore/kprefs.h | 10 | ||||
-rw-r--r-- | microkde/kdecore/kshortcut.h | 8 | ||||
-rw-r--r-- | microkde/kdecore/kstandarddirs.cpp | 24 | ||||
-rw-r--r-- | microkde/kdecore/kstandarddirs.h | 10 |
13 files changed, 167 insertions, 152 deletions
diff --git a/microkde/kdecore/kcatalogue.cpp b/microkde/kdecore/kcatalogue.cpp index 97ac326..1600b08 100644 --- a/microkde/kdecore/kcatalogue.cpp +++ b/microkde/kdecore/kcatalogue.cpp | |||
@@ -1,54 +1,56 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (c) 2001 Hans Petter Bieker <bieker@kde.org> | 2 | Copyright (c) 2001 Hans Petter Bieker <bieker@kde.org> |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | //US #include <config.h> | 20 | //US #include <config.h> |
21 | 21 | ||
22 | #include <qfile.h> | 22 | #include <qfile.h> |
23 | //Added by qt3to4: | ||
24 | #include <Q3CString> | ||
23 | 25 | ||
24 | #include <kdebug.h> | 26 | #include <kdebug.h> |
25 | 27 | ||
26 | #include "kcatalogue.h" | 28 | #include "kcatalogue.h" |
27 | 29 | ||
28 | char *k_nl_find_msg(struct kde_loaded_l10nfile *domain_file, | 30 | char *k_nl_find_msg(struct kde_loaded_l10nfile *domain_file, |
29 | const char *msgid); | 31 | const char *msgid); |
30 | void k_nl_unload_domain (struct loaded_domain *domain); | 32 | void k_nl_unload_domain (struct loaded_domain *domain); |
31 | 33 | ||
32 | #ifndef KDE_USE_FINAL // with --enable-final, we're getting this from libintl.cpp | 34 | #ifndef KDE_USE_FINAL // with --enable-final, we're getting this from libintl.cpp |
33 | struct kde_loaded_l10nfile | 35 | struct kde_loaded_l10nfile |
34 | { | 36 | { |
35 | const char *filename; | 37 | const char *filename; |
36 | int decided; | 38 | int decided; |
37 | 39 | ||
38 | const void *data; | 40 | const void *data; |
39 | 41 | ||
40 | kde_loaded_l10nfile() : filename(0), decided(0), data(0) {} | 42 | kde_loaded_l10nfile() : filename(0), decided(0), data(0) {} |
41 | }; | 43 | }; |
42 | #endif | 44 | #endif |
43 | 45 | ||
44 | class KCataloguePrivate | 46 | class KCataloguePrivate |
45 | { | 47 | { |
46 | public: | 48 | public: |
47 | QString name; | 49 | QString name; |
48 | 50 | ||
49 | kde_loaded_l10nfile domain; | 51 | kde_loaded_l10nfile domain; |
50 | }; | 52 | }; |
51 | 53 | ||
52 | KCatalogue::KCatalogue(const QString & name) | 54 | KCatalogue::KCatalogue(const QString & name) |
53 | : d( new KCataloguePrivate ) | 55 | : d( new KCataloguePrivate ) |
54 | { | 56 | { |
@@ -59,65 +61,65 @@ KCatalogue::KCatalogue(const KCatalogue & rhs) | |||
59 | : d( new KCataloguePrivate ) | 61 | : d( new KCataloguePrivate ) |
60 | { | 62 | { |
61 | *this = rhs; | 63 | *this = rhs; |
62 | } | 64 | } |
63 | 65 | ||
64 | KCatalogue & KCatalogue::operator=(const KCatalogue & rhs) | 66 | KCatalogue & KCatalogue::operator=(const KCatalogue & rhs) |
65 | { | 67 | { |
66 | d->name = rhs.d->name; | 68 | d->name = rhs.d->name; |
67 | setFileName( rhs.fileName() ); | 69 | setFileName( rhs.fileName() ); |
68 | 70 | ||
69 | return *this; | 71 | return *this; |
70 | } | 72 | } |
71 | 73 | ||
72 | KCatalogue::~KCatalogue() | 74 | KCatalogue::~KCatalogue() |
73 | { | 75 | { |
74 | doUnload(); | 76 | doUnload(); |
75 | 77 | ||
76 | delete d; | 78 | delete d; |
77 | } | 79 | } |
78 | 80 | ||
79 | QString KCatalogue::name() const | 81 | QString KCatalogue::name() const |
80 | { | 82 | { |
81 | return d->name; | 83 | return d->name; |
82 | } | 84 | } |
83 | 85 | ||
84 | void KCatalogue::setFileName( const QString & fileName ) | 86 | void KCatalogue::setFileName( const QString & fileName ) |
85 | { | 87 | { |
86 | // nothing to do if the file name is already the same | 88 | // nothing to do if the file name is already the same |
87 | if ( this->fileName() == fileName ) return; | 89 | if ( this->fileName() == fileName ) return; |
88 | 90 | ||
89 | doUnload(); | 91 | doUnload(); |
90 | 92 | ||
91 | QCString newFileName = QFile::encodeName( fileName ); | 93 | Q3CString newFileName = QFile::encodeName( fileName ); |
92 | 94 | ||
93 | if ( !fileName.isEmpty() ) | 95 | if ( !fileName.isEmpty() ) |
94 | { | 96 | { |
95 | // set file name | 97 | // set file name |
96 | char *filename = new char[ newFileName.length() + 1 ]; | 98 | char *filename = new char[ newFileName.length() + 1 ]; |
97 | ::qstrcpy( filename, newFileName ); | 99 | ::qstrcpy( filename, newFileName ); |
98 | d->domain.filename = filename; | 100 | d->domain.filename = filename; |
99 | } | 101 | } |
100 | } | 102 | } |
101 | 103 | ||
102 | QString KCatalogue::fileName() const | 104 | QString KCatalogue::fileName() const |
103 | { | 105 | { |
104 | return QFile::decodeName( d->domain.filename ); | 106 | return QFile::decodeName( d->domain.filename ); |
105 | } | 107 | } |
106 | 108 | ||
107 | const char * KCatalogue::translate(const char * msgid) const | 109 | const char * KCatalogue::translate(const char * msgid) const |
108 | { | 110 | { |
109 | qDebug("KCatalogue::translate has to be fixed %s",msgid ); | 111 | qDebug("KCatalogue::translate has to be fixed %s",msgid ); |
110 | //US return ::k_nl_find_msg( &d->domain, msgid ); | 112 | //US return ::k_nl_find_msg( &d->domain, msgid ); |
111 | return msgid; | 113 | return msgid; |
112 | 114 | ||
113 | } | 115 | } |
114 | 116 | ||
115 | void KCatalogue::doUnload() | 117 | void KCatalogue::doUnload() |
116 | { | 118 | { |
117 | // use gettext's unloader | 119 | // use gettext's unloader |
118 | if ( d->domain.data ) | 120 | if ( d->domain.data ) |
119 | { | 121 | { |
120 | //US ::k_nl_unload_domain( (struct loaded_domain *)d->domain.data ); | 122 | //US ::k_nl_unload_domain( (struct loaded_domain *)d->domain.data ); |
121 | qDebug("KCatalogue::doUnload has to be fixed" ); | 123 | qDebug("KCatalogue::doUnload has to be fixed" ); |
122 | 124 | ||
123 | } | 125 | } |
diff --git a/microkde/kdecore/kconfigbase.h b/microkde/kdecore/kconfigbase.h index 7e56d11..1ef6a04 100644 --- a/microkde/kdecore/kconfigbase.h +++ b/microkde/kdecore/kconfigbase.h | |||
@@ -1,102 +1,104 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the KDE libraries | 2 | This file is part of the KDE libraries |
3 | Copyright (c) 1999 Preston Brown <pbrown@kde.org> | 3 | Copyright (c) 1999 Preston Brown <pbrown@kde.org> |
4 | Copyright (c) 1997 Matthias Kalle Dalheimer <kalle@kde.org> | 4 | Copyright (c) 1997 Matthias Kalle Dalheimer <kalle@kde.org> |
5 | Copyright (c) 2001 Waldo Bastian <bastian@kde.org> | 5 | Copyright (c) 2001 Waldo Bastian <bastian@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 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 | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | // $Id$ | 23 | // $Id$ |
24 | 24 | ||
25 | #ifndef _KCONFIGBASE_H | 25 | #ifndef _KCONFIGBASE_H |
26 | #define _KCONFIGBASE_H | 26 | #define _KCONFIGBASE_H |
27 | 27 | ||
28 | #include "kconfig.h" | 28 | #include "kconfig.h" |
29 | //Added by qt3to4: | ||
30 | #include <Q3CString> | ||
29 | 31 | ||
30 | /** | 32 | /** |
31 | * Helper class to facilitate working with @ref KConfig / @ref KSimpleConfig | 33 | * Helper class to facilitate working with @ref KConfig / @ref KSimpleConfig |
32 | * groups. | 34 | * groups. |
33 | * | 35 | * |
34 | * Careful programmers always set the group of a | 36 | * Careful programmers always set the group of a |
35 | * @ref KConfig @ref KSimpleConfig object to the group they want to read from | 37 | * @ref KConfig @ref KSimpleConfig object to the group they want to read from |
36 | * and set it back to the old one of afterwards. This is usually | 38 | * and set it back to the old one of afterwards. This is usually |
37 | * written as: | 39 | * written as: |
38 | * <pre> | 40 | * <pre> |
39 | * | 41 | * |
40 | * QString oldgroup config->group(); | 42 | * QString oldgroup config->group(); |
41 | * config->setGroup( "TheGroupThatIWant" ); | 43 | * config->setGroup( "TheGroupThatIWant" ); |
42 | * ... | 44 | * ... |
43 | * config->writeEntry( "Blah", "Blubb" ); | 45 | * config->writeEntry( "Blah", "Blubb" ); |
44 | * | 46 | * |
45 | * config->setGroup( oldgroup ); | 47 | * config->setGroup( oldgroup ); |
46 | * </pre> | 48 | * </pre> |
47 | * | 49 | * |
48 | * In order to facilitate this task, you can use | 50 | * In order to facilitate this task, you can use |
49 | * KConfigGroupSaver. Simply construct such an object ON THE STACK | 51 | * KConfigGroupSaver. Simply construct such an object ON THE STACK |
50 | * when you want to switch to a new group. Then, when the object goes | 52 | * when you want to switch to a new group. Then, when the object goes |
51 | * out of scope, the group will automatically be restored. If you | 53 | * out of scope, the group will automatically be restored. If you |
52 | * want to use several different groups within a function or method, | 54 | * want to use several different groups within a function or method, |
53 | * you can still use KConfigGroupSaver: Simply enclose all work with | 55 | * you can still use KConfigGroupSaver: Simply enclose all work with |
54 | * one group (including the creation of the KConfigGroupSaver object) | 56 | * one group (including the creation of the KConfigGroupSaver object) |
55 | * in one block. | 57 | * in one block. |
56 | * | 58 | * |
57 | * @author Matthias Kalle Dalheimer <kalle@kde.org> | 59 | * @author Matthias Kalle Dalheimer <kalle@kde.org> |
58 | * @version $Id$ | 60 | * @version $Id$ |
59 | * @see KConfigBase, KConfig, KSimpleConfig | 61 | * @see KConfigBase, KConfig, KSimpleConfig |
60 | * @short Helper class for easier use of KConfig/KSimpleConfig groups | 62 | * @short Helper class for easier use of KConfig/KSimpleConfig groups |
61 | */ | 63 | */ |
62 | //US I converted the class in a way that it can be used with KConfig objects of microkde | 64 | //US I converted the class in a way that it can be used with KConfig objects of microkde |
63 | 65 | ||
64 | class KConfigGroupSaver | 66 | class KConfigGroupSaver |
65 | { | 67 | { |
66 | public: | 68 | public: |
67 | /** | 69 | /** |
68 | * Constructor. You pass a pointer to the KConfigBase-derived | 70 | * Constructor. You pass a pointer to the KConfigBase-derived |
69 | * object you want to work with and a string indicating the _new_ | 71 | * object you want to work with and a string indicating the _new_ |
70 | * group. | 72 | * group. |
71 | * | 73 | * |
72 | * @param config The KConfigBase-derived object this | 74 | * @param config The KConfigBase-derived object this |
73 | * KConfigGroupSaver works on. | 75 | * KConfigGroupSaver works on. |
74 | * @param group The new group that the config object should switch to. | 76 | * @param group The new group that the config object should switch to. |
75 | */ | 77 | */ |
76 | KConfigGroupSaver( KConfig* config, QString group ) | 78 | KConfigGroupSaver( KConfig* config, QString group ) |
77 | /* KDE 4 : make the second parameter const QString & */ | 79 | /* KDE 4 : make the second parameter const QString & */ |
78 | : _config(config), _oldgroup(config->group()) | 80 | : _config(config), _oldgroup(config->group()) |
79 | { _config->setGroup( group ); } | 81 | { _config->setGroup( group ); } |
80 | 82 | ||
81 | KConfigGroupSaver( KConfig* config, const char *group ) | 83 | KConfigGroupSaver( KConfig* config, const char *group ) |
82 | : _config(config), _oldgroup(config->group()) | 84 | : _config(config), _oldgroup(config->group()) |
83 | { _config->setGroup( group ); } | 85 | { _config->setGroup( group ); } |
84 | 86 | ||
85 | KConfigGroupSaver( KConfig* config, const QCString &group ) | 87 | KConfigGroupSaver( KConfig* config, const Q3CString &group ) |
86 | : _config(config), _oldgroup(config->group()) | 88 | : _config(config), _oldgroup(config->group()) |
87 | { _config->setGroup( group ); } | 89 | { _config->setGroup( group ); } |
88 | 90 | ||
89 | ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); } | 91 | ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); } |
90 | 92 | ||
91 | KConfig* config() { return _config; }; | 93 | KConfig* config() { return _config; }; |
92 | 94 | ||
93 | private: | 95 | private: |
94 | KConfig* _config; | 96 | KConfig* _config; |
95 | QString _oldgroup; | 97 | QString _oldgroup; |
96 | 98 | ||
97 | KConfigGroupSaver(const KConfigGroupSaver&); | 99 | KConfigGroupSaver(const KConfigGroupSaver&); |
98 | KConfigGroupSaver& operator=(const KConfigGroupSaver&); | 100 | KConfigGroupSaver& operator=(const KConfigGroupSaver&); |
99 | 101 | ||
100 | }; | 102 | }; |
101 | 103 | ||
102 | #endif | 104 | #endif |
diff --git a/microkde/kdecore/klibloader.cpp b/microkde/kdecore/klibloader.cpp index 6d0475a..0b54eb6 100644 --- a/microkde/kdecore/klibloader.cpp +++ b/microkde/kdecore/klibloader.cpp | |||
@@ -1,80 +1,83 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1999 Torben Weis <weis@kde.org> | 2 | Copyright (C) 1999 Torben Weis <weis@kde.org> |
3 | Copyright (C) 2000 Michael Matz <matz@kde.org> | 3 | Copyright (C) 2000 Michael Matz <matz@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License version 2 as published by the Free Software Foundation. | 7 | License version 2 as published by the Free Software Foundation. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | //US #include <config.h> | 19 | //US #include <config.h> |
20 | #include <qclipboard.h> | 20 | #include <qclipboard.h> |
21 | #include <qfile.h> | 21 | #include <qfile.h> |
22 | #include <qtimer.h> | 22 | #include <qtimer.h> |
23 | #include <qobjectdict.h> | 23 | #include <q3objectdict.h> |
24 | #include <qwidgetlist.h> | ||
25 | #include <qwidget.h> | 24 | #include <qwidget.h> |
25 | #include <qwidget.h> | ||
26 | //Added by qt3to4: | ||
27 | #include <Q3CString> | ||
28 | #include <Q3PtrList> | ||
26 | 29 | ||
27 | #include "kapplication.h" | 30 | #include "kapplication.h" |
28 | #include "klibloader.h" | 31 | #include "klibloader.h" |
29 | #include "kstandarddirs.h" | 32 | #include "kstandarddirs.h" |
30 | #include "kdebug.h" | 33 | #include "kdebug.h" |
31 | #include "klocale.h" | 34 | #include "klocale.h" |
32 | 35 | ||
33 | /*US | 36 | /*US |
34 | #ifndef NDEBUG | 37 | #ifndef NDEBUG |
35 | #include "ltdl.h" | 38 | #include "ltdl.h" |
36 | #endif | 39 | #endif |
37 | */ | 40 | */ |
38 | 41 | ||
39 | //US do everything through qlibrary | 42 | //US do everything through qlibrary |
40 | #ifndef DESKTOP_VERSION | 43 | #ifndef DESKTOP_VERSION |
41 | #include <qpe/qpeapplication.h> | 44 | #include <qpe/qpeapplication.h> |
42 | #include <qtopia/qlibrary.h> | 45 | #include <qtopia/qlibrary.h> |
43 | #else | 46 | #else |
44 | #include <qlibrary.h> | 47 | #include <qlibrary.h> |
45 | #endif | 48 | #endif |
46 | 49 | ||
47 | 50 | ||
48 | template class QAsciiDict<KLibrary>; | 51 | template class Q3AsciiDict<KLibrary>; |
49 | 52 | ||
50 | #include <stdlib.h> //getenv | 53 | #include <stdlib.h> //getenv |
51 | 54 | ||
52 | /*US | 55 | /*US |
53 | #if HAVE_DLFCN_H | 56 | #if HAVE_DLFCN_H |
54 | # include <dlfcn.h> | 57 | # include <dlfcn.h> |
55 | #endif | 58 | #endif |
56 | 59 | ||
57 | #ifdef RTLD_GLOBAL | 60 | #ifdef RTLD_GLOBAL |
58 | # define LT_GLOBAL RTLD_GLOBAL | 61 | # define LT_GLOBAL RTLD_GLOBAL |
59 | #else | 62 | #else |
60 | # ifdef DL_GLOBAL | 63 | # ifdef DL_GLOBAL |
61 | # define LT_GLOBAL DL_GLOBAL | 64 | # define LT_GLOBAL DL_GLOBAL |
62 | # endif | 65 | # endif |
63 | #endif | 66 | #endif |
64 | #ifndef LT_GLOBAL | 67 | #ifndef LT_GLOBAL |
65 | # define LT_GLOBAL 0 | 68 | # define LT_GLOBAL 0 |
66 | #endif | 69 | #endif |
67 | */ | 70 | */ |
68 | 71 | ||
69 | /*US | 72 | /*US |
70 | extern "C" { | 73 | extern "C" { |
71 | extern int lt_dlopen_flag; | 74 | extern int lt_dlopen_flag; |
72 | } | 75 | } |
73 | */ | 76 | */ |
74 | 77 | ||
75 | KLibFactory::KLibFactory( QObject* parent, const char* name ) | 78 | KLibFactory::KLibFactory( QObject* parent, const char* name ) |
76 | : QObject( parent, name ) | 79 | : QObject( parent, name ) |
77 | { | 80 | { |
78 | } | 81 | } |
79 | 82 | ||
80 | KLibFactory::~KLibFactory() | 83 | KLibFactory::~KLibFactory() |
@@ -91,97 +94,97 @@ QObject* KLibFactory::create( QObject* parent, const char* name, const char* cla | |||
91 | } | 94 | } |
92 | 95 | ||
93 | 96 | ||
94 | QObject* KLibFactory::createObject( QObject*, const char*, const char*, const QStringList &) | 97 | QObject* KLibFactory::createObject( QObject*, const char*, const char*, const QStringList &) |
95 | { | 98 | { |
96 | return 0; | 99 | return 0; |
97 | } | 100 | } |
98 | 101 | ||
99 | 102 | ||
100 | // ----------------------------------------------- | 103 | // ----------------------------------------------- |
101 | 104 | ||
102 | //US KLibrary::KLibrary( const QString& libname, const QString& filename, void * handle ) | 105 | //US KLibrary::KLibrary( const QString& libname, const QString& filename, void * handle ) |
103 | KLibrary::KLibrary( const QString& libname, const QString& filename, QLibrary* handle ) | 106 | KLibrary::KLibrary( const QString& libname, const QString& filename, QLibrary* handle ) |
104 | { | 107 | { |
105 | /* Make sure, we have a KLibLoader */ | 108 | /* Make sure, we have a KLibLoader */ |
106 | (void) KLibLoader::self(); | 109 | (void) KLibLoader::self(); |
107 | m_libname = libname; | 110 | m_libname = libname; |
108 | m_filename = filename; | 111 | m_filename = filename; |
109 | m_handle = handle; | 112 | m_handle = handle; |
110 | m_factory = 0; | 113 | m_factory = 0; |
111 | m_timer = 0; | 114 | m_timer = 0; |
112 | } | 115 | } |
113 | 116 | ||
114 | KLibrary::~KLibrary() | 117 | KLibrary::~KLibrary() |
115 | { | 118 | { |
116 | // kdDebug(150) << "Deleting KLibrary " << this << " " << m_libname << endl; | 119 | // kdDebug(150) << "Deleting KLibrary " << this << " " << m_libname << endl; |
117 | if ( m_timer && m_timer->isActive() ) | 120 | if ( m_timer && m_timer->isActive() ) |
118 | m_timer->stop(); | 121 | m_timer->stop(); |
119 | 122 | ||
120 | // If any object is remaining, delete | 123 | // If any object is remaining, delete |
121 | if ( m_objs.count() > 0 ) | 124 | if ( m_objs.count() > 0 ) |
122 | { | 125 | { |
123 | QPtrListIterator<QObject> it( m_objs ); | 126 | Q3PtrListIterator<QObject> it( m_objs ); |
124 | for ( ; it.current() ; ++it ) | 127 | for ( ; it.current() ; ++it ) |
125 | { | 128 | { |
126 | kdDebug(150) << "Factory still has object " << it.current() << " " << it.current()->name () << " Library = " << m_libname << endl; | 129 | kdDebug(150) << "Factory still has object " << it.current() << " " << it.current()->name () << " Library = " << m_libname << endl; |
127 | disconnect( it.current(), SIGNAL( destroyed() ), | 130 | disconnect( it.current(), SIGNAL( destroyed() ), |
128 | this, SLOT( slotObjectDestroyed() ) ); | 131 | this, SLOT( slotObjectDestroyed() ) ); |
129 | } | 132 | } |
130 | m_objs.setAutoDelete(true); | 133 | m_objs.setAutoDelete(true); |
131 | m_objs.clear(); | 134 | m_objs.clear(); |
132 | } | 135 | } |
133 | 136 | ||
134 | if ( m_factory ) { | 137 | if ( m_factory ) { |
135 | //kdDebug(150) << " ... deleting the factory " << m_factory << endl; | 138 | //kdDebug(150) << " ... deleting the factory " << m_factory << endl; |
136 | delete m_factory; | 139 | delete m_factory; |
137 | } | 140 | } |
138 | } | 141 | } |
139 | 142 | ||
140 | QString KLibrary::name() const | 143 | QString KLibrary::name() const |
141 | { | 144 | { |
142 | return m_libname; | 145 | return m_libname; |
143 | } | 146 | } |
144 | 147 | ||
145 | QString KLibrary::fileName() const | 148 | QString KLibrary::fileName() const |
146 | { | 149 | { |
147 | return m_filename; | 150 | return m_filename; |
148 | } | 151 | } |
149 | 152 | ||
150 | KLibFactory* KLibrary::factory() | 153 | KLibFactory* KLibrary::factory() |
151 | { | 154 | { |
152 | if ( m_factory ) | 155 | if ( m_factory ) |
153 | return m_factory; | 156 | return m_factory; |
154 | 157 | ||
155 | QCString symname; | 158 | Q3CString symname; |
156 | symname.sprintf("init_%s", name().latin1() ); | 159 | symname.sprintf("init_%s", name().latin1() ); |
157 | 160 | ||
158 | void* sym = symbol( symname ); | 161 | void* sym = symbol( symname ); |
159 | if ( !sym ) | 162 | if ( !sym ) |
160 | { | 163 | { |
161 | qDebug("KLibrary: The library %s does not offer an %s function", name().latin1(), symname.data()); | 164 | qDebug("KLibrary: The library %s does not offer an %s function", name().latin1(), symname.data()); |
162 | #ifndef NDEBUG | 165 | #ifndef NDEBUG |
163 | //US qDebug("KLibrary: errorcode: %s", lt_dlerror()); | 166 | //US qDebug("KLibrary: errorcode: %s", lt_dlerror()); |
164 | #endif | 167 | #endif |
165 | kdWarning(150) << "KLibrary: The library " << name().latin1() << " does not offer an init_" << name().latin1() << " function" << endl; | 168 | kdWarning(150) << "KLibrary: The library " << name().latin1() << " does not offer an init_" << name().latin1() << " function" << endl; |
166 | return 0; | 169 | return 0; |
167 | } | 170 | } |
168 | 171 | ||
169 | typedef KLibFactory* (*t_func)(); | 172 | typedef KLibFactory* (*t_func)(); |
170 | t_func func = (t_func)sym; | 173 | t_func func = (t_func)sym; |
171 | m_factory = func(); | 174 | m_factory = func(); |
172 | 175 | ||
173 | if( !m_factory ) | 176 | if( !m_factory ) |
174 | { | 177 | { |
175 | kdWarning(150) << "KLibrary: The library " << name() << " does not offer a KDE compatible factory" << endl; | 178 | kdWarning(150) << "KLibrary: The library " << name() << " does not offer a KDE compatible factory" << endl; |
176 | return 0; | 179 | return 0; |
177 | } | 180 | } |
178 | 181 | ||
179 | connect( m_factory, SIGNAL( objectCreated( QObject * ) ), | 182 | connect( m_factory, SIGNAL( objectCreated( QObject * ) ), |
180 | this, SLOT( slotObjectCreated( QObject * ) ) ); | 183 | this, SLOT( slotObjectCreated( QObject * ) ) ); |
181 | 184 | ||
182 | return m_factory; | 185 | return m_factory; |
183 | } | 186 | } |
184 | 187 | ||
185 | void* KLibrary::symbol( const char* symname ) const | 188 | void* KLibrary::symbol( const char* symname ) const |
186 | { | 189 | { |
187 | //US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname ); | 190 | //US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname ); |
@@ -276,229 +279,229 @@ public: | |||
276 | int ref_count; | 279 | int ref_count; |
277 | //US lt_dlhandle handle; | 280 | //US lt_dlhandle handle; |
278 | QLibrary *handle; | 281 | QLibrary *handle; |
279 | QString name; | 282 | QString name; |
280 | QString filename; | 283 | QString filename; |
281 | }; | 284 | }; |
282 | 285 | ||
283 | //US KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, lt_dlhandle h) | 286 | //US KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, lt_dlhandle h) |
284 | KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, QLibrary* h) | 287 | KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, QLibrary* h) |
285 | : lib(l), ref_count(1), handle(h), name(l->name()), filename(l->fileName()) | 288 | : lib(l), ref_count(1), handle(h), name(l->name()), filename(l->fileName()) |
286 | { | 289 | { |
287 | unload_mode = UNKNOWN; | 290 | unload_mode = UNKNOWN; |
288 | /*US | 291 | /*US |
289 | if (lt_dlsym(handle, "__kde_do_not_unload") != 0) { | 292 | if (lt_dlsym(handle, "__kde_do_not_unload") != 0) { |
290 | // kdDebug(150) << "Will not unload " << name << endl; | 293 | // kdDebug(150) << "Will not unload " << name << endl; |
291 | unload_mode = DONT_UNLOAD; | 294 | unload_mode = DONT_UNLOAD; |
292 | } else if (lt_dlsym(handle, "__kde_do_unload") != 0) { | 295 | } else if (lt_dlsym(handle, "__kde_do_unload") != 0) { |
293 | unload_mode = UNLOAD; | 296 | unload_mode = UNLOAD; |
294 | } | 297 | } |
295 | */ | 298 | */ |
296 | //US use instead: | 299 | //US use instead: |
297 | if (h->resolve("__kde_do_not_unload") != 0) { | 300 | if (h->resolve("__kde_do_not_unload") != 0) { |
298 | // kdDebug(150) << "Will not unload " << name << endl; | 301 | // kdDebug(150) << "Will not unload " << name << endl; |
299 | unload_mode = DONT_UNLOAD; | 302 | unload_mode = DONT_UNLOAD; |
300 | } else if (h->resolve("__kde_do_unload") != 0) { | 303 | } else if (h->resolve("__kde_do_unload") != 0) { |
301 | unload_mode = UNLOAD; | 304 | unload_mode = UNLOAD; |
302 | } | 305 | } |
303 | } | 306 | } |
304 | 307 | ||
305 | class KLibLoaderPrivate | 308 | class KLibLoaderPrivate |
306 | { | 309 | { |
307 | public: | 310 | public: |
308 | QPtrList<KLibWrapPrivate> loaded_stack; | 311 | Q3PtrList<KLibWrapPrivate> loaded_stack; |
309 | QPtrList<KLibWrapPrivate> pending_close; | 312 | Q3PtrList<KLibWrapPrivate> pending_close; |
310 | enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; | 313 | enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; |
311 | 314 | ||
312 | QString errorMessage; | 315 | QString errorMessage; |
313 | }; | 316 | }; |
314 | 317 | ||
315 | KLibLoader* KLibLoader::s_self = 0; | 318 | KLibLoader* KLibLoader::s_self = 0; |
316 | 319 | ||
317 | KLibLoader* KLibLoader::self() | 320 | KLibLoader* KLibLoader::self() |
318 | { | 321 | { |
319 | if ( !s_self ) | 322 | if ( !s_self ) |
320 | s_self = new KLibLoader; | 323 | s_self = new KLibLoader; |
321 | return s_self; | 324 | return s_self; |
322 | } | 325 | } |
323 | 326 | ||
324 | void KLibLoader::cleanUp() | 327 | void KLibLoader::cleanUp() |
325 | { | 328 | { |
326 | if ( !s_self ) | 329 | if ( !s_self ) |
327 | return; | 330 | return; |
328 | 331 | ||
329 | delete s_self; | 332 | delete s_self; |
330 | s_self = 0; | 333 | s_self = 0; |
331 | } | 334 | } |
332 | 335 | ||
333 | KLibLoader::KLibLoader( QObject* parent, const char* name ) | 336 | KLibLoader::KLibLoader( QObject* parent, const char* name ) |
334 | : QObject( parent, name ) | 337 | : QObject( parent, name ) |
335 | { | 338 | { |
336 | s_self = this; | 339 | s_self = this; |
337 | d = new KLibLoaderPrivate; | 340 | d = new KLibLoaderPrivate; |
338 | //US lt_dlinit(); | 341 | //US lt_dlinit(); |
339 | d->unload_mode = KLibLoaderPrivate::UNKNOWN; | 342 | d->unload_mode = KLibLoaderPrivate::UNKNOWN; |
340 | if (getenv("KDE_NOUNLOAD") != 0) | 343 | if (getenv("KDE_NOUNLOAD") != 0) |
341 | d->unload_mode = KLibLoaderPrivate::DONT_UNLOAD; | 344 | d->unload_mode = KLibLoaderPrivate::DONT_UNLOAD; |
342 | else if (getenv("KDE_DOUNLOAD") != 0) | 345 | else if (getenv("KDE_DOUNLOAD") != 0) |
343 | d->unload_mode = KLibLoaderPrivate::UNLOAD; | 346 | d->unload_mode = KLibLoaderPrivate::UNLOAD; |
344 | d->loaded_stack.setAutoDelete( true ); | 347 | d->loaded_stack.setAutoDelete( true ); |
345 | } | 348 | } |
346 | 349 | ||
347 | KLibLoader::~KLibLoader() | 350 | KLibLoader::~KLibLoader() |
348 | { | 351 | { |
349 | // kdDebug(150) << "Deleting KLibLoader " << this << " " << name() << endl; | 352 | // kdDebug(150) << "Deleting KLibLoader " << this << " " << name() << endl; |
350 | 353 | ||
351 | QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); | 354 | Q3AsciiDictIterator<KLibWrapPrivate> it( m_libs ); |
352 | for (; it.current(); ++it ) | 355 | for (; it.current(); ++it ) |
353 | { | 356 | { |
354 | kdDebug(150) << "The KLibLoader contains the library " << it.current()->name | 357 | kdDebug(150) << "The KLibLoader contains the library " << it.current()->name |
355 | << " (" << it.current()->lib << ")" << endl; | 358 | << " (" << it.current()->lib << ")" << endl; |
356 | d->pending_close.append(it.current()); | 359 | d->pending_close.append(it.current()); |
357 | } | 360 | } |
358 | 361 | ||
359 | close_pending(0); | 362 | close_pending(0); |
360 | 363 | ||
361 | delete d; | 364 | delete d; |
362 | } | 365 | } |
363 | 366 | ||
364 | //static | 367 | //static |
365 | QString KLibLoader::findLibrary( const char * name/*US , const KInstance * instance*/ ) | 368 | QString KLibLoader::findLibrary( const char * name/*US , const KInstance * instance*/ ) |
366 | { | 369 | { |
367 | QCString libname( name ); | 370 | Q3CString libname( name ); |
368 | 371 | ||
369 | // only append ".la" if there is no extension | 372 | // only append ".la" if there is no extension |
370 | // this allows to load non-libtool libraries as well | 373 | // this allows to load non-libtool libraries as well |
371 | // (mhk, 20000228) | 374 | // (mhk, 20000228) |
372 | int pos = libname.findRev('/'); | 375 | int pos = libname.findRev('/'); |
373 | if (pos < 0) | 376 | if (pos < 0) |
374 | pos = 0; | 377 | pos = 0; |
375 | /*US | 378 | /*US |
376 | if (libname.find('.', pos) < 0) { | 379 | if (libname.find('.', pos) < 0) { |
377 | libname += ".la"; | 380 | libname += ".la"; |
378 | } | 381 | } |
379 | */ | 382 | */ |
380 | //US in the microedition we work only with shared libraries. | 383 | //US in the microedition we work only with shared libraries. |
381 | 384 | ||
382 | if (libname.find('.', pos) < 0) { | 385 | if (libname.find('.', pos) < 0) { |
383 | #ifdef _WIN32_ | 386 | #ifdef _WIN32_ |
384 | libname += ".dll"; | 387 | libname += ".dll"; |
385 | #else | 388 | #else |
386 | libname += ".so"; | 389 | libname += ".so"; |
387 | #endif | 390 | #endif |
388 | } | 391 | } |
389 | 392 | ||
390 | // only look up the file if it is not an absolute filename | 393 | // only look up the file if it is not an absolute filename |
391 | // (mhk, 20000228) | 394 | // (mhk, 20000228) |
392 | QString libfile; | 395 | QString libfile; |
393 | if (libname[0] == '/') | 396 | if (libname[0] == '/') |
394 | libfile = libname; | 397 | libfile = libname; |
395 | else | 398 | else |
396 | { | 399 | { |
397 | //US at this point the libname must exist as real filesname. No expansions will be made later | 400 | //US at this point the libname must exist as real filesname. No expansions will be made later |
398 | // in findResources. Because of that we prepend the lib prefix here to the name | 401 | // in findResources. Because of that we prepend the lib prefix here to the name |
399 | //US I add also the "lib" prefix. I do not how could this could have worked before without it? | 402 | //US I add also the "lib" prefix. I do not how could this could have worked before without it? |
400 | #ifndef _WIN32_ | 403 | #ifndef _WIN32_ |
401 | libname.insert(pos, "lib"); | 404 | libname.insert(pos, "lib"); |
402 | #endif | 405 | #endif |
403 | 406 | ||
404 | 407 | ||
405 | //US libfile = instance->dirs()->findResource( "module", libname ); | 408 | //US libfile = instance->dirs()->findResource( "module", libname ); |
406 | //qDebug("libname = %s ",libname.data() ); | 409 | //qDebug("libname = %s ",libname.data() ); |
407 | libfile = KGlobal::dirs()->findResource( "module", libname ); | 410 | libfile = KGlobal::dirs()->findResource( "module", libname ); |
408 | //qDebug("libfile = %s ",libfile.latin1() ); | 411 | //qDebug("libfile = %s ",libfile.latin1() ); |
409 | 412 | ||
410 | if ( libfile.isEmpty() ) | 413 | if ( libfile.isEmpty() ) |
411 | { | 414 | { |
412 | //US libfile = instance->dirs()->findResource( "lib", libname ); | 415 | //US libfile = instance->dirs()->findResource( "lib", libname ); |
413 | libfile = KGlobal::dirs()->findResource( "lib", libname ); | 416 | libfile = KGlobal::dirs()->findResource( "lib", libname ); |
414 | //qDebug("libfile2 = %s ",libfile.latin1() ); | 417 | //qDebug("libfile2 = %s ",libfile.latin1() ); |
415 | #ifndef NDEBUG | 418 | #ifndef NDEBUG |
416 | if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules | 419 | if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules |
417 | kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl; | 420 | kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl; |
418 | #endif | 421 | #endif |
419 | } | 422 | } |
420 | if ( libfile.isEmpty() ) | 423 | if ( libfile.isEmpty() ) |
421 | { | 424 | { |
422 | #ifndef NDEBUG | 425 | #ifndef NDEBUG |
423 | kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl; | 426 | kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl; |
424 | self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(libname); | 427 | self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(QString(libname)); |
425 | 428 | ||
426 | qDebug("KLibLoader::library could not find library: %s", libname.data()); | 429 | qDebug("KLibLoader::library could not find library: %s", libname.data()); |
427 | #endif | 430 | #endif |
428 | 431 | ||
429 | } | 432 | } |
430 | else | 433 | else |
431 | self()->d->errorMessage = QString::null; | 434 | self()->d->errorMessage = QString::null; |
432 | } | 435 | } |
433 | 436 | ||
434 | //qDebug("return libfile = %s ",libfile.latin1() ); | 437 | //qDebug("return libfile = %s ",libfile.latin1() ); |
435 | return libfile; | 438 | return libfile; |
436 | } | 439 | } |
437 | 440 | ||
438 | 441 | ||
439 | KLibrary* KLibLoader::globalLibrary( const char *name ) | 442 | KLibrary* KLibLoader::globalLibrary( const char *name ) |
440 | { | 443 | { |
441 | KLibrary *tmp; | 444 | KLibrary *tmp; |
442 | /*US | 445 | /*US |
443 | int olt_dlopen_flag = lt_dlopen_flag; | 446 | int olt_dlopen_flag = lt_dlopen_flag; |
444 | 447 | ||
445 | lt_dlopen_flag |= LT_GLOBAL; | 448 | lt_dlopen_flag |= LT_GLOBAL; |
446 | kdDebug(150) << "Loading the next library global with flag " | 449 | kdDebug(150) << "Loading the next library global with flag " |
447 | << lt_dlopen_flag | 450 | << lt_dlopen_flag |
448 | << "." << endl; | 451 | << "." << endl; |
449 | */ | 452 | */ |
450 | tmp = library(name); | 453 | tmp = library(name); |
451 | /*US | 454 | /*US |
452 | lt_dlopen_flag = olt_dlopen_flag; | 455 | lt_dlopen_flag = olt_dlopen_flag; |
453 | */ | 456 | */ |
454 | return tmp; | 457 | return tmp; |
455 | } | 458 | } |
456 | 459 | ||
457 | 460 | ||
458 | KLibrary* KLibLoader::library( const char *name ) | 461 | KLibrary* KLibLoader::library( const char *name ) |
459 | { | 462 | { |
460 | if (!name) | 463 | if (!name) |
461 | return 0; | 464 | return 0; |
462 | 465 | ||
463 | KLibWrapPrivate* wrap = m_libs[name]; | 466 | KLibWrapPrivate* wrap = m_libs[name]; |
464 | if (wrap) { | 467 | if (wrap) { |
465 | /* Nothing to do to load the library. */ | 468 | /* Nothing to do to load the library. */ |
466 | wrap->ref_count++; | 469 | wrap->ref_count++; |
467 | return wrap->lib; | 470 | return wrap->lib; |
468 | } | 471 | } |
469 | 472 | ||
470 | /* Test if this library was loaded at some time, but got | 473 | /* Test if this library was loaded at some time, but got |
471 | unloaded meanwhile, whithout being dlclose()'ed. */ | 474 | unloaded meanwhile, whithout being dlclose()'ed. */ |
472 | QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack); | 475 | Q3PtrListIterator<KLibWrapPrivate> it(d->loaded_stack); |
473 | for (; it.current(); ++it) { | 476 | for (; it.current(); ++it) { |
474 | if (it.current()->name == name) | 477 | if (it.current()->name == name) |
475 | wrap = it.current(); | 478 | wrap = it.current(); |
476 | } | 479 | } |
477 | 480 | ||
478 | if (wrap) { | 481 | if (wrap) { |
479 | d->pending_close.removeRef(wrap); | 482 | d->pending_close.removeRef(wrap); |
480 | if (!wrap->lib) { | 483 | if (!wrap->lib) { |
481 | /* This lib only was in loaded_stack, but not in m_libs. */ | 484 | /* This lib only was in loaded_stack, but not in m_libs. */ |
482 | wrap->lib = new KLibrary( name, wrap->filename, wrap->handle ); | 485 | wrap->lib = new KLibrary( name, wrap->filename, wrap->handle ); |
483 | } | 486 | } |
484 | wrap->ref_count++; | 487 | wrap->ref_count++; |
485 | } else { | 488 | } else { |
486 | QString libfile = findLibrary( name ); | 489 | QString libfile = findLibrary( name ); |
487 | if ( libfile.isEmpty() ) | 490 | if ( libfile.isEmpty() ) |
488 | return 0; | 491 | return 0; |
489 | #ifdef DESKTOP_VERSION | 492 | #ifdef DESKTOP_VERSION |
490 | QLibrary *qlib = new QLibrary( libfile.latin1() ); | 493 | QLibrary *qlib = new QLibrary( libfile.latin1() ); |
491 | #else | 494 | #else |
492 | QLibrary *qlib = new QLibrary( libfile.latin1(), QLibrary::Immediately ); | 495 | QLibrary *qlib = new QLibrary( libfile.latin1(), QLibrary::Immediately ); |
493 | #endif | 496 | #endif |
494 | 497 | ||
495 | //US lt_dlhandle handle = lt_dlopen( libfile.latin1() ); | 498 | //US lt_dlhandle handle = lt_dlopen( libfile.latin1() ); |
496 | //US if ( !handle ) | 499 | //US if ( !handle ) |
497 | if ( !qlib ) | 500 | if ( !qlib ) |
498 | { | 501 | { |
499 | qDebug( "KLibLoader::library could not load library: %s", libfile.latin1()); | 502 | qDebug( "KLibLoader::library could not load library: %s", libfile.latin1()); |
500 | d->errorMessage = QString::null; | 503 | d->errorMessage = QString::null; |
501 | return 0; | 504 | return 0; |
502 | } | 505 | } |
503 | else | 506 | else |
504 | d->errorMessage = QString::null; | 507 | d->errorMessage = QString::null; |
@@ -521,84 +524,84 @@ QString KLibLoader::lastErrorMessage() const | |||
521 | } | 524 | } |
522 | 525 | ||
523 | void KLibLoader::unloadLibrary( const char *libname ) | 526 | void KLibLoader::unloadLibrary( const char *libname ) |
524 | { | 527 | { |
525 | KLibWrapPrivate *wrap = m_libs[ libname ]; | 528 | KLibWrapPrivate *wrap = m_libs[ libname ]; |
526 | if (!wrap) | 529 | if (!wrap) |
527 | return; | 530 | return; |
528 | if (--wrap->ref_count) | 531 | if (--wrap->ref_count) |
529 | return; | 532 | return; |
530 | 533 | ||
531 | // kdDebug(150) << "closing library " << libname << endl; | 534 | // kdDebug(150) << "closing library " << libname << endl; |
532 | 535 | ||
533 | m_libs.remove( libname ); | 536 | m_libs.remove( libname ); |
534 | 537 | ||
535 | disconnect( wrap->lib, SIGNAL( destroyed() ), | 538 | disconnect( wrap->lib, SIGNAL( destroyed() ), |
536 | this, SLOT( slotLibraryDestroyed() ) ); | 539 | this, SLOT( slotLibraryDestroyed() ) ); |
537 | close_pending( wrap ); | 540 | close_pending( wrap ); |
538 | } | 541 | } |
539 | 542 | ||
540 | KLibFactory* KLibLoader::factory( const char* name ) | 543 | KLibFactory* KLibLoader::factory( const char* name ) |
541 | { | 544 | { |
542 | KLibrary* lib = library( name ); | 545 | KLibrary* lib = library( name ); |
543 | if ( !lib ) | 546 | if ( !lib ) |
544 | return 0; | 547 | return 0; |
545 | 548 | ||
546 | return lib->factory(); | 549 | return lib->factory(); |
547 | } | 550 | } |
548 | 551 | ||
549 | void KLibLoader::slotLibraryDestroyed() | 552 | void KLibLoader::slotLibraryDestroyed() |
550 | { | 553 | { |
551 | const KLibrary *lib = static_cast<const KLibrary *>( sender() ); | 554 | const KLibrary *lib = static_cast<const KLibrary *>( sender() ); |
552 | 555 | ||
553 | QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); | 556 | Q3AsciiDictIterator<KLibWrapPrivate> it( m_libs ); |
554 | for (; it.current(); ++it ) | 557 | for (; it.current(); ++it ) |
555 | if ( it.current()->lib == lib ) | 558 | if ( it.current()->lib == lib ) |
556 | { | 559 | { |
557 | KLibWrapPrivate *wrap = it.current(); | 560 | KLibWrapPrivate *wrap = it.current(); |
558 | wrap->lib = 0; /* the KLibrary object is already away */ | 561 | wrap->lib = 0; /* the KLibrary object is already away */ |
559 | m_libs.remove( it.currentKey() ); | 562 | m_libs.remove( it.currentKey() ); |
560 | close_pending( wrap ); | 563 | close_pending( wrap ); |
561 | return; | 564 | return; |
562 | } | 565 | } |
563 | } | 566 | } |
564 | 567 | ||
565 | void KLibLoader::close_pending(KLibWrapPrivate *wrap) | 568 | void KLibLoader::close_pending(KLibWrapPrivate *wrap) |
566 | { | 569 | { |
567 | if (wrap && !d->pending_close.containsRef( wrap )) | 570 | if (wrap && !d->pending_close.containsRef( wrap )) |
568 | d->pending_close.append( wrap ); | 571 | d->pending_close.append( wrap ); |
569 | 572 | ||
570 | /* First delete all KLibrary objects in pending_close, but _don't_ unload | 573 | /* First delete all KLibrary objects in pending_close, but _don't_ unload |
571 | the DSO behind it. */ | 574 | the DSO behind it. */ |
572 | QPtrListIterator<KLibWrapPrivate> it(d->pending_close); | 575 | Q3PtrListIterator<KLibWrapPrivate> it(d->pending_close); |
573 | for (; it.current(); ++it) { | 576 | for (; it.current(); ++it) { |
574 | wrap = it.current(); | 577 | wrap = it.current(); |
575 | if (wrap->lib) { | 578 | if (wrap->lib) { |
576 | disconnect( wrap->lib, SIGNAL( destroyed() ), | 579 | disconnect( wrap->lib, SIGNAL( destroyed() ), |
577 | this, SLOT( slotLibraryDestroyed() ) ); | 580 | this, SLOT( slotLibraryDestroyed() ) ); |
578 | delete wrap->lib; | 581 | delete wrap->lib; |
579 | wrap->lib = 0; | 582 | wrap->lib = 0; |
580 | } | 583 | } |
581 | } | 584 | } |
582 | 585 | ||
583 | if (d->unload_mode == KLibLoaderPrivate::DONT_UNLOAD) return; | 586 | if (d->unload_mode == KLibLoaderPrivate::DONT_UNLOAD) return; |
584 | 587 | ||
585 | bool deleted_one = false; | 588 | bool deleted_one = false; |
586 | while ((wrap = d->loaded_stack.first())) { | 589 | while ((wrap = d->loaded_stack.first())) { |
587 | /* Let's first see, if we want to try to unload this lib. | 590 | /* Let's first see, if we want to try to unload this lib. |
588 | If the env. var KDE_DOUNLOAD is set, we try to unload every lib. | 591 | If the env. var KDE_DOUNLOAD is set, we try to unload every lib. |
589 | If not, we look at the lib itself, and unload it only, if it exports | 592 | If not, we look at the lib itself, and unload it only, if it exports |
590 | the symbol __kde_do_unload. */ | 593 | the symbol __kde_do_unload. */ |
591 | if (d->unload_mode != KLibLoaderPrivate::UNLOAD | 594 | if (d->unload_mode != KLibLoaderPrivate::UNLOAD |
592 | && wrap->unload_mode != KLibWrapPrivate::UNLOAD) | 595 | && wrap->unload_mode != KLibWrapPrivate::UNLOAD) |
593 | break; | 596 | break; |
594 | 597 | ||
595 | /* Now ensure, that the libs are only unloaded in the reverse direction | 598 | /* Now ensure, that the libs are only unloaded in the reverse direction |
596 | they were loaded. */ | 599 | they were loaded. */ |
597 | if (!d->pending_close.containsRef( wrap )) { | 600 | if (!d->pending_close.containsRef( wrap )) { |
598 | if (!deleted_one) | 601 | if (!deleted_one) |
599 | /* Only diagnose, if we really haven't deleted anything. */ | 602 | /* Only diagnose, if we really haven't deleted anything. */ |
600 | // kdDebug(150) << "try to dlclose " << wrap->name << ": not yet" << endl; | 603 | // kdDebug(150) << "try to dlclose " << wrap->name << ": not yet" << endl; |
601 | break; | 604 | break; |
602 | } | 605 | } |
603 | 606 | ||
604 | // kdDebug(150) << "try to dlclose " << wrap->name << ": yes, done." << endl; | 607 | // kdDebug(150) << "try to dlclose " << wrap->name << ": yes, done." << endl; |
diff --git a/microkde/kdecore/klibloader.h b/microkde/kdecore/klibloader.h index ed57109..53d146e 100644 --- a/microkde/kdecore/klibloader.h +++ b/microkde/kdecore/klibloader.h | |||
@@ -1,87 +1,87 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1999 Torben Weis <weis@kde.org> | 2 | Copyright (C) 1999 Torben Weis <weis@kde.org> |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License version 2 as published by the Free Software Foundation. | 6 | License version 2 as published by the Free Software Foundation. |
7 | 7 | ||
8 | This library is distributed in the hope that it will be useful, | 8 | This library is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | Library General Public License for more details. | 11 | Library General Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU Library General Public License | 13 | You should have received a copy of the GNU Library General Public License |
14 | along with this library; see the file COPYING.LIB. If not, write to | 14 | along with this library; see the file COPYING.LIB. If not, write to |
15 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 15 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
16 | Boston, MA 02111-1307, USA. | 16 | Boston, MA 02111-1307, USA. |
17 | */ | 17 | */ |
18 | #ifndef KLIBLOADER_H | 18 | #ifndef KLIBLOADER_H |
19 | #define KLIBLOADER_H | 19 | #define KLIBLOADER_H |
20 | 20 | ||
21 | #include <qobject.h> | 21 | #include <qobject.h> |
22 | #include <qstring.h> | 22 | #include <qstring.h> |
23 | #include <qstringlist.h> | 23 | #include <qstringlist.h> |
24 | #include <qasciidict.h> | 24 | #include <q3asciidict.h> |
25 | #include <qptrlist.h> | 25 | #include <q3ptrlist.h> |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | 27 | ||
28 | #include <stdlib.h> // For backwards compatibility | 28 | #include <stdlib.h> // For backwards compatibility |
29 | 29 | ||
30 | class KInstance; | 30 | class KInstance; |
31 | class QTimer; | 31 | class QTimer; |
32 | class KLibrary; | 32 | class KLibrary; |
33 | class KLibFactory; | 33 | class KLibFactory; |
34 | class KLibFactoryPrivate; | 34 | class KLibFactoryPrivate; |
35 | class KLibLoaderPrivate; | 35 | class KLibLoaderPrivate; |
36 | class KLibraryPrivate; | 36 | class KLibraryPrivate; |
37 | 37 | ||
38 | class QLibrary; | 38 | class QLibrary; |
39 | 39 | ||
40 | #define K_EXPORT_COMPONENT_FACTORY( libname, factory ) \ | 40 | #define K_EXPORT_COMPONENT_FACTORY( libname, factory ) \ |
41 | extern "C" { void *init_##libname() { return new factory; } } | 41 | extern "C" { void *init_##libname() { return new factory; } } |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * @short Represents a dynamically loaded library. | 44 | * @short Represents a dynamically loaded library. |
45 | * | 45 | * |
46 | * KLibrary allows you to look up symbols of the shared library. | 46 | * KLibrary allows you to look up symbols of the shared library. |
47 | * Use @ref KLibLoader to create a new instance of KLibrary. | 47 | * Use @ref KLibLoader to create a new instance of KLibrary. |
48 | * | 48 | * |
49 | * @see KLibLoader | 49 | * @see KLibLoader |
50 | * @author Torben Weis <weis@kde.org> | 50 | * @author Torben Weis <weis@kde.org> |
51 | */ | 51 | */ |
52 | class KLibrary : public QObject | 52 | class KLibrary : public QObject |
53 | { | 53 | { |
54 | friend class KLibLoader; | 54 | friend class KLibLoader; |
55 | friend class QAsciiDict<KLibrary>; | 55 | friend class Q3AsciiDict<KLibrary>; |
56 | 56 | ||
57 | Q_OBJECT | 57 | Q_OBJECT |
58 | public: | 58 | public: |
59 | /** | 59 | /** |
60 | * @internal | 60 | * @internal |
61 | * Don't create KLibrary objects on your own. Instead use @ref KLibLoader. | 61 | * Don't create KLibrary objects on your own. Instead use @ref KLibLoader. |
62 | */ | 62 | */ |
63 | //US KLibrary( const QString& libname, const QString& filename, void * handle ); | 63 | //US KLibrary( const QString& libname, const QString& filename, void * handle ); |
64 | KLibrary( const QString& libname, const QString& filename, QLibrary* handle ); | 64 | KLibrary( const QString& libname, const QString& filename, QLibrary* handle ); |
65 | 65 | ||
66 | /** | 66 | /** |
67 | * Returns the name of the library. | 67 | * Returns the name of the library. |
68 | * @return The name of the library like "libkspread". | 68 | * @return The name of the library like "libkspread". |
69 | */ | 69 | */ |
70 | QString name() const; | 70 | QString name() const; |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Returns the file name of the library. | 73 | * Returns the file name of the library. |
74 | * @return The filename of the library, for example "/opt/kde2&/lib/libkspread.la" | 74 | * @return The filename of the library, for example "/opt/kde2&/lib/libkspread.la" |
75 | */ | 75 | */ |
76 | QString fileName() const; | 76 | QString fileName() const; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Returns the factory of the library. | 79 | * Returns the factory of the library. |
80 | * @return The factory of the library if there is any, otherwise 0 | 80 | * @return The factory of the library if there is any, otherwise 0 |
81 | */ | 81 | */ |
82 | KLibFactory* factory(); | 82 | KLibFactory* factory(); |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Looks up a symbol from the library. This is a very low level | 85 | * Looks up a symbol from the library. This is a very low level |
86 | * function that you usually don't want to use. Usually you should | 86 | * function that you usually don't want to use. Usually you should |
87 | * check using @ref hasSymbol() whether the symbol actually exists, | 87 | * check using @ref hasSymbol() whether the symbol actually exists, |
@@ -98,65 +98,65 @@ public: | |||
98 | * Unlike @ref symbol(), this method doesn't warn if the symbol doesn't exist, | 98 | * Unlike @ref symbol(), this method doesn't warn if the symbol doesn't exist, |
99 | * so if the symbol might or might not exist, better use hasSymbol() before symbol(). | 99 | * so if the symbol might or might not exist, better use hasSymbol() before symbol(). |
100 | * @param name the name of the symbol to check | 100 | * @param name the name of the symbol to check |
101 | * @return true if the symbol exists | 101 | * @return true if the symbol exists |
102 | * @since 3.1 | 102 | * @since 3.1 |
103 | */ | 103 | */ |
104 | bool hasSymbol( const char* name ) const; | 104 | bool hasSymbol( const char* name ) const; |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * Unloads the library. | 107 | * Unloads the library. |
108 | * This typically results in the deletion of this object. You should | 108 | * This typically results in the deletion of this object. You should |
109 | * not reference its pointer after calling this function. | 109 | * not reference its pointer after calling this function. |
110 | */ | 110 | */ |
111 | void unload() const; | 111 | void unload() const; |
112 | 112 | ||
113 | private slots: | 113 | private slots: |
114 | void slotObjectCreated( QObject *obj ); | 114 | void slotObjectCreated( QObject *obj ); |
115 | void slotObjectDestroyed(); | 115 | void slotObjectDestroyed(); |
116 | void slotTimeout(); | 116 | void slotTimeout(); |
117 | 117 | ||
118 | private: | 118 | private: |
119 | /** | 119 | /** |
120 | * @internal | 120 | * @internal |
121 | * Don't destruct KLibrary objects yourself. Instead use @ref unload() instead. | 121 | * Don't destruct KLibrary objects yourself. Instead use @ref unload() instead. |
122 | */ | 122 | */ |
123 | ~KLibrary(); | 123 | ~KLibrary(); |
124 | 124 | ||
125 | QString m_libname; | 125 | QString m_libname; |
126 | QString m_filename; | 126 | QString m_filename; |
127 | KLibFactory* m_factory; | 127 | KLibFactory* m_factory; |
128 | //US void * m_handle; | 128 | //US void * m_handle; |
129 | QLibrary* m_handle; | 129 | QLibrary* m_handle; |
130 | QPtrList<QObject> m_objs; | 130 | Q3PtrList<QObject> m_objs; |
131 | QTimer *m_timer; | 131 | QTimer *m_timer; |
132 | KLibraryPrivate *d; | 132 | KLibraryPrivate *d; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | class KLibWrapPrivate; | 135 | class KLibWrapPrivate; |
136 | 136 | ||
137 | /** | 137 | /** |
138 | * The KLibLoader allows you to load libraries dynamically at runtime. | 138 | * The KLibLoader allows you to load libraries dynamically at runtime. |
139 | * Dependent libraries are loaded automatically. | 139 | * Dependent libraries are loaded automatically. |
140 | * | 140 | * |
141 | * KLibLoader follows the singleton pattern. You can not create multiple | 141 | * KLibLoader follows the singleton pattern. You can not create multiple |
142 | * instances. Use @ref self() to get a pointer to the loader. | 142 | * instances. Use @ref self() to get a pointer to the loader. |
143 | * | 143 | * |
144 | * @see KLibrary | 144 | * @see KLibrary |
145 | * @author Torben Weis <weis@kde.org> | 145 | * @author Torben Weis <weis@kde.org> |
146 | */ | 146 | */ |
147 | class KLibLoader : public QObject | 147 | class KLibLoader : public QObject |
148 | { | 148 | { |
149 | friend class KLibrary; | 149 | friend class KLibrary; |
150 | 150 | ||
151 | Q_OBJECT | 151 | Q_OBJECT |
152 | public: | 152 | public: |
153 | /** | 153 | /** |
154 | * You should NEVER destruct an instance of KLibLoader | 154 | * You should NEVER destruct an instance of KLibLoader |
155 | * until you know what you are doing. This will release | 155 | * until you know what you are doing. This will release |
156 | * the loaded libraries. | 156 | * the loaded libraries. |
157 | */ | 157 | */ |
158 | ~KLibLoader(); | 158 | ~KLibLoader(); |
159 | 159 | ||
160 | /** | 160 | /** |
161 | * Loads and initializes a library. Loading a library multiple times is | 161 | * Loads and initializes a library. Loading a library multiple times is |
162 | * handled gracefully. | 162 | * handled gracefully. |
@@ -258,65 +258,65 @@ public: | |||
258 | */ | 258 | */ |
259 | static KLibLoader* self(); | 259 | static KLibLoader* self(); |
260 | 260 | ||
261 | /** | 261 | /** |
262 | * @internal | 262 | * @internal |
263 | * Internal Method, called by the KApplication destructor. | 263 | * Internal Method, called by the KApplication destructor. |
264 | * Do not call it. | 264 | * Do not call it. |
265 | * This is what makes it possible to rely on ~KLibFactory | 265 | * This is what makes it possible to rely on ~KLibFactory |
266 | * being called in all cases, whether the library is unloaded | 266 | * being called in all cases, whether the library is unloaded |
267 | * while the application is running or when exiting. | 267 | * while the application is running or when exiting. |
268 | */ | 268 | */ |
269 | static void cleanUp(); | 269 | static void cleanUp(); |
270 | 270 | ||
271 | /** | 271 | /** |
272 | * Helper method which looks for a library in the standard paths | 272 | * Helper method which looks for a library in the standard paths |
273 | * ("module" and "lib" resources). | 273 | * ("module" and "lib" resources). |
274 | * Made public for code that doesn't use KLibLoader itself, but still | 274 | * Made public for code that doesn't use KLibLoader itself, but still |
275 | * wants to open modules. | 275 | * wants to open modules. |
276 | * @param name of the library. If it is not a path, the function searches in | 276 | * @param name of the library. If it is not a path, the function searches in |
277 | * the "module" and "lib" resources. If there is no extension, | 277 | * the "module" and "lib" resources. If there is no extension, |
278 | * ".la" will be appended. | 278 | * ".la" will be appended. |
279 | * @param instance a KInstance used to get the standard paths | 279 | * @param instance a KInstance used to get the standard paths |
280 | */ | 280 | */ |
281 | static QString findLibrary( const char * name/*US , const KInstance * instance = KGlobal::instance()*/ ); | 281 | static QString findLibrary( const char * name/*US , const KInstance * instance = KGlobal::instance()*/ ); |
282 | 282 | ||
283 | protected: | 283 | protected: |
284 | KLibLoader( QObject* parent = 0, const char* name = 0 ); | 284 | KLibLoader( QObject* parent = 0, const char* name = 0 ); |
285 | 285 | ||
286 | private slots: | 286 | private slots: |
287 | void slotLibraryDestroyed(); | 287 | void slotLibraryDestroyed(); |
288 | private: | 288 | private: |
289 | void close_pending( KLibWrapPrivate * ); | 289 | void close_pending( KLibWrapPrivate * ); |
290 | QAsciiDict<KLibWrapPrivate> m_libs; | 290 | Q3AsciiDict<KLibWrapPrivate> m_libs; |
291 | 291 | ||
292 | static KLibLoader* s_self; | 292 | static KLibLoader* s_self; |
293 | 293 | ||
294 | protected: | 294 | protected: |
295 | virtual void virtual_hook( int id, void* data ); | 295 | virtual void virtual_hook( int id, void* data ); |
296 | private: | 296 | private: |
297 | KLibLoaderPrivate *d; | 297 | KLibLoaderPrivate *d; |
298 | }; | 298 | }; |
299 | 299 | ||
300 | /** | 300 | /** |
301 | * If you develop a library that is to be loaded dynamically at runtime, then | 301 | * If you develop a library that is to be loaded dynamically at runtime, then |
302 | * you should return a pointer to your factory. The K_EXPORT_COMPONENT_FACTORY | 302 | * you should return a pointer to your factory. The K_EXPORT_COMPONENT_FACTORY |
303 | * macro is provided for this purpose: | 303 | * macro is provided for this purpose: |
304 | * <pre> | 304 | * <pre> |
305 | * K_EXPORT_COMPONENT_FACTORY( libkspread, KSpreadFactory ) | 305 | * K_EXPORT_COMPONENT_FACTORY( libkspread, KSpreadFactory ) |
306 | * </pre> | 306 | * </pre> |
307 | * | 307 | * |
308 | * The first macro argument is the name of your library, the second specifies the name | 308 | * The first macro argument is the name of your library, the second specifies the name |
309 | * of your factory. | 309 | * of your factory. |
310 | * | 310 | * |
311 | * In the constructor of your factory you should create an instance of @ref KInstance | 311 | * In the constructor of your factory you should create an instance of @ref KInstance |
312 | * like this: | 312 | * like this: |
313 | * <pre> | 313 | * <pre> |
314 | * s_global = new KInstance( "kspread" ); | 314 | * s_global = new KInstance( "kspread" ); |
315 | * </pre> | 315 | * </pre> |
316 | * This @ref KInstance is comparable to @ref KGlobal used by normal applications. | 316 | * This @ref KInstance is comparable to @ref KGlobal used by normal applications. |
317 | * It allows you to find resource files (images, XML, sound etc.) belonging | 317 | * It allows you to find resource files (images, XML, sound etc.) belonging |
318 | * to the library. | 318 | * to the library. |
319 | * | 319 | * |
320 | * If you want to load a library, use @ref KLibLoader. You can query @ref KLibLoader | 320 | * If you want to load a library, use @ref KLibLoader. You can query @ref KLibLoader |
321 | * directly for a pointer to the libraries factory by using the @ref KLibLoader::factory() | 321 | * directly for a pointer to the libraries factory by using the @ref KLibLoader::factory() |
322 | * function. | 322 | * function. |
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp index 1d8ae9f..dd310fa 100644 --- a/microkde/kdecore/klocale.cpp +++ b/microkde/kdecore/klocale.cpp | |||
@@ -1,108 +1,109 @@ | |||
1 | #include <qregexp.h> | 1 | #include <qregexp.h> |
2 | #include <qapplication.h> | 2 | #include <qapplication.h> |
3 | #include <QDesktopWidget> | ||
3 | 4 | ||
4 | #include "kdebug.h" | 5 | #include "kdebug.h" |
5 | #include "kcalendarsystemgregorian.h" | 6 | #include "kcalendarsystemgregorian.h" |
6 | 7 | ||
7 | #include "klocale.h" | 8 | #include "klocale.h" |
8 | 9 | ||
9 | #include <qstringlist.h> | 10 | #include <qstringlist.h> |
10 | 11 | ||
11 | //#define COLLECT_TRANSLATION | 12 | //#define COLLECT_TRANSLATION |
12 | 13 | ||
13 | 14 | ||
14 | QDict<QString> *mLocaleDict = 0; | 15 | Q3Dict<QString> *mLocaleDict = 0; |
15 | void setLocaleDict( QDict<QString> * dict ) | 16 | void setLocaleDict( Q3Dict<QString> * dict ) |
16 | { | 17 | { |
17 | mLocaleDict = dict; | 18 | mLocaleDict = dict; |
18 | 19 | ||
19 | } | 20 | } |
20 | 21 | ||
21 | #ifdef COLLECT_TRANSLATION | 22 | #ifdef COLLECT_TRANSLATION |
22 | 23 | ||
23 | QStringList missingTrans; | 24 | QStringList missingTrans; |
24 | QStringList existingTrans1; | 25 | QStringList existingTrans1; |
25 | QStringList existingTrans2; | 26 | QStringList existingTrans2; |
26 | 27 | ||
27 | void addMissing(const char *text) | 28 | void addMissing(const char *text) |
28 | { | 29 | { |
29 | 30 | ||
30 | QString mis ( text ); | 31 | QString mis ( text ); |
31 | if ( !missingTrans.contains( mis ) ) | 32 | if ( !missingTrans.contains( mis ) ) |
32 | missingTrans.append(mis); | 33 | missingTrans.append(mis); |
33 | 34 | ||
34 | } | 35 | } |
35 | void addExist(const char *text,QString trans ) | 36 | void addExist(const char *text,QString trans ) |
36 | { | 37 | { |
37 | //return; | 38 | //return; |
38 | QString mis ( text ); | 39 | QString mis ( text ); |
39 | if ( !existingTrans1.contains( mis ) ) { | 40 | if ( !existingTrans1.contains( mis ) ) { |
40 | existingTrans1.append(mis); | 41 | existingTrans1.append(mis); |
41 | existingTrans2.append(trans); | 42 | existingTrans2.append(trans); |
42 | 43 | ||
43 | } | 44 | } |
44 | 45 | ||
45 | } | 46 | } |
46 | 47 | ||
47 | #include <qfile.h> | 48 | #include <qfile.h> |
48 | #include <qtextstream.h> | 49 | #include <q3textstream.h> |
49 | #include <qtextcodec.h> | 50 | #include <qtextcodec.h> |
50 | #endif | 51 | #endif |
51 | void dumpMissing() | 52 | void dumpMissing() |
52 | { | 53 | { |
53 | #ifdef COLLECT_TRANSLATION | 54 | #ifdef COLLECT_TRANSLATION |
54 | QString fileName = "/tmp/usernewtrans.txt"; | 55 | QString fileName = "/tmp/usernewtrans.txt"; |
55 | QFile file( fileName ); | 56 | QFile file( fileName ); |
56 | if (!file.open( IO_WriteOnly ) ) { | 57 | if (!file.open( QIODevice::WriteOnly ) ) { |
57 | return ; | 58 | return ; |
58 | } | 59 | } |
59 | QTextStream ts( &file ); | 60 | Q3TextStream ts( &file ); |
60 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 61 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
61 | 62 | ||
62 | int i; | 63 | int i; |
63 | for ( i = 0; i< missingTrans.count(); ++i ) { | 64 | for ( i = 0; i< missingTrans.count(); ++i ) { |
64 | 65 | ||
65 | QString text = missingTrans[i].replace( QRegExp("\n"),"\\n" ); | 66 | QString text = missingTrans[i].replace( QRegExp("\n"),"\\n" ); |
66 | ts << "{ \""<<text<< "\",\""<< text <<"\" },\n"; | 67 | ts << "{ \""<<text<< "\",\""<< text <<"\" },\n"; |
67 | 68 | ||
68 | } | 69 | } |
69 | file.close(); | 70 | file.close(); |
70 | { | 71 | { |
71 | QString fileName = "/tmp/usertrans.txt"; | 72 | QString fileName = "/tmp/usertrans.txt"; |
72 | QFile file( fileName ); | 73 | QFile file( fileName ); |
73 | if (!file.open( IO_WriteOnly ) ) { | 74 | if (!file.open( QIODevice::WriteOnly ) ) { |
74 | return ; | 75 | return ; |
75 | } | 76 | } |
76 | QTextStream ts( &file ); | 77 | Q3TextStream ts( &file ); |
77 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 78 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
78 | 79 | ||
79 | int i; | 80 | int i; |
80 | for ( i = 0; i< existingTrans1.count(); ++i ) { | 81 | for ( i = 0; i< existingTrans1.count(); ++i ) { |
81 | 82 | ||
82 | QString text = existingTrans1[i].replace( QRegExp("\n"),"\\n" ); | 83 | QString text = existingTrans1[i].replace( QRegExp("\n"),"\\n" ); |
83 | QString text2 = existingTrans2[i].replace( QRegExp("\n"),"\\n" ); | 84 | QString text2 = existingTrans2[i].replace( QRegExp("\n"),"\\n" ); |
84 | ts << "{ \""<<text<< "\",\""<< text2 <<"\" },\n"; | 85 | ts << "{ \""<<text<< "\",\""<< text2 <<"\" },\n"; |
85 | 86 | ||
86 | } | 87 | } |
87 | file.close(); | 88 | file.close(); |
88 | } | 89 | } |
89 | #endif | 90 | #endif |
90 | } | 91 | } |
91 | QString i18n(const char *text) | 92 | QString i18n(const char *text) |
92 | { | 93 | { |
93 | if ( ! mLocaleDict ) { | 94 | if ( ! mLocaleDict ) { |
94 | #ifdef COLLECT_TRANSLATION | 95 | #ifdef COLLECT_TRANSLATION |
95 | addMissing( text ); | 96 | addMissing( text ); |
96 | #endif | 97 | #endif |
97 | return QString( text ); | 98 | return QString( text ); |
98 | } | 99 | } |
99 | else { | 100 | else { |
100 | QString* ret = mLocaleDict->find(QString(text)) ; | 101 | QString* ret = mLocaleDict->find(QString(text)) ; |
101 | if ( ret == 0 ) { | 102 | if ( ret == 0 ) { |
102 | #ifdef COLLECT_TRANSLATION | 103 | #ifdef COLLECT_TRANSLATION |
103 | addMissing( text ); | 104 | addMissing( text ); |
104 | #endif | 105 | #endif |
105 | return QString( text ); | 106 | return QString( text ); |
106 | } | 107 | } |
107 | else { | 108 | else { |
108 | if ( (*ret).isEmpty() ) { | 109 | if ( (*ret).isEmpty() ) { |
@@ -438,125 +439,125 @@ QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat | |||
438 | case 'd': | 439 | case 'd': |
439 | put_it_in( buffer, index, pDate.day() ); | 440 | put_it_in( buffer, index, pDate.day() ); |
440 | break; | 441 | break; |
441 | case 'a': | 442 | case 'a': |
442 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) ); | 443 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) ); |
443 | break; | 444 | break; |
444 | case 'A': | 445 | case 'A': |
445 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) ); | 446 | put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) ); |
446 | break; | 447 | break; |
447 | default: | 448 | default: |
448 | buffer[index++] = rst.at( format_index ); | 449 | buffer[index++] = rst.at( format_index ); |
449 | break; | 450 | break; |
450 | } | 451 | } |
451 | escape = false; | 452 | escape = false; |
452 | } | 453 | } |
453 | } | 454 | } |
454 | QString ret( buffer, index ); | 455 | QString ret( buffer, index ); |
455 | delete [] buffer; | 456 | delete [] buffer; |
456 | return ret; | 457 | return ret; |
457 | } | 458 | } |
458 | 459 | ||
459 | QString KLocale::formatDateTime(const QDateTime &pDateTime, | 460 | QString KLocale::formatDateTime(const QDateTime &pDateTime, |
460 | bool shortFormat, | 461 | bool shortFormat, |
461 | bool includeSeconds, | 462 | bool includeSeconds, |
462 | IntDateFormat intIntDateFormat) const | 463 | IntDateFormat intIntDateFormat) const |
463 | { | 464 | { |
464 | QString format("%1 %2"); | 465 | QString format("%1 %2"); |
465 | 466 | ||
466 | if ( intIntDateFormat == Default ) | 467 | if ( intIntDateFormat == Default ) |
467 | format = "%1 %2"; | 468 | format = "%1 %2"; |
468 | else if ( intIntDateFormat == Format1 ) | 469 | else if ( intIntDateFormat == Format1 ) |
469 | format = "%1 %2"; | 470 | format = "%1 %2"; |
470 | else if ( intIntDateFormat == ISODate ) | 471 | else if ( intIntDateFormat == Qt::ISODate ) |
471 | format = "%1T%2"; | 472 | format = "%1T%2"; |
472 | 473 | ||
473 | QString res = format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat )) | 474 | QString res = format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat )) |
474 | .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat )); | 475 | .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat )); |
475 | 476 | ||
476 | //qDebug("KLocale::formatDateTime transformed %s, into %s", pDateTime.toString().latin1(), res.latin1() ); | 477 | //qDebug("KLocale::formatDateTime transformed %s, into %s", pDateTime.toString().latin1(), res.latin1() ); |
477 | 478 | ||
478 | return res; | 479 | return res; |
479 | } | 480 | } |
480 | 481 | ||
481 | QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const | 482 | QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const |
482 | { | 483 | { |
483 | return formatDateTime(pDateTime, true, true, intIntDateFormat); | 484 | return formatDateTime(pDateTime, true, true, intIntDateFormat); |
484 | } | 485 | } |
485 | 486 | ||
486 | QDate KLocale::readDate(const QString &intstr, bool* ok) const | 487 | QDate KLocale::readDate(const QString &intstr, bool* ok) const |
487 | { | 488 | { |
488 | QDate date; | 489 | QDate date; |
489 | date = readDate(intstr, true, ok); | 490 | date = readDate(intstr, true, ok); |
490 | if (date.isValid()) return date; | 491 | if (date.isValid()) return date; |
491 | return readDate(intstr, false, ok); | 492 | return readDate(intstr, false, ok); |
492 | } | 493 | } |
493 | 494 | ||
494 | QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const | 495 | QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const |
495 | { | 496 | { |
496 | QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace(); | 497 | QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace(); |
497 | return readDate( intstr, fmt, ok ); | 498 | return readDate( intstr, fmt, ok ); |
498 | } | 499 | } |
499 | 500 | ||
500 | QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const | 501 | QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const |
501 | { | 502 | { |
502 | //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl; | 503 | //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl; |
503 | QString str = intstr.simplifyWhiteSpace().lower(); | 504 | QString str = intstr.simplifyWhiteSpace().lower(); |
504 | int day = -1, month = -1; | 505 | int day = -1, month = -1; |
505 | // allow the year to be omitted if not in the format | 506 | // allow the year to be omitted if not in the format |
506 | int year = QDate::currentDate().year(); | 507 | int year = QDate::currentDate().year(); |
507 | uint strpos = 0; | 508 | uint strpos = 0; |
508 | uint fmtpos = 0; | 509 | uint fmtpos = 0; |
509 | 510 | ||
510 | while (fmt.length() > fmtpos || str.length() > strpos) | 511 | while (fmt.length() > fmtpos || str.length() > strpos) |
511 | { | 512 | { |
512 | if ( !(fmt.length() > fmtpos && str.length() > strpos) ) | 513 | if ( !(fmt.length() > fmtpos && str.length() > strpos) ) |
513 | goto error; | 514 | goto error; |
514 | 515 | ||
515 | QChar c = fmt.at(fmtpos++); | 516 | QChar c = fmt.at(fmtpos++); |
516 | 517 | ||
517 | if (c != '%') { | 518 | if (c != '%') { |
518 | if (c.isSpace()) | 519 | if (c.isSpace()) |
519 | strpos++; | 520 | strpos++; |
520 | else if (c != str.at(strpos++)) | 521 | else if (c != str.at(strpos++)) |
521 | goto error; | 522 | goto error; |
522 | continue; | 523 | continue; |
523 | } | 524 | } |
524 | 525 | ||
525 | // remove space at the begining | 526 | // remove space at the begining |
526 | if (str.length() > strpos && str.at(strpos).isSpace()) | 527 | if (str.length() > strpos && str.at(strpos).isSpace()) |
527 | strpos++; | 528 | strpos++; |
528 | 529 | ||
529 | c = fmt.at(fmtpos++); | 530 | c = fmt.at(fmtpos++); |
530 | switch (c) | 531 | switch (c.unicode()) |
531 | { | 532 | { |
532 | case 'a': | 533 | case 'a': |
533 | case 'A': | 534 | case 'A': |
534 | // this will just be ignored | 535 | // this will just be ignored |
535 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition | 536 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition |
536 | for (int j = 1; j < 8; j++) { | 537 | for (int j = 1; j < 8; j++) { |
537 | QString s = weekDayName(j, c == 'a').lower(); | 538 | QString s = weekDayName(j, c == 'a').lower(); |
538 | int len = s.length(); | 539 | int len = s.length(); |
539 | if (str.mid(strpos, len) == s) | 540 | if (str.mid(strpos, len) == s) |
540 | strpos += len; | 541 | strpos += len; |
541 | } | 542 | } |
542 | break; | 543 | break; |
543 | } | 544 | } |
544 | case 'b': | 545 | case 'b': |
545 | case 'B': | 546 | case 'B': |
546 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition | 547 | { // Cristian Tache: porting to Win: Block added because of "j" redefinition |
547 | for (int j = 1; j < 13; j++) { | 548 | for (int j = 1; j < 13; j++) { |
548 | QString s = monthName(j, c == 'b').lower(); | 549 | QString s = monthName(j, c == 'b').lower(); |
549 | int len = s.length(); | 550 | int len = s.length(); |
550 | if (str.mid(strpos, len) == s) { | 551 | if (str.mid(strpos, len) == s) { |
551 | month = j; | 552 | month = j; |
552 | strpos += len; | 553 | strpos += len; |
553 | } | 554 | } |
554 | } | 555 | } |
555 | break; | 556 | break; |
556 | } | 557 | } |
557 | case 'd': | 558 | case 'd': |
558 | case 'e': | 559 | case 'e': |
559 | day = readInt(str, strpos); | 560 | day = readInt(str, strpos); |
560 | if (day < 1 || day > 31) | 561 | if (day < 1 || day > 31) |
561 | goto error; | 562 | goto error; |
562 | 563 | ||
@@ -609,65 +610,65 @@ QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const | |||
609 | QString str = intstr.simplifyWhiteSpace().lower(); | 610 | QString str = intstr.simplifyWhiteSpace().lower(); |
610 | QString Format = timeFormat().simplifyWhiteSpace(); | 611 | QString Format = timeFormat().simplifyWhiteSpace(); |
611 | if (!seconds) | 612 | if (!seconds) |
612 | Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null); | 613 | Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null); |
613 | 614 | ||
614 | int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds | 615 | int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds |
615 | 616 | ||
616 | bool g_12h = false; | 617 | bool g_12h = false; |
617 | bool pm = false; | 618 | bool pm = false; |
618 | uint strpos = 0; | 619 | uint strpos = 0; |
619 | uint Formatpos = 0; | 620 | uint Formatpos = 0; |
620 | 621 | ||
621 | while (Format.length() > Formatpos || str.length() > strpos) | 622 | while (Format.length() > Formatpos || str.length() > strpos) |
622 | { | 623 | { |
623 | if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error; | 624 | if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error; |
624 | 625 | ||
625 | QChar c = Format.at(Formatpos++); | 626 | QChar c = Format.at(Formatpos++); |
626 | 627 | ||
627 | if (c != '%') | 628 | if (c != '%') |
628 | { | 629 | { |
629 | if (c.isSpace()) | 630 | if (c.isSpace()) |
630 | strpos++; | 631 | strpos++; |
631 | else if (c != str.at(strpos++)) | 632 | else if (c != str.at(strpos++)) |
632 | goto error; | 633 | goto error; |
633 | continue; | 634 | continue; |
634 | } | 635 | } |
635 | 636 | ||
636 | // remove space at the begining | 637 | // remove space at the begining |
637 | if (str.length() > strpos && str.at(strpos).isSpace()) | 638 | if (str.length() > strpos && str.at(strpos).isSpace()) |
638 | strpos++; | 639 | strpos++; |
639 | 640 | ||
640 | c = Format.at(Formatpos++); | 641 | c = Format.at(Formatpos++); |
641 | switch (c) | 642 | switch (c.unicode()) |
642 | { | 643 | { |
643 | case 'p': | 644 | case 'p': |
644 | { | 645 | { |
645 | QString s; | 646 | QString s; |
646 | s = i18n("pm").lower(); | 647 | s = i18n("pm").lower(); |
647 | int len = s.length(); | 648 | int len = s.length(); |
648 | if (str.mid(strpos, len) == s) | 649 | if (str.mid(strpos, len) == s) |
649 | { | 650 | { |
650 | pm = true; | 651 | pm = true; |
651 | strpos += len; | 652 | strpos += len; |
652 | } | 653 | } |
653 | else | 654 | else |
654 | { | 655 | { |
655 | s = i18n("am").lower(); | 656 | s = i18n("am").lower(); |
656 | len = s.length(); | 657 | len = s.length(); |
657 | if (str.mid(strpos, len) == s) { | 658 | if (str.mid(strpos, len) == s) { |
658 | pm = false; | 659 | pm = false; |
659 | strpos += len; | 660 | strpos += len; |
660 | } | 661 | } |
661 | else | 662 | else |
662 | goto error; | 663 | goto error; |
663 | } | 664 | } |
664 | } | 665 | } |
665 | break; | 666 | break; |
666 | 667 | ||
667 | case 'k': | 668 | case 'k': |
668 | case 'H': | 669 | case 'H': |
669 | g_12h = false; | 670 | g_12h = false; |
670 | hour = readInt(str, strpos); | 671 | hour = readInt(str, strpos); |
671 | if (hour < 0 || hour > 23) | 672 | if (hour < 0 || hour > 23) |
672 | goto error; | 673 | goto error; |
673 | 674 | ||
@@ -705,65 +706,65 @@ QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const | |||
705 | 706 | ||
706 | if (ok) *ok = true; | 707 | if (ok) *ok = true; |
707 | return QTime(hour, minute, second); | 708 | return QTime(hour, minute, second); |
708 | 709 | ||
709 | error: | 710 | error: |
710 | if (ok) *ok = false; | 711 | if (ok) *ok = false; |
711 | return QTime(-1, -1, -1); // return invalid date if it didn't work | 712 | return QTime(-1, -1, -1); // return invalid date if it didn't work |
712 | // This will be removed in the near future, since it gives a warning on stderr. | 713 | // This will be removed in the near future, since it gives a warning on stderr. |
713 | // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime. | 714 | // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime. |
714 | } | 715 | } |
715 | 716 | ||
716 | QDateTime KLocale::readDateTime(const QString &intstr, | 717 | QDateTime KLocale::readDateTime(const QString &intstr, |
717 | IntDateFormat intIntDateFormat, | 718 | IntDateFormat intIntDateFormat, |
718 | bool* ok) const | 719 | bool* ok) const |
719 | { | 720 | { |
720 | bool ok1, ok2; | 721 | bool ok1, ok2; |
721 | 722 | ||
722 | // AT the moment we can not read any other format then ISODate | 723 | // AT the moment we can not read any other format then ISODate |
723 | if ( intIntDateFormat != ISODate ) | 724 | if ( intIntDateFormat != ISODate ) |
724 | { | 725 | { |
725 | qDebug("KLocale::readDateTime, only ISODate is supported."); | 726 | qDebug("KLocale::readDateTime, only ISODate is supported."); |
726 | return QDateTime(); | 727 | return QDateTime(); |
727 | } | 728 | } |
728 | 729 | ||
729 | int pos = intstr.find("T"); | 730 | int pos = intstr.find("T"); |
730 | QString date = intstr.left(pos); | 731 | QString date = intstr.left(pos); |
731 | QString time = intstr.mid(pos+1); | 732 | QString time = intstr.mid(pos+1); |
732 | 733 | ||
733 | QString dformat = dateFormat(intIntDateFormat); | 734 | QString dformat = dateFormat(intIntDateFormat); |
734 | QString tformat = timeFormat(intIntDateFormat); | 735 | QString tformat = timeFormat(intIntDateFormat); |
735 | 736 | ||
736 | QDate m_date = readDate(date, dformat, &ok1); | 737 | QDate m_date = readDate(date, dformat, &ok1); |
737 | QTime m_time = readTime(time, tformat, &ok2); | 738 | QTime m_time = readTime(time, !tformat.isEmpty(), &ok2); |
738 | 739 | ||
739 | QDateTime m_dt; | 740 | QDateTime m_dt; |
740 | 741 | ||
741 | if (ok) | 742 | if (ok) |
742 | { | 743 | { |
743 | if ((ok1 == false) || (ok2 == false)) | 744 | if ((ok1 == false) || (ok2 == false)) |
744 | *ok = false; | 745 | *ok = false; |
745 | else | 746 | else |
746 | *ok = true; | 747 | *ok = true; |
747 | } | 748 | } |
748 | 749 | ||
749 | //only set values if both operations returned true. | 750 | //only set values if both operations returned true. |
750 | if ((ok1 == true) && (ok2 == true)) | 751 | if ((ok1 == true) && (ok2 == true)) |
751 | { | 752 | { |
752 | m_dt.setDate(m_date); | 753 | m_dt.setDate(m_date); |
753 | m_dt.setTime(m_time); | 754 | m_dt.setTime(m_time); |
754 | } | 755 | } |
755 | 756 | ||
756 | //qDebug("KLocale::readDateTime() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2); | 757 | //qDebug("KLocale::readDateTime() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2); |
757 | return m_dt; | 758 | return m_dt; |
758 | } | 759 | } |
759 | 760 | ||
760 | QDate KLocale::readDate(const QString &intstr, | 761 | QDate KLocale::readDate(const QString &intstr, |
761 | IntDateFormat intIntDateFormat, | 762 | IntDateFormat intIntDateFormat, |
762 | bool* ok) const | 763 | bool* ok) const |
763 | { | 764 | { |
764 | bool ok1; | 765 | bool ok1; |
765 | 766 | ||
766 | QString dformat = dateFormat(intIntDateFormat); | 767 | QString dformat = dateFormat(intIntDateFormat); |
767 | 768 | ||
768 | QDate m_date = readDate(intstr, dformat, &ok1); | 769 | QDate m_date = readDate(intstr, dformat, &ok1); |
769 | 770 | ||
diff --git a/microkde/kdecore/klocale.h b/microkde/kdecore/klocale.h index 58e0b39..840fc9d 100644 --- a/microkde/kdecore/klocale.h +++ b/microkde/kdecore/klocale.h | |||
@@ -1,46 +1,46 @@ | |||
1 | #ifndef MINIKDE_KLOCALE_H | 1 | #ifndef MINIKDE_KLOCALE_H |
2 | #define MINIKDE_KLOCALE_H | 2 | #define MINIKDE_KLOCALE_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | #include <qdatetime.h> | 6 | #include <qdatetime.h> |
7 | #include <qdict.h> | 7 | #include <q3dict.h> |
8 | 8 | ||
9 | #ifndef I18N_NOOP | 9 | #ifndef I18N_NOOP |
10 | #define I18N_NOOP(x) (x) | 10 | #define I18N_NOOP(x) (x) |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | class KCalendarSystem; | 13 | class KCalendarSystem; |
14 | void setLocaleDict( QDict<QString> * dict ); | 14 | void setLocaleDict( Q3Dict<QString> * dict ); |
15 | QString i18n(const char *text); | 15 | QString i18n(const char *text); |
16 | QString i18n(const char *hint, const char *text); | 16 | QString i18n(const char *hint, const char *text); |
17 | QString i18n(const char *text1, const char *textn, int num); | 17 | QString i18n(const char *text1, const char *textn, int num); |
18 | 18 | ||
19 | // Qt3's uic generates i18n( "msg", "comment" ) calls which conflict | 19 | // Qt3's uic generates i18n( "msg", "comment" ) calls which conflict |
20 | // with our i18n method. we use uic -tr tr2i18n to redirect | 20 | // with our i18n method. we use uic -tr tr2i18n to redirect |
21 | // to the right i18n() function | 21 | // to the right i18n() function |
22 | inline QString tr2i18n(const char* message, const char* =0) { | 22 | inline QString tr2i18n(const char* message, const char* =0) { |
23 | return i18n( message); | 23 | return i18n( message); |
24 | } | 24 | } |
25 | 25 | ||
26 | class KLocale | 26 | class KLocale |
27 | { | 27 | { |
28 | public: | 28 | public: |
29 | KLocale(); | 29 | KLocale(); |
30 | 30 | ||
31 | QString formatNumber(double num, int precision = -1) const; | 31 | QString formatNumber(double num, int precision = -1) const; |
32 | QString formatNumber(const QString &numStr) const; | 32 | QString formatNumber(const QString &numStr) const; |
33 | double readNumber(const QString &numStr, bool * ok = 0) const; | 33 | double readNumber(const QString &numStr, bool * ok = 0) const; |
34 | 34 | ||
35 | QString decimalSymbol() const; | 35 | QString decimalSymbol() const; |
36 | QString thousandsSeparator() const; | 36 | QString thousandsSeparator() const; |
37 | QString positiveSign() const; | 37 | QString positiveSign() const; |
38 | QString negativeSign() const; | 38 | QString negativeSign() const; |
39 | 39 | ||
40 | 40 | ||
41 | QString translate( const char *index ) const; | 41 | QString translate( const char *index ) const; |
42 | QString translate( const char *index, const char *fallback) const; | 42 | QString translate( const char *index, const char *fallback) const; |
43 | 43 | ||
44 | enum IntDateFormat { Undefined=-1, Default=0, Format1=1, ISODate=2, Userdefined=3 }; | 44 | enum IntDateFormat { Undefined=-1, Default=0, Format1=1, ISODate=2, Userdefined=3 }; |
45 | 45 | ||
46 | QString formatDate(const QDate &pDate, bool shortFormat = false, IntDateFormat intIntDateFormat = Undefined) const; | 46 | QString formatDate(const QDate &pDate, bool shortFormat = false, IntDateFormat intIntDateFormat = Undefined) const; |
diff --git a/microkde/kdecore/kmdcodec.cpp b/microkde/kdecore/kmdcodec.cpp index bc03569..db11e52 100644 --- a/microkde/kdecore/kmdcodec.cpp +++ b/microkde/kdecore/kmdcodec.cpp | |||
@@ -10,64 +10,66 @@ | |||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public | 14 | You should have received a copy of the GNU Library General Public |
15 | License along with this program; if not, write to the Free Software | 15 | License along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 | 17 | ||
18 | RFC 1321 "MD5 Message-Digest Algorithm" Copyright (C) 1991-1992. | 18 | RFC 1321 "MD5 Message-Digest Algorithm" Copyright (C) 1991-1992. |
19 | RSA Data Security, Inc. Created 1991. All rights reserved. | 19 | RSA Data Security, Inc. Created 1991. All rights reserved. |
20 | 20 | ||
21 | The KMD5 class is based on a C++ implementation of | 21 | The KMD5 class is based on a C++ implementation of |
22 | "RSA Data Security, Inc. MD5 Message-Digest Algorithm" by | 22 | "RSA Data Security, Inc. MD5 Message-Digest Algorithm" by |
23 | Mordechai T. Abzug,Copyright (c) 1995. This implementation | 23 | Mordechai T. Abzug,Copyright (c) 1995. This implementation |
24 | passes the test-suite as defined in RFC 1321. | 24 | passes the test-suite as defined in RFC 1321. |
25 | 25 | ||
26 | The encoding and decoding utilities in KCodecs with the exception of | 26 | The encoding and decoding utilities in KCodecs with the exception of |
27 | quoted-printable are based on the java implementation in HTTPClient | 27 | quoted-printable are based on the java implementation in HTTPClient |
28 | package by Ronald Tschal� Copyright (C) 1996-1999. | 28 | package by Ronald Tschal� Copyright (C) 1996-1999. |
29 | 29 | ||
30 | The quoted-printable codec as described in RFC 2045, section 6.7. is by | 30 | The quoted-printable codec as described in RFC 2045, section 6.7. is by |
31 | Rik Hemsley (C) 2001. | 31 | Rik Hemsley (C) 2001. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | //US #include <config.h> | 34 | //US #include <config.h> |
35 | 35 | ||
36 | #include <stdio.h> | 36 | #include <stdio.h> |
37 | #include <string.h> | 37 | #include <string.h> |
38 | #include <stdlib.h> | 38 | #include <stdlib.h> |
39 | 39 | ||
40 | #include <kdebug.h> | 40 | #include <kdebug.h> |
41 | #include "kmdcodec.h" | 41 | #include "kmdcodec.h" |
42 | //Added by qt3to4: | ||
43 | #include <Q3CString> | ||
42 | 44 | ||
43 | #define KMD5_S11 7 | 45 | #define KMD5_S11 7 |
44 | #define KMD5_S12 12 | 46 | #define KMD5_S12 12 |
45 | #define KMD5_S13 17 | 47 | #define KMD5_S13 17 |
46 | #define KMD5_S14 22 | 48 | #define KMD5_S14 22 |
47 | #define KMD5_S21 5 | 49 | #define KMD5_S21 5 |
48 | #define KMD5_S22 9 | 50 | #define KMD5_S22 9 |
49 | #define KMD5_S23 14 | 51 | #define KMD5_S23 14 |
50 | #define KMD5_S24 20 | 52 | #define KMD5_S24 20 |
51 | #define KMD5_S31 4 | 53 | #define KMD5_S31 4 |
52 | #define KMD5_S32 11 | 54 | #define KMD5_S32 11 |
53 | #define KMD5_S33 16 | 55 | #define KMD5_S33 16 |
54 | #define KMD5_S34 23 | 56 | #define KMD5_S34 23 |
55 | #define KMD5_S41 6 | 57 | #define KMD5_S41 6 |
56 | #define KMD5_S42 10 | 58 | #define KMD5_S42 10 |
57 | #define KMD5_S43 15 | 59 | #define KMD5_S43 15 |
58 | #define KMD5_S44 21 | 60 | #define KMD5_S44 21 |
59 | 61 | ||
60 | const char KCodecs::Base64EncMap[64] = | 62 | const char KCodecs::Base64EncMap[64] = |
61 | { | 63 | { |
62 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, | 64 | 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, |
63 | 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, | 65 | 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, |
64 | 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, | 66 | 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, |
65 | 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, | 67 | 0x59, 0x5A, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, |
66 | 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, | 68 | 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, |
67 | 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, | 69 | 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, |
68 | 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, | 70 | 0x77, 0x78, 0x79, 0x7A, 0x30, 0x31, 0x32, 0x33, |
69 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F | 71 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2B, 0x2F |
70 | }; | 72 | }; |
71 | 73 | ||
72 | const char KCodecs::Base64DecMap[128] = | 74 | const char KCodecs::Base64DecMap[128] = |
73 | { | 75 | { |
@@ -118,72 +120,72 @@ const char KCodecs::UUDecMap[128] = | |||
118 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 120 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
119 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 121 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
120 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 122 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
121 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 | 123 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
122 | }; | 124 | }; |
123 | 125 | ||
124 | const char KCodecs::hexChars[16] = | 126 | const char KCodecs::hexChars[16] = |
125 | { | 127 | { |
126 | '0', '1', '2', '3', '4', '5', '6', '7', | 128 | '0', '1', '2', '3', '4', '5', '6', '7', |
127 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' | 129 | '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' |
128 | }; | 130 | }; |
129 | 131 | ||
130 | const unsigned int KCodecs::maxQPLineLength = 70; | 132 | const unsigned int KCodecs::maxQPLineLength = 70; |
131 | 133 | ||
132 | 134 | ||
133 | /******************************** KCodecs ********************************/ | 135 | /******************************** KCodecs ********************************/ |
134 | // strchr(3) for broken systems. | 136 | // strchr(3) for broken systems. |
135 | static int rikFindChar(register const char * _s, const char c) | 137 | static int rikFindChar(register const char * _s, const char c) |
136 | { | 138 | { |
137 | register const char * s = _s; | 139 | register const char * s = _s; |
138 | 140 | ||
139 | while (true) | 141 | while (true) |
140 | { | 142 | { |
141 | if ((0 == *s) || (c == *s)) break; ++s; | 143 | if ((0 == *s) || (c == *s)) break; ++s; |
142 | if ((0 == *s) || (c == *s)) break; ++s; | 144 | if ((0 == *s) || (c == *s)) break; ++s; |
143 | if ((0 == *s) || (c == *s)) break; ++s; | 145 | if ((0 == *s) || (c == *s)) break; ++s; |
144 | if ((0 == *s) || (c == *s)) break; ++s; | 146 | if ((0 == *s) || (c == *s)) break; ++s; |
145 | } | 147 | } |
146 | 148 | ||
147 | return s - _s; | 149 | return s - _s; |
148 | } | 150 | } |
149 | 151 | ||
150 | QCString KCodecs::quotedPrintableEncode(const QByteArray& in, bool useCRLF) | 152 | Q3CString KCodecs::quotedPrintableEncode(const QByteArray& in, bool useCRLF) |
151 | { | 153 | { |
152 | QByteArray out; | 154 | QByteArray out; |
153 | quotedPrintableEncode (in, out, useCRLF); | 155 | quotedPrintableEncode (in, out, useCRLF); |
154 | return QCString (out.data(), out.size()+1); | 156 | return Q3CString (out.data(), out.size()+1); |
155 | } | 157 | } |
156 | 158 | ||
157 | QCString KCodecs::quotedPrintableEncode(const QCString& str, bool useCRLF) | 159 | Q3CString KCodecs::quotedPrintableEncode(const Q3CString& str, bool useCRLF) |
158 | { | 160 | { |
159 | if (str.isEmpty()) | 161 | if (str.isEmpty()) |
160 | return ""; | 162 | return ""; |
161 | 163 | ||
162 | QByteArray in (str.length()); | 164 | QByteArray in (str.length()); |
163 | memcpy (in.data(), str.data(), str.length()); | 165 | memcpy (in.data(), str.data(), str.length()); |
164 | return quotedPrintableEncode(in, useCRLF); | 166 | return quotedPrintableEncode(in, useCRLF); |
165 | } | 167 | } |
166 | 168 | ||
167 | void KCodecs::quotedPrintableEncode(const QByteArray& in, QByteArray& out, bool useCRLF) | 169 | void KCodecs::quotedPrintableEncode(const QByteArray& in, QByteArray& out, bool useCRLF) |
168 | { | 170 | { |
169 | out.resize (0); | 171 | out.resize (0); |
170 | if (in.isEmpty()) | 172 | if (in.isEmpty()) |
171 | return; | 173 | return; |
172 | 174 | ||
173 | char *cursor; | 175 | char *cursor; |
174 | const char *data; | 176 | const char *data; |
175 | unsigned int lineLength; | 177 | unsigned int lineLength; |
176 | unsigned int pos; | 178 | unsigned int pos; |
177 | 179 | ||
178 | const unsigned int length = in.size(); | 180 | const unsigned int length = in.size(); |
179 | const unsigned int end = length - 1; | 181 | const unsigned int end = length - 1; |
180 | 182 | ||
181 | 183 | ||
182 | // Reasonable guess for output size when we're encoding | 184 | // Reasonable guess for output size when we're encoding |
183 | // mostly-ASCII data. It doesn't really matter, because | 185 | // mostly-ASCII data. It doesn't really matter, because |
184 | // the underlying allocation routines are quite efficient, | 186 | // the underlying allocation routines are quite efficient, |
185 | // but it's nice to have 0 allocations in many cases. | 187 | // but it's nice to have 0 allocations in many cases. |
186 | out.resize ((length*12)/10); | 188 | out.resize ((length*12)/10); |
187 | cursor = out.data(); | 189 | cursor = out.data(); |
188 | data = in.data(); | 190 | data = in.data(); |
189 | lineLength = 0; | 191 | lineLength = 0; |
@@ -251,72 +253,72 @@ void KCodecs::quotedPrintableEncode(const QByteArray& in, QByteArray& out, bool | |||
251 | 253 | ||
252 | // Anything else is converted to =XX. | 254 | // Anything else is converted to =XX. |
253 | 255 | ||
254 | else | 256 | else |
255 | { | 257 | { |
256 | *cursor++ = '='; | 258 | *cursor++ = '='; |
257 | *cursor++ = hexChars[c / 16]; | 259 | *cursor++ = hexChars[c / 16]; |
258 | *cursor++ = hexChars[c % 16]; | 260 | *cursor++ = hexChars[c % 16]; |
259 | 261 | ||
260 | lineLength += 3; | 262 | lineLength += 3; |
261 | } | 263 | } |
262 | 264 | ||
263 | // If we're approaching the maximum line length, do a soft line break. | 265 | // If we're approaching the maximum line length, do a soft line break. |
264 | 266 | ||
265 | if ((lineLength > maxQPLineLength) && (i < end)) | 267 | if ((lineLength > maxQPLineLength) && (i < end)) |
266 | { | 268 | { |
267 | if (useCRLF) { | 269 | if (useCRLF) { |
268 | *cursor++ = '='; | 270 | *cursor++ = '='; |
269 | *cursor++ = '\r'; | 271 | *cursor++ = '\r'; |
270 | *cursor++ = '\n'; | 272 | *cursor++ = '\n'; |
271 | } else { | 273 | } else { |
272 | *cursor++ = '='; | 274 | *cursor++ = '='; |
273 | *cursor++ = '\n'; | 275 | *cursor++ = '\n'; |
274 | } | 276 | } |
275 | 277 | ||
276 | lineLength = 0; | 278 | lineLength = 0; |
277 | } | 279 | } |
278 | } | 280 | } |
279 | 281 | ||
280 | out.truncate(cursor - out.data()); | 282 | out.truncate(cursor - out.data()); |
281 | } | 283 | } |
282 | 284 | ||
283 | QCString KCodecs::quotedPrintableDecode(const QByteArray & in) | 285 | Q3CString KCodecs::quotedPrintableDecode(const QByteArray & in) |
284 | { | 286 | { |
285 | QByteArray out; | 287 | QByteArray out; |
286 | quotedPrintableDecode (in, out); | 288 | quotedPrintableDecode (in, out); |
287 | return QCString (out.data(), out.size()+1); | 289 | return Q3CString (out.data(), out.size()+1); |
288 | } | 290 | } |
289 | 291 | ||
290 | QCString KCodecs::quotedPrintableDecode(const QCString & str) | 292 | Q3CString KCodecs::quotedPrintableDecode(const Q3CString & str) |
291 | { | 293 | { |
292 | if (str.isEmpty()) | 294 | if (str.isEmpty()) |
293 | return ""; | 295 | return ""; |
294 | 296 | ||
295 | QByteArray in (str.length()); | 297 | QByteArray in (str.length()); |
296 | memcpy (in.data(), str.data(), str.length()); | 298 | memcpy (in.data(), str.data(), str.length()); |
297 | return quotedPrintableDecode (in); | 299 | return quotedPrintableDecode (in); |
298 | } | 300 | } |
299 | 301 | ||
300 | void KCodecs::quotedPrintableDecode(const QByteArray& in, QByteArray& out) | 302 | void KCodecs::quotedPrintableDecode(const QByteArray& in, QByteArray& out) |
301 | { | 303 | { |
302 | // clear out the output buffer | 304 | // clear out the output buffer |
303 | out.resize (0); | 305 | out.resize (0); |
304 | if (in.isEmpty()) | 306 | if (in.isEmpty()) |
305 | return; | 307 | return; |
306 | 308 | ||
307 | char *cursor; | 309 | char *cursor; |
308 | const char *data; | 310 | const char *data; |
309 | const unsigned int length = in.size(); | 311 | const unsigned int length = in.size(); |
310 | 312 | ||
311 | data = in.data(); | 313 | data = in.data(); |
312 | out.resize (length); | 314 | out.resize (length); |
313 | cursor = out.data(); | 315 | cursor = out.data(); |
314 | 316 | ||
315 | for (unsigned int i = 0; i < length; i++) | 317 | for (unsigned int i = 0; i < length; i++) |
316 | { | 318 | { |
317 | char c(in.at(i)); | 319 | char c(in.at(i)); |
318 | 320 | ||
319 | if ('=' == c) | 321 | if ('=' == c) |
320 | { | 322 | { |
321 | if (i < length - 2) | 323 | if (i < length - 2) |
322 | { | 324 | { |
@@ -326,482 +328,479 @@ void KCodecs::quotedPrintableDecode(const QByteArray& in, QByteArray& out) | |||
326 | if (('\n' == c1) || ('\r' == c1 && '\n' == c2)) | 328 | if (('\n' == c1) || ('\r' == c1 && '\n' == c2)) |
327 | { | 329 | { |
328 | // Soft line break. No output. | 330 | // Soft line break. No output. |
329 | if ('\r' == c1) | 331 | if ('\r' == c1) |
330 | i += 2; // CRLF line breaks | 332 | i += 2; // CRLF line breaks |
331 | else | 333 | else |
332 | i += 1; | 334 | i += 1; |
333 | } | 335 | } |
334 | else | 336 | else |
335 | { | 337 | { |
336 | // =XX encoded byte. | 338 | // =XX encoded byte. |
337 | 339 | ||
338 | int hexChar0 = rikFindChar(hexChars, c1); | 340 | int hexChar0 = rikFindChar(hexChars, c1); |
339 | int hexChar1 = rikFindChar(hexChars, c2); | 341 | int hexChar1 = rikFindChar(hexChars, c2); |
340 | 342 | ||
341 | if (hexChar0 < 16 && hexChar1 < 16) | 343 | if (hexChar0 < 16 && hexChar1 < 16) |
342 | { | 344 | { |
343 | *cursor++ = char((hexChar0 * 16) | hexChar1); | 345 | *cursor++ = char((hexChar0 * 16) | hexChar1); |
344 | i += 2; | 346 | i += 2; |
345 | } | 347 | } |
346 | } | 348 | } |
347 | } | 349 | } |
348 | } | 350 | } |
349 | else | 351 | else |
350 | { | 352 | { |
351 | *cursor++ = c; | 353 | *cursor++ = c; |
352 | } | 354 | } |
353 | } | 355 | } |
354 | 356 | ||
355 | out.truncate(cursor - out.data()); | 357 | out.truncate(cursor - out.data()); |
356 | } | 358 | } |
357 | 359 | ||
358 | QCString KCodecs::base64Encode( const QCString& str, bool insertLFs ) | 360 | Q3CString KCodecs::base64Encode( const Q3CString& str, bool insertLFs ) |
359 | { | 361 | { |
360 | if ( str.isEmpty() ) | 362 | if ( str.isEmpty() ) |
361 | return ""; | 363 | return ""; |
362 | 364 | ||
363 | QByteArray in (str.length()); | 365 | QByteArray in (str.length()); |
364 | memcpy( in.data(), str.data(), str.length() ); | 366 | memcpy( in.data(), str.data(), str.length() ); |
365 | return base64Encode( in, insertLFs ); | 367 | return base64Encode( in, insertLFs ); |
366 | } | 368 | } |
367 | 369 | ||
368 | QCString KCodecs::base64Encode( const QByteArray& in, bool insertLFs ) | 370 | Q3CString KCodecs::base64Encode( const QByteArray& in, bool insertLFs ) |
369 | { | 371 | { |
370 | QByteArray out; | 372 | QByteArray out; |
371 | base64Encode( in, out, insertLFs ); | 373 | base64Encode( in, out, insertLFs ); |
372 | return QCString( out.data(), out.size()+1 ); | 374 | return Q3CString( out.data(), out.size()+1 ); |
373 | } | 375 | } |
374 | 376 | ||
375 | void KCodecs::base64Encode( const QByteArray& in, QByteArray& out, | 377 | void KCodecs::base64Encode( const QByteArray& in, QByteArray& out, |
376 | bool insertLFs ) | 378 | bool insertLFs ) |
377 | { | 379 | { |
378 | // clear out the output buffer | 380 | // clear out the output buffer |
379 | out.resize (0); | 381 | out.resize (0); |
380 | if ( in.isEmpty() ) | 382 | if ( in.isEmpty() ) |
381 | return; | 383 | return; |
382 | 384 | ||
383 | unsigned int sidx = 0; | 385 | unsigned int sidx = 0; |
384 | unsigned int didx = 0; | 386 | unsigned int didx = 0; |
385 | const char* data = in.data(); | 387 | const char* data = in.data(); |
386 | const unsigned int len = in.size(); | 388 | const unsigned int len = in.size(); |
387 | 389 | ||
388 | unsigned int out_len = ((len+2)/3)*4; | 390 | unsigned int out_len = ((len+2)/3)*4; |
389 | 391 | ||
390 | // Deal with the 76 characters or less per | 392 | // Deal with the 76 characters or less per |
391 | // line limit specified in RFC 2045 on a | 393 | // line limit specified in RFC 2045 on a |
392 | // pre request basis. | 394 | // pre request basis. |
393 | insertLFs = (insertLFs && out_len > 76); | 395 | insertLFs = (insertLFs && out_len > 76); |
394 | if ( insertLFs ) | 396 | if ( insertLFs ) |
395 | out_len += ((out_len-1)/76); | 397 | out_len += ((out_len-1)/76); |
396 | 398 | ||
397 | int count = 0; | 399 | int count = 0; |
398 | out.resize( out_len ); | 400 | out.resize( out_len ); |
399 | 401 | ||
400 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion | 402 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion |
401 | if ( len > 1 ) | 403 | if ( len > 1 ) |
402 | { | 404 | { |
403 | while (sidx < len-2) | 405 | while (sidx < len-2) |
404 | { | 406 | { |
405 | if ( insertLFs ) | 407 | if ( insertLFs ) |
406 | { | 408 | { |
407 | if ( count && (count%76) == 0 ) | 409 | if ( count && (count%76) == 0 ) |
408 | out.at(didx++) = '\n'; | 410 | out[didx++] = '\n'; |
409 | count += 4; | 411 | count += 4; |
410 | } | 412 | } |
411 | out.at(didx++) = Base64EncMap[(data[sidx] >> 2) & 077]; | 413 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; |
412 | out.at(didx++) = Base64EncMap[(data[sidx+1] >> 4) & 017 | | 414 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | |
413 | (data[sidx] << 4) & 077]; | 415 | (data[sidx] << 4) & 077]; |
414 | out.at(didx++) = Base64EncMap[(data[sidx+2] >> 6) & 003 | | 416 | out[didx++] = Base64EncMap[(data[sidx+2] >> 6) & 003 | |
415 | (data[sidx+1] << 2) & 077]; | 417 | (data[sidx+1] << 2) & 077]; |
416 | out.at(didx++) = Base64EncMap[data[sidx+2] & 077]; | 418 | out[didx++] = Base64EncMap[data[sidx+2] & 077]; |
417 | sidx += 3; | 419 | sidx += 3; |
418 | } | 420 | } |
419 | } | 421 | } |
420 | 422 | ||
421 | if (sidx < len) | 423 | if (sidx < len) |
422 | { | 424 | { |
423 | if ( insertLFs && (count > 0) && (count%76) == 0 ) | 425 | if ( insertLFs && (count > 0) && (count%76) == 0 ) |
424 | out.at(didx++) = '\n'; | 426 | out[didx++] = '\n'; |
425 | 427 | ||
426 | out.at(didx++) = Base64EncMap[(data[sidx] >> 2) & 077]; | 428 | out[didx++] = Base64EncMap[(data[sidx] >> 2) & 077]; |
427 | if (sidx < len-1) | 429 | if (sidx < len-1) |
428 | { | 430 | { |
429 | out.at(didx++) = Base64EncMap[(data[sidx+1] >> 4) & 017 | | 431 | out[didx++] = Base64EncMap[(data[sidx+1] >> 4) & 017 | |
430 | (data[sidx] << 4) & 077]; | 432 | (data[sidx] << 4) & 077]; |
431 | out.at(didx++) = Base64EncMap[(data[sidx+1] << 2) & 077]; | 433 | out[didx++] = Base64EncMap[(data[sidx+1] << 2) & 077]; |
432 | } | 434 | } |
433 | else | 435 | else |
434 | { | 436 | { |
435 | out.at(didx++) = Base64EncMap[(data[sidx] << 4) & 077]; | 437 | out[didx++] = Base64EncMap[(data[sidx] << 4) & 077]; |
436 | } | 438 | } |
437 | } | 439 | } |
438 | 440 | ||
439 | // Add padding | 441 | // Add padding |
440 | while (didx < out.size()) | 442 | while (didx < out.size()) |
441 | { | 443 | out[didx++] = '='; |
442 | out.at(didx) = '='; | ||
443 | didx++; | ||
444 | } | ||
445 | } | 444 | } |
446 | 445 | ||
447 | QCString KCodecs::base64Decode( const QCString& str ) | 446 | Q3CString KCodecs::base64Decode( const Q3CString& str ) |
448 | { | 447 | { |
449 | if ( str.isEmpty() ) | 448 | if ( str.isEmpty() ) |
450 | return ""; | 449 | return ""; |
451 | 450 | ||
452 | QByteArray in( str.length() ); | 451 | QByteArray in( str.length() ); |
453 | memcpy( in.data(), str.data(), str.length() ); | 452 | memcpy( in.data(), str.data(), str.length() ); |
454 | return base64Decode( in ); | 453 | return base64Decode( in ); |
455 | } | 454 | } |
456 | 455 | ||
457 | QCString KCodecs::base64Decode( const QByteArray& in ) | 456 | Q3CString KCodecs::base64Decode( const QByteArray& in ) |
458 | { | 457 | { |
459 | QByteArray out; | 458 | QByteArray out; |
460 | base64Decode( in, out ); | 459 | base64Decode( in, out ); |
461 | return QCString( out.data(), out.size()+1 ); | 460 | return Q3CString( out.data(), out.size()+1 ); |
462 | } | 461 | } |
463 | 462 | ||
464 | void KCodecs::base64Decode( const QByteArray& in, QByteArray& out ) | 463 | void KCodecs::base64Decode( const QByteArray& in, QByteArray& out ) |
465 | { | 464 | { |
466 | out.resize(0); | 465 | out.resize(0); |
467 | if ( in.isEmpty() ) | 466 | if ( in.isEmpty() ) |
468 | return; | 467 | return; |
469 | 468 | ||
470 | unsigned int count = 0; | 469 | unsigned int count = 0; |
471 | unsigned int len = in.size(), tail = len; | 470 | unsigned int len = in.size(), tail = len; |
472 | const char* data = in.data(); | 471 | const char* data = in.data(); |
473 | 472 | ||
474 | // Deal with possible *nix "BEGIN" marker!! | 473 | // Deal with possible *nix "BEGIN" marker!! |
475 | while ( count < len && (data[count] == '\n' || data[count] == '\r' || | 474 | while ( count < len && (data[count] == '\n' || data[count] == '\r' || |
476 | data[count] == '\t' || data[count] == ' ') ) | 475 | data[count] == '\t' || data[count] == ' ') ) |
477 | count++; | 476 | count++; |
478 | 477 | ||
479 | if ( QString(data+count).left(5).lower() == "begin" ) | 478 | if ( QString(data+count).left(5).lower() == "begin" ) |
480 | { | 479 | { |
481 | count += 5; | 480 | count += 5; |
482 | while ( count < len && data[count] != '\n' && data[count] != '\r' ) | 481 | while ( count < len && data[count] != '\n' && data[count] != '\r' ) |
483 | count++; | 482 | count++; |
484 | 483 | ||
485 | while ( count < len && (data[count] == '\n' || data[count] == '\r') ) | 484 | while ( count < len && (data[count] == '\n' || data[count] == '\r') ) |
486 | count ++; | 485 | count ++; |
487 | 486 | ||
488 | data += count; | 487 | data += count; |
489 | tail = (len -= count); | 488 | tail = (len -= count); |
490 | } | 489 | } |
491 | 490 | ||
492 | // Find the tail end of the actual encoded data even if | 491 | // Find the tail end of the actual encoded data even if |
493 | // there is/are trailing CR and/or LF. | 492 | // there is/are trailing CR and/or LF. |
494 | while ( data[tail-1] == '=' || data[tail-1] == '\n' || | 493 | while ( data[tail-1] == '=' || data[tail-1] == '\n' || |
495 | data[tail-1] == '\r' ) | 494 | data[tail-1] == '\r' ) |
496 | if ( data[--tail] != '=' ) len = tail; | 495 | if ( data[--tail] != '=' ) len = tail; |
497 | 496 | ||
498 | unsigned int outIdx = 0; | 497 | unsigned int outIdx = 0; |
499 | out.resize( (count=len) ); | 498 | out.resize( (count=len) ); |
500 | for (unsigned int idx = 0; idx < count; idx++) | 499 | for (unsigned int idx = 0; idx < count; idx++) |
501 | { | 500 | { |
502 | // Adhere to RFC 2045 and ignore characters | 501 | // Adhere to RFC 2045 and ignore characters |
503 | // that are not part of the encoding table. | 502 | // that are not part of the encoding table. |
504 | unsigned char ch = data[idx]; | 503 | unsigned char ch = data[idx]; |
505 | if ((ch > 47 && ch < 58) || (ch > 64 && ch < 91) || | 504 | if ((ch > 47 && ch < 58) || (ch > 64 && ch < 91) || |
506 | (ch > 96 && ch < 123) || ch == '+' || ch == '/' || ch == '=') | 505 | (ch > 96 && ch < 123) || ch == '+' || ch == '/' || ch == '=') |
507 | { | 506 | { |
508 | out.at(outIdx++) = Base64DecMap[ch]; | 507 | out[outIdx++] = Base64DecMap[ch]; |
509 | } | 508 | } |
510 | else | 509 | else |
511 | { | 510 | { |
512 | len--; | 511 | len--; |
513 | tail--; | 512 | tail--; |
514 | } | 513 | } |
515 | } | 514 | } |
516 | 515 | ||
517 | // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; | 516 | // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; |
518 | 517 | ||
519 | // 4-byte to 3-byte conversion | 518 | // 4-byte to 3-byte conversion |
520 | len = (tail>(len/4)) ? tail-(len/4) : 0; | 519 | len = (tail>(len/4)) ? tail-(len/4) : 0; |
521 | unsigned int sidx = 0, didx = 0; | 520 | unsigned int sidx = 0, didx = 0; |
522 | if ( len > 1 ) | 521 | if ( len > 1 ) |
523 | { | 522 | { |
524 | while (didx < len-2) | 523 | while (didx < len-2) |
525 | { | 524 | { |
526 | out.at(didx) = (((out.at(sidx) << 2) & 255) | ((out.at(sidx+1) >> 4) & 003)); | 525 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); |
527 | out.at(didx+1) = (((out.at(sidx+1) << 4) & 255) | ((out.at(sidx+2) >> 2) & 017)); | 526 | out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); |
528 | out.at(didx+2) = (((out.at(sidx+2) << 6) & 255) | (out.at(sidx+3) & 077)); | 527 | out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077)); |
529 | sidx += 4; | 528 | sidx += 4; |
530 | didx += 3; | 529 | didx += 3; |
531 | } | 530 | } |
532 | } | 531 | } |
533 | 532 | ||
534 | if (didx < len) | 533 | if (didx < len) |
535 | out.at(didx) = (((out.at(sidx) << 2) & 255) | ((out.at(sidx+1) >> 4) & 003)); | 534 | out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); |
536 | 535 | ||
537 | if (++didx < len ) | 536 | if (++didx < len ) |
538 | out.at(didx) = (((out.at(sidx+1) << 4) & 255) | ((out.at(sidx+2) >> 2) & 017)); | 537 | out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); |
539 | 538 | ||
540 | // Resize the output buffer | 539 | // Resize the output buffer |
541 | if ( len == 0 || len < out.size() ) | 540 | if ( len == 0 || len < out.size() ) |
542 | out.resize(len); | 541 | out.resize(len); |
543 | } | 542 | } |
544 | 543 | ||
545 | QCString KCodecs::uuencode( const QCString& str ) | 544 | Q3CString KCodecs::uuencode( const Q3CString& str ) |
546 | { | 545 | { |
547 | if ( str.isEmpty() ) | 546 | if ( str.isEmpty() ) |
548 | return ""; | 547 | return ""; |
549 | 548 | ||
550 | QByteArray in; | 549 | QByteArray in; |
551 | in.resize( str.length() ); | 550 | in.resize( str.length() ); |
552 | memcpy( in.data(), str.data(), str.length() ); | 551 | memcpy( in.data(), str.data(), str.length() ); |
553 | return uuencode( in ); | 552 | return uuencode( in ); |
554 | } | 553 | } |
555 | 554 | ||
556 | QCString KCodecs::uuencode( const QByteArray& in ) | 555 | Q3CString KCodecs::uuencode( const QByteArray& in ) |
557 | { | 556 | { |
558 | QByteArray out; | 557 | QByteArray out; |
559 | uuencode( in, out ); | 558 | uuencode( in, out ); |
560 | return QCString( out.data(), out.size()+1 ); | 559 | return Q3CString( out.data(), out.size()+1 ); |
561 | } | 560 | } |
562 | 561 | ||
563 | void KCodecs::uuencode( const QByteArray& in, QByteArray& out ) | 562 | void KCodecs::uuencode( const QByteArray& in, QByteArray& out ) |
564 | { | 563 | { |
565 | out.resize( 0 ); | 564 | out.resize( 0 ); |
566 | if( in.isEmpty() ) | 565 | if( in.isEmpty() ) |
567 | return; | 566 | return; |
568 | 567 | ||
569 | unsigned int sidx = 0; | 568 | unsigned int sidx = 0; |
570 | unsigned int didx = 0; | 569 | unsigned int didx = 0; |
571 | unsigned int line_len = 45; | 570 | unsigned int line_len = 45; |
572 | 571 | ||
573 | const char nl[] = "\n"; | 572 | const char nl[] = "\n"; |
574 | const char* data = in.data(); | 573 | const char* data = in.data(); |
575 | const unsigned int nl_len = strlen(nl); | 574 | const unsigned int nl_len = strlen(nl); |
576 | const unsigned int len = in.size(); | 575 | const unsigned int len = in.size(); |
577 | 576 | ||
578 | out.resize( (len+2)/3*4 + ((len+line_len-1)/line_len)*(nl_len+1) ); | 577 | out.resize( (len+2)/3*4 + ((len+line_len-1)/line_len)*(nl_len+1) ); |
579 | // split into lines, adding line-length and line terminator | 578 | // split into lines, adding line-length and line terminator |
580 | while (sidx+line_len < len) | 579 | while (sidx+line_len < len) |
581 | { | 580 | { |
582 | // line length | 581 | // line length |
583 | out.at(didx++) = UUEncMap[line_len]; | 582 | out[didx++] = UUEncMap[line_len]; |
584 | 583 | ||
585 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion | 584 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion |
586 | for (unsigned int end = sidx+line_len; sidx < end; sidx += 3) | 585 | for (unsigned int end = sidx+line_len; sidx < end; sidx += 3) |
587 | { | 586 | { |
588 | out.at(didx++) = UUEncMap[(data[sidx] >> 2) & 077]; | 587 | out[didx++] = UUEncMap[(data[sidx] >> 2) & 077]; |
589 | out.at(didx++) = UUEncMap[(data[sidx+1] >> 4) & 017 | | 588 | out[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 | |
590 | (data[sidx] << 4) & 077]; | 589 | (data[sidx] << 4) & 077]; |
591 | out.at(didx++) = UUEncMap[(data[sidx+2] >> 6) & 003 | | 590 | out[didx++] = UUEncMap[(data[sidx+2] >> 6) & 003 | |
592 | (data[sidx+1] << 2) & 077]; | 591 | (data[sidx+1] << 2) & 077]; |
593 | out.at(didx++) = UUEncMap[data[sidx+2] & 077]; | 592 | out[didx++] = UUEncMap[data[sidx+2] & 077]; |
594 | } | 593 | } |
595 | 594 | ||
596 | // line terminator | 595 | // line terminator |
597 | //for (unsigned int idx=0; idx < nl_len; idx++) | 596 | //for (unsigned int idx=0; idx < nl_len; idx++) |
598 | //out.at(didx++) = nl[idx]; | 597 | //out[didx++] = nl[idx]; |
599 | memcpy(out.data()+didx, nl, nl_len); | 598 | memcpy(out.data()+didx, nl, nl_len); |
600 | didx += nl_len; | 599 | didx += nl_len; |
601 | } | 600 | } |
602 | 601 | ||
603 | // line length | 602 | // line length |
604 | out.at(didx++) = UUEncMap[len-sidx]; | 603 | out[didx++] = UUEncMap[len-sidx]; |
605 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion | 604 | // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion |
606 | while (sidx+2 < len) | 605 | while (sidx+2 < len) |
607 | { | 606 | { |
608 | out.at(didx++) = UUEncMap[(data[sidx] >> 2) & 077]; | 607 | out[didx++] = UUEncMap[(data[sidx] >> 2) & 077]; |
609 | out.at(didx++) = UUEncMap[(data[sidx+1] >> 4) & 017 | | 608 | out[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 | |
610 | (data[sidx] << 4) & 077]; | 609 | (data[sidx] << 4) & 077]; |
611 | out.at(didx++) = UUEncMap[(data[sidx+2] >> 6) & 003 | | 610 | out[didx++] = UUEncMap[(data[sidx+2] >> 6) & 003 | |
612 | (data[sidx+1] << 2) & 077]; | 611 | (data[sidx+1] << 2) & 077]; |
613 | out.at(didx++) = UUEncMap[data[sidx+2] & 077]; | 612 | out[didx++] = UUEncMap[data[sidx+2] & 077]; |
614 | sidx += 3; | 613 | sidx += 3; |
615 | } | 614 | } |
616 | 615 | ||
617 | if (sidx < len-1) | 616 | if (sidx < len-1) |
618 | { | 617 | { |
619 | out.at(didx++) = UUEncMap[(data[sidx] >> 2) & 077]; | 618 | out[didx++] = UUEncMap[(data[sidx] >> 2) & 077]; |
620 | out.at(didx++) = UUEncMap[(data[sidx+1] >> 4) & 017 | | 619 | out[didx++] = UUEncMap[(data[sidx+1] >> 4) & 017 | |
621 | (data[sidx] << 4) & 077]; | 620 | (data[sidx] << 4) & 077]; |
622 | out.at(didx++) = UUEncMap[(data[sidx+1] << 2) & 077]; | 621 | out[didx++] = UUEncMap[(data[sidx+1] << 2) & 077]; |
623 | out.at(didx++) = UUEncMap[0]; | 622 | out[didx++] = UUEncMap[0]; |
624 | } | 623 | } |
625 | else if (sidx < len) | 624 | else if (sidx < len) |
626 | { | 625 | { |
627 | out.at(didx++) = UUEncMap[(data[sidx] >> 2) & 077]; | 626 | out[didx++] = UUEncMap[(data[sidx] >> 2) & 077]; |
628 | out.at(didx++) = UUEncMap[(data[sidx] << 4) & 077]; | 627 | out[didx++] = UUEncMap[(data[sidx] << 4) & 077]; |
629 | out.at(didx++) = UUEncMap[0]; | 628 | out[didx++] = UUEncMap[0]; |
630 | out.at(didx++) = UUEncMap[0]; | 629 | out[didx++] = UUEncMap[0]; |
631 | } | 630 | } |
632 | 631 | ||
633 | // line terminator | 632 | // line terminator |
634 | memcpy(out.data()+didx, nl, nl_len); | 633 | memcpy(out.data()+didx, nl, nl_len); |
635 | didx += nl_len; | 634 | didx += nl_len; |
636 | 635 | ||
637 | // sanity check | 636 | // sanity check |
638 | if ( didx != out.size() ) | 637 | if ( didx != out.size() ) |
639 | out.resize( 0 ); | 638 | out.resize( 0 ); |
640 | } | 639 | } |
641 | 640 | ||
642 | QCString KCodecs::uudecode( const QCString& str ) | 641 | Q3CString KCodecs::uudecode( const Q3CString& str ) |
643 | { | 642 | { |
644 | if ( str.isEmpty() ) | 643 | if ( str.isEmpty() ) |
645 | return ""; | 644 | return ""; |
646 | 645 | ||
647 | QByteArray in; | 646 | QByteArray in; |
648 | in.resize( str.length() ); | 647 | in.resize( str.length() ); |
649 | memcpy( in.data(), str.data(), str.length() ); | 648 | memcpy( in.data(), str.data(), str.length() ); |
650 | return uudecode( in ); | 649 | return uudecode( in ); |
651 | } | 650 | } |
652 | 651 | ||
653 | QCString KCodecs::uudecode( const QByteArray& in ) | 652 | Q3CString KCodecs::uudecode( const QByteArray& in ) |
654 | { | 653 | { |
655 | QByteArray out; | 654 | QByteArray out; |
656 | uudecode( in, out ); | 655 | uudecode( in, out ); |
657 | return QCString( out.data(), out.size()+1 ); | 656 | return Q3CString( out.data(), out.size()+1 ); |
658 | } | 657 | } |
659 | 658 | ||
660 | void KCodecs::uudecode( const QByteArray& in, QByteArray& out ) | 659 | void KCodecs::uudecode( const QByteArray& in, QByteArray& out ) |
661 | { | 660 | { |
662 | out.resize( 0 ); | 661 | out.resize( 0 ); |
663 | if( in.isEmpty() ) | 662 | if( in.isEmpty() ) |
664 | return; | 663 | return; |
665 | 664 | ||
666 | unsigned int sidx = 0; | 665 | unsigned int sidx = 0; |
667 | unsigned int didx = 0; | 666 | unsigned int didx = 0; |
668 | unsigned int len = in.size(); | 667 | unsigned int len = in.size(); |
669 | unsigned int line_len, end; | 668 | unsigned int line_len, end; |
670 | const char* data = in.data(); | 669 | const char* data = in.data(); |
671 | 670 | ||
672 | // Deal with *nix "BEGIN"/"END" separators!! | 671 | // Deal with *nix "BEGIN"/"END" separators!! |
673 | unsigned int count = 0; | 672 | unsigned int count = 0; |
674 | while ( count < len && (data[count] == '\n' || data[count] == '\r' || | 673 | while ( count < len && (data[count] == '\n' || data[count] == '\r' || |
675 | data[count] == '\t' || data[count] == ' ') ) | 674 | data[count] == '\t' || data[count] == ' ') ) |
676 | count ++; | 675 | count ++; |
677 | 676 | ||
678 | bool hasLF = false; | 677 | bool hasLF = false; |
679 | if ( QString( data+count).left(5).lower() == "begin" ) | 678 | if ( QString( data+count).left(5).lower() == "begin" ) |
680 | { | 679 | { |
681 | count += 5; | 680 | count += 5; |
682 | while ( count < len && data[count] != '\n' && data[count] != '\r' ) | 681 | while ( count < len && data[count] != '\n' && data[count] != '\r' ) |
683 | count ++; | 682 | count ++; |
684 | 683 | ||
685 | while ( count < len && (data[count] == '\n' || data[count] == '\r') ) | 684 | while ( count < len && (data[count] == '\n' || data[count] == '\r') ) |
686 | count ++; | 685 | count ++; |
687 | 686 | ||
688 | data += count; | 687 | data += count; |
689 | len -= count; | 688 | len -= count; |
690 | hasLF = true; | 689 | hasLF = true; |
691 | } | 690 | } |
692 | 691 | ||
693 | out.resize( len/4*3 ); | 692 | out.resize( len/4*3 ); |
694 | while ( sidx < len ) | 693 | while ( sidx < len ) |
695 | { | 694 | { |
696 | // get line length (in number of encoded octets) | 695 | // get line length (in number of encoded octets) |
697 | line_len = UUDecMap[ (unsigned char) data[sidx++]]; | 696 | line_len = UUDecMap[ (unsigned char) data[sidx++]]; |
698 | // ascii printable to 0-63 and 4-byte to 3-byte conversion | 697 | // ascii printable to 0-63 and 4-byte to 3-byte conversion |
699 | end = didx+line_len; | 698 | end = didx+line_len; |
700 | char A, B, C, D; | 699 | char A, B, C, D; |
701 | if (end > 2) { | 700 | if (end > 2) { |
702 | while (didx < end-2) | 701 | while (didx < end-2) |
703 | { | 702 | { |
704 | A = UUDecMap[(unsigned char) data[sidx]]; | 703 | A = UUDecMap[(unsigned char) data[sidx]]; |
705 | B = UUDecMap[(unsigned char) data[sidx+1]]; | 704 | B = UUDecMap[(unsigned char) data[sidx+1]]; |
706 | C = UUDecMap[(unsigned char) data[sidx+2]]; | 705 | C = UUDecMap[(unsigned char) data[sidx+2]]; |
707 | D = UUDecMap[(unsigned char) data[sidx+3]]; | 706 | D = UUDecMap[(unsigned char) data[sidx+3]]; |
708 | out.at(didx++) = ( ((A << 2) & 255) | ((B >> 4) & 003) ); | 707 | out[didx++] = ( ((A << 2) & 255) | ((B >> 4) & 003) ); |
709 | out.at(didx++) = ( ((B << 4) & 255) | ((C >> 2) & 017) ); | 708 | out[didx++] = ( ((B << 4) & 255) | ((C >> 2) & 017) ); |
710 | out.at(didx++) = ( ((C << 6) & 255) | (D & 077) ); | 709 | out[didx++] = ( ((C << 6) & 255) | (D & 077) ); |
711 | sidx += 4; | 710 | sidx += 4; |
712 | } | 711 | } |
713 | } | 712 | } |
714 | 713 | ||
715 | if (didx < end) | 714 | if (didx < end) |
716 | { | 715 | { |
717 | A = UUDecMap[(unsigned char) data[sidx]]; | 716 | A = UUDecMap[(unsigned char) data[sidx]]; |
718 | B = UUDecMap[(unsigned char) data[sidx+1]]; | 717 | B = UUDecMap[(unsigned char) data[sidx+1]]; |
719 | out.at(didx++) = ( ((A << 2) & 255) | ((B >> 4) & 003) ); | 718 | out[didx++] = ( ((A << 2) & 255) | ((B >> 4) & 003) ); |
720 | } | 719 | } |
721 | 720 | ||
722 | if (didx < end) | 721 | if (didx < end) |
723 | { | 722 | { |
724 | B = UUDecMap[(unsigned char) data[sidx+1]]; | 723 | B = UUDecMap[(unsigned char) data[sidx+1]]; |
725 | C = UUDecMap[(unsigned char) data[sidx+2]]; | 724 | C = UUDecMap[(unsigned char) data[sidx+2]]; |
726 | out.at(didx++) = ( ((B << 4) & 255) | ((C >> 2) & 017) ); | 725 | out[didx++] = ( ((B << 4) & 255) | ((C >> 2) & 017) ); |
727 | } | 726 | } |
728 | 727 | ||
729 | // skip padding | 728 | // skip padding |
730 | while (sidx < len && data[sidx] != '\n' && data[sidx] != '\r') | 729 | while (sidx < len && data[sidx] != '\n' && data[sidx] != '\r') |
731 | sidx++; | 730 | sidx++; |
732 | 731 | ||
733 | // skip end of line | 732 | // skip end of line |
734 | while (sidx < len && (data[sidx] == '\n' || data[sidx] == '\r')) | 733 | while (sidx < len && (data[sidx] == '\n' || data[sidx] == '\r')) |
735 | sidx++; | 734 | sidx++; |
736 | 735 | ||
737 | // skip the "END" separator when present. | 736 | // skip the "END" separator when present. |
738 | if ( hasLF && QString( data+sidx).left(3).lower() == "end" ) | 737 | if ( hasLF && QString( data+sidx).left(3).lower() == "end" ) |
739 | break; | 738 | break; |
740 | } | 739 | } |
741 | 740 | ||
742 | if ( didx < out.size() ) | 741 | if ( didx < out.size() ) |
743 | out.resize( didx ); | 742 | out.resize( didx ); |
744 | } | 743 | } |
745 | 744 | ||
746 | /******************************** KMD5 ********************************/ | 745 | /******************************** KMD5 ********************************/ |
747 | KMD5::KMD5() | 746 | KMD5::KMD5() |
748 | { | 747 | { |
749 | init(); | 748 | init(); |
750 | } | 749 | } |
751 | 750 | ||
752 | KMD5::KMD5(const char *in, int len) | 751 | KMD5::KMD5(const char *in, int len) |
753 | { | 752 | { |
754 | init(); | 753 | init(); |
755 | update(in, len); | 754 | update(in, len); |
756 | } | 755 | } |
757 | 756 | ||
758 | KMD5::KMD5(const QByteArray& in) | 757 | KMD5::KMD5(const QByteArray& in) |
759 | { | 758 | { |
760 | init(); | 759 | init(); |
761 | update( in ); | 760 | update( in ); |
762 | } | 761 | } |
763 | 762 | ||
764 | KMD5::KMD5(const QCString& in) | 763 | KMD5::KMD5(const Q3CString& in) |
765 | { | 764 | { |
766 | init(); | 765 | init(); |
767 | update( in ); | 766 | update( in ); |
768 | } | 767 | } |
769 | 768 | ||
770 | void KMD5::update(const QByteArray& in) | 769 | void KMD5::update(const QByteArray& in) |
771 | { | 770 | { |
772 | update(in.data(), int(in.size())); | 771 | update(in.data(), int(in.size())); |
773 | } | 772 | } |
774 | 773 | ||
775 | void KMD5::update(const QCString& in) | 774 | void KMD5::update(const Q3CString& in) |
776 | { | 775 | { |
777 | update(in.data(), int(in.length())); | 776 | update(in.data(), int(in.length())); |
778 | } | 777 | } |
779 | 778 | ||
780 | void KMD5::update(const unsigned char* in, int len) | 779 | void KMD5::update(const unsigned char* in, int len) |
781 | { | 780 | { |
782 | if (len < 0) | 781 | if (len < 0) |
783 | len = qstrlen(reinterpret_cast<const char*>(in)); | 782 | len = qstrlen(reinterpret_cast<const char*>(in)); |
784 | 783 | ||
785 | if (!len) | 784 | if (!len) |
786 | return; | 785 | return; |
787 | 786 | ||
788 | if (m_finalized) { | 787 | if (m_finalized) { |
789 | kdWarning() << "KMD5::update called after state was finalized!" << endl; | 788 | kdWarning() << "KMD5::update called after state was finalized!" << endl; |
790 | return; | 789 | return; |
791 | } | 790 | } |
792 | 791 | ||
793 | Q_UINT32 in_index; | 792 | Q_UINT32 in_index; |
794 | Q_UINT32 buffer_index; | 793 | Q_UINT32 buffer_index; |
795 | Q_UINT32 buffer_space; | 794 | Q_UINT32 buffer_space; |
796 | Q_UINT32 in_length = static_cast<Q_UINT32>( len ); | 795 | Q_UINT32 in_length = static_cast<Q_UINT32>( len ); |
797 | 796 | ||
798 | buffer_index = static_cast<Q_UINT32>((m_count[0] >> 3) & 0x3F); | 797 | buffer_index = static_cast<Q_UINT32>((m_count[0] >> 3) & 0x3F); |
799 | 798 | ||
800 | if ( (m_count[0] += (in_length << 3))<(in_length << 3) ) | 799 | if ( (m_count[0] += (in_length << 3))<(in_length << 3) ) |
801 | m_count[1]++; | 800 | m_count[1]++; |
802 | 801 | ||
803 | m_count[1] += (in_length >> 29); | 802 | m_count[1] += (in_length >> 29); |
804 | buffer_space = 64 - buffer_index; | 803 | buffer_space = 64 - buffer_index; |
805 | 804 | ||
806 | if (in_length >= buffer_space) | 805 | if (in_length >= buffer_space) |
807 | { | 806 | { |
@@ -844,148 +843,148 @@ void KMD5::finalize () | |||
844 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 843 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
845 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | 844 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
846 | }; | 845 | }; |
847 | 846 | ||
848 | encode (bits, m_count, 8); | 847 | encode (bits, m_count, 8); |
849 | //memcpy( bits, m_count, 8 ); | 848 | //memcpy( bits, m_count, 8 ); |
850 | 849 | ||
851 | // Pad out to 56 mod 64. | 850 | // Pad out to 56 mod 64. |
852 | index = static_cast<Q_UINT32>((m_count[0] >> 3) & 0x3f); | 851 | index = static_cast<Q_UINT32>((m_count[0] >> 3) & 0x3f); |
853 | padLen = (index < 56) ? (56 - index) : (120 - index); | 852 | padLen = (index < 56) ? (56 - index) : (120 - index); |
854 | update (reinterpret_cast<const char*>(PADDING), padLen); | 853 | update (reinterpret_cast<const char*>(PADDING), padLen); |
855 | 854 | ||
856 | // Append length (before padding) | 855 | // Append length (before padding) |
857 | update (reinterpret_cast<const char*>(bits), 8); | 856 | update (reinterpret_cast<const char*>(bits), 8); |
858 | 857 | ||
859 | // Store state in digest | 858 | // Store state in digest |
860 | encode (m_digest, m_state, 16); | 859 | encode (m_digest, m_state, 16); |
861 | //memcpy( m_digest, m_state, 16 ); | 860 | //memcpy( m_digest, m_state, 16 ); |
862 | 861 | ||
863 | // Fill sensitive information with zero's | 862 | // Fill sensitive information with zero's |
864 | memset ( (void *)m_buffer, 0, sizeof(*m_buffer)); | 863 | memset ( (void *)m_buffer, 0, sizeof(*m_buffer)); |
865 | 864 | ||
866 | m_finalized = true; | 865 | m_finalized = true; |
867 | } | 866 | } |
868 | 867 | ||
869 | 868 | ||
870 | bool KMD5::verify( const KMD5::Digest& digest) | 869 | bool KMD5::verify( const KMD5::Digest& digest) |
871 | { | 870 | { |
872 | finalize(); | 871 | finalize(); |
873 | return (0 == memcmp(rawDigest(), digest, sizeof(KMD5::Digest))); | 872 | return (0 == memcmp(rawDigest(), digest, sizeof(KMD5::Digest))); |
874 | } | 873 | } |
875 | 874 | ||
876 | bool KMD5::verify( const QCString& hexdigest) | 875 | bool KMD5::verify( const Q3CString& hexdigest) |
877 | { | 876 | { |
878 | finalize(); | 877 | finalize(); |
879 | return (0 == strcmp(hexDigest().data(), hexdigest)); | 878 | return (0 == strcmp(hexDigest().data(), hexdigest)); |
880 | } | 879 | } |
881 | 880 | ||
882 | const KMD5::Digest& KMD5::rawDigest() | 881 | const KMD5::Digest& KMD5::rawDigest() |
883 | { | 882 | { |
884 | finalize(); | 883 | finalize(); |
885 | return m_digest; | 884 | return m_digest; |
886 | } | 885 | } |
887 | 886 | ||
888 | void KMD5::rawDigest( KMD5::Digest& bin ) | 887 | void KMD5::rawDigest( KMD5::Digest& bin ) |
889 | { | 888 | { |
890 | finalize(); | 889 | finalize(); |
891 | memcpy( bin, m_digest, 16 ); | 890 | memcpy( bin, m_digest, 16 ); |
892 | } | 891 | } |
893 | 892 | ||
894 | 893 | ||
895 | QCString KMD5::hexDigest() | 894 | Q3CString KMD5::hexDigest() |
896 | { | 895 | { |
897 | QCString s(33); | 896 | Q3CString s(33); |
898 | 897 | ||
899 | finalize(); | 898 | finalize(); |
900 | sprintf(s.data(), "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", | 899 | sprintf(s.data(), "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", |
901 | m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5], | 900 | m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5], |
902 | m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11], | 901 | m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11], |
903 | m_digest[12], m_digest[13], m_digest[14], m_digest[15]); | 902 | m_digest[12], m_digest[13], m_digest[14], m_digest[15]); |
904 | 903 | ||
905 | return s; | 904 | return s; |
906 | } | 905 | } |
907 | 906 | ||
908 | void KMD5::hexDigest(QCString& s) | 907 | void KMD5::hexDigest(Q3CString& s) |
909 | { | 908 | { |
910 | finalize(); | 909 | finalize(); |
911 | s.resize(33); | 910 | s.resize(33); |
912 | sprintf(s.data(), "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", | 911 | sprintf(s.data(), "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", |
913 | m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5], | 912 | m_digest[0], m_digest[1], m_digest[2], m_digest[3], m_digest[4], m_digest[5], |
914 | m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11], | 913 | m_digest[6], m_digest[7], m_digest[8], m_digest[9], m_digest[10], m_digest[11], |
915 | m_digest[12], m_digest[13], m_digest[14], m_digest[15]); | 914 | m_digest[12], m_digest[13], m_digest[14], m_digest[15]); |
916 | } | 915 | } |
917 | 916 | ||
918 | QCString KMD5::base64Digest() | 917 | Q3CString KMD5::base64Digest() |
919 | { | 918 | { |
920 | QByteArray ba(16); | 919 | QByteArray ba(16); |
921 | 920 | ||
922 | finalize(); | 921 | finalize(); |
923 | memcpy(ba.data(), m_digest, 16); | 922 | memcpy(ba.data(), m_digest, 16); |
924 | return KCodecs::base64Encode(ba); | 923 | return KCodecs::base64Encode(ba); |
925 | } | 924 | } |
926 | 925 | ||
927 | 926 | ||
928 | void KMD5::init() | 927 | void KMD5::init() |
929 | { | 928 | { |
930 | d = 0; | 929 | d = 0; |
931 | reset(); | 930 | reset(); |
932 | } | 931 | } |
933 | 932 | ||
934 | void KMD5::reset() | 933 | void KMD5::reset() |
935 | { | 934 | { |
936 | m_finalized = false; | 935 | m_finalized = false; |
937 | 936 | ||
938 | m_count[0] = 0; | 937 | m_count[0] = 0; |
939 | m_count[1] = 0; | 938 | m_count[1] = 0; |
940 | 939 | ||
941 | m_state[0] = 0x67452301; | 940 | m_state[0] = 0x67452301; |
942 | m_state[1] = 0xefcdab89; | 941 | m_state[1] = 0xefcdab89; |
943 | m_state[2] = 0x98badcfe; | 942 | m_state[2] = 0x98badcfe; |
944 | m_state[3] = 0x10325476; | 943 | m_state[3] = 0x10325476; |
945 | 944 | ||
946 | memset ( m_buffer, 0, sizeof(*m_buffer)); | 945 | memset ( m_buffer, 0, sizeof(*m_buffer)); |
947 | memset ( m_digest, 0, sizeof(*m_digest)); | 946 | memset ( m_digest, 0, sizeof(*m_digest)); |
948 | } | 947 | } |
949 | 948 | ||
950 | void KMD5::transform( const unsigned char block[64] ) | 949 | void KMD5::transform( const unsigned char block[64] ) |
951 | { | 950 | { |
952 | 951 | ||
953 | Q_UINT32 a = m_state[0], b = m_state[1], c = m_state[2], d = m_state[3], x[16]; | 952 | Q_UINT32 a = m_state[0], b = m_state[1], c = m_state[2], d = m_state[3], x[16]; |
954 | 953 | ||
955 | decode (x, block, 64); | 954 | decode (x, block, 64); |
956 | //memcpy( x, block, 64 ); | 955 | //memcpy( x, block, 64 ); |
957 | 956 | ||
958 | //US Q_ASSERT(!m_finalized); // not just a user error, since the method is private | 957 | //US Q_ASSERT(!m_finalized); // not just a user error, since the method is private |
959 | ASSERT(!m_finalized); // not just a user error, since the method is private | 958 | Q_ASSERT(!m_finalized); // not just a user error, since the method is private |
960 | 959 | ||
961 | /* Round 1 */ | 960 | /* Round 1 */ |
962 | FF (a, b, c, d, x[ 0], KMD5_S11, 0xd76aa478); /* 1 */ | 961 | FF (a, b, c, d, x[ 0], KMD5_S11, 0xd76aa478); /* 1 */ |
963 | FF (d, a, b, c, x[ 1], KMD5_S12, 0xe8c7b756); /* 2 */ | 962 | FF (d, a, b, c, x[ 1], KMD5_S12, 0xe8c7b756); /* 2 */ |
964 | FF (c, d, a, b, x[ 2], KMD5_S13, 0x242070db); /* 3 */ | 963 | FF (c, d, a, b, x[ 2], KMD5_S13, 0x242070db); /* 3 */ |
965 | FF (b, c, d, a, x[ 3], KMD5_S14, 0xc1bdceee); /* 4 */ | 964 | FF (b, c, d, a, x[ 3], KMD5_S14, 0xc1bdceee); /* 4 */ |
966 | FF (a, b, c, d, x[ 4], KMD5_S11, 0xf57c0faf); /* 5 */ | 965 | FF (a, b, c, d, x[ 4], KMD5_S11, 0xf57c0faf); /* 5 */ |
967 | FF (d, a, b, c, x[ 5], KMD5_S12, 0x4787c62a); /* 6 */ | 966 | FF (d, a, b, c, x[ 5], KMD5_S12, 0x4787c62a); /* 6 */ |
968 | FF (c, d, a, b, x[ 6], KMD5_S13, 0xa8304613); /* 7 */ | 967 | FF (c, d, a, b, x[ 6], KMD5_S13, 0xa8304613); /* 7 */ |
969 | FF (b, c, d, a, x[ 7], KMD5_S14, 0xfd469501); /* 8 */ | 968 | FF (b, c, d, a, x[ 7], KMD5_S14, 0xfd469501); /* 8 */ |
970 | FF (a, b, c, d, x[ 8], KMD5_S11, 0x698098d8); /* 9 */ | 969 | FF (a, b, c, d, x[ 8], KMD5_S11, 0x698098d8); /* 9 */ |
971 | FF (d, a, b, c, x[ 9], KMD5_S12, 0x8b44f7af); /* 10 */ | 970 | FF (d, a, b, c, x[ 9], KMD5_S12, 0x8b44f7af); /* 10 */ |
972 | FF (c, d, a, b, x[10], KMD5_S13, 0xffff5bb1); /* 11 */ | 971 | FF (c, d, a, b, x[10], KMD5_S13, 0xffff5bb1); /* 11 */ |
973 | FF (b, c, d, a, x[11], KMD5_S14, 0x895cd7be); /* 12 */ | 972 | FF (b, c, d, a, x[11], KMD5_S14, 0x895cd7be); /* 12 */ |
974 | FF (a, b, c, d, x[12], KMD5_S11, 0x6b901122); /* 13 */ | 973 | FF (a, b, c, d, x[12], KMD5_S11, 0x6b901122); /* 13 */ |
975 | FF (d, a, b, c, x[13], KMD5_S12, 0xfd987193); /* 14 */ | 974 | FF (d, a, b, c, x[13], KMD5_S12, 0xfd987193); /* 14 */ |
976 | FF (c, d, a, b, x[14], KMD5_S13, 0xa679438e); /* 15 */ | 975 | FF (c, d, a, b, x[14], KMD5_S13, 0xa679438e); /* 15 */ |
977 | FF (b, c, d, a, x[15], KMD5_S14, 0x49b40821); /* 16 */ | 976 | FF (b, c, d, a, x[15], KMD5_S14, 0x49b40821); /* 16 */ |
978 | 977 | ||
979 | /* Round 2 */ | 978 | /* Round 2 */ |
980 | GG (a, b, c, d, x[ 1], KMD5_S21, 0xf61e2562); /* 17 */ | 979 | GG (a, b, c, d, x[ 1], KMD5_S21, 0xf61e2562); /* 17 */ |
981 | GG (d, a, b, c, x[ 6], KMD5_S22, 0xc040b340); /* 18 */ | 980 | GG (d, a, b, c, x[ 6], KMD5_S22, 0xc040b340); /* 18 */ |
982 | GG (c, d, a, b, x[11], KMD5_S23, 0x265e5a51); /* 19 */ | 981 | GG (c, d, a, b, x[11], KMD5_S23, 0x265e5a51); /* 19 */ |
983 | GG (b, c, d, a, x[ 0], KMD5_S24, 0xe9b6c7aa); /* 20 */ | 982 | GG (b, c, d, a, x[ 0], KMD5_S24, 0xe9b6c7aa); /* 20 */ |
984 | GG (a, b, c, d, x[ 5], KMD5_S21, 0xd62f105d); /* 21 */ | 983 | GG (a, b, c, d, x[ 5], KMD5_S21, 0xd62f105d); /* 21 */ |
985 | GG (d, a, b, c, x[10], KMD5_S22, 0x2441453); /* 22 */ | 984 | GG (d, a, b, c, x[10], KMD5_S22, 0x2441453); /* 22 */ |
986 | GG (c, d, a, b, x[15], KMD5_S23, 0xd8a1e681); /* 23 */ | 985 | GG (c, d, a, b, x[15], KMD5_S23, 0xd8a1e681); /* 23 */ |
987 | GG (b, c, d, a, x[ 4], KMD5_S24, 0xe7d3fbc8); /* 24 */ | 986 | GG (b, c, d, a, x[ 4], KMD5_S24, 0xe7d3fbc8); /* 24 */ |
988 | GG (a, b, c, d, x[ 9], KMD5_S21, 0x21e1cde6); /* 25 */ | 987 | GG (a, b, c, d, x[ 9], KMD5_S21, 0x21e1cde6); /* 25 */ |
989 | GG (d, a, b, c, x[14], KMD5_S22, 0xc33707d6); /* 26 */ | 988 | GG (d, a, b, c, x[14], KMD5_S22, 0xc33707d6); /* 26 */ |
990 | GG (c, d, a, b, x[ 3], KMD5_S23, 0xf4d50d87); /* 27 */ | 989 | GG (c, d, a, b, x[ 3], KMD5_S23, 0xf4d50d87); /* 27 */ |
991 | GG (b, c, d, a, x[ 8], KMD5_S24, 0x455a14ed); /* 28 */ | 990 | GG (b, c, d, a, x[ 8], KMD5_S24, 0x455a14ed); /* 28 */ |
diff --git a/microkde/kdecore/kmdcodec.h b/microkde/kdecore/kmdcodec.h index 2c4d611..616b683 100644 --- a/microkde/kdecore/kmdcodec.h +++ b/microkde/kdecore/kmdcodec.h | |||
@@ -10,345 +10,347 @@ | |||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public | 14 | You should have received a copy of the GNU Library General Public |
15 | License along with this program; if not, write to the Free Software | 15 | License along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 16 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
17 | 17 | ||
18 | RFC 1321 "MD5 Message-Digest Algorithm" Copyright (C) 1991-1992. | 18 | RFC 1321 "MD5 Message-Digest Algorithm" Copyright (C) 1991-1992. |
19 | RSA Data Security, Inc. Created 1991. All rights reserved. | 19 | RSA Data Security, Inc. Created 1991. All rights reserved. |
20 | 20 | ||
21 | The KMD5 class is based on a C++ implementation of | 21 | The KMD5 class is based on a C++ implementation of |
22 | "RSA Data Security, Inc. MD5 Message-Digest Algorithm" by | 22 | "RSA Data Security, Inc. MD5 Message-Digest Algorithm" by |
23 | Mordechai T. Abzug,Copyright (c) 1995. This implementation | 23 | Mordechai T. Abzug,Copyright (c) 1995. This implementation |
24 | passes the test-suite as defined in RFC 1321. | 24 | passes the test-suite as defined in RFC 1321. |
25 | 25 | ||
26 | The encoding and decoding utilities in KCodecs with the exception of | 26 | The encoding and decoding utilities in KCodecs with the exception of |
27 | quoted-printable are based on the java implementation in HTTPClient | 27 | quoted-printable are based on the java implementation in HTTPClient |
28 | package by Ronald Tschalär Copyright (C) 1996-1999. | 28 | package by Ronald Tschalär Copyright (C) 1996-1999. |
29 | 29 | ||
30 | The quoted-printable codec as described in RFC 2045, section 6.7. is by | 30 | The quoted-printable codec as described in RFC 2045, section 6.7. is by |
31 | Rik Hemsley (C) 2001. | 31 | Rik Hemsley (C) 2001. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef _KMDBASE_H | 34 | #ifndef _KMDBASE_H |
35 | #define _KMDBASE_H | 35 | #define _KMDBASE_H |
36 | 36 | ||
37 | #define KBase64 KCodecs | 37 | #define KBase64 KCodecs |
38 | 38 | ||
39 | #include <qglobal.h> | 39 | #include <qglobal.h> |
40 | #include <qstring.h> | 40 | #include <qstring.h> |
41 | #include <qiodevice.h> | 41 | #include <qiodevice.h> |
42 | //Added by qt3to4: | ||
43 | #include <Q3CString> | ||
42 | 44 | ||
43 | /** | 45 | /** |
44 | * A wrapper class for the most commonly used encoding and | 46 | * A wrapper class for the most commonly used encoding and |
45 | * decoding algorithms. Currently there is support for encoding | 47 | * decoding algorithms. Currently there is support for encoding |
46 | * and decoding input using base64, uu and the quoted-printable | 48 | * and decoding input using base64, uu and the quoted-printable |
47 | * specifications. | 49 | * specifications. |
48 | * | 50 | * |
49 | * @sect Usage: | 51 | * @sect Usage: |
50 | * | 52 | * |
51 | * <PRE> | 53 | * <PRE> |
52 | * QCString input = "Aladdin:open sesame"; | 54 | * QCString input = "Aladdin:open sesame"; |
53 | * QCString result = KCodecs::base64Encode(input); | 55 | * QCString result = KCodecs::base64Encode(input); |
54 | * cout << "Result: " << result.data() << endl; | 56 | * cout << "Result: " << result.data() << endl; |
55 | * | 57 | * |
56 | * Output should be | 58 | * Output should be |
57 | * Result: QWxhZGRpbjpvcGVuIHNlc2FtZQ== | 59 | * Result: QWxhZGRpbjpvcGVuIHNlc2FtZQ== |
58 | * </PRE> | 60 | * </PRE> |
59 | * | 61 | * |
60 | * The above example makes use of the convenience functions | 62 | * The above example makes use of the convenience functions |
61 | * (ones that accept/return null-terminated strings) to encode/decode | 63 | * (ones that accept/return null-terminated strings) to encode/decode |
62 | * a string. If what you need is to encode or decode binary data, then | 64 | * a string. If what you need is to encode or decode binary data, then |
63 | * it is highly recommended that you use the functions that take an input | 65 | * it is highly recommended that you use the functions that take an input |
64 | * and output QByteArray as arguments. These functions are specifically | 66 | * and output QByteArray as arguments. These functions are specifically |
65 | * tailored for encoding and decoding binary data. | 67 | * tailored for encoding and decoding binary data. |
66 | * | 68 | * |
67 | * @short A collection of commonly used encoding and decoding algorithms. | 69 | * @short A collection of commonly used encoding and decoding algorithms. |
68 | * @author Dawit Alemayehu <adawit@kde.org> | 70 | * @author Dawit Alemayehu <adawit@kde.org> |
69 | * @author Rik Hemsley <rik@kde.org> | 71 | * @author Rik Hemsley <rik@kde.org> |
70 | */ | 72 | */ |
71 | class KCodecs | 73 | class KCodecs |
72 | { | 74 | { |
73 | public: | 75 | public: |
74 | 76 | ||
75 | /** | 77 | /** |
76 | * Encodes the given data using the quoted-printable algorithm. | 78 | * Encodes the given data using the quoted-printable algorithm. |
77 | * | 79 | * |
78 | * @param in data to be encoded. | 80 | * @param in data to be encoded. |
79 | * @param useCRLF if true the input data is expected to have | 81 | * @param useCRLF if true the input data is expected to have |
80 | * CRLF line breaks and the output will have CRLF line | 82 | * CRLF line breaks and the output will have CRLF line |
81 | * breaks, too. | 83 | * breaks, too. |
82 | * @return quoted-printable encoded data. | 84 | * @return quoted-printable encoded data. |
83 | */ | 85 | */ |
84 | static QCString quotedPrintableEncode(const QByteArray & in, | 86 | static Q3CString quotedPrintableEncode(const QByteArray & in, |
85 | bool useCRLF = true); | 87 | bool useCRLF = true); |
86 | 88 | ||
87 | /** | 89 | /** |
88 | * @overload | 90 | * @overload |
89 | * | 91 | * |
90 | * Same as above except it accepts a null terminated | 92 | * Same as above except it accepts a null terminated |
91 | * string instead an array. | 93 | * string instead an array. |
92 | * | 94 | * |
93 | * @param str data to be encoded. | 95 | * @param str data to be encoded. |
94 | * @param useCRLF if true the input data is expected to have | 96 | * @param useCRLF if true the input data is expected to have |
95 | * CRLF line breaks and the output will have CRLF line | 97 | * CRLF line breaks and the output will have CRLF line |
96 | * breaks, too. | 98 | * breaks, too. |
97 | * @return quoted-printable encoded data. | 99 | * @return quoted-printable encoded data. |
98 | */ | 100 | */ |
99 | static QCString quotedPrintableEncode(const QCString & str, | 101 | static Q3CString quotedPrintableEncode(const Q3CString & str, |
100 | bool useCRLF = true); | 102 | bool useCRLF = true); |
101 | 103 | ||
102 | /** | 104 | /** |
103 | * Encodes the given data using the quoted-printable algorithm. | 105 | * Encodes the given data using the quoted-printable algorithm. |
104 | * | 106 | * |
105 | * Use this function if you want the result of the encoding | 107 | * Use this function if you want the result of the encoding |
106 | * to be placed in another array which cuts down the number | 108 | * to be placed in another array which cuts down the number |
107 | * of copy operation that have to be performed in the process. | 109 | * of copy operation that have to be performed in the process. |
108 | * This is also the preferred method for encoding binary data. | 110 | * This is also the preferred method for encoding binary data. |
109 | * | 111 | * |
110 | * NOTE: the output array is first reset and then resized | 112 | * NOTE: the output array is first reset and then resized |
111 | * appropriately before use, hence, all data stored in the | 113 | * appropriately before use, hence, all data stored in the |
112 | * output array will be lost. | 114 | * output array will be lost. |
113 | * | 115 | * |
114 | * @param in data to be encoded. | 116 | * @param in data to be encoded. |
115 | * @param out decoded data. | 117 | * @param out decoded data. |
116 | * @param useCRLF if true the input data is expected to have | 118 | * @param useCRLF if true the input data is expected to have |
117 | * CRLF line breaks and the output will have CRLF line | 119 | * CRLF line breaks and the output will have CRLF line |
118 | * breaks, too. | 120 | * breaks, too. |
119 | * @return quoted-printable encoded data. | 121 | * @return quoted-printable encoded data. |
120 | */ | 122 | */ |
121 | static void quotedPrintableEncode(const QByteArray & in, QByteArray& out, | 123 | static void quotedPrintableEncode(const QByteArray & in, QByteArray& out, |
122 | bool useCRLF); | 124 | bool useCRLF); |
123 | 125 | ||
124 | /** | 126 | /** |
125 | * Decodes a quoted-printable encoded string. | 127 | * Decodes a quoted-printable encoded string. |
126 | * | 128 | * |
127 | * Accepts data with CRLF or standard unix line breaks. | 129 | * Accepts data with CRLF or standard unix line breaks. |
128 | * | 130 | * |
129 | * @param in the data to be decoded. | 131 | * @param in the data to be decoded. |
130 | * @return decoded data. | 132 | * @return decoded data. |
131 | */ | 133 | */ |
132 | static QCString quotedPrintableDecode(const QByteArray & in); | 134 | static Q3CString quotedPrintableDecode(const QByteArray & in); |
133 | 135 | ||
134 | /** | 136 | /** |
135 | * @overload | 137 | * @overload |
136 | * | 138 | * |
137 | * Same as above except it accepts a null terminated | 139 | * Same as above except it accepts a null terminated |
138 | * string instead an array. | 140 | * string instead an array. |
139 | * | 141 | * |
140 | * @param str the data to be decoded. | 142 | * @param str the data to be decoded. |
141 | * @return decoded data. | 143 | * @return decoded data. |
142 | */ | 144 | */ |
143 | static QCString quotedPrintableDecode(const QCString & str); | 145 | static Q3CString quotedPrintableDecode(const Q3CString & str); |
144 | 146 | ||
145 | /** | 147 | /** |
146 | * Decodes a quoted-printable encoded data. | 148 | * Decodes a quoted-printable encoded data. |
147 | * | 149 | * |
148 | * Accepts data with CRLF or standard unix line breaks. | 150 | * Accepts data with CRLF or standard unix line breaks. |
149 | * Use this function if you want the result of the decoding | 151 | * Use this function if you want the result of the decoding |
150 | * to be placed in another array which cuts down the number | 152 | * to be placed in another array which cuts down the number |
151 | * of copy operation that have to be performed in the process. | 153 | * of copy operation that have to be performed in the process. |
152 | * This is also the preferred method for decoding an encoded | 154 | * This is also the preferred method for decoding an encoded |
153 | * binary data. | 155 | * binary data. |
154 | * | 156 | * |
155 | * NOTE: the output array is first reset and then resized | 157 | * NOTE: the output array is first reset and then resized |
156 | * appropriately before use, hence, all data stored in the | 158 | * appropriately before use, hence, all data stored in the |
157 | * output array will be lost. | 159 | * output array will be lost. |
158 | * | 160 | * |
159 | * @param in data to be encoded. | 161 | * @param in data to be encoded. |
160 | * @param out decoded data. | 162 | * @param out decoded data. |
161 | * | 163 | * |
162 | * @return quoted-printable encoded data. | 164 | * @return quoted-printable encoded data. |
163 | */ | 165 | */ |
164 | static void quotedPrintableDecode(const QByteArray & in, QByteArray& out); | 166 | static void quotedPrintableDecode(const QByteArray & in, QByteArray& out); |
165 | 167 | ||
166 | 168 | ||
167 | /** | 169 | /** |
168 | * Encodes the given data using the uuencode algorithm. | 170 | * Encodes the given data using the uuencode algorithm. |
169 | * | 171 | * |
170 | * The output is split into lines starting with the number of | 172 | * The output is split into lines starting with the number of |
171 | * encoded octets in the line and ending with a newline. No | 173 | * encoded octets in the line and ending with a newline. No |
172 | * line is longer than 45 octets (60 characters), excluding the | 174 | * line is longer than 45 octets (60 characters), excluding the |
173 | * line terminator. | 175 | * line terminator. |
174 | * | 176 | * |
175 | * @param in the data to be uuencoded | 177 | * @param in the data to be uuencoded |
176 | * @return a uuencoded data. | 178 | * @return a uuencoded data. |
177 | */ | 179 | */ |
178 | static QCString uuencode( const QByteArray& in ); | 180 | static Q3CString uuencode( const QByteArray& in ); |
179 | 181 | ||
180 | /** | 182 | /** |
181 | * @overload | 183 | * @overload |
182 | * | 184 | * |
183 | * Same as the above functions except it accepts | 185 | * Same as the above functions except it accepts |
184 | * a null terminated string instead an array. | 186 | * a null terminated string instead an array. |
185 | * | 187 | * |
186 | * @param str the string to be uuencoded. | 188 | * @param str the string to be uuencoded. |
187 | * @return the encoded string. | 189 | * @return the encoded string. |
188 | */ | 190 | */ |
189 | static QCString uuencode( const QCString& str ); | 191 | static Q3CString uuencode( const Q3CString& str ); |
190 | 192 | ||
191 | /** | 193 | /** |
192 | * Encodes the given data using the uuencode algorithm. | 194 | * Encodes the given data using the uuencode algorithm. |
193 | * | 195 | * |
194 | * Use this function if you want the result of the encoding | 196 | * Use this function if you want the result of the encoding |
195 | * to be placed in another array and cut down the number of | 197 | * to be placed in another array and cut down the number of |
196 | * copy operation that have to be performed in the process. | 198 | * copy operation that have to be performed in the process. |
197 | * This is the preffered method for encoding binary data. | 199 | * This is the preffered method for encoding binary data. |
198 | * | 200 | * |
199 | * NOTE: the output array is first reset and then resized | 201 | * NOTE: the output array is first reset and then resized |
200 | * appropriately before use, hence, all data stored in the | 202 | * appropriately before use, hence, all data stored in the |
201 | * output array will be lost. | 203 | * output array will be lost. |
202 | * | 204 | * |
203 | * @param in the data to be uuencoded. | 205 | * @param in the data to be uuencoded. |
204 | * @param out the container for the uudecoded data. | 206 | * @param out the container for the uudecoded data. |
205 | */ | 207 | */ |
206 | static void uuencode( const QByteArray& in, QByteArray& out ); | 208 | static void uuencode( const QByteArray& in, QByteArray& out ); |
207 | 209 | ||
208 | /** | 210 | /** |
209 | * Decodes the given data using the uuencode algorithm. | 211 | * Decodes the given data using the uuencode algorithm. |
210 | * | 212 | * |
211 | * Any 'begin' and 'end' lines like those generated by | 213 | * Any 'begin' and 'end' lines like those generated by |
212 | * the utilities in unix and unix-like OS will be | 214 | * the utilities in unix and unix-like OS will be |
213 | * automatically ignored. | 215 | * automatically ignored. |
214 | * | 216 | * |
215 | * @param in the data uuencoded data to be decoded. | 217 | * @param in the data uuencoded data to be decoded. |
216 | * @return a decoded string. | 218 | * @return a decoded string. |
217 | */ | 219 | */ |
218 | static QCString uudecode( const QByteArray& in ); | 220 | static Q3CString uudecode( const QByteArray& in ); |
219 | 221 | ||
220 | /** | 222 | /** |
221 | * @overload | 223 | * @overload |
222 | * | 224 | * |
223 | * Same as the above functions except it accepts | 225 | * Same as the above functions except it accepts |
224 | * a null terminated string instead an array. | 226 | * a null terminated string instead an array. |
225 | * | 227 | * |
226 | * @param str the string to be decoded. | 228 | * @param str the string to be decoded. |
227 | * @return a uudecoded string. | 229 | * @return a uudecoded string. |
228 | */ | 230 | */ |
229 | static QCString uudecode( const QCString& str ); | 231 | static Q3CString uudecode( const Q3CString& str ); |
230 | 232 | ||
231 | /** | 233 | /** |
232 | * Decodes the given data using the uudecode algorithm. | 234 | * Decodes the given data using the uudecode algorithm. |
233 | * | 235 | * |
234 | * Use this function if you want the result of the decoding | 236 | * Use this function if you want the result of the decoding |
235 | * to be placed in another array which cuts down the number | 237 | * to be placed in another array which cuts down the number |
236 | * of copy operation that have to be performed in the process. | 238 | * of copy operation that have to be performed in the process. |
237 | * This is the preferred method for decoding binary data. | 239 | * This is the preferred method for decoding binary data. |
238 | * | 240 | * |
239 | * Any 'begin' and 'end' lines like those generated by | 241 | * Any 'begin' and 'end' lines like those generated by |
240 | * the utilities in unix and unix-like OS will be | 242 | * the utilities in unix and unix-like OS will be |
241 | * automatically ignored. | 243 | * automatically ignored. |
242 | * | 244 | * |
243 | * NOTE: the output array is first reset and then resized | 245 | * NOTE: the output array is first reset and then resized |
244 | * appropriately before use, hence, all data stored in the | 246 | * appropriately before use, hence, all data stored in the |
245 | * output array will be lost. | 247 | * output array will be lost. |
246 | * | 248 | * |
247 | * @param in the uuencoded-data to be decoded. | 249 | * @param in the uuencoded-data to be decoded. |
248 | * @param out the container for the uudecoded data. | 250 | * @param out the container for the uudecoded data. |
249 | */ | 251 | */ |
250 | static void uudecode( const QByteArray& in, QByteArray& out ); | 252 | static void uudecode( const QByteArray& in, QByteArray& out ); |
251 | 253 | ||
252 | 254 | ||
253 | /** | 255 | /** |
254 | * Encodes the given data using the base64 algorithm. | 256 | * Encodes the given data using the base64 algorithm. |
255 | * | 257 | * |
256 | * The boolean argument determines if the encoded data is | 258 | * The boolean argument determines if the encoded data is |
257 | * going to be restricted to 76 characters or less per line | 259 | * going to be restricted to 76 characters or less per line |
258 | * as specified by RFC 2045. If @p insertLFs is true, then | 260 | * as specified by RFC 2045. If @p insertLFs is true, then |
259 | * there will be 76 characters or less per line. | 261 | * there will be 76 characters or less per line. |
260 | * | 262 | * |
261 | * @param in the data to be encoded. | 263 | * @param in the data to be encoded. |
262 | * @param insertLFs limit the number of characters per line. | 264 | * @param insertLFs limit the number of characters per line. |
263 | * | 265 | * |
264 | * @return a base64 encoded string. | 266 | * @return a base64 encoded string. |
265 | */ | 267 | */ |
266 | static QCString base64Encode( const QByteArray& in, bool insertLFs = false); | 268 | static Q3CString base64Encode( const QByteArray& in, bool insertLFs = false); |
267 | 269 | ||
268 | /** | 270 | /** |
269 | * @overload | 271 | * @overload |
270 | * | 272 | * |
271 | * Same as the above functions except it accepts | 273 | * Same as the above functions except it accepts |
272 | * a null terminated string instead an array. | 274 | * a null terminated string instead an array. |
273 | * | 275 | * |
274 | * @param str the string to be encoded. | 276 | * @param str the string to be encoded. |
275 | * @param insertLFs limit the number of characters per line. | 277 | * @param insertLFs limit the number of characters per line. |
276 | * @return the decoded string. | 278 | * @return the decoded string. |
277 | */ | 279 | */ |
278 | static QCString base64Encode( const QCString& str, bool insertLFs = false ); | 280 | static Q3CString base64Encode( const Q3CString& str, bool insertLFs = false ); |
279 | 281 | ||
280 | /** | 282 | /** |
281 | * Encodes the given data using the base64 algorithm. | 283 | * Encodes the given data using the base64 algorithm. |
282 | * | 284 | * |
283 | * Use this function if you want the result of the encoding | 285 | * Use this function if you want the result of the encoding |
284 | * to be placed in another array which cuts down the number | 286 | * to be placed in another array which cuts down the number |
285 | * of copy operation that have to be performed in the process. | 287 | * of copy operation that have to be performed in the process. |
286 | * This is also the preferred method for encoding binary data. | 288 | * This is also the preferred method for encoding binary data. |
287 | * | 289 | * |
288 | * The boolean argument determines if the encoded data is going | 290 | * The boolean argument determines if the encoded data is going |
289 | * to be restricted to 76 characters or less per line as specified | 291 | * to be restricted to 76 characters or less per line as specified |
290 | * by RFC 2045. If @p insertLFs is true, then there will be 76 | 292 | * by RFC 2045. If @p insertLFs is true, then there will be 76 |
291 | * characters or less per line. | 293 | * characters or less per line. |
292 | * | 294 | * |
293 | * NOTE: the output array is first reset and then resized | 295 | * NOTE: the output array is first reset and then resized |
294 | * appropriately before use, hence, all data stored in the | 296 | * appropriately before use, hence, all data stored in the |
295 | * output array will be lost. | 297 | * output array will be lost. |
296 | * | 298 | * |
297 | * @param in the data to be encoded using base64. | 299 | * @param in the data to be encoded using base64. |
298 | * @param out the container for the encoded data. | 300 | * @param out the container for the encoded data. |
299 | * @param insertLFs limit the number of characters per line. | 301 | * @param insertLFs limit the number of characters per line. |
300 | */ | 302 | */ |
301 | static void base64Encode( const QByteArray& in, QByteArray& out, | 303 | static void base64Encode( const QByteArray& in, QByteArray& out, |
302 | bool insertLFs = false ); | 304 | bool insertLFs = false ); |
303 | 305 | ||
304 | /** | 306 | /** |
305 | * Decodes the given data that was encoded using the | 307 | * Decodes the given data that was encoded using the |
306 | * base64 algorithm. | 308 | * base64 algorithm. |
307 | * | 309 | * |
308 | * @param in the base64-encoded data to be decoded. | 310 | * @param in the base64-encoded data to be decoded. |
309 | * @return the decoded data. | 311 | * @return the decoded data. |
310 | */ | 312 | */ |
311 | static QCString base64Decode( const QByteArray& in ); | 313 | static Q3CString base64Decode( const QByteArray& in ); |
312 | 314 | ||
313 | /** | 315 | /** |
314 | * @overload | 316 | * @overload |
315 | * | 317 | * |
316 | * Same as the above functions except it accepts | 318 | * Same as the above functions except it accepts |
317 | * a null terminated string instead an array. | 319 | * a null terminated string instead an array. |
318 | * | 320 | * |
319 | * @param str the base64-encoded string. | 321 | * @param str the base64-encoded string. |
320 | * @return the decoded string. | 322 | * @return the decoded string. |
321 | */ | 323 | */ |
322 | static QCString base64Decode( const QCString& str ); | 324 | static Q3CString base64Decode( const Q3CString& str ); |
323 | 325 | ||
324 | /** | 326 | /** |
325 | * Decodes the given data that was encoded with the base64 | 327 | * Decodes the given data that was encoded with the base64 |
326 | * algorithm. | 328 | * algorithm. |
327 | * | 329 | * |
328 | * Use this function if you want the result of the decoding | 330 | * Use this function if you want the result of the decoding |
329 | * to be placed in another array which cuts down the number | 331 | * to be placed in another array which cuts down the number |
330 | * of copy operation that have to be performed in the process. | 332 | * of copy operation that have to be performed in the process. |
331 | * This is also the preferred method for decoding an encoded | 333 | * This is also the preferred method for decoding an encoded |
332 | * binary data. | 334 | * binary data. |
333 | * | 335 | * |
334 | * NOTE: the output array is first reset and then resized | 336 | * NOTE: the output array is first reset and then resized |
335 | * appropriately before use, hence, all data stored in the | 337 | * appropriately before use, hence, all data stored in the |
336 | * output array will be lost. | 338 | * output array will be lost. |
337 | * | 339 | * |
338 | * @param in the encoded data to be decoded. | 340 | * @param in the encoded data to be decoded. |
339 | * @param out the container for the decoded data. | 341 | * @param out the container for the decoded data. |
340 | */ | 342 | */ |
341 | static void base64Decode( const QByteArray& in, QByteArray& out ); | 343 | static void base64Decode( const QByteArray& in, QByteArray& out ); |
342 | 344 | ||
343 | 345 | ||
344 | private: | 346 | private: |
345 | KCodecs(); | 347 | KCodecs(); |
346 | 348 | ||
347 | private: | 349 | private: |
348 | static const char UUEncMap[64]; | 350 | static const char UUEncMap[64]; |
349 | static const char UUDecMap[128]; | 351 | static const char UUDecMap[128]; |
350 | static const char Base64EncMap[64]; | 352 | static const char Base64EncMap[64]; |
351 | static const char Base64DecMap[128]; | 353 | static const char Base64DecMap[128]; |
352 | static const char hexChars[16]; | 354 | static const char hexChars[16]; |
353 | static const unsigned int maxQPLineLength; | 355 | static const unsigned int maxQPLineLength; |
354 | }; | 356 | }; |
@@ -402,158 +404,158 @@ class KMD5Private; | |||
402 | */ | 404 | */ |
403 | 405 | ||
404 | class KMD5 | 406 | class KMD5 |
405 | { | 407 | { |
406 | public: | 408 | public: |
407 | 409 | ||
408 | typedef unsigned char Digest[16]; | 410 | typedef unsigned char Digest[16]; |
409 | 411 | ||
410 | KMD5(); | 412 | KMD5(); |
411 | 413 | ||
412 | /** | 414 | /** |
413 | * Constructor that updates the digest for the given string. | 415 | * Constructor that updates the digest for the given string. |
414 | * | 416 | * |
415 | * @param in C string or binary data | 417 | * @param in C string or binary data |
416 | * @param len if negative, calculates the length by using | 418 | * @param len if negative, calculates the length by using |
417 | * strlen on the first parameter, otherwise | 419 | * strlen on the first parameter, otherwise |
418 | * it trusts the given length (does not stop on NUL byte). | 420 | * it trusts the given length (does not stop on NUL byte). |
419 | */ | 421 | */ |
420 | KMD5(const char* in, int len = -1); | 422 | KMD5(const char* in, int len = -1); |
421 | 423 | ||
422 | /** | 424 | /** |
423 | * @overload | 425 | * @overload |
424 | * | 426 | * |
425 | * Same as above except it accepts a QByteArray as its argument. | 427 | * Same as above except it accepts a QByteArray as its argument. |
426 | */ | 428 | */ |
427 | KMD5(const QByteArray& a ); | 429 | KMD5(const QByteArray& a ); |
428 | 430 | ||
429 | /** | 431 | /** |
430 | * @overload | 432 | * @overload |
431 | * | 433 | * |
432 | * Same as above except it accepts a QByteArray as its argument. | 434 | * Same as above except it accepts a QByteArray as its argument. |
433 | */ | 435 | */ |
434 | KMD5(const QCString& a ); | 436 | KMD5(const Q3CString& a ); |
435 | 437 | ||
436 | /** | 438 | /** |
437 | * Updates the message to be digested. Be sure to add all data | 439 | * Updates the message to be digested. Be sure to add all data |
438 | * before you read the digest. After reading the digest, you | 440 | * before you read the digest. After reading the digest, you |
439 | * can <b>not</b> add more data! | 441 | * can <b>not</b> add more data! |
440 | * | 442 | * |
441 | * @param in message to be added to digest | 443 | * @param in message to be added to digest |
442 | * @param len the length of the given message. | 444 | * @param len the length of the given message. |
443 | */ | 445 | */ |
444 | void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); } | 446 | void update(const char* in, int len = -1) { update(reinterpret_cast<const unsigned char*>(in), len); } |
445 | 447 | ||
446 | /** | 448 | /** |
447 | * @overload | 449 | * @overload |
448 | */ | 450 | */ |
449 | void update(const unsigned char* in, int len = -1); | 451 | void update(const unsigned char* in, int len = -1); |
450 | 452 | ||
451 | /** | 453 | /** |
452 | * @overload | 454 | * @overload |
453 | * | 455 | * |
454 | * @param in message to be added to the digest (QByteArray). | 456 | * @param in message to be added to the digest (QByteArray). |
455 | */ | 457 | */ |
456 | void update(const QByteArray& in ); | 458 | void update(const QByteArray& in ); |
457 | 459 | ||
458 | /** | 460 | /** |
459 | * @overload | 461 | * @overload |
460 | * | 462 | * |
461 | * @param in message to be added to the digest (QByteArray). | 463 | * @param in message to be added to the digest (QByteArray). |
462 | */ | 464 | */ |
463 | void update(const QCString& in ); | 465 | void update(const Q3CString& in ); |
464 | 466 | ||
465 | /** | 467 | /** |
466 | * @overload | 468 | * @overload |
467 | * | 469 | * |
468 | * reads the data from an I/O device, i.e. from a file (QFile). | 470 | * reads the data from an I/O device, i.e. from a file (QFile). |
469 | * | 471 | * |
470 | * NOTE that the file must be open for reading. | 472 | * NOTE that the file must be open for reading. |
471 | * | 473 | * |
472 | * @param file a pointer to FILE as returned by calls like f{d,re}open | 474 | * @param file a pointer to FILE as returned by calls like f{d,re}open |
473 | * | 475 | * |
474 | * @returns false if an error occured during reading. | 476 | * @returns false if an error occured during reading. |
475 | */ | 477 | */ |
476 | bool update(QIODevice& file); | 478 | bool update(QIODevice& file); |
477 | 479 | ||
478 | /** | 480 | /** |
479 | * Calling this function will reset the calculated message digest. | 481 | * Calling this function will reset the calculated message digest. |
480 | * Use this method to perform another message digest calculation | 482 | * Use this method to perform another message digest calculation |
481 | * without recreating the KMD5 object. | 483 | * without recreating the KMD5 object. |
482 | */ | 484 | */ |
483 | void reset(); | 485 | void reset(); |
484 | 486 | ||
485 | /** | 487 | /** |
486 | * @return the raw representation of the digest | 488 | * @return the raw representation of the digest |
487 | */ | 489 | */ |
488 | const Digest& rawDigest (); | 490 | const Digest& rawDigest (); |
489 | 491 | ||
490 | /** | 492 | /** |
491 | * Fills the given array with the binary representation of the | 493 | * Fills the given array with the binary representation of the |
492 | * message digest. | 494 | * message digest. |
493 | * | 495 | * |
494 | * Use this method if you do not want to worry about making | 496 | * Use this method if you do not want to worry about making |
495 | * copy of the digest once you obtain it. | 497 | * copy of the digest once you obtain it. |
496 | * | 498 | * |
497 | * @param bin an array of 16 characters ( char[16] ) | 499 | * @param bin an array of 16 characters ( char[16] ) |
498 | */ | 500 | */ |
499 | void rawDigest( KMD5::Digest& bin ); | 501 | void rawDigest( KMD5::Digest& bin ); |
500 | 502 | ||
501 | /** | 503 | /** |
502 | * Returns the value of the calculated message digest in | 504 | * Returns the value of the calculated message digest in |
503 | * a hexadecimal representation. | 505 | * a hexadecimal representation. |
504 | */ | 506 | */ |
505 | QCString hexDigest (); | 507 | Q3CString hexDigest (); |
506 | 508 | ||
507 | /** | 509 | /** |
508 | * @overload | 510 | * @overload |
509 | */ | 511 | */ |
510 | void hexDigest(QCString&); | 512 | void hexDigest(Q3CString&); |
511 | 513 | ||
512 | /** | 514 | /** |
513 | * Returns the value of the calculated message digest in | 515 | * Returns the value of the calculated message digest in |
514 | * a base64-encoded representation. | 516 | * a base64-encoded representation. |
515 | */ | 517 | */ |
516 | QCString base64Digest (); | 518 | Q3CString base64Digest (); |
517 | 519 | ||
518 | /** | 520 | /** |
519 | * returns true if the calculated digest for the given | 521 | * returns true if the calculated digest for the given |
520 | * message matches the given one. | 522 | * message matches the given one. |
521 | */ | 523 | */ |
522 | bool verify( const KMD5::Digest& digest); | 524 | bool verify( const KMD5::Digest& digest); |
523 | 525 | ||
524 | /** | 526 | /** |
525 | * @overload | 527 | * @overload |
526 | */ | 528 | */ |
527 | bool verify(const QCString&); | 529 | bool verify(const Q3CString&); |
528 | 530 | ||
529 | protected: | 531 | protected: |
530 | /** | 532 | /** |
531 | * Performs the real update work. Note | 533 | * Performs the real update work. Note |
532 | * that length is implied to be 64. | 534 | * that length is implied to be 64. |
533 | */ | 535 | */ |
534 | void transform( const unsigned char buffer[64] ); | 536 | void transform( const unsigned char buffer[64] ); |
535 | 537 | ||
536 | /** | 538 | /** |
537 | * finalizes the digest | 539 | * finalizes the digest |
538 | */ | 540 | */ |
539 | void finalize(); | 541 | void finalize(); |
540 | 542 | ||
541 | private: | 543 | private: |
542 | KMD5(const KMD5& u); | 544 | KMD5(const KMD5& u); |
543 | KMD5& operator=(const KMD5& md); | 545 | KMD5& operator=(const KMD5& md); |
544 | 546 | ||
545 | void init(); | 547 | void init(); |
546 | void encode( unsigned char* output, Q_UINT32 *in, Q_UINT32 len ); | 548 | void encode( unsigned char* output, Q_UINT32 *in, Q_UINT32 len ); |
547 | void decode( Q_UINT32 *output, const unsigned char* in, Q_UINT32 len ); | 549 | void decode( Q_UINT32 *output, const unsigned char* in, Q_UINT32 len ); |
548 | 550 | ||
549 | Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n ); | 551 | Q_UINT32 rotate_left( Q_UINT32 x, Q_UINT32 n ); |
550 | Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); | 552 | Q_UINT32 F( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); |
551 | Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); | 553 | Q_UINT32 G( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); |
552 | Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); | 554 | Q_UINT32 H( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); |
553 | Q_UINT32 I( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); | 555 | Q_UINT32 I( Q_UINT32 x, Q_UINT32 y, Q_UINT32 z ); |
554 | void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, | 556 | void FF( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, |
555 | Q_UINT32 s, Q_UINT32 ac ); | 557 | Q_UINT32 s, Q_UINT32 ac ); |
556 | void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, | 558 | void GG( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, |
557 | Q_UINT32 s, Q_UINT32 ac ); | 559 | Q_UINT32 s, Q_UINT32 ac ); |
558 | void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, | 560 | void HH( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, |
559 | Q_UINT32 s, Q_UINT32 ac ); | 561 | Q_UINT32 s, Q_UINT32 ac ); |
diff --git a/microkde/kdecore/kprefs.cpp b/microkde/kdecore/kprefs.cpp index 0220a34..d4010fa 100644 --- a/microkde/kdecore/kprefs.cpp +++ b/microkde/kdecore/kprefs.cpp | |||
@@ -1,55 +1,57 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | // $Id$ | 21 | // $Id$ |
22 | 22 | ||
23 | #include <qcolor.h> | 23 | #include <qcolor.h> |
24 | //Added by qt3to4: | ||
25 | #include <Q3ValueList> | ||
24 | 26 | ||
25 | #include <kconfig.h> | 27 | #include <kconfig.h> |
26 | #include <kstandarddirs.h> | 28 | #include <kstandarddirs.h> |
27 | #include <kglobal.h> | 29 | #include <kglobal.h> |
28 | #include <kdebug.h> | 30 | #include <kdebug.h> |
29 | 31 | ||
30 | #include "kprefs.h" | 32 | #include "kprefs.h" |
31 | 33 | ||
32 | class KPrefsItemBool : public KPrefsItem { | 34 | class KPrefsItemBool : public KPrefsItem { |
33 | public: | 35 | public: |
34 | KPrefsItemBool(const QString &group,const QString &name,bool *,bool defaultValue=true); | 36 | KPrefsItemBool(const QString &group,const QString &name,bool *,bool defaultValue=true); |
35 | virtual ~KPrefsItemBool() {} | 37 | virtual ~KPrefsItemBool() {} |
36 | 38 | ||
37 | void setDefault(); | 39 | void setDefault(); |
38 | void readConfig(KConfig *); | 40 | void readConfig(KConfig *); |
39 | void writeConfig(KConfig *); | 41 | void writeConfig(KConfig *); |
40 | 42 | ||
41 | private: | 43 | private: |
42 | bool *mReference; | 44 | bool *mReference; |
43 | bool mDefault; | 45 | bool mDefault; |
44 | }; | 46 | }; |
45 | 47 | ||
46 | class KPrefsItemInt : public KPrefsItem { | 48 | class KPrefsItemInt : public KPrefsItem { |
47 | public: | 49 | public: |
48 | KPrefsItemInt(const QString &group,const QString &name,int *,int defaultValue=0); | 50 | KPrefsItemInt(const QString &group,const QString &name,int *,int defaultValue=0); |
49 | virtual ~KPrefsItemInt() {} | 51 | virtual ~KPrefsItemInt() {} |
50 | 52 | ||
51 | void setDefault(); | 53 | void setDefault(); |
52 | void readConfig(KConfig *); | 54 | void readConfig(KConfig *); |
53 | void writeConfig(KConfig *); | 55 | void writeConfig(KConfig *); |
54 | 56 | ||
55 | private: | 57 | private: |
@@ -111,75 +113,75 @@ class KPrefsItemString : public KPrefsItem { | |||
111 | const QString &defaultValue="", bool isPassword=false); | 113 | const QString &defaultValue="", bool isPassword=false); |
112 | virtual ~KPrefsItemString() {} | 114 | virtual ~KPrefsItemString() {} |
113 | 115 | ||
114 | void setDefault(); | 116 | void setDefault(); |
115 | void readConfig(KConfig *); | 117 | void readConfig(KConfig *); |
116 | void writeConfig(KConfig *); | 118 | void writeConfig(KConfig *); |
117 | 119 | ||
118 | private: | 120 | private: |
119 | QString *mReference; | 121 | QString *mReference; |
120 | QString mDefault; | 122 | QString mDefault; |
121 | bool mPassword; | 123 | bool mPassword; |
122 | }; | 124 | }; |
123 | 125 | ||
124 | 126 | ||
125 | class KPrefsItemStringList : public KPrefsItem { | 127 | class KPrefsItemStringList : public KPrefsItem { |
126 | public: | 128 | public: |
127 | KPrefsItemStringList(const QString &group,const QString &name,QStringList *, | 129 | KPrefsItemStringList(const QString &group,const QString &name,QStringList *, |
128 | const QStringList &defaultValue=QStringList()); | 130 | const QStringList &defaultValue=QStringList()); |
129 | virtual ~KPrefsItemStringList() {} | 131 | virtual ~KPrefsItemStringList() {} |
130 | 132 | ||
131 | void setDefault(); | 133 | void setDefault(); |
132 | void readConfig(KConfig *); | 134 | void readConfig(KConfig *); |
133 | void writeConfig(KConfig *); | 135 | void writeConfig(KConfig *); |
134 | 136 | ||
135 | private: | 137 | private: |
136 | QStringList *mReference; | 138 | QStringList *mReference; |
137 | QStringList mDefault; | 139 | QStringList mDefault; |
138 | }; | 140 | }; |
139 | 141 | ||
140 | 142 | ||
141 | class KPrefsItemIntList : public KPrefsItem { | 143 | class KPrefsItemIntList : public KPrefsItem { |
142 | public: | 144 | public: |
143 | KPrefsItemIntList(const QString &group,const QString &name,QValueList<int> *, | 145 | KPrefsItemIntList(const QString &group,const QString &name,Q3ValueList<int> *, |
144 | const QValueList<int> &defaultValue=QValueList<int>()); | 146 | const Q3ValueList<int> &defaultValue=Q3ValueList<int>()); |
145 | virtual ~KPrefsItemIntList() {} | 147 | virtual ~KPrefsItemIntList() {} |
146 | 148 | ||
147 | void setDefault(); | 149 | void setDefault(); |
148 | void readConfig(KConfig *); | 150 | void readConfig(KConfig *); |
149 | void writeConfig(KConfig *); | 151 | void writeConfig(KConfig *); |
150 | 152 | ||
151 | private: | 153 | private: |
152 | QValueList<int> *mReference; | 154 | Q3ValueList<int> *mReference; |
153 | QValueList<int> mDefault; | 155 | Q3ValueList<int> mDefault; |
154 | }; | 156 | }; |
155 | 157 | ||
156 | 158 | ||
157 | KPrefsItemBool::KPrefsItemBool(const QString &group,const QString &name, | 159 | KPrefsItemBool::KPrefsItemBool(const QString &group,const QString &name, |
158 | bool *reference,bool defaultValue) : | 160 | bool *reference,bool defaultValue) : |
159 | KPrefsItem(group,name) | 161 | KPrefsItem(group,name) |
160 | { | 162 | { |
161 | mReference = reference; | 163 | mReference = reference; |
162 | mDefault = defaultValue; | 164 | mDefault = defaultValue; |
163 | } | 165 | } |
164 | 166 | ||
165 | void KPrefsItemBool::setDefault() | 167 | void KPrefsItemBool::setDefault() |
166 | { | 168 | { |
167 | *mReference = mDefault; | 169 | *mReference = mDefault; |
168 | } | 170 | } |
169 | 171 | ||
170 | void KPrefsItemBool::writeConfig(KConfig *config) | 172 | void KPrefsItemBool::writeConfig(KConfig *config) |
171 | { | 173 | { |
172 | config->setGroup(mGroup); | 174 | config->setGroup(mGroup); |
173 | config->writeEntry(mName,*mReference); | 175 | config->writeEntry(mName,*mReference); |
174 | } | 176 | } |
175 | 177 | ||
176 | 178 | ||
177 | void KPrefsItemBool::readConfig(KConfig *config) | 179 | void KPrefsItemBool::readConfig(KConfig *config) |
178 | { | 180 | { |
179 | config->setGroup(mGroup); | 181 | config->setGroup(mGroup); |
180 | *mReference = config->readBoolEntry(mName,mDefault); | 182 | *mReference = config->readBoolEntry(mName,mDefault); |
181 | } | 183 | } |
182 | 184 | ||
183 | 185 | ||
184 | KPrefsItemInt::KPrefsItemInt(const QString &group,const QString &name, | 186 | KPrefsItemInt::KPrefsItemInt(const QString &group,const QString &name, |
185 | int *reference,int defaultValue) : | 187 | int *reference,int defaultValue) : |
@@ -335,65 +337,65 @@ void KPrefsItemString::readConfig(KConfig *config) | |||
335 | *mReference = config->readEntry( mName, mDefault ); | 337 | *mReference = config->readEntry( mName, mDefault ); |
336 | } | 338 | } |
337 | } | 339 | } |
338 | 340 | ||
339 | 341 | ||
340 | KPrefsItemStringList::KPrefsItemStringList(const QString &group,const QString &name, | 342 | KPrefsItemStringList::KPrefsItemStringList(const QString &group,const QString &name, |
341 | QStringList *reference,const QStringList &defaultValue) : | 343 | QStringList *reference,const QStringList &defaultValue) : |
342 | KPrefsItem(group,name) | 344 | KPrefsItem(group,name) |
343 | { | 345 | { |
344 | mReference = reference; | 346 | mReference = reference; |
345 | mDefault = defaultValue; | 347 | mDefault = defaultValue; |
346 | } | 348 | } |
347 | 349 | ||
348 | void KPrefsItemStringList::setDefault() | 350 | void KPrefsItemStringList::setDefault() |
349 | { | 351 | { |
350 | *mReference = mDefault; | 352 | *mReference = mDefault; |
351 | } | 353 | } |
352 | 354 | ||
353 | void KPrefsItemStringList::writeConfig(KConfig *config) | 355 | void KPrefsItemStringList::writeConfig(KConfig *config) |
354 | { | 356 | { |
355 | config->setGroup(mGroup); | 357 | config->setGroup(mGroup); |
356 | config->writeEntry(mName,*mReference); | 358 | config->writeEntry(mName,*mReference); |
357 | } | 359 | } |
358 | 360 | ||
359 | void KPrefsItemStringList::readConfig(KConfig *config) | 361 | void KPrefsItemStringList::readConfig(KConfig *config) |
360 | { | 362 | { |
361 | config->setGroup(mGroup); | 363 | config->setGroup(mGroup); |
362 | *mReference = config->readListEntry(mName); | 364 | *mReference = config->readListEntry(mName); |
363 | } | 365 | } |
364 | 366 | ||
365 | 367 | ||
366 | KPrefsItemIntList::KPrefsItemIntList(const QString &group,const QString &name, | 368 | KPrefsItemIntList::KPrefsItemIntList(const QString &group,const QString &name, |
367 | QValueList<int> *reference,const QValueList<int> &defaultValue) : | 369 | Q3ValueList<int> *reference,const Q3ValueList<int> &defaultValue) : |
368 | KPrefsItem(group,name) | 370 | KPrefsItem(group,name) |
369 | { | 371 | { |
370 | mReference = reference; | 372 | mReference = reference; |
371 | mDefault = defaultValue; | 373 | mDefault = defaultValue; |
372 | } | 374 | } |
373 | 375 | ||
374 | void KPrefsItemIntList::setDefault() | 376 | void KPrefsItemIntList::setDefault() |
375 | { | 377 | { |
376 | *mReference = mDefault; | 378 | *mReference = mDefault; |
377 | } | 379 | } |
378 | 380 | ||
379 | void KPrefsItemIntList::writeConfig(KConfig *config) | 381 | void KPrefsItemIntList::writeConfig(KConfig *config) |
380 | { | 382 | { |
381 | config->setGroup(mGroup); | 383 | config->setGroup(mGroup); |
382 | config->writeEntry(mName,*mReference); | 384 | config->writeEntry(mName,*mReference); |
383 | } | 385 | } |
384 | 386 | ||
385 | void KPrefsItemIntList::readConfig(KConfig *config) | 387 | void KPrefsItemIntList::readConfig(KConfig *config) |
386 | { | 388 | { |
387 | config->setGroup(mGroup); | 389 | config->setGroup(mGroup); |
388 | *mReference = config->readIntListEntry(mName); | 390 | *mReference = config->readIntListEntry(mName); |
389 | } | 391 | } |
390 | 392 | ||
391 | 393 | ||
392 | QString *KPrefs::mCurrentGroup = 0; | 394 | QString *KPrefs::mCurrentGroup = 0; |
393 | 395 | ||
394 | KPrefs::KPrefs(const QString &configname) | 396 | KPrefs::KPrefs(const QString &configname) |
395 | { | 397 | { |
396 | if (!configname.isEmpty()) { | 398 | if (!configname.isEmpty()) { |
397 | //qDebug("KPrefs::KPrefs %s",configname.latin1() ); | 399 | //qDebug("KPrefs::KPrefs %s",configname.latin1() ); |
398 | mConfig = new KConfig(locateLocal("config",configname)); | 400 | mConfig = new KConfig(locateLocal("config",configname)); |
399 | } else { | 401 | } else { |
@@ -476,37 +478,37 @@ void KPrefs::addItemInt(const QString &key,int *reference,int defaultValue) | |||
476 | 478 | ||
477 | void KPrefs::addItemColor(const QString &key,QColor *reference,const QColor &defaultValue) | 479 | void KPrefs::addItemColor(const QString &key,QColor *reference,const QColor &defaultValue) |
478 | { | 480 | { |
479 | addItem(new KPrefsItemColor(*mCurrentGroup,key,reference,defaultValue)); | 481 | addItem(new KPrefsItemColor(*mCurrentGroup,key,reference,defaultValue)); |
480 | } | 482 | } |
481 | 483 | ||
482 | void KPrefs::addItemFont(const QString &key,QFont *reference,const QFont &defaultValue) | 484 | void KPrefs::addItemFont(const QString &key,QFont *reference,const QFont &defaultValue) |
483 | { | 485 | { |
484 | addItem(new KPrefsItemFont(*mCurrentGroup,key,reference,defaultValue)); | 486 | addItem(new KPrefsItemFont(*mCurrentGroup,key,reference,defaultValue)); |
485 | } | 487 | } |
486 | 488 | ||
487 | void KPrefs::addItemSize(const QString &key,QSize *reference,const QSize &defaultValue) | 489 | void KPrefs::addItemSize(const QString &key,QSize *reference,const QSize &defaultValue) |
488 | { | 490 | { |
489 | addItem(new KPrefsItemSize(*mCurrentGroup,key,reference,defaultValue)); | 491 | addItem(new KPrefsItemSize(*mCurrentGroup,key,reference,defaultValue)); |
490 | } | 492 | } |
491 | 493 | ||
492 | void KPrefs::addItemString(const QString &key,QString *reference,const QString &defaultValue) | 494 | void KPrefs::addItemString(const QString &key,QString *reference,const QString &defaultValue) |
493 | { | 495 | { |
494 | addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,false)); | 496 | addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,false)); |
495 | } | 497 | } |
496 | 498 | ||
497 | void KPrefs::addItemPassword(const QString &key,QString *reference,const QString &defaultValue) | 499 | void KPrefs::addItemPassword(const QString &key,QString *reference,const QString &defaultValue) |
498 | { | 500 | { |
499 | addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,true)); | 501 | addItem(new KPrefsItemString(*mCurrentGroup,key,reference,defaultValue,true)); |
500 | } | 502 | } |
501 | 503 | ||
502 | void KPrefs::addItemStringList(const QString &key,QStringList *reference, | 504 | void KPrefs::addItemStringList(const QString &key,QStringList *reference, |
503 | const QStringList &defaultValue) | 505 | const QStringList &defaultValue) |
504 | { | 506 | { |
505 | addItem(new KPrefsItemStringList(*mCurrentGroup,key,reference,defaultValue)); | 507 | addItem(new KPrefsItemStringList(*mCurrentGroup,key,reference,defaultValue)); |
506 | } | 508 | } |
507 | 509 | ||
508 | void KPrefs::addItemIntList(const QString &key,QValueList<int> *reference, | 510 | void KPrefs::addItemIntList(const QString &key,Q3ValueList<int> *reference, |
509 | const QValueList<int> &defaultValue) | 511 | const Q3ValueList<int> &defaultValue) |
510 | { | 512 | { |
511 | addItem(new KPrefsItemIntList(*mCurrentGroup,key,reference,defaultValue)); | 513 | addItem(new KPrefsItemIntList(*mCurrentGroup,key,reference,defaultValue)); |
512 | } | 514 | } |
diff --git a/microkde/kdecore/kprefs.h b/microkde/kdecore/kprefs.h index 95d2724..d9d1572 100644 --- a/microkde/kdecore/kprefs.h +++ b/microkde/kdecore/kprefs.h | |||
@@ -1,60 +1,62 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | #ifndef _KPREFS_H | 20 | #ifndef _KPREFS_H |
21 | #define _KPREFS_H | 21 | #define _KPREFS_H |
22 | // $Id$ | 22 | // $Id$ |
23 | 23 | ||
24 | #include <qptrlist.h> | 24 | #include <q3ptrlist.h> |
25 | #include <qcolor.h> | 25 | #include <qcolor.h> |
26 | #include <qfont.h> | 26 | #include <qfont.h> |
27 | #include <qsize.h> | 27 | #include <qsize.h> |
28 | #include <qstringlist.h> | 28 | #include <qstringlist.h> |
29 | //Added by qt3to4: | ||
30 | #include <Q3ValueList> | ||
29 | 31 | ||
30 | class KConfig; | 32 | class KConfig; |
31 | 33 | ||
32 | /** | 34 | /** |
33 | @short Class for storing a preferences setting | 35 | @short Class for storing a preferences setting |
34 | @author Cornelius Schumacher | 36 | @author Cornelius Schumacher |
35 | @see KPref | 37 | @see KPref |
36 | 38 | ||
37 | This class represents one preferences setting as used by @ref KPrefs. | 39 | This class represents one preferences setting as used by @ref KPrefs. |
38 | Subclasses of KPrefsItem implement storage functions for a certain type of | 40 | Subclasses of KPrefsItem implement storage functions for a certain type of |
39 | setting. Normally you don't have to use this class directly. Use the special | 41 | setting. Normally you don't have to use this class directly. Use the special |
40 | addItem() functions of KPrefs instead. If you subclass this class you will | 42 | addItem() functions of KPrefs instead. If you subclass this class you will |
41 | have to register instances with the function KPrefs::addItem(). | 43 | have to register instances with the function KPrefs::addItem(). |
42 | */ | 44 | */ |
43 | class KPrefsItem { | 45 | class KPrefsItem { |
44 | public: | 46 | public: |
45 | /** | 47 | /** |
46 | Constructor. | 48 | Constructor. |
47 | 49 | ||
48 | @param group Config file group. | 50 | @param group Config file group. |
49 | @param name Config file key. | 51 | @param name Config file key. |
50 | */ | 52 | */ |
51 | KPrefsItem(const QString &group,const QString &name) : | 53 | KPrefsItem(const QString &group,const QString &name) : |
52 | mGroup(group),mName(name) {} | 54 | mGroup(group),mName(name) {} |
53 | /** | 55 | /** |
54 | Destructor. | 56 | Destructor. |
55 | */ | 57 | */ |
56 | virtual ~KPrefsItem() {} | 58 | virtual ~KPrefsItem() {} |
57 | 59 | ||
58 | /** | 60 | /** |
59 | This function is called by @ref KPrefs to set this setting to its default | 61 | This function is called by @ref KPrefs to set this setting to its default |
60 | value. | 62 | value. |
@@ -254,63 +256,63 @@ class KPrefs { | |||
254 | @param key Key used in config file. | 256 | @param key Key used in config file. |
255 | @param reference Pointer to the variable, which is set by readConfig() | 257 | @param reference Pointer to the variable, which is set by readConfig() |
256 | and setDefaults() calls and read by writeConfig() calls. | 258 | and setDefaults() calls and read by writeConfig() calls. |
257 | @param defaultValue Default value, which is used by setDefaults() and | 259 | @param defaultValue Default value, which is used by setDefaults() and |
258 | when the config file does not yet contain the key of | 260 | when the config file does not yet contain the key of |
259 | this item. | 261 | this item. |
260 | */ | 262 | */ |
261 | void addItemPassword(const QString &key,QString *reference, | 263 | void addItemPassword(const QString &key,QString *reference, |
262 | const QString &defaultValue=""); | 264 | const QString &defaultValue=""); |
263 | /** | 265 | /** |
264 | Register an item of type QStringList. | 266 | Register an item of type QStringList. |
265 | 267 | ||
266 | @param key Key used in config file. | 268 | @param key Key used in config file. |
267 | @param reference Pointer to the variable, which is set by readConfig() | 269 | @param reference Pointer to the variable, which is set by readConfig() |
268 | and setDefaults() calls and read by writeConfig() calls. | 270 | and setDefaults() calls and read by writeConfig() calls. |
269 | @param defaultValue Default value, which is used by setDefaults() and | 271 | @param defaultValue Default value, which is used by setDefaults() and |
270 | when the config file does not yet contain the key of | 272 | when the config file does not yet contain the key of |
271 | this item. | 273 | this item. |
272 | */ | 274 | */ |
273 | void addItemStringList(const QString &key,QStringList *reference, | 275 | void addItemStringList(const QString &key,QStringList *reference, |
274 | const QStringList &defaultValue=QStringList()); | 276 | const QStringList &defaultValue=QStringList()); |
275 | 277 | ||
276 | /** | 278 | /** |
277 | Register an item of type QValueList<int>. | 279 | Register an item of type QValueList<int>. |
278 | 280 | ||
279 | @param key Key used in config file. | 281 | @param key Key used in config file. |
280 | @param reference Pointer to the variable, which is set by readConfig() | 282 | @param reference Pointer to the variable, which is set by readConfig() |
281 | and setDefaults() calls and read by writeConfig() calls. | 283 | and setDefaults() calls and read by writeConfig() calls. |
282 | @param defaultValue Default value, which is used by setDefaults() and | 284 | @param defaultValue Default value, which is used by setDefaults() and |
283 | when the config file does not yet contain the key of | 285 | when the config file does not yet contain the key of |
284 | this item. | 286 | this item. |
285 | */ | 287 | */ |
286 | void addItemIntList(const QString &key,QValueList<int> *reference, | 288 | void addItemIntList(const QString &key,Q3ValueList<int> *reference, |
287 | const QValueList<int> &defaultValue=QValueList<int>()); | 289 | const Q3ValueList<int> &defaultValue=Q3ValueList<int>()); |
288 | 290 | ||
289 | protected: | 291 | protected: |
290 | /** | 292 | /** |
291 | Implemented by subclasses that use special defaults. | 293 | Implemented by subclasses that use special defaults. |
292 | */ | 294 | */ |
293 | virtual void usrSetDefaults() {}; | 295 | virtual void usrSetDefaults() {}; |
294 | /** | 296 | /** |
295 | Implemented by subclasses that read special config values. | 297 | Implemented by subclasses that read special config values. |
296 | */ | 298 | */ |
297 | virtual void usrReadConfig() {}; | 299 | virtual void usrReadConfig() {}; |
298 | /** | 300 | /** |
299 | Implemented by subclasses that write special config values. | 301 | Implemented by subclasses that write special config values. |
300 | */ | 302 | */ |
301 | virtual void usrWriteConfig() {}; | 303 | virtual void usrWriteConfig() {}; |
302 | 304 | ||
303 | /** | 305 | /** |
304 | Return the @ref KConfig object used for reading and writing the settings. | 306 | Return the @ref KConfig object used for reading and writing the settings. |
305 | */ | 307 | */ |
306 | KConfig *config() const; | 308 | KConfig *config() const; |
307 | 309 | ||
308 | private: | 310 | private: |
309 | static QString *mCurrentGroup; | 311 | static QString *mCurrentGroup; |
310 | 312 | ||
311 | KConfig *mConfig; // pointer to KConfig object | 313 | KConfig *mConfig; // pointer to KConfig object |
312 | 314 | ||
313 | QPtrList<KPrefsItem> mItems; | 315 | Q3PtrList<KPrefsItem> mItems; |
314 | }; | 316 | }; |
315 | 317 | ||
316 | #endif | 318 | #endif |
diff --git a/microkde/kdecore/kshortcut.h b/microkde/kdecore/kshortcut.h index 4813734..244d590 100644 --- a/microkde/kdecore/kshortcut.h +++ b/microkde/kdecore/kshortcut.h | |||
@@ -534,110 +534,110 @@ class KKey | |||
534 | 534 | ||
535 | /** | 535 | /** |
536 | * The KShortcut class is used to represent a keyboard shortcut to an action. | 536 | * The KShortcut class is used to represent a keyboard shortcut to an action. |
537 | * A shortcut is normally a single key with modifiers, such as Ctrl+V. | 537 | * A shortcut is normally a single key with modifiers, such as Ctrl+V. |
538 | * A KShortcut object may also contain an alternate key which will also | 538 | * A KShortcut object may also contain an alternate key which will also |
539 | * activate the action it's associated to, as long as no other actions have | 539 | * activate the action it's associated to, as long as no other actions have |
540 | * defined that key as their primary key. Ex: Ctrl+V;Shift+Insert. | 540 | * defined that key as their primary key. Ex: Ctrl+V;Shift+Insert. |
541 | */ | 541 | */ |
542 | 542 | ||
543 | class KShortcut | 543 | class KShortcut |
544 | { | 544 | { |
545 | public: | 545 | public: |
546 | /** | 546 | /** |
547 | * The maximum number of key sequences that can be contained in | 547 | * The maximum number of key sequences that can be contained in |
548 | * a KShortcut. | 548 | * a KShortcut. |
549 | */ | 549 | */ |
550 | enum { MAX_SEQUENCES = 2 }; | 550 | enum { MAX_SEQUENCES = 2 }; |
551 | 551 | ||
552 | /** | 552 | /** |
553 | * Creates a new null shortcut. | 553 | * Creates a new null shortcut. |
554 | * @see null() | 554 | * @see null() |
555 | * @see isNull() | 555 | * @see isNull() |
556 | * @see clear() | 556 | * @see clear() |
557 | */ | 557 | */ |
558 | KShortcut() {} | 558 | KShortcut() {} |
559 | 559 | ||
560 | /** | 560 | /** |
561 | * Creates a new shortcut with the given Qt key code | 561 | * Creates a new shortcut with the given Qt key code |
562 | * as the only key sequence. | 562 | * as the only key sequence. |
563 | * @param keyQt the qt keycode | 563 | * @param keyQt the qt keycode |
564 | * @see Qt::Key | 564 | * @see Qt::Key |
565 | */ | 565 | */ |
566 | KShortcut( int keyQt ) {} | 566 | KShortcut( int /*keyQt */) {} |
567 | 567 | ||
568 | /** | 568 | /** |
569 | * Creates a new shortcut that contains only the given qt key | 569 | * Creates a new shortcut that contains only the given qt key |
570 | * sequence. | 570 | * sequence. |
571 | * @param keySeq the qt key sequence to add | 571 | * @param keySeq the qt key sequence to add |
572 | */ | 572 | */ |
573 | //USKShortcut( const QKeySequence& keySeq ) {} | 573 | //USKShortcut( const QKeySequence& keySeq ) {} |
574 | 574 | ||
575 | /** | 575 | /** |
576 | * Creates a new shortcut that contains only the given key | 576 | * Creates a new shortcut that contains only the given key |
577 | * in its only sequence. | 577 | * in its only sequence. |
578 | * @param key the key to add | 578 | * @param key the key to add |
579 | */ | 579 | */ |
580 | //USKShortcut( const KKey& key ); | 580 | //USKShortcut( const KKey& key ); |
581 | 581 | ||
582 | /** | 582 | /** |
583 | * Creates a new shortcut that contains only the given key | 583 | * Creates a new shortcut that contains only the given key |
584 | * sequence. | 584 | * sequence. |
585 | * @param keySeq the key sequence to add | 585 | * @param keySeq the key sequence to add |
586 | */ | 586 | */ |
587 | //USKShortcut( const KKeySequence& keySeq ); | 587 | //USKShortcut( const KKeySequence& keySeq ); |
588 | 588 | ||
589 | /** | 589 | /** |
590 | * Copies the given shortcut. | 590 | * Copies the given shortcut. |
591 | * @param shortcut the shortcut to add | 591 | * @param shortcut the shortcut to add |
592 | */ | 592 | */ |
593 | //USKShortcut( const KShortcut& shortcut ); | 593 | //USKShortcut( const KShortcut& shortcut ); |
594 | 594 | ||
595 | /** | 595 | /** |
596 | * Creates a new key sequence that contains the given key sequence. | 596 | * Creates a new key sequence that contains the given key sequence. |
597 | * The description consists of semicolon-separated keys as | 597 | * The description consists of semicolon-separated keys as |
598 | * used in @ref KKeySequence::KKeySequence(const QString&). | 598 | * used in @ref KKeySequence::KKeySequence(const QString&). |
599 | * @param shortcut the description of the key | 599 | * @param shortcut the description of the key |
600 | * @see KKeySequence::KKeySequence(const QString&) | 600 | * @see KKeySequence::KKeySequence(const QString&) |
601 | */ | 601 | */ |
602 | KShortcut( const char* shortcut ) {} | 602 | KShortcut( const char* /*shortcut */) {} |
603 | 603 | ||
604 | /** | 604 | /** |
605 | * Creates a new key sequence that contains the given key sequence. | 605 | * Creates a new key sequence that contains the given key sequence. |
606 | * The description consists of semicolon-separated keys as | 606 | * The description consists of semicolon-separated keys as |
607 | * used in @ref KKeySequence::KKeySequence(const QString&). | 607 | * used in @ref KKeySequence::KKeySequence(const QString&). |
608 | * @param shortcut the description of the key | 608 | * @param shortcut the description of the key |
609 | * @see KKeySequence::KKeySequence(const QString&) | 609 | * @see KKeySequence::KKeySequence(const QString&) |
610 | */ | 610 | */ |
611 | KShortcut( const QString& shortcut ) {} | 611 | KShortcut( const QString& /*shortcut */) {} |
612 | ~KShortcut() {} | 612 | ~KShortcut() {} |
613 | 613 | ||
614 | /** | 614 | /** |
615 | * Clears the shortcut. The shortcut is null after calling this | 615 | * Clears the shortcut. The shortcut is null after calling this |
616 | * function. | 616 | * function. |
617 | * @see isNull() | 617 | * @see isNull() |
618 | */ | 618 | */ |
619 | //USvoid clear(); | 619 | //USvoid clear(); |
620 | 620 | ||
621 | /** | 621 | /** |
622 | * Initializes the shortcut with the given Qt key code | 622 | * Initializes the shortcut with the given Qt key code |
623 | * as the only key sequence. | 623 | * as the only key sequence. |
624 | * @param keyQt the qt keycode | 624 | * @param keyQt the qt keycode |
625 | * @see Qt::Key | 625 | * @see Qt::Key |
626 | */ | 626 | */ |
627 | //USbool init( int keyQt ); | 627 | //USbool init( int keyQt ); |
628 | 628 | ||
629 | /** | 629 | /** |
630 | * Initializes the shortcut with the given qt key sequence. | 630 | * Initializes the shortcut with the given qt key sequence. |
631 | * @param keySeq the qt key sequence to add | 631 | * @param keySeq the qt key sequence to add |
632 | */ | 632 | */ |
633 | //USbool init( const QKeySequence& keySeq ); | 633 | //USbool init( const QKeySequence& keySeq ); |
634 | 634 | ||
635 | /** | 635 | /** |
636 | * Initializes the shortcut with the given key as its only sequence. | 636 | * Initializes the shortcut with the given key as its only sequence. |
637 | * @param key the key to add | 637 | * @param key the key to add |
638 | */ | 638 | */ |
639 | //USbool init( const KKey& key ); | 639 | //USbool init( const KKey& key ); |
640 | 640 | ||
641 | /** | 641 | /** |
642 | * Initializes the shortcut with the given qt key sequence. | 642 | * Initializes the shortcut with the given qt key sequence. |
643 | * @param keySeq the qt key sequence to add | 643 | * @param keySeq the qt key sequence to add |
@@ -787,60 +787,60 @@ class KShortcut | |||
787 | * @see MAX_SEQUENCES | 787 | * @see MAX_SEQUENCES |
788 | * @since 3.2 | 788 | * @since 3.2 |
789 | */ | 789 | */ |
790 | //USbool append( const KKey& spec ); | 790 | //USbool append( const KKey& spec ); |
791 | 791 | ||
792 | /** | 792 | /** |
793 | * Appends the sequences from the given shortcut. | 793 | * Appends the sequences from the given shortcut. |
794 | * @param cut the shortcut to append | 794 | * @param cut the shortcut to append |
795 | * @return true if successful, false otherwise | 795 | * @return true if successful, false otherwise |
796 | * @see MAX_SEQUENCES | 796 | * @see MAX_SEQUENCES |
797 | * @since 3.2 | 797 | * @since 3.2 |
798 | */ | 798 | */ |
799 | //USbool append( const KShortcut& cut ); | 799 | //USbool append( const KShortcut& cut ); |
800 | 800 | ||
801 | /** | 801 | /** |
802 | * Converts this shortcut to a key sequence. The first key sequence | 802 | * Converts this shortcut to a key sequence. The first key sequence |
803 | * will be taken. | 803 | * will be taken. |
804 | */ | 804 | */ |
805 | //USoperator QKeySequence () const; | 805 | //USoperator QKeySequence () const; |
806 | 806 | ||
807 | /** | 807 | /** |
808 | * Returns a description of the shortcut as semicolon-separated | 808 | * Returns a description of the shortcut as semicolon-separated |
809 | * ket sequences, as returned by @ref KKeySequence::toString(). | 809 | * ket sequences, as returned by @ref KKeySequence::toString(). |
810 | * @return the string represenation of this shortcut | 810 | * @return the string represenation of this shortcut |
811 | * @see KKey::toString() | 811 | * @see KKey::toString() |
812 | * @see KKeySequence::toString() | 812 | * @see KKeySequence::toString() |
813 | */ | 813 | */ |
814 | //USQString toString() const; | 814 | //USQString toString() const; |
815 | 815 | ||
816 | /** | 816 | /** |
817 | * @internal | 817 | * @internal |
818 | */ | 818 | */ |
819 | QString toStringInternal( const KShortcut* pcutDefault = 0 ) const | 819 | QString toStringInternal( const KShortcut* /*pcutDefault*/ = 0 ) const |
820 | { | 820 | { |
821 | return "EMPTY IMPL."; | 821 | return "EMPTY IMPL."; |
822 | } | 822 | } |
823 | 823 | ||
824 | /** | 824 | /** |
825 | * Returns a null shortcut. | 825 | * Returns a null shortcut. |
826 | * @return the null shortcut | 826 | * @return the null shortcut |
827 | * @see isNull() | 827 | * @see isNull() |
828 | * @see clear() | 828 | * @see clear() |
829 | */ | 829 | */ |
830 | //USstatic KShortcut& null(); | 830 | //USstatic KShortcut& null(); |
831 | 831 | ||
832 | //US protected: | 832 | //US protected: |
833 | //USuint m_nSeqs; | 833 | //USuint m_nSeqs; |
834 | //USKKeySequence m_rgseq[MAX_SEQUENCES]; | 834 | //USKKeySequence m_rgseq[MAX_SEQUENCES]; |
835 | 835 | ||
836 | //US private: | 836 | //US private: |
837 | //USclass KShortcutPrivate* d; | 837 | //USclass KShortcutPrivate* d; |
838 | //USfriend class KKeyNative; | 838 | //USfriend class KKeyNative; |
839 | 839 | ||
840 | //US#ifndef KDE_NO_COMPAT | 840 | //US#ifndef KDE_NO_COMPAT |
841 | //US public: | 841 | //US public: |
842 | //USoperator int () const { return keyCodeQt(); } | 842 | //USoperator int () const { return keyCodeQt(); } |
843 | //US#endif | 843 | //US#endif |
844 | }; | 844 | }; |
845 | 845 | ||
846 | #endif // __KSHORTCUT_H | 846 | #endif // __KSHORTCUT_H |
diff --git a/microkde/kdecore/kstandarddirs.cpp b/microkde/kdecore/kstandarddirs.cpp index d5bfefd..f10934b 100644 --- a/microkde/kdecore/kstandarddirs.cpp +++ b/microkde/kdecore/kstandarddirs.cpp | |||
@@ -8,113 +8,115 @@ | |||
8 | License version 2 as published by the Free Software Foundation. | 8 | License version 2 as published by the Free Software Foundation. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> | 22 | * Author: Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> |
23 | * Version:$Id$ | 23 | * Version:$Id$ |
24 | * Generated:Thu Mar 5 16:05:28 EST 1998 | 24 | * Generated:Thu Mar 5 16:05:28 EST 1998 |
25 | */ | 25 | */ |
26 | 26 | ||
27 | //US #include "config.h" | 27 | //US #include "config.h" |
28 | 28 | ||
29 | #include <stdlib.h> | 29 | #include <stdlib.h> |
30 | #include <assert.h> | 30 | #include <assert.h> |
31 | //US#include <errno.h> | 31 | //US#include <errno.h> |
32 | //US #ifdef HAVE_SYS_STAT_H | 32 | //US #ifdef HAVE_SYS_STAT_H |
33 | //US #include <sys/stat.h> | 33 | //US #include <sys/stat.h> |
34 | //US #endif | 34 | //US #endif |
35 | //US#include <sys/types.h> | 35 | //US#include <sys/types.h> |
36 | //US#include <dirent.h> | 36 | //US#include <dirent.h> |
37 | //US#include <pwd.h> | 37 | //US#include <pwd.h> |
38 | 38 | ||
39 | #include <qregexp.h> | 39 | #include <qregexp.h> |
40 | #include <qasciidict.h> | 40 | #include <q3asciidict.h> |
41 | #include <qdict.h> | 41 | #include <q3dict.h> |
42 | #include <qdir.h> | 42 | #include <qdir.h> |
43 | #include <qfileinfo.h> | 43 | #include <qfileinfo.h> |
44 | #include <qstring.h> | 44 | #include <qstring.h> |
45 | #include <qmessagebox.h> | 45 | #include <qmessagebox.h> |
46 | #include <qapplication.h> | 46 | #include <qapplication.h> |
47 | 47 | ||
48 | #include <qstringlist.h> | 48 | #include <qstringlist.h> |
49 | //Added by qt3to4: | ||
50 | #include <Q3CString> | ||
49 | 51 | ||
50 | #include "kstandarddirs.h" | 52 | #include "kstandarddirs.h" |
51 | #include "kconfig.h" | 53 | #include "kconfig.h" |
52 | #include "kdebug.h" | 54 | #include "kdebug.h" |
53 | //US #include "kinstance.h" | 55 | //US #include "kinstance.h" |
54 | #include "kshell.h" | 56 | #include "kshell.h" |
55 | //US#include <sys/param.h> | 57 | //US#include <sys/param.h> |
56 | //US#include <unistd.h> | 58 | //US#include <unistd.h> |
57 | 59 | ||
58 | //US | 60 | //US |
59 | QString KStandardDirs::mAppDir = QString::null; | 61 | QString KStandardDirs::mAppDir = QString::null; |
60 | 62 | ||
61 | 63 | ||
62 | template class QDict<QStringList>; | 64 | template class Q3Dict<QStringList>; |
63 | 65 | ||
64 | #if 0 | 66 | #if 0 |
65 | #include <qtextedit.h> | 67 | #include <q3textedit.h> |
66 | void ddd( QString op ) | 68 | void ddd( QString op ) |
67 | { | 69 | { |
68 | static QTextEdit * dot = 0; | 70 | static Q3TextEdit * dot = 0; |
69 | if ( ! dot ) | 71 | if ( ! dot ) |
70 | dot = new QTextEdit(); | 72 | dot = new Q3TextEdit(); |
71 | 73 | ||
72 | dot->show(); | 74 | dot->show(); |
73 | 75 | ||
74 | dot->append( op ); | 76 | dot->append( op ); |
75 | 77 | ||
76 | } | 78 | } |
77 | #endif | 79 | #endif |
78 | class KStandardDirs::KStandardDirsPrivate | 80 | class KStandardDirs::KStandardDirsPrivate |
79 | { | 81 | { |
80 | public: | 82 | public: |
81 | KStandardDirsPrivate() | 83 | KStandardDirsPrivate() |
82 | : restrictionsActive(false), | 84 | : restrictionsActive(false), |
83 | dataRestrictionActive(false) | 85 | dataRestrictionActive(false) |
84 | { } | 86 | { } |
85 | 87 | ||
86 | bool restrictionsActive; | 88 | bool restrictionsActive; |
87 | bool dataRestrictionActive; | 89 | bool dataRestrictionActive; |
88 | QAsciiDict<bool> restrictions; | 90 | Q3AsciiDict<bool> restrictions; |
89 | QStringList xdgdata_prefixes; | 91 | QStringList xdgdata_prefixes; |
90 | QStringList xdgconf_prefixes; | 92 | QStringList xdgconf_prefixes; |
91 | }; | 93 | }; |
92 | 94 | ||
93 | static const char* const types[] = {"html", "icon", "apps", "sound", | 95 | static const char* const types[] = {"html", "icon", "apps", "sound", |
94 | "data", "locale", "services", "mime", | 96 | "data", "locale", "services", "mime", |
95 | "servicetypes", "config", "exe", "tmp", | 97 | "servicetypes", "config", "exe", "tmp", |
96 | "wallpaper", "lib", "pixmap", "templates", | 98 | "wallpaper", "lib", "pixmap", "templates", |
97 | "module", "qtplugins", | 99 | "module", "qtplugins", |
98 | "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 }; | 100 | "xdgdata-apps", "xdgdata-dirs", "xdgconf-menu", 0 }; |
99 | 101 | ||
100 | static int tokenize( QStringList& token, const QString& str, | 102 | static int tokenize( QStringList& token, const QString& str, |
101 | const QString& delim ); | 103 | const QString& delim ); |
102 | 104 | ||
103 | KStandardDirs::KStandardDirs( ) : addedCustoms(false) | 105 | KStandardDirs::KStandardDirs( ) : addedCustoms(false) |
104 | { | 106 | { |
105 | d = new KStandardDirsPrivate; | 107 | d = new KStandardDirsPrivate; |
106 | dircache.setAutoDelete(true); | 108 | dircache.setAutoDelete(true); |
107 | relatives.setAutoDelete(true); | 109 | relatives.setAutoDelete(true); |
108 | absolutes.setAutoDelete(true); | 110 | absolutes.setAutoDelete(true); |
109 | savelocations.setAutoDelete(true); | 111 | savelocations.setAutoDelete(true); |
110 | addKDEDefaults(); | 112 | addKDEDefaults(); |
111 | } | 113 | } |
112 | 114 | ||
113 | KStandardDirs::~KStandardDirs() | 115 | KStandardDirs::~KStandardDirs() |
114 | { | 116 | { |
115 | delete d; | 117 | delete d; |
116 | } | 118 | } |
117 | 119 | ||
118 | bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const | 120 | bool KStandardDirs::isRestrictedResource(const char *type, const QString& relPath) const |
119 | { | 121 | { |
120 | if (!d || !d->restrictionsActive) | 122 | if (!d || !d->restrictionsActive) |
@@ -416,102 +418,102 @@ static void lookupDirectory(const QString& path, const QString &relPart, | |||
416 | ++iii; | 418 | ++iii; |
417 | if ( iii == 5 ) | 419 | if ( iii == 5 ) |
418 | abort(); | 420 | abort(); |
419 | assert(path.at(path.length() - 1) == '/'); | 421 | assert(path.at(path.length() - 1) == '/'); |
420 | 422 | ||
421 | //US struct dirent *ep; | 423 | //US struct dirent *ep; |
422 | //US struct stat buff; | 424 | //US struct stat buff; |
423 | 425 | ||
424 | QString _dot("."); | 426 | QString _dot("."); |
425 | QString _dotdot(".."); | 427 | QString _dotdot(".."); |
426 | 428 | ||
427 | //US while( ( ep = readdir( dp ) ) != 0L ) | 429 | //US while( ( ep = readdir( dp ) ) != 0L ) |
428 | QStringList direntries = dp.entryList(); | 430 | QStringList direntries = dp.entryList(); |
429 | QStringList::Iterator it = direntries.begin(); | 431 | QStringList::Iterator it = direntries.begin(); |
430 | 432 | ||
431 | while ( it != list.end() ) // for each file... | 433 | while ( it != list.end() ) // for each file... |
432 | { | 434 | { |
433 | 435 | ||
434 | //US QString fn( QFile::decodeName(ep->d_name)); | 436 | //US QString fn( QFile::decodeName(ep->d_name)); |
435 | QString fn = (*it); // dp.entryList already decodes | 437 | QString fn = (*it); // dp.entryList already decodes |
436 | it++; | 438 | it++; |
437 | if ( fn.isNull() ) | 439 | if ( fn.isNull() ) |
438 | break; | 440 | break; |
439 | 441 | ||
440 | if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' ) | 442 | if (fn == _dot || fn == _dotdot || fn.at(fn.length() - 1).latin1() == '~' ) |
441 | continue; | 443 | continue; |
442 | 444 | ||
443 | /*US | 445 | /*US |
444 | if (!recursive && !regexp.exactMatch(fn)) | 446 | if (!recursive && !regexp.exactMatch(fn)) |
445 | continue; // No match | 447 | continue; // No match |
446 | */ | 448 | */ |
447 | //US this should do the same: | 449 | //US this should do the same: |
448 | int pos = regexp.match(fn); | 450 | int pos = regexp.exactMatch(fn); |
449 | if (!recursive && !pos == 0) | 451 | if (!recursive && !pos == 0) |
450 | continue; // No match | 452 | continue; // No match |
451 | 453 | ||
452 | QString pathfn = path + fn; | 454 | QString pathfn = path + fn; |
453 | /*US | 455 | /*US |
454 | if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) { | 456 | if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) { |
455 | kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; | 457 | kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; |
456 | continue; // Couldn't stat (e.g. no read permissions) | 458 | continue; // Couldn't stat (e.g. no read permissions) |
457 | } | 459 | } |
458 | 460 | ||
459 | if ( recursive ) | 461 | if ( recursive ) |
460 | { | 462 | { |
461 | if ( S_ISDIR( buff.st_mode )) { | 463 | if ( S_ISDIR( buff.st_mode )) { |
462 | lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); | 464 | lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); |
463 | } | 465 | } |
464 | */ | 466 | */ |
465 | //US replacement: | 467 | //US replacement: |
466 | QFileInfo pathfnInfo(QFile::encodeName(pathfn)); | 468 | QFileInfo pathfnInfo(QFile::encodeName(pathfn)); |
467 | if ( pathfnInfo.isReadable() == false ) | 469 | if ( pathfnInfo.isReadable() == false ) |
468 | { | 470 | { |
469 | //US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; | 471 | //US kdDebug() << "Error stat'ing " << pathfn << " : " << perror << endl; |
470 | continue; // Couldn't stat (e.g. no read permissions) | 472 | continue; // Couldn't stat (e.g. no read permissions) |
471 | } | 473 | } |
472 | 474 | ||
473 | if ( recursive ) | 475 | if ( recursive ) |
474 | { | 476 | { |
475 | if ( pathfnInfo.isDir()) { | 477 | if ( pathfnInfo.isDir()) { |
476 | lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); | 478 | lookupDirectory(pathfn + '/', relPart + fn + '/', regexp, list, relList, recursive, uniq); |
477 | } | 479 | } |
478 | 480 | ||
479 | 481 | ||
480 | /*US | 482 | /*US |
481 | if (!regexp.exactMatch(fn)) | 483 | if (!regexp.exactMatch(fn)) |
482 | continue; // No match | 484 | continue; // No match |
483 | */ | 485 | */ |
484 | //US this should do the same: | 486 | //US this should do the same: |
485 | pos = regexp.match(fn); | 487 | pos = regexp.exactMatch(fn); |
486 | if (!pos == 0) | 488 | if (!pos == 0) |
487 | continue; // No match | 489 | continue; // No match |
488 | } | 490 | } |
489 | 491 | ||
490 | //US if ( S_ISREG( buff.st_mode)) | 492 | //US if ( S_ISREG( buff.st_mode)) |
491 | if ( pathfnInfo.isFile()) | 493 | if ( pathfnInfo.isFile()) |
492 | { | 494 | { |
493 | if (!uniq || !relList.contains(relPart + fn)) | 495 | if (!uniq || !relList.contains(relPart + fn)) |
494 | { | 496 | { |
495 | list.append( pathfn ); | 497 | list.append( pathfn ); |
496 | relList.append( relPart + fn ); | 498 | relList.append( relPart + fn ); |
497 | } | 499 | } |
498 | } | 500 | } |
499 | } | 501 | } |
500 | //US closedir( dp ); | 502 | //US closedir( dp ); |
501 | } | 503 | } |
502 | else | 504 | else |
503 | { | 505 | { |
504 | // We look for a single file. | 506 | // We look for a single file. |
505 | QString fn = pattern; | 507 | QString fn = pattern; |
506 | QString pathfn = path + fn; | 508 | QString pathfn = path + fn; |
507 | //US struct stat buff; | 509 | //US struct stat buff; |
508 | QFileInfo pathfnInfo(QFile::encodeName(pathfn)); | 510 | QFileInfo pathfnInfo(QFile::encodeName(pathfn)); |
509 | 511 | ||
510 | 512 | ||
511 | //US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) | 513 | //US if ( stat( QFile::encodeName(pathfn), &buff ) != 0 ) |
512 | if ( pathfnInfo.isReadable() == false ) | 514 | if ( pathfnInfo.isReadable() == false ) |
513 | return; // File not found | 515 | return; // File not found |
514 | 516 | ||
515 | //US if ( S_ISREG( buff.st_mode)) | 517 | //US if ( S_ISREG( buff.st_mode)) |
516 | if ( pathfnInfo.isFile()) | 518 | if ( pathfnInfo.isFile()) |
517 | { | 519 | { |
@@ -1079,65 +1081,65 @@ QString KStandardDirs::relativeLocation(const char *type, const QString &absPath | |||
1079 | return fullPath.mid((*it).length()); | 1081 | return fullPath.mid((*it).length()); |
1080 | } | 1082 | } |
1081 | 1083 | ||
1082 | return absPath; | 1084 | return absPath; |
1083 | } | 1085 | } |
1084 | 1086 | ||
1085 | 1087 | ||
1086 | bool KStandardDirs::makeDir(const QString& dir2, int mode) | 1088 | bool KStandardDirs::makeDir(const QString& dir2, int mode) |
1087 | { | 1089 | { |
1088 | QString dir = QDir::convertSeparators( dir2 ); | 1090 | QString dir = QDir::convertSeparators( dir2 ); |
1089 | #if 0 | 1091 | #if 0 |
1090 | //LR | 1092 | //LR |
1091 | 1093 | ||
1092 | // we want an absolute path | 1094 | // we want an absolute path |
1093 | if (dir.at(0) != '/') | 1095 | if (dir.at(0) != '/') |
1094 | return false; | 1096 | return false; |
1095 | 1097 | ||
1096 | QString target = dir; | 1098 | QString target = dir; |
1097 | uint len = target.length(); | 1099 | uint len = target.length(); |
1098 | 1100 | ||
1099 | // append trailing slash if missing | 1101 | // append trailing slash if missing |
1100 | if (dir.at(len - 1) != '/') | 1102 | if (dir.at(len - 1) != '/') |
1101 | target += '/'; | 1103 | target += '/'; |
1102 | 1104 | ||
1103 | QString base(""); | 1105 | QString base(""); |
1104 | uint i = 1; | 1106 | uint i = 1; |
1105 | 1107 | ||
1106 | while( i < len ) | 1108 | while( i < len ) |
1107 | { | 1109 | { |
1108 | //US struct stat st; | 1110 | //US struct stat st; |
1109 | int pos = target.find('/', i); | 1111 | int pos = target.find('/', i); |
1110 | base += target.mid(i - 1, pos - i + 1); | 1112 | base += target.mid(i - 1, pos - i + 1); |
1111 | QCString baseEncoded = QFile::encodeName(base); | 1113 | Q3CString baseEncoded = QFile::encodeName(base); |
1112 | // bail out if we encountered a problem | 1114 | // bail out if we encountered a problem |
1113 | //US if (stat(baseEncoded, &st) != 0) | 1115 | //US if (stat(baseEncoded, &st) != 0) |
1114 | QFileInfo baseEncodedInfo(baseEncoded); | 1116 | QFileInfo baseEncodedInfo(baseEncoded); |
1115 | if (!baseEncodedInfo.exists()) | 1117 | if (!baseEncodedInfo.exists()) |
1116 | { | 1118 | { |
1117 | // Directory does not exist.... | 1119 | // Directory does not exist.... |
1118 | // Or maybe a dangling symlink ? | 1120 | // Or maybe a dangling symlink ? |
1119 | //US if (lstat(baseEncoded, &st) == 0) | 1121 | //US if (lstat(baseEncoded, &st) == 0) |
1120 | if (baseEncodedInfo.isSymLink()) { | 1122 | if (baseEncodedInfo.isSymLink()) { |
1121 | //US (void)unlink(baseEncoded); // try removing | 1123 | //US (void)unlink(baseEncoded); // try removing |
1122 | QFile(baseEncoded).remove(); | 1124 | QFile(baseEncoded).remove(); |
1123 | } | 1125 | } |
1124 | 1126 | ||
1125 | //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) | 1127 | //US if ( mkdir(baseEncoded, (mode_t) mode) != 0) |
1126 | QDir dirObj; | 1128 | QDir dirObj; |
1127 | if ( dirObj.mkdir(baseEncoded) != true ) | 1129 | if ( dirObj.mkdir(baseEncoded) != true ) |
1128 | { | 1130 | { |
1129 | //US perror("trying to create local folder"); | 1131 | //US perror("trying to create local folder"); |
1130 | return false; // Couldn't create it :-( | 1132 | return false; // Couldn't create it :-( |
1131 | } | 1133 | } |
1132 | } | 1134 | } |
1133 | i = pos + 1; | 1135 | i = pos + 1; |
1134 | } | 1136 | } |
1135 | return true; | 1137 | return true; |
1136 | #endif | 1138 | #endif |
1137 | 1139 | ||
1138 | // ******************************************** | 1140 | // ******************************************** |
1139 | // new code for WIN32 | 1141 | // new code for WIN32 |
1140 | QDir dirObj; | 1142 | QDir dirObj; |
1141 | 1143 | ||
1142 | 1144 | ||
1143 | // we want an absolute path | 1145 | // we want an absolute path |
@@ -1179,65 +1181,65 @@ bool KStandardDirs::makeDir(const QString& dir2, int mode) | |||
1179 | if (lstat(baseEncoded, &st) == 0) | 1181 | if (lstat(baseEncoded, &st) == 0) |
1180 | (void)unlink(baseEncoded); // try removing | 1182 | (void)unlink(baseEncoded); // try removing |
1181 | 1183 | ||
1182 | 1184 | ||
1183 | if ( mkdir(baseEncoded, (mode_t) mode) != 0) { | 1185 | if ( mkdir(baseEncoded, (mode_t) mode) != 0) { |
1184 | perror("trying to create local folder"); | 1186 | perror("trying to create local folder"); |
1185 | return false; // Couldn't create it :-( | 1187 | return false; // Couldn't create it :-( |
1186 | } | 1188 | } |
1187 | } | 1189 | } |
1188 | */ | 1190 | */ |
1189 | 1191 | ||
1190 | if (dirObj.exists(base) == false) | 1192 | if (dirObj.exists(base) == false) |
1191 | { | 1193 | { |
1192 | //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); | 1194 | //qDebug("KStandardDirs::makeDir try to create : %s" , base.latin1()); |
1193 | if (dirObj.mkdir(base) != true) | 1195 | if (dirObj.mkdir(base) != true) |
1194 | { | 1196 | { |
1195 | qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); | 1197 | qDebug("KStandardDirs::makeDir could not create: %s" , base.latin1()); |
1196 | return false; | 1198 | return false; |
1197 | } | 1199 | } |
1198 | } | 1200 | } |
1199 | 1201 | ||
1200 | i = pos + 1; | 1202 | i = pos + 1; |
1201 | } | 1203 | } |
1202 | return true; | 1204 | return true; |
1203 | 1205 | ||
1204 | } | 1206 | } |
1205 | 1207 | ||
1206 | QString readEnvPath(const char *env) | 1208 | QString readEnvPath(const char *env) |
1207 | { | 1209 | { |
1208 | //#ifdef _WIN32_ | 1210 | //#ifdef _WIN32_ |
1209 | // return ""; | 1211 | // return ""; |
1210 | //#else | 1212 | //#else |
1211 | QCString c_path; | 1213 | Q3CString c_path; |
1212 | if ( getenv(env) != NULL ) | 1214 | if ( getenv(env) != NULL ) |
1213 | c_path = QString ( getenv(env) ); | 1215 | c_path = QString ( getenv(env) ); |
1214 | if (c_path.isEmpty()) | 1216 | if (c_path.isEmpty()) |
1215 | return QString::null; | 1217 | return QString::null; |
1216 | return QFile::decodeName(c_path); | 1218 | return QFile::decodeName(c_path); |
1217 | //#endif | 1219 | //#endif |
1218 | 1220 | ||
1219 | } | 1221 | } |
1220 | 1222 | ||
1221 | void KStandardDirs::addKDEDefaults() | 1223 | void KStandardDirs::addKDEDefaults() |
1222 | { | 1224 | { |
1223 | 1225 | ||
1224 | //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); | 1226 | //qDebug("ERROR: KStandardDirs::addKDEDefaults() called "); |
1225 | //return; | 1227 | //return; |
1226 | QStringList kdedirList; | 1228 | QStringList kdedirList; |
1227 | 1229 | ||
1228 | // begin KDEDIRS | 1230 | // begin KDEDIRS |
1229 | QString kdedirs = readEnvPath("MICROKDEDIRS"); | 1231 | QString kdedirs = readEnvPath("MICROKDEDIRS"); |
1230 | if (!kdedirs.isEmpty()) | 1232 | if (!kdedirs.isEmpty()) |
1231 | { | 1233 | { |
1232 | tokenize(kdedirList, kdedirs, ":"); | 1234 | tokenize(kdedirList, kdedirs, ":"); |
1233 | } | 1235 | } |
1234 | else | 1236 | else |
1235 | { | 1237 | { |
1236 | QString kdedir = readEnvPath("MICROKDEDIR"); | 1238 | QString kdedir = readEnvPath("MICROKDEDIR"); |
1237 | if (!kdedir.isEmpty()) | 1239 | if (!kdedir.isEmpty()) |
1238 | { | 1240 | { |
1239 | kdedir = KShell::tildeExpand(kdedir); | 1241 | kdedir = KShell::tildeExpand(kdedir); |
1240 | kdedirList.append(kdedir); | 1242 | kdedirList.append(kdedir); |
1241 | } | 1243 | } |
1242 | } | 1244 | } |
1243 | //US kdedirList.append(KDEDIR); | 1245 | //US kdedirList.append(KDEDIR); |
diff --git a/microkde/kdecore/kstandarddirs.h b/microkde/kdecore/kstandarddirs.h index 901384e..f0e28fc 100644 --- a/microkde/kdecore/kstandarddirs.h +++ b/microkde/kdecore/kstandarddirs.h | |||
@@ -1,59 +1,59 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the KDE libraries | 2 | This file is part of the KDE libraries |
3 | Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org> | 3 | Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org> |
4 | Stephan Kulow <coolo@kde.org> | 4 | Stephan Kulow <coolo@kde.org> |
5 | Waldo Bastian <bastian@kde.org> | 5 | Waldo Bastian <bastian@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 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 | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #ifndef SSK_KSTDDIRS_H | 23 | #ifndef SSK_KSTDDIRS_H |
24 | #define SSK_KSTDDIRS_H | 24 | #define SSK_KSTDDIRS_H |
25 | 25 | ||
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qdict.h> | 27 | #include <q3dict.h> |
28 | #include <qstringlist.h> | 28 | #include <qstringlist.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | 30 | ||
31 | class KConfig; | 31 | class KConfig; |
32 | class KStandardDirsPrivate; | 32 | class KStandardDirsPrivate; |
33 | 33 | ||
34 | 34 | ||
35 | /** | 35 | /** |
36 | * @short Site-independent access to standard KDE directories. | 36 | * @short Site-independent access to standard KDE directories. |
37 | * @author Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> | 37 | * @author Stephan Kulow <coolo@kde.org> and Sirtaj Singh Kang <taj@kde.org> |
38 | * @version $Id$ | 38 | * @version $Id$ |
39 | * | 39 | * |
40 | * This is one of the most central classes in kdelibs as | 40 | * This is one of the most central classes in kdelibs as |
41 | * it provides a basic service: It knows where the files | 41 | * it provides a basic service: It knows where the files |
42 | * reside on the user's hard disk. And it's meant to be the | 42 | * reside on the user's hard disk. And it's meant to be the |
43 | * only one that knows -- to make the real location as | 43 | * only one that knows -- to make the real location as |
44 | * transparent as possible to both the user and the applications. | 44 | * transparent as possible to both the user and the applications. |
45 | * | 45 | * |
46 | * To this end it insulates the application from all information | 46 | * To this end it insulates the application from all information |
47 | * and applications always refer to a file with a resource type | 47 | * and applications always refer to a file with a resource type |
48 | * (e.g. icon) and a filename (e.g. khexdit.xpm). In an ideal world | 48 | * (e.g. icon) and a filename (e.g. khexdit.xpm). In an ideal world |
49 | * the application would make no assumption where this file is and | 49 | * the application would make no assumption where this file is and |
50 | * leave it up to @ref KStandardDirs::findResource("apps", "Home.desktop") | 50 | * leave it up to @ref KStandardDirs::findResource("apps", "Home.desktop") |
51 | * to apply this knowledge to return /opt/kde/share/applnk/Home.desktop | 51 | * to apply this knowledge to return /opt/kde/share/applnk/Home.desktop |
52 | * or ::locate("data", "kgame/background.jpg") to return | 52 | * or ::locate("data", "kgame/background.jpg") to return |
53 | * /opt/kde/share/apps/kgame/background.jpg | 53 | * /opt/kde/share/apps/kgame/background.jpg |
54 | * | 54 | * |
55 | * The main idea behind KStandardDirs is that there are several | 55 | * The main idea behind KStandardDirs is that there are several |
56 | * toplevel prefixes below which the files lie. One of these prefixes is | 56 | * toplevel prefixes below which the files lie. One of these prefixes is |
57 | * the one where the user installed kdelibs, one is where the | 57 | * the one where the user installed kdelibs, one is where the |
58 | * application was installed, and one is $HOME/.kde, but there | 58 | * application was installed, and one is $HOME/.kde, but there |
59 | * may be even more. Under these prefixes there are several well | 59 | * may be even more. Under these prefixes there are several well |
@@ -545,69 +545,69 @@ public: | |||
545 | /** | 545 | /** |
546 | * @return $XDG_CONFIG_HOME | 546 | * @return $XDG_CONFIG_HOME |
547 | * See also http://www.freedesktop.org/standards/basedir/draft/basedir-spec/basedir-spec.html | 547 | * See also http://www.freedesktop.org/standards/basedir/draft/basedir-spec/basedir-spec.html |
548 | */ | 548 | */ |
549 | QString localxdgconfdir() const; | 549 | QString localxdgconfdir() const; |
550 | 550 | ||
551 | /** | 551 | /** |
552 | * Checks for existence and accessability. | 552 | * Checks for existence and accessability. |
553 | * Faster than creating a QFileInfo first. | 553 | * Faster than creating a QFileInfo first. |
554 | * @param fullPath the path to check | 554 | * @param fullPath the path to check |
555 | * @return true if the directory exists | 555 | * @return true if the directory exists |
556 | */ | 556 | */ |
557 | static bool exists(const QString &fullPath); | 557 | static bool exists(const QString &fullPath); |
558 | 558 | ||
559 | /** | 559 | /** |
560 | * Expands all symbolic links and resolves references to | 560 | * Expands all symbolic links and resolves references to |
561 | * '/./', '/../' and extra '/' characters in @p dirname | 561 | * '/./', '/../' and extra '/' characters in @p dirname |
562 | * and returns the canonicalized absolute pathname. | 562 | * and returns the canonicalized absolute pathname. |
563 | * The resulting path will have no symbolic link, '/./' | 563 | * The resulting path will have no symbolic link, '/./' |
564 | * or '/../' components. | 564 | * or '/../' components. |
565 | * @since 3.1 | 565 | * @since 3.1 |
566 | */ | 566 | */ |
567 | static QString realPath(const QString &dirname); | 567 | static QString realPath(const QString &dirname); |
568 | 568 | ||
569 | static void setAppDir( const QString & ); | 569 | static void setAppDir( const QString & ); |
570 | static QString appDir(); | 570 | static QString appDir(); |
571 | 571 | ||
572 | private: | 572 | private: |
573 | 573 | ||
574 | QStringList prefixes; | 574 | QStringList prefixes; |
575 | 575 | ||
576 | // Directory dictionaries | 576 | // Directory dictionaries |
577 | QDict<QStringList> absolutes; | 577 | Q3Dict<QStringList> absolutes; |
578 | QDict<QStringList> relatives; | 578 | Q3Dict<QStringList> relatives; |
579 | 579 | ||
580 | mutable QDict<QStringList> dircache; | 580 | mutable Q3Dict<QStringList> dircache; |
581 | mutable QDict<QString> savelocations; | 581 | mutable Q3Dict<QString> savelocations; |
582 | 582 | ||
583 | // Disallow assignment and copy-construction | 583 | // Disallow assignment and copy-construction |
584 | KStandardDirs( const KStandardDirs& ); | 584 | KStandardDirs( const KStandardDirs& ); |
585 | KStandardDirs& operator= ( const KStandardDirs& ); | 585 | KStandardDirs& operator= ( const KStandardDirs& ); |
586 | 586 | ||
587 | bool addedCustoms; | 587 | bool addedCustoms; |
588 | 588 | ||
589 | class KStandardDirsPrivate; | 589 | class KStandardDirsPrivate; |
590 | KStandardDirsPrivate *d; | 590 | KStandardDirsPrivate *d; |
591 | //US | 591 | //US |
592 | static QString mAppDir; | 592 | static QString mAppDir; |
593 | 593 | ||
594 | void checkConfig() const; | 594 | void checkConfig() const; |
595 | void applyDataRestrictions(const QString &) const; | 595 | void applyDataRestrictions(const QString &) const; |
596 | //US void createSpecialResource(const char*); | 596 | //US void createSpecialResource(const char*); |
597 | }; | 597 | }; |
598 | 598 | ||
599 | /** | 599 | /** |
600 | * \addtogroup locates Locate Functions | 600 | * \addtogroup locates Locate Functions |
601 | * @{ | 601 | * @{ |
602 | * On The Usage Of 'locate' and 'locateLocal' | 602 | * On The Usage Of 'locate' and 'locateLocal' |
603 | * | 603 | * |
604 | * Typical KDE applications use resource files in one out of | 604 | * Typical KDE applications use resource files in one out of |
605 | * three ways: | 605 | * three ways: |
606 | * | 606 | * |
607 | * 1) A resource file is read but is never written. A system | 607 | * 1) A resource file is read but is never written. A system |
608 | * default is supplied but the user can override this | 608 | * default is supplied but the user can override this |
609 | * default in his local .kde directory: | 609 | * default in his local .kde directory: |
610 | * | 610 | * |
611 | * \code | 611 | * \code |
612 | * // Code example | 612 | * // Code example |
613 | * myFile = locate("appdata", "groups.lst"); | 613 | * myFile = locate("appdata", "groups.lst"); |