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 { ...@@ -44,6 +44,7 @@ Dialog {
property string selectedFileName: "" property string selectedFileName: ""
function raise() { function raise() {
folderModel.folder = standardLocationUrl(InteractionFilesystem.DESKTOP_LOCATION)
root.open() root.open()
} }
...@@ -51,6 +52,10 @@ Dialog { ...@@ -51,6 +52,10 @@ Dialog {
return url.toString().replace(/^(file:\/{2})/, "") return url.toString().replace(/^(file:\/{2})/, "")
} }
function standardLocationUrl(location) {
return "file://" + interactionFilesystem.locate(location)
}
InteractionFilesystem { InteractionFilesystem {
id: interactionFilesystem id: interactionFilesystem
} }
...@@ -58,6 +63,30 @@ Dialog { ...@@ -58,6 +63,30 @@ Dialog {
contentItem: ColumnLayout { contentItem: ColumnLayout {
spacing: 6 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 { RowLayout {
anchors { anchors {
left: parent.left; left: parent.left;
...@@ -120,7 +149,7 @@ Dialog { ...@@ -120,7 +149,7 @@ Dialog {
showDirsFirst: true showDirsFirst: true
nameFilters: ["*.*"] nameFilters: ["*.*"]
folder: "file://" + interactionFilesystem.locateHome() folder: standardLocationUrl(InteractionFilesystem.DESKTOP_LOCATION)
onFolderChanged: { onFolderChanged: {
selectedFileName = "" selectedFileName = ""
......
...@@ -31,6 +31,7 @@ void InteractionFilesystem::declareQML(void) ...@@ -31,6 +31,7 @@ void InteractionFilesystem::declareQML(void)
{ {
qmlRegisterType<InteractionFilesystem>("cz.nic.mobileDatovka.qmlInteraction", 1, 0, "InteractionFilesystem"); qmlRegisterType<InteractionFilesystem>("cz.nic.mobileDatovka.qmlInteraction", 1, 0, "InteractionFilesystem");
qRegisterMetaType<InteractionFilesystem>(); qRegisterMetaType<InteractionFilesystem>();
qRegisterMetaType<InteractionFilesystem::Location>();
} }
InteractionFilesystem::InteractionFilesystem(QObject *parent) InteractionFilesystem::InteractionFilesystem(QObject *parent)
...@@ -44,12 +45,36 @@ InteractionFilesystem::InteractionFilesystem(const InteractionFilesystem &inter) ...@@ -44,12 +45,36 @@ InteractionFilesystem::InteractionFilesystem(const InteractionFilesystem &inter)
Q_UNUSED(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( const QStringList locations(
QStandardPaths::standardLocations(QStandardPaths::HomeLocation)); QStandardPaths::standardLocations(toStandardLocation(location)));
if (!homesLocation.isEmpty()) { if (!locations.isEmpty()) {
return homesLocation.at(0); return locations.at(0);
} else { } else {
return QStringLiteral("."); return QStringLiteral(".");
} }
......
...@@ -34,6 +34,13 @@ class InteractionFilesystem : public QObject { ...@@ -34,6 +34,13 @@ class InteractionFilesystem : public QObject {
Q_OBJECT Q_OBJECT
public: 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. */ /* Don't forget to declare various properties to the QML system. */
static static
void declareQML(void); void declareQML(void);
...@@ -60,7 +67,7 @@ public: ...@@ -60,7 +67,7 @@ public:
* @return Home location path. * @return Home location path.
*/ */
static Q_INVOKABLE static Q_INVOKABLE
QString locateHome(void); QString locate(enum Location location);
/*! /*!
* @brief Check whether path is a readable directory. * @brief Check whether path is a readable directory.
...@@ -87,5 +94,6 @@ public: ...@@ -87,5 +94,6 @@ public:
/* QML passes its arguments via QVariant. */ /* QML passes its arguments via QVariant. */
Q_DECLARE_METATYPE(InteractionFilesystem) Q_DECLARE_METATYPE(InteractionFilesystem)
Q_DECLARE_METATYPE(InteractionFilesystem::Location)
#endif /* _INTERACTION_FILESYSTEM_H_ */ #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