Skip to content

Commit

Permalink
QR Code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
car031 committed Dec 20, 2024
1 parent d4417a5 commit f56d387
Show file tree
Hide file tree
Showing 17 changed files with 830 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ public class Feature {
public static final int READING_CONFIRMATION = 102;

public static final int TECHNICAL_SUPPORT = 103;

public static final int CHATGPT = 104;

public static final int GOOGLE_CALENDAR = 105;

public static final int ONLYOFFICE = 107;

private static Set<String> features = new HashSet<>();
Expand Down Expand Up @@ -264,4 +264,8 @@ public static boolean showDisabled() {
public static boolean showLicensee() {
return enabled(SHOW_DISABLED);
}

public static boolean isCommercial() {
return enabled(ADDITIONAL_FORMATS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.logicaldoc.gui.common.client.widgets.DocumentSelector;
import com.logicaldoc.gui.common.client.widgets.FolderSelector;
import com.logicaldoc.gui.common.client.widgets.PasswordGenerator;
import com.logicaldoc.gui.common.client.widgets.QRFormItemIcon;
import com.logicaldoc.gui.common.client.widgets.UserSelector;
import com.logicaldoc.gui.common.client.widgets.automation.AutomationItemEditor;
import com.logicaldoc.gui.common.client.widgets.automation.HtmlItemEditor;
Expand Down Expand Up @@ -885,7 +886,7 @@ public static SelectItem newUserSelector(String name, String title, String group
boolean skipDisabled) {
return newUserSelector(name, title, groupIdOrName, !required, skipDisabled, true);
}

public static SelectItem newUserSelector(String name, String title, String groupIdOrName, boolean required,
boolean skipDisabled, boolean withClear) {
return new UserSelector(name, title, groupIdOrName, !required, skipDisabled, withClear, null);
Expand Down Expand Up @@ -1145,7 +1146,8 @@ public static SelectItem newEventsSelector(String name, String title, final Chan
select.setHeight(250);
select.setMultipleAppearance(MultipleAppearance.GRID);
select.setMultiple(true);
select.setOptionDataSource(new EventsDS(options.isFolder(), options.isWorkflow(), options.isUser(), options.isImportfolder(), options.isOcr(), options.isWebservice(), options.isAllOption()));
select.setOptionDataSource(new EventsDS(options.isFolder(), options.isWorkflow(), options.isUser(),
options.isImportfolder(), options.isOcr(), options.isWebservice(), options.isAllOption()));
select.setValueField("code");
select.setDisplayField(LABEL);
if (handler != null)
Expand All @@ -1164,11 +1166,13 @@ public static SelectItem newEventsSelector(String name, String title, final Chan
return select;
}

public static SelectItem newEventSelector(String name, String title, final ChangedHandler handler, EventSelectorOptions options) {
public static SelectItem newEventSelector(String name, String title, final ChangedHandler handler,
EventSelectorOptions options) {
final SelectItem select = newSelectItem(originalItemName(name), title);
select.setWidth(350);
select.setMultiple(false);
select.setOptionDataSource(new EventsDS(options.isFolder(), options.isWorkflow(), options.isUser(), options.isImportfolder(), options.isOcr(), options.isWebservice(), options.isAllOption()));
select.setOptionDataSource(new EventsDS(options.isFolder(), options.isWorkflow(), options.isUser(),
options.isImportfolder(), options.isOcr(), options.isWebservice(), options.isAllOption()));
select.setValueField("code");
select.setDisplayField(LABEL);
if (handler != null)
Expand Down Expand Up @@ -1883,8 +1887,16 @@ public static LinkItem newLinkItem(String name, String title, String linkTitle,
if (url != null)
linkItem.setValue(url);

linkItem.setIcons(new CopyTextFormItemIcon(textToCopy != null ? textToCopy : url,
textToCopy != null ? "copytext" : "copylink"));
QRFormItemIcon qrFormItemIcon = new QRFormItemIcon();

final CopyTextFormItemIcon copyTextFormItemIcon = new CopyTextFormItemIcon(
textToCopy != null ? textToCopy : url, textToCopy != null ? "copytext" : "copylink");

if (Feature.isCommercial())
linkItem.setIcons(copyTextFormItemIcon, qrFormItemIcon);
else
linkItem.setIcons(copyTextFormItemIcon);

return linkItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ public static void downloadTicket(String ticketId) {
download(downloadTicketURL(ticketId));
}

public static String qrURL(String content, int size) {
return Util.contextPath() + "barcode?label=false&format=QR_CODE&width=" + size + "&height=" + size + "&code="
+ content;
}

public static String qrImg(String content, int size) {
if (Feature.isCommercial())
return "<img src='" + qrURL(content, size) + "' width='" + size + "' />";
else
return "";
}

public static String displayURL(Long docId, Long folderId) {
String url = contextPath() + "display?";
if (docId != null)
Expand Down Expand Up @@ -1159,7 +1171,7 @@ public void run() {
}

/**
* Converts some HTML specific cahrd into it's entity
* Converts some HTML specific chars into it's entity
*
* @param originalText the original string to filter
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CopyTextFormItemIcon extends FormItemIcon {
public CopyTextFormItemIcon(String text, String tooltip) {
setName("copy");
setPrompt(I18N.message(tooltip));
setSrc("[SKIN]/page_white_paste.png");
setSrc("[SKIN]/paste.svg");
setWidth(16);
setHeight(16);
addFormItemClickHandler(event -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
package com.logicaldoc.gui.common.client.widgets;

import com.logicaldoc.gui.common.client.Session;
import com.logicaldoc.gui.common.client.util.Util;
import com.google.gwt.widgetideas.graphics.client.ImageLoader;
import com.logicaldoc.gui.common.client.i18n.I18N;
import com.smartgwt.client.types.HeaderControls;
import com.smartgwt.client.types.ImageStyle;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Window;

public class ImageLightbox extends Window {
public ImageLightbox(long docId, String title) {
int size = 800;
if (Session.get().getConfig("gui.tile.size") != null)
size = Integer.parseInt(Session.get().getConfig("gui.tile.size"));
int windowHeight = size + 10;
if (windowHeight > com.google.gwt.user.client.Window.getClientHeight())
windowHeight = com.google.gwt.user.client.Window.getClientHeight();

public ImageLightbox(String imageUrl, String title, int size) {
setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
setTitle(title);
setWidth("50%");
setHeight(windowHeight);
setTitle(I18N.message(title));
setCanDragResize(true);
setIsModal(true);
setShowModalMask(true);
setAutoSize(true);
centerInPage();

HTMLPanel html = new HTMLPanel(Util.tileImageHTML(docId, null, null, size));
addItem(html);
ImageLoader.loadImages(new String[] { imageUrl },
imageElements -> {
Img img = new Img(imageUrl);
img.setImageWidth(size);
img.setImageHeight(size);
img.setImageType(ImageStyle.NORMAL);
addItem(img);
});



}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.logicaldoc.gui.common.client.widgets;

import com.logicaldoc.gui.common.client.Feature;
import com.logicaldoc.gui.common.client.i18n.I18N;
import com.smartgwt.client.widgets.form.fields.FormItemIcon;

/**
* An icon to be used display a QR Code
*
* @author Marco Meschieri - LogicalDOC
* @since 9.1.1
*/
public class QRFormItemIcon extends FormItemIcon {

/**
* The constructor.
*
* @param code the text to render in the QR Code
* @param tooltip the tooltip to display
*/
public QRFormItemIcon(String code, String tooltip) {
setName("qrcode");
if (Feature.isCommercial()) {
setPrompt(I18N.message(tooltip));
setSrc("[SKIN]/qrcode.svg");
setWidth(16);
setHeight(16);

addFormItemClickHandler(event -> {
String content = code;
if (content == null)
content = event.getItem().getValue().toString();
new QRLightbox(content, "qrcode", 150).show();
});
} else {
setSrc("[SKIN]/blank.png");
setText("");
setWidth(16);
setHeight(16);
setDisabled(true);
}
}

/**
* The constructor.
*
* @param code the text to render in the QR Code
*/
public QRFormItemIcon(String code) {
this(code, "qrcode");
}

/**
* The constructor, the current item's text will be user for the QR Code
*/
public QRFormItemIcon() {
this(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.logicaldoc.gui.common.client.widgets;

import com.google.gwt.widgetideas.graphics.client.ImageLoader;
import com.logicaldoc.gui.common.client.Session;
import com.logicaldoc.gui.common.client.i18n.I18N;
import com.logicaldoc.gui.common.client.util.ItemFactory;
import com.logicaldoc.gui.common.client.util.Util;
import com.smartgwt.client.types.HeaderControls;
import com.smartgwt.client.types.ImageStyle;
import com.smartgwt.client.types.TitleOrientation;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.StaticTextItem;

/**
* A light box to show a barcode. If the barcode is a link and the provided
* content
*
* @author Marco Meschieri - LogicalDOC
* @since 9.1.1
*
*/
public class QRLightbox extends Window {
public QRLightbox(String content, String title, int size) {
setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
setTitle(I18N.message(title));
setCanDragResize(true);
setIsModal(true);
setShowModalMask(true);
setAutoSize(true);
centerInPage();

String qrUrl1 = Util.qrURL(content, size);
if ((content.startsWith("http") || content.startsWith("https")) && content.startsWith(Util.contextPath())
&& !content.startsWith(Session.get().getConfig("server.url"))) {

// We are not accessing from the declared server.url so display the additional QR with server.url
final StringBuilder content2 = new StringBuilder(Session.get().getConfig("server.url"));
if (!content2.toString().endsWith("/"))
content2.append("/");
content2.append(content.substring(Util.contextPath().length()));

String qrUrl2 = Util.qrURL(content2.toString(), size);

ImageLoader.loadImages(new String[] { qrUrl1, qrUrl2 }, imageElements -> {
StaticTextItem qr1Item = ItemFactory.newStaticTextItem("qr1", title,
"<table border='0'><tr><td><img src='" +imageElements[0].getSrc()+"' />"
+ "</td><td><a href='" + content + "' target='_blank'>"
+ content + "</a></td></tr></table>");
qr1Item.setWrap(false);
qr1Item.setWrapTitle(false);
qr1Item.setShowTitle(false);

StaticTextItem qr2Item = ItemFactory.newStaticTextItem("qr2", title,
"<table border='0'><tr><td><img src='" +imageElements[1].getSrc()+"' />"
+ "</td><td><a href='" + content2 + "' target='_blank'>"
+ content2 + "</a></td></tr></table>");
qr2Item.setWrap(false);
qr2Item.setWrapTitle(false);
qr2Item.setShowTitle(false);

DynamicForm form = new DynamicForm();
form.setMargin(2);
form.setNumCols(1);
form.setTitleOrientation(TitleOrientation.LEFT);
form.setItems(qr1Item, qr2Item);
addItem(form);
});
} else {
// We are accessing from the declared server.url so just display the QR
ImageLoader.loadImages(new String[] { qrUrl1 }, imageElements -> {
Img img = new Img(qrUrl1);
img.setImageWidth(size);
img.setImageHeight(size);
img.setImageType(ImageStyle.NORMAL);
addItem(img);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.logicaldoc.gui.common.client.Session;
import com.logicaldoc.gui.common.client.i18n.I18N;
import com.logicaldoc.gui.common.client.util.Util;
import com.logicaldoc.gui.common.client.widgets.ImageLightbox;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.Canvas;
Expand Down Expand Up @@ -46,7 +45,7 @@ private void initGUI() {
HTMLFlow thumbnailImage = new HTMLFlow(html);
thumbnailImage.addClickHandler(event -> {
if (Session.get().isShowThumbnail()) {
new ImageLightbox(docId, title).show();
new TileImageLightbox(docId, title).show();
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.logicaldoc.gui.common.client.widgets.preview;

import com.logicaldoc.gui.common.client.Session;
import com.logicaldoc.gui.common.client.util.Util;
import com.logicaldoc.gui.common.client.widgets.HTMLPanel;
import com.smartgwt.client.types.HeaderControls;
import com.smartgwt.client.widgets.Window;

public class TileImageLightbox extends Window {
public TileImageLightbox(long docId, String title) {
int size = 800;
if (Session.get().getConfig("gui.tile.size") != null)
size = Integer.parseInt(Session.get().getConfig("gui.tile.size"));
int windowHeight = size + 10;
if (windowHeight > com.google.gwt.user.client.Window.getClientHeight())
windowHeight = com.google.gwt.user.client.Window.getClientHeight();

setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
setTitle(title);
setWidth("50%");
setHeight(windowHeight);
setCanDragResize(true);
setIsModal(true);
setShowModalMask(true);
centerInPage();

HTMLPanel html = new HTMLPanel(Util.tileImageHTML(docId, null, null, size));
addItem(html);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class DocumentDetailsPanel extends VLayout implements DocumentObserver {

protected Layout securityTabPanel;

protected StandardPropertiesPanel propertiesPanel;
protected DocumentStandardPropertiesPanel propertiesPanel;

protected DocumentExtendedPropertiesPanel extendedPropertiesPanel;

Expand Down Expand Up @@ -570,7 +570,7 @@ private void prepareStandardPropertiesTab(ChangedHandler changeHandler) {
}

try {
propertiesPanel = new StandardPropertiesPanel(document, changeHandler);
propertiesPanel = new DocumentStandardPropertiesPanel(document, changeHandler);
propertiesTabPanel.addMember(propertiesPanel);
} catch (Exception t) {
// Nothing to do
Expand Down
Loading

0 comments on commit f56d387

Please sign in to comment.