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; } }
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; }
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; }
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; }
const KstTimezones::ZoneMap KstTimezones::allZones() { // Have we already done all the hard work? If not, create the cache. if (m_zones) return *m_zones; m_zones = new ZoneMap(); // Go read the database. // // On Windows, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones // is the place to look. The TZI binary value is the TIME_ZONE_INFORMATION structure. // // For Unix its all easy except knowing where to look. Try the LSB location first. QFile f; m_zoneinfoDir = "/usr/share/zoneinfo"; f.setName(m_zoneinfoDir + "/zone.tab"); if (!f.open(IO_ReadOnly)) { m_zoneinfoDir = "/usr/lib/zoneinfo"; f.setName(m_zoneinfoDir + "/zone.tab"); if (!f.open(IO_ReadOnly)) { m_zoneinfoDir = ::getenv("TZDIR"); f.setName(m_zoneinfoDir + "/zone.tab"); if (m_zoneinfoDir.isEmpty() || !f.open(IO_ReadOnly)) { // Solaris support. Synthesise something that looks like a zone.tab. // // /bin/grep -h ^Zone /usr/share/lib/zoneinfo/src/* | /bin/awk '{print "??\t+9999+99999\t" $2}' // // where the country code is set to "??" and the lattitude/longitude // values are dummies. m_zoneinfoDir = "/usr/share/lib/zoneinfo"; KTempFile temp; KShellProcess reader; reader << "/bin/grep" << "-h" << "^Zone" << m_zoneinfoDir << "/src/*" << temp.name() << "|" << "/bin/awk" << "'{print \"??\\t+9999+99999\\t\" $2}'"; // Note the use of blocking here...it is a trivial amount of data! temp.close(); reader.start(KProcess::Block); f.setName(temp.name()); if (!temp.status() || !f.open(IO_ReadOnly)) { return *m_zones; } } } } // Parse the zone.tab. QTextStream str(&f); QRegExp lineSeparator("[ \t]"); QRegExp ordinateSeparator("[+-]"); KSharedPtr<KstTimezoneSource> db(new KstTimezoneSource(m_zoneinfoDir)); while (!str.atEnd()) { QString line = str.readLine(); if (line.isEmpty() || '#' == line[0]) continue; QStringList tokens = KStringHandler::perlSplit(lineSeparator, line, 4); if (tokens.count() < 3) { continue; } // Got three tokens. Now check for two ordinates plus first one is "". QStringList ordinates = KStringHandler::perlSplit(ordinateSeparator, tokens[1], 2); if (ordinates.count() < 2) { continue; } float latitude = convertCoordinate(ordinates[1]); float longitude = convertCoordinate(ordinates[2]); // Add entry to list. if (tokens[0] == "??") tokens[0] = ""; KstTimezone *timezone = new KstTimezone(db, tokens[2], tokens[0], latitude, longitude, tokens[3]); add(timezone); } f.close(); return *m_zones; }
KDE_EXPORT void kimgio_eps_read(QImageIO *image) { kdDebug(399) << "kimgio EPS: starting..." << endl; FILE *ghostfd; int x1, y1, x2, y2; // QTime dt; // dt.start(); QString cmdBuf; QString tmp; QIODevice *io = image->ioDevice(); Q_UINT32 ps_offset, ps_size; // find start of PostScript code if(!seekToCodeStart(io, ps_offset, ps_size)) return; // find bounding box if(!bbox(io, &x1, &y1, &x2, &y2)) { kdError(399) << "kimgio EPS: no bounding box found!" << endl; return; } KTempFile tmpFile; tmpFile.setAutoDelete(true); if(tmpFile.status() != 0) { kdError(399) << "kimgio EPS: no temp file!" << endl; return; } tmpFile.close(); // Close the file, we just want the filename // x1, y1 -> translation // x2, y2 -> new size x2 -= x1; y2 -= y1; // kdDebug(399) << "origin point: " << x1 << "," << y1 << " size:" << x2 << "," << y2 << endl; double xScale = 1.0; double yScale = 1.0; bool needsScaling = false; int wantedWidth = x2; int wantedHeight = y2; if(image->parameters()) { // Size forced by the caller QStringList params = QStringList::split(':', image->parameters()); if(params.count() >= 2 && x2 != 0.0 && y2 != 0.0) { wantedWidth = params[0].toInt(); xScale = (double)wantedWidth / (double)x2; wantedHeight = params[1].toInt(); yScale = (double)wantedHeight / (double)y2; // kdDebug(399) << "wanted size:" << wantedWidth << "x" << wantedHeight << endl; // kdDebug(399) << "scaling:" << xScale << "," << yScale << endl; needsScaling = true; } } // create GS command line cmdBuf = "gs -sOutputFile="; cmdBuf += tmpFile.name(); cmdBuf += " -q -g"; tmp.setNum(wantedWidth); cmdBuf += tmp; tmp.setNum(wantedHeight); cmdBuf += "x"; cmdBuf += tmp; cmdBuf += " -dSAFER -dPARANOIDSAFER -dNOPAUSE -sDEVICE=ppm -c " "0 0 moveto " "1000 0 lineto " "1000 1000 lineto " "0 1000 lineto " "1 1 254 255 div setrgbcolor fill " "0 0 0 setrgbcolor - -c showpage quit"; // run ghostview ghostfd = popen(QFile::encodeName(cmdBuf), "w"); if(ghostfd == 0) { kdError(399) << "kimgio EPS: no GhostScript?" << endl; return; } fprintf(ghostfd, "\n%d %d translate\n", -qRound(x1 * xScale), -qRound(y1 * yScale)); if(needsScaling) fprintf(ghostfd, "%g %g scale\n", xScale, yScale); // write image to gs io->reset(); // Go back to start of file to give all the file to GhostScript if(ps_offset > 0L) // We have an offset io->at(ps_offset); QByteArray buffer(io->readAll()); // If we have no MS-DOS EPS file or if the size seems wrong, then choose the buffer size if(ps_size <= 0L || ps_size > buffer.size()) ps_size = buffer.size(); fwrite(buffer.data(), sizeof(char), ps_size, ghostfd); buffer.resize(0); pclose(ghostfd); // load image QImage myimage; if(myimage.load(tmpFile.name())) { image->setImage(myimage); image->setStatus(0); kdDebug(399) << "kimgio EPS: success!" << endl; } else kdError(399) << "kimgio EPS: no image!" << endl; // kdDebug(399) << "Loading EPS took " << (float)(dt.elapsed()) / 1000 << " seconds" << endl; return; }
// Helper method for scaleWithGhostScript. Returns 1 on success, 0 on error, -1 if nothing generated // (in which case another 'output device' can be tried) int KoPictureEps::tryScaleWithGhostScript(QImage &image, const QSize& size, const int resolutionx, const int resolutiony, const char* device ) // Based on the code of the file kdelibs/kimgio/eps.cpp { kdDebug(30003) << "Sampling with GhostScript, using device \"" << device << "\" (in KoPictureEps::tryScaleWithGhostScript)" << endl; KTempFile tmpFile; tmpFile.setAutoDelete(true); if ( tmpFile.status() ) { kdError(30003) << "No KTempFile! (in KoPictureEps::tryScaleWithGhostScript)" << endl; return 0; // error } const int wantedWidth = size.width(); const int wantedHeight = size.height(); const double xScale = double(size.width()) / double(m_boundingBox.width()); const double yScale = double(size.height()) / double(m_boundingBox.height()); // create GS command line QString cmdBuf ( "gs -sOutputFile=" ); cmdBuf += KProcess::quote(tmpFile.name()); cmdBuf += " -q -g"; cmdBuf += QString::number( wantedWidth ); cmdBuf += "x"; cmdBuf += QString::number( wantedHeight ); if ( ( resolutionx > 0) && ( resolutiony > 0) ) { #if 0 // Do not play with resolution for now. // It brings more problems at print than solutions cmdBuf += " -r"; cmdBuf += QString::number( resolutionx ); cmdBuf += "x"; cmdBuf += QString::number( resolutiony ); #endif } cmdBuf += " -dSAFER -dPARANOIDSAFER -dNOPAUSE -sDEVICE="; cmdBuf += device; //cmdBuf += " -c 255 255 255 setrgbcolor fill 0 0 0 setrgbcolor"; cmdBuf += " -"; cmdBuf += " -c showpage quit"; // run ghostview FILE* ghostfd = popen (QFile::encodeName(cmdBuf), "w"); if ( ghostfd == 0 ) { kdError(30003) << "No connection to GhostScript (in KoPictureEps::tryScaleWithGhostScript)" << endl; return 0; // error } // The translation is needed as GhostScript (7.07) cannot handle negative values in the bounding box otherwise. fprintf (ghostfd, "\n%d %d translate\n", -qRound(m_boundingBox.left()*xScale), -qRound(m_boundingBox.top()*yScale)); fprintf (ghostfd, "%g %g scale\n", xScale, yScale); // write image to gs fwrite( m_rawData.data() + m_psStreamStart, sizeof(char), m_psStreamLength, ghostfd); pclose ( ghostfd ); // load image if( !image.load (tmpFile.name()) ) { // It failed - maybe the device isn't supported by gs return -1; } if ( image.size() != size ) // this can happen due to rounding problems { //kdDebug(30003) << "fixing size to " << size.width() << "x" << size.height() // << " (was " << image.width() << "x" << image.height() << ")" << endl; image = image.scale( size ); // hmm, smoothScale instead? } kdDebug(30003) << "Image parameters: " << image.width() << "x" << image.height() << "x" << image.depth() << endl; return 1; // success }