~thrrgilag/RenamedTodo

ed466b428b1ce2d3e845bbb9af2eba53dcb4cb40 — Morgan McMillian 4 years ago 778ab32
add ability to load todo.txt from any shared location, resolves #4
3 files changed, 69 insertions(+), 36 deletions(-)

M assets/SettingsPage.qml
M src/TaskModel.cpp
M src/TaskModel.h
M assets/SettingsPage.qml => assets/SettingsPage.qml +60 -36
@@ 181,46 181,60 @@ Page {
                    }
                }
            }
//            Divider {}
//            Container {
//                layout: DockLayout {}
//                horizontalAlignment: HorizontalAlignment.Fill
//                Container {
//                    leftPadding: 30.0
//                    rightPadding: 30.0
//                    DropDown {
//                        title: "Storage:"
//                        preferredWidth: 1440.0
//                        onSelectedIndexChanged: {
//                            if (sync != selectedValue) {
//                                modifySetting("sync", selectedValue)
//                            }
//                        }
//                        Option {
//                            text: "Local only"
//                            value: "local"
//                            selected: sync == "local"
//                        }
//                    }
//                }
//            }
//            Container {
//                layout: DockLayout {}
//                horizontalAlignment: HorizontalAlignment.Fill
//                Container {
//                    leftPadding: 30.0
//                    rightPadding: 30.0
//                    topPadding: 10.0
//                    TextField {
//                        id: dboxPath
//                        hintText: "Dropbox location"
//                        text: dboxpath
//                        visible: sync == "dropbox"
//                        onTextChanged: {
//                            if (dboxPath.text.length > 0) {
//                                modifySetting("dbox_path", dboxPath.text)
//                            }
//                        }
//                    }
//                }
//            }
            Divider {}
            Container {
                layout: DockLayout {}
                horizontalAlignment: HorizontalAlignment.Fill
                Container {
                    leftPadding: 30.0
                    rightPadding: 30.0
                    DropDown {
                        title: "Storage:"
                        preferredWidth: 1440.0
                        onSelectedIndexChanged: {
                            if (sync != selectedValue) {
                                modifySetting("sync", selectedValue)
                            }
                        }
                        Option {
                            text: "Local only"
                            value: "local"
                            selected: sync == "local"
                        }
                    }
                }
            }
            Container {
                layout: DockLayout {}
                horizontalAlignment: HorizontalAlignment.Fill
                Container {
                    leftPadding: 30.0
                    rightPadding: 30.0
                    topPadding: 10.0
                    TextField {
                        id: dboxPath
                        hintText: "Dropbox location"
                        text: dboxpath
                        visible: sync == "dropbox"
                        onTextChanged: {
                            if (dboxPath.text.length > 0) {
                                modifySetting("dbox_path", dboxPath.text)
                            }
                        }
                leftPadding: 30.0
                rightPadding: 30.0
                Button {
                    preferredWidth: 1440.0
                    text: "Open shared todo.txt"
                    onClicked: {
                        sharedPicker.open()
                    }
                }
            }


@@ 267,6 281,16 @@ Page {
                console.log("FileSelected signal received : " + selectedFiles);
                taskModel.exportFiles(selectedFiles)
            }
        },
        FilePicker {
            id: sharedPicker
            title: "Select shared todo.txt"
            type: FileType.Document
            viewMode: FilePickerViewMode.ListView
            onFileSelected: {
                console.log("FileSelected signal: " + selectedFiles);
                taskModel.openSharedFiles(selectedFiles);
            }
        }
    ]
}

M src/TaskModel.cpp => src/TaskModel.cpp +8 -0
@@ 268,6 268,14 @@ void TaskModel::exportFiles(const QStringList &files) {
	exportto.saveArchive(done);
}

void TaskModel::openSharedFiles(QString filepath) {
    QRegExp pathrgx("^/accounts/1000/");
    QRegExp filergx("/(todo|done).txt$");
    filepath.replace(pathrgx, "");
    filepath.replace(filergx, "");
    modifySetting("path", filepath);
}

void TaskModel::promptPurgeSandbox() {
	dialog = new SystemDialog("PURGE", "CANCEL");
	dialog->setTitle("Purge local sandbox");

M src/TaskModel.h => src/TaskModel.h +1 -0
@@ 59,6 59,7 @@ public:
	Q_INVOKABLE QString formatDate(const QDateTime &date) const;
	Q_INVOKABLE void promptPurgeSandbox();
	Q_INVOKABLE void exportFiles(const QStringList &files);
	Q_INVOKABLE void openSharedFiles(QString filepath);
	Q_SLOT void setView();
	Q_SLOT void setValue(int idx, const QString &key, const QVariant &value);
	Q_SLOT void updateTask(int idx, const QString &task);