Merge lp:~mcuelenaere/syncany/trunk into lp:~syncany-team/syncany/trunk

Proposed by Maurus Cuelenaere
Status: Needs review
Proposed branch: lp:~mcuelenaere/syncany/trunk
Merge into: lp:~syncany-team/syncany/trunk
Diff against target: 632 lines (+522/-1)
9 files modified
syncany/README (+4/-0)
syncany/build.xml (+5/-1)
syncany/nbproject/project.properties (+8/-0)
syncany/src/org/syncany/connection/plugins/dropbox/DropboxConfigPanel.form (+42/-0)
syncany/src/org/syncany/connection/plugins/dropbox/DropboxConfigPanel.java (+126/-0)
syncany/src/org/syncany/connection/plugins/dropbox/DropboxConnection.java (+121/-0)
syncany/src/org/syncany/connection/plugins/dropbox/DropboxPluginInfo.java (+57/-0)
syncany/src/org/syncany/connection/plugins/dropbox/DropboxTransferManager.java (+145/-0)
syncany/src/org/syncany/i18n/I18n_en_US.properties (+14/-0)
To merge this branch: bzr merge lp:~mcuelenaere/syncany/trunk
Reviewer Review Type Date Requested Status
Syncany Team Pending
Review via email: mp+92642@code.launchpad.net

Description of the change

Adds some minor fixes + Dropbox plugin

To post a comment you must log in.

Unmerged revisions

63. By Maurus Cuelenaere

Add Dropbox plugin

62. By Maurus Cuelenaere

Fix project.properties

61. By Maurus Cuelenaere

Fix Linux run target

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'syncany/README'
--- syncany/README 2011-06-10 18:44:48 +0000
+++ syncany/README 2012-02-11 23:28:18 +0000
@@ -62,3 +62,7 @@
62- The Syncany Rackspace plugin uses the java-cloudfiles library provided by62- The Syncany Rackspace plugin uses the java-cloudfiles library provided by
63 Rackspace (https://github.com/rackspace/java-cloudfiles). It is distributed63 Rackspace (https://github.com/rackspace/java-cloudfiles). It is distributed
64 under the GPL-compatible MIT License.64 under the GPL-compatible MIT License.
65
66- The Dropbox plugin uses the SDK provided by Dropbox
67 (https://www.dropbox.com/developers/reference/sdk). It is distributed under
68 the GPL-compatible MIT License.
6569
=== modified file 'syncany/build.xml'
--- syncany/build.xml 2011-06-05 20:06:20 +0000
+++ syncany/build.xml 2012-02-11 23:28:18 +0000
@@ -163,7 +163,11 @@
163 </fileset> 163 </fileset>
164 </copy>164 </copy>
165 </target> 165 </target>
166 166
167 <target name="run" depends="compile" if="isLinux">
168 <exec dir="bin" executable="./syncany.sh" />
169 </target>
170
167 <!--171 <!--
168172
169 There exist several targets which are by default empty and which can be 173 There exist several targets which are by default empty and which can be
170174
=== added directory 'syncany/lib/plugins/dropbox'
=== added file 'syncany/lib/plugins/dropbox/dropbox-java-sdk-1.2.3.jar'
171Binary files syncany/lib/plugins/dropbox/dropbox-java-sdk-1.2.3.jar 1970-01-01 00:00:00 +0000 and syncany/lib/plugins/dropbox/dropbox-java-sdk-1.2.3.jar 2012-02-11 23:28:18 +0000 differ175Binary files syncany/lib/plugins/dropbox/dropbox-java-sdk-1.2.3.jar 1970-01-01 00:00:00 +0000 and syncany/lib/plugins/dropbox/dropbox-java-sdk-1.2.3.jar 2012-02-11 23:28:18 +0000 differ
=== added file 'syncany/lib/plugins/dropbox/httpmime-4.0.3.jar'
172Binary files syncany/lib/plugins/dropbox/httpmime-4.0.3.jar 1970-01-01 00:00:00 +0000 and syncany/lib/plugins/dropbox/httpmime-4.0.3.jar 2012-02-11 23:28:18 +0000 differ176Binary files syncany/lib/plugins/dropbox/httpmime-4.0.3.jar 1970-01-01 00:00:00 +0000 and syncany/lib/plugins/dropbox/httpmime-4.0.3.jar 2012-02-11 23:28:18 +0000 differ
=== added file 'syncany/lib/plugins/dropbox/json_simple-1.1.jar'
173Binary files syncany/lib/plugins/dropbox/json_simple-1.1.jar 1970-01-01 00:00:00 +0000 and syncany/lib/plugins/dropbox/json_simple-1.1.jar 2012-02-11 23:28:18 +0000 differ177Binary files syncany/lib/plugins/dropbox/json_simple-1.1.jar 1970-01-01 00:00:00 +0000 and syncany/lib/plugins/dropbox/json_simple-1.1.jar 2012-02-11 23:28:18 +0000 differ
=== modified file 'syncany/nbproject/project.properties'
--- syncany/nbproject/project.properties 2011-06-05 21:47:40 +0000
+++ syncany/nbproject/project.properties 2012-02-11 23:28:18 +0000
@@ -34,6 +34,7 @@
34excludes=34excludes=
35file.reference.AbsoluteLayout.jar=lib/AbsoluteLayout.jar35file.reference.AbsoluteLayout.jar=lib/AbsoluteLayout.jar
36file.reference.AppFramework-1.03.jar=lib/AppFramework-1.03.jar36file.reference.AppFramework-1.03.jar=lib/AppFramework-1.03.jar
37file.reference.bcprov-jdk16-146.jar=lib/bcprov-jdk16-146.jar
37file.reference.box4j-1.4.0.jar=lib/plugins/box/box4j-1.4.0.jar38file.reference.box4j-1.4.0.jar=lib/plugins/box/box4j-1.4.0.jar
38file.reference.commons-cli-1.2.jar=lib/commons-cli-1.2.jar39file.reference.commons-cli-1.2.jar=lib/commons-cli-1.2.jar
39file.reference.commons-codec-1.4.jar=lib/commons-codec-1.4.jar40file.reference.commons-codec-1.4.jar=lib/commons-codec-1.4.jar
@@ -45,6 +46,7 @@
45file.reference.commons-vfs-1.0.jar=lib/commons-vfs-1.0.jar46file.reference.commons-vfs-1.0.jar=lib/commons-vfs-1.0.jar
46file.reference.derby-10.8.1.2.jar=lib/derby-10.8.1.2.jar47file.reference.derby-10.8.1.2.jar=lib/derby-10.8.1.2.jar
47file.reference.dom4j-1.6.1.jar=lib/dom4j-1.6.1.jar48file.reference.dom4j-1.6.1.jar=lib/dom4j-1.6.1.jar
49file.reference.dropbox-java-sdk-1.2.3.jar=lib/plugins/dropbox/dropbox-java-sdk-1.2.3.jar
48file.reference.eclipselink-2.2.0.jar=lib/eclipselink-2.2.0.jar50file.reference.eclipselink-2.2.0.jar=lib/eclipselink-2.2.0.jar
49file.reference.eclipselink-javax.persistence-2.0.jar=lib/eclipselink-javax.persistence-2.0.jar51file.reference.eclipselink-javax.persistence-2.0.jar=lib/eclipselink-javax.persistence-2.0.jar
50file.reference.gdata-client-1.0.jar=lib/plugins/picasa/gdata-client-1.0.jar52file.reference.gdata-client-1.0.jar=lib/plugins/picasa/gdata-client-1.0.jar
@@ -55,6 +57,7 @@
55file.reference.guava-r09.jar=lib/plugins/picasa/guava-r09.jar57file.reference.guava-r09.jar=lib/plugins/picasa/guava-r09.jar
56file.reference.httpclient-4.0.3.jar=lib/httpclient-4.0.3.jar58file.reference.httpclient-4.0.3.jar=lib/httpclient-4.0.3.jar
57file.reference.httpcore-4.1.jar=lib/httpcore-4.1.jar59file.reference.httpcore-4.1.jar=lib/httpcore-4.1.jar
60file.reference.httpmime-4.0.3.jar=lib/plugins/dropbox/httpmime-4.0.3.jar
58file.reference.inotify-java-recursive-source=../inotify-java-recursive/source61file.reference.inotify-java-recursive-source=../inotify-java-recursive/source
59file.reference.j2ssh-core-0.2.9.jar=lib/plugins/sftp/j2ssh-core-0.2.9.jar62file.reference.j2ssh-core-0.2.9.jar=lib/plugins/sftp/j2ssh-core-0.2.9.jar
60file.reference.java-cloudfiles.jar=lib/plugins/rackspace/java-cloudfiles.jar63file.reference.java-cloudfiles.jar=lib/plugins/rackspace/java-cloudfiles.jar
@@ -66,6 +69,7 @@
66file.reference.jets3t-0.8.1.jar-1=lib/plugins/shared/jets3t-0.8.1.jar69file.reference.jets3t-0.8.1.jar-1=lib/plugins/shared/jets3t-0.8.1.jar
67file.reference.jpathwatch-0-94-libs-only.jar=lib/jpathwatch-0-94-libs-only.jar70file.reference.jpathwatch-0-94-libs-only.jar=lib/jpathwatch-0-94-libs-only.jar
68file.reference.jsch-0.1.44.jar=lib/jsch-0.1.44.jar71file.reference.jsch-0.1.44.jar=lib/jsch-0.1.44.jar
72file.reference.json_simple-1.1.jar=lib/plugins/dropbox/json_simple-1.1.jar
69file.reference.log4j-1.2.jar=lib/log4j-1.2.jar73file.reference.log4j-1.2.jar=lib/log4j-1.2.jar
70file.reference.mx4j-3.0.2.jar=lib/mx4j-3.0.2.jar74file.reference.mx4j-3.0.2.jar=lib/mx4j-3.0.2.jar
71file.reference.mysql-connector-java-5.1.13-bin.jar=lib/mysql-connector-java-5.1.13-bin.jar75file.reference.mysql-connector-java-5.1.13-bin.jar=lib/mysql-connector-java-5.1.13-bin.jar
@@ -73,6 +77,7 @@
73file.reference.rabin-hash-function-2.0.jar=lib/rabin-hash-function-2.0.jar77file.reference.rabin-hash-function-2.0.jar=lib/rabin-hash-function-2.0.jar
74file.reference.sardine.jar=lib/plugins/webdav/sardine.jar78file.reference.sardine.jar=lib/plugins/webdav/sardine.jar
75file.reference.source-java=../inotify-java-recursive/source/java79file.reference.source-java=../inotify-java-recursive/source/java
80file.reference.SSHTools-j2ssh-ext-0.1.0.jar=lib/plugins/sftp/SSHTools-j2ssh-ext-0.1.0.jar
76file.reference.swing-layout-1.0.4.jar=lib/swing-layout-1.0.4.jar81file.reference.swing-layout-1.0.4.jar=lib/swing-layout-1.0.4.jar
77file.reference.swing-worker-1.1.jar=lib/swing-worker-1.1.jar82file.reference.swing-worker-1.1.jar=lib/swing-worker-1.1.jar
78includes=**83includes=**
@@ -120,8 +125,11 @@
120 ${file.reference.rabin-hash-function-2.0.jar}:\125 ${file.reference.rabin-hash-function-2.0.jar}:\
121 ${file.reference.swing-layout-1.0.4.jar}:\126 ${file.reference.swing-layout-1.0.4.jar}:\
122 ${file.reference.swing-worker-1.1.jar}:\127 ${file.reference.swing-worker-1.1.jar}:\
128 ${file.reference.dropbox-java-sdk-1.2.3.jar}:\
123 ${file.reference.bcprov-jdk16-146.jar}:\129 ${file.reference.bcprov-jdk16-146.jar}:\
124 ${file.reference.SSHTools-j2ssh-ext-0.1.0.jar}:\130 ${file.reference.SSHTools-j2ssh-ext-0.1.0.jar}:\
131 ${file.reference.httpmime-4.0.3.jar}:\
132 ${file.reference.json_simple-1.1.jar}:\
125 ${file.reference.jsch-0.1.44.jar}133 ${file.reference.jsch-0.1.44.jar}
126# Space-separated list of extra javac options134# Space-separated list of extra javac options
127javac.compilerargs=135javac.compilerargs=
128136
=== added directory 'syncany/src/org/syncany/connection/plugins/dropbox'
=== added file 'syncany/src/org/syncany/connection/plugins/dropbox/DropboxConfigPanel.form'
--- syncany/src/org/syncany/connection/plugins/dropbox/DropboxConfigPanel.form 1970-01-01 00:00:00 +0000
+++ syncany/src/org/syncany/connection/plugins/dropbox/DropboxConfigPanel.form 2012-02-11 23:28:18 +0000
@@ -0,0 +1,42 @@
1<?xml version="1.0" encoding="UTF-8" ?>
2
3<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4 <AuxValues>
5 <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
6 <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="true"/>
7 <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8 <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
9 <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
10 <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
11 <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
12 <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13 <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
14 <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,56,0,0,0,-34"/>
15 </AuxValues>
16
17 <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout">
18 <Property name="axis" type="int" value="1"/>
19 </Layout>
20 <SubComponents>
21 <Component class="javax.swing.JLabel" name="lblStatus">
22 <Properties>
23 <Property name="horizontalAlignment" type="int" value="2"/>
24 <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
25 <Connection code="resourceBundle.getString(&quot;dropbox_begin_auth&quot;)" type="code"/>
26 </Property>
27 <Property name="name" type="java.lang.String" value="lblStatus" noResource="true"/>
28 </Properties>
29 </Component>
30 <Component class="javax.swing.JButton" name="btnAuthenticate">
31 <Properties>
32 <Property name="text" type="java.lang.String" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
33 <Connection code="resourceBundle.getString(&quot;dropbox_btn_authenticate&quot;)" type="code"/>
34 </Property>
35 <Property name="name" type="java.lang.String" value="btnAuthenticate"/>
36 </Properties>
37 <Events>
38 <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnAuthenticateActionPerformed"/>
39 </Events>
40 </Component>
41 </SubComponents>
42</Form>
043
=== added file 'syncany/src/org/syncany/connection/plugins/dropbox/DropboxConfigPanel.java'
--- syncany/src/org/syncany/connection/plugins/dropbox/DropboxConfigPanel.java 1970-01-01 00:00:00 +0000
+++ syncany/src/org/syncany/connection/plugins/dropbox/DropboxConfigPanel.java 2012-02-11 23:28:18 +0000
@@ -0,0 +1,126 @@
1/*
2 * Syncany, www.syncany.org
3 * Copyright (C) 2012 Maurus Cuelenaere<mcuelenaere@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18package org.syncany.connection.plugins.dropbox;
19
20import java.awt.Desktop;
21import java.net.URI;
22import java.util.ResourceBundle;
23import javax.swing.JOptionPane;
24import org.syncany.config.Config;
25import org.syncany.connection.plugins.ConfigPanel;
26import org.syncany.connection.plugins.dropbox.DropboxConnection.DropboxAuthentication;
27
28/**
29 * @author Maurus Cuelenaere <mcuelenaere@gmail.com>
30 */
31public class DropboxConfigPanel extends ConfigPanel {
32 private ResourceBundle resourceBundle;
33 private DropboxAuthentication pendingAuthentication;
34
35 public DropboxConfigPanel(DropboxConnection connection) {
36 super(connection);
37 resourceBundle = Config.getInstance().getResourceBundle();
38 initComponents();
39 }
40
41 @Override
42 public void load() {
43 if (getConnection().isAuthenticated()) {
44 lblStatus.setText(resourceBundle.getString("dropbox_auth_success"));
45 btnAuthenticate.setText(resourceBundle.getString("dropbox_btn_reauthenticate"));
46 } else {
47 lblStatus.setText(resourceBundle.getString("dropbox_begin_auth"));
48 btnAuthenticate.setText(resourceBundle.getString("dropbox_btn_authenticate"));
49 }
50 }
51
52 @Override
53 public void save() {
54 // do nothing
55 }
56
57 @Override
58 public DropboxConnection getConnection() {
59 return (DropboxConnection) super.getConnection();
60 }
61
62 private void browseUrl(String url) {
63 try {
64 Desktop.getDesktop().browse(new URI(url));
65 } catch (Exception ex) {
66 // fallback
67 JOptionPane.showInputDialog(this, resourceBundle.getString("dropbox_browse_url"), url);
68 }
69 }
70
71 /** This method is called from within the constructor to
72 * initialize the form.
73 * WARNING: Do NOT modify this code. The content of this method is
74 * always regenerated by the Form Editor.
75 */
76 @SuppressWarnings("unchecked")
77 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
78 private void initComponents() {
79
80 lblStatus = new javax.swing.JLabel();
81 btnAuthenticate = new javax.swing.JButton();
82
83 setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
84
85 lblStatus.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
86 lblStatus.setText(resourceBundle.getString("dropbox_begin_auth"));
87 lblStatus.setName("lblStatus"); // NOI18N
88 add(lblStatus);
89
90 btnAuthenticate.setText(resourceBundle.getString("dropbox_btn_authenticate"));
91 btnAuthenticate.setName("btnAuthenticate");
92 btnAuthenticate.addActionListener(new java.awt.event.ActionListener() {
93 public void actionPerformed(java.awt.event.ActionEvent evt) {
94 btnAuthenticateActionPerformed(evt);
95 }
96 });
97 add(btnAuthenticate);
98 }// </editor-fold>//GEN-END:initComponents
99
100 private void btnAuthenticateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAuthenticateActionPerformed
101 if (pendingAuthentication != null) {
102 boolean result = pendingAuthentication.complete();
103 pendingAuthentication = null;
104
105 if (result) {
106 btnAuthenticate.setText(resourceBundle.getString("dropbox_btn_reauthenticate"));
107 lblStatus.setText(resourceBundle.getString("dropbox_auth_success"));
108 } else {
109 btnAuthenticate.setText(resourceBundle.getString("dropbox_btn_authenticate"));
110 lblStatus.setText(resourceBundle.getString("dropbox_auth_fail"));
111 }
112 } else {
113 pendingAuthentication = getConnection().authenticate();
114
115 browseUrl(pendingAuthentication.getUrl());
116
117 lblStatus.setText(resourceBundle.getString("dropbox_awaiting_auth"));
118 btnAuthenticate.setText(resourceBundle.getString("dropbox_btn_complete_authentication"));
119 }
120 }//GEN-LAST:event_btnAuthenticateActionPerformed
121
122 // Variables declaration - do not modify//GEN-BEGIN:variables
123 private javax.swing.JButton btnAuthenticate;
124 private javax.swing.JLabel lblStatus;
125 // End of variables declaration//GEN-END:variables
126}
0127
=== added file 'syncany/src/org/syncany/connection/plugins/dropbox/DropboxConnection.java'
--- syncany/src/org/syncany/connection/plugins/dropbox/DropboxConnection.java 1970-01-01 00:00:00 +0000
+++ syncany/src/org/syncany/connection/plugins/dropbox/DropboxConnection.java 2012-02-11 23:28:18 +0000
@@ -0,0 +1,121 @@
1/*
2 * Syncany, www.syncany.org
3 * Copyright (C) 2012 Maurus Cuelenaere<mcuelenaere@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18package org.syncany.connection.plugins.dropbox;
19
20import com.dropbox.client2.exception.DropboxException;
21import com.dropbox.client2.session.AccessTokenPair;
22import com.dropbox.client2.session.AppKeyPair;
23import com.dropbox.client2.session.Session;
24import com.dropbox.client2.session.WebAuthSession;
25import com.dropbox.client2.session.WebAuthSession.WebAuthInfo;
26import java.util.logging.Level;
27import java.util.logging.Logger;
28import org.syncany.config.ConfigNode;
29import org.syncany.connection.plugins.ConfigPanel;
30import org.syncany.connection.plugins.Connection;
31import org.syncany.connection.plugins.PluginInfo;
32import org.syncany.connection.plugins.TransferManager;
33import org.syncany.exceptions.ConfigException;
34
35/**
36 * @author Maurus Cuelenaere <mcuelenaere@gmail.com>
37 */
38public class DropboxConnection implements Connection {
39 private static final AppKeyPair APP_KEY = new AppKeyPair("<FILLME>", "<FILLME>");
40 private static final Logger logger = Logger.getLogger(DropboxConnection.class.getSimpleName());
41
42 private WebAuthSession authSession;
43
44 public DropboxConnection() {
45 authSession = new WebAuthSession(APP_KEY, Session.AccessType.APP_FOLDER);
46 }
47
48 public WebAuthSession getAuthSession() {
49 return authSession;
50 }
51
52 public boolean isAuthenticated() {
53 return authSession.getAccessTokenPair() != null;
54 }
55
56 public class DropboxAuthentication {
57 private final WebAuthInfo authInfo;
58
59 public DropboxAuthentication() throws DropboxException {
60 authInfo = authSession.getAuthInfo();
61 }
62
63 public String getUrl() {
64 return authInfo.url;
65 }
66
67 public boolean complete() {
68 try {
69 authSession.retrieveWebAccessToken(authInfo.requestTokenPair);
70 return true;
71 } catch (DropboxException ex) {
72 logger.log(Level.WARNING, "Couldn't complete Dropbox authentication", ex);
73 return false;
74 }
75 }
76 }
77
78 public DropboxAuthentication authenticate() {
79 try {
80 return new DropboxAuthentication();
81 } catch (DropboxException ex) {
82 logger.log(Level.WARNING, "Couldn't start Dropbox authentication", ex);
83 return null;
84 }
85 }
86
87 @Override
88 public TransferManager createTransferManager() {
89 return new DropboxTransferManager(this);
90 }
91
92 @Override
93 public ConfigPanel createConfigPanel() {
94 return new DropboxConfigPanel(this);
95 }
96
97 @Override
98 public PluginInfo getPluginInfo() {
99 return new DropboxPluginInfo();
100 }
101
102 @Override
103 public void load(ConfigNode node) throws ConfigException {
104 String key = node.getProperty("accessKey");
105 String secret = node.getProperty("accessSecret");
106
107 if (key == null || secret == null)
108 throw new ConfigException("Dropbox connection properties must at least contain the parameters 'accessKey' and 'accessSecret'.");
109
110 authSession.setAccessTokenPair(new AccessTokenPair(key, secret));
111 }
112
113 @Override
114 public void save(ConfigNode node) {
115 AccessTokenPair tokenPair = authSession.getAccessTokenPair();
116
117 node.setAttribute("type", getPluginInfo().getId());
118 node.setProperty("accessKey", tokenPair.key);
119 node.setProperty("accessSecret", tokenPair.secret);
120 }
121}
0\ No newline at end of file122\ No newline at end of file
1123
=== added file 'syncany/src/org/syncany/connection/plugins/dropbox/DropboxPluginInfo.java'
--- syncany/src/org/syncany/connection/plugins/dropbox/DropboxPluginInfo.java 1970-01-01 00:00:00 +0000
+++ syncany/src/org/syncany/connection/plugins/dropbox/DropboxPluginInfo.java 2012-02-11 23:28:18 +0000
@@ -0,0 +1,57 @@
1/*
2 * Syncany, www.syncany.org
3 * Copyright (C) 2012 Maurus Cuelenaere<mcuelenaere@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18package org.syncany.connection.plugins.dropbox;
19
20import java.util.ResourceBundle;
21import org.syncany.config.Config;
22import org.syncany.connection.plugins.Connection;
23import org.syncany.connection.plugins.PluginInfo;
24
25/**
26 * @author Maurus Cuelenaere <mcuelenaere@gmail.com>
27 */
28public class DropboxPluginInfo extends PluginInfo {
29 public static final String ID = "dropbox";
30
31 private ResourceBundle resourceBundle = Config.getInstance().getResourceBundle();
32
33 @Override
34 public String getId() {
35 return ID;
36 }
37
38 @Override
39 public String getName() {
40 return resourceBundle.getString("dropbox_plugin_name");
41 }
42
43 @Override
44 public Integer[] getVersion() {
45 return new Integer[] {0, 1};
46 }
47
48 @Override
49 public String getDescripton() {
50 return resourceBundle.getString("dropbox_plugin_description");
51 }
52
53 @Override
54 public Connection createConnection() {
55 return new DropboxConnection();
56 }
57}
058
=== added file 'syncany/src/org/syncany/connection/plugins/dropbox/DropboxTransferManager.java'
--- syncany/src/org/syncany/connection/plugins/dropbox/DropboxTransferManager.java 1970-01-01 00:00:00 +0000
+++ syncany/src/org/syncany/connection/plugins/dropbox/DropboxTransferManager.java 2012-02-11 23:28:18 +0000
@@ -0,0 +1,145 @@
1/*
2 * Syncany, www.syncany.org
3 * Copyright (C) 2012 Maurus Cuelenaere<mcuelenaere@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18package org.syncany.connection.plugins.dropbox;
19
20import com.dropbox.client2.DropboxAPI;
21import com.dropbox.client2.exception.DropboxException;
22import com.dropbox.client2.exception.DropboxServerException;
23import com.dropbox.client2.session.WebAuthSession;
24import java.io.*;
25import java.util.HashMap;
26import java.util.Map;
27import org.syncany.connection.plugins.AbstractTransferManager;
28import org.syncany.exceptions.LocalFileNotFoundException;
29import org.syncany.exceptions.RemoteFileNotFoundException;
30import org.syncany.exceptions.StorageConnectException;
31import org.syncany.exceptions.StorageException;
32import org.syncany.repository.files.RemoteFile;
33
34/**
35 * @author Maurus Cuelenaere <mcuelenaere@gmail.com>
36 */
37public class DropboxTransferManager extends AbstractTransferManager {
38 private final DropboxAPI<WebAuthSession> api;
39 private String cachedListHash;
40 private Map<String, RemoteFile> cachedListResult;
41
42 public DropboxTransferManager(DropboxConnection connection) {
43 super(connection);
44
45 api = new DropboxAPI<WebAuthSession>(connection.getAuthSession());
46 }
47
48 @Override
49 public void connect() throws StorageConnectException {
50 }
51
52 @Override
53 public void disconnect() throws StorageException {
54 }
55
56 @Override
57 public void download(RemoteFile remoteFile, File localFile) throws RemoteFileNotFoundException, StorageException {
58 String name = "/" + remoteFile.getName();
59 OutputStream out = null;
60 try {
61 out = new FileOutputStream(localFile);
62 api.getFile(name, null, out, null);
63 } catch (Exception ex) {
64 if (ex instanceof DropboxServerException) {
65 DropboxServerException sex = (DropboxServerException) ex;
66 if (sex.error == 404)
67 throw new RemoteFileNotFoundException(ex);
68 }
69
70 throw new StorageException(ex);
71 } finally {
72 if (out != null) {
73 try {
74 out.close();
75 } catch (IOException ex) {
76 throw new StorageException(ex);
77 }
78 }
79 }
80 }
81
82 @Override
83 public void upload(File localFile, RemoteFile remoteFile) throws LocalFileNotFoundException, StorageException {
84 if (!localFile.exists())
85 throw new LocalFileNotFoundException();
86
87 String name = "/" + remoteFile.getName();
88 InputStream in = null;
89 try {
90 in = new FileInputStream(localFile);
91 api.putFile(name, in, localFile.length(), null, null);
92 } catch (Exception ex) {
93 throw new StorageException(ex);
94 } finally {
95 if (in != null) {
96 try {
97 in.close();
98 } catch (IOException ex) {
99 throw new StorageException(ex);
100 }
101 }
102 }
103 }
104
105 @Override
106 public void delete(RemoteFile remoteFile) throws RemoteFileNotFoundException, StorageException {
107 try {
108 api.delete(remoteFile.getName());
109 } catch (DropboxException ex) {
110 throw new StorageException(ex);
111 }
112 }
113
114 @Override
115 public Map<String, RemoteFile> list() throws StorageException {
116 try {
117 Map<String, RemoteFile> result = new HashMap<String, RemoteFile>();
118 DropboxAPI.Entry entry = api.metadata("", 0, cachedListHash, true, null);
119 assert(!entry.isDir);
120
121 for (DropboxAPI.Entry child : entry.contents) {
122 if (child.isDeleted || child.isDir)
123 continue;
124
125 String name = child.path.substring(1); // skip the first slash
126 RemoteFile file = new RemoteFile(name, child.bytes);
127 result.put(name, file);
128 }
129
130 // update cache
131 cachedListHash = entry.hash;
132 cachedListResult = result;
133
134 return result;
135 } catch (DropboxException ex) {
136 if (ex instanceof DropboxServerException) {
137 DropboxServerException sex = (DropboxServerException) ex;
138 if (sex.error == 304)
139 return cachedListResult;
140 }
141
142 throw new StorageException(ex);
143 }
144 }
145}
0146
=== modified file 'syncany/src/org/syncany/i18n/I18n_en_US.properties'
--- syncany/src/org/syncany/i18n/I18n_en_US.properties 2011-06-04 00:29:53 +0000
+++ syncany/src/org/syncany/i18n/I18n_en_US.properties 2012-02-11 23:28:18 +0000
@@ -290,3 +290,17 @@
290webdav_path = Path:290webdav_path = Path:
291webdav_name = WebDAV291webdav_name = WebDAV
292webdav_plugin_description = Uses a WebDAV folder as data repository.292webdav_plugin_description = Uses a WebDAV folder as data repository.
293
294## DROPBOX PLUGIN
295## DROPBOX PLUGIN INFO
296dropbox_plugin_name = Dropbox
297dropbox_plugin_description = Uses Dropbox as data repository
298## DROPBOX PLUGIN CONFIG PANEL
299dropbox_auth_success = Authentication successfull!
300dropbox_auth_fail = Couldn't complete authentication!
301dropbox_begin_auth = Please start authentication
302dropbox_awaiting_auth = Awaiting authentication completion...
303dropbox_btn_authenticate = Authenticate
304dropbox_btn_reauthenticate = Re-authenticate
305dropbox_btn_complete_authentication = Complete authentication
306dropbox_browse_url = Browse to the following url:
293\ No newline at end of file307\ No newline at end of file