~linuxdcpp-team/linuxdcpp/1.1

« back to all changes in this revision

Viewing changes to linux/wulfor.cc

  • Committer: Razzloss
  • Date: 2011-04-04 16:31:38 UTC
  • Revision ID: razzloss@gmail.com-20110404163138-hdmbtpr7ihd3q66z
lp#546227 possibility to queue magnet directly

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include <signal.h>
36
36
 
37
37
struct CommandlineArgs {
38
 
        std::vector<std::string> magnets;
 
38
        std::vector<std::string> searchmagnets;
 
39
        std::vector<std::string> addmagnets;
39
40
        std::vector<std::string> urls;
40
41
        bool show;
41
42
        bool refresh;
67
68
                if (WulforUtil::isHubURL(arg))
68
69
                        args->urls.push_back(arg);
69
70
                else if (WulforUtil::isMagnet(arg))
70
 
                        args->magnets.push_back(arg);
 
71
                        args->addmagnets.push_back(arg);
71
72
        }
72
73
}
73
74
 
74
75
bool parseArguments(int *argc, char **argv[], CommandlineArgs* args)
75
76
{
76
 
        gchar **magnet = NULL, **address = NULL;
 
77
        gchar **searchmagnet = NULL, **address = NULL, **addmagnet = NULL;
77
78
        gboolean show = FALSE, refresh = FALSE, version = FALSE, existing = FALSE;
78
79
 
79
80
        GOptionEntry entries[] = {
80
81
                { "connect", 'c', 0, G_OPTION_ARG_STRING_ARRAY, &address, N_("Connect to the given hub"), N_("URI") },
81
82
                { "existing", 'e', 0, G_OPTION_ARG_NONE, &existing, N_("Send commands to the existing instance (if applicable)"), NULL },
82
 
                { "magnet", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &magnet, N_("Search for the given magnet link"), N_("URI") },
 
83
                { "search-magnet", 'm', 0, G_OPTION_ARG_STRING_ARRAY, &searchmagnet, N_("Search for the given magnet link"), N_("URI") },
 
84
                { "add-magnet", 'a', 0, G_OPTION_ARG_STRING_ARRAY, &addmagnet, N_("Try to add given magnet directly to download queue"), N_("URI") },
83
85
                { "refresh", 'r', 0, G_OPTION_ARG_NONE, &refresh, N_("Initiate filelist refresh"), NULL },
84
86
                { "show", 's', 0, G_OPTION_ARG_NONE, &show, N_("Show the running instance (default action)"), NULL },
85
87
                { "version", 'v', 0, G_OPTION_ARG_NONE, &version, N_("Show version information and exit"), NULL },
109
111
                        args->version = TRUE;
110
112
                if (existing)
111
113
                        args->existing = TRUE;
112
 
                if (magnet)
113
 
                {
114
 
                        int i = 0;
115
 
                        for (gchar* it = magnet[0]; it != NULL; it = magnet[++i])
116
 
                                args->magnets.push_back(std::string(it));
117
 
                        g_strfreev(magnet);
 
114
                if (searchmagnet)
 
115
                {
 
116
                        int i = 0;
 
117
                        for (gchar* it = searchmagnet[0]; it != NULL; it = searchmagnet[++i])
 
118
                                args->searchmagnets.push_back(std::string(it));
 
119
                        g_strfreev(searchmagnet);
 
120
                }
 
121
                if (addmagnet)
 
122
                {
 
123
                        int i = 0;
 
124
                        for (gchar* it = addmagnet[0]; it != NULL; it = addmagnet[++i])
 
125
                                args->addmagnets.push_back(std::string(it));
 
126
                        g_strfreev(addmagnet);
118
127
                }
119
128
                if (address)
120
129
                {
138
147
        int retval = 1;
139
148
        if (args.refresh)
140
149
                retval = WulforUtil::writeIPCCommand("refresh");
141
 
        for (std::vector<std::string>::const_iterator it = args.magnets.begin();
142
 
                        retval > 0 && it != args.magnets.end(); ++it)
143
 
        {
144
 
                retval = WulforUtil::writeIPCCommand(std::string("magnet ") + *it);
 
150
        for (std::vector<std::string>::const_iterator it = args.searchmagnets.begin();
 
151
                        retval > 0 && it != args.searchmagnets.end(); ++it)
 
152
        {
 
153
                retval = WulforUtil::writeIPCCommand(std::string("search-magnet ") + *it);
 
154
        }
 
155
        for (std::vector<std::string>::const_iterator it = args.addmagnets.begin();
 
156
                        retval > 0 && it != args.addmagnets.end(); ++it)
 
157
        {
 
158
                retval = WulforUtil::writeIPCCommand(std::string("add-magnet ") + *it);
145
159
        }
146
160
        for (std::vector<std::string>::const_iterator it = args.urls.begin();
147
161
                        retval > 0 && it != args.urls.end(); ++it)