Support for validating locations entered by the user

Bug #1195488 reported by Michael Spencer
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu File Manager App
Fix Released
Low
Carlos Jose Mazieri

Bug Description

I'm working on a UI to allow the user to enter a location to go to. In order to do this, the folder model needs support for checking locations. Ideally, this should be a function that takes a folder name and returns true if it is exists and is a folder or false otherwise.

Changed in ubuntu-filemanager-app:
status: New → Confirmed
importance: Undecided → Low
assignee: nobody → Carlos Jose Mazieri (carlos-mazieri)
Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

maybe: existsDir(folderName) and also canReadDir(folderName) which will return true when a folder is readble.

Revision history for this message
Michael Spencer (ibelieve) wrote :

Also having existsFile(fileName) and maybe canOpenFile(fileName) might be nice so that if the user types in a path to a file, the app can open it as if it had been clicked on.

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

I would suggest canReadFile(fileName) instead of canOpenFile(fileName), canOpenFile() may indicate that there is a suitable application to open it.

There is already openIndex(int item) and openPath(itemName), both return true when can open a file or directory.

In fact you can use openPath() for directories and for files, I think that it matches your needs and no other function is necessary.

If you pass a directory and it exists, it should become the current one, it you pass a file it will be opened.

Try using openPath() it should be enough.

Revision history for this message
Michael Spencer (ibelieve) wrote :

I knew those exist, but I wanted to be able to validate a file/folder name before opening for providing input validation for a text field, so a user can't enter an invalid filename.

Now that I've thought about it, understand how validators work, and have looked at how other file managers handle invalid paths, I'm thinking trying to open the path and displaying an error message if the folder/file doesn't exist would be better, so this can just be closed now.

Revision history for this message
Sam Bull (dreamsorcerer) wrote :

Two things I'd like to point out. You shouldn't expect the user to type out the full name from memory, some form of auto-completion should be used. For example, press Ctrl+L in the file manager and start typing a path name, you'll see it auto-completing.

Now, to auto-complete, you're surely going to get a list of items in a folder, in which case you can validate against that list.

Second, I don't know about QML, but the recommended way to handle invalid files in Python is using a try/except statement. It's more efficient and cleaner, otherwise you may end up with a bunch of if statements checking if the file exists, you have permission to access it, it's in the right format etc.

Revision history for this message
Michael Spencer (ibelieve) wrote :

Yes, I understand that know (See my last comment).

Thanks for the info about Ctrl+L, I never knew you could do that, and manual entry is one of my favorite features in a file manager.

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Thanks for the suggestions, as a initial version I think you can start using openPath(), if a folder/file does not exist or is not readable it returns false, it should work for absolute paths and relative from the current Dir.

It will be useful when the user knows the path, auto-completion can be added later.

I will add those functions as static anyway they can be useful to other apps as well.

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

created functions that receive absolute or relative pathnames:
                  Q_INVOKABLE bool existsDir(const QString& folderName) const;
                  Q_INVOKABLE bool canReadDir(const QString& folderName) const;
                  Q_INVOKABLE bool existsFile(const QString& fileName) const;
                  Q_INVOKABLE bool canReadFile(const QString& fileName) const;

openPath() has been fixed.

Changed in ubuntu-filemanager-app:
status: Confirmed → Fix Committed
Sam Bull (dreamsorcerer)
Changed in ubuntu-filemanager-app:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.