-rw-r--r-- | core/apps/embeddedkonsole/TEScreen.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/checkbook/listedit.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/TEScreen.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-sheet/Excel.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katedocument.cpp | 4 | ||||
-rw-r--r-- | noncore/comm/keypebble/krfbdecoder.cpp | 6 | ||||
-rw-r--r-- | noncore/games/sfcave/sfcave.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/aqpkg/settingsimpl.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/aqpkg/version.cpp | 2 |
9 files changed, 14 insertions, 14 deletions
diff --git a/core/apps/embeddedkonsole/TEScreen.cpp b/core/apps/embeddedkonsole/TEScreen.cpp index 8e69a88..1db34d2 100644 --- a/core/apps/embeddedkonsole/TEScreen.cpp +++ b/core/apps/embeddedkonsole/TEScreen.cpp | |||
@@ -1045,192 +1045,192 @@ QString TEScreen::getSelText(const BOOL preserve_line_breaks) | |||
1045 | s++; | 1045 | s++; |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | if (s <= sel_BR) | 1048 | if (s <= sel_BR) |
1049 | { | 1049 | { |
1050 | // The line break handling | 1050 | // The line break handling |
1051 | // It's different from the screen | 1051 | // It's different from the screen |
1052 | // image case! | 1052 | // image case! |
1053 | if (eol % columns == 0) | 1053 | if (eol % columns == 0) |
1054 | { | 1054 | { |
1055 | // That's either a completely filled | 1055 | // That's either a completely filled |
1056 | // line or an empty line | 1056 | // line or an empty line |
1057 | if (eol == 0) | 1057 | if (eol == 0) |
1058 | { | 1058 | { |
1059 | m[d++] = '\n'; | 1059 | m[d++] = '\n'; |
1060 | } | 1060 | } |
1061 | else | 1061 | else |
1062 | { | 1062 | { |
1063 | // We have a full line. | 1063 | // We have a full line. |
1064 | // FIXME: How can we handle newlines | 1064 | // FIXME: How can we handle newlines |
1065 | // at this position?! | 1065 | // at this position?! |
1066 | } | 1066 | } |
1067 | } | 1067 | } |
1068 | else if ((eol + 1) % columns == 0) | 1068 | else if ((eol + 1) % columns == 0) |
1069 | { | 1069 | { |
1070 | // FIXME: We don't know if this was a | 1070 | // FIXME: We don't know if this was a |
1071 | // space at the last position or a | 1071 | // space at the last position or a |
1072 | // short line!! | 1072 | // short line!! |
1073 | m[d++] = ' '; | 1073 | m[d++] = ' '; |
1074 | } | 1074 | } |
1075 | else | 1075 | else |
1076 | { | 1076 | { |
1077 | // We have a short line here. Put a | 1077 | // We have a short line here. Put a |
1078 | // newline or a space into the | 1078 | // newline or a space into the |
1079 | // buffer. | 1079 | // buffer. |
1080 | m[d++] = preserve_line_breaks ? '\n' : ' '; | 1080 | m[d++] = preserve_line_breaks ? '\n' : ' '; |
1081 | } | 1081 | } |
1082 | } | 1082 | } |
1083 | 1083 | ||
1084 | hY++; | 1084 | hY++; |
1085 | hX = 0; | 1085 | hX = 0; |
1086 | s = hY * columns; | 1086 | s = hY * columns; |
1087 | } | 1087 | } |
1088 | else | 1088 | else |
1089 | { // or from screen image. | 1089 | { // or from screen image. |
1090 | eol = (s / columns + 1) * columns - 1; | 1090 | eol = (s / columns + 1) * columns - 1; |
1091 | 1091 | ||
1092 | if (eol < sel_BR) | 1092 | if (eol < sel_BR) |
1093 | { | 1093 | { |
1094 | while ((eol > s) && | 1094 | while ((eol > s) && |
1095 | isspace(image[eol - hist_BR].c)) | 1095 | isspace(image[eol - hist_BR].c)) |
1096 | { | 1096 | { |
1097 | eol--; | 1097 | eol--; |
1098 | } | 1098 | } |
1099 | } | 1099 | } |
1100 | else | 1100 | else |
1101 | { | 1101 | { |
1102 | eol = sel_BR; | 1102 | eol = sel_BR; |
1103 | } | 1103 | } |
1104 | 1104 | ||
1105 | while (s <= eol) | 1105 | while (s <= eol) |
1106 | { | 1106 | { |
1107 | m[d++] = image[s++ - hist_BR].c; | 1107 | m[d++] = image[s++ - hist_BR].c; |
1108 | } | 1108 | } |
1109 | 1109 | ||
1110 | if (eol < sel_BR) | 1110 | if (eol < sel_BR) |
1111 | { | 1111 | { |
1112 | // eol processing see below ... | 1112 | // eol processing see below ... |
1113 | if ((eol + 1) % columns == 0) | 1113 | if ((eol + 1) % columns == 0) |
1114 | { | 1114 | { |
1115 | if (image[eol - hist_BR].c == ' ') | 1115 | if (image[eol - hist_BR].c == ' ') |
1116 | { | 1116 | { |
1117 | m[d++] = ' '; | 1117 | m[d++] = ' '; |
1118 | } | 1118 | } |
1119 | } | 1119 | } |
1120 | else | 1120 | else |
1121 | { | 1121 | { |
1122 | m[d++] = ((preserve_line_breaks || | 1122 | m[d++] = ((preserve_line_breaks || |
1123 | ((eol % columns) == 0)) ? | 1123 | ((eol % columns) == 0)) ? |
1124 | '\n' : ' '); | 1124 | '\n' : ' '); |
1125 | } | 1125 | } |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | s = (eol / columns + 1) * columns; | 1128 | s = (eol / columns + 1) * columns; |
1129 | } | 1129 | } |
1130 | } | 1130 | } |
1131 | 1131 | ||
1132 | QChar* qc = new QChar[d]; | 1132 | QChar* qc = new QChar[d]; |
1133 | 1133 | ||
1134 | for (int i = 0; i < d; i++) | 1134 | for (int i = 0; i < d; i++) |
1135 | { | 1135 | { |
1136 | qc[i] = m[i]; | 1136 | qc[i] = m[i]; |
1137 | } | 1137 | } |
1138 | 1138 | ||
1139 | QString res(qc, d); | 1139 | QString res(qc, d); |
1140 | 1140 | ||
1141 | delete m; | 1141 | delete [] m; |
1142 | delete qc; | 1142 | delete [] qc; |
1143 | 1143 | ||
1144 | return res; | 1144 | return res; |
1145 | } | 1145 | } |
1146 | /* above ... end of line processing for selection -- psilva | 1146 | /* above ... end of line processing for selection -- psilva |
1147 | cases: | 1147 | cases: |
1148 | 1148 | ||
1149 | 1) (eol+1)%columns == 0 --> the whole line is filled. | 1149 | 1) (eol+1)%columns == 0 --> the whole line is filled. |
1150 | If the last char is a space, insert (preserve) space. otherwise | 1150 | If the last char is a space, insert (preserve) space. otherwise |
1151 | leave the text alone, so that words that are broken by linewrap | 1151 | leave the text alone, so that words that are broken by linewrap |
1152 | are preserved. | 1152 | are preserved. |
1153 | 1153 | ||
1154 | FIXME: | 1154 | FIXME: |
1155 | * this suppresses \n for command output that is | 1155 | * this suppresses \n for command output that is |
1156 | sized to the exact column width of the screen. | 1156 | sized to the exact column width of the screen. |
1157 | 1157 | ||
1158 | 2) eol%columns == 0 --> blank line. | 1158 | 2) eol%columns == 0 --> blank line. |
1159 | insert a \n unconditionally. | 1159 | insert a \n unconditionally. |
1160 | Do it either you would because you are in preserve_line_break mode, | 1160 | Do it either you would because you are in preserve_line_break mode, |
1161 | or because it's an ASCII paragraph delimiter, so even when | 1161 | or because it's an ASCII paragraph delimiter, so even when |
1162 | not preserving line_breaks, you want to preserve paragraph breaks. | 1162 | not preserving line_breaks, you want to preserve paragraph breaks. |
1163 | 1163 | ||
1164 | 3) else --> partially filled line | 1164 | 3) else --> partially filled line |
1165 | insert a \n in preserve line break mode, else a space | 1165 | insert a \n in preserve line break mode, else a space |
1166 | The space prevents concatenation of the last word of one | 1166 | The space prevents concatenation of the last word of one |
1167 | line with the first of the next. | 1167 | line with the first of the next. |
1168 | 1168 | ||
1169 | */ | 1169 | */ |
1170 | 1170 | ||
1171 | void TEScreen::addHistLine() | 1171 | void TEScreen::addHistLine() |
1172 | { | 1172 | { |
1173 | assert(hasScroll() || histCursor == 0); | 1173 | assert(hasScroll() || histCursor == 0); |
1174 | 1174 | ||
1175 | // add to hist buffer | 1175 | // add to hist buffer |
1176 | // we have to take care about scrolling, too... | 1176 | // we have to take care about scrolling, too... |
1177 | 1177 | ||
1178 | if (hasScroll()){ | 1178 | if (hasScroll()){ |
1179 | ca dft; | 1179 | ca dft; |
1180 | 1180 | ||
1181 | int end = columns - 1; | 1181 | int end = columns - 1; |
1182 | while (end >= 0 && image[end] == dft) | 1182 | while (end >= 0 && image[end] == dft) |
1183 | end -= 1; | 1183 | end -= 1; |
1184 | 1184 | ||
1185 | hist.addCells( image, end + 1); | 1185 | hist.addCells( image, end + 1); |
1186 | hist.addLine(); | 1186 | hist.addLine(); |
1187 | 1187 | ||
1188 | // adjust history cursor | 1188 | // adjust history cursor |
1189 | histCursor += ( hist.getLines() - 1 == histCursor); | 1189 | histCursor += ( hist.getLines() - 1 == histCursor); |
1190 | } | 1190 | } |
1191 | 1191 | ||
1192 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround | 1192 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround |
1193 | } | 1193 | } |
1194 | 1194 | ||
1195 | void TEScreen::setHistCursor(int cursor) | 1195 | void TEScreen::setHistCursor(int cursor) |
1196 | { | 1196 | { |
1197 | histCursor = cursor; //FIXME:rangecheck | 1197 | histCursor = cursor; //FIXME:rangecheck |
1198 | if (histCursor > hist.getLines()) { | 1198 | if (histCursor > hist.getLines()) { |
1199 | histCursor = hist.getLines(); | 1199 | histCursor = hist.getLines(); |
1200 | } | 1200 | } |
1201 | if (histCursor < 0) { | 1201 | if (histCursor < 0) { |
1202 | histCursor = 0; | 1202 | histCursor = 0; |
1203 | } | 1203 | } |
1204 | } | 1204 | } |
1205 | 1205 | ||
1206 | void TEScreen::setHorzCursor(int cursor) | 1206 | void TEScreen::setHorzCursor(int cursor) |
1207 | { | 1207 | { |
1208 | horzCursor = cursor; | 1208 | horzCursor = cursor; |
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | int TEScreen::getHistCursor() | 1211 | int TEScreen::getHistCursor() |
1212 | { | 1212 | { |
1213 | return histCursor; | 1213 | return histCursor; |
1214 | } | 1214 | } |
1215 | 1215 | ||
1216 | int TEScreen::getHorzCursor() | 1216 | int TEScreen::getHorzCursor() |
1217 | { | 1217 | { |
1218 | return horzCursor; | 1218 | return horzCursor; |
1219 | } | 1219 | } |
1220 | 1220 | ||
1221 | int TEScreen::getHistLines() | 1221 | int TEScreen::getHistLines() |
1222 | { | 1222 | { |
1223 | return hist.getLines(); | 1223 | return hist.getLines(); |
1224 | } | 1224 | } |
1225 | 1225 | ||
1226 | void TEScreen::setScroll(bool on) | 1226 | void TEScreen::setScroll(bool on) |
1227 | { | 1227 | { |
1228 | histCursor = 0; | 1228 | histCursor = 0; |
1229 | clearSelection(); | 1229 | clearSelection(); |
1230 | hist.setScroll(on); | 1230 | hist.setScroll(on); |
1231 | } | 1231 | } |
1232 | 1232 | ||
1233 | bool TEScreen::hasScroll() | 1233 | bool TEScreen::hasScroll() |
1234 | { | 1234 | { |
1235 | return hist.hasScroll(); | 1235 | return hist.hasScroll(); |
1236 | } | 1236 | } |
diff --git a/noncore/apps/checkbook/listedit.cpp b/noncore/apps/checkbook/listedit.cpp index e40377b..b297d69 100644 --- a/noncore/apps/checkbook/listedit.cpp +++ b/noncore/apps/checkbook/listedit.cpp | |||
@@ -143,193 +143,193 @@ void ListEdit::slotDel() | |||
143 | _stack->raiseWidget(_typeEdit); | 143 | _stack->raiseWidget(_typeEdit); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | // --- fixTypes ---------------------------------------------------------------- | 147 | // --- fixTypes ---------------------------------------------------------------- |
148 | // Makes sure all entries have a unique name and empty entries are replaced | 148 | // Makes sure all entries have a unique name and empty entries are replaced |
149 | // by a generic string. The first version performs the operation on a particular | 149 | // by a generic string. The first version performs the operation on a particular |
150 | // column, whereas the 2nd does it for all unique columns. | 150 | // column, whereas the 2nd does it for all unique columns. |
151 | class ColMap { | 151 | class ColMap { |
152 | public: | 152 | public: |
153 | ColMap(QString sValue, QListViewItem *pEntry) { | 153 | ColMap(QString sValue, QListViewItem *pEntry) { |
154 | _sValue=sValue; | 154 | _sValue=sValue; |
155 | _pEntry=pEntry; | 155 | _pEntry=pEntry; |
156 | } | 156 | } |
157 | QString &getValue() { return(_sValue); } | 157 | QString &getValue() { return(_sValue); } |
158 | QListViewItem *getItem() { return(_pEntry); } | 158 | QListViewItem *getItem() { return(_pEntry); } |
159 | 159 | ||
160 | protected: | 160 | protected: |
161 | QString _sValue; | 161 | QString _sValue; |
162 | QListViewItem *_pEntry; | 162 | QListViewItem *_pEntry; |
163 | }; | 163 | }; |
164 | 164 | ||
165 | class ColList : public QList<QString> | 165 | class ColList : public QList<QString> |
166 | { | 166 | { |
167 | public: | 167 | public: |
168 | ColList() : QList<QString>() { } | 168 | ColList() : QList<QString>() { } |
169 | 169 | ||
170 | protected: | 170 | protected: |
171 | int compareItems(QCollection::Item, QCollection::Item); | 171 | int compareItems(QCollection::Item, QCollection::Item); |
172 | }; | 172 | }; |
173 | 173 | ||
174 | int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { | 174 | int ColList::compareItems(QCollection::Item i1, QCollection::Item i2) { |
175 | return( ((QString *)i1)->compare(*(QString *)i2) ); | 175 | return( ((QString *)i1)->compare(*(QString *)i2) ); |
176 | } | 176 | } |
177 | 177 | ||
178 | void ListEdit::fixTypes(int iColumn) | 178 | void ListEdit::fixTypes(int iColumn) |
179 | { | 179 | { |
180 | // get column def | 180 | // get column def |
181 | ColumnDef *pDef=this->at(iColumn); | 181 | ColumnDef *pDef=this->at(iColumn); |
182 | 182 | ||
183 | // create map of entries | 183 | // create map of entries |
184 | if( !_typeTable->childCount() ) return; | 184 | if( !_typeTable->childCount() ) return; |
185 | ColMap **colMap=new ColMap *[_typeTable->childCount()]; | 185 | ColMap **colMap=new ColMap *[_typeTable->childCount()]; |
186 | QListViewItem *cur=_typeTable->firstChild(); | 186 | QListViewItem *cur=_typeTable->firstChild(); |
187 | ColList lst; | 187 | ColList lst; |
188 | for(int i=0; i<_typeTable->childCount(); i++) { | 188 | for(int i=0; i<_typeTable->childCount(); i++) { |
189 | colMap[i]=new ColMap(cur->text(iColumn), cur); | 189 | colMap[i]=new ColMap(cur->text(iColumn), cur); |
190 | lst.append( &(colMap[i]->getValue()) ); | 190 | lst.append( &(colMap[i]->getValue()) ); |
191 | cur=cur->nextSibling(); | 191 | cur=cur->nextSibling(); |
192 | } | 192 | } |
193 | 193 | ||
194 | // fix empty entries | 194 | // fix empty entries |
195 | int i=0; | 195 | int i=0; |
196 | for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { | 196 | for(QString *ptr=lst.first(); ptr; ptr=lst.next()) { |
197 | *ptr=ptr->stripWhiteSpace(); | 197 | *ptr=ptr->stripWhiteSpace(); |
198 | if( ptr->isEmpty() ) { | 198 | if( ptr->isEmpty() ) { |
199 | i++; | 199 | i++; |
200 | if( i==1 ) *ptr=pDef->getNewValue(); | 200 | if( i==1 ) *ptr=pDef->getNewValue(); |
201 | else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); | 201 | else ptr->sprintf("%s %d", (const char *)pDef->getNewValue(), i); |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | // fix dups | 205 | // fix dups |
206 | lst.sort(); | 206 | lst.sort(); |
207 | QString repl; | 207 | QString repl; |
208 | for(uint iCur=0; iCur<lst.count()-1; iCur++) { | 208 | for(uint iCur=0; iCur<lst.count()-1; iCur++) { |
209 | QString *current=lst.at(iCur); | 209 | QString *current=lst.at(iCur); |
210 | for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { | 210 | for(uint iNext=iCur+1; iNext<lst.count(); iNext++ ) { |
211 | if( *current!=*lst.at(iNext) ) continue; | 211 | if( *current!=*lst.at(iNext) ) continue; |
212 | for(int i=2; ; i++) { | 212 | for(int i=2; ; i++) { |
213 | repl.sprintf("%s %d", (const char *)*current, i); | 213 | repl.sprintf("%s %d", (const char *)*current, i); |
214 | bool bDup=false; | 214 | bool bDup=false; |
215 | uint iChk=iNext+1; | 215 | uint iChk=iNext+1; |
216 | while( iChk<lst.count() ) { | 216 | while( iChk<lst.count() ) { |
217 | QString *chk=lst.at(iChk); | 217 | QString *chk=lst.at(iChk); |
218 | if( !chk->startsWith(*current) ) break; | 218 | if( !chk->startsWith(*current) ) break; |
219 | if( *chk==repl ) { | 219 | if( *chk==repl ) { |
220 | bDup=true; | 220 | bDup=true; |
221 | break; | 221 | break; |
222 | } | 222 | } |
223 | iChk++; | 223 | iChk++; |
224 | } | 224 | } |
225 | if( !bDup ) { | 225 | if( !bDup ) { |
226 | *lst.at(iNext)=repl; | 226 | *lst.at(iNext)=repl; |
227 | break; | 227 | break; |
228 | } | 228 | } |
229 | } | 229 | } |
230 | } | 230 | } |
231 | } | 231 | } |
232 | lst.sort(); | 232 | lst.sort(); |
233 | 233 | ||
234 | // copy back clean up col map | 234 | // copy back clean up col map |
235 | for(int i=0; i<_typeTable->childCount(); i++) { | 235 | for(int i=0; i<_typeTable->childCount(); i++) { |
236 | colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); | 236 | colMap[i]->getItem()->setText(iColumn, colMap[i]->getValue()); |
237 | delete colMap[i]; | 237 | delete colMap[i]; |
238 | } | 238 | } |
239 | delete colMap; | 239 | delete [] colMap; |
240 | } | 240 | } |
241 | 241 | ||
242 | void ListEdit::fixTypes() | 242 | void ListEdit::fixTypes() |
243 | { | 243 | { |
244 | int i; | 244 | int i; |
245 | ColumnDef *pDef; | 245 | ColumnDef *pDef; |
246 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { | 246 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { |
247 | if( pDef->hasFlag(ColumnDef::typeUnique) ) | 247 | if( pDef->hasFlag(ColumnDef::typeUnique) ) |
248 | fixTypes(i); | 248 | fixTypes(i); |
249 | } | 249 | } |
250 | _typeTable->sort(); | 250 | _typeTable->sort(); |
251 | } | 251 | } |
252 | 252 | ||
253 | 253 | ||
254 | // --- storeInList ------------------------------------------------------------ | 254 | // --- storeInList ------------------------------------------------------------ |
255 | void ListEdit::storeInList(QStringList &lst) | 255 | void ListEdit::storeInList(QStringList &lst) |
256 | { | 256 | { |
257 | // delete old content | 257 | // delete old content |
258 | lst.clear(); | 258 | lst.clear(); |
259 | 259 | ||
260 | // add new one | 260 | // add new one |
261 | fixTypes(); | 261 | fixTypes(); |
262 | QListViewItem *itm=_typeTable->firstChild(); | 262 | QListViewItem *itm=_typeTable->firstChild(); |
263 | while( itm ) { | 263 | while( itm ) { |
264 | int i=0; | 264 | int i=0; |
265 | QString sAdd; | 265 | QString sAdd; |
266 | ColumnDef *pDef; | 266 | ColumnDef *pDef; |
267 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { | 267 | for(pDef=this->first(), i=0; pDef; pDef=this->next(), i++) { |
268 | if( i>=1 ) sAdd+=";"; | 268 | if( i>=1 ) sAdd+=";"; |
269 | sAdd += itm->text(i); | 269 | sAdd += itm->text(i); |
270 | } | 270 | } |
271 | lst.append( sAdd ); | 271 | lst.append( sAdd ); |
272 | itm=itm->nextSibling(); | 272 | itm=itm->nextSibling(); |
273 | } | 273 | } |
274 | } | 274 | } |
275 | 275 | ||
276 | 276 | ||
277 | // --- slotClicked ------------------------------------------------------------ | 277 | // --- slotClicked ------------------------------------------------------------ |
278 | void ListEdit::slotClick(QListViewItem *itm, const QPoint &pnt, int col) | 278 | void ListEdit::slotClick(QListViewItem *itm, const QPoint &pnt, int col) |
279 | { | 279 | { |
280 | (void)pnt; // get rid of unused warning; | 280 | (void)pnt; // get rid of unused warning; |
281 | 281 | ||
282 | // save values | 282 | // save values |
283 | _currentItem=itm; | 283 | _currentItem=itm; |
284 | _currentColumn=col; | 284 | _currentColumn=col; |
285 | if( itm==NULL ) { | 285 | if( itm==NULL ) { |
286 | _typeEdit->setText(""); | 286 | _typeEdit->setText(""); |
287 | _stack->raiseWidget(_typeEdit); | 287 | _stack->raiseWidget(_typeEdit); |
288 | return; | 288 | return; |
289 | } | 289 | } |
290 | 290 | ||
291 | // display value | 291 | // display value |
292 | if( _currentColumn<0 ) _currentColumn=0; | 292 | if( _currentColumn<0 ) _currentColumn=0; |
293 | ColumnDef *pDef=this->at(_currentColumn); | 293 | ColumnDef *pDef=this->at(_currentColumn); |
294 | if( pDef->isType(ColumnDef::typeString) ) { | 294 | if( pDef->isType(ColumnDef::typeString) ) { |
295 | _typeEdit->setText( _currentItem->text(_currentColumn) ); | 295 | _typeEdit->setText( _currentItem->text(_currentColumn) ); |
296 | _stack->raiseWidget(_typeEdit); | 296 | _stack->raiseWidget(_typeEdit); |
297 | } else if( pDef->isType(ColumnDef::typeList) ){ | 297 | } else if( pDef->isType(ColumnDef::typeList) ){ |
298 | _box->clear(); | 298 | _box->clear(); |
299 | _box->insertStringList( pDef->getValueList() ); | 299 | _box->insertStringList( pDef->getValueList() ); |
300 | QStringList::Iterator itr; | 300 | QStringList::Iterator itr; |
301 | int i=0; | 301 | int i=0; |
302 | for(itr=pDef->getValueList().begin(); itr!=pDef->getValueList().end(); itr++) { | 302 | for(itr=pDef->getValueList().begin(); itr!=pDef->getValueList().end(); itr++) { |
303 | if( (*itr)==_currentItem->text(_currentColumn) ) { | 303 | if( (*itr)==_currentItem->text(_currentColumn) ) { |
304 | _box->setCurrentItem(i); | 304 | _box->setCurrentItem(i); |
305 | i=-1; | 305 | i=-1; |
306 | break; | 306 | break; |
307 | } | 307 | } |
308 | i++; | 308 | i++; |
309 | } | 309 | } |
310 | if( i>=0 ) { | 310 | if( i>=0 ) { |
311 | _box->insertItem( _currentItem->text(_currentColumn) ); | 311 | _box->insertItem( _currentItem->text(_currentColumn) ); |
312 | _box->setCurrentItem(i); | 312 | _box->setCurrentItem(i); |
313 | } | 313 | } |
314 | _stack->raiseWidget(_box); | 314 | _stack->raiseWidget(_box); |
315 | } else { | 315 | } else { |
316 | odebug << "Unsupported column type for column " << (const char *)pDef->getName() << "" << oendl; | 316 | odebug << "Unsupported column type for column " << (const char *)pDef->getName() << "" << oendl; |
317 | _typeEdit->setText(""); | 317 | _typeEdit->setText(""); |
318 | _stack->raiseWidget(_typeEdit); | 318 | _stack->raiseWidget(_typeEdit); |
319 | } | 319 | } |
320 | } | 320 | } |
321 | 321 | ||
322 | 322 | ||
323 | // --- addColumnDef ----------------------------------------------------------- | 323 | // --- addColumnDef ----------------------------------------------------------- |
324 | void ListEdit::addColumnDef(ColumnDef *pDef) | 324 | void ListEdit::addColumnDef(ColumnDef *pDef) |
325 | { | 325 | { |
326 | _typeTable->addColumn( pDef->getName() ); | 326 | _typeTable->addColumn( pDef->getName() ); |
327 | _vColumns.append(pDef); | 327 | _vColumns.append(pDef); |
328 | } | 328 | } |
329 | 329 | ||
330 | // --- addData ---------------------------------------------------------------- | 330 | // --- addData ---------------------------------------------------------------- |
331 | void ListEdit::addData(QStringList &lst) | 331 | void ListEdit::addData(QStringList &lst) |
332 | { | 332 | { |
333 | // run through list | 333 | // run through list |
334 | QStringList::Iterator itr; | 334 | QStringList::Iterator itr; |
335 | for(itr=lst.begin(); itr!=lst.end(); itr++) { | 335 | for(itr=lst.begin(); itr!=lst.end(); itr++) { |
diff --git a/noncore/apps/opie-console/TEScreen.cpp b/noncore/apps/opie-console/TEScreen.cpp index 2675d31..8e91532 100644 --- a/noncore/apps/opie-console/TEScreen.cpp +++ b/noncore/apps/opie-console/TEScreen.cpp | |||
@@ -1022,187 +1022,187 @@ QString TEScreen::getSelText(const BOOL preserve_line_breaks) | |||
1022 | s++; | 1022 | s++; |
1023 | } | 1023 | } |
1024 | 1024 | ||
1025 | if (s <= sel_BR) | 1025 | if (s <= sel_BR) |
1026 | { | 1026 | { |
1027 | // The line break handling | 1027 | // The line break handling |
1028 | // It's different from the screen | 1028 | // It's different from the screen |
1029 | // image case! | 1029 | // image case! |
1030 | if (eol % columns == 0) | 1030 | if (eol % columns == 0) |
1031 | { | 1031 | { |
1032 | // That's either a completely filled | 1032 | // That's either a completely filled |
1033 | // line or an empty line | 1033 | // line or an empty line |
1034 | if (eol == 0) | 1034 | if (eol == 0) |
1035 | { | 1035 | { |
1036 | m[d++] = '\n'; | 1036 | m[d++] = '\n'; |
1037 | } | 1037 | } |
1038 | else | 1038 | else |
1039 | { | 1039 | { |
1040 | // We have a full line. | 1040 | // We have a full line. |
1041 | // FIXME: How can we handle newlines | 1041 | // FIXME: How can we handle newlines |
1042 | // at this position?! | 1042 | // at this position?! |
1043 | } | 1043 | } |
1044 | } | 1044 | } |
1045 | else if ((eol + 1) % columns == 0) | 1045 | else if ((eol + 1) % columns == 0) |
1046 | { | 1046 | { |
1047 | // FIXME: We don't know if this was a | 1047 | // FIXME: We don't know if this was a |
1048 | // space at the last position or a | 1048 | // space at the last position or a |
1049 | // short line!! | 1049 | // short line!! |
1050 | m[d++] = ' '; | 1050 | m[d++] = ' '; |
1051 | } | 1051 | } |
1052 | else | 1052 | else |
1053 | { | 1053 | { |
1054 | // We have a short line here. Put a | 1054 | // We have a short line here. Put a |
1055 | // newline or a space into the | 1055 | // newline or a space into the |
1056 | // buffer. | 1056 | // buffer. |
1057 | m[d++] = preserve_line_breaks ? '\n' : ' '; | 1057 | m[d++] = preserve_line_breaks ? '\n' : ' '; |
1058 | } | 1058 | } |
1059 | } | 1059 | } |
1060 | 1060 | ||
1061 | hY++; | 1061 | hY++; |
1062 | hX = 0; | 1062 | hX = 0; |
1063 | s = hY * columns; | 1063 | s = hY * columns; |
1064 | } | 1064 | } |
1065 | else | 1065 | else |
1066 | { // or from screen image. | 1066 | { // or from screen image. |
1067 | eol = (s / columns + 1) * columns - 1; | 1067 | eol = (s / columns + 1) * columns - 1; |
1068 | 1068 | ||
1069 | if (eol < sel_BR) | 1069 | if (eol < sel_BR) |
1070 | { | 1070 | { |
1071 | while ((eol > s) && | 1071 | while ((eol > s) && |
1072 | isspace(image[eol - hist_BR].c)) | 1072 | isspace(image[eol - hist_BR].c)) |
1073 | { | 1073 | { |
1074 | eol--; | 1074 | eol--; |
1075 | } | 1075 | } |
1076 | } | 1076 | } |
1077 | else | 1077 | else |
1078 | { | 1078 | { |
1079 | eol = sel_BR; | 1079 | eol = sel_BR; |
1080 | } | 1080 | } |
1081 | 1081 | ||
1082 | while (s <= eol) | 1082 | while (s <= eol) |
1083 | { | 1083 | { |
1084 | m[d++] = image[s++ - hist_BR].c; | 1084 | m[d++] = image[s++ - hist_BR].c; |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | if (eol < sel_BR) | 1087 | if (eol < sel_BR) |
1088 | { | 1088 | { |
1089 | // eol processing see below ... | 1089 | // eol processing see below ... |
1090 | if ((eol + 1) % columns == 0) | 1090 | if ((eol + 1) % columns == 0) |
1091 | { | 1091 | { |
1092 | if (image[eol - hist_BR].c == ' ') | 1092 | if (image[eol - hist_BR].c == ' ') |
1093 | { | 1093 | { |
1094 | m[d++] = ' '; | 1094 | m[d++] = ' '; |
1095 | } | 1095 | } |
1096 | } | 1096 | } |
1097 | else | 1097 | else |
1098 | { | 1098 | { |
1099 | m[d++] = ((preserve_line_breaks || | 1099 | m[d++] = ((preserve_line_breaks || |
1100 | ((eol % columns) == 0)) ? | 1100 | ((eol % columns) == 0)) ? |
1101 | '\n' : ' '); | 1101 | '\n' : ' '); |
1102 | } | 1102 | } |
1103 | } | 1103 | } |
1104 | 1104 | ||
1105 | s = (eol / columns + 1) * columns; | 1105 | s = (eol / columns + 1) * columns; |
1106 | } | 1106 | } |
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | QChar* qc = new QChar[d]; | 1109 | QChar* qc = new QChar[d]; |
1110 | 1110 | ||
1111 | for (int i = 0; i < d; i++) | 1111 | for (int i = 0; i < d; i++) |
1112 | { | 1112 | { |
1113 | qc[i] = m[i]; | 1113 | qc[i] = m[i]; |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | QString res(qc, d); | 1116 | QString res(qc, d); |
1117 | 1117 | ||
1118 | delete m; | 1118 | delete [] m; |
1119 | delete qc; | 1119 | delete [] qc; |
1120 | 1120 | ||
1121 | return res; | 1121 | return res; |
1122 | } | 1122 | } |
1123 | QString TEScreen::getHistory() { | 1123 | QString TEScreen::getHistory() { |
1124 | sel_begin = 0; | 1124 | sel_begin = 0; |
1125 | sel_BR = sel_begin; | 1125 | sel_BR = sel_begin; |
1126 | sel_TL = sel_begin; | 1126 | sel_TL = sel_begin; |
1127 | setSelExtentXY(columns-1,lines-1); | 1127 | setSelExtentXY(columns-1,lines-1); |
1128 | QString tmp=getSelText(true); | 1128 | QString tmp=getSelText(true); |
1129 | while (tmp.at(tmp.length()-2).unicode()==10 && tmp.at(tmp.length()-1).unicode()==10) | 1129 | while (tmp.at(tmp.length()-2).unicode()==10 && tmp.at(tmp.length()-1).unicode()==10) |
1130 | tmp.truncate(tmp.length()-1); | 1130 | tmp.truncate(tmp.length()-1); |
1131 | 1131 | ||
1132 | return tmp; | 1132 | return tmp; |
1133 | } | 1133 | } |
1134 | /* above ... end of line processing for selection -- psilva | 1134 | /* above ... end of line processing for selection -- psilva |
1135 | cases: | 1135 | cases: |
1136 | 1136 | ||
1137 | 1) (eol+1)%columns == 0 --> the whole line is filled. | 1137 | 1) (eol+1)%columns == 0 --> the whole line is filled. |
1138 | If the last char is a space, insert (preserve) space. otherwise | 1138 | If the last char is a space, insert (preserve) space. otherwise |
1139 | leave the text alone, so that words that are broken by linewrap | 1139 | leave the text alone, so that words that are broken by linewrap |
1140 | are preserved. | 1140 | are preserved. |
1141 | 1141 | ||
1142 | FIXME: | 1142 | FIXME: |
1143 | * this suppresses \n for command output that is | 1143 | * this suppresses \n for command output that is |
1144 | sized to the exact column width of the screen. | 1144 | sized to the exact column width of the screen. |
1145 | 1145 | ||
1146 | 2) eol%columns == 0 --> blank line. | 1146 | 2) eol%columns == 0 --> blank line. |
1147 | insert a \n unconditionally. | 1147 | insert a \n unconditionally. |
1148 | Do it either you would because you are in preserve_line_break mode, | 1148 | Do it either you would because you are in preserve_line_break mode, |
1149 | or because it's an ASCII paragraph delimiter, so even when | 1149 | or because it's an ASCII paragraph delimiter, so even when |
1150 | not preserving line_breaks, you want to preserve paragraph breaks. | 1150 | not preserving line_breaks, you want to preserve paragraph breaks. |
1151 | 1151 | ||
1152 | 3) else --> partially filled line | 1152 | 3) else --> partially filled line |
1153 | insert a \n in preserve line break mode, else a space | 1153 | insert a \n in preserve line break mode, else a space |
1154 | The space prevents concatenation of the last word of one | 1154 | The space prevents concatenation of the last word of one |
1155 | line with the first of the next. | 1155 | line with the first of the next. |
1156 | 1156 | ||
1157 | */ | 1157 | */ |
1158 | 1158 | ||
1159 | void TEScreen::addHistLine() | 1159 | void TEScreen::addHistLine() |
1160 | { | 1160 | { |
1161 | assert(hasScroll() || histCursor == 0); | 1161 | assert(hasScroll() || histCursor == 0); |
1162 | 1162 | ||
1163 | // add to hist buffer | 1163 | // add to hist buffer |
1164 | // we have to take care about scrolling, too... | 1164 | // we have to take care about scrolling, too... |
1165 | 1165 | ||
1166 | if (hasScroll()) | 1166 | if (hasScroll()) |
1167 | { ca dft; | 1167 | { ca dft; |
1168 | 1168 | ||
1169 | int end = columns-1; | 1169 | int end = columns-1; |
1170 | while (end >= 0 && image[end] == dft) | 1170 | while (end >= 0 && image[end] == dft) |
1171 | end -= 1; | 1171 | end -= 1; |
1172 | 1172 | ||
1173 | hist.addCells(image,end+1); | 1173 | hist.addCells(image,end+1); |
1174 | hist.addLine(); | 1174 | hist.addLine(); |
1175 | 1175 | ||
1176 | // adjust history cursor | 1176 | // adjust history cursor |
1177 | histCursor += (hist.getLines()-1 == histCursor); | 1177 | histCursor += (hist.getLines()-1 == histCursor); |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround | 1180 | if (!hasScroll()) histCursor = 0; //FIXME: a poor workaround |
1181 | } | 1181 | } |
1182 | 1182 | ||
1183 | void TEScreen::setHistCursor(int cursor) | 1183 | void TEScreen::setHistCursor(int cursor) |
1184 | { | 1184 | { |
1185 | histCursor = cursor; //FIXME:rangecheck | 1185 | histCursor = cursor; //FIXME:rangecheck |
1186 | } | 1186 | } |
1187 | 1187 | ||
1188 | int TEScreen::getHistCursor() | 1188 | int TEScreen::getHistCursor() |
1189 | { | 1189 | { |
1190 | return histCursor; | 1190 | return histCursor; |
1191 | } | 1191 | } |
1192 | 1192 | ||
1193 | int TEScreen::getHistLines() | 1193 | int TEScreen::getHistLines() |
1194 | { | 1194 | { |
1195 | return hist.getLines(); | 1195 | return hist.getLines(); |
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | void TEScreen::setScroll(bool on) | 1198 | void TEScreen::setScroll(bool on) |
1199 | { | 1199 | { |
1200 | histCursor = 0; | 1200 | histCursor = 0; |
1201 | clearSelection(); | 1201 | clearSelection(); |
1202 | hist.setScroll(on); | 1202 | hist.setScroll(on); |
1203 | } | 1203 | } |
1204 | 1204 | ||
1205 | bool TEScreen::hasScroll() | 1205 | bool TEScreen::hasScroll() |
1206 | { | 1206 | { |
1207 | return hist.hasScroll(); | 1207 | return hist.hasScroll(); |
1208 | } | 1208 | } |
diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp index 338bc30..51fe707 100644 --- a/noncore/apps/opie-sheet/Excel.cpp +++ b/noncore/apps/opie-sheet/Excel.cpp | |||
@@ -245,193 +245,193 @@ void ExcelBook::SeekPosition(int pos) | |||
245 | { | 245 | { |
246 | if(!feof(File)) | 246 | if(!feof(File)) |
247 | { | 247 | { |
248 | Position=pos; | 248 | Position=pos; |
249 | //printf("SeekPosition:Pos:%d\r\n",Position); | 249 | //printf("SeekPosition:Pos:%d\r\n",Position); |
250 | fseek(File,pos,SEEK_SET); | 250 | fseek(File,pos,SEEK_SET); |
251 | }; | 251 | }; |
252 | }; | 252 | }; |
253 | 253 | ||
254 | void ExcelBook::SeekSkip(int pos) | 254 | void ExcelBook::SeekSkip(int pos) |
255 | { | 255 | { |
256 | if(!feof(File)) | 256 | if(!feof(File)) |
257 | { | 257 | { |
258 | Position=Position+pos; | 258 | Position=Position+pos; |
259 | //printf("SeekSkip:Pos:%d\r\n",Position); | 259 | //printf("SeekSkip:Pos:%d\r\n",Position); |
260 | fseek(File, Position, SEEK_SET); | 260 | fseek(File, Position, SEEK_SET); |
261 | }; | 261 | }; |
262 | }; | 262 | }; |
263 | 263 | ||
264 | int ExcelBook::FileEOF(void) | 264 | int ExcelBook::FileEOF(void) |
265 | { | 265 | { |
266 | if(File!=NULL) return(feof(File)); else return 0; | 266 | if(File!=NULL) return(feof(File)); else return 0; |
267 | //EOF is defined in stdlib as -1 | 267 | //EOF is defined in stdlib as -1 |
268 | }; | 268 | }; |
269 | 269 | ||
270 | int ExcelBook::Get2Bytes(void) | 270 | int ExcelBook::Get2Bytes(void) |
271 | { | 271 | { |
272 | int i1,i2; | 272 | int i1,i2; |
273 | i1=0; i2=0; | 273 | i1=0; i2=0; |
274 | if (!feof(File)) | 274 | if (!feof(File)) |
275 | { | 275 | { |
276 | i1=fgetc(File); | 276 | i1=fgetc(File); |
277 | Position++; | 277 | Position++; |
278 | }; | 278 | }; |
279 | if (!feof(File)) | 279 | if (!feof(File)) |
280 | { | 280 | { |
281 | i2=fgetc(File); | 281 | i2=fgetc(File); |
282 | Position++; | 282 | Position++; |
283 | }; | 283 | }; |
284 | return Integer2Byte(i1,i2); | 284 | return Integer2Byte(i1,i2); |
285 | }; | 285 | }; |
286 | 286 | ||
287 | char* ExcelBook::Read(int pos, int length) | 287 | char* ExcelBook::Read(int pos, int length) |
288 | { | 288 | { |
289 | int i; | 289 | int i; |
290 | char *data; | 290 | char *data; |
291 | data= new char[length]; | 291 | data= new char[length]; |
292 | SeekPosition(pos); | 292 | SeekPosition(pos); |
293 | for(i=0; i<length; i++) | 293 | for(i=0; i<length; i++) |
294 | { | 294 | { |
295 | if(!feof(File)) data[i]=fgetc(File); | 295 | if(!feof(File)) data[i]=fgetc(File); |
296 | }; | 296 | }; |
297 | Position= Position+length; | 297 | Position= Position+length; |
298 | return data; | 298 | return data; |
299 | }; | 299 | }; |
300 | 300 | ||
301 | QString ExcelBook::ReadUnicodeChar(int pos, int length) | 301 | QString ExcelBook::ReadUnicodeChar(int pos, int length) |
302 | { | 302 | { |
303 | int i; | 303 | int i; |
304 | QString data; | 304 | QString data; |
305 | int i1=' ',i2=' ',ii; | 305 | int i1=' ',i2=' ',ii; |
306 | SeekPosition(pos); | 306 | SeekPosition(pos); |
307 | for(i=0; i<length; i++) | 307 | for(i=0; i<length; i++) |
308 | { | 308 | { |
309 | if(!feof(File)) i1=fgetc(File); | 309 | if(!feof(File)) i1=fgetc(File); |
310 | if(!feof(File)) i2=fgetc(File); | 310 | if(!feof(File)) i2=fgetc(File); |
311 | ii=Integer2Byte(i1,i2); | 311 | ii=Integer2Byte(i1,i2); |
312 | data.append(ii); | 312 | data.append(ii); |
313 | Position+=2; | 313 | Position+=2; |
314 | }; | 314 | }; |
315 | return data; | 315 | return data; |
316 | }; | 316 | }; |
317 | 317 | ||
318 | QString* ExcelBook::GetString(int num) | 318 | QString* ExcelBook::GetString(int num) |
319 | { | 319 | { |
320 | if(num>=0 && num<(int)SharedStrings.count()) | 320 | if(num>=0 && num<(int)SharedStrings.count()) |
321 | { | 321 | { |
322 | return SharedStrings[num]; | 322 | return SharedStrings[num]; |
323 | }; | 323 | }; |
324 | return new QString(""); | 324 | return new QString(""); |
325 | }; | 325 | }; |
326 | 326 | ||
327 | int ExcelBook::SeekBOF(void) | 327 | int ExcelBook::SeekBOF(void) |
328 | { | 328 | { |
329 | int opcode,version,streamtype,length,ret=0; | 329 | int opcode,version,streamtype,length,ret=0; |
330 | char *data; | 330 | char *data; |
331 | while(!feof(File)) | 331 | while(!feof(File)) |
332 | { | 332 | { |
333 | opcode=Get2Bytes(); | 333 | opcode=Get2Bytes(); |
334 | if(opcode==XL_BOF) | 334 | if(opcode==XL_BOF) |
335 | { | 335 | { |
336 | length=Get2Bytes(); | 336 | length=Get2Bytes(); |
337 | data=Read(Position,length); | 337 | data=Read(Position,length); |
338 | version=Integer2Byte(data[0], data[1]); | 338 | version=Integer2Byte(data[0], data[1]); |
339 | streamtype=Integer2Byte(data[2], data[3]); | 339 | streamtype=Integer2Byte(data[2], data[3]); |
340 | printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version); | 340 | printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version); |
341 | delete data; data=NULL; | 341 | delete [] data; data=NULL; |
342 | if (version==BIFF8) ret=8; | 342 | if (version==BIFF8) ret=8; |
343 | else if(version==BIFF7) ret=7; | 343 | else if(version==BIFF7) ret=7; |
344 | printf("SEEKBOF:versionBIFF%d\r\n",ret); | 344 | printf("SEEKBOF:versionBIFF%d\r\n",ret); |
345 | if(streamtype==WBKGLOBAL) return ret *2; | 345 | if(streamtype==WBKGLOBAL) return ret *2; |
346 | else if(streamtype==WRKSHEET) return ret *1; | 346 | else if(streamtype==WRKSHEET) return ret *1; |
347 | return 1; | 347 | return 1; |
348 | }; | 348 | }; |
349 | }; | 349 | }; |
350 | return 0; | 350 | return 0; |
351 | }; | 351 | }; |
352 | 352 | ||
353 | ExcelBREC* ExcelBook::GetBREC(void) | 353 | ExcelBREC* ExcelBook::GetBREC(void) |
354 | { | 354 | { |
355 | ExcelBREC* rec; | 355 | ExcelBREC* rec; |
356 | rec= new ExcelBREC; | 356 | rec= new ExcelBREC; |
357 | if(FileEOF()) return NULL; | 357 | if(FileEOF()) return NULL; |
358 | rec->data=NULL; | 358 | rec->data=NULL; |
359 | rec->code=Get2Bytes(); | 359 | rec->code=Get2Bytes(); |
360 | rec->length=Get2Bytes(); | 360 | rec->length=Get2Bytes(); |
361 | rec->position=Position; | 361 | rec->position=Position; |
362 | SeekSkip(rec->length); | 362 | SeekSkip(rec->length); |
363 | return rec; | 363 | return rec; |
364 | }; | 364 | }; |
365 | 365 | ||
366 | ExcelBREC* ExcelBook::PeekBREC(void) | 366 | ExcelBREC* ExcelBook::PeekBREC(void) |
367 | { | 367 | { |
368 | int oldpos; | 368 | int oldpos; |
369 | ExcelBREC* NextRec; | 369 | ExcelBREC* NextRec; |
370 | oldpos=Position; | 370 | oldpos=Position; |
371 | NextRec=GetBREC(); | 371 | NextRec=GetBREC(); |
372 | SeekPosition(oldpos); | 372 | SeekPosition(oldpos); |
373 | return NextRec; | 373 | return NextRec; |
374 | }; | 374 | }; |
375 | 375 | ||
376 | char* ExcelBook::GetDataOfBREC(ExcelBREC* record) | 376 | char* ExcelBook::GetDataOfBREC(ExcelBREC* record) |
377 | { | 377 | { |
378 | if(record->data==NULL) | 378 | if(record->data==NULL) |
379 | { | 379 | { |
380 | ConvertCharToArray(record,Read(record->position,record->length),record->length); | 380 | ConvertCharToArray(record,Read(record->position,record->length),record->length); |
381 | }; | 381 | }; |
382 | return record->data;//new? | 382 | return record->data;//new? |
383 | }; | 383 | }; |
384 | 384 | ||
385 | void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) | 385 | void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) |
386 | { | 386 | { |
387 | record->data=new char[length]; | 387 | record->data=new char[length]; |
388 | for(int w1=0;w1<=length-1;w1++) | 388 | for(int w1=0;w1<=length-1;w1++) |
389 | record->data[w1]=chars[w1]; | 389 | record->data[w1]=chars[w1]; |
390 | }; | 390 | }; |
391 | 391 | ||
392 | 392 | ||
393 | bool ExcelSheet::InitCells() | 393 | bool ExcelSheet::InitCells() |
394 | { | 394 | { |
395 | int r; | 395 | int r; |
396 | Cells.resize(rows * cols + cols+1); | 396 | Cells.resize(rows * cols + cols+1); |
397 | if(Cells.count()==0) return false; | 397 | if(Cells.count()==0) return false; |
398 | for(r=0;r < Cells.count();r++) | 398 | for(r=0;r < Cells.count();r++) |
399 | { | 399 | { |
400 | Cells[r]=NULL; | 400 | Cells[r]=NULL; |
401 | }; | 401 | }; |
402 | return true; | 402 | return true; |
403 | }; | 403 | }; |
404 | 404 | ||
405 | void ExcelSheet::Set(int row, int col, ExcelCell* cell) | 405 | void ExcelSheet::Set(int row, int col, ExcelCell* cell) |
406 | { | 406 | { |
407 | if(cell!=NULL&&(row*cols+col)<Cells.count()) | 407 | if(cell!=NULL&&(row*cols+col)<Cells.count()) |
408 | { | 408 | { |
409 | Cells[row*cols+col]=cell; | 409 | Cells[row*cols+col]=cell; |
410 | }; | 410 | }; |
411 | }; | 411 | }; |
412 | 412 | ||
413 | ExcelCell* ExcelSheet::Get(int row, int col) | 413 | ExcelCell* ExcelSheet::Get(int row, int col) |
414 | { | 414 | { |
415 | ExcelCell* cell; | 415 | ExcelCell* cell; |
416 | cell=Cells[row*cols+col]; | 416 | cell=Cells[row*cols+col]; |
417 | if(cell==NULL) return NULL; | 417 | if(cell==NULL) return NULL; |
418 | return cell; | 418 | return cell; |
419 | }; | 419 | }; |
420 | 420 | ||
421 | int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) | 421 | int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) |
422 | { | 422 | { |
423 | char* data=NULL; | 423 | char* data=NULL; |
424 | switch (record->code) | 424 | switch (record->code) |
425 | { | 425 | { |
426 | case XL_DIMENSION: | 426 | case XL_DIMENSION: |
427 | data = GetDataOfBREC(record); | 427 | data = GetDataOfBREC(record); |
428 | if (record->length == 10) | 428 | if (record->length == 10) |
429 | { | 429 | { |
430 | sheet->rows = Integer2Byte(data[2], data[3]); | 430 | sheet->rows = Integer2Byte(data[2], data[3]); |
431 | sheet->cols = Integer2Byte(data[6], data[7]); | 431 | sheet->cols = Integer2Byte(data[6], data[7]); |
432 | } | 432 | } |
433 | else | 433 | else |
434 | { | 434 | { |
435 | sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); | 435 | sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); |
436 | sheet->cols = Integer2Byte(data[10], data[11]); | 436 | sheet->cols = Integer2Byte(data[10], data[11]); |
437 | } | 437 | } |
diff --git a/noncore/apps/tinykate/libkate/document/katedocument.cpp b/noncore/apps/tinykate/libkate/document/katedocument.cpp index 6dc4fd2..a70f3aa 100644 --- a/noncore/apps/tinykate/libkate/document/katedocument.cpp +++ b/noncore/apps/tinykate/libkate/document/katedocument.cpp | |||
@@ -2126,254 +2126,254 @@ void KateDocument::paintTextLine(QPainter &paint, int line, int y, int xStart, i | |||
2126 | attr = nextAttr; | 2126 | attr = nextAttr; |
2127 | a = &m_attribs[attr & taAttrMask]; | 2127 | a = &m_attribs[attr & taAttrMask]; |
2128 | 2128 | ||
2129 | if (attr & taSelected) paint.setPen(a->selCol); | 2129 | if (attr & taSelected) paint.setPen(a->selCol); |
2130 | else paint.setPen(a->col); | 2130 | else paint.setPen(a->col); |
2131 | 2131 | ||
2132 | if (a->bold && a->italic) | 2132 | if (a->bold && a->italic) |
2133 | paint.setFont(myFontBI); | 2133 | paint.setFont(myFontBI); |
2134 | else if (a->bold) | 2134 | else if (a->bold) |
2135 | paint.setFont(myFontBold); | 2135 | paint.setFont(myFontBold); |
2136 | else if (a->italic) | 2136 | else if (a->italic) |
2137 | paint.setFont(myFontItalic); | 2137 | paint.setFont(myFontItalic); |
2138 | else | 2138 | else |
2139 | paint.setFont(myFont); | 2139 | paint.setFont(myFont); |
2140 | } | 2140 | } |
2141 | 2141 | ||
2142 | // paint.drawLine(x - xStart, y -2, x - xStart, y); | 2142 | // paint.drawLine(x - xStart, y -2, x - xStart, y); |
2143 | // paint.drawLine(x - xStart, y, x - xStart + 2, y); | 2143 | // paint.drawLine(x - xStart, y, x - xStart + 2, y); |
2144 | paint.drawPoint(x - xStart, y); | 2144 | paint.drawPoint(x - xStart, y); |
2145 | paint.drawPoint(x - xStart +1, y); | 2145 | paint.drawPoint(x - xStart +1, y); |
2146 | paint.drawPoint(x - xStart, y -1); | 2146 | paint.drawPoint(x - xStart, y -1); |
2147 | } | 2147 | } |
2148 | x += m_tabWidth - (x % m_tabWidth); | 2148 | x += m_tabWidth - (x % m_tabWidth); |
2149 | } else { | 2149 | } else { |
2150 | nextAttr = textLine->getRawAttr(z); | 2150 | nextAttr = textLine->getRawAttr(z); |
2151 | if (nextAttr != attr) { | 2151 | if (nextAttr != attr) { |
2152 | if (z > zc) { | 2152 | if (z > zc) { |
2153 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2153 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2154 | QString s = str.string(); | 2154 | QString s = str.string(); |
2155 | paint.drawText(x - xStart, y, s); | 2155 | paint.drawText(x - xStart, y, s); |
2156 | 2156 | ||
2157 | if (a->bold && a->italic) | 2157 | if (a->bold && a->italic) |
2158 | x += myFontMetricsBI.width(s); | 2158 | x += myFontMetricsBI.width(s); |
2159 | else if (a->bold) | 2159 | else if (a->bold) |
2160 | x += myFontMetricsBold.width(s); | 2160 | x += myFontMetricsBold.width(s); |
2161 | else if (a->italic) | 2161 | else if (a->italic) |
2162 | x += myFontMetricsItalic.width(s); | 2162 | x += myFontMetricsItalic.width(s); |
2163 | else | 2163 | else |
2164 | x += myFontMetrics.width(s); | 2164 | x += myFontMetrics.width(s); |
2165 | zc = z; | 2165 | zc = z; |
2166 | } | 2166 | } |
2167 | attr = nextAttr; | 2167 | attr = nextAttr; |
2168 | a = &m_attribs[attr & taAttrMask]; | 2168 | a = &m_attribs[attr & taAttrMask]; |
2169 | 2169 | ||
2170 | if (attr & taSelected) paint.setPen(a->selCol); | 2170 | if (attr & taSelected) paint.setPen(a->selCol); |
2171 | else paint.setPen(a->col); | 2171 | else paint.setPen(a->col); |
2172 | 2172 | ||
2173 | if (a->bold && a->italic) | 2173 | if (a->bold && a->italic) |
2174 | paint.setFont(myFontBI); | 2174 | paint.setFont(myFontBI); |
2175 | else if (a->bold) | 2175 | else if (a->bold) |
2176 | paint.setFont(myFontBold); | 2176 | paint.setFont(myFontBold); |
2177 | else if (a->italic) | 2177 | else if (a->italic) |
2178 | paint.setFont(myFontItalic); | 2178 | paint.setFont(myFontItalic); |
2179 | else | 2179 | else |
2180 | paint.setFont(myFont); | 2180 | paint.setFont(myFont); |
2181 | } | 2181 | } |
2182 | } | 2182 | } |
2183 | z++; | 2183 | z++; |
2184 | } | 2184 | } |
2185 | if (z > zc) { | 2185 | if (z > zc) { |
2186 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); | 2186 | QConstString str((QChar *) &s[zc], z - zc /*+1*/); |
2187 | paint.drawText(x - xStart, y, str.string()); | 2187 | paint.drawText(x - xStart, y, str.string()); |
2188 | } | 2188 | } |
2189 | } | 2189 | } |
2190 | 2190 | ||
2191 | // Applies the search context, and returns whether a match was found. If one is, | 2191 | // Applies the search context, and returns whether a match was found. If one is, |
2192 | // the length of the string matched is also returned. | 2192 | // the length of the string matched is also returned. |
2193 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { | 2193 | bool KateDocument::doSearch(SConfig &sc, const QString &searchFor) { |
2194 | int line, col; | 2194 | int line, col; |
2195 | int searchEnd; | 2195 | int searchEnd; |
2196 | int bufLen, tlen; | 2196 | int bufLen, tlen; |
2197 | QChar *t; | 2197 | QChar *t; |
2198 | TextLine::Ptr textLine; | 2198 | TextLine::Ptr textLine; |
2199 | int pos, newPos; | 2199 | int pos, newPos; |
2200 | 2200 | ||
2201 | if (searchFor.isEmpty()) return false; | 2201 | if (searchFor.isEmpty()) return false; |
2202 | 2202 | ||
2203 | bufLen = 0; | 2203 | bufLen = 0; |
2204 | t = 0L; | 2204 | t = 0L; |
2205 | 2205 | ||
2206 | line = sc.cursor.y; | 2206 | line = sc.cursor.y; |
2207 | col = sc.cursor.x; | 2207 | col = sc.cursor.x; |
2208 | if (!(sc.flags & KateView::sfBackward)) { | 2208 | if (!(sc.flags & KateView::sfBackward)) { |
2209 | //forward search | 2209 | //forward search |
2210 | if (sc.flags & KateView::sfSelected) { | 2210 | if (sc.flags & KateView::sfSelected) { |
2211 | if (line < selectStart) { | 2211 | if (line < selectStart) { |
2212 | line = selectStart; | 2212 | line = selectStart; |
2213 | col = 0; | 2213 | col = 0; |
2214 | } | 2214 | } |
2215 | searchEnd = selectEnd; | 2215 | searchEnd = selectEnd; |
2216 | } else searchEnd = lastLine(); | 2216 | } else searchEnd = lastLine(); |
2217 | 2217 | ||
2218 | while (line <= searchEnd) { | 2218 | while (line <= searchEnd) { |
2219 | textLine = getTextLine(line); | 2219 | textLine = getTextLine(line); |
2220 | tlen = textLine->length(); | 2220 | tlen = textLine->length(); |
2221 | if (tlen > bufLen) { | 2221 | if (tlen > bufLen) { |
2222 | delete t; | 2222 | delete [] t; |
2223 | bufLen = (tlen + 255) & (~255); | 2223 | bufLen = (tlen + 255) & (~255); |
2224 | t = new QChar[bufLen]; | 2224 | t = new QChar[bufLen]; |
2225 | } | 2225 | } |
2226 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2226 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2227 | if (sc.flags & KateView::sfSelected) { | 2227 | if (sc.flags & KateView::sfSelected) { |
2228 | pos = 0; | 2228 | pos = 0; |
2229 | do { | 2229 | do { |
2230 | pos = textLine->findSelected(pos); | 2230 | pos = textLine->findSelected(pos); |
2231 | newPos = textLine->findUnselected(pos); | 2231 | newPos = textLine->findUnselected(pos); |
2232 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2232 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2233 | pos = newPos; | 2233 | pos = newPos; |
2234 | } while (pos < tlen); | 2234 | } while (pos < tlen); |
2235 | } | 2235 | } |
2236 | 2236 | ||
2237 | QString text(t, tlen); | 2237 | QString text(t, tlen); |
2238 | if (sc.flags & KateView::sfWholeWords) { | 2238 | if (sc.flags & KateView::sfWholeWords) { |
2239 | // Until the end of the line... | 2239 | // Until the end of the line... |
2240 | while (col < tlen) { | 2240 | while (col < tlen) { |
2241 | // ...find the next match. | 2241 | // ...find the next match. |
2242 | col = sc.search(text, col); | 2242 | col = sc.search(text, col); |
2243 | if (col != -1) { | 2243 | if (col != -1) { |
2244 | // Is the match delimited correctly? | 2244 | // Is the match delimited correctly? |
2245 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2245 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2246 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2246 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2247 | goto found; | 2247 | goto found; |
2248 | } | 2248 | } |
2249 | else { | 2249 | else { |
2250 | // Start again from the next character. | 2250 | // Start again from the next character. |
2251 | col++; | 2251 | col++; |
2252 | } | 2252 | } |
2253 | } | 2253 | } |
2254 | else { | 2254 | else { |
2255 | // No match. | 2255 | // No match. |
2256 | break; | 2256 | break; |
2257 | } | 2257 | } |
2258 | } | 2258 | } |
2259 | } | 2259 | } |
2260 | else { | 2260 | else { |
2261 | // Non-whole-word search. | 2261 | // Non-whole-word search. |
2262 | col = sc.search(text, col); | 2262 | col = sc.search(text, col); |
2263 | if (col != -1) | 2263 | if (col != -1) |
2264 | goto found; | 2264 | goto found; |
2265 | } | 2265 | } |
2266 | col = 0; | 2266 | col = 0; |
2267 | line++; | 2267 | line++; |
2268 | } | 2268 | } |
2269 | } else { | 2269 | } else { |
2270 | // backward search | 2270 | // backward search |
2271 | if (sc.flags & KateView::sfSelected) { | 2271 | if (sc.flags & KateView::sfSelected) { |
2272 | if (line > selectEnd) { | 2272 | if (line > selectEnd) { |
2273 | line = selectEnd; | 2273 | line = selectEnd; |
2274 | col = -1; | 2274 | col = -1; |
2275 | } | 2275 | } |
2276 | searchEnd = selectStart; | 2276 | searchEnd = selectStart; |
2277 | } else searchEnd = 0; | 2277 | } else searchEnd = 0; |
2278 | 2278 | ||
2279 | while (line >= searchEnd) { | 2279 | while (line >= searchEnd) { |
2280 | textLine = getTextLine(line); | 2280 | textLine = getTextLine(line); |
2281 | tlen = textLine->length(); | 2281 | tlen = textLine->length(); |
2282 | if (tlen > bufLen) { | 2282 | if (tlen > bufLen) { |
2283 | delete t; | 2283 | delete [] t; |
2284 | bufLen = (tlen + 255) & (~255); | 2284 | bufLen = (tlen + 255) & (~255); |
2285 | t = new QChar[bufLen]; | 2285 | t = new QChar[bufLen]; |
2286 | } | 2286 | } |
2287 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); | 2287 | memcpy(t, textLine->getText(), tlen*sizeof(QChar)); |
2288 | if (sc.flags & KateView::sfSelected) { | 2288 | if (sc.flags & KateView::sfSelected) { |
2289 | pos = 0; | 2289 | pos = 0; |
2290 | do { | 2290 | do { |
2291 | pos = textLine->findSelected(pos); | 2291 | pos = textLine->findSelected(pos); |
2292 | newPos = textLine->findUnselected(pos); | 2292 | newPos = textLine->findUnselected(pos); |
2293 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); | 2293 | memset(&t[pos], 0, (newPos - pos)*sizeof(QChar)); |
2294 | pos = newPos; | 2294 | pos = newPos; |
2295 | } while (pos < tlen); | 2295 | } while (pos < tlen); |
2296 | } | 2296 | } |
2297 | 2297 | ||
2298 | if (col < 0 || col > tlen) col = tlen; | 2298 | if (col < 0 || col > tlen) col = tlen; |
2299 | 2299 | ||
2300 | QString text(t, tlen); | 2300 | QString text(t, tlen); |
2301 | if (sc.flags & KateView::sfWholeWords) { | 2301 | if (sc.flags & KateView::sfWholeWords) { |
2302 | // Until the beginning of the line... | 2302 | // Until the beginning of the line... |
2303 | while (col >= 0) { | 2303 | while (col >= 0) { |
2304 | // ...find the next match. | 2304 | // ...find the next match. |
2305 | col = sc.search(text, col); | 2305 | col = sc.search(text, col); |
2306 | if (col != -1) { | 2306 | if (col != -1) { |
2307 | // Is the match delimited correctly? | 2307 | // Is the match delimited correctly? |
2308 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && | 2308 | if (((col == 0) || (!m_highlight->isInWord(t[col]))) && |
2309 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { | 2309 | ((col + sc.matchedLength == tlen) || (!m_highlight->isInWord(t[col + sc.matchedLength])))) { |
2310 | goto found; | 2310 | goto found; |
2311 | } | 2311 | } |
2312 | else { | 2312 | else { |
2313 | // Start again from the previous character. | 2313 | // Start again from the previous character. |
2314 | col--; | 2314 | col--; |
2315 | } | 2315 | } |
2316 | } | 2316 | } |
2317 | else { | 2317 | else { |
2318 | // No match. | 2318 | // No match. |
2319 | break; | 2319 | break; |
2320 | } | 2320 | } |
2321 | } | 2321 | } |
2322 | } | 2322 | } |
2323 | else { | 2323 | else { |
2324 | // Non-whole-word search. | 2324 | // Non-whole-word search. |
2325 | col = sc.search(text, col); | 2325 | col = sc.search(text, col); |
2326 | if (col != -1) | 2326 | if (col != -1) |
2327 | goto found; | 2327 | goto found; |
2328 | } | 2328 | } |
2329 | col = -1; | 2329 | col = -1; |
2330 | line--; | 2330 | line--; |
2331 | } | 2331 | } |
2332 | } | 2332 | } |
2333 | sc.flags |= KateView::sfWrapped; | 2333 | sc.flags |= KateView::sfWrapped; |
2334 | return false; | 2334 | return false; |
2335 | found: | 2335 | found: |
2336 | if (sc.flags & KateView::sfWrapped) { | 2336 | if (sc.flags & KateView::sfWrapped) { |
2337 | if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) | 2337 | if ((line > sc.startCursor.y || (line == sc.startCursor.y && col >= sc.startCursor.x)) |
2338 | ^ ((sc.flags & KateView::sfBackward) != 0)) return false; | 2338 | ^ ((sc.flags & KateView::sfBackward) != 0)) return false; |
2339 | } | 2339 | } |
2340 | sc.cursor.x = col; | 2340 | sc.cursor.x = col; |
2341 | sc.cursor.y = line; | 2341 | sc.cursor.y = line; |
2342 | return true; | 2342 | return true; |
2343 | } | 2343 | } |
2344 | 2344 | ||
2345 | void KateDocument::tagLine(int line) { | 2345 | void KateDocument::tagLine(int line) { |
2346 | 2346 | ||
2347 | if (tagStart > line) tagStart = line; | 2347 | if (tagStart > line) tagStart = line; |
2348 | if (tagEnd < line) tagEnd = line; | 2348 | if (tagEnd < line) tagEnd = line; |
2349 | } | 2349 | } |
2350 | 2350 | ||
2351 | void KateDocument::insLine(int line) { | 2351 | void KateDocument::insLine(int line) { |
2352 | KateView *view; | 2352 | KateView *view; |
2353 | 2353 | ||
2354 | if (selectStart >= line) selectStart++; | 2354 | if (selectStart >= line) selectStart++; |
2355 | if (selectEnd >= line) selectEnd++; | 2355 | if (selectEnd >= line) selectEnd++; |
2356 | if (tagStart >= line) tagStart++; | 2356 | if (tagStart >= line) tagStart++; |
2357 | if (tagEnd >= line) tagEnd++; | 2357 | if (tagEnd >= line) tagEnd++; |
2358 | 2358 | ||
2359 | newDocGeometry = true; | 2359 | newDocGeometry = true; |
2360 | for (view = views.first(); view != 0L; view = views.next() ) { | 2360 | for (view = views.first(); view != 0L; view = views.next() ) { |
2361 | view->insLine(line); | 2361 | view->insLine(line); |
2362 | } | 2362 | } |
2363 | } | 2363 | } |
2364 | 2364 | ||
2365 | void KateDocument::delLine(int line) { | 2365 | void KateDocument::delLine(int line) { |
2366 | KateView *view; | 2366 | KateView *view; |
2367 | 2367 | ||
2368 | if (selectStart >= line && selectStart > 0) selectStart--; | 2368 | if (selectStart >= line && selectStart > 0) selectStart--; |
2369 | if (selectEnd >= line) selectEnd--; | 2369 | if (selectEnd >= line) selectEnd--; |
2370 | if (tagStart >= line && tagStart > 0) tagStart--; | 2370 | if (tagStart >= line && tagStart > 0) tagStart--; |
2371 | if (tagEnd >= line) tagEnd--; | 2371 | if (tagEnd >= line) tagEnd--; |
2372 | 2372 | ||
2373 | newDocGeometry = true; | 2373 | newDocGeometry = true; |
2374 | for (view = views.first(); view != 0L; view = views.next() ) { | 2374 | for (view = views.first(); view != 0L; view = views.next() ) { |
2375 | view->delLine(line); | 2375 | view->delLine(line); |
2376 | } | 2376 | } |
2377 | } | 2377 | } |
2378 | 2378 | ||
2379 | void KateDocument::optimizeSelection() { | 2379 | void KateDocument::optimizeSelection() { |
diff --git a/noncore/comm/keypebble/krfbdecoder.cpp b/noncore/comm/keypebble/krfbdecoder.cpp index 837fcc5..27ae101 100644 --- a/noncore/comm/keypebble/krfbdecoder.cpp +++ b/noncore/comm/keypebble/krfbdecoder.cpp | |||
@@ -132,193 +132,193 @@ KRFBDecoder::~KRFBDecoder() | |||
132 | 132 | ||
133 | void KRFBDecoder::start() | 133 | void KRFBDecoder::start() |
134 | { | 134 | { |
135 | sendClientInit(); | 135 | sendClientInit(); |
136 | } | 136 | } |
137 | 137 | ||
138 | void KRFBDecoder::sendClientInit() | 138 | void KRFBDecoder::sendClientInit() |
139 | { | 139 | { |
140 | con->write( &( con->options()->shared ), 1 ); | 140 | con->write( &( con->options()->shared ), 1 ); |
141 | 141 | ||
142 | // Wait for server init | 142 | // Wait for server init |
143 | owarn << "Waiting for server init" << oendl; | 143 | owarn << "Waiting for server init" << oendl; |
144 | 144 | ||
145 | static QString statusMsg = tr( "Waiting for server initialization..." ); | 145 | static QString statusMsg = tr( "Waiting for server initialization..." ); |
146 | emit status( statusMsg ); | 146 | emit status( statusMsg ); |
147 | 147 | ||
148 | currentState = AwaitingServerInit; | 148 | currentState = AwaitingServerInit; |
149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); | 149 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerInit() ) ); |
150 | con->waitForData( ServerInitLength ); | 150 | con->waitForData( ServerInitLength ); |
151 | } | 151 | } |
152 | 152 | ||
153 | void KRFBDecoder::gotServerInit() | 153 | void KRFBDecoder::gotServerInit() |
154 | { | 154 | { |
155 | owarn << "Got server init" << oendl; | 155 | owarn << "Got server init" << oendl; |
156 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); | 156 | disconnect( con, SIGNAL( gotEnoughData() ), this, SLOT( gotServerInit() ) ); |
157 | 157 | ||
158 | if ( info ) | 158 | if ( info ) |
159 | delete info; | 159 | delete info; |
160 | info = new KRFBServerInfo; | 160 | info = new KRFBServerInfo; |
161 | CHECK_PTR( info ); | 161 | CHECK_PTR( info ); |
162 | 162 | ||
163 | con->read( &(info->width), 2 ); | 163 | con->read( &(info->width), 2 ); |
164 | info->width = Swap16IfLE( info->width ); | 164 | info->width = Swap16IfLE( info->width ); |
165 | con->read( &info->height, 2 ); | 165 | con->read( &info->height, 2 ); |
166 | info->height = Swap16IfLE( info->height ); | 166 | info->height = Swap16IfLE( info->height ); |
167 | 167 | ||
168 | con->read( &(info->bpp), 1 ); | 168 | con->read( &(info->bpp), 1 ); |
169 | con->read( &(info->depth), 1 ); | 169 | con->read( &(info->depth), 1 ); |
170 | con->read( &(info->bigEndian), 1 ); | 170 | con->read( &(info->bigEndian), 1 ); |
171 | con->read( &(info->trueColor), 1 ); | 171 | con->read( &(info->trueColor), 1 ); |
172 | 172 | ||
173 | con->read( &(info->redMax), 2 ); | 173 | con->read( &(info->redMax), 2 ); |
174 | info->redMax = Swap16IfLE( info->redMax ); | 174 | info->redMax = Swap16IfLE( info->redMax ); |
175 | con->read( &(info->greenMax), 2 ); | 175 | con->read( &(info->greenMax), 2 ); |
176 | info->greenMax = Swap16IfLE( info->greenMax ); | 176 | info->greenMax = Swap16IfLE( info->greenMax ); |
177 | con->read( &(info->blueMax), 2 ); | 177 | con->read( &(info->blueMax), 2 ); |
178 | info->blueMax = Swap16IfLE( info->blueMax ); | 178 | info->blueMax = Swap16IfLE( info->blueMax ); |
179 | 179 | ||
180 | con->read( &(info->redShift), 1 ); | 180 | con->read( &(info->redShift), 1 ); |
181 | con->read( &(info->greenShift), 1 ); | 181 | con->read( &(info->greenShift), 1 ); |
182 | con->read( &(info->blueShift), 1 ); | 182 | con->read( &(info->blueShift), 1 ); |
183 | 183 | ||
184 | con->read( info->padding, 3 ); | 184 | con->read( info->padding, 3 ); |
185 | 185 | ||
186 | con->read( &(info->nameLength), 4 ); | 186 | con->read( &(info->nameLength), 4 ); |
187 | info->nameLength = Swap32IfLE( info->nameLength ); | 187 | info->nameLength = Swap32IfLE( info->nameLength ); |
188 | 188 | ||
189 | owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; | 189 | owarn << "Width = " << info->width << ", Height = " << info->height << "" << oendl; |
190 | owarn << "Bpp = " << info->bpp << ", Depth = " << info->depth << ", Big = " << info->bigEndian | 190 | owarn << "Bpp = " << info->bpp << ", Depth = " << info->depth << ", Big = " << info->bigEndian |
191 | << ", True = " << info->trueColor << oendl; | 191 | << ", True = " << info->trueColor << oendl; |
192 | owarn << "RedMax = " << info->redMax << ", GreenMax = " << info->greenMax << ", BlueMax = " << info->blueMax << oendl; | 192 | owarn << "RedMax = " << info->redMax << ", GreenMax = " << info->greenMax << ", BlueMax = " << info->blueMax << oendl; |
193 | owarn << "RedShift = " << info->redShift << ", GreenShift = " << info->greenShift | 193 | owarn << "RedShift = " << info->redShift << ", GreenShift = " << info->greenShift |
194 | << ", BlueShift = " << info-> blueShift << oendl; | 194 | << ", BlueShift = " << info-> blueShift << oendl; |
195 | 195 | ||
196 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); | 196 | buf->resize( info->width/con->options()->scaleFactor, info->height /con->options()->scaleFactor); |
197 | 197 | ||
198 | // Wait for desktop name | 198 | // Wait for desktop name |
199 | owarn << "Waiting for desktop name" << oendl; | 199 | owarn << "Waiting for desktop name" << oendl; |
200 | 200 | ||
201 | static QString statusMsg = tr( "Waiting for desktop name..." ); | 201 | static QString statusMsg = tr( "Waiting for desktop name..." ); |
202 | emit status( statusMsg ); | 202 | emit status( statusMsg ); |
203 | 203 | ||
204 | currentState = AwaitingDesktopName; | 204 | currentState = AwaitingDesktopName; |
205 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); | 205 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotDesktopName() ) ); |
206 | con->waitForData( info->nameLength ); | 206 | con->waitForData( info->nameLength ); |
207 | } | 207 | } |
208 | 208 | ||
209 | void KRFBDecoder::gotDesktopName() | 209 | void KRFBDecoder::gotDesktopName() |
210 | { | 210 | { |
211 | assert( info ); | 211 | assert( info ); |
212 | assert( currentState == AwaitingDesktopName ); | 212 | assert( currentState == AwaitingDesktopName ); |
213 | 213 | ||
214 | owarn << "Got desktop name" << oendl; | 214 | owarn << "Got desktop name" << oendl; |
215 | 215 | ||
216 | disconnect( con, SIGNAL( gotEnoughData() ), | 216 | disconnect( con, SIGNAL( gotEnoughData() ), |
217 | this, SLOT( gotDesktopName() ) ); | 217 | this, SLOT( gotDesktopName() ) ); |
218 | 218 | ||
219 | char *buf = new char[ info->nameLength + 1 ]; | 219 | char *buf = new char[ info->nameLength + 1 ]; |
220 | CHECK_PTR( buf ); | 220 | CHECK_PTR( buf ); |
221 | 221 | ||
222 | con->read( buf, info->nameLength ); | 222 | con->read( buf, info->nameLength ); |
223 | buf[ info->nameLength ] = '\0'; | 223 | buf[ info->nameLength ] = '\0'; |
224 | info->name = buf; | 224 | info->name = buf; |
225 | 225 | ||
226 | owarn << "Desktop: " << info->name.latin1() << "" << oendl; | 226 | owarn << "Desktop: " << info->name.latin1() << "" << oendl; |
227 | 227 | ||
228 | delete buf; | 228 | delete [] buf; |
229 | 229 | ||
230 | // Get the format we'll really use and tell the server | 230 | // Get the format we'll really use and tell the server |
231 | decidePixelFormat(); | 231 | decidePixelFormat(); |
232 | sendPixelFormat(); | 232 | sendPixelFormat(); |
233 | sendAllowedEncodings(); | 233 | sendAllowedEncodings(); |
234 | currentState = Idle; | 234 | currentState = Idle; |
235 | 235 | ||
236 | QString msg; | 236 | QString msg; |
237 | msg = tr( "Connected to %1" ); | 237 | msg = tr( "Connected to %1" ); |
238 | msg = msg.arg( info->name ); | 238 | msg = msg.arg( info->name ); |
239 | emit status( msg ); | 239 | emit status( msg ); |
240 | 240 | ||
241 | sendUpdateRequest( false ); | 241 | sendUpdateRequest( false ); |
242 | } | 242 | } |
243 | 243 | ||
244 | void KRFBDecoder::decidePixelFormat() | 244 | void KRFBDecoder::decidePixelFormat() |
245 | { | 245 | { |
246 | assert( info ); | 246 | assert( info ); |
247 | 247 | ||
248 | if ( format ) | 248 | if ( format ) |
249 | delete format; | 249 | delete format; |
250 | format = new KRFBPixelFormat; | 250 | format = new KRFBPixelFormat; |
251 | CHECK_PTR( format ); | 251 | CHECK_PTR( format ); |
252 | 252 | ||
253 | // What depth do we want? | 253 | // What depth do we want? |
254 | // | 254 | // |
255 | // We'll use the minimum of the remote and local depths, UNLESS an | 255 | // We'll use the minimum of the remote and local depths, UNLESS an |
256 | // eight bit session has been specifically requested by the user. | 256 | // eight bit session has been specifically requested by the user. |
257 | int screenDepth = QPixmap::defaultDepth(); | 257 | int screenDepth = QPixmap::defaultDepth(); |
258 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; | 258 | int bestDepth = ( screenDepth > info->depth ) ? info->depth : screenDepth; |
259 | int chosenDepth; | 259 | int chosenDepth; |
260 | 260 | ||
261 | if ( con->options()->colors256 ) | 261 | if ( con->options()->colors256 ) |
262 | chosenDepth = 8; | 262 | chosenDepth = 8; |
263 | else | 263 | else |
264 | chosenDepth = bestDepth; | 264 | chosenDepth = bestDepth; |
265 | 265 | ||
266 | owarn << "Screen depth=" << screenDepth << ", server depth=" << info->depth | 266 | owarn << "Screen depth=" << screenDepth << ", server depth=" << info->depth |
267 | << ", best depth=" << bestDepth << "eight bit " << con->options()->colors256 | 267 | << ", best depth=" << bestDepth << "eight bit " << con->options()->colors256 |
268 | << ", chosenDepth=" << chosenDepth << oendl; | 268 | << ", chosenDepth=" << chosenDepth << oendl; |
269 | 269 | ||
270 | format->depth = chosenDepth; | 270 | format->depth = chosenDepth; |
271 | 271 | ||
272 | // If we're using the servers native depth | 272 | // If we're using the servers native depth |
273 | if ( chosenDepth == info->depth ) { | 273 | if ( chosenDepth == info->depth ) { |
274 | // Use the servers native format | 274 | // Use the servers native format |
275 | format->bpp = info->bpp; | 275 | format->bpp = info->bpp; |
276 | // format->bigEndian = info->bigEndian; | 276 | // format->bigEndian = info->bigEndian; |
277 | format->bigEndian = true; | 277 | format->bigEndian = true; |
278 | format->trueColor = info->trueColor; | 278 | format->trueColor = info->trueColor; |
279 | format->redMax = info->redMax; | 279 | format->redMax = info->redMax; |
280 | format->greenMax = info->greenMax; | 280 | format->greenMax = info->greenMax; |
281 | format->blueMax = info->blueMax; | 281 | format->blueMax = info->blueMax; |
282 | format->redShift = info->redShift; | 282 | format->redShift = info->redShift; |
283 | format->greenShift = info->greenShift; | 283 | format->greenShift = info->greenShift; |
284 | format->blueShift = info->blueShift; | 284 | format->blueShift = info->blueShift; |
285 | } | 285 | } |
286 | else { | 286 | else { |
287 | if ( chosenDepth == 8 ) { | 287 | if ( chosenDepth == 8 ) { |
288 | format->bpp = 8; | 288 | format->bpp = 8; |
289 | format->bigEndian = true; | 289 | format->bigEndian = true; |
290 | format->trueColor = true; | 290 | format->trueColor = true; |
291 | format->redMax = 7; | 291 | format->redMax = 7; |
292 | format->greenMax = 7; | 292 | format->greenMax = 7; |
293 | format->blueMax = 3; | 293 | format->blueMax = 3; |
294 | format->redShift = 0; | 294 | format->redShift = 0; |
295 | format->greenShift = 3; | 295 | format->greenShift = 3; |
296 | format->blueShift = 6; | 296 | format->blueShift = 6; |
297 | } | 297 | } |
298 | } | 298 | } |
299 | 299 | ||
300 | format->redMax = Swap16IfLE( format->redMax ); | 300 | format->redMax = Swap16IfLE( format->redMax ); |
301 | format->greenMax = Swap16IfLE( format->greenMax ); | 301 | format->greenMax = Swap16IfLE( format->greenMax ); |
302 | format->blueMax = Swap16IfLE( format->blueMax ); | 302 | format->blueMax = Swap16IfLE( format->blueMax ); |
303 | } | 303 | } |
304 | 304 | ||
305 | void KRFBDecoder::sendPixelFormat() | 305 | void KRFBDecoder::sendPixelFormat() |
306 | { | 306 | { |
307 | static char padding[3]; | 307 | static char padding[3]; |
308 | con->write( &SetPixelFormatId, 1 ); | 308 | con->write( &SetPixelFormatId, 1 ); |
309 | con->write( padding, 3 ); | 309 | con->write( padding, 3 ); |
310 | 310 | ||
311 | con->write( &(format->bpp), 1 ); | 311 | con->write( &(format->bpp), 1 ); |
312 | con->write( &(format->depth), 1 ); | 312 | con->write( &(format->depth), 1 ); |
313 | con->write( &(format->bigEndian), 1 ); | 313 | con->write( &(format->bigEndian), 1 ); |
314 | con->write( &(format->trueColor), 1 ); | 314 | con->write( &(format->trueColor), 1 ); |
315 | 315 | ||
316 | con->write( &(format->redMax), 2 ); | 316 | con->write( &(format->redMax), 2 ); |
317 | con->write( &(format->greenMax), 2 ); | 317 | con->write( &(format->greenMax), 2 ); |
318 | con->write( &(format->blueMax), 2 ); | 318 | con->write( &(format->blueMax), 2 ); |
319 | 319 | ||
320 | con->write( &(format->redShift), 1 ); | 320 | con->write( &(format->redShift), 1 ); |
321 | con->write( &(format->greenShift), 1 ); | 321 | con->write( &(format->greenShift), 1 ); |
322 | con->write( &(format->blueShift), 1 ); | 322 | con->write( &(format->blueShift), 1 ); |
323 | con->write( format->padding, 3 ); // Padding | 323 | con->write( format->padding, 3 ); // Padding |
324 | } | 324 | } |
@@ -442,386 +442,386 @@ void KRFBDecoder::gotRectHeader() | |||
442 | 442 | ||
443 | // | 443 | // |
444 | // Each encoding needs to be handled differently. Some require | 444 | // Each encoding needs to be handled differently. Some require |
445 | // waiting for more data, but others like a copyrect do not. | 445 | // waiting for more data, but others like a copyrect do not. |
446 | // Our constants have already been byte swapped, so we use | 446 | // Our constants have already been byte swapped, so we use |
447 | // the remote value as is. | 447 | // the remote value as is. |
448 | // | 448 | // |
449 | if ( encoding == RawEncoding ) { | 449 | if ( encoding == RawEncoding ) { |
450 | // owarn << "Raw encoding" << oendl; | 450 | // owarn << "Raw encoding" << oendl; |
451 | handleRawRect(); | 451 | handleRawRect(); |
452 | } | 452 | } |
453 | else if ( encoding == CopyRectEncoding ) { | 453 | else if ( encoding == CopyRectEncoding ) { |
454 | // owarn << "CopyRect encoding" << oendl; | 454 | // owarn << "CopyRect encoding" << oendl; |
455 | handleCopyRect(); | 455 | handleCopyRect(); |
456 | } | 456 | } |
457 | else if ( encoding == RreEncoding ) { | 457 | else if ( encoding == RreEncoding ) { |
458 | owarn << "RRE encoding" << oendl; | 458 | owarn << "RRE encoding" << oendl; |
459 | handleRRERect(); | 459 | handleRRERect(); |
460 | } | 460 | } |
461 | else if ( encoding == CorreEncoding ) { | 461 | else if ( encoding == CorreEncoding ) { |
462 | owarn << "CoRRE encoding" << oendl; | 462 | owarn << "CoRRE encoding" << oendl; |
463 | handleCoRRERect(); | 463 | handleCoRRERect(); |
464 | } | 464 | } |
465 | else if ( encoding == HexTileEncoding ) { | 465 | else if ( encoding == HexTileEncoding ) { |
466 | owarn << "HexTile encoding" << oendl; | 466 | owarn << "HexTile encoding" << oendl; |
467 | handleHexTileRect(); | 467 | handleHexTileRect(); |
468 | } | 468 | } |
469 | else { | 469 | else { |
470 | int msg = Swap32IfLE( encoding ); | 470 | int msg = Swap32IfLE( encoding ); |
471 | QString protocolError = tr( "Protocol Error: An unknown encoding was " | 471 | QString protocolError = tr( "Protocol Error: An unknown encoding was " |
472 | "used by the server %1" ).arg( msg ); | 472 | "used by the server %1" ).arg( msg ); |
473 | currentState = Error; | 473 | currentState = Error; |
474 | owarn << "Unknown encoding, " << msg << "" << oendl; | 474 | owarn << "Unknown encoding, " << msg << "" << oendl; |
475 | emit error( protocolError ); | 475 | emit error( protocolError ); |
476 | return; | 476 | return; |
477 | } | 477 | } |
478 | } | 478 | } |
479 | 479 | ||
480 | // | 480 | // |
481 | // Raw Encoding | 481 | // Raw Encoding |
482 | // | 482 | // |
483 | 483 | ||
484 | void KRFBDecoder::handleRawRect() | 484 | void KRFBDecoder::handleRawRect() |
485 | { | 485 | { |
486 | // We need something a bit cleverer here to handle large | 486 | // We need something a bit cleverer here to handle large |
487 | // rectanges nicely. The chunking should be based on the | 487 | // rectanges nicely. The chunking should be based on the |
488 | // overall size (but has to be in complete lines). | 488 | // overall size (but has to be in complete lines). |
489 | 489 | ||
490 | // owarn << "Handling a raw rect chunk" << oendl; | 490 | // owarn << "Handling a raw rect chunk" << oendl; |
491 | 491 | ||
492 | // CARD32 lineCount = w * format->bpp / 8; | 492 | // CARD32 lineCount = w * format->bpp / 8; |
493 | 493 | ||
494 | if ( h > RectChunkSize ) { | 494 | if ( h > RectChunkSize ) { |
495 | // if ( con->sock->size() / lineCount ) { | 495 | // if ( con->sock->size() / lineCount ) { |
496 | // getRawRectChunk( con->sock->size() / lineCount ); | 496 | // getRawRectChunk( con->sock->size() / lineCount ); |
497 | // } | 497 | // } |
498 | // else { | 498 | // else { |
499 | getRawRectChunk( RectChunkSize ); | 499 | getRawRectChunk( RectChunkSize ); |
500 | // } | 500 | // } |
501 | } | 501 | } |
502 | else { | 502 | else { |
503 | getRawRectChunk( h ); | 503 | getRawRectChunk( h ); |
504 | } | 504 | } |
505 | } | 505 | } |
506 | 506 | ||
507 | void KRFBDecoder::getRawRectChunk( int lines ) | 507 | void KRFBDecoder::getRawRectChunk( int lines ) |
508 | { | 508 | { |
509 | this->lines = lines; | 509 | this->lines = lines; |
510 | CARD32 count = lines * w * format->bpp / 8; | 510 | CARD32 count = lines * w * format->bpp / 8; |
511 | 511 | ||
512 | // Wait for server init | 512 | // Wait for server init |
513 | // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; | 513 | // owarn << "Waiting for raw rect chunk, " << count << "" << oendl; |
514 | 514 | ||
515 | currentState = AwaitingRawRectChunk; | 515 | currentState = AwaitingRawRectChunk; |
516 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); | 516 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRawRectChunk() ) ); |
517 | con->waitForData( count ); | 517 | con->waitForData( count ); |
518 | } | 518 | } |
519 | 519 | ||
520 | void KRFBDecoder::gotRawRectChunk() | 520 | void KRFBDecoder::gotRawRectChunk() |
521 | { | 521 | { |
522 | assert( currentState == AwaitingRawRectChunk ); | 522 | assert( currentState == AwaitingRawRectChunk ); |
523 | 523 | ||
524 | disconnect( con, SIGNAL( gotEnoughData() ), | 524 | disconnect( con, SIGNAL( gotEnoughData() ), |
525 | this, SLOT( gotRawRectChunk() ) ); | 525 | this, SLOT( gotRawRectChunk() ) ); |
526 | 526 | ||
527 | // owarn << "Got raw rect chunk" << oendl; | 527 | // owarn << "Got raw rect chunk" << oendl; |
528 | 528 | ||
529 | // | 529 | // |
530 | // Read the rect data and copy it to the buffer. | 530 | // Read the rect data and copy it to the buffer. |
531 | // | 531 | // |
532 | 532 | ||
533 | // TODO: Replace this! | 533 | // TODO: Replace this! |
534 | int count = lines * w * format->bpp / 8; | 534 | int count = lines * w * format->bpp / 8; |
535 | char *hack = new char[ count ]; | 535 | char *hack = new char[ count ]; |
536 | con->read( hack, count ); | 536 | con->read( hack, count ); |
537 | buf->drawRawRectChunk( hack, x, y, w, lines ); | 537 | buf->drawRawRectChunk( hack, x, y, w, lines ); |
538 | delete hack; | 538 | delete [] hack; |
539 | // /TODO: | 539 | // /TODO: |
540 | 540 | ||
541 | h = h - lines; | 541 | h = h - lines; |
542 | y = y + lines; | 542 | y = y + lines; |
543 | 543 | ||
544 | if ( h > 0 ) { | 544 | if ( h > 0 ) { |
545 | handleRawRect(); | 545 | handleRawRect(); |
546 | } | 546 | } |
547 | else { | 547 | else { |
548 | noRects--; | 548 | noRects--; |
549 | 549 | ||
550 | // owarn << "There are " << noRects << " rects left" << oendl; | 550 | // owarn << "There are " << noRects << " rects left" << oendl; |
551 | 551 | ||
552 | if ( noRects ) { | 552 | if ( noRects ) { |
553 | currentState = AwaitingRectHeader; | 553 | currentState = AwaitingRectHeader; |
554 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 554 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
555 | con->waitForData( RectHeaderLength ); | 555 | con->waitForData( RectHeaderLength ); |
556 | } | 556 | } |
557 | else { | 557 | else { |
558 | // we are now ready for the next update - no need to wait for the timer | 558 | // we are now ready for the next update - no need to wait for the timer |
559 | currentState = Idle; | 559 | currentState = Idle; |
560 | sendUpdateRequest (1); | 560 | sendUpdateRequest (1); |
561 | } | 561 | } |
562 | } | 562 | } |
563 | } | 563 | } |
564 | 564 | ||
565 | // | 565 | // |
566 | // Copy Rectangle Encoding | 566 | // Copy Rectangle Encoding |
567 | // | 567 | // |
568 | 568 | ||
569 | void KRFBDecoder::handleCopyRect() | 569 | void KRFBDecoder::handleCopyRect() |
570 | { | 570 | { |
571 | currentState = AwaitingCopyRectPos; | 571 | currentState = AwaitingCopyRectPos; |
572 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); | 572 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotCopyRectPos() ) ); |
573 | con->waitForData( CopyRectPosLength ); | 573 | con->waitForData( CopyRectPosLength ); |
574 | } | 574 | } |
575 | 575 | ||
576 | void KRFBDecoder::gotCopyRectPos() | 576 | void KRFBDecoder::gotCopyRectPos() |
577 | { | 577 | { |
578 | disconnect( con, SIGNAL( gotEnoughData() ), | 578 | disconnect( con, SIGNAL( gotEnoughData() ), |
579 | this, SLOT( gotCopyRectPos() ) ); | 579 | this, SLOT( gotCopyRectPos() ) ); |
580 | 580 | ||
581 | CARD16 srcX; | 581 | CARD16 srcX; |
582 | CARD16 srcY; | 582 | CARD16 srcY; |
583 | 583 | ||
584 | con->read( &srcX, 2 ); | 584 | con->read( &srcX, 2 ); |
585 | con->read( &srcY, 2 ); | 585 | con->read( &srcY, 2 ); |
586 | 586 | ||
587 | srcX = Swap16IfLE( srcX ); | 587 | srcX = Swap16IfLE( srcX ); |
588 | srcY = Swap16IfLE( srcY ); | 588 | srcY = Swap16IfLE( srcY ); |
589 | 589 | ||
590 | buf->copyRect( srcX, srcY, x, y, w, h ); | 590 | buf->copyRect( srcX, srcY, x, y, w, h ); |
591 | 591 | ||
592 | noRects--; | 592 | noRects--; |
593 | 593 | ||
594 | // owarn << "There are " << noRects << " rects left" << oendl; | 594 | // owarn << "There are " << noRects << " rects left" << oendl; |
595 | 595 | ||
596 | if ( noRects ) { | 596 | if ( noRects ) { |
597 | currentState = AwaitingRectHeader; | 597 | currentState = AwaitingRectHeader; |
598 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); | 598 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotRectHeader() ) ); |
599 | con->waitForData( RectHeaderLength ); | 599 | con->waitForData( RectHeaderLength ); |
600 | } | 600 | } |
601 | else | 601 | else |
602 | currentState = Idle; | 602 | currentState = Idle; |
603 | } | 603 | } |
604 | 604 | ||
605 | void KRFBDecoder::handleRRERect() | 605 | void KRFBDecoder::handleRRERect() |
606 | { | 606 | { |
607 | owarn << "RRE not implemented" << oendl; | 607 | owarn << "RRE not implemented" << oendl; |
608 | } | 608 | } |
609 | 609 | ||
610 | void KRFBDecoder::handleCoRRERect() | 610 | void KRFBDecoder::handleCoRRERect() |
611 | { | 611 | { |
612 | owarn << "CoRRE not implemented" << oendl; | 612 | owarn << "CoRRE not implemented" << oendl; |
613 | } | 613 | } |
614 | 614 | ||
615 | void KRFBDecoder::handleHexTileRect() | 615 | void KRFBDecoder::handleHexTileRect() |
616 | { | 616 | { |
617 | owarn << "HexTile not implemented" << oendl; | 617 | owarn << "HexTile not implemented" << oendl; |
618 | } | 618 | } |
619 | 619 | ||
620 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) | 620 | void KRFBDecoder::sendMouseEvent( QMouseEvent *e ) |
621 | { | 621 | { |
622 | // Deal with the buttons | 622 | // Deal with the buttons |
623 | if ( e->type() != QEvent::MouseMove ) { | 623 | if ( e->type() != QEvent::MouseMove ) { |
624 | buttonMask = 0; | 624 | buttonMask = 0; |
625 | if ( e->type() == QEvent::MouseButtonPress ) { | 625 | if ( e->type() == QEvent::MouseButtonPress ) { |
626 | if ( e->button() & LeftButton ) | 626 | if ( e->button() & LeftButton ) |
627 | buttonMask |= 0x01; | 627 | buttonMask |= 0x01; |
628 | if ( e->button() & MidButton ) | 628 | if ( e->button() & MidButton ) |
629 | buttonMask |= 0x04; | 629 | buttonMask |= 0x04; |
630 | if ( e->button() & RightButton ) | 630 | if ( e->button() & RightButton ) |
631 | buttonMask |= 0x02; | 631 | buttonMask |= 0x02; |
632 | } | 632 | } |
633 | else if ( e->type() == QEvent::MouseButtonRelease ) { | 633 | else if ( e->type() == QEvent::MouseButtonRelease ) { |
634 | if ( e->button() & LeftButton ) | 634 | if ( e->button() & LeftButton ) |
635 | buttonMask &= 0x06; | 635 | buttonMask &= 0x06; |
636 | if ( e->button() & MidButton ) | 636 | if ( e->button() & MidButton ) |
637 | buttonMask |= 0x03; | 637 | buttonMask |= 0x03; |
638 | if ( e->button() & RightButton ) | 638 | if ( e->button() & RightButton ) |
639 | buttonMask |= 0x05; | 639 | buttonMask |= 0x05; |
640 | } | 640 | } |
641 | } | 641 | } |
642 | 642 | ||
643 | // HACK: Scaling | 643 | // HACK: Scaling |
644 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); | 644 | CARD16 x = Swap16IfLE( e->x() * con->options()->scaleFactor ); |
645 | CARD16 y = Swap16IfLE( e->y() * con->options()->scaleFactor ); | 645 | CARD16 y = Swap16IfLE( e->y() * con->options()->scaleFactor ); |
646 | 646 | ||
647 | con->write( &PointerEventId, 1 ); | 647 | con->write( &PointerEventId, 1 ); |
648 | con->write( &buttonMask, 1 ); | 648 | con->write( &buttonMask, 1 ); |
649 | con->write( &x, 2 ); | 649 | con->write( &x, 2 ); |
650 | con->write( &y, 2 ); | 650 | con->write( &y, 2 ); |
651 | } | 651 | } |
652 | 652 | ||
653 | 653 | ||
654 | void KRFBDecoder::sendCutEvent( const QString &unicode ) | 654 | void KRFBDecoder::sendCutEvent( const QString &unicode ) |
655 | { | 655 | { |
656 | // | 656 | // |
657 | // Warning: There is a bug in the RFB protocol because there is no way to find | 657 | // Warning: There is a bug in the RFB protocol because there is no way to find |
658 | // out the codepage in use on the remote machine. This could be fixed by requiring | 658 | // out the codepage in use on the remote machine. This could be fixed by requiring |
659 | // the remote server to use utf8 etc. but for now we have to assume they're the | 659 | // the remote server to use utf8 etc. but for now we have to assume they're the |
660 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 660 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
661 | // immediate plans to fix the issue. :-( (rich) | 661 | // immediate plans to fix the issue. :-( (rich) |
662 | // | 662 | // |
663 | 663 | ||
664 | CARD8 padding[3]; | 664 | CARD8 padding[3]; |
665 | QCString text = unicode.local8Bit(); | 665 | QCString text = unicode.local8Bit(); |
666 | CARD32 length = text.length(); | 666 | CARD32 length = text.length(); |
667 | length = Swap32IfLE( length ); | 667 | length = Swap32IfLE( length ); |
668 | 668 | ||
669 | con->write( &ClientCutTextId, 1 ); | 669 | con->write( &ClientCutTextId, 1 ); |
670 | con->write( &padding, 3 ); | 670 | con->write( &padding, 3 ); |
671 | con->write( &length, 4 ); | 671 | con->write( &length, 4 ); |
672 | con->write( text.data(), length ); | 672 | con->write( text.data(), length ); |
673 | } | 673 | } |
674 | 674 | ||
675 | void KRFBDecoder::gotServerCut() | 675 | void KRFBDecoder::gotServerCut() |
676 | { | 676 | { |
677 | owarn << "Got server cut" << oendl; | 677 | owarn << "Got server cut" << oendl; |
678 | 678 | ||
679 | currentState = AwaitingServerCutLength; | 679 | currentState = AwaitingServerCutLength; |
680 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); | 680 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutLength() ) ); |
681 | con->waitForData( ServerCutLenLength ); | 681 | con->waitForData( ServerCutLenLength ); |
682 | } | 682 | } |
683 | 683 | ||
684 | void KRFBDecoder::gotServerCutLength() | 684 | void KRFBDecoder::gotServerCutLength() |
685 | { | 685 | { |
686 | assert( currentState = AwaitingServerCutLength ); | 686 | assert( currentState = AwaitingServerCutLength ); |
687 | disconnect( con, SIGNAL( gotEnoughData() ), | 687 | disconnect( con, SIGNAL( gotEnoughData() ), |
688 | this, SLOT( gotServerCutLength() ) ); | 688 | this, SLOT( gotServerCutLength() ) ); |
689 | 689 | ||
690 | CARD8 padding[3]; | 690 | CARD8 padding[3]; |
691 | con->read( padding, 3 ); | 691 | con->read( padding, 3 ); |
692 | 692 | ||
693 | con->read( &serverCutTextLen, 4 ); | 693 | con->read( &serverCutTextLen, 4 ); |
694 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); | 694 | serverCutTextLen = Swap32IfLE( serverCutTextLen ); |
695 | 695 | ||
696 | currentState = AwaitingServerCutText; | 696 | currentState = AwaitingServerCutText; |
697 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); | 697 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotServerCutText() ) ); |
698 | con->waitForData( serverCutTextLen ); | 698 | con->waitForData( serverCutTextLen ); |
699 | } | 699 | } |
700 | 700 | ||
701 | void KRFBDecoder::gotServerCutText() | 701 | void KRFBDecoder::gotServerCutText() |
702 | { | 702 | { |
703 | assert( currentState = AwaitingServerCutText ); | 703 | assert( currentState = AwaitingServerCutText ); |
704 | 704 | ||
705 | disconnect( con, SIGNAL( gotEnoughData() ), | 705 | disconnect( con, SIGNAL( gotEnoughData() ), |
706 | this, SLOT( gotServerCutText() ) ); | 706 | this, SLOT( gotServerCutText() ) ); |
707 | 707 | ||
708 | 708 | ||
709 | // | 709 | // |
710 | // Warning: There is a bug in the RFB protocol because there is no way to find | 710 | // Warning: There is a bug in the RFB protocol because there is no way to find |
711 | // out the codepage in use on the remote machine. This could be fixed by requiring | 711 | // out the codepage in use on the remote machine. This could be fixed by requiring |
712 | // the remote server to use utf8 etc. but for now we have to assume they're the | 712 | // the remote server to use utf8 etc. but for now we have to assume they're the |
713 | // same. I've reported this problem to the ORL guys, but they apparantly have no | 713 | // same. I've reported this problem to the ORL guys, but they apparantly have no |
714 | // immediate plans to fix the issue. :-( (rich) | 714 | // immediate plans to fix the issue. :-( (rich) |
715 | // | 715 | // |
716 | 716 | ||
717 | char *cutbuf = new char[ serverCutTextLen + 1 ]; | 717 | char *cutbuf = new char[ serverCutTextLen + 1 ]; |
718 | CHECK_PTR( cutbuf ); | 718 | CHECK_PTR( cutbuf ); |
719 | 719 | ||
720 | con->read( cutbuf, serverCutTextLen ); | 720 | con->read( cutbuf, serverCutTextLen ); |
721 | cutbuf[ serverCutTextLen ] = '\0'; | 721 | cutbuf[ serverCutTextLen ] = '\0'; |
722 | 722 | ||
723 | /* For some reason QApplication::clipboard()->setText() segfaults when called | 723 | /* For some reason QApplication::clipboard()->setText() segfaults when called |
724 | * from within keypebble's mass of signals and slots | 724 | * from within keypebble's mass of signals and slots |
725 | owarn << "Server cut: " << cutbuf << "" << oendl; | 725 | owarn << "Server cut: " << cutbuf << "" << oendl; |
726 | 726 | ||
727 | QString cutText( cutbuf ); // DANGER!! | 727 | QString cutText( cutbuf ); // DANGER!! |
728 | qApp->clipboard()->setText( cutText ); | 728 | qApp->clipboard()->setText( cutText ); |
729 | */ | 729 | */ |
730 | 730 | ||
731 | delete cutbuf; | 731 | delete [] cutbuf; |
732 | // Now wait for the update (again) | 732 | // Now wait for the update (again) |
733 | if ( oldState == AwaitingUpdate ) { | 733 | if ( oldState == AwaitingUpdate ) { |
734 | currentState = AwaitingUpdate; | 734 | currentState = AwaitingUpdate; |
735 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 735 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
736 | con->waitForData( UpdateHeaderLength ); | 736 | con->waitForData( UpdateHeaderLength ); |
737 | } | 737 | } |
738 | else if ( oldState == Idle ) { | 738 | else if ( oldState == Idle ) { |
739 | currentState = Idle; | 739 | currentState = Idle; |
740 | } | 740 | } |
741 | else { | 741 | else { |
742 | owarn << "Async handled in weird state" << oendl; | 742 | owarn << "Async handled in weird state" << oendl; |
743 | currentState = oldState; | 743 | currentState = oldState; |
744 | }; | 744 | }; |
745 | } | 745 | } |
746 | 746 | ||
747 | void KRFBDecoder::gotBell() | 747 | void KRFBDecoder::gotBell() |
748 | { | 748 | { |
749 | owarn << "Got server bell" << oendl; | 749 | owarn << "Got server bell" << oendl; |
750 | buf->soundBell(); | 750 | buf->soundBell(); |
751 | 751 | ||
752 | // Now wait for the update (again) | 752 | // Now wait for the update (again) |
753 | if ( oldState == AwaitingUpdate ) { | 753 | if ( oldState == AwaitingUpdate ) { |
754 | currentState = AwaitingUpdate; | 754 | currentState = AwaitingUpdate; |
755 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); | 755 | connect( con, SIGNAL( gotEnoughData() ), SLOT( gotUpdateHeader() ) ); |
756 | con->waitForData( UpdateHeaderLength ); | 756 | con->waitForData( UpdateHeaderLength ); |
757 | } | 757 | } |
758 | else if ( oldState == Idle ) { | 758 | else if ( oldState == Idle ) { |
759 | currentState = Idle; | 759 | currentState = Idle; |
760 | } | 760 | } |
761 | else { | 761 | else { |
762 | owarn << "Async handled in weird state" << oendl; | 762 | owarn << "Async handled in weird state" << oendl; |
763 | currentState = oldState; | 763 | currentState = oldState; |
764 | }; | 764 | }; |
765 | } | 765 | } |
766 | 766 | ||
767 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) | 767 | void KRFBDecoder::sendKeyPressEvent( QKeyEvent *event ) |
768 | { | 768 | { |
769 | int key; | 769 | int key; |
770 | key = toKeySym( event ); | 770 | key = toKeySym( event ); |
771 | if ( key ) { | 771 | if ( key ) { |
772 | key = Swap32IfLE( key ); | 772 | key = Swap32IfLE( key ); |
773 | 773 | ||
774 | CARD8 mask = true; | 774 | CARD8 mask = true; |
775 | 775 | ||
776 | CARD16 padding = 0; | 776 | CARD16 padding = 0; |
777 | con->write( &KeyEventId, 1 ); | 777 | con->write( &KeyEventId, 1 ); |
778 | con->write( &mask, 1 ); | 778 | con->write( &mask, 1 ); |
779 | con->write( &padding, 2 ); | 779 | con->write( &padding, 2 ); |
780 | con->write( &key, 4 ); | 780 | con->write( &key, 4 ); |
781 | } | 781 | } |
782 | } | 782 | } |
783 | 783 | ||
784 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) | 784 | void KRFBDecoder::sendKeyReleaseEvent( QKeyEvent *event ) |
785 | { | 785 | { |
786 | int key; | 786 | int key; |
787 | key = toKeySym( event ); | 787 | key = toKeySym( event ); |
788 | if ( key ) { | 788 | if ( key ) { |
789 | key = Swap32IfLE( key ); | 789 | key = Swap32IfLE( key ); |
790 | 790 | ||
791 | CARD8 mask = false; | 791 | CARD8 mask = false; |
792 | 792 | ||
793 | CARD16 padding = 0; | 793 | CARD16 padding = 0; |
794 | con->write( &KeyEventId, 1 ); | 794 | con->write( &KeyEventId, 1 ); |
795 | con->write( &mask, 1 ); | 795 | con->write( &mask, 1 ); |
796 | con->write( &padding, 2 ); | 796 | con->write( &padding, 2 ); |
797 | con->write( &key, 4 ); | 797 | con->write( &key, 4 ); |
798 | } | 798 | } |
799 | } | 799 | } |
800 | 800 | ||
801 | 801 | ||
802 | 802 | ||
803 | 803 | ||
804 | // | 804 | // |
805 | // The RFB protocol spec says 'For most ordinary keys, the 'keysym' | 805 | // The RFB protocol spec says 'For most ordinary keys, the 'keysym' |
806 | // is the same as the corresponding ASCII value.', but doesn't | 806 | // is the same as the corresponding ASCII value.', but doesn't |
807 | // elaborate what the most ordinary keys are. The spec also lists | 807 | // elaborate what the most ordinary keys are. The spec also lists |
808 | // a set (possibly subset, it's unspecified) of mappings for | 808 | // a set (possibly subset, it's unspecified) of mappings for |
809 | // "other common keys" (backspace, tab, return, escape, etc). | 809 | // "other common keys" (backspace, tab, return, escape, etc). |
810 | // | 810 | // |
811 | int KRFBDecoder::toKeySym( QKeyEvent *k ) | 811 | int KRFBDecoder::toKeySym( QKeyEvent *k ) |
812 | { | 812 | { |
813 | 813 | ||
814 | // | 814 | // |
815 | // Try and map these "other common keys" first. | 815 | // Try and map these "other common keys" first. |
816 | // | 816 | // |
817 | if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { | 817 | if ((k->key() >= Qt::Key_Escape) && (k->key() <= Qt::Key_F12)) { |
818 | for(int i = 0; keyMap[i].keycode != 0; i++) { | 818 | for(int i = 0; keyMap[i].keycode != 0; i++) { |
819 | if (k->key() == keyMap[i].keycode) { | 819 | if (k->key() == keyMap[i].keycode) { |
820 | return keyMap[i].keysym; | 820 | return keyMap[i].keysym; |
821 | } | 821 | } |
822 | } | 822 | } |
823 | } | 823 | } |
824 | 824 | ||
825 | // | 825 | // |
826 | // If these keys aren't matched, return the ascii code and let the | 826 | // If these keys aren't matched, return the ascii code and let the |
827 | // server figure it out. We don't return k->key(), as the data in | 827 | // server figure it out. We don't return k->key(), as the data in |
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp index a6c92a0..516dc93 100644 --- a/noncore/games/sfcave/sfcave.cpp +++ b/noncore/games/sfcave/sfcave.cpp | |||
@@ -905,193 +905,193 @@ void SFCave :: keyReleaseEvent( QKeyEvent *e ) | |||
905 | } | 905 | } |
906 | 906 | ||
907 | } | 907 | } |
908 | 908 | ||
909 | 909 | ||
910 | void SFCave :: saveScore() | 910 | void SFCave :: saveScore() |
911 | { | 911 | { |
912 | #ifdef QWS | 912 | #ifdef QWS |
913 | Config cfg( "sfcave" ); | 913 | Config cfg( "sfcave" ); |
914 | cfg.setGroup( "settings" ); | 914 | cfg.setGroup( "settings" ); |
915 | QString key = "highScore_"; | 915 | QString key = "highScore_"; |
916 | 916 | ||
917 | cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); | 917 | cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); |
918 | key += CURRENT_GAME_TYPE; | 918 | key += CURRENT_GAME_TYPE; |
919 | cfg.writeEntry( key, highestScore[currentGameType] ); | 919 | cfg.writeEntry( key, highestScore[currentGameType] ); |
920 | #endif | 920 | #endif |
921 | } | 921 | } |
922 | 922 | ||
923 | void SFCave :: saveReplay() | 923 | void SFCave :: saveReplay() |
924 | { | 924 | { |
925 | FILE *out; | 925 | FILE *out; |
926 | out = fopen( QFile::encodeName(replayFile).data(), "w" ); | 926 | out = fopen( QFile::encodeName(replayFile).data(), "w" ); |
927 | if ( !out ) | 927 | if ( !out ) |
928 | { | 928 | { |
929 | printf( "Couldn't write to %s\n", QFile::encodeName(replayFile).data() ); | 929 | printf( "Couldn't write to %s\n", QFile::encodeName(replayFile).data() ); |
930 | return; | 930 | return; |
931 | } | 931 | } |
932 | 932 | ||
933 | // Build up string of values | 933 | // Build up string of values |
934 | // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... | 934 | // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... |
935 | QString val; | 935 | QString val; |
936 | val.sprintf( "%d %d %d ", currentSeed, currentGameType, currentGameDifficulty ); | 936 | val.sprintf( "%d %d %d ", currentSeed, currentGameType, currentGameDifficulty ); |
937 | 937 | ||
938 | QListIterator<int> it( replayList ); | 938 | QListIterator<int> it( replayList ); |
939 | while( it.current() ) | 939 | while( it.current() ) |
940 | { | 940 | { |
941 | QString tmp; | 941 | QString tmp; |
942 | tmp.sprintf( "%d ", (*it.current()) ); | 942 | tmp.sprintf( "%d ", (*it.current()) ); |
943 | val += tmp; | 943 | val += tmp; |
944 | 944 | ||
945 | ++it; | 945 | ++it; |
946 | } | 946 | } |
947 | val += "\n"; | 947 | val += "\n"; |
948 | 948 | ||
949 | QString line; | 949 | QString line; |
950 | line.sprintf( "%d\n", val.length() ); | 950 | line.sprintf( "%d\n", val.length() ); |
951 | fwrite( (const char *)line, 1, line.length(), out ); | 951 | fwrite( (const char *)line, 1, line.length(), out ); |
952 | 952 | ||
953 | fwrite( (const char *)val, 1, val.length(), out ); | 953 | fwrite( (const char *)val, 1, val.length(), out ); |
954 | 954 | ||
955 | fclose( out ); | 955 | fclose( out ); |
956 | 956 | ||
957 | printf( "Replay saved to %s\n", QFile::encodeName(replayFile).data() ); | 957 | printf( "Replay saved to %s\n", QFile::encodeName(replayFile).data() ); |
958 | 958 | ||
959 | } | 959 | } |
960 | 960 | ||
961 | void SFCave :: loadReplay() | 961 | void SFCave :: loadReplay() |
962 | { | 962 | { |
963 | FILE *in = fopen( QFile::encodeName(replayFile).data() , "r" ); | 963 | FILE *in = fopen( QFile::encodeName(replayFile).data() , "r" ); |
964 | 964 | ||
965 | if ( in == 0 ) | 965 | if ( in == 0 ) |
966 | { | 966 | { |
967 | printf( "Couldn't load replay file!\n" ); | 967 | printf( "Couldn't load replay file!\n" ); |
968 | return; | 968 | return; |
969 | } | 969 | } |
970 | 970 | ||
971 | // Read next line - contains the size of the options | 971 | // Read next line - contains the size of the options |
972 | char line[10+1]; | 972 | char line[10+1]; |
973 | fgets( line, 10, in ); | 973 | fgets( line, 10, in ); |
974 | 974 | ||
975 | int length = -1; | 975 | int length = -1; |
976 | sscanf( line, "%d", &length ); | 976 | sscanf( line, "%d", &length ); |
977 | char *data = new char[length+1]; | 977 | char *data = new char[length+1]; |
978 | 978 | ||
979 | fread( data, 1, length, in ); | 979 | fread( data, 1, length, in ); |
980 | // printf( "data - %s", data ); | 980 | // printf( "data - %s", data ); |
981 | 981 | ||
982 | QString sep = " "; | 982 | QString sep = " "; |
983 | QStringList list = QStringList::split( sep, QString( data ) ); | 983 | QStringList list = QStringList::split( sep, QString( data ) ); |
984 | 984 | ||
985 | // print it out | 985 | // print it out |
986 | QStringList::Iterator it = list.begin(); | 986 | QStringList::Iterator it = list.begin(); |
987 | currentSeed = (*it).toInt(); | 987 | currentSeed = (*it).toInt(); |
988 | ++it; | 988 | ++it; |
989 | currentGameType = (*it).toInt(); | 989 | currentGameType = (*it).toInt(); |
990 | ++it; | 990 | ++it; |
991 | currentGameDifficulty = (*it).toInt(); | 991 | currentGameDifficulty = (*it).toInt(); |
992 | ++it; | 992 | ++it; |
993 | 993 | ||
994 | replayList.clear(); | 994 | replayList.clear(); |
995 | for ( ; it != list.end(); ++it ) | 995 | for ( ; it != list.end(); ++it ) |
996 | { | 996 | { |
997 | int v = (*it).toInt(); | 997 | int v = (*it).toInt(); |
998 | replayList.append( new int( v ) ); | 998 | replayList.append( new int( v ) ); |
999 | } | 999 | } |
1000 | 1000 | ||
1001 | delete data; | 1001 | delete [] data; |
1002 | 1002 | ||
1003 | fclose( in ); | 1003 | fclose( in ); |
1004 | 1004 | ||
1005 | printf( "Replay loaded from %s\n", QFile::encodeName(replayFile).data() ); | 1005 | printf( "Replay loaded from %s\n", QFile::encodeName(replayFile).data() ); |
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | 1008 | ||
1009 | //--------------- MENU CODE --------------------- | 1009 | //--------------- MENU CODE --------------------- |
1010 | void SFCave :: handleMenuKeys( QKeyEvent *e ) | 1010 | void SFCave :: handleMenuKeys( QKeyEvent *e ) |
1011 | { | 1011 | { |
1012 | switch( e->key() ) | 1012 | switch( e->key() ) |
1013 | { | 1013 | { |
1014 | case Qt::Key_Down: | 1014 | case Qt::Key_Down: |
1015 | currentMenuOption[currentMenuNr] ++; | 1015 | currentMenuOption[currentMenuNr] ++; |
1016 | if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) | 1016 | if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) |
1017 | currentMenuOption[currentMenuNr] = 0; | 1017 | currentMenuOption[currentMenuNr] = 0; |
1018 | break; | 1018 | break; |
1019 | case Qt::Key_Up: | 1019 | case Qt::Key_Up: |
1020 | currentMenuOption[currentMenuNr] --; | 1020 | currentMenuOption[currentMenuNr] --; |
1021 | if ( currentMenuOption[currentMenuNr] < 0 ) | 1021 | if ( currentMenuOption[currentMenuNr] < 0 ) |
1022 | currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; | 1022 | currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; |
1023 | break; | 1023 | break; |
1024 | 1024 | ||
1025 | case Qt::Key_Left: | 1025 | case Qt::Key_Left: |
1026 | if ( currentMenuNr == MENU_OPTIONS_MENU ) | 1026 | if ( currentMenuNr == MENU_OPTIONS_MENU ) |
1027 | { | 1027 | { |
1028 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) | 1028 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) |
1029 | { | 1029 | { |
1030 | currentGameType --; | 1030 | currentGameType --; |
1031 | if ( currentGameType < 0 ) | 1031 | if ( currentGameType < 0 ) |
1032 | currentGameType = NR_GAME_TYPES - 1; | 1032 | currentGameType = NR_GAME_TYPES - 1; |
1033 | } | 1033 | } |
1034 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) | 1034 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) |
1035 | { | 1035 | { |
1036 | currentGameDifficulty --; | 1036 | currentGameDifficulty --; |
1037 | if ( currentGameDifficulty < 0 ) | 1037 | if ( currentGameDifficulty < 0 ) |
1038 | currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; | 1038 | currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; |
1039 | } | 1039 | } |
1040 | } | 1040 | } |
1041 | break; | 1041 | break; |
1042 | 1042 | ||
1043 | case Qt::Key_Right: | 1043 | case Qt::Key_Right: |
1044 | if ( currentMenuNr == MENU_OPTIONS_MENU ) | 1044 | if ( currentMenuNr == MENU_OPTIONS_MENU ) |
1045 | { | 1045 | { |
1046 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) | 1046 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) |
1047 | { | 1047 | { |
1048 | currentGameType ++; | 1048 | currentGameType ++; |
1049 | if ( currentGameType == NR_GAME_TYPES ) | 1049 | if ( currentGameType == NR_GAME_TYPES ) |
1050 | currentGameType = 0; | 1050 | currentGameType = 0; |
1051 | } | 1051 | } |
1052 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) | 1052 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) |
1053 | { | 1053 | { |
1054 | currentGameDifficulty ++; | 1054 | currentGameDifficulty ++; |
1055 | if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) | 1055 | if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) |
1056 | currentGameDifficulty = 0; | 1056 | currentGameDifficulty = 0; |
1057 | } | 1057 | } |
1058 | } | 1058 | } |
1059 | break; | 1059 | break; |
1060 | 1060 | ||
1061 | case Qt::Key_Space: | 1061 | case Qt::Key_Space: |
1062 | case Qt::Key_Return: | 1062 | case Qt::Key_Return: |
1063 | case Qt::Key_Enter: | 1063 | case Qt::Key_Enter: |
1064 | dealWithMenuSelection(); | 1064 | dealWithMenuSelection(); |
1065 | break; | 1065 | break; |
1066 | } | 1066 | } |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | void SFCave :: displayMenu() | 1069 | void SFCave :: displayMenu() |
1070 | { | 1070 | { |
1071 | offscreen->fill( Qt::black ); | 1071 | offscreen->fill( Qt::black ); |
1072 | 1072 | ||
1073 | QPainter p( offscreen ); | 1073 | QPainter p( offscreen ); |
1074 | p.setPen( Qt::white ); | 1074 | p.setPen( Qt::white ); |
1075 | 1075 | ||
1076 | QFont f( "Helvetica", 16 ); | 1076 | QFont f( "Helvetica", 16 ); |
1077 | p.setFont( f ); | 1077 | p.setFont( f ); |
1078 | 1078 | ||
1079 | QFontMetrics fm = p.fontMetrics(); | 1079 | QFontMetrics fm = p.fontMetrics(); |
1080 | 1080 | ||
1081 | QString text = "SFCave"; | 1081 | QString text = "SFCave"; |
1082 | p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); | 1082 | p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); |
1083 | 1083 | ||
1084 | text = "Written by Andy Qua"; | 1084 | text = "Written by Andy Qua"; |
1085 | p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); | 1085 | p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); |
1086 | 1086 | ||
1087 | // Draw options | 1087 | // Draw options |
1088 | int pos = 140; | 1088 | int pos = 140; |
1089 | for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) | 1089 | for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) |
1090 | { | 1090 | { |
1091 | if ( currentMenuOption[currentMenuNr] == i ) | 1091 | if ( currentMenuOption[currentMenuNr] == i ) |
1092 | p.setPen( Qt::yellow ); | 1092 | p.setPen( Qt::yellow ); |
1093 | else | 1093 | else |
1094 | p.setPen( Qt::white ); | 1094 | p.setPen( Qt::white ); |
1095 | 1095 | ||
1096 | QString text; | 1096 | QString text; |
1097 | if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) | 1097 | if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) |
diff --git a/noncore/settings/aqpkg/settingsimpl.cpp b/noncore/settings/aqpkg/settingsimpl.cpp index 7ffa1d6..0886e69 100644 --- a/noncore/settings/aqpkg/settingsimpl.cpp +++ b/noncore/settings/aqpkg/settingsimpl.cpp | |||
@@ -254,193 +254,193 @@ QWidget *SettingsImpl :: initProxyTab() | |||
254 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), container ); | 254 | QPushButton *btn = new QPushButton( Opie::Core::OResource::loadPixmap( "edit", Opie::Core::OResource::SmallIcon ), tr( "Update" ), container ); |
255 | connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) ); | 255 | connect( btn, SIGNAL( clicked() ), this, SLOT( proxyApplyChanges() ) ); |
256 | layout->addMultiCellWidget( btn, 4, 4, 0, 1 ); | 256 | layout->addMultiCellWidget( btn, 4, 4, 0, 1 ); |
257 | 257 | ||
258 | return control; | 258 | return control; |
259 | } | 259 | } |
260 | 260 | ||
261 | void SettingsImpl :: setupData() | 261 | void SettingsImpl :: setupData() |
262 | { | 262 | { |
263 | // add servers | 263 | // add servers |
264 | QString serverName; | 264 | QString serverName; |
265 | QListIterator<Server> it( dataMgr->getServerList() ); | 265 | QListIterator<Server> it( dataMgr->getServerList() ); |
266 | for ( ; it.current(); ++it ) | 266 | for ( ; it.current(); ++it ) |
267 | { | 267 | { |
268 | serverName = it.current()->getServerName(); | 268 | serverName = it.current()->getServerName(); |
269 | if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS ) | 269 | if ( serverName == LOCAL_SERVER || serverName == LOCAL_IPKGS ) |
270 | continue; | 270 | continue; |
271 | 271 | ||
272 | servers->insertItem( serverName ); | 272 | servers->insertItem( serverName ); |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
276 | // add destinations | 276 | // add destinations |
277 | QListIterator<Destination> it2( dataMgr->getDestinationList() ); | 277 | QListIterator<Destination> it2( dataMgr->getDestinationList() ); |
278 | for ( ; it2.current(); ++it2 ) | 278 | for ( ; it2.current(); ++it2 ) |
279 | destinations->insertItem( it2.current()->getDestinationName() ); | 279 | destinations->insertItem( it2.current()->getDestinationName() ); |
280 | 280 | ||
281 | // setup proxy tab | 281 | // setup proxy tab |
282 | txtHttpProxy->setText( dataMgr->getHttpProxy() ); | 282 | txtHttpProxy->setText( dataMgr->getHttpProxy() ); |
283 | txtFtpProxy->setText( dataMgr->getFtpProxy() ); | 283 | txtFtpProxy->setText( dataMgr->getFtpProxy() ); |
284 | txtUsername->setText( dataMgr->getProxyUsername() ); | 284 | txtUsername->setText( dataMgr->getProxyUsername() ); |
285 | txtPassword->setText( dataMgr->getProxyPassword() ); | 285 | txtPassword->setText( dataMgr->getProxyPassword() ); |
286 | chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() ); | 286 | chkHttpProxyEnabled->setChecked( dataMgr->getHttpProxyEnabled() ); |
287 | chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() ); | 287 | chkFtpProxyEnabled->setChecked( dataMgr->getFtpProxyEnabled() ); |
288 | } | 288 | } |
289 | 289 | ||
290 | //------------------ Servers tab ---------------------- | 290 | //------------------ Servers tab ---------------------- |
291 | 291 | ||
292 | void SettingsImpl :: editServer( int sel ) | 292 | void SettingsImpl :: editServer( int sel ) |
293 | { | 293 | { |
294 | currentSelectedServer = sel; | 294 | currentSelectedServer = sel; |
295 | Server *s = dataMgr->getServer( servers->currentText() ); | 295 | Server *s = dataMgr->getServer( servers->currentText() ); |
296 | if ( s ) | 296 | if ( s ) |
297 | { | 297 | { |
298 | serverName = s->getServerName(); | 298 | serverName = s->getServerName(); |
299 | servername->setText( s->getServerName() ); | 299 | servername->setText( s->getServerName() ); |
300 | serverurl->setText( s->getServerUrl() ); | 300 | serverurl->setText( s->getServerUrl() ); |
301 | active->setChecked( s->isServerActive() ); | 301 | active->setChecked( s->isServerActive() ); |
302 | } | 302 | } |
303 | else | 303 | else |
304 | { | 304 | { |
305 | serverName = ""; | 305 | serverName = ""; |
306 | servername->setText( "" ); | 306 | servername->setText( "" ); |
307 | serverurl->setText( "" ); | 307 | serverurl->setText( "" ); |
308 | active->setChecked( false ); | 308 | active->setChecked( false ); |
309 | } | 309 | } |
310 | } | 310 | } |
311 | 311 | ||
312 | void SettingsImpl :: newServer() | 312 | void SettingsImpl :: newServer() |
313 | { | 313 | { |
314 | newserver = true; | 314 | newserver = true; |
315 | servername->setText( "" ); | 315 | servername->setText( "" ); |
316 | serverurl->setText( "" ); | 316 | serverurl->setText( "" ); |
317 | servername->setFocus(); | 317 | servername->setFocus(); |
318 | active->setChecked( true ); | 318 | active->setChecked( true ); |
319 | } | 319 | } |
320 | 320 | ||
321 | void SettingsImpl :: removeServer() | 321 | void SettingsImpl :: removeServer() |
322 | { | 322 | { |
323 | changed = true; | 323 | changed = true; |
324 | Server *s = dataMgr->getServer( servers->currentText() ); | 324 | Server *s = dataMgr->getServer( servers->currentText() ); |
325 | if ( s ) | 325 | if ( s ) |
326 | { | 326 | { |
327 | dataMgr->getServerList().removeRef( s ); | 327 | dataMgr->getServerList().removeRef( s ); |
328 | servers->removeItem( currentSelectedServer ); | 328 | servers->removeItem( currentSelectedServer ); |
329 | } | 329 | } |
330 | } | 330 | } |
331 | 331 | ||
332 | void SettingsImpl :: changeServerDetails() | 332 | void SettingsImpl :: changeServerDetails() |
333 | { | 333 | { |
334 | changed = true; | 334 | changed = true; |
335 | 335 | ||
336 | QString newName = servername->text(); | 336 | QString newName = servername->text(); |
337 | 337 | ||
338 | // Convert any spaces to underscores | 338 | // Convert any spaces to underscores |
339 | char *tmpStr = new char[newName.length() + 1]; | 339 | char *tmpStr = new char[newName.length() + 1]; |
340 | for ( unsigned int i = 0 ; i < newName.length() ; ++i ) | 340 | for ( unsigned int i = 0 ; i < newName.length() ; ++i ) |
341 | { | 341 | { |
342 | if ( newName[i] == ' ' ) | 342 | if ( newName[i] == ' ' ) |
343 | tmpStr[i] = '_'; | 343 | tmpStr[i] = '_'; |
344 | else | 344 | else |
345 | tmpStr[i] = newName[i].latin1(); | 345 | tmpStr[i] = newName[i].latin1(); |
346 | } | 346 | } |
347 | tmpStr[newName.length()] = '\0'; | 347 | tmpStr[newName.length()] = '\0'; |
348 | 348 | ||
349 | newName = tmpStr; | 349 | newName = tmpStr; |
350 | delete tmpStr; | 350 | delete [] tmpStr; |
351 | 351 | ||
352 | if ( !newserver ) | 352 | if ( !newserver ) |
353 | { | 353 | { |
354 | Server *s = dataMgr->getServer( servers->currentText() ); | 354 | Server *s = dataMgr->getServer( servers->currentText() ); |
355 | if ( s ) | 355 | if ( s ) |
356 | { | 356 | { |
357 | // Update url | 357 | // Update url |
358 | s->setServerUrl( serverurl->text() ); | 358 | s->setServerUrl( serverurl->text() ); |
359 | s->setActive( active->isChecked() ); | 359 | s->setActive( active->isChecked() ); |
360 | 360 | ||
361 | // Check if server name has changed, if it has then we need to replace the key in the map | 361 | // Check if server name has changed, if it has then we need to replace the key in the map |
362 | if ( serverName != newName ) | 362 | if ( serverName != newName ) |
363 | { | 363 | { |
364 | // Update server name | 364 | // Update server name |
365 | s->setServerName( newName ); | 365 | s->setServerName( newName ); |
366 | } | 366 | } |
367 | 367 | ||
368 | // Update list box | 368 | // Update list box |
369 | servers->changeItem( newName, currentSelectedServer ); | 369 | servers->changeItem( newName, currentSelectedServer ); |
370 | } | 370 | } |
371 | } | 371 | } |
372 | else | 372 | else |
373 | { | 373 | { |
374 | Server s( newName, serverurl->text() ); | 374 | Server s( newName, serverurl->text() ); |
375 | dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); | 375 | dataMgr->getServerList().append( new Server( newName, serverurl->text() ) ); |
376 | dataMgr->getServerList().last()->setActive( active->isChecked() ); | 376 | dataMgr->getServerList().last()->setActive( active->isChecked() ); |
377 | servers->insertItem( newName ); | 377 | servers->insertItem( newName ); |
378 | servers->setCurrentItem( servers->count() ); | 378 | servers->setCurrentItem( servers->count() ); |
379 | newserver = false; | 379 | newserver = false; |
380 | } | 380 | } |
381 | } | 381 | } |
382 | 382 | ||
383 | //------------------ Destinations tab ---------------------- | 383 | //------------------ Destinations tab ---------------------- |
384 | 384 | ||
385 | void SettingsImpl :: editDestination( int sel ) | 385 | void SettingsImpl :: editDestination( int sel ) |
386 | { | 386 | { |
387 | currentSelectedDestination = sel; | 387 | currentSelectedDestination = sel; |
388 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 388 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
389 | if ( d ) | 389 | if ( d ) |
390 | { | 390 | { |
391 | destinationName = d->getDestinationName(); | 391 | destinationName = d->getDestinationName(); |
392 | destinationname->setText( d->getDestinationName() ); | 392 | destinationname->setText( d->getDestinationName() ); |
393 | destinationurl->setText( d->getDestinationPath() ); | 393 | destinationurl->setText( d->getDestinationPath() ); |
394 | linkToRoot->setChecked( d->linkToRoot() ); | 394 | linkToRoot->setChecked( d->linkToRoot() ); |
395 | } | 395 | } |
396 | else | 396 | else |
397 | { | 397 | { |
398 | destinationName = ""; | 398 | destinationName = ""; |
399 | destinationname->setText( "" ); | 399 | destinationname->setText( "" ); |
400 | destinationurl->setText( "" ); | 400 | destinationurl->setText( "" ); |
401 | linkToRoot->setChecked( false ); | 401 | linkToRoot->setChecked( false ); |
402 | } | 402 | } |
403 | } | 403 | } |
404 | 404 | ||
405 | void SettingsImpl :: newDestination() | 405 | void SettingsImpl :: newDestination() |
406 | { | 406 | { |
407 | newdestination = true; | 407 | newdestination = true; |
408 | destinationname->setText( "" ); | 408 | destinationname->setText( "" ); |
409 | destinationurl->setText( "" ); | 409 | destinationurl->setText( "" ); |
410 | destinationname->setFocus(); | 410 | destinationname->setFocus(); |
411 | linkToRoot->setChecked( true ); | 411 | linkToRoot->setChecked( true ); |
412 | } | 412 | } |
413 | 413 | ||
414 | void SettingsImpl :: removeDestination() | 414 | void SettingsImpl :: removeDestination() |
415 | { | 415 | { |
416 | changed = true; | 416 | changed = true; |
417 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 417 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
418 | if ( d ) | 418 | if ( d ) |
419 | { | 419 | { |
420 | dataMgr->getDestinationList().removeRef( d ); | 420 | dataMgr->getDestinationList().removeRef( d ); |
421 | destinations->removeItem( currentSelectedDestination ); | 421 | destinations->removeItem( currentSelectedDestination ); |
422 | } | 422 | } |
423 | } | 423 | } |
424 | 424 | ||
425 | void SettingsImpl :: changeDestinationDetails() | 425 | void SettingsImpl :: changeDestinationDetails() |
426 | { | 426 | { |
427 | changed = true; | 427 | changed = true; |
428 | 428 | ||
429 | #ifdef QWS | 429 | #ifdef QWS |
430 | Config cfg( "aqpkg" ); | 430 | Config cfg( "aqpkg" ); |
431 | cfg.setGroup( "destinations" ); | 431 | cfg.setGroup( "destinations" ); |
432 | #endif | 432 | #endif |
433 | 433 | ||
434 | QString newName = destinationname->text(); | 434 | QString newName = destinationname->text(); |
435 | if ( !newdestination ) | 435 | if ( !newdestination ) |
436 | { | 436 | { |
437 | Destination *d = dataMgr->getDestination( destinations->currentText() ); | 437 | Destination *d = dataMgr->getDestination( destinations->currentText() ); |
438 | if ( d ) | 438 | if ( d ) |
439 | { | 439 | { |
440 | // Update url | 440 | // Update url |
441 | d->setDestinationPath( destinationurl->text() ); | 441 | d->setDestinationPath( destinationurl->text() ); |
442 | d->linkToRoot( linkToRoot->isChecked() ); | 442 | d->linkToRoot( linkToRoot->isChecked() ); |
443 | 443 | ||
444 | // Check if server name has changed, if it has then we need to replace the key in the map | 444 | // Check if server name has changed, if it has then we need to replace the key in the map |
445 | if ( destinationName != newName ) | 445 | if ( destinationName != newName ) |
446 | { | 446 | { |
diff --git a/noncore/settings/aqpkg/version.cpp b/noncore/settings/aqpkg/version.cpp index 59e6f3f..ce2de7b 100644 --- a/noncore/settings/aqpkg/version.cpp +++ b/noncore/settings/aqpkg/version.cpp | |||
@@ -1,137 +1,137 @@ | |||
1 | /* | 1 | /* |
2 | * libdpkg - Debian packaging suite library routines | 2 | * libdpkg - Debian packaging suite library routines |
3 | * vercmp.c - comparison of version numbers | 3 | * vercmp.c - comparison of version numbers |
4 | * | 4 | * |
5 | * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk> | 5 | * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk> |
6 | * | 6 | * |
7 | * This is free software; you can redistribute it and/or modify | 7 | * This is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as | 8 | * it under the terms of the GNU General Public License as |
9 | * published by the Free Software Foundation; either version 2, | 9 | * published by the Free Software Foundation; either version 2, |
10 | * or (at your option) any later version. | 10 | * or (at your option) any later version. |
11 | * | 11 | * |
12 | * This is distributed in the hope that it will be useful, but | 12 | * This is distributed in the hope that it will be useful, but |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. |
16 | * | 16 | * |
17 | * You should have received a copy of the GNU General Public | 17 | * You should have received a copy of the GNU General Public |
18 | * License along with dpkg; if not, write to the Free Software | 18 | * License along with dpkg; if not, write to the Free Software |
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | */ | 20 | */ |
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <ctype.h> | 23 | #include <ctype.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | 25 | ||
26 | #include <qobject.h> | 26 | #include <qobject.h> |
27 | 27 | ||
28 | //# define _(Text) Text | 28 | //# define _(Text) Text |
29 | 29 | ||
30 | class versionrevision | 30 | class versionrevision |
31 | { | 31 | { |
32 | public: | 32 | public: |
33 | versionrevision() | 33 | versionrevision() |
34 | { | 34 | { |
35 | version = 0; | 35 | version = 0; |
36 | } | 36 | } |
37 | 37 | ||
38 | ~versionrevision() | 38 | ~versionrevision() |
39 | { | 39 | { |
40 | if ( version ) | 40 | if ( version ) |
41 | delete version; | 41 | delete [] version; |
42 | } | 42 | } |
43 | 43 | ||
44 | void setVersion( const char *str ) | 44 | void setVersion( const char *str ) |
45 | { | 45 | { |
46 | version = new char[(strlen(str)+1)]; | 46 | version = new char[(strlen(str)+1)]; |
47 | strcpy( version, str ); | 47 | strcpy( version, str ); |
48 | } | 48 | } |
49 | 49 | ||
50 | unsigned long epoch; | 50 | unsigned long epoch; |
51 | char *version; | 51 | char *version; |
52 | const char *revision; | 52 | const char *revision; |
53 | const char *familiar_revision; | 53 | const char *familiar_revision; |
54 | }; | 54 | }; |
55 | 55 | ||
56 | static int verrevcmp(const char *val, const char *ref) | 56 | static int verrevcmp(const char *val, const char *ref) |
57 | { | 57 | { |
58 | int vc, rc; | 58 | int vc, rc; |
59 | long vl, rl; | 59 | long vl, rl; |
60 | const char *vp, *rp; | 60 | const char *vp, *rp; |
61 | 61 | ||
62 | if (!val) val= ""; | 62 | if (!val) val= ""; |
63 | if (!ref) ref= ""; | 63 | if (!ref) ref= ""; |
64 | for (;;) { | 64 | for (;;) { |
65 | vp= val; while (*vp && !isdigit(*vp)) vp++; | 65 | vp= val; while (*vp && !isdigit(*vp)) vp++; |
66 | rp= ref; while (*rp && !isdigit(*rp)) rp++; | 66 | rp= ref; while (*rp && !isdigit(*rp)) rp++; |
67 | for (;;) { | 67 | for (;;) { |
68 | vc= val == vp ? 0 : *val++; | 68 | vc= val == vp ? 0 : *val++; |
69 | rc= ref == rp ? 0 : *ref++; | 69 | rc= ref == rp ? 0 : *ref++; |
70 | if (!rc && !vc) break; | 70 | if (!rc && !vc) break; |
71 | if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ | 71 | if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ |
72 | if (rc && !isalpha(rc)) rc += 256; | 72 | if (rc && !isalpha(rc)) rc += 256; |
73 | if (vc != rc) return vc - rc; | 73 | if (vc != rc) return vc - rc; |
74 | } | 74 | } |
75 | val= vp; | 75 | val= vp; |
76 | ref= rp; | 76 | ref= rp; |
77 | vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); | 77 | vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); |
78 | rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); | 78 | rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); |
79 | if (vl != rl) return vl - rl; | 79 | if (vl != rl) return vl - rl; |
80 | if (!*val && !*ref) return 0; | 80 | if (!*val && !*ref) return 0; |
81 | if (!*val) return -1; | 81 | if (!*val) return -1; |
82 | if (!*ref) return +1; | 82 | if (!*ref) return +1; |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | int versioncompare(const struct versionrevision *version, | 86 | int versioncompare(const struct versionrevision *version, |
87 | const struct versionrevision *refversion) | 87 | const struct versionrevision *refversion) |
88 | { | 88 | { |
89 | int r; | 89 | int r; |
90 | 90 | ||
91 | if (version->epoch > refversion->epoch) return 1; | 91 | if (version->epoch > refversion->epoch) return 1; |
92 | if (version->epoch < refversion->epoch) return -1; | 92 | if (version->epoch < refversion->epoch) return -1; |
93 | r= verrevcmp(version->version,refversion->version); if (r) return r; | 93 | r= verrevcmp(version->version,refversion->version); if (r) return r; |
94 | r= verrevcmp(version->revision,refversion->revision); if (r) return r; | 94 | r= verrevcmp(version->revision,refversion->revision); if (r) return r; |
95 | return verrevcmp(version->familiar_revision,refversion->familiar_revision); | 95 | return verrevcmp(version->familiar_revision,refversion->familiar_revision); |
96 | } | 96 | } |
97 | 97 | ||
98 | int versionsatisfied3(const struct versionrevision *it, | 98 | int versionsatisfied3(const struct versionrevision *it, |
99 | const struct versionrevision *ref, | 99 | const struct versionrevision *ref, |
100 | const char *op) | 100 | const char *op) |
101 | { | 101 | { |
102 | int r; | 102 | int r; |
103 | r= versioncompare(it,ref); | 103 | r= versioncompare(it,ref); |
104 | if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) | 104 | if (strcmp(op, "<=") == 0 || strcmp(op, "<") == 0) |
105 | return r <= 0; | 105 | return r <= 0; |
106 | if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) | 106 | if (strcmp(op, ">=") == 0 || strcmp(op, ">") == 0) |
107 | return r >= 0; | 107 | return r >= 0; |
108 | if (strcmp(op, "<<") == 0) | 108 | if (strcmp(op, "<<") == 0) |
109 | return r < 0; | 109 | return r < 0; |
110 | if (strcmp(op, ">>") == 0) | 110 | if (strcmp(op, ">>") == 0) |
111 | return r > 0; | 111 | return r > 0; |
112 | if (strcmp(op, "=") == 0) | 112 | if (strcmp(op, "=") == 0) |
113 | return r == 0; | 113 | return r == 0; |
114 | // fprintf(stderr, "unknown operator: %s", op); | 114 | // fprintf(stderr, "unknown operator: %s", op); |
115 | 115 | ||
116 | exit(1); | 116 | exit(1); |
117 | } | 117 | } |
118 | 118 | ||
119 | const char *parseversion(struct versionrevision *rversion, const char *string) | 119 | const char *parseversion(struct versionrevision *rversion, const char *string) |
120 | { | 120 | { |
121 | char *hyphen, *colon, *eepochcolon; | 121 | char *hyphen, *colon, *eepochcolon; |
122 | unsigned long epoch; | 122 | unsigned long epoch; |
123 | 123 | ||
124 | if ( !*string ) | 124 | if ( !*string ) |
125 | return QObject::tr( "Version string is empty." ); | 125 | return QObject::tr( "Version string is empty." ); |
126 | 126 | ||
127 | colon= strchr(string,':'); | 127 | colon= strchr(string,':'); |
128 | if (colon) { | 128 | if (colon) { |
129 | epoch= strtoul(string,&eepochcolon,10); | 129 | epoch= strtoul(string,&eepochcolon,10); |
130 | if ( colon != eepochcolon ) | 130 | if ( colon != eepochcolon ) |
131 | return QObject::tr( "Epoch in version is not number." ); | 131 | return QObject::tr( "Epoch in version is not number." ); |
132 | if ( !*++colon ) | 132 | if ( !*++colon ) |
133 | return QObject::tr( "Nothing after colon in version number." ); | 133 | return QObject::tr( "Nothing after colon in version number." ); |
134 | string= colon; | 134 | string= colon; |
135 | rversion->epoch= epoch; | 135 | rversion->epoch= epoch; |
136 | } else { | 136 | } else { |
137 | rversion->epoch= 0; | 137 | rversion->epoch= 0; |