From e9a9d742d6f596193f846024add2cda5190ac80e Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sat, 7 Jun 2014 18:27:08 +0200 Subject: [PATCH] Fixed sftp plugin crashing when mounting Removed sftp notificatons and some configuration options Homogenized coding style --- kded/kdeconnect.notifyrc | 83 ---------------- kded/plugins/sftp/sftp_config.cpp | 8 +- kded/plugins/sftp/sftp_config.ui | 118 ++++++++--------------- kded/plugins/sftp/sftpplugin.cpp | 52 ++++------ kded/plugins/sftp/sftpplugin.h | 5 - plasmoid/package/contents/ui/Battery.qml | 10 +- plasmoid/package/contents/ui/Sftp.qml | 42 ++------ 7 files changed, 70 insertions(+), 248 deletions(-) diff --git a/kded/kdeconnect.notifyrc b/kded/kdeconnect.notifyrc index 656943dc4..735080fb9 100644 --- a/kded/kdeconnect.notifyrc +++ b/kded/kdeconnect.notifyrc @@ -389,86 +389,3 @@ Comment[tr]=Bilinmeyen bir durum oluştu Comment[uk]=Сталося щось невідоме програмі Comment[x-test]=xxSomething unknown happenedxx Action=Popup - -[Event/mounted] -Name=Mounted -Name[bg]=Монтирана -Name[ca]=Muntada -Name[cs]=Připojen -Name[da]=Monteret -Name[de]=Eingebunden -Name[fr]=Monté -Name[hu]=Csatolva -Name[ko]=마운트됨 -Name[nl]=Aangekoppeld -Name[pl]=Zamontowany -Name[pt]=Montado -Name[pt_BR]=Montado -Name[ro]=Montat -Name[sk]=Pripojené -Name[sv]=Monterat -Name[tr]=Bağlı -Name[uk]=Змонтовано -Name[x-test]=xxMountedxx -Comment=Filesystem mounted -Comment[bg]=Файловата система е монтирана -Comment[ca]=Sistema de fitxers muntat -Comment[cs]=Souborový systém byl připojen -Comment[da]=Filsystem monteret -Comment[de]=Dateisystem eingebunden -Comment[fr]=Système de fichiers monté -Comment[hu]=Fájlrendszer csatolva -Comment[ko]=파일 시스템 마운트됨 -Comment[nl]=Bestandssysteem aangekoppeld -Comment[pl]=Zamontowano system plików -Comment[pt]=Sistema de ficheiros montado -Comment[pt_BR]=Sistema de arquivos montado -Comment[ro]=Sistem de fișiere montat -Comment[sk]=Súborový systém pripojený -Comment[sv]=Filsystem monterat -Comment[tr]=Dosya sistemi bağlandı -Comment[uk]=Файлову систему змонтовано -Comment[x-test]=xxFilesystem mountedxx -Action=None - -[Event/unmounted] -Name=Unmounted -Name[bg]=Демонтирана -Name[ca]=Desmuntat -Name[cs]=Odpojen -Name[da]=Afmonteret -Name[de]=Einbindung gelöst -Name[fr]=Libéré -Name[hu]=Leválasztva -Name[ko]=마운트 해제됨 -Name[nl]=Afgekoppeld -Name[pl]=Odmontowano -Name[pt]=Desmontado -Name[pt_BR]=Desmontado -Name[ro]=Nemontat -Name[sk]=Nepripojený -Name[sv]=Avmonterat -Name[tr]=Ayrıldı -Name[uk]=Демонтовано -Name[x-test]=xxUnmountedxx -Comment=Filesystem unmounted -Comment[bg]=Файловата система е демонтирана -Comment[ca]=Sistema de fitxers desmuntat -Comment[cs]=Souborový systém byl odpojen -Comment[da]=Filsystem afmonteret -Comment[de]=Einbindung des Dateisystems gelöst -Comment[fr]=Système de fichiers libéré -Comment[hu]=Fájlrendszer leválasztva -Comment[ko]=파일 시스템 마운트 해제됨 -Comment[nl]=Bestandssysteem afgekoppeld -Comment[pl]=Odmontowano system plików -Comment[pt]=Sistema de ficheiros desmontado -Comment[pt_BR]=Sistema de arquivos desmontado -Comment[ro]=Sistem de fișiere nemontat -Comment[sk]=Súborový systém odpojený -Comment[sv]=Filsystem avmonterat -Comment[tr]=Dosya sistemi ayrıldı -Comment[uk]=Файлову систему демонтовано -Comment[x-test]=xxFilesystem unmountedxx -Action=None - diff --git a/kded/plugins/sftp/sftp_config.cpp b/kded/plugins/sftp/sftp_config.cpp index 05f26223f..4f67213ce 100644 --- a/kded/plugins/sftp/sftp_config.cpp +++ b/kded/plugins/sftp/sftp_config.cpp @@ -46,7 +46,6 @@ SftpConfig::SftpConfig(QWidget *parent, const QVariantList& ) connect(m_ui->refresh, SIGNAL(clicked(bool)), this, SLOT(checkSshfs())); - connect(m_ui->mountpoint, SIGNAL(textChanged(QString)), this, SLOT(changed())); connect(m_ui->idle, SIGNAL(toggled(bool)), this, SLOT(changed())); connect(m_ui->timeout, SIGNAL(valueChanged(int)), this, SLOT(changed())); } @@ -65,8 +64,6 @@ void SftpConfig::defaults() KCModule::defaults(); checkSshfs(); - m_ui->mountpoint->setUrl(m_cfg->group("main").readEntry("mountpoint" - , KStandardDirs::locateLocal("appdata", "", true, SftpPlugin::componentData()))); m_ui->idle->setChecked(m_cfg->group("main").readEntry("idle", true)); m_ui->timeout->setValue(m_cfg->group("main").readEntry("idletimeout", 10)); @@ -79,8 +76,6 @@ void SftpConfig::load() KCModule::load(); checkSshfs(); - m_ui->mountpoint->setUrl(m_cfg->group("main").readEntry("mountpoint" - , KStandardDirs::locateLocal("appdata", "", true, SftpPlugin::componentData()))); m_ui->idle->setChecked(m_cfg->group("main").readEntry("idle", true)); m_ui->timeout->setValue(m_cfg->group("main").readEntry("idletimeout", 10)); @@ -93,8 +88,7 @@ void SftpConfig::save() checkSshfs(); m_cfg->group("main").writeEntry("idle", m_ui->idle->isChecked()); m_cfg->group("main").writeEntry("idletimeout", m_ui->timeout->value()); - m_cfg->group("main").writeEntry("mountpoint", m_ui->mountpoint->url().url()); - + KCModule::save(); Q_EMIT changed(false); } diff --git a/kded/plugins/sftp/sftp_config.ui b/kded/plugins/sftp/sftp_config.ui index 8f666988a..9a080dc9a 100644 --- a/kded/plugins/sftp/sftp_config.ui +++ b/kded/plugins/sftp/sftp_config.ui @@ -9,51 +9,15 @@ 0 0 - 303 - 155 + 505 + 127 Share plugin settings - - - - - false - - - KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly - - - - - - - - - - Qt::Vertical - - - - 291 - 26 - - - - - - - - Disconnect when idle - - - true - - - - + + Error @@ -101,23 +65,7 @@ - - - - - 0 - 0 - - - - Mountpoint: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - + QFrame::NoFrame @@ -132,6 +80,29 @@ 0 + + + + Disconnect when idle + + + true + + + + + + + Qt::Horizontal + + + + 53 + 20 + + + + @@ -170,31 +141,24 @@ - - - - Qt::Horizontal - - - - 53 - 20 - - - - + + + + Qt::Vertical + + + + 291 + 26 + + + + - - - KUrlRequester - QFrame -
kurlrequester.h
-
-
diff --git a/kded/plugins/sftp/sftpplugin.cpp b/kded/plugins/sftp/sftpplugin.cpp index d6b7cb41f..6a9a5649f 100644 --- a/kded/plugins/sftp/sftpplugin.cpp +++ b/kded/plugins/sftp/sftpplugin.cpp @@ -87,15 +87,14 @@ void SftpPlugin::removeFromDolphin() void SftpPlugin::connected() { - kDebug(kdeconnect_kded()) << "Exposing DBUS interface: " - << QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents); + bool state = QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents); + kDebug(kdeconnect_kded()) << "Exposing DBUS interface: " << state; } void SftpPlugin::mount() { - kDebug(kdeconnect_kded()) << "Device:" << device()->name(); - if (m_d->mounter) - { + kDebug(kdeconnect_kded()) << "Mount device:" << device()->name(); + if (m_d->mounter) { return; } @@ -113,8 +112,11 @@ void SftpPlugin::mount() void SftpPlugin::unmount() { - //FIXME - if (m_d->mounter) m_d->mounter->deleteLater(); + if (m_d->mounter) + { + m_d->mounter->deleteLater(); + m_d->mounter = 0; + } } bool SftpPlugin::mountAndWait() @@ -130,8 +132,7 @@ bool SftpPlugin::isMounted() const bool SftpPlugin::startBrowsing() { - if (mountAndWait()) - { + if (mountAndWait()) { //return new KRun(KUrl::fromLocalFile(mountPoint()), 0); return new KRun(KUrl::fromPathOrUrl("kdeconnect://"+device()->id()), 0); } @@ -153,8 +154,7 @@ bool SftpPlugin::receivePackage(const NetworkPackage& np) QString SftpPlugin::mountPoint() { - const QString defaultMountDir = KStandardDirs::locateLocal("appdata", "", true, componentData()); - const QString mountDir = KConfig("kdeconnect/plugins/sftp").group("main").readEntry("mountpoint", defaultMountDir); + const QString mountDir = KStandardDirs::locateLocal("appdata", "", true, KComponentData("kdeconnect", "kdeconnect")); return QDir(mountDir).absoluteFilePath(device()->id()); } @@ -162,36 +162,18 @@ void SftpPlugin::onMounted() { kDebug(kdeconnect_kded()) << device()->name() << QString("Remote filesystem mounted at %1").arg(mountPoint()); - KNotification* notification = new KNotification("mounted", KNotification::CloseOnTimeout, this); - notification->setPixmap(KIconLoader::global()->loadIcon("drive-removable-media", KIconLoader::Desktop)); - notification->setComponentData(KComponentData("kdeconnect", "kdeconnect-kded")); - notification->setTitle(i18n("Device %1", device()->name())); - notification->setText(i18n("Filesystem mounted at %1", mountPoint())); - notification->sendEvent(); - Q_EMIT mounted(); } void SftpPlugin::onUnmounted(bool idleTimeout) { - if (idleTimeout) - { + if (idleTimeout) { kDebug(kdeconnect_kded()) << device()->name() << "Remote filesystem unmounted by idle timeout"; - } - else - { + } else { kDebug(kdeconnect_kded()) << device()->name() << "Remote filesystem unmounted"; } - KNotification* notification = new KNotification("unmounted", KNotification::CloseOnTimeout, this); - notification->setPixmap(KIconLoader::global()->loadIcon("dialog-ok", KIconLoader::Desktop)); - notification->setComponentData(KComponentData("kdeconnect", "kdeconnect")); - notification->setTitle(i18n("Device %1", device()->name())); - notification->setText(i18n("Filesystem unmounted")); - notification->sendEvent(); - - m_d->mounter->deleteLater(); - m_d->mounter = 0; + unmount(); Q_EMIT unmounted(); } @@ -202,9 +184,9 @@ void SftpPlugin::onFailed(const QString& message) , message , KIconLoader::global()->loadIcon("dialog-error", KIconLoader::Desktop) ); - m_d->mounter->deleteLater(); - m_d->mounter = 0; - + + unmount(); + Q_EMIT unmounted(); } diff --git a/kded/plugins/sftp/sftpplugin.h b/kded/plugins/sftp/sftpplugin.h index 24b556052..6189a2146 100644 --- a/kded/plugins/sftp/sftpplugin.h +++ b/kded/plugins/sftp/sftpplugin.h @@ -38,11 +38,6 @@ public: explicit SftpPlugin(QObject *parent, const QVariantList &args); virtual ~SftpPlugin(); - inline static KComponentData componentData() - { - return KComponentData("kdeconnect", "kdeconnect"); - } - Q_SIGNALS: void packageReceived(const NetworkPackage& np); diff --git a/plasmoid/package/contents/ui/Battery.qml b/plasmoid/package/contents/ui/Battery.qml index 31c537caa..6fcb7c456 100644 --- a/plasmoid/package/contents/ui/Battery.qml +++ b/plasmoid/package/contents/ui/Battery.qml @@ -48,18 +48,17 @@ QtObject { onSuccess: root.charge = result } - /* Note: magically called by qml */ + // Note: magically called by qml onAvailableChanged: { if (available) { battery = DeviceBatteryDbusInterfaceFactory.create(deviceId) battery.stateChanged.connect(function(charging) {root.charging = charging}) battery.chargeChanged.connect(function(charge) {root.charge = charge}) - + startupCheck1.setPendingCall(battery.isCharging()) startupCheck2.setPendingCall(battery.charge()) - } - else { + } else { battery = null } } @@ -69,8 +68,7 @@ QtObject { if (result && result != "error") { available = true - } - else { + } else { available = false } } diff --git a/plasmoid/package/contents/ui/Sftp.qml b/plasmoid/package/contents/ui/Sftp.qml index cd9760414..5a2437b92 100644 --- a/plasmoid/package/contents/ui/Sftp.qml +++ b/plasmoid/package/contents/ui/Sftp.qml @@ -31,58 +31,30 @@ QtObject { property variant device: DeviceDbusInterfaceFactory.create(deviceId) property bool available: false - property bool isMounted: false property variant sftp: null - property variant nested: DBusAsyncResponse { - id: startupCheck - onSuccess: (result) ? root.mounted() : root.unmounted() - onError: root.error(message) - } - - signal mounted - signal unmounted - signal error(string message) - - onMounted: isMounted = true - onUnmounted: isMounted = false function browse() { - startupCheck.setPendingCall(sftp.startBrowsing()) - } - - function unmount() { - sftp.unmount() + if (sftp) + sftp.startBrowsing(); } Component.onCompleted: { device.pluginsChanged.connect(pluginsChanged) - device.pluginsChanged() + pluginsChanged() } - /* Note: magically called by qml */ + // Note: magically called by qml onAvailableChanged: { if (available) { sftp = SftpDbusInterfaceFactory.create(deviceId) - - sftp.mounted.connect(mounted) - sftp.unmounted.connect(unmounted) - - startupCheck.setPendingCall(sftp.isMounted()) - } - else { + } else { sftp = null } } - + function pluginsChanged() { var result = DBusResponseWaiter.waitForReply(device.hasPlugin("kdeconnect_sftp")) - - if (result && result != "error") { - available = true - } - else { - available = false - } + available = (result && result != "error"); } }