00001 /*************************************************************************** 00002 * file klfmain.h 00003 * This file is part of the KLatexFormula Project. 00004 * Copyright (C) 2009 by Philippe Faist 00005 * philippe.faist at bluewin.ch 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program; if not, write to the * 00019 * Free Software Foundation, Inc., * 00020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 ***************************************************************************/ 00022 /* $Id: klfmain.h 574 2010-11-30 20:24:25Z philippe $ */ 00023 00024 #ifndef KLFMAIN_H 00025 #define KLFMAIN_H 00026 00027 #include <QCoreApplication> 00028 #include <QString> 00029 #include <QList> 00030 #include <QMap> 00031 #include <QStringList> 00032 #include <QDataStream> 00033 #include <QTranslator> 00034 #include <QDir> 00035 00036 #include <klfdefs.h> 00037 00038 00039 00040 00041 // SOME DEFINITIONS 00042 00043 #if defined(Q_WS_WIN) 00044 #define KLF_DLL_EXT_LIST (QStringList()<<"*.dll") 00045 #elif defined(Q_WS_MAC) 00046 #define KLF_DLL_EXT_LIST (QStringList()<<"*.so"<<"*.dylib") 00047 #else 00048 #define KLF_DLL_EXT_LIST (QStringList()<<"*.so") 00049 #endif 00050 00051 00052 00053 // SOME DECLARATIONS FOR ADD-ONS 00054 00055 class KLF_EXPORT KLFAddOnInfo 00056 { 00057 public: 00060 KLFAddOnInfo(QString rccfpath, bool isFresh = false); 00061 00063 KLFAddOnInfo(const KLFAddOnInfo& o); 00064 00065 struct KLF_EXPORT PluginSysInfo { 00067 QString dir; 00070 QString qtminversion; 00073 QString klfminversion; 00075 QString os; 00077 QString arch; 00078 00079 bool isCompatibleWithCurrentSystem() const; 00080 }; 00081 00082 ~KLFAddOnInfo(); 00083 00085 QString dir() { return d->dir; } 00087 QString fname() { return d->fname; }; 00089 QString fpath() { return d->fpath; } 00091 bool islocal() { return d->islocal; } 00092 00094 QString title() { return d->title; } 00096 QString author() { return d->author; } 00098 QString description() { return d->description; } 00100 QString klfminversion() { return d->klfminversion; } 00101 00103 QString rccmountroot() { return d->rccmountroot; } 00104 00113 QStringList pluginList() const { return d->pluginList; } 00114 00115 PluginSysInfo pluginSysInfo(const QString& plugin) const { return d->plugins[plugin]; } 00116 00117 QString pluginLocalSubDirName(const QString& plugin) const 00118 { 00119 if ( ! d->plugins[plugin].klfminversion.isEmpty() ) 00120 return QString("klf%1").arg(d->plugins[plugin].klfminversion); 00121 return QString("."); 00122 } 00123 00130 QStringList localPluginList() const; 00131 00132 00135 QStringList translations() { return d->translations; } 00136 00140 bool isfresh() { return d->isfresh; } 00141 00142 private: 00143 00145 struct Private { 00146 int ref; // number of times this data structure is referenced 00147 00148 QString dir; 00149 QString fname; 00150 QString fpath; 00151 bool islocal; 00152 00153 QString title; 00154 QString author; 00155 QString description; 00156 QString klfminversion; 00157 00158 QString rccmountroot; 00159 00160 QStringList pluginList; 00161 QMap<QString,PluginSysInfo> plugins; 00162 00163 QStringList translations; 00164 00165 bool isfresh; 00166 }; 00167 00168 Private *d; 00169 00170 void initPlugins(); 00171 }; 00172 00173 KLF_EXPORT extern QList<KLFAddOnInfo> klf_addons; 00174 KLF_EXPORT extern bool klf_addons_canimport; 00175 00176 KLF_EXPORT QDebug& operator<<(QDebug& str, const KLFAddOnInfo::PluginSysInfo& i); 00177 00178 00179 00180 // SOME DEFINITIONS FOR PLUGINS 00181 00182 class KLFPluginGenericInterface; 00183 00184 struct KLFPluginInfo 00185 { 00186 QString name; 00187 QString author; 00188 QString title; 00189 QString description; 00190 00191 QString fpath; 00192 QString fname; 00193 00194 KLFPluginGenericInterface * instance; 00195 }; 00196 00197 00198 KLF_EXPORT extern QList<KLFPluginInfo> klf_plugins; 00199 00200 00201 00202 00203 00204 00212 struct KLF_EXPORT KLFTranslationInfo 00213 { 00214 KLFTranslationInfo() : hasnicetranslatedname(false) { } 00215 00216 QString localename; 00217 QString translatedname; 00221 bool hasnicetranslatedname; 00222 }; 00223 00225 KLF_EXPORT extern QList<KLFTranslationInfo> klf_avail_translations; 00226 00228 KLF_EXPORT extern QList<QTranslator*> klf_translators; 00229 00230 00239 class KLF_EXPORT KLFI18nFile 00240 { 00241 public: 00242 QString fpath; 00244 QString name; 00246 QString locale; 00248 int locale_specificity; 00249 00251 KLFI18nFile(QString filepath); 00252 }; 00253 00254 00255 00256 KLF_EXPORT void klf_add_avail_translation(KLFI18nFile i18nfile); 00257 00258 00260 KLF_EXPORT void klf_reload_translations(QCoreApplication *app, const QString& currentlocale); 00261 00262 00263 00264 // eg. baseFileName="cmdl-help" extension=".txt" will look for 00265 // "cmdl-help_fr_CH.txt", "cmdl-help_fr.txt", "cmdl-help.txt" assuming current locale is "fr_CH" 00266 KLF_EXPORT QString klfFindTranslatedDataFile(const QString& baseFileName, const QString& extension); 00267 00268 00269 00270 00280 #define KLF_DATA_STREAM_APP_VERSION "3.2" 00281 // --- don't forget to update below too! --- 00282 00284 #define KLF_DATA_STREAM_APP_VERSION_MAJ 3 00285 00286 #define KLF_DATA_STREAM_APP_VERSION_MIN 2 00287 00288 00293 inline QString klfDataStreamAppVersion(const QDataStream& d) 00294 { return d.device()->property("klfDataStreamAppVersion").toString(); } 00295 00296 00304 KLF_EXPORT void klfDataStreamWriteHeader(QDataStream& stream, const QString headermagic); 00305 00308 KLF_EXPORT bool klfDataStreamReadHeader(QDataStream& stream, const QStringList possibleHeaders, 00309 QString * readHeader = NULL, QString * readCompatKLFVersion = NULL) ; 00310 00311 00312 00313 #endif