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

List:       kde-commits
Subject:    extragear/network/ktorrent/plugins/search
From:       Joris Guisson <joris.guisson () gmail ! com>
Date:       2006-12-05 18:31:03
Message-ID: 1165343463.438213.1047.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 610835 by guisson:

Remember search history

BUG: 137929



 M  +44 -0     searchtab.cpp  
 M  +6 -0      searchtab.h  


--- trunk/extragear/network/ktorrent/plugins/search/searchtab.cpp #610834:610835
@@ -17,6 +17,8 @@
  *   Free Software Foundation, Inc.,                                       *
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
  ***************************************************************************/
+#include <qfile.h>
+#include <qtextstream.h>
 #include <qapplication.h>
 #include <qcheckbox.h>
 #include <kglobal.h>
@@ -27,6 +29,7 @@
 #include "searchtab.h"
 #include "searchenginelist.h"
 #include "searchpluginsettings.h"
+#include "functions.h"
 
 using namespace bt;
 
@@ -47,6 +50,7 @@
 		m_search_text->setInsertionPolicy(QComboBox::AtTop);
 		m_search_text->setMaxCount(20);
 		m_search_new_tab->setEnabled(false);
+		loadSearchHistory();
 	}
 
 	SearchTab::~SearchTab()
@@ -77,6 +81,7 @@
 		comp->addItem(str);
 		m_search_text->insertItem(str);
 		m_search_text->clearEdit();
+		saveSearchHistory();
 		search(str,m_search_engine->currentItem(),false, externalBrowser->isChecked());
 	}
 	
@@ -95,6 +100,7 @@
 		KCompletion *comp = m_search_text->completionObject();
 		comp->clear();
 		m_search_text->clear();
+		saveSearchHistory();
 	}
 	
 	void SearchTab::textChanged(const QString & str)
@@ -102,6 +108,44 @@
 		m_search_new_tab->setEnabled(str.length() > 0);
 	}
 
+	void SearchTab::loadSearchHistory()
+	{
+		QFile fptr(kt::DataDir() + "search_history");
+		if (!fptr.open(IO_ReadOnly))
+			return;
+		
+		KCompletion *comp = m_search_text->completionObject();
+		
+		Uint32 cnt = 0;
+		QTextStream in(&fptr);
+		while (!in.atEnd() && cnt < 50)
+		{
+			QString line = in.readLine();
+			if (line.isNull())
+				break; 
+			
+			comp->addItem(line);
+			m_search_text->insertItem(line);
+			cnt++;
+		}
+		
+		m_search_text->clearEdit();
+	}
+	
+	void SearchTab::saveSearchHistory()
+	{
+		QFile fptr(kt::DataDir() + "search_history");
+		if (!fptr.open(IO_WriteOnly))
+			return;
+		
+		QTextStream out(&fptr);
+		KCompletion *comp = m_search_text->completionObject();
+		QStringList items = comp->items();
+		for (QStringList::iterator i = items.begin();i != items.end();i++)
+		{
+			out << *i << endl;
+		}
+	}
 }
 
 #include "searchtab.moc"
--- trunk/extragear/network/ktorrent/plugins/search/searchtab.h #610834:610835
@@ -36,6 +36,8 @@
 		virtual ~SearchTab();
 	
 		void updateSearchEngines(const SearchEngineList & sl);
+		
+		
 	
 	protected slots:
 		void clearButtonPressed();
@@ -46,6 +48,10 @@
 		
 	signals:
 		void search(const QString & text,int engine,bool cur_tab, bool external);
+		
+	private:
+		void loadSearchHistory();
+		void saveSearchHistory();
 	};
 }
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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