From 756b52396fe1df1b9542b163fffcce70e60de366 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Paour Date: Tue, 20 Sep 2005 16:28:41 +0000 Subject: [PATCH] 2005-09-20 Pierre-Luc Paour (1.4.2-b27) * With G2, the slideshow now increments the view count on images. --- ChangeLog | 4 ++ com/gallery/GalleryRemote/GRAppletMini.java | 48 +++++++++++++- com/gallery/GalleryRemote/GalleryComm.java | 5 ++ com/gallery/GalleryRemote/GalleryComm2.java | 13 ++-- com/gallery/GalleryRemote/GalleryComm2_5.java | 64 +++++++++++++++++-- .../GalleryCommCapabilities.java | 1 + com/gallery/GalleryRemote/SlideshowFrame.java | 3 + com/gallery/GalleryRemote/StatusBar.java | 4 ++ com/gallery/GalleryRemote/StatusUpdate.java | 4 ++ .../GalleryRemote/StatusUpdateAdapter.java | 5 ++ com/gallery/GalleryRemote/UploadProgress.java | 4 ++ com/gallery/GalleryRemote/model/Gallery.java | 9 ++- com/gallery/GalleryRemote/model/Picture.java | 9 +++ defaults.properties | 4 +- 14 files changed, 163 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5bfdce8..3cc8f51 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-09-20 Pierre-Luc Paour (1.4.2-b27) + + * With G2, the slideshow now increments the view count on images. + 2005-08-26 Pierre-Luc Paour (1.4.2-b26) * Slideshows starting on a specific picture (G2 only) now start diff --git a/com/gallery/GalleryRemote/GRAppletMini.java b/com/gallery/GalleryRemote/GRAppletMini.java index 5227cfa..2413948 100644 --- a/com/gallery/GalleryRemote/GRAppletMini.java +++ b/com/gallery/GalleryRemote/GRAppletMini.java @@ -24,6 +24,9 @@ import java.awt.event.KeyEvent; import java.net.URL; import java.net.MalformedURLException; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.applet.Applet; /** * Created by IntelliJ IDEA. @@ -51,6 +54,8 @@ public class GRAppletMini extends GRApplet implements GalleryRemoteCore, ActionL Gallery gallery = null; boolean inProgress = false; boolean hasHadPictures = false; + Method call; + Object window; public GRAppletMini() { coreClass = "com.gallery.GalleryRemote.GalleryRemoteMini"; @@ -148,8 +153,11 @@ public void setInProgress(boolean inProgress) { if (! (gallery.getComm(null) instanceof GalleryComm2_5) && gallery.getType() != Gallery.TYPE_APPLET) { getAppletContext().showDocument(new URL(getCodeBase().toString() + "add_photos_refresh.php"), "hack"); } - } catch (MalformedURLException e1) { - Log.logException(Log.LEVEL_ERROR, MODULE, e1); + + // use Java to Javascript scripting + g2Feedback("doneUploading", new Object[] {}); + } catch (MalformedURLException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); } hasHadPictures = false; @@ -247,6 +255,22 @@ public void keyPressed(KeyEvent e) { jListKeyPressed(e); } }); + + Class jsobject = null; + try { + jsobject = Class.forName("netscape.javascript.JSObject"); + Method getWindow = jsobject.getMethod("getWindow", new Class[] {Applet.class}); + call = jsobject.getMethod("call", new Class[] {String.class, Object[].class}); + window = getWindow.invoke(null, new Object[] { this }); + } catch (ClassNotFoundException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); + } catch (IllegalAccessException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); + } catch (NoSuchMethodException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); + } catch (InvocationTargetException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); + } } public void jListKeyPressed(KeyEvent e) { @@ -286,7 +310,12 @@ public void actionPerformed(ActionEvent e) { hasHadPictures = true; } } else if (source == jUpload) { - gallery.doUploadFiles(new UploadProgress(DialogUtil.findParentWindow(this))); + g2Feedback("startingUpload", new Object[] {}); + gallery.doUploadFiles(new UploadProgress(DialogUtil.findParentWindow(this)) { + public void doneUploading(String newItemName, Picture picture) { + g2Feedback("uploadedOne", new Object[] {newItemName, picture.toString()}); + } + }); } else if (source == jResize) { GalleryRemote._().properties.setBooleanProperty(RESIZE_BEFORE_UPLOAD, jResize.isSelected()); } @@ -327,4 +356,17 @@ public void valueChanged(ListSelectionEvent e) { jCaption.setBackground(UIManager.getColor("TextField.background")); } } + + public void g2Feedback(String method, Object[] params) { + //if (gallery.galleryVersion == 2) { + try { + Log.log(Log.LEVEL_TRACE, MODULE, "Invoking Javascript method '" + method + "' with " + params); + call.invoke(window, new Object[] {method, params}); + } catch (IllegalAccessException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); + } catch (InvocationTargetException e) { + Log.logException(Log.LEVEL_ERROR, MODULE, e); + } + //} + } } diff --git a/com/gallery/GalleryRemote/GalleryComm.java b/com/gallery/GalleryRemote/GalleryComm.java index 4e9908d..324dedc 100644 --- a/com/gallery/GalleryRemote/GalleryComm.java +++ b/com/gallery/GalleryRemote/GalleryComm.java @@ -23,6 +23,7 @@ import HTTPClient.*; import com.gallery.GalleryRemote.model.Album; +import com.gallery.GalleryRemote.model.Picture; import com.gallery.GalleryRemote.model.Gallery; import com.gallery.GalleryRemote.prefs.GalleryProperties; import com.gallery.GalleryRemote.prefs.PreferenceNames; @@ -168,6 +169,10 @@ public void login(StatusUpdate su) { throw new RuntimeException("This method is not available on this protocol"); } + public void incrementViewCount(StatusUpdate su, Picture p) { + throw new RuntimeException("This method is not available on this protocol"); + } + public void logOut() { Log.log(Log.LEVEL_INFO, MODULE, "Logging out and clearing cookies"); isLoggedIn = false; diff --git a/com/gallery/GalleryRemote/GalleryComm2.java b/com/gallery/GalleryRemote/GalleryComm2.java index 401866f..30062b5 100644 --- a/com/gallery/GalleryRemote/GalleryComm2.java +++ b/com/gallery/GalleryRemote/GalleryComm2.java @@ -41,7 +41,6 @@ import java.net.SocketException; import java.net.URL; import java.net.MalformedURLException; -import java.net.URLEncoder; import java.util.*; /** @@ -171,7 +170,8 @@ protected GalleryComm2(Gallery g) { * @param su an instance that implements the StatusUpdate interface. */ public void uploadFiles(StatusUpdate su, boolean async) { - doTask(new UploadTask(su), async); + UploadTask uploadTask = new UploadTask(su); + doTask(uploadTask, async); } /** @@ -483,7 +483,7 @@ public void actionPerformed(ActionEvent e) { Object[] params = {p.toString(), new Integer((uploadedCount + 1)), new Integer(pictures.size())}; su.updateProgressStatus(StatusUpdate.LEVEL_UPLOAD_PROGRESS, GRI18n.getString(MODULE, "upStatus", params)); - allGood = uploadPicture(p); + allGood = uploadPicture(p, p); su.updateProgressValue(StatusUpdate.LEVEL_UPLOAD_PROGRESS, ++uploadedCount); @@ -507,7 +507,7 @@ public void actionPerformed(ActionEvent e) { } } - boolean uploadPicture(Picture p) { + boolean uploadPicture(Picture p, Picture picture) { try { boolean escapeCaptions = GalleryRemote._().properties.getBooleanProperty(HTML_ESCAPE_CAPTIONS); boolean utf8 = !escapeCaptions && p.getParentAlbum().getGallery().galleryVersion == 2; @@ -573,6 +573,10 @@ boolean uploadPicture(Picture p) { Properties props = requestResponse(hdrs, data, g.getGalleryUrl(scriptName), true, su, this); if (props.getProperty("status").equals(GR_STAT_SUCCESS)) { status(su, StatusUpdate.LEVEL_UPLOAD_ONE, GRI18n.getString(MODULE, "upSucc")); + String newItemName = props.getProperty("item_name"); + if (newItemName != null) { + su.doneUploading(newItemName, picture); + } return true; } else { Object[] params = {props.getProperty("status_text")}; @@ -1133,6 +1137,7 @@ private void fetch(Album a, String albumName, ArrayList newPictures) picture.setFileSize(p.getIntProperty("image.raw_filesize." + i)); picture.setUniqueId(a.getName() + '_' + rawName); + picture.setItemId(rawName); } String forceExtension = p.getProperty("image.forceExtension." + i); diff --git a/com/gallery/GalleryRemote/GalleryComm2_5.java b/com/gallery/GalleryRemote/GalleryComm2_5.java index 7c2bd8c..9077a02 100644 --- a/com/gallery/GalleryRemote/GalleryComm2_5.java +++ b/com/gallery/GalleryRemote/GalleryComm2_5.java @@ -7,7 +7,10 @@ package com.gallery.GalleryRemote; import com.gallery.GalleryRemote.model.Gallery; +import com.gallery.GalleryRemote.model.Picture; +import com.gallery.GalleryRemote.model.Album; import com.gallery.GalleryRemote.prefs.GalleryProperties; +import com.gallery.GalleryRemote.util.GRI18n; import HTTPClient.NVPair; import HTTPClient.ModuleException; @@ -16,10 +19,10 @@ import java.util.Arrays; public class GalleryComm2_5 extends GalleryComm2 { - private static final String MODULE = "GalComm2_5"; + private static final String MODULE = "GalComm2"; /** Remote scriptname that provides version 2 of the protocol on the server. */ - public static final String SCRIPT_NAME = "main.php?g2_controller=remote:GalleryRemote&g2_form[cmd]=no-op"; + public static final String SCRIPT_NAME = "main.php?g2_controller=remote.GalleryRemote&g2_form[cmd]=no-op"; public static final boolean ZEND_DEBUG = false; @@ -27,6 +30,7 @@ public class GalleryComm2_5 extends GalleryComm2 { private static int[] capabilities3; private static int[] capabilities4; private static int[] capabilities6; + private static int[] capabilities7; protected GalleryComm2_5(Gallery g) { super(g); @@ -43,15 +47,65 @@ protected GalleryComm2_5(Gallery g) { capabilities6 = new int[]{CAPA_UPLOAD_FILES, CAPA_FETCH_ALBUMS, CAPA_UPLOAD_CAPTION, CAPA_FETCH_HIERARCHICAL, CAPA_ALBUM_INFO, CAPA_NEW_ALBUM, CAPA_FETCH_ALBUMS_PRUNE, CAPA_FETCH_ALBUM_IMAGES}; + capabilities7 = new int[]{CAPA_UPLOAD_FILES, CAPA_FETCH_ALBUMS, CAPA_UPLOAD_CAPTION, + CAPA_FETCH_HIERARCHICAL, CAPA_ALBUM_INFO, CAPA_NEW_ALBUM, CAPA_FETCH_ALBUMS_PRUNE, + CAPA_FETCH_ALBUM_IMAGES, CAPA_INCREMENT_VIEW_COUNT}; Arrays.sort(capabilities2); Arrays.sort(capabilities3); Arrays.sort(capabilities4); Arrays.sort(capabilities6); + Arrays.sort(capabilities7); g.setGalleryVersion(2); } + public void incrementViewCount(StatusUpdate su, Picture p) { + doTask(new IncrementViewCountTask(su, p), true); + } + + /** + * An extension of GalleryTask to handle moving an album. + */ + class IncrementViewCountTask extends GalleryTask { + Picture p; + + IncrementViewCountTask(StatusUpdate su, Picture p) { + super(su); + this.p = p; + } + + void runTask() { + try { + // setup the protocol parameters + NVPair form_data[] = { + new NVPair("cmd", "increment-view-count"), + new NVPair("protocol_version", PROTOCOL_VERSION), + new NVPair("itemId", p.getItemId()), + }; + Log.log(Log.LEVEL_TRACE, MODULE, "increment-view-count parameters: " + + Arrays.asList(form_data)); + + form_data = fudgeFormParameters(form_data); + + // load and validate the response + GalleryProperties p = requestResponse(form_data, su, this); + } catch (GR2Exception gr2e) { + Log.logException(Log.LEVEL_ERROR, MODULE, gr2e); + Object[] params2 = {gr2e.getMessage()}; + error(su, GRI18n.getString(MODULE, "error", params2)); + } catch (IOException ioe) { + Log.logException(Log.LEVEL_ERROR, MODULE, ioe); + Object[] params2 = {ioe.toString()}; + error(su, GRI18n.getString(MODULE, "error", params2)); + } catch (ModuleException me) { + Log.logException(Log.LEVEL_ERROR, MODULE, me); + Object[] params2 = {me.toString()}; + error(su, GRI18n.getString(MODULE, "error", params2)); + } + } + } + public NVPair[] fudgeParameters(NVPair[] data) { NVPair[] data_modified = new NVPair[data.length]; for (int i = 0; i < data.length; i++) { @@ -78,7 +132,7 @@ public NVPair[] fudgeFormParameters(NVPair form_data[]) { } } - form_data_modified[form_data.length] = new NVPair("g2_controller", "remote:GalleryRemote"); + form_data_modified[form_data.length] = new NVPair("g2_controller", "remote.GalleryRemote"); if (ZEND_DEBUG) { form_data_modified[form_data.length + 1] = new NVPair("start_debug", "1"); @@ -96,7 +150,9 @@ public NVPair[] fudgeFormParameters(NVPair form_data[]) { } void handleCapabilities() { - if (serverMinorVersion >= 6) { + if (serverMinorVersion >= 7) { + capabilities = capabilities7; + } else if (serverMinorVersion >= 6) { capabilities = capabilities6; } else if (serverMinorVersion >= 4) { capabilities = capabilities4; diff --git a/com/gallery/GalleryRemote/GalleryCommCapabilities.java b/com/gallery/GalleryRemote/GalleryCommCapabilities.java index 92b6958..0356930 100644 --- a/com/gallery/GalleryRemote/GalleryCommCapabilities.java +++ b/com/gallery/GalleryRemote/GalleryCommCapabilities.java @@ -43,4 +43,5 @@ public interface GalleryCommCapabilities { public static final int CAPA_FETCH_NON_WRITEABLE_ALBUMS = 12; public static final int CAPA_FETCH_HONORS_HIDDEN = 13; public static final int CAPA_IMAGE_MAX_SIZE = 14; + public static final int CAPA_INCREMENT_VIEW_COUNT = 15; } diff --git a/com/gallery/GalleryRemote/SlideshowFrame.java b/com/gallery/GalleryRemote/SlideshowFrame.java index 53c7ce8..5c223e0 100644 --- a/com/gallery/GalleryRemote/SlideshowFrame.java +++ b/com/gallery/GalleryRemote/SlideshowFrame.java @@ -418,6 +418,9 @@ public void pictureReady(ImageIcon image, Picture picture) { extra = picture.getExtraFieldsString(); if (picture.isOnline()) { url = picture.safeGetUrlFull().toString(); + + // update view count on Gallery + picture.getParentAlbum().getGallery().incrementViewCount(picture, GalleryRemote._().getCore().getMainStatusUpdate()); } else { url = picture.getSource().toString(); } diff --git a/com/gallery/GalleryRemote/StatusBar.java b/com/gallery/GalleryRemote/StatusBar.java index 23e7a91..8e5ec46 100644 --- a/com/gallery/GalleryRemote/StatusBar.java +++ b/com/gallery/GalleryRemote/StatusBar.java @@ -2,6 +2,7 @@ import com.gallery.GalleryRemote.util.DialogUtil; import com.gallery.GalleryRemote.util.GRI18n; +import com.gallery.GalleryRemote.model.Picture; import javax.swing.*; import javax.swing.border.BevelBorder; @@ -208,6 +209,9 @@ private void resetUIState() { } } + public void doneUploading(String newItemName, Picture picture) { + } + class StatusLevelData { boolean active = false; String message; diff --git a/com/gallery/GalleryRemote/StatusUpdate.java b/com/gallery/GalleryRemote/StatusUpdate.java index f060f33..92beea5 100644 --- a/com/gallery/GalleryRemote/StatusUpdate.java +++ b/com/gallery/GalleryRemote/StatusUpdate.java @@ -20,6 +20,8 @@ */ package com.gallery.GalleryRemote; +import com.gallery.GalleryRemote.model.Picture; + /** * This interface decouples the status updating methods from MainFrame. * @@ -60,4 +62,6 @@ public interface StatusUpdate { public void setInProgress(boolean inProgress); public void error(String message); + + public void doneUploading(String newItemName, Picture picture); } diff --git a/com/gallery/GalleryRemote/StatusUpdateAdapter.java b/com/gallery/GalleryRemote/StatusUpdateAdapter.java index bab98b8..62df9a2 100644 --- a/com/gallery/GalleryRemote/StatusUpdateAdapter.java +++ b/com/gallery/GalleryRemote/StatusUpdateAdapter.java @@ -20,6 +20,8 @@ */ package com.gallery.GalleryRemote; +import com.gallery.GalleryRemote.model.Picture; + /** * This is an event adapter for the StatusUpdateListener class. * @@ -67,4 +69,7 @@ public int getProgressMinValue(int level) { public int getProgressMaxValue(int level) { return 0; } + + public void doneUploading(String newItemName, Picture picture) { + } } diff --git a/com/gallery/GalleryRemote/UploadProgress.java b/com/gallery/GalleryRemote/UploadProgress.java index c45fa25..f26ed7d 100644 --- a/com/gallery/GalleryRemote/UploadProgress.java +++ b/com/gallery/GalleryRemote/UploadProgress.java @@ -2,6 +2,7 @@ import com.gallery.GalleryRemote.util.DialogUtil; import com.gallery.GalleryRemote.util.GRI18n; +import com.gallery.GalleryRemote.model.Picture; import javax.swing.*; import javax.swing.border.TitledBorder; @@ -263,4 +264,7 @@ public void setCancelListener(ActionListener cancelListener) { public boolean isShutdown() { return jShutdown.isSelected(); } + + public void doneUploading(String newItemName, Picture picture) { + } } \ No newline at end of file diff --git a/com/gallery/GalleryRemote/model/Gallery.java b/com/gallery/GalleryRemote/model/Gallery.java index 96d6246..14912a6 100644 --- a/com/gallery/GalleryRemote/model/Gallery.java +++ b/com/gallery/GalleryRemote/model/Gallery.java @@ -42,7 +42,6 @@ * Gallery model * * @author paour - * @created 17 août 2002 */ public class Gallery extends DefaultTreeModel implements Serializable, PreferenceNames { @@ -160,6 +159,14 @@ public String doNewAlbum(Album a, StatusUpdate su) { return newAlbumName; } + public void incrementViewCount(Picture p, StatusUpdate su) { + if (getComm(su).hasCapability(su, GalleryCommCapabilities.CAPA_INCREMENT_VIEW_COUNT)) { + Log.log(Log.LEVEL_INFO, MODULE, "Incrementing viewCount on " + p.toString()); + + getComm(su).incrementViewCount(su, p); + } + } + public void logOut() { if (comm != null) { comm.logOut(); diff --git a/com/gallery/GalleryRemote/model/Picture.java b/com/gallery/GalleryRemote/model/Picture.java index f325adb..50ec947 100644 --- a/com/gallery/GalleryRemote/model/Picture.java +++ b/com/gallery/GalleryRemote/model/Picture.java @@ -70,6 +70,7 @@ public class Picture extends GalleryItem implements Serializable, PreferenceName transient ExifData exif = null; transient String forceExtension = null; transient String uniqueId = null; + transient String itemId = null; transient String name = null; /** @@ -601,5 +602,13 @@ public String getUniqueId() { public void setUniqueId(String uniqueId) { this.uniqueId = uniqueId; } + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } } diff --git a/defaults.properties b/defaults.properties index ad0c943..a02cab5 100644 --- a/defaults.properties +++ b/defaults.properties @@ -245,6 +245,6 @@ updateUrlBeta=http://gallery.sourceforge.net/gallery_remote_version_check_beta.p # # --- Do not edit below this line --- # -version=1.4.2-b26 -releaseDate=2005/08/26 +version=1.4.2-b27 +releaseDate=2005/09/20 aboutText=Gallery Remote\n \n \nA part of the Gallery Open-Source Project\nhttp://gallery.sourceforge.net\n \n \nMaintained by:\n \nPierre-Luc Paour\n \n \nInitial version by Chris Smith\n \n \nContributors:\n \nTim Miller\nDolan Halbrook\nMarkus Cozowicz\nScott Gartner\nAmedeo Paglione\nChris Schwerdt\nSeth Ladd\n \n \nArtwork by Ross A. Reyman\n \n \nBundled software:\n \nImageMagick\nJava look and feel Graphics Repository icons\njpegtran, Guido Vollbeding's version\nMetadataExtractor