interaction_filesystem.h 2.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*
 * Copyright (C) 2014-2017 CZ.NIC
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

#ifndef _INTERACTION_FILESYSTEM_H_
#define _INTERACTION_FILESYSTEM_H_

#include <QObject>
#include <QString>

/*!
 * @provides interface between QML and file-system functionality.
 */
class InteractionFilesystem : public QObject {
	Q_OBJECT

public:
37 38 39 40 41 42 43
	/* Corresponds to some QStandardPaths::StandardLocation. */
	enum Location {
		DESKTOP_LOCATION,
		DOCUMENTS_LOCATION
	};
	Q_ENUM(Location)

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
	/* Don't forget to declare various properties to the QML system. */
	static
	void declareQML(void);

	/*!
	 * @brief Constructor.
	 *
	 * @param[in] parent Parent object.
	 */
	explicit InteractionFilesystem(QObject *parent = Q_NULLPTR);

	/*!
	 * @brief Copy constructor.
	 *
	 * @note Needed for QVariant conversion.
	 *
	 * @param[in] inter Object to be copied.
	 */
	InteractionFilesystem(const InteractionFilesystem &inter);

	/*!
	 * @brief Returns home location.
	 *
	 * @return Home location path.
	 */
	static Q_INVOKABLE
70
	QString locate(enum Location location);
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

	/*!
	 * @brief Check whether path is a readable directory.
	 *
	 * @param[in] path Absolute or relative path.
	 * @return Non-empty absolute path to directory if supplied path is a
	 *     directory. Returns empty string if directory does not exist or
	 *     is not accessible.
	 */
	static Q_INVOKABLE
	QString absoluteDirPath(const QString &path);

	/*!
	 * @brief Check whether path is a readable file.
	 *
	 * @param[in] path Absolute or relative path.
	 * @return Non-empty absolute path to directory without file name if
	 *     the supplied path is a file. Returns empty string if directory
	 *     does not exist or is not accessible.
	 */
	static Q_INVOKABLE
	QString absolutePath(const QString &path);
};

/* QML passes its arguments via QVariant. */
Q_DECLARE_METATYPE(InteractionFilesystem)
97
Q_DECLARE_METATYPE(InteractionFilesystem::Location)
98 99

#endif /* _INTERACTION_FILESYSTEM_H_ */