• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
global.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 David Faure <faure@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include <config.h>
20 
21 #include <sys/types.h>
22 #include <sys/wait.h>
23 #include <sys/uio.h>
24 
25 #include <assert.h>
26 #include <signal.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <stdio.h>
31 
32 #include "tdeio/global.h"
33 #include "tdeio/job.h"
34 
35 #include <kdebug.h>
36 #include <tdelocale.h>
37 #include <tdeglobal.h>
38 #include <tdeprotocolmanager.h>
39 #include <kde_file.h>
40 
41 #ifdef HAVE_VOLMGT
42 #include <volmgt.h>
43 #endif
44 
45 TDEIO_EXPORT TQString TDEIO::convertSizeWithBytes( TDEIO::filesize_t size )
46 {
47  if ( size >= 1024 )
48  return convertSize( size ) + " (" + i18n( "%1 B" ).arg( TDEGlobal::locale()->formatNumber(size, 0) ) + ")";
49  else
50  return convertSize( size );
51 }
52 
53 TDEIO_EXPORT TQString TDEIO::convertSize( TDEIO::filesize_t size )
54 {
55  double fsize = size;
56  TQString s;
57  // Giga-byte
58  if ( size >= 1073741824 )
59  {
60  fsize /= 1073741824.0;
61  if ( fsize > 1024 ) // Tera-byte
62  s = i18n( "%1 TB" ).arg( TDEGlobal::locale()->formatNumber(fsize / 1024.0, 1));
63  else
64  s = i18n( "%1 GB" ).arg( TDEGlobal::locale()->formatNumber(fsize, 1));
65  }
66  // Mega-byte
67  else if ( size >= 1048576 )
68  {
69  fsize /= 1048576.0;
70  s = i18n( "%1 MB" ).arg( TDEGlobal::locale()->formatNumber(fsize, 1));
71  }
72  // Kilo-byte
73  else if ( size >= 1024 )
74  {
75  fsize /= 1024.0;
76  s = i18n( "%1 KB" ).arg( TDEGlobal::locale()->formatNumber(fsize, 1));
77  }
78  // Just byte
79  else if ( size > 0 )
80  {
81  s = i18n( "%1 B" ).arg( TDEGlobal::locale()->formatNumber(fsize, 0));
82  }
83  // Nothing
84  else
85  {
86  s = i18n( "0 B" );
87  }
88  return s;
89 }
90 
91 TDEIO_EXPORT TQString TDEIO::convertSizeFromKB( TDEIO::filesize_t kbSize )
92 {
93  return convertSize(kbSize * 1024);
94 }
95 
96 TDEIO_EXPORT TQString TDEIO::number( TDEIO::filesize_t size )
97 {
98  char charbuf[256];
99  sprintf(charbuf, "%lld", size);
100  return TQString::fromLatin1(charbuf);
101 }
102 
103 TDEIO_EXPORT unsigned int TDEIO::calculateRemainingSeconds( TDEIO::filesize_t totalSize,
104  TDEIO::filesize_t processedSize, TDEIO::filesize_t speed )
105 {
106  if ( (speed != 0) && (totalSize != 0) )
107  return ( totalSize - processedSize ) / speed;
108  else
109  return 0;
110 }
111 
112 TDEIO_EXPORT TQString TDEIO::convertSeconds( unsigned int seconds )
113 {
114  unsigned int days = seconds / 86400;
115  unsigned int hours = (seconds - (days * 86400)) / 3600;
116  unsigned int mins = (seconds - (days * 86400) - (hours * 3600)) / 60;
117  seconds = (seconds - (days * 86400) - (hours * 3600) - (mins * 60));
118 
119  const TQTime time(hours, mins, seconds);
120  const TQString timeStr( TDEGlobal::locale()->formatTime(time, true /*with seconds*/, true /*duration*/) );
121  if ( days > 0 )
122  return i18n("1 day %1", "%n days %1", days).arg(timeStr);
123  else
124  return timeStr;
125 }
126 
127 TDEIO_EXPORT TQTime TDEIO::calculateRemaining( TDEIO::filesize_t totalSize, TDEIO::filesize_t processedSize, TDEIO::filesize_t speed )
128 {
129  TQTime remainingTime;
130 
131  if ( speed != 0 ) {
132  TDEIO::filesize_t secs;
133  if ( totalSize == 0 ) {
134  secs = 0;
135  } else {
136  secs = ( totalSize - processedSize ) / speed;
137  }
138  if (secs >= (24*60*60)) // Limit to 23:59:59
139  secs = (24*60*60)-1;
140  int hr = secs / ( 60 * 60 );
141  int mn = ( secs - hr * 60 * 60 ) / 60;
142  int sc = ( secs - hr * 60 * 60 - mn * 60 );
143 
144  remainingTime.setHMS( hr, mn, sc );
145  }
146 
147  return remainingTime;
148 }
149 
150 TDEIO_EXPORT TQString TDEIO::itemsSummaryString(uint items, uint files, uint dirs, TDEIO::filesize_t size, bool showSize)
151 {
152  TQString text = items == 0 ? i18n( "No Items" ) : i18n( "One Item", "%n Items", items );
153  text += " - ";
154  text += files == 0 ? i18n( "No Files" ) : i18n( "One File", "%n Files", files );
155  if ( showSize && files > 0 )
156  {
157  text += " ";
158  text += i18n("(%1 Total)").arg(TDEIO::convertSize( size ) );
159  }
160  text += " - ";
161  text += dirs == 0 ? i18n( "No Folders" ) : i18n("One Folder", "%n Folders", dirs);
162  return text;
163 }
164 
165 TDEIO_EXPORT TQString TDEIO::encodeFileName( const TQString & _str )
166 {
167  TQString str( _str );
168  bool unicode_supported = (TQString::fromLocal8Bit(TQString(TQChar((uint)0x2215)).local8Bit())[0].unicode() != 0x3f);
169 
170  int i = 0;
171  while ( ( i = str.find( "%", i ) ) != -1 ) {
172  str.replace( i, 1, "%%");
173  i += 2;
174  }
175  while ( ( i = str.find( "/" ) ) != -1 ) {
176  if (unicode_supported) {
177  // Use U+2215 (DIVISION SLASH) to represent the forward slash
178  // While U+2044 (FRACTION SLASH) is a tempting replacement, it can indicate to
179  // rendering engines that a combined fraction character should be displayed
180  str.replace( i, 1, TQChar((uint)0x2215));
181  }
182  else {
183  // Unicode does not appear to be supported on this system!
184  // Fall back to older encoding method...
185  str.replace( i, 1, "%2f");
186  }
187  }
188  return str;
189 }
190 
191 TDEIO_EXPORT TQString TDEIO::decodeFileName( const TQString & _str )
192 {
193  TQString str;
194  bool unicode_supported = (TQString::fromLocal8Bit(TQString(TQChar((uint)0x2215)).local8Bit())[0].unicode() != 0x3f);
195 
196  unsigned int i = 0;
197  for ( ; i < _str.length() ; ++i ) {
198  if ( _str[i]=='%' ) {
199  if ( _str[i+1]=='%' ) // %% -> %
200  {
201  str.append('%');
202  ++i;
203  }
204  else if ((!unicode_supported) && ( _str[i+1]=='2' && (i+2<_str.length()) && _str[i+2].lower()=='f' )) // %2f -> /
205  {
206  str.append('/');
207  i += 2;
208  }
209  else
210  {
211  str.append('%');
212  }
213  }
214  else if ( _str[i] == TQChar((uint)0x2215) ) {
215  str.append('/');
216  }
217  else {
218  str.append(_str[i]);
219  }
220  }
221 
222  return str;
223 }
224 
225 TDEIO_EXPORT TQString TDEIO::Job::errorString() const
226 {
227  return TDEIO::buildErrorString(m_error, m_errorText);
228 }
229 
230 TDEIO_EXPORT TQString TDEIO::buildErrorString(int errorCode, const TQString &errorText)
231 {
232  TQString result;
233 
234  switch( errorCode )
235  {
236  case TDEIO::ERR_CANNOT_OPEN_FOR_READING:
237  result = i18n( "Could not read %1." ).arg( errorText );
238  break;
239  case TDEIO::ERR_CANNOT_OPEN_FOR_WRITING:
240  result = i18n( "Could not write to %1." ).arg( errorText );
241  break;
242  case TDEIO::ERR_CANNOT_LAUNCH_PROCESS:
243  result = i18n( "Could not start process %1." ).arg( errorText );
244  break;
245  case TDEIO::ERR_INTERNAL:
246  result = i18n( "Internal Error\nPlease send a full bug report at http://bugs.trinitydesktop.org\n%1" ).arg( errorText );
247  break;
248  case TDEIO::ERR_MALFORMED_URL:
249  result = i18n( "Malformed URL %1." ).arg( errorText );
250  break;
251  case TDEIO::ERR_UNSUPPORTED_PROTOCOL:
252  result = i18n( "The protocol %1 is not supported." ).arg( errorText );
253  break;
254  case TDEIO::ERR_NO_SOURCE_PROTOCOL:
255  result = i18n( "The protocol %1 is only a filter protocol.").arg( errorText );
256  break;
257  case TDEIO::ERR_UNSUPPORTED_ACTION:
258  result = errorText;
259 // result = i18n( "Unsupported action %1" ).arg( errorText );
260  break;
261  case TDEIO::ERR_IS_DIRECTORY:
262  result = i18n( "%1 is a folder, but a file was expected." ).arg( errorText );
263  break;
264  case TDEIO::ERR_IS_FILE:
265  result = i18n( "%1 is a file, but a folder was expected." ).arg( errorText );
266  break;
267  case TDEIO::ERR_DOES_NOT_EXIST:
268  result = i18n( "The file or folder %1 does not exist." ).arg( errorText );
269  break;
270  case TDEIO::ERR_FILE_ALREADY_EXIST:
271  result = i18n( "A file named %1 already exists." ).arg( errorText );
272  break;
273  case TDEIO::ERR_DIR_ALREADY_EXIST:
274  result = i18n( "A folder named %1 already exists." ).arg( errorText );
275  break;
276  case TDEIO::ERR_UNKNOWN_HOST:
277  result = errorText.isEmpty() ? i18n( "No hostname specified." ) : i18n( "Unknown host %1" ).arg( errorText );
278  break;
279  case TDEIO::ERR_ACCESS_DENIED:
280  result = i18n( "Access denied to %1." ).arg( errorText );
281  break;
282  case TDEIO::ERR_WRITE_ACCESS_DENIED:
283  result = i18n( "Access denied.\nCould not write to %1." ).arg( errorText );
284  break;
285  case TDEIO::ERR_CANNOT_ENTER_DIRECTORY:
286  result = i18n( "Could not enter folder %1." ).arg( errorText );
287  break;
288  case TDEIO::ERR_PROTOCOL_IS_NOT_A_FILESYSTEM:
289  result = i18n( "The protocol %1 does not implement a folder service." ).arg( errorText );
290  break;
291  case TDEIO::ERR_CYCLIC_LINK:
292  result = i18n( "Found a cyclic link in %1." ).arg( errorText );
293  break;
294  case TDEIO::ERR_USER_CANCELED:
295  // Do nothing in this case. The user doesn't need to be told what he just did.
296  break;
297  case TDEIO::ERR_CYCLIC_COPY:
298  result = i18n( "Found a cyclic link while copying %1." ).arg( errorText );
299  break;
300  case TDEIO::ERR_COULD_NOT_CREATE_SOCKET:
301  result = i18n( "Could not create socket for accessing %1." ).arg( errorText );
302  break;
303  case TDEIO::ERR_COULD_NOT_CONNECT:
304  result = i18n( "Could not connect to host %1." ).arg( errorText.isEmpty() ? TQString::fromLatin1("localhost") : errorText );
305  break;
306  case TDEIO::ERR_CONNECTION_BROKEN:
307  result = i18n( "Connection to host %1 is broken." ).arg( errorText );
308  break;
309  case TDEIO::ERR_NOT_FILTER_PROTOCOL:
310  result = i18n( "The protocol %1 is not a filter protocol." ).arg( errorText );
311  break;
312  case TDEIO::ERR_COULD_NOT_MOUNT:
313  result = i18n( "Could not mount device.\nThe reported error was:\n%1" ).arg( errorText );
314  break;
315  case TDEIO::ERR_COULD_NOT_UNMOUNT:
316  result = i18n( "Could not unmount device.\nThe reported error was:\n%1" ).arg( errorText );
317  break;
318  case TDEIO::ERR_COULD_NOT_READ:
319  result = i18n( "Could not read file %1." ).arg( errorText );
320  break;
321  case TDEIO::ERR_COULD_NOT_WRITE:
322  result = i18n( "Could not write to file %1." ).arg( errorText );
323  break;
324  case TDEIO::ERR_COULD_NOT_BIND:
325  result = i18n( "Could not bind %1." ).arg( errorText );
326  break;
327  case TDEIO::ERR_COULD_NOT_LISTEN:
328  result = i18n( "Could not listen %1." ).arg( errorText );
329  break;
330  case TDEIO::ERR_COULD_NOT_ACCEPT:
331  result = i18n( "Could not accept %1." ).arg( errorText );
332  break;
333  case TDEIO::ERR_COULD_NOT_LOGIN:
334  result = errorText;
335  break;
336  case TDEIO::ERR_COULD_NOT_STAT:
337  result = i18n( "Could not access %1." ).arg( errorText );
338  break;
339  case TDEIO::ERR_COULD_NOT_CLOSEDIR:
340  result = i18n( "Could not terminate listing %1." ).arg( errorText );
341  break;
342  case TDEIO::ERR_COULD_NOT_MKDIR:
343  result = i18n( "Could not make folder %1." ).arg( errorText );
344  break;
345  case TDEIO::ERR_COULD_NOT_RMDIR:
346  result = i18n( "Could not remove folder %1." ).arg( errorText );
347  break;
348  case TDEIO::ERR_CANNOT_RESUME:
349  result = i18n( "Could not resume file %1." ).arg( errorText );
350  break;
351  case TDEIO::ERR_CANNOT_RENAME:
352  result = i18n( "Could not rename file %1." ).arg( errorText );
353  break;
354  case TDEIO::ERR_CANNOT_CHMOD:
355  result = i18n( "Could not change permissions for %1." ).arg( errorText );
356  break;
357  case TDEIO::ERR_CANNOT_DELETE:
358  result = i18n( "Could not delete file %1." ).arg( errorText );
359  break;
360  case TDEIO::ERR_SLAVE_DIED:
361  result = i18n( "The process for the %1 protocol died unexpectedly." ).arg( errorText );
362  break;
363  case TDEIO::ERR_OUT_OF_MEMORY:
364  result = i18n( "Error. Out of memory.\n%1" ).arg( errorText );
365  break;
366  case TDEIO::ERR_UNKNOWN_PROXY_HOST:
367  result = i18n( "Unknown proxy host\n%1" ).arg( errorText );
368  break;
369  case TDEIO::ERR_COULD_NOT_AUTHENTICATE:
370  result = i18n( "Authorization failed, %1 authentication not supported" ).arg( errorText );
371  break;
372  case TDEIO::ERR_ABORTED:
373  result = i18n( "User canceled action\n%1" ).arg( errorText );
374  break;
375  case TDEIO::ERR_INTERNAL_SERVER:
376  result = i18n( "Internal error in server\n%1" ).arg( errorText );
377  break;
378  case TDEIO::ERR_SERVER_TIMEOUT:
379  result = i18n( "Timeout on server\n%1" ).arg( errorText );
380  break;
381  case TDEIO::ERR_UNKNOWN:
382  result = i18n( "Unknown error\n%1" ).arg( errorText );
383  break;
384  case TDEIO::ERR_UNKNOWN_INTERRUPT:
385  result = i18n( "Unknown interrupt\n%1" ).arg( errorText );
386  break;
387 /*
388  case TDEIO::ERR_CHECKSUM_MISMATCH:
389  if (errorText)
390  result = i18n( "Warning: MD5 Checksum for %1 does not match checksum returned from server" ).arg(errorText);
391  else
392  result = i18n( "Warning: MD5 Checksum for %1 does not match checksum returned from server" ).arg("document");
393  break;
394 */
395  case TDEIO::ERR_CANNOT_DELETE_ORIGINAL:
396  result = i18n( "Could not delete original file %1.\nPlease check permissions." ).arg( errorText );
397  break;
398  case TDEIO::ERR_CANNOT_DELETE_PARTIAL:
399  result = i18n( "Could not delete partial file %1.\nPlease check permissions." ).arg( errorText );
400  break;
401  case TDEIO::ERR_CANNOT_RENAME_ORIGINAL:
402  result = i18n( "Could not rename original file %1.\nPlease check permissions." ).arg( errorText );
403  break;
404  case TDEIO::ERR_CANNOT_RENAME_PARTIAL:
405  result = i18n( "Could not rename partial file %1.\nPlease check permissions." ).arg( errorText );
406  break;
407  case TDEIO::ERR_CANNOT_SYMLINK:
408  result = i18n( "Could not create symlink %1.\nPlease check permissions." ).arg( errorText );
409  break;
410  case TDEIO::ERR_NO_CONTENT:
411  result = errorText;
412  break;
413  case TDEIO::ERR_DISK_FULL:
414  result = i18n( "Could not write file %1.\nDisk full." ).arg( errorText );
415  break;
416  case TDEIO::ERR_IDENTICAL_FILES:
417  result = i18n( "The source and destination are the same file.\n%1" ).arg( errorText );
418  break;
419  case TDEIO::ERR_SLAVE_DEFINED:
420  result = errorText;
421  break;
422  case TDEIO::ERR_UPGRADE_REQUIRED:
423  result = i18n( "%1 is required by the server, but is not available." ).arg(errorText);
424  break;
425  case TDEIO::ERR_POST_DENIED:
426  result = i18n( "Access to restricted port in POST denied.");
427  break;
428  case TDEIO::ERR_OFFLINE_MODE:
429  result = i18n( "Could not access %1.\nOffline mode active.").arg( errorText );
430  break;
431  default:
432  result = i18n( "Unknown error code %1\n%2\nPlease send a full bug report at http://bugs.trinitydesktop.org." ).arg( errorCode ).arg( errorText );
433  break;
434  }
435 
436  return result;
437 }
438 
439 TDEIO_EXPORT TQString TDEIO::unsupportedActionErrorString(const TQString &protocol, int cmd) {
440  switch (cmd) {
441  case CMD_CONNECT:
442  return i18n("Opening connections is not supported with the protocol %1." ).arg(protocol);
443  case CMD_DISCONNECT:
444  return i18n("Closing connections is not supported with the protocol %1." ).arg(protocol);
445  case CMD_STAT:
446  return i18n("Accessing files is not supported with the protocol %1.").arg(protocol);
447  case CMD_PUT:
448  return i18n("Writing to %1 is not supported.").arg(protocol);
449  case CMD_SPECIAL:
450  return i18n("There are no special actions available for protocol %1.").arg(protocol);
451  case CMD_LISTDIR:
452  return i18n("Listing folders is not supported for protocol %1.").arg(protocol);
453  case CMD_GET:
454  return i18n("Retrieving data from %1 is not supported.").arg(protocol);
455  case CMD_MIMETYPE:
456  return i18n("Retrieving mime type information from %1 is not supported.").arg(protocol);
457  case CMD_RENAME:
458  return i18n("Renaming or moving files within %1 is not supported.").arg(protocol);
459  case CMD_SYMLINK:
460  return i18n("Creating symlinks is not supported with protocol %1.").arg(protocol);
461  case CMD_COPY:
462  return i18n("Copying files within %1 is not supported.").arg(protocol);
463  case CMD_DEL:
464  return i18n("Deleting files from %1 is not supported.").arg(protocol);
465  case CMD_MKDIR:
466  return i18n("Creating folders is not supported with protocol %1.").arg(protocol);
467  case CMD_CHMOD:
468  return i18n("Changing the attributes of files is not supported with protocol %1.").arg(protocol);
469  case CMD_SUBURL:
470  return i18n("Using sub-URLs with %1 is not supported.").arg(protocol);
471  case CMD_MULTI_GET:
472  return i18n("Multiple get is not supported with protocol %1.").arg(protocol);
473  default:
474  return i18n("Protocol %1 does not support action %2.").arg(protocol).arg(cmd);
475  }/*end switch*/
476 }
477 
478 TDEIO_EXPORT TQStringList TDEIO::Job::detailedErrorStrings( const KURL *reqUrl /*= 0L*/,
479  int method /*= -1*/ ) const
480 {
481  TQString errorName, techName, description, ret2;
482  TQStringList causes, solutions, ret;
483 
484  TQByteArray raw = rawErrorDetail( m_error, m_errorText, reqUrl, method );
485  TQDataStream stream(raw, IO_ReadOnly);
486 
487  stream >> errorName >> techName >> description >> causes >> solutions;
488 
489  TQString url, protocol, datetime;
490  if ( reqUrl ) {
491  url = reqUrl->htmlURL();
492  protocol = reqUrl->protocol();
493  } else {
494  url = i18n( "(unknown)" );
495  }
496 
497  datetime = TDEGlobal::locale()->formatDateTime( TQDateTime::currentDateTime(),
498  false );
499 
500  ret << errorName;
501  ret << TQString::fromLatin1( "<qt><p><b>" ) + errorName +
502  TQString::fromLatin1( "</b></p><p>" ) + description +
503  TQString::fromLatin1( "</p>" );
504  ret2 = TQString::fromLatin1( "<qt><p>" );
505  if ( !techName.isEmpty() )
506  ret2 += i18n( "<b>Technical reason</b>: " ) + techName + TQString::fromLatin1( "</p>" );
507  ret2 += i18n( "</p><p><b>Details of the request</b>:" );
508  ret2 += i18n( "</p><ul><li>URL: %1</li>" ).arg( url );
509  if ( !protocol.isEmpty() ) {
510  ret2 += i18n( "<li>Protocol: %1</li>" ).arg( protocol );
511  }
512  ret2 += i18n( "<li>Date and time: %1</li>" ).arg( datetime );
513  ret2 += i18n( "<li>Additional information: %1</li></ul>" ).arg( m_errorText );
514  if ( !causes.isEmpty() ) {
515  ret2 += i18n( "<p><b>Possible causes</b>:</p><ul><li>" );
516  ret2 += causes.join( "</li><li>" );
517  ret2 += TQString::fromLatin1( "</li></ul>" );
518  }
519  if ( !solutions.isEmpty() ) {
520  ret2 += i18n( "<p><b>Possible solutions</b>:</p><ul><li>" );
521  ret2 += solutions.join( "</li><li>" );
522  ret2 += TQString::fromLatin1( "</li></ul>" );
523  }
524  ret << ret2;
525  return ret;
526 }
527 
528 TDEIO_EXPORT TQByteArray TDEIO::rawErrorDetail(int errorCode, const TQString &errorText,
529  const KURL *reqUrl /*= 0L*/, int /*method = -1*/ )
530 {
531  TQString url, host, protocol, datetime, domain, path, dir, filename;
532  bool isSlaveNetwork = false;
533  if ( reqUrl ) {
534  url = reqUrl->prettyURL();
535  host = reqUrl->host();
536  protocol = reqUrl->protocol();
537 
538  if ( host.left(4) == "www." )
539  domain = host.mid(4);
540  else
541  domain = host;
542 
543  path = reqUrl->path(1);
544  filename = reqUrl->fileName();
545  dir = path + filename;
546 
547  // detect if protocol is a network protocol...
548  // add your hacks here...
549  if ( protocol == "http" ||
550  protocol == "https" ||
551  protocol == "ftp" ||
552  protocol == "sftp" ||
553  protocol == "webdav" ||
554  protocol == "webdavs" ||
555  protocol == "finger" ||
556  protocol == "fish" ||
557  protocol == "gopher" ||
558  protocol == "imap" ||
559  protocol == "imaps" ||
560  protocol == "lan" ||
561  protocol == "ldap" ||
562  protocol == "mailto" ||
563  protocol == "news" ||
564  protocol == "nntp" ||
565  protocol == "pop3" ||
566  protocol == "pop3s" ||
567  protocol == "smtp" ||
568  protocol == "smtps" ||
569  protocol == "telnet"
570  ) {
571  isSlaveNetwork = false;
572  }
573  } else {
574  // assume that the errorText has the location we are interested in
575  url = host = domain = path = filename = dir = errorText;
576  protocol = i18n( "(unknown)" );
577  }
578 
579  datetime = TDEGlobal::locale()->formatDateTime( TQDateTime::currentDateTime(),
580  false );
581 
582  TQString errorName, techName, description;
583  TQStringList causes, solutions;
584 
585  // c == cause, s == solution
586  TQString sSysadmin = i18n( "Contact your appropriate computer support system, "
587  "whether the system administrator, or technical support group for further "
588  "assistance." );
589  TQString sServeradmin = i18n( "Contact the administrator of the server "
590  "for further assistance." );
591  // FIXME active link to permissions dialog
592  TQString sAccess = i18n( "Check your access permissions on this resource." );
593  TQString cAccess = i18n( "Your access permissions may be inadequate to "
594  "perform the requested operation on this resource." );
595  TQString cLocked = i18n( "The file may be in use (and thus locked) by "
596  "another user or application." );
597  TQString sQuerylock = i18n( "Check to make sure that no other "
598  "application or user is using the file or has locked the file." );
599  TQString cHardware = i18n( "Although unlikely, a hardware error may have "
600  "occurred." );
601  TQString cBug = i18n( "You may have encountered a bug in the program." );
602  TQString cBuglikely = i18n( "This is most likely to be caused by a bug in the "
603  "program. Please consider submitting a full bug report as detailed below." );
604  TQString sUpdate = i18n( "Update your software to the latest version. "
605  "Your distribution should provide tools to update your software." );
606  TQString sBugreport = i18n( "When all else fails, please consider helping the "
607  "TDE team or the third party maintainer of this software by submitting a "
608  "high quality bug report. If the software is provided by a third party, "
609  "please contact them directly. Otherwise, first look to see if "
610  "the same bug has been submitted by someone else by searching at the "
611  "<a href=\"http://bugs.trinitydesktop.org/\">TDE bug reporting website</a>. If not, take "
612  "note of the details given above, and include them in your bug report, along "
613  "with as many other details as you think might help." );
614  TQString cNetwork = i18n( "There may have been a problem with your network "
615  "connection." );
616  // FIXME netconf kcontrol link
617  TQString cNetconf = i18n( "There may have been a problem with your network "
618  "configuration. If you have been accessing the Internet with no problems "
619  "recently, this is unlikely." );
620  TQString cNetpath = i18n( "There may have been a problem at some point along "
621  "the network path between the server and this computer." );
622  TQString sTryagain = i18n( "Try again, either now or at a later time." );
623  TQString cProtocol = i18n( "A protocol error or incompatibility may have occurred." );
624  TQString sExists = i18n( "Ensure that the resource exists, and try again." );
625  TQString cExists = i18n( "The specified resource may not exist." );
626  TQString cTypo = i18n( "You may have incorrectly typed the location." );
627  TQString sTypo = i18n( "Double-check that you have entered the correct location "
628  "and try again." );
629  TQString sNetwork = i18n( "Check your network connection status." );
630 
631  switch( errorCode ) {
632  case TDEIO::ERR_CANNOT_OPEN_FOR_READING:
633  errorName = i18n( "Cannot Open Resource For Reading" );
634  description = i18n( "This means that the contents of the requested file "
635  "or folder <strong>%1</strong> could not be retrieved, as read "
636  "access could not be obtained." ).arg( dir );
637  causes << i18n( "You may not have permissions to read the file or open "
638  "the folder.") << cLocked << cHardware;
639  solutions << sAccess << sQuerylock << sSysadmin;
640  break;
641 
642  case TDEIO::ERR_CANNOT_OPEN_FOR_WRITING:
643  errorName = i18n( "Cannot Open Resource For Writing" );
644  description = i18n( "This means that the file, <strong>%1</strong>, could "
645  "not be written to as requested, because access with permission to "
646  "write could not be obtained." ).arg( filename );
647  causes << cAccess << cLocked << cHardware;
648  solutions << sAccess << sQuerylock << sSysadmin;
649  break;
650 
651  case TDEIO::ERR_CANNOT_LAUNCH_PROCESS:
652  errorName = i18n( "Cannot Initiate the %1 Protocol" ).arg( protocol );
653  techName = i18n( "Unable to Launch Process" );
654  description = i18n( "The program on your computer which provides access "
655  "to the <strong>%1</strong> protocol could not be started. This is "
656  "usually due to technical reasons." ).arg( protocol );
657  causes << i18n( "The program which provides compatibility with this "
658  "protocol may not have been updated with your last update of TDE. "
659  "This can cause the program to be incompatible with the current version "
660  "and thus not start." ) << cBug;
661  solutions << sUpdate << sSysadmin;
662  break;
663 
664  case TDEIO::ERR_INTERNAL:
665  errorName = i18n( "Internal Error" );
666  description = i18n( "The program on your computer which provides access "
667  "to the <strong>%1</strong> protocol has reported an internal error." )
668  .arg( protocol );
669  causes << cBuglikely;
670  solutions << sUpdate << sBugreport;
671  break;
672 
673  case TDEIO::ERR_MALFORMED_URL:
674  errorName = i18n( "Improperly Formatted URL" );
675  description = i18n( "The <strong>U</strong>niform <strong>R</strong>esource "
676  "<strong>L</strong>ocator (URL) that you entered was not properly "
677  "formatted. The format of a URL is generally as follows:"
678  "<blockquote><strong>protocol://user:password@www.example.org:port/folder/"
679  "filename.extension?query=value</strong></blockquote>" );
680  solutions << sTypo;
681  break;
682 
683  case TDEIO::ERR_UNSUPPORTED_PROTOCOL:
684  errorName = i18n( "Unsupported Protocol %1" ).arg( protocol );
685  description = i18n( "The protocol <strong>%1</strong> is not supported "
686  "by the TDE programs currently installed on this computer." )
687  .arg( protocol );
688  causes << i18n( "The requested protocol may not be supported." )
689  << i18n( "The versions of the %1 protocol supported by this computer and "
690  "the server may be incompatible." ).arg( protocol );
691  solutions << i18n( "You may perform a search on the Trinity website for a TDE "
692  "program (called a tdeioslave, ioslave or tdeio) which supports this protocol. "
693  "Places to search include <a href=\"https://mirror.git.trinitydesktop.org/cgit/\">"
694  "https://mirror.git.trinitydesktop.org/cgit/</a> or the repos for your distribution." )
695  << sUpdate << sSysadmin;
696  break;
697 
698  case TDEIO::ERR_NO_SOURCE_PROTOCOL:
699  errorName = i18n( "URL Does Not Refer to a Resource." );
700  techName = i18n( "Protocol is a Filter Protocol" );
701  description = i18n( "The <strong>U</strong>niform <strong>R</strong>esource "
702  "<strong>L</strong>ocator (URL) that you entered did not refer to a "
703  "specific resource." );
704  causes << i18n( "TDE is able to communicate through a protocol within a "
705  "protocol; the protocol specified is only for use in such situations, "
706  "however this is not one of these situations. This is a rare event, and "
707  "is likely to indicate a programming error." );
708  solutions << sTypo;
709  break;
710 
711  case TDEIO::ERR_UNSUPPORTED_ACTION:
712  errorName = i18n( "Unsupported Action: %1" ).arg( errorText );
713  description = i18n( "The requested action is not supported by the TDE "
714  "program which is implementing the <strong>%1</strong> protocol." )
715  .arg( protocol );
716  causes << i18n( "This error is very much dependent on the TDE program. The "
717  "additional information should give you more information than is available "
718  "to the TDE input/output architecture." );
719  solutions << i18n( "Attempt to find another way to accomplish the same "
720  "outcome." );
721  break;
722 
723  case TDEIO::ERR_IS_DIRECTORY:
724  errorName = i18n( "File Expected" );
725  description = i18n( "The request expected a file, however the "
726  "folder <strong>%1</strong> was found instead." ).arg( dir );
727  causes << i18n( "This may be an error on the server side." ) << cBug;
728  solutions << sUpdate << sSysadmin;
729  break;
730 
731  case TDEIO::ERR_IS_FILE:
732  errorName = i18n( "Folder Expected" );
733  description = i18n( "The request expected a folder, however "
734  "the file <strong>%1</strong> was found instead." ).arg( filename );
735  causes << cBug;
736  solutions << sUpdate << sSysadmin;
737  break;
738 
739  case TDEIO::ERR_DOES_NOT_EXIST:
740  errorName = i18n( "File or Folder Does Not Exist" );
741  description = i18n( "The specified file or folder <strong>%1</strong> "
742  "does not exist." ).arg( dir );
743  causes << cBug;
744  solutions << sUpdate << sSysadmin;
745  break;
746 
747  case TDEIO::ERR_FILE_ALREADY_EXIST:
748  errorName = i18n( "File Already Exists" );
749  description = i18n( "The requested file could not be created because a "
750  "file with the same name already exists." );
751  solutions << i18n ( "Try moving the current file out of the way first, "
752  "and then try again." )
753  << i18n ( "Delete the current file and try again." )
754  << i18n( "Choose an alternate filename for the new file." );
755  break;
756 
757  case TDEIO::ERR_DIR_ALREADY_EXIST:
758  errorName = i18n( "Folder Already Exists" );
759  description = i18n( "The requested folder could not be created because "
760  "a folder with the same name already exists." );
761  solutions << i18n( "Try moving the current folder out of the way first, "
762  "and then try again." )
763  << i18n( "Delete the current folder and try again." )
764  << i18n( "Choose an alternate name for the new folder." );
765  break;
766 
767  case TDEIO::ERR_UNKNOWN_HOST:
768  errorName = i18n( "Unknown Host" );
769  description = i18n( "An unknown host error indicates that the server with "
770  "the requested name, <strong>%1</strong>, could not be "
771  "located on the Internet." ).arg( host );
772  causes << i18n( "The name that you typed, %1, may not exist: it may be "
773  "incorrectly typed." ).arg( host )
774  << cNetwork << cNetconf;
775  solutions << sNetwork << sSysadmin;
776  break;
777 
778  case TDEIO::ERR_ACCESS_DENIED:
779  errorName = i18n( "Access Denied" );
780  description = i18n( "Access was denied to the specified resource, "
781  "<strong>%1</strong>." ).arg( url );
782  causes << i18n( "You may have supplied incorrect authentication details or "
783  "none at all." )
784  << i18n( "Your account may not have permission to access the "
785  "specified resource." );
786  solutions << i18n( "Retry the request and ensure your authentication details "
787  "are entered correctly." ) << sSysadmin;
788  if ( !isSlaveNetwork ) solutions << sServeradmin;
789  break;
790 
791  case TDEIO::ERR_WRITE_ACCESS_DENIED:
792  errorName = i18n( "Write Access Denied" );
793  description = i18n( "This means that an attempt to write to the file "
794  "<strong>%1</strong> was rejected." ).arg( filename );
795  causes << cAccess << cLocked << cHardware;
796  solutions << sAccess << sQuerylock << sSysadmin;
797  break;
798 
799  case TDEIO::ERR_CANNOT_ENTER_DIRECTORY:
800  errorName = i18n( "Unable to Enter Folder" );
801  description = i18n( "This means that an attempt to enter (in other words, "
802  "to open) the requested folder <strong>%1</strong> was rejected." )
803  .arg( dir );
804  causes << cAccess << cLocked;
805  solutions << sAccess << sQuerylock << sSysadmin;
806  break;
807 
808  case TDEIO::ERR_PROTOCOL_IS_NOT_A_FILESYSTEM:
809  errorName = i18n( "Folder Listing Unavailable" );
810  techName = i18n( "Protocol %1 is not a Filesystem" ).arg( protocol );
811  description = i18n( "This means that a request was made which requires "
812  "determining the contents of the folder, and the TDE program supporting "
813  "this protocol is unable to do so." );
814  causes << cBug;
815  solutions << sUpdate << sBugreport;
816  break;
817 
818  case TDEIO::ERR_CYCLIC_LINK:
819  errorName = i18n( "Cyclic Link Detected" );
820  description = i18n( "UNIX environments are commonly able to link a file or "
821  "folder to a separate name and/or location. TDE detected a link or "
822  "series of links that results in an infinite loop - i.e. the file was "
823  "(perhaps in a roundabout way) linked to itself." );
824  solutions << i18n( "Delete one part of the loop in order that it does not "
825  "cause an infinite loop, and try again." ) << sSysadmin;
826  break;
827 
828  case TDEIO::ERR_USER_CANCELED:
829  // Do nothing in this case. The user doesn't need to be told what he just did.
830  // rodda: However, if we have been called, an application is about to display
831  // this information anyway. If we don't return sensible information, the
832  // user sees a blank dialog (I have seen this myself)
833  errorName = i18n( "Request Aborted By User" );
834  description = i18n( "The request was not completed because it was "
835  "aborted." );
836  solutions << i18n( "Retry the request." );
837  break;
838 
839  case TDEIO::ERR_CYCLIC_COPY:
840  errorName = i18n( "Cyclic Link Detected During Copy" );
841  description = i18n( "UNIX environments are commonly able to link a file or "
842  "folder to a separate name and/or location. During the requested copy "
843  "operation, TDE detected a link or series of links that results in an "
844  "infinite loop - i.e. the file was (perhaps in a roundabout way) linked "
845  "to itself." );
846  solutions << i18n( "Delete one part of the loop in order that it does not "
847  "cause an infinite loop, and try again." ) << sSysadmin;
848  break;
849 
850  case TDEIO::ERR_COULD_NOT_CREATE_SOCKET:
851  errorName = i18n( "Could Not Create Network Connection" );
852  techName = i18n( "Could Not Create Socket" );
853  description = i18n( "This is a fairly technical error in which a required "
854  "device for network communications (a socket) could not be created." );
855  causes << i18n( "The network connection may be incorrectly configured, or "
856  "the network interface may not be enabled." );
857  solutions << sNetwork << sSysadmin;
858  break;
859 
860  case TDEIO::ERR_COULD_NOT_CONNECT:
861  errorName = i18n( "Connection to Server Refused" );
862  description = i18n( "The server <strong>%1</strong> refused to allow this "
863  "computer to make a connection." ).arg( host );
864  causes << i18n( "The server, while currently connected to the Internet, "
865  "may not be configured to allow requests." )
866  << i18n( "The server, while currently connected to the Internet, "
867  "may not be running the requested service (%1)." ).arg( protocol )
868  << i18n( "A network firewall (a device which restricts Internet "
869  "requests), either protecting your network or the network of the server, "
870  "may have intervened, preventing this request." );
871  solutions << sTryagain << sServeradmin << sSysadmin;
872  break;
873 
874  case TDEIO::ERR_CONNECTION_BROKEN:
875  errorName = i18n( "Connection to Server Closed Unexpectedly" );
876  description = i18n( "Although a connection was established to "
877  "<strong>%1</strong>, the connection was closed at an unexpected point "
878  "in the communication." ).arg( host );
879  causes << cNetwork << cNetpath << i18n( "A protocol error may have occurred, "
880  "causing the server to close the connection as a response to the error." );
881  solutions << sTryagain << sServeradmin << sSysadmin;
882  break;
883 
884  case TDEIO::ERR_NOT_FILTER_PROTOCOL:
885  errorName = i18n( "URL Resource Invalid" );
886  techName = i18n( "Protocol %1 is not a Filter Protocol" ).arg( protocol );
887  description = i18n( "The <strong>U</strong>niform <strong>R</strong>esource "
888  "<strong>L</strong>ocator (URL) that you entered did not refer to "
889  "a valid mechanism of accessing the specific resource, "
890  "<strong>%1%2</strong>." )
891  .arg( !host.isNull() ? host + '/' : TQString::null ).arg( dir );
892  causes << i18n( "TDE is able to communicate through a protocol within a "
893  "protocol. This request specified a protocol be used as such, however "
894  "this protocol is not capable of such an action. This is a rare event, "
895  "and is likely to indicate a programming error." );
896  solutions << sTypo << sSysadmin;
897  break;
898 
899  case TDEIO::ERR_COULD_NOT_MOUNT:
900  errorName = i18n( "Unable to Initialize Input/Output Device" );
901  techName = i18n( "Could Not Mount Device" );
902  description = i18n( "The requested device could not be initialized "
903  "(\"mounted\"). The reported error was: <strong>%1</strong>" )
904  .arg( errorText );
905  causes << i18n( "The device may not be ready, for example there may be "
906  "no media in a removable media device (i.e. no CD-ROM in a CD drive), "
907  "or in the case of a peripheral/portable device, the device may not "
908  "be correctly connected." )
909  << i18n( "You may not have permissions to initialize (\"mount\") the "
910  "device. On UNIX systems, often system administrator privileges are "
911  "required to initialize a device." )
912  << cHardware;
913  solutions << i18n( "Check that the device is ready; removable drives "
914  "must contain media, and portable devices must be connected and powered "
915  "on.; and try again." ) << sAccess << sSysadmin;
916  break;
917 
918  case TDEIO::ERR_COULD_NOT_UNMOUNT:
919  errorName = i18n( "Unable to Uninitialize Input/Output Device" );
920  techName = i18n( "Could Not Unmount Device" );
921  description = i18n( "The requested device could not be uninitialized "
922  "(\"unmounted\"). The reported error was: <strong>%1</strong>" )
923  .arg( errorText );
924  causes << i18n( "The device may be busy, that is, still in use by "
925  "another application or user. Even such things as having an open "
926  "browser window on a location on this device may cause the device to "
927  "remain in use." )
928  << i18n( "You may not have permissions to uninitialize (\"unmount\") "
929  "the device. On UNIX systems, system administrator privileges are "
930  "often required to uninitialize a device." )
931  << cHardware;
932  solutions << i18n( "Check that no applications are accessing the device, "
933  "and try again." ) << sAccess << sSysadmin;
934  break;
935 
936  case TDEIO::ERR_COULD_NOT_READ:
937  errorName = i18n( "Cannot Read From Resource" );
938  description = i18n( "This means that although the resource, "
939  "<strong>%1</strong>, was able to be opened, an error occurred while "
940  "reading the contents of the resource." ).arg( url );
941  causes << i18n( "You may not have permissions to read from the resource." );
942  if ( !isSlaveNetwork ) causes << cNetwork;
943  causes << cHardware;
944  solutions << sAccess;
945  if ( !isSlaveNetwork ) solutions << sNetwork;
946  solutions << sSysadmin;
947  break;
948 
949  case TDEIO::ERR_COULD_NOT_WRITE:
950  errorName = i18n( "Cannot Write to Resource" );
951  description = i18n( "This means that although the resource, <strong>%1</strong>"
952  ", was able to be opened, an error occurred while writing to the resource." )
953  .arg( url );
954  causes << i18n( "You may not have permissions to write to the resource." );
955  if ( !isSlaveNetwork ) causes << cNetwork;
956  causes << cHardware;
957  solutions << sAccess;
958  if ( !isSlaveNetwork ) solutions << sNetwork;
959  solutions << sSysadmin;
960  break;
961 
962  case TDEIO::ERR_COULD_NOT_BIND:
963  errorName = i18n( "Could Not Listen for Network Connections" );
964  techName = i18n( "Could Not Bind" );
965  description = i18n( "This is a fairly technical error in which a required "
966  "device for network communications (a socket) could not be established "
967  "to listen for incoming network connections." );
968  causes << i18n( "The network connection may be incorrectly configured, or "
969  "the network interface may not be enabled." );
970  solutions << sNetwork << sSysadmin;
971  break;
972 
973  case TDEIO::ERR_COULD_NOT_LISTEN:
974  errorName = i18n( "Could Not Listen for Network Connections" );
975  techName = i18n( "Could Not Listen" );
976  description = i18n( "This is a fairly technical error in which a required "
977  "device for network communications (a socket) could not be established "
978  "to listen for incoming network connections." );
979  causes << i18n( "The network connection may be incorrectly configured, or "
980  "the network interface may not be enabled." );
981  solutions << sNetwork << sSysadmin;
982  break;
983 
984  case TDEIO::ERR_COULD_NOT_ACCEPT:
985  errorName = i18n( "Could Not Accept Network Connection" );
986  description = i18n( "This is a fairly technical error in which an error "
987  "occurred while attempting to accept an incoming network connection." );
988  causes << i18n( "The network connection may be incorrectly configured, or "
989  "the network interface may not be enabled." )
990  << i18n( "You may not have permissions to accept the connection." );
991  solutions << sNetwork << sSysadmin;
992  break;
993 
994  case TDEIO::ERR_COULD_NOT_LOGIN:
995  errorName = i18n( "Could Not Login: %1" ).arg( errorText );
996  description = i18n( "An attempt to login to perform the requested "
997  "operation was unsuccessful." );
998  causes << i18n( "You may have supplied incorrect authentication details or "
999  "none at all." )
1000  << i18n( "Your account may not have permission to access the "
1001  "specified resource." ) << cProtocol;
1002  solutions << i18n( "Retry the request and ensure your authentication details "
1003  "are entered correctly." ) << sServeradmin << sSysadmin;
1004  break;
1005 
1006  case TDEIO::ERR_COULD_NOT_STAT:
1007  errorName = i18n( "Could Not Determine Resource Status" );
1008  techName = i18n( "Could Not Stat Resource" );
1009  description = i18n( "An attempt to determine information about the status "
1010  "of the resource <strong>%1</strong>, such as the resource name, type, "
1011  "size, etc., was unsuccessful." ).arg( url );
1012  causes << i18n( "The specified resource may not have existed or may "
1013  "not be accessible." ) << cProtocol << cHardware;
1014  solutions << i18n( "Retry the request and ensure your authentication details "
1015  "are entered correctly." ) << sSysadmin;
1016  break;
1017 
1018  case TDEIO::ERR_COULD_NOT_CLOSEDIR:
1019  //result = i18n( "Could not terminate listing %1" ).arg( errorText );
1020  errorName = i18n( "Could Not Cancel Listing" );
1021  techName = i18n( "FIXME: Document this" );
1022  break;
1023 
1024  case TDEIO::ERR_COULD_NOT_MKDIR:
1025  errorName = i18n( "Could Not Create Folder" );
1026  description = i18n( "An attempt to create the requested folder failed." );
1027  causes << cAccess << i18n( "The location where the folder was to be created "
1028  "may not exist." );
1029  if ( !isSlaveNetwork ) causes << cProtocol;
1030  solutions << i18n( "Retry the request." ) << sAccess;
1031  break;
1032 
1033  case TDEIO::ERR_COULD_NOT_RMDIR:
1034  errorName = i18n( "Could Not Remove Folder" );
1035  description = i18n( "An attempt to remove the specified folder, "
1036  "<strong>%1</strong>, failed." ).arg( dir );
1037  causes << i18n( "The specified folder may not exist." )
1038  << i18n( "The specified folder may not be empty." )
1039  << cAccess;
1040  if ( !isSlaveNetwork ) causes << cProtocol;
1041  solutions << i18n( "Ensure that the folder exists and is empty, and try "
1042  "again." ) << sAccess;
1043  break;
1044 
1045  case TDEIO::ERR_CANNOT_RESUME:
1046  errorName = i18n( "Could Not Resume File Transfer" );
1047  description = i18n( "The specified request asked that the transfer of "
1048  "file <strong>%1</strong> be resumed at a certain point of the "
1049  "transfer. This was not possible." ).arg( filename );
1050  causes << i18n( "The protocol, or the server, may not support file "
1051  "resuming." );
1052  solutions << i18n( "Retry the request without attempting to resume "
1053  "transfer." );
1054  break;
1055 
1056  case TDEIO::ERR_CANNOT_RENAME:
1057  errorName = i18n( "Could Not Rename Resource" );
1058  description = i18n( "An attempt to rename the specified resource "
1059  "<strong>%1</strong> failed." ).arg( url );
1060  causes << cAccess << cExists;
1061  if ( !isSlaveNetwork ) causes << cProtocol;
1062  solutions << sAccess << sExists;
1063  break;
1064 
1065  case TDEIO::ERR_CANNOT_CHMOD:
1066  errorName = i18n( "Could Not Alter Permissions of Resource" );
1067  description = i18n( "An attempt to alter the permissions on the specified "
1068  "resource <strong>%1</strong> failed." ).arg( url );
1069  causes << cAccess << cExists;
1070  solutions << sAccess << sExists;
1071  break;
1072 
1073  case TDEIO::ERR_CANNOT_DELETE:
1074  errorName = i18n( "Could Not Delete Resource" );
1075  description = i18n( "An attempt to delete the specified resource "
1076  "<strong>%1</strong> failed." ).arg( url );
1077  causes << cAccess << cExists;
1078  solutions << sAccess << sExists;
1079  break;
1080 
1081  case TDEIO::ERR_SLAVE_DIED:
1082  errorName = i18n( "Unexpected Program Termination" );
1083  description = i18n( "The program on your computer which provides access "
1084  "to the <strong>%1</strong> protocol has unexpectedly terminated." )
1085  .arg( url );
1086  causes << cBuglikely;
1087  solutions << sUpdate << sBugreport;
1088  break;
1089 
1090  case TDEIO::ERR_OUT_OF_MEMORY:
1091  errorName = i18n( "Out of Memory" );
1092  description = i18n( "The program on your computer which provides access "
1093  "to the <strong>%1</strong> protocol could not obtain the memory "
1094  "required to continue." ).arg( protocol );
1095  causes << cBuglikely;
1096  solutions << sUpdate << sBugreport;
1097  break;
1098 
1099  case TDEIO::ERR_UNKNOWN_PROXY_HOST:
1100  errorName = i18n( "Unknown Proxy Host" );
1101  description = i18n( "While retrieving information about the specified "
1102  "proxy host, <strong>%1</strong>, an Unknown Host error was encountered. "
1103  "An unknown host error indicates that the requested name could not be "
1104  "located on the Internet." ).arg( errorText );
1105  causes << i18n( "There may have been a problem with your network "
1106  "configuration, specifically your proxy's hostname. If you have been "
1107  "accessing the Internet with no problems recently, this is unlikely." )
1108  << cNetwork;
1109  solutions << i18n( "Double-check your proxy settings and try again." )
1110  << sSysadmin;
1111  break;
1112 
1113  case TDEIO::ERR_COULD_NOT_AUTHENTICATE:
1114  errorName = i18n( "Authentication Failed: Method %1 Not Supported" )
1115  .arg( errorText );
1116  description = i18n( "Although you may have supplied the correct "
1117  "authentication details, the authentication failed because the "
1118  "method that the server is using is not supported by the TDE "
1119  "program implementing the protocol %1." ).arg( protocol );
1120  solutions << i18n( "Please file a bug at <a href=\"http://bugs.trinitydesktop.org/\">"
1121  "http://bugs.trinitydesktop.org/</a> to inform the TDE team of the unsupported "
1122  "authentication method." ) << sSysadmin;
1123  break;
1124 
1125  case TDEIO::ERR_ABORTED:
1126  errorName = i18n( "Request Aborted" );
1127  description = i18n( "The request was not completed because it was "
1128  "aborted." );
1129  solutions << i18n( "Retry the request." );
1130  break;
1131 
1132  case TDEIO::ERR_INTERNAL_SERVER:
1133  errorName = i18n( "Internal Error in Server" );
1134  description = i18n( "The program on the server which provides access "
1135  "to the <strong>%1</strong> protocol has reported an internal error: "
1136  "%0." ).arg( protocol );
1137  causes << i18n( "This is most likely to be caused by a bug in the "
1138  "server program. Please consider submitting a full bug report as "
1139  "detailed below." );
1140  solutions << i18n( "Contact the administrator of the server "
1141  "to advise them of the problem." )
1142  << i18n( "If you know who the authors of the server software are, "
1143  "submit the bug report directly to them." );
1144  break;
1145 
1146  case TDEIO::ERR_SERVER_TIMEOUT:
1147  {
1148  int connTimeout = KProtocolManager::connectTimeout();
1149  int respTimeout = KProtocolManager::responseTimeout();
1150  int prConnTimeout = KProtocolManager::proxyConnectTimeout();
1151  errorName = i18n( "Timeout Error" );
1152  description = i18n("Although contact was made with the server, a "
1153  "response was not received within the amount of time allocated for "
1154  "the request as follows:")
1155  .append(TQString::fromLatin1("<ul><li>"))
1156  .append(i18n("Timeout for establishing a connection: %n second",
1157  "Timeout for establishing a connection: %n seconds",
1158  connTimeout))
1159  .append(TQString::fromLatin1("</li><li>"))
1160  .append(i18n("Timeout for receiving a response: %n second",
1161  "Timeout for receiving a response: %n seconds",
1162  respTimeout))
1163  .append(TQString::fromLatin1("</li><li>"))
1164  .append(i18n("Timeout for accessing proxy servers: %n second",
1165  "Timeout for accessing proxy servers: %n seconds",
1166  prConnTimeout))
1167  .append(TQString::fromLatin1("</li></ul>"))
1168  .append(i18n("Please note that you can alter these timeout settings in the TDE "
1169  "Control Center, by selecting Network -> Preferences." ));
1170  causes << cNetpath << i18n( "The server was too busy responding to other "
1171  "requests to respond." );
1172  solutions << sTryagain << sServeradmin;
1173  break;
1174  }
1175 
1176  case TDEIO::ERR_UNKNOWN:
1177  errorName = i18n( "Unknown Error" );
1178  description = i18n( "The program on your computer which provides access "
1179  "to the <strong>%1</strong> protocol has reported an unknown error: "
1180  "%2." ).arg( protocol ).arg( errorText );
1181  causes << cBug;
1182  solutions << sUpdate << sBugreport;
1183  break;
1184 
1185  case TDEIO::ERR_UNKNOWN_INTERRUPT:
1186  errorName = i18n( "Unknown Interruption" );
1187  description = i18n( "The program on your computer which provides access "
1188  "to the <strong>%1</strong> protocol has reported an interruption of "
1189  "an unknown type: %2." ).arg( protocol ).arg( errorText );
1190  causes << cBug;
1191  solutions << sUpdate << sBugreport;
1192  break;
1193 
1194  case TDEIO::ERR_CANNOT_DELETE_ORIGINAL:
1195  errorName = i18n( "Could Not Delete Original File" );
1196  description = i18n( "The requested operation required the deleting of "
1197  "the original file, most likely at the end of a file move operation. "
1198  "The original file <strong>%1</strong> could not be deleted." )
1199  .arg( errorText );
1200  causes << cAccess;
1201  solutions << sAccess;
1202  break;
1203 
1204  case TDEIO::ERR_CANNOT_DELETE_PARTIAL:
1205  errorName = i18n( "Could Not Delete Temporary File" );
1206  description = i18n( "The requested operation required the creation of "
1207  "a temporary file in which to save the new file while being "
1208  "downloaded. This temporary file <strong>%1</strong> could not be "
1209  "deleted." ).arg( errorText );
1210  causes << cAccess;
1211  solutions << sAccess;
1212  break;
1213 
1214  case TDEIO::ERR_CANNOT_RENAME_ORIGINAL:
1215  errorName = i18n( "Could Not Rename Original File" );
1216  description = i18n( "The requested operation required the renaming of "
1217  "the original file <strong>%1</strong>, however it could not be "
1218  "renamed." ).arg( errorText );
1219  causes << cAccess;
1220  solutions << sAccess;
1221  break;
1222 
1223  case TDEIO::ERR_CANNOT_RENAME_PARTIAL:
1224  errorName = i18n( "Could Not Rename Temporary File" );
1225  description = i18n( "The requested operation required the creation of "
1226  "a temporary file <strong>%1</strong>, however it could not be "
1227  "created." ).arg( errorText );
1228  causes << cAccess;
1229  solutions << sAccess;
1230  break;
1231 
1232  case TDEIO::ERR_CANNOT_SYMLINK:
1233  errorName = i18n( "Could Not Create Link" );
1234  techName = i18n( "Could Not Create Symbolic Link" );
1235  description = i18n( "The requested symbolic link %1 could not be created." )
1236  .arg( errorText );
1237  causes << cAccess;
1238  solutions << sAccess;
1239  break;
1240 
1241  case TDEIO::ERR_NO_CONTENT:
1242  errorName = i18n( "No Content" );
1243  description = errorText;
1244  break;
1245 
1246  case TDEIO::ERR_DISK_FULL:
1247  errorName = i18n( "Disk Full" );
1248  description = i18n( "The requested file <strong>%1</strong> could not be "
1249  "written to as there is inadequate disk space." ).arg( errorText );
1250  solutions << i18n( "Free up enough disk space by 1) deleting unwanted and "
1251  "temporary files; 2) archiving files to removable media storage such as "
1252  "CD-Recordable discs; or 3) obtain more storage capacity." )
1253  << sSysadmin;
1254  break;
1255 
1256  case TDEIO::ERR_IDENTICAL_FILES:
1257  errorName = i18n( "Source and Destination Files Identical" );
1258  description = i18n( "The operation could not be completed because the "
1259  "source and destination files are the same file." );
1260  solutions << i18n( "Choose a different filename for the destination file." );
1261  break;
1262 
1263  // We assume that the slave has all the details
1264  case TDEIO::ERR_SLAVE_DEFINED:
1265  errorName = TQString::null;
1266  description = errorText;
1267  break;
1268 
1269  default:
1270  // fall back to the plain error...
1271  errorName = i18n( "Undocumented Error" );
1272  description = buildErrorString( errorCode, errorText );
1273  }
1274 
1275  TQByteArray ret;
1276  TQDataStream stream(ret, IO_WriteOnly);
1277  stream << errorName << techName << description << causes << solutions;
1278  return ret;
1279 }
1280 
1281 #ifdef Q_OS_UNIX
1282 
1283 #include <limits.h>
1284 #include <stdlib.h>
1285 #include <stdio.h>
1286 #include <tqfile.h>
1287 
1288 #include <config.h>
1289 
1290 #ifdef HAVE_PATHS_H
1291 #include <paths.h>
1292 #endif
1293 #ifdef HAVE_SYS_STAT_H
1294 #include <sys/stat.h>
1295 #endif
1296 #include <sys/param.h>
1297 #ifdef HAVE_LIMITS_H
1298 #include <limits.h>
1299 #endif
1300 #ifdef HAVE_SYS_MNTTAB_H
1301 #include <sys/mnttab.h>
1302 #endif
1303 #ifdef HAVE_MNTENT_H
1304 #include <mntent.h>
1305 #elif defined(HAVE_SYS_MNTENT_H)
1306 #include <sys/mntent.h>
1307 #endif
1308 #ifdef HAVE_SYS_UCRED_H
1309 #include <sys/ucred.h>
1310 #elif defined(HAVE_UCRED_H)
1311 #include <ucred.h>
1312 #endif
1313 #ifdef HAVE_SYS_MOUNT_H
1314 #include <sys/mount.h>
1315 #endif
1316 #ifdef HAVE_FSTAB_H
1317 #include <fstab.h>
1318 #endif
1319 #if defined(_AIX)
1320 #include <sys/mntctl.h>
1321 #include <sys/vmount.h>
1322 #include <sys/vfs.h>
1323 
1324 /* AIX does not prototype mntctl anywhere that I can find */
1325 #ifndef mntctl
1326 extern "C" {
1327 int mntctl(int command, int size, void* buffer);
1328 }
1329 #endif
1330 extern "C" struct vfs_ent *getvfsbytype(int vfsType);
1331 extern "C" void endvfsent( );
1332 #endif
1333 
1334 /***************************************************************
1335  *
1336  * Utility functions
1337  *
1338  ***************************************************************/
1339 
1340 #ifndef HAVE_GETMNTINFO
1341 
1342 #ifdef _PATH_MOUNTED
1343 // On some Linux, MNTTAB points to /etc/fstab !
1344 # undef MNTTAB
1345 # define MNTTAB _PATH_MOUNTED
1346 #else
1347 # ifndef MNTTAB
1348 # ifdef MTAB_FILE
1349 # define MNTTAB MTAB_FILE
1350 # else
1351 # define MNTTAB "/etc/mnttab"
1352 # endif
1353 # endif
1354 #endif
1355 
1356 #ifndef FSTAB
1357 # ifdef _PATH_FSTAB
1358 # define FSTAB _PATH_FSTAB
1359 # else
1360 # define FSTAB "/etc/fstab"
1361 # endif
1362 #endif
1363 
1364 #ifdef __CYGWIN__
1365 #define hasmntopt(var,opt) (0)
1366 #endif
1367 
1368 // There are (at least) four kind of APIs:
1369 // setmntent + getmntent + struct mntent (linux...)
1370 // getmntent + struct mnttab
1371 // mntctl + struct vmount (AIX)
1372 // getmntinfo + struct statfs&flags (BSD 4.4 and friends)
1373 // getfsent + char* (BSD 4.3 and friends)
1374 
1375 #ifdef HAVE_SETMNTENT
1376 #define SETMNTENT setmntent
1377 #define ENDMNTENT endmntent
1378 #define STRUCT_MNTENT struct mntent *
1379 #define STRUCT_SETMNTENT FILE *
1380 #define GETMNTENT(file, var) ((var = getmntent(file)) != 0)
1381 #define MOUNTPOINT(var) var->mnt_dir
1382 #define MOUNTTYPE(var) var->mnt_type
1383 #define HASMNTOPT(var, opt) hasmntopt(var, opt)
1384 #define FSNAME(var) var->mnt_fsname
1385 #elif defined(_AIX)
1386 /* we don't need this stuff */
1387 #else
1388 #define SETMNTENT fopen
1389 #define ENDMNTENT fclose
1390 #define STRUCT_MNTENT struct mnttab
1391 #define STRUCT_SETMNTENT FILE *
1392 #define GETMNTENT(file, var) (getmntent(file, &var) == 0)
1393 #define MOUNTPOINT(var) var.mnt_mountp
1394 #define MOUNTTYPE(var) var.mnt_fstype
1395 #define HASMNTOPT(var, opt) hasmntopt(&var, opt)
1396 #define FSNAME(var) var.mnt_special
1397 #endif
1398 
1399 #endif /* HAVE_GETMNTINFO */
1400 
1401 TQString TDEIO::findDeviceMountPoint( const TQString& filename )
1402 {
1403  TQString result;
1404 
1405 #ifdef HAVE_VOLMGT
1406  /*
1407  * support for Solaris volume management
1408  */
1409  const char *volpath;
1410  FILE *mnttab;
1411  struct mnttab mnt;
1412  int len;
1413  TQCString devname;
1414 
1415  if( (volpath = volmgt_root()) == NULL ) {
1416  kdDebug( 7007 ) << "findDeviceMountPoint: "
1417  << "VOLMGT: can't find volmgt root dir" << endl;
1418  return TQString::null;
1419  }
1420 
1421  if( (mnttab = fopen( MNTTAB, "r" )) == NULL ) {
1422  kdDebug( 7007 ) << "findDeviceMountPoint: "
1423  << "VOLMGT: can't open mnttab" << endl;
1424  return TQString::null;
1425  }
1426 
1427  devname = volpath;
1428  devname += TQFile::encodeName( filename );
1429  devname += '/';
1430  len = devname.length();
1431 // kdDebug( 7007 ) << "findDeviceMountPoint: "
1432 // << "VOLMGT: searching mountpoint for \"" << devname << "\""
1433 // << endl;
1434 
1435  /*
1436  * find the mountpoint
1437  * floppies:
1438  * /dev/disketteN => <volpath>/dev/disketteN
1439  * CDROM, ZIP, and other media:
1440  * /dev/dsk/cXtYdZs2 => <volpath>/dev/dsk/cXtYdZ (without slice#)
1441  */
1442  rewind( mnttab );
1443  result = TQString::null;
1444  while( getmntent( mnttab, &mnt ) == 0 ) {
1445  /*
1446  * either match the exact device name (floppies),
1447  * or the device name without the slice#
1448  */
1449  if( strncmp( devname.data(), mnt.mnt_special, len ) == 0
1450  || (strncmp( devname.data(), mnt.mnt_special, len - 3 ) == 0
1451  && mnt.mnt_special[len - 3] == '/' )
1452  || (strcmp(TQFile::encodeName(filename).data()
1453  , mnt.mnt_special)==0)) {
1454  result = mnt.mnt_mountp;
1455  break;
1456  }
1457  }
1458  fclose( mnttab );
1459 #else
1460 
1461  char realpath_buffer[MAXPATHLEN];
1462  TQCString realname;
1463 
1464  realname = TQFile::encodeName(filename);
1465  /* If the path contains symlinks, get the real name */
1466  if (realpath(realname, realpath_buffer) != 0)
1467  // succes, use result from realpath
1468  realname = realpath_buffer;
1469 
1470  //kdDebug(7007) << "findDeviceMountPoint realname=" << realname << endl;
1471 
1472 #ifdef HAVE_GETMNTINFO
1473 
1474 #ifdef GETMNTINFO_USES_STATVFS
1475  struct statvfs *mounted;
1476 #else
1477  struct statfs *mounted;
1478 #endif
1479 
1480  int num_fs = getmntinfo(&mounted, MNT_NOWAIT);
1481 
1482  for (int i=0;i<num_fs;i++) {
1483 
1484  TQCString device_name = mounted[i].f_mntfromname;
1485 
1486  // If the path contains symlinks, get
1487  // the real name
1488  if (realpath(device_name, realpath_buffer) != 0)
1489  // succes, use result from realpath
1490  device_name = realpath_buffer;
1491 
1492  if (realname == device_name) {
1493  result = mounted[i].f_mntonname;
1494  break;
1495  }
1496  }
1497 
1498 #elif defined(_AIX)
1499 
1500  struct vmount *mntctl_buffer;
1501  struct vmount *vm;
1502  char *mountedfrom;
1503  char *mountedto;
1504  int fsname_len, num;
1505  int buf_sz = 4096;
1506 
1507  /* mntctl can be used to query mounted file systems.
1508  * mntctl takes only the command MCTL_QUERY so far.
1509  * The buffer is filled with an array of vmount structures, but these
1510  * vmount structures have variable size.
1511  * mntctl return values:
1512  * -1 error
1513  * 0 look in first word of buffer for required bytes, 4096 may be
1514  * a good starting size, but if tables grow too large, look here.
1515  * >0 number of vmount structures
1516  */
1517  mntctl_buffer = (struct vmount*)malloc(buf_sz);
1518  num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
1519  if (num == 0)
1520  {
1521  buf_sz = *(int*)mntctl_buffer;
1522  free(mntctl_buffer);
1523  mntctl_buffer = (struct vmount*)malloc(buf_sz);
1524  num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
1525  }
1526 
1527  if (num > 0)
1528  {
1529  /* iterate through items in the vmount structure: */
1530  vm = mntctl_buffer;
1531  for ( ; num > 0; num-- )
1532  {
1533  /* get the name of the mounted file systems: */
1534  fsname_len = vmt2datasize(vm, VMT_STUB);
1535  mountedto = (char*)malloc(fsname_len + 1);
1536  mountedto[fsname_len] = '\0';
1537  strncpy(mountedto, (char *)vmt2dataptr(vm, VMT_STUB), fsname_len);
1538 
1539  /* get the mount-from information: */
1540  fsname_len = vmt2datasize(vm, VMT_OBJECT);
1541  mountedfrom = (char*)malloc(fsname_len + 1);
1542  mountedfrom[fsname_len] = '\0';
1543  strncpy(mountedfrom, (char *)vmt2dataptr(vm, VMT_OBJECT), fsname_len);
1544 
1545  TQCString device_name = mountedfrom;
1546 
1547  if (realpath(device_name, realpath_buffer) != 0)
1548  // success, use result from realpath
1549  device_name = realpath_buffer;
1550 
1551  free(mountedfrom);
1552 
1553  if (realname == device_name) {
1554  result = mountedto;
1555  free(mountedto);
1556  break;
1557  }
1558 
1559  free(mountedto);
1560 
1561  /* goto the next vmount structure: */
1562  vm = (struct vmount *)((char *)vm + vm->vmt_length);
1563  }
1564  }
1565 
1566  free( mntctl_buffer );
1567 
1568 #else
1569 
1570  STRUCT_SETMNTENT mtab;
1571 
1572  /* Get the list of mounted file systems */
1573 
1574  if ((mtab = SETMNTENT(MNTTAB, "r")) == 0) {
1575  perror("setmntent");
1576  return TQString::null;
1577  }
1578 
1579  /* Loop over all file systems and see if we can find our
1580  * mount point.
1581  * Note that this is the mount point with the longest match.
1582  * XXX: Fails if me->mnt_dir is not a realpath but goes
1583  * through a symlink, e.g. /foo/bar where /foo is a symlink
1584  * pointing to /local/foo.
1585  *
1586  * How kinky can you get with a filesystem?
1587  */
1588 
1589  STRUCT_MNTENT me;
1590 
1591  while (GETMNTENT(mtab, me))
1592  {
1593  // There may be symbolic links into the /etc/mnttab
1594  // So we have to find the real device name here as well!
1595  TQCString device_name = FSNAME(me);
1596  if (device_name.isEmpty() || (device_name == "none"))
1597  continue;
1598 
1599  //kdDebug( 7007 ) << "device_name=" << device_name << endl;
1600 
1601  // If the path contains symlinks, get
1602  // the real name
1603  if (realpath(device_name, realpath_buffer) != 0)
1604  // succes, use result from realpath
1605  device_name = realpath_buffer;
1606 
1607  //kdDebug( 7007 ) << "device_name after realpath =" << device_name << endl;
1608 
1609  if (realname == device_name)
1610  {
1611  result = MOUNTPOINT(me);
1612  break;
1613  }
1614  }
1615 
1616  ENDMNTENT(mtab);
1617 
1618 #endif /* GET_MNTINFO */
1619 #endif /* HAVE_VOLMGT */
1620 
1621  //kdDebug( 7007 ) << "Returning result " << result << endl;
1622  return result;
1623 }
1624 
1625 // Don't just trust the return value, keep iterating to check for a better match (bigger max)
1626 static bool is_my_mountpoint( const char *mountpoint, const char *realname, int &max )
1627 {
1628  int length = strlen(mountpoint);
1629 
1630  if (!strncmp(mountpoint, realname, length)
1631  && length > max) {
1632  max = length;
1633  if (length == 1 || realname[length] == '/' || realname[length] == '\0')
1634  return true;
1635  }
1636  return false;
1637 }
1638 
1639 typedef enum { Unseen, Right, Wrong } MountState;
1640 
1644 static void check_mount_point(const char *mounttype,
1645  const char *fsname,
1646  MountState &isslow, MountState &isautofs)
1647 {
1648  bool nfs = !strcmp(mounttype, "nfs");
1649  bool autofs = !strcmp(mounttype, "autofs") || !strcmp(mounttype,"subfs");
1650  bool pid = (strstr(fsname, ":(pid") != 0);
1651 
1652  if (nfs && !pid)
1653  isslow = Right;
1654  else if (isslow == Right)
1655  isslow = Wrong;
1656 
1657  /* Does this look like automounted? */
1658  if (autofs || (nfs && pid)) {
1659  isautofs = Right;
1660  isslow = Right;
1661  }
1662 }
1663 
1664 // returns the mount point, checks the mount state.
1665 // if ismanual == Wrong this function does not check the manual mount state
1666 static TQString get_mount_info(const TQString& filename,
1667  MountState& isautofs, MountState& isslow, MountState& ismanual,
1668  TQString& fstype)
1669 {
1670  static bool gotRoot = false;
1671  static dev_t rootDevice;
1672 
1673  struct cachedDevice_t
1674  {
1675  dev_t device;
1676  TQString mountPoint;
1677  MountState isautofs;
1678  MountState isslow;
1679  MountState ismanual;
1680  TQString fstype;
1681  };
1682  static struct cachedDevice_t *cachedDevice = 0;
1683 
1684  if (!gotRoot)
1685  {
1686  KDE_struct_stat stat_buf;
1687  KDE_stat("/", &stat_buf);
1688  gotRoot = true;
1689  rootDevice = stat_buf.st_dev;
1690  }
1691 
1692  bool gotDevice = false;
1693  KDE_struct_stat stat_buf;
1694  if (KDE_stat(TQFile::encodeName(filename), &stat_buf) == 0)
1695  {
1696  gotDevice = true;
1697  if (stat_buf.st_dev == rootDevice)
1698  {
1699  static const TQString &root = TDEGlobal::staticQString("/");
1700  isautofs = Wrong;
1701  isslow = Wrong;
1702  ismanual = Wrong;
1703  fstype = TQString::null; // ### do we need it?
1704  return root;
1705  }
1706  if (cachedDevice && (stat_buf.st_dev == cachedDevice->device))
1707  {
1708  bool interestedInIsManual = ismanual != Wrong;
1709  isautofs = cachedDevice->isautofs;
1710  isslow = cachedDevice->isslow;
1711  ismanual = cachedDevice->ismanual;
1712  fstype = cachedDevice->fstype;
1713  // Don't use the cache if it doesn't have the information we're looking for
1714  if ( !interestedInIsManual || ismanual != Unseen )
1715  return cachedDevice->mountPoint;
1716  }
1717  }
1718 
1719  char realname[MAXPATHLEN];
1720 
1721  memset(realname, 0, MAXPATHLEN);
1722 
1723  /* If the path contains symlinks, get the real name */
1724  if (realpath(TQFile::encodeName(filename), realname) == 0) {
1725  if( strlcpy(realname, TQFile::encodeName(filename), MAXPATHLEN)>=MAXPATHLEN)
1726  return TQString::null;
1727  }
1728 
1729  int max = 0;
1730  TQString mountPoint;
1731 
1732  /* Loop over all file systems and see if we can find our
1733  * mount point.
1734  * Note that this is the mount point with the longest match.
1735  * XXX: Fails if me->mnt_dir is not a realpath but goes
1736  * through a symlink, e.g. /foo/bar where /foo is a symlink
1737  * pointing to /local/foo.
1738  *
1739  * How kinky can you get with a filesystem?
1740  */
1741 
1742 #ifdef HAVE_GETMNTINFO
1743 
1744 #ifdef GETMNTINFO_USES_STATVFS
1745  struct statvfs *mounted;
1746 #else
1747  struct statfs *mounted;
1748 #endif
1749 
1750  char realpath_buffer[MAXPATHLEN];
1751 
1752  int num_fs = getmntinfo(&mounted, MNT_NOWAIT);
1753 
1754  for (int i=0;i<num_fs;i++) {
1755 
1756  TQCString device_name = mounted[i].f_mntfromname;
1757 
1758  // If the path contains symlinks, get
1759  // the real name
1760  if (realpath(device_name, realpath_buffer) != 0)
1761  // succes, use result from realpath
1762  device_name = realpath_buffer;
1763  char * mounttype = mounted[i].f_fstypename;
1764  if ( is_my_mountpoint( mounted[i].f_mntonname, realname, max ) )
1765  {
1766  mountPoint = TQFile::decodeName(mounted[i].f_mntonname);
1767  fstype = TQString::fromLatin1(mounttype);
1768  check_mount_point( mounttype, mounted[i].f_mntfromname,
1769  isautofs, isslow );
1770  // keep going, looking for a potentially better one
1771 
1772  if (ismanual == Unseen)
1773  {
1774  struct fstab *ft = getfsfile(mounted[i].f_mntonname);
1775  if (!ft || strstr(ft->fs_mntops, "noauto"))
1776  ismanual = Right;
1777  }
1778  }
1779  }
1780 
1781 #elif defined(_AIX)
1782 
1783  struct vmount *mntctl_buffer;
1784  struct vmount *vm;
1785  char *mountedfrom;
1786  char *mountedto;
1787  int fsname_len, num;
1788  char realpath_buffer[MAXPATHLEN];
1789  int buf_sz = 4096;
1790 
1791  mntctl_buffer = (struct vmount*)malloc(buf_sz);
1792  num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
1793  if (num == 0)
1794  {
1795  buf_sz = *(int*)mntctl_buffer;
1796  free(mntctl_buffer);
1797  mntctl_buffer = (struct vmount*)malloc(buf_sz);
1798  num = mntctl(MCTL_QUERY, buf_sz, mntctl_buffer);
1799  }
1800 
1801  if (num > 0)
1802  {
1803  /* iterate through items in the vmount structure: */
1804  vm = (struct vmount *)mntctl_buffer;
1805  for ( ; num > 0; num-- )
1806  {
1807  /* get the name of the mounted file systems: */
1808  fsname_len = vmt2datasize(vm, VMT_STUB);
1809  mountedto = (char*)malloc(fsname_len + 1);
1810  mountedto[fsname_len] = '\0';
1811  strncpy(mountedto, (char *)vmt2dataptr(vm, VMT_STUB), fsname_len);
1812 
1813  fsname_len = vmt2datasize(vm, VMT_OBJECT);
1814  mountedfrom = (char*)malloc(fsname_len + 1);
1815  mountedfrom[fsname_len] = '\0';
1816  strncpy(mountedfrom, (char *)vmt2dataptr(vm, VMT_OBJECT), fsname_len);
1817 
1818  /* get the mount-from information: */
1819  TQCString device_name = mountedfrom;
1820 
1821  if (realpath(device_name, realpath_buffer) != 0)
1822  // success, use result from realpath
1823  device_name = realpath_buffer;
1824 
1825  /* Look up the string for the file system type,
1826  * as listed in /etc/vfs.
1827  * ex.: nfs,jfs,afs,cdrfs,sfs,cachefs,nfs3,autofs
1828  */
1829  struct vfs_ent* ent = getvfsbytype(vm->vmt_gfstype);
1830 
1831  if ( is_my_mountpoint( mountedto, realname, max ) )
1832  {
1833  mountPoint = TQFile::decodeName(mountedto);
1834  fstype = TQString::fromLatin1(ent->vfsent_name);
1835  check_mount_point(ent->vfsent_name, device_name, isautofs, isslow);
1836 
1837  if (ismanual == Unseen)
1838  {
1839  // TODO: add check for ismanual, I couldn't find any way
1840  // how to get the mount attribute from /etc/filesystems
1841  ismanual == Wrong;
1842  }
1843  }
1844 
1845  free(mountedfrom);
1846  free(mountedto);
1847 
1848  /* goto the next vmount structure: */
1849  vm = (struct vmount *)((char *)vm + vm->vmt_length);
1850  }
1851 
1852  endvfsent( );
1853  }
1854 
1855  free( mntctl_buffer );
1856 
1857 #else
1858 
1859  STRUCT_SETMNTENT mtab;
1860  /* Get the list of mounted file systems */
1861 
1862  if ((mtab = SETMNTENT(MNTTAB, "r")) == 0) {
1863  perror("setmntent");
1864  return TQString::null;
1865  }
1866 
1867  STRUCT_MNTENT me;
1868 
1869  while (true) {
1870  if (!GETMNTENT(mtab, me))
1871  break;
1872 
1873  if ( is_my_mountpoint( MOUNTPOINT(me), realname, max ) )
1874  {
1875  mountPoint = TQFile::decodeName( MOUNTPOINT(me) );
1876  fstype = MOUNTTYPE(me);
1877  check_mount_point(MOUNTTYPE(me), FSNAME(me), isautofs, isslow);
1878  // we don't check if ismanual is Right, if /a/b is manually
1879  // mounted /a/b/c can't be automounted. At least IMO.
1880  if (ismanual == Unseen)
1881  {
1882  // The next GETMNTENT call may destroy 'me'
1883  // Copy out the info that we need
1884  TQCString fsname_me = FSNAME(me);
1885  TQCString mounttype_me = MOUNTTYPE(me);
1886 
1887  STRUCT_SETMNTENT fstab;
1888  if ((fstab = SETMNTENT(FSTAB, "r")) == 0) {
1889  continue;
1890  }
1891 
1892  bool found = false;
1893  STRUCT_MNTENT fe;
1894  while (GETMNTENT(fstab, fe))
1895  {
1896  if (fsname_me == FSNAME(fe))
1897  {
1898  found = true;
1899  if (HASMNTOPT(fe, "noauto") ||
1900  !strcmp(MOUNTTYPE(fe), "supermount"))
1901  ismanual = Right;
1902  break;
1903  }
1904  }
1905  if (!found || (mounttype_me == "supermount"))
1906  ismanual = Right;
1907 
1908  ENDMNTENT(fstab);
1909  }
1910  }
1911  }
1912 
1913  ENDMNTENT(mtab);
1914 
1915 #endif
1916 
1917  if (isautofs == Right && isslow == Unseen)
1918  isslow = Right;
1919 
1920  if (gotDevice)
1921  {
1922  if (!cachedDevice)
1923  cachedDevice = new cachedDevice_t;
1924 
1925  cachedDevice->device = stat_buf.st_dev;
1926  cachedDevice->mountPoint = mountPoint;
1927  cachedDevice->isautofs = isautofs;
1928  cachedDevice->isslow = isslow;
1929  cachedDevice->ismanual = ismanual;
1930  cachedDevice->fstype = fstype;
1931  }
1932 
1933  return mountPoint;
1934 }
1935 
1936 #else
1937 //dummy
1938 TQString TDEIO::findDeviceMountPoint( const TQString& filename )
1939 {
1940  return TQString::null;
1941 }
1942 #endif
1943 
1944 TQString TDEIO::findPathMountPoint(const TQString& filename)
1945 {
1946 #ifdef Q_OS_UNIX
1947  MountState isautofs = Unseen, isslow = Unseen, ismanual = Wrong;
1948  TQString fstype;
1949  return get_mount_info(filename, isautofs, isslow, ismanual, fstype);
1950 #else
1951  return TQString::null;
1952 #endif
1953 }
1954 
1955 bool TDEIO::manually_mounted(const TQString& filename)
1956 {
1957 #ifdef Q_OS_UNIX
1958  MountState isautofs = Unseen, isslow = Unseen, ismanual = Unseen;
1959  TQString fstype;
1960  TQString mountPoint = get_mount_info(filename, isautofs, isslow, ismanual, fstype);
1961  return !mountPoint.isNull() && (ismanual == Right);
1962 #else
1963  return false;
1964 #endif
1965 }
1966 
1967 bool TDEIO::probably_slow_mounted(const TQString& filename)
1968 {
1969 #ifdef Q_OS_UNIX
1970  MountState isautofs = Unseen, isslow = Unseen, ismanual = Wrong;
1971  TQString fstype;
1972  TQString mountPoint = get_mount_info(filename, isautofs, isslow, ismanual, fstype);
1973  return !mountPoint.isNull() && (isslow == Right);
1974 #else
1975  return false;
1976 #endif
1977 }
1978 
1979 bool TDEIO::testFileSystemFlag(const TQString& filename, FileSystemFlag flag)
1980 {
1981 #ifdef Q_OS_UNIX
1982  MountState isautofs = Unseen, isslow = Unseen, ismanual = Wrong;
1983  TQString fstype;
1984  TQString mountPoint = get_mount_info(filename, isautofs, isslow, ismanual, fstype);
1985  kdDebug() << "testFileSystemFlag: fstype=" << fstype << endl;
1986  if (mountPoint.isNull())
1987  return false;
1988  bool isMsDos = ( fstype == "msdos" || fstype == "fat" || fstype == "vfat" );
1989  switch (flag) {
1990  case SupportsChmod:
1991  case SupportsChown:
1992  case SupportsUTime:
1993  case SupportsSymlinks:
1994  return !isMsDos; // it's amazing the number of things FAT doesn't support :)
1995  case CaseInsensitive:
1996  return isMsDos;
1997  }
1998 #endif
1999  return false;
2000 }
2001 
2002 TDEIO::CacheControl TDEIO::parseCacheControl(const TQString &cacheControl)
2003 {
2004  TQString tmp = cacheControl.lower();
2005 
2006  if (tmp == "cacheonly")
2007  return TDEIO::CC_CacheOnly;
2008  if (tmp == "cache")
2009  return TDEIO::CC_Cache;
2010  if (tmp == "verify")
2011  return TDEIO::CC_Verify;
2012  if (tmp == "refresh")
2013  return TDEIO::CC_Refresh;
2014  if (tmp == "reload")
2015  return TDEIO::CC_Reload;
2016 
2017  kdDebug() << "unrecognized Cache control option:"<<cacheControl<<endl;
2018  return TDEIO::CC_Verify;
2019 }
2020 
2021 TQString TDEIO::getCacheControlString(TDEIO::CacheControl cacheControl)
2022 {
2023  if (cacheControl == TDEIO::CC_CacheOnly)
2024  return "CacheOnly";
2025  if (cacheControl == TDEIO::CC_Cache)
2026  return "Cache";
2027  if (cacheControl == TDEIO::CC_Verify)
2028  return "Verify";
2029  if (cacheControl == TDEIO::CC_Refresh)
2030  return "Refresh";
2031  if (cacheControl == TDEIO::CC_Reload)
2032  return "Reload";
2033  kdDebug() << "unrecognized Cache control enum value:"<<cacheControl<<endl;
2034  return TQString::null;
2035 }
KProtocolManager::proxyConnectTimeout
static int proxyConnectTimeout()
Returns the preferred timeout value for proxy connections in seconds.
Definition: tdeprotocolmanager.cpp:128
KProtocolManager::connectTimeout
static int connectTimeout()
Returns the preferred timeout value for remote connections in seconds.
Definition: tdeprotocolmanager.cpp:120
KProtocolManager::responseTimeout
static int responseTimeout()
Returns the preferred response timeout value for remote connecting in seconds.
Definition: tdeprotocolmanager.cpp:136
TDEIO::Job::detailedErrorStrings
TQStringList detailedErrorStrings(const KURL *reqUrl=0L, int method=-1) const
Converts an error code and a non-i18n error message into i18n strings suitable for presentation in a ...
Definition: global.cpp:478
TDEIO::Job::errorString
TQString errorString() const
Definition: global.cpp:225
TDEIO::convertSizeWithBytes
TDEIO_EXPORT TQString convertSizeWithBytes(TDEIO::filesize_t size)
Converts size from bytes to a string representation with includes the size in bytes.
Definition: global.cpp:45
TDEIO::convertSizeFromKB
TDEIO_EXPORT TQString convertSizeFromKB(TDEIO::filesize_t kbSize)
Converts size from kilo-bytes to the string representation.
Definition: global.cpp:91
TDEIO::calculateRemainingSeconds
TDEIO_EXPORT unsigned int calculateRemainingSeconds(TDEIO::filesize_t totalSize, TDEIO::filesize_t processedSize, TDEIO::filesize_t speed)
Calculates remaining time in seconds from total size, processed size and speed.
Definition: global.cpp:103
TDEIO::number
TDEIO_EXPORT TQString number(TDEIO::filesize_t size)
Converts a size to a string representation Not unlike TQString::number(...)
Definition: global.cpp:96
TDEIO::convertSeconds
TDEIO_EXPORT TQString convertSeconds(unsigned int seconds)
Convert seconds to a string representing number of days, hours, minutes and seconds.
Definition: global.cpp:112
TDEIO::probably_slow_mounted
TDEIO_EXPORT bool probably_slow_mounted(const TQString &filename)
Checks if the path belongs to a filesystem that is probably slow.
Definition: global.cpp:1967
TDEIO::rawErrorDetail
TDEIO_EXPORT TQByteArray rawErrorDetail(int errorCode, const TQString &errorText, const KURL *reqUrl=0L, int method=-1)
Returns translated error details for errorCode using the additional error information provided by err...
Definition: global.cpp:528
TDEIO::parseCacheControl
TDEIO_EXPORT TDEIO::CacheControl parseCacheControl(const TQString &cacheControl)
Parses the string representation of the cache control option.
Definition: global.cpp:2002
TDEIO::buildErrorString
TDEIO_EXPORT TQString buildErrorString(int errorCode, const TQString &errorText)
Returns a translated error message for errorCode using the additional error information provided by e...
Definition: global.cpp:230
TDEIO::convertSize
TDEIO_EXPORT TQString convertSize(TDEIO::filesize_t size)
Converts size from bytes to the string representation.
Definition: global.cpp:53
TDEIO::calculateRemaining
TDEIO_EXPORT TQTime calculateRemaining(TDEIO::filesize_t totalSize, TDEIO::filesize_t processedSize, TDEIO::filesize_t speed) TDE_DEPRECATED
Calculates remaining time from total size, processed size and speed.
Definition: global.cpp:127
TDEIO::getCacheControlString
TDEIO_EXPORT TQString getCacheControlString(TDEIO::CacheControl cacheControl)
Returns a string representation of the given cache control method.
Definition: global.cpp:2021
TDEIO::testFileSystemFlag
TDEIO_EXPORT bool testFileSystemFlag(const TQString &filename, FileSystemFlag flag)
Checks the capabilities of the filesystem to which a given file belongs.
Definition: global.cpp:1979
TDEIO::manually_mounted
TDEIO_EXPORT bool manually_mounted(const TQString &filename)
Checks if the path belongs to a filesystem that is manually mounted.
Definition: global.cpp:1955
TDEIO::encodeFileName
TDEIO_EXPORT TQString encodeFileName(const TQString &str)
Encodes (from the text displayed to the real filename) This translates % into %% and / into ∕ (U+2215...
Definition: global.cpp:165
TDEIO::CacheControl
CacheControl
Specifies how to use the cache.
Definition: global.h:388
TDEIO::CC_Cache
@ CC_Cache
Use cached entry if available.
Definition: global.h:390
TDEIO::CC_CacheOnly
@ CC_CacheOnly
Fail request if not in cache.
Definition: global.h:389
TDEIO::CC_Refresh
@ CC_Refresh
Always validate cached entry with remote site.
Definition: global.h:392
TDEIO::CC_Verify
@ CC_Verify
Validate cached entry with remote site if expired.
Definition: global.h:391
TDEIO::CC_Reload
@ CC_Reload
Always fetch from remote site.
Definition: global.h:394
TDEIO::unsupportedActionErrorString
TDEIO_EXPORT TQString unsupportedActionErrorString(const TQString &protocol, int cmd)
Returns an appropriate error message if the given command cmd is an unsupported action (ERR_UNSUPPORT...
Definition: global.cpp:439
TDEIO::findDeviceMountPoint
TDEIO_EXPORT TQString findDeviceMountPoint(const TQString &device)
Returns the mount point where device is mounted right now.
Definition: global.cpp:1401
TDEIO::decodeFileName
TDEIO_EXPORT TQString decodeFileName(const TQString &str)
Decodes (from the filename to the text displayed) This translates %2[fF] into /, %% into %,...
Definition: global.cpp:191
TDEIO::filesize_t
TQ_ULLONG filesize_t
64-bit file size
Definition: global.h:39
TDEIO::findPathMountPoint
TDEIO_EXPORT TQString findPathMountPoint(const TQString &filename)
Returns the mount point on which resides filename.
Definition: global.cpp:1944
TDEIO::itemsSummaryString
TDEIO_EXPORT TQString itemsSummaryString(uint items, uint files, uint dirs, TDEIO::filesize_t size, bool showSize)
Helper for showing information about a set of files and directories.
Definition: global.cpp:150

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.9.1
This website is maintained by Timothy Pearson.