[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-14 16:16:45
Message-ID: 20100914161645.7732CAC888 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1175273 by guisson:

Add exclusion patterns to syndication plugin filters. Patch was made by Jaroslaw \
Swierczynski, big thanks to him.

BUG: 251141

 M  +1 -0      ChangeLog  
 M  +1 -0      ktorrent/main.cpp  
 M  +70 -0     plugins/syndication/filter.cpp  
 M  +34 -0     plugins/syndication/filter.h  
 M  +22 -0     plugins/syndication/filtereditor.cpp  
 M  +73 -1     plugins/syndication/filtereditor.ui  


--- trunk/extragear/network/ktorrent/ChangeLog #1175272:1175273
@@ -21,6 +21,7 @@
 - Add default move on completion location to group policy (248092)
 - Prevent torrents from sharing the same files (228220)
 - Add option to open all torrents silently
+- Add exclusion patterns to syndication plugin filters (251141)
 
 Changes in 4.0.4:
 - Make sure that syndication filter save location overrides group save location \
                (250116)
--- trunk/extragear/network/ktorrent/ktorrent/main.cpp #1175272:1175273
@@ -144,6 +144,7 @@
 	about.addCredit(ki18n("Andrei Barbu"),ki18n("Feature which adds the date a torrent \
was added"),"andrei@0xab.com");  KCmdLineArgs::init(argc, argv, &about);
 	about.addCredit(ki18n("Jonas Lundqvist"),ki18n("Feature to disable authentication \
in the webinterface"),"jonas@gannon.se");  +	about.addCredit(ki18n("Jaroslaw \
Swierczynski"),ki18n("Exclusion patterns in the syndication \
plugin"),"swiergot@gmail.com");  
 	KCmdLineOptions options;
 	options.add("+[Url]", ki18n("Document to open"));
--- trunk/extragear/network/ktorrent/plugins/syndication/filter.cpp #1175272:1175273
@@ -48,6 +48,9 @@
 		case_sensitive = false;
 		all_word_matches_must_match = false;
 		use_regular_expressions = false;
+		exclusion_case_sensitive = false;
+		exclusion_all_must_match = false;
+		exclusion_reg_exp = false;
 		no_duplicate_se_matches = true;
 	}
 
@@ -61,6 +64,9 @@
 		case_sensitive = false;
 		all_word_matches_must_match = false;
 		use_regular_expressions = false;
+		exclusion_case_sensitive = false;
+		exclusion_all_must_match = false;
+		exclusion_reg_exp = false;
 		no_duplicate_se_matches = true;
 	}
 
@@ -132,6 +138,29 @@
 		if (!found_match)
 			return false;
 		
+		found_match = false;
+		foreach (const QRegExp & exp,exclusion_patterns)
+		{
+			QRegExp tmp = exp;
+			tmp.setCaseSensitivity(exclusion_case_sensitive ? Qt::CaseSensitive : \
Qt::CaseInsensitive); +			tmp.setPatternSyntax(exclusion_reg_exp ? QRegExp::RegExp : \
QRegExp::Wildcard); +			if (exclusion_all_must_match)
+			{
+				if (!match(item->title(),tmp))
+				{
+					found_match = false;
+					break;
+				}
+				else
+					found_match = true;
+			}
+			else if (match(item->title(),tmp))
+				return false;
+		}
+
+		if (found_match)
+			return false;
+
 		if (use_season_and_episode_matching)
 		{
 			int season = 0;
@@ -188,6 +217,16 @@
 		word_matches.removeAll(exp);
 	}
 	
+	void Filter::addExclusionPattern(const QRegExp & exp)
+	{
+		exclusion_patterns.append(exp);
+	}
+
+	void Filter::removeExclusionPattern(const QRegExp & exp)
+	{
+		exclusion_patterns.removeAll(exp);
+	}
+
 	bool Filter::stringToRange(const QString & s,Range & r)
 	{
 		QString tmp = s.trimmed(); // Get rid of whitespace
@@ -276,11 +315,18 @@
 		enc.write("name",name);
 		enc.write("case_sensitive",case_sensitive);
 		enc.write("all_word_matches_must_match",all_word_matches_must_match);
+		enc.write("exclusion_case_sensitive",exclusion_case_sensitive);
+		enc.write("exclusion_all_must_match",exclusion_all_must_match);
 		enc.write("word_matches"); 
 		enc.beginList();
 		foreach (const QRegExp & exp,word_matches)
 			enc.write(exp.pattern());
 		enc.end();
+		enc.write("exclusion_patterns");
+		enc.beginList();
+		foreach (const QRegExp & exp,exclusion_patterns)
+			enc.write(exp.pattern());
+		enc.end();
 		enc.write("use_season_and_episode_matching",use_season_and_episode_matching);
 		enc.write("no_duplicate_se_matches",no_duplicate_se_matches);
 		enc.write("seasons",seasons_string);
@@ -295,6 +341,7 @@
 			enc.write("move_on_completion_location",move_on_completion_location);
 		enc.write("silently",silent);
 		enc.write("use_regular_expressions",use_regular_expressions);
+		enc.write("exclusion_reg_exp",exclusion_reg_exp);
 		enc.end();
 	}
 	
@@ -323,6 +370,14 @@
 		
 		all_word_matches_must_match = vn->data().toInt() == 1;
 		
+		vn = dict->getValue("exclusion_case_sensitive");
+		if (vn)
+			exclusion_case_sensitive = vn->data().toInt() == 1;
+
+		vn = dict->getValue("exclusion_all_must_match");
+		if (vn)
+			exclusion_all_must_match = vn->data().toInt() == 1;
+
 		BListNode* ln = dict->getList("word_matches");
 		if (!ln)
 			return false;
@@ -334,6 +389,17 @@
 				word_matches.append(QRegExp(vn->data().toString(codec),case_sensitive ? \
Qt::CaseSensitive : Qt::CaseInsensitive));  }
 		
+		ln = dict->getList("exclusion_patterns");
+		if (ln)
+		{
+			for (Uint32 i = 0;i < ln->getNumChildren();i++)
+			{
+				vn = ln->getValue(i);
+				if (vn)
+					exclusion_patterns.append(QRegExp(vn->data().toString(codec),exclusion_case_sensitive \
? Qt::CaseSensitive : Qt::CaseInsensitive)); +			}
+		}
+
 		vn = dict->getValue("use_season_and_episode_matching");
 		if (!vn)
 			return false;
@@ -392,6 +458,10 @@
 		if (vn)
 			use_regular_expressions = vn->data().toInt() == 1;
 		
+		vn = dict->getValue("exclusion_reg_exp");
+		if (vn)
+			exclusion_reg_exp = vn->data().toInt() == 1;
+
 		return true;
 	}
 	
--- trunk/extragear/network/ktorrent/plugins/syndication/filter.h #1175272:1175273
@@ -74,12 +74,24 @@
 		/// Remove a word match
 		void removeWordMatch(const QRegExp & exp);
 		
+		/// Add a word match
+		void addExclusionPattern(const QRegExp & exp);
+
+		/// Remove a word match
+		void removeExclusionPattern(const QRegExp & exp);
+
 		/// Get all word matches
 		QList<QRegExp> wordMatches() const {return word_matches;}
 		
+		/// Get all word matches
+		QList<QRegExp> exclusionPatterns() const {return exclusion_patterns;}
+
 		/// Clear the list of word matches
 		void clearWordMatches() {word_matches.clear();}
 		
+		/// Clear the list of word matches
+		void clearExclusionPatterns() {exclusion_patterns.clear();}
+
 		/// Is season and episode matching enabled
 		bool useSeasonAndEpisodeMatching() const {return use_season_and_episode_matching;}
 		
@@ -160,6 +172,18 @@
 		/// Set wether or not all word matches must match
 		void setAllWordMatchesMustMatch(bool on) {all_word_matches_must_match = on;}
 		
+		/// Are the word matches case sensitive
+		bool exclusionCaseSensitive() const {return exclusion_case_sensitive;}
+
+		/// Set case sensitivity of word matches
+		void setExclusionCaseSensitive(bool on) {exclusion_case_sensitive = on;}
+
+		/// Return wether or not all word matches must match
+		bool exclusionAllMustMatch() const {return exclusion_all_must_match;}
+
+		/// Set wether or not all word matches must match
+		void setExclusionAllMustMatch(bool on) {exclusion_all_must_match = on;}
+
 		/// Save the filter
 		void save(bt::BEncoder & enc);
 		
@@ -172,6 +196,12 @@
 		/// Enable or disable regular expressions
 		void setUseRegularExpressions(bool on) {use_regular_expressions = on;}
 		
+		/// Wether or not the string matches are regular expressions
+		bool exclusionUseRegularExpressions() const {return exclusion_reg_exp;}
+
+		/// Enable or disable regular expressions
+		void setExclusionUseRegularExpressions(bool on) {exclusion_reg_exp = on;}
+
 		/// Is a string a valid seasons or episode string
 		static bool validSeasonOrEpisodeString(const QString & s);
 		
@@ -204,6 +234,7 @@
 		QString id;
 		QString name;
 		QList<QRegExp> word_matches;
+		QList<QRegExp> exclusion_patterns;;
 		bool use_season_and_episode_matching;
 		bool no_duplicate_se_matches;
 		QList<Range> seasons;
@@ -219,6 +250,9 @@
 		bool case_sensitive;
 		bool all_word_matches_must_match;
 		bool use_regular_expressions;
+		bool exclusion_case_sensitive;
+		bool exclusion_all_must_match;
+		bool exclusion_reg_exp;
 		
 		QList<MatchedSeasonAndEpisode> se_matches;
 	};
--- trunk/extragear/network/ktorrent/plugins/syndication/filtereditor.cpp \
#1175272:1175273 @@ -43,6 +43,8 @@
 		m_name->setText(filter->filterName());
 		m_match_case_sensitive->setChecked(filter->caseSensitive());
 		m_all_words_must_match->setChecked(filter->allWordMatchesMustMatch());
+		m_exclusion_case_sensitive->setChecked(filter->exclusionCaseSensitive());
+		m_exclusion_all_must_match->setChecked(filter->exclusionAllMustMatch());
 		m_use_se_matching->setChecked(filter->useSeasonAndEpisodeMatching());
 		m_seasons->setEnabled(filter->useSeasonAndEpisodeMatching());
 		m_seasons->setText(filter->seasonsToString());
@@ -91,6 +93,16 @@
 		m_word_matches->setItems(items);
 		m_reg_exp_syntax->setChecked(filter->useRegularExpressions());
 		
+		re = filter->exclusionPatterns();
+		items.clear();
+		foreach (const QRegExp & r,re)
+		{
+			items.append(r.pattern());
+		}
+
+		m_exclusion_patterns->setItems(items);
+		m_exclusion_reg_exp->setChecked(filter->exclusionUseRegularExpressions());
+
 		connect(m_name,SIGNAL(textChanged(const QString & )),this,SLOT(checkOKButton()));
 		connect(m_seasons,SIGNAL(textChanged(const QString & \
)),this,SLOT(checkOKButton()));  connect(m_episodes,SIGNAL(textChanged(const QString \
& )),this,SLOT(checkOKButton())); @@ -168,6 +180,8 @@
 		f->setFilterName(m_name->text());
 		f->setCaseSensitive(m_match_case_sensitive->isChecked());
 		f->setAllWordMatchesMustMatch(m_all_words_must_match->isChecked());
+		f->setExclusionCaseSensitive(m_exclusion_case_sensitive->isChecked());
+		f->setExclusionAllMustMatch(m_exclusion_all_must_match->isChecked());
 		
 		f->setSeasonAndEpisodeMatching(m_use_se_matching->isChecked());
 		f->setSeasons(m_seasons->text());
@@ -201,7 +215,15 @@
 			f->addWordMatch(QRegExp(p,filter->caseSensitive() ? Qt::CaseSensitive : \
Qt::CaseInsensitive));  }
 		f->setUseRegularExpressions(m_reg_exp_syntax->isChecked());
+
+		f->clearExclusionPatterns();
+		for (int i = 0;i < m_exclusion_patterns->count();i++)
+		{
+			QString p = m_exclusion_patterns->text(i);
+			f->addExclusionPattern(QRegExp(p,filter->exclusionCaseSensitive() ? \
Qt::CaseSensitive : Qt::CaseInsensitive));  }
+		f->setExclusionUseRegularExpressions(m_exclusion_reg_exp->isChecked());
+	}
 	
 	void FilterEditor::onOK()
 	{
--- trunk/extragear/network/ktorrent/plugins/syndication/filtereditor.ui \
#1175272:1175273 @@ -92,7 +92,7 @@
        <item>
         <widget class="QCheckBox" name="m_all_words_must_match">
          <property name="text">
-          <string>Item must match all strings</string>
+          <string>Item must match all strings to be included</string>
          </property>
         </widget>
        </item>
@@ -105,6 +105,78 @@
        </item>
       </layout>
      </widget>
+     <widget class="QWidget" name="tab_5" >
+      <attribute name="title" >
+       <string>Exclusion Patterns</string>
+      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout_6" >
+       <item>
+        <widget class="KEditListBox" name="m_exclusion_patterns" >
+         <property name="toolTip" >
+          <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" \
"http://www.w3.org/TR/REC-html40/strict.dtd"> +&lt;html>&lt;head>&lt;meta \
name="qrichtext" content="1" />&lt;style type="text/css"> +p, li { white-space: \
pre-wrap; } +&lt;/style>&lt;/head>&lt;body style=" font-family:'OpenSymbol'; \
font-size:8pt; font-weight:400; font-style:normal;"> +&lt;p style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px;">The string to find in the title of an item. Simple wildcard syntax \
is supported :&lt;/p> +&lt;p style="-qt-paragraph-type:empty; margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px;">&lt;/p> +&lt;p style="-qt-paragraph-type:empty; margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px;">&lt;/p> +&lt;table border="0" style=" margin-top:0px; \
margin-bottom:0px; margin-left:0px; margin-right:0px;" align="center" cellspacing="1" \
cellpadding="2"> +&lt;tr>
+&lt;td style=" vertical-align:top;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; color:#000000;">&lt;span style=" \
font-weight:600;">c&lt;/span>&lt;/p>&lt;/td> +&lt;td style=" vertical-align:top;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px;">Any character represents itself apart from \
those mentioned below. Thus &lt;span style=" font-weight:600;">c&lt;/span> matches \
the character &lt;span style=" \
font-style:italic;">c&lt;/span>.&lt;/p>&lt;/td>&lt;/tr> +&lt;tr>
+&lt;td style=" vertical-align:top;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; color:#000000;">&lt;span style=" \
font-weight:600;">?&lt;/span>&lt;/p>&lt;/td> +&lt;td style=" vertical-align:top;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; color:#000000;">Matches any single character. \
&lt;/p>&lt;/td>&lt;/tr> +&lt;tr>
+&lt;td style=" vertical-align:top;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; color:#000000;">&lt;span style=" \
font-weight:600;">*&lt;/span>&lt;/p>&lt;/td> +&lt;td style=" vertical-align:top;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; color:#000000;">Matches zero or more of any \
characters.&lt;/p>&lt;/td>&lt;/tr> +&lt;tr>
+&lt;td style=" vertical-align:top;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; \
-qt-block-indent:0; text-indent:0px; color:#000000;">&lt;span style=" \
font-weight:600;">[...]&lt;/span>&lt;/p>&lt;/td> +&lt;td style=" \
vertical-align:top;"> +&lt;p style=" margin-top:0px; margin-bottom:0px; \
margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; \
color:#000000;">Sets of characters can be represented in square brackets. Within the \
character class, like outside, backslash has no special \
meaning.&lt;/p>&lt;/td>&lt;/tr>&lt;/table> +&lt;p style=" margin-top:12px; \
margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; \
text-indent:0px; color:#000000;">For example the *.torrent will match any item which \
ends in .torrent. &lt;/p>&lt;/body>&lt;/html></string> +         </property>
+         <property name="title" >
+          <string/>
+         </property>
+         <property name="buttons" >
+          <set>KEditListBox::Add|KEditListBox::Remove</set>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QCheckBox" name="m_exclusion_reg_exp" >
+         <property name="toolTip" >
+          <string>By default strings will use wildcard matching. If you want to use \
regular expressions, this needs to be enabled.</string> +         </property>
+         <property name="text" >
+          <string>Strings are regular expressions</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QCheckBox" name="m_exclusion_all_must_match" >
+         <property name="text" >
+          <string>Item must match all strings to be excluded</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QCheckBox" name="m_exclusion_case_sensitive" >
+         <property name="text" >
+          <string>Case sensitive matching</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
      <widget class="QWidget" name="tab_2">
       <attribute name="title">
        <string>Seasons &amp;&amp; Episodes</string>


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

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