summaryrefslogtreecommitdiffstats
path: root/kopete/plugins/connectionstatus
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/plugins/connectionstatus
downloadtdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz
tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/plugins/connectionstatus')
-rw-r--r--kopete/plugins/connectionstatus/Makefile.am12
-rw-r--r--kopete/plugins/connectionstatus/connectionstatusplugin.cpp137
-rw-r--r--kopete/plugins/connectionstatus/connectionstatusplugin.h58
-rw-r--r--kopete/plugins/connectionstatus/kopete_connectionstatus.desktop125
4 files changed, 332 insertions, 0 deletions
diff --git a/kopete/plugins/connectionstatus/Makefile.am b/kopete/plugins/connectionstatus/Makefile.am
new file mode 100644
index 00000000..7fcb3ed8
--- /dev/null
+++ b/kopete/plugins/connectionstatus/Makefile.am
@@ -0,0 +1,12 @@
+METASOURCES = AUTO
+
+AM_CPPFLAGS = $(KOPETE_INCLUDES) $(all_includes)
+
+kde_module_LTLIBRARIES = kopete_connectionstatus.la
+
+kopete_connectionstatus_la_SOURCES = connectionstatusplugin.cpp
+kopete_connectionstatus_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
+kopete_connectionstatus_la_LIBADD = ../../libkopete/libkopete.la
+
+service_DATA = kopete_connectionstatus.desktop
+servicedir = $(kde_servicesdir)
diff --git a/kopete/plugins/connectionstatus/connectionstatusplugin.cpp b/kopete/plugins/connectionstatus/connectionstatusplugin.cpp
new file mode 100644
index 00000000..8840c893
--- /dev/null
+++ b/kopete/plugins/connectionstatus/connectionstatusplugin.cpp
@@ -0,0 +1,137 @@
+/*
+ connectionstatusplugin.cpp
+
+ Copyright (c) 2002-2003 by Chris Howells <howells@kde.org>
+ Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
+
+ Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
+
+ *************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; version 2 of the License. *
+ * *
+ *************************************************************************
+*/
+
+#include "connectionstatusplugin.h"
+
+#include <qtimer.h>
+
+#include <kdebug.h>
+#include <kgenericfactory.h>
+#include <kprocess.h>
+
+#include "kopeteaccountmanager.h"
+
+typedef KGenericFactory<ConnectionStatusPlugin> ConnectionStatusPluginFactory;
+K_EXPORT_COMPONENT_FACTORY( kopete_connectionstatus, ConnectionStatusPluginFactory( "kopete_connectionstatus" ) )
+
+ConnectionStatusPlugin::ConnectionStatusPlugin( QObject *parent, const char *name, const QStringList& /* args */ )
+: Kopete::Plugin( ConnectionStatusPluginFactory::instance(), parent, name )
+{
+ kdDebug( 14301 ) << k_funcinfo << endl;
+
+ m_process = 0L;
+
+ m_timer = new QTimer();
+ connect( m_timer, SIGNAL( timeout() ), this, SLOT( slotCheckStatus() ) );
+ m_timer->start( 60000 );
+
+ m_pluginConnected = false;
+}
+
+ConnectionStatusPlugin::~ConnectionStatusPlugin()
+{
+ kdDebug( 14301 ) << k_funcinfo << endl;
+ delete m_timer;
+ delete m_process;
+}
+
+void ConnectionStatusPlugin::slotCheckStatus()
+{
+ kdDebug( 14301 ) << k_funcinfo << endl;
+
+ if ( m_process )
+ {
+ kdWarning( 14301 ) << k_funcinfo << "Previous netstat process is still running!" << endl
+ << "Not starting new netstat. Perhaps your system is under heavy load?" << endl;
+
+ return;
+ }
+
+ m_buffer = QString::null;
+
+ // Use KProcess to run netstat -rn. We'll then parse the output of
+ // netstat -rn in slotProcessStdout() to see if it mentions the
+ // default gateway. If so, we're connected, if not, we're offline
+ m_process = new KProcess;
+ *m_process << "netstat" << "-r";
+
+ connect( m_process, SIGNAL( receivedStdout( KProcess *, char *, int ) ), this, SLOT( slotProcessStdout( KProcess *, char *, int ) ) );
+ connect( m_process, SIGNAL( processExited( KProcess * ) ), this, SLOT( slotProcessExited( KProcess * ) ) );
+
+ if ( !m_process->start( KProcess::NotifyOnExit, KProcess::Stdout ) )
+ {
+ kdWarning( 14301 ) << k_funcinfo << "Unable to start netstat process!" << endl;
+
+ delete m_process;
+ m_process = 0L;
+ }
+}
+
+void ConnectionStatusPlugin::slotProcessExited( KProcess *process )
+{
+ kdDebug( 14301 ) << m_buffer << endl;
+
+ if ( process == m_process )
+ {
+ setConnectedStatus( m_buffer.contains( "default" ) );
+ m_buffer = QString::null;
+ delete m_process;
+ m_process = 0L;
+ }
+}
+
+void ConnectionStatusPlugin::slotProcessStdout( KProcess *, char *buffer, int buflen )
+{
+ // Look for a default gateway
+ //kdDebug( 14301 ) << k_funcinfo << endl;
+ m_buffer += QString::fromLatin1( buffer, buflen );
+ //kdDebug( 14301 ) << qsBuffer << endl;
+}
+
+void ConnectionStatusPlugin::setConnectedStatus( bool connected )
+{
+ //kdDebug( 14301 ) << k_funcinfo << endl;
+
+ // We have to handle a few cases here. First is the machine is connected, and the plugin thinks
+ // we're connected. Then we don't do anything. Next, we can have machine connected, but plugin thinks
+ // we're disconnected. Also, machine disconnected, plugin disconnected -- we
+ // don't do anything. Finally, we can have the machine disconnected, and the plugin thinks we're
+ // connected. This mechanism is required so that we don't keep calling the connect/disconnect functions
+ // constantly.
+
+ if ( connected && !m_pluginConnected )
+ {
+ // The machine is connected and plugin thinks we're disconnected
+ kdDebug( 14301 ) << k_funcinfo << "Setting m_pluginConnected to true" << endl;
+ m_pluginConnected = true;
+ Kopete::AccountManager::self()->connectAll();
+ kdDebug( 14301 ) << k_funcinfo << "We're connected" << endl;
+ }
+ else if ( !connected && m_pluginConnected )
+ {
+ // The machine isn't connected and plugin thinks we're connected
+ kdDebug( 14301 ) << k_funcinfo << "Setting m_pluginConnected to false" << endl;
+ m_pluginConnected = false;
+ Kopete::AccountManager::self()->disconnectAll();
+ kdDebug( 14301 ) << k_funcinfo << "We're offline" << endl;
+ }
+}
+
+#include "connectionstatusplugin.moc"
+
+// vim: set noet ts=4 sts=4 sw=4:
+
diff --git a/kopete/plugins/connectionstatus/connectionstatusplugin.h b/kopete/plugins/connectionstatus/connectionstatusplugin.h
new file mode 100644
index 00000000..5f0a53bf
--- /dev/null
+++ b/kopete/plugins/connectionstatus/connectionstatusplugin.h
@@ -0,0 +1,58 @@
+/*
+ connectionstatusplugin.h
+
+ Copyright (c) 2002-2003 by Chris Howells <howells@kde.org>
+ Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
+
+ Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
+
+ *************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; version 2 of the License. *
+ * *
+ *************************************************************************
+*/
+
+#ifndef CONNECTIONSTATUSPLUGIN_H
+#define CONNECTIONSTATUSPLUGIN_H
+
+#include "kopeteplugin.h"
+
+class QTimer;
+class KProcess;
+
+/**
+ * @author Chris Howells <howells@kde.org>
+ */
+class ConnectionStatusPlugin : public Kopete::Plugin
+{
+ Q_OBJECT
+
+public:
+ ConnectionStatusPlugin( QObject *parent, const char *name, const QStringList &args );
+ ~ConnectionStatusPlugin();
+
+private slots:
+ void slotCheckStatus();
+ void slotProcessStdout( KProcess *process, char *buffer, int len );
+
+ /**
+ * Notify when the netstat process has exited
+ */
+ void slotProcessExited( KProcess *process );
+
+private:
+ void setConnectedStatus( bool newStatus );
+
+ bool m_pluginConnected;
+ KProcess *m_process;
+ QTimer *m_timer;
+ QString m_buffer;
+};
+
+#endif
+
+// vim: set noet ts=4 sts=4 sw=4:
+
diff --git a/kopete/plugins/connectionstatus/kopete_connectionstatus.desktop b/kopete/plugins/connectionstatus/kopete_connectionstatus.desktop
new file mode 100644
index 00000000..bbad7456
--- /dev/null
+++ b/kopete/plugins/connectionstatus/kopete_connectionstatus.desktop
@@ -0,0 +1,125 @@
+[Desktop Entry]
+Type=Service
+X-Kopete-Version=1000900
+ServiceTypes=Kopete/Plugin
+X-KDE-Library=kopete_connectionstatus
+X-KDE-PluginInfo-Author=Chris Howells
+X-KDE-PluginInfo-Email=howells@kde.org
+X-KDE-PluginInfo-Name=kopete_connectionstatus
+X-KDE-PluginInfo-Version=0.8.0
+X-KDE-PluginInfo-Website=http://kopete.kde.org
+X-KDE-PluginInfo-Category=Plugins
+X-KDE-PluginInfo-Depends=
+X-KDE-PluginInfo-License=GPL
+X-KDE-PluginInfo-EnabledByDefault=false
+Name=Connection Status
+Name[ar]=وضع الاتصال
+Name[be]=Стан злучэння
+Name[bg]=Състояние на връзката
+Name[bn]=সংযোগ অবস্থা
+Name[bs]=Status veze
+Name[ca]=Estatus de la connexió
+Name[cs]=Stav spojení
+Name[cy]=Cyflwr Cysylltiad
+Name[da]=Forbindelsesstatus
+Name[de]=Verbindungsstatus
+Name[el]=Κατάσταση σύνδεσης
+Name[eo]=Konektostato
+Name[es]=Estado de conexión
+Name[et]=Ühenduse staatus
+Name[eu]=Konexioaren egoera
+Name[fa]=وضعیت اتصال
+Name[fi]=Yhteyden tila
+Name[fr]=État de la connexion
+Name[ga]=Stádas Ceangail
+Name[gl]=Estado da conexión1
+Name[he]=מצב החיבור
+Name[hi]=कनेक्शन स्थिति
+Name[hr]=Status veze
+Name[hu]=A kapcsolat állapota
+Name[is]=Staða tengingar
+Name[it]=Stato della connessione
+Name[ja]=接続状況
+Name[ka]=კავშირის სტატუსი
+Name[kk]=Қосылымның күй-жайы
+Name[km]=ស្ថានភាព​តការ​​ភ្ជាប់
+Name[lt]=Ryšio būsena
+Name[mk]=Статус на поврзувањето
+Name[nb]=Tilstand for forbindelsen
+Name[nds]=Verbinnen-Status
+Name[ne]=जडान वस्तुस्थिति
+Name[nl]=Verbindingsstatus
+Name[nn]=Tilstand for sambandet
+Name[pa]=ਕੁਨੈਕਸ਼ਨ ਹਾਲਤ
+Name[pl]=Status połączenia
+Name[pt]=Estado da Ligação
+Name[pt_BR]=Status da Conexão
+Name[ro]=Stare conexiune
+Name[ru]=Статус соединения
+Name[se]=Oktavuohtástáhtus
+Name[sk]=Stav spojenia
+Name[sl]=Stanje povezave
+Name[sr]=Статус везе
+Name[sr@Latn]=Status veze
+Name[sv]=Anslutningsstatus
+Name[ta]=இணைப்பு நிலை
+Name[tg]=Ҳолати Пайвастшавӣ
+Name[tr]=Bağlantı Durumu
+Name[uk]=Стан з'єднання
+Name[uz]=Aloqaning holati
+Name[uz@cyrillic]=Алоқанинг ҳолати
+Name[wa]=Estat do raloyaedje
+Name[zh_CN]=连接状态
+Name[zh_HK]=連線狀態
+Name[zh_TW]=連線狀態
+Comment=Connects/disconnects Kopete automatically depending on availability of Internet connection
+Comment[ar]=يقوم بوصل و فصل Kopete تلقائيا استنادا إلى وضع الاتصال بالشبكة
+Comment[be]=Злучае/адлучае Kopete ад сервісаў у залежнасці ад наяўнасці інтэрфэйсаў з Інтэрнэтам
+Comment[bg]=Автоматично установяване и прекъсване на връзката в зависимост от състоянието на връзката с Интернет
+Comment[bn]=ইন্টারনেট সংযোগের সুবিধা অনুযায়ী কপেট স্বয়ংক্রীয়ভাবে সংযোগ/সংযোগবিচ্ছিন্নকরে
+Comment[bs]=Automatski spaja Kopete i prekida vezu ovisno o dostupnosti Internet konekcije
+Comment[ca]=Connecta/desconnecta automàticament depenent de la disponibilitat de la connexió a Internet
+Comment[cs]=Automaticky připojí nebo odpojí vzhledem k dostupnosti připojení na Internet
+Comment[cy]=Cysylltu/datgyslltu Kopete yn ymysgogol, yn dibynnu ar argaeledd cysylltiad Rhyngrwyd
+Comment[da]=Forbinder/afbryder Kopete automatisk afhængig af om der er en internet-forbindelse
+Comment[de]=Verbindet/trennt Kopete automatisch abhängig von der Verfügbarkeit einer Internetverbindung
+Comment[el]=Συνδέει/αποσυνδέει το Kopete αυτόματα ανάλογα με την κατάσταση της σύνδεσης με το διαδίκτυο
+Comment[es]=Conecta/desconecta Kopete automáticamente según la disponibilidad de la conexión a internet
+Comment[et]=Kopete automaatne ühendamine/ühenduse katkestamine vastavalt internetiühenduse olemasolule
+Comment[eu]=Kopete automatikoki konektatu/deskonektatzen du internet-eko konexioaren eskuragarritasunaren arabera
+Comment[fa]=بسته به قابلیت دسترسی اتصال اینترنت، Kopete به طور خودکار وصل/قطع ارتباط می‌کند
+Comment[fi]=Yhdistää/katkaisee yhteyden automaattisesti riippuen onko Internet-yhteys päällä
+Comment[fr]=Connecte / déconnecte automatiquement Kopete en fonction de la disponibilité de la connexion Internet
+Comment[gl]=Conecta/desconecta a Kopete automáticamente dependendo da disponibilidade de conexión a Internet
+Comment[he]=חיבור\ניתוק Kopete באופן אוטומטי בתלות בזמינות של החיבור לאינטרנט
+Comment[hi]=इंटरनेट कनेक्शन की उपलब्धता की निर्भरता के आधार पर के-ऑप्टी को स्वचलित कनेक्ट/डिस्कनेक्ट करता है
+Comment[hu]=A Kopete automatikus csatlakoztatása és bontása az internetkapcsolat elérhetőségétől függően
+Comment[is]=(Af)tengir Kopete sjálfkrafa miðað við stöðu Internettengingar
+Comment[it]=Connetti/disconnetti automaticamente Kopete a seconda della disponibilità della connessione ad internet
+Comment[ja]=インターネット接続の有無により自動的に Kopete を接続/切断します
+Comment[ka]=ინტერნეტ კავშირის არსებობისას ავტომატურად აკავშირებს Kopete-ს
+Comment[kk]=Интернетке қосылымның бар=жоғына қарай Kopete-ті автоматты түрде қосады және ажыратады
+Comment[km]=ភ្ជាប់ ​ ​ផ្ដាច​ Kopeteដោយ​ស្វ័យប្រវត្តិ​ដោយ​ផ្អែក​លើ​ភាព​មាន​នៃការណត​ភ្ជាប់​អ៊ីនធឺណិត
+Comment[lt]=Automatiškai prijungia/atjungia Kopete, priklausomai nuo interneto ryšio buvimo
+Comment[mk]=Автоматски го поврзува/исклучува Kopete во зависност на достапноста на поврзувањето на Интернет
+Comment[nb]=Kobler Kopete automatisk til/fra avhengig av om internettforbindelse er tilgjengelig
+Comment[nds]=Koppelt Kopete automaatsch to- oder af, afhangen vun de Verföögborkeit vun de Internetverbinnen
+Comment[ne]=इन्टरनेट जडानको उपलब्धतामा आधारित कोपेट स्वचालित रूपमा जडान गर्दछ/विच्छेदन गर्दछ
+Comment[nl]=Bouwt automatisch verbindingen op voor Kopete of verbreekt ze, afhankelijk van de beschikbaarheid van de internetverbinding
+Comment[nn]=Koplar Kopete automatisk til eller frå avhengig av om Internett-sambandet er tilgjengeleg.
+Comment[pl]=Automatycznie podłącza/odłącza Kopete zależnie od stanu połączenia z Internetem
+Comment[pt]=Liga/desliga o Kopete automaticamente, dependendo da disponibilidade de uma ligação à Internet
+Comment[pt_BR]=Conecta/desconecta o Kopete automaticamente dependendo da disponibilidade da conexão com a Internet
+Comment[ru]=Автоматически входит в сеть или выходит из неё в зависимости от наличия соединения с Интернет
+Comment[sk]=Pripojí/odpojí Kopete v závislosti či existuje pripojenie na Internet
+Comment[sl]=Samodejno vzpostavi/prekine povezavo Kopete glede na dostopnost internetne povezave
+Comment[sr]=Аутоматски успоставља или прекида везу у Kopete-у у зависности од доступности интернет везе
+Comment[sr@Latn]=Automatski uspostavlja ili prekida vezu u Kopete-u u zavisnosti od dostupnosti internet veze
+Comment[sv]=Ansluter eller kopplar ner Kopete automatiskt beroende på Internetförbindelsens tillgänglighet
+Comment[ta]=இணைய இணைப்பை பொருத்து Kopete யுடன்தானாக இணையும்/நீக்கும்
+Comment[tg]=Вобаста ба имкониятҳои алоқаи Интернет Kopete-ро ба таври худкор пайваст/канда мекунад
+Comment[tr]=İnternet bağlantısının kullanılabilir olabilirliğine göre Kopete'yi otomatik bağlar/bağlamaz
+Comment[uk]=Автоматично входить в мережу чи виходить з неї в залежності від наявності з'єднання з Інтернет
+Comment[zh_CN]=根据 Internet 连接是否可用自动连接/断开 Kopete
+Comment[zh_HK]=自動根據互聯網連接情況連接或中斷 Kopete 連線
+Comment[zh_TW]=自動依據網路狀況來連線/中斷連線 Kopete