File indexing completed on 2024-04-21 05:48:33

0001 /*
0002     SPDX-FileCopyrightText: 2016 ROSA
0003     SPDX-License-Identifier: GPL-3.0-or-later
0004 */
0005 
0006 #include <QApplication>
0007 #include <QTranslator>
0008 #include <QLibraryInfo>
0009 #include <QIcon>
0010 #include <QLoggingCategory>
0011 
0012 #include <KAboutData>
0013 #include <KLocalizedString>
0014 #include <KCrash>
0015 
0016 #include "common.h"
0017 #include "mainapplication.h"
0018 #include "mainwindow.h"
0019 #include "usbdevicemonitor.h"
0020 
0021 #if !defined(Q_OS_WIN32) && !defined(Q_OS_LINUX) && !defined(Q_OS_MAC) && !defined(Q_OS_FREEBSD)
0022 #error Unsupported platform!
0023 #endif
0024 
0025 
0026 int main(int argc, char *argv[])
0027 {
0028 #if defined(Q_OS_MAC)
0029     // On Mac OS X elevated launch is treated as setuid which is forbidden by default -> enable it
0030     // TODO: Try to find a more "kosher" way, as well as get rid of deprecated AuthorizationExecuteWithPrivileges()
0031     QCoreApplication::setSetuidAllowed(true);
0032 #endif
0033 
0034     MainApplication a(argc, argv);
0035     KCrash::initialize();
0036 
0037     if (!ensureElevated())
0038         return 1;
0039 
0040 #if defined(Q_OS_WIN32)
0041     // CoInitialize() seems to be called by Qt automatically, so only set security attributes
0042     HRESULT res = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0);
0043     if (res != S_OK)
0044     {
0045         printf("CoInitializeSecurity failed! (Code: 0x%08lx)\n", res);
0046         return res;
0047     }
0048 #endif
0049 
0050     MainWindow w;
0051     w.show();
0052 
0053     UsbDeviceMonitor deviceMonitor;
0054     deviceMonitor.startMonitoring();
0055 
0056     // When device changing event comes, refresh the list of USB flash disks
0057     // Using QueuedConnection to avoid delays in processing the message
0058     QObject::connect(&deviceMonitor, &UsbDeviceMonitor::deviceChanged, &w,
0059                      &MainWindow::scheduleEnumFlashDevices, Qt::QueuedConnection);
0060 
0061     return a.exec();
0062 }