]> Shamusworld >> Repos - architektonas/blob - src/base/rs_system.cpp
Adding missing implementation.
[architektonas] / src / base / rs_system.cpp
1 // rs_system.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/21/2010  Added this text. :-)
15 //
16
17 #include "rs_system.h"
18
19 #include <QTranslator>
20 #include "settings.h"
21
22 RS_System * RS_System::uniqueInstance = NULL;
23
24 // Constructor
25 RS_System::RS_System()
26 {
27         initialized = false;
28 }
29
30 /**
31  * @return Instance to the unique system object.
32  */
33 /*static*/ RS_System * RS_System::instance()
34 {
35         if (uniqueInstance == NULL)
36                 uniqueInstance = new RS_System();
37
38         return uniqueInstance;
39 }
40
41 /**
42  * Initializes the system.
43  *
44  * @param appName Application name (e.g. "QCad II")
45  * @param appVersion Application version (e.g. "1.2.3")
46  * @param appDirName Application directory name used for
47  *     subdirectories in /usr, /etc ~/.
48  * @param appDir Absolute application directory (e.g. /opt/qcad)
49  *                 defaults to current directory.
50  */
51 void RS_System::init(const QString & appName, const QString & appVersion,
52         const QString & appDirName, const QString & appDir)
53 {
54         this->appName = appName;
55         this->appVersion = appVersion;
56         this->appDirName = appDirName;
57
58         if (appDir == "")
59         {
60 //        this->appDir = QDir::currentDirPath();
61                 this->appDir = QDir::currentPath();
62         }
63         else
64         {
65                 this->appDir = appDir;
66         }
67
68         RS_DEBUG->print("RS_System::init: System %s initialized.", appName.toLatin1().data());
69         RS_DEBUG->print("RS_System::init: App dir: %s", appDir.toLatin1().data());
70         initialized = true;
71
72         initLanguageList();
73 }
74
75 /**
76  * Initializes the list of available translations.
77  */
78 void RS_System::initLanguageList()
79 {
80         RS_DEBUG->print("RS_System::initLanguageList");
81         QStringList lst = getFileList("qm", "qm");
82
83         settings.beginGroup("Paths");
84 //      lst += QStringList::split(";", RS_SETTINGS->readEntry("/Translations", ""));
85         lst += settings.value("Translations", "").toString().split(";");
86         settings.endGroup();
87
88         for(QStringList::Iterator it=lst.begin(); it!=lst.end(); ++it)
89         {
90                 RS_DEBUG->print("RS_System::initLanguageList: qm file: %s", (*it).toLatin1().data());
91
92 //              int i1 = (*it).findRev('_');
93                 int i1 = (*it).lastIndexOf('_');
94 //              int i2 = (*it).find('.', i1);
95                 int i2 = (*it).indexOf('.', i1);
96                 QString l = (*it).mid(i1 + 1, i2 - i1 - 1);
97
98 //              if (languageList.find(l) == languageList.end())
99                 if (languageList.indexOf(l) == -1)
100                 {
101                         RS_DEBUG->print("RS_System::initLanguageList: append language: %s", l.toLatin1().data());
102                         languageList.append(l);
103                 }
104         }
105
106         RS_DEBUG->print("RS_System::initLanguageList: OK");
107 }
108
109 /**
110  * Loads a different translation for the application GUI.
111  */
112 void RS_System::loadTranslation(const QString & lang, const QString & langCmd)
113 {
114         static QTranslator * tQt = NULL;
115         static QTranslator * tQCad = NULL;
116         static QTranslator * tQCadGuiQt = NULL;
117         static QTranslator * tQCadActions = NULL;
118         static QTranslator * tQCadCmd = NULL;
119         static QTranslator * tQCadLib = NULL;
120         static QTranslator * tQCadCam = NULL;
121         static QTranslator * tQCadProf = NULL;
122
123         QString langFile;
124
125         // search in various directories for translations
126         QStringList lst = getDirectoryList("qm");
127
128         settings.beginGroup("Paths");
129 //      lst += QStringList::split(";", RS_SETTINGS->readEntry("/Translations", ""));
130         lst += settings.value("Translations", "").toString().split(";");
131         settings.endGroup();
132
133         for(QStringList::Iterator it=lst.begin(); it!=lst.end(); ++it)
134         {
135                 langFile = "qt_" + lang + ".qm";
136
137                 if (tQt != NULL)
138                 {
139                         qApp->removeTranslator(tQt);
140                         delete tQt;
141                 }
142
143                 tQt = new QTranslator(0);
144
145                 if (tQt->load(langFile, (*it)))
146                 {
147                         qApp->installTranslator(tQt);
148                 }
149
150                 langFile = "qcad_" + lang + ".qm";
151
152                 if (tQCad != NULL)
153                 {
154                         qApp->removeTranslator(tQCad);
155                         delete tQCad;
156                 }
157
158                 tQCad = new QTranslator(0);
159
160                 if (tQCad->load(langFile, (*it)))
161                 {
162                         qApp->installTranslator(tQCad);
163                 }
164
165                 langFile = "qcadguiqt_" + lang + ".qm";
166
167                 if (tQCadGuiQt != NULL)
168                 {
169                         qApp->removeTranslator(tQCadGuiQt);
170                         delete tQCadGuiQt;
171                 }
172
173                 tQCadGuiQt = new QTranslator(0);
174
175                 if (tQCadGuiQt->load(langFile, (*it)))
176                 {
177                         qApp->installTranslator(tQCadGuiQt);
178                 }
179
180                 langFile = "qcadactions_" + lang + ".qm";
181
182                 if (tQCadActions != NULL)
183                 {
184                         qApp->removeTranslator(tQCadActions);
185                         delete tQCadActions;
186                 }
187
188                 tQCadActions = new QTranslator(0);
189
190                 if (tQCadActions->load(langFile, (*it)))
191                 {
192                         qApp->installTranslator(tQCadActions);
193                 }
194
195                 langFile = "qcadcmd_" + langCmd + ".qm";
196
197                 if (tQCadCmd != NULL)
198                 {
199                         qApp->removeTranslator(tQCadCmd);
200                         delete tQCadCmd;
201                 }
202
203                 tQCadCmd = new QTranslator(0);
204
205                 if (tQCadCmd->load(langFile, (*it)))
206                 {
207                         qApp->installTranslator(tQCadCmd);
208                 }
209
210                 langFile = "qcadlib_" + lang + ".qm";
211
212                 if (tQCadLib != NULL)
213                 {
214                         qApp->removeTranslator(tQCadLib);
215                         delete tQCadLib;
216                 }
217
218                 tQCadLib = new QTranslator(0);
219
220                 if (tQCadLib->load(langFile, (*it)))
221                 {
222                         qApp->installTranslator(tQCadLib);
223                 }
224
225                 langFile = "qcadcam_" + lang + ".qm";
226
227                 if (tQCadLib != NULL)
228                 {
229                         qApp->removeTranslator(tQCadCam);
230                         delete tQCadCam;
231                 }
232
233                 tQCadCam = new QTranslator(0);
234
235                 if (tQCadCam->load(langFile, (*it)))
236                 {
237                         qApp->installTranslator(tQCadCam);
238                 }
239
240                 langFile = "qcadprof_" + lang + ".qm";
241
242                 if (tQCadProf != NULL)
243                 {
244                         qApp->removeTranslator(tQCadProf);
245                         delete tQCadProf;
246                 }
247
248                 tQCadProf = new QTranslator(0);
249
250                 if (tQCadProf->load(langFile, (*it)))
251                 {
252                         qApp->installTranslator(tQCadProf);
253                 }
254         }
255 }
256
257 /**
258  * Checks if the system has been initialized and prints a warning
259  * otherwise to stderr.
260  */
261 bool RS_System::checkInit()
262 {
263         if (!initialized)
264         {
265                 RS_DEBUG->print(RS_Debug::D_WARNING, "RS_System::checkInit: System not initialized.\n"
266                         "Use RS_SYSTEM->init(appname, appdirname) to do so.");
267         }
268
269         return initialized;
270 }
271
272 /**
273  * Creates all given directories in the user's home.
274  */
275 bool RS_System::createHomePath(const QString & p)
276 {
277         QDir dr;
278
279 //      QStringList dirs = QStringList::split('/', p, false);
280         QStringList dirs = p.split('/', QString::SkipEmptyParts);
281         QString created = getHomeDir();
282
283         for(QStringList::Iterator it=dirs.begin(); it!=dirs.end(); ++it)
284         {
285                 created += QString("/%1").arg(*it);
286
287 //              if (created.isEmpty() || QFileInfo(created).isDir() || dr.mkdir(created, true))
288                 if (created.isEmpty() || QFileInfo(created).isDir() || dr.mkdir(created))
289                 {
290                         RS_DEBUG->print("RS_System::createHomePath: Created directory '%s'",
291                                 created.toLatin1().data());
292                 }
293                 else
294                 {
295                         RS_DEBUG->print(RS_Debug::D_ERROR, "RS_System::createHomePath: Cannot create directory '%s'",
296                                 created.toLatin1().data());
297                         return false;
298                 }
299         }
300
301         return true;
302 }
303
304 /**
305  * @return Users home directory.
306  */
307 QString RS_System::getHomeDir()
308 {
309 //      return QDir::homeDirPath();
310         return QDir::homePath();
311 }
312
313 /**
314  * @return Current directory.
315  */
316 QString RS_System::getCurrentDir()
317 {
318 //      return QDir::currentDirPath();
319         return QDir::currentPath();
320 }
321
322 /**
323  * @return Application directory.
324  */
325 QString RS_System::getAppDir()
326 {
327         return appDir;
328 }
329
330 /**
331  * @return A list of absolute paths to all font files found.
332  */
333 QStringList RS_System::getFontList()
334 {
335         QStringList ret = getFileList("fonts", "cxf");
336         return ret;
337 }
338
339 /**
340  * @return A list of absolute paths to all hatch pattern files found.
341  */
342 QStringList RS_System::getPatternList()
343 {
344         QStringList ret = getFileList("patterns", "dxf");
345         return ret;
346 }
347
348 /**
349  * @return A list of absolute paths to all script files found.
350  */
351 QStringList RS_System::getScriptList()
352 {
353         QStringList ret = getFileList("scripts/qsa", "qs");
354         return ret;
355 }
356
357 /**
358  * @return A list of absolute paths to all machine configuration files found.
359  */
360 QStringList RS_System::getMachineList()
361 {
362         QStringList ret = getFileList("machines", "cxm");
363         return ret;
364 }
365
366 /**
367  * @return Absolute path to the documentation.
368  */
369 QString RS_System::getDocPath()
370 {
371         QStringList lst = getDirectoryList("doc");
372         return lst.first();
373 }
374
375 /**
376  * @return The application name.
377  */
378 QString RS_System::getAppName()
379 {
380         return appName;
381 }
382
383 /**
384  * @return The application version.
385  */
386 QString RS_System::getAppVersion()
387 {
388         return appVersion;
389 }
390
391 /**
392  * Searches for files in an application shared directory in the given
393  * subdirectory with the given extension.
394  *
395  * @return List of the absolute paths of the files found.
396  */
397 QStringList RS_System::getFileList(const QString & subDirectory, const QString & fileExtension)
398 {
399         checkInit();
400
401         /*QStringList dirList;
402
403         // Redhat style:
404         dirList.append("/usr/share/" + appDirName);
405
406         // SuSE style:
407         dirList.append("/usr/X11R6/" + appDirName);
408
409         dirList.append("/usr/X11R6/share/" + appDirName);
410         dirList.append(getHomeDir() + "/." + appDirName);
411
412         // Local directory:
413         dirList.append(".");
414         //dirList.append(getCurrentDir());
415
416         // Debian Doc:
417         /usr/share/doc/qcad/html/en/
418         */
419
420         QStringList dirList = getDirectoryList(subDirectory);
421
422         QStringList fileList;
423         QString path;
424         QDir dir;
425
426         for(QStringList::Iterator it=dirList.begin(); it!=dirList.end(); ++it)
427         {
428                 //path = QString(*it) + "/" + subDirectory;
429                 path = QString(*it);
430                 dir = QDir(path);
431
432                 if (dir.exists() && dir.isReadable())
433                 {
434 //                      QStringList files = dir.entryList("*." + fileExtension);
435                         QStringList filters;
436                         filters << "*." + fileExtension;
437                         QStringList files = dir.entryList(filters);
438
439                         for(QStringList::Iterator it2=files.begin(); it2!=files.end(); it2++)
440                                 fileList += path + "/" + (*it2);
441                 }
442         }
443
444         return fileList;
445 }
446
447 /**
448  * @return List of all directories in subdirectory 'subDirectory' in
449  * all possible QCad directories.
450  */
451 QStringList RS_System::getDirectoryList(const QString & subDirectory)
452 {
453         QStringList dirList;
454
455 #ifdef __APPLE__
456         if (subDirectory != "library")
457         {
458 #endif
459                 //local (application) directory has priority over other dirs:
460                 if (!appDir.isEmpty() && appDir != "/" && appDir != getHomeDir())
461                 {
462                         dirList.append(appDir + "/" + subDirectory);
463                 }
464
465                 // Redhat style:
466                 dirList.append("/usr/share/" + appDirName + "/" + subDirectory);
467                 // SuSE style:
468                 dirList.append("/usr/X11R6/" + appDirName + "/" + subDirectory);
469                 dirList.append("/usr/X11R6/share/" + appDirName + "/" + subDirectory);
470                 dirList.append(getHomeDir() + "/." + appDirName + "/" + subDirectory);
471 #ifdef __APPLE__
472         }
473 #endif
474
475 #ifdef __APPLE__
476         // Mac OS X - don't scan for library since this might lead us into the
477         //  wrong directory tree:
478         if (!appDir.isEmpty() && appDir != "/" /*&& subDirectory!="library"*/)
479         {
480                 dirList.append(appDir + "/../Resources/" + subDirectory);
481                 dirList.append(appDir + "/../../../" + subDirectory);
482         }
483 #endif
484
485         // Individual directories:
486         settings.beginGroup("Paths");
487
488         if (subDirectory == "fonts")
489         {
490                 dirList += settings.value("Fonts", "").toString().split(QRegExp("[;]"));
491         }
492         else if (subDirectory == "patterns")
493         {
494                 dirList += settings.value("Patterns", "").toString().split(QRegExp("[;]"));
495         }
496         else if (subDirectory.startsWith("scripts"))
497         {
498                 dirList += settings.value("Scripts", "").toString().split(QRegExp("[;]"));
499         }
500         else if (subDirectory.startsWith("library"))
501         {
502                 dirList += settings.value("Library", "").toString().split(QRegExp("[;]"));
503         }
504         else if (subDirectory.startsWith("po"))
505         {
506                 dirList += settings.value("Translations", "").toString().split(QRegExp("[;]"));
507         }
508
509         settings.endGroup();
510
511         QStringList ret;
512
513         RS_DEBUG->print("RS_System::getDirectoryList: Paths:");
514
515         for(QStringList::Iterator it=dirList.begin(); it!=dirList.end(); ++it)
516         {
517                 if (QFileInfo(*it).isDir())
518                 {
519                         ret += (*it);
520                         RS_DEBUG->print((*it).toLatin1().data());
521                 }
522         }
523
524         return ret;
525 }
526
527 QStringList RS_System::getLanguageList()
528 {
529         return languageList;
530 }
531
532 /**
533  * Converts a language string to a symbol (e.g. Deutsch or German to 'de').
534  *
535  * Supported languages: http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt
536  */
537 QString RS_System::languageToSymbol(const QString& lang)
538 {
539     QString l = lang.toLower();
540
541     // don't use else if.. M$ visual wannabe c++ can't handle it
542     if (l == "afar")
543         {
544         return "aa";
545     }
546     if (l=="abkhazian") {
547         return "ab";
548     }
549     if (l=="afrikaans") {
550         return "af";
551     }
552     if (l=="amharic") {
553         return "am";
554     }
555     if (l=="arabic") {
556         return "ar";
557     }
558     if (l=="assamese") {
559         return "as";
560     }
561     if (l=="aymara") {
562         return "ay";
563     }
564     if (l=="azerbaijani") {
565         return "az";
566     }
567     if (l=="bashkir") {
568         return "ba";
569     }
570     if (l=="byelorussian") {
571         return "be";
572     }
573     if (l=="bulgarian") {
574         return "bg";
575     }
576     if (l=="bihari") {
577         return "bh";
578     }
579     if (l=="bislama") {
580         return "bi";
581     }
582     if (l=="bengali" || l=="bangla") {
583         return "bn";
584     }
585     if (l=="tibetan") {
586         return "bo";
587     }
588     if (l=="breton") {
589         return "br";
590     }
591     if (l=="catalan") {
592         return "ca";
593     }
594     if (l=="corsican") {
595         return "co";
596     }
597     if (l=="czech") {
598         return "cs";
599     }
600     if (l=="welsh") {
601         return "cy";
602     }
603     if (l=="danish") {
604         return "da";
605     }
606     if (l=="german" || l=="deutsch") {
607         return "de";
608     }
609     if (l=="bhutani") {
610         return "dz";
611     }
612     if (l=="greek") {
613         return "el";
614     }
615     if (l=="english") {
616         return "en";
617     }
618     if (l=="esperanto") {
619         return "eo";
620     }
621     if (l=="spanish") {
622         return "es";
623     }
624     if (l=="estonian") {
625         return "et";
626     }
627     if (l=="basque") {
628         return "eu";
629     }
630     if (l=="persian") {
631         return "fa";
632     }
633     if (l=="finnish") {
634         return "fi";
635     }
636     if (l=="fiji") {
637         return "fj";
638     }
639     if (l=="faroese") {
640         return "fo";
641     }
642     if (l=="french" || l=="francais") {
643         return "fr";
644     }
645     if (l=="frisian") {
646         return "fy";
647     }
648     if (l=="irish") {
649         return "ga";
650     }
651     if (l=="scots gaelic" || l=="gaelic") {
652         return "gd";
653     }
654     if (l=="galician") {
655         return "gl";
656     }
657     if (l=="guarani") {
658         return "gn";
659     }
660     if (l=="gujarati") {
661         return "gu";
662     }
663     if (l=="hausa") {
664         return "ha";
665     }
666     if (l=="hebrew") {
667         return "he";
668     }
669     if (l=="hindi") {
670         return "hi";
671     }
672     if (l=="croatian") {
673         return "hr";
674     }
675     if (l=="hungarian") {
676         return "hu";
677     }
678     if (l=="armenian") {
679         return "hy";
680     }
681     if (l=="interlingua") {
682         return "ia";
683     }
684     if (l=="indonesian") {
685         return "id";
686     }
687     if (l=="interlingue") {
688         return "ie";
689     }
690     if (l=="inupiak") {
691         return "ik";
692     }
693     if (l=="icelandic") {
694         return "is";
695     }
696     if (l=="italian") {
697         return "it";
698     }
699     if (l=="inuktitut") {
700         return "iu";
701     }
702     if (l=="japanese") {
703         return "ja";
704     }
705     if (l=="javanese") {
706         return "jw";
707     }
708     if (l=="georgian") {
709         return "ka";
710     }
711     if (l=="kazakh") {
712         return "kk";
713     }
714     if (l=="greenlandic") {
715         return "kl";
716     }
717     if (l=="cambodian") {
718         return "km";
719     }
720     if (l=="kannada") {
721         return "kn";
722     }
723     if (l=="korean") {
724         return "ko";
725     }
726     if (l=="kashmiri") {
727         return "ks";
728     }
729     if (l=="kurdish") {
730         return "ku";
731     }
732     if (l=="kirghiz") {
733         return "ky";
734     }
735     if (l=="latin") {
736         return "la";
737     }
738     if (l=="lingala") {
739         return "ln";
740     }
741     if (l=="laothian") {
742         return "lo";
743     }
744     if (l=="lithuanian") {
745         return "lt";
746     }
747     if (l=="latvian" || l=="lettish") {
748         return "lv";
749     }
750     if (l=="malagasy") {
751         return "mg";
752     }
753     if (l=="maori") {
754         return "mi";
755     }
756     if (l=="macedonian") {
757         return "mk";
758     }
759     if (l=="malayalam") {
760         return "ml";
761     }
762     if (l=="mongolian") {
763         return "mn";
764     }
765     if (l=="moldavian") {
766         return "mo";
767     }
768     if (l=="marathi") {
769         return "mr";
770     }
771     if (l=="malay") {
772         return "ms";
773     }
774     if (l=="maltese") {
775         return "mt";
776     }
777     if (l=="burmese") {
778         return "my";
779     }
780     if (l=="nauru") {
781         return "na";
782     }
783     if (l=="nepali") {
784         return "ne";
785     }
786     if (l=="dutch") {
787         return "nl";
788     }
789     if (l=="norwegian") {
790         return "no";
791     }
792     if (l=="occitan") {
793         return "oc";
794     }
795     if (l=="afan" || l=="oromo" || l=="afan oromo") {
796         return "om";
797     }
798     if (l=="oriya") {
799         return "or";
800     }
801     if (l=="punjabi") {
802         return "pa";
803     }
804     if (l=="polish") {
805         return "pl";
806     }
807     if (l=="pashto" || l=="pushto") {
808         return "ps";
809     }
810     if (l=="portuguese") {
811         return "pt";
812     }
813     if (l=="brasilian portuguese") {
814         return "pt-br";
815     }
816     if (l=="quechua") {
817         return "qu";
818     }
819     if (l=="rhaeto-romance") {
820         return "rm";
821     }
822     if (l=="kirundi") {
823         return "rn";
824     }
825     if (l=="romanian") {
826         return "ro";
827     }
828     if (l=="russian") {
829         return "ru";
830     }
831     if (l=="kinyarwanda") {
832         return "rw";
833     }
834     if (l=="sanskrit") {
835         return "sa";
836     }
837     if (l=="sindhi") {
838         return "sd";
839     }
840     if (l=="sangho") {
841         return "sg";
842     }
843     if (l=="serbo-Croatian") {
844         return "sh";
845     }
846     if (l=="sinhalese") {
847         return "si";
848     }
849     if (l=="slovak") {
850         return "sk";
851     }
852     if (l=="slovenian") {
853         return "sl";
854     }
855     if (l=="samoan") {
856         return "sm";
857     }
858     if (l=="shona") {
859         return "sn";
860     }
861     if (l=="somali") {
862         return "so";
863     }
864     if (l=="albanian") {
865         return "sq";
866     }
867     if (l=="serbian") {
868         return "sr";
869     }
870     if (l=="siswati") {
871         return "ss";
872     }
873     if (l=="sesotho") {
874         return "st";
875     }
876     if (l=="sundanese") {
877         return "su";
878     }
879     if (l=="swedish") {
880         return "sv";
881     }
882     if (l=="swahili") {
883         return "sw";
884     }
885     if (l=="tamil") {
886         return "ta";
887     }
888     if (l=="telugu") {
889         return "te";
890     }
891     if (l=="tajik") {
892         return "tg";
893     }
894     if (l=="thai") {
895         return "th";
896     }
897     if (l=="tigrinya") {
898         return "ti";
899     }
900     if (l=="turkmen") {
901         return "tk";
902     }
903     if (l=="tagalog") {
904         return "tl";
905     }
906     if (l=="setswana") {
907         return "tn";
908     }
909     if (l=="tonga") {
910         return "to";
911     }
912     if (l=="turkish") {
913         return "tr";
914     }
915     if (l=="tsonga") {
916         return "ts";
917     }
918     if (l=="tatar") {
919         return "tt";
920     }
921     if (l=="twi") {
922         return "tw";
923     }
924     if (l=="uighur") {
925         return "ug";
926     }
927     if (l=="ukrainian") {
928         return "uk";
929     }
930     if (l=="urdu") {
931         return "ur";
932     }
933     if (l=="uzbek") {
934         return "uz";
935     }
936     if (l=="vietnamese") {
937         return "vi";
938     }
939     if (l=="volapuk") {
940         return "vo";
941     }
942     if (l=="wolof") {
943         return "wo";
944     }
945     if (l=="xhosa") {
946         return "xh";
947     }
948     if (l=="yiddish") {
949         return "yi";
950     }
951     if (l=="yoruba") {
952         return "yo";
953     }
954     if (l=="zhuang") {
955         return "za";
956     }
957     if (l=="chinese") {
958         return "zh";
959     }
960     if (l=="zulu") {
961         return "zu";
962     }
963
964     return "";
965 }
966
967 /**
968  * Converst a language two-letter-code into a readable string
969  * (e.g. 'de' to Deutsch)
970  */
971 QString RS_System::symbolToLanguage(const QString & symb)
972 {
973         QString l = symb.toLower();
974
975         if (l == "aa")
976                 return "Afar";
977
978         if (l == "ab") {
979                 return "Abkhazian";
980         }
981         if (l == "af") {
982                 return "Afrikaans";
983         }
984         if (l == "am") {
985                 return "Amharic";
986         }
987         if (l == "ar") {
988                 return "Arabic";
989         }
990         if (l == "as") {
991                 return "Assamese";
992         }
993         if (l == "ay") {
994                 return "Aymara";
995         }
996         if (l == "az") {
997                 return "Azerbaijani";
998         }
999         if (l == "ba") {
1000                 return "Bashkir";
1001         }
1002         if (l == "be") {
1003                 return "Byelorussian";
1004         }
1005         if (l == "bg") {
1006                 return "Bulgarian";
1007         }
1008         if (l == "bh") {
1009                 return "Bihari";
1010         }
1011         if (l == "bi") {
1012                 return "Bislama";
1013         }
1014         if (l == "bn") {
1015                 return "Bengali";
1016         }
1017         if (l == "bo") {
1018                 return "Tibetan";
1019         }
1020         if (l == "br") {
1021                 return "Breton";
1022         }
1023         if (l == "ca") {
1024                 return "Catalan";
1025         }
1026         if (l == "co") {
1027                 return "Corsican";
1028         }
1029         if (l == "cs") {
1030                 return "Czech";
1031         }
1032         if (l == "cy") {
1033                 return "Welsh";
1034         }
1035         if (l == "da") {
1036                 return "Danish";
1037         }
1038         if (l == "de") {
1039                 return "German";
1040         }
1041         if (l == "dz") {
1042                 return "Bhutani";
1043         }
1044         if (l == "el") {
1045                 return "Greek";
1046         }
1047         if (l == "en") {
1048                 return "English";
1049         }
1050         if (l == "eo") {
1051                 return "Esperanto";
1052         }
1053         if (l == "es") {
1054                 return "Spanish";
1055         }
1056         if (l == "et") {
1057                 return "Estonian";
1058         }
1059         if (l == "eu") {
1060                 return "Basque";
1061         }
1062         if (l == "fa") {
1063                 return "Persian";
1064         }
1065         if (l == "fi") {
1066                 return "Finnish";
1067         }
1068         if (l == "fj") {
1069                 return "Fiji";
1070         }
1071         if (l == "fo") {
1072                 return "Faroese";
1073         }
1074         if (l == "fr") {
1075                 return "French";
1076         }
1077         if (l == "fy") {
1078                 return "Frisian";
1079         }
1080         if (l == "ga") {
1081                 return "Irish";
1082         }
1083         if (l == "gd") {
1084                 return "Scots Gaelic";
1085         }
1086         if (l == "gl") {
1087                 return "Galician";
1088         }
1089         if (l == "gn") {
1090                 return "Guarani";
1091         }
1092         if (l == "gu") {
1093                 return "Gujarati";
1094         }
1095         if (l == "ha") {
1096                 return "Hausa";
1097         }
1098         if (l == "he") {
1099                 return "Hebrew";
1100         }
1101         if (l == "hi") {
1102                 return "Hindi";
1103         }
1104         if (l == "hr") {
1105                 return "Croatian";
1106         }
1107         if (l == "hu") {
1108                 return "Hungarian";
1109         }
1110         if (l == "hy") {
1111                 return "Armenian";
1112         }
1113         if (l == "ia") {
1114                 return "Interlingua";
1115         }
1116         if (l == "id") {
1117                 return "Indonesian";
1118         }
1119         if (l == "ie") {
1120                 return "Interlingue";
1121         }
1122         if (l == "ik") {
1123                 return "Inupiak";
1124         }
1125         if (l == "is") {
1126                 return "Icelandic";
1127         }
1128         if (l == "it") {
1129                 return "Italian";
1130         }
1131         if (l == "iu") {
1132                 return "Inuktitut";
1133         }
1134         if (l == "ja") {
1135                 return "Japanese";
1136         }
1137         if (l == "jw") {
1138                 return "Javanese";
1139         }
1140         if (l == "ka") {
1141                 return "Georgian";
1142         }
1143         if (l == "kk") {
1144                 return "Kazakh";
1145         }
1146         if (l == "kl") {
1147                 return "Greenlandic";
1148         }
1149         if (l == "km") {
1150                 return "Cambodian";
1151         }
1152         if (l == "kn") {
1153                 return "Kannada";
1154         }
1155         if (l == "ko") {
1156                 return "Korean";
1157         }
1158         if (l == "ks") {
1159                 return "Kashmiri";
1160         }
1161         if (l == "ku") {
1162                 return "Kurdish";
1163         }
1164         if (l == "ky") {
1165                 return "Kirghiz";
1166         }
1167         if (l == "la") {
1168                 return "Latin";
1169         }
1170         if (l == "ln") {
1171                 return "Lingala";
1172         }
1173         if (l == "lo") {
1174                 return "Laothian";
1175         }
1176         if (l == "lt") {
1177                 return "Lithuanian";
1178         }
1179         if (l == "lv") {
1180                 return "Latvian";
1181         }
1182         if (l == "mg") {
1183                 return "Malagasy";
1184         }
1185         if (l == "mi") {
1186                 return "Maori";
1187         }
1188         if (l == "mk") {
1189                 return "Macedonian";
1190         }
1191         if (l == "ml") {
1192                 return "Malayalam";
1193         }
1194         if (l == "mn") {
1195                 return "Mongolian";
1196         }
1197         if (l == "mo") {
1198                 return "Moldavian";
1199         }
1200         if (l == "mr") {
1201                 return "Marathi";
1202         }
1203         if (l == "ms") {
1204                 return "Malay";
1205         }
1206         if (l == "mt") {
1207                 return "Maltese";
1208         }
1209         if (l == "my") {
1210                 return "Burmese";
1211         }
1212         if (l == "na") {
1213                 return "Nauru";
1214         }
1215         if (l == "ne") {
1216                 return "Nepali";
1217         }
1218         if (l == "nl") {
1219                 return "Dutch";
1220         }
1221         if (l == "no") {
1222                 return "Norwegian";
1223         }
1224         if (l == "oc") {
1225                 return "Occitan";
1226         }
1227         if (l == "om") {
1228                 return "Afan Oromo";
1229         }
1230         if (l == "or") {
1231                 return "Oriya";
1232         }
1233         if (l == "pa") {
1234                 return "Punjabi";
1235         }
1236         if (l == "pl") {
1237                 return "Polish";
1238         }
1239         if (l == "ps") {
1240                 return "Pashto";
1241         }
1242         if (l == "pt") {
1243                 return "Portuguese";
1244         }
1245         if (l == "pt-br") {
1246                 return "Brasilian Portuguese";
1247         }
1248         if (l == "qu") {
1249                 return "Quechua";
1250         }
1251         if (l == "rm") {
1252                 return "Rhaeto-Romance";
1253         }
1254         if (l == "rn") {
1255                 return "Kirundi";
1256         }
1257         if (l == "ro") {
1258                 return "Romanian";
1259         }
1260         if (l == "ru") {
1261                 return "Russian";
1262         }
1263         if (l == "rw") {
1264                 return "Kinyarwanda";
1265         }
1266         if (l == "sa") {
1267                 return "Sanskrit";
1268         }
1269         if (l == "sd") {
1270                 return "Sindhi";
1271         }
1272         if (l == "sg") {
1273                 return "Sangho";
1274         }
1275         if (l == "sh") {
1276                 return "Serbo-croatian";
1277         }
1278         if (l == "si") {
1279                 return "Sinhalese";
1280         }
1281         if (l == "sk") {
1282                 return "Slovak";
1283         }
1284         if (l == "sl") {
1285                 return "Slovenian";
1286         }
1287         if (l == "sm") {
1288                 return "Samoan";
1289         }
1290         if (l == "sn") {
1291                 return "Shona";
1292         }
1293         if (l == "so") {
1294                 return "Somali";
1295         }
1296         if (l == "sq") {
1297                 return "Albanian";
1298         }
1299         if (l == "sr") {
1300                 return "Serbian";
1301         }
1302         if (l == "ss") {
1303                 return "Siswati";
1304         }
1305         if (l == "st") {
1306                 return "Sesotho";
1307         }
1308         if (l == "su") {
1309                 return "Sundanese";
1310         }
1311         if (l == "sv") {
1312                 return "Swedish";
1313         }
1314         if (l == "sw") {
1315                 return "Swahili";
1316         }
1317         if (l == "ta") {
1318                 return "Tamil";
1319         }
1320         if (l == "te") {
1321                 return "Telugu";
1322         }
1323         if (l == "tg") {
1324                 return "Tajik";
1325         }
1326         if (l == "th") {
1327                 return "Thai";
1328         }
1329         if (l == "ti") {
1330                 return "Tigrinya";
1331         }
1332         if (l == "tk") {
1333                 return "Turkmen";
1334         }
1335         if (l == "tl") {
1336                 return "Tagalog";
1337         }
1338         if (l == "tn") {
1339                 return "Setswana";
1340         }
1341         if (l == "to") {
1342                 return "Tonga";
1343         }
1344         if (l == "tr") {
1345                 return "Turkish";
1346         }
1347         if (l == "ts") {
1348                 return "Tsonga";
1349         }
1350         if (l == "tt") {
1351                 return "Tatar";
1352         }
1353         if (l == "tw") {
1354                 return "Twi";
1355         }
1356         if (l == "ug") {
1357                 return "Uighur";
1358         }
1359         if (l == "uk") {
1360                 return "Ukrainian";
1361         }
1362         if (l == "ur") {
1363                 return "Urdu";
1364         }
1365         if (l == "uz") {
1366                 return "Uzbek";
1367         }
1368         if (l == "vi") {
1369                 return "Vietnamese";
1370         }
1371         if (l == "vo") {
1372                 return "Volapuk";
1373         }
1374         if (l == "wo") {
1375                 return "Wolof";
1376         }
1377         if (l == "xh") {
1378                 return "Xhosa";
1379         }
1380         if (l == "yi") {
1381                 return "Yiddish";
1382         }
1383
1384         if (l == "yo")
1385                 return "Yoruba";
1386
1387         if (l == "za")
1388                 return "Zhuang";
1389
1390         if (l == "zh")
1391                 return "Chinese";
1392
1393         if (l == "zu")
1394                 return "Zulu";
1395
1396         return "";
1397 }
1398
1399 /**
1400  * Tries to convert the given encoding string to an encoding Qt knows.
1401  */
1402 QString RS_System::getEncoding(const QString & str)
1403 {
1404     QString l=str.toLower();
1405
1406     if (l=="latin1" || l=="ansi_1252" || l=="iso-8859-1" ||
1407             l=="cp819" || l=="csiso" || l=="ibm819" || l=="iso_8859-1" ||
1408             l=="iso8859-1" || l=="iso-ir-100" || l=="l1") {
1409         return "Latin1";
1410     } else if (l=="big5" || l=="ansi_950" || l=="cn-big5" || l=="csbig5" ||
1411                l=="x-x-big5") {
1412         return "Big5";
1413     } else if (l=="big5-hkscs") {
1414         return "Big5-HKSCS";
1415     } else if (l=="eucjp" || l=="euc-jp" || l=="cseucpkdfmtjapanese" ||
1416                l=="x-euc" || l=="x-euc-jp") {
1417         return "eucJP";
1418     } else if (l=="euckr") {
1419         return "eucKR";
1420     } else if (l=="gb2312" || l=="gb2312" || l=="chinese" || l=="cn-gb" ||
1421                l=="csgb2312" || l=="csgb231280" || l=="csiso58gb231280" ||
1422                l=="gb_2312-80" || l=="gb231280" || l=="gb2312-80" || l=="gbk" ||
1423                l=="iso-ir-58") {
1424         return "GB2312";
1425     } else if (l=="gbk") {
1426         return "GBK";
1427     } else if (l=="gb18030") {
1428         return "GB18030";
1429     } else if (l=="jis7") {
1430         return "JIS7";
1431     } else if (l=="shift-jis" || l=="ansi_932" || l=="shift_jis" || l=="csShiftJIS" ||
1432                l=="cswindows31j" || l=="ms_kanji" || l=="x-ms-cp932" || l=="x-sjis") {
1433         return "Shift-JIS";
1434     } else if (l=="tscii") {
1435         return "TSCII";
1436     } else if (l=="utf88-bit") {
1437         return "utf88-bit";
1438     } else if (l=="utf16") {
1439         return "utf16";
1440     } else if (l=="koi8-r") {
1441         return "KOI8-R";
1442     } else if (l=="koi8-u") {
1443         return "KOI8-U";
1444     } else if (l=="iso8859-1") {
1445         return "ISO8859-1";
1446     } else if (l=="iso8859-2") {
1447         return "ISO8859-2";
1448     } else if (l=="iso8859-3") {
1449         return "ISO8859-3";
1450     } else if (l=="iso8859-4" || l=="ansi_1257") {
1451         return "ISO8859-4";
1452     } else if (l=="iso8859-5") {
1453         return "ISO8859-5";
1454     } else if (l=="iso8859-6" || l=="ansi_1256") {
1455         return "ISO8859-6";
1456     } else if (l=="iso8859-7" || l=="ansi_1253") {
1457         return "ISO8859-7";
1458     } else if (l=="iso8859-8") {
1459         return "ISO8859-8";
1460     } else if (l=="iso8859-8-i" || l=="ansi_1255") {
1461         return "ISO8859-8-i";
1462     } else if (l=="iso8859-9" || l=="ansi_1254") {
1463         return "ISO8859-9";
1464     } else if (l=="iso8859-10") {
1465         return "ISO8859-10";
1466     } else if (l=="iso8859-13") {
1467         return "ISO8859-13";
1468     } else if (l=="iso8859-14") {
1469         return "ISO8859-14";
1470     } else if (l=="iso8859-15") {
1471         return "ISO8859-15";
1472     } else if (l=="ibm 850") {
1473         return "IBM 850";
1474     } else if (l=="ibm 866") {
1475         return "IBM 866";
1476     } else if (l=="cp874") {
1477         return "CP874";
1478     } else if (l=="cp1250") {
1479         return "CP1250";
1480     } else if (l=="cp1251") {
1481         return "CP1251";
1482     } else if (l=="cp1252") {
1483         return "CP1252";
1484     } else if (l=="cp1253") {
1485         return "CP1253";
1486     } else if (l=="cp1254") {
1487         return "CP1254";
1488     } else if (l=="cp1255") {
1489         return "CP1255";
1490     } else if (l=="cp1256") {
1491         return "CP1256";
1492     } else if (l=="cp1257") {
1493         return "CP1257";
1494     } else if (l=="cp1258") {
1495         return "CP1258";
1496     } else if (l=="apple roman") {
1497         return "Apple Roman";
1498     } else if (l=="tis-620") {
1499         return "TIS-620";
1500     }
1501
1502     return "latin1";
1503 }
1504
1505 /** Returns ISO code for given locale. Needed for win32 to convert
1506  from system encodings.
1507  Locale names mostly copied from XFree86.
1508
1509  The code may be incomplete (chinese/japanese locales, etc.)
1510
1511  2004-05-13, J Staniek
1512 */
1513 static QMap<QString, QString> loc_map;
1514
1515 QString RS_System::localeToISO(const QString & locale)
1516 {
1517         if (loc_map.isEmpty())
1518         {
1519                 loc_map["croatian"]="ISO8859-2";
1520                 loc_map["cs"]="ISO8859-2";
1521                 loc_map["cs_CS"]="ISO8859-2";
1522                 loc_map["cs_CZ"]="ISO8859-2";
1523                 loc_map["cz"]="ISO8859-2";
1524                 loc_map["cz_CZ"]="ISO8859-2";
1525                 loc_map["czech"]="ISO8859-2";
1526                 loc_map["hr"]="ISO8859-2";
1527                 loc_map["hr_HR"]="ISO8859-2";
1528                 loc_map["hu"]="ISO8859-2";
1529                 loc_map["hu_HU"]="ISO8859-2";
1530                 loc_map["hungarian"]="ISO8859-2";
1531                 loc_map["pl"]="ISO8859-2";
1532                 loc_map["pl_PL"]="ISO8859-2";
1533                 loc_map["polish"]="ISO8859-2";
1534                 loc_map["ro"]="ISO8859-2";
1535                 loc_map["ro_RO"]="ISO8859-2";
1536                 loc_map["rumanian"]="ISO8859-2";
1537                 loc_map["serbocroatian"]="ISO8859-2";
1538                 loc_map["sh"]="ISO8859-2";
1539                 loc_map["sh_SP"]="ISO8859-2";
1540                 loc_map["sh_YU"]="ISO8859-2";
1541                 loc_map["sk"]="ISO8859-2";
1542                 loc_map["sk_SK"]="ISO8859-2";
1543                 loc_map["sl"]="ISO8859-2";
1544                 loc_map["sl_CS"]="ISO8859-2";
1545                 loc_map["sl_SI"]="ISO8859-2";
1546                 loc_map["slovak"]="ISO8859-2";
1547                 loc_map["slovene"]="ISO8859-2";
1548                 loc_map["sr_SP"]="ISO8859-2";
1549
1550                 loc_map["eo"]="ISO8859-3";
1551
1552                 loc_map["ee"]="ISO8859-4";
1553                 loc_map["ee_EE"]="ISO8859-4";
1554
1555                 loc_map["mk"]="ISO8859-5";
1556                 loc_map["mk_MK"]="ISO8859-5";
1557                 loc_map["sp"]="ISO8859-5";
1558                 loc_map["sp_YU"]="ISO8859-5";
1559
1560                 loc_map["ar_AA"]="ISO8859-6";
1561                 loc_map["ar_SA"]="ISO8859-6";
1562                 loc_map["arabic"]="ISO8859-6";
1563
1564                 loc_map["el"]="ISO8859-7";
1565                 loc_map["el_GR"]="ISO8859-7";
1566                 loc_map["greek"]="ISO8859-7";
1567
1568                 loc_map["hebrew"]="ISO8859-8";
1569                 loc_map["he"]="ISO8859-8";
1570                 loc_map["he_IL"]="ISO8859-8";
1571                 loc_map["iw"]="ISO8859-8";
1572                 loc_map["iw_IL"]="ISO8859-8";
1573
1574                 loc_map["tr"]="ISO8859-9";
1575                 loc_map["tr_TR"]="ISO8859-9";
1576                 loc_map["turkish"]="ISO8859-9";
1577
1578                 loc_map["lt"]="ISO8859-13";
1579                 loc_map["lt_LT"]="ISO8859-13";
1580                 loc_map["lv"]="ISO8859-13";
1581                 loc_map["lv_LV"]="ISO8859-13";
1582
1583                 loc_map["et"]="ISO8859-15";
1584                 loc_map["et_EE"]="ISO8859-15";
1585                 loc_map["br_FR"]="ISO8859-15";
1586                 loc_map["ca_ES"]="ISO8859-15";
1587                 loc_map["de"]="ISO8859-15";
1588                 loc_map["de_AT"]="ISO8859-15";
1589                 loc_map["de_BE"]="ISO8859-15";
1590                 loc_map["de_DE"]="ISO8859-15";
1591                 loc_map["de_LU"]="ISO8859-15";
1592                 loc_map["en_IE"]="ISO8859-15";
1593                 loc_map["es"]="ISO8859-15";
1594                 loc_map["es_ES"]="ISO8859-15";
1595                 loc_map["eu_ES"]="ISO8859-15";
1596                 loc_map["fi"]="ISO8859-15";
1597                 loc_map["fi_FI"]="ISO8859-15";
1598                 loc_map["finnish"]="ISO8859-15";
1599                 loc_map["fr"]="ISO8859-15";
1600                 loc_map["fr_FR"]="ISO8859-15";
1601                 loc_map["fr_BE"]="ISO8859-15";
1602                 loc_map["fr_LU"]="ISO8859-15";
1603                 loc_map["french"]="ISO8859-15";
1604                 loc_map["ga_IE"]="ISO8859-15";
1605                 loc_map["gl_ES"]="ISO8859-15";
1606                 loc_map["it"]="ISO8859-15";
1607                 loc_map["it_IT"]="ISO8859-15";
1608                 loc_map["oc_FR"]="ISO8859-15";
1609                 loc_map["nl"]="ISO8859-15";
1610                 loc_map["nl_BE"]="ISO8859-15";
1611                 loc_map["nl_NL"]="ISO8859-15";
1612                 loc_map["pt"]="ISO8859-15";
1613                 loc_map["pt_PT"]="ISO8859-15";
1614                 loc_map["sv_FI"]="ISO8859-15";
1615                 loc_map["wa_BE"]="ISO8859-15";
1616
1617                 loc_map["uk"]="KOI8-U";
1618                 loc_map["uk_UA"]="KOI8-U";
1619                 loc_map["ru_YA"]="KOI8-U";
1620                 loc_map["ukrainian"]="KOI8-U";
1621
1622                 loc_map["be"]="KOI8-R";
1623                 loc_map["be_BY"]="KOI8-R";
1624                 loc_map["bg"]="KOI8-R";
1625                 loc_map["bg_BG"]="KOI8-R";
1626                 loc_map["bulgarian"]="KOI8-R";
1627                 loc_map["ba_RU"]="KOI8-R";
1628                 loc_map["ky"]="KOI8-R";
1629                 loc_map["ky_KG"]="KOI8-R";
1630                 loc_map["kk"]="KOI8-R";
1631                 loc_map["kk_KZ"]="KOI8-R";
1632         }
1633
1634         QString l = loc_map[locale];
1635
1636         if (l.isEmpty())
1637                 return "ISO8859-1";
1638
1639         return l;
1640 }