Warning, file /network/smb4k/smb4k/main.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /***************************************************************************
0002     Main file of the Smb4K program.
0003                              -------------------
0004     begin                : Sam Mär  1 14:57:21 CET 2003
0005     copyright            : (C) 2003-2016 by Alexander Reinholdt
0006     email                : alexander.reinholdt@kdemail.net
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *   This program is free software; you can redistribute it and/or modify  *
0011  *   it under the terms of the GNU General Public License as published by  *
0012  *   the Free Software Foundation; either version 2 of the License, or     *
0013  *   (at your option) any later version.                                   *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful, but   *
0016  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
0018  *   General Public License for more details.                              *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program; if not, write to the                         *
0022  *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
0023  *   MA 02110-1335, USA                                                    *
0024  ***************************************************************************/
0025 
0026 #include <config.h>
0027 
0028 // application specific includes
0029 #include "smb4kmainwindow.h"
0030 #include "core/smb4ksettings.h"
0031 #include "core/smb4kglobal.h"
0032 
0033 // Qt includes
0034 #include <QString>
0035 #include <QApplication>
0036 
0037 // KDE includes
0038 #include <KI18n/KLocalizedString>
0039 #include <KCoreAddons/KAboutData>
0040 #include <KCoreAddons/Kdelibs4ConfigMigrator>
0041 #include <KCoreAddons/Kdelibs4Migration>
0042 #include <KDBusAddons/KDBusService>
0043 #include <KCrash/KCrash>
0044 
0045 using namespace Smb4KGlobal;
0046 
0047 
0048 int main(int argc, char **argv)
0049 {
0050   // Migrate KDE4 configuration and XML files 
0051   QStringList configFiles;
0052   configFiles << QLatin1String("smb4krc");
0053   
0054   Kdelibs4ConfigMigrator migrator(QLatin1String("smb4k"));
0055   migrator.setConfigFiles(configFiles);
0056   
0057   if (migrator.migrate())
0058   {
0059     Kdelibs4Migration migration;
0060     
0061     if (migration.kdeHomeFound())
0062     {
0063       //
0064       // NOTE: We need the 'smb4k' subdirectory, since no QApplication 
0065       // is running at this point.
0066       //
0067       
0068       // New location
0069       QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)+QDir::separator()+"smb4k";
0070       
0071       // XML files
0072       QString bookmarks = migration.locateLocal("data", "smb4k/bookmarks.xml");
0073       QString options = migration.locateLocal("data", "smb4k/custom_options.xml");
0074       QString homes = migration.locateLocal("data", "smb4k/homes_shares.xml");
0075       
0076       // Copy the files if they don't already exist
0077       if (!bookmarks.isEmpty() && QFile().exists(bookmarks))
0078       {
0079         if (!QDir().exists(path))
0080         {
0081           QDir().mkpath(path);
0082         }
0083         else
0084         {
0085           // Do nothing
0086         }
0087         
0088         QFile(bookmarks).copy(path+QDir::separator()+"bookmarks.xml");
0089       }
0090       else
0091       {
0092         // Do nothing
0093       }
0094       
0095       if (!options.isEmpty() && QFile().exists(options))
0096       {
0097         if (!QDir().exists(path))
0098         {
0099           QDir().mkpath(path);
0100         }
0101         else
0102         {
0103           // Do nothing
0104         }
0105         
0106         QFile(options).copy(path+QDir::separator()+"custom_options.xml");
0107       }
0108       else
0109       {
0110         // Do nothing
0111       }
0112       
0113       if (!homes.isEmpty() && QFile().exists(homes))
0114       {
0115         if (!QDir().exists(path))
0116         {
0117           QDir().mkpath(path);
0118         }
0119         else
0120         {
0121           // Do nothing
0122         }
0123         
0124         QFile(homes).copy(path+QDir::separator()+"homes_shares.xml");
0125       }
0126       else
0127       {
0128         // Do nothing
0129       }
0130     }
0131     else
0132     {
0133       // Do nothing
0134     }
0135   }
0136   else
0137   {
0138     // Do nothing
0139   }
0140   
0141   // Set attributes
0142   QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
0143   
0144   // Create the application
0145   QApplication app(argc, argv);
0146   
0147   // Connect the application with the translation catalog
0148   KLocalizedString::setApplicationDomain("smb4k");
0149   
0150   // Create the about data for Smb4K  
0151   KAboutData aboutData(QStringLiteral("smb4k"), i18n("Smb4K"), QStringLiteral(VERSION),
0152     i18n("Advanced network neighborhood browser and Samba share mounting utility"),
0153     KAboutLicense::GPL_V2, i18n("\u00A9 2003-2019 Alexander Reinholdt"), QString(), 
0154     QStringLiteral("https://smb4k.sourceforge.io"));
0155   
0156   // DBus prefix
0157   aboutData.setOrganizationDomain("kde.org");
0158   
0159   // Authors
0160   aboutData.addAuthor(i18n("Alexander Reinholdt"), i18n("Developer"), QStringLiteral("alexander.reinholdt@kdemail.net"));
0161   
0162   // Credits:
0163   // People who supported the Smb4K development by donating
0164   // money
0165   aboutData.addCredit(i18n("Wolfgang Geisendörfer"), i18n("Donator"), QStringLiteral("wdm-lin@gmx.net"));
0166   
0167   // Register about data
0168   KAboutData::setApplicationData(aboutData);
0169   
0170   // Now add the data to the application
0171   app.setApplicationName(aboutData.componentName());
0172   app.setApplicationDisplayName(aboutData.displayName());
0173   app.setOrganizationDomain(aboutData.organizationDomain());
0174   app.setApplicationVersion(aboutData.version());
0175   
0176   // We need to set this property because otherwise the application
0177   // will quit when it is embedded into the system tray, the main window
0178   // is hidden and the last window that was opened through the system
0179   // tray is closed.
0180   app.setQuitOnLastWindowClosed(false);
0181   
0182   // Support high dpi screens
0183   app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
0184   
0185   // Program icon
0186   app.setWindowIcon(QIcon::fromTheme(QLatin1String("smb4k")));
0187   
0188   // Launch the main window
0189   Smb4KMainWindow *mainWindow = new Smb4KMainWindow();
0190   mainWindow->setVisible(!Smb4KSettings::startMainWindowDocked());
0191 
0192   // Initialize the core. Use a busy cursor.
0193   initCore(true);
0194   
0195   // Unique application
0196   const KDBusService service(KDBusService::Unique);
0197   
0198   // Use a crash handler
0199   KCrash::setDrKonqiEnabled(true);
0200   
0201   // Start the application
0202   return app.exec();
0203 }