-rw-r--r-- | noncore/apps/opie-console/filereceive.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-console/filetransfer.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-console/logger.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/opie-console/script.cpp | 6 | ||||
-rw-r--r-- | noncore/apps/opie-gutenbrowser/gutenbrowser.cpp | 26 | ||||
-rw-r--r-- | noncore/apps/opie-gutenbrowser/helpwindow.cpp | 64 |
7 files changed, 56 insertions, 55 deletions
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,69 +1,70 @@ | |||
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 | ||
12 | FileReceive::FileReceive( Type t, IOLayer* lay, const QString& dir ) | 13 | FileReceive::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 | } |
19 | FileReceive::~FileReceive() { | 20 | FileReceive::~FileReceive() { |
20 | } | 21 | } |
21 | void FileReceive::receive() { | 22 | void FileReceive::receive() { |
22 | receive( currentDir() ); | 23 | receive( currentDir() ); |
23 | } | 24 | } |
24 | void FileReceive::receive( const QString& dir ) { | 25 | void 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 | } |
@@ -87,76 +88,77 @@ void FileReceive::receive( const QString& dir ) { | |||
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 | } |
110 | void FileReceive::cancel() { | 111 | void FileReceive::cancel() { |
111 | ::kill(m_pid, 9 ); | 112 | ::kill(m_pid, 9 ); |
112 | } | 113 | } |
113 | void FileReceive::setupChild() { | 114 | void 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 | } |
140 | void FileReceive::slotRead() { | 141 | void 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 | } |
149 | void FileReceive::slotExec() { | 150 | void 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,70 +1,71 @@ | |||
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 | ||
13 | FileTransfer::FileTransfer( Type t, IOLayer* lay ) | 14 | FileTransfer::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 | } |
21 | FileTransfer::~FileTransfer() { | 22 | FileTransfer::~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 | */ |
32 | void FileTransfer::sendFile( const QString& file ) { | 33 | void 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 | } |
@@ -173,76 +174,77 @@ void FileTransfer::slotRead() { | |||
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 | */ |
188 | void FileTransfer::slotProgress( const QStringList& list ) { | 189 | void 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 | } |
231 | void FileTransfer::cancel() { | 232 | void FileTransfer::cancel() { |
232 | if(m_pid > 0) ::kill(m_pid,9 ); | 233 | if(m_pid > 0) ::kill(m_pid,9 ); |
233 | 234 | ||
234 | } | 235 | } |
235 | void FileTransfer::slotExec() { | 236 | void 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 | ||
7 | Logger::Logger() {} | 8 | Logger::Logger() {} |
8 | 9 | ||
9 | Logger::Logger(const QString fileName) { | 10 | Logger::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 | ||
14 | Logger::~Logger() { | 16 | Logger::~Logger() { |
15 | m_file.close(); | 17 | m_file.close(); |
16 | } | 18 | } |
17 | 19 | ||
18 | void Logger::append(QByteArray ar) { | 20 | void 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 | |||
@@ -763,72 +763,73 @@ void MainWindow::slotPaste() { | |||
763 | /* | 763 | /* |
764 | * Save the session | 764 | * Save the session |
765 | */ | 765 | */ |
766 | 766 | ||
767 | void MainWindow::slotSaveSession() { | 767 | void 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 | ||
780 | void MainWindow::slotSaveLog() { | 780 | void 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 | ||
810 | void MainWindow::slotSaveHistory() { | 810 | void 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 | ||
4 | Script::Script() { | 4 | Script::Script() { |
5 | } | 5 | } |
6 | 6 | ||
7 | Script::Script(const QString fileName) { | 7 | Script::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 | ||
13 | void Script::saveTo(const QString fileName) const { | 14 | void 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 | ||
21 | void Script::append(const QByteArray &data) { | 23 | void 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 | ||
27 | QByteArray Script::script() const { | 29 | QByteArray 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 | |||
@@ -784,144 +784,138 @@ bool Gutenbrowser::load( const char *fileName) { | |||
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 | ||
847 | void Gutenbrowser::Search() { | 847 | void 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 | ||
866 | void Gutenbrowser::search_slot( ) { | 860 | void 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 | ||
909 | int Gutenbrowser::doSearch( const QString &s_pattern , bool case_sensitive, bool forward, int line, int col ) { | 903 | int 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(); |
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 | |||
@@ -132,202 +132,200 @@ HelpWindow::HelpWindow( const QString& home_, const QString&, QWidget* parent, c | |||
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 | ||
150 | void HelpWindow::setBackwardAvailable( bool b) | 150 | void HelpWindow::setBackwardAvailable( bool b) |
151 | { | 151 | { |
152 | menuBar()->setItemEnabled( backwardId, b); | 152 | menuBar()->setItemEnabled( backwardId, b); |
153 | } | 153 | } |
154 | 154 | ||
155 | void HelpWindow::setForwardAvailable( bool b) | 155 | void HelpWindow::setForwardAvailable( bool b) |
156 | { | 156 | { |
157 | menuBar()->setItemEnabled( forwardId, b); | 157 | menuBar()->setItemEnabled( forwardId, b); |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | void HelpWindow::textChanged() | 161 | void 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 | ||
191 | HelpWindow::~HelpWindow() | 191 | HelpWindow::~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 | |||
226 | void HelpWindow::openFile() | 219 | void 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 | ||
235 | void HelpWindow::newWindow() | 228 | void HelpWindow::newWindow() |
236 | { | 229 | { |
237 | ( new HelpWindow(browser->source(), "qbrowser") )->show(); | 230 | ( new HelpWindow(browser->source(), "qbrowser") )->show(); |
238 | } | 231 | } |
239 | 232 | ||
240 | void HelpWindow::print() | 233 | void 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 | ||
278 | void HelpWindow::pathSelected( const QString &_path ) | 271 | void 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 | ||
293 | void HelpWindow::readHistory() | 286 | void 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 | ||
306 | void HelpWindow::readBookmarks() | 302 | void 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 | ||
317 | void HelpWindow::histChosen( int i ) | 315 | void 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 | ||
323 | void HelpWindow::bookmChosen( int i ) | 321 | void 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 | ||
329 | void HelpWindow::addBookmark() | 327 | void HelpWindow::addBookmark() |
330 | { | 328 | { |
331 | mBookmarks[ bookm->insertItem( caption() ) ] = caption(); | 329 | mBookmarks[ bookm->insertItem( caption() ) ] = caption(); |
332 | } | 330 | } |
333 | 331 | ||