void JobRemoteTest::putAndGet() { const QString filePath = remoteTmpDir() + "putAndGetFile"; KUrl u(filePath); KIO::TransferJob* job = KIO::put( u, 0600, KIO::Overwrite | KIO::HideProgressInfo ); QDateTime mtime = QDateTime::currentDateTime().addSecs( -30 ); // 30 seconds ago mtime.setTime_t(mtime.toTime_t()); // hack for losing the milliseconds job->setModificationTime(mtime); job->setUiDelegate( 0 ); connect( job, SIGNAL( result(KJob*) ), this, SLOT( slotResult(KJob*) ) ); connect( job, SIGNAL(dataReq(KIO::Job*, QByteArray&)), this, SLOT(slotDataReq(KIO::Job*, QByteArray&)) ); m_result = -1; m_dataReqCount = 0; enterLoop(); QVERIFY( m_result == 0 ); // no error m_result = -1; KIO::StoredTransferJob* getJob = KIO::storedGet( u, KIO::NoReload, KIO::HideProgressInfo ); getJob->setUiDelegate( 0 ); connect( getJob, SIGNAL( result( KJob* ) ), this, SLOT( slotGetResult( KJob* ) ) ); enterLoop(); QCOMPARE( m_result, 0 ); // no error QCOMPARE( m_data, QByteArray("This is a test for KIO::put()\n") ); //QCOMPARE( m_data.size(), 11 ); }
bool ClientApp::doIt() { KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); const int argc = args->count(); checkArgumentCount(argc, 1, 0); if ( !args->isSet( "ninteractive" ) ) { s_interactive = false; s_jobFlags = KIO::HideProgressInfo; } #if !defined(KIOCLIENT_AS_KDEOPEN) if (args->isSet("overwrite")) { s_jobFlags |= KIO::Overwrite; } #endif kDebug() << "Creating ClientApp"; int fake_argc = 0; char** fake_argv = 0; ClientApp app( fake_argc, fake_argv ); KComponentData componentData("kioclient"); // needed by KIO's internal use of KConfig app.setApplicationName(componentData.componentName()); KGlobal::ref(); KGlobal::setAllowQuit(true); // KIO needs dbus (for uiserver communication) extern void qDBusBindToApplication(); qDBusBindToApplication(); if (!QDBusConnection::sessionBus().isConnected()) kFatal(101) << "Session bus not found" ; #ifdef KIOCLIENT_AS_KDEOPEN return app.kde_open(args->url(0), QByteArray(), false); #elif defined(KIOCLIENT_AS_KDECP) checkArgumentCount(argc, 2, 0); return app.doCopy(0); #elif defined(KIOCLIENT_AS_KDEMV) checkArgumentCount(argc, 2, 0); return app.doMove(0); #else // Normal kioclient mode const QByteArray command = args->arg(0).toLocal8Bit(); if ( command == "openProperties" ) { checkArgumentCount(argc, 2, 2); // openProperties <url> KPropertiesDialog * p = new KPropertiesDialog( args->url(1), 0 /*no parent*/ ); QObject::connect( p, SIGNAL( destroyed() ), &app, SLOT( quit() )); QObject::connect( p, SIGNAL( canceled() ), &app, SLOT( slotDialogCanceled() )); p->show(); app.exec(); return m_ok; } else if ( command == "cat" ) { checkArgumentCount(argc, 2, 2); // cat <url> KIO::TransferJob* job = KIO::get(args->url(1), KIO::NoReload, s_jobFlags); if ( !s_interactive ) job->setUiDelegate( 0 ); connect(job, SIGNAL(data(KIO::Job*,QByteArray) ), &app, SLOT(slotPrintData(KIO::Job*,QByteArray))); connect( job, SIGNAL( result( KJob * ) ), &app, SLOT( slotResult( KJob * ) ) ); app.exec(); return m_ok; }