Commit bdcd0728 authored by Karel Slaný's avatar Karel Slaný Committed by Martin Straka

Added location selector combo box into FileDialogue.

parent 24722008
......@@ -44,6 +44,7 @@ Dialog {
property string selectedFileName: ""
function raise() {
folderModel.folder = standardLocationUrl(InteractionFilesystem.DESKTOP_LOCATION)
root.open()
}
......@@ -51,6 +52,10 @@ Dialog {
return url.toString().replace(/^(file:\/{2})/, "")
}
function standardLocationUrl(location) {
return "file://" + interactionFilesystem.locate(location)
}
InteractionFilesystem {
id: interactionFilesystem
}
......@@ -58,6 +63,30 @@ Dialog {
contentItem: ColumnLayout {
spacing: 6
ComboBox {
anchors {
left: parent.left;
right: parent.right;
}
textRole: "label"
model: ListModel {
ListElement { label: qsTr("Desktop"); value: "desktop" }
ListElement { label: qsTr("Documents"); value: "documents" }
}
onCurrentIndexChanged: {
var location = InteractionFilesystem.DESKTOP_LOCATION
if (model.get(currentIndex).value == "desktop") {
location = InteractionFilesystem.DESKTOP_LOCATION
} else if (model.get(currentIndex).value == "documents") {
location = InteractionFilesystem.DOCUMENTS_LOCATION
} else {
location = InteractionFilesystem.DESKTOP_LOCATION
}
folderModel.folder = standardLocationUrl(location)
}
}
RowLayout {
anchors {
left: parent.left;
......@@ -120,7 +149,7 @@ Dialog {
showDirsFirst: true
nameFilters: ["*.*"]
folder: "file://" + interactionFilesystem.locateHome()
folder: standardLocationUrl(InteractionFilesystem.DESKTOP_LOCATION)
onFolderChanged: {
selectedFileName = ""
......
......@@ -31,6 +31,7 @@ void InteractionFilesystem::declareQML(void)
{
qmlRegisterType<InteractionFilesystem>("cz.nic.mobileDatovka.qmlInteraction", 1, 0, "InteractionFilesystem");
qRegisterMetaType<InteractionFilesystem>();
qRegisterMetaType<InteractionFilesystem::Location>();
}
InteractionFilesystem::InteractionFilesystem(QObject *parent)
......@@ -44,12 +45,36 @@ InteractionFilesystem::InteractionFilesystem(const InteractionFilesystem &inter)
Q_UNUSED(inter)
}
QString InteractionFilesystem::locateHome(void)
/*!
* @brief Converts between location enums.
*
* @param[in] location Location as defined in QML convenience class.
* @return Location as defined in QStandardPaths.
*/
static
enum QStandardPaths::StandardLocation toStandardLocation(
enum InteractionFilesystem::Location location)
{
switch (location) {
case InteractionFilesystem::DESKTOP_LOCATION:
return QStandardPaths::DesktopLocation;
break;
case InteractionFilesystem::DOCUMENTS_LOCATION:
return QStandardPaths::DocumentsLocation;
break;
default :
Q_ASSERT(0);
return QStandardPaths::DesktopLocation;
break;
}
}
QString InteractionFilesystem::locate(enum Location location)
{
const QStringList homesLocation(
QStandardPaths::standardLocations(QStandardPaths::HomeLocation));
if (!homesLocation.isEmpty()) {
return homesLocation.at(0);
const QStringList locations(
QStandardPaths::standardLocations(toStandardLocation(location)));
if (!locations.isEmpty()) {
return locations.at(0);
} else {
return QStringLiteral(".");
}
......
......@@ -34,6 +34,13 @@ class InteractionFilesystem : public QObject {
Q_OBJECT
public:
/* Corresponds to some QStandardPaths::StandardLocation. */
enum Location {
DESKTOP_LOCATION,
DOCUMENTS_LOCATION
};
Q_ENUM(Location)
/* Don't forget to declare various properties to the QML system. */
static
void declareQML(void);
......@@ -60,7 +67,7 @@ public:
* @return Home location path.
*/
static Q_INVOKABLE
QString locateHome(void);
QString locate(enum Location location);
/*!
* @brief Check whether path is a readable directory.
......@@ -87,5 +94,6 @@ public:
/* QML passes its arguments via QVariant. */
Q_DECLARE_METATYPE(InteractionFilesystem)
Q_DECLARE_METATYPE(InteractionFilesystem::Location)
#endif /* _INTERACTION_FILESYSTEM_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment