22 #include "tdeio/job.h"
26 #include <sys/types.h>
44 #include <tdeapplication.h>
45 #include <tdeglobal.h>
46 #include <tdelocale.h>
47 #include <ksimpleconfig.h>
50 #include <tdemessagebox.h>
51 #include <kdatastream.h>
52 #include <tdemainwindow.h>
57 #include "kmimetype.h"
59 #include "scheduler.h"
60 #include "kdirwatch.h"
61 #include "kmimemagic.h"
62 #include "kprotocolinfo.h"
63 #include "tdeprotocolmanager.h"
65 #include "tdeio/observer.h"
67 #include "kssl/ksslcsessioncache.h"
69 #include <kdirnotify_stub.h>
70 #include <tdetempfile.h>
71 #include <dcopclient.h>
81 using namespace TDEIO;
82 template class TQPtrList<TDEIO::Job>;
85 #define REPORT_TIMEOUT 200
87 #define KIO_ARGS TQByteArray packedArgs; TQDataStream stream( packedArgs, IO_WriteOnly ); stream
92 JobPrivate() : m_autoErrorHandling( false ), m_autoWarningHandling( true ),
93 m_interactive( true ), m_parentJob( 0L ), m_extraFlags(0),
94 m_processedSize(0), m_userTimestamp(0)
97 bool m_autoErrorHandling;
98 bool m_autoWarningHandling;
100 TQGuardedPtr<TQWidget> m_errorParentWidget;
106 unsigned long m_userTimestamp;
109 Job::Job(
bool showProgressInfo) : TQObject(0,
"job"), m_error(0), m_percent(0)
110 , m_progressId(0), m_speedTimer(0), d( new JobPrivate )
115 if ( showProgressInfo )
118 addMetaData(
"progress-id", TQString::number(m_progressId));
121 connect(
this, TQT_SIGNAL( percent(
TDEIO::Job*,
unsigned long ) ),
123 connect(
this, TQT_SIGNAL( infoMessage(
TDEIO::Job*,
const TQString & ) ),
129 connect(
this, TQT_SIGNAL( speed(
TDEIO::Job*,
unsigned long ) ),
136 updateUserTimestamp( kapp->userTimestamp());
147 int& Job::extraFlags()
149 return d->m_extraFlags;
154 d->m_processedSize = size;
159 return d->m_processedSize;
194 m_incomingMetaData += job->
metaData();
196 if ( subjobs.isEmpty() && emitResultIfLast )
203 unsigned long ipercent = m_percent;
205 if ( totalSize == 0 )
208 m_percent = (
unsigned long)(( (
float)(processedSize) / (
float)(totalSize) ) * 100.0);
210 if ( m_percent != ipercent || m_percent == 100 ) {
211 emit
percent(
this, m_percent );
221 m_speedTimer =
new TQTimer();
222 connect( m_speedTimer, TQT_SIGNAL( timeout() ), TQT_SLOT(
slotSpeedTimeout() ) );
224 emit
speed(
this, bytes_per_second );
225 m_speedTimer->start( 5000 );
233 if ( m_error && d->m_interactive && d->m_autoErrorHandling )
241 kdDebug(7007) <<
"Job::kill this=" <<
this <<
" " << className() <<
" m_progressId=" << m_progressId <<
" quietly=" << quietly << endl;
243 TQPtrListIterator<Job> it( subjobs );
244 for ( ; it.current() ; ++it )
249 m_error = ERR_USER_CANCELED;
263 if ( job->
error() && !m_error )
266 m_error = job->
error();
288 emit
speed(
this, 0 );
289 m_speedTimer->stop();
297 kapp->enableStyles();
299 if ( (m_error != ERR_USER_CANCELED) && (m_error != ERR_NO_CONTENT) ) {
303 KMessageBox::queuedMessageBox( parent, KMessageBox::Error,
errorString() );
307 TQString caption, err, detail;
308 TQStringList::const_iterator it = errors.begin();
309 if ( it != errors.end() )
311 if ( it != errors.end() )
313 if ( it != errors.end() )
315 KMessageBox::queuedDetailedError( parent, err, detail, caption );
321 void Job::setAutoErrorHandlingEnabled(
bool enable, TQWidget *parentWidget )
323 d->m_autoErrorHandling = enable;
324 d->m_errorParentWidget = parentWidget;
329 return d->m_autoErrorHandling;
334 d->m_autoWarningHandling = enable;
339 return d->m_autoWarningHandling;
344 d->m_interactive = enable;
349 return d->m_interactive;
366 if( d->m_userTimestamp == 0 || NET::timestampCompare( time, d->m_userTimestamp ) > 0 )
367 d->m_userTimestamp = time;
371 unsigned long Job::userTimestamp()
const
373 return d->m_userTimestamp;
378 Q_ASSERT(d->m_parentJob == 0L);
380 d->m_parentJob = job;
385 return d->m_parentJob;
390 return m_incomingMetaData;
395 if (!m_incomingMetaData.contains(key))
396 return TQString::null;
397 return m_incomingMetaData[key];
402 m_outgoingMetaData = _metaData;
407 m_outgoingMetaData.insert(key, value);
412 TQMapConstIterator<TQString,TQString> it = values.begin();
413 for(;it != values.end(); ++it)
414 m_outgoingMetaData.insert(it.key(), it.data());
419 TQMapConstIterator<TQString,TQString> it = values.begin();
420 for(;it != values.end(); ++it)
421 m_outgoingMetaData.insert(it.key(), it.data(),
false);
424 MetaData Job::outgoingMetaData()
const
426 return m_outgoingMetaData;
431 bool showProgressInfo )
432 :
Job(showProgressInfo), m_slave(0), m_packedArgs(packedArgs),
433 m_url(url), m_command(command), m_totalSize(0)
435 if (m_url.hasSubURL())
437 KURL::List list = KURL::split(m_url);
438 KURL::List::Iterator it = list.fromLast();
440 m_subUrl = KURL::join(list);
447 if (!m_url.isValid())
449 kdDebug() <<
"ERR_MALFORMED_URL" << endl;
450 m_error = ERR_MALFORMED_URL;
451 m_errorText = m_url.url();
452 TQTimer::singleShot(0,
this, TQT_SLOT(
slotFinished()) );
480 SimpleJob::~SimpleJob()
484 kdDebug(7007) <<
"SimpleJob::~SimpleJob: Killing running job in destructor!" << endl;
494 void SimpleJob::start(
Slave *slave)
498 connect( m_slave, TQT_SIGNAL(
error(
int ,
const TQString & ) ),
499 TQT_SLOT( slotError(
int ,
const TQString & ) ) );
501 connect( m_slave, TQT_SIGNAL(
warning(
const TQString & ) ),
502 TQT_SLOT( slotWarning(
const TQString & ) ) );
504 connect( m_slave, TQT_SIGNAL(
infoMessage(
const TQString & ) ),
507 connect( m_slave, TQT_SIGNAL(
connected() ),
510 connect( m_slave, TQT_SIGNAL( finished() ),
513 if ((extraFlags() & EF_TransferJobDataSent) == 0)
521 connect( m_slave, TQT_SIGNAL(
speed(
unsigned long ) ),
522 TQT_SLOT(
slotSpeed(
unsigned long ) ) );
525 connect( slave, TQT_SIGNAL( needProgressId() ),
526 TQT_SLOT( slotNeedProgressId() ) );
534 addMetaData(
"window-id",
id.setNum((ulong)m_window->winId()));
539 addMetaData(
"user-timestamp",
id.setNum(userTimestamp()));
542 TQString sslSession = KSSLCSessionCache::getSessionForURL(m_url);
543 if ( !sslSession.isNull() )
553 if (!m_outgoingMetaData.isEmpty())
555 KIO_ARGS << m_outgoingMetaData;
556 slave->
send( CMD_META_DATA, packedArgs );
559 if (!m_subUrl.isEmpty())
561 KIO_ARGS << m_subUrl;
562 m_slave->
send( CMD_SUBURL, packedArgs );
565 m_slave->
send( m_command, m_packedArgs );
568 void SimpleJob::slaveDone()
570 if (!m_slave)
return;
581 if (subjobs.isEmpty())
583 if ( !m_error && (m_command == CMD_MKDIR || m_command == CMD_RENAME ) )
585 KDirNotify_stub allDirNotify(
"*",
"KDirNotify*" );
586 if ( m_command == CMD_MKDIR )
588 KURL urlDir(
url() );
589 urlDir.setPath( urlDir.directory() );
590 allDirNotify.FilesAdded( urlDir );
595 TQDataStream str( m_packedArgs, IO_ReadOnly );
597 if ( src.directory() == dst.directory() )
598 allDirNotify.FileRenamed( src, dst );
605 void SimpleJob::slotError(
int error,
const TQString & errorText )
609 if ((m_error == ERR_UNKNOWN_HOST) && m_url.host().isEmpty())
610 m_errorText = TQString::null;
615 void SimpleJob::slotWarning(
const TQString & errorText )
617 TQGuardedPtr<SimpleJob> guard(
this );
620 static uint msgBoxDisplayed = 0;
621 if ( msgBoxDisplayed == 0 )
624 KMessageBox::information( 0L, errorText );
630 if ( !guard.isNull() )
631 emit
warning(
this, errorText );
644 void SimpleJob::slotNeedProgressId()
648 m_slave->setProgressId( m_progressId );
653 if (size > m_totalSize)
665 if ( size > m_totalSize ) {
679 m_incomingMetaData += _metaData;
682 void SimpleJob::storeSSLSessionFromJob(
const KURL &m_redirectionURL) {
685 if ( !sslSession.isNull() ) {
686 const KURL &queryURL = m_redirectionURL.isEmpty()?m_url:m_redirectionURL;
687 KSSLCSessionCache::putSessionForURL(queryURL, sslSession);
693 const TQByteArray &packedArgs,
bool showProgressInfo )
694 :
SimpleJob(url, command, packedArgs, showProgressInfo)
698 void MkdirJob::start(
Slave *slave)
700 connect( slave, TQT_SIGNAL(
redirection(
const KURL &) ),
701 TQT_SLOT( slotRedirection(
const KURL &) ) );
703 SimpleJob::start(slave);
707 void MkdirJob::slotRedirection(
const KURL &url)
709 kdDebug(7007) <<
"MkdirJob::slotRedirection(" << url <<
")" << endl;
710 if (!kapp->authorizeURLAction(
"redirect", m_url, url))
712 kdWarning(7007) <<
"MkdirJob: Redirection from " << m_url <<
" to " << url <<
" REJECTED!" << endl;
713 m_error = ERR_ACCESS_DENIED;
714 m_errorText = url.prettyURL();
717 m_redirectionURL =
url;
718 if (m_url.hasUser() && !url.hasUser() && (m_url.host().lower() == url.host().lower()))
719 m_redirectionURL.setUser(m_url.user());
724 void MkdirJob::slotFinished()
726 if ( m_redirectionURL.isEmpty() || !m_redirectionURL.isValid())
736 TQDataStream istream( m_packedArgs, IO_ReadOnly );
737 istream >> dummyUrl >> permissions;
739 m_url = m_redirectionURL;
740 m_redirectionURL = KURL();
741 m_packedArgs.truncate(0);
742 TQDataStream stream( m_packedArgs, IO_WriteOnly );
743 stream << m_url << permissions;
754 KIO_ARGS << url << permissions;
755 return new MkdirJob(url, CMD_MKDIR, packedArgs,
false);
761 KIO_ARGS << url << TQ_INT8(
false);
762 return new SimpleJob(url, CMD_DEL, packedArgs,
false);
768 KIO_ARGS << url << permissions;
769 return new SimpleJob(url, CMD_CHMOD, packedArgs,
false);
775 KIO_ARGS << src << dest << (TQ_INT8) overwrite;
776 return new SimpleJob(src, CMD_RENAME, packedArgs,
false);
782 KIO_ARGS << target << dest << (TQ_INT8) overwrite;
783 return new SimpleJob(dest, CMD_SYMLINK, packedArgs, showProgressInfo);
789 return new SimpleJob(url, CMD_SPECIAL, data, showProgressInfo);
792 SimpleJob *
TDEIO::mount(
bool ro,
const char *fstype,
const TQString& dev,
const TQString& point,
bool showProgressInfo )
794 KIO_ARGS << int(1) << TQ_INT8( ro ? 1 : 0 )
795 << TQString::fromLatin1(fstype) << dev << point;
797 if ( showProgressInfo )
804 KIO_ARGS << int(2) << point;
806 if ( showProgressInfo )
813 const TQByteArray &packedArgs,
bool showProgressInfo )
814 :
SimpleJob(url, command, packedArgs, showProgressInfo)
819 void LocalURLJob::start(
Slave *slave)
821 connect( slave, TQT_SIGNAL(
localURL(
const KURL &,
bool) ),
822 TQT_SLOT( slotLocalURL(
const KURL &,
bool) ) );
824 SimpleJob::start(slave);
828 void LocalURLJob::slotLocalURL(
const KURL &url,
bool isLocal)
830 kdDebug(7007) <<
"LocalURLJob::slotLocalURL(" << url <<
")" << endl;
834 void LocalURLJob::slotFinished()
842 KIO_ARGS << remoteUrl;
843 return new LocalURLJob(remoteUrl, CMD_LOCALURL, packedArgs,
false);
850 const TQByteArray &packedArgs,
bool showProgressInfo )
851 :
SimpleJob(url, command, packedArgs, showProgressInfo),
852 m_bSource(true), m_details(2)
856 void StatJob::start(
Slave *slave)
858 m_outgoingMetaData.replace(
"statSide", m_bSource ?
"source" :
"dest" );
859 m_outgoingMetaData.replace(
"details", TQString::number(m_details) );
863 connect( slave, TQT_SIGNAL(
redirection(
const KURL &) ),
864 TQT_SLOT( slotRedirection(
const KURL &) ) );
866 SimpleJob::start(slave);
872 m_statResult = entry;
876 void StatJob::slotRedirection(
const KURL &url)
878 kdDebug(7007) <<
"StatJob::slotRedirection(" << url <<
")" << endl;
879 if (!kapp->authorizeURLAction(
"redirect", m_url, url))
881 kdWarning(7007) <<
"StatJob: Redirection from " << m_url <<
" to " << url <<
" REJECTED!" << endl;
882 m_error = ERR_ACCESS_DENIED;
883 m_errorText = url.prettyURL();
886 m_redirectionURL =
url;
887 if (m_url.hasUser() && !url.hasUser() && (m_url.host().lower() == url.host().lower()))
888 m_redirectionURL.setUser(m_url.user());
893 void StatJob::slotFinished()
895 if ( m_redirectionURL.isEmpty() || !m_redirectionURL.isValid())
903 m_url = m_redirectionURL;
904 m_redirectionURL = KURL();
905 m_packedArgs.truncate(0);
906 TQDataStream stream( m_packedArgs, IO_WriteOnly );
917 storeSSLSessionFromJob(m_redirectionURL);
923 return stat( url,
true, 2, showProgressInfo );
928 kdDebug(7007) <<
"stat " << url << endl;
930 StatJob * job =
new StatJob(url, CMD_STAT, packedArgs, showProgressInfo );
933 if ( showProgressInfo )
940 assert( (url.protocol() ==
"http") || (url.protocol() ==
"https") );
942 KIO_ARGS << (int)2 << url << no_cache << expireDate;
951 const TQByteArray &packedArgs,
952 const TQByteArray &_staticData,
953 bool showProgressInfo)
954 :
SimpleJob(url, command, packedArgs, showProgressInfo), staticData( _staticData)
959 if ( showProgressInfo )
964 void TransferJob::slotData(
const TQByteArray &_data)
966 if(m_redirectionURL.isEmpty() || !m_redirectionURL.isValid() || m_error)
967 emit
data(
this, _data);
971 void TransferJob::slotRedirection(
const KURL &url)
973 kdDebug(7007) <<
"TransferJob::slotRedirection(" << url <<
")" << endl;
974 if (!kapp->authorizeURLAction(
"redirect", m_url, url))
976 kdWarning(7007) <<
"TransferJob: Redirection from " << m_url <<
" to " << url <<
" REJECTED!" << endl;
983 if (m_redirectionList.contains(url) > 5)
985 kdDebug(7007) <<
"TransferJob::slotRedirection: CYCLIC REDIRECTION!" << endl;
986 m_error = ERR_CYCLIC_LINK;
987 m_errorText = m_url.prettyURL();
991 m_redirectionURL =
url;
992 if (m_url.hasUser() && !url.hasUser() && (m_url.host().lower() == url.host().lower()))
993 m_redirectionURL.setUser(m_url.user());
994 m_redirectionList.append(url);
995 m_outgoingMetaData[
"ssl_was_in_use"] = m_incomingMetaData[
"ssl_in_use"];
1001 void TransferJob::slotFinished()
1004 if (m_redirectionURL.isEmpty() || !m_redirectionURL.isValid())
1014 staticData.truncate(0);
1015 m_incomingMetaData.clear();
1018 m_suspended =
false;
1019 m_url = m_redirectionURL;
1020 m_redirectionURL = KURL();
1024 TQDataStream istream( m_packedArgs, IO_ReadOnly );
1025 switch( m_command ) {
1027 m_packedArgs.truncate(0);
1028 TQDataStream stream( m_packedArgs, IO_WriteOnly );
1034 TQ_INT8 iOverwrite, iResume;
1035 istream >> dummyUrl >> iOverwrite >> iResume >> permissions;
1036 m_packedArgs.truncate(0);
1037 TQDataStream stream( m_packedArgs, IO_WriteOnly );
1038 stream << m_url << iOverwrite << iResume << permissions;
1043 istream >> specialcmd;
1044 if (specialcmd == 1)
1047 m_packedArgs.truncate(0);
1048 TQDataStream stream( m_packedArgs, IO_WriteOnly );
1050 m_command = CMD_GET;
1065 extraFlags() |= EF_TransferJobAsync;
1067 extraFlags() &= ~EF_TransferJobAsync;
1072 if (extraFlags() & EF_TransferJobNeedData)
1074 m_slave->
send( MSG_DATA, dataForSlave );
1075 if (extraFlags() & EF_TransferJobDataSent)
1080 if ( size > m_totalSize ) {
1087 extraFlags() &= ~EF_TransferJobNeedData;
1093 extraFlags() |= EF_TransferJobDataSent;
1095 extraFlags() &= ~EF_TransferJobDataSent;
1100 return (extraFlags() & EF_TransferJobDataSent);
1105 void TransferJob::slotDataReq()
1107 TQByteArray dataForSlave;
1109 extraFlags() |= EF_TransferJobNeedData;
1111 if (!staticData.isEmpty())
1113 dataForSlave = staticData;
1114 staticData = TQByteArray();
1118 emit
dataReq(
this, dataForSlave);
1120 if (extraFlags() & EF_TransferJobAsync)
1124 static const size_t max_size = 14 * 1024 * 1024;
1125 if (dataForSlave.size() > max_size)
1127 kdDebug(7007) <<
"send " << dataForSlave.size() / 1024 / 1024 <<
"MB of data in TransferJob::dataReq. This needs to be splitted, which requires a copy. Fix the application.\n";
1128 staticData.duplicate(dataForSlave.data() + max_size , dataForSlave.size() - max_size);
1129 dataForSlave.truncate(max_size);
1142 void TransferJob::slotMimetype(
const TQString& type )
1158 m_suspended =
false;
1163 void TransferJob::start(
Slave *slave)
1166 connect( slave, TQT_SIGNAL(
data(
const TQByteArray & ) ),
1167 TQT_SLOT( slotData(
const TQByteArray & ) ) );
1169 connect( slave, TQT_SIGNAL(
dataReq() ),
1170 TQT_SLOT( slotDataReq() ) );
1172 connect( slave, TQT_SIGNAL(
redirection(
const KURL &) ),
1173 TQT_SLOT( slotRedirection(
const KURL &) ) );
1175 connect( slave, TQT_SIGNAL(mimeType(
const TQString& ) ),
1176 TQT_SLOT( slotMimetype(
const TQString& ) ) );
1178 connect( slave, TQT_SIGNAL(errorPage() ),
1179 TQT_SLOT( slotErrorPage() ) );
1181 connect( slave, TQT_SIGNAL( needSubURLData() ),
1182 TQT_SLOT( slotNeedSubURLData() ) );
1189 m_mimetype =
"unknown";
1194 SimpleJob::start(slave);
1199 void TransferJob::slotNeedSubURLData()
1202 m_subJob =
TDEIO::get( m_subUrl,
false,
false);
1204 connect(m_subJob, TQT_SIGNAL(
data(
TDEIO::Job*,
const TQByteArray &)),
1205 TQT_SLOT( slotSubURLData(
TDEIO::Job*,
const TQByteArray &)));
1209 void TransferJob::slotSubURLData(
TDEIO::Job*,
const TQByteArray &data)
1219 storeSSLSessionFromJob(m_redirectionURL);
1222 void TransferJob::slotErrorPage()
1229 emit canResume(
this, offset);
1235 assert(job == m_subJob);
1239 m_error = job->
error();
1246 if (job == m_subJob)
1268 PostErrorJob(
int _error,
const TQString& url,
const TQByteArray &packedArgs,
const TQByteArray &postData,
bool showProgressInfo)
1269 :
TransferJob(KURL(), CMD_SPECIAL, packedArgs, postData, showProgressInfo)
1282 static const int bad_ports[] = {
1344 for (
int cnt=0; bad_ports[cnt]; ++cnt)
1345 if (url.port() == bad_ports[cnt])
1347 _error = TDEIO::ERR_POST_DENIED;
1353 static bool override_loaded =
false;
1354 static TQValueList< int >* overriden_ports = NULL;
1355 if( !override_loaded )
1357 TDEConfig cfg(
"tdeio_httprc",
true );
1358 overriden_ports =
new TQValueList< int >;
1359 *overriden_ports = cfg.readIntListEntry(
"OverriddenPorts" );
1360 override_loaded =
true;
1362 for( TQValueList< int >::ConstIterator it = overriden_ports->begin();
1363 it != overriden_ports->end();
1365 if( overriden_ports->contains( url.port()))
1370 if ((url.protocol() !=
"http") && (url.protocol() !=
"https" ))
1371 _error = TDEIO::ERR_POST_DENIED;
1373 bool redirection =
false;
1375 if (_url.path().isEmpty())
1381 if (!_error && !kapp->authorizeURLAction(
"open", KURL(), _url))
1382 _error = TDEIO::ERR_ACCESS_DENIED;
1387 KIO_ARGS << (int)1 << url;
1388 TransferJob * job =
new PostErrorJob(_error, url.prettyURL(), packedArgs, postData, showProgressInfo);
1393 KIO_ARGS << (int)1 << _url;
1395 packedArgs, postData, showProgressInfo );
1398 TQTimer::singleShot(0, job, TQT_SLOT(slotPostRedirection()) );
1406 void TransferJob::slotPostRedirection()
1408 kdDebug(7007) <<
"TransferJob::slotPostRedirection(" << m_url <<
")" << endl;
1415 bool overwrite,
bool resume,
bool showProgressInfo )
1417 KIO_ARGS << url << TQ_INT8( overwrite ? 1 : 0 ) << TQ_INT8( resume ? 1 : 0 ) << permissions;
1425 const TQByteArray &packedArgs,
1426 const TQByteArray &_staticData,
1427 bool showProgressInfo)
1428 :
TransferJob( url, command, packedArgs, _staticData, showProgressInfo ),
1431 connect(
this, TQT_SIGNAL(
data(
TDEIO::Job *,
const TQByteArray & ) ),
1432 TQT_SLOT( slotStoredData(
TDEIO::Job *,
const TQByteArray & ) ) );
1434 TQT_SLOT( slotStoredDataReq(
TDEIO::Job *, TQByteArray & ) ) );
1439 Q_ASSERT( m_data.isNull() );
1440 Q_ASSERT( m_uploadOffset == 0 );
1444 void StoredTransferJob::slotStoredData(
TDEIO::Job *,
const TQByteArray &data )
1447 if ( data.size() == 0 )
1449 unsigned int oldSize = m_data.size();
1450 m_data.resize( oldSize + data.size(), TQGArray::SpeedOptim );
1451 memcpy( m_data.data() + oldSize, data.data(), data.size() );
1454 void StoredTransferJob::slotStoredDataReq(
TDEIO::Job *, TQByteArray &data )
1458 const int MAX_CHUNK_SIZE = 64*1024;
1459 int remainingBytes = m_data.size() - m_uploadOffset;
1460 if( remainingBytes > MAX_CHUNK_SIZE ) {
1462 data.duplicate( m_data.data() + m_uploadOffset, MAX_CHUNK_SIZE );
1463 m_uploadOffset += MAX_CHUNK_SIZE;
1468 data.duplicate( m_data.data() + m_uploadOffset, remainingBytes );
1469 m_data = TQByteArray();
1486 bool overwrite,
bool resume,
bool showProgressInfo )
1488 KIO_ARGS << url << TQ_INT8( overwrite ? 1 : 0 ) << TQ_INT8( resume ? 1 : 0 ) << permissions;
1497 const TQByteArray &packedArgs,
bool showProgressInfo )
1498 :
TransferJob(url, command, packedArgs, TQByteArray(), showProgressInfo)
1502 void MimetypeJob::start(
Slave *slave)
1504 TransferJob::start(slave);
1508 void MimetypeJob::slotFinished( )
1511 if ( m_error == TDEIO::ERR_IS_DIRECTORY )
1516 kdDebug(7007) <<
"It is in fact a directory!" << endl;
1517 m_mimetype = TQString::fromLatin1(
"inode/directory");
1521 if ( m_redirectionURL.isEmpty() || !m_redirectionURL.isValid() || m_error )
1524 TransferJob::slotFinished();
1529 staticData.truncate(0);
1530 m_suspended =
false;
1531 m_url = m_redirectionURL;
1532 m_redirectionURL = KURL();
1533 m_packedArgs.truncate(0);
1534 TQDataStream stream( m_packedArgs, IO_WriteOnly );
1547 if ( showProgressInfo )
1554 DirectCopyJob::DirectCopyJob(
const KURL& url,
int command,
1555 const TQByteArray &packedArgs,
bool showProgressInfo )
1556 :
SimpleJob(url, command, packedArgs, showProgressInfo)
1560 void DirectCopyJob::start(
Slave* slave )
1564 SimpleJob::start(slave);
1569 emit canResume(
this, offset);
1575 class FileCopyJob::FileCopyJobPrivate
1579 time_t m_modificationTime;
1590 FileCopyJob::FileCopyJob(
const KURL& src,
const KURL& dest,
int permissions,
1591 bool move,
bool overwrite,
bool resume,
bool showProgressInfo)
1592 :
Job(showProgressInfo), m_src(src), m_dest(dest),
1593 m_permissions(permissions), m_move(move), m_overwrite(overwrite), m_resume(resume),
1596 if (showProgressInfo && !move)
1598 else if (showProgressInfo && move)
1606 d =
new FileCopyJobPrivate;
1609 d->m_modificationTime =
static_cast<time_t
>( -1 );
1610 TQTimer::singleShot(0,
this, TQT_SLOT(slotStart()));
1613 void FileCopyJob::slotStart()
1618 if ((m_src.protocol() == m_dest.protocol()) &&
1619 (m_src.host() == m_dest.host()) &&
1620 (m_src.port() == m_dest.port()) &&
1621 (m_src.user() == m_dest.user()) &&
1622 (m_src.pass() == m_dest.pass()) &&
1623 !m_src.hasSubURL() && !m_dest.hasSubURL())
1625 startRenameJob(m_src);
1628 else if (m_src.isLocalFile() && KProtocolInfo::canRenameFromFile(m_dest))
1630 startRenameJob(m_dest);
1635 startRenameJob(m_src);
1640 startBestCopyMethod();
1643 void FileCopyJob::startBestCopyMethod()
1645 if ((m_src.protocol() == m_dest.protocol()) &&
1646 (m_src.host() == m_dest.host()) &&
1647 (m_src.port() == m_dest.port()) &&
1648 (m_src.user() == m_dest.user()) &&
1649 (m_src.pass() == m_dest.pass()) &&
1650 !m_src.hasSubURL() && !m_dest.hasSubURL())
1656 startCopyJob(m_dest);
1660 startCopyJob(m_src);
1668 FileCopyJob::~FileCopyJob()
1675 d->m_sourceSize = size;
1676 if (size != (off_t) -1)
1682 d->m_sourceSize = size;
1689 d->m_modificationTime = mtime;
1692 void FileCopyJob::startCopyJob()
1694 startCopyJob(m_src);
1697 void FileCopyJob::startCopyJob(
const KURL &slave_url)
1700 KIO_ARGS << m_src << m_dest << m_permissions << (TQ_INT8) m_overwrite;
1701 m_copyJob =
new DirectCopyJob(slave_url, CMD_COPY, packedArgs,
false);
1703 connectSubjob( m_copyJob );
1708 void FileCopyJob::startRenameJob(
const KURL &slave_url)
1710 KIO_ARGS << m_src << m_dest << (TQ_INT8) m_overwrite;
1711 m_moveJob =
new SimpleJob(slave_url, CMD_RENAME, packedArgs,
false);
1713 connectSubjob( m_moveJob );
1716 void FileCopyJob::connectSubjob(
SimpleJob * job )
1733 if ( size > m_totalSize ) {
1741 if (size > m_totalSize)
1750 if ( pct > m_percent )
1753 emit
percent(
this, m_percent );
1757 void FileCopyJob::startDataPump()
1761 m_canResume =
false;
1762 m_resumeAnswerSent =
false;
1764 m_putJob =
put( m_dest, m_permissions, m_overwrite, m_resume,
false );
1765 if ( d->m_modificationTime != static_cast<time_t>( -1 ) ) {
1766 TQDateTime dt; dt.setTime_t( d->m_modificationTime );
1767 m_putJob->
addMetaData(
"modified", dt.toString( Qt::ISODate ) );
1775 connect( m_putJob, TQT_SIGNAL(dataReq(
TDEIO::Job *, TQByteArray&)),
1776 TQT_SLOT( slotDataReq(
TDEIO::Job *, TQByteArray&)));
1782 if ( job == m_putJob || job == m_copyJob )
1795 job, i18n(
"File Already Exists"),
1798 (RenameDlg_Mode) (M_OVERWRITE | M_RESUME | M_NORENAME), newPath,
1799 d->m_sourceSize, offset );
1802 if ( res == R_OVERWRITE || m_overwrite )
1804 else if ( res == R_CANCEL )
1806 if ( job == m_putJob )
1807 m_putJob->
kill(
true);
1809 m_copyJob->kill(
true);
1810 m_error = ERR_USER_CANCELED;
1816 m_resumeAnswerSent =
true;
1818 if ( job == m_putJob )
1820 m_getJob =
get( m_src,
false,
false );
1823 m_getJob->
addMetaData(
"AllowCompressedPage",
"false" );
1838 m_putJob->slave()->setOffset( offset );
1842 connectSubjob( m_getJob );
1845 connect( m_getJob, TQT_SIGNAL(data(
TDEIO::Job*,
const TQByteArray&)),
1846 TQT_SLOT( slotData(
TDEIO::Job*,
const TQByteArray&)) );
1848 TQT_SLOT(slotMimetype(
TDEIO::Job*,
const TQString&)) );
1852 m_copyJob->slave()->sendResumeAnswer( offset != 0 );
1855 else if ( job == m_getJob )
1861 m_getJob->slave()->setOffset( m_putJob->slave()->offset() );
1864 kdWarning(7007) <<
"FileCopyJob::slotCanResume from unknown job=" << job
1865 <<
" m_getJob=" << m_getJob <<
" m_putJob=" << m_putJob << endl;
1868 void FileCopyJob::slotData(
TDEIO::Job * ,
const TQByteArray &data)
1873 if (!m_putJob)
return;
1880 if (!m_resumeAnswerSent)
1882 m_resumeAnswerSent =
true;
1888 void FileCopyJob::slotDataReq(
TDEIO::Job * , TQByteArray &data)
1891 if (!m_resumeAnswerSent && !m_getJob)
1894 m_error = ERR_INTERNAL;
1895 m_errorText =
"'Put' job didn't send canResume or 'Get' job didn't send data!";
1896 m_putJob->
kill(
true);
1906 m_buffer = TQByteArray();
1909 void FileCopyJob::slotMimetype(
TDEIO::Job*,
const TQString& type )
1920 if ((job == m_moveJob) && (job->
error() == ERR_UNSUPPORTED_ACTION))
1923 startBestCopyMethod();
1927 else if ((job == m_copyJob) && (job->
error() == ERR_UNSUPPORTED_ACTION))
1934 else if (job == m_getJob)
1938 m_putJob->
kill(
true);
1940 else if (job == m_putJob)
1944 m_getJob->
kill(
true);
1946 m_error = job->
error();
1952 if (job == m_moveJob)
1957 if (job == m_copyJob)
1967 if (job == m_getJob)
1974 if (job == m_putJob)
1980 kdWarning(7007) <<
"WARNING ! Get still going on..." << endl;
1990 if (job == d->m_delJob)
1998 bool overwrite,
bool resume,
bool showProgressInfo)
2000 return new FileCopyJob( src, dest, permissions,
false, overwrite, resume, showProgressInfo );
2004 bool overwrite,
bool resume,
bool showProgressInfo)
2006 return new FileCopyJob( src, dest, permissions,
true, overwrite, resume, showProgressInfo );
2011 KIO_ARGS << src << TQ_INT8(
true);
2012 return new SimpleJob(src, CMD_DEL, packedArgs, showProgressInfo );
2018 ListJob::ListJob(
const KURL& u,
bool showProgressInfo,
bool _recursive, TQString _prefix,
bool _includeHidden) :
2019 SimpleJob(u, CMD_LISTDIR, TQByteArray(), showProgressInfo),
2020 recursive(_recursive), includeHidden(_includeHidden), prefix(_prefix), m_processedEntries(0)
2024 TQDataStream stream( m_packedArgs, IO_WriteOnly );
2028 void ListJob::slotListEntries(
const TDEIO::UDSEntryList& list )
2031 m_processedEntries += list.count();
2035 UDSEntryListConstIterator it = list.begin();
2036 UDSEntryListConstIterator end = list.end();
2038 for (; it != end; ++it) {
2040 bool isLink =
false;
2043 UDSEntry::ConstIterator it2 = (*it).begin();
2044 UDSEntry::ConstIterator end2 = (*it).end();
2045 for( ; it2 != end2; it2++ ) {
2046 switch( (*it2).m_uds ) {
2048 isDir = S_ISDIR((*it2).m_long);
2051 if( itemURL.isEmpty() ) {
2053 itemURL.addPath( (*it2).m_str );
2057 itemURL = (*it2).m_str;
2061 isLink = !(*it2).m_str.isEmpty();
2067 if (isDir && !isLink) {
2068 const TQString filename = itemURL.fileName();
2070 if (filename !=
".." && filename !=
"." && (includeHidden || filename[0] !=
'.')) {
2074 prefix + filename +
"/",
2078 const TDEIO::UDSEntryList& )),
2080 const TDEIO::UDSEntryList& )));
2090 if (prefix.isNull() && includeHidden) {
2094 UDSEntryList newlist;
2096 UDSEntryListConstIterator it = list.begin();
2097 UDSEntryListConstIterator end = list.end();
2098 for (; it != end; ++it) {
2101 UDSEntry::Iterator it2 = newone.begin();
2103 for( ; it2 != newone.end(); it2++ ) {
2105 filename = (*it2).m_str;
2106 (*it2).m_str = prefix + filename;
2111 if ( (prefix.isNull() || (filename !=
".." && filename !=
".") )
2112 && (includeHidden || (filename[0] !=
'.') ) )
2113 newlist.append(newone);
2120 void ListJob::gotEntries(
TDEIO::Job *,
const TDEIO::UDSEntryList& list )
2133 void ListJob::slotRedirection(
const KURL & url )
2135 if (!kapp->authorizeURLAction(
"redirect", m_url, url))
2137 kdWarning(7007) <<
"ListJob: Redirection from " << m_url <<
" to " << url <<
" REJECTED!" << endl;
2140 m_redirectionURL =
url;
2141 if (m_url.hasUser() && !url.hasUser() && (m_url.host().lower() == url.host().lower()))
2142 m_redirectionURL.setUser(m_url.user());
2146 void ListJob::slotFinished()
2149 if ( m_error == TDEIO::ERR_IS_FILE && m_url.isLocalFile() ) {
2152 TQString proto = ptr->property(
"X-TDE-LocalProtocol").toString();
2154 m_redirectionURL = m_url;
2155 m_redirectionURL.setProtocol( proto );
2161 if ( m_redirectionURL.isEmpty() || !m_redirectionURL.isValid() || m_error ) {
2169 m_url = m_redirectionURL;
2170 m_redirectionURL = KURL();
2171 m_packedArgs.truncate(0);
2172 TQDataStream stream( m_packedArgs, IO_WriteOnly );
2183 storeSSLSessionFromJob(m_redirectionURL);
2188 ListJob * job =
new ListJob(url, showProgressInfo,
false,TQString::null,includeHidden);
2194 ListJob * job =
new ListJob(url, showProgressInfo,
true,TQString::null,includeHidden);
2201 extraFlags() |= EF_ListJobUnrestricted;
2203 extraFlags() &= ~EF_ListJobUnrestricted;
2206 void ListJob::start(
Slave *slave)
2208 if (kapp && !kapp->authorizeURLAction(
"list", m_url, m_url) && !(extraFlags() & EF_ListJobUnrestricted))
2210 m_error = ERR_ACCESS_DENIED;
2211 m_errorText = m_url.url();
2212 TQTimer::singleShot(0,
this, TQT_SLOT(slotFinished()) );
2215 connect( slave, TQT_SIGNAL( listEntries(
const TDEIO::UDSEntryList& )),
2216 TQT_SLOT( slotListEntries(
const TDEIO::UDSEntryList& )));
2219 connect( slave, TQT_SIGNAL(
redirection(
const KURL &) ),
2220 TQT_SLOT( slotRedirection(
const KURL &) ) );
2222 SimpleJob::start(slave);
2225 class CopyJob::CopyJobPrivate
2229 m_defaultPermissions =
false;
2230 m_bURLDirty =
false;
2238 CopyJob::DestinationState m_globalDestinationState;
2240 bool m_defaultPermissions;
2245 TQValueList<CopyInfo> m_directoriesCopied;
2249 :
Job(showProgressInfo), m_mode(mode), m_asMethod(asMethod),
2250 destinationState(DEST_NOT_STATED), state(STATE_STATING),
2251 m_totalSize(0), m_processedSize(0), m_fileProcessedSize(0),
2252 m_processedFiles(0), m_processedDirs(0),
2253 m_srcList(src), m_currentStatSrc(m_srcList.begin()),
2254 m_bCurrentOperationIsLink(false), m_bSingleFileCopy(false), m_bOnlyRenames(mode==Move),
2255 m_dest(dest), m_bAutoSkip( false ), m_bOverwriteAll( false ),
2256 m_conflictError(0), m_reportTimer(0)
2258 d =
new CopyJobPrivate;
2259 d->m_globalDest = dest;
2260 d->m_globalDestinationState = destinationState;
2262 if ( showProgressInfo ) {
2269 TQTimer::singleShot(0,
this, TQT_SLOT(
slotStart()));
2298 m_reportTimer =
new TQTimer(
this);
2300 connect(m_reportTimer,TQT_SIGNAL(timeout()),
this,TQT_SLOT(slotReport()));
2301 m_reportTimer->start(REPORT_TIMEOUT,
false);
2310 TDEIO_EXPORT
bool tdeio_resolve_local_urls =
true;
2312 void CopyJob::slotResultStating(
Job *job )
2316 if (job->
error() && destinationState != DEST_NOT_STATED )
2319 if ( !srcurl.isLocalFile() )
2324 kdDebug(7007) <<
"Error while stating source. Activating hack" << endl;
2325 subjobs.remove( job );
2326 assert ( subjobs.isEmpty() );
2327 struct CopyInfo info;
2328 info.permissions = (mode_t) -1;
2329 info.mtime = (time_t) -1;
2330 info.ctime = (time_t) -1;
2332 info.uSource = srcurl;
2333 info.uDest = m_dest;
2335 if ( destinationState == DEST_IS_DIR && !m_asMethod )
2336 info.uDest.addPath( srcurl.fileName() );
2338 files.append( info );
2352 TQString sLocalPath;
2353 UDSEntry::ConstIterator it2 = entry.begin();
2354 for( ; it2 != entry.end(); it2++ ) {
2356 bDir = S_ISDIR( (mode_t)(*it2).m_long );
2358 bLink = !((*it2).m_str.isEmpty());
2359 else if ( ((*it2).m_uds) ==
UDS_NAME )
2360 sName = (*it2).m_str;
2362 sLocalPath = (*it2).m_str;
2365 if ( destinationState == DEST_NOT_STATED )
2369 destinationState = DEST_DOESNT_EXIST;
2372 destinationState = bDir ? DEST_IS_DIR : DEST_IS_FILE;
2375 const bool isGlobalDest = m_dest == d->m_globalDest;
2377 d->m_globalDestinationState = destinationState;
2379 if ( !sLocalPath.isEmpty() && tdeio_resolve_local_urls ) {
2381 m_dest.setPath(sLocalPath);
2383 d->m_globalDest = m_dest;
2386 subjobs.remove( job );
2387 assert ( subjobs.isEmpty() );
2394 m_currentDest = m_dest;
2411 m_bCurrentSrcIsDir =
false;
2412 slotEntries(job, lst);
2415 if (!sLocalPath.isEmpty())
2416 srcurl.setPath(sLocalPath);
2420 subjobs.remove( job );
2421 assert ( subjobs.isEmpty() );
2429 m_bCurrentSrcIsDir =
true;
2430 if ( destinationState == DEST_IS_DIR )
2435 TQString directory = srcurl.fileName();
2440 m_currentDest.addPath( directory );
2443 else if ( destinationState == DEST_IS_FILE )
2445 m_error = ERR_IS_FILE;
2446 m_errorText = m_dest.prettyURL();
2456 destinationState = DEST_IS_DIR;
2457 if ( m_dest == d->m_globalDest )
2458 d->m_globalDestinationState = destinationState;
2461 startListing( srcurl );
2470 void CopyJob::slotReport()
2475 case STATE_COPYING_FILES:
2477 if (observer) observer->slotProcessedFiles(
this, m_processedFiles);
2481 d->m_bURLDirty =
false;
2484 if (observer) observer->slotMoving(
this, m_currentSrcURL, m_currentDestURL);
2485 emit
moving(
this, m_currentSrcURL, m_currentDestURL);
2487 else if (m_mode==Link)
2489 if (observer) observer->slotCopying(
this, m_currentSrcURL, m_currentDestURL );
2490 emit
linking(
this, m_currentSrcURL.path(), m_currentDestURL );
2494 if (observer) observer->slotCopying(
this, m_currentSrcURL, m_currentDestURL );
2495 emit
copying(
this, m_currentSrcURL, m_currentDestURL );
2500 case STATE_CREATING_DIRS:
2501 if (observer) observer->slotProcessedDirs(
this, m_processedDirs );
2505 d->m_bURLDirty =
false;
2507 if (observer) observer->slotCreatingDir(
this, m_currentDestURL);
2515 d->m_bURLDirty =
false;
2516 if (observer) observer->slotCopying(
this, m_currentSrcURL, m_currentDestURL );
2528 void CopyJob::slotEntries(
TDEIO::Job* job,
const UDSEntryList& list)
2530 UDSEntryListConstIterator it = list.begin();
2531 UDSEntryListConstIterator end = list.end();
2532 for (; it != end; ++it) {
2533 UDSEntry::ConstIterator it2 = (*it).begin();
2534 struct CopyInfo info;
2535 info.permissions = -1;
2536 info.mtime = (time_t) -1;
2537 info.ctime = (time_t) -1;
2539 TQString displayName;
2543 for( ; it2 != (*it).end(); it2++ ) {
2544 switch ((*it2).m_uds) {
2547 isDir = S_ISDIR( (mode_t)((*it2).m_long) );
2550 displayName = (*it2).m_str;
2553 url = KURL((*it2).m_str);
2556 localPath = (*it2).m_str;
2559 info.linkDest = (*it2).m_str;
2562 info.permissions = ((*it2).m_long);
2566 m_totalSize += info.size;
2569 info.mtime = (time_t)((*it2).m_long);
2572 info.ctime = (time_t)((*it2).m_long);
2577 if (displayName !=
".." && displayName !=
".")
2579 bool hasCustomURL = !url.isEmpty() || !localPath.isEmpty();
2580 if( !hasCustomURL ) {
2583 if ( m_bCurrentSrcIsDir ) {
2585 url.addPath( displayName );
2589 if (!localPath.isEmpty() && tdeio_resolve_local_urls) {
2591 url.setPath(localPath);
2595 info.uDest = m_currentDest;
2598 if ( destinationState == DEST_IS_DIR &&
2601 ( ! ( m_asMethod && state == STATE_STATING ) ) )
2603 TQString destFileName;
2604 if ( hasCustomURL &&
2605 KProtocolInfo::fileNameUsedForCopying( url ) == KProtocolInfo::FromURL ) {
2608 int numberOfSlashes = displayName.contains(
'/' );
2609 TQString path = url.path();
2611 for (
int n = 0; n < numberOfSlashes + 1; ++n ) {
2612 pos = path.findRev(
'/', pos - 1 );
2614 kdWarning(7007) <<
"tdeioslave bug: not enough slashes in UDS_URL " << path <<
" - looking for " << numberOfSlashes <<
" slashes" << endl;
2619 destFileName = path.mid( pos + 1 );
2623 destFileName = displayName;
2629 if ( destFileName.isEmpty() )
2633 info.uDest.addPath( destFileName );
2637 if ( info.linkDest.isEmpty() && isDir && m_mode != Link )
2639 dirs.append( info );
2641 dirsToRemove.append( info.uSource );
2644 files.append( info );
2650 void CopyJob::skipSrc()
2652 m_dest = d->m_globalDest;
2653 destinationState = d->m_globalDestinationState;
2655 skip( m_currentSrcURL );
2659 void CopyJob::statNextSrc()
2665 m_dest = d->m_globalDest;
2666 destinationState = d->m_globalDestinationState;
2671 void CopyJob::statCurrentSrc()
2673 if ( m_currentStatSrc != m_srcList.end() )
2675 m_currentSrcURL = (*m_currentStatSrc);
2676 d->m_bURLDirty =
true;
2677 if ( m_mode == Link )
2680 m_currentDest = m_dest;
2681 struct CopyInfo info;
2682 info.permissions = -1;
2683 info.mtime = (time_t) -1;
2684 info.ctime = (time_t) -1;
2686 info.uSource = m_currentSrcURL;
2687 info.uDest = m_currentDest;
2689 if ( destinationState == DEST_IS_DIR && !m_asMethod )
2692 (m_currentSrcURL.protocol() == info.uDest.protocol()) &&
2693 (m_currentSrcURL.host() == info.uDest.host()) &&
2694 (m_currentSrcURL.port() == info.uDest.port()) &&
2695 (m_currentSrcURL.user() == info.uDest.user()) &&
2696 (m_currentSrcURL.pass() == info.uDest.pass()) )
2699 info.uDest.addPath( m_currentSrcURL.fileName() );
2709 files.append( info );
2713 else if ( m_mode == Move && (
2715 KProtocolInfo::fileNameUsedForCopying( m_currentSrcURL ) == KProtocolInfo::FromURL ||
2716 destinationState != DEST_IS_DIR || m_asMethod )
2721 if ( (m_currentSrcURL.protocol() == m_dest.protocol()) &&
2722 (m_currentSrcURL.host() == m_dest.host()) &&
2723 (m_currentSrcURL.port() == m_dest.port()) &&
2724 (m_currentSrcURL.user() == m_dest.user()) &&
2725 (m_currentSrcURL.pass() == m_dest.pass()) )
2727 startRenameJob( m_currentSrcURL );
2732 startRenameJob( m_dest );
2737 startRenameJob( m_currentSrcURL );
2744 TQGuardedPtr<CopyJob> that =
this;
2746 KMessageBox::information( 0,
buildErrorString(ERR_CANNOT_DELETE, m_currentSrcURL.prettyURL()));
2755 state = STATE_STATING;
2757 m_currentDestURL=m_dest;
2758 m_bOnlyRenames =
false;
2759 d->m_bURLDirty =
true;
2765 state = STATE_STATING;
2766 d->m_bURLDirty =
true;
2768 if (!dirs.isEmpty())
2770 if (!files.isEmpty())
2773 m_bSingleFileCopy = ( files.count() == 1 && dirs.isEmpty() );
2775 state = STATE_CREATING_DIRS;
2780 void CopyJob::startRenameJob(
const KURL& slave_url )
2784 if ( destinationState == DEST_IS_DIR && !m_asMethod )
2785 dest.addPath( m_currentSrcURL.fileName() );
2786 kdDebug(7007) <<
"This seems to be a suitable case for trying to rename before stat+[list+]copy+del" << endl;
2787 state = STATE_RENAMING;
2789 struct CopyInfo info;
2790 info.permissions = -1;
2791 info.mtime = (time_t) -1;
2792 info.ctime = (time_t) -1;
2794 info.uSource = m_currentSrcURL;
2796 TQValueList<CopyInfo> files;
2800 KIO_ARGS << m_currentSrcURL << dest << (TQ_INT8)
false ;
2804 if ( m_currentSrcURL.directory() != dest.directory() )
2805 m_bOnlyRenames =
false;
2808 void CopyJob::startListing(
const KURL & src )
2810 state = STATE_LISTING;
2811 d->m_bURLDirty =
true;
2814 connect(newjob, TQT_SIGNAL(entries(
TDEIO::Job *,
2815 const TDEIO::UDSEntryList& )),
2817 const TDEIO::UDSEntryList& )));
2821 void CopyJob::skip(
const KURL & sourceUrl )
2826 KURL::List::Iterator sit = m_srcList.find( sourceUrl );
2827 if ( sit != m_srcList.end() )
2830 m_srcList.remove( sit );
2832 dirsToRemove.remove( sourceUrl );
2835 bool CopyJob::shouldOverwrite(
const TQString& path )
const
2837 if ( m_bOverwriteAll )
2839 TQStringList::ConstIterator sit = m_overwriteList.begin();
2840 for( ; sit != m_overwriteList.end(); ++sit )
2841 if ( path.startsWith( *sit ) )
2846 bool CopyJob::shouldSkip(
const TQString& path )
const
2848 TQStringList::ConstIterator sit = m_skipList.begin();
2849 for( ; sit != m_skipList.end(); ++sit )
2850 if ( path.startsWith( *sit ) )
2855 void CopyJob::slotResultCreatingDirs(
Job * job )
2858 TQValueList<CopyInfo>::Iterator it = dirs.begin();
2862 m_conflictError = job->
error();
2863 if ( (m_conflictError == ERR_DIR_ALREADY_EXIST)
2864 || (m_conflictError == ERR_FILE_ALREADY_EXIST) )
2868 if ( m_bAutoSkip ) {
2870 m_skipList.append( oldURL.path( 1 ) );
2875 const TQString destFile = (*it).uDest.path();
2876 if ( shouldOverwrite( destFile ) ) {
2877 emit
copyingDone(
this, ( *it ).uSource, ( *it ).uDest,
true ,
false );
2885 assert( ((
SimpleJob*)job)->url().url() == (*it).uDest.url() );
2886 subjobs.remove( job );
2887 assert ( subjobs.isEmpty() );
2890 KURL existingDest( (*it).uDest );
2893 kdDebug(7007) <<
"TDEIO::stat for resolving conflict on " << existingDest << endl;
2894 state = STATE_CONFLICT_CREATING_DIRS;
2910 emit
copyingDone(
this, (*it).uSource, (*it).uDest,
true,
false );
2911 d->m_directoriesCopied.append( *it );
2917 subjobs.remove( job );
2918 assert( subjobs.isEmpty() );
2922 void CopyJob::slotResultConflictCreatingDirs(
TDEIO::Job * job )
2927 TQValueList<CopyInfo>::Iterator it = dirs.begin();
2929 time_t destmtime = (time_t)-1;
2930 time_t destctime = (time_t)-1;
2935 TDEIO::UDSEntry::ConstIterator it2 = entry.begin();
2936 for( ; it2 != entry.end(); it2++ ) {
2937 switch ((*it2).m_uds) {
2939 destmtime = (time_t)((*it2).m_long);
2942 destctime = (time_t)((*it2).m_long);
2945 destsize = (*it2).m_long;
2948 linkDest = (*it2).m_str;
2952 subjobs.remove( job );
2953 assert ( subjobs.isEmpty() );
2956 RenameDlg_Mode mode = (RenameDlg_Mode)( M_MULTI | M_SKIP );
2958 if ( m_conflictError == ERR_DIR_ALREADY_EXIST )
2960 if( (*it).uSource == (*it).uDest ||
2961 ((*it).uSource.protocol() == (*it).uDest.protocol() &&
2962 (*it).uSource.path(-1) == linkDest) )
2963 mode = (RenameDlg_Mode)( mode | M_OVERWRITE_ITSELF);
2965 mode = (RenameDlg_Mode)( mode | M_OVERWRITE );
2968 TQString existingDest = (*it).uDest.path();
2971 m_reportTimer->stop();
2973 (*it).uSource.url(),
2976 (*it).size, destsize,
2977 (*it).ctime, destctime,
2978 (*it).mtime, destmtime );
2980 m_reportTimer->start(REPORT_TIMEOUT,
false);
2983 m_error = ERR_USER_CANCELED;
2988 TQString oldPath = (*it).uDest.path( 1 );
2989 KURL newUrl( (*it).uDest );
2990 newUrl.setPath( newPath );
2991 emit
renamed(
this, (*it).uDest, newUrl );
2994 (*it).uDest.setPath( newUrl.path( -1 ) );
2995 newPath = newUrl.path( 1 );
2996 TQValueList<CopyInfo>::Iterator renamedirit = it;
2999 for( ; renamedirit != dirs.end() ; ++renamedirit )
3001 TQString path = (*renamedirit).uDest.path();
3002 if ( path.left(oldPath.length()) == oldPath ) {
3004 n.replace( 0, oldPath.length(), newPath );
3005 kdDebug(7007) <<
"dirs list: " << (*renamedirit).uSource.path()
3006 <<
" was going to be " << path
3007 <<
", changed into " << n << endl;
3008 (*renamedirit).uDest.setPath( n );
3012 TQValueList<CopyInfo>::Iterator renamefileit = files.begin();
3013 for( ; renamefileit != files.end() ; ++renamefileit )
3015 TQString path = (*renamefileit).uDest.path();
3016 if ( path.left(oldPath.length()) == oldPath ) {
3018 n.replace( 0, oldPath.length(), newPath );
3019 kdDebug(7007) <<
"files list: " << (*renamefileit).uSource.path()
3020 <<
" was going to be " << path
3021 <<
", changed into " << n << endl;
3022 (*renamefileit).uDest.setPath( n );
3025 if (!dirs.isEmpty())
3027 if (!files.isEmpty())
3035 m_skipList.append( existingDest );
3036 skip( (*it).uSource );
3042 m_overwriteList.append( existingDest );
3043 emit
copyingDone(
this, ( *it ).uSource, ( *it ).uDest,
true ,
false );
3048 case R_OVERWRITE_ALL:
3049 m_bOverwriteAll =
true;
3050 emit
copyingDone(
this, ( *it ).uSource, ( *it ).uDest,
true ,
false );
3058 state = STATE_CREATING_DIRS;
3063 void CopyJob::createNextDir()
3066 if ( !dirs.isEmpty() )
3069 TQValueList<CopyInfo>::Iterator it = dirs.begin();
3071 while( it != dirs.end() && udir.isEmpty() )
3073 const TQString dir = (*it).uDest.path();
3074 if ( shouldSkip( dir ) ) {
3081 if ( !udir.isEmpty() )
3088 m_currentDestURL = udir;
3089 d->m_bURLDirty =
true;
3097 if (m_progressId)
Observer::self()->slotProcessedDirs(
this, m_processedDirs );
3099 state = STATE_COPYING_FILES;
3105 void CopyJob::slotResultCopyingFiles(
Job * job )
3108 TQValueList<CopyInfo>::Iterator it = files.begin();
3114 skip( (*it).uSource );
3115 m_fileProcessedSize = (*it).size;
3125 m_conflictError = job->
error();
3127 if ( ( m_conflictError == ERR_FILE_ALREADY_EXIST )
3128 || ( m_conflictError == ERR_DIR_ALREADY_EXIST )
3129 || ( m_conflictError == ERR_IDENTICAL_FILES ) )
3131 subjobs.remove( job );
3132 assert ( subjobs.isEmpty() );
3134 KURL existingFile( (*it).uDest );
3137 kdDebug(7007) <<
"TDEIO::stat for resolving conflict on " << existingFile << endl;
3138 state = STATE_CONFLICT_COPYING_FILES;
3144 if ( m_bCurrentOperationIsLink && ::tqqt_cast<TDEIO::DeleteJob*>( job ) )
3148 m_fileProcessedSize = (*it).size;
3152 slotResultConflictCopyingFiles( job );
3160 if ( m_bCurrentOperationIsLink && m_mode == Move
3161 && !::tqqt_cast<TDEIO::DeleteJob *>( job )
3164 subjobs.remove( job );
3165 assert ( subjobs.isEmpty() );
3173 if ( m_bCurrentOperationIsLink )
3175 TQString target = ( m_mode == Link ? (*it).uSource.path() : (*it).linkDest );
3181 emit
copyingDone(
this, (*it).uSource, (*it).uDest,
false,
false );
3188 m_processedSize += m_fileProcessedSize;
3189 m_fileProcessedSize = 0;
3194 assert ( subjobs.isEmpty() );
3198 void CopyJob::slotResultConflictCopyingFiles(
TDEIO::Job * job )
3202 TQValueList<CopyInfo>::Iterator it = files.begin();
3208 m_reportTimer->stop();
3210 if ( ( m_conflictError == ERR_FILE_ALREADY_EXIST )
3211 || ( m_conflictError == ERR_DIR_ALREADY_EXIST )
3212 || ( m_conflictError == ERR_IDENTICAL_FILES ) )
3215 time_t destmtime = (time_t)-1;
3216 time_t destctime = (time_t)-1;
3220 TDEIO::UDSEntry::ConstIterator it2 = entry.begin();
3221 for( ; it2 != entry.end(); it2++ ) {
3222 switch ((*it2).m_uds) {
3224 destmtime = (time_t)((*it2).m_long);
3227 destctime = (time_t)((*it2).m_long);
3230 destsize = (*it2).m_long;
3233 linkDest = (*it2).m_str;
3240 RenameDlg_Mode mode;
3243 if( m_conflictError == ERR_DIR_ALREADY_EXIST )
3244 mode = (RenameDlg_Mode) 0;
3247 if ( (*it).uSource == (*it).uDest ||
3248 ((*it).uSource.protocol() == (*it).uDest.protocol() &&
3249 (*it).uSource.path(-1) == linkDest) )
3250 mode = M_OVERWRITE_ITSELF;
3256 if ( m_bSingleFileCopy )
3257 mode = (RenameDlg_Mode) ( mode | M_SINGLE );
3259 mode = (RenameDlg_Mode) ( mode | M_MULTI | M_SKIP );
3262 i18n(
"File Already Exists") : i18n(
"Already Exists as Folder"),
3263 (*it).uSource.url(),
3266 (*it).size, destsize,
3267 (*it).ctime, destctime,
3268 (*it).mtime, destmtime );
3273 if ( job->
error() == ERR_USER_CANCELED )
3281 SkipDlg_Result skipResult =
Observer::self()->open_SkipDlg(
this, files.count() > 1,
3285 res = ( skipResult == S_SKIP ) ? R_SKIP :
3286 ( skipResult == S_AUTO_SKIP ) ? R_AUTO_SKIP :
3292 m_reportTimer->start(REPORT_TIMEOUT,
false);
3294 subjobs.remove( job );
3295 assert ( subjobs.isEmpty() );
3298 m_error = ERR_USER_CANCELED;
3303 KURL newUrl( (*it).uDest );
3304 newUrl.setPath( newPath );
3305 emit
renamed(
this, (*it).uDest, newUrl );
3306 (*it).uDest = newUrl;
3308 TQValueList<CopyInfo> files;
3318 skip( (*it).uSource );
3319 m_processedSize += (*it).size;
3323 case R_OVERWRITE_ALL:
3324 m_bOverwriteAll =
true;
3328 m_overwriteList.append( (*it).uDest.path() );
3333 state = STATE_COPYING_FILES;
3338 void CopyJob::copyNextFile()
3340 bool bCopyFile =
false;
3343 TQValueList<CopyInfo>::Iterator it = files.begin();
3345 while (it != files.end() && !bCopyFile)
3347 const TQString destFile = (*it).uDest.path();
3348 bCopyFile = !shouldSkip( destFile );
3359 const TQString destFile = (*it).uDest.path();
3360 kdDebug(7007) <<
"copying " << destFile << endl;
3361 if ( (*it).uDest == (*it).uSource )
3364 bOverwrite = shouldOverwrite( destFile );
3366 m_bCurrentOperationIsLink =
false;
3368 if ( m_mode == Link )
3372 ((*it).uSource.protocol() == (*it).uDest.protocol()) &&
3373 ((*it).uSource.host() == (*it).uDest.host()) &&
3374 ((*it).uSource.port() == (*it).uDest.port()) &&
3375 ((*it).uSource.user() == (*it).uDest.user()) &&
3376 ((*it).uSource.pass() == (*it).uDest.pass()) )
3384 m_bCurrentOperationIsLink =
true;
3385 m_currentSrcURL=(*it).uSource;
3386 m_currentDestURL=(*it).uDest;
3387 d->m_bURLDirty =
true;
3391 if ( (*it).uDest.isLocalFile() )
3393 bool devicesOk=
false;
3396 if ((*it).uSource.protocol()==TQString::fromLatin1(
"devices"))
3401 TQDataStream streamout(param,IO_WriteOnly);
3402 streamout<<(*it).uSource;
3403 streamout<<(*it).uDest;
3404 if ( kapp && kapp->dcopClient()->call(
"kded",
3405 "mountwatcher",
"createLink(KURL, KURL)", param,retType,data,
false ) )
3407 TQDataStream streamin(data,IO_ReadOnly);
3408 streamin>>devicesOk;
3422 TQString path = (*it).uDest.path();
3425 if ( f.open( IO_ReadWrite ) )
3428 KSimpleConfig config( path );
3429 config.setDesktopGroup();
3430 KURL url = (*it).uSource;
3432 config.writePathEntry( TQString::fromLatin1(
"URL"), url.url() );
3433 config.writeEntry( TQString::fromLatin1(
"Name"), url.url() );
3434 config.writeEntry( TQString::fromLatin1(
"Type"), TQString::fromLatin1(
"Link") );
3435 TQString protocol = (*it).uSource.protocol();
3436 if ( protocol == TQString::fromLatin1(
"ftp") )
3437 config.writeEntry( TQString::fromLatin1(
"Icon"), TQString::fromLatin1(
"ftp") );
3438 else if ( protocol == TQString::fromLatin1(
"http") )
3439 config.writeEntry( TQString::fromLatin1(
"Icon"), TQString::fromLatin1(
"www") );
3440 else if ( protocol == TQString::fromLatin1(
"info") )
3441 config.writeEntry( TQString::fromLatin1(
"Icon"), TQString::fromLatin1(
"info") );
3442 else if ( protocol == TQString::fromLatin1(
"mailto") )
3443 config.writeEntry( TQString::fromLatin1(
"Icon"), TQString::fromLatin1(
"kmail") );
3445 config.writeEntry( TQString::fromLatin1(
"Icon"), TQString::fromLatin1(
"unknown") );
3455 kdDebug(7007) <<
"CopyJob::copyNextFile ERR_CANNOT_OPEN_FOR_WRITING" << endl;
3456 m_error = ERR_CANNOT_OPEN_FOR_WRITING;
3457 m_errorText = (*it).uDest.path();
3464 m_error = ERR_CANNOT_SYMLINK;
3465 m_errorText = (*it).uDest.prettyURL();
3471 else if ( !(*it).linkDest.isEmpty() &&
3472 ((*it).uSource.protocol() == (*it).uDest.protocol()) &&
3473 ((*it).uSource.host() == (*it).uDest.host()) &&
3474 ((*it).uSource.port() == (*it).uDest.port()) &&
3475 ((*it).uSource.user() == (*it).uDest.user()) &&
3476 ((*it).uSource.pass() == (*it).uDest.pass()))
3484 m_currentSrcURL=(*it).linkDest;
3485 m_currentDestURL=(*it).uDest;
3486 d->m_bURLDirty =
true;
3488 m_bCurrentOperationIsLink =
true;
3490 }
else if (m_mode == Move)
3497 m_currentSrcURL=(*it).uSource;
3498 m_currentDestURL=(*it).uDest;
3499 d->m_bURLDirty =
true;
3507 int permissions = (*it).permissions;
3508 if ( d->m_defaultPermissions || ( remoteSource && (*it).uDest.isLocalFile() ) )
3516 m_currentSrcURL=(*it).uSource;
3517 m_currentDestURL=(*it).uDest;
3518 d->m_bURLDirty =
true;
3534 void CopyJob::deleteNextDir()
3536 if ( m_mode == Move && !dirsToRemove.isEmpty() )
3538 state = STATE_DELETING_DIRS;
3539 d->m_bURLDirty =
true;
3541 KURL::List::Iterator it = dirsToRemove.fromLast();
3544 dirsToRemove.remove(it);
3550 setNextDirAttribute();
3554 void CopyJob::setNextDirAttribute()
3556 if ( !d->m_directoriesCopied.isEmpty() )
3558 state = STATE_SETTING_DIR_ATTRIBUTES;
3561 TQValueList<CopyInfo>::Iterator it = d->m_directoriesCopied.begin();
3562 for ( ; it != d->m_directoriesCopied.end() ; ++it ) {
3563 const KURL& url = (*it).uDest;
3564 if ( url.isLocalFile() && (*it).mtime != (time_t)-1 ) {
3565 const TQCString path = TQFile::encodeName( url.path() );
3566 KDE_struct_stat statbuf;
3567 if (KDE_lstat(path, &statbuf) == 0) {
3568 struct utimbuf utbuf;
3569 utbuf.actime = statbuf.st_atime;
3570 utbuf.modtime = (*it).mtime;
3571 utime( path, &utbuf );
3577 d->m_directoriesCopied.clear();
3584 if ( !m_bOnlyRenames )
3586 KDirNotify_stub allDirNotify(
"*",
"KDirNotify*");
3587 KURL url( d->m_globalDest );
3588 if ( d->m_globalDestinationState != DEST_IS_DIR || m_asMethod )
3589 url.setPath( url.directory() );
3591 allDirNotify.FilesAdded( url );
3593 if ( m_mode == Move && !m_srcList.isEmpty() ) {
3595 allDirNotify.FilesRemoved( m_srcList );
3599 m_reportTimer->stop();
3610 m_fileProcessedSize = data_size;
3613 if ( m_processedSize + m_fileProcessedSize > m_totalSize )
3615 m_totalSize = m_processedSize + m_fileProcessedSize;
3620 emit
processedSize(
this, m_processedSize + m_fileProcessedSize );
3621 emitPercent( m_processedSize + m_fileProcessedSize, m_totalSize );
3631 if ( m_bSingleFileCopy && size > m_totalSize)
3639 void CopyJob::slotResultDeletingDirs(
Job * job )
3647 subjobs.remove( job );
3648 assert ( subjobs.isEmpty() );
3653 void CopyJob::slotResultSettingDirAttributes(
Job * job )
3661 subjobs.remove( job );
3662 assert ( subjobs.isEmpty() );
3663 setNextDirAttribute();
3667 void CopyJob::slotResultRenaming(
Job* job )
3669 int err = job->
error();
3670 const TQString errText = job->
errorText();
3672 assert ( subjobs.isEmpty() );
3675 if ( destinationState == DEST_IS_DIR && !m_asMethod )
3676 dest.addPath( m_currentSrcURL.fileName() );
3682 if ( m_currentSrcURL.isLocalFile() && m_currentSrcURL.url(-1) != dest.url(-1) &&
3683 m_currentSrcURL.url(-1).lower() == dest.url(-1).lower() &&
3684 ( err == ERR_FILE_ALREADY_EXIST ||
3685 err == ERR_DIR_ALREADY_EXIST ||
3686 err == ERR_IDENTICAL_FILES ) )
3688 kdDebug(7007) <<
"Couldn't rename directly, dest already exists. Detected special case of lower/uppercase renaming in same dir, try with 2 rename calls" << endl;
3689 TQCString _src( TQFile::encodeName(m_currentSrcURL.path()) );
3690 TQCString _dest( TQFile::encodeName(dest.path()) );
3691 KTempFile tmpFile( m_currentSrcURL.directory(
false) );
3692 TQCString _tmp( TQFile::encodeName(tmpFile.name()) );
3693 kdDebug(7007) <<
"CopyJob::slotResult KTempFile status:" << tmpFile.status() <<
" using " << _tmp <<
" as intermediary" << endl;
3695 if ( ::
rename( _src, _tmp ) == 0 )
3697 if ( !TQFile::exists( _dest ) && ::
rename( _tmp, _dest ) == 0 )
3699 kdDebug(7007) <<
"Success." << endl;
3705 if ( ::
rename( _tmp, _src ) != 0 ) {
3706 kdError(7007) <<
"Couldn't rename " << tmpFile.name() <<
" back to " << _src <<
" !" << endl;
3724 Q_ASSERT( m_currentSrcURL == *m_currentStatSrc );
3727 if ( ( err == ERR_DIR_ALREADY_EXIST ||
3728 err == ERR_FILE_ALREADY_EXIST ||
3729 err == ERR_IDENTICAL_FILES )
3733 m_reportTimer->stop();
3736 if ( m_bAutoSkip ) {
3740 }
else if ( m_bOverwriteAll ) {
3745 RenameDlg_Mode mode = (RenameDlg_Mode)
3746 ( ( m_currentSrcURL == dest ) ? M_OVERWRITE_ITSELF : M_OVERWRITE );
3748 if ( m_srcList.count() > 1 )
3749 mode = (RenameDlg_Mode) ( mode | M_MULTI | M_SKIP );
3751 mode = (RenameDlg_Mode) ( mode | M_SINGLE );
3758 time_t ctimeSrc = (time_t) -1;
3759 time_t ctimeDest = (time_t) -1;
3760 time_t mtimeSrc = (time_t) -1;
3761 time_t mtimeDest = (time_t) -1;
3763 KDE_struct_stat stat_buf;
3764 if ( m_currentSrcURL.isLocalFile() &&
3765 KDE_stat(TQFile::encodeName(m_currentSrcURL.path()), &stat_buf) == 0 ) {
3766 sizeSrc = stat_buf.st_size;
3767 ctimeSrc = stat_buf.st_ctime;
3768 mtimeSrc = stat_buf.st_mtime;
3770 if ( dest.isLocalFile() &&
3771 KDE_stat(TQFile::encodeName(dest.path()), &stat_buf) == 0 ) {
3772 sizeDest = stat_buf.st_size;
3773 ctimeDest = stat_buf.st_ctime;
3774 mtimeDest = stat_buf.st_mtime;
3779 err != ERR_DIR_ALREADY_EXIST ? i18n(
"File Already Exists") : i18n(
"Already Exists as Folder"),
3780 m_currentSrcURL.url(),
3784 ctimeSrc, ctimeDest,
3785 mtimeSrc, mtimeDest );
3787 m_reportTimer->start(REPORT_TIMEOUT,
false);
3793 m_error = ERR_USER_CANCELED;
3801 m_dest.setPath( newPath );
3803 state = STATE_STATING;
3804 destinationState = DEST_NOT_STATED;
3815 case R_OVERWRITE_ALL:
3816 m_bOverwriteAll =
true;
3824 kdDebug(7007) <<
"adding to overwrite list: " << dest.path() << endl;
3825 m_overwriteList.append( dest.path() );
3832 }
else if ( err != TDEIO::ERR_UNSUPPORTED_ACTION ) {
3833 kdDebug(7007) <<
"Couldn't rename " << m_currentSrcURL <<
" to " << dest <<
", aborting" << endl;
3835 m_errorText = errText;
3839 kdDebug(7007) <<
"Couldn't rename " << m_currentSrcURL <<
" to " << dest <<
", reverting to normal way, starting with stat" << endl;
3842 state = STATE_STATING;
3844 m_bOnlyRenames =
false;
3849 emit
copyingDone(
this, *m_currentStatSrc, dest,
true,
true );
3854 void CopyJob::slotResult(
Job *job )
3864 slotResultStating( job );
3866 case STATE_RENAMING:
3868 slotResultRenaming( job );
3880 subjobs.remove( job );
3881 assert ( subjobs.isEmpty() );
3885 case STATE_CREATING_DIRS:
3886 slotResultCreatingDirs( job );
3888 case STATE_CONFLICT_CREATING_DIRS:
3889 slotResultConflictCreatingDirs( job );
3891 case STATE_COPYING_FILES:
3892 slotResultCopyingFiles( job );
3894 case STATE_CONFLICT_COPYING_FILES:
3895 slotResultConflictCopyingFiles( job );
3897 case STATE_DELETING_DIRS:
3898 slotResultDeletingDirs( job );
3900 case STATE_SETTING_DIR_ATTRIBUTES:
3911 d->m_defaultPermissions = b;
3924 srcList.append( src );
3925 return new CopyJob( srcList, dest, CopyJob::Copy,
false, showProgressInfo );
3932 srcList.append( src );
3933 return new CopyJob( srcList, dest, CopyJob::Copy,
true, showProgressInfo );
3939 return new CopyJob( src, dest, CopyJob::Copy,
false, showProgressInfo );
3946 srcList.append( src );
3947 return new CopyJob( srcList, dest, CopyJob::Move,
false, showProgressInfo );
3954 srcList.append( src );
3955 return new CopyJob( srcList, dest, CopyJob::Move,
true, showProgressInfo );
3961 return new CopyJob( src, dest, CopyJob::Move,
false, showProgressInfo );
3967 srcList.append( src );
3968 return new CopyJob( srcList, destDir, CopyJob::Link,
false, showProgressInfo );
3973 return new CopyJob( srcList, destDir, CopyJob::Link,
false, showProgressInfo );
3979 srcList.append( src );
3980 return new CopyJob( srcList, destDir, CopyJob::Link,
false, showProgressInfo );
3986 srcList.append( src );
3987 return new CopyJob( srcList, KURL(
"trash:/" ), CopyJob::Move,
false, showProgressInfo );
3992 return new CopyJob( srcList, KURL(
"trash:/" ), CopyJob::Move,
false, showProgressInfo );
3998 :
Job(showProgressInfo), m_totalSize( 0 ), m_processedSize( 0 ), m_fileProcessedSize( 0 ),
3999 m_processedFiles( 0 ), m_processedDirs( 0 ), m_totalFilesDirs( 0 ),
4000 m_srcList(src), m_currentStat(m_srcList.begin()), m_reportTimer(0)
4002 if ( showProgressInfo ) {
4005 Observer::self(), TQT_SLOT( slotTotalFiles(
TDEIO::Job*,
unsigned long ) ) );
4008 Observer::self(), TQT_SLOT( slotTotalDirs(
TDEIO::Job*,
unsigned long ) ) );
4020 m_reportTimer=
new TQTimer(
this);
4021 connect(m_reportTimer,TQT_SIGNAL(timeout()),
this,TQT_SLOT(slotReport()));
4023 m_reportTimer->start(REPORT_TIMEOUT,
false);
4026 TQTimer::singleShot(0,
this, TQT_SLOT(slotStart()));
4029 void DeleteJob::slotStart()
4037 void DeleteJob::slotReport()
4039 if (m_progressId==0)
4044 emit
deleting(
this, m_currentURL );
4045 observer->slotDeleting(
this,m_currentURL);
4054 case STATE_DELETING_DIRS:
4056 observer->slotProcessedDirs(
this,m_processedDirs);
4057 emitPercent( m_processedFiles + m_processedDirs, m_totalFilesDirs );
4059 case STATE_DELETING_FILES:
4060 observer->slotProcessedFiles(
this,m_processedFiles);
4062 emitPercent( m_processedFiles, m_totalFilesDirs );
4068 void DeleteJob::slotEntries(
TDEIO::Job* job,
const UDSEntryList& list)
4070 UDSEntryListConstIterator it = list.begin();
4071 UDSEntryListConstIterator end = list.end();
4072 for (; it != end; ++it)
4074 UDSEntry::ConstIterator it2 = (*it).begin();
4077 TQString displayName;
4080 for( ; it2 != (*it).end(); it2++ )
4082 switch ((*it2).m_uds)
4085 bDir = S_ISDIR((*it2).m_long);
4089 displayName = (*it2).m_str;
4093 url = KURL((*it2).m_str);
4097 bLink = !(*it2).m_str.isEmpty();
4107 if (atomsFound==5)
break;
4109 assert(!displayName.isEmpty());
4110 if (displayName !=
".." && displayName !=
".")
4112 if( url.isEmpty() ) {
4114 url.addPath( displayName );
4118 symlinks.append( url );
4122 files.append( url );
4128 void DeleteJob::statNextSrc()
4131 if ( m_currentStat != m_srcList.end() )
4133 m_currentURL = (*m_currentStat);
4137 TQGuardedPtr<DeleteJob> that =
this;
4140 KMessageBox::information( 0,
buildErrorString(ERR_CANNOT_DELETE, m_currentURL.prettyURL()));
4146 state = STATE_STATING;
4155 m_totalFilesDirs = files.count()+symlinks.count() + dirs.count();
4161 for ( TQStringList::Iterator it = m_parentDirs.begin() ; it != m_parentDirs.end() ; ++it )
4163 state = STATE_DELETING_FILES;
4168 void DeleteJob::deleteNextFile()
4171 if ( !files.isEmpty() || !symlinks.isEmpty() )
4176 KURL::List::Iterator it = files.begin();
4177 bool isLink =
false;
4178 if ( it == files.end() )
4180 it = symlinks.begin();
4185 if ( (*it).isLocalFile() && unlink( TQFile::encodeName((*it).path()) ) == 0 ) {
4189 if ( m_processedFiles % 300 == 0 || m_totalFilesDirs < 300) {
4200 symlinks.remove(it);
4208 }
while (!job && (!files.isEmpty() || !symlinks.isEmpty()));
4210 state = STATE_DELETING_DIRS;
4214 void DeleteJob::deleteNextDir()
4216 if ( !dirs.isEmpty() )
4220 KURL::List::Iterator it = dirs.fromLast();
4222 if ( (*it).isLocalFile() &&
::rmdir( TQFile::encodeName((*it).path()) ) == 0 ) {
4225 if ( m_processedDirs % 100 == 0 ) {
4231 if ( KProtocolInfo::canDeleteRecursive( *it ) ) {
4244 }
while ( !dirs.isEmpty() );
4248 for ( TQStringList::Iterator it = m_parentDirs.begin() ; it != m_parentDirs.end() ; ++it )
4252 if ( !m_srcList.isEmpty() )
4254 KDirNotify_stub allDirNotify(
"*",
"KDirNotify*");
4256 allDirNotify.FilesRemoved( m_srcList );
4258 if (m_reportTimer!=0)
4259 m_reportTimer->stop();
4269 m_fileProcessedSize = data_size;
4274 emit
processedSize(
this, m_processedSize + m_fileProcessedSize );
4277 unsigned long ipercent = m_percent;
4279 if ( m_totalSize == 0 )
4282 m_percent = (
unsigned long)(( (
float)(m_processedSize + m_fileProcessedSize) / (
float)m_totalSize ) * 100.0);
4284 if ( m_percent > ipercent )
4286 emit
percent(
this, m_percent );
4292 void DeleteJob::slotResult(
Job *job )
4311 UDSEntry::ConstIterator it2 = entry.begin();
4313 for( ; it2 != entry.end(); it2++ )
4317 bDir = S_ISDIR( (mode_t)(*it2).m_long );
4322 bLink = !((*it2).m_str.isEmpty());
4325 else if ( ((*it2).m_uds) ==
UDS_SIZE )
4327 size = (*it2).m_long;
4330 if (atomsFound==3)
break;
4335 subjobs.remove( job );
4336 assert( subjobs.isEmpty() );
4342 if ( url.isLocalFile() && !m_parentDirs.contains( url.path(-1) ) )
4343 m_parentDirs.append( url.path(-1) );
4345 if ( !KProtocolInfo::canDeleteRecursive( url ) ) {
4348 state = STATE_LISTING;
4352 connect(newjob, TQT_SIGNAL(entries(
TDEIO::Job *,
4353 const TDEIO::UDSEntryList& )),
4355 const TDEIO::UDSEntryList& )));
4366 symlinks.append( url );
4369 files.append( url );
4371 if ( url.isLocalFile() && !m_parentDirs.contains( url.directory(
false) ) )
4372 m_parentDirs.append( url.directory(
false) );
4383 subjobs.remove( job );
4384 assert( subjobs.isEmpty() );
4388 case STATE_DELETING_FILES:
4394 subjobs.remove( job );
4395 assert( subjobs.isEmpty() );
4400 case STATE_DELETING_DIRS:
4406 subjobs.remove( job );
4407 assert( subjobs.isEmpty() );
4423 srcList.append( src );
4435 bool showProgressInfo)
4436 :
TransferJob(url, 0, TQByteArray(), TQByteArray(), showProgressInfo)
4438 m_waitQueue.setAutoDelete(
true);
4439 m_activeQueue.setAutoDelete(
true);
4445 GetRequest *entry =
new GetRequest(
id, url, metaData);
4446 entry->metaData[
"request-id"] = TQString(
"%1").arg(
id);
4447 m_waitQueue.append(entry);
4450 void MultiGetJob::flushQueue(TQPtrList<GetRequest> &queue)
4455 for(entry = m_waitQueue.first(); entry; )
4457 if ((m_url.protocol() == entry->url.protocol()) &&
4458 (m_url.host() == entry->url.host()) &&
4459 (m_url.port() == entry->url.port()) &&
4460 (m_url.user() == entry->url.user()))
4463 queue.append(entry);
4464 entry = m_waitQueue.current();
4468 entry = m_waitQueue.next();
4472 KIO_ARGS << (TQ_INT32) queue.count();
4473 for(entry = queue.first(); entry; entry = queue.next())
4475 stream << entry->url << entry->metaData;
4477 m_packedArgs = packedArgs;
4478 m_command = CMD_MULTI_GET;
4479 m_outgoingMetaData.clear();
4482 void MultiGetJob::start(
Slave *slave)
4485 GetRequest *entry = m_waitQueue.take(0);
4486 m_activeQueue.append(entry);
4490 if (!entry->url.protocol().startsWith(
"http"))
4493 KIO_ARGS << entry->url;
4494 m_packedArgs = packedArgs;
4495 m_outgoingMetaData = entry->metaData;
4496 m_command = CMD_GET;
4497 b_multiGetActive =
false;
4501 flushQueue(m_activeQueue);
4502 b_multiGetActive =
true;
4505 TransferJob::start(slave);
4508 bool MultiGetJob::findCurrentEntry()
4510 if (b_multiGetActive)
4512 long id = m_incomingMetaData[
"request-id"].toLong();
4513 for(GetRequest *entry = m_activeQueue.first(); entry; entry = m_activeQueue.next())
4515 if (entry->id ==
id)
4517 m_currentEntry = entry;
4526 m_currentEntry = m_activeQueue.first();
4527 return (m_currentEntry != 0);
4531 void MultiGetJob::slotRedirection(
const KURL &url)
4533 if (!findCurrentEntry())
return;
4534 if (kapp && !kapp->authorizeURLAction(
"redirect", m_url, url))
4536 kdWarning(7007) <<
"MultiGetJob: Redirection from " << m_currentEntry->url <<
" to " << url <<
" REJECTED!" << endl;
4539 m_redirectionURL =
url;
4540 if (m_currentEntry->url.hasUser() && !url.hasUser() && (m_currentEntry->url.host().lower() == url.host().lower()))
4541 m_redirectionURL.setUser(m_currentEntry->url.user());
4542 get(m_currentEntry->id, m_redirectionURL, m_currentEntry->metaData);
4546 void MultiGetJob::slotFinished()
4548 if (!findCurrentEntry())
return;
4549 if (m_redirectionURL.isEmpty())
4552 emit
result(m_currentEntry->id);
4554 m_redirectionURL = KURL();
4556 m_incomingMetaData.clear();
4557 m_activeQueue.removeRef(m_currentEntry);
4558 if (m_activeQueue.count() == 0)
4560 if (m_waitQueue.count() == 0)
4563 TransferJob::slotFinished();
4570 GetRequest *entry = m_waitQueue.at(0);
4578 void MultiGetJob::slotData(
const TQByteArray &_data)
4580 if(!m_currentEntry)
return;
4581 if(m_redirectionURL.isEmpty() || !m_redirectionURL.isValid() || m_error)
4582 emit
data(m_currentEntry->id, _data);
4585 void MultiGetJob::slotMimetype(
const TQString &_mimetype )
4587 if (b_multiGetActive)
4589 TQPtrList<GetRequest> newQueue;
4590 flushQueue(newQueue);
4591 if (!newQueue.isEmpty())
4593 while(!newQueue.isEmpty())
4594 m_activeQueue.append(newQueue.take(0));
4595 m_slave->
send( m_command, m_packedArgs );
4598 if (!findCurrentEntry())
return;
4599 emit
mimetype(m_currentEntry->id, _mimetype);
4605 job->
get(
id, url, metaData);
4611 CacheInfo::CacheInfo(
const KURL &url)
4616 TQString CacheInfo::cachedFileName()
4618 const TQChar separator =
'_';
4620 TQString CEF = m_url.path();
4622 int p = CEF.find(
'/');
4627 p = CEF.find(
'/', p);
4630 TQString host = m_url.host().lower();
4631 CEF = host + CEF +
'_';
4634 if (dir[dir.length()-1] !=
'/')
4637 int l = m_url.host().length();
4638 for(
int i = 0; i < l; i++)
4640 if (host[i].isLetter() && (host[i] !=
'w'))
4646 if (dir[dir.length()-1] ==
'/')
4649 unsigned long hash = 0x00000000;
4650 TQCString u = m_url.url().latin1();
4651 for(
int i = u.length(); i--;)
4653 hash = (hash * 12211 + u[i]) % 2147483563;
4656 TQString hashString;
4657 hashString.sprintf(
"%08lx", hash);
4659 CEF = CEF + hashString;
4661 CEF = dir +
"/" + CEF;
4666 TQFile *CacheInfo::cachedFile()
4669 const char *mode = (readWrite ?
"rb+" :
"rb");
4671 const char *mode = (readWrite ?
"r+" :
"r");
4674 FILE *fs = fopen(TQFile::encodeName(CEF), mode);
4682 if (ok && (!fgets(buffer, 400, fs)))
4684 if (ok && (strcmp(buffer, CACHE_REVISION) != 0))
4688 time_t currentDate = time(0);
4691 if (ok && (!fgets(buffer, 400, fs)))
4695 int l = strlen(buffer);
4698 if (m_.url.url() != buffer)
4705 if (ok && (!fgets(buffer, 400, fs)))
4709 date = (time_t) strtoul(buffer, 0, 10);
4710 if (m_maxCacheAge && (difftime(currentDate, date) > m_maxCacheAge))
4712 m_bMustRevalidate =
true;
4713 m_expireDate = currentDate;
4718 m_cacheExpireDateOffset = ftell(fs);
4719 if (ok && (!fgets(buffer, 400, fs)))
4725 date = (time_t) strtoul(buffer, 0, 10);
4727 if (!date || difftime(currentDate, date) >= 0)
4728 m_bMustRevalidate =
true;
4729 m_expireDate = date;
4734 if (ok && (!fgets(buffer, 400, fs)))
4738 m_etag = TQString(buffer).stripWhiteSpace();
4742 if (ok && (!fgets(buffer, 400, fs)))
4746 m_lastModified = TQString(buffer).stripWhiteSpace();
4754 unlink( TQFile::encodeName(CEF) );
4759 void CacheInfo::flush()
4761 cachedFile().remove();
4764 void CacheInfo::touch()
4768 void CacheInfo::setExpireDate(
int);
4769 void CacheInfo::setExpireTimeout(
int);
4772 int CacheInfo::creationDate();
4773 int CacheInfo::expireDate();
4774 int CacheInfo::expireTimeout();
4777 void Job::virtual_hook(
int,
void* )
4780 void SimpleJob::virtual_hook(
int id,
void* data )
4781 { TDEIO::Job::virtual_hook(
id, data ); }
4783 void MkdirJob::virtual_hook(
int id,
void* data )
4784 { SimpleJob::virtual_hook(
id, data ); }
4786 void StatJob::virtual_hook(
int id,
void* data )
4787 { SimpleJob::virtual_hook(
id, data ); }
4789 void TransferJob::virtual_hook(
int id,
void* data )
4790 { SimpleJob::virtual_hook(
id, data ); }
4792 void MultiGetJob::virtual_hook(
int id,
void* data )
4793 { TransferJob::virtual_hook(
id, data ); }
4795 void MimetypeJob::virtual_hook(
int id,
void* data )
4796 { TransferJob::virtual_hook(
id, data ); }
4798 void FileCopyJob::virtual_hook(
int id,
void* data )
4799 { Job::virtual_hook(
id, data ); }
4801 void ListJob::virtual_hook(
int id,
void* data )
4802 { SimpleJob::virtual_hook(
id, data ); }
4804 void CopyJob::virtual_hook(
int id,
void* data )
4805 { Job::virtual_hook(
id, data ); }
4807 void DeleteJob::virtual_hook(
int id,
void* data )
4808 { Job::virtual_hook(
id, data ); }
4810 void LocalURLJob::virtual_hook(
int id,
void* data )
4811 { Job::virtual_hook(
id, data ); }
4814 #include "jobclasses.moc"