Skip to content

Commit

Permalink
[kmail] added NetworkManager support
Browse files Browse the repository at this point in the history
  • Loading branch information
serghei committed May 3, 2013
1 parent a32b14d commit 0577b2e
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kmail/CMakeLists.txt
Expand Up @@ -177,7 +177,7 @@ set( ${target}_SRCS
localsubscriptiondialog.cpp editorwatcher.cpp favoritefolderview.cpp
foldertreebase.cpp snippetdlgbase.ui snippetwidget.cpp snippetconfig.cpp
snippetdlg.cpp snippetitem.cpp snippetsettings.cpp snippetsettingsbase.ui
messageactions.cpp korghelper.cpp
messageactions.cpp korghelper.cpp kmnetworkmonitor.cpp
${CMAKE_SOURCE_DIR}/korganizer/kcalendariface.stub
kmailIface.skel_ng kmailicalIface.skel_ng
${CMAKE_SOURCE_DIR}/korganizer/korganizeriface.stub )
Expand All @@ -186,7 +186,7 @@ kde_add_library( ${target} SHARED AUTOMOC
SOURCES ${${target}_SRCS}
LINK
emailfunctions-static kmime-shared kpgp-shared kdepim-shared kpimidentities-shared
mimelib-shared ksieve-shared khtml-shared ${INDEX_LIBRARY}
mimelib-shared ksieve-shared khtml-shared kdedbus-shared ${INDEX_LIBRARY}
DESTINATION ${LIB_INSTALL_DIR}
)

Expand Down
12 changes: 12 additions & 0 deletions kmail/kmkernel.cpp
Expand Up @@ -70,6 +70,7 @@ using KMail::FolderIface;
#include <kwallet.h>
using KWallet::Wallet;
#include "actionscheduler.h"
#include "kmnetworkmonitor.h"

#include <qutf7codec.h>
#include <qvbox.h>
Expand Down Expand Up @@ -166,6 +167,9 @@ KMKernel::KMKernel (QObject *parent, const char *name) :

connectDCOPSignal( 0, 0, "kmailSelectFolder(QString)",
"selectFolder(QString)", false );

networkMonitor = new KMNetworkMonitor(this, "KMNetworkMonitor");
connect(networkMonitor, SIGNAL(stateChanged(bool)), SLOT(slotNetworkStateChanged(bool)));
}

KMKernel::~KMKernel ()
Expand Down Expand Up @@ -1946,6 +1950,14 @@ void KMKernel::slotResult(KIO::Job *job)
mPutJobs.remove(it);
}

void KMKernel::slotNetworkStateChanged(bool state)
{
if(state)
resumeNetworkJobs();
else
stopNetworkJobs();
}

void KMKernel::slotRequestConfigSync() {
// ### FIXME: delay as promised in the kdoc of this function ;-)
KMKernel::config()->sync();
Expand Down
5 changes: 5 additions & 0 deletions kmail/kmkernel.h
Expand Up @@ -28,6 +28,8 @@ namespace KWallet {
class Wallet;
}

class KMNetworkMonitor;

/** The KMail namespace contains classes used for KMail.
* This is to keep them out of the way from all the other
* un-namespaced classes in libs and the rest of PIM.
Expand Down Expand Up @@ -412,6 +414,7 @@ public slots:
protected slots:
void slotDataReq(KIO::Job*,QByteArray&);
void slotResult(KIO::Job*);
void slotNetworkStateChanged(bool);

signals:
void configChanged();
Expand Down Expand Up @@ -495,6 +498,8 @@ protected slots:

KWallet::Wallet *mWallet;

KMNetworkMonitor *networkMonitor;

// variables used by dcopAddMessage()
QStringList mAddMessageMsgIds;
QString mAddMessageLastFolder;
Expand Down
116 changes: 116 additions & 0 deletions kmail/kmnetworkmonitor.cpp
@@ -0,0 +1,116 @@
/*
This file is part of the KDE3 Fork Project
Copyright (c) 2013 Serghei Amelian <serghei.amelian@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/

#include <qtimer.h>

#include <dbus/qdbusconnection.h>
#include <dbus/qdbuserror.h>
#include <dbus/qdbusmessage.h>
#include <dbus/qdbusproxy.h>

#include <kdebug.h>

#include "kmnetworkmonitor.h"


class KMNetworkMonitorPrivate : public QDBusProxy {

Q_OBJECT

public:
KMNetworkMonitorPrivate(KMNetworkMonitor *parent)
: QDBusProxy(parent, "KMNetworkMonitorPrivate"), lastStatus(-1)
{
setService("org.freedesktop.NetworkManager");
setPath("/org/freedesktop/NetworkManager");
setInterface("org.freedesktop.NetworkManager");

QTimer::singleShot(0, this, SLOT(initialize()));
}

protected slots:
void initialize()
{
// connect to DBUS
QDBusConnection dbus = QDBusConnection::systemBus();
if(!dbus.isConnected()) {
kdDebug() << "Unable to connect to DBus: " << dbus.lastError().message() << endl;
return;
}
setConnection(dbus);

// check for current status
int rc = sendWithAsyncReply("state", QValueList<QDBusData>());
if(0 == rc) {
kdDebug() << "Unable to send \"state\" command to DBus" << endl;
return;
}
}

void handleDBusSignal(const QDBusMessage &message)
{
// the message is for us
if(path() == message.path() && interface() == message.interface() && "StateChanged" == message.member())
handleMessage(message);
}

void handleAsyncReply(const QDBusMessage &message)
{
handleMessage(message);
}

void handleMessage(const QDBusMessage &message)
{
bool ok;
Q_UINT32 state = message[0].toUInt32(&ok);

if(!ok) {
kdDebug() << "KMNetworkMonitor: received unexpected type for state (" << message[0].typeName() << ")" << endl;
return;
}

int currStatus = (50 < state ? 1 : 0);

if(lastStatus != currStatus) {
emit static_cast<KMNetworkMonitor*>(parent())->stateChanged(1 == currStatus);
lastStatus = currStatus;
}
}

private:
// -1 = unitialized, 0 = offline, 1 = online
int lastStatus;
};


KMNetworkMonitor::KMNetworkMonitor(QObject *parent, const char *name)
: QObject(parent, name)
{
d = new KMNetworkMonitorPrivate(this);
}


KMNetworkMonitor::~KMNetworkMonitor()
{
delete d;
}


#include "kmnetworkmonitor.moc"
#include "kmnetworkmonitor.cpp.moc"
45 changes: 45 additions & 0 deletions kmail/kmnetworkmonitor.h
@@ -0,0 +1,45 @@
/*
This file is part of the KDE3 Fork Project
Copyright (c) 2013 Serghei Amelian <serghei.amelian@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _KMNETWORKMONITOR_H_
#define _KMNETWORKMONITOR_H_

#include <qobject.h>

class KMNetworkMonitorPrivate;


class KMNetworkMonitor : public QObject {

Q_OBJECT

friend class KMNetworkMonitorPrivate;

public:
KMNetworkMonitor(QObject *parent = 0, const char *name = 0);
~KMNetworkMonitor();

signals:
void stateChanged(bool);

private:
KMNetworkMonitorPrivate *d;
};


#endif

0 comments on commit 0577b2e

Please sign in to comment.