Example #1
0
void ImportGrammarWorkingPage::initializePage()
{
  completed=false;
  emit completeChanged();

  grammarImporter = new ImportGrammar(this);
  connect(grammarImporter, SIGNAL(status(QString)), this, SLOT(printStatus(QString)));
  connect(grammarImporter, SIGNAL(fileProgress(int,int)), this, SLOT(displayFileProgress(int,int)));
  connect(grammarImporter, SIGNAL(allProgress(int,int)), this, SLOT(displayWholeProgress(int,int)));
  connect(grammarImporter, SIGNAL(grammarCreated()), this, SIGNAL(grammarCreated()));
  connect(grammarImporter, SIGNAL(terminated()), this, SLOT(processCompletion()));

  bool isText = field("inputIsText").toBool();
  if (isText) {
    //bla
    QString tempFileName = KStandardDirs::locateLocal("tmp", "grammarImport/importText");

    QFile f(tempFileName);
    if (!f.open(QIODevice::WriteOnly)) {
      KMessageBox::sorry(this, i18n("Could not open temporary file."));
      return;
    }

    QByteArray textByte = field("grammarInputText").toString().toUtf8();
    f.write(textByte);
    f.close();

    grammarImporter->setFiles(QStringList() << tempFileName);
    grammarImporter->setEncoding("UTF-8");
  }
  else {

    QStringList files = field("files").toStringList();

    int index=0;
    QStringList tempFiles;
    foreach (const QString& file, files) {
      KUrl srcUrl(file);
      QString targetPath = KStandardDirs::locateLocal("tmp", "grammarImport/"+
        QString::number(index)+'_'+srcUrl.fileName());
      KIO::FileCopyJob *job = KIO::file_copy(srcUrl, targetPath, -1, KIO::Overwrite);
      if (!job->exec()) {
        job->ui()->showErrorMessage();
        continue;
      } else
      tempFiles << targetPath;
      index++;
      delete job;
    }
    grammarImporter->setFiles(tempFiles);
    grammarImporter->setEncoding(field("encoding").toString());
  }
void KAResourceRemote::slotLoadJobResult(KJob* job)
{
	bool err = false;
	if (job)
	{
		emit invalidate(this);
		calendar()->close();
		setWrongAlarmType(false, false);
		clearChanges();
		if (job->error())
		{
			if (hasGui())
			{
				KIO::FileCopyJob* j = qobject_cast<KIO::FileCopyJob*>(job);
				if (j)
					j->ui()->showErrorMessage();
			}
			kError(KARES_DEBUG) << "Resource" << identifier() << " download error:" << job->errorString();
			setEnabled(false);
			err = true;
		}
		else
		{
			kDebug(KARES_DEBUG) << mDownloadUrl.prettyUrl() << ": success";
			setReloaded(true);    // the resource has now been downloaded at least once
			emit cacheDownloaded(this);
			disableChangeNotification();
			loadFromCache();
			enableChangeNotification();
		}

#if 0
		emit downloading(this, (unsigned long)-1);
#endif
	}
	mDownloadJob = 0;

	if (!err)
	{
		checkCompatibility(cacheFile());
		mLoaded = true;
	}
	mLoading = false;
	lock()->unlock();
	updateCustomEvents();
	emit loaded(this);
	if (job  &&  !err)
		emit resourceChanged(this);
}
void KAResourceRemote::slotSaveJobResult(KJob* job)
{
	if (job->error())
	{
		if (hasGui())
		{
			KIO::FileCopyJob* j = qobject_cast<KIO::FileCopyJob*>(job);
			if (j)
				j->ui()->showErrorMessage();
		}
		kError(KARES_DEBUG) << "Resource" << identifier() << " upload error:" << job->errorString();
	}
	else
	{
		kDebug(KARES_DEBUG) << mUploadUrl.prettyUrl() << ": success";
		clearChanges();
	}

	mUploadJob = 0;
	emit resourceSaved(this);
	if (closeAfterSave())
		close();
}