author | erik <erik> | 2007-01-24 19:54:07 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-24 19:54:07 (UTC) |
commit | 89e81059e832ff77c2f0ac8b9db12f80eafa03fc (patch) (unidiff) | |
tree | 99a130fc643d2aeefdecab452f644e7b61a5f50e | |
parent | 035bbc5bf689839c8d8e7be37f347b0dd900fccf (diff) | |
download | opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.zip opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.tar.gz opie-89e81059e832ff77c2f0ac8b9db12f80eafa03fc.tar.bz2 |
Each file in this commit has an instance where a pointer is checked at
one point in the code and then not checked in another point in the code.
If it needed to be checked once, it needs to be checked the other time. If not
the application could segfault.
-rw-r--r-- | libopie2/opieui/big-screen/osplitter.cpp | 2 | ||||
-rw-r--r-- | library/qpeapplication.cpp | 10 | ||||
-rw-r--r-- | noncore/applets/pcmcia/pcmcia.cpp | 6 | ||||
-rw-r--r-- | noncore/apps/checkbook/mainwindow.cpp | 7 | ||||
-rw-r--r-- | noncore/apps/opie-console/procctl.cpp | 5 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katedocument.cpp | 123 | ||||
-rw-r--r-- | noncore/settings/sysinfo/devicesinfo.cpp | 2 | ||||
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/http.c | 2 |
8 files changed, 83 insertions, 74 deletions
diff --git a/libopie2/opieui/big-screen/osplitter.cpp b/libopie2/opieui/big-screen/osplitter.cpp index 78e919a..5d1e2cf 100644 --- a/libopie2/opieui/big-screen/osplitter.cpp +++ b/libopie2/opieui/big-screen/osplitter.cpp | |||
@@ -1,614 +1,614 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org> | 3 | .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This library is free software; you can | 5 | _;:, .> :=|. This library is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This library is distributed in the hope that | 12 | .i_,=:_. -<s. This library is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
17 | ..}^=.= = ; Library General Public License for more | 17 | ..}^=.= = ; Library General Public License for more |
18 | ++= -. .` .: details. | 18 | ++= -. .` .: details. |
19 | : = ...= . :.=- | 19 | : = ...= . :.=- |
20 | -. .:....=;==+<; You should have received a copy of the GNU | 20 | -. .:....=;==+<; You should have received a copy of the GNU |
21 | -_. . . )=. = Library General Public License along with | 21 | -_. . . )=. = Library General Public License along with |
22 | -- :-=` this library; see the file COPYING.LIB. | 22 | -- :-=` this library; see the file COPYING.LIB. |
23 | If not, write to the Free Software Foundation, | 23 | If not, write to the Free Software Foundation, |
24 | Inc., 59 Temple Place - Suite 330, | 24 | Inc., 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "osplitter.h" | 29 | #include "osplitter.h" |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | #include <opie2/otabwidget.h> | 32 | #include <opie2/otabwidget.h> |
33 | #include <opie2/odebug.h> | 33 | #include <opie2/odebug.h> |
34 | 34 | ||
35 | /* QT */ | 35 | /* QT */ |
36 | #include <qvaluelist.h> | 36 | #include <qvaluelist.h> |
37 | #include <qvbox.h> | 37 | #include <qvbox.h> |
38 | 38 | ||
39 | using namespace Opie::Ui; | 39 | using namespace Opie::Ui; |
40 | using namespace Opie::Ui::Internal; | 40 | using namespace Opie::Ui::Internal; |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * | 43 | * |
44 | * This is the constructor of OSplitter | 44 | * This is the constructor of OSplitter |
45 | * You might want to call setSizeChange to tell | 45 | * You might want to call setSizeChange to tell |
46 | * OSplitter to change its layout when a specefic | 46 | * OSplitter to change its layout when a specefic |
47 | * mark was crossed. OSplitter sets a default value. | 47 | * mark was crossed. OSplitter sets a default value. |
48 | * | 48 | * |
49 | * You cann add widget with addWidget to the OSplitter. | 49 | * You cann add widget with addWidget to the OSplitter. |
50 | * OSplitter supports also grouping of Splitters where they | 50 | * OSplitter supports also grouping of Splitters where they |
51 | * can share one OTabBar in small screen mode. This can be used | 51 | * can share one OTabBar in small screen mode. This can be used |
52 | * for email clients like vies but see the example. | 52 | * for email clients like vies but see the example. |
53 | * | 53 | * |
54 | * @param orient The orientation wether to layout horizontal or vertical | 54 | * @param orient The orientation wether to layout horizontal or vertical |
55 | * @param parent The parent of this widget | 55 | * @param parent The parent of this widget |
56 | * @param name The name passed on to QObject | 56 | * @param name The name passed on to QObject |
57 | * @param fl Additional widgets flags passed to QWidget | 57 | * @param fl Additional widgets flags passed to QWidget |
58 | * | 58 | * |
59 | * @short single c'tor of the OSplitter | 59 | * @short single c'tor of the OSplitter |
60 | */ | 60 | */ |
61 | OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl ) | 61 | OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl ) |
62 | : QFrame( parent, name, fl ) | 62 | : QFrame( parent, name, fl ) |
63 | { | 63 | { |
64 | m_orient = orient; | 64 | m_orient = orient; |
65 | m_hbox = 0; | 65 | m_hbox = 0; |
66 | m_size_policy = 330; | 66 | m_size_policy = 330; |
67 | setFontPropagation( AllChildren ); | 67 | setFontPropagation( AllChildren ); |
68 | setPalettePropagation( AllChildren ); | 68 | setPalettePropagation( AllChildren ); |
69 | 69 | ||
70 | /* start by default with the tab widget */ | 70 | /* start by default with the tab widget */ |
71 | m_tabWidget = 0; | 71 | m_tabWidget = 0; |
72 | m_parentTab = 0; | 72 | m_parentTab = 0; |
73 | changeTab(); | 73 | changeTab(); |
74 | 74 | ||
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Destructor destructs this object and cleans up. All child | 79 | * Destructor destructs this object and cleans up. All child |
80 | * widgets will be deleted | 80 | * widgets will be deleted |
81 | * @see addWidget | 81 | * @see addWidget |
82 | */ | 82 | */ |
83 | OSplitter::~OSplitter() | 83 | OSplitter::~OSplitter() |
84 | { | 84 | { |
85 | m_splitter.setAutoDelete( true ); | 85 | m_splitter.setAutoDelete( true ); |
86 | m_splitter.clear(); | 86 | m_splitter.clear(); |
87 | 87 | ||
88 | delete m_hbox; | 88 | delete m_hbox; |
89 | delete m_tabWidget; | 89 | delete m_tabWidget; |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Sets the label for the Splitter. This label will be used | 94 | * Sets the label for the Splitter. This label will be used |
95 | * if a parent splitter is arranged as TabWidget but | 95 | * if a parent splitter is arranged as TabWidget but |
96 | * this splitter is in fullscreen mode. Then a tab with OSplitter::label() | 96 | * this splitter is in fullscreen mode. Then a tab with OSplitter::label() |
97 | * and iconName() gets added. | 97 | * and iconName() gets added. |
98 | * | 98 | * |
99 | * @param name The name of the Label | 99 | * @param name The name of the Label |
100 | */ | 100 | */ |
101 | void OSplitter::setLabel( const QString& name ) | 101 | void OSplitter::setLabel( const QString& name ) |
102 | { | 102 | { |
103 | m_name = name; | 103 | m_name = name; |
104 | } | 104 | } |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * @see setLabel but this is for the icon retrieved by Resource | 107 | * @see setLabel but this is for the icon retrieved by Resource |
108 | * | 108 | * |
109 | * @param name The name of the icon in example ( "zoom" ) | 109 | * @param name The name of the icon in example ( "zoom" ) |
110 | */ | 110 | */ |
111 | void OSplitter::setIconName( const QString& name ) | 111 | void OSplitter::setIconName( const QString& name ) |
112 | { | 112 | { |
113 | m_icon = name; | 113 | m_icon = name; |
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
117 | /** | 117 | /** |
118 | * returns the iconName | 118 | * returns the iconName |
119 | * @see setIconName | 119 | * @see setIconName |
120 | */ | 120 | */ |
121 | QString OSplitter::iconName()const | 121 | QString OSplitter::iconName()const |
122 | { | 122 | { |
123 | return m_icon; | 123 | return m_icon; |
124 | } | 124 | } |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * returns the label set with setLabel | 127 | * returns the label set with setLabel |
128 | * @see setLabel | 128 | * @see setLabel |
129 | */ | 129 | */ |
130 | QString OSplitter::label()const | 130 | QString OSplitter::label()const |
131 | { | 131 | { |
132 | return m_name; | 132 | return m_name; |
133 | } | 133 | } |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * This function sets the size change policy of the splitter. | 136 | * This function sets the size change policy of the splitter. |
137 | * If this size marked is crossed the splitter will relayout. | 137 | * If this size marked is crossed the splitter will relayout. |
138 | * Note: that depending on the set Orientation it'll either look | 138 | * Note: that depending on the set Orientation it'll either look |
139 | * at the width or height. | 139 | * at the width or height. |
140 | * Note: If you want to from side to side view to tabbed view you need | 140 | * Note: If you want to from side to side view to tabbed view you need |
141 | * to make sure that the size you supply is not smaller than the minimum | 141 | * to make sure that the size you supply is not smaller than the minimum |
142 | * size of your added widgets. Note that if you use widgets like QComboBoxes | 142 | * size of your added widgets. Note that if you use widgets like QComboBoxes |
143 | * you need to teach them to accept smaller sizes as well @see QWidget::setSizePolicy | 143 | * you need to teach them to accept smaller sizes as well @see QWidget::setSizePolicy |
144 | * | 144 | * |
145 | * @param width_height The mark that will be watched. Interpreted depending on the Orientation of the Splitter. | 145 | * @param width_height The mark that will be watched. Interpreted depending on the Orientation of the Splitter. |
146 | * @return void | 146 | * @return void |
147 | */ | 147 | */ |
148 | void OSplitter::setSizeChange( int width_height ) | 148 | void OSplitter::setSizeChange( int width_height ) |
149 | { | 149 | { |
150 | m_size_policy = width_height; | 150 | m_size_policy = width_height; |
151 | QSize sz(width(), height() ); | 151 | QSize sz(width(), height() ); |
152 | QResizeEvent ev(sz, sz ); | 152 | QResizeEvent ev(sz, sz ); |
153 | resizeEvent(&ev); | 153 | resizeEvent(&ev); |
154 | } | 154 | } |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * This functions allows to add another OSplitter and to share | 157 | * This functions allows to add another OSplitter and to share |
158 | * the OTabBar in small screen mode. The ownerships gets transfered. | 158 | * the OTabBar in small screen mode. The ownerships gets transfered. |
159 | * OSplitters are always added after normal widget items | 159 | * OSplitters are always added after normal widget items |
160 | */ | 160 | */ |
161 | void OSplitter::addWidget( OSplitter* split ) | 161 | void OSplitter::addWidget( OSplitter* split ) |
162 | { | 162 | { |
163 | m_splitter.append( split ); | 163 | m_splitter.append( split ); |
164 | 164 | ||
165 | /* | 165 | /* |
166 | * set tab widget | 166 | * set tab widget |
167 | */ | 167 | */ |
168 | if (m_tabWidget ) | 168 | if (m_tabWidget ) |
169 | setTabWidget( m_parentTab ); | 169 | setTabWidget( m_parentTab ); |
170 | else | 170 | else |
171 | { | 171 | { |
172 | OSplitterContainer con; | 172 | OSplitterContainer con; |
173 | con.widget =split; | 173 | con.widget =split; |
174 | addToBox( con ); | 174 | addToBox( con ); |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | /* | 178 | /* |
179 | * If in a tab it should be removed | 179 | * If in a tab it should be removed |
180 | * and if in a hbox the reparent kills it too | 180 | * and if in a hbox the reparent kills it too |
181 | */ | 181 | */ |
182 | /** | 182 | /** |
183 | * This removes the splitter again. You currently need to call this | 183 | * This removes the splitter again. You currently need to call this |
184 | * before you delete or otherwise you can get mem corruption | 184 | * before you delete or otherwise you can get mem corruption |
185 | * or other weird behaviour. | 185 | * or other weird behaviour. |
186 | * Owner ship gets transfered back to you it's current parent | 186 | * Owner ship gets transfered back to you it's current parent |
187 | * is 0 | 187 | * is 0 |
188 | */ | 188 | */ |
189 | void OSplitter::removeWidget( OSplitter* split) | 189 | void OSplitter::removeWidget( OSplitter* split) |
190 | { | 190 | { |
191 | split->setTabWidget( 0 ); | 191 | split->setTabWidget( 0 ); |
192 | split->reparent( 0, 0, QPoint(0, 0) ); | 192 | split->reparent( 0, 0, QPoint(0, 0) ); |
193 | } | 193 | } |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Adds a widget to the Splitter. The widgets gets inserted | 196 | * Adds a widget to the Splitter. The widgets gets inserted |
197 | * at the end of either the Box or TabWidget. | 197 | * at the end of either the Box or TabWidget. |
198 | * Ownership gets transfered and the widgets gets reparented. | 198 | * Ownership gets transfered and the widgets gets reparented. |
199 | * Note: icon and label is only available on small screensizes | 199 | * Note: icon and label is only available on small screensizes |
200 | * if size is smaller than the mark | 200 | * if size is smaller than the mark |
201 | * Warning: No null checking of the widget is done. Only on debug | 201 | * Warning: No null checking of the widget is done. Only on debug |
202 | * a message will be outputtet | 202 | * a message will be outputtet |
203 | * | 203 | * |
204 | * @param wid The widget which will be added | 204 | * @param wid The widget which will be added |
205 | * @param icon The icon of the possible Tab | 205 | * @param icon The icon of the possible Tab |
206 | * @param label The label of the possible Tab | 206 | * @param label The label of the possible Tab |
207 | */ | 207 | */ |
208 | void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& label ) | 208 | void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& label ) |
209 | { | 209 | { |
210 | #ifdef DEBUG | 210 | #ifdef DEBUG |
211 | if (!wid ) | 211 | if (!wid ) |
212 | return; | 212 | return; |
213 | #endif | 213 | #endif |
214 | OSplitterContainer cont; | 214 | OSplitterContainer cont; |
215 | cont.widget = wid; | 215 | cont.widget = wid; |
216 | cont.icon =icon; | 216 | cont.icon =icon; |
217 | cont.name = label; | 217 | cont.name = label; |
218 | 218 | ||
219 | m_container.append( cont ); | 219 | m_container.append( cont ); |
220 | 220 | ||
221 | /* | 221 | /* |
222 | * | 222 | * |
223 | */ | 223 | */ |
224 | if (!m_splitter.isEmpty() && (m_tabWidget || m_parentTab ) ) | 224 | if (!m_splitter.isEmpty() && (m_tabWidget || m_parentTab ) ) |
225 | setTabWidget( m_parentTab ); | 225 | setTabWidget( m_parentTab ); |
226 | else | 226 | else |
227 | { | 227 | { |
228 | if (m_hbox ) | 228 | if (m_hbox ) |
229 | addToBox( cont ); | 229 | addToBox( cont ); |
230 | else | 230 | else if (m_tabWidget) |
231 | addToTab( cont ); | 231 | addToTab( cont ); |
232 | } | 232 | } |
233 | } | 233 | } |
234 | 234 | ||
235 | 235 | ||
236 | /** | 236 | /** |
237 | * Removes the widget from the tab widgets if necessary. | 237 | * Removes the widget from the tab widgets if necessary. |
238 | * OSplitter drops ownership of this widget and the widget | 238 | * OSplitter drops ownership of this widget and the widget |
239 | * will be reparented i tto 0. | 239 | * will be reparented i tto 0. |
240 | * The widget will not be deleted. | 240 | * The widget will not be deleted. |
241 | * | 241 | * |
242 | * @param w The widget to be removed | 242 | * @param w The widget to be removed |
243 | */ | 243 | */ |
244 | void OSplitter::removeWidget( QWidget* w) | 244 | void OSplitter::removeWidget( QWidget* w) |
245 | { | 245 | { |
246 | ContainerList::Iterator it; | 246 | ContainerList::Iterator it; |
247 | for ( it = m_container.begin(); it != m_container.end(); ++it ) | 247 | for ( it = m_container.begin(); it != m_container.end(); ++it ) |
248 | if ( (*it).widget == w ) | 248 | if ( (*it).widget == w ) |
249 | break; | 249 | break; |
250 | 250 | ||
251 | if (it == m_container.end() ) | 251 | if (it == m_container.end() ) |
252 | return; | 252 | return; |
253 | 253 | ||
254 | 254 | ||
255 | /* only tab needs to be removed.. box recognizes it */ | 255 | /* only tab needs to be removed.. box recognizes it */ |
256 | if ( !m_hbox ) | 256 | if ( !m_hbox ) |
257 | removeFromTab( w ); | 257 | removeFromTab( w ); |
258 | 258 | ||
259 | 259 | ||
260 | /* Find reparent it and remove it from our list */ | 260 | /* Find reparent it and remove it from our list */ |
261 | 261 | ||
262 | w->reparent( 0, 0, QPoint(0, 0)); | 262 | w->reparent( 0, 0, QPoint(0, 0)); |
263 | it = m_container.remove( it ); | 263 | it = m_container.remove( it ); |
264 | 264 | ||
265 | } | 265 | } |
266 | 266 | ||
267 | 267 | ||
268 | /** | 268 | /** |
269 | * This method will give focus to the widget. If in a tabwidget | 269 | * This method will give focus to the widget. If in a tabwidget |
270 | * the tabbar will be changed | 270 | * the tabbar will be changed |
271 | * | 271 | * |
272 | * @param w The widget which will be set the current one | 272 | * @param w The widget which will be set the current one |
273 | */ | 273 | */ |
274 | void OSplitter::setCurrentWidget( QWidget* w) | 274 | void OSplitter::setCurrentWidget( QWidget* w) |
275 | { | 275 | { |
276 | if (m_tabWidget ) | 276 | if (m_tabWidget ) |
277 | m_tabWidget->setCurrentTab( w ); | 277 | m_tabWidget->setCurrentTab( w ); |
278 | // else | 278 | // else |
279 | // m_hbox->setFocus( w ); | 279 | // m_hbox->setFocus( w ); |
280 | 280 | ||
281 | } | 281 | } |
282 | 282 | ||
283 | /** | 283 | /** |
284 | * This is an overloaded member function and only differs in the | 284 | * This is an overloaded member function and only differs in the |
285 | * argument it takes. | 285 | * argument it takes. |
286 | * Searches list of widgets for label. It'll pick the first label it finds | 286 | * Searches list of widgets for label. It'll pick the first label it finds |
287 | * | 287 | * |
288 | * @param label Label to look for. First match will be taken | 288 | * @param label Label to look for. First match will be taken |
289 | */ | 289 | */ |
290 | void OSplitter::setCurrentWidget( const QString& label ) | 290 | void OSplitter::setCurrentWidget( const QString& label ) |
291 | { | 291 | { |
292 | ContainerList::Iterator it; | 292 | ContainerList::Iterator it; |
293 | for (it = m_container.begin(); it != m_container.end(); ++it ) | 293 | for (it = m_container.begin(); it != m_container.end(); ++it ) |
294 | { | 294 | { |
295 | if ( (*it).name == label ) | 295 | if ( (*it).name == label ) |
296 | { | 296 | { |
297 | setCurrentWidget( (*it).widget ); | 297 | setCurrentWidget( (*it).widget ); |
298 | break; | 298 | break; |
299 | } | 299 | } |
300 | } | 300 | } |
301 | } | 301 | } |
302 | 302 | ||
303 | /** | 303 | /** |
304 | * This will only work when the TabWidget is active | 304 | * This will only work when the TabWidget is active |
305 | * If everything is visible this signal is kindly ignored | 305 | * If everything is visible this signal is kindly ignored |
306 | * @see OTabWidget::setCurrentTab(int) | 306 | * @see OTabWidget::setCurrentTab(int) |
307 | * | 307 | * |
308 | * @param tab The tab to make current | 308 | * @param tab The tab to make current |
309 | */ | 309 | */ |
310 | void OSplitter::setCurrentWidget( int tab ) | 310 | void OSplitter::setCurrentWidget( int tab ) |
311 | { | 311 | { |
312 | if (m_tabWidget ) | 312 | if (m_tabWidget ) |
313 | m_tabWidget->setCurrentTab( tab ); | 313 | m_tabWidget->setCurrentTab( tab ); |
314 | } | 314 | } |
315 | 315 | ||
316 | /** | 316 | /** |
317 | * return the currently activated widget if in tab widget mode | 317 | * return the currently activated widget if in tab widget mode |
318 | * or null because all widgets are visible | 318 | * or null because all widgets are visible |
319 | */ | 319 | */ |
320 | QWidget* OSplitter::currentWidget() const | 320 | QWidget* OSplitter::currentWidget() const |
321 | { | 321 | { |
322 | if (m_tabWidget) | 322 | if (m_tabWidget) |
323 | return m_tabWidget->currentWidget(); | 323 | return m_tabWidget->currentWidget(); |
324 | else if (m_parentTab ) | 324 | else if (m_parentTab ) |
325 | return m_parentTab->currentWidget(); | 325 | return m_parentTab->currentWidget(); |
326 | 326 | ||
327 | return 0l; | 327 | return 0l; |
328 | } | 328 | } |
329 | /* wrong */ | 329 | /* wrong */ |
330 | #if 0 | 330 | #if 0 |
331 | /** | 331 | /** |
332 | * @reimplented for internal reasons | 332 | * @reimplented for internal reasons |
333 | * returns the sizeHint of one of its sub widgets | 333 | * returns the sizeHint of one of its sub widgets |
334 | */ | 334 | */ |
335 | QSize OSplitter::sizeHint()const | 335 | QSize OSplitter::sizeHint()const |
336 | { | 336 | { |
337 | if (m_parentTab ) | 337 | if (m_parentTab ) |
338 | return QFrame::sizeHint(); | 338 | return QFrame::sizeHint(); |
339 | 339 | ||
340 | if (m_hbox ) | 340 | if (m_hbox ) |
341 | return m_hbox->sizeHint(); | 341 | return m_hbox->sizeHint(); |
342 | else | 342 | else |
343 | return m_tabWidget->sizeHint(); | 343 | return m_tabWidget->sizeHint(); |
344 | } | 344 | } |
345 | 345 | ||
346 | QSize OSplitter::minimumSizeHint()const | 346 | QSize OSplitter::minimumSizeHint()const |
347 | { | 347 | { |
348 | if (m_parentTab ) | 348 | if (m_parentTab ) |
349 | return QFrame::minimumSizeHint(); | 349 | return QFrame::minimumSizeHint(); |
350 | if (m_hbox) | 350 | if (m_hbox) |
351 | return m_hbox->sizeHint(); | 351 | return m_hbox->sizeHint(); |
352 | else | 352 | else |
353 | return m_tabWidget->sizeHint(); | 353 | return m_tabWidget->sizeHint(); |
354 | } | 354 | } |
355 | #endif | 355 | #endif |
356 | 356 | ||
357 | /** | 357 | /** |
358 | * @reimplemented for internal reasons | 358 | * @reimplemented for internal reasons |
359 | */ | 359 | */ |
360 | void OSplitter::resizeEvent( QResizeEvent* res ) | 360 | void OSplitter::resizeEvent( QResizeEvent* res ) |
361 | { | 361 | { |
362 | QFrame::resizeEvent( res ); | 362 | QFrame::resizeEvent( res ); |
363 | /* | 363 | /* |
364 | * | 364 | * |
365 | */ | 365 | */ |
366 | bool mode = true; | 366 | bool mode = true; |
367 | if ( res->size().width() > m_size_policy && | 367 | if ( res->size().width() > m_size_policy && |
368 | m_orient == Horizontal ) | 368 | m_orient == Horizontal ) |
369 | { | 369 | { |
370 | changeHBox(); | 370 | changeHBox(); |
371 | mode = false; | 371 | mode = false; |
372 | } | 372 | } |
373 | else if ( (res->size().width() <= m_size_policy && | 373 | else if ( (res->size().width() <= m_size_policy && |
374 | m_orient == Horizontal ) || | 374 | m_orient == Horizontal ) || |
375 | (res->size().height() <= m_size_policy && | 375 | (res->size().height() <= m_size_policy && |
376 | m_orient == Vertical ) ) | 376 | m_orient == Vertical ) ) |
377 | { | 377 | { |
378 | changeTab(); | 378 | changeTab(); |
379 | } | 379 | } |
380 | else if ( res->size().height() > m_size_policy && | 380 | else if ( res->size().height() > m_size_policy && |
381 | m_orient == Vertical ) | 381 | m_orient == Vertical ) |
382 | { | 382 | { |
383 | changeVBox(); | 383 | changeVBox(); |
384 | mode = false; | 384 | mode = false; |
385 | } | 385 | } |
386 | 386 | ||
387 | emit sizeChanged(mode, m_orient ); | 387 | emit sizeChanged(mode, m_orient ); |
388 | } | 388 | } |
389 | 389 | ||
390 | /* | 390 | /* |
391 | * Adds a container to a tab either the parent tab | 391 | * Adds a container to a tab either the parent tab |
392 | * or our own | 392 | * or our own |
393 | */ | 393 | */ |
394 | void OSplitter::addToTab( const Opie::Ui::Internal::OSplitterContainer& con ) | 394 | void OSplitter::addToTab( const Opie::Ui::Internal::OSplitterContainer& con ) |
395 | { | 395 | { |
396 | QWidget *wid = con.widget; | 396 | QWidget *wid = con.widget; |
397 | // not needed widgetstack will reparent as well wid.reparent(m_tabWidget, wid->getWFlags(), QPoint(0, 0) ); | 397 | // not needed widgetstack will reparent as well wid.reparent(m_tabWidget, wid->getWFlags(), QPoint(0, 0) ); |
398 | if (m_parentTab ) | 398 | if (m_parentTab ) |
399 | m_parentTab->addTab( wid, con.icon, con.name ); | 399 | m_parentTab->addTab( wid, con.icon, con.name ); |
400 | else | 400 | else |
401 | m_tabWidget->addTab( wid, con.icon, con.name ); | 401 | m_tabWidget->addTab( wid, con.icon, con.name ); |
402 | } | 402 | } |
403 | 403 | ||
404 | 404 | ||
405 | /* | 405 | /* |
406 | * adds a container to the box | 406 | * adds a container to the box |
407 | */ | 407 | */ |
408 | void OSplitter::addToBox( const Opie::Ui::Internal::OSplitterContainer& con ) | 408 | void OSplitter::addToBox( const Opie::Ui::Internal::OSplitterContainer& con ) |
409 | { | 409 | { |
410 | QWidget* wid = con.widget; | 410 | QWidget* wid = con.widget; |
411 | wid->reparent(m_hbox, 0, QPoint(0, 0) ); | 411 | wid->reparent(m_hbox, 0, QPoint(0, 0) ); |
412 | } | 412 | } |
413 | 413 | ||
414 | 414 | ||
415 | /* | 415 | /* |
416 | * Removes a widget from the tab | 416 | * Removes a widget from the tab |
417 | */ | 417 | */ |
418 | void OSplitter::removeFromTab( QWidget* wid ) | 418 | void OSplitter::removeFromTab( QWidget* wid ) |
419 | { | 419 | { |
420 | if (m_parentTab ) | 420 | if (m_parentTab ) |
421 | m_parentTab->removePage( wid ); | 421 | m_parentTab->removePage( wid ); |
422 | else | 422 | else |
423 | m_tabWidget->removePage( wid ); | 423 | m_tabWidget->removePage( wid ); |
424 | } | 424 | } |
425 | 425 | ||
426 | /* | 426 | /* |
427 | * switches over to a OTabWidget layout | 427 | * switches over to a OTabWidget layout |
428 | * it is recursive | 428 | * it is recursive |
429 | */ | 429 | */ |
430 | void OSplitter::changeTab() | 430 | void OSplitter::changeTab() |
431 | { | 431 | { |
432 | /* if we're the owner of the tab widget */ | 432 | /* if we're the owner of the tab widget */ |
433 | if (m_tabWidget ) | 433 | if (m_tabWidget ) |
434 | { | 434 | { |
435 | raise(); | 435 | raise(); |
436 | show(); | 436 | show(); |
437 | m_tabWidget->setGeometry( frameRect() ); | 437 | m_tabWidget->setGeometry( frameRect() ); |
438 | return; | 438 | return; |
439 | } | 439 | } |
440 | 440 | ||
441 | /* | 441 | /* |
442 | * and add all widgets this will reparent them | 442 | * and add all widgets this will reparent them |
443 | * delete m_hbox set it to 0 | 443 | * delete m_hbox set it to 0 |
444 | * | 444 | * |
445 | */ | 445 | */ |
446 | OTabWidget *tab; | 446 | OTabWidget *tab; |
447 | if ( m_parentTab ) | 447 | if ( m_parentTab ) |
448 | { | 448 | { |
449 | hide(); | 449 | hide(); |
450 | tab = m_parentTab; | 450 | tab = m_parentTab; |
451 | /* expensive but needed cause we're called from setTabWidget and resizeEvent*/ | 451 | /* expensive but needed cause we're called from setTabWidget and resizeEvent*/ |
452 | if (!m_container.isEmpty() ) | 452 | if (!m_container.isEmpty() ) |
453 | { | 453 | { |
454 | ContainerList::Iterator it = m_container.begin(); | 454 | ContainerList::Iterator it = m_container.begin(); |
455 | for (; it != m_container.end(); ++it ) | 455 | for (; it != m_container.end(); ++it ) |
456 | m_parentTab->removePage( (*it).widget ); | 456 | m_parentTab->removePage( (*it).widget ); |
457 | } | 457 | } |
458 | } | 458 | } |
459 | else | 459 | else |
460 | tab = m_tabWidget = new OTabWidget( this ); | 460 | tab = m_tabWidget = new OTabWidget( this ); |
461 | 461 | ||
462 | connect(tab, SIGNAL(currentChanged(QWidget*) ), | 462 | connect(tab, SIGNAL(currentChanged(QWidget*) ), |
463 | this, SIGNAL(currentChanged(QWidget*) ) ); | 463 | this, SIGNAL(currentChanged(QWidget*) ) ); |
464 | 464 | ||
465 | for ( ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) | 465 | for ( ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) |
466 | { | 466 | { |
467 | addToTab( (*it) ); | 467 | addToTab( (*it) ); |
468 | } | 468 | } |
469 | 469 | ||
470 | for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) | 470 | for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) |
471 | { | 471 | { |
472 | split->reparent(this, 0, QPoint(0, 0) ); | 472 | split->reparent(this, 0, QPoint(0, 0) ); |
473 | split->setTabWidget( tab ); | 473 | split->setTabWidget( tab ); |
474 | } | 474 | } |
475 | 475 | ||
476 | 476 | ||
477 | delete m_hbox; | 477 | delete m_hbox; |
478 | m_hbox = 0; | 478 | m_hbox = 0; |
479 | if (!m_tabWidget ) | 479 | if (!m_tabWidget ) |
480 | return; | 480 | return; |
481 | 481 | ||
482 | m_tabWidget->setGeometry( frameRect() ); | 482 | m_tabWidget->setGeometry( frameRect() ); |
483 | m_tabWidget->show(); | 483 | m_tabWidget->show(); |
484 | 484 | ||
485 | } | 485 | } |
486 | 486 | ||
487 | /* | 487 | /* |
488 | * changes over to a box | 488 | * changes over to a box |
489 | * this is recursive as well | 489 | * this is recursive as well |
490 | */ | 490 | */ |
491 | void OSplitter::changeHBox() | 491 | void OSplitter::changeHBox() |
492 | { | 492 | { |
493 | if (m_hbox ) | 493 | if (m_hbox ) |
494 | { | 494 | { |
495 | m_hbox->setGeometry( frameRect() ); | 495 | m_hbox->setGeometry( frameRect() ); |
496 | return; | 496 | return; |
497 | } | 497 | } |
498 | 498 | ||
499 | m_hbox = new QHBox( this ); | 499 | m_hbox = new QHBox( this ); |
500 | commonChangeBox(); | 500 | commonChangeBox(); |
501 | } | 501 | } |
502 | 502 | ||
503 | void OSplitter::changeVBox() | 503 | void OSplitter::changeVBox() |
504 | { | 504 | { |
505 | if (m_hbox ) | 505 | if (m_hbox ) |
506 | { | 506 | { |
507 | m_hbox->setGeometry( frameRect() ); | 507 | m_hbox->setGeometry( frameRect() ); |
508 | return; | 508 | return; |
509 | } | 509 | } |
510 | 510 | ||
511 | m_hbox = new QVBox( this ); | 511 | m_hbox = new QVBox( this ); |
512 | 512 | ||
513 | commonChangeBox(); | 513 | commonChangeBox(); |
514 | 514 | ||
515 | } | 515 | } |
516 | 516 | ||
517 | /* | 517 | /* |
518 | * common box code | 518 | * common box code |
519 | * first remove and add children | 519 | * first remove and add children |
520 | * the other splitters | 520 | * the other splitters |
521 | * it is recursive as well due the call to setTabWidget | 521 | * it is recursive as well due the call to setTabWidget |
522 | */ | 522 | */ |
523 | void OSplitter::commonChangeBox() | 523 | void OSplitter::commonChangeBox() |
524 | { | 524 | { |
525 | for (ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) | 525 | for (ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it ) |
526 | { | 526 | { |
527 | /* only if parent tab.. m_tabWidgets gets deleted and would do that as well */ | 527 | /* only if parent tab.. m_tabWidgets gets deleted and would do that as well */ |
528 | if (m_parentTab ) | 528 | if (m_parentTab ) |
529 | removeFromTab( (*it).widget ); | 529 | removeFromTab( (*it).widget ); |
530 | addToBox( (*it) ); | 530 | addToBox( (*it) ); |
531 | } | 531 | } |
532 | for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) | 532 | for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() ) |
533 | { | 533 | { |
534 | /* tell them the world had changed */ | 534 | /* tell them the world had changed */ |
535 | split->setTabWidget( 0 ); | 535 | split->setTabWidget( 0 ); |
536 | OSplitterContainer con; | 536 | OSplitterContainer con; |
537 | con.widget = split; | 537 | con.widget = split; |
538 | // con.widget = split->m_tabWidget ? static_cast<QWidget*>(split->m_tabWidget) | 538 | // con.widget = split->m_tabWidget ? static_cast<QWidget*>(split->m_tabWidget) |
539 | // : static_cast<QWidget*>(split->m_hbox); | 539 | // : static_cast<QWidget*>(split->m_hbox); |
540 | addToBox( con ); | 540 | addToBox( con ); |
541 | } | 541 | } |
542 | 542 | ||
543 | 543 | ||
544 | 544 | ||
545 | if (m_parentTab ) | 545 | if (m_parentTab ) |
546 | m_parentTab->addTab(m_hbox, iconName(), label() ); | 546 | m_parentTab->addTab(m_hbox, iconName(), label() ); |
547 | else | 547 | else |
548 | { | 548 | { |
549 | m_hbox->setGeometry( frameRect() ); | 549 | m_hbox->setGeometry( frameRect() ); |
550 | m_hbox->show(); | 550 | m_hbox->show(); |
551 | delete m_tabWidget; | 551 | delete m_tabWidget; |
552 | m_tabWidget = 0; | 552 | m_tabWidget = 0; |
553 | show(); // also show this widget | 553 | show(); // also show this widget |
554 | } | 554 | } |
555 | } | 555 | } |
556 | 556 | ||
557 | /* | 557 | /* |
558 | * sets the tabwidget, removes tabs, and relayouts the widget | 558 | * sets the tabwidget, removes tabs, and relayouts the widget |
559 | */ | 559 | */ |
560 | void OSplitter::setTabWidget( OTabWidget* wid) | 560 | void OSplitter::setTabWidget( OTabWidget* wid) |
561 | { | 561 | { |
562 | /* clean up cause m_parentTab will not be available for us */ | 562 | /* clean up cause m_parentTab will not be available for us */ |
563 | if ( m_parentTab ) | 563 | if ( m_parentTab ) |
564 | { | 564 | { |
565 | if (m_hbox ) | 565 | if (m_hbox ) |
566 | m_parentTab->removePage( m_hbox ); | 566 | m_parentTab->removePage( m_hbox ); |
567 | else if (!m_container.isEmpty() ) | 567 | else if (!m_container.isEmpty() ) |
568 | { | 568 | { |
569 | ContainerList::Iterator it = m_container.begin(); | 569 | ContainerList::Iterator it = m_container.begin(); |
570 | for ( ; it != m_container.end(); ++it ) | 570 | for ( ; it != m_container.end(); ++it ) |
571 | m_parentTab->removePage( (*it).widget ); | 571 | m_parentTab->removePage( (*it).widget ); |
572 | } | 572 | } |
573 | } | 573 | } |
574 | /* the parent Splitter changed so either make us indepent or dep */ | 574 | /* the parent Splitter changed so either make us indepent or dep */ |
575 | 575 | ||
576 | m_parentTab = wid; | 576 | m_parentTab = wid; |
577 | 577 | ||
578 | QWidget *tab = m_tabWidget; | 578 | QWidget *tab = m_tabWidget; |
579 | QWidget *box = m_hbox; | 579 | QWidget *box = m_hbox; |
580 | m_hbox = 0; m_tabWidget = 0; | 580 | m_hbox = 0; m_tabWidget = 0; |
581 | 581 | ||
582 | if ( layoutMode() ) | 582 | if ( layoutMode() ) |
583 | changeTab(); | 583 | changeTab(); |
584 | else if (m_orient == Horizontal ) | 584 | else if (m_orient == Horizontal ) |
585 | changeHBox(); | 585 | changeHBox(); |
586 | else | 586 | else |
587 | changeVBox(); | 587 | changeVBox(); |
588 | 588 | ||
589 | /* our own crap is added and children from change* */ | 589 | /* our own crap is added and children from change* */ |
590 | delete tab; | 590 | delete tab; |
591 | delete box; | 591 | delete box; |
592 | } | 592 | } |
593 | 593 | ||
594 | #if 0 | 594 | #if 0 |
595 | void OSplitter::reparentAll() | 595 | void OSplitter::reparentAll() |
596 | { | 596 | { |
597 | if (m_container.isEmpty() ) | 597 | if (m_container.isEmpty() ) |
598 | return; | 598 | return; |
599 | 599 | ||
600 | ContainerList::Iterator it = m_container.begin(); | 600 | ContainerList::Iterator it = m_container.begin(); |
601 | for ( ; it != m_container.end(); ++it ) | 601 | for ( ; it != m_container.end(); ++it ) |
602 | (*it).wid->reparent(0, 0, QPoint(0, 0) ); | 602 | (*it).wid->reparent(0, 0, QPoint(0, 0) ); |
603 | 603 | ||
604 | 604 | ||
605 | } | 605 | } |
606 | #endif | 606 | #endif |
607 | 607 | ||
608 | /** | 608 | /** |
609 | * @internal | 609 | * @internal |
610 | */ | 610 | */ |
611 | bool OSplitter::layoutMode()const | 611 | bool OSplitter::layoutMode()const |
612 | { | 612 | { |
613 | if ( size().width() > m_size_policy && | 613 | if ( size().width() > m_size_policy && |
614 | m_orient == Horizontal ) | 614 | m_orient == Horizontal ) |
diff --git a/library/qpeapplication.cpp b/library/qpeapplication.cpp index 34f5e6a..d959c7a 100644 --- a/library/qpeapplication.cpp +++ b/library/qpeapplication.cpp | |||
@@ -1388,774 +1388,774 @@ void QPEApplication::applyStyle() | |||
1388 | 1388 | ||
1389 | // Set the ScrollBar on the 'right' side but only if the weak symbol is present | 1389 | // Set the ScrollBar on the 'right' side but only if the weak symbol is present |
1390 | if (&qt_left_hand_scrollbars ) | 1390 | if (&qt_left_hand_scrollbars ) |
1391 | qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false ); | 1391 | qt_left_hand_scrollbars = config.readBoolEntry( "LeftHand", false ); |
1392 | 1392 | ||
1393 | // Window Decoration | 1393 | // Window Decoration |
1394 | QString dec = config.readEntry( "Decoration", "Flat" ); | 1394 | QString dec = config.readEntry( "Decoration", "Flat" ); |
1395 | 1395 | ||
1396 | if ( dec != d->decorationName ) { | 1396 | if ( dec != d->decorationName ) { |
1397 | qwsSetDecoration( new QPEDecoration( dec ) ); | 1397 | qwsSetDecoration( new QPEDecoration( dec ) ); |
1398 | d->decorationName = dec; | 1398 | d->decorationName = dec; |
1399 | } | 1399 | } |
1400 | 1400 | ||
1401 | // Font | 1401 | // Font |
1402 | QString ff = config.readEntry( "FontFamily", font().family() ); | 1402 | QString ff = config.readEntry( "FontFamily", font().family() ); |
1403 | int fs = config.readNumEntry( "FontSize", font().pointSize() ); | 1403 | int fs = config.readNumEntry( "FontSize", font().pointSize() ); |
1404 | 1404 | ||
1405 | setFont ( QFont ( ff, fs ), true ); | 1405 | setFont ( QFont ( ff, fs ), true ); |
1406 | #endif | 1406 | #endif |
1407 | } | 1407 | } |
1408 | 1408 | ||
1409 | void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) | 1409 | void QPEApplication::systemMessage( const QCString& msg, const QByteArray& data ) |
1410 | { | 1410 | { |
1411 | #ifdef Q_WS_QWS | 1411 | #ifdef Q_WS_QWS |
1412 | QDataStream stream( data, IO_ReadOnly ); | 1412 | QDataStream stream( data, IO_ReadOnly ); |
1413 | if ( msg == "applyStyle()" ) { | 1413 | if ( msg == "applyStyle()" ) { |
1414 | applyStyle(); | 1414 | applyStyle(); |
1415 | } | 1415 | } |
1416 | else if ( msg == "toggleApplicationMenu()" ) { | 1416 | else if ( msg == "toggleApplicationMenu()" ) { |
1417 | QWidget *active = activeWindow ( ); | 1417 | QWidget *active = activeWindow ( ); |
1418 | 1418 | ||
1419 | if ( active ) { | 1419 | if ( active ) { |
1420 | QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); | 1420 | QPEMenuToolFocusManager *man = QPEMenuToolFocusManager::manager ( ); |
1421 | bool oldactive = man-> isActive ( ); | 1421 | bool oldactive = man-> isActive ( ); |
1422 | 1422 | ||
1423 | man-> setActive( !man-> isActive() ); | 1423 | man-> setActive( !man-> isActive() ); |
1424 | 1424 | ||
1425 | if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu | 1425 | if ( !oldactive && !man-> isActive ( )) { // no menubar to toggle -> try O-Menu |
1426 | QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); | 1426 | QCopEnvelope e ( "QPE/TaskBar", "toggleStartMenu()" ); |
1427 | } | 1427 | } |
1428 | } | 1428 | } |
1429 | } | 1429 | } |
1430 | else if ( msg == "setDefaultRotation(int)" ) { | 1430 | else if ( msg == "setDefaultRotation(int)" ) { |
1431 | if ( type() == GuiServer ) { | 1431 | if ( type() == GuiServer ) { |
1432 | int r; | 1432 | int r; |
1433 | stream >> r; | 1433 | stream >> r; |
1434 | setDefaultRotation( r ); | 1434 | setDefaultRotation( r ); |
1435 | } | 1435 | } |
1436 | } | 1436 | } |
1437 | else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net> | 1437 | else if ( msg == "setCurrentMode(int,int,int)" ) { // Added: 2003-06-11 by Tim Ansell <mithro@mithis.net> |
1438 | if ( type() == GuiServer ) { | 1438 | if ( type() == GuiServer ) { |
1439 | int x, y, depth; | 1439 | int x, y, depth; |
1440 | stream >> x; | 1440 | stream >> x; |
1441 | stream >> y; | 1441 | stream >> y; |
1442 | stream >> depth; | 1442 | stream >> depth; |
1443 | setCurrentMode( x, y, depth ); | 1443 | setCurrentMode( x, y, depth ); |
1444 | } | 1444 | } |
1445 | } | 1445 | } |
1446 | else if ( msg == "reset()" ) { | 1446 | else if ( msg == "reset()" ) { |
1447 | if ( type() != GuiServer ) | 1447 | if ( type() != GuiServer ) |
1448 | reset(); | 1448 | reset(); |
1449 | } | 1449 | } |
1450 | else if ( msg == "setCurrentRotation(int)" ) { | 1450 | else if ( msg == "setCurrentRotation(int)" ) { |
1451 | int r; | 1451 | int r; |
1452 | stream >> r; | 1452 | stream >> r; |
1453 | setCurrentRotation( r ); | 1453 | setCurrentRotation( r ); |
1454 | } | 1454 | } |
1455 | else if ( msg == "shutdown()" ) { | 1455 | else if ( msg == "shutdown()" ) { |
1456 | if ( type() == GuiServer ) | 1456 | if ( type() == GuiServer ) |
1457 | shutdown(); | 1457 | shutdown(); |
1458 | } | 1458 | } |
1459 | else if ( msg == "quit()" ) { | 1459 | else if ( msg == "quit()" ) { |
1460 | if ( type() != GuiServer ) | 1460 | if ( type() != GuiServer ) |
1461 | tryQuit(); | 1461 | tryQuit(); |
1462 | } | 1462 | } |
1463 | else if ( msg == "forceQuit()" ) { | 1463 | else if ( msg == "forceQuit()" ) { |
1464 | if ( type() != GuiServer ) | 1464 | if ( type() != GuiServer ) |
1465 | quit(); | 1465 | quit(); |
1466 | } | 1466 | } |
1467 | else if ( msg == "restart()" ) { | 1467 | else if ( msg == "restart()" ) { |
1468 | if ( type() == GuiServer ) | 1468 | if ( type() == GuiServer ) |
1469 | restart(); | 1469 | restart(); |
1470 | } | 1470 | } |
1471 | else if ( msg == "language(QString)" ) { | 1471 | else if ( msg == "language(QString)" ) { |
1472 | if ( type() == GuiServer ) { | 1472 | if ( type() == GuiServer ) { |
1473 | QString l; | 1473 | QString l; |
1474 | stream >> l; | 1474 | stream >> l; |
1475 | QString cl = getenv( "LANG" ); | 1475 | QString cl = getenv( "LANG" ); |
1476 | if ( cl != l ) { | 1476 | if ( cl != l ) { |
1477 | if ( l.isNull() ) | 1477 | if ( l.isNull() ) |
1478 | unsetenv( "LANG" ); | 1478 | unsetenv( "LANG" ); |
1479 | else | 1479 | else |
1480 | setenv( "LANG", l.latin1(), 1 ); | 1480 | setenv( "LANG", l.latin1(), 1 ); |
1481 | restart(); | 1481 | restart(); |
1482 | } | 1482 | } |
1483 | } | 1483 | } |
1484 | } | 1484 | } |
1485 | else if ( msg == "timeChange(QString)" ) { | 1485 | else if ( msg == "timeChange(QString)" ) { |
1486 | QString t; | 1486 | QString t; |
1487 | stream >> t; | 1487 | stream >> t; |
1488 | if ( t.isNull() ) | 1488 | if ( t.isNull() ) |
1489 | unsetenv( "TZ" ); | 1489 | unsetenv( "TZ" ); |
1490 | else | 1490 | else |
1491 | setenv( "TZ", t.latin1(), 1 ); | 1491 | setenv( "TZ", t.latin1(), 1 ); |
1492 | // emit the signal so everyone else knows... | 1492 | // emit the signal so everyone else knows... |
1493 | emit timeChanged(); | 1493 | emit timeChanged(); |
1494 | } | 1494 | } |
1495 | else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { | 1495 | else if ( msg == "addAlarm(QDateTime,QCString,QCString,int)" ) { |
1496 | if ( type() == GuiServer ) { | 1496 | if ( type() == GuiServer ) { |
1497 | QDateTime when; | 1497 | QDateTime when; |
1498 | QCString channel, message; | 1498 | QCString channel, message; |
1499 | int data; | 1499 | int data; |
1500 | stream >> when >> channel >> message >> data; | 1500 | stream >> when >> channel >> message >> data; |
1501 | AlarmServer::addAlarm( when, channel, message, data ); | 1501 | AlarmServer::addAlarm( when, channel, message, data ); |
1502 | } | 1502 | } |
1503 | } | 1503 | } |
1504 | else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { | 1504 | else if ( msg == "deleteAlarm(QDateTime,QCString,QCString,int)" ) { |
1505 | if ( type() == GuiServer ) { | 1505 | if ( type() == GuiServer ) { |
1506 | QDateTime when; | 1506 | QDateTime when; |
1507 | QCString channel, message; | 1507 | QCString channel, message; |
1508 | int data; | 1508 | int data; |
1509 | stream >> when >> channel >> message >> data; | 1509 | stream >> when >> channel >> message >> data; |
1510 | AlarmServer::deleteAlarm( when, channel, message, data ); | 1510 | AlarmServer::deleteAlarm( when, channel, message, data ); |
1511 | } | 1511 | } |
1512 | } | 1512 | } |
1513 | else if ( msg == "clockChange(bool)" ) { | 1513 | else if ( msg == "clockChange(bool)" ) { |
1514 | int tmp; | 1514 | int tmp; |
1515 | stream >> tmp; | 1515 | stream >> tmp; |
1516 | emit clockChanged( tmp ); | 1516 | emit clockChanged( tmp ); |
1517 | } | 1517 | } |
1518 | else if ( msg == "weekChange(bool)" ) { | 1518 | else if ( msg == "weekChange(bool)" ) { |
1519 | int tmp; | 1519 | int tmp; |
1520 | stream >> tmp; | 1520 | stream >> tmp; |
1521 | emit weekChanged( tmp ); | 1521 | emit weekChanged( tmp ); |
1522 | } | 1522 | } |
1523 | else if ( msg == "setDateFormat(DateFormat)" ) { | 1523 | else if ( msg == "setDateFormat(DateFormat)" ) { |
1524 | DateFormat tmp; | 1524 | DateFormat tmp; |
1525 | stream >> tmp; | 1525 | stream >> tmp; |
1526 | emit dateFormatChanged( tmp ); | 1526 | emit dateFormatChanged( tmp ); |
1527 | } | 1527 | } |
1528 | else if ( msg == "setVolume(int,int)" ) { | 1528 | else if ( msg == "setVolume(int,int)" ) { |
1529 | int t, v; | 1529 | int t, v; |
1530 | stream >> t >> v; | 1530 | stream >> t >> v; |
1531 | setVolume( t, v ); | 1531 | setVolume( t, v ); |
1532 | emit volumeChanged( muted ); | 1532 | emit volumeChanged( muted ); |
1533 | } | 1533 | } |
1534 | else if ( msg == "volumeChange(bool)" ) { | 1534 | else if ( msg == "volumeChange(bool)" ) { |
1535 | stream >> muted; | 1535 | stream >> muted; |
1536 | setVolume(); | 1536 | setVolume(); |
1537 | emit volumeChanged( muted ); | 1537 | emit volumeChanged( muted ); |
1538 | } | 1538 | } |
1539 | else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> | 1539 | else if ( msg == "setMic(int,int)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> |
1540 | int t, v; | 1540 | int t, v; |
1541 | stream >> t >> v; | 1541 | stream >> t >> v; |
1542 | setMic( t, v ); | 1542 | setMic( t, v ); |
1543 | emit micChanged( micMuted ); | 1543 | emit micChanged( micMuted ); |
1544 | } | 1544 | } |
1545 | else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> | 1545 | else if ( msg == "micChange(bool)" ) { // Added: 2002-02-08 by Jeremy Cowgar <jc@cowgar.com> |
1546 | stream >> micMuted; | 1546 | stream >> micMuted; |
1547 | setMic(); | 1547 | setMic(); |
1548 | emit micChanged( micMuted ); | 1548 | emit micChanged( micMuted ); |
1549 | } | 1549 | } |
1550 | else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> | 1550 | else if ( msg == "setBass(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> |
1551 | int t, v; | 1551 | int t, v; |
1552 | stream >> t >> v; | 1552 | stream >> t >> v; |
1553 | setBass( t, v ); | 1553 | setBass( t, v ); |
1554 | } | 1554 | } |
1555 | else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> | 1555 | else if ( msg == "bassChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> |
1556 | setBass(); | 1556 | setBass(); |
1557 | } | 1557 | } |
1558 | else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> | 1558 | else if ( msg == "setTreble(int,int)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> |
1559 | int t, v; | 1559 | int t, v; |
1560 | stream >> t >> v; | 1560 | stream >> t >> v; |
1561 | setTreble( t, v ); | 1561 | setTreble( t, v ); |
1562 | } | 1562 | } |
1563 | else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> | 1563 | else if ( msg == "trebleChange(bool)" ) { // Added: 2002-12-13 by Maximilian Reiss <harlekin@handhelds.org> |
1564 | setTreble(); | 1564 | setTreble(); |
1565 | } else if ( msg == "getMarkedText()" ) { | 1565 | } else if ( msg == "getMarkedText()" ) { |
1566 | if ( type() == GuiServer ) { | 1566 | if ( type() == GuiServer ) { |
1567 | const ushort unicode = 'C'-'@'; | 1567 | const ushort unicode = 'C'-'@'; |
1568 | const int scan = Key_C; | 1568 | const int scan = Key_C; |
1569 | qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE ); | 1569 | qwsServer->processKeyEvent( unicode, scan, ControlButton, TRUE, FALSE ); |
1570 | qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE ); | 1570 | qwsServer->processKeyEvent( unicode, scan, ControlButton, FALSE, FALSE ); |
1571 | } | 1571 | } |
1572 | } else if ( msg == "newChannel(QString)") { | 1572 | } else if ( msg == "newChannel(QString)") { |
1573 | QString myChannel = "QPE/Application/" + d->appName; | 1573 | QString myChannel = "QPE/Application/" + d->appName; |
1574 | QString channel; | 1574 | QString channel; |
1575 | stream >> channel; | 1575 | stream >> channel; |
1576 | if (channel == myChannel) { | 1576 | if (channel == myChannel) { |
1577 | processQCopFile(); | 1577 | processQCopFile(); |
1578 | d->sendQCopQ(); | 1578 | d->sendQCopQ(); |
1579 | } | 1579 | } |
1580 | } | 1580 | } |
1581 | 1581 | ||
1582 | 1582 | ||
1583 | #endif | 1583 | #endif |
1584 | } | 1584 | } |
1585 | 1585 | ||
1586 | 1586 | ||
1587 | 1587 | ||
1588 | 1588 | ||
1589 | 1589 | ||
1590 | /*! | 1590 | /*! |
1591 | \internal | 1591 | \internal |
1592 | */ | 1592 | */ |
1593 | bool QPEApplication::raiseAppropriateWindow() | 1593 | bool QPEApplication::raiseAppropriateWindow() |
1594 | { | 1594 | { |
1595 | bool r=FALSE; | 1595 | bool r=FALSE; |
1596 | 1596 | ||
1597 | // 1. Raise the main widget | 1597 | // 1. Raise the main widget |
1598 | QWidget *top = d->qpe_main_widget; | 1598 | QWidget *top = d->qpe_main_widget; |
1599 | if ( !top ) top = mainWidget(); | 1599 | if ( !top ) top = mainWidget(); |
1600 | 1600 | ||
1601 | if ( top && d->keep_running ) { | 1601 | if ( top && d->keep_running ) { |
1602 | if ( top->isVisible() ) | 1602 | if ( top->isVisible() ) |
1603 | r = TRUE; | 1603 | r = TRUE; |
1604 | else if (d->preloaded) { | 1604 | else if (d->preloaded) { |
1605 | // We are preloaded and not visible.. pretend we just started.. | 1605 | // We are preloaded and not visible.. pretend we just started.. |
1606 | #ifndef QT_NO_COP | 1606 | #ifndef QT_NO_COP |
1607 | QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); | 1607 | QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); |
1608 | e << d->appName; | 1608 | e << d->appName; |
1609 | #endif | 1609 | #endif |
1610 | } | 1610 | } |
1611 | 1611 | ||
1612 | d->show_mx(top,d->nomaximize, d->appName); | 1612 | d->show_mx(top,d->nomaximize, d->appName); |
1613 | top->raise(); | 1613 | top->raise(); |
1614 | } | 1614 | } |
1615 | 1615 | ||
1616 | QWidget *topm = activeModalWidget(); | 1616 | QWidget *topm = activeModalWidget(); |
1617 | 1617 | ||
1618 | // 2. Raise any parentless widgets (except top and topm, as they | 1618 | // 2. Raise any parentless widgets (except top and topm, as they |
1619 | // are raised before and after this loop). Order from most | 1619 | // are raised before and after this loop). Order from most |
1620 | // recently raised as deepest to least recently as top, so | 1620 | // recently raised as deepest to least recently as top, so |
1621 | // that repeated calls cycle through widgets. | 1621 | // that repeated calls cycle through widgets. |
1622 | QWidgetList *list = topLevelWidgets(); | 1622 | QWidgetList *list = topLevelWidgets(); |
1623 | if ( list ) { | 1623 | if ( list ) { |
1624 | bool foundlast = FALSE; | 1624 | bool foundlast = FALSE; |
1625 | QWidget* topsub = 0; | 1625 | QWidget* topsub = 0; |
1626 | if ( d->lastraised ) { | 1626 | if ( d->lastraised ) { |
1627 | for (QWidget* w = list->first(); w; w = list->next()) { | 1627 | for (QWidget* w = list->first(); w; w = list->next()) { |
1628 | if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { | 1628 | if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { |
1629 | if ( w == d->lastraised ) | 1629 | if ( w == d->lastraised ) |
1630 | foundlast = TRUE; | 1630 | foundlast = TRUE; |
1631 | if ( foundlast ) { | 1631 | if ( foundlast ) { |
1632 | w->raise(); | 1632 | w->raise(); |
1633 | topsub = w; | 1633 | topsub = w; |
1634 | } | 1634 | } |
1635 | } | 1635 | } |
1636 | } | 1636 | } |
1637 | } | 1637 | } |
1638 | for (QWidget* w = list->first(); w; w = list->next()) { | 1638 | for (QWidget* w = list->first(); w; w = list->next()) { |
1639 | if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { | 1639 | if ( !w->parentWidget() && w != topm && w->isVisible() && !w->isDesktop() ) { |
1640 | if ( w == d->lastraised ) | 1640 | if ( w == d->lastraised ) |
1641 | break; | 1641 | break; |
1642 | w->raise(); | 1642 | w->raise(); |
1643 | topsub = w; | 1643 | topsub = w; |
1644 | } | 1644 | } |
1645 | } | 1645 | } |
1646 | d->lastraised = topsub; | 1646 | d->lastraised = topsub; |
1647 | delete list; | 1647 | delete list; |
1648 | } | 1648 | } |
1649 | 1649 | ||
1650 | // 3. Raise the active modal widget. | 1650 | // 3. Raise the active modal widget. |
1651 | if ( topm ) { | 1651 | if ( topm ) { |
1652 | topm->show(); | 1652 | topm->show(); |
1653 | topm->raise(); | 1653 | topm->raise(); |
1654 | // If we haven't already handled the fastAppShowing message | 1654 | // If we haven't already handled the fastAppShowing message |
1655 | if (!top && d->preloaded) { | 1655 | if (!top && d->preloaded) { |
1656 | #ifndef QT_NO_COP | 1656 | #ifndef QT_NO_COP |
1657 | QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); | 1657 | QCopEnvelope e("QPE/System", "fastAppShowing(QString)"); |
1658 | e << d->appName; | 1658 | e << d->appName; |
1659 | #endif | 1659 | #endif |
1660 | } | 1660 | } |
1661 | r = FALSE; | 1661 | r = FALSE; |
1662 | } | 1662 | } |
1663 | 1663 | ||
1664 | return r; | 1664 | return r; |
1665 | } | 1665 | } |
1666 | 1666 | ||
1667 | 1667 | ||
1668 | void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) | 1668 | void QPEApplication::pidMessage( const QCString& msg, const QByteArray& data) |
1669 | { | 1669 | { |
1670 | #ifdef Q_WS_QWS | 1670 | #ifdef Q_WS_QWS |
1671 | 1671 | ||
1672 | if ( msg == "quit()" ) { | 1672 | if ( msg == "quit()" ) { |
1673 | tryQuit(); | 1673 | tryQuit(); |
1674 | } | 1674 | } |
1675 | else if ( msg == "quitIfInvisible()" ) { | 1675 | else if ( msg == "quitIfInvisible()" ) { |
1676 | if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) | 1676 | if ( d->qpe_main_widget && !d->qpe_main_widget->isVisible() ) |
1677 | quit(); | 1677 | quit(); |
1678 | } | 1678 | } |
1679 | else if ( msg == "close()" ) { | 1679 | else if ( msg == "close()" ) { |
1680 | hideOrQuit(); | 1680 | hideOrQuit(); |
1681 | } | 1681 | } |
1682 | else if ( msg == "disablePreload()" ) { | 1682 | else if ( msg == "disablePreload()" ) { |
1683 | d->preloaded = FALSE; | 1683 | d->preloaded = FALSE; |
1684 | d->keep_running = TRUE; | 1684 | d->keep_running = TRUE; |
1685 | /* so that quit will quit */ | 1685 | /* so that quit will quit */ |
1686 | } | 1686 | } |
1687 | else if ( msg == "enablePreload()" ) { | 1687 | else if ( msg == "enablePreload()" ) { |
1688 | if (d->qpe_main_widget) | 1688 | if (d->qpe_main_widget) |
1689 | d->preloaded = TRUE; | 1689 | d->preloaded = TRUE; |
1690 | d->keep_running = TRUE; | 1690 | d->keep_running = TRUE; |
1691 | /* so next quit won't quit */ | 1691 | /* so next quit won't quit */ |
1692 | } | 1692 | } |
1693 | else if ( msg == "raise()" ) { | 1693 | else if ( msg == "raise()" ) { |
1694 | d->keep_running = TRUE; | 1694 | d->keep_running = TRUE; |
1695 | d->notbusysent = FALSE; | 1695 | d->notbusysent = FALSE; |
1696 | raiseAppropriateWindow(); | 1696 | raiseAppropriateWindow(); |
1697 | // Tell the system we're still chugging along... | 1697 | // Tell the system we're still chugging along... |
1698 | QCopEnvelope e("QPE/System", "appRaised(QString)"); | 1698 | QCopEnvelope e("QPE/System", "appRaised(QString)"); |
1699 | e << d->appName; | 1699 | e << d->appName; |
1700 | } | 1700 | } |
1701 | else if ( msg == "flush()" ) { | 1701 | else if ( msg == "flush()" ) { |
1702 | emit flush(); | 1702 | emit flush(); |
1703 | // we need to tell the desktop | 1703 | // we need to tell the desktop |
1704 | QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); | 1704 | QCopEnvelope e( "QPE/Desktop", "flushDone(QString)" ); |
1705 | e << d->appName; | 1705 | e << d->appName; |
1706 | } | 1706 | } |
1707 | else if ( msg == "reload()" ) { | 1707 | else if ( msg == "reload()" ) { |
1708 | emit reload(); | 1708 | emit reload(); |
1709 | } | 1709 | } |
1710 | else if ( msg == "setDocument(QString)" ) { | 1710 | else if ( msg == "setDocument(QString)" ) { |
1711 | d->keep_running = TRUE; | 1711 | d->keep_running = TRUE; |
1712 | QDataStream stream( data, IO_ReadOnly ); | 1712 | QDataStream stream( data, IO_ReadOnly ); |
1713 | QString doc; | 1713 | QString doc; |
1714 | stream >> doc; | 1714 | stream >> doc; |
1715 | QWidget *mw = mainWidget(); | 1715 | QWidget *mw = mainWidget(); |
1716 | if ( !mw ) | 1716 | if ( !mw ) |
1717 | mw = d->qpe_main_widget; | 1717 | mw = d->qpe_main_widget; |
1718 | if ( mw ) | 1718 | if ( mw ) |
1719 | Global::setDocument( mw, doc ); | 1719 | Global::setDocument( mw, doc ); |
1720 | 1720 | ||
1721 | } else if ( msg == "QPEProcessQCop()" ) { | 1721 | } else if ( msg == "QPEProcessQCop()" ) { |
1722 | processQCopFile(); | 1722 | processQCopFile(); |
1723 | d->sendQCopQ(); | 1723 | d->sendQCopQ(); |
1724 | }else | 1724 | }else |
1725 | { | 1725 | { |
1726 | bool p = d->keep_running; | 1726 | bool p = d->keep_running; |
1727 | d->keep_running = FALSE; | 1727 | d->keep_running = FALSE; |
1728 | emit appMessage( msg, data); | 1728 | emit appMessage( msg, data); |
1729 | if ( d->keep_running ) { | 1729 | if ( d->keep_running ) { |
1730 | d->notbusysent = FALSE; | 1730 | d->notbusysent = FALSE; |
1731 | raiseAppropriateWindow(); | 1731 | raiseAppropriateWindow(); |
1732 | if ( !p ) { | 1732 | if ( !p ) { |
1733 | // Tell the system we're still chugging along... | 1733 | // Tell the system we're still chugging along... |
1734 | #ifndef QT_NO_COP | 1734 | #ifndef QT_NO_COP |
1735 | QCopEnvelope e("QPE/System", "appRaised(QString)"); | 1735 | QCopEnvelope e("QPE/System", "appRaised(QString)"); |
1736 | e << d->appName; | 1736 | e << d->appName; |
1737 | #endif | 1737 | #endif |
1738 | } | 1738 | } |
1739 | } | 1739 | } |
1740 | if ( p ) | 1740 | if ( p ) |
1741 | d->keep_running = p; | 1741 | d->keep_running = p; |
1742 | } | 1742 | } |
1743 | #endif | 1743 | #endif |
1744 | } | 1744 | } |
1745 | 1745 | ||
1746 | 1746 | ||
1747 | /*! | 1747 | /*! |
1748 | Sets widget \a mw as the mainWidget() and shows it. For small windows, | 1748 | Sets widget \a mw as the mainWidget() and shows it. For small windows, |
1749 | consider passing TRUE for \a nomaximize rather than the default FALSE. | 1749 | consider passing TRUE for \a nomaximize rather than the default FALSE. |
1750 | 1750 | ||
1751 | \sa showMainDocumentWidget() | 1751 | \sa showMainDocumentWidget() |
1752 | */ | 1752 | */ |
1753 | void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) | 1753 | void QPEApplication::showMainWidget( QWidget* mw, bool nomaximize ) |
1754 | { | 1754 | { |
1755 | // setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit | 1755 | // setMainWidget(mw); this breaks FastLoading because lastWindowClose() would quit |
1756 | d->show(mw, nomaximize ); | 1756 | d->show(mw, nomaximize ); |
1757 | } | 1757 | } |
1758 | 1758 | ||
1759 | /*! | 1759 | /*! |
1760 | Sets widget \a mw as the mainWidget() and shows it. For small windows, | 1760 | Sets widget \a mw as the mainWidget() and shows it. For small windows, |
1761 | consider passing TRUE for \a nomaximize rather than the default FALSE. | 1761 | consider passing TRUE for \a nomaximize rather than the default FALSE. |
1762 | 1762 | ||
1763 | This calls designates the application as | 1763 | This calls designates the application as |
1764 | a \link docwidget.html document-oriented\endlink application. | 1764 | a \link docwidget.html document-oriented\endlink application. |
1765 | 1765 | ||
1766 | The \a mw widget \e must have this slot: setDocument(const QString&). | 1766 | The \a mw widget \e must have this slot: setDocument(const QString&). |
1767 | 1767 | ||
1768 | \sa showMainWidget() | 1768 | \sa showMainWidget() |
1769 | */ | 1769 | */ |
1770 | void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) | 1770 | void QPEApplication::showMainDocumentWidget( QWidget* mw, bool nomaximize ) |
1771 | { | 1771 | { |
1772 | if ( mw && argc() == 2 ) | 1772 | if ( mw ) { |
1773 | Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); | 1773 | if ( argc() == 2 ) |
1774 | Global::setDocument( mw, QString::fromUtf8(argv()[1]) ); | ||
1774 | 1775 | ||
1775 | 1776 | d->show(mw, nomaximize ); | |
1776 | // setMainWidget(mw); see above | 1777 | } |
1777 | d->show(mw, nomaximize ); | ||
1778 | } | 1778 | } |
1779 | 1779 | ||
1780 | 1780 | ||
1781 | /*! | 1781 | /*! |
1782 | If an application is started via a \link qcop.html QCop\endlink | 1782 | If an application is started via a \link qcop.html QCop\endlink |
1783 | message, the application will process the \link qcop.html | 1783 | message, the application will process the \link qcop.html |
1784 | QCop\endlink message and then quit. If the application calls this | 1784 | QCop\endlink message and then quit. If the application calls this |
1785 | function while processing a \link qcop.html QCop\endlink message, | 1785 | function while processing a \link qcop.html QCop\endlink message, |
1786 | after processing its outstanding \link qcop.html QCop\endlink | 1786 | after processing its outstanding \link qcop.html QCop\endlink |
1787 | messages the application will start 'properly' and show itself. | 1787 | messages the application will start 'properly' and show itself. |
1788 | 1788 | ||
1789 | \sa keepRunning() | 1789 | \sa keepRunning() |
1790 | */ | 1790 | */ |
1791 | void QPEApplication::setKeepRunning() | 1791 | void QPEApplication::setKeepRunning() |
1792 | { | 1792 | { |
1793 | if ( qApp && qApp->inherits( "QPEApplication" ) ) { | 1793 | if ( qApp && qApp->inherits( "QPEApplication" ) ) { |
1794 | QPEApplication * qpeApp = ( QPEApplication* ) qApp; | 1794 | QPEApplication * qpeApp = ( QPEApplication* ) qApp; |
1795 | qpeApp->d->keep_running = TRUE; | 1795 | qpeApp->d->keep_running = TRUE; |
1796 | } | 1796 | } |
1797 | } | 1797 | } |
1798 | 1798 | ||
1799 | /*! | 1799 | /*! |
1800 | Returns TRUE if the application will quit after processing the | 1800 | Returns TRUE if the application will quit after processing the |
1801 | current list of qcop messages; otherwise returns FALSE. | 1801 | current list of qcop messages; otherwise returns FALSE. |
1802 | 1802 | ||
1803 | \sa setKeepRunning() | 1803 | \sa setKeepRunning() |
1804 | */ | 1804 | */ |
1805 | bool QPEApplication::keepRunning() const | 1805 | bool QPEApplication::keepRunning() const |
1806 | { | 1806 | { |
1807 | return d->keep_running; | 1807 | return d->keep_running; |
1808 | } | 1808 | } |
1809 | 1809 | ||
1810 | /*! | 1810 | /*! |
1811 | \internal | 1811 | \internal |
1812 | */ | 1812 | */ |
1813 | void QPEApplication::internalSetStyle( const QString &style ) | 1813 | void QPEApplication::internalSetStyle( const QString &style ) |
1814 | { | 1814 | { |
1815 | #if QT_VERSION >= 0x030000 | 1815 | #if QT_VERSION >= 0x030000 |
1816 | if ( style == "QPE" ) { | 1816 | if ( style == "QPE" ) { |
1817 | setStyle( new QPEStyle ); | 1817 | setStyle( new QPEStyle ); |
1818 | } | 1818 | } |
1819 | else { | 1819 | else { |
1820 | QStyle *s = QStyleFactory::create( style ); | 1820 | QStyle *s = QStyleFactory::create( style ); |
1821 | if ( s ) | 1821 | if ( s ) |
1822 | setStyle( s ); | 1822 | setStyle( s ); |
1823 | } | 1823 | } |
1824 | #else | 1824 | #else |
1825 | if ( style == "Windows" ) { | 1825 | if ( style == "Windows" ) { |
1826 | setStyle( new QWindowsStyle ); | 1826 | setStyle( new QWindowsStyle ); |
1827 | } | 1827 | } |
1828 | else if ( style == "QPE" ) { | 1828 | else if ( style == "QPE" ) { |
1829 | setStyle( new QPEStyle ); | 1829 | setStyle( new QPEStyle ); |
1830 | } | 1830 | } |
1831 | else if ( style == "Light" ) { | 1831 | else if ( style == "Light" ) { |
1832 | setStyle( new LightStyle ); | 1832 | setStyle( new LightStyle ); |
1833 | } | 1833 | } |
1834 | #ifndef QT_NO_STYLE_PLATINUM | 1834 | #ifndef QT_NO_STYLE_PLATINUM |
1835 | else if ( style == "Platinum" ) { | 1835 | else if ( style == "Platinum" ) { |
1836 | setStyle( new QPlatinumStyle ); | 1836 | setStyle( new QPlatinumStyle ); |
1837 | } | 1837 | } |
1838 | #endif | 1838 | #endif |
1839 | #ifndef QT_NO_STYLE_MOTIF | 1839 | #ifndef QT_NO_STYLE_MOTIF |
1840 | else if ( style == "Motif" ) { | 1840 | else if ( style == "Motif" ) { |
1841 | setStyle( new QMotifStyle ); | 1841 | setStyle( new QMotifStyle ); |
1842 | } | 1842 | } |
1843 | #endif | 1843 | #endif |
1844 | #ifndef QT_NO_STYLE_MOTIFPLUS | 1844 | #ifndef QT_NO_STYLE_MOTIFPLUS |
1845 | else if ( style == "MotifPlus" ) { | 1845 | else if ( style == "MotifPlus" ) { |
1846 | setStyle( new QMotifPlusStyle ); | 1846 | setStyle( new QMotifPlusStyle ); |
1847 | } | 1847 | } |
1848 | #endif | 1848 | #endif |
1849 | 1849 | ||
1850 | else { | 1850 | else { |
1851 | QStyle *sty = 0; | 1851 | QStyle *sty = 0; |
1852 | QString path = QPEApplication::qpeDir ( ) + "plugins/styles/"; | 1852 | QString path = QPEApplication::qpeDir ( ) + "plugins/styles/"; |
1853 | 1853 | ||
1854 | #ifdef Q_OS_MACX | 1854 | #ifdef Q_OS_MACX |
1855 | if ( style. find ( ".dylib" ) > 0 ) | 1855 | if ( style. find ( ".dylib" ) > 0 ) |
1856 | path += style; | 1856 | path += style; |
1857 | else | 1857 | else |
1858 | path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility | 1858 | path = path + "lib" + style. lower ( ) + ".dylib"; // compatibility |
1859 | #else | 1859 | #else |
1860 | if ( style. find ( ".so" ) > 0 ) | 1860 | if ( style. find ( ".so" ) > 0 ) |
1861 | path += style; | 1861 | path += style; |
1862 | else | 1862 | else |
1863 | path = path + "lib" + style. lower ( ) + ".so"; // compatibility | 1863 | path = path + "lib" + style. lower ( ) + ".so"; // compatibility |
1864 | #endif | 1864 | #endif |
1865 | static QLibrary *lastlib = 0; | 1865 | static QLibrary *lastlib = 0; |
1866 | static StyleInterface *lastiface = 0; | 1866 | static StyleInterface *lastiface = 0; |
1867 | 1867 | ||
1868 | QLibrary *lib = new QLibrary ( path ); | 1868 | QLibrary *lib = new QLibrary ( path ); |
1869 | StyleInterface *iface = 0; | 1869 | StyleInterface *iface = 0; |
1870 | 1870 | ||
1871 | if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) | 1871 | if (( lib-> queryInterface ( IID_Style, ( QUnknownInterface ** ) &iface ) == QS_OK ) && iface ) |
1872 | sty = iface-> style ( ); | 1872 | sty = iface-> style ( ); |
1873 | 1873 | ||
1874 | if ( sty ) { | 1874 | if ( sty ) { |
1875 | setStyle ( sty ); | 1875 | setStyle ( sty ); |
1876 | 1876 | ||
1877 | if ( lastiface ) | 1877 | if ( lastiface ) |
1878 | lastiface-> release ( ); | 1878 | lastiface-> release ( ); |
1879 | lastiface = iface; | 1879 | lastiface = iface; |
1880 | 1880 | ||
1881 | if ( lastlib ) { | 1881 | if ( lastlib ) { |
1882 | lastlib-> unload ( ); | 1882 | lastlib-> unload ( ); |
1883 | delete lastlib; | 1883 | delete lastlib; |
1884 | } | 1884 | } |
1885 | lastlib = lib; | 1885 | lastlib = lib; |
1886 | } | 1886 | } |
1887 | else { | 1887 | else { |
1888 | if ( iface ) | 1888 | if ( iface ) |
1889 | iface-> release ( ); | 1889 | iface-> release ( ); |
1890 | delete lib; | 1890 | delete lib; |
1891 | 1891 | ||
1892 | setStyle ( new LightStyle ( )); | 1892 | setStyle ( new LightStyle ( )); |
1893 | } | 1893 | } |
1894 | } | 1894 | } |
1895 | #endif | 1895 | #endif |
1896 | } | 1896 | } |
1897 | 1897 | ||
1898 | /*! | 1898 | /*! |
1899 | \internal | 1899 | \internal |
1900 | */ | 1900 | */ |
1901 | void QPEApplication::prepareForTermination( bool willrestart ) | 1901 | void QPEApplication::prepareForTermination( bool willrestart ) |
1902 | { | 1902 | { |
1903 | if ( willrestart ) { | 1903 | if ( willrestart ) { |
1904 | QLabel *lblWait = new QLabel( tr( "Please wait..." ), 0, "wait hack", QWidget::WStyle_Customize | | 1904 | QLabel *lblWait = new QLabel( tr( "Please wait..." ), 0, "wait hack", QWidget::WStyle_Customize | |
1905 | QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); | 1905 | QWidget::WStyle_NoBorder | QWidget::WStyle_Tool ); |
1906 | lblWait->setAlignment( QWidget::AlignCenter ); | 1906 | lblWait->setAlignment( QWidget::AlignCenter ); |
1907 | lblWait->show(); | 1907 | lblWait->show(); |
1908 | lblWait->showMaximized(); | 1908 | lblWait->showMaximized(); |
1909 | } | 1909 | } |
1910 | { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); | 1910 | { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); |
1911 | } | 1911 | } |
1912 | processEvents(); // ensure the message goes out. | 1912 | processEvents(); // ensure the message goes out. |
1913 | } | 1913 | } |
1914 | 1914 | ||
1915 | /*! | 1915 | /*! |
1916 | \internal | 1916 | \internal |
1917 | */ | 1917 | */ |
1918 | void QPEApplication::shutdown() | 1918 | void QPEApplication::shutdown() |
1919 | { | 1919 | { |
1920 | // Implement in server's QPEApplication subclass | 1920 | // Implement in server's QPEApplication subclass |
1921 | } | 1921 | } |
1922 | 1922 | ||
1923 | /*! | 1923 | /*! |
1924 | \internal | 1924 | \internal |
1925 | */ | 1925 | */ |
1926 | void QPEApplication::restart() | 1926 | void QPEApplication::restart() |
1927 | { | 1927 | { |
1928 | // Implement in server's QPEApplication subclass | 1928 | // Implement in server's QPEApplication subclass |
1929 | } | 1929 | } |
1930 | 1930 | ||
1931 | static QPtrDict<void>* stylusDict = 0; | 1931 | static QPtrDict<void>* stylusDict = 0; |
1932 | static void createDict() | 1932 | static void createDict() |
1933 | { | 1933 | { |
1934 | if ( !stylusDict ) | 1934 | if ( !stylusDict ) |
1935 | stylusDict = new QPtrDict<void>; | 1935 | stylusDict = new QPtrDict<void>; |
1936 | } | 1936 | } |
1937 | 1937 | ||
1938 | /*! | 1938 | /*! |
1939 | Returns the current StylusMode for widget \a w. | 1939 | Returns the current StylusMode for widget \a w. |
1940 | 1940 | ||
1941 | \sa setStylusOperation() StylusMode | 1941 | \sa setStylusOperation() StylusMode |
1942 | */ | 1942 | */ |
1943 | QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) | 1943 | QPEApplication::StylusMode QPEApplication::stylusOperation( QWidget* w ) |
1944 | { | 1944 | { |
1945 | if ( stylusDict ) | 1945 | if ( stylusDict ) |
1946 | return ( StylusMode ) ( int ) stylusDict->find( w ); | 1946 | return ( StylusMode ) ( int ) stylusDict->find( w ); |
1947 | return LeftOnly; | 1947 | return LeftOnly; |
1948 | } | 1948 | } |
1949 | 1949 | ||
1950 | /*! | 1950 | /*! |
1951 | \enum QPEApplication::StylusMode | 1951 | \enum QPEApplication::StylusMode |
1952 | 1952 | ||
1953 | \value LeftOnly the stylus only generates LeftButton | 1953 | \value LeftOnly the stylus only generates LeftButton |
1954 | events (the default). | 1954 | events (the default). |
1955 | \value RightOnHold the stylus generates RightButton events | 1955 | \value RightOnHold the stylus generates RightButton events |
1956 | if the user uses the press-and-hold gesture. | 1956 | if the user uses the press-and-hold gesture. |
1957 | 1957 | ||
1958 | \sa setStylusOperation() stylusOperation() | 1958 | \sa setStylusOperation() stylusOperation() |
1959 | */ | 1959 | */ |
1960 | 1960 | ||
1961 | /*! | 1961 | /*! |
1962 | Causes widget \a w to receive mouse events according to the stylus | 1962 | Causes widget \a w to receive mouse events according to the stylus |
1963 | \a mode. | 1963 | \a mode. |
1964 | 1964 | ||
1965 | \sa stylusOperation() StylusMode | 1965 | \sa stylusOperation() StylusMode |
1966 | */ | 1966 | */ |
1967 | void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) | 1967 | void QPEApplication::setStylusOperation( QWidget * w, StylusMode mode ) |
1968 | { | 1968 | { |
1969 | createDict(); | 1969 | createDict(); |
1970 | if ( mode == LeftOnly ) { | 1970 | if ( mode == LeftOnly ) { |
1971 | stylusDict->remove | 1971 | stylusDict->remove |
1972 | ( w ); | 1972 | ( w ); |
1973 | w->removeEventFilter( qApp ); | 1973 | w->removeEventFilter( qApp ); |
1974 | } | 1974 | } |
1975 | else { | 1975 | else { |
1976 | stylusDict->insert( w, ( void* ) mode ); | 1976 | stylusDict->insert( w, ( void* ) mode ); |
1977 | connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); | 1977 | connect( w, SIGNAL( destroyed() ), qApp, SLOT( removeSenderFromStylusDict() ) ); |
1978 | w->installEventFilter( qApp ); | 1978 | w->installEventFilter( qApp ); |
1979 | } | 1979 | } |
1980 | } | 1980 | } |
1981 | 1981 | ||
1982 | 1982 | ||
1983 | /*! | 1983 | /*! |
1984 | \reimp | 1984 | \reimp |
1985 | */ | 1985 | */ |
1986 | bool QPEApplication::eventFilter( QObject *o, QEvent *e ) | 1986 | bool QPEApplication::eventFilter( QObject *o, QEvent *e ) |
1987 | { | 1987 | { |
1988 | if ( !o->isWidgetType() ) | 1988 | if ( !o->isWidgetType() ) |
1989 | return FALSE; | 1989 | return FALSE; |
1990 | 1990 | ||
1991 | if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { | 1991 | if ( stylusDict && e->type() >= QEvent::MouseButtonPress && e->type() <= QEvent::MouseMove ) { |
1992 | QMouseEvent * me = ( QMouseEvent* ) e; | 1992 | QMouseEvent * me = ( QMouseEvent* ) e; |
1993 | StylusMode mode = (StylusMode)(int)stylusDict->find(o); | 1993 | StylusMode mode = (StylusMode)(int)stylusDict->find(o); |
1994 | switch (mode) { | 1994 | switch (mode) { |
1995 | case RightOnHold: | 1995 | case RightOnHold: |
1996 | switch ( me->type() ) { | 1996 | switch ( me->type() ) { |
1997 | case QEvent::MouseButtonPress: | 1997 | case QEvent::MouseButtonPress: |
1998 | if ( me->button() == LeftButton ) { | 1998 | if ( me->button() == LeftButton ) { |
1999 | static long Pref = 500; // #### pref. | 1999 | static long Pref = 500; // #### pref. |
2000 | d->presswidget = (QWidget*)o; | 2000 | d->presswidget = (QWidget*)o; |
2001 | d->presspos = me->pos(); | 2001 | d->presspos = me->pos(); |
2002 | d->rightpressed = FALSE; | 2002 | d->rightpressed = FALSE; |
2003 | #ifdef OPIE_WITHROHFEEDBACK | 2003 | #ifdef OPIE_WITHROHFEEDBACK |
2004 | if( ! d->RoH ) | 2004 | if( ! d->RoH ) |
2005 | d->RoH = new Opie::Internal::RoHFeedback; | 2005 | d->RoH = new Opie::Internal::RoHFeedback; |
2006 | 2006 | ||
2007 | d->RoH->init( me->globalPos(), d->presswidget ); | 2007 | d->RoH->init( me->globalPos(), d->presswidget ); |
2008 | Pref = d->RoH->delay(); | 2008 | Pref = d->RoH->delay(); |
2009 | 2009 | ||
2010 | #endif | 2010 | #endif |
2011 | if (!d->presstimer ) | 2011 | if (!d->presstimer ) |
2012 | d->presstimer = startTimer( Pref ); // #### pref. | 2012 | d->presstimer = startTimer( Pref ); // #### pref. |
2013 | 2013 | ||
2014 | } | 2014 | } |
2015 | break; | 2015 | break; |
2016 | case QEvent::MouseMove: | 2016 | case QEvent::MouseMove: |
2017 | if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { | 2017 | if (d->presstimer && (me->pos() - d->presspos).manhattanLength() > 8) { |
2018 | killTimer(d->presstimer); | 2018 | killTimer(d->presstimer); |
2019 | #ifdef OPIE_WITHROHFEEDBACK | 2019 | #ifdef OPIE_WITHROHFEEDBACK |
2020 | d->RoH->stop(); | 2020 | d->RoH->stop(); |
2021 | #endif | 2021 | #endif |
2022 | d->presstimer = 0; | 2022 | d->presstimer = 0; |
2023 | } | 2023 | } |
2024 | break; | 2024 | break; |
2025 | case QEvent::MouseButtonRelease: | 2025 | case QEvent::MouseButtonRelease: |
2026 | if ( me->button() == LeftButton ) { | 2026 | if ( me->button() == LeftButton ) { |
2027 | if ( d->presstimer ) { | 2027 | if ( d->presstimer ) { |
2028 | killTimer(d->presstimer); | 2028 | killTimer(d->presstimer); |
2029 | #ifdef OPIE_WITHROHFEEDBACK | 2029 | #ifdef OPIE_WITHROHFEEDBACK |
2030 | d->RoH->stop( ); | 2030 | d->RoH->stop( ); |
2031 | #endif | 2031 | #endif |
2032 | d->presstimer = 0; | 2032 | d->presstimer = 0; |
2033 | } | 2033 | } |
2034 | if ( d->rightpressed && d->presswidget ) { | 2034 | if ( d->rightpressed && d->presswidget ) { |
2035 | printf( "Send ButtonRelease\n" ); | 2035 | printf( "Send ButtonRelease\n" ); |
2036 | // Right released | 2036 | // Right released |
2037 | postEvent( d->presswidget, | 2037 | postEvent( d->presswidget, |
2038 | new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), | 2038 | new QMouseEvent( QEvent::MouseButtonRelease, me->pos(), |
2039 | RightButton, LeftButton + RightButton ) ); | 2039 | RightButton, LeftButton + RightButton ) ); |
2040 | // Left released, off-widget | 2040 | // Left released, off-widget |
2041 | postEvent( d->presswidget, | 2041 | postEvent( d->presswidget, |
2042 | new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), | 2042 | new QMouseEvent( QEvent::MouseMove, QPoint( -1, -1), |
2043 | LeftButton, LeftButton ) ); | 2043 | LeftButton, LeftButton ) ); |
2044 | postEvent( d->presswidget, | 2044 | postEvent( d->presswidget, |
2045 | new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), | 2045 | new QMouseEvent( QEvent::MouseButtonRelease, QPoint( -1, -1), |
2046 | LeftButton, LeftButton ) ); | 2046 | LeftButton, LeftButton ) ); |
2047 | d->rightpressed = FALSE; | 2047 | d->rightpressed = FALSE; |
2048 | return TRUE; // don't send the real Left release | 2048 | return TRUE; // don't send the real Left release |
2049 | } | 2049 | } |
2050 | } | 2050 | } |
2051 | break; | 2051 | break; |
2052 | default: | 2052 | default: |
2053 | break; | 2053 | break; |
2054 | } | 2054 | } |
2055 | break; | 2055 | break; |
2056 | default: | 2056 | default: |
2057 | ; | 2057 | ; |
2058 | } | 2058 | } |
2059 | } | 2059 | } |
2060 | else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { | 2060 | else if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { |
2061 | QKeyEvent *ke = (QKeyEvent *)e; | 2061 | QKeyEvent *ke = (QKeyEvent *)e; |
2062 | if ( ke->key() == Key_Enter ) { | 2062 | if ( ke->key() == Key_Enter ) { |
2063 | if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { | 2063 | if ( o->isA( "QRadioButton" ) || o->isA( "QCheckBox" ) ) { |
2064 | postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', | 2064 | postEvent( o, new QKeyEvent( e->type(), Key_Space, ' ', |
2065 | ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); | 2065 | ke->state(), " ", ke->isAutoRepeat(), ke->count() ) ); |
2066 | return TRUE; | 2066 | return TRUE; |
2067 | } | 2067 | } |
2068 | } | 2068 | } |
2069 | } | 2069 | } |
2070 | return FALSE; | 2070 | return FALSE; |
2071 | } | 2071 | } |
2072 | 2072 | ||
2073 | /*! | 2073 | /*! |
2074 | \reimp | 2074 | \reimp |
2075 | */ | 2075 | */ |
2076 | void QPEApplication::timerEvent( QTimerEvent *e ) | 2076 | void QPEApplication::timerEvent( QTimerEvent *e ) |
2077 | { | 2077 | { |
2078 | if ( e->timerId() == d->presstimer && d->presswidget ) { | 2078 | if ( e->timerId() == d->presstimer && d->presswidget ) { |
2079 | 2079 | ||
2080 | // Right pressed | 2080 | // Right pressed |
2081 | postEvent( d->presswidget, | 2081 | postEvent( d->presswidget, |
2082 | new QMouseEvent( QEvent::MouseButtonPress, d->presspos, | 2082 | new QMouseEvent( QEvent::MouseButtonPress, d->presspos, |
2083 | RightButton, LeftButton ) ); | 2083 | RightButton, LeftButton ) ); |
2084 | killTimer( d->presstimer ); | 2084 | killTimer( d->presstimer ); |
2085 | d->presstimer = 0; | 2085 | d->presstimer = 0; |
2086 | d->rightpressed = TRUE; | 2086 | d->rightpressed = TRUE; |
2087 | #ifdef OPIE_WITHROHFEEDBACK | 2087 | #ifdef OPIE_WITHROHFEEDBACK |
2088 | d->RoH->stop(); | 2088 | d->RoH->stop(); |
2089 | #endif | 2089 | #endif |
2090 | } | 2090 | } |
2091 | } | 2091 | } |
2092 | 2092 | ||
2093 | void QPEApplication::removeSenderFromStylusDict() | 2093 | void QPEApplication::removeSenderFromStylusDict() |
2094 | { | 2094 | { |
2095 | stylusDict->remove | 2095 | stylusDict->remove |
2096 | ( ( void* ) sender() ); | 2096 | ( ( void* ) sender() ); |
2097 | if ( d->presswidget == sender() ) | 2097 | if ( d->presswidget == sender() ) |
2098 | d->presswidget = 0; | 2098 | d->presswidget = 0; |
2099 | } | 2099 | } |
2100 | 2100 | ||
2101 | /*! | 2101 | /*! |
2102 | \internal | 2102 | \internal |
2103 | */ | 2103 | */ |
2104 | bool QPEApplication::keyboardGrabbed() const | 2104 | bool QPEApplication::keyboardGrabbed() const |
2105 | { | 2105 | { |
2106 | return d->kbgrabbed; | 2106 | return d->kbgrabbed; |
2107 | } | 2107 | } |
2108 | 2108 | ||
2109 | 2109 | ||
2110 | /*! | 2110 | /*! |
2111 | Reverses the effect of grabKeyboard(). This is called automatically | 2111 | Reverses the effect of grabKeyboard(). This is called automatically |
2112 | on program exit. | 2112 | on program exit. |
2113 | */ | 2113 | */ |
2114 | void QPEApplication::ungrabKeyboard() | 2114 | void QPEApplication::ungrabKeyboard() |
2115 | { | 2115 | { |
2116 | ((QPEApplication *) qApp )-> d-> kbgrabbed = false; | 2116 | ((QPEApplication *) qApp )-> d-> kbgrabbed = false; |
2117 | } | 2117 | } |
2118 | 2118 | ||
2119 | /*! | 2119 | /*! |
2120 | Grabs the physical keyboard keys, e.g. the application's launching | 2120 | Grabs the physical keyboard keys, e.g. the application's launching |
2121 | keys. Instead of launching applications when these keys are pressed | 2121 | keys. Instead of launching applications when these keys are pressed |
2122 | the signals emitted are sent to this application instead. Some games | 2122 | the signals emitted are sent to this application instead. Some games |
2123 | programs take over the launch keys in this way to make interaction | 2123 | programs take over the launch keys in this way to make interaction |
2124 | easier. | 2124 | easier. |
2125 | 2125 | ||
2126 | \sa ungrabKeyboard() | 2126 | \sa ungrabKeyboard() |
2127 | */ | 2127 | */ |
2128 | void QPEApplication::grabKeyboard() | 2128 | void QPEApplication::grabKeyboard() |
2129 | { | 2129 | { |
2130 | ((QPEApplication *) qApp )-> d-> kbgrabbed = true; | 2130 | ((QPEApplication *) qApp )-> d-> kbgrabbed = true; |
2131 | } | 2131 | } |
2132 | 2132 | ||
2133 | /*! | 2133 | /*! |
2134 | \reimp | 2134 | \reimp |
2135 | */ | 2135 | */ |
2136 | int QPEApplication::exec() | 2136 | int QPEApplication::exec() |
2137 | { | 2137 | { |
2138 | d->qcopQok = true; | 2138 | d->qcopQok = true; |
2139 | #ifndef QT_NO_COP | 2139 | #ifndef QT_NO_COP |
2140 | d->sendQCopQ(); | 2140 | d->sendQCopQ(); |
2141 | if ( !d->keep_running ) | 2141 | if ( !d->keep_running ) |
2142 | processEvents(); // we may have received QCop messages in the meantime. | 2142 | processEvents(); // we may have received QCop messages in the meantime. |
2143 | #endif | 2143 | #endif |
2144 | 2144 | ||
2145 | if ( d->keep_running ) | 2145 | if ( d->keep_running ) |
2146 | //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) | 2146 | //|| d->qpe_main_widget && d->qpe_main_widget->isVisible() ) |
2147 | return QApplication::exec(); | 2147 | return QApplication::exec(); |
2148 | 2148 | ||
2149 | #ifndef QT_NO_COP | 2149 | #ifndef QT_NO_COP |
2150 | 2150 | ||
2151 | { | 2151 | { |
2152 | QCopEnvelope e( "QPE/System", "closing(QString)" ); | 2152 | QCopEnvelope e( "QPE/System", "closing(QString)" ); |
2153 | e << d->appName; | 2153 | e << d->appName; |
2154 | } | 2154 | } |
2155 | #endif | 2155 | #endif |
2156 | processEvents(); | 2156 | processEvents(); |
2157 | return 0; | 2157 | return 0; |
2158 | } | 2158 | } |
2159 | 2159 | ||
2160 | /*! | 2160 | /*! |
2161 | \internal | 2161 | \internal |
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp index 187adc6..c639002 100644 --- a/noncore/applets/pcmcia/pcmcia.cpp +++ b/noncore/applets/pcmcia/pcmcia.cpp | |||
@@ -1,368 +1,374 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. | 4 | .=l. |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; Library General Public License for more | 18 | ..}^=.= = ; Library General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = Library General Public License along with | 22 | -_. . . )=. = Library General Public License along with |
23 | -- :-=` this library; see the file COPYING.LIB. | 23 | -- :-=` this library; see the file COPYING.LIB. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "pcmcia.h" | 30 | #include "pcmcia.h" |
31 | #include "configdialog.h" | 31 | #include "configdialog.h" |
32 | #include "promptactiondialog.h" | 32 | #include "promptactiondialog.h" |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | #include <opie2/odevice.h> | 36 | #include <opie2/odevice.h> |
37 | #include <opie2/oconfig.h> | 37 | #include <opie2/oconfig.h> |
38 | #include <opie2/oprocess.h> | 38 | #include <opie2/oprocess.h> |
39 | #include <opie2/opcmciasystem.h> | 39 | #include <opie2/opcmciasystem.h> |
40 | #include <opie2/oresource.h> | 40 | #include <opie2/oresource.h> |
41 | #include <opie2/otaskbarapplet.h> | 41 | #include <opie2/otaskbarapplet.h> |
42 | #include <qpe/applnk.h> | 42 | #include <qpe/applnk.h> |
43 | #include <qpe/global.h> | 43 | #include <qpe/global.h> |
44 | #include <qpe/resource.h> | 44 | #include <qpe/resource.h> |
45 | using namespace Opie::Core; | 45 | using namespace Opie::Core; |
46 | using namespace Opie::Ui; | 46 | using namespace Opie::Ui; |
47 | 47 | ||
48 | /* QT */ | 48 | /* QT */ |
49 | #include <qcombobox.h> | 49 | #include <qcombobox.h> |
50 | #include <qcopchannel_qws.h> | 50 | #include <qcopchannel_qws.h> |
51 | #include <qpainter.h> | 51 | #include <qpainter.h> |
52 | #include <qfile.h> | 52 | #include <qfile.h> |
53 | #include <qtextstream.h> | 53 | #include <qtextstream.h> |
54 | #include <qmessagebox.h> | 54 | #include <qmessagebox.h> |
55 | #include <qsound.h> | 55 | #include <qsound.h> |
56 | #include <qtimer.h> | 56 | #include <qtimer.h> |
57 | 57 | ||
58 | /* STD */ | 58 | /* STD */ |
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <unistd.h> | 60 | #include <unistd.h> |
61 | #include <stdlib.h> | 61 | #include <stdlib.h> |
62 | #include <string.h> | 62 | #include <string.h> |
63 | #include <errno.h> | 63 | #include <errno.h> |
64 | #include <fcntl.h> | 64 | #include <fcntl.h> |
65 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 65 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
66 | #include <sys/vfs.h> | 66 | #include <sys/vfs.h> |
67 | #include <mntent.h> | 67 | #include <mntent.h> |
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ), popupMenu( 0 ) | 70 | PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ), popupMenu( 0 ) |
71 | { | 71 | { |
72 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); | 72 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); |
73 | connect( pcmciaChannel, | 73 | connect( pcmciaChannel, |
74 | SIGNAL( received(const QCString&,const QByteArray&) ), this, | 74 | SIGNAL( received(const QCString&,const QByteArray&) ), this, |
75 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); | 75 | SLOT( cardMessage(const QCString&,const QByteArray&) ) ); |
76 | 76 | ||
77 | setFocusPolicy( NoFocus ); | 77 | setFocusPolicy( NoFocus ); |
78 | setFixedWidth ( AppLnk::smallIconSize() ); | 78 | setFixedWidth ( AppLnk::smallIconSize() ); |
79 | setFixedHeight ( AppLnk::smallIconSize() ); | 79 | setFixedHeight ( AppLnk::smallIconSize() ); |
80 | pm = Opie::Core::OResource::loadPixmap( "pcmcia", Opie::Core::OResource::SmallIcon ); | 80 | pm = Opie::Core::OResource::loadPixmap( "pcmcia", Opie::Core::OResource::SmallIcon ); |
81 | configuring = false; | 81 | configuring = false; |
82 | 82 | ||
83 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 83 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
84 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), | 84 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
85 | this, SLOT(handleSystemChannel(const QCString&,const QByteArray&)) ); | 85 | this, SLOT(handleSystemChannel(const QCString&,const QByteArray&)) ); |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
89 | PcmciaManager::~PcmciaManager() | 89 | PcmciaManager::~PcmciaManager() |
90 | { | 90 | { |
91 | } | 91 | } |
92 | 92 | ||
93 | void PcmciaManager::handleSystemChannel( const QCString&msg, const QByteArray& ) | 93 | void PcmciaManager::handleSystemChannel( const QCString&msg, const QByteArray& ) |
94 | { | 94 | { |
95 | if ( msg == "returnFromSuspend()" ) | 95 | if ( msg == "returnFromSuspend()" ) |
96 | { | 96 | { |
97 | if ( !OPcmciaSystem::instance()->cardCount() ) return; | 97 | if ( !OPcmciaSystem::instance()->cardCount() ) return; |
98 | OPcmciaSystem* sys = OPcmciaSystem::instance(); | 98 | OPcmciaSystem* sys = OPcmciaSystem::instance(); |
99 | OPcmciaSystem::CardIterator it = sys->iterator(); | 99 | OPcmciaSystem::CardIterator it = sys->iterator(); |
100 | 100 | ||
101 | while ( it.current() ) | 101 | while ( it.current() ) |
102 | { | 102 | { |
103 | if ( !it.current()->isEmpty() ) | 103 | if ( !it.current()->isEmpty() ) |
104 | { | 104 | { |
105 | executeAction( it.current(), "resume" ); | 105 | executeAction( it.current(), "resume" ); |
106 | } | 106 | } |
107 | ++it; | 107 | ++it; |
108 | } | 108 | } |
109 | } | 109 | } |
110 | } | 110 | } |
111 | 111 | ||
112 | void PcmciaManager::popUp( QString message, QString icon ) | 112 | void PcmciaManager::popUp( QString message, QString icon ) |
113 | { | 113 | { |
114 | if ( !popupMenu) | 114 | if ( !popupMenu) |
115 | { | 115 | { |
116 | popupMenu = new QPopupMenu( this ); | 116 | popupMenu = new QPopupMenu( this ); |
117 | popupMenu->setFocusPolicy( QWidget::NoFocus ); | 117 | popupMenu->setFocusPolicy( QWidget::NoFocus ); |
118 | } | 118 | } |
119 | popupMenu->clear(); | 119 | popupMenu->clear(); |
120 | 120 | ||
121 | if ( icon.isEmpty() ) { | 121 | if ( icon.isEmpty() ) { |
122 | popupMenu->insertItem( message, 0 ); | 122 | popupMenu->insertItem( message, 0 ); |
123 | } else { | 123 | } else { |
124 | popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), | 124 | popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), |
125 | message, 0 ); | 125 | message, 0 ); |
126 | } | 126 | } |
127 | 127 | ||
128 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | 128 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
129 | QSize s = popupMenu->sizeHint(); | 129 | QSize s = popupMenu->sizeHint(); |
130 | popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), | 130 | popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), |
131 | p.y() - s.height() ), 0 ); | 131 | p.y() - s.height() ), 0 ); |
132 | 132 | ||
133 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); | 133 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); |
134 | } | 134 | } |
135 | 135 | ||
136 | 136 | ||
137 | void PcmciaManager::popupTimeout() | 137 | void PcmciaManager::popupTimeout() |
138 | { | 138 | { |
139 | popupMenu->hide(); | 139 | popupMenu->hide(); |
140 | } | 140 | } |
141 | 141 | ||
142 | enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE, ACTIVATE }; | 142 | enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE, ACTIVATE }; |
143 | static const char* actionText[] = { "eject", "insert", "suspend", "resum", "resett", "configur", "activat" }; | 143 | static const char* actionText[] = { "eject", "insert", "suspend", "resum", "resett", "configur", "activat" }; |
144 | 144 | ||
145 | void PcmciaManager::mousePressEvent( QMouseEvent* ) | 145 | void PcmciaManager::mousePressEvent( QMouseEvent* ) |
146 | { | 146 | { |
147 | QPopupMenu* menu = new QPopupMenu( this ); | 147 | QPopupMenu* menu = new QPopupMenu( this ); |
148 | QStringList cmd; | 148 | QStringList cmd; |
149 | bool execute = true; | 149 | bool execute = true; |
150 | 150 | ||
151 | OPcmciaSystem* sys = OPcmciaSystem::instance(); | 151 | OPcmciaSystem* sys = OPcmciaSystem::instance(); |
152 | sys->synchronize(); | 152 | sys->synchronize(); |
153 | OPcmciaSystem::CardIterator it = sys->iterator(); | 153 | OPcmciaSystem::CardIterator it = sys->iterator(); |
154 | if ( !sys->count() ) return; | 154 | if ( !sys->count() ) return; |
155 | 155 | ||
156 | int i = 0; | 156 | int i = 0; |
157 | while ( it.current() ) | 157 | while ( it.current() ) |
158 | { | 158 | { |
159 | QPopupMenu* submenu = new QPopupMenu( menu ); | 159 | QPopupMenu* submenu = new QPopupMenu( menu ); |
160 | submenu->insertItem( "&Eject", EJECT+i*100 ); | 160 | submenu->insertItem( "&Eject", EJECT+i*100 ); |
161 | submenu->insertItem( "&Insert", INSERT+i*100 ); | 161 | submenu->insertItem( "&Insert", INSERT+i*100 ); |
162 | submenu->insertItem( "&Suspend", SUSPEND+i*100 ); | 162 | submenu->insertItem( "&Suspend", SUSPEND+i*100 ); |
163 | submenu->insertItem( "&Resume", RESUME+i*100 ); | 163 | submenu->insertItem( "&Resume", RESUME+i*100 ); |
164 | submenu->insertItem( "Rese&t", RESET+i*100 ); | 164 | submenu->insertItem( "Rese&t", RESET+i*100 ); |
165 | submenu->insertItem( "&Configure", CONFIGURE+i*100 ); | 165 | submenu->insertItem( "&Configure", CONFIGURE+i*100 ); |
166 | 166 | ||
167 | bool isSuspended = it.current()->isSuspended(); | 167 | bool isSuspended = it.current()->isSuspended(); |
168 | bool isEmpty = it.current()->isEmpty(); | 168 | bool isEmpty = it.current()->isEmpty(); |
169 | 169 | ||
170 | submenu->setItemEnabled( EJECT+i*100, !isEmpty ); | 170 | submenu->setItemEnabled( EJECT+i*100, !isEmpty ); |
171 | submenu->setItemEnabled( INSERT+i*100, isEmpty ); | 171 | submenu->setItemEnabled( INSERT+i*100, isEmpty ); |
172 | submenu->setItemEnabled( SUSPEND+i*100, !isEmpty && !isSuspended ); | 172 | submenu->setItemEnabled( SUSPEND+i*100, !isEmpty && !isSuspended ); |
173 | submenu->setItemEnabled( RESUME+i*100, !isEmpty && isSuspended ); | 173 | submenu->setItemEnabled( RESUME+i*100, !isEmpty && isSuspended ); |
174 | submenu->setItemEnabled( RESET+i*100, !isEmpty && !isSuspended ); | 174 | submenu->setItemEnabled( RESET+i*100, !isEmpty && !isSuspended ); |
175 | submenu->setItemEnabled( CONFIGURE+i*100, !isEmpty && !configuring ); | 175 | submenu->setItemEnabled( CONFIGURE+i*100, !isEmpty && !configuring ); |
176 | 176 | ||
177 | connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) ); | 177 | connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) ); |
178 | menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 ); | 178 | menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 ); |
179 | ++it; | 179 | ++it; |
180 | } | 180 | } |
181 | 181 | ||
182 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); | 182 | QPoint p = mapToGlobal( QPoint( 0, 0 ) ); |
183 | QSize s = menu->sizeHint(); | 183 | QSize s = menu->sizeHint(); |
184 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); | 184 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), p.y() - s.height() ), 0 ); |
185 | qDebug( "pcmcia: menu result = %d", opt ); | 185 | qDebug( "pcmcia: menu result = %d", opt ); |
186 | delete menu; | 186 | delete menu; |
187 | } | 187 | } |
188 | 188 | ||
189 | 189 | ||
190 | void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) | 190 | void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) |
191 | { | 191 | { |
192 | odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; | 192 | odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; |
193 | if ( msg != "stabChanged()" ) return; | 193 | if ( msg != "stabChanged()" ) return; |
194 | 194 | ||
195 | /* check if a previously unknown card has been inserted */ | 195 | /* check if a previously unknown card has been inserted */ |
196 | OPcmciaSystem::instance()->synchronize(); | 196 | OPcmciaSystem::instance()->synchronize(); |
197 | 197 | ||
198 | if ( !OPcmciaSystem::instance()->cardCount() ) return; | 198 | if ( !OPcmciaSystem::instance()->cardCount() ) return; |
199 | 199 | ||
200 | OConfig cfg( "PCMCIA" ); | 200 | OConfig cfg( "PCMCIA" ); |
201 | cfg.setGroup( "Global" ); | 201 | cfg.setGroup( "Global" ); |
202 | int nCards = cfg.readNumEntry( "nCards", 0 ); | 202 | int nCards = cfg.readNumEntry( "nCards", 0 ); |
203 | 203 | ||
204 | OPcmciaSystem* sys = OPcmciaSystem::instance(); | 204 | OPcmciaSystem* sys = OPcmciaSystem::instance(); |
205 | OPcmciaSystem::CardIterator it = sys->iterator(); | 205 | OPcmciaSystem::CardIterator it = sys->iterator(); |
206 | 206 | ||
207 | bool newCard = true; | 207 | bool newCard = true; |
208 | OPcmciaSocket* theCard = 0; | 208 | OPcmciaSocket* theCard = 0; |
209 | 209 | ||
210 | while ( it.current() && newCard ) | 210 | while ( it.current() && newCard ) |
211 | { | 211 | { |
212 | if ( it.current()->isEmpty() ) | 212 | if ( it.current()->isEmpty() ) |
213 | { | 213 | { |
214 | odebug << "pcmcia: skipping empty card in socket " << it.current()->number() << oendl; | 214 | odebug << "pcmcia: skipping empty card in socket " << it.current()->number() << oendl; |
215 | ++it; | 215 | ++it; |
216 | continue; | 216 | continue; |
217 | } | 217 | } |
218 | else | 218 | else |
219 | { | 219 | { |
220 | theCard = it.current(); | 220 | theCard = it.current(); |
221 | QString cardName = theCard->productIdentity(); | 221 | QString cardName = theCard->productIdentity(); |
222 | for ( int i = 0; i < nCards; ++i ) | 222 | for ( int i = 0; i < nCards; ++i ) |
223 | { | 223 | { |
224 | QString cardSection = QString( "Card_%1" ).arg( i ); | 224 | QString cardSection = QString( "Card_%1" ).arg( i ); |
225 | cfg.setGroup( cardSection ); | 225 | cfg.setGroup( cardSection ); |
226 | QString name = cfg.readEntry( "name" ); | 226 | QString name = cfg.readEntry( "name" ); |
227 | odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl; | 227 | odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl; |
228 | if ( cardName == name ) | 228 | if ( cardName == name ) |
229 | { | 229 | { |
230 | newCard = false; | 230 | newCard = false; |
231 | odebug << "pcmcia: we have seen this card before" << oendl; | 231 | odebug << "pcmcia: we have seen this card before" << oendl; |
232 | executeAction( theCard, "insert" ); | 232 | executeAction( theCard, "insert" ); |
233 | break; | 233 | break; |
234 | } | 234 | } |
235 | } | 235 | } |
236 | if ( !newCard ) ++it; else break; | 236 | if ( !newCard ) ++it; else break; |
237 | } | 237 | } |
238 | } | 238 | } |
239 | |||
240 | if ( !theCard ) { | ||
241 | owarn << "pcmcia: Finished working through cards in PCMCIA system but I do not have a valid card handle" << oendl; | ||
242 | return; | ||
243 | } | ||
244 | |||
239 | if ( newCard ) | 245 | if ( newCard ) |
240 | { | 246 | { |
241 | odebug << "pcmcia: unconfigured card detected" << oendl; | 247 | odebug << "pcmcia: unconfigured card detected" << oendl; |
242 | QString newCardName = theCard->productIdentity(); | 248 | QString newCardName = theCard->productIdentity(); |
243 | int result = QMessageBox::information( qApp->desktop(), | 249 | int result = QMessageBox::information( qApp->desktop(), |
244 | tr( "PCMCIA/CF Subsystem" ), | 250 | tr( "PCMCIA/CF Subsystem" ), |
245 | tr( "<qt>You have inserted the card<br/><b>%1</b><br/>This card is not yet configured. Do you want to configure it now?</qt>" ).arg( newCardName ), | 251 | tr( "<qt>You have inserted the card<br/><b>%1</b><br/>This card is not yet configured. Do you want to configure it now?</qt>" ).arg( newCardName ), |
246 | tr( "Yes" ), tr( "No" ), 0, 0, 1 ); | 252 | tr( "Yes" ), tr( "No" ), 0, 0, 1 ); |
247 | odebug << "pcmcia: result = " << result << oendl; | 253 | odebug << "pcmcia: result = " << result << oendl; |
248 | if ( result == 0 ) | 254 | if ( result == 0 ) |
249 | { | 255 | { |
250 | configure( theCard ); | 256 | configure( theCard ); |
251 | } | 257 | } |
252 | else | 258 | else |
253 | { | 259 | { |
254 | odebug << "pcmcia: user doesn't want to configure " << newCardName << " now." << oendl; | 260 | odebug << "pcmcia: user doesn't want to configure " << newCardName << " now." << oendl; |
255 | } | 261 | } |
256 | } | 262 | } |
257 | else // it's an already configured card | 263 | else // it's an already configured card |
258 | { | 264 | { |
259 | odebug << "pcmcia: doing nothing... why do we come here?" << oendl; | 265 | odebug << "pcmcia: doing nothing... why do we come here?" << oendl; |
260 | } | 266 | } |
261 | } | 267 | } |
262 | 268 | ||
263 | void PcmciaManager::paintEvent( QPaintEvent * ) | 269 | void PcmciaManager::paintEvent( QPaintEvent * ) |
264 | { | 270 | { |
265 | QPainter p( this ); | 271 | QPainter p( this ); |
266 | p.drawPixmap( 0, 0, pm ); | 272 | p.drawPixmap( 0, 0, pm ); |
267 | } | 273 | } |
268 | 274 | ||
269 | int PcmciaManager::position() | 275 | int PcmciaManager::position() |
270 | { | 276 | { |
271 | return 7; | 277 | return 7; |
272 | } | 278 | } |
273 | 279 | ||
274 | void PcmciaManager::execCommand( const QStringList &strList ) | 280 | void PcmciaManager::execCommand( const QStringList &strList ) |
275 | { | 281 | { |
276 | } | 282 | } |
277 | 283 | ||
278 | void PcmciaManager::userCardAction( int action ) | 284 | void PcmciaManager::userCardAction( int action ) |
279 | { | 285 | { |
280 | odebug << "pcmcia: user action on socket " << action / 100 << " requested. action = " << action << oendl; | 286 | odebug << "pcmcia: user action on socket " << action / 100 << " requested. action = " << action << oendl; |
281 | 287 | ||
282 | int socket = action / 100; | 288 | int socket = action / 100; |
283 | int what = action % 100; | 289 | int what = action % 100; |
284 | bool success = false; | 290 | bool success = false; |
285 | 291 | ||
286 | switch ( what ) | 292 | switch ( what ) |
287 | { | 293 | { |
288 | case CONFIGURE: | 294 | case CONFIGURE: |
289 | { | 295 | { |
290 | QString insertAction; QString resumeAction; QString driver; QString conf; | 296 | QString insertAction; QString resumeAction; QString driver; QString conf; |
291 | configure( OPcmciaSystem::instance()->socket( socket ) ); | 297 | configure( OPcmciaSystem::instance()->socket( socket ) ); |
292 | return; | 298 | return; |
293 | } | 299 | } |
294 | case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); | 300 | case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); |
295 | break; | 301 | break; |
296 | case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); | 302 | case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); |
297 | break; | 303 | break; |
298 | case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); | 304 | case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); |
299 | break; | 305 | break; |
300 | case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); | 306 | case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); |
301 | break; | 307 | break; |
302 | case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); | 308 | case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); |
303 | break; | 309 | break; |
304 | case ACTIVATE: success = true; | 310 | case ACTIVATE: success = true; |
305 | break; | 311 | break; |
306 | default: odebug << "pcmcia: not yet implemented" << oendl; | 312 | default: odebug << "pcmcia: not yet implemented" << oendl; |
307 | } | 313 | } |
308 | 314 | ||
309 | if ( success ) | 315 | if ( success ) |
310 | { | 316 | { |
311 | odebug << tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) << oendl; | 317 | odebug << tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) << oendl; |
312 | popUp( tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) ); | 318 | popUp( tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) ); |
313 | } | 319 | } |
314 | else | 320 | else |
315 | { | 321 | { |
316 | odebug << tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) << oendl; | 322 | odebug << tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) << oendl; |
317 | popUp( tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) ); | 323 | popUp( tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) ); |
318 | } | 324 | } |
319 | } | 325 | } |
320 | 326 | ||
321 | void PcmciaManager::configure( OPcmciaSocket* card ) | 327 | void PcmciaManager::configure( OPcmciaSocket* card ) |
322 | { | 328 | { |
323 | configuring = true; | 329 | configuring = true; |
324 | ConfigDialog dialog( card, qApp->desktop() ); | 330 | ConfigDialog dialog( card, qApp->desktop() ); |
325 | int result = QPEApplication::execDialog( &dialog, false ); | 331 | int result = QPEApplication::execDialog( &dialog, false ); |
326 | configuring = false; | 332 | configuring = false; |
327 | odebug << "pcmcia: configresult = " << result << oendl; | 333 | odebug << "pcmcia: configresult = " << result << oendl; |
328 | if ( result ) | 334 | if ( result ) |
329 | { | 335 | { |
330 | dialog.writeConfiguration( card ); | 336 | dialog.writeConfiguration( card ); |
331 | } | 337 | } |
332 | } | 338 | } |
333 | 339 | ||
334 | void PcmciaManager::executeAction( Opie::Core::OPcmciaSocket* card, const QString& type ) | 340 | void PcmciaManager::executeAction( Opie::Core::OPcmciaSocket* card, const QString& type ) |
335 | { | 341 | { |
336 | odebug << "pcmcia: performing " << type << " action ..." << oendl; | 342 | odebug << "pcmcia: performing " << type << " action ..." << oendl; |
337 | QString theAction = ConfigDialog::preferredAction( card, type ); | 343 | QString theAction = ConfigDialog::preferredAction( card, type ); |
338 | int intAction = card->number() * 100; | 344 | int intAction = card->number() * 100; |
339 | 345 | ||
340 | if ( theAction == "prompt for" ) | 346 | if ( theAction == "prompt for" ) |
341 | { | 347 | { |
342 | PromptActionDialog dialog( qApp->desktop(), "promptfor", true ); | 348 | PromptActionDialog dialog( qApp->desktop(), "promptfor", true ); |
343 | dialog.setCaption( QString( "Choose action for card #%1" ).arg( card->number() ) ); | 349 | dialog.setCaption( QString( "Choose action for card #%1" ).arg( card->number() ) ); |
344 | int result = QPEApplication::execDialog( &dialog, true ); | 350 | int result = QPEApplication::execDialog( &dialog, true ); |
345 | odebug << "pcmcia: configresult = " << result << oendl; | 351 | odebug << "pcmcia: configresult = " << result << oendl; |
346 | if ( result ) | 352 | if ( result ) |
347 | { | 353 | { |
348 | theAction = dialog.cbAction->currentText(); | 354 | theAction = dialog.cbAction->currentText(); |
349 | } | 355 | } |
350 | else | 356 | else |
351 | { | 357 | { |
352 | odebug << "pcmcia: prompted to do nothing" << oendl; | 358 | odebug << "pcmcia: prompted to do nothing" << oendl; |
353 | return; | 359 | return; |
354 | } | 360 | } |
355 | } | 361 | } |
356 | if ( theAction == "activate" ) intAction += ACTIVATE; | 362 | if ( theAction == "activate" ) intAction += ACTIVATE; |
357 | else if ( theAction == "eject" ) intAction += EJECT; | 363 | else if ( theAction == "eject" ) intAction += EJECT; |
358 | else if ( theAction == "suspend" ) intAction += SUSPEND; | 364 | else if ( theAction == "suspend" ) intAction += SUSPEND; |
359 | else | 365 | else |
360 | { | 366 | { |
361 | owarn << "pcmcia: action '" << theAction << "' not known. Huh?" << oendl; | 367 | owarn << "pcmcia: action '" << theAction << "' not known. Huh?" << oendl; |
362 | return; | 368 | return; |
363 | } | 369 | } |
364 | userCardAction( intAction ); | 370 | userCardAction( intAction ); |
365 | } | 371 | } |
366 | 372 | ||
367 | EXPORT_OPIE_APPLET_v1( PcmciaManager ) | 373 | EXPORT_OPIE_APPLET_v1( PcmciaManager ) |
368 | 374 | ||
diff --git a/noncore/apps/checkbook/mainwindow.cpp b/noncore/apps/checkbook/mainwindow.cpp index d9e2047..8e2e2e3 100644 --- a/noncore/apps/checkbook/mainwindow.cpp +++ b/noncore/apps/checkbook/mainwindow.cpp | |||
@@ -1,363 +1,362 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the OPIE Project | 2 | This file is part of the OPIE Project |
3 | =. | 3 | =. |
4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> | 4 | .=l. Copyright (c) 2002 Dan Williams <drw@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This file is free software; you can | 6 | _;:, .> :=|. This file is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "mainwindow.h" | 29 | #include "mainwindow.h" |
30 | #include "cbinfo.h" | 30 | #include "cbinfo.h" |
31 | #include "configuration.h" | 31 | #include "configuration.h" |
32 | #include "password.h" | 32 | #include "password.h" |
33 | #include "checkbook.h" | 33 | #include "checkbook.h" |
34 | 34 | ||
35 | #include <opie2/oresource.h> | 35 | #include <opie2/oresource.h> |
36 | 36 | ||
37 | #include <qpe/config.h> | 37 | #include <qpe/config.h> |
38 | #include <qpe/qpeapplication.h> | 38 | #include <qpe/qpeapplication.h> |
39 | #include <qpe/qpemessagebox.h> | 39 | #include <qpe/qpemessagebox.h> |
40 | 40 | ||
41 | #include <qaction.h> | 41 | #include <qaction.h> |
42 | #include <qdir.h> | 42 | #include <qdir.h> |
43 | #include <qmenubar.h> | 43 | #include <qmenubar.h> |
44 | #include <qtoolbar.h> | 44 | #include <qtoolbar.h> |
45 | #include <qwhatsthis.h> | 45 | #include <qwhatsthis.h> |
46 | 46 | ||
47 | 47 | ||
48 | MainWindow::MainWindow( QWidget* parent, const char* name, WFlags /*fl*/ ) | 48 | MainWindow::MainWindow( QWidget* parent, const char* name, WFlags /*fl*/ ) |
49 | : QMainWindow( parent, name, WStyle_ContextHelp ) | 49 | : QMainWindow( parent, name, WStyle_ContextHelp ) |
50 | { | 50 | { |
51 | setCaption( tr( "Checkbook" ) ); | 51 | setCaption( tr( "Checkbook" ) ); |
52 | 52 | ||
53 | cbDir = Global::applicationFileName( "checkbook", "" ); | 53 | cbDir = Global::applicationFileName( "checkbook", "" ); |
54 | lockIcon = Opie::Core::OResource::loadPixmap( "locked", Opie::Core::OResource::SmallIcon ); | 54 | lockIcon = Opie::Core::OResource::loadPixmap( "locked", Opie::Core::OResource::SmallIcon ); |
55 | 55 | ||
56 | // Load configuration options | 56 | // Load configuration options |
57 | Config config( "checkbook" ); | 57 | Config config( "checkbook" ); |
58 | _cfg.readConfig( config ); | 58 | _cfg.readConfig( config ); |
59 | 59 | ||
60 | 60 | ||
61 | // Build menu and tool bars | 61 | // Build menu and tool bars |
62 | setToolBarsMovable( FALSE ); | 62 | setToolBarsMovable( FALSE ); |
63 | 63 | ||
64 | QToolBar *bar = new QToolBar( this ); | 64 | QToolBar *bar = new QToolBar( this ); |
65 | bar->setHorizontalStretchable( TRUE ); | 65 | bar->setHorizontalStretchable( TRUE ); |
66 | QMenuBar *mb = new QMenuBar( bar ); | 66 | QMenuBar *mb = new QMenuBar( bar ); |
67 | mb->setMargin( 0 ); | 67 | mb->setMargin( 0 ); |
68 | QPopupMenu *popup = new QPopupMenu( this ); | 68 | QPopupMenu *popup = new QPopupMenu( this ); |
69 | 69 | ||
70 | bar = new QToolBar( this ); | 70 | bar = new QToolBar( this ); |
71 | QAction *a = new QAction( tr( "New" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), | 71 | QAction *a = new QAction( tr( "New" ), Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), |
72 | QString::null, 0, this, 0 ); | 72 | QString::null, 0, this, 0 ); |
73 | a->setWhatsThis( tr( "Click here to create a new checkbook.\n\nYou also can select New from the Checkbook menu." ) ); | 73 | a->setWhatsThis( tr( "Click here to create a new checkbook.\n\nYou also can select New from the Checkbook menu." ) ); |
74 | connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) ); | 74 | connect( a, SIGNAL( activated() ), this, SLOT( slotNew() ) ); |
75 | a->addTo( popup ); | 75 | a->addTo( popup ); |
76 | a->addTo( bar ); | 76 | a->addTo( bar ); |
77 | 77 | ||
78 | actionOpen = new QAction( tr( "Edit" ), Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), | 78 | actionOpen = new QAction( tr( "Edit" ), Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), |
79 | QString::null, 0, this, 0 ); | 79 | QString::null, 0, this, 0 ); |
80 | actionOpen->setWhatsThis( tr( "Select a checkbook and then click here to edit it.\n\nYou also can select Edit from the Checkbook menu, or click and hold on a checkbook name." ) ); | 80 | actionOpen->setWhatsThis( tr( "Select a checkbook and then click here to edit it.\n\nYou also can select Edit from the Checkbook menu, or click and hold on a checkbook name." ) ); |
81 | connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotEdit() ) ); | 81 | connect( actionOpen, SIGNAL( activated() ), this, SLOT( slotEdit() ) ); |
82 | actionOpen->addTo( popup ); | 82 | actionOpen->addTo( popup ); |
83 | actionOpen->addTo( bar ); | 83 | actionOpen->addTo( bar ); |
84 | 84 | ||
85 | actionDelete = new QAction( tr( "Delete" ), Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), | 85 | actionDelete = new QAction( tr( "Delete" ), Opie::Core::OResource::loadPixmap( "trash", Opie::Core::OResource::SmallIcon ), |
86 | QString::null, 0, this, 0 ); | 86 | QString::null, 0, this, 0 ); |
87 | actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) ); | 87 | actionDelete->setWhatsThis( tr( "Select a checkbook and then click here delete it.\n\nYou also can select Delete from the Checkbook menu." ) ); |
88 | connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) ); | 88 | connect( actionDelete, SIGNAL( activated() ), this, SLOT( slotDelete() ) ); |
89 | actionDelete->addTo( popup ); | 89 | actionDelete->addTo( popup ); |
90 | actionDelete->addTo( bar ); | 90 | actionDelete->addTo( bar ); |
91 | 91 | ||
92 | popup->insertSeparator(); | 92 | popup->insertSeparator(); |
93 | 93 | ||
94 | a = new QAction( tr( "Configure" ), Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), | 94 | a = new QAction( tr( "Configure" ), Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), |
95 | QString::null, 0, this, 0 ); | 95 | QString::null, 0, this, 0 ); |
96 | a->setWhatsThis( tr( "Click here to configure this app." ) ); | 96 | a->setWhatsThis( tr( "Click here to configure this app." ) ); |
97 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); | 97 | connect( a, SIGNAL( activated() ), this, SLOT( slotConfigure() ) ); |
98 | a->addTo( popup ); | 98 | a->addTo( popup ); |
99 | a->addTo( bar ); | 99 | a->addTo( bar ); |
100 | 100 | ||
101 | mb->insertItem( tr( "Checkbook" ), popup ); | 101 | mb->insertItem( tr( "Checkbook" ), popup ); |
102 | 102 | ||
103 | // Load Checkbook selection list | 103 | // Load Checkbook selection list |
104 | checkbooks = new CBInfoList(); | 104 | checkbooks = new CBInfoList(); |
105 | 105 | ||
106 | QDir checkdir( cbDir ); | 106 | QDir checkdir( cbDir ); |
107 | if (checkdir.exists() == true) | 107 | if (checkdir.exists() == true) |
108 | { | 108 | { |
109 | QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable, | 109 | QStringList cblist = checkdir.entryList( "*.qcb", QDir::Files|QDir::Readable|QDir::Writable, |
110 | QDir::Time ); | 110 | QDir::Time ); |
111 | CBInfo *cb = 0x0; | 111 | CBInfo *cb = 0x0; |
112 | QString filename; | 112 | QString filename; |
113 | 113 | ||
114 | for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ ) | 114 | for ( QStringList::Iterator it = cblist.begin(); it != cblist.end(); it++ ) |
115 | { | 115 | { |
116 | filename = cbDir; | 116 | filename = cbDir; |
117 | filename.append( (*it) ); | 117 | filename.append( (*it) ); |
118 | 118 | ||
119 | cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename ); | 119 | cb = new CBInfo( (*it).remove( (*it).find('.'), (*it).length() ), filename ); |
120 | checkbooks->inSort( cb ); | 120 | checkbooks->inSort( cb ); |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
124 | // Build Checkbook selection list control | 124 | // Build Checkbook selection list control |
125 | cbList = 0x0; | 125 | cbList = 0x0; |
126 | buildList(); | 126 | buildList(); |
127 | 127 | ||
128 | // open last book? | 128 | // open last book? |
129 | if( _cfg.isOpenLastBook() ) { | 129 | if( _cfg.isOpenLastBook() ) { |
130 | this->show(); | 130 | this->show(); |
131 | this->showMaximized(); | 131 | this->showMaximized(); |
132 | QListViewItem *itm=cbList->firstChild(); | 132 | QListViewItem *itm=cbList->firstChild(); |
133 | while( itm ) { | 133 | while( itm ) { |
134 | if( itm->text(posName)==_cfg.getLastBook() ) { | 134 | if( itm->text(posName)==_cfg.getLastBook() ) { |
135 | openBook( itm ); | 135 | openBook( itm ); |
136 | break; | 136 | break; |
137 | } | 137 | } |
138 | itm=itm->nextSibling(); | 138 | itm=itm->nextSibling(); |
139 | } | 139 | } |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||
144 | // --- ~MainWindow ------------------------------------------------------------ | 144 | // --- ~MainWindow ------------------------------------------------------------ |
145 | MainWindow::~MainWindow() | 145 | MainWindow::~MainWindow() |
146 | { | 146 | { |
147 | writeConfig(); | 147 | writeConfig(); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | // --- buildList -------------------------------------------------------------- | 151 | // --- buildList -------------------------------------------------------------- |
152 | void MainWindow::buildList() | 152 | void MainWindow::buildList() |
153 | { | 153 | { |
154 | if ( cbList ) | 154 | if ( cbList ) |
155 | delete cbList; | 155 | delete cbList; |
156 | 156 | ||
157 | cbList = new QListView( this ); | 157 | cbList = new QListView( this ); |
158 | QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); | 158 | QWhatsThis::add( cbList, tr( "This is a listing of all checkbooks currently available." ) ); |
159 | 159 | ||
160 | if ( _cfg.getShowLocks() ) | 160 | if ( _cfg.getShowLocks() ) |
161 | { | 161 | { |
162 | cbList->addColumn( lockIcon, "", 24 ); | 162 | cbList->addColumn( lockIcon, "", 24 ); |
163 | posName = 1; | 163 | posName = 1; |
164 | } | 164 | } |
165 | else | 165 | else |
166 | { | 166 | { |
167 | posName = 0; | 167 | posName = 0; |
168 | } | 168 | } |
169 | cbList->addColumn( tr( "Checkbook Name" ) ); | 169 | cbList->addColumn( tr( "Checkbook Name" ) ); |
170 | if ( _cfg.getShowBalances() ) | 170 | if ( _cfg.getShowBalances() ) |
171 | { | 171 | { |
172 | int colnum = cbList->addColumn( tr( "Balance" ) ); | 172 | int colnum = cbList->addColumn( tr( "Balance" ) ); |
173 | cbList->setColumnAlignment( colnum, Qt::AlignRight ); | 173 | cbList->setColumnAlignment( colnum, Qt::AlignRight ); |
174 | } | 174 | } |
175 | cbList->setAllColumnsShowFocus( TRUE ); | 175 | cbList->setAllColumnsShowFocus( TRUE ); |
176 | cbList->setSorting( posName ); | 176 | cbList->setSorting( posName ); |
177 | QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); | 177 | QPEApplication::setStylusOperation( cbList->viewport(), QPEApplication::RightOnHold ); |
178 | connect( cbList, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), | 178 | connect( cbList, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), |
179 | this, SLOT( slotEdit() ) ); | 179 | this, SLOT( slotEdit() ) ); |
180 | setCentralWidget( cbList ); | 180 | setCentralWidget( cbList ); |
181 | 181 | ||
182 | for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() ) | 182 | for ( CBInfo *cb = checkbooks->first(); cb; cb = checkbooks->next() ) |
183 | { | 183 | { |
184 | addCheckbook( cb ); | 184 | addCheckbook( cb ); |
185 | } | 185 | } |
186 | } | 186 | } |
187 | 187 | ||
188 | void MainWindow::addCheckbook( CBInfo *cb ) | 188 | void MainWindow::addCheckbook( CBInfo *cb ) |
189 | { | 189 | { |
190 | QListViewItem *lvi = new QListViewItem( cbList ); | 190 | QListViewItem *lvi = new QListViewItem( cbList ); |
191 | if ( _cfg.getShowLocks() && !cb->password().isNull() ) | 191 | if ( _cfg.getShowLocks() && !cb->password().isNull() ) |
192 | { | 192 | { |
193 | lvi->setPixmap( 0, lockIcon ); | 193 | lvi->setPixmap( 0, lockIcon ); |
194 | } | 194 | } |
195 | lvi->setText( posName, cb->name() ); | 195 | lvi->setText( posName, cb->name() ); |
196 | if ( _cfg.getShowBalances() ) | 196 | if ( _cfg.getShowBalances() ) |
197 | { | 197 | { |
198 | QString balance; | 198 | QString balance; |
199 | balance.sprintf( "%.2f", cb->balance() ); | 199 | balance.sprintf( "%.2f", cb->balance() ); |
200 | balance.prepend( _cfg.getCurrencySymbol() ); | 200 | balance.prepend( _cfg.getCurrencySymbol() ); |
201 | lvi->setText( posName + 1, balance ); | 201 | lvi->setText( posName + 1, balance ); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | void MainWindow::buildFilename( const QString &name ) | 205 | void MainWindow::buildFilename( const QString &name ) |
206 | { | 206 | { |
207 | tempFilename = cbDir; | 207 | tempFilename = cbDir; |
208 | tempFilename.append( name ); | 208 | tempFilename.append( name ); |
209 | tempFilename.append( ".qcb" ); | 209 | tempFilename.append( ".qcb" ); |
210 | } | 210 | } |
211 | 211 | ||
212 | void MainWindow::slotNew() | 212 | void MainWindow::slotNew() |
213 | { | 213 | { |
214 | CBInfo *cb = new CBInfo(); | 214 | CBInfo *cb = new CBInfo(); |
215 | 215 | ||
216 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); | 216 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); |
217 | if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) | 217 | if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) |
218 | { | 218 | { |
219 | // Save new checkbook | 219 | // Save new checkbook |
220 | buildFilename( cb->name() ); | 220 | buildFilename( cb->name() ); |
221 | _cfg.setLastBook( cb->name() ); | 221 | _cfg.setLastBook( cb->name() ); |
222 | cb->setFilename( tempFilename ); | 222 | cb->setFilename( tempFilename ); |
223 | cb->write(); | 223 | cb->write(); |
224 | 224 | ||
225 | // Add to listbox | 225 | // Add to listbox |
226 | checkbooks->inSort( cb ); | 226 | checkbooks->inSort( cb ); |
227 | addCheckbook( cb ); | 227 | addCheckbook( cb ); |
228 | } | 228 | } |
229 | delete currcb; | 229 | delete currcb; |
230 | } | 230 | } |
231 | 231 | ||
232 | // --- slotEdit --------------------------------------------------------------- | 232 | // --- slotEdit --------------------------------------------------------------- |
233 | void MainWindow::slotEdit() | 233 | void MainWindow::slotEdit() |
234 | { | 234 | { |
235 | // get name and open it | 235 | // get name and open it |
236 | QListViewItem *curritem = cbList->currentItem(); | 236 | QListViewItem *curritem = cbList->currentItem(); |
237 | if ( !curritem ) | 237 | if ( !curritem ) |
238 | return; | 238 | return; |
239 | openBook( curritem ); | 239 | openBook( curritem ); |
240 | } | 240 | } |
241 | 241 | ||
242 | 242 | ||
243 | // --- openBook --------------------------------------------------------------- | 243 | // --- openBook --------------------------------------------------------------- |
244 | void MainWindow::openBook(QListViewItem *curritem) | 244 | void MainWindow::openBook(QListViewItem *curritem) |
245 | { | 245 | { |
246 | if ( !curritem ) return; | ||
246 | // find book in List | 247 | // find book in List |
247 | QString currname=curritem->text(posName); | 248 | QString currname=curritem->text(posName); |
248 | CBInfo *cb = checkbooks->first(); | 249 | CBInfo *cb = checkbooks->first(); |
249 | while ( cb ) { | 250 | while ( cb ) { |
250 | if ( cb->name() == currname ) | 251 | if ( cb->name() == currname ) |
251 | break; | 252 | break; |
252 | cb = checkbooks->next(); | 253 | cb = checkbooks->next(); |
253 | } | 254 | } |
254 | if ( !cb ) return; | 255 | if ( !cb ) return; |
255 | 256 | ||
256 | // | 257 | // |
257 | buildFilename( currname ); | 258 | buildFilename( currname ); |
258 | float currbalance = cb->balance(); | 259 | float currbalance = cb->balance(); |
259 | bool currlock = !cb->password().isNull(); | 260 | bool currlock = !cb->password().isNull(); |
260 | 261 | ||
261 | if ( currlock ) | 262 | if ( currlock ) |
262 | { | 263 | { |
263 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); | 264 | Password *pw = new Password( this, tr( "Enter password" ), tr( "Please enter your password:" ) ); |
264 | if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) | 265 | if ( pw->exec() != QDialog::Accepted || pw->password != cb->password() ) |
265 | { | 266 | { |
266 | delete pw; | 267 | delete pw; |
267 | return; | 268 | return; |
268 | } | 269 | } |
269 | delete pw; | 270 | delete pw; |
270 | } | 271 | } |
271 | 272 | ||
272 | _cfg.setLastBook( currname ); | 273 | _cfg.setLastBook( currname ); |
273 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); | 274 | Checkbook *currcb = new Checkbook( this, cb, &_cfg ); |
274 | if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) | 275 | if ( QPEApplication::execDialog( currcb ) == QDialog::Accepted ) |
275 | { | 276 | { |
276 | QString newname = cb->name(); | 277 | QString newname = cb->name(); |
277 | if ( currname != newname ) | 278 | if ( currname != newname ) |
278 | { | 279 | { |
279 | // Update name if changed | 280 | // Update name if changed |
280 | if( curritem ) { | 281 | curritem->setText( posName, newname ); |
281 | curritem->setText( posName, newname ); | 282 | cbList->sort(); |
282 | cbList->sort(); | ||
283 | } | ||
284 | _cfg.setLastBook( newname ); | 283 | _cfg.setLastBook( newname ); |
285 | 284 | ||
286 | // Remove old file | 285 | // Remove old file |
287 | QFile f( tempFilename ); | 286 | QFile f( tempFilename ); |
288 | if ( f.exists() ) | 287 | if ( f.exists() ) |
289 | f.remove(); | 288 | f.remove(); |
290 | 289 | ||
291 | // Get new filename | 290 | // Get new filename |
292 | buildFilename( newname ); | 291 | buildFilename( newname ); |
293 | cb->setFilename( tempFilename ); | 292 | cb->setFilename( tempFilename ); |
294 | } | 293 | } |
295 | 294 | ||
296 | cb->write(); | 295 | cb->write(); |
297 | 296 | ||
298 | // Update lock if changed | 297 | // Update lock if changed |
299 | if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) | 298 | if ( _cfg.getShowLocks() && !cb->password().isNull() != currlock ) |
300 | { | 299 | { |
301 | if ( !cb->password().isNull() ) | 300 | if ( !cb->password().isNull() ) |
302 | curritem->setPixmap( 0, lockIcon ); | 301 | curritem->setPixmap( 0, lockIcon ); |
303 | else | 302 | else |
304 | curritem->setPixmap( 0, nullIcon ); | 303 | curritem->setPixmap( 0, nullIcon ); |
305 | } | 304 | } |
306 | 305 | ||
307 | // Update balance if changed | 306 | // Update balance if changed |
308 | if ( _cfg.getShowBalances() && cb->balance() != currbalance ) | 307 | if ( _cfg.getShowBalances() && cb->balance() != currbalance ) |
309 | { | 308 | { |
310 | QString tempstr; | 309 | QString tempstr; |
311 | tempstr.sprintf( "%.2f", cb->balance() ); | 310 | tempstr.sprintf( "%.2f", cb->balance() ); |
312 | tempstr.prepend( _cfg.getCurrencySymbol() ); | 311 | tempstr.prepend( _cfg.getCurrencySymbol() ); |
313 | curritem->setText( posName + 1, tempstr ); | 312 | curritem->setText( posName + 1, tempstr ); |
314 | } | 313 | } |
315 | 314 | ||
316 | // write config, if needed | 315 | // write config, if needed |
317 | if( _cfg.isDirty() ) { | 316 | if( _cfg.isDirty() ) { |
318 | Config config("checkbook"); | 317 | Config config("checkbook"); |
319 | _cfg.writeConfig( config ); | 318 | _cfg.writeConfig( config ); |
320 | } | 319 | } |
321 | } | 320 | } |
322 | delete currcb; | 321 | delete currcb; |
323 | } | 322 | } |
324 | 323 | ||
325 | // --- slotDelete ------------------------------------------------------------- | 324 | // --- slotDelete ------------------------------------------------------------- |
326 | void MainWindow::slotDelete() | 325 | void MainWindow::slotDelete() |
327 | { | 326 | { |
328 | QString currname = cbList->currentItem()->text( posName ); | 327 | QString currname = cbList->currentItem()->text( posName ); |
329 | 328 | ||
330 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) | 329 | if ( QPEMessageBox::confirmDelete ( this, tr( "Delete checkbook" ), currname ) ) |
331 | { | 330 | { |
332 | buildFilename( currname ); | 331 | buildFilename( currname ); |
333 | QFile f( tempFilename ); | 332 | QFile f( tempFilename ); |
334 | if ( f.exists() ) | 333 | if ( f.exists() ) |
335 | { | 334 | { |
336 | f.remove(); | 335 | f.remove(); |
337 | } | 336 | } |
338 | 337 | ||
339 | delete cbList->currentItem(); | 338 | delete cbList->currentItem(); |
340 | } | 339 | } |
341 | } | 340 | } |
342 | 341 | ||
343 | // --- slotConfigure ---------------------------------------------------------- | 342 | // --- slotConfigure ---------------------------------------------------------- |
344 | void MainWindow::slotConfigure() | 343 | void MainWindow::slotConfigure() |
345 | { | 344 | { |
346 | Configuration *cfgdlg = new Configuration( this, _cfg ); | 345 | Configuration *cfgdlg = new Configuration( this, _cfg ); |
347 | if ( QPEApplication::execDialog( cfgdlg ) == QDialog::Accepted ) | 346 | if ( QPEApplication::execDialog( cfgdlg ) == QDialog::Accepted ) |
348 | { | 347 | { |
349 | // read data from config dialog & save it | 348 | // read data from config dialog & save it |
350 | cfgdlg->saveConfig( _cfg ); | 349 | cfgdlg->saveConfig( _cfg ); |
351 | writeConfig(); | 350 | writeConfig(); |
352 | buildList(); | 351 | buildList(); |
353 | } | 352 | } |
354 | delete cfgdlg; | 353 | delete cfgdlg; |
355 | } | 354 | } |
356 | 355 | ||
357 | 356 | ||
358 | // --- writeConfig -------------------------------------------------------------- | 357 | // --- writeConfig -------------------------------------------------------------- |
359 | void MainWindow::writeConfig() | 358 | void MainWindow::writeConfig() |
360 | { | 359 | { |
361 | Config config("checkbook"); | 360 | Config config("checkbook"); |
362 | _cfg.writeConfig( config ); | 361 | _cfg.writeConfig( config ); |
363 | } | 362 | } |
diff --git a/noncore/apps/opie-console/procctl.cpp b/noncore/apps/opie-console/procctl.cpp index a44529b..5239e26 100644 --- a/noncore/apps/opie-console/procctl.cpp +++ b/noncore/apps/opie-console/procctl.cpp | |||
@@ -1,97 +1,100 @@ | |||
1 | #include <sys/wait.h> | 1 | #include <sys/wait.h> |
2 | 2 | ||
3 | #include <fcntl.h> | 3 | #include <fcntl.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | 5 | ||
6 | #include "procctl.h" | 6 | #include "procctl.h" |
7 | 7 | ||
8 | ProcContainer *ProcCtl::m_last = 0; | 8 | ProcContainer *ProcCtl::m_last = 0; |
9 | ProcCtl* ProcCtl::m_self = 0; | 9 | ProcCtl* ProcCtl::m_self = 0; |
10 | 10 | ||
11 | ProcCtl::ProcCtl() { | 11 | ProcCtl::ProcCtl() { |
12 | signal( SIGCHLD, signal_handler ); | 12 | signal( SIGCHLD, signal_handler ); |
13 | } | 13 | } |
14 | ProcCtl::~ProcCtl() { | 14 | ProcCtl::~ProcCtl() { |
15 | } | 15 | } |
16 | ProcCtl* ProcCtl::self() { | 16 | ProcCtl* ProcCtl::self() { |
17 | if (!m_self ) { | 17 | if (!m_self ) { |
18 | m_self = new ProcCtl; | 18 | m_self = new ProcCtl; |
19 | } | 19 | } |
20 | return m_self; | 20 | return m_self; |
21 | } | 21 | } |
22 | void ProcCtl::add(pid_t pi, int fd ) { | 22 | void ProcCtl::add(pid_t pi, int fd ) { |
23 | ProcContainer * con = new ProcContainer; | 23 | ProcContainer * con = new ProcContainer; |
24 | //memset(con, 0, sizeof(con) ); | 24 | //memset(con, 0, sizeof(con) ); |
25 | con->pid = pi; | 25 | con->pid = pi; |
26 | con->fd = fd; | 26 | con->fd = fd; |
27 | con->status = 0; | 27 | con->status = 0; |
28 | con->prev = m_last; | 28 | con->prev = m_last; |
29 | 29 | ||
30 | m_last = con; | 30 | m_last = con; |
31 | 31 | ||
32 | } | 32 | } |
33 | void ProcCtl::remove( pid_t pi ) { | 33 | void ProcCtl::remove( pid_t pi ) { |
34 | /* | 34 | /* |
35 | * We first check if the last item | 35 | * We first check if the last item |
36 | * is equal to pi the we | 36 | * is equal to pi the we |
37 | * | 37 | * |
38 | */ | 38 | */ |
39 | ProcContainer* con; | 39 | ProcContainer* con; |
40 | if (m_last->pid == pi ) { | 40 | if (m_last->pid == pi ) { |
41 | con = m_last; | 41 | con = m_last; |
42 | m_last = con->prev; | 42 | m_last = con->prev; |
43 | delete con; | 43 | delete con; |
44 | return; | 44 | return; |
45 | } | 45 | } |
46 | 46 | ||
47 | con = m_last; | 47 | con = m_last; |
48 | ProcContainer* forw = 0l; | 48 | ProcContainer* forw = 0l; |
49 | while (con ) { | 49 | while (con ) { |
50 | /* remove it */ | 50 | /* remove it */ |
51 | if ( pi == con->pid ) { | 51 | if ( pi == con->pid ) { |
52 | forw->prev = con->prev; | 52 | if (forw) |
53 | forw->prev = con->prev; | ||
54 | else | ||
55 | forw = con->prev; | ||
53 | delete con; | 56 | delete con; |
54 | return; | 57 | return; |
55 | } | 58 | } |
56 | 59 | ||
57 | forw = con; | 60 | forw = con; |
58 | con = con->prev; | 61 | con = con->prev; |
59 | } | 62 | } |
60 | 63 | ||
61 | } | 64 | } |
62 | void ProcCtl::remove( ProcContainer con ) { | 65 | void ProcCtl::remove( ProcContainer con ) { |
63 | remove( con.pid ); | 66 | remove( con.pid ); |
64 | } | 67 | } |
65 | int ProcCtl::status(pid_t pid )const{ | 68 | int ProcCtl::status(pid_t pid )const{ |
66 | ProcContainer *con = m_last; | 69 | ProcContainer *con = m_last; |
67 | while (con) { | 70 | while (con) { |
68 | if (con->pid == pid ) | 71 | if (con->pid == pid ) |
69 | return con->status; | 72 | return con->status; |
70 | con = con->prev; | 73 | con = con->prev; |
71 | } | 74 | } |
72 | return -1; | 75 | return -1; |
73 | } | 76 | } |
74 | void ProcCtl::signal_handler(int) { | 77 | void ProcCtl::signal_handler(int) { |
75 | int status; | 78 | int status; |
76 | signal( SIGCHLD, signal_handler ); | 79 | signal( SIGCHLD, signal_handler ); |
77 | pid_t pi = waitpid( -1, &status, WNOHANG ); | 80 | pid_t pi = waitpid( -1, &status, WNOHANG ); |
78 | 81 | ||
79 | /* | 82 | /* |
80 | * find the container for pid | 83 | * find the container for pid |
81 | * | 84 | * |
82 | */ | 85 | */ |
83 | if ( pi < 0 ) { | 86 | if ( pi < 0 ) { |
84 | return; | 87 | return; |
85 | } | 88 | } |
86 | 89 | ||
87 | ProcContainer* con = m_last; | 90 | ProcContainer* con = m_last; |
88 | while (con) { | 91 | while (con) { |
89 | if ( con->pid == pi ) { | 92 | if ( con->pid == pi ) { |
90 | con->status = status; | 93 | con->status = status; |
91 | char result = 1; | 94 | char result = 1; |
92 | /* give a 'signal' */ | 95 | /* give a 'signal' */ |
93 | ::write(con->fd, &result, 1 ); | 96 | ::write(con->fd, &result, 1 ); |
94 | } | 97 | } |
95 | con = con->prev; | 98 | con = con->prev; |
96 | } | 99 | } |
97 | } | 100 | } |
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index b82a86a..692fd46 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp | |||
@@ -1634,1042 +1634,1043 @@ void KateDocument::optimizeLeadingSpace(int line, int flags, int change) { | |||
1634 | } | 1634 | } |
1635 | 1635 | ||
1636 | void KateDocument::doComment(VConfig &c, int change) | 1636 | void KateDocument::doComment(VConfig &c, int change) |
1637 | { | 1637 | { |
1638 | c.flags |=KateView:: cfPersistent; | 1638 | c.flags |=KateView:: cfPersistent; |
1639 | 1639 | ||
1640 | recordStart(c, (change < 0) ? KateActionGroup::ugUncomment | 1640 | recordStart(c, (change < 0) ? KateActionGroup::ugUncomment |
1641 | : KateActionGroup::ugComment); | 1641 | : KateActionGroup::ugComment); |
1642 | 1642 | ||
1643 | QString startComment = m_highlight->getCommentStart(); | 1643 | QString startComment = m_highlight->getCommentStart(); |
1644 | QString startLineComment = m_highlight->getCommentSingleLineStart(); | 1644 | QString startLineComment = m_highlight->getCommentSingleLineStart(); |
1645 | QString endComment = m_highlight->getCommentEnd(); | 1645 | QString endComment = m_highlight->getCommentEnd(); |
1646 | 1646 | ||
1647 | int startCommentLen = startComment.length(); | 1647 | int startCommentLen = startComment.length(); |
1648 | int startLineCommentLen = startLineComment.length(); | 1648 | int startLineCommentLen = startLineComment.length(); |
1649 | int endCommentLen = endComment.length(); | 1649 | int endCommentLen = endComment.length(); |
1650 | 1650 | ||
1651 | if (change > 0) | 1651 | if (change > 0) |
1652 | { | 1652 | { |
1653 | if ( !hasMarkedText() ) | 1653 | if ( !hasMarkedText() ) |
1654 | { | 1654 | { |
1655 | if (startLineComment != "") | 1655 | if (startLineComment != "") |
1656 | { | 1656 | { |
1657 | // Add a start comment mark | 1657 | // Add a start comment mark |
1658 | c.cursor.x = 0; | 1658 | c.cursor.x = 0; |
1659 | recordReplace(c.cursor, 0, startLineComment); | 1659 | recordReplace(c.cursor, 0, startLineComment); |
1660 | } | 1660 | } |
1661 | else if ((startComment != "") && (endComment != "")) | 1661 | else if ((startComment != "") && (endComment != "")) |
1662 | { | 1662 | { |
1663 | // Add a start comment mark | 1663 | // Add a start comment mark |
1664 | c.cursor.x = 0; | 1664 | c.cursor.x = 0; |
1665 | recordReplace(c.cursor, 0, startComment); | 1665 | recordReplace(c.cursor, 0, startComment); |
1666 | 1666 | ||
1667 | // Add an end comment mark | 1667 | // Add an end comment mark |
1668 | TextLine* textline = getTextLine(c.cursor.y); | 1668 | TextLine* textline = getTextLine(c.cursor.y); |
1669 | c.cursor.x = textline->length(); | 1669 | c.cursor.x = textline->length(); |
1670 | recordReplace(c.cursor, 0, endComment); | 1670 | recordReplace(c.cursor, 0, endComment); |
1671 | c.cursor.x = 0; | 1671 | c.cursor.x = 0; |
1672 | } | 1672 | } |
1673 | } | 1673 | } |
1674 | else if ((startComment != "") && (endComment != "")) | 1674 | else if ((startComment != "") && (endComment != "")) |
1675 | { | 1675 | { |
1676 | QString marked (c.view->markedText ()); | 1676 | QString marked (c.view->markedText ()); |
1677 | int preDeleteLine = -1, preDeleteCol = -1; | 1677 | int preDeleteLine = -1, preDeleteCol = -1; |
1678 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); | 1678 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); |
1679 | 1679 | ||
1680 | if (marked.length() > 0) | 1680 | if (marked.length() > 0) |
1681 | c.view->keyDelete (); | 1681 | c.view->keyDelete (); |
1682 | 1682 | ||
1683 | int line = -1, col = -1; | 1683 | int line = -1, col = -1; |
1684 | c.view->getCursorPosition (&line, &col); | 1684 | c.view->getCursorPosition (&line, &col); |
1685 | 1685 | ||
1686 | c.view->insertText (startComment + marked + endComment); | 1686 | c.view->insertText (startComment + marked + endComment); |
1687 | } | 1687 | } |
1688 | } | 1688 | } |
1689 | else | 1689 | else |
1690 | { | 1690 | { |
1691 | if ( !hasMarkedText() ) | 1691 | if ( !hasMarkedText() ) |
1692 | { | 1692 | { |
1693 | TextLine* textline = getTextLine(c.cursor.y); | 1693 | TextLine* textline = getTextLine(c.cursor.y); |
1694 | 1694 | ||
1695 | if(textline->startingWith(startLineComment)) | 1695 | if(textline->startingWith(startLineComment)) |
1696 | { | 1696 | { |
1697 | // Remove start comment mark | 1697 | // Remove start comment mark |
1698 | c.cursor.x = 0; | 1698 | c.cursor.x = 0; |
1699 | recordReplace(c.cursor, startLineCommentLen, ""); | 1699 | recordReplace(c.cursor, startLineCommentLen, ""); |
1700 | } | 1700 | } |
1701 | else if (textline->startingWith(startComment) && textline->endingWith(endComment)) | 1701 | else if (textline->startingWith(startComment) && textline->endingWith(endComment)) |
1702 | { | 1702 | { |
1703 | // Remove start comment mark | 1703 | // Remove start comment mark |
1704 | c.cursor.x = 0; | 1704 | c.cursor.x = 0; |
1705 | recordReplace(c.cursor, startCommentLen, ""); | 1705 | recordReplace(c.cursor, startCommentLen, ""); |
1706 | 1706 | ||
1707 | // Remove end comment mark | 1707 | // Remove end comment mark |
1708 | if(endComment != "") | 1708 | if(endComment != "") |
1709 | { | 1709 | { |
1710 | c.cursor.x = textline->length() - endCommentLen; | 1710 | c.cursor.x = textline->length() - endCommentLen; |
1711 | recordReplace(c.cursor, endCommentLen, ""); | 1711 | recordReplace(c.cursor, endCommentLen, ""); |
1712 | c.cursor.x = 0; | 1712 | c.cursor.x = 0; |
1713 | } | 1713 | } |
1714 | } | 1714 | } |
1715 | } | 1715 | } |
1716 | else | 1716 | else |
1717 | { | 1717 | { |
1718 | QString marked (c.view->markedText ()); | 1718 | QString marked (c.view->markedText ()); |
1719 | int preDeleteLine = -1, preDeleteCol = -1; | 1719 | int preDeleteLine = -1, preDeleteCol = -1; |
1720 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); | 1720 | c.view->getCursorPosition (&preDeleteLine, &preDeleteCol); |
1721 | 1721 | ||
1722 | int start = marked.find (startComment); | 1722 | int start = marked.find (startComment); |
1723 | int end = marked.findRev (endComment); | 1723 | int end = marked.findRev (endComment); |
1724 | 1724 | ||
1725 | if ((start > -1) && (end > -1)) | 1725 | if ((start > -1) && (end > -1)) |
1726 | { | 1726 | { |
1727 | marked.remove (start, startCommentLen); | 1727 | marked.remove (start, startCommentLen); |
1728 | marked.remove (end-startCommentLen, endCommentLen); | 1728 | marked.remove (end-startCommentLen, endCommentLen); |
1729 | 1729 | ||
1730 | c.view->keyDelete (); | 1730 | c.view->keyDelete (); |
1731 | 1731 | ||
1732 | int line = -1, col = -1; | 1732 | int line = -1, col = -1; |
1733 | c.view->getCursorPosition (&line, &col); | 1733 | c.view->getCursorPosition (&line, &col); |
1734 | c.view->insertText (marked); | 1734 | c.view->insertText (marked); |
1735 | } | 1735 | } |
1736 | } | 1736 | } |
1737 | } | 1737 | } |
1738 | 1738 | ||
1739 | recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); | 1739 | recordEnd(c.view, c.cursor, c.flags | KateView::cfPersistent); |
1740 | } | 1740 | } |
1741 | 1741 | ||
1742 | 1742 | ||
1743 | QString KateDocument::text() const | 1743 | QString KateDocument::text() const |
1744 | { | 1744 | { |
1745 | QString s; | 1745 | QString s; |
1746 | 1746 | ||
1747 | for (int i=0; i < buffer->count(); i++) | 1747 | for (int i=0; i < buffer->count(); i++) |
1748 | { | 1748 | { |
1749 | TextLine::Ptr textLine = buffer->line(i); | 1749 | TextLine::Ptr textLine = buffer->line(i); |
1750 | s.insert(s.length(), textLine->getText(), textLine->length()); | 1750 | s.insert(s.length(), textLine->getText(), textLine->length()); |
1751 | if ( (i < (buffer->count()-1)) ) | 1751 | if ( (i < (buffer->count()-1)) ) |
1752 | s.append('\n'); | 1752 | s.append('\n'); |
1753 | } | 1753 | } |
1754 | 1754 | ||
1755 | return s; | 1755 | return s; |
1756 | } | 1756 | } |
1757 | 1757 | ||
1758 | QString KateDocument::getWord(PointStruc &cursor) { | 1758 | QString KateDocument::getWord(PointStruc &cursor) { |
1759 | int start, end, len; | 1759 | int start, end, len; |
1760 | 1760 | ||
1761 | TextLine::Ptr textLine = getTextLine(cursor.y); | 1761 | TextLine::Ptr textLine = getTextLine(cursor.y); |
1762 | len = textLine->length(); | 1762 | len = textLine->length(); |
1763 | start = end = cursor.x; | 1763 | start = end = cursor.x; |
1764 | while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; | 1764 | while (start > 0 && m_highlight->isInWord(textLine->getChar(start - 1))) start--; |
1765 | while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; | 1765 | while (end < len && m_highlight->isInWord(textLine->getChar(end))) end++; |
1766 | len = end - start; | 1766 | len = end - start; |
1767 | return QString(&textLine->getText()[start], len); | 1767 | return QString(&textLine->getText()[start], len); |
1768 | } | 1768 | } |
1769 | 1769 | ||
1770 | void KateDocument::setText(const QString &s) { | 1770 | void KateDocument::setText(const QString &s) { |
1771 | int pos; | 1771 | int pos; |
1772 | QChar ch; | 1772 | QChar ch; |
1773 | 1773 | ||
1774 | clear(); | 1774 | clear(); |
1775 | 1775 | ||
1776 | int line=1; | 1776 | int line=1; |
1777 | 1777 | ||
1778 | TextLine::Ptr textLine = buffer->line(0); | 1778 | TextLine::Ptr textLine = buffer->line(0); |
1779 | for (pos = 0; pos <= (int) s.length(); pos++) { | 1779 | for (pos = 0; pos <= (int) s.length(); pos++) { |
1780 | ch = s[pos]; | 1780 | ch = s[pos]; |
1781 | if (ch.isPrint() || ch == '\t') { | 1781 | if (ch.isPrint() || ch == '\t') { |
1782 | textLine->append(&ch, 1); | 1782 | textLine->append(&ch, 1); |
1783 | } else if (ch == '\n') | 1783 | } else if (ch == '\n') |
1784 | { | 1784 | { |
1785 | textLine = new TextLine(); | 1785 | textLine = new TextLine(); |
1786 | buffer->insertLine (line, textLine); | 1786 | buffer->insertLine (line, textLine); |
1787 | line++; | 1787 | line++; |
1788 | } | 1788 | } |
1789 | } | 1789 | } |
1790 | updateLines(); | 1790 | updateLines(); |
1791 | } | 1791 | } |
1792 | 1792 | ||
1793 | 1793 | ||
1794 | QString KateDocument::markedText(int flags) { | 1794 | QString KateDocument::markedText(int flags) { |
1795 | TextLine::Ptr textLine; | 1795 | TextLine::Ptr textLine; |
1796 | int len, z, start, end, i; | 1796 | int len, z, start, end, i; |
1797 | 1797 | ||
1798 | len = 1; | 1798 | len = 1; |
1799 | if (!(flags & KateView::cfVerticalSelect)) { | 1799 | if (!(flags & KateView::cfVerticalSelect)) { |
1800 | for (z = selectStart; z <= selectEnd; z++) { | 1800 | for (z = selectStart; z <= selectEnd; z++) { |
1801 | textLine = getTextLine(z); | 1801 | textLine = getTextLine(z); |
1802 | len += textLine->numSelected(); | 1802 | len += textLine->numSelected(); |
1803 | if (textLine->isSelected()) len++; | 1803 | if (textLine->isSelected()) len++; |
1804 | } | 1804 | } |
1805 | QString s; | 1805 | QString s; |
1806 | len = 0; | 1806 | len = 0; |
1807 | for (z = selectStart; z <= selectEnd; z++) { | 1807 | for (z = selectStart; z <= selectEnd; z++) { |
1808 | textLine = getTextLine(z); | 1808 | textLine = getTextLine(z); |
1809 | end = 0; | 1809 | end = 0; |
1810 | do { | 1810 | do { |
1811 | start = textLine->findUnselected(end); | 1811 | start = textLine->findUnselected(end); |
1812 | end = textLine->findSelected(start); | 1812 | end = textLine->findSelected(start); |
1813 | for (i = start; i < end; i++) { | 1813 | for (i = start; i < end; i++) { |
1814 | s[len] = textLine->getChar(i); | 1814 | s[len] = textLine->getChar(i); |
1815 | len++; | 1815 | len++; |
1816 | } | 1816 | } |
1817 | } while (start < end); | 1817 | } while (start < end); |
1818 | if (textLine->isSelected()) { | 1818 | if (textLine->isSelected()) { |
1819 | s[len] = '\n'; | 1819 | s[len] = '\n'; |
1820 | len++; | 1820 | len++; |
1821 | } | 1821 | } |
1822 | } | 1822 | } |
1823 | // s[len] = '\0'; | 1823 | // s[len] = '\0'; |
1824 | return s; | 1824 | return s; |
1825 | } else { | 1825 | } else { |
1826 | for (z = selectStart; z <= selectEnd; z++) { | 1826 | for (z = selectStart; z <= selectEnd; z++) { |
1827 | textLine = getTextLine(z); | 1827 | textLine = getTextLine(z); |
1828 | len += textLine->numSelected() + 1; | 1828 | len += textLine->numSelected() + 1; |
1829 | } | 1829 | } |
1830 | QString s; | 1830 | QString s; |
1831 | len = 0; | 1831 | len = 0; |
1832 | for (z = selectStart; z <= selectEnd; z++) { | 1832 | for (z = selectStart; z <= selectEnd; z++) { |
1833 | textLine = getTextLine(z); | 1833 | textLine = getTextLine(z); |
1834 | end = 0; | 1834 | end = 0; |
1835 | do { | 1835 | do { |
1836 | start = textLine->findUnselected(end); | 1836 | start = textLine->findUnselected(end); |
1837 | end = textLine->findSelected(start); | 1837 | end = textLine->findSelected(start); |
1838 | for (i = start; i < end; i++) { | 1838 | for (i = start; i < end; i++) { |
1839 | s[len] = textLine->getChar(i); | 1839 | s[len] = textLine->getChar(i); |
1840 | len++; | 1840 | len++; |
1841 | } | 1841 | } |
1842 | } while (start < end); | 1842 | } while (start < end); |
1843 | s[len] = '\n'; | 1843 | s[len] = '\n'; |
1844 | len++; | 1844 | len++; |
1845 | } | 1845 | } |
1846 | // s[len] = '\0'; // the final \0 is not counted in length() | 1846 | // s[len] = '\0'; // the final \0 is not counted in length() |
1847 | return s; | 1847 | return s; |
1848 | } | 1848 | } |
1849 | } | 1849 | } |
1850 | 1850 | ||
1851 | void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) { | 1851 | void KateDocument::delMarkedText(VConfig &c/*, bool undo*/) { |
1852 | int end = 0; | 1852 | int end = 0; |
1853 | 1853 | ||
1854 | if (selectEnd < selectStart) return; | 1854 | if (selectEnd < selectStart) return; |
1855 | 1855 | ||
1856 | // the caller may have already started an undo record for the current action | 1856 | // the caller may have already started an undo record for the current action |
1857 | // if (undo) | 1857 | // if (undo) |
1858 | 1858 | ||
1859 | //auto deletion of the marked text occurs not very often and can therefore | 1859 | //auto deletion of the marked text occurs not very often and can therefore |
1860 | // be recorded separately | 1860 | // be recorded separately |
1861 | recordStart(c, KateActionGroup::ugDelBlock); | 1861 | recordStart(c, KateActionGroup::ugDelBlock); |
1862 | 1862 | ||
1863 | for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) { | 1863 | for (c.cursor.y = selectEnd; c.cursor.y >= selectStart; c.cursor.y--) { |
1864 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 1864 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
1865 | 1865 | ||
1866 | c.cursor.x = textLine->length(); | 1866 | c.cursor.x = textLine->length(); |
1867 | do { | 1867 | do { |
1868 | end = textLine->findRevUnselected(c.cursor.x); | 1868 | end = textLine->findRevUnselected(c.cursor.x); |
1869 | if (end == 0) break; | 1869 | if (end == 0) break; |
1870 | c.cursor.x = textLine->findRevSelected(end); | 1870 | c.cursor.x = textLine->findRevSelected(end); |
1871 | recordDelete(c.cursor, end - c.cursor.x); | 1871 | recordDelete(c.cursor, end - c.cursor.x); |
1872 | } while (true); | 1872 | } while (true); |
1873 | end = c.cursor.x; | 1873 | end = c.cursor.x; |
1874 | c.cursor.x = textLine->length(); | 1874 | c.cursor.x = textLine->length(); |
1875 | if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor); | 1875 | if (textLine->isSelected()) recordAction(KateAction::delLine,c.cursor); |
1876 | } | 1876 | } |
1877 | c.cursor.y++; | 1877 | c.cursor.y++; |
1878 | /*if (end < c.cursor.x)*/ c.cursor.x = end; | 1878 | /*if (end < c.cursor.x)*/ c.cursor.x = end; |
1879 | 1879 | ||
1880 | selectEnd = -1; | 1880 | selectEnd = -1; |
1881 | select.x = -1; | 1881 | select.x = -1; |
1882 | 1882 | ||
1883 | /*if (undo)*/ recordEnd(c); | 1883 | /*if (undo)*/ recordEnd(c); |
1884 | } | 1884 | } |
1885 | 1885 | ||
1886 | void KateDocument::tagLineRange(int line, int x1, int x2) { | 1886 | void KateDocument::tagLineRange(int line, int x1, int x2) { |
1887 | int z; | 1887 | int z; |
1888 | 1888 | ||
1889 | for (z = 0; z < (int) views.count(); z++) { | 1889 | for (z = 0; z < (int) views.count(); z++) { |
1890 | views.at(z)->tagLines(line, line, x1, x2); | 1890 | views.at(z)->tagLines(line, line, x1, x2); |
1891 | } | 1891 | } |
1892 | } | 1892 | } |
1893 | 1893 | ||
1894 | void KateDocument::tagLines(int start, int end) { | 1894 | void KateDocument::tagLines(int start, int end) { |
1895 | int z; | 1895 | int z; |
1896 | 1896 | ||
1897 | for (z = 0; z < (int) views.count(); z++) { | 1897 | for (z = 0; z < (int) views.count(); z++) { |
1898 | views.at(z)->tagLines(start, end, 0, 0xffffff); | 1898 | views.at(z)->tagLines(start, end, 0, 0xffffff); |
1899 | } | 1899 | } |
1900 | } | 1900 | } |
1901 | 1901 | ||
1902 | void KateDocument::tagAll() { | 1902 | void KateDocument::tagAll() { |
1903 | int z; | 1903 | int z; |
1904 | 1904 | ||
1905 | for (z = 0; z < (int) views.count(); z++) { | 1905 | for (z = 0; z < (int) views.count(); z++) { |
1906 | views.at(z)->tagAll(); | 1906 | views.at(z)->tagAll(); |
1907 | } | 1907 | } |
1908 | } | 1908 | } |
1909 | 1909 | ||
1910 | void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { | 1910 | void KateDocument::updateLines(int startLine, int endLine, int flags, int cursorY) { |
1911 | TextLine::Ptr textLine; | 1911 | TextLine::Ptr textLine; |
1912 | int line, last_line; | 1912 | int line, last_line; |
1913 | int ctxNum, endCtx; | 1913 | int ctxNum, endCtx; |
1914 | // kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; | 1914 | // kdDebug(13020)<<"******************KateDocument::updateLines Checkpoint 1"<<endl; |
1915 | if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; | 1915 | if (buffer->line(startLine)==0) {kdDebug(13020)<<"********************No buffer for line " << startLine << " found**************"<<endl; return;}; |
1916 | // kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; | 1916 | // kdDebug(13020)<<"KateDocument::updateLines Checkpoint 2"<<endl; |
1917 | last_line = lastLine(); | 1917 | last_line = lastLine(); |
1918 | // if (endLine >= last_line) endLine = last_line; | 1918 | // if (endLine >= last_line) endLine = last_line; |
1919 | 1919 | ||
1920 | line = startLine; | 1920 | line = startLine; |
1921 | ctxNum = 0; | 1921 | ctxNum = 0; |
1922 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); | 1922 | if (line > 0) ctxNum = getTextLine(line - 1)->getContext(); |
1923 | do { | 1923 | do { |
1924 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; | 1924 | // kdDebug(13020)<<QString("**************Working on line: %1").arg(line)<<endl; |
1925 | textLine = getTextLine(line); | 1925 | textLine = getTextLine(line); |
1926 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; | 1926 | if (textLine==0) kdDebug(13020)<<"****updateLines()>> error textLine==0"<<endl; |
1927 | if (line <= endLine && line != cursorY) { | 1927 | if (line <= endLine && line != cursorY) { |
1928 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); | 1928 | if (flags & KateView::cfRemoveSpaces) textLine->removeSpaces(); |
1929 | updateMaxLength(textLine); | 1929 | updateMaxLength(textLine); |
1930 | } | 1930 | } |
1931 | endCtx = textLine->getContext(); | 1931 | endCtx = textLine->getContext(); |
1932 | // odebug << "DOHIGHLIGHT" << oendl; | 1932 | // odebug << "DOHIGHLIGHT" << oendl; |
1933 | 1933 | ||
1934 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); | 1934 | ctxNum = m_highlight->doHighlight(ctxNum,textLine); |
1935 | textLine->setContext(ctxNum); | 1935 | textLine->setContext(ctxNum); |
1936 | line++; | 1936 | line++; |
1937 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); | 1937 | } while ((buffer->line(line)!=0) && (line <= endLine || endCtx != ctxNum)); |
1938 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; | 1938 | // kdDebug(13020)<<"updateLines :: while loop left"<<endl; |
1939 | tagLines(startLine, line - 1); | 1939 | tagLines(startLine, line - 1); |
1940 | } | 1940 | } |
1941 | 1941 | ||
1942 | 1942 | ||
1943 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { | 1943 | void KateDocument::updateMaxLength(TextLine::Ptr &textLine) { |
1944 | int len; | 1944 | int len; |
1945 | 1945 | ||
1946 | len = textWidth(textLine,textLine->length()); | 1946 | len = textWidth(textLine,textLine->length()); |
1947 | 1947 | ||
1948 | if (len > maxLength) { | 1948 | if (len > maxLength) { |
1949 | longestLine = textLine; | 1949 | longestLine = textLine; |
1950 | maxLength = len; | 1950 | maxLength = len; |
1951 | newDocGeometry = true; | 1951 | newDocGeometry = true; |
1952 | } else { | 1952 | } else { |
1953 | if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { | 1953 | if (!longestLine || (textLine == longestLine && len <= maxLength*3/4)) { |
1954 | maxLength = -1; | 1954 | maxLength = -1; |
1955 | for (int i = 0; i < numLines();i++) { | 1955 | for (int i = 0; i < numLines();i++) { |
1956 | textLine = getTextLine(i); | 1956 | textLine = getTextLine(i); |
1957 | len = textWidth(textLine,textLine->length()); | 1957 | len = textWidth(textLine,textLine->length()); |
1958 | if (len > maxLength) { | 1958 | if (len > maxLength) { |
1959 | maxLength = len; | 1959 | maxLength = len; |
1960 | longestLine = textLine; | 1960 | longestLine = textLine; |
1961 | } | 1961 | } |
1962 | } | 1962 | } |
1963 | newDocGeometry = true; | 1963 | newDocGeometry = true; |
1964 | } | 1964 | } |
1965 | } | 1965 | } |
1966 | } | 1966 | } |
1967 | 1967 | ||
1968 | void KateDocument::slotBufferChanged() { | 1968 | void KateDocument::slotBufferChanged() { |
1969 | newDocGeometry = true; | 1969 | newDocGeometry = true; |
1970 | //updateLines();//JW | 1970 | //updateLines();//JW |
1971 | updateViews(); | 1971 | updateViews(); |
1972 | } | 1972 | } |
1973 | 1973 | ||
1974 | void KateDocument::slotBufferHighlight(long start,long stop) { | 1974 | void KateDocument::slotBufferHighlight(long start,long stop) { |
1975 | kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; | 1975 | kdDebug(13020)<<"KateDocument::slotBufferHighlight"<<QString("%1-%2").arg(start).arg(stop)<<endl; |
1976 | updateLines(start,stop); | 1976 | updateLines(start,stop); |
1977 | // buffer->startLoadTimer(); | 1977 | // buffer->startLoadTimer(); |
1978 | } | 1978 | } |
1979 | 1979 | ||
1980 | void KateDocument::updateViews(KateView *exclude) { | 1980 | void KateDocument::updateViews(KateView *exclude) { |
1981 | KateView *view; | 1981 | KateView *view; |
1982 | int flags; | 1982 | int flags; |
1983 | bool markState = hasMarkedText(); | 1983 | bool markState = hasMarkedText(); |
1984 | 1984 | ||
1985 | flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; | 1985 | flags = (newDocGeometry) ? KateView::ufDocGeometry : 0; |
1986 | for (view = views.first(); view != 0L; view = views.next() ) { | 1986 | for (view = views.first(); view != 0L; view = views.next() ) { |
1987 | if (view != exclude) view->updateView(flags); | 1987 | if (view != exclude) view->updateView(flags); |
1988 | 1988 | ||
1989 | // notify every view about the changed mark state.... | 1989 | // notify every view about the changed mark state.... |
1990 | if (oldMarkState != markState) emit view->newMarkStatus(); | 1990 | if (oldMarkState != markState) emit view->newMarkStatus(); |
1991 | } | 1991 | } |
1992 | oldMarkState = markState; | 1992 | oldMarkState = markState; |
1993 | newDocGeometry = false; | 1993 | newDocGeometry = false; |
1994 | } | 1994 | } |
1995 | 1995 | ||
1996 | QColor &KateDocument::cursorCol(int x, int y) { | 1996 | QColor &KateDocument::cursorCol(int x, int y) { |
1997 | int attr; | 1997 | int attr; |
1998 | Attribute *a; | 1998 | Attribute *a; |
1999 | 1999 | ||
2000 | TextLine::Ptr textLine = getTextLine(y); | 2000 | TextLine::Ptr textLine = getTextLine(y); |
2001 | attr = textLine->getRawAttr(x); | 2001 | attr = textLine->getRawAttr(x); |
2002 | a = &m_attribs[attr & taAttrMask]; | 2002 | a = &m_attribs[attr & taAttrMask]; |
2003 | if (attr & taSelected) return a->selCol; else return a->col; | 2003 | if (attr & taSelected) return a->selCol; else return a->col; |
2004 | } | 2004 | } |
2005 | 2005 | ||
2006 | void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) | 2006 | void KateDocument::paintTextLine(QPainter &paint, int line, int xStart, int xEnd, bool showTabs) |
2007 | { | 2007 | { |
2008 | paintTextLine (paint, line, 0, xStart, xEnd, showTabs); | 2008 | paintTextLine (paint, line, 0, xStart, xEnd, showTabs); |
2009 | } | 2009 | } |
2010 | 2010 | ||
2011 | void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) | 2011 | void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, int xEnd, bool showTabs) |
2012 | { | 2012 | { |
2013 | TextLine::Ptr textLine; | 2013 | TextLine::Ptr textLine; |
2014 | int len; | 2014 | int len; |
2015 | const QChar *s; | 2015 | const QChar *s; |
2016 | int z, x; | 2016 | int z, x; |
2017 | QChar ch; | 2017 | QChar ch; |
2018 | Attribute *a = 0L; | 2018 | Attribute *attrptr = 0L; |
2019 | int attr, nextAttr; | 2019 | int attr, nextAttr; |
2020 | int xs; | 2020 | int xs; |
2021 | int xc, zc; | 2021 | int xc, zc; |
2022 | 2022 | ||
2023 | if (line > lastLine()) { | 2023 | if (line > lastLine()) { |
2024 | paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); | 2024 | paint.fillRect(0, y, xEnd - xStart,fontHeight, colors[0]); |
2025 | return; | 2025 | return; |
2026 | } | 2026 | } |
2027 | 2027 | ||
2028 | textLine = getTextLine(line); | 2028 | textLine = getTextLine(line); |
2029 | len = textLine->length(); | 2029 | len = textLine->length(); |
2030 | s = textLine->getText(); | 2030 | s = textLine->getText(); |
2031 | 2031 | ||
2032 | // skip to first visible character | 2032 | // skip to first visible character |
2033 | x = 0; | 2033 | x = 0; |
2034 | z = 0; | 2034 | z = 0; |
2035 | do { | 2035 | do { |
2036 | xc = x; | 2036 | xc = x; |
2037 | zc = z; | 2037 | zc = z; |
2038 | if (z == len) break; | 2038 | if (z == len) break; |
2039 | ch = s[z];//textLine->getChar(z); | 2039 | ch = s[z];//textLine->getChar(z); |
2040 | if (ch == '\t') { | 2040 | if (ch == '\t') { |
2041 | x += m_tabWidth - (x % m_tabWidth); | 2041 | x += m_tabWidth - (x % m_tabWidth); |
2042 | } else { | 2042 | } else { |
2043 | a = &m_attribs[textLine->getAttr(z)]; | 2043 | attrptr = &m_attribs[textLine->getAttr(z)]; |
2044 | 2044 | ||
2045 | if (a->bold && a->italic) | 2045 | if (attrptr->bold && attrptr->italic) |
2046 | x += myFontMetricsBI.width(ch); | 2046 | x += myFontMetricsBI.width(ch); |
2047 | else if (a->bold) | 2047 | else if (attrptr->bold) |
2048 | x += myFontMetricsBold.width(ch); | 2048 | x += myFontMetricsBold.width(ch); |
2049 | else if (a->italic) | 2049 | else if (attrptr->italic) |
2050 | x += myFontMetricsItalic.width(ch); | 2050 | x += myFontMetricsItalic.width(ch); |
2051 | else | 2051 | else |
2052 | x += myFontMetrics.width(ch); | 2052 | x += myFontMetrics.width(ch); |
2053 | } | 2053 | } |
2054 | z++; | 2054 | z++; |
2055 | } while (x <= xStart); | 2055 | } while (x <= xStart); |
2056 | 2056 | ||
2057 | // draw background | 2057 | // draw background |
2058 | xs = xStart; | 2058 | xs = xStart; |
2059 | attr = textLine->getRawAttr(zc); | 2059 | attr = textLine->getRawAttr(zc); |
2060 | while (x < xEnd) | 2060 | while (x < xEnd) |
2061 | { | 2061 | { |
2062 | nextAttr = textLine->getRawAttr(z); | 2062 | nextAttr = textLine->getRawAttr(z); |
2063 | if ((nextAttr ^ attr) & taSelected) | 2063 | if ((nextAttr ^ attr) & taSelected) |
2064 | { | 2064 | { |
2065 | if (attr & taSelected) | 2065 | if (attr & taSelected) |
2066 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); | 2066 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[1]); |
2067 | else | 2067 | else |
2068 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); | 2068 | paint.fillRect(xs - xStart, y, x - xs, fontHeight, colors[0]); |
2069 | 2069 | ||
2070 | xs = x; | 2070 | xs = x; |
2071 | attr = nextAttr; | 2071 | attr = nextAttr; |
2072 | } | 2072 | } |
2073 | 2073 | ||
2074 | if (z == len) break; | 2074 | if (z == len) break; |
2075 | 2075 | ||
2076 | ch = s[z];//textLine->getChar(z); | 2076 | ch = s[z];//textLine->getChar(z); |
2077 | 2077 | ||
2078 | if (ch == '\t') | 2078 | if (ch == '\t') |
2079 | x += m_tabWidth - (x % m_tabWidth); | 2079 | x += m_tabWidth - (x % m_tabWidth); |
2080 | else | 2080 | else |
2081 | { | 2081 | { |
2082 | a = &m_attribs[textLine->getAttr(z)]; | 2082 | attrptr = &m_attribs[textLine->getAttr(z)]; |
2083 | 2083 | ||
2084 | if (a->bold && a->italic) | 2084 | if (attrptr->bold && attrptr->italic) |
2085 | x += myFontMetricsBI.width(ch); | 2085 | x += myFontMetricsBI.width(ch); |
2086 | else if (a->bold) | 2086 | else if (attrptr->bold) |
2087 | x += myFontMetricsBold.width(ch); | 2087 | x += myFontMetricsBold.width(ch); |
2088 | else if (a->italic) | 2088 | else if (attrptr->italic) |
2089 | x += myFontMetricsItalic.width(ch); | 2089 | x += myFontMetricsItalic.width(ch); |
2090 | else | 2090 | else |
2091 | x += myFontMetrics.width(ch); | 2091 | x += myFontMetrics.width(ch); |
2092 | } | 2092 | } |
2093 | z++; | 2093 | z++; |
2094 | } | 2094 | } |
2095 | 2095 | ||
2096 | if (attr & taSelected) | 2096 | if (attr & taSelected) |
2097 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); | 2097 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[1]); |
2098 | else | 2098 | else |
2099 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); | 2099 | paint.fillRect(xs - xStart, y, xEnd - xs, fontHeight, colors[0]); |
2100 | 2100 | ||
2101 | len = z; //reduce length to visible length | 2101 | len = z; //reduce length to visible length |
2102 | 2102 | ||
2103 | // draw text | 2103 | // draw text |
2104 | x = xc; | 2104 | x = xc; |
2105 | z = zc; | 2105 | z = zc; |
2106 | y += fontAscent;// -1; | 2106 | y += fontAscent;// -1; |
2107 | attr = -1; | 2107 | attr = -1; |
2108 | while (z < len) { | 2108 | while (z < len) { |
2109 | ch = s[z];//textLine->getChar(z); | 2109 | ch = s[z];//textLine->getChar(z); |
2110 | if (ch == '\t') { | 2110 | if (ch == '\t') { |
2111 | if (z > zc) { | 2111 | if (z > zc) { |
2112 | //this should cause no copy at all | 2112 | //this should cause no copy at all |
2113 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2113 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2114 | QString s = str.string(); | 2114 | QString s = str.string(); |
2115 | paint.drawText(x - xStart, y, s); | 2115 | paint.drawText(x - xStart, y, s); |
2116 | 2116 | ||
2117 | if (a->bold && a->italic) | 2117 | if (attrptr && attrptr->bold && attrptr->italic) |
2118 | x += myFontMetricsBI.width(s); | 2118 | x += myFontMetricsBI.width(s); |
2119 | else if (a->bold) | 2119 | else if (attrptr && attrptr->bold) |
2120 | x += myFontMetricsBold.width(s); | 2120 | x += myFontMetricsBold.width(s); |
2121 | else if (a->italic) | 2121 | else if (attrptr && attrptr->italic) |
2122 | x += myFontMetricsItalic.width(s); | 2122 | x += myFontMetricsItalic.width(s); |
2123 | else | 2123 | else |
2124 | x += myFontMetrics.width(s); | 2124 | x += myFontMetrics.width(s); |
2125 | } | 2125 | } |
2126 | zc = z +1; | 2126 | zc = z +1; |
2127 | 2127 | ||
2128 | if (showTabs) { | 2128 | if (showTabs) { |
2129 | nextAttr = textLine->getRawAttr(z); | 2129 | nextAttr = textLine->getRawAttr(z); |
2130 | if (nextAttr != attr) { | 2130 | if (nextAttr != attr) { |
2131 | attr = nextAttr; | 2131 | attr = nextAttr; |
2132 | a = &m_attribs[attr & taAttrMask]; | 2132 | attrptr = &m_attribs[attr & taAttrMask]; |
2133 | 2133 | ||
2134 | if (attr & taSelected) paint.setPen(a->selCol); | 2134 | if (attr & taSelected) paint.setPen(attrptr->selCol); |
2135 | else paint.setPen(a->col); | 2135 | else paint.setPen(attrptr->col); |
2136 | 2136 | ||
2137 | if (a->bold && a->italic) | 2137 | if (attrptr->bold && attrptr->italic) |
2138 | paint.setFont(myFontBI); | 2138 | paint.setFont(myFontBI); |
2139 | else if (a->bold) | 2139 | else if (attrptr->bold) |
2140 | paint.setFont(myFontBold); | 2140 | paint.setFont(myFontBold); |
2141 | else if (a->italic) | 2141 | else if (attrptr->italic) |
2142 | paint.setFont(myFontItalic); | 2142 | paint.setFont(myFontItalic); |
2143 | else | 2143 | else |
2144 | paint.setFont(myFont); | 2144 | paint.setFont(myFont); |
2145 | } | 2145 | } |
2146 | 2146 | ||
2147 | // paint.drawLine(x - xStart, y -2, x - xStart, y); | ||
2148 | // paint.drawLine(x - xStart, y, x - xStart + 2, y); | ||
2149 | paint.drawPoint(x - xStart, y); | 2147 | paint.drawPoint(x - xStart, y); |
2150 | paint.drawPoint(x - xStart +1, y); | 2148 | paint.drawPoint(x - xStart +1, y); |
2151 | paint.drawPoint(x - xStart, y -1); | 2149 | paint.drawPoint(x - xStart, y -1); |
2152 | } | 2150 | } |
2153 | x += m_tabWidth - (x % m_tabWidth); | 2151 | x += m_tabWidth - (x % m_tabWidth); |
2154 | } else { | 2152 | } else { |
2155 | nextAttr = textLine->getRawAttr(z); | 2153 | nextAttr = textLine->getRawAttr(z); |
2156 | if (nextAttr != attr) { | 2154 | if (nextAttr != attr) { |
2157 | if (z > zc) { | 2155 | if (z > zc) { |
2158 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2156 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2159 | QString s = str.string(); | 2157 | QString s = str.string(); |
2160 | paint.drawText(x - xStart, y, s); | 2158 | paint.drawText(x - xStart, y, s); |
2161 | 2159 | ||
2162 | if (a->bold && a->italic) | 2160 | if (attrptr->bold && attrptr->italic) |
2163 | x += myFontMetricsBI.width(s); | 2161 | x += myFontMetricsBI.width(s); |
2164 | else if (a->bold) | 2162 | else if (attrptr->bold) |
2165 | x += myFontMetricsBold.width(s); | 2163 | x += myFontMetricsBold.width(s); |
2166 | else if (a->italic) | 2164 | else if (attrptr->italic) |
2167 | x += myFontMetricsItalic.width(s); | 2165 | x += myFontMetricsItalic.width(s); |
2168 | else | 2166 | else |
2169 | x += myFontMetrics.width(s); | 2167 | x += myFontMetrics.width(s); |
2170 | zc = z; | 2168 | zc = z; |
2171 | } | 2169 | } |
2172 | attr = nextAttr; | 2170 | attr = nextAttr; |
2173 | a = &m_attribs[attr & taAttrMask]; | 2171 | attrptr = &m_attribs[attr & taAttrMask]; |
2174 | 2172 | ||
2175 | if (attr & taSelected) paint.setPen(a->selCol); | 2173 | if (attr & taSelected) paint.setPen(attrptr->selCol); |
2176 | else paint.setPen(a->col); | 2174 | else paint.setPen(attrptr->col); |
2177 | 2175 | ||
2178 | if (a->bold && a->italic) | 2176 | if (attrptr->bold && attrptr->italic) |
2179 | paint.setFont(myFontBI); | 2177 | paint.setFont(myFontBI); |
2180 | else if (a->bold) | 2178 | else if (attrptr->bold) |
2181 | paint.setFont(myFontBold); | 2179 | paint.setFont(myFontBold); |
2182 | else if (a->italic) | 2180 | else if (attrptr->italic) |
2183 | paint.setFont(myFontItalic); | 2181 | paint.setFont(myFontItalic); |
2184 | else | 2182 | else |
2185 | paint.setFont(myFont); | 2183 | paint.setFont(myFont); |
2186 | } | 2184 | } |
2187 | } | 2185 | } |
2188 | z++; | 2186 | z++; |
2189 | } | 2187 | } |
2190 | if (z > zc) { | 2188 | if (z > zc) { |
2191 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2189 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2192 | paint.drawText(x - xStart, y, str.string()); | 2190 | paint.drawText(x - xStart, y, str.string()); |
2193 | } | 2191 | } |
2194 | } | 2192 | } |
2195 | 2193 | ||
2196 | // Applies the search context, and returns whether a match was found. If one is, | 2194 | // Applies the search context, and returns whether a match was found. If one is, |
2197 | // the length of the string matched is also returned. | 2195 | // the length of the string matched is also returned. |
2198 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { | 2196 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { |
2199 | int line, col; | 2197 | int line, col; |
2200 | int searchEnd; | 2198 | int searchEnd; |
2201 | int bufLen, tlen; | 2199 | int bufLen, tlen; |
2202 | QChar *t; | 2200 | QChar *t; |
2203 | TextLine::Ptr textLine; | 2201 | TextLine::Ptr textLine; |
2204 | int pos, newPos; | 2202 | int pos, newPos; |
2205 | 2203 | ||
2206 | if (searchFor.isEmpty()) return false; | 2204 | if (searchFor.isEmpty()) return false; |
2207 | 2205 | ||
2208 | bufLen = 0; | 2206 | bufLen = 0; |
2209 | t = 0L; | 2207 | t = 0L; |
2210 | 2208 | ||
2211 | line = sc.cursor.y; | 2209 | line = sc.cursor.y; |
2212 | col = sc.cursor.x; | 2210 | col = sc.cursor.x; |
2213 | if (!(sc.flags & KateView::sfBackward)) { | 2211 | if (!(sc.flags & KateView::sfBackward)) { |
2214 | //forward search | 2212 | //forward search |
2215 | if (sc.flags & KateView::sfSelected) { | 2213 | if (sc.flags & KateView::sfSelected) { |
2216 | if (line < selectStart) { | 2214 | if (line < selectStart) { |
2217 | line = selectStart; | 2215 | line = selectStart; |
2218 | col = 0; | 2216 | col = 0; |
2219 | } | 2217 | } |
2220 | searchEnd = selectEnd; | 2218 | searchEnd = selectEnd; |
2221 | } else searchEnd = lastLine(); | 2219 | } else searchEnd = lastLine(); |
2222 | 2220 | ||
2223 | while (line <= searchEnd) { | 2221 | while (line <= searchEnd) { |
2224 | textLine = getTextLine(line); | 2222 | textLine = getTextLine(line); |
2225 | tlen = textLine->length(); | 2223 | tlen = textLine->length(); |
2226 | if (tlen > bufLen) { | 2224 | if (tlen > bufLen) { |
2227 | delete [] t; | 2225 | delete [] t; |
2228 | bufLen = (tlen + 255) & (~255); | 2226 | bufLen = (tlen + 255) & (~255); |
2229 | t = new QChar[bufLen]; | 2227 | t = new QChar[bufLen]; |
2230 | } | 2228 | } else if (!t) |
2229 | t = new QChar[bufLen]; | ||
2230 | |||
2231 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2231 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2232 | if (sc.flags & KateView::sfSelected) { | 2232 | if (sc.flags & KateView::sfSelected) { |
2233 | pos = 0; | 2233 | pos = 0; |
2234 | do { | 2234 | do { |
2235 | pos = textLine->findSelected(pos); | 2235 | pos = textLine->findSelected(pos); |
2236 | newPos = textLine->findUnselected(pos); | 2236 | newPos = textLine->findUnselected(pos); |
2237 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2237 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2238 | pos = newPos; | 2238 | pos = newPos; |
2239 | } while (pos < tlen); | 2239 | } while (pos < tlen); |
2240 | } | 2240 | } |
2241 | 2241 | ||
2242 | QString text(t, tlen); | 2242 | QString text(t, tlen); |
2243 | if (sc.flags & KateView::sfWholeWords) { | 2243 | if (sc.flags & KateView::sfWholeWords) { |
2244 | // Until the end of the line... | 2244 | // Until the end of the line... |
2245 | while (col < tlen) { | 2245 | while (col < tlen) { |
2246 | // ...find the next match. | 2246 | // ...find the next match. |
2247 | col = sc.search(text, col); | 2247 | col = sc.search(text, col); |
2248 | if (col != -1) { | 2248 | if (col != -1) { |
2249 | // Is the match delimited correctly? | 2249 | // Is the match delimited correctly? |
2250 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2250 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2251 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2251 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2252 | goto found; | 2252 | goto found; |
2253 | } | 2253 | } |
2254 | else { | 2254 | else { |
2255 | // Start again from the next character. | 2255 | // Start again from the next character. |
2256 | col++; | 2256 | col++; |
2257 | } | 2257 | } |
2258 | } | 2258 | } |
2259 | else { | 2259 | else { |
2260 | // No match. | 2260 | // No match. |
2261 | break; | 2261 | break; |
2262 | } | 2262 | } |
2263 | } | 2263 | } |
2264 | } | 2264 | } |
2265 | else { | 2265 | else { |
2266 | // Non-whole-word search. | 2266 | // Non-whole-word search. |
2267 | col = sc.search(text, col); | 2267 | col = sc.search(text, col); |
2268 | if (col != -1) | 2268 | if (col != -1) |
2269 | goto found; | 2269 | goto found; |
2270 | } | 2270 | } |
2271 | col = 0; | 2271 | col = 0; |
2272 | line++; | 2272 | line++; |
2273 | } | 2273 | } |
2274 | } else { | 2274 | } else { |
2275 | // backward search | 2275 | // backward search |
2276 | if (sc.flags & KateView::sfSelected) { | 2276 | if (sc.flags & KateView::sfSelected) { |
2277 | if (line > selectEnd) { | 2277 | if (line > selectEnd) { |
2278 | line = selectEnd; | 2278 | line = selectEnd; |
2279 | col = -1; | 2279 | col = -1; |
2280 | } | 2280 | } |
2281 | searchEnd = selectStart; | 2281 | searchEnd = selectStart; |
2282 | } else searchEnd = 0; | 2282 | } else searchEnd = 0; |
2283 | 2283 | ||
2284 | while (line >= searchEnd) { | 2284 | while (line >= searchEnd) { |
2285 | textLine = getTextLine(line); | 2285 | textLine = getTextLine(line); |
2286 | tlen = textLine->length(); | 2286 | tlen = textLine->length(); |
2287 | if (tlen > bufLen) { | 2287 | if (tlen > bufLen) { |
2288 | delete [] t; | 2288 | delete [] t; |
2289 | bufLen = (tlen + 255) & (~255); | 2289 | bufLen = (tlen + 255) & (~255); |
2290 | t = new QChar[bufLen]; | 2290 | t = new QChar[bufLen]; |
2291 | } | 2291 | } else if (!t) |
2292 | t = new QChar[bufLen]; | ||
2292 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2293 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2293 | if (sc.flags & KateView::sfSelected) { | 2294 | if (sc.flags & KateView::sfSelected) { |
2294 | pos = 0; | 2295 | pos = 0; |
2295 | do { | 2296 | do { |
2296 | pos = textLine->findSelected(pos); | 2297 | pos = textLine->findSelected(pos); |
2297 | newPos = textLine->findUnselected(pos); | 2298 | newPos = textLine->findUnselected(pos); |
2298 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2299 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2299 | pos = newPos; | 2300 | pos = newPos; |
2300 | } while (pos < tlen); | 2301 | } while (pos < tlen); |
2301 | } | 2302 | } |
2302 | 2303 | ||
2303 | if (col < 0 || col > tlen) col = tlen; | 2304 | if (col < 0 || col > tlen) col = tlen; |
2304 | 2305 | ||
2305 | QString text(t, tlen); | 2306 | QString text(t, tlen); |
2306 | if (sc.flags & KateView::sfWholeWords) { | 2307 | if (sc.flags & KateView::sfWholeWords) { |
2307 | // Until the beginning of the line... | 2308 | // Until the beginning of the line... |
2308 | while (col >= 0) { | 2309 | while (col >= 0) { |
2309 | // ...find the next match. | 2310 | // ...find the next match. |
2310 | col = sc.search(text, col); | 2311 | col = sc.search(text, col); |
2311 | if (col != -1) { | 2312 | if (col != -1) { |
2312 | // Is the match delimited correctly? | 2313 | // Is the match delimited correctly? |
2313 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2314 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2314 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2315 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2315 | goto found; | 2316 | goto found; |
2316 | } | 2317 | } |
2317 | else { | 2318 | else { |
2318 | // Start again from the previous character. | 2319 | // Start again from the previous character. |
2319 | col--; | 2320 | col--; |
2320 | } | 2321 | } |
2321 | } | 2322 | } |
2322 | else { | 2323 | else { |
2323 | // No match. | 2324 | // No match. |
2324 | break; | 2325 | break; |
2325 | } | 2326 | } |
2326 | } | 2327 | } |
2327 | } | 2328 | } |
2328 | else { | 2329 | else { |
2329 | // Non-whole-word search. | 2330 | // Non-whole-word search. |
2330 | col = sc.search(text, col); | 2331 | col = sc.search(text, col); |
2331 | if (col != -1) | 2332 | if (col != -1) |
2332 | goto found; | 2333 | goto found; |
2333 | } | 2334 | } |
2334 | col = -1; | 2335 | col = -1; |
2335 | line--; | 2336 | line--; |
2336 | } | 2337 | } |
2337 | } | 2338 | } |
2338 | sc.flags |= KateView::sfWrapped; | 2339 | sc.flags |= KateView::sfWrapped; |
2339 | return false; | 2340 | return false; |
2340 | found: | 2341 | found: |
2341 | if (sc.flags & KateView::sfWrapped) { | 2342 | if (sc.flags & KateView::sfWrapped) { |
2342 | if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) | 2343 | if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) |
2343 | ^ ((sc.flags & KateView::sfBackward) != 0)) return false; | 2344 | ^ ((sc.flags & KateView::sfBackward) != 0)) return false; |
2344 | } | 2345 | } |
2345 | sc.cursor.x = col; | 2346 | sc.cursor.x = col; |
2346 | sc.cursor.y = line; | 2347 | sc.cursor.y = line; |
2347 | return true; | 2348 | return true; |
2348 | } | 2349 | } |
2349 | 2350 | ||
2350 | void KateDocument::tagLine(int line) { | 2351 | void KateDocument::tagLine(int line) { |
2351 | 2352 | ||
2352 | if (tagStart > line) tagStart = line; | 2353 | if (tagStart > line) tagStart = line; |
2353 | if (tagEnd < line) tagEnd = line; | 2354 | if (tagEnd < line) tagEnd = line; |
2354 | } | 2355 | } |
2355 | 2356 | ||
2356 | void KateDocument::insLine(int line) { | 2357 | void KateDocument::insLine(int line) { |
2357 | KateView *view; | 2358 | KateView *view; |
2358 | 2359 | ||
2359 | if (selectStart >= line) selectStart++; | 2360 | if (selectStart >= line) selectStart++; |
2360 | if (selectEnd >= line) selectEnd++; | 2361 | if (selectEnd >= line) selectEnd++; |
2361 | if (tagStart >= line) tagStart++; | 2362 | if (tagStart >= line) tagStart++; |
2362 | if (tagEnd >= line) tagEnd++; | 2363 | if (tagEnd >= line) tagEnd++; |
2363 | 2364 | ||
2364 | newDocGeometry = true; | 2365 | newDocGeometry = true; |
2365 | for (view = views.first(); view != 0L; view = views.next() ) { | 2366 | for (view = views.first(); view != 0L; view = views.next() ) { |
2366 | view->insLine(line); | 2367 | view->insLine(line); |
2367 | } | 2368 | } |
2368 | } | 2369 | } |
2369 | 2370 | ||
2370 | void KateDocument::delLine(int line) { | 2371 | void KateDocument::delLine(int line) { |
2371 | KateView *view; | 2372 | KateView *view; |
2372 | 2373 | ||
2373 | if (selectStart >= line && selectStart > 0) selectStart--; | 2374 | if (selectStart >= line && selectStart > 0) selectStart--; |
2374 | if (selectEnd >= line) selectEnd--; | 2375 | if (selectEnd >= line) selectEnd--; |
2375 | if (tagStart >= line && tagStart > 0) tagStart--; | 2376 | if (tagStart >= line && tagStart > 0) tagStart--; |
2376 | if (tagEnd >= line) tagEnd--; | 2377 | if (tagEnd >= line) tagEnd--; |
2377 | 2378 | ||
2378 | newDocGeometry = true; | 2379 | newDocGeometry = true; |
2379 | for (view = views.first(); view != 0L; view = views.next() ) { | 2380 | for (view = views.first(); view != 0L; view = views.next() ) { |
2380 | view->delLine(line); | 2381 | view->delLine(line); |
2381 | } | 2382 | } |
2382 | } | 2383 | } |
2383 | 2384 | ||
2384 | void KateDocument::optimizeSelection() { | 2385 | void KateDocument::optimizeSelection() { |
2385 | TextLine::Ptr textLine; | 2386 | TextLine::Ptr textLine; |
2386 | 2387 | ||
2387 | while (selectStart <= selectEnd) { | 2388 | while (selectStart <= selectEnd) { |
2388 | textLine = getTextLine(selectStart); | 2389 | textLine = getTextLine(selectStart); |
2389 | if (textLine->isSelected() || textLine->numSelected() > 0) break; | 2390 | if (textLine->isSelected() || textLine->numSelected() > 0) break; |
2390 | selectStart++; | 2391 | selectStart++; |
2391 | } | 2392 | } |
2392 | while (selectEnd >= selectStart) { | 2393 | while (selectEnd >= selectStart) { |
2393 | textLine = getTextLine(selectEnd); | 2394 | textLine = getTextLine(selectEnd); |
2394 | if (textLine->isSelected() || textLine->numSelected() > 0) break; | 2395 | if (textLine->isSelected() || textLine->numSelected() > 0) break; |
2395 | selectEnd--; | 2396 | selectEnd--; |
2396 | } | 2397 | } |
2397 | if (selectStart > selectEnd) { | 2398 | if (selectStart > selectEnd) { |
2398 | selectStart = 0xffffff; | 2399 | selectStart = 0xffffff; |
2399 | selectEnd = 0; | 2400 | selectEnd = 0; |
2400 | } | 2401 | } |
2401 | } | 2402 | } |
2402 | 2403 | ||
2403 | void KateDocument::doAction(KateAction *a) { | 2404 | void KateDocument::doAction(KateAction *a) { |
2404 | 2405 | ||
2405 | switch (a->action) { | 2406 | switch (a->action) { |
2406 | case KateAction::replace: | 2407 | case KateAction::replace: |
2407 | doReplace(a); | 2408 | doReplace(a); |
2408 | break; | 2409 | break; |
2409 | case KateAction::wordWrap: | 2410 | case KateAction::wordWrap: |
2410 | doWordWrap(a); | 2411 | doWordWrap(a); |
2411 | break; | 2412 | break; |
2412 | case KateAction::wordUnWrap: | 2413 | case KateAction::wordUnWrap: |
2413 | doWordUnWrap(a); | 2414 | doWordUnWrap(a); |
2414 | break; | 2415 | break; |
2415 | case KateAction::newLine: | 2416 | case KateAction::newLine: |
2416 | doNewLine(a); | 2417 | doNewLine(a); |
2417 | break; | 2418 | break; |
2418 | case KateAction::delLine: | 2419 | case KateAction::delLine: |
2419 | doDelLine(a); | 2420 | doDelLine(a); |
2420 | break; | 2421 | break; |
2421 | case KateAction::insLine: | 2422 | case KateAction::insLine: |
2422 | doInsLine(a); | 2423 | doInsLine(a); |
2423 | break; | 2424 | break; |
2424 | case KateAction::killLine: | 2425 | case KateAction::killLine: |
2425 | doKillLine(a); | 2426 | doKillLine(a); |
2426 | break; | 2427 | break; |
2427 | /* case KateAction::doubleLine: | 2428 | /* case KateAction::doubleLine: |
2428 | break; | 2429 | break; |
2429 | case KateAction::removeLine: | 2430 | case KateAction::removeLine: |
2430 | break;*/ | 2431 | break;*/ |
2431 | } | 2432 | } |
2432 | } | 2433 | } |
2433 | 2434 | ||
2434 | void KateDocument::doReplace(KateAction *a) { | 2435 | void KateDocument::doReplace(KateAction *a) { |
2435 | TextLine::Ptr textLine; | 2436 | TextLine::Ptr textLine; |
2436 | int l; | 2437 | int l; |
2437 | 2438 | ||
2438 | //exchange current text with stored text in KateAction *a | 2439 | //exchange current text with stored text in KateAction *a |
2439 | 2440 | ||
2440 | textLine = getTextLine(a->cursor.y); | 2441 | textLine = getTextLine(a->cursor.y); |
2441 | l = textLine->length() - a->cursor.x; | 2442 | l = textLine->length() - a->cursor.x; |
2442 | if (l > a->len) l = a->len; | 2443 | if (l > a->len) l = a->len; |
2443 | 2444 | ||
2444 | QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l); | 2445 | QString oldText(&textLine->getText()[a->cursor.x], (l < 0) ? 0 : l); |
2445 | textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length()); | 2446 | textLine->replace(a->cursor.x, a->len, a->text.unicode(), a->text.length()); |
2446 | 2447 | ||
2447 | a->len = a->text.length(); | 2448 | a->len = a->text.length(); |
2448 | a->text = oldText; | 2449 | a->text = oldText; |
2449 | 2450 | ||
2450 | buffer->changeLine(a->cursor.y); | 2451 | buffer->changeLine(a->cursor.y); |
2451 | 2452 | ||
2452 | tagLine(a->cursor.y); | 2453 | tagLine(a->cursor.y); |
2453 | } | 2454 | } |
2454 | 2455 | ||
2455 | void KateDocument::doWordWrap(KateAction *a) { | 2456 | void KateDocument::doWordWrap(KateAction *a) { |
2456 | TextLine::Ptr textLine; | 2457 | TextLine::Ptr textLine; |
2457 | 2458 | ||
2458 | textLine = getTextLine(a->cursor.y - 1); | 2459 | textLine = getTextLine(a->cursor.y - 1); |
2459 | a->len = textLine->length() - a->cursor.x; | 2460 | a->len = textLine->length() - a->cursor.x; |
2460 | textLine->wrap(getTextLine(a->cursor.y),a->len); | 2461 | textLine->wrap(getTextLine(a->cursor.y),a->len); |
2461 | 2462 | ||
2462 | buffer->changeLine(a->cursor.y - 1); | 2463 | buffer->changeLine(a->cursor.y - 1); |
2463 | buffer->changeLine(a->cursor.y); | 2464 | buffer->changeLine(a->cursor.y); |
2464 | 2465 | ||
2465 | tagLine(a->cursor.y - 1); | 2466 | tagLine(a->cursor.y - 1); |
2466 | tagLine(a->cursor.y); | 2467 | tagLine(a->cursor.y); |
2467 | if (selectEnd == a->cursor.y - 1) selectEnd++; | 2468 | if (selectEnd == a->cursor.y - 1) selectEnd++; |
2468 | 2469 | ||
2469 | a->action = KateAction::wordUnWrap; | 2470 | a->action = KateAction::wordUnWrap; |
2470 | } | 2471 | } |
2471 | 2472 | ||
2472 | void KateDocument::doWordUnWrap(KateAction *a) { | 2473 | void KateDocument::doWordUnWrap(KateAction *a) { |
2473 | TextLine::Ptr textLine; | 2474 | TextLine::Ptr textLine; |
2474 | 2475 | ||
2475 | textLine = getTextLine(a->cursor.y - 1); | 2476 | textLine = getTextLine(a->cursor.y - 1); |
2476 | // textLine->setLength(a->len); | 2477 | // textLine->setLength(a->len); |
2477 | textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x); | 2478 | textLine->unWrap(a->len, getTextLine(a->cursor.y),a->cursor.x); |
2478 | 2479 | ||
2479 | buffer->changeLine(a->cursor.y - 1); | 2480 | buffer->changeLine(a->cursor.y - 1); |
2480 | buffer->changeLine(a->cursor.y); | 2481 | buffer->changeLine(a->cursor.y); |
2481 | 2482 | ||
2482 | tagLine(a->cursor.y - 1); | 2483 | tagLine(a->cursor.y - 1); |
2483 | tagLine(a->cursor.y); | 2484 | tagLine(a->cursor.y); |
2484 | 2485 | ||
2485 | a->action = KateAction::wordWrap; | 2486 | a->action = KateAction::wordWrap; |
2486 | } | 2487 | } |
2487 | 2488 | ||
2488 | void KateDocument::doNewLine(KateAction *a) { | 2489 | void KateDocument::doNewLine(KateAction *a) { |
2489 | TextLine::Ptr textLine, newLine; | 2490 | TextLine::Ptr textLine, newLine; |
2490 | 2491 | ||
2491 | textLine = getTextLine(a->cursor.y); | 2492 | textLine = getTextLine(a->cursor.y); |
2492 | newLine = new TextLine(textLine->getRawAttr(), textLine->getContext()); | 2493 | newLine = new TextLine(textLine->getRawAttr(), textLine->getContext()); |
2493 | textLine->wrap(newLine,a->cursor.x); | 2494 | textLine->wrap(newLine,a->cursor.x); |
2494 | 2495 | ||
2495 | buffer->insertLine(a->cursor.y + 1, newLine); | 2496 | buffer->insertLine(a->cursor.y + 1, newLine); |
2496 | buffer->changeLine(a->cursor.y); | 2497 | buffer->changeLine(a->cursor.y); |
2497 | 2498 | ||
2498 | insLine(a->cursor.y + 1); | 2499 | insLine(a->cursor.y + 1); |
2499 | tagLine(a->cursor.y); | 2500 | tagLine(a->cursor.y); |
2500 | tagLine(a->cursor.y + 1); | 2501 | tagLine(a->cursor.y + 1); |
2501 | if (selectEnd == a->cursor.y) selectEnd++;//addSelection(a->cursor.y + 1); | 2502 | if (selectEnd == a->cursor.y) selectEnd++;//addSelection(a->cursor.y + 1); |
2502 | 2503 | ||
2503 | a->action = KateAction::delLine; | 2504 | a->action = KateAction::delLine; |
2504 | } | 2505 | } |
2505 | 2506 | ||
2506 | void KateDocument::doDelLine(KateAction *a) { | 2507 | void KateDocument::doDelLine(KateAction *a) { |
2507 | TextLine::Ptr textLine, nextLine; | 2508 | TextLine::Ptr textLine, nextLine; |
2508 | 2509 | ||
2509 | textLine = getTextLine(a->cursor.y); | 2510 | textLine = getTextLine(a->cursor.y); |
2510 | nextLine = getTextLine(a->cursor.y+1); | 2511 | nextLine = getTextLine(a->cursor.y+1); |
2511 | // textLine->setLength(a->cursor.x); | 2512 | // textLine->setLength(a->cursor.x); |
2512 | textLine->unWrap(a->cursor.x, nextLine,nextLine->length()); | 2513 | textLine->unWrap(a->cursor.x, nextLine,nextLine->length()); |
2513 | textLine->setContext(nextLine->getContext()); | 2514 | textLine->setContext(nextLine->getContext()); |
2514 | if (longestLine == nextLine) longestLine = 0L; | 2515 | if (longestLine == nextLine) longestLine = 0L; |
2515 | 2516 | ||
2516 | buffer->changeLine(a->cursor.y); | 2517 | buffer->changeLine(a->cursor.y); |
2517 | buffer->removeLine(a->cursor.y+1); | 2518 | buffer->removeLine(a->cursor.y+1); |
2518 | 2519 | ||
2519 | tagLine(a->cursor.y); | 2520 | tagLine(a->cursor.y); |
2520 | delLine(a->cursor.y + 1); | 2521 | delLine(a->cursor.y + 1); |
2521 | 2522 | ||
2522 | a->action = KateAction::newLine; | 2523 | a->action = KateAction::newLine; |
2523 | } | 2524 | } |
2524 | 2525 | ||
2525 | void KateDocument::doInsLine(KateAction *a) { | 2526 | void KateDocument::doInsLine(KateAction *a) { |
2526 | 2527 | ||
2527 | buffer->insertLine(a->cursor.y, new TextLine()); | 2528 | buffer->insertLine(a->cursor.y, new TextLine()); |
2528 | 2529 | ||
2529 | insLine(a->cursor.y); | 2530 | insLine(a->cursor.y); |
2530 | 2531 | ||
2531 | a->action = KateAction::killLine; | 2532 | a->action = KateAction::killLine; |
2532 | } | 2533 | } |
2533 | 2534 | ||
2534 | void KateDocument::doKillLine(KateAction *a) { | 2535 | void KateDocument::doKillLine(KateAction *a) { |
2535 | TextLine::Ptr textLine = getTextLine(a->cursor.y); | 2536 | TextLine::Ptr textLine = getTextLine(a->cursor.y); |
2536 | if (longestLine == textLine) longestLine = 0L; | 2537 | if (longestLine == textLine) longestLine = 0L; |
2537 | 2538 | ||
2538 | buffer->removeLine(a->cursor.y); | 2539 | buffer->removeLine(a->cursor.y); |
2539 | 2540 | ||
2540 | delLine(a->cursor.y); | 2541 | delLine(a->cursor.y); |
2541 | tagLine(a->cursor.y); | 2542 | tagLine(a->cursor.y); |
2542 | 2543 | ||
2543 | a->action = KateAction::insLine; | 2544 | a->action = KateAction::insLine; |
2544 | } | 2545 | } |
2545 | 2546 | ||
2546 | void KateDocument::newUndo() { | 2547 | void KateDocument::newUndo() { |
2547 | KTextEditor::View *view; | 2548 | KTextEditor::View *view; |
2548 | int state; | 2549 | int state; |
2549 | 2550 | ||
2550 | state = 0; | 2551 | state = 0; |
2551 | if (currentUndo > 0) state |= 1; | 2552 | if (currentUndo > 0) state |= 1; |
2552 | if (currentUndo < (int) undoList.count()) state |= 2; | 2553 | if (currentUndo < (int) undoList.count()) state |= 2; |
2553 | undoState = state; | 2554 | undoState = state; |
2554 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { | 2555 | for (view = m_views.first(); view != 0L; view = m_views.next() ) { |
2555 | emit static_cast<KateView *>( view )->newUndo(); | 2556 | emit static_cast<KateView *>( view )->newUndo(); |
2556 | } | 2557 | } |
2557 | } | 2558 | } |
2558 | 2559 | ||
2559 | void KateDocument::recordStart(VConfig &c, int newUndoType) { | 2560 | void KateDocument::recordStart(VConfig &c, int newUndoType) { |
2560 | recordStart(c.view, c.cursor, c.flags, newUndoType); | 2561 | recordStart(c.view, c.cursor, c.flags, newUndoType); |
2561 | } | 2562 | } |
2562 | 2563 | ||
2563 | void KateDocument::recordStart(KateView *, PointStruc &cursor, int flags, | 2564 | void KateDocument::recordStart(KateView *, PointStruc &cursor, int flags, |
2564 | int newUndoType, bool keepModal, bool mergeUndo) { | 2565 | int newUndoType, bool keepModal, bool mergeUndo) { |
2565 | 2566 | ||
2566 | KateActionGroup *g; | 2567 | KateActionGroup *g; |
2567 | 2568 | ||
2568 | // if (newUndoType == KateActionGroup::ugNone) { | 2569 | // if (newUndoType == KateActionGroup::ugNone) { |
2569 | // only a bug would cause this | 2570 | // only a bug would cause this |
2570 | //why should someone do this? we can't prevent all programming errors :) (jochen whilhelmy) | 2571 | //why should someone do this? we can't prevent all programming errors :) (jochen whilhelmy) |
2571 | // debug("KateDocument::recordStart() called with no undo group type!"); | 2572 | // debug("KateDocument::recordStart() called with no undo group type!"); |
2572 | // return; | 2573 | // return; |
2573 | // } | 2574 | // } |
2574 | 2575 | ||
2575 | if (!keepModal) setPseudoModal(0L); | 2576 | if (!keepModal) setPseudoModal(0L); |
2576 | 2577 | ||
2577 | //i optimized the group undo stuff a bit (jochen wilhelmy) | 2578 | //i optimized the group undo stuff a bit (jochen wilhelmy) |
2578 | // recordReset() is not needed any more | 2579 | // recordReset() is not needed any more |
2579 | g = undoList.getLast(); | 2580 | g = undoList.getLast(); |
2580 | if (g != 0L && ((undoCount < 1024 && flags & KateView::cfGroupUndo | 2581 | if (g != 0L && ((undoCount < 1024 && flags & KateView::cfGroupUndo |
2581 | && g->end.x == cursor.x && g->end.y == cursor.y) || mergeUndo)) { | 2582 | && g->end.x == cursor.x && g->end.y == cursor.y) || mergeUndo)) { |
2582 | 2583 | ||
2583 | //undo grouping : same actions are put into one undo step | 2584 | //undo grouping : same actions are put into one undo step |
2584 | //precondition : new action starts where old stops or mergeUndo flag | 2585 | //precondition : new action starts where old stops or mergeUndo flag |
2585 | if (g->undoType == newUndoType | 2586 | if (g->undoType == newUndoType |
2586 | || (g->undoType == KateActionGroup::ugInsChar | 2587 | || (g->undoType == KateActionGroup::ugInsChar |
2587 | && newUndoType == KateActionGroup::ugInsLine) | 2588 | && newUndoType == KateActionGroup::ugInsLine) |
2588 | || (g->undoType == KateActionGroup::ugDelChar | 2589 | || (g->undoType == KateActionGroup::ugDelChar |
2589 | && newUndoType == KateActionGroup::ugDelLine)) { | 2590 | && newUndoType == KateActionGroup::ugDelLine)) { |
2590 | 2591 | ||
2591 | undoCount++; | 2592 | undoCount++; |
2592 | if (g->undoType != newUndoType) undoCount = 0xffffff; | 2593 | if (g->undoType != newUndoType) undoCount = 0xffffff; |
2593 | return; | 2594 | return; |
2594 | } | 2595 | } |
2595 | } | 2596 | } |
2596 | undoCount = 0; | 2597 | undoCount = 0; |
2597 | /* | 2598 | /* |
2598 | if (undoView != view) { | 2599 | if (undoView != view) { |
2599 | // always kill the current undo group if the editing view changes | 2600 | // always kill the current undo group if the editing view changes |
2600 | recordReset(); | 2601 | recordReset(); |
2601 | undoType = newUndoType; | 2602 | undoType = newUndoType; |
2602 | } else if (newUndoType == undoType) { | 2603 | } else if (newUndoType == undoType) { |
2603 | printf("bla!!!\n"); | 2604 | printf("bla!!!\n"); |
2604 | // same as current type, keep using it | 2605 | // same as current type, keep using it |
2605 | return; | 2606 | return; |
2606 | } else if ( (undoType == KateActionGroup::ugInsChar && newUndoType == KateActionGroup::ugInsLine) || | 2607 | } else if ( (undoType == KateActionGroup::ugInsChar && newUndoType == KateActionGroup::ugInsLine) || |
2607 | (undoType == KateActionGroup::ugDelChar && newUndoType == KateActionGroup::ugDelLine) ) { | 2608 | (undoType == KateActionGroup::ugDelChar && newUndoType == KateActionGroup::ugDelLine) ) { |
2608 | // some type combinations can run together... | 2609 | // some type combinations can run together... |
2609 | undoType += 1000; | 2610 | undoType += 1000; |
2610 | return; | 2611 | return; |
2611 | } else { | 2612 | } else { |
2612 | recordReset(); | 2613 | recordReset(); |
2613 | undoType = newUndoType; | 2614 | undoType = newUndoType; |
2614 | } | 2615 | } |
2615 | 2616 | ||
2616 | undoView = view; | 2617 | undoView = view; |
2617 | */ | 2618 | */ |
2618 | while ((int) undoList.count() > currentUndo) undoList.removeLast(); | 2619 | while ((int) undoList.count() > currentUndo) undoList.removeLast(); |
2619 | while ((int) undoList.count() > undoSteps) { | 2620 | while ((int) undoList.count() > undoSteps) { |
2620 | undoList.removeFirst(); | 2621 | undoList.removeFirst(); |
2621 | currentUndo--; | 2622 | currentUndo--; |
2622 | } | 2623 | } |
2623 | 2624 | ||
2624 | g = new KateActionGroup(cursor, newUndoType); | 2625 | g = new KateActionGroup(cursor, newUndoType); |
2625 | undoList.append(g); | 2626 | undoList.append(g); |
2626 | // currentUndo++; | 2627 | // currentUndo++; |
2627 | 2628 | ||
2628 | tagEnd = 0; | 2629 | tagEnd = 0; |
2629 | tagStart = 0xffffff; | 2630 | tagStart = 0xffffff; |
2630 | } | 2631 | } |
2631 | 2632 | ||
2632 | void KateDocument::recordAction(KateAction::Action action, PointStruc &cursor) { | 2633 | void KateDocument::recordAction(KateAction::Action action, PointStruc &cursor) { |
2633 | KateAction *a; | 2634 | KateAction *a; |
2634 | 2635 | ||
2635 | a = new KateAction(action, cursor); | 2636 | a = new KateAction(action, cursor); |
2636 | doAction(a); | 2637 | doAction(a); |
2637 | undoList.getLast()->insertAction(a); | 2638 | undoList.getLast()->insertAction(a); |
2638 | } | 2639 | } |
2639 | 2640 | ||
2640 | void KateDocument::recordInsert(VConfig &c, const QString &text) { | 2641 | void KateDocument::recordInsert(VConfig &c, const QString &text) { |
2641 | recordReplace(c, 0, text); | 2642 | recordReplace(c, 0, text); |
2642 | } | 2643 | } |
2643 | 2644 | ||
2644 | void KateDocument::recordReplace(VConfig &c, int len, const QString &text) { | 2645 | void KateDocument::recordReplace(VConfig &c, int len, const QString &text) { |
2645 | if (c.cursor.x > 0 && !(c.flags & KateView::cfSpaceIndent)) { | 2646 | if (c.cursor.x > 0 && !(c.flags & KateView::cfSpaceIndent)) { |
2646 | TextLine::Ptr textLine = getTextLine(c.cursor.y); | 2647 | TextLine::Ptr textLine = getTextLine(c.cursor.y); |
2647 | if (textLine->length() == 0) { | 2648 | if (textLine->length() == 0) { |
2648 | QString s = tabString(c.cursor.x, tabChars); | 2649 | QString s = tabString(c.cursor.x, tabChars); |
2649 | int len = s.length(); | 2650 | int len = s.length(); |
2650 | s += text; | 2651 | s += text; |
2651 | c.cursor.x = 0; | 2652 | c.cursor.x = 0; |
2652 | recordReplace(c.cursor, len, s); | 2653 | recordReplace(c.cursor, len, s); |
2653 | c.cursor.x = len; | 2654 | c.cursor.x = len; |
2654 | return; | 2655 | return; |
2655 | } | 2656 | } |
2656 | } | 2657 | } |
2657 | recordReplace(c.cursor, len, text); | 2658 | recordReplace(c.cursor, len, text); |
2658 | } | 2659 | } |
2659 | 2660 | ||
2660 | void KateDocument::recordInsert(PointStruc &cursor, const QString &text) { | 2661 | void KateDocument::recordInsert(PointStruc &cursor, const QString &text) { |
2661 | recordReplace(cursor, 0, text); | 2662 | recordReplace(cursor, 0, text); |
2662 | } | 2663 | } |
2663 | 2664 | ||
2664 | void KateDocument::recordDelete(PointStruc &cursor, int len) { | 2665 | void KateDocument::recordDelete(PointStruc &cursor, int len) { |
2665 | recordReplace(cursor, len, QString::null); | 2666 | recordReplace(cursor, len, QString::null); |
2666 | } | 2667 | } |
2667 | 2668 | ||
2668 | void KateDocument::recordReplace(PointStruc &cursor, int len, const QString &text) { | 2669 | void KateDocument::recordReplace(PointStruc &cursor, int len, const QString &text) { |
2669 | KateAction *a; | 2670 | KateAction *a; |
2670 | TextLine::Ptr textLine; | 2671 | TextLine::Ptr textLine; |
2671 | int l; | 2672 | int l; |
2672 | 2673 | ||
2673 | if (len == 0 && text.isEmpty()) return; | 2674 | if (len == 0 && text.isEmpty()) return; |
2674 | 2675 | ||
2675 | //try to append to last replace action | 2676 | //try to append to last replace action |
diff --git a/noncore/settings/sysinfo/devicesinfo.cpp b/noncore/settings/sysinfo/devicesinfo.cpp index 164d608..428cfd4 100644 --- a/noncore/settings/sysinfo/devicesinfo.cpp +++ b/noncore/settings/sysinfo/devicesinfo.cpp | |||
@@ -1,433 +1,433 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | =. Copyright (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> | 3 | =. Copyright (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> |
4 | .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .>+-= | 5 | .>+-= |
6 | _;:, .> :=|. This program is free software; you can | 6 | _;:, .> :=|. This program is free software; you can |
7 | .> <`_, > . <= redistribute it and/or modify it under | 7 | .> <`_, > . <= redistribute it and/or modify it under |
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; version 2 of the License. | 10 | - . .-<_> .<> Foundation; version 2 of the License. |
11 | ._= =} : | 11 | ._= =} : |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This program is distributed in the hope that | 13 | .i_,=:_. -<s. This program is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
18 | ..}^=.= = ; General Public License for more | 18 | ..}^=.= = ; General Public License for more |
19 | ++= -. .` .: details. | 19 | ++= -. .` .: details. |
20 | : = ...= . :.=- | 20 | : = ...= . :.=- |
21 | -. .:....=;==+<; You should have received a copy of the GNU | 21 | -. .:....=;==+<; You should have received a copy of the GNU |
22 | -_. . . )=. = General Public License along with | 22 | -_. . . )=. = General Public License along with |
23 | -- :-=` this application; see the file LICENSE.GPL. | 23 | -- :-=` this application; see the file LICENSE.GPL. |
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "devicesinfo.h" | 29 | #include "devicesinfo.h" |
30 | /* OPIE */ | 30 | /* OPIE */ |
31 | #include <opie2/odebug.h> | 31 | #include <opie2/odebug.h> |
32 | #include <opie2/oinputsystem.h> | 32 | #include <opie2/oinputsystem.h> |
33 | #include <opie2/opcmciasystem.h> | 33 | #include <opie2/opcmciasystem.h> |
34 | #include <opie2/olayout.h> | 34 | #include <opie2/olayout.h> |
35 | #include <opie2/olistview.h> | 35 | #include <opie2/olistview.h> |
36 | #include <qpe/qpeapplication.h> | 36 | #include <qpe/qpeapplication.h> |
37 | using namespace Opie::Core; | 37 | using namespace Opie::Core; |
38 | using namespace Opie::Ui; | 38 | using namespace Opie::Ui; |
39 | 39 | ||
40 | /* QT */ | 40 | /* QT */ |
41 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
42 | #include <qlistview.h> | 42 | #include <qlistview.h> |
43 | #include <qcombobox.h> | 43 | #include <qcombobox.h> |
44 | #include <qfile.h> | 44 | #include <qfile.h> |
45 | #include <qpushbutton.h> | 45 | #include <qpushbutton.h> |
46 | #include <qstringlist.h> | 46 | #include <qstringlist.h> |
47 | #include <qtextstream.h> | 47 | #include <qtextstream.h> |
48 | #include <qtextview.h> | 48 | #include <qtextview.h> |
49 | #include <qtimer.h> | 49 | #include <qtimer.h> |
50 | #include <qwhatsthis.h> | 50 | #include <qwhatsthis.h> |
51 | 51 | ||
52 | //================================================================================================= | 52 | //================================================================================================= |
53 | DevicesView::DevicesView( QWidget* parent, const char* name, WFlags fl ) | 53 | DevicesView::DevicesView( QWidget* parent, const char* name, WFlags fl ) |
54 | :Opie::Ui::OListView( parent, name, fl ) | 54 | :Opie::Ui::OListView( parent, name, fl ) |
55 | { | 55 | { |
56 | addColumn( tr( "My Computer" ) ); | 56 | addColumn( tr( "My Computer" ) ); |
57 | setAllColumnsShowFocus( true ); | 57 | setAllColumnsShowFocus( true ); |
58 | setRootIsDecorated( true ); | 58 | setRootIsDecorated( true ); |
59 | QWhatsThis::add( this, tr( "This is a list of all the devices currently recognized on this device." ) ); | 59 | QWhatsThis::add( this, tr( "This is a list of all the devices currently recognized on this device." ) ); |
60 | 60 | ||
61 | DevicesView* root = this; | 61 | DevicesView* root = this; |
62 | ( new CpuCategory( root ) )->populate(); | 62 | ( new CpuCategory( root ) )->populate(); |
63 | ( new InputCategory( root ) )->populate(); | 63 | ( new InputCategory( root ) )->populate(); |
64 | ( new CardsCategory( root ) )->populate(); | 64 | ( new CardsCategory( root ) )->populate(); |
65 | ( new UsbCategory( root ) )->populate(); | 65 | ( new UsbCategory( root ) )->populate(); |
66 | 66 | ||
67 | connect( this, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(selectionChanged(QListViewItem*)) ); | 67 | connect( this, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(selectionChanged(QListViewItem*)) ); |
68 | } | 68 | } |
69 | 69 | ||
70 | DevicesView::~DevicesView() | 70 | DevicesView::~DevicesView() |
71 | { | 71 | { |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
75 | void DevicesView::selectionChanged( QListViewItem* item ) | 75 | void DevicesView::selectionChanged( QListViewItem* item ) |
76 | { | 76 | { |
77 | odebug << "DevicesView::selectionChanged to '" << item->text( 0 ) << "'" << oendl; | 77 | odebug << "DevicesView::selectionChanged to '" << item->text( 0 ) << "'" << oendl; |
78 | if ( item->parent() ) | 78 | if ( item->parent() ) |
79 | { | 79 | { |
80 | QWidget* details = ( static_cast<Device*>( item ) )->detailsWidget(); | 80 | QWidget* details = ( static_cast<Device*>( item ) )->detailsWidget(); |
81 | ( static_cast<DevicesInfo*>( parent() ) )->setDetailsWidget( details ); | 81 | ( static_cast<DevicesInfo*>( parent() ) )->setDetailsWidget( details ); |
82 | } | 82 | } |
83 | else | 83 | else |
84 | { | 84 | { |
85 | odebug << "DevicesView::not a device node." << oendl; | 85 | odebug << "DevicesView::not a device node." << oendl; |
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | 89 | ||
90 | //================================================================================================= | 90 | //================================================================================================= |
91 | DevicesInfo::DevicesInfo( QWidget* parent, const char* name, WFlags fl ) | 91 | DevicesInfo::DevicesInfo( QWidget* parent, const char* name, WFlags fl ) |
92 | :QWidget( parent, name, fl ), details( 0 ) | 92 | :QWidget( parent, name, fl ), details( 0 ) |
93 | { | 93 | { |
94 | layout = new OAutoBoxLayout( this ); | 94 | layout = new OAutoBoxLayout( this ); |
95 | layout->setSpacing( 2 ); | 95 | layout->setSpacing( 2 ); |
96 | layout->setMargin( 2 ); | 96 | layout->setMargin( 2 ); |
97 | view = new DevicesView( this ); | 97 | view = new DevicesView( this ); |
98 | layout->addWidget( view, 100 ); | 98 | layout->addWidget( view, 100 ); |
99 | stack = new QWidgetStack( this ); | 99 | stack = new QWidgetStack( this ); |
100 | layout->addWidget( stack, 80 ); | 100 | layout->addWidget( stack, 80 ); |
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ||
104 | DevicesInfo::~DevicesInfo() | 104 | DevicesInfo::~DevicesInfo() |
105 | { | 105 | { |
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
109 | void DevicesInfo::setDetailsWidget( QWidget* w ) | 109 | void DevicesInfo::setDetailsWidget( QWidget* w ) |
110 | { | 110 | { |
111 | if ( details ) | 111 | if ( details ) |
112 | { | 112 | { |
113 | qDebug( "hiding widget '%s' ('%s')", details->name(), details->className() ); | 113 | qDebug( "hiding widget '%s' ('%s')", details->name(), details->className() ); |
114 | stack->removeWidget( w ); | 114 | stack->removeWidget( w ); |
115 | } | 115 | } |
116 | 116 | ||
117 | stack->addWidget( details = w, 40 ); | 117 | stack->addWidget( details = w, 40 ); |
118 | stack->raiseWidget( details ); | 118 | stack->raiseWidget( details ); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | //================================================================================================= | 122 | //================================================================================================= |
123 | Category::Category( DevicesView* parent, const QString& name ) | 123 | Category::Category( DevicesView* parent, const QString& name ) |
124 | :OListViewItem( parent, name ) | 124 | :OListViewItem( parent, name ) |
125 | { | 125 | { |
126 | odebug << "Category '" << name << "' inserted. Scanning for devices..." << oendl; | 126 | odebug << "Category '" << name << "' inserted. Scanning for devices..." << oendl; |
127 | } | 127 | } |
128 | 128 | ||
129 | Category::~Category() | 129 | Category::~Category() |
130 | { | 130 | { |
131 | } | 131 | } |
132 | 132 | ||
133 | //================================================================================================= | 133 | //================================================================================================= |
134 | CpuCategory::CpuCategory( DevicesView* parent ) | 134 | CpuCategory::CpuCategory( DevicesView* parent ) |
135 | :Category( parent, "1. Central Processing Unit" ) | 135 | :Category( parent, "1. Central Processing Unit" ) |
136 | { | 136 | { |
137 | } | 137 | } |
138 | 138 | ||
139 | CpuCategory::~CpuCategory() | 139 | CpuCategory::~CpuCategory() |
140 | { | 140 | { |
141 | } | 141 | } |
142 | 142 | ||
143 | void CpuCategory::populate() | 143 | void CpuCategory::populate() |
144 | { | 144 | { |
145 | odebug << "CpuCategory::populate()" << oendl; | 145 | odebug << "CpuCategory::populate()" << oendl; |
146 | QFile cpuinfofile( "/proc/cpuinfo" ); | 146 | QFile cpuinfofile( "/proc/cpuinfo" ); |
147 | if ( !cpuinfofile.exists() || !cpuinfofile.open( IO_ReadOnly ) ) | 147 | if ( !cpuinfofile.exists() || !cpuinfofile.open( IO_ReadOnly ) ) |
148 | { | 148 | { |
149 | new CpuDevice( this, "(no cpu found)" ); | 149 | new CpuDevice( this, "(no cpu found)" ); |
150 | return; | 150 | return; |
151 | } | 151 | } |
152 | QTextStream cpuinfo( &cpuinfofile ); | 152 | QTextStream cpuinfo( &cpuinfofile ); |
153 | 153 | ||
154 | int cpucount = 0; | 154 | int cpucount = 0; |
155 | CpuDevice* dev = 0; | 155 | CpuDevice* dev = 0; |
156 | 156 | ||
157 | while ( !cpuinfo.atEnd() ) | 157 | while ( !cpuinfo.atEnd() ) |
158 | { | 158 | { |
159 | QString line = cpuinfo.readLine(); | 159 | QString line = cpuinfo.readLine(); |
160 | odebug << "got line '" << line << "'" << oendl; | 160 | odebug << "got line '" << line << "'" << oendl; |
161 | if ( line.lower().startsWith( "processor" ) ) | 161 | if ( line.lower().startsWith( "processor" ) ) |
162 | { | 162 | { |
163 | dev = new CpuDevice( this, QString( "CPU #%1" ).arg( cpucount++ ) ); | 163 | dev = new CpuDevice( this, QString( "CPU #%1" ).arg( cpucount++ ) ); |
164 | dev->addInfo( line ); | 164 | dev->addInfo( line ); |
165 | } | 165 | } |
166 | else | 166 | else |
167 | { | 167 | { |
168 | if ( dev ) dev->addInfo( line ); | 168 | if ( dev ) dev->addInfo( line ); |
169 | } | 169 | } |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | //================================================================================================= | 173 | //================================================================================================= |
174 | InputCategory::InputCategory( DevicesView* parent ) | 174 | InputCategory::InputCategory( DevicesView* parent ) |
175 | :Category( parent, "2. Input Subsystem" ) | 175 | :Category( parent, "2. Input Subsystem" ) |
176 | { | 176 | { |
177 | } | 177 | } |
178 | 178 | ||
179 | InputCategory::~InputCategory() | 179 | InputCategory::~InputCategory() |
180 | { | 180 | { |
181 | } | 181 | } |
182 | 182 | ||
183 | void InputCategory::populate() | 183 | void InputCategory::populate() |
184 | { | 184 | { |
185 | odebug << "InputCategory::populate()" << oendl; | 185 | odebug << "InputCategory::populate()" << oendl; |
186 | OInputSystem* sys = OInputSystem::instance(); | 186 | OInputSystem* sys = OInputSystem::instance(); |
187 | OInputSystem::DeviceIterator it = sys->iterator(); | 187 | OInputSystem::DeviceIterator it = sys->iterator(); |
188 | while ( it.current() ) | 188 | while ( it.current() ) |
189 | { | 189 | { |
190 | InputDevice* dev = new InputDevice( this, it.current()->identity() ); | 190 | InputDevice* dev = new InputDevice( this, it.current()->identity() ); |
191 | dev->setInfo( it.current() ); | 191 | dev->setInfo( it.current() ); |
192 | ++it; | 192 | ++it; |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | //================================================================================================= | 196 | //================================================================================================= |
197 | CardsCategory::CardsCategory( DevicesView* parent ) | 197 | CardsCategory::CardsCategory( DevicesView* parent ) |
198 | :Category( parent, "3. Removable Cards" ) | 198 | :Category( parent, "3. Removable Cards" ) |
199 | { | 199 | { |
200 | } | 200 | } |
201 | 201 | ||
202 | CardsCategory::~CardsCategory() | 202 | CardsCategory::~CardsCategory() |
203 | { | 203 | { |
204 | } | 204 | } |
205 | 205 | ||
206 | void CardsCategory::populate() | 206 | void CardsCategory::populate() |
207 | { | 207 | { |
208 | odebug << "CardsCategory::populate()" << oendl; | 208 | odebug << "CardsCategory::populate()" << oendl; |
209 | OPcmciaSystem* sys = OPcmciaSystem::instance(); | 209 | OPcmciaSystem* sys = OPcmciaSystem::instance(); |
210 | OPcmciaSystem::CardIterator it = sys->iterator(); | 210 | OPcmciaSystem::CardIterator it = sys->iterator(); |
211 | while ( it.current() ) | 211 | while ( it.current() ) |
212 | { | 212 | { |
213 | CardDevice *dev = new CardDevice( this, it.current()->identity() ); | 213 | CardDevice *dev = new CardDevice( this, it.current()->identity() ); |
214 | dev->setInfo( it.current() ); | 214 | dev->setInfo( it.current() ); |
215 | ++it; | 215 | ++it; |
216 | } | 216 | } |
217 | } | 217 | } |
218 | 218 | ||
219 | //================================================================================================= | 219 | //================================================================================================= |
220 | UsbCategory::UsbCategory( DevicesView* parent ) | 220 | UsbCategory::UsbCategory( DevicesView* parent ) |
221 | :Category( parent, "4. Universal Serial Bus" ) | 221 | :Category( parent, "4. Universal Serial Bus" ) |
222 | { | 222 | { |
223 | } | 223 | } |
224 | 224 | ||
225 | UsbCategory::~UsbCategory() | 225 | UsbCategory::~UsbCategory() |
226 | { | 226 | { |
227 | } | 227 | } |
228 | 228 | ||
229 | void UsbCategory::populate() | 229 | void UsbCategory::populate() |
230 | { | 230 | { |
231 | odebug << "UsbCategory::populate()" << oendl; | 231 | odebug << "UsbCategory::populate()" << oendl; |
232 | QFile usbinfofile( "/proc/bus/usb/devices" ); | 232 | QFile usbinfofile( "/proc/bus/usb/devices" ); |
233 | if ( !usbinfofile.exists() || !usbinfofile.open( IO_ReadOnly ) ) | 233 | if ( !usbinfofile.exists() || !usbinfofile.open( IO_ReadOnly ) ) |
234 | { | 234 | { |
235 | new UsbDevice( this, "(no USB found)" ); | 235 | new UsbDevice( this, "(no USB found)" ); |
236 | return; | 236 | return; |
237 | } | 237 | } |
238 | QTextStream usbinfo( &usbinfofile ); | 238 | QTextStream usbinfo( &usbinfofile ); |
239 | 239 | ||
240 | int _bus, _level, _parent, _port, _count, _device, _channels, _power; | 240 | int _bus, _level, _parent, _port, _count, _device, _channels, _power; |
241 | float _speed; | 241 | float _speed; |
242 | QString _manufacturer, _product, _serial; | 242 | QString _manufacturer, _product, _serial; |
243 | 243 | ||
244 | int usbcount = 0; | 244 | int usbcount = 0; |
245 | UsbDevice* lastDev = 0; | 245 | UsbDevice* lastDev = 0; |
246 | UsbDevice* dev = 0; | 246 | UsbDevice* dev = 0; |
247 | while ( !usbinfo.atEnd() ) | 247 | while ( !usbinfo.atEnd() ) |
248 | { | 248 | { |
249 | QString line = usbinfo.readLine(); | 249 | QString line = usbinfo.readLine(); |
250 | odebug << "got line '" << line << "'" << oendl; | 250 | odebug << "got line '" << line << "'" << oendl; |
251 | if ( line.startsWith( "T:" ) ) | 251 | if ( line.startsWith( "T:" ) ) |
252 | { | 252 | { |
253 | sscanf(line.local8Bit().data(), "T: Bus=%2d Lev=%2d Prnt=%2d Port=%d Cnt=%2d Dev#=%3d Spd=%3f MxCh=%2d", &_bus, &_level, &_parent, &_port, &_count, &_device, &_speed, &_channels); | 253 | sscanf(line.local8Bit().data(), "T: Bus=%2d Lev=%2d Prnt=%2d Port=%d Cnt=%2d Dev#=%3d Spd=%3f MxCh=%2d", &_bus, &_level, &_parent, &_port, &_count, &_device, &_speed, &_channels); |
254 | 254 | ||
255 | if ( !_level ) | 255 | if ( !_level ) |
256 | { | 256 | { |
257 | odebug << "adding new bus" << oendl; | 257 | odebug << "adding new bus" << oendl; |
258 | dev = new UsbDevice( this, QString( "Generic USB Hub Device" ) ); | 258 | dev = new UsbDevice( this, QString( "Generic USB Hub Device" ) ); |
259 | lastDev = dev; | 259 | lastDev = dev; |
260 | } | 260 | } |
261 | else | 261 | else |
262 | { | 262 | { |
263 | odebug << "adding new dev" << oendl; | 263 | odebug << "adding new dev" << oendl; |
264 | dev = new UsbDevice( lastDev, QString( "Generic USB Hub Device" ) ); | 264 | dev = new UsbDevice( lastDev, QString( "Generic USB Hub Device" ) ); |
265 | lastDev = dev; | 265 | lastDev = dev; |
266 | } | 266 | } |
267 | } | 267 | } |
268 | else if ( line.startsWith( "S: Product" ) ) | 268 | else if ( dev && line.startsWith( "S: Product" ) ) |
269 | { | 269 | { |
270 | int dp = line.find( '=' ); | 270 | int dp = line.find( '=' ); |
271 | dev->setText( 0, dp != -1 ? line.right( line.length()-1-dp ) : "<unknown>" ); | 271 | dev->setText( 0, dp != -1 ? line.right( line.length()-1-dp ) : "<unknown>" ); |
272 | } | 272 | } |
273 | else | 273 | else |
274 | { | 274 | { |
275 | continue; | 275 | continue; |
276 | } | 276 | } |
277 | } | 277 | } |
278 | } | 278 | } |
279 | 279 | ||
280 | 280 | ||
281 | //================================================================================================= | 281 | //================================================================================================= |
282 | Device::Device( Category* parent, const QString& name ) | 282 | Device::Device( Category* parent, const QString& name ) |
283 | :OListViewItem( parent, name ) | 283 | :OListViewItem( parent, name ) |
284 | { | 284 | { |
285 | devinfo = static_cast<QWidget*>( listView()->parent() ); | 285 | devinfo = static_cast<QWidget*>( listView()->parent() ); |
286 | } | 286 | } |
287 | 287 | ||
288 | Device::Device( Device* parent, const QString& name ) | 288 | Device::Device( Device* parent, const QString& name ) |
289 | :OListViewItem( parent, name ) | 289 | :OListViewItem( parent, name ) |
290 | { | 290 | { |
291 | devinfo = static_cast<QWidget*>( listView()->parent() ); | 291 | devinfo = static_cast<QWidget*>( listView()->parent() ); |
292 | } | 292 | } |
293 | 293 | ||
294 | Device::~Device() | 294 | Device::~Device() |
295 | { | 295 | { |
296 | } | 296 | } |
297 | 297 | ||
298 | 298 | ||
299 | QWidget* Device::detailsWidget() | 299 | QWidget* Device::detailsWidget() |
300 | { | 300 | { |
301 | return details; | 301 | return details; |
302 | } | 302 | } |
303 | 303 | ||
304 | //================================================================================================= | 304 | //================================================================================================= |
305 | CpuDevice::CpuDevice( Category* parent, const QString& name ) | 305 | CpuDevice::CpuDevice( Category* parent, const QString& name ) |
306 | :Device( parent, name ) | 306 | :Device( parent, name ) |
307 | { | 307 | { |
308 | OListView* w = new OListView( devinfo ); | 308 | OListView* w = new OListView( devinfo ); |
309 | details = w; | 309 | details = w; |
310 | w->addColumn( "Info" ); | 310 | w->addColumn( "Info" ); |
311 | w->addColumn( "Value" ); | 311 | w->addColumn( "Value" ); |
312 | w->hide(); | 312 | w->hide(); |
313 | } | 313 | } |
314 | 314 | ||
315 | CpuDevice::~CpuDevice() | 315 | CpuDevice::~CpuDevice() |
316 | { | 316 | { |
317 | } | 317 | } |
318 | 318 | ||
319 | void CpuDevice::addInfo( const QString& info ) | 319 | void CpuDevice::addInfo( const QString& info ) |
320 | { | 320 | { |
321 | int dp = info.find( ':' ); | 321 | int dp = info.find( ':' ); |
322 | if ( dp != -1 ) | 322 | if ( dp != -1 ) |
323 | { | 323 | { |
324 | new OListViewItem( (OListView*) details, info.left( dp ), info.right( info.length()-dp ) ); | 324 | new OListViewItem( (OListView*) details, info.left( dp ), info.right( info.length()-dp ) ); |
325 | } | 325 | } |
326 | } | 326 | } |
327 | 327 | ||
328 | //================================================================================================= | 328 | //================================================================================================= |
329 | CardDevice::CardDevice( Category* parent, const QString& name ) | 329 | CardDevice::CardDevice( Category* parent, const QString& name ) |
330 | :Device( parent, name ) | 330 | :Device( parent, name ) |
331 | { | 331 | { |
332 | OListView* w = new OListView( devinfo ); | 332 | OListView* w = new OListView( devinfo ); |
333 | details = w; | 333 | details = w; |
334 | w->addColumn( "Info" ); | 334 | w->addColumn( "Info" ); |
335 | w->addColumn( "Value" ); | 335 | w->addColumn( "Value" ); |
336 | w->hide(); | 336 | w->hide(); |
337 | } | 337 | } |
338 | 338 | ||
339 | void CardDevice::setInfo( const OPcmciaSocket* card ) | 339 | void CardDevice::setInfo( const OPcmciaSocket* card ) |
340 | { | 340 | { |
341 | QStringList vendorlst = card->productIdentityVector(); | 341 | QStringList vendorlst = card->productIdentityVector(); |
342 | for( QStringList::Iterator it = vendorlst.begin(); it != vendorlst.end(); ++it ) | 342 | for( QStringList::Iterator it = vendorlst.begin(); it != vendorlst.end(); ++it ) |
343 | { | 343 | { |
344 | new OListViewItem( (OListView*) details, "VendorID", *it ); | 344 | new OListViewItem( (OListView*) details, "VendorID", *it ); |
345 | } | 345 | } |
346 | new OListViewItem( (OListView*) details, "Manufacturer", card->manufacturerIdentity() ); | 346 | new OListViewItem( (OListView*) details, "Manufacturer", card->manufacturerIdentity() ); |
347 | new OListViewItem( (OListView*) details, "Function", card->function() ); | 347 | new OListViewItem( (OListView*) details, "Function", card->function() ); |
348 | 348 | ||
349 | QStringList text; | 349 | QStringList text; |
350 | OPcmciaSocket::OPcmciaSocketCardStatus status = card->status(); | 350 | OPcmciaSocket::OPcmciaSocketCardStatus status = card->status(); |
351 | if ( status ) | 351 | if ( status ) |
352 | { | 352 | { |
353 | if ( status & OPcmciaSocket::Occupied ) text += "Occupied"; | 353 | if ( status & OPcmciaSocket::Occupied ) text += "Occupied"; |
354 | if ( status & OPcmciaSocket::OccupiedCardBus ) text += "CardBus"; | 354 | if ( status & OPcmciaSocket::OccupiedCardBus ) text += "CardBus"; |
355 | if ( status & OPcmciaSocket::WriteProtected ) text += "WriteProtected"; | 355 | if ( status & OPcmciaSocket::WriteProtected ) text += "WriteProtected"; |
356 | if ( status & OPcmciaSocket::BatteryLow ) text += "BatteryLow"; | 356 | if ( status & OPcmciaSocket::BatteryLow ) text += "BatteryLow"; |
357 | if ( status & OPcmciaSocket::BatteryDead ) text += "BatteryDead"; | 357 | if ( status & OPcmciaSocket::BatteryDead ) text += "BatteryDead"; |
358 | if ( status & OPcmciaSocket::Ready ) text += "Ready"; | 358 | if ( status & OPcmciaSocket::Ready ) text += "Ready"; |
359 | if ( status & OPcmciaSocket::Suspended ) text += "Suspended"; | 359 | if ( status & OPcmciaSocket::Suspended ) text += "Suspended"; |
360 | if ( status & OPcmciaSocket::Attention ) text += "Attention"; | 360 | if ( status & OPcmciaSocket::Attention ) text += "Attention"; |
361 | if ( status & OPcmciaSocket::InsertionInProgress ) text += "InsertionInProgress"; | 361 | if ( status & OPcmciaSocket::InsertionInProgress ) text += "InsertionInProgress"; |
362 | if ( status & OPcmciaSocket::RemovalInProgress ) text += "RemovalInProgress"; | 362 | if ( status & OPcmciaSocket::RemovalInProgress ) text += "RemovalInProgress"; |
363 | if ( status & OPcmciaSocket::ThreeVolts ) text += "3V"; | 363 | if ( status & OPcmciaSocket::ThreeVolts ) text += "3V"; |
364 | if ( status & OPcmciaSocket::SupportsVoltage ) text += "SupportsVoltage"; | 364 | if ( status & OPcmciaSocket::SupportsVoltage ) text += "SupportsVoltage"; |
365 | } | 365 | } |
366 | else | 366 | else |
367 | { | 367 | { |
368 | text += "<unknown>"; | 368 | text += "<unknown>"; |
369 | } | 369 | } |
370 | new OListViewItem( (OListView*) details, "Status", text.join( ", " ) ); | 370 | new OListViewItem( (OListView*) details, "Status", text.join( ", " ) ); |
371 | } | 371 | } |
372 | 372 | ||
373 | CardDevice::~CardDevice() | 373 | CardDevice::~CardDevice() |
374 | { | 374 | { |
375 | } | 375 | } |
376 | 376 | ||
377 | //================================================================================================= | 377 | //================================================================================================= |
378 | InputDevice::InputDevice( Category* parent, const QString& name ) | 378 | InputDevice::InputDevice( Category* parent, const QString& name ) |
379 | :Device( parent, name ) | 379 | :Device( parent, name ) |
380 | { | 380 | { |
381 | OListView* w = new OListView( devinfo ); | 381 | OListView* w = new OListView( devinfo ); |
382 | details = w; | 382 | details = w; |
383 | w->addColumn( "Info" ); | 383 | w->addColumn( "Info" ); |
384 | w->addColumn( "Value" ); | 384 | w->addColumn( "Value" ); |
385 | w->hide(); | 385 | w->hide(); |
386 | } | 386 | } |
387 | 387 | ||
388 | void InputDevice::setInfo( const OInputDevice* dev ) | 388 | void InputDevice::setInfo( const OInputDevice* dev ) |
389 | { | 389 | { |
390 | new OListViewItem( (OListView*) details, "Identity", dev->identity() ); | 390 | new OListViewItem( (OListView*) details, "Identity", dev->identity() ); |
391 | new OListViewItem( (OListView*) details, "Path", dev->path() ); | 391 | new OListViewItem( (OListView*) details, "Path", dev->path() ); |
392 | new OListViewItem( (OListView*) details, "Unique", dev->uniq() ); | 392 | new OListViewItem( (OListView*) details, "Unique", dev->uniq() ); |
393 | 393 | ||
394 | QStringList text; | 394 | QStringList text; |
395 | if ( dev->hasFeature( OInputDevice::Synchronous ) ) text += "Synchronous"; | 395 | if ( dev->hasFeature( OInputDevice::Synchronous ) ) text += "Synchronous"; |
396 | if ( dev->hasFeature( OInputDevice::Keys ) ) text += "Keys"; | 396 | if ( dev->hasFeature( OInputDevice::Keys ) ) text += "Keys"; |
397 | if ( dev->hasFeature( OInputDevice::Relative ) ) text += "Relative"; | 397 | if ( dev->hasFeature( OInputDevice::Relative ) ) text += "Relative"; |
398 | if ( dev->hasFeature( OInputDevice::Absolute ) ) text += "Absolute"; | 398 | if ( dev->hasFeature( OInputDevice::Absolute ) ) text += "Absolute"; |
399 | if ( dev->hasFeature( OInputDevice::Miscellaneous ) ) text += "Miscellaneous"; | 399 | if ( dev->hasFeature( OInputDevice::Miscellaneous ) ) text += "Miscellaneous"; |
400 | if ( dev->hasFeature( OInputDevice::Switches ) ) text += "Switches"; | 400 | if ( dev->hasFeature( OInputDevice::Switches ) ) text += "Switches"; |
401 | if ( dev->hasFeature( OInputDevice::Leds ) ) text += "Leds"; | 401 | if ( dev->hasFeature( OInputDevice::Leds ) ) text += "Leds"; |
402 | if ( dev->hasFeature( OInputDevice::Sound ) ) text += "Sound"; | 402 | if ( dev->hasFeature( OInputDevice::Sound ) ) text += "Sound"; |
403 | if ( dev->hasFeature( OInputDevice::AutoRepeat ) ) text += "AutoRepeat"; | 403 | if ( dev->hasFeature( OInputDevice::AutoRepeat ) ) text += "AutoRepeat"; |
404 | if ( dev->hasFeature( OInputDevice::ForceFeedback ) ) text += "ForceFeedback"; | 404 | if ( dev->hasFeature( OInputDevice::ForceFeedback ) ) text += "ForceFeedback"; |
405 | if ( dev->hasFeature( OInputDevice::PowerManagement ) ) text += "PowerManagement"; | 405 | if ( dev->hasFeature( OInputDevice::PowerManagement ) ) text += "PowerManagement"; |
406 | if ( dev->hasFeature( OInputDevice::ForceFeedbackStatus ) ) text += "ForceFeedbackStatus"; | 406 | if ( dev->hasFeature( OInputDevice::ForceFeedbackStatus ) ) text += "ForceFeedbackStatus"; |
407 | new OListViewItem( (OListView*) details, "Features", text.join( ", " ) ); | 407 | new OListViewItem( (OListView*) details, "Features", text.join( ", " ) ); |
408 | 408 | ||
409 | } | 409 | } |
410 | 410 | ||
411 | InputDevice::~InputDevice() | 411 | InputDevice::~InputDevice() |
412 | { | 412 | { |
413 | } | 413 | } |
414 | 414 | ||
415 | //================================================================================================= | 415 | //================================================================================================= |
416 | UsbDevice::UsbDevice( Category* parent, const QString& name ) | 416 | UsbDevice::UsbDevice( Category* parent, const QString& name ) |
417 | :Device( parent, name ) | 417 | :Device( parent, name ) |
418 | { | 418 | { |
419 | details = new QPushButton( name, devinfo ); | 419 | details = new QPushButton( name, devinfo ); |
420 | details->hide(); | 420 | details->hide(); |
421 | } | 421 | } |
422 | 422 | ||
423 | //================================================================================================= | 423 | //================================================================================================= |
424 | UsbDevice::UsbDevice( UsbDevice* parent, const QString& name ) | 424 | UsbDevice::UsbDevice( UsbDevice* parent, const QString& name ) |
425 | :Device( parent, name ) | 425 | :Device( parent, name ) |
426 | { | 426 | { |
427 | details = new QPushButton( name, devinfo ); | 427 | details = new QPushButton( name, devinfo ); |
428 | details->hide(); | 428 | details->hide(); |
429 | } | 429 | } |
430 | 430 | ||
431 | UsbDevice::~UsbDevice() | 431 | UsbDevice::~UsbDevice() |
432 | { | 432 | { |
433 | } | 433 | } |
diff --git a/noncore/todayplugins/stockticker/libstocks/http.c b/noncore/todayplugins/stockticker/libstocks/http.c index 2f38f8a..cc78ab7 100644 --- a/noncore/todayplugins/stockticker/libstocks/http.c +++ b/noncore/todayplugins/stockticker/libstocks/http.c | |||
@@ -1,303 +1,303 @@ | |||
1 | /* libstocks - Library to get current stock quotes from Yahoo Finance | 1 | /* libstocks - Library to get current stock quotes from Yahoo Finance |
2 | * | 2 | * |
3 | * Copyright (C) 2000 Eric Laeuffer | 3 | * Copyright (C) 2000 Eric Laeuffer |
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 | 15 | * You should have received a copy of the GNU Library General Public |
16 | * License along with this library; if not, write to the | 16 | * License along with this library; if not, write to the |
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | * 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 | #define __HTTP_C__ | 21 | #define __HTTP_C__ |
22 | #ifndef __UNIX__ | 22 | #ifndef __UNIX__ |
23 | #define __UNIX__ | 23 | #define __UNIX__ |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | #ifdef __UNIX__ | 26 | #ifdef __UNIX__ |
27 | #include <sys/socket.h> | 27 | #include <sys/socket.h> |
28 | #include <netinet/in.h> | 28 | #include <netinet/in.h> |
29 | #include <arpa/inet.h> | 29 | #include <arpa/inet.h> |
30 | #include <netdb.h> | 30 | #include <netdb.h> |
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | #elif __WINDOWS__ | 32 | #elif __WINDOWS__ |
33 | #include <winsock.h> | 33 | #include <winsock.h> |
34 | #include <mbstring.h> | 34 | #include <mbstring.h> |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #include <sys/types.h> | 37 | #include <sys/types.h> |
38 | #include <ctype.h> | 38 | #include <ctype.h> |
39 | #include <string.h> | 39 | #include <string.h> |
40 | #include <stdlib.h> | 40 | #include <stdlib.h> |
41 | #include <stdio.h> | 41 | #include <stdio.h> |
42 | 42 | ||
43 | #include "http.h" | 43 | #include "http.h" |
44 | #include "stocks.h" | 44 | #include "stocks.h" |
45 | 45 | ||
46 | #define BUF_SIZE 1024 | 46 | #define BUF_SIZE 1024 |
47 | #define HEADER_MAXBUF 512 | 47 | #define HEADER_MAXBUF 512 |
48 | 48 | ||
49 | /* pointer to proxy server name or NULL */ | 49 | /* pointer to proxy server name or NULL */ |
50 | char *http_proxy_server=NULL; | 50 | char *http_proxy_server=NULL; |
51 | /* proxy server port number or 0 */ | 51 | /* proxy server port number or 0 */ |
52 | int http_proxy_port=0; | 52 | int http_proxy_port=0; |
53 | 53 | ||
54 | /*****************************************************************************/ | 54 | /*****************************************************************************/ |
55 | /* Gets the file from http://http_server/http_file */ | 55 | /* Gets the file from http://http_server/http_file */ |
56 | /* This function is used to get quotes csv file from yahoo. */ | 56 | /* This function is used to get quotes csv file from yahoo. */ |
57 | /* It allocates memory for the file and defines *pdata (the pointer of datas)*/ | 57 | /* It allocates memory for the file and defines *pdata (the pointer of datas)*/ |
58 | /*****************************************************************************/ | 58 | /*****************************************************************************/ |
59 | libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) | 59 | libstocks_return_code http_get(char *http_file, char *http_server, char **pdata) |
60 | { | 60 | { |
61 | struct hostent *host; /* structs needed by socket */ | 61 | struct hostent *host; /* structs needed by socket */ |
62 | struct sockaddr_in server; | 62 | struct sockaddr_in server; |
63 | int s; /* socket descriptor */ | 63 | int s; /* socket descriptor */ |
64 | char header[HEADER_MAXBUF]; /* request header */ | 64 | char header[HEADER_MAXBUF]; /* request header */ |
65 | int hlg; /* header length */ | 65 | int hlg; /* header length */ |
66 | char buf[BUF_SIZE+1]; /* tempory buffer from socket read */ | 66 | char buf[BUF_SIZE+1]; /* tempory buffer from socket read */ |
67 | int r; /* number of bytes read by read function */ | 67 | int r; /* number of bytes read by read function */ |
68 | char *data=NULL; /* http server response */ | 68 | char *data=NULL; /* http server response */ |
69 | int data_lgr; /* http server response length */ | 69 | int data_lgr; /* http server response length */ |
70 | char *temp; /* pointer used to split header and csv */ | 70 | char *temp; /* pointer used to split header and csv */ |
71 | int error_code; /* error code returned by http server */ | 71 | int error_code; /* error code returned by http server */ |
72 | char *csv_ptr; /* pointer to the csv content */ | 72 | char *csv_ptr; /* pointer to the csv content */ |
73 | int header_founded; /* test if header is founded */ | 73 | int header_founded; /* test if header is founded */ |
74 | 74 | ||
75 | #ifdef DEBUG | 75 | #ifdef DEBUG |
76 | printf("*http_get\n"); | 76 | printf("*http_get\n"); |
77 | #endif | 77 | #endif |
78 | 78 | ||
79 | /* get host info by name :*/ | 79 | /* get host info by name :*/ |
80 | if ((host = gethostbyname( http_proxy_server ? http_proxy_server : http_server))) | 80 | if ((host = gethostbyname( http_proxy_server ? http_proxy_server : http_server))) |
81 | { | 81 | { |
82 | memset((char *) &server,0, sizeof(server)); | 82 | memset((char *) &server,0, sizeof(server)); |
83 | memmove((char *) &server.sin_addr, host->h_addr, host->h_length); | 83 | memmove((char *) &server.sin_addr, host->h_addr, host->h_length); |
84 | server.sin_family = host->h_addrtype; | 84 | server.sin_family = host->h_addrtype; |
85 | server.sin_port = (unsigned short) htons( http_proxy_server ? http_proxy_port : 80 ); | 85 | server.sin_port = (unsigned short) htons( http_proxy_server ? http_proxy_port : 80 ); |
86 | 86 | ||
87 | } else | 87 | } else |
88 | { | 88 | { |
89 | 89 | ||
90 | #ifdef DEBUG | 90 | #ifdef DEBUG |
91 | printf(" gethostbyname : NOK\n"); | 91 | printf(" gethostbyname : NOK\n"); |
92 | #endif | 92 | #endif |
93 | return ERRHOST; | 93 | return ERRHOST; |
94 | } | 94 | } |
95 | 95 | ||
96 | /* create socket */ | 96 | /* create socket */ |
97 | if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) | 97 | if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) |
98 | { | 98 | { |
99 | 99 | ||
100 | #ifdef DEBUG | 100 | #ifdef DEBUG |
101 | printf(" create socket : NOK\n"); | 101 | printf(" create socket : NOK\n"); |
102 | #endif | 102 | #endif |
103 | return ERRSOCK; | 103 | return ERRSOCK; |
104 | } | 104 | } |
105 | 105 | ||
106 | setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0); | 106 | setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, 0, 0); |
107 | 107 | ||
108 | /* connect to server */ | 108 | /* connect to server */ |
109 | if (connect(s, &server, sizeof(server)) < 0) | 109 | if (connect(s, &server, sizeof(server)) < 0) |
110 | { | 110 | { |
111 | #ifdef DEBUG | 111 | #ifdef DEBUG |
112 | printf(" connect to server : NOK\n"); | 112 | printf(" connect to server : NOK\n"); |
113 | #endif | 113 | #endif |
114 | 114 | ||
115 | #ifdef __UNIX__ | 115 | #ifdef __UNIX__ |
116 | close(s); | 116 | close(s); |
117 | #elif __WINDOWS__ | 117 | #elif __WINDOWS__ |
118 | closesocket(s); | 118 | closesocket(s); |
119 | #endif | 119 | #endif |
120 | return ERRCONN; | 120 | return ERRCONN; |
121 | } | 121 | } |
122 | 122 | ||
123 | /* create header */ | 123 | /* create header */ |
124 | if (http_proxy_server) | 124 | if (http_proxy_server) |
125 | { | 125 | { |
126 | sprintf(header,"GET http://%.128s:80%.256s HTTP/1.0\015\012\015\012", | 126 | sprintf(header,"GET http://%.128s:80%.256s HTTP/1.0\015\012\015\012", |
127 | http_server, http_file); | 127 | http_server, http_file); |
128 | } | 128 | } |
129 | else | 129 | else |
130 | { | 130 | { |
131 | sprintf(header,"GET %s HTTP/1.0\015\012\015\012",http_file); | 131 | sprintf(header,"GET %s HTTP/1.0\015\012\015\012",http_file); |
132 | } | 132 | } |
133 | 133 | ||
134 | hlg=strlen(header); | 134 | hlg=strlen(header); |
135 | 135 | ||
136 | /* send header */ | 136 | /* send header */ |
137 | #ifdef __UNIX__ | 137 | #ifdef __UNIX__ |
138 | if (write(s,header,hlg)!=hlg) | 138 | if (write(s,header,hlg)!=hlg) |
139 | #elif __WINDOWS__ | 139 | #elif __WINDOWS__ |
140 | if (send(s,header,hlg, 0)!=hlg) | 140 | if (send(s,header,hlg, 0)!=hlg) |
141 | #endif | 141 | #endif |
142 | { | 142 | { |
143 | #ifdef DEBUG | 143 | #ifdef DEBUG |
144 | printf(" send header : NOK\n"); | 144 | printf(" send header : NOK\n"); |
145 | #endif | 145 | #endif |
146 | return ERRWHEA; | 146 | return ERRWHEA; |
147 | } | 147 | } |
148 | 148 | ||
149 | data_lgr = 0; | 149 | data_lgr = 0; |
150 | r=1; | 150 | r=1; |
151 | while(r) | 151 | while(r) |
152 | { | 152 | { |
153 | /* Clear Buffer */ | 153 | /* Clear Buffer */ |
154 | memset(buf,0,BUF_SIZE+1); | 154 | memset(buf,0,BUF_SIZE+1); |
155 | 155 | ||
156 | #ifdef __UNIX__ | 156 | #ifdef __UNIX__ |
157 | r=read(s,buf,BUF_SIZE); | 157 | r=read(s,buf,BUF_SIZE); |
158 | #elif __WINDOWS__ | 158 | #elif __WINDOWS__ |
159 | r=recv(s,buf,BUF_SIZE,0); | 159 | r=recv(s,buf,BUF_SIZE,0); |
160 | #endif | 160 | #endif |
161 | 161 | ||
162 | if (r) | 162 | if (r) |
163 | { | 163 | { |
164 | if(!data_lgr) | 164 | if(!data_lgr) |
165 | { | 165 | { |
166 | if((data = malloc(r+1))==NULL) | 166 | if((data = malloc(r+1))==NULL) |
167 | { | 167 | { |
168 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 168 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
169 | ,__FILE__, __LINE__); | 169 | ,__FILE__, __LINE__); |
170 | exit(1); | 170 | exit(1); |
171 | } | 171 | } |
172 | 172 | ||
173 | memcpy(data,buf,r); | 173 | memcpy(data,buf,r); |
174 | data_lgr = r; | 174 | data_lgr = r; |
175 | data[r]=0; | 175 | data[r]=0; |
176 | } | 176 | } |
177 | else | 177 | else |
178 | { | 178 | { |
179 | if((temp = malloc(r+data_lgr+1))==NULL) | 179 | if((temp = malloc(r+data_lgr+1))==NULL) |
180 | { | 180 | { |
181 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 181 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
182 | ,__FILE__, __LINE__); | 182 | ,__FILE__, __LINE__); |
183 | exit(1); | 183 | exit(1); |
184 | } | 184 | } |
185 | memcpy(temp, data, data_lgr); | 185 | memcpy(temp, data, data_lgr); |
186 | memcpy(temp+data_lgr, buf, r); | 186 | memcpy(temp+data_lgr, buf, r); |
187 | temp[r+data_lgr]=0; | 187 | temp[r+data_lgr]=0; |
188 | data_lgr += r; | 188 | data_lgr += r; |
189 | free(data); | 189 | free(data); |
190 | data = temp; | 190 | data = temp; |
191 | } | 191 | } |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | /* close socket */ | 195 | /* close socket */ |
196 | #ifdef __UNIX__ | 196 | #ifdef __UNIX__ |
197 | close(s); | 197 | close(s); |
198 | #elif __WINDOWS__ | 198 | #elif __WINDOWS__ |
199 | closesocket(s); | 199 | closesocket(s); |
200 | #endif | 200 | #endif |
201 | 201 | ||
202 | #ifdef DEBUG | 202 | #ifdef DEBUG |
203 | printf("%s\n", data); | 203 | printf("%s\n", data); |
204 | #endif | 204 | #endif |
205 | 205 | ||
206 | /* get headers to test status line */ | 206 | /* get headers to test status line */ |
207 | /* and to split headers and content */ | 207 | /* and to split headers and content */ |
208 | 208 | ||
209 | temp = data; | 209 | temp = data; |
210 | header_founded = 0; | 210 | header_founded = 0; |
211 | while( !header_founded ) | 211 | while( !header_founded ) |
212 | { | 212 | { |
213 | if (*temp==0) return ERRRHEA; | 213 | if (!temp || *temp==0) return ERRRHEA; |
214 | 214 | ||
215 | if( *temp==0x0A ) | 215 | if( *temp==0x0A ) |
216 | { | 216 | { |
217 | /* test if it is the header end */ | 217 | /* test if it is the header end */ |
218 | temp ++; | 218 | temp ++; |
219 | if (*temp == 0x0D) temp++; | 219 | if (*temp == 0x0D) temp++; |
220 | if (*temp == 0x0A) header_founded = 1; | 220 | if (*temp == 0x0A) header_founded = 1; |
221 | } | 221 | } |
222 | else | 222 | else |
223 | temp++; | 223 | temp++; |
224 | } | 224 | } |
225 | 225 | ||
226 | *temp = 0; | 226 | *temp = 0; |
227 | temp++; | 227 | temp++; |
228 | 228 | ||
229 | sscanf(data,"HTTP/1.%*d %03d",&error_code); | 229 | sscanf(data,"HTTP/1.%*d %03d",&error_code); |
230 | 230 | ||
231 | if (error_code != 200) | 231 | if (error_code != 200) |
232 | { | 232 | { |
233 | #ifdef DEBUG | 233 | #ifdef DEBUG |
234 | printf(" HTTP error code : %d\n", error_code); | 234 | printf(" HTTP error code : %d\n", error_code); |
235 | #endif | 235 | #endif |
236 | free(data); | 236 | free(data); |
237 | return ERRPAHD; | 237 | return ERRPAHD; |
238 | } | 238 | } |
239 | 239 | ||
240 | if ((csv_ptr = malloc(strlen(temp)+1))==NULL) | 240 | if ((csv_ptr = malloc(strlen(temp)+1))==NULL) |
241 | { | 241 | { |
242 | free(data); | 242 | free(data); |
243 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 243 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
244 | ,__FILE__, __LINE__); | 244 | ,__FILE__, __LINE__); |
245 | exit(1); | 245 | exit(1); |
246 | } | 246 | } |
247 | 247 | ||
248 | memcpy(csv_ptr, temp, strlen(temp)+1); | 248 | memcpy(csv_ptr, temp, strlen(temp)+1); |
249 | free(data); | 249 | free(data); |
250 | 250 | ||
251 | #ifdef DEBUG | 251 | #ifdef DEBUG |
252 | printf(" CSV\n"); | 252 | printf(" CSV\n"); |
253 | printf("%s,\n", csv_ptr); | 253 | printf("%s,\n", csv_ptr); |
254 | #endif | 254 | #endif |
255 | 255 | ||
256 | *pdata = csv_ptr; | 256 | *pdata = csv_ptr; |
257 | 257 | ||
258 | return 0; | 258 | return 0; |
259 | } | 259 | } |
260 | 260 | ||
261 | /******************************************************************************/ | 261 | /******************************************************************************/ |
262 | /* Set the proxy server to use */ | 262 | /* Set the proxy server to use */ |
263 | /******************************************************************************/ | 263 | /******************************************************************************/ |
264 | libstocks_return_code set_proxy(char *proxy) | 264 | libstocks_return_code set_proxy(char *proxy) |
265 | { | 265 | { |
266 | char *ptr; | 266 | char *ptr; |
267 | char c; | 267 | char c; |
268 | 268 | ||
269 | #ifdef DEBUG | 269 | #ifdef DEBUG |
270 | printf("*set_proxy\n"); | 270 | printf("*set_proxy\n"); |
271 | #endif | 271 | #endif |
272 | 272 | ||
273 | /* Parse the proxy URL - It must start with http:// */ | 273 | /* Parse the proxy URL - It must start with http:// */ |
274 | #ifdef __UNIX__ | 274 | #ifdef __UNIX__ |
275 | if (strncasecmp("http://",proxy,7)) return ERRPROX; | 275 | if (strncasecmp("http://",proxy,7)) return ERRPROX; |
276 | #elif __WINDOWS__ | 276 | #elif __WINDOWS__ |
277 | if (_mbsnbicmp("http://",proxy,7)) return ERRPROX; | 277 | if (_mbsnbicmp("http://",proxy,7)) return ERRPROX; |
278 | #endif | 278 | #endif |
279 | 279 | ||
280 | proxy+=7; | 280 | proxy+=7; |
281 | 281 | ||
282 | /* find ":" in the proxy url */ | 282 | /* find ":" in the proxy url */ |
283 | ptr = proxy; | 283 | ptr = proxy; |
284 | for (c=*ptr; (c && c!=':');) c=*ptr++; | 284 | for (c=*ptr; (c && c!=':');) c=*ptr++; |
285 | 285 | ||
286 | /* ptr points just after the ":" or at the end of proxy if : not founded */ | 286 | /* ptr points just after the ":" or at the end of proxy if : not founded */ |
287 | *(ptr-1)=0; /* clear the ":" */ | 287 | *(ptr-1)=0; /* clear the ":" */ |
288 | 288 | ||
289 | http_proxy_server=strdup(proxy); | 289 | http_proxy_server=strdup(proxy); |
290 | 290 | ||
291 | #ifdef DEBUG | 291 | #ifdef DEBUG |
292 | printf("http_proxy_server : %s\n", http_proxy_server); | 292 | printf("http_proxy_server : %s\n", http_proxy_server); |
293 | #endif | 293 | #endif |
294 | 294 | ||
295 | /* get the port number of the url */ | 295 | /* get the port number of the url */ |
296 | if (sscanf(ptr,"%d",&http_proxy_port)!=1) return ERRPROX; | 296 | if (sscanf(ptr,"%d",&http_proxy_port)!=1) return ERRPROX; |
297 | 297 | ||
298 | #ifdef DEBUG | 298 | #ifdef DEBUG |
299 | printf("http_proxy_port : %d\n", http_proxy_port); | 299 | printf("http_proxy_port : %d\n", http_proxy_port); |
300 | #endif | 300 | #endif |
301 | 301 | ||
302 | return 0; | 302 | return 0; |
303 | } | 303 | } |