This file is indexed.

/usr/lib/x86_64-linux-gnu/qt5/qml/Ubuntu/Components/1.3/Tabs.qml is in qml-module-ubuntu-components-gles 1.3.1918+16.04.20160404-0ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/*
 * Copyright 2012 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.4
import Ubuntu.Components 1.3 as Toolkit

/*!
    \qmltype Tabs
    \inqmlmodule Ubuntu.Components 1.1
    \ingroup ubuntu
    \brief The Tabs class provides an environment where multible \l Tab
    children can be added, and the user is presented with a tab
    bar with tab buttons to select different tab pages.

    Tabs must be placed inside a \l MainView so that it will automatically
    have a header that shows the tabs that can be selected, and the toolbar
    which contains the tools of the \l Page in the currently selected \l Tab.

    Example:
    \qml
        import QtQuick 2.4
        import Ubuntu.Components 1.3
        import Ubuntu.Components.ListItems 1.3 as ListItem

        MainView {
            width: units.gu(48)
            height: units.gu(60)

            Tabs {
                id: tabs
                Tab {
                    title: i18n.tr("Simple page")
                    page: Page {
                        Label {
                            id: label
                            anchors.centerIn: parent
                            text: "A centered label"
                        }
                        tools: ToolbarItems {
                            ToolbarButton {
                                text: "action"
                                onTriggered: print("action triggered")
                            }
                        }
                    }
                }
                Tab {
                    id: externalTab
                    title: i18n.tr("External")
                    page: Loader {
                        parent: externalTab
                        anchors {
                            left: parent.left
                            right: parent.right
                            bottom: parent.bottom
                        }
                        source: (tabs.selectedTab === externalTab) ? Qt.resolvedUrl("MyCustomPage.qml") : ""
                    }
                }
                Tab {
                    title: i18n.tr("List view")
                    page: Page {
                        ListView {
                            clip: true
                            anchors.fill: parent
                            model: 20
                            delegate: ListItem.Standard {
                                iconName: "compose"
                                text: "Item "+modelData
                            }
                        }
                    }
                }
            }
        }

    \endqml
    As the example above shows, an external \l Page inside a \l Tab can be loaded using a Loader.
    Note that setting the top anchor or the height of the Loader would override the \l Page height.
    We avoid this because the \l Page automatically adapts its height to accommodate for the header.

    It is possible to use a Repeater to generate tabs, but when doing so, ensure that the Repeater
    is declared inside the Tabs at the end, because otherwise the shuffling of
    the order of children by the Repeater can cause incorrect ordering of the tabs.

    The \l {http://design.ubuntu.com/apps/global-patterns/navigation}{Navigation Patterns} specify that
    a tabs header should never be combined with the back button of a \l PageStack. The only way to
    combine Tabs and \l PageStack that avoids this is by pushing the Tabs as the first page on the
    \l PageStack, and pushing other pages on top of that, as is shown in the following example:

    \qml
        import QtQuick 2.4
        import Ubuntu.Components 1.3

        MainView {
            id: mainView
            width: units.gu(38)
            height: units.gu(50)

            PageStack {
                id: pageStack
                Component.onCompleted: push(tabs)

                Tabs {
                    id: tabs
                    Tab {
                        title: "Tab 1"
                        page: Page {
                            Button {
                                anchors.centerIn: parent
                                onClicked: pageStack.push(page3)
                                text: "Press"
                            }
                        }
                    }
                    Tab {
                        title: "Tab 2"
                        page: Page {
                            Label {
                                anchors.centerIn: parent
                                text: "Use header to navigate between tabs"
                            }
                        }
                    }
                }
                Page {
                    id: page3
                    visible: false
                    title: "Page on stack"
                    Label {
                        anchors.centerIn: parent
                        text: "Press back to return to the tabs"
                    }
                }
            }
        }
    \endqml
*/
Toolkit.PageTreeNode {
    id: tabs
    anchors.fill: parent

    /*!
      \qmlproperty int selectedTabIndex
      The index of the currently selected tab.
      The first tab is 0, and -1 means that no tab is selected.
      The initial value is 0 if Tabs has contents, or -1 otherwise.
     */
    property alias selectedTabIndex: tabsModel.selectedIndex

    /*!
      The currently selected tab.
     */
    readonly property Tab selectedTab: (selectedTabIndex < 0) || (tabsModel.count <= selectedTabIndex) ?
                                           null : tabsModel.get(selectedTabIndex).tab

    /*!
      The page of the currently selected tab.
     */
    readonly property Item currentPage: selectedTab ? selectedTab.page : null

    /*!
      \deprecated
      The \l TabBar that will be shown in the header
      and provides scrollable tab buttons.
      This property is DEPRECATED. TabBar is now part of the header style.
     */
    property TabBar tabBar: internal.header && internal.header.__styleInstance &&
                            internal.header.__styleInstance.hasOwnProperty("__tabBar") ?
                                internal.header.__styleInstance.__tabBar : null

    /*!
      Children are placed in a separate item that has functionality to extract the Tab items.
      \qmlproperty list<Item> tabChildren
     */
    default property alias tabChildren: tabStack.data

    /*!
      \qmlproperty int count
      Contains the number of tabs in the Tabs component.
      */
    readonly property alias count: tabsModel.count

    /*!
      \deprecated
      Used by the tabs style to update the tabs header with the titles of all the tabs.
      This signal is used in an intermediate step in transitioning the tabs to a new
      implementation and may be removed in the future.
     */
    signal modelChanged()

    /*!
      \internal
      tst_tabs.qml needs access to the model to verify that Repeaters inside Tabs works.
     */
    property var __model: tabsModel

    /*!
      \internal
      required by TabsStyle
     */
    ListModel {
        id: tabsModel

        property bool updateDisabled: false

        /*!
          The index of the selected tab.
         */
        property int selectedIndex: tabsModel.count > 0 ? 0 : -1

        function listModel(tab) {
            return {"title": tab.title, "tab": tab};
        }

        function updateTabList(tabsList) {
            var offset = 0;
            var tabIndex;
            for (var i in tabsList) {
                var tab = tabsList[i];
                if (internal.isTab(tab)) {
                    tabIndex = i - offset;
                    // make sure we have the right parent
                    tab.parent = tabStack;

                    if (!tab.__protected.inserted) {
                        tab.__protected.index = tabIndex;
                        tab.__protected.inserted = true;
                        insert(tabIndex, listModel(tab));
                    } else if (!tab.__protected.removedFromTabs && tabsModel.count > tab.index) {
                        get(tab.index).title = tab.title;
                    }

                    // always makes sure that tabsModel has the same order as tabsList
                    move(tab.__protected.index, tabIndex, 1);
                    reindex();
                } else {
                    // keep track of children that are not tabs so that we compute
                    // the right index for actual tabs
                    offset += 1;
                }
            }
            internal.sync();
        }

        function reindex(from) {
            var start = 0;
            if (from !== undefined) {
                start = from + 1;
            }

            for (var i = start; i < count; i++) {
                var tab = get(i).tab;
                tab.__protected.index = i;
            }
        }
    }

    // FIXME: this component is not really needed, as it doesn't really bring any
    // value; should be removed in a later MR
    Item {
        anchors.fill: parent
        id: tabStack

        onChildrenChanged: {
            internal.connectToRepeaters(tabStack.children);
            tabsModel.updateTabList(tabStack.children);
        }
    }

    /*
      This timer is used when tabs are created using Repeaters. Repeater model
      element moves (shuffling) are causing re-stacking of the tab stack children
      which may not be realized at the time the rowsMoved/columnsMoved or layoutChanged
      signals are triggered. Therefore we use an idle timer to update the tabs
      model, so the tab stack is re-stacked by then.
      */
    Timer {
        id: updateTimer
        interval: 1
        running: false
        onTriggered: {
            tabsModel.updateTabList(tabStack.children);
            internal.sync();
        }
    }

    Toolkit.Object {
        id: internal
        property AppHeader header: tabs.__propagated ? tabs.__propagated.header : null

        /*
          List of connected Repeaters to avoid repeater "hammering" of itemAdded() signal.
          */
        property var repeaters: []

        function sync() {
            if (tabBar && tabBar.__styleInstance && tabBar.__styleInstance.hasOwnProperty("sync")) {
                tabBar.__styleInstance.sync();
            }
            if ((tabs.active && internal.header) &&
                    !(internal.header.config &&
                      internal.header.config.hasOwnProperty("locked") &&
                      internal.header.config.locked)) {
                internal.header.show();
            }
            // deprecated, however use it till we remove it completely
            tabs.modelChanged();
        }

        function isTab(item) {
            if (item && item.hasOwnProperty("__isPageTreeNode")
                    && item.__isPageTreeNode && item.hasOwnProperty("title")
                    && item.hasOwnProperty("page")) {
                return true;
            } else {
                return false;
            }
        }

        function isRepeater(item) {
            return (item && item.hasOwnProperty("itemAdded"));
        }

        function connectToRepeaters(children) {
            for (var i = 0; i < children.length; i++) {
                var child = children[i];
                if (internal.isRepeater(child) && internal.repeaters && (internal.repeaters.indexOf(child) < 0)) {
                    internal.connectRepeater(child);
                }
            }
        }
        /* When inserting a delegate into its parent the Repeater does it in 3
           steps:
           1) sets the parent of the delegate thus inserting it in the list of
              children in a position that does not correspond to the position of
              the corresponding item in the model. At that point the
              childrenChanged() signal is emitted.
           2) reorder the delegate to match the position of the corresponding item
              in the model.
           3) emits the itemAdded() signal.

           We need to update the list of tabs (tabsModel) when the children are in the
           adequate order hence the workaround below. It connects to the itemAdded()
           signal of any repeater it finds and triggers an update of the tabsModel.

           Somewhat related Qt bug report:
           https://bugreports.qt-project.org/browse/QTBUG-32438
        */
        function updateTabsModel() {
            tabsModel.updateTabList(tabStack.children);
        }

        /*
          Connects a Repeater and stores it so further connects will not happen to
          the same repeater avoiding in this way hammering.
          */
        function connectRepeater(repeater) {
            // store repeater
            repeaters.push(repeater);

            // connect destruction signal so we have a proper cleanup
            repeater.Component.onDestruction.connect(internal.disconnectRepeater.bind(repeater));

            // connect repeater's itemAdded and itemRemoved signals
            repeater.itemAdded.connect(internal.updateTabsModel);
            repeater.itemRemoved.connect(internal.removeTabFromModel);

            // check if the repeater's model is set, if not, connect to modelChanged to catch that
            if (repeater.model === undefined) {
                repeater.modelChanged.connect(internal.connectRepeaterModelChanges.bind(repeater));
            } else {
                connectRepeaterModelChanges(repeater);
            }
        }

        /*
          Disconnects the given repeater signals.
          */
        function disconnectRepeater() {
            this.itemAdded.disconnect(internal.updateTabsModel);
            this.itemRemoved.disconnect(internal.removeTabFromModel);
            this.modelChanged.disconnect(internal.connectRepeaterModelChanges);
        }

        /*
          Connects a Repeater's model change signals so we get notified whenever those change.
          This can be called either by the Repeater's modelChanged() signal, in which case the
          parameter is undefined, or from the connectRepeater() in case the model is given for
          the Repeater.
          */
        function connectRepeaterModelChanges(repeater) {
            if (repeater === undefined) {
                repeater = this;
            }

            /*
              Omit model types which are not derived from object (i.e. are [object Number]
              or [object Array] typed).

              JS 'instanceof' operator does not return true for all types of arrays (i.e
              for property var array: [....] it returns false). The safest way to detect
              whether the model is really an object we use the toString() prototype of
              the generic JS Object.

              Inspired from http://perfectionkills.com/instanceof-considered-harmful-or-how-to-write-a-robust-isarray/
              */
            if (Object.prototype.toString.call(repeater.model) !== "[object Object]") {
                return;
            }

            // other models are most likely derived from QAbstractItemModel,
            // therefore we can safely connect to the signals to get notified about refreshes
            repeater.model.rowsMoved.connect(updateTimer.restart);
            repeater.model.columnsMoved.connect(updateTimer.restart);
            repeater.model.layoutChanged.connect(updateTimer.restart);
        }

        // clean items removed trough a repeater
        function removeTabFromModel(index, item) {
            // cannot use index as that one is relative to the Repeater's model, therefore
            // we need to look after the Tabs models' role to find out which item to remove
            for (var i = 0; i < tabsModel.count; i++) {
                if (tabsModel.get(i).tab === item) {
                    tabsModel.remove(i);
                    break;
                }
            }
            tabsModel.reindex();
        }
    }

    Binding {
        target: internal.header
        property: "tabsModel"
        value: tabsModel
        when: internal.header && tabs.active
    }
}