File indexing completed on 2023-11-26 04:58:05

0001 /*
0002     Main file of the Smb4K program.
0003 
0004     SPDX-FileCopyrightText: 2003-2023 Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 // application specific includes
0009 #include "core/smb4kglobal.h"
0010 #include "core/smb4ksettings.h"
0011 #include "smb4kmainwindow.h"
0012 
0013 // Qt includes
0014 #include <QApplication>
0015 #include <QString>
0016 
0017 // KDE includes
0018 #include <KAboutData>
0019 #include <KCrash>
0020 #include <KDBusService>
0021 #include <KLocalizedString>
0022 #include <KWindowSystem>
0023 #include <kwindowsystem_version.h>
0024 
0025 #include <smb4k_version.h>
0026 
0027 using namespace Smb4KGlobal;
0028 
0029 int main(int argc, char **argv)
0030 {
0031 #if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
0032     // Set attributes
0033     QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
0034     QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
0035 #endif
0036 
0037     // Create the application
0038     QApplication app(argc, argv);
0039 
0040     // Connect the application with the translation catalog
0041     KLocalizedString::setApplicationDomain("smb4k");
0042 
0043     // Create the about data for Smb4K
0044     KAboutData aboutData(QStringLiteral("smb4k"),
0045                          i18n("Smb4K"),
0046                          QStringLiteral(SMB4K_VERSION_STRING),
0047                          i18n("Advanced network neighborhood browser and Samba share mounting utility"),
0048                          KAboutLicense::GPL_V2,
0049                          i18n("\u00A9 2003-2023 Alexander Reinholdt"),
0050                          QString(),
0051                          QStringLiteral("https://smb4k.sourceforge.io"));
0052 
0053     // DBus prefix
0054     aboutData.setOrganizationDomain("kde.org");
0055     aboutData.setDesktopFileName(QStringLiteral("org.kde.") + aboutData.componentName());
0056 
0057     // Authors
0058     aboutData.addAuthor(i18n("Alexander Reinholdt"), i18n("Developer"), QStringLiteral("alexander.reinholdt@kdemail.net"));
0059 
0060     // Credits:
0061     // People who supported the Smb4K development by donating
0062     // money
0063     aboutData.addCredit(i18n("Wolfgang Geisendörfer"), i18n("Donator"), QStringLiteral("wdm-lin@gmx.net"));
0064 
0065     // Register about data
0066     KAboutData::setApplicationData(aboutData);
0067 
0068     // Now add the data to the application
0069     app.setApplicationName(aboutData.componentName());
0070     app.setApplicationDisplayName(aboutData.displayName());
0071     app.setOrganizationDomain(aboutData.organizationDomain());
0072     app.setApplicationVersion(aboutData.version());
0073 
0074     // We need to set this property because otherwise the application
0075     // will quit when it is embedded into the system tray, the main window
0076     // is hidden and the last window that was opened through the system
0077     // tray is closed.
0078     app.setQuitOnLastWindowClosed(false);
0079 
0080     // Program icon
0081     app.setWindowIcon(QIcon::fromTheme(QStringLiteral("smb4k")));
0082 
0083     // Launch the main window
0084     Smb4KMainWindow *mainWindow = new Smb4KMainWindow();
0085     mainWindow->setVisible(!Smb4KSettings::startMainWindowDocked());
0086 
0087     // Initialize the core. Use a busy cursor.
0088     initCore(true);
0089 
0090     // Unique application
0091     const KDBusService service(KDBusService::Unique);
0092 
0093     QObject::connect(&service, &KDBusService::activateRequested, mainWindow, [mainWindow](const QStringList & /*args*/, const QString & /*workingDir*/) {
0094         if (mainWindow->isVisible()) {
0095             KWindowSystem::updateStartupId(mainWindow->windowHandle());
0096             KWindowSystem::activateWindow(mainWindow->windowHandle());
0097         } else {
0098             mainWindow->setVisible(true);
0099         }
0100     });
0101 
0102     // Use a crash handler
0103     KCrash::setDrKonqiEnabled(true);
0104 
0105     // Start the application
0106     return app.exec();
0107 }