-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,131 +1,133 @@ | |||
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 | { |
55 | d->name = name; | 57 | d->name = name; |
56 | } | 58 | } |
57 | 59 | ||
58 | KCatalogue::KCatalogue(const KCatalogue & rhs) | 60 | 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 | } |
124 | d->domain.data = 0; | 126 | d->domain.data = 0; |
125 | 127 | ||
126 | // free name | 128 | // free name |
127 | delete [] const_cast<char *>(d->domain.filename); | 129 | delete [] const_cast<char *>(d->domain.filename); |
128 | d->domain.filename = 0; | 130 | d->domain.filename = 0; |
129 | 131 | ||
130 | d->domain.decided = 0; | 132 | d->domain.decided = 0; |
131 | } | 133 | } |
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,653 +1,656 @@ | |||
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() |
81 | { | 84 | { |
82 | // kdDebug(150) << "Deleting KLibFactory " << this << endl; | 85 | // kdDebug(150) << "Deleting KLibFactory " << this << endl; |
83 | } | 86 | } |
84 | 87 | ||
85 | QObject* KLibFactory::create( QObject* parent, const char* name, const char* classname, const QStringList &args ) | 88 | QObject* KLibFactory::create( QObject* parent, const char* name, const char* classname, const QStringList &args ) |
86 | { | 89 | { |
87 | QObject* obj = createObject( parent, name, classname, args ); | 90 | QObject* obj = createObject( parent, name, classname, args ); |
88 | if ( obj ) | 91 | if ( obj ) |
89 | emit objectCreated( obj ); | 92 | emit objectCreated( obj ); |
90 | return obj; | 93 | return obj; |
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 ); |
188 | void* sym = m_handle->resolve( symname ); | 191 | void* sym = m_handle->resolve( symname ); |
189 | if ( !sym ) | 192 | if ( !sym ) |
190 | { | 193 | { |
191 | //US kdWarning(150) << "KLibrary: " << lt_dlerror() << endl; | 194 | //US kdWarning(150) << "KLibrary: " << lt_dlerror() << endl; |
192 | return 0; | 195 | return 0; |
193 | } | 196 | } |
194 | 197 | ||
195 | return sym; | 198 | return sym; |
196 | } | 199 | } |
197 | 200 | ||
198 | bool KLibrary::hasSymbol( const char* symname ) const | 201 | bool KLibrary::hasSymbol( const char* symname ) const |
199 | { | 202 | { |
200 | //US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname ); | 203 | //US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname ); |
201 | void* sym = m_handle->resolve( symname ); | 204 | void* sym = m_handle->resolve( symname ); |
202 | return (sym != 0L ); | 205 | return (sym != 0L ); |
203 | } | 206 | } |
204 | 207 | ||
205 | void KLibrary::unload() const | 208 | void KLibrary::unload() const |
206 | { | 209 | { |
207 | if (KLibLoader::s_self) | 210 | if (KLibLoader::s_self) |
208 | KLibLoader::s_self->unloadLibrary(QFile::encodeName(name())); | 211 | KLibLoader::s_self->unloadLibrary(QFile::encodeName(name())); |
209 | } | 212 | } |
210 | 213 | ||
211 | void KLibrary::slotObjectCreated( QObject *obj ) | 214 | void KLibrary::slotObjectCreated( QObject *obj ) |
212 | { | 215 | { |
213 | if ( !obj ) | 216 | if ( !obj ) |
214 | return; | 217 | return; |
215 | 218 | ||
216 | if ( m_timer && m_timer->isActive() ) | 219 | if ( m_timer && m_timer->isActive() ) |
217 | m_timer->stop(); | 220 | m_timer->stop(); |
218 | 221 | ||
219 | if ( m_objs.containsRef( obj ) ) | 222 | if ( m_objs.containsRef( obj ) ) |
220 | return; // we know this object already | 223 | return; // we know this object already |
221 | 224 | ||
222 | connect( obj, SIGNAL( destroyed() ), | 225 | connect( obj, SIGNAL( destroyed() ), |
223 | this, SLOT( slotObjectDestroyed() ) ); | 226 | this, SLOT( slotObjectDestroyed() ) ); |
224 | 227 | ||
225 | m_objs.append( obj ); | 228 | m_objs.append( obj ); |
226 | } | 229 | } |
227 | 230 | ||
228 | void KLibrary::slotObjectDestroyed() | 231 | void KLibrary::slotObjectDestroyed() |
229 | { | 232 | { |
230 | m_objs.removeRef( sender() ); | 233 | m_objs.removeRef( sender() ); |
231 | 234 | ||
232 | if ( m_objs.count() == 0 ) | 235 | if ( m_objs.count() == 0 ) |
233 | { | 236 | { |
234 | // kdDebug(150) << "KLibrary: shutdown timer for " << name() << " started!" | 237 | // kdDebug(150) << "KLibrary: shutdown timer for " << name() << " started!" |
235 | // << endl; | 238 | // << endl; |
236 | 239 | ||
237 | if ( !m_timer ) | 240 | if ( !m_timer ) |
238 | { | 241 | { |
239 | m_timer = new QTimer( this, "klibrary_shutdown_timer" ); | 242 | m_timer = new QTimer( this, "klibrary_shutdown_timer" ); |
240 | connect( m_timer, SIGNAL( timeout() ), | 243 | connect( m_timer, SIGNAL( timeout() ), |
241 | this, SLOT( slotTimeout() ) ); | 244 | this, SLOT( slotTimeout() ) ); |
242 | } | 245 | } |
243 | 246 | ||
244 | // as long as it's not stable make the timeout short, for debugging | 247 | // as long as it's not stable make the timeout short, for debugging |
245 | // pleasure (matz) | 248 | // pleasure (matz) |
246 | //m_timer->start( 1000*60, true ); | 249 | //m_timer->start( 1000*60, true ); |
247 | m_timer->start( 1000*10, true ); | 250 | m_timer->start( 1000*10, true ); |
248 | } | 251 | } |
249 | } | 252 | } |
250 | 253 | ||
251 | void KLibrary::slotTimeout() | 254 | void KLibrary::slotTimeout() |
252 | { | 255 | { |
253 | if ( m_objs.count() != 0 ) | 256 | if ( m_objs.count() != 0 ) |
254 | return; | 257 | return; |
255 | 258 | ||
256 | /* Don't go through KLibLoader::unloadLibrary(), because that uses the | 259 | /* Don't go through KLibLoader::unloadLibrary(), because that uses the |
257 | ref counter, but this timeout means to unconditionally close this library | 260 | ref counter, but this timeout means to unconditionally close this library |
258 | The destroyed() signal will take care to remove us from all lists. | 261 | The destroyed() signal will take care to remove us from all lists. |
259 | */ | 262 | */ |
260 | delete this; | 263 | delete this; |
261 | } | 264 | } |
262 | 265 | ||
263 | // ------------------------------------------------- | 266 | // ------------------------------------------------- |
264 | 267 | ||
265 | /* This helper class is needed, because KLibraries can go away without | 268 | /* This helper class is needed, because KLibraries can go away without |
266 | being unloaded. So we need some info about KLibraries even after its | 269 | being unloaded. So we need some info about KLibraries even after its |
267 | death. */ | 270 | death. */ |
268 | class KLibWrapPrivate | 271 | class KLibWrapPrivate |
269 | { | 272 | { |
270 | public: | 273 | public: |
271 | //US KLibWrapPrivate(KLibrary *l, lt_dlhandle h); | 274 | //US KLibWrapPrivate(KLibrary *l, lt_dlhandle h); |
272 | KLibWrapPrivate(KLibrary *l, QLibrary* h); | 275 | KLibWrapPrivate(KLibrary *l, QLibrary* h); |
273 | 276 | ||
274 | KLibrary *lib; | 277 | KLibrary *lib; |
275 | enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; | 278 | enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; |
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; |
505 | 508 | ||
506 | KLibrary *lib = new KLibrary( name, libfile, qlib ); | 509 | KLibrary *lib = new KLibrary( name, libfile, qlib ); |
507 | wrap = new KLibWrapPrivate(lib, qlib); | 510 | wrap = new KLibWrapPrivate(lib, qlib); |
508 | d->loaded_stack.prepend(wrap); | 511 | d->loaded_stack.prepend(wrap); |
509 | } | 512 | } |
510 | m_libs.insert( name, wrap ); | 513 | m_libs.insert( name, wrap ); |
511 | 514 | ||
512 | connect( wrap->lib, SIGNAL( destroyed() ), | 515 | connect( wrap->lib, SIGNAL( destroyed() ), |
513 | this, SLOT( slotLibraryDestroyed() ) ); | 516 | this, SLOT( slotLibraryDestroyed() ) ); |
514 | 517 | ||
515 | return wrap->lib; | 518 | return wrap->lib; |
516 | } | 519 | } |
517 | 520 | ||
518 | QString KLibLoader::lastErrorMessage() const | 521 | QString KLibLoader::lastErrorMessage() const |
519 | { | 522 | { |
520 | return d->errorMessage; | 523 | return d->errorMessage; |
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; |
605 | 608 | ||
606 | #if 0 | 609 | #if 0 |
607 | #ifndef Q_WS_QWS | 610 | #ifndef Q_WS_QWS |
608 | if ( !deleted_one ) { | 611 | if ( !deleted_one ) { |
609 | /* Only do the hack once in this loop. | 612 | /* Only do the hack once in this loop. |
610 | WABA: *HACK* | 613 | WABA: *HACK* |
611 | We need to make sure to clear the clipboard before unloading a DSO | 614 | We need to make sure to clear the clipboard before unloading a DSO |
612 | because the DSO could have defined an object derived from QMimeSource | 615 | because the DSO could have defined an object derived from QMimeSource |
613 | and placed that on the clipboard. */ | 616 | and placed that on the clipboard. */ |
614 | /*kapp->clipboard()->clear();*/ | 617 | /*kapp->clipboard()->clear();*/ |
615 | 618 | ||
616 | /* Well.. let's do something more subtle... convert the clipboard context | 619 | /* Well.. let's do something more subtle... convert the clipboard context |
617 | to text. That should be safe as it only uses objects defined by Qt. */ | 620 | to text. That should be safe as it only uses objects defined by Qt. */ |
618 | 621 | ||
619 | QWidgetList *widgetlist = QApplication::topLevelWidgets(); | 622 | QWidgetList *widgetlist = QApplication::topLevelWidgets(); |
620 | QWidget *co = widgetlist->first(); | 623 | QWidget *co = widgetlist->first(); |
621 | while (co) { | 624 | while (co) { |
622 | if (qstrcmp(co->name(), "internal clipboard owner") == 0) { | 625 | if (qstrcmp(co->name(), "internal clipboard owner") == 0) { |
623 | if (XGetSelectionOwner(co->x11Display(), XA_PRIMARY) == co->winId()) | 626 | if (XGetSelectionOwner(co->x11Display(), XA_PRIMARY) == co->winId()) |
624 | kapp->clipboard()->setText(kapp->clipboard()->text()); | 627 | kapp->clipboard()->setText(kapp->clipboard()->text()); |
625 | 628 | ||
626 | break; | 629 | break; |
627 | } | 630 | } |
628 | co = widgetlist->next(); | 631 | co = widgetlist->next(); |
629 | } | 632 | } |
630 | delete widgetlist; | 633 | delete widgetlist; |
631 | } | 634 | } |
632 | #else | 635 | #else |
633 | // FIXME(E): Implement in Qt Embedded | 636 | // FIXME(E): Implement in Qt Embedded |
634 | #endif | 637 | #endif |
635 | 638 | ||
636 | #endif // 0 | 639 | #endif // 0 |
637 | deleted_one = true; | 640 | deleted_one = true; |
638 | //US lt_dlclose(wrap->handle); | 641 | //US lt_dlclose(wrap->handle); |
639 | wrap->handle->unload(); | 642 | wrap->handle->unload(); |
640 | 643 | ||
641 | d->pending_close.removeRef(wrap); | 644 | d->pending_close.removeRef(wrap); |
642 | /* loaded_stack is AutoDelete, so wrap is freed */ | 645 | /* loaded_stack is AutoDelete, so wrap is freed */ |
643 | d->loaded_stack.remove(); | 646 | d->loaded_stack.remove(); |
644 | } | 647 | } |
645 | } | 648 | } |
646 | 649 | ||
647 | void KLibLoader::virtual_hook( int, void* ) | 650 | void KLibLoader::virtual_hook( int, void* ) |
648 | { /*BASE::virtual_hook( id, data );*/ } | 651 | { /*BASE::virtual_hook( id, data );*/ } |
649 | 652 | ||
650 | void KLibFactory::virtual_hook( int, void* ) | 653 | void KLibFactory::virtual_hook( int, void* ) |
651 | { /*BASE::virtual_hook( id, data );*/ } | 654 | { /*BASE::virtual_hook( id, data );*/ } |
652 | 655 | ||
653 | //US #include "klibloader.moc" | 656 | //US #include "klibloader.moc" |
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,386 +1,386 @@ | |||
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, |
88 | * otherwise a warning will be printed. | 88 | * otherwise a warning will be printed. |
89 | * @param name the name of the symbol to look up | 89 | * @param name the name of the symbol to look up |
90 | * @return the address of the symbol, or 0 if it does not exist | 90 | * @return the address of the symbol, or 0 if it does not exist |
91 | * @see #hasSymbol | 91 | * @see #hasSymbol |
92 | */ | 92 | */ |
93 | void* symbol( const char* name ) const; | 93 | void* symbol( const char* name ) const; |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Looks up a symbol from the library. This is a very low level | 96 | * Looks up a symbol from the library. This is a very low level |
97 | * function that you usually don't want to use. | 97 | * function that you usually don't want to use. |
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. |
163 | * | 163 | * |
164 | * This is a convenience function that returns the factory immediately | 164 | * This is a convenience function that returns the factory immediately |
165 | * @param libname This is the library name without extension. Usually that is something like | 165 | * @param libname This is the library name without extension. Usually that is something like |
166 | * "libkspread". The function will then search for a file named | 166 | * "libkspread". The function will then search for a file named |
167 | * "libkspread.la" in the KDE library paths. | 167 | * "libkspread.la" in the KDE library paths. |
168 | * The *.la files are created by libtool and contain | 168 | * The *.la files are created by libtool and contain |
169 | * important information especially about the libraries dependencies | 169 | * important information especially about the libraries dependencies |
170 | * on other shared libs. Loading a "libfoo.so" could not solve the | 170 | * on other shared libs. Loading a "libfoo.so" could not solve the |
171 | * dependencies problem. | 171 | * dependencies problem. |
172 | * | 172 | * |
173 | * You can, however, give a library name ending in ".so" | 173 | * You can, however, give a library name ending in ".so" |
174 | * (or whatever is used on your platform), and the library | 174 | * (or whatever is used on your platform), and the library |
175 | * will be loaded without resolving dependencies. USE WITH CARE :) | 175 | * will be loaded without resolving dependencies. USE WITH CARE :) |
176 | * @return the @ref KLibFactory, or 0 if the library does not exist or it does | 176 | * @return the @ref KLibFactory, or 0 if the library does not exist or it does |
177 | * not have a factory | 177 | * not have a factory |
178 | * @see #library | 178 | * @see #library |
179 | */ | 179 | */ |
180 | KLibFactory* factory( const char* libname ); | 180 | KLibFactory* factory( const char* libname ); |
181 | 181 | ||
182 | /** | 182 | /** |
183 | * Loads and initializes a library. Loading a library multiple times is | 183 | * Loads and initializes a library. Loading a library multiple times is |
184 | * handled gracefully. | 184 | * handled gracefully. |
185 | * | 185 | * |
186 | * @param libname This is the library name without extension. Usually that is something like | 186 | * @param libname This is the library name without extension. Usually that is something like |
187 | * "libkspread". The function will then search for a file named | 187 | * "libkspread". The function will then search for a file named |
188 | * "libkspread.la" in the KDE library paths. | 188 | * "libkspread.la" in the KDE library paths. |
189 | * The *.la files are created by libtool and contain | 189 | * The *.la files are created by libtool and contain |
190 | * important information especially about the libraries dependencies | 190 | * important information especially about the libraries dependencies |
191 | * on other shared libs. Loading a "libfoo.so" could not solve the | 191 | * on other shared libs. Loading a "libfoo.so" could not solve the |
192 | * dependencies problem. | 192 | * dependencies problem. |
193 | * | 193 | * |
194 | * You can, however, give a library name ending in ".so" | 194 | * You can, however, give a library name ending in ".so" |
195 | * (or whatever is used on your platform), and the library | 195 | * (or whatever is used on your platform), and the library |
196 | * will be loaded without resolving dependencies. USE WITH CARE :) | 196 | * will be loaded without resolving dependencies. USE WITH CARE :) |
197 | * @return @ref KLibrary is invalid (0) when the library couldn't be dlopened. in such | 197 | * @return @ref KLibrary is invalid (0) when the library couldn't be dlopened. in such |
198 | * a case you can retrieve the error message by calling KLibLoader::lastErrorMessage() | 198 | * a case you can retrieve the error message by calling KLibLoader::lastErrorMessage() |
199 | * | 199 | * |
200 | * @see #factory | 200 | * @see #factory |
201 | */ | 201 | */ |
202 | virtual KLibrary* library( const char* libname ); | 202 | virtual KLibrary* library( const char* libname ); |
203 | 203 | ||
204 | /** | 204 | /** |
205 | * Loads and initializes a library. Loading a library multiple times is | 205 | * Loads and initializes a library. Loading a library multiple times is |
206 | * handled gracefully. The library is loaded such that the symbols are | 206 | * handled gracefully. The library is loaded such that the symbols are |
207 | * globally accessible so libraries with dependencies can be loaded | 207 | * globally accessible so libraries with dependencies can be loaded |
208 | * sequentially. | 208 | * sequentially. |
209 | * | 209 | * |
210 | * @param name This is the library name without extension. Usually that is something like | 210 | * @param name This is the library name without extension. Usually that is something like |
211 | * "libkspread". The function will then search for a file named | 211 | * "libkspread". The function will then search for a file named |
212 | * "libkspread.la" in the KDE library paths. | 212 | * "libkspread.la" in the KDE library paths. |
213 | * The *.la files are created by libtool and contain | 213 | * The *.la files are created by libtool and contain |
214 | * important information especially about the libraries dependencies | 214 | * important information especially about the libraries dependencies |
215 | * on other shared libs. Loading a "libfoo.so" could not solve the | 215 | * on other shared libs. Loading a "libfoo.so" could not solve the |
216 | * dependencies problem. | 216 | * dependencies problem. |
217 | * | 217 | * |
218 | * You can, however, give a library name ending in ".so" | 218 | * You can, however, give a library name ending in ".so" |
219 | * (or whatever is used on your platform), and the library | 219 | * (or whatever is used on your platform), and the library |
220 | * will be loaded without resolving dependencies. USE WITH CARE :) | 220 | * will be loaded without resolving dependencies. USE WITH CARE :) |
221 | * @return KLibrariy is invalid (0) when the library couldn't be dlopened. in such | 221 | * @return KLibrariy is invalid (0) when the library couldn't be dlopened. in such |
222 | * a case you can retrieve the error message by calling KLibLoader::lastErrorMessage() | 222 | * a case you can retrieve the error message by calling KLibLoader::lastErrorMessage() |
223 | * | 223 | * |
224 | * @see #factory | 224 | * @see #factory |
225 | */ | 225 | */ |
226 | KLibrary* globalLibrary( const char *name ); | 226 | KLibrary* globalLibrary( const char *name ); |
227 | 227 | ||
228 | /* | 228 | /* |
229 | * Returns an error message that can be useful to debug the problem. | 229 | * Returns an error message that can be useful to debug the problem. |
230 | * Returns QString::null if the last call to @ref #library() was successful. | 230 | * Returns QString::null if the last call to @ref #library() was successful. |
231 | * You can call this function more than once. The error message is only | 231 | * You can call this function more than once. The error message is only |
232 | * reset by a new call to library(). | 232 | * reset by a new call to library(). |
233 | * @return the last error message, or QString::null if there was no error | 233 | * @return the last error message, or QString::null if there was no error |
234 | */ | 234 | */ |
235 | QString lastErrorMessage() const; | 235 | QString lastErrorMessage() const; |
236 | 236 | ||
237 | /** | 237 | /** |
238 | * Unloads the library with the given name. | 238 | * Unloads the library with the given name. |
239 | * @param libname This is the library name without extension. Usually that is something like | 239 | * @param libname This is the library name without extension. Usually that is something like |
240 | * "libkspread". The function will then search for a file named | 240 | * "libkspread". The function will then search for a file named |
241 | * "libkspread.la" in the KDE library paths. | 241 | * "libkspread.la" in the KDE library paths. |
242 | * The *.la files are created by libtool and contain | 242 | * The *.la files are created by libtool and contain |
243 | * important information especially about the libraries dependencies | 243 | * important information especially about the libraries dependencies |
244 | * on other shared libs. Loading a "libfoo.so" could not solve the | 244 | * on other shared libs. Loading a "libfoo.so" could not solve the |
245 | * dependencies problem. | 245 | * dependencies problem. |
246 | * | 246 | * |
247 | * You can, however, give a library name ending in ".so" | 247 | * You can, however, give a library name ending in ".so" |
248 | * (or whatever is used on your platform), and the library | 248 | * (or whatever is used on your platform), and the library |
249 | * will be loaded without resolving dependencies. USE WITH CARE :) | 249 | * will be loaded without resolving dependencies. USE WITH CARE :) |
250 | */ | 250 | */ |
251 | virtual void unloadLibrary( const char *libname ); | 251 | virtual void unloadLibrary( const char *libname ); |
252 | 252 | ||
253 | /** | 253 | /** |
254 | * Returns a pointer to the factory. Use this function to get an instance | 254 | * Returns a pointer to the factory. Use this function to get an instance |
255 | * of KLibLoader. | 255 | * of KLibLoader. |
256 | * @return a pointer to the loader. If no loader exists until now | 256 | * @return a pointer to the loader. If no loader exists until now |
257 | * then one is created. | 257 | * then one is created. |
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. |
323 | * | 323 | * |
324 | * The KLibFactory is used to create the components, the library has to offer. | 324 | * The KLibFactory is used to create the components, the library has to offer. |
325 | * The factory of KSpread for example will create instances of KSpreadDoc, | 325 | * The factory of KSpread for example will create instances of KSpreadDoc, |
326 | * while the Konqueror factory will create KonqView widgets. | 326 | * while the Konqueror factory will create KonqView widgets. |
327 | * All objects created by the factory must be derived from @ref QObject, since @ref QObject | 327 | * All objects created by the factory must be derived from @ref QObject, since @ref QObject |
328 | * offers type safe casting. | 328 | * offers type safe casting. |
329 | * | 329 | * |
330 | * KLibFactory is an abstract class. Reimplement the @ref | 330 | * KLibFactory is an abstract class. Reimplement the @ref |
331 | * createObject() method to give it functionality. | 331 | * createObject() method to give it functionality. |
332 | * | 332 | * |
333 | * @author Torben Weis <weis@kde.org> | 333 | * @author Torben Weis <weis@kde.org> |
334 | */ | 334 | */ |
335 | class KLibFactory : public QObject | 335 | class KLibFactory : public QObject |
336 | { | 336 | { |
337 | Q_OBJECT | 337 | Q_OBJECT |
338 | public: | 338 | public: |
339 | /** | 339 | /** |
340 | * Create a new factory. | 340 | * Create a new factory. |
341 | * @param parent the parent of the QObject, 0 for no parent | 341 | * @param parent the parent of the QObject, 0 for no parent |
342 | * @param name the name of the QObject, 0 for no name | 342 | * @param name the name of the QObject, 0 for no name |
343 | */ | 343 | */ |
344 | KLibFactory( QObject* parent = 0, const char* name = 0 ); | 344 | KLibFactory( QObject* parent = 0, const char* name = 0 ); |
345 | virtual ~KLibFactory(); | 345 | virtual ~KLibFactory(); |
346 | 346 | ||
347 | /** | 347 | /** |
348 | * Creates a new object. The returned object has to be derived from | 348 | * Creates a new object. The returned object has to be derived from |
349 | * the requested classname. | 349 | * the requested classname. |
350 | * | 350 | * |
351 | * It is valid behavior to create different kinds of objects | 351 | * It is valid behavior to create different kinds of objects |
352 | * depending on the requested @p classname. For example a koffice | 352 | * depending on the requested @p classname. For example a koffice |
353 | * library may usually return a pointer to KoDocument. But | 353 | * library may usually return a pointer to KoDocument. But |
354 | * if asked for a "QWidget", it could create a wrapper widget, | 354 | * if asked for a "QWidget", it could create a wrapper widget, |
355 | * that encapsulates the Koffice specific features. | 355 | * that encapsulates the Koffice specific features. |
356 | * | 356 | * |
357 | * create() automatically emits a signal @ref objectCreated to tell | 357 | * create() automatically emits a signal @ref objectCreated to tell |
358 | * the library about its newly created object. This is very | 358 | * the library about its newly created object. This is very |
359 | * important for reference counting, and allows unloading the | 359 | * important for reference counting, and allows unloading the |
360 | * library automatically once all its objects have been destroyed. | 360 | * library automatically once all its objects have been destroyed. |
361 | * | 361 | * |
362 | * @param parent the parent of the QObject, 0 for no parent | 362 | * @param parent the parent of the QObject, 0 for no parent |
363 | * @param name the name of the QObject, 0 for no name | 363 | * @param name the name of the QObject, 0 for no name |
364 | * @param classname the name of the class | 364 | * @param classname the name of the class |
365 | * @param args a list of arguments | 365 | * @param args a list of arguments |
366 | */ | 366 | */ |
367 | 367 | ||
368 | QObject* create( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() ); | 368 | QObject* create( QObject* parent = 0, const char* name = 0, const char* classname = "QObject", const QStringList &args = QStringList() ); |
369 | 369 | ||
370 | signals: | 370 | signals: |
371 | /** | 371 | /** |
372 | * Emitted in #create | 372 | * Emitted in #create |
373 | * @param obj the new object | 373 | * @param obj the new object |
374 | */ | 374 | */ |
375 | void objectCreated( QObject *obj ); | 375 | void objectCreated( QObject *obj ); |
376 | 376 | ||
377 | 377 | ||
378 | protected: | 378 | protected: |
379 | 379 | ||
380 | /** | 380 | /** |
381 | * Creates a new object. The returned object has to be derived from | 381 | * Creates a new object. The returned object has to be derived from |
382 | * the requested classname. | 382 | * the requested classname. |
383 | * | 383 | * |
384 | * It is valid behavior to create different kinds of objects | 384 | * It is valid behavior to create different kinds of objects |
385 | * depending on the requested @p classname. For example a koffice | 385 | * depending on the requested @p classname. For example a koffice |
386 | * library may usually return a pointer to KoDocument. But | 386 | * library may usually return a pointer to KoDocument. But |
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,172 +1,173 @@ | |||
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() ) { |
109 | #ifdef COLLECT_TRANSLATION | 110 | #ifdef COLLECT_TRANSLATION |
110 | addMissing( text ); | 111 | addMissing( text ); |
111 | #endif | 112 | #endif |
112 | return QString( text ); | 113 | return QString( text ); |
113 | } | 114 | } |
114 | else { | 115 | else { |
115 | #ifdef COLLECT_TRANSLATION | 116 | #ifdef COLLECT_TRANSLATION |
116 | addExist( text, *ret ); | 117 | addExist( text, *ret ); |
117 | #endif | 118 | #endif |
118 | return (*ret); | 119 | return (*ret); |
119 | } | 120 | } |
120 | } | 121 | } |
121 | } | 122 | } |
122 | 123 | ||
123 | } | 124 | } |
124 | 125 | ||
125 | QString i18n(const char *,const char *text) | 126 | QString i18n(const char *,const char *text) |
126 | { | 127 | { |
127 | return i18n( text ); | 128 | return i18n( text ); |
128 | } | 129 | } |
129 | 130 | ||
130 | QString i18n(const char *text1, const char *textn, int num) | 131 | QString i18n(const char *text1, const char *textn, int num) |
131 | { | 132 | { |
132 | if ( num == 1 ) return i18n( text1 ); | 133 | if ( num == 1 ) return i18n( text1 ); |
133 | else { | 134 | else { |
134 | QString text = i18n( textn ); | 135 | QString text = i18n( textn ); |
135 | int pos = text.find( "%n" ); | 136 | int pos = text.find( "%n" ); |
136 | if ( pos >= 0 ) text.replace( pos, 2, QString::number( num ) ); | 137 | if ( pos >= 0 ) text.replace( pos, 2, QString::number( num ) ); |
137 | return text; | 138 | return text; |
138 | } | 139 | } |
139 | } | 140 | } |
140 | 141 | ||
141 | inline void put_it_in( QChar *buffer, uint& index, const QString &s ) | 142 | inline void put_it_in( QChar *buffer, uint& index, const QString &s ) |
142 | { | 143 | { |
143 | for ( uint l = 0; l < s.length(); l++ ) | 144 | for ( uint l = 0; l < s.length(); l++ ) |
144 | buffer[index++] = s.at( l ); | 145 | buffer[index++] = s.at( l ); |
145 | } | 146 | } |
146 | 147 | ||
147 | inline void put_it_in( QChar *buffer, uint& index, int number ) | 148 | inline void put_it_in( QChar *buffer, uint& index, int number ) |
148 | { | 149 | { |
149 | buffer[index++] = number / 10 + '0'; | 150 | buffer[index++] = number / 10 + '0'; |
150 | buffer[index++] = number % 10 + '0'; | 151 | buffer[index++] = number % 10 + '0'; |
151 | } | 152 | } |
152 | 153 | ||
153 | static int readInt(const QString &str, uint &pos) | 154 | static int readInt(const QString &str, uint &pos) |
154 | { | 155 | { |
155 | if (!str.at(pos).isDigit()) return -1; | 156 | if (!str.at(pos).isDigit()) return -1; |
156 | int result = 0; | 157 | int result = 0; |
157 | for (; str.length() > pos && str.at(pos).isDigit(); pos++) | 158 | for (; str.length() > pos && str.at(pos).isDigit(); pos++) |
158 | { | 159 | { |
159 | result *= 10; | 160 | result *= 10; |
160 | result += str.at(pos).digitValue(); | 161 | result += str.at(pos).digitValue(); |
161 | } | 162 | } |
162 | 163 | ||
163 | return result; | 164 | return result; |
164 | } | 165 | } |
165 | 166 | ||
166 | KLocale::KLocale() : mCalendarSystem( 0 ) | 167 | KLocale::KLocale() : mCalendarSystem( 0 ) |
167 | { | 168 | { |
168 | 169 | ||
169 | m_decimalSymbol = "."; | 170 | m_decimalSymbol = "."; |
170 | m_positiveSign = ""; | 171 | m_positiveSign = ""; |
171 | m_negativeSign = "-"; | 172 | m_negativeSign = "-"; |
172 | m_thousandsSeparator = ","; | 173 | m_thousandsSeparator = ","; |
@@ -374,460 +375,460 @@ QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat | |||
374 | } | 375 | } |
375 | default: | 376 | default: |
376 | buffer[index++] = rst.at( format_index ); | 377 | buffer[index++] = rst.at( format_index ); |
377 | break; | 378 | break; |
378 | } | 379 | } |
379 | escape = false; | 380 | escape = false; |
380 | } | 381 | } |
381 | } | 382 | } |
382 | QString ret( buffer, index ); | 383 | QString ret( buffer, index ); |
383 | delete [] buffer; | 384 | delete [] buffer; |
384 | return ret; | 385 | return ret; |
385 | } | 386 | } |
386 | 387 | ||
387 | QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const | 388 | QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const |
388 | { | 389 | { |
389 | const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat); | 390 | const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat); |
390 | 391 | ||
391 | // I'm rather safe than sorry | 392 | // I'm rather safe than sorry |
392 | QChar *buffer = new QChar[rst.length() * 3 / 2 + 50]; | 393 | QChar *buffer = new QChar[rst.length() * 3 / 2 + 50]; |
393 | 394 | ||
394 | unsigned int index = 0; | 395 | unsigned int index = 0; |
395 | bool escape = false; | 396 | bool escape = false; |
396 | int number = 0; | 397 | int number = 0; |
397 | 398 | ||
398 | for ( uint format_index = 0; format_index < rst.length(); ++format_index ) | 399 | for ( uint format_index = 0; format_index < rst.length(); ++format_index ) |
399 | { | 400 | { |
400 | if ( !escape ) | 401 | if ( !escape ) |
401 | { | 402 | { |
402 | if ( rst.at( format_index ).unicode() == '%' ) | 403 | if ( rst.at( format_index ).unicode() == '%' ) |
403 | escape = true; | 404 | escape = true; |
404 | else | 405 | else |
405 | buffer[index++] = rst.at( format_index ); | 406 | buffer[index++] = rst.at( format_index ); |
406 | } | 407 | } |
407 | else | 408 | else |
408 | { | 409 | { |
409 | switch ( rst.at( format_index ).unicode() ) | 410 | switch ( rst.at( format_index ).unicode() ) |
410 | { | 411 | { |
411 | case '%': | 412 | case '%': |
412 | buffer[index++] = '%'; | 413 | buffer[index++] = '%'; |
413 | break; | 414 | break; |
414 | case 'Y': | 415 | case 'Y': |
415 | put_it_in( buffer, index, pDate.year() / 100 ); | 416 | put_it_in( buffer, index, pDate.year() / 100 ); |
416 | case 'y': | 417 | case 'y': |
417 | put_it_in( buffer, index, pDate.year() % 100 ); | 418 | put_it_in( buffer, index, pDate.year() % 100 ); |
418 | break; | 419 | break; |
419 | case 'n': | 420 | case 'n': |
420 | number = pDate.month(); | 421 | number = pDate.month(); |
421 | case 'e': | 422 | case 'e': |
422 | // to share the code | 423 | // to share the code |
423 | if ( rst.at( format_index ).unicode() == 'e' ) | 424 | if ( rst.at( format_index ).unicode() == 'e' ) |
424 | number = pDate.day(); | 425 | number = pDate.day(); |
425 | if ( number / 10 ) | 426 | if ( number / 10 ) |
426 | buffer[index++] = number / 10 + '0'; | 427 | buffer[index++] = number / 10 + '0'; |
427 | buffer[index++] = number % 10 + '0'; | 428 | buffer[index++] = number % 10 + '0'; |
428 | break; | 429 | break; |
429 | case 'm': | 430 | case 'm': |
430 | put_it_in( buffer, index, pDate.month() ); | 431 | put_it_in( buffer, index, pDate.month() ); |
431 | break; | 432 | break; |
432 | case 'b': | 433 | case 'b': |
433 | put_it_in( buffer, index, monthName(pDate.month(), true) ); | 434 | put_it_in( buffer, index, monthName(pDate.month(), true) ); |
434 | break; | 435 | break; |
435 | case 'B': | 436 | case 'B': |
436 | put_it_in( buffer, index, monthName(pDate.month(), false) ); | 437 | put_it_in( buffer, index, monthName(pDate.month(), false) ); |
437 | break; | 438 | break; |
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 | ||
563 | break; | 564 | break; |
564 | 565 | ||
565 | case 'n': | 566 | case 'n': |
566 | case 'm': | 567 | case 'm': |
567 | month = readInt(str, strpos); | 568 | month = readInt(str, strpos); |
568 | if (month < 1 || month > 12) | 569 | if (month < 1 || month > 12) |
569 | goto error; | 570 | goto error; |
570 | 571 | ||
571 | break; | 572 | break; |
572 | 573 | ||
573 | case 'Y': | 574 | case 'Y': |
574 | case 'y': | 575 | case 'y': |
575 | year = readInt(str, strpos); | 576 | year = readInt(str, strpos); |
576 | if (year < 0) | 577 | if (year < 0) |
577 | goto error; | 578 | goto error; |
578 | // Qt treats a year in the range 0-100 as 1900-1999. | 579 | // Qt treats a year in the range 0-100 as 1900-1999. |
579 | // It is nicer for the user if we treat 0-68 as 2000-2068 | 580 | // It is nicer for the user if we treat 0-68 as 2000-2068 |
580 | if (year < 69) | 581 | if (year < 69) |
581 | year += 2000; | 582 | year += 2000; |
582 | else if (c == 'y') | 583 | else if (c == 'y') |
583 | year += 1900; | 584 | year += 1900; |
584 | 585 | ||
585 | break; | 586 | break; |
586 | } | 587 | } |
587 | } | 588 | } |
588 | //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl; | 589 | //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl; |
589 | if ( year != -1 && month != -1 && day != -1 ) | 590 | if ( year != -1 && month != -1 && day != -1 ) |
590 | { | 591 | { |
591 | if (ok) *ok = true; | 592 | if (ok) *ok = true; |
592 | return QDate(year, month, day); | 593 | return QDate(year, month, day); |
593 | } | 594 | } |
594 | error: | 595 | error: |
595 | if (ok) *ok = false; | 596 | if (ok) *ok = false; |
596 | return QDate(); // invalid date | 597 | return QDate(); // invalid date |
597 | } | 598 | } |
598 | 599 | ||
599 | QTime KLocale::readTime(const QString &intstr, bool *ok) const | 600 | QTime KLocale::readTime(const QString &intstr, bool *ok) const |
600 | { | 601 | { |
601 | QTime _time; | 602 | QTime _time; |
602 | _time = readTime(intstr, false, ok); | 603 | _time = readTime(intstr, false, ok); |
603 | if (_time.isValid()) return _time; | 604 | if (_time.isValid()) return _time; |
604 | return readTime(intstr, true, ok); | 605 | return readTime(intstr, true, ok); |
605 | } | 606 | } |
606 | 607 | ||
607 | QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const | 608 | QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const |
608 | { | 609 | { |
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 | ||
674 | break; | 675 | break; |
675 | 676 | ||
676 | case 'l': | 677 | case 'l': |
677 | case 'I': | 678 | case 'I': |
678 | g_12h = true; | 679 | g_12h = true; |
679 | hour = readInt(str, strpos); | 680 | hour = readInt(str, strpos); |
680 | if (hour < 1 || hour > 12) | 681 | if (hour < 1 || hour > 12) |
681 | goto error; | 682 | goto error; |
682 | 683 | ||
683 | break; | 684 | break; |
684 | 685 | ||
685 | case 'M': | 686 | case 'M': |
686 | minute = readInt(str, strpos); | 687 | minute = readInt(str, strpos); |
687 | if (minute < 0 || minute > 59) | 688 | if (minute < 0 || minute > 59) |
688 | goto error; | 689 | goto error; |
689 | 690 | ||
690 | break; | 691 | break; |
691 | 692 | ||
692 | case 'S': | 693 | case 'S': |
693 | second = readInt(str, strpos); | 694 | second = readInt(str, strpos); |
694 | if (second < 0 || second > 59) | 695 | if (second < 0 || second > 59) |
695 | goto error; | 696 | goto error; |
696 | 697 | ||
697 | break; | 698 | break; |
698 | } | 699 | } |
699 | } | 700 | } |
700 | if (g_12h) | 701 | if (g_12h) |
701 | { | 702 | { |
702 | hour %= 12; | 703 | hour %= 12; |
703 | if (pm) hour += 12; | 704 | if (pm) hour += 12; |
704 | } | 705 | } |
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 | ||
770 | if (ok) | 771 | if (ok) |
771 | *ok = ok1; | 772 | *ok = ok1; |
772 | 773 | ||
773 | //qDebug("KLocale::readDate() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2); | 774 | //qDebug("KLocale::readDate() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2); |
774 | return m_date; | 775 | return m_date; |
775 | } | 776 | } |
776 | 777 | ||
777 | 778 | ||
778 | bool KLocale::use12Clock() const | 779 | bool KLocale::use12Clock() const |
779 | { | 780 | { |
780 | return !mHourF24Format ;; | 781 | return !mHourF24Format ;; |
781 | } | 782 | } |
782 | 783 | ||
783 | bool KLocale::weekStartsMonday() const | 784 | bool KLocale::weekStartsMonday() const |
784 | { | 785 | { |
785 | return mWeekStartsMonday; | 786 | return mWeekStartsMonday; |
786 | } | 787 | } |
787 | 788 | ||
788 | int KLocale::weekStartDay() const | 789 | int KLocale::weekStartDay() const |
789 | { | 790 | { |
790 | if ( mWeekStartsMonday ) | 791 | if ( mWeekStartsMonday ) |
791 | return 1; | 792 | return 1; |
792 | return 7; | 793 | return 7; |
793 | } | 794 | } |
794 | 795 | ||
795 | QString KLocale::weekDayName(int i,bool shortName) const | 796 | QString KLocale::weekDayName(int i,bool shortName) const |
796 | { | 797 | { |
797 | if ( shortName ) | 798 | if ( shortName ) |
798 | switch ( i ) | 799 | switch ( i ) |
799 | { | 800 | { |
800 | case 1: return i18n("Monday", "Mon"); | 801 | case 1: return i18n("Monday", "Mon"); |
801 | case 2: return i18n("Tuesday", "Tue"); | 802 | case 2: return i18n("Tuesday", "Tue"); |
802 | case 3: return i18n("Wednesday", "Wed"); | 803 | case 3: return i18n("Wednesday", "Wed"); |
803 | case 4: return i18n("Thursday", "Thu"); | 804 | case 4: return i18n("Thursday", "Thu"); |
804 | case 5: return i18n("Friday", "Fri"); | 805 | case 5: return i18n("Friday", "Fri"); |
805 | case 6: return i18n("Saturday", "Sat"); | 806 | case 6: return i18n("Saturday", "Sat"); |
806 | case 7: return i18n("Sunday", "Sun"); | 807 | case 7: return i18n("Sunday", "Sun"); |
807 | } | 808 | } |
808 | else | 809 | else |
809 | switch ( i ) | 810 | switch ( i ) |
810 | { | 811 | { |
811 | case 1: return i18n("Monday"); | 812 | case 1: return i18n("Monday"); |
812 | case 2: return i18n("Tuesday"); | 813 | case 2: return i18n("Tuesday"); |
813 | case 3: return i18n("Wednesday"); | 814 | case 3: return i18n("Wednesday"); |
814 | case 4: return i18n("Thursday"); | 815 | case 4: return i18n("Thursday"); |
815 | case 5: return i18n("Friday"); | 816 | case 5: return i18n("Friday"); |
816 | case 6: return i18n("Saturday"); | 817 | case 6: return i18n("Saturday"); |
817 | case 7: return i18n("Sunday"); | 818 | case 7: return i18n("Sunday"); |
818 | } | 819 | } |
819 | 820 | ||
820 | return QString::null; | 821 | return QString::null; |
821 | } | 822 | } |
822 | 823 | ||
823 | QString KLocale::monthName(int i,bool shortName) const | 824 | QString KLocale::monthName(int i,bool shortName) const |
824 | { | 825 | { |
825 | if ( shortName ) | 826 | if ( shortName ) |
826 | switch ( i ) | 827 | switch ( i ) |
827 | { | 828 | { |
828 | case 1: return i18n("January", "Jan"); | 829 | case 1: return i18n("January", "Jan"); |
829 | case 2: return i18n("February", "Feb"); | 830 | case 2: return i18n("February", "Feb"); |
830 | case 3: return i18n("March", "Mar"); | 831 | case 3: return i18n("March", "Mar"); |
831 | case 4: return i18n("April", "Apr"); | 832 | case 4: return i18n("April", "Apr"); |
832 | case 5: return i18n("May short", "May"); | 833 | case 5: return i18n("May short", "May"); |
833 | case 6: return i18n("June", "Jun"); | 834 | case 6: return i18n("June", "Jun"); |
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,110 +1,110 @@ | |||
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; |
47 | QString formatTime(const QTime &pTime, bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const; | 47 | QString formatTime(const QTime &pTime, bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const; |
48 | QString formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat = Undefined) const; | 48 | QString formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat = Undefined) const; |
49 | QString formatDateTime(const QDateTime &pDateTime, | 49 | QString formatDateTime(const QDateTime &pDateTime, |
50 | bool shortFormat, | 50 | bool shortFormat, |
51 | bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const; | 51 | bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const; |
52 | 52 | ||
53 | QDate readDate(const QString &str, bool* ok = 0) const; | 53 | QDate readDate(const QString &str, bool* ok = 0) const; |
54 | QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const; | 54 | QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const; |
55 | QTime readTime(const QString &str, bool* ok = 0) const; | 55 | QTime readTime(const QString &str, bool* ok = 0) const; |
56 | QDate readDate(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const; | 56 | QDate readDate(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const; |
57 | 57 | ||
58 | QDateTime readDateTime(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const; | 58 | QDateTime readDateTime(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const; |
59 | 59 | ||
60 | bool use12Clock() const; | 60 | bool use12Clock() const; |
61 | bool weekStartsMonday() const; | 61 | bool weekStartsMonday() const; |
62 | int weekStartDay() const; | 62 | int weekStartDay() const; |
63 | 63 | ||
64 | QString weekDayName(int,bool=false) const; | 64 | QString weekDayName(int,bool=false) const; |
65 | QString monthName(int,bool=false) const; | 65 | QString monthName(int,bool=false) const; |
66 | 66 | ||
67 | QString country() const; | 67 | QString country() const; |
68 | int weekNum ( const QDate & ); | 68 | int weekNum ( const QDate & ); |
69 | QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; | 69 | QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; |
70 | QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; | 70 | QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; |
71 | QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const; | 71 | QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const; |
72 | 72 | ||
73 | void insertCatalogue ( const QString & ); | 73 | void insertCatalogue ( const QString & ); |
74 | 74 | ||
75 | KCalendarSystem *calendar(); | 75 | KCalendarSystem *calendar(); |
76 | void setHore24Format ( bool ); | 76 | void setHore24Format ( bool ); |
77 | void setWeekStartMonday( bool ); | 77 | void setWeekStartMonday( bool ); |
78 | void setIntDateFormat( IntDateFormat ); | 78 | void setIntDateFormat( IntDateFormat ); |
79 | void setIntTimeFormat( IntDateFormat ); | 79 | void setIntTimeFormat( IntDateFormat ); |
80 | IntDateFormat getIntDateFormat( ); | 80 | IntDateFormat getIntDateFormat( ); |
81 | IntDateFormat getIntTimeFormat( ); | 81 | IntDateFormat getIntTimeFormat( ); |
82 | void setLanguage( int ); | 82 | void setLanguage( int ); |
83 | int language(); | 83 | int language(); |
84 | void setDateFormat( QString ); | 84 | void setDateFormat( QString ); |
85 | void setDateFormatShort( QString ); | 85 | void setDateFormatShort( QString ); |
86 | 86 | ||
87 | QString m_decimalSymbol; | 87 | QString m_decimalSymbol; |
88 | QString m_thousandsSeparator; | 88 | QString m_thousandsSeparator; |
89 | QString m_currencySymbol; | 89 | QString m_currencySymbol; |
90 | QString m_monetaryDecimalSymbol; | 90 | QString m_monetaryDecimalSymbol; |
91 | QString m_monetaryThousandsSeparator; | 91 | QString m_monetaryThousandsSeparator; |
92 | QString m_positiveSign; | 92 | QString m_positiveSign; |
93 | QString m_negativeSign; | 93 | QString m_negativeSign; |
94 | 94 | ||
95 | int timezoneOffset( QString ); | 95 | int timezoneOffset( QString ); |
96 | QStringList timeZoneList() const; | 96 | QStringList timeZoneList() const; |
97 | void setDaylightSaving( bool, int , int ); | 97 | void setDaylightSaving( bool, int , int ); |
98 | int localTimeOffset(const QDateTime &); | 98 | int localTimeOffset(const QDateTime &); |
99 | void setTimezone( const QString &timeZone , bool oddTZ); | 99 | void setTimezone( const QString &timeZone , bool oddTZ); |
100 | private: | 100 | private: |
101 | QTime readTime(const QString &str, bool seconds, bool *ok) const; | 101 | QTime readTime(const QString &str, bool seconds, bool *ok) const; |
102 | QDate readDate(const QString &str, bool shortFormat, bool *ok) const; | 102 | QDate readDate(const QString &str, bool shortFormat, bool *ok) const; |
103 | KCalendarSystem *mCalendarSystem; | 103 | KCalendarSystem *mCalendarSystem; |
104 | bool mWeekStartsMonday; | 104 | bool mWeekStartsMonday; |
105 | bool mHourF24Format; | 105 | bool mHourF24Format; |
106 | IntDateFormat mIntDateFormat; | 106 | IntDateFormat mIntDateFormat; |
107 | IntDateFormat mIntTimeFormat; | 107 | IntDateFormat mIntTimeFormat; |
108 | int mLanguage; | 108 | int mLanguage; |
109 | QString mDateFormat; | 109 | QString mDateFormat; |
110 | QString mDateFormatShort; | 110 | QString mDateFormatShort; |
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 | |||
@@ -1,1055 +1,1054 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org> | 2 | Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org> |
3 | Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org> | 3 | Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU Lesser General Public License (LGPL) | 6 | it under the terms of the GNU Lesser General Public License (LGPL) |
7 | version 2 as published by the Free Software Foundation. | 7 | version 2 as published by the Free Software Foundation. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, | 9 | This program 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 | 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 | { |
74 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 76 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
75 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 77 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
76 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 78 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
77 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 79 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
78 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 80 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
79 | 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, | 81 | 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F, |
80 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, | 82 | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, |
81 | 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 83 | 0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
82 | 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, | 84 | 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, |
83 | 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, | 85 | 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, |
84 | 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, | 86 | 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, |
85 | 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, | 87 | 0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, |
86 | 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, | 88 | 0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, |
87 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, | 89 | 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
88 | 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, | 90 | 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, |
89 | 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 | 91 | 0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00 |
90 | }; | 92 | }; |
91 | 93 | ||
92 | const char KCodecs::UUEncMap[64] = | 94 | const char KCodecs::UUEncMap[64] = |
93 | { | 95 | { |
94 | 0x60, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | 96 | 0x60, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, |
95 | 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, | 97 | 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, |
96 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, | 98 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, |
97 | 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, | 99 | 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, |
98 | 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, | 100 | 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, |
99 | 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, | 101 | 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, |
100 | 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, | 102 | 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, |
101 | 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F | 103 | 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F |
102 | }; | 104 | }; |
103 | 105 | ||
104 | const char KCodecs::UUDecMap[128] = | 106 | const char KCodecs::UUDecMap[128] = |
105 | { | 107 | { |
106 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 108 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
107 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 109 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
108 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 110 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
109 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 111 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
110 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | 112 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
111 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | 113 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, |
112 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | 114 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
113 | 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, | 115 | 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, |
114 | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, | 116 | 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, |
115 | 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, | 117 | 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, |
116 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, | 118 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, |
117 | 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, | 119 | 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, |
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; |
190 | pos = 0; | 192 | pos = 0; |
191 | 193 | ||
192 | for (unsigned int i = 0; i < length; i++) | 194 | for (unsigned int i = 0; i < length; i++) |
193 | { | 195 | { |
194 | unsigned char c (data[i]); | 196 | unsigned char c (data[i]); |
195 | 197 | ||
196 | // check if we have to enlarge the output buffer, use | 198 | // check if we have to enlarge the output buffer, use |
197 | // a safety margin of 16 byte | 199 | // a safety margin of 16 byte |
198 | pos = cursor-out.data(); | 200 | pos = cursor-out.data(); |
199 | if (out.size()-pos < 16) { | 201 | if (out.size()-pos < 16) { |
200 | out.resize(out.size()+4096); | 202 | out.resize(out.size()+4096); |
201 | cursor = out.data()+pos; | 203 | cursor = out.data()+pos; |
202 | } | 204 | } |
203 | 205 | ||
204 | // Plain ASCII chars just go straight out. | 206 | // Plain ASCII chars just go straight out. |
205 | 207 | ||
206 | if ((c >= 33) && (c <= 126) && ('=' != c)) | 208 | if ((c >= 33) && (c <= 126) && ('=' != c)) |
207 | { | 209 | { |
208 | *cursor++ = c; | 210 | *cursor++ = c; |
209 | ++lineLength; | 211 | ++lineLength; |
210 | } | 212 | } |
211 | 213 | ||
212 | // Spaces need some thought. We have to encode them at eol (or eof). | 214 | // Spaces need some thought. We have to encode them at eol (or eof). |
213 | 215 | ||
214 | else if (' ' == c) | 216 | else if (' ' == c) |
215 | { | 217 | { |
216 | if | 218 | if |
217 | ( | 219 | ( |
218 | (i >= length) | 220 | (i >= length) |
219 | || | 221 | || |
220 | ((i < end) && ((useCRLF && ('\r' == data[i + 1]) && ('\n' == data[i + 2])) | 222 | ((i < end) && ((useCRLF && ('\r' == data[i + 1]) && ('\n' == data[i + 2])) |
221 | || | 223 | || |
222 | (!useCRLF && ('\n' == data[i + 1])))) | 224 | (!useCRLF && ('\n' == data[i + 1])))) |
223 | ) | 225 | ) |
224 | { | 226 | { |
225 | *cursor++ = '='; | 227 | *cursor++ = '='; |
226 | *cursor++ = '2'; | 228 | *cursor++ = '2'; |
227 | *cursor++ = '0'; | 229 | *cursor++ = '0'; |
228 | 230 | ||
229 | lineLength += 3; | 231 | lineLength += 3; |
230 | } | 232 | } |
231 | else | 233 | else |
232 | { | 234 | { |
233 | *cursor++ = ' '; | 235 | *cursor++ = ' '; |
234 | ++lineLength; | 236 | ++lineLength; |
235 | } | 237 | } |
236 | } | 238 | } |
237 | // If we find a line break, just let it through. | 239 | // If we find a line break, just let it through. |
238 | else if ((useCRLF && ('\r' == c) && (i < end) && ('\n' == data[i + 1])) || | 240 | else if ((useCRLF && ('\r' == c) && (i < end) && ('\n' == data[i + 1])) || |
239 | (!useCRLF && ('\n' == c))) | 241 | (!useCRLF && ('\n' == c))) |
240 | { | 242 | { |
241 | lineLength = 0; | 243 | lineLength = 0; |
242 | 244 | ||
243 | if (useCRLF) { | 245 | if (useCRLF) { |
244 | *cursor++ = '\r'; | 246 | *cursor++ = '\r'; |
245 | *cursor++ = '\n'; | 247 | *cursor++ = '\n'; |
246 | ++i; | 248 | ++i; |
247 | } else { | 249 | } else { |
248 | *cursor++ = '\n'; | 250 | *cursor++ = '\n'; |
249 | } | 251 | } |
250 | } | 252 | } |
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 | { |
323 | char c1 = in.at(i + 1); | 325 | char c1 = in.at(i + 1); |
324 | char c2 = in.at(i + 2); | 326 | char c2 = in.at(i + 2); |
325 | 327 | ||
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 | { |
808 | memcpy (m_buffer + buffer_index, in, buffer_space); | 807 | memcpy (m_buffer + buffer_index, in, buffer_space); |
809 | transform (m_buffer); | 808 | transform (m_buffer); |
810 | 809 | ||
811 | for (in_index = buffer_space; in_index + 63 < in_length; | 810 | for (in_index = buffer_space; in_index + 63 < in_length; |
812 | in_index += 64) | 811 | in_index += 64) |
813 | transform (reinterpret_cast<const unsigned char*>(in+in_index)); | 812 | transform (reinterpret_cast<const unsigned char*>(in+in_index)); |
814 | 813 | ||
815 | buffer_index = 0; | 814 | buffer_index = 0; |
816 | } | 815 | } |
817 | else | 816 | else |
818 | in_index=0; | 817 | in_index=0; |
819 | 818 | ||
820 | memcpy(m_buffer+buffer_index, in+in_index, in_length-in_index); | 819 | memcpy(m_buffer+buffer_index, in+in_index, in_length-in_index); |
821 | } | 820 | } |
822 | 821 | ||
823 | bool KMD5::update(QIODevice& file) | 822 | bool KMD5::update(QIODevice& file) |
824 | { | 823 | { |
825 | char buffer[1024]; | 824 | char buffer[1024]; |
826 | int len; | 825 | int len; |
827 | 826 | ||
828 | while ((len=file.readBlock(reinterpret_cast<char*>(buffer), sizeof(buffer))) > 0) | 827 | while ((len=file.readBlock(reinterpret_cast<char*>(buffer), sizeof(buffer))) > 0) |
829 | update(buffer, len); | 828 | update(buffer, len); |
830 | 829 | ||
831 | return file.atEnd(); | 830 | return file.atEnd(); |
832 | } | 831 | } |
833 | 832 | ||
834 | void KMD5::finalize () | 833 | void KMD5::finalize () |
835 | { | 834 | { |
836 | if (m_finalized) return; | 835 | if (m_finalized) return; |
837 | 836 | ||
838 | Q_UINT8 bits[8]; | 837 | Q_UINT8 bits[8]; |
839 | Q_UINT32 index, padLen; | 838 | Q_UINT32 index, padLen; |
840 | static unsigned char PADDING[64]= | 839 | static unsigned char PADDING[64]= |
841 | { | 840 | { |
842 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 841 | 0x80, 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, | 842 | 0, 0, 0, 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, 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 */ |
992 | GG (a, b, c, d, x[13], KMD5_S21, 0xa9e3e905); /* 29 */ | 991 | GG (a, b, c, d, x[13], KMD5_S21, 0xa9e3e905); /* 29 */ |
993 | GG (d, a, b, c, x[ 2], KMD5_S22, 0xfcefa3f8); /* 30 */ | 992 | GG (d, a, b, c, x[ 2], KMD5_S22, 0xfcefa3f8); /* 30 */ |
994 | GG (c, d, a, b, x[ 7], KMD5_S23, 0x676f02d9); /* 31 */ | 993 | GG (c, d, a, b, x[ 7], KMD5_S23, 0x676f02d9); /* 31 */ |
995 | GG (b, c, d, a, x[12], KMD5_S24, 0x8d2a4c8a); /* 32 */ | 994 | GG (b, c, d, a, x[12], KMD5_S24, 0x8d2a4c8a); /* 32 */ |
996 | 995 | ||
997 | /* Round 3 */ | 996 | /* Round 3 */ |
998 | HH (a, b, c, d, x[ 5], KMD5_S31, 0xfffa3942); /* 33 */ | 997 | HH (a, b, c, d, x[ 5], KMD5_S31, 0xfffa3942); /* 33 */ |
999 | HH (d, a, b, c, x[ 8], KMD5_S32, 0x8771f681); /* 34 */ | 998 | HH (d, a, b, c, x[ 8], KMD5_S32, 0x8771f681); /* 34 */ |
1000 | HH (c, d, a, b, x[11], KMD5_S33, 0x6d9d6122); /* 35 */ | 999 | HH (c, d, a, b, x[11], KMD5_S33, 0x6d9d6122); /* 35 */ |
1001 | HH (b, c, d, a, x[14], KMD5_S34, 0xfde5380c); /* 36 */ | 1000 | HH (b, c, d, a, x[14], KMD5_S34, 0xfde5380c); /* 36 */ |
1002 | HH (a, b, c, d, x[ 1], KMD5_S31, 0xa4beea44); /* 37 */ | 1001 | HH (a, b, c, d, x[ 1], KMD5_S31, 0xa4beea44); /* 37 */ |
1003 | HH (d, a, b, c, x[ 4], KMD5_S32, 0x4bdecfa9); /* 38 */ | 1002 | HH (d, a, b, c, x[ 4], KMD5_S32, 0x4bdecfa9); /* 38 */ |
1004 | HH (c, d, a, b, x[ 7], KMD5_S33, 0xf6bb4b60); /* 39 */ | 1003 | HH (c, d, a, b, x[ 7], KMD5_S33, 0xf6bb4b60); /* 39 */ |
1005 | HH (b, c, d, a, x[10], KMD5_S34, 0xbebfbc70); /* 40 */ | 1004 | HH (b, c, d, a, x[10], KMD5_S34, 0xbebfbc70); /* 40 */ |
1006 | HH (a, b, c, d, x[13], KMD5_S31, 0x289b7ec6); /* 41 */ | 1005 | HH (a, b, c, d, x[13], KMD5_S31, 0x289b7ec6); /* 41 */ |
1007 | HH (d, a, b, c, x[ 0], KMD5_S32, 0xeaa127fa); /* 42 */ | 1006 | HH (d, a, b, c, x[ 0], KMD5_S32, 0xeaa127fa); /* 42 */ |
1008 | HH (c, d, a, b, x[ 3], KMD5_S33, 0xd4ef3085); /* 43 */ | 1007 | HH (c, d, a, b, x[ 3], KMD5_S33, 0xd4ef3085); /* 43 */ |
1009 | HH (b, c, d, a, x[ 6], KMD5_S34, 0x4881d05); /* 44 */ | 1008 | HH (b, c, d, a, x[ 6], KMD5_S34, 0x4881d05); /* 44 */ |
1010 | HH (a, b, c, d, x[ 9], KMD5_S31, 0xd9d4d039); /* 45 */ | 1009 | HH (a, b, c, d, x[ 9], KMD5_S31, 0xd9d4d039); /* 45 */ |
1011 | HH (d, a, b, c, x[12], KMD5_S32, 0xe6db99e5); /* 46 */ | 1010 | HH (d, a, b, c, x[12], KMD5_S32, 0xe6db99e5); /* 46 */ |
1012 | HH (c, d, a, b, x[15], KMD5_S33, 0x1fa27cf8); /* 47 */ | 1011 | HH (c, d, a, b, x[15], KMD5_S33, 0x1fa27cf8); /* 47 */ |
1013 | HH (b, c, d, a, x[ 2], KMD5_S34, 0xc4ac5665); /* 48 */ | 1012 | HH (b, c, d, a, x[ 2], KMD5_S34, 0xc4ac5665); /* 48 */ |
1014 | 1013 | ||
1015 | /* Round 4 */ | 1014 | /* Round 4 */ |
1016 | II (a, b, c, d, x[ 0], KMD5_S41, 0xf4292244); /* 49 */ | 1015 | II (a, b, c, d, x[ 0], KMD5_S41, 0xf4292244); /* 49 */ |
1017 | II (d, a, b, c, x[ 7], KMD5_S42, 0x432aff97); /* 50 */ | 1016 | II (d, a, b, c, x[ 7], KMD5_S42, 0x432aff97); /* 50 */ |
1018 | II (c, d, a, b, x[14], KMD5_S43, 0xab9423a7); /* 51 */ | 1017 | II (c, d, a, b, x[14], KMD5_S43, 0xab9423a7); /* 51 */ |
1019 | II (b, c, d, a, x[ 5], KMD5_S44, 0xfc93a039); /* 52 */ | 1018 | II (b, c, d, a, x[ 5], KMD5_S44, 0xfc93a039); /* 52 */ |
1020 | II (a, b, c, d, x[12], KMD5_S41, 0x655b59c3); /* 53 */ | 1019 | II (a, b, c, d, x[12], KMD5_S41, 0x655b59c3); /* 53 */ |
1021 | II (d, a, b, c, x[ 3], KMD5_S42, 0x8f0ccc92); /* 54 */ | 1020 | II (d, a, b, c, x[ 3], KMD5_S42, 0x8f0ccc92); /* 54 */ |
1022 | II (c, d, a, b, x[10], KMD5_S43, 0xffeff47d); /* 55 */ | 1021 | II (c, d, a, b, x[10], KMD5_S43, 0xffeff47d); /* 55 */ |
1023 | II (b, c, d, a, x[ 1], KMD5_S44, 0x85845dd1); /* 56 */ | 1022 | II (b, c, d, a, x[ 1], KMD5_S44, 0x85845dd1); /* 56 */ |
1024 | II (a, b, c, d, x[ 8], KMD5_S41, 0x6fa87e4f); /* 57 */ | 1023 | II (a, b, c, d, x[ 8], KMD5_S41, 0x6fa87e4f); /* 57 */ |
1025 | II (d, a, b, c, x[15], KMD5_S42, 0xfe2ce6e0); /* 58 */ | 1024 | II (d, a, b, c, x[15], KMD5_S42, 0xfe2ce6e0); /* 58 */ |
1026 | II (c, d, a, b, x[ 6], KMD5_S43, 0xa3014314); /* 59 */ | 1025 | II (c, d, a, b, x[ 6], KMD5_S43, 0xa3014314); /* 59 */ |
1027 | II (b, c, d, a, x[13], KMD5_S44, 0x4e0811a1); /* 60 */ | 1026 | II (b, c, d, a, x[13], KMD5_S44, 0x4e0811a1); /* 60 */ |
1028 | II (a, b, c, d, x[ 4], KMD5_S41, 0xf7537e82); /* 61 */ | 1027 | II (a, b, c, d, x[ 4], KMD5_S41, 0xf7537e82); /* 61 */ |
1029 | II (d, a, b, c, x[11], KMD5_S42, 0xbd3af235); /* 62 */ | 1028 | II (d, a, b, c, x[11], KMD5_S42, 0xbd3af235); /* 62 */ |
1030 | II (c, d, a, b, x[ 2], KMD5_S43, 0x2ad7d2bb); /* 63 */ | 1029 | II (c, d, a, b, x[ 2], KMD5_S43, 0x2ad7d2bb); /* 63 */ |
1031 | II (b, c, d, a, x[ 9], KMD5_S44, 0xeb86d391); /* 64 */ | 1030 | II (b, c, d, a, x[ 9], KMD5_S44, 0xeb86d391); /* 64 */ |
1032 | 1031 | ||
1033 | m_state[0] += a; | 1032 | m_state[0] += a; |
1034 | m_state[1] += b; | 1033 | m_state[1] += b; |
1035 | m_state[2] += c; | 1034 | m_state[2] += c; |
1036 | m_state[3] += d; | 1035 | m_state[3] += d; |
1037 | 1036 | ||
1038 | memset ( static_cast<void *>(x), 0, sizeof(x) ); | 1037 | memset ( static_cast<void *>(x), 0, sizeof(x) ); |
1039 | } | 1038 | } |
1040 | 1039 | ||
1041 | inline Q_UINT32 KMD5::rotate_left (Q_UINT32 x, Q_UINT32 n) | 1040 | inline Q_UINT32 KMD5::rotate_left (Q_UINT32 x, Q_UINT32 n) |
1042 | { | 1041 | { |
1043 | return (x << n) | (x >> (32-n)) ; | 1042 | return (x << n) | (x >> (32-n)) ; |
1044 | } | 1043 | } |
1045 | 1044 | ||
1046 | inline Q_UINT32 KMD5::F (Q_UINT32 x, Q_UINT32 y, Q_UINT32 z) | 1045 | inline Q_UINT32 KMD5::F (Q_UINT32 x, Q_UINT32 y, Q_UINT32 z) |
1047 | { | 1046 | { |
1048 | return (x & y) | (~x & z); | 1047 | return (x & y) | (~x & z); |
1049 | } | 1048 | } |
1050 | 1049 | ||
1051 | inline Q_UINT32 KMD5::G (Q_UINT32 x, Q_UINT32 y, Q_UINT32 z) | 1050 | inline Q_UINT32 KMD5::G (Q_UINT32 x, Q_UINT32 y, Q_UINT32 z) |
1052 | { | 1051 | { |
1053 | return (x & z) | (y & ~z); | 1052 | return (x & z) | (y & ~z); |
1054 | } | 1053 | } |
1055 | 1054 | ||
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 | |||
@@ -1,572 +1,574 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org> | 2 | Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org> |
3 | Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org> | 3 | Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU Lesser General Public License (LGPL) | 6 | it under the terms of the GNU Lesser General Public License (LGPL) |
7 | version 2 as published by the Free Software Foundation. | 7 | version 2 as published by the Free Software Foundation. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, | 9 | This program 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 | 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 | }; |
355 | 357 | ||
356 | class KMD5Private; | 358 | class KMD5Private; |
357 | /** | 359 | /** |
358 | * Provides an easy to use C++ implementation of RSA's | 360 | * Provides an easy to use C++ implementation of RSA's |
359 | * MD5 algorithm. | 361 | * MD5 algorithm. |
360 | * | 362 | * |
361 | * The default constructor is designed to provide much the same | 363 | * The default constructor is designed to provide much the same |
362 | * functionality as the most commonly used C-implementation, while | 364 | * functionality as the most commonly used C-implementation, while |
363 | * the other three constructors are meant to further simplify the | 365 | * the other three constructors are meant to further simplify the |
364 | * process of obtaining a digest by calculating the result in a | 366 | * process of obtaining a digest by calculating the result in a |
365 | * single step. | 367 | * single step. |
366 | * | 368 | * |
367 | * KMD5 is state-based, that means you can add new contents with | 369 | * KMD5 is state-based, that means you can add new contents with |
368 | * update() as long as you didn't request the digest value yet. | 370 | * update() as long as you didn't request the digest value yet. |
369 | * After the digest value was requested, the object is "finalized" | 371 | * After the digest value was requested, the object is "finalized" |
370 | * and you have to call reset() to be able to do another calculation | 372 | * and you have to call reset() to be able to do another calculation |
371 | * with it. The reason for this behaviour is that upon requesting | 373 | * with it. The reason for this behaviour is that upon requesting |
372 | * the message digest KMD5 has to pad the received contents up to a | 374 | * the message digest KMD5 has to pad the received contents up to a |
373 | * 64 byte boundary to calculate its value. After this operation it | 375 | * 64 byte boundary to calculate its value. After this operation it |
374 | * is not possible to resume consuming data. | 376 | * is not possible to resume consuming data. |
375 | * | 377 | * |
376 | * @sect Usage: | 378 | * @sect Usage: |
377 | * | 379 | * |
378 | * A common usage of this class: | 380 | * A common usage of this class: |
379 | * | 381 | * |
380 | * <PRE> | 382 | * <PRE> |
381 | * const char* test1; | 383 | * const char* test1; |
382 | * KMD5::Digest rawResult; | 384 | * KMD5::Digest rawResult; |
383 | * | 385 | * |
384 | * test1 = "This is a simple test."; | 386 | * test1 = "This is a simple test."; |
385 | * KMD5 context (test1); | 387 | * KMD5 context (test1); |
386 | * cout << "Hex Digest output: " << context.hexDigest().data() << endl; | 388 | * cout << "Hex Digest output: " << context.hexDigest().data() << endl; |
387 | * </PRE> | 389 | * </PRE> |
388 | * | 390 | * |
389 | * To cut down on the unnecessary overhead of creating multiple KMD5 | 391 | * To cut down on the unnecessary overhead of creating multiple KMD5 |
390 | * objects, you can simply invoke @ref reset() to reuse the same object | 392 | * objects, you can simply invoke @ref reset() to reuse the same object |
391 | * in making another calculation: | 393 | * in making another calculation: |
392 | * | 394 | * |
393 | * <PRE> | 395 | * <PRE> |
394 | * context.reset (); | 396 | * context.reset (); |
395 | * context.update ("TWO"); | 397 | * context.update ("TWO"); |
396 | * context.update ("THREE"); | 398 | * context.update ("THREE"); |
397 | * cout << "Hex Digest output: " << context.hexDigest().data() << endl; | 399 | * cout << "Hex Digest output: " << context.hexDigest().data() << endl; |
398 | * </PRE> | 400 | * </PRE> |
399 | * | 401 | * |
400 | * @short An adapted C++ implementation of RSA Data Securities MD5 algorithm. | 402 | * @short An adapted C++ implementation of RSA Data Securities MD5 algorithm. |
401 | * @author Dirk Mueller <mueller@kde.org>, Dawit Alemayehu <adawit@kde.org> | 403 | * @author Dirk Mueller <mueller@kde.org>, Dawit Alemayehu <adawit@kde.org> |
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 ); |
560 | void II( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, | 562 | void II( Q_UINT32& a, Q_UINT32 b, Q_UINT32 c, Q_UINT32 d, Q_UINT32 x, |
561 | Q_UINT32 s, Q_UINT32 ac ); | 563 | Q_UINT32 s, Q_UINT32 ac ); |
562 | 564 | ||
563 | private: | 565 | private: |
564 | Q_UINT32 m_state[4]; | 566 | Q_UINT32 m_state[4]; |
565 | Q_UINT32 m_count[2]; | 567 | Q_UINT32 m_count[2]; |
566 | Q_UINT8 m_buffer[64]; | 568 | Q_UINT8 m_buffer[64]; |
567 | Digest m_digest; | 569 | Digest m_digest; |
568 | bool m_finalized; | 570 | bool m_finalized; |
569 | 571 | ||
570 | KMD5Private* d; | 572 | KMD5Private* d; |
571 | }; | 573 | }; |
572 | #endif | 574 | #endif |
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,249 +1,251 @@ | |||
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: |
56 | int *mReference; | 58 | int *mReference; |
57 | int mDefault; | 59 | int mDefault; |
58 | }; | 60 | }; |
59 | 61 | ||
60 | 62 | ||
61 | class KPrefsItemColor : public KPrefsItem { | 63 | class KPrefsItemColor : public KPrefsItem { |
62 | public: | 64 | public: |
63 | KPrefsItemColor(const QString &group,const QString &name,QColor *, | 65 | KPrefsItemColor(const QString &group,const QString &name,QColor *, |
64 | const QColor &defaultValue=QColor(128,128,128)); | 66 | const QColor &defaultValue=QColor(128,128,128)); |
65 | virtual ~KPrefsItemColor() {} | 67 | virtual ~KPrefsItemColor() {} |
66 | 68 | ||
67 | void setDefault(); | 69 | void setDefault(); |
68 | void readConfig(KConfig *); | 70 | void readConfig(KConfig *); |
69 | void writeConfig(KConfig *); | 71 | void writeConfig(KConfig *); |
70 | 72 | ||
71 | private: | 73 | private: |
72 | QColor *mReference; | 74 | QColor *mReference; |
73 | QColor mDefault; | 75 | QColor mDefault; |
74 | }; | 76 | }; |
75 | 77 | ||
76 | class KPrefsItemSize : public KPrefsItem { | 78 | class KPrefsItemSize : public KPrefsItem { |
77 | public: | 79 | public: |
78 | KPrefsItemSize(const QString &group,const QString &name,QSize *, | 80 | KPrefsItemSize(const QString &group,const QString &name,QSize *, |
79 | const QSize &defaultValue=QSize()); | 81 | const QSize &defaultValue=QSize()); |
80 | ~KPrefsItemSize() {} | 82 | ~KPrefsItemSize() {} |
81 | 83 | ||
82 | void setDefault(); | 84 | void setDefault(); |
83 | void readConfig(KConfig *); | 85 | void readConfig(KConfig *); |
84 | void writeConfig(KConfig *); | 86 | void writeConfig(KConfig *); |
85 | 87 | ||
86 | private: | 88 | private: |
87 | QSize *mReference; | 89 | QSize *mReference; |
88 | QSize mDefault; | 90 | QSize mDefault; |
89 | }; | 91 | }; |
90 | 92 | ||
91 | 93 | ||
92 | class KPrefsItemFont : public KPrefsItem { | 94 | class KPrefsItemFont : public KPrefsItem { |
93 | public: | 95 | public: |
94 | KPrefsItemFont(const QString &group,const QString &name,QFont *, | 96 | KPrefsItemFont(const QString &group,const QString &name,QFont *, |
95 | const QFont &defaultValue=QFont("helvetica",12)); | 97 | const QFont &defaultValue=QFont("helvetica",12)); |
96 | virtual ~KPrefsItemFont() {} | 98 | virtual ~KPrefsItemFont() {} |
97 | 99 | ||
98 | void setDefault(); | 100 | void setDefault(); |
99 | void readConfig(KConfig *); | 101 | void readConfig(KConfig *); |
100 | void writeConfig(KConfig *); | 102 | void writeConfig(KConfig *); |
101 | 103 | ||
102 | private: | 104 | private: |
103 | QFont *mReference; | 105 | QFont *mReference; |
104 | QFont mDefault; | 106 | QFont mDefault; |
105 | }; | 107 | }; |
106 | 108 | ||
107 | 109 | ||
108 | class KPrefsItemString : public KPrefsItem { | 110 | class KPrefsItemString : public KPrefsItem { |
109 | public: | 111 | public: |
110 | KPrefsItemString(const QString &group,const QString &name,QString *, | 112 | KPrefsItemString(const QString &group,const QString &name,QString *, |
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) : |
186 | KPrefsItem(group,name) | 188 | KPrefsItem(group,name) |
187 | { | 189 | { |
188 | mReference = reference; | 190 | mReference = reference; |
189 | mDefault = defaultValue; | 191 | mDefault = defaultValue; |
190 | } | 192 | } |
191 | 193 | ||
192 | void KPrefsItemInt::setDefault() | 194 | void KPrefsItemInt::setDefault() |
193 | { | 195 | { |
194 | *mReference = mDefault; | 196 | *mReference = mDefault; |
195 | } | 197 | } |
196 | 198 | ||
197 | void KPrefsItemInt::writeConfig(KConfig *config) | 199 | void KPrefsItemInt::writeConfig(KConfig *config) |
198 | { | 200 | { |
199 | config->setGroup(mGroup); | 201 | config->setGroup(mGroup); |
200 | config->writeEntry(mName,*mReference); | 202 | config->writeEntry(mName,*mReference); |
201 | } | 203 | } |
202 | 204 | ||
203 | void KPrefsItemInt::readConfig(KConfig *config) | 205 | void KPrefsItemInt::readConfig(KConfig *config) |
204 | { | 206 | { |
205 | config->setGroup(mGroup); | 207 | config->setGroup(mGroup); |
206 | *mReference = config->readNumEntry(mName,mDefault); | 208 | *mReference = config->readNumEntry(mName,mDefault); |
207 | } | 209 | } |
208 | 210 | ||
209 | 211 | ||
210 | KPrefsItemColor::KPrefsItemColor(const QString &group,const QString &name, | 212 | KPrefsItemColor::KPrefsItemColor(const QString &group,const QString &name, |
211 | QColor *reference,const QColor &defaultValue) : | 213 | QColor *reference,const QColor &defaultValue) : |
212 | KPrefsItem(group,name) | 214 | KPrefsItem(group,name) |
213 | { | 215 | { |
214 | mReference = reference; | 216 | mReference = reference; |
215 | mDefault = defaultValue; | 217 | mDefault = defaultValue; |
216 | } | 218 | } |
217 | 219 | ||
218 | void KPrefsItemColor::setDefault() | 220 | void KPrefsItemColor::setDefault() |
219 | { | 221 | { |
220 | *mReference = mDefault; | 222 | *mReference = mDefault; |
221 | } | 223 | } |
222 | 224 | ||
223 | void KPrefsItemColor::writeConfig(KConfig *config) | 225 | void KPrefsItemColor::writeConfig(KConfig *config) |
224 | { | 226 | { |
225 | config->setGroup(mGroup); | 227 | config->setGroup(mGroup); |
226 | config->writeEntry(mName,*mReference); | 228 | config->writeEntry(mName,*mReference); |
227 | } | 229 | } |
228 | 230 | ||
229 | void KPrefsItemColor::readConfig(KConfig *config) | 231 | void KPrefsItemColor::readConfig(KConfig *config) |
230 | { | 232 | { |
231 | config->setGroup(mGroup); | 233 | config->setGroup(mGroup); |
232 | *mReference = config->readColorEntry(mName,&mDefault); | 234 | *mReference = config->readColorEntry(mName,&mDefault); |
233 | 235 | ||
234 | } | 236 | } |
235 | 237 | ||
236 | 238 | ||
237 | KPrefsItemSize::KPrefsItemSize(const QString &group,const QString &name, | 239 | KPrefsItemSize::KPrefsItemSize(const QString &group,const QString &name, |
238 | QSize *reference,const QSize &defaultValue) : | 240 | QSize *reference,const QSize &defaultValue) : |
239 | KPrefsItem(group,name) | 241 | KPrefsItem(group,name) |
240 | { | 242 | { |
241 | mReference = reference; | 243 | mReference = reference; |
242 | mDefault = defaultValue; | 244 | mDefault = defaultValue; |
243 | } | 245 | } |
244 | 246 | ||
245 | void KPrefsItemSize::setDefault() | 247 | void KPrefsItemSize::setDefault() |
246 | { | 248 | { |
247 | *mReference = mDefault; | 249 | *mReference = mDefault; |
248 | } | 250 | } |
249 | 251 | ||
@@ -271,242 +273,242 @@ KPrefsItemFont::KPrefsItemFont(const QString &group,const QString &name, | |||
271 | 273 | ||
272 | void KPrefsItemFont::setDefault() | 274 | void KPrefsItemFont::setDefault() |
273 | { | 275 | { |
274 | *mReference = mDefault; | 276 | *mReference = mDefault; |
275 | } | 277 | } |
276 | 278 | ||
277 | void KPrefsItemFont::writeConfig(KConfig *config) | 279 | void KPrefsItemFont::writeConfig(KConfig *config) |
278 | { | 280 | { |
279 | config->setGroup(mGroup); | 281 | config->setGroup(mGroup); |
280 | config->writeEntry(mName,*mReference); | 282 | config->writeEntry(mName,*mReference); |
281 | } | 283 | } |
282 | 284 | ||
283 | void KPrefsItemFont::readConfig(KConfig *config) | 285 | void KPrefsItemFont::readConfig(KConfig *config) |
284 | { | 286 | { |
285 | config->setGroup(mGroup); | 287 | config->setGroup(mGroup); |
286 | *mReference = config->readFontEntry(mName,&mDefault); | 288 | *mReference = config->readFontEntry(mName,&mDefault); |
287 | } | 289 | } |
288 | 290 | ||
289 | 291 | ||
290 | QString endecryptStr( const QString &aStr ) | 292 | QString endecryptStr( const QString &aStr ) |
291 | { | 293 | { |
292 | QString result; | 294 | QString result; |
293 | uint i; | 295 | uint i; |
294 | for ( i = 0; i < aStr.length(); i++) | 296 | for ( i = 0; i < aStr.length(); i++) |
295 | result += (aStr.at(i).unicode() < 0x20) ? | 297 | result += (aStr.at(i).unicode() < 0x20) ? |
296 | aStr.at(i) : | 298 | aStr.at(i) : |
297 | QChar(0x1001F - aStr.at(i).unicode()); | 299 | QChar(0x1001F - aStr.at(i).unicode()); |
298 | return result; | 300 | return result; |
299 | } | 301 | } |
300 | 302 | ||
301 | 303 | ||
302 | KPrefsItemString::KPrefsItemString(const QString &group,const QString &name, | 304 | KPrefsItemString::KPrefsItemString(const QString &group,const QString &name, |
303 | QString *reference,const QString &defaultValue, | 305 | QString *reference,const QString &defaultValue, |
304 | bool isPassword) : | 306 | bool isPassword) : |
305 | KPrefsItem(group,name) | 307 | KPrefsItem(group,name) |
306 | { | 308 | { |
307 | mReference = reference; | 309 | mReference = reference; |
308 | mDefault = defaultValue; | 310 | mDefault = defaultValue; |
309 | mPassword = isPassword; | 311 | mPassword = isPassword; |
310 | } | 312 | } |
311 | 313 | ||
312 | void KPrefsItemString::setDefault() | 314 | void KPrefsItemString::setDefault() |
313 | { | 315 | { |
314 | *mReference = mDefault; | 316 | *mReference = mDefault; |
315 | } | 317 | } |
316 | 318 | ||
317 | void KPrefsItemString::writeConfig(KConfig *config) | 319 | void KPrefsItemString::writeConfig(KConfig *config) |
318 | { | 320 | { |
319 | config->setGroup(mGroup); | 321 | config->setGroup(mGroup); |
320 | if ( mPassword ) | 322 | if ( mPassword ) |
321 | config->writeEntry(mName, endecryptStr( *mReference ) ); | 323 | config->writeEntry(mName, endecryptStr( *mReference ) ); |
322 | else | 324 | else |
323 | config->writeEntry(mName,*mReference); | 325 | config->writeEntry(mName,*mReference); |
324 | } | 326 | } |
325 | 327 | ||
326 | void KPrefsItemString::readConfig(KConfig *config) | 328 | void KPrefsItemString::readConfig(KConfig *config) |
327 | { | 329 | { |
328 | config->setGroup(mGroup); | 330 | config->setGroup(mGroup); |
329 | 331 | ||
330 | QString value; | 332 | QString value; |
331 | if ( mPassword ) { | 333 | if ( mPassword ) { |
332 | value = config->readEntry( mName, endecryptStr( mDefault ) ); | 334 | value = config->readEntry( mName, endecryptStr( mDefault ) ); |
333 | *mReference = endecryptStr( value ); | 335 | *mReference = endecryptStr( value ); |
334 | } else { | 336 | } else { |
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 { |
400 | qDebug("KPrefs::Global config "); | 402 | qDebug("KPrefs::Global config "); |
401 | mConfig = KGlobal::config(); | 403 | mConfig = KGlobal::config(); |
402 | } | 404 | } |
403 | 405 | ||
404 | mItems.setAutoDelete(true); | 406 | mItems.setAutoDelete(true); |
405 | 407 | ||
406 | // Set default group | 408 | // Set default group |
407 | if (mCurrentGroup == 0) mCurrentGroup = new QString("No Group"); | 409 | if (mCurrentGroup == 0) mCurrentGroup = new QString("No Group"); |
408 | } | 410 | } |
409 | 411 | ||
410 | KPrefs::~KPrefs() | 412 | KPrefs::~KPrefs() |
411 | { | 413 | { |
412 | if (mConfig != KGlobal::config()) { | 414 | if (mConfig != KGlobal::config()) { |
413 | delete mConfig; | 415 | delete mConfig; |
414 | } | 416 | } |
415 | } | 417 | } |
416 | 418 | ||
417 | void KPrefs::setCurrentGroup(const QString &group) | 419 | void KPrefs::setCurrentGroup(const QString &group) |
418 | { | 420 | { |
419 | if (mCurrentGroup) delete mCurrentGroup; | 421 | if (mCurrentGroup) delete mCurrentGroup; |
420 | mCurrentGroup = new QString(group); | 422 | mCurrentGroup = new QString(group); |
421 | } | 423 | } |
422 | 424 | ||
423 | KConfig *KPrefs::config() const | 425 | KConfig *KPrefs::config() const |
424 | { | 426 | { |
425 | return mConfig; | 427 | return mConfig; |
426 | } | 428 | } |
427 | 429 | ||
428 | void KPrefs::setDefaults() | 430 | void KPrefs::setDefaults() |
429 | { | 431 | { |
430 | KPrefsItem *item; | 432 | KPrefsItem *item; |
431 | for(item = mItems.first();item;item = mItems.next()) { | 433 | for(item = mItems.first();item;item = mItems.next()) { |
432 | item->setDefault(); | 434 | item->setDefault(); |
433 | } | 435 | } |
434 | 436 | ||
435 | usrSetDefaults(); | 437 | usrSetDefaults(); |
436 | } | 438 | } |
437 | 439 | ||
438 | void KPrefs::readConfig() | 440 | void KPrefs::readConfig() |
439 | { | 441 | { |
440 | KPrefsItem *item; | 442 | KPrefsItem *item; |
441 | for(item = mItems.first();item;item = mItems.next()) { | 443 | for(item = mItems.first();item;item = mItems.next()) { |
442 | item->readConfig(mConfig); | 444 | item->readConfig(mConfig); |
443 | } | 445 | } |
444 | 446 | ||
445 | usrReadConfig(); | 447 | usrReadConfig(); |
446 | //qDebug("KPrefs::readConfig: %s", mConfig->getFileName().latin1()); | 448 | //qDebug("KPrefs::readConfig: %s", mConfig->getFileName().latin1()); |
447 | } | 449 | } |
448 | 450 | ||
449 | void KPrefs::writeConfig() | 451 | void KPrefs::writeConfig() |
450 | { | 452 | { |
451 | KPrefsItem *item; | 453 | KPrefsItem *item; |
452 | for(item = mItems.first();item;item = mItems.next()) { | 454 | for(item = mItems.first();item;item = mItems.next()) { |
453 | item->writeConfig(mConfig); | 455 | item->writeConfig(mConfig); |
454 | } | 456 | } |
455 | 457 | ||
456 | usrWriteConfig(); | 458 | usrWriteConfig(); |
457 | //qDebug("KPrefs::WriteConfig: %s", mConfig->getFileName().latin1()); | 459 | //qDebug("KPrefs::WriteConfig: %s", mConfig->getFileName().latin1()); |
458 | mConfig->sync(); | 460 | mConfig->sync(); |
459 | } | 461 | } |
460 | 462 | ||
461 | 463 | ||
462 | void KPrefs::addItem(KPrefsItem *item) | 464 | void KPrefs::addItem(KPrefsItem *item) |
463 | { | 465 | { |
464 | mItems.append(item); | 466 | mItems.append(item); |
465 | } | 467 | } |
466 | 468 | ||
467 | void KPrefs::addItemBool(const QString &key,bool *reference,bool defaultValue) | 469 | void KPrefs::addItemBool(const QString &key,bool *reference,bool defaultValue) |
468 | { | 470 | { |
469 | addItem(new KPrefsItemBool(*mCurrentGroup,key,reference,defaultValue)); | 471 | addItem(new KPrefsItemBool(*mCurrentGroup,key,reference,defaultValue)); |
470 | } | 472 | } |
471 | 473 | ||
472 | void KPrefs::addItemInt(const QString &key,int *reference,int defaultValue) | 474 | void KPrefs::addItemInt(const QString &key,int *reference,int defaultValue) |
473 | { | 475 | { |
474 | addItem(new KPrefsItemInt(*mCurrentGroup,key,reference,defaultValue)); | 476 | addItem(new KPrefsItemInt(*mCurrentGroup,key,reference,defaultValue)); |
475 | } | 477 | } |
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,124 +1,126 @@ | |||
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. |
61 | */ | 63 | */ |
62 | virtual void setDefault() = 0; | 64 | virtual void setDefault() = 0; |
63 | /** | 65 | /** |
64 | This function is called by @ref KPrefs to read the value for this setting | 66 | This function is called by @ref KPrefs to read the value for this setting |
65 | from a config file. | 67 | from a config file. |
66 | value. | 68 | value. |
67 | */ | 69 | */ |
68 | virtual void readConfig(KConfig *) = 0; | 70 | virtual void readConfig(KConfig *) = 0; |
69 | /** | 71 | /** |
70 | This function is called by @ref KPrefs to write the value of this setting | 72 | This function is called by @ref KPrefs to write the value of this setting |
71 | to a config file. | 73 | to a config file. |
72 | */ | 74 | */ |
73 | virtual void writeConfig(KConfig *) = 0; | 75 | virtual void writeConfig(KConfig *) = 0; |
74 | 76 | ||
75 | protected: | 77 | protected: |
76 | QString mGroup; | 78 | QString mGroup; |
77 | QString mName; | 79 | QString mName; |
78 | }; | 80 | }; |
79 | 81 | ||
80 | /** | 82 | /** |
81 | @short Class for handling preferences settings for an application. | 83 | @short Class for handling preferences settings for an application. |
82 | @author Cornelius Schumacher | 84 | @author Cornelius Schumacher |
83 | @see KPrefsItem | 85 | @see KPrefsItem |
84 | 86 | ||
85 | This class provides an interface to preferences settings. Preferences items | 87 | This class provides an interface to preferences settings. Preferences items |
86 | can be registered by the addItem() function corresponding to the data type of | 88 | can be registered by the addItem() function corresponding to the data type of |
87 | the seetting. KPrefs then handles reading and writing of config files and | 89 | the seetting. KPrefs then handles reading and writing of config files and |
88 | setting of default values. | 90 | setting of default values. |
89 | 91 | ||
90 | Normally you will subclass KPrefs, add data members for the preferences | 92 | Normally you will subclass KPrefs, add data members for the preferences |
91 | settings and register the members in the constructor of the subclass. | 93 | settings and register the members in the constructor of the subclass. |
92 | 94 | ||
93 | Example: | 95 | Example: |
94 | <pre> | 96 | <pre> |
95 | class MyPrefs : public KPrefs { | 97 | class MyPrefs : public KPrefs { |
96 | public: | 98 | public: |
97 | MyPrefs() | 99 | MyPrefs() |
98 | { | 100 | { |
99 | setCurrentGroup("MyGroup"); | 101 | setCurrentGroup("MyGroup"); |
100 | addItemBool("MySetting1",&mMyBool,false); | 102 | addItemBool("MySetting1",&mMyBool,false); |
101 | addItemColor("MySetting2",&mMyColor,QColor(1,2,3)); | 103 | addItemColor("MySetting2",&mMyColor,QColor(1,2,3)); |
102 | 104 | ||
103 | setCurrentGroup("MyOtherGroup"); | 105 | setCurrentGroup("MyOtherGroup"); |
104 | addItemFont("MySetting3",&mMyFont,QFont("helvetica",12)); | 106 | addItemFont("MySetting3",&mMyFont,QFont("helvetica",12)); |
105 | } | 107 | } |
106 | 108 | ||
107 | bool mMyBool; | 109 | bool mMyBool; |
108 | QColor mMyColor; | 110 | QColor mMyColor; |
109 | QFont mMyFont; | 111 | QFont mMyFont; |
110 | } | 112 | } |
111 | </pre> | 113 | </pre> |
112 | 114 | ||
113 | It might be convenient in many cases to make this subclass of KPrefs a | 115 | It might be convenient in many cases to make this subclass of KPrefs a |
114 | singleton for global access from all over the application without passing | 116 | singleton for global access from all over the application without passing |
115 | references to the KPrefs object around. | 117 | references to the KPrefs object around. |
116 | 118 | ||
117 | You can set all values to default values by calling @ref setDefaults(), write | 119 | You can set all values to default values by calling @ref setDefaults(), write |
118 | the data to the configuration file by calling @ref writeConfig() and read the | 120 | the data to the configuration file by calling @ref writeConfig() and read the |
119 | data from the configuration file by calling @ref readConfig(). | 121 | data from the configuration file by calling @ref readConfig(). |
120 | 122 | ||
121 | If you have items, which are not covered by the existing addItem() functions | 123 | If you have items, which are not covered by the existing addItem() functions |
122 | you can add customized code for reading, writing and default setting by | 124 | you can add customized code for reading, writing and default setting by |
123 | implementing the functions @ref usrSetDefaults(), @ref usrReadConfig() and | 125 | implementing the functions @ref usrSetDefaults(), @ref usrReadConfig() and |
124 | @ref usrWriteConfig(). | 126 | @ref usrWriteConfig(). |
@@ -190,127 +192,127 @@ class KPrefs { | |||
190 | @param key Key used in config file. | 192 | @param key Key used in config file. |
191 | @param reference Pointer to the variable, which is set by readConfig() | 193 | @param reference Pointer to the variable, which is set by readConfig() |
192 | and setDefaults() calls and read by writeConfig() calls. | 194 | and setDefaults() calls and read by writeConfig() calls. |
193 | @param defaultValue Default value, which is used by setDefaults() and | 195 | @param defaultValue Default value, which is used by setDefaults() and |
194 | when the config file does not yet contain the key of | 196 | when the config file does not yet contain the key of |
195 | this item. | 197 | this item. |
196 | */ | 198 | */ |
197 | void addItemInt(const QString &key,int *reference, | 199 | void addItemInt(const QString &key,int *reference, |
198 | int defaultValue=0); | 200 | int defaultValue=0); |
199 | /** | 201 | /** |
200 | Register an item of type QColor. | 202 | Register an item of type QColor. |
201 | 203 | ||
202 | @param key Key used in config file. | 204 | @param key Key used in config file. |
203 | @param reference Pointer to the variable, which is set by readConfig() | 205 | @param reference Pointer to the variable, which is set by readConfig() |
204 | and setDefaults() calls and read by writeConfig() calls. | 206 | and setDefaults() calls and read by writeConfig() calls. |
205 | @param defaultValue Default value, which is used by setDefaults() and | 207 | @param defaultValue Default value, which is used by setDefaults() and |
206 | when the config file does not yet contain the key of | 208 | when the config file does not yet contain the key of |
207 | this item. | 209 | this item. |
208 | */ | 210 | */ |
209 | void addItemColor(const QString &key,QColor *reference, | 211 | void addItemColor(const QString &key,QColor *reference, |
210 | const QColor &defaultValue=QColor(128,128,128)); | 212 | const QColor &defaultValue=QColor(128,128,128)); |
211 | 213 | ||
212 | /** | 214 | /** |
213 | Register an item of type QSize. | 215 | Register an item of type QSize. |
214 | 216 | ||
215 | @param key Key used in config file. | 217 | @param key Key used in config file. |
216 | @param reference Pointer to the variable, which is set by readConfig() | 218 | @param reference Pointer to the variable, which is set by readConfig() |
217 | and setDefaults() calls and read by writeConfig() calls. | 219 | and setDefaults() calls and read by writeConfig() calls. |
218 | @param defaultValue Default value, which is used by setDefaults() and | 220 | @param defaultValue Default value, which is used by setDefaults() and |
219 | when the config file does not yet contain the key of | 221 | when the config file does not yet contain the key of |
220 | this item. | 222 | this item. |
221 | */ | 223 | */ |
222 | void addItemSize(const QString &key,QSize *reference, | 224 | void addItemSize(const QString &key,QSize *reference, |
223 | const QSize &defaultValue=QSize()); | 225 | const QSize &defaultValue=QSize()); |
224 | 226 | ||
225 | /** | 227 | /** |
226 | Register an item of type QFont. | 228 | Register an item of type QFont. |
227 | 229 | ||
228 | @param key Key used in config file. | 230 | @param key Key used in config file. |
229 | @param reference Pointer to the variable, which is set by readConfig() | 231 | @param reference Pointer to the variable, which is set by readConfig() |
230 | and setDefaults() calls and read by writeConfig() calls. | 232 | and setDefaults() calls and read by writeConfig() calls. |
231 | @param defaultValue Default value, which is used by setDefaults() and | 233 | @param defaultValue Default value, which is used by setDefaults() and |
232 | when the config file does not yet contain the key of | 234 | when the config file does not yet contain the key of |
233 | this item. | 235 | this item. |
234 | */ | 236 | */ |
235 | void addItemFont(const QString &key,QFont *reference, | 237 | void addItemFont(const QString &key,QFont *reference, |
236 | const QFont &defaultValue=QFont("helvetica",12)); | 238 | const QFont &defaultValue=QFont("helvetica",12)); |
237 | /** | 239 | /** |
238 | Register an item of type QString. | 240 | Register an item of type QString. |
239 | 241 | ||
240 | @param key Key used in config file. | 242 | @param key Key used in config file. |
241 | @param reference Pointer to the variable, which is set by readConfig() | 243 | @param reference Pointer to the variable, which is set by readConfig() |
242 | and setDefaults() calls and read by writeConfig() calls. | 244 | and setDefaults() calls and read by writeConfig() calls. |
243 | @param defaultValue Default value, which is used by setDefaults() and | 245 | @param defaultValue Default value, which is used by setDefaults() and |
244 | when the config file does not yet contain the key of | 246 | when the config file does not yet contain the key of |
245 | this item. | 247 | this item. |
246 | */ | 248 | */ |
247 | void addItemString(const QString &key,QString *reference, | 249 | void addItemString(const QString &key,QString *reference, |
248 | const QString &defaultValue=""); | 250 | const QString &defaultValue=""); |
249 | /** | 251 | /** |
250 | Register a password item of type QString. The string value is written | 252 | Register a password item of type QString. The string value is written |
251 | encrypted to the config file. Note that the current encryption scheme | 253 | encrypted to the config file. Note that the current encryption scheme |
252 | is very weak. | 254 | is very weak. |
253 | 255 | ||
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 | |||
@@ -470,238 +470,238 @@ class KKey | |||
470 | */ | 470 | */ |
471 | //USbool operator == ( const KKeySequence& seq ) const | 471 | //USbool operator == ( const KKeySequence& seq ) const |
472 | //US { return compare( seq ) == 0; } | 472 | //US { return compare( seq ) == 0; } |
473 | 473 | ||
474 | /** | 474 | /** |
475 | * Compares the keys of both sequences. | 475 | * Compares the keys of both sequences. |
476 | * @see compare() | 476 | * @see compare() |
477 | */ | 477 | */ |
478 | //USbool operator != ( const KKeySequence& seq ) const | 478 | //USbool operator != ( const KKeySequence& seq ) const |
479 | //US { return compare( seq ) != 0; } | 479 | //US { return compare( seq ) != 0; } |
480 | 480 | ||
481 | /** | 481 | /** |
482 | * Compares the keys of both sequences. | 482 | * Compares the keys of both sequences. |
483 | * @see compare() | 483 | * @see compare() |
484 | */ | 484 | */ |
485 | //USbool operator < ( const KKeySequence& seq ) const | 485 | //USbool operator < ( const KKeySequence& seq ) const |
486 | //US { return compare( seq ) < 0; } | 486 | //US { return compare( seq ) < 0; } |
487 | // TODO: consider adding Qt::SequenceMatch matches(...) methods for QKeySequence equivalence | 487 | // TODO: consider adding Qt::SequenceMatch matches(...) methods for QKeySequence equivalence |
488 | 488 | ||
489 | /** | 489 | /** |
490 | * Converts this key sequence to a QKeySequence. | 490 | * Converts this key sequence to a QKeySequence. |
491 | * @return the QKeySequence | 491 | * @return the QKeySequence |
492 | */ | 492 | */ |
493 | //USQKeySequence qt() const; | 493 | //USQKeySequence qt() const; |
494 | 494 | ||
495 | /** | 495 | /** |
496 | * Returns the qt key code of the first key. | 496 | * Returns the qt key code of the first key. |
497 | * @return the qt key code of the first key | 497 | * @return the qt key code of the first key |
498 | * @see Qt::Key | 498 | * @see Qt::Key |
499 | * @see KKey::keyCodeQt() | 499 | * @see KKey::keyCodeQt() |
500 | */ | 500 | */ |
501 | //USint keyCodeQt() const; | 501 | //USint keyCodeQt() const; |
502 | 502 | ||
503 | /** | 503 | /** |
504 | * Returns the key sequence as a number of key presses as | 504 | * Returns the key sequence as a number of key presses as |
505 | * returned by @ref KKey::toString(), seperated by commas. | 505 | * returned by @ref KKey::toString(), seperated by commas. |
506 | * @return the string represenation of this key sequence | 506 | * @return the string represenation of this key sequence |
507 | * @see KKey::toString() | 507 | * @see KKey::toString() |
508 | */ | 508 | */ |
509 | //USQString toString() const; | 509 | //USQString toString() const; |
510 | 510 | ||
511 | /** | 511 | /** |
512 | * @internal | 512 | * @internal |
513 | */ | 513 | */ |
514 | //US QString toStringInternal() const; | 514 | //US QString toStringInternal() const; |
515 | 515 | ||
516 | /** | 516 | /** |
517 | * Returns a null key sequence. | 517 | * Returns a null key sequence. |
518 | * @return the null key sequence | 518 | * @return the null key sequence |
519 | * @see isNull() | 519 | * @see isNull() |
520 | * @see clear() | 520 | * @see clear() |
521 | */ | 521 | */ |
522 | //USstatic KKeySequence& null(); | 522 | //USstatic KKeySequence& null(); |
523 | 523 | ||
524 | //US protected: | 524 | //US protected: |
525 | //USuchar m_nKeys; | 525 | //USuchar m_nKeys; |
526 | //USuchar m_bTriggerOnRelease; | 526 | //USuchar m_bTriggerOnRelease; |
527 | // BCI: m_rgvar should be renamed to m_rgkey for KDE 4.0 | 527 | // BCI: m_rgvar should be renamed to m_rgkey for KDE 4.0 |
528 | //USKKey m_rgvar[MAX_KEYS]; | 528 | //USKKey m_rgvar[MAX_KEYS]; |
529 | 529 | ||
530 | //US private: | 530 | //US private: |
531 | //USclass KKeySequencePrivate* d; | 531 | //USclass KKeySequencePrivate* d; |
532 | //USfriend class KKeyNative; | 532 | //USfriend class KKeyNative; |
533 | //US}; | 533 | //US}; |
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 |
644 | */ | 644 | */ |
645 | //USbool init( const KKeySequence& keySeq ); | 645 | //USbool init( const KKeySequence& keySeq ); |
646 | 646 | ||
647 | /** | 647 | /** |
648 | * Copies the given shortcut. | 648 | * Copies the given shortcut. |
649 | * @param shortcut the shortcut to add | 649 | * @param shortcut the shortcut to add |
650 | */ | 650 | */ |
651 | //USbool init( const KShortcut& shortcut ); | 651 | //USbool init( const KShortcut& shortcut ); |
652 | 652 | ||
653 | /** | 653 | /** |
654 | * Initializes the key sequence with the given key sequence. | 654 | * Initializes the key sequence with the given key sequence. |
655 | * The description consists of semicolon-separated keys as | 655 | * The description consists of semicolon-separated keys as |
656 | * used in @ref KKeySequence::KKeySequence(const QString&). | 656 | * used in @ref KKeySequence::KKeySequence(const QString&). |
657 | * @param shortcut the description of the key | 657 | * @param shortcut the description of the key |
658 | * @see KKeySequence::KKeySequence(const QString&) | 658 | * @see KKeySequence::KKeySequence(const QString&) |
659 | */ | 659 | */ |
660 | //USbool init( const QString& shortcut ); | 660 | //USbool init( const QString& shortcut ); |
661 | 661 | ||
662 | /** | 662 | /** |
663 | * Copies the given shortcut over this shortcut. | 663 | * Copies the given shortcut over this shortcut. |
664 | */ | 664 | */ |
665 | //USKShortcut& operator =( const KShortcut& cut ) | 665 | //USKShortcut& operator =( const KShortcut& cut ) |
666 | //US { init( cut ); return *this; } | 666 | //US { init( cut ); return *this; } |
667 | 667 | ||
668 | /** | 668 | /** |
669 | * Returns the number of sequences that are in this | 669 | * Returns the number of sequences that are in this |
670 | * shortcut. | 670 | * shortcut. |
671 | * @return the number of sequences | 671 | * @return the number of sequences |
672 | * @ref MAX_SEQUENCES | 672 | * @ref MAX_SEQUENCES |
673 | */ | 673 | */ |
674 | //USuint count() const; | 674 | //USuint count() const; |
675 | 675 | ||
676 | /** | 676 | /** |
677 | * Returns the @p i'th key sequence of this shortcut. | 677 | * Returns the @p i'th key sequence of this shortcut. |
678 | * @param i the number of the key sequence to retrieve | 678 | * @param i the number of the key sequence to retrieve |
679 | * @return the @p i'th sequence or @ref KKeySequence::null() if | 679 | * @return the @p i'th sequence or @ref KKeySequence::null() if |
680 | * there are less than @p i key sequences | 680 | * there are less than @p i key sequences |
681 | * @ref MAX_SEQUENCES | 681 | * @ref MAX_SEQUENCES |
682 | */ | 682 | */ |
683 | //USconst KKeySequence& seq( uint i ) const; | 683 | //USconst KKeySequence& seq( uint i ) const; |
684 | 684 | ||
685 | /** | 685 | /** |
686 | * Returns the key code of the first key sequence, or | 686 | * Returns the key code of the first key sequence, or |
687 | * null if there is no first key sequence. | 687 | * null if there is no first key sequence. |
688 | * @return the key code of the first sequence's first key | 688 | * @return the key code of the first sequence's first key |
689 | * @see Qt::Key | 689 | * @see Qt::Key |
690 | * @see KKeySequence::keyCodeQt() | 690 | * @see KKeySequence::keyCodeQt() |
691 | */ | 691 | */ |
692 | //USint keyCodeQt() const; | 692 | //USint keyCodeQt() const; |
693 | 693 | ||
694 | /** | 694 | /** |
695 | * Returns true if the shortcut is null (after @ref clear() or empty | 695 | * Returns true if the shortcut is null (after @ref clear() or empty |
696 | * constructor). | 696 | * constructor). |
697 | * @return true if the shortcut is null | 697 | * @return true if the shortcut is null |
698 | * @see clear() | 698 | * @see clear() |
699 | * @see null() | 699 | * @see null() |
700 | */ | 700 | */ |
701 | bool isNull() const { return true; } | 701 | bool isNull() const { return true; } |
702 | 702 | ||
703 | /** | 703 | /** |
704 | * Compares this object with the given shortcut. Returns a negative | 704 | * Compares this object with the given shortcut. Returns a negative |
705 | * number if the given shortcut is larger, 0 if they are equal and | 705 | * number if the given shortcut is larger, 0 if they are equal and |
706 | * a positive number this shortcut is larger. Shortcuts are | 706 | * a positive number this shortcut is larger. Shortcuts are |
707 | * compared by comparing the individual key sequences, starting from the | 707 | * compared by comparing the individual key sequences, starting from the |
@@ -723,124 +723,124 @@ class KShortcut | |||
723 | //US { return compare( cut ) == 0; } | 723 | //US { return compare( cut ) == 0; } |
724 | 724 | ||
725 | /** | 725 | /** |
726 | * Compares the sequences of both shortcuts. | 726 | * Compares the sequences of both shortcuts. |
727 | * @see compare() | 727 | * @see compare() |
728 | */ | 728 | */ |
729 | //USbool operator != ( const KShortcut& cut ) const | 729 | //USbool operator != ( const KShortcut& cut ) const |
730 | //US { return compare( cut ) != 0; } | 730 | //US { return compare( cut ) != 0; } |
731 | 731 | ||
732 | /** | 732 | /** |
733 | * Compares the sequences of both shortcuts. | 733 | * Compares the sequences of both shortcuts. |
734 | * @see compare() | 734 | * @see compare() |
735 | */ | 735 | */ |
736 | //USbool operator < ( const KShortcut& cut ) const | 736 | //USbool operator < ( const KShortcut& cut ) const |
737 | //US { return compare( cut ) < 0; } | 737 | //US { return compare( cut ) < 0; } |
738 | 738 | ||
739 | /** | 739 | /** |
740 | * Checks whether this shortcut contains a sequence that starts | 740 | * Checks whether this shortcut contains a sequence that starts |
741 | * with the given key. | 741 | * with the given key. |
742 | * @param key the key to check | 742 | * @param key the key to check |
743 | * @return true if a key sequence starts with the key | 743 | * @return true if a key sequence starts with the key |
744 | */ | 744 | */ |
745 | //USbool contains( const KKey& key ) const; | 745 | //USbool contains( const KKey& key ) const; |
746 | 746 | ||
747 | /** | 747 | /** |
748 | * Checks whether this shortcut contains a sequence that starts | 748 | * Checks whether this shortcut contains a sequence that starts |
749 | * with the given key. | 749 | * with the given key. |
750 | * @param key the key to check | 750 | * @param key the key to check |
751 | * @return true if a key sequence starts with the key | 751 | * @return true if a key sequence starts with the key |
752 | */ | 752 | */ |
753 | //USbool contains( const KKeyNative& key ) const; | 753 | //USbool contains( const KKeyNative& key ) const; |
754 | 754 | ||
755 | /** | 755 | /** |
756 | * Checks whether this shortcut contains the given sequence. | 756 | * Checks whether this shortcut contains the given sequence. |
757 | * @param keySeq the key sequence to check | 757 | * @param keySeq the key sequence to check |
758 | * @return true if the shortcut has the given key sequence | 758 | * @return true if the shortcut has the given key sequence |
759 | */ | 759 | */ |
760 | //USbool contains( const KKeySequence& keySeq ) const; | 760 | //USbool contains( const KKeySequence& keySeq ) const; |
761 | 761 | ||
762 | /** | 762 | /** |
763 | * Sets the @p i'th key sequence of the shortcut. You can not introduce | 763 | * Sets the @p i'th key sequence of the shortcut. You can not introduce |
764 | * gaps in the list of sequences, so you must use an @i <= @ref count(). | 764 | * gaps in the list of sequences, so you must use an @i <= @ref count(). |
765 | * Also note that the maximum number of key sequences is @ref MAX_SEQUENCES. | 765 | * Also note that the maximum number of key sequences is @ref MAX_SEQUENCES. |
766 | * @param i the position of the new key sequence(<= @ref count(), | 766 | * @param i the position of the new key sequence(<= @ref count(), |
767 | * <= @ref MAX_SEQUENCES) | 767 | * <= @ref MAX_SEQUENCES) |
768 | * @param keySeq the key sequence to set | 768 | * @param keySeq the key sequence to set |
769 | * @return true if successful, false otherwise | 769 | * @return true if successful, false otherwise |
770 | */ | 770 | */ |
771 | //USbool setSeq( uint i, const KKeySequence& keySeq ); | 771 | //USbool setSeq( uint i, const KKeySequence& keySeq ); |
772 | 772 | ||
773 | /** | 773 | /** |
774 | * Appends the given key sequence. | 774 | * Appends the given key sequence. |
775 | * @param keySeq the key sequence to add | 775 | * @param keySeq the key sequence to add |
776 | * @return true if successful, false otherwise | 776 | * @return true if successful, false otherwise |
777 | * @see setSeq() | 777 | * @see setSeq() |
778 | * @see MAX_SEQUENCES | 778 | * @see MAX_SEQUENCES |
779 | */ | 779 | */ |
780 | //USbool append( const KKeySequence& keySeq ); | 780 | //USbool append( const KKeySequence& keySeq ); |
781 | 781 | ||
782 | /** | 782 | /** |
783 | * Appends the given key | 783 | * Appends the given key |
784 | * @param spec the key to add | 784 | * @param spec the key to add |
785 | * @return true if successful, false otherwise | 785 | * @return true if successful, false otherwise |
786 | * @see setSeq() | 786 | * @see setSeq() |
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 | |||
@@ -1,184 +1,186 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org> | 2 | Copyright (C) 1999 Sirtaj Singh Kang <taj@kde.org> |
3 | Copyright (C) 1999 Stephan Kulow <coolo@kde.org> | 3 | Copyright (C) 1999 Stephan Kulow <coolo@kde.org> |
4 | Copyright (C) 1999 Waldo Bastian <bastian@kde.org> | 4 | Copyright (C) 1999 Waldo Bastian <bastian@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
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) |
121 | return false; | 123 | return false; |
122 | 124 | ||
123 | if (d->restrictions[type]) | 125 | if (d->restrictions[type]) |
124 | return true; | 126 | return true; |
125 | 127 | ||
126 | if (strcmp(type, "data")==0) | 128 | if (strcmp(type, "data")==0) |
127 | { | 129 | { |
128 | applyDataRestrictions(relPath); | 130 | applyDataRestrictions(relPath); |
129 | if (d->dataRestrictionActive) | 131 | if (d->dataRestrictionActive) |
130 | { | 132 | { |
131 | d->dataRestrictionActive = false; | 133 | d->dataRestrictionActive = false; |
132 | return true; | 134 | return true; |
133 | } | 135 | } |
134 | } | 136 | } |
135 | return false; | 137 | return false; |
136 | } | 138 | } |
137 | 139 | ||
138 | void KStandardDirs::applyDataRestrictions(const QString &relPath) const | 140 | void KStandardDirs::applyDataRestrictions(const QString &relPath) const |
139 | { | 141 | { |
140 | QString key; | 142 | QString key; |
141 | int i = relPath.find('/'); | 143 | int i = relPath.find('/'); |
142 | if (i != -1) | 144 | if (i != -1) |
143 | key = "data_"+relPath.left(i); | 145 | key = "data_"+relPath.left(i); |
144 | else | 146 | else |
145 | key = "data_"+relPath; | 147 | key = "data_"+relPath; |
146 | 148 | ||
147 | if (d && d->restrictions[key.latin1()]) | 149 | if (d && d->restrictions[key.latin1()]) |
148 | d->dataRestrictionActive = true; | 150 | d->dataRestrictionActive = true; |
149 | } | 151 | } |
150 | 152 | ||
151 | 153 | ||
152 | QStringList KStandardDirs::allTypes() const | 154 | QStringList KStandardDirs::allTypes() const |
153 | { | 155 | { |
154 | QStringList list; | 156 | QStringList list; |
155 | for (int i = 0; types[i] != 0; ++i) | 157 | for (int i = 0; types[i] != 0; ++i) |
156 | list.append(QString::fromLatin1(types[i])); | 158 | list.append(QString::fromLatin1(types[i])); |
157 | return list; | 159 | return list; |
158 | } | 160 | } |
159 | 161 | ||
160 | void KStandardDirs::addPrefix( const QString& _dir ) | 162 | void KStandardDirs::addPrefix( const QString& _dir ) |
161 | { | 163 | { |
162 | if (_dir.isNull()) | 164 | if (_dir.isNull()) |
163 | return; | 165 | return; |
164 | 166 | ||
165 | QString dir = _dir; | 167 | QString dir = _dir; |
166 | if (dir.at(dir.length() - 1) != '/') | 168 | if (dir.at(dir.length() - 1) != '/') |
167 | dir += '/'; | 169 | dir += '/'; |
168 | 170 | ||
169 | if (!prefixes.contains(dir)) { | 171 | if (!prefixes.contains(dir)) { |
170 | prefixes.append(dir); | 172 | prefixes.append(dir); |
171 | dircache.clear(); | 173 | dircache.clear(); |
172 | } | 174 | } |
173 | } | 175 | } |
174 | 176 | ||
175 | void KStandardDirs::addXdgConfigPrefix( const QString& _dir ) | 177 | void KStandardDirs::addXdgConfigPrefix( const QString& _dir ) |
176 | { | 178 | { |
177 | if (_dir.isNull()) | 179 | if (_dir.isNull()) |
178 | return; | 180 | return; |
179 | 181 | ||
180 | QString dir = _dir; | 182 | QString dir = _dir; |
181 | if (dir.at(dir.length() - 1) != '/') | 183 | if (dir.at(dir.length() - 1) != '/') |
182 | dir += '/'; | 184 | dir += '/'; |
183 | 185 | ||
184 | if (!d->xdgconf_prefixes.contains(dir)) { | 186 | if (!d->xdgconf_prefixes.contains(dir)) { |
@@ -352,230 +354,230 @@ QString KStandardDirs::findResourceDir( const char *type, | |||
352 | applyDataRestrictions(filename); | 354 | applyDataRestrictions(filename); |
353 | QStringList candidates = resourceDirs(type); | 355 | QStringList candidates = resourceDirs(type); |
354 | QString fullPath; | 356 | QString fullPath; |
355 | #ifdef DESKTOP_VERSION | 357 | #ifdef DESKTOP_VERSION |
356 | #ifdef _WIN32_ | 358 | #ifdef _WIN32_ |
357 | candidates.prepend( qApp->applicationDirPath () +"\\"); | 359 | candidates.prepend( qApp->applicationDirPath () +"\\"); |
358 | #else | 360 | #else |
359 | candidates.prepend( qApp->applicationDirPath () +"/"); | 361 | candidates.prepend( qApp->applicationDirPath () +"/"); |
360 | #endif | 362 | #endif |
361 | #endif | 363 | #endif |
362 | for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++) | 364 | for (QStringList::ConstIterator it = candidates.begin(); it != candidates.end(); it++) |
363 | { | 365 | { |
364 | //qDebug("looking for dir %s - file %s", (*it).latin1(), filename.latin1()); | 366 | //qDebug("looking for dir %s - file %s", (*it).latin1(), filename.latin1()); |
365 | if (exists(*it + filename)) | 367 | if (exists(*it + filename)) |
366 | return *it; | 368 | return *it; |
367 | } | 369 | } |
368 | 370 | ||
369 | #ifndef NDEBUG | 371 | #ifndef NDEBUG |
370 | if(false && type != "locale") | 372 | if(false && type != "locale") |
371 | qDebug("KStdDirs::findResDir(): can't find %s ", filename.latin1()); | 373 | qDebug("KStdDirs::findResDir(): can't find %s ", filename.latin1()); |
372 | 374 | ||
373 | #endif | 375 | #endif |
374 | 376 | ||
375 | return QString::null; | 377 | return QString::null; |
376 | } | 378 | } |
377 | 379 | ||
378 | bool KStandardDirs::exists(const QString &fullPath) | 380 | bool KStandardDirs::exists(const QString &fullPath) |
379 | { | 381 | { |
380 | //US struct stat buff; | 382 | //US struct stat buff; |
381 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); | 383 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); |
382 | 384 | ||
383 | //US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable()) | 385 | //US if (access(QFile::encodeName(fullPath), R_OK) == 0 && fullPathInfo.isReadable()) |
384 | if (fullPathInfo.isReadable()) | 386 | if (fullPathInfo.isReadable()) |
385 | { | 387 | { |
386 | if (fullPath.at(fullPath.length() - 1) != '/') { | 388 | if (fullPath.at(fullPath.length() - 1) != '/') { |
387 | //US if (S_ISREG( buff.st_mode )) | 389 | //US if (S_ISREG( buff.st_mode )) |
388 | if (fullPathInfo.isFile()) | 390 | if (fullPathInfo.isFile()) |
389 | return true; | 391 | return true; |
390 | } | 392 | } |
391 | else { | 393 | else { |
392 | //US if (S_ISDIR( buff.st_mode )) | 394 | //US if (S_ISDIR( buff.st_mode )) |
393 | if (fullPathInfo.isDir()) | 395 | if (fullPathInfo.isDir()) |
394 | return true; | 396 | return true; |
395 | } | 397 | } |
396 | } | 398 | } |
397 | return false; | 399 | return false; |
398 | } | 400 | } |
399 | 401 | ||
400 | static void lookupDirectory(const QString& path, const QString &relPart, | 402 | static void lookupDirectory(const QString& path, const QString &relPart, |
401 | const QRegExp ®exp, | 403 | const QRegExp ®exp, |
402 | QStringList& list, | 404 | QStringList& list, |
403 | QStringList& relList, | 405 | QStringList& relList, |
404 | bool recursive, bool uniq) | 406 | bool recursive, bool uniq) |
405 | { | 407 | { |
406 | QString pattern = regexp.pattern(); | 408 | QString pattern = regexp.pattern(); |
407 | if (recursive || pattern.contains('?') || pattern.contains('*')) | 409 | if (recursive || pattern.contains('?') || pattern.contains('*')) |
408 | { | 410 | { |
409 | // We look for a set of files. | 411 | // We look for a set of files. |
410 | //US DIR *dp = opendir( QFile::encodeName(path)); | 412 | //US DIR *dp = opendir( QFile::encodeName(path)); |
411 | QDir dp(QFile::encodeName(path)); | 413 | QDir dp(QFile::encodeName(path)); |
412 | 414 | ||
413 | if (!dp.exists()) | 415 | if (!dp.exists()) |
414 | return; | 416 | return; |
415 | static int iii = 0; | 417 | static int iii = 0; |
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 | { |
518 | if (!uniq || !relList.contains(relPart + fn)) | 520 | if (!uniq || !relList.contains(relPart + fn)) |
519 | { | 521 | { |
520 | list.append( pathfn ); | 522 | list.append( pathfn ); |
521 | relList.append( relPart + fn ); | 523 | relList.append( relPart + fn ); |
522 | } | 524 | } |
523 | } | 525 | } |
524 | } | 526 | } |
525 | } | 527 | } |
526 | 528 | ||
527 | static void lookupPrefix(const QString& prefix, const QString& relpath, | 529 | static void lookupPrefix(const QString& prefix, const QString& relpath, |
528 | const QString& relPart, | 530 | const QString& relPart, |
529 | const QRegExp ®exp, | 531 | const QRegExp ®exp, |
530 | QStringList& list, | 532 | QStringList& list, |
531 | QStringList& relList, | 533 | QStringList& relList, |
532 | bool recursive, bool uniq) | 534 | bool recursive, bool uniq) |
533 | { | 535 | { |
534 | if (relpath.isNull()) { | 536 | if (relpath.isNull()) { |
535 | lookupDirectory(prefix, relPart, regexp, list, | 537 | lookupDirectory(prefix, relPart, regexp, list, |
536 | relList, recursive, uniq); | 538 | relList, recursive, uniq); |
537 | return; | 539 | return; |
538 | } | 540 | } |
539 | QString path; | 541 | QString path; |
540 | QString rest; | 542 | QString rest; |
541 | 543 | ||
542 | if (relpath.length()) | 544 | if (relpath.length()) |
543 | { | 545 | { |
544 | int slash = relpath.find('/'); | 546 | int slash = relpath.find('/'); |
545 | if (slash < 0) | 547 | if (slash < 0) |
546 | rest = relpath.left(relpath.length() - 1); | 548 | rest = relpath.left(relpath.length() - 1); |
547 | else { | 549 | else { |
548 | path = relpath.left(slash); | 550 | path = relpath.left(slash); |
549 | rest = relpath.mid(slash + 1); | 551 | rest = relpath.mid(slash + 1); |
550 | } | 552 | } |
551 | } | 553 | } |
552 | assert(prefix.at(prefix.length() - 1) == '/'); | 554 | assert(prefix.at(prefix.length() - 1) == '/'); |
553 | 555 | ||
554 | //US struct stat buff; | 556 | //US struct stat buff; |
555 | 557 | ||
556 | if (path.contains('*') || path.contains('?')) { | 558 | if (path.contains('*') || path.contains('?')) { |
557 | QRegExp pathExp(path, true, true); | 559 | QRegExp pathExp(path, true, true); |
558 | //USDIR *dp = opendir( QFile::encodeName(prefix) ); | 560 | //USDIR *dp = opendir( QFile::encodeName(prefix) ); |
559 | QDir dp(QFile::encodeName(prefix)); | 561 | QDir dp(QFile::encodeName(prefix)); |
560 | 562 | ||
561 | //USif (!dp) | 563 | //USif (!dp) |
562 | if (!dp.exists()) | 564 | if (!dp.exists()) |
563 | { | 565 | { |
564 | return; | 566 | return; |
565 | } | 567 | } |
566 | 568 | ||
567 | //USstruct dirent *ep; | 569 | //USstruct dirent *ep; |
568 | 570 | ||
569 | QString _dot("."); | 571 | QString _dot("."); |
570 | QString _dotdot(".."); | 572 | QString _dotdot(".."); |
571 | 573 | ||
572 | //USwhile( ( ep = readdir( dp ) ) != 0L ) | 574 | //USwhile( ( ep = readdir( dp ) ) != 0L ) |
573 | QStringList direntries = dp.entryList(); | 575 | QStringList direntries = dp.entryList(); |
574 | QStringList::Iterator it = direntries.begin(); | 576 | QStringList::Iterator it = direntries.begin(); |
575 | 577 | ||
576 | while ( it != list.end() ) // for each file... | 578 | while ( it != list.end() ) // for each file... |
577 | { | 579 | { |
578 | //US QString fn( QFile::decodeName(ep->d_name)); | 580 | //US QString fn( QFile::decodeName(ep->d_name)); |
579 | QString fn = (*it); // dp.entryList() already encodes the strings | 581 | QString fn = (*it); // dp.entryList() already encodes the strings |
580 | it++; | 582 | it++; |
581 | 583 | ||
@@ -1015,293 +1017,293 @@ QString KStandardDirs::saveLocation(const char *type, | |||
1015 | (strcmp(type, "tmp") == 0) || | 1017 | (strcmp(type, "tmp") == 0) || |
1016 | (strcmp(type, "cache") == 0) )) | 1018 | (strcmp(type, "cache") == 0) )) |
1017 | { | 1019 | { |
1018 | (void) resourceDirs(type); // Generate socket|tmp|cache resource. | 1020 | (void) resourceDirs(type); // Generate socket|tmp|cache resource. |
1019 | dirs = relatives.find(type); // Search again. | 1021 | dirs = relatives.find(type); // Search again. |
1020 | } | 1022 | } |
1021 | if (dirs) | 1023 | if (dirs) |
1022 | { | 1024 | { |
1023 | // Check for existance of typed directory + suffix | 1025 | // Check for existance of typed directory + suffix |
1024 | if (strncmp(type, "xdgdata-", 8) == 0) | 1026 | if (strncmp(type, "xdgdata-", 8) == 0) |
1025 | pPath = new QString(realPath(localxdgdatadir() + dirs->last())); | 1027 | pPath = new QString(realPath(localxdgdatadir() + dirs->last())); |
1026 | else if (strncmp(type, "xdgconf-", 8) == 0) | 1028 | else if (strncmp(type, "xdgconf-", 8) == 0) |
1027 | pPath = new QString(realPath(localxdgconfdir() + dirs->last())); | 1029 | pPath = new QString(realPath(localxdgconfdir() + dirs->last())); |
1028 | else | 1030 | else |
1029 | pPath = new QString(realPath(localkdedir() + dirs->last())); | 1031 | pPath = new QString(realPath(localkdedir() + dirs->last())); |
1030 | } | 1032 | } |
1031 | else { | 1033 | else { |
1032 | dirs = absolutes.find(type); | 1034 | dirs = absolutes.find(type); |
1033 | if (!dirs) | 1035 | if (!dirs) |
1034 | qFatal("KStandardDirs: The resource type %s is not registered", type); | 1036 | qFatal("KStandardDirs: The resource type %s is not registered", type); |
1035 | pPath = new QString(realPath(dirs->last())); | 1037 | pPath = new QString(realPath(dirs->last())); |
1036 | } | 1038 | } |
1037 | 1039 | ||
1038 | savelocations.insert(type, pPath); | 1040 | savelocations.insert(type, pPath); |
1039 | } | 1041 | } |
1040 | 1042 | ||
1041 | QString fullPath = *pPath + suffix; | 1043 | QString fullPath = *pPath + suffix; |
1042 | //US struct stat st; | 1044 | //US struct stat st; |
1043 | //US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode))) | 1045 | //US if (stat(QFile::encodeName(fullPath), &st) != 0 || !(S_ISDIR(st.st_mode))) |
1044 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); | 1046 | QFileInfo fullPathInfo(QFile::encodeName(fullPath)); |
1045 | if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) | 1047 | if (fullPathInfo.isReadable() || !fullPathInfo.isDir()) |
1046 | 1048 | ||
1047 | 1049 | ||
1048 | { | 1050 | { |
1049 | if(!create) { | 1051 | if(!create) { |
1050 | #ifndef NDEBUG | 1052 | #ifndef NDEBUG |
1051 | qDebug("save location %s doesn't exist", fullPath.latin1()); | 1053 | qDebug("save location %s doesn't exist", fullPath.latin1()); |
1052 | #endif | 1054 | #endif |
1053 | return fullPath; | 1055 | return fullPath; |
1054 | } | 1056 | } |
1055 | if(!makeDir(fullPath, 0700)) { | 1057 | if(!makeDir(fullPath, 0700)) { |
1056 | qWarning("failed to create %s", fullPath.latin1()); | 1058 | qWarning("failed to create %s", fullPath.latin1()); |
1057 | return fullPath; | 1059 | return fullPath; |
1058 | } | 1060 | } |
1059 | dircache.remove(type); | 1061 | dircache.remove(type); |
1060 | } | 1062 | } |
1061 | return fullPath; | 1063 | return fullPath; |
1062 | } | 1064 | } |
1063 | 1065 | ||
1064 | QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) | 1066 | QString KStandardDirs::relativeLocation(const char *type, const QString &absPath) |
1065 | { | 1067 | { |
1066 | QString fullPath = absPath; | 1068 | QString fullPath = absPath; |
1067 | int i = absPath.findRev('/'); | 1069 | int i = absPath.findRev('/'); |
1068 | if (i != -1) | 1070 | if (i != -1) |
1069 | { | 1071 | { |
1070 | fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize | 1072 | fullPath = realPath(absPath.left(i+1))+absPath.mid(i+1); // Normalize |
1071 | } | 1073 | } |
1072 | 1074 | ||
1073 | QStringList candidates = resourceDirs(type); | 1075 | QStringList candidates = resourceDirs(type); |
1074 | 1076 | ||
1075 | for (QStringList::ConstIterator it = candidates.begin(); | 1077 | for (QStringList::ConstIterator it = candidates.begin(); |
1076 | it != candidates.end(); it++) | 1078 | it != candidates.end(); it++) |
1077 | if (fullPath.startsWith(*it)) | 1079 | if (fullPath.startsWith(*it)) |
1078 | { | 1080 | { |
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 |
1144 | #ifndef _WIN32_ | 1146 | #ifndef _WIN32_ |
1145 | if (dir.at(0) != '/') | 1147 | if (dir.at(0) != '/') |
1146 | return false; | 1148 | return false; |
1147 | #endif | 1149 | #endif |
1148 | 1150 | ||
1149 | QString target = dir; | 1151 | QString target = dir; |
1150 | uint len = target.length(); | 1152 | uint len = target.length(); |
1151 | #ifndef _WIN32_ | 1153 | #ifndef _WIN32_ |
1152 | // append trailing slash if missing | 1154 | // append trailing slash if missing |
1153 | if (dir.at(len - 1) != '/') | 1155 | if (dir.at(len - 1) != '/') |
1154 | target += '/'; | 1156 | target += '/'; |
1155 | #endif | 1157 | #endif |
1156 | 1158 | ||
1157 | QString base(""); | 1159 | QString base(""); |
1158 | uint i = 1; | 1160 | uint i = 1; |
1159 | 1161 | ||
1160 | while( i < len ) | 1162 | while( i < len ) |
1161 | { | 1163 | { |
1162 | //US struct stat st; | 1164 | //US struct stat st; |
1163 | #ifndef _WIN32_ | 1165 | #ifndef _WIN32_ |
1164 | int pos = target.find('/', i); | 1166 | int pos = target.find('/', i); |
1165 | #else | 1167 | #else |
1166 | int pos = target.find('\\', i); | 1168 | int pos = target.find('\\', i); |
1167 | #endif | 1169 | #endif |
1168 | if ( pos < 0 ) | 1170 | if ( pos < 0 ) |
1169 | return true; | 1171 | return true; |
1170 | base += target.mid(i - 1, pos - i + 1); | 1172 | base += target.mid(i - 1, pos - i + 1); |
1171 | //QMessageBox::information( 0,"cap111", base, 1 ); | 1173 | //QMessageBox::information( 0,"cap111", base, 1 ); |
1172 | /*US | 1174 | /*US |
1173 | QCString baseEncoded = QFile::encodeName(base); | 1175 | QCString baseEncoded = QFile::encodeName(base); |
1174 | // bail out if we encountered a problem | 1176 | // bail out if we encountered a problem |
1175 | if (stat(baseEncoded, &st) != 0) | 1177 | if (stat(baseEncoded, &st) != 0) |
1176 | { | 1178 | { |
1177 | // Directory does not exist.... | 1179 | // Directory does not exist.... |
1178 | // Or maybe a dangling symlink ? | 1180 | // Or maybe a dangling symlink ? |
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); |
1244 | //US for embedded, add qtopia dir as kdedir | 1246 | //US for embedded, add qtopia dir as kdedir |
1245 | 1247 | ||
1246 | #ifndef DESKTOP_VERSION | 1248 | #ifndef DESKTOP_VERSION |
1247 | QString tmp = readEnvPath("QPEDIR"); | 1249 | QString tmp = readEnvPath("QPEDIR"); |
1248 | if (!tmp.isEmpty()) | 1250 | if (!tmp.isEmpty()) |
1249 | kdedirList.append(tmp); | 1251 | kdedirList.append(tmp); |
1250 | 1252 | ||
1251 | tmp = readEnvPath("QTDIR"); | 1253 | tmp = readEnvPath("QTDIR"); |
1252 | if (!tmp.isEmpty()) | 1254 | if (!tmp.isEmpty()) |
1253 | kdedirList.append(tmp); | 1255 | kdedirList.append(tmp); |
1254 | 1256 | ||
1255 | tmp = readEnvPath("OPIEDIR"); | 1257 | tmp = readEnvPath("OPIEDIR"); |
1256 | if (!tmp.isEmpty()) | 1258 | if (!tmp.isEmpty()) |
1257 | kdedirList.append(tmp); | 1259 | kdedirList.append(tmp); |
1258 | 1260 | ||
1259 | #endif | 1261 | #endif |
1260 | 1262 | ||
1261 | #ifdef __KDE_EXECPREFIX | 1263 | #ifdef __KDE_EXECPREFIX |
1262 | QString execPrefix(__KDE_EXECPREFIX); | 1264 | QString execPrefix(__KDE_EXECPREFIX); |
1263 | if (execPrefix!="NONE") | 1265 | if (execPrefix!="NONE") |
1264 | kdedirList.append(execPrefix); | 1266 | kdedirList.append(execPrefix); |
1265 | #endif | 1267 | #endif |
1266 | 1268 | ||
1267 | QString localKdeDir; | 1269 | QString localKdeDir; |
1268 | 1270 | ||
1269 | //US if (getuid()) | 1271 | //US if (getuid()) |
1270 | if (true) | 1272 | if (true) |
1271 | { | 1273 | { |
1272 | localKdeDir = readEnvPath("MICROKDEHOME"); | 1274 | localKdeDir = readEnvPath("MICROKDEHOME"); |
1273 | if (!localKdeDir.isEmpty()) | 1275 | if (!localKdeDir.isEmpty()) |
1274 | { | 1276 | { |
1275 | #ifdef _WIN32_ | 1277 | #ifdef _WIN32_ |
1276 | if (localKdeDir.at(localKdeDir.length()-1) != '\\') | 1278 | if (localKdeDir.at(localKdeDir.length()-1) != '\\') |
1277 | localKdeDir += '\\'; | 1279 | localKdeDir += '\\'; |
1278 | #else | 1280 | #else |
1279 | if (localKdeDir.at(localKdeDir.length()-1) != '/') | 1281 | if (localKdeDir.at(localKdeDir.length()-1) != '/') |
1280 | localKdeDir += '/'; | 1282 | localKdeDir += '/'; |
1281 | #endif | 1283 | #endif |
1282 | //QMessageBox::information( 0,"localKdeDir",localKdeDir, 1 ); | 1284 | //QMessageBox::information( 0,"localKdeDir",localKdeDir, 1 ); |
1283 | } | 1285 | } |
1284 | else | 1286 | else |
1285 | { | 1287 | { |
1286 | QString confFile; | 1288 | QString confFile; |
1287 | #ifdef DESKTOP_VERSION | 1289 | #ifdef DESKTOP_VERSION |
1288 | confFile = qApp->applicationDirPath ()+ "/.microkdehome" ; | 1290 | confFile = qApp->applicationDirPath ()+ "/.microkdehome" ; |
1289 | QFileInfo fi ( confFile ); | 1291 | QFileInfo fi ( confFile ); |
1290 | if ( !fi.exists() ) | 1292 | if ( !fi.exists() ) |
1291 | confFile = QDir::homeDirPath() + "/.microkdehome"; | 1293 | confFile = QDir::homeDirPath() + "/.microkdehome"; |
1292 | else | 1294 | else |
1293 | qDebug("Loading path info from " + confFile ); | 1295 | qDebug("Loading path info from " + confFile ); |
1294 | 1296 | ||
1295 | #else | 1297 | #else |
1296 | confFile = QDir::homeDirPath() + "/.microkdehome"; | 1298 | confFile = QDir::homeDirPath() + "/.microkdehome"; |
1297 | #endif | 1299 | #endif |
1298 | KConfig cfg ( confFile ); | 1300 | KConfig cfg ( confFile ); |
1299 | cfg.setGroup("Global"); | 1301 | cfg.setGroup("Global"); |
1300 | localKdeDir = cfg.readEntry( "MICROKDEHOME", QDir::homeDirPath() + "/kdepim/" ); | 1302 | localKdeDir = cfg.readEntry( "MICROKDEHOME", QDir::homeDirPath() + "/kdepim/" ); |
1301 | #ifdef DESKTOP_VERSION | 1303 | #ifdef DESKTOP_VERSION |
1302 | if ( localKdeDir.startsWith( "LOCAL:" ) ) { | 1304 | if ( localKdeDir.startsWith( "LOCAL:" ) ) { |
1303 | #ifdef _WIN32_ | 1305 | #ifdef _WIN32_ |
1304 | localKdeDir = qApp->applicationDirPath () + "\\"+ localKdeDir.mid( 6 ); | 1306 | localKdeDir = qApp->applicationDirPath () + "\\"+ localKdeDir.mid( 6 ); |
1305 | #else | 1307 | #else |
1306 | localKdeDir = qApp->applicationDirPath () + "/"+ localKdeDir.mid( 6 ); | 1308 | localKdeDir = qApp->applicationDirPath () + "/"+ localKdeDir.mid( 6 ); |
1307 | #endif | 1309 | #endif |
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,123 +1,123 @@ | |||
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 |
60 | * defined suffixes where specific resource types are to be found. | 60 | * defined suffixes where specific resource types are to be found. |
61 | * For example, for the resource type "html" the suffixes could be | 61 | * For example, for the resource type "html" the suffixes could be |
62 | * share/doc/HTML and share/doc/kde/HTML. | 62 | * share/doc/HTML and share/doc/kde/HTML. |
63 | * So the search algorithm basicly appends to each prefix each registered | 63 | * So the search algorithm basicly appends to each prefix each registered |
64 | * suffix and tries to locate the file there. | 64 | * suffix and tries to locate the file there. |
65 | * To make the thing even more complex, it's also possible to register | 65 | * To make the thing even more complex, it's also possible to register |
66 | * absolute paths that KStandardDirs looks up after not finding anything | 66 | * absolute paths that KStandardDirs looks up after not finding anything |
67 | * in the former steps. They can be useful if the user wants to provide | 67 | * in the former steps. They can be useful if the user wants to provide |
68 | * specific directories that aren't in his $HOME/.kde directory for, | 68 | * specific directories that aren't in his $HOME/.kde directory for, |
69 | * for example, icons. | 69 | * for example, icons. |
70 | * | 70 | * |
71 | * @sect Standard resources that kdelibs allocates are: | 71 | * @sect Standard resources that kdelibs allocates are: |
72 | * | 72 | * |
73 | * @li apps - Applications menu (.desktop files). | 73 | * @li apps - Applications menu (.desktop files). |
74 | * @li cache - Cached information (e.g. favicons, web-pages) | 74 | * @li cache - Cached information (e.g. favicons, web-pages) |
75 | * @li cgi - CGIs to run from kdehelp. | 75 | * @li cgi - CGIs to run from kdehelp. |
76 | * @li config - Configuration files. | 76 | * @li config - Configuration files. |
77 | * @li data - Where applications store data. | 77 | * @li data - Where applications store data. |
78 | * @li exe - Executables in $prefix/bin. @ref findExe() for a function that takes $PATH into account. | 78 | * @li exe - Executables in $prefix/bin. @ref findExe() for a function that takes $PATH into account. |
79 | * @li html - HTML documentation. | 79 | * @li html - HTML documentation. |
80 | * @li icon - Icons, see @ref KIconLoader. | 80 | * @li icon - Icons, see @ref KIconLoader. |
81 | * @li lib - Libraries. | 81 | * @li lib - Libraries. |
82 | * @li locale - Translation files for @ref KLocale. | 82 | * @li locale - Translation files for @ref KLocale. |
83 | * @li mime - Mime types. | 83 | * @li mime - Mime types. |
84 | * @li module - Module (dynamically loaded library). | 84 | * @li module - Module (dynamically loaded library). |
85 | * @li qtplugins - Qt plugins (dynamically loaded objects for Qt) | 85 | * @li qtplugins - Qt plugins (dynamically loaded objects for Qt) |
86 | * @li services - Services. | 86 | * @li services - Services. |
87 | * @li servicetypes - Service types. | 87 | * @li servicetypes - Service types. |
88 | * @li scripts - Application scripting additions. | 88 | * @li scripts - Application scripting additions. |
89 | * @li sound - Application sounds. | 89 | * @li sound - Application sounds. |
90 | * @li templates - Templates | 90 | * @li templates - Templates |
91 | * @li wallpaper - Wallpapers. | 91 | * @li wallpaper - Wallpapers. |
92 | * @li tmp - Temporary files (specfic for both current host and current user) | 92 | * @li tmp - Temporary files (specfic for both current host and current user) |
93 | * @li socket - UNIX Sockets (specific for both current host and current user) | 93 | * @li socket - UNIX Sockets (specific for both current host and current user) |
94 | * | 94 | * |
95 | * A type that is added by the class @ref KApplication if you use it, is | 95 | * A type that is added by the class @ref KApplication if you use it, is |
96 | * appdata. This one makes the use of the type data a bit easier as it | 96 | * appdata. This one makes the use of the type data a bit easier as it |
97 | * appends the name of the application. | 97 | * appends the name of the application. |
98 | * So while you had to ::locate("data", "appname/filename") so you can | 98 | * So while you had to ::locate("data", "appname/filename") so you can |
99 | * also write ::locate("appdata", "filename") if your KApplication instance | 99 | * also write ::locate("appdata", "filename") if your KApplication instance |
100 | * is called "appname" (as set via KApplication's constructor or KAboutData, if | 100 | * is called "appname" (as set via KApplication's constructor or KAboutData, if |
101 | * you use the global KStandardDirs object @ref KGlobal::dirs()). | 101 | * you use the global KStandardDirs object @ref KGlobal::dirs()). |
102 | * Please note though that you cannot use the "appdata" | 102 | * Please note though that you cannot use the "appdata" |
103 | * type if you intend to use it in an applet for Kicker because 'appname' would | 103 | * type if you intend to use it in an applet for Kicker because 'appname' would |
104 | * be "Kicker" instead of the applet's name. Therefore, for applets, you've got | 104 | * be "Kicker" instead of the applet's name. Therefore, for applets, you've got |
105 | * to work around this by using ::locate("data", "appletname/filename"). | 105 | * to work around this by using ::locate("data", "appletname/filename"). |
106 | * | 106 | * |
107 | * @sect KStandardDirs supports the following environment variables: | 107 | * @sect KStandardDirs supports the following environment variables: |
108 | * | 108 | * |
109 | * @li KDEDIRS: This may set an additional number of directory prefixes to | 109 | * @li KDEDIRS: This may set an additional number of directory prefixes to |
110 | * search for resources. The directories should be seperated | 110 | * search for resources. The directories should be seperated |
111 | * by ':'. The directories are searched in the order they are | 111 | * by ':'. The directories are searched in the order they are |
112 | * specified. | 112 | * specified. |
113 | * @li KDEDIR: Used for backwards compatibility. As KDEDIRS but only a single | 113 | * @li KDEDIR: Used for backwards compatibility. As KDEDIRS but only a single |
114 | * directory may be specified. If KDEDIRS is set KDEDIR is | 114 | * directory may be specified. If KDEDIRS is set KDEDIR is |
115 | * ignored. | 115 | * ignored. |
116 | * @li KDEHOME: The directory where changes are saved to. This directory is | 116 | * @li KDEHOME: The directory where changes are saved to. This directory is |
117 | * used to search for resources first. If KDEHOME is not | 117 | * used to search for resources first. If KDEHOME is not |
118 | * specified it defaults to "$HOME/.kde" | 118 | * specified it defaults to "$HOME/.kde" |
119 | * @li KDEROOTHOME: Like KDEHOME, but used for the root user. | 119 | * @li KDEROOTHOME: Like KDEHOME, but used for the root user. |
120 | * If KDEROOTHOME is not set it defaults to the .kde directory in the | 120 | * If KDEROOTHOME is not set it defaults to the .kde directory in the |
121 | * home directory of root, usually "/root/.kde". | 121 | * home directory of root, usually "/root/.kde". |
122 | * Note that the setting of $HOME is ignored in this case. | 122 | * Note that the setting of $HOME is ignored in this case. |
123 | * | 123 | * |
@@ -481,197 +481,197 @@ public: | |||
481 | * will be returned unchanged. | 481 | * will be returned unchanged. |
482 | */ | 482 | */ |
483 | QString relativeLocation(const char *type, const QString &absPath); | 483 | QString relativeLocation(const char *type, const QString &absPath); |
484 | 484 | ||
485 | /** | 485 | /** |
486 | * Recursively creates still-missing directories in the given path. | 486 | * Recursively creates still-missing directories in the given path. |
487 | * | 487 | * |
488 | * The resulting permissions will depend on the current umask setting. | 488 | * The resulting permissions will depend on the current umask setting. |
489 | * permission = mode & ~umask. | 489 | * permission = mode & ~umask. |
490 | * | 490 | * |
491 | * @param dir Absolute path of the directory to be made. | 491 | * @param dir Absolute path of the directory to be made. |
492 | * @param mode Directory permissions. | 492 | * @param mode Directory permissions. |
493 | * @return true if successful, false otherwise | 493 | * @return true if successful, false otherwise |
494 | */ | 494 | */ |
495 | static bool makeDir(const QString& dir, int mode = 0755); | 495 | static bool makeDir(const QString& dir, int mode = 0755); |
496 | 496 | ||
497 | /** | 497 | /** |
498 | * This returns a default relative path for the standard KDE | 498 | * This returns a default relative path for the standard KDE |
499 | * resource types. Below is a list of them so you get an idea | 499 | * resource types. Below is a list of them so you get an idea |
500 | * of what this is all about. | 500 | * of what this is all about. |
501 | * | 501 | * |
502 | * @li data - share/apps | 502 | * @li data - share/apps |
503 | * @li html - share/doc/HTML | 503 | * @li html - share/doc/HTML |
504 | * @li icon - share/icon | 504 | * @li icon - share/icon |
505 | * @li config - share/config | 505 | * @li config - share/config |
506 | * @li pixmap - share/pixmaps | 506 | * @li pixmap - share/pixmaps |
507 | * @li apps - share/applnk | 507 | * @li apps - share/applnk |
508 | * @li sound - share/sounds | 508 | * @li sound - share/sounds |
509 | * @li locale - share/locale | 509 | * @li locale - share/locale |
510 | * @li services - share/services | 510 | * @li services - share/services |
511 | * @li servicetypes - share/servicetypes | 511 | * @li servicetypes - share/servicetypes |
512 | * @li mime - share/mimelnk | 512 | * @li mime - share/mimelnk |
513 | * @li wallpaper - share/wallpapers | 513 | * @li wallpaper - share/wallpapers |
514 | * @li templates - share/templates | 514 | * @li templates - share/templates |
515 | * @li exe - bin | 515 | * @li exe - bin |
516 | * @li lib - lib | 516 | * @li lib - lib |
517 | * | 517 | * |
518 | * @returns Static default for the specified resource. You | 518 | * @returns Static default for the specified resource. You |
519 | * should probably be using locate() or locateLocal() | 519 | * should probably be using locate() or locateLocal() |
520 | * instead. | 520 | * instead. |
521 | * @see locate() | 521 | * @see locate() |
522 | * @see locateLocal() | 522 | * @see locateLocal() |
523 | */ | 523 | */ |
524 | static QString kde_default(const char *type); | 524 | static QString kde_default(const char *type); |
525 | 525 | ||
526 | /** | 526 | /** |
527 | * @internal (for use by sycoca only) | 527 | * @internal (for use by sycoca only) |
528 | */ | 528 | */ |
529 | QString kfsstnd_prefixes(); | 529 | QString kfsstnd_prefixes(); |
530 | 530 | ||
531 | /** | 531 | /** |
532 | * Returns the toplevel directory in which KStandardDirs | 532 | * Returns the toplevel directory in which KStandardDirs |
533 | * will store things. Most likely $HOME/.kde | 533 | * will store things. Most likely $HOME/.kde |
534 | * Don't use this function if you can use locateLocal | 534 | * Don't use this function if you can use locateLocal |
535 | * @return the toplevel directory | 535 | * @return the toplevel directory |
536 | */ | 536 | */ |
537 | QString localkdedir() const; | 537 | QString localkdedir() const; |
538 | 538 | ||
539 | /** | 539 | /** |
540 | * @return $XDG_DATA_HOME | 540 | * @return $XDG_DATA_HOME |
541 | * See also http://www.freedesktop.org/standards/basedir/draft/basedir-spec/basedir-spec.html | 541 | * See also http://www.freedesktop.org/standards/basedir/draft/basedir-spec/basedir-spec.html |
542 | */ | 542 | */ |
543 | QString localxdgdatadir() const; | 543 | QString localxdgdatadir() const; |
544 | 544 | ||
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"); |
614 | * myData = myReadGroups(myFile); // myFile may be null | 614 | * myData = myReadGroups(myFile); // myFile may be null |
615 | * \endcode | 615 | * \endcode |
616 | * | 616 | * |
617 | * 2) A resource file is read and written. If the user has no | 617 | * 2) A resource file is read and written. If the user has no |
618 | * local version of the file the system default is used. | 618 | * local version of the file the system default is used. |
619 | * The resource file is always written to the users local | 619 | * The resource file is always written to the users local |
620 | * .kde directory. | 620 | * .kde directory. |
621 | * | 621 | * |
622 | * \code | 622 | * \code |
623 | * // Code example | 623 | * // Code example |
624 | * myFile = locate("appdata", "groups.lst") | 624 | * myFile = locate("appdata", "groups.lst") |
625 | * myData = myReadGroups(myFile); | 625 | * myData = myReadGroups(myFile); |
626 | * ... | 626 | * ... |
627 | * doSomething(myData); | 627 | * doSomething(myData); |
628 | * ... | 628 | * ... |
629 | * myFile = locateLocal("appdata", "groups.lst"); | 629 | * myFile = locateLocal("appdata", "groups.lst"); |
630 | * myWriteGroups(myFile, myData); | 630 | * myWriteGroups(myFile, myData); |
631 | * \endcode | 631 | * \endcode |
632 | * | 632 | * |
633 | * 3) A resource file is read and written. No system default | 633 | * 3) A resource file is read and written. No system default |
634 | * is used if the user has no local version of the file. | 634 | * is used if the user has no local version of the file. |
635 | * The resource file is always written to the users local | 635 | * The resource file is always written to the users local |
636 | * .kde directory. | 636 | * .kde directory. |
637 | * | 637 | * |
638 | * \code | 638 | * \code |
639 | * // Code example | 639 | * // Code example |
640 | * myFile = locateLocal("appdata", "groups.lst"); | 640 | * myFile = locateLocal("appdata", "groups.lst"); |
641 | * myData = myReadGroups(myFile); | 641 | * myData = myReadGroups(myFile); |
642 | * ... | 642 | * ... |
643 | * doSomething(myData); | 643 | * doSomething(myData); |
644 | * ... | 644 | * ... |
645 | * myFile = locateLocal("appdata", "groups.lst"); | 645 | * myFile = locateLocal("appdata", "groups.lst"); |
646 | * myWriteGroups(myFile, myData); | 646 | * myWriteGroups(myFile, myData); |
647 | * \endcode | 647 | * \endcode |
648 | **/ | 648 | **/ |
649 | 649 | ||
650 | 650 | ||
651 | /*! | 651 | /*! |
652 | * \relates KStandardDirs | 652 | * \relates KStandardDirs |
653 | * This function is just for convenience. It simply calls | 653 | * This function is just for convenience. It simply calls |
654 | *instance->dirs()->\link KStandardDirs::findResource() findResource\endlink(type, filename). | 654 | *instance->dirs()->\link KStandardDirs::findResource() findResource\endlink(type, filename). |
655 | **/ | 655 | **/ |
656 | QString locate( const char *type, const QString& filename /*US , const KInstance* instance = KGlobal::instance()*/ ); | 656 | QString locate( const char *type, const QString& filename /*US , const KInstance* instance = KGlobal::instance()*/ ); |
657 | 657 | ||
658 | /*! | 658 | /*! |
659 | * \relates KStandardDirs | 659 | * \relates KStandardDirs |
660 | * This function is much like locate. However it returns a | 660 | * This function is much like locate. However it returns a |
661 | * filename suitable for writing to. No check is made if the | 661 | * filename suitable for writing to. No check is made if the |
662 | * specified filename actually exists. Missing directories | 662 | * specified filename actually exists. Missing directories |
663 | * are created. If filename is only a directory, without a | 663 | * are created. If filename is only a directory, without a |
664 | * specific file, filename must have a trailing slash. | 664 | * specific file, filename must have a trailing slash. |
665 | * | 665 | * |
666 | **/ | 666 | **/ |
667 | QString locateLocal( const char *type, const QString& filename /*US , const KInstance* instance = KGlobal::instance() */ ); | 667 | QString locateLocal( const char *type, const QString& filename /*US , const KInstance* instance = KGlobal::instance() */ ); |
668 | 668 | ||
669 | /*! | 669 | /*! |
670 | * \relates KStandardDirs | 670 | * \relates KStandardDirs |
671 | * This function is much like locate. No check is made if the | 671 | * This function is much like locate. No check is made if the |
672 | * specified filename actually exists. Missing directories | 672 | * specified filename actually exists. Missing directories |
673 | * are created if @p createDir is true. If filename is only | 673 | * are created if @p createDir is true. If filename is only |
674 | * a directory, without a specific file, | 674 | * a directory, without a specific file, |
675 | * filename must have a trailing slash. | 675 | * filename must have a trailing slash. |
676 | * | 676 | * |
677 | **/ | 677 | **/ |