diff --git a/biz.ganttproject.impex.google/build.gradle b/biz.ganttproject.impex.google/build.gradle new file mode 100644 index 0000000000..52a85b1e33 --- /dev/null +++ b/biz.ganttproject.impex.google/build.gradle @@ -0,0 +1,36 @@ +apply plugin: 'java' +apply plugin: 'idea' + +dependencies { + compile fileTree(dir: 'lib', include: ['*.jar']) + compile project(':..:ganttproject') + mavenDeps group: 'com.google.api-client', name: 'google-api-client', version: '1.22.0' + mavenDeps group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.22.0' + mavenDeps group: 'com.google.apis', name: 'google-api-services-calendar', version: 'v3-rev237-1.22.0' +} + +updateMavenDeps.doFirst { + into project.ext.libDir +} + +sourceSets { + main { + java { + srcDir 'src' + } + resources { + } + } +} + +task copyPlugin(type: Copy) { + into(new File(rootProject.pluginsDir, project.name)) + from(jar.outputs.getFiles().getFiles().flatten()) + from(fileTree(".")) { + include "plugin.xml" + include "lib/**.jar" + } + doLast { + println "Copying $project.name to $rootProject.pluginsDir" + } +} diff --git a/biz.ganttproject.impex.google/plugin.xml b/biz.ganttproject.impex.google/plugin.xml new file mode 100644 index 0000000000..60f2e122ad --- /dev/null +++ b/biz.ganttproject.impex.google/plugin.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ganttproject/src/biz/ganttproject/impex/google/GoogleExportOptionPageProvider.java b/biz.ganttproject.impex.google/src/biz/ganttproject/impex/google/ExporterToGoogle.java similarity index 56% rename from ganttproject/src/biz/ganttproject/impex/google/GoogleExportOptionPageProvider.java rename to biz.ganttproject.impex.google/src/biz/ganttproject/impex/google/ExporterToGoogle.java index 0396e33d85..a8cc4a5a3b 100644 --- a/ganttproject/src/biz/ganttproject/impex/google/GoogleExportOptionPageProvider.java +++ b/biz.ganttproject.impex.google/src/biz/ganttproject/impex/google/ExporterToGoogle.java @@ -17,53 +17,82 @@ package biz.ganttproject.impex.google; import biz.ganttproject.core.option.GPOptionGroup; +import com.google.api.services.calendar.model.CalendarListEntry; import net.sourceforge.ganttproject.GPLogger; import net.sourceforge.ganttproject.action.GPAction; -import net.sourceforge.ganttproject.gui.options.OptionPageProviderBase; +import net.sourceforge.ganttproject.export.ExporterBase; import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.event.ActionEvent; +import java.io.File; +import java.util.List; import java.util.logging.Level; /** - * Builds option page for google authorization + * Exporter to google calendar * * @author Leonid Shatunov (shatuln@gmail.com) */ -public class GoogleExportOptionPageProvider extends OptionPageProviderBase { +public class ExporterToGoogle extends ExporterBase { private GoogleAuth myAuth = new GoogleAuth(); + private List myCalendars; - public GoogleExportOptionPageProvider() { - super("impex.google"); + @Override + public String getFileTypeDescription() { + return language.getText("impex.google.description"); + } + + @Override + public GPOptionGroup getOptions() { + return null; + } + + @Override + public List getSecondaryOptions() { + return null; } @Override - public GPOptionGroup[] getOptionGroups() { - return new GPOptionGroup[0]; + public String getFileNamePattern() { + return null; } @Override - public boolean hasCustomComponent() { - return true; + public String proposeFileExtension() { + return null; } - public Component buildPageComponent() { + @Override + public String[] getFileExtensions() { + return new String[0]; + } + + @Override + public Component getCustomOptionsUI() { JPanel result = new JPanel(new BorderLayout()); result.setBorder(new EmptyBorder(5, 5, 5, 5)); JButton testConnectionButton = new JButton(new GPAction("googleConnect") { @Override public void actionPerformed(ActionEvent e) { try { - myAuth.someSampleWork(myAuth.getCalendarService(myAuth.authorize())); + myCalendars = myAuth.getAvaliableCalendarList(myAuth.getCalendarService(myAuth.authorize())); + for (CalendarListEntry i : myCalendars) { + System.out.println(i.getSummary()); + } } catch (Exception e1) { - GPLogger.getLogger(GoogleExportOptionPageProvider.class).log(Level.WARNING, "Something went wrong", e1); + GPLogger.getLogger(ExporterToGoogle.class).log(Level.WARNING, "Something went wrong", e1); } } }); result.add(testConnectionButton, BorderLayout.SOUTH); return result; } + + @Override + protected ExporterJob[] createJobs(File outputFile, List resultFiles) { + return new ExporterJob[0]; + } } \ No newline at end of file diff --git a/ganttproject/src/biz/ganttproject/impex/google/GoogleAuth.java b/biz.ganttproject.impex.google/src/biz/ganttproject/impex/google/GoogleAuth.java similarity index 77% rename from ganttproject/src/biz/ganttproject/impex/google/GoogleAuth.java rename to biz.ganttproject.impex.google/src/biz/ganttproject/impex/google/GoogleAuth.java index 8cdd8bde82..4e244b664f 100644 --- a/ganttproject/src/biz/ganttproject/impex/google/GoogleAuth.java +++ b/biz.ganttproject.impex.google/src/biz/ganttproject/impex/google/GoogleAuth.java @@ -24,7 +24,6 @@ import com.google.api.client.http.HttpTransport; import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.client.json.JsonFactory; -import com.google.api.client.util.DateTime; import com.google.api.services.calendar.Calendar; import com.google.api.services.calendar.CalendarScopes; @@ -33,6 +32,7 @@ import java.io.IOException; import java.security.GeneralSecurityException; +import java.util.Iterator; import java.util.List; /** @@ -68,27 +68,15 @@ public Calendar getCalendarService(Credential credential) throws GeneralSecurity .build(); } - public void someSampleWork(Calendar service) throws IOException { - // List the next 10 events from the primary calendar. - DateTime now = new DateTime(System.currentTimeMillis()); - Events events = service.events().list("primary") - .setMaxResults(10) - .setTimeMin(now) - .setOrderBy("startTime") - .setSingleEvents(true) - .execute(); - List items = events.getItems(); - if (items.isEmpty()) { - System.out.println("No upcoming events found."); - } else { - System.out.println("Upcoming events"); - for (Event event : items) { - DateTime start = event.getStart().getDateTime(); - if (start == null) { - start = event.getStart().getDate(); - } - System.out.printf("%s (%s)\n", event.getSummary(), start); - } + public List getAvaliableCalendarList(Calendar service) throws IOException { + List myCalendars = service.calendarList().list().execute().getItems(); + Iterator iter = myCalendars.iterator(); + while (iter.hasNext()) { + String role = iter.next().getAccessRole(); + if (!role.equals("owner") || !role.equals("writer")) + iter.remove(); } + return myCalendars; } + } \ No newline at end of file diff --git a/ganttproject-builder/settings.gradle b/ganttproject-builder/settings.gradle index dd50998004..9934f28060 100644 --- a/ganttproject-builder/settings.gradle +++ b/ganttproject-builder/settings.gradle @@ -1 +1 @@ -include ':..:ganttproject','..:biz.ganttproject.core','..:biz.ganttproject.impex.ical','..:biz.ganttproject.impex.msproject2','..:org.ganttproject.impex.htmlpdf','..:org.ganttproject.chart.pert','..:ganttproject-tester' +include ':..:ganttproject','..:biz.ganttproject.core','..:biz.ganttproject.impex.ical','..:biz.ganttproject.impex.msproject2','..:org.ganttproject.impex.htmlpdf','..:org.ganttproject.chart.pert','..:ganttproject-tester','..:biz.ganttproject.impex.google' diff --git a/ganttproject/build.gradle b/ganttproject/build.gradle index f6379378e7..c96b488630 100644 --- a/ganttproject/build.gradle +++ b/ganttproject/build.gradle @@ -12,9 +12,6 @@ dependencies { mavenDeps group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.1' mavenDeps group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.1' mavenDeps group: 'de.jensd', name: 'fontawesomefx-fontawesome', version: '4.6.3', transitive: true - mavenDeps group: 'com.google.api-client', name: 'google-api-client', version: '1.22.0' - mavenDeps group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.22.0' - mavenDeps group: 'com.google.apis', name: 'google-api-services-calendar', version: 'v3-rev237-1.22.0' } diff --git a/ganttproject/data/resources/language/i18n.properties b/ganttproject/data/resources/language/i18n.properties index 89e126b8dc..3e8b682b05 100644 --- a/ganttproject/data/resources/language/i18n.properties +++ b/ganttproject/data/resources/language/i18n.properties @@ -177,6 +177,7 @@ impex.csv.description = Comma-Separated-Values file impex.csv.error.parse_date = Failed to parse date {0}. Date is expected to have format {1} (e.g. today is {2}). You can change date format in the settings dialog impex.csv.importErrorReport = The following problems were detected during import. Please note that some of them may be harmless
    {0}

This report has been written to the log file. If you send it to GanttProject developers, please attach your CSV file

impex.html.description = HTML report +impex.google.description = Google Export impex.ics = iCalendar file impex.image.description = Raster image file impex.msproject.description = Microsoft Project file @@ -374,8 +375,6 @@ optionPage.impex.ftp.description #optionPage.impex.ftp.description = Configure access to your FTP-server. This data is used to publish your projects to your project to your web-server. If you specify a subdirectory, it must exist on the server. optionPage.impex.ftp.label = FTP optionPage.impex.ftp.title = FTP server settings -optionPage.impex.google.label = Google Export -optionPage.impex.google.title = Google Export settings page optionPage.project.basic.label = Name and description optionPage.project.basic.title = Basic project settings optionPage.project.calendar.label = Calendar @@ -570,7 +569,7 @@ separatedFields = Columns delimiter separator = Separator settings.app = $Settings... settings.app.description = Show GanttProject settings -settings.app.pageOrder = ui.general,pageGroup.chart,ganttChart,resourceChart,pageGroup.export,impex.ftp,impex.csv,storage.webdav,impex.google +settings.app.pageOrder = ui.general,pageGroup.chart,ganttChart,resourceChart,pageGroup.export,impex.ftp,impex.csv,storage.webdav settings.project.pageOrder = project.basic,project.calendar,project.roles shape = Shape shortDescription = Description diff --git a/ganttproject/plugin.xml b/ganttproject/plugin.xml index 6224bff578..faf6905d9f 100644 --- a/ganttproject/plugin.xml +++ b/ganttproject/plugin.xml @@ -81,40 +81,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -154,7 +120,6 @@ -