kexi
kexitemplateloader.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexitemplateloader.h"
00021
00022 #include <kstandarddirs.h>
00023 #include <kglobal.h>
00024 #include <klocale.h>
00025 #include <kconfig.h>
00026 #include <kdebug.h>
00027 #include <kiconloader.h>
00028 #include <kapplication.h>
00029
00030 #include <qdir.h>
00031
00032
00033 KexiTemplateInfo::List KexiTemplateLoader::loadListInfo()
00034 {
00035 KexiTemplateInfo::List list;
00036 const QString subdir = QString(kapp->instanceName()) + "/templates";
00037 QString lang( KGlobal::locale()->language() );
00038 QStringList dirs( kapp->dirs()->findDirs("data", subdir) );
00039 while (true) {
00040 foreach( QStringList::ConstIterator, it, dirs) {
00041 QDir dir((*it)+lang);
00042 if (!dir.exists())
00043 continue;
00044 if (!dir.isReadable()) {
00045 kdWarning() << "KexiTemplateLoader::loadListInfo() \"" << dir.absPath() << "\" not readable!" << endl;
00046 continue;
00047 }
00048 const QStringList templateDirs( dir.entryList(QDir::Dirs, QDir::Name) );
00049 const QString absDirPath( dir.absPath() + '/' );
00050 foreach(QStringList::ConstIterator, templateIt, templateDirs) {
00051 if ((*templateIt)=="." || (*templateIt==".."))
00052 continue;
00053 KexiTemplateInfo info = KexiTemplateLoader::loadInfo( absDirPath + *templateIt );
00054 if (!info.name.isEmpty())
00055 list.append( info );
00056 }
00057 }
00058 if (lang != "en" && list.isEmpty())
00059 lang = "en";
00060 else
00061 break;
00062 }
00063 return list;
00064 }
00065
00066
00067 KexiTemplateInfo KexiTemplateLoader::loadInfo(const QString& directory)
00068 {
00069 QDir dir(directory);
00070 if (!dir.isReadable()) {
00071 kdWarning() << "KexiTemplateLoader::loadInfo() \""
00072 << directory << "\" not readable!" << endl;
00073 return KexiTemplateInfo();
00074 }
00075 if (!QFileInfo(directory+"/info.txt").isReadable())
00076 return KexiTemplateInfo();
00077 KConfig infoTxt(directory+"/info.txt", true, false);
00078 KexiTemplateInfo info;
00079 info.name = infoTxt.readEntry("Name");
00080 if (info.name.isEmpty()) {
00081 kdWarning() << "KexiTemplateLoader::loadInfo() \"" << (directory+"/info.txt") << "\" contains no \"name\" field" << endl;
00082 return KexiTemplateInfo();
00083 }
00084 const QStringList templateFiles( dir.entryList("*.kexi", QDir::Files|QDir::Readable, QDir::Name) );
00085 if (templateFiles.isEmpty()) {
00086 kdWarning() << "KexiTemplateLoader::loadInfo() no readable .kexi template file found in \"" << directory << "\"" << endl;
00087 return KexiTemplateInfo();
00088 }
00089 info.filename = directory+"/"+templateFiles.first();
00090 info.description = infoTxt.readEntry("Description");
00091 const QString iconFileName( infoTxt.readEntry("Icon") );
00092 if (!iconFileName.isEmpty())
00093 info.icon = QPixmap(directory+'/'+iconFileName);
00094 if (info.icon.isNull())
00095 info.icon = DesktopIcon("kexiproject_sqlite");
00096 QStringList autoopenObjectsString = infoTxt.readListEntry("AutoOpenObjects");
00097 foreach( QStringList::ConstIterator, it, autoopenObjectsString) {
00098 KexiProjectData::ObjectInfo autoopenObject;
00099 QStringList autoopenObjectNameSplitted( QStringList::split(':', *it) );
00100 if (autoopenObjectNameSplitted.count()>1) {
00101 autoopenObject["type"] = autoopenObjectNameSplitted[0];
00102 autoopenObject["name"] = autoopenObjectNameSplitted[1];
00103 }
00104 else {
00105 autoopenObject["type"] = "table";
00106 autoopenObject["name"] = autoopenObjectNameSplitted[0];
00107 }
00108 autoopenObject["action"] = "open";
00109 info.autoopenObjects.append( autoopenObject );
00110 }
00111 return info;
00112 }
|