1 /*
2  * Copyright © 2004-2010 Jens Oknelid, paskharen@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * In addition, as a special exception, compiling, linking, and/or
19  * using OpenSSL with this program is allowed.
20  */
21 
22 #pragma once
23 
24 #include <gtk/gtk.h>
25 #include <dcpp/stdinc.h>
26 #include <dcpp/CID.h>
27 #include <dcpp/User.h>
28 
29 #define C_EMPTY(x) ((x) == NULL || (x)[0] == '\0')
30 
31 class WulforUtil
32 {
33     public:
34         static std::vector<int> splitString(const std::string &str, const std::string &delimiter);
35         static std::string linuxSeparator(const std::string &ps);
36         static std::string windowsSeparator(const std::string &ps);
37         static std::vector<std::string> getLocalIPs();
38 
39         /** get nick */
40         static std::string getNicks(const std::string &cid, const std::string& hintUrl);
41         static std::string getNicks(const dcpp::CID& cid, const std::string& hintUrl);
42         static std::string getNicks(const dcpp::UserPtr& user, const std::string& hintUrl);
getNicks(const dcpp::HintedUser & user)43         static std::string getNicks(const dcpp::HintedUser& user) {return getNicks(user.user->getCID(), user.hint);}
44         /** get hub name */
45         static std::string getHubNames(const std::string &cid, const std::string& hintUrl);
46         static std::string getHubNames(const dcpp::CID& cid, const std::string& hintUrl);
47         static std::string getHubNames(const dcpp::UserPtr& user, const std::string& hintUrl);
getHubNames(const dcpp::HintedUser & user)48         static std::string getHubNames(const dcpp::HintedUser& user) {return getHubNames(user.user->getCID(), user.hint);}
49         /** get hub address */
50         static dcpp::StringList getHubAddress(const dcpp::CID& cid, const std::string& hintUrl);
51         static dcpp::StringList getHubAddress(const dcpp::UserPtr& user, const std::string& hintUrl);
52 
53         static std::string getTextFromMenu(GtkMenuItem *item);
54         static std::vector<std::string>& getCharsets();
55         static void openURI(const std::string &uri);
56         static void openURItoApp(const std::string &cmd);
57 
58 #if GTK_CHECK_VERSION (3,0,0)
59         static std::string colorToString(const GdkRGBA *color);
60 #endif
61         static std::string colorToString(const GdkColor *color); /* gdk < 2.12 */
62         static GdkPixbuf* scalePixbuf(const GdkPixbuf *pixbuf,
63             const int width, const int height, GdkInterpType type = GDK_INTERP_BILINEAR);
64 
65         // Magnet links
66         static std::string makeMagnet(const std::string &name, const int64_t size, const std::string &tth);
67         static bool splitMagnet(const std::string &magnet, std::string &name, int64_t &size, std::string &tth);
68         static bool splitMagnet(const std::string &magnet, std::string &line);
69         static bool isMagnet(const std::string &text);
70         static bool isLink(const std::string &text);
71         static bool isHubURL(const std::string &text);
72         // Profile locking
73         static bool profileIsLocked();
74         static gboolean getNextIter_gui(GtkTreeModel *model, GtkTreeIter *iter, bool children = TRUE, bool parent = TRUE);
75         static GtkTreeIter copyRow_gui(GtkListStore *store, GtkTreeIter *fromIter, int position = -1);
76         static void copyValue_gui(GtkListStore* store, GtkTreeIter *fromIter, GtkTreeIter *toIter, int position);
77         static GtkTreeIter copyRow_gui(GtkTreeStore *store, GtkTreeIter *fromIter, GtkTreeIter *parent = NULL, int position = -1);
78         static void copyValue_gui(GtkTreeStore* store, GtkTreeIter *fromIter, GtkTreeIter *toIter, int position);
79         static void registerIcons();
80 
81         static const std::string ENCODING_LOCALE;
82 
83     private:
84         static std::vector<std::string> charsets;
85         static const std::string magnetSignature;
86         static GtkIconFactory *iconFactory;
87 };
88