idok-commit AT lists.psi.ch
Subject: Commit emails of the iDok project
List archive
- From: "Apache" <apache AT savannah.psi.ch>
- To: idok-commit AT lists.psi.ch
- Subject: [idok-commit] idok commit r75 - trunk/java/ch/idok/qtgui
- Date: Wed, 30 Apr 2008 16:14:40 +0200
- List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
- List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>
Author: huebner AT PSI.CH
Date: Wed Apr 30 16:14:40 2008
New Revision: 75
Log:
Code cleanup
Modified:
trunk/java/ch/idok/qtgui/PreviewWidget.java
Modified: trunk/java/ch/idok/qtgui/PreviewWidget.java
==============================================================================
--- trunk/java/ch/idok/qtgui/PreviewWidget.java (original)
+++ trunk/java/ch/idok/qtgui/PreviewWidget.java Wed Apr 30 16:14:40 2008
@@ -27,7 +27,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.Authenticator;
import java.net.HttpURLConnection;
@@ -41,17 +40,9 @@
import javax.imageio.ImageIO;
-import org.tmatesoft.svn.core.SVNErrorCode;
-import org.tmatesoft.svn.core.SVNURL;
-import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
-import org.tmatesoft.svn.core.internal.io.dav.http.IHTTPConnection;
-import org.tmatesoft.svn.core.SVNErrorMessage;
-
import ch.idok.common.errorhandling.DmsException;
-import ch.idok.common.repository.Repository;
import ch.idok.common.repository.RepositoryPath;
-
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
import com.trolltech.qt.core.QByteArray;
@@ -77,11 +68,6 @@
import com.trolltech.qt.gui.QSpinBox;
import com.trolltech.qt.gui.QWidget;
-import
ch.idok.common.impl.repository.svn.kerberized.DmsHTTPConnectionFactory;
-import ch.idok.common.impl.repository.svn.kerberized.HTTPKerb5Authentication;
-import ch.idok.common.impl.repository.svn.SvnRepository;
-//import ch.idok.common.impl.repository.svn.kerberized.HTTPConnection;
-
/**
* Previews contents of a single file, both images and text are supported
*/
@@ -96,10 +82,6 @@
private QLabel docLabel_;
- // private QPushButton buttonLeft_;
- //
- // private QPushButton buttonRight_;
- //
private QSpinBox pdfPageSpinBox_;
int numPages_;
@@ -129,8 +111,8 @@
public Signal1<RepositoryPath> documentSelected = new
Signal1<RepositoryPath>();
-
private PDFFile pdfFile_ = null;
+
private QImage[] pictureArray;
private static QCursor BUSYCURSOR = new
QCursor(Qt.CursorShape.BusyCursor);
@@ -184,7 +166,6 @@
try {
tempPageFile_ = File.createTempFile("lastViewedPage", "");
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
tempPageFile_.deleteOnExit();
@@ -310,8 +291,6 @@
} else if (ext.equals("jpg")| ext.equals("gif")| ext.equals("tif")|
ext.equals("svg")) {
try {
QTime time = new QTime();
- int convertTime = 0;
- int displayTime = 0;
time.start();
if(fileName_.startsWith("/tmp/lastViewedFile")){
ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
@@ -323,6 +302,7 @@
imageView_.setImage(image);
enableImageView();
pdfPageSpinBox_.hide();
+ System.out.println("Display time: "+
time.elapsed() + " ms");
}else{
textView_.setText("<b> Sorry, preview of this file
type on a local drive is not yet supported </b>");
enableTextView();
@@ -333,31 +313,6 @@
}
- } else if (ext.equals("svg")) {
- try {
- QTime time = new QTime();
- int convertTime = 0;
- int displayTime = 0;
- time.start();
- if(fileName_.startsWith("/tmp/lastViewedFile")){
- ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
- outStream =
repoCon_.getCurrentRepo().getFileOverHttp(repoCon_.getCurrentRepo(),
repPath_, repPath_.getRelativeFilesystemPath() + "?png");
- byte[] buf = outStream.toByteArray();
- QPixmap pixMap = new QPixmap();
- pixMap.loadFromData(buf);
- QImage image = pixMap.toImage();
- imageView_.setImage(image);
- enableImageView();
- pdfPageSpinBox_.hide();
- }else{
- textView_.setText("<b> Sorry, preview of this file
type on a local drive is not yet supported </b>");
- enableTextView();
- }
- } catch (Exception e) {
- QMessageBox.warning(null, tr("iDok Warning"),
- tr("General PDF decoding problem:") + e.getMessage());
- }
-
}else{
textView_
.setText("<b> Sorry, preview of this file type is not
yet supported </b> <br> (Doubleclick on document to start external viewer)");
@@ -375,160 +330,8 @@
return (new PasswordAuthentication(kuser, kpass));
}
}
-
-
- static class HTTPConnection {
-
-
-// public byte[] get(String file) throws IOException {
-// byte[] bytes = null;
-// try {
-// Authenticator.setDefault(new MyAuthenticator());
-// // Put a valid url here
-// URL url = new URL(file);
-// URLConnection con = url.openConnection();
-// InputStream stream = con.getInputStream();
-// final int length = con.getContentLength( );
-// final int buflen = Math.max( 1024, Math.max( length,
stream.available() ) );
-// byte[] buf = new byte[buflen];;
-// for ( int nRead = stream.read(buf); nRead != -1; nRead =
stream.read(buf) ) {
-// if ( bytes == null ) {
-// bytes = buf;
-// buf = new byte[buflen];
-// continue;
-// }
-// final byte[] newBytes = new byte[ bytes.length + nRead ];
-// System.arraycopy( bytes, 0, newBytes, 0, bytes.length );
-// System.arraycopy( buf, 0, newBytes, bytes.length, nRead
);
-// bytes = newBytes;
-// }
-// if ( charset == null )
-// return bytes;
-// try {
-// return new String( bytes, charset );
-// }
-// catch ( java.io.UnsupportedEncodingException e ) { }
-// return bytes;
-//
-// }
- // Saved response.
- private java.util.Map<String,java.util.List<String>> responseHeader =
null;
- private java.net.URL responseURL = null;
- private int responseCode = -1;
- private String MIMEtype = null;
- private String charset = null;
- private Object content = null;
-
- /** Open a web file.
- * @return */
- public void webFile( String urlString )
- throws java.net.MalformedURLException, java.io.IOException {
- Authenticator.setDefault(new MyAuthenticator());
- // Open a URL connection.
- final URL url = new java.net.URL(urlString);
- final URLConnection uconn = url.openConnection();
- if ( !(uconn instanceof HttpURLConnection) )
- throw new java.lang.IllegalArgumentException(
- "URL protocol must be HTTP." );
- final HttpURLConnection conn = (HttpURLConnection)uconn;
-
- // Set up a request.
- conn.setConnectTimeout(10000); // 10 sec
- conn.setReadTimeout(10000); // 10 sec
- conn.setInstanceFollowRedirects( true );
- conn.setRequestProperty( "User-agent", "spider" );
-
- // Send the request.
- conn.connect( );
-
- // Get the response.
- responseHeader = conn.getHeaderFields();
- responseCode = conn.getResponseCode();
- responseURL = conn.getURL();
- final int length = conn.getContentLength();
- final String type = conn.getContentType();
- if ( type != null ) {
- final String[] parts = type.split(";");
- MIMEtype = parts[0].trim();
- for ( int i = 1; i < parts.length && charset == null; i++ ) {
- final String t = parts[i].trim();
- final int index = t.toLowerCase().indexOf( "charset=" );
- if ( index != -1 )
- charset = t.substring( index+8 );
- }
- }
-
- // Get the content.
- final InputStream stream = conn.getErrorStream( );
- if ( stream != null )
- content = readStream( length, stream );
- else if ( (content = conn.getContent()) != null &&
- content instanceof InputStream )
- content = readStream( length, (InputStream)content );
- conn.disconnect();
- }
-
- /** Read stream bytes and transcode. */
- private Object readStream( int length, java.io.InputStream stream )
- throws java.io.IOException {
- final int buflen = Math.max( 1024, Math.max( length,
stream.available() ) );
- byte[] buf = new byte[buflen];;
- byte[] bytes = null;
-
- for ( int nRead = stream.read(buf); nRead != -1; nRead =
stream.read(buf) ) {
- if ( bytes == null ) {
- bytes = buf;
- buf = new byte[buflen];
- continue;
- }
- final byte[] newBytes = new byte[ bytes.length + nRead ];
- System.arraycopy( bytes, 0, newBytes, 0, bytes.length );
- System.arraycopy( buf, 0, newBytes, bytes.length, nRead );
- bytes = newBytes;
- }
-
- if ( charset == null )
- return bytes;
- try {
- return new String( bytes, charset );
- }
- catch ( java.io.UnsupportedEncodingException e ) { }
- return bytes;
- }
-
- /** Get the content. */
- public Object getContent() {
- return content;
- }
-
- /** Get the response code. */
- public int getResponseCode() {
- return responseCode;
- }
-
- /** Get the response header. */
- public java.util.Map<String,java.util.List<String>> getHeaderFields( )
{
- return responseHeader;
- }
-
- /** Get the URL of the received page. */
- public java.net.URL getURL() {
- return responseURL;
- }
-
- /** Get the MIME type. */
- public String getMIMEType() {
- return MIMEtype;
- }
-
- /** Get the content. */
- public byte[] getByteArray() {
- return (byte[])content;
- }
-
-
- }
+
private void previewImage() {
image_ = new QImage(fileName_);
if (image_.width() * image_.height() < 8000000) {
- [idok-commit] idok commit r75 - trunk/java/ch/idok/qtgui, Apache, 04/30/2008
Archive powered by MHonArc 2.6.19.