| | 82 | |
| | 83 | #ifdef WITH_UNIQUE |
| | 84 | int send_message_with_uris(UniqueApp* app, |
| | 85 | gint message_id, |
| | 86 | const std::vector<Glib::ustring>& uris) |
| | 87 | { |
| | 88 | std::vector<const gchar*> uri_cstrs(uris.size() + 1); |
| | 89 | for(int i = 0; i < uris.size(); ++i) |
| | 90 | uri_cstrs[i] = uris[i].c_str(); |
| | 91 | |
| | 92 | UniqueMessageData* message = unique_message_data_new(); |
| | 93 | unique_message_data_set_uris( |
| | 94 | message, const_cast<gchar**>(&uri_cstrs[0])); |
| | 95 | UniqueResponse response = unique_app_send_message( |
| | 96 | app, message_id, message); |
| | 97 | unique_message_data_free(message); |
| | 98 | |
| | 99 | if(response == UNIQUE_RESPONSE_OK) |
| | 100 | { |
| | 101 | return 0; |
| | 102 | } |
| | 103 | else |
| | 104 | { |
| | 105 | std::cerr |
| | 106 | << "error sending URIs to existing gobby " |
| | 107 | "instance (libunique): " |
| | 108 | << static_cast<int>(response) |
| | 109 | << std::endl; |
| | 110 | return -1; |
| | 111 | } |
| | 112 | } |
| | 113 | |
| | 114 | int my_unique_activate(UniqueApp* app) { |
| | 115 | UniqueResponse response = |
| | 116 | unique_app_send_message(app, UNIQUE_ACTIVATE, NULL); |
| | 117 | if(response != UNIQUE_RESPONSE_OK) |
| | 118 | { |
| | 119 | std::cerr |
| | 120 | << "error activating existing gobby " |
| | 121 | "instance (libunique): " |
| | 122 | << static_cast<int>(response) |
| | 123 | << std::endl; |
| | 124 | return -1; |
| | 125 | } |
| | 126 | } |
| | 127 | |
| | 128 | int my_unique_send_file_args(UniqueApp* app, |
| | 129 | int argc, |
| | 130 | const char* const* argv) |
| | 131 | { |
| | 132 | std::vector<Glib::ustring> uris(argc); |
| | 133 | for(int i = 0; i < argc; ++i) |
| | 134 | { |
| | 135 | uris[i] = Gio::File::create_for_commandline_arg( |
| | 136 | argv[i])->get_uri(); |
| | 137 | } |
| | 138 | return send_message_with_uris(app, UNIQUE_OPEN, uris); |
| | 139 | } |
| | 140 | |
| | 141 | int my_unique_check_other(UniqueApp* app, |
| | 142 | int argc, const char* const* argv) |
| | 143 | { |
| | 144 | if(argc == 0) |
| | 145 | { |
| | 146 | return my_unique_activate(app); |
| | 147 | } |
| | 148 | else |
| | 149 | { |
| | 150 | if(my_unique_send_file_args(app, argc, argv) != 0) |
| | 151 | return -1; |
| | 152 | } |
| | 153 | |
| | 154 | return 0; |
| | 155 | } |
| | 156 | #endif // WITH_UNIQUE |
| 154 | | if (!new_instance && unique_app_is_running(app)) |
| 155 | | { |
| 156 | | // TODO: Also send the hostnames to connect to to the remote |
| 157 | | // Gobby. |
| 158 | | UniqueResponse response; |
| 159 | | if (argc < 2) |
| 160 | | { |
| 161 | | response = unique_app_send_message( |
| 162 | | app, UNIQUE_ACTIVATE, NULL); |
| 163 | | } |
| 164 | | else |
| 165 | | { |
| 166 | | UniqueMessageData* message = |
| 167 | | unique_message_data_new(); |
| 168 | | std::vector<const gchar*> uris(argc); |
| 169 | | std::vector<Glib::ustring> uri_strs(argc-1); |
| 170 | | for (int i = 0; i < argc - 1; ++i) { |
| 171 | | uri_strs[i] = |
| 172 | | Gio::File::create_for_commandline_arg( |
| 173 | | argv[i+1])->get_uri(); |
| 174 | | uris[i] = uri_strs[i].c_str(); |
| 175 | | } |
| 176 | | |
| 177 | | unique_message_data_set_uris( |
| 178 | | message, const_cast<gchar**>(&uris[0])); |
| 179 | | response = unique_app_send_message( |
| 180 | | app, UNIQUE_OPEN, message); |
| 181 | | unique_message_data_free(message); |
| 182 | | } |
| 183 | | |
| | 229 | if(!new_instance && unique_app_is_running(app)) |
| | 230 | { |
| | 231 | int exit_code = my_unique_check_other(app, argc - 1, argv + 1); |