summaryrefslogtreecommitdiff
authorerik <erik>2007-01-22 22:56:12 (UTC)
committer erik <erik>2007-01-22 22:56:12 (UTC)
commit9b4871054d01a47b4c546952a0948553413840d6 (patch) (unidiff)
tree4e0248489c2790cf4225a116cfb903b637d4cdf0
parentf60301bab1f8aa3693089036a3791a01ae6f9db8 (diff)
downloadopie-9b4871054d01a47b4c546952a0948553413840d6.zip
opie-9b4871054d01a47b4c546952a0948553413840d6.tar.gz
opie-9b4871054d01a47b4c546952a0948553413840d6.tar.bz2
Every file in this commit makes a call to a function which returns a value.
Each file also didn't check the return value. This commit changes it so that every single non-checked call in these files is checked.
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,163 +1,164 @@
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;
147 148
148 if( filePath != currentFile) 149 if( filePath != currentFile)
149 list += currentFile+"\n"; 150 list += currentFile+"\n";
150 } 151 }
151 f.writeBlock( list, list.length() ); 152 f.writeBlock( list, list.length() );
152 } 153 }
153} 154}
154 155
155void Om3u::deleteFile(const QString &) {//deletes m3u file 156void Om3u::deleteFile(const QString &) {//deletes m3u file
156 f.close(); 157 f.close();
157 f.remove(); 158 f.remove();
158 159
159} 160}
160 161
161void Om3u::close() { //closes m3u file 162void Om3u::close() { //closes m3u file
162 f.close(); 163 f.close();
163} 164}
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
@@ -1,1151 +1,1155 @@
1#include "opieexif.h" 1#include "opieexif.h"
2 2
3/* OPIE */ 3/* OPIE */
4#include <opie2/odebug.h> 4#include <opie2/odebug.h>
5#include <qpe/timestring.h> 5#include <qpe/timestring.h>
6/* QT */ 6/* QT */
7#include <qobject.h> 7#include <qobject.h>
8#include <qimage.h> 8#include <qimage.h>
9 9
10/** 10/**
11 exif.h 11 exif.h
12*/ 12*/
13 13
14#include <stdio.h> 14#include <stdio.h>
15#include <stdlib.h> 15#include <stdlib.h>
16#include <math.h> 16#include <math.h>
17#include <time.h> 17#include <time.h>
18 18
19#include <qstring.h> 19#include <qstring.h>
20#include <qfile.h> 20#include <qfile.h>
21#include <qimage.h> 21#include <qimage.h>
22 22
23//static int HaveAll; 23//static int HaveAll;
24 24
25//-------------------------------------------------------------------------- 25//--------------------------------------------------------------------------
26// Table of Jpeg encoding process names 26// Table of Jpeg encoding process names
27 27
28#define M_SOF0 0xC0 // Start Of Frame N 28#define M_SOF0 0xC0 // Start Of Frame N
29#define M_SOF1 0xC1 // N indicates which compression process 29#define M_SOF1 0xC1 // N indicates which compression process
30#define M_SOF2 0xC2 // Only SOF0-SOF2 are now in common use 30#define M_SOF2 0xC2 // Only SOF0-SOF2 are now in common use
31#define M_SOF3 0xC3 31#define M_SOF3 0xC3
32#define M_SOF5 0xC5 // NB: codes C4 and CC are NOT SOF markers 32#define M_SOF5 0xC5 // NB: codes C4 and CC are NOT SOF markers
33#define M_SOF6 0xC6 33#define M_SOF6 0xC6
34#define M_SOF7 0xC7 34#define M_SOF7 0xC7
35#define M_SOF9 0xC9 35#define M_SOF9 0xC9
36#define M_SOF10 0xCA 36#define M_SOF10 0xCA
37#define M_SOF11 0xCB 37#define M_SOF11 0xCB
38#define M_SOF13 0xCD 38#define M_SOF13 0xCD
39#define M_SOF14 0xCE 39#define M_SOF14 0xCE
40#define M_SOF15 0xCF 40#define M_SOF15 0xCF
41#define M_SOI 0xD8 // Start Of Image (beginning of datastream) 41#define M_SOI 0xD8 // Start Of Image (beginning of datastream)
42#define M_EOI 0xD9 // End Of Image (end of datastream) 42#define M_EOI 0xD9 // End Of Image (end of datastream)
43#define M_SOS 0xDA // Start Of Scan (begins compressed data) 43#define M_SOS 0xDA // Start Of Scan (begins compressed data)
44#define M_JFIF 0xE0 // Jfif marker 44#define M_JFIF 0xE0 // Jfif marker
45#define M_EXIF 0xE1 // Exif marker 45#define M_EXIF 0xE1 // Exif marker
46#define M_COM 0xFE // COMment 46#define M_COM 0xFE // COMment
47 47
48 48
49//-------------------------------------------------------------------------- 49//--------------------------------------------------------------------------
50// Describes format descriptor 50// Describes format descriptor
51static int BytesPerFormat[] = {0,1,1,2,4,8,1,1,2,4,8,4,8}; 51static int BytesPerFormat[] = {0,1,1,2,4,8,1,1,2,4,8,4,8};
52#define NUM_FORMATS 12 52#define NUM_FORMATS 12
53 53
54#define FMT_BYTE 1 54#define FMT_BYTE 1
55#define FMT_STRING 2 55#define FMT_STRING 2
56#define FMT_USHORT 3 56#define FMT_USHORT 3
57#define FMT_ULONG 4 57#define FMT_ULONG 4
58#define FMT_URATIONAL 5 58#define FMT_URATIONAL 5
59#define FMT_SBYTE 6 59#define FMT_SBYTE 6
60#define FMT_UNDEFINED 7 60#define FMT_UNDEFINED 7
61#define FMT_SSHORT 8 61#define FMT_SSHORT 8
62#define FMT_SLONG 9 62#define FMT_SLONG 9
63#define FMT_SRATIONAL 10 63#define FMT_SRATIONAL 10
64#define FMT_SINGLE 11 64#define FMT_SINGLE 11
65#define FMT_DOUBLE 12 65#define FMT_DOUBLE 12
66 66
67//-------------------------------------------------------------------------- 67//--------------------------------------------------------------------------
68// Describes tag values 68// Describes tag values
69 69
70#define TAG_EXIF_OFFSET 0x8769 70#define TAG_EXIF_OFFSET 0x8769
71#define TAG_INTEROP_OFFSET 0xa005 71#define TAG_INTEROP_OFFSET 0xa005
72 72
73#define TAG_MAKE 0x010F 73#define TAG_MAKE 0x010F
74#define TAG_MODEL 0x0110 74#define TAG_MODEL 0x0110
75#define TAG_ORIENTATION 0x0112 75#define TAG_ORIENTATION 0x0112
76 76
77#define TAG_EXPOSURETIME 0x829A 77#define TAG_EXPOSURETIME 0x829A
78#define TAG_FNUMBER 0x829D 78#define TAG_FNUMBER 0x829D
79 79
80#define TAG_SHUTTERSPEED 0x9201 80#define TAG_SHUTTERSPEED 0x9201
81#define TAG_APERTURE 0x9202 81#define TAG_APERTURE 0x9202
82#define TAG_MAXAPERTURE 0x9205 82#define TAG_MAXAPERTURE 0x9205
83#define TAG_FOCALLENGTH 0x920A 83#define TAG_FOCALLENGTH 0x920A
84 84
85#define TAG_DATETIME_ORIGINAL 0x9003 85#define TAG_DATETIME_ORIGINAL 0x9003
86#define TAG_USERCOMMENT 0x9286 86#define TAG_USERCOMMENT 0x9286
87 87
88#define TAG_SUBJECT_DISTANCE 0x9206 88#define TAG_SUBJECT_DISTANCE 0x9206
89#define TAG_FLASH 0x9209 89#define TAG_FLASH 0x9209
90 90
91#define TAG_FOCALPLANEXRES 0xa20E 91#define TAG_FOCALPLANEXRES 0xa20E
92#define TAG_FOCALPLANEUNITS 0xa210 92#define TAG_FOCALPLANEUNITS 0xa210
93#define TAG_EXIF_IMAGEWIDTH 0xA002 93#define TAG_EXIF_IMAGEWIDTH 0xA002
94#define TAG_EXIF_IMAGELENGTH 0xA003 94#define TAG_EXIF_IMAGELENGTH 0xA003
95 95
96// the following is added 05-jan-2001 vcs 96// the following is added 05-jan-2001 vcs
97#define TAG_EXPOSURE_BIAS 0x9204 97#define TAG_EXPOSURE_BIAS 0x9204
98#define TAG_WHITEBALANCE 0x9208 98#define TAG_WHITEBALANCE 0x9208
99#define TAG_METERING_MODE 0x9207 99#define TAG_METERING_MODE 0x9207
100#define TAG_EXPOSURE_PROGRAM 0x8822 100#define TAG_EXPOSURE_PROGRAM 0x8822
101#define TAG_ISO_EQUIVALENT 0x8827 101#define TAG_ISO_EQUIVALENT 0x8827
102#define TAG_COMPRESSION_LEVEL 0x9102 102#define TAG_COMPRESSION_LEVEL 0x9102
103 103
104#define TAG_THUMBNAIL_OFFSET 0x0201 104#define TAG_THUMBNAIL_OFFSET 0x0201
105#define TAG_THUMBNAIL_LENGTH 0x0202 105#define TAG_THUMBNAIL_LENGTH 0x0202
106 106
107 107
108 108
109namespace Opie { 109namespace Opie {
110 110
111namespace MM { 111namespace 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//--------------------------------------------------------------------------
305int ExifData::Get32s(void * Long) 305int ExifData::Get32s(void * Long)
306{ 306{
307 if (MotorolaOrder){ 307 if (MotorolaOrder){
308 return ((( char *)Long)[0] << 24) | (((uchar *)Long)[1] << 16) 308 return ((( char *)Long)[0] << 24) | (((uchar *)Long)[1] << 16)
309 | (((uchar *)Long)[2] << 8 ) | (((uchar *)Long)[3] << 0 ); 309 | (((uchar *)Long)[2] << 8 ) | (((uchar *)Long)[3] << 0 );
310 }else{ 310 }else{
311 return ((( char *)Long)[3] << 24) | (((uchar *)Long)[2] << 16) 311 return ((( char *)Long)[3] << 24) | (((uchar *)Long)[2] << 16)
312 | (((uchar *)Long)[1] << 8 ) | (((uchar *)Long)[0] << 0 ); 312 | (((uchar *)Long)[1] << 8 ) | (((uchar *)Long)[0] << 0 );
313 } 313 }
314} 314}
315 315
316//-------------------------------------------------------------------------- 316//--------------------------------------------------------------------------
317// Convert a 32 bit unsigned value from file's native byte order 317// Convert a 32 bit unsigned value from file's native byte order
318//-------------------------------------------------------------------------- 318//--------------------------------------------------------------------------
319unsigned ExifData::Get32u(void * Long) 319unsigned ExifData::Get32u(void * Long)
320{ 320{
321 return (unsigned)Get32s(Long) & 0xffffffff; 321 return (unsigned)Get32s(Long) & 0xffffffff;
322} 322}
323 323
324//-------------------------------------------------------------------------- 324//--------------------------------------------------------------------------
325// Evaluate number, be it int, rational, or float from directory. 325// Evaluate number, be it int, rational, or float from directory.
326//-------------------------------------------------------------------------- 326//--------------------------------------------------------------------------
327double ExifData::ConvertAnyFormat(void * ValuePtr, int Format) 327double ExifData::ConvertAnyFormat(void * ValuePtr, int Format)
328{ 328{
329 double Value; 329 double Value;
330 Value = 0; 330 Value = 0;
331 331
332 switch(Format){ 332 switch(Format){
333 case FMT_SBYTE: Value = *(signed char *)ValuePtr; break; 333 case FMT_SBYTE: Value = *(signed char *)ValuePtr; break;
334 case FMT_BYTE: Value = *(uchar *)ValuePtr; break; 334 case FMT_BYTE: Value = *(uchar *)ValuePtr; break;
335 335
336 case FMT_USHORT: Value = Get16u(ValuePtr); break; 336 case FMT_USHORT: Value = Get16u(ValuePtr); break;
337 337
338 case FMT_ULONG: Value = Get32u(ValuePtr); break; 338 case FMT_ULONG: Value = Get32u(ValuePtr); break;
339 339
340 case FMT_URATIONAL: 340 case FMT_URATIONAL:
341 case FMT_SRATIONAL: 341 case FMT_SRATIONAL:
342 { 342 {
343 int Num,Den; 343 int Num,Den;
344 Num = Get32s(ValuePtr); 344 Num = Get32s(ValuePtr);
345 Den = Get32s(4+(char *)ValuePtr); 345 Den = Get32s(4+(char *)ValuePtr);
346 if (Den == 0){ 346 if (Den == 0){
347 Value = 0; 347 Value = 0;
348 }else{ 348 }else{
349 Value = (double)Num/Den; 349 Value = (double)Num/Den;
350 } 350 }
351 break; 351 break;
352 } 352 }
353 353
354 case FMT_SSHORT: Value = (signed short)Get16u(ValuePtr); break; 354 case FMT_SSHORT: Value = (signed short)Get16u(ValuePtr); break;
355 case FMT_SLONG: Value = Get32s(ValuePtr); break; 355 case FMT_SLONG: Value = Get32s(ValuePtr); break;
356 356
357 // Not sure if this is correct (never seen float used in Exif format) 357 // Not sure if this is correct (never seen float used in Exif format)
358 case FMT_SINGLE: Value = (double)*(float *)ValuePtr; break; 358 case FMT_SINGLE: Value = (double)*(float *)ValuePtr; break;
359 case FMT_DOUBLE: Value = *(double *)ValuePtr; break; 359 case FMT_DOUBLE: Value = *(double *)ValuePtr; break;
360 } 360 }
361 return Value; 361 return Value;
362} 362}
363 363
364//-------------------------------------------------------------------------- 364//--------------------------------------------------------------------------
365// Process one of the nested EXIF directories. 365// Process one of the nested EXIF directories.
366//-------------------------------------------------------------------------- 366//--------------------------------------------------------------------------
367void ExifData::ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength) 367void ExifData::ProcessExifDir(unsigned char * DirStart, unsigned char * OffsetBase, unsigned ExifLength)
368{ 368{
369 int de; 369 int de;
370 int a; 370 int a;
371 int NumDirEntries; 371 int NumDirEntries;
372 unsigned ThumbnailOffset = 0; 372 unsigned ThumbnailOffset = 0;
373 unsigned ThumbnailSize = 0; 373 unsigned ThumbnailSize = 0;
374 374
375 NumDirEntries = Get16u(DirStart); 375 NumDirEntries = Get16u(DirStart);
376 #define DIR_ENTRY_ADDR(Start, Entry) (Start+2+12*(Entry)) 376 #define DIR_ENTRY_ADDR(Start, Entry) (Start+2+12*(Entry))
377 377
378 { 378 {
379 unsigned char * DirEnd; 379 unsigned char * DirEnd;
380 DirEnd = DIR_ENTRY_ADDR(DirStart, NumDirEntries); 380 DirEnd = DIR_ENTRY_ADDR(DirStart, NumDirEntries);
381 if (DirEnd+4 > (OffsetBase+ExifLength)){ 381 if (DirEnd+4 > (OffsetBase+ExifLength)){
382 if (DirEnd+2 == OffsetBase+ExifLength || DirEnd == OffsetBase+ExifLength){ 382 if (DirEnd+2 == OffsetBase+ExifLength || DirEnd == OffsetBase+ExifLength){
383 // Version 1.3 of jhead would truncate a bit too much. 383 // Version 1.3 of jhead would truncate a bit too much.
384 // This also caught later on as well. 384 // This also caught later on as well.
385 }else{ 385 }else{
386 // Note: Files that had thumbnails trimmed with jhead 1.3 or earlier 386 // Note: Files that had thumbnails trimmed with jhead 1.3 or earlier
387 // might trigger this. 387 // might trigger this.
388 return; 388 return;
389 } 389 }
390 } 390 }
391 if (DirEnd < LastExifRefd) LastExifRefd = DirEnd; 391 if (DirEnd < LastExifRefd) LastExifRefd = DirEnd;
392 } 392 }
393 393
394 for (de=0;de<NumDirEntries;de++){ 394 for (de=0;de<NumDirEntries;de++){
395 int Tag, Format, Components; 395 int Tag, Format, Components;
396 unsigned char * ValuePtr; 396 unsigned char * ValuePtr;
397 int ByteCount; 397 int ByteCount;
398 char * DirEntry; 398 char * DirEntry;
399 DirEntry = (char *)DIR_ENTRY_ADDR(DirStart, de); 399 DirEntry = (char *)DIR_ENTRY_ADDR(DirStart, de);
400 400
401 Tag = Get16u(DirEntry); 401 Tag = Get16u(DirEntry);
402 Format = Get16u(DirEntry+2); 402 Format = Get16u(DirEntry+2);
403 Components = Get32u(DirEntry+4); 403 Components = Get32u(DirEntry+4);
404 404
405 if ((Format-1) >= NUM_FORMATS) { 405 if ((Format-1) >= NUM_FORMATS) {
406 // (-1) catches illegal zero case as unsigned underflows to positive large. 406 // (-1) catches illegal zero case as unsigned underflows to positive large.
407 return; 407 return;
408 } 408 }
409 409
410 ByteCount = Components * BytesPerFormat[Format]; 410 ByteCount = Components * BytesPerFormat[Format];
411 411
412 if (ByteCount > 4){ 412 if (ByteCount > 4){
413 unsigned OffsetVal; 413 unsigned OffsetVal;
414 OffsetVal = Get32u(DirEntry+8); 414 OffsetVal = Get32u(DirEntry+8);
415 // If its bigger than 4 bytes, the dir entry contains an offset. 415 // If its bigger than 4 bytes, the dir entry contains an offset.
416 if (OffsetVal+ByteCount > ExifLength){ 416 if (OffsetVal+ByteCount > ExifLength){
417 // Bogus pointer offset and / or bytecount value 417 // Bogus pointer offset and / or bytecount value
418 //printf("Offset %d bytes %d ExifLen %d\n",OffsetVal, ByteCount, ExifLength); 418 //printf("Offset %d bytes %d ExifLen %d\n",OffsetVal, ByteCount, ExifLength);
419 419
420 return; 420 return;
421 } 421 }
422 ValuePtr = OffsetBase+OffsetVal; 422 ValuePtr = OffsetBase+OffsetVal;
423 }else{ 423 }else{
424 // 4 bytes or less and value is in the dir entry itself 424 // 4 bytes or less and value is in the dir entry itself
425 ValuePtr = (unsigned char *)DirEntry+8; 425 ValuePtr = (unsigned char *)DirEntry+8;
426 } 426 }
427 427
428 if (LastExifRefd < ValuePtr+ByteCount){ 428 if (LastExifRefd < ValuePtr+ByteCount){
429 // Keep track of last byte in the exif header that was actually referenced. 429 // Keep track of last byte in the exif header that was actually referenced.
430 // That way, we know where the discardable thumbnail data begins. 430 // That way, we know where the discardable thumbnail data begins.
431 LastExifRefd = ValuePtr+ByteCount; 431 LastExifRefd = ValuePtr+ByteCount;
432 } 432 }
433 433
434 // Extract useful components of tag 434 // Extract useful components of tag
435 switch(Tag){ 435 switch(Tag){
436 436
437 case TAG_MAKE: 437 case TAG_MAKE:
438 ExifData::CameraMake = QString((char*)ValuePtr); 438 ExifData::CameraMake = QString((char*)ValuePtr);
439 break; 439 break;
440 440
441 case TAG_MODEL: 441 case TAG_MODEL:
442 ExifData::CameraModel = QString((char*)ValuePtr); 442 ExifData::CameraModel = QString((char*)ValuePtr);
443 break; 443 break;
444 444
445 case TAG_ORIENTATION: 445 case TAG_ORIENTATION:
446 Orientation = (int)ConvertAnyFormat(ValuePtr, Format); 446 Orientation = (int)ConvertAnyFormat(ValuePtr, Format);
447 break; 447 break;
448 448
449 case TAG_DATETIME_ORIGINAL: 449 case TAG_DATETIME_ORIGINAL:
450 DateTime = QString((char*)ValuePtr); 450 DateTime = QString((char*)ValuePtr);
451 break; 451 break;
452 452
453 case TAG_USERCOMMENT: 453 case TAG_USERCOMMENT:
454 // Olympus has this padded with trailing spaces. Remove these first. 454 // Olympus has this padded with trailing spaces. Remove these first.
455 for (a=ByteCount;;){ 455 for (a=ByteCount;;){
456 a--; 456 a--;
457 if ((ValuePtr)[a] == ' '){ 457 if ((ValuePtr)[a] == ' '){
458 (ValuePtr)[a] = '\0'; 458 (ValuePtr)[a] = '\0';
459 }else{ 459 }else{
460 break; 460 break;
461 } 461 }
462 if (a == 0) break; 462 if (a == 0) break;
463 } 463 }
464 464
465 // Copy the comment 465 // Copy the comment
466 if (memcmp(ValuePtr, "ASCII",5) == 0){ 466 if (memcmp(ValuePtr, "ASCII",5) == 0){
467 for (a=5;a<10;a++){ 467 for (a=5;a<10;a++){
468 int c; 468 int c;
469 c = (ValuePtr)[a]; 469 c = (ValuePtr)[a];
470 if (c != '\0' && c != ' '){ 470 if (c != '\0' && c != ' '){
471 //strncpy(ImageInfo.Comments, (const char*)(a+ValuePtr), 199); 471 //strncpy(ImageInfo.Comments, (const char*)(a+ValuePtr), 199);
472 UserComment.sprintf("%s", (const char*)(a+ValuePtr)); 472 UserComment.sprintf("%s", (const char*)(a+ValuePtr));
473 break; 473 break;
474 } 474 }
475 } 475 }
476 }else{ 476 }else{
477 //strncpy(ImageInfo.Comments, (const char*)ValuePtr, 199); 477 //strncpy(ImageInfo.Comments, (const char*)ValuePtr, 199);
478 UserComment.sprintf("%s", (const char*)ValuePtr); 478 UserComment.sprintf("%s", (const char*)ValuePtr);
479 } 479 }
480 break; 480 break;
481 481
482 case TAG_FNUMBER: 482 case TAG_FNUMBER:
483 // Simplest way of expressing aperture, so I trust it the most. 483 // Simplest way of expressing aperture, so I trust it the most.
484 // (overwrite previously computd value if there is one) 484 // (overwrite previously computd value if there is one)
485 ExifData::ApertureFNumber = (float)ConvertAnyFormat(ValuePtr, Format); 485 ExifData::ApertureFNumber = (float)ConvertAnyFormat(ValuePtr, Format);
486 break; 486 break;
487 487
488 case TAG_APERTURE: 488 case TAG_APERTURE:
489 case TAG_MAXAPERTURE: 489 case TAG_MAXAPERTURE:
490 // More relevant info always comes earlier, so only use this field if we don't 490 // More relevant info always comes earlier, so only use this field if we don't
491 // have appropriate aperture information yet. 491 // have appropriate aperture information yet.
492 if (ExifData::ApertureFNumber == 0){ 492 if (ExifData::ApertureFNumber == 0){
493 ExifData::ApertureFNumber 493 ExifData::ApertureFNumber
494 = (float)exp(ConvertAnyFormat(ValuePtr, Format)*log(2)*0.5); 494 = (float)exp(ConvertAnyFormat(ValuePtr, Format)*log(2)*0.5);
495 } 495 }
496 break; 496 break;
497 497
498 case TAG_FOCALLENGTH: 498 case TAG_FOCALLENGTH:
499 // Nice digital cameras actually save the focal length as a function 499 // Nice digital cameras actually save the focal length as a function
500 // of how farthey are zoomed in. 500 // of how farthey are zoomed in.
501 ExifData::FocalLength = (float)ConvertAnyFormat(ValuePtr, Format); 501 ExifData::FocalLength = (float)ConvertAnyFormat(ValuePtr, Format);
502 break; 502 break;
503 503
504 case TAG_SUBJECT_DISTANCE: 504 case TAG_SUBJECT_DISTANCE:
505 // Inidcates the distacne the autofocus camera is focused to. 505 // Inidcates the distacne the autofocus camera is focused to.
506 // Tends to be less accurate as distance increases. 506 // Tends to be less accurate as distance increases.
507 ExifData::Distance = (float)ConvertAnyFormat(ValuePtr, Format); 507 ExifData::Distance = (float)ConvertAnyFormat(ValuePtr, Format);
508 break; 508 break;
509 509
510 case TAG_EXPOSURETIME: 510 case TAG_EXPOSURETIME:
511 // Simplest way of expressing exposure time, so I trust it most. 511 // Simplest way of expressing exposure time, so I trust it most.
512 // (overwrite previously computd value if there is one) 512 // (overwrite previously computd value if there is one)
513 ExifData::ExposureTime = (float)ConvertAnyFormat(ValuePtr, Format); 513 ExifData::ExposureTime = (float)ConvertAnyFormat(ValuePtr, Format);
514 break; 514 break;
515 515
516 case TAG_SHUTTERSPEED: 516 case TAG_SHUTTERSPEED:
517 // More complicated way of expressing exposure time, so only use 517 // More complicated way of expressing exposure time, so only use
518 // this value if we don't already have it from somewhere else. 518 // this value if we don't already have it from somewhere else.
519 if (ExifData::ExposureTime == 0){ 519 if (ExifData::ExposureTime == 0){
520 ExifData::ExposureTime 520 ExifData::ExposureTime
521 = (float)(1/exp(ConvertAnyFormat(ValuePtr, Format)*log(2))); 521 = (float)(1/exp(ConvertAnyFormat(ValuePtr, Format)*log(2)));
522 } 522 }
523 break; 523 break;
524 524
525 case TAG_FLASH: 525 case TAG_FLASH:
526 if (ConvertAnyFormat(ValuePtr, Format)){ 526 if (ConvertAnyFormat(ValuePtr, Format)){
527 ExifData::FlashUsed = 1; 527 ExifData::FlashUsed = 1;
528 } 528 }
529 break; 529 break;
530 530
531 case TAG_EXIF_IMAGELENGTH: 531 case TAG_EXIF_IMAGELENGTH:
532 ExifImageLength = (int)ConvertAnyFormat(ValuePtr, Format); 532 ExifImageLength = (int)ConvertAnyFormat(ValuePtr, Format);
533 break; 533 break;
534 534
535 case TAG_EXIF_IMAGEWIDTH: 535 case TAG_EXIF_IMAGEWIDTH:
536 ExifImageWidth = (int)ConvertAnyFormat(ValuePtr, Format); 536 ExifImageWidth = (int)ConvertAnyFormat(ValuePtr, Format);
537 break; 537 break;
538 538
539 case TAG_FOCALPLANEXRES: 539 case TAG_FOCALPLANEXRES:
540 FocalplaneXRes = ConvertAnyFormat(ValuePtr, Format); 540 FocalplaneXRes = ConvertAnyFormat(ValuePtr, Format);
541 break; 541 break;
542 542
543 case TAG_FOCALPLANEUNITS: 543 case TAG_FOCALPLANEUNITS:
544 switch((int)ConvertAnyFormat(ValuePtr, Format)){ 544 switch((int)ConvertAnyFormat(ValuePtr, Format)){
545 case 1: FocalplaneUnits = 25.4; break; // inch 545 case 1: FocalplaneUnits = 25.4; break; // inch
546 case 2: 546 case 2:
547 // According to the information I was using, 2 means meters. 547 // According to the information I was using, 2 means meters.
548 // But looking at the Cannon powershot's files, inches is the only 548 // But looking at the Cannon powershot's files, inches is the only
549 // sensible value. 549 // sensible value.
550 FocalplaneUnits = 25.4; 550 FocalplaneUnits = 25.4;
551 break; 551 break;
552 552
553 case 3: FocalplaneUnits = 10; break; // centimeter 553 case 3: FocalplaneUnits = 10; break; // centimeter
554 case 4: FocalplaneUnits = 1; break; // milimeter 554 case 4: FocalplaneUnits = 1; break; // milimeter
555 case 5: FocalplaneUnits = .001; break; // micrometer 555 case 5: FocalplaneUnits = .001; break; // micrometer
556 } 556 }
557 break; 557 break;
558 558
559 // Remaining cases contributed by: Volker C. Schoech (schoech@gmx.de) 559 // Remaining cases contributed by: Volker C. Schoech (schoech@gmx.de)
560 560
561 case TAG_EXPOSURE_BIAS: 561 case TAG_EXPOSURE_BIAS:
562 ExifData::ExposureBias = (float)ConvertAnyFormat(ValuePtr, Format); 562 ExifData::ExposureBias = (float)ConvertAnyFormat(ValuePtr, Format);
563 break; 563 break;
564 564
565 case TAG_WHITEBALANCE: 565 case TAG_WHITEBALANCE:
566 ExifData::Whitebalance = (int)ConvertAnyFormat(ValuePtr, Format); 566 ExifData::Whitebalance = (int)ConvertAnyFormat(ValuePtr, Format);
567 break; 567 break;
568 568
569 case TAG_METERING_MODE: 569 case TAG_METERING_MODE:
570 ExifData::MeteringMode = (int)ConvertAnyFormat(ValuePtr, Format); 570 ExifData::MeteringMode = (int)ConvertAnyFormat(ValuePtr, Format);
571 break; 571 break;
572 572
573 case TAG_EXPOSURE_PROGRAM: 573 case TAG_EXPOSURE_PROGRAM:
574 ExifData::ExposureProgram = (int)ConvertAnyFormat(ValuePtr, Format); 574 ExifData::ExposureProgram = (int)ConvertAnyFormat(ValuePtr, Format);
575 break; 575 break;
576 576
577 case TAG_ISO_EQUIVALENT: 577 case TAG_ISO_EQUIVALENT:
578 ExifData::ISOequivalent = (int)ConvertAnyFormat(ValuePtr, Format); 578 ExifData::ISOequivalent = (int)ConvertAnyFormat(ValuePtr, Format);
579 if ( ExifData::ISOequivalent < 50 ) ExifData::ISOequivalent *= 200; 579 if ( ExifData::ISOequivalent < 50 ) ExifData::ISOequivalent *= 200;
580 break; 580 break;
581 581
582 case TAG_COMPRESSION_LEVEL: 582 case TAG_COMPRESSION_LEVEL:
583 ExifData::CompressionLevel = (int)ConvertAnyFormat(ValuePtr, Format); 583 ExifData::CompressionLevel = (int)ConvertAnyFormat(ValuePtr, Format);
584 break; 584 break;
585 585
586 case TAG_THUMBNAIL_OFFSET: 586 case TAG_THUMBNAIL_OFFSET:
587 ThumbnailOffset = (unsigned)ConvertAnyFormat(ValuePtr, Format); 587 ThumbnailOffset = (unsigned)ConvertAnyFormat(ValuePtr, Format);
588 break; 588 break;
589 589
590 case TAG_THUMBNAIL_LENGTH: 590 case TAG_THUMBNAIL_LENGTH:
591 ThumbnailSize = (unsigned)ConvertAnyFormat(ValuePtr, Format); 591 ThumbnailSize = (unsigned)ConvertAnyFormat(ValuePtr, Format);
592 break; 592 break;
593 593
594 } 594 }
595 595
596 if (Tag == TAG_EXIF_OFFSET || Tag == TAG_INTEROP_OFFSET){ 596 if (Tag == TAG_EXIF_OFFSET || Tag == TAG_INTEROP_OFFSET){
597 unsigned char * SubdirStart; 597 unsigned char * SubdirStart;
598 SubdirStart = OffsetBase + Get32u(ValuePtr); 598 SubdirStart = OffsetBase + Get32u(ValuePtr);
599 if (SubdirStart < OffsetBase || SubdirStart > OffsetBase+ExifLength){ 599 if (SubdirStart < OffsetBase || SubdirStart > OffsetBase+ExifLength){
600 return; 600 return;
601 } 601 }
602 ProcessExifDir(SubdirStart, OffsetBase, ExifLength); 602 ProcessExifDir(SubdirStart, OffsetBase, ExifLength);
603 continue; 603 continue;
604 } 604 }
605 } 605 }
606 606
607 { 607 {
608 // In addition to linking to subdirectories via exif tags, 608 // In addition to linking to subdirectories via exif tags,
609 // there's also a potential link to another directory at the end of each 609 // there's also a potential link to another directory at the end of each
610 // directory. this has got to be the result of a comitee! 610 // directory. this has got to be the result of a comitee!
611 unsigned char * SubdirStart; 611 unsigned char * SubdirStart;
612 unsigned Offset; 612 unsigned Offset;
613 613
614 if (DIR_ENTRY_ADDR(DirStart, NumDirEntries) + 4 <= OffsetBase+ExifLength){ 614 if (DIR_ENTRY_ADDR(DirStart, NumDirEntries) + 4 <= OffsetBase+ExifLength){
615 Offset = Get32u(DIR_ENTRY_ADDR(DirStart, NumDirEntries)); 615 Offset = Get32u(DIR_ENTRY_ADDR(DirStart, NumDirEntries));
616 // There is at least one jpeg from an HP camera having an Offset of almost MAXUINT. 616 // There is at least one jpeg from an HP camera having an Offset of almost MAXUINT.
617 // Adding OffsetBase to it produces an overflow, so compare with ExifLength here. 617 // Adding OffsetBase to it produces an overflow, so compare with ExifLength here.
618 // See http://bugs.kde.org/show_bug.cgi?id=54542 618 // See http://bugs.kde.org/show_bug.cgi?id=54542
619 if (Offset && Offset < ExifLength){ 619 if (Offset && Offset < ExifLength){
620 SubdirStart = OffsetBase + Offset; 620 SubdirStart = OffsetBase + Offset;
621 if (SubdirStart > OffsetBase+ExifLength){ 621 if (SubdirStart > OffsetBase+ExifLength){
622 if (SubdirStart < OffsetBase+ExifLength+20){ 622 if (SubdirStart < OffsetBase+ExifLength+20){
623 // Jhead 1.3 or earlier would crop the whole directory! 623 // Jhead 1.3 or earlier would crop the whole directory!
624 // As Jhead produces this form of format incorrectness, 624 // As Jhead produces this form of format incorrectness,
625 // I'll just let it pass silently 625 // I'll just let it pass silently
626 owarn << "Thumbnail removed with Jhead 1.3 or earlier" << oendl; 626 owarn << "Thumbnail removed with Jhead 1.3 or earlier" << oendl;
627 }else{ 627 }else{
628 return; 628 return;
629 } 629 }
630 }else{ 630 }else{
631 if (SubdirStart <= OffsetBase+ExifLength){ 631 if (SubdirStart <= OffsetBase+ExifLength){
632 ProcessExifDir(SubdirStart, OffsetBase, ExifLength); 632 ProcessExifDir(SubdirStart, OffsetBase, ExifLength);
633 } 633 }
634 } 634 }
635 } 635 }
636 }else{ 636 }else{
637 // The exif header ends before the last next directory pointer. 637 // The exif header ends before the last next directory pointer.
638 } 638 }
639 } 639 }
640 640
641 if (ThumbnailSize && ThumbnailOffset){ 641 if (ThumbnailSize && ThumbnailOffset){
642 if (ThumbnailSize + ThumbnailOffset <= ExifLength){ 642 if (ThumbnailSize + ThumbnailOffset <= ExifLength){
643 // The thumbnail pointer appears to be valid. Store it. 643 // The thumbnail pointer appears to be valid. Store it.
644 Thumbnail.loadFromData(OffsetBase + ThumbnailOffset, ThumbnailSize, "JPEG"); 644 Thumbnail.loadFromData(OffsetBase + ThumbnailOffset, ThumbnailSize, "JPEG");
645 } 645 }
646 } 646 }
647} 647}
648 648
649//-------------------------------------------------------------------------- 649//--------------------------------------------------------------------------
650// Process a COM marker. We want to leave the bytes unchanged. The 650// Process a COM marker. We want to leave the bytes unchanged. The
651// progam that displays this text may decide to remove blanks, convert 651// progam that displays this text may decide to remove blanks, convert
652// newlines, or otherwise modify the text. In particular we want to be 652// newlines, or otherwise modify the text. In particular we want to be
653// safe for passing utf-8 text. 653// safe for passing utf-8 text.
654//-------------------------------------------------------------------------- 654//--------------------------------------------------------------------------
655void ExifData::process_COM (const uchar * Data, int length) 655void ExifData::process_COM (const uchar * Data, int length)
656{ 656{
657 QChar ch; 657 QChar ch;
658 int a; 658 int a;
659 659
660 for (a=2;a<length;a++){ 660 for (a=2;a<length;a++){
661 ch = Data[a]; 661 ch = Data[a];
662 if (ch == '\000') continue; // Remove nulls 662 if (ch == '\000') continue; // Remove nulls
663 Comment.append(ch); 663 Comment.append(ch);
664 } 664 }
665} 665}
666 666
667 667
668//-------------------------------------------------------------------------- 668//--------------------------------------------------------------------------
669// Process a SOFn marker. This is useful for the image dimensions 669// Process a SOFn marker. This is useful for the image dimensions
670//-------------------------------------------------------------------------- 670//--------------------------------------------------------------------------
671void ExifData::process_SOFn (const uchar * Data, int marker) 671void ExifData::process_SOFn (const uchar * Data, int marker)
672{ 672{
673 int data_precision, num_components; 673 int data_precision, num_components;
674 674
675 data_precision = Data[2]; 675 data_precision = Data[2];
676 ExifData::Height = Get16m(Data+3); 676 ExifData::Height = Get16m(Data+3);
677 ExifData::Width = Get16m(Data+5); 677 ExifData::Width = Get16m(Data+5);
678 num_components = Data[7]; 678 num_components = Data[7];
679 679
680 if (num_components == 3){ 680 if (num_components == 3){
681 ExifData::IsColor = 1; 681 ExifData::IsColor = 1;
682 }else{ 682 }else{
683 ExifData::IsColor = 0; 683 ExifData::IsColor = 0;
684 } 684 }
685 685
686 ExifData::Process = marker; 686 ExifData::Process = marker;
687 687
688} 688}
689 689
690//-------------------------------------------------------------------------- 690//--------------------------------------------------------------------------
691// Get 16 bits motorola order (always) for jpeg header stuff. 691// Get 16 bits motorola order (always) for jpeg header stuff.
692//-------------------------------------------------------------------------- 692//--------------------------------------------------------------------------
693int ExifData::Get16m(const void * Short) 693int ExifData::Get16m(const void * Short)
694{ 694{
695 return (((uchar *)Short)[0] << 8) | ((uchar *)Short)[1]; 695 return (((uchar *)Short)[0] << 8) | ((uchar *)Short)[1];
696} 696}
697 697
698 698
699//-------------------------------------------------------------------------- 699//--------------------------------------------------------------------------
700// Process a EXIF marker 700// Process a EXIF marker
701// Describes all the drivel that most digital cameras include... 701// Describes all the drivel that most digital cameras include...
702//-------------------------------------------------------------------------- 702//--------------------------------------------------------------------------
703void ExifData::process_EXIF(unsigned char * CharBuf, unsigned int length) 703void ExifData::process_EXIF(unsigned char * CharBuf, unsigned int length)
704{ 704{
705 ExifData::FlashUsed = 0; // If it s from a digicam, and it used flash, it says so. 705 ExifData::FlashUsed = 0; // If it s from a digicam, and it used flash, it says so.
706 706
707 FocalplaneXRes = 0; 707 FocalplaneXRes = 0;
708 FocalplaneUnits = 0; 708 FocalplaneUnits = 0;
709 ExifImageWidth = 0; 709 ExifImageWidth = 0;
710 ExifImageLength = 0; 710 ExifImageLength = 0;
711 711
712 { // Check the EXIF header component 712 { // Check the EXIF header component
713 static const uchar ExifHeader[] = "Exif\0\0"; 713 static const uchar ExifHeader[] = "Exif\0\0";
714 if (memcmp(CharBuf+2, ExifHeader,6)){ 714 if (memcmp(CharBuf+2, ExifHeader,6)){
715 return; 715 return;
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 ){
909 srcData8 = (unsigned char *)img.scanLine(y); 913 srcData8 = (unsigned char *)img.scanLine(y);
910 for ( x=0; x < img.width(); ++x ){ 914 for ( x=0; x < img.width(); ++x ){
911 destData8 = (unsigned char *)dest.scanLine(x); 915 destData8 = (unsigned char *)dest.scanLine(x);
912 destData8[img.height()-y-1] = srcData8[x]; 916 destData8[img.height()-y-1] = srcData8[x];
913 } 917 }
914 } 918 }
915 return dest; 919 return dest;
916} 920}
917 921
918static QImage rotate_90_all( const QImage& img ) { 922static QImage rotate_90_all( const QImage& img ) {
919 dest.create(img.height(), img.width(), img.depth()); 923 dest.create(img.height(), img.width(), img.depth());
920 for ( y=0; y < img.height(); ++y ) { 924 for ( y=0; y < img.height(); ++y ) {
921 srcData = (unsigned int *)img.scanLine(y); 925 srcData = (unsigned int *)img.scanLine(y);
922 for ( x=0; x < img.width(); ++x ) { 926 for ( x=0; x < img.width(); ++x ) {
923 destData = (unsigned int *)dest.scanLine(x); 927 destData = (unsigned int *)dest.scanLine(x);
924 destData[img.height()-y-1] = srcData[x]; 928 destData[img.height()-y-1] = srcData[x];
925 } 929 }
926 } 930 }
927 931
928 return dest; 932 return dest;
929} 933}
930 934
931 935
932static QImage rotate_90( const QImage & img ) { 936static QImage rotate_90( const QImage & img ) {
933 if ( img.depth() > 8) 937 if ( img.depth() > 8)
934 return rotate_90_all( img ); 938 return rotate_90_all( img );
935 else 939 else
936 return rotate_90_8( img ); 940 return rotate_90_8( img );
937} 941}
938 942
939static QImage rotate_180_all( const QImage& img ) { 943static QImage rotate_180_all( const QImage& img ) {
940 dest.create(img.width(), img.height(), img.depth()); 944 dest.create(img.width(), img.height(), img.depth());
941 for ( y=0; y < img.height(); ++y ){ 945 for ( y=0; y < img.height(); ++y ){
942 srcData = (unsigned int *)img.scanLine(y); 946 srcData = (unsigned int *)img.scanLine(y);
943 destData = (unsigned int *)dest.scanLine(img.height()-y-1); 947 destData = (unsigned int *)dest.scanLine(img.height()-y-1);
944 for ( x=0; x < img.width(); ++x ) 948 for ( x=0; x < img.width(); ++x )
945 destData[img.width()-x-1] = srcData[x]; 949 destData[img.width()-x-1] = srcData[x];
946 } 950 }
947 return dest; 951 return dest;
948} 952}
949 953
950static QImage rotate_180_8( const QImage& img ) { 954static QImage rotate_180_8( const QImage& img ) {
951 dest.create(img.width(), img.height(), img.depth()); 955 dest.create(img.width(), img.height(), img.depth());
952 dest.setNumColors(img.numColors()); 956 dest.setNumColors(img.numColors());
953 srcTable = (unsigned int *)img.colorTable(); 957 srcTable = (unsigned int *)img.colorTable();
954 destTable = (unsigned int *)dest.colorTable(); 958 destTable = (unsigned int *)dest.colorTable();
955 for ( x=0; x < img.numColors(); ++x ) 959 for ( x=0; x < img.numColors(); ++x )
956 destTable[x] = srcTable[x]; 960 destTable[x] = srcTable[x];
957 for ( y=0; y < img.height(); ++y ){ 961 for ( y=0; y < img.height(); ++y ){
958 srcData8 = (unsigned char *)img.scanLine(y); 962 srcData8 = (unsigned char *)img.scanLine(y);
959 destData8 = (unsigned char *)dest.scanLine(img.height()-y-1); 963 destData8 = (unsigned char *)dest.scanLine(img.height()-y-1);
960 for ( x=0; x < img.width(); ++x ) 964 for ( x=0; x < img.width(); ++x )
961 destData8[img.width()-x-1] = srcData8[x]; 965 destData8[img.width()-x-1] = srcData8[x];
962 } 966 }
963 return dest; 967 return dest;
964} 968}
965 969
966static QImage rotate_180( const QImage& img ) { 970static QImage rotate_180( const QImage& img ) {
967 if ( img.depth() > 8 ) 971 if ( img.depth() > 8 )
968 return rotate_180_all( img ); 972 return rotate_180_all( img );
969 else 973 else
970 return rotate_180_8( img ); 974 return rotate_180_8( img );
971} 975}
972 976
973 977
974static QImage rotate_270_8( const QImage& img ) { 978static QImage rotate_270_8( const QImage& img ) {
975 dest.create(img.height(), img.width(), img.depth()); 979 dest.create(img.height(), img.width(), img.depth());
976 dest.setNumColors(img.numColors()); 980 dest.setNumColors(img.numColors());
977 srcTable = (unsigned int *)img.colorTable(); 981 srcTable = (unsigned int *)img.colorTable();
978 destTable = (unsigned int *)dest.colorTable(); 982 destTable = (unsigned int *)dest.colorTable();
979 for ( x=0; x < img.numColors(); ++x ) 983 for ( x=0; x < img.numColors(); ++x )
980 destTable[x] = srcTable[x]; 984 destTable[x] = srcTable[x];
981 for ( y=0; y < img.height(); ++y ){ 985 for ( y=0; y < img.height(); ++y ){
982 srcData8 = (unsigned char *)img.scanLine(y); 986 srcData8 = (unsigned char *)img.scanLine(y);
983 for ( x=0; x < img.width(); ++x ){ 987 for ( x=0; x < img.width(); ++x ){
984 destData8 = (unsigned char *)dest.scanLine(img.width()-x-1); 988 destData8 = (unsigned char *)dest.scanLine(img.width()-x-1);
985 destData8[y] = srcData8[x]; 989 destData8[y] = srcData8[x];
986 } 990 }
987 } 991 }
988 992
989 return dest; 993 return dest;
990} 994}
991 995
992static QImage rotate_270_all( const QImage& img ) { 996static QImage rotate_270_all( const QImage& img ) {
993 dest.create(img.height(), img.width(), img.depth()); 997 dest.create(img.height(), img.width(), img.depth());
994 for ( y=0; y < img.height(); ++y ){ 998 for ( y=0; y < img.height(); ++y ){
995 srcData = (unsigned int *)img.scanLine(y); 999 srcData = (unsigned int *)img.scanLine(y);
996 for ( x=0; x < img.width(); ++x ){ 1000 for ( x=0; x < img.width(); ++x ){
997 destData = (unsigned int *)dest.scanLine(img.width()-x-1); 1001 destData = (unsigned int *)dest.scanLine(img.width()-x-1);
998 destData[y] = srcData[x]; 1002 destData[y] = srcData[x];
999 } 1003 }
1000 } 1004 }
1001 return dest; 1005 return dest;
1002} 1006}
1003 1007
1004static QImage rotate_270( const QImage& img ) { 1008static QImage rotate_270( const QImage& img ) {
1005 if ( img.depth() > 8 ) 1009 if ( img.depth() > 8 )
1006 return rotate_270_all( img ); 1010 return rotate_270_all( img );
1007 else 1011 else
1008 return rotate_270_8( img ); 1012 return rotate_270_8( img );
1009} 1013}
1010 1014
1011QString ExifData::color_mode_to_string( bool b ) { 1015QString ExifData::color_mode_to_string( bool b ) {
1012 return b ? QObject::tr( "Colormode: Color\n" ) : QObject::tr( "Colormode: Black and white\n" ); 1016 return b ? QObject::tr( "Colormode: Color\n" ) : QObject::tr( "Colormode: Black and white\n" );
1013} 1017}
1014 1018
1015QString ExifData::compression_to_string( int level ) { 1019QString ExifData::compression_to_string( int level ) {
1016 QString str; 1020 QString str;
1017 switch( level ) { 1021 switch( level ) {
1018 case 1: 1022 case 1:
1019 str = QObject::tr( "Basic" ); 1023 str = QObject::tr( "Basic" );
1020 break; 1024 break;
1021 case 2: 1025 case 2:
1022 str = QObject::tr( "Normal" ); 1026 str = QObject::tr( "Normal" );
1023 break; 1027 break;
1024 case 4: 1028 case 4:
1025 str = QObject::tr( "Fine" ); 1029 str = QObject::tr( "Fine" );
1026 break; 1030 break;
1027 default: 1031 default:
1028 str = QObject::tr( "Unknown" ); 1032 str = QObject::tr( "Unknown" );
1029 1033
1030 } 1034 }
1031 return QObject::tr("Quality: %1\n").arg(str); 1035 return QObject::tr("Quality: %1\n").arg(str);
1032} 1036}
1033 1037
1034QString ExifData::white_balance_string( int i ) { 1038QString ExifData::white_balance_string( int i ) {
1035 QString balance; 1039 QString balance;
1036 switch ( i ) { 1040 switch ( i ) {
1037 case 0: 1041 case 0:
1038 balance = QObject::tr( "Unknown" ); 1042 balance = QObject::tr( "Unknown" );
1039 break; 1043 break;
1040 case 1: 1044 case 1:
1041 balance = QObject::tr( "Daylight" ); 1045 balance = QObject::tr( "Daylight" );
1042 break; 1046 break;
1043 case 2: 1047 case 2:
1044 balance = QObject::tr( "Fluorescent" ); 1048 balance = QObject::tr( "Fluorescent" );
1045 break; 1049 break;
1046 case 3: 1050 case 3:
1047 balance = QObject::tr( "Tungsten" ); 1051 balance = QObject::tr( "Tungsten" );
1048 break; 1052 break;
1049 case 17: 1053 case 17:
1050 balance = QObject::tr( "Standard light A" ); 1054 balance = QObject::tr( "Standard light A" );
1051 break; 1055 break;
1052 case 18: 1056 case 18:
1053 balance = QObject::tr( "Standard light B" ); 1057 balance = QObject::tr( "Standard light B" );
1054 break; 1058 break;
1055 case 19: 1059 case 19:
1056 balance = QObject::tr( "Standard light C" ); 1060 balance = QObject::tr( "Standard light C" );
1057 break; 1061 break;
1058 case 20: 1062 case 20:
1059 balance = QObject::tr( "D55" ); 1063 balance = QObject::tr( "D55" );
1060 break; 1064 break;
1061 case 21: 1065 case 21:
1062 balance = QObject::tr( "D65" ); 1066 balance = QObject::tr( "D65" );
1063 break; 1067 break;
1064 case 22: 1068 case 22:
1065 balance = QObject::tr( "D75" ); 1069 balance = QObject::tr( "D75" );
1066 break; 1070 break;
1067 case 255: 1071 case 255:
1068 balance = QObject::tr( "Other" ); 1072 balance = QObject::tr( "Other" );
1069 break; 1073 break;
1070 default: 1074 default:
1071 balance = QObject::tr( "Unknown" ); 1075 balance = QObject::tr( "Unknown" );
1072 } 1076 }
1073 return QObject::tr( "White Balance: %1\n" ).arg( balance ); 1077 return QObject::tr( "White Balance: %1\n" ).arg( balance );
1074 1078
1075} 1079}
1076 1080
1077 1081
1078QString ExifData::metering_mode( int i) { 1082QString ExifData::metering_mode( int i) {
1079 QString meter; 1083 QString meter;
1080 switch( i ) { 1084 switch( i ) {
1081 case 0: 1085 case 0:
1082 meter = QObject::tr( "Unknown" ); 1086 meter = QObject::tr( "Unknown" );
1083 break; 1087 break;
1084 case 1: 1088 case 1:
1085 meter = QObject::tr( "Average" ); 1089 meter = QObject::tr( "Average" );
1086 break; 1090 break;
1087 case 2: 1091 case 2:
1088 meter = QObject::tr( "Center weighted average" ); 1092 meter = QObject::tr( "Center weighted average" );
1089 break; 1093 break;
1090 case 3: 1094 case 3:
1091 meter = QObject::tr( "Spot" ); 1095 meter = QObject::tr( "Spot" );
1092 break; 1096 break;
1093 case 4: 1097 case 4:
1094 meter = QObject::tr( "MultiSpot" ); 1098 meter = QObject::tr( "MultiSpot" );
1095 break; 1099 break;
1096 case 5: 1100 case 5:
1097 meter = QObject::tr( "Pattern" ); 1101 meter = QObject::tr( "Pattern" );
1098 break; 1102 break;
1099 case 6: 1103 case 6:
1100 meter = QObject::tr( "Partial" ); 1104 meter = QObject::tr( "Partial" );
1101 break; 1105 break;
1102 case 255: 1106 case 255:
1103 meter = QObject::tr( "Other" ); 1107 meter = QObject::tr( "Other" );
1104 break; 1108 break;
1105 default: 1109 default:
1106 meter = QObject::tr( "Unknown" ); 1110 meter = QObject::tr( "Unknown" );
1107 } 1111 }
1108 1112
1109 return QObject::tr( "Metering Mode: %1\n" ).arg( meter ); 1113 return QObject::tr( "Metering Mode: %1\n" ).arg( meter );
1110} 1114}
1111 1115
1112 1116
1113QString ExifData::exposure_program( int i ) { 1117QString ExifData::exposure_program( int i ) {
1114 QString exp; 1118 QString exp;
1115 switch( i ) { 1119 switch( i ) {
1116 case 0: 1120 case 0:
1117 exp = QObject::tr( "Not defined" ); 1121 exp = QObject::tr( "Not defined" );
1118 break; 1122 break;
1119 case 1: 1123 case 1:
1120 exp = QObject::tr( "Manual" ); 1124 exp = QObject::tr( "Manual" );
1121 break; 1125 break;
1122 case 2: 1126 case 2:
1123 exp = QObject::tr( "Normal progam" ); 1127 exp = QObject::tr( "Normal progam" );
1124 break; 1128 break;
1125 case 3: 1129 case 3:
1126 exp = QObject::tr( "Aperture priority" ); 1130 exp = QObject::tr( "Aperture priority" );
1127 break; 1131 break;
1128 case 4: 1132 case 4:
1129 exp = QObject::tr( "Shutter priority" ); 1133 exp = QObject::tr( "Shutter priority" );
1130 break; 1134 break;
1131 case 5: 1135 case 5:
1132 exp = QObject::tr( "Creative progam\n(biased toward fast shutter speed" ); 1136 exp = QObject::tr( "Creative progam\n(biased toward fast shutter speed" );
1133 break; 1137 break;
1134 case 6: 1138 case 6:
1135 exp = QObject::tr( "Action progam\n(biased toward fast shutter speed)" ); 1139 exp = QObject::tr( "Action progam\n(biased toward fast shutter speed)" );
1136 break; 1140 break;
1137 case 7: 1141 case 7:
1138 exp = QObject::tr( "Portrait mode\n(for closeup photos with the background out of focus)" ); 1142 exp = QObject::tr( "Portrait mode\n(for closeup photos with the background out of focus)" );
1139 break; 1143 break;
1140 case 8: 1144 case 8:
1141 exp = QObject::tr( "Landscape mode\n(for landscape photos with the background in focus)" ); 1145 exp = QObject::tr( "Landscape mode\n(for landscape photos with the background in focus)" );
1142 break; 1146 break;
1143 default: 1147 default:
1144 exp = QObject::tr( "Unknown" ); 1148 exp = QObject::tr( "Unknown" );
1145 } 1149 }
1146 1150
1147 return QObject::tr( "Exposure Program: %1\n" ).arg( exp ); 1151 return QObject::tr( "Exposure Program: %1\n" ).arg( exp );
1148} 1152}
1149 1153
1150} // namespace MM 1154} // namespace MM
1151} // namespace OPIE 1155} // namespace OPIE
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,248 +1,250 @@
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
103 104
104 105
105 /* replace by QSocketNotifier!!! */ 106 /* replace by QSocketNotifier!!! */
106 m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read ); 107 m_not = new QSocketNotifier(m_comm[0], QSocketNotifier::Read );
107 connect(m_not, SIGNAL(activated(int) ), 108 connect(m_not, SIGNAL(activated(int) ),
108 this, SLOT(slotRead() ) ); 109 this, SLOT(slotRead() ) );
109 if ( pipe(m_term) < 0 ) 110 if ( pipe(m_term) < 0 )
110 m_term[0] = m_term[1] = 0; 111 m_term[0] = m_term[1] = 0;
111 112
112 ProcCtl::self()->add(m_pid, m_term[1] ); 113 ProcCtl::self()->add(m_pid, m_term[1] );
113 m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read ); 114 m_proc = new QSocketNotifier(m_term[0], QSocketNotifier::Read );
114 connect(m_proc, SIGNAL(activated(int) ), 115 connect(m_proc, SIGNAL(activated(int) ),
115 this, SLOT(slotExec() ) ); 116 this, SLOT(slotExec() ) );
116 117
117 } 118 }
118 break; 119 break;
119 } 120 }
120} 121}
121/* 122/*
122 * let's call the one with the filename 123 * let's call the one with the filename
123 */ 124 */
124void FileTransfer::sendFile( const QFile& file ) { 125void FileTransfer::sendFile( const QFile& file ) {
125 sendFile( file.name() ); 126 sendFile( file.name() );
126} 127}
127 128
128/* 129/*
129 * setting up communication 130 * setting up communication
130 * between parent child and ioLayer 131 * between parent child and ioLayer
131 */ 132 */
132void FileTransfer::setupChild() { 133void FileTransfer::setupChild() {
133 /* 134 /*
134 * we do not want to read from our 135 * we do not want to read from our
135 * information channel 136 * information channel
136 */ 137 */
137 if (m_info[0] ) 138 if (m_info[0] )
138 close(m_info[0] ); 139 close(m_info[0] );
139 /* 140 /*
140 * FD_CLOEXEC will close the 141 * FD_CLOEXEC will close the
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
@@ -1,834 +1,835 @@
1#include "TEmulation.h" 1#include "TEmulation.h"
2#include "profileeditordialog.h" 2#include "profileeditordialog.h"
3#include "configdialog.h" 3#include "configdialog.h"
4#include "default.h" 4#include "default.h"
5#include "profilemanager.h" 5#include "profilemanager.h"
6#include "mainwindow.h" 6#include "mainwindow.h"
7#include "tabwidget.h" 7#include "tabwidget.h"
8#include "transferdialog.h" 8#include "transferdialog.h"
9#include "function_keyboard.h" 9#include "function_keyboard.h"
10#include "emulation_handler.h" 10#include "emulation_handler.h"
11#include "script.h" 11#include "script.h"
12#include "fixit.h" 12#include "fixit.h"
13 13
14/* OPIE */ 14/* OPIE */
15#include <opie2/ofiledialog.h> 15#include <opie2/ofiledialog.h>
16#include <opie2/oresource.h> 16#include <opie2/oresource.h>
17#include <qpe/filemanager.h> 17#include <qpe/filemanager.h>
18using namespace Opie::Ui; 18using namespace Opie::Ui;
19 19
20/* QT */ 20/* QT */
21#include <qaction.h> 21#include <qaction.h>
22#include <qmenubar.h> 22#include <qmenubar.h>
23#include <qtoolbar.h> 23#include <qtoolbar.h>
24#include <qmessagebox.h> 24#include <qmessagebox.h>
25#include <qwhatsthis.h> 25#include <qwhatsthis.h>
26#include <qfileinfo.h> 26#include <qfileinfo.h>
27 27
28/* STD */ 28/* STD */
29#include <assert.h> 29#include <assert.h>
30 30
31#include <opie2/oconfig.h> 31#include <opie2/oconfig.h>
32 32
33MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { 33MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) {
34 34
35#ifdef FSCKED_DISTRI 35#ifdef FSCKED_DISTRI
36 FixIt fix; 36 FixIt fix;
37 fix.fixIt(); 37 fix.fixIt();
38#endif 38#endif
39 39
40 setCaption(QObject::tr("Opie Console") ); 40 setCaption(QObject::tr("Opie Console") );
41 KeyTrans::loadAll(); 41 KeyTrans::loadAll();
42 for (int i = 0; i < KeyTrans::count(); i++ ) { 42 for (int i = 0; i < KeyTrans::count(); i++ ) {
43 KeyTrans* s = KeyTrans::find(i ); 43 KeyTrans* s = KeyTrans::find(i );
44 assert( s ); 44 assert( s );
45 } 45 }
46 m_factory = new MetaFactory(); 46 m_factory = new MetaFactory();
47 Default def(m_factory); 47 Default def(m_factory);
48 m_sessions.setAutoDelete( TRUE ); 48 m_sessions.setAutoDelete( TRUE );
49 m_curSession = 0; 49 m_curSession = 0;
50 m_manager = new ProfileManager( m_factory ); 50 m_manager = new ProfileManager( m_factory );
51 m_manager->load(); 51 m_manager->load();
52 m_scriptsData.setAutoDelete(TRUE); 52 m_scriptsData.setAutoDelete(TRUE);
53 53
54 initUI(); 54 initUI();
55 populateProfiles(); 55 populateProfiles();
56 populateScripts(); 56 populateScripts();
57} 57}
58 58
59void MainWindow::initUI() { 59void MainWindow::initUI() {
60 60
61 setToolBarsMovable( FALSE ); 61 setToolBarsMovable( FALSE );
62 62
63 /* tool bar for the menu */ 63 /* tool bar for the menu */
64 m_tool = new QToolBar( this ); 64 m_tool = new QToolBar( this );
65 m_tool->setHorizontalStretchable( TRUE ); 65 m_tool->setHorizontalStretchable( TRUE );
66 66
67 m_bar = new QMenuBar( m_tool ); 67 m_bar = new QMenuBar( m_tool );
68 m_console = new QPopupMenu( this ); 68 m_console = new QPopupMenu( this );
69 m_scripts = new QPopupMenu( this ); 69 m_scripts = new QPopupMenu( this );
70 m_sessionsPop= new QPopupMenu( this ); 70 m_sessionsPop= new QPopupMenu( this );
71 m_scriptsPop = new QPopupMenu( this ); 71 m_scriptsPop = new QPopupMenu( this );
72 m_scrollbar = new QPopupMenu( this ); 72 m_scrollbar = new QPopupMenu( this );
73 73
74 /* add a toolbar for icons */ 74 /* add a toolbar for icons */
75 m_icons = new QToolBar(this); 75 m_icons = new QToolBar(this);
76 76
77 /* 77 /*
78 * the settings action 78 * the settings action
79 */ 79 */
80 m_setProfiles = new QAction(tr("Configure Profiles"), 80 m_setProfiles = new QAction(tr("Configure Profiles"),
81 Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ), 81 Opie::Core::OResource::loadPixmap( "SettingsIcon", Opie::Core::OResource::SmallIcon ),
82 QString::null, 0, this, 0); 82 QString::null, 0, this, 0);
83 m_setProfiles->addTo( m_console ); 83 m_setProfiles->addTo( m_console );
84 connect( m_setProfiles, SIGNAL(activated() ), 84 connect( m_setProfiles, SIGNAL(activated() ),
85 this, SLOT(slotConfigure() ) ); 85 this, SLOT(slotConfigure() ) );
86 86
87 m_console->insertSeparator(); 87 m_console->insertSeparator();
88 /* 88 /*
89 * new Action for new sessions 89 * new Action for new sessions
90 */ 90 */
91 QAction* newCon = new QAction(tr("New Profile"), 91 QAction* newCon = new QAction(tr("New Profile"),
92 Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ), 92 Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ),
93 QString::null, 0, this, 0); 93 QString::null, 0, this, 0);
94 newCon->addTo( m_console ); 94 newCon->addTo( m_console );
95 connect( newCon, SIGNAL(activated() ), 95 connect( newCon, SIGNAL(activated() ),
96 this, SLOT(slotNew() ) ); 96 this, SLOT(slotNew() ) );
97 97
98 m_console->insertSeparator(); 98 m_console->insertSeparator();
99 99
100 QAction *saveCon = new QAction( tr("Save Profile" ), 100 QAction *saveCon = new QAction( tr("Save Profile" ),
101 Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), QString::null, 101 Opie::Core::OResource::loadPixmap( "save", Opie::Core::OResource::SmallIcon ), QString::null,
102 0, this, 0 ); 102 0, this, 0 );
103 saveCon->addTo( m_console ); 103 saveCon->addTo( m_console );
104 connect( saveCon, SIGNAL(activated() ), 104 connect( saveCon, SIGNAL(activated() ),
105 this, SLOT(slotSaveSession() ) ); 105 this, SLOT(slotSaveSession() ) );
106 m_console->insertSeparator(); 106 m_console->insertSeparator();
107 107
108 /* 108 /*
109 * connect action 109 * connect action
110 */ 110 */
111 m_connect = new QAction( tr("Connect"), Opie::Core::OResource::loadPixmap("console/connected", 111 m_connect = new QAction( tr("Connect"), Opie::Core::OResource::loadPixmap("console/connected",
112 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); 112 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
113 m_connect->addTo( m_console ); 113 m_connect->addTo( m_console );
114 connect(m_connect, SIGNAL(activated() ), 114 connect(m_connect, SIGNAL(activated() ),
115 this, SLOT(slotConnect() ) ); 115 this, SLOT(slotConnect() ) );
116 116
117 /* 117 /*
118 * disconnect action 118 * disconnect action
119 */ 119 */
120 m_disconnect = new QAction( tr("Disconnect"), Opie::Core::OResource::loadPixmap("console/notconnected", 120 m_disconnect = new QAction( tr("Disconnect"), Opie::Core::OResource::loadPixmap("console/notconnected",
121 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); 121 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
122 m_disconnect->addTo( m_console ); 122 m_disconnect->addTo( m_console );
123 connect(m_disconnect, SIGNAL(activated() ), 123 connect(m_disconnect, SIGNAL(activated() ),
124 this, SLOT(slotDisconnect() ) ); 124 this, SLOT(slotDisconnect() ) );
125 125
126 m_console->insertSeparator(); 126 m_console->insertSeparator();
127 127
128#ifndef EAST 128#ifndef EAST
129 m_quickLaunch = new QAction( tr("QuickLaunch"), 129 m_quickLaunch = new QAction( tr("QuickLaunch"),
130 Opie::Core::OResource::loadPixmap("console/konsole_mini", Opie::Core::OResource::SmallIcon ), 130 Opie::Core::OResource::loadPixmap("console/konsole_mini", Opie::Core::OResource::SmallIcon ),
131 QString::null, 0, this, 0 ); 131 QString::null, 0, this, 0 );
132 m_quickLaunch->addTo( m_icons ); 132 m_quickLaunch->addTo( m_icons );
133 connect( m_quickLaunch, SIGNAL( activated() ), 133 connect( m_quickLaunch, SIGNAL( activated() ),
134 this, SLOT( slotQuickLaunch() ) ); 134 this, SLOT( slotQuickLaunch() ) );
135#endif 135#endif
136 136
137 QWhatsThis::add( m_icons, tr( "The shell button launches the \"default\" profile. If there is none default values are taken" ) ); 137 QWhatsThis::add( m_icons, tr( "The shell button launches the \"default\" profile. If there is none default values are taken" ) );
138 138
139 m_transfer = new QAction( tr("Transfer file..."), Opie::Core::OResource::loadPixmap("pass", Opie::Core::OResource::SmallIcon ), 139 m_transfer = new QAction( tr("Transfer file..."), Opie::Core::OResource::loadPixmap("pass", Opie::Core::OResource::SmallIcon ),
140 QString::null, 0, this, 0 ); 140 QString::null, 0, this, 0 );
141 m_transfer->addTo( m_console ); 141 m_transfer->addTo( m_console );
142 connect(m_transfer, SIGNAL(activated() ), 142 connect(m_transfer, SIGNAL(activated() ),
143 this, SLOT(slotTransfer() ) ); 143 this, SLOT(slotTransfer() ) );
144 144
145 145
146 146
147 /* 147 /*
148 * immediate change of line wrap policy 148 * immediate change of line wrap policy
149 */ 149 */
150 m_isWrapped = true; 150 m_isWrapped = true;
151 m_wrap = new QAction( tr("Line wrap"), Opie::Core::OResource::loadPixmap( "linewrap", Opie::Core::OResource::SmallIcon ), 151 m_wrap = new QAction( tr("Line wrap"), Opie::Core::OResource::loadPixmap( "linewrap", Opie::Core::OResource::SmallIcon ),
152 QString::null, 0, this, 0, true ); 152 QString::null, 0, this, 0, true );
153 m_wrap->addTo( m_console ); 153 m_wrap->addTo( m_console );
154 m_wrap->setOn( true ); 154 m_wrap->setOn( true );
155 connect( m_wrap, SIGNAL( activated() ), SLOT( slotWrap() ) ); 155 connect( m_wrap, SIGNAL( activated() ), SLOT( slotWrap() ) );
156 156
157 /* 157 /*
158 * fullscreen 158 * fullscreen
159 */ 159 */
160 m_isFullscreen = false; 160 m_isFullscreen = false;
161 161
162 m_fullscreen = new QAction( tr("Full screen"), Opie::Core::OResource::loadPixmap( "fullscreen", 162 m_fullscreen = new QAction( tr("Full screen"), Opie::Core::OResource::loadPixmap( "fullscreen",
163 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 ); 163 Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
164 m_fullscreen->addTo( m_console ); 164 m_fullscreen->addTo( m_console );
165 connect( m_fullscreen, SIGNAL( activated() ), 165 connect( m_fullscreen, SIGNAL( activated() ),
166 this, SLOT( slotFullscreen() ) ); 166 this, SLOT( slotFullscreen() ) );
167 167
168 /* 168 /*
169 * scrollbar 169 * scrollbar
170 */ 170 */
171 sm_none = m_scrollbar->insertItem(tr( "None" )); 171 sm_none = m_scrollbar->insertItem(tr( "None" ));
172 sm_left = m_scrollbar->insertItem(tr( "Left" )); 172 sm_left = m_scrollbar->insertItem(tr( "Left" ));
173 sm_right = m_scrollbar->insertItem(tr( "Right" )); 173 sm_right = m_scrollbar->insertItem(tr( "Right" ));
174 174
175 m_console->insertItem(tr("Scrollbar"), m_scrollbar, -1, 0); 175 m_console->insertItem(tr("Scrollbar"), m_scrollbar, -1, 0);
176 connect( m_scrollbar, SIGNAL(activated(int)), 176 connect( m_scrollbar, SIGNAL(activated(int)),
177 this, SLOT(slotScrollbarSelected(int))); 177 this, SLOT(slotScrollbarSelected(int)));
178 178
179 m_console->insertSeparator(); 179 m_console->insertSeparator();
180 180
181 m_recordLog = new QAction(); 181 m_recordLog = new QAction();
182 m_recordLog->setText( tr("Start log") ); 182 m_recordLog->setText( tr("Start log") );
183 m_recordLog->addTo( m_console ); 183 m_recordLog->addTo( m_console );
184 connect(m_recordLog, SIGNAL(activated() ), 184 connect(m_recordLog, SIGNAL(activated() ),
185 this, SLOT( slotSaveLog() ) ); 185 this, SLOT( slotSaveLog() ) );
186 m_recordingLog = false; 186 m_recordingLog = false;
187 187
188 QAction *a = new QAction(); 188 QAction *a = new QAction();
189 a->setText( tr("Save history") ); 189 a->setText( tr("Save history") );
190 a->addTo( m_console ); 190 a->addTo( m_console );
191 connect(a, SIGNAL(activated() ), 191 connect(a, SIGNAL(activated() ),
192 this, SLOT(slotSaveHistory() ) ); 192 this, SLOT(slotSaveHistory() ) );
193 /* 193 /*
194 * terminate action 194 * terminate action
195 */ 195 */
196 m_terminate = new QAction(); 196 m_terminate = new QAction();
197 m_terminate->setText( tr("Terminate") ); 197 m_terminate->setText( tr("Terminate") );
198 m_terminate->addTo( m_console ); 198 m_terminate->addTo( m_console );
199 connect(m_terminate, SIGNAL(activated() ), 199 connect(m_terminate, SIGNAL(activated() ),
200 this, SLOT(slotTerminate() ) ); 200 this, SLOT(slotTerminate() ) );
201 201
202 m_closewindow = new QAction(); 202 m_closewindow = new QAction();
203 m_closewindow->setText( tr("Close Window") ); 203 m_closewindow->setText( tr("Close Window") );
204 m_closewindow->addTo( m_console ); 204 m_closewindow->addTo( m_console );
205 connect( m_closewindow, SIGNAL(activated() ), 205 connect( m_closewindow, SIGNAL(activated() ),
206 this, SLOT(slotClose() ) ); 206 this, SLOT(slotClose() ) );
207 207
208 208
209 /* 209 /*
210 * script actions 210 * script actions
211 */ 211 */
212 m_runScript_id = m_scripts->insertItem(tr("Run Script"), m_scriptsPop, -1, 0); 212 m_runScript_id = m_scripts->insertItem(tr("Run Script"), m_scriptsPop, -1, 0);
213 connect(m_scriptsPop, SIGNAL(activated(int)), this, SLOT(slotRunScript(int))); 213 connect(m_scriptsPop, SIGNAL(activated(int)), this, SLOT(slotRunScript(int)));
214 214
215 m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0); 215 m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0);
216 m_recordScript->addTo(m_scripts); 216 m_recordScript->addTo(m_scripts);
217 connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript())); 217 connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript()));
218 218
219 m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0); 219 m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0);
220 m_saveScript->addTo(m_scripts); 220 m_saveScript->addTo(m_scripts);
221 connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript())); 221 connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript()));
222 222
223 223
224 224
225 225
226 /* 226 /*
227 * action that open/closes the keyboard 227 * action that open/closes the keyboard
228 */ 228 */
229 m_openKeys = new QAction (tr("Open Keyboard..."), 229 m_openKeys = new QAction (tr("Open Keyboard..."),
230 Opie::Core::OResource::loadPixmap( "console/keys/keyboard_icon", Opie::Core::OResource::SmallIcon ), 230 Opie::Core::OResource::loadPixmap( "console/keys/keyboard_icon", Opie::Core::OResource::SmallIcon ),
231 QString::null, 0, this, 0); 231 QString::null, 0, this, 0);
232 m_openKeys->setToggleAction(true); 232 m_openKeys->setToggleAction(true);
233 connect (m_openKeys, SIGNAL(toggled(bool)), this, SLOT(slotOpenKeb(bool))); 233 connect (m_openKeys, SIGNAL(toggled(bool)), this, SLOT(slotOpenKeb(bool)));
234 234
235 /* insert the submenu */ 235 /* insert the submenu */
236 m_console->insertItem(tr("New from Profile"), m_sessionsPop, 236 m_console->insertItem(tr("New from Profile"), m_sessionsPop,
237 -1, 0); 237 -1, 0);
238 238
239 /* insert the connection menu */ 239 /* insert the connection menu */
240 m_bar->insertItem( tr("Connection"), m_console ); 240 m_bar->insertItem( tr("Connection"), m_console );
241 241
242 /* the scripts menu */ 242 /* the scripts menu */
243#ifdef EAST 243#ifdef EAST
244 Opie::Core::OConfig cfg("opie-console"); 244 Opie::Core::OConfig cfg("opie-console");
245 cfg.setGroup("10east"); 245 cfg.setGroup("10east");
246 if( !cfg.readEntry("scripthide",0) ) { 246 if( !cfg.readEntry("scripthide",0) ) {
247 m_bar->insertItem( tr("Scripts"), m_scripts ); 247 m_bar->insertItem( tr("Scripts"), m_scripts );
248 } 248 }
249#endif 249#endif
250 250
251 /* and the keyboard */ 251 /* and the keyboard */
252 m_keyBar = new QToolBar(this); 252 m_keyBar = new QToolBar(this);
253 addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE ); 253 addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE );
254 m_keyBar->setHorizontalStretchable( TRUE ); 254 m_keyBar->setHorizontalStretchable( TRUE );
255 m_keyBar->hide(); 255 m_keyBar->hide();
256 256
257 m_kb = new FunctionKeyboard(m_keyBar); 257 m_kb = new FunctionKeyboard(m_keyBar);
258 connect(m_kb, SIGNAL(keyPressed(FKey,ushort,ushort,bool)), 258 connect(m_kb, SIGNAL(keyPressed(FKey,ushort,ushort,bool)),
259 this, SLOT(slotKeyReceived(FKey,ushort,ushort,bool))); 259 this, SLOT(slotKeyReceived(FKey,ushort,ushort,bool)));
260 260
261 261
262 a = new QAction(tr("Copy"), 262 a = new QAction(tr("Copy"),
263 Opie::Core::OResource::loadPixmap("copy", Opie::Core::OResource::SmallIcon ), QString::null, 263 Opie::Core::OResource::loadPixmap("copy", Opie::Core::OResource::SmallIcon ), QString::null,
264 0, this, 0 ); 264 0, this, 0 );
265 //a->addTo( m_icons ); 265 //a->addTo( m_icons );
266 connect( a, SIGNAL(activated() ), 266 connect( a, SIGNAL(activated() ),
267 this, SLOT(slotCopy() ) ); 267 this, SLOT(slotCopy() ) );
268 268
269 QAction *paste = new QAction(tr("Paste"), 269 QAction *paste = new QAction(tr("Paste"),
270 Opie::Core::OResource::loadPixmap("paste", Opie::Core::OResource::SmallIcon ), QString::null, 270 Opie::Core::OResource::loadPixmap("paste", Opie::Core::OResource::SmallIcon ), QString::null,
271 0, this, 0 ); 271 0, this, 0 );
272 connect( paste, SIGNAL(activated() ), 272 connect( paste, SIGNAL(activated() ),
273 this, SLOT(slotPaste() ) ); 273 this, SLOT(slotPaste() ) );
274 274
275 275
276 newCon->addTo( m_icons ); 276 newCon->addTo( m_icons );
277 //m_setProfiles->addTo( m_icons ); 277 //m_setProfiles->addTo( m_icons );
278 paste->addTo( m_icons ); 278 paste->addTo( m_icons );
279 m_openKeys->addTo(m_icons); 279 m_openKeys->addTo(m_icons);
280 m_fullscreen->addTo( m_icons ); 280 m_fullscreen->addTo( m_icons );
281 281
282 m_connect->setEnabled( false ); 282 m_connect->setEnabled( false );
283 m_disconnect->setEnabled( false ); 283 m_disconnect->setEnabled( false );
284 m_terminate->setEnabled( false ); 284 m_terminate->setEnabled( false );
285 m_transfer->setEnabled( false ); 285 m_transfer->setEnabled( false );
286 m_scripts->setItemEnabled(m_runScript_id, false); 286 m_scripts->setItemEnabled(m_runScript_id, false);
287 m_recordScript->setEnabled( false ); 287 m_recordScript->setEnabled( false );
288 m_saveScript->setEnabled( false ); 288 m_saveScript->setEnabled( false );
289 m_fullscreen->setEnabled( false ); 289 m_fullscreen->setEnabled( false );
290 m_closewindow->setEnabled( false ); 290 m_closewindow->setEnabled( false );
291 m_wrap->setEnabled( false ); 291 m_wrap->setEnabled( false );
292 292
293 /* 293 /*
294 * connect to the menu activation 294 * connect to the menu activation
295 */ 295 */
296 connect( m_sessionsPop, SIGNAL(activated(int) ), 296 connect( m_sessionsPop, SIGNAL(activated(int) ),
297 this, SLOT(slotProfile(int) ) ); 297 this, SLOT(slotProfile(int) ) );
298 298
299 m_consoleWindow = new TabWidget( this, "blah"); 299 m_consoleWindow = new TabWidget( this, "blah");
300 connect(m_consoleWindow, SIGNAL(activated(Session*) ), 300 connect(m_consoleWindow, SIGNAL(activated(Session*) ),
301 this, SLOT(slotSessionChanged(Session*) ) ); 301 this, SLOT(slotSessionChanged(Session*) ) );
302 setCentralWidget( m_consoleWindow ); 302 setCentralWidget( m_consoleWindow );
303 303
304 slotQuickLaunch(); 304 slotQuickLaunch();
305} 305}
306 306
307ProfileManager* MainWindow::manager() { 307ProfileManager* MainWindow::manager() {
308 return m_manager; 308 return m_manager;
309} 309}
310TabWidget* MainWindow::tabWidget() { 310TabWidget* MainWindow::tabWidget() {
311 return m_consoleWindow; 311 return m_consoleWindow;
312} 312}
313void MainWindow::populateProfiles() { 313void MainWindow::populateProfiles() {
314 m_sessionsPop->clear(); 314 m_sessionsPop->clear();
315 Profile::ValueList list = manager()->all(); 315 Profile::ValueList list = manager()->all();
316 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { 316 for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) {
317 m_sessionsPop->insertItem( (*it).name() ); 317 m_sessionsPop->insertItem( (*it).name() );
318 } 318 }
319 319
320} 320}
321 321
322void MainWindow::populateScripts() { 322void MainWindow::populateScripts() {
323 m_scriptsPop->clear(); 323 m_scriptsPop->clear();
324 m_scriptsData.clear(); 324 m_scriptsData.clear();
325 DocLnkSet files(QPEApplication::documentDir(), "text/plain"); 325 DocLnkSet files(QPEApplication::documentDir(), "text/plain");
326 QListIterator<DocLnk> dit(files.children()); 326 QListIterator<DocLnk> dit(files.children());
327 for (; dit.current(); ++dit) { 327 for (; dit.current(); ++dit) {
328 if (*dit && (*dit)->name().length()>0) { 328 if (*dit && (*dit)->name().length()>0) {
329 QFileInfo info((*dit)->file()); 329 QFileInfo info((*dit)->file());
330 if (info.extension(false) == "script") { 330 if (info.extension(false) == "script") {
331 m_scriptsData.append(new DocLnk(**dit)); 331 m_scriptsData.append(new DocLnk(**dit));
332 m_scriptsPop->insertItem((*dit)->name()); 332 m_scriptsPop->insertItem((*dit)->name());
333 } 333 }
334 } 334 }
335 } 335 }
336 336
337} 337}
338 338
339MainWindow::~MainWindow() { 339MainWindow::~MainWindow() {
340 delete m_factory; 340 delete m_factory;
341 manager()->save(); 341 manager()->save();
342#ifdef FSCKED_DISTRI 342#ifdef FSCKED_DISTRI
343 FixIt fix; 343 FixIt fix;
344 fix.breakIt(); 344 fix.breakIt();
345#endif 345#endif
346} 346}
347 347
348MetaFactory* MainWindow::factory() { 348MetaFactory* MainWindow::factory() {
349 return m_factory; 349 return m_factory;
350} 350}
351 351
352Session* MainWindow::currentSession() { 352Session* MainWindow::currentSession() {
353 return m_curSession; 353 return m_curSession;
354} 354}
355 355
356QList<Session> MainWindow::sessions() { 356QList<Session> MainWindow::sessions() {
357 return m_sessions; 357 return m_sessions;
358} 358}
359 359
360void MainWindow::slotNew() { 360void MainWindow::slotNew() {
361 ProfileEditorDialog dlg(factory() ); 361 ProfileEditorDialog dlg(factory() );
362 dlg.setCaption( tr("New Connection") ); 362 dlg.setCaption( tr("New Connection") );
363 int ret = QPEApplication::execDialog( &dlg ); 363 int ret = QPEApplication::execDialog( &dlg );
364 364
365 if ( ret == QDialog::Accepted ) { 365 if ( ret == QDialog::Accepted ) {
366 create( dlg.profile() ); 366 create( dlg.profile() );
367 } 367 }
368} 368}
369 369
370void MainWindow::slotRecordScript() { 370void MainWindow::slotRecordScript() {
371 if (currentSession()) { 371 if (currentSession()) {
372 currentSession()->emulationHandler()->startRecording(); 372 currentSession()->emulationHandler()->startRecording();
373 m_saveScript->setEnabled(true); 373 m_saveScript->setEnabled(true);
374 m_recordScript->setEnabled(false); 374 m_recordScript->setEnabled(false);
375 } 375 }
376} 376}
377 377
378void MainWindow::slotSaveScript() { 378void MainWindow::slotSaveScript() {
379 if (currentSession() && currentSession()->emulationHandler()->isRecording()) { 379 if (currentSession() && currentSession()->emulationHandler()->isRecording()) {
380 QMap<QString, QStringList> map; 380 QMap<QString, QStringList> map;
381 QStringList text; 381 QStringList text;
382 text << "text/plain"; 382 text << "text/plain";
383 map.insert(tr("Script"), text ); 383 map.insert(tr("Script"), text );
384 QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map); 384 QString filename = OFileDialog::getSaveFileName(2, QPEApplication::documentDir(), QString::null, map);
385 if (!filename.isEmpty()) { 385 if (!filename.isEmpty()) {
386 QFileInfo info(filename); 386 QFileInfo info(filename);
387 if (info.extension(FALSE) != "script") 387 if (info.extension(FALSE) != "script")
388 filename += ".script"; 388 filename += ".script";
389 DocLnk nf; 389 DocLnk nf;
390 nf.setType("text/plain"); 390 nf.setType("text/plain");
391 nf.setFile(filename); 391 nf.setFile(filename);
392 nf.setName(info.fileName()); 392 nf.setName(info.fileName());
393 FileManager fm; 393 FileManager fm;
394 fm.saveFile(nf, currentSession()->emulationHandler()->script()->script()); 394 fm.saveFile(nf, currentSession()->emulationHandler()->script()->script());
395 currentSession()->emulationHandler()->clearScript(); 395 currentSession()->emulationHandler()->clearScript();
396 m_saveScript->setEnabled(false); 396 m_saveScript->setEnabled(false);
397 m_recordScript->setEnabled(true); 397 m_recordScript->setEnabled(true);
398 populateScripts(); 398 populateScripts();
399 } 399 }
400 } 400 }
401} 401}
402 402
403void MainWindow::slotRunScript(int id) { 403void MainWindow::slotRunScript(int id) {
404 if (currentSession()) { 404 if (currentSession()) {
405 int index = m_scriptsPop->indexOf(id); 405 int index = m_scriptsPop->indexOf(id);
406 DocLnk *lnk = m_scriptsData.at(index); 406 DocLnk *lnk = m_scriptsData.at(index);
407 QString filePath = lnk->file(); 407 QString filePath = lnk->file();
408 Script script(filePath); 408 Script script(filePath);
409 currentSession()->emulationHandler()->runScript(&script); 409 currentSession()->emulationHandler()->runScript(&script);
410 } 410 }
411} 411}
412 412
413void MainWindow::slotConnect() { 413void MainWindow::slotConnect() {
414 if ( currentSession() ) { 414 if ( currentSession() ) {
415 bool ret = currentSession()->layer()->open(); 415 bool ret = currentSession()->layer()->open();
416 if(!ret) QMessageBox::warning(currentSession()->widgetStack(), 416 if(!ret) QMessageBox::warning(currentSession()->widgetStack(),
417 QObject::tr("Failed"), 417 QObject::tr("Failed"),
418 QObject::tr("Connecting failed for this session.")); 418 QObject::tr("Connecting failed for this session."));
419 else { 419 else {
420 m_connect->setEnabled( false ); 420 m_connect->setEnabled( false );
421 m_disconnect->setEnabled( true ); 421 m_disconnect->setEnabled( true );
422 422
423 // if it does not support file transfer, disable the menu entry 423 // if it does not support file transfer, disable the menu entry
424 if ( ( m_curSession->layer() )->supports()[1] == 0 ) { 424 if ( ( m_curSession->layer() )->supports()[1] == 0 ) {
425 m_transfer->setEnabled( false ); 425 m_transfer->setEnabled( false );
426 } else { 426 } else {
427 m_transfer->setEnabled( true ); 427 m_transfer->setEnabled( true );
428 } 428 }
429 429
430 m_recordScript->setEnabled( true ); 430 m_recordScript->setEnabled( true );
431 m_scripts->setItemEnabled(m_runScript_id, true); 431 m_scripts->setItemEnabled(m_runScript_id, true);
432 } 432 }
433 } 433 }
434} 434}
435 435
436void MainWindow::slotDisconnect() { 436void MainWindow::slotDisconnect() {
437 if ( currentSession() ) { 437 if ( currentSession() ) {
438 currentSession()->layer()->close(); 438 currentSession()->layer()->close();
439 m_connect->setEnabled( true ); 439 m_connect->setEnabled( true );
440 m_disconnect->setEnabled( false ); 440 m_disconnect->setEnabled( false );
441 m_transfer->setEnabled( false ); 441 m_transfer->setEnabled( false );
442 m_recordScript->setEnabled( false); 442 m_recordScript->setEnabled( false);
443 m_saveScript->setEnabled( false ); 443 m_saveScript->setEnabled( false );
444 m_scripts->setItemEnabled(m_runScript_id, false); 444 m_scripts->setItemEnabled(m_runScript_id, false);
445 } 445 }
446} 446}
447 447
448void MainWindow::slotTerminate() { 448void MainWindow::slotTerminate() {
449 if ( currentSession() ) 449 if ( currentSession() )
450 currentSession()->layer()->close(); 450 currentSession()->layer()->close();
451 451
452 slotClose(); 452 slotClose();
453 /* FIXME move to the next session */ 453 /* FIXME move to the next session */
454} 454}
455 455
456 456
457 457
458void MainWindow::slotQuickLaunch() { 458void MainWindow::slotQuickLaunch() {
459 459
460 Profile prof = manager()->profile( "default" ); 460 Profile prof = manager()->profile( "default" );
461 if ( prof.name() == "default" ) { 461 if ( prof.name() == "default" ) {
462 create( prof ); 462 create( prof );
463 } else { 463 } else {
464 #ifndef EAST 464 #ifndef EAST
465 Profile newProf = Profile( "default", "console", "default" , 0, 3, 0 ); 465 Profile newProf = Profile( "default", "console", "default" , 0, 3, 0 );
466 newProf.setAutoConnect( true ); 466 newProf.setAutoConnect( true );
467 create( newProf ); 467 create( newProf );
468 slotSaveSession(); 468 slotSaveSession();
469 #endif 469 #endif
470 } 470 }
471} 471}
472 472
473void MainWindow::slotConfigure() { 473void MainWindow::slotConfigure() {
474 ConfigDialog conf( manager()->all(), factory() ); 474 ConfigDialog conf( manager()->all(), factory() );
475 475
476 int ret = QPEApplication::execDialog( &conf ); 476 int ret = QPEApplication::execDialog( &conf );
477 477
478 if ( QDialog::Accepted == ret ) { 478 if ( QDialog::Accepted == ret ) {
479 manager()->setProfiles( conf.list() ); 479 manager()->setProfiles( conf.list() );
480 manager()->save(); 480 manager()->save();
481 populateProfiles(); 481 populateProfiles();
482 } 482 }
483} 483}
484/* 484/*
485 * we will remove 485 * we will remove
486 * this window from the tabwidget 486 * this window from the tabwidget
487 * remove it from the list 487 * remove it from the list
488 * delete it 488 * delete it
489 * and set the currentSession() 489 * and set the currentSession()
490 */ 490 */
491void MainWindow::slotClose() { 491void MainWindow::slotClose() {
492 if (!currentSession() ) 492 if (!currentSession() )
493 return; 493 return;
494 494
495 Session* ses = currentSession(); 495 Session* ses = currentSession();
496 /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */ 496 /* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */
497 m_curSession = NULL; 497 m_curSession = NULL;
498 tabWidget()->remove( /*currentSession()*/ses ); 498 tabWidget()->remove( /*currentSession()*/ses );
499 /*it's autodelete */ 499 /*it's autodelete */
500 m_sessions.remove( ses ); 500 m_sessions.remove( ses );
501 501
502 if (!currentSession() ) { 502 if (!currentSession() ) {
503 m_connect->setEnabled( false ); 503 m_connect->setEnabled( false );
504 m_disconnect->setEnabled( false ); 504 m_disconnect->setEnabled( false );
505 m_terminate->setEnabled( false ); 505 m_terminate->setEnabled( false );
506 m_transfer->setEnabled( false ); 506 m_transfer->setEnabled( false );
507 m_recordScript->setEnabled( false ); 507 m_recordScript->setEnabled( false );
508 m_saveScript->setEnabled( false ); 508 m_saveScript->setEnabled( false );
509 m_scripts->setItemEnabled(m_runScript_id, false); 509 m_scripts->setItemEnabled(m_runScript_id, false);
510 m_fullscreen->setEnabled( false ); 510 m_fullscreen->setEnabled( false );
511 m_wrap->setEnabled( false ); 511 m_wrap->setEnabled( false );
512 m_closewindow->setEnabled( false ); 512 m_closewindow->setEnabled( false );
513 } 513 }
514 514
515 m_kb->loadDefaults(); 515 m_kb->loadDefaults();
516} 516}
517 517
518/* 518/*
519 * We will get the name 519 * We will get the name
520 * Then the profile 520 * Then the profile
521 * and then we will make a profile 521 * and then we will make a profile
522 */ 522 */
523void MainWindow::slotProfile( int id) { 523void MainWindow::slotProfile( int id) {
524 Profile prof = manager()->profile( m_sessionsPop->text( id) ); 524 Profile prof = manager()->profile( m_sessionsPop->text( id) );
525 create( prof ); 525 create( prof );
526} 526}
527 527
528 528
529 529
530void MainWindow::create( const Profile& prof ) { 530void MainWindow::create( const Profile& prof ) {
531 char *homeDir = getenv("HOME"); 531 char *homeDir = getenv("HOME");
532 532
533 if ( homeDir ) 533 if ( homeDir )
534 ::chdir( homeDir ); 534 ::chdir( homeDir );
535 535
536 if(m_curSession) 536 if(m_curSession)
537 if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide(); 537 if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide();
538 538
539 Session *ses = manager()->fromProfile( prof, tabWidget() ); 539 Session *ses = manager()->fromProfile( prof, tabWidget() );
540 540
541 if((!ses) || (!ses->layer()) || (!ses->widgetStack())) 541 if((!ses) || (!ses->layer()) || (!ses->widgetStack()))
542 { 542 {
543 QMessageBox::warning(this, 543 QMessageBox::warning(this,
544 QObject::tr("Session failed"), 544 QObject::tr("Session failed"),
545 QObject::tr("<qt>Cannot open session: Not all components were found.</qt>")); 545 QObject::tr("<qt>Cannot open session: Not all components were found.</qt>"));
546 //if(ses) delete ses; 546 //if(ses) delete ses;
547 return; 547 return;
548 } 548 }
549 549
550 m_sessions.append( ses ); 550 m_sessions.append( ses );
551 tabWidget()->add( ses ); 551 tabWidget()->add( ses );
552 tabWidget()->repaint(); 552 tabWidget()->repaint();
553 m_curSession = ses; 553 m_curSession = ses;
554 554
555 // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it 555 // dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it
556 m_connect->setEnabled( true ); 556 m_connect->setEnabled( true );
557 m_disconnect->setEnabled( false ); 557 m_disconnect->setEnabled( false );
558 m_terminate->setEnabled( true ); 558 m_terminate->setEnabled( true );
559 m_fullscreen->setEnabled( true ); 559 m_fullscreen->setEnabled( true );
560 m_wrap->setEnabled( true ); 560 m_wrap->setEnabled( true );
561 m_closewindow->setEnabled( true ); 561 m_closewindow->setEnabled( true );
562 m_transfer->setEnabled( false ); 562 m_transfer->setEnabled( false );
563 m_recordScript->setEnabled( false ); 563 m_recordScript->setEnabled( false );
564 m_saveScript->setEnabled( false ); 564 m_saveScript->setEnabled( false );
565 m_scripts->setItemEnabled(m_runScript_id, false); 565 m_scripts->setItemEnabled(m_runScript_id, false);
566 566
567 // is io_layer wants direct connection, then autoconnect 567 // is io_layer wants direct connection, then autoconnect
568 //if ( ( m_curSession->layer() )->supports()[0] == 1 ) { 568 //if ( ( m_curSession->layer() )->supports()[0] == 1 ) {
569 if (prof.autoConnect()) { 569 if (prof.autoConnect()) {
570 slotConnect(); 570 slotConnect();
571 } 571 }
572 572
573 QWidget *w = currentSession()->widget(); 573 QWidget *w = currentSession()->widget();
574 if(w) w->setFocus(); 574 if(w) w->setFocus();
575 575
576 if(currentSession()->profile().readNumEntry("Wrap", 80)){ 576 if(currentSession()->profile().readNumEntry("Wrap", 80)){
577 m_isWrapped = true; 577 m_isWrapped = true;
578 } else { 578 } else {
579 m_isWrapped = false; 579 m_isWrapped = false;
580 } 580 }
581 581
582 m_kb->load(currentSession()->profile()); 582 m_kb->load(currentSession()->profile());
583} 583}
584 584
585void MainWindow::slotTransfer() 585void MainWindow::slotTransfer()
586{ 586{
587 if ( currentSession() ) { 587 if ( currentSession() ) {
588 Session *mysession = currentSession(); 588 Session *mysession = currentSession();
589 TransferDialog dlg(/*mysession->widgetStack()*/this, this); 589 TransferDialog dlg(/*mysession->widgetStack()*/this, this);
590 mysession->setTransferDialog(&dlg); 590 mysession->setTransferDialog(&dlg);
591 //dlg.reparent(mysession->widgetStack(), QPoint(0, 0)); 591 //dlg.reparent(mysession->widgetStack(), QPoint(0, 0));
592 //dlg.showMaximized(); 592 //dlg.showMaximized();
593 currentSession()->widgetStack()->addWidget(&dlg, -1); 593 currentSession()->widgetStack()->addWidget(&dlg, -1);
594 dlg.show(); 594 dlg.show();
595 //dlg.exec(); 595 //dlg.exec();
596 while(dlg.isRunning()) qApp->processEvents(); 596 while(dlg.isRunning()) qApp->processEvents();
597 mysession->setTransferDialog(0l); 597 mysession->setTransferDialog(0l);
598 } 598 }
599} 599}
600 600
601 601
602void MainWindow::slotOpenKeb(bool state) { 602void MainWindow::slotOpenKeb(bool state) {
603 603
604 if (state) m_keyBar->show(); 604 if (state) m_keyBar->show();
605 else m_keyBar->hide(); 605 else m_keyBar->hide();
606 606
607} 607}
608 608
609 609
610void MainWindow::slotOpenButtons( bool state ) { 610void MainWindow::slotOpenButtons( bool state ) {
611 611
612 if ( state ) { 612 if ( state ) {
613 m_buttonBar->show(); 613 m_buttonBar->show();
614 } else { 614 } else {
615 m_buttonBar->hide(); 615 m_buttonBar->hide();
616 } 616 }
617} 617}
618 618
619 619
620 620
621void MainWindow::slotSessionChanged( Session* ses ) { 621void MainWindow::slotSessionChanged( Session* ses ) {
622 if(m_curSession) 622 if(m_curSession)
623 if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide(); 623 if(m_curSession->transferDialog()) m_curSession->transferDialog()->hide();
624 if(ses) 624 if(ses)
625 if(ses->transferDialog()) ses->transferDialog()->show(); 625 if(ses->transferDialog()) ses->transferDialog()->show();
626 626
627 if ( ses ) { 627 if ( ses ) {
628 m_curSession = ses; 628 m_curSession = ses;
629 if ( m_curSession->layer()->isConnected() ) { 629 if ( m_curSession->layer()->isConnected() ) {
630 m_connect->setEnabled( false ); 630 m_connect->setEnabled( false );
631 m_disconnect->setEnabled( true ); 631 m_disconnect->setEnabled( true );
632 m_recordScript->setEnabled(!m_curSession->emulationHandler()->isRecording()); 632 m_recordScript->setEnabled(!m_curSession->emulationHandler()->isRecording());
633 m_saveScript->setEnabled(m_curSession->emulationHandler()->isRecording()); 633 m_saveScript->setEnabled(m_curSession->emulationHandler()->isRecording());
634 m_scripts->setItemEnabled(m_runScript_id, true); 634 m_scripts->setItemEnabled(m_runScript_id, true);
635 } else { 635 } else {
636 m_connect->setEnabled( true ); 636 m_connect->setEnabled( true );
637 m_disconnect->setEnabled( false ); 637 m_disconnect->setEnabled( false );
638 m_recordScript->setEnabled( false ); 638 m_recordScript->setEnabled( false );
639 m_saveScript->setEnabled( false ); 639 m_saveScript->setEnabled( false );
640 m_scripts->setItemEnabled(m_runScript_id, false); 640 m_scripts->setItemEnabled(m_runScript_id, false);
641 } 641 }
642 642
643 if ( ( currentSession()->emulationHandler()->isLogging() ) ) { 643 if ( ( currentSession()->emulationHandler()->isLogging() ) ) {
644 m_recordLog->setText( tr("Stop log") ); 644 m_recordLog->setText( tr("Stop log") );
645 } else { 645 } else {
646 m_recordLog->setText( tr("Start log") ); 646 m_recordLog->setText( tr("Start log") );
647 } 647 }
648 648
649 if ( ( m_curSession->layer() )->supports()[1] == 0 ) { 649 if ( ( m_curSession->layer() )->supports()[1] == 0 ) {
650 m_transfer->setEnabled( false ); 650 m_transfer->setEnabled( false );
651 } else { 651 } else {
652 m_transfer->setEnabled( true ); 652 m_transfer->setEnabled( true );
653 } 653 }
654 654
655 QWidget *w = m_curSession->widget(); 655 QWidget *w = m_curSession->widget();
656 if(w) w->setFocus(); 656 if(w) w->setFocus();
657 657
658 if(currentSession()->profile().readNumEntry("Wrap", 80)){ 658 if(currentSession()->profile().readNumEntry("Wrap", 80)){
659 m_isWrapped = true; 659 m_isWrapped = true;
660 } else { 660 } else {
661 m_isWrapped = false; 661 m_isWrapped = false;
662 } 662 }
663 663
664 m_kb->load(currentSession()->profile()); 664 m_kb->load(currentSession()->profile());
665 } 665 }
666} 666}
667 667
668void MainWindow::slotWrap() 668void MainWindow::slotWrap()
669{ 669{
670 if(m_curSession) 670 if(m_curSession)
671 { 671 {
672 EmulationHandler *e = m_curSession->emulationHandler(); 672 EmulationHandler *e = m_curSession->emulationHandler();
673 if(e) 673 if(e)
674 { 674 {
675 e->setWrap( m_isWrapped ? 80:0 ); 675 e->setWrap( m_isWrapped ? 80:0 );
676 m_isWrapped = !m_isWrapped; 676 m_isWrapped = !m_isWrapped;
677 } 677 }
678 } 678 }
679} 679}
680 680
681void MainWindow::slotFullscreen() { 681void MainWindow::slotFullscreen() {
682 682
683 683
684 684
685 if ( m_isFullscreen ) { 685 if ( m_isFullscreen ) {
686 ( m_curSession->widgetStack() )->reparent( savedParentFullscreen, 0, QPoint(0,0), true ); 686 ( m_curSession->widgetStack() )->reparent( savedParentFullscreen, 0, QPoint(0,0), true );
687 ( m_curSession->widgetStack() )->resize( savedParentFullscreen->width(), savedParentFullscreen->height() ); 687 ( m_curSession->widgetStack() )->resize( savedParentFullscreen->width(), savedParentFullscreen->height() );
688 ( m_curSession->emulationHandler() )->cornerButton()->hide(); 688 ( m_curSession->emulationHandler() )->cornerButton()->hide();
689 disconnect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) ); 689 disconnect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
690 690
691 } else { 691 } else {
692 savedParentFullscreen = ( m_curSession->widgetStack() )->parentWidget(); 692 savedParentFullscreen = ( m_curSession->widgetStack() )->parentWidget();
693 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame ); 693 ( m_curSession->widgetStack() )->setFrameStyle( QFrame::NoFrame );
694 ( m_curSession->widgetStack() )->reparent( 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop 694 ( m_curSession->widgetStack() )->reparent( 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop
695 , QPoint(0,0), false ); 695 , QPoint(0,0), false );
696 ( m_curSession->widgetStack() )->resize( qApp->desktop()->width(), qApp->desktop()->height() ); 696 ( m_curSession->widgetStack() )->resize( qApp->desktop()->width(), qApp->desktop()->height() );
697 ( m_curSession->widgetStack() )->setFocus(); 697 ( m_curSession->widgetStack() )->setFocus();
698 ( m_curSession->widgetStack() )->show(); 698 ( m_curSession->widgetStack() )->show();
699 699
700 ( ( m_curSession->emulationHandler() )->cornerButton() )->show(); 700 ( ( m_curSession->emulationHandler() )->cornerButton() )->show();
701 701
702 connect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) ); 702 connect( ( m_curSession->emulationHandler() )->cornerButton(), SIGNAL( pressed() ), this, SLOT( slotFullscreen() ) );
703 } 703 }
704 704
705 m_isFullscreen = !m_isFullscreen; 705 m_isFullscreen = !m_isFullscreen;
706} 706}
707 707
708void MainWindow::slotScrollbarSelected(int index) 708void MainWindow::slotScrollbarSelected(int index)
709{ 709{
710 int loc; 710 int loc;
711 711
712 Config cfg( "Konsole" ); 712 Config cfg( "Konsole" );
713 cfg.setGroup("ScrollBar"); 713 cfg.setGroup("ScrollBar");
714 if(index == sm_none) 714 if(index == sm_none)
715 { 715 {
716 loc = 0; 716 loc = 0;
717 } 717 }
718 else if(index == sm_left) 718 else if(index == sm_left)
719 { 719 {
720 loc = 1; 720 loc = 1;
721 } 721 }
722 else if(index == sm_right) 722 else if(index == sm_right)
723 { 723 {
724 loc = 2; 724 loc = 2;
725 } 725 }
726 726
727 cfg.writeEntry("Position", loc); 727 cfg.writeEntry("Position", loc);
728 728
729 if (currentSession()) { 729 if (currentSession()) {
730 currentSession()->emulationHandler()->setScrollbarLocation(loc); 730 currentSession()->emulationHandler()->setScrollbarLocation(loc);
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
@@ -1,2009 +1,2003 @@
1/*************************************************************************** 1/***************************************************************************
2 gutenbrowser.cpp - description 2 gutenbrowser.cpp - description
3 ------------------- 3 -------------------
4 begin : Mon Jul 24 22:33:12 MDT 2000 4 begin : Mon Jul 24 22:33:12 MDT 2000
5 copyright : (C) 2000 -2004 by llornkcor 5 copyright : (C) 2000 -2004 by llornkcor
6 email : ljp@llornkcor.com 6 email : ljp@llornkcor.com
7 * This program is free software; you can redistribute it and/or modify * 7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by * 8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or * 9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. * 10 * (at your option) any later version. *
11 ***************************************************************************/ 11 ***************************************************************************/
12// http search 12// http search
13// http://digital.library.upenn.edu/books/authors.html 13// http://digital.library.upenn.edu/books/authors.html
14// http://digital.library.upenn.edu/books/titles.html 14// http://digital.library.upenn.edu/books/titles.html
15// ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL 15// ftp://ibiblio.org/pub/docs/books/gutenberg/GUTINDEX.ALL
16// donate@gutenberg.net 16// donate@gutenberg.net
17 17
18 18
19#include "editTitle.h" 19#include "editTitle.h"
20#include "gutenbrowser.h" 20#include "gutenbrowser.h"
21#include "LibraryDialog.h" 21#include "LibraryDialog.h"
22 //#include "bookmarksdlg.h" 22 //#include "bookmarksdlg.h"
23#include "optionsDialog.h" 23#include "optionsDialog.h"
24#include "helpme.h" 24#include "helpme.h"
25#include "NetworkDialog.h" 25#include "NetworkDialog.h"
26 26
27#include "openetext.h" 27#include "openetext.h"
28#include "output.h" 28#include "output.h"
29 29
30/* OPIE */ 30/* OPIE */
31#include <opie2/odebug.h> 31#include <opie2/odebug.h>
32#include <opie2/oresource.h> 32#include <opie2/oresource.h>
33 33
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/fontdatabase.h> 35#include <qpe/fontdatabase.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <qpe/qcopenvelope_qws.h> 37#include <qpe/qcopenvelope_qws.h>
38#include <qpe/mimetype.h> 38#include <qpe/mimetype.h>
39#include <qpe/applnk.h> 39#include <qpe/applnk.h>
40 40
41/* QT */ 41/* QT */
42#include <qregexp.h> 42#include <qregexp.h>
43#include <qregion.h> 43#include <qregion.h>
44#include <qpaintdevicemetrics.h> 44#include <qpaintdevicemetrics.h>
45#include <qvaluelist.h> 45#include <qvaluelist.h>
46#include <qlabel.h> 46#include <qlabel.h>
47#include <qclipboard.h> 47#include <qclipboard.h>
48#include <qpainter.h> 48#include <qpainter.h>
49#include <qpalette.h> 49#include <qpalette.h>
50#include <qobjectlist.h> 50#include <qobjectlist.h>
51#include <qfontdialog.h> 51#include <qfontdialog.h>
52#include <qtextview.h> 52#include <qtextview.h>
53#include <qbrush.h> 53#include <qbrush.h>
54#include <qfile.h> 54#include <qfile.h>
55#include <qfontinfo.h> 55#include <qfontinfo.h>
56#include <qscrollview.h> 56#include <qscrollview.h>
57#include <qpoint.h> 57#include <qpoint.h>
58 58
59/* STD */ 59/* STD */
60#include <stdio.h> 60#include <stdio.h>
61#include <stdlib.h> 61#include <stdlib.h>
62#include <unistd.h> 62#include <unistd.h>
63#include <sys/stat.h> 63#include <sys/stat.h>
64#include <fcntl.h> 64#include <fcntl.h>
65#include <errno.h> 65#include <errno.h>
66 66
67static const int nfontsizes = 9; 67static const int nfontsizes = 9;
68static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24}; 68static const int fontsize[nfontsizes] = {8,9,10,11,12,13,14,18,24};
69 69
70#ifdef NOQUICKLAUNCH 70#ifdef NOQUICKLAUNCH
71Gutenbrowser::Gutenbrowser() 71Gutenbrowser::Gutenbrowser()
72 Gutenbrowser(); 72 Gutenbrowser();
73#else 73#else
74Gutenbrowser::Gutenbrowser(QWidget *,const char*, WFlags ) 74Gutenbrowser::Gutenbrowser(QWidget *,const char*, WFlags )
75#endif 75#endif
76 : QMainWindow() 76 : QMainWindow()
77{ 77{
78 // QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 78 // QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
79 // QCopEnvelope e("QPE/System", "grabKeyboard(QString)" ); 79 // QCopEnvelope e("QPE/System", "grabKeyboard(QString)" );
80 // e << ""; 80 // e << "";
81 // QPEApplication::grabKeyboard(); 81 // QPEApplication::grabKeyboard();
82 showMainList=TRUE; 82 showMainList=TRUE;
83 working=false; 83 working=false;
84 this->setUpdatesEnabled(TRUE); 84 this->setUpdatesEnabled(TRUE);
85 // #ifndef Q_WS_QWS 85 // #ifndef Q_WS_QWS
86 QString msg; 86 QString msg;
87 msg="You have now entered unto gutenbrowser,\n"; 87 msg="You have now entered unto gutenbrowser,\n";
88 msg+="make your self at home, sit back, relax and read something great.\n"; 88 msg+="make your self at home, sit back, relax and read something great.\n";
89 89
90 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; 90 local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/";
91 setCaption("Gutenbrowser");// Embedded " VERSION); 91 setCaption("Gutenbrowser");// Embedded " VERSION);
92 this->setUpdatesEnabled(TRUE); 92 this->setUpdatesEnabled(TRUE);
93 93
94 // bool firstTime=FALSE; 94 // bool firstTime=FALSE;
95 topLayout = new QVBoxLayout( this, 0, 0, "topLayout"); 95 topLayout = new QVBoxLayout( this, 0, 0, "topLayout");
96 96
97 menu = new QHBoxLayout(-1,"menu"); 97 menu = new QHBoxLayout(-1,"menu");
98 buttons2 = new QHBoxLayout(-1,"buttons2"); 98 buttons2 = new QHBoxLayout(-1,"buttons2");
99 edits = new QHBoxLayout(-1,"edits"); 99 edits = new QHBoxLayout(-1,"edits");
100 100
101 useSplitter=TRUE; 101 useSplitter=TRUE;
102 102
103 initConfig(); 103 initConfig();
104 initMenuBar(); 104 initMenuBar();
105 initButtonBar(); 105 initButtonBar();
106 initStatusBar(); 106 initStatusBar();
107 initView(); 107 initView();
108 initSlots(); 108 initSlots();
109 qDebug("init finished"); 109 qDebug("init finished");
110 QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold); 110 QPEApplication::setStylusOperation( mainList->viewport(),QPEApplication::RightOnHold);
111 111
112 connect( mainList, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint &)), 112 connect( mainList, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint &)),
113 this, SLOT( mainListPressed(int, QListBoxItem *, const QPoint &)) ); 113 this, SLOT( mainListPressed(int, QListBoxItem *, const QPoint &)) );
114 if( useIcons) 114 if( useIcons)
115 toggleButtonIcons( TRUE); 115 toggleButtonIcons( TRUE);
116 else 116 else
117 toggleButtonIcons( FALSE); 117 toggleButtonIcons( FALSE);
118 118
119 enableButtons(false); 119 enableButtons(false);
120 120
121 Config config("Gutenbrowser"); // populate menubuttonlist 121 Config config("Gutenbrowser"); // populate menubuttonlist
122 config.setGroup("General"); 122 config.setGroup("General");
123 123
124 config.setGroup( "Files" ); 124 config.setGroup( "Files" );
125 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); 125 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
126 int i_numofFiles = s_numofFiles.toInt(); 126 int i_numofFiles = s_numofFiles.toInt();
127 127
128 QString tempFileName; 128 QString tempFileName;
129 129
130 for (int i = 0; i <= i_numofFiles; i++) { 130 for (int i = 0; i <= i_numofFiles; i++) {
131 // tempFileName.setNum(i); 131 // tempFileName.setNum(i);
132 config.setGroup( "Files" ); 132 config.setGroup( "Files" );
133 QString ramble = config.readEntry( QString::number(i), "" ); 133 QString ramble = config.readEntry( QString::number(i), "" );
134 134
135 config.setGroup( "Titles" ); 135 config.setGroup( "Titles" );
136 QString tempTitle = config.readEntry( ramble, ""); 136 QString tempTitle = config.readEntry( ramble, "");
137 config.setGroup( tempTitle); 137 config.setGroup( tempTitle);
138 int index = config.readNumEntry( "LineNumber", -1 ); 138 int index = config.readNumEntry( "LineNumber", -1 );
139 if( index != -1) { 139 if( index != -1) {
140 odebug << tempTitle << oendl; 140 odebug << tempTitle << oendl;
141 if(!tempTitle.isEmpty()) bookmarksMenu->insertItem( tempTitle); 141 if(!tempTitle.isEmpty()) bookmarksMenu->insertItem( tempTitle);
142 } 142 }
143 } 143 }
144 144
145 QString gutenIndex = local_library + "/GUTINDEX.ALL"; 145 QString gutenIndex = local_library + "/GUTINDEX.ALL";
146 qDebug("gutenindex "+gutenIndex ); 146 qDebug("gutenindex "+gutenIndex );
147 147
148 if( QFile( gutenIndex).exists() ) { 148 if( QFile( gutenIndex).exists() ) {
149 indexLib.setName( gutenIndex); 149 indexLib.setName( gutenIndex);
150 } else { 150 } else {
151 QString localLibIndexFile = local_library + "/PGWHOLE.TXT"; 151 QString localLibIndexFile = local_library + "/PGWHOLE.TXT";
152 // QString localLibIndexFile= local_library + "PGWHOLE.TXT"; 152 // QString localLibIndexFile= local_library + "PGWHOLE.TXT";
153 newindexLib.setName( localLibIndexFile); 153 newindexLib.setName( localLibIndexFile);
154 } 154 }
155 qDebug("attempting new library"); 155 qDebug("attempting new library");
156 LibraryDlg = new LibraryDialog( this, "Library Index" /*, TRUE */); 156 LibraryDlg = new LibraryDialog( this, "Library Index" /*, TRUE */);
157 loadCheck = false; 157 loadCheck = false;
158 chdir(local_library); 158 chdir(local_library);
159 if(!showMainList) { 159 if(!showMainList) {
160 Lview->setFocus(); 160 Lview->setFocus();
161 // if(firstTime) 161 // if(firstTime)
162 // Bookmark(); 162 // Bookmark();
163 for (int i=1;i< qApp->argc();i++) { 163 for (int i=1;i< qApp->argc();i++) {
164 qDebug("Suppose we open somethin"); 164 qDebug("Suppose we open somethin");
165 if(!load(qApp->argv()[i])) return; 165 if(!load(qApp->argv()[i])) return;
166 } 166 }
167 } else { 167 } else {
168 fillWithTitles(); 168 fillWithTitles();
169 mainList->setFocus(); 169 mainList->setFocus();
170 // mainList->setCurrentItem(0); 170 // mainList->setCurrentItem(0);
171 171
172 } 172 }
173 writeConfig(); 173 writeConfig();
174 QTimer::singleShot( 250, this, SLOT(hideView()) ); 174 QTimer::singleShot( 250, this, SLOT(hideView()) );
175} //end init 175} //end init
176 176
177Gutenbrowser::~Gutenbrowser() { 177Gutenbrowser::~Gutenbrowser() {
178 // QPEApplication::grabKeyboard(); 178 // QPEApplication::grabKeyboard();
179 // QPEApplication::ungrabKeyboard(); 179 // QPEApplication::ungrabKeyboard();
180 odebug << "Exit" << oendl; 180 odebug << "Exit" << oendl;
181} 181}
182 182
183 /* 183 /*
184 Google.com search */ 184 Google.com search */
185void Gutenbrowser::InfoBarClick() { 185void Gutenbrowser::InfoBarClick() {
186 QString text; 186 QString text;
187 if( Lview->hasSelectedText()) { 187 if( Lview->hasSelectedText()) {
188 Lview->copy(); 188 Lview->copy();
189 QClipboard *cb = QApplication::clipboard(); 189 QClipboard *cb = QApplication::clipboard();
190 text = cb->text(); 190 text = cb->text();
191 } else { 191 } else {
192 // text=title; 192 // text=title;
193 text=this->caption(); 193 text=this->caption();
194 } 194 }
195 searchGoogle(text); 195 searchGoogle(text);
196} 196}
197 197
198 /* 198 /*
199 download http with wget or preferred browser */ 199 download http with wget or preferred browser */
200void Gutenbrowser::goGetit( const QString &url, bool showMsg) { 200void Gutenbrowser::goGetit( const QString &url, bool showMsg) {
201 QString cmd; 201 QString cmd;
202 qApp->processEvents(); 202 qApp->processEvents();
203 203
204 QString filename = local_library + "/GUTINDEX.ALL"; 204 QString filename = local_library + "/GUTINDEX.ALL";
205// QString filename = old_index; 205// QString filename = old_index;
206 206
207 // filename += url.right( url.length() - url.findRev("/",-1,TRUE) -1); 207 // filename += url.right( url.length() - url.findRev("/",-1,TRUE) -1);
208 208
209 Config cfg("Gutenbrowser"); 209 Config cfg("Gutenbrowser");
210 cfg.setGroup("FTPsite"); 210 cfg.setGroup("FTPsite");
211 ftp_host=cfg.readEntry("SiteName", "sailor.gutenberg.org"); 211 ftp_host=cfg.readEntry("SiteName", "sailor.gutenberg.org");
212 ftp_base_dir= cfg.readEntry("base", "/pub/gutenberg"); 212 ftp_base_dir= cfg.readEntry("base", "/pub/gutenberg");
213 213
214 // Config config("Gutenbrowser"); 214 // Config config("Gutenbrowser");
215 // config.setGroup( "Browser" ); 215 // config.setGroup( "Browser" );
216 // QString brow = config.readEntry("Preferred", "Opera"); 216 // QString brow = config.readEntry("Preferred", "Opera");
217 // //odebug << "Preferred browser is "+brow << oendl; 217 // //odebug << "Preferred browser is "+brow << oendl;
218 if(!showMsg) { //if we just get the gutenindex.all 218 if(!showMsg) { //if we just get the gutenindex.all
219// QString cmd="wget -O " + gutenindex1 + " http://sailor.gutenberg.org/GUTINDEX.ALL 2>&1"; 219// QString cmd="wget -O " + gutenindex1 + " http://sailor.gutenberg.org/GUTINDEX.ALL 2>&1";
220 cmd="wget -O " + filename +" " + url+" 2>&1" ; 220 cmd="wget -O " + filename +" " + url+" 2>&1" ;
221 chdir(local_library); 221 chdir(local_library);
222 // //odebug << "Issuing the system command: " << cmd << "" << oendl; 222 // //odebug << "Issuing the system command: " << cmd << "" << oendl;
223 223
224 Output *outDlg; 224 Output *outDlg;
225 225
226 outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),TRUE); 226 outDlg = new Output( 0, tr("Downloading Gutenberg Index...."),TRUE);
227 227
228 outDlg->showMaximized(); 228 outDlg->showMaximized();
229 outDlg->show(); 229 outDlg->show();
230 qApp->processEvents(); 230 qApp->processEvents();
231 FILE *fp; 231 FILE *fp;
232 char line[130]; 232 char line[130];
233 outDlg->OutputEdit->append( tr("Running wget") ); 233 outDlg->OutputEdit->append( tr("Running wget") );
234 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 234 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
235 sleep(1); 235 sleep(1);
236 fp = popen( (const char *) cmd, "r"); 236 fp = popen( (const char *) cmd, "r");
237 if ( !fp ) { 237 if ( !fp ) {
238 } else { 238 } else {
239 //odebug << "Issuing the command\n"+cmd << oendl; 239 //odebug << "Issuing the command\n"+cmd << oendl;
240 // system(cmd); 240 // system(cmd);
241 while ( fgets( line, sizeof line, fp)) { 241 while ( fgets( line, sizeof line, fp)) {
242 outDlg->OutputEdit->append(line); 242 outDlg->OutputEdit->append(line);
243 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 243 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
244 } 244 }
245 pclose(fp); 245 pclose(fp);
246 outDlg->OutputEdit->append("Finished downloading\n"); 246 outDlg->OutputEdit->append("Finished downloading\n");
247 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); 247 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
248 qApp->processEvents(); 248 qApp->processEvents();
249 249
250 } 250 }
251 outDlg->close(); 251 outDlg->close();
252 252
253 if(outDlg) 253 if(outDlg)
254 delete outDlg; 254 delete outDlg;
255 } else { 255 } else {
256 if( brow == "Konq") { 256 if( brow == "Konq") {
257 cmd = "konqueror "+url+" &"; 257 cmd = "konqueror "+url+" &";
258 } 258 }
259 if( brow == "Opera") { //for desktop testing 259 if( brow == "Opera") { //for desktop testing
260 cmd = "opera "+url+" &"; 260 cmd = "opera "+url+" &";
261 } 261 }
262 // if( brow == "Opera") { // on Zaurus 262 // if( brow == "Opera") { // on Zaurus
263 // cmd = "operagui "+url+" &"; 263 // cmd = "operagui "+url+" &";
264 // } 264 // }
265 if( brow == "Mozilla") { 265 if( brow == "Mozilla") {
266 cmd = "mozilla "+url+" &"; 266 cmd = "mozilla "+url+" &";
267 } 267 }
268 if( brow == "Netscape") { 268 if( brow == "Netscape") {
269 cmd = "netscape "+url+" &"; 269 cmd = "netscape "+url+" &";
270 } 270 }
271 if(brow == "wget") { 271 if(brow == "wget") {
272 // cmd="wget -q "+url+" &"; 272 // cmd="wget -q "+url+" &";
273 QString tempHtml=local_library+"webster.html"; 273 QString tempHtml=local_library+"webster.html";
274 cmd="wget -O "+tempHtml+" -q "+url; 274 cmd="wget -O "+tempHtml+" -q "+url;
275 } 275 }
276 276
277 chdir(local_library); 277 chdir(local_library);
278 // //odebug << "Issuing the sys command: " << cmd << "" << oendl; 278 // //odebug << "Issuing the sys command: " << cmd << "" << oendl;
279 system(cmd); 279 system(cmd);
280 } 280 }
281} 281}
282 282
283void Gutenbrowser::toggleButtonIcons( bool useEm) { 283void Gutenbrowser::toggleButtonIcons( bool useEm) {
284 QString pixDir; 284 QString pixDir;
285 if(useEm) 285 if(useEm)
286 useEm=TRUE; 286 useEm=TRUE;
287 pixDir=QPEApplication::qpeDir()+"pics/gutenbrowser"; 287 pixDir=QPEApplication::qpeDir()+"pics/gutenbrowser";
288 odebug << "Docdir is "+QPEApplication::documentDir() << oendl; 288 odebug << "Docdir is "+QPEApplication::documentDir() << oendl;
289 289
290 if( useIcons && QDir( pixDir).exists() ) { 290 if( useIcons && QDir( pixDir).exists() ) {
291 LibraryButton->setPixmap( Opie::Core::OResource::loadPixmap("home", Opie::Core::OResource::SmallIcon ) ); 291 LibraryButton->setPixmap( Opie::Core::OResource::loadPixmap("home", Opie::Core::OResource::SmallIcon ) );
292 OpenButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/openbook", Opie::Core::OResource::SmallIcon )); 292 OpenButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/openbook", Opie::Core::OResource::SmallIcon ));
293 ForwardButton->setPixmap( Opie::Core::OResource::loadPixmap("forward", Opie::Core::OResource::SmallIcon )); 293 ForwardButton->setPixmap( Opie::Core::OResource::loadPixmap("forward", Opie::Core::OResource::SmallIcon ));
294 BackButton->setPixmap( Opie::Core::OResource::loadPixmap("back", Opie::Core::OResource::SmallIcon ) ); 294 BackButton->setPixmap( Opie::Core::OResource::loadPixmap("back", Opie::Core::OResource::SmallIcon ) );
295 SearchButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/search", Opie::Core::OResource::SmallIcon ) ); 295 SearchButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/search", Opie::Core::OResource::SmallIcon ) );
296 lastBmkButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/bookmark_folder", Opie::Core::OResource::SmallIcon )); 296 lastBmkButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/bookmark_folder", Opie::Core::OResource::SmallIcon ));
297 setBookmarkButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/bookmark", Opie::Core::OResource::SmallIcon ) ); 297 setBookmarkButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/bookmark", Opie::Core::OResource::SmallIcon ) );
298 dictionaryButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/spellcheck", Opie::Core::OResource::SmallIcon ) ); 298 dictionaryButton->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/spellcheck", Opie::Core::OResource::SmallIcon ) );
299 InfoBar->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/google", Opie::Core::OResource::SmallIcon )); 299 InfoBar->setPixmap( Opie::Core::OResource::loadPixmap("gutenbrowser/google", Opie::Core::OResource::SmallIcon ));
300 } 300 }
301} 301}
302 302
303 303
304bool Gutenbrowser::queryExit() 304bool Gutenbrowser::queryExit()
305{ 305{
306 int exit=QMessageBox::information(this, "Quit...", "Do your really want to quit?", 306 int exit=QMessageBox::information(this, "Quit...", "Do your really want to quit?",
307 QMessageBox::Ok, QMessageBox::Cancel); 307 QMessageBox::Ok, QMessageBox::Cancel);
308 if (exit==1) { 308 if (exit==1) {
309 writeConfig(); 309 writeConfig();
310 qApp->quit(); 310 qApp->quit();
311 } else { 311 } else {
312 }; 312 };
313 return (exit==1); 313 return (exit==1);
314} 314}
315 315
316 // SLOT IMPLEMENTATION 316 // SLOT IMPLEMENTATION
317 317
318void Gutenbrowser::slotFilePrint() { 318void Gutenbrowser::slotFilePrint() {
319} 319}
320 320
321void Gutenbrowser::ByeBye() { 321void Gutenbrowser::ByeBye() {
322 if (b_queryExit) 322 if (b_queryExit)
323 queryExit(); 323 queryExit();
324 else { 324 else {
325 // writeConfig(); 325 // writeConfig();
326 qApp->quit(); 326 qApp->quit();
327 } 327 }
328} 328}
329 329
330void Gutenbrowser::HelpBtn() { 330void Gutenbrowser::HelpBtn() {
331 HelpMe* HelpDlg; 331 HelpMe* HelpDlg;
332 HelpDlg = new HelpMe( this, "Help Dialog"); 332 HelpDlg = new HelpMe( this, "Help Dialog");
333 HelpDlg->showMaximized(); 333 HelpDlg->showMaximized();
334} 334}
335 335
336void Gutenbrowser::DownloadIndex() { 336void Gutenbrowser::DownloadIndex() {
337#ifndef Q_WS_QWS 337#ifndef Q_WS_QWS
338 { 338 {
339 switch( QMessageBox::information( 0, (tr("Download Library Index, or FTP sites?")), 339 switch( QMessageBox::information( 0, (tr("Download Library Index, or FTP sites?")),
340 (tr("Do you want to download the newest\n" 340 (tr("Do you want to download the newest\n"
341 "Project Gutenberg Library Index?\n" 341 "Project Gutenberg Library Index?\n"
342 "or select an ftp site?\n")), 342 "or select an ftp site?\n")),
343 (tr("&Library Index")), (tr("&Ftp Site")), (tr("&Cancel")), 2, 2 ) ) 343 (tr("&Library Index")), (tr("&Ftp Site")), (tr("&Cancel")), 2, 2 ) )
344 { 344 {
345 case 0: // index clicked, 345 case 0: // index clicked,
346 downloadLibIndex(); 346 downloadLibIndex();
347 break; 347 break;
348 348
349 case 1: // ftp selected 349 case 1: // ftp selected
350 downloadFtpList(); 350 downloadFtpList();
351 break; 351 break;
352 352
353 case 2: // Cancel 353 case 2: // Cancel
354 break; 354 break;
355 }; 355 };
356 } 356 }
357#endif 357#endif
358} // end DownloadIndex 358} // end DownloadIndex
359 359
360 360
361void Gutenbrowser::downloadFtpList() { 361void Gutenbrowser::downloadFtpList() {
362 // QString cmd="wget http://www.promo.net/pg/list.html"); 362 // QString cmd="wget http://www.promo.net/pg/list.html");
363 //system(cmd); 363 //system(cmd);
364 qApp->processEvents(); 364 qApp->processEvents();
365 optionsDialog* optDlg; 365 optionsDialog* optDlg;
366 optDlg = new optionsDialog( this,"Options_Dlg", true); 366 optDlg = new optionsDialog( this,"Options_Dlg", true);
367 optDlg->getSite(); 367 optDlg->getSite();
368 if(optDlg) 368 if(optDlg)
369 delete optDlg; 369 delete optDlg;
370} 370}
371 371
372 372
373void Gutenbrowser::downloadLibIndex() { 373void Gutenbrowser::downloadLibIndex() {
374 // QString dwmloader = local_library + "pgwhole.zip"; 374 // QString dwmloader = local_library + "pgwhole.zip";
375 // QString cmd = "lynx -source http://www.gutenberg.net/pgwhole.zip | cat >> " + dwmloader; 375 // QString cmd = "lynx -source http://www.gutenberg.net/pgwhole.zip | cat >> " + dwmloader;
376 // system(cmd); 376 // system(cmd);
377 377
378 // QString outputFile= local_library+ "GUTINDEX.ALL"; 378 // QString outputFile= local_library+ "GUTINDEX.ALL";
379 // config.setGroup( "FTPsite" ); // ftp server config 379 // config.setGroup( "FTPsite" ); // ftp server config
380 // ftp_host=config.readEntry("SiteName", ""); 380 // ftp_host=config.readEntry("SiteName", "");
381 // ftp_base_dir= config.readEntry("base", ""); 381 // ftp_base_dir= config.readEntry("base", "");
382 // QString networkUrl= "ftp://"+ftp_host+ftp_base_dir+"/GUTINDEX.ALL"; 382 // QString networkUrl= "ftp://"+ftp_host+ftp_base_dir+"/GUTINDEX.ALL";
383 QDir dir( local_library); 383 QDir dir( local_library);
384 dir.cd("", TRUE); 384 dir.cd("", TRUE);
385 goGetit( "http://www.gutenberg.org/dirs/GUTINDEX.ALL", false); // until ghttp works on binaries -qt3 385 goGetit( "http://www.gutenberg.org/dirs/GUTINDEX.ALL", false); // until ghttp works on binaries -qt3
386 // goGetit( "http://www.gutenberg.net/pgwhole.zip", true); // until ghttp works on binaries -qt3 386 // goGetit( "http://www.gutenberg.net/pgwhole.zip", true); // until ghttp works on binaries -qt3
387 // NetworkDialog *NetworkDlg; 387 // NetworkDialog *NetworkDlg;
388 // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, outputFile ); 388 // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, outputFile );
389 // if( NetworkDlg->exec() != 0 ) 389 // if( NetworkDlg->exec() != 0 )
390 // { // use new, improved, *INSTANT* network-dialog-file-getterer 390 // { // use new, improved, *INSTANT* network-dialog-file-getterer
391 //// QMessageBox::message("Note",""); 391 //// QMessageBox::message("Note","");
392 // } 392 // }
393 // if(NetworkDlg) 393 // if(NetworkDlg)
394 // delete NetworkDlg; 394 // delete NetworkDlg;
395} 395}
396 396
397 397
398void Gutenbrowser::PrintBtn() { 398void Gutenbrowser::PrintBtn() {
399} 399}
400 400
401void Gutenbrowser::SearchBtn() { 401void Gutenbrowser::SearchBtn() {
402 if( loadCheck) { 402 if( loadCheck) {
403 odebug << "loadCheck: we have a loaded doc" << oendl; 403 odebug << "loadCheck: we have a loaded doc" << oendl;
404 Search(); 404 Search();
405 } 405 }
406 // else 406 // else
407 // QMessageBox::message("Note","Sorry, can't search. No etext is loaded"); 407 // QMessageBox::message("Note","Sorry, can't search. No etext is loaded");
408} 408}
409 409
410 410
411void Gutenbrowser::ForwardBtn() { 411void Gutenbrowser::ForwardBtn() {
412 412
413 if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) { 413 if( !ForwardButton->autoRepeat() && !ForwardButton->isDown()) {
414 414
415 QString s; 415 QString s;
416 QString insertString; 416 QString insertString;
417 int pageSize= Lview->PageSize(); 417 int pageSize= Lview->PageSize();
418 Lview->clear(); 418 Lview->clear();
419 419
420 for(int fd=0; fd < pageSize - 1;fd++) { 420 for(int fd=0; fd < pageSize - 1;fd++) {
421 f.readLine(s, 256); 421 f.readLine(s, 256);
422 if(useWrap) 422 if(useWrap)
423 s.replace(QRegExp("\n"),""); 423 s.replace(QRegExp("\n"),"");
424 insertString+=s; 424 insertString+=s;
425 Lview->insertLine( s, -1); 425 Lview->insertLine( s, -1);
426 // odebug << s << oendl; 426 // odebug << s << oendl;
427 currentLine++; 427 currentLine++;
428 } 428 }
429 // Lview->insertAt( insertString,0,0, FALSE); 429 // Lview->insertAt( insertString,0,0, FALSE);
430 currentFilePos = f.at(); 430 currentFilePos = f.at();
431 // if( i_pageNum != pages) { 431 // if( i_pageNum != pages) {
432 // Lview->MultiLine_Ex::pageDown( FALSE); 432 // Lview->MultiLine_Ex::pageDown( FALSE);
433 i_pageNum++; 433 i_pageNum++;
434 pageStopArray.resize(i_pageNum + 1); 434 pageStopArray.resize(i_pageNum + 1);
435 // int length = Lview->length(); 435 // int length = Lview->length();
436 436
437 pageStopArray[i_pageNum ] = currentFilePos; 437 pageStopArray[i_pageNum ] = currentFilePos;
438 odebug << currentFilePos << " current page is number " << i_pageNum 438 odebug << currentFilePos << " current page is number " << i_pageNum
439 << ", pagesize " << pageSize << ", length " << Lview->length() 439 << ", pagesize " << pageSize << ", length " << Lview->length()
440 << ", current " << pageStopArray[i_pageNum] << oendl; 440 << ", current " << pageStopArray[i_pageNum] << oendl;
441 setStatus(); 441 setStatus();
442// Lview->setCursorPosition( 0, 0, FALSE); 442// Lview->setCursorPosition( 0, 0, FALSE);
443 // } 443 // }
444 444
445 } else { 445 } else {
446 odebug << "bal" << oendl; 446 odebug << "bal" << oendl;
447 // if( i_pageNum != pages) { 447 // if( i_pageNum != pages) {
448 448
449 // // int newTop = Lview->Top(); 449 // // int newTop = Lview->Top();
450 // // if(Lview->lastRow() > i) 450 // // if(Lview->lastRow() > i)
451 // Lview->ScrollUp(1); 451 // Lview->ScrollUp(1);
452 // // i_pageNum++; 452 // // i_pageNum++;
453 // setStatus(); 453 // setStatus();
454 // Lview->setCursorPosition( Lview->Top(), 0, FALSE); 454 // Lview->setCursorPosition( Lview->Top(), 0, FALSE);
455 455
456 // } 456 // }
457 457
458 } 458 }
459 Lview->setFocus(); 459 Lview->setFocus();
460 460
461 odebug << "page number " << i_pageNum << " line number " << currentLine << "" << oendl; 461 odebug << "page number " << i_pageNum << " line number " << currentLine << "" << oendl;
462} 462}
463 463
464 464
465void Gutenbrowser::BackBtn() { 465void Gutenbrowser::BackBtn() {
466 if( i_pageNum > 0) { 466 if( i_pageNum > 0) {
467 int pageSize= Lview->PageSize(); 467 int pageSize= Lview->PageSize();
468 // int length=Lview->length(); 468 // int length=Lview->length();
469 469
470 i_pageNum--; 470 i_pageNum--;
471 currentFilePos = f.at(); 471 currentFilePos = f.at();
472 472
473 odebug << currentFilePos << " move back to " << pageStopArray[i_pageNum - 1 ] 473 odebug << currentFilePos << " move back to " << pageStopArray[i_pageNum - 1 ]
474 << ", current page number " << i_pageNum 474 << ", current page number " << i_pageNum
475 << ", " << pageSize << ", length " << Lview->length() << oendl; 475 << ", " << pageSize << ", length " << Lview->length() << oendl;
476 476
477 if( i_pageNum < 2) { 477 if( i_pageNum < 2) {
478 f.at( 0); 478 f.at( 0);
479 } else { 479 } else {
480 if(!f.at( pageStopArray[i_pageNum - 1] )) 480 if(!f.at( pageStopArray[i_pageNum - 1] ))
481 odebug << "File positioned backward did not work" << oendl; 481 odebug << "File positioned backward did not work" << oendl;
482 } 482 }
483 QString s; 483 QString s;
484 // int sizeLine=0; 484 // int sizeLine=0;
485 Lview->clear(); 485 Lview->clear();
486 // QString insertString; 486 // QString insertString;
487 487
488 for(int fd = 0; fd < pageSize ;fd++) { 488 for(int fd = 0; fd < pageSize ;fd++) {
489 // Lview->removeLine( Lview->PageSize() ); 489 // Lview->removeLine( Lview->PageSize() );
490 f.readLine(s, 256); 490 f.readLine(s, 256);
491 if(useWrap) 491 if(useWrap)
492 s.replace(QRegExp("\n"),""); 492 s.replace(QRegExp("\n"),"");
493 currentLine++; 493 currentLine++;
494 // insertString+=s; 494 // insertString+=s;
495 Lview->insertLine( s, -1); 495 Lview->insertLine( s, -1);
496 } 496 }
497 497
498 // Lview->insertAt( insertString,0,0, FALSE); 498 // Lview->insertAt( insertString,0,0, FALSE);
499 499
500 if( !BackButton->autoRepeat() && !BackButton->isDown()) { 500 if( !BackButton->autoRepeat() && !BackButton->isDown()) {
501 QString topR; 501 QString topR;
502 QString lastR; 502 QString lastR;
503 QString pageR; 503 QString pageR;
504 // int sizer = Lview->lastRow() - Lview->topRow(); 504 // int sizer = Lview->lastRow() - Lview->topRow();
505 // int i_topRow = Lview->topRow(); 505 // int i_topRow = Lview->topRow();
506 if( i_pageNum < 1) 506 if( i_pageNum < 1)
507 i_pageNum = 1; 507 i_pageNum = 1;
508 setCaption(QString::number(i_pageNum)); 508 setCaption(QString::number(i_pageNum));
509 } else { 509 } else {
510 // int newTop = Lview->Top(); 510 // int newTop = Lview->Top();
511 // if(Lview->lastRow() > i) 511 // if(Lview->lastRow() > i)
512 Lview->MultiLine_Ex::pageUp( FALSE); 512 Lview->MultiLine_Ex::pageUp( FALSE);
513 // Lview->ScrollDown(1); 513 // Lview->ScrollDown(1);
514 // i_pageNum--; 514 // i_pageNum--;
515 if( i_pageNum < 1) 515 if( i_pageNum < 1)
516 i_pageNum = 1; 516 i_pageNum = 1;
517 setStatus(); 517 setStatus();
518// Lview->setCursorPosition( Lview->Top(), 0, FALSE); 518// Lview->setCursorPosition( Lview->Top(), 0, FALSE);
519 519
520 } 520 }
521 } 521 }
522 Lview->setFocus(); 522 Lview->setFocus();
523} 523}
524 524
525void Gutenbrowser::doBeginBtn() { 525void Gutenbrowser::doBeginBtn() {
526 if(loadCheck) { 526 if(loadCheck) {
527 qApp->processEvents(); 527 qApp->processEvents();
528 BeginBtn(); 528 BeginBtn();
529 } 529 }
530} 530}
531 531
532 // moves text to the very top = 0 532 // moves text to the very top = 0
533void Gutenbrowser::TopBtn() { 533void Gutenbrowser::TopBtn() {
534 534
535 if(loadCheck) { 535 if(loadCheck) {
536 if( i_pageNum != 0) { 536 if( i_pageNum != 0) {
537 odebug << "top" << oendl; 537 odebug << "top" << oendl;
538 qApp->processEvents(); 538 qApp->processEvents();
539 currentLine = 0; 539 currentLine = 0;
540 i_pageNum = 1; 540 i_pageNum = 1;
541 int pageSize = Lview->PageSize() ; 541 int pageSize = Lview->PageSize() ;
542 Lview->clear(); 542 Lview->clear();
543 QString s; 543 QString s;
544 f.at(0); 544 f.at(0);
545 for(int fd=0; fd < pageSize ;fd++) { 545 for(int fd=0; fd < pageSize ;fd++) {
546 f.readLine(s, 256); 546 f.readLine(s, 256);
547 if(useWrap) 547 if(useWrap)
548 s.replace(QRegExp("\n"),""); 548 s.replace(QRegExp("\n"),"");
549 Lview->insertLine(s ,-1); 549 Lview->insertLine(s ,-1);
550 currentLine++; 550 currentLine++;
551 } 551 }
552// Lview->setCursorPosition( 0,0, FALSE); 552// Lview->setCursorPosition( 0,0, FALSE);
553 i_pageNum=1; 553 i_pageNum=1;
554 setStatus(); 554 setStatus();
555 } 555 }
556 Lview->setFocus(); 556 Lview->setFocus();
557 } 557 }
558} 558}
559 559
560 //moves text to the start of the EText 560 //moves text to the start of the EText
561void Gutenbrowser::BeginBtn() { 561void Gutenbrowser::BeginBtn() {
562 i_pageNum = 1; 562 i_pageNum = 1;
563 currentLine = 0; 563 currentLine = 0;
564 QString s_pattern="*END*THE SMALL PRINT"; 564 QString s_pattern="*END*THE SMALL PRINT";
565 QString sPattern2 = "*END THE SMALL PRINT"; 565 QString sPattern2 = "*END THE SMALL PRINT";
566 566
567 int pageSize = Lview->PageSize(); 567 int pageSize = Lview->PageSize();
568 Lview->clear(); 568 Lview->clear();
569 569
570 // int lines = Lview->numLines(); 570 // int lines = Lview->numLines();
571 int pos = 0;//, i = 0; 571 int pos = 0;//, i = 0;
572 int i_topRow = Lview->topRow(); 572 int i_topRow = Lview->topRow();
573 573
574 QString LeftText;// = Lview->text(); 574 QString LeftText;// = Lview->text();
575 575
576 // int linesPerPage = Lview->lastRow() - Lview->topRow(); 576 // int linesPerPage = Lview->lastRow() - Lview->topRow();
577 // int pages = (( linesPerPage / Lview->editSize() ) ) +1; 577 // int pages = (( linesPerPage / Lview->editSize() ) ) +1;
578 // int pageN = 0; 578 // int pageN = 0;
579 i_pageNum = 1; 579 i_pageNum = 1;
580 int lastPage=1; 580 int lastPage=1;
581 int lineNo=0; 581 int lineNo=0;
582 QString s; 582 QString s;
583 f.at( 0); 583 f.at( 0);
584 584
585 while ( !f.atEnd() ) { 585 while ( !f.atEnd() ) {
586 f.readLine(s, 256); 586 f.readLine(s, 256);
587 lineNo++; 587 lineNo++;
588 LeftText = s; 588 LeftText = s;
589 currentFilePos = f.at(); 589 currentFilePos = f.at();
590 590
591 i_pageNum = lineNo/pageSize; 591 i_pageNum = lineNo/pageSize;
592 if(lastPage < i_pageNum) { 592 if(lastPage < i_pageNum) {
593 pageStopArray.resize(i_pageNum + 1); 593 pageStopArray.resize(i_pageNum + 1);
594 pageStopArray[i_pageNum ] = currentFilePos; 594 pageStopArray[i_pageNum ] = currentFilePos;
595 // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; 595 // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl;
596 } 596 }
597 // lastPage = i_pageNum; 597 // lastPage = i_pageNum;
598 if( LeftText.find( s_pattern, 0 , TRUE) != -1 || LeftText.find( sPattern2, 0 , TRUE) != -1 ) { 598 if( LeftText.find( s_pattern, 0 , TRUE) != -1 || LeftText.find( sPattern2, 0 , TRUE) != -1 ) {
599 odebug << "<<<<<< FOUND IT!! new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; 599 odebug << "<<<<<< FOUND IT!! new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl;
600 break; 600 break;
601 } 601 }
602 } 602 }
603 if(f.atEnd()) //in case we didnt find anything, we need to show something 603 if(f.atEnd()) //in case we didnt find anything, we need to show something
604 f.at(0); 604 f.at(0);
605 Lview->clear(); 605 Lview->clear();
606 for(int fd=0; fd < pageSize - 1;fd++) { 606 for(int fd=0; fd < pageSize - 1;fd++) {
607 f.readLine(s, 256); 607 f.readLine(s, 256);
608 if(useWrap) 608 if(useWrap)
609 s.replace(QRegExp("\n"),""); 609 s.replace(QRegExp("\n"),"");
610 Lview->insertLine( s, -1); 610 Lview->insertLine( s, -1);
611 currentLine++; 611 currentLine++;
612 } 612 }
613 613
614 i_pageNum = lineNo/pageSize; 614 i_pageNum = lineNo/pageSize;
615 pageStopArray.resize(i_pageNum + 1); 615 pageStopArray.resize(i_pageNum + 1);
616 // int length = Lview->length(); 616 // int length = Lview->length();
617 617
618 qApp->processEvents(); 618 qApp->processEvents();
619 619
620 if( pos > i_topRow ) { 620 if( pos > i_topRow ) {
621// Lview->setCursorPosition( pos+linesPerPage+2/* - i_topRow+3 */,0, FALSE); 621// Lview->setCursorPosition( pos+linesPerPage+2/* - i_topRow+3 */,0, FALSE);
622 } else { 622 } else {
623// Lview->setCursorPosition( pos+2 , 0, FALSE ); 623// Lview->setCursorPosition( pos+2 , 0, FALSE );
624 } 624 }
625 625
626 Lview->deselect(); 626 Lview->deselect();
627 // AdjustStatus(); 627 // AdjustStatus();
628 Lview->setFocus(); 628 Lview->setFocus();
629} 629}
630 630
631 /* 631 /*
632 sets the current page and place as a bookmark*/ 632 sets the current page and place as a bookmark*/
633void Gutenbrowser::setBookmark() { 633void Gutenbrowser::setBookmark() {
634 int eexit=QMessageBox::information(this, "Note", 634 int eexit=QMessageBox::information(this, "Note",
635 "Do you really want to \nset this bookmark?." 635 "Do you really want to \nset this bookmark?."
636 ,QMessageBox::Yes, QMessageBox::No); 636 ,QMessageBox::Yes, QMessageBox::No);
637 if (eexit== 3) { 637 if (eexit== 3) {
638 638
639 currentFilePos = f.at(); 639 currentFilePos = f.at();
640 640
641 Config cfg("Gutenbrowser"); 641 Config cfg("Gutenbrowser");
642 cfg.setGroup("General"); 642 cfg.setGroup("General");
643 file_name = cfg.readEntry("Current",""); 643 file_name = cfg.readEntry("Current","");
644 qApp->processEvents(); 644 qApp->processEvents();
645 odebug << "Setting book mark "+file_name << oendl; 645 odebug << "Setting book mark "+file_name << oendl;
646 646
647 cfg.setGroup("Titles"); 647 cfg.setGroup("Titles");
648 title = cfg.readEntry(file_name,""); 648 title = cfg.readEntry(file_name,"");
649 odebug << "title is "+ title << oendl; 649 odebug << "title is "+ title << oendl;
650 650
651 cfg.setGroup( "Bookmarks" ); 651 cfg.setGroup( "Bookmarks" );
652 652
653 cfg.writeEntry("File Name",file_name); 653 cfg.writeEntry("File Name",file_name);
654 cfg.writeEntry("Page Number",QString::number(i_pageNum) ); 654 cfg.writeEntry("Page Number",QString::number(i_pageNum) );
655 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1])); 655 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1]));
656 cfg.writeEntry("Title", title); 656 cfg.writeEntry("Title", title);
657 657
658 int row = Lview->topRow();// Lview->Top(); 658 int row = Lview->topRow();// Lview->Top();
659 cfg.writeEntry("LineNumber",QString::number(row) ); 659 cfg.writeEntry("LineNumber",QString::number(row) );
660 660
661 cfg.setGroup(title); 661 cfg.setGroup(title);
662 cfg.writeEntry("File Name",file_name); 662 cfg.writeEntry("File Name",file_name);
663 cfg.writeEntry( "LineNumber", QString::number( row)); 663 cfg.writeEntry( "LineNumber", QString::number( row));
664 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1])); 664 cfg.writeEntry( "PagePosition", QString::number( pageStopArray[i_pageNum - 1]));
665 cfg.writeEntry( "Page Number", QString::number( i_pageNum) ); 665 cfg.writeEntry( "Page Number", QString::number( i_pageNum) );
666 cfg.write(); 666 cfg.write();
667 bookmarksMenu->insertItem( title); 667 bookmarksMenu->insertItem( title);
668 } 668 }
669} //end setBookmark 669} //end setBookmark
670 670
671 671
672 /* goes to last set bookmark*/ 672 /* goes to last set bookmark*/
673void Gutenbrowser::Bookmark( int itemId) { 673void Gutenbrowser::Bookmark( int itemId) {
674 674
675 // qApp->processEvents(); 675 // qApp->processEvents();
676 Config config("Gutenbrowser"); 676 Config config("Gutenbrowser");
677 config.setGroup( "Bookmarks" ); 677 config.setGroup( "Bookmarks" );
678 678
679 odebug << "<<<<<< " << Lview->PageSize() << ", " << Lview->lastRow() - Lview->topRow() << "" << oendl; 679 odebug << "<<<<<< " << Lview->PageSize() << ", " << Lview->lastRow() - Lview->topRow() << "" << oendl;
680 680
681 QString itemString; 681 QString itemString;
682 682
683 odebug << "menu item " << itemId << "" << oendl; 683 odebug << "menu item " << itemId << "" << oendl;
684 QString tempTitle; 684 QString tempTitle;
685 QString s_Bmrkrow; 685 QString s_Bmrkrow;
686 QString s_pageNum; 686 QString s_pageNum;
687 int Bmrkrow=0; 687 int Bmrkrow=0;
688 int bookmarkPosition = 0; 688 int bookmarkPosition = 0;
689 689
690 // qApp->processEvents(); 690 // qApp->processEvents();
691 config.setGroup( "Bookmarks" ); 691 config.setGroup( "Bookmarks" );
692 title = config.readEntry("Title", ""); 692 title = config.readEntry("Title", "");
693 file_name = config.readEntry("File Name", ""); 693 file_name = config.readEntry("File Name", "");
694 i_pageNum = config.readNumEntry("Page Number", 0); 694 i_pageNum = config.readNumEntry("Page Number", 0);
695 bookmarkPosition = config.readNumEntry( "PagePosition",0); 695 bookmarkPosition = config.readNumEntry( "PagePosition",0);
696 Bmrkrow = config.readNumEntry("LineNumber",0); 696 Bmrkrow = config.readNumEntry("LineNumber",0);
697 if( !file_name.contains("/")) { 697 if( !file_name.contains("/")) {
698 file_name = local_library + file_name; 698 file_name = local_library + file_name;
699 } 699 }
700 700
701 // getTitle(file_name); 701 // getTitle(file_name);
702 // qApp->processEvents(); 702 // qApp->processEvents();
703 // Lview->setFocus(); 703 // Lview->setFocus();
704 this->setFocus(); 704 this->setFocus();
705 705
706 Lview->clear(); 706 Lview->clear();
707 707
708 if(!load(file_name)) return; 708 if(!load(file_name)) return;
709 709
710 int pageSize = Lview->PageSize(); 710 int pageSize = Lview->PageSize();
711 f.at(0); 711 f.at(0);
712 // Lview->clear(); 712 // Lview->clear();
713 QString s; 713 QString s;
714 int lineNo=0; 714 int lineNo=0;
715 int lastPage=1; 715 int lastPage=1;
716 while ( !f.atEnd() ) { 716 while ( !f.atEnd() ) {
717 f.readLine(s, 256); 717 f.readLine(s, 256);
718 lineNo++; 718 lineNo++;
719 currentFilePos = f.at(); 719 currentFilePos = f.at();
720 720
721 i_pageNum = lineNo/pageSize; 721 i_pageNum = lineNo/pageSize;
722 if(lastPage < i_pageNum) { 722 if(lastPage < i_pageNum) {
723 pageStopArray.resize(i_pageNum + 1); 723 pageStopArray.resize(i_pageNum + 1);
724 pageStopArray[i_pageNum ] = currentFilePos; 724 pageStopArray[i_pageNum ] = currentFilePos;
725 // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl; 725 // odebug << "new page number " << i_pageNum << ", found at " << currentFilePos << "" << oendl;
726 } 726 }
727 if(currentFilePos == bookmarkPosition) 727 if(currentFilePos == bookmarkPosition)
728 break; 728 break;
729 } 729 }
730 if(f.atEnd()) 730 if(f.atEnd())
731 f.at(0); 731 f.at(0);
732 else 732 else
733 f.at( bookmarkPosition); 733 f.at( bookmarkPosition);
734 734
735 for(int fd=0; fd < pageSize - 1;fd++) { 735 for(int fd=0; fd < pageSize - 1;fd++) {
736 f.readLine(s, 256); 736 f.readLine(s, 256);
737 lineNo++; 737 lineNo++;
738 if(useWrap) 738 if(useWrap)
739 s.replace(QRegExp("\n"),""); 739 s.replace(QRegExp("\n"),"");
740 Lview->insertLine( s, -1); 740 Lview->insertLine( s, -1);
741 currentLine++; 741 currentLine++;
742 } 742 }
743 743
744 i_pageNum = lineNo/pageSize; 744 i_pageNum = lineNo/pageSize;
745 pageStopArray.resize(i_pageNum + 1); 745 pageStopArray.resize(i_pageNum + 1);
746 746
747 if(showMainList) { 747 if(showMainList) {
748 showMainList=FALSE; 748 showMainList=FALSE;
749 mainList->hide(); 749 mainList->hide();
750 Lview->show(); 750 Lview->show();
751 // qApp->processEvents(); 751 // qApp->processEvents();
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);
960 } 954 }
961// Lview->setCursorPosition(i ,pos + length ,TRUE ); 955// Lview->setCursorPosition(i ,pos + length ,TRUE );
962 // int newTop = Lview->Top(); 956 // int newTop = Lview->Top();
963 /* if(useSplitter) Rview->ScrollUp( newTop - top); 957 /* if(useSplitter) Rview->ScrollUp( newTop - top);
964 */ } 958 */ }
965 } else { 959 } else {
966 if( ! (line == i && pos > col ) ) { 960 if( ! (line == i && pos > col ) ) {
967// Lview->setCursorPosition( i, pos, FALSE ); 961// Lview->setCursorPosition( i, pos, FALSE );
968 for( int l = 0 ; l < length; l++) { 962 for( int l = 0 ; l < length; l++) {
969 Lview->cursorRight( TRUE); 963 Lview->cursorRight( TRUE);
970 } 964 }
971// Lview->setCursorPosition( i, pos + length, TRUE ); 965// Lview->setCursorPosition( i, pos + length, TRUE );
972 } 966 }
973 pattern = s_pattern; 967 pattern = s_pattern;
974 last_search = -1; 968 last_search = -1;
975 return 1; 969 return 1;
976 } 970 }
977 } 971 }
978 } 972 }
979 } 973 }
980 return 0; 974 return 0;
981} 975}
982 976
983void Gutenbrowser::LibraryBtn() { 977void Gutenbrowser::LibraryBtn() {
984 978
985 QString newestLibraryFile ="pgwhole.zip"; 979 QString newestLibraryFile ="pgwhole.zip";
986 QString zipFile; 980 QString zipFile;
987 // odebug << "Local Library is " << local_library << " " << oendl; 981 // odebug << "Local Library is " << local_library << " " << oendl;
988 zipFile="/usr/bin/unzip"; 982 zipFile="/usr/bin/unzip";
989 // odebug << "newestLibraryFile is " << newestLibraryFile << " " << oendl; 983 // odebug << "newestLibraryFile is " << newestLibraryFile << " " << oendl;
990 if( QFile::exists( local_library+newestLibraryFile)) { 984 if( QFile::exists( local_library+newestLibraryFile)) {
991 if( QFile::exists(zipFile) ) { 985 if( QFile::exists(zipFile) ) {
992 UnZipIt(newestLibraryFile); 986 UnZipIt(newestLibraryFile);
993 } 987 }
994 else 988 else
995 QMessageBox::message( "Note",( tr("Please install unzip")) ); 989 QMessageBox::message( "Note",( tr("Please install unzip")) );
996 } 990 }
997 // LibraryDlg = new LibraryDialog( this, "Library Index"); 991 // LibraryDlg = new LibraryDialog( this, "Library Index");
998 LibraryDlg->setCaption( tr( "Gutenberg Library")); 992 LibraryDlg->setCaption( tr( "Gutenberg Library"));
999 Config config("Gutenbrowser"); 993 Config config("Gutenbrowser");
1000 config.setGroup("General"); 994 config.setGroup("General");
1001 995
1002 if(useSplitter) 996 if(useSplitter)
1003 LibraryDlg->useSmallInterface=FALSE; 997 LibraryDlg->useSmallInterface=FALSE;
1004 998
1005 LibraryDlg->showMaximized(); 999 LibraryDlg->showMaximized();
1006 1000
1007 if( LibraryDlg->exec() != 0 ) { 1001 if( LibraryDlg->exec() != 0 ) {
1008 listItemNumber = LibraryDlg->DlglistItemNumber; 1002 listItemNumber = LibraryDlg->DlglistItemNumber;
1009 listItemFile = LibraryDlg->DlglistItemFile; 1003 listItemFile = LibraryDlg->DlglistItemFile;
1010 listItemYear = LibraryDlg->DlglistItemYear; 1004 listItemYear = LibraryDlg->DlglistItemYear;
1011 listItemTitle = LibraryDlg->DlglistItemTitle; 1005 listItemTitle = LibraryDlg->DlglistItemTitle;
1012 file_name = LibraryDlg->File_Name; 1006 file_name = LibraryDlg->File_Name;
1013 // odebug << "title is being set as "+title << oendl; 1007 // odebug << "title is being set as "+title << oendl;
1014 title = listItemTitle; 1008 title = listItemTitle;
1015 1009
1016 // config.setGroup( "Proxy" ); 1010 // config.setGroup( "Proxy" );
1017 // if( LibraryDlg->checked == 1) { 1011 // if( LibraryDlg->checked == 1) {
1018 // config.writeEntry("IsChecked", "TRUE"); 1012 // config.writeEntry("IsChecked", "TRUE");
1019 // } else { 1013 // } else {
1020 // config.writeEntry("IsChecked", "FALSE"); 1014 // config.writeEntry("IsChecked", "FALSE");
1021 // } 1015 // }
1022 // config.write(); 1016 // config.write();
1023 // config.read(); 1017 // config.read();
1024 if ( listItemNumber.isNull()) { 1018 if ( listItemNumber.isNull()) {
1025 } else { 1019 } else {
1026 i_pageNum = 1; 1020 i_pageNum = 1;
1027 if( file_name !="Error" && file_name.length() >2 && !file_name.isEmpty() ) { 1021 if( file_name !="Error" && file_name.length() >2 && !file_name.isEmpty() ) {
1028 //replace .zip with txt for opening it. 1022 //replace .zip with txt for opening it.
1029 // printf("\nFile name is now\n"); 1023 // printf("\nFile name is now\n");
1030 // printf(file_name); 1024 // printf(file_name);
1031 // printf("\n"); 1025 // printf("\n");
1032 // 1026 //
1033 if( file_name.find(".zip")) 1027 if( file_name.find(".zip"))
1034 { 1028 {
1035 odebug << "Found zip file\n" << oendl; 1029 odebug << "Found zip file\n" << oendl;
1036 // QStringList args; 1030 // QStringList args;
1037 // args="unzip"; 1031 // args="unzip";
1038 // args+="-o"; 1032 // args+="-o";
1039 // args+=local_library+file_name; 1033 // args+=local_library+file_name;
1040 // args+="-d"; 1034 // args+="-d";
1041 // args+=local_library; 1035 // args+=local_library;
1042 QString cmd = "/usr/bin/unzip -o " + local_library+file_name + " -d " + local_library; 1036 QString cmd = "/usr/bin/unzip -o " + local_library+file_name + " -d " + local_library;
1043 odebug << "Issuing the command "+ cmd << oendl; 1037 odebug << "Issuing the command "+ cmd << oendl;
1044 // unzipProc=new QProcess( this, "unzipProc" ); /// fark that idea! 1038 // unzipProc=new QProcess( this, "unzipProc" ); /// fark that idea!
1045 // unzipProc->start(); 1039 // unzipProc->start();
1046 system(cmd); 1040 system(cmd);
1047 remove( file_name); 1041 remove( file_name);
1048 1042
1049 } 1043 }
1050 // // 1044 // //
1051 // file_name = file_name.left(4)+ ".txt"; 1045 // file_name = file_name.left(4)+ ".txt";
1052 if( LibraryDlg) 1046 if( LibraryDlg)
1053 delete LibraryDlg; 1047 delete LibraryDlg;
1054 setTitle(); 1048 setTitle();
1055 // QCopEnvelope ( "QPE/System", "busy()" ); 1049 // QCopEnvelope ( "QPE/System", "busy()" );
1056 if( !load( file_name)) return; 1050 if( !load( file_name)) return;
1057 } else { 1051 } else {
1058 printf("Not opening the file.\n"); 1052 printf("Not opening the file.\n");
1059 } 1053 }
1060 } 1054 }
1061 } 1055 }
1062 if(showMainList) { 1056 if(showMainList) {
1063 if(!Lview->isHidden()) 1057 if(!Lview->isHidden())
1064 Lview->hide(); 1058 Lview->hide();
1065 qApp->processEvents(); 1059 qApp->processEvents();
1066 showMainList=TRUE; 1060 showMainList=TRUE;
1067 if(mainList->isHidden()) 1061 if(mainList->isHidden())
1068 mainList->show(); 1062 mainList->show();
1069 fillWithTitles(); 1063 fillWithTitles();
1070 qApp->processEvents(); 1064 qApp->processEvents();
1071 } else 1065 } else
1072 setCentralWidget( Lview); 1066 setCentralWidget( Lview);
1073 // QPEApplication::grabKeyboard(); 1067 // QPEApplication::grabKeyboard();
1074 // fixKeys(); 1068 // fixKeys();
1075} 1069}
1076 1070
1077void Gutenbrowser::OpenBtn() { 1071void Gutenbrowser::OpenBtn() {
1078 QString s_temp; 1072 QString s_temp;
1079 s_temp = status; 1073 s_temp = status;
1080 OpenEtext* OpenDlg; 1074 OpenEtext* OpenDlg;
1081 OpenDlg = new OpenEtext(this,"OpenDlg"); 1075 OpenDlg = new OpenEtext(this,"OpenDlg");
1082 OpenDlg->showMaximized(); 1076 OpenDlg->showMaximized();
1083 1077
1084 if( OpenDlg->exec() != 0) { 1078 if( OpenDlg->exec() != 0) {
1085 title = OpenDlg->openFileTitle; 1079 title = OpenDlg->openFileTitle;
1086 odebug << "title open as "+title << oendl; 1080 odebug << "title open as "+title << oendl;
1087 file_name = OpenDlg->file; 1081 file_name = OpenDlg->file;
1088 i_pageNum = 1; 1082 i_pageNum = 1;
1089 1083
1090 if( !file_name.isEmpty() || file_name.length() > 2 ) { 1084 if( !file_name.isEmpty() || file_name.length() > 2 ) {
1091 if(showMainList) { 1085 if(showMainList) {
1092 showMainList=FALSE; 1086 showMainList=FALSE;
1093 odebug << "ShowMainList is now false" << oendl; 1087 odebug << "ShowMainList is now false" << oendl;
1094 mainList->hide(); 1088 mainList->hide();
1095 Lview->show(); 1089 Lview->show();
1096 qApp->processEvents(); 1090 qApp->processEvents();
1097 } 1091 }
1098 Lview->clear(); 1092 Lview->clear();
1099 // QCopEnvelope ( "QPE/System", "busy()" ); 1093 // QCopEnvelope ( "QPE/System", "busy()" );
1100 if(!load(file_name)) return; 1094 if(!load(file_name)) return;
1101 } else { 1095 } else {
1102 odebug << "file_name is empty!" << oendl; 1096 odebug << "file_name is empty!" << oendl;
1103 if(showMainList) { 1097 if(showMainList) {
1104 if(!Lview->isHidden()) 1098 if(!Lview->isHidden())
1105 Lview->hide(); 1099 Lview->hide();
1106 qApp->processEvents(); 1100 qApp->processEvents();
1107 if(mainList->isHidden()) 1101 if(mainList->isHidden())
1108 mainList->show(); 1102 mainList->show();
1109 fillWithTitles(); 1103 fillWithTitles();
1110 qApp->processEvents(); 1104 qApp->processEvents();
1111 } 1105 }
1112 1106
1113 } 1107 }
1114 } 1108 }
1115 if( OpenDlg) 1109 if( OpenDlg)
1116 delete OpenDlg; 1110 delete OpenDlg;
1117 /* 1111 /*
1118 Config config("Gutenbrowser"); 1112 Config config("Gutenbrowser");
1119 config.setGroup( title); 1113 config.setGroup( title);
1120 file_name = config.readEntry("File Name", ""); 1114 file_name = config.readEntry("File Name", "");
1121 i_pageNum = config.readNumEntry("Page Number", -1); 1115 i_pageNum = config.readNumEntry("Page Number", -1);
1122 int Bmrkrow = config.readNumEntry("LineNumber", -1); 1116 int Bmrkrow = config.readNumEntry("LineNumber", -1);
1123 if(Bmrkrow > -1) { 1117 if(Bmrkrow > -1) {
1124 if( Bmrkrow > Lview->topRow() ) { 1118 if( Bmrkrow > Lview->topRow() ) {
1125 Lview->setCursorPosition( Bmrkrow ,0, FALSE ); 1119 Lview->setCursorPosition( Bmrkrow ,0, FALSE );
1126 Lview->ScrollUp( Bmrkrow - Lview->topRow() ); 1120 Lview->ScrollUp( Bmrkrow - Lview->topRow() );
1127 // AdjustStatus(); 1121 // AdjustStatus();
1128 } 1122 }
1129 else if( Bmrkrow < Lview->topRow() ) { 1123 else if( Bmrkrow < Lview->topRow() ) {
1130 Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE ); 1124 Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE );
1131 Lview->ScrollDown( Lview->topRow() - Bmrkrow ); 1125 Lview->ScrollDown( Lview->topRow() - Bmrkrow );
1132 // AdjustStatus(); 1126 // AdjustStatus();
1133 } 1127 }
1134 } 1128 }
1135 */ 1129 */
1136 // ResizeEdits(); 1130 // ResizeEdits();
1137 1131
1138} 1132}
1139 1133
1140void Gutenbrowser::ChangeFont() { 1134void Gutenbrowser::ChangeFont() {
1141#ifndef Q_WS_QWS 1135#ifndef Q_WS_QWS
1142 bool ok; 1136 bool ok;
1143 1137
1144 weight= Lview->fontInfo().weight(); 1138 weight= Lview->fontInfo().weight();
1145 italic = Lview->fontInfo().italic(); 1139 italic = Lview->fontInfo().italic();
1146 bold=Lview->fontInfo().bold(); 1140 bold=Lview->fontInfo().bold();
1147 pointSize= Lview->fontInfo().pointSize(); 1141 pointSize= Lview->fontInfo().pointSize();
1148 fontStr=Lview->fontInfo().family(); 1142 fontStr=Lview->fontInfo().family();
1149 1143
1150 if(italic == true) 1144 if(italic == true)
1151 italicStr="TRUE"; 1145 italicStr="TRUE";
1152 else 1146 else
1153 italicStr="FALSE"; 1147 italicStr="FALSE";
1154 1148
1155 QFont currentfont( fontStr, pointSize, weight, italic ); 1149 QFont currentfont( fontStr, pointSize, weight, italic );
1156 1150
1157 if (ok) { 1151 if (ok) {
1158 QFontInfo fontInfo(font ); 1152 QFontInfo fontInfo(font );
1159 fontStr=fontInfo.family(); 1153 fontStr=fontInfo.family();
1160 1154
1161 pointSize= fontInfo.pointSize(); 1155 pointSize= fontInfo.pointSize();
1162 1156
1163 font.setFontSize(pointSize); 1157 font.setFontSize(pointSize);
1164 1158
1165 pointSizeStr.setNum( pointSize); 1159 pointSizeStr.setNum( pointSize);
1166 1160
1167 weight= fontInfo.weight(); 1161 weight= fontInfo.weight();
1168 weightStr.setNum( weight); 1162 weightStr.setNum( weight);
1169 italic =fontInfo.italic(); 1163 italic =fontInfo.italic();
1170 bold=fontInfo.bold(); 1164 bold=fontInfo.bold();
1171 1165
1172 if(italic == true) 1166 if(italic == true)
1173 italicStr="TRUE"; 1167 italicStr="TRUE";
1174 else 1168 else
1175 italicStr="FALSE"; 1169 italicStr="FALSE";
1176 if(bold == true) 1170 if(bold == true)
1177 boldStr="TRUE"; 1171 boldStr="TRUE";
1178 else 1172 else
1179 boldStr="FALSE"; 1173 boldStr="FALSE";
1180 1174
1181 pointSizeStr.setNum( pointSize); 1175 pointSizeStr.setNum( pointSize);
1182 config.setGroup( "Font" ); 1176 config.setGroup( "Font" );
1183 config.writeEntry("Family", fontStr ); 1177 config.writeEntry("Family", fontStr );
1184 config.writeEntry("Size", pointSizeStr ); 1178 config.writeEntry("Size", pointSizeStr );
1185 config.writeEntry("Weight", weightStr ); 1179 config.writeEntry("Weight", weightStr );
1186 config.writeEntry("Italic", italicStr ); 1180 config.writeEntry("Italic", italicStr );
1187 config.writeEntry("Bold", boldStr ); 1181 config.writeEntry("Bold", boldStr );
1188 // config.write(); 1182 // config.write();
1189 1183
1190 Lview->setFont(font); 1184 Lview->setFont(font);
1191 1185
1192 QRect lRect; 1186 QRect lRect;
1193 QRect rRect; 1187 QRect rRect;
1194 lRect = Lview->rect(); 1188 lRect = Lview->rect();
1195 if(useSplitter) { 1189 if(useSplitter) {
1196 } 1190 }
1197 // if(loadCheck) { 1191 // if(loadCheck) {
1198 // ResizeEdits(); 1192 // ResizeEdits();
1199 // } 1193 // }
1200 update(); 1194 update();
1201 } 1195 }
1202#endif 1196#endif
1203} 1197}
1204 1198
1205 1199
1206 /* 1200 /*
1207 performs dictionary look ups on the web */ 1201 performs dictionary look ups on the web */
1208void Gutenbrowser::LookupBtn() { 1202void Gutenbrowser::LookupBtn() {
1209 QString text; 1203 QString text;
1210 if( Lview->hasSelectedText()) { 1204 if( Lview->hasSelectedText()) {
1211 Lview->copy(); 1205 Lview->copy();
1212 } 1206 }
1213 QClipboard *cb = QApplication::clipboard(); 1207 QClipboard *cb = QApplication::clipboard();
1214 text = cb->text(); 1208 text = cb->text();
1215 int eexit=QMessageBox::information(this, 1209 int eexit=QMessageBox::information(this,
1216 "Note","Do you want to lookup\n\""+text+"\"\non websters web dictionary?", 1210 "Note","Do you want to lookup\n\""+text+"\"\non websters web dictionary?",
1217 QMessageBox::Yes, QMessageBox::No); 1211 QMessageBox::Yes, QMessageBox::No);
1218 if (eexit== 3) { 1212 if (eexit== 3) {
1219 // this link for sale!! 1213 // this link for sale!!
1220 qApp->processEvents(); 1214 qApp->processEvents();
1221 goGetit( "http://www.m-w.com/cgi-bin/dictionary?" + text, true); 1215 goGetit( "http://www.m-w.com/cgi-bin/dictionary?" + text, true);
1222 } 1216 }
1223} 1217}
1224 1218
1225void Gutenbrowser::ClearEdit() { 1219void Gutenbrowser::ClearEdit() {
1226 Lview->setText(""); 1220 Lview->setText("");
1227 loadCheck = false; 1221 loadCheck = false;
1228 status = ( tr("Gutenbrowser")); 1222 status = ( tr("Gutenbrowser"));
1229 InfoBar->setText( ""); 1223 InfoBar->setText( "");
1230 setCaption( tr("Gutenbrowser")); 1224 setCaption( tr("Gutenbrowser"));
1231 i_pageNum = 0; 1225 i_pageNum = 0;
1232 enableButtons(false); 1226 enableButtons(false);
1233 1227
1234 if(!showMainList) { 1228 if(!showMainList) {
1235 Lview->hide(); 1229 Lview->hide();
1236 showMainList=TRUE; 1230 showMainList=TRUE;
1237 mainList->show(); 1231 mainList->show();
1238 fillWithTitles(); 1232 fillWithTitles();
1239 qApp->processEvents(); 1233 qApp->processEvents();
1240 } 1234 }
1241 if(donateMenu->idAt(3) != -1) 1235 if(donateMenu->idAt(3) != -1)
1242 donateMenu->removeItemAt(3); 1236 donateMenu->removeItemAt(3);
1243} 1237}
1244 1238
1245 1239
1246bool Gutenbrowser::getTitle( const char *file ) { 1240bool Gutenbrowser::getTitle( const char *file ) {
1247 QString s_file; 1241 QString s_file;
1248 QString filer = file; 1242 QString filer = file;
1249 if( filer.contains(local_library, TRUE)) { 1243 if( filer.contains(local_library, TRUE)) {
1250 QFileInfo f(file); 1244 QFileInfo f(file);
1251 s_file = f.fileName(); 1245 s_file = f.fileName();
1252 } else { 1246 } else {
1253 s_file = filer; 1247 s_file = filer;
1254 } 1248 }
1255 Config config("Gutenbrowser"); 1249 Config config("Gutenbrowser");
1256 config.setGroup( "Files" ); 1250 config.setGroup( "Files" );
1257 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); 1251 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
1258 int i_numofFiles = s_numofFiles.toInt(); 1252 int i_numofFiles = s_numofFiles.toInt();
1259 1253
1260 for (int i = 1; i <= i_numofFiles; i++) { 1254 for (int i = 1; i <= i_numofFiles; i++) {
1261 QString temp; 1255 QString temp;
1262 temp.setNum(i); 1256 temp.setNum(i);
1263 QString ramble = config.readEntry(temp, "" ); 1257 QString ramble = config.readEntry(temp, "" );
1264 1258
1265 if( strcmp(ramble, s_file) == 0) { 1259 if( strcmp(ramble, s_file) == 0) {
1266 config.setGroup( "Titles" ); 1260 config.setGroup( "Titles" );
1267 title = config.readEntry(ramble, ""); 1261 title = config.readEntry(ramble, "");
1268 // odebug << "(getTitle)title is being set as "+title << oendl; 1262 // odebug << "(getTitle)title is being set as "+title << oendl;
1269 } 1263 }
1270 } 1264 }
1271 return true; 1265 return true;
1272} 1266}
1273 1267
1274void Gutenbrowser::searchdone_slot() { 1268void Gutenbrowser::searchdone_slot() {
1275 // if (!searchDlg) 1269 // if (!searchDlg)
1276 // return; 1270 // return;
1277 // searchDlg->hide(); 1271 // searchDlg->hide();
1278 // Lview->setFocus(); 1272 // Lview->setFocus();
1279 this->setFocus(); 1273 this->setFocus();
1280 last_search = 0; 1274 last_search = 0;
1281 // ResizeEdits(); 1275 // ResizeEdits();
1282} 1276}
1283 1277
1284 /* 1278 /*
1285 sets the status message */ 1279 sets the status message */
1286bool Gutenbrowser::setStatus() { 1280bool Gutenbrowser::setStatus() {
1287 1281
1288#ifndef Q_WS_QWS 1282#ifndef Q_WS_QWS
1289 QString s_pages; 1283 QString s_pages;
1290 s_pages.setNum( pages); 1284 s_pages.setNum( pages);
1291 QString chNum; 1285 QString chNum;
1292 statusTop = status.left( status.find(" ", TRUE) ); 1286 statusTop = status.left( status.find(" ", TRUE) );
1293 status.append(chNum.setNum( i_pageNum)); 1287 status.append(chNum.setNum( i_pageNum));
1294 status += " / " + s_pages; 1288 status += " / " + s_pages;
1295 1289
1296 if(loadCheck) { 1290 if(loadCheck) {
1297 statusBar->message( status); 1291 statusBar->message( status);
1298 InfoBar->setText( title); 1292 InfoBar->setText( title);
1299 } else { 1293 } else {
1300 } 1294 }
1301#else 1295#else
1302 QString msg; 1296 QString msg;
1303 msg.sprintf(title+" %d", i_pageNum); 1297 msg.sprintf(title+" %d", i_pageNum);
1304 setCaption( msg); 1298 setCaption( msg);
1305#endif 1299#endif
1306 return true; 1300 return true;
1307} 1301}
1308 1302
1309void Gutenbrowser::keyReleaseEvent( QKeyEvent *e) { 1303void Gutenbrowser::keyReleaseEvent( QKeyEvent *e) {
1310 switch ( e->key() ) { 1304 switch ( e->key() ) {
1311 1305
1312 case Key_M: 1306 case Key_M:
1313 // Bookmark(); 1307 // Bookmark();
1314 break; 1308 break;
1315 case Key_D: 1309 case Key_D:
1316 DownloadIndex(); 1310 DownloadIndex();
1317 break; 1311 break;
1318 case Key_L: 1312 case Key_L:
1319 LibraryBtn(); 1313 LibraryBtn();
1320 break; 1314 break;
1321 case Key_O: 1315 case Key_O:
1322 OpenBtn(); 1316 OpenBtn();
1323 break; 1317 break;
1324 case Key_F: 1318 case Key_F:
1325 ForwardBtn(); 1319 ForwardBtn();
1326 break; 1320 break;
1327 case Key_B: 1321 case Key_B:
1328 BackBtn(); 1322 BackBtn();
1329 break; 1323 break;
1330 case Key_P: 1324 case Key_P:
1331 PrintBtn(); 1325 PrintBtn();
1332 break; 1326 break;
1333 case Key_S: 1327 case Key_S:
1334 SearchBtn(); 1328 SearchBtn();
1335 break; 1329 break;
1336 case Key_E: 1330 case Key_E:
1337 ByeBye(); 1331 ByeBye();
1338 break; 1332 break;
1339 case Key_R: 1333 case Key_R:
1340 // setBookmark(); 1334 // setBookmark();
1341 break; 1335 break;
1342 case Key_T: 1336 case Key_T:
1343 ChangeFont(); 1337 ChangeFont();
1344 break; 1338 break;
1345 case Key_C: 1339 case Key_C:
1346 ClearEdit(); 1340 ClearEdit();
1347 break; 1341 break;
1348 case Key_H: 1342 case Key_H:
1349 HelpBtn(); 1343 HelpBtn();
1350 break; 1344 break;
1351 case Key_K: 1345 case Key_K:
1352 LookupBtn(); 1346 LookupBtn();
1353 break; 1347 break;
1354 case Key_U:// hide menu 1348 case Key_U:// hide menu
1355 if(menubar->isHidden() ) 1349 if(menubar->isHidden() )
1356 menubar->show(); 1350 menubar->show();
1357 else 1351 else
1358 menubar->hide(); 1352 menubar->hide();
1359 break; 1353 break;
1360 case Key_I: 1354 case Key_I:
1361 hideButtons(); 1355 hideButtons();
1362 break; 1356 break;
1363 ////////////////////////////// Zaurus keys 1357 ////////////////////////////// Zaurus keys
1364 case Key_Home: 1358 case Key_Home:
1365 // BeginBtn(); 1359 // BeginBtn();
1366 break; 1360 break;
1367 case Key_F9: //activity 1361 case Key_F9: //activity
1368 OpenBtn(); 1362 OpenBtn();
1369 break; 1363 break;
1370 case Key_F10: //contacts 1364 case Key_F10: //contacts
1371 hideButtons(); 1365 hideButtons();
1372 break; 1366 break;
1373 case Key_F11: //menu 1367 case Key_F11: //menu
1374 if(menubar->isHidden() ) 1368 if(menubar->isHidden() )
1375 menubar->show(); 1369 menubar->show();
1376 else 1370 else
1377 menubar->hide(); 1371 menubar->hide();
1378 break; 1372 break;
1379 case Key_F12: //home 1373 case Key_F12: //home
1380 BeginBtn(); 1374 BeginBtn();
1381 break; 1375 break;
1382 case Key_F13: //mail 1376 case Key_F13: //mail
1383 LibraryBtn(); 1377 LibraryBtn();
1384 break; 1378 break;
1385 case Key_Space: 1379 case Key_Space:
1386 if(loadCheck) 1380 if(loadCheck)
1387 ForwardBtn(); 1381 ForwardBtn();
1388 // else 1382 // else
1389 // Bookmark(); 1383 // Bookmark();
1390 break; 1384 break;
1391 case Key_Down: 1385 case Key_Down:
1392 if(loadCheck) { 1386 if(loadCheck) {
1393 // if( !e->isAutoRepeat() ) 1387 // if( !e->isAutoRepeat() )
1394 // AdjustStatus(); 1388 // AdjustStatus();
1395 // } else { 1389 // } else {
1396 // LibraryBtn(); 1390 // LibraryBtn();
1397 // ForwardBtn(); 1391 // ForwardBtn();
1398 } 1392 }
1399 1393
1400 // ForwardButton->setFocus(); 1394 // ForwardButton->setFocus();
1401 // Lview->setFocus(); 1395 // Lview->setFocus();
1402 // if(s_Wrap=="FALSE") 1396 // if(s_Wrap=="FALSE")
1403 // Lview->MultiLine_Ex::ScrollDown( 1); 1397 // Lview->MultiLine_Ex::ScrollDown( 1);
1404 // LibraryBtn(); 1398 // LibraryBtn();
1405 break; 1399 break;
1406 case Key_Up: 1400 case Key_Up:
1407 if(loadCheck) { 1401 if(loadCheck) {
1408 // if( !e->isAutoRepeat() ) 1402 // if( !e->isAutoRepeat() )
1409 // AdjustStatus(); 1403 // AdjustStatus();
1410 // } else { 1404 // } else {
1411 // OpenBtn(); 1405 // OpenBtn();
1412 // BackBtn(); 1406 // BackBtn();
1413 } 1407 }
1414 // BackButton->setFocus(); 1408 // BackButton->setFocus();
1415 // Lview->setFocus(); 1409 // Lview->setFocus();
1416 // if(s_Wrap=="FALSE") 1410 // if(s_Wrap=="FALSE")
1417 // Lview->MultiLine_Ex::ScrollUp( 1); 1411 // Lview->MultiLine_Ex::ScrollUp( 1);
1418 1412
1419 // LibraryBtn(); 1413 // LibraryBtn();
1420 break; 1414 break;
1421 case Key_Right: 1415 case Key_Right:
1422 ForwardButton->setFocus(); 1416 ForwardButton->setFocus();
1423 ForwardBtn(); 1417 ForwardBtn();
1424 // LibraryBtn(); 1418 // LibraryBtn();
1425 break; 1419 break;
1426 case Key_Left: 1420 case Key_Left:
1427 BackBtn(); 1421 BackBtn();
1428 BackButton->setFocus(); 1422 BackButton->setFocus();
1429 // OpenBtn(); 1423 // OpenBtn();
1430 break; 1424 break;
1431 case Key_Escape: 1425 case Key_Escape:
1432 ByeBye(); 1426 ByeBye();
1433 break; 1427 break;
1434 case Key_PageUp: 1428 case Key_PageUp:
1435 BackBtn(); 1429 BackBtn();
1436 break; 1430 break;
1437 case Key_PageDown: 1431 case Key_PageDown:
1438 ForwardBtn(); 1432 ForwardBtn();
1439 break; 1433 break;
1440 1434
1441 ////////////////////////////// Zaurus keys 1435 ////////////////////////////// Zaurus keys
1442 }; 1436 };
1443} 1437}
1444 1438
1445void Gutenbrowser::keyPressEvent( QKeyEvent *e) { 1439void Gutenbrowser::keyPressEvent( QKeyEvent *e) {
1446 switch ( e->key() ) { 1440 switch ( e->key() ) {
1447 // case Key_Next: 1441 // case Key_Next:
1448 // ForwardBtn(); 1442 // ForwardBtn();
1449 // break; 1443 // break;
1450 // case Key_Prior: 1444 // case Key_Prior:
1451 // BackBtn(); 1445 // BackBtn();
1452 // break; 1446 // break;
1453 // case Key_Space: 1447 // case Key_Space:
1454 // ForwardBtn(); 1448 // ForwardBtn();
1455 // break; 1449 // break;
1456 // case Key_Down: 1450 // case Key_Down:
1457 // Lview->MultiLine_Ex::ScrollUp( 1); 1451 // Lview->MultiLine_Ex::ScrollUp( 1);
1458 // if(useSplitter) Rview->MultiLine_Ex::ScrollUp( 1); 1452 // if(useSplitter) Rview->MultiLine_Ex::ScrollUp( 1);
1459 // break; 1453 // break;
1460 // case Key_Up: 1454 // case Key_Up:
1461 // if( Lview->Top() != 0) { 1455 // if( Lview->Top() != 0) {
1462 // Lview->MultiLine_Ex::ScrollDown( 1); 1456 // Lview->MultiLine_Ex::ScrollDown( 1);
1463 // if(useSplitter) Rview->MultiLine_Ex::ScrollDown( 1); 1457 // if(useSplitter) Rview->MultiLine_Ex::ScrollDown( 1);
1464 // } 1458 // }
1465 // break; 1459 // break;
1466 } 1460 }
1467} 1461}
1468 1462
1469void Gutenbrowser::resizeEvent( QResizeEvent *ev) { 1463void Gutenbrowser::resizeEvent( QResizeEvent *ev) {
1470 // odebug << "resize: " << ev->size().width() << "," << ev->size().height() << "\n" << oendl; 1464 // odebug << "resize: " << ev->size().width() << "," << ev->size().height() << "\n" << oendl;
1471 1465
1472 if( !LibraryDlg->isHidden()) 1466 if( !LibraryDlg->isHidden())
1473 LibraryDlg->resize(ev->size().width(),ev->size().height() ); 1467 LibraryDlg->resize(ev->size().width(),ev->size().height() );
1474 1468
1475 // if( loadCheck == true) { 1469 // if( loadCheck == true) {
1476 // ResizeEdits(); 1470 // ResizeEdits();
1477 // AdjustStatus(); 1471 // AdjustStatus();
1478 // } 1472 // }
1479} 1473}
1480 1474
1481 1475
1482void Gutenbrowser::doOptions() { 1476void Gutenbrowser::doOptions() {
1483 optionsDialog* optDlg; 1477 optionsDialog* optDlg;
1484 optDlg = new optionsDialog( this,"Options_Dlg", true); 1478 optDlg = new optionsDialog( this,"Options_Dlg", true);
1485 QString Ddir; 1479 QString Ddir;
1486 Config config("Gutenbrowser"); 1480 Config config("Gutenbrowser");
1487 config.setGroup( "General" ); 1481 config.setGroup( "General" );
1488 QFont myFont; 1482 QFont myFont;
1489 optDlg->showMaximized(); 1483 optDlg->showMaximized();
1490 1484
1491 if( optDlg->exec() !=0) { 1485 if( optDlg->exec() !=0) {
1492 qApp->processEvents(); 1486 qApp->processEvents();
1493 brow=optDlg->browserName; 1487 brow=optDlg->browserName;
1494 toggleButtonIcons( optDlg->useIcon); 1488 toggleButtonIcons( optDlg->useIcon);
1495 ftp_host= optDlg->ftp_host; 1489 ftp_host= optDlg->ftp_host;
1496 ftp_base_dir= optDlg->ftp_base_dir; 1490 ftp_base_dir= optDlg->ftp_base_dir;
1497 brow=optDlg->browserName; 1491 brow=optDlg->browserName;
1498 Ddir=optDlg->downloadDirEdit->text(); 1492 Ddir=optDlg->downloadDirEdit->text();
1499 1493
1500 odebug << "writing library config" << oendl; 1494 odebug << "writing library config" << oendl;
1501 Config config("Gutenbrowser"); 1495 Config config("Gutenbrowser");
1502 config.setGroup("General"); 1496 config.setGroup("General");
1503 1497
1504 QString dirname= optDlg->downloadDirEdit->text(); 1498 QString dirname= optDlg->downloadDirEdit->text();
1505 if(dirname.right(1)!="/") 1499 if(dirname.right(1)!="/")
1506 dirname+="/"; 1500 dirname+="/";
1507 config.writeEntry( "DownloadDirectory",dirname); 1501 config.writeEntry( "DownloadDirectory",dirname);
1508 QDir newDir( optDlg->downloadDirEdit->text()); 1502 QDir newDir( optDlg->downloadDirEdit->text());
1509 1503
1510 if( !newDir.exists() ) { 1504 if( !newDir.exists() ) {
1511 int exit=QMessageBox::information(this, "Note", "Ok, to make a new directory\n"+Ddir+" ?", 1505 int exit=QMessageBox::information(this, "Note", "Ok, to make a new directory\n"+Ddir+" ?",
1512 QMessageBox::Ok, QMessageBox::Cancel); 1506 QMessageBox::Ok, QMessageBox::Cancel);
1513 if (exit==1) { 1507 if (exit==1) {
1514 QString cmd="mkdir -p "; 1508 QString cmd="mkdir -p ";
1515 cmd+=Ddir.latin1(); 1509 cmd+=Ddir.latin1();
1516 system(cmd); 1510 system(cmd);
1517 odebug << "Making new dir "+cmd << oendl; 1511 odebug << "Making new dir "+cmd << oendl;
1518 if(Ddir.right(1)!="/") { 1512 if(Ddir.right(1)!="/") {
1519 Ddir+="/"; 1513 Ddir+="/";
1520 } 1514 }
1521 config.writeEntry("DownloadDirectory",Ddir); 1515 config.writeEntry("DownloadDirectory",Ddir);
1522 } 1516 }
1523 } 1517 }
1524 1518
1525// if(optDlg->styleChanged) 1519// if(optDlg->styleChanged)
1526// setStyle( optDlg->styleInt); 1520// setStyle( optDlg->styleInt);
1527 if(optDlg->b_qExit==TRUE) 1521 if(optDlg->b_qExit==TRUE)
1528 b_queryExit=TRUE; 1522 b_queryExit=TRUE;
1529 else 1523 else
1530 b_queryExit=FALSE; 1524 b_queryExit=FALSE;
1531 1525
1532 if(optDlg->fontDlg-> changedFonts) { 1526 if(optDlg->fontDlg-> changedFonts) {
1533 odebug << "Setting font" << oendl; 1527 odebug << "Setting font" << oendl;
1534 myFont=optDlg->fontDlg->selectedFont; 1528 myFont=optDlg->fontDlg->selectedFont;
1535 Lview->setFont( myFont); 1529 Lview->setFont( myFont);
1536 } 1530 }
1537 1531
1538 if(optDlg->useWordWrap_CheckBox->isChecked() ) { 1532 if(optDlg->useWordWrap_CheckBox->isChecked() ) {
1539 odebug << "WORD WRAP is set" << oendl; 1533 odebug << "WORD WRAP is set" << oendl;
1540 Lview->setWordWrap(QMultiLineEdit::WidgetWidth); 1534 Lview->setWordWrap(QMultiLineEdit::WidgetWidth);
1541 useWrap=true; 1535 useWrap=true;
1542 } else { 1536 } else {
1543 odebug << "Word wrap is NOT set" << oendl; 1537 odebug << "Word wrap is NOT set" << oendl;
1544 Lview->setWordWrap(QMultiLineEdit::NoWrap); 1538 Lview->setWordWrap(QMultiLineEdit::NoWrap);
1545 useWrap=false; 1539 useWrap=false;
1546 } 1540 }
1547 } 1541 }
1548 if(showMainList) { 1542 if(showMainList) {
1549 if(!Lview->isHidden()) 1543 if(!Lview->isHidden())
1550 Lview->hide(); 1544 Lview->hide();
1551 qApp->processEvents(); 1545 qApp->processEvents();
1552 if(mainList->isHidden()) 1546 if(mainList->isHidden())
1553 mainList->show(); 1547 mainList->show();
1554 fillWithTitles(); 1548 fillWithTitles();
1555 } else { 1549 } else {
1556 Lview->show(); 1550 Lview->show();
1557 showMainList=FALSE; 1551 showMainList=FALSE;
1558 mainList->hide(); 1552 mainList->hide();
1559 } 1553 }
1560 qApp->processEvents(); 1554 qApp->processEvents();
1561 update(); 1555 update();
1562} 1556}
1563 1557
1564bool Gutenbrowser::setTitle() { 1558bool Gutenbrowser::setTitle() {
1565 if( file_name.contains( local_library)) { 1559 if( file_name.contains( local_library)) {
1566 QFileInfo f( file_name); 1560 QFileInfo f( file_name);
1567 QString s_file = f.fileName(); 1561 QString s_file = f.fileName();
1568 file_name = s_file; 1562 file_name = s_file;
1569 } 1563 }
1570 1564
1571 int test = 0; 1565 int test = 0;
1572 Config config("Gutenbrowser"); 1566 Config config("Gutenbrowser");
1573 config.setGroup( "Files" ); 1567 config.setGroup( "Files" );
1574 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" ); 1568 QString s_numofFiles = config.readEntry("NumberOfFiles", "0" );
1575 int i_numofFiles = s_numofFiles.toInt(); 1569 int i_numofFiles = s_numofFiles.toInt();
1576 1570
1577 for (int i = 1; i <= i_numofFiles; i++) { 1571 for (int i = 1; i <= i_numofFiles; i++) {
1578 QString temp; 1572 QString temp;
1579 temp.setNum(i); 1573 temp.setNum(i);
1580 QString ramble = config.readEntry(temp, "" ); 1574 QString ramble = config.readEntry(temp, "" );
1581 1575
1582 if( strcmp(ramble, file_name) == 0) { 1576 if( strcmp(ramble, file_name) == 0) {
1583 test = 1; 1577 test = 1;
1584 } 1578 }
1585 } 1579 }
1586 if (test == 0) { 1580 if (test == 0) {
1587 config.writeEntry("NumberOfFiles",i_numofFiles +1 ); 1581 config.writeEntry("NumberOfFiles",i_numofFiles +1 );
1588 QString interger; 1582 QString interger;
1589 interger.setNum( i_numofFiles +1); 1583 interger.setNum( i_numofFiles +1);
1590 config.writeEntry(interger, file_name); 1584 config.writeEntry(interger, file_name);
1591 1585
1592 config.setGroup( "Titles" ); 1586 config.setGroup( "Titles" );
1593 config.writeEntry(file_name,listItemTitle); 1587 config.writeEntry(file_name,listItemTitle);
1594 } 1588 }
1595 test = 0; 1589 test = 0;
1596 // config.write(); 1590 // config.write();
1597 return true; 1591 return true;
1598} 1592}
1599 /*Calls new fangled network dialog */ 1593 /*Calls new fangled network dialog */
1600void Gutenbrowser::OnNetworkDialog( const QString &/*networkUrl*/, const QString &/*output*/) 1594void Gutenbrowser::OnNetworkDialog( const QString &/*networkUrl*/, const QString &/*output*/)
1601{ 1595{
1602 // odebug << networkUrl << oendl; 1596 // odebug << networkUrl << oendl;
1603 // odebug << output << oendl; 1597 // odebug << output << oendl;
1604 // #ifndef Q_WS_QWS 1598 // #ifndef Q_WS_QWS
1605 // NetworkDialog *NetworkDlg; 1599 // NetworkDialog *NetworkDlg;
1606 // if( networkUrl.length() < 4 ) networkUrl= "http://sailor.gutenberg.org/mirror.sites.html"; 1600 // if( networkUrl.length() < 4 ) networkUrl= "http://sailor.gutenberg.org/mirror.sites.html";
1607 // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, output); 1601 // NetworkDlg = new NetworkDialog( this,"Network Protocol Dialog", TRUE, 0, networkUrl, output);
1608 // if( NetworkDlg->exec() != 0 ) { 1602 // if( NetworkDlg->exec() != 0 ) {
1609 // } 1603 // }
1610 // if(NetworkDlg) 1604 // if(NetworkDlg)
1611 // delete NetworkDlg; 1605 // delete NetworkDlg;
1612 // #endif 1606 // #endif
1613} 1607}
1614 1608
1615void Gutenbrowser::donateGutenberg() 1609void Gutenbrowser::donateGutenberg()
1616{ 1610{
1617 int exit=QMessageBox::information(this, "Info", "http://www.gutenberg.org\ndonate@gutenberg.net", 1611 int exit=QMessageBox::information(this, "Info", "http://www.gutenberg.org\ndonate@gutenberg.net",
1618 QMessageBox::Ok, QMessageBox::Cancel); 1612 QMessageBox::Ok, QMessageBox::Cancel);
1619 1613
1620 if (exit==1) { 1614 if (exit==1) {
1621 } else { 1615 } else {
1622 }; 1616 };
1623} 1617}
1624 1618
1625void Gutenbrowser::donateByteMonkie() 1619void Gutenbrowser::donateByteMonkie()
1626{ 1620{
1627} 1621}
1628 1622
1629void Gutenbrowser::writeConfig() 1623void Gutenbrowser::writeConfig()
1630{ 1624{
1631 // config.read(); 1625 // config.read();
1632 // Config config("Gutenbrowser"); 1626 // Config config("Gutenbrowser");
1633 // #ifndef Q_WS_QWS 1627 // #ifndef Q_WS_QWS
1634 // config.setGroup( "Geometry" ); 1628 // config.setGroup( "Geometry" );
1635 // QString s; 1629 // QString s;
1636 // QString globalPosition; 1630 // QString globalPosition;
1637 // QPoint point; 1631 // QPoint point;
1638 // point=mapToGlobal(QPoint(0,0) ); 1632 // point=mapToGlobal(QPoint(0,0) );
1639 // int posiX, posiY; 1633 // int posiX, posiY;
1640 // posiX=point.x(); 1634 // posiX=point.x();
1641 // posiY=point.y(); 1635 // posiY=point.y();
1642 // globalPosition.sprintf("%i,%i", posiX, posiY); 1636 // globalPosition.sprintf("%i,%i", posiX, posiY);
1643 1637
1644 // QRect frameRect; 1638 // QRect frameRect;
1645 // frameRect = geometry(); 1639 // frameRect = geometry();
1646 // s.sprintf("%i,%i", frameRect.width(), frameRect.height()); 1640 // s.sprintf("%i,%i", frameRect.width(), frameRect.height());
1647 // config.writeEntry("Frame", s); 1641 // config.writeEntry("Frame", s);
1648 // config.writeEntry("Position", globalPosition); 1642 // config.writeEntry("Position", globalPosition);
1649 1643
1650 // if( useIcons==TRUE) 1644 // if( useIcons==TRUE)
1651 // config.writeEntry("Icons", "TRUE"); 1645 // config.writeEntry("Icons", "TRUE");
1652 // else 1646 // else
1653 // config.writeEntry("Icons", "FALSE"); 1647 // config.writeEntry("Icons", "FALSE");
1654 // #endif 1648 // #endif
1655 1649
1656 // #ifndef Q_WS_QWS 1650 // #ifndef Q_WS_QWS
1657 // QString temp; 1651 // QString temp;
1658 // temp.setNum(styleI, 10); 1652 // temp.setNum(styleI, 10);
1659 // config.setGroup( "StyleIze" ); 1653 // config.setGroup( "StyleIze" );
1660 // config.writeEntry( "Style", temp); 1654 // config.writeEntry( "Style", temp);
1661 // #endif 1655 // #endif
1662 1656
1663 // config.setGroup("General"); 1657 // config.setGroup("General");
1664} 1658}
1665 1659
1666void Gutenbrowser::annotations() 1660void Gutenbrowser::annotations()
1667{ 1661{
1668 // #ifndef Q_WS_QWS 1662 // #ifndef Q_WS_QWS
1669 // QMessageBox::message("Note","hi annotate"); 1663 // QMessageBox::message("Note","hi annotate");
1670 // lastBmkButton->setDown(FALSE); 1664 // lastBmkButton->setDown(FALSE);
1671 // #endif 1665 // #endif
1672} 1666}
1673 1667
1674void Gutenbrowser::hideButtons() 1668void Gutenbrowser::hideButtons()
1675{ 1669{
1676 1670
1677 if( !buttonsHidden) { 1671 if( !buttonsHidden) {
1678 buttonsHidden=TRUE; 1672 buttonsHidden=TRUE;
1679 LibraryButton->hide(); 1673 LibraryButton->hide();
1680 SearchButton->hide(); 1674 SearchButton->hide();
1681 InfoBar->hide(); 1675 InfoBar->hide();
1682 OpenButton->hide(); 1676 OpenButton->hide();
1683 BackButton->hide(); 1677 BackButton->hide();
1684 ForwardButton->hide(); 1678 ForwardButton->hide();
1685 setBookmarkButton->hide(); 1679 setBookmarkButton->hide();
1686 lastBmkButton->hide(); 1680 lastBmkButton->hide();
1687 dictionaryButton->hide(); 1681 dictionaryButton->hide();
1688 if(useSplitter) { 1682 if(useSplitter) {
1689 ClearButton->hide(); 1683 ClearButton->hide();
1690 PrintButton->hide(); 1684 PrintButton->hide();
1691 beginButton->hide(); 1685 beginButton->hide();
1692 HelpButton->hide(); 1686 HelpButton->hide();
1693 FontButton->hide(); 1687 FontButton->hide();
1694 ExitButton->hide(); 1688 ExitButton->hide();
1695 OptionsButton->hide(); 1689 OptionsButton->hide();
1696 DownloadButton->hide(); 1690 DownloadButton->hide();
1697 } 1691 }
1698 } else { 1692 } else {
1699 buttonsHidden=FALSE; 1693 buttonsHidden=FALSE;
1700 1694
1701 LibraryButton->show(); 1695 LibraryButton->show();
1702 SearchButton->show(); 1696 SearchButton->show();
1703 InfoBar->show(); 1697 InfoBar->show();
1704 OpenButton->show(); 1698 OpenButton->show();
1705 BackButton->show(); 1699 BackButton->show();
1706 ForwardButton->show(); 1700 ForwardButton->show();
1707 setBookmarkButton->show(); 1701 setBookmarkButton->show();
1708 lastBmkButton->show(); 1702 lastBmkButton->show();
1709 dictionaryButton->show(); 1703 dictionaryButton->show();
1710 if(useSplitter) { 1704 if(useSplitter) {
1711 ClearButton->show(); 1705 ClearButton->show();
1712 PrintButton->show(); 1706 PrintButton->show();
1713 beginButton->show(); 1707 beginButton->show();
1714 HelpButton->show(); 1708 HelpButton->show();
1715 FontButton->show(); 1709 FontButton->show();
1716 ExitButton->show(); 1710 ExitButton->show();
1717 OptionsButton->show(); 1711 OptionsButton->show();
1718 DownloadButton->show(); 1712 DownloadButton->show();
1719 } 1713 }
1720 } 1714 }
1721} 1715}
1722 1716
1723void Gutenbrowser::focusInEvent( QFocusEvent* ) 1717void Gutenbrowser::focusInEvent( QFocusEvent* )
1724{ 1718{
1725} 1719}
1726void Gutenbrowser::focusOutEvent( QFocusEvent* ) 1720void Gutenbrowser::focusOutEvent( QFocusEvent* )
1727{ 1721{
1728} 1722}
1729 1723
1730void Gutenbrowser::cleanUp( ) 1724void Gutenbrowser::cleanUp( )
1731{ 1725{
1732 writeConfig(); 1726 writeConfig();
1733 QPEApplication::grabKeyboard(); 1727 QPEApplication::grabKeyboard();
1734 1728
1735 QPEApplication::ungrabKeyboard(); 1729 QPEApplication::ungrabKeyboard();
1736 // odebug << "Cleanup" << oendl; 1730 // odebug << "Cleanup" << oendl;
1737 if(f.isOpen()) f.close(); 1731 if(f.isOpen()) f.close();
1738} 1732}
1739 1733
1740void Gutenbrowser::fixKeys() 1734void Gutenbrowser::fixKeys()
1741{ 1735{
1742 odebug << "Attempting to fix keys" << oendl; 1736 odebug << "Attempting to fix keys" << oendl;
1743 1737
1744} 1738}
1745 1739
1746void Gutenbrowser::enableButtons(bool b) 1740void Gutenbrowser::enableButtons(bool b)
1747{ 1741{
1748 BackButton->setEnabled(b); 1742 BackButton->setEnabled(b);
1749 ForwardButton->setEnabled(b); 1743 ForwardButton->setEnabled(b);
1750 SearchButton->setEnabled(b); 1744 SearchButton->setEnabled(b);
1751 setBookmarkButton->setEnabled(b); 1745 setBookmarkButton->setEnabled(b);
1752 dictionaryButton->setEnabled(b); 1746 dictionaryButton->setEnabled(b);
1753 InfoBar->setEnabled(b); 1747 InfoBar->setEnabled(b);
1754 1748
1755 editMenu->setItemEnabled( -5, b); 1749 editMenu->setItemEnabled( -5, b);
1756 editMenu->setItemEnabled( -6, b); 1750 editMenu->setItemEnabled( -6, b);
1757 editMenu->setItemEnabled( -7, b); 1751 editMenu->setItemEnabled( -7, b);
1758 editMenu->setItemEnabled( -8, b); 1752 editMenu->setItemEnabled( -8, b);
1759 1753
1760} 1754}
1761 1755
1762void Gutenbrowser::fillWithTitles() { 1756void Gutenbrowser::fillWithTitles() {
1763 Config config("Gutenbrowser"); 1757 Config config("Gutenbrowser");
1764 config.setGroup( "Files" ); 1758 config.setGroup( "Files" );
1765 int i_numofFiles = config.readNumEntry("NumberOfFiles", 0); 1759 int i_numofFiles = config.readNumEntry("NumberOfFiles", 0);
1766 mainList->clear(); 1760 mainList->clear();
1767 QString temp; 1761 QString temp;
1768 for (int i = 1; i <= i_numofFiles; i++) { 1762 for (int i = 1; i <= i_numofFiles; i++) {
1769 temp.setNum(i); 1763 temp.setNum(i);
1770 config.setGroup( "Files" ); 1764 config.setGroup( "Files" );
1771 QString ramble = config.readEntry(temp, "" ); 1765 QString ramble = config.readEntry(temp, "" );
1772 config.setGroup( "Titles" ); 1766 config.setGroup( "Titles" );
1773 temp = config.readEntry(ramble, ""); 1767 temp = config.readEntry(ramble, "");
1774 if( !temp.isEmpty()) { 1768 if( !temp.isEmpty()) {
1775 mainList->insertItem ( Opie::Core::OResource::loadPixmap("gutenbrowser/gutenbrowser_sm", 1769 mainList->insertItem ( Opie::Core::OResource::loadPixmap("gutenbrowser/gutenbrowser_sm",
1776 Opie::Core::OResource::SmallIcon ), temp, -1); 1770 Opie::Core::OResource::SmallIcon ), temp, -1);
1777 } 1771 }
1778 } 1772 }
1779} 1773}
1780 1774
1781void Gutenbrowser::listClickedSlot( QListBoxItem * index) { 1775void Gutenbrowser::listClickedSlot( QListBoxItem * index) {
1782 // if( !working) { 1776 // if( !working) {
1783 // working=true; 1777 // working=true;
1784 if(index) { 1778 if(index) {
1785 // QCopEnvelope ( "QPE/System", "busy()" ); 1779 // QCopEnvelope ( "QPE/System", "busy()" );
1786 title = index->text(); 1780 title = index->text();
1787 showMainList=FALSE; 1781 showMainList=FALSE;
1788 mainList->hide(); 1782 mainList->hide();
1789 Lview->show(); 1783 Lview->show();
1790 qApp->processEvents(); 1784 qApp->processEvents();
1791 QString temp; 1785 QString temp;
1792 temp.setNum( mainList->currentItem() + 1); 1786 temp.setNum( mainList->currentItem() + 1);
1793 // openFileTitle = title; 1787 // openFileTitle = title;
1794 Config config("Gutenbrowser"); 1788 Config config("Gutenbrowser");
1795 config.setGroup( "Files" ); 1789 config.setGroup( "Files" );
1796 QString file = config.readEntry(temp, ""); 1790 QString file = config.readEntry(temp, "");
1797 odebug << "About to load" << oendl; 1791 odebug << "About to load" << oendl;
1798 if( Lview->isVisible()) 1792 if( Lview->isVisible())
1799 if(!load(file)) return; 1793 if(!load(file)) return;
1800 1794
1801 config.setGroup( title); 1795 config.setGroup( title);
1802 file_name = config.readEntry("File Name", ""); 1796 file_name = config.readEntry("File Name", "");
1803 i_pageNum = config.readNumEntry("Page Number", 1); 1797 i_pageNum = config.readNumEntry("Page Number", 1);
1804 int Bmrkrow = config.readNumEntry("LineNumber", -1); 1798 int Bmrkrow = config.readNumEntry("LineNumber", -1);
1805 if(Bmrkrow > -1) { 1799 if(Bmrkrow > -1) {
1806 if( Bmrkrow > Lview->topRow() ) { 1800 if( Bmrkrow > Lview->topRow() ) {
1807// Lview->setCursorPosition( Bmrkrow /* - Lview->topRow() */,0, FALSE ); 1801// Lview->setCursorPosition( Bmrkrow /* - Lview->topRow() */,0, FALSE );
1808 Lview->ScrollUp( Bmrkrow - Lview->topRow() ); 1802 Lview->ScrollUp( Bmrkrow - Lview->topRow() );
1809 // AdjustStatus(); 1803 // AdjustStatus();
1810 } 1804 }
1811 else if( Bmrkrow < Lview->topRow() ) { 1805 else if( Bmrkrow < Lview->topRow() ) {
1812// Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE ); 1806// Lview->setCursorPosition( Lview->topRow() - Bmrkrow ,0, FALSE );
1813 Lview->ScrollDown( Lview->topRow() - Bmrkrow ); 1807 Lview->ScrollDown( Lview->topRow() - Bmrkrow );
1814 // AdjustStatus(); 1808 // AdjustStatus();
1815 } 1809 }
1816 } 1810 }
1817 } 1811 }
1818} 1812}
1819 1813
1820void Gutenbrowser::infoGutenbrowser() { 1814void Gutenbrowser::infoGutenbrowser() {
1821 QMessageBox::message("Info","Gutenbrowser was developed by\n" 1815 QMessageBox::message("Info","Gutenbrowser was developed by\n"
1822 "Lorn Potter\n" 1816 "Lorn Potter\n"
1823 "ljp<ljp@llornkcor.com>\n"); 1817 "ljp<ljp@llornkcor.com>\n");
1824} 1818}
1825 1819
1826void Gutenbrowser::setDocument(const QString & frozenBoogers) { 1820void Gutenbrowser::setDocument(const QString & frozenBoogers) {
1827 // this->hide(); 1821 // this->hide();
1828 qWarning("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSET DOCUMENT\n"); 1822 qWarning("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXSET DOCUMENT\n");
1829 if(showMainList) { 1823 if(showMainList) {
1830 showMainList=FALSE; 1824 showMainList=FALSE;
1831 if(!mainList->isHidden()) 1825 if(!mainList->isHidden())
1832 mainList->hide(); 1826 mainList->hide();
1833 if(Lview->isHidden()) 1827 if(Lview->isHidden())
1834 Lview->show(); 1828 Lview->show();
1835 qApp->processEvents(); 1829 qApp->processEvents();
1836 } 1830 }
1837 DocLnk lnk; 1831 DocLnk lnk;
1838 lnk = DocLnk(frozenBoogers); 1832 lnk = DocLnk(frozenBoogers);
1839 qWarning("open "+frozenBoogers); 1833 qWarning("open "+frozenBoogers);
1840 // odebug << lnk.file() << oendl; 1834 // odebug << lnk.file() << oendl;
1841 title=lnk.comment(); 1835 title=lnk.comment();
1842 if(!load( lnk.file())) return; 1836 if(!load( lnk.file())) return;
1843 this->show(); 1837 this->show();
1844 // odebug << title << oendl; 1838 // odebug << title << oendl;
1845 // qApp->processEvents(); 1839 // qApp->processEvents();
1846 // repaint(); 1840 // repaint();
1847} 1841}
1848 1842
1849void Gutenbrowser::mainListPressed(int mouse, QListBoxItem * , const QPoint & ) 1843void Gutenbrowser::mainListPressed(int mouse, QListBoxItem * , const QPoint & )
1850{ 1844{
1851 switch (mouse) { 1845 switch (mouse) {
1852 case 1: 1846 case 1:
1853 break; 1847 break;
1854 case 2: { 1848 case 2: {
1855 QPopupMenu m;// = new QPopupMenu( Local_View ); 1849 QPopupMenu m;// = new QPopupMenu( Local_View );
1856 m.insertItem( tr( "Open" ), this, SLOT( menuOpen() )); 1850 m.insertItem( tr( "Open" ), this, SLOT( menuOpen() ));
1857 m.insertSeparator(); 1851 m.insertSeparator();
1858 m.insertItem( tr( "Search google.com" ), this, SLOT( menuGoogle())); 1852 m.insertItem( tr( "Search google.com" ), this, SLOT( menuGoogle()));
1859 m.insertItem( tr( "Edit Title" ), this, SLOT( menuEditTitle())); 1853 m.insertItem( tr( "Edit Title" ), this, SLOT( menuEditTitle()));
1860 // m.insertSeparator(); 1854 // m.insertSeparator();
1861 // m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); 1855 // m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() ));
1862 m.exec( QCursor::pos() ); 1856 m.exec( QCursor::pos() );
1863 } 1857 }
1864 break; 1858 break;
1865 }; 1859 };
1866} 1860}
1867 1861
1868void Gutenbrowser::menuOpen() { 1862void Gutenbrowser::menuOpen() {
1869 listClickedSlot( mainList->item( mainList->currentItem())); 1863 listClickedSlot( mainList->item( mainList->currentItem()));
1870} 1864}
1871 1865
1872void Gutenbrowser::menuGoogle() { 1866void Gutenbrowser::menuGoogle() {
1873 searchGoogle( mainList->text(mainList->currentItem())); 1867 searchGoogle( mainList->text(mainList->currentItem()));
1874} 1868}
1875 1869
1876void Gutenbrowser::searchGoogle( const QString &tempText) { 1870void Gutenbrowser::searchGoogle( const QString &tempText) {
1877 QString text = tempText; 1871 QString text = tempText;
1878 1872
1879 int eexit=QMessageBox::information(this, "Note","Do you want to search for\n"+text+ 1873 int eexit=QMessageBox::information(this, "Note","Do you want to search for\n"+text+
1880 "\non google.com?",QMessageBox::Yes, QMessageBox::No); 1874 "\non google.com?",QMessageBox::Yes, QMessageBox::No);
1881 if (eexit== 3) { 1875 if (eexit== 3) {
1882 qApp->processEvents(); 1876 qApp->processEvents();
1883 text.replace( QRegExp("\\s"), "%20"); 1877 text.replace( QRegExp("\\s"), "%20");
1884 text.replace( QRegExp("#"), ""); 1878 text.replace( QRegExp("#"), "");
1885 text.replace( QRegExp(","), "%20"); 1879 text.replace( QRegExp(","), "%20");
1886 text.replace( QRegExp("'"), "%20"); 1880 text.replace( QRegExp("'"), "%20");
1887 text.replace( QRegExp("("), ""); 1881 text.replace( QRegExp("("), "");
1888 text.replace( QRegExp(")"), ""); 1882 text.replace( QRegExp(")"), "");
1889 // text.replace( QRegExp("[0-9]"), ""); 1883 // text.replace( QRegExp("[0-9]"), "");
1890 QString s_lookup = "http://google.com/search?q="+text+"&num=30&sa=Google+Search"; 1884 QString s_lookup = "http://google.com/search?q="+text+"&num=30&sa=Google+Search";
1891 goGetit( s_lookup, true); 1885 goGetit( s_lookup, true);
1892 } 1886 }
1893 1887
1894} 1888}
1895 1889
1896void Gutenbrowser::menuEditTitle() 1890void Gutenbrowser::menuEditTitle()
1897{ 1891{
1898 int currentItem = mainList->currentItem(); 1892 int currentItem = mainList->currentItem();
1899 QString title_text = mainList->text( currentItem); 1893 QString title_text = mainList->text( currentItem);
1900 //odebug << "Selected "+title_text << oendl; 1894 //odebug << "Selected "+title_text << oendl;
1901 1895
1902 Config config("Gutenbrowser"); 1896 Config config("Gutenbrowser");
1903 config.setGroup( "Files" ); 1897 config.setGroup( "Files" );
1904 QString s_numofFiles = config.readEntry("NumberOfFiles", "0"); 1898 QString s_numofFiles = config.readEntry("NumberOfFiles", "0");
1905 int i_numofFiles = s_numofFiles.toInt(); 1899 int i_numofFiles = s_numofFiles.toInt();
1906 QString fileNum; 1900 QString fileNum;
1907 for (int i = 1; i <= i_numofFiles+1; i++) { 1901 for (int i = 1; i <= i_numofFiles+1; i++) {
1908 1902
1909 fileNum.setNum(i); 1903 fileNum.setNum(i);
1910 config.setGroup( "Files" ); 1904 config.setGroup( "Files" );
1911 QString s_filename = config.readEntry(fileNum, "" ); 1905 QString s_filename = config.readEntry(fileNum, "" );
1912 config.setGroup( "Titles" ); 1906 config.setGroup( "Titles" );
1913 QString file_title = config.readEntry( s_filename, ""); 1907 QString file_title = config.readEntry( s_filename, "");
1914 //odebug << "file_title is "+file_title << oendl; 1908 //odebug << "file_title is "+file_title << oendl;
1915 if(title_text == file_title ) { 1909 if(title_text == file_title ) {
1916 // selFile = s_filename; 1910 // selFile = s_filename;
1917 //odebug << "Edit: "+ file_title << oendl; 1911 //odebug << "Edit: "+ file_title << oendl;
1918 i=i_numofFiles+1; 1912 i=i_numofFiles+1;
1919 Edit_Title *titleEdit; 1913 Edit_Title *titleEdit;
1920 titleEdit = new Edit_Title(this,file_title ,TRUE); 1914 titleEdit = new Edit_Title(this,file_title ,TRUE);
1921 if(titleEdit->exec() !=0) { 1915 if(titleEdit->exec() !=0) {
1922 //odebug << titleEdit->newTitle << oendl; 1916 //odebug << titleEdit->newTitle << oendl;
1923 config.writeEntry( s_filename, titleEdit->newTitle); 1917 config.writeEntry( s_filename, titleEdit->newTitle);
1924 mainList->removeItem(currentItem); 1918 mainList->removeItem(currentItem);
1925 mainList->insertItem ( Opie::Core::OResource::loadPixmap("gutenbrowser/gutenbrowser_sm", 1919 mainList->insertItem ( Opie::Core::OResource::loadPixmap("gutenbrowser/gutenbrowser_sm",
1926 Opie::Core::OResource::SmallIcon ), titleEdit->newTitle, currentItem); 1920 Opie::Core::OResource::SmallIcon ), titleEdit->newTitle, currentItem);
1927 } 1921 }
1928 } 1922 }
1929 } 1923 }
1930 1924
1931 // getTitles(); 1925 // getTitles();
1932 mainList->triggerUpdate(true); 1926 mainList->triggerUpdate(true);
1933 1927
1934} 1928}
1935 1929
1936 1930
1937 1931
1938bool Gutenbrowser::UnZipIt(const QString &zipFile) { 1932bool Gutenbrowser::UnZipIt(const QString &zipFile) {
1939 odebug << zipFile << oendl; 1933 odebug << zipFile << oendl;
1940#ifndef Q_WS_QWS 1934#ifndef Q_WS_QWS
1941 if( QFile::exists( zipFile)) { // TODO findsome other way of dealingwithzip files. 1935 if( QFile::exists( zipFile)) { // TODO findsome other way of dealingwithzip files.
1942 bool isPgWhole=false; 1936 bool isPgWhole=false;
1943 QString thatFile; 1937 QString thatFile;
1944 if(zipFile.find("pgwhole",0,TRUE)) { 1938 if(zipFile.find("pgwhole",0,TRUE)) {
1945 isPgWhole=TRUE; 1939 isPgWhole=TRUE;
1946 thatFile= local_library +"PGWHOLE.TXT"; 1940 thatFile= local_library +"PGWHOLE.TXT";
1947 } 1941 }
1948 // else { 1942 // else {
1949 // thatFile=zipFile.left(4); 1943 // thatFile=zipFile.left(4);
1950 // } 1944 // }
1951 // odebug << (const char*)local_library.latin1() << oendl; 1945 // odebug << (const char*)local_library.latin1() << oendl;
1952 QString cmd; 1946 QString cmd;
1953#if defined(_WS_X11_) 1947#if defined(_WS_X11_)
1954 if( chdir((const char*)local_library.latin1())!=0) 1948 if( chdir((const char*)local_library.latin1())!=0)
1955 odebug << "chdir failed." << oendl; 1949 odebug << "chdir failed." << oendl;
1956 cmd = "gunzip -S .zip " + local_library+zipFile; 1950 cmd = "gunzip -S .zip " + local_library+zipFile;
1957 //cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library; 1951 //cmd = "gunzip -d " + zipFile /*newestLibraryFile */+" -d " + local_library;
1958#endif 1952#endif
1959#ifdef Q_WS_QWS 1953#ifdef Q_WS_QWS
1960 if( chdir((const char*)local_library.latin1())!=0) 1954 if( chdir((const char*)local_library.latin1())!=0)
1961 odebug << "chdir failed." << oendl; 1955 odebug << "chdir failed." << oendl;
1962 cmd = "unzip " + local_library+zipFile; 1956 cmd = "unzip " + local_library+zipFile;
1963 // cmd = "/usr/bin/unzip -o " + local_library+zipFile +" -d /usr/share/doc/gutenbrowser" ;//+ local_library; 1957 // cmd = "/usr/bin/unzip -o " + local_library+zipFile +" -d /usr/share/doc/gutenbrowser" ;//+ local_library;
1964#endif 1958#endif
1965 int exit=QMessageBox::information(this, "Ok to unzip?", 1959 int exit=QMessageBox::information(this, "Ok to unzip?",
1966 "Ok to unnzip\n"+ zipFile+" ?", 1960 "Ok to unnzip\n"+ zipFile+" ?",
1967 QMessageBox::Yes, QMessageBox::No); 1961 QMessageBox::Yes, QMessageBox::No);
1968 if (exit==QMessageBox::Yes) { 1962 if (exit==QMessageBox::Yes) {
1969#if defined(_WS_X11_)// 1963#if defined(_WS_X11_)//
1970 odebug << "Issuing the command "+cmd << oendl; 1964 odebug << "Issuing the command "+cmd << oendl;
1971 system( cmd); 1965 system( cmd);
1972 if( QFile::exists(thatFile)) 1966 if( QFile::exists(thatFile))
1973 remove (thatFile); 1967 remove (thatFile);
1974 if(isPgWhole) { 1968 if(isPgWhole) {
1975 if( rename("pgwhole","PGWHOLE.TXT") !=0) 1969 if( rename("pgwhole","PGWHOLE.TXT") !=0)
1976 odebug << "rename failed" << oendl; 1970 odebug << "rename failed" << oendl;
1977 } else { 1971 } else {
1978 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0) 1972 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0)
1979 odebug << "rename failed" << oendl; 1973 odebug << "rename failed" << oendl;
1980 } 1974 }
1981#endif 1975#endif
1982#ifdef Q_WS_QWS 1976#ifdef Q_WS_QWS
1983 odebug << "Issuing the command "+cmd << oendl; 1977 odebug << "Issuing the command "+cmd << oendl;
1984 system( cmd); 1978 system( cmd);
1985 if( QFile::exists(thatFile)) 1979 if( QFile::exists(thatFile))
1986 remove(thatFile); 1980 remove(thatFile);
1987 if(isPgWhole) { 1981 if(isPgWhole) {
1988 if( rename("pgwhole","PGWHOLE.TXT") !=0) 1982 if( rename("pgwhole","PGWHOLE.TXT") !=0)
1989 odebug << "rename failed" << oendl; 1983 odebug << "rename failed" << oendl;
1990 } else { 1984 } else {
1991 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0) 1985 if( rename(thatFile.left(4),thatFile.left(4)+".txt") !=0)
1992 odebug << "rename failed" << oendl; 1986 odebug << "rename failed" << oendl;
1993 } 1987 }
1994#endif 1988#endif
1995 // remove( zipFile); 1989 // remove( zipFile);
1996 return true; 1990 return true;
1997 } 1991 }
1998 else if(exit==QMessageBox::No) { 1992 else if(exit==QMessageBox::No) {
1999 // odebug << "unzip" << oendl; 1993 // odebug << "unzip" << oendl;
2000 return false; 1994 return false;
2001 } 1995 }
2002 } 1996 }
2003 else 1997 else
2004 QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) ); 1998 QMessageBox::message( "Note",( tr("Please install unzip in your PATH")) );
2005#endif 1999#endif
2006 return false; 2000 return false;
2007} 2001}
2008 2002
2009 2003
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
@@ -1,333 +1,331 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5** 5**
6** This file is part of an example program for Qt. This example 6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation. 7** program may be used, distributed and modified without limitation.
8** 8**
9 copyright : (C) 2000 -2004 by llornkcor 9 copyright : (C) 2000 -2004 by llornkcor
10 email : ljp@llornkcor.com 10 email : ljp@llornkcor.com
11*****************************************************************************/ 11*****************************************************************************/
12 12
13#include "helpwindow.h" 13#include "helpwindow.h"
14 14
15#include <qpe/global.h> 15#include <qpe/global.h>
16 16
17#include <qstatusbar.h> 17#include <qstatusbar.h>
18 18
19#include <qmenubar.h> 19#include <qmenubar.h>
20#include <qtoolbar.h> 20#include <qtoolbar.h>
21#include <qtoolbutton.h> 21#include <qtoolbutton.h>
22#include <qcombobox.h> 22#include <qcombobox.h>
23 23
24#ifndef QT_NO_FILEDIALOG 24#ifndef QT_NO_FILEDIALOG
25#include <qfiledialog.h> 25#include <qfiledialog.h>
26#endif 26#endif
27 27
28#include <ctype.h> 28#include <ctype.h>
29 29
30HelpWindow::HelpWindow( const QString& home_, const QString&, QWidget* parent, const char *name ) 30HelpWindow::HelpWindow( const QString& home_, const QString&, QWidget* parent, const char *name )
31 : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL() 31 : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL()
32{ 32{
33 QString local_library = Global::applicationFileName("gutenbrowser", QString::null); 33 QString local_library = Global::applicationFileName("gutenbrowser", QString::null);
34// readHistory(); 34// readHistory();
35// readBookmarks(); 35// readBookmarks();
36 36
37 browser = new QTextBrowser( this ); 37 browser = new QTextBrowser( this );
38 QStringList Strlist; 38 QStringList Strlist;
39 Strlist.append( home_); 39 Strlist.append( home_);
40 browser->mimeSourceFactory()->setFilePath( Strlist ); 40 browser->mimeSourceFactory()->setFilePath( Strlist );
41 41
42 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 42 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
43 43
44 connect(browser,SIGNAL(textChanged()),this,SLOT(textChanged())); 44 connect(browser,SIGNAL(textChanged()),this,SLOT(textChanged()));
45 45
46 setCentralWidget( browser ); 46 setCentralWidget( browser );
47 47
48 if ( !home_.isEmpty() ) 48 if ( !home_.isEmpty() )
49 49
50//////////////////////////////// 50////////////////////////////////
51 browser->setSource( home_ ); 51 browser->setSource( home_ );
52 52
53//////////////////////////////// 53////////////////////////////////
54 connect( browser, SIGNAL( highlighted( const QString&) ), 54 connect( browser, SIGNAL( highlighted( const QString&) ),
55 statusBar(), SLOT( message( const QString&)) ); 55 statusBar(), SLOT( message( const QString&)) );
56 56
57// resize( 640,600 ); 57// resize( 640,600 );
58#ifdef Q_WS_QWS 58#ifdef Q_WS_QWS
59 setGeometry( 0,0,236,280); 59 setGeometry( 0,0,236,280);
60#else 60#else
61 setGeometry( 10,30,520,420 ); 61 setGeometry( 10,30,520,420 );
62// resize(520,420); 62// resize(520,420);
63#endif 63#endif
64 64
65 QPopupMenu* file = new QPopupMenu( this ); 65 QPopupMenu* file = new QPopupMenu( this );
66// file->insertItem( tr("&New Window"), this, SLOT( newWindow() ), ALT | Key_N ); 66// file->insertItem( tr("&New Window"), this, SLOT( newWindow() ), ALT | Key_N );
67 file->insertItem( tr("&Open File"), this, SLOT( openFile() ), ALT | Key_O ); 67 file->insertItem( tr("&Open File"), this, SLOT( openFile() ), ALT | Key_O );
68// file->insertItem( tr("&Print"), this, SLOT( print() ), ALT | Key_P ); 68// file->insertItem( tr("&Print"), this, SLOT( print() ), ALT | Key_P );
69 file->insertSeparator(); 69 file->insertSeparator();
70 file->insertItem( tr("&Close"), this, SLOT( close() ), ALT | Key_Q ); 70 file->insertItem( tr("&Close"), this, SLOT( close() ), ALT | Key_Q );
71// file->insertItem( tr("E&xit"), qApp, SLOT( closeAllWindows() ), ALT | Key_X ); 71// file->insertItem( tr("E&xit"), qApp, SLOT( closeAllWindows() ), ALT | Key_X );
72 72
73 // The same three icons are used twice each. 73 // The same three icons are used twice each.
74////F FIXME 74////F FIXME
75 QString pixs=(QDir::homeDirPath ()) +"/Applications/gutenbrowser/pix/"; 75 QString pixs=(QDir::homeDirPath ()) +"/Applications/gutenbrowser/pix/";
76 QIconSet icon_back( QPixmap(pixs+"back.png") ); 76 QIconSet icon_back( QPixmap(pixs+"back.png") );
77 QIconSet icon_forward( QPixmap(pixs+"forward.png") ); 77 QIconSet icon_forward( QPixmap(pixs+"forward.png") );
78 QIconSet icon_home( QPixmap(pixs+"home.png") ); 78 QIconSet icon_home( QPixmap(pixs+"home.png") );
79 79
80 QPopupMenu* go = new QPopupMenu( this ); 80 QPopupMenu* go = new QPopupMenu( this );
81 backwardId = go->insertItem( icon_back, tr("&Backward"), browser, SLOT( backward() ), ALT | Key_Left ); 81 backwardId = go->insertItem( icon_back, tr("&Backward"), browser, SLOT( backward() ), ALT | Key_Left );
82 forwardId = go->insertItem( icon_forward, tr("&Forward"), browser, SLOT( forward() ), ALT | Key_Right ); 82 forwardId = go->insertItem( icon_forward, tr("&Forward"), browser, SLOT( forward() ), ALT | Key_Right );
83 go->insertItem( icon_home, tr("&Home"), browser, SLOT( home() ) ); 83 go->insertItem( icon_home, tr("&Home"), browser, SLOT( home() ) );
84 84
85// QPopupMenu* help = new QPopupMenu( this ); 85// QPopupMenu* help = new QPopupMenu( this );
86// help->insertItem( tr("&About ..."), this, SLOT( about() ) ); 86// help->insertItem( tr("&About ..."), this, SLOT( about() ) );
87// help->insertItem( tr("About &Qt ..."), this, SLOT( aboutQt() ) ); 87// help->insertItem( tr("About &Qt ..."), this, SLOT( aboutQt() ) );
88 88
89 89
90 hist = new QPopupMenu( this ); 90 hist = new QPopupMenu( this );
91 QStringList::Iterator it = history.begin(); 91 QStringList::Iterator it = history.begin();
92 for ( ; it != history.end(); ++it ) 92 for ( ; it != history.end(); ++it )
93 mHistory[ hist->insertItem( *it ) ] = *it; 93 mHistory[ hist->insertItem( *it ) ] = *it;
94 connect( hist, SIGNAL( activated( int ) ), this, SLOT( histChosen( int ) ) ); 94 connect( hist, SIGNAL( activated( int ) ), this, SLOT( histChosen( int ) ) );
95 95
96 bookm = new QPopupMenu( this ); 96 bookm = new QPopupMenu( this );
97 bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); 97 bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) );
98 bookm->insertSeparator(); 98 bookm->insertSeparator();
99 99
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
@@ -1,1346 +1,1350 @@
1/***************************************************************************/ 1/***************************************************************************/
2/* ftplib.c - callable ftp access routines */ 2/* ftplib.c - callable ftp access routines */
3/* Copyright (C) 1996-2000 Thomas Pfau, pfau@cnj.digex.net */ 3/* Copyright (C) 1996-2000 Thomas Pfau, pfau@cnj.digex.net */
4/* 73 Catherine Street, South Bound Brook, NJ, 08880 */ 4/* 73 Catherine Street, South Bound Brook, NJ, 08880 */
5/* */ 5/* */
6/* This library is free software; you can redistribute it and/or */ 6/* This library is free software; you can redistribute it and/or */
7/* modify it under the terms of the GNU Library General Public */ 7/* modify it under the terms of the GNU Library General Public */
8/* License as published by the Free Software Foundation; either */ 8/* License as published by the Free Software Foundation; either */
9/* version 2 of the License, or (at your option) any later version. */ 9/* version 2 of the License, or (at your option) any later version. */
10/* */ 10/* */
11/* This library is distributed in the hope that it will be useful, */ 11/* This library is distributed in the hope that it will be useful, */
12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
14/* Library General Public License for more details. */ 14/* Library General Public License for more details. */
15/* */ 15/* */
16/* You should have received a copy of the GNU Library General Public */ 16/* You should have received a copy of the GNU Library General Public */
17/* License along with this progam; if not, write to the */ 17/* License along with this progam; if not, write to the */
18/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ 18/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
19/* Boston, MA 02111-1307, USA. */ 19/* Boston, MA 02111-1307, USA. */
20/* */ 20/* */
21/***************************************************************************/ 21/***************************************************************************/
22// changes made by Lorn Potter <llornkcor@handhelds.org> 22// changes made by Lorn Potter <llornkcor@handhelds.org>
23// 23//
24#if defined(__unix__) || defined(__VMS) 24#if defined(__unix__) || defined(__VMS)
25#include <unistd.h> 25#include <unistd.h>
26#endif 26#endif
27#if defined(_WIN32) 27#if defined(_WIN32)
28#include <windows.h> 28#include <windows.h>
29#endif 29#endif
30 30
31#include <stdio.h> 31#include <stdio.h>
32#include <stdlib.h> 32#include <stdlib.h>
33#include <string.h> 33#include <string.h>
34#include <errno.h> 34#include <errno.h>
35#include <ctype.h> 35#include <ctype.h>
36 36
37#if defined(__unix__) 37#if defined(__unix__)
38 38
39#include <sys/types.h> 39#include <sys/types.h>
40#include <unistd.h> 40#include <unistd.h>
41#include <fcntl.h> 41#include <fcntl.h>
42#include <sys/time.h> 42#include <sys/time.h>
43#include <sys/types.h> 43#include <sys/types.h>
44#include <sys/socket.h> 44#include <sys/socket.h>
45#include <netinet/in.h> 45#include <netinet/in.h>
46#include <netdb.h> 46#include <netdb.h>
47#include <arpa/inet.h> 47#include <arpa/inet.h>
48 48
49#elif defined(VMS) 49#elif defined(VMS)
50 50
51#include <types.h> 51#include <types.h>
52#include <socket.h> 52#include <socket.h>
53#include <in.h> 53#include <in.h>
54#include <netdb.h> 54#include <netdb.h>
55#include <inet.h> 55#include <inet.h>
56 56
57#elif defined(_WIN32) 57#elif defined(_WIN32)
58 58
59#include <winsock.h> 59#include <winsock.h>
60 60
61#endif 61#endif
62 62
63#define BUILDING_LIBRARY 63#define BUILDING_LIBRARY
64#include "ftplib.h" 64#include "ftplib.h"
65 65
66#if defined(_WIN32) 66#if defined(_WIN32)
67#define SETSOCKOPT_OPTVAL_TYPE (const char *) 67#define SETSOCKOPT_OPTVAL_TYPE (const char *)
68#else 68#else
69#define SETSOCKOPT_OPTVAL_TYPE (void *) 69#define SETSOCKOPT_OPTVAL_TYPE (void *)
70#endif 70#endif
71 71
72#define FTPLIB_BUFSIZ 8192 72#define FTPLIB_BUFSIZ 8192
73#define ACCEPT_TIMEOUT 10 73#define ACCEPT_TIMEOUT 10
74 74
75#define FTPLIB_CONTROL 0 75#define FTPLIB_CONTROL 0
76#define FTPLIB_READ 1 76#define FTPLIB_READ 1
77#define FTPLIB_WRITE 2 77#define FTPLIB_WRITE 2
78 78
79#if !defined FTPLIB_DEFMODE 79#if !defined FTPLIB_DEFMODE
80#define FTPLIB_DEFMODE FTPLIB_PASSIVE 80#define FTPLIB_DEFMODE FTPLIB_PASSIVE
81#endif 81#endif
82 82
83struct NetBuf { 83struct NetBuf {
84 char *cput,*cget; 84 char *cput,*cget;
85 int handle; 85 int handle;
86 int cavail,cleft; 86 int cavail,cleft;
87 char *buf; 87 char *buf;
88 int dir; 88 int dir;
89 netbuf *ctrl; 89 netbuf *ctrl;
90 netbuf *data; 90 netbuf *data;
91 int cmode; 91 int cmode;
92 struct timeval idletime; 92 struct timeval idletime;
93 FtpCallback idlecb; 93 FtpCallback idlecb;
94 void *idlearg; 94 void *idlearg;
95 int xfered; 95 int xfered;
96 int cbbytes; 96 int cbbytes;
97 int xfered1; 97 int xfered1;
98 char response[256]; 98 char response[256];
99}; 99};
100 100
101static char *version = 101static char *version =
102"ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau"; 102"ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau";
103 103
104GLOBALDEF int ftplib_debug = 0; 104GLOBALDEF int ftplib_debug = 0;
105 105
106#if defined(__unix__) || defined(VMS) 106#if defined(__unix__) || defined(VMS)
107#define net_read read 107#define net_read read
108#define net_write write 108#define net_write write
109#define net_close close 109#define net_close close
110#elif defined(_WIN32) 110#elif defined(_WIN32)
111#define net_read(x,y,z) recv(x,y,z,0) 111#define net_read(x,y,z) recv(x,y,z,0)
112#define net_write(x,y,z) send(x,y,z,0) 112#define net_write(x,y,z) send(x,y,z,0)
113#define net_close closesocket 113#define net_close closesocket
114#endif 114#endif
115 115
116#if defined(NEED_MEMCCPY) 116#if defined(NEED_MEMCCPY)
117/* 117/*
118 * VAX C does not supply a memccpy routine so I provide my own 118 * VAX C does not supply a memccpy routine so I provide my own
119 */ 119 */
120void *memccpy(void *dest, const void *src, int c, size_t n) 120void *memccpy(void *dest, const void *src, int c, size_t n)
121{ 121{
122 int i=0; 122 int i=0;
123 const unsigned char *ip=src; 123 const unsigned char *ip=src;
124 unsigned char *op=dest; 124 unsigned char *op=dest;
125 125
126 while (i < n) 126 while (i < n)
127 { 127 {
128 if ((*op++ = *ip++) == c) 128 if ((*op++ = *ip++) == c)
129 break; 129 break;
130 i++; 130 i++;
131 } 131 }
132 if (i == n) 132 if (i == n)
133 return NULL; 133 return NULL;
134 return op; 134 return op;
135} 135}
136#endif 136#endif
137#if defined(NEED_STRDUP) 137#if defined(NEED_STRDUP)
138/* 138/*
139 * strdup - return a malloc'ed copy of a string 139 * strdup - return a malloc'ed copy of a string
140 */ 140 */
141char *strdup(const char *src) 141char *strdup(const char *src)
142{ 142{
143 int l = strlen(src) + 1; 143 int l = strlen(src) + 1;
144 char *dst = malloc(l); 144 char *dst = malloc(l);
145 if (dst) 145 if (dst)
146 strcpy(dst,src); 146 strcpy(dst,src);
147 return dst; 147 return dst;
148} 148}
149#endif 149#endif
150 150
151/* 151/*
152 * socket_wait - wait for socket to receive or flush data 152 * socket_wait - wait for socket to receive or flush data
153 * 153 *
154 * return 1 if no user callback, otherwise, return value returned by 154 * return 1 if no user callback, otherwise, return value returned by
155 * user callback 155 * user callback
156 */ 156 */
157static int socket_wait(netbuf *ctl) 157static int socket_wait(netbuf *ctl)
158{ 158{
159 fd_set fd,*rfd = NULL,*wfd = NULL; 159 fd_set fd,*rfd = NULL,*wfd = NULL;
160 struct timeval tv; 160 struct timeval tv;
161 int rv = 0; 161 int rv = 0;
162 if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL)) 162 if ((ctl->dir == FTPLIB_CONTROL) || (ctl->idlecb == NULL))
163 return 1; 163 return 1;
164 if (ctl->dir == FTPLIB_WRITE) 164 if (ctl->dir == FTPLIB_WRITE)
165 wfd = &fd; 165 wfd = &fd;
166 else 166 else
167 rfd = &fd; 167 rfd = &fd;
168 FD_ZERO(&fd); 168 FD_ZERO(&fd);
169 do 169 do
170 { 170 {
171 FD_SET(ctl->handle,&fd); 171 FD_SET(ctl->handle,&fd);
172 tv = ctl->idletime; 172 tv = ctl->idletime;
173 rv = select(ctl->handle+1, rfd, wfd, NULL, &tv); 173 rv = select(ctl->handle+1, rfd, wfd, NULL, &tv);
174 if (rv == -1) 174 if (rv == -1)
175 { 175 {
176 rv = 0; 176 rv = 0;
177 strncpy(ctl->ctrl->response, strerror(errno), 177 strncpy(ctl->ctrl->response, strerror(errno),
178 sizeof(ctl->ctrl->response)); 178 sizeof(ctl->ctrl->response));
179 break; 179 break;
180 } 180 }
181 else if (rv > 0) 181 else if (rv > 0)
182 { 182 {
183 rv = 1; 183 rv = 1;
184 break; 184 break;
185 } 185 }
186 } 186 }
187 while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg))); 187 while ((rv = ctl->idlecb(ctl, ctl->xfered, ctl->idlearg)));
188 return rv; 188 return rv;
189} 189}
190 190
191/* 191/*
192 * read a line of text 192 * read a line of text
193 * 193 *
194 * return -1 on error or bytecount 194 * return -1 on error or bytecount
195 */ 195 */
196static int readline(char *buf,int max,netbuf *ctl) 196static int readline(char *buf,int max,netbuf *ctl)
197{ 197{
198 int x,retval = 0; 198 int x,retval = 0;
199 char *end,*bp=buf; 199 char *end,*bp=buf;
200 int eof = 0; 200 int eof = 0;
201 201
202 if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ)) 202 if ((ctl->dir != FTPLIB_CONTROL) && (ctl->dir != FTPLIB_READ))
203 return -1; 203 return -1;
204 if (max == 0) 204 if (max == 0)
205 return 0; 205 return 0;
206 do 206 do
207 { 207 {
208 if (ctl->cavail > 0) 208 if (ctl->cavail > 0)
209 { 209 {
210 x = (max >= ctl->cavail) ? ctl->cavail : max-1; 210 x = (max >= ctl->cavail) ? ctl->cavail : max-1;
211 end = memccpy(bp,ctl->cget,'\n',x); 211 end = memccpy(bp,ctl->cget,'\n',x);
212 if (end != NULL) 212 if (end != NULL)
213 x = end - bp; 213 x = end - bp;
214 retval += x; 214 retval += x;
215 bp += x; 215 bp += x;
216 *bp = '\0'; 216 *bp = '\0';
217 max -= x; 217 max -= x;
218 ctl->cget += x; 218 ctl->cget += x;
219 ctl->cavail -= x; 219 ctl->cavail -= x;
220 if (end != NULL) 220 if (end != NULL)
221 { 221 {
222 bp -= 2; 222 bp -= 2;
223 if (strcmp(bp,"\r\n") == 0) 223 if (strcmp(bp,"\r\n") == 0)
224 { 224 {
225 *bp++ = '\n'; 225 *bp++ = '\n';
226 *bp++ = '\0'; 226 *bp++ = '\0';
227 --retval; 227 --retval;
228 } 228 }
229 break; 229 break;
230 } 230 }
231 } 231 }
232 if (max == 1) 232 if (max == 1)
233 { 233 {
234 *buf = '\0'; 234 *buf = '\0';
235 break; 235 break;
236 } 236 }
237 if (ctl->cput == ctl->cget) 237 if (ctl->cput == ctl->cget)
238 { 238 {
239 ctl->cput = ctl->cget = ctl->buf; 239 ctl->cput = ctl->cget = ctl->buf;
240 ctl->cavail = 0; 240 ctl->cavail = 0;
241 ctl->cleft = FTPLIB_BUFSIZ; 241 ctl->cleft = FTPLIB_BUFSIZ;
242 } 242 }
243 if (eof) 243 if (eof)
244 { 244 {
245 if (retval == 0) 245 if (retval == 0)
246 retval = -1; 246 retval = -1;
247 break; 247 break;
248 } 248 }
249 if (!socket_wait(ctl)) 249 if (!socket_wait(ctl))
250 return retval; 250 return retval;
251 if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1) 251 if ((x = net_read(ctl->handle,ctl->cput,ctl->cleft)) == -1)
252 { 252 {
253 perror("read"); 253 perror("read");
254 retval = -1; 254 retval = -1;
255 break; 255 break;
256 } 256 }
257 if (x == 0) 257 if (x == 0)
258 eof = 1; 258 eof = 1;
259 ctl->cleft -= x; 259 ctl->cleft -= x;
260 ctl->cavail += x; 260 ctl->cavail += x;
261 ctl->cput += x; 261 ctl->cput += x;
262 } 262 }
263 while (1); 263 while (1);
264 return retval; 264 return retval;
265} 265}
266 266
267/* 267/*
268 * write lines of text 268 * write lines of text
269 * 269 *
270 * return -1 on error or bytecount 270 * return -1 on error or bytecount
271 */ 271 */
272static int writeline(char *buf, int len, netbuf *nData) 272static int writeline(char *buf, int len, netbuf *nData)
273{ 273{
274 int x, nb=0, w; 274 int x, nb=0, w;
275 char *ubp = buf, *nbp; 275 char *ubp = buf, *nbp;
276 char lc=0; 276 char lc=0;
277 277
278 if (nData->dir != FTPLIB_WRITE) 278 if (nData->dir != FTPLIB_WRITE)
279 return -1; 279 return -1;
280 nbp = nData->buf; 280 nbp = nData->buf;
281 for (x=0; x < len; x++) 281 for (x=0; x < len; x++)
282 { 282 {
283 if ((*ubp == '\n') && (lc != '\r')) 283 if ((*ubp == '\n') && (lc != '\r'))
284 { 284 {
285 if (nb == FTPLIB_BUFSIZ) 285 if (nb == FTPLIB_BUFSIZ)
286 { 286 {
287 if (!socket_wait(nData)) 287 if (!socket_wait(nData))
288 return x; 288 return x;
289 w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); 289 w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
290 if (w != FTPLIB_BUFSIZ) 290 if (w != FTPLIB_BUFSIZ)
291 { 291 {
292 printf("net_write(1) returned %d, errno = %d\n", w, errno); 292 printf("net_write(1) returned %d, errno = %d\n", w, errno);
293 return(-1); 293 return(-1);
294 } 294 }
295 nb = 0; 295 nb = 0;
296 } 296 }
297 nbp[nb++] = '\r'; 297 nbp[nb++] = '\r';
298 } 298 }
299 if (nb == FTPLIB_BUFSIZ) 299 if (nb == FTPLIB_BUFSIZ)
300 { 300 {
301 if (!socket_wait(nData)) 301 if (!socket_wait(nData))
302 return x; 302 return x;
303 w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ); 303 w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
304 if (w != FTPLIB_BUFSIZ) 304 if (w != FTPLIB_BUFSIZ)
305 { 305 {
306 printf("net_write(2) returned %d, errno = %d\n", w, errno); 306 printf("net_write(2) returned %d, errno = %d\n", w, errno);
307 return(-1); 307 return(-1);
308 } 308 }
309 nb = 0; 309 nb = 0;
310 } 310 }
311 nbp[nb++] = lc = *ubp++; 311 nbp[nb++] = lc = *ubp++;
312 } 312 }
313 if (nb) 313 if (nb)
314 { 314 {
315 if (!socket_wait(nData)) 315 if (!socket_wait(nData))
316 return x; 316 return x;
317 w = net_write(nData->handle, nbp, nb); 317 w = net_write(nData->handle, nbp, nb);
318 if (w != nb) 318 if (w != nb)
319 { 319 {
320 printf("net_write(3) returned %d, errno = %d\n", w, errno); 320 printf("net_write(3) returned %d, errno = %d\n", w, errno);
321 return(-1); 321 return(-1);
322 } 322 }
323 } 323 }
324 return len; 324 return len;
325} 325}
326 326
327/* 327/*
328 * read a response from the server 328 * read a response from the server
329 * 329 *
330 * return 0 if first char doesn't match 330 * return 0 if first char doesn't match
331 * return 1 if first char matches 331 * return 1 if first char matches
332 */ 332 */
333static int readresp(char c, netbuf *nControl) 333static int readresp(char c, netbuf *nControl)
334{ 334{
335 char match[5]; 335 char match[5];
336 if (readline(nControl->response,256,nControl) == -1) 336 if (readline(nControl->response,256,nControl) == -1)
337 { 337 {
338 perror("Control socket read failed"); 338 perror("Control socket read failed");
339 return 0; 339 return 0;
340 } 340 }
341 if (ftplib_debug > 1) 341 if (ftplib_debug > 1)
342 fprintf(stderr,"%s",nControl->response); 342 fprintf(stderr,"%s",nControl->response);
343 if (nControl->response[3] == '-') 343 if (nControl->response[3] == '-')
344 { 344 {
345 strncpy(match,nControl->response,3); 345 strncpy(match,nControl->response,3);
346 match[3] = ' '; 346 match[3] = ' ';
347 match[4] = '\0'; 347 match[4] = '\0';
348 do 348 do
349 { 349 {
350 if (readline(nControl->response,256,nControl) == -1) 350 if (readline(nControl->response,256,nControl) == -1)
351 { 351 {
352 perror("Control socket read failed"); 352 perror("Control socket read failed");
353 return 0; 353 return 0;
354 } 354 }
355 if (ftplib_debug > 1) 355 if (ftplib_debug > 1)
356 fprintf(stderr,"%s",nControl->response); 356 fprintf(stderr,"%s",nControl->response);
357 } 357 }
358 while (strncmp(nControl->response,match,4)); 358 while (strncmp(nControl->response,match,4));
359 } 359 }
360 if (nControl->response[0] == c) 360 if (nControl->response[0] == c)
361 return 1; 361 return 1;
362 return 0; 362 return 0;
363} 363}
364 364
365/* 365/*
366 * FtpInit for stupid operating systems that require it (Windows NT) 366 * FtpInit for stupid operating systems that require it (Windows NT)
367 */ 367 */
368GLOBALDEF void FtpInit(void) 368GLOBALDEF void FtpInit(void)
369{ 369{
370#if defined(_WIN32) 370#if defined(_WIN32)
371 WORD wVersionRequested; 371 WORD wVersionRequested;
372 WSADATA wsadata; 372 WSADATA wsadata;
373 int err; 373 int err;
374 wVersionRequested = MAKEWORD(1,1); 374 wVersionRequested = MAKEWORD(1,1);
375 if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0) 375 if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0)
376 fprintf(stderr,"Network failed to start: %d\n",err); 376 fprintf(stderr,"Network failed to start: %d\n",err);
377#endif 377#endif
378} 378}
379 379
380/* 380/*
381 * FtpLastResponse - return a pointer to the last response received 381 * FtpLastResponse - return a pointer to the last response received
382 */ 382 */
383GLOBALDEF char *FtpLastResponse(netbuf *nControl) 383GLOBALDEF char *FtpLastResponse(netbuf *nControl)
384{ 384{
385 if ((nControl) && (nControl->dir == FTPLIB_CONTROL)) 385 if ((nControl) && (nControl->dir == FTPLIB_CONTROL))
386 return nControl->response; 386 return nControl->response;
387 return NULL; 387 return NULL;
388} 388}
389 389
390/* 390/*
391 * FtpConnect - connect to remote server 391 * FtpConnect - connect to remote server
392 * 392 *
393 * return 1 if connected, 0 if not 393 * return 1 if connected, 0 if not
394 */ 394 */
395GLOBALDEF int FtpConnect(const char *host, netbuf **nControl) 395GLOBALDEF int FtpConnect(const char *host, netbuf **nControl)
396{ 396{
397 int sControl, stat, flags, oldflags; 397 int sControl, stat, flags, oldflags;
398 struct sockaddr_in sin; 398 struct sockaddr_in sin;
399 struct hostent *phe; 399 struct hostent *phe;
400 struct servent *pse; 400 struct servent *pse;
401 int on=1; 401 int on=1;
402 netbuf *ctrl; 402 netbuf *ctrl;
403 char *lhost; 403 char *lhost;
404 char *pnum; 404 char *pnum;
405 struct timeval tv; 405 struct timeval tv;
406 fd_set wr; 406 fd_set wr;
407 407
408 memset(&sin,0,sizeof(sin)); 408 memset(&sin,0,sizeof(sin));
409 sin.sin_family = AF_INET; 409 sin.sin_family = AF_INET;
410 lhost = strdup(host); 410 lhost = strdup(host);
411 pnum = strchr(lhost,':'); 411 pnum = strchr(lhost,':');
412 if (pnum == NULL) 412 if (pnum == NULL)
413 { 413 {
414#if defined(VMS) 414#if defined(VMS)
415 sin.sin_port = htons(21); 415 sin.sin_port = htons(21);
416#else 416#else
417 if ((pse = getservbyname("ftp","tcp")) == NULL) 417 if ((pse = getservbyname("ftp","tcp")) == NULL)
418 { 418 {
419 perror("getservbyname"); 419 perror("getservbyname");
420 return 0; 420 return 0;
421 } 421 }
422 sin.sin_port = pse->s_port; 422 sin.sin_port = pse->s_port;
423#endif 423#endif
424 } 424 }
425 else 425 else
426 { 426 {
427 *pnum++ = '\0'; 427 *pnum++ = '\0';
428 if (isdigit(*pnum)) 428 if (isdigit(*pnum))
429 sin.sin_port = htons(atoi(pnum)); 429 sin.sin_port = htons(atoi(pnum));
430 else 430 else
431 { 431 {
432 pse = getservbyname(pnum,"tcp"); 432 pse = getservbyname(pnum,"tcp");
433 sin.sin_port = pse->s_port; 433 sin.sin_port = pse->s_port;
434 } 434 }
435 } 435 }
436 if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1) 436 if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1)
437 { 437 {
438 if ((phe = gethostbyname(lhost)) == NULL) 438 if ((phe = gethostbyname(lhost)) == NULL)
439 { 439 {
440 perror("gethostbyname"); 440 perror("gethostbyname");
441 return 0; 441 return 0;
442 } 442 }
443 443
444 memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length); 444 memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length);
445 445
446 } 446 }
447 free(lhost); 447 free(lhost);
448 448
449 sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); 449 sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
450 if (sControl == -1) 450 if (sControl == -1)
451 { 451 {
452 perror("socket"); 452 perror("socket");
453 return 0; 453 return 0;
454 } 454 }
455 455
456 if ( setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR, 456 if ( setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR,
457 SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1) 457 SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1)
458 { 458 {
459 perror("setsockopt"); 459 perror("setsockopt");
460 net_close(sControl); 460 net_close(sControl);
461 return 0; 461 return 0;
462 } 462 }
463 463
464 //set nonblocking for connection timeout 464 //set nonblocking for connection timeout
465 flags = fcntl( sControl, F_GETFL,0); 465 flags = fcntl( sControl, F_GETFL,0);
466 oldflags=flags; 466 oldflags=flags;
467 fcntl( sControl, F_SETFL, O_NONBLOCK|flags); 467 fcntl( sControl, F_SETFL, O_NONBLOCK|flags);
468 468
469 stat=connect( sControl, (struct sockaddr *)&sin, sizeof(sin)); 469 stat=connect( sControl, (struct sockaddr *)&sin, sizeof(sin));
470 if (stat < 0) 470 if (stat < 0)
471 { 471 {
472 if (errno != EWOULDBLOCK && errno != EINPROGRESS) 472 if (errno != EWOULDBLOCK && errno != EINPROGRESS)
473 { 473 {
474 perror("connect"); 474 perror("connect");
475 net_close(sControl); 475 net_close(sControl);
476 return 0; 476 return 0;
477 } 477 }
478 } 478 }
479 479
480 FD_ZERO(&wr); 480 FD_ZERO(&wr);
481 FD_SET( sControl, &wr); 481 FD_SET( sControl, &wr);
482 482
483 tv.tv_sec = ACCEPT_TIMEOUT; 483 tv.tv_sec = ACCEPT_TIMEOUT;
484 tv.tv_usec = 0; 484 tv.tv_usec = 0;
485 485
486 stat = select(sControl+1, 0, &wr, 0, &tv); 486 stat = select(sControl+1, 0, &wr, 0, &tv);
487 487
488 if (stat < 1) 488 if (stat < 1)
489 { 489 {
490 // time out has expired, 490 // time out has expired,
491 // or an error has ocurred 491 // or an error has ocurred
492 perror("timeout"); 492 perror("timeout");
493 net_close(sControl); 493 net_close(sControl);
494 return 0; 494 return 0;
495 } 495 }
496 496
497 printf("connected\n"); 497 printf("connected\n");
498 498
499 //set original flags 499 //set original flags
500 fcntl( sControl, F_SETFL, oldflags); 500 fcntl( sControl, F_SETFL, oldflags);
501 501
502 ctrl = calloc(1,sizeof(netbuf)); 502 ctrl = calloc(1,sizeof(netbuf));
503 if (ctrl == NULL) 503 if (ctrl == NULL)
504 { 504 {
505 perror("calloc"); 505 perror("calloc");
506 net_close(sControl); 506 net_close(sControl);
507 return 0; 507 return 0;
508 } 508 }
509 ctrl->buf = malloc(FTPLIB_BUFSIZ); 509 ctrl->buf = malloc(FTPLIB_BUFSIZ);
510 if (ctrl->buf == NULL) 510 if (ctrl->buf == NULL)
511 { 511 {
512 perror("calloc"); 512 perror("calloc");
513 net_close(sControl); 513 net_close(sControl);
514 free(ctrl); 514 free(ctrl);
515 return 0; 515 return 0;
516 } 516 }
517 ctrl->handle = sControl; 517 ctrl->handle = sControl;
518 ctrl->dir = FTPLIB_CONTROL; 518 ctrl->dir = FTPLIB_CONTROL;
519 ctrl->ctrl = NULL; 519 ctrl->ctrl = NULL;
520 ctrl->cmode = FTPLIB_DEFMODE; 520 ctrl->cmode = FTPLIB_DEFMODE;
521 ctrl->idlecb = NULL; 521 ctrl->idlecb = NULL;
522 ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0; 522 ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
523 ctrl->idlearg = NULL; 523 ctrl->idlearg = NULL;
524 ctrl->xfered = 0; 524 ctrl->xfered = 0;
525 ctrl->xfered1 = 0; 525 ctrl->xfered1 = 0;
526 ctrl->cbbytes = 0; 526 ctrl->cbbytes = 0;
527 if (readresp('2', ctrl) == 0) 527 if (readresp('2', ctrl) == 0)
528 { 528 {
529 net_close(sControl); 529 net_close(sControl);
530 free(ctrl->buf); 530 free(ctrl->buf);
531 free(ctrl); 531 free(ctrl);
532 return 0; 532 return 0;
533 } 533 }
534 *nControl = ctrl; 534 *nControl = ctrl;
535 return 1; 535 return 1;
536} 536}
537 537
538/* 538/*
539 * FtpOptions - change connection options 539 * FtpOptions - change connection options
540 * 540 *
541 * returns 1 if successful, 0 on error 541 * returns 1 if successful, 0 on error
542 */ 542 */
543GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl) 543GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl)
544{ 544{
545 int v,rv=0; 545 int v,rv=0;
546 switch (opt) 546 switch (opt)
547 { 547 {
548 case FTPLIB_CONNMODE: 548 case FTPLIB_CONNMODE:
549 v = (int) val; 549 v = (int) val;
550 if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT)) 550 if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT))
551 { 551 {
552 nControl->cmode = v; 552 nControl->cmode = v;
553 rv = 1; 553 rv = 1;
554 } 554 }
555 break; 555 break;
556 case FTPLIB_CALLBACK: 556 case FTPLIB_CALLBACK:
557 nControl->idlecb = (FtpCallback) val; 557 nControl->idlecb = (FtpCallback) val;
558 rv = 1; 558 rv = 1;
559 break; 559 break;
560 case FTPLIB_IDLETIME: 560 case FTPLIB_IDLETIME:
561 v = (int) val; 561 v = (int) val;
562 rv = 1; 562 rv = 1;
563 nControl->idletime.tv_sec = v / 1000; 563 nControl->idletime.tv_sec = v / 1000;
564 nControl->idletime.tv_usec = (v % 1000) * 1000; 564 nControl->idletime.tv_usec = (v % 1000) * 1000;
565 break; 565 break;
566 case FTPLIB_CALLBACKARG: 566 case FTPLIB_CALLBACKARG:
567 rv = 1; 567 rv = 1;
568 nControl->idlearg = (void *) val; 568 nControl->idlearg = (void *) val;
569 break; 569 break;
570 case FTPLIB_CALLBACKBYTES: 570 case FTPLIB_CALLBACKBYTES:
571 rv = 1; 571 rv = 1;
572 nControl->cbbytes = (int) val; 572 nControl->cbbytes = (int) val;
573 break; 573 break;
574 } 574 }
575 return rv; 575 return rv;
576} 576}
577 577
578/* 578/*
579 * FtpSendCmd - send a command and wait for expected response 579 * FtpSendCmd - send a command and wait for expected response
580 * 580 *
581 * return 1 if proper response received, 0 otherwise 581 * return 1 if proper response received, 0 otherwise
582 */ 582 */
583static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl) 583static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
584{ 584{
585 char buf[256]; 585 char buf[256];
586 if (nControl->dir != FTPLIB_CONTROL) 586 if (nControl->dir != FTPLIB_CONTROL)
587 return 0; 587 return 0;
588 if (ftplib_debug > 2) 588 if (ftplib_debug > 2)
589 fprintf(stderr,"%s\n",cmd); 589 fprintf(stderr,"%s\n",cmd);
590 if ((strlen(cmd) + 3) > sizeof(buf)) 590 if ((strlen(cmd) + 3) > sizeof(buf))
591 return 0; 591 return 0;
592 sprintf(buf,"%s\r\n",cmd); 592 sprintf(buf,"%s\r\n",cmd);
593 if (net_write(nControl->handle,buf,strlen(buf)) <= 0) 593 if (net_write(nControl->handle,buf,strlen(buf)) <= 0)
594 { 594 {
595 perror("write"); 595 perror("write");
596 return 0; 596 return 0;
597 } 597 }
598 return readresp(expresp, nControl); 598 return readresp(expresp, nControl);
599} 599}
600 600
601/* 601/*
602 * FtpLogin - log in to remote server 602 * FtpLogin - log in to remote server
603 * 603 *
604 * return 1 if logged in, 0 otherwise 604 * return 1 if logged in, 0 otherwise
605 */ 605 */
606GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl) 606GLOBALDEF int FtpLogin(const char *user, const char *pass, netbuf *nControl)
607{ 607{
608 char tempbuf[64]; 608 char tempbuf[64];
609 609
610 if (((strlen(user) + 7) > sizeof(tempbuf)) || 610 if (((strlen(user) + 7) > sizeof(tempbuf)) ||
611 ((strlen(pass) + 7) > sizeof(tempbuf))) 611 ((strlen(pass) + 7) > sizeof(tempbuf)))
612 return 0; 612 return 0;
613 sprintf(tempbuf,"USER %s",user); 613 sprintf(tempbuf,"USER %s",user);
614 if (!FtpSendCmd(tempbuf,'3',nControl)) 614 if (!FtpSendCmd(tempbuf,'3',nControl))
615 { 615 {
616 if (nControl->response[0] == '2') 616 if (nControl->response[0] == '2')
617 return 1; 617 return 1;
618 return 0; 618 return 0;
619 } 619 }
620 sprintf(tempbuf,"PASS %s",pass); 620 sprintf(tempbuf,"PASS %s",pass);
621 return FtpSendCmd(tempbuf,'2',nControl); 621 return FtpSendCmd(tempbuf,'2',nControl);
622} 622}
623 623
624/* 624/*
625 * FtpOpenPort - set up data connection 625 * FtpOpenPort - set up data connection
626 * 626 *
627 * return 1 if successful, 0 otherwise 627 * return 1 if successful, 0 otherwise
628 */ 628 */
629static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir) 629static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir)
630{ 630{
631 int sData; 631 int sData;
632 union { 632 union {
633 struct sockaddr sa; 633 struct sockaddr sa;
634 struct sockaddr_in in; 634 struct sockaddr_in in;
635 } sin; 635 } sin;
636 struct linger lng = { 0, 0 }; 636 struct linger lng = { 0, 0 };
637 unsigned int l; 637 unsigned int l;
638 int on=1; 638 int on=1;
639 netbuf *ctrl; 639 netbuf *ctrl;
640 char *cp; 640 char *cp;
641 unsigned int v[6]; 641 unsigned int v[6];
642 char buf[256]; 642 char buf[256];
643 643
644 if (nControl->dir != FTPLIB_CONTROL) 644 if (nControl->dir != FTPLIB_CONTROL)
645 return -1; 645 return -1;
646 if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE)) 646 if ((dir != FTPLIB_READ) && (dir != FTPLIB_WRITE))
647 { 647 {
648 sprintf(nControl->response, "Invalid direction %d\n", dir); 648 sprintf(nControl->response, "Invalid direction %d\n", dir);
649 return -1; 649 return -1;
650 } 650 }
651 if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE)) 651 if ((mode != FTPLIB_ASCII) && (mode != FTPLIB_IMAGE))
652 { 652 {
653 sprintf(nControl->response, "Invalid mode %c\n", mode); 653 sprintf(nControl->response, "Invalid mode %c\n", mode);
654 return -1; 654 return -1;
655 } 655 }
656 l = sizeof(sin); 656 l = sizeof(sin);
657 if (nControl->cmode == FTPLIB_PASSIVE) 657 if (nControl->cmode == FTPLIB_PASSIVE)
658 { 658 {
659 memset(&sin, 0, l); 659 memset(&sin, 0, l);
660 sin.in.sin_family = AF_INET; 660 sin.in.sin_family = AF_INET;
661 if (!FtpSendCmd("PASV",'2',nControl)) 661 if (!FtpSendCmd("PASV",'2',nControl))
662 return -1; 662 return -1;
663 cp = strchr(nControl->response,'('); 663 cp = strchr(nControl->response,'(');
664 if (cp == NULL) 664 if (cp == NULL)
665 return -1; 665 return -1;
666 cp++; 666 cp++;
667 sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]); 667 sscanf(cp,"%u,%u,%u,%u,%u,%u",&v[2],&v[3],&v[4],&v[5],&v[0],&v[1]);
668 sin.sa.sa_data[2] = v[2]; 668 sin.sa.sa_data[2] = v[2];
669 sin.sa.sa_data[3] = v[3]; 669 sin.sa.sa_data[3] = v[3];
670 sin.sa.sa_data[4] = v[4]; 670 sin.sa.sa_data[4] = v[4];
671 sin.sa.sa_data[5] = v[5]; 671 sin.sa.sa_data[5] = v[5];
672 sin.sa.sa_data[0] = v[0]; 672 sin.sa.sa_data[0] = v[0];
673 sin.sa.sa_data[1] = v[1]; 673 sin.sa.sa_data[1] = v[1];
674 } 674 }
675 else 675 else
676 { 676 {
677 if (getsockname(nControl->handle, &sin.sa, &l) < 0) 677 if (getsockname(nControl->handle, &sin.sa, &l) < 0)
678 { 678 {
679 perror("getsockname"); 679 perror("getsockname");
680 return 0; 680 return 0;
681 } 681 }
682 } 682 }
683 sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP); 683 sData = socket(PF_INET,SOCK_STREAM,IPPROTO_TCP);
684 if (sData == -1) 684 if (sData == -1)
685 { 685 {
686 perror("socket"); 686 perror("socket");
687 return -1; 687 return -1;
688 } 688 }
689 if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR, 689 if (setsockopt(sData,SOL_SOCKET,SO_REUSEADDR,
690 SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1) 690 SETSOCKOPT_OPTVAL_TYPE &on,sizeof(on)) == -1)
691 { 691 {
692 perror("setsockopt"); 692 perror("setsockopt");
693 net_close(sData); 693 net_close(sData);
694 return -1; 694 return -1;
695 } 695 }
696 if (setsockopt(sData,SOL_SOCKET,SO_LINGER, 696 if (setsockopt(sData,SOL_SOCKET,SO_LINGER,
697 SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1) 697 SETSOCKOPT_OPTVAL_TYPE &lng,sizeof(lng)) == -1)
698 { 698 {
699 perror("setsockopt"); 699 perror("setsockopt");
700 net_close(sData); 700 net_close(sData);
701 return -1; 701 return -1;
702 } 702 }
703 if (nControl->cmode == FTPLIB_PASSIVE) 703 if (nControl->cmode == FTPLIB_PASSIVE)
704 { 704 {
705 if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1) 705 if (connect(sData, &sin.sa, sizeof(sin.sa)) == -1)
706 { 706 {
707 perror("connect"); 707 perror("connect");
708 net_close(sData); 708 net_close(sData);
709 return -1; 709 return -1;
710 } 710 }
711 } 711 }
712 else 712 else
713 { 713 {
714 sin.in.sin_port = 0; 714 sin.in.sin_port = 0;
715 if (bind(sData, &sin.sa, sizeof(sin)) == -1) 715 if (bind(sData, &sin.sa, sizeof(sin)) == -1)
716 { 716 {
717 perror("bind"); 717 perror("bind");
718 net_close(sData); 718 net_close(sData);
719 return 0; 719 return 0;
720 } 720 }
721 if (listen(sData, 1) < 0) 721 if (listen(sData, 1) < 0)
722 { 722 {
723 perror("listen"); 723 perror("listen");
724 net_close(sData); 724 net_close(sData);
725 return 0; 725 return 0;
726 } 726 }
727 if (getsockname(sData, &sin.sa, &l) < 0) 727 if (getsockname(sData, &sin.sa, &l) < 0)
728 return 0; 728 return 0;
729 sprintf(buf, "PORT %d,%d,%d,%d,%d,%d", 729 sprintf(buf, "PORT %d,%d,%d,%d,%d,%d",
730 (unsigned char) sin.sa.sa_data[2], 730 (unsigned char) sin.sa.sa_data[2],
731 (unsigned char) sin.sa.sa_data[3], 731 (unsigned char) sin.sa.sa_data[3],
732 (unsigned char) sin.sa.sa_data[4], 732 (unsigned char) sin.sa.sa_data[4],
733 (unsigned char) sin.sa.sa_data[5], 733 (unsigned char) sin.sa.sa_data[5],
734 (unsigned char) sin.sa.sa_data[0], 734 (unsigned char) sin.sa.sa_data[0],
735 (unsigned char) sin.sa.sa_data[1]); 735 (unsigned char) sin.sa.sa_data[1]);
736 if (!FtpSendCmd(buf,'2',nControl)) 736 if (!FtpSendCmd(buf,'2',nControl))
737 { 737 {
738 net_close(sData); 738 net_close(sData);
739 return 0; 739 return 0;
740 } 740 }
741 } 741 }
742 ctrl = calloc(1,sizeof(netbuf)); 742 ctrl = calloc(1,sizeof(netbuf));
743 if (ctrl == NULL) 743 if (ctrl == NULL)
744 { 744 {
745 perror("calloc"); 745 perror("calloc");
746 net_close(sData); 746 net_close(sData);
747 return -1; 747 return -1;
748 } 748 }
749 if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL)) 749 if ((mode == 'A') && ((ctrl->buf = malloc(FTPLIB_BUFSIZ)) == NULL))
750 { 750 {
751 perror("calloc"); 751 perror("calloc");
752 net_close(sData); 752 net_close(sData);
753 free(ctrl); 753 free(ctrl);
754 return -1; 754 return -1;
755 } 755 }
756 ctrl->handle = sData; 756 ctrl->handle = sData;
757 ctrl->dir = dir; 757 ctrl->dir = dir;
758 ctrl->idletime = nControl->idletime; 758 ctrl->idletime = nControl->idletime;
759 ctrl->idlearg = nControl->idlearg; 759 ctrl->idlearg = nControl->idlearg;
760 ctrl->xfered = 0; 760 ctrl->xfered = 0;
761 ctrl->xfered1 = 0; 761 ctrl->xfered1 = 0;
762 ctrl->cbbytes = nControl->cbbytes; 762 ctrl->cbbytes = nControl->cbbytes;
763 if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes) 763 if (ctrl->idletime.tv_sec || ctrl->idletime.tv_usec || ctrl->cbbytes)
764 ctrl->idlecb = nControl->idlecb; 764 ctrl->idlecb = nControl->idlecb;
765 else 765 else
766 ctrl->idlecb = NULL; 766 ctrl->idlecb = NULL;
767 *nData = ctrl; 767 *nData = ctrl;
768 return 1; 768 return 1;
769} 769}
770 770
771/* 771/*
772 * FtpAcceptConnection - accept connection from server 772 * FtpAcceptConnection - accept connection from server
773 * 773 *
774 * return 1 if successful, 0 otherwise 774 * return 1 if successful, 0 otherwise
775 */ 775 */
776static int FtpAcceptConnection(netbuf *nData, netbuf *nControl) 776static int FtpAcceptConnection(netbuf *nData, netbuf *nControl)
777{ 777{
778 int sData; 778 int sData;
779 struct sockaddr addr; 779 struct sockaddr addr;
780 unsigned int l; 780 unsigned int l;
781 int i; 781 int i;
782 struct timeval tv; 782 struct timeval tv;
783 fd_set mask; 783 fd_set mask;
784 int rv; 784 int rv;
785 785
786 FD_ZERO(&mask); 786 FD_ZERO(&mask);
787 FD_SET(nControl->handle, &mask); 787 FD_SET(nControl->handle, &mask);
788 FD_SET(nData->handle, &mask); 788 FD_SET(nData->handle, &mask);
789 tv.tv_usec = 0; 789 tv.tv_usec = 0;
790 tv.tv_sec = ACCEPT_TIMEOUT; 790 tv.tv_sec = ACCEPT_TIMEOUT;
791 printf("<<<<<<<<<<<<<<<<%d\n",ACCEPT_TIMEOUT); 791 printf("<<<<<<<<<<<<<<<<%d\n",ACCEPT_TIMEOUT);
792 i = nControl->handle; 792 i = nControl->handle;
793 if (i < nData->handle) 793 if (i < nData->handle)
794 i = nData->handle; 794 i = nData->handle;
795 i = select(i+1, &mask, NULL, NULL, &tv); 795 i = select(i+1, &mask, NULL, NULL, &tv);
796 if (i == -1) 796 if (i == -1)
797 { 797 {
798 strncpy(nControl->response, strerror(errno), 798 strncpy(nControl->response, strerror(errno),
799 sizeof(nControl->response)); 799 sizeof(nControl->response));
800 net_close(nData->handle); 800 net_close(nData->handle);
801 nData->handle = 0; 801 nData->handle = 0;
802 rv = 0; 802 rv = 0;
803 } 803 }
804 else if (i == 0) 804 else if (i == 0)
805 { 805 {
806 strcpy(nControl->response, "timed out waiting for connection"); 806 strcpy(nControl->response, "timed out waiting for connection");
807 net_close(nData->handle); 807 net_close(nData->handle);
808 nData->handle = 0; 808 nData->handle = 0;
809 rv = 0; 809 rv = 0;
810 } 810 }
811 else 811 else
812 { 812 {
813 if (FD_ISSET(nData->handle, &mask)) 813 if (FD_ISSET(nData->handle, &mask))
814 { 814 {
815 l = sizeof(addr); 815 l = sizeof(addr);
816 sData = accept(nData->handle, &addr, &l); 816 sData = accept(nData->handle, &addr, &l);
817 i = errno; 817 i = errno;
818 net_close(nData->handle); 818 net_close(nData->handle);
819 if (sData > 0) 819 if (sData > 0)
820 { 820 {
821 rv = 1; 821 rv = 1;
822 nData->handle = sData; 822 nData->handle = sData;
823 } 823 }
824 else 824 else
825 { 825 {
826 strncpy(nControl->response, strerror(i), 826 strncpy(nControl->response, strerror(i),
827 sizeof(nControl->response)); 827 sizeof(nControl->response));
828 nData->handle = 0; 828 nData->handle = 0;
829 rv = 0; 829 rv = 0;
830 } 830 }
831 } 831 }
832 else if (FD_ISSET(nControl->handle, &mask)) 832 else if (FD_ISSET(nControl->handle, &mask))
833 { 833 {
834 net_close(nData->handle); 834 net_close(nData->handle);
835 nData->handle = 0; 835 nData->handle = 0;
836 readresp('2', nControl); 836 readresp('2', nControl);
837 rv = 0; 837 rv = 0;
838 } 838 }
839 } 839 }
840 return rv; 840 return rv;
841} 841}
842 842
843/* 843/*
844 * FtpAccess - return a handle for a data stream 844 * FtpAccess - return a handle for a data stream
845 * 845 *
846 * return 1 if successful, 0 otherwise 846 * return 1 if successful, 0 otherwise
847 */ 847 */
848GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl, 848GLOBALDEF int FtpAccess(const char *path, int typ, int mode, netbuf *nControl,
849 netbuf **nData) 849 netbuf **nData)
850{ 850{
851 char buf[256]; 851 char buf[256];
852 int dir; 852 int dir;
853 if ((path == NULL) && 853 if ((path == NULL) &&
854 ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ))) 854 ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ)))
855 { 855 {
856 sprintf(nControl->response, 856 sprintf(nControl->response,
857 "Missing path argument for file transfer\n"); 857 "Missing path argument for file transfer\n");
858 return 0; 858 return 0;
859 } 859 }
860 sprintf(buf, "TYPE %c", mode); 860 sprintf(buf, "TYPE %c", mode);
861 if (!FtpSendCmd(buf, '2', nControl)) 861 if (!FtpSendCmd(buf, '2', nControl))
862 return 0; 862 return 0;
863 switch (typ) 863 switch (typ)
864 { 864 {
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/*
1058 * FtpMkdir - create a directory at server 1059 * FtpMkdir - create a directory at server
1059 * 1060 *
1060 * return 1 if successful, 0 otherwise 1061 * return 1 if successful, 0 otherwise
1061 */ 1062 */
1062GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl) 1063GLOBALDEF int FtpMkdir(const char *path, netbuf *nControl)
1063{ 1064{
1064 char buf[256]; 1065 char buf[256];
1065 1066
1066 if ((strlen(path) + 6) > sizeof(buf)) 1067 if ((strlen(path) + 6) > sizeof(buf))
1067 return 0; 1068 return 0;
1068 sprintf(buf,"MKD %s",path); 1069 sprintf(buf,"MKD %s",path);
1069 if (!FtpSendCmd(buf,'2', nControl)) 1070 if (!FtpSendCmd(buf,'2', nControl))
1070 return 0; 1071 return 0;
1071 return 1; 1072 return 1;
1072} 1073}
1073 1074
1074/* 1075/*
1075 * FtpChdir - change path at remote 1076 * FtpChdir - change path at remote
1076 * 1077 *
1077 * return 1 if successful, 0 otherwise 1078 * return 1 if successful, 0 otherwise
1078 */ 1079 */
1079GLOBALDEF int FtpChdir(const char *path, netbuf *nControl) 1080GLOBALDEF int FtpChdir(const char *path, netbuf *nControl)
1080{ 1081{
1081 char buf[256]; 1082 char buf[256];
1082 1083
1083 if ((strlen(path) + 6) > sizeof(buf)) 1084 if ((strlen(path) + 6) > sizeof(buf))
1084 return 0; 1085 return 0;
1085 sprintf(buf,"CWD %s",path); 1086 sprintf(buf,"CWD %s",path);
1086 if (!FtpSendCmd(buf,'2',nControl)) 1087 if (!FtpSendCmd(buf,'2',nControl))
1087 return 0; 1088 return 0;
1088 return 1; 1089 return 1;
1089} 1090}
1090 1091
1091/* 1092/*
1092 * FtpCDUp - move to parent directory at remote 1093 * FtpCDUp - move to parent directory at remote
1093 * 1094 *
1094 * return 1 if successful, 0 otherwise 1095 * return 1 if successful, 0 otherwise
1095 */ 1096 */
1096GLOBALDEF int FtpCDUp(netbuf *nControl) 1097GLOBALDEF int FtpCDUp(netbuf *nControl)
1097{ 1098{
1098 if (!FtpSendCmd("CDUP",'2',nControl)) 1099 if (!FtpSendCmd("CDUP",'2',nControl))
1099 return 0; 1100 return 0;
1100 return 1; 1101 return 1;
1101} 1102}
1102 1103
1103/* 1104/*
1104 * FtpRmdir - remove directory at remote 1105 * FtpRmdir - remove directory at remote
1105 * 1106 *
1106 * return 1 if successful, 0 otherwise 1107 * return 1 if successful, 0 otherwise
1107 */ 1108 */
1108GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl) 1109GLOBALDEF int FtpRmdir(const char *path, netbuf *nControl)
1109{ 1110{
1110 char buf[256]; 1111 char buf[256];
1111 1112
1112 if ((strlen(path) + 6) > sizeof(buf)) 1113 if ((strlen(path) + 6) > sizeof(buf))
1113 return 0; 1114 return 0;
1114 sprintf(buf,"RMD %s",path); 1115 sprintf(buf,"RMD %s",path);
1115 if (!FtpSendCmd(buf,'2',nControl)) 1116 if (!FtpSendCmd(buf,'2',nControl))
1116 return 0; 1117 return 0;
1117 return 1; 1118 return 1;
1118} 1119}
1119 1120
1120/* 1121/*
1121 * FtpPwd - get working directory at remote 1122 * FtpPwd - get working directory at remote
1122 * 1123 *
1123 * return 1 if successful, 0 otherwise 1124 * return 1 if successful, 0 otherwise
1124 */ 1125 */
1125GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl) 1126GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl)
1126{ 1127{
1127 int l = max; 1128 int l = max;
1128 char *b = path; 1129 char *b = path;
1129 char *s; 1130 char *s;
1130 if (!FtpSendCmd("PWD",'2',nControl)) 1131 if (!FtpSendCmd("PWD",'2',nControl))
1131 return 0; 1132 return 0;
1132 s = strchr(nControl->response, '"'); 1133 s = strchr(nControl->response, '"');
1133 if (s == NULL) 1134 if (s == NULL)
1134 return 0; 1135 return 0;
1135 s++; 1136 s++;
1136 while ((--l) && (*s) && (*s != '"')) 1137 while ((--l) && (*s) && (*s != '"'))
1137 *b++ = *s++; 1138 *b++ = *s++;
1138 *b++ = '\0'; 1139 *b++ = '\0';
1139 return 1; 1140 return 1;
1140} 1141}
1141 1142
1142/* 1143/*
1143 * FtpXfer - issue a command and transfer data 1144 * FtpXfer - issue a command and transfer data
1144 * 1145 *
1145 * return 1 if successful, 0 otherwise 1146 * return 1 if successful, 0 otherwise
1146 */ 1147 */
1147static int FtpXfer(const char *localfile, const char *path, 1148static int FtpXfer(const char *localfile, const char *path,
1148 netbuf *nControl, int typ, int mode) 1149 netbuf *nControl, int typ, int mode)
1149{ 1150{
1150 int l,c; 1151 int l,c;
1151 char *dbuf; 1152 char *dbuf;
1152 FILE *local = NULL; 1153 FILE *local = NULL;
1153 netbuf *nData; 1154 netbuf *nData;
1154 int rv=1; 1155 int rv=1;
1155 1156
1156 if (localfile != NULL) 1157 if (localfile != NULL)
1157 { 1158 {
1158 char ac[4] = "w"; 1159 char ac[4] = "w";
1159 if (typ == FTPLIB_FILE_WRITE) 1160 if (typ == FTPLIB_FILE_WRITE)
1160 ac[0] = 'r'; 1161 ac[0] = 'r';
1161 if (mode == FTPLIB_IMAGE) 1162 if (mode == FTPLIB_IMAGE)
1162 ac[1] = 'b'; 1163 ac[1] = 'b';
1163 local = fopen(localfile, ac); 1164 local = fopen(localfile, ac);
1164 if (local == NULL) 1165 if (local == NULL)
1165 { 1166 {
1166 strncpy(nControl->response, strerror(errno), 1167 strncpy(nControl->response, strerror(errno),
1167 sizeof(nControl->response)); 1168 sizeof(nControl->response));
1168 return 0; 1169 return 0;
1169 } 1170 }
1170 } 1171 }
1171 if (local == NULL) 1172 if (local == NULL)
1172 local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout; 1173 local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout;
1173 if (!FtpAccess(path, typ, mode, nControl, &nData)) 1174 if (!FtpAccess(path, typ, mode, nControl, &nData))
1174 return 0; 1175 return 0;
1175 dbuf = malloc(FTPLIB_BUFSIZ); 1176 dbuf = malloc(FTPLIB_BUFSIZ);
1176 if (typ == FTPLIB_FILE_WRITE) 1177 if (typ == FTPLIB_FILE_WRITE)
1177 { 1178 {
1178 while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0) 1179 while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0)
1179 if ((c = FtpWrite(dbuf, l, nData)) < l) 1180 if ((c = FtpWrite(dbuf, l, nData)) < l)
1180 { 1181 {
1181 printf("short write: passed %d, wrote %d\n", l, c); 1182 printf("short write: passed %d, wrote %d\n", l, c);
1182 rv = 0; 1183 rv = 0;
1183 break; 1184 break;
1184 } 1185 }
1185 } 1186 }
1186 else 1187 else
1187 { 1188 {
1188 while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) 1189 while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0)
1189 if (fwrite(dbuf, 1, l, local) <= 0) 1190 if (fwrite(dbuf, 1, l, local) <= 0)
1190 { 1191 {
1191 perror("localfile write"); 1192 perror("localfile write");
1192 rv = 0; 1193 rv = 0;
1193 break; 1194 break;
1194 } 1195 }
1195 } 1196 }
1196 free(dbuf); 1197 free(dbuf);
1197 fflush(local); 1198 fflush(local);
1198 if (localfile != NULL) 1199 if (localfile != NULL)
1199 fclose(local); 1200 fclose(local);
1200 FtpClose(nData); 1201 FtpClose(nData);
1201 return rv; 1202 return rv;
1202} 1203}
1203 1204
1204/* 1205/*
1205 * FtpNlst - issue an NLST command and write response to output 1206 * FtpNlst - issue an NLST command and write response to output
1206 * 1207 *
1207 * return 1 if successful, 0 otherwise 1208 * return 1 if successful, 0 otherwise
1208 */ 1209 */
1209GLOBALDEF int FtpNlst(const char *outputfile, const char *path, 1210GLOBALDEF int FtpNlst(const char *outputfile, const char *path,
1210 netbuf *nControl) 1211 netbuf *nControl)
1211{ 1212{
1212 return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII); 1213 return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII);
1213} 1214}
1214 1215
1215/* 1216/*
1216 * FtpDir - issue a LIST command and write response to output 1217 * FtpDir - issue a LIST command and write response to output
1217 * 1218 *
1218 * return 1 if successful, 0 otherwise 1219 * return 1 if successful, 0 otherwise
1219 */ 1220 */
1220GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl) 1221GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl)
1221{ 1222{
1222 return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII); 1223 return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII);
1223} 1224}
1224 1225
1225/* 1226/*
1226 * FtpSize - determine the size of a remote file 1227 * FtpSize - determine the size of a remote file
1227 * 1228 *
1228 * return 1 if successful, 0 otherwise 1229 * return 1 if successful, 0 otherwise
1229 */ 1230 */
1230GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl) 1231GLOBALDEF int FtpSize(const char *path, int *size, char mode, netbuf *nControl)
1231{ 1232{
1232 char cmd[256]; 1233 char cmd[256];
1233 int resp,sz,rv=1; 1234 int resp,sz,rv=1;
1234 1235
1235 if ((strlen(path) + 7) > sizeof(cmd)) 1236 if ((strlen(path) + 7) > sizeof(cmd))
1236 return 0; 1237 return 0;
1237 sprintf(cmd, "TYPE %c", mode); 1238 sprintf(cmd, "TYPE %c", mode);
1238 if (!FtpSendCmd(cmd, '2', nControl)) 1239 if (!FtpSendCmd(cmd, '2', nControl))
1239 return 0; 1240 return 0;
1240 sprintf(cmd,"SIZE %s",path); 1241 sprintf(cmd,"SIZE %s",path);
1241 if (!FtpSendCmd(cmd,'2',nControl)) 1242 if (!FtpSendCmd(cmd,'2',nControl))
1242 rv = 0; 1243 rv = 0;
1243 else 1244 else
1244 { 1245 {
1245 if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2) 1246 if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2)
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
@@ -1,271 +1,275 @@
1/**************************************************************************** 1/****************************************************************************
2** 2**
3** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 3** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
4** 4**
5** This file is part of an example program for Qt. This example 5** This file is part of an example program for Qt. This example
6** program may be used, distributed and modified without limitation. 6** program may be used, distributed and modified without limitation.
7** 7**
8*****************************************************************************/ 8*****************************************************************************/
9 9
10#include "helpwindow.h" 10#include "helpwindow.h"
11#include <qstatusbar.h> 11#include <qstatusbar.h>
12 12
13#include <qmenubar.h> 13#include <qmenubar.h>
14#include <qtoolbar.h> 14#include <qtoolbar.h>
15#include <qtoolbutton.h> 15#include <qtoolbutton.h>
16#include <qcombobox.h> 16#include <qcombobox.h>
17 17
18#ifndef QT_NO_FILEDIALOG 18#ifndef QT_NO_FILEDIALOG
19#include <qfiledialog.h> 19#include <qfiledialog.h>
20#endif 20#endif
21 21
22#include <ctype.h> 22#include <ctype.h>
23 23
24HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* parent, const char *name ) 24HelpWindow::HelpWindow( const QString& home_, const QString& _path, QWidget* parent, const char *name )
25 : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL() 25 : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL()
26{ 26{
27 readHistory(); 27 readHistory();
28 readBookmarks(); 28 readBookmarks();
29 29
30 browser = new QTextBrowser( this ); 30 browser = new QTextBrowser( this );
31 QStringList Strlist; 31 QStringList Strlist;
32 Strlist.append( home_); 32 Strlist.append( home_);
33 33
34 browser->mimeSourceFactory()->setFilePath( Strlist ); 34 browser->mimeSourceFactory()->setFilePath( Strlist );
35 35
36 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 36 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
37 37
38 connect( browser, SIGNAL( textChanged() ), 38 connect( browser, SIGNAL( textChanged() ),
39 39
40 this, SLOT( textChanged() ) ); 40 this, SLOT( textChanged() ) );
41 41
42 setCentralWidget( browser ); 42 setCentralWidget( browser );
43 43
44 if ( !home_.isEmpty() ) 44 if ( !home_.isEmpty() )
45 45
46//////////////////////////////// 46////////////////////////////////
47 browser->setSource( home_ ); 47 browser->setSource( home_ );
48 48
49//////////////////////////////// 49////////////////////////////////
50 connect( browser, SIGNAL( highlighted(const QString&) ), 50 connect( browser, SIGNAL( highlighted(const QString&) ),
51 statusBar(), SLOT( message(const QString&)) ); 51 statusBar(), SLOT( message(const QString&)) );
52 52
53 setGeometry( 0,0,236,280); 53 setGeometry( 0,0,236,280);
54 54
55 QPopupMenu* file = new QPopupMenu( this ); 55 QPopupMenu* file = new QPopupMenu( this );
56// file->insertItem( tr("&New Window"), this, SLOT( newWindow() ), ALT | Key_N ); 56// file->insertItem( tr("&New Window"), this, SLOT( newWindow() ), ALT | Key_N );
57 file->insertItem( tr("&Open File"), this, SLOT( openFile() ), ALT | Key_O ); 57 file->insertItem( tr("&Open File"), this, SLOT( openFile() ), ALT | Key_O );
58// file->insertItem( tr("&Print"), this, SLOT( print() ), ALT | Key_P ); 58// file->insertItem( tr("&Print"), this, SLOT( print() ), ALT | Key_P );
59 file->insertSeparator(); 59 file->insertSeparator();
60 file->insertItem( tr("&Close"), this, SLOT( close() ), ALT | Key_Q ); 60 file->insertItem( tr("&Close"), this, SLOT( close() ), ALT | Key_Q );
61// file->insertItem( tr("E&xit"), qApp, SLOT( closeAllWindows() ), ALT | Key_X ); 61// file->insertItem( tr("E&xit"), qApp, SLOT( closeAllWindows() ), ALT | Key_X );
62 62
63 // The same three icons are used twice each. 63 // The same three icons are used twice each.
64////F FIXME 64////F FIXME
65 QString pixs=(QDir::homeDirPath ()) +"/Applications/gutenbrowser/pix/"; 65 QString pixs=(QDir::homeDirPath ()) +"/Applications/gutenbrowser/pix/";
66 QIconSet icon_back( QPixmap(pixs+"back.png") ); 66 QIconSet icon_back( QPixmap(pixs+"back.png") );
67 QIconSet icon_forward( QPixmap(pixs+"forward.png") ); 67 QIconSet icon_forward( QPixmap(pixs+"forward.png") );
68 QIconSet icon_home( QPixmap(pixs+"home.png") ); 68 QIconSet icon_home( QPixmap(pixs+"home.png") );
69 69
70 QPopupMenu* go = new QPopupMenu( this ); 70 QPopupMenu* go = new QPopupMenu( this );
71 backwardId = go->insertItem( icon_back, tr("&Backward"), browser, SLOT( backward() ), ALT | Key_Left ); 71 backwardId = go->insertItem( icon_back, tr("&Backward"), browser, SLOT( backward() ), ALT | Key_Left );
72 forwardId = go->insertItem( icon_forward, tr("&Forward"), browser, SLOT( forward() ), ALT | Key_Right ); 72 forwardId = go->insertItem( icon_forward, tr("&Forward"), browser, SLOT( forward() ), ALT | Key_Right );
73 go->insertItem( icon_home, tr("&Home"), browser, SLOT( home() ) ); 73 go->insertItem( icon_home, tr("&Home"), browser, SLOT( home() ) );
74 74
75 75
76 hist = new QPopupMenu( this ); 76 hist = new QPopupMenu( this );
77 QStringList::Iterator it = history.begin(); 77 QStringList::Iterator it = history.begin();
78 for ( ; it != history.end(); ++it ) 78 for ( ; it != history.end(); ++it )
79 mHistory[ hist->insertItem( *it ) ] = *it; 79 mHistory[ hist->insertItem( *it ) ] = *it;
80 connect( hist, SIGNAL( activated(int) ), this, SLOT( histChosen(int) ) ); 80 connect( hist, SIGNAL( activated(int) ), this, SLOT( histChosen(int) ) );
81 81
82 bookm = new QPopupMenu( this ); 82 bookm = new QPopupMenu( this );
83 bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); 83 bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) );
84 bookm->insertSeparator(); 84 bookm->insertSeparator();
85 85
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
@@ -1,320 +1,321 @@
1/* 1/*
2 This file is part of the OPIE Project 2 This file is part of the OPIE Project
3 =. 3 =.
4 .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org> 4 .=l. Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
5 .>+-= 5 .>+-=
6_;:, .> :=|. This file is free software; you can 6_;:, .> :=|. This file is free software; you can
7.> <`_, > . <= redistribute it and/or modify it under 7.> <`_, > . <= redistribute it and/or modify it under
8:`=1 )Y*s>-.-- : the terms of the GNU General Public 8:`=1 )Y*s>-.-- : the terms of the GNU General Public
9.="- .-=="i, .._ License as published by the Free Software 9.="- .-=="i, .._ License as published by the Free Software
10- . .-<_> .<> Foundation; either version 2 of the License, 10- . .-<_> .<> Foundation; either version 2 of the License,
11 ._= =} : or (at your option) any later version. 11 ._= =} : or (at your option) any later version.
12 .%`+i> _;_. 12 .%`+i> _;_.
13 .i_,=:_. -<s. This file is distributed in the hope that 13 .i_,=:_. -<s. This file is distributed in the hope that
14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 14 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
15 : .. .:, . . . without even the implied warranty of 15 : .. .:, . . . without even the implied warranty of
16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 16 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General 17 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.= = ; Public License for more details. 18..}^=.= = ; Public License for more details.
19++= -. .` .: 19++= -. .` .:
20: = ...= . :.=- You should have received a copy of the GNU 20: = ...= . :.=- You should have received a copy of the GNU
21-. .:....=;==+<; General Public License along with this file; 21-. .:....=;==+<; General Public License along with this file;
22 -_. . . )=. = see the file COPYING. If not, write to the 22 -_. . . )=. = see the file COPYING. If not, write to the
23 -- :-=` Free Software Foundation, Inc., 23 -- :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include <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
242void WeatherPluginWidget::getPressure( const QString &data ) 243void WeatherPluginWidget::getPressure( const QString &data )
243{ 244{
244 float value; 245 float value;
245 bool ok; 246 bool ok;
246 247
247 int pos = data.find( QRegExp( "[AQ][0-9]+" ), 20 ); 248 int pos = data.find( QRegExp( "[AQ][0-9]+" ), 20 );
248 if ( pos > -1 ) 249 if ( pos > -1 )
249 { 250 {
250 value = data.mid( pos + 1, 4 ).toFloat( &ok ); 251 value = data.mid( pos + 1, 4 ).toFloat( &ok );
251 if ( useMetric ) 252 if ( useMetric )
252 { 253 {
253 if ( data.mid( pos, 1 ) == "A" ) 254 if ( data.mid( pos, 1 ) == "A" )
254 value *= 33.8639 / 100; 255 value *= 33.8639 / 100;
255 dataStr = QString::number( value, 'f', 2 ); 256 dataStr = QString::number( value, 'f', 2 );
256 dataStr.append( tr( " kPa" ) ); 257 dataStr.append( tr( " kPa" ) );
257 } 258 }
258 else 259 else
259 { 260 {
260 if ( data.mid( pos, 1 ) == "Q" ) 261 if ( data.mid( pos, 1 ) == "Q" )
261 value /= 33.8639; 262 value /= 33.8639;
262 else 263 else
263 value /= 100; 264 value /= 100;
264 dataStr = QString::number( value, 'f', 2 ); 265 dataStr = QString::number( value, 'f', 2 );
265 dataStr.append( tr( " Hg" ) ); 266 dataStr.append( tr( " Hg" ) );
266 } 267 }
267 } 268 }
268 else 269 else
269 { 270 {
270 dataStr = tr( "n/a" ); 271 dataStr = tr( "n/a" );
271 } 272 }
272} 273}
273 274
274void WeatherPluginWidget::getIcon(const QString &data ) 275void WeatherPluginWidget::getIcon(const QString &data )
275{ 276{
276 dataStr = "psunny"; 277 dataStr = "psunny";
277 if ( data.find( "CLR ", 20 ) > -1 || 278 if ( data.find( "CLR ", 20 ) > -1 ||
278 data.find( "SKC ", 20 ) > -1 || 279 data.find( "SKC ", 20 ) > -1 ||
279 data.find( "CAVOK ", 20 ) > -1 ) 280 data.find( "CAVOK ", 20 ) > -1 )
280 { 281 {
281 dataStr = "sunny"; 282 dataStr = "sunny";
282 } 283 }
283 else if ( data.find( "SH ", 20 ) > -1 || 284 else if ( data.find( "SH ", 20 ) > -1 ||
284 data.find( "DZ ", 20 ) > -1 || 285 data.find( "DZ ", 20 ) > -1 ||
285 data.find( "RA ", 20 ) > -1 || 286 data.find( "RA ", 20 ) > -1 ||
286 data.find( "UP ", 20 ) > -1 || 287 data.find( "UP ", 20 ) > -1 ||
287 data.find( "BR ", 20 ) > -1 ) 288 data.find( "BR ", 20 ) > -1 )
288 { 289 {
289 dataStr = "shower"; 290 dataStr = "shower";
290 } 291 }
291 else if ( data.find( "TS ", 20 ) > -1 ) 292 else if ( data.find( "TS ", 20 ) > -1 )
292 { 293 {
293 dataStr = "tstorm"; 294 dataStr = "tstorm";
294 } 295 }
295 else if ( data.find( "SN ", 20 ) > -1 || 296 else if ( data.find( "SN ", 20 ) > -1 ||
296 data.find( "SG ", 20 ) > -1 ) 297 data.find( "SG ", 20 ) > -1 )
297 { 298 {
298 dataStr = "snow"; 299 dataStr = "snow";
299 } 300 }
300 else if ( data.find( "FZ ", 20 ) > -1 || 301 else if ( data.find( "FZ ", 20 ) > -1 ||
301 data.find( "GR ", 20 ) > -1 || 302 data.find( "GR ", 20 ) > -1 ||
302 data.find( "GS ", 20 ) > -1 || 303 data.find( "GS ", 20 ) > -1 ||
303 data.find( "PE ", 20 ) > -1 || 304 data.find( "PE ", 20 ) > -1 ||
304 data.find( "IC ", 20 ) > -1 ) 305 data.find( "IC ", 20 ) > -1 )
305 { 306 {
306 dataStr = "sleet"; 307 dataStr = "sleet";
307 } 308 }
308} 309}
309 310
310void WeatherPluginWidget::dataRetrieved( OProcess *process ) 311void WeatherPluginWidget::dataRetrieved( OProcess *process )
311{ 312{
312 if ( process->normalExit() ) 313 if ( process->normalExit() )
313 { 314 {
314 displayWeather(); 315 displayWeather();
315 } 316 }
316 else 317 else
317 { 318 {
318 weatherLabel->setText( tr( "Current weather data not available." ) ); 319 weatherLabel->setText( tr( "Current weather data not available." ) );
319 } 320 }
320} 321}
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}