Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. ComboBox {
  2. id: storageSwitch
  3. //objectName: storageSwitch
  4.  
  5. //property var places: fsOperations.getPlaces()
  6. property var places: fsOperations.storageModel
  7.  
  8. function findIndex(id) {
  9. for (var i = 0; i < places.length; i++) {
  10. if (places[i]["id"] === id) {
  11. return i;
  12. }
  13. }
  14. console.log("Storage: couldn't find index for", id);
  15. return -1;
  16. }
  17.  
  18. label: qsTr("Storage:")
  19. currentIndex: findIndex(settings.global.storageID)
  20.  
  21. menu: ContextMenu {
  22. Repeater {
  23. //model: storageSwitch.places
  24. model: fsOperations.storageModel
  25.  
  26. delegate: MenuItem {
  27. text: modelData["name"]
  28.  
  29. onClicked: {
  30. settings.global.storageID = modelData["id"];
  31. settings.global.storagePath = modelData["path"];
  32. }
  33. }
  34. }
  35. }
  36.  
  37. Connections {
  38. target: fsOperations
  39. onStorageModelChanged: console.log("Storage Connections: model changed !");
  40. }
  41. [...]
  42. FSOperations {
  43. id: fsOperations
  44. onStorageModelChanged: console.log("fsOperations: model changed !");
  45. }
  46. =============================================================================================================
  47. class FSOperations : public QObject
  48. {
  49. Q_OBJECT
  50. Q_PROPERTY(QVariantList storageModel READ storageModel NOTIFY storageModelChanged)
  51. public:
  52. explicit FSOperations(QObject *parent = nullptr);
  53. Q_INVOKABLE bool deleteFile(const QString &path);
  54. Q_INVOKABLE QString writableLocation(const QString &type, const QString &baseDir);
  55. Q_INVOKABLE bool createFolder(const QString &path);
  56. //Q_INVOKABLE QVariantList getPlaces();
  57. Q_INVOKABLE QVariantList storageModel();
  58. signals:
  59. void storageModelChanged();
  60. };
  61. ===================================================================================================
  62. QString FSOperations::writableLocation(const QString &type, const QString &baseDir)
  63. {
  64. QString dir;
  65. if (type == "image") {
  66. dir = baseDir + "/Pictures/AdvancedCam";
  67. } else if (type == "video") {
  68. dir = baseDir + "/Videos/AdvancedCam";
  69. }
  70. else
  71. {
  72. qWarning() << "Invalid writableLocation of type" << type << "requested!";
  73. return QString();
  74. }
  75. if (!createFolder(dir))
  76. {
  77. qWarning() << "Unable to create writableLocation" << dir << ", failing-over to home dir!";
  78. //QQmlEngine engine;
  79. //QObject *storageSwitch = engine.findChild<QObject *>("storageSwitch");
  80. //QQmlProperty::write(storageSwitch, "places", storageModel());
  81. storageModel();
  82. qDebug() << "Storage: about to emit...";
  83. emit storageModelChanged();
  84. qDebug() << "Storage: should have emitted!";
  85. return writableLocation(type, QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
  86. }
  87. return dir;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement