From 60250b5200838ce202c62d6b263eb201055d941e Mon Sep 17 00:00:00 2001 From: Pierre-Luc Paour Date: Wed, 14 Jan 2004 01:50:18 +0000 Subject: [PATCH] 2003-01-13 Pierre-Luc Paour (1.3-b15) * Detect even more screwed up album hierarchies and display an alert to suggest a fix. --- ChangeLog | 5 ++ com/gallery/GalleryRemote/GalleryComm2.java | 52 +++++++++++--- com/gallery/GalleryRemote/model/Album.java | 10 ++- .../GalleryRemote/prefs/PreferenceNames.java | 1 + .../resources/GRResources.properties | 7 ++ .../GalleryRemote/util/ImageUtils.java | 57 +-------------- .../GalleryRemote/util/UrlMessageDialog.java | 71 +++++++++++++++++++ defaults.properties | 7 +- 8 files changed, 142 insertions(+), 68 deletions(-) create mode 100644 com/gallery/GalleryRemote/util/UrlMessageDialog.java diff --git a/ChangeLog b/ChangeLog index fa21270..5ecc481 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2003-01-13 Pierre-Luc Paour (1.3-b15) + + * Detect even more screwed up album hierarchies and + display an alert to suggest a fix. + 2003-01-11 Pierre-Luc Paour (1.3-b14) * Fixed adding album into root album: extra album would appear diff --git a/com/gallery/GalleryRemote/GalleryComm2.java b/com/gallery/GalleryRemote/GalleryComm2.java index 3c133e0..f227b40 100644 --- a/com/gallery/GalleryRemote/GalleryComm2.java +++ b/com/gallery/GalleryRemote/GalleryComm2.java @@ -29,6 +29,7 @@ import com.gallery.GalleryRemote.prefs.PreferenceNames; import com.gallery.GalleryRemote.util.GRI18n; import com.gallery.GalleryRemote.util.HTMLEscaper; +import com.gallery.GalleryRemote.util.UrlMessageDialog; import javax.swing.*; import java.awt.*; @@ -358,6 +359,8 @@ GalleryProperties requestResponse(NVPair form_data[], byte[] data, URL galUrl, b GalleryProperties p = new GalleryProperties(); p.load(new StringBufferInputStream(response)); + //mConnection.stop(); + su.stopProgress(StatusUpdate.LEVEL_UPLOAD_ONE, GRI18n.getString(MODULE, "addImgOk")); return p; @@ -857,16 +860,49 @@ private void list22() throws IOException, ModuleException { while (it.hasNext()) { Album a = (Album) it.next(); - if (a.getAlbumDepth() == depth) { + try { + if (a.getAlbumDepth() == depth) { + it.remove(); + + Album parentAlbum = a.getParentAlbum(); + if (parentAlbum == null) { + orderedAlbums.add(a); + } else { + int i = orderedAlbums.indexOf(parentAlbum); + orderedAlbums.add(i + 1, a); + } + } + } catch (IllegalArgumentException e) { it.remove(); - - Album parentAlbum = a.getParentAlbum(); - if (parentAlbum == null) { - orderedAlbums.add(a); - } else { - int i = orderedAlbums.indexOf(parentAlbum); - orderedAlbums.add(i + 1, a); + Log.log(Log.LEVEL_TRACE, MODULE, "Gallery server album list is corrupted: " + + "album " + a.getName() + " has a bad containment hierarchy."); + + /*JOptionPane.showMessageDialog(GalleryRemote.getInstance().mainFrame, + GRI18n.getString(MODULE, "fixCorrupted", new String[] { + a.getTitle(), + a.getGallery().getGalleryUrl(a.getName()).toString()}), + GRI18n.getString(MODULE, "fixCorruptedTitle"), + JOptionPane.ERROR_MESSAGE);*/ + + if (! GalleryRemote.getInstance().properties.getBooleanProperty(SUPPRESS_WARNING_CORRUPTED)) { + UrlMessageDialog md = new UrlMessageDialog( + GRI18n.getString(MODULE, "fixCorrupted", new String[] { + a.getTitle(), + a.getGallery().getGalleryUrl(a.getName()).toString()}), + a.getGallery().getGalleryUrl(GRI18n.getString(MODULE, "fixCorruptedUrl", new String[] { + a.getName()} )).toString(), + null); + + if (md.dontShow()) { + GalleryRemote.getInstance().properties.setBooleanProperty(SUPPRESS_WARNING_CORRUPTED, true); + } } + + // This doesn't work: there's a problem with the connection (maybe not re-entrant...) + //if (answer == JOptionPane.YES_OPTION) { + //a.moveAlbumTo(su, null); + //moveAlbum(su, a, null, true); + //} } } diff --git a/com/gallery/GalleryRemote/model/Album.java b/com/gallery/GalleryRemote/model/Album.java index 72d8a25..696fa67 100644 --- a/com/gallery/GalleryRemote/model/Album.java +++ b/com/gallery/GalleryRemote/model/Album.java @@ -687,7 +687,7 @@ void setPicturesList(ArrayList pictures) { notifyListeners(); } - public int getAlbumDepth() { + public int getAlbumDepth() throws IllegalArgumentException { if (albumDepth == null) { albumDepth = new Integer(depthHelper(0)); } @@ -695,8 +695,12 @@ public int getAlbumDepth() { return albumDepth.intValue(); } - int depthHelper(int depth) { - if (getParentAlbum() != null && getParentAlbum() != this) { + int depthHelper(int depth) throws IllegalArgumentException { + if (getParentAlbum() == this || depth > 20) { + throw new IllegalArgumentException("Circular containment hierarchy. Gallery corrupted!"); + } + + if (getParentAlbum() != null) { return getParentAlbum().depthHelper(depth + 1); } else { return depth; diff --git a/com/gallery/GalleryRemote/prefs/PreferenceNames.java b/com/gallery/GalleryRemote/prefs/PreferenceNames.java index d64161d..f6aee0a 100644 --- a/com/gallery/GalleryRemote/prefs/PreferenceNames.java +++ b/com/gallery/GalleryRemote/prefs/PreferenceNames.java @@ -60,4 +60,5 @@ public interface PreferenceNames { // Other public static final String SUPPRESS_WARNING_IM = "suppressWarningIM"; public static final String SUPPRESS_WARNING_JPEGTRAN = "suppressWarningJpegtran"; + public static final String SUPPRESS_WARNING_CORRUPTED = "suppressWarningCorrupted"; } diff --git a/com/gallery/GalleryRemote/resources/GRResources.properties b/com/gallery/GalleryRemote/resources/GRResources.properties index aa6b155..afd723b 100644 --- a/com/gallery/GalleryRemote/resources/GRResources.properties +++ b/com/gallery/GalleryRemote/resources/GRResources.properties @@ -330,6 +330,13 @@ GalComm2.fetchAlbImagesDone = Received {0} images descriptions from server. GalComm2.moveAlbum = Moving album {0} to {1} GalComm2.moveAlbumDone = Album successfully moved GalComm2.rootAlbum = root album +GalComm2.fixCorrupted = The album called {0} at URL:

  {1}

is corrupted: \ + its containment hierarchy is an endless loop.
\ + Gallery Remote can help you fix this situation. Log in to the gallery that contains \ + this album with the administrator account, then click on the link below.
\ + This will fix the album by placing it at the root of the gallery.
\ + You will need then want to move it to a permanent location. +GalComm2.fixCorruptedUrl = gallery_remote2.php?cmd=move-album&protocol_version=2.7&set_albumName={0}&set_destalbumName=0 #NewAlbum module diff --git a/com/gallery/GalleryRemote/util/ImageUtils.java b/com/gallery/GalleryRemote/util/ImageUtils.java index 5d52ba2..4b55949 100644 --- a/com/gallery/GalleryRemote/util/ImageUtils.java +++ b/com/gallery/GalleryRemote/util/ImageUtils.java @@ -27,8 +27,6 @@ import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.geom.AffineTransform; import java.io.*; import java.lang.reflect.Method; @@ -815,7 +813,7 @@ static void stopUsingIM() { if (!GalleryRemote.getInstance().properties.getBooleanProperty(PreferenceNames.SUPPRESS_WARNING_IM)) { if (GalleryRemote.getInstance().mainFrame != null && GalleryRemote.getInstance().mainFrame.isVisible()) { - MessageDialog md = new MessageDialog( + UrlMessageDialog md = new UrlMessageDialog( GRI18n.getString(MODULE, "warningTextIM"), GRI18n.getString(MODULE, "warningUrlIM"), GRI18n.getString(MODULE, "warningUrlTextIM") @@ -836,7 +834,7 @@ static void stopUsingJpegtran() { if (!GalleryRemote.getInstance().properties.getBooleanProperty(PreferenceNames.SUPPRESS_WARNING_JPEGTRAN)) { if (GalleryRemote.getInstance().mainFrame != null && GalleryRemote.getInstance().mainFrame.isVisible()) { - MessageDialog md = new MessageDialog( + UrlMessageDialog md = new UrlMessageDialog( GRI18n.getString(MODULE, "warningTextJpegtran"), GRI18n.getString(MODULE, "warningUrlJpegtran"), GRI18n.getString(MODULE, "warningUrlTextJpegtran") @@ -850,55 +848,4 @@ static void stopUsingJpegtran() { } } } - - static class MessageDialog extends JDialog { - JLabel jIcon = new JLabel(); - JLabel jMessage = new JLabel(); - BrowserLink jURL = new BrowserLink(); - JCheckBox jDontShow = new JCheckBox(); - JButton jOk = new JButton(); - - public MessageDialog(String message, String url, String urlText) { - super(GalleryRemote.getInstance().mainFrame, - GRI18n.getString(MODULE, "warningTitle"), - true); - - jIcon.setIcon(UIManager.getIcon("OptionPane.warningIcon")); - setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - getContentPane().setLayout(new GridBagLayout()); - jMessage.setText(message); - jURL.setText(urlText); - jURL.setUrl(url); - jDontShow.setText(GRI18n.getString(MODULE, "warningDontShow")); - jOk.setText(GRI18n.getString(MODULE, "warningOK")); - jOk.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - setVisible(false); - } - }); - - getContentPane().add(jIcon, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 - , GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 0, 10), 0, 0)); - getContentPane().add(jMessage, new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0 - , GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0)); - getContentPane().add(jURL, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0 - , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0)); - getContentPane().add(jDontShow, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 - , GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0)); - getContentPane().add(jOk, new GridBagConstraints(2, 2, 1, 2, 0.0, 0.0 - , GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); - - getRootPane().setDefaultButton(jOk); - - pack(); - - DialogUtil.center(this, getOwner()); - - setVisible(true); - } - - public boolean dontShow() { - return jDontShow.isSelected(); - } - } } diff --git a/com/gallery/GalleryRemote/util/UrlMessageDialog.java b/com/gallery/GalleryRemote/util/UrlMessageDialog.java new file mode 100644 index 0000000..c8a0faa --- /dev/null +++ b/com/gallery/GalleryRemote/util/UrlMessageDialog.java @@ -0,0 +1,71 @@ +package com.gallery.GalleryRemote.util; + +import com.gallery.GalleryRemote.GalleryRemote; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +/** + * Created by IntelliJ IDEA. + * User: paour + * Date: Jan 13, 2004 + */ +public class UrlMessageDialog extends JDialog { + public static final String MODULE = "ImageUtils"; + JLabel jIcon = new JLabel(); + JLabel jMessage = new JLabel(); + BrowserLink jURL = new BrowserLink(); + JCheckBox jDontShow = new JCheckBox(); + JButton jOk = new JButton(); + + public UrlMessageDialog(String message, String url, String urlText) { + super(GalleryRemote.getInstance().mainFrame, + GRI18n.getString(MODULE, "warningTitle"), + true); + + jIcon.setIcon(UIManager.getIcon("OptionPane.warningIcon")); + setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + getContentPane().setLayout(new GridBagLayout()); + jMessage.setText(message); + + if (urlText != null) { + jURL.setText(urlText); + } else { + jURL.setText(url); + } + + jURL.setUrl(url); + jDontShow.setText(GRI18n.getString(MODULE, "warningDontShow")); + jOk.setText(GRI18n.getString(MODULE, "warningOK")); + jOk.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + setVisible(false); + } + }); + + getContentPane().add(jIcon, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 + , GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 5, 0, 10), 0, 0)); + getContentPane().add(jMessage, new GridBagConstraints(1, 0, 2, 1, 1.0, 1.0 + , GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0)); + getContentPane().add(jURL, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0 + , GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0)); + getContentPane().add(jDontShow, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 + , GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 0, 5), 0, 0)); + getContentPane().add(jOk, new GridBagConstraints(2, 2, 1, 2, 0.0, 0.0 + , GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); + + getRootPane().setDefaultButton(jOk); + + pack(); + + DialogUtil.center(this, getOwner()); + + setVisible(true); + } + + public boolean dontShow() { + return jDontShow.isSelected(); + } +} diff --git a/defaults.properties b/defaults.properties index 6b415f0..4f68531 100644 --- a/defaults.properties +++ b/defaults.properties @@ -100,6 +100,9 @@ uiLocale= suppressWarningIM=false suppressWarningJpegtran=false; +# Warning windows for corruped galleries +suppressWarningCorrupted=false + # # --- File Menu --- # @@ -165,6 +168,6 @@ updateUrlBeta=http://gallery.sourceforge.net/gallery_remote_version_check_beta.p # # --- Do not edit below this line --- # -version=1.3-b14 -releaseDate=2004/01/11 +version=1.3-b15 +releaseDate=2004/01/13 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\nAmedeo Paglione\nChris Schwerdt\n \n \nInitial version by Chris Smith\n \n \nContributors:\n \nTim Miller\nDolan Halbrook\nMarkus Cozowicz\nScott Gartner\n \n \nArtwork by Ross A. Reyman\n \n \nBundled software:\n \nImageMagick\nJSX\nJava look and feel Graphics Repository icons\njpegtran, Guido Vollbeding's version\nMetadataExtractor