~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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/***************************************************************************
 *            Utils.h
 *
 *  Sun Jan 21 00:54:41 2007
 *  Copyright  2007  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 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 _UTILS_H
#define _UTILS_H

#include <vector>

#include <glibmm.h>
#include <gtkmm.h>
#include <boost/filesystem/path.hpp>

#include "libtorrent/session.hpp"
#include "libtorrent/torrent_info.hpp"

#if defined(_WIN32) && defined(__MINGW32__)
#include "Windows.h"
#endif

namespace Utils{

	Glib::ustring getFilenameFromSaveDialog(const Glib::ustring & message, const Glib::ustring & filename, const Glib::ustring & directory);
	Glib::ustring getFilenameFromLoadDialog(const Glib::ustring & message, const Glib::ustring & directory = "", const Glib::ustring & pattern_name = "", const Glib::ustring & pattern = "");

	std::vector<Glib::ustring> getFilenamesFromLoadDialog(const Glib::ustring & message, const Glib::ustring & directory = "", const Glib::ustring & pattern_name = "", const Glib::ustring & pattern = "");

	Glib::ustring getDirectoryFromDialog(const Glib::ustring & message, const Glib::ustring & directory);
	Glib::ustring getDirectoryFromDialog(const Glib::ustring & message);

	void addTorrentToSession(const boost::filesystem::path &, const Glib::ustring&,
			std::vector<int>&, std::vector<std::string>&, bool, bool=true);
	void addMagnetToSession(const std::string&, const Glib::ustring&, bool=true);

	void warningDialog(const Glib::ustring & header, const Glib::ustring & message);
	void infoDialog(const Glib::ustring & window, const Glib::ustring & header, const Glib::ustring & message);
	int askDialogYesNoCancel(const Glib::ustring & title, const Glib::ustring & header, const Glib::ustring & message);
	bool askDialog(const Glib::ustring & title, const Glib::ustring & header, const Glib::ustring & message);
	bool askIntValueDialog(const Glib::ustring & message, const Glib::ustring & label, int & value);
	bool askUstringDialog(const Glib::ustring & message, const Glib::ustring & label, Glib::ustring & answer);
	bool askLoginDataDialog(const Glib::ustring & message, std::pair<Glib::ustring, Glib::ustring> &loginData);

	Glib::ustring askNameDialog(const Glib::ustring & message, const Glib::ustring & name = "");

	bool isAnURL(Glib::ustring &);
	bool isAMagnetLink(Glib::ustring &);
	bool isATorrentFile(const boost::filesystem::path &);

	void registerIcon(const Glib::RefPtr<Gtk::IconFactory>&, const std::string&, const Glib::ustring&, const Glib::ustring&);

	void uSleep(int64_t);

	class ModelColumnsIntString : public Gtk::TreeModel::ColumnRecord{
		public:
			ModelColumnsIntString(){
				add(m_col_id); add(m_col_name);
			}
			Gtk::TreeModelColumn<int> m_col_id;
			Gtk::TreeModelColumn<Glib::ustring> m_col_name;
	};

	class ModelColumnsString : public Gtk::TreeModel::ColumnRecord{
		public:
			ModelColumnsString(){
				add(m_col_name);
			}
			Gtk::TreeModelColumn<Glib::ustring> m_col_name;
	};

	class TorrentModelColumns : public Gtk::TreeModel::ColumnRecord{
			public:
				TorrentModelColumns()
					{
					add(m_col_id); add(m_col_health); add(m_col_name); add(m_col_size); add(m_col_percentage); add(m_col_downloaded); add(m_col_rest);
					add(m_col_uploaded); add(m_col_ratio); add(m_col_download_speed); add(m_col_upload_speed); add(m_col_seeders); add(m_col_downloaders);
					add(m_col_status); add(m_col_time); add(m_health); add(m_percentage); add(m_downloaded); add(m_rest); add(m_uploaded); add(m_size); add(m_down_speed);
					add(m_up_speed); add(m_time); add(m_ratio);
					}

					Gtk::TreeModelColumn<unsigned int> m_col_id;
					Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> > m_col_health;
					Gtk::TreeModelColumn<Glib::ustring> m_col_name;
					Gtk::TreeModelColumn<Glib::ustring> m_col_size;
					Gtk::TreeModelColumn<float> m_col_percentage;
					Gtk::TreeModelColumn<Glib::ustring> m_col_downloaded;
					Gtk::TreeModelColumn<Glib::ustring> m_col_rest;
					Gtk::TreeModelColumn<Glib::ustring> m_col_uploaded;
					Gtk::TreeModelColumn<Glib::ustring> m_col_ratio;
					Gtk::TreeModelColumn<Glib::ustring> m_col_download_speed;
					Gtk::TreeModelColumn<Glib::ustring> m_col_upload_speed;
					Gtk::TreeModelColumn<Glib::ustring> m_col_seeders;
					Gtk::TreeModelColumn<Glib::ustring> m_col_downloaders;
					Gtk::TreeModelColumn<Glib::ustring> m_col_status;
					Gtk::TreeModelColumn<Glib::ustring> m_col_time;
					// Sort columns
					Gtk::TreeModelColumn<int> m_health;
					Gtk::TreeModelColumn<float> m_percentage;
					Gtk::TreeModelColumn<float> m_size;
					Gtk::TreeModelColumn<float> m_downloaded;
					Gtk::TreeModelColumn<float> m_rest;
					Gtk::TreeModelColumn<float> m_uploaded;
					Gtk::TreeModelColumn<float> m_ratio;
					Gtk::TreeModelColumn<float> m_down_speed;
					Gtk::TreeModelColumn<float> m_up_speed;
					Gtk::TreeModelColumn<float> m_time;
		};

	typedef std::list<Gtk::TreeModel::Row> rowsList;

	struct torrent_data
	{
		bool isamagnetlink;
		Glib::ustring torrentname;
		Glib::ustring torrenturi, savepath;
		std::vector<int> priorities;
		std::vector<std::string> newfilenames;
		std::vector<libtorrent::size_type> sizes;
	};
}

#endif /* _UTILS_H */