File indexing completed on 2024-05-05 04:47:05
0001 // Copyright 2018-2020 Camilo Higuita <milo.h@aol.com> 0002 // Copyright 2018-2020 Nitrux Latinoamericana S.C. 0003 // 0004 // SPDX-License-Identifier: GPL-3.0-or-later 0005 0006 /*** 0007 Pix Copyright (C) 2018 Camilo Higuita 0008 This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 0009 This is free software, and you are welcome to redistribute it 0010 under certain conditions; type `show c' for details. 0011 0012 This program is free software: you can redistribute it and/or modify 0013 it under the terms of the GNU General Public License as published by 0014 the Free Software Foundation, either version 3 of the License, or 0015 (at your option) any later version. 0016 0017 This program is distributed in the hope that it will be useful, 0018 but WITHOUT ANY WARRANTY; without even the implied warranty of 0019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0020 GNU General Public License for more details. 0021 0022 You should have received a copy of the GNU General Public License 0023 along with this program. If not, see <http://www.gnu.org/licenses/>. 0024 ***/ 0025 0026 #include <QCommandLineParser> 0027 #include <QFileInfo> 0028 #include <QIcon> 0029 #include <QQmlApplicationEngine> 0030 #include <QQmlContext> 0031 #include <QDirIterator> 0032 #include <QPair> 0033 0034 #ifdef Q_OS_ANDROID 0035 #include <QGuiApplication> 0036 #include <MauiKit3/Core/mauiandroid.h> 0037 #else 0038 #include <QApplication> 0039 #endif 0040 0041 #include "../pix_version.h" 0042 0043 #include <MauiKit3/Core/mauiapp.h> 0044 #include <MauiKit3/FileBrowsing/fmstatic.h> 0045 0046 #include <MauiKit3/ImageTools/moduleinfo.h> 0047 0048 #ifdef Q_OS_MACOS 0049 #include <MauiKit3/Core/mauimacos.h> 0050 #endif 0051 0052 #include <KI18n/KLocalizedString> 0053 0054 #include "models/folders/folders.h" 0055 #include "models/folders/placesmodel.h" 0056 #include "models/gallery/gallery.h" 0057 #include "models/tags/tagsmodel.h" 0058 #include "models/cities/citiesmodel.h" 0059 0060 #include "pix.h" 0061 0062 #define PIX_URI "org.maui.pix" 0063 0064 //static const QList<QUrl> getFolderImages(const QString &path) 0065 //{ 0066 // QList<QUrl> urls; 0067 0068 // if (QFileInfo(path).isDir()) { 0069 // QDirIterator it(path, FMStatic::FILTER_LIST[FMStatic::FILTER_TYPE::IMAGE], QDir::Files, QDirIterator::NoIteratorFlags); 0070 // while (it.hasNext()) 0071 // urls << QUrl::fromLocalFile(it.next()); 0072 0073 // } else if (QFileInfo(path).isFile()) 0074 // urls << path; 0075 0076 // return urls; 0077 //} 0078 0079 static const QPair<QString, QList<QUrl>> openFiles(const QStringList &files) 0080 { 0081 QList<QUrl> urls; 0082 QString module; 0083 0084 if (files.size() > 1) 0085 { 0086 module = "viewer"; 0087 for (const auto &file : files) 0088 { 0089 if(FMStatic::isDir(QUrl::fromUserInput(file))) 0090 continue; 0091 0092 urls << QUrl::fromUserInput(file); 0093 } 0094 } else if (files.size() == 1) 0095 { 0096 if(FMStatic::isDir(QUrl::fromUserInput(files.first()))) 0097 { 0098 module = "folder"; 0099 urls << QUrl::fromUserInput(files.first()); 0100 }else 0101 { 0102 module = "viewer"; 0103 // auto folder = QFileInfo(files.first()).dir().absolutePath(); 0104 // urls = getFolderImages(folder); 0105 // urls.removeOne(QUrl::fromLocalFile(files.first())); 0106 urls.insert(0, QUrl::fromLocalFile(files.first())); 0107 } 0108 } 0109 0110 return {module, urls}; 0111 } 0112 0113 Q_DECL_EXPORT int main(int argc, char *argv[]) 0114 { 0115 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 0116 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); 0117 0118 #ifdef Q_OS_ANDROID 0119 QGuiApplication app(argc, argv); 0120 if (!MAUIAndroid::checkRunTimePermissions({"android.permission.WRITE_EXTERNAL_STORAGE"})) 0121 return -1; 0122 #else 0123 QApplication app(argc, argv); 0124 #endif 0125 0126 app.setOrganizationName(QStringLiteral("Maui")); 0127 app.setWindowIcon(QIcon(":/assets/pix.png")); 0128 0129 KLocalizedString::setApplicationDomain("pix"); 0130 0131 KAboutData about(QStringLiteral("pix"), 0132 QStringLiteral("Pix"), 0133 PIX_VERSION_STRING, 0134 i18n("Organize, browse, and edit your images."), 0135 KAboutLicense::LGPL_V3, 0136 APP_COPYRIGHT_NOTICE, 0137 QString(GIT_BRANCH) + "/" + QString(GIT_COMMIT_HASH)); 0138 about.addAuthor(QStringLiteral("Camilo Higuita"), i18n("Developer"), QStringLiteral("milo.h@aol.com")); 0139 about.setHomepage("https://mauikit.org"); 0140 about.setProductName("maui/pix"); 0141 about.setBugAddress("https://invent.kde.org/maui/pix/-/issues"); 0142 about.setOrganizationDomain(PIX_URI); 0143 about.setProgramLogo(app.windowIcon()); 0144 0145 const auto exiv2Data = MauiKitImageTools::exiv2Data(); 0146 about.addComponent(exiv2Data.name(), "", exiv2Data.version(), exiv2Data.webAddress()); 0147 0148 const auto ITData = MauiKitImageTools::aboutData(); 0149 about.addComponent(ITData.name(), MauiKitImageTools::buildVersion(), ITData.version(), ITData.webAddress()); 0150 0151 KAboutData::setApplicationData(about); 0152 MauiApp::instance()->setIconName("qrc:/assets/pix.png"); 0153 0154 QCommandLineParser parser; 0155 0156 about.setupCommandLine(&parser); 0157 parser.process(app); 0158 0159 about.processCommandLine(&parser); 0160 const QStringList args = parser.positionalArguments(); 0161 0162 QPair<QString, QList<QUrl>> arguments; 0163 arguments.first = "folder"; 0164 0165 if (!args.isEmpty()) 0166 { 0167 arguments = openFiles(args); 0168 } 0169 0170 // QScopedPointer<ScreenshotInhibit> screenshot(new ScreenshotInhibit(qApp->desktopFileName())); 0171 // screenshot->blacklist(); 0172 0173 QQmlApplicationEngine engine; 0174 QUrl url(QStringLiteral("qrc:/main.qml")); 0175 QObject::connect( 0176 &engine, 0177 &QQmlApplicationEngine::objectCreated, 0178 &app, 0179 [url, arguments](QObject *obj, const QUrl &objUrl) { 0180 if (!obj && url == objUrl) 0181 QCoreApplication::exit(-1); 0182 0183 auto module = arguments.first; 0184 auto data = arguments.second; 0185 0186 if (!data.isEmpty() ) 0187 { 0188 if(module == "viewer") 0189 { 0190 Pix::instance()->openPics(data); 0191 }else if(module == " folder") 0192 { 0193 0194 } 0195 } 0196 }, 0197 Qt::QueuedConnection); 0198 0199 engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); 0200 0201 engine.rootContext()->setContextProperty("initModule", arguments.first); 0202 engine.rootContext()->setContextProperty("initData", QUrl::toStringList(arguments.second)); 0203 0204 qmlRegisterSingletonInstance<Pix>(PIX_URI, 1, 0, "Collection", Pix::instance()); 0205 0206 qmlRegisterType<Gallery>(PIX_URI, 1, 0, "GalleryList"); 0207 qmlRegisterType<PlacesModel>(PIX_URI, 1, 0, "PlacesList"); 0208 qmlRegisterType<Folders>(PIX_URI, 1, 0, "FoldersList"); 0209 qmlRegisterType<CitiesModel>(PIX_URI, 1, 0, "CitiesList"); 0210 qmlRegisterType<TagsModel>(PIX_URI, 1, 0, "TagsList"); 0211 0212 engine.load(url); 0213 0214 #ifdef Q_OS_MACOS 0215 // MAUIMacOS::removeTitlebarFromWindow(); 0216 // MauiApp::instance()->setEnableCSD(true); //for now index can not handle cloud accounts 0217 #endif 0218 0219 return app.exec(); 0220 }