From 6cca6bf70449ae08cec72d0b8142079eec2c0216 Mon Sep 17 00:00:00 2001 From: "A. Madani" Date: Wed, 22 Feb 2023 22:46:58 +0300 Subject: [PATCH] apply gallery patch | not implemented --- qml/pages/SettingsPage.qml | 19 ++++++++++++++ qml/python/header.py | 4 +++ qml/python/main.py | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml index 513717f..b442978 100644 --- a/qml/pages/SettingsPage.qml +++ b/qml/pages/SettingsPage.qml @@ -12,6 +12,7 @@ Page { property var currentIconSet property var currentIcon property var configBoolean + property var applyPatchBoolean SilicaFlickable { id: settingsContainer @@ -41,6 +42,16 @@ Page { } } + TextSwitch { + id: applyPatch + text: qsTr("Add A Gallery Folder For Drive! Image Downloads") + description: qsTr("This will apply a patch to Jolla Gallery that will display an aditional Gallery folder for Drive!") + checked: false +// onCheckedChanged: { +// py.applyPatch(applyPatch.checked) +// } + } + TextSwitch { id: gridModeSet text: qsTr("Enable Grid Mode") @@ -75,6 +86,10 @@ Page { iconSet.checked = option }) + setHandler('applyPatchBoolean', function (option) { + applyPatch.checked = option + }) + setHandler('currentConfig', function (option) { currentIcon = option }) @@ -82,6 +97,10 @@ Page { importModule('main', function () {}) } + function applyPatch(checked) { + call('main.api.applyPatch', [checked], function () {}) + } + function configBooleanIconChange(checked) { call('main.api.configBooleanIconChange', [checked], function () {}) } diff --git a/qml/python/header.py b/qml/python/header.py index cb68a86..3b5edca 100644 --- a/qml/python/header.py +++ b/qml/python/header.py @@ -12,6 +12,10 @@ PORT = 8098 SUCCESS_MESSAGE = 'You can close this page now!...' DEFAULT_CONFIG = "iconSet=[silicaIconSet]\npageSize=[25]" +PATCH_PATH = "/usr/share//harbour-cargo/qml/python/patches/" +JOLLA_GALLERY_PATH = '/usr/share/jolla-gallery/' +GALLERY_QML_256 = '7ed28197af82d58d0fb3d4599db9ba08b15556efde7f8e4c85ac91304671997e' +GALLERY_START_PAGE_256 = '83fac1158194a85917605d18fbb3a458677fb4e978615b3c4e85b097a0c79519' SCOPES = [ 'https://www.googleapis.com/auth/drive.metadata.readonly', diff --git a/qml/python/main.py b/qml/python/main.py index 9e82d3d..1473452 100755 --- a/qml/python/main.py +++ b/qml/python/main.py @@ -15,6 +15,7 @@ import header import hashlib import mimetypes +import hashlib socket.setdefaulttimeout = 5 @@ -53,6 +54,14 @@ def __init__(self): self.host = header.HOST self.port = header.PORT self.success_message = header.SUCCESS_MESSAGE + self.gallery_path = header.JOLLA_GALLERY_PATH + self.gallery_qml_256 = header.GALLERY_QML_256 + self.gallery_start_page_256 = header.GALLERY_START_PAGE_256 + self.gallery_name = 'gallery' + self.gallery_start_page_name = 'GalleryStartPage' + self.qml_suffix = '.qml' + self.patch_suffix = '.patch' + self.patch_path = header.PATCH_PATH def pathChecks(self, path): @@ -432,6 +441,51 @@ def isAscii(self, string): else: return True + def checkSum(self, filename): + + with open(filename, 'rb') as orig: + bytes = orig.read() + sha256sum = hashlib.sha256(bytes).hexdigest() + return sha256sum + + def patchCommand(self, file, patch): + + patch_command = "patch -u -b %s -i %s" %(file, self.patch_path + patch + self.patch_suffix) + print(patch_command) + return os.system(patch_command) + + def applyPatch(self, checked): + ''' + apply patches/ to header.gallery_path + gallery.qml and pages/GalleryStartPage.qml + + This will add a Cargo! Photos section to Gallery + + will checksum both files as of 4.5.0.18 + ''' + + gallery = self.gallery_path + self.gallery_name + self.qml_suffix + gallery_start_page = self.gallery_path + 'pages/' + self.gallery_start_page_name + self.qml_suffix + + if checked: + print(checked, 'applyingPatch') + if self.checkSum(gallery) == self.gallery_qml_256 and self.checkSum(gallery_start_page) == self.gallery_start_page_256: + self.patchCommand(gallery, self.gallery_name) + self.patchCommand(gallery_start_page, self.gallery_start_page_name) + pyotherside.send('applyPatch', True) + return True + else: + pass + + else: + print(checked, 'revertingPatch') + pyotherside.send('applyPatch', False) +# patchCommand(self.gallery_name) +# patchCommand(self.gallery_start_page_name) + return False + + + api = Operations()