Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r729 - branches/opensource/java/ch/idok/qtgui

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r729 - branches/opensource/java/ch/idok/qtgui


Chronological Thread 
  • From: "Apache" <apache AT savannah.psi.ch>
  • To: idok-commit AT lists.psi.ch
  • Subject: [idok-commit] idok commit r729 - branches/opensource/java/ch/idok/qtgui
  • Date: Fri, 8 Feb 2008 15:48:51 +0100
  • List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
  • List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>

Author: geus AT PSI.CH
Date: Fri Feb 8 15:48:51 2008
New Revision: 729

Log:
Implemented workaround for i18n translations when using webstart

Modified:
branches/opensource/java/ch/idok/qtgui/DmsGui.java

Modified: branches/opensource/java/ch/idok/qtgui/DmsGui.java
==============================================================================
--- branches/opensource/java/ch/idok/qtgui/DmsGui.java (original)
+++ branches/opensource/java/ch/idok/qtgui/DmsGui.java Fri Feb 8 15:48:51
2008
@@ -19,6 +19,10 @@

package ch.idok.qtgui;

+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

@@ -65,19 +69,42 @@
splash
.showMessage(" Loading iDok
Application...");
QApplication.processEvents();
-
- // load translations
- String locale = QLocale.system().name();
- QTranslator translator = new QTranslator();
- if (translator.load("classpath:ch/idok/qtgui/translations/iDok_"
+ locale+ ".qm")){
- QApplication.installTranslator(translator);
- }
+
+ // Load i18n translations
+ try {
+ /*
+ * We download the translations file to the local file
system in
+ * order to work around a bug in QTranslator.load() when used
+ * with Java webstart.
+ */
+ String locale = QLocale.system().name();
+ l.fine("Locale used for i18n translations is " + locale);
+ Class<DmsGui> c = DmsGui.class;
+ File f;
+ f = copyToTemp(c.getResourceAsStream("translations/iDok_"
+ + locale + ".qm"));
+ f.deleteOnExit();
+ l.fine("Wrote i18n translations to " + f.getPath());
+ QTranslator translator = new QTranslator();
+ if (translator.load(f.getPath())) {
+ l.fine("i18n translations installed");
+ QApplication.installTranslator(translator);
+ } else {
+ l
+ .warning("Could not install i18n translations,
QTranslator returned with error code.");
+ }
+ } catch (IOException e) {
+ l.log(Level.WARNING,
+ "Could not load i18n translations from resources",
e);
+ }
+
// Start GUI
MainWindow d = new MainWindow();
d.show();
splash.finish(d);
QApplication.exec();
- // Shutdown application: Under some circumstances System.exit() is
+
+ // Shutdown application: Under some circumstances System.exit()
is
// necessary to get rid of all threads and thus to shutdown the
Java
// VM
l.info("Exiting DmsGui.main()");
@@ -89,4 +116,17 @@
}
}

+ static protected File copyToTemp(InputStream is) throws IOException {
+ File t = File.createTempFile("idok_temp", null);
+ FileOutputStream os = new FileOutputStream(t);
+ byte[] buf = new byte[4096];
+ while (true) {
+ int numBytes = is.read(buf);
+ if (numBytes <= 0)
+ break;
+ os.write(buf, 0, numBytes);
+ }
+ os.close();
+ return t;
+ }
}



  • [idok-commit] idok commit r729 - branches/opensource/java/ch/idok/qtgui, Apache, 02/08/2008

Archive powered by MHonArc 2.6.19.

Top of Page