Skip to content

Commit

Permalink
2005-09-20 Pierre-Luc Paour <gallery@paour.com> (1.4.2-b27)
Browse files Browse the repository at this point in the history
	* With G2, the slideshow now increments the view count on images.
  • Loading branch information
Pierre-Luc Paour committed Sep 20, 2005
1 parent d60985e commit 756b523
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 14 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
@@ -1,3 +1,7 @@
2005-09-20 Pierre-Luc Paour <gallery@paour.com> (1.4.2-b27)

* With G2, the slideshow now increments the view count on images.

2005-08-26 Pierre-Luc Paour <gallery@paour.com> (1.4.2-b26)

* Slideshows starting on a specific picture (G2 only) now start
Expand Down
48 changes: 45 additions & 3 deletions com/gallery/GalleryRemote/GRAppletMini.java
Expand Up @@ -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.
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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);
}
//}
}
}
5 changes: 5 additions & 0 deletions com/gallery/GalleryRemote/GalleryComm.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions com/gallery/GalleryRemote/GalleryComm2.java
Expand Up @@ -41,7 +41,6 @@
import java.net.SocketException;
import java.net.URL;
import java.net.MalformedURLException;
import java.net.URLEncoder;
import java.util.*;

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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")};
Expand Down Expand Up @@ -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);
Expand Down
64 changes: 60 additions & 4 deletions com/gallery/GalleryRemote/GalleryComm2_5.java
Expand Up @@ -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;

Expand All @@ -16,17 +19,18 @@
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;

private static int[] capabilities2;
private static int[] capabilities3;
private static int[] capabilities4;
private static int[] capabilities6;
private static int[] capabilities7;

protected GalleryComm2_5(Gallery g) {
super(g);
Expand All @@ -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++) {
Expand All @@ -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");
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions com/gallery/GalleryRemote/GalleryCommCapabilities.java
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions com/gallery/GalleryRemote/SlideshowFrame.java
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions com/gallery/GalleryRemote/StatusBar.java
Expand Up @@ -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;
Expand Down Expand Up @@ -208,6 +209,9 @@ private void resetUIState() {
}
}

public void doneUploading(String newItemName, Picture picture) {
}

class StatusLevelData {
boolean active = false;
String message;
Expand Down
4 changes: 4 additions & 0 deletions com/gallery/GalleryRemote/StatusUpdate.java
Expand Up @@ -20,6 +20,8 @@
*/
package com.gallery.GalleryRemote;

import com.gallery.GalleryRemote.model.Picture;

/**
* This interface decouples the status updating methods from MainFrame.
*
Expand Down Expand Up @@ -60,4 +62,6 @@ public interface StatusUpdate {
public void setInProgress(boolean inProgress);

public void error(String message);

public void doneUploading(String newItemName, Picture picture);
}
5 changes: 5 additions & 0 deletions com/gallery/GalleryRemote/StatusUpdateAdapter.java
Expand Up @@ -20,6 +20,8 @@
*/
package com.gallery.GalleryRemote;

import com.gallery.GalleryRemote.model.Picture;

/**
* This is an event adapter for the StatusUpdateListener class.
*
Expand Down Expand Up @@ -67,4 +69,7 @@ public int getProgressMinValue(int level) {
public int getProgressMaxValue(int level) {
return 0;
}

public void doneUploading(String newItemName, Picture picture) {
}
}
4 changes: 4 additions & 0 deletions com/gallery/GalleryRemote/UploadProgress.java
Expand Up @@ -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;
Expand Down Expand Up @@ -263,4 +264,7 @@ public void setCancelListener(ActionListener cancelListener) {
public boolean isShutdown() {
return jShutdown.isSelected();
}

public void doneUploading(String newItemName, Picture picture) {
}
}
9 changes: 8 additions & 1 deletion com/gallery/GalleryRemote/model/Gallery.java
Expand Up @@ -42,7 +42,6 @@
* Gallery model
*
* @author paour
* @created 17 août 2002
*/

public class Gallery extends DefaultTreeModel implements Serializable, PreferenceNames {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 756b523

Please sign in to comment.