int ShowFolderInOSWindow(ExtensionString pathname) { int error = NO_ERROR; GError *gerror = NULL; gchar *uri = NULL, *parentdir = NULL; if (g_file_test(pathname.c_str(), G_FILE_TEST_IS_DIR)) { uri = g_filename_to_uri(pathname.c_str(), NULL, NULL); if (!gtk_show_uri(NULL, uri, GDK_CURRENT_TIME, &gerror)) { error = ConvertGnomeErrorCode(gerror); g_warning("%s", gerror->message); g_error_free(gerror); } g_free(uri); } else { if (!FileManager1_ShowItems(pathname.c_str())) { // Fall back to using gtk_show_uri on the dirname (without highlighting the file) parentdir = g_path_get_dirname(pathname.c_str()); uri = g_filename_to_uri(parentdir, NULL, NULL); if (!gtk_show_uri(NULL, uri, GDK_CURRENT_TIME, &gerror)) { error = ConvertGnomeErrorCode(gerror); g_warning("%s", gerror->message); g_error_free(gerror); } g_free(parentdir); g_free(uri); } } return error; }
void CloseLiveBrowser(CefRefPtr<CefBrowser> browser, CefRefPtr<CefProcessMessage> response) { const char *killall = "killall -9 %s"; gchar *cmdline; gint exitstatus; GError *gerror = NULL; int error = NO_ERROR; CefRefPtr<CefListValue> responseArgs = response->GetArgumentList(); // check for supported browsers (in PATH directories) for (size_t i = 0; i < sizeof(browsers) / sizeof(browsers[0]); i++) { cmdline = g_strdup_printf(killall, browsers[i].c_str()); // FIXME (jasonsanjose): use async if (!g_spawn_command_line_sync(cmdline, NULL, NULL, &exitstatus, &gerror)) { error = ConvertGnomeErrorCode(gerror); g_error_free(gerror); } g_free(cmdline); // browser is found in os; stop iterating if (exitstatus == 0) { error = NO_ERROR; break; } } responseArgs->SetInt(1, error); browser->SendProcessMessage(PID_RENDERER, response); }
int GErrorToErrorCode(GError *gerror) { int error = ConvertGnomeErrorCode(gerror); // uncomment to see errors printed to the console //g_warning(gerror->message); g_error_free(gerror); return error; }
void MoveFileOrDirectoryToTrash(ExtensionString filename, CefRefPtr<CefBrowser> browser, CefRefPtr<CefProcessMessage> response) { int error = NO_ERROR; GFile *file = g_file_new_for_path(filename.c_str()); GError *gerror = NULL; if (!g_file_trash(file, NULL, &gerror)) { error = ConvertGnomeErrorCode(gerror); g_error_free(gerror); } g_object_unref(file); response->GetArgumentList()->SetInt(1, error); browser->SendProcessMessage(PID_RENDERER, response); }
int32 OpenLiveBrowser(ExtensionString argURL, bool enableRemoteDebugging) { const char *remoteDebuggingFormat = "--no-first-run --no-default-browser-check --allow-file-access-from-files --temp-profile --user-data-dir=%s --remote-debugging-port=9222"; gchar *remoteDebugging; gchar *cmdline; int error = ERR_BROWSER_NOT_INSTALLED; GError *gerror = NULL; if (enableRemoteDebugging) { CefString appSupportDirectory = ClientApp::AppGetSupportDirectory(); // TODO: (INGO) to better understand to string conversion issue, I need a consultant // here. Getting the char* from CefString I had to call ToString().c_str() // Calling only c_str() didn't return anything. gchar *userDataDir = g_strdup_printf("%s/live-dev-profile", appSupportDirectory.ToString().c_str()); g_message("USERDATADIR= %s", userDataDir); remoteDebugging = g_strdup_printf(remoteDebuggingFormat, userDataDir); g_free(userDataDir); } else { remoteDebugging = g_strdup(""); } // check for supported browsers (in PATH directories) for (size_t i = 0; i < sizeof(browsers) / sizeof(browsers[0]); i++) { cmdline = g_strdup_printf("%s %s %s", browsers[i].c_str(), argURL.c_str(), remoteDebugging); if (g_spawn_command_line_async(cmdline, &gerror)) { // browser is found in os; stop iterating error = NO_ERROR; } else { error = ConvertGnomeErrorCode(gerror); } g_free(cmdline); if (error == NO_ERROR) { break; } else { g_error_free(gerror); gerror = NULL; } } g_free(remoteDebugging); return error; }
int32 CopyFile(ExtensionString src, ExtensionString dest) { int error = NO_ERROR; GFile *source = g_file_new_for_path(src.c_str()); GFile *destination = g_file_new_for_path(dest.c_str()); GError *gerror = NULL; if (!g_file_copy(source, destination, (GFileCopyFlags)(G_FILE_COPY_OVERWRITE|G_FILE_COPY_NOFOLLOW_SYMLINKS|G_FILE_COPY_TARGET_DEFAULT_PERMS), NULL, NULL, NULL, &gerror)) { error = ConvertGnomeErrorCode(gerror); g_error_free(gerror); } g_object_unref(source); g_object_unref(destination); return error; }
int ShowFolderInOSWindow(ExtensionString pathname) { int error = NO_ERROR; GError *gerror = NULL; gchar *uri = g_strdup_printf("file://%s", pathname.c_str()); if (!gtk_show_uri(NULL, uri, GDK_CURRENT_TIME, &gerror)) { error = ConvertGnomeErrorCode(gerror); g_warning("%s", gerror->message); g_error_free(gerror); } g_free(uri); return error; }