Skip to Content.
Sympa Menu

idok-commit - [idok-commit] idok commit r102 - trunk/java/ch/idok/qtgui

idok-commit AT lists.psi.ch

Subject: Commit emails of the iDok project

List archive

[idok-commit] idok commit r102 - trunk/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 r102 - trunk/java/ch/idok/qtgui
  • Date: Wed, 14 May 2008 13:57:50 +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 May 14 13:57:50 2008
New Revision: 102

Log:
Added a button to access the preview of certain file types + Changed the
format to comply with PSI code formatting rules

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 May 14 13:57:50 2008
@@ -80,9 +80,11 @@
private QLabel docLabel_;

private QSpinBox pdfPageSpinBox_;
-
+
private QPushButton previewButton_;

+ private QPushButton previewAnywayButton_;
+
int numPages_;

String fileName_;
@@ -109,9 +111,11 @@
private File tempPageFile_ = null;

public Signal1<RepositoryPath> documentSelected = new
Signal1<RepositoryPath>();
-
+
public boolean enablePreview = false;

+ public boolean enablePreviewAnyway = false;
+
private PDFFile pdfFile_ = null;

private QImage[] pictureArray;
@@ -156,8 +160,14 @@
layouter_.addItem(spacerItem, 1, 1);
previewButton_ = new QPushButton("Preview");
layouter_.addWidget(previewButton_, 1, 2);
- previewButton_.clicked.connect(this,"enablePreview()");
+ previewButton_.clicked.connect(this, "enablePreview()");
previewButton_.hide();
+
+ previewAnywayButton_ = new QPushButton("Preview as text");
+ layouter_.addWidget(previewAnywayButton_, 1, 2);
+ previewAnywayButton_.clicked.connect(this, "enablePreviewAnyway()");
+ previewAnywayButton_.hide();
+
layouter_.addItem(spacerItem, 1, 3);
pdfPageSpinBox_ = new QSpinBox();
layouter_.addWidget(pdfPageSpinBox_, 1, 4);
@@ -190,12 +200,17 @@
}
}
}
-
- private void enablePreview(){
+
+ private void enablePreview() {
enablePreview = true;
setDmsContents(repoCon_, repPath_);
}

+ private void enablePreviewAnyway() {
+ enablePreviewAnyway = true;
+ setDmsContents(repoCon_, repPath_);
+ }
+
public void setLocalContents(String fileName) {
fileName_ = fileName;
previewData(fileName);
@@ -207,6 +222,7 @@
repPath_ = repPath;
repoCon_ = repoC;
try {
+ previewAnywayButton_.hide();
FileOutputStream os = null;
File tempFile = File.createTempFile("lastViewedFile", "");
fileName_ = tempFile.getAbsolutePath();
@@ -215,18 +231,22 @@
repoC.getCurrentRepo().getDocumentData(repPath, os, null);
os.close();
String name = repPath.getDocumentId().getTail();
- if(!enablePreview && (name.endsWith("pdf") |
name.endsWith("odt") | name.endsWith("sxw")
- | name.endsWith("rtf") |
name.endsWith("doc") | name.endsWith("wdp")
- | name.endsWith("ods") |
name.endsWith("sxc") | name.endsWith("xls")
- | name.endsWith("csv") |
name.endsWith("tsv") | name.endsWith("odp")
- | name.endsWith("sxi") |
name.endsWith("ppt"))){
- textView_.setText("<b> Please press the button below to
generate a preview </b>");
+ if (!enablePreview
+ && (name.endsWith("pdf") | name.endsWith("odt")
+ | name.endsWith("sxw") | name.endsWith("rtf")
+ | name.endsWith("doc") | name.endsWith("wdp")
+ | name.endsWith("ods") | name.endsWith("sxc")
+ | name.endsWith("xls") | name.endsWith("csv")
+ | name.endsWith("tsv") | name.endsWith("odp")
+ | name.endsWith("sxi") | name.endsWith("ppt"))) {
+ textView_
+ .setText("<b> Please press the button below to
generate a preview </b>");
enableTextView();
previewButton_.show();
pdfPageSpinBox_.hide();
- }else{
- previewData(name);
- previewButton_.hide();
+ } else {
+ previewData(name);
+ previewButton_.hide();
}
enablePreview = false;
tempFile.delete();
@@ -245,18 +265,26 @@
}

private void previewData(String name) {
- int pos = name.lastIndexOf(".");
- String ext = name.substring(pos + 1, pos + 4).toLowerCase();
+ setCursor(BUSYCURSOR);
+
+ String ext = new String("");
+ if ((name.length() >= 2) && name.contains(".")) {
+ ext = name.split("\\.")[name.split("\\.").length - 1];
+ ext = ext.toLowerCase();
+ }
+
if (imageFilters_.contains(ext)) {
// Should contain: bmp,pbm,pgm,png,ppm,xbm,xpm
previewImage();
pdfPageSpinBox_.hide();
- } else if (ext.equals("txt") | ext.equals("htm") | ext.equals("xml")
- | ext.equals("tex") | ext.equals("log") | ext.equals("sh")
- | ext.equals("bat") | ext.equals("cmd")) {
+ } else if (ext.contains("txt") | ext.contains("htm")
+ | ext.contains("xml") | ext.contains("tex")
+ | ext.contains("log") | ext.contains("sh")
+ | ext.contains("bat") | ext.contains("cmd")
+ | ext.contains("py")) {
previewText();
pdfPageSpinBox_.hide();
- } else if (ext.equals("pdf")) {
+ } else if (ext.contains("pdf")) {
// fileName_ contains the local copy of the PDF file
try {
QTime time = new QTime();
@@ -280,11 +308,13 @@
QMessageBox.warning(null, tr("iDok Warning"),
tr("General PDF decoding problem:") +
e.getMessage());
}
- } else if (ext.equals("odt") | ext.equals("sxw") | ext.equals("rtf")
- | ext.equals("doc") | ext.equals("wpd") | ext.equals("ods")
- | ext.equals("sxc") | ext.equals("xls") | ext.equals("csv")
- | ext.equals("tsv") | ext.equals("odp") | ext.equals("sxi")
- | ext.equals("ppt")) {
+ } else if (ext.contains("odt") | ext.contains("sxw")
+ | ext.contains("rtf") | ext.contains("doc")
+ | ext.contains("wpd") | ext.contains("ods")
+ | ext.contains("sxc") | ext.contains("xls")
+ | ext.contains("csv") | ext.contains("tsv")
+ | ext.contains("odp") | ext.contains("sxi")
+ | ext.contains("ppt")) {
try {
QTime time = new QTime();
int convertTime = 0;
@@ -293,8 +323,10 @@
if (fileName_.startsWith("/tmp/lastViewedFile")) {
ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
outStream = repoCon_.getCurrentRepo().getFileOverHttp(
- repoCon_.getCurrentRepo(), repPath_,
- repPath_.getRelativeFilesystemPath() + "?pdf");
+ repoCon_.getCurrentRepo(),
+ repPath_,
+ (repPath_.getRelativeFilesystemPath() + "?pdf")
+ .toString().replaceAll(" ", "%20"));
ByteBuffer outBuffer = ByteBuffer.wrap(outStream
.toByteArray());
outStream.close();
@@ -319,16 +351,18 @@
tr("General PDF decoding problem:") +
e.getMessage());
}

- } else if (ext.equals("jpg") | ext.equals("gif") | ext.equals("tif")
- | ext.equals("svg")) {
+ } else if (ext.contains("jpg") | ext.contains("gif")
+ | ext.contains("tif") | ext.contains("svg")) {
try {
QTime time = new QTime();
time.start();
if (fileName_.startsWith("/tmp/lastViewedFile")) {
ByteArrayOutputStream outStream = new
ByteArrayOutputStream();
outStream = repoCon_.getCurrentRepo().getFileOverHttp(
- repoCon_.getCurrentRepo(), repPath_,
- repPath_.getRelativeFilesystemPath() + "?png");
+ repoCon_.getCurrentRepo(),
+ repPath_,
+ (repPath_.getRelativeFilesystemPath() + "?png")
+ .toString().replaceAll(" ", "%20"));
byte[] buf = outStream.toByteArray();
outStream.close();
QPixmap pixMap = new QPixmap();
@@ -343,17 +377,26 @@
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 if (enablePreviewAnyway) {
+ previewText();
+ pdfPageSpinBox_.hide();
+ previewAnywayButton_.hide();
+ enablePreviewAnyway = false;
} else {
textView_
.setText("<b> Sorry, preview of this file type is not
yet supported </b> <br> (Doubleclick on document to start external viewer)");
enableTextView();
+ previewAnywayButton_.show();
+ enablePreviewAnyway = false;
}
+ unsetCursor();
}

static class MyAuthenticator extends Authenticator {



  • [idok-commit] idok commit r102 - trunk/java/ch/idok/qtgui, Apache, 05/14/2008

Archive powered by MHonArc 2.6.19.

Top of Page