File indexing completed on 2024-04-21 05:48:31
0001 /*********************************************************************** 0002 * SPDX-FileCopyrightText: 2003-2004 Max Howell <max.howell@methylblue.com> 0003 * SPDX-FileCopyrightText: 2008-2014 Martin Sandsmark <martin.sandsmark@kde.org> 0004 * SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 ***********************************************************************/ 0008 0009 #include "define.h" 0010 #include "mainContext.h" 0011 0012 #include <filesystem> 0013 0014 #include <QApplication> 0015 #include <QCommandLineParser> 0016 #include <QDebug> 0017 #include <QDir> 0018 #include <QIcon> 0019 #include <QQuickStyle> 0020 #include <QUrl> 0021 0022 #include <KAboutData> 0023 #include <KConfigGroup> 0024 #include <KLocalizedString> 0025 #include <KSharedConfig> 0026 0027 #include "fileCleaner.h" 0028 #include "fileTree.h" 0029 0030 int main(int argc, char *argv[]) 0031 { 0032 // Since filelight may get used when the disk is full or near full we'll not 0033 // want to risk caching problems. If we don't have enough space -> disable caching. 0034 // https://bugs.kde.org/show_bug.cgi?id=466415 0035 const QString cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); 0036 std::error_code ec; 0037 const auto spaceInfo = std::filesystem::space(cachePath.toStdString(), ec); 0038 constexpr auto minimumSpace = 5UL * 1024 * 1024 * 1024; // GiB 0039 const bool cache = ec ? false : (spaceInfo.available > minimumSpace); 0040 if (!cache) { 0041 qWarning() << "Disabling QML cache because of low disk space"; 0042 qputenv("QML_DISABLE_DISK_CACHE", "1"); 0043 } 0044 0045 QApplication app(argc, argv); 0046 0047 qRegisterMetaType<std::shared_ptr<File>>("std::shared_ptr<File>"); 0048 qRegisterMetaType<std::shared_ptr<Folder>>("std::shared_ptr<Folder>"); 0049 0050 std::ignore = FileCleaner::instance(); // make sure the cleaner is up and running early so it is definitely up by the time shutdown happens 0051 0052 if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { 0053 QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); 0054 } 0055 0056 KLocalizedString::setApplicationDomain(QByteArrayLiteral("filelight")); 0057 auto config = KSharedConfig::openConfig(); 0058 auto stateConfig = KSharedConfig::openStateConfig(); 0059 if (config->hasGroup(QLatin1String("general"))) { 0060 auto grp = stateConfig->group(QStringLiteral("general")); 0061 config->group(QStringLiteral("general")).copyTo(&grp); 0062 config->deleteGroup(QStringLiteral("general")); 0063 } 0064 0065 KAboutData about(QStringLiteral(APP_NAME), 0066 i18n(APP_PRETTYNAME), 0067 QStringLiteral(APP_VERSION), 0068 i18n("Graphical disk-usage information"), 0069 KAboutLicense::GPL, 0070 i18n("(C) 2006 Max Howell\n" 0071 "(C) 2008-2014 Martin Sandsmark\n" 0072 "(C) 2017-2022 Harald Sitter"), 0073 QString(), 0074 QStringLiteral("https://apps.kde.org/filelight")); 0075 about.addAuthor(i18n("Martin Sandsmark"), i18n("Maintainer"), QStringLiteral("martin.sandsmark@kde.org"), QStringLiteral("https://iskrembilen.com/")); 0076 about.addAuthor(i18n("Harald Sitter"), i18n("QtQuick Port"), QStringLiteral("sitter@kde.org")); 0077 about.addAuthor(i18n("Max Howell"), i18n("Original author"), QStringLiteral("max.howell@methylblue.com"), QStringLiteral("https://www.methylblue.com/")); 0078 about.addCredit(i18n("Lukas Appelhans"), i18n("Help and support")); 0079 about.addCredit(i18n("Steffen Gerlach"), i18n("Inspiration"), QString(), QStringLiteral("http://www.steffengerlach.de/")); 0080 about.addCredit(i18n("Mike Diehl"), i18n("Original documentation")); 0081 about.addCredit(i18n("Sune Vuorela"), i18n("Icon")); 0082 about.addCredit(i18n("Nuno Pinheiro"), i18n("Icon")); 0083 0084 KAboutData::setApplicationData(about); 0085 app.setOrganizationName(QStringLiteral("KDE")); 0086 app.setWindowIcon(QIcon::fromTheme(QStringLiteral(APP_NAME))); 0087 0088 QCommandLineParser options; 0089 options.addPositionalArgument(QStringLiteral("url"), i18n("Path or URL to scan"), i18n("[url]")); 0090 about.setupCommandLine(&options); 0091 options.process(app); 0092 about.processCommandLine(&options); 0093 0094 Filelight::MainContext mainContext; 0095 const QStringList args = options.positionalArguments(); 0096 if (args.count() > 0) { 0097 mainContext.scan(QUrl::fromUserInput(args.at(0), QDir::currentPath(), QUrl::AssumeLocalFile)); 0098 } 0099 0100 return app.exec(); 0101 }