예제 #1
0
bool GMXXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
{
  KURL url = KFileDialog::getSaveURL( ":xxport_gmx", GMX_FILESELECTION_STRING );
  if ( url.isEmpty() )
      return true;

  if ( !url.isLocalFile() ) {
    KTempFile tmpFile;
    if ( tmpFile.status() != 0 ) {
      QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" );
      KMessageBox::error( parentWidget(), txt.arg( url.url() )
                          .arg( strerror( tmpFile.status() ) ) );
      return false;
    }

    doExport( tmpFile.file(), list );
    tmpFile.close();

    return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
  } else {
    QString filename = url.path();
    QFile file( filename );

    if ( !file.open( IO_WriteOnly ) ) {
      QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
      KMessageBox::error( parentWidget(), txt.arg( filename ) );
      return false;
    }

    doExport( &file, list );
    file.close();

    return true;
  }
}
예제 #2
0
QString copyfile(const QString &filename)
{
    kdDebug(500) << "Copying file " << filename << endl;
    QString result;
    QFile f(filename);
    if(f.open(IO_ReadOnly))
    {
        KTempFile temp;
        temp.setAutoDelete(false);
        QFile *tf = temp.file();
        if(tf)
        {
            char buffer[0xFFFF];
            int b = 0;
            while((b = f.readBlock(buffer, 0xFFFF)) > 0)
            {
                if(tf->writeBlock(buffer, b) != b)
                    break;
            }
            tf->close();
            if(b > 0)
                temp.setAutoDelete(true);
            else
            {
                kdDebug(500) << "File copied to " << temp.name() << endl;
                result = temp.name();
            }
        }
        else
            temp.setAutoDelete(true);
        f.close();
    }
    return result;
}
예제 #3
0
void KOrganizerPlugin::processDropEvent( QDropEvent *event )
{
  QString text;

  KABC::VCardConverter converter;
  if ( KVCardDrag::canDecode( event ) && KVCardDrag::decode( event, text ) ) {
    KABC::Addressee::List contacts = converter.parseVCards( text );
    KABC::Addressee::List::Iterator it;

    QStringList attendees;
    for ( it = contacts.begin(); it != contacts.end(); ++it ) {
      QString email = (*it).fullEmail();
      if ( email.isEmpty() )
        attendees.append( (*it).realName() + "<>" );
      else
        attendees.append( email );
    }

    interface()->openEventEditor( i18n( "Meeting" ), QString::null, QString::null,
                                  attendees );
    return;
  }

  if ( QTextDrag::decode( event, text ) ) {
    kdDebug(5602) << "DROP:" << text << endl;
    interface()->openEventEditor( text );
    return;
  }

  KPIM::MailList mails;
  if ( KPIM::MailListDrag::decode( event, mails ) ) {
    if ( mails.count() != 1 ) {
      KMessageBox::sorry( core(),
                          i18n("Drops of multiple mails are not supported." ) );
    } else {
      KPIM::MailSummary mail = mails.first();
      QString txt = i18n("From: %1\nTo: %2\nSubject: %3").arg( mail.from() )
                    .arg( mail.to() ).arg( mail.subject() );

      KTempFile tf;
      tf.setAutoDelete( true );
      QString uri = QString::fromLatin1("kmail:") + QString::number( mail.serialNumber() );
      tf.file()->writeBlock( event->encodedData( "message/rfc822" ) );
      tf.close();
      interface()->openEventEditor( i18n("Mail: %1").arg( mail.subject() ), txt,
                                    uri, tf.name(), QStringList(), "message/rfc822" );
    }
    return;
  }

  KMessageBox::sorry( core(), i18n("Cannot handle drop events of type '%1'.")
                              .arg( event->format() ) );
}
예제 #4
0
bool VCardXXPort::doExport( const KURL &url, const QString &data )
{
  KTempFile tmpFile;
  tmpFile.setAutoDelete( true );

  QTextStream stream( tmpFile.file() );
  stream.setEncoding( QTextStream::UnicodeUTF8 );

  stream << data;
  tmpFile.close();

  return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
}
예제 #5
0
bool KSnapshot::save( const KURL& url )
{
    if ( KIO::NetAccess::exists( url, false, this ) ) {
        const QString title = i18n( "File Exists" );
        const QString text = i18n( "<qt>Do you really want to overwrite <b>%1</b>?</qt>" ).arg(url.prettyURL());
        if (KMessageBox::Continue != KMessageBox::warningContinueCancel( this, text, title, i18n("Overwrite") ) ) 
        {
            return false;
        }
    }

    QString type( KImageIO::type(url.path()) );
    if ( type.isNull() )
	type = "PNG";

    bool ok = false;

    if ( url.isLocalFile() ) {
	KSaveFile saveFile( url.path() );
	if ( saveFile.status() == 0 ) {
	    if ( snapshot.save( saveFile.file(), type.latin1() ) )
		ok = saveFile.close();
	}
    }
    else {
	KTempFile tmpFile;
        tmpFile.setAutoDelete( true );
	if ( tmpFile.status() == 0 ) {
	    if ( snapshot.save( tmpFile.file(), type.latin1() ) ) {
		if ( tmpFile.close() )
		    ok = KIO::NetAccess::upload( tmpFile.name(), url, this );
	    }
	}
    }

    QApplication::restoreOverrideCursor();
    if ( !ok ) {
	kdWarning() << "KSnapshot was unable to save the snapshot" << endl;

	QString caption = i18n("Unable to save image");
	QString text = i18n("KSnapshot was unable to save the image to\n%1.")
	               .arg(url.prettyURL());
	KMessageBox::error(this, text, caption);
    }

    return ok;
}
예제 #6
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;
}
예제 #7
0
bool KSnapshot::save( const KURL& url )
{
    QString type( KImageIO::type(url.path()) );
    if ( type.isNull() )
        type = "PNG";

    bool ok = false;

    if ( url.isLocalFile() ) {
        KSaveFile saveFile( url.path() );
        if ( saveFile.status() == 0 ) {
            if ( snapshot.save( saveFile.file(), type.latin1() ) )
                ok = saveFile.close();
        }
    }
    else {
        KTempFile tmpFile;
        tmpFile.setAutoDelete( true );
        if ( tmpFile.status() == 0 ) {
            if ( snapshot.save( tmpFile.file(), type.latin1() ) ) {
                if ( tmpFile.close() )
                    ok = KIO::NetAccess::upload( tmpFile.name(), url, this );
            }
        }
    }

    QApplication::restoreOverrideCursor();
    if ( !ok ) {
        kdWarning() << "KSnapshot was unable to save the snapshot" << endl;

        QString caption = i18n("Unable to Save Image");
        QString text = i18n("KSnapshot was unable to save the image to\n%1.")
            .arg(url.prettyURL());
        KMessageBox::error(this, text, caption);
    }

    return ok;
}
예제 #8
0
bool Q3DGraph::save(const KURL& url)
{
	if ( KIO::NetAccess::exists( url, false, this ) ) //The file already exist
		return false;

	QString type(KImageIO::type(url.path()));
	if (type.isNull())
		type = "PNG";

	bool ok = false;

	if(url.isLocalFile()) {
		KSaveFile saveFile(url.path());
		if ( saveFile.status() == 0 ) {
			if (toPixmap().save( saveFile.file(), type.latin1() ) )
				ok = saveFile.close();
		}
	} else {
		KTempFile tmpFile;
		tmpFile.setAutoDelete(true);
		if(tmpFile.status()==0) {
			if(toPixmap().save( tmpFile.file(), type.latin1())) {
				if(tmpFile.close())
					ok = KIO::NetAccess::upload( tmpFile.name(), url, this );
			}
		}
	}
	
//	QApplication::restoreOverrideCursor();
	
	if (!ok) {
		qDebug("Was unable to save it");
	}

	return ok;
}
예제 #9
0
void KPrMSPresentation::createIndexFile( KProgress *progressBar )
{
    int p;
    KTempFile sppFile;

    QString filenameStore = (path + "/MSSONY/PJ/" + title + ".SPP");

    QDataStream sppStream( sppFile.file() );
    sppStream.setByteOrder(QDataStream::LittleEndian);
    p = progressBar->progress();
    progressBar->setProgress( ++p );
    kapp->processEvents();

    // We are doing little endian
    sppStream << (Q_UINT32)0x00505053; // SPP magic header
    sppStream << (Q_UINT32)0x00000000; // four null bytes
    sppStream << (Q_UINT32)0x30303130; // version(?) 0100
    sppStream << (Q_UINT32)0x00000000; // more nulls
    sppStream << (Q_UINT32)(slideInfos.count());

    // DCIM path 1, 68 bytes null padded
    char buff[68];
    strncpy( buff, QString("%1").arg(slidePath).ascii(), 67 );
    buff[67] = 0x00;
    sppStream.writeRawBytes( buff, 68 );
    sppStream << (Q_UINT32)0x00000001; // fixed value
    sppStream << (Q_UINT32)0x00000005; // fixed value
    sppStream << (Q_UINT32)0x00000000; // more nulls
    sppStream << (Q_UINT32)0x00000000; // more nulls
    sppStream << (Q_UINT32)0x00000000; // more nulls
    sppStream << (Q_UINT32)0x00000000; // more nulls
    sppStream << (Q_UINT32)0x00000000; // more nulls
    sppStream << (Q_UINT32)0x00000000; // more nulls
    p = progressBar->progress();
    progressBar->setProgress( ++p );
    kapp->processEvents();

    // title 1, 16 bytes null padded
    strncpy( buff, "SPJT0001.JPG", 15 );
    buff[15] = 0x00;
    sppStream.writeRawBytes( buff, 16 );

    // title 2, 16 bytes null padded
    strncpy( buff, "SPJT0002.JPG", 15 );
    buff[15] = 0x00;
    sppStream.writeRawBytes( buff, 16 );


    // type face (?), 44 bytes null padded
    strncpy( buff, "MS Sans Serif", 43 );
    buff[44] = 0x00;
    sppStream.writeRawBytes( buff, 44 );

    //not really sure what this is about
    sppStream << (Q_UINT32)0xffff0000;
    sppStream << (Q_UINT32)0xffff00ff;
    sppStream << (Q_UINT32)0xffff00ff;
    sppStream << (Q_UINT32)0x000000ff;
    sppStream << (Q_UINT32)0x00000002;
    for (int i = 0; i < (296/4); i++) {
        sppStream << (Q_UINT32)0x00000000;
    }
    p = progressBar->progress();
    progressBar->setProgress( ++p );
    kapp->processEvents();

    // Add in the slide filenames
    QString filename;
    for ( unsigned int i = 0; i < slideInfos.count(); i++ ) {
        filename.sprintf("SPJP%04i.JPG", i+3);
        strncpy( buff, filename.ascii(), 63 );
        buff[64] = 0x00;
        sppStream.writeRawBytes( buff, 64 );
        p = progressBar->progress();
        progressBar->setProgress( ++p );
        kapp->processEvents();
    }

    // OK, now we need to fill to 16384 bytes
    // the logic is 16384 bytes total, lead in is 512 bytes, and there
    // is 64 bytes for each real slide
    for(unsigned int i = 0;  i < (16384-512-64*(slideInfos.count()))/4; i++) {
        sppStream << (Q_UINT32)0x00000000;
    }

    p = progressBar->progress();
    progressBar->setProgress( ++p );
    kapp->processEvents();

    sppFile.close();
    KIO::NetAccess::file_move( sppFile.name(), filenameStore, -1, true /*overwrite*/);
}