Adding project to GIT
authorMani <manikandaprasad.chandrasekar@nokia.com>
Tue, 17 Aug 2010 08:53:03 +0000 (14:23 +0530)
committerMani <manikandaprasad.chandrasekar@nokia.com>
Tue, 17 Aug 2010 08:53:03 +0000 (14:23 +0530)
40 files changed:
OfficeInterface.h [new file with mode: 0644]
README [new file with mode: 0644]
authenticationdialog.ui [new file with mode: 0644]
debian/README.Debian [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/copyright [new file with mode: 0644]
debian/rules [new file with mode: 0755]
encryptsupport.cpp [new file with mode: 0644]
encryptsupport.h [new file with mode: 0644]
filelistdialog.ui [new file with mode: 0644]
googlecontenthandler.cpp [new file with mode: 0644]
googlecontenthandler.h [new file with mode: 0644]
googledocument.cpp [new file with mode: 0644]
googledocument.h [new file with mode: 0644]
googledocumentlist.cpp [new file with mode: 0644]
googledocumentlist.h [new file with mode: 0644]
googledocumentservice.cpp [new file with mode: 0644]
googledocumentservice.h [new file with mode: 0644]
googlelistdialog.cpp [new file with mode: 0644]
googlelistdialog.h [new file with mode: 0644]
googleuploaddialog.cpp [new file with mode: 0644]
googleuploaddialog.h [new file with mode: 0644]
loginwindow.cpp [new file with mode: 0644]
loginwindow.h [new file with mode: 0644]
mimetypes.cpp [new file with mode: 0644]
mimetypes.h [new file with mode: 0644]
onlineServicesPlugin.pro [new file with mode: 0644]
onlineservicesplugin.cpp [new file with mode: 0644]
onlineservicesplugin.h [new file with mode: 0644]
slideshare.cpp [new file with mode: 0644]
slideshare.h [new file with mode: 0644]
slideshareDocument.h [new file with mode: 0644]
slidesharelistdialog.cpp [new file with mode: 0644]
slidesharelistdialog.h [new file with mode: 0644]
slideshareuploaddialog.cpp [new file with mode: 0644]
slideshareuploaddialog.h [new file with mode: 0644]
src.pro [new symlink]
uploaddialog.ui [new file with mode: 0644]

diff --git a/OfficeInterface.h b/OfficeInterface.h
new file mode 100644 (file)
index 0000000..cd4bb06
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * This file is part of Maemo 5 Office UI for KOffice
+ *
+ * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * Contact: Lassi Nieminen <lassniem@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef OFFICEINTERFACE_H
+#define OFFICEINTERFACE_H
+
+#include <QtPlugin>
+#include <QWidget>
+#include <QStringList>
+
+class OfficeInterface
+{
+public:
+
+    virtual ~OfficeInterface() {}
+
+    // This is used to give information about the currently active doc to the plugin
+    // 0 if there is no document open
+    virtual void setDocument(void *doc) = 0;
+
+    // Asks the plugin to create it's view for the main program to use
+    virtual QWidget *view() = 0;
+
+    // Should return the name of the plugin
+    virtual QString pluginName() = 0;
+
+    // Should return list of document types in presence of which this plugin
+    // should be shown in the menubar.
+    // Possible values : All, presentation, document, spreadsheet
+    //
+    // NOTE: this is not actually used yet in the main program and may be extented
+    // in the future.
+    virtual QStringList pluginSupportTypes() = 0;
+};
+
+Q_DECLARE_INTERFACE(OfficeInterface, "com.office.Freoffice.OfficeInterface/1.0")
+
+#endif
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..0e57bdf
--- /dev/null
+++ b/README
@@ -0,0 +1,32 @@
+Build Instructions
+******************
+Plugin can be built only on maemo as there are dependencies on QtMaemo libraries. Therefore, no more standalone support.
+To build it use Scratchbox or the Nokia Qt SDK.
+
+Features
+********
+SlideShare:
+> Supports download of all uploaded files in the format they were uploaded. Only file available for download are allowed for download.
+> Upload formats: Documents      odt, doc
+                  Spreadsheet    ods, xls
+                  Presentation   odp, ppt
+
+Google Documents:
+> Download formats: Documents      odt
+                    Spreadsheet    ods
+                    Presentation   odp
+                    Others         In the format they were uploaded
+> Upload formats: Documents      odt, doc
+                  Spreadsheet    ods, xls
+                  Presentation   ppt
+                  Others         No support yet
+
+Current Issues
+**************
+1) Sometimes uploads to GoogleDocuments fail because of a internal server error. If that happens try uploading again.
+2) Upload of "ods" spreadsheets to Google Documents always fails. So it has been disabled.
+
+
+Contact
+*******
+If you have any issues contact me at: kshlmster at gmail dot com
diff --git a/authenticationdialog.ui b/authenticationdialog.ui
new file mode 100644 (file)
index 0000000..0fcc756
--- /dev/null
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Dialog</class>
+ <widget class="QDialog" name="Dialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>449</width>
+    <height>135</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Account Signin</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>You need to supply Username and Password to access documents</string>
+     </property>
+     <property name="wordWrap">
+      <bool>false</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QGridLayout" name="gridLayout">
+     <item row="0" column="0">
+      <widget class="QLabel" name="label_4">
+       <property name="text">
+        <string>Site:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1">
+      <widget class="QComboBox" name="comboBox"/>
+     </item>
+     <item row="1" column="0">
+      <widget class="QLabel" name="label_2">
+       <property name="text">
+        <string>Username:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1">
+      <widget class="QLineEdit" name="userEdit">
+       <property name="text">
+        <string>@gmail.com</string>
+       </property>
+      </widget>
+     </item>
+     <item row="2" column="0">
+      <widget class="QLabel" name="label_3">
+       <property name="text">
+        <string>Password:</string>
+       </property>
+      </widget>
+     </item>
+     <item row="2" column="1">
+      <widget class="QLineEdit" name="passwordEdit">
+       <property name="inputMask">
+        <string/>
+       </property>
+       <property name="text">
+        <string/>
+       </property>
+       <property name="echoMode">
+        <enum>QLineEdit::Password</enum>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QCheckBox" name="saveCheckBox">
+       <property name="enabled">
+        <bool>true</bool>
+       </property>
+       <property name="text">
+        <string>Save Details</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="loginButton">
+       <property name="text">
+        <string>Sign In</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/debian/README.Debian b/debian/README.Debian
new file mode 100644 (file)
index 0000000..ac4a799
--- /dev/null
@@ -0,0 +1,6 @@
+freoffice-online-services-plugin-0.1 for Debian
+-----------------------------------------------
+
+<possible notes regarding this package - if none, delete this file>
+
+ -- unknown <maninc@gmail.com>  Tue, 17 Aug 2010 10:54:14 +0530
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..37e902e
--- /dev/null
@@ -0,0 +1,6 @@
+freoffice-online-services-plugin (0.1-0) unstable; urgency=low
+
+  * Initial release 
+
+ -- Mani <maninc@gmail.com>  Tue, 17 Aug 2010 10:54:14 +0530
+
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..2b800a1
--- /dev/null
@@ -0,0 +1,12 @@
+Source: freoffice-online-services-plugin
+Section: user/office
+Priority: extra
+Maintainer: Mani Chandrasekar <maninc@gmail.com>
+Build-Depends: debhelper (>= 5), libqt4-dev, freoffice-dev (>= 0.2-7)
+Standards-Version: 3.7.2
+
+Package: freoffice-online-services-plugin
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, freoffice-dev (>=0.2-7)
+Description: Online document plugin for FreOffice
+ Online document plugin for freoffice. Download/Upload documents from Google docs / Slide share to FreOffice.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644 (file)
index 0000000..32a48de
--- /dev/null
@@ -0,0 +1,10 @@
+This package was debianized by Mani Chandrasekar <maninc@gmail.com> on
+Tue, 17 Aug 2010 10:54:14 +0530.
+
+Copyright: 2010, Mani Chandrasekar, Kaushal 
+
+License:
+
+The Debian packaging is (C) 2010, unknown <maninc@gmail.com> and
+is licensed under the GPL, see `/usr/share/common-licenses/GPL'.
+
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..d9b093b
--- /dev/null
@@ -0,0 +1,57 @@
+#!/usr/bin/make -f
+
+builddir:
+       mkdir -p builddir
+
+builddir/Makefile: builddir
+       cd builddir && qmake-qt4 PREFIX=/usr ../src.pro
+
+build: build-stamp
+
+build-stamp: builddir/Makefile
+       dh_testdir
+       cd builddir && $(MAKE)
+       touch $@
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp configure-stamp
+
+       # Add here commands to clean up after the build process.
+       rm -rf builddir
+       dh_clean 
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k 
+       dh_installdirs
+
+       cd builddir && $(MAKE) INSTALL_ROOT=$(CURDIR)/debian/freoffice-online-services-plugin install
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+       dh_installchangelogs 
+       dh_installdocs
+       dh_installexamples
+       dh_installman
+       dh_link
+       dh_strip
+       dh_compress
+       dh_fixperms
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
diff --git a/encryptsupport.cpp b/encryptsupport.cpp
new file mode 100644 (file)
index 0000000..8978826
--- /dev/null
@@ -0,0 +1,107 @@
+#include "encryptsupport.h"
+
+#include <QString>
+#include <QByteArray>
+#include <QSettings>
+#include <QInputDialog>
+#include <QLineEdit>
+#include <QLabel>
+#include <QCryptographicHash>
+#include <QFile>
+#include <QMaemo5InformationBox>
+
+#include  <openssl/evp.h>
+
+encryptSupport::encryptSupport(QWidget *parent):
+        QWidget(parent)
+{
+    QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, "/tmp/");
+    getDetails();
+}
+
+void encryptSupport::getDetails()
+{
+    QSettings passphraseConf("freoffice", "plugin-encryption-support");
+    QSettings passphraseTemp(QSettings::SystemScope, "freoffice-encryption-support-temp.conf");
+    if (!passphraseTemp.contains("key")) {
+        enterPassphraseDialog();
+        return;
+    }
+    key = passphraseTemp.value("key").toByteArray();
+    iv = passphraseConf.value("iv").toByteArray();
+}
+
+void encryptSupport::enterPassphraseDialog()
+{
+    QSettings passphraseConf("freoffice", "plugin-encryption-support");
+    if(!passphraseConf.contains("hash")) {
+        newPassphraseDialog();
+        return;
+    }
+    QString hash = passphraseConf.value("hash").toString();
+    QString passphrase;
+    while(true) {
+        passphrase = QInputDialog::getText(this,"Enter Passphrase", "Enter the passphrase you used to encrypt.\n This will be done once every session only", QLineEdit::Normal,"");
+        if(QCryptographicHash::hash(passphrase.toUtf8(), QCryptographicHash::Sha1).toHex() == hash.toUtf8())
+            break;
+        QMaemo5InformationBox::information(this, "Wrong passphrase.\nEnter again.", QMaemo5InformationBox::NoTimeout);
+    }
+    QSettings passphraseTemp(QSettings::SystemScope, "freoffice-encryption-support-temp.conf");
+    passphraseTemp.setValue("key", passphrase);
+    passphraseTemp.sync();
+    getDetails();
+}
+
+void encryptSupport::newPassphraseDialog()
+{
+    QString passphrase;
+    while("" == passphrase) {
+        passphrase = QInputDialog::getText(this,"New Passphrase", "Please enter a phrase which is long.\nThis phrase will be used to encrypt your passwords and details", QLineEdit::Normal,"");
+    }
+    QSettings passphraseConf("freoffice","plugin-encryption-support");
+    QString hash(QCryptographicHash::hash(passphrase.toUtf8(), QCryptographicHash::Sha1).toHex());
+    passphraseConf.setValue("hash",hash);
+    QFile f("/dev/urandom");
+    f.open(QFile::ReadOnly);
+    QByteArray ivInit = f.read(8);
+    f.close();
+    passphraseConf.setValue("iv", ivInit);
+    passphraseConf.sync();
+    QSettings passphraseTemp(QSettings::SystemScope,"freoffice-encryption-support-temp.conf");
+    passphraseTemp.setValue("key", passphrase);
+    passphraseTemp.sync();
+    getDetails();
+}
+
+QString encryptSupport::encrypt(const QString & dataString)
+{
+    QByteArray data = dataString.toUtf8();
+    EVP_CIPHER_CTX ctx;
+    EVP_CIPHER_CTX_init(&ctx);
+    EVP_EncryptInit(&ctx, EVP_bf_cbc(), (unsigned char*)key.constData(), (unsigned char*)iv.constData());
+    unsigned char outbuf[1024];
+    int len = data.length();
+    int outlen, tmplen;
+    EVP_EncryptUpdate(&ctx, outbuf, &outlen, (unsigned char*)data.constData(), len);
+    EVP_EncryptFinal_ex(&ctx, outbuf+len, &tmplen);
+    outlen += tmplen;
+    EVP_CIPHER_CTX_cleanup(&ctx);
+    QByteArray encData((const char*)outbuf, outlen);
+    return QString(encData.toHex());
+}
+
+QString encryptSupport::decrypt(const QString &dataString)
+{
+    QByteArray data = QByteArray::fromHex(dataString.toUtf8());
+    EVP_CIPHER_CTX ctx;
+    EVP_CIPHER_CTX_init(&ctx);
+    EVP_DecryptInit(&ctx, EVP_bf_cbc(), (unsigned char*)key.constData(), (unsigned char*)iv.constData());
+    unsigned char outbuf[1024];
+    int len = data.length();
+    int outlen, tmplen;
+    EVP_DecryptUpdate(&ctx, outbuf, &outlen, (unsigned char*)data.constData(), len);
+    EVP_DecryptFinal(&ctx, outbuf+outlen, &tmplen);
+    EVP_CIPHER_CTX_cleanup(&ctx);
+    QByteArray decData((const char*)outbuf, outlen);
+    return QString(decData);
+}
diff --git a/encryptsupport.h b/encryptsupport.h
new file mode 100644 (file)
index 0000000..a14fdaf
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef ENCRYPTSUPPORT_H
+#define ENCRYPTSUPPORT_H
+
+#include <QWidget>
+class QString;
+class QByteArray;
+
+class encryptSupport:public QWidget
+{
+public:
+    encryptSupport(QWidget * parent = 0);
+    QString encrypt(const QString &);
+    QString decrypt(const QString &);
+private:
+    QByteArray key;
+    QByteArray iv;
+
+    void getDetails();
+    void newPassphraseDialog();
+    void enterPassphraseDialog();
+};
+
+#endif // ENCRYPTSUPPORT_H
diff --git a/filelistdialog.ui b/filelistdialog.ui
new file mode 100644 (file)
index 0000000..90afc2e
--- /dev/null
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>fileListDialog</class>
+ <widget class="QDialog" name="fileListDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>640</width>
+    <height>480</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>FileList</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_4">
+   <item>
+    <widget class="QTabWidget" name="listTab">
+     <property name="tabShape">
+      <enum>QTabWidget::Rounded</enum>
+     </property>
+     <property name="currentIndex">
+      <number>1</number>
+     </property>
+     <widget class="QWidget" name="documentTab">
+      <attribute name="title">
+       <string>Documents</string>
+      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout">
+       <item>
+        <widget class="QListWidget" name="documentList"/>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="presentationTab">
+      <attribute name="title">
+       <string>Presentations</string>
+      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout_2">
+       <item>
+        <widget class="QListWidget" name="presentationList"/>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="spreadsheetTab">
+      <attribute name="title">
+       <string>Spreadsheets</string>
+      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout_3">
+       <item>
+        <widget class="QListWidget" name="spreadsheetList"/>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="othersTab">
+      <attribute name="title">
+       <string>Others</string>
+      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout_5">
+       <item>
+        <widget class="QListWidget" name="othersList"/>
+       </item>
+      </layout>
+     </widget>
+    </widget>
+   </item>
+   <item>
+    <widget class="QProgressBar" name="downloadProgressBar">
+     <property name="value">
+      <number>0</number>
+     </property>
+     <property name="textVisible">
+      <bool>false</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QPushButton" name="uploadButton">
+       <property name="text">
+        <string>&amp;Upload</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="refreshButton">
+       <property name="text">
+        <string>&amp;Refresh List</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="downloadButton">
+       <property name="text">
+        <string>&amp;Download</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/googlecontenthandler.cpp b/googlecontenthandler.cpp
new file mode 100644 (file)
index 0000000..41acfdb
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ *  Copyright (c) 2010 Mani Chandrasekar <maninc@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <QtXml>
+
+#include "googledocumentlist.h"
+#include "googledocument.h"
+#include "googlecontenthandler.h"
+
+GoogleContentHandler::GoogleContentHandler()
+    : m_docList(0),
+      m_docEntry(0)
+{
+    m_docList = new GoogleDocumentList();
+}
+
+bool GoogleContentHandler::characters(const QString & ch)
+{
+    if(!insideEntry) {
+        if(QString::compare(m_nodeStack.top(), "title", Qt::CaseInsensitive) == 0) {
+            if(m_nodeStack.count() == 2)
+                m_docList->setTitle(ch);
+        } else if(QString::compare(m_nodeStack.top(), "name", Qt::CaseInsensitive) == 0) {
+            if(m_nodeStack.count() == 3)
+                m_docList->setAuthor(ch);
+        } else if(QString::compare(m_nodeStack.top(), "email", Qt::CaseInsensitive) == 0) {
+            if(m_nodeStack.count() == 3)
+                m_docList->setEmail(ch);
+        }
+    } else {
+        if(m_docEntry == 0)
+            return true;
+
+        if(QString::compare(m_nodeStack.top(), "title", Qt::CaseInsensitive) == 0) {
+            m_docEntry->setTitle(ch);
+        } else if(QString::compare(m_nodeStack.top(), "name", Qt::CaseInsensitive) == 0) {
+            m_docEntry->setAuthor(ch);
+        } else if(QString::compare(m_nodeStack.top(), "resourceId", Qt::CaseInsensitive) == 0) {
+            m_docEntry->setId(ch);
+        }
+    }
+    return true;
+}
+
+bool GoogleContentHandler::endDocument()
+{
+    //qDebug() << "GoogleContentHandler::endDocument()";
+    return true;
+}
+
+bool GoogleContentHandler::endElement(const QString & namespaceURI, const QString & localName, const QString & qName)
+{
+    //printName(localName);
+    QString element = m_nodeStack.pop();
+    if(QString::compare(element, "entry") == 0) {
+        insideEntry = false;
+        m_docList->append(m_docEntry);
+        m_docEntry = 0;
+    }
+    return true;
+}
+
+bool GoogleContentHandler::endPrefixMapping(const QString & prefix)
+{
+    return true;
+}
+
+QString GoogleContentHandler::errorString() const
+{
+    return QString();
+}
+
+bool GoogleContentHandler::ignorableWhitespace(const QString & ch)
+{
+    return true;
+}
+
+bool GoogleContentHandler::processingInstruction(const QString & target, const QString & data)
+{
+    return true;
+}
+
+void GoogleContentHandler::setDocumentLocator(QXmlLocator * locator)
+{
+}
+
+bool GoogleContentHandler::skippedEntity(const QString & name)
+{
+    return true;
+}
+
+bool GoogleContentHandler::startDocument()
+{
+    return true;
+}
+
+bool GoogleContentHandler::startElement(const QString & namespaceURI, const QString & localName,
+                                        const QString & qName, const QXmlAttributes & atts)
+{
+    m_nodeStack.push(localName);
+
+    if((m_nodeStack.count() == 1) && (m_docList != 0)) {  //Feed element
+        m_docList->setEtag(atts.value("gd:etag"));
+    }
+
+    if(QString::compare(localName, "entry", Qt::CaseInsensitive) == 0) {
+        m_docEntry = new GoogleDocument();
+        m_docEntry->setEtag(atts.value("gd:etag"));
+        insideEntry = true;
+    }
+    if(insideEntry && (QString::compare(localName, "content", Qt::CaseInsensitive) == 0) && (m_docEntry != 0)) {
+        m_docEntry->setDocumentUrl(atts.value("src"));
+    }
+
+    //printName(localName);
+
+    return true;
+}
+
+bool GoogleContentHandler::startPrefixMapping(const QString & prefix, const QString & uri)
+{
+    //qDebug() << "GoogleContentHandler::startPrefixMapping() " << prefix << uri;
+    return true;
+}
+
+void GoogleContentHandler::printName(const QString & name)
+{
+    int count = m_nodeStack.count();
+    QString indent;
+    for(int i = 0; i < count; i++)
+        indent.append("\t");
+    indent.append(name);
+
+    if(insideEntry);
+//        qDebug() << indent;
+}
diff --git a/googlecontenthandler.h b/googlecontenthandler.h
new file mode 100644 (file)
index 0000000..8bfd7b5
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  Copyright (c) 2010 Mani Chandrasekar <maninc@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GOOGLECONTENTHANDLER_H
+#define GOOGLECONTENTHANDLER_H
+
+#include <QXmlContentHandler>
+#include <QStack>
+
+class GoogleDocumentList;
+class GoogleDocument;
+
+class GoogleContentHandler : public QXmlContentHandler
+{
+public:
+    GoogleContentHandler();
+
+    virtual bool characters(const QString & ch);
+    virtual bool endDocument();
+    virtual bool endElement(const QString & namespaceURI, const QString & localName, const QString & qName);
+    virtual bool endPrefixMapping(const QString & prefix);
+    virtual QString errorString() const;
+    virtual bool ignorableWhitespace(const QString & ch);
+    virtual bool processingInstruction(const QString & target, const QString & data);
+    virtual void setDocumentLocator(QXmlLocator * locator);
+    virtual bool skippedEntity(const QString & name);
+    virtual bool startDocument();
+    virtual bool startElement(const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts);
+    virtual bool startPrefixMapping(const QString & prefix, const QString & uri);
+
+    GoogleDocumentList *documentList() {
+        return m_docList;
+    }
+
+private:
+    QStack<QString> m_nodeStack;
+    bool insideEntry;
+    GoogleDocumentList *m_docList;
+    GoogleDocument *m_docEntry;
+
+    void printName(const QString & name);
+};
+
+#endif // GOOGLECONTENTHANDLER_H
diff --git a/googledocument.cpp b/googledocument.cpp
new file mode 100644 (file)
index 0000000..68427a7
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * This file is part of Maemo 5 Office UI for KOffice
+ *
+ * Copyright (C) 2010 Manikandaprasad N C <maninc@gmail.com>.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "googledocument.h"
+
+GoogleDocument::GoogleDocument()
+{
+}
+
+void GoogleDocument::setEtag(const QString & etag)
+{
+    m_etag = etag;
+}
+
+QString GoogleDocument::etag()
+{
+    return m_etag;
+}
+
+void GoogleDocument::setId(const QString & id)
+{
+    m_id = id;
+
+    setDocumentType(id.left(id.indexOf(":")));
+}
+
+QString GoogleDocument::id()
+{
+    return m_id;
+}
+
+void GoogleDocument::setTitle(const QString & title)
+{
+    m_title = title;
+}
+
+QString GoogleDocument::title()
+{
+    return m_title;
+}
+
+void GoogleDocument::setAuthor(const QString & author)
+{
+    m_author = author;
+}
+
+QString GoogleDocument::author()
+{
+    return m_author;
+}
+
+void GoogleDocument::setDocumentType(const QString & docType)
+{
+    m_docType = docType;
+}
+
+QString GoogleDocument::documentType()
+{
+    return m_docType;
+}
+
+void GoogleDocument::setDocumentUrl(const QString & url)
+{
+    m_documetUrl = url;
+}
+
+QString GoogleDocument::documentUrl()
+{
+    return m_documetUrl;
+}
diff --git a/googledocument.h b/googledocument.h
new file mode 100644 (file)
index 0000000..762867b
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * This file is part of Maemo 5 Office UI for KOffice
+ *
+ * Copyright (C) 2010 Manikandaprasad N C <maninc@gmail.com>.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef GOOGLEDOCUMENT_H
+#define GOOGLEDOCUMENT_H
+
+#include <QObject>
+
+class GoogleDocument : public QObject
+{
+public:
+    GoogleDocument();
+
+    void setEtag(const QString & etag);
+    QString etag();
+
+    void setId(const QString & id);
+    QString id();
+
+    void setTitle(const QString & title);
+    QString title();
+
+    void setAuthor(const QString & author);
+    QString author();
+
+    void setDocumentType(const QString & docType);
+    QString documentType();
+
+    void setDocumentUrl(const QString & url);
+    QString documentUrl();
+
+private:
+    QString m_etag;
+    QString m_id;
+    QString m_title;
+    QString m_author;
+    QString m_docType;
+    QString m_documetUrl;
+};
+
+#endif // GOOGLEDOCUMENT_H
diff --git a/googledocumentlist.cpp b/googledocumentlist.cpp
new file mode 100644 (file)
index 0000000..0fee772
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * This file is part of Maemo 5 Office UI for KOffice
+ *
+ * Copyright (C) 2010 Manikandaprasad N C <maninc@gmail.com>.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "googledocumentlist.h"
+#include "googledocument.h"
+
+#include <stdio.h>
+#include <QtCore>
+
+GoogleDocumentList::GoogleDocumentList()
+{
+    docModel = new QStandardItemModel(0, 2);
+}
+
+void GoogleDocumentList::setEtag(const QString  &etag)
+{
+    m_etag = etag;
+}
+
+QString GoogleDocumentList::etag()
+{
+    return m_etag;
+}
+
+void GoogleDocumentList::setEmail(const QString &email)
+{
+    m_email = email;
+}
+
+QString GoogleDocumentList::email()
+{
+    return m_email;
+}
+
+void GoogleDocumentList::setTitle(const QString &title)
+{
+    m_title = title;
+}
+
+QString GoogleDocumentList::title()
+{
+    return m_title;
+}
+
+void GoogleDocumentList::setAuthor(const QString &author)
+{
+    m_author = author;
+}
+
+QString GoogleDocumentList::author()
+{
+    return m_author;
+}
+
+void GoogleDocumentList::append(GoogleDocument *entry)
+{
+    if(entry != 0) {
+        m_entries.append(entry);
+
+        //count = docModel->rowCount();
+        docModel->insertRow(0);
+        docModel->setData(docModel->index(0, 0), entry->title());
+        docModel->setData(docModel->index(0, 1), entry->documentUrl());
+//       qDebug() << "Resource ID : " << entry->id();
+//        qDebug() << "Title : " << entry->title();
+//        qDebug() << "Author : " << entry->author();
+//        qDebug() << "Url : " << entry->documentUrl();
+    }
+}
+
+QList<GoogleDocument *> GoogleDocumentList::entries()
+{
+    return m_entries;
+}
+
+int GoogleDocumentList::documentsCount()
+{
+    return m_entries.count();
+}
diff --git a/googledocumentlist.h b/googledocumentlist.h
new file mode 100644 (file)
index 0000000..d458d39
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * This file is part of Maemo 5 Office UI for KOffice
+ *
+ * Copyright (C) 2010 Manikandaprasad N C <maninc@gmail.com>.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef GOOGLEDOCUMENTLIST_H
+#define GOOGLEDOCUMENTLIST_H
+
+#include <QObject>
+#include <QList>
+#include <QStandardItemModel>
+
+class GoogleDocument;
+
+class GoogleDocumentList : public QObject
+{
+public:
+    GoogleDocumentList();
+
+    void setEtag(const QString &etag);
+    QString etag();
+
+    void setEmail(const QString &email);
+    QString email();
+
+    void setTitle(const QString &title);
+    QString title();
+
+    void setAuthor(const QString &author);
+    QString author();
+
+    void append(GoogleDocument *entry);
+    int documentsCount();
+
+    QList<GoogleDocument *> entries();
+
+    QStandardItemModel * documentModel() {
+        return docModel;
+    }
+
+private:
+    QString m_author;
+    QString m_email;
+    QString m_title;
+    QString m_etag;
+
+    QList <GoogleDocument *>m_entries;
+
+    QStandardItemModel *docModel;
+};
+
+#endif // GOOGLEDOCUMENTLIST_H
diff --git a/googledocumentservice.cpp b/googledocumentservice.cpp
new file mode 100644 (file)
index 0000000..10a8c07
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ *  Copyright (c) 2010 Mani Chandrasekar <maninc@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <QtGui>
+#include <QtNetwork>
+#include <QMessageBox>
+
+#include "googledocumentservice.h"
+#include "googledocumentlist.h"
+#include "googledocument.h"
+#include "googlecontenthandler.h"
+#include "mimetypes.h"
+const QString GoogleDocumentService::GOOGLE_DOCUMENT_URL = "docs.google.com";
+const QString GoogleDocumentService::GOOGLE_SPREADSHEET_URL = "spreadsheets.google.com";
+
+GoogleDocumentService::GoogleDocumentService()
+    : newInformation(true)
+    , waitingForDoc(false)
+    , uploadingDoc(false)
+    , loggedin(false)
+    , haveDocAuthToken(false)
+{
+    saveFileName = 0;
+    connect(&networkManager, SIGNAL(finished(QNetworkReply*)),
+            this, SLOT(handleNetworkData(QNetworkReply*)));
+    gHandler = new GoogleContentHandler();
+    xmlReader.setContentHandler(gHandler);
+}
+
+void GoogleDocumentService::clientLogin(const QString & username, const QString & password)
+{
+    QByteArray data;
+    data.append(QString("Email=" + username + "&Passwd=" + password).toUtf8());
+
+    if(!haveDocAuthToken) {
+        data.append(QString("&service=writely&source=KOfficev2").toUtf8());
+        this->username = username;
+        this->password = password;
+    } else {
+        data.append(QString("&service=wise&source=KOfficev2").toUtf8());
+    }
+    QNetworkRequest req(QUrl("https://www.google.com/accounts/ClientLogin"));
+    req.setRawHeader("Host", "www.google.com");
+    req.setRawHeader("GData-Version", "3.0");
+    req.setRawHeader("Content-Type", "application/x-www-form-urlencoded");
+    req.setHeader(QNetworkRequest::ContentLengthHeader, data.length());
+
+    networkManager.post(req, data);
+}
+
+void GoogleDocumentService::listDocuments()
+{
+    qDebug() << ">>>>>>>>>>>>>> List Documents" ;
+    authToken = docAuthToken;
+    QNetworkRequest requestHeader(QUrl("https://docs.google.com/feeds/default/private/full"));
+    requestHeader.setRawHeader("Host", "docs.google.com");
+    requestHeader.setRawHeader("User-Agent", "KOffice");
+    requestHeader.setRawHeader("GData-Version", "3.0");
+    requestHeader.setRawHeader("Content-Type", "application/atom+xml");
+    requestHeader.setRawHeader("Authorization", authToken.toUtf8());
+
+    networkManager.get(requestHeader);
+}
+
+void GoogleDocumentService::handleNetworkData(QNetworkReply *networkReply)
+{
+    QUrl url = networkReply->url();
+    bool ok = false;
+    if(!networkReply->error()) {
+        if(!loggedin) {
+            QByteArray m_data = networkReply->readAll();
+            QString text(m_data.data());
+            text = text.right(text.length() - text.indexOf("Auth=") - 5);
+            authToken = QString("GoogleLogin auth=") + text.left(text.indexOf("\n"));
+            if(authToken.length() > 20) {
+                if(!haveDocAuthToken) {
+                    docAuthToken = authToken;
+                    haveDocAuthToken = true;
+                    clientLogin(this->username, this->password);
+                    return;
+                }
+                spreadAuthToken = authToken;
+                authToken = "";
+                loggedin = true;
+                qDebug() << ">>>>>>>>>>>>>> Login success" ;
+                emit userAuthenticated(loggedin);
+            } else {
+                qDebug() << ">>>>>>>>>>>>>> Login failed" ;
+                emit userAuthenticated(false);
+            }
+        } else if(waitingForDoc) {
+            QByteArray data = networkReply->readAll();
+            QFile file(*saveFileName);
+            file.open(QIODevice::WriteOnly);
+            file.write(data);
+            file.close();
+            qDebug() << ">>>>>>>>>>>>>> Received Document!!!!! " << file.fileName();
+            waitingForDoc = false;
+            emit downloadDone(true);
+        } else if(uploadingDoc) {
+            uploadingDoc = false;
+            qDebug() << ">>>>>>>>>>>>>> Upload done" ;
+            emit uploadDone(true);
+        } else {
+            qDebug() << ">>>>>>>>>>>>>> Received List" ;
+            gHandler = new GoogleContentHandler();
+            xmlReader.setContentHandler(gHandler);
+            QByteArray data = networkReply->readAll();
+            xmlInput.setData(data);
+            ok = xmlReader.parse(&xmlInput, true);
+            prepareLists();
+        }
+    } else {
+        qDebug() << networkReply->readAll();
+        if(!loggedin)
+            emit userAuthenticated(false);
+        else if(waitingForDoc) {
+            emit downloadDone(false);
+            waitingForDoc = false;
+        } else if(uploadingDoc) {
+            emit uploadDone(false);
+            uploadingDoc = false;
+        } else
+            emit listDone(false);
+    }
+    networkReply->deleteLater();
+}
+
+void GoogleDocumentService::prepareLists()
+{
+    presentationList.clear();
+    documentList.clear();
+    spreadsheetList.clear();
+    othersList.clear();
+    QList<GoogleDocument *> gList = gHandler->documentList()->entries();
+    foreach(GoogleDocument * i, gList) {
+        if("presentation" == i->documentType())
+            presentationList.append(i);
+        else if("spreadsheet" == i->documentType())
+            spreadsheetList.append(i);
+        else if("document" == i->documentType())
+            documentList.append(i);
+        else
+            othersList.append(i);
+    }
+    qDebug() << ">>>>>>>>>>>>>> Lists Done" ;
+    emit listDone(true);
+}
+
+
+void GoogleDocumentService::downloadDocument(GoogleDocument *doc, QString *saveFileName)
+{
+    this->saveFileName = saveFileName;
+    authToken = docAuthToken;
+    QString url = doc->documentUrl();
+    QString type = doc->documentType();
+    qDebug() << type << "=" << url;
+    url.replace("docId", "docID", Qt::CaseInsensitive);
+    QString exportFormat = "";
+
+    if(QString::compare(type, "spreadsheet") == 0) {
+        exportFormat = "&exportFormat=ods&format=ods";
+        authToken = spreadAuthToken;
+    } else if(QString::compare(type, "presentation") == 0)
+        exportFormat = "&exportFormat=ppt&format=ppt";
+    else if(QString::compare(type, "document") == 0)
+        exportFormat = "&exportFormat=odt&format=odt";
+
+    QUrl documentUrl(url + exportFormat);
+
+    QNetworkRequest requestHeader(documentUrl);
+    requestHeader.setRawHeader("User-Agent", "KOffice");
+    requestHeader.setRawHeader("GData-Version", "3.0");
+    requestHeader.setRawHeader("Authorization", authToken.toUtf8());
+
+    QNetworkReply *reply = networkManager.get(requestHeader);
+    connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(downloadProgress(qint64, qint64)));
+    waitingForDoc = true;
+    qDebug() << ">>>>>>>>>>>>>> Downloading file" ;
+}
+
+void GoogleDocumentService::uploadDocument(QString *filename, QString *title)
+{
+    authToken = docAuthToken;
+    QFile file(*filename);
+    file.open(QFile::ReadOnly);
+    QByteArray data = file.readAll();
+    file.close();
+    QUrl url;
+    url.setUrl("https://docs.google.com/feeds/default/private/full");
+
+    QNetworkRequest requestHeader(url);
+    requestHeader.setRawHeader("User-Agent", "KOffice");
+    requestHeader.setRawHeader("GData-Version", "3.0");
+    requestHeader.setRawHeader("Authorization", authToken.toUtf8());
+    requestHeader.setRawHeader("Content-Type", MimeTypes::getMimeType(QFileInfo(*filename).suffix()).toUtf8());
+    requestHeader.setRawHeader("Content-Length", QString::number(data.length()).toUtf8());
+    requestHeader.setRawHeader("Slug", QUrl::toPercentEncoding(*title));
+
+    QNetworkReply *reply = networkManager.post(requestHeader, data);
+    connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, SIGNAL(uploadProgress(qint64, qint64)));
+    uploadingDoc = true;
+    qDebug() << ">>>>>>>>>>>>>> Uploading file" ;
+}
+
diff --git a/googledocumentservice.h b/googledocumentservice.h
new file mode 100644 (file)
index 0000000..b2919c0
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ *  Copyright (c) 2010 Mani Chandrasekar <maninc@gmail.com>
+ *                     Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GOOGLEDOCUMENTSERVICE_H
+#define GOOGLEDOCUMENTSERVICE_H
+
+#include <QObject>
+#include <QXmlInputSource>
+#include <QNetworkAccessManager>
+#include <QList>
+//#include "documentlistwindow.h"
+
+class GoogleDocumentList;
+class GoogleDocument;
+class GoogleContentHandler;
+//class DocumentListWindow;
+
+class GoogleDocumentService : public QObject
+{
+    Q_OBJECT
+
+public:
+    GoogleDocumentService();
+    void clientLogin(const QString & username, const QString & password);
+    void listDocuments();
+    void prepareLists();
+    void uploadDocument(QString *filename, QString *title);
+    void downloadDocument(GoogleDocument *, QString *saveFileName);
+    bool alreadyAuthenticated() {
+        return loggedin;
+    }
+
+    QList<GoogleDocument *> documentList;
+    QList<GoogleDocument *> presentationList;
+    QList<GoogleDocument *> spreadsheetList;
+    QList<GoogleDocument *> othersList;
+
+signals:
+    void userAuthenticated(bool success);
+    void listDone(bool);
+    void downloadDone(bool);
+    void uploadDone(bool);
+    void downloadProgress(qint64 bytesSent, qint64 bytesTotal);
+    void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
+
+private slots:
+    void handleNetworkData(QNetworkReply *networkReply);
+
+private:
+    QXmlSimpleReader xmlReader;
+    QXmlInputSource  xmlInput;
+    bool newInformation;
+    bool waitingForDoc;
+    bool uploadingDoc;
+    bool loggedin;
+    bool haveDocAuthToken;
+    GoogleContentHandler *gHandler;
+    QString authToken;
+    QString docAuthToken;
+    QString spreadAuthToken;
+    QString *saveFileName;
+    QString username;
+    QString password;
+    QNetworkAccessManager networkManager;
+
+    static const QString GOOGLE_DOCUMENT_URL;
+    static const QString GOOGLE_SPREADSHEET_URL;
+};
+
+#endif // GOOGLEDOCUMENTSERVICE_H
diff --git a/googlelistdialog.cpp b/googlelistdialog.cpp
new file mode 100644 (file)
index 0000000..74d167c
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "googlelistdialog.h"
+#include "ui_filelistdialog.h"
+
+#include "googledocument.h"
+#include "googleuploaddialog.h"
+
+#include <QMaemo5InformationBox>
+#include <QFileDialog>
+#include <QDesktopServices>
+
+googleListDialog::googleListDialog(GoogleDocumentService *service, QWidget *parent):
+    QDialog(parent),
+    ui(new Ui::fileListDialog)
+{
+    ui->setupUi(this);
+    this->setWindowTitle("Google Docs");
+    this->service = service;
+    ui->listTab->setCurrentIndex(0);
+    ui->downloadProgressBar->setVisible(false);
+
+    connect(ui->downloadButton, SIGNAL(clicked()), this, SLOT(downloadButtonClickedSlot()));
+    connect(ui->uploadButton, SIGNAL(clicked()), this, SLOT(uploadButtonClickedSlot()));
+    connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(refreshList()));
+    connect(service, SIGNAL(listDone(bool)), this, SLOT(fillList(bool)));
+    connect(service, SIGNAL(downloadDone(bool)), this, SLOT(downloadDoneSlot(bool)));
+    connect(service, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateProgressBar(qint64, qint64)));
+    refreshList();
+}
+
+void googleListDialog::changeEvent(QEvent *e)
+{
+    QDialog::changeEvent(e);
+    switch(e->type()) {
+    case QEvent::LanguageChange:
+        ui->retranslateUi(this);
+        break;
+    default:
+        break;
+    }
+}
+
+void googleListDialog::refreshList()
+{
+    ui->listTab->setEnabled(false);
+    ui->downloadButton->setEnabled(false);
+    ui->uploadButton->setEnabled(false);
+    ui->refreshButton->setEnabled(false);
+    ui->downloadProgressBar->setMinimum(0);
+    ui->downloadProgressBar->setMaximum(0);
+    ui->downloadProgressBar->setVisible(true);
+    service->listDocuments();
+}
+
+void googleListDialog::fillList(bool status)
+{
+    if(status) {
+        ui->documentList->clear();
+        ui->presentationList->clear();
+        ui->spreadsheetList->clear();
+        ui->othersList->clear();
+
+        QList<GoogleDocument *> list;
+
+        list = service->documentList;
+        foreach(GoogleDocument * i, list) {
+            ui->documentList->addItem(i->title());
+        }
+
+        list = service->presentationList;
+        foreach(GoogleDocument * i, list) {
+            ui->presentationList->addItem(i->title());
+        }
+
+        list = service->spreadsheetList;
+        foreach(GoogleDocument * i, list) {
+            ui->spreadsheetList->addItem(i->title());
+        }
+
+        list = service->othersList;
+        foreach(GoogleDocument * i, list) {
+            ui->othersList->addItem(i->title());
+        }
+    } else {
+        QMaemo5InformationBox::information(this, "<p><b>Error</b></p> <p>An error occured while fetching document list</p>", QMaemo5InformationBox::NoTimeout);
+    }
+    ui->downloadProgressBar->setMaximum(100);
+    ui->downloadProgressBar->setVisible(false);
+    ui->listTab->setEnabled(true);
+    ui->downloadButton->setEnabled(true);
+    ui->uploadButton->setEnabled(true);
+    ui->refreshButton->setEnabled(true);
+}
+
+void googleListDialog::downloadButtonClickedSlot()
+{
+    QList<GoogleDocument *> list;
+    QListWidget *tmp = 0;
+    switch(ui->listTab->currentIndex()) {
+    case 0:
+        tmp = ui->documentList;
+        list = service->documentList;
+        break;
+    case 1:
+        tmp = ui->presentationList;
+        list = service->presentationList;
+        break;
+    case 2:
+        tmp = ui->spreadsheetList;
+        list = service->spreadsheetList;
+        break;
+    case 3:
+        tmp = ui->othersList;
+        list = service->othersList;
+    }
+
+    if(-1 == tmp->currentRow()) {
+        QMaemo5InformationBox::information(this, "Select a file from the list to download", QMaemo5InformationBox::DefaultTimeout);
+        return;
+    }
+    GoogleDocument *doc = list[tmp->currentRow()];
+    QString format = "";
+    if("presentation" == doc->documentType()) {
+        format = ".ppt";
+    } else if("document" == doc->documentType()) {
+        format = ".odt";
+    } else if("spreadsheet" == doc->documentType()) {
+        format = ".ods";
+    }
+    QString filename = QFileDialog::getSaveFileName(this, "Save File", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation) + "/" + doc->title() + format, "(*" + format + ")");
+    if("" == filename)
+        return;
+    service->downloadDocument(doc, new QString(filename));
+    ui->listTab->setEnabled(false);
+    ui->uploadButton->setEnabled(false);
+    ui->downloadButton->setEnabled(false);
+    ui->refreshButton->setEnabled(false);
+    ui->downloadProgressBar->setVisible(true);
+}
+
+void googleListDialog::uploadButtonClickedSlot()
+{
+    googleUploadDialog *ud = new googleUploadDialog(service, this);
+    if("" != openDocPath) {
+        ud->setOpenDoc(openDocPath);
+    }
+    ud->show();
+    connect(ud, SIGNAL(accepted()), this, SLOT(refreshList()));
+}
+
+void googleListDialog::downloadDoneSlot(bool status)
+{
+    ui->downloadProgressBar->setVisible(false);
+    ui->downloadProgressBar->setValue(0);
+    ui->listTab->setEnabled(true);
+    ui->downloadButton->setEnabled(true);
+    ui->refreshButton->setEnabled(true);
+    ui->uploadButton->setEnabled(true);
+    if(status)
+        QMaemo5InformationBox::information(this, "The file has finished downloading", QMaemo5InformationBox::DefaultTimeout);
+    else
+        QMaemo5InformationBox::information(this, "<p><b>Error</b></p> <p>An error occured while downloading the document</p>", QMaemo5InformationBox::NoTimeout);
+}
+
+void googleListDialog::updateProgressBar(qint64 bytesDone, qint64 bytesTotal)
+{
+    int value = (bytesDone * 100) / bytesTotal;
+    ui->downloadProgressBar->setValue(value);
+}
+
+void googleListDialog::setOpenDoc(const QString & openDocPath)
+{
+    this->openDocPath = openDocPath;
+}
diff --git a/googlelistdialog.h b/googlelistdialog.h
new file mode 100644 (file)
index 0000000..53df319
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GOOGLELISTDIALOG_H
+#define GOOGLELISTDIALOG_H
+
+#include <QDialog>
+#include <googledocumentservice.h>
+
+namespace Ui
+{
+class fileListDialog;
+}
+
+class googleListDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    googleListDialog(GoogleDocumentService *service, QWidget *parent = 0);
+    void setOpenDoc(const QString &);
+protected:
+    void changeEvent(QEvent *e);
+
+private slots:
+    void downloadButtonClickedSlot();
+    void uploadButtonClickedSlot();
+    void fillList(bool);
+    void downloadDoneSlot(bool);
+    void updateProgressBar(qint64, qint64);
+    void refreshList();
+
+private:
+    Ui::fileListDialog *ui;
+    GoogleDocumentService *service;
+    QString openDocPath;
+};
+
+#endif // GOOGLELISTDIALOG_H
diff --git a/googleuploaddialog.cpp b/googleuploaddialog.cpp
new file mode 100644 (file)
index 0000000..c3b5ba2
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "googleuploaddialog.h"
+#include "ui_uploaddialog.h"
+
+#include "googledocumentservice.h"
+
+#include <QFileDialog>
+#include <QDesktopServices>
+#include <QMaemo5InformationBox>
+
+googleUploadDialog::googleUploadDialog(GoogleDocumentService *service, QWidget *parent):
+    QDialog(parent),
+    ui(new Ui::uploadDialog)
+{
+    this->service = service;
+    ui->setupUi(this);
+    ui->descriptionBox->setVisible(false);
+    ui->tagsEdit->setVisible(false);
+    ui->label_3->setVisible(false);
+    ui->label_4->setVisible(false);
+
+    connect(service, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgressSlot(qint64, qint64)));
+    connect(ui->fileSelectButton, SIGNAL(clicked()), this, SLOT(showFileDialog()));
+    connect(ui->uploadButton, SIGNAL(clicked()), this, SLOT(uploadButtonClickedSlot()));
+}
+
+googleUploadDialog::~googleUploadDialog()
+{
+    disconnect(service, SIGNAL(uploadDone(bool)), this, SLOT(uploadDoneSlot(bool)));
+    delete ui;
+}
+
+void googleUploadDialog::setOpenDoc(const QString & openDocPath)
+{
+    ui->fileSelectEdit->setText(openDocPath);
+}
+
+void googleUploadDialog::changeEvent(QEvent *e)
+{
+    QDialog::changeEvent(e);
+    switch(e->type()) {
+    case QEvent::LanguageChange:
+        ui->retranslateUi(this);
+        break;
+    default:
+        break;
+    }
+}
+
+void googleUploadDialog::uploadProgressSlot(qint64 bytesSent, qint64 bytesTotal)
+{
+    int value = (bytesSent * 100) / bytesTotal;
+    ui->uploadProgress->setValue(value);
+}
+
+void googleUploadDialog::showFileDialog()
+{
+    QString currentFile = ("" == ui->fileSelectEdit->text()) ? QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation) : ui->fileSelectEdit->text();
+    QString filter = "Supported Files (*.odt *.doc *.ppt *.xls)";
+    QString filename = QFileDialog::getOpenFileName(this, QString("Select File"), currentFile, filter, &filter);
+    if("" != filename)
+        ui->fileSelectEdit->setText(filename);
+}
+
+void googleUploadDialog::uploadButtonClickedSlot()
+{
+    if(ui->fileSelectEdit->text() == "" || ui->titleEdit->text() == "") {
+        QMaemo5InformationBox::information(this, "Please enter both filename and title");
+        return;
+    } else {
+        ui->fileSelectButton->setEnabled(false);
+        ui->titleEdit->setEnabled(false);
+        ui->uploadButton->setEnabled(false);
+        service->uploadDocument(&ui->fileSelectEdit->text(), &ui->titleEdit->text());
+        connect(service, SIGNAL(uploadDone(bool)), this, SLOT(uploadDoneSlot(bool)));
+    }
+}
+
+void googleUploadDialog::uploadDoneSlot(bool status)
+{
+    if(!status) {
+        QMaemo5InformationBox::information(this, "\nUpload failed\n", QMaemo5InformationBox::NoTimeout);
+    } else {
+        QMaemo5InformationBox::information(this, "Upload completed");
+    }
+    ui->doneButton->setEnabled(true);
+}
diff --git a/googleuploaddialog.h b/googleuploaddialog.h
new file mode 100644 (file)
index 0000000..e97b616
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GOOGLEUPLOADDIALOG_H
+#define GOOGLEUPLOADDIALOG_H
+
+#include <QDialog>
+
+class GoogleDocumentService;
+namespace Ui
+{
+class uploadDialog;
+}
+
+class googleUploadDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    googleUploadDialog(GoogleDocumentService *service, QWidget *parent = 0);
+    ~googleUploadDialog();
+    void setOpenDoc(const QString &);
+
+protected:
+    void changeEvent(QEvent *);
+
+private:
+    Ui::uploadDialog *ui;
+    GoogleDocumentService *service;
+
+private slots:
+    void uploadProgressSlot(qint64 bytesSent, qint64 bytesTotal);
+    void showFileDialog();
+    void uploadButtonClickedSlot();
+    void uploadDoneSlot(bool);
+};
+
+#endif // GOOGLEUPLOADDIALOG_H
diff --git a/loginwindow.cpp b/loginwindow.cpp
new file mode 100644 (file)
index 0000000..caacb21
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * This file is part of Maemo 5 Office UI for KOffice
+ *
+ * Copyright (C) 2010 Manikandaprasad N C <maninc@gmail.com>.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "loginwindow.h"
+#include "googledocumentservice.h"
+#include "googlelistdialog.h"
+#include "slideshare.h"
+#include "slidesharelistdialog.h"
+#include "encryptsupport.h"
+
+#include <QtGui>
+#include <QX11Info>
+#include <QSettings>
+
+#include <QMaemo5InformationBox>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+LoginWindow::LoginWindow(QWidget *parent)
+    : QDialog(parent),
+      m_authDialog(new Ui_Dialog),
+      settings(new QSettings("freoffice", "online-services-plugin", this)),
+      cipher(new encryptSupport(this))
+{
+    m_authDialog->setupUi(this);
+
+    QStringList onlineServices;
+    onlineServices << "Google Documents";
+    // Add services here
+    onlineServices << "Slide Share";
+    m_authDialog->comboBox->addItems(onlineServices);
+
+    connect(m_authDialog->loginButton, SIGNAL(clicked()), this, SLOT(loginService()));
+    connect(m_authDialog->comboBox, SIGNAL(activated(int)), this, SLOT(serviceSelected(int)));
+    fillDetails();
+    m_authDialog->userEdit->setInputMethodHints(Qt::ImhNoAutoUppercase);
+    m_authDialog->userEdit->setFocus();
+    show();
+}
+
+LoginWindow::~LoginWindow()
+{
+    settings->sync();
+}
+
+void LoginWindow::setOpenDoc(const QString & openDocPath)
+{
+    this->openDocPath = openDocPath;
+}
+
+void LoginWindow::loginService()
+{
+    if("" == m_authDialog->userEdit->text() || "" == m_authDialog->passwordEdit->text()) {
+        QMaemo5InformationBox::information(this, "Enter both username and password", QMaemo5InformationBox::DefaultTimeout);
+        return;
+    }
+    disableWidgets();
+    if(0 == m_authDialog->comboBox->currentIndex()) {
+        gdoc = new GoogleDocumentService();
+        setShowProgressIndicator(true);
+        gdoc->clientLogin(m_authDialog->userEdit->text(), m_authDialog->passwordEdit->text());
+        connect(gdoc, SIGNAL(userAuthenticated(bool)), this, SLOT(authenticated(bool)));
+    }
+    if(1 == m_authDialog->comboBox->currentIndex()) {
+        service = new SlideShare(this);
+        service->setApikey(new QString("KhSMYyiF"));
+        service->setsecretKey(new QString("HDXhAC5g"));
+        service->setUsername(new QString(m_authDialog->userEdit->text()));
+        service->setPassword(new QString(m_authDialog->passwordEdit->text()));
+        service->login();
+        setShowProgressIndicator(true);
+        connect(service, SIGNAL(loginDone(bool)), this, SLOT(slideShareLoginDoneSlot(bool)));
+    }
+}
+
+void LoginWindow::serviceSelected(int index)
+{
+    if(index == 0) {
+        m_authDialog->userEdit->setText("@gmail.com");
+        m_authDialog->passwordEdit->clear();
+    } else if(index == 1) {
+        m_authDialog->userEdit->clear();
+        m_authDialog->passwordEdit->clear();
+    }
+    fillDetails();
+    m_authDialog->userEdit->setFocus();
+}
+
+void LoginWindow::authenticated(bool success)
+{
+    if(success) {
+        QString key("user/gdocs");
+        saveDetails(key);
+        googleListDialog *ld = new googleListDialog(gdoc, this);
+        ld->setOpenDoc(openDocPath);
+        this->accept();;
+        ld->show();
+    } else {
+        QMaemo5InformationBox::information(this, ("<p>Login Failed</p><p>Check your username & password</p>"), QMaemo5InformationBox::NoTimeout);
+        enableWidgets();
+    }
+}
+
+void LoginWindow::setShowProgressIndicator(bool visible)
+{
+    unsigned long val = visible ? 1 : 0;
+    Atom atom = XInternAtom(QX11Info::display(),
+                            "_HILDON_WM_WINDOW_PROGRESS_INDICATOR", False);
+    XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER,
+                    32, PropModeReplace,
+                    (unsigned char *) &val, 1);
+}
+
+void LoginWindow::slideShareLoginDoneSlot(bool loginStatus)
+{
+    if(loginStatus == false) {
+        QMaemo5InformationBox::information(this, "<p>Login Failed.</p><p>Check your username and password</p> ", QMaemo5InformationBox::NoTimeout);
+        enableWidgets();
+    } else {
+        QString key("user/slideshare");
+        saveDetails(key);
+        slideshareListDialog * ld = new slideshareListDialog(service, this);
+        ld->setOpenDoc(openDocPath);
+        this->accept();
+        ld->show();
+    }
+}
+
+void LoginWindow::enableWidgets()
+{
+    setShowProgressIndicator(false);
+    m_authDialog->loginButton->setEnabled(true);
+    m_authDialog->userEdit->setEnabled(true);
+    m_authDialog->passwordEdit->setEnabled(true);
+    m_authDialog->comboBox->setEnabled(true);
+    m_authDialog->saveCheckBox->setEnabled(true);
+}
+
+void LoginWindow::disableWidgets()
+{
+    m_authDialog->loginButton->setEnabled(false);
+    m_authDialog->userEdit->setEnabled(false);
+    m_authDialog->passwordEdit->setEnabled(false);
+    m_authDialog->comboBox->setEnabled(false);
+    m_authDialog->saveCheckBox->setEnabled(false);
+}
+
+void LoginWindow::saveDetails(QString &key)
+{
+    if(Qt::Checked == m_authDialog->saveCheckBox->checkState()) {
+        QVariantMap m;
+        QString username = m_authDialog->userEdit->text();
+        QString password = m_authDialog->passwordEdit->text();
+        m.insert("username", username);
+        m.insert("password", cipher->encrypt(password));
+        settings->setValue(key, m);
+    } else {
+        settings->remove(key);
+    }
+}
+
+void LoginWindow::fillDetails()
+{
+    QString key = "";
+    if(0 == m_authDialog->comboBox->currentIndex())
+        key = "user/gdocs";
+    else if(1 == m_authDialog->comboBox->currentIndex())
+        key = "user/slideshare";
+    else
+        return;
+    if(settings->contains(key)) {
+        QVariantMap m = settings->value(key).value<QVariantMap>();
+        QString username = m.value("username").toString();
+        QString password = m.value("password").toString();
+        m_authDialog->userEdit->setText(username);
+        m_authDialog->passwordEdit->setText(cipher->decrypt(password));
+        m_authDialog->saveCheckBox->setCheckState(Qt::Checked);
+    } else
+        m_authDialog->saveCheckBox->setCheckState(Qt::Unchecked);
+    return;
+}
diff --git a/loginwindow.h b/loginwindow.h
new file mode 100644 (file)
index 0000000..a1fc8e8
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * This file is part of Maemo 5 Office UI for KOffice
+ *
+ * Copyright (C) 2010 Manikandaprasad N C <maninc@gmail.com>.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef LOGINWINDOW_H
+#define LOGINWINDOW_H
+
+#include <QDialog>
+
+#include "ui_authenticationdialog.h"
+
+class SlideShare;
+class GoogleDocumentService;
+class encryptSupport;
+class QSettings;
+class LoginWindow : public QDialog
+{
+    Q_OBJECT
+
+public:
+    LoginWindow(QWidget *parent = 0);
+    ~LoginWindow();
+    void setShowProgressIndicator(bool visible);
+    void setOpenDoc(const QString &);
+
+private slots:
+    void loginService();
+    void serviceSelected(int index);
+    void authenticated(bool success);
+    void slideShareLoginDoneSlot(bool loginStatus);
+
+private:
+    Ui_Dialog *m_authDialog;
+    encryptSupport *cipher;
+    GoogleDocumentService *gdoc;
+    SlideShare *service;
+    QSettings *settings;
+    QString openDocPath;
+    void enableWidgets();
+    void disableWidgets();
+    void saveDetails(QString &key);
+    void fillDetails();
+};
+
+#endif // LOGINWINDOW_H
diff --git a/mimetypes.cpp b/mimetypes.cpp
new file mode 100644 (file)
index 0000000..9124f7b
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "mimetypes.h"
+
+QString MimeTypes::getMimeType(const QString & extension)
+{
+    QHash <QString, QString> mimelist;
+    mimelist["odt"] = "application/vnd.oasis.opendocument.text";
+    mimelist["doc"] = "application/msword";
+    mimelist["odp"] = "application/vnd.oasis.opendocument.presentation";
+    mimelist["ppt"] = "application/vnd.ms-powerpoint";
+    mimelist["ods"] = "application/x-vnd.oasis.opendocument.spreadsheet";
+    mimelist["xls"] = "application/ms-excel";
+    return mimelist[extension];
+}
diff --git a/mimetypes.h b/mimetypes.h
new file mode 100644 (file)
index 0000000..8c93a08
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef MIMETYPES_H
+#define MIMETYPES_H
+
+#include <QString>
+#include <QHash>
+class MimeTypes
+{
+public:
+    static QString getMimeType(const QString &);
+};
+
+#endif // MIMETYPES_H
diff --git a/onlineServicesPlugin.pro b/onlineServicesPlugin.pro
new file mode 100644 (file)
index 0000000..fe30764
--- /dev/null
@@ -0,0 +1,56 @@
+# #####################################################################
+# Automatically generated by qmake (2.01a) Sat Jul 10 12:41:16 2010
+# #####################################################################
+QT += network
+QT += xml
+QT += maemo5
+
+TEMPLATE = lib
+
+CONFIG += plugin
+
+TARGET = OnlineServicesPlugin
+target.path = /usr/lib/freoffice/
+
+INSTALLS += target
+
+DEPENDPATH += .
+
+INCLUDEPATH += . \
+    /usr/local/include/office \
+    /usr/include/office
+
+LIBS += -lcrypto
+
+# Input
+HEADERS += googlecontenthandler.h \
+    googledocument.h \
+    googledocumentlist.h \
+    googledocumentservice.h \
+    googlelistdialog.h \
+    googleuploaddialog.h \
+    loginwindow.h \
+    mimetypes.h \
+    onlineservicesplugin.h \
+    slideshare.h \
+    slideshareDocument.h \
+    slidesharelistdialog.h \
+    slideshareuploaddialog.h \
+    encryptsupport.h
+FORMS += authenticationdialog.ui \
+    filelistdialog.ui \
+    uploaddialog.ui
+SOURCES += googlecontenthandler.cpp \
+    googledocument.cpp \
+    googledocumentlist.cpp \
+    googledocumentservice.cpp \
+    googlelistdialog.cpp \
+    googleuploaddialog.cpp \
+    loginwindow.cpp \
+    mimetypes.cpp \
+    onlineservicesplugin.cpp \
+    slideshare.cpp \
+    slidesharelistdialog.cpp \
+    slideshareuploaddialog.cpp \
+    encryptsupport.cpp
+
diff --git a/onlineservicesplugin.cpp b/onlineservicesplugin.cpp
new file mode 100644 (file)
index 0000000..2bccf40
--- /dev/null
@@ -0,0 +1,42 @@
+#include "onlineservicesplugin.h"
+#include "loginwindow.h"
+#include <KoDocument.h>
+
+onlineServicesPlugin::onlineServicesPlugin()
+{
+    name = "Online Services";
+    window = 0;
+}
+onlineServicesPlugin::~onlineServicesPlugin()
+{
+    delete window;
+    window = 0;
+}
+
+void onlineServicesPlugin::setDocument(void *doc)
+{
+    this->doc = (KoDocument *) doc;
+}
+
+QWidget *onlineServicesPlugin::view()
+{
+    window = new LoginWindow();
+    if(doc) {
+        window->setOpenDoc(doc->url().path());
+    }
+    return window;
+}
+
+QString onlineServicesPlugin::pluginName()
+{
+    return name;
+}
+
+QStringList onlineServicesPlugin::pluginSupportTypes()
+{
+    QStringList types;
+    types << "All";
+    return types;
+}
+
+Q_EXPORT_PLUGIN2(OnlineServicesPlugin, onlineServicesPlugin)
diff --git a/onlineservicesplugin.h b/onlineservicesplugin.h
new file mode 100644 (file)
index 0000000..d4ac85c
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef ONLINESERVICESPLUGIN_H
+#define ONLINESERVICESPLUGIN_H
+
+#include "OfficeInterface.h"
+#include <QObject>
+
+class LoginWindow;
+class KoDocument;
+
+class onlineServicesPlugin: public QObject, public OfficeInterface
+{
+    Q_OBJECT
+    Q_INTERFACES(OfficeInterface)
+public:
+    onlineServicesPlugin();
+    ~onlineServicesPlugin();
+    void setDocument(void *doc);
+    QWidget * view();
+    QString pluginName();
+    QStringList pluginSupportTypes();
+
+private:
+    QString name;
+    KoDocument *doc;
+    LoginWindow *window;
+};
+
+#endif // ONLINESERVICESPLUGIN_H
diff --git a/slideshare.cpp b/slideshare.cpp
new file mode 100644 (file)
index 0000000..7a09d95
--- /dev/null
@@ -0,0 +1,295 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QDateTime>
+#include <QCryptographicHash>
+#include <QHash>
+#include <QDebug>
+#include <QByteArray>
+#include <QList>
+#include <QPair>
+#include <QFile>
+#include <QFileInfo>
+#include <QDomDocument>
+#include <QNetworkProxy>
+
+#include "slideshare.h"
+#include "slideshareDocument.h"
+#include "mimetypes.h"
+
+SlideShare::SlideShare(QObject *parent): QObject(parent)
+{
+    manager.setCookieJar(&this->cookieJar);
+    doc = new SlideShareDocument;
+}
+
+SlideShare::SlideShare(QString *username, QString *password, QObject *parent): QObject(parent)
+{
+    this->username = username;
+    this->password = password;
+    SlideShare();
+}
+SlideShare::SlideShare(QString *username, QString *password, QString *apiKey, QString *secretKey, QObject *parent): QObject(parent)
+{
+    this->apiKey = apiKey;
+    this->secretKey = secretKey;
+    SlideShare(username, password);
+}
+
+SlideShare::~SlideShare()
+{
+}
+
+void SlideShare::setUsername(QString *username)
+{
+    this->username = username;
+}
+
+void SlideShare::setPassword(QString *password)
+{
+    this->password = password;
+}
+
+void SlideShare::setApikey(QString *apiKey)
+{
+    this->apiKey = apiKey;
+}
+
+void SlideShare::setsecretKey(QString *secretKey)
+{
+    this->secretKey = secretKey;
+}
+
+void SlideShare::setSlideTitle(QString *title)
+{
+    doc->title = *title;
+}
+
+void SlideShare::setDescription(QString *description)
+{
+    doc->description = *description;
+}
+
+void SlideShare::setTags(QString *tags)
+{
+    doc->tags = *tags;
+}
+
+void SlideShare::setFormat(QString *format)
+{
+    doc->format = *format;
+}
+
+void SlideShare::setSourceFile(QString *filename)
+{
+    this->sourceFilename = filename;
+}
+
+void SlideShare::setSaveFileName(QString *saveFileName)
+{
+    this->saveFileName = saveFileName;
+}
+
+
+void SlideShare::login()
+{
+    qDebug() << ">>>>>>>>> SlideShare::login()";
+    QUrl *login = new QUrl(QString("http://www.slideshare.net/login"));
+    QByteArray data;
+    data.append(QString("user_login=").append(username).toUtf8());
+    data.append(QString("&user_password=").append(password).toUtf8());
+
+    QNetworkRequest request;
+    request.setUrl(*login);
+
+    reply = manager.post(request, data);
+    connect(reply, SIGNAL(finished()), this, SLOT(afterLogin()));
+}
+
+
+void SlideShare::afterLogin()
+{
+    qDebug() << ">>>>>>>>> SlideShare::afterLogin()";
+    if(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 302) {
+        if(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString().contains(*username))
+            emit loginDone(true);
+    } else
+        emit loginDone(false);
+}
+
+void SlideShare::download(QString *durl)
+{
+    qDebug() << ">>>>>>>>> SlideShare::download()";
+    QUrl *dload = new QUrl(*durl) ;
+    QNetworkRequest request;
+    request.setUrl(*dload);
+
+    QList<QNetworkCookie> list = cookieJar.cookiesForUrl(QUrl("http://www.slideshare.net/"));
+
+    foreach(QNetworkCookie c, list) {
+        if(c.name() == "_cookie_id") {
+            request.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue(list));
+        }
+    }
+
+    reply = manager.get(request);
+    connect(reply, SIGNAL(finished()), this, SLOT(saveFile()));
+
+}
+void SlideShare::saveFile()
+{
+    qDebug() << ">>>>>>>>> SlideShare::saveFile()";
+    if(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 302) {
+        reply = manager.get(QNetworkRequest(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl()));
+        connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(downloadProgress(qint64, qint64)));
+        connect(reply, SIGNAL(finished()), this, SLOT(saveFile()));
+        return;
+    }
+
+    QFile file(*saveFileName);
+    file.open(QFile::WriteOnly);
+
+    file.write(reply->readAll());
+    file.close();
+
+
+    emit downloadDone();
+}
+
+void SlideShare::upload()
+{
+    qDebug() << ">>>>>>>>> SlideShare::upload()";
+    QDateTime *time = new QDateTime();
+    QString ts;
+    ts.setNum(time->toTime_t());
+
+    QByteArray data = this->secretKey->toAscii();
+    data += ts;
+
+    QFile *file = new QFile(*this->sourceFilename, this);
+    file->open(QFile::ReadOnly);
+
+    QByteArray fileData ;
+    fileData = file->readAll();
+
+    QByteArray postData;
+    postData.append("--BOUNDARY\r\n");
+    postData.append("Content-Disposition: form-data; name=\"slideshow_srcfile\"; filename=\"");
+    postData.append(file->fileName().toUtf8());
+    postData.append("\"\r\n");
+    postData.append("Content-Type: " + MimeTypes::getMimeType(doc->format));
+    postData.append("\r\n\r\n");
+    postData.append(fileData);
+    postData.append("\r\n--BOUNDARY\r\n");
+
+
+    QList<QPair<QString, QString> > params;
+    params.append(qMakePair(QString("api_key"), *this->apiKey));
+    params.append(qMakePair(QString("ts"), ts));
+    params.append(qMakePair(QString("hash"), QString(QCryptographicHash::hash(data, QCryptographicHash::Sha1).toHex())));
+    params.append(qMakePair(QString("username"), *this->username));
+    params.append(qMakePair(QString("password"), *this->password));
+    params.append(qMakePair(QString("slideshow_title"), doc->title));
+    if(doc->description != "")
+        params.append(qMakePair(QString("slideshow_description"), doc->description));
+    if(doc->tags != "")
+        params.append(qMakePair(QString("slideshow_tags"), doc->tags));
+
+    QUrl url("http://www.slideshare.net/api/2/upload_slideshow", QUrl::TolerantMode);
+    url.setQueryItems(params);
+    QNetworkRequest request;
+    request.setUrl(url);
+    request.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=BOUNDARY");
+    request.setHeader(QNetworkRequest::ContentLengthHeader, postData.length());
+
+
+    QNetworkReply *reply = manager.post(request, postData);
+    connect(reply, SIGNAL(uploadProgress(qint64, qint64)), this, SIGNAL(uploadProgress(qint64, qint64)));
+    connect(reply, SIGNAL(finished()), this, SIGNAL(uploadDone()));
+}
+
+void SlideShare::listDocuments()
+{
+    qDebug() << ">>>>>>>>> SlideShare::listDocuments()";
+    QDateTime *time = new QDateTime(QDateTime::currentDateTime());
+    QString ts;
+    ts.setNum(time->toTime_t());
+
+    QByteArray data = this->secretKey->toAscii();
+    data += ts;
+
+    QList<QPair<QString, QString> > params;
+    params.append(qMakePair(QString("api_key"), *this->apiKey));
+    params.append(qMakePair(QString("ts"), ts));
+    params.append(qMakePair(QString("hash"), QString(QCryptographicHash::hash(data, QCryptographicHash::Sha1).toHex())));
+    params.append(qMakePair(QString("username"), *this->username));
+    params.append(qMakePair(QString("password"), *this->password));
+    params.append(qMakePair(QString("username_for"), *this->username));
+
+
+    QUrl url("http://www.slideshare.net/api/2/get_slideshows_by_user");
+    url.setQueryItems(params);
+
+
+    QNetworkRequest request;
+    request.setUrl(url);
+
+    reply = manager.get(request);
+    connect(reply, SIGNAL(finished()), this, SLOT(parseList()));
+}
+void SlideShare::parseList()
+{
+    qDebug() << ">>>>>>>>> SlideShare::parseList()" ;
+    QDomDocument doc;
+    QByteArray data = reply->readAll();
+    doc.setContent(data);
+
+    QDomElement root = doc.documentElement();
+    QDomElement child = root.firstChildElement("Slideshow");
+
+    textDocList.clear();
+    presentationList.clear();
+    spreadsheetList.clear();
+
+    while(!child.isNull()) {
+        SlideShareDocument *p = new SlideShareDocument;
+        p->title = child.firstChildElement("Title").text();
+        p->url = child.firstChildElement("URL").text();
+        p->format = child.firstChildElement("Format").text();
+        p->slideID = child.firstChildElement("ID").text();
+        p->thumbnailBig = child.firstChildElement("ThumbnailUrl").text();
+        p->thumbnailSmall = child.firstChildElement("ThumbnailSmallURL").text();
+        p->downloadUrl = p->url.append("/download");
+        QString download = child.firstChildElement("Download").text();
+        if(download == "1") {
+            if(p->format == "odt" || p->format == "doc")
+                this->textDocList.append(*p);
+            if(p->format == "odp" || p->format == "ppt")
+                this->presentationList.append(*p);
+            if(p->format == "ods" || p->format == "xls")
+                this->spreadsheetList.append(*p);
+        }
+
+        child = child.nextSiblingElement("Slideshow");
+    }
+    emit listDone();
+}
+
diff --git a/slideshare.h b/slideshare.h
new file mode 100644 (file)
index 0000000..dd38aa5
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SLIDESHARE_H
+#define SLIDESHARE_H
+
+#include <QObject>
+#include <QtCore>
+#include <QUrl>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkCookieJar>
+
+
+struct SlideShareDocument;
+
+class SlideShare : public QObject
+{
+    Q_OBJECT
+
+public:
+    SlideShare(QObject *parent = 0);
+    SlideShare(QString *username, QString *password, QObject *parent = 0);
+    SlideShare(QString *username, QString *password, QString *apiKey, QString *secretKey, QObject *parent);
+    ~SlideShare();
+
+    void login();
+    void upload();
+    void download(QString *durl);
+    void listDocuments();
+    void searchByTags(QString *tag);
+
+    void setApikey(QString *apiKey);
+    void setsecretKey(QString *secretKey);
+
+    void setUsername(QString *username);
+    void setPassword(QString *password);
+
+    void setSlideTitle(QString *title);
+    void setDescription(QString *description);
+    void setTags(QString *tags);
+    void setFormat(QString *format);
+
+    void setSourceFile(QString *filename);
+    void setSaveFileName(QString *saveFileName);
+
+    QList<SlideShareDocument> textDocList;
+    QList<SlideShareDocument> presentationList;
+    QList<SlideShareDocument> spreadsheetList;
+
+private:
+    QString *apiKey;
+    QString *secretKey;
+    QString *username;
+    QString *password;
+
+    QString *sourceFilename;
+    QString *saveFileName;
+
+    SlideShareDocument *doc;
+
+    bool loginStatus;
+
+    QNetworkAccessManager manager;
+    QNetworkCookieJar cookieJar;
+    QNetworkReply *reply;
+
+    void getThumbnailSmall();
+    void getThumbnailBig();
+
+
+private slots:
+    void afterLogin();
+    void parseList();
+    void saveFile();
+
+signals:
+    void downloadProgress(qint64 bytesSent, qint64 bytesTotal);
+    void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
+    void loginDone(bool);
+    void uploadDone();
+    void listDone();
+    void downloadDone();
+
+};
+
+#endif // SLIDESHARE_H
diff --git a/slideshareDocument.h b/slideshareDocument.h
new file mode 100644 (file)
index 0000000..34ef49e
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SLIDESHAREDOCUMENT_H
+#define SLIDESHAREDOCUMENT_H
+class QString;
+
+struct SlideShareDocument {
+    QString title;
+    QString slideID;
+    QString url;
+    QString downloadUrl;
+    QString format;
+    QString description;
+    QString tags;
+    QString thumbnailSmall;
+    QString thumbnailBig;
+};
+#endif // SLIDESHAREDOCUMENT_H
diff --git a/slidesharelistdialog.cpp b/slidesharelistdialog.cpp
new file mode 100644 (file)
index 0000000..8e97e48
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "slidesharelistdialog.h"
+#include "ui_filelistdialog.h"
+
+#include "slideshareuploaddialog.h"
+#include "slideshareDocument.h"
+
+#include <QFileDialog>
+#include <QDesktopServices>
+#include <QListWidgetItem>
+#include <QMenu>
+#include <QMouseEvent>
+#include <QMaemo5InformationBox>
+
+slideshareListDialog::slideshareListDialog(SlideShare *s, QWidget *parent):
+    QDialog(parent),
+    ui(new Ui::fileListDialog)
+{
+    ui->setupUi(this);
+    this->setWindowTitle("SlideShare");
+    ui->downloadProgressBar->setVisible(false);
+    this->service = s;
+    ui->listTab->setCurrentIndex(1);
+    ui->listTab->removeTab(3);
+    connect(ui->uploadButton, SIGNAL(clicked()), this, SLOT(uploadButtonClickedSlot()));
+    connect(ui->downloadButton, SIGNAL(clicked()), this, SLOT(downloadButtonClickedSlot()));
+    connect(ui->refreshButton, SIGNAL(clicked()), this, SLOT(refreshList()));
+    connect(service, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateProgressBar(qint64, qint64)));
+    connect(service, SIGNAL(downloadDone()), this, SLOT(downloadDoneSlot()));
+    connect(service, SIGNAL(listDone()), this, SLOT(fillList()));
+
+    refreshList();
+}
+
+slideshareListDialog::~slideshareListDialog()
+{
+    delete ui;
+}
+
+void slideshareListDialog::refreshList()
+{
+    ui->downloadProgressBar->setMaximum(0);
+    ui->downloadProgressBar->setVisible(true);
+    ui->listTab->setEnabled(false);
+    ui->downloadButton->setEnabled(false);
+    ui->uploadButton->setEnabled(false);
+    ui->refreshButton->setEnabled(false);
+    service->listDocuments();
+}
+
+void slideshareListDialog::changeEvent(QEvent *e)
+{
+    QDialog::changeEvent(e);
+    switch(e->type()) {
+    case QEvent::LanguageChange:
+        ui->retranslateUi(this);
+        break;
+    default:
+        break;
+    }
+}
+
+void slideshareListDialog::downloadButtonClickedSlot()
+{
+    QListWidget *tmp;
+    QList<SlideShareDocument> list;
+    if(0 == ui->listTab->currentIndex()) {
+        tmp = ui->documentList;
+        list = service->textDocList;
+    }
+    if(1 == ui->listTab->currentIndex()) {
+        tmp = ui->presentationList;
+        list = service->presentationList;
+    }
+    if(2 == ui->listTab->currentIndex()) {
+        tmp = ui->spreadsheetList;
+        list = service->spreadsheetList;
+    }
+
+    if(tmp->currentRow() == -1) {
+        QMaemo5InformationBox::information(this, "Select a file from the list to download", QMaemo5InformationBox::DefaultTimeout);
+        return;
+    }
+
+    SlideShareDocument p = list[tmp->currentRow()];
+    QString durl = p.downloadUrl;
+
+    QString saveFileName = QFileDialog::getSaveFileName(this, "Save file", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation).append("/").append(p.title).append(".").append(p.format), QString("(*.").append(p.format).append(")"));
+    qDebug() << saveFileName << endl;
+    if("" == saveFileName) {
+        return;
+    }
+    service->setSaveFileName(new QString(saveFileName));
+
+    service->download(&durl);
+    ui->listTab->setEnabled(false);
+    ui->downloadButton->setEnabled(false);
+    ui->uploadButton->setEnabled(false);
+    ui->refreshButton->setEnabled(false);
+    ui->downloadProgressBar->setVisible(true);
+}
+
+void slideshareListDialog::uploadButtonClickedSlot()
+{
+    slideshareUploadDialog *ud = new slideshareUploadDialog(service, this);
+    if("" != openDocPath) {
+        ud->setOpenDoc(openDocPath);
+    }
+    ud->show();
+    connect(ud, SIGNAL(accepted()), this, SLOT(refreshList()));
+}
+
+void slideshareListDialog::fillList()
+{
+    ui->documentList->clear();
+    ui->presentationList->clear();
+    ui->spreadsheetList->clear();
+
+    QList<SlideShareDocument>  list;
+    QList<SlideShareDocument>::iterator i;
+
+    list = service->textDocList;
+    for(i = list.begin(); i != list.end(); ++i) {
+        SlideShareDocument j = *i;
+        QListWidgetItem *k = new QListWidgetItem(j.title);
+        ui->documentList->addItem(k);
+    }
+
+    list = service->presentationList;
+    for(i = list.begin(); i != list.end(); ++i) {
+        SlideShareDocument j = *i;
+        QListWidgetItem *k = new QListWidgetItem(j.title);
+        ui->presentationList->addItem(k);
+    }
+
+    list = service->spreadsheetList;
+    for(i = list.begin(); i != list.end(); ++i) {
+        SlideShareDocument j = *i;
+        QListWidgetItem *k = new QListWidgetItem(j.title);
+        ui->spreadsheetList->addItem(k);
+    }
+    ui->downloadProgressBar->setMaximum(100);
+    ui->downloadProgressBar->setVisible(false);
+    ui->listTab->setEnabled(true);
+    ui->downloadButton->setEnabled(true);
+    ui->uploadButton->setEnabled(true);
+    ui->refreshButton->setEnabled(true);
+}
+
+void slideshareListDialog::updateProgressBar(qint64 done, qint64 total)
+{
+    int value = (done * 100 / total);
+    ui->downloadProgressBar->setValue((int)value);
+}
+
+void slideshareListDialog::downloadDoneSlot()
+{
+    ui->downloadProgressBar->setVisible(false);
+    ui->downloadProgressBar->setValue(0);
+    ui->listTab->setEnabled(true);
+    ui->downloadButton->setEnabled(true);
+    ui->refreshButton->setEnabled(true);
+    ui->uploadButton->setEnabled(true);
+    QMaemo5InformationBox::information(this, "The file has finished downloading", QMaemo5InformationBox::DefaultTimeout);
+}
+
+void slideshareListDialog::setOpenDoc(const QString & openDocPath)
+{
+    this->openDocPath = openDocPath;
+}
+
+bool slideshareListDialog::eventFilter(QObject *obj, QEvent *event)
+{
+    if(event->type() == QEvent::ContextMenu) {
+        QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
+        QMenu *menu = new QMenu(this);
+        menu->addAction(new QAction("CLICK", this));
+        menu->exec(mouseEvent->globalPos());
+        return false;
+    }
+    return true;
+}
+
diff --git a/slidesharelistdialog.h b/slidesharelistdialog.h
new file mode 100644 (file)
index 0000000..5047b81
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SLIDESHARELISTDIALOG_H
+#define SLIDESHARELISTDIALOG_H
+
+#include <QDialog>
+#include "slideshare.h"
+
+namespace Ui
+{
+class fileListDialog;
+}
+
+class slideshareListDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    slideshareListDialog(SlideShare *s, QWidget *parent = 0);
+    ~slideshareListDialog();
+    void setOpenDoc(const QString &);
+
+protected:
+    void changeEvent(QEvent *e);
+
+private slots:
+    void downloadButtonClickedSlot();
+    void uploadButtonClickedSlot();
+    void fillList();
+    void downloadDoneSlot();
+    void updateProgressBar(qint64, qint64);
+    void refreshList();
+
+private:
+    Ui::fileListDialog *ui;
+    SlideShare *service;
+    bool eventFilter(QObject *, QEvent *);
+    QString openDocPath;
+
+};
+
+#endif // FILELISTDIALOG_H
diff --git a/slideshareuploaddialog.cpp b/slideshareuploaddialog.cpp
new file mode 100644 (file)
index 0000000..0d0a59a
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "slideshareuploaddialog.h"
+#include "ui_uploaddialog.h"
+
+#include "slideshare.h"
+
+#include <QFileDialog>
+#include <QDesktopServices>
+#include <QMaemo5InformationBox>
+
+slideshareUploadDialog::slideshareUploadDialog(SlideShare *service, QWidget *parent) :
+    QDialog(parent),
+    ui(new Ui::uploadDialog)
+{
+    this->service = service;
+    ui->setupUi(this);
+    connect(service, SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgressSlot(qint64, qint64)));
+    connect(ui->fileSelectButton, SIGNAL(clicked()), this, SLOT(showFileDialog()));
+    connect(ui->uploadButton, SIGNAL(clicked()), this, SLOT(uploadButtonClickedSlot()));
+    connect(service, SIGNAL(uploadDone()), this, SLOT(uploadDoneSlot()));
+}
+
+slideshareUploadDialog::~slideshareUploadDialog()
+{
+    delete ui;
+}
+
+void slideshareUploadDialog::setOpenDoc(const QString & openDocPath)
+{
+    ui->fileSelectEdit->setText(openDocPath);
+}
+
+void slideshareUploadDialog::changeEvent(QEvent *e)
+{
+    QDialog::changeEvent(e);
+    switch(e->type()) {
+    case QEvent::LanguageChange:
+        ui->retranslateUi(this);
+        break;
+    default:
+        break;
+    }
+}
+
+
+void slideshareUploadDialog::uploadProgressSlot(qint64 sent, qint64 total)
+{
+    qint64 value = (sent * 100 / total) ;
+    ui->uploadProgress->setValue(value);
+}
+
+void slideshareUploadDialog::showFileDialog()
+{
+    QString currentFile = ("" == ui->fileSelectEdit->text()) ? QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation) : ui->fileSelectEdit->text();
+    QString filter = "Supported Files (*.odt *.doc *.odp *.ppt *.ods *.xls)";
+    QString filename = QFileDialog::getOpenFileName(this, QString("Select File"), currentFile, filter, &filter);
+    if("" != filename)
+        ui->fileSelectEdit->setText(filename);
+}
+
+void slideshareUploadDialog::uploadButtonClickedSlot()
+{
+    if(ui->fileSelectEdit->text() == "" || ui->titleEdit->text() == "") {
+        QMaemo5InformationBox::information(this, "Please enter atleast filename and title");
+        return;
+    } else {
+        ui->fileSelectButton->setEnabled(false);
+        ui->titleEdit->setEnabled(false);
+        ui->descriptionBox->setEnabled(false);
+        ui->tagsEdit->setEnabled(false);
+        ui->uploadButton->setEnabled(false);
+        service->setSourceFile(&ui->fileSelectEdit->text());
+        service->setSlideTitle(&ui->titleEdit->text());
+        service->setDescription(&ui->descriptionBox->text());
+        service->setTags(&ui->tagsEdit->text());
+        service->setFormat(new QString(QFileInfo(ui->fileSelectEdit->text()).suffix()));
+        service->upload();
+    }
+}
+
+void slideshareUploadDialog::uploadDoneSlot()
+{
+    QMaemo5InformationBox::information(this, "<p><b>Upload done</b></p> It'll take some time for the file to appear in the list. Please be patient.");
+    ui->doneButton->setEnabled(true);
+}
diff --git a/slideshareuploaddialog.h b/slideshareuploaddialog.h
new file mode 100644 (file)
index 0000000..393ca19
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ *  Copyright (c) 2010 Kaushal M <kshlmster@gmail.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SLIDESHAREUPLOADDIALOG_H
+#define SLIDESHAREUPLOADDIALOG_H
+
+#include <QDialog>
+
+class SlideShare;
+namespace Ui
+{
+class uploadDialog;
+}
+
+class slideshareUploadDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    slideshareUploadDialog(SlideShare *service, QWidget *parent = 0);
+    ~slideshareUploadDialog();
+    void setOpenDoc(const QString &);
+
+protected:
+    void changeEvent(QEvent *e);
+
+private:
+    Ui::uploadDialog *ui;
+    SlideShare *service;
+
+private slots:
+    void uploadProgressSlot(qint64 bytesSent, qint64 bytesTotal);
+    void showFileDialog();
+    void uploadButtonClickedSlot();
+    void uploadDoneSlot();
+};
+
+#endif // UPLOADDIALOG_H
diff --git a/src.pro b/src.pro
new file mode 120000 (symlink)
index 0000000..2aaf2f8
--- /dev/null
+++ b/src.pro
@@ -0,0 +1 @@
+onlineServicesPlugin.pro
\ No newline at end of file
diff --git a/uploaddialog.ui b/uploaddialog.ui
new file mode 100644 (file)
index 0000000..5466f59
--- /dev/null
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>uploadDialog</class>
+ <widget class="QDialog" name="uploadDialog">
+  <property name="enabled">
+   <bool>true</bool>
+  </property>
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>514</width>
+    <height>147</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="windowTitle">
+   <string>Upload</string>
+  </property>
+  <property name="autoFillBackground">
+   <bool>false</bool>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QFormLayout" name="formLayout">
+     <item row="0" column="0">
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Select a file</string>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1">
+      <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <item>
+        <widget class="QLineEdit" name="fileSelectEdit">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+         <property name="readOnly">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QPushButton" name="fileSelectButton">
+         <property name="text">
+          <string>Select</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </item>
+     <item row="1" column="0">
+      <widget class="QLabel" name="label_2">
+       <property name="text">
+        <string>Title</string>
+       </property>
+      </widget>
+     </item>
+     <item row="1" column="1">
+      <widget class="QLineEdit" name="titleEdit"/>
+     </item>
+     <item row="2" column="0">
+      <widget class="QLabel" name="label_3">
+       <property name="text">
+        <string>Description</string>
+       </property>
+      </widget>
+     </item>
+     <item row="2" column="1">
+      <widget class="QLineEdit" name="descriptionBox"/>
+     </item>
+     <item row="3" column="0">
+      <widget class="QLabel" name="label_4">
+       <property name="text">
+        <string>Tags</string>
+       </property>
+      </widget>
+     </item>
+     <item row="3" column="1">
+      <widget class="QLineEdit" name="tagsEdit">
+       <property name="contextMenuPolicy">
+        <enum>Qt::DefaultContextMenu</enum>
+       </property>
+       <property name="frame">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QPushButton" name="uploadButton">
+       <property name="enabled">
+        <bool>true</bool>
+       </property>
+       <property name="text">
+        <string>Upload</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QProgressBar" name="uploadProgress">
+       <property name="value">
+        <number>0</number>
+       </property>
+       <property name="textVisible">
+        <bool>false</bool>
+       </property>
+       <property name="invertedAppearance">
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="doneButton">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
+       <property name="text">
+        <string>Done</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>doneButton</sender>
+   <signal>clicked()</signal>
+   <receiver>uploadDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>607</x>
+     <y>179</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>591</x>
+     <y>107</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>