summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/om3u.cpp3
-rw-r--r--libopie2/opiemm/opieexif.cpp8
-rw-r--r--noncore/apps/opie-console/filereceive.cpp4
-rw-r--r--noncore/apps/opie-console/filetransfer.cpp4
-rw-r--r--noncore/apps/opie-console/logger.cpp4
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp3
-rw-r--r--noncore/apps/opie-console/script.cpp6
-rw-r--r--noncore/apps/opie-gutenbrowser/gutenbrowser.cpp26
-rw-r--r--noncore/apps/opie-gutenbrowser/helpwindow.cpp64
-rw-r--r--noncore/graphics/opie-eye/slave/bmp_slave.cpp4
-rw-r--r--noncore/net/ftplib/ftplib.c8
-rw-r--r--noncore/todayplugins/stockticker/stockticker/helpwindow.cpp42
-rw-r--r--noncore/todayplugins/weather/weatherpluginwidget.cpp5
-rw-r--r--noncore/tools/opie-sh/inputdialog.cpp20
14 files changed, 109 insertions, 92 deletions
diff --git a/core/multimedia/opieplayer/om3u.cpp b/core/multimedia/opieplayer/om3u.cpp
index 48aa47e..68ea015 100644
--- a/core/multimedia/opieplayer/om3u.cpp
+++ b/core/multimedia/opieplayer/om3u.cpp
@@ -1,146 +1,147 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 Copyright (C) 2002 L. Potter <ljp@llornkcor.com> 4 Copyright (C) 2002 L. Potter <ljp@llornkcor.com>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17 : ..    .:,     . . . without even the implied warranty of 17 : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22:     =  ...= . :.=- 22:     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include "om3u.h" 31#include "om3u.h"
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35 35
36 36
37static inline QString fullBaseName ( const QFileInfo &fi ) 37static inline QString fullBaseName ( const QFileInfo &fi )
38{ 38{
39 QString str = fi. fileName ( ); 39 QString str = fi. fileName ( );
40 return str. left ( str. findRev ( '.' )); 40 return str. left ( str. findRev ( '.' ));
41} 41}
42 42
43 43
44//extern PlayListWidget *playList; 44//extern PlayListWidget *playList;
45 45
46Om3u::Om3u( const QString &filePath, int mode) 46Om3u::Om3u( const QString &filePath, int mode)
47 : QStringList (){ 47 : QStringList (){
48//odebug << "<<<<<<<new m3u "+filePath << oendl; 48//odebug << "<<<<<<<new m3u "+filePath << oendl;
49 f.setName(filePath); 49 f.setName(filePath);
50 f.open(mode); 50 if ( !f.open(mode) )
51 owarn << "Failed to open file " << f.name() << oendl;
51} 52}
52 53
53Om3u::~Om3u(){} 54Om3u::~Om3u(){}
54 55
55void Om3u::readM3u() { 56void Om3u::readM3u() {
56// odebug << "<<<<<<reading m3u "+f.name() << oendl; 57// odebug << "<<<<<<reading m3u "+f.name() << oendl;
57 QTextStream t(&f); 58 QTextStream t(&f);
58 t.setEncoding(QTextStream::UnicodeUTF8); 59 t.setEncoding(QTextStream::UnicodeUTF8);
59 QString s; 60 QString s;
60 while ( !t.atEnd() ) { 61 while ( !t.atEnd() ) {
61 s=t.readLine(); 62 s=t.readLine();
62 // odebug << s << oendl; 63 // odebug << s << oendl;
63 if( s.find( "#", 0, TRUE) == -1 ) { 64 if( s.find( "#", 0, TRUE) == -1 ) {
64 if( s.left(2) == "E:" || s.left(2) == "P:" ) { 65 if( s.left(2) == "E:" || s.left(2) == "P:" ) {
65 s = s.right( s.length() -2 ); 66 s = s.right( s.length() -2 );
66 QFileInfo f( s ); 67 QFileInfo f( s );
67 QString name = fullBaseName ( f ); 68 QString name = fullBaseName ( f );
68 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); 69 name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 );
69 s=s.replace( QRegExp( "\\" ), "/" ); 70 s=s.replace( QRegExp( "\\" ), "/" );
70 append(s); 71 append(s);
71 // odebug << s << oendl; 72 // odebug << s << oendl;
72 } else { // is url 73 } else { // is url
73 s.replace( QRegExp( "%20" )," " ); 74 s.replace( QRegExp( "%20" )," " );
74 QString name; 75 QString name;
75 // if( name.left( 4 ) == "http" ) { 76 // if( name.left( 4 ) == "http" ) {
76 // name = s.right( s.length() - 7 ); 77 // name = s.right( s.length() - 7 );
77 // } else { 78 // } else {
78 name = s; 79 name = s;
79 // } 80 // }
80 append(name); 81 append(name);
81 // odebug << name << oendl; 82 // odebug << name << oendl;
82 } 83 }
83 } 84 }
84 } 85 }
85} 86}
86 87
87void Om3u::readPls() { //it's a pls file 88void Om3u::readPls() { //it's a pls file
88 QTextStream t( &f ); 89 QTextStream t( &f );
89 t.setEncoding(QTextStream::UnicodeUTF8); 90 t.setEncoding(QTextStream::UnicodeUTF8);
90 QString s; 91 QString s;
91 while ( !t.atEnd() ) { 92 while ( !t.atEnd() ) {
92 s = t.readLine(); 93 s = t.readLine();
93 if( s.left(4) == "File" ) { 94 if( s.left(4) == "File" ) {
94 s = s.right( s.length() - 6 ); 95 s = s.right( s.length() - 6 );
95 s.replace( QRegExp( "%20" )," "); 96 s.replace( QRegExp( "%20" )," ");
96// odebug << "adding " + s + " to playlist" << oendl; 97// odebug << "adding " + s + " to playlist" << oendl;
97 // numberofentries=2 98 // numberofentries=2
98 // File1=http 99 // File1=http
99 // Title 100 // Title
100 // Length 101 // Length
101 // Version 102 // Version
102 // File2=http 103 // File2=http
103 s = s.replace( QRegExp( "\\" ), "/" ); 104 s = s.replace( QRegExp( "\\" ), "/" );
104 QFileInfo f( s ); 105 QFileInfo f( s );
105 QString name = fullBaseName ( f ); 106 QString name = fullBaseName ( f );
106 if( name.left( 4 ) == "http" ) { 107 if( name.left( 4 ) == "http" ) {
107 name = s.right( s.length() - 7); 108 name = s.right( s.length() - 7);
108 } else { 109 } else {
109 name = s; 110 name = s;
110 } 111 }
111 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); 112 name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 );
112 if( s.at( s.length() - 4) == '.') // if this is probably a file 113 if( s.at( s.length() - 4) == '.') // if this is probably a file
113 append(s); 114 append(s);
114 else { //if its a url 115 else { //if its a url
115 if( name.right( 1 ).find( '/' ) == -1) { 116 if( name.right( 1 ).find( '/' ) == -1) {
116 s += "/"; 117 s += "/";
117 } 118 }
118 append(s); 119 append(s);
119 } 120 }
120 } 121 }
121 } 122 }
122} 123}
123 124
124void Om3u::write() { //writes list to m3u file 125void Om3u::write() { //writes list to m3u file
125 QString list; 126 QString list;
126 QTextStream t(&f); 127 QTextStream t(&f);
127 t.setEncoding(QTextStream::UnicodeUTF8); 128 t.setEncoding(QTextStream::UnicodeUTF8);
128 if(count()>0) { 129 if(count()>0) {
129 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { 130 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
130 // odebug << *it << oendl; 131 // odebug << *it << oendl;
131 t << *it << "\n"; 132 t << *it << "\n";
132 } 133 }
133 } 134 }
134// f.close(); 135// f.close();
135} 136}
136 137
137void Om3u::add(const QString &filePath) { //adds to m3u file 138void Om3u::add(const QString &filePath) { //adds to m3u file
138 append(filePath); 139 append(filePath);
139} 140}
140 141
141void Om3u::remove(const QString &filePath) { //removes from m3u list 142void Om3u::remove(const QString &filePath) { //removes from m3u list
142 QString list, currentFile; 143 QString list, currentFile;
143 if(count()>0) { 144 if(count()>0) {
144 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) { 145 for ( QStringList::ConstIterator it = begin(); it != end(); ++it ) {
145 currentFile=*it; 146 currentFile=*it;
146 // odebug << *it << oendl; 147 // odebug << *it << oendl;
diff --git a/libopie2/opiemm/opieexif.cpp b/libopie2/opiemm/opieexif.cpp
index de49937..653216c 100644
--- a/libopie2/opiemm/opieexif.cpp
+++ b/libopie2/opiemm/opieexif.cpp
@@ -112,193 +112,193 @@ namespace MM {
112 112
113class FatalError { 113class FatalError {
114 const char* ex; 114 const char* ex;
115public: 115public:
116 FatalError(const char* s) { ex = s; } 116 FatalError(const char* s) { ex = s; }
117 void debug_print() const { owarn << "exception: " << ex << "" << oendl; } 117 void debug_print() const { owarn << "exception: " << ex << "" << oendl; }
118}; 118};
119 119
120ExifData::TagTable_t ProcessTable[] = { 120ExifData::TagTable_t ProcessTable[] = {
121 { M_SOF0, "Baseline"}, 121 { M_SOF0, "Baseline"},
122 { M_SOF1, "Extended sequential"}, 122 { M_SOF1, "Extended sequential"},
123 { M_SOF2, "Progressive"}, 123 { M_SOF2, "Progressive"},
124 { M_SOF3, "Lossless"}, 124 { M_SOF3, "Lossless"},
125 { M_SOF5, "Differential sequential"}, 125 { M_SOF5, "Differential sequential"},
126 { M_SOF6, "Differential progressive"}, 126 { M_SOF6, "Differential progressive"},
127 { M_SOF7, "Differential lossless"}, 127 { M_SOF7, "Differential lossless"},
128 { M_SOF9, "Extended sequential, arithmetic coding"}, 128 { M_SOF9, "Extended sequential, arithmetic coding"},
129 { M_SOF10, "Progressive, arithmetic coding"}, 129 { M_SOF10, "Progressive, arithmetic coding"},
130 { M_SOF11, "Lossless, arithmetic coding"}, 130 { M_SOF11, "Lossless, arithmetic coding"},
131 { M_SOF13, "Differential sequential, arithmetic coding"}, 131 { M_SOF13, "Differential sequential, arithmetic coding"},
132 { M_SOF14, "Differential progressive, arithmetic coding"}, 132 { M_SOF14, "Differential progressive, arithmetic coding"},
133 { M_SOF15, "Differential lossless, arithmetic coding"}, 133 { M_SOF15, "Differential lossless, arithmetic coding"},
134 { 0, "Unknown"} 134 { 0, "Unknown"}
135}; 135};
136 136
137//-------------------------------------------------------------------------- 137//--------------------------------------------------------------------------
138// Parse the marker stream until SOS or EOI is seen; 138// Parse the marker stream until SOS or EOI is seen;
139//-------------------------------------------------------------------------- 139//--------------------------------------------------------------------------
140int ExifData::ReadJpegSections (QFile & infile, ReadMode_t ReadMode) 140int ExifData::ReadJpegSections (QFile & infile, ReadMode_t ReadMode)
141{ 141{
142 int a; 142 int a;
143 143
144 a = infile.getch(); 144 a = infile.getch();
145 145
146 if (a != 0xff || infile.getch() != M_SOI) { 146 if (a != 0xff || infile.getch() != M_SOI) {
147 SectionsRead = 0; 147 SectionsRead = 0;
148 return false; 148 return false;
149 } 149 }
150 for(SectionsRead = 0; SectionsRead < MAX_SECTIONS-1; ){ 150 for(SectionsRead = 0; SectionsRead < MAX_SECTIONS-1; ){
151 int marker = 0; 151 int marker = 0;
152 int got; 152 int got;
153 unsigned int ll,lh; 153 unsigned int ll,lh;
154 unsigned int itemlen; 154 unsigned int itemlen;
155 uchar * Data; 155 uchar * Data;
156 156
157 for (a=0;a<7;a++){ 157 for (a=0;a<7;a++){
158 marker = infile.getch(); 158 marker = infile.getch();
159 if (marker != 0xff) break; 159 if (marker != 0xff) break;
160 160
161 if (a >= 6){ 161 if (a >= 6){
162 162
163 owarn << "too many padding bytes" << oendl; 163 owarn << "too many padding bytes" << oendl;
164 return false; 164 return false;
165 165
166 } 166 }
167 } 167 }
168 168
169 if (marker == 0xff){ 169 if (marker == 0xff){
170 // 0xff is legal padding, but if we get that many, something's wrong. 170 // 0xff is legal padding, but if we get that many, something's wrong.
171 return false; 171 return false;
172 } 172 }
173 173
174 Sections[SectionsRead].Type = marker; 174 Sections[SectionsRead].Type = marker;
175 175
176 // Read the length of the section. 176 // Read the length of the section.
177 lh = (uchar) infile.getch(); 177 lh = (uchar) infile.getch();
178 ll = (uchar) infile.getch(); 178 ll = (uchar) infile.getch();
179 179
180 itemlen = (lh << 8) | ll; 180 itemlen = (lh << 8) | ll;
181 181
182 if (itemlen < 2) { 182 if (itemlen < 2) {
183 return false;; 183 return false;;
184 } 184 }
185 185
186 Sections[SectionsRead].Size = itemlen; 186 Sections[SectionsRead].Size = itemlen;
187 187
188 Data = (uchar *)malloc(itemlen+1); // Add 1 to allow sticking a 0 at the end. 188 Data = (uchar *)malloc(itemlen+1); // Add 1 to allow sticking a 0 at the end.
189 Sections[SectionsRead].Data = Data; 189 Sections[SectionsRead].Data = Data;
190 190
191 // Store first two pre-read bytes. 191 // Store first two pre-read bytes.
192 Data[0] = (uchar)lh; 192 Data[0] = (uchar)lh;
193 Data[1] = (uchar)ll; 193 Data[1] = (uchar)ll;
194 194
195 got = infile.readBlock((char*)Data+2, itemlen-2); // Read the whole section. 195 got = infile.readBlock((char*)Data+2, itemlen-2); // Read the whole section.
196 if (( unsigned ) got != itemlen-2){ 196 if (( unsigned ) got != itemlen-2){
197 return false; 197 return false;
198 } 198 }
199 SectionsRead++; 199 SectionsRead++;
200 200
201 switch(marker){ 201 switch(marker){
202 202
203 case M_SOS: // stop before hitting compressed data 203 case M_SOS: // stop before hitting compressed data
204 // If reading entire image is requested, read the rest of the data. 204 // If reading entire image is requested, read the rest of the data.
205 if (ReadMode & READ_IMAGE){ 205 if (ReadMode & READ_IMAGE){
206 unsigned long size; 206 unsigned long size;
207 207
208 size = QMAX( 0ul, infile.size()-infile.at() ); 208 size = infile.size()-infile.at();
209 Data = (uchar *)malloc(size); 209 Data = (uchar *)malloc(size);
210 if (Data == NULL){ 210 if (Data == NULL){
211 return false; 211 return false;
212 } 212 }
213 213
214 got = infile.readBlock((char*)Data, size); 214 got = infile.readBlock((char*)Data, size);
215 if (( unsigned ) got != size){ 215 if (( unsigned ) got != size){
216 return false; 216 return false;
217 } 217 }
218 218
219 Sections[SectionsRead].Data = Data; 219 Sections[SectionsRead].Data = Data;
220 Sections[SectionsRead].Size = size; 220 Sections[SectionsRead].Size = size;
221 Sections[SectionsRead].Type = PSEUDO_IMAGE_MARKER; 221 Sections[SectionsRead].Type = PSEUDO_IMAGE_MARKER;
222 SectionsRead ++; 222 SectionsRead ++;
223 //HaveAll = 1; 223 //HaveAll = 1;
224 } 224 }
225 return true; 225 return true;
226 226
227 case M_EOI: // in case it's a tables-only JPEG stream 227 case M_EOI: // in case it's a tables-only JPEG stream
228 owarn << "No image in jpeg!" << oendl; 228 owarn << "No image in jpeg!" << oendl;
229 return false; 229 return false;
230 230
231 case M_COM: // Comment section 231 case M_COM: // Comment section
232 // pieczy 2002-02-12 232 // pieczy 2002-02-12
233 // now the User comment goes to UserComment 233 // now the User comment goes to UserComment
234 // so we can store a Comment section also in READ_EXIF mode 234 // so we can store a Comment section also in READ_EXIF mode
235 process_COM(Data, itemlen); 235 process_COM(Data, itemlen);
236 break; 236 break;
237 237
238 case M_JFIF: 238 case M_JFIF:
239 // Regular jpegs always have this tag, exif images have the exif 239 // Regular jpegs always have this tag, exif images have the exif
240 // marker instead, althogh ACDsee will write images with both markers. 240 // marker instead, althogh ACDsee will write images with both markers.
241 // this program will re-create this marker on absence of exif marker. 241 // this program will re-create this marker on absence of exif marker.
242 // hence no need to keep the copy from the file. 242 // hence no need to keep the copy from the file.
243 free(Sections[--SectionsRead].Data); 243 free(Sections[--SectionsRead].Data);
244 break; 244 break;
245 245
246 case M_EXIF: 246 case M_EXIF:
247 // Seen files from some 'U-lead' software with Vivitar scanner 247 // Seen files from some 'U-lead' software with Vivitar scanner
248 // that uses marker 31 for non exif stuff. Thus make sure 248 // that uses marker 31 for non exif stuff. Thus make sure
249 // it says 'Exif' in the section before treating it as exif. 249 // it says 'Exif' in the section before treating it as exif.
250 if ((ReadMode & READ_EXIF) && memcmp(Data+2, "Exif", 4) == 0){ 250 if ((ReadMode & READ_EXIF) && memcmp(Data+2, "Exif", 4) == 0){
251 process_EXIF((uchar *)Data, itemlen); 251 process_EXIF((uchar *)Data, itemlen);
252 }else{ 252 }else{
253 // Discard this section. 253 // Discard this section.
254 free(Sections[--SectionsRead].Data); 254 free(Sections[--SectionsRead].Data);
255 } 255 }
256 break; 256 break;
257 257
258 case M_SOF0: 258 case M_SOF0:
259 case M_SOF1: 259 case M_SOF1:
260 case M_SOF2: 260 case M_SOF2:
261 case M_SOF3: 261 case M_SOF3:
262 case M_SOF5: 262 case M_SOF5:
263 case M_SOF6: 263 case M_SOF6:
264 case M_SOF7: 264 case M_SOF7:
265 case M_SOF9: 265 case M_SOF9:
266 case M_SOF10: 266 case M_SOF10:
267 case M_SOF11: 267 case M_SOF11:
268 case M_SOF13: 268 case M_SOF13:
269 case M_SOF14: 269 case M_SOF14:
270 case M_SOF15: 270 case M_SOF15:
271 process_SOFn(Data, marker); 271 process_SOFn(Data, marker);
272 default: 272 default:
273 break; 273 break;
274 break; 274 break;
275 } 275 }
276 } 276 }
277 return true; 277 return true;
278} 278}
279 279
280//-------------------------------------------------------------------------- 280//--------------------------------------------------------------------------
281// Discard read data. 281// Discard read data.
282//-------------------------------------------------------------------------- 282//--------------------------------------------------------------------------
283void ExifData::DiscardData(void) 283void ExifData::DiscardData(void)
284{ 284{
285 for (int a=0; a < SectionsRead; a++) 285 for (int a=0; a < SectionsRead; a++)
286 free(Sections[a].Data); 286 free(Sections[a].Data);
287 SectionsRead = 0; 287 SectionsRead = 0;
288} 288}
289 289
290//-------------------------------------------------------------------------- 290//--------------------------------------------------------------------------
291// Convert a 16 bit unsigned value from file's native byte order 291// Convert a 16 bit unsigned value from file's native byte order
292//-------------------------------------------------------------------------- 292//--------------------------------------------------------------------------
293int ExifData::Get16u(void * Short) 293int ExifData::Get16u(void * Short)
294{ 294{
295 if (MotorolaOrder){ 295 if (MotorolaOrder){
296 return (((uchar *)Short)[0] << 8) | ((uchar *)Short)[1]; 296 return (((uchar *)Short)[0] << 8) | ((uchar *)Short)[1];
297 }else{ 297 }else{
298 return (((uchar *)Short)[1] << 8) | ((uchar *)Short)[0]; 298 return (((uchar *)Short)[1] << 8) | ((uchar *)Short)[0];
299 } 299 }
300} 300}
301 301
302//-------------------------------------------------------------------------- 302//--------------------------------------------------------------------------
303// Convert a 32 bit signed value from file's native byte order 303// Convert a 32 bit signed value from file's native byte order
304//-------------------------------------------------------------------------- 304//--------------------------------------------------------------------------
@@ -716,193 +716,197 @@ void ExifData::process_EXIF(unsigned char * CharBuf, unsigned int length)
716 } 716 }
717 } 717 }
718 718
719 if (memcmp(CharBuf+8,"II",2) == 0){ 719 if (memcmp(CharBuf+8,"II",2) == 0){
720 // printf("Exif section in Intel order\n"); 720 // printf("Exif section in Intel order\n");
721 MotorolaOrder = 0; 721 MotorolaOrder = 0;
722 }else{ 722 }else{
723 if (memcmp(CharBuf+8,"MM",2) == 0){ 723 if (memcmp(CharBuf+8,"MM",2) == 0){
724 // printf("Exif section in Motorola order\n"); 724 // printf("Exif section in Motorola order\n");
725 MotorolaOrder = 1; 725 MotorolaOrder = 1;
726 }else{ 726 }else{
727 return; 727 return;
728 } 728 }
729 } 729 }
730 730
731 // Check the next two values for correctness. 731 // Check the next two values for correctness.
732 if (Get16u(CharBuf+10) != 0x2a 732 if (Get16u(CharBuf+10) != 0x2a
733 || Get32u(CharBuf+12) != 0x08){ 733 || Get32u(CharBuf+12) != 0x08){
734 return; 734 return;
735 } 735 }
736 736
737 LastExifRefd = CharBuf; 737 LastExifRefd = CharBuf;
738 738
739 // First directory starts 16 bytes in. Offsets start at 8 bytes in. 739 // First directory starts 16 bytes in. Offsets start at 8 bytes in.
740 ProcessExifDir(CharBuf+16, CharBuf+8, length-6); 740 ProcessExifDir(CharBuf+16, CharBuf+8, length-6);
741 741
742 // This is how far the interesting (non thumbnail) part of the exif went. 742 // This is how far the interesting (non thumbnail) part of the exif went.
743 ExifSettingsLength = LastExifRefd - CharBuf; 743 ExifSettingsLength = LastExifRefd - CharBuf;
744 744
745 // Compute the CCD width, in milimeters. 745 // Compute the CCD width, in milimeters.
746 if (FocalplaneXRes != 0){ 746 if (FocalplaneXRes != 0){
747 ExifData::CCDWidth = (float)(ExifImageWidth * FocalplaneUnits / FocalplaneXRes); 747 ExifData::CCDWidth = (float)(ExifImageWidth * FocalplaneUnits / FocalplaneXRes);
748 } 748 }
749} 749}
750 750
751//-------------------------------------------------------------------------- 751//--------------------------------------------------------------------------
752// Convert exif time to Unix time structure 752// Convert exif time to Unix time structure
753//-------------------------------------------------------------------------- 753//--------------------------------------------------------------------------
754int ExifData::Exif2tm(struct ::tm * timeptr, char * ExifTime) 754int ExifData::Exif2tm(struct ::tm * timeptr, char * ExifTime)
755{ 755{
756 int a; 756 int a;
757 757
758 timeptr->tm_wday = -1; 758 timeptr->tm_wday = -1;
759 759
760 // Check for format: YYYY:MM:DD HH:MM:SS format. 760 // Check for format: YYYY:MM:DD HH:MM:SS format.
761 a = sscanf(ExifTime, "%d:%d:%d %d:%d:%d", 761 a = sscanf(ExifTime, "%d:%d:%d %d:%d:%d",
762 &timeptr->tm_year, &timeptr->tm_mon, &timeptr->tm_mday, 762 &timeptr->tm_year, &timeptr->tm_mon, &timeptr->tm_mday,
763 &timeptr->tm_hour, &timeptr->tm_min, &timeptr->tm_sec); 763 &timeptr->tm_hour, &timeptr->tm_min, &timeptr->tm_sec);
764 764
765 if (a == 6){ 765 if (a == 6){
766 timeptr->tm_isdst = -1; 766 timeptr->tm_isdst = -1;
767 timeptr->tm_mon -= 1; // Adjust for unix zero-based months 767 timeptr->tm_mon -= 1; // Adjust for unix zero-based months
768 timeptr->tm_year -= 1900; // Adjust for year starting at 1900 768 timeptr->tm_year -= 1900; // Adjust for year starting at 1900
769 return true; // worked. 769 return true; // worked.
770 } 770 }
771 771
772 return false; // Wasn't in Exif date format. 772 return false; // Wasn't in Exif date format.
773} 773}
774 774
775//-------------------------------------------------------------------------- 775//--------------------------------------------------------------------------
776// Contructor for initialising 776// Contructor for initialising
777//-------------------------------------------------------------------------- 777//--------------------------------------------------------------------------
778ExifData::ExifData() 778ExifData::ExifData()
779{ 779{
780 ExifData::Whitebalance = -1; 780 ExifData::Whitebalance = -1;
781 ExifData::MeteringMode = -1; 781 ExifData::MeteringMode = -1;
782 ExifData::FlashUsed = -1; 782 ExifData::FlashUsed = -1;
783 Orientation = 0; 783 Orientation = 0;
784 Height = 0; 784 Height = 0;
785 Width = 0; 785 Width = 0;
786 IsColor = 0; 786 IsColor = 0;
787 Process = 0; 787 Process = 0;
788 FocalLength = 0; 788 FocalLength = 0;
789 ExposureTime = 0; 789 ExposureTime = 0;
790 ApertureFNumber = 0; 790 ApertureFNumber = 0;
791 Distance = 0; 791 Distance = 0;
792 CCDWidth = 0; 792 CCDWidth = 0;
793 ExposureBias = 0; 793 ExposureBias = 0;
794 ExposureProgram = 0; 794 ExposureProgram = 0;
795 ISOequivalent = 0; 795 ISOequivalent = 0;
796 CompressionLevel = 0; 796 CompressionLevel = 0;
797 MotorolaOrder = 0; 797 MotorolaOrder = 0;
798} 798}
799 799
800ExifData::~ExifData() 800ExifData::~ExifData()
801{ 801{
802} 802}
803 803
804//-------------------------------------------------------------------------- 804//--------------------------------------------------------------------------
805// process a EXIF jpeg file 805// process a EXIF jpeg file
806//-------------------------------------------------------------------------- 806//--------------------------------------------------------------------------
807bool ExifData::scan(const QString & path) 807bool ExifData::scan(const QString & path)
808{ 808{
809 int ret; 809 int ret;
810 810
811 QFile f(path); 811 QFile f(path);
812 f.open(IO_ReadOnly); 812 if ( !f.open(IO_ReadOnly) ) {
813 owarn << "Unable to open file " << f.name() << " readonly" << oendl;
814 DiscardData();
815 return false;
816 }
813 817
814 // Scan the JPEG headers. 818 // Scan the JPEG headers.
815 ret = ReadJpegSections(f, READ_EXIF); 819 ret = ReadJpegSections(f, READ_EXIF);
816 820
817 if (ret == false){ 821 if (ret == false){
818 owarn << "Not JPEG file!" << oendl; 822 owarn << "Not JPEG file!" << oendl;
819 DiscardData(); 823 DiscardData();
820 f.close(); 824 f.close();
821 return false; 825 return false;
822 } 826 }
823 f.close(); 827 f.close();
824 DiscardData(); 828 DiscardData();
825 829
826 //now make the strings clean, 830 //now make the strings clean,
827 // for exmaple my Casio is a "QV-4000 " 831 // for exmaple my Casio is a "QV-4000 "
828 CameraMake = CameraMake.stripWhiteSpace(); 832 CameraMake = CameraMake.stripWhiteSpace();
829 CameraModel = CameraModel.stripWhiteSpace(); 833 CameraModel = CameraModel.stripWhiteSpace();
830 UserComment = UserComment.stripWhiteSpace(); 834 UserComment = UserComment.stripWhiteSpace();
831 Comment = Comment.stripWhiteSpace(); 835 Comment = Comment.stripWhiteSpace();
832 return true; 836 return true;
833} 837}
834 838
835//-------------------------------------------------------------------------- 839//--------------------------------------------------------------------------
836// Does the embedded thumbnail match the jpeg image? 840// Does the embedded thumbnail match the jpeg image?
837//-------------------------------------------------------------------------- 841//--------------------------------------------------------------------------
838#ifndef JPEG_TOL 842#ifndef JPEG_TOL
839#define JPEG_TOL 0.02 843#define JPEG_TOL 0.02
840#endif 844#endif
841bool ExifData::isThumbnailSane() { 845bool ExifData::isThumbnailSane() {
842 if (Thumbnail.isNull()) return false; 846 if (Thumbnail.isNull()) return false;
843 847
844 // check whether thumbnail dimensions match the image 848 // check whether thumbnail dimensions match the image
845 // not foolproof, but catches some altered images (jpegtran -rotate) 849 // not foolproof, but catches some altered images (jpegtran -rotate)
846 if (ExifImageLength != 0 && ExifImageLength != Height) return false; 850 if (ExifImageLength != 0 && ExifImageLength != Height) return false;
847 if (ExifImageWidth != 0 && ExifImageWidth != Width) return false; 851 if (ExifImageWidth != 0 && ExifImageWidth != Width) return false;
848 if (Thumbnail.width() == 0 || Thumbnail.height() == 0) return false; 852 if (Thumbnail.width() == 0 || Thumbnail.height() == 0) return false;
849 if (Height == 0 || Width == 0) return false; 853 if (Height == 0 || Width == 0) return false;
850 double d = (double)Height/Width*Thumbnail.width()/Thumbnail.height(); 854 double d = (double)Height/Width*Thumbnail.width()/Thumbnail.height();
851 return (1-JPEG_TOL < d) && (d < 1+JPEG_TOL); 855 return (1-JPEG_TOL < d) && (d < 1+JPEG_TOL);
852} 856}
853 857
854 858
855 859
856static QImage flip_image( const QImage& img ); 860static QImage flip_image( const QImage& img );
857static QImage rotate_90( const QImage& img ); 861static QImage rotate_90( const QImage& img );
858static QImage rotate_180( const QImage& ); 862static QImage rotate_180( const QImage& );
859static QImage rotate_270( const QImage& ); 863static QImage rotate_270( const QImage& );
860 864
861//-------------------------------------------------------------------------- 865//--------------------------------------------------------------------------
862// return a thumbnail that respects the orientation flag 866// return a thumbnail that respects the orientation flag
863// only if it seems sane 867// only if it seems sane
864//-------------------------------------------------------------------------- 868//--------------------------------------------------------------------------
865QImage ExifData::getThumbnail() { 869QImage ExifData::getThumbnail() {
866 if (!isThumbnailSane()) return NULL; 870 if (!isThumbnailSane()) return NULL;
867 if (!Orientation || Orientation == 1) return Thumbnail; 871 if (!Orientation || Orientation == 1) return Thumbnail;
868 872
869 // now fix orientation 873 // now fix orientation
870 874
871 QImage dest = Thumbnail; 875 QImage dest = Thumbnail;
872 switch (Orientation) { // notice intentional fallthroughs 876 switch (Orientation) { // notice intentional fallthroughs
873 case 2: dest = flip_image( dest ); break; 877 case 2: dest = flip_image( dest ); break;
874 case 4: dest = flip_image( dest ); 878 case 4: dest = flip_image( dest );
875 case 3: dest =rotate_180( dest ); break; 879 case 3: dest =rotate_180( dest ); break;
876 case 5: dest = flip_image( dest ); 880 case 5: dest = flip_image( dest );
877 case 6: dest = rotate_90( dest ); break; 881 case 6: dest = rotate_90( dest ); break;
878 case 7: dest = flip_image( dest ); 882 case 7: dest = flip_image( dest );
879 case 8: dest = rotate_270( dest ); break; 883 case 8: dest = rotate_270( dest ); break;
880 default: break; // should never happen 884 default: break; // should never happen
881 } 885 }
882 return dest; 886 return dest;
883} 887}
884 888
885 889
886/* 890/*
887 * 891 *
888 */ 892 */
889static QImage flip_image( const QImage& img ) { 893static QImage flip_image( const QImage& img ) {
890 return img.mirror( TRUE, FALSE ); 894 return img.mirror( TRUE, FALSE );
891} 895}
892 896
893 897
894static QImage dest; 898static QImage dest;
895static int x, y; 899static int x, y;
896static unsigned int *srcData, *destData; // we're not threaded anyway 900static unsigned int *srcData, *destData; // we're not threaded anyway
897static unsigned char *srcData8, *destData8; // 8 bit is char 901static unsigned char *srcData8, *destData8; // 8 bit is char
898static unsigned int *srcTable, *destTable; // destination table 902static unsigned int *srcTable, *destTable; // destination table
899 903
900 904
901static QImage rotate_90_8( const QImage &img ) { 905static QImage rotate_90_8( const QImage &img ) {
902 dest.create(img.height(), img.width(), img.depth()); 906 dest.create(img.height(), img.width(), img.depth());
903 dest.setNumColors(img.numColors()); 907 dest.setNumColors(img.numColors());
904 srcTable = (unsigned int *)img.colorTable(); 908 srcTable = (unsigned int *)img.colorTable();
905 destTable = (unsigned int *)dest.colorTable(); 909 destTable = (unsigned int *)dest.colorTable();
906 for ( x=0; x < img.numColors(); ++x ) 910 for ( x=0; x < img.numColors(); ++x )
907 destTable[x] = srcTable[x]; 911 destTable[x] = srcTable[x];
908 for ( y=0; y < img.height(); ++y ){ 912 for ( y=0; y < img.height(); ++y ){
diff --git a/noncore/apps/opie-console/filereceive.cpp b/noncore/apps/opie-console/filereceive.cpp
index 452be60..41e6888 100644
--- a/noncore/apps/opie-console/filereceive.cpp
+++ b/noncore/apps/opie-console/filereceive.cpp
@@ -1,162 +1,164 @@
1#include <unistd.h> 1#include <unistd.h>
2#include <fcntl.h> 2#include <fcntl.h>
3#include <signal.h> 3#include <signal.h>
4#include <errno.h> 4#include <errno.h>
5 5
6#include <opie2/odebug.h>
6#include <qsocketnotifier.h> 7#include <qsocketnotifier.h>
7 8
8#include "io_layer.h" 9#include "io_layer.h"
9#include "procctl.h" 10#include "procctl.h"
10#include "filereceive.h" 11#include "filereceive.h"
11 12
12FileReceive::FileReceive( Type t, IOLayer* lay, const QString& dir ) 13FileReceive::FileReceive( Type t, IOLayer* lay, const QString& dir )
13 : ReceiveLayer(lay, dir ), m_type( t ) 14 : ReceiveLayer(lay, dir ), m_type( t )
14{ 15{
15 m_fd = -1; 16 m_fd = -1;
16 m_not = 0l; 17 m_not = 0l;
17 m_proc = 0l; 18 m_proc = 0l;
18} 19}
19FileReceive::~FileReceive() { 20FileReceive::~FileReceive() {
20} 21}
21void FileReceive::receive() { 22void FileReceive::receive() {
22 receive( currentDir() ); 23 receive( currentDir() );
23} 24}
24void FileReceive::receive( const QString& dir ) { 25void FileReceive::receive( const QString& dir ) {
25 m_prog = -1; 26 m_prog = -1;
26 m_fd = layer()->rawIO(); 27 m_fd = layer()->rawIO();
27 m_curDir = dir; 28 m_curDir = dir;
28 29
29 if (pipe( m_comm ) < 0 ) 30 if (pipe( m_comm ) < 0 )
30 m_comm[0] = m_comm[1] = 0; 31 m_comm[0] = m_comm[1] = 0;
31 if (pipe( m_info ) < 0 ) 32 if (pipe( m_info ) < 0 )
32 m_info[0] = m_info[1] = 0; 33 m_info[0] = m_info[1] = 0;
33 34
34 m_pid = fork(); 35 m_pid = fork();
35 switch( m_pid ) { 36 switch( m_pid ) {
36 case -1: 37 case -1:
37 //emit error 38 //emit error
38 slotExec(); 39 slotExec();
39 break; 40 break;
40 /* child */ 41 /* child */
41 case 0: { 42 case 0: {
42 setupChild(); 43 setupChild();
43 char* typus = NULL; 44 char* typus = NULL;
44 switch(m_type ) { 45 switch(m_type ) {
45 case SZ: 46 case SZ:
46 break; 47 break;
47 case SX: 48 case SX:
48 typus = "-X"; 49 typus = "-X";
49 break; 50 break;
50 case SY: 51 case SY:
51 typus = "--ymodem"; 52 typus = "--ymodem";
52 break; 53 break;
53 } 54 }
54 55
55 /* we should never return from here */ 56 /* we should never return from here */
56 if( m_type == SX ) 57 if( m_type == SX )
57 // FIXME: file name should be configurable - currently we ensure it 58 // FIXME: file name should be configurable - currently we ensure it
58 // doesn't get overwritten by -E (--rename) 59 // doesn't get overwritten by -E (--rename)
59 execlp("rz", "rz", typus, "--overwrite", QObject::tr("SynchronizedFile").latin1(), NULL ); 60 execlp("rz", "rz", typus, "--overwrite", QObject::tr("SynchronizedFile").latin1(), NULL );
60 else 61 else
61 execlp("rz", "rz", typus, "--overwrite", NULL ); 62 execlp("rz", "rz", typus, "--overwrite", NULL );
62 63
63 char resultByte = 1; 64 char resultByte = 1;
64 if (m_info[1] ) 65 if (m_info[1] )
65 ::write(m_info[1], &resultByte, 1 ); 66 ::write(m_info[1], &resultByte, 1 );
66 67
67 _exit( -1 ); 68 _exit( -1 );
68 break; 69 break;
69 } 70 }
70 default: { 71 default: {
71 if ( m_info[1] ) 72 if ( m_info[1] )
72 close( m_info[1] ); 73 close( m_info[1] );
73 74
74 if ( m_info[0] ) for (;;) { 75 if ( m_info[0] ) for (;;) {
75 char resultByte; int len; 76 char resultByte; int len;
76 len = read(m_info[0], &resultByte, 1 ); 77 len = read(m_info[0], &resultByte, 1 );
77 /* len == 1 start up failed */ 78 /* len == 1 start up failed */
78 if ( len == 1 ) { 79 if ( len == 1 ) {
79 emit error( StartError, tr("Could not start") ); 80 emit error( StartError, tr("Could not start") );
80 return; 81 return;
81 } 82 }
82 if ( len == -1 ) 83 if ( len == -1 )
83 if ( (errno == ECHILD ) || (errno == EINTR ) ) 84 if ( (errno == ECHILD ) || (errno == EINTR ) )
84 continue; 85 continue;
85 86
86 // len == 0 or something like this 87 // len == 0 or something like this
87 break; 88 break;
88 } 89 }
89 90
90 if ( m_info[0] ) 91 if ( m_info[0] )
91 close( m_info[0] ); 92 close( m_info[0] );
92 93
93 m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); 94 m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read );
94 connect(m_not, SIGNAL(activated(int) ), 95 connect(m_not, SIGNAL(activated(int) ),
95 this, SLOT(slotRead() ) ); 96 this, SLOT(slotRead() ) );
96 if ( pipe(m_term) < 0 ) 97 if ( pipe(m_term) < 0 )
97 m_term[0] = m_term[1] = 0; 98 m_term[0] = m_term[1] = 0;
98 99
99 ProcCtl::self()->add(m_pid, m_term[1] ); 100 ProcCtl::self()->add(m_pid, m_term[1] );
100 m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read ); 101 m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read );
101 connect(m_proc, SIGNAL(activated(int) ), 102 connect(m_proc, SIGNAL(activated(int) ),
102 this, SLOT(slotExec() ) ); 103 this, SLOT(slotExec() ) );
103 104
104 } 105 }
105 break; 106 break;
106 107
107 } 108 }
108 109
109} 110}
110void FileReceive::cancel() { 111void FileReceive::cancel() {
111 ::kill(m_pid, 9 ); 112 ::kill(m_pid, 9 );
112} 113}
113void FileReceive::setupChild() { 114void FileReceive::setupChild() {
114 changeDir( currentDir() ); 115 changeDir( currentDir() );
115 /* 116 /*
116 * we do not want to read from our 117 * we do not want to read from our
117 * information channel 118 * information channel
118 */ 119 */
119 if (m_info[0] ) 120 if (m_info[0] )
120 close(m_info[0] ); 121 close(m_info[0] );
121 /* 122 /*
122 * FD_CLOEXEC will close the 123 * FD_CLOEXEC will close the
123 * fd on successful exec 124 * fd on successful exec
124 */ 125 */
125 if (m_info[1] ) 126 if (m_info[1] )
126 fcntl(m_info[1], F_SETFD, FD_CLOEXEC ); 127 fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
127 128
128 if (m_comm[0] ) 129 if (m_comm[0] )
129 close( m_comm[0] ); 130 close( m_comm[0] );
130 /* 131 /*
131 * now set the communication 132 * now set the communication
132 * m_fd STDIN_FILENO 133 * m_fd STDIN_FILENO
133 * STDOUT_FILENO 134 * STDOUT_FILENO
134 * STDERR_FILENO 135 * STDERR_FILENO
135 */ 136 */
136 dup2( m_fd, STDIN_FILENO ); 137 dup2( m_fd, STDIN_FILENO );
137 dup2( m_fd, STDOUT_FILENO ); 138 dup2( m_fd, STDOUT_FILENO );
138 dup2( m_comm[1], STDERR_FILENO ); 139 dup2( m_comm[1], STDERR_FILENO );
139} 140}
140void FileReceive::slotRead() { 141void FileReceive::slotRead() {
141 QByteArray ar(4096); 142 QByteArray ar(4096);
142 int len = read(m_comm[0], ar.data(), 4096 ); 143 int len = read(m_comm[0], ar.data(), 4096 );
143 for (int i = 0; i < len; i++ ) { 144 for (int i = 0; i < len; i++ ) {
144 // printf("%c", ar[i] ); 145 // printf("%c", ar[i] );
145 } 146 }
146 ar.resize( len ); 147 ar.resize( len );
147 QString str( ar ); 148 QString str( ar );
148} 149}
149void FileReceive::slotExec() { 150void FileReceive::slotExec() {
150 char buf[2]; 151 char buf[2];
151 ::read(m_term[0], buf, 1 ); 152 if (::read(m_term[0], buf, 1 ) == -1)
153 owarn << "read of m_term[0] failed" << oendl;
152 delete m_proc; 154 delete m_proc;
153 delete m_not; 155 delete m_not;
154 m_not = m_proc = 0l; 156 m_not = m_proc = 0l;
155 close( m_term[0] ); 157 close( m_term[0] );
156 close( m_term[1] ); 158 close( m_term[1] );
157 close( m_comm[0] ); 159 close( m_comm[0] );
158 close( m_comm[1] ); 160 close( m_comm[1] );
159 layer()->closeRawIO(m_fd); 161 layer()->closeRawIO(m_fd);
160 emit received(QString::null); 162 emit received(QString::null);
161 163
162} 164}
diff --git a/noncore/apps/opie-console/filetransfer.cpp b/noncore/apps/opie-console/filetransfer.cpp
index 7eebc65..6e2d2d5 100644
--- a/noncore/apps/opie-console/filetransfer.cpp
+++ b/noncore/apps/opie-console/filetransfer.cpp
@@ -1,102 +1,103 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <errno.h> 3#include <errno.h>
4#include <fcntl.h> 4#include <fcntl.h>
5#include <unistd.h> 5#include <unistd.h>
6 6
7#include <opie2/odebug.h>
7#include <qsocketnotifier.h> 8#include <qsocketnotifier.h>
8 9
9#include "procctl.h" 10#include "procctl.h"
10#include "filetransfer.h" 11#include "filetransfer.h"
11 12
12 13
13FileTransfer::FileTransfer( Type t, IOLayer* lay ) 14FileTransfer::FileTransfer( Type t, IOLayer* lay )
14 : FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) { 15 : FileTransferLayer( lay ), m_type( t ), m_pid ( 0 ) {
15 signal(SIGPIPE, SIG_IGN ); 16 signal(SIGPIPE, SIG_IGN );
16 17
17 m_pid = 0; 18 m_pid = 0;
18 m_not = 0l; 19 m_not = 0l;
19 m_proc = 0l; 20 m_proc = 0l;
20} 21}
21FileTransfer::~FileTransfer() { 22FileTransfer::~FileTransfer() {
22} 23}
23 24
24/** 25/**
25 * now we will send the file. 26 * now we will send the file.
26 * 27 *
27 * we request an fd. The IOLayer should be closed 28 * we request an fd. The IOLayer should be closed
28 * then we will setup a pipe for progress communication 29 * then we will setup a pipe for progress communication
29 * then we will dup2 the m_fd in the forked process 30 * then we will dup2 the m_fd in the forked process
30 * to do direct IO from and to the fd 31 * to do direct IO from and to the fd
31 */ 32 */
32void FileTransfer::sendFile( const QString& file ) { 33void FileTransfer::sendFile( const QString& file ) {
33 m_prog =-1; 34 m_prog =-1;
34 m_fd = layer()->rawIO(); 35 m_fd = layer()->rawIO();
35// 36//
36// m_fd = ::open("/dev/ttyS0", O_RDWR); 37// m_fd = ::open("/dev/ttyS0", O_RDWR);
37 38
38 m_file = file; 39 m_file = file;
39 if ( pipe( m_comm ) < 0 ) 40 if ( pipe( m_comm ) < 0 )
40 m_comm[0] = m_comm[1] = 0; 41 m_comm[0] = m_comm[1] = 0;
41 if ( pipe( m_info ) < 0 ) 42 if ( pipe( m_info ) < 0 )
42 m_info[0] = m_info[1] = 0; 43 m_info[0] = m_info[1] = 0;
43 44
44 45
45 m_pid = fork(); 46 m_pid = fork();
46 switch( m_pid ) { 47 switch( m_pid ) {
47 case -1: 48 case -1:
48 emit error( StartError, tr("Was not able to fork") ); 49 emit error( StartError, tr("Was not able to fork") );
49 slotExec(); 50 slotExec();
50 break; 51 break;
51 case 0:{ 52 case 0:{
52 setupChild(); 53 setupChild();
53 /* exec */ 54 /* exec */
54 char* verbose = "-vv"; 55 char* verbose = "-vv";
55 char* binray = "-b"; 56 char* binray = "-b";
56 57
57 58
58 char* typus; 59 char* typus;
59 switch(m_type ) { 60 switch(m_type ) {
60 default: 61 default:
61 case SZ: 62 case SZ:
62 typus = ""; 63 typus = "";
63 break; 64 break;
64 case SX: 65 case SX:
65 typus = "-X"; 66 typus = "-X";
66 break; 67 break;
67 case SY: 68 case SY:
68 typus = "--ymodem"; 69 typus = "--ymodem";
69 break; 70 break;
70 } 71 }
71 72
72 /* we should never return from here */ 73 /* we should never return from here */
73 execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL ); 74 execlp("sz", "sz", verbose, binray, file.latin1(), typus, NULL );
74 75
75 /* communication for error!*/ 76 /* communication for error!*/
76 char resultByte =1; 77 char resultByte =1;
77 if (m_info[1] ) 78 if (m_info[1] )
78 write(m_info[1], &resultByte, 1 ); 79 write(m_info[1], &resultByte, 1 );
79 _exit( -1 ); 80 _exit( -1 );
80 break; 81 break;
81 } 82 }
82 default:{ 83 default:{
83 if ( m_info[1] ) 84 if ( m_info[1] )
84 close( m_info[1] ); 85 close( m_info[1] );
85 if ( m_info[0] ) for (;;) { 86 if ( m_info[0] ) for (;;) {
86 char resultByte; int len; 87 char resultByte; int len;
87 len = read(m_info[0], &resultByte, 1 ); 88 len = read(m_info[0], &resultByte, 1 );
88 /* len == 1 start up failed */ 89 /* len == 1 start up failed */
89 if ( len == 1 ) { 90 if ( len == 1 ) {
90 emit error( StartError, tr("Could not start") ); 91 emit error( StartError, tr("Could not start") );
91 return; 92 return;
92 } 93 }
93 if ( len == -1 ) 94 if ( len == -1 )
94 if ( (errno == ECHILD ) || (errno == EINTR ) ) 95 if ( (errno == ECHILD ) || (errno == EINTR ) )
95 continue; 96 continue;
96 97
97 // len == 0 or something like this 98 // len == 0 or something like this
98 break; 99 break;
99 } 100 }
100 if ( m_info[0] ) 101 if ( m_info[0] )
101 close( m_info[0] ); 102 close( m_info[0] );
102 103
@@ -141,108 +142,109 @@ void FileTransfer::setupChild() {
141 * fd on successful exec 142 * fd on successful exec
142 */ 143 */
143 if (m_info[1] ) 144 if (m_info[1] )
144 fcntl(m_info[1], F_SETFD, FD_CLOEXEC ); 145 fcntl(m_info[1], F_SETFD, FD_CLOEXEC );
145 146
146 if (m_comm[0] ) 147 if (m_comm[0] )
147 close( m_comm[0] ); 148 close( m_comm[0] );
148 /* 149 /*
149 * now set the communication 150 * now set the communication
150 * m_fd STDIN_FILENO 151 * m_fd STDIN_FILENO
151 * STDOUT_FILENO 152 * STDOUT_FILENO
152 * STDERR_FILENO 153 * STDERR_FILENO
153 */ 154 */
154 dup2( m_fd, STDIN_FILENO ); 155 dup2( m_fd, STDIN_FILENO );
155 dup2( m_fd, STDOUT_FILENO ); 156 dup2( m_fd, STDOUT_FILENO );
156 dup2( m_comm[1], STDERR_FILENO ); 157 dup2( m_comm[1], STDERR_FILENO );
157} 158}
158 159
159/* 160/*
160 * read from the stderr of the child 161 * read from the stderr of the child
161 * process 162 * process
162 */ 163 */
163void FileTransfer::slotRead() { 164void FileTransfer::slotRead() {
164 QByteArray ar(4096); 165 QByteArray ar(4096);
165 int len = read(m_comm[0], ar.data(), 4096 ); 166 int len = read(m_comm[0], ar.data(), 4096 );
166 for (int i = 0; i < len; i++ ) { 167 for (int i = 0; i < len; i++ ) {
167 // printf("%c", ar[i] ); 168 // printf("%c", ar[i] );
168 } 169 }
169 ar.resize( len ); 170 ar.resize( len );
170 QString str( ar ); 171 QString str( ar );
171 QStringList lis = QStringList::split(' ', str ); 172 QStringList lis = QStringList::split(' ', str );
172 /* 173 /*
173 * Transfer finished.. either complete or incomplete 174 * Transfer finished.. either complete or incomplete
174 */ 175 */
175 if ( lis[0].simplifyWhiteSpace() == "Transfer" ) { 176 if ( lis[0].simplifyWhiteSpace() == "Transfer" ) {
176 return; 177 return;
177 } 178 }
178 /* 179 /*
179 * do progress reading 180 * do progress reading
180 */ 181 */
181 slotProgress( lis ); 182 slotProgress( lis );
182 183
183 184
184} 185}
185/* 186/*
186 * find the progress 187 * find the progress
187 */ 188 */
188void FileTransfer::slotProgress( const QStringList& list ) { 189void FileTransfer::slotProgress( const QStringList& list ) {
189 if ( m_type != SZ ) 190 if ( m_type != SZ )
190 return; 191 return;
191 bool complete = true; 192 bool complete = true;
192 int min, sec; 193 int min, sec;
193 int bps; 194 int bps;
194 unsigned long sent, total; 195 unsigned long sent, total;
195 196
196 min = sec = bps = -1; 197 min = sec = bps = -1;
197 sent = total = 0; 198 sent = total = 0;
198 199
199 // Data looks like this 200 // Data looks like this
200 // 0 1 2 3 4 5 201 // 0 1 2 3 4 5
201 // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33 202 // Bytes Sent 65536/11534336 BPS:7784 ETA 24:33
202 QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() ); 203 QStringList progi = QStringList::split('/', list[2].simplifyWhiteSpace() );
203 sent = progi[0].toULong(&complete ); 204 sent = progi[0].toULong(&complete );
204 if (!complete ) return; 205 if (!complete ) return;
205 206
206 total = progi[1].toULong(&complete ); 207 total = progi[1].toULong(&complete );
207 if (!complete || total == 0) { 208 if (!complete || total == 0) {
208 return; 209 return;
209 } 210 }
210 211
211 212
212 double pro = (double)sent/total; 213 double pro = (double)sent/total;
213 int prog = pro * 100; 214 int prog = pro * 100;
214 215
215 // speed 216 // speed
216 progi = QStringList::split(':', list[3].simplifyWhiteSpace() ); 217 progi = QStringList::split(':', list[3].simplifyWhiteSpace() );
217 bps = progi[1].toInt(); 218 bps = progi[1].toInt();
218 219
219 // time 220 // time
220 progi = QStringList::split(':', list[5].simplifyWhiteSpace() ); 221 progi = QStringList::split(':', list[5].simplifyWhiteSpace() );
221 min = progi[0].toInt(); 222 min = progi[0].toInt();
222 sec = progi[1].toInt(); 223 sec = progi[1].toInt();
223 224
224 225
225 if ( prog > m_prog ) { 226 if ( prog > m_prog ) {
226 m_prog = prog; 227 m_prog = prog;
227 emit progress(m_file, m_prog, bps, -1, min , sec ); 228 emit progress(m_file, m_prog, bps, -1, min , sec );
228 } 229 }
229 230
230} 231}
231void FileTransfer::cancel() { 232void FileTransfer::cancel() {
232 if(m_pid > 0) ::kill(m_pid,9 ); 233 if(m_pid > 0) ::kill(m_pid,9 );
233 234
234} 235}
235void FileTransfer::slotExec() { 236void FileTransfer::slotExec() {
236 char buf[2]; 237 char buf[2];
237 ::read(m_term[0], buf, 1 ); 238 if (::read(m_term[0], buf, 1 ) == -1)
239 owarn << "read of m_term[0] failed" << oendl;
238 delete m_proc; 240 delete m_proc;
239 delete m_not; 241 delete m_not;
240 m_proc = m_not = 0l; 242 m_proc = m_not = 0l;
241 close( m_term[0] ); 243 close( m_term[0] );
242 close( m_term[1] ); 244 close( m_term[1] );
243 close( m_comm[0] ); 245 close( m_comm[0] );
244 close( m_comm[1] ); 246 close( m_comm[1] );
245 layer()->closeRawIO( m_fd ); 247 layer()->closeRawIO( m_fd );
246 emit sent(); 248 emit sent();
247 m_pid = 0; 249 m_pid = 0;
248} 250}
diff --git a/noncore/apps/opie-console/logger.cpp b/noncore/apps/opie-console/logger.cpp
index 6620faf..0fdeca0 100644
--- a/noncore/apps/opie-console/logger.cpp
+++ b/noncore/apps/opie-console/logger.cpp
@@ -1,20 +1,22 @@
1#include <qfile.h> 1#include <qfile.h>
2#include <qtextstream.h> 2#include <qtextstream.h>
3#include <opie2/odebug.h>
3 4
4#include "logger.h" 5#include "logger.h"
5 6
6 7
7Logger::Logger() {} 8Logger::Logger() {}
8 9
9Logger::Logger(const QString fileName) { 10Logger::Logger(const QString fileName) {
10 m_file.setName(fileName); 11 m_file.setName(fileName);
11 m_file.open(IO_ReadWrite); 12 if ( !m_file.open(IO_ReadWrite) )
13 owarn << "failed to open " << m_file.name() << oendl;
12} 14}
13 15
14Logger::~Logger() { 16Logger::~Logger() {
15 m_file.close(); 17 m_file.close();
16} 18}
17 19
18void Logger::append(QByteArray ar) { 20void Logger::append(QByteArray ar) {
19 m_file.writeBlock(ar); 21 m_file.writeBlock(ar);
20} 22}
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index 18c0434..aba7244 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -731,104 +731,105 @@ void MainWindow::slotScrollbarSelected(int index)
731 } 731 }
732 732
733 m_scrollbar->setItemChecked(sm_none, index == sm_none); 733 m_scrollbar->setItemChecked(sm_none, index == sm_none);
734 m_scrollbar->setItemChecked(sm_left, index == sm_left); 734 m_scrollbar->setItemChecked(sm_left, index == sm_left);
735 m_scrollbar->setItemChecked(sm_right, index == sm_right); 735 m_scrollbar->setItemChecked(sm_right, index == sm_right);
736} 736}
737 737
738void MainWindow::slotKeyReceived(FKey k, ushort, ushort, bool pressed) { 738void MainWindow::slotKeyReceived(FKey k, ushort, ushort, bool pressed) {
739 739
740 if ( m_curSession ) { 740 if ( m_curSession ) {
741 741
742 QEvent::Type state; 742 QEvent::Type state;
743 743
744 if (pressed) state = QEvent::KeyPress; 744 if (pressed) state = QEvent::KeyPress;
745 else state = QEvent::KeyRelease; 745 else state = QEvent::KeyRelease;
746 746
747 QKeyEvent ke(state, k.qcode, k.unicode, 0, QString(QChar(k.unicode))); 747 QKeyEvent ke(state, k.qcode, k.unicode, 0, QString(QChar(k.unicode)));
748 748
749 // is this the best way to do this? cant figure out any other way to work 749 // is this the best way to do this? cant figure out any other way to work
750 QApplication::sendEvent((QObject *)m_curSession->widget(), &ke); 750 QApplication::sendEvent((QObject *)m_curSession->widget(), &ke);
751 ke.ignore(); 751 ke.ignore();
752 } 752 }
753} 753}
754void MainWindow::slotCopy() { 754void MainWindow::slotCopy() {
755 if (!currentSession() ) return; 755 if (!currentSession() ) return;
756 currentSession()->emulationHandler()->copy(); 756 currentSession()->emulationHandler()->copy();
757} 757}
758void MainWindow::slotPaste() { 758void MainWindow::slotPaste() {
759 if (!currentSession() ) return; 759 if (!currentSession() ) return;
760 currentSession()->emulationHandler()->paste(); 760 currentSession()->emulationHandler()->paste();
761} 761}
762 762
763/* 763/*
764 * Save the session 764 * Save the session
765 */ 765 */
766 766
767void MainWindow::slotSaveSession() { 767void MainWindow::slotSaveSession() {
768 if (!currentSession() ) { 768 if (!currentSession() ) {
769 QMessageBox::information(this, tr("Save Connection"), 769 QMessageBox::information(this, tr("Save Connection"),
770 tr("<qt>There is no Connection.</qt>"), 1 ); 770 tr("<qt>There is no Connection.</qt>"), 1 );
771 return; 771 return;
772 } 772 }
773 manager()->add( currentSession()->profile() ); 773 manager()->add( currentSession()->profile() );
774 manager()->save(); 774 manager()->save();
775 populateProfiles(); 775 populateProfiles();
776} 776}
777 777
778 778
779 779
780void MainWindow::slotSaveLog() { 780void MainWindow::slotSaveLog() {
781 781
782 if( currentSession()->emulationHandler()->isLogging() ) { 782 if( currentSession()->emulationHandler()->isLogging() ) {
783 DocLnk nf; 783 DocLnk nf;
784 QString m_logName = currentSession()->emulationHandler()->logFileName(); 784 QString m_logName = currentSession()->emulationHandler()->logFileName();
785 QFileInfo info(m_logName); 785 QFileInfo info(m_logName);
786 nf.setType("text/plain"); 786 nf.setType("text/plain");
787 nf.setFile(m_logName); 787 nf.setFile(m_logName);
788 nf.setName(info.fileName()); 788 nf.setName(info.fileName());
789 nf.writeLink(); 789 nf.writeLink();
790 m_recordLog->setText( tr("Start log") ); 790 m_recordLog->setText( tr("Start log") );
791 m_recordingLog = false; 791 m_recordingLog = false;
792 currentSession()->emulationHandler()->clearLog(); 792 currentSession()->emulationHandler()->clearLog();
793 } else { 793 } else {
794 QMap<QString, QStringList> map; 794 QMap<QString, QStringList> map;
795 QStringList text; 795 QStringList text;
796 text << "text/plain"; 796 text << "text/plain";
797 map.insert(tr("Log"), text ); 797 map.insert(tr("Log"), text );
798 Opie::Core::OConfig cfg("opie-console"); 798 Opie::Core::OConfig cfg("opie-console");
799 cfg.setGroup("defaults"); 799 cfg.setGroup("defaults");
800 QString startDir = cfg.readEntry("defaultlogdir", QPEApplication::documentDir() ); 800 QString startDir = cfg.readEntry("defaultlogdir", QPEApplication::documentDir() );
801 QString m_logName = OFileDialog::getSaveFileName(2, startDir, QString::null, map, 0, startDir); 801 QString m_logName = OFileDialog::getSaveFileName(2, startDir, QString::null, map, 0, startDir);
802 if (m_logName.isEmpty() ) return; 802 if (m_logName.isEmpty() ) return;
803 803
804 m_recordLog->setText( tr("Stop log") ); 804 m_recordLog->setText( tr("Stop log") );
805 m_recordingLog = true; 805 m_recordingLog = true;
806 currentSession()->emulationHandler()->startLogging(m_logName); 806 currentSession()->emulationHandler()->startLogging(m_logName);
807 } 807 }
808} 808}
809 809
810void MainWindow::slotSaveHistory() { 810void MainWindow::slotSaveHistory() {
811 QMap<QString, QStringList> map; 811 QMap<QString, QStringList> map;
812 QStringList text; 812 QStringList text;
813 text << "text/plain"; 813 text << "text/plain";
814 map.insert(tr("History"), text ); 814 map.insert(tr("History"), text );
815 QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map); 815 QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
816 if (filename.isEmpty() ) return; 816 if (filename.isEmpty() ) return;
817 817
818 QFileInfo info(filename); 818 QFileInfo info(filename);
819 819
820 DocLnk nf; 820 DocLnk nf;
821 nf.setType("text/plain"); 821 nf.setType("text/plain");
822 nf.setFile(filename); 822 nf.setFile(filename);
823 nf.setName(info.fileName()); 823 nf.setName(info.fileName());
824 824
825 825
826 QFile file(filename); 826 QFile file(filename);
827 file.open(IO_WriteOnly ); 827 if ( !file.open(IO_WriteOnly ) ) return;
828
828 QTextStream str(&file ); 829 QTextStream str(&file );
829 if ( currentSession() ) 830 if ( currentSession() )
830 currentSession()->emulationHandler()->emulation()->streamHistory(&str); 831 currentSession()->emulationHandler()->emulation()->streamHistory(&str);
831 832
832 file.close(); 833 file.close();
833 nf.writeLink(); 834 nf.writeLink();
834} 835}
diff --git a/noncore/apps/opie-console/script.cpp b/noncore/apps/opie-console/script.cpp
index faea412..8d35776 100644
--- a/noncore/apps/opie-console/script.cpp
+++ b/noncore/apps/opie-console/script.cpp
@@ -1,29 +1,31 @@
1#include <qfile.h> 1#include <qfile.h>
2#include "script.h" 2#include "script.h"
3 3
4Script::Script() { 4Script::Script() {
5} 5}
6 6
7Script::Script(const QString fileName) { 7Script::Script(const QString fileName) {
8 QFile file(fileName); 8 QFile file(fileName);
9 file.open(IO_ReadOnly ); 9 if ( !file.open(IO_ReadOnly ) )
10 return;
10 m_script = file.readAll(); 11 m_script = file.readAll();
11} 12}
12 13
13void Script::saveTo(const QString fileName) const { 14void Script::saveTo(const QString fileName) const {
14 QFile file(fileName); 15 QFile file(fileName);
15 file.open(IO_WriteOnly); 16 if ( !file.open(IO_WriteOnly) )
17 return;
16 file.writeBlock(m_script); 18 file.writeBlock(m_script);
17 file.close(); 19 file.close();
18} 20}
19 21
20 22
21void Script::append(const QByteArray &data) { 23void Script::append(const QByteArray &data) {
22 int size = m_script.size(); 24 int size = m_script.size();
23 m_script.resize(size + data.size()); 25 m_script.resize(size + data.size());
24 memcpy(m_script.data() + size, data.data(), data.size()); 26 memcpy(m_script.data() + size, data.data(), data.size());
25} 27}
26 28
27QByteArray Script::script() const { 29QByteArray Script::script() const {
28 return m_script; 30 return m_script;
29} 31}
diff --git a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
index 733db17..8b02f9f 100644
--- a/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
+++ b/noncore/apps/opie-gutenbrowser/gutenbrowser.cpp
@@ -752,208 +752,202 @@ void Gutenbrowser::Bookmark( int itemId) {
752 } 752 }
753 753
754 odebug << "bookmark loaded" << oendl; 754 odebug << "bookmark loaded" << oendl;
755 setCaption(title); 755 setCaption(title);
756} 756}
757 757
758 758
759bool Gutenbrowser::load( const char *fileName) { 759bool Gutenbrowser::load( const char *fileName) {
760 760
761 // QCopEnvelope ( "QPE/System", "busy()" ); 761 // QCopEnvelope ( "QPE/System", "busy()" );
762 odebug << "Title is already set as "+title << oendl; 762 odebug << "Title is already set as "+title << oendl;
763 odebug << "sizeHint " << sizeHint().height() << " pageSize " << Lview->PageSize() << "" << oendl; 763 odebug << "sizeHint " << sizeHint().height() << " pageSize " << Lview->PageSize() << "" << oendl;
764 // pointSize = Lview->fontInfo().pointSize(); 764 // pointSize = Lview->fontInfo().pointSize();
765 // odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl; 765 // odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl;
766 if( Lview->PageSize() < 4) { 766 if( Lview->PageSize() < 4) {
767 767
768 //Lview->setMaximumHeight( sizeHint().height() ); 768 //Lview->setMaximumHeight( sizeHint().height() );
769 Lview->setMinimumHeight( sizeHint().height() ); 769 Lview->setMinimumHeight( sizeHint().height() );
770 pointSize = Lview->fontInfo().pointSize(); 770 pointSize = Lview->fontInfo().pointSize();
771 odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl; 771 odebug << "sizeHint " << sizeHint().height() << " point size " << pointSize << "" << oendl;
772 if(pointSize < 15) 772 if(pointSize < 15)
773 Lview->setFixedVisibleLines(19); 773 Lview->setFixedVisibleLines(19);
774 else 774 else
775 Lview->setFixedVisibleLines( ( (sizeHint().height() / pointSize ) * 2) -2); 775 Lview->setFixedVisibleLines( ( (sizeHint().height() / pointSize ) * 2) -2);
776 } 776 }
777 777
778 Config cfg("Gutenbrowser"); 778 Config cfg("Gutenbrowser");
779 cfg.setGroup("General"); 779 cfg.setGroup("General");
780 cfg.writeEntry("Current",fileName); 780 cfg.writeEntry("Current",fileName);
781 cfg.write(); 781 cfg.write();
782 currentLine=0; 782 currentLine=0;
783 783
784 file_name=fileName; 784 file_name=fileName;
785 QString o_file = fileName; 785 QString o_file = fileName;
786 786
787 // if (i_pageNum < 1) { 787 // if (i_pageNum < 1) {
788 i_pageNum = 1; 788 i_pageNum = 1;
789 // } 789 // }
790 odebug << "ready to open "+o_file << oendl; 790 odebug << "ready to open "+o_file << oendl;
791 791
792 if(f.isOpen()) f.close(); 792 if(f.isOpen()) f.close();
793 f.setName( o_file); 793 f.setName( o_file);
794 794
795 if ( !f.open( IO_ReadOnly)) { 795 if ( !f.open( IO_ReadOnly)) {
796 QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n" +o_file)) ); 796 QMessageBox::message( (tr("Note")), (tr("File not opened sucessfully.\n" +o_file)) );
797 return false; 797 return false;
798 } 798 }
799 currentFilePos = 0; 799 currentFilePos = 0;
800 pageStopArray.resize(3); 800 pageStopArray.resize(3);
801 pageStopArray[0] = currentFilePos; 801 pageStopArray[0] = currentFilePos;
802 802
803 fileHandle = f.handle(); 803 fileHandle = f.handle();
804 QString insertString; 804 QString insertString;
805 QTextStream t(&f); 805 QTextStream t(&f);
806 QString s; 806 QString s;
807 for(int fd=0; fd < Lview->PageSize() ;fd++) { 807 for(int fd=0; fd < Lview->PageSize() ;fd++) {
808 s=t.readLine(); 808 s=t.readLine();
809 // insertString+=s; 809 // insertString+=s;
810 if(useWrap) 810 if(useWrap)
811 s.replace(QRegExp("\n"),""); 811 s.replace(QRegExp("\n"),"");
812 // s.replace(QRegExp("\r"),""); 812 // s.replace(QRegExp("\r"),"");
813 Lview->insertLine( s,-1); 813 Lview->insertLine( s,-1);
814 currentLine++; 814 currentLine++;
815 } 815 }
816 816
817 // int length = Lview->length(); 817 // int length = Lview->length();
818 currentFilePos = f.at(); 818 currentFilePos = f.at();
819 819
820 pageStopArray[1] = currentFilePos; 820 pageStopArray[1] = currentFilePos;
821 821
822 odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum 822 odebug << "<<<<<<<<<<<" << currentFilePos << " current page is number " << i_pageNum
823 << ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum] 823 << ", length " << Lview->length() << ", current " << pageStopArray[i_pageNum]
824 << ", pageSize " << Lview->PageSize() << oendl; 824 << ", pageSize " << Lview->PageSize() << oendl;
825 825
826 Lview->setMaxLines(Lview->PageSize()*2); 826 Lview->setMaxLines(Lview->PageSize()*2);
827// odebug << "Gulped " << currentLine << "" << oendl; 827// odebug << "Gulped " << currentLine << "" << oendl;
828 setCaption(title); 828 setCaption(title);
829 Lview->setAutoUpdate( TRUE); 829 Lview->setAutoUpdate( TRUE);
830 830
831// Lview->setCursorPosition(0,0,FALSE); 831// Lview->setCursorPosition(0,0,FALSE);
832 832
833 // pages = (int)(( Lview->numLines() / Lview->editSize() ) / 2 ) +1; 833 // pages = (int)(( Lview->numLines() / Lview->editSize() ) / 2 ) +1;
834 //odebug << "number of pages " << pages << "" << oendl; 834 //odebug << "number of pages " << pages << "" << oendl;
835 835
836 loadCheck = true; 836 loadCheck = true;
837 enableButtons(true); 837 enableButtons(true);
838 if( donateMenu->count() == 3) { 838 if( donateMenu->count() == 3) {
839 donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() )); 839 donateMenu->insertItem("Current Title", this, SLOT( InfoBarClick() ));
840 } 840 }
841 Lview->setFocus(); 841 Lview->setFocus();
842 842
843 // QCopEnvelope("QPE/System", "notBusy()" ); 843 // QCopEnvelope("QPE/System", "notBusy()" );
844 return true; 844 return true;
845} // end load 845} // end load
846 846
847void Gutenbrowser::Search() { 847void Gutenbrowser::Search() {
848 848 odebug << "Starting search dialog" << oendl;
849 // if( searchDlg->isHidden()) 849 searchDlg = new SearchDialog( this, "Etext Search", true);
850 { 850 searchDlg->setCaption( tr( "Etext Search" ));
851 odebug << "Starting search dialog" << oendl; 851 connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot()));
852 searchDlg = new SearchDialog( this, "Etext Search", true); 852 connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot()));
853 searchDlg->setCaption( tr( "Etext Search" )); 853
854 // searchDlg->setLabel( "- searches etext"); 854 QString resultString;
855 connect( searchDlg,SIGNAL( search_signal()),this,SLOT( search_slot())); 855 QString string = searchDlg->searchString;
856 connect( searchDlg,SIGNAL( search_done_signal()),this,SLOT( searchdone_slot())); 856 Lview->deselect();
857 857 searchDlg->show();
858 QString resultString;
859 QString string = searchDlg->searchString;
860 Lview->deselect();
861 searchDlg->show();
862 searchDlg->result();
863 }
864} 858}
865 859
866void Gutenbrowser::search_slot( ) { 860void Gutenbrowser::search_slot( ) {
867 int line, col; 861 int line, col;
868 if (!searchDlg /*&& !loadCheck */) 862 if (!searchDlg /*&& !loadCheck */)
869 return; 863 return;
870 864
871 Lview->getCursorPosition(&line,&col); 865 Lview->getCursorPosition(&line,&col);
872 QString to_find_string=searchDlg->get_text(); 866 QString to_find_string=searchDlg->get_text();
873 867
874 // searchDlg->get_direction();// is true if searching backward 868 // searchDlg->get_direction();// is true if searching backward
875 if ( last_search != 0 && searchDlg->get_direction() ){ 869 if ( last_search != 0 && searchDlg->get_direction() ){
876 col = col - pattern.length() - 1 ; 870 col = col - pattern.length() - 1 ;
877 } 871 }
878 again: 872 again:
879 int result = doSearch( to_find_string , /* searchDlg->case_sensitive()*/ TRUE, searchDlg->forward_search(), line, col); 873 int result = doSearch( to_find_string , /* searchDlg->case_sensitive()*/ TRUE, searchDlg->forward_search(), line, col);
880 if(result == 0){ 874 if(result == 0){
881 if(!searchDlg->get_direction()){ // forward search 875 if(!searchDlg->get_direction()){ // forward search
882 int query = QMessageBox::information( searchDlg, "Find", 876 int query = QMessageBox::information( searchDlg, "Find",
883 "End of document reached.\nContinue from the beginning?", 877 "End of document reached.\nContinue from the beginning?",
884 "Yes", "No", "", 0,1); 878 "Yes", "No", "", 0,1);
885 if (query == 0){ 879 if (query == 0){
886 line = 0; 880 line = 0;
887 col = 0; 881 col = 0;
888 goto again; 882 goto again;
889 } 883 }
890 } else { //backward search 884 } else { //backward search
891 int query = QMessageBox::information( searchDlg, "Find", 885 int query = QMessageBox::information( searchDlg, "Find",
892 "End of document reached.\nContinue from the beginning?", 886 "End of document reached.\nContinue from the beginning?",
893 "Yes", "No", "", 0,1); 887 "Yes", "No", "", 0,1);
894 if (query == 0){ 888 if (query == 0){
895 QString string = Lview->textLine( Lview->numLines() - 1 ); 889 QString string = Lview->textLine( Lview->numLines() - 1 );
896 line = Lview->numLines() - 1; 890 line = Lview->numLines() - 1;
897 lineCheck = line; 891 lineCheck = line;
898 col = string.length(); 892 col = string.length();
899 last_search = -1; //BACKWARD; 893 last_search = -1; //BACKWARD;
900 goto again; 894 goto again;
901 } 895 }
902 } 896 }
903 } else { 897 } else {
904 898
905 //// emit CursorPositionChanged(); textLine 899 //// emit CursorPositionChanged(); textLine
906 } 900 }
907} 901}
908 902
909int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) { 903int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) {
910 int i, length; 904 int i, length;
911 int pos = -1; 905 int pos = -1;
912 if(forward) { 906 if(forward) {
913 QString string; 907 QString string;
914 for(i = line; i < Lview->numLines(); i++) { 908 for(i = line; i < Lview->numLines(); i++) {
915 909
916 string = Lview->textLine(i); 910 string = Lview->textLine(i);
917 pos = string.find(s_pattern, i == line ? col : 0, case_sensitive); 911 pos = string.find(s_pattern, i == line ? col : 0, case_sensitive);
918 if( pos != -1) { 912 if( pos != -1) {
919 int top = Lview->Top(); 913 int top = Lview->Top();
920 length = s_pattern.length(); 914 length = s_pattern.length();
921 if( i > Lview->lastRow() ) { 915 if( i > Lview->lastRow() ) {
922// Lview->setCursorPosition(i,pos,FALSE); 916// Lview->setCursorPosition(i,pos,FALSE);
923 for(int l = 0 ; l < length; l++) { 917 for(int l = 0 ; l < length; l++) {
924 Lview->cursorRight(TRUE); 918 Lview->cursorRight(TRUE);
925 } 919 }
926// Lview->setCursorPosition( i , pos + length, TRUE ); 920// Lview->setCursorPosition( i , pos + length, TRUE );
927 int newTop = Lview->Top(); 921 int newTop = Lview->Top();
928 if(Lview->lastRow() > i) 922 if(Lview->lastRow() > i)
929 Lview->ScrollUp( newTop - top); 923 Lview->ScrollUp( newTop - top);
930 // AdjustStatus(); 924 // AdjustStatus();
931 } else { 925 } else {
932// Lview->setCursorPosition(i,pos,FALSE); 926// Lview->setCursorPosition(i,pos,FALSE);
933 for(int l = 0 ; l < length; l++) { 927 for(int l = 0 ; l < length; l++) {
934 Lview->cursorRight(TRUE); 928 Lview->cursorRight(TRUE);
935 } 929 }
936// Lview->setCursorPosition( i , pos + length, TRUE ); 930// Lview->setCursorPosition( i , pos + length, TRUE );
937 // AdjustStatus(); 931 // AdjustStatus();
938 } 932 }
939 pattern = s_pattern; 933 pattern = s_pattern;
940 last_search = 1; //FORWARD; 934 last_search = 1; //FORWARD;
941 return 1; 935 return 1;
942 } 936 }
943 } 937 }
944 } else { //////////////// searching backwards 938 } else { //////////////// searching backwards
945 QString string; 939 QString string;
946 for( i = line; i >= 0; i--) { 940 for( i = line; i >= 0; i--) {
947 string = Lview->textLine(i); 941 string = Lview->textLine(i);
948 int line_length = string.length(); 942 int line_length = string.length();
949 pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive); 943 pos = string.findRev(s_pattern, line == i ? col : line_length , case_sensitive);
950 if (pos != -1) { 944 if (pos != -1) {
951 // int top = Lview->Top(); 945 // int top = Lview->Top();
952 length = s_pattern.length(); 946 length = s_pattern.length();
953 if( i < Lview->Top() ) { 947 if( i < Lview->Top() ) {
954 Lview->ScrollDown( Lview->PageSize() ); 948 Lview->ScrollDown( Lview->PageSize() );
955 Lview->MultiLine_Ex::pageUp( FALSE ); 949 Lview->MultiLine_Ex::pageUp( FALSE );
956 if( ! (line == i && pos > col ) ) { 950 if( ! (line == i && pos > col ) ) {
957// Lview->setCursorPosition( i ,pos ,FALSE ); 951// Lview->setCursorPosition( i ,pos ,FALSE );
958 for(int l = 0 ; l < length; l++) { 952 for(int l = 0 ; l < length; l++) {
959 Lview->cursorRight(TRUE); 953 Lview->cursorRight(TRUE);
diff --git a/noncore/apps/opie-gutenbrowser/helpwindow.cpp b/noncore/apps/opie-gutenbrowser/helpwindow.cpp
index 4bdac02..f444a2e 100644
--- a/noncore/apps/opie-gutenbrowser/helpwindow.cpp
+++ b/noncore/apps/opie-gutenbrowser/helpwindow.cpp
@@ -100,234 +100,232 @@ HelpWindow::HelpWindow( const QString& home_, const QString&, QWidget* parent, c
100 QStringList::Iterator it2 = bookmarks.begin(); 100 QStringList::Iterator it2 = bookmarks.begin();
101 for ( ; it2 != bookmarks.end(); ++it2 ) 101 for ( ; it2 != bookmarks.end(); ++it2 )
102 mBookmarks[ bookm->insertItem( *it2 ) ] = *it2; 102 mBookmarks[ bookm->insertItem( *it2 ) ] = *it2;
103 connect( bookm, SIGNAL( activated( int ) ), 103 connect( bookm, SIGNAL( activated( int ) ),
104 this, SLOT( bookmChosen( int ) ) ); 104 this, SLOT( bookmChosen( int ) ) );
105 105
106 menuBar()->insertItem( tr("&File"), file ); 106 menuBar()->insertItem( tr("&File"), file );
107 menuBar()->insertItem( tr("&Go"), go ); 107 menuBar()->insertItem( tr("&Go"), go );
108 menuBar()->insertItem( tr( "History" ), hist ); 108 menuBar()->insertItem( tr( "History" ), hist );
109 menuBar()->insertItem( tr( "Bookmarks" ), bookm ); 109 menuBar()->insertItem( tr( "Bookmarks" ), bookm );
110// menuBar()->insertSeparator(); 110// menuBar()->insertSeparator();
111// menuBar()->insertItem( tr("&Help"), help ); 111// menuBar()->insertItem( tr("&Help"), help );
112 112
113 menuBar()->setItemEnabled( forwardId, FALSE); 113 menuBar()->setItemEnabled( forwardId, FALSE);
114 menuBar()->setItemEnabled( backwardId, FALSE); 114 menuBar()->setItemEnabled( backwardId, FALSE);
115 connect( browser, SIGNAL( backwardAvailable( bool ) ), this, SLOT( setBackwardAvailable( bool ) ) ); 115 connect( browser, SIGNAL( backwardAvailable( bool ) ), this, SLOT( setBackwardAvailable( bool ) ) );
116 connect( browser, SIGNAL( forwardAvailable( bool ) ), this, SLOT( setForwardAvailable( bool ) ) ); 116 connect( browser, SIGNAL( forwardAvailable( bool ) ), this, SLOT( setForwardAvailable( bool ) ) );
117 117
118 118
119 QToolBar* toolbar = new QToolBar( this ); 119 QToolBar* toolbar = new QToolBar( this );
120 addToolBar( toolbar, "Toolbar"); 120 addToolBar( toolbar, "Toolbar");
121 QToolButton* button; 121 QToolButton* button;
122 122
123 button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar ); 123 button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar );
124 connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); 124 connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
125 button->setEnabled( FALSE ); 125 button->setEnabled( FALSE );
126 button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar ); 126 button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar );
127 connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); 127 connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
128 button->setEnabled( FALSE ); 128 button->setEnabled( FALSE );
129 button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar ); 129 button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar );
130 130
131 toolbar->addSeparator(); 131 toolbar->addSeparator();
132 132
133 pathCombo = new QComboBox( TRUE, toolbar ); 133 pathCombo = new QComboBox( TRUE, toolbar );
134 connect( pathCombo, SIGNAL( activated( const QString & ) ), this, SLOT( pathSelected( const QString & ) ) ); 134 connect( pathCombo, SIGNAL( activated( const QString & ) ), this, SLOT( pathSelected( const QString & ) ) );
135 toolbar->setStretchableWidget( pathCombo ); 135 toolbar->setStretchableWidget( pathCombo );
136 136
137// pathCombo->setMaximumWidth(190); 137// pathCombo->setMaximumWidth(190);
138// setRightJustification( TRUE ); 138// setRightJustification( TRUE );
139// setDockEnabled( Left, FALSE ); 139// setDockEnabled( Left, FALSE );
140// setDockEnabled( Right, FALSE ); 140// setDockEnabled( Right, FALSE );
141 141
142 pathCombo->insertItem( home_ ); 142 pathCombo->insertItem( home_ );
143 143
144 browser->setFocus(); 144 browser->setFocus();
145 145
146 146
147} 147}
148 148
149 149
150void HelpWindow::setBackwardAvailable( bool b) 150void HelpWindow::setBackwardAvailable( bool b)
151{ 151{
152 menuBar()->setItemEnabled( backwardId, b); 152 menuBar()->setItemEnabled( backwardId, b);
153} 153}
154 154
155void HelpWindow::setForwardAvailable( bool b) 155void HelpWindow::setForwardAvailable( bool b)
156{ 156{
157 menuBar()->setItemEnabled( forwardId, b); 157 menuBar()->setItemEnabled( forwardId, b);
158} 158}
159 159
160 160
161void HelpWindow::textChanged() 161void HelpWindow::textChanged()
162{ 162{
163 if ( browser->documentTitle().isNull() ) { 163 if ( browser->documentTitle().isNull() ) {
164 setCaption( "Gutenbrowser - Helpviewer - " + browser->context() ); 164 setCaption( "Gutenbrowser - Helpviewer - " + browser->context() );
165 selectedURL = browser->context(); 165 selectedURL = browser->context();
166 } 166 }
167 else { 167 else {
168 setCaption( "Gutenbrowser - Helpviewer - " + browser->documentTitle() ) ; 168 setCaption( "Gutenbrowser - Helpviewer - " + browser->documentTitle() ) ;
169 selectedURL = browser->documentTitle(); 169 selectedURL = browser->documentTitle();
170 } 170 }
171 171
172 if ( !selectedURL.isEmpty() && pathCombo ) { 172 if ( !selectedURL.isEmpty() && pathCombo ) {
173 bool exists = FALSE; 173 bool exists = FALSE;
174 int i; 174 int i;
175 for ( i = 0; i < pathCombo->count(); ++i ) { 175 for ( i = 0; i < pathCombo->count(); ++i ) {
176 if ( pathCombo->text( i ) == selectedURL ) { 176 if ( pathCombo->text( i ) == selectedURL ) {
177 exists = TRUE; 177 exists = TRUE;
178 break; 178 break;
179 } 179 }
180 } 180 }
181 if ( !exists ) { 181 if ( !exists ) {
182 pathCombo->insertItem( selectedURL, 0 ); 182 pathCombo->insertItem( selectedURL, 0 );
183 pathCombo->setCurrentItem( 0 ); 183 pathCombo->setCurrentItem( 0 );
184 mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; 184 mHistory[ hist->insertItem( selectedURL ) ] = selectedURL;
185 } else 185 } else
186 pathCombo->setCurrentItem( i ); 186 pathCombo->setCurrentItem( i );
187 selectedURL = QString::null; 187 selectedURL = QString::null;
188 } 188 }
189} 189}
190 190
191HelpWindow::~HelpWindow() 191HelpWindow::~HelpWindow()
192{ 192{
193 history.clear(); 193 history.clear();
194 QMap<int, QString>::Iterator it = mHistory.begin(); 194 QMap<int, QString>::Iterator it = mHistory.begin();
195 for ( ; it != mHistory.end(); ++it ) 195 for ( ; it != mHistory.end(); ++it )
196 history.append( *it ); 196 history.append( *it );
197 197
198 QFile f( QDir::currentDirPath() + "/.history" ); 198 QFile f( QDir::currentDirPath() + "/.history" );
199 f.open( IO_WriteOnly ); 199 if ( f.open( IO_WriteOnly ) ) {
200 QDataStream s( &f ); 200 QDataStream s( &f );
201 s << history; 201 s << history;
202 f.close(); 202 f.close();
203 }
203 204
204 bookmarks.clear(); 205 bookmarks.clear();
205 QMap<int, QString>::Iterator it2 = mBookmarks.begin(); 206 QMap<int, QString>::Iterator it2 = mBookmarks.begin();
206 for ( ; it2 != mBookmarks.end(); ++it2 ) 207 for ( ; it2 != mBookmarks.end(); ++it2 )
207 bookmarks.append( *it2 ); 208 bookmarks.append( *it2 );
208 209
209 QFile f2( QDir::currentDirPath() + "/.bookmarks" ); 210 QFile f2( QDir::currentDirPath() + "/.bookmarks" );
210 f2.open( IO_WriteOnly ); 211 if ( !f2.open( IO_WriteOnly ) )
212 return;
213
211 QDataStream s2( &f2 ); 214 QDataStream s2( &f2 );
212 s2 << bookmarks; 215 s2 << bookmarks;
213 f2.close(); 216 f2.close();
214} 217}
215 218
216// void HelpWindow::about()
217// {
218// QMessageBox::about( this, "Gutenbrowser", "<p>Thanks to Trolltech for this</p>" );
219// }
220
221// void HelpWindow::aboutQt()
222// {
223// QMessageBox::aboutQt( this, "QBrowser" );
224// }
225
226void HelpWindow::openFile() 219void HelpWindow::openFile()
227{ 220{
228#ifndef QT_NO_FILEDIALOG 221#ifndef QT_NO_FILEDIALOG
229 QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); 222 QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );
230 if ( !fn.isEmpty() ) 223 if ( !fn.isEmpty() )
231 browser->setSource( fn ); 224 browser->setSource( fn );
232#endif 225#endif
233} 226}
234 227
235void HelpWindow::newWindow() 228void HelpWindow::newWindow()
236{ 229{
237 ( new HelpWindow(browser->source(), "qbrowser") )->show(); 230 ( new HelpWindow(browser->source(), "qbrowser") )->show();
238} 231}
239 232
240void HelpWindow::print() 233void HelpWindow::print()
241{ 234{
242#ifndef QT_NO_PRINTER 235#ifndef QT_NO_PRINTER
243 QPrinter printer; 236 QPrinter printer;
244 printer.setFullPage(TRUE); 237 printer.setFullPage(TRUE);
245 if ( printer.setup() ) { 238 if ( printer.setup() ) {
246 QPainter p( &printer ); 239 QPainter p( &printer );
247 QPaintDeviceMetrics metrics(p.device()); 240 QPaintDeviceMetrics metrics(p.device());
248 int dpix = metrics.logicalDpiX(); 241 int dpix = metrics.logicalDpiX();
249 int dpiy = metrics.logicalDpiY(); 242 int dpiy = metrics.logicalDpiY();
250 const int margin = 72; // pt 243 const int margin = 72; // pt
251 QRect body(margin*dpix/72, margin*dpiy/72, 244 QRect body(margin*dpix/72, margin*dpiy/72,
252 metrics.width()-margin*dpix/72*2, 245 metrics.width()-margin*dpix/72*2,
253 metrics.height()-margin*dpiy/72*2 ); 246 metrics.height()-margin*dpiy/72*2 );
254 QFont font("times", 10); 247 QFont font("times", 10);
255 QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(), 248 QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(),
256 browser->mimeSourceFactory(), body.height() ); 249 browser->mimeSourceFactory(), body.height() );
257 richText.setWidth( &p, body.width() ); 250 richText.setWidth( &p, body.width() );
258 QRect view( body ); 251 QRect view( body );
259 int page = 1; 252 int page = 1;
260 do { 253 do {
261 p.setClipRect( body ); 254 p.setClipRect( body );
262 richText.draw( &p, body.left(), body.top(), view, colorGroup() ); 255 richText.draw( &p, body.left(), body.top(), view, colorGroup() );
263 p.setClipping( FALSE ); 256 p.setClipping( FALSE );
264 view.moveBy( 0, body.height() ); 257 view.moveBy( 0, body.height() );
265 p.translate( 0 , -body.height() ); 258 p.translate( 0 , -body.height() );
266 p.setFont( font ); 259 p.setFont( font );
267 p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ), 260 p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ),
268 view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) ); 261 view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) );
269 if ( view.top() >= richText.height() ) 262 if ( view.top() >= richText.height() )
270 break; 263 break;
271 printer.newPage(); 264 printer.newPage();
272 page++; 265 page++;
273 } while (TRUE); 266 } while (TRUE);
274 } 267 }
275#endif 268#endif
276} 269}
277 270
278void HelpWindow::pathSelected( const QString &_path ) 271void HelpWindow::pathSelected( const QString &_path )
279{ 272{
280 browser->setSource( _path ); 273 browser->setSource( _path );
281 QMap<int, QString>::Iterator it = mHistory.begin(); 274 QMap<int, QString>::Iterator it = mHistory.begin();
282 bool exists = FALSE; 275 bool exists = FALSE;
283 for ( ; it != mHistory.end(); ++it ) { 276 for ( ; it != mHistory.end(); ++it ) {
284 if ( *it == _path ) { 277 if ( *it == _path ) {
285 exists = TRUE; 278 exists = TRUE;
286 break; 279 break;
287 } 280 }
288 } 281 }
289 if ( !exists ) 282 if ( !exists )
290 mHistory[ hist->insertItem( _path ) ] = _path; 283 mHistory[ hist->insertItem( _path ) ] = _path;
291} 284}
292 285
293void HelpWindow::readHistory() 286void HelpWindow::readHistory()
294{ 287{
295 if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { 288 if ( !QFile::exists( QDir::currentDirPath() + "/.history" ) )
296 QFile f( QDir::currentDirPath() + "/.history" ); 289 return;
297 f.open( IO_ReadOnly ); 290
298 QDataStream s( &f ); 291 QFile f( QDir::currentDirPath() + "/.history" );
299 s >> history; 292 if ( !f.open( IO_ReadOnly ) )
300 f.close(); 293 return;
301 while ( history.count() > 20 ) 294
302 history.remove( history.begin() ); 295 QDataStream s( &f );
303 } 296 s >> history;
297 f.close();
298 while ( history.count() > 20 )
299 history.remove( history.begin() );
304} 300}
305 301
306void HelpWindow::readBookmarks() 302void HelpWindow::readBookmarks()
307{ 303{
308 if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { 304 if ( !QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) )
309 QFile f( QDir::currentDirPath() + "/.bookmarks" ); 305 return;
310 f.open( IO_ReadOnly ); 306
311 QDataStream s( &f ); 307 QFile f( QDir::currentDirPath() + "/.bookmarks" );
312 s >> bookmarks; 308 if ( !f.open( IO_ReadOnly ) )
313 f.close(); 309 return;
314 } 310 QDataStream s( &f );
311 s >> bookmarks;
312 f.close();
315} 313}
316 314
317void HelpWindow::histChosen( int i ) 315void HelpWindow::histChosen( int i )
318{ 316{
319 if ( mHistory.contains( i ) ) 317 if ( mHistory.contains( i ) )
320 browser->setSource( mHistory[ i ] ); 318 browser->setSource( mHistory[ i ] );
321} 319}
322 320
323void HelpWindow::bookmChosen( int i ) 321void HelpWindow::bookmChosen( int i )
324{ 322{
325 if ( mBookmarks.contains( i ) ) 323 if ( mBookmarks.contains( i ) )
326 browser->setSource( mBookmarks[ i ] ); 324 browser->setSource( mBookmarks[ i ] );
327} 325}
328 326
329void HelpWindow::addBookmark() 327void HelpWindow::addBookmark()
330{ 328{
331 mBookmarks[ bookm->insertItem( caption() ) ] = caption(); 329 mBookmarks[ bookm->insertItem( caption() ) ] = caption();
332} 330}
333 331
diff --git a/noncore/graphics/opie-eye/slave/bmp_slave.cpp b/noncore/graphics/opie-eye/slave/bmp_slave.cpp
index 2fa825f..0efadac 100644
--- a/noncore/graphics/opie-eye/slave/bmp_slave.cpp
+++ b/noncore/graphics/opie-eye/slave/bmp_slave.cpp
@@ -1,175 +1,173 @@
1#include "bmp_slave.h" 1#include "bmp_slave.h"
2 2
3#include "thumbnailtool.h" 3#include "thumbnailtool.h"
4 4
5#include <qimage.h> 5#include <qimage.h>
6#include <qobject.h> 6#include <qobject.h>
7#include <qfile.h> 7#include <qfile.h>
8#include <qpixmap.h> 8#include <qpixmap.h>
9#include <qstring.h> 9#include <qstring.h>
10 10
11PHUNK_VIEW_INTERFACE( "Bmp", BmpSlave ); 11PHUNK_VIEW_INTERFACE( "Bmp", BmpSlave );
12namespace { 12namespace {
13 13
14 struct pBmpHeader { 14 struct pBmpHeader {
15 // file header of bmp 15 // file header of bmp
16 char type[2]; // must be "BM" otherwise it is no bmp 16 char type[2]; // must be "BM" otherwise it is no bmp
17 Q_INT32 hSize; 17 Q_INT32 hSize;
18 Q_INT32 reserved1,reserved2; 18 Q_INT32 reserved1,reserved2;
19 19
20 Q_INT16 Planes; 20 Q_INT16 Planes;
21 Q_INT16 BitCount; 21 Q_INT16 BitCount;
22 Q_INT32 Size; 22 Q_INT32 Size;
23 Q_INT32 Width; 23 Q_INT32 Width;
24 Q_INT32 Height; 24 Q_INT32 Height;
25 Q_INT32 Compression; 25 Q_INT32 Compression;
26 Q_INT32 SizeImage; 26 Q_INT32 SizeImage;
27 Q_INT32 XPerMeter; 27 Q_INT32 XPerMeter;
28 Q_INT32 YPerMeter; 28 Q_INT32 YPerMeter;
29 Q_INT32 ClrUsed; 29 Q_INT32 ClrUsed;
30 Q_INT32 ClrImportant; 30 Q_INT32 ClrImportant;
31 }; 31 };
32 32
33 class BmpHeader { 33 class BmpHeader {
34 protected: 34 protected:
35 void read_data(); 35 void read_data();
36 QString _name; 36 QString _name;
37 QFile _inputfile; 37 QFile _inputfile;
38 pBmpHeader m_Header; 38 pBmpHeader m_Header;
39 39
40 static const int OLD = 12; 40 static const int OLD = 12;
41 static const int WIN = 40; 41 static const int WIN = 40;
42 static const int OS2 = 64; 42 static const int OS2 = 64;
43 static const int RGB = 0; 43 static const int RGB = 0;
44 static const int RLE8 = 1; 44 static const int RLE8 = 1;
45 static const int RLE4 = 2; 45 static const int RLE4 = 2;
46 46
47 public: 47 public:
48 BmpHeader(const QString&fname); 48 BmpHeader(const QString&fname);
49 virtual ~BmpHeader(); 49 virtual ~BmpHeader();
50 bool isBmp()const{return qstrncmp(m_Header.type,"BM",2)==0;} 50 bool isBmp()const{return qstrncmp(m_Header.type,"BM",2)==0;}
51 bool isCompressed()const{return m_Header.Compression != 0;} 51 bool isCompressed()const{return m_Header.Compression != 0;}
52 QSize imageSize(){return QSize(m_Header.Width,m_Header.Height);} 52 QSize imageSize(){return QSize(m_Header.Width,m_Header.Height);}
53 QString imageCompression()const; 53 QString imageCompression()const;
54 int bitsPixel()const{return m_Header.BitCount;} 54 int bitsPixel()const{return m_Header.BitCount;}
55 int Size()const{return m_Header.hSize;} 55 int Size()const{return m_Header.hSize;}
56 int compressedSize()const{return m_Header.SizeImage;} 56 int compressedSize()const{return m_Header.SizeImage;}
57 int ColorsUsed()const{return m_Header.ClrUsed;} 57 int ColorsUsed()const{return m_Header.ClrUsed;}
58 int XPix()const{return m_Header.XPerMeter;} 58 int XPix()const{return m_Header.XPerMeter;}
59 int YPix()const{return m_Header.YPerMeter;} 59 int YPix()const{return m_Header.YPerMeter;}
60 }; 60 };
61 61
62 QString BmpHeader::imageCompression()const 62 QString BmpHeader::imageCompression()const
63 { 63 {
64 switch (m_Header.Compression) { 64 switch (m_Header.Compression) {
65 case RLE8: 65 case RLE8:
66 return "8Bit RLE Encoding"; 66 return "8Bit RLE Encoding";
67 break; 67 break;
68 case RLE4: 68 case RLE4:
69 return "4Bit RLE Encoding"; 69 return "4Bit RLE Encoding";
70 break; 70 break;
71 case RGB: 71 case RGB:
72 default: 72 default:
73 return "No encoding"; 73 return "No encoding";
74 } 74 }
75 } 75 }
76 76
77 BmpHeader::BmpHeader(const QString&fname) 77 BmpHeader::BmpHeader(const QString&fname)
78 : _name(fname),_inputfile(_name) 78 : _name(fname),_inputfile(_name)
79 { 79 {
80 read_data(); 80 read_data();
81 } 81 }
82 82
83 void BmpHeader::read_data() { 83 void BmpHeader::read_data() {
84 memset(&m_Header,0,sizeof(pBmpHeader)); 84 memset(&m_Header,0,sizeof(pBmpHeader));
85 _inputfile.open(IO_Raw|IO_ReadOnly); 85 if (!_inputfile.open(IO_Raw|IO_ReadOnly))
86 if (!_inputfile.isOpen()) {
87 return; 86 return;
88 }
89 QDataStream s(&_inputfile); 87 QDataStream s(&_inputfile);
90 s.setByteOrder( QDataStream::LittleEndian ); 88 s.setByteOrder( QDataStream::LittleEndian );
91 s.readRawBytes(m_Header.type,2); 89 s.readRawBytes(m_Header.type,2);
92 if (!isBmp()) { 90 if (!isBmp()) {
93 _inputfile.close(); 91 _inputfile.close();
94 return; 92 return;
95 } 93 }
96 s >> m_Header.hSize; 94 s >> m_Header.hSize;
97 s >> m_Header.reserved1 >> m_Header.reserved2; 95 s >> m_Header.reserved1 >> m_Header.reserved2;
98 s >> m_Header.Size; 96 s >> m_Header.Size;
99 if ( m_Header.Size == BmpHeader::WIN || m_Header.Size == BmpHeader::OS2 ) { 97 if ( m_Header.Size == BmpHeader::WIN || m_Header.Size == BmpHeader::OS2 ) {
100 s >> m_Header.Width >> m_Header.Height >> m_Header.Planes >> m_Header.BitCount; 98 s >> m_Header.Width >> m_Header.Height >> m_Header.Planes >> m_Header.BitCount;
101 s >> m_Header.Compression >> m_Header.SizeImage; 99 s >> m_Header.Compression >> m_Header.SizeImage;
102 s >> m_Header.XPerMeter >> m_Header.YPerMeter; 100 s >> m_Header.XPerMeter >> m_Header.YPerMeter;
103 s >> m_Header.ClrUsed >> m_Header.ClrImportant; 101 s >> m_Header.ClrUsed >> m_Header.ClrImportant;
104 } else { 102 } else {
105 Q_INT16 w, h; 103 Q_INT16 w, h;
106 s >> w >> h >> m_Header.Planes >> m_Header.BitCount; 104 s >> w >> h >> m_Header.Planes >> m_Header.BitCount;
107 m_Header.Width = w; 105 m_Header.Width = w;
108 m_Header.Height = h; 106 m_Header.Height = h;
109 m_Header.Compression = BmpHeader::RGB; 107 m_Header.Compression = BmpHeader::RGB;
110 m_Header.SizeImage = 0; 108 m_Header.SizeImage = 0;
111 m_Header.XPerMeter = m_Header.YPerMeter = 0; 109 m_Header.XPerMeter = m_Header.YPerMeter = 0;
112 m_Header.ClrUsed = m_Header.ClrImportant = 0; 110 m_Header.ClrUsed = m_Header.ClrImportant = 0;
113 } 111 }
114 _inputfile.close(); 112 _inputfile.close();
115 } 113 }
116 114
117 BmpHeader::~BmpHeader() { 115 BmpHeader::~BmpHeader() {
118 } 116 }
119} 117}
120 118
121 119
122BmpSlave::BmpSlave() 120BmpSlave::BmpSlave()
123 : SlaveInterface(QStringList("bmp")) 121 : SlaveInterface(QStringList("bmp"))
124{} 122{}
125 123
126BmpSlave::~BmpSlave() { 124BmpSlave::~BmpSlave() {
127 125
128} 126}
129 127
130QString BmpSlave::iconViewName(const QString& str) { 128QString BmpSlave::iconViewName(const QString& str) {
131 QString st; 129 QString st;
132 BmpHeader bh(str); 130 BmpHeader bh(str);
133 if (!bh.isBmp()) { 131 if (!bh.isBmp()) {
134 st.append("No bmp file"); 132 st.append("No bmp file");
135 return st; 133 return st;
136 } 134 }
137 QSize isize = bh.imageSize(); 135 QSize isize = bh.imageSize();
138 st+=QObject::tr("Dimensions: %1 x %2\n").arg(isize.width()).arg(isize.height()); 136 st+=QObject::tr("Dimensions: %1 x %2\n").arg(isize.width()).arg(isize.height());
139 st+=QObject::tr("Size: %1\n").arg(bh.Size()); 137 st+=QObject::tr("Size: %1\n").arg(bh.Size());
140 st+=QObject::tr("Depth: %1\n").arg(bh.bitsPixel()); 138 st+=QObject::tr("Depth: %1\n").arg(bh.bitsPixel());
141 return st; 139 return st;
142} 140}
143 141
144QString BmpSlave::fullImageInfo( const QString& str) { 142QString BmpSlave::fullImageInfo( const QString& str) {
145 QString st = "<qt>"; 143 QString st = "<qt>";
146 BmpHeader bh(str); 144 BmpHeader bh(str);
147 if (!bh.isBmp()) { 145 if (!bh.isBmp()) {
148 st.append("No bmp file"); 146 st.append("No bmp file");
149 st.append( "</qt>" ); 147 st.append( "</qt>" );
150 return st; 148 return st;
151 } 149 }
152 QSize isize = bh.imageSize(); 150 QSize isize = bh.imageSize();
153 st+=QObject::tr("Dimensions: %1 x %2\n").arg(isize.width()).arg(isize.height()); 151 st+=QObject::tr("Dimensions: %1 x %2\n").arg(isize.width()).arg(isize.height());
154 st+=QObject::tr("Size: %1\n").arg(bh.Size()); 152 st+=QObject::tr("Size: %1\n").arg(bh.Size());
155 st+=QObject::tr("Compression: %1\n").arg(bh.imageCompression()); 153 st+=QObject::tr("Compression: %1\n").arg(bh.imageCompression());
156 if (bh.isCompressed()) { 154 if (bh.isCompressed()) {
157 st+=QObject::tr("Compressed size: %1").arg(bh.compressedSize()); 155 st+=QObject::tr("Compressed size: %1").arg(bh.compressedSize());
158 } 156 }
159 st+=QObject::tr("Depth: %1\n").arg(bh.bitsPixel()); 157 st+=QObject::tr("Depth: %1\n").arg(bh.bitsPixel());
160 st+=QObject::tr("used colors: %1\n").arg(bh.ColorsUsed()); 158 st+=QObject::tr("used colors: %1\n").arg(bh.ColorsUsed());
161 st+=QObject::tr("Resolution: %1 x %2\n").arg(bh.XPix()).arg(bh.YPix()); 159 st+=QObject::tr("Resolution: %1 x %2\n").arg(bh.XPix()).arg(bh.YPix());
162 st.append( "</qt>" ); 160 st.append( "</qt>" );
163 return st; 161 return st;
164} 162}
165 163
166QPixmap BmpSlave::pixmap(const QString& path, int width, int height ) { 164QPixmap BmpSlave::pixmap(const QString& path, int width, int height ) {
167 static QImage img; 165 static QImage img;
168 img.load( path ); 166 img.load( path );
169 if ( img.isNull() ) { 167 if ( img.isNull() ) {
170 QPixmap pix; 168 QPixmap pix;
171 return pix; 169 return pix;
172 } 170 }
173 171
174 return ThumbNailTool::scaleImage( img, width,height ); 172 return ThumbNailTool::scaleImage( img, width,height );
175} 173}
diff --git a/noncore/net/ftplib/ftplib.c b/noncore/net/ftplib/ftplib.c
index 421f855..efcd6f0 100644
--- a/noncore/net/ftplib/ftplib.c
+++ b/noncore/net/ftplib/ftplib.c
@@ -865,193 +865,194 @@ GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl,
865 case FTPLIB_DIR: 865 case FTPLIB_DIR:
866 strcpy(buf,"NLST"); 866 strcpy(buf,"NLST");
867 dir = FTPLIB_READ; 867 dir = FTPLIB_READ;
868 break; 868 break;
869 case FTPLIB_DIR_VERBOSE: 869 case FTPLIB_DIR_VERBOSE:
870 strcpy(buf,"LIST"); 870 strcpy(buf,"LIST");
871 dir = FTPLIB_READ; 871 dir = FTPLIB_READ;
872 break; 872 break;
873 case FTPLIB_FILE_READ: 873 case FTPLIB_FILE_READ:
874 strcpy(buf,"RETR"); 874 strcpy(buf,"RETR");
875 dir = FTPLIB_READ; 875 dir = FTPLIB_READ;
876 break; 876 break;
877 case FTPLIB_FILE_WRITE: 877 case FTPLIB_FILE_WRITE:
878 strcpy(buf,"STOR"); 878 strcpy(buf,"STOR");
879 dir = FTPLIB_WRITE; 879 dir = FTPLIB_WRITE;
880 break; 880 break;
881 default: 881 default:
882 sprintf(nControl->response, "Invalid open type %d\n", typ); 882 sprintf(nControl->response, "Invalid open type %d\n", typ);
883 return 0; 883 return 0;
884 } 884 }
885 if (path != NULL) 885 if (path != NULL)
886 { 886 {
887 int i = strlen(buf); 887 int i = strlen(buf);
888 buf[i++] = ' '; 888 buf[i++] = ' ';
889 if ((strlen(path) + i) >= sizeof(buf)) 889 if ((strlen(path) + i) >= sizeof(buf))
890 return 0; 890 return 0;
891 strcpy(&buf[i],path); 891 strcpy(&buf[i],path);
892 } 892 }
893 if (FtpOpenPort(nControl, nData, mode, dir) == -1) 893 if (FtpOpenPort(nControl, nData, mode, dir) == -1)
894 return 0; 894 return 0;
895 if (!FtpSendCmd(buf, '1', nControl)) 895 if (!FtpSendCmd(buf, '1', nControl))
896 { 896 {
897 FtpClose(*nData); 897 FtpClose(*nData);
898 *nData = NULL; 898 *nData = NULL;
899 return 0; 899 return 0;
900 } 900 }
901 (*nData)->ctrl = nControl; 901 (*nData)->ctrl = nControl;
902 nControl->data = *nData; 902 nControl->data = *nData;
903 if (nControl->cmode == FTPLIB_PORT) 903 if (nControl->cmode == FTPLIB_PORT)
904 { 904 {
905 if (!FtpAcceptConnection(*nData,nControl)) 905 if (!FtpAcceptConnection(*nData,nControl))
906 { 906 {
907 FtpClose(*nData); 907 FtpClose(*nData);
908 *nData = NULL; 908 *nData = NULL;
909 nControl->data = NULL; 909 nControl->data = NULL;
910 return 0; 910 return 0;
911 } 911 }
912 } 912 }
913 return 1; 913 return 1;
914} 914}
915 915
916/* 916/*
917 * FtpRead - read from a data connection 917 * FtpRead - read from a data connection
918 */ 918 */
919GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData) 919GLOBALDEF int FtpRead(void *buf, int max, netbuf *nData)
920{ 920{
921 int i; 921 int i;
922 if (nData->dir != FTPLIB_READ) 922 if (nData->dir != FTPLIB_READ)
923 return 0; 923 return 0;
924 if (nData->buf) 924 if (nData->buf)
925 i = readline(buf, max, nData); 925 i = readline(buf, max, nData);
926 else 926 else
927 { 927 {
928 i = socket_wait(nData); 928 i = socket_wait(nData);
929 if (i != 1) 929 if (i != 1)
930 return 0; 930 return 0;
931 i = net_read(nData->handle, buf, max); 931 i = net_read(nData->handle, buf, max);
932 } 932 }
933 if (i == -1) 933 if (i == -1)
934 return 0; 934 return 0;
935 nData->xfered += i; 935 nData->xfered += i;
936 if (nData->idlecb && nData->cbbytes) 936 if (nData->idlecb && nData->cbbytes)
937 { 937 {
938 nData->xfered1 += i; 938 nData->xfered1 += i;
939 if (nData->xfered1 > nData->cbbytes) 939 if (nData->xfered1 > nData->cbbytes)
940 { 940 {
941 if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0) 941 if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0)
942 return 0; 942 return 0;
943 nData->xfered1 = 0; 943 nData->xfered1 = 0;
944 } 944 }
945 } 945 }
946 return i; 946 return i;
947} 947}
948 948
949/* 949/*
950 * FtpWrite - write to a data connection 950 * FtpWrite - write to a data connection
951 */ 951 */
952GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData) 952GLOBALDEF int FtpWrite(void *buf, int len, netbuf *nData)
953{ 953{
954 int i; 954 int i;
955 if (nData->dir != FTPLIB_WRITE) 955 if (nData->dir != FTPLIB_WRITE)
956 return 0; 956 return 0;
957 if (nData->buf) 957 if (nData->buf)
958 i = writeline(buf, len, nData); 958 i = writeline(buf, len, nData);
959 else 959 else
960 { 960 {
961 socket_wait(nData); 961 if (socket_wait(nData) < 0)
962 fprintf(stderr, "FtpWrite: socket_wait failed with %s\n", nData->ctrl->response);
962 i = net_write(nData->handle, buf, len); 963 i = net_write(nData->handle, buf, len);
963 } 964 }
964 if (i == -1) 965 if (i == -1)
965 return 0; 966 return 0;
966 nData->xfered += i; 967 nData->xfered += i;
967 if (nData->idlecb && nData->cbbytes) 968 if (nData->idlecb && nData->cbbytes)
968 { 969 {
969 nData->xfered1 += i; 970 nData->xfered1 += i;
970 if (nData->xfered1 > nData->cbbytes) 971 if (nData->xfered1 > nData->cbbytes)
971 { 972 {
972 nData->idlecb(nData, nData->xfered, nData->idlearg); 973 nData->idlecb(nData, nData->xfered, nData->idlearg);
973 nData->xfered1 = 0; 974 nData->xfered1 = 0;
974 } 975 }
975 } 976 }
976 return i; 977 return i;
977} 978}
978 979
979/* 980/*
980 * FtpClose - close a data connection 981 * FtpClose - close a data connection
981 */ 982 */
982GLOBALDEF int FtpClose(netbuf *nData) 983GLOBALDEF int FtpClose(netbuf *nData)
983{ 984{
984 netbuf *ctrl; 985 netbuf *ctrl;
985 switch (nData->dir) 986 switch (nData->dir)
986 { 987 {
987 case FTPLIB_WRITE: 988 case FTPLIB_WRITE:
988 /* potential problem - if buffer flush fails, how to notify user? */ 989 /* potential problem - if buffer flush fails, how to notify user? */
989 if (nData->buf != NULL) 990 if (nData->buf != NULL)
990 writeline(NULL, 0, nData); 991 writeline(NULL, 0, nData);
991 case FTPLIB_READ: 992 case FTPLIB_READ:
992 if (nData->buf) 993 if (nData->buf)
993 free(nData->buf); 994 free(nData->buf);
994 shutdown(nData->handle,2); 995 shutdown(nData->handle,2);
995 net_close(nData->handle); 996 net_close(nData->handle);
996 ctrl = nData->ctrl; 997 ctrl = nData->ctrl;
997 free(nData); 998 free(nData);
998 if (ctrl) 999 if (ctrl)
999 { 1000 {
1000 ctrl->data = NULL; 1001 ctrl->data = NULL;
1001 return(readresp('2', ctrl)); 1002 return(readresp('2', ctrl));
1002 } 1003 }
1003 return 1; 1004 return 1;
1004 case FTPLIB_CONTROL: 1005 case FTPLIB_CONTROL:
1005 if (nData->data) 1006 if (nData->data)
1006 { 1007 {
1007 nData->ctrl = NULL; 1008 nData->ctrl = NULL;
1008 FtpClose(nData); 1009 FtpClose(nData);
1009 } 1010 }
1010 net_close(nData->handle); 1011 net_close(nData->handle);
1011 free(nData); 1012 free(nData);
1012 return 0; 1013 return 0;
1013 } 1014 }
1014 return 1; 1015 return 1;
1015} 1016}
1016 1017
1017/* 1018/*
1018 * FtpSite - send a SITE command 1019 * FtpSite - send a SITE command
1019 * 1020 *
1020 * return 1 if command successful, 0 otherwise 1021 * return 1 if command successful, 0 otherwise
1021 */ 1022 */
1022GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl) 1023GLOBALDEF int FtpSite(const char *cmd, netbuf *nControl)
1023{ 1024{
1024 char buf[256]; 1025 char buf[256];
1025 1026
1026 if ((strlen(cmd) + 7) > sizeof(buf)) 1027 if ((strlen(cmd) + 7) > sizeof(buf))
1027 return 0; 1028 return 0;
1028 sprintf(buf,"SITE %s",cmd); 1029 sprintf(buf,"SITE %s",cmd);
1029 if (!FtpSendCmd(buf,'2',nControl)) 1030 if (!FtpSendCmd(buf,'2',nControl))
1030 return 0; 1031 return 0;
1031 return 1; 1032 return 1;
1032} 1033}
1033 1034
1034/* 1035/*
1035 * FtpSysType - send a SYST command 1036 * FtpSysType - send a SYST command
1036 * 1037 *
1037 * Fills in the user buffer with the remote system type. If more 1038 * Fills in the user buffer with the remote system type. If more
1038 * information from the response is required, the user can parse 1039 * information from the response is required, the user can parse
1039 * it out of the response buffer returned by FtpLastResponse(). 1040 * it out of the response buffer returned by FtpLastResponse().
1040 * 1041 *
1041 * return 1 if command successful, 0 otherwise 1042 * return 1 if command successful, 0 otherwise
1042 */ 1043 */
1043GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl) 1044GLOBALDEF int FtpSysType(char *buf, int max, netbuf *nControl)
1044{ 1045{
1045 int l = max; 1046 int l = max;
1046 char *b = buf; 1047 char *b = buf;
1047 char *s; 1048 char *s;
1048 if (!FtpSendCmd("SYST",'2',nControl)) 1049 if (!FtpSendCmd("SYST",'2',nControl))
1049 return 0; 1050 return 0;
1050 s = &nControl->response[4]; 1051 s = &nControl->response[4];
1051 while ((--l) && (*s != ' ')) 1052 while ((--l) && (*s != ' '))
1052 *b++ = *s++; 1053 *b++ = *s++;
1053 *b++ = '\0'; 1054 *b++ = '\0';
1054 return 1; 1055 return 1;
1055} 1056}
1056 1057
1057/* 1058/*
@@ -1246,101 +1247,104 @@ GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl)
1246 *size = sz; 1247 *size = sz;
1247 else 1248 else
1248 rv = 0; 1249 rv = 0;
1249 } 1250 }
1250 return rv; 1251 return rv;
1251} 1252}
1252 1253
1253/* 1254/*
1254 * FtpModDate - determine the modification date of a remote file 1255 * FtpModDate - determine the modification date of a remote file
1255 * 1256 *
1256 * return 1 if successful, 0 otherwise 1257 * return 1 if successful, 0 otherwise
1257 */ 1258 */
1258GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl) 1259GLOBALDEF int FtpModDate(const char *path, char *dt, int max, netbuf *nControl)
1259{ 1260{
1260 char buf[256]; 1261 char buf[256];
1261 int rv = 1; 1262 int rv = 1;
1262 1263
1263 if ((strlen(path) + 7) > sizeof(buf)) 1264 if ((strlen(path) + 7) > sizeof(buf))
1264 return 0; 1265 return 0;
1265 sprintf(buf,"MDTM %s",path); 1266 sprintf(buf,"MDTM %s",path);
1266 if (!FtpSendCmd(buf,'2',nControl)) 1267 if (!FtpSendCmd(buf,'2',nControl))
1267 rv = 0; 1268 rv = 0;
1268 else 1269 else
1269 strncpy(dt, &nControl->response[4], max); 1270 strncpy(dt, &nControl->response[4], max);
1270 return rv; 1271 return rv;
1271} 1272}
1272 1273
1273/* 1274/*
1274 * FtpGet - issue a GET command and write received data to output 1275 * FtpGet - issue a GET command and write received data to output
1275 * 1276 *
1276 * return 1 if successful, 0 otherwise 1277 * return 1 if successful, 0 otherwise
1277 */ 1278 */
1278GLOBALDEF int FtpGet(const char *outputfile, const char *path, 1279GLOBALDEF int FtpGet(const char *outputfile, const char *path,
1279 char mode, netbuf *nControl) 1280 char mode, netbuf *nControl)
1280{ 1281{
1281 return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode); 1282 return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode);
1282} 1283}
1283 1284
1284/* 1285/*
1285 * FtpPut - issue a PUT command and send data from input 1286 * FtpPut - issue a PUT command and send data from input
1286 * 1287 *
1287 * return 1 if successful, 0 otherwise 1288 * return 1 if successful, 0 otherwise
1288 */ 1289 */
1289GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode, 1290GLOBALDEF int FtpPut(const char *inputfile, const char *path, char mode,
1290 netbuf *nControl) 1291 netbuf *nControl)
1291{ 1292{
1292 return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode); 1293 return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode);
1293} 1294}
1294 1295
1295/* 1296/*
1296 * FtpRename - rename a file at remote 1297 * FtpRename - rename a file at remote
1297 * 1298 *
1298 * return 1 if successful, 0 otherwise 1299 * return 1 if successful, 0 otherwise
1299 */ 1300 */
1300GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl) 1301GLOBALDEF int FtpRename(const char *src, const char *dst, netbuf *nControl)
1301{ 1302{
1302 char cmd[256]; 1303 char cmd[256];
1303 1304
1304 if (((strlen(src) + 7) > sizeof(cmd)) || 1305 if (((strlen(src) + 7) > sizeof(cmd)) ||
1305 ((strlen(dst) + 7) > sizeof(cmd))) 1306 ((strlen(dst) + 7) > sizeof(cmd)))
1306 return 0; 1307 return 0;
1307 sprintf(cmd,"RNFR %s",src); 1308 sprintf(cmd,"RNFR %s",src);
1308 if (!FtpSendCmd(cmd,'3',nControl)) 1309 if (!FtpSendCmd(cmd,'3',nControl))
1309 return 0; 1310 return 0;
1310 sprintf(cmd,"RNTO %s",dst); 1311 sprintf(cmd,"RNTO %s",dst);
1311 if (!FtpSendCmd(cmd,'2',nControl)) 1312 if (!FtpSendCmd(cmd,'2',nControl))
1312 return 0; 1313 return 0;
1313 return 1; 1314 return 1;
1314} 1315}
1315 1316
1316/* 1317/*
1317 * FtpDelete - delete a file at remote 1318 * FtpDelete - delete a file at remote
1318 * 1319 *
1319 * return 1 if successful, 0 otherwise 1320 * return 1 if successful, 0 otherwise
1320 */ 1321 */
1321GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl) 1322GLOBALDEF int FtpDelete(const char *fnm, netbuf *nControl)
1322{ 1323{
1323 char cmd[256]; 1324 char cmd[256];
1324 1325
1325 if ((strlen(fnm) + 7) > sizeof(cmd)) 1326 if ((strlen(fnm) + 7) > sizeof(cmd))
1326 return 0; 1327 return 0;
1327 sprintf(cmd,"DELE %s",fnm); 1328 sprintf(cmd,"DELE %s",fnm);
1328 if (!FtpSendCmd(cmd,'2', nControl)) 1329 if (!FtpSendCmd(cmd,'2', nControl))
1329 return 0; 1330 return 0;
1330 return 1; 1331 return 1;
1331} 1332}
1332 1333
1333/* 1334/*
1334 * FtpQuit - disconnect from remote 1335 * FtpQuit - disconnect from remote
1335 * 1336 *
1336 * return 1 if successful, 0 otherwise 1337 * return 1 if successful, 0 otherwise
1337 */ 1338 */
1338GLOBALDEF void FtpQuit(netbuf *nControl) 1339GLOBALDEF void FtpQuit(netbuf *nControl)
1339{ 1340{
1340 if (nControl->dir != FTPLIB_CONTROL) 1341 if (nControl->dir != FTPLIB_CONTROL)
1341 return; 1342 return;
1342 FtpSendCmd("QUIT",'2',nControl); 1343 if (FtpSendCmd("QUIT",'2',nControl) == 1) {
1344 if (ftplib_debug > 2)
1345 fprintf(stderr, "FtpQuit: FtpSendCmd(QUIT) failed\n");
1346 }
1343 net_close(nControl->handle); 1347 net_close(nControl->handle);
1344 free(nControl->buf); 1348 free(nControl->buf);
1345 free(nControl); 1349 free(nControl);
1346} 1350}
diff --git a/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp b/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp
index 410d642..2498bf9 100644
--- a/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp
+++ b/noncore/todayplugins/stockticker/stockticker/helpwindow.cpp
@@ -86,186 +86,190 @@ HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* par
86 QStringList::Iterator it2 = bookmarks.begin(); 86 QStringList::Iterator it2 = bookmarks.begin();
87 for ( ; it2 != bookmarks.end(); ++it2 ) 87 for ( ; it2 != bookmarks.end(); ++it2 )
88 mBookmarks[ bookm->insertItem( *it2 ) ] = *it2; 88 mBookmarks[ bookm->insertItem( *it2 ) ] = *it2;
89 connect( bookm, SIGNAL( activated(int) ), 89 connect( bookm, SIGNAL( activated(int) ),
90 this, SLOT( bookmChosen(int) ) ); 90 this, SLOT( bookmChosen(int) ) );
91 91
92 menuBar()->insertItem( tr("&File"), file ); 92 menuBar()->insertItem( tr("&File"), file );
93 menuBar()->insertItem( tr("&Go"), go ); 93 menuBar()->insertItem( tr("&Go"), go );
94 menuBar()->insertItem( tr( "History" ), hist ); 94 menuBar()->insertItem( tr( "History" ), hist );
95 menuBar()->insertItem( tr( "Bookmarks" ), bookm ); 95 menuBar()->insertItem( tr( "Bookmarks" ), bookm );
96// menuBar()->insertSeparator(); 96// menuBar()->insertSeparator();
97// menuBar()->insertItem( tr("&Help"), help ); 97// menuBar()->insertItem( tr("&Help"), help );
98 98
99 menuBar()->setItemEnabled( forwardId, FALSE); 99 menuBar()->setItemEnabled( forwardId, FALSE);
100 menuBar()->setItemEnabled( backwardId, FALSE); 100 menuBar()->setItemEnabled( backwardId, FALSE);
101 connect( browser, SIGNAL( backwardAvailable(bool) ), this, SLOT( setBackwardAvailable(bool) ) ); 101 connect( browser, SIGNAL( backwardAvailable(bool) ), this, SLOT( setBackwardAvailable(bool) ) );
102 connect( browser, SIGNAL( forwardAvailable(bool) ), this, SLOT( setForwardAvailable(bool) ) ); 102 connect( browser, SIGNAL( forwardAvailable(bool) ), this, SLOT( setForwardAvailable(bool) ) );
103 103
104 104
105 QToolBar* toolbar = new QToolBar( this ); 105 QToolBar* toolbar = new QToolBar( this );
106 addToolBar( toolbar, "Toolbar"); 106 addToolBar( toolbar, "Toolbar");
107 QToolButton* button; 107 QToolButton* button;
108 108
109 button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar ); 109 button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar );
110 connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); 110 connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
111 button->setEnabled( FALSE ); 111 button->setEnabled( FALSE );
112 button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar ); 112 button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar );
113 connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); 113 connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
114 button->setEnabled( FALSE ); 114 button->setEnabled( FALSE );
115 button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar ); 115 button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar );
116 116
117 toolbar->addSeparator(); 117 toolbar->addSeparator();
118 118
119 pathCombo = new QComboBox( TRUE, toolbar ); 119 pathCombo = new QComboBox( TRUE, toolbar );
120 connect( pathCombo, SIGNAL( activated(const QString&) ), this, SLOT( pathSelected(const QString&) ) ); 120 connect( pathCombo, SIGNAL( activated(const QString&) ), this, SLOT( pathSelected(const QString&) ) );
121 toolbar->setStretchableWidget( pathCombo ); 121 toolbar->setStretchableWidget( pathCombo );
122 122
123// pathCombo->setMaximumWidth(190); 123// pathCombo->setMaximumWidth(190);
124// setRightJustification( TRUE ); 124// setRightJustification( TRUE );
125// setDockEnabled( Left, FALSE ); 125// setDockEnabled( Left, FALSE );
126// setDockEnabled( Right, FALSE ); 126// setDockEnabled( Right, FALSE );
127 127
128 pathCombo->insertItem( home_ ); 128 pathCombo->insertItem( home_ );
129 129
130 browser->setFocus(); 130 browser->setFocus();
131 131
132 132
133} 133}
134 134
135 135
136void HelpWindow::setBackwardAvailable( bool b) 136void HelpWindow::setBackwardAvailable( bool b)
137{ 137{
138 menuBar()->setItemEnabled( backwardId, b); 138 menuBar()->setItemEnabled( backwardId, b);
139} 139}
140 140
141void HelpWindow::setForwardAvailable( bool b) 141void HelpWindow::setForwardAvailable( bool b)
142{ 142{
143 menuBar()->setItemEnabled( forwardId, b); 143 menuBar()->setItemEnabled( forwardId, b);
144} 144}
145 145
146 146
147void HelpWindow::textChanged() 147void HelpWindow::textChanged()
148{ 148{
149 if ( browser->documentTitle().isNull() ) { 149 if ( browser->documentTitle().isNull() ) {
150 setCaption( "Stockticker Lookup - " + browser->context() ); 150 setCaption( "Stockticker Lookup - " + browser->context() );
151 selectedURL = browser->context(); 151 selectedURL = browser->context();
152 } 152 }
153 else { 153 else {
154 setCaption( "Stockticker Lookup - " + browser->documentTitle() ) ; 154 setCaption( "Stockticker Lookup - " + browser->documentTitle() ) ;
155 selectedURL = browser->documentTitle(); 155 selectedURL = browser->documentTitle();
156 } 156 }
157 157
158 if ( !selectedURL.isEmpty() && pathCombo ) { 158 if ( !selectedURL.isEmpty() && pathCombo ) {
159 bool exists = FALSE; 159 bool exists = FALSE;
160 int i; 160 int i;
161 for ( i = 0; i < pathCombo->count(); ++i ) { 161 for ( i = 0; i < pathCombo->count(); ++i ) {
162 if ( pathCombo->text( i ) == selectedURL ) { 162 if ( pathCombo->text( i ) == selectedURL ) {
163 exists = TRUE; 163 exists = TRUE;
164 break; 164 break;
165 } 165 }
166 } 166 }
167 if ( !exists ) { 167 if ( !exists ) {
168 pathCombo->insertItem( selectedURL, 0 ); 168 pathCombo->insertItem( selectedURL, 0 );
169 pathCombo->setCurrentItem( 0 ); 169 pathCombo->setCurrentItem( 0 );
170 mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; 170 mHistory[ hist->insertItem( selectedURL ) ] = selectedURL;
171 } else 171 } else
172 pathCombo->setCurrentItem( i ); 172 pathCombo->setCurrentItem( i );
173 selectedURL = QString::null; 173 selectedURL = QString::null;
174 } 174 }
175} 175}
176 176
177HelpWindow::~HelpWindow() 177HelpWindow::~HelpWindow()
178{ 178{
179 history.clear(); 179 history.clear();
180 QMap<int, QString>::Iterator it = mHistory.begin(); 180 QMap<int, QString>::Iterator it = mHistory.begin();
181 for ( ; it != mHistory.end(); ++it ) 181 for ( ; it != mHistory.end(); ++it )
182 history.append( *it ); 182 history.append( *it );
183 183
184 QFile f( QDir::currentDirPath() + "/.history" ); 184 QFile f( QDir::currentDirPath() + "/.history" );
185 f.open( IO_WriteOnly ); 185 if ( f.open( IO_WriteOnly ) ) {
186 QDataStream s( &f ); 186 QDataStream s( &f );
187 s << history; 187 s << history;
188 f.close(); 188 f.close();
189 }
189 190
190 bookmarks.clear(); 191 bookmarks.clear();
191 QMap<int, QString>::Iterator it2 = mBookmarks.begin(); 192 QMap<int, QString>::Iterator it2 = mBookmarks.begin();
192 for ( ; it2 != mBookmarks.end(); ++it2 ) 193 for ( ; it2 != mBookmarks.end(); ++it2 )
193 bookmarks.append( *it2 ); 194 bookmarks.append( *it2 );
194 195
195 QFile f2( QDir::currentDirPath() + "/.bookmarks" ); 196 QFile f2( QDir::currentDirPath() + "/.bookmarks" );
196 f2.open( IO_WriteOnly ); 197 if ( !f2.open( IO_WriteOnly ) )
198 return;
197 QDataStream s2( &f2 ); 199 QDataStream s2( &f2 );
198 s2 << bookmarks; 200 s2 << bookmarks;
199 f2.close(); 201 f2.close();
200} 202}
201 203
202void HelpWindow::openFile() 204void HelpWindow::openFile()
203{ 205{
204#ifndef QT_NO_FILEDIALOG 206#ifndef QT_NO_FILEDIALOG
205 QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); 207 QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );
206 if ( !fn.isEmpty() ) 208 if ( !fn.isEmpty() )
207 browser->setSource( fn ); 209 browser->setSource( fn );
208#endif 210#endif
209} 211}
210 212
211void HelpWindow::newWindow() 213void HelpWindow::newWindow()
212{ 214{
213 ( new HelpWindow(browser->source(), "qbrowser") )->show(); 215 ( new HelpWindow(browser->source(), "qbrowser") )->show();
214} 216}
215 217
216void HelpWindow::pathSelected( const QString &_path ) 218void HelpWindow::pathSelected( const QString &_path )
217{ 219{
218 browser->setSource( _path ); 220 browser->setSource( _path );
219 QMap<int, QString>::Iterator it = mHistory.begin(); 221 QMap<int, QString>::Iterator it = mHistory.begin();
220 bool exists = FALSE; 222 bool exists = FALSE;
221 for ( ; it != mHistory.end(); ++it ) { 223 for ( ; it != mHistory.end(); ++it ) {
222 if ( *it == _path ) { 224 if ( *it == _path ) {
223 exists = TRUE; 225 exists = TRUE;
224 break; 226 break;
225 } 227 }
226 } 228 }
227 if ( !exists ) 229 if ( !exists )
228 mHistory[ hist->insertItem( _path ) ] = _path; 230 mHistory[ hist->insertItem( _path ) ] = _path;
229} 231}
230 232
231void HelpWindow::readHistory() 233void HelpWindow::readHistory()
232{ 234{
233 if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) { 235 if ( QFile::exists( QDir::currentDirPath() + "/.history" ) ) {
234 QFile f( QDir::currentDirPath() + "/.history" ); 236 QFile f( QDir::currentDirPath() + "/.history" );
235 f.open( IO_ReadOnly ); 237 if ( !f.open( IO_ReadOnly ) )
236 QDataStream s( &f ); 238 return;
237 s >> history; 239 QDataStream s( &f );
238 f.close(); 240 s >> history;
239 while ( history.count() > 20 ) 241 f.close();
240 history.remove( history.begin() ); 242 while ( history.count() > 20 )
243 history.remove( history.begin() );
241 } 244 }
242} 245}
243 246
244void HelpWindow::readBookmarks() 247void HelpWindow::readBookmarks()
245{ 248{
246 if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) { 249 if ( QFile::exists( QDir::currentDirPath() + "/.bookmarks" ) ) {
247 QFile f( QDir::currentDirPath() + "/.bookmarks" ); 250 QFile f( QDir::currentDirPath() + "/.bookmarks" );
248 f.open( IO_ReadOnly ); 251 if ( !f.open( IO_ReadOnly ) )
249 QDataStream s( &f ); 252 return;
250 s >> bookmarks; 253 QDataStream s( &f );
251 f.close(); 254 s >> bookmarks;
255 f.close();
252 } 256 }
253} 257}
254 258
255void HelpWindow::histChosen( int i ) 259void HelpWindow::histChosen( int i )
256{ 260{
257 if ( mHistory.contains( i ) ) 261 if ( mHistory.contains( i ) )
258 browser->setSource( mHistory[ i ] ); 262 browser->setSource( mHistory[ i ] );
259} 263}
260 264
261void HelpWindow::bookmChosen( int i ) 265void HelpWindow::bookmChosen( int i )
262{ 266{
263 if ( mBookmarks.contains( i ) ) 267 if ( mBookmarks.contains( i ) )
264 browser->setSource( mBookmarks[ i ] ); 268 browser->setSource( mBookmarks[ i ] );
265} 269}
266 270
267void HelpWindow::addBookmark() 271void HelpWindow::addBookmark()
268{ 272{
269 mBookmarks[ bookm->insertItem( caption() ) ] = caption(); 273 mBookmarks[ bookm->insertItem( caption() ) ] = caption();
270} 274}
271 275
diff --git a/noncore/todayplugins/weather/weatherpluginwidget.cpp b/noncore/todayplugins/weather/weatherpluginwidget.cpp
index fe54051..27624c5 100644
--- a/noncore/todayplugins/weather/weatherpluginwidget.cpp
+++ b/noncore/todayplugins/weather/weatherpluginwidget.cpp
@@ -11,231 +11,232 @@ _;:, .> :=|. This file is free software; you can
11 ._= =} : or (at your option) any later version. 11 ._= =} : or (at your option) any later version.
12 .%`+i> _;_. 12 .%`+i> _;_.
13 .i_,=:_. -<s. This file is distributed in the hope that 13 .i_,=:_. -<s. This file is distributed in the hope that
14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
15 : .. .:, . . . without even the implied warranty of 15 : .. .:, . . . without even the implied warranty of
16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General 17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.= = ; Public License for more details. 18..}^=.= = ; Public License for more details.
19++= -. .` .: 19++= -. .` .:
20: = ...= . :.=- You should have received a copy of the GNU 20: = ...= . :.=- You should have received a copy of the GNU
21-. .:....=;==+<; General Public License along with this file; 21-. .:....=;==+<; General Public License along with this file;
22 -_. . . )=. = see the file COPYING. If not, write to the 22 -_. . . )=. = see the file COPYING. If not, write to the
23 -- :-=` Free Software Foundation, Inc., 23 -- :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <opie2/oprocess.h> 29#include <opie2/oprocess.h>
30 30
31#include <opie2/oresource.h> 31#include <opie2/oresource.h>
32 32
33#include <qpe/config.h> 33#include <qpe/config.h>
34 34
35#include <qfile.h> 35#include <qfile.h>
36#include <qlabel.h> 36#include <qlabel.h>
37#include <qlayout.h> 37#include <qlayout.h>
38#include <qpixmap.h> 38#include <qpixmap.h>
39#include <qtextstream.h> 39#include <qtextstream.h>
40 40
41#include "weatherpluginwidget.h" 41#include "weatherpluginwidget.h"
42 42
43using namespace Opie::Core; 43using namespace Opie::Core;
44WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name ) 44WeatherPluginWidget::WeatherPluginWidget( QWidget *parent, const char* name )
45 : QWidget( parent, name ) 45 : QWidget( parent, name )
46{ 46{
47 QHBoxLayout *layout = new QHBoxLayout( this, 1, 2 ); 47 QHBoxLayout *layout = new QHBoxLayout( this, 1, 2 );
48 layout->setAutoAdd( true ); 48 layout->setAutoAdd( true );
49 49
50 weatherIcon = new QLabel( this ); 50 weatherIcon = new QLabel( this );
51 weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( "Clock", Opie::Core::OResource::SmallIcon ) ); 51 weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( "Clock", Opie::Core::OResource::SmallIcon ) );
52 52
53 weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this ); 53 weatherLabel = new QLabel( tr( "Retreiving current weather information." ), this );
54 weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) ); 54 weatherLabel->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ) );
55 55
56 weatherIcon->setFixedSize( weatherLabel->height(), weatherLabel->height() ); 56 weatherIcon->setFixedSize( weatherLabel->height(), weatherLabel->height() );
57 57
58 startTimer(1000); 58 startTimer(1000);
59} 59}
60 60
61WeatherPluginWidget::~WeatherPluginWidget() 61WeatherPluginWidget::~WeatherPluginWidget()
62{ 62{
63 QFile file( localFile ); 63 QFile file( localFile );
64 if ( file.exists() ) 64 if ( file.exists() )
65 { 65 {
66 file.remove(); 66 file.remove();
67 } 67 }
68} 68}
69 69
70void WeatherPluginWidget::timerEvent( QTimerEvent *e ) 70void WeatherPluginWidget::timerEvent( QTimerEvent *e )
71{ 71{
72 killTimer( e->timerId() ); 72 killTimer( e->timerId() );
73 retreiveData(); 73 retreiveData();
74} 74}
75 75
76 76
77 77
78void WeatherPluginWidget::retreiveData() 78void WeatherPluginWidget::retreiveData()
79{ 79{
80 Config config( "todayweatherplugin"); 80 Config config( "todayweatherplugin");
81 config.setGroup( "Config" ); 81 config.setGroup( "Config" );
82 82
83 location = config.readEntry( "Location", "" ); 83 location = config.readEntry( "Location", "" );
84 useMetric = config.readBoolEntry( "Metric", true ); 84 useMetric = config.readBoolEntry( "Metric", true );
85 frequency = config.readNumEntry( "Frequency", 5 ); 85 frequency = config.readNumEntry( "Frequency", 5 );
86 86
87 startTimer( frequency * 60000 ); 87 startTimer( frequency * 60000 );
88 88
89 localFile = "/tmp/"; 89 localFile = "/tmp/";
90 localFile.append( location ); 90 localFile.append( location );
91 localFile.append( ".TXT" ); 91 localFile.append( ".TXT" );
92 92
93 remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/"; 93 remoteFile = "http://weather.noaa.gov/pub/data/observations/metar/stations/";
94 remoteFile.append( location ); 94 remoteFile.append( location );
95 remoteFile.append( ".TXT" ); 95 remoteFile.append( ".TXT" );
96 96
97 QFile file( localFile ); 97 QFile file( localFile );
98 if ( file.exists() ) 98 if ( file.exists() )
99 { 99 {
100 file.remove(); 100 file.remove();
101 } 101 }
102 102
103 OProcess *proc = new OProcess; 103 OProcess *proc = new OProcess;
104 104
105 *proc << "wget" << "-q" << remoteFile << "-O" << localFile; 105 *proc << "wget" << "-q" << remoteFile << "-O" << localFile;
106 connect( proc, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( dataRetrieved(Opie::Core::OProcess*) ) ); 106 connect( proc, SIGNAL( processExited(Opie::Core::OProcess*) ), this, SLOT( dataRetrieved(Opie::Core::OProcess*) ) );
107 proc->start(); 107 if ( !proc->start() )
108 weatherLabel->setText( tr( "Could not start wget process." ) );
108} 109}
109 110
110void WeatherPluginWidget::displayWeather() 111void WeatherPluginWidget::displayWeather()
111{ 112{
112 weatherData = QString::null; 113 weatherData = QString::null;
113 114
114 QFile file( localFile ); 115 QFile file( localFile );
115 116
116 if ( file.size() > 0 && file.open( IO_ReadOnly ) ) 117 if ( file.size() > 0 && file.open( IO_ReadOnly ) )
117 { 118 {
118 QTextStream data( &file ); 119 QTextStream data( &file );
119 while ( !data.eof() ) 120 while ( !data.eof() )
120 { 121 {
121 weatherData.append( data.readLine() ); 122 weatherData.append( data.readLine() );
122 } 123 }
123 file.close(); 124 file.close();
124 weatherData = weatherData.simplifyWhiteSpace(); 125 weatherData = weatherData.simplifyWhiteSpace();
125 126
126 QString tmpstr; 127 QString tmpstr;
127 128
128 tmpstr.append( tr( "Temp: " ) ); 129 tmpstr.append( tr( "Temp: " ) );
129 getTemp( weatherData ); 130 getTemp( weatherData );
130 tmpstr.append( dataStr ); 131 tmpstr.append( dataStr );
131 132
132 tmpstr.append( tr( " Wind: " ) ); 133 tmpstr.append( tr( " Wind: " ) );
133 getWind( weatherData ); 134 getWind( weatherData );
134 tmpstr.append( dataStr ); 135 tmpstr.append( dataStr );
135 136
136 tmpstr.append( tr( "\nPres: " ) ); 137 tmpstr.append( tr( "\nPres: " ) );
137 getPressure( weatherData ); 138 getPressure( weatherData );
138 tmpstr.append( dataStr ); 139 tmpstr.append( dataStr );
139 140
140 weatherLabel->setText( tmpstr ); 141 weatherLabel->setText( tmpstr );
141 142
142 tmpstr = "todayweatherplugin/"; 143 tmpstr = "todayweatherplugin/";
143 getIcon( weatherData ); 144 getIcon( weatherData );
144 tmpstr.append( dataStr ); 145 tmpstr.append( dataStr );
145 weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( tmpstr, Opie::Core::OResource::SmallIcon ) ); 146 weatherIcon->setPixmap( Opie::Core::OResource::loadPixmap( tmpstr, Opie::Core::OResource::SmallIcon ) );
146 } 147 }
147 else 148 else
148 { 149 {
149 weatherLabel->setText( tr( "Current weather data not available." ) ); 150 weatherLabel->setText( tr( "Current weather data not available." ) );
150 } 151 }
151} 152}
152 153
153void WeatherPluginWidget::getTemp( const QString &data ) 154void WeatherPluginWidget::getTemp( const QString &data )
154{ 155{
155 int value; 156 int value;
156 bool ok; 157 bool ok;
157 158
158 int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 ); 159 int pos = data.find( QRegExp( "M?[0-9]+/M?[0-9]+" ), 20 );
159 if ( pos > -1 ) 160 if ( pos > -1 )
160 { 161 {
161 if ( data.at( pos ) == 'M' ) 162 if ( data.at( pos ) == 'M' )
162 { 163 {
163 value = -1 * data.mid( pos + 1, 2 ).toInt( &ok ); 164 value = -1 * data.mid( pos + 1, 2 ).toInt( &ok );
164 } 165 }
165 else 166 else
166 { 167 {
167 value = data.mid( pos, 2 ).toInt( &ok ); 168 value = data.mid( pos, 2 ).toInt( &ok );
168 } 169 }
169 if ( useMetric ) 170 if ( useMetric )
170 { 171 {
171 dataStr = QString::number( value ); 172 dataStr = QString::number( value );
172 dataStr.append( 'C' ); 173 dataStr.append( 'C' );
173 } 174 }
174 else 175 else
175 { 176 {
176 dataStr = QString::number( ( value * 9 / 5 ) + 32 ); 177 dataStr = QString::number( ( value * 9 / 5 ) + 32 );
177 dataStr.append( 'F' ); 178 dataStr.append( 'F' );
178 } 179 }
179 } 180 }
180 else 181 else
181 { 182 {
182 dataStr = tr( "n/a" ); 183 dataStr = tr( "n/a" );
183 } 184 }
184} 185}
185 186
186void WeatherPluginWidget::getWind( const QString &data ) 187void WeatherPluginWidget::getWind( const QString &data )
187{ 188{
188 int value; 189 int value;
189 bool ok; 190 bool ok;
190 191
191 int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 ); 192 int pos = data.find( QRegExp( "[0-9]*G*[0-9]*KT" ), 20 );
192 if ( pos > -1 ) 193 if ( pos > -1 )
193 { 194 {
194 if ( data.mid( pos, 3 ) != "VRB" ) 195 if ( data.mid( pos, 3 ) != "VRB" )
195 { 196 {
196 value = data.mid( pos, 3 ).toInt( &ok ); 197 value = data.mid( pos, 3 ).toInt( &ok );
197 if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) ) 198 if ( ( value >= 0 && value < 23 ) || ( value >= 239 && value <= 360 ) )
198 dataStr = tr("E " ); 199 dataStr = tr("E " );
199 else if ( value >= 23 && value < 69 ) 200 else if ( value >= 23 && value < 69 )
200 dataStr = tr( "NE " ); 201 dataStr = tr( "NE " );
201 else if ( value >= 69 && value < 113 ) 202 else if ( value >= 69 && value < 113 )
202 dataStr = tr( "N " ); 203 dataStr = tr( "N " );
203 else if ( value >= 113 && value < 157 ) 204 else if ( value >= 113 && value < 157 )
204 dataStr = tr( "NW " ); 205 dataStr = tr( "NW " );
205 else if ( value >= 157 && value < 203 ) 206 else if ( value >= 157 && value < 203 )
206 dataStr = tr( "W " ); 207 dataStr = tr( "W " );
207 else if ( value >= 203 && value < 248 ) 208 else if ( value >= 203 && value < 248 )
208 dataStr = tr( "SW " ); 209 dataStr = tr( "SW " );
209 else if ( value >= 248 && value < 294 ) 210 else if ( value >= 248 && value < 294 )
210 dataStr = tr( "S " ); 211 dataStr = tr( "S " );
211 else if ( value >= 294 && value < 238 ) 212 else if ( value >= 294 && value < 238 )
212 dataStr = tr( "SE " ); 213 dataStr = tr( "SE " );
213 } 214 }
214 if ( data.mid( pos + 5, 1) == "G" || 215 if ( data.mid( pos + 5, 1) == "G" ||
215 data.mid( pos + 5, 1) == "K" ) 216 data.mid( pos + 5, 1) == "K" )
216 { 217 {
217 value = data.mid( pos + 3, 2 ).toInt( &ok ); 218 value = data.mid( pos + 3, 2 ).toInt( &ok );
218 } 219 }
219 else 220 else
220 { 221 {
221 value = data.mid( pos + 3, 3 ).toInt( &ok ); 222 value = data.mid( pos + 3, 3 ).toInt( &ok );
222 } 223 }
223 if ( useMetric ) 224 if ( useMetric )
224 { 225 {
225 value = value * 3.6 / 1.94; 226 value = value * 3.6 / 1.94;
226 dataStr.append( QString::number( value ) ); 227 dataStr.append( QString::number( value ) );
227 dataStr.append( tr( " KPH" ) ); 228 dataStr.append( tr( " KPH" ) );
228 } 229 }
229 else 230 else
230 { 231 {
231 value = value * 2.24 / 1.94; 232 value = value * 2.24 / 1.94;
232 dataStr.append( QString::number( value ) ); 233 dataStr.append( QString::number( value ) );
233 dataStr.append( tr( " MPH" ) ); 234 dataStr.append( tr( " MPH" ) );
234 } 235 }
235 } 236 }
236 else 237 else
237 { 238 {
238 dataStr = tr( "n/a" ); 239 dataStr = tr( "n/a" );
239 } 240 }
240} 241}
241 242
diff --git a/noncore/tools/opie-sh/inputdialog.cpp b/noncore/tools/opie-sh/inputdialog.cpp
index 8046795..1dd8bf7 100644
--- a/noncore/tools/opie-sh/inputdialog.cpp
+++ b/noncore/tools/opie-sh/inputdialog.cpp
@@ -1,124 +1,128 @@
1/* 1/*
2Opie-sh. convinience app to allow you to use qdialogs in scripts (mainly shell scripts) 2Opie-sh. convinience app to allow you to use qdialogs in scripts (mainly shell scripts)
3Copyright (C) 2002 Thomas Stephens 3Copyright (C) 2002 Thomas Stephens
4 4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later 6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version. 7version.
8 8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details. 11Public License for more details.
12 12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free 13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/ 15*/
16#include "inputdialog.h" 16#include "inputdialog.h"
17 17
18InputDialog::InputDialog(int w, int h, int newtype, QString labelString, QString title, QString filename, bool edit, QWidget *parent, const char *name, bool modal, WFlags f):QDialog(parent, name, modal, f) 18InputDialog::InputDialog(int w, int h, int newtype, QString labelString, QString title, QString filename, bool edit, QWidget *parent, const char *name, bool modal, WFlags f):QDialog(parent, name, modal, f)
19{ 19{
20 type = newtype; 20 type = newtype;
21 QHBoxLayout *layout = new QHBoxLayout(this); 21 QHBoxLayout *layout = new QHBoxLayout(this);
22 layout->addStrut(32); 22 layout->addStrut(32);
23 QLabel *label = new QLabel(labelString, this, "label"); 23 QLabel *label = new QLabel(labelString, this, "label");
24 setCaption(title); 24 setCaption(title);
25 int x, y; 25 int x, y;
26 26
27 layout->addSpacing(5); 27 layout->addSpacing(5);
28 layout->addWidget(label); 28 layout->addWidget(label);
29 layout->addSpacing(5); 29 layout->addSpacing(5);
30 30
31 switch(type) 31 switch(type)
32 { 32 {
33 case 0: 33 case 0:
34 lineEdit = new QLineEdit(this, "line edit"); 34 lineEdit = new QLineEdit(this, "line edit");
35 layout->addWidget(lineEdit); 35 layout->addWidget(lineEdit);
36 break; 36 break;
37 case 1: 37 case 1:
38 comboBox = new QComboBox(edit, this, "combo box"); 38 comboBox = new QComboBox(edit, this, "combo box");
39 layout->addWidget(comboBox); 39 layout->addWidget(comboBox);
40 if(!filename.isNull()) 40 if(!filename.isNull())
41 { 41 {
42 QFile file(filename); 42 QFile file(filename);
43 file.open(IO_ReadOnly); 43 if (file.open(IO_ReadOnly))
44 QTextStream stream(&file); 44 {
45 QString string = stream.read(); 45 QTextStream stream(&file);
46 QString string = stream.read();
46 47
47 comboBox->insertStringList(QStringList::split('\n', string)); 48 comboBox->insertStringList(QStringList::split('\n', string));
49 }
48 } 50 }
49 else 51 else
50 { 52 {
51 QFile file; 53 QFile file;
52 file.open(IO_ReadOnly, 0); 54 file.open(IO_ReadOnly, 0);
53 QTextStream stream(&file); 55 QTextStream stream(&file);
54 QString string = stream.read(); 56 QString string = stream.read();
55 57
56 comboBox->insertStringList(QStringList::split('\n', string)); 58 comboBox->insertStringList(QStringList::split('\n', string));
57 } 59 }
58 break; 60 break;
59 case 2: 61 case 2:
60 listBox = new QListBox(this, "list box"); 62 listBox = new QListBox(this, "list box");
61 listBox->setSelectionMode(QListBox::Multi); 63 listBox->setSelectionMode(QListBox::Multi);
62 layout->addWidget(listBox); 64 layout->addWidget(listBox);
63 if(!filename.isNull()) 65 if(!filename.isNull())
64 { 66 {
65 QFile file(filename); 67 QFile file(filename);
66 file.open(IO_ReadOnly); 68 if (file.open(IO_ReadOnly))
67 QTextStream stream(&file); 69 {
68 QString string = stream.read(); 70 QTextStream stream(&file);
71 QString string = stream.read();
69 72
70 listBox->insertStringList(QStringList::split('\n', string)); 73 listBox->insertStringList(QStringList::split('\n', string));
74 }
71 } 75 }
72 else 76 else
73 { 77 {
74 QFile file; 78 QFile file;
75 file.open(IO_ReadOnly, 0); 79 file.open(IO_ReadOnly, 0);
76 QTextStream stream(&file); 80 QTextStream stream(&file);
77 QString string = stream.read(); 81 QString string = stream.read();
78 82
79 listBox->insertStringList(QStringList::split('\n', string)); 83 listBox->insertStringList(QStringList::split('\n', string));
80 } 84 }
81 break; 85 break;
82 case 3: 86 case 3:
83 lineEdit = new QLineEdit(this, "line edit"); 87 lineEdit = new QLineEdit(this, "line edit");
84 lineEdit->setEchoMode(QLineEdit::Password); 88 lineEdit->setEchoMode(QLineEdit::Password);
85 layout->addWidget(lineEdit); 89 layout->addWidget(lineEdit);
86 break; 90 break;
87 } 91 }
88 layout->addSpacing(5); 92 layout->addSpacing(5);
89 93
90 x=(w/2)-(width()/2); 94 x=(w/2)-(width()/2);
91 y=(h/2)-(height()/2); 95 y=(h/2)-(height()/2);
92 96
93 move(x,y); 97 move(x,y);
94} 98}
95 99
96QString InputDialog::getString() 100QString InputDialog::getString()
97{ 101{
98 switch (type) 102 switch (type)
99 { 103 {
100 case 0: 104 case 0:
101 case 3: 105 case 3:
102 return ((QLineEdit *)child("line edit"))->text(); 106 return ((QLineEdit *)child("line edit"))->text();
103 break; 107 break;
104 case 1: 108 case 1:
105 return ((QComboBox *)child("combo box"))->currentText(); 109 return ((QComboBox *)child("combo box"))->currentText();
106 break; 110 break;
107 case 2: 111 case 2:
108 QString string; 112 QString string;
109 int i; 113 int i;
110 for(i = 0; i < listBox->count(); i++) 114 for(i = 0; i < listBox->count(); i++)
111 { 115 {
112 if(listBox->isSelected(i)) 116 if(listBox->isSelected(i))
113 { 117 {
114 string+=listBox->text(i)+'\n'; 118 string+=listBox->text(i)+'\n';
115 } 119 }
116 } 120 }
117 if(string[string.length()-1] == '\n') 121 if(string[string.length()-1] == '\n')
118 { 122 {
119 string.truncate(string.length()-1); 123 string.truncate(string.length()-1);
120 } 124 }
121 return string; 125 return string;
122 } 126 }
123 return QString::null; 127 return QString::null;
124} 128}