pax_global_header00006660000000000000000000000064140260675370014524gustar00rootroot0000000000000052 comment=ed75ef1134af14f37fbcd3b0557d15adb49e1797 gio-qt-0.0.11/000077500000000000000000000000001402606753700130035ustar00rootroot00000000000000gio-qt-0.0.11/.gitignore000066400000000000000000000000501402606753700147660ustar00rootroot00000000000000# User *.user # Build directory build/ gio-qt-0.0.11/CMakeLists.txt000066400000000000000000000040271402606753700155460ustar00rootroot00000000000000project(gio-qt) cmake_minimum_required(VERSION 3.12.4) option(BUILD_TESTS "Build tests" OFF) option(BUILD_UTILS "Build utilities" ON) option(BUILD_DOCS "Build documentation" ON) # Version if (NOT PROJECT_VERSION) set(PROJECT_VERSION "0.0.1") endif() if (NOT PROJECT_VERSION_MAJOR) set(PROJECT_VERSION_MAJOR 0) endif() # Find includes in corresponding build directories set(CMAKE_INCLUDE_CURRENT_DIR ON) # Instruct CMake to run moc automatically when needed set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_FLAGS "-g -Wall") set(QT_MINIMUM_VERSION "5.6.3") # Install settings if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX /usr) endif () include(GNUInstallDirs) # Find the QtWidgets library find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Core) find_package(PkgConfig REQUIRED) find_package(Doxygen) pkg_check_modules(GIOMM giomm-2.4) # look into FindPkgConfig.cmake add_subdirectory (gio-qt) if (BUILD_TESTS) find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Test) add_subdirectory(test) endif () if (BUILD_UTILS) add_subdirectory(qgio-tools) endif () if (BUILD_DOCS) if (NOT DOXYGEN_FOUND) message(FATAL_ERROR "Doxygen is required to build the documentation.") endif () set (DOXYGEN_GENERATE_HTML YES) set (DOXYGEN_GENERATE_QHP YES) set (DOXYGEN_EXTRACT_STATIC YES) set (DOXYGEN_OUTPUT_DIRECTORY "./docs/") set (DOXYGEN_EXCLUDE_SYMBOLS "*Private;*Test") set (DOXYGEN_QHG_LOCATION "qhelpgenerator") set (DOXYGEN_QHP_NAMESPACE "org.deepin.gio-qt") set (DOXYGEN_QCH_FILE "../gio-qt.qch") set (DOXYGEN_QHP_VIRTUAL_FOLDER "gio-qt") doxygen_add_docs(doxygen ${CMAKE_CURRENT_SOURCE_DIR}/gio-qt ALL WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/gio-qt COMMENT "Generate documentation via Doxygen" ) install (FILES ${CMAKE_CURRENT_BINARY_DIR}/docs/gio-qt.qch DESTINATION share/qt5/doc) else () message (STATUS "") message (STATUS "To build docs, please use -DBUILD_DOCS=Yes") message (STATUS "") endif() gio-qt-0.0.11/LICENSE000066400000000000000000000167441402606753700140240ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. gio-qt-0.0.11/README.md000066400000000000000000000050711402606753700142650ustar00rootroot00000000000000# gio-qt: Qt wrapper library of Gio ## Description This is a Qt wrapper library for Gio (or say it's a glib/glibmm wrapper mainly focused on [GIO](https://gitlab.gnome.org/GNOME/glibmm/tree/master/gio) module). This library is designed to be exception-free and avoid Qt application developer do direct access to glib/glibmm (so they can use Gio in a more Qt way). ## Build # ### Build depts: - cmake `>= 3.12.4` - pkg-config (to find and use giomm module) - Qt5Core `>= 5.6.3` - Qt5Test (if you would like to build tests) - giomm-2.4 - doxygen (to build documentations) If you are using an older system which are using a lower cmake version and attempt to build this library, please turn off the `BUILD_DOCS` option. ### Build manually ``` shell $ cd /path/to/your/source/code $ mkdir build $ cd build $ cmake ../ $ make $ sudo make install ``` It will installed to `/usr/local/lib` by default. You may also need to do a `sudo ldconfig /usr/local/lib` after install. ## Questions and Answers ### Should I use? Before this library release it's first stable tag (1.0.0) the answer is mostly **no** since the API may change at any time, and since this library is mainly for Deepin product for now so only the APIs we need will be implemented at first. If you are writing a non-Qt application, please consider using [glibmm](https://gitlab.gnome.org/GNOME/glibmm). If you are writing Qt application and really wanna use this library, consider wait its API stable release or create a fork and start hacking! ### What about generate Qt binding using GObject Introspection As you can see `gio-qt` currently is a hand-crafted Qt/C++ bindings for GIO. Using [GObject Introspection (gir)](https://wiki.gnome.org/Projects/GObjectIntrospection) to generate code could be a really good idea but we currently doesn't have very enough time to look into it. It's definitely worth to look into `gir` to generate Qt binding and actually there was some cool guys working on this idea (see [GObject Consume](https://wiki.gnome.org/action/show/Projects/GObjectIntrospection/GObjectConsume)) and worth to check it out. Due to the project time limit so we are not going to use it currently, but we encourage you contirbute on that project if you are familiar to `gir`. ## Documentation For Deepin there will be a `libgio-qt-doc` package, if you are building it manually with `BUILD_DOCS` option enabled, there will be a docs folder inside your build folder, and there will be a doxygen generated html folder and also a `gio-qt.qch` for QtCreator. ## License GPLv3 gio-qt-0.0.11/debian/000077500000000000000000000000001402606753700142255ustar00rootroot00000000000000gio-qt-0.0.11/debian/changelog000066400000000000000000000002061402606753700160750ustar00rootroot00000000000000gio-qt (0.0.1) unstable; urgency=medium * Initial release -- Gary Wang Tue, 23 Jul 2019 19:49:31 +0800 gio-qt-0.0.11/debian/compat000066400000000000000000000000021402606753700154230ustar00rootroot000000000000009 gio-qt-0.0.11/debian/control000066400000000000000000000015141402606753700156310ustar00rootroot00000000000000Source: gio-qt Section: libs Priority: optional Maintainer: Gary Wang Build-Depends: debhelper (>= 9), cmake, pkg-config, qtbase5-dev, qt5-qmake, libglibmm-2.4-dev, doxygen, qttools5-dev-tools Standards-Version: 3.9.8 Homepage: https://github.com/linuxdeepin/gio-qt Package: libgio-qt Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, libglibmm-2.4-1v5 Description: Gio wrapper for Qt. A convenient way to bind gio with Qt5. Package: libgio-qt-dev Architecture: any Section: libdevel Depends: libgio-qt, ${misc:Depends}, libglibmm-2.4-dev Description: Development package for libgio-qt. A convenient way to bind gio with Qt5. Package: libgio-qt-doc Architecture: any Section: doc Depends: ${misc:Depends} Description: Gio wrapper for Qt (documentation) A convenient way to bind gio with Qt5. gio-qt-0.0.11/debian/copyright000066400000000000000000000017761402606753700161730ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: gio-qt Source: https://github.com/linuxdeepin/gio-qt Files: * Copyright: 2019-2019 Deepin Technology Co., Ltd. License: LGPL-3+ License: LGPL-3+ This package is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. . This package 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 Lesser General Public License for more details. . You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . On Debian systems, the complete text of the GNU General Public License version 3 can be found in "/usr/share/common-licenses/LGPL-3". gio-qt-0.0.11/debian/libgio-qt-dev.install000066400000000000000000000000441402606753700202560ustar00rootroot00000000000000/usr/include/* /usr/lib/*/pkgconfig gio-qt-0.0.11/debian/libgio-qt-doc.install000066400000000000000000000000301402606753700202400ustar00rootroot00000000000000/usr/share/qt5/doc/*.qchgio-qt-0.0.11/debian/libgio-qt.install000066400000000000000000000000211402606753700174750ustar00rootroot00000000000000/usr/lib/*/*.so* gio-qt-0.0.11/debian/rules000077500000000000000000000001441402606753700153040ustar00rootroot00000000000000#!/usr/bin/make -f include /usr/share/dpkg/default.mk export QT_SELECT = qt5 %: dh $@ --parallel gio-qt-0.0.11/debian/source/000077500000000000000000000000001402606753700155255ustar00rootroot00000000000000gio-qt-0.0.11/debian/source/format000066400000000000000000000000151402606753700167340ustar00rootroot000000000000003.0 (native) gio-qt-0.0.11/gio-qt/000077500000000000000000000000001402606753700142035ustar00rootroot00000000000000gio-qt-0.0.11/gio-qt/CMakeLists.txt000066400000000000000000000031071402606753700167440ustar00rootroot00000000000000# Populate a CMake variable with the sources # TODO: portable headers? configure_file ("gio-qt.pc.in" "gio-qt.pc" @ONLY) set (QGIO_PUBLIC_HEADER_FILES include/dglibutils.h include/dgiovolumemanager.h include/dgiomountoperation.h include/dgiomount.h include/dgiovolume.h include/dgiofile.h include/dgiofileinfo.h include/dgiofileiterator.h include/dgiodrive.h include/dgiosettings.h ) set (QGIO_PRIVATE_HEADER_FILES private/dgiohelper.h ) set (QGIO_PRIVATE_CPP_FILES source/dglibutils.cpp source/dgiovolumemanager.cpp source/dgiomountoperation.cpp source/dgiomount.cpp source/dgiovolume.cpp source/dgiofile.cpp source/dgiofileinfo.cpp source/dgiofileiterator.cpp source/dgiodrive.cpp source/dgiosettings.cpp private/dgiohelper.cpp ) # Library add_library (gio-qt SHARED ${QGIO_PUBLIC_HEADER_FILES} ${QGIO_PRIVATE_HEADER_FILES} ${QGIO_PRIVATE_CPP_FILES} ) set_target_properties( gio-qt PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR} ) target_include_directories(gio-qt PRIVATE ${GIOMM_INCLUDE_DIRS} ${CMAKE_CURRENT_LIST_DIR}/private PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include ) target_link_libraries (gio-qt Qt5::Core ${GIOMM_LIBRARIES}) target_compile_definitions(gio-qt PRIVATE QT_NO_KEYWORDS ) ## dev files install (FILES ${QGIO_PUBLIC_HEADER_FILES} DESTINATION include/gio-qt ) install_targets ("/${CMAKE_INSTALL_LIBDIR}" gio-qt) install (FILES "${CMAKE_CURRENT_BINARY_DIR}/gio-qt.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) gio-qt-0.0.11/gio-qt/gio-qt.pc.in000066400000000000000000000005001402606753700163270ustar00rootroot00000000000000prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=@CMAKE_INSTALL_PREFIX@ libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ includedir=${prefix}/include Name: gio-qt Description: Qt wrapper library for GIO. Version: @PROJECT_VERSION@ Requires: glibmm-2.4, Qt5Core Libs: -L${libdir} -lgio-qt Cflags: -I${includedir} -I${includedir}/gio-qtgio-qt-0.0.11/gio-qt/include/000077500000000000000000000000001402606753700156265ustar00rootroot00000000000000gio-qt-0.0.11/gio-qt/include/dgiodrive.h000066400000000000000000000030551402606753700177560ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Mike Chen * * Maintainer: Mike Chen * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGIODRIVE_H #define DGIODRIVE_H #include #include #define DGIODRIVE_IDENTIFIER_KIND_UNIX_DEVICE "unix-device" namespace Gio { class Drive; } class DGioDrivePrivate; class DGioDrive : public QObject, public QSharedData { Q_OBJECT public: explicit DGioDrive(Gio::Drive *gmmDrivePtr, QObject *parent = nullptr); ~DGioDrive(); QString name() const; QString identifier(const QString & kind = DGIODRIVE_IDENTIFIER_KIND_UNIX_DEVICE) const; bool hasVolumes() const; bool canStart() const; bool canStop() const; bool canEject() const; bool isMediaRemovable() const; bool isRemovable() const; private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(DGioDrive) }; #endif // DGIODRIVE_H gio-qt-0.0.11/gio-qt/include/dgiofile.h000066400000000000000000000051311402606753700175610ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGIOFILE_H #define DGIOFILE_H #include #include namespace Gio { class File; } enum DGioFileQueryInfoFlag { FILE_QUERY_INFO_NONE = 0x0, FILE_QUERY_INFO_NOFOLLOW_SYMLINKS = (1 << 0) }; Q_DECLARE_FLAGS(DGioFileQueryInfoFlags, DGioFileQueryInfoFlag) class DGioFileInfo; class DGioMount; class DGioFileIterator; class DGioMountOperation; class DGioFilePrivate; class DGioFile : public QObject, public QSharedData { Q_OBJECT public: explicit DGioFile(Gio::File *gmmFilePtr, QObject *parent = nullptr); ~DGioFile(); static DGioFile * createFromPath(QString path, QObject *parent = nullptr); static DGioFile * createFromUri(QString uri, QObject *parent = nullptr); static DGioFile * createFromCmdArg(QString uri, QObject *parent = nullptr); QString basename() const; QString path() const; QString uri() const; QExplicitlySharedDataPointer createFileInfo(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE, unsigned long timeout_msec = ULONG_MAX); QExplicitlySharedDataPointer createFileSystemInfo(QString attr = "*"); QExplicitlySharedDataPointer createFileIterator(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE); void createFileIteratorAsync(QString attr = "*", DGioFileQueryInfoFlags queryInfoFlags = FILE_QUERY_INFO_NONE); void mountEnclosingVolume(DGioMountOperation *dgioMountOperation); QExplicitlySharedDataPointer findEnclosingMount(); Q_SIGNALS: void createFileIteratorReady(QExplicitlySharedDataPointer iter); void mountEnclosingVolumeReady(bool result, QString msg); private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(DGioFile) }; #endif // DGIOFILE_H gio-qt-0.0.11/gio-qt/include/dgiofileinfo.h000066400000000000000000000035511402606753700204410ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGIOFILEINFO_H #define DGIOFILEINFO_H #include #include enum DGioFileType { FILE_TYPE_NOT_KNOWN, FILE_TYPE_REGULAR, FILE_TYPE_DIRECTORY, FILE_TYPE_SYMBOLIC_LINK, FILE_TYPE_SPECIAL, FILE_TYPE_SHORTCUT, FILE_TYPE_MOUNTABLE }; Q_ENUMS(DGioFileType); namespace Gio { class FileInfo; } class DGioFileInfoPrivate; class DGioFileInfo : public QObject, public QSharedData { Q_OBJECT public: explicit DGioFileInfo(Gio::FileInfo *gmmFileInfoInfoPtr, QObject *parent = nullptr); ~DGioFileInfo(); // file info QString displayName() const; DGioFileType fileType() const; quint64 fileSize() const; QString contentType() const; QString iconString() const; QStringList themedIconNames() const; // filesystem info. bool fsReadOnly() const; quint64 fsTotalBytes() const; quint64 fsUsedBytes() const; quint64 fsFreeBytes() const; QString fsType() const; private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(DGioFileInfo) }; #endif // DGIOFILEINFO_H gio-qt-0.0.11/gio-qt/include/dgiofileiterator.h000066400000000000000000000054231402606753700213370ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGIOFILEITERATOR_H #define DGIOFILEITERATOR_H #include #include namespace Gio { class FileEnumerator; } enum DGioIOPriority { /*! Use this for high priority event sources. It is not used within * GLib or GTK+.

*/ PRIORITY_HIGH = -100, /*! Use this for default priority event sources. In glibmm this * priority is used by default when installing timeout handlers with * SignalTimeout::connect(). In GDK this priority is used for events * from the X server.

*/ PRIORITY_DEFAULT = 0, /*! Use this for high priority idle functions. GTK+ uses * PRIORITY_HIGH_IDLE + 10 for resizing operations, and * PRIORITY_HIGH_IDLE + 20 for redrawing operations. * (This is done to ensure that any pending resizes are processed before * any pending redraws, so that widgets are not redrawn twice unnecessarily.) *

*/ PRIORITY_HIGH_IDLE = 100, /*! Use this for default priority idle functions. In glibmm this priority is * used by default when installing idle handlers with SignalIdle::connect(). *

*/ PRIORITY_DEFAULT_IDLE = 200, /*! Use this for very low priority background tasks. It is not used within * GLib or GTK+. */ PRIORITY_LOW = 300 }; Q_ENUMS(DGioIOPriority); class DGioFileInfo; class DGioFileIteratorPrivate; class DGioFileIterator : public QObject, public QSharedData { Q_OBJECT public: explicit DGioFileIterator(Gio::FileEnumerator *gmmFileEnumeratorPtr, QObject *parent = nullptr); ~DGioFileIterator(); QExplicitlySharedDataPointer nextFile(); void nextFilesAsync(int numberOfFiles = 1, DGioIOPriority io_priority = PRIORITY_DEFAULT); Q_SIGNALS: void nextFilesReady(QList > fileInfoList); void nextFilesCancelled(); private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(DGioFileIterator) }; #endif // DGIOFILEITERATOR_H gio-qt-0.0.11/gio-qt/include/dgiomount.h000066400000000000000000000035661402606753700200160ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGIOMOUNT_H #define DGIOMOUNT_H #include #include namespace Gio { class Mount; } class DGioFile; class DGioVolume; class DGioMountPrivate; class DGioMount : public QObject, public QSharedData { Q_OBJECT public: explicit DGioMount(Gio::Mount *gmmMountPtr, QObject *parent = nullptr); ~DGioMount(); static DGioMount * createFromPath(QString path, QObject *parent = nullptr); QString name() const; QString uuid() const; QString mountClass() const; bool isShadowed() const; bool canUnmount() const; bool canEject() const; QString sortKey() const; QStringList themedIconNames() const; QStringList themedSymbolicIconNames() const; void unmount(bool forceUnmount = false); void eject(bool forceEject = false); QExplicitlySharedDataPointer getRootFile(); QExplicitlySharedDataPointer getDefaultLocationFile(); QExplicitlySharedDataPointer getVolume(); private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(DGioMount) }; #endif // DGIOMOUNT_H gio-qt-0.0.11/gio-qt/include/dgiomountoperation.h000066400000000000000000000057331402606753700217350ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGIOMOUNTOPERATION_H #define DGIOMOUNTOPERATION_H #include namespace Glib{ template class RefPtr; } namespace Gio{ class MountOperation; } enum DGioAskPasswordFlag { ASK_PASSWORD_NEED_PASSWORD = (1 << 0), ASK_PASSWORD_NEED_USERNAME = (1 << 1), ASK_PASSWORD_NEED_DOMAIN = (1 << 2), ASK_PASSWORD_SAVING_SUPPORTED = (1 << 3), ASK_PASSWORD_ANONYMOUS_SUPPORTED = (1 << 4) }; Q_DECLARE_FLAGS(DGioAskPasswordFlags, DGioAskPasswordFlag) //! Indicated the mount operation result /*! * Wrapper of GMountOperationResult. */ enum DGioMountOperationResult { MOUNT_OPERATION_HANDLED, /*!< The request was fulfilled and the user specified data is now available */ MOUNT_OPERATION_ABORTED, /*!< The user requested the mount operation to be aborted */ MOUNT_OPERATION_UNHANDLED /*!< The request was unhandled (i.e. not implemented) */ }; Q_ENUMS(DGioMountOperationResult); enum DGioPasswordSave { PASSWORD_SAVE_NEVER, PASSWORD_SAVE_FOR_SESSION, PASSWORD_SAVE_PERMANENTLY }; Q_ENUMS(DGioPasswordSave); class DGioMountOperationPrivate; class DGioMountOperation : public QObject { Q_OBJECT public: explicit DGioMountOperation(QObject *parent); ~DGioMountOperation(); QString username() const; void setUsername(QString name); QString password() const; void setPassword(QString password); DGioPasswordSave passwordSave(); void setPasswordSave(DGioPasswordSave save); QString domain() const; void setDomain(QString domain); bool anonymous()const; void setAnonymous(bool anonymous = true); int choice()const; void setChoice(int choice); void reply(DGioMountOperationResult result); // do not release the ptr returned Glib::RefPtr getGIOMountOperationObj(); Q_SIGNALS: void askPassword(QString message, QString defaultUser, QString defaultDomain, DGioAskPasswordFlags flags); void askQuestion(QString message, QStringList choices); void showUnmountProgress(QString message, qint64 timeLeftMs, qint64 bytesLeft); private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(DGioMountOperation) }; #endif // DGIOMOUNTOPERATION_H gio-qt-0.0.11/gio-qt/include/dgiosettings.h000066400000000000000000000032451402606753700205060ustar00rootroot00000000000000/* * Copyright (C) 2011 ~ 2019 Deepin Technology Co., Ltd. * * Author: justforlxz * * Maintainer: justforlxz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGIOSETTINGS_H #define DGIOSETTINGS_H #include #include class DGioSettingsPrivate; class DGioSettings : public QObject { Q_OBJECT public: explicit DGioSettings(const QString& schemaId, QObject* parent = nullptr); DGioSettings(const QString& schemaId, const QString& path, QObject* parent = nullptr); ~DGioSettings(); void sync(); bool setValue(const QString& key, const QVariant& value, bool sync = false); QVariant value(const QString& key) const; Q_DECL_DEPRECATED QStringList keys() const; void reset(const QString& key); static bool isSchemaInstalled(const QString& schemaId); Q_SIGNALS: void valueChanged(const QString& key, const QVariant& value); private: QScopedPointer d_private; Q_DECLARE_PRIVATE_D(d_private, DGioSettings) }; #endif // DGIOSETTINGS_H gio-qt-0.0.11/gio-qt/include/dgiovolume.h000066400000000000000000000034571402606753700201620ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGIOVOLUME_H #define DGIOVOLUME_H #include #include namespace Gio { class Volume; } enum DGioVolumeIdentifierType { VOLUME_IDENTIFIER_TYPE_LABEL, VOLUME_IDENTIFIER_TYPE_NFS_MOUNT, VOLUME_IDENTIFIER_TYPE_UNIX_DEVICE, VOLUME_IDENTIFIER_TYPE_UUID, VOLUME_IDENTIFIER_TYPE_CLASS }; Q_ENUMS(DGioVolumeIdentifierType); class DGioMount; class DGioVolumePrivate; class DGioVolume : public QObject, public QSharedData { Q_OBJECT public: explicit DGioVolume(Gio::Volume *gmmVolumePtr, QObject *parent = nullptr); ~DGioVolume(); QString name() const; QString volumeClass() const; QString volumeMonitorName() const; bool canMount() const; bool canEject() const; bool shouldAutoMount() const; void mount() const; QExplicitlySharedDataPointer getMount(); QString identifier(DGioVolumeIdentifierType id) const; private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(DGioVolume) }; #endif // DGIOVOLUME_H gio-qt-0.0.11/gio-qt/include/dgiovolumemanager.h000066400000000000000000000043251402606753700215100ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGIOVOLUMEMANAGER_H #define DGIOVOLUMEMANAGER_H #include #include class DGioMount; class DGioVolume; class DGioDrive; class DGioVolumeManagerPrivate; class DGioVolumeManager : public QObject { Q_OBJECT public: explicit DGioVolumeManager(QObject *parent = nullptr); ~DGioVolumeManager(); static const QList > getMounts(); static const QList > getVolumes(); static const QList > getDrives(); Q_SIGNALS: void mountAdded(QExplicitlySharedDataPointer mount); void mountRemoved(QExplicitlySharedDataPointer mount); void mountPreRemoved(QExplicitlySharedDataPointer mount); void mountChanged(QExplicitlySharedDataPointer mount); void volumeAdded(QExplicitlySharedDataPointer volume); void volumeRemoved(QExplicitlySharedDataPointer volume); void volumeChanged(QExplicitlySharedDataPointer volume); void driveConnected(QExplicitlySharedDataPointer drive); void driveDisconnected(QExplicitlySharedDataPointer drive); void driveChanged(QExplicitlySharedDataPointer drive); private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(DGioVolumeManager) }; #endif // DGIOVOLUMEMANAGER_H gio-qt-0.0.11/gio-qt/include/dglibutils.h000066400000000000000000000033051402606753700201420ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGLIBUTILS_H #define DGLIBUTILS_H #include enum DGlibUserDirectory { USER_DIRECTORY_DESKTOP, USER_DIRECTORY_DOCUMENTS, USER_DIRECTORY_DOWNLOAD, USER_DIRECTORY_MUSIC, USER_DIRECTORY_PICTURES, USER_DIRECTORY_PUBLIC_SHARE, USER_DIRECTORY_TEMPLATES, USER_DIRECTORY_VIDEOS, USER_N_DIRECTORIES }; Q_ENUMS(DGlibUserDirectory); enum DGlibFormatSizeFlag { FORMAT_SIZE_DEFAULT = 0x0, FORMAT_SIZE_LONG_FORMAT = 1 << 0, FORMAT_SIZE_IEC_UNITS = 1 << 1, FORMAT_SIZE_BITS = 1 << 2 }; Q_DECLARE_FLAGS(DGlibFormatSizeFlags, DGlibFormatSizeFlag) class DGlibUtils { public: static QString userSpecialDir(DGlibUserDirectory userDirectory); static QStringList systemDataDirs(); static QString userDataDir(); static QString tmpDir(); static QString formatSize(quint64 size, DGlibFormatSizeFlags flags = FORMAT_SIZE_DEFAULT); }; #endif // DGLIBUTILS_H gio-qt-0.0.11/gio-qt/private/000077500000000000000000000000001402606753700156555ustar00rootroot00000000000000gio-qt-0.0.11/gio-qt/private/dgiohelper.cpp000066400000000000000000000051251402606753700205060ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include "dgiohelper.h" #include #include using namespace Gio; namespace DGioPrivate { QStringList getThemedIconNames(Glib::RefPtr icon) { QStringList iconNames; Glib::RefPtr themedIcon = Glib::RefPtr::cast_dynamic(icon); // due to https://gitlab.gnome.org/GNOME/glibmm/issues/50 we cannot use the glibmm way to get icon name. // upstream already fixed the issue but we still need debian backport the patch so we can use it. // see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=932950 // if (G_IS_THEMED_ICON(themedIcon->gobj()) ) { // qDebug() << "Yes and"; // } // if (themedIcon) { // qDebug() << "Yes"; // } if (themedIcon) { char **names; char **iter; names = NULL; g_object_get(G_THEMED_ICON(themedIcon->gobj()), "names", &names, NULL); for (iter = names; *iter; iter++) { iconNames.append(QString(*iter)); } g_strfreev(names); return iconNames; } // return {QStringList::fromStdList(themedIcon->get_names())}; // char* name = 0; // g_object_get(G_OBJECT(themedIcon->gobj()), "name", &name, NULL); // return {QString(name)}; // if (themedIcon) { // auto ustring_names = themedIcon->get_names(); //// for (const Glib::ustring &str : ustring_names) { //// iconNames.append(QString::fromStdString(str.raw())); //// } // } return iconNames; } gchar *converToGChar(const QByteArray &array) { GString *str = g_string_new(nullptr); for (const QChar c : array) { g_string_append_c(str, c.toLower().toLatin1()); } return g_string_free(str, FALSE); } } gio-qt-0.0.11/gio-qt/private/dgiohelper.h000066400000000000000000000020631402606753700201510ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #ifndef DGIOHELPER_H #define DGIOHELPER_H #include #include namespace DGioPrivate { QStringList getThemedIconNames(Glib::RefPtr icon); gchar * converToGChar(const QByteArray& array); } #endif // DGIOHELPER_H gio-qt-0.0.11/gio-qt/source/000077500000000000000000000000001402606753700155035ustar00rootroot00000000000000gio-qt-0.0.11/gio-qt/source/dgiodrive.cpp000066400000000000000000000054511402606753700201700ustar00rootroot00000000000000#include "dgiodrive.h" #include #include using namespace Gio; class DGioDrivePrivate{ public: DGioDrivePrivate(DGioDrive *qq, Drive *gmmDrivePtr); Glib::RefPtr getGmmDriveInstence() const; QString name() const; private: Glib::RefPtr m_gmmDrivePtr; DGioDrive *q_ptr; Q_DECLARE_PUBLIC(DGioDrive) }; DGioDrivePrivate::DGioDrivePrivate(DGioDrive *qq, Drive *gmmDrivePtr) : m_gmmDrivePtr(gmmDrivePtr) , q_ptr(qq) { } Glib::RefPtr DGioDrivePrivate::getGmmDriveInstence() const { return m_gmmDrivePtr; } QString DGioDrivePrivate::name() const { return QString::fromStdString(m_gmmDrivePtr->get_name()); } // ------------------------------------------------------------- DGioDrive::DGioDrive(Gio::Drive *gmmDrivePtr, QObject *parent) : QObject(parent) , d_ptr(new DGioDrivePrivate(this, gmmDrivePtr)) { Q_CHECK_PTR(gmmDrivePtr); } DGioDrive::~DGioDrive() { } /*! * \brief Gets the name of drive. * * Wrapper of Gio::Drive::get_name() */ QString DGioDrive::name() const { Q_D(const DGioDrive); return d->name(); } /*! * \brief Gets the identifier of the given kind for drive. * * Wrapper of Gio::Drive::get_identifier() * * The only identifier currently available is DGIODRIVE_IDENTIFIER_KIND_UNIX_DEVICE. * * \param kind the kind of identifier to return * * \return A string containing the requested identfier, or empty string if the drive doesn't have this kind of identifier. */ QString DGioDrive::identifier(const QString &kind) const { Q_D(const DGioDrive); return QString::fromStdString(d->getGmmDriveInstence()->get_identifier(kind.toStdString())); } bool DGioDrive::hasVolumes() const { Q_D(const DGioDrive); return d->getGmmDriveInstence()->has_volumes(); } bool DGioDrive::canStart() const { Q_D(const DGioDrive); return d->getGmmDriveInstence()->can_start(); } bool DGioDrive::canStop() const { Q_D(const DGioDrive); return d->getGmmDriveInstence()->can_stop(); } bool DGioDrive::canEject() const { Q_D(const DGioDrive); return d->getGmmDriveInstence()->can_eject(); } /*! * \brief Checks if the drive supports removable media. * * Wrapper of Gio::Drive::is_media_removable() * * \return true if drive supports removable media, false otherwise. */ bool DGioDrive::isMediaRemovable() const { Q_D(const DGioDrive); return d->getGmmDriveInstence()->is_media_removable(); } /*! * \brief Checks if the drive and/or its media is considered removable by the user. * * Wrapper of Gio::Drive::is_removable() * * \return true if drive and/or its media is considered removable, false otherwise. * * \sa isMediaRemovable() */ bool DGioDrive::isRemovable() const { Q_D(const DGioDrive); return d->getGmmDriveInstence()->is_removable(); } gio-qt-0.0.11/gio-qt/source/dgiofile.cpp000066400000000000000000000267751402606753700200120ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include "dgiofile.h" #include "dgiofileinfo.h" #include "dgiofileiterator.h" #include "dgiomount.h" #include #include #include #include #include #include #include #include #include #include using namespace Gio; class DGioFilePrivate { public: DGioFilePrivate(DGioFile *qq, File *gmmFilePtr); Glib::RefPtr getGmmFileInstance() const; private: Glib::RefPtr m_gmmFilePtr; QString uri() const; DGioFile *q_ptr; void slot_enumerateChildrenAsyncResult(const Glib::RefPtr& result); void slot_mountEnclosingVolumeResult(const Glib::RefPtr& result); Q_DECLARE_PUBLIC(DGioFile) }; DGioFilePrivate::DGioFilePrivate(DGioFile *qq, File *gmmFilePtr) : m_gmmFilePtr(gmmFilePtr) , q_ptr(qq) { } Glib::RefPtr DGioFilePrivate::getGmmFileInstance() const { return m_gmmFilePtr; } QString DGioFilePrivate::uri() const { return QString::fromStdString(m_gmmFilePtr->get_uri()); } void DGioFilePrivate::slot_enumerateChildrenAsyncResult(const Glib::RefPtr &result) { Q_Q(DGioFile); try { Glib::RefPtr iter = m_gmmFilePtr->enumerate_children_finish(result); QExplicitlySharedDataPointer fileIterPtr(new DGioFileIterator(iter.release())); Q_EMIT q->createFileIteratorReady(fileIterPtr); } catch (const Glib::Error & error) { qDebug() << QString::fromStdString(error.what().raw()); } } void DGioFilePrivate::slot_mountEnclosingVolumeResult(const Glib::RefPtr &result) { Q_Q(DGioFile); try { bool res = m_gmmFilePtr->mount_enclosing_volume_finish(result); Q_EMIT q->mountEnclosingVolumeReady(res, ""); } catch (const Glib::Error & error) { qDebug() << QString::fromStdString(error.what().raw()); Q_EMIT q->mountEnclosingVolumeReady(false, QString::fromStdString(error.what().raw())); } } // ------------------------------------------------------------- DGioFile::DGioFile(File* gmmFilePtr, QObject *parent) : QObject(parent) , d_ptr(new DGioFilePrivate(this, gmmFilePtr)) { // gmountPtr must be valid; Q_CHECK_PTR(gmmFilePtr); } DGioFile::~DGioFile() { } /*! * \brief Create a DGioFile instance by given \a path * * This operation never fails since Gio::File::create_for_path never fails, but the returned * object might not support any I/O operation if path is malformed. * * Caller take the ownership of the created object, you can also provide a \a parent object. * * \return the created DGioFile instance */ DGioFile *DGioFile::createFromPath(QString path, QObject *parent) { // ensure GIO got initialized Gio::init(); // File::create_for_path never falls. Glib::RefPtr gmmFile = File::create_for_path(path.toStdString()); return new DGioFile(gmmFile.release(), parent); } /*! * \brief Create a DGioFile instance by given \a uri * * This operation never fails since Gio::File::create_for_uri never fails, but the returned * object might not support any I/O operation if uri is malformed. * * Caller take the ownership of the created object, you can also provide a \a parent object. * * \return the created DGioFile instance */ DGioFile *DGioFile::createFromUri(QString uri, QObject *parent) { // ensure GIO got initialized Gio::init(); // File::create_for_uri never falls. Glib::RefPtr gmmFile = File::create_for_uri(uri.toStdString()); return new DGioFile(gmmFile.release(), parent); } /*! * \brief Create a DGioFile instance for a given argument from the command line. * * The value of \a arg can be either a URI, an absolute path or a relative path resolved relative * to the current working directory. This operation never fails, but the returned object might * not support any I/O operation if \a arg points to a malformed path. * * \param arg A string containing either a URI, a relative or absolute path. * \return the created DGioFile instance */ DGioFile *DGioFile::createFromCmdArg(QString arg, QObject *parent) { // ensure GIO got initialized Gio::init(); // File::create_for_uri never falls. Glib::RefPtr gmmFile = File::create_for_commandline_arg(arg.toStdString()); return new DGioFile(gmmFile.release(), parent); } /*! * \brief Gets the base name (the last component of the path) of the DGioFile * * Wrapper of Gio::File::get_basename(), normally return filename with suffix (without path). * * If called for the top level of a system (such as the filesystem root or a uri like sftp://host/) * it will return a single directory separator (and on Windows, possibly a drive letter). * * If you want to use filenames in a user interface you should use DGioFileInfo::displayName() instead. */ QString DGioFile::basename() const { Q_D(const DGioFile); return QString::fromStdString(d->getGmmFileInstance()->get_basename()); } /*! * \brief Gets the local pathname of the DGioFile, if one exists. * * Wrapper of Gio::File::get_path(). For local file it gets the local pathname with filename included, * for filesystem it gets the mount point path. * * If valid, this is guaranteed to be an absolute, canonical path. It might contain symlinks. */ QString DGioFile::path() const { Q_D(const DGioFile); return QString::fromStdString(d->getGmmFileInstance()->get_path()); } QString DGioFile::uri() const { Q_D(const DGioFile); return d->uri(); } /*! * \brief Gets the requested information about the file. * * Wrapper of Gio::File::query_info(const std::string& attributes = "*", FileQueryInfoFlags flags = FILE_QUERY_INFO_NONE). * * \return the created file info object, or nullptr if create failed. */ QExplicitlySharedDataPointer DGioFile::createFileInfo(QString attr, DGioFileQueryInfoFlags queryInfoFlags, unsigned long timeout_msec) { Q_D(DGioFile); try { unsigned int flagValue = queryInfoFlags; FileQueryInfoFlags flags = static_cast(flagValue); Glib::RefPtr gmmFileInfo; QSharedPointer cond(new QWaitCondition); QSharedPointer m(new QMutex); QtConcurrent::run([&, cond, m, timeout_msec] { Glib::RefPtr localret; QTime t; t.start(); try { localret = d->getGmmFileInstance()->query_info(attr.toStdString(), flags); } catch (const Glib::Error &error) { qDebug() << QString::fromStdString(error.what().raw()); return; } if (t.elapsed() < timeout_msec) { gmmFileInfo = localret; cond->wakeAll(); } }); m->lock(); bool finished = gmmFileInfo || cond->wait(m.data(), timeout_msec); m->unlock(); if (finished && gmmFileInfo) { QExplicitlySharedDataPointer fileInfoPtr(new DGioFileInfo(gmmFileInfo.release())); return fileInfoPtr; } } catch (const Glib::Error &error) { qDebug() << QString::fromStdString(error.what().raw()); } return QExplicitlySharedDataPointer(nullptr); } /*! * \brief Obtains information about the filesystem the file is on. * * Wrapper of Gio::File::query_filesystem_info("filesystem::*"). * * \return the created file system info object, or nullptr if create failed. */ QExplicitlySharedDataPointer DGioFile::createFileSystemInfo(QString attr) { Q_D(DGioFile); try { Glib::RefPtr gmmFileInfo = d->getGmmFileInstance()->query_filesystem_info(attr.toStdString()); if (gmmFileInfo) { QExplicitlySharedDataPointer fileInfoPtr(new DGioFileInfo(gmmFileInfo.release())); return fileInfoPtr; } } catch (const Glib::Error &error) { qDebug() << QString::fromStdString(error.what().raw()); } return QExplicitlySharedDataPointer(nullptr); } /*! * \brief Gets the requested information about the files in a directory. * * Wrapper of Gio::File::enumerate_children() * * The attribute value is a string that specifies the file attributes that should be gathered. * It is not an error if its not possible to read a particular requested attribute from a file, * it just won't be set. attribute should be a comma-separated list of attribute or attribute * wildcards. The wildcard "*" means all attributes, and a wildcard like "standard::*" means all * attributes in the standard namespace. An example attribute query be "standard::*,owner::user". * The standard attributes are available as defines, like FILE_ATTRIBUTE_STANDARD_NAME. * * \param attr An attribute query string. * \param queryInfoFlags * \return the created DGioFileIterator object, or nullptr if failed. */ QExplicitlySharedDataPointer DGioFile::createFileIterator(QString attr, DGioFileQueryInfoFlags queryInfoFlags) { Q_D(DGioFile); unsigned int flagValue = queryInfoFlags; FileQueryInfoFlags flags = static_cast(flagValue); try { Glib::RefPtr gmmFileEnumerator = d->getGmmFileInstance()->enumerate_children(attr.toStdString(), flags); QExplicitlySharedDataPointer fileIterPtr(new DGioFileIterator(gmmFileEnumerator.release())); return fileIterPtr; } catch (const Glib::Error &error) { qDebug() << QString::fromStdString(error.what().raw()); } return QExplicitlySharedDataPointer(nullptr); } void DGioFile::createFileIteratorAsync(QString attr, DGioFileQueryInfoFlags queryInfoFlags) { Q_D(DGioFile); unsigned int flagValue = queryInfoFlags; FileQueryInfoFlags flags = static_cast(flagValue); d->getGmmFileInstance()->enumerate_children_async(sigc::mem_fun(d, &DGioFilePrivate::slot_enumerateChildrenAsyncResult), attr.toStdString(), flags); } void DGioFile::mountEnclosingVolume(DGioMountOperation *dgioMountOperation) { Q_D(DGioFile); d->getGmmFileInstance()->mount_enclosing_volume(dgioMountOperation->getGIOMountOperationObj(), sigc::mem_fun(d, &DGioFilePrivate::slot_mountEnclosingVolumeResult)); } QExplicitlySharedDataPointer DGioFile::findEnclosingMount() { Q_D(DGioFile); QExplicitlySharedDataPointer ret; try { ret = new DGioMount(d->getGmmFileInstance()->find_enclosing_mount().release()); } catch (const Glib::Error &error) { qDebug() << QString::fromStdString(error.what().raw()); } return ret; } gio-qt-0.0.11/gio-qt/source/dgiofileinfo.cpp000066400000000000000000000130401402606753700206430ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include "dgiofileinfo.h" #include "dgiohelper.h" #include using namespace Gio; class DGioFileInfoPrivate { public: DGioFileInfoPrivate(DGioFileInfo *qq, FileInfo *gmmFileInfoPtr); Glib::RefPtr getGmmFileInfoInstance() const; Glib::RefPtr icon() const; bool getAttributeBoolean(const std::string &attribute) const; quint64 getAttributeUint64(const std::string &attribute) const; QString getAttributeString(const std::string &attribute) const; private: Glib::RefPtr m_gmmFileInfoPtr; QString uri() const; DGioFileInfo *q_ptr; Q_DECLARE_PUBLIC(DGioFileInfo) }; DGioFileInfoPrivate::DGioFileInfoPrivate(DGioFileInfo *qq, FileInfo *gmmFileInfoPtr) : m_gmmFileInfoPtr(gmmFileInfoPtr) , q_ptr(qq) { } Glib::RefPtr DGioFileInfoPrivate::getGmmFileInfoInstance() const { return m_gmmFileInfoPtr; } Glib::RefPtr DGioFileInfoPrivate::icon() const { return getGmmFileInfoInstance()->get_icon(); } bool DGioFileInfoPrivate::getAttributeBoolean(const std::string &attribute) const { return m_gmmFileInfoPtr->get_attribute_boolean(attribute); } quint64 DGioFileInfoPrivate::getAttributeUint64(const std::string &attribute) const { return m_gmmFileInfoPtr->get_attribute_uint64(attribute); } QString DGioFileInfoPrivate::getAttributeString(const std::string &attribute) const { return QString::fromStdString(m_gmmFileInfoPtr->get_attribute_string(attribute)); } // ------------------------------------------------------------- DGioFileInfo::DGioFileInfo(FileInfo *gmmFileInfoInfoPtr, QObject *parent) : QObject(parent) , d_ptr(new DGioFileInfoPrivate(this, gmmFileInfoInfoPtr)) { } DGioFileInfo::~DGioFileInfo() { } /*! * \brief Gets a display name for a file. * * A display name is guaranteed to be in UTF8 and can thus be displayed in the UI. * * Wrapper of Gio::FileInfo::get_display_name(), internally it returns the * G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute value. */ QString DGioFileInfo::displayName() const { Q_D(const DGioFileInfo); return QString::fromStdString(d->getGmmFileInfoInstance()->get_display_name()); } /*! * \brief DGioFileInfo::fileType * * Wrapper of Gio::FileInfo::get_file_type(), internally it returns the * G_FILE_ATTRIBUTE_STANDARD_TYPE attribute value. * \return */ DGioFileType DGioFileInfo::fileType() const { Q_D(const DGioFileInfo); return static_cast(d->getGmmFileInfoInstance()->get_file_type()); } /*! * \brief DGioFileInfo::fileSize * * Wrapper of Gio::FileInfo::get_size() * * \return the file size in bytes. */ quint64 DGioFileInfo::fileSize() const { Q_D(const DGioFileInfo); return static_cast(d->getGmmFileInfoInstance()->get_size()); } /*! * \brief get the file content type (MimeType). * * Wrapper of Gio::FileInfo::get_content_type() * * \return a single MimeType of the file, such as "text/plain". */ QString DGioFileInfo::contentType() const { Q_D(const DGioFileInfo); return QString::fromStdString(d->getGmmFileInfoInstance()->get_content_type()); } /*! * \brief DGioFileInfo::iconString * * Wrapper of Gio::FileInfo::get_icon() and then Gio::Icon::to_string(). * * Notice the returned value can be in two different form: * * - a native path (such as "/path/to/my icon.png") without escaping if the file for icon is a native * file. If the file is not native, the returned string is the result of g_file_get_uri() * (such as "sftp://path/to/my%20icon.png"). * * - a icon name if icon is a ThemedIcon with exactly one name, the encoding is simply the name (such as * network-server), or a list of theme names (such as ". GThemedIcon text-plain text-x-generic text-plain-symbolic"). * * \return the icon string as discribed above. */ QString DGioFileInfo::iconString() const { Q_D(const DGioFileInfo); return QString::fromStdString(d->icon()->to_string()); } QStringList DGioFileInfo::themedIconNames() const { Q_D(const DGioFileInfo); return DGioPrivate::getThemedIconNames(d->icon()); } bool DGioFileInfo::fsReadOnly() const { Q_D(const DGioFileInfo); return d->getAttributeBoolean(G_FILE_ATTRIBUTE_FILESYSTEM_READONLY); } quint64 DGioFileInfo::fsTotalBytes() const { Q_D(const DGioFileInfo); return d->getAttributeUint64(G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); } quint64 DGioFileInfo::fsUsedBytes() const { Q_D(const DGioFileInfo); return d->getAttributeUint64(G_FILE_ATTRIBUTE_FILESYSTEM_USED); } quint64 DGioFileInfo::fsFreeBytes() const { Q_D(const DGioFileInfo); return d->getAttributeUint64(G_FILE_ATTRIBUTE_FILESYSTEM_FREE); } QString DGioFileInfo::fsType() const { Q_D(const DGioFileInfo); return d->getAttributeString(G_FILE_ATTRIBUTE_FILESYSTEM_TYPE); } gio-qt-0.0.11/gio-qt/source/dgiofileiterator.cpp000066400000000000000000000077511402606753700215550ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include "dgiofileiterator.h" #include "dgiofileinfo.h" #include #include #include #include #include using namespace Gio; class DGioFileIteratorPrivate { public: DGioFileIteratorPrivate(DGioFileIterator *qq, FileEnumerator *gmmFileEnumeratorPtr); Glib::RefPtr getGmmFileEnumeratorInstance() const; private: Glib::RefPtr m_gmmFileEnumeratorPtr; DGioFileIterator *q_ptr; void slot_nextFileAsyncResult(const Glib::RefPtr& result); Q_DECLARE_PUBLIC(DGioFileIterator) }; DGioFileIteratorPrivate::DGioFileIteratorPrivate(DGioFileIterator *qq, FileEnumerator *gmmFileEnumeratorPtr) : m_gmmFileEnumeratorPtr(gmmFileEnumeratorPtr) , q_ptr(qq) { } Glib::RefPtr DGioFileIteratorPrivate::getGmmFileEnumeratorInstance() const { return m_gmmFileEnumeratorPtr; } void DGioFileIteratorPrivate::slot_nextFileAsyncResult(const Glib::RefPtr &result) { Q_Q(DGioFileIterator); try { Glib::ListHandle< Glib::RefPtr > files = m_gmmFileEnumeratorPtr->next_files_finish(result); QList > fileInfoList; for (auto gmmFileInfoPtr : files) { QExplicitlySharedDataPointer info(new DGioFileInfo(gmmFileInfoPtr.release())); fileInfoList.append(info); } Q_EMIT q->nextFilesReady(fileInfoList); } catch (const Gio::Error& error) { if (error.code() != Gio::Error::CANCELLED) { Q_EMIT q->nextFilesCancelled(); } else { // should we add an error signal? qDebug() << QString::fromStdString(error.what().raw()); } } catch (const Glib::Error& error) { // should we add an error signal? qDebug() << QString::fromStdString(error.what().raw()); } } // ------------------------------------------------------------- DGioFileIterator::DGioFileIterator(FileEnumerator* gmmFileEnumeratorPtr, QObject *parent) : QObject(parent) , d_ptr(new DGioFileIteratorPrivate(this, gmmFileEnumeratorPtr)) { // gmmFileEnumeratorPtr must be valid; Q_CHECK_PTR(gmmFileEnumeratorPtr); } DGioFileIterator::~DGioFileIterator() { } QExplicitlySharedDataPointer DGioFileIterator::nextFile() { Q_D(DGioFileIterator); try { // can return nullptr if there is no file left. Glib::RefPtr gmmFileInfoPtr = d->getGmmFileEnumeratorInstance()->next_file(); if (gmmFileInfoPtr) { QExplicitlySharedDataPointer fileInfo(new DGioFileInfo(gmmFileInfoPtr.release())); return fileInfo; } } catch (const Glib::Error &error) { qDebug() << QString::fromStdString(error.what().raw()); } return QExplicitlySharedDataPointer(nullptr); } void DGioFileIterator::nextFilesAsync(int numberOfFiles, DGioIOPriority io_priority) { Q_D(DGioFileIterator); d->getGmmFileEnumeratorInstance()->next_files_async(sigc::mem_fun(d, &DGioFileIteratorPrivate::slot_nextFileAsyncResult), numberOfFiles, io_priority); } gio-qt-0.0.11/gio-qt/source/dgiomount.cpp000066400000000000000000000143121402606753700202150ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include "dgiomount.h" #include "dgiovolume.h" #include "dgiofile.h" #include #include #include #include #include #include // private #include "dgiohelper.h" using namespace Gio; class DGioMountPrivate { public: DGioMountPrivate(DGioMount *qq, Mount *gmmMountPtr); Glib::RefPtr getGmmMountInstance() const; QString name() const; QString uuid() const; bool canUnmount() const; bool canEject() const; private: Glib::RefPtr m_gmmMountPtr; DGioMount *q_ptr; Q_DECLARE_PUBLIC(DGioMount) }; DGioMountPrivate::DGioMountPrivate(DGioMount *qq, Mount *gmmMountPtr) : m_gmmMountPtr(gmmMountPtr) , q_ptr(qq) { } Glib::RefPtr DGioMountPrivate::getGmmMountInstance() const { return m_gmmMountPtr; } QString DGioMountPrivate::name() const { return QString::fromStdString(m_gmmMountPtr->get_name()); } QString DGioMountPrivate::uuid() const { return QString::fromStdString(m_gmmMountPtr->get_uuid()); } // ------------------------------------------------------------- DGioMount::DGioMount(Mount *gmmMountPtr, QObject *parent) : QObject(parent) , d_ptr(new DGioMountPrivate(this, gmmMountPtr)) { // gmountPtr must be valid; Q_CHECK_PTR(gmmMountPtr); } DGioMount::~DGioMount() { } /*! * \brief Create a DGioMount instance by a given \a path * * \return the created DGioMount instance or nullptr if failed. */ DGioMount *DGioMount::createFromPath(QString path, QObject *parent) { // ensure GIO got initialized Gio::init(); Glib::RefPtr gmmFile = File::create_for_path(path.toStdString()); try { Glib::RefPtr gmmMount = gmmFile->find_enclosing_mount(); if (gmmMount) { return new DGioMount(gmmMount.release(), parent); } } catch (const Glib::Error &error) { qDebug() << QString::fromStdString(error.what().raw()); } return nullptr; } QString DGioMount::name() const { Q_D(const DGioMount); return d->name(); } QString DGioMount::uuid() const { Q_D(const DGioMount); return d->uuid(); } QString DGioMount::mountClass() const { Q_D(const DGioMount); return QString(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(d->m_gmmMountPtr->gobj()))); } /*! * \brief Determines if mount is shadowed. * * A mount is said to be shadowed if there exists one or more user visible objects (currently Mount objects) * with a root that is inside the root of mount. * * One application of shadow mounts is when exposing a single file system that is used to address several * logical volumes. In this situation, a Gio::VolumeMonitor implementation would create two Gio::Volume * objects, in gio-qt, DGioVolumeManager will create two DGioVolume objects. * * For example, one for the camera functionality of the device and one for a SD card reader on the device) with * activation URIs gphoto2://[usb:001,002]/store1/ and gphoto2://[usb:001,002]/store2/. When the underlying * mount (with root gphoto2://[usb:001,002]/) is mounted, said VolumeMonitor implementation would create two * Mount objects (each with their root matching the corresponding volume activation root) that would shadow * the original mount. * * \return true if mount is shadowed */ bool DGioMount::isShadowed() const { Q_D(const DGioMount); return d->getGmmMountInstance()->is_shadowed(); } bool DGioMount::canUnmount() const { Q_D(const DGioMount); return d->getGmmMountInstance()->can_unmount(); } bool DGioMount::canEject() const { Q_D(const DGioMount); return d->getGmmMountInstance()->can_eject(); } QString DGioMount::sortKey() const { Q_D(const DGioMount); return QString::fromStdString(d->getGmmMountInstance()->get_sort_key()); } QStringList DGioMount::themedIconNames() const { Q_D(const DGioMount); Glib::RefPtr icon = d->getGmmMountInstance()->get_icon(); return DGioPrivate::getThemedIconNames(icon); } QStringList DGioMount::themedSymbolicIconNames() const { Q_D(const DGioMount); Glib::RefPtr icon = d->getGmmMountInstance()->get_symbolic_icon(); return DGioPrivate::getThemedIconNames(icon); } void DGioMount::unmount(bool forceUnmount) { Q_D(const DGioMount); return d->getGmmMountInstance()->unmount(forceUnmount ? MOUNT_UNMOUNT_FORCE : MOUNT_UNMOUNT_NONE); } void DGioMount::eject(bool forceEject) { Q_D(const DGioMount); return d->getGmmMountInstance()->eject(forceEject ? MOUNT_UNMOUNT_FORCE : MOUNT_UNMOUNT_NONE); } QExplicitlySharedDataPointer DGioMount::getRootFile() { Q_D(const DGioMount); Glib::RefPtr file = d->getGmmMountInstance()->get_root(); QExplicitlySharedDataPointer filePtr(new DGioFile(file.release())); return filePtr; } QExplicitlySharedDataPointer DGioMount::getDefaultLocationFile() { Q_D(const DGioMount); Glib::RefPtr file = d->getGmmMountInstance()->get_default_location(); QExplicitlySharedDataPointer filePtr(new DGioFile(file.release())); return filePtr; } QExplicitlySharedDataPointer DGioMount::getVolume() { Q_D(const DGioMount); Glib::RefPtr vol = d->getGmmMountInstance()->get_volume(); if (vol) { QExplicitlySharedDataPointer volPtr(new DGioVolume(vol.release())); return volPtr; } return QExplicitlySharedDataPointer(nullptr); } gio-qt-0.0.11/gio-qt/source/dgiomountoperation.cpp000066400000000000000000000144331402606753700221420ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include "dgiomountoperation.h" #include using namespace Gio; class DGioMountOperationPrivate { public: DGioMountOperationPrivate(DGioMountOperation *qq); ~DGioMountOperationPrivate(); private: Glib::RefPtr getGmmMountOperationInstance() const; QString username() const; void slot_askPassword(const Glib::ustring& message, const Glib::ustring& default_user, const Glib::ustring& default_domain, AskPasswordFlags flags); void slot_askQuestion(const Glib::ustring& message, const Glib::StringArrayHandle& choices); void slot_showUnmountProgress(const Glib::ustring &message, gint64 time_left, gint64 bytes_left); QList m_connections; private: Glib::RefPtr m_gmmMountOperationPtr; DGioMountOperation *q_ptr; Q_DECLARE_PUBLIC(DGioMountOperation) }; DGioMountOperationPrivate::DGioMountOperationPrivate(DGioMountOperation *qq) : q_ptr(qq) { m_gmmMountOperationPtr = Gio::MountOperation::create(); m_connections.append(m_gmmMountOperationPtr->signal_ask_password().connect(sigc::mem_fun(*this, &DGioMountOperationPrivate::slot_askPassword))); m_connections.append(m_gmmMountOperationPtr->signal_ask_question().connect(sigc::mem_fun(*this, &DGioMountOperationPrivate::slot_askQuestion))); m_connections.append(m_gmmMountOperationPtr->signal_show_unmount_progress().connect(sigc::mem_fun(*this, &DGioMountOperationPrivate::slot_showUnmountProgress))); } DGioMountOperationPrivate::~DGioMountOperationPrivate() { for (auto & c : m_connections) { c.disconnect(); } } Glib::RefPtr DGioMountOperationPrivate::getGmmMountOperationInstance() const { return m_gmmMountOperationPtr; } QString DGioMountOperationPrivate::username() const { return QString::fromStdString(m_gmmMountOperationPtr->get_username().raw()); } void DGioMountOperationPrivate::slot_askPassword(const Glib::ustring &message, const Glib::ustring &default_user, const Glib::ustring &default_domain, AskPasswordFlags flags) { Q_Q(DGioMountOperation); QString msg = QString::fromStdString(message.raw()); QString defaultUser = QString::fromStdString(default_user.raw()); QString defaultDomain = QString::fromStdString(default_domain.raw()); DGioAskPasswordFlags askPasswordFlags(static_cast(flags)); Q_EMIT q->askPassword(msg, defaultUser, defaultDomain, askPasswordFlags); } void DGioMountOperationPrivate::slot_askQuestion(const Glib::ustring &message, const Glib::StringArrayHandle &choices) { Q_Q(DGioMountOperation); QString msg = QString::fromStdString(message.raw()); QStringList choiceList; for (auto oneChoice : choices) { choiceList.append(QString::fromStdString(oneChoice.raw())); } Q_EMIT q->askQuestion(msg, choiceList); } void DGioMountOperationPrivate::slot_showUnmountProgress(const Glib::ustring& message, gint64 time_left, gint64 bytes_left) { Q_Q(DGioMountOperation); Q_EMIT q->showUnmountProgress(QString::fromStdString(message.raw()), time_left, bytes_left); } // ------------------------------------------------------------- DGioMountOperation::DGioMountOperation(QObject *parent) : QObject(parent) , d_ptr(new DGioMountOperationPrivate(this)) { } DGioMountOperation::~DGioMountOperation() { } QString DGioMountOperation::username() const { Q_D(const DGioMountOperation); return d->username(); } void DGioMountOperation::setUsername(QString name) { Q_D(DGioMountOperation); d->getGmmMountOperationInstance()->set_username(name.toStdString()); } QString DGioMountOperation::password() const { Q_D(const DGioMountOperation); return QString::fromStdString(d->getGmmMountOperationInstance()->get_password()); } void DGioMountOperation::setPassword(QString password) { Q_D(DGioMountOperation); d->getGmmMountOperationInstance()->set_password(password.toStdString()); } DGioPasswordSave DGioMountOperation::passwordSave() { Q_D(const DGioMountOperation); return static_cast(d->getGmmMountOperationInstance()->get_password_save()); } void DGioMountOperation::setPasswordSave(DGioPasswordSave save) { Q_D(DGioMountOperation); d->getGmmMountOperationInstance()->set_password_save(static_cast(save)); } QString DGioMountOperation::domain() const { Q_D(const DGioMountOperation); return QString::fromStdString(d->getGmmMountOperationInstance()->get_domain()); } void DGioMountOperation::setDomain(QString domain) { Q_D(DGioMountOperation); d->getGmmMountOperationInstance()->set_domain(domain.toStdString()); } bool DGioMountOperation::anonymous() const { Q_D(const DGioMountOperation); return d->getGmmMountOperationInstance()->get_anonymous(); } void DGioMountOperation::setAnonymous(bool anonymous) { Q_D(DGioMountOperation); d->getGmmMountOperationInstance()->set_anonymous(anonymous); } int DGioMountOperation::choice() const { Q_D(const DGioMountOperation); return d->getGmmMountOperationInstance()->get_choice(); } void DGioMountOperation::setChoice(int choice) { Q_D(DGioMountOperation); d->getGmmMountOperationInstance()->set_choice(choice); } void DGioMountOperation::reply(DGioMountOperationResult result) { Q_D(DGioMountOperation); d->getGmmMountOperationInstance()->reply(static_cast(result)); } Glib::RefPtr DGioMountOperation::getGIOMountOperationObj() { Q_D(const DGioMountOperation); return d->getGmmMountOperationInstance(); } gio-qt-0.0.11/gio-qt/source/dgiosettings.cpp000066400000000000000000000271361402606753700207230ustar00rootroot00000000000000/* * Copyright (C) 2011 ~ 2019 Deepin Technology Co., Ltd. * * Author: justforlxz * * Maintainer: justforlxz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include "dgiosettings.h" #include "private/dgiohelper.h" #include #include #include #include static QVariant qconf_types_to_qvariant(GVariant* value) { switch (g_variant_classify(value)) { case G_VARIANT_CLASS_BOOLEAN: return QVariant(static_cast(g_variant_get_boolean(value))); case G_VARIANT_CLASS_BYTE: return QVariant(static_cast(g_variant_get_byte(value))); case G_VARIANT_CLASS_INT16: return QVariant(static_cast(g_variant_get_int16(value))); case G_VARIANT_CLASS_UINT16: return QVariant(static_cast(g_variant_get_uint16(value))); case G_VARIANT_CLASS_INT32: return QVariant(static_cast(g_variant_get_int32(value))); case G_VARIANT_CLASS_UINT32: return QVariant(static_cast(g_variant_get_uint32(value))); case G_VARIANT_CLASS_INT64: return QVariant(static_cast(g_variant_get_int64(value))); case G_VARIANT_CLASS_UINT64: return QVariant(static_cast(g_variant_get_uint64(value))); case G_VARIANT_CLASS_DOUBLE: return QVariant(g_variant_get_double(value)); case G_VARIANT_CLASS_STRING: return QVariant(g_variant_get_string(value, nullptr)); case G_VARIANT_CLASS_ARRAY: if (g_variant_is_of_type(value, G_VARIANT_TYPE_STRING_ARRAY)) { GVariantIter iter; QStringList list; const gchar *str; g_variant_iter_init (&iter, value); while (g_variant_iter_next(&iter, "&s", &str)) { list.append (str); } return QVariant(list); } else if (g_variant_is_of_type(value, G_VARIANT_TYPE_BYTESTRING)) { return QVariant(QByteArray(g_variant_get_bytestring(value))); } else if (g_variant_is_of_type(value, G_VARIANT_TYPE("a{ss}"))) { GVariantIter iter; QMap map; const gchar* key; const gchar* val; g_variant_iter_init (&iter, value); while (g_variant_iter_next(&iter, "{&s&s}", &key, &val)) { map.insert(key, QVariant(val)); } return map; } } qWarning() << "No matching type! " << g_variant_classify(value); return QVariant(); } static GVariant *qconf_types_collect_from_variant(const GVariantType* gtype, const QVariant& v) { switch (g_variant_type_peek_string(gtype)[0]) { case G_VARIANT_CLASS_BOOLEAN: return g_variant_new_boolean(v.toBool()); case G_VARIANT_CLASS_BYTE: return g_variant_new_byte(v.toChar().cell()); case G_VARIANT_CLASS_INT16: return g_variant_new_int16(v.toInt()); case G_VARIANT_CLASS_UINT16: return g_variant_new_uint16(v.toUInt()); case G_VARIANT_CLASS_INT32: return g_variant_new_int32(v.toInt()); case G_VARIANT_CLASS_UINT32: return g_variant_new_uint32(v.toUInt()); case G_VARIANT_CLASS_INT64: return g_variant_new_int64(v.toLongLong()); case G_VARIANT_CLASS_UINT64: return g_variant_new_int64(v.toULongLong()); case G_VARIANT_CLASS_DOUBLE: return g_variant_new_double(v.toDouble()); case G_VARIANT_CLASS_STRING: return g_variant_new_string(v.toString().toUtf8()); case G_VARIANT_CLASS_ARRAY: if (g_variant_type_equal(gtype, G_VARIANT_TYPE_STRING_ARRAY)) { const QStringList list = v.toStringList(); GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE_STRING_ARRAY); for (const QString& string : list) { g_variant_builder_add(&builder, "s", string.toUtf8().constData()); } return g_variant_builder_end(&builder); } else if (g_variant_type_equal(gtype, G_VARIANT_TYPE_BYTESTRING)) { const QByteArray& array = v.toByteArray(); gsize size = static_cast(array.size()); gpointer data; data = g_memdup(array.data(), static_cast(size)); return g_variant_new_from_data(G_VARIANT_TYPE_BYTESTRING, data, size, TRUE, g_free, data); } else if (g_variant_type_equal(gtype, G_VARIANT_TYPE("a{ss}"))) { GVariantBuilder builder; g_variant_builder_init(&builder, G_VARIANT_TYPE ("a{ss}")); QMapIterator it(v.toMap()); while (it.hasNext()) { it.next(); const QByteArray& key = it.key().toUtf8(); const QByteArray& val = it.value().toByteArray(); g_variant_builder_add (&builder, "{ss}", key.constData(), val.constData()); } return g_variant_builder_end (&builder); } } qWarning() << "No matching type! " << g_variant_type_peek_string(gtype)[0]; return nullptr; } class DGioSettingsPrivate { public: DGioSettingsPrivate(DGioSettings* qq) : ptr(qq) { } QString schemaId; QString path; DGioSettings* ptr; GSettings* settings; GSettingsSchema* schema; gulong signalHandlerId; bool strvHasString (gchar **haystack, const gchar *needle) const { if (needle == nullptr) return false; for (guint n = 0; haystack != NULL && haystack[n] != NULL; n++) { if (g_strcmp0 (haystack[n], needle) == 0) return true; } return false; } bool inlcudeKey(const gchar* gkey) const { gchar **allKeys = g_settings_list_keys(settings); bool ret = strvHasString (allKeys, gkey); g_strfreev (allKeys); return ret; } QVariant value(GSettings* gsettings, const QString& key) const { gchar* gkey = DGioPrivate::converToGChar(key.toUtf8()); if(!inlcudeKey(gkey)) { g_free(gkey); return QVariant(); } GVariant* variant = g_settings_get_value(gsettings, gkey); QVariant qvalue = qconf_types_to_qvariant(variant); g_variant_unref(variant); g_free(gkey); return qvalue; } bool trySet(const QString& key, const QVariant& value) { const gchar* gkey = key.toUtf8().constData(); if(!inlcudeKey(gkey)) return false; bool success = false; /* fetch current value to find out the exact type */ GVariant* cur = g_settings_get_value(settings, gkey); GVariant* new_value = qconf_types_collect_from_variant(g_variant_get_type(cur), value); if (new_value) { success = g_settings_set_value(settings, gkey, new_value); } g_variant_unref(cur); return success; } void sync() { g_settings_sync(); } static void onSettingChanged(GSettings* settings, const gchar* key, gpointer pointer) { DGioSettingsPrivate* self = static_cast(pointer); Q_EMIT self->ptr->valueChanged(key, self->value(settings, key)); } }; /*! * \class DGioSettings * \brief Access GSettings in a more Qt way. * * This is not a directly wrapper of Gio::Settings class, so interfaces are not matched to the * giomm ome. */ /*! * \brief Create a DGioSettings object for a given \a schemaId. * * In case you would like to skip path but provide a \a parent. * * Warning: not existed schemaId will cause the program crashed. */ DGioSettings::DGioSettings(const QString& schemaId, QObject* parent) : DGioSettings(schemaId, QString(), parent) { } /*! * \brief Create a DGioSettings object for a given \a schemaId and \a path. * * Warning: not existed schemaId will cause the program crashed. */ DGioSettings::DGioSettings(const QString& schemaId, const QString& path, QObject* parent) : QObject(parent) , d_private(new DGioSettingsPrivate(this)) { d_private->schemaId = schemaId; d_private->path = path; d_private->settings = path.isEmpty() ? g_settings_new(d_private->schemaId.toUtf8().constData()) : g_settings_new_with_path(d_private->schemaId.toUtf8().constData(), path.toUtf8().constData()); g_object_get(d_private->settings, "settings-schema", &d_private->schema, nullptr); d_private->signalHandlerId = g_signal_connect(d_private->settings, "changed", G_CALLBACK(DGioSettingsPrivate::onSettingChanged), d_private.data()); } DGioSettings::~DGioSettings() { Q_D(DGioSettings); if (d->schema) { g_settings_sync (); g_signal_handler_disconnect(d->settings, d->signalHandlerId); g_object_unref (d->settings); g_settings_schema_unref (d->schema); } } /*! * \brief Sets the value at \a key to \a value * * Not all values that a QVariant can hold can be serialized into a setting. Basic types are supported. the * provided variant value will be converted according to the original GSetting value type. * * List of supported types: * * - boolean * - byte/char * - int, uint, long long * - double * - string * - string list. * * \param sync call sync() after value applied if success. * \return true if success, false if failed. */ bool DGioSettings::setValue(const QString& key, const QVariant& value, bool sync) { Q_D(DGioSettings); if (!d->trySet(key, value)) { qWarning() << QString("unable to set key %1 to value %2").arg(key).arg(value.toString()); return false; } if (sync) { d->sync(); } return true; } QVariant DGioSettings::value(const QString& key) const { Q_D(const DGioSettings); return d->value(d->settings, key); } /*! * \brief Retrieves the list of avaliable keys * * According to g_settings_list_keys() document: You should probably not be calling this function * from "normal" code (since you should already know what keys are in your schema). This function * is intended for introspection reasons. * * Thus we also mark this function as DEPRECATED just like what glib does. */ QStringList DGioSettings::keys() const { Q_D(const DGioSettings); QStringList list; gchar** keys = g_settings_list_keys(d->settings); for (int i = 0; keys[i]; i++) { list.append(keys[i]); } g_strfreev(keys); return list; } void DGioSettings::reset(const QString& key) { Q_D(DGioSettings); g_settings_reset(d->settings, key.toUtf8().constData()); } void DGioSettings::sync() { Q_D(DGioSettings); d->sync(); } bool DGioSettings::isSchemaInstalled(const QString& schemaId) { GSettingsSchemaSource* source = g_settings_schema_source_get_default(); if (GSettingsSchema* schema = g_settings_schema_source_lookup(source, schemaId.toUtf8().constData(), true)) { g_settings_schema_unref (schema); return true; } else { return false; } } gio-qt-0.0.11/gio-qt/source/dgiovolume.cpp000066400000000000000000000077501402606753700203720ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include "dgiomount.h" #include "dgiovolume.h" #include #include #include using namespace Gio; class DGioVolumePrivate { public: DGioVolumePrivate(DGioVolume *qq, Volume *gmmVolumePtr); Glib::RefPtr getGmmVolumeInstance() const; QString name() const; private: Glib::RefPtr m_gmmVolumePtr; DGioVolume *q_ptr; Q_DECLARE_PUBLIC(DGioVolume) }; DGioVolumePrivate::DGioVolumePrivate(DGioVolume *qq, Volume *gmmVolumePtr) : m_gmmVolumePtr(gmmVolumePtr) , q_ptr(qq) { // m_gvolumePtr = Glib::wrap(gvolumePtr); } Glib::RefPtr DGioVolumePrivate::getGmmVolumeInstance() const { return m_gmmVolumePtr; } QString DGioVolumePrivate::name() const { return QString::fromStdString(m_gmmVolumePtr->get_name()); } // ------------------------------------------------------------- DGioVolume::DGioVolume(Volume* gmmVolumePtr, QObject *parent) : QObject(parent) , d_ptr(new DGioVolumePrivate(this, gmmVolumePtr)) { // gvolumePtr must be valid; Q_CHECK_PTR(gmmVolumePtr); } DGioVolume::~DGioVolume() { } QString DGioVolume::name() const { Q_D(const DGioVolume); return d->name(); } QString DGioVolume::volumeClass() const { Q_D(const DGioVolume); return QString(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(d->m_gmmVolumePtr->gobj()))); } QString DGioVolume::volumeMonitorName() const { Q_D(const DGioVolume); if (QString(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(d->m_gmmVolumePtr->gobj()))) == "GProxyVolume") { return (const char*)g_object_get_data(G_OBJECT(d->m_gmmVolumePtr->gobj()), "g-proxy-volume-volume-monitor-name"); } return ""; } bool DGioVolume::canMount() const { Q_D(const DGioVolume); return d->getGmmVolumeInstance()->can_mount(); } bool DGioVolume::canEject() const { Q_D(const DGioVolume); return d->getGmmVolumeInstance()->can_eject(); } bool DGioVolume::shouldAutoMount() const { Q_D(const DGioVolume); return d->getGmmVolumeInstance()->should_automount(); } void DGioVolume::mount() const { Q_D(const DGioVolume); d->getGmmVolumeInstance()->mount(); } // Return value can be nullptr QExplicitlySharedDataPointer DGioVolume::getMount() { Q_D(DGioVolume); Glib::RefPtr mnt = d->getGmmVolumeInstance()->get_mount(); QExplicitlySharedDataPointer mntPtr(mnt ? new DGioMount(mnt.release()) : nullptr); return mntPtr; } QString DGioVolume::identifier(DGioVolumeIdentifierType id) const { Q_D(const DGioVolume); const static QHash idtmap = { {DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_LABEL, G_VOLUME_IDENTIFIER_KIND_LABEL}, {DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_NFS_MOUNT, G_VOLUME_IDENTIFIER_KIND_NFS_MOUNT}, {DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_UNIX_DEVICE, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE}, {DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_UUID, G_VOLUME_IDENTIFIER_KIND_UUID}, {DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_CLASS, G_VOLUME_IDENTIFIER_KIND_CLASS} }; return QString::fromStdString(d->getGmmVolumeInstance()->get_identifier(idtmap[id])); } gio-qt-0.0.11/gio-qt/source/dgiovolumemanager.cpp000066400000000000000000000206301402606753700217150ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include "dgiomount.h" #include "dgiovolume.h" #include "dgiodrive.h" #include "dgiovolumemanager.h" #include #include #include using namespace Gio; class DGioVolumeManagerPrivate { public: DGioVolumeManagerPrivate(DGioVolumeManager *qq); ~DGioVolumeManagerPrivate(); private: Glib::RefPtr m_gmmVolumeMonitorPtr; DGioVolumeManager *q_ptr; void slot_mountAdded(const Glib::RefPtr< Mount >& gmmMount); void slot_mountRemoved(const Glib::RefPtr< Mount >& gmmMount); void slot_mountPreRemoved(const Glib::RefPtr< Mount >& gmmMount); void slot_mountChanged(const Glib::RefPtr< Mount >& gmmMount); void slot_volumeAdded(const Glib::RefPtr< Volume >& gmmVolume); void slot_volumeRemoved(const Glib::RefPtr< Volume >& gmmVolume); void slot_volumeChanged(const Glib::RefPtr< Volume >& gmmVolume); void slot_driveConnected(const Glib::RefPtr< Drive >& gmmDrive); void slot_driveDisconnected(const Glib::RefPtr< Drive >& gmmDrive); void slot_driveChanged(const Glib::RefPtr< Drive >& gmmDrive); QList m_connections; Q_DECLARE_PUBLIC(DGioVolumeManager) }; DGioVolumeManagerPrivate::DGioVolumeManagerPrivate(DGioVolumeManager *qq) : q_ptr(qq) { // Do Gio's init or things like Gio::VolumeMonitor::get() won't working // Gio::init() will also call Glib::init() so we don't need to call it again. Gio::init(); m_gmmVolumeMonitorPtr = VolumeMonitor::get(); m_connections.append(m_gmmVolumeMonitorPtr->signal_mount_added().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_mountAdded))); m_connections.append(m_gmmVolumeMonitorPtr->signal_mount_removed().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_mountRemoved))); m_connections.append(m_gmmVolumeMonitorPtr->signal_mount_pre_unmount().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_mountPreRemoved))); m_connections.append(m_gmmVolumeMonitorPtr->signal_mount_changed().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_mountChanged))); m_connections.append(m_gmmVolumeMonitorPtr->signal_volume_added().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_volumeAdded))); m_connections.append(m_gmmVolumeMonitorPtr->signal_volume_removed().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_volumeRemoved))); m_connections.append(m_gmmVolumeMonitorPtr->signal_volume_changed().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_volumeChanged))); m_connections.append(m_gmmVolumeMonitorPtr->signal_drive_connected().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_driveConnected))); m_connections.append(m_gmmVolumeMonitorPtr->signal_drive_disconnected().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_driveDisconnected))); m_connections.append(m_gmmVolumeMonitorPtr->signal_drive_changed().connect(sigc::mem_fun(*this, &DGioVolumeManagerPrivate::slot_driveChanged))); } DGioVolumeManagerPrivate::~DGioVolumeManagerPrivate() { for (auto & c : m_connections) { c.disconnect(); } m_gmmVolumeMonitorPtr.release(); } void DGioVolumeManagerPrivate::slot_mountAdded(const Glib::RefPtr &gmmMount) { Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmMount); QExplicitlySharedDataPointer mount(new DGioMount(copy.release())); Q_EMIT q->mountAdded(mount); } void DGioVolumeManagerPrivate::slot_mountRemoved(const Glib::RefPtr &gmmMount) { Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmMount); QExplicitlySharedDataPointer mount(new DGioMount(copy.release())); Q_EMIT q->mountRemoved(mount); } void DGioVolumeManagerPrivate::slot_mountPreRemoved(const Glib::RefPtr &gmmMount) { Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmMount); QExplicitlySharedDataPointer mount(new DGioMount(copy.release())); Q_EMIT q->mountPreRemoved(mount); } void DGioVolumeManagerPrivate::slot_mountChanged(const Glib::RefPtr &gmmMount) { Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmMount); QExplicitlySharedDataPointer mount(new DGioMount(copy.release())); Q_EMIT q->mountChanged(mount); } void DGioVolumeManagerPrivate::slot_volumeAdded(const Glib::RefPtr &gmmVolume) { Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmVolume); QExplicitlySharedDataPointer volume(new DGioVolume(copy.release())); Q_EMIT q->volumeAdded(volume); } void DGioVolumeManagerPrivate::slot_volumeRemoved(const Glib::RefPtr &gmmVolume) { Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmVolume); QExplicitlySharedDataPointer volume(new DGioVolume(copy.release())); Q_EMIT q->volumeRemoved(volume); } void DGioVolumeManagerPrivate::slot_volumeChanged(const Glib::RefPtr &gmmVolume) { Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmVolume); QExplicitlySharedDataPointer volume(new DGioVolume(copy.release())); Q_EMIT q->volumeChanged(volume); } void DGioVolumeManagerPrivate::slot_driveConnected(const Glib::RefPtr &gmmDrive) { Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmDrive); QExplicitlySharedDataPointer drive(new DGioDrive(copy.release())); Q_EMIT q->driveConnected(drive); } void DGioVolumeManagerPrivate::slot_driveDisconnected(const Glib::RefPtr &gmmDrive) { Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmDrive); QExplicitlySharedDataPointer drive(new DGioDrive(copy.release())); Q_EMIT q->driveDisconnected(drive); } void DGioVolumeManagerPrivate::slot_driveChanged(const Glib::RefPtr &gmmDrive) { Q_Q(DGioVolumeManager); Glib::RefPtr copy(gmmDrive); QExplicitlySharedDataPointer drive(new DGioDrive(copy.release())); Q_EMIT q->driveChanged(drive); } // ------------------------------------------------------------- DGioVolumeManager::DGioVolumeManager(QObject *parent) : QObject(parent) , d_ptr(new DGioVolumeManagerPrivate(this)) { } DGioVolumeManager::~DGioVolumeManager() { } const QList > DGioVolumeManager::getMounts() { // ensure GIO got initialized Gio::init(); QList > mounts; Glib::RefPtr vm = Gio::VolumeMonitor::get(); Glib::ListHandle > mnt = vm->get_mounts(); for (Glib::RefPtr oneMnt : mnt) { QExplicitlySharedDataPointer mntPtr(new DGioMount(oneMnt.release())); mounts.append(mntPtr); } return mounts; } const QList > DGioVolumeManager::getVolumes() { // ensure GIO got initialized Gio::init(); QList > volumes; Glib::RefPtr vm = Gio::VolumeMonitor::get(); Glib::ListHandle > vol = vm->get_volumes(); for (Glib::RefPtr oneVol : vol) { QExplicitlySharedDataPointer volPtr(new DGioVolume(oneVol.release())); volumes.append(volPtr); } return volumes; } const QList > DGioVolumeManager::getDrives() { Gio::init(); QList > drives; Glib::RefPtr vm = Gio::VolumeMonitor::get(); auto drvs = vm->get_connected_drives(); for(auto oneDrive : drvs){ QExplicitlySharedDataPointer drvPtr(new DGioDrive(oneDrive.release())); drives.push_back(drvPtr); } return drives; } gio-qt-0.0.11/gio-qt/source/dglibutils.cpp000066400000000000000000000104141402606753700203510ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include "dglibutils.h" #include #include /*! * \brief Get the full path by directory type. * * Wrapper of Glib::get_user_data_dir(), behavior similar to QStandardPaths::writableLocation(), * but at least it has USER_DIRECTORY_TEMPLATES . * * On UNIX platforms this is determined using the mechanisms described in the * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec). * * \param userDirectory The logical id of special directory. * \return The path to the specified special directory, or an empty string if the logical id was not found. */ QString DGlibUtils::userSpecialDir(DGlibUserDirectory userDirectory) { return QString::fromStdString(Glib::get_user_special_dir(static_cast(userDirectory))); } /*! * \brief Get an ordered list of base directories in which to access system-wide application data. * * Wrapper of Glib::get_system_data_dirs(), behavior similar (should be the same under UNIX) to * QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation). * * On UNIX platforms this is determined using the mechanisms described in the * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec) * In this case the list of directories retrieved will be XDG_DATA_DIRS. */ QStringList DGlibUtils::systemDataDirs() { std::vector dirs = Glib::get_system_data_dirs(); QStringList lst; for (auto dir : dirs) { lst.append(QString::fromStdString(dir)); } return lst; } /*! * \brief Get a base directory in which to access application data such as icons that is customized for a particular user. * * Wrapper of Glib::get_user_data_dir(), behavior similar (should be the same under UNIX) to * QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation). * * On UNIX platforms this is determined using the mechanisms described in the * [XDG Base Directory Specification](http://www.freedesktop.org/Standards/basedir-spec). * In this case the directory retrieved will be `XDG_DATA_HOME`. */ QString DGlibUtils::userDataDir() { return QString::fromStdString(Glib::get_user_data_dir()); } /*! * \brief Gets the directory to use for temporary files. * * Wrapper of Glib::get_user_data_dir(), behavior similar (but not the same) to QDir::temp() or * QStandardPaths::writableLocation(QStandardPaths::TempLocation). * * This is found from inspecting the environment variables TMPDIR, TMP, and TEMP in that order. If none of those are defined * "/tmp" is returned on UNIX and "C:\\" on Windows. * * \return The directory to use for temporary files. */ QString DGlibUtils::tmpDir() { return QString::fromStdString(Glib::get_tmp_dir()); } /*! * \brief Formats a size (for example the size of a file) into a human readable string. * * Sizes are rounded to the nearest size prefix (kB, MB, GB) and are displayed rounded to the nearest tenth. E.g. the file * size 3292528 bytes will be converted into the string "3.2 MB". * * The prefix units base is 1000 (i.e. 1 kB is 1000 bytes), unless the DGlibFormatSizeFlags::FORMAT_SIZE_IEC_UNITS flag is set. * * \param size A size in bytes. * \param flags Flags to modify the output. * \return A formatted string containing a human readable file size. */ QString DGlibUtils::formatSize(quint64 size, DGlibFormatSizeFlags flags) { unsigned int flagValue = flags; return QString::fromStdString(Glib::format_size(size, static_cast(flagValue))); } gio-qt-0.0.11/qgio-tools/000077500000000000000000000000001402606753700151005ustar00rootroot00000000000000gio-qt-0.0.11/qgio-tools/CMakeLists.txt000066400000000000000000000001541402606753700176400ustar00rootroot00000000000000# QXdgDesktopEntryTest add_executable (qgio-tools main.cpp ) target_link_libraries (qgio-tools gio-qt) gio-qt-0.0.11/qgio-tools/main.cpp000066400000000000000000000151421402606753700165330ustar00rootroot00000000000000/* * Copyright (C) 2019 Deepin Technology Co., Ltd. * * Author: Gary Wang * * Maintainer: Gary Wang * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * 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 Lesser General Public License * along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include int main(int argc, char * argv[]) { qDebug() << DGlibUtils::systemDataDirs(); qDebug() << "----------------------"; DGioFile *networkFile = DGioFile::createFromUri("network:///"); if (networkFile) { QExplicitlySharedDataPointer iter = networkFile->createFileIterator("standard::*,mountable::can-mount"); if (iter) { while (QExplicitlySharedDataPointer fi = iter->nextFile()) { if (fi) { qDebug() << fi->displayName() << fi->fileType(); } } } delete networkFile; } // // Can't do asynchronous next_files() on a file enumerator created synchronously // DGioFile *recentFile1 = DGioFile::createFromUri("recent:///"); // QExplicitlySharedDataPointer iter1; // if (recentFile1) { // iter1 = recentFile1->createFileIterator("standard::*"); // if (iter1) { // iter1->nextFilesAsync(5); // QObject::connect(iter1.data(), &DGioFileIterator::nextFilesReady, [](QList > fileInfoList){ // for (auto fi : fileInfoList) { // qDebug() << "xxxxxx" << fi->displayName() << fi->fileType(); // } // }); // } // } DGioFile *recentFile = DGioFile::createFromUri("recent:///"); QExplicitlySharedDataPointer iter; if (recentFile) { recentFile->createFileIteratorAsync("standard::*"); QObject::connect(recentFile, &DGioFile::createFileIteratorReady, [&iter](QExplicitlySharedDataPointer iterr){ iter = iterr; if (iter) { iter->nextFilesAsync(5); QObject::connect(iter.data(), &DGioFileIterator::nextFilesReady, [](QList > fileInfoList){ for (auto fi : fileInfoList) { qDebug() << "under recent:" << fi->displayName() << fi->fileType(); } }); } }); } qDebug() << "----------------------"; DGioFile * f = DGioFile::createFromPath("/media/wzc/_dde_data"); if (f) { qDebug() << f->basename() << f->path() << f->uri(); QExplicitlySharedDataPointer fi = f->createFileSystemInfo(); if (fi) { qDebug() << fi->fsFreeBytes() << fi->fsUsedBytes() << fi->fsTotalBytes() << fi->fileType() << fi->displayName(); } delete f; } qDebug() << "----------------------"; DGioMount * m = DGioMount::createFromPath("/media/wzc/_dde_data"); if (m) { QExplicitlySharedDataPointer f = m->getRootFile(); QExplicitlySharedDataPointer f2 = m->getDefaultLocationFile(); qDebug() << m->name() << m->themedIconNames() << f->createFileSystemInfo()->fsTotalBytes() << f->uri() << f2->uri(); qDebug() << m->name() << m->themedIconNames() << f->createFileSystemInfo()->fsTotalBytes() << f->uri() << f2->uri(); // m->unmount(); delete m; } qDebug() << "---------mounts-------------"; const QList > mnts = DGioVolumeManager::getMounts(); for (const QExplicitlySharedDataPointer &p : mnts) { QExplicitlySharedDataPointer f = p->getRootFile(); QExplicitlySharedDataPointer f2 = p->getDefaultLocationFile(); qDebug() << f->uri() << f2->uri() << f->path() << f2->path(); qDebug() << f->uri() << f2->uri(); qDebug() << p->name() << p->uuid() << p->mountClass() << p->canUnmount() << p->themedIconNames() << p->themedIconNames(); } qDebug() << "--------volumes--------------"; const QList > vols = DGioVolumeManager::getVolumes(); for (const QExplicitlySharedDataPointer &p : vols) { qDebug() << p->name() << p->volumeClass() << p->volumeMonitorName() << p->identifier(DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_UUID) << p->identifier(DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_CLASS) << p->identifier(DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_LABEL) << p->identifier(DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_NFS_MOUNT) << p->identifier(DGioVolumeIdentifierType::VOLUME_IDENTIFIER_TYPE_UNIX_DEVICE); } qDebug() << "----------drives------------"; const QList > drvs = DGioVolumeManager::getDrives(); for (const QExplicitlySharedDataPointer &p : drvs) { qDebug() << p->name() << p->isRemovable() << p->isMediaRemovable(); } qDebug() << "----------------------"; QCoreApplication app(argc, argv); DGioVolumeManager vm; QObject::connect(&vm, &DGioVolumeManager::mountAdded, [](QExplicitlySharedDataPointer mnt){ qDebug() << "MountAdded" << mnt->name(); }); QObject::connect(&vm, &DGioVolumeManager::mountPreRemoved, [](QExplicitlySharedDataPointer mnt){ qDebug() << "MountPreRemoved" << mnt->name(); }); QObject::connect(&vm, &DGioVolumeManager::mountRemoved, [](QExplicitlySharedDataPointer mnt){ qDebug() << "MountRemoved" << mnt->name(); }); QObject::connect(&vm, &DGioVolumeManager::mountChanged, [](QExplicitlySharedDataPointer mnt){ qDebug() << "MountChanged" << mnt->name(); }); app.exec(); return 0; } gio-qt-0.0.11/test/000077500000000000000000000000001402606753700137625ustar00rootroot00000000000000gio-qt-0.0.11/test/CMakeLists.txt000066400000000000000000000016201402606753700165210ustar00rootroot00000000000000enable_testing () function(DGIO_CREATE_TEST _generated_target_name _input_file_name _use_giomm) set (extra_libraries) if (_use_giomm) list(APPEND extra_libraries ${GIOMM_LIBRARIES}) endif () add_executable (${_generated_target_name} ${_input_file_name} ) add_test (NAME ${_generated_target_name} COMMAND ${_generated_target_name} ) target_link_libraries (${_generated_target_name} gio-qt Qt5::Test ${extra_libraries}) if (_use_giomm) target_include_directories(${_generated_target_name} PRIVATE ${GIOMM_INCLUDE_DIRS}) target_compile_definitions(${_generated_target_name} PRIVATE QT_NO_KEYWORDS) endif () endfunction() # Match GIO Enum dgio_create_test (tst_matchgioenum tst_matchgioenum.cpp YES) # Simple FileInfo dgio_create_test (tst_simplefileinfo tst_simplefileinfo.cpp NO) dgio_create_test (tst_dgiosettings tst_dgiosettings.cpp NO) gio-qt-0.0.11/test/tst_dgiosettings.cpp000066400000000000000000000023671402606753700200730ustar00rootroot00000000000000#include #include #include #include #include "dgiosettings.h" class DGioSettingsTest : public QObject { Q_OBJECT public: DGioSettingsTest() {} private Q_SLOTS: void testCase_Settings() { if (DGioSettings::isSchemaInstalled("com.deepin.dde.appearance") == false) { qWarning() << "com.deepin.dde.appearance" << "invalid"; return; } DGioSettings settings("com.deepin.dde.appearance", this); QVERIFY(settings.value("background-uris").isValid()); QVERIFY(settings.value("extra-picture-uris").isValid()); const QStringList& tmpValue = settings.value("extra-picture-uris").toStringList(); settings.setValue("extra-picture-uris", QStringList()); settings.setValue("extra-picture-uris", QStringList() << "ddd"); settings.sync(); QVERIFY(settings.value("extra-picture-uris").toStringList() == QStringList() << "ddd"); settings.setValue("extra-picture-uris", tmpValue, true); QVERIFY(settings.value("extra-picture-uris").toStringList() == tmpValue); QVERIFY(settings.keys().contains("extra-picture-uris")); } }; QTEST_APPLESS_MAIN(DGioSettingsTest) #include "tst_dgiosettings.moc" gio-qt-0.0.11/test/tst_matchgioenum.cpp000066400000000000000000000042711402606753700200440ustar00rootroot00000000000000#include #include #include #include #include #include #include class DGioMatchGioEnumTest : public QObject { Q_OBJECT public: DGioMatchGioEnumTest(); private Q_SLOTS: void testCase_DGlibUtilsClass(); void testCase_DGioFileClass(); void testCase_DGioFileInfoClass(); void testCase_DGioMountOperationClass(); }; DGioMatchGioEnumTest::DGioMatchGioEnumTest() { // } void DGioMatchGioEnumTest::testCase_DGlibUtilsClass() { QCOMPARE(DGlibFormatSizeFlag::FORMAT_SIZE_DEFAULT, Glib::FORMAT_SIZE_DEFAULT); QCOMPARE(DGlibFormatSizeFlag::FORMAT_SIZE_LONG_FORMAT, Glib::FORMAT_SIZE_LONG_FORMAT); QCOMPARE(DGlibFormatSizeFlag::FORMAT_SIZE_IEC_UNITS, Glib::FORMAT_SIZE_IEC_UNITS); QCOMPARE(DGlibFormatSizeFlag::FORMAT_SIZE_BITS, Glib::FORMAT_SIZE_BITS); } void DGioMatchGioEnumTest::testCase_DGioFileClass() { QCOMPARE(DGioFileQueryInfoFlag::FILE_QUERY_INFO_NONE, Gio::FILE_QUERY_INFO_NONE); QCOMPARE(DGioFileQueryInfoFlag::FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, Gio::FILE_QUERY_INFO_NOFOLLOW_SYMLINKS); } void DGioMatchGioEnumTest::testCase_DGioFileInfoClass() { QCOMPARE(DGioFileType::FILE_TYPE_NOT_KNOWN, Gio::FILE_TYPE_NOT_KNOWN); QCOMPARE(DGioFileType::FILE_TYPE_SYMBOLIC_LINK, Gio::FILE_TYPE_SYMBOLIC_LINK); QCOMPARE(DGioFileType::FILE_TYPE_MOUNTABLE, Gio::FILE_TYPE_MOUNTABLE); } void DGioMatchGioEnumTest::testCase_DGioMountOperationClass() { QCOMPARE(DGioAskPasswordFlag::ASK_PASSWORD_NEED_PASSWORD, Gio::ASK_PASSWORD_NEED_PASSWORD); QCOMPARE(DGioAskPasswordFlag::ASK_PASSWORD_NEED_DOMAIN, Gio::ASK_PASSWORD_NEED_DOMAIN); QCOMPARE(DGioAskPasswordFlag::ASK_PASSWORD_ANONYMOUS_SUPPORTED, Gio::ASK_PASSWORD_ANONYMOUS_SUPPORTED); QCOMPARE(DGioMountOperationResult::MOUNT_OPERATION_ABORTED, Gio::MountOperationResult::MOUNT_OPERATION_ABORTED); QCOMPARE(DGioMountOperationResult::MOUNT_OPERATION_HANDLED, Gio::MountOperationResult::MOUNT_OPERATION_HANDLED); QCOMPARE(DGioMountOperationResult::MOUNT_OPERATION_UNHANDLED, Gio::MountOperationResult::MOUNT_OPERATION_UNHANDLED); } QTEST_APPLESS_MAIN(DGioMatchGioEnumTest) #include "tst_matchgioenum.moc" gio-qt-0.0.11/test/tst_simplefileinfo.cpp000066400000000000000000000020251402606753700203640ustar00rootroot00000000000000#include #include #include #include class DGioSimpleFileInfoTest : public QObject { Q_OBJECT public: DGioSimpleFileInfoTest(); private Q_SLOTS: void testCase_RegularFile(); }; DGioSimpleFileInfoTest::DGioSimpleFileInfoTest() { // } void DGioSimpleFileInfoTest::testCase_RegularFile() { QTemporaryFile tmpFile("test_RegularFile.txt"); QVERIFY(tmpFile.open()); QFileInfo tmpFileInfo(tmpFile); QScopedPointer file(DGioFile::createFromPath(tmpFileInfo.absoluteFilePath())); QExplicitlySharedDataPointer fi = file->createFileInfo(); QCOMPARE(file->basename(), tmpFileInfo.fileName()); QCOMPARE(file->path(), tmpFileInfo.absoluteFilePath()); QCOMPARE(fi->fileSize(), tmpFileInfo.size()); qDebug() << fi->iconString() << fi->contentType(); QVERIFY(fi->themedIconNames().contains("text-plain")); // is this check okay? better approach? } QTEST_APPLESS_MAIN(DGioSimpleFileInfoTest) #include "tst_simplefileinfo.moc"