Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/arduino/Arduino into test
Browse files Browse the repository at this point in the history
  • Loading branch information
penguin359 committed Apr 10, 2013
2 parents c6da87f + afc9ad2 commit c97a710
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 18 deletions.
40 changes: 36 additions & 4 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import processing.app.debug.Compiler;
import processing.app.debug.Target;
import processing.app.tools.ZipDeflater;
import processing.core.*;
import static processing.app.I18n._;

Expand Down Expand Up @@ -942,10 +943,20 @@ protected void rebuildSketchbookMenu(JMenu menu) {
}


public void rebuildImportMenu(JMenu importMenu) {
//System.out.println("rebuilding import menu");
public void rebuildImportMenu(JMenu importMenu, final Editor editor) {
importMenu.removeAll();


JMenuItem addLibraryMenuItem = new JMenuItem(_("Add Library..."));
addLibraryMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Base.this.handleAddZipLibrary(editor);
Base.this.onBoardOrPortChange();
Base.this.rebuildImportMenu(Editor.importMenu, editor);
}
});
importMenu.add(addLibraryMenuItem);
importMenu.addSeparator();

// reset the set of libraries
libraries = new HashSet<File>();

Expand Down Expand Up @@ -997,7 +1008,7 @@ public void onBoardOrPortChange() {
}


public void rebuildBoardsMenu(JMenu menu) {
public void rebuildBoardsMenu(JMenu menu, final Editor editor) {
//System.out.println("rebuilding boards menu");
menu.removeAll();
ButtonGroup group = new ButtonGroup();
Expand Down Expand Up @@ -2362,4 +2373,25 @@ static protected void listFiles(String basePath,
}
}
}


public void handleAddZipLibrary(Editor editor) {
String prompt = _("Select a zip file containing the library you'd like to add");
FileDialog fd = new FileDialog(editor, prompt, FileDialog.LOAD);
fd.setDirectory(System.getProperty("user.home"));
fd.setVisible(true);

String directory = fd.getDirectory();
String filename = fd.getFile();
if (filename == null) return;

File sourceFile = new File(directory, filename);
try {
ZipDeflater zipDeflater = new ZipDeflater(sourceFile, getSketchbookLibrariesFolder());
zipDeflater.deflate();
editor.statusNotice(_("Library added to your libraries. Check \"Import library\" menu"));
} catch (IOException e) {
editor.statusError(e);
}
}
}
8 changes: 4 additions & 4 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void windowActivated(WindowEvent e) {
// re-add the sub-menus that are shared by all windows
fileMenu.insert(sketchbookMenu, 2);
fileMenu.insert(examplesMenu, 3);
sketchMenu.insert(importMenu, 4);
//sketchMenu.insert(importMenu, 4);
toolsMenu.insert(boardsMenu, numTools);
toolsMenu.insert(serialMenu, numTools + 1);
}
Expand All @@ -188,7 +188,7 @@ public void windowDeactivated(WindowEvent e) {
// System.err.println("deactivate"); // not coming through
fileMenu.remove(sketchbookMenu);
fileMenu.remove(examplesMenu);
sketchMenu.remove(importMenu);
//sketchMenu.remove(importMenu);
toolsMenu.remove(boardsMenu);
toolsMenu.remove(serialMenu);
}
Expand Down Expand Up @@ -627,7 +627,7 @@ public void actionPerformed(ActionEvent e) {

if (importMenu == null) {
importMenu = new JMenu(_("Import Library..."));
base.rebuildImportMenu(importMenu);
base.rebuildImportMenu(importMenu, this);
}
sketchMenu.add(importMenu);

Expand Down Expand Up @@ -680,7 +680,7 @@ public void actionPerformed(ActionEvent e) {

if (boardsMenu == null) {
boardsMenu = new JMenu(_("Board"));
base.rebuildBoardsMenu(boardsMenu);
base.rebuildBoardsMenu(boardsMenu, this);
}
menu.add(boardsMenu);

Expand Down
2 changes: 1 addition & 1 deletion app/src/processing/app/Resources_fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ msgstr "Couper"

#: Editor.java:1143 Editor.java:2660
msgid "Copy"
msgstr "Coller"
msgstr "Copier"

#: Editor.java:1151 Editor.java:2668
msgid "Copy for Forum"
Expand Down
2 changes: 1 addition & 1 deletion app/src/processing/app/Resources_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Redo=R\u00e9tablir
Cut=Couper

#: Editor.java:1143 Editor.java:2660
Copy=Coller
Copy=Copier

#: Editor.java:1151 Editor.java:2668
Copy\ for\ Forum=Copier pour le forum
Expand Down
97 changes: 97 additions & 0 deletions app/src/processing/app/tools/ZipDeflater.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package processing.app.tools;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Random;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

public class ZipDeflater {

private final ZipFile zipFile;
private final File destFolder;

public ZipDeflater(File file, File destFolder) throws ZipException, IOException {
this.destFolder = destFolder;
this.zipFile = new ZipFile(file);
}

public void deflate() throws IOException {
String folderName = tempFolderNameFromZip();

File folder = new File(destFolder, folderName);

if (!folder.mkdir()) {
throw new IOException("Unable to create folder " + folderName);
}

Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
ensureFoldersOfEntryExist(folder, entry);
File entryFile = new File(folder, entry.getName());
if (entry.isDirectory()) {
entryFile.mkdir();
} else {
FileOutputStream fos = null;
InputStream zipInputStream = null;
try {
fos = new FileOutputStream(entryFile);
zipInputStream = zipFile.getInputStream(entry);
byte[] buffer = new byte[1024 * 4];
int len = -1;
while ((len = zipInputStream.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
} finally {
if (fos != null) {
fos.close();
}
if (zipInputStream != null) {
zipInputStream.close();
}
}
}
}

// Test.zip may or may not contain Test folder. We use zip name to create libraries folder. Therefore, a contained Test folder is useless and must be removed
ensureOneLevelFolder(folder);
}

private void ensureFoldersOfEntryExist(File folder, ZipEntry entry) {
String[] parts = entry.getName().split("/");
File current = folder;
for (int i = 0; i < parts.length - 1; i++) {
current = new File(current, parts[i]);
current.mkdir();
}
}

private void ensureOneLevelFolder(File folder) {
File[] files = folder.listFiles();
if (files.length == 1 && files[0].isDirectory()) {
File tempFile = new File(files[0].getPath() + new Random().nextInt(1000));
files[0].renameTo(tempFile);
for (File file : tempFile.listFiles()) {
file.renameTo(new File(folder, file.getName()));
}
tempFile.delete();
}
}

private String tempFolderNameFromZip() {
String folderName = zipFile.getName();
if (folderName.lastIndexOf(".") != -1) {
folderName = folderName.substring(0, folderName.lastIndexOf("."));
}
if (folderName.lastIndexOf(File.separator) != -1) {
folderName = folderName.substring(folderName.lastIndexOf(File.separator) + 1);
}
return folderName;
}

}
6 changes: 5 additions & 1 deletion build/shared/revisions.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

ARDUINO 1.0.5 - 2013.03.29
ARDUINO 1.0.5 - 2013.04.08

[core]

Expand All @@ -15,6 +15,10 @@ ARDUINO 1.0.5 - 2013.03.29

* Upgrades to WiFi firmwares

[ide]

* Backport from 1.5: install Library from file

ARDUINO 1.0.4 - 2013.03.11

[core]
Expand Down
17 changes: 10 additions & 7 deletions libraries/GSM/examples/GsmWebClient/GsmWebClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Web client
This sketch connects to a website through a GSM shield. Specifically,
this example downloads the URL "http://arduino.cc/" and prints it
to the Serial monitor.
this example downloads the URL "http://arduino.cc/asciilogo.txt" and
prints it to the Serial monitor.
Circuit:
* GSM shield attached to an Arduino
Expand Down Expand Up @@ -34,7 +34,7 @@ GSM gsmAccess;

// URL, path & port (for example: arduino.cc)
char server[] = "arduino.cc";
char path[] = "/";
char path[] = "/asciilogo.txt";
int port = 80; // port 80 is the default for HTTP

void setup()
Expand All @@ -48,13 +48,13 @@ void setup()
Serial.println("Starting Arduino web client.");
// connection state
boolean notConnected = true;

// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while(notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
notConnected = false;
else
{
Expand All @@ -72,7 +72,10 @@ void setup()
// Make a HTTP request:
client.print("GET ");
client.print(path);
client.println(" HTTP/1.0");
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
}
else
Expand All @@ -91,7 +94,7 @@ void loop()
char c = client.read();
Serial.print(c);
}

// if the server's disconnected, stop the client:
if (!client.available() && !client.connected())
{
Expand Down

0 comments on commit c97a710

Please sign in to comment.