diff --git a/harbour-tooter.pro.user b/harbour-tooter.pro.user index b34a024..9306f93 100644 --- a/harbour-tooter.pro.user +++ b/harbour-tooter.pro.user @@ -1,14 +1,14 @@ - + EnvironmentId - {41ec03ca-9430-48f3-b421-990d428b2838} + {25497605-1bff-4134-a878-76c1475dd8e3} ProjectExplorer.Project.ActiveTarget - 1 + 0 ProjectExplorer.Project.EditorSettings @@ -61,12 +61,12 @@ MerSDK-SailfishOS-i486 MerSDK-SailfishOS-i486 - {fd18ca89-dfc9-4054-9c53-c67be7689951} + {f49c1b5a-d715-401a-9a10-0e5fe9e5b72a} 0 - 2 + 0 0 - /Users/dysko/GIT/build-harbour-tooter-MerSDK_SailfishOS_i486-Debug + C:/Users/dysko/SF/build-harbour-tooter-MerSDK_SailfishOS_i486-Debug true @@ -138,7 +138,7 @@ true - /Users/dysko/GIT/build-harbour-tooter-MerSDK_SailfishOS_i486-Release + C:/Users/dysko/SF/build-harbour-tooter-MerSDK_SailfishOS_i486-Release true @@ -210,7 +210,7 @@ true - /Users/dysko/GIT/build-harbour-tooter-MerSDK_SailfishOS_i486-Profile + C:/Users/dysko/SF/build-harbour-tooter-MerSDK_SailfishOS_i486-Profile true @@ -396,21 +396,19 @@ 13 14 - /Users/dysko/GIT/harbour-tooter + C:/Users/dysko/SF/harbour-tooter false 10234 3 - 1 + 2 - harbour-tooter (on Remote Device) + + + %{buildDir} + Custom Executable - QmakeProjectManager.MerRunConfiguration:harbour-tooter - - harbour-tooter - - false - + ProjectExplorer.CustomExecutableRunConfiguration 3768 false true @@ -426,12 +424,12 @@ MerSDK-SailfishOS-armv7hl MerSDK-SailfishOS-armv7hl - {f895389d-b51a-4d4f-8b03-5ec64bda6f66} + {588087e2-ecc1-41aa-b652-86f16cba9351} 0 - 2 + 0 0 - /Users/dysko/GIT/build-harbour-tooter-MerSDK_SailfishOS_armv7hl-Debug + C:/Users/dysko/SF/build-harbour-tooter-MerSDK_SailfishOS_armv7hl-Debug true @@ -503,7 +501,7 @@ true - /Users/dysko/GIT/build-harbour-tooter-MerSDK_SailfishOS_armv7hl-Release + C:/Users/dysko/SF/build-harbour-tooter-MerSDK_SailfishOS_armv7hl-Release true @@ -575,7 +573,7 @@ true - /Users/dysko/GIT/build-harbour-tooter-MerSDK_SailfishOS_armv7hl-Profile + C:/Users/dysko/SF/build-harbour-tooter-MerSDK_SailfishOS_armv7hl-Profile true @@ -761,21 +759,19 @@ 13 14 - /Users/dysko/GIT/harbour-tooter + C:/Users/dysko/SF/harbour-tooter false 10234 3 - 1 + -1 - harbour-tooter (on Remote Device) + + + %{buildDir} + Custom Executable - QmakeProjectManager.MerRunConfiguration:harbour-tooter - - harbour-tooter - - false - + ProjectExplorer.CustomExecutableRunConfiguration 3768 false true diff --git a/qml/harbour-tooter.qml b/qml/harbour-tooter.qml index 1d0fe50..95d704a 100644 --- a/qml/harbour-tooter.qml +++ b/qml/harbour-tooter.qml @@ -52,8 +52,8 @@ ApplicationWindow } if (Logic.conf['login']) { Logic.api.setConfig("api_user_token", Logic.conf['api_user_token']) - //pageStack.push(Qt.resolvedUrl("./pages/MainPage.qml"), {}) - pageStack.push(Qt.resolvedUrl("./pages/Conversation.qml"), {}) + pageStack.push(Qt.resolvedUrl("./pages/MainPage.qml"), {}) + //pageStack.push(Qt.resolvedUrl("./pages/Conversation.qml"), {}) } else { pageStack.push(Qt.resolvedUrl("./pages/LoginPage.qml"), {}) } diff --git a/qml/pages/Conversation.qml b/qml/pages/Conversation.qml index 6b9461f..b1adb82 100644 --- a/qml/pages/Conversation.qml +++ b/qml/pages/Conversation.qml @@ -12,6 +12,9 @@ Page { property alias avatar: header.image property int toot_id property ListModel mdl; + ListModel { + id: mediaModel + } WorkerScript { id: worker @@ -131,29 +134,31 @@ Page { ? Theme.highlightColor : (warningContent.visible ? Theme.secondaryHighlightColor : Theme.primaryColor)) onClicked: { + btnAddImage.enabled = false; //receiver.receiveFromQml(42); //imageUploader.run() var once = true; - var imagePicker = pageStack.push("Sailfish.Pickers.MultiImagePickerDialog", { "allowedOrientations" : Orientation.All }); + // MultiImagePickerDialog + var imagePicker = pageStack.push("Sailfish.Pickers.ImagePickerPage", { "allowedOrientations" : Orientation.All }); imagePicker.selectedContentChanged.connect(function () { - if (once) { + var imagePath = imagePicker.selectedContent; + console.log(imagePath) + imageUploader.setUploadUrl(Logic.conf.instance + "/api/v1/media") + imageUploader.setFile(imagePath); + imageUploader.setAuthorizationHeader(Logic.conf.api_user_token); + imageUploader.upload(); + /*if (once) { for(var i = 0; i < imagePicker.selectedContent.count; i++){ var file = imagePicker.selectedContent.get(i); console.log(JSON.stringify(file)) + imageUploader.setUploadUrl("https://mastodon.social/api/v1/media") + //imageUploader.setUploadUrl("https://httpbin.org/post") imageUploader.setFile(file.url); imageUploader.setAuthorizationHeader(Logic.conf.api_user_token); imageUploader.upload(); } once = false; - } - - - /*var file = imagePicker.selectedContent + ""; - //file = file.replace("file://", ""); - console.log(file) - imageUploader.setFile(file); - imageUploader.setAuthorizationHeader(Logic.conf.api_user_token); - imageUploader.upload();*/ + }*/ }); } } @@ -166,15 +171,19 @@ Page { onSuccess: { console.log(replyData); + mediaModel.append(JSON.parse(replyData)) + btnAddImage.enabled = true; + } onFailure: { + btnAddImage.enabled = true; console.log(status) console.log(statusText) } - function run() { + /*function run() { imageUploader.setFile('file:///media/sdcard/686E-E026/Pictures/Camera/20170701_143819.jpg'); imageUploader.setParameters("imageUploadData.imageAlbum", "imageUploadData.imageTitle", "imageUploadData.imageDesc"); @@ -182,7 +191,7 @@ Page { imageUploader.setUserAgent("constant.userAgent"); imageUploader.upload(); - } + }*/ } ComboBox { id: privacy @@ -212,6 +221,12 @@ Page { enabled: toot.text !== "" onClicked: { var visibility = [ "public", "unlisted", "private", "direct"]; + var media_ids = []; + for(var k = 0; k < mediaModel.count; k++){ + console.log(mediaModel.get(k).id) + media_ids.push(mediaModel.get(k).id) + } + var msg = { 'action' : 'statuses', 'method' : 'POST', @@ -219,7 +234,8 @@ Page { 'mode' : "append", 'params' : { "status": toot.text, - "visibility": visibility[privacy.currentIndex] + "visibility": visibility[privacy.currentIndex], + "media_ids": media_ids }, 'conf' : Logic.conf }; diff --git a/qml/pages/LoginPage.qml b/qml/pages/LoginPage.qml index 0c1bd14..d4612e7 100644 --- a/qml/pages/LoginPage.qml +++ b/qml/pages/LoginPage.qml @@ -53,7 +53,7 @@ Page { id: column width: parent.width - PageHeader { title: "Login" } + PageHeader { title: qsTr("Login") } SectionHeader { text: "Instance" diff --git a/qml/pages/components/MyList.qml b/qml/pages/components/MyList.qml index 0a56a54..b013d10 100644 --- a/qml/pages/components/MyList.qml +++ b/qml/pages/components/MyList.qml @@ -58,7 +58,7 @@ SilicaListView { PullDownMenu { MenuItem { - text: Logic.conf['login'] ? qsTrId("Logout"): qsTrId("Login") + text: Logic.conf['login'] ? qsTr("Logout"): qsTr("Login") onClicked: { if (Logic.conf['login']) { Logic.conf['login'] = false diff --git a/rpm/harbour-tooter.changes.in b/rpm/harbour-tooter.changes.in index 6b1ae33..947c9da 100644 --- a/rpm/harbour-tooter.changes.in +++ b/rpm/harbour-tooter.changes.in @@ -29,3 +29,6 @@ * Tue July 4 2017 Dusko Angirevic 0.1.8-0 - Added notifications - App Cover redesigned + +* Thu July 7 2017 Dusko Angirevic 0.1.9-0 +- Image Upload added [#9] diff --git a/rpm/harbour-tooter.spec b/rpm/harbour-tooter.spec index b66ce07..f501ba0 100644 --- a/rpm/harbour-tooter.spec +++ b/rpm/harbour-tooter.spec @@ -13,7 +13,7 @@ Name: harbour-tooter %{!?qtc_make:%define qtc_make make} %{?qtc_builddir:%define _builddir %qtc_builddir} Summary: Tooter -Version: 0.1.8 +Version: 0.1.9 Release: 1 Group: Qt/Qt License: LICENSE diff --git a/rpm/harbour-tooter.yaml b/rpm/harbour-tooter.yaml index a4b9186..d75ffda 100644 --- a/rpm/harbour-tooter.yaml +++ b/rpm/harbour-tooter.yaml @@ -1,6 +1,6 @@ Name: harbour-tooter Summary: Tooter -Version: 0.1.8 +Version: 0.1.9 Release: # The contents of the Group field should be one of the groups listed here: # http://gitorious.org/meego-developer-tools/spectacle/blobs/master/data/GROUPS diff --git a/src/imageuploader.cpp b/src/imageuploader.cpp index f8cc271..3153372 100644 --- a/src/imageuploader.cpp +++ b/src/imageuploader.cpp @@ -3,12 +3,13 @@ #include #include #include -#include +#include + #include #include //static const QUrl IMGUR_UPLOAD_URL("https://httpbin.org/post"); -static const QUrl IMGUR_UPLOAD_URL("https://mastodon.social/api/v1/media"); +//static const QUrl IMGUR_UPLOAD_URL(); ImageUploader::ImageUploader(QObject *parent) : QObject(parent), m_networkAccessManager(0), m_reply(0) { m_networkAccessManager = new QNetworkAccessManager(this); @@ -45,8 +46,9 @@ void ImageUploader::setAuthorizationHeader(const QString &authorizationHeader) { m_authorizationHeader = "Bearer "+authorizationHeader.toUtf8(); } -void ImageUploader::setUserAgent(const QString &userAgent) { - m_userAgent = userAgent.toUtf8(); +void ImageUploader::setUploadUrl(const QString &UrlString) { + qDebug() << "Set Upload URL " + UrlString; + m_uploadUrl = UrlString.toUtf8(); } void ImageUploader::upload() { @@ -62,41 +64,60 @@ void ImageUploader::upload() { m_reply = 0; } - qDebug() << "TwitterApi::uploadImage"; - QUrl url = IMGUR_UPLOAD_URL; - QNetworkRequest request(url); - QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); - QHttpPart imagePart; - //imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); - imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"file\"")); - QFile *file = new QFile(m_fileName); - file->open(QIODevice::ReadOnly); - QByteArray rawImage = file->readAll(); - imagePart.setBody(rawImage); - file->setParent(multiPart); + /*QFileInfo fileInfo(QUrl(m_fileName).toLocalFile()); + qDebug("fileName: %s", qPrintable(m_fileName)); + if (!fileInfo.exists()) { + emit failure(-1, tr("The file %1 does not exists").arg(m_fileName)); + postdata.clear(); + return; + }*/ + QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); + QHttpPart imagePart; + + + //QFile file(fileInfo.absoluteFilePath()); + QFileInfo fileInfo(QUrl(m_fileName).toLocalFile()); + QFile* file = new QFile(QUrl(m_fileName).toLocalFile()); + if (!file->open(QIODevice::ReadWrite)) { + emit failure(-1, tr("The file %1 does not exists").arg(m_fileName)); + return; + } + /*bool opened = file.open(QIODevice::ReadOnly); + + if (!opened) { + qDebug("can't read file: %s", qPrintable(m_fileName)); + emit failure(-1, tr("Unable to open the file %1").arg(file.fileName())); + postdata.clear(); + return; + }*/ + + //QByteArray fileData = file.readAll().toBase64(); + imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg")); + imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name=\"file\"; filename=\"%1\"").arg(fileInfo.fileName()).toLatin1())); + imagePart.setBodyDevice(file); + file->setParent(multiPart); multiPart->append(imagePart); + //imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(fileInfo)); + //POST data - //request.setUrl(IMGUR_UPLOAD_URL); + + + QNetworkRequest request(m_uploadUrl); request.setRawHeader("Authorization", m_authorizationHeader); - request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); - - // request.setRawHeader("User-Agent", m_userAgent); - - - m_reply = m_networkAccessManager->post(request, multiPart); multiPart->setParent(m_reply); - m_reply->setObjectName("file"); - - - connect(m_reply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(uploadProgress(qint64,qint64))); connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished())); + + + + //connect(m_reply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(uploadProgress(qint64,qint64))); + //connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));*/ } qreal ImageUploader::progress() const { diff --git a/src/imageuploader.h b/src/imageuploader.h index 2410b67..e530e48 100644 --- a/src/imageuploader.h +++ b/src/imageuploader.h @@ -17,7 +17,7 @@ public: Q_INVOKABLE void setFile(const QString &fileName); Q_INVOKABLE void setAuthorizationHeader(const QString &authorizationHeader); - Q_INVOKABLE void setUserAgent(const QString &userAgent); + Q_INVOKABLE void setUploadUrl(const QString &userAgent); Q_INVOKABLE void setParameters(const QString &album, const QString &title, const QString &description); Q_INVOKABLE void upload(); @@ -38,7 +38,7 @@ private: QString m_fileName; QByteArray m_authorizationHeader; - QByteArray m_userAgent; + QString m_uploadUrl; QByteArray postdata; QNetworkReply *m_reply; }; diff --git a/translations/harbour-tooter-es.ts b/translations/harbour-tooter-es.ts index 741e002..9a05c21 100644 --- a/translations/harbour-tooter-es.ts +++ b/translations/harbour-tooter-es.ts @@ -1,17 +1,6 @@ - - - - - Cerrar sesión - - - - Iniciar sesión - - API @@ -24,11 +13,11 @@ boosted - Aumentado + aumentado said - Dijo + dijo @@ -50,27 +39,41 @@ Conversation Conversation - Conversación + Content warning! - Advertencia de contenido! + public - Público + unlisted - Deslistado + followers only - Sólo seguidores + direct - Directo + + + + + ImageUploader + + The file %1 does not exists + + + + + LoginPage + + Login + Iniciar sesión @@ -117,6 +120,14 @@ Load more Cargar más + + Logout + Cerrar sesión + + + Login + Iniciar sesión + Profile diff --git a/translations/harbour-tooter-fr.ts b/translations/harbour-tooter-fr.ts index b90de67..d48e262 100644 --- a/translations/harbour-tooter-fr.ts +++ b/translations/harbour-tooter-fr.ts @@ -1,17 +1,6 @@ - - - - - Déconnexion - - - - Connexion - - API @@ -50,27 +39,41 @@ Conversation Conversation - Conversation + Content warning! - Contenu sensible ! + public - public + unlisted - non-listé + followers only - abonnés uniquement + direct - direct + + + + + ImageUploader + + The file %1 does not exists + + + + + LoginPage + + Login + @@ -117,6 +120,14 @@ Load more Charger plus + + Logout + + + + Login + + Profile diff --git a/translations/harbour-tooter-nl.ts b/translations/harbour-tooter-nl.ts index 7206687..fc3131f 100644 --- a/translations/harbour-tooter-nl.ts +++ b/translations/harbour-tooter-nl.ts @@ -1,17 +1,6 @@ - - - - - - - - - - - API @@ -50,27 +39,41 @@ Conversation Conversation - Gesprek + Content warning! - Gevoelige inhoud! + public - openbaar + unlisted - niet op lijst + followers only - alleen volgers + direct - direct + + + + + ImageUploader + + The file %1 does not exists + + + + + LoginPage + + Login + @@ -117,6 +120,14 @@ Load more + + Logout + + + + Login + + Profile diff --git a/translations/harbour-tooter-oc.ts b/translations/harbour-tooter-oc.ts index 4710ad4..64798b6 100644 --- a/translations/harbour-tooter-oc.ts +++ b/translations/harbour-tooter-oc.ts @@ -1,17 +1,6 @@ - - - - - Se desconnectar - - - - Connexion - - API @@ -50,27 +39,41 @@ Conversation Conversation - Conversacion + Content warning! - Contengut sensible ! + public - public + unlisted - pas listat + followers only - seguidors solament + direct - dirècte + + + + + ImageUploader + + The file %1 does not exists + + + + + LoginPage + + Login + @@ -117,6 +120,14 @@ Load more Cargar mai + + Logout + + + + Login + + Profile diff --git a/translations/harbour-tooter.ts b/translations/harbour-tooter.ts index 1d791ef..b3243fe 100644 --- a/translations/harbour-tooter.ts +++ b/translations/harbour-tooter.ts @@ -1,34 +1,23 @@ - - - - - - - - - - - API favourited - favourited + favourited followed you - followed you + followed you boosted - boosted + boosted said - + said @@ -50,7 +39,7 @@ Conversation Conversation - + Conversation Content warning! @@ -58,19 +47,33 @@ public - + Content warning! unlisted - + unlisted followers only - + followers only direct - + direct + + + + ImageUploader + + The file %1 does not exists + The file %1 does not exists + + + + LoginPage + + Login + Login @@ -115,7 +118,15 @@ MyList Load more - + Load more + + + Logout + Logout + + + Login + Login @@ -188,19 +199,19 @@ VisualContainer Unboost - + Unboost Boost - + Boost Unfavorite - + Unfavorite Favorite - + Favorite