32 #include <QApplication>
34 #include <QTranslator>
39 #include <QPluginLoader>
40 #include <QMessageBox>
41 #include <QLibraryInfo>
44 #include <QFontDatabase>
75 #ifndef KLF_RESOURCES_ENVNAM
76 #define KLF_RESOURCES_ENVNAM "KLF_RESOURCES"
81 #define EXIT_ERR_FILEINPUT 100
82 #define EXIT_ERR_FILESAVE 101
83 #define EXIT_ERR_OPT 102
216 {
"gs", 1, NULL,
OPT_GS },
235 ftty = fopen(
"/dev/tty",
"w");
241 fprintf(ftty,
"Interrupt\n");
242 if (ftty != stderr) fprintf(stderr,
"*** Interrupt\n");
244 static time_t last_sigint_time = 0;
247 bool isInsisted = (curtime - last_sigint_time <= 2);
248 if (!isInsisted && qApp != NULL) {
250 last_sigint_time = curtime;
252 fprintf(ftty,
"Exiting\n");
253 if (ftty != stderr) fprintf(stderr,
"*** Exiting\n");
257 if (sig == SIGSEGV) {
258 fprintf(ftty,
"Segmentation Fault :-(\n");
259 if (ftty != stderr) fprintf(stderr,
"** Segmentation Fault :-( **\n");
264 signal(SIGSEGV, SIG_DFL);
298 fprintf(fout,
"D: %s\n", msg);
303 fprintf(fout,
"Warning: %s\n", msg);
310 #if defined Q_WS_WIN && defined KLF_DEBUG
311 # define SAFECOUNTER_NUM 10
313 if (qApp != NULL && qApp->inherits(
"QApplication")) {
314 static int safecounter = SAFECOUNTER_NUM;
315 if (safecounter-- >= 0) {
318 QString(
"KLatexFormula System Warning:\n%1")
322 if (safecounter == -1) {
324 QString(
"Shown %1 system warnings. Will stop displaying them.").arg(SAFECOUNTER_NUM));
327 if (safecounter < -2) safecounter = -2;
332 fprintf(fout,
"Error: %s\n", msg);
335 if (qApp != NULL && qApp->inherits(
"QApplication")) {
338 "[[KLF's Qt Message Handler: dialog text]]")
344 fprintf(fout,
"Fatal: %s\n", msg);
347 if (qApp != NULL && qApp->inherits(
"QApplication")) {
349 "[[KLF's Qt Message Handler: dialog title]]"),
350 QObject::tr(
"KLatexFormula System FATAL ERROR:\n%1",
351 "[[KLF's Qt Message Handler: dialog text]]")
357 fprintf(fout,
"?????: %s\n", msg);
380 foreach(
QString s, qttempfiles) {
404 if (latexinput != NULL && strlen(latexinput) != 0) {
407 if (input != NULL && strlen(input) != 0) {
410 if ( fname ==
"-" ) {
411 if ( ! f.
open(stdin, QIODevice::ReadOnly) ) {
412 qCritical(
"%s", qPrintable(
QObject::tr(
"Can't read standard input (!)")));
417 if ( ! f.
open(QIODevice::ReadOnly) ) {
418 qCritical(
"%s", qPrintable(
QObject::tr(
"Can't read input file `%1'.").arg(fname)));
428 if (!qApp->inherits(
"QApplication")) {
430 qPrintable(
QObject::tr(
"--paste-{clipboard|selection} requires interactive mode. Ignoring option.")));
452 char sindent[] =
" ";
453 uint nindent = indent*2;
454 if (nindent < strlen(sindent))
455 sindent[nindent] =
'\0';
460 for (k = 0; k < dchildren.size(); ++k) {
462 if (indent == 0 && dchildren[k] ==
"trolltech")
464 qDebug(
"%s%s/", sindent, qPrintable(dchildren[k]));
469 for (k = 0; k < fchildren.size(); ++k) {
470 qDebug(
"%s%s", sindent, qPrintable(fchildren[k]));
486 QString klf_resources = QString::null;
487 if (klf_resources_l.size() > 0) {
488 klf_resources = klf_resources_l[0].replace(rgx,
"");
491 bool klfsettings_can_import =
false;
495 #ifdef KLF_SHARE_RCCRESOURCES_DIR
502 if ( klf_resources.
isNull() ) {
505 rccfilepath = klf_resources;
510 for (QStringList::iterator it = rccfiles.begin(); it != rccfiles.end(); ++it) {
511 if ((*it).isEmpty()) {
513 it = rccfiles.erase(it, it+1);
514 for (j = 0; j < defaultrccpaths.size(); ++j) {
515 it = rccfiles.insert(it, defaultrccpaths[j]) + 1;
518 klfsettings_can_import =
true;
523 for (j = 0; j < rccfiles.size(); ++j) {
526 QDir dir(rccfiles[j]);
528 for (k = 0; k < files.size(); ++k) {
529 QString f = files[k].canonicalFilePath();
539 for (j = 0; j < rccfilesToLoad.size(); ++j) {
543 klfDbg(
"registered resource "<<addoninfo.
fpath()<<
".") ;
549 klfDbg(
"dump of :/ :" ) ;
573 klfDbg(
"base plugins dirs are "<<baseplugindirs) ;
580 for (j = 0; j < pluginList.size(); ++j) {
582 klfDbg(
"Testing plugin psinfo="<<psinfo<<
"\n\tTo our system: qtver="<<qVersion()
593 qDebug(
"Comparing resource datetime (%s) with installed plugin datetime (%s)",
594 qPrintable(resourceplugin_dt.
toString()), qPrintable(installedplugin_dt.
toString()));
596 installedplugin_dt.
isNull() || resourceplugin_dt.
isNull() ||
597 ( resourceplugin_dt > installedplugin_dt ) ) {
605 klfDbg(
"\tcopy "<<resfn<<
" to "<<locfn ) ;
608 qWarning(
"Unable to copy plugin '%s' to local directory!", qPrintable(pluginList[j]));
611 QFile::ReadUser|QFile::WriteUser|QFile::ExeUser|
612 QFile::ReadGroup|QFile::ExeGroup|QFile::ReadOther|QFile::ExeOther);
613 qDebug(
"Copied plugin %s to local directory %s.", qPrintable(resfn), qPrintable(locfn));
623 for (n = 0; n < baseplugindirs.size(); ++n) {
624 QString baseplugindir = baseplugindirs[n];
625 klfDbg(
"exploring base plugin directory "<<baseplugindir) ;
631 QDir pdir(baseplugindir);
636 for (i = 0; i < pdirlist.size(); ++i) {
637 klfDbg(
"maybe adding plugin dir"<<pdirlist[i]<<
"; klfver="<<pdirlist[i].mid(3) ) ;
640 pluginsdirsbaserel << pdirlist[i]+
"/";
644 pluginsdirsbaserel <<
"" ;
646 klfDbg(
"pluginsdirs="<<pluginsdirs ) ;
648 for (i = 0; i < pluginsdirs.size(); ++i) {
652 QDir thisplugdir(pluginsdirs[i]);
655 for (j = 0; j < plugins.size(); ++j) {
656 QString pluginfname = plugins[j];
657 QString pluginfnamebaserel = pluginsdirsbaserel[i]+plugins[j];
658 bool plugin_already_loaded =
false;
662 klfDbg(
"Rejecting loading of plugin "<<pluginfname<<
" in dir "<<pluginsdirs[i]
663 <<
"; already loaded." ) ;
664 plugin_already_loaded =
true;
668 if (plugin_already_loaded)
672 bool loaded = pluginLoader.
load();
674 klfDbg(
"QPluginLoader failed to load plugin "<<pluginpath<<
". Skipping.");
678 if (pluginInstObject == NULL) {
679 klfDbg(
"QPluginLoader failed to load plugin "<<pluginpath<<
" (object is NULL). Skipping.");
683 if (pluginInstance == NULL) {
684 klfDbg(
"QPluginLoader failed to load plugin "<<pluginpath<<
" (instance is NULL). Skipping.");
690 <<
") from file "<<pluginfnamebaserel);
699 bool keepPlugin =
true;
702 bool pluginRejected =
false;
705 klfDbg(
"Rejecting loading of plugin "<<nm<<
" in "<<pluginfname<<
"; already loaded." ) ;
707 pluginRejected =
true;
715 pluginInfo.
name = nm;
719 pluginInfo.
fname = pluginfnamebaserel;
720 pluginInfo.
fpath = pluginpath;
725 klfDbg(
"got plugin info. keeping plugin? "<<keepPlugin);
729 klfDbg(
"prepared a configaccess "<<c);
731 pluginInfo.
instance = pluginInstance;
732 qDebug(
"\tPlugin %s loaded and initialized.", qPrintable(nm));
736 delete pluginInstance;
738 qDebug(
"\tPlugin %s NOT loaded.", qPrintable(nm));
754 a->setOrganizationDomain(
QLatin1String(
"klatexformula.org"));
757 #ifdef KLF_LIBKLFTOOLS_STATIC
758 Q_INIT_RESOURCE(klftoolsres) ;
760 #ifdef KLF_LIBKLFAPP_STATIC
761 Q_INIT_RESOURCE(klfres) ;
771 qRegisterMetaType< QImage >(
"QImage");
772 qRegisterMetaType< KLFStyle >();
773 qRegisterMetaTypeStreamOperators< KLFStyle >(
"KLFStyle");
774 qRegisterMetaType< KLFLibEntry >();
775 qRegisterMetaTypeStreamOperators< KLFLibEntry >(
"KLFLibEntry");
776 qRegisterMetaType< KLFLibResourceEngine::KLFLibEntryWithId >();
777 qRegisterMetaTypeStreamOperators< KLFLibResourceEngine::KLFLibEntryWithId >
778 (
"KLFLibResourceEngine::KLFLibEntryWithId");
781 qRegisterMetaType< QItemSelection >(
"QItemSelection");
782 qRegisterMetaType< QItemSelectionModel::SelectionFlags >(
"QItemSelectionModel::SelectionFlags");
788 int main(
int argc,
char **argv)
804 klfDbg(
"about to parse options") ;
809 klfDbg(
"options parsed.") ;
813 qCritical(
"Error while parsing command-line arguments.");
814 qCritical(
"Use --help to display command-line help.");
822 const char * SUFFIX =
".klfdebug";
824 if (strncmp(fname+(strlen(fname)-strlen(SUFFIX)), SUFFIX, strlen(SUFFIX)) != 0) {
826 strcat(fname, SUFFIX);
834 "-------------------------------------------------\n"
835 " KLATEXFORMULA DEBUG OUTPUT\n"
836 "-------------------------------------------------\n"
865 for (k = 0; k < appFontsInfoList.size(); ++k) {
882 args <<
"--latexinput="+latexinput;
905 const struct {
char c;
int optval; } borderoffsets[] =
909 for (k = 0; borderoffsets[k].c != 0; ++k)
910 if (borderoffsets[k].optval != -1)
923 for (k = 0; k < qtargvlist.size(); ++k)
924 args <<
"--qtoption="+qtargvlist[k];
926 for (k = 0;
klf_args[k] != NULL; ++k)
927 args << QString::fromLocal8Bit(
klf_args[k]);
929 klfDbg(
"Prepared deamonized process' command-line: progexe="<<progexe<<
"; args="<<args) ;
935 fprintf(stderr,
"%s",
936 qPrintable(
QObject::tr(
"KLatexFormula Daemon Process successfully launched with pid %1\n")
940 qWarning()<<qPrintable(
QObject::tr(
"Failed to launch daemon process. Not daemonizing."));
945 #if defined(KLF_USE_DBUS)
964 if ( ! latexinput.
isNull() )
992 for (
int k = 0;
klf_args[k] != NULL; ++k)
1001 fprintf(stderr,
"KLatexFormula Version %s by Philippe Faist (c) 2005-2011\n"
1002 "Licensed under the terms of the GNU Public License GPL\n\n",
1003 KLF_VERSION_STRING);
1005 klfDbgT(
"$$About to load config$$");
1012 klfDbgT(
"$$About to main_load_extra_resources$$");
1015 klfDbgT(
"$$About to main_reload_translations$$");
1023 klfDbgT(
"$$About to create lib factories$$");
1031 klfDbgT(
"$$START LOADING$$" ) ;
1047 klfDbgT(
"$$END LOADING$$" ) ;
1049 #if defined(KLF_USE_DBUS)
1055 dbusconn.
registerObject(
"/MainWindow/KLFMainWin", &mainWin, QDBusConnection::ExportAllContents
1056 | QDBusConnection::ExportChildObjects);
1063 qWarning(
"%s", qPrintable(
QObject::tr(
"Can't use --output without any input")));
1066 if ( ! latexinput.
isNull() )
1082 qDebug(
"opt_preamble != NULL, gui mode, preamble=%s",
opt_preamble);
1115 for (
int k = 0;
klf_args[k] != NULL; ++k)
1120 app.setQuitOnLastWindowClosed(
false);
1123 klfDbg(
"application has quit; we have cleaned up main(), ready to return. code="<<r) ;
1164 if (!cmdlHelpFile.
open(QIODevice::ReadOnly)) {
1165 qWarning()<<
KLF_FUNC_NAME<<
": Can't access command-line-help file :/data/cmdl-help.txt!";
1174 fprintf(stderr,
"KLatexFormula Version %s by Philippe Faist (c) 2005-2011\n"
1175 "Licensed under the terms of the GNU Public License GPL\n\n",
1176 KLF_VERSION_STRING);
1179 qWarning()<<qPrintable(
QObject::tr(
"The option --daemonize can only be used in interactive mode."));
1183 for (
int kl = 0;
klf_args[kl] != NULL; ++kl)
1184 qWarning()<<qPrintable(
QObject::tr(
"[Non-Interactive Mode] Ignoring additional command-line argument: %1")
1200 input.
latex = latexinput;
1227 bgcolor.
setRgb(255, 255, 255, 0);
1266 if (klfoutput.
status != 0) {
1292 if (arg[0] ==
'&') {
1293 int fd = atoi(&arg[1]);
1295 fp = fdopen(fd,
"a");
1296 if (fd <= 0 || fp == NULL) {
1297 qWarning(
"Failed to open file descriptor %d.", fd);
1302 if (!strcmp(arg,
"-")) {
1306 fp = fopen(arg,
"a");
1308 qWarning(
"Failed to open file `%s' to print help message.", arg);
1319 return defaultvalue;
1321 QRegExp booltruerx =
QRegExp(
"^\\s*on|y(es)?|1|t(rue)?\\s*", Qt::CaseInsensitive);
1322 QRegExp boolfalserx =
QRegExp(
"^\\s*off|n(o)?|0|f(alse)?\\s*", Qt::CaseInsensitive);
1333 return defaultvalue;
1348 char klfcmdl_optstring[1024];
1354 klfcmdl_optstring[j++] =
':';
1357 klfcmdl_optstring[j] =
'\0';
1362 c = getopt_long(argc, argv, klfcmdl_optstring,
klfcmdl_optlist, NULL);
1367 if (optarg != NULL) {
1378 arg = strdup(optarg);
1401 qWarning(
"%s", qPrintable(
QObject::tr(
"--paste-clipboard requires interactive mode. Switching.")));
1409 qWarning(
"%s", qPrintable(
QObject::tr(
"--paste-selection requires interactive mode. Switching.")));
1439 #if defined(Q_WS_MAC)
1443 if ( !strncmp(arg,
"sn_", 3) )
1500 char *colonptr = strchr(arg,
':');
1501 if (colonptr != NULL) {
1535 qWarning(
"%s", qPrintable(
QObject::tr(
"--noeval is relevant only in interactive mode.")));
1539 qWarning(
"%s", qPrintable(
QObject::tr(
"--noeval may not be used when --output is present.")));
1543 qWarning(
"%s", qPrintable(
QObject::tr(
"Ignoring --format without --output.")));
QDBusReply< void > openFiles(const QStringList &fileNameList)
KLF_EXPORT void klf_reload_translations(QCoreApplication *app, const QString ¤tLocale)
#define KLF_RESOURCES_ENVNAM
QString locale
When setting this, don't forget to call QLocale::setDefault().
entryInfoList(const QStringList &nameFilters, Filters filters=NoFilter, SortFlags sort=NoSort)
QList< QColor > colorChooseWidgetRecent
toString(const QString &format)
QString homeConfigDirRCCResources
QMap< QString, QMap< QString, QVariant > > pluginConfig
QList< QColor > userColorList
char * opt_redirect_debug
#define klfDbgT(streamableItems)
void slotSetLatex(const QString &latex)
int opt_strdup_free_list_n
setFont(const QFont &font, const char *className=0)
int main(int argc, char **argv)
QDBusReply< void > evaluateAndSave(const QString &output, const QString &fmt)
startDetached(const QString &program, const QStringList &arguments, const QString &workingDirectory, qint64 *pid=0)
registerObject(const QString &path, QObject *object, RegisterOptions options=ExportAdaptors)
contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
setFileName(const QString &name)
#define klfDbg(streamableItems)
#define KLF_DEBUG_BLOCK(msg)
void slotSetFgColor(const QColor &fgcolor)
static bool __klf_parse_bool_arg(const char *arg, bool defaultvalue)
QDBusReply< void > setAlterSetting_s(int setting, const QString &value)
setPermissions(Permissions permissions)
void main_parse_options(int argc, char *argv[])
#define EXIT_ERR_FILEINPUT
join(const QString &separator)
QDBusReply< void > setAlterSetting_i(int setting, int value)
Utility class for plugins to access their configuration space in KLFConfig.
KLFPluginGenericInterface * instance
setRgb(int r, int g, int b, int a=255)
setNamedColor(const QString &name)
tr(const char *sourceText, const char *comment=0, int n=-1)
FILE * main_msg_get_fp_arg(const char *arg)
copy(const QString &newName)
KLF_EXPORT QString klfPrefixedPath(const QString &path, const QString &reference)
addLibraryPath(const QString &path)
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
replace(int position, int n, const QString &after)
void __klf_init_the_macpasteboardmime()
bool isCompatibleWithCurrentSystem() const
static bool klf_fp_tty_failed
setDesktopSettingsAware(bool on)
QString pluginName() const
QString pluginAuthor() const
number(long n, int base=10)
QList< QColor > colorChooseWidgetCustom
split(const QRegExp &sep, const QString &str, bool allowEmptyEntries=false)
fromLocal8Bit(const char *str, int size=-1)
fromUtf8(const char *str, int size=-1)
static void setColorList(const QList< QColor > &colorlist)
void dumpDir(const QDir &, int=0)
static struct @13 opt_error
addApplicationFont(const QString &fileName)
static struct option klfcmdl_optlist[]
entryList(const QStringList &nameFilters, Filters filters=NoFilter, SortFlags sort=NoSort)
void main_save(KLFBackend::klfOutput klfoutput, const QString &f_output, QString format)
void slotSetPreamble(const QString &preamble)
QString pluginDescription() const
KLF_EXPORT QString klf_share_dir_abspath()
VersionCompareWithPrefixGreaterThan(const QString &prefix)
void main_load_extra_resources()
void alterSetting(altersetting_which, int ivalue)
KLF_EXPORT QString arch()
QDBusReply< void > setInputData(const QString &key, const QString &svalue, int ivalue=-1)
QList< KLFPluginInfo > klf_plugins
bool opt_version_requested
struct KLFConfig::@3 BackendSettings
void slotSetBgColor(const QColor &bgcolor)
virtual void initialize(QApplication *app, KLFMainWin *mainWin, KLFPluginConfigAccess *config)=0
void klf_qt_message(QtMsgType type, const char *msg)
QString pluginTitle() const
QDBusReply< void > raiseWindow()
void refreshWindowSizes()
void detectMissingSettings()
mid(int position, int n=-1)
static FILE * klf_qt_msg_fp
fromBase64(const QByteArray &base64)
KLF_EXPORT QString osString(KLFSysInfo::Os sysos=os())
KLF_EXPORT int klfVersionCompare(const QString &v1, const QString &v2)
void slotEvaluateAndSave(const QString &output, const QString &format)
KLF_EXPORT QString klfFindTranslatedDataFile(const QString &baseFileName, const QString &extension)
QList< KLFAddOnInfo > klf_addons
critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
KLFPluginConfigAccess getPluginConfigAccess(const QString &name)
absoluteFilePath(const QString &fileName)
char * opt_strdup_free_list[64]
void main_setup_app(QCoreApplication *a)
static bool saveOutputToFile(const klfOutput &output, const QString &fileName, const QString &format=QString(), QString *errorString=NULL)
fromLatin1(const char *str, int size=-1)
bool opt_dbus_export_mainwin
warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
exists(const QString &name)
char * opt_version_format
bool klf_addons_canimport
filter(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
bool given as an int value
void slotSetMathMode(const QString &mathmode)
bool operator()(const QString &a, const QString &b)
exactMatch(const QString &str)
static klfOutput getLatexFormula(const klfInput &in, const klfSettings &settings)
struct KLFConfig::@5 Plugins
bool pluginDefaultLoadEnable() const
registerService(const QString &serviceName)
mkpath(const QString &dirPath)
void main_load_plugins(QApplication *app, KLFMainWin *mainWin)
QString main_get_input(char *input, char *latexinput, int paste)
QString homeConfigDirPlugins
static void setUserMaxColors(int maxcolors)