TDE core libraries
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.

jobclasses.h 62KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909
  1. // -*- c++ -*-
  2. /* This file is part of the KDE libraries
  3. Copyright (C) 2000 Stephan Kulow <coolo@kde.org>
  4. David Faure <faure@kde.org>
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  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. #ifndef __tdeio_jobclasses_h__
  19. #define __tdeio_jobclasses_h__
  20. #include <tqobject.h>
  21. #include <tqptrlist.h>
  22. #include <tqstring.h>
  23. #include <tqstringlist.h>
  24. #include <tqguardedptr.h>
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <kurl.h>
  28. #include <tdeio/global.h>
  29. class Observer;
  30. class TQTimer;
  31. #define KIO_COPYJOB_HAS_SETINTERACTIVE // new in 3.4. Used by tdeio_trash.
  32. namespace TDEIO {
  33. class Slave;
  34. class SlaveInterface;
  35. /**
  36. * The base class for all jobs.
  37. * For all jobs created in an application, the code looks like
  38. *
  39. * \code
  40. * TDEIO::Job * job = TDEIO::someoperation( some parameters );
  41. * connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ),
  42. * this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
  43. * \endcode
  44. * (other connects, specific to the job)
  45. *
  46. * And slotResult is usually at least:
  47. *
  48. * \code
  49. * if ( job->error() )
  50. * job->showErrorDialog( this or 0L );
  51. * \endcode
  52. * @see TDEIO::Scheduler
  53. * @see TDEIO::Slave
  54. */
  55. class TDEIO_EXPORT Job : public TQObject {
  56. Q_OBJECT
  57. protected:
  58. Job( bool showProgressInfo );
  59. public:
  60. virtual ~Job();
  61. /**
  62. * Abort this job.
  63. * This kills all subjobs and deletes the job.
  64. *
  65. * @param quietly if false, Job will emit signal result
  66. * and ask tdeio_uiserver to close the progress window.
  67. * @p quietly is set to true for subjobs. Whether applications
  68. * should call with true or false depends on whether they rely
  69. * on result being emitted or not.
  70. */
  71. virtual void kill( bool quietly = true );
  72. /**
  73. * Returns the error code, if there has been an error.
  74. * Only call this method from the slot connected to result().
  75. * @return the error code for this job, 0 if no error.
  76. * Error codes are defined in TDEIO::Error.
  77. */
  78. int error() const { return m_error; }
  79. /**
  80. * Returns the progress id for this job.
  81. * @return the progress id for this job, as returned by uiserver
  82. */
  83. int progressId() const { return m_progressId; }
  84. /**
  85. * Returns the error text if there has been an error.
  86. * Only call if error is not 0.
  87. * This is really internal, better use errorString() or errorDialog().
  88. *
  89. * @return a string to help understand the error, usually the url
  90. * related to the error. Only valid if error() is not 0.
  91. */
  92. const TQString & errorText() const { return m_errorText; }
  93. /**
  94. * Converts an error code and a non-i18n error message into an
  95. * error message in the current language. The low level (non-i18n)
  96. * error message (usually a url) is put into the translated error
  97. * message using %1.
  98. *
  99. * Example for errid == ERR_CANNOT_OPEN_FOR_READING:
  100. * \code
  101. * i18n( "Could not read\n%1" ).arg( errortext );
  102. * \endcode
  103. * Use this to display the error yourself, but for a dialog box
  104. * use Job::showErrorDialog. Do not call it if error()
  105. * is not 0.
  106. * @return the error message and if there is no error, a message
  107. * telling the user that the app is broken, so check with
  108. * error() whether there is an error
  109. */
  110. TQString errorString() const;
  111. /**
  112. * Converts an error code and a non-i18n error message into i18n
  113. * strings suitable for presentation in a detailed error message box.
  114. *
  115. * @param reqUrl the request URL that generated this error message
  116. * @param method the method that generated this error message
  117. * (unimplemented)
  118. * @return the following strings: caption, error + description,
  119. * causes+solutions
  120. */
  121. TQStringList detailedErrorStrings(const KURL *reqUrl = 0L,
  122. int method = -1) const;
  123. /**
  124. * Display a dialog box to inform the user of the error given by
  125. * this job.
  126. * Only call if error is not 0, and only in the slot connected
  127. * to result.
  128. * @param parent the parent widget for the dialog box, can be 0 for
  129. * top-level
  130. */
  131. void showErrorDialog( TQWidget * parent = 0L );
  132. /**
  133. * Enable or disable the automatic error handling. When automatic
  134. * error handling is enabled and an error occurs, then showErrorDialog()
  135. * is called with the specified @p parentWidget (if supplied) , right before
  136. * the emission of the result signal.
  137. *
  138. * The default is false.
  139. *
  140. * @param enable enable or disable automatic error handling
  141. * @param parentWidget the parent widget, passed to showErrorDialog.
  142. * Can be 0 for top-level
  143. * @see isAutoErrorHandlingEnabled(), showErrorDialog()
  144. */
  145. void setAutoErrorHandlingEnabled( bool enable, TQWidget *parentWidget = 0 );
  146. /**
  147. * Returns whether automatic error handling is enabled or disabled.
  148. * @return true if automatic error handling is enabled
  149. * @see setAutoErrorHandlingEnabled()
  150. */
  151. bool isAutoErrorHandlingEnabled() const;
  152. /**
  153. * Enable or disable the automatic warning handling. When automatic
  154. * warning handling is enabled and an error occurs, then a message box
  155. * is displayed with the warning message
  156. *
  157. * The default is true.
  158. *
  159. * See also isAutoWarningHandlingEnabled , showErrorDialog
  160. *
  161. * @param enable enable or disable automatic warning handling
  162. * @see isAutoWarningHandlingEnabled()
  163. * @since 3.5
  164. */
  165. void setAutoWarningHandlingEnabled( bool enable );
  166. /**
  167. * Returns whether automatic warning handling is enabled or disabled.
  168. * See also setAutoWarningHandlingEnabled .
  169. * @return true if automatic warning handling is enabled
  170. * @see setAutoWarningHandlingEnabled()
  171. * @since 3.5
  172. */
  173. bool isAutoWarningHandlingEnabled() const;
  174. /**
  175. * Enable or disable the message display from the job.
  176. *
  177. * The default is true.
  178. * @param enable enable or disable message display
  179. * @since 3.4.1
  180. */
  181. void setInteractive(bool enable);
  182. /**
  183. * Returns whether message display is enabled or disabled.
  184. * @return true if message display is enabled
  185. * @see setInteractive()
  186. * @since 3.4.1
  187. */
  188. bool isInteractive() const;
  189. /**
  190. * Associate this job with a window given by @p window.
  191. * @param window the window to associate to
  192. * @see window()
  193. */
  194. void setWindow(TQWidget *window);
  195. /**
  196. * Returns the window this job is associated with.
  197. * @return the associated window
  198. * @see setWindow()
  199. */
  200. TQWidget *window() const;
  201. /**
  202. * Updates the last user action timestamp to the given time.
  203. * See TDEApplication::updateUserTimestamp() .
  204. * @since 3.5.6
  205. */
  206. void updateUserTimestamp( unsigned long time );
  207. /**
  208. * Set the parent Job.
  209. * One example use of this is when FileCopyJob calls open_RenameDlg,
  210. * it must pass the correct progress ID of the parent CopyJob
  211. * (to hide the progress dialog).
  212. * You can set the parent job only once. By default a job does not
  213. * have a parent job.
  214. * @param parentJob the new parent job
  215. * @since 3.1
  216. */
  217. void setParentJob( Job* parentJob );
  218. /**
  219. * Returns the parent job, if there is one.
  220. * @return the parent job, or 0 if there is none
  221. * @see setParentJob
  222. * @since 3.1
  223. */
  224. Job* parentJob() const;
  225. /**
  226. * Set meta data to be sent to the slave, replacing existing
  227. * meta data.
  228. * @param metaData the meta data to set
  229. * @see addMetaData()
  230. * @see mergeMetaData()
  231. */
  232. void setMetaData( const TDEIO::MetaData &metaData);
  233. /**
  234. * Add key/value pair to the meta data that is sent to the slave.
  235. * @param key the key of the meta data
  236. * @param value the value of the meta data
  237. * @see setMetaData()
  238. * @see mergeMetaData()
  239. */
  240. void addMetaData(const TQString &key, const TQString &value);
  241. /**
  242. * Add key/value pairs to the meta data that is sent to the slave.
  243. * If a certain key already existed, it will be overridden.
  244. * @param values the meta data to add
  245. * @see setMetaData()
  246. * @see mergeMetaData()
  247. */
  248. void addMetaData(const TQMap<TQString,TQString> &values);
  249. /**
  250. * Add key/value pairs to the meta data that is sent to the slave.
  251. * If a certain key already existed, it will remain unchanged.
  252. * @param values the meta data to merge
  253. * @see setMetaData()
  254. * @see addMetaData()
  255. */
  256. void mergeMetaData(const TQMap<TQString,TQString> &values);
  257. /**
  258. * @internal. For the scheduler. Do not use.
  259. */
  260. MetaData outgoingMetaData() const;
  261. /**
  262. * Get meta data received from the slave.
  263. * (Valid when first data is received and/or slave is finished)
  264. * @return the job's meta data
  265. */
  266. MetaData metaData() const;
  267. /**
  268. * Query meta data received from the slave.
  269. * (Valid when first data is received and/or slave is finished)
  270. * @param key the key of the meta data to retrieve
  271. * @return the value of the meta data, or TQString::null if the
  272. * @p key does not exist
  273. */
  274. TQString queryMetaData(const TQString &key);
  275. /**
  276. * Returns the processed size for this job.
  277. * @see processedSize
  278. * @since 3.2
  279. */
  280. TDEIO::filesize_t getProcessedSize();
  281. signals:
  282. /**
  283. * Emitted when the job is finished, in any case (completed, canceled,
  284. * failed...). Use error to know the result.
  285. * @param job the job that emitted this signal
  286. */
  287. void result( TDEIO::Job *job );
  288. /**
  289. * @deprecated. Don't use !
  290. * Emitted when the job is canceled.
  291. * Signal result() is emitted as well, and error() is,
  292. * in this case, ERR_USER_CANCELED.
  293. * @param job the job that emitted this signal
  294. */
  295. void canceled( TDEIO::Job *job );
  296. /**
  297. * Emitted to display information about this job, as sent by the slave.
  298. * Examples of message are "Resolving host", "Connecting to host...", etc.
  299. * @param job the job that emitted this signal
  300. * @param msg the info message
  301. */
  302. void infoMessage( TDEIO::Job *job, const TQString & msg );
  303. // KDE4: Separate rich-text string from plain-text string, for different widgets.
  304. /**
  305. * Emitted to display a warning about this job, as sent by the slave.
  306. * @param job the job that emitted this signal
  307. * @param msg the info message
  308. * @since 3.5
  309. */
  310. void warning( TDEIO::Job *job, const TQString & msg );
  311. // KDE4: Separate rich-text string from plain-text string, for different widgets.
  312. /**
  313. * Emitted when the slave successfully connected to the host.
  314. * There is no guarantee the slave will send this, and this is
  315. * currently unused (in the applications).
  316. * @param job the job that emitted this signal
  317. */
  318. void connected( TDEIO::Job *job );
  319. /**
  320. * Progress signal showing the overall progress of the job
  321. * This is valid for any kind of job, and allows using a
  322. * a progress bar very easily. (see KProgress).
  323. * Note that this signal is not emitted for finished jobs.
  324. * @param job the job that emitted this signal
  325. * @param percent the percentage
  326. */
  327. void percent( TDEIO::Job *job, unsigned long percent );
  328. /**
  329. * Emitted when we know the size of this job (data size for transfers,
  330. * number of entries for listings).
  331. * @param job the job that emitted this signal
  332. * @param size the total size in bytes
  333. */
  334. void totalSize( TDEIO::Job *job, TDEIO::filesize_t size );
  335. /**
  336. * Regularly emitted to show the progress of this job
  337. * (current data size for transfers, entries listed).
  338. * @param job the job that emitted this signal
  339. * @param size the processed size in bytes
  340. */
  341. void processedSize( TDEIO::Job *job, TDEIO::filesize_t size );
  342. /**
  343. * Emitted to display information about the speed of this job.
  344. * @param job the job that emitted this signal
  345. * @param speed the speed in bytes/s
  346. */
  347. void speed( TDEIO::Job *job, unsigned long speed );
  348. protected slots:
  349. /**
  350. * Called whenever a subjob finishes.
  351. * Default implementation checks for errors and propagates
  352. * to parent job, then calls removeSubjob.
  353. * Override if you don't want subjobs errors to be propagated.
  354. * @param job the subjob
  355. * @see result()
  356. */
  357. virtual void slotResult( TDEIO::Job *job );
  358. /**
  359. * Forward signal from subjob.
  360. * @param job the subjob
  361. * @param speed the speed in bytes/s
  362. * @see speed()
  363. */
  364. void slotSpeed( TDEIO::Job *job, unsigned long speed );
  365. /**
  366. * Forward signal from subjob.
  367. * @param job the subjob
  368. * @param msg the info message
  369. * @see infoMessage()
  370. */
  371. void slotInfoMessage( TDEIO::Job *job, const TQString &msg );
  372. /**
  373. * Remove speed information.
  374. */
  375. void slotSpeedTimeout();
  376. protected:
  377. /**
  378. * Add a job that has to be finished before a result
  379. * is emitted. This has obviously to be called before
  380. * the finish signal is emitted by the slave.
  381. *
  382. * @param job the subjob to add
  383. * @param inheritMetaData if true, the subjob will
  384. * inherit the meta data from this job.
  385. */
  386. virtual void addSubjob( Job *job, bool inheritMetaData=true );
  387. /**
  388. * Mark a sub job as being done. If it's the last to
  389. * wait on the job will emit a result - jobs with
  390. * two steps might want to override slotResult
  391. * in order to avoid calling this method.
  392. *
  393. * @param job the subjob to add
  394. */
  395. virtual void removeSubjob( Job *job );
  396. /**
  397. * Overloaded version of removeSubjob
  398. * @param job the subjob to remove
  399. * @param mergeMetaData if set, the metadata received by the subjob is
  400. * merged into this job.
  401. * @param emitResultIfLast if this was the last subjob, emit result,
  402. * i.e. terminate this job.
  403. */
  404. void removeSubjob( Job *job, bool mergeMetaData, bool emitResultIfLast ); // KDE4: merge with above, with =true to both
  405. /**
  406. * Utility function for inherited jobs.
  407. * Emits the percent signal if bigger than m_percent,
  408. * after calculating it from the parameters.
  409. *
  410. * @param processedSize the processed size in bytes
  411. * @param totalSize the total size in bytes
  412. */
  413. void emitPercent( TDEIO::filesize_t processedSize, TDEIO::filesize_t totalSize );
  414. /**
  415. * Utility function for inherited jobs.
  416. * Emits the speed signal and starts the timer for removing that info
  417. *
  418. * @param speed the speed in bytes/s
  419. */
  420. void emitSpeed( unsigned long speed );
  421. /**
  422. * Utility function to emit the result signal, and suicide this job.
  423. * It first tells the observer to hide the progress dialog for this job.
  424. */
  425. void emitResult();
  426. /**
  427. * Set the processed size, does not emit processedSize
  428. * @since 3.2
  429. */
  430. void setProcessedSize(TDEIO::filesize_t size);
  431. /**
  432. * @internal
  433. */
  434. unsigned long userTimestamp() const;
  435. /**
  436. * @internal
  437. * Some extra storage space for jobs that don't have their own
  438. * private d pointer.
  439. */
  440. enum { EF_TransferJobAsync = (1 << 0),
  441. EF_TransferJobNeedData = (1 << 1),
  442. EF_TransferJobDataSent = (1 << 2),
  443. EF_ListJobUnrestricted = (1 << 3) };
  444. int &extraFlags();
  445. TQPtrList<Job> subjobs;
  446. int m_error;
  447. TQString m_errorText;
  448. unsigned long m_percent;
  449. int m_progressId; // for uiserver
  450. TQTimer *m_speedTimer;
  451. TQGuardedPtr<TQWidget> m_window;
  452. MetaData m_outgoingMetaData;
  453. MetaData m_incomingMetaData;
  454. protected:
  455. virtual void virtual_hook( int id, void* data );
  456. private:
  457. class JobPrivate;
  458. JobPrivate *d;
  459. };
  460. /**
  461. * A simple job (one url and one command).
  462. * This is the base class for all jobs that are scheduled.
  463. * Other jobs are high-level jobs (CopyJob, DeleteJob, FileCopyJob...)
  464. * that manage subjobs but aren't scheduled directly.
  465. */
  466. class TDEIO_EXPORT SimpleJob : public TDEIO::Job {
  467. Q_OBJECT
  468. public:
  469. /**
  470. * Creates a new simple job. You don't need to use this constructor,
  471. * unless you create a new job that inherits from SimpleJob.
  472. * @param url the url of the job
  473. * @param command the command of the job
  474. * @param packedArgs the arguments
  475. * @param showProgressInfo true to show progress information to the user
  476. */
  477. SimpleJob(const KURL& url, int command, const TQByteArray &packedArgs,
  478. bool showProgressInfo);
  479. ~SimpleJob();
  480. /**
  481. * Returns the SimpleJob's URL
  482. * @return the url
  483. */
  484. const KURL& url() const { return m_url; }
  485. /**
  486. * Abort job.
  487. * This kills all subjobs and deletes the job.
  488. * @param quietly if true, Job will emit signal result
  489. * Should only be set to false when the user kills the job
  490. * (from tdeio_uiserver), not when you want to abort a job.
  491. */
  492. virtual void kill( bool quietly = true );
  493. /**
  494. * Abort job.
  495. * Suspends slave to be reused by another job for the same request.
  496. */
  497. virtual void putOnHold();
  498. /**
  499. * Discard suspended slave.
  500. */
  501. static void removeOnHold();
  502. /**
  503. * @internal
  504. * Called by the scheduler when a slave gets to
  505. * work on this job.
  506. **/
  507. virtual void start( Slave *slave );
  508. /**
  509. * @internal
  510. * Called to detach a slave from a job.
  511. **/
  512. void slaveDone();
  513. /**
  514. * @internal
  515. * Slave in use by this job.
  516. */
  517. Slave *slave() const { return m_slave; }
  518. /**
  519. * @internal
  520. */
  521. int command() const { return m_command; }
  522. public slots:
  523. /**
  524. * Forward signal from the slave
  525. * Can also be called by the parent job, when it knows the size.
  526. * @param data_size the total size
  527. */
  528. void slotTotalSize( TDEIO::filesize_t data_size );
  529. protected slots:
  530. /**
  531. * Called when the slave marks the job
  532. * as finished.
  533. */
  534. virtual void slotFinished( );
  535. /**
  536. * @internal
  537. * Called on a slave's warning.
  538. */
  539. void slotWarning( const TQString & ); // KDE4: make virtual
  540. /**
  541. * Called on a slave's info message.
  542. * @param s the info message
  543. * @see infoMessage()
  544. */
  545. void slotInfoMessage( const TQString &s ); // KDE4: make virtual
  546. /**
  547. * Called on a slave's connected signal.
  548. * @see connected()
  549. */
  550. void slotConnected();
  551. /**
  552. * Forward signal from the slave.
  553. * @param data_size the processed size in bytes
  554. * @see processedSize()
  555. */
  556. void slotProcessedSize( TDEIO::filesize_t data_size );
  557. /**
  558. * Forward signal from the slave.
  559. * @param speed the speed in bytes/s
  560. * @see speed()
  561. */
  562. void slotSpeed( unsigned long speed );
  563. /**
  564. * MetaData from the slave is received.
  565. * @param _metaData the meta data
  566. * @see metaData()
  567. */
  568. virtual void slotMetaData( const TDEIO::MetaData &_metaData);
  569. public slots:
  570. /**
  571. * @internal
  572. * Called on a slave's error.
  573. * Made public for the scheduler.
  574. */
  575. virtual void slotError( int , const TQString & );
  576. protected slots:
  577. /**
  578. * @internal
  579. */
  580. void slotNeedProgressId();
  581. protected:
  582. Slave * m_slave;
  583. TQByteArray m_packedArgs;
  584. KURL m_url;
  585. KURL m_subUrl;
  586. int m_command;
  587. TDEIO::filesize_t m_totalSize;
  588. protected:
  589. virtual void virtual_hook( int id, void* data );
  590. /*
  591. * Allow jobs that inherit SimpleJob and are aware
  592. * of redirections to store the SSL session used.
  593. * Retrieval is handled by SimpleJob::start
  594. * @param m_redirectionURL Reference to redirection URL,
  595. * used instead of m_url if not empty
  596. */
  597. void storeSSLSessionFromJob(const KURL &m_redirectionURL);
  598. private:
  599. class SimpleJobPrivate* d;
  600. };
  601. /**
  602. * A KIO job that retrieves information about a file or directory.
  603. * @see TDEIO::stat()
  604. */
  605. class TDEIO_EXPORT StatJob : public SimpleJob {
  606. Q_OBJECT
  607. public:
  608. /**
  609. * Do not use this constructor to create a StatJob, use TDEIO::stat() instead.
  610. * @param url the url of the file or directory to check
  611. * @param command the command to issue
  612. * @param packedArgs the arguments
  613. * @param showProgressInfo true to show progress information to the user
  614. */
  615. StatJob(const KURL& url, int command, const TQByteArray &packedArgs, bool showProgressInfo);
  616. /**
  617. * A stat() can have two meanings. Either we want to read from this URL,
  618. * or to check if we can write to it. First case is "source", second is "dest".
  619. * It is necessary to know what the StatJob is for, to tune the tdeioslave's behavior
  620. * (e.g. with FTP).
  621. * @param source true for "source" mode, false for "dest" mode
  622. */
  623. void setSide( bool source ) { m_bSource = source; }
  624. /**
  625. * Selects the level of @p details we want.
  626. * By default this is 2 (all details wanted, including modification time, size, etc.),
  627. * setDetails(1) is used when deleting: we don't need all the information if it takes
  628. * too much time, no need to follow symlinks etc.
  629. * setDetails(0) is used for very simple probing: we'll only get the answer
  630. * "it's a file or a directory, or it doesn't exist". This is used by KRun.
  631. * @param details 2 for all details, 1 for simple, 0 for very simple
  632. */
  633. void setDetails( short int details ) { m_details = details; }
  634. /**
  635. * Call this in the slot connected to result,
  636. * and only after making sure no error happened.
  637. * @return the result of the stat
  638. */
  639. const UDSEntry & statResult() const { return m_statResult; }
  640. /**
  641. * @internal
  642. * Called by the scheduler when a @p slave gets to
  643. * work on this job.
  644. * @param slave the slave that starts working on this job
  645. */
  646. virtual void start( Slave *slave );
  647. signals:
  648. /**
  649. * Signals a redirection.
  650. * Use to update the URL shown to the user.
  651. * The redirection itself is handled internally.
  652. * @param job the job that is redirected
  653. * @param url the new url
  654. */
  655. void redirection( TDEIO::Job *job, const KURL &url );
  656. /**
  657. * Signals a permanent redirection.
  658. * The redirection itself is handled internally.
  659. * @param job the job that is redirected
  660. * @param fromUrl the original URL
  661. * @param toUrl the new URL
  662. * @since 3.1
  663. */
  664. void permanentRedirection( TDEIO::Job *job, const KURL &fromUrl, const KURL &toUrl );
  665. protected slots:
  666. void slotStatEntry( const TDEIO::UDSEntry & entry );
  667. void slotRedirection( const KURL &url);
  668. virtual void slotFinished();
  669. virtual void slotMetaData( const TDEIO::MetaData &_metaData);
  670. protected:
  671. UDSEntry m_statResult;
  672. KURL m_redirectionURL;
  673. bool m_bSource;
  674. short int m_details;
  675. protected:
  676. virtual void virtual_hook( int id, void* data );
  677. private:
  678. class StatJobPrivate;
  679. StatJobPrivate *d;
  680. };
  681. /**
  682. * A KIO job that creates a directory
  683. * @see TDEIO::mkdir()
  684. * @since 3.3
  685. */
  686. class TDEIO_EXPORT MkdirJob : public SimpleJob {
  687. Q_OBJECT
  688. public:
  689. /**
  690. * Do not use this constructor to create a MkdirJob, use TDEIO::mkdir() instead.
  691. * @param url the url of the file or directory to check
  692. * @param command the command to issue
  693. * @param packedArgs the arguments
  694. * @param showProgressInfo true to show progress information to the user
  695. */
  696. MkdirJob(const KURL& url, int command, const TQByteArray &packedArgs, bool showProgressInfo);
  697. /**
  698. * @internal
  699. * Called by the scheduler when a @p slave gets to
  700. * work on this job.
  701. * @param slave the slave that starts working on this job
  702. */
  703. virtual void start( Slave *slave );
  704. signals:
  705. /**
  706. * Signals a redirection.
  707. * Use to update the URL shown to the user.
  708. * The redirection itself is handled internally.
  709. * @param job the job that is redirected
  710. * @param url the new url
  711. */
  712. void redirection( TDEIO::Job *job, const KURL &url );
  713. /**
  714. * Signals a permanent redirection.
  715. * The redirection itself is handled internally.
  716. * @param job the job that is redirected
  717. * @param fromUrl the original URL
  718. * @param toUrl the new URL
  719. */
  720. void permanentRedirection( TDEIO::Job *job, const KURL &fromUrl, const KURL &toUrl );
  721. protected slots:
  722. void slotRedirection( const KURL &url);
  723. virtual void slotFinished();
  724. protected:
  725. KURL m_redirectionURL;
  726. protected:
  727. virtual void virtual_hook( int id, void* data );
  728. private:
  729. class MkdirJobPrivate;
  730. MkdirJobPrivate *d;
  731. };
  732. /**
  733. * @internal
  734. * Used for direct copy from or to the local filesystem (i.e. SlaveBase::copy())
  735. */
  736. class TDEIO_EXPORT DirectCopyJob : public SimpleJob {
  737. Q_OBJECT
  738. public:
  739. /**
  740. * Do not create a DirectCopyJob. Use TDEIO::copy() or TDEIO::file_copy() instead.
  741. */
  742. DirectCopyJob(const KURL& url, int command, const TQByteArray &packedArgs,
  743. bool showProgressInfo);
  744. /**
  745. * @internal
  746. * Called by the scheduler when a @p slave gets to
  747. * work on this job.
  748. * @param slave the slave that starts working on this job
  749. */
  750. virtual void start(Slave *slave);
  751. signals:
  752. /**
  753. * @internal
  754. * Emitted if the job found an existing partial file
  755. * and supports resuming. Used by FileCopyJob.
  756. */
  757. void canResume( TDEIO::Job *job, TDEIO::filesize_t offset );
  758. private slots:
  759. void slotCanResume( TDEIO::filesize_t offset );
  760. };
  761. /**
  762. * The transfer job pumps data into and/or out of a Slave.
  763. * Data is sent to the slave on request of the slave ( dataReq).
  764. * If data coming from the slave can not be handled, the
  765. * reading of data from the slave should be suspended.
  766. */
  767. class TDEIO_EXPORT TransferJob : public SimpleJob {
  768. Q_OBJECT
  769. public:
  770. /**
  771. * Do not create a TransferJob. Use TDEIO::get() or TDEIO::put()
  772. * instead.
  773. * @param url the url to get or put
  774. * @param command the command to issue
  775. * @param packedArgs the arguments
  776. * @param _staticData additional data to transmit (e.g. in a HTTP Post)
  777. * @param showProgressInfo true to show progress information to the user
  778. */
  779. TransferJob(const KURL& url, int command,
  780. const TQByteArray &packedArgs,
  781. const TQByteArray &_staticData,
  782. bool showProgressInfo);
  783. /**
  784. * @internal
  785. * Called by the scheduler when a @p slave gets to
  786. * work on this job.
  787. * @param slave the slave that starts working on this job
  788. */
  789. virtual void start(Slave *slave);
  790. /**
  791. * Called when m_subJob finishes.
  792. * @param job the job that finished
  793. */
  794. virtual void slotResult( TDEIO::Job *job );
  795. /**
  796. * Flow control. Suspend data processing from the slave.
  797. */
  798. void suspend();
  799. /**
  800. * Flow control. Resume data processing from the slave.
  801. */
  802. void resume();
  803. /**
  804. * Flow control.
  805. * @return true if the job is suspended
  806. */
  807. bool isSuspended() const { return m_suspended; }
  808. /**
  809. * Checks whether we got an error page. This currently only happens
  810. * with HTTP urls. Call this from your slot connected to result().
  811. *
  812. * @return true if we got an (HTML) error page from the server
  813. * instead of what we asked for.
  814. */
  815. bool isErrorPage() const { return m_errorPage; }
  816. /**
  817. * Enable the async data mode.
  818. * When async data is enabled, data should be provided to the job by
  819. * calling sendAsyncData() instead of returning data in the
  820. * dataReq() signal.
  821. * @since 3.2
  822. */
  823. void setAsyncDataEnabled(bool enabled);
  824. /**
  825. * Provide data to the job when async data is enabled.
  826. * Should be called exactly once after receiving a dataReq signal
  827. * Sending an empty block indicates end of data.
  828. * @since 3.2
  829. */
  830. void sendAsyncData(const TQByteArray &data);
  831. /**
  832. * When enabled, the job reports the amount of data that has been sent,
  833. * instead of the amount of data that that has been received.
  834. * @see slotProcessedSize
  835. * @see slotSpeed
  836. * @since 3.2
  837. */
  838. void setReportDataSent(bool enabled);
  839. /**
  840. * Returns whether the job reports the amount of data that has been
  841. * sent (true), or whether the job reports the amount of data that
  842. * has been received (false)
  843. * @since 3.2
  844. */
  845. bool reportDataSent();
  846. signals:
  847. /**
  848. * Data from the slave has arrived.
  849. * @param job the job that emitted this signal
  850. * @param data data received from the slave.
  851. *
  852. * End of data (EOD) has been reached if data.size() == 0, however, you
  853. * should not be certain of data.size() == 0 ever happening (e.g. in case
  854. * of an error), so you should rely on result() instead.
  855. */
  856. void data( TDEIO::Job *job, const TQByteArray &data );
  857. /**
  858. * Request for data.
  859. * Please note, that you shouldn't put too large chunks
  860. * of data in it as this requires copies within the frame
  861. * work, so you should rather split the data you want
  862. * to pass here in reasonable chunks (about 1MB maximum)
  863. *
  864. * @param job the job that emitted this signal
  865. * @param data buffer to fill with data to send to the
  866. * slave. An empty buffer indicates end of data. (EOD)
  867. */
  868. void dataReq( TDEIO::Job *job, TQByteArray &data );
  869. /**
  870. * Signals a redirection.
  871. * Use to update the URL shown to the user.
  872. * The redirection itself is handled internally.
  873. * @param job the job that emitted this signal
  874. * @param url the new URL
  875. */
  876. void redirection( TDEIO::Job *job, const KURL &url );
  877. /**
  878. * Signals a permanent redirection.
  879. * The redirection itself is handled internally.
  880. * @param job the job that emitted this signal
  881. * @param fromUrl the original URL
  882. * @param toUrl the new URL
  883. * @since 3.1
  884. */
  885. void permanentRedirection( TDEIO::Job *job, const KURL &fromUrl, const KURL &toUrl );
  886. /**
  887. * Mimetype determined.
  888. * @param job the job that emitted this signal
  889. * @param type the mime type
  890. */
  891. void mimetype( TDEIO::Job *job, const TQString &type );
  892. /**
  893. * @internal
  894. * Emitted if the "put" job found an existing partial file
  895. * (in which case offset is the size of that file)
  896. * and emitted by the "get" job if it supports resuming to
  897. * the given offset - in this case @p offset is unused)
  898. */
  899. void canResume( TDEIO::Job *job, TDEIO::filesize_t offset );
  900. protected slots:
  901. virtual void slotRedirection( const KURL &url);
  902. virtual void slotFinished();
  903. virtual void slotData( const TQByteArray &data);
  904. virtual void slotDataReq();
  905. virtual void slotMimetype( const TQString &mimetype );
  906. virtual void slotNeedSubURLData();
  907. virtual void slotSubURLData(TDEIO::Job*, const TQByteArray &);
  908. virtual void slotMetaData( const TDEIO::MetaData &_metaData);
  909. void slotErrorPage();
  910. void slotCanResume( TDEIO::filesize_t offset );
  911. void slotPostRedirection();
  912. protected:
  913. bool m_suspended;
  914. bool m_errorPage;
  915. TQByteArray staticData;
  916. KURL m_redirectionURL;
  917. KURL::List m_redirectionList;
  918. TQString m_mimetype;
  919. TransferJob *m_subJob;
  920. protected:
  921. virtual void virtual_hook( int id, void* data );
  922. private:
  923. class TransferJobPrivate *d;
  924. };
  925. /**
  926. * StoredTransferJob is a TransferJob (for downloading or uploading data) that
  927. * also stores a TQByteArray with the data, making it simpler to use than the
  928. * standard TransferJob.
  929. *
  930. * For TDEIO::storedGet it puts the data into the member TQByteArray, so the user
  931. * of this class can get hold of the whole data at once by calling data()
  932. * when the result signal is emitted.
  933. * You should only use StoredTransferJob to download data if you cannot
  934. * process the data by chunks while it's being downloaded, since storing
  935. * everything in a TQByteArray can potentially require a lot of memory.
  936. *
  937. * For TDEIO::storedPut the user of this class simply provides the bytearray from
  938. * the start, and the job takes care of uploading it.
  939. * You should only use StoredTransferJob to upload data if you cannot
  940. * provide the in chunks while it's being uploaded, since storing
  941. * everything in a TQByteArray can potentially require a lot of memory.
  942. *
  943. * @since 3.3
  944. */
  945. class TDEIO_EXPORT StoredTransferJob : public TDEIO::TransferJob {
  946. Q_OBJECT
  947. public:
  948. /**
  949. * Do not create a StoredTransferJob. Use storedGet() or storedPut()
  950. * instead.
  951. * @param url the url to get or put
  952. * @param command the command to issue
  953. * @param packedArgs the arguments
  954. * @param _staticData additional data to transmit (e.g. in a HTTP Post)
  955. * @param showProgressInfo true to show progress information to the user
  956. */
  957. StoredTransferJob(const KURL& url, int command,
  958. const TQByteArray &packedArgs,
  959. const TQByteArray &_staticData,
  960. bool showProgressInfo);
  961. /**
  962. * Set data to be uploaded. This is for put jobs.
  963. * Automatically called by TDEIO::storedPut(const TQByteArray &, ...),
  964. * do not call this yourself.
  965. */
  966. void setData( const TQByteArray& arr );
  967. /**
  968. * Get hold of the downloaded data. This is for get jobs.
  969. * You're supposed to call this only from the slot connected to the result() signal.
  970. */
  971. TQByteArray data() const { return m_data; }
  972. private slots:
  973. void slotStoredData( TDEIO::Job *job, const TQByteArray &data );
  974. void slotStoredDataReq( TDEIO::Job *job, TQByteArray &data );
  975. private:
  976. TQByteArray m_data;
  977. int m_uploadOffset;
  978. };
  979. /**
  980. * The MultiGetJob is a TransferJob that allows you to get
  981. * several files from a single server. Don't create directly,
  982. * but use TDEIO::multi_get() instead.
  983. * @see TDEIO::multi_get()
  984. */
  985. class TDEIO_EXPORT MultiGetJob : public TransferJob {
  986. Q_OBJECT
  987. public:
  988. /**
  989. * Do not create a MultiGetJob directly, use TDEIO::multi_get()
  990. * instead.
  991. *
  992. * @param url the first url to get
  993. * @param showProgressInfo true to show progress information to the user
  994. */
  995. MultiGetJob(const KURL& url, bool showProgressInfo);
  996. /**
  997. * @internal
  998. * Called by the scheduler when a @p slave gets to
  999. * work on this job.
  1000. * @param slave the slave that starts working on this job
  1001. */
  1002. virtual void start(Slave *slave);
  1003. /**
  1004. * Get an additional file.
  1005. *
  1006. * @param id the id of the file
  1007. * @param url the url of the file to get
  1008. * @param metaData the meta data for this request
  1009. */
  1010. void get(long id, const KURL &url, const MetaData &metaData);
  1011. signals:
  1012. /**
  1013. * Data from the slave has arrived.
  1014. * @param id the id of the request
  1015. * @param data data received from the slave.
  1016. * End of data (EOD) has been reached if data.size() == 0
  1017. */
  1018. void data( long id, const TQByteArray &data);
  1019. /**
  1020. * Mimetype determined
  1021. * @param id the id of the request
  1022. * @param type the mime type
  1023. */
  1024. void mimetype( long id, const TQString &type );
  1025. /**
  1026. * File transfer completed.
  1027. *
  1028. * When all files have been processed, result(TDEIO::Job *) gets
  1029. * emitted.
  1030. * @param id the id of the request
  1031. */
  1032. void result( long id);
  1033. protected slots:
  1034. virtual void slotRedirection( const KURL &url);
  1035. virtual void slotFinished();
  1036. virtual void slotData( const TQByteArray &data);
  1037. virtual void slotMimetype( const TQString &mimetype );
  1038. private:
  1039. struct GetRequest {
  1040. public:
  1041. GetRequest(long _id, const KURL &_url, const MetaData &_metaData)
  1042. : id(_id), url(_url), metaData(_metaData) { }
  1043. long id;
  1044. KURL url;
  1045. MetaData metaData;
  1046. };
  1047. bool findCurrentEntry();
  1048. void flushQueue(TQPtrList<GetRequest> &queue);
  1049. TQPtrList<GetRequest> m_waitQueue;
  1050. TQPtrList<GetRequest> m_activeQueue;
  1051. bool b_multiGetActive;
  1052. GetRequest *m_currentEntry;
  1053. protected:
  1054. virtual void virtual_hook( int id, void* data );
  1055. private:
  1056. class MultiGetJobPrivate* d;
  1057. };
  1058. /**
  1059. * A MimetypeJob is a TransferJob that allows you to get
  1060. * the mime type of an URL. Don't create directly,
  1061. * but use TDEIO::mimetype() instead.
  1062. * @see TDEIO::mimetype()
  1063. */
  1064. class TDEIO_EXPORT MimetypeJob : public TransferJob {
  1065. Q_OBJECT
  1066. public:
  1067. /**
  1068. * Do not create a MimetypeJob directly. Use TDEIO::mimetype()
  1069. * instead.
  1070. * @param url the url to get
  1071. * @param command the command to issue
  1072. * @param packedArgs the arguments
  1073. * @param showProgressInfo true to show progress information to the user
  1074. */
  1075. MimetypeJob(const KURL& url, int command, const TQByteArray &packedArgs, bool showProgressInfo);
  1076. /**
  1077. * Call this in the slot connected to result,
  1078. * and only after making sure no error happened.
  1079. * @return the mimetype of the URL
  1080. */
  1081. TQString mimetype() const { return m_mimetype; }
  1082. /**
  1083. * @internal
  1084. * Called by the scheduler when a slave gets to
  1085. * work on this job.
  1086. * @param slave the slave that works on the job
  1087. */
  1088. virtual void start( Slave *slave );
  1089. protected slots:
  1090. virtual void slotFinished( );
  1091. protected:
  1092. virtual void virtual_hook( int id, void* data );
  1093. private:
  1094. class MimetypeJobPrivate* d;
  1095. };
  1096. /**
  1097. * The FileCopyJob copies data from one place to another.
  1098. * @see TDEIO::file_copy()
  1099. * @see TDEIO::file_move()
  1100. */
  1101. class TDEIO_EXPORT FileCopyJob : public Job {
  1102. Q_OBJECT
  1103. public:
  1104. /**
  1105. * Do not create a FileCopyJob directly. Use TDEIO::file_move()
  1106. * or TDEIO::file_copy() instead.
  1107. * @param src the source URL
  1108. * @param dest the destination URL
  1109. * @param permissions the permissions of the resulting resource
  1110. * @param move true to move, false to copy
  1111. * @param overwrite true to allow overwriting, false otherwise
  1112. * @param resume true to resume an operation, false otherwise
  1113. * @param showProgressInfo true to show progress information to the user
  1114. */
  1115. FileCopyJob( const KURL& src, const KURL& dest, int permissions,
  1116. bool move, bool overwrite, bool resume, bool showProgressInfo);
  1117. ~FileCopyJob();
  1118. /**
  1119. * If you know the size of the source file, call this method
  1120. * to inform this job. It will be displayed in the "resume" dialog.
  1121. * @param size the size of the source file
  1122. * @since 3.2
  1123. */
  1124. void setSourceSize64(TDEIO::filesize_t size);
  1125. /**
  1126. * Sets the modification time of the file
  1127. *
  1128. * Note that this is ignored if a direct copy (SlaveBase::copy) can be done,
  1129. * in which case the mtime of the source is applied to the destination (if the protocol
  1130. * supports the concept).
  1131. */
  1132. void setModificationTime( time_t mtime );
  1133. /**
  1134. * @deprecated
  1135. */
  1136. void setSourceSize( off_t size ) KDE_DEPRECATED;
  1137. /**
  1138. * Returns the source URL.
  1139. * @return the source URL
  1140. */
  1141. KURL srcURL() const { return m_src; }
  1142. /**
  1143. * Returns the destination URL.
  1144. * @return the destination URL
  1145. */
  1146. KURL destURL() const { return m_dest; }
  1147. signals:
  1148. /**
  1149. * Mimetype determined during a file copy.
  1150. * This is never emitted during a move, and might not be emitted during
  1151. * a copy, depending on the slave.
  1152. * @param job the job that emitted this signal
  1153. * @param type the mime type
  1154. *
  1155. * @since 3.5.7
  1156. */
  1157. void mimetype( TDEIO::Job *job, const TQString &type );
  1158. public slots:
  1159. void slotStart();
  1160. void slotData( TDEIO::Job *, const TQByteArray &data);
  1161. void slotDataReq( TDEIO::Job *, TQByteArray &data);
  1162. void slotMimetype( TDEIO::Job *, const TQString& type );
  1163. protected slots:
  1164. /**
  1165. * Called whenever a subjob finishes.
  1166. * @param job the job that emitted this signal
  1167. */
  1168. virtual void slotResult( TDEIO::Job *job );
  1169. /**
  1170. * Forward signal from subjob
  1171. * @param job the job that emitted this signal
  1172. * @param size the processed size in bytes
  1173. */
  1174. void slotProcessedSize( TDEIO::Job *job, TDEIO::filesize_t size );
  1175. /**
  1176. * Forward signal from subjob
  1177. * @param job the job that emitted this signal
  1178. * @param size the total size
  1179. */
  1180. void slotTotalSize( TDEIO::Job *job, TDEIO::filesize_t size );
  1181. /**
  1182. * Forward signal from subjob
  1183. * @param job the job that emitted this signal
  1184. * @param pct the percentage
  1185. */
  1186. void slotPercent( TDEIO::Job *job, unsigned long pct );
  1187. /**
  1188. * Forward signal from subjob
  1189. * @param job the job that emitted this signal
  1190. * @param offset the offset to resume from
  1191. */
  1192. void slotCanResume( TDEIO::Job *job, TDEIO::filesize_t offset );
  1193. protected:
  1194. void startCopyJob();
  1195. void startCopyJob(const KURL &slave_url);
  1196. void startRenameJob(const KURL &slave_url);
  1197. void startDataPump();
  1198. void connectSubjob( SimpleJob * job );
  1199. private:
  1200. void startBestCopyMethod();
  1201. protected:
  1202. KURL m_src;
  1203. KURL m_dest;
  1204. int m_permissions;
  1205. bool m_move:1;
  1206. bool m_overwrite:1;
  1207. bool m_resume:1;
  1208. bool m_canResume:1;
  1209. bool m_resumeAnswerSent:1;
  1210. TQByteArray m_buffer;
  1211. SimpleJob *m_moveJob;
  1212. SimpleJob *m_copyJob;
  1213. TransferJob *m_getJob;
  1214. TransferJob *m_putJob;
  1215. TDEIO::filesize_t m_totalSize;
  1216. protected:
  1217. virtual void virtual_hook( int id, void* data );
  1218. private:
  1219. class FileCopyJobPrivate;
  1220. FileCopyJobPrivate* d;
  1221. };
  1222. /**
  1223. * A ListJob is allows you to get the get the content of a directory.
  1224. * Don't create the job directly, but use TDEIO::listRecursive() or
  1225. * TDEIO::listDir() instead.
  1226. * @see TDEIO::listRecursive()
  1227. * @see TDEIO::listDir()
  1228. */
  1229. class TDEIO_EXPORT ListJob : public SimpleJob {
  1230. Q_OBJECT
  1231. public:
  1232. /**
  1233. * Do not create a ListJob directly. Use TDEIO::listDir() or
  1234. * TDEIO::listRecursive() instead.
  1235. * @param url the url of the directory
  1236. * @param showProgressInfo true to show progress information to the user
  1237. * @param recursive true to get the data recursively from child directories,
  1238. * false to get only the content of the specified dir
  1239. * @param prefix the prefix of the files, or TQString::null for no prefix
  1240. * @param includeHidden true to include hidden files (those starting with '.')
  1241. */
  1242. ListJob(const KURL& url, bool showProgressInfo,
  1243. bool recursive = false, TQString prefix = TQString::null,
  1244. bool includeHidden = true);
  1245. /**
  1246. * @internal
  1247. * Called by the scheduler when a @p slave gets to
  1248. * work on this job.
  1249. * @param slave the slave that starts working on this job
  1250. */
  1251. virtual void start( Slave *slave );
  1252. /**
  1253. * Returns the ListJob's redirection URL. This will be invalid if there
  1254. * was no redirection.
  1255. * @return the redirection url
  1256. * @since 3.4.1
  1257. */
  1258. const KURL& redirectionURL() const { return m_redirectionURL; }
  1259. /**
  1260. * Do not apply any KIOSK restrictions to this job.
  1261. * @since 3.2
  1262. */
  1263. void setUnrestricted(bool unrestricted);
  1264. signals:
  1265. /**
  1266. * This signal emits the entry found by the job while listing.
  1267. * The progress signals aren't specific to ListJob. It simply
  1268. * uses SimpleJob's processedSize (number of entries listed) and
  1269. * totalSize (total number of entries, if known),
  1270. * as well as percent.
  1271. * @param job the job that emitted this signal
  1272. * @param list the list of UDSEntries
  1273. */
  1274. void entries( TDEIO::Job *job, const TDEIO::UDSEntryList& list);
  1275. /**
  1276. * Signals a redirection.
  1277. * Use to update the URL shown to the user.
  1278. * The redirection itself is handled internally.
  1279. * @param job the job that is redirected
  1280. * @param url the new url
  1281. */
  1282. void redirection( TDEIO::Job *job, const KURL &url );
  1283. /**
  1284. * Signals a permanent redirection.
  1285. * The redirection itself is handled internally.
  1286. * @param job the job that emitted this signal
  1287. * @param fromUrl the original URL
  1288. * @param toUrl the new URL
  1289. * @since 3.1
  1290. */
  1291. void permanentRedirection( TDEIO::Job *job, const KURL &fromUrl, const KURL &toUrl );
  1292. protected slots:
  1293. virtual void slotFinished( );
  1294. virtual void slotMetaData( const TDEIO::MetaData &_metaData);
  1295. virtual void slotResult( TDEIO::Job *job );
  1296. void slotListEntries( const TDEIO::UDSEntryList& list );
  1297. void slotRedirection( const KURL &url );
  1298. void gotEntries( TDEIO::Job * subjob, const TDEIO::UDSEntryList& list );
  1299. private:
  1300. bool recursive;
  1301. bool includeHidden;
  1302. TQString prefix;
  1303. unsigned long m_processedEntries;
  1304. KURL m_redirectionURL;
  1305. protected:
  1306. virtual void virtual_hook( int id, void* data );
  1307. private:
  1308. class ListJobPrivate* d;
  1309. };
  1310. /// @internal
  1311. struct TDEIO_EXPORT CopyInfo
  1312. {
  1313. KURL uSource;
  1314. KURL uDest;
  1315. TQString linkDest; // for symlinks only
  1316. int permissions;
  1317. //mode_t type;
  1318. time_t ctime;
  1319. time_t mtime;
  1320. TDEIO::filesize_t size; // 0 for dirs
  1321. };
  1322. /**
  1323. * CopyJob is used to move, copy or symlink files and directories.
  1324. * Don't create the job directly, but use TDEIO::copy(),
  1325. * TDEIO::move(), TDEIO::link() and friends.
  1326. *
  1327. * @see TDEIO::copy()
  1328. * @see TDEIO::copyAs()
  1329. * @see TDEIO::move()
  1330. * @see TDEIO::moveAs()
  1331. * @see TDEIO::link()
  1332. * @see TDEIO::linkAs()
  1333. */
  1334. class TDEIO_EXPORT CopyJob : public Job {
  1335. Q_OBJECT
  1336. public:
  1337. /**
  1338. * Defines the mode of the operation
  1339. */
  1340. enum CopyMode{ Copy, Move, Link };
  1341. /**
  1342. * Do not create a CopyJob directly. Use TDEIO::copy(),
  1343. * TDEIO::move(), TDEIO::link() and friends instead.
  1344. *
  1345. * @param src the list of source URLs
  1346. * @param dest the destination URL
  1347. * @param mode specifies whether the job should copy, move or link
  1348. * @param asMethod if true, behaves like TDEIO::copyAs(),
  1349. * TDEIO::moveAs() or TDEIO::linkAs()
  1350. * @param showProgressInfo true to show progress information to the user
  1351. * @see TDEIO::copy()
  1352. * @see TDEIO::copyAs()
  1353. * @see TDEIO::move()
  1354. * @see TDEIO::moveAs()
  1355. * @see TDEIO::link()
  1356. * @see TDEIO::linkAs()
  1357. */
  1358. CopyJob( const KURL::List& src, const KURL& dest, CopyMode mode, bool asMethod, bool showProgressInfo );
  1359. virtual ~CopyJob();
  1360. /**
  1361. * Returns the list of source URLs.
  1362. * @return the list of source URLs.
  1363. */
  1364. KURL::List srcURLs() const { return m_srcList; }
  1365. /**
  1366. * Returns the destination URL.
  1367. * @return the destination URL
  1368. */
  1369. KURL destURL() const { return m_dest; }
  1370. /**
  1371. * By default the permissions of the copied files will be those of the source files.
  1372. *
  1373. * But when copying "template" files to "new" files, people prefer the umask
  1374. * to apply, rather than the template's permissions.
  1375. * For that case, call setDefaultPermissions(true)
  1376. *
  1377. * TODO KDE4: consider adding this as bool to copy/copyAs?
  1378. * @since 3.2.3
  1379. */
  1380. void setDefaultPermissions( bool b );
  1381. /**
  1382. * When an error happens while copying/moving a file, the user will be presented with
  1383. * a dialog for skipping the file that can't be copied/moved.
  1384. * Or if the error is that the destination file already exists, the standard
  1385. * rename dialog is shown.
  1386. * If the program doesn't want CopyJob to show dialogs, but to simply fail on error,
  1387. * call setInteractive( false ).
  1388. *
  1389. * KDE4: remove, already in Job
  1390. * @since 3.4
  1391. */
  1392. void setInteractive( bool b );
  1393. signals:
  1394. /**
  1395. * Emitted when the total number of files is known.
  1396. * @param job the job that emitted this signal
  1397. * @param files the total number of files
  1398. */
  1399. void totalFiles( TDEIO::Job *job, unsigned long files );
  1400. /**
  1401. * Emitted when the toal number of direcotries is known.
  1402. * @param job the job that emitted this signal
  1403. * @param dirs the total number of directories
  1404. */
  1405. void totalDirs( TDEIO::Job *job, unsigned long dirs );
  1406. /**
  1407. * Emitted when it is known which files / directories are going
  1408. * to be created. Note that this may still change e.g. when
  1409. * existing files with the same name are discovered.
  1410. * @param job the job that emitted this signal
  1411. * @param files a list of items that are about to be created.
  1412. */
  1413. void aboutToCreate( TDEIO::Job *job, const TQValueList<TDEIO::CopyInfo> &files);
  1414. /**
  1415. * Sends the number of processed files.
  1416. * @param job the job that emitted this signal
  1417. * @param files the number of processed files
  1418. */
  1419. void processedFiles( TDEIO::Job *job, unsigned long files );
  1420. /**
  1421. * Sends the number of processed directories.
  1422. * @param job the job that emitted this signal
  1423. * @param dirs the number of processed dirs
  1424. */
  1425. void processedDirs( TDEIO::Job *job, unsigned long dirs );
  1426. /**
  1427. * The job is copying a file or directory.
  1428. * @param job the job that emitted this signal
  1429. * @param from the URl of the file or directory that is currently
  1430. * being copied
  1431. * @param to the destination of the current operation
  1432. */
  1433. void copying( TDEIO::Job *job, const KURL& from, const KURL& to );
  1434. /**
  1435. * The job is creating a symbolic link.
  1436. * @param job the job that emitted this signal
  1437. * @param target the URl of the file or directory that is currently
  1438. * being linked
  1439. * @param to the destination of the current operation
  1440. */
  1441. void linking( TDEIO::Job *job, const TQString& target, const KURL& to );
  1442. /**
  1443. * The job is moving a file or directory.
  1444. * @param job the job that emitted this signal
  1445. * @param from the URl of the file or directory that is currently
  1446. * being moved
  1447. * @param to the destination of the current operation
  1448. */
  1449. void moving( TDEIO::Job *job, const KURL& from, const KURL& to );
  1450. /**
  1451. * The job is creating the directory @p dir.
  1452. * @param job the job that emitted this signal
  1453. * @param dir the directory that is currently being created
  1454. */
  1455. void creatingDir( TDEIO::Job *job, const KURL& dir );
  1456. /**
  1457. * The user chose to rename @p from to @p to.
  1458. * @param job the job that emitted this signal
  1459. * @param from the original name
  1460. * @param to the new name
  1461. */
  1462. void renamed( TDEIO::Job *job, const KURL& from, const KURL& to );
  1463. /**
  1464. * The job emits this signal when copying or moving a file or directory successfully finished.
  1465. * This signal is mainly for the Undo feature.
  1466. *
  1467. * @param job the job that emitted this signal
  1468. * @param from the source URL
  1469. * @param to the destination URL
  1470. * @param directory indicates whether a file or directory was successfully copied/moved.
  1471. * true for a directoy, false for file
  1472. * @param renamed indicates that the destination URL was created using a
  1473. * rename operation (i.e. fast directory moving). true if is has been renamed
  1474. */
  1475. void copyingDone( TDEIO::Job *job, const KURL &from, const KURL &to, bool directory, bool renamed );
  1476. /**
  1477. * The job is copying or moving a symbolic link, that points to target.
  1478. * The new link is created in @p to. The existing one is/was in @p from.
  1479. * This signal is mainly for the Undo feature.
  1480. * @param job the job that emitted this signal
  1481. * @param from the source URL
  1482. * @param target the target
  1483. * @param to the destination URL
  1484. */
  1485. void copyingLinkDone( TDEIO::Job *job, const KURL &from, const TQString& target, const KURL& to );
  1486. protected:
  1487. void statCurrentSrc();
  1488. void statNextSrc();
  1489. // Those aren't slots but submethods for slotResult.
  1490. void slotResultStating( TDEIO::Job * job );
  1491. void startListing( const KURL & src );
  1492. void slotResultCreatingDirs( TDEIO::Job * job );
  1493. void slotResultConflictCreatingDirs( TDEIO::Job * job );
  1494. void createNextDir();
  1495. void slotResultCopyingFiles( TDEIO::Job * job );
  1496. void slotResultConflictCopyingFiles( TDEIO::Job * job );
  1497. void copyNextFile();
  1498. void slotResultDeletingDirs( TDEIO::Job * job );
  1499. void deleteNextDir();
  1500. void skip( const KURL & sourceURL );
  1501. void slotResultRenaming( TDEIO::Job * job );
  1502. //void slotResultSettingDirAttributes( TDEIO::Job * job );
  1503. void setNextDirAttribute();
  1504. private:
  1505. void startRenameJob(const KURL &slave_url);
  1506. bool shouldOverwrite( const TQString& path ) const;
  1507. bool shouldSkip( const TQString& path ) const;
  1508. void skipSrc();
  1509. protected slots:
  1510. void slotStart();
  1511. void slotEntries( TDEIO::Job*, const TDEIO::UDSEntryList& list );
  1512. virtual void slotResult( TDEIO::Job *job );
  1513. /**
  1514. * Forward signal from subjob
  1515. */
  1516. void slotProcessedSize( TDEIO::Job*, TDEIO::filesize_t data_size );
  1517. /**
  1518. * Forward signal from subjob
  1519. * @param size the total size
  1520. */
  1521. void slotTotalSize( TDEIO::Job*, TDEIO::filesize_t size );
  1522. void slotReport();
  1523. private:
  1524. CopyMode m_mode;
  1525. bool m_asMethod;
  1526. enum DestinationState { DEST_NOT_STATED, DEST_IS_DIR, DEST_IS_FILE, DEST_DOESNT_EXIST };
  1527. DestinationState destinationState;
  1528. enum { STATE_STATING, STATE_RENAMING, STATE_LISTING, STATE_CREATING_DIRS,
  1529. STATE_CONFLICT_CREATING_DIRS, STATE_COPYING_FILES, STATE_CONFLICT_COPYING_FILES,
  1530. STATE_DELETING_DIRS, STATE_SETTING_DIR_ATTRIBUTES } state;
  1531. TDEIO::filesize_t m_totalSize;
  1532. TDEIO::filesize_t m_processedSize;
  1533. TDEIO::filesize_t m_fileProcessedSize;
  1534. int m_processedFiles;
  1535. int m_processedDirs;
  1536. TQValueList<CopyInfo> files;
  1537. TQValueList<CopyInfo> dirs;
  1538. KURL::List dirsToRemove;
  1539. KURL::List m_srcList;
  1540. KURL::List::Iterator m_currentStatSrc;
  1541. bool m_bCurrentSrcIsDir;
  1542. bool m_bCurrentOperationIsLink;
  1543. bool m_bSingleFileCopy;
  1544. bool m_bOnlyRenames;
  1545. KURL m_dest;
  1546. KURL m_currentDest;
  1547. //
  1548. TQStringList m_skipList;
  1549. TQStringList m_overwriteList;
  1550. bool m_bAutoSkip;
  1551. bool m_bOverwriteAll;
  1552. int m_conflictError;
  1553. TQTimer *m_reportTimer;
  1554. //these both are used for progress dialog reporting
  1555. KURL m_currentSrcURL;
  1556. KURL m_currentDestURL;
  1557. protected:
  1558. virtual void virtual_hook( int id, void* data );
  1559. private:
  1560. class CopyJobPrivate;
  1561. CopyJobPrivate* d;
  1562. friend class CopyJobPrivate; // for DestinationState
  1563. };
  1564. /**
  1565. * A more complex Job to delete files and directories.
  1566. * Don't create the job directly, but use TDEIO::del() instead.
  1567. *
  1568. * @see TDEIO::del()
  1569. */
  1570. class TDEIO_EXPORT DeleteJob : public Job {
  1571. Q_OBJECT
  1572. public:
  1573. /**
  1574. * Do not create a DeleteJob directly. Use TDEIO::del()
  1575. * instead.
  1576. *
  1577. * @param src the list of URLs to delete
  1578. * @param shred true to shred (make sure that data is not recoverable)a
  1579. * @param showProgressInfo true to show progress information to the user
  1580. * @see TDEIO::del()
  1581. */
  1582. DeleteJob( const KURL::List& src, bool shred, bool showProgressInfo );
  1583. /**
  1584. * Returns the list of URLs.
  1585. * @return the list of URLs.
  1586. */
  1587. KURL::List urls() const { return m_srcList; }
  1588. signals:
  1589. /**
  1590. * Emitted when the total number of files is known.
  1591. * @param job the job that emitted this signal
  1592. * @param files the total number of files
  1593. */
  1594. void totalFiles( TDEIO::Job *job, unsigned long files );
  1595. /**
  1596. * Emitted when the toal number of direcotries is known.
  1597. * @param job the job that emitted this signal
  1598. * @param dirs the total number of directories
  1599. */
  1600. void totalDirs( TDEIO::Job *job, unsigned long dirs );
  1601. /**
  1602. * Sends the number of processed files.
  1603. * @param job the job that emitted this signal
  1604. * @param files the number of processed files
  1605. */
  1606. void processedFiles( TDEIO::Job *job, unsigned long files );
  1607. /**
  1608. * Sends the number of processed directories.
  1609. * @param job the job that emitted this signal
  1610. * @param dirs the number of processed dirs
  1611. */
  1612. void processedDirs( TDEIO::Job *job, unsigned long dirs );
  1613. /**
  1614. * Sends the URL of the file that is currently being deleted.
  1615. * @param job the job that emitted this signal
  1616. * @param file the URL of the file or directory that is being
  1617. * deleted
  1618. */
  1619. void deleting( TDEIO::Job *job, const KURL& file );
  1620. protected slots:
  1621. void slotStart();
  1622. void slotEntries( TDEIO::Job*, const TDEIO::UDSEntryList& list );
  1623. virtual void slotResult( TDEIO::Job *job );
  1624. /**
  1625. * Forward signal from subjob
  1626. */
  1627. void slotProcessedSize( TDEIO::Job*, TDEIO::filesize_t data_size );
  1628. void slotReport();
  1629. private:
  1630. void statNextSrc();
  1631. void deleteNextFile();
  1632. void deleteNextDir();
  1633. private:
  1634. enum { STATE_STATING, STATE_LISTING,
  1635. STATE_DELETING_FILES, STATE_DELETING_DIRS } state;
  1636. TDEIO::filesize_t m_totalSize;
  1637. TDEIO::filesize_t m_processedSize;
  1638. TDEIO::filesize_t m_fileProcessedSize;
  1639. int m_processedFiles;
  1640. int m_processedDirs;
  1641. int m_totalFilesDirs;
  1642. KURL m_currentURL;
  1643. KURL::List files;
  1644. KURL::List symlinks;
  1645. KURL::List dirs;
  1646. KURL::List m_srcList;
  1647. KURL::List::Iterator m_currentStat;
  1648. TQStringList m_parentDirs;
  1649. bool m_shred; // BIC: remove in KDE4
  1650. TQTimer *m_reportTimer;
  1651. protected:
  1652. /** \internal */
  1653. virtual void virtual_hook( int id, void* data );
  1654. private:
  1655. class DeleteJobPrivate* d;
  1656. };
  1657. /**
  1658. * A KIO job that finds a local URL
  1659. * @see TDEIO::localURL()
  1660. * @since R14.0.0
  1661. */
  1662. class TDEIO_EXPORT LocalURLJob : public SimpleJob {
  1663. Q_OBJECT
  1664. public:
  1665. /**
  1666. * Do not use this constructor to create a LocalURLJob, use TDEIO::localURL() instead.
  1667. * @param url the url of the file or directory to check
  1668. * @param command the command to issue
  1669. * @param packedArgs the arguments
  1670. * @param showProgressInfo true to show progress information to the user
  1671. */
  1672. LocalURLJob(const KURL& url, int command, const TQByteArray &packedArgs, bool showProgressInfo);
  1673. /**
  1674. * @internal
  1675. * Called by the scheduler when a @p slave gets to
  1676. * work on this job.
  1677. * @param slave the slave that starts working on this job
  1678. */
  1679. virtual void start( Slave *slave );
  1680. signals:
  1681. /**
  1682. * @param job the job that emitted this signal
  1683. * @param url the local url
  1684. * @param isLocal true if the returned URL is local, false if not
  1685. */
  1686. void localURL( TDEIO::Job *job, const KURL &url, bool isLocal );
  1687. protected slots:
  1688. void slotLocalURL( const KURL &url, bool isLocal );
  1689. virtual void slotFinished();
  1690. protected:
  1691. virtual void virtual_hook( int id, void* data );
  1692. private:
  1693. class LocalURLJobPrivate;
  1694. LocalURLJobPrivate *d;
  1695. };
  1696. }
  1697. #endif