Merge lp:~nikwen/webbrowser-app/open-in-new-background-tab into lp:webbrowser-app

Proposed by Niklas Wenzel
Status: Merged
Approved by: Olivier Tilloy
Approved revision: 871
Merged at revision: 885
Proposed branch: lp:~nikwen/webbrowser-app/open-in-new-background-tab
Merge into: lp:webbrowser-app
Diff against target: 113 lines (+39/-0)
6 files modified
src/app/actions/OpenLinkInNewBackgroundTab.qml (+23/-0)
src/app/webbrowser/Browser.qml (+6/-0)
src/app/webbrowser/settings.cpp (+6/-0)
src/app/webbrowser/settings.h (+2/-0)
src/app/webbrowser/webbrowser-app.cpp (+1/-0)
src/app/webbrowser/webbrowser-app.qml (+1/-0)
To merge this branch: bzr merge lp:~nikwen/webbrowser-app/open-in-new-background-tab
Reviewer Review Type Date Requested Status
Olivier Tilloy Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+245372@code.launchpad.net

Commit message

Add the ability to open a link in a new background tab

Description of the change

Added the ability to open a link in a new background tab

This is in some way related to LP: #1339437.
https://bugs.launchpad.net/webbrowser-app/+bug/1339437

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Here's an excerpt from the logs which states that the build failed, but it works fine on my local machine. Would somebody be so kind as to re-run the build, please?

The following tests FAILED:
   2 - tst_QmlTests (Failed)
Errors while running CTest
Makefile:120: recipe for target 'test' failed
make[1]: *** [test] Error 8
make[1]: Leaving directory '/tmp/buildd/webbrowser-app-0.23+15.04.20141218bzr864pkg0vivid121/obj-x86_64-linux-gnu'
dh_auto_test: make -j2 test ARGS+=-j2 returned exit code 2
debian/rules:11: recipe for target 'build' failed
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2
E: Failed autobuilding of package
[...]
bzr: ERROR: The build failed.
ERROR:pbuilderjenkins:Error during build execution
ERROR:pbuilderjenkins:pdebuild failed
pbuilder returned ERROR.
Build step 'Debian PBuilder NG' marked build as failure

Revision history for this message
Olivier Tilloy (osomon) wrote :

Niklas: the build failure is a known issue not related to your change, see bug #1396951 for details.

Revision history for this message
Olivier Tilloy (osomon) wrote :

And since I see that you updated the copyright notice, a minor remark: that file was added in 2014, and not modified since then, so the year in the notice should be 2014 only.

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Hi Olivier,

Thank you very much for looking into this. :)
Do you have any dates for when the chroots will be set up properly again?
I'll add changing the copyright notice to my TODO list. ;)

Revision history for this message
Olivier Tilloy (osomon) wrote :

No date that I can commit on, but I know it’s being worked on. In the meantime, it’s relatively safe to ignore those failures, given that the build succeeds on armhf (where it’s built on real hardware).

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Ok, here's the copyright notice fix.

What's about the change in general? As far as I can see, nobody has reviewed it yet, right?

Revision history for this message
Olivier Tilloy (osomon) wrote :

Looks good to me, thanks!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Thanks for approving. :)

I'll ping you again when the i386 chroot is working properly again, so that you can re-run the tests. ;)

Revision history for this message
Olivier Tilloy (osomon) wrote :

Hey Niklas, Giorgio mentioned in https://bugs.launchpad.net/webbrowser-app/+bug/1339437/comments/4 that this option should be added to the desktop version only.

Could you make it conditional? Something like this:

  Actions.OpenLinkInNewBackgroundTab {
    enabled: contextualData.href.toString() && (formFactor == "desktop")
    […]
  }

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Hi Olivier,

Thank you for pointing me to this post. I somehow forgot to subscribe to the bug report, so I didn't see it earlier.
Let me comment on the bug report for this. ;)

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Here you go. Now it's a setting as well. :)

Revision history for this message
Niklas Wenzel (nikwen) wrote :

The setting to enable the "Open in new background tab" option on the phone form factor can be turned on like this:

mkdir ~/.config/webbrowser-app
nano ~/.config/webbrowser-app/settings.conf

Add the following line to the file and save it. Then restart the webbrowser app.

enableBackgroundTabs=true

Revision history for this message
Olivier Tilloy (osomon) wrote :

Thanks Niklas, from a quick glance at the diff the change looks good. I wonder whether the setting could be made a boolean instead of a string. If I understand Giorgio’s suggestion correctly, on desktop it’s ok to always have the entry in the context menu, whereas on mobile it’s optional. So basically the setting should be ignored on desktop, and taken into account on mobile only.
By the way, can the name of the setting be updated to make it more explicit that it applies to mobile only?

Revision history for this message
Olivier Tilloy (osomon) wrote :

I would rename the setting to something like "allowOpenInBackgroundTabOnMobile". It’s a tad verbose, but it says what it does.

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Yes, it could be made a boolean but that would also alter its current behaviour.

The way it's currently implemented allows to disable the entry on the desktop as well. It uses three options: Show, don't show, and decide based on form factor.

We could drop the ability to hide it on the desktop in favour of making it a boolean but I'd vote for the more flexible current approach here.

Revision history for this message
Olivier Tilloy (osomon) wrote :

In that case the option can still be made a boolean (and renamed "allowOpenInBackgroundTab"). The option would in fact have three possible values:

  (not set) default behaviour, i.e. enabled on desktop and disabled on mobile
  (True) enabled on all form factors
  (False) disabled on all form factors

The fact that the default behaviour is form-factor dependent should be clearly documented in the code.

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Yes, this is how it currently works.
Since C++ (as far as I know) doesn't allow undefined as a value for boolean variables, we need to have a variable with at least 3 different values, hence an enumaration (which will be troublesome in connection with QML), a numerical value (whose meaning won't be self-explaining when passing it to the QML property) or a string, which in this particular case is what was entered in the settings file.

We can't directly provide the "show option or not" value from the settings C++ class because we cannot easily get the form factor there.

This is why I decided to do it this way:

1) Pass the value from the settings.conf file directly to QML as a string.
2) Let QML decide whether to hide the option based on the settings vallue and the form factor.

These are the values the string can have:

  "formfactor_dependend": The default value if the setting isn't set, i.e. decide based on form factor.
  "true": If the option should be shown.
  "false" or anything else: If the option should not be shown.

I do, however, agree that we can rename the settings entry. I'll do that tomorrow and use the suggestion from your last post. ;)

What do you think?

Revision history for this message
Olivier Tilloy (osomon) wrote :

That sounds about right (I didn’t remember that we don’t have access to the form factor on the C++ side). Can "formfactor_dependend" be renamed to "default" ?

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Here you go. Is there anything left which I should change as well?

Thanks again for looking into this. :)

Revision history for this message
Olivier Tilloy (osomon) wrote :

That looks great now, thanks!
A couple of really minor comments:

 - the return type of allowOpenInBackgroundTab() could be "const QString&" to avoid an unnecessary copy

 - "anything else disables background tabs" is confusing, background tabs are not disabled, it’s just that the context menu option is not available. Can it be "anything else disables the option" instead?

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Thank you, Olivier. I'll change that later this day. :)

Revision history for this message
Niklas Wenzel (nikwen) wrote :

Here you go.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Is this actually an issue with my code or with the webbrowser-app in general? I saw the webbrowser_app.tests.test_addressbar_states.TestAddressBarStates.test_looses_focus_when_reloading test fail for other MPs as well, e.g. https://code.launchpad.net/~osomon/webbrowser-app/bottom-edge/+merge/248019, so it might be an issue in trunk.

Revision history for this message
Olivier Tilloy (osomon) wrote :

Not an issue with your code, this test is failing on otto (desktop) with other MRs, I need to look into it.

Revision history for this message
Olivier Tilloy (osomon) wrote :

Looks good and works well, both on desktop and a mobile device. Thanks!

review: Approve
Revision history for this message
Niklas Wenzel (nikwen) wrote :

Thank you, Oliver, for your generally quick replies. And thank you for merging this now. :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'src/app/actions/OpenLinkInNewBackgroundTab.qml'
2--- src/app/actions/OpenLinkInNewBackgroundTab.qml 1970-01-01 00:00:00 +0000
3+++ src/app/actions/OpenLinkInNewBackgroundTab.qml 2015-01-30 18:14:04 +0000
4@@ -0,0 +1,23 @@
5+/*
6+ * Copyright 2014 Canonical Ltd.
7+ *
8+ * This file is part of webbrowser-app.
9+ *
10+ * webbrowser-app is free software; you can redistribute it and/or modify
11+ * it under the terms of the GNU General Public License as published by
12+ * the Free Software Foundation; version 3.
13+ *
14+ * webbrowser-app is distributed in the hope that it will be useful,
15+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+ * GNU General Public License for more details.
18+ *
19+ * You should have received a copy of the GNU General Public License
20+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
21+ */
22+
23+import Ubuntu.Components 1.1
24+
25+Action {
26+ text: i18n.tr("Open link in new background tab")
27+}
28
29=== modified file 'src/app/webbrowser/Browser.qml'
30--- src/app/webbrowser/Browser.qml 2014-12-17 09:22:40 +0000
31+++ src/app/webbrowser/Browser.qml 2015-01-30 18:14:04 +0000
32@@ -37,6 +37,7 @@
33
34 property url homepage
35 property QtObject searchEngine
36+ property string allowOpenInBackgroundTab
37
38 // XXX: we might want to tweak this value depending
39 // on the form factor and/or the available memory
40@@ -357,6 +358,11 @@
41 enabled: contextualData.href.toString()
42 onTriggered: browser.openUrlInNewTab(contextualData.href, true)
43 }
44+ Actions.OpenLinkInNewBackgroundTab {
45+ enabled: contextualData.href.toString() && ((browser.allowOpenInBackgroundTab === "true") ||
46+ ((browser.allowOpenInBackgroundTab === "default") && (formFactor === "desktop")))
47+ onTriggered: browser.openUrlInNewTab(contextualData.href, false)
48+ }
49 Actions.BookmarkLink {
50 enabled: contextualData.href.toString() && browser.bookmarksModel
51 onTriggered: browser.bookmarksModel.add(contextualData.href, contextualData.title, "")
52
53=== modified file 'src/app/webbrowser/settings.cpp'
54--- src/app/webbrowser/settings.cpp 2014-06-30 10:40:59 +0000
55+++ src/app/webbrowser/settings.cpp 2015-01-30 18:14:04 +0000
56@@ -32,6 +32,7 @@
57 m_homepage = settings.value("homepage", QUrl(DEFAULT_HOMEPAGE)).toUrl();
58 QString name = settings.value("searchengine", QString(DEFAULT_SEARCH_ENGINE)).toString();
59 m_searchengine = new SearchEngine(name, this);
60+ m_allowOpenInBackgroundTab = settings.value("allowOpenInBackgroundTab", "default").toString().toLower();
61 }
62
63 const QUrl& Settings::homepage() const
64@@ -43,3 +44,8 @@
65 {
66 return m_searchengine;
67 }
68+
69+const QString& Settings::allowOpenInBackgroundTab() const
70+{
71+ return m_allowOpenInBackgroundTab;
72+}
73
74=== modified file 'src/app/webbrowser/settings.h'
75--- src/app/webbrowser/settings.h 2014-06-30 10:40:59 +0000
76+++ src/app/webbrowser/settings.h 2015-01-30 18:14:04 +0000
77@@ -38,10 +38,12 @@
78
79 const QUrl& homepage() const;
80 SearchEngine* searchEngine() const;
81+ const QString& allowOpenInBackgroundTab() const;
82
83 private:
84 QUrl m_homepage;
85 SearchEngine* m_searchengine;
86+ QString m_allowOpenInBackgroundTab; //"true" for enabled, "default" for form factor dependend behaviour (currently desktop only), anything else disables the option
87 };
88
89 #endif // __SETTINGS_H__
90
91=== modified file 'src/app/webbrowser/webbrowser-app.cpp'
92--- src/app/webbrowser/webbrowser-app.cpp 2014-12-11 17:04:20 +0000
93+++ src/app/webbrowser/webbrowser-app.cpp 2015-01-30 18:14:04 +0000
94@@ -100,6 +100,7 @@
95 searchEngine->setParent(m_window);
96 m_window->setProperty("homepage", settings.homepage());
97 m_window->setProperty("searchEngine", QVariant::fromValue(searchEngine));
98+ m_window->setProperty("allowOpenInBackgroundTab", settings.allowOpenInBackgroundTab());
99 m_window->setProperty("restoreSession", !m_arguments.contains("--new-session"));
100 QVariantList urls;
101 Q_FOREACH(const QUrl& url, this->urls()) {
102
103=== modified file 'src/app/webbrowser/webbrowser-app.qml'
104--- src/app/webbrowser/webbrowser-app.qml 2014-11-03 17:01:29 +0000
105+++ src/app/webbrowser/webbrowser-app.qml 2015-01-30 18:14:04 +0000
106@@ -25,6 +25,7 @@
107
108 property alias searchEngine: browser.searchEngine
109 property alias restoreSession: browser.restoreSession
110+ property alias allowOpenInBackgroundTab: browser.allowOpenInBackgroundTab
111
112 property alias homepage: browser.homepage
113 property alias urls: browser.initialUrls

Subscribers

People subscribed via source and target branches

to status/vote changes: