[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/network/ktorrent
From:       Joris Guisson <joris.guisson () gmail ! com>
Date:       2010-09-24 9:29:18
Message-ID: 20100924092918.8D13CAC88C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1179001 by guisson:

Show notifications when automatic update of IP filter fails 

BUG: 243458

 M  +2 -1      ChangeLog  
 M  +4 -0      ktorrent/ktorrent.notifyrc  
 M  +52 -0     plugins/ipfilter/downloadandconvertjob.cpp  
 M  +4 -0      plugins/ipfilter/downloadandconvertjob.h  
 M  +7 -1      plugins/ipfilter/ipblockingprefpage.cpp  
 M  +22 -5     plugins/ipfilter/ipfilterplugin.cpp  
 M  +4 -1      plugins/ipfilter/ipfilterplugin.h  


--- trunk/extragear/network/ktorrent/ChangeLog #1179000:1179001
@@ -4,7 +4,6 @@
 - Change from and to fields to always ensure that from is smaller then to in the \
                bandwidth scheduler plugin (225951)
 - Show if a peer is using the  TP protocol or not 
 - Cleanup file dialog filters for torrents and make sure that files named torrent, \
                are also seen by the filter (241259)
-- Improve performance of ViewModel when there are many torrents (216501)
 - Ensure that webinterface plugin works properly with bindv6only flag on (238688)
 - Add option to not restore the previous session of the search plugin (233288)
 - Save suspended state on exit and restore on restart (241675)
@@ -23,10 +22,12 @@
 - Add option to open all torrents silently
 - Add exclusion patterns to syndication plugin filters (251141)
 - Show current upload and download limit in trayicon submenus instead of limits from \
the settings (251953) +- Show notifications when automatic update of IP filter fails \
(243458)  
 Changes in 4.0.4:
 - Make sure that syndication filter save location overrides group save location \
                (250116)
 - Don't hardcode background of bandwidth schedule to white so that system colors are \
used (251925) +- Improve performance of ViewModel when there are many torrents \
(216501)  
 Changes in 4.0.3:
 - Fix bug causing wrong encoding to be used when the default save location of a \
                group is read (244873)
--- trunk/extragear/network/ktorrent/ktorrent/ktorrent.notifyrc #1179000:1179001
@@ -511,3 +511,7 @@
 Name[zh_CN]=未启用 DHT
 Name[zh_TW]=DHT 未開啟
 Action=Sound|Popup
+
+[Event/PluginEvent]
+Name=Event generated by plugin
+Action=Sound|Popup
\ No newline at end of file
--- trunk/extragear/network/ktorrent/plugins/ipfilter/downloadandconvertjob.cpp \
#1179000:1179001 @@ -33,7 +33,9 @@
 #include "convertdialog.h"
 #include "downloadandconvertjob.h"
 
+using namespace bt;
 
+
 namespace kt
 {
 
@@ -70,8 +72,16 @@
 		active_job = 0;
 		if (j->error())
 		{
+			Out(SYS_IPF|LOG_NOTICE) << "IP filter update failed: " << j->errorString() << \
endl;  if (mode == Verbose)
+			{
 				((KIO::Job*)j)->ui()->showErrorMessage();
+			}
+			else
+			{
+				QString msg = i18n("Automatic update of IP filter failed: %1", \
j->errorString()); +				notification(msg);
+			}
 			setError(unzip ? UNZIP_FAILED : MOVE_FAILED);
 			emitResult();
 		}
@@ -84,8 +94,17 @@
 		active_job = 0;
 		if (j->error())
 		{
+			Out(SYS_IPF|LOG_NOTICE) << "IP filter update failed: " << j->errorString() << \
endl;  if (mode == Verbose)
+			{
 				((KIO::Job*)j)->ui()->showErrorMessage();
+			}
+			else
+			{
+				QString msg = i18n("Automatic update of IP filter failed: %1", \
j->errorString()); +				notification(msg);
+			}
+			
 			setError(DOWNLOAD_FAILED); 
 			emitResult();
 			return;
@@ -118,8 +137,16 @@
 		active_job = 0;
 		if (j->error())
 		{
+			Out(SYS_IPF|LOG_NOTICE) << "IP filter update failed: " << j->errorString() << \
endl;  if (mode == Verbose)
+			{
 				((KIO::Job*)j)->ui()->showErrorMessage();
+			}
+			else
+			{
+				QString msg = i18n("Automatic update of IP filter failed: %1", \
j->errorString()); +				notification(msg);
+			}
 			setError(MOVE_FAILED);
 			emitResult();
 			return;
@@ -129,8 +156,17 @@
 		KZip* zip = new KZip(zipfile);
 		if (!zip->open(QIODevice::ReadOnly) || !zip->directory())
 		{
+			Out(SYS_IPF|LOG_NOTICE) << "IP filter update failed: cannot open zip file " << \
zipfile << endl;  if (mode == Verbose)
+			{
 				KMessageBox::error(0,i18n("Cannot open zip file %1.",zipfile));
+			}
+			else
+			{
+				QString msg = i18n("Automatic update of IP filter failed: cannot open zipfile \
%1", zipfile); +				notification(msg);
+			}
+			
 			setError(UNZIP_FAILED);
 			emitResult();
 			delete zip;
@@ -161,8 +197,16 @@
 		}
 		else
 		{
+			Out(SYS_IPF|LOG_NOTICE) << "IP filter update failed: no blocklist found in \
zipfile " << zipfile << endl;  if (mode == Verbose)
+			{
 				KMessageBox::error(0,i18n("Cannot find blocklist in zip file %1.",zipfile));
+			}
+			else
+			{
+				QString msg = i18n("Automatic update of IP filter failed: cannot find blocklist \
in zip file %1", zipfile); +				notification(msg);
+			}
 			
 			setError(UNZIP_FAILED);
 			emitResult();
@@ -182,8 +226,16 @@
 	{
 		if (j && j->error())
 		{
+			Out(SYS_IPF|LOG_NOTICE) << "IP filter update failed: " << j->errorString() << \
endl;  if (mode == Verbose)
+			{
 				((KIO::Job*)j)->ui()->showErrorMessage();
+			}
+			else
+			{
+				QString msg = i18n("Automatic update of IP filter failed: %1", \
j->errorString()); +				notification(msg);
+			}
 			setError(BACKUP_FAILED);
 			emitResult();
 		}
--- trunk/extragear/network/ktorrent/plugins/ipfilter/downloadandconvertjob.h \
#1179000:1179001 @@ -51,6 +51,10 @@
 		
 		bool isAutoUpdate() const {return mode == Quietly;}
 		
+	signals:
+		/// Emitted when the job needs to show a notification
+		void notification(const QString & msg);
+		
 	private slots:
 		void downloadFileFinished(KJob*);
 		void convert(KJob*);
--- trunk/extragear/network/ktorrent/plugins/ipfilter/ipblockingprefpage.cpp \
#1179000:1179001 @@ -19,6 +19,7 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ***************************************************************************/
 #include <klocale.h>
+#include <util/log.h>
 #include "ipblockingprefpage.h"
 #include "ipfilterpluginsettings.h"
 #include "ipfilterplugin.h"
@@ -123,6 +124,7 @@
 		m_plugin->unloadAntiP2P();
 		m_job = new DownloadAndConvertJob(url,m_verbose ? DownloadAndConvertJob::Verbose : \
DownloadAndConvertJob::Quietly);  \
connect(m_job,SIGNAL(result(KJob*)),this,SLOT(downloadAndConvertFinished(KJob*))); \
+		connect(m_job,SIGNAL(notification(QString)),m_plugin,SLOT(notification(QString))); \
m_job->start();  }
 	
@@ -137,6 +139,7 @@
 		}
 		
 		m_verbose = false;
+		Out(SYS_IPF|LOG_NOTICE) << "Doing ipfilter auto update !" << endl;
 		downloadClicked();
 		m_verbose = true;
 		return true;
@@ -162,11 +165,14 @@
 		KConfigGroup g = KGlobal::config()->group("IPFilterAutoUpdate");
 		if (!j->error())
 		{
-			g.writeEntry("last_updated",QDate::currentDate());
+			g.writeEntry("last_updated",QDateTime::currentDateTime());
 			g.writeEntry("last_update_ok",true);
 		}
 		else
+		{
+			g.writeEntry("last_update_attempt",QDateTime::currentDateTime()); 
 			g.writeEntry("last_update_ok",false);
+		}
 		
 		g.sync();
 		
--- trunk/extragear/network/ktorrent/plugins/ipfilter/ipfilterplugin.cpp \
#1179000:1179001 @@ -19,6 +19,8 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.             *
  ***************************************************************************/
 #include <kgenericfactory.h>
+#include <knotification.h>
+#include <kmainwindow.h>
 #include <QTimer>
 
 #include <interfaces/coreinterface.h>
@@ -129,10 +131,19 @@
 			return;
 		
 		KConfigGroup g = KGlobal::config()->group("IPFilterAutoUpdate");
-		QDate last_updated = g.readEntry("last_updated",QDate());
-		
+		bool ok = g.readEntry("last_update_ok",false);
+		QDateTime now = QDateTime::currentDateTime();
+		if (!ok)
+		{
+			QDateTime last_update_attempt = g.readEntry("last_update_attempt",now);
+			// if we cannot do it now, or the last attempt was less then 15 minute ago, try \
again in 15 minutes +			if (last_update_attempt.secsTo(now) < \
AUTO_UPDATE_RETRY_INTERVAL || !pref->doAutoUpdate())  \
+				auto_update_timer.start(AUTO_UPDATE_RETRY_INTERVAL * 1000); +		}
+		else
+		{
+			QDateTime last_updated = g.readEntry("last_updated",QDateTime());
 		QDateTime next_update;
-		QDateTime now = QDateTime::currentDateTime();
 		if (last_updated.isNull())
 			next_update = now.addDays(IPBlockingPluginSettings::autoUpdateInterval());
 		else
@@ -140,9 +151,8 @@
 			
 		if (now >= next_update)
 		{
-			Out(SYS_IPF|LOG_NOTICE) << "Doing ipfilter auto update !" << endl;
 			if (!pref->doAutoUpdate()) // if we cannot do it now, try again in 15 minutes
-				auto_update_timer.start(15*60*1000);
+					auto_update_timer.start(AUTO_UPDATE_RETRY_INTERVAL * 1000);
 		}
 		else
 		{
@@ -152,3 +162,10 @@
 		}
 	}
 }
+	
+	void IPFilterPlugin::notification(const QString& msg)
+	{
+		KNotification::event("PluginEvent",msg,QPixmap(),getGUI()->getMainWindow());
+	}
+
+}
--- trunk/extragear/network/ktorrent/plugins/ipfilter/ipfilterplugin.h \
#1179000:1179001 @@ -32,6 +32,8 @@
 {	
 	class IPBlockingPrefPage;
 	
+	const int AUTO_UPDATE_RETRY_INTERVAL = 15*60; // seconds
+	
 	/**
 	 * @author Ivan Vasic <ivasic@gmail.com>
 	 * @brief IP filter plugin
@@ -60,10 +62,11 @@
 		
 		/// Whether or not the IP filter is loaded and running
 		bool loadedAndRunning(); 
+		
 	public slots:
 		void checkAutoUpdate();
+		void notification(const QString & msg);
 		
-		
 	private:
 		IPBlockingPrefPage* pref;
 		AntiP2P* level1;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic