19 #include "tdeio/slaveinterface.h"
20 #include "tdeio/slavebase.h"
21 #include "tdeio/connection.h"
29 #include <tdeio/observer.h>
30 #include <tdeapplication.h>
31 #include <dcopclient.h>
35 using namespace TDEIO;
47 TDEIO::UDSEntry::ConstIterator it = e.begin();
48 for( ; it != e.end(); ++it )
56 for( ; it != e.end(); ++it )
61 a.m_uds = TDEIO::UDS_SIZE_LARGE;
62 a.m_long = (*it).m_long >> 32;
82 for(TQ_UINT32 i = 0; i < size; i++)
86 if (a.m_uds == TDEIO::UDS_SIZE_LARGE)
95 a.m_long += (TQ_LLONG) 1 << 32;
96 a.m_long += msb << 32;
105 static const unsigned int max_nums = 8;
107 class TDEIO::SlaveInterfacePrivate
110 SlaveInterfacePrivate() {
111 slave_calcs_speed =
false;
112 start_time.tv_sec = 0;
113 start_time.tv_usec = 0;
119 bool slave_calcs_speed;
120 struct timeval start_time;
122 long times[max_nums];
132 SlaveInterface::SlaveInterface(
Connection * connection )
134 m_pConnection = connection;
137 d =
new SlaveInterfacePrivate;
138 connect(&d->speed_timer, TQ_SIGNAL(timeout()), TQ_SLOT(calcSpeed()));
141 SlaveInterface::~SlaveInterface()
163 bool SlaveInterface::dispatch()
165 assert( m_pConnection );
170 if (m_pConnection->
read( &cmd, data ) == -1)
173 return dispatch( cmd, data );
176 void SlaveInterface::calcSpeed()
178 if (d->slave_calcs_speed) {
179 d->speed_timer.stop();
184 gettimeofday(&tv, 0);
186 long diff = ((tv.tv_sec - d->start_time.tv_sec) * 1000000 +
187 tv.tv_usec - d->start_time.tv_usec) / 1000;
188 if (diff - d->last_time >= 900) {
190 if (d->nums == max_nums) {
193 for (
unsigned int i = 1; i < max_nums; ++i) {
194 d->times[i-1] = d->times[i];
195 d->sizes[i-1] = d->sizes[i];
199 d->times[d->nums] = diff;
200 d->sizes[d->nums++] = d->filesize - d->offset;
202 TDEIO::filesize_t lspeed = 1000 * (d->sizes[d->nums-1] - d->sizes[0]) / (d->times[d->nums-1] - d->times[0]);
215 d->sizes[0] = d->filesize - d->offset;
221 bool SlaveInterface::dispatch(
int _cmd,
const TQByteArray &rawdata )
225 TQDataStream stream( rawdata, IO_ReadOnly );
234 emit data( rawdata );
242 d->speed_timer.stop();
249 emit statEntry(entry);
252 case MSG_LIST_ENTRIES:
259 for (uint i = 0; i < count; i++) {
263 emit listEntries(list);
269 d->offset = readFilesize_t(stream);
270 emit canResume( d->offset );
274 d->filesize = d->offset;
279 kdDebug(7007) <<
"error " << i <<
" " << str1 << endl;
280 emit error( i, str1 );
282 case MSG_SLAVE_STATUS:
286 stream >> pid >> protocol >> str1 >> b;
287 emit slaveStatus(pid, protocol, str1, (b != 0));
297 gettimeofday(&d->start_time, 0);
299 d->filesize = d->offset;
300 d->sizes[0] = d->filesize - d->offset;
303 d->speed_timer.start(1000);
304 d->slave_calcs_speed =
false;
305 emit totalSize( size );
308 case INF_PROCESSED_SIZE:
311 emit processedSize( size );
317 d->slave_calcs_speed =
true;
318 d->speed_timer.stop();
322 case INF_GETTING_FILE:
327 case INF_REDIRECTION:
332 emit redirection( url );
338 emit mimeType( str1 );
340 m_pConnection->
sendnow( CMD_NONE, TQByteArray() );
345 emit warning( str1 );
347 case INF_NEED_PASSWD: {
353 case INF_MESSAGEBOX: {
354 kdDebug(7007) <<
"needs a msg box" << endl;
355 TQString text, caption, buttonYes, buttonNo, dontAskAgainName;
357 stream >> type >> text >> caption >> buttonYes >> buttonNo;
359 messageBox(type, text, caption, buttonYes, buttonNo);
361 stream >> dontAskAgainName;
362 messageBox(type, text, caption, buttonYes, buttonNo, dontAskAgainName);
366 case INF_INFOMESSAGE: {
372 case INF_META_DATA: {
381 stream >> islocal >> url;
382 emit localURL( url, islocal );
385 case MSG_NET_REQUEST: {
388 stream >> host >> slaveid;
389 requestNetwork(host, slaveid);
395 stream >> host >> slaveid;
396 dropNetwork(host, slaveid);
399 case MSG_NEED_SUBURL_DATA: {
400 emit needSubURLData();
405 TQCString key, group;
406 stream >> key >> group >> keep;
407 kdDebug(7007) <<
"Got auth-key: " << key << endl
408 <<
" group-key: " << group << endl
409 <<
" keep password: " << keep << endl;
413 case MSG_DEL_AUTH_KEY: {
416 kdDebug(7007) <<
"Delete auth-key: " << key << endl;
420 kdWarning(7007) <<
"Slave sends unknown command (" << _cmd <<
"), dropping slave" << endl;
433 void SlaveInterface::requestNetwork(
const TQString &host,
const TQString &slaveid)
435 kdDebug(7007) <<
"requestNetwork " << host << slaveid << endl;
436 TQByteArray packedArgs;
437 TQDataStream stream( packedArgs, IO_WriteOnly );
439 m_pConnection->
sendnow( INF_NETWORK_STATUS, packedArgs );
442 void SlaveInterface::dropNetwork(
const TQString &host,
const TQString &slaveid)
444 kdDebug(7007) <<
"dropNetwork " << host << slaveid << endl;
449 kdDebug(7007) <<
"SlaveInterface::sendResumeAnswer ok for resuming :" << resume << endl;
450 m_pConnection->
sendnow( resume ? CMD_RESUMEANSWER : CMD_NONE, TQByteArray() );
463 const TQString& caption,
const TQString& comment,
464 const TQString& label,
bool readOnly )
478 kdDebug(7007) <<
"SlaveInterface::openPassDlg: "
480 <<
", Message= " << info.
prompt << endl;
485 TQDataStream stream( data, IO_WriteOnly );
489 kdDebug(7007) <<
"SlaveInterface:::openPassDlg got: "
491 <<
", Password= [hidden]" << endl;
492 m_pConnection->
sendnow( CMD_USERPASS, data );
495 m_pConnection->
sendnow( CMD_NONE, data );
499 void SlaveInterface::messageBox(
int type,
const TQString &text,
const TQString &_caption,
500 const TQString &buttonYes,
const TQString &buttonNo )
502 messageBox( type, text, _caption, buttonYes, buttonNo, TQString::null );
505 void SlaveInterface::messageBox(
int type,
const TQString &text,
const TQString &_caption,
506 const TQString &buttonYes,
const TQString &buttonNo,
const TQString &dontAskAgainName )
508 kdDebug(7007) <<
"messageBox " << type <<
" " << text <<
" - " << _caption <<
" " << dontAskAgainName << endl;
509 TQByteArray packedArgs;
510 TQDataStream stream( packedArgs, IO_WriteOnly );
512 TQString caption( _caption );
513 if ( type == TDEIO::SlaveBase::SSLMessageBox )
514 caption = TQString::fromUtf8(kapp->dcopClient()->appId());
516 emit needProgressId();
517 kdDebug(7007) <<
"SlaveInterface::messageBox m_progressId=" << m_progressId << endl;
518 TQGuardedPtr<SlaveInterface> me =
this;
520 int result =
Observer::messageBox( m_progressId, type, text, caption, buttonYes, buttonNo, dontAskAgainName );
521 if ( me && m_pConnection )
524 kdDebug(7007) <<
this <<
" SlaveInterface result=" << result << endl;
526 m_pConnection->
sendnow( CMD_MESSAGEBOXANSWER, packedArgs );
532 void SlaveInterface::sigpipe_handler(
int)
534 int saved_errno = errno;
538 sprintf(msg,
"*** SIGPIPE *** (ignored, pid = %ld)\n", (
long) getpid());
539 if (write(2, msg, strlen(msg)) < 0) {
551 void SlaveInterface::virtual_hook(
int,
void* )
554 #include "slaveinterface.moc"
Observer for TDEIO::Job progress information.
bool openPassDlg(const TQString &prompt, TQString &user, TQString &pass, bool readOnly)
static Observer * self()
Returns the unique observer object.
This class is intended to make it easier to prompt for, cache and retrieve authorization information.
TQString username
This is required for caching.
TQString prompt
Information to be displayed when prompting the user for authentication information.
TQString commentLabel
Descriptive label to be displayed in front of the comment when prompting the user for password.
TQString comment
Additional comment to be displayed when prompting the user for authentication information.
TQString caption
The text to displayed in the title bar of the password prompting dialog.
bool readOnly
Flag which if set forces the username field to be read-only.
This class provides a simple means for IPC between two applications via a pipe.
void resume()
Resume handling of incoming data.
void suspend()
Don't handle incoming data until resumed.
int read(int *_cmd, TQByteArray &data)
Receive data.
bool sendnow(int _cmd, const TQByteArray &data)
Sends the given command immediately.
void sendResumeAnswer(bool resume)
Send our answer to the MSG_RESUME (canResume) request (to tell the "put" job whether to resume or not...
void delAuthorization(const TQCString &grpkey)
void authorizationKey(const TQCString &, const TQCString &, bool)
void openPassDlg(TDEIO::AuthInfo &info)
Prompt the user for authrization info (login & password).
A namespace for TDEIO globals.
@ UDS_SIZE
Size of the file.
TQValueList< UDSAtom > UDSEntry
An entry is the list of atoms containing all the information for a file or URL.
TQ_ULLONG filesize_t
64-bit file size