File indexing completed on 2024-04-28 05:47:27
0001 /************************************************************************************* 0002 * Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU General Public License * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the Free Software * 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0017 ************************************************************************************/ 0018 0019 #include "onstart.h" 0020 0021 #include <QApplication> 0022 0023 #include <KAuthAction> 0024 #include <KAuthExecuteJob> 0025 #include <kconfiggroup.h> 0026 #include <ksharedconfig.h> 0027 0028 #include <QDebug> 0029 #include <unistd.h> 0030 0031 using namespace KAuth; 0032 0033 OnStart::OnStart(QObject* parent) 0034 : QObject(parent) 0035 , m_someFailed(false) 0036 { 0037 QMetaObject::invokeMethod(this, "mountConfiguredShares", Qt::QueuedConnection); 0038 0039 connect(&m_networkConfigurationManager, &QNetworkConfigurationManager::configurationAdded, this, &OnStart::mountConfiguredShares) ; 0040 connect(&m_networkConfigurationManager, &QNetworkConfigurationManager::configurationChanged, this, &OnStart::mountConfiguredShares) ; 0041 } 0042 0043 OnStart::~OnStart() 0044 { 0045 0046 } 0047 0048 void OnStart::mountConfiguredShares() 0049 { 0050 if(!m_networkConfigurationManager.isOnline()) { 0051 return; 0052 } 0053 0054 KConfigGroup group = KSharedConfig::openConfig("samba-mounter")->group("mounts"); 0055 0056 m_someFailed = false; 0057 QStringList nameList = group.groupList(); 0058 Q_FOREACH(const QString &name, nameList) { 0059 mountSamba(group.group(name)); 0060 } 0061 0062 //if it failed, don't quit, it might be because there's no network connection 0063 if (!m_someFailed) { 0064 qDebug() << "Exiting"; 0065 qApp->quit(); 0066 } 0067 } 0068 0069 void OnStart::mountSamba(KConfigGroup group) 0070 { 0071 Action readAction("org.kde.sambamounter.mount"); 0072 readAction.setHelperId("org.kde.sambamounter"); 0073 0074 readAction.addArgument("uid", QString::number(getuid())); 0075 readAction.addArgument("ip", group.readEntry("ip", "")); 0076 readAction.addArgument("locale", getenv("LANG")); 0077 readAction.addArgument("path", getenv("PATH")); 0078 readAction.addArgument("sambaDir", group.readEntry("sambaDir", "").toLocal8Bit().toBase64()); 0079 readAction.addArgument("mountPoint", group.readEntry("mountPoint", "").toLocal8Bit().toBase64()); 0080 readAction.addArgument("username", group.readEntry("username", "none").toLocal8Bit().toBase64()); 0081 readAction.addArgument("password", group.readEntry("password", "none").toLocal8Bit().toBase64()); 0082 0083 ExecuteJob* reply = readAction.execute(); 0084 bool ret = reply->exec(); 0085 0086 qDebug() << reply->data()["output"]; 0087 qDebug() << reply->data()["error"]; 0088 if (!ret) { 0089 m_someFailed = true; 0090 } 0091 }