added DesktopUtils::openLocalFileOrDir()

This commit is contained in:
Martchus 2016-02-05 19:29:11 +01:00
parent 67be5bc4ff
commit b5ee1adc3f
4 changed files with 161 additions and 116 deletions

View File

@ -5,6 +5,7 @@ set(HEADER_FILES
aboutdialog/aboutdialog.h
enterpassworddialog/enterpassworddialog.h
misc/dialogutils.h
misc/desktoputils.h
models/checklistmodel.h
resources/qtconfigarguments.h
resources/resources.h
@ -24,6 +25,7 @@ set(SRC_FILES
aboutdialog/aboutdialog.cpp
enterpassworddialog/enterpassworddialog.cpp
misc/dialogutils.cpp
misc/desktoputils.cpp
models/checklistmodel.cpp
resources/qtconfigarguments.cpp
resources/resources.cpp

27
misc/desktoputils.cpp Normal file
View File

@ -0,0 +1,27 @@
#include "desktoputils.h"
#include <c++utilities/application/global.h>
#include <QDesktopServices>
#include <QUrl>
namespace DesktopUtils {
/*!
* \brief Shows the specified file or directory using the default file browser.
* \remarks
*/
bool LIB_EXPORT openLocalFileOrDir(const QString &path)
{
#ifdef Q_OS_WIN32
// backslashes are commonly used under Windows
// -> replace backslashes with slashes to support Windows paths
QString tmp(path);
tmp.replace(QChar('\\'), QChar('/'));
return QDesktopServices::openUrl(QUrl(QStringLiteral("file:///") + path, QUrl::TolerantMode));
#else
return QDesktopServices::openUrl(QUrl(QStringLiteral("file://") + path, QUrl::TolerantMode));
#endif
}
}

14
misc/desktoputils.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef DESKTOPSERVICES_H
#define DESKTOPSERVICES_H
#include <QtGlobal>
QT_FORWARD_DECLARE_CLASS(QString)
namespace DesktopUtils {
bool openLocalFileOrDir(const QString &path);
}
#endif // DESKTOPSERVICES_H

View File

@ -1,116 +1,118 @@
# meta data
projectname = qtutilities
appname = "Qt Utilities"
appauthor = Martchus
QMAKE_TARGET_DESCRIPTION = "Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models."
VERSION = 3.1.1
# include ../../common.pri when building as part of a subdirs project; otherwise include general.pri
!include(../../common.pri) {
!include(./general.pri) {
error("Couldn't find the common.pri or the general.pri file!")
}
}
# basic configuration: shared library
TEMPLATE = lib
QT += core gui
CONFIG += shared
# enable platform specific capslock detection (for password dialog)
CONFIG(noplatformspecificcapslockdetection, noplatformspecificcapslockdetection|platformspecificcapslockdetection) {
DEFINES -= PLATFORM_SPECIFIC_CAPSLOCK_DETECTION
} else {
DEFINES += PLATFORM_SPECIFIC_CAPSLOCK_DETECTION
}
# add project files
HEADERS += \
resources/resources.h \
models/checklistmodel.h \
resources/qtconfigarguments.h \
misc/dialogutils.h
SOURCES += resources/resources.cpp \
models/checklistmodel.cpp \
resources/qtconfigarguments.cpp \
misc/dialogutils.cpp
contains(DEFINES, GUI_QTWIDGETS) {
HEADERS += \
aboutdialog/aboutdialog.h \
enterpassworddialog/enterpassworddialog.h \
settingsdialog/optioncategorymodel.h \
settingsdialog/settingsdialog.h \
settingsdialog/optioncategory.h \
settingsdialog/optionpage.h \
settingsdialog/optioncategoryfiltermodel.h \
widgets/clearlineedit.h \
widgets/iconbutton.h \
widgets/buttonoverlay.h \
widgets/clearcombobox.h \
widgets/clearspinbox.h \
widgets/clearplaintextedit.h
SOURCES += \
aboutdialog/aboutdialog.cpp \
enterpassworddialog/enterpassworddialog.cpp \
settingsdialog/optioncategorymodel.cpp \
settingsdialog/settingsdialog.cpp \
settingsdialog/optionpage.cpp \
settingsdialog/optioncategory.cpp \
settingsdialog/optioncategoryfiltermodel.cpp \
widgets/clearlineedit.cpp \
widgets/iconbutton.cpp \
widgets/buttonoverlay.cpp \
widgets/clearcombobox.cpp \
widgets/clearspinbox.cpp \
widgets/clearplaintextedit.cpp
FORMS += \
aboutdialog/aboutdialog.ui \
enterpassworddialog/enterpassworddialog.ui \
settingsdialog/settingsdialog.ui
}
RESOURCES += \
resources/qtutilsicons.qrc
OTHER_FILES += \
README.md \
LICENSE \
CMakeLists.txt \
resources/config.h.in \
resources/windows.rc.in
# add libs
CONFIG(debug, debug|release) {
LIBS += -lc++utilitiesd
} else {
LIBS += -lc++utilities
}
contains(DEFINES, PLATFORM_SPECIFIC_CAPSLOCK_DETECTION) {
x11 {
LIBS += -lX11
}
}
# installs
mingw-w64-install {
target.path = $$(INSTALL_ROOT)
target.extra = install -m755 -D $${OUT_PWD}/release/lib$(TARGET).a $$(INSTALL_ROOT)/lib/lib$(TARGET).a
INSTALLS += target
dlltarget.path = $$(INSTALL_ROOT)
dlltarget.extra = install -m755 -D $${OUT_PWD}/release/$(TARGET) $$(INSTALL_ROOT)/bin/$(TARGET)
INSTALLS += dlltarget
} else {
target.path = $$(INSTALL_ROOT)/lib
INSTALLS += target
}
for(dir, $$list(aboutdialog enterpassworddialog models resources settingsdialog widgets misc)) {
eval(inc_$${dir} = $${dir})
inc_$${dir}.path = $$(INSTALL_ROOT)/include/$$projectname/$${dir}
inc_$${dir}.files = $${dir}/*.h
INSTALLS += inc_$${dir}
}
# meta data
projectname = qtutilities
appname = "Qt Utilities"
appauthor = Martchus
QMAKE_TARGET_DESCRIPTION = "Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models."
VERSION = 3.1.1
# include ../../common.pri when building as part of a subdirs project; otherwise include general.pri
!include(../../common.pri) {
!include(./general.pri) {
error("Couldn't find the common.pri or the general.pri file!")
}
}
# basic configuration: shared library
TEMPLATE = lib
QT += core gui
CONFIG += shared
# enable platform specific capslock detection (for password dialog)
CONFIG(noplatformspecificcapslockdetection, noplatformspecificcapslockdetection|platformspecificcapslockdetection) {
DEFINES -= PLATFORM_SPECIFIC_CAPSLOCK_DETECTION
} else {
DEFINES += PLATFORM_SPECIFIC_CAPSLOCK_DETECTION
}
# add project files
HEADERS += \
resources/resources.h \
models/checklistmodel.h \
resources/qtconfigarguments.h \
misc/dialogutils.h \
misc/desktoputils.h
SOURCES += resources/resources.cpp \
models/checklistmodel.cpp \
resources/qtconfigarguments.cpp \
misc/dialogutils.cpp \
misc/desktoputils.cpp
contains(DEFINES, GUI_QTWIDGETS) {
HEADERS += \
aboutdialog/aboutdialog.h \
enterpassworddialog/enterpassworddialog.h \
settingsdialog/optioncategorymodel.h \
settingsdialog/settingsdialog.h \
settingsdialog/optioncategory.h \
settingsdialog/optionpage.h \
settingsdialog/optioncategoryfiltermodel.h \
widgets/clearlineedit.h \
widgets/iconbutton.h \
widgets/buttonoverlay.h \
widgets/clearcombobox.h \
widgets/clearspinbox.h \
widgets/clearplaintextedit.h
SOURCES += \
aboutdialog/aboutdialog.cpp \
enterpassworddialog/enterpassworddialog.cpp \
settingsdialog/optioncategorymodel.cpp \
settingsdialog/settingsdialog.cpp \
settingsdialog/optionpage.cpp \
settingsdialog/optioncategory.cpp \
settingsdialog/optioncategoryfiltermodel.cpp \
widgets/clearlineedit.cpp \
widgets/iconbutton.cpp \
widgets/buttonoverlay.cpp \
widgets/clearcombobox.cpp \
widgets/clearspinbox.cpp \
widgets/clearplaintextedit.cpp
FORMS += \
aboutdialog/aboutdialog.ui \
enterpassworddialog/enterpassworddialog.ui \
settingsdialog/settingsdialog.ui
}
RESOURCES += \
resources/qtutilsicons.qrc
OTHER_FILES += \
README.md \
LICENSE \
CMakeLists.txt \
resources/config.h.in \
resources/windows.rc.in
# add libs
CONFIG(debug, debug|release) {
LIBS += -lc++utilitiesd
} else {
LIBS += -lc++utilities
}
contains(DEFINES, PLATFORM_SPECIFIC_CAPSLOCK_DETECTION) {
x11 {
LIBS += -lX11
}
}
# installs
mingw-w64-install {
target.path = $$(INSTALL_ROOT)
target.extra = install -m755 -D $${OUT_PWD}/release/lib$(TARGET).a $$(INSTALL_ROOT)/lib/lib$(TARGET).a
INSTALLS += target
dlltarget.path = $$(INSTALL_ROOT)
dlltarget.extra = install -m755 -D $${OUT_PWD}/release/$(TARGET) $$(INSTALL_ROOT)/bin/$(TARGET)
INSTALLS += dlltarget
} else {
target.path = $$(INSTALL_ROOT)/lib
INSTALLS += target
}
for(dir, $$list(aboutdialog enterpassworddialog models resources settingsdialog widgets misc)) {
eval(inc_$${dir} = $${dir})
inc_$${dir}.path = $$(INSTALL_ROOT)/include/$$projectname/$${dir}
inc_$${dir}.files = $${dir}/*.h
INSTALLS += inc_$${dir}
}