Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ComboBox {
- id: storageSwitch
- //objectName: storageSwitch
- //property var places: fsOperations.getPlaces()
- property var places: fsOperations.storageModel
- function findIndex(id) {
- for (var i = 0; i < places.length; i++) {
- if (places[i]["id"] === id) {
- return i;
- }
- }
- console.log("Storage: couldn't find index for", id);
- return -1;
- }
- label: qsTr("Storage:")
- currentIndex: findIndex(settings.global.storageID)
- menu: ContextMenu {
- Repeater {
- //model: storageSwitch.places
- model: fsOperations.storageModel
- delegate: MenuItem {
- text: modelData["name"]
- onClicked: {
- settings.global.storageID = modelData["id"];
- settings.global.storagePath = modelData["path"];
- }
- }
- }
- }
- Connections {
- target: fsOperations
- onStorageModelChanged: console.log("Storage Connections: model changed !");
- }
- [...]
- FSOperations {
- id: fsOperations
- onStorageModelChanged: console.log("fsOperations: model changed !");
- }
- =============================================================================================================
- class FSOperations : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(QVariantList storageModel READ storageModel NOTIFY storageModelChanged)
- public:
- explicit FSOperations(QObject *parent = nullptr);
- Q_INVOKABLE bool deleteFile(const QString &path);
- Q_INVOKABLE QString writableLocation(const QString &type, const QString &baseDir);
- Q_INVOKABLE bool createFolder(const QString &path);
- //Q_INVOKABLE QVariantList getPlaces();
- Q_INVOKABLE QVariantList storageModel();
- signals:
- void storageModelChanged();
- };
- ===================================================================================================
- QString FSOperations::writableLocation(const QString &type, const QString &baseDir)
- {
- QString dir;
- if (type == "image") {
- dir = baseDir + "/Pictures/AdvancedCam";
- } else if (type == "video") {
- dir = baseDir + "/Videos/AdvancedCam";
- }
- else
- {
- qWarning() << "Invalid writableLocation of type" << type << "requested!";
- return QString();
- }
- if (!createFolder(dir))
- {
- qWarning() << "Unable to create writableLocation" << dir << ", failing-over to home dir!";
- //QQmlEngine engine;
- //QObject *storageSwitch = engine.findChild<QObject *>("storageSwitch");
- //QQmlProperty::write(storageSwitch, "places", storageModel());
- storageModel();
- qDebug() << "Storage: about to emit...";
- emit storageModelChanged();
- qDebug() << "Storage: should have emitted!";
- return writableLocation(type, QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
- }
- return dir;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement