Ejemplo n.º 1
0
void KPrHtmlExport::exportHtml(const KPrHtmlExport::Parameter &parameters)
{
    m_parameters = parameters;

    // Create a temporary dir
    KTempDir tmpDir;
    m_tmpDirPath = tmpDir.name();
    tmpDir.setAutoRemove(false);
    extractStyle();
    exportImageToTmpDir();
    generateHtml();
    generateToc();
    copyFromTmpToDest();
}
Ejemplo n.º 2
0
KUrl KPrHtmlExport::exportPreview(const Parameter &parameters)
{
    m_parameters = parameters;

    // Create a temporary dir
    KTempDir tmpDir;
    tmpDir.setAutoRemove(false);
    m_tmpDirPath = tmpDir.name();
    extractStyle();
    exportImageToTmpDir();
    generateHtml();

    KUrl previewUrl;
    previewUrl.setPath(tmpDir.name());
    previewUrl.addPath("slide0.html");
    return previewUrl;
}
Ejemplo n.º 3
0
bool BasketThumbCreator::create(const QString &path, int /*width*/, int /*height*/, QImage &image)
{
	// Create the temporar folder:
	KTempDir tempDir;
	tempDir.setAutoRemove(true);
	QString tempFolder = tempDir.name();
	QDir dir;
	dir.mkdir(tempFolder);
	const unsigned long int BUFFER_SIZE = 1024;

	QFile file(path);
	if (file.open(QIODevice::ReadOnly)) {
		QTextStream stream(&file);
		stream.setCodec(QTextCodec::codecForName("UTF-8"));
		QString line = stream.readLine();
		if (line != "BasKetNP:archive" && line != "BasKetNP:template") {
			file.close();
			return false;
		}
		while (!stream.atEnd()) {
			// Get Key/Value Pair From the Line to Read:
			line = stream.readLine();
			int index = line.indexOf(':');
			QString key;
			QString value;
			if (index >= 0) {
				key = line.left(index);
				value = line.right(line.length() - index - 1);
			} else {
				key = line;
				value = "";
			}
			if (key == "preview*") {
				bool ok;
				ulong size = value.toULong(&ok);
				if (!ok) {
					file.close();
					return false;
				}
				// Get the preview file:
				QFile previewFile(tempFolder + "preview.png");
				if (previewFile.open(QIODevice::WriteOnly)) {
					char *buffer = new char[BUFFER_SIZE];
					long int sizeRead;
					while ((sizeRead = file.read(buffer, qMin(BUFFER_SIZE, size))) > 0) {
						previewFile.write(buffer, sizeRead);
						size -= sizeRead;
					}
					previewFile.close();
					delete buffer;
					image = QImage(tempFolder + "preview.png");
					file.close();
					return true;
				}
			} else if (key.endsWith("*")) {
				// We do not know what it is, but we should read the embedded-file in order to discard it:
				bool ok;
				ulong size = value.toULong(&ok);
				if (!ok) {
					file.close();
					return false;
				}
				// Get the archive file:
				char *buffer = new char[BUFFER_SIZE];
				long int sizeRead;
				while ((sizeRead = file.read(buffer, qMin(BUFFER_SIZE, size))) > 0) {
					size -= sizeRead;
				}
				delete buffer;
			}
		}
		file.close();
	}
	return false;
}
Ejemplo n.º 4
0
bool CFontThumbnail::create(const QString &path, int width, int height, QImage &img)
{
    QString  realPath(path);
    KTempDir *tempDir = 0;

    KFI_DBUG << "Create font thumbnail for:" << path << endl;

    // Is this a appliaction/vnd.kde.fontspackage file? If so, extract 1 scalable font...
    if(Misc::isPackage(path) || "application/zip"==KMimeType::findByFileContent(path)->name())
    {
        KZip zip(path);

        if(zip.open(QIODevice::ReadOnly))
        {
            const KArchiveDirectory *zipDir=zip.directory();

            if(zipDir)
            {
                QStringList fonts(zipDir->entries());

                if(fonts.count())
                {
                    QStringList::ConstIterator it(fonts.begin()),
                                               end(fonts.end());

                    for(; it!=end; ++it)
                    {
                        const KArchiveEntry *entry=zipDir->entry(*it);

                        if(entry && entry->isFile())
                        {
                            delete tempDir;
                            tempDir=new KTempDir(KStandardDirs::locateLocal("tmp", KFI_TMP_DIR_PREFIX));
                            tempDir->setAutoRemove(true);

                            ((KArchiveFile *)entry)->copyTo(tempDir->name());

                            QString mime(KMimeType::findByPath(tempDir->name()+entry->name())->name());

                            if(mime=="application/x-font-ttf" || mime=="application/x-font-otf" ||
                               mime=="application/x-font-type1")
                            {
                                realPath=tempDir->name()+entry->name();
                                break;
                            }
                            else
                                ::unlink(QFile::encodeName(tempDir->name()+entry->name()).data());
                        }
                    }
                }
            }
        }
    }

    QColor bgnd(Qt::black);

    bgnd.setAlpha(0);
    img=itsEngine.draw(realPath, KFI_NO_STYLE_INFO, 0, QApplication::palette().text().color(), bgnd, width, height, true);

    delete tempDir;
    return !img.isNull();
}
Ejemplo n.º 5
0
Archivo: package.cpp Proyecto: KDE/silk
Package::Package(QString path, QObject* parent)
    : QObject(parent),
    m_metadata(new MetaData)
{
    /*
    A package roughly looks like this:

    examplepackage/
    |-- actions
    |   |-- silk-webapp-silk-commitlog.desktop
    |   |-- silk-webapp-silk-sidebar.desktop
    |   |-- silk-webapp-silk-sourcetree.desktop
    |   `-- silk-webapp-silk-urltrigger.desktop
    |-- plugin.desktop
    |-- scripts
    |   `-- togglesidebar.js
    `-- webapp.desktop


    */
    //m_metadata->pluginName = QString("silk");
    QString installedPath = findPackage(path);
    if (!installedPath.isEmpty()) {
        m_root = installedPath;
        m_metadataFile = m_root.path() + "/" + "metadata.desktop";
        readMetadata();
        readDir();
        //kDebug() << "installed, but valid?" << isValid();
        return;
    }

    QDir _d(path);
    if (_d.isRelative()) {
        path = QDir::currentPath() + "/" + path;
    }
    
    KUrl _dir(path);

    if (path.isEmpty()) {
        kDebug() << "Empty package structure";
    } else if (path.endsWith(".selkie")) {
        //kDebug() << "Package file:" << path;
        //QString unpackPath = "/tmp/unpacked/";

        KTempDir tmp;
        tmp.setAutoRemove(false);
        //kDebug() << "TempDir:" << tmp.name();
        QString unpackPath = tmp.name();
        importPackage(path, unpackPath);
        m_root = KUrl(unpackPath);
        m_metadataFile = unpackPath + "/" + "metadata.desktop";
        readMetadata();
        readDir();
    } else if (_dir.isValid()) {
        //kDebug() << "Reading dir" << _dir;
        m_root = _dir;
        m_metadataFile = m_root.path() + "/" + "metadata.desktop";
        readMetadata();
        readDir();
    }
    //show();
}