[Feature] modified image uploader to serve other mimetypes, added pickers
This commit is contained in:
parent
43ff5e5c78
commit
29a6086ad2
4 changed files with 100 additions and 15 deletions
|
@ -4,3 +4,9 @@ X-Nemo-Application-Type=silica-qt5
|
||||||
Icon=harbour-tooterb
|
Icon=harbour-tooterb
|
||||||
Exec=harbour-tooterb
|
Exec=harbour-tooterb
|
||||||
Name=Tooter β
|
Name=Tooter β
|
||||||
|
|
||||||
|
#[X-Sailjail]
|
||||||
|
#OrganizationName=de.poetaster
|
||||||
|
#ApplicationName=harbour-tooterb
|
||||||
|
#Permissions=Compatibility;Internet;Camera;Audio;MediaIndexing;RemovableMedia;UserDirs
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import QtQuick 2.0
|
import QtQuick 2.6
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
|
import Sailfish.Pickers 1.0
|
||||||
import harbour.tooterb.Uploader 1.0
|
import harbour.tooterb.Uploader 1.0
|
||||||
import "../lib/API.js" as Logic
|
import "../lib/API.js" as Logic
|
||||||
import "./components/"
|
import "./components/"
|
||||||
|
@ -38,6 +39,17 @@ Page {
|
||||||
else status_link = status_uri
|
else status_link = status_uri
|
||||||
} else status_link = status_url
|
} else status_link = status_url
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// This function is used by the upload Pickers
|
||||||
|
function fileUpload(file,mime) {
|
||||||
|
imageUploader.setUploadUrl(Logic.conf.instance + "/api/v1/media")
|
||||||
|
imageUploader.setFile(file)
|
||||||
|
imageUploader.setMime(mime)
|
||||||
|
imageUploader.setAuthorizationHeader(Logic.conf.api_user_token)
|
||||||
|
imageUploader.upload()
|
||||||
|
}
|
||||||
|
|
||||||
allowedOrientations: Orientation.All
|
allowedOrientations: Orientation.All
|
||||||
onSuggestedUserChanged: {
|
onSuggestedUserChanged: {
|
||||||
//console.log(suggestedUser)
|
//console.log(suggestedUser)
|
||||||
|
@ -375,7 +387,7 @@ Page {
|
||||||
IconButton {
|
IconButton {
|
||||||
id: btnAddImage
|
id: btnAddImage
|
||||||
enabled: mediaModel.count < 4
|
enabled: mediaModel.count < 4
|
||||||
icon.source: "image://theme/icon-s-attach?" + ( pressed ? Theme.highlightColor : (warningContent.visible ? Theme.secondaryHighlightColor : Theme.primaryColor) )
|
icon.source: "image://theme/icon-m-file-image?" + ( pressed ? Theme.highlightColor : (warningContent.visible ? Theme.secondaryHighlightColor : Theme.primaryColor) )
|
||||||
anchors {
|
anchors {
|
||||||
top: toot.bottom
|
top: toot.bottom
|
||||||
topMargin: -Theme.paddingSmall * 1.5
|
topMargin: -Theme.paddingSmall * 1.5
|
||||||
|
@ -385,20 +397,79 @@ Page {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
btnAddImage.enabled = false
|
btnAddImage.enabled = false
|
||||||
var once = true
|
var once = true
|
||||||
var imagePicker = pageStack.push("Sailfish.Pickers.ImagePickerPage", { "allowedOrientations": Orientation.All })
|
pageStack.push(imagePickerPage)
|
||||||
imagePicker.selectedContentChanged.connect(function () {
|
}
|
||||||
var imagePath = imagePicker.selectedContent
|
}
|
||||||
|
|
||||||
// console.log(imagePath)
|
|
||||||
|
|
||||||
|
IconButton {
|
||||||
|
id: btnAddMusic
|
||||||
|
enabled: mediaModel.count < 4
|
||||||
|
icon.source: "image://theme/icon-m-file-audio?" + ( pressed ? Theme.highlightColor : (warningContent.visible ? Theme.secondaryHighlightColor : Theme.primaryColor) )
|
||||||
|
anchors {
|
||||||
|
top: toot.bottom
|
||||||
|
topMargin: -Theme.paddingSmall * 1.5
|
||||||
|
left: btnAddImage.right
|
||||||
|
leftMargin: Theme.paddingSmall
|
||||||
|
}
|
||||||
|
onClicked: {
|
||||||
|
btnAddMusic.enabled = false
|
||||||
|
var once = true
|
||||||
|
pageStack.push(musicPickerPage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IconButton {
|
||||||
|
id: btnAddVideo
|
||||||
|
enabled: mediaModel.count < 4
|
||||||
|
icon.source: "image://theme/icon-m-file-video?" + ( pressed ? Theme.highlightColor : (warningContent.visible ? Theme.secondaryHighlightColor : Theme.primaryColor) )
|
||||||
|
anchors {
|
||||||
|
top: toot.bottom
|
||||||
|
topMargin: -Theme.paddingSmall * 1.5
|
||||||
|
left: btnAddMusic.right
|
||||||
|
leftMargin: Theme.paddingSmall
|
||||||
|
}
|
||||||
|
onClicked: {
|
||||||
|
btnAddVideo.enabled = false
|
||||||
|
var once = true
|
||||||
|
pageStack.push(videoPickerPage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Component {
|
||||||
|
id: musicPickerPage
|
||||||
|
MusicPickerPage {
|
||||||
|
onSelectedContentPropertiesChanged: {
|
||||||
|
var imagePath = selectedContentProperties.url
|
||||||
|
var mimeType = selectedContentProperties.mimeType
|
||||||
|
fileUpload(imagePath,mimeType)
|
||||||
|
/*
|
||||||
imageUploader.setUploadUrl(Logic.conf.instance + "/api/v1/media")
|
imageUploader.setUploadUrl(Logic.conf.instance + "/api/v1/media")
|
||||||
imageUploader.setFile(imagePath)
|
imageUploader.setFile(imagePath)
|
||||||
|
imageUploader.setMime(mimeType)
|
||||||
imageUploader.setAuthorizationHeader(Logic.conf.api_user_token)
|
imageUploader.setAuthorizationHeader(Logic.conf.api_user_token)
|
||||||
imageUploader.upload()
|
imageUploader.upload()
|
||||||
})
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Component {
|
||||||
|
id: imagePickerPage
|
||||||
|
ImagePickerPage {
|
||||||
|
onSelectedContentPropertiesChanged: {
|
||||||
|
var imagePath = selectedContentProperties.url
|
||||||
|
var mimeType = selectedContentProperties.mimeType
|
||||||
|
fileUpload(imagePath,mimeType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Component {
|
||||||
|
id: videoPickerPage
|
||||||
|
VideoPickerPage {
|
||||||
|
onSelectedContentPropertiesChanged: {
|
||||||
|
var imagePath = selectedContentProperties.url
|
||||||
|
var mimeType = selectedContentProperties.mimeType
|
||||||
|
fileUpload(imagePath,mimeType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageUploader {
|
ImageUploader {
|
||||||
id: imageUploader
|
id: imageUploader
|
||||||
onProgressChanged: {
|
onProgressChanged: {
|
||||||
|
@ -413,6 +484,8 @@ Page {
|
||||||
onFailure: {
|
onFailure: {
|
||||||
uploadProgress.width = 0
|
uploadProgress.width = 0
|
||||||
btnAddImage.enabled = true
|
btnAddImage.enabled = true
|
||||||
|
btnAddMusic.enabled = true
|
||||||
|
btnAddVideo.enabled = true
|
||||||
//console.log(status)
|
//console.log(status)
|
||||||
//console.log(statusText)
|
//console.log(statusText)
|
||||||
}
|
}
|
||||||
|
@ -437,7 +510,7 @@ Page {
|
||||||
anchors {
|
anchors {
|
||||||
top: toot.bottom
|
top: toot.bottom
|
||||||
topMargin: -Theme.paddingSmall * 1.5
|
topMargin: -Theme.paddingSmall * 1.5
|
||||||
left: btnAddImage.right
|
left: btnAddVideo.right
|
||||||
right: btnSend.left
|
right: btnSend.left
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,9 @@ ImageUploader::~ImageUploader() {
|
||||||
void ImageUploader::setFile(const QString &fileName) {
|
void ImageUploader::setFile(const QString &fileName) {
|
||||||
m_fileName = fileName;
|
m_fileName = fileName;
|
||||||
}
|
}
|
||||||
|
void ImageUploader::setMime(const QString &mimeType) {
|
||||||
|
m_mimeType = mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
void ImageUploader::setParameters(const QString &album, const QString &title, const QString &description) {
|
void ImageUploader::setParameters(const QString &album, const QString &title, const QString &description) {
|
||||||
//if (!album.isEmpty()) {
|
//if (!album.isEmpty()) {
|
||||||
|
@ -92,7 +95,8 @@ void ImageUploader::upload() {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
//QByteArray fileData = file.readAll().toBase64();
|
//QByteArray fileData = file.readAll().toBase64();
|
||||||
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
|
//imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
|
||||||
|
imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(m_mimeType));
|
||||||
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name=\"file\"; filename=\"%1\"").arg(fileInfo.fileName()).toLatin1()));
|
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QString("form-data; name=\"file\"; filename=\"%1\"").arg(fileInfo.fileName()).toLatin1()));
|
||||||
imagePart.setBodyDevice(file);
|
imagePart.setBodyDevice(file);
|
||||||
file->setParent(multiPart);
|
file->setParent(multiPart);
|
||||||
|
|
|
@ -16,6 +16,7 @@ public:
|
||||||
~ImageUploader();
|
~ImageUploader();
|
||||||
|
|
||||||
Q_INVOKABLE void setFile(const QString &fileName);
|
Q_INVOKABLE void setFile(const QString &fileName);
|
||||||
|
Q_INVOKABLE void setMime(const QString &mimeType);
|
||||||
Q_INVOKABLE void setAuthorizationHeader(const QString &authorizationHeader);
|
Q_INVOKABLE void setAuthorizationHeader(const QString &authorizationHeader);
|
||||||
Q_INVOKABLE void setUploadUrl(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 setParameters(const QString &album, const QString &title, const QString &description);
|
||||||
|
@ -37,6 +38,7 @@ private:
|
||||||
QNetworkAccessManager *m_networkAccessManager;
|
QNetworkAccessManager *m_networkAccessManager;
|
||||||
|
|
||||||
QString m_fileName;
|
QString m_fileName;
|
||||||
|
QString m_mimeType;
|
||||||
QByteArray m_authorizationHeader;
|
QByteArray m_authorizationHeader;
|
||||||
QString m_uploadUrl;
|
QString m_uploadUrl;
|
||||||
QByteArray postdata;
|
QByteArray postdata;
|
||||||
|
|
Loading…
Reference in a new issue