Esempio n. 1
0
void KgpgApp::slotFileSave()
{
    TQString filn=Docname.path();
    if (filn.isEmpty()) {
    	slotFileSaveAs();
    	return;
    }
    TQTextCodec*cod=TQTextCodec::codecForName (textEncoding.ascii());
        // slotStatusMsg(i18n("Saving file..."));
    if (!checkEncoding(cod)) {
	KMessageBox::sorry(this,i18n("The document could not been saved, as the selected encoding cannot encode every unicode character in it."));
	return;
    }

    KTempFile tmpfile;
    if (Docname.isLocalFile()) {
    TQFile f(filn);
    if ( !f.open( IO_WriteOnly ) ) {
	KMessageBox::sorry(this,i18n("The document could not be saved, please check your permissions and disk space."));
        return;
    }
    TQTextStream t( &f );
    t.setCodec(cod);
    //t.setEncoding( TQTextStream::Latin1 );
    t << view->editor->text();//.utf8();
    f.close();
    }
    else {
	/*FIXME  use following code:
	 TQFile f( fName );
00983         if ( !f.open( IO_ReadOnly ) )
00984             return;
00985         TQFileInfo info ( f );
00986         smModificationTime = new TQTime( info.lastModified().time() );
00987         TQTextStream t(&f);
00988         t.setEncoding( TQTextStream::Latin1 );
00989         TQString s = t.readLine();
00990         f.close();

*/
	TQTextStream *stream = tmpfile.textStream();
	stream->setCodec(cod);
    	*stream << view->editor->text();//.utf8();
   	tmpfile.close();
	if(!TDEIO::NetAccess::upload(tmpfile.name(), Docname,this)) {
	    KMessageBox::sorry(this,i18n("The document could not be saved, please check your permissions and disk space."));
	    tmpfile.unlink();
            return;
	}
	tmpfile.unlink();
    }

    fileSave->setEnabled(false);
    setCaption(Docname.fileName(),false);
}
Esempio n. 2
0
void K3bIsoImager::writePathSpecForFile( K3bFileItem* item, QTextStream& stream )
{
  stream << escapeGraftPoint( item->writtenPath() )
	 << "=";

  if( m_doc->bootImages().containsRef( dynamic_cast<K3bBootItem*>(item) ) ) { // boot-image-backup-hack

    // create temp file
    KTempFile temp;
    QString tempPath = temp.name();
    temp.unlink();

    if( !KIO::NetAccess::copy( KURL(item->localPath()), KURL::fromPathOrURL(tempPath) ) ) {
      emit infoMessage( i18n("Failed to backup boot image file %1").arg(item->localPath()), ERROR );
      return;
    }

    static_cast<K3bBootItem*>(item)->setTempPath( tempPath );

    m_tempFiles.append(tempPath);
    stream << escapeGraftPoint( tempPath ) << "\n";
  }
  else if( item->isSymLink() && d->usedLinkHandling == Private::FOLLOW )
    stream << escapeGraftPoint( K3b::resolveLink( item->localPath() ) ) << "\n";
  else
    stream << escapeGraftPoint( item->localPath() ) << "\n";
}
Esempio n. 3
0
void RulesDialog::slotUser2()
{
  KURL kurl = KFileDialog::getSaveURL(0, i18n("*.sh|Shell Scripts (*.sh)"), this);
  if (kurl.path() == "")
    return;

  KTempFile temp;
  QString fileName = kurl.path();

  if (fileName == "")
    return;

  if (!kurl.isLocalFile())
  {
    fileName = temp.name();
  }
  
  QFile file(fileName);
  file.open(IO_WriteOnly);
  QTextStream stream(&file);
  stream << mRules->text();
  file.close();
  if (!kurl.isLocalFile())
  {
    if (!KIO::NetAccess::upload(fileName, kurl, this))
      KMessageBox::error(this, i18n("Failed to upload file."));
  }

  temp.unlink();
}
void KMoneyThingMainWidget::slotSave()
{
  KTempFile temp;
  QString fileName = mCurrentFile->kurl().path();
  
  if (fileName == "")
  {
    slotSaveAs();
    return;
  }
  
  if (!mCurrentFile->kurl().isLocalFile())
  {
    fileName = temp.name();
  }
  
  emit(setStatus(i18n("Saving file...")));
  QByteArray dump = qCompress(mCurrentFile->dump());
  QFile file(fileName);
  file.open(IO_WriteOnly);
  QDataStream stream(&file);
  stream << (QString) "KMoneyThingFile" << dump;
  file.close();
  
  if (!mCurrentFile->kurl().isLocalFile())
  {
    emit(setStatus(i18n("Uploading file...")));
    if (!KIO::NetAccess::upload(fileName, mCurrentFile->kurl(), this))
      KMessageBox::error(this, i18n("Failed to upload file."));
  }
  
  temp.unlink();
  
  emit(setStatus(i18n("Ready.")));
}
Esempio n. 5
0
bool KMiniEdit::saveFile(KURL newurl)
{
  if (newurl.isEmpty())
    newurl = KFileDialog::getSaveURL();

  if (newurl.isEmpty())
    return false;

  if (newurl.isMalformed())
  {
    QString text = i18n("<b>THe URL %1 is not correct!</b>");
    KMessageBox::sorry(this, text.arg(newurl.prettyURL()));
    return false;
  }

  if (newurl.isLocalFile())
  {
    QFile file(newurl.path());
    file.open(IO_WriteOnly);
    saveToLocalFile(&file);
  }

  else
  {
    KTempFile tempfile;
    saveToLocalFile(tempfile.file());
    if (!KIO::NetAccess::upload(tempfile.name(), newurl))
    {
      QString text = i18n("<b>Error uploading %1!</b>");
      KMessageBox::sorry(this, text.arg(newurl.prettyURL()));
      tempfile.unlink();
      return false;
    }

    tempfile.unlink();
  }

  url = newurl;
  
  addURLtoRecent();
  
  resetEdited();
  return true;
}