~vcs-imports/lince/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/***************************************************************************
 *            SearchTabResults.h
 *
 *  Sat Oct  4 13:37:44 2008
 *  Copyright  2008  Fernando TarĂ­n Morales
 *  <icemanf@gmail.com>
 ****************************************************************************/

/*
 * 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; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program 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 General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 */
 
#ifndef _SEARCHTABRESULTS_H
#define _SEARCHTABRESULTS_H

#include <gtkmm/label.h>
#include <gtkmm/box.h>
#include <gtkmm/treeview.h>
#include <gtkmm/treemodel.h>

#include "Lince/Utils.h"

#include "BaseTab.h"
#include "GuiSetupManager.h"

class SearchResults: public Gtk::VBox
{
	private:
		Glib::ustring search_terms, categorie;
		Gtk::Label status, results;
		
		class searchResultsModelColumns: public Gtk::TreeModel::ColumnRecord{
		public:
			searchResultsModelColumns(){
				add(m_position); add(m_link); add(m_name); add(m_size);
				add(m_seeds); add(m_leechs); add(m_engine); add(size);
				add(colSelected);
			}
			Gtk::TreeModelColumn< int > m_position;
			Gtk::TreeModelColumn< Glib::ustring > m_link;
			Gtk::TreeModelColumn< Glib::ustring > m_name;
			Gtk::TreeModelColumn< Glib::ustring > m_size;
			Gtk::TreeModelColumn< int > m_seeds;
			Gtk::TreeModelColumn< int > m_leechs;
			Gtk::TreeModelColumn< Glib::ustring > m_engine;
			
			Gtk::TreeModelColumn< boost::int64_t > size;
			Gtk::TreeModelColumn< bool > colSelected;
		};
		
		Gtk::TreeView searchResultsTreeView;
		Glib::RefPtr<Gtk::ListStore> searchResultsTreeModel;
		searchResultsModelColumns searchResultsColumns;
		
		GuiSetupManager * gsm;
	
		// Search
		Glib::Pid pid_search;
		bool is_search_running;
		Glib::RefPtr<Glib::IOChannel> io_stdout_search, io_stderr_search;
		
		void addRow(const Glib::ustring&, const Glib::ustring&, boost::int64_t,
					int, int, const Glib::ustring&);
		
		void searchFinished(int, int);
		bool showResults();
		void row_activated(const Gtk::TreeModel::Path&, Gtk::TreeViewColumn*);

		// TODO: Deprecated function to download torrents using http protocol
		void downloadTorrent();

		// Handle downloading torrents
		void startDownloadingTorrentFile();
		void downloadingTorrentFileFinished(int, int, int, Glib::ustring, Glib::ustring);
		void addDownloadedTorrentFile(const Glib::ustring &, const Glib::ustring &, const Glib::ustring &);

		// Mark the line of the download torrent
		void set_cell_foreground(Gtk::CellRenderer*, const Gtk::TreeModel::iterator&);
	
	public:
		SearchResults(GuiSetupManager *, const Glib::ustring &_search_terms,
				const Glib::ustring &_categorie);
		~SearchResults();
		
		void startSearch();
		void stopSearch();
		bool isSearchRunning() { return is_search_running; };
};

class SearchTabResults: public BaseTab
{
	private:
		GuiSetupManager * gsm;
		Glib::ustring search_terms, categorie;
		SearchResults search_results;
		
	public:
		SearchTabResults(GuiSetupManager *, const Glib::ustring &, const Glib::ustring &);
		SearchTabResults(const SearchTabResults& t);
		~SearchTabResults();
		
		Gtk::Widget * getTabChild(void) { return & search_results; };
};

#endif /* SEARCHTABRESULTS_H */