The applications path is different on all OS!
This is a way to find installed MiniScribus http://code.google.com/p/fop-miniscribus/
first get path from appication executable and after run its...
/* find cpl MiniScribus path or exe
*/
static inline QString getFOPDefaultExeName
() {
#if defined Q_WS_WIN
// Try to locate Miniscribus thanks to the qsetting
for (int i = 0; i < ppkonly.size(); ++i) {
const QString RealName
= ppkonly.
at(i
);
/* realpath */ ///////////qDebug() << "### soft " << RealName;
if (softs.value(RealName+"/FOP MiniScribus/path").toString().size() > 6 ) {
foppath = softs.value(RealName+"/FOP MiniScribus/path").toString();
foppath.append(softs.value(RealName+"/FOP MiniScribus/Bundlename").toString()+".exe");
return foppath;
}
}
/* win not having GPL Ghostscript ! */
foppath = "";
return foppath;
#endif
#if defined Q_WS_MAC
foppath = "/Applications/MiniScribus.app/Contents/MacOS/MiniScribus";
#endif
#if defined Q_WS_X11
foppath
= getGSLinuxPath
(QString("MiniScribus") );
#endif
return foppath;
/* forum http://www.qtcentre.org/forum/f-qt-programming-2/t-qsettings-read-only-avaiable-10254.html */
}
{
potential_paths.append("/usr/local/bin");
potential_paths.append("/sw/bin"); /* to use on mac as same */
potential_paths.append("/opt/bin");
process
->setReadChannelMode
(QProcess::MergedChannels);
env.
replaceInStrings(QRegExp("^PATH=(.*)", Qt
::CaseInsensitive),
"PATH=\\1;"+potential_paths.
join(";"));
process->setEnvironment(env);
if (!process->waitForFinished()) {
} else {
QString finder
= process
->readAll
().
trimmed();
if (finder.endsWith(apps,Qt::CaseInsensitive)) {
///////////// qDebug() << "### finder " << finder;
return finder;
} else {
}
}
}
/* find cpl MiniScribus path or exe
*/
static inline QString getFOPDefaultExeName()
{
QString exename;
QString foppath;
#if defined Q_WS_WIN
QFileInfo Pinfo;
// Try to locate Miniscribus thanks to the qsetting
QSettings softs("HKEY_LOCAL_MACHINE\\Software",QSettings::NativeFormat);
QStringList allsoftware = softs.childGroups();
QStringList ppkonly = allsoftware.filter(QRegExp("1-PPK-Schweiz"));
for (int i = 0; i < ppkonly.size(); ++i) {
const QString RealName = ppkonly.at(i); /* realpath */
///////////qDebug() << "### soft " << RealName;
if (softs.value(RealName+"/FOP MiniScribus/path").toString().size() > 6 ) {
foppath = softs.value(RealName+"/FOP MiniScribus/path").toString();
foppath.append(softs.value(RealName+"/FOP MiniScribus/Bundlename").toString()+".exe");
return foppath;
}
}
/* win not having GPL Ghostscript ! */
foppath = "";
return foppath;
#endif
#if defined Q_WS_MAC
foppath = "/Applications/MiniScribus.app/Contents/MacOS/MiniScribus";
#endif
#if defined Q_WS_X11
foppath = getGSLinuxPath(QString("MiniScribus") );
#endif
return foppath;
/* forum http://www.qtcentre.org/forum/f-qt-programming-2/t-qsettings-read-only-avaiable-10254.html */
}
extern inline QString getGSLinuxPath( QString apps = QString("gs") )
{
QStringList potential_paths;
potential_paths.append("/usr/local/bin");
potential_paths.append("/sw/bin"); /* to use on mac as same */
potential_paths.append("/opt/bin");
QProcess *process = new QProcess(NULL);
process->setReadChannelMode(QProcess::MergedChannels);
QStringList env = process->systemEnvironment();
env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;"+potential_paths.join(";"));
process->setEnvironment(env);
process->start( QString("which") , QStringList() << apps , QIODevice::ReadOnly );
if (!process->waitForFinished()) {
return QString();
} else {
QString finder = process->readAll().trimmed();
if (finder.endsWith(apps,Qt::CaseInsensitive)) {
///////////// qDebug() << "### finder " << finder;
return finder;
} else {
return QString();
}
}
}
To copy to clipboard, switch view to plain text mode
and here run appication + params to create a pdf from template...
connect(proc, SIGNAL(finished(int)),this, SLOT(RegisterPDFstream(int)));
proc->start(Generate_Command());
/* if finished get pdf stream and save on db mysql */
QString Invoice
::Generate_Command() {
if (Current_Faktura.barcode_value.size() < 1) {
QMessageBox::information(0, tr
("File Error"),tr
("Unable to read barcode nummer!"));
}
Result_fop_file_final
= QString("%1/%2_result_code.fop") .arg(FAKTURA_CACHEDIR)
.arg(Current_Faktura.barcode_value);
QFile f
( Result_fop_file_final
);
/* old pdf file */ if (f.exists()) {
f.remove();
}
registro->FillOnFile(FopWorkingActual.absoluteFilePath(),textEdit->toPlainText(),0,Result_fop_file_final);
QFile f2
( PRINTONFILEFAKE
);
/* old pdf file */ if (f2.exists()) {
f2.remove();
}
#if defined Q_WS_WIN
cmd.append("\""+FopAppsFullPath+"\"");
cmd.append("-pdf");
cmd.append("\""+PRINTONFILEFAKE+"\"");
cmd.append("\""+Result_fop_file_final+"\"");
#else
cmd.append(FopAppsFullPath);
cmd.append("-pdf");
cmd.append(PRINTONFILEFAKE);
cmd.append(Result_fop_file_final);
#endif
QString makepnggreycommand
= cmd.
join(" ");
return makepnggreycommand;
}
proc = new QProcess(this); /* */
connect(proc, SIGNAL(finished(int)),this, SLOT(RegisterPDFstream(int)));
proc->start(Generate_Command());
/* if finished get pdf stream and save on db mysql */
QString Invoice::Generate_Command()
{
if (Current_Faktura.barcode_value.size() < 1) {
QMessageBox::information(0, tr("File Error"),tr("Unable to read barcode nummer!"));
return QString();
}
Result_fop_file_final = QString("%1/%2_result_code.fop")
.arg(FAKTURA_CACHEDIR)
.arg(Current_Faktura.barcode_value);
QFile f( Result_fop_file_final ); /* old pdf file */
if (f.exists()) {
f.remove();
}
registro->FillOnFile(FopWorkingActual.absoluteFilePath(),textEdit->toPlainText(),0,Result_fop_file_final);
QFile f2( PRINTONFILEFAKE ); /* old pdf file */
if (f2.exists()) {
f2.remove();
}
QStringList cmd;
#if defined Q_WS_WIN
cmd.append("\""+FopAppsFullPath+"\"");
cmd.append("-pdf");
cmd.append("\""+PRINTONFILEFAKE+"\"");
cmd.append("\""+Result_fop_file_final+"\"");
#else
cmd.append(FopAppsFullPath);
cmd.append("-pdf");
cmd.append(PRINTONFILEFAKE);
cmd.append(Result_fop_file_final);
#endif
QString makepnggreycommand = cmd.join(" ");
return makepnggreycommand;
}
To copy to clipboard, switch view to plain text mode
Bookmarks