├── AUTHORS ├── CHANGELOG ├── CMakeLists.txt ├── Doxyfile.in ├── LICENSE ├── LICENSE.BSD-3-Clause ├── README.md ├── cmake └── fm-qt-config.cmake.in ├── data ├── CMakeLists.txt ├── archivers.list ├── libfm-qt6-mimetypes.xml └── terminals.list └── src ├── CMakeLists.txt ├── app-chooser-dialog.ui ├── appchoosercombobox.cpp ├── appchoosercombobox.h ├── appchooserdialog.cpp ├── appchooserdialog.h ├── applaunchcontext.cpp ├── applaunchcontext.h ├── appmenuview.cpp ├── appmenuview.h ├── appmenuview_p.h ├── bookmarkaction.cpp ├── bookmarkaction.h ├── browsehistory.cpp ├── browsehistory.h ├── cachedfoldermodel.cpp ├── cachedfoldermodel.h ├── colorbutton.cpp ├── colorbutton.h ├── core ├── archiver.cpp ├── archiver.h ├── basicfilelauncher.cpp ├── basicfilelauncher.h ├── bookmarks.cpp ├── bookmarks.h ├── cstrptr.h ├── deletejob.cpp ├── deletejob.h ├── dirlistjob.cpp ├── dirlistjob.h ├── filechangeattrjob.cpp ├── filechangeattrjob.h ├── fileinfo.cpp ├── fileinfo.h ├── fileinfo_p.h ├── fileinfojob.cpp ├── fileinfojob.h ├── filelinkjob.cpp ├── filelinkjob.h ├── filemonitor.cpp ├── filemonitor.h ├── fileoperationjob.cpp ├── fileoperationjob.h ├── filepath.cpp ├── filepath.h ├── filesysteminfojob.cpp ├── filesysteminfojob.h ├── filetransferjob.cpp ├── filetransferjob.h ├── folder.cpp ├── folder.h ├── folderconfig.cpp ├── folderconfig.h ├── gioptrs.h ├── gobjectptr.h ├── iconinfo.cpp ├── iconinfo.h ├── iconinfo_p.h ├── job.cpp ├── job.h ├── job_p.h ├── legacy │ ├── fm-app-info.c │ ├── fm-app-info.h │ ├── fm-config.c │ ├── fm-config.h │ └── glib-compat.h ├── mimetype.cpp ├── mimetype.h ├── templates.cpp ├── templates.h ├── terminal.cpp ├── terminal.h ├── thumbnailer.cpp ├── thumbnailer.h ├── thumbnailjob.cpp ├── thumbnailjob.h ├── totalsizejob.cpp ├── totalsizejob.h ├── trashjob.cpp ├── trashjob.h ├── untrashjob.cpp ├── untrashjob.h ├── userinfocache.cpp ├── userinfocache.h ├── vfs │ ├── fm-file.c │ ├── fm-file.h │ ├── fm-xml-file.c │ ├── fm-xml-file.h │ ├── vfs-menu.c │ └── vfs-search.c ├── volumemanager.cpp └── volumemanager.h ├── createnewmenu.cpp ├── createnewmenu.h ├── customaction_p.h ├── customactions ├── fileaction.cpp ├── fileaction.h ├── fileactioncondition.cpp ├── fileactioncondition.h ├── fileactionprofile.cpp └── fileactionprofile.h ├── dirtreemodel.cpp ├── dirtreemodel.h ├── dirtreemodelitem.cpp ├── dirtreemodelitem.h ├── dirtreeview.cpp ├── dirtreeview.h ├── dndactionmenu.cpp ├── dndactionmenu.h ├── dnddest.cpp ├── dnddest.h ├── edit-bookmarks.ui ├── editbookmarksdialog.cpp ├── editbookmarksdialog.h ├── exec-file.ui ├── execfiledialog.cpp ├── execfiledialog_p.h ├── file-operation-dialog.ui ├── file-props.ui ├── filedialog.cpp ├── filedialog.h ├── filedialog.ui ├── filedialog_p.h ├── filedialoghelper.cpp ├── filedialoghelper.h ├── filelauncher.cpp ├── filelauncher.h ├── filemenu.cpp ├── filemenu.h ├── filemenu_p.h ├── fileoperation.cpp ├── fileoperation.h ├── fileoperationdialog.cpp ├── fileoperationdialog.h ├── fileoperationdialog_p.h ├── filepropsdialog.cpp ├── filepropsdialog.h ├── filesearch.ui ├── filesearchdialog.cpp ├── filesearchdialog.h ├── fm-search.c ├── fm-search.h ├── folderitemdelegate.cpp ├── folderitemdelegate.h ├── foldermenu.cpp ├── foldermenu.h ├── foldermodel.cpp ├── foldermodel.h ├── foldermodelitem.cpp ├── foldermodelitem.h ├── folderview.cpp ├── folderview.h ├── folderview_p.h ├── fontbutton.cpp ├── fontbutton.h ├── libfm-qt.pc.in ├── libfmqt.cpp ├── libfmqt.h ├── libfmqtglobals.h ├── mount-operation-password.ui ├── mountoperation.cpp ├── mountoperation.h ├── mountoperationpassworddialog.cpp ├── mountoperationpassworddialog_p.h ├── mountoperationquestiondialog.cpp ├── mountoperationquestiondialog_p.h ├── pathbar.cpp ├── pathbar.h ├── pathbar_p.h ├── pathedit.cpp ├── pathedit.h ├── pathedit_p.h ├── placesmodel.cpp ├── placesmodel.h ├── placesmodelitem.cpp ├── placesmodelitem.h ├── placesview.cpp ├── placesview.h ├── proxyfoldermodel.cpp ├── proxyfoldermodel.h ├── rename-dialog.ui ├── renamedialog.cpp ├── renamedialog.h ├── sidepane.cpp ├── sidepane.h ├── tests ├── test-filedialog.cpp ├── test-folder.cpp ├── test-folderview.cpp ├── test-placesview.cpp └── test-volumemanager.cpp ├── translations ├── CMakeLists.txt ├── libfm-qt.ts ├── libfm-qt_ar.ts ├── libfm-qt_arn.ts ├── libfm-qt_ast.ts ├── libfm-qt_bg.ts ├── libfm-qt_ca.ts ├── libfm-qt_cs.ts ├── libfm-qt_cy.ts ├── libfm-qt_da.ts ├── libfm-qt_de.ts ├── libfm-qt_el.ts ├── libfm-qt_en_GB.ts ├── libfm-qt_es.ts ├── libfm-qt_et.ts ├── libfm-qt_eu.ts ├── libfm-qt_fi.ts ├── libfm-qt_fr.ts ├── libfm-qt_fur.ts ├── libfm-qt_gl.ts ├── libfm-qt_he.ts ├── libfm-qt_hi.ts ├── libfm-qt_hr.ts ├── libfm-qt_hu.ts ├── libfm-qt_id.ts ├── libfm-qt_ie.ts ├── libfm-qt_it.ts ├── libfm-qt_ja.ts ├── libfm-qt_ka.ts ├── libfm-qt_kab.ts ├── libfm-qt_kk.ts ├── libfm-qt_ko.ts ├── libfm-qt_lg.ts ├── libfm-qt_lt.ts ├── libfm-qt_lv.ts ├── libfm-qt_nb_NO.ts ├── libfm-qt_nl.ts ├── libfm-qt_or.ts ├── libfm-qt_pa.ts ├── libfm-qt_pl.ts ├── libfm-qt_pt.ts ├── libfm-qt_pt_BR.ts ├── libfm-qt_ru.ts ├── libfm-qt_si.ts ├── libfm-qt_sk.ts ├── libfm-qt_sl.ts ├── libfm-qt_tr.ts ├── libfm-qt_uk.ts ├── libfm-qt_zh_CN.ts └── libfm-qt_zh_TW.ts ├── utilities.cpp ├── utilities.h ├── utilities_p.h ├── xdndworkaround.cpp └── xdndworkaround.h /AUTHORS: -------------------------------------------------------------------------------- 1 | Upstream Authors: 2 | LXQt team: https://lxqt-project.org/ 3 | Hong Jen Yee (PCMan) 4 | 5 | Copyright: 6 | Copyright (c) 2013-2018 LXQt team 7 | -------------------------------------------------------------------------------- /LICENSE.BSD-3-Clause: -------------------------------------------------------------------------------- 1 | Copyright (c) The Regents of the University of California. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 3. Neither the name of the University nor the names of its contributors 13 | may be used to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libfm-qt 2 | 3 | ## Overview 4 | 5 | libfm-qt is the Qt port of libfm, a library that provides components for building 6 | desktop file managers, belonging to [LXDE](https://lxde.org). 7 | 8 | libfm-qt is licensed under the terms of the 9 | [LGPLv2.1](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html) 10 | or any later version. See file LICENSE for its full text. 11 | 12 | fm-qt-config.cmake.in is licensed under the terms of the 13 | [BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause) 14 | 15 | ## Installation 16 | 17 | ### Compiling source code 18 | 19 | Runtime dependencies are Qt X11 Extras (although libfm-qt works under Wayland too) 20 | and menu-cache (not all libfm features are provided by libfm-qt yet). 21 | Additional build dependencies are CMake, 22 | [lxqt-build-tools](https://github.com/lxqt/lxqt-build-tools),[lxqt-menu-data](https://github.com/lxqt/lxqt-menu-data) and, optionally, Git for pulling latest VCS checkouts. 23 | 24 | Code configuration is handled by CMake. CMake variable `CMAKE_INSTALL_PREFIX` 25 | has to be set to `/usr` on most operating systems. Depending on the way library 26 | paths are dealt with on 64bit systems, variables like `CMAKE_INSTALL_LIBDIR` may 27 | have to be set as well. 28 | 29 | To build run `make`, to install `make install`, which accepts variable `DESTDIR` 30 | as usual. 31 | 32 | ### Binary packages 33 | 34 | Official binary packages are provided by all major Linux and BSD distributions. Just use your package manager to search for string `libfm-qt` 35 | 36 | ## Development 37 | 38 | Issues should go to the tracker of PCManFM-Qt at 39 | https://github.com/lxqt/pcmanfm-qt/issues. 40 | 41 | 42 | ### Translation 43 | 44 | Translations can be done in [LXQt-Weblate](https://translate.lxqt-project.org/projects/lxqt-desktop/libfm-qt/) 45 | 46 | 47 | Translation status 48 | 49 | -------------------------------------------------------------------------------- /cmake/fm-qt-config.cmake.in: -------------------------------------------------------------------------------- 1 | #============================================================================= 2 | # Copyright 2015 Luís Pereira 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions 6 | # are met: 7 | # 8 | # 1. Redistributions of source code must retain the copyright 9 | # notice, this list of conditions and the following disclaimer. 10 | # 2. Redistributions in binary form must reproduce the copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # 3. The name of the author may not be used to endorse or promote products 14 | # derived from this software without specific prior written permission. 15 | # 16 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | #============================================================================= 27 | 28 | @PACKAGE_INIT@ 29 | 30 | if (CMAKE_VERSION VERSION_LESS 3.0.2) 31 | message(FATAL_ERROR \"fm-qt requires at least CMake version 3.0.2\") 32 | endif() 33 | 34 | include(CMakeFindDependencyMacro) 35 | 36 | if (NOT TARGET @LIBFM_QT_LIBRARY_NAME@) 37 | if (POLICY CMP0024) 38 | cmake_policy(SET CMP0024 NEW) 39 | endif() 40 | include("${CMAKE_CURRENT_LIST_DIR}/@LIBFM_QT_LIBRARY_NAME@-targets.cmake") 41 | endif() 42 | -------------------------------------------------------------------------------- /data/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | "archivers.list" 3 | "terminals.list" 4 | DESTINATION "${CMAKE_INSTALL_DATADIR}/libfm-qt6" 5 | ) 6 | 7 | install(FILES 8 | "libfm-qt6-mimetypes.xml" 9 | DESTINATION "${CMAKE_INSTALL_DATADIR}/mime/packages" 10 | ) 11 | -------------------------------------------------------------------------------- /data/libfm-qt6-mimetypes.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Windows installer 19 | Windows 安裝程式 20 | 21 | 22 | 23 | 24 | MS VBScript 25 | 26 | 27 | 28 | 29 | C# source 30 | C# 程式碼 31 | 32 | 33 | 34 | 35 | 應用程式捷徑 36 | 37 | 38 | 39 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /data/terminals.list: -------------------------------------------------------------------------------- 1 | [xterm] 2 | open_arg=-e 3 | noclose_arg=-hold -e 4 | desktop_id=xterm.desktop 5 | 6 | [uxterm] 7 | open_arg=-e 8 | noclose_arg=-hold -e 9 | 10 | [lxterminal] 11 | open_arg=-e 12 | desktop_id=lxterminal.desktop 13 | 14 | [konsole] 15 | open_arg=-e 16 | noclose_arg=--noclose -e 17 | desktop_id=konsole.desktop 18 | 19 | [xfce4-terminal] 20 | open_arg=-x 21 | noclose_arg=--hold -x 22 | desktop_id=xfce4-terminal.desktop 23 | 24 | [terminator] 25 | open_arg=-x 26 | desktop_id=terminator.desktop 27 | 28 | [rxvt] 29 | open_arg=-e 30 | 31 | [urxvt] 32 | open_arg=-e 33 | noclose_arg=-hold -e 34 | desktop_id=rxvt-unicode.desktop 35 | 36 | [eterm] 37 | open_arg=-e 38 | noclose_arg=--pause -e 39 | desktop_id=eterm.desktop 40 | 41 | [gnome-terminal] 42 | open_arg=-x 43 | desktop_id=gnome-terminal.desktop 44 | 45 | [wterm] 46 | open_arg=-e 47 | 48 | [roxterm] 49 | open_arg=-e 50 | desktop_id=roxterm.desktop 51 | 52 | [sakura] 53 | open_arg=-e 54 | desktop_id=sakura.desktop 55 | 56 | [qterminal] 57 | open_arg=-e 58 | desktop_id=qterminal.desktop 59 | 60 | [lilyterm] 61 | open_arg=-e 62 | noclose_arg=--hold -e 63 | desktop_id=lilyterm.desktop 64 | 65 | [urxvtc] 66 | open_arg=-e 67 | noclose_arg=-hold -e 68 | 69 | [terminology] 70 | open_arg=-e 71 | noclose_arg=--hold -e 72 | desktop_id=terminology.desktop 73 | 74 | [termite] 75 | open_arg=-e 76 | noclose_arg=--hold -e 77 | desktop_id=termite.desktop 78 | 79 | [kitty] 80 | noclose_arg=--hold 81 | desktop_id=kitty.desktop 82 | 83 | [st] 84 | open_arg=-e 85 | 86 | [alacritty] 87 | open_arg=-e 88 | noclose_arg=--hold -e 89 | desktop_id=Alacritty.desktop 90 | 91 | [foot] 92 | noclose_arg=--hold 93 | desktop_id=org.codeberg.dnkl.foot.desktop 94 | -------------------------------------------------------------------------------- /src/appchoosercombobox.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_APPCHOOSERCOMBOBOX_H 21 | #define FM_APPCHOOSERCOMBOBOX_H 22 | 23 | #include "libfmqtglobals.h" 24 | #include 25 | 26 | #include 27 | 28 | #include "core/mimetype.h" 29 | #include "core/gioptrs.h" 30 | 31 | namespace Fm { 32 | 33 | class LIBFM_QT_API AppChooserComboBox : public QComboBox { 34 | Q_OBJECT 35 | public: 36 | ~AppChooserComboBox() override; 37 | explicit AppChooserComboBox(QWidget* parent); 38 | 39 | void setMimeType(std::shared_ptr mimeType); 40 | 41 | const std::shared_ptr& mimeType() const { 42 | return mimeType_; 43 | } 44 | 45 | Fm::GAppInfoPtr selectedApp() const; 46 | // const GList* customApps(); 47 | 48 | bool isChanged() const; 49 | 50 | private Q_SLOTS: 51 | void onCurrentIndexChanged(int index); 52 | 53 | private: 54 | std::shared_ptr mimeType_; 55 | std::vector appInfos_; // applications used to open the file type 56 | Fm::GAppInfoPtr defaultApp_; // default application used to open the file type 57 | int defaultAppIndex_; 58 | int prevIndex_; 59 | bool blockOnCurrentIndexChanged_; 60 | }; 61 | 62 | } 63 | 64 | #endif // FM_APPCHOOSERCOMBOBOX_H 65 | -------------------------------------------------------------------------------- /src/appchooserdialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2014 Hong Jen Yee (PCMan) 3 | * Copyright 2012-2013 Andriy Grytsenko (LStranger) 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library; if not, write to the Free Software 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | * 19 | */ 20 | 21 | #ifndef FM_APPCHOOSERDIALOG_H 22 | #define FM_APPCHOOSERDIALOG_H 23 | 24 | #include 25 | #include "libfmqtglobals.h" 26 | 27 | #include "core/mimetype.h" 28 | #include "core/gioptrs.h" 29 | 30 | namespace Ui { 31 | class AppChooserDialog; 32 | } 33 | 34 | namespace Fm { 35 | 36 | class LIBFM_QT_API AppChooserDialog : public QDialog { 37 | Q_OBJECT 38 | public: 39 | explicit AppChooserDialog(std::shared_ptr mimeType, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); 40 | ~AppChooserDialog() override; 41 | 42 | void accept() override; 43 | 44 | void setMimeType(std::shared_ptr mimeType); 45 | 46 | const std::shared_ptr& mimeType() const { 47 | return mimeType_; 48 | } 49 | 50 | void setCanSetDefault(bool value); 51 | 52 | bool canSetDefault() const { 53 | return canSetDefault_; 54 | } 55 | 56 | const Fm::GAppInfoPtr& selectedApp() const { 57 | return selectedApp_; 58 | } 59 | 60 | bool isSetDefault() const; 61 | 62 | private: 63 | GAppInfo* customCommandToApp(); 64 | 65 | private Q_SLOTS: 66 | void onSelectionChanged(); 67 | void onTabChanged(int index); 68 | 69 | private: 70 | Ui::AppChooserDialog* ui; 71 | std::shared_ptr mimeType_; 72 | bool canSetDefault_; 73 | Fm::GAppInfoPtr selectedApp_; 74 | }; 75 | 76 | } 77 | 78 | #endif // FM_APPCHOOSERDIALOG_H 79 | -------------------------------------------------------------------------------- /src/applaunchcontext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #include "applaunchcontext.h" 22 | #include 23 | #include 24 | 25 | typedef struct _FmAppLaunchContext { 26 | GAppLaunchContext parent; 27 | }FmAppLaunchContext; 28 | 29 | G_DEFINE_TYPE(FmAppLaunchContext, fm_app_launch_context, G_TYPE_APP_LAUNCH_CONTEXT) 30 | 31 | static char* fm_app_launch_context_get_display(GAppLaunchContext * /*context*/, GAppInfo * /*info*/, GList * /*files*/) { 32 | if(auto x11NativeInterface = qApp->nativeInterface()) { 33 | Display* dpy = x11NativeInterface->display(); 34 | if(dpy) { 35 | char* xstr = DisplayString(dpy); 36 | return g_strdup(xstr); 37 | } 38 | } 39 | return nullptr; 40 | } 41 | 42 | static char* fm_app_launch_context_get_startup_notify_id(GAppLaunchContext * /*context*/, GAppInfo * /*info*/, GList * /*files*/) { 43 | return nullptr; 44 | } 45 | 46 | static void fm_app_launch_context_class_init(FmAppLaunchContextClass* klass) { 47 | GAppLaunchContextClass* app_launch_class = G_APP_LAUNCH_CONTEXT_CLASS(klass); 48 | app_launch_class->get_display = fm_app_launch_context_get_display; 49 | app_launch_class->get_startup_notify_id = fm_app_launch_context_get_startup_notify_id; 50 | } 51 | 52 | static void fm_app_launch_context_init(FmAppLaunchContext* /*context*/) { 53 | } 54 | 55 | FmAppLaunchContext* fm_app_launch_context_new_for_widget(QWidget* /*widget*/) { 56 | FmAppLaunchContext* context = (FmAppLaunchContext*)g_object_new(FM_TYPE_APP_LAUNCH_CONTEXT, nullptr); 57 | return context; 58 | } 59 | 60 | FmAppLaunchContext* fm_app_launch_context_new() { 61 | FmAppLaunchContext* context = (FmAppLaunchContext*)g_object_new(FM_TYPE_APP_LAUNCH_CONTEXT, nullptr); 62 | return context; 63 | } 64 | -------------------------------------------------------------------------------- /src/applaunchcontext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_APP_LAUNCHCONTEXT_H 22 | #define FM_APP_LAUNCHCONTEXT_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include 27 | 28 | #define FM_TYPE_APP_LAUNCH_CONTEXT (fm_app_launch_context_get_type()) 29 | #define FM_APP_LAUNCH_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\ 30 | FM_TYPE_APP_LAUNCH_CONTEXT, FmAppLaunchContext)) 31 | #define FM_APP_LAUNCH_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),\ 32 | FM_TYPE_APP_LAUNCH_CONTEXT, FmAppLaunchContextClass)) 33 | #define FM_IS_APP_LAUNCH_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),\ 34 | FM_TYPE_APP_LAUNCH_CONTEXT)) 35 | #define FM_IS_APP_LAUNCH_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),\ 36 | FM_TYPE_APP_LAUNCH_CONTEXT)) 37 | #define FM_APP_LAUNCH_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),\ 38 | FM_TYPE_APP_LAUNCH_CONTEXT, FmAppLaunchContextClass)) 39 | 40 | typedef struct _FmAppLaunchContext FmAppLaunchContext; 41 | 42 | typedef struct _FmAppLaunchContextClass { 43 | GAppLaunchContextClass parent; 44 | }FmAppLaunchContextClass; 45 | 46 | FmAppLaunchContext* fm_app_launch_context_new(); 47 | FmAppLaunchContext* fm_app_launch_context_new_for_widget(QWidget* widget); 48 | GType fm_app_launch_context_get_type(); 49 | 50 | #endif // FM_APPLAUNCHCONTEXT_H 51 | -------------------------------------------------------------------------------- /src/appmenuview.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_APPMENUVIEW_H 21 | #define FM_APPMENUVIEW_H 22 | 23 | #include 24 | #include "libfmqtglobals.h" 25 | #include 26 | 27 | #include "core/gioptrs.h" 28 | #include "core/filepath.h" 29 | 30 | class QStandardItemModel; 31 | class QStandardItem; 32 | 33 | namespace Fm { 34 | 35 | class AppMenuViewItem; 36 | 37 | class LIBFM_QT_API AppMenuView : public QTreeView { 38 | Q_OBJECT 39 | public: 40 | explicit AppMenuView(QWidget* parent = nullptr); 41 | ~AppMenuView() override; 42 | 43 | Fm::GAppInfoPtr selectedApp() const; 44 | 45 | const char* selectedAppDesktopId() const; 46 | 47 | QByteArray selectedAppDesktopFilePath() const; 48 | 49 | FilePath selectedAppDesktopPath() const; 50 | 51 | bool isAppSelected() const; 52 | 53 | Q_SIGNALS: 54 | void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override; 55 | 56 | private: 57 | void addMenuItems(QStandardItem* parentItem, MenuCacheDir* dir); 58 | void onMenuCacheReload(MenuCache* mc); 59 | static void _onMenuCacheReload(MenuCache* mc, gpointer user_data) { 60 | static_cast(user_data)->onMenuCacheReload(mc); 61 | } 62 | 63 | AppMenuViewItem* selectedItem() const; 64 | 65 | QModelIndex indexForId(const QByteArray& id, bool isDir, const QModelIndex& index = QModelIndex()) const; 66 | QSet getExpanded(const QModelIndex& index = QModelIndex()) const; 67 | void restoreExpanded(const QSet& expanded, const QModelIndex& index = QModelIndex()); 68 | 69 | private: 70 | // gboolean fm_app_menu_view_is_item_app(, GtkTreeIter* it); 71 | QStandardItemModel* model_; 72 | MenuCache* menu_cache; 73 | MenuCacheNotifyId menu_cache_reload_notify; 74 | }; 75 | 76 | } 77 | 78 | #endif // FM_APPMENUVIEW_H 79 | -------------------------------------------------------------------------------- /src/appmenuview_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_APPMENUVIEW_P_H 21 | #define FM_APPMENUVIEW_P_H 22 | 23 | #include 24 | #include 25 | #include "core/iconinfo.h" 26 | 27 | namespace Fm { 28 | 29 | class AppMenuViewItem : public QStandardItem { 30 | public: 31 | explicit AppMenuViewItem(MenuCacheItem* item): 32 | item_(menu_cache_item_ref(item)) { 33 | std::shared_ptr icon; 34 | if(menu_cache_item_get_icon(item)) { 35 | icon = Fm::IconInfo::fromName(menu_cache_item_get_icon(item)); 36 | } 37 | setText(QString::fromUtf8(menu_cache_item_get_name(item))); 38 | setEditable(false); 39 | setDragEnabled(false); 40 | if(icon) { 41 | setIcon(icon->qicon()); 42 | } 43 | } 44 | 45 | ~AppMenuViewItem() override { 46 | menu_cache_item_unref(item_); 47 | } 48 | 49 | MenuCacheItem* item() { 50 | return item_; 51 | } 52 | 53 | int type() const override { 54 | return menu_cache_item_get_type(item_); 55 | } 56 | 57 | bool isApp() { 58 | return type() == MENU_CACHE_TYPE_APP; 59 | } 60 | 61 | bool isDir() { 62 | return type() == MENU_CACHE_TYPE_DIR; 63 | } 64 | 65 | private: 66 | MenuCacheItem* item_; 67 | }; 68 | 69 | } 70 | 71 | #endif // FM_APPMENUVIEW_P_H 72 | -------------------------------------------------------------------------------- /src/bookmarkaction.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #include "bookmarkaction.h" 22 | 23 | namespace Fm { 24 | 25 | BookmarkAction::BookmarkAction(std::shared_ptr item, QObject* parent): 26 | QAction(parent), 27 | item_(std::move(item)) { 28 | 29 | setText(item_->name()); 30 | } 31 | 32 | } // namespace Fm 33 | -------------------------------------------------------------------------------- /src/bookmarkaction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef BOOKMARKACTION_H 22 | #define BOOKMARKACTION_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include "core/bookmarks.h" 27 | 28 | namespace Fm { 29 | 30 | // action used to create bookmark menu items 31 | class LIBFM_QT_API BookmarkAction : public QAction { 32 | public: 33 | explicit BookmarkAction(std::shared_ptr item, QObject* parent = nullptr); 34 | 35 | const std::shared_ptr& bookmark() const { 36 | return item_; 37 | } 38 | 39 | const Fm::FilePath& path() const { 40 | return item_->path(); 41 | } 42 | 43 | private: 44 | std::shared_ptr item_; 45 | }; 46 | 47 | } 48 | 49 | #endif // BOOKMARKACTION_H 50 | -------------------------------------------------------------------------------- /src/browsehistory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #include "browsehistory.h" 22 | 23 | namespace Fm { 24 | 25 | BrowseHistory::BrowseHistory(): 26 | currentIndex_(0), 27 | maxCount_(10) { 28 | } 29 | 30 | BrowseHistory::~BrowseHistory() { 31 | } 32 | 33 | void BrowseHistory::add(Fm::FilePath path, int scrollPos) { 34 | int lastIndex = items_.size() - 1; 35 | if(currentIndex_ < lastIndex) { 36 | // if we're not at the last item, remove items after the current one. 37 | items_.erase(items_.cbegin() + currentIndex_ + 1, items_.cend()); 38 | } 39 | 40 | if(items_.size() + 1 > static_cast(maxCount_)) { 41 | // if there are too many items, remove the oldest one. 42 | // FIXME: what if currentIndex_ == 0? remove the last item instead? 43 | if(currentIndex_ == 0) { 44 | items_.erase(items_.cbegin() + lastIndex); 45 | } 46 | else { 47 | items_.erase(items_.cbegin()); 48 | --currentIndex_; 49 | } 50 | } 51 | // add a path and current scroll position to browse history 52 | items_.push_back(BrowseHistoryItem(path, scrollPos)); 53 | currentIndex_ = items_.size() - 1; 54 | } 55 | 56 | void BrowseHistory::setCurrentIndex(int index) { 57 | if(index >= 0 && static_cast(index) < items_.size()) { 58 | currentIndex_ = index; 59 | // FIXME: should we emit a signal for the change? 60 | } 61 | } 62 | 63 | bool BrowseHistory::canBackward() const { 64 | return (currentIndex_ > 0); 65 | } 66 | 67 | int BrowseHistory::backward() { 68 | if(canBackward()) { 69 | --currentIndex_; 70 | } 71 | return currentIndex_; 72 | } 73 | 74 | bool BrowseHistory::canForward() const { 75 | return (static_cast(currentIndex_) + 1 < items_.size()); 76 | } 77 | 78 | int BrowseHistory::forward() { 79 | if(canForward()) { 80 | ++currentIndex_; 81 | } 82 | return currentIndex_; 83 | } 84 | 85 | void BrowseHistory::setMaxCount(int maxCount) { 86 | maxCount_ = maxCount; 87 | if(items_.size() > static_cast(maxCount)) { 88 | // TODO: remove some items 89 | } 90 | } 91 | 92 | 93 | } // namespace Fm 94 | -------------------------------------------------------------------------------- /src/browsehistory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_BROWSEHISTORY_H 22 | #define FM_BROWSEHISTORY_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | 27 | #include "core/filepath.h" 28 | 29 | namespace Fm { 30 | 31 | // class used to story browsing history of folder views 32 | // We use this class to replace FmNavHistory provided by libfm since 33 | // the original Libfm API is hard to use and confusing. 34 | 35 | class LIBFM_QT_API BrowseHistoryItem { 36 | public: 37 | 38 | explicit BrowseHistoryItem(): 39 | scrollPos_(0) { 40 | } 41 | 42 | explicit BrowseHistoryItem(Fm::FilePath path, int scrollPos = 0): 43 | path_(std::move(path)), 44 | scrollPos_(scrollPos) { 45 | } 46 | 47 | BrowseHistoryItem(const BrowseHistoryItem& other) = default; 48 | 49 | ~BrowseHistoryItem() { 50 | } 51 | 52 | BrowseHistoryItem& operator=(const BrowseHistoryItem& other) { 53 | path_ = other.path_; 54 | scrollPos_ = other.scrollPos_; 55 | return *this; 56 | } 57 | 58 | Fm::FilePath path() const { 59 | return path_; 60 | } 61 | 62 | int scrollPos() const { 63 | return scrollPos_; 64 | } 65 | 66 | void setScrollPos(int pos) { 67 | scrollPos_ = pos; 68 | } 69 | 70 | private: 71 | Fm::FilePath path_; 72 | int scrollPos_; 73 | // TODO: we may need to store current selection as well. 74 | }; 75 | 76 | class LIBFM_QT_API BrowseHistory { 77 | 78 | public: 79 | BrowseHistory(); 80 | virtual ~BrowseHistory(); 81 | 82 | int currentIndex() const { 83 | return currentIndex_; 84 | } 85 | void setCurrentIndex(int index); 86 | 87 | Fm::FilePath currentPath() const { 88 | return items_[currentIndex_].path(); 89 | } 90 | 91 | int currentScrollPos() const { 92 | return items_[currentIndex_].scrollPos(); 93 | } 94 | 95 | BrowseHistoryItem& currentItem() { 96 | return items_[currentIndex_]; 97 | } 98 | 99 | size_t size() const { 100 | return items_.size(); 101 | } 102 | 103 | BrowseHistoryItem& at(int index) { 104 | return items_[index]; 105 | } 106 | 107 | void add(Fm::FilePath path, int scrollPos = 0); 108 | 109 | bool canForward() const; 110 | 111 | bool canBackward() const; 112 | 113 | int backward(); 114 | 115 | int forward(); 116 | 117 | int maxCount() const { 118 | return maxCount_; 119 | } 120 | 121 | void setMaxCount(int maxCount); 122 | 123 | private: 124 | std::vector items_; 125 | int currentIndex_; 126 | int maxCount_; 127 | }; 128 | 129 | } 130 | 131 | #endif // FM_BROWSEHISTORY_H 132 | -------------------------------------------------------------------------------- /src/cachedfoldermodel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #include "cachedfoldermodel.h" 21 | 22 | namespace Fm { 23 | 24 | CachedFolderModel::CachedFolderModel(const std::shared_ptr& folder): 25 | FolderModel(), 26 | refCount(1) { 27 | FolderModel::setFolder(folder); 28 | } 29 | 30 | CachedFolderModel::~CachedFolderModel() { 31 | // qDebug("delete CachedFolderModel"); 32 | } 33 | 34 | CachedFolderModel* CachedFolderModel::modelFromFolder(const std::shared_ptr& folder) { 35 | QVariant cache = folder->property(cacheKey); 36 | CachedFolderModel* model = cache.value(); 37 | if(model) { 38 | model->ref(); 39 | } 40 | else { 41 | model = new CachedFolderModel(folder); 42 | cache = QVariant::fromValue(model); 43 | folder->setProperty(cacheKey, cache); 44 | } 45 | return model; 46 | } 47 | 48 | CachedFolderModel* CachedFolderModel::modelFromPath(const Fm::FilePath& path) { 49 | auto folder = Fm::Folder::fromPath(path); 50 | if(folder) { 51 | CachedFolderModel* model = modelFromFolder(folder); 52 | return model; 53 | } 54 | return nullptr; 55 | } 56 | 57 | void CachedFolderModel::unref() { 58 | // qDebug("unref cache"); 59 | --refCount; 60 | if(refCount <= 0) { 61 | folder()->setProperty(cacheKey, QVariant()); 62 | delete(this); 63 | } 64 | } 65 | 66 | 67 | } // namespace Fm 68 | -------------------------------------------------------------------------------- /src/cachedfoldermodel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_CACHEDFOLDERMODEL_H 22 | #define FM_CACHEDFOLDERMODEL_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include "foldermodel.h" 26 | 27 | #include "core/folder.h" 28 | 29 | namespace Fm { 30 | 31 | // FIXME: deprecate CachedFolderModel later (ugly API design with manual ref()/unref()) 32 | class LIBFM_QT_API CachedFolderModel : public FolderModel { 33 | Q_OBJECT 34 | public: 35 | explicit CachedFolderModel(const std::shared_ptr& folder); 36 | void ref() { 37 | ++refCount; 38 | } 39 | void unref(); 40 | 41 | static CachedFolderModel* modelFromFolder(const std::shared_ptr& folder); 42 | static CachedFolderModel* modelFromPath(const Fm::FilePath& path); 43 | 44 | private: 45 | ~CachedFolderModel() override; 46 | 47 | private: 48 | int refCount; 49 | constexpr static const char* cacheKey = "CachedFolderModel"; 50 | }; 51 | 52 | 53 | } 54 | 55 | #endif // FM_CACHEDFOLDERMODEL_H 56 | -------------------------------------------------------------------------------- /src/colorbutton.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #include "colorbutton.h" 22 | #include 23 | 24 | namespace Fm { 25 | 26 | ColorButton::ColorButton(QWidget* parent): QPushButton(parent) { 27 | connect(this, &QPushButton::clicked, this, &ColorButton::onClicked); 28 | } 29 | 30 | ColorButton::~ColorButton() { 31 | 32 | } 33 | 34 | void ColorButton::onClicked() { 35 | QColorDialog dlg(color_); 36 | if(dlg.exec() == QDialog::Accepted) { 37 | setColor(dlg.selectedColor()); 38 | } 39 | } 40 | 41 | void ColorButton::setColor(const QColor& color) { 42 | if(color != color_) { 43 | color_ = color; 44 | // use qss instead of QPalette to set the background color 45 | // otherwise, this won't work when using the gtk style. 46 | QString style = QStringLiteral("QPushButton{background-color:%1;}").arg(color.name()); 47 | setStyleSheet(style); 48 | Q_EMIT changed(); 49 | } 50 | } 51 | 52 | 53 | } // namespace Fm 54 | -------------------------------------------------------------------------------- /src/colorbutton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_COLORBUTTON_H 22 | #define FM_COLORBUTTON_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include 27 | 28 | namespace Fm { 29 | 30 | class LIBFM_QT_API ColorButton : public QPushButton { 31 | Q_OBJECT 32 | 33 | public: 34 | explicit ColorButton(QWidget* parent = nullptr); 35 | ~ColorButton() override; 36 | 37 | void setColor(const QColor&); 38 | 39 | QColor color() const { 40 | return color_; 41 | } 42 | 43 | Q_SIGNALS: 44 | void changed(); 45 | 46 | private Q_SLOTS: 47 | void onClicked(); 48 | 49 | private: 50 | QColor color_; 51 | }; 52 | 53 | } 54 | 55 | #endif // FM_COLORBUTTON_H 56 | -------------------------------------------------------------------------------- /src/core/archiver.h: -------------------------------------------------------------------------------- 1 | #ifndef ARCHIVER_H 2 | #define ARCHIVER_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "filepath.h" 6 | #include "gioptrs.h" 7 | 8 | #include 9 | #include 10 | 11 | namespace Fm { 12 | 13 | class LIBFM_QT_API Archiver { 14 | public: 15 | Archiver(); 16 | 17 | bool isMimeTypeSupported(const char* type); 18 | 19 | bool canCreateArchive() const { 20 | return createCmd_ != nullptr; 21 | } 22 | 23 | bool createArchive(GAppLaunchContext* ctx, const FilePathList& files); 24 | 25 | bool canExtractArchives() const { 26 | return extractCmd_ != nullptr; 27 | } 28 | 29 | bool extractArchives(GAppLaunchContext* ctx, const FilePathList& files); 30 | 31 | bool canExtractArchivesTo() const { 32 | return extractToCmd_ != nullptr; 33 | } 34 | 35 | bool extractArchivesTo(GAppLaunchContext* ctx, const FilePathList& files, const FilePath& dest_dir); 36 | 37 | /* get default GUI archivers used by libfm */ 38 | static Archiver* defaultArchiver(); 39 | 40 | /* set default GUI archivers used by libfm */ 41 | static void setDefaultArchiverByName(const char* name); 42 | 43 | /* set default GUI archivers used by libfm */ 44 | static void setDefaultArchiver(Archiver* archiver); 45 | 46 | /* get a list of FmArchiver* of all GUI archivers known to libfm */ 47 | static const std::vector>& allArchivers(); 48 | 49 | const char* program() const { 50 | return program_.get(); 51 | } 52 | 53 | private: 54 | bool launchProgram(GAppLaunchContext* ctx, const char* cmd, const FilePathList& files, const FilePath &dir); 55 | 56 | private: 57 | CStrPtr program_; 58 | CStrPtr createCmd_; 59 | CStrPtr extractCmd_; 60 | CStrPtr extractToCmd_; 61 | CStrArrayPtr mimeTypes_; 62 | 63 | static Archiver* defaultArchiver_; 64 | static std::vector> allArchivers_; 65 | }; 66 | 67 | } // namespace Fm 68 | 69 | #endif // ARCHIVER_H 70 | -------------------------------------------------------------------------------- /src/core/basicfilelauncher.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICFILELAUNCHER_H 2 | #define BASICFILELAUNCHER_H 3 | 4 | #include "../libfmqtglobals.h" 5 | 6 | #include "fileinfo.h" 7 | #include "filepath.h" 8 | #include "mimetype.h" 9 | 10 | #include 11 | 12 | namespace Fm { 13 | 14 | class LIBFM_QT_API BasicFileLauncher { 15 | public: 16 | 17 | enum class ExecAction { 18 | NONE, 19 | DIRECT_EXEC, 20 | EXEC_IN_TERMINAL, 21 | OPEN_WITH_DEFAULT_APP, 22 | CANCEL 23 | }; 24 | 25 | explicit BasicFileLauncher(); 26 | virtual ~BasicFileLauncher(); 27 | 28 | bool launchFiles(const FileInfoList &fileInfos, GAppLaunchContext* ctx = nullptr); 29 | 30 | bool launchPaths(FilePathList paths, GAppLaunchContext* ctx = nullptr); 31 | 32 | bool launchDesktopEntry(const FileInfoPtr &fileInfo, const FilePathList& paths = FilePathList{}, GAppLaunchContext* ctx = nullptr); 33 | 34 | bool launchDesktopEntry(const char* desktopEntryName, const FilePathList& paths = FilePathList{}, GAppLaunchContext* ctx = nullptr); 35 | 36 | bool launchWithDefaultApp(const FileInfoPtr& fileInfo, GAppLaunchContext* ctx = nullptr); 37 | 38 | bool launchWithApp(GAppInfo* app, const FilePathList& paths, GAppLaunchContext* ctx = nullptr); 39 | 40 | bool launchExecutable(const FileInfoPtr &fileInfo, GAppLaunchContext* ctx = nullptr); 41 | 42 | bool quickExec() const { 43 | return quickExec_; 44 | } 45 | 46 | void setQuickExec(bool value) { 47 | quickExec_ = value; 48 | } 49 | 50 | protected: 51 | 52 | virtual GAppInfoPtr chooseApp(const FileInfoList& fileInfos, const char* mimeType, GErrorPtr& err); 53 | 54 | virtual bool openFolder(GAppLaunchContext* ctx, const FileInfoList& folderInfos, GErrorPtr& err); 55 | 56 | virtual bool showError(GAppLaunchContext* ctx, const GErrorPtr& err, const FilePath& path = FilePath{}, const FileInfoPtr& info = FileInfoPtr{}); 57 | 58 | virtual ExecAction askExecFile(const FileInfoPtr& file); 59 | 60 | virtual int ask(const char* msg, char* const* btn_labels, int default_btn); 61 | 62 | private: 63 | 64 | FilePath handleShortcut(const FileInfoPtr &fileInfo, GAppLaunchContext* ctx = nullptr); 65 | 66 | private: 67 | bool quickExec_; // Don't ask options on launch executable file 68 | }; 69 | 70 | } // namespace Fm 71 | 72 | #endif // BASICFILELAUNCHER_H 73 | -------------------------------------------------------------------------------- /src/core/bookmarks.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_BOOKMARKS_H 2 | #define FM2_BOOKMARKS_H 3 | 4 | #include 5 | #include "gobjectptr.h" 6 | #include "filepath.h" 7 | #include "iconinfo.h" 8 | 9 | namespace Fm { 10 | 11 | class LIBFM_QT_API BookmarkItem { 12 | public: 13 | friend class Bookmarks; 14 | 15 | explicit BookmarkItem(const FilePath& path, const QString name); 16 | 17 | const QString& name() const { 18 | return name_; 19 | } 20 | 21 | const FilePath& path() const { 22 | return path_; 23 | } 24 | 25 | const std::shared_ptr& icon() const { 26 | return icon_; 27 | } 28 | 29 | private: 30 | void setName(const QString& name) { 31 | name_ = name; 32 | } 33 | 34 | private: 35 | FilePath path_; 36 | QString name_; 37 | std::shared_ptr icon_; 38 | }; 39 | 40 | 41 | class LIBFM_QT_API Bookmarks : public QObject { 42 | Q_OBJECT 43 | public: 44 | explicit Bookmarks(QObject* parent = nullptr); 45 | 46 | ~Bookmarks() override; 47 | 48 | const FilePath& bookmarksFile() const; 49 | 50 | const std::shared_ptr &insert(const FilePath& path, const QString& name, int pos); 51 | 52 | void remove(const std::shared_ptr& item); 53 | 54 | void reorder(const std::shared_ptr &item, int pos); 55 | 56 | void rename(const std::shared_ptr& item, QString new_name); 57 | 58 | const std::vector>& items() const { 59 | return items_; 60 | } 61 | 62 | static std::shared_ptr globalInstance(); 63 | 64 | Q_SIGNALS: 65 | void changed(); 66 | 67 | private Q_SLOTS: 68 | void save(); 69 | 70 | private: 71 | void load(); 72 | void queueSave(); 73 | 74 | static void _onFileChanged(GFileMonitor* mon, GFile* gf, GFile* other, GFileMonitorEvent evt, Bookmarks* _this) { 75 | _this->onFileChanged(mon, gf, other, evt); 76 | } 77 | void onFileChanged(GFileMonitor* mon, GFile* gf, GFile* other, GFileMonitorEvent evt); 78 | 79 | private: 80 | FilePath file_; 81 | GObjectPtr mon; 82 | std::vector> items_; 83 | static std::weak_ptr globalInstance_; 84 | bool idle_handler; 85 | }; 86 | 87 | } // namespace Fm 88 | 89 | #endif // FM2_BOOKMARKS_H 90 | -------------------------------------------------------------------------------- /src/core/cstrptr.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_CSTRPTR_H 2 | #define FM2_CSTRPTR_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Fm { 8 | 9 | struct CStrDeleter { 10 | void operator()(char* ptr) const { 11 | g_free(ptr); 12 | } 13 | }; 14 | 15 | // smart pointer for C string (char*) which should be freed by free() 16 | typedef std::unique_ptr CStrPtr; 17 | 18 | struct CStrHash { 19 | std::size_t operator()(const char* str) const { 20 | return g_str_hash(str); 21 | } 22 | }; 23 | 24 | struct CStrEqual { 25 | bool operator()(const char* str1, const char* str2) const { 26 | return g_str_equal(str1, str2); 27 | } 28 | }; 29 | 30 | struct CStrVDeleter { 31 | void operator()(char** ptr) const { 32 | g_strfreev(ptr); 33 | } 34 | }; 35 | 36 | // smart pointer for C string array (char**) which should be freed by g_strfreev() of glib 37 | typedef std::unique_ptr CStrArrayPtr; 38 | 39 | 40 | } // namespace Fm 41 | 42 | #endif // FM2_CSTRPTR_H 43 | -------------------------------------------------------------------------------- /src/core/deletejob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_DELETEJOB_H 2 | #define FM2_DELETEJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "fileoperationjob.h" 6 | #include "filepath.h" 7 | #include "gioptrs.h" 8 | 9 | namespace Fm { 10 | 11 | class LIBFM_QT_API DeleteJob : public Fm::FileOperationJob { 12 | Q_OBJECT 13 | public: 14 | explicit DeleteJob(const FilePathList& paths); 15 | 16 | explicit DeleteJob(FilePathList&& paths); 17 | 18 | ~DeleteJob() override; 19 | 20 | protected: 21 | void exec() override; 22 | 23 | private: 24 | bool deleteFile(const FilePath& path, GFileInfoPtr inf); 25 | bool deleteDirContent(const FilePath& path, GFileInfoPtr inf); 26 | 27 | private: 28 | FilePathList paths_; 29 | }; 30 | 31 | } // namespace Fm 32 | 33 | #endif // FM2_DELETEJOB_H 34 | -------------------------------------------------------------------------------- /src/core/dirlistjob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_DIRLISTJOB_H 2 | #define FM2_DIRLISTJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include 6 | #include "job.h" 7 | #include "filepath.h" 8 | #include "gobjectptr.h" 9 | #include "fileinfo.h" 10 | 11 | namespace Fm { 12 | 13 | class LIBFM_QT_API DirListJob : public Job { 14 | Q_OBJECT 15 | public: 16 | enum Flags { 17 | FAST = 0, 18 | DIR_ONLY = 1 << 0, 19 | DETAILED = 1 << 1 20 | }; 21 | 22 | explicit DirListJob(const FilePath& path, Flags flags); 23 | 24 | FileInfoList& files() { 25 | return files_; 26 | } 27 | 28 | void setIncremental(bool set); 29 | 30 | bool incremental() const { 31 | return emit_files_found; 32 | } 33 | 34 | FilePath dirPath() const { 35 | std::lock_guard lock{mutex_}; 36 | return dir_path; 37 | } 38 | 39 | std::shared_ptr dirInfo() const { 40 | std::lock_guard lock{mutex_}; 41 | return dir_fi; 42 | } 43 | 44 | Q_SIGNALS: 45 | void filesFound(FileInfoList& foundFiles); 46 | 47 | protected: 48 | 49 | void exec() override; 50 | 51 | private: 52 | mutable std::mutex mutex_; 53 | FilePath dir_path; 54 | Flags flags; 55 | std::shared_ptr dir_fi; 56 | FileInfoList files_; 57 | bool emit_files_found; 58 | // guint delay_add_files_handler; 59 | // GSList* files_to_add; 60 | }; 61 | 62 | } // namespace Fm 63 | 64 | #endif // FM2_DIRLISTJOB_H 65 | -------------------------------------------------------------------------------- /src/core/fileinfo_p.h: -------------------------------------------------------------------------------- 1 | #ifndef FILEINFO_P_H 2 | #define FILEINFO_P_H 3 | 4 | namespace Fm { 5 | 6 | extern const char defaultGFileInfoQueryAttribs[]; 7 | 8 | } // namespace Fm 9 | 10 | #endif // FILEINFO_P_H 11 | -------------------------------------------------------------------------------- /src/core/fileinfojob.cpp: -------------------------------------------------------------------------------- 1 | #include "fileinfojob.h" 2 | #include "fileinfo_p.h" 3 | 4 | namespace Fm { 5 | 6 | FileInfoJob::FileInfoJob(FilePathList paths): 7 | Job(), 8 | paths_{std::move(paths)} { 9 | } 10 | 11 | void FileInfoJob::exec() { 12 | for(const auto& path: paths_) { 13 | if(isCancelled()) { 14 | break; 15 | } 16 | currentPath_ = path; 17 | 18 | bool retry; 19 | do { 20 | retry = false; 21 | GErrorPtr err; 22 | GFileInfoPtr inf{ 23 | g_file_query_info(path.gfile().get(), defaultGFileInfoQueryAttribs, 24 | G_FILE_QUERY_INFO_NONE, cancellable().get(), &err), 25 | false 26 | }; 27 | if(inf) { 28 | auto fileInfoPtr = std::make_shared(inf, path); 29 | results_.push_back(fileInfoPtr); 30 | Q_EMIT gotInfo(path, results_.back()); 31 | } 32 | else { 33 | auto act = emitError(err); 34 | if(act == Job::ErrorAction::RETRY) { 35 | retry = true; 36 | } 37 | } 38 | } while(retry && !isCancelled()); 39 | } 40 | } 41 | 42 | } // namespace Fm 43 | -------------------------------------------------------------------------------- /src/core/fileinfojob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_FILEINFOJOB_H 2 | #define FM2_FILEINFOJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "job.h" 6 | #include "filepath.h" 7 | #include "fileinfo.h" 8 | 9 | namespace Fm { 10 | 11 | 12 | class LIBFM_QT_API FileInfoJob : public Job { 13 | Q_OBJECT 14 | public: 15 | 16 | explicit FileInfoJob(FilePathList paths); 17 | 18 | const FilePathList& paths() const { 19 | return paths_; 20 | } 21 | 22 | const FileInfoList& files() const { 23 | return results_; 24 | } 25 | 26 | const FilePath& currentPath() const { 27 | return currentPath_; 28 | } 29 | 30 | Q_SIGNALS: 31 | void gotInfo(const FilePath& path, std::shared_ptr& info); 32 | 33 | protected: 34 | void exec() override; 35 | 36 | private: 37 | FilePathList paths_; 38 | FileInfoList results_; 39 | FilePath currentPath_; 40 | }; 41 | 42 | } // namespace Fm 43 | 44 | #endif // FM2_FILEINFOJOB_H 45 | -------------------------------------------------------------------------------- /src/core/filelinkjob.cpp: -------------------------------------------------------------------------------- 1 | #include "filelinkjob.h" 2 | 3 | namespace Fm { 4 | 5 | FileLinkJob::FileLinkJob() { 6 | 7 | } 8 | 9 | } // namespace Fm 10 | -------------------------------------------------------------------------------- /src/core/filelinkjob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_FILELINKJOB_H 2 | #define FM2_FILELINKJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "fileoperationjob.h" 6 | 7 | namespace Fm { 8 | 9 | class LIBFM_QT_API FileLinkJob : public Fm::FileOperationJob { 10 | public: 11 | explicit FileLinkJob(); 12 | }; 13 | 14 | } // namespace Fm 15 | 16 | #endif // FM2_FILELINKJOB_H 17 | -------------------------------------------------------------------------------- /src/core/filemonitor.cpp: -------------------------------------------------------------------------------- 1 | #include "filemonitor.h" 2 | 3 | namespace Fm { 4 | 5 | FileMonitor::FileMonitor() { 6 | 7 | } 8 | 9 | } // namespace Fm 10 | -------------------------------------------------------------------------------- /src/core/filemonitor.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_FILEMONITOR_H 2 | #define FM2_FILEMONITOR_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include 6 | #include "gioptrs.h" 7 | #include "filepath.h" 8 | 9 | namespace Fm { 10 | 11 | class LIBFM_QT_API FileMonitor: public QObject { 12 | Q_OBJECT 13 | public: 14 | 15 | explicit FileMonitor(); 16 | 17 | Q_SIGNALS: 18 | 19 | 20 | private: 21 | GFileMonitorPtr monitor_; 22 | }; 23 | 24 | } // namespace Fm 25 | 26 | #endif // FM2_FILEMONITOR_H 27 | -------------------------------------------------------------------------------- /src/core/fileoperationjob.cpp: -------------------------------------------------------------------------------- 1 | #include "fileoperationjob.h" 2 | 3 | namespace Fm { 4 | 5 | FileOperationJob::FileOperationJob(): 6 | hasTotalAmount_{false}, 7 | calcProgressUsingSize_{true}, 8 | totalSize_{0}, 9 | totalCount_{0}, 10 | finishedSize_{0}, 11 | finishedCount_{0}, 12 | currentFileSize_{0}, 13 | currentFileFinished_{0} { 14 | } 15 | 16 | bool FileOperationJob::totalAmount(uint64_t& fileSize, uint64_t& fileCount) const { 17 | std::lock_guard lock{mutex_}; 18 | if(hasTotalAmount_) { 19 | fileSize = totalSize_; 20 | fileCount = totalCount_; 21 | } 22 | return hasTotalAmount_; 23 | } 24 | 25 | bool FileOperationJob::currentFileProgress(FilePath& path, uint64_t& totalSize, uint64_t& finishedSize) const { 26 | std::lock_guard lock{mutex_}; 27 | if(currentFile_.isValid()) { 28 | path = currentFile_; 29 | totalSize = currentFileSize_; 30 | finishedSize = currentFileFinished_; 31 | } 32 | return currentFile_.isValid(); 33 | } 34 | 35 | double FileOperationJob::progress() const { 36 | std::lock_guard lock{mutex_}; 37 | double finishedRatio; 38 | if(calcProgressUsingSize_) { 39 | finishedRatio = totalSize_ > 0 ? double(finishedSize_ + currentFileFinished_) / totalSize_ : 0.0; 40 | } 41 | else { 42 | finishedRatio = totalCount_ > 0 ? double(finishedCount_) / totalCount_ : 0.0; 43 | } 44 | 45 | if(finishedRatio > 1.0) { 46 | finishedRatio = 1.0; 47 | } 48 | return finishedRatio; 49 | } 50 | 51 | FileOperationJob::FileExistsAction FileOperationJob::askRename(const FileInfo &src, const FileInfo &dest, FilePath &newDest) { 52 | FileExistsAction action = SKIP; 53 | Q_EMIT fileExists(src, dest, action, newDest); 54 | return action; 55 | } 56 | 57 | bool FileOperationJob::finishedAmount(uint64_t& finishedSize, uint64_t& finishedCount) const { 58 | std::lock_guard lock{mutex_}; 59 | if(hasTotalAmount_) { 60 | finishedSize = finishedSize_; 61 | finishedCount = finishedCount_; 62 | } 63 | return hasTotalAmount_; 64 | } 65 | 66 | void FileOperationJob::setTotalAmount(uint64_t fileSize, uint64_t fileCount) { 67 | std::lock_guard lock{mutex_}; 68 | hasTotalAmount_ = true; 69 | totalSize_ = fileSize; 70 | totalCount_ = fileCount; 71 | } 72 | 73 | void FileOperationJob::setFinishedAmount(uint64_t finishedSize, uint64_t finishedCount) { 74 | std::lock_guard lock{mutex_}; 75 | finishedSize_ = finishedSize; 76 | finishedCount_ = finishedCount; 77 | } 78 | 79 | void FileOperationJob::addFinishedAmount(uint64_t finishedSize, uint64_t finishedCount) { 80 | std::lock_guard lock{mutex_}; 81 | finishedSize_ += finishedSize; 82 | finishedCount_ += finishedCount; 83 | } 84 | 85 | FilePath FileOperationJob::currentFile() const { 86 | std::lock_guard lock{mutex_}; 87 | auto ret = currentFile_; 88 | return ret; 89 | } 90 | 91 | void FileOperationJob::setCurrentFile(const FilePath& path) { 92 | std::lock_guard lock{mutex_}; 93 | currentFile_ = path; 94 | } 95 | 96 | void FileOperationJob::setCurrentFileProgress(uint64_t totalSize, uint64_t finishedSize) { 97 | std::lock_guard lock{mutex_}; 98 | currentFileSize_ = totalSize; 99 | currentFileFinished_ = finishedSize; 100 | } 101 | 102 | } // namespace Fm 103 | -------------------------------------------------------------------------------- /src/core/fileoperationjob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_FILEOPERATIONJOB_H 2 | #define FM2_FILEOPERATIONJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "job.h" 6 | #include 7 | #include 8 | #include 9 | #include "fileinfo.h" 10 | #include "filepath.h" 11 | 12 | namespace Fm { 13 | 14 | class LIBFM_QT_API FileOperationJob : public Fm::Job { 15 | Q_OBJECT 16 | public: 17 | enum FileExistsAction { 18 | CANCEL = 0, 19 | OVERWRITE = 1<<0, 20 | RENAME = 1<<1, 21 | SKIP = 1<<2, 22 | SKIP_ERROR = 1<<3 23 | }; 24 | 25 | explicit FileOperationJob(); 26 | 27 | // get total amount of work to do 28 | bool totalAmount(std::uint64_t& fileSize, std::uint64_t& fileCount) const; 29 | 30 | // get currently finished job amount 31 | bool finishedAmount(std::uint64_t& finishedSize, std::uint64_t& finishedCount) const; 32 | 33 | // get the current file 34 | FilePath currentFile() const; 35 | 36 | // get progress of the current file 37 | bool currentFileProgress(FilePath& path, std::uint64_t& totalSize, std::uint64_t& finishedSize) const; 38 | 39 | // is the job calculate progress based on file size or file counts 40 | bool calcProgressUsingSize() const { 41 | return calcProgressUsingSize_; 42 | } 43 | 44 | // get currently finished amount (0.0 to 1.0) 45 | virtual double progress() const; 46 | 47 | Q_SIGNALS: 48 | 49 | void preparedToRun(); 50 | 51 | // void currentFile(const char* file); 52 | 53 | // void progress(uint32_t percent); 54 | 55 | // to correctly handle the signal, connect with Qt::BlockingQueuedConnection so it's a sync call. 56 | void fileExists(const FileInfo& src, const FileInfo& dest, FileExistsAction& response, FilePath& newDest); 57 | 58 | protected: 59 | 60 | FileExistsAction askRename(const FileInfo& src, const FileInfo& dest, FilePath& newDest); 61 | 62 | void setTotalAmount(std::uint64_t fileSize, std::uint64_t fileCount); 63 | 64 | void setFinishedAmount(std::uint64_t finishedSize, std::uint64_t finishedCount); 65 | 66 | void addFinishedAmount(std::uint64_t finishedSize, std::uint64_t finishedCount); 67 | 68 | void setCurrentFile(const FilePath &path); 69 | 70 | void setCurrentFileProgress(uint64_t totalSize, uint64_t finishedSize); 71 | 72 | void setCalcProgressUsingSize(bool value) { 73 | calcProgressUsingSize_ = value; 74 | } 75 | 76 | std::mutex& mutex() { 77 | return mutex_; 78 | } 79 | 80 | private: 81 | bool hasTotalAmount_; 82 | bool calcProgressUsingSize_; 83 | std::uint64_t totalSize_; 84 | std::uint64_t totalCount_; 85 | std::uint64_t finishedSize_; 86 | std::uint64_t finishedCount_; 87 | 88 | FilePath currentFile_; 89 | std::uint64_t currentFileSize_; 90 | std::uint64_t currentFileFinished_; 91 | mutable std::mutex mutex_; 92 | }; 93 | 94 | } // namespace Fm 95 | 96 | #endif // FM2_FILEOPERATIONJOB_H 97 | -------------------------------------------------------------------------------- /src/core/filepath.cpp: -------------------------------------------------------------------------------- 1 | #include "filepath.h" 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Fm { 7 | 8 | FilePath FilePath::homeDir_; 9 | 10 | const FilePath &FilePath::homeDir() { 11 | if(!homeDir_) { 12 | const char* home = getenv("HOME"); 13 | if(!home) { 14 | home = g_get_home_dir(); 15 | } 16 | homeDir_ = FilePath::fromLocalPath(home); 17 | } 18 | return homeDir_; 19 | } 20 | 21 | } // namespace Fm 22 | -------------------------------------------------------------------------------- /src/core/filesysteminfojob.cpp: -------------------------------------------------------------------------------- 1 | #include "filesysteminfojob.h" 2 | #include "gobjectptr.h" 3 | 4 | namespace Fm { 5 | 6 | void FileSystemInfoJob::exec() { 7 | GObjectPtr inf = GObjectPtr{ 8 | g_file_query_filesystem_info( 9 | path_.gfile().get(), 10 | G_FILE_ATTRIBUTE_FILESYSTEM_SIZE"," 11 | G_FILE_ATTRIBUTE_FILESYSTEM_FREE, 12 | cancellable().get(), nullptr), 13 | false 14 | }; 15 | if(!inf) 16 | return; 17 | if(g_file_info_has_attribute(inf.get(), G_FILE_ATTRIBUTE_FILESYSTEM_SIZE)) { 18 | size_ = g_file_info_get_attribute_uint64(inf.get(), G_FILE_ATTRIBUTE_FILESYSTEM_SIZE); 19 | freeSize_ = g_file_info_get_attribute_uint64(inf.get(), G_FILE_ATTRIBUTE_FILESYSTEM_FREE); 20 | isAvailable_ = true; 21 | } 22 | } 23 | 24 | } // namespace Fm 25 | -------------------------------------------------------------------------------- /src/core/filesysteminfojob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_FILESYSTEMINFOJOB_H 2 | #define FM2_FILESYSTEMINFOJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "job.h" 6 | #include "filepath.h" 7 | 8 | namespace Fm { 9 | 10 | class LIBFM_QT_API FileSystemInfoJob : public Job { 11 | Q_OBJECT 12 | public: 13 | explicit FileSystemInfoJob(const FilePath& path): 14 | path_{path}, 15 | isAvailable_{false}, 16 | size_{0}, 17 | freeSize_{0} { 18 | } 19 | 20 | bool isAvailable() const { 21 | return isAvailable_; 22 | } 23 | 24 | uint64_t size() const { 25 | return size_; 26 | } 27 | 28 | uint64_t freeSize() const { 29 | return freeSize_; 30 | } 31 | 32 | protected: 33 | 34 | void exec() override; 35 | 36 | private: 37 | FilePath path_; 38 | bool isAvailable_; 39 | uint64_t size_; 40 | uint64_t freeSize_; 41 | }; 42 | 43 | } // namespace Fm 44 | 45 | #endif // FM2_FILESYSTEMINFOJOB_H 46 | -------------------------------------------------------------------------------- /src/core/filetransferjob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_COPYJOB_H 2 | #define FM2_COPYJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "fileoperationjob.h" 6 | #include "gioptrs.h" 7 | 8 | namespace Fm { 9 | 10 | class LIBFM_QT_API FileTransferJob : public Fm::FileOperationJob { 11 | Q_OBJECT 12 | public: 13 | 14 | enum class Mode { 15 | COPY, 16 | MOVE, 17 | LINK 18 | }; 19 | 20 | explicit FileTransferJob(FilePathList srcPaths, Mode mode = Mode::COPY); 21 | explicit FileTransferJob(FilePathList srcPaths, FilePathList destPaths, Mode mode = Mode::COPY); 22 | explicit FileTransferJob(FilePathList srcPaths, const FilePath &destDirPath, Mode mode = Mode::COPY); 23 | 24 | void setSrcPaths(FilePathList srcPaths); 25 | void setDestPaths(FilePathList destPaths); 26 | void setDestDirPath(const FilePath &destDirPath); 27 | 28 | protected: 29 | void exec() override; 30 | 31 | private: 32 | bool processPath(const FilePath& srcPath, const FilePath& destPath, const char *destFileName); 33 | bool moveFile(const FilePath &srcPath, const GFileInfoPtr &srcInfo, const FilePath &destDirPath, const char *destFileName); 34 | bool copyFile(const FilePath &srcPath, const GFileInfoPtr &srcInfo, const FilePath &destDirPath, const char *destFileName, bool skip = false); 35 | bool linkFile(const FilePath &srcPath, const GFileInfoPtr &srcInfo, const FilePath &destDirPath, const char *destFileName); 36 | 37 | bool moveFileSameFs(const FilePath &srcPath, const GFileInfoPtr& srcInfo, FilePath &destPath); 38 | bool copyRegularFile(const FilePath &srcPath, const GFileInfoPtr& srcInfo, FilePath &destPath); 39 | bool copySpecialFile(const FilePath &srcPath, const GFileInfoPtr& srcInfo, FilePath& destPath); 40 | bool copyDirContent(const FilePath &srcPath, GFileInfoPtr srcInfo, FilePath &destPath, bool skip = false); 41 | bool makeDir(const FilePath &srcPath, GFileInfoPtr srcInfo, FilePath &destPath); 42 | bool createSymlink(const FilePath &srcPath, const GFileInfoPtr& srcInfo, FilePath& destPath); 43 | bool createShortcut(const FilePath &srcPath, const GFileInfoPtr& srcInfo, FilePath& destPath); 44 | 45 | bool handleError(GErrorPtr& err, const FilePath &srcPath, const GFileInfoPtr &srcInfo, FilePath &destPath, int& flags); 46 | 47 | static void gfileCopyProgressCallback(goffset current_num_bytes, goffset total_num_bytes, FileTransferJob* _this); 48 | 49 | private: 50 | FilePathList srcPaths_; 51 | FilePathList destPaths_; 52 | Mode mode_; 53 | bool hasDestDirPath_; 54 | }; 55 | 56 | 57 | } // namespace Fm 58 | 59 | #endif // FM2_COPYJOB_H 60 | -------------------------------------------------------------------------------- /src/core/folderconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef FOLDERCONFIG_H 2 | #define FOLDERCONFIG_H 3 | 4 | #include "../libfmqtglobals.h" 5 | 6 | #include "filepath.h" 7 | #include "gioptrs.h" 8 | 9 | #include 10 | 11 | namespace Fm { 12 | 13 | class LIBFM_QT_API FolderConfig { 14 | public: 15 | FolderConfig(); 16 | 17 | explicit FolderConfig(const Fm::FilePath& path); 18 | 19 | ~FolderConfig(); 20 | 21 | bool open(const Fm::FilePath& path); 22 | 23 | bool close(GErrorPtr& err); 24 | 25 | bool isOpened() const; 26 | 27 | void purge(void); 28 | 29 | void removeKey(const char* key); 30 | 31 | void setStringList(const char* key, const gchar* const list[], gsize length); 32 | 33 | void setString(const char* key, const char* string); 34 | 35 | void setBoolean(const char* key, bool val); 36 | 37 | void setDouble(const char* key, double val); 38 | 39 | void setUint64(const char* key, std::uint64_t val); 40 | 41 | void setInteger(const char* key, int val); 42 | 43 | char** getStringList(const char* key, gsize* length); 44 | 45 | char* getString(const char* key); 46 | 47 | bool getBoolean(const char* key, bool* val); 48 | 49 | bool getDouble(const char* key, double* val); 50 | 51 | bool getUint64(const char* key, std::uint64_t* val); 52 | 53 | bool getInteger(const char* key, int* val); 54 | 55 | bool isEmpty(void); 56 | 57 | // this needs to be called before using Fm::FolderConfig 58 | static void init(const char* globalConfigFile); 59 | 60 | static void finalize(); 61 | 62 | static void saveCache(void); 63 | 64 | // the object cannot be copied. 65 | private: 66 | FolderConfig(const FolderConfig& other) = delete; 67 | FolderConfig& operator=(const FolderConfig& other) = delete; 68 | 69 | private: 70 | GKeyFile *keyFile_; 71 | CStrPtr group_; /* allocated if not in cache */ 72 | CStrPtr configFilePath_; /* NULL if in cache */ 73 | bool changed_; 74 | 75 | static CStrPtr globalConfigFile_; 76 | }; 77 | 78 | } // namespace Fm 79 | 80 | #endif // FOLDERCONFIG_H 81 | -------------------------------------------------------------------------------- /src/core/gioptrs.h: -------------------------------------------------------------------------------- 1 | #ifndef GIOPTRS_H 2 | #define GIOPTRS_H 3 | // define smart pointers for GIO data types 4 | 5 | #include 6 | #include 7 | #include "gobjectptr.h" 8 | #include "cstrptr.h" 9 | 10 | namespace Fm { 11 | 12 | typedef GObjectPtr GFilePtr; 13 | typedef GObjectPtr GFileInfoPtr; 14 | typedef GObjectPtr GFileMonitorPtr; 15 | typedef GObjectPtr GCancellablePtr; 16 | typedef GObjectPtr GFileEnumeratorPtr; 17 | 18 | typedef GObjectPtr GInputStreamPtr; 19 | typedef GObjectPtr GFileInputStreamPtr; 20 | typedef GObjectPtr GOutputStreamPtr; 21 | typedef GObjectPtr GFileOutputStreamPtr; 22 | 23 | typedef GObjectPtr GIconPtr; 24 | 25 | typedef GObjectPtr GVolumeMonitorPtr; 26 | typedef GObjectPtr GVolumePtr; 27 | typedef GObjectPtr GMountPtr; 28 | 29 | typedef GObjectPtr GAppInfoPtr; 30 | 31 | 32 | class GErrorPtr { 33 | public: 34 | GErrorPtr(): err_{nullptr} { 35 | } 36 | 37 | GErrorPtr(GError*&& err) noexcept: err_{err} { 38 | err = nullptr; 39 | } 40 | 41 | GErrorPtr(const GErrorPtr& other) = delete; 42 | 43 | GErrorPtr(GErrorPtr&& other) noexcept: err_{other.err_} { 44 | other.err_ = nullptr; 45 | } 46 | 47 | GErrorPtr(std::uint32_t domain, unsigned int code, const char* msg): 48 | GErrorPtr{g_error_new_literal(domain, code, msg)} { 49 | } 50 | 51 | GErrorPtr(std::uint32_t domain, unsigned int code, const QString& msg): 52 | GErrorPtr{domain, code, msg.toUtf8().constData()} { 53 | } 54 | 55 | ~GErrorPtr() { 56 | reset(); 57 | } 58 | 59 | std::uint32_t domain() const { 60 | if(err_ != nullptr) { 61 | return err_->domain; 62 | } 63 | return 0; 64 | } 65 | 66 | unsigned int code() const { 67 | if(err_ != nullptr) { 68 | return err_->code; 69 | } 70 | return 0; 71 | } 72 | 73 | QString message() const { 74 | if(err_ != nullptr) { 75 | return QString::fromUtf8(err_->message); 76 | } 77 | return QString(); 78 | } 79 | 80 | void reset() { 81 | if(err_) { 82 | g_error_free(err_); 83 | } 84 | err_ = nullptr; 85 | } 86 | 87 | GError* get() const { 88 | return err_; 89 | } 90 | 91 | GErrorPtr& operator = (const GErrorPtr& other) = delete; 92 | 93 | GErrorPtr& operator = (GErrorPtr&& other) noexcept { 94 | reset(); 95 | err_ = other.err_; 96 | other.err_ = nullptr; 97 | return *this; 98 | } 99 | 100 | GErrorPtr& operator = (GError*&& err) { 101 | reset(); 102 | err_ = err; 103 | return *this; 104 | } 105 | 106 | GError** operator&() { 107 | return &err_; 108 | } 109 | 110 | GError* operator->() { 111 | return err_; 112 | } 113 | 114 | const GError* operator->() const { 115 | return err_; 116 | } 117 | 118 | bool operator == (const GErrorPtr& other) const { 119 | return err_ == other.err_; 120 | } 121 | 122 | bool operator == (GError* err) const { 123 | return err_ == err; 124 | } 125 | 126 | bool operator != (std::nullptr_t) const { 127 | return err_ != nullptr; 128 | } 129 | 130 | operator bool() const { 131 | return err_ != nullptr; 132 | } 133 | 134 | private: 135 | GError* err_; 136 | }; 137 | 138 | } //namespace Fm 139 | 140 | #endif // GIOPTRS_H 141 | -------------------------------------------------------------------------------- /src/core/gobjectptr.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_GOBJECTPTR_H 2 | #define FM2_GOBJECTPTR_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Fm { 11 | 12 | template 13 | class LIBFM_QT_API GObjectPtr { 14 | public: 15 | 16 | explicit GObjectPtr(): gobj_{nullptr} { 17 | } 18 | 19 | explicit GObjectPtr(T* gobj, bool add_ref = true): gobj_{gobj} { 20 | if(gobj_ != nullptr && add_ref) 21 | g_object_ref(gobj_); 22 | } 23 | 24 | GObjectPtr(const GObjectPtr& other): gobj_{other.gobj_ ? reinterpret_cast(g_object_ref(other.gobj_)) : nullptr} { 25 | } 26 | 27 | GObjectPtr(GObjectPtr&& other) noexcept: gobj_{other.release()} { 28 | } 29 | 30 | ~GObjectPtr() { 31 | if(gobj_ != nullptr) 32 | g_object_unref(gobj_); 33 | } 34 | 35 | T* get() const { 36 | return gobj_; 37 | } 38 | 39 | T* release() { 40 | T* tmp = gobj_; 41 | gobj_ = nullptr; 42 | return tmp; 43 | } 44 | 45 | void reset() { 46 | if(gobj_ != nullptr) 47 | g_object_unref(gobj_); 48 | gobj_ = nullptr; 49 | } 50 | 51 | GObjectPtr& operator = (const GObjectPtr& other) { 52 | if (*this == other) 53 | return *this; 54 | 55 | if(gobj_ != nullptr) 56 | g_object_unref(gobj_); 57 | gobj_ = other.gobj_ ? reinterpret_cast(g_object_ref(other.gobj_)) : nullptr; 58 | return *this; 59 | } 60 | 61 | GObjectPtr& operator = (GObjectPtr&& other) noexcept { 62 | if (this == &other) 63 | return *this; 64 | 65 | if(gobj_ != nullptr) 66 | g_object_unref(gobj_); 67 | gobj_ = other.release(); 68 | return *this; 69 | } 70 | 71 | GObjectPtr& operator = (T* gobj) { 72 | if (*this == gobj) 73 | return *this; 74 | 75 | if(gobj_ != nullptr) 76 | g_object_unref(gobj_); 77 | gobj_ = gobj ? reinterpret_cast(g_object_ref(gobj)) : nullptr; 78 | return *this; 79 | } 80 | 81 | bool operator == (const GObjectPtr& other) const { 82 | return gobj_ == other.gobj_; 83 | } 84 | 85 | bool operator == (T* gobj) const { 86 | return gobj_ == gobj; 87 | } 88 | 89 | bool operator != (std::nullptr_t) const { 90 | return gobj_ != nullptr; 91 | } 92 | 93 | operator bool() const { 94 | return gobj_ != nullptr; 95 | } 96 | 97 | private: 98 | mutable T* gobj_; 99 | }; 100 | 101 | 102 | } // namespace Fm 103 | 104 | #endif // FM2_GOBJECTPTR_H 105 | -------------------------------------------------------------------------------- /src/core/iconinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fm-icon.h 3 | * 4 | * Copyright 2009 Hong Jen Yee (PCMan) 5 | * Copyright 2013 Andriy Grytsenko (LStranger) 6 | * 7 | * This file is a part of the Libfm library. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | 25 | #ifndef __FM2_ICON_INFO_H__ 26 | #define __FM2_ICON_INFO_H__ 27 | 28 | #include "../libfmqtglobals.h" 29 | #include 30 | #include "gioptrs.h" 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | namespace Fm { 39 | 40 | class LIBFM_QT_API IconInfo: public std::enable_shared_from_this { 41 | public: 42 | friend class IconEngine; 43 | 44 | explicit IconInfo() {} 45 | 46 | explicit IconInfo(const char* name); 47 | 48 | explicit IconInfo(const GIconPtr gicon); 49 | 50 | ~IconInfo(); 51 | 52 | static std::shared_ptr fromName(const char* name); 53 | 54 | static std::shared_ptr fromGIcon(GIconPtr gicon); 55 | 56 | static std::shared_ptr fromGIcon(GIcon* gicon) { 57 | return fromGIcon(GIconPtr{gicon, true}); 58 | } 59 | 60 | static void updateQIcons(); 61 | 62 | GIconPtr gicon() const { 63 | return gicon_; 64 | } 65 | 66 | QIcon qicon() const; 67 | 68 | bool hasEmblems() const { 69 | return G_IS_EMBLEMED_ICON(gicon_.get()); 70 | } 71 | 72 | std::forward_list> emblems() const; 73 | 74 | bool isValid() const { 75 | return gicon_ != nullptr; 76 | } 77 | 78 | private: 79 | 80 | static QList qiconsFromNames(const char* const* names); 81 | 82 | // actual QIcon loaded by QIcon::fromTheme 83 | QIcon internalQicon() const; 84 | 85 | struct GIconHash { 86 | std::size_t operator()(GIcon* gicon) const { 87 | return g_icon_hash(gicon); 88 | } 89 | }; 90 | 91 | struct GIconEqual { 92 | bool operator()(GIcon* gicon1, GIcon* gicon2) const { 93 | return g_icon_equal(gicon1, gicon2); 94 | } 95 | }; 96 | 97 | private: 98 | GIconPtr gicon_; 99 | mutable QIcon qicon_; 100 | mutable QList internalQicons_; 101 | 102 | static std::unordered_map, GIconHash, GIconEqual> cache_; 103 | static std::mutex mutex_; 104 | static QList fallbackQicons_; 105 | }; 106 | 107 | } // namespace Fm 108 | 109 | Q_DECLARE_METATYPE(std::shared_ptr) 110 | 111 | #endif /* __FM2_ICON_INFO_H__ */ 112 | -------------------------------------------------------------------------------- /src/core/job.cpp: -------------------------------------------------------------------------------- 1 | #include "job.h" 2 | #include "job_p.h" 3 | 4 | namespace Fm { 5 | 6 | Job::Job(): 7 | paused_{false}, 8 | cancellable_{g_cancellable_new(), false}, 9 | cancellableHandler_{g_signal_connect(cancellable_.get(), "cancelled", G_CALLBACK(_onCancellableCancelled), this)} { 10 | } 11 | 12 | Job::~Job() { 13 | if(cancellable_) { 14 | g_cancellable_disconnect(cancellable_.get(), cancellableHandler_); 15 | } 16 | } 17 | 18 | void Job::runAsync(QThread::Priority priority) { 19 | auto thread = new JobThread(this); 20 | connect(thread, &QThread::finished, thread, &QThread::deleteLater); 21 | if(autoDelete()) { 22 | connect(this, &Job::finished, this, &Job::deleteLater); 23 | } 24 | thread->start(priority); 25 | } 26 | 27 | void Job::cancel() { 28 | g_cancellable_cancel(cancellable_.get()); 29 | } 30 | 31 | void Job::run() { 32 | exec(); 33 | Q_EMIT finished(); 34 | } 35 | 36 | 37 | Job::ErrorAction Job::emitError(const GErrorPtr &err, Job::ErrorSeverity severity) { 38 | ErrorAction response = ErrorAction::CONTINUE; 39 | // if the error is already handled, don't emit it. 40 | if(err.domain() == G_IO_ERROR && err.code() == G_IO_ERROR_FAILED_HANDLED) { 41 | return response; 42 | } 43 | Q_EMIT error(err, severity, response); 44 | 45 | if(severity == ErrorSeverity::CRITICAL || response == ErrorAction::ABORT) { 46 | cancel(); 47 | } 48 | else if(response == ErrorAction::RETRY ) { 49 | /* If the job is already cancelled, retry is not allowed. */ 50 | if(isCancelled() || (err.domain() == G_IO_ERROR && err.code() == G_IO_ERROR_CANCELLED)) { 51 | response = ErrorAction::CONTINUE; 52 | } 53 | } 54 | return response; 55 | } 56 | 57 | } // namespace Fm 58 | -------------------------------------------------------------------------------- /src/core/job.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef __LIBFM_QT_FM_JOB_H__ 21 | #define __LIBFM_QT_FM_JOB_H__ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "gobjectptr.h" 30 | #include "gioptrs.h" 31 | #include "../libfmqtglobals.h" 32 | 33 | 34 | namespace Fm { 35 | 36 | /* 37 | * Fm::Job can be used in several different modes. 38 | * 1. run with QThreadPool::start() 39 | * 2. call runAsync(), which will create a new QThread and move the object to the thread. 40 | * 3. create a new QThread, and connect the started() signal to the slot Job::run() 41 | * 4. Directly call Job::run(), which executes synchrounously as a normal blocking call 42 | */ 43 | 44 | class LIBFM_QT_API Job: public QObject, public QRunnable { 45 | Q_OBJECT 46 | public: 47 | 48 | enum class ErrorAction{ 49 | CONTINUE, 50 | RETRY, 51 | ABORT 52 | }; 53 | 54 | enum class ErrorSeverity { 55 | UNKNOWN, 56 | WARNING, 57 | MILD, 58 | MODERATE, 59 | SEVERE, 60 | CRITICAL 61 | }; 62 | 63 | explicit Job(); 64 | 65 | ~Job() override; 66 | 67 | bool isCancelled() const { 68 | return g_cancellable_is_cancelled(cancellable_.get()); 69 | } 70 | 71 | void runAsync(QThread::Priority priority = QThread::InheritPriority); 72 | 73 | bool pause(); 74 | 75 | void resume(); 76 | 77 | const GCancellablePtr& cancellable() const { 78 | return cancellable_; 79 | } 80 | 81 | Q_SIGNALS: 82 | void cancelled(); 83 | 84 | void finished(); 85 | 86 | // this signal should be connected with Qt::BlockingQueuedConnection 87 | void error(const GErrorPtr& err, ErrorSeverity severity, ErrorAction& response); 88 | 89 | public Q_SLOTS: 90 | 91 | void cancel(); 92 | 93 | void run() override; 94 | 95 | protected: 96 | ErrorAction emitError(const GErrorPtr& err, ErrorSeverity severity = ErrorSeverity::MODERATE); 97 | 98 | // all derived job subclasses should do their work in this method. 99 | virtual void exec() = 0; 100 | 101 | private: 102 | static void _onCancellableCancelled(GCancellable* cancellable, Job* _this) { 103 | _this->onCancellableCancelled(cancellable); 104 | } 105 | 106 | void onCancellableCancelled(GCancellable* /*cancellable*/) { 107 | Q_EMIT cancelled(); 108 | } 109 | 110 | private: 111 | bool paused_; 112 | GCancellablePtr cancellable_; 113 | gulong cancellableHandler_; 114 | }; 115 | 116 | 117 | } 118 | 119 | #endif // __LIBFM_QT_FM_JOB_H__ 120 | -------------------------------------------------------------------------------- /src/core/job_p.h: -------------------------------------------------------------------------------- 1 | #ifndef JOB_P_H 2 | #define JOB_P_H 3 | 4 | #include 5 | #include "job.h" 6 | 7 | namespace Fm { 8 | 9 | class JobThread: public QThread { 10 | Q_OBJECT 11 | public: 12 | JobThread(Job* job): job_{job} { 13 | } 14 | 15 | protected: 16 | 17 | void run() override { 18 | job_->run(); 19 | } 20 | 21 | Job* job_; 22 | }; 23 | 24 | } // namespace Fm 25 | 26 | #endif // JOB_P_H 27 | -------------------------------------------------------------------------------- /src/core/legacy/fm-app-info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fm-app-info.h 3 | * 4 | * Copyright 2010 Hong Jen Yee (PCMan) 5 | * 6 | * This file is a part of the Libfm library. 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #ifndef __FM_APP_INFO_H__ 24 | #define __FM_APP_INFO_H__ 25 | 26 | #include 27 | 28 | G_BEGIN_DECLS 29 | 30 | gboolean fm_app_info_launch(GAppInfo *appinfo, GList *files, 31 | GAppLaunchContext *launch_context, GError **error); 32 | 33 | gboolean fm_app_info_launch_uris(GAppInfo *appinfo, GList *uris, 34 | GAppLaunchContext *launch_context, GError **error); 35 | 36 | gboolean fm_app_info_launch_default_for_uri(const char *uri, 37 | GAppLaunchContext *launch_context, 38 | GError **error); 39 | 40 | GAppInfo* fm_app_info_create_from_commandline(const char *commandline, 41 | const char *application_name, 42 | GAppInfoCreateFlags flags, 43 | GError **error); 44 | 45 | G_END_DECLS 46 | 47 | #endif /* __FM_APP_INFO_H__ */ 48 | -------------------------------------------------------------------------------- /src/core/legacy/glib-compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * glib-compat.h 3 | * 4 | * Copyright 2011 Hong Jen Yee (PCMan) 5 | * 6 | * This file is a part of the Libfm library. 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #ifndef __GLIB_COMPAT_H__ 24 | #define __GLIB_COMPAT_H__ 25 | #include 26 | #include 27 | 28 | G_BEGIN_DECLS 29 | 30 | /* GLib prior 2.24 have no such macro */ 31 | #ifndef G_DEFINE_INTERFACE 32 | # define G_DEFINE_INTERFACE(TN, t_n, T_P) \ 33 | static void t_n##_default_init (TN##Interface *klass); \ 34 | GType t_n##_get_type (void) \ 35 | { \ 36 | static volatile gsize g_define_type_id__volatile = 0; \ 37 | if (g_once_init_enter (&g_define_type_id__volatile)) \ 38 | { \ 39 | GType g_define_type_id = \ 40 | g_type_register_static_simple (G_TYPE_INTERFACE, \ 41 | g_intern_static_string (#TN), \ 42 | sizeof (TN##Interface), \ 43 | (GClassInitFunc)t_n##_default_init, \ 44 | 0, \ 45 | (GInstanceInitFunc)NULL, \ 46 | (GTypeFlags) 0); \ 47 | if (T_P) \ 48 | g_type_interface_add_prerequisite (g_define_type_id, T_P); \ 49 | g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \ 50 | } \ 51 | return g_define_type_id__volatile; \ 52 | } /* closes t_n##_get_type() */ 53 | #endif /* G_DEFINE_INTERFACE */ 54 | 55 | #if !GLIB_CHECK_VERSION(2, 28, 0) 56 | 57 | /* This API was added in glib 2.28 */ 58 | 59 | #define g_slist_free_full(slist, free_func) \ 60 | { \ 61 | g_slist_foreach(slist, (GFunc)free_func, NULL); \ 62 | g_slist_free(slist); \ 63 | } 64 | 65 | #define g_list_free_full(list, free_func) \ 66 | { \ 67 | g_list_foreach(list, (GFunc)free_func, NULL); \ 68 | g_list_free(list); \ 69 | } 70 | 71 | #endif 72 | 73 | #if !GLIB_CHECK_VERSION(2, 34, 0) 74 | /* This useful API was added in glib 2.34 */ 75 | static inline GSList *g_slist_copy_deep(GSList *list, GCopyFunc func, gpointer user_data) 76 | { 77 | GSList *new_list = g_slist_copy(list), *l; 78 | for(l = new_list; l; l = l->next) 79 | l->data = func(l->data, user_data); 80 | return new_list; 81 | } 82 | #endif 83 | 84 | G_END_DECLS 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /src/core/mimetype.cpp: -------------------------------------------------------------------------------- 1 | #include "mimetype.h" 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | namespace Fm { 10 | 11 | std::unordered_map, CStrHash, CStrEqual> MimeType::cache_; 12 | std::mutex MimeType::mutex_; 13 | 14 | std::shared_ptr MimeType::inodeDirectory_; // inode/directory 15 | std::shared_ptr MimeType::inodeShortcut_; // inode/x-shortcut 16 | std::shared_ptr MimeType::inodeMountPoint_; // inode/mount-point 17 | std::shared_ptr MimeType::desktopEntry_; // application/x-desktop 18 | 19 | 20 | MimeType::MimeType(const char* typeName): 21 | name_{g_strdup(typeName)}, 22 | desc_{nullptr} { 23 | 24 | GObjectPtr gicon{g_content_type_get_icon(typeName), false}; 25 | if(strcmp(typeName, "inode/directory") == 0) 26 | g_themed_icon_prepend_name(G_THEMED_ICON(gicon.get()), "folder"); 27 | else if(g_content_type_can_be_executable(typeName)) 28 | g_themed_icon_append_name(G_THEMED_ICON(gicon.get()), "application-x-executable"); 29 | 30 | icon_ = IconInfo::fromGIcon(gicon); 31 | } 32 | 33 | MimeType::~MimeType () { 34 | } 35 | 36 | //static 37 | std::shared_ptr MimeType::fromName(const char* typeName) { 38 | std::shared_ptr ret; 39 | std::lock_guard lock(mutex_); 40 | auto it = cache_.find(typeName); 41 | if(it == cache_.end()) { 42 | ret = std::make_shared(typeName); 43 | cache_.insert(std::make_pair(ret->name_.get(), ret)); 44 | } 45 | else { 46 | ret = it->second; 47 | } 48 | return ret; 49 | } 50 | 51 | // static 52 | std::shared_ptr MimeType::guessFromFileName(const char* fileName) { 53 | gboolean uncertain; 54 | /* let skip scheme and host from non-native names */ 55 | auto uri_scheme = g_strstr_len(fileName, -1, "://"); 56 | if(uri_scheme) 57 | fileName = strchr(uri_scheme + 3, '/'); 58 | if(fileName == nullptr) 59 | fileName = "unknown"; 60 | auto type = CStrPtr{g_content_type_guess(fileName, nullptr, 0, &uncertain)}; 61 | return fromName(type.get()); 62 | } 63 | 64 | } // namespace Fm 65 | -------------------------------------------------------------------------------- /src/core/templates.h: -------------------------------------------------------------------------------- 1 | #ifndef TEMPLATES_H 2 | #define TEMPLATES_H 3 | 4 | #include "../libfmqtglobals.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include "folder.h" 10 | #include "fileinfo.h" 11 | #include "mimetype.h" 12 | #include "iconinfo.h" 13 | 14 | namespace Fm { 15 | 16 | class LIBFM_QT_API TemplateItem { 17 | public: 18 | explicit TemplateItem(std::shared_ptr fileInfo); 19 | 20 | QString displayName() const { 21 | return fileInfo_->displayName(); 22 | } 23 | 24 | const std::string& name() const { 25 | return fileInfo_->name(); 26 | } 27 | 28 | std::shared_ptr icon() const { 29 | return fileInfo_->icon(); 30 | } 31 | 32 | std::shared_ptr fileInfo() const { 33 | return fileInfo_; 34 | } 35 | 36 | std::shared_ptr mimeType() const { 37 | return fileInfo_->mimeType(); 38 | } 39 | 40 | FilePath filePath() const; 41 | 42 | private: 43 | std::shared_ptr fileInfo_; 44 | }; 45 | 46 | 47 | class LIBFM_QT_API Templates : public QObject { 48 | Q_OBJECT 49 | public: 50 | explicit Templates(); 51 | 52 | // FIXME: the first call to this method will get no templates since dir loading is in progress. 53 | static std::shared_ptr globalInstance(); 54 | 55 | void forEachItem(std::function&)> func) const { 56 | for(const auto& item : items_) { 57 | func(item); 58 | } 59 | } 60 | 61 | std::vector> items() const { 62 | std::vector> tmp_items; 63 | for(auto& item: items_) { 64 | tmp_items.emplace_back(item); 65 | } 66 | return tmp_items; 67 | } 68 | 69 | bool hasTemplates() const { 70 | return !items_.empty(); 71 | } 72 | 73 | Q_SIGNALS: 74 | void itemAdded(const std::shared_ptr& item); 75 | 76 | void itemChanged(const std::shared_ptr& oldItem, const std::shared_ptr& newItem); 77 | 78 | void itemRemoved(const std::shared_ptr& item); 79 | 80 | private: 81 | void addTemplateDir(const char* dirPathName); 82 | 83 | private Q_SLOTS: 84 | void onFilesAdded(FileInfoList& addedFiles); 85 | 86 | void onFilesChanged(std::vector& changePairs); 87 | 88 | void onFilesRemoved(FileInfoList& removedFiles); 89 | 90 | void onTemplateDirRemoved(); 91 | 92 | private: 93 | std::vector> items_; 94 | std::vector> templateFolders_; 95 | std::vector> types_; 96 | static std::weak_ptr globalInstance_; 97 | }; 98 | 99 | } // namespace Fm 100 | 101 | #endif // TEMPLATES_H 102 | -------------------------------------------------------------------------------- /src/core/terminal.h: -------------------------------------------------------------------------------- 1 | #ifndef TERMINAL_H 2 | #define TERMINAL_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "gioptrs.h" 6 | #include "filepath.h" 7 | #include 8 | #include 9 | 10 | namespace Fm { 11 | 12 | LIBFM_QT_API bool launchTerminal(const char* programName, const FilePath& workingDir, GErrorPtr& error); 13 | 14 | LIBFM_QT_API std::vector internalTerminals(); 15 | 16 | LIBFM_QT_API std::vector allKnownTerminals(); 17 | 18 | LIBFM_QT_API const std::string defaultTerminal(); 19 | 20 | LIBFM_QT_API void setDefaultTerminal(std::string program); 21 | 22 | inline bool launchDefaultTerminal(const FilePath& workingDir, GErrorPtr& error) { 23 | return launchTerminal(defaultTerminal().c_str(), workingDir, error); 24 | } 25 | 26 | } // namespace Fm 27 | 28 | #endif // TERMINAL_H 29 | -------------------------------------------------------------------------------- /src/core/thumbnailer.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_THUMBNAILER_H 2 | #define FM2_THUMBNAILER_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "cstrptr.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace Fm { 12 | 13 | class MimeType; 14 | 15 | class LIBFM_QT_API Thumbnailer { 16 | public: 17 | explicit Thumbnailer(const char *id, GKeyFile *kf); 18 | 19 | CStrPtr commandForUri(const char* uri, const char* output_file, guint size) const; 20 | 21 | bool run(const char* uri, const char* output_file, int size) const; 22 | 23 | static void loadAll(); 24 | 25 | private: 26 | CStrPtr id_; 27 | CStrPtr try_exec_; /* FIXME: is this useful? */ 28 | CStrPtr exec_; 29 | //std::vector> mimeTypes_; 30 | 31 | static std::mutex mutex_; 32 | static std::vector> allThumbnailers_; 33 | }; 34 | 35 | } // namespace Fm 36 | 37 | #endif // FM2_THUMBNAILER_H 38 | -------------------------------------------------------------------------------- /src/core/thumbnailjob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_THUMBNAILJOB_H 2 | #define FM2_THUMBNAILJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "fileinfo.h" 6 | #include "gioptrs.h" 7 | #include "job.h" 8 | #include 9 | 10 | namespace Fm { 11 | 12 | class LIBFM_QT_API ThumbnailJob: public Job { 13 | Q_OBJECT 14 | public: 15 | 16 | explicit ThumbnailJob(FileInfoList files, int size, bool isRemote = false); 17 | 18 | ~ThumbnailJob() override; 19 | 20 | int size() const { 21 | return size_; 22 | } 23 | 24 | static QThreadPool* threadPool(); 25 | 26 | static void setLocalFilesOnly(bool value); 27 | 28 | static bool localFilesOnly() { 29 | return localFilesOnly_; 30 | } 31 | 32 | static int maxThumbnailFileSize() { 33 | return maxThumbnailFileSize_; 34 | } 35 | 36 | static void setMaxThumbnailFileSize(int size); 37 | 38 | static int maxExternalThumbnailFileSize() { 39 | return maxExternalThumbnailFileSize_; 40 | } 41 | 42 | static void setMaxExternalThumbnailFileSize(int size); 43 | 44 | const std::vector& results() const { 45 | return results_; 46 | } 47 | 48 | Q_SIGNALS: 49 | void thumbnailLoaded(const std::shared_ptr& file, int size, QImage thumbnail); 50 | 51 | protected: 52 | 53 | void exec() override; 54 | 55 | private: 56 | 57 | bool isSupportedImageType(const std::shared_ptr& mimeType) const; 58 | 59 | bool isThumbnailOutdated(const std::shared_ptr& file, const QImage& thumbnail) const; 60 | 61 | QImage generateThumbnail(const std::shared_ptr& file, const FilePath& origPath, const char* uri, const QString& thumbnailFilename); 62 | 63 | QImage readImageFromStream(GInputStream* stream, size_t len); 64 | 65 | QImage loadForFile(const std::shared_ptr& file); 66 | 67 | bool readJpegExif(GInputStream* stream, QImage& thumbnail, QTransform& matrix); 68 | 69 | private: 70 | FileInfoList files_; 71 | int size_; 72 | bool isRemote_; 73 | std::vector results_; 74 | GCancellablePtr cancellable_; 75 | GChecksum* md5Calc_; 76 | 77 | static QThreadPool* threadPool_; 78 | 79 | static bool localFilesOnly_; 80 | static int maxThumbnailFileSize_; 81 | static int maxExternalThumbnailFileSize_; 82 | }; 83 | 84 | } // namespace Fm 85 | 86 | #endif // FM2_THUMBNAILJOB_H 87 | -------------------------------------------------------------------------------- /src/core/totalsizejob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_TOTALSIZEJOB_H 2 | #define FM2_TOTALSIZEJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "fileoperationjob.h" 6 | #include "filepath.h" 7 | #include 8 | #include "gioptrs.h" 9 | 10 | namespace Fm { 11 | 12 | class LIBFM_QT_API TotalSizeJob : public Fm::FileOperationJob { 13 | Q_OBJECT 14 | public: 15 | enum Flags { 16 | DEFAULT = 0, 17 | FOLLOW_LINKS = 1 << 0, 18 | SAME_FS = 1 << 1, 19 | PREPARE_MOVE = 1 << 2, 20 | PREPARE_DELETE = 1 << 3 21 | }; 22 | 23 | explicit TotalSizeJob(FilePathList paths = FilePathList{}, Flags flags = DEFAULT); 24 | 25 | std::uint64_t totalSize() const { 26 | return totalSize_; 27 | } 28 | 29 | std::uint64_t totalOnDiskSize() const { 30 | return totalOndiskSize_; 31 | } 32 | 33 | unsigned int fileCount() const { 34 | return fileCount_; 35 | } 36 | 37 | protected: 38 | 39 | void exec() override; 40 | 41 | private: 42 | void exec(FilePath path, GFileInfoPtr inf); 43 | 44 | private: 45 | FilePathList paths_; 46 | 47 | int flags_; 48 | std::uint64_t totalSize_; 49 | std::uint64_t totalOndiskSize_; 50 | unsigned int fileCount_; 51 | const char* dest_fs_id; 52 | }; 53 | 54 | } // namespace Fm 55 | 56 | #endif // FM2_TOTALSIZEJOB_H 57 | -------------------------------------------------------------------------------- /src/core/trashjob.cpp: -------------------------------------------------------------------------------- 1 | #include "trashjob.h" 2 | 3 | #include "core/legacy/fm-config.h" 4 | 5 | namespace Fm { 6 | 7 | TrashJob::TrashJob(FilePathList paths): paths_{std::move(paths)} { 8 | // calculate progress using finished file counts rather than their sizes 9 | setCalcProgressUsingSize(false); 10 | } 11 | 12 | void TrashJob::exec() { 13 | setTotalAmount(paths_.size(), paths_.size()); 14 | Q_EMIT preparedToRun(); 15 | 16 | /* FIXME: we shouldn't trash a file already in trash:/// */ 17 | for(auto& path : paths_) { 18 | if(isCancelled()) { 19 | break; 20 | } 21 | 22 | setCurrentFile(path); 23 | 24 | // TODO: get parent dir of the current path. 25 | // if there is a Fm::Folder object created for it, block the update for the folder temporarily. 26 | 27 | for(;;) { // retry the i/o operation on errors 28 | auto gf = path.gfile(); 29 | bool ret = false; 30 | // FIXME: do not depend on fm_config 31 | if(fm_config->no_usb_trash) { 32 | GMountPtr mnt{g_file_find_enclosing_mount(gf.get(), nullptr, nullptr), false}; 33 | if(mnt) { 34 | ret = g_mount_can_unmount(mnt.get()); /* TRUE if it's removable media */ 35 | if(ret) { 36 | unsupportedFiles_.push_back(path); 37 | break; // don't trash the file 38 | } 39 | } 40 | } 41 | 42 | // move the file to trash 43 | GErrorPtr err; 44 | ret = g_file_trash(gf.get(), cancellable().get(), &err); 45 | if(ret) { // trash operation succeeded 46 | break; 47 | } 48 | else { // failed 49 | // if trashing is not supported by the file system 50 | if(err.domain() == G_IO_ERROR && err.code() == G_IO_ERROR_NOT_SUPPORTED) { 51 | unsupportedFiles_.push_back(path); 52 | break; 53 | } 54 | else { 55 | ErrorAction act = emitError(err, ErrorSeverity::MODERATE); 56 | if(act == ErrorAction::RETRY) { 57 | err.reset(); 58 | } 59 | else if(act == ErrorAction::ABORT) { 60 | cancel(); 61 | return; 62 | } 63 | else { 64 | break; 65 | } 66 | } 67 | } 68 | } 69 | addFinishedAmount(1, 1); 70 | } 71 | } 72 | 73 | 74 | } // namespace Fm 75 | -------------------------------------------------------------------------------- /src/core/trashjob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_TRASHJOB_H 2 | #define FM2_TRASHJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "fileoperationjob.h" 6 | #include "filepath.h" 7 | 8 | namespace Fm { 9 | 10 | class LIBFM_QT_API TrashJob : public Fm::FileOperationJob { 11 | Q_OBJECT 12 | public: 13 | explicit TrashJob(FilePathList paths); 14 | 15 | FilePathList unsupportedFiles() const { 16 | return unsupportedFiles_; 17 | } 18 | 19 | protected: 20 | 21 | void exec() override; 22 | 23 | private: 24 | FilePathList paths_; 25 | FilePathList unsupportedFiles_; 26 | }; 27 | 28 | } // namespace Fm 29 | 30 | #endif // FM2_TRASHJOB_H 31 | -------------------------------------------------------------------------------- /src/core/untrashjob.cpp: -------------------------------------------------------------------------------- 1 | #include "untrashjob.h" 2 | #include "filetransferjob.h" 3 | 4 | namespace Fm { 5 | 6 | UntrashJob::UntrashJob(FilePathList srcPaths): 7 | srcPaths_{std::move(srcPaths)} { 8 | } 9 | 10 | void UntrashJob::exec() { 11 | // preparing for the job 12 | FilePathList validSrcPaths; 13 | FilePathList origPaths; 14 | for(auto& srcPath: srcPaths_) { 15 | if(isCancelled()) { 16 | break; 17 | } 18 | GErrorPtr err; 19 | GFileInfoPtr srcInfo{ 20 | g_file_query_info(srcPath.gfile().get(), 21 | "trash::orig-path", 22 | G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, 23 | cancellable().get(), 24 | &err), 25 | false 26 | }; 27 | if(srcInfo) { 28 | const char* orig_path_str = g_file_info_get_attribute_byte_string(srcInfo.get(), "trash::orig-path"); 29 | if(orig_path_str) { 30 | validSrcPaths.emplace_back(srcPath); 31 | origPaths.emplace_back(FilePath::fromPathStr(orig_path_str)); 32 | } 33 | else { 34 | g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED, 35 | tr("Cannot untrash file '%s': original path not known").toUtf8().constData(), 36 | g_file_info_get_display_name(srcInfo.get())); 37 | // FIXME: do we need to retry here? 38 | emitError(err, ErrorSeverity::MODERATE); 39 | } 40 | } 41 | else { 42 | // FIXME: do we need to retry here? 43 | emitError(err); 44 | } 45 | } 46 | 47 | // collected original paths of the trashed files 48 | // use the file transfer job to handle the actual file move 49 | FileTransferJob fileTransferJob{std::move(validSrcPaths), std::move(origPaths), FileTransferJob::Mode::MOVE}; 50 | // FIXME: 51 | // I'm not sure why specifying Qt::DirectConnection is needed here since the caller & receiver are in the same thread. :-( 52 | // However without this, the signals/slots here will cause deadlocks. 53 | connect(&fileTransferJob, &FileTransferJob::preparedToRun, this, &UntrashJob::preparedToRun, Qt::DirectConnection); 54 | connect(&fileTransferJob, &FileTransferJob::error, this, &UntrashJob::error, Qt::DirectConnection); 55 | connect(&fileTransferJob, &FileTransferJob::fileExists, this, &UntrashJob::fileExists, Qt::DirectConnection); 56 | 57 | // cancel the file transfer subjob if the parent job is cancelled 58 | connect(this, &UntrashJob::cancelled, &fileTransferJob, 59 | [&fileTransferJob]() { 60 | if(!fileTransferJob.isCancelled()) { 61 | fileTransferJob.cancel(); 62 | } 63 | }, Qt::DirectConnection); 64 | 65 | // cancel the parent job if the file transfer subjob is cancelled 66 | connect(&fileTransferJob, &FileTransferJob::cancelled, this, 67 | [this]() { 68 | if(!isCancelled()) { 69 | cancel(); 70 | } 71 | }, Qt::DirectConnection); 72 | fileTransferJob.run(); 73 | } 74 | 75 | } // namespace Fm 76 | -------------------------------------------------------------------------------- /src/core/untrashjob.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_UNTRASHJOB_H 2 | #define FM2_UNTRASHJOB_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include "fileoperationjob.h" 6 | 7 | namespace Fm { 8 | 9 | class LIBFM_QT_API UntrashJob : public FileOperationJob { 10 | public: 11 | explicit UntrashJob(FilePathList srcPaths); 12 | 13 | protected: 14 | void exec() override; 15 | 16 | private: 17 | FilePathList srcPaths_; 18 | }; 19 | 20 | } // namespace Fm 21 | 22 | #endif // FM2_UNTRASHJOB_H 23 | -------------------------------------------------------------------------------- /src/core/userinfocache.cpp: -------------------------------------------------------------------------------- 1 | #include "userinfocache.h" 2 | #include 3 | #include 4 | 5 | namespace Fm { 6 | 7 | UserInfoCache* UserInfoCache::globalInstance_ = nullptr; 8 | std::mutex UserInfoCache::mutex_; 9 | 10 | UserInfoCache::UserInfoCache() : QObject() { 11 | } 12 | 13 | const std::shared_ptr& UserInfoCache::userFromId(uid_t uid) { 14 | std::lock_guard lock{mutex_}; 15 | auto it = users_.find(uid); 16 | if(it != users_.end()) 17 | return it->second; 18 | std::shared_ptr user; 19 | auto pw = getpwuid(uid); 20 | if(pw) { 21 | user = std::make_shared(uid, pw->pw_name, pw->pw_gecos); 22 | } 23 | return (users_[uid] = user); 24 | } 25 | 26 | const std::shared_ptr& UserInfoCache::groupFromId(gid_t gid) { 27 | std::lock_guard lock{mutex_}; 28 | auto it = groups_.find(gid); 29 | if(it != groups_.end()) 30 | return it->second; 31 | std::shared_ptr group; 32 | auto gr = getgrgid(gid); 33 | if(gr) { 34 | group = std::make_shared(gid, gr->gr_name); 35 | } 36 | return (groups_[gid] = group); 37 | } 38 | 39 | // static 40 | UserInfoCache* UserInfoCache::globalInstance() { 41 | std::lock_guard lock{mutex_}; 42 | if(!globalInstance_) 43 | globalInstance_ = new UserInfoCache(); 44 | return globalInstance_; 45 | } 46 | 47 | } // namespace Fm 48 | -------------------------------------------------------------------------------- /src/core/userinfocache.h: -------------------------------------------------------------------------------- 1 | #ifndef FM2_USERINFOCACHE_H 2 | #define FM2_USERINFOCACHE_H 3 | 4 | #include "../libfmqtglobals.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Fm { 13 | 14 | class LIBFM_QT_API UserInfo { 15 | public: 16 | explicit UserInfo(uid_t uid, const char* name, const char* realName): 17 | uid_{uid}, name_{QString::fromUtf8(name)}, realName_{QString::fromUtf8(realName)} { 18 | } 19 | 20 | uid_t uid() const { 21 | return uid_; 22 | } 23 | 24 | const QString& name() const { 25 | return name_; 26 | } 27 | 28 | const QString& realName() const { 29 | return realName_; 30 | } 31 | 32 | private: 33 | uid_t uid_; 34 | QString name_; 35 | QString realName_; 36 | 37 | }; 38 | 39 | class LIBFM_QT_API GroupInfo { 40 | public: 41 | explicit GroupInfo(gid_t gid, const char* name): gid_{gid}, name_{QString::fromUtf8(name)} { 42 | } 43 | 44 | gid_t gid() const { 45 | return gid_; 46 | } 47 | 48 | const QString& name() const { 49 | return name_; 50 | } 51 | 52 | private: 53 | gid_t gid_; 54 | QString name_; 55 | }; 56 | 57 | // FIXME: handle file changes 58 | 59 | class LIBFM_QT_API UserInfoCache : public QObject { 60 | Q_OBJECT 61 | public: 62 | explicit UserInfoCache(); 63 | 64 | const std::shared_ptr& userFromId(uid_t uid); 65 | 66 | const std::shared_ptr& groupFromId(gid_t gid); 67 | 68 | static UserInfoCache* globalInstance(); 69 | 70 | Q_SIGNALS: 71 | void changed(); 72 | 73 | private: 74 | std::unordered_map> users_; 75 | std::unordered_map> groups_; 76 | static UserInfoCache* globalInstance_; 77 | static std::mutex mutex_; 78 | }; 79 | 80 | } // namespace Fm 81 | 82 | #endif // FM2_USERINFOCACHE_H 83 | -------------------------------------------------------------------------------- /src/core/vfs/fm-file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fm-file.h 3 | * 4 | * Copyright 2012 Andriy Grytsenko (LStranger) 5 | * 6 | * This file is a part of the Libfm library. 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2.1 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 | */ 22 | 23 | #ifndef _FM_FILE_H_ 24 | #define _FM_FILE_H_ 1 25 | 26 | // #include "fm-module.h" 27 | 28 | #include 29 | #include 30 | 31 | G_BEGIN_DECLS 32 | 33 | #define FM_TYPE_FILE (fm_file_get_type()) 34 | #define FM_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\ 35 | FM_TYPE_FILE, FmFile)) 36 | #define FM_IS_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),\ 37 | FM_TYPE_FILE)) 38 | #define FM_FILE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj),\ 39 | FM_TYPE_FILE, FmFileInterface)) 40 | 41 | typedef struct _FmFile FmFile; /* Dummy typedef */ 42 | typedef struct _FmFileInterface FmFileInterface; 43 | 44 | /** 45 | * FmFileInterface: 46 | * @wants_incremental: VTable func, see fm_file_wants_incremental() 47 | */ 48 | struct _FmFileInterface 49 | { 50 | /*< private >*/ 51 | GTypeInterface g_iface; 52 | 53 | /*< public >*/ 54 | gboolean (*wants_incremental)(GFile* file); 55 | 56 | /*< private >*/ 57 | gpointer _reserved1; 58 | gpointer _reserved2; 59 | }; 60 | 61 | typedef struct _FmFileInitTable FmFileInitTable; 62 | 63 | /** 64 | * FmFileInitTable: 65 | * @new_for_uri: function to create new #GFile object from URI 66 | * 67 | * Functions to initialize FmFile instance. 68 | * 69 | * This structure is used for "vfs" module initialization. The key for 70 | * module of this type is scheme name to support. 71 | */ 72 | struct _FmFileInitTable 73 | { 74 | /*< public >*/ 75 | GFile * (*new_for_uri)(const char *uri); 76 | /*< private >*/ 77 | gpointer _reserved1; 78 | gpointer _reserved2; 79 | }; 80 | 81 | GType fm_file_get_type(void); 82 | 83 | void fm_file_add_vfs(const char *name, FmFileInitTable *init); 84 | 85 | /* VTable calls */ 86 | gboolean fm_file_wants_incremental(GFile* file); 87 | 88 | /* Gfile functions replacements */ 89 | GFile *fm_file_new_for_uri(const char *uri); 90 | GFile *fm_file_new_for_commandline_arg(const char *arg); 91 | 92 | void _fm_file_init(void); 93 | void _fm_file_finalize(void); 94 | 95 | /* for modules */ 96 | #define FM_MODULE_vfs_VERSION 1 97 | // extern FmFileInitTable fm_module_init_vfs; 98 | 99 | G_END_DECLS 100 | #endif /* _FM_FILE_H_ */ 101 | -------------------------------------------------------------------------------- /src/createnewmenu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_CREATENEWMENU_H 21 | #define FM_CREATENEWMENU_H 22 | 23 | #include "libfmqtglobals.h" 24 | #include 25 | 26 | #include "core/filepath.h" 27 | 28 | namespace Fm { 29 | 30 | class FolderView; 31 | class Templates; 32 | class TemplateItem; 33 | 34 | class LIBFM_QT_API CreateNewMenu : public QMenu { 35 | Q_OBJECT 36 | 37 | public: 38 | explicit CreateNewMenu(QWidget* dialogParent, Fm::FilePath dirPath, QWidget* parent = nullptr); 39 | ~CreateNewMenu() override; 40 | 41 | protected Q_SLOTS: 42 | void onCreateNewFolder(); 43 | 44 | void onCreateNewFile(); 45 | 46 | void onCreateNew(); 47 | 48 | private Q_SLOTS: 49 | void addTemplateItem(const std::shared_ptr& item); 50 | 51 | void updateTemplateItem(const std::shared_ptr& oldItem, const std::shared_ptr& newItem); 52 | 53 | void removeTemplateItem(const std::shared_ptr& item); 54 | 55 | private: 56 | QWidget* dialogParent_; 57 | Fm::FilePath dirPath_; 58 | QAction* templateSeparator_; 59 | std::shared_ptr templates_; 60 | }; 61 | 62 | } 63 | 64 | #endif // FM_CREATENEWMENU_H 65 | -------------------------------------------------------------------------------- /src/customaction_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_CUSTOMACTION_P_H 21 | #define FM_CUSTOMACTION_P_H 22 | 23 | #include 24 | #include "customactions/fileaction.h" 25 | 26 | namespace Fm { 27 | 28 | class CustomAction : public QAction { 29 | public: 30 | explicit CustomAction(std::shared_ptr item, QObject* parent = nullptr): 31 | QAction{QString::fromStdString(item->get_name()), parent}, 32 | item_{item} { 33 | auto& icon_name = item->get_icon(); 34 | if(!icon_name.empty()) { 35 | setIcon(QIcon::fromTheme(QString::fromUtf8(icon_name.c_str()))); 36 | } 37 | } 38 | 39 | ~CustomAction() override { 40 | } 41 | 42 | const std::shared_ptr& item() const { 43 | return item_; 44 | } 45 | 46 | private: 47 | std::shared_ptr item_; 48 | }; 49 | 50 | } // namespace Fm 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/customactions/fileactionprofile.h: -------------------------------------------------------------------------------- 1 | #ifndef FILEACTIONPROFILE_H 2 | #define FILEACTIONPROFILE_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../core/fileinfo.h" 10 | #include "fileactioncondition.h" 11 | 12 | namespace Fm { 13 | 14 | enum class FileActionExecMode { 15 | NORMAL, 16 | TERMINAL, 17 | EMBEDDED, 18 | DISPLAY_OUTPUT 19 | }; 20 | 21 | class FileActionProfile { 22 | public: 23 | explicit FileActionProfile(GKeyFile* kf, const char* profile_name); 24 | 25 | bool launch_once(GAppLaunchContext* ctx, std::shared_ptr first_file, const FileInfoList& files, CStrPtr& output); 26 | 27 | bool launch(GAppLaunchContext* ctx, const FileInfoList& files, CStrPtr& output); 28 | 29 | bool match(FileInfoList files); 30 | 31 | std::string id; 32 | CStrPtr name; 33 | CStrPtr exec; 34 | CStrPtr path; 35 | FileActionExecMode exec_mode; 36 | bool startup_notify; 37 | CStrPtr startup_wm_class; 38 | CStrPtr exec_as; 39 | 40 | std::shared_ptr condition; 41 | }; 42 | 43 | } // namespace Fm 44 | 45 | #endif // FILEACTIONPROFILE_H 46 | -------------------------------------------------------------------------------- /src/dirtreemodelitem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_DIRTREEMODELITEM_H 21 | #define FM_DIRTREEMODELITEM_H 22 | 23 | #include "libfmqtglobals.h" 24 | #include 25 | #include 26 | #include 27 | 28 | #include "core/fileinfo.h" 29 | #include "core/folder.h" 30 | 31 | namespace Fm { 32 | 33 | class DirTreeModel; 34 | class DirTreeView; 35 | 36 | class LIBFM_QT_API DirTreeModelItem { 37 | public: 38 | friend class DirTreeModel; // allow direct access of private members in DirTreeModel 39 | friend class DirTreeView; // allow direct access of private members in DirTreeView 40 | 41 | explicit DirTreeModelItem(); 42 | explicit DirTreeModelItem(std::shared_ptr info, DirTreeModel* model, DirTreeModelItem* parent = nullptr); 43 | ~DirTreeModelItem(); 44 | 45 | void loadFolder(); 46 | void unloadFolder(); 47 | 48 | inline bool isPlaceHolder() const { 49 | return (fileInfo_ == nullptr); 50 | } 51 | 52 | void setShowHidden(bool show); 53 | 54 | bool isQueuedForDeletion() const { 55 | return queuedForDeletion_; 56 | } 57 | 58 | 59 | private: 60 | void freeFolder(); 61 | void addPlaceHolderChild(); 62 | DirTreeModelItem* childFromName(const char* utf8_name, int* pos); 63 | DirTreeModelItem* childFromPath(Fm::FilePath path, bool recursive) const; 64 | 65 | DirTreeModelItem* insertFile(std::shared_ptr fi); 66 | void insertFiles(Fm::FileInfoList files); 67 | int insertItem(Fm::DirTreeModelItem* newItem); 68 | QModelIndex index(); 69 | 70 | void onFolderFinishLoading(); 71 | void onFolderFilesAdded(Fm::FileInfoList &files); 72 | void onFolderFilesRemoved(Fm::FileInfoList &files); 73 | void onFolderFilesChanged(std::vector& changes); 74 | 75 | private: 76 | std::shared_ptr fileInfo_; 77 | std::shared_ptr folder_; 78 | QString displayName_ ; 79 | QIcon icon_; 80 | bool expanded_; 81 | bool loaded_; 82 | DirTreeModelItem* parent_; 83 | DirTreeModelItem* placeHolderChild_; 84 | std::vector children_; 85 | std::vector hiddenChildren_; 86 | DirTreeModel* model_; 87 | bool queuedForDeletion_; 88 | // signal connections 89 | QMetaObject::Connection onFolderFinishLoadingConn_; 90 | QMetaObject::Connection onFolderFilesAddedConn_; 91 | QMetaObject::Connection onFolderFilesRemovedConn_; 92 | QMetaObject::Connection onFolderFilesChangedConn_; 93 | }; 94 | 95 | } 96 | 97 | #endif // FM_DIRTREEMODELITEM_H 98 | -------------------------------------------------------------------------------- /src/dirtreeview.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_DIRTREEVIEW_H 21 | #define FM_DIRTREEVIEW_H 22 | 23 | #include "libfmqtglobals.h" 24 | #include 25 | 26 | #include "core/filepath.h" 27 | 28 | class QItemSelection; 29 | 30 | namespace Fm { 31 | 32 | class FileMenu; 33 | class DirTreeModelItem; 34 | 35 | class LIBFM_QT_API DirTreeView : public QTreeView { 36 | Q_OBJECT 37 | 38 | public: 39 | explicit DirTreeView(QWidget* parent); 40 | ~DirTreeView() override; 41 | 42 | const Fm::FilePath& currentPath() const { 43 | return currentPath_; 44 | } 45 | 46 | void setCurrentPath(Fm::FilePath path); 47 | 48 | void chdir(Fm::FilePath path) { 49 | setCurrentPath(std::move(path)); 50 | } 51 | 52 | void setModel(QAbstractItemModel* model) override; 53 | 54 | protected: 55 | void mousePressEvent(QMouseEvent* event) override; 56 | void rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end) override; 57 | void dropEvent(QDropEvent* event) override; 58 | 59 | private: 60 | void cancelPendingChdir(); 61 | void expandPendingPath(); 62 | 63 | Q_SIGNALS: 64 | void chdirRequested(int type, const Fm::FilePath& path); 65 | void openFolderInNewWindowRequested(const Fm::FilePath& path); 66 | void openFolderInNewTabRequested(const Fm::FilePath& path); 67 | void openFolderInTerminalRequested(const Fm::FilePath& path); 68 | void createNewFolderRequested(const Fm::FilePath& path); 69 | void prepareFileMenu(Fm::FileMenu* menu); // emit before showing a Fm::FileMenu 70 | 71 | protected Q_SLOTS: 72 | void onCollapsed(const QModelIndex& index); 73 | void onExpanded(const QModelIndex& index); 74 | void onRowLoaded(const QModelIndex& index); 75 | void onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected); 76 | void onCustomContextMenuRequested(const QPoint& pos); 77 | void onOpen(); 78 | void onNewWindow(); 79 | void onNewTab(); 80 | void onOpenInTerminal(); 81 | void onNewFolder(); 82 | void rowsRemoved(const QModelIndex& parent, int start, int end); 83 | void doQueuedDeletions(); 84 | 85 | private: 86 | Fm::FilePath currentPath_; 87 | Fm::FilePathList pathsToExpand_; 88 | DirTreeModelItem* currentExpandingItem_; 89 | std::vector queuedForDeletion_; 90 | }; 91 | 92 | } 93 | 94 | #endif // FM_DIRTREEVIEW_H 95 | -------------------------------------------------------------------------------- /src/dndactionmenu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #include "dndactionmenu.h" 22 | 23 | namespace Fm { 24 | 25 | DndActionMenu::DndActionMenu(Qt::DropActions possibleActions, QWidget* parent) 26 | : QMenu(parent) 27 | , copyAction(nullptr) 28 | , moveAction(nullptr) 29 | , linkAction(nullptr) 30 | , cancelAction(nullptr) { 31 | if(possibleActions.testFlag(Qt::CopyAction)) { 32 | copyAction = addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), tr("Copy here")); 33 | } 34 | if(possibleActions.testFlag(Qt::MoveAction)) { 35 | moveAction = addAction(tr("Move here")); 36 | } 37 | if(possibleActions.testFlag(Qt::LinkAction)) { 38 | linkAction = addAction(tr("Create symlink here")); 39 | } 40 | addSeparator(); 41 | cancelAction = addAction(copyAction || moveAction || linkAction ? 42 | tr("Cancel") : tr("Cannot drop here")); 43 | } 44 | 45 | DndActionMenu::~DndActionMenu() { 46 | 47 | } 48 | 49 | Qt::DropAction DndActionMenu::askUser(Qt::DropActions possibleActions, QPoint pos, QWidget* parent) { 50 | Qt::DropAction result = Qt::IgnoreAction; 51 | DndActionMenu menu{possibleActions, parent}; 52 | QAction* action = menu.exec(pos); 53 | if(nullptr != action) { 54 | if(action == menu.copyAction) { 55 | result = Qt::CopyAction; 56 | } 57 | else if(action == menu.moveAction) { 58 | result = Qt::MoveAction; 59 | } 60 | else if(action == menu.linkAction) { 61 | result = Qt::LinkAction; 62 | } 63 | } 64 | return result; 65 | } 66 | 67 | 68 | } // namespace Fm 69 | -------------------------------------------------------------------------------- /src/dndactionmenu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_DNDACTIONMENU_H 22 | #define FM_DNDACTIONMENU_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include 27 | 28 | namespace Fm { 29 | 30 | class DndActionMenu : public QMenu { 31 | Q_OBJECT 32 | public: 33 | explicit DndActionMenu(Qt::DropActions possibleActions, QWidget* parent = nullptr); 34 | ~DndActionMenu() override; 35 | 36 | static Qt::DropAction askUser(Qt::DropActions possibleActions, QPoint pos, QWidget* parent = nullptr); 37 | 38 | private: 39 | QAction* copyAction; 40 | QAction* moveAction; 41 | QAction* linkAction; 42 | QAction* cancelAction; 43 | }; 44 | 45 | } 46 | 47 | #endif // FM_DNDACTIONMENU_H 48 | -------------------------------------------------------------------------------- /src/dnddest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #include "dnddest.h" 21 | #include "fileoperation.h" 22 | #include "utilities.h" 23 | 24 | namespace Fm { 25 | 26 | const char* supportedMimeTypes[] = { 27 | "text/uri-list" 28 | "XdndDirectSave0"/* X direct save */ 29 | /* TODO: add more targets to support: text types, _NETSCAPE_URL, property/bgimage ... */ 30 | }; 31 | 32 | DndDest::DndDest() { 33 | 34 | } 35 | 36 | DndDest::~DndDest() { 37 | 38 | } 39 | 40 | bool DndDest::dropMimeData(const QMimeData* data, Qt::DropAction action) { 41 | // FIXME: should we put this in dropEvent handler of FolderView instead? 42 | if(data->hasUrls()) { 43 | qDebug("drop action: %d", action); 44 | auto srcPaths = pathListFromQUrls(data->urls()); 45 | switch(action) { 46 | case Qt::CopyAction: 47 | FileOperation::copyFiles(srcPaths, destPath_); 48 | break; 49 | case Qt::MoveAction: 50 | FileOperation::moveFiles(srcPaths, destPath_); 51 | break; 52 | case Qt::LinkAction: 53 | FileOperation::symlinkFiles(srcPaths, destPath_); 54 | /* Falls through. */ 55 | default: 56 | return false; 57 | } 58 | return true; 59 | } 60 | return false; 61 | } 62 | 63 | bool DndDest::isSupported(const QMimeData* /*data*/) { 64 | return false; 65 | } 66 | 67 | bool DndDest::isSupported(QString /*mimeType*/) { 68 | return false; 69 | } 70 | 71 | 72 | } // namespace Fm 73 | -------------------------------------------------------------------------------- /src/dnddest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_DNDDEST_H 21 | #define FM_DNDDEST_H 22 | 23 | #include 24 | #include "core/filepath.h" 25 | 26 | namespace Fm { 27 | 28 | class DndDest { 29 | public: 30 | explicit DndDest(); 31 | ~DndDest(); 32 | 33 | void setDestPath(Fm::FilePath dest) { 34 | destPath_ = std::move(dest); 35 | } 36 | 37 | const Fm::FilePath& destPath() const { 38 | return destPath_; 39 | } 40 | 41 | static bool isSupported(const QMimeData* data); 42 | static bool isSupported(QString mimeType); 43 | 44 | bool dropMimeData(const QMimeData* data, Qt::DropAction action); 45 | 46 | private: 47 | Fm::FilePath destPath_; 48 | }; 49 | 50 | } 51 | 52 | #endif // FM_DNDDEST_H 53 | -------------------------------------------------------------------------------- /src/editbookmarksdialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_EDITBOOKMARKSDIALOG_H 22 | #define FM_EDITBOOKMARKSDIALOG_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include "core/bookmarks.h" 27 | 28 | namespace Ui { 29 | class EditBookmarksDialog; 30 | } 31 | 32 | namespace Fm { 33 | 34 | class LIBFM_QT_API EditBookmarksDialog : public QDialog { 35 | Q_OBJECT 36 | public: 37 | explicit EditBookmarksDialog(std::shared_ptr bookmarks, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); 38 | ~EditBookmarksDialog() override; 39 | 40 | void accept() override; 41 | 42 | private Q_SLOTS: 43 | void onAddItem(); 44 | void onRemoveItem(); 45 | 46 | private: 47 | Ui::EditBookmarksDialog* ui; 48 | std::shared_ptr bookmarks_; 49 | }; 50 | 51 | } 52 | 53 | #endif // FM_EDITBOOKMARKSDIALOG_H 54 | -------------------------------------------------------------------------------- /src/execfiledialog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #include "execfiledialog_p.h" 21 | #include "ui_exec-file.h" 22 | #include "core/iconinfo.h" 23 | 24 | namespace Fm { 25 | 26 | ExecFileDialog::ExecFileDialog(const FileInfo &fileInfo, QWidget* parent, Qt::WindowFlags f): 27 | QDialog(parent, f), 28 | ui(new Ui::ExecFileDialog()), 29 | result_(BasicFileLauncher::ExecAction::DIRECT_EXEC) { 30 | 31 | ui->setupUi(this); 32 | // show file icon 33 | auto gicon = fileInfo.icon(); 34 | if(gicon) { 35 | ui->icon->setPixmap(gicon->qicon().pixmap(QSize(48, 48))); 36 | } 37 | 38 | QString msg; 39 | if(fileInfo.isDesktopEntry()) { 40 | msg = tr("This file '%1' seems to be a desktop entry.\nWhat do you want to do with it?") 41 | .arg(fileInfo.displayName()); 42 | ui->exec->setDefault(true); 43 | ui->execTerm->hide(); 44 | } 45 | else if(fileInfo.isText()) { 46 | msg = tr("This text file '%1' seems to be an executable script.\nWhat do you want to do with it?") 47 | .arg(fileInfo.displayName()); 48 | ui->execTerm->setDefault(true); 49 | } 50 | else { 51 | msg = tr("This file '%1' is executable. Do you want to execute it?") 52 | .arg(fileInfo.displayName()); 53 | ui->exec->setDefault(true); 54 | ui->open->hide(); 55 | } 56 | ui->msg->setText(msg); 57 | ui->remBox->hide(); 58 | resize(sizeHint().expandedTo(QSize(400, 0))); // make sure that the label is shown completely (a Qt bug?) 59 | } 60 | 61 | ExecFileDialog::~ExecFileDialog() { 62 | delete ui; 63 | } 64 | 65 | void ExecFileDialog::allowRemembering() { 66 | ui->remLayout->setContentsMargins(0, 10, 0, 0); 67 | ui->remBox->show(); 68 | resize(sizeHint().expandedTo(QSize(400, 0))); 69 | } 70 | 71 | bool ExecFileDialog::isRemembered() { 72 | return ui->remBox->isChecked(); 73 | } 74 | 75 | void ExecFileDialog::accept() { 76 | QObject* _sender = sender(); 77 | if(_sender == ui->exec) { 78 | result_ = BasicFileLauncher::ExecAction::DIRECT_EXEC; 79 | } 80 | else if(_sender == ui->execTerm) { 81 | result_ = BasicFileLauncher::ExecAction::EXEC_IN_TERMINAL; 82 | } 83 | else if(_sender == ui->open) { 84 | result_ = BasicFileLauncher::ExecAction::OPEN_WITH_DEFAULT_APP; 85 | } 86 | else { 87 | result_ = BasicFileLauncher::ExecAction::CANCEL; 88 | } 89 | QDialog::accept(); 90 | } 91 | 92 | void ExecFileDialog::reject() { 93 | result_ = BasicFileLauncher::ExecAction::CANCEL; 94 | QDialog::reject(); 95 | } 96 | 97 | } // namespace Fm 98 | -------------------------------------------------------------------------------- /src/execfiledialog_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_EXECFILEDIALOG_H 21 | #define FM_EXECFILEDIALOG_H 22 | 23 | #include "core/basicfilelauncher.h" 24 | #include "core/fileinfo.h" 25 | 26 | #include 27 | 28 | #include 29 | 30 | namespace Ui { 31 | class ExecFileDialog; 32 | } 33 | 34 | namespace Fm { 35 | 36 | class ExecFileDialog : public QDialog { 37 | Q_OBJECT 38 | public: 39 | ~ExecFileDialog() override; 40 | ExecFileDialog(const FileInfo& fileInfo, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); 41 | 42 | BasicFileLauncher::ExecAction result() { 43 | return result_; 44 | } 45 | 46 | void allowRemembering(); 47 | bool isRemembered(); 48 | 49 | protected: 50 | void accept() override; 51 | void reject() override; 52 | 53 | private: 54 | Ui::ExecFileDialog* ui; 55 | BasicFileLauncher::ExecAction result_; 56 | }; 57 | 58 | } 59 | 60 | #endif // FM_EXECFILEDIALOG_H 61 | -------------------------------------------------------------------------------- /src/filedialog_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_FILEDIALOG_P_H 21 | #define FM_FILEDIALOG_P_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace Fm { 29 | 30 | class FileDialogIconSizeAction : public QWidgetAction { 31 | Q_OBJECT 32 | public: 33 | FileDialogIconSizeAction(const QString& text, QObject* parent) : QWidgetAction (parent) { 34 | QWidget* w = new QWidget(); 35 | QHBoxLayout* layout = new QHBoxLayout(); 36 | layout->setSpacing(4); 37 | QLabel* label = new QLabel(text); 38 | layout->addWidget(label); 39 | spinBox = new QSpinBox(); 40 | spinBox->setSuffix(tr(" px")); 41 | spinBox->setSingleStep(2); 42 | layout->addWidget(spinBox); 43 | w->setLayout(layout); 44 | setDefaultWidget(w); 45 | 46 | connect(spinBox, &QAbstractSpinBox::editingFinished, this, &FileDialogIconSizeAction::editingFinished); 47 | } 48 | 49 | int value() const { 50 | return spinBox->value(); 51 | } 52 | void setValue(int val) { 53 | spinBox->setValue(val); 54 | } 55 | 56 | void setBounds(int min, int max) { 57 | spinBox->setMinimum(min); 58 | spinBox->setMaximum(max); 59 | } 60 | 61 | void setSingleStep(int val) { 62 | spinBox->setSingleStep(val); 63 | } 64 | 65 | Q_SIGNALS: 66 | void editingFinished(); 67 | 68 | private: 69 | QSpinBox* spinBox; 70 | }; 71 | 72 | 73 | } // namespace Fm 74 | #endif // FM_FILEDIALOG_P_H 75 | -------------------------------------------------------------------------------- /src/filedialoghelper.h: -------------------------------------------------------------------------------- 1 | #ifndef FILEDIALOGHELPER_H 2 | #define FILEDIALOGHELPER_H 3 | 4 | #include "libfmqtglobals.h" 5 | #include // this private header is subject to changes 6 | #include 7 | 8 | namespace Fm { 9 | 10 | class FileDialog; 11 | 12 | class LIBFM_QT_API FileDialogHelper : public QPlatformFileDialogHelper { 13 | Q_OBJECT 14 | 15 | public: 16 | FileDialogHelper(); 17 | 18 | ~FileDialogHelper() override; 19 | 20 | // QPlatformDialogHelper 21 | void exec() override; 22 | bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) override; 23 | void hide() override; 24 | 25 | // QPlatformFileDialogHelper 26 | bool defaultNameFilterDisables() const override; 27 | void setDirectory(const QUrl &directory) override; 28 | QUrl directory() const override; 29 | void selectFile(const QUrl &filename) override; 30 | QList selectedFiles() const override; 31 | void setFilter() override; 32 | void selectNameFilter(const QString &filter) override; 33 | QString selectedMimeTypeFilter() const override; 34 | void selectMimeTypeFilter(const QString &filter) override; 35 | QString selectedNameFilter() const override; 36 | 37 | bool isSupportedUrl(const QUrl &url) const override; 38 | 39 | protected: 40 | inline Fm::FileDialog & dialog() { return *dlg_; } 41 | 42 | private: 43 | void applyOptions(); 44 | void loadSettings(); 45 | void saveSettings(); 46 | 47 | private: 48 | std::unique_ptr dlg_; 49 | }; 50 | 51 | } // namespace Fm 52 | 53 | // export a C API without C++ name mangling so others can dynamically load libfm-qt at runtime 54 | // to call this API and get a new QPlatformFileDialogHelper object. 55 | 56 | extern "C" { 57 | 58 | // if the process calling this API fail to load libfm-qt, nullptr will be returned instead. 59 | LIBFM_QT_API QPlatformFileDialogHelper* createFileDialogHelper(); 60 | 61 | } 62 | 63 | #endif // FILEDIALOGHELPER_H 64 | -------------------------------------------------------------------------------- /src/filelauncher.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_FILELAUNCHER_H 22 | #define FM_FILELAUNCHER_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include "core/fileinfo.h" 27 | #include "core/basicfilelauncher.h" 28 | 29 | namespace Fm { 30 | 31 | class LIBFM_QT_API FileLauncher: public BasicFileLauncher { 32 | public: 33 | explicit FileLauncher(); 34 | ~FileLauncher() override; 35 | 36 | bool launchFiles(QWidget* parent, const FileInfoList& file_infos); 37 | 38 | bool launchPaths(QWidget* parent, const FilePathList &paths); 39 | 40 | bool launchWithApp(QWidget* parent, GAppInfo* app, const FilePathList& paths); 41 | 42 | protected: 43 | 44 | GAppInfoPtr chooseApp(const FileInfoList& fileInfos, const char* mimeType, GErrorPtr& err) override; 45 | 46 | bool openFolder(GAppLaunchContext* ctx, const FileInfoList& folderInfos, GErrorPtr& err) override; 47 | 48 | bool showError(GAppLaunchContext* ctx, const GErrorPtr &err, const FilePath& path = FilePath{}, const FileInfoPtr& info = FileInfoPtr{}) override; 49 | 50 | ExecAction askExecFile(const FileInfoPtr& file) override; 51 | 52 | int ask(const char* msg, char* const* btn_labels, int default_btn) override; 53 | 54 | virtual void launchedFiles(const FileInfoList& files) const; 55 | virtual void launchedPaths(const FilePathList& paths) const; 56 | 57 | private: 58 | void resetExecActions(); 59 | 60 | private: 61 | bool multiple_; 62 | BasicFileLauncher::ExecAction desktopEntryAction_; 63 | BasicFileLauncher::ExecAction scriptAction_; 64 | BasicFileLauncher::ExecAction execAction_; 65 | }; 66 | 67 | } 68 | 69 | #endif // FM_FILELAUNCHER_H 70 | -------------------------------------------------------------------------------- /src/filemenu_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_FILEMENU_P_H 21 | #define FM_FILEMENU_P_H 22 | 23 | #include 24 | #include "core/gioptrs.h" 25 | #include "core/iconinfo.h" 26 | 27 | namespace Fm { 28 | 29 | class AppInfoAction : public QAction { 30 | Q_OBJECT 31 | public: 32 | explicit AppInfoAction(Fm::GAppInfoPtr app, QObject* parent = nullptr): 33 | QAction(QString::fromUtf8(g_app_info_get_name(app.get())), parent), 34 | appInfo_{std::move(app)} { 35 | setToolTip(QString::fromUtf8(g_app_info_get_description(appInfo_.get()))); 36 | GIcon* gicon = g_app_info_get_icon(appInfo_.get()); 37 | const auto icnInfo = Fm::IconInfo::fromGIcon(gicon); 38 | if(icnInfo) { 39 | setIcon(icnInfo->qicon()); 40 | } 41 | } 42 | 43 | ~AppInfoAction() override { 44 | } 45 | 46 | const Fm::GAppInfoPtr& appInfo() const { 47 | return appInfo_; 48 | } 49 | 50 | private: 51 | Fm::GAppInfoPtr appInfo_; 52 | }; 53 | 54 | } // namespace Fm 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /src/fileoperationdialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_FILEOPERATIONDIALOG_H 22 | #define FM_FILEOPERATIONDIALOG_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include 27 | #include "core/filepath.h" 28 | #include "core/fileinfo.h" 29 | #include "core/fileoperationjob.h" 30 | 31 | namespace Ui { 32 | class FileOperationDialog; 33 | } 34 | 35 | namespace Fm { 36 | 37 | class FileOperation; 38 | 39 | class LIBFM_QT_API FileOperationDialog : public QDialog { 40 | Q_OBJECT 41 | public: 42 | explicit FileOperationDialog(FileOperation* _operation); 43 | ~FileOperationDialog() override; 44 | 45 | void setSourceFiles(const Fm::FilePathList& srcFiles); 46 | void setDestPath(const Fm::FilePath& dest); 47 | 48 | int ask(QString question, char* const* options); 49 | 50 | FileOperationJob::FileExistsAction askRename(const FileInfo& src, const FileInfo& dest, FilePath& newDest); 51 | 52 | Job::ErrorAction error(GError* err, Job::ErrorSeverity severity); 53 | void setPrepared(); 54 | void setCurFile(QString cur_file); 55 | void setPercent(unsigned int percent); 56 | void setDataTransferred(std::uint64_t finishedSize, std::uint64_t totalSize); 57 | void setFilesProcessed(std::uint64_t finishedCount, std::uint64_t totalCount); 58 | void setRemainingTime(unsigned int sec); 59 | 60 | void reject() override; 61 | 62 | private: 63 | Ui::FileOperationDialog* ui; 64 | FileOperation* operation; 65 | int defaultOption; 66 | bool ignoreNonCriticalErrors_; 67 | }; 68 | 69 | } 70 | 71 | #endif // FM_FILEOPERATIONDIALOG_H 72 | -------------------------------------------------------------------------------- /src/fileoperationdialog_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This library is free software; you can redistribute it and/or 3 | * modify it under the terms of the GNU Lesser General Public 4 | * License as published by the Free Software Foundation; either 5 | * version 2.1 of the License, or (at your option) any later version. 6 | * 7 | * This library is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 | * Lesser General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU Lesser General Public 13 | * License along with this library; if not, write to the Free Software 14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 15 | * 16 | */ 17 | 18 | 19 | #ifndef FM_FILEOPERATIONDIALOG_P_H 20 | #define FM_FILEOPERATIONDIALOG_P_H 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace Fm { 27 | 28 | class ElidedLabel : public QLabel { 29 | Q_OBJECT 30 | 31 | public: 32 | explicit ElidedLabel(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()): 33 | QLabel(parent, f), 34 | lastWidth_(0) { 35 | setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 36 | // set a min width to prevent the window from widening with long texts 37 | setMinimumWidth(fontMetrics().averageCharWidth() * 10); 38 | } 39 | 40 | protected: 41 | // A simplified version of QLabel::paintEvent() without pixmap or shortcut but with eliding. 42 | void paintEvent(QPaintEvent* /*event*/) override { 43 | QRect cr = contentsRect().adjusted(margin(), margin(), -margin(), -margin()); 44 | QString txt = text(); 45 | // if the text is changed or its rect is resized (due to window resizing), 46 | // find whether it needs to be elided... 47 | if (txt != lastText_ || cr.width() != lastWidth_) { 48 | lastText_ = txt; 49 | lastWidth_ = cr.width(); 50 | elidedText_ = fontMetrics().elidedText(txt, Qt::ElideMiddle, cr.width()); 51 | } 52 | // ... then, draw the (elided) text 53 | if(!elidedText_.isEmpty()) { 54 | QPainter painter(this); 55 | QStyleOption opt; 56 | opt.initFrom(this); 57 | style()->drawItemText(&painter, cr, alignment(), opt.palette, isEnabled(), elidedText_, foregroundRole()); 58 | } 59 | } 60 | 61 | private: 62 | QString elidedText_; 63 | QString lastText_; 64 | int lastWidth_; 65 | }; 66 | 67 | } 68 | 69 | #endif // FM_FILEOPERATIONDIALOG_P_H 70 | -------------------------------------------------------------------------------- /src/filesearchdialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_FILESEARCHDIALOG_H 21 | #define FM_FILESEARCHDIALOG_H 22 | 23 | #include "libfmqtglobals.h" 24 | #include 25 | #include "core/filepath.h" 26 | 27 | namespace Ui { 28 | class SearchDialog; 29 | } 30 | 31 | namespace Fm { 32 | 33 | class LIBFM_QT_API FileSearchDialog : public QDialog { 34 | public: 35 | explicit FileSearchDialog(QStringList paths = QStringList(), QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); 36 | ~FileSearchDialog() override; 37 | 38 | const FilePath& searchUri() const { 39 | return searchUri_; 40 | } 41 | 42 | void accept() override; 43 | 44 | bool nameCaseInsensitive() const; 45 | void setNameCaseInsensitive(bool caseInsensitive); 46 | 47 | bool contentCaseInsensitive() const; 48 | void setContentCaseInsensitive(bool caseInsensitive); 49 | 50 | bool nameRegexp() const; 51 | void setNameRegexp(bool reg); 52 | 53 | bool contentRegexp() const; 54 | void setContentRegexp(bool reg); 55 | 56 | bool recursive() const; 57 | void setRecursive(bool rec); 58 | 59 | bool searchhHidden() const; 60 | void setSearchhHidden(bool hidden); 61 | 62 | QString namePattern() const; 63 | QString contentPattern() const; 64 | 65 | void addNamePatterns(const QStringList& patterns); 66 | void addContentPatterns(const QStringList& patterns); 67 | 68 | private Q_SLOTS: 69 | void onAddPath(); 70 | void onRemovePath(); 71 | 72 | private: 73 | Ui::SearchDialog* ui; 74 | FilePath searchUri_; 75 | }; 76 | 77 | } 78 | 79 | #endif // FM_FILESEARCHDIALOG_H 80 | -------------------------------------------------------------------------------- /src/fm-search.h: -------------------------------------------------------------------------------- 1 | /* 2 | * fm-search-uri.h 3 | * 4 | * Copyright 2015 Hong Jen Yee (PCMan) 5 | * Copyright 2012-2014 Andriy Grytsenko (LStranger) 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | */ 22 | 23 | /* FmSearch implements a tool used to generate a search:// URI used by libfm to search for files. 24 | * This API might become part of libfm in the future. 25 | */ 26 | 27 | #ifndef _FM_SEARCH_H_ 28 | #define _FM_SEARCH_H_ 29 | 30 | #include 31 | 32 | G_BEGIN_DECLS 33 | 34 | typedef struct _FmSearch FmSearch; 35 | 36 | FmSearch* fm_search_new(void); 37 | void fm_search_free(FmSearch* search); 38 | 39 | GFile* fm_search_to_gfile(FmSearch* search); 40 | 41 | gboolean fm_search_get_recursive(FmSearch* search); 42 | void fm_search_set_recursive(FmSearch* search, gboolean recursive); 43 | 44 | gboolean fm_search_get_show_hidden(FmSearch* search); 45 | void fm_search_set_show_hidden(FmSearch* search, gboolean show_hidden); 46 | 47 | const char* fm_search_get_name_patterns(FmSearch* search); 48 | void fm_search_set_name_patterns(FmSearch* search, const char* name_patterns); 49 | 50 | gboolean fm_search_get_name_ci(FmSearch* search); 51 | void fm_search_set_name_ci(FmSearch* search, gboolean name_ci); 52 | 53 | gboolean fm_search_get_name_regex(FmSearch* search); 54 | void fm_search_set_name_regex(FmSearch* search, gboolean name_regex); 55 | 56 | const char* fm_search_get_content_pattern(FmSearch* search); 57 | void fm_search_set_content_pattern(FmSearch* search, const char* content_pattern); 58 | 59 | gboolean fm_search_get_content_ci(FmSearch* search); 60 | void fm_search_set_content_ci(FmSearch* search, gboolean content_ci); 61 | 62 | gboolean fm_search_get_content_regex(FmSearch* search); 63 | void fm_search_set_content_regex(FmSearch* search, gboolean content_regex); 64 | 65 | void fm_search_add_dir(FmSearch* search, const char* dir); 66 | void fm_search_remove_dir(FmSearch* search, const char* dir); 67 | GList* fm_search_get_dirs(FmSearch* search); 68 | 69 | void fm_search_add_mime_type(FmSearch* search, const char* mime_type); 70 | void fm_search_remove_mime_type(FmSearch* search, const char* mime_type); 71 | GList* fm_search_get_mime_types(FmSearch* search); 72 | 73 | guint64 fm_search_get_max_size(FmSearch* search); 74 | void fm_search_set_max_size(FmSearch* search, guint64 size); 75 | 76 | guint64 fm_search_get_min_size(FmSearch* search); 77 | void fm_search_set_min_size(FmSearch* search, guint64 size); 78 | 79 | /* format of mtime: YYYY-MM-DD */ 80 | const char* fm_search_get_max_mtime(FmSearch* search); 81 | void fm_search_set_max_mtime(FmSearch* search, const char* mtime); 82 | 83 | /* format of mtime: YYYY-MM-DD */ 84 | const char* fm_search_get_min_mtime(FmSearch* search); 85 | void fm_search_set_min_mtime(FmSearch* search, const char* mtime); 86 | 87 | G_END_DECLS 88 | 89 | #endif /* _FM_SEARCH_H_ */ 90 | -------------------------------------------------------------------------------- /src/foldermenu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_FOLDERMENU_H 22 | #define FM_FOLDERMENU_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include "foldermodel.h" 27 | 28 | class QAction; 29 | 30 | namespace Fm { 31 | 32 | class FolderView; 33 | class FileActionItem; 34 | 35 | class LIBFM_QT_API FolderMenu : public QMenu { 36 | Q_OBJECT 37 | 38 | public: 39 | explicit FolderMenu(FolderView* view, QWidget* parent = nullptr); 40 | ~FolderMenu() override; 41 | 42 | QAction* createAction() { 43 | return createAction_; 44 | } 45 | 46 | QAction* separator1() { 47 | return separator1_; 48 | } 49 | 50 | QAction* pasteAction() { 51 | return pasteAction_; 52 | } 53 | 54 | QAction* separator2() { 55 | return separator2_; 56 | } 57 | 58 | QAction* selectAllAction() { 59 | return selectAllAction_; 60 | } 61 | 62 | QAction* invertSelectionAction() { 63 | return invertSelectionAction_; 64 | } 65 | 66 | QAction* separator3() { 67 | return separator3_; 68 | } 69 | 70 | QAction* sortAction() { 71 | return sortAction_; 72 | } 73 | 74 | QAction* showHiddenAction() { 75 | return showHiddenAction_; 76 | } 77 | 78 | QAction* separator4() { 79 | return separator4_; 80 | } 81 | 82 | QAction* propertiesAction() { 83 | return propertiesAction_; 84 | } 85 | 86 | FolderView* view() { 87 | return view_; 88 | } 89 | 90 | protected: 91 | void addCustomActionItem(QMenu* menu, std::shared_ptr item); 92 | 93 | protected Q_SLOTS: 94 | void onPasteActionTriggered(); 95 | void onSelectAllActionTriggered(); 96 | void onInvertSelectionActionTriggered(); 97 | void onSortActionTriggered(bool checked); 98 | void onSortOrderActionTriggered(bool checked); 99 | void onShowHiddenActionTriggered(bool checked); 100 | void onCaseSensitiveActionTriggered(bool checked); 101 | void onFolderFirstActionTriggered(bool checked); 102 | void onHiddenLastActionTriggered(bool checked); 103 | void onPropertiesActionTriggered(); 104 | void onCustomActionTriggered(); 105 | 106 | private: 107 | void createSortMenu(); 108 | void addSortMenuItem(const QString &title, int id); 109 | 110 | private: 111 | FolderView* view_; 112 | QAction* createAction_; 113 | QAction* separator1_; 114 | QAction* pasteAction_; 115 | QAction* separator2_; 116 | QAction* selectAllAction_; 117 | QAction* invertSelectionAction_; 118 | QAction* separator3_; 119 | QAction* sortAction_; 120 | QActionGroup* sortActionGroup_; 121 | QMenu* sortMenu_; 122 | QAction* actionAscending_; 123 | QAction* actionDescending_; 124 | QAction* showHiddenAction_; 125 | QAction* separator4_; 126 | QAction* propertiesAction_; 127 | }; 128 | 129 | } 130 | 131 | #endif // FM_FOLDERMENU_H 132 | -------------------------------------------------------------------------------- /src/foldermodelitem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_FOLDERMODELITEM_H 22 | #define FM_FOLDERMODELITEM_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "core/folder.h" 31 | 32 | namespace Fm { 33 | 34 | class LIBFM_QT_API FolderModelItem { 35 | public: 36 | 37 | enum ThumbnailStatus { 38 | ThumbnailNotChecked, 39 | ThumbnailLoading, 40 | ThumbnailLoaded, 41 | ThumbnailFailed 42 | }; 43 | 44 | struct Thumbnail { 45 | int size; 46 | ThumbnailStatus status; 47 | QImage image; 48 | }; 49 | 50 | public: 51 | explicit FolderModelItem(const std::shared_ptr& _info); 52 | FolderModelItem(const FolderModelItem& other); 53 | virtual ~FolderModelItem(); 54 | 55 | const QString& displayName() const { 56 | return info->displayName(); 57 | } 58 | 59 | const std::string& name() const { 60 | return info->name(); 61 | } 62 | 63 | QIcon icon() const { 64 | const auto i = info->icon(); 65 | return i ? i->qicon() : QIcon{}; 66 | } 67 | 68 | QString ownerName() const; 69 | 70 | QString ownerGroup() const; 71 | 72 | const QString& displayMtime() const; 73 | 74 | const QString& displayCrtime() const; 75 | 76 | const QString& displayDtime() const; 77 | 78 | const QString &displaySize() const; 79 | 80 | Thumbnail* findThumbnail(int size); 81 | 82 | void removeThumbnail(int size); 83 | 84 | std::shared_ptr info; 85 | mutable QString dispMtime_; 86 | mutable QString dispCrtime_; 87 | mutable QString dispDtime_; 88 | mutable QString dispSize_; 89 | QList thumbnails; 90 | bool isCut; 91 | }; 92 | 93 | } 94 | 95 | #endif // FM_FOLDERMODELITEM_H 96 | -------------------------------------------------------------------------------- /src/fontbutton.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #include "fontbutton.h" 22 | #include 23 | #include 24 | 25 | namespace Fm { 26 | 27 | FontButton::FontButton(QWidget* parent): QPushButton(parent) { 28 | connect(this, &QPushButton::clicked, this, &FontButton::onClicked); 29 | } 30 | 31 | FontButton::~FontButton() { 32 | } 33 | 34 | void FontButton::onClicked() { 35 | QFontDialog dlg(font_); 36 | if(dlg.exec() == QDialog::Accepted) { 37 | setFont(dlg.selectedFont()); 38 | } 39 | } 40 | 41 | void FontButton::setFont(QFont font) { 42 | font_ = font; 43 | QString text = font.family(); 44 | if(font.bold()) { 45 | text += QLatin1StringView(" "); 46 | text += tr("Bold"); 47 | } 48 | if(font.italic()) { 49 | text += QLatin1StringView(" "); 50 | text += tr("Italic"); 51 | } 52 | text += QStringLiteral(" %1").arg(font.pointSize()); 53 | setText(text); 54 | Q_EMIT changed(); 55 | } 56 | 57 | 58 | } // namespace Fm 59 | -------------------------------------------------------------------------------- /src/fontbutton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_FONTBUTTON_H 22 | #define FM_FONTBUTTON_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | 27 | 28 | namespace Fm { 29 | 30 | class LIBFM_QT_API FontButton : public QPushButton { 31 | Q_OBJECT 32 | public: 33 | explicit FontButton(QWidget* parent = nullptr); 34 | ~FontButton() override; 35 | 36 | QFont font() { 37 | return font_; 38 | } 39 | 40 | void setFont(QFont font); 41 | 42 | Q_SIGNALS: 43 | void changed(); 44 | 45 | private Q_SLOTS: 46 | void onClicked(); 47 | 48 | private: 49 | QFont font_; 50 | }; 51 | 52 | } 53 | 54 | #endif // FM_FONTBUTTON_H 55 | -------------------------------------------------------------------------------- /src/libfm-qt.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=${exec_prefix}/lib 4 | includedir=${prefix}/include 5 | 6 | Name: libfm-qt 7 | Description: A Qt/glib/gio-based lib used to develop file managers providing some file management utilities. 8 | URL: https://github.com/lxqt/libfm-qt 9 | Requires: @REQUIRED_QT@ 10 | Version: @LIBFM_QT_API_VERSION@ 11 | Libs: -L${libdir} -l@LIBFM_QT_LIBRARY_NAME@ 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /src/libfmqt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #include "libfmqt.h" 21 | #include 22 | #include 23 | #include "core/thumbnailer.h" 24 | #include "xdndworkaround.h" 25 | #include "core/vfs/fm-file.h" 26 | #include "core/legacy/fm-config.h" 27 | 28 | namespace Fm { 29 | 30 | struct LibFmQtData { 31 | LibFmQtData(); 32 | ~LibFmQtData(); 33 | 34 | QTranslator translator; 35 | XdndWorkaround workaround; 36 | int refCount; 37 | Q_DISABLE_COPY(LibFmQtData) 38 | }; 39 | 40 | static LibFmQtData* theLibFmData = nullptr; 41 | 42 | extern "C" { 43 | 44 | GFile *_fm_vfs_search_new_for_uri(const char *uri); // defined in vfs-search.c 45 | GFile *_fm_vfs_menu_new_for_uri(const char *uri); // defined in vfs-menu.c 46 | 47 | } 48 | 49 | static GFile* lookupSearchUri(GVfs * /*vfs*/, const char *identifier, gpointer /*user_data*/) { 50 | return _fm_vfs_search_new_for_uri(identifier); 51 | } 52 | 53 | static GFile* lookupMenuUri(GVfs * /*vfs*/, const char *identifier, gpointer /*user_data*/) { 54 | return _fm_vfs_menu_new_for_uri(identifier); 55 | } 56 | 57 | LibFmQtData::LibFmQtData(): refCount(1) { 58 | #if !GLIB_CHECK_VERSION(2, 36, 0) 59 | g_type_init(); 60 | #endif 61 | // turn on glib debug message 62 | // g_setenv("G_MESSAGES_DEBUG", "all", true); 63 | Fm::Thumbnailer::loadAll(); 64 | (void)translator.load(QStringLiteral("libfm-qt_") + QLocale::system().name(), QStringLiteral(LIBFM_QT_DATA_DIR) + QStringLiteral("/translations")); 65 | 66 | // FIXME: we keep the FmConfig data structure here to keep compatibility with legacy libfm API. 67 | fm_config_init(); 68 | 69 | // register some URI schemes implemented by libfm 70 | GVfs* vfs = g_vfs_get_default(); 71 | g_vfs_register_uri_scheme(vfs, "menu", lookupMenuUri, nullptr, nullptr, lookupMenuUri, nullptr, nullptr); 72 | g_vfs_register_uri_scheme(vfs, "search", lookupSearchUri, nullptr, nullptr, lookupSearchUri, nullptr, nullptr); 73 | } 74 | 75 | LibFmQtData::~LibFmQtData() { 76 | // _fm_file_finalize(); 77 | 78 | GVfs* vfs = g_vfs_get_default(); 79 | g_vfs_unregister_uri_scheme(vfs, "menu"); 80 | g_vfs_unregister_uri_scheme(vfs, "search"); 81 | } 82 | 83 | LibFmQt::LibFmQt() { 84 | if(!theLibFmData) { 85 | theLibFmData = new LibFmQtData(); 86 | } 87 | else { 88 | ++theLibFmData->refCount; 89 | } 90 | d = theLibFmData; 91 | } 92 | 93 | LibFmQt::~LibFmQt() { 94 | if(--d->refCount == 0) { 95 | delete d; 96 | theLibFmData = nullptr; 97 | } 98 | } 99 | 100 | QTranslator* LibFmQt::translator() { 101 | return &d->translator; 102 | } 103 | 104 | } // namespace Fm 105 | -------------------------------------------------------------------------------- /src/libfmqt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_APPLICATION_H 22 | #define FM_APPLICATION_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include 27 | 28 | namespace Fm { 29 | 30 | struct LibFmQtData; 31 | 32 | class LIBFM_QT_API LibFmQt { 33 | public: 34 | explicit LibFmQt(); 35 | ~LibFmQt(); 36 | 37 | QTranslator* translator(); 38 | 39 | private: 40 | LibFmQt(LibFmQt& other); // disable copy 41 | LibFmQtData* d; 42 | }; 43 | 44 | } 45 | 46 | #endif // FM_APPLICATION_H 47 | -------------------------------------------------------------------------------- /src/libfmqtglobals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef _LIBFM_QT_GLOBALS_ 21 | #define _LIBFM_QT_GLOBALS_ 22 | 23 | #include "fm-qt6_export.h" 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/mountoperationpassworddialog_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_MOUNTOPERATIONPASSWORDDIALOG_H 22 | #define FM_MOUNTOPERATIONPASSWORDDIALOG_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include 27 | 28 | namespace Ui { 29 | class MountOperationPasswordDialog; 30 | } 31 | 32 | namespace Fm { 33 | 34 | class MountOperation; 35 | 36 | class MountOperationPasswordDialog : public QDialog { 37 | Q_OBJECT 38 | 39 | public: 40 | explicit MountOperationPasswordDialog(MountOperation* op, GAskPasswordFlags flags); 41 | ~MountOperationPasswordDialog() override; 42 | 43 | void setMessage(QString message); 44 | void setDefaultUser(QString user); 45 | void setDefaultDomain(QString domain); 46 | 47 | void done(int r) override; 48 | 49 | private Q_SLOTS: 50 | void onAnonymousToggled(bool checked); 51 | 52 | private: 53 | Ui::MountOperationPasswordDialog* ui; 54 | MountOperation* mountOperation; 55 | bool needPassword; 56 | bool needUserName; 57 | bool needDomain; 58 | bool canSavePassword; 59 | bool canAnonymous; 60 | }; 61 | 62 | } 63 | 64 | #endif // FM_MOUNTOPERATIONPASSWORDDIALOG_H 65 | -------------------------------------------------------------------------------- /src/mountoperationquestiondialog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #include "mountoperationquestiondialog_p.h" 22 | #include "mountoperation.h" 23 | #include 24 | 25 | namespace Fm { 26 | 27 | MountOperationQuestionDialog::MountOperationQuestionDialog(MountOperation* op, gchar* message, GStrv choices): 28 | QMessageBox(), 29 | mountOperation(op) { 30 | 31 | setIcon(QMessageBox::Question); 32 | setText(QString::fromUtf8(message)); 33 | 34 | choiceCount = g_strv_length(choices); 35 | choiceButtons = new QAbstractButton*[choiceCount]; 36 | for(int i = 0; i < choiceCount; ++i) { 37 | // It's not allowed to add custom buttons without standard roles 38 | // to QMessageBox. So we set role of all buttons to AcceptRole. 39 | // When any of the set buttons is clicked, exec() always returns "accept". 40 | QPushButton* button = new QPushButton(QString::fromUtf8(choices[i])); 41 | addButton(button, QMessageBox::AcceptRole); 42 | choiceButtons[i] = button; 43 | } 44 | } 45 | 46 | MountOperationQuestionDialog::~MountOperationQuestionDialog() { 47 | delete []choiceButtons; 48 | } 49 | 50 | void MountOperationQuestionDialog::done(int r) { 51 | GMountOperation* op = mountOperation->mountOperation(); 52 | 53 | g_mount_operation_set_choice(op, r); 54 | g_mount_operation_reply(op, G_MOUNT_OPERATION_HANDLED); 55 | 56 | QDialog::done(r); 57 | } 58 | 59 | void MountOperationQuestionDialog::closeEvent(QCloseEvent *event) 60 | { 61 | GMountOperation* op = mountOperation->mountOperation(); 62 | 63 | g_mount_operation_reply(op, G_MOUNT_OPERATION_ABORTED); 64 | 65 | event->accept(); 66 | } 67 | 68 | } // namespace Fm 69 | -------------------------------------------------------------------------------- /src/mountoperationquestiondialog_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_MOUNTOPERATIONQUESTIONDIALOG_H 22 | #define FM_MOUNTOPERATIONQUESTIONDIALOG_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include 27 | #include 28 | 29 | namespace Fm { 30 | 31 | class MountOperation; 32 | 33 | class MountOperationQuestionDialog : public QMessageBox { 34 | Q_OBJECT 35 | public: 36 | MountOperationQuestionDialog(MountOperation* op, gchar* message, GStrv choices); 37 | ~MountOperationQuestionDialog() override; 38 | 39 | void done(int r) override; 40 | void closeEvent(QCloseEvent *event) override; 41 | 42 | private: 43 | MountOperation* mountOperation; 44 | QAbstractButton** choiceButtons; 45 | int choiceCount; 46 | }; 47 | 48 | } 49 | 50 | #endif // FM_MOUNTOPERATIONQUESTIONDIALOG_H 51 | -------------------------------------------------------------------------------- /src/pathbar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_PATHBAR_H 21 | #define FM_PATHBAR_H 22 | 23 | #include "libfmqtglobals.h" 24 | #include 25 | #include "core/filepath.h" 26 | 27 | class QToolButton; 28 | class QScrollArea; 29 | class QPushButton; 30 | class QHBoxLayout; 31 | 32 | namespace Fm { 33 | 34 | class PathEdit; 35 | class PathButton; 36 | 37 | class LIBFM_QT_API PathBar: public QWidget { 38 | Q_OBJECT 39 | public: 40 | explicit PathBar(QWidget* parent = nullptr); 41 | 42 | const Fm::FilePath& path() { 43 | return currentPath_; 44 | } 45 | 46 | void setPath(Fm::FilePath path); 47 | 48 | Q_SIGNALS: 49 | void chdir(const Fm::FilePath& path); 50 | void middleClickChdir(const Fm::FilePath& path); 51 | void editingFinished(); 52 | 53 | public Q_SLOTS: 54 | void openEditor(); 55 | void closeEditor(); 56 | void copyPath(); 57 | 58 | private Q_SLOTS: 59 | void onButtonToggled(bool checked); 60 | void onScrollButtonClicked(); 61 | void onReturnPressed(); 62 | void setArrowEnabledState(int value); 63 | void setScrollButtonVisibility(); 64 | void ensureToggledVisible(); 65 | 66 | protected: 67 | void resizeEvent(QResizeEvent* event) override; 68 | void mousePressEvent(QMouseEvent* event) override; 69 | void contextMenuEvent(QContextMenuEvent* event) override; 70 | bool eventFilter(QObject* watched, QEvent* event) override; 71 | 72 | private: 73 | void updateScrollButtonVisibility(); 74 | Fm::FilePath pathForButton(PathButton* btn); 75 | 76 | private: 77 | QToolButton* scrollToStart_; 78 | QToolButton* scrollToEnd_; 79 | QScrollArea* scrollArea_; 80 | QWidget* buttonsWidget_; 81 | QHBoxLayout* buttonsLayout_; 82 | PathEdit* tempPathEdit_; 83 | 84 | Fm::FilePath currentPath_; // currently active path 85 | PathButton* toggledBtn_; 86 | }; 87 | 88 | } // namespace Fm 89 | 90 | #endif // FM_PATHBAR_H 91 | -------------------------------------------------------------------------------- /src/pathbar_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_PATHBAR_P_H 21 | #define FM_PATHBAR_P_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace Fm { 31 | 32 | class PathButton: public QToolButton { 33 | Q_OBJECT 34 | public: 35 | PathButton(std::string name, QString displayName, bool isRoot = false, QWidget* parent = nullptr): 36 | QToolButton(parent), 37 | name_{name} { 38 | 39 | setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding); 40 | setCheckable(true); 41 | setAutoExclusive(true); 42 | setToolButtonStyle(Qt::ToolButtonTextBesideIcon); 43 | /* respect the toolbar icon size (can be set with some styles) */ 44 | int icnSize = style()->pixelMetric(QStyle::PM_ToolBarIconSize); 45 | setIconSize(QSize(icnSize, icnSize)); 46 | 47 | setText(displayName.replace(QLatin1Char('\n'), QLatin1Char(' '))); // single-line text 48 | 49 | if(isRoot) { /* this element is root */ 50 | QIcon icon = QIcon::fromTheme(QStringLiteral("drive-harddisk")); 51 | setIcon(icon); 52 | } 53 | } 54 | 55 | void changeEvent(QEvent* event) override { 56 | QToolButton::changeEvent(event); 57 | if(event->type() == QEvent::StyleChange) { 58 | int icnSize = style()->pixelMetric(QStyle::PM_ToolBarIconSize); 59 | setIconSize(QSize(icnSize, icnSize)); 60 | } 61 | } 62 | 63 | std::string name() const { 64 | return name_; 65 | } 66 | 67 | void setName(const std::string& name) { 68 | name_ = name; 69 | } 70 | 71 | private: 72 | std::string name_; 73 | }; 74 | 75 | } // namespace Fm 76 | 77 | #endif // FM_PATHBAR_P_H 78 | -------------------------------------------------------------------------------- /src/pathedit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_PATHEDIT_H 22 | #define FM_PATHEDIT_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | #include 27 | 28 | class QCompleter; 29 | class QStringListModel; 30 | 31 | namespace Fm { 32 | 33 | class PathEditJob; 34 | 35 | class LIBFM_QT_API PathEdit : public QLineEdit { 36 | Q_OBJECT 37 | public: 38 | explicit PathEdit(QWidget* parent = nullptr); 39 | ~PathEdit() override; 40 | 41 | protected: 42 | void focusInEvent(QFocusEvent* e) override; 43 | void focusOutEvent(QFocusEvent* e) override; 44 | bool event(QEvent* e) override; 45 | 46 | private Q_SLOTS: 47 | void onTextChanged(const QString& text); 48 | void onTextEdited(const QString& text); 49 | 50 | private: 51 | void selectNextCompletionRow(bool downward); 52 | void reloadCompleter(bool triggeredByFocusInEvent = false); 53 | void freeCompleter(); 54 | void onJobFinished(); 55 | 56 | private: 57 | QCompleter* completer_; 58 | QStringListModel* model_; 59 | QString currentPrefix_; 60 | GCancellable* cancellable_; 61 | QString lastTypedText_; 62 | }; 63 | 64 | } 65 | 66 | #endif // FM_PATHEDIT_H 67 | -------------------------------------------------------------------------------- /src/pathedit_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_PATHEDIT_P_H 22 | #define FM_PATHEDIT_P_H 23 | 24 | #include 25 | 26 | namespace Fm { 27 | 28 | class PathEdit; 29 | 30 | class PathEditJob : public QObject { 31 | Q_OBJECT 32 | public: 33 | GCancellable* cancellable; 34 | GFile* dirName; 35 | QStringList subDirs; 36 | PathEdit* edit; 37 | bool triggeredByFocusInEvent; 38 | 39 | ~PathEditJob() override { 40 | g_object_unref(dirName); 41 | g_object_unref(cancellable); 42 | } 43 | 44 | Q_SIGNALS: 45 | void finished(); 46 | 47 | public Q_SLOTS: 48 | void runJob(); 49 | 50 | }; 51 | 52 | } 53 | 54 | #endif // FM_PATHEDIT_P_H 55 | -------------------------------------------------------------------------------- /src/renamedialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_RENAMEDIALOG_H 22 | #define FM_RENAMEDIALOG_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | 27 | #include "core/fileinfo.h" 28 | 29 | namespace Ui { 30 | class RenameDialog; 31 | } 32 | 33 | class QPushButton; 34 | 35 | namespace Fm { 36 | 37 | class LIBFM_QT_API RenameDialog : public QDialog { 38 | Q_OBJECT 39 | 40 | public: 41 | enum Action { 42 | ActionCancel, 43 | ActionRename, 44 | ActionOverwrite, 45 | ActionIgnore 46 | }; 47 | 48 | public: 49 | explicit RenameDialog(const FileInfo &src, const FileInfo &dest, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); 50 | ~RenameDialog() override; 51 | 52 | Action action() { 53 | return action_; 54 | } 55 | 56 | bool applyToAll() { 57 | return applyToAll_; 58 | } 59 | 60 | QString newName() { 61 | return newName_; 62 | } 63 | 64 | protected Q_SLOTS: 65 | void onRenameClicked(); 66 | void onIgnoreClicked(); 67 | void onFileNameChanged(QString newName); 68 | 69 | protected: 70 | void accept() override; 71 | void reject() override; 72 | 73 | private: 74 | Ui::RenameDialog* ui; 75 | QPushButton* renameButton_; 76 | Action action_; 77 | bool applyToAll_; 78 | QString oldName_; 79 | QString newName_; 80 | }; 81 | 82 | } 83 | 84 | #endif // FM_RENAMEDIALOG_H 85 | -------------------------------------------------------------------------------- /src/sidepane.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | 21 | #ifndef FM_SIDEPANE_H 22 | #define FM_SIDEPANE_H 23 | 24 | #include "libfmqtglobals.h" 25 | #include 26 | 27 | #include "core/filepath.h" 28 | 29 | class QComboBox; 30 | class QVBoxLayout; 31 | class QWidget; 32 | 33 | namespace Fm { 34 | 35 | class FileMenu; 36 | 37 | class LIBFM_QT_API SidePane : public QWidget { 38 | Q_OBJECT 39 | 40 | public: 41 | enum Mode { 42 | ModeNone = -1, 43 | ModePlaces = 0, 44 | ModeDirTree, 45 | NumModes 46 | }; 47 | 48 | public: 49 | explicit SidePane(QWidget* parent = nullptr); 50 | ~SidePane() override; 51 | 52 | QSize iconSize() const { 53 | return iconSize_; 54 | } 55 | 56 | void setIconSize(QSize size); 57 | 58 | const Fm::FilePath& currentPath() const { 59 | return currentPath_; 60 | } 61 | 62 | void setCurrentPath(Fm::FilePath path); 63 | 64 | void setMode(Mode mode); 65 | 66 | Mode mode() const { 67 | return mode_; 68 | } 69 | 70 | QWidget* view() const { 71 | return view_; 72 | } 73 | 74 | static const char* modeName(Mode mode); 75 | 76 | static Mode modeByName(const char* str); 77 | 78 | #if 0 // FIXME: are these APIs from libfm-qt needed? 79 | int modeCount(void) { 80 | return NumModes; 81 | } 82 | 83 | QString modeLabel(Mode mode); 84 | 85 | QString modeTooltip(Mode mode); 86 | #endif 87 | 88 | void setShowHidden(bool show_hidden); 89 | 90 | bool showHidden() const { 91 | return showHidden_; 92 | } 93 | 94 | bool setHomeDir(const char* home_dir); 95 | 96 | void chdir(Fm::FilePath path) { 97 | setCurrentPath(std::move(path)); 98 | } 99 | 100 | void restoreHiddenPlaces(const QSet& items); 101 | 102 | Q_SIGNALS: 103 | void chdirRequested(int type, const Fm::FilePath& path); 104 | void openFolderInNewWindowRequested(const Fm::FilePath& path); 105 | void openFolderInNewTabRequested(const Fm::FilePath& path); 106 | void openFolderInTerminalRequested(const Fm::FilePath& path); 107 | void createNewFolderRequested(const Fm::FilePath& path); 108 | void modeChanged(Fm::SidePane::Mode mode); 109 | 110 | void prepareFileMenu(Fm::FileMenu* menu); // emit before showing a Fm::FileMenu 111 | 112 | void hiddenPlaceSet(const QString& str, bool hide); 113 | 114 | protected: 115 | bool eventFilter(QObject* watched, QEvent* event) override; 116 | 117 | protected Q_SLOTS: 118 | void onComboCurrentIndexChanged(int current); 119 | 120 | private: 121 | void initDirTree(); 122 | 123 | private: 124 | Fm::FilePath currentPath_; 125 | QWidget* view_; 126 | QComboBox* combo_; 127 | QVBoxLayout* verticalLayout; 128 | QSize iconSize_; 129 | Mode mode_; 130 | bool showHidden_; 131 | QSet restorableHiddenPlaces_; 132 | }; 133 | 134 | } 135 | 136 | #endif // FM_SIDEPANE_H 137 | -------------------------------------------------------------------------------- /src/tests/test-filedialog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "../core/folder.h" 24 | #include "../foldermodel.h" 25 | #include "../folderview.h" 26 | #include "../cachedfoldermodel.h" 27 | #include "../proxyfoldermodel.h" 28 | #include "../pathedit.h" 29 | #include "../filedialog.h" 30 | #include "libfmqt.h" 31 | 32 | 33 | int main(int argc, char** argv) { 34 | QApplication app(argc, argv); 35 | 36 | Fm::LibFmQt contex; 37 | 38 | /* 39 | QFileDialog dlg0; 40 | dlg0.setFileMode(QFileDialog::ExistingFiles); 41 | 42 | dlg0.setNameFilters(QStringList() << "Txt (*.txt)"); 43 | QObject::connect(&dlg0, &QFileDialog::currentChanged, [](const QString& path) { 44 | qDebug() << "currentChanged:" << path; 45 | }); 46 | QObject::connect(&dlg0, &QFileDialog::fileSelected, [](const QString& path) { 47 | qDebug() << "fileSelected:" << path; 48 | }); 49 | QObject::connect(&dlg0, &QFileDialog::filesSelected, [](const QStringList& paths) { 50 | qDebug() << "filesSelected:" << paths; 51 | }); 52 | 53 | dlg0.exec(); 54 | */ 55 | 56 | Fm::FileDialog dlg; 57 | // dlg.setFileMode(QFileDialog::ExistingFile); 58 | dlg.setFileMode(QFileDialog::ExistingFiles); 59 | // dlg.setFileMode(QFileDialog::Directory); 60 | dlg.setNameFilters(QStringList() << QStringLiteral("All (*)") << QStringLiteral("Text (*.txt)") << QStringLiteral("Images (*.gif *.jpeg *.jpg)")); 61 | 62 | dlg.exec(); 63 | qDebug() << "selected files:" << dlg.selectedFiles(); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /src/tests/test-folder.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | #include 20 | #include 21 | #include "../core/folder.h" 22 | 23 | int main(int argc, char** argv) { 24 | QApplication app(argc, argv); 25 | 26 | auto home = Fm::FilePath::homeDir(); 27 | auto folder = Fm::Folder::fromPath(home); 28 | 29 | QObject::connect(folder.get(), &Fm::Folder::startLoading, [=]() { 30 | qDebug("start loading"); 31 | }); 32 | QObject::connect(folder.get(), &Fm::Folder::finishLoading, [=]() { 33 | qDebug("finish loading"); 34 | }); 35 | 36 | QObject::connect(folder.get(), &Fm::Folder::filesAdded, [=](Fm::FileInfoList& files) { 37 | qDebug("files added"); 38 | for(auto& item: files) { 39 | qDebug() << item->displayName(); 40 | } 41 | }); 42 | QObject::connect(folder.get(), &Fm::Folder::filesRemoved, [=](Fm::FileInfoList& files) { 43 | qDebug("files removed"); 44 | for(auto& item: files) { 45 | qDebug() << item->displayName(); 46 | } 47 | }); 48 | QObject::connect(folder.get(), &Fm::Folder::filesChanged, [=](std::vector& file_pairs) { 49 | qDebug("files changed"); 50 | for(auto& pair: file_pairs) { 51 | auto& item = pair.second; 52 | qDebug() << item->displayName(); 53 | } 54 | }); 55 | 56 | for(auto& item: folder->files()) { 57 | qDebug() << item->displayName(); 58 | } 59 | qDebug() << "here"; 60 | 61 | return app.exec(); 62 | } 63 | -------------------------------------------------------------------------------- /src/tests/test-folderview.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "../core/folder.h" 24 | #include "../foldermodel.h" 25 | #include "../folderview.h" 26 | #include "../cachedfoldermodel.h" 27 | #include "../proxyfoldermodel.h" 28 | #include "../pathedit.h" 29 | #include "libfmqt.h" 30 | 31 | int main(int argc, char** argv) { 32 | QApplication app(argc, argv); 33 | 34 | Fm::LibFmQt contex; 35 | QMainWindow win; 36 | 37 | Fm::FolderView folder_view; 38 | win.setCentralWidget(&folder_view); 39 | 40 | auto home = Fm::FilePath::homeDir(); 41 | Fm::CachedFolderModel* model = Fm::CachedFolderModel::modelFromPath(home); 42 | auto proxy_model = new Fm::ProxyFolderModel(); 43 | proxy_model->sort(Fm::FolderModel::ColumnFileName, Qt::AscendingOrder); 44 | proxy_model->setSourceModel(model); 45 | 46 | proxy_model->setThumbnailSize(64); 47 | proxy_model->setShowThumbnails(true); 48 | 49 | folder_view.setModel(proxy_model); 50 | 51 | QToolBar toolbar; 52 | win.addToolBar(Qt::TopToolBarArea, &toolbar); 53 | Fm::PathEdit edit; 54 | edit.setText(QString::fromUtf8(home.toString().get())); 55 | toolbar.addWidget(&edit); 56 | auto action = new QAction(QStringLiteral("Go"), nullptr); 57 | toolbar.addAction(action); 58 | QObject::connect(action, &QAction::triggered, [&]() { 59 | auto path = Fm::FilePath::fromPathStr(edit.text().toLocal8Bit().constData()); 60 | auto new_model = Fm::CachedFolderModel::modelFromPath(path); 61 | proxy_model->setSourceModel(new_model); 62 | }); 63 | 64 | win.show(); 65 | return app.exec(); 66 | } 67 | -------------------------------------------------------------------------------- /src/tests/test-placesview.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "../placesview.h" 25 | #include "libfmqt.h" 26 | 27 | int main(int argc, char** argv) { 28 | QApplication app(argc, argv); 29 | 30 | Fm::LibFmQt contex; 31 | QMainWindow win; 32 | 33 | Fm::PlacesView view; 34 | win.setCentralWidget(&view); 35 | 36 | win.show(); 37 | return app.exec(); 38 | } 39 | -------------------------------------------------------------------------------- /src/tests/test-volumemanager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | #include 20 | #include 21 | #include 22 | #include "../core/volumemanager.h" 23 | 24 | int main(int argc, char** argv) { 25 | QApplication app(argc, argv); 26 | 27 | auto vm = Fm::VolumeManager::globalInstance(); 28 | 29 | QObject::connect(vm.get(), &Fm::VolumeManager::volumeAdded, [=](const Fm::Volume& vol) { 30 | qDebug() << "volume added:" << vol.name().get(); 31 | }); 32 | QObject::connect(vm.get(), &Fm::VolumeManager::volumeRemoved, [=](const Fm::Volume& vol) { 33 | qDebug() << "volume removed:" << vol.name().get(); 34 | }); 35 | 36 | for(auto& item: vm->volumes()) { 37 | auto name = item.name(); 38 | qDebug() << "list volume:" << name.get(); 39 | } 40 | 41 | return app.exec(); 42 | } 43 | -------------------------------------------------------------------------------- /src/translations/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(libfm-qt) 2 | 3 | build_component("." "${CMAKE_INSTALL_FULL_DATADIR}/libfm-qt6/translations") 4 | -------------------------------------------------------------------------------- /src/utilities.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef FM_UTILITIES_H 21 | #define FM_UTILITIES_H 22 | 23 | #include "libfmqtglobals.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | 32 | #include "core/filepath.h" 33 | #include "core/fileinfo.h" 34 | #include "core/templates.h" 35 | 36 | class QDialog; 37 | 38 | namespace Fm { 39 | 40 | LIBFM_QT_API Fm::FilePathList pathListFromUriList(const char* uriList); 41 | 42 | LIBFM_QT_API QByteArray pathListToUriList(const Fm::FilePathList& paths); 43 | 44 | LIBFM_QT_API Fm::FilePathList pathListFromQUrls(QList urls); 45 | 46 | LIBFM_QT_API void pasteFilesFromClipboard(const Fm::FilePath& destPath, QWidget* parent = nullptr); 47 | 48 | LIBFM_QT_API void copyFilesToClipboard(const Fm::FilePathList& files); 49 | 50 | LIBFM_QT_API void cutFilesToClipboard(const Fm::FilePathList& files); 51 | 52 | LIBFM_QT_API bool changeFileName(const Fm::FilePath& path, const QString& newName, QWidget* parent, bool showMessage = true); 53 | 54 | LIBFM_QT_API bool renameFile(std::shared_ptr file, QWidget* parent = nullptr); 55 | 56 | LIBFM_QT_API void setDefaultAppForType(const Fm::GAppInfoPtr app, std::shared_ptr mimeType); 57 | 58 | enum CreateFileType { 59 | CreateNewFolder, 60 | CreateNewTextFile, 61 | CreateWithTemplate 62 | }; 63 | 64 | LIBFM_QT_API void createFileOrFolder(CreateFileType type, FilePath parentDir, const TemplateItem* templ = nullptr, QWidget* parent = nullptr); 65 | 66 | constexpr uid_t INVALID_UID = uid_t(-1); 67 | 68 | LIBFM_QT_API uid_t uidFromName(QString name); 69 | 70 | LIBFM_QT_API QString uidToName(uid_t uid); 71 | 72 | constexpr gid_t INVALID_GID = gid_t(-1); 73 | 74 | LIBFM_QT_API gid_t gidFromName(QString name); 75 | 76 | LIBFM_QT_API QString gidToName(gid_t gid); 77 | 78 | LIBFM_QT_API int execModelessDialog(QDialog* dlg); 79 | 80 | // NOTE: this does not work reliably due to some problems in gio/gvfs 81 | // Use uriExists() whenever possible. 82 | LIBFM_QT_API bool isUriSchemeSupported(const char* uriScheme); 83 | 84 | LIBFM_QT_API bool uriExists(const char* uri); 85 | 86 | LIBFM_QT_API QString formatFileSize(std::uint64_t size, bool useSI = false); 87 | 88 | } 89 | 90 | #endif // FM_UTILITIES_H 91 | -------------------------------------------------------------------------------- /src/utilities_p.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 - 2015 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef __UTILITS_P_H__ 21 | #define __UTILITS_P_H__ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace Fm { 28 | 29 | // private class used in internal implementation 30 | class FilenameDialog : public QInputDialog { 31 | Q_OBJECT 32 | public: 33 | FilenameDialog(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()): 34 | QInputDialog(parent, flags), 35 | selectExtension_(false) { 36 | } 37 | 38 | void showEvent(QShowEvent * event) override { 39 | QWidget::showEvent(event); 40 | if(!selectExtension_) // dot not select filename extension 41 | QTimer::singleShot(0, this, SLOT(initSelection())); 42 | } 43 | 44 | bool selectExtension() const { 45 | return selectExtension_; 46 | } 47 | 48 | void setSelectExtension(bool value) { 49 | selectExtension_ = value; 50 | } 51 | 52 | private Q_SLOTS: 53 | // do not select filename extensions 54 | void initSelection() { 55 | // find the QLineEdit child widget 56 | QLineEdit* lineEdit = findChild(); 57 | if(lineEdit) { 58 | QString filename = lineEdit->text(); 59 | if(!filename.isEmpty()) { 60 | // only select filename part without extension name. 61 | int ext = filename.lastIndexOf(QLatin1Char('.')); 62 | if(ext != -1) { 63 | // add special cases for tar.gz, tar.bz2, and other tar.* files 64 | if(filename.first(ext).endsWith(QStringLiteral(".tar"))) 65 | ext -= 4; 66 | // FIXME: should we also handle other special cases? 67 | lineEdit->setSelection(0, ext); 68 | } 69 | } 70 | } 71 | } 72 | 73 | private: 74 | bool selectExtension_; 75 | }; 76 | 77 | } // namespace Fm 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/xdndworkaround.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Hong Jen Yee (PCMan) 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | /* 21 | * Note: 22 | * This is a workaround for the following Qt5 bugs. 23 | * 24 | * #49947: Drop events have broken mimeData()->urls() and text/uri-list. 25 | * #47981: Qt5.4 regression: Dropping text/urilist over browser windows stop working. 26 | * 27 | * Related LXQt bug: https://github.com/lxqt/lxqt/issues/688 28 | * 29 | * This workaround is not 100% reliable, but it should work most of the time. 30 | * In theory, when there are multiple drag and drops at nearly the same time and 31 | * you are using a remote X11 instance via a slow network connection, this workaround 32 | * might break. However, that should be a really rare corner case. 33 | * 34 | * How this fix works: 35 | * 1. Hook QApplication to filter raw X11 events 36 | * 2. Intercept SelectionRequest events sent from XDnd target window. 37 | * 3. Check if the data requested have the type "text/uri-list" or "x-moz-url" 38 | * 4. Bypass the broken Qt5 code and send the mime data to the target with our own code. 39 | * 40 | * The mime data is obtained during the most recent mouse button release event. 41 | * This can be incorrect in some corner cases, but it is still a simple and 42 | * good enough approximation that returns the correct data most of the time. 43 | * Anyway, a workarond is just a workaround. Ask Qt developers to fix their bugs. 44 | */ 45 | 46 | #ifndef XDNDWORKAROUND_H 47 | #define XDNDWORKAROUND_H 48 | 49 | #include 50 | 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | class QDrag; 58 | 59 | class XdndWorkaround : public QAbstractNativeEventFilter { 60 | public: 61 | explicit XdndWorkaround(); 62 | ~XdndWorkaround() override; 63 | bool nativeEventFilter(const QByteArray& eventType, void* message, qintptr* result) override; 64 | static QByteArray atomName(xcb_atom_t atom); 65 | static xcb_atom_t internAtom(const char* name, int len = -1); 66 | static QByteArray windowProperty(xcb_window_t window, xcb_atom_t propAtom, xcb_atom_t typeAtom, int len); 67 | static void setWindowProperty(xcb_window_t window, xcb_atom_t propAtom, xcb_atom_t typeAtom, void* data, int len, int format = 8); 68 | 69 | private: 70 | bool clientMessage(xcb_client_message_event_t* event); 71 | bool selectionNotify(xcb_selection_notify_event_t* event); 72 | 73 | private: 74 | bool selectionRequest(xcb_selection_request_event_t* event); 75 | bool genericEvent(xcb_ge_generic_event_t* event); 76 | // _QBasicDrag* xcbDrag() const; 77 | void buttonRelease(); 78 | 79 | QPointer lastDrag_; 80 | // xinput related 81 | bool xinput2Enabled_; 82 | int xinputOpCode_; 83 | int xinputEventBase_; 84 | int xinputErrorBase_; 85 | }; 86 | 87 | #endif // XDNDWORKAROUND_H 88 | --------------------------------------------------------------------------------