Changeset View
Changeset View
Standalone View
Standalone View
applets/quickshare/plasmoid/contents/ui/main.qml
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | 28 | DropArea { | |||
---|---|---|---|---|---|
63 | function filenameFromUrl(url) { | 63 | function filenameFromUrl(url) { | ||
64 | var parts = url.split("/"); | 64 | var parts = url.split("/"); | ||
65 | return parts[parts.length - 1]; | 65 | return parts[parts.length - 1]; | ||
66 | } | 66 | } | ||
67 | 67 | | |||
68 | function objectToArray(object) { | 68 | function objectToArray(object) { | ||
69 | var array = []; | 69 | var array = []; | ||
70 | for(var v in object) { | 70 | for(var v in object) { | ||
71 | array.push(object[v]); | 71 | // toString() here too because sometimes the contents are non-string (eg QUrl) | ||
72 | array.push(object[v].toString()); | ||||
72 | } | 73 | } | ||
73 | return array; | 74 | return array; | ||
74 | } | 75 | } | ||
75 | 76 | | |||
76 | onEntered: { | 77 | onEntered: { | ||
77 | root.state = "idle"; | 78 | root.state = "idle"; | ||
78 | var mimetype; | 79 | var mimetype; | ||
79 | if (drag.hasUrls) { | 80 | if (drag.hasUrls) { | ||
Show All 20 Lines | 100 | function resetActions() { | |||
100 | for(var v in root.pasteUrls) { | 101 | for(var v in root.pasteUrls) { | ||
101 | plasmoid.setAction(v, root.pasteUrls[v], ""); | 102 | plasmoid.setAction(v, root.pasteUrls[v], ""); | ||
102 | } | 103 | } | ||
103 | } | 104 | } | ||
104 | 105 | | |||
105 | ContentTracker { | 106 | ContentTracker { | ||
106 | id: contentTracker | 107 | id: contentTracker | ||
107 | } | 108 | } | ||
108 | MouseArea { | 109 | | ||
109 | anchors.fill: parent | 110 | function activate() { | ||
110 | onClicked: { | | |||
111 | if (root.state == "configuration") { | 111 | if (root.state == "configuration") { | ||
112 | root.state = "idle"; | 112 | root.state = "idle"; | ||
113 | } else if (contentTracker.uri) { | 113 | } else if (contentTracker.uri) { | ||
114 | var mime = contentTracker.mimeType; | 114 | var mime = contentTracker.mimeType; | ||
115 | if (!mime) { | 115 | if (!mime) { | ||
116 | mime = mimeDb.mimeTypeForUrl(contentTracker.uri).name; | 116 | mime = mimeDb.mimeTypeForUrl(contentTracker.uri).name; | ||
117 | } | 117 | } | ||
118 | sendData([contentTracker.uri], mime); | 118 | sendData([contentTracker.uri], mime); | ||
119 | } else { | 119 | } else { | ||
120 | action_paste(); | 120 | action_paste(); | ||
121 | } | 121 | } | ||
122 | } | 122 | } | ||
123 | | ||||
124 | MouseArea { | ||||
125 | anchors.fill: parent | ||||
126 | onClicked: { | ||||
127 | activate(); | ||||
128 | } | ||||
129 | } | ||||
130 | Plasmoid.onActivated: { | ||||
131 | activate(); | ||||
123 | } | 132 | } | ||
124 | 133 | | |||
125 | ShowUrlDialog { | 134 | ShowUrlDialog { | ||
126 | id: showUrl | 135 | id: showUrl | ||
127 | location: plasmoid.location | 136 | location: plasmoid.location | ||
128 | visualParent: parent | 137 | visualParent: parent | ||
129 | onCopyUrl: { | 138 | onCopyUrl: { | ||
130 | clipboard.content = showUrl.url; | 139 | clipboard.content = showUrl.url; | ||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 188 | // Awesome KIO magic <3 | |||
209 | 218 | | |||
210 | function actionTriggered(actionName) { | 219 | function actionTriggered(actionName) { | ||
211 | var index = parseInt(actionName); | 220 | var index = parseInt(actionName); | ||
212 | if (index) | 221 | if (index) | ||
213 | Qt.openUrlExternally(pasteUrls[actionName]); | 222 | Qt.openUrlExternally(pasteUrls[actionName]); | ||
214 | } | 223 | } | ||
215 | 224 | | |||
216 | function action_paste() { | 225 | function action_paste() { | ||
226 | if (clipboard.formats.length < 1) { // empty clipboard! | ||||
apol: This is not correct. What if the content isn't urls? | |||||
I think you are talking about the toString in line 72? If so: The objectToArray function is only called on clipboard.contentFormat() and on drop/drag.urls, so it's always only dealing with url types I think. I added the toString() because somehow it doesn't otherwise work with the QUrls returned by clipboard.contentFormat(), but it doesn't affect the urllists from drop/drag.urls, so I thought it's better to just add in the toString() instead of making a version of objectToArray just for clipboard.contentFormat(). yuenlim: I think you are talking about the toString in line 72? If so:
The objectToArray function is… | |||||
227 | return; // do nothing (there's the tooltip!) | ||||
228 | } | ||||
217 | if (clipboard.formats.indexOf("text/uri-list")>=0) { | 229 | if (clipboard.formats.indexOf("text/uri-list")>=0) { | ||
218 | sendData(clipboard.contentFormat("text/uri-list")); | 230 | var urls = objectToArray(clipboard.contentFormat("text/uri-list")) | ||
231 | sendData(urls, urlsMimetype(urls).name); | ||||
219 | } else { | 232 | } else { | ||
220 | var mimetype = firstMimeType(clipboard.formats).name; | 233 | var mimetype = firstMimeType(clipboard.formats).name; | ||
221 | sendBase64Data(PurposeHelper.variantToBase64(clipboard.contentFormat(mimetype)), mimetype); | 234 | sendBase64Data(PurposeHelper.variantToBase64(clipboard.contentFormat(mimetype)), mimetype); | ||
222 | } | 235 | } | ||
223 | } | 236 | } | ||
224 | 237 | | |||
225 | PlasmaCore.ToolTipArea { | 238 | PlasmaCore.ToolTipArea { | ||
226 | id: tooltipArea | 239 | id: tooltipArea | ||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |
This is not correct. What if the content isn't urls?