KRename – powerful batch renamer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fileoperation.cpp 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /***************************************************************************
  2. fileoperation.cpp - description
  3. -------------------
  4. begin : Sun Nov 11 2001
  5. copyright : (C) 2001 by Dominik Seichter
  6. email : domseichter@web.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. // KDE includes
  17. #include <tdeapplication.h>
  18. #include <tdelocale.h>
  19. #include <tdeio/netaccess.h>
  20. #include <tdeio/job.h>
  21. // QT includes
  22. #include <tqeventloop.h>
  23. #include <tqfileinfo.h>
  24. // OS includes
  25. #include <stdio.h>
  26. #include <unistd.h>
  27. // Own includes
  28. #include "fileoperation.h"
  29. #include "ProgressDialog.h"
  30. #include "batchrenamer.h"
  31. using namespace TDEIO;
  32. FileOperation::FileOperation()
  33. {
  34. canceled = false;
  35. }
  36. FileOperation::~FileOperation() { }
  37. bool FileOperation::start( const KURL & src, const KURL & dest, int mode, bool overwrite )
  38. {
  39. locked = true;
  40. result = 0;
  41. if( src == dest && !overwrite ) {
  42. m_error = i18n( "File %1 exists already!").arg( dest.prettyURL() );
  43. return false;
  44. }
  45. Job* job = 0;
  46. switch( mode ) {
  47. case RENAME:
  48. case MOVE:
  49. default:
  50. job = file_move( src, dest, -1, overwrite, false, false );
  51. break;
  52. case COPY:
  53. job = file_copy( src, dest, -1, overwrite, false, false );
  54. break;
  55. case LINK:
  56. // Does only work if both files are on the same host
  57. if( src.protocol() == dest.protocol() && src.host() == dest.host() )
  58. {
  59. job = symlink( src.path(), dest, overwrite, false );
  60. }
  61. else
  62. {
  63. m_error = i18n("Can't create symlinks on different hosts for file %1.").arg( src.prettyURL() );
  64. result = true;
  65. return !result;
  66. }
  67. break;
  68. };
  69. if( !job )
  70. return false;
  71. job->setAutoErrorHandlingEnabled( false, 0 );
  72. connect( job, TQT_SIGNAL( result (TDEIO::Job *) ),
  73. this, TQT_SLOT( slotResult (TDEIO::Job *) ) );
  74. kapp->eventLoop()->enterLoop();
  75. return !result;
  76. }
  77. bool FileOperation::fcopy( const TQString & src, const TQString & dest )
  78. {
  79. return start( KURL( src ), KURL( dest ), TDEIO::CopyJob::Copy, false );
  80. }
  81. TQString FileOperation::getName( const TQString & file )
  82. {
  83. TQFileInfo info( file );
  84. return info.fileName();
  85. }
  86. void FileOperation::slotResult( TDEIO::Job * job )
  87. {
  88. result = job->error();
  89. if( result )
  90. m_error = job->errorString();
  91. kapp->eventLoop()->exitLoop();
  92. }
  93. #include "fileoperation.moc"