Skip to content
Snippets Groups Projects
systemhandler.cpp 1.26 KiB
Newer Older
  • Learn to ignore specific revisions
  • akiraohgaki's avatar
    akiraohgaki committed
    #include "systemhandler.h"
    
    
    akiraohgaki's avatar
    akiraohgaki committed
    #include <QUrl>
    #include <QDesktopServices>
    
    
    akiraohgaki's avatar
    akiraohgaki committed
    #ifdef QTIL_OS_UNIX
    
    akiraohgaki's avatar
    akiraohgaki committed
    #include <QFileInfo>
    #include <QProcess>
    #endif
    
    
    akiraohgaki's avatar
    akiraohgaki committed
    #ifdef Q_OS_ANDROID
    
    akiraohgaki's avatar
    akiraohgaki committed
    #include "qtil_package.h"
    
    akiraohgaki's avatar
    akiraohgaki committed
    #endif
    
    
    akiraohgaki's avatar
    akiraohgaki committed
    SystemHandler::SystemHandler(QObject *parent)
        : QObject(parent)
    {}
    
    
    akiraohgaki's avatar
    akiraohgaki committed
    bool SystemHandler::isUnix() const
    
    akiraohgaki's avatar
    akiraohgaki committed
    {
    
    akiraohgaki's avatar
    akiraohgaki committed
    #ifdef QTIL_OS_UNIX
    
    akiraohgaki's avatar
    akiraohgaki committed
        return true;
    #endif
        return false;
    }
    
    
    akiraohgaki's avatar
    akiraohgaki committed
    bool SystemHandler::isMobileDevice() const
    
    akiraohgaki's avatar
    akiraohgaki committed
    {
    #if defined(APP_MOBILE)
        return true;
    #elif defined(Q_OS_IOS) || defined(Q_OS_ANDROID) || defined(Q_OS_WINPHONE)
        return true;
    #elif defined(Q_OS_LINUX) && defined(Q_PROCESSOR_ARM) // Ubuntu Phone, Plasma Phone
        return true;
    #endif
        return false;
    }
    
    
    akiraohgaki's avatar
    akiraohgaki committed
    bool SystemHandler::openUrl(const QString &url) const
    
    akiraohgaki's avatar
    akiraohgaki committed
    {
    
    akiraohgaki's avatar
    akiraohgaki committed
        auto path = url;
    
    akiraohgaki's avatar
    akiraohgaki committed
        path.replace("file://localhost", "", Qt::CaseInsensitive);
        path.replace("file://", "", Qt::CaseInsensitive);
    
    
    akiraohgaki's avatar
    akiraohgaki committed
    #ifdef QTIL_OS_UNIX
    
    akiraohgaki's avatar
    akiraohgaki committed
        if ((path.endsWith(".appimage", Qt::CaseInsensitive) || path.endsWith(".exe", Qt::CaseInsensitive))
                && QFileInfo(path).isExecutable()) {
            return QProcess::startDetached(path);
        }
    #endif
    
    #ifdef Q_OS_ANDROID
        if (path.endsWith(".apk", Qt::CaseInsensitive)) {
    
    akiraohgaki's avatar
    akiraohgaki committed
            return qtil::Package(path).installAsApk();
    
    akiraohgaki's avatar
    akiraohgaki committed
        }
    #endif
    
        return QDesktopServices::openUrl(QUrl(url));
    }