20#include "kexitemplateloader.h"
22#include <kstandarddirs.h>
27#include <kiconloader.h>
28#include <tdeapplication.h>
33KexiTemplateInfo::List KexiTemplateLoader::loadListInfo()
35 KexiTemplateInfo::List list;
36 const TQString subdir = TQString(kapp->instanceName()) +
"/templates";
37 TQString lang( TDEGlobal::locale()->language() );
38 TQStringList dirs( kapp->dirs()->findDirs(
"data", subdir) );
40 foreach( TQStringList::ConstIterator, it, dirs) {
41 TQDir dir((*it)+lang);
44 if (!dir.isReadable()) {
45 kdWarning() <<
"KexiTemplateLoader::loadListInfo() \"" << dir.absPath() <<
"\" not readable!" << endl;
48 const TQStringList templateDirs( dir.entryList(TQDir::Dirs, TQDir::Name) );
49 const TQString absDirPath( dir.absPath() +
'/' );
50 foreach(TQStringList::ConstIterator, templateIt, templateDirs) {
51 if ((*templateIt)==
"." || (*templateIt==
".."))
53 KexiTemplateInfo info = KexiTemplateLoader::loadInfo( absDirPath + *templateIt );
54 if (!info.name.isEmpty())
58 if (lang !=
"en" && list.isEmpty())
70 if (!dir.isReadable()) {
71 kdWarning() <<
"KexiTemplateLoader::loadInfo() \""
72 << directory <<
"\" not readable!" << endl;
75 if (!TQFileInfo(directory+
"/info.txt").isReadable())
77 TDEConfig infoTxt(directory+
"/info.txt",
true,
false);
79 info.name = infoTxt.readEntry(
"Name");
80 if (info.name.isEmpty()) {
81 kdWarning() <<
"KexiTemplateLoader::loadInfo() \"" << (directory+
"/info.txt") <<
"\" contains no \"name\" field" << endl;
84 const TQStringList templateFiles( dir.entryList(
"*.kexi", TQDir::Files|TQDir::Readable, TQDir::Name) );
85 if (templateFiles.isEmpty()) {
86 kdWarning() <<
"KexiTemplateLoader::loadInfo() no readable .kexi template file found in \"" << directory <<
"\"" << endl;
89 info.filename = directory+
"/"+templateFiles.first();
90 info.description = infoTxt.readEntry(
"Description");
91 const TQString iconFileName( infoTxt.readEntry(
"Icon") );
92 if (!iconFileName.isEmpty())
93 info.icon = TQPixmap(directory+
'/'+iconFileName);
94 if (info.icon.isNull())
95 info.icon = DesktopIcon(
"kexiproject_sqlite");
96 TQStringList autoopenObjectsString = infoTxt.readListEntry(
"AutoOpenObjects");
97 foreach( TQStringList::ConstIterator, it, autoopenObjectsString) {
98 KexiProjectData::ObjectInfo autoopenObject;
99 TQStringList autoopenObjectNameSplitted( TQStringList::split(
':', *it) );
100 if (autoopenObjectNameSplitted.count()>1) {
101 autoopenObject[
"type"] = autoopenObjectNameSplitted[0];
102 autoopenObject[
"name"] = autoopenObjectNameSplitted[1];
105 autoopenObject[
"type"] =
"table";
106 autoopenObject[
"name"] = autoopenObjectNameSplitted[0];
108 autoopenObject[
"action"] =
"open";
109 info.autoopenObjects.append( autoopenObject );
A structure providing information about single kexi database template file.