From 39daccbd92545801c9025f5503f281692422db1b Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Fri, 1 Mar 2013 11:19:18 +0100 Subject: [PATCH] QML UI: Initial support for Sailfish Silica --- bin/gpodder | 2 +- share/gpodder/ui/qml/Main.qml | 1 + share/gpodder/ui/qml/Subscribe.qml | 1 + .../org/gpodder/qmlui}/ActionMenu.qml | 0 .../org/gpodder/qmlui}/InputField.qml | 0 .../{ => harmattan/org/gpodder/qmlui}/PagePage.qml | 1 + .../org/gpodder/qmlui}/SettingsSwitch.qml | 0 .../ui/qml/harmattan/org/gpodder/qmlui/qmldir | 4 ++++ share/gpodder/ui/qml/main_default.qml | 1 + .../org/gpodder/qmlui}/ActionMenu.qml | 26 +++++++++++----------- .../org/gpodder/qmlui}/InputField.qml | 8 +------ .../ui/qml/sailfish/org/gpodder/qmlui/PagePage.qml | 21 +++++++++++++++++ .../org/gpodder/qmlui}/SettingsSwitch.qml | 2 +- .../ui/qml/sailfish/org/gpodder/qmlui/qmldir | 4 ++++ src/gpodder/__init__.py | 2 ++ src/gpodder/qmlui/__init__.py | 15 ++++++++++--- src/gpodder/util.py | 4 ++-- src/gpodder/youtube.py | 2 +- 18 files changed, 66 insertions(+), 28 deletions(-) copy share/gpodder/ui/qml/{ => harmattan/org/gpodder/qmlui}/ActionMenu.qml (100%) copy share/gpodder/ui/qml/{ => harmattan/org/gpodder/qmlui}/InputField.qml (100%) rename share/gpodder/ui/qml/{ => harmattan/org/gpodder/qmlui}/PagePage.qml (92%) copy share/gpodder/ui/qml/{ => harmattan/org/gpodder/qmlui}/SettingsSwitch.qml (100%) create mode 100644 share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/qmldir rename share/gpodder/ui/qml/{ => sailfish/org/gpodder/qmlui}/ActionMenu.qml (53%) rename share/gpodder/ui/qml/{ => sailfish/org/gpodder/qmlui}/InputField.qml (63%) create mode 100644 share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/PagePage.qml rename share/gpodder/ui/qml/{ => sailfish/org/gpodder/qmlui}/SettingsSwitch.qml (94%) create mode 100644 share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/qmldir diff --git a/bin/gpodder b/bin/gpodder index aa702877..f705819e 100755 --- a/bin/gpodder +++ b/bin/gpodder @@ -121,7 +121,7 @@ def main(): options, args = parser.parse_args(sys.argv) - if options.qml or gpodder.ui.harmattan: + if options.qml or (gpodder.ui.harmattan or gpodder.ui.sailfish): gpodder.ui.qml = True else: gpodder.ui.gtk = True diff --git a/share/gpodder/ui/qml/Main.qml b/share/gpodder/ui/qml/Main.qml index 1975bc70..184dfb61 100644 --- a/share/gpodder/ui/qml/Main.qml +++ b/share/gpodder/ui/qml/Main.qml @@ -1,6 +1,7 @@ import QtQuick 1.1 import com.nokia.meego 1.0 +import org.gpodder.qmlui 1.0 import 'config.js' as Config import 'util.js' as Util diff --git a/share/gpodder/ui/qml/Subscribe.qml b/share/gpodder/ui/qml/Subscribe.qml index 595a8be7..7b8257c9 100644 --- a/share/gpodder/ui/qml/Subscribe.qml +++ b/share/gpodder/ui/qml/Subscribe.qml @@ -2,6 +2,7 @@ import QtQuick 1.1 import com.nokia.meego 1.0 +import org.gpodder.qmlui 1.0 import 'config.js' as Config diff --git a/share/gpodder/ui/qml/ActionMenu.qml b/share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/ActionMenu.qml similarity index 100% copy from share/gpodder/ui/qml/ActionMenu.qml copy to share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/ActionMenu.qml diff --git a/share/gpodder/ui/qml/InputField.qml b/share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/InputField.qml similarity index 100% copy from share/gpodder/ui/qml/InputField.qml copy to share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/InputField.qml diff --git a/share/gpodder/ui/qml/PagePage.qml b/share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/PagePage.qml similarity index 92% rename from share/gpodder/ui/qml/PagePage.qml rename to share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/PagePage.qml index 17f62eb7..245e094d 100644 --- a/share/gpodder/ui/qml/PagePage.qml +++ b/share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/PagePage.qml @@ -7,6 +7,7 @@ Page { signal closed property bool hasMenu: actions.length > 0 property alias actions: actionMenu.content + property variant listview // Unused here, see Sailfish UI function close() { pageStack.pop(); diff --git a/share/gpodder/ui/qml/SettingsSwitch.qml b/share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/SettingsSwitch.qml similarity index 100% copy from share/gpodder/ui/qml/SettingsSwitch.qml copy to share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/SettingsSwitch.qml diff --git a/share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/qmldir b/share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/qmldir new file mode 100644 index 00000000..b9e56d98 --- /dev/null +++ b/share/gpodder/ui/qml/harmattan/org/gpodder/qmlui/qmldir @@ -0,0 +1,4 @@ +ActionMenu 1.0 ActionMenu.qml +InputField 1.0 InputField.qml +PagePage 1.0 PagePage.qml +SettingsSwitch 1.0 SettingsSwitch.qml diff --git a/share/gpodder/ui/qml/main_default.qml b/share/gpodder/ui/qml/main_default.qml index 3ab996d1..c1291586 100644 --- a/share/gpodder/ui/qml/main_default.qml +++ b/share/gpodder/ui/qml/main_default.qml @@ -3,6 +3,7 @@ import QtQuick 1.1 import com.nokia.meego 1.0 import com.nokia.extras 1.1 import QtWebKit 1.0 +import org.gpodder.qmlui 1.0 import 'config.js' as Config diff --git a/share/gpodder/ui/qml/ActionMenu.qml b/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/ActionMenu.qml similarity index 53% rename from share/gpodder/ui/qml/ActionMenu.qml rename to share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/ActionMenu.qml index f2bcff43..0503f5fa 100644 --- a/share/gpodder/ui/qml/ActionMenu.qml +++ b/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/ActionMenu.qml @@ -1,6 +1,6 @@ import QtQuick 1.1 -import com.nokia.meego 1.0 +import Sailfish.Silica 1.0 Item { id: actionmenu @@ -14,26 +14,26 @@ Item { /* Show action menu when this function is called */ function open() { - contextMenu.open(); + pullDownMenu.open(); } anchors.fill: parent - ContextMenu { - id: contextMenu + PullDownMenu { + id: pullDownMenu - MenuLayout { - id: menuLayout + Repeater { + model: actions.children - Repeater { - model: actions.children - - MenuItem { - text: modelData.text - onClicked: modelData.clicked() - } + MenuItem { + text: modelData.text + onClicked: modelData.clicked() } } } + + Component.onCompleted: { + pullDownMenu.parent = actionmenu.listview; + } } diff --git a/share/gpodder/ui/qml/InputField.qml b/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/InputField.qml similarity index 63% rename from share/gpodder/ui/qml/InputField.qml rename to share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/InputField.qml index 327c67e9..844e2b80 100644 --- a/share/gpodder/ui/qml/InputField.qml +++ b/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/InputField.qml @@ -1,6 +1,6 @@ import QtQuick 1.1 -import com.nokia.meego 1.0 +import Sailfish.Silica 1.0 TextField { id: textField @@ -15,11 +15,5 @@ TextField { function closeVirtualKeyboard() { textField.platformCloseSoftwareInputPanel() } - - platformSipAttributes: SipAttributes { - actionKeyLabel: textField.actionName - actionKeyHighlighted: true - actionKeyEnabled: true - } } diff --git a/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/PagePage.qml b/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/PagePage.qml new file mode 100644 index 00000000..348d7c96 --- /dev/null +++ b/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/PagePage.qml @@ -0,0 +1,21 @@ + +import QtQuick 1.1 +import Sailfish.Silica 1.0 + +Page { + id: pagePage + signal closed + property bool hasMenu: actions.length > 0 + property alias actions: actionMenu.content + property alias listview: actionMenu.listview + + function close() { + pageStack.pop(); + closed(); + } + + ActionMenu { + id: actionMenu + } +} + diff --git a/share/gpodder/ui/qml/SettingsSwitch.qml b/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/SettingsSwitch.qml similarity index 94% rename from share/gpodder/ui/qml/SettingsSwitch.qml rename to share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/SettingsSwitch.qml index d257d8ce..f7748c7f 100644 --- a/share/gpodder/ui/qml/SettingsSwitch.qml +++ b/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/SettingsSwitch.qml @@ -1,6 +1,6 @@ import QtQuick 1.1 -import com.nokia.meego 1.0 +import Sailfish.Silica 1.0 Item { id: settingsSwitch diff --git a/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/qmldir b/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/qmldir new file mode 100644 index 00000000..b9e56d98 --- /dev/null +++ b/share/gpodder/ui/qml/sailfish/org/gpodder/qmlui/qmldir @@ -0,0 +1,4 @@ +ActionMenu 1.0 ActionMenu.qml +InputField 1.0 InputField.qml +PagePage 1.0 PagePage.qml +SettingsSwitch 1.0 SettingsSwitch.qml diff --git a/src/gpodder/__init__.py b/src/gpodder/__init__.py index f762dd75..c317322a 100644 --- a/src/gpodder/__init__.py +++ b/src/gpodder/__init__.py @@ -77,6 +77,7 @@ user_agent = 'gPodder/%s (+%s)' % (__version__, __url__) class UI(object): def __init__(self): self.harmattan = False + self.sailfish = False self.gtk = False self.qml = False self.cli = False @@ -211,6 +212,7 @@ def detect_platform(): etc_issue = '' ui.harmattan = ('MeeGo 1.2 Harmattan' in etc_issue) + ui.sailfish = ('Mer release' in etc_issue) if ui.harmattan and ENV_HOME not in os.environ: new_home = os.path.expanduser(os.path.join('~', 'MyDocs', 'gPodder')) diff --git a/src/gpodder/qmlui/__init__.py b/src/gpodder/qmlui/__init__.py index 23304f9d..d604ac10 100644 --- a/src/gpodder/qmlui/__init__.py +++ b/src/gpodder/qmlui/__init__.py @@ -496,8 +496,7 @@ class Controller(QObject): self.show_context_menu(menu) def show_context_menu(self, actions): - if gpodder.ui.harmattan: - actions = filter(lambda a: a.caption != '', actions) + actions = filter(lambda a: a.caption != '', actions) self.context_menu_actions = actions self.openContextMenu.emit(self.context_menu_actions) @@ -1039,12 +1038,22 @@ class qtPodder(QObject): root_context.setContextProperty('podcastModel', self.podcast_model) root_context.setContextProperty('episodeModel', self.episode_model) + for folder in gpodder.ui_folders: + if gpodder.ui.sailfish: + path = os.path.join(folder, 'sailfish') + else: + path = os.path.join(folder, 'harmattan') + + if os.path.exists(path): + logger.info('Adding QML Import Path: %s', path) + engine.addImportPath(path) + # Load the QML UI (this could take a while...) self.view.setSource(QUrl.fromLocalFile(QML('main_default.qml'))) self.view.setWindowTitle('gPodder') - if gpodder.ui.harmattan: + if gpodder.ui.harmattan or gpodder.ui.sailfish: self.view.showFullScreen() else: # On the Desktop, scale to fit my small laptop screen.. diff --git a/src/gpodder/util.py b/src/gpodder/util.py index 0be5eb00..85657618 100644 --- a/src/gpodder/util.py +++ b/src/gpodder/util.py @@ -92,7 +92,7 @@ if encoding is None: lang = os.environ['LANG'] (language, encoding) = lang.rsplit('.', 1) logger.info('Detected encoding: %s', encoding) - elif gpodder.ui.harmattan: + elif gpodder.ui.harmattan or gpodder.ui.sailfish: encoding = 'utf-8' elif gpodder.ui.win32: # To quote http://docs.python.org/howto/unicode.html: @@ -1512,7 +1512,7 @@ def detect_device_type(): Possible return values: desktop, laptop, mobile, server, other """ - if gpodder.ui.harmattan: + if gpodder.ui.harmattan or gpodder.ui.sailfish: return 'mobile' elif glob.glob('/proc/acpi/battery/*'): # Linux: If we have a battery, assume Laptop diff --git a/src/gpodder/youtube.py b/src/gpodder/youtube.py index 4a6fa044..f92c6ea5 100644 --- a/src/gpodder/youtube.py +++ b/src/gpodder/youtube.py @@ -135,7 +135,7 @@ def get_real_download_url(url, preferred_fmt_ids=None): # This provides good quality video, seems to be always available # and is playable fluently in Media Player - if gpodder.ui.harmattan: + if gpodder.ui.harmattan or gpodder.ui.sailfish: preferred_fmt_ids = [18] for id in preferred_fmt_ids: -- 2.11.4.GIT