author | ulf69 <ulf69> | 2004-07-02 15:33:56 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-07-02 15:33:56 (UTC) |
commit | bb7ad945c1541684a02e853fdaabd0e3ba74f8df (patch) (unidiff) | |
tree | 4ccde1ffdcb3b14cc6ef4945be87a6e82ff174b4 | |
parent | df5b4df6bc00ea8acfee0b11a335a9d2f39d04dc (diff) | |
download | kdepimpi-bb7ad945c1541684a02e853fdaabd0e3ba74f8df.zip kdepimpi-bb7ad945c1541684a02e853fdaabd0e3ba74f8df.tar.gz kdepimpi-bb7ad945c1541684a02e853fdaabd0e3ba74f8df.tar.bz2 |
removed reentrant solution, for something better
-rw-r--r-- | microkde/kglobal.cpp | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/microkde/kglobal.cpp b/microkde/kglobal.cpp index 6fa0dd6..2b1bd34 100644 --- a/microkde/kglobal.cpp +++ b/microkde/kglobal.cpp | |||
@@ -1,174 +1,166 @@ | |||
1 | #include "kglobal.h" | 1 | #include "kglobal.h" |
2 | #include "kstandarddirs.h" | 2 | #include "kstandarddirs.h" |
3 | #include <qkeycode.h> | 3 | #include <qkeycode.h> |
4 | #include <qapplication.h> | 4 | #include <qapplication.h> |
5 | 5 | ||
6 | KLocale *KGlobal::mLocale = 0; | 6 | KLocale *KGlobal::mLocale = 0; |
7 | KConfig *KGlobal::mConfig = 0; | 7 | KConfig *KGlobal::mConfig = 0; |
8 | KIconLoader *KGlobal::mIconLoader = 0; | 8 | KIconLoader *KGlobal::mIconLoader = 0; |
9 | KStandardDirs *KGlobal::mDirs = 0; | 9 | KStandardDirs *KGlobal::mDirs = 0; |
10 | 10 | ||
11 | QString KGlobal::mAppName = "godot"; | 11 | QString KGlobal::mAppName = "godot"; |
12 | 12 | ||
13 | KLocale *KGlobal::locale() | 13 | KLocale *KGlobal::locale() |
14 | { | 14 | { |
15 | if ( !mLocale ) { | 15 | if ( !mLocale ) { |
16 | ASSERT(mAppName); | 16 | ASSERT(mAppName); |
17 | 17 | ||
18 | mLocale = new KLocale();//mAppName); | 18 | mLocale = new KLocale();//mAppName); |
19 | } | 19 | } |
20 | 20 | ||
21 | return mLocale; | 21 | return mLocale; |
22 | } | 22 | } |
23 | 23 | ||
24 | //US | 24 | //US |
25 | void KGlobal::setLocale(KLocale *kg) | 25 | void KGlobal::setLocale(KLocale *kg) |
26 | { | 26 | { |
27 | mLocale = kg; | 27 | mLocale = kg; |
28 | } | 28 | } |
29 | 29 | ||
30 | KConfig *KGlobal::config() | 30 | KConfig *KGlobal::config() |
31 | { | 31 | { |
32 | static bool reentrant = false; | 32 | //mConfig is set inside setAppName. Though it has to be the first function you call. |
33 | |||
34 | if (reentrant) | ||
35 | return 0; | ||
36 | |||
37 | if ( !mConfig ) { | ||
38 | reentrant = true; | ||
39 | mConfig = new KConfig( locateLocal("config", mAppName + "rc" ) ); | ||
40 | reentrant = false; | ||
41 | } | ||
42 | |||
43 | return mConfig; | 33 | return mConfig; |
44 | } | 34 | } |
45 | 35 | ||
46 | KGlobal::Size KGlobal::getDesktopSize() | 36 | KGlobal::Size KGlobal::getDesktopSize() |
47 | { | 37 | { |
48 | #ifdef DESKTOP_VERSION | 38 | #ifdef DESKTOP_VERSION |
49 | return KGlobal::Desktop; | 39 | return KGlobal::Desktop; |
50 | #else | 40 | #else |
51 | if ( QApplication::desktop()->width() < 480 ) | 41 | if ( QApplication::desktop()->width() < 480 ) |
52 | return KGlobal::Small; | 42 | return KGlobal::Small; |
53 | else | 43 | else |
54 | return KGlobal::Medium; | 44 | return KGlobal::Medium; |
55 | #endif | 45 | #endif |
56 | } | 46 | } |
57 | 47 | ||
58 | KGlobal::Orientation KGlobal::getOrientation() | 48 | KGlobal::Orientation KGlobal::getOrientation() |
59 | { | 49 | { |
60 | if (QApplication::desktop()->width() > QApplication::desktop()->height()) | 50 | if (QApplication::desktop()->width() > QApplication::desktop()->height()) |
61 | return KGlobal::Landscape; | 51 | return KGlobal::Landscape; |
62 | else | 52 | else |
63 | return KGlobal::Portrait; | 53 | return KGlobal::Portrait; |
64 | } | 54 | } |
65 | 55 | ||
66 | int KGlobal::getDesktopWidth() | 56 | int KGlobal::getDesktopWidth() |
67 | { | 57 | { |
68 | return QApplication::desktop()->width(); | 58 | return QApplication::desktop()->width(); |
69 | } | 59 | } |
70 | 60 | ||
71 | int KGlobal::getDesktopHeight() | 61 | int KGlobal::getDesktopHeight() |
72 | { | 62 | { |
73 | return QApplication::desktop()->height(); | 63 | return QApplication::desktop()->height(); |
74 | } | 64 | } |
75 | 65 | ||
76 | 66 | ||
77 | KIconLoader *KGlobal::iconLoader() | 67 | KIconLoader *KGlobal::iconLoader() |
78 | { | 68 | { |
79 | if ( !mIconLoader ) { | 69 | if ( !mIconLoader ) { |
80 | mIconLoader = new KIconLoader(); | 70 | mIconLoader = new KIconLoader(); |
81 | } | 71 | } |
82 | 72 | ||
83 | return mIconLoader; | 73 | return mIconLoader; |
84 | } | 74 | } |
85 | 75 | ||
86 | KStandardDirs *KGlobal::dirs() | 76 | KStandardDirs *KGlobal::dirs() |
87 | { | 77 | { |
88 | if ( !mDirs ) { | 78 | if ( !mDirs ) { |
89 | mDirs = new KStandardDirs(); | 79 | mDirs = new KStandardDirs(); |
90 | } | 80 | } |
91 | 81 | ||
92 | return mDirs; | 82 | return mDirs; |
93 | } | 83 | } |
94 | 84 | ||
95 | void KGlobal::setAppName( const QString &appName ) | 85 | void KGlobal::setAppName( const QString &appName ) |
96 | { | 86 | { |
97 | mAppName = appName; | 87 | mAppName = appName; |
88 | |||
89 | mConfig = new KConfig( locateLocal("config", mAppName + "rc" ) ); | ||
98 | } | 90 | } |
99 | 91 | ||
100 | //US | 92 | //US |
101 | QString KGlobal::getAppName() | 93 | QString KGlobal::getAppName() |
102 | { | 94 | { |
103 | return mAppName; | 95 | return mAppName; |
104 | } | 96 | } |
105 | QString KGlobal::formatMessage ( QString mess, int maxlen ) | 97 | QString KGlobal::formatMessage ( QString mess, int maxlen ) |
106 | { | 98 | { |
107 | //int maxlen = 80; | 99 | //int maxlen = 80; |
108 | int start = 0; | 100 | int start = 0; |
109 | int end = mess.length(); | 101 | int end = mess.length(); |
110 | QString retVal = ""; | 102 | QString retVal = ""; |
111 | int nl, space; | 103 | int nl, space; |
112 | while ( (end - start) > maxlen ) { | 104 | while ( (end - start) > maxlen ) { |
113 | nl = mess.find( "\n", start ); | 105 | nl = mess.find( "\n", start ); |
114 | if ( nl > 0 && nl < start + maxlen ) { | 106 | if ( nl > 0 && nl < start + maxlen ) { |
115 | nl += 1; | 107 | nl += 1; |
116 | retVal += mess.mid( start, nl - start); | 108 | retVal += mess.mid( start, nl - start); |
117 | start = nl; | 109 | start = nl; |
118 | } else { | 110 | } else { |
119 | space = mess.findRev( " ", start + maxlen ); | 111 | space = mess.findRev( " ", start + maxlen ); |
120 | if ( space < start ) { | 112 | if ( space < start ) { |
121 | retVal += mess.mid( start, maxlen) +"\n"; | 113 | retVal += mess.mid( start, maxlen) +"\n"; |
122 | start += maxlen ; | 114 | start += maxlen ; |
123 | } else { | 115 | } else { |
124 | retVal += mess.mid( start, space - start ) +"\n"; | 116 | retVal += mess.mid( start, space - start ) +"\n"; |
125 | start = space+ 1; | 117 | start = space+ 1; |
126 | } | 118 | } |
127 | } | 119 | } |
128 | } | 120 | } |
129 | retVal += mess.mid( start, end - start ); | 121 | retVal += mess.mid( start, end - start ); |
130 | return retVal; | 122 | return retVal; |
131 | } | 123 | } |
132 | int KGlobal::knumkeykonv( int k ) | 124 | int KGlobal::knumkeykonv( int k ) |
133 | { | 125 | { |
134 | int key; | 126 | int key; |
135 | switch( k ) { | 127 | switch( k ) { |
136 | case Qt::Key_Q : | 128 | case Qt::Key_Q : |
137 | key = Qt::Key_1; | 129 | key = Qt::Key_1; |
138 | break; | 130 | break; |
139 | case Qt::Key_W : | 131 | case Qt::Key_W : |
140 | key = Qt::Key_2; | 132 | key = Qt::Key_2; |
141 | break; | 133 | break; |
142 | case Qt::Key_E : | 134 | case Qt::Key_E : |
143 | key = Qt::Key_3; | 135 | key = Qt::Key_3; |
144 | break; | 136 | break; |
145 | case Qt::Key_R : | 137 | case Qt::Key_R : |
146 | key = Qt::Key_4; | 138 | key = Qt::Key_4; |
147 | break; | 139 | break; |
148 | case Qt::Key_T : | 140 | case Qt::Key_T : |
149 | key = Qt::Key_5; | 141 | key = Qt::Key_5; |
150 | break; | 142 | break; |
151 | case Qt::Key_Z : | 143 | case Qt::Key_Z : |
152 | key = Qt::Key_6; | 144 | key = Qt::Key_6; |
153 | break; | 145 | break; |
154 | case Qt::Key_Y : | 146 | case Qt::Key_Y : |
155 | key = Qt::Key_6; | 147 | key = Qt::Key_6; |
156 | break; | 148 | break; |
157 | case Qt::Key_U : | 149 | case Qt::Key_U : |
158 | key = Qt::Key_7; | 150 | key = Qt::Key_7; |
159 | break; | 151 | break; |
160 | case Qt::Key_I : | 152 | case Qt::Key_I : |
161 | key = Qt::Key_8; | 153 | key = Qt::Key_8; |
162 | break; | 154 | break; |
163 | case Qt::Key_O : | 155 | case Qt::Key_O : |
164 | key = Qt::Key_9; | 156 | key = Qt::Key_9; |
165 | break; | 157 | break; |
166 | case Qt::Key_P : | 158 | case Qt::Key_P : |
167 | key = Qt::Key_0; | 159 | key = Qt::Key_0; |
168 | break; | 160 | break; |
169 | default: | 161 | default: |
170 | key = k; | 162 | key = k; |
171 | break; | 163 | break; |
172 | } // switch | 164 | } // switch |
173 | return key; | 165 | return key; |
174 | } | 166 | } |