-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support push imports from content hub
It should support multiple imports, but I haven't had a chance to test that. The import dialog probably won't be that useful in that case, especially if there are errors. The import dialog generaly doesn't show as soon as it should, since the import processing happens before it has a chance to draw the dialog on the screen. Refs #61.
- Loading branch information
Showing
9 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"policy_groups": ["networking", "webview"], | ||
"policy_groups": ["networking", "webview", "content_exchange"], | ||
"policy_version": 1.2, | ||
"read_path": ["@{HOME}/"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"policy_groups": ["networking", "webview"], | ||
"policy_groups": ["networking", "webview", "content_exchange"], | ||
"policy_version": 1.2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"destination": ["ebooks", "documents"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
"hooks": { | ||
"beru": { | ||
"apparmor": "apparmor/beru@[email protected]", | ||
"desktop": "beru.desktop" | ||
"desktop": "beru.desktop", | ||
"content-hub": "beru.contenthub.json" | ||
} | ||
}, | ||
"maintainer": "Robert Schroll <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* Copyright 2015 Robert Schroll | ||
* | ||
* This file is part of Beru and is distributed under the terms of | ||
* the GPL. See the file COPYING for full details. | ||
*/ | ||
|
||
import QtQuick 2.0 | ||
import Ubuntu.Components 1.1 | ||
import Ubuntu.Components.Popups 1.0 | ||
import Ubuntu.Content 0.1 | ||
|
||
import "components" | ||
|
||
Item { | ||
id: importer | ||
property bool importError: false | ||
property bool openImport: true | ||
|
||
Connections { | ||
target: ContentHub | ||
onImportRequested: { | ||
if (transfer.state === ContentTransfer.Charged) | ||
importItems(transfer.items) | ||
} | ||
} | ||
|
||
Reader { | ||
id: importReader | ||
} | ||
|
||
function doImport(filename, item) { | ||
return function () { | ||
var components = filename.split("/").pop().split(".") | ||
var ext = components.pop() | ||
var dir = filesystem.getDataDir(localBooks.defaultdirname) | ||
var basename =components.join(".") | ||
var newfilename = basename + "." + ext | ||
var i = 0 | ||
while (filesystem.exists(dir + "/" + newfilename)) { | ||
i += 1 | ||
newfilename = basename + "(" + i + ")." + ext | ||
} | ||
item.move(dir, newfilename) | ||
localBooks.addFile(dir + "/" + newfilename, true) | ||
console.log("Importing as " + dir + "/" + newfilename) | ||
if (openImport) | ||
loadFile(dir + "/" + newfilename) | ||
} | ||
} | ||
|
||
function importItems(items) { | ||
var dialog = PopupUtils.open(importComponent) | ||
openImport = (items.length == 1) | ||
importError = false | ||
|
||
for (var i=0; i<items.length; i++) { | ||
var filename = items[i].url.toString().slice(7) | ||
if (importReader.load(filename)) { | ||
localBooks.inDatabase( | ||
importReader.hash(), | ||
function (currentfilename) { | ||
if (openImport) | ||
loadFile(currentfilename) | ||
console.log("This was already imported as " + currentfilename) | ||
}, | ||
doImport(filename, items[i])) | ||
} else { | ||
console.log("Import error: " + importReader.error) | ||
importError = true | ||
} | ||
} | ||
if (!importError) | ||
PopupUtils.close(dialog) | ||
} | ||
|
||
Component { | ||
id: importComponent | ||
Dialog { | ||
id: importDialog | ||
title: importError ? i18n.tr("Error Importing File") : i18n.tr("Import in Progress") | ||
text: importError ? importReader.error : "" | ||
StyledButton { | ||
text: i18n.tr("Dismiss") | ||
onClicked: { | ||
openImport = false | ||
PopupUtils.close(importDialog) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters