Skip to content

Commit

Permalink
2008-11-25 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b43)
Browse files Browse the repository at this point in the history
* Fixed finding ImageMagick (convert) on Mac and presumably Linux.
* Added support for importing from Aperture: the user must first
  select the pictures to be imported in Aperture, and GR will use
  AppleScript to tell Aperture to export them, along with the captions,
  then GR will load the pictures.
  • Loading branch information
Pierre-Luc Paour committed Nov 26, 2008
1 parent 85e7b60 commit 15db6fb
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 44 deletions.
98 changes: 98 additions & 0 deletions ApertureToGallery.applescript
@@ -0,0 +1,98 @@
on run argv
set destination to "/tmp/"
set outputFile to "ApertureToGallery.txt"
set decision to ""

try
repeat
do shell script "/bin/ls " & destination & outputFile
tell application "System Events"
activate
set decision to display dialog "The file used to communicate between Aperture and Gallery Remote is already present. This may mean Gallery Remote has not yet finished processing Aperture's output." buttons {"Continue anyway", "Retry", "Cancel"} default button 3 with icon caution
end tell
log decision
set decision to button returned of decision
if decision is not "Retry" then
exit repeat
end if
end repeat
on error errStr number errorNumber
if errorNumber is -128 then
set decision to "Cancel"
return "user cancelled"
end if
end try

tell application "Aperture"
set myselected to the selection
set captions to {}
repeat with imageversion in myselected
if exists the value of the IPTC tag named "Caption/Abstract" of imageversion then
set myCaption to the value of the IPTC tag named "Caption/Abstract" of imageversion
copy myCaption to the end of captions
else
copy "" to the end of captions
end if
end repeat
export myselected using export setting "JPEG - Original size" to destination
set exportedFiles to the result

end tell

set fileRef to open for access (POSIX file (destination & outputFile)) with write permission
set eof fileRef to 0
try
repeat with i from 1 to count exportedFiles
set tmpFile to POSIX path of item i of exportedFiles
write tmpFile to fileRef
write "\t" & item i of captions to fileRef
write "\r" to fileRef
end repeat
end try
close access fileRef

return "done"
end run

(*script gallery
property myGalleryUrl : "http://www.paour.com/gallery2/"
property myGalleryUser : "paour"
property myGalleryPass : "charsome"
property authToken : 0
to login()
set myCommand to "curl -c /tmp/curlCookies -b /tmp/curlCookies -g \"" & myGalleryUrl & "main.php?g2_controller=remote:GalleryRemote&g2_form[cmd]=login&g2_form[protocol_version]=2.0&g2_form[uname]=" & myGalleryUser & "&g2_form[password]=" & myGalleryPass & "\""
log myCommand
do shell script myCommand
set loginResult to the result
set AppleScript's text item delimiters to "="
repeat with p in paragraphs of loginResult
if word 1 of p = "status" then
set loginStatus to word 3 of p
else if word 1 of p = "auth_token" then
set authToken to word 3 of p
end if
end repeat
if loginStatus ­ "0" then
display alert "Login failed"
end if
return loginStatus
end login
to upload of galleryPicturePath into galleryAlbum
log galleryPicturePath
log authToken
end upload
to listAlbums()
set myCommand to "curl -c /tmp/curlCookies -b /tmp/curlCookies -g \"" & myGalleryUrl & "main.php?g2_controller=remote:GalleryRemote&g2_form[cmd]=fetch-albums-prune&g2_form[protocol_version]=2.0&g2_form[no_perms]=yes&g2_form[auth_token]=" & authToken & "\""
log myCommand
do shell script myCommand
set listAlbumResult to the result
end listAlbums
end script*)
8 changes: 8 additions & 0 deletions ChangeLog
@@ -1,3 +1,11 @@
2008-11-25 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b43)

* Fixed finding ImageMagick (convert) on Mac and presumably Linux.
* Added support for importing from Aperture: the user must first
select the pictures to be imported in Aperture, and GR will use
AppleScript to tell Aperture to export them, along with the captions,
then GR will load the pictures.

2008-09-16 Pierre-Luc Paour <gallery@paour.com> (1.5.1-b42)

* Fixed blinking when dropping to the album tree.
Expand Down
2 changes: 1 addition & 1 deletion build.xml
Expand Up @@ -79,7 +79,7 @@
<delete file="GalleryRemote.jar" />
<jar destfile="GalleryRemote.jar">
<fileset dir="${build}" />
<fileset dir="." includes="*.properties" excludes="postchangelog.properties" />
<fileset dir="." includes="*.properties,ApertureToGallery.applescript" excludes="postchangelog.properties" />
<manifest>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Main-Class" value="com.gallery.GalleryRemote.GalleryRemote" />
Expand Down
4 changes: 4 additions & 0 deletions com/gallery/GalleryRemote/GalleryRemote.java
Expand Up @@ -33,6 +33,7 @@
import java.util.Enumeration;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Properties;
import java.lang.reflect.Method;

/**
Expand Down Expand Up @@ -100,6 +101,9 @@ protected void initializeGR() {
// log system properties
new GalleryProperties(System.getProperties()).logProperties(Log.LEVEL_INFO, "SysProps");

// log system environment
new GalleryProperties(System.getenv()).logProperties(Log.LEVEL_INFO, "SysEnv");

// log properties
properties.logProperties(Log.LEVEL_TRACE, "UsrProps");

Expand Down
51 changes: 51 additions & 0 deletions com/gallery/GalleryRemote/MainFrame.java
Expand Up @@ -110,6 +110,7 @@ public class MainFrame extends JFrame
JSplitPane jAlbumPictureDivider = new JSplitPane();
JButton jUploadButton = new JButton();
JButton jBrowseButton = new JButton();
JButton jApertureImport = new JButton();
JButton jSortButton = new JButton();
JComboBox jSortCombo = new JComboBox();
JButton jNewAlbumButton = new JButton();
Expand Down Expand Up @@ -157,6 +158,7 @@ public class MainFrame extends JFrame

public static final String CARD_PICTURE = "picture";
public static final String CARD_ALBUM = "album";
private File source;

public void initMainFrame() {
macOSXRegistration();
Expand Down Expand Up @@ -499,6 +501,7 @@ public void run() {
// if the selected album is uploading, disable everything
boolean enabled = !inProgress && currentAlbum != null && jAlbumTree.getModel().getChildCount(jAlbumTree.getModel().getRoot()) >= 1;
jBrowseButton.setEnabled(enabled && currentAlbum.getCanAdd());
jApertureImport.setEnabled(enabled && currentAlbum.getCanAdd());
jPictureInspector.setEnabled(enabled);
jPicturesList.setEnabled(enabled && currentAlbum.getCanAdd());
jNewAlbumButton.setEnabled(!inProgress && currentGallery != null && currentGallery.hasComm()
Expand Down Expand Up @@ -620,6 +623,45 @@ public void browseAddPictures() {
}
}

public void importApertureSelection() {
jStatusBar.startProgress(StatusUpdate.LEVEL_UNINTERUPTIBLE, 0, 100, GRI18n.getString(MODULE, "apertureStartImport"), true);
jStatusBar.setInProgress(true);
new Thread() {
public void run() {
ArrayList resultList = ImageUtils.importApertureSelection();
if (resultList == null || resultList.size() == 0) {
jStatusBar.stopProgress(StatusUpdate.LEVEL_UNINTERUPTIBLE, GRI18n.getString(MODULE, "apertureCancelImport"));
jStatusBar.setInProgress(false);
return;
}

ArrayList pictures = new ArrayList();

Iterator i = resultList.iterator();
while (i.hasNext()) {
String line = (String) i.next();
int j = line.indexOf('\t');
if (j != -1) {
String imagePath = line.substring(0, j);
String caption = line.substring(j + 1);

source = new File(imagePath);
ImageUtils.addToDelete(source);
Picture p = new Picture(getCurrentGallery(), source);
p.setCaption(caption);
pictures.add(p);
}
}

getCurrentAlbum().addPictures(pictures);
preloadThumbnails(pictures.iterator());

jStatusBar.stopProgress(StatusUpdate.LEVEL_UNINTERUPTIBLE, GRI18n.getString(MODULE, "apertureDoneImport"));
jStatusBar.setInProgress(false);
}
}.start();
}

public void addPictures(File[] files, boolean select) {
addPictures(null, files, -1, select);
}
Expand Down Expand Up @@ -975,6 +1017,9 @@ private void jbInit()
jBrowseButton.setText(GRI18n.getString(MODULE, "brwsBtnTxt"));
jBrowseButton.setActionCommand("Browse");
jBrowseButton.setToolTipText(GRI18n.getString(MODULE, "brwsBtnTip"));
jApertureImport.setText(GRI18n.getString(MODULE, "apertureBtnTxt"));
jApertureImport.setActionCommand("ApertureImport");
jApertureImport.setToolTipText(GRI18n.getString(MODULE, "apertureBtnTip"));
//jSortAlternativesButton.setText(GRI18n.getString(MODULE, "sortBtnTxt"));
jSortCombo.setActionCommand("SortAlternative");
jSortCombo.setToolTipText(GRI18n.getString(MODULE, "sortAlternativesBtnTip"));
Expand Down Expand Up @@ -1092,6 +1137,9 @@ private void jbInit()
this.getContentPane().add(jBottomPanel, new GridBagConstraints(0, 2, 1, 1, 1.0, 0.0
, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
jBottomPanel.add(jBrowseButton, null);
if (GalleryRemote.IS_MAC_OS_X) {
jBottomPanel.add(jApertureImport, null);
}
JPanel sortPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
sortPanel.add(jSortButton);
sortPanel.add(jSortCombo);
Expand Down Expand Up @@ -1173,6 +1221,7 @@ private void jbInitEvents() {
jSortButton.addActionListener(this);
jSortCombo.addActionListener(this);
jBrowseButton.addActionListener(this);
jApertureImport.addActionListener(this);
jNewGalleryButton.addActionListener(this);
//jGalleryCombo.addActionListener( this );
jAlbumTree.addTreeSelectionListener(this);
Expand Down Expand Up @@ -1390,6 +1439,8 @@ public void actionPerformed(ActionEvent e) {
newAlbum();
} else if (command.equals("Browse")) {
browseAddPictures();
} else if (command.equals("ApertureImport")) {
importApertureSelection();
} else if (command.equals("Upload")) {
uploadPictures();
} else if (command.equals("SortAlternative")) {
Expand Down
10 changes: 10 additions & 0 deletions com/gallery/GalleryRemote/prefs/GalleryProperties.java
Expand Up @@ -55,6 +55,16 @@ public GalleryProperties(Properties p) {
super(p);
}

public GalleryProperties(Map p) {
super();

Iterator names = p.keySet().iterator();
while (names.hasNext()) {
String name = (String) names.next();
super.setProperty(name, (String) p.get(name));
}
}

public GalleryProperties() {
}

Expand Down
5 changes: 5 additions & 0 deletions com/gallery/GalleryRemote/resources/GRResources.properties
Expand Up @@ -21,6 +21,11 @@ MainFrame.albums = Albums
MainFrame.panel1 = Destination Gallery
MainFrame.brwsBtnTxt = Add pictures...
MainFrame.brwsBtnTip = Find images to add to the currently selected album. This button is disabled, if the currently selected album is read-only or you're not logged in.
MainFrame.apertureBtnTxt = Aperture Import
MainFrame.apertureBtnTip = Import the current selection of pictures in Aperture. Aperture must be started and you must have selected the pictures you want to import.
MainFrame.apertureStartImport = Importing from Aperture
MainFrame.apertureCancelImport = Cancelled Aperture import
MainFrame.apertureDoneImport = Aperture Import successful
MainFrame.sortBtnTxt = Sort
MainFrame.sortBtnTip = Resort images in the current album
MainFrame.sortAlternativesBtnTip = Choose the sort order criteria
Expand Down

0 comments on commit 15db6fb

Please sign in to comment.