Merge lp:~dpm/ubuntu-filemanager-app/xdguserdir into lp:ubuntu-filemanager-app

Proposed by David Planella
Status: Superseded
Proposed branch: lp:~dpm/ubuntu-filemanager-app/xdguserdir
Merge into: lp:ubuntu-filemanager-app
Diff against target: 638 lines (+319/-101)
14 files modified
debian/control (+10/-0)
debian/qtdeclarative5-xdguserdirs0.1.install (+1/-0)
src/app/qml/components/PathBar.qml (+6/-1)
src/app/qml/components/PlacesSidebar.qml (+2/-35)
src/app/qml/filemanager.qml (+7/-2)
src/app/qml/ui/FolderListPage.qml (+15/-28)
src/app/qml/ui/PlacesPopover.qml (+2/-35)
src/plugin/CMakeLists.txt (+1/-0)
src/plugin/xdguserdir/CMakeLists.txt (+35/-0)
src/plugin/xdguserdir/qmldir (+2/-0)
src/plugin/xdguserdir/xdguserdir.cpp (+108/-0)
src/plugin/xdguserdir/xdguserdir.h (+57/-0)
src/plugin/xdguserdir/xdguserdir_plugin.cpp (+34/-0)
src/plugin/xdguserdir/xdguserdir_plugin.h (+39/-0)
To merge this branch: bzr merge lp:~dpm/ubuntu-filemanager-app/xdguserdir
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Needs Fixing
David Planella Needs Information
Michael Spencer Needs Fixing
Nicholas Skaggs Pending
Review via email: mp+223411@code.launchpad.net

This proposal has been superseded by a proposal from 2014-06-18.

Commit message

Add a plugin to return the user's directories via the XDG spec

Description of the change

Add a plugin to return the user's directories via the XDG spec

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michael Spencer (ibelieve) wrote :

What is the reason for replacing "~" with userdirs.locationHome? "~" will get converted automatically into the right directory for use by the model, but is used throughout the app to refer to the home folder.

Also, you should mark your branch as fixing LP #1328332 and assign your self to the bug.

review: Needs Information
Revision history for this message
Michael Spencer (ibelieve) wrote :

I see the bug related to the "~" question I was wondering about, but I don't think using userdirs.locationHome is the right solution (assuming it is something like /home/mspencer). The folder property is designed to use "~", so if that is not working, it is a bug elsewhere, most likely involving the path property, which expands "~" to the user's home directory.

review: Needs Fixing
Revision history for this message
David Planella (dpm) wrote :

To answer the first question, the model does not seem to do the "~" expansion. This is the first bug this branch addresses.

The next one is about it not loading the localized user dirs.

Why do you think that userdirs.locationHome is not the right solution?

review: Needs Information
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Add the depends?

file:///usr/share/filemanager/qml/filemanager.qml:24:1: module "com.canonical.xdguserdir" is not installed
import com.canonical.xdguserdir 1.0

Revision history for this message
Michael Spencer (ibelieve) wrote :

Actually, it is doing the expansion correctly, at least it is when I just checked. The bug is here:

    FolderListModel {
        id: repeaterModel
        path: folderListPage.folder

        onPathChanged: {
            console.log("Path: " + repeaterModel.path)
        }
    }

userdirs.locationHome is wrong because folder is designed to use "~", while path converts that to the actual /home/<user> path:

    // This stores the location using ~ to represent home
    property string folder: homeFolder
    property string homeFolder: "~"

    // This replaces ~ with the actual home folder, since the
    // plugin doesn't recognize the ~
    property string path: folder.replace("~", folderModel.homePath())

So the actual fix to that bug should be changing:

    id: repeaterModel
    path: folderListPage.folder

To:

    id: repeaterModel
    path: folderListPage.path

Does that make sense, or is there something else I am missing?

210. By David Planella

Fixed ~ replacements, renamed plugin

211. By David Planella

Created debian package for the XDG user dirs plugin

Revision history for this message
David Planella (dpm) wrote :

Ah, I know what you mean now. Yes, what you are saying makes sense, and if that'd be the only bug targetted, this would be the fix that I'd favour too.

However, while fixing the hardcoded Documents, Music, etc. folders, I think it makes sense to return the home dir as part of the XDG user dirs listing, and it gives us the ability to use that as a model for the places sidebar and the places popup. Also, after your last comment, I've made some changes to remove the need to do on-the-fly replacement of "~"

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2014-05-06 17:57:59 +0000
+++ debian/control 2014-06-18 07:41:55 +0000
@@ -41,6 +41,16 @@
41 This package contains the Folder List model plugin of the Nemo QML 41 This package contains the Folder List model plugin of the Nemo QML
42 plugins collection.42 plugins collection.
4343
44Package: qtdeclarative5-xdguserdirs0.1
45Architecture: any
46Multi-Arch: same
47Depends: ${misc:Depends},
48 ${shlibs:Depends},
49 ${misc:Pre-Depends},
50Description: XDG user dirs QML plugin
51 This package contains a plugin that enables QML apps to list the
52 XDG user locations in the file system.
53
44Package: ubuntu-filemanager-app-autopilot54Package: ubuntu-filemanager-app-autopilot
45Architecture: all55Architecture: all
46Depends: ${misc:Depends},56Depends: ${misc:Depends},
4757
=== added file 'debian/qtdeclarative5-xdguserdirs0.1.install'
--- debian/qtdeclarative5-xdguserdirs0.1.install 1970-01-01 00:00:00 +0000
+++ debian/qtdeclarative5-xdguserdirs0.1.install 2014-06-18 07:41:55 +0000
@@ -0,0 +1,1 @@
1usr/lib/*/qt5/qml/com/ubuntu/XdgUserDirs/
02
=== modified file 'src/app/qml/components/PathBar.qml'
--- src/app/qml/components/PathBar.qml 2014-06-03 23:27:22 +0000
+++ src/app/qml/components/PathBar.qml 2014-06-18 07:41:55 +0000
@@ -1,6 +1,7 @@
1import QtQuick 2.01import QtQuick 2.0
2import Ubuntu.Components 0.12import Ubuntu.Components 0.1
3import Ubuntu.Components.Popups 0.13import Ubuntu.Components.Popups 0.1
4import com.ubuntu.XdgUserDirs 0.1
45
5Rectangle {6Rectangle {
6 id: root7 id: root
@@ -17,6 +18,10 @@
17 UbuntuNumberAnimation {}18 UbuntuNumberAnimation {}
18 }19 }
1920
21 XdgUserDirs {
22 id: userdirs
23 }
24
20 Rectangle {25 Rectangle {
21 id: goToButton26 id: goToButton
22 objectName: "goToButton"27 objectName: "goToButton"
@@ -117,7 +122,7 @@
117 Label {122 Label {
118 id: label123 id: label
119 anchors.centerIn: parent124 anchors.centerIn: parent
120 text: modelData === "" ? "/" : modelData === "~" ? i18n.tr("Home") : modelData125 text: modelData === "" ? "/" : modelData
121 color: UbuntuColors.coolGrey126 color: UbuntuColors.coolGrey
122 }127 }
123128
124129
=== modified file 'src/app/qml/components/PlacesSidebar.qml'
--- src/app/qml/components/PlacesSidebar.qml 2014-06-10 02:34:07 +0000
+++ src/app/qml/components/PlacesSidebar.qml 2014-06-18 07:41:55 +0000
@@ -20,6 +20,7 @@
20import Ubuntu.Components 0.120import Ubuntu.Components 0.1
21import Ubuntu.Components.ListItems 0.121import Ubuntu.Components.ListItems 0.1
22import Ubuntu.Components.Popups 0.122import Ubuntu.Components.Popups 0.1
23import com.ubuntu.XdgUserDirs 0.1
2324
24Sidebar {25Sidebar {
25 id: root26 id: root
@@ -42,40 +43,6 @@
42 UbuntuNumberAnimation {}43 UbuntuNumberAnimation {}
43 }44 }
4445
45 ListModel {
46 id: places
47
48 ListElement {
49 objectName: "placeHome"
50 path: "~"
51 }
52
53 ListElement {
54 path: "~/Documents"
55 }
56
57 ListElement {
58 path: "~/Downloads"
59 }
60
61 ListElement {
62 path: "~/Music"
63 }
64
65 ListElement {
66 path: "~/Pictures"
67 }
68
69 ListElement {
70 path: "~/Videos"
71 }
72
73 ListElement {
74 objectName: "placeRoot"
75 path: "/"
76 }
77 }
78
79 Column {46 Column {
80 anchors {47 anchors {
81 left: parent.left48 left: parent.left
@@ -91,7 +58,7 @@
91 id: placesList58 id: placesList
92 objectName: "placesList"59 objectName: "placesList"
9360
94 model: places61 model: XdgUserDirs {}
9562
96 delegate: Standard {63 delegate: Standard {
97 objectName: model.objectName64 objectName: model.objectName
9865
=== modified file 'src/app/qml/filemanager.qml'
--- src/app/qml/filemanager.qml 2014-04-29 18:05:45 +0000
+++ src/app/qml/filemanager.qml 2014-06-18 07:41:55 +0000
@@ -21,6 +21,7 @@
21import Ubuntu.Components.Popups 0.121import Ubuntu.Components.Popups 0.1
22import Ubuntu.Unity.Action 1.0 as UnityActions22import Ubuntu.Unity.Action 1.0 as UnityActions
23import U1db 1.0 as U1db23import U1db 1.0 as U1db
24import com.ubuntu.XdgUserDirs 0.1
2425
25import "ui"26import "ui"
2627
@@ -60,6 +61,10 @@
60 backgroundColor: "#797979"61 backgroundColor: "#797979"
61 footerColor: "#808080"62 footerColor: "#808080"
6263
64 XdgUserDirs {
65 id: userdirs
66 }
67
63 // HUD Actions68 // HUD Actions
64 Action {69 Action {
65 id: settingsAction70 id: settingsAction
@@ -72,7 +77,7 @@
7277
73 property var pageStack: pageStack78 property var pageStack: pageStack
7479
75 property var folderTabs: ["~"]80 property var folderTabs: [userdirs.locationHome]
7681
77 function openTab(folder) {82 function openTab(folder) {
78 var list = folderTabs83 var list = folderTabs
@@ -100,7 +105,7 @@
100 page: FolderListPage {105 page: FolderListPage {
101 objectName: "folderPage"106 objectName: "folderPage"
102107
103 folder: "~"//modelData108 folder: userdirs.locationHome //modelData
104 }109 }
105 }110 }
106111
107112
=== modified file 'src/app/qml/ui/FolderListPage.qml'
--- src/app/qml/ui/FolderListPage.qml 2014-04-30 08:54:08 +0000
+++ src/app/qml/ui/FolderListPage.qml 2014-06-18 07:41:55 +0000
@@ -20,6 +20,7 @@
20import Ubuntu.Components.Popups 0.120import Ubuntu.Components.Popups 0.1
21import Ubuntu.Components.ListItems 0.121import Ubuntu.Components.ListItems 0.1
22import org.nemomobile.folderlistmodel 1.022import org.nemomobile.folderlistmodel 1.0
23import com.ubuntu.XdgUserDirs 0.1
23import "../components"24import "../components"
2425
25Page {26Page {
@@ -63,27 +64,15 @@
63 }64 }
64 }65 }
6566
66 // This stores the location using ~ to represent home67 XdgUserDirs { id: userdirs }
68
67 property string folder69 property string folder
68 property string homeFolder: "~"70 property string path: folder
69
70 // This replaces ~ with the actual home folder, since the
71 // plugin doesn't recognize the ~
72 property string path: folder.replace("~", pageModel.homePath())
73
74 function goHome() {
75 goTo(folderListPage.homeFolder)
76 }
7771
78 function goTo(location) {72 function goTo(location) {
79 // Since the FolderListModel returns paths using the actual73 // This allows us to enter "~" as a shortcut to the home folder
80 // home folder, this replaces with ~ before actually going74 // when entering a location on the Go To dialog
81 // to the specified folder75 folderListPage.folder = location.replace("~", userdirs.locationHome)
82 while (location !== '/' && location.substring(location.lastIndexOf('/')+1) === "") {
83 location = location.substring(0, location.length - 1)
84 }
85
86 folderListPage.folder = location.replace(pageModel.homePath(), "~")
87 refresh()76 refresh()
88 }77 }
8978
@@ -113,21 +102,20 @@
113 // files will need an icon.102 // files will need an icon.
114 // TODO: Remove isDir parameter and use new model functions103 // TODO: Remove isDir parameter and use new model functions
115 function fileIcon(file, isDir) {104 function fileIcon(file, isDir) {
116 file = file.replace(pageModel.homePath(), "~")
117 var iconPath = isDir ? "/usr/share/icons/Humanity/places/48/folder.svg"105 var iconPath = isDir ? "/usr/share/icons/Humanity/places/48/folder.svg"
118 : "/usr/share/icons/Humanity/mimes/48/empty.svg"106 : "/usr/share/icons/Humanity/mimes/48/empty.svg"
119107
120 if (file === "~") {108 if (file === userdirs.locationHome) {
121 iconPath = "../icons/folder-home.svg"109 iconPath = "../icons/folder-home.svg"
122 } else if (file === i18n.tr("~/Desktop")) {110 } else if (file === i18n.tr("~/Desktop")) {
123 iconPath = "/usr/share/icons/Humanity/places/48/user-desktop.svg"111 iconPath = "/usr/share/icons/Humanity/places/48/user-desktop.svg"
124 } else if (file === i18n.tr("~/Documents")) {112 } else if (file === userdirs.locationDocuments) {
125 iconPath = "/usr/share/icons/Humanity/places/48/folder-documents.svg"113 iconPath = "/usr/share/icons/Humanity/places/48/folder-documents.svg"
126 } else if (file === i18n.tr("~/Downloads")) {114 } else if (file === userdirs.locationDownloads) {
127 iconPath = "/usr/share/icons/Humanity/places/48/folder-downloads.svg"115 iconPath = "/usr/share/icons/Humanity/places/48/folder-downloads.svg"
128 } else if (file === i18n.tr("~/Music")) {116 } else if (file === userdirs.locationMusic) {
129 iconPath = "/usr/share/icons/Humanity/places/48/folder-music.svg"117 iconPath = "/usr/share/icons/Humanity/places/48/folder-music.svg"
130 } else if (file === i18n.tr("~/Pictures")) {118 } else if (file === userdirs.locationPictures) {
131 iconPath = "/usr/share/icons/Humanity/places/48/folder-pictures.svg"119 iconPath = "/usr/share/icons/Humanity/places/48/folder-pictures.svg"
132 } else if (file === i18n.tr("~/Public")) {120 } else if (file === i18n.tr("~/Public")) {
133 iconPath = "/usr/share/icons/Humanity/places/48/folder-publicshare.svg"121 iconPath = "/usr/share/icons/Humanity/places/48/folder-publicshare.svg"
@@ -135,7 +123,7 @@
135 iconPath = "/usr/share/icons/Humanity/places/48/folder-system.svg"123 iconPath = "/usr/share/icons/Humanity/places/48/folder-system.svg"
136 } else if (file === i18n.tr("~/Templates")) {124 } else if (file === i18n.tr("~/Templates")) {
137 iconPath = "/usr/share/icons/Humanity/places/48/folder-templates.svg"125 iconPath = "/usr/share/icons/Humanity/places/48/folder-templates.svg"
138 } else if (file === i18n.tr("~/Videos")) {126 } else if (file === userdirs.locationVideos) {
139 iconPath = "/usr/share/icons/Humanity/places/48/folder-videos.svg"127 iconPath = "/usr/share/icons/Humanity/places/48/folder-videos.svg"
140 } else if (file === "/") {128 } else if (file === "/") {
141 iconPath = "/usr/share/icons/Humanity/devices/48/drive-harddisk.svg"129 iconPath = "/usr/share/icons/Humanity/devices/48/drive-harddisk.svg"
@@ -145,9 +133,8 @@
145 }133 }
146134
147 function folderName(folder) {135 function folderName(folder) {
148 folder = folder.replace(pageModel.homePath(), "~")
149136
150 if (folder === folderListPage.homeFolder) {137 if (folder === userdirs.locationHome) {
151 return i18n.tr("Home")138 return i18n.tr("Home")
152 } else if (folder === "/") {139 } else if (folder === "/") {
153 return i18n.tr("File System")140 return i18n.tr("File System")
@@ -208,7 +195,7 @@
208 path: folderListPage.folder195 path: folderListPage.folder
209196
210 onPathChanged: {197 onPathChanged: {
211 console.log("Path: " + repeaterModel.path)198 console.log("Path changed to: " + repeaterModel.path)
212 }199 }
213 }200 }
214201
215202
=== modified file 'src/app/qml/ui/PlacesPopover.qml'
--- src/app/qml/ui/PlacesPopover.qml 2014-06-10 02:34:07 +0000
+++ src/app/qml/ui/PlacesPopover.qml 2014-06-18 07:41:55 +0000
@@ -19,45 +19,12 @@
19import Ubuntu.Components 0.119import Ubuntu.Components 0.1
20import Ubuntu.Components.Popups 0.120import Ubuntu.Components.Popups 0.1
21import Ubuntu.Components.ListItems 0.121import Ubuntu.Components.ListItems 0.1
22import com.ubuntu.XdgUserDirs 0.1
2223
23Popover {24Popover {
24 id: root25 id: root
25 objectName: "placesPopover"26 objectName: "placesPopover"
2627
27 ListModel {
28 id: places
29
30 ListElement {
31 objectName: 'placeHome'
32 path: "~"
33 }
34
35 ListElement {
36 path: "~/Documents"
37 }
38
39 ListElement {
40 path: "~/Downloads"
41 }
42
43 ListElement {
44 path: "~/Music"
45 }
46
47 ListElement {
48 path: "~/Pictures"
49 }
50
51 ListElement {
52 path: "~/Videos"
53 }
54
55 ListElement {
56 objectName: "placeRoot"
57 path: "/"
58 }
59 }
60
61 Column {28 Column {
62 anchors {29 anchors {
63 left: parent.left30 left: parent.left
@@ -113,7 +80,7 @@
113 id: placesList80 id: placesList
114 objectName: "placesList"81 objectName: "placesList"
11582
116 model: places83 model: XdgUserDirs {}
11784
118 delegate: Standard {85 delegate: Standard {
119 objectName: model.objectName86 objectName: model.objectName
12087
=== modified file 'src/plugin/CMakeLists.txt'
--- src/plugin/CMakeLists.txt 2014-03-29 17:04:56 +0000
+++ src/plugin/CMakeLists.txt 2014-06-18 07:41:55 +0000
@@ -5,3 +5,4 @@
5find_package(Qt5Widgets)5find_package(Qt5Widgets)
66
7add_subdirectory(folderlistmodel)7add_subdirectory(folderlistmodel)
8add_subdirectory(xdguserdir)
89
=== added directory 'src/plugin/xdguserdir'
=== added file 'src/plugin/xdguserdir/CMakeLists.txt'
--- src/plugin/xdguserdir/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/plugin/xdguserdir/CMakeLists.txt 2014-06-18 07:41:55 +0000
@@ -0,0 +1,35 @@
1include_directories(
2 ${CMAKE_CURRENT_SOURCE_DIR}
3)
4
5set(PLUGIN_DIR com/ubuntu/XdgUserDirs)
6
7set(xdguserdir_SRCS
8 xdguserdir.cpp
9 xdguserdir.h
10 xdguserdir_plugin.cpp
11 xdguserdir_plugin.h
12)
13
14add_library(XdgUserDirs MODULE
15 ${xdguserdir_SRCS}
16)
17
18qt5_use_modules(XdgUserDirs Gui Qml Quick Widgets)
19
20# Copy the plugin, the qmldir file and other assets to the build dir for running in QtCreator
21if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
22 add_custom_command(TARGET XdgUserDirs POST_BUILD
23 COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/../${PLUGIN_DIR}
24 COMMENT "Creating plugin directory layout in the build directory"
25 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/qmldir ${CMAKE_CURRENT_BINARY_DIR}/../${PLUGIN_DIR}
26 COMMENT "Copying the qmldir file to the build directory"
27 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:XdgUserDirs> ${CMAKE_CURRENT_BINARY_DIR}/../${PLUGIN_DIR}
28 COMMENT "Copying the plugin binary to the build directory"
29 )
30endif(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
31
32# Install plugin file
33install(TARGETS XdgUserDirs DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN_DIR})
34install(FILES qmldir DESTINATION ${QT_IMPORTS_DIR}/${PLUGIN_DIR})
35
036
=== added file 'src/plugin/xdguserdir/qmldir'
--- src/plugin/xdguserdir/qmldir 1970-01-01 00:00:00 +0000
+++ src/plugin/xdguserdir/qmldir 2014-06-18 07:41:55 +0000
@@ -0,0 +1,2 @@
1module com.ubuntu.XdgUserDirs
2plugin XdgUserDirs
03
=== added file 'src/plugin/xdguserdir/xdguserdir.cpp'
--- src/plugin/xdguserdir/xdguserdir.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/xdguserdir/xdguserdir.cpp 2014-06-18 07:41:55 +0000
@@ -0,0 +1,108 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author : David Planella <david.planella@ubuntu.com>
17 */
18
19#include "xdguserdir.h"
20#include <QDebug>
21#include <QDir>
22
23XdgUserDir::XdgUserDir(QAbstractListModel *parent) :
24 QAbstractListModel(parent)
25{
26
27}
28
29XdgUserDir::~XdgUserDir() {
30
31}
32
33QString XdgUserDir::standardLocation(QStandardPaths::StandardLocation location) const
34{
35 QStringList locations = QStandardPaths::standardLocations(location);
36 QString standardLocation = "";
37
38 foreach (const QString &location, locations) {
39 // We always return the first location or an empty string
40 // The frontend should check out that it exists
41 if (QDir(location).exists()) {
42 standardLocation = location;
43 break;
44 }
45 }
46
47 return standardLocation;
48}
49
50QString XdgUserDir::locationHome() const
51{
52 return standardLocation(QStandardPaths::HomeLocation);
53}
54
55QString XdgUserDir::locationDocuments() const
56{
57 return standardLocation(QStandardPaths::DocumentsLocation);
58}
59
60QString XdgUserDir::locationDownloads() const
61{
62 return standardLocation(QStandardPaths::DownloadLocation);
63}
64
65QString XdgUserDir::locationMusic() const
66{
67 return standardLocation(QStandardPaths::MusicLocation);
68}
69
70QString XdgUserDir::locationPictures() const
71{
72 return standardLocation(QStandardPaths::PicturesLocation);
73}
74
75QString XdgUserDir::locationVideos() const
76{
77 return standardLocation(QStandardPaths::MoviesLocation);
78}
79
80int XdgUserDir::rowCount(const QModelIndex &parent) const
81{
82 Q_UNUSED(parent)
83 return 6;
84}
85
86QVariant XdgUserDir::data(const QModelIndex &index, int role) const
87{
88 Q_UNUSED(role)
89
90 switch(index.row()) {
91 case 0: return locationHome();
92 case 1: return locationDocuments();
93 case 2: return locationDownloads();
94 case 3: return locationMusic();
95 case 4: return locationPictures();
96 case 5: return locationVideos();
97 }
98
99 return QVariant();
100}
101
102QHash<int, QByteArray> XdgUserDir::roleNames() const
103{
104 QHash<int, QByteArray> roles;
105 roles.insert(Qt::UserRole, "path");
106
107 return roles;
108 }
0109
=== added file 'src/plugin/xdguserdir/xdguserdir.h'
--- src/plugin/xdguserdir/xdguserdir.h 1970-01-01 00:00:00 +0000
+++ src/plugin/xdguserdir/xdguserdir.h 2014-06-18 07:41:55 +0000
@@ -0,0 +1,57 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author : David Planella <david.planella@ubuntu.com>
17 */
18
19#ifndef XDGUSERDIR_H
20#define XDGUSERDIR_H
21
22#include <QObject>
23#include <QAbstractListModel>
24#include <QStandardPaths>
25
26class XdgUserDir : public QAbstractListModel
27{
28 Q_OBJECT
29
30 Q_PROPERTY(QString locationHome READ locationHome CONSTANT)
31 Q_PROPERTY(QString locationDocuments READ locationDocuments CONSTANT)
32 Q_PROPERTY(QString locationDownloads READ locationDownloads CONSTANT)
33 Q_PROPERTY(QString locationMusic READ locationMusic CONSTANT)
34 Q_PROPERTY(QString locationPictures READ locationPictures CONSTANT)
35 Q_PROPERTY(QString locationVideos READ locationVideos CONSTANT)
36
37public:
38 explicit XdgUserDir(QAbstractListModel *parent = 0);
39 ~XdgUserDir();
40 QString locationHome() const;
41 QString locationDocuments() const;
42 QString locationDownloads() const;
43 QString locationMusic() const;
44 QString locationPictures() const;
45 QString locationVideos() const;
46 int rowCount(const QModelIndex &parent) const override;
47 QVariant data(const QModelIndex &index, int role) const override;
48 QHash<int, QByteArray> roleNames() const override;
49
50private:
51 QString standardLocation(QStandardPaths::StandardLocation location) const;
52};
53
54#endif // XDGUSERDIR_H
55
56
57
058
=== added file 'src/plugin/xdguserdir/xdguserdir_plugin.cpp'
--- src/plugin/xdguserdir/xdguserdir_plugin.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/xdguserdir/xdguserdir_plugin.cpp 2014-06-18 07:41:55 +0000
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author : David Planella <david.planella@ubuntu.com>
17 */
18
19#include <QtQml>
20#include <QtQml/QQmlContext>
21#include "xdguserdir_plugin.h"
22#include "xdguserdir.h"
23
24void BackendPlugin::registerTypes(const char *uri)
25{
26 Q_ASSERT(uri == QLatin1String(QUOTES(PLUGIN_URI)));
27
28 qmlRegisterType<XdgUserDir>(uri, 0, 1, "XdgUserDirs");
29}
30
31void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
32{
33 QQmlExtensionPlugin::initializeEngine(engine, uri);
34}
035
=== added file 'src/plugin/xdguserdir/xdguserdir_plugin.h'
--- src/plugin/xdguserdir/xdguserdir_plugin.h 1970-01-01 00:00:00 +0000
+++ src/plugin/xdguserdir/xdguserdir_plugin.h 2014-06-18 07:41:55 +0000
@@ -0,0 +1,39 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author : David Planella <david.planella@ubuntu.com>
17 */
18
19#ifndef XDGUSERDIR_PLUGIN_H
20#define XDGUSERDIR_PLUGIN_H
21
22#include <QtQml/QQmlEngine>
23#include <QtQml/QQmlExtensionPlugin>
24
25class BackendPlugin : public QQmlExtensionPlugin
26{
27 Q_OBJECT
28 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
29
30public:
31 void registerTypes(const char *uri);
32 void initializeEngine(QQmlEngine *engine, const char *uri);
33};
34#endif // XDGUSERDIR_PLUGIN_H
35
36
37
38
39

Subscribers

People subscribed via source and target branches