author | sandman <sandman> | 2002-08-28 23:18:58 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-08-28 23:18:58 (UTC) |
commit | 178bd471d12a88862fb4ac1a17842ea0fd63c160 (patch) (unidiff) | |
tree | c37b10465eca3b6c2431b7999fe32eb4692f12ee | |
parent | 186bdeb08c0d9ccd78177310cf9f69ea80b76a96 (diff) | |
download | opie-178bd471d12a88862fb4ac1a17842ea0fd63c160.zip opie-178bd471d12a88862fb4ac1a17842ea0fd63c160.tar.gz opie-178bd471d12a88862fb4ac1a17842ea0fd63c160.tar.bz2 |
Workaround for a possible race condition in the QWS server (mostly OZ)
(clipboard handling in Qt/E is a mess)
-rw-r--r-- | core/applets/clipboardapplet/clipboard.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/core/applets/clipboardapplet/clipboard.cpp b/core/applets/clipboardapplet/clipboard.cpp index 4fbdf6f..3099a84 100644 --- a/core/applets/clipboardapplet/clipboard.cpp +++ b/core/applets/clipboardapplet/clipboard.cpp | |||
@@ -1,242 +1,255 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "clipboard.h" | 21 | #include "clipboard.h" |
22 | 22 | ||
23 | #include <qpe/resource.h> | 23 | #include <qpe/resource.h> |
24 | 24 | ||
25 | #include <qpainter.h> | 25 | #include <qpainter.h> |
26 | #include <qpopupmenu.h> | 26 | #include <qpopupmenu.h> |
27 | #include <qwindowsystem_qws.h> | 27 | #include <qwindowsystem_qws.h> |
28 | #include <qapplication.h> | 28 | #include <qapplication.h> |
29 | #include <qclipboard.h> | 29 | #include <qclipboard.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | 31 | ||
32 | //=========================================================================== | 32 | //=========================================================================== |
33 | 33 | ||
34 | /* XPM */ | 34 | /* XPM */ |
35 | static const char * paste_xpm[] = { | 35 | static const char * paste_xpm[] = { |
36 | "14 16 64 1", | 36 | "14 16 64 1", |
37 | " c None", | 37 | " c None", |
38 | ".c #020202", | 38 | ".c #020202", |
39 | "+c #867616", | 39 | "+c #867616", |
40 | "@c #A69A42", | 40 | "@c #A69A42", |
41 | "#c #BAB676", | 41 | "#c #BAB676", |
42 | "$c #060606", | 42 | "$c #060606", |
43 | "%c #EAD2AA", | 43 | "%c #EAD2AA", |
44 | "&c #F6F6DA", | 44 | "&c #F6F6DA", |
45 | "*c #222212", | 45 | "*c #222212", |
46 | "=c #86761E", | 46 | "=c #86761E", |
47 | "-c #868686", | 47 | "-c #868686", |
48 | ";c #5A5202", | 48 | ";c #5A5202", |
49 | ">c #8A7E2E", | 49 | ">c #8A7E2E", |
50 | ",c #2C2C2C", | 50 | ",c #2C2C2C", |
51 | "'c #9A9A9A", | 51 | "'c #9A9A9A", |
52 | ")c #F6EADA", | 52 | ")c #F6EADA", |
53 | "!c #AAA262", | 53 | "!c #AAA262", |
54 | "~c #323232", | 54 | "~c #323232", |
55 | "{c #726A32", | 55 | "{c #726A32", |
56 | "]c #6E6E6E", | 56 | "]c #6E6E6E", |
57 | "^c #C2B69E", | 57 | "^c #C2B69E", |
58 | "/c #9E9E9E", | 58 | "/c #9E9E9E", |
59 | "(c #EED6BA", | 59 | "(c #EED6BA", |
60 | "_c #F2DEC2", | 60 | "_c #F2DEC2", |
61 | ":c #D2CE8E", | 61 | ":c #D2CE8E", |
62 | "<c #3A3A3A", | 62 | "<c #3A3A3A", |
63 | "[c #EACAA2", | 63 | "[c #EACAA2", |
64 | "}c #3E3E3E", | 64 | "}c #3E3E3E", |
65 | "|c #727272", | 65 | "|c #727272", |
66 | "1c #CECECE", | 66 | "1c #CECECE", |
67 | "2c #929292", | 67 | "2c #929292", |
68 | "3c #4A462A", | 68 | "3c #4A462A", |
69 | "4c #424242", | 69 | "4c #424242", |
70 | "5c #666666", | 70 | "5c #666666", |
71 | "6c #C2AE96", | 71 | "6c #C2AE96", |
72 | "7c #767676", | 72 | "7c #767676", |
73 | "8c #D6D6D6", | 73 | "8c #D6D6D6", |
74 | "9c #C2C2C2", | 74 | "9c #C2C2C2", |
75 | "0c #BFA681", | 75 | "0c #BFA681", |
76 | "ac #1E1E1E", | 76 | "ac #1E1E1E", |
77 | "bc #FAF6F3", | 77 | "bc #FAF6F3", |
78 | "cc #AEAEAE", | 78 | "cc #AEAEAE", |
79 | "dc #C29A6A", | 79 | "dc #C29A6A", |
80 | "ec #FEFEFE", | 80 | "ec #FEFEFE", |
81 | "fc #B6B6B6", | 81 | "fc #B6B6B6", |
82 | "gc #7E7E7E", | 82 | "gc #7E7E7E", |
83 | "hc #FAF2E6", | 83 | "hc #FAF2E6", |
84 | "ic #8E8E8E", | 84 | "ic #8E8E8E", |
85 | "jc #C6BCAE", | 85 | "jc #C6BCAE", |
86 | "kc #DEDEDE", | 86 | "kc #DEDEDE", |
87 | "lc #BEBEBE", | 87 | "lc #BEBEBE", |
88 | "mc #464646", | 88 | "mc #464646", |
89 | "nc #BEAE92", | 89 | "nc #BEAE92", |
90 | "oc #262626", | 90 | "oc #262626", |
91 | "pc #F2E2CE", | 91 | "pc #F2E2CE", |
92 | "qc #C2A175", | 92 | "qc #C2A175", |
93 | "rc #CACACA", | 93 | "rc #CACACA", |
94 | "sc #969696", | 94 | "sc #969696", |
95 | "tc #8A8A8A", | 95 | "tc #8A8A8A", |
96 | "uc #828282", | 96 | "uc #828282", |
97 | "vc #6A6A6A", | 97 | "vc #6A6A6A", |
98 | "wc #BEB6AE", | 98 | "wc #BEB6AE", |
99 | "xc #E2E0E0", | 99 | "xc #E2E0E0", |
100 | "yc #7A7A7A", | 100 | "yc #7A7A7A", |
101 | " *{>; ", | 101 | " *{>; ", |
102 | " }}}@e:!;}}} ", | 102 | " }}}@e:!;}}} ", |
103 | "<x8=&:#@+;ll, ", | 103 | "<x8=&:#@+;ll, ", |
104 | "}k/=;;3}337|o ", | 104 | "}k/=;;3}337|o ", |
105 | "<k's24444m45o ", | 105 | "<k's24444m45o ", |
106 | "}8'ss4xkkk]}a ", | 106 | "}8'ss4xkkk]}a ", |
107 | "<1s224keee|b4 ", | 107 | "<1s224keee|b4 ", |
108 | "}r2itmkeee]]44", | 108 | "}r2itmkeee]]44", |
109 | "<9iitmkeeehkw.", | 109 | "<9iitmkeeehkw.", |
110 | "<lt-u4keeb)pn.", | 110 | "<lt-u4keeb)pn.", |
111 | "<fu-umkebhp(0.", | 111 | "<fu-umkebhp(0.", |
112 | "<cugg4kbh)_(q.", | 112 | "<cugg4kbh)_(q.", |
113 | "<cyyymk))p(%q.", | 113 | "<cyyymk))p(%q.", |
114 | ",5vvv4k)p_%[q.", | 114 | ",5vvv4k)p_%[q.", |
115 | " ...$mljnn0qd.", | 115 | " ...$mljnn0qd.", |
116 | " 4.......,"}; | 116 | " 4.......,"}; |
117 | 117 | ||
118 | 118 | ||
119 | ClipboardApplet::ClipboardApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) | 119 | ClipboardApplet::ClipboardApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) |
120 | { | 120 | { |
121 | setFixedWidth ( 14 ); | 121 | setFixedWidth ( 14 ); |
122 | setFixedHeight ( 18 ); | 122 | setFixedHeight ( 18 ); |
123 | m_clipboardPixmap = QPixmap ( paste_xpm ); | 123 | m_clipboardPixmap = QPixmap ( paste_xpm ); |
124 | 124 | ||
125 | m_timer = new QTimer ( this ); | 125 | m_timer = new QTimer ( this ); |
126 | 126 | ||
127 | connect ( QApplication::clipboard ( ), SIGNAL( dataChanged ( )), this, SLOT( newData ( ))); | 127 | connect ( QApplication::clipboard ( ), SIGNAL( dataChanged ( )), this, SLOT( newData ( ))); |
128 | connect ( m_timer, SIGNAL( timeout ( )), this, SLOT( newData ( ))); | 128 | connect ( m_timer, SIGNAL( timeout ( )), this, SLOT( newData ( ))); |
129 | connect ( qApp, SIGNAL( aboutToQuit ( )), this, SLOT( shutdown ( ))); | 129 | connect ( qApp, SIGNAL( aboutToQuit ( )), this, SLOT( shutdown ( ))); |
130 | 130 | ||
131 | m_timer-> start ( 1500 ); | ||
132 | |||
133 | m_menu = 0; | 131 | m_menu = 0; |
134 | m_dirty = true; | 132 | m_dirty = true; |
135 | m_lasttext = QString::null; | 133 | m_lasttext = QString::null; |
134 | |||
135 | m_timer-> start ( 0, true ); | ||
136 | } | 136 | } |
137 | 137 | ||
138 | ClipboardApplet::~ClipboardApplet ( ) | 138 | ClipboardApplet::~ClipboardApplet ( ) |
139 | { | 139 | { |
140 | } | 140 | } |
141 | 141 | ||
142 | void ClipboardApplet::shutdown ( ) | 142 | void ClipboardApplet::shutdown ( ) |
143 | { | 143 | { |
144 | // the timer has to be stopped, or Qt/E will hang on quit() | 144 | // the timer has to be stopped, or Qt/E will hang on quit() |
145 | // see launcher/desktop.cpp | 145 | // see launcher/desktop.cpp |
146 | 146 | ||
147 | m_timer-> stop ( ); | 147 | m_timer-> stop ( ); |
148 | } | 148 | } |
149 | 149 | ||
150 | void ClipboardApplet::mousePressEvent ( QMouseEvent *) | 150 | void ClipboardApplet::mousePressEvent ( QMouseEvent *) |
151 | { | 151 | { |
152 | if ( m_dirty ) { | 152 | if ( m_dirty ) { |
153 | delete m_menu; | 153 | delete m_menu; |
154 | 154 | ||
155 | m_menu = new QPopupMenu ( this ); | 155 | m_menu = new QPopupMenu ( this ); |
156 | m_menu-> setCheckable ( true ); | 156 | m_menu-> setCheckable ( true ); |
157 | 157 | ||
158 | if ( m_history. count ( )) { | 158 | if ( m_history. count ( )) { |
159 | for ( unsigned int i = 0; i < m_history. count ( ); i++ ) { | 159 | for ( unsigned int i = 0; i < m_history. count ( ); i++ ) { |
160 | QString str = m_history [i]; | 160 | QString str = m_history [i]; |
161 | 161 | ||
162 | if ( str. length ( ) > 20 ) | 162 | if ( str. length ( ) > 20 ) |
163 | str = str. left ( 20 ) + "..."; | 163 | str = str. left ( 20 ) + "..."; |
164 | 164 | ||
165 | m_menu-> insertItem ( QString ( "%1: %2" ). arg ( i + 1 ). arg ( str ), i ); | 165 | m_menu-> insertItem ( QString ( "%1: %2" ). arg ( i + 1 ). arg ( str ), i ); |
166 | m_menu-> setItemChecked ( i, false ); | 166 | m_menu-> setItemChecked ( i, false ); |
167 | } | 167 | } |
168 | m_menu-> setItemChecked ( m_history. count ( ) - 1, true ); | 168 | m_menu-> setItemChecked ( m_history. count ( ) - 1, true ); |
169 | m_menu-> insertSeparator ( ); | 169 | m_menu-> insertSeparator ( ); |
170 | } | 170 | } |
171 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "cut" )), tr( "Cut" ), 100 ); | 171 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "cut" )), tr( "Cut" ), 100 ); |
172 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "copy" )), tr( "Copy" ), 101 ); | 172 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "copy" )), tr( "Copy" ), 101 ); |
173 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "paste" )), tr( "Paste" ), 102 ); | 173 | m_menu-> insertItem ( QIconSet ( Resource::loadPixmap ( "paste" )), tr( "Paste" ), 102 ); |
174 | 174 | ||
175 | connect ( m_menu, SIGNAL( activated ( int )), this, SLOT( action ( int ))); | 175 | connect ( m_menu, SIGNAL( activated ( int )), this, SLOT( action ( int ))); |
176 | 176 | ||
177 | m_dirty = false; | 177 | m_dirty = false; |
178 | } | 178 | } |
179 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); | 179 | QPoint p = mapToGlobal ( QPoint ( 0, 0 )); |
180 | QSize s = m_menu-> sizeHint ( ); | 180 | QSize s = m_menu-> sizeHint ( ); |
181 | 181 | ||
182 | m_menu-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ))); | 182 | m_menu-> popup ( QPoint ( p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), p. y ( ) - s. height ( ))); |
183 | } | 183 | } |
184 | 184 | ||
185 | void ClipboardApplet::action(int id) | 185 | void ClipboardApplet::action(int id) |
186 | { | 186 | { |
187 | ushort unicode = 0; | 187 | ushort unicode = 0; |
188 | int scan = 0; | 188 | int scan = 0; |
189 | 189 | ||
190 | switch ( id ) { | 190 | switch ( id ) { |
191 | case 100: | 191 | case 100: |
192 | unicode = 'X' - '@'; | 192 | unicode = 'X' - '@'; |
193 | scan = Key_X; // Cut | 193 | scan = Key_X; // Cut |
194 | break; | 194 | break; |
195 | case 101: | 195 | case 101: |
196 | unicode = 'C' - '@'; | 196 | unicode = 'C' - '@'; |
197 | scan = Key_C; // Copy | 197 | scan = Key_C; // Copy |
198 | break; | 198 | break; |
199 | case 102: | 199 | case 102: |
200 | unicode = 'V' - '@'; | 200 | unicode = 'V' - '@'; |
201 | scan = Key_V; // Paste | 201 | scan = Key_V; // Paste |
202 | break; | 202 | break; |
203 | 203 | ||
204 | default: | 204 | default: |
205 | if (( id >= 0 ) && ( uint( id ) < m_history. count ( ))) { | 205 | if (( id >= 0 ) && ( uint( id ) < m_history. count ( ))) { |
206 | QApplication::clipboard ( )-> setText ( m_history [id] ); | 206 | QApplication::clipboard ( )-> setText ( m_history [id] ); |
207 | 207 | ||
208 | for ( uint i = 0; i < m_history. count ( ); i++ ) | 208 | for ( uint i = 0; i < m_history. count ( ); i++ ) |
209 | m_menu-> setItemChecked ( i, i == uint( id )); | 209 | m_menu-> setItemChecked ( i, i == uint( id )); |
210 | 210 | ||
211 | unicode = 'V' - '@'; | 211 | unicode = 'V' - '@'; |
212 | scan = Key_V; | 212 | scan = Key_V; |
213 | } | 213 | } |
214 | break; | 214 | break; |
215 | } | 215 | } |
216 | 216 | ||
217 | if ( scan ) { | 217 | if ( scan ) { |
218 | qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, true, false ); | 218 | qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, true, false ); |
219 | qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, false, false ); | 219 | qwsServer-> sendKeyEvent ( unicode, scan, ControlButton, false, false ); |
220 | } | 220 | } |
221 | } | 221 | } |
222 | 222 | ||
223 | void ClipboardApplet::paintEvent ( QPaintEvent* ) | 223 | void ClipboardApplet::paintEvent ( QPaintEvent* ) |
224 | { | 224 | { |
225 | QPainter p ( this ); | 225 | QPainter p ( this ); |
226 | p. drawPixmap ( 0, 1, m_clipboardPixmap ); | 226 | p. drawPixmap ( 0, 1, m_clipboardPixmap ); |
227 | } | 227 | } |
228 | 228 | ||
229 | void ClipboardApplet::newData ( ) | 229 | void ClipboardApplet::newData ( ) |
230 | { | 230 | { |
231 | static bool excllock = false; | ||
232 | |||
233 | if ( excllock ) | ||
234 | return; | ||
235 | else | ||
236 | excllock = true; | ||
237 | |||
238 | m_timer-> stop ( ); | ||
239 | |||
231 | QCString type = "plain"; | 240 | QCString type = "plain"; |
232 | QString txt = QApplication::clipboard ( )-> text ( type ); | 241 | QString txt = QApplication::clipboard ( )-> text ( type ); |
233 | 242 | ||
234 | if ( !txt. isEmpty ( ) && !m_history. contains ( txt )) { | 243 | if ( !txt. isEmpty ( ) && !m_history. contains ( txt )) { |
235 | m_history. append ( txt ); | 244 | m_history. append ( txt ); |
236 | 245 | ||
237 | if ( m_history. count ( ) > 5 ) | 246 | if ( m_history. count ( ) > 5 ) |
238 | m_history. remove ( m_history. begin ( )); | 247 | m_history. remove ( m_history. begin ( )); |
239 | 248 | ||
240 | m_dirty = true; | 249 | m_dirty = true; |
241 | } | 250 | } |
251 | |||
252 | m_timer-> start ( 1500, true ); | ||
253 | |||
254 | excllock = false; | ||
242 | } | 255 | } |