| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <set> | 5 #include <set> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 public: | 40 public: |
| 41 SelectFileDialogImplKDE(Listener* listener, | 41 SelectFileDialogImplKDE(Listener* listener, |
| 42 ui::SelectFilePolicy* policy, | 42 ui::SelectFilePolicy* policy, |
| 43 base::nix::DesktopEnvironment desktop); | 43 base::nix::DesktopEnvironment desktop); |
| 44 | 44 |
| 45 protected: | 45 protected: |
| 46 virtual ~SelectFileDialogImplKDE(); | 46 virtual ~SelectFileDialogImplKDE(); |
| 47 | 47 |
| 48 // SelectFileDialog implementation. | 48 // SelectFileDialog implementation. |
| 49 // |params| is user data we pass back via the Listener interface. | 49 // |params| is user data we pass back via the Listener interface. |
| 50 virtual void SelectFileImpl(Type type, | 50 virtual void SelectFileImpl( |
| 51 const string16& title, | 51 Type type, |
| 52 const FilePath& default_path, | 52 const string16& title, |
| 53 const FileTypeInfo* file_types, | 53 const base::FilePath& default_path, |
| 54 int file_type_index, | 54 const FileTypeInfo* file_types, |
| 55 const FilePath::StringType& default_extension, | 55 int file_type_index, |
| 56 gfx::NativeWindow owning_window, | 56 const base::FilePath::StringType& default_extension, |
| 57 void* params) OVERRIDE; | 57 gfx::NativeWindow owning_window, |
| 58 void* params) OVERRIDE; |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 virtual bool HasMultipleFileTypeChoicesImpl() OVERRIDE; | 61 virtual bool HasMultipleFileTypeChoicesImpl() OVERRIDE; |
| 61 | 62 |
| 62 struct KDialogParams { | 63 struct KDialogParams { |
| 63 // This constructor can only be run from the UI thread. | 64 // This constructor can only be run from the UI thread. |
| 64 KDialogParams(const std::string& type, const std::string& title, | 65 KDialogParams(const std::string& type, const std::string& title, |
| 65 const FilePath& default_path, gfx::NativeWindow parent, | 66 const base::FilePath& default_path, gfx::NativeWindow parent, |
| 66 bool file_operation, bool multiple_selection, | 67 bool file_operation, bool multiple_selection, |
| 67 void* kdialog_params, | 68 void* kdialog_params, |
| 68 void (SelectFileDialogImplKDE::*callback)(const std::string&, | 69 void (SelectFileDialogImplKDE::*callback)(const std::string&, |
| 69 int, void*)) | 70 int, void*)) |
| 70 : type(type), title(title), default_path(default_path), parent(parent), | 71 : type(type), title(title), default_path(default_path), parent(parent), |
| 71 file_operation(file_operation), | 72 file_operation(file_operation), |
| 72 multiple_selection(multiple_selection), | 73 multiple_selection(multiple_selection), |
| 73 kdialog_params(kdialog_params), | 74 kdialog_params(kdialog_params), |
| 74 ui_loop_proxy(MessageLoopForUI::current()->message_loop_proxy()), | 75 ui_loop_proxy(MessageLoopForUI::current()->message_loop_proxy()), |
| 75 callback(callback) { | 76 callback(callback) { |
| 76 } | 77 } |
| 77 | 78 |
| 78 std::string type; | 79 std::string type; |
| 79 std::string title; | 80 std::string title; |
| 80 FilePath default_path; | 81 base::FilePath default_path; |
| 81 gfx::NativeWindow parent; | 82 gfx::NativeWindow parent; |
| 82 bool file_operation; | 83 bool file_operation; |
| 83 bool multiple_selection; | 84 bool multiple_selection; |
| 84 void* kdialog_params; | 85 void* kdialog_params; |
| 85 scoped_refptr<base::MessageLoopProxy> ui_loop_proxy; | 86 scoped_refptr<base::MessageLoopProxy> ui_loop_proxy; |
| 86 | 87 |
| 87 void (SelectFileDialogImplKDE::*callback)(const std::string&, int, void*); | 88 void (SelectFileDialogImplKDE::*callback)(const std::string&, int, void*); |
| 88 }; | 89 }; |
| 89 | 90 |
| 90 // Get the filters from |file_types_| and concatenate them into | 91 // Get the filters from |file_types_| and concatenate them into |
| 91 // |filter_string|. | 92 // |filter_string|. |
| 92 std::string GetMimeTypeFilterString(); | 93 std::string GetMimeTypeFilterString(); |
| 93 | 94 |
| 94 // Get KDialog command line representing the Argv array for KDialog. | 95 // Get KDialog command line representing the Argv array for KDialog. |
| 95 void GetKDialogCommandLine(const std::string& type, const std::string& title, | 96 void GetKDialogCommandLine(const std::string& type, const std::string& title, |
| 96 const FilePath& default_path, gfx::NativeWindow parent, | 97 const base::FilePath& default_path, gfx::NativeWindow parent, |
| 97 bool file_operation, bool multiple_selection, CommandLine* command_line); | 98 bool file_operation, bool multiple_selection, CommandLine* command_line); |
| 98 | 99 |
| 99 // Call KDialog on a worker thread and post results back to the caller | 100 // Call KDialog on a worker thread and post results back to the caller |
| 100 // thread. | 101 // thread. |
| 101 void CallKDialogOutput(const KDialogParams& params); | 102 void CallKDialogOutput(const KDialogParams& params); |
| 102 | 103 |
| 103 // Notifies the listener that a single file was chosen. | 104 // Notifies the listener that a single file was chosen. |
| 104 void FileSelected(const FilePath& path, void* params); | 105 void FileSelected(const base::FilePath& path, void* params); |
| 105 | 106 |
| 106 // Notifies the listener that multiple files were chosen. | 107 // Notifies the listener that multiple files were chosen. |
| 107 void MultiFilesSelected(const std::vector<FilePath>& files, void* params); | 108 void MultiFilesSelected(const std::vector<base::FilePath>& files, |
| 109 void* params); |
| 108 | 110 |
| 109 // Notifies the listener that no file was chosen (the action was canceled). | 111 // Notifies the listener that no file was chosen (the action was canceled). |
| 110 // Dialog is passed so we can find that |params| pointer that was passed to | 112 // Dialog is passed so we can find that |params| pointer that was passed to |
| 111 // us when we were told to show the dialog. | 113 // us when we were told to show the dialog. |
| 112 void FileNotSelected(void *params); | 114 void FileNotSelected(void *params); |
| 113 | 115 |
| 114 void CreateSelectFolderDialog(const std::string& title, | 116 void CreateSelectFolderDialog(const std::string& title, |
| 115 const FilePath& default_path, | 117 const base::FilePath& default_path, |
| 116 gfx::NativeWindow parent, void* params); | 118 gfx::NativeWindow parent, void* params); |
| 117 | 119 |
| 118 void CreateFileOpenDialog(const std::string& title, | 120 void CreateFileOpenDialog(const std::string& title, |
| 119 const FilePath& default_path, | 121 const base::FilePath& default_path, |
| 120 gfx::NativeWindow parent, void* params); | 122 gfx::NativeWindow parent, void* params); |
| 121 | 123 |
| 122 void CreateMultiFileOpenDialog(const std::string& title, | 124 void CreateMultiFileOpenDialog(const std::string& title, |
| 123 const FilePath& default_path, | 125 const base::FilePath& default_path, |
| 124 gfx::NativeWindow parent, void* params); | 126 gfx::NativeWindow parent, void* params); |
| 125 | 127 |
| 126 void CreateSaveAsDialog(const std::string& title, | 128 void CreateSaveAsDialog(const std::string& title, |
| 127 const FilePath& default_path, | 129 const base::FilePath& default_path, |
| 128 gfx::NativeWindow parent, void* params); | 130 gfx::NativeWindow parent, void* params); |
| 129 | 131 |
| 130 // Common function for OnSelectSingleFileDialogResponse and | 132 // Common function for OnSelectSingleFileDialogResponse and |
| 131 // OnSelectSingleFolderDialogResponse. | 133 // OnSelectSingleFolderDialogResponse. |
| 132 void SelectSingleFileHelper(const std::string& output, int exit_code, | 134 void SelectSingleFileHelper(const std::string& output, int exit_code, |
| 133 void* params, bool allow_folder); | 135 void* params, bool allow_folder); |
| 134 | 136 |
| 135 void OnSelectSingleFileDialogResponse(const std::string& output, | 137 void OnSelectSingleFileDialogResponse(const std::string& output, |
| 136 int exit_code, void* params); | 138 int exit_code, void* params); |
| 137 void OnSelectMultiFileDialogResponse(const std::string& output, | 139 void OnSelectMultiFileDialogResponse(const std::string& output, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 155 desktop_ == base::nix::DESKTOP_ENVIRONMENT_KDE4); | 157 desktop_ == base::nix::DESKTOP_ENVIRONMENT_KDE4); |
| 156 } | 158 } |
| 157 | 159 |
| 158 SelectFileDialogImplKDE::~SelectFileDialogImplKDE() { | 160 SelectFileDialogImplKDE::~SelectFileDialogImplKDE() { |
| 159 } | 161 } |
| 160 | 162 |
| 161 // We ignore |default_extension|. | 163 // We ignore |default_extension|. |
| 162 void SelectFileDialogImplKDE::SelectFileImpl( | 164 void SelectFileDialogImplKDE::SelectFileImpl( |
| 163 Type type, | 165 Type type, |
| 164 const string16& title, | 166 const string16& title, |
| 165 const FilePath& default_path, | 167 const base::FilePath& default_path, |
| 166 const FileTypeInfo* file_types, | 168 const FileTypeInfo* file_types, |
| 167 int file_type_index, | 169 int file_type_index, |
| 168 const FilePath::StringType& default_extension, | 170 const base::FilePath::StringType& default_extension, |
| 169 gfx::NativeWindow owning_window, | 171 gfx::NativeWindow owning_window, |
| 170 void* params) { | 172 void* params) { |
| 171 type_ = type; | 173 type_ = type; |
| 172 // |owning_window| can be null when user right-clicks on a downloadable item | 174 // |owning_window| can be null when user right-clicks on a downloadable item |
| 173 // and chooses 'Open Link in New Tab' when 'Ask where to save each file | 175 // and chooses 'Open Link in New Tab' when 'Ask where to save each file |
| 174 // before downloading.' preference is turned on. (http://crbug.com/29213) | 176 // before downloading.' preference is turned on. (http://crbug.com/29213) |
| 175 if (owning_window) | 177 if (owning_window) |
| 176 parents_.insert(owning_window); | 178 parents_.insert(owning_window); |
| 177 | 179 |
| 178 std::string title_string = UTF16ToUTF8(title); | 180 std::string title_string = UTF16ToUTF8(title); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 213 } |
| 212 | 214 |
| 213 std::string SelectFileDialogImplKDE::GetMimeTypeFilterString() { | 215 std::string SelectFileDialogImplKDE::GetMimeTypeFilterString() { |
| 214 std::string filter_string; | 216 std::string filter_string; |
| 215 // We need a filter set because the same mime type can appear multiple times. | 217 // We need a filter set because the same mime type can appear multiple times. |
| 216 std::set<std::string> filter_set; | 218 std::set<std::string> filter_set; |
| 217 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { | 219 for (size_t i = 0; i < file_types_.extensions.size(); ++i) { |
| 218 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { | 220 for (size_t j = 0; j < file_types_.extensions[i].size(); ++j) { |
| 219 if (!file_types_.extensions[i][j].empty()) { | 221 if (!file_types_.extensions[i][j].empty()) { |
| 220 std::string mime_type = base::nix::GetFileMimeType( | 222 std::string mime_type = base::nix::GetFileMimeType( |
| 221 FilePath("name").ReplaceExtension(file_types_.extensions[i][j])); | 223 base::FilePath("name").ReplaceExtension( |
| 224 file_types_.extensions[i][j])); |
| 222 filter_set.insert(mime_type); | 225 filter_set.insert(mime_type); |
| 223 } | 226 } |
| 224 } | 227 } |
| 225 } | 228 } |
| 226 // Add the *.* filter, but only if we have added other filters (otherwise it | 229 // Add the *.* filter, but only if we have added other filters (otherwise it |
| 227 // is implied). | 230 // is implied). |
| 228 if (file_types_.include_all_files && !file_types_.extensions.empty()) | 231 if (file_types_.include_all_files && !file_types_.extensions.empty()) |
| 229 filter_set.insert("application/octet-stream"); | 232 filter_set.insert("application/octet-stream"); |
| 230 // Create the final output string. | 233 // Create the final output string. |
| 231 filter_string.clear(); | 234 filter_string.clear(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 253 // parent set. | 256 // parent set. |
| 254 std::set<GtkWindow*>::iterator iter = parents_.find(params.parent); | 257 std::set<GtkWindow*>::iterator iter = parents_.find(params.parent); |
| 255 if (iter != parents_.end()) | 258 if (iter != parents_.end()) |
| 256 parents_.erase(iter); | 259 parents_.erase(iter); |
| 257 params.ui_loop_proxy->PostTask(FROM_HERE, | 260 params.ui_loop_proxy->PostTask(FROM_HERE, |
| 258 base::Bind(params.callback, this, output, exit_code, | 261 base::Bind(params.callback, this, output, exit_code, |
| 259 params.kdialog_params)); | 262 params.kdialog_params)); |
| 260 } | 263 } |
| 261 | 264 |
| 262 void SelectFileDialogImplKDE::GetKDialogCommandLine(const std::string& type, | 265 void SelectFileDialogImplKDE::GetKDialogCommandLine(const std::string& type, |
| 263 const std::string& title, const FilePath& path, | 266 const std::string& title, const base::FilePath& path, |
| 264 gfx::NativeWindow parent, bool file_operation, bool multiple_selection, | 267 gfx::NativeWindow parent, bool file_operation, bool multiple_selection, |
| 265 CommandLine* command_line) { | 268 CommandLine* command_line) { |
| 266 CHECK(command_line); | 269 CHECK(command_line); |
| 267 | 270 |
| 268 // Attach to the current Chrome window. | 271 // Attach to the current Chrome window. |
| 269 GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET((parent))); | 272 GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET((parent))); |
| 270 int window_id = GDK_DRAWABLE_XID(gdk_window); | 273 int window_id = GDK_DRAWABLE_XID(gdk_window); |
| 271 command_line->AppendSwitchNative( | 274 command_line->AppendSwitchNative( |
| 272 desktop_ == base::nix::DESKTOP_ENVIRONMENT_KDE3 ? "--embed" : "--attach", | 275 desktop_ == base::nix::DESKTOP_ENVIRONMENT_KDE3 ? "--embed" : "--attach", |
| 273 base::IntToString(window_id)); | 276 base::IntToString(window_id)); |
| 274 // Set the correct title for the dialog. | 277 // Set the correct title for the dialog. |
| 275 if (!title.empty()) | 278 if (!title.empty()) |
| 276 command_line->AppendSwitchNative("--title", title); | 279 command_line->AppendSwitchNative("--title", title); |
| 277 // Enable multiple file selection if we need to. | 280 // Enable multiple file selection if we need to. |
| 278 if (multiple_selection) { | 281 if (multiple_selection) { |
| 279 command_line->AppendSwitch("--multiple"); | 282 command_line->AppendSwitch("--multiple"); |
| 280 command_line->AppendSwitch("--separate-output"); | 283 command_line->AppendSwitch("--separate-output"); |
| 281 } | 284 } |
| 282 command_line->AppendSwitch(type); | 285 command_line->AppendSwitch(type); |
| 283 // The path should never be empty. If it is, set it to PWD. | 286 // The path should never be empty. If it is, set it to PWD. |
| 284 if (path.empty()) | 287 if (path.empty()) |
| 285 command_line->AppendArgPath(FilePath(".")); | 288 command_line->AppendArgPath(base::FilePath(".")); |
| 286 else | 289 else |
| 287 command_line->AppendArgPath(path); | 290 command_line->AppendArgPath(path); |
| 288 // Depending on the type of the operation we need, get the path to the | 291 // Depending on the type of the operation we need, get the path to the |
| 289 // file/folder and set up mime type filters. | 292 // file/folder and set up mime type filters. |
| 290 if (file_operation) | 293 if (file_operation) |
| 291 command_line->AppendArg(GetMimeTypeFilterString()); | 294 command_line->AppendArg(GetMimeTypeFilterString()); |
| 292 VLOG(1) << "KDialog command line: " << command_line->GetCommandLineString(); | 295 VLOG(1) << "KDialog command line: " << command_line->GetCommandLineString(); |
| 293 } | 296 } |
| 294 | 297 |
| 295 void SelectFileDialogImplKDE::FileSelected(const FilePath& path, void* params) { | 298 void SelectFileDialogImplKDE::FileSelected(const base::FilePath& path, |
| 299 void* params) { |
| 296 if (type_ == SELECT_SAVEAS_FILE) | 300 if (type_ == SELECT_SAVEAS_FILE) |
| 297 *last_saved_path_ = path.DirName(); | 301 *last_saved_path_ = path.DirName(); |
| 298 else if (type_ == SELECT_OPEN_FILE) | 302 else if (type_ == SELECT_OPEN_FILE) |
| 299 *last_opened_path_ = path.DirName(); | 303 *last_opened_path_ = path.DirName(); |
| 300 else if (type_ == SELECT_FOLDER) | 304 else if (type_ == SELECT_FOLDER) |
| 301 *last_opened_path_ = path; | 305 *last_opened_path_ = path; |
| 302 else | 306 else |
| 303 NOTREACHED(); | 307 NOTREACHED(); |
| 304 if (listener_) { // What does the filter index actually do? | 308 if (listener_) { // What does the filter index actually do? |
| 305 // TODO(dfilimon): Get a reasonable index value from somewhere. | 309 // TODO(dfilimon): Get a reasonable index value from somewhere. |
| 306 listener_->FileSelected(path, 1, params); | 310 listener_->FileSelected(path, 1, params); |
| 307 } | 311 } |
| 308 } | 312 } |
| 309 | 313 |
| 310 void SelectFileDialogImplKDE::MultiFilesSelected( | 314 void SelectFileDialogImplKDE::MultiFilesSelected( |
| 311 const std::vector<FilePath>& files, void* params) { | 315 const std::vector<base::FilePath>& files, void* params) { |
| 312 *last_opened_path_ = files[0].DirName(); | 316 *last_opened_path_ = files[0].DirName(); |
| 313 if (listener_) | 317 if (listener_) |
| 314 listener_->MultiFilesSelected(files, params); | 318 listener_->MultiFilesSelected(files, params); |
| 315 } | 319 } |
| 316 | 320 |
| 317 void SelectFileDialogImplKDE::FileNotSelected(void* params) { | 321 void SelectFileDialogImplKDE::FileNotSelected(void* params) { |
| 318 if (listener_) | 322 if (listener_) |
| 319 listener_->FileSelectionCanceled(params); | 323 listener_->FileSelectionCanceled(params); |
| 320 } | 324 } |
| 321 | 325 |
| 322 void SelectFileDialogImplKDE::CreateSelectFolderDialog( | 326 void SelectFileDialogImplKDE::CreateSelectFolderDialog( |
| 323 const std::string& title, const FilePath& default_path, | 327 const std::string& title, const base::FilePath& default_path, |
| 324 gfx::NativeWindow parent, void *params) { | 328 gfx::NativeWindow parent, void *params) { |
| 325 base::WorkerPool::PostTask(FROM_HERE, | 329 base::WorkerPool::PostTask(FROM_HERE, |
| 326 base::Bind( | 330 base::Bind( |
| 327 &SelectFileDialogImplKDE::CallKDialogOutput, | 331 &SelectFileDialogImplKDE::CallKDialogOutput, |
| 328 this, | 332 this, |
| 329 KDialogParams( | 333 KDialogParams( |
| 330 "--getexistingdirectory", | 334 "--getexistingdirectory", |
| 331 GetTitle(title, IDS_SELECT_FOLDER_DIALOG_TITLE), | 335 GetTitle(title, IDS_SELECT_FOLDER_DIALOG_TITLE), |
| 332 default_path.empty() ? *last_opened_path_ : default_path, | 336 default_path.empty() ? *last_opened_path_ : default_path, |
| 333 parent, false, false, params, | 337 parent, false, false, params, |
| 334 &SelectFileDialogImplKDE::OnSelectSingleFolderDialogResponse)), | 338 &SelectFileDialogImplKDE::OnSelectSingleFolderDialogResponse)), |
| 335 true); | 339 true); |
| 336 } | 340 } |
| 337 | 341 |
| 338 void SelectFileDialogImplKDE::CreateFileOpenDialog( | 342 void SelectFileDialogImplKDE::CreateFileOpenDialog( |
| 339 const std::string& title, const FilePath& default_path, | 343 const std::string& title, const base::FilePath& default_path, |
| 340 gfx::NativeWindow parent, void* params) { | 344 gfx::NativeWindow parent, void* params) { |
| 341 base::WorkerPool::PostTask(FROM_HERE, | 345 base::WorkerPool::PostTask(FROM_HERE, |
| 342 base::Bind( | 346 base::Bind( |
| 343 &SelectFileDialogImplKDE::CallKDialogOutput, | 347 &SelectFileDialogImplKDE::CallKDialogOutput, |
| 344 this, | 348 this, |
| 345 KDialogParams( | 349 KDialogParams( |
| 346 "--getopenfilename", | 350 "--getopenfilename", |
| 347 GetTitle(title, IDS_OPEN_FILE_DIALOG_TITLE), | 351 GetTitle(title, IDS_OPEN_FILE_DIALOG_TITLE), |
| 348 default_path.empty() ? *last_opened_path_ : default_path, | 352 default_path.empty() ? *last_opened_path_ : default_path, |
| 349 parent, true, false, params, | 353 parent, true, false, params, |
| 350 &SelectFileDialogImplKDE::OnSelectSingleFileDialogResponse)), | 354 &SelectFileDialogImplKDE::OnSelectSingleFileDialogResponse)), |
| 351 true); | 355 true); |
| 352 } | 356 } |
| 353 | 357 |
| 354 void SelectFileDialogImplKDE::CreateMultiFileOpenDialog( | 358 void SelectFileDialogImplKDE::CreateMultiFileOpenDialog( |
| 355 const std::string& title, const FilePath& default_path, | 359 const std::string& title, const base::FilePath& default_path, |
| 356 gfx::NativeWindow parent, void* params) { | 360 gfx::NativeWindow parent, void* params) { |
| 357 base::WorkerPool::PostTask(FROM_HERE, | 361 base::WorkerPool::PostTask(FROM_HERE, |
| 358 base::Bind( | 362 base::Bind( |
| 359 &SelectFileDialogImplKDE::CallKDialogOutput, | 363 &SelectFileDialogImplKDE::CallKDialogOutput, |
| 360 this, | 364 this, |
| 361 KDialogParams( | 365 KDialogParams( |
| 362 "--getopenfilename", | 366 "--getopenfilename", |
| 363 GetTitle(title, IDS_OPEN_FILES_DIALOG_TITLE), | 367 GetTitle(title, IDS_OPEN_FILES_DIALOG_TITLE), |
| 364 default_path.empty() ? *last_opened_path_ : default_path, | 368 default_path.empty() ? *last_opened_path_ : default_path, |
| 365 parent, true, true, params, | 369 parent, true, true, params, |
| 366 &SelectFileDialogImplKDE::OnSelectMultiFileDialogResponse)), | 370 &SelectFileDialogImplKDE::OnSelectMultiFileDialogResponse)), |
| 367 true); | 371 true); |
| 368 } | 372 } |
| 369 | 373 |
| 370 void SelectFileDialogImplKDE::CreateSaveAsDialog( | 374 void SelectFileDialogImplKDE::CreateSaveAsDialog( |
| 371 const std::string& title, const FilePath& default_path, | 375 const std::string& title, const base::FilePath& default_path, |
| 372 gfx::NativeWindow parent, void* params) { | 376 gfx::NativeWindow parent, void* params) { |
| 373 base::WorkerPool::PostTask(FROM_HERE, | 377 base::WorkerPool::PostTask(FROM_HERE, |
| 374 base::Bind( | 378 base::Bind( |
| 375 &SelectFileDialogImplKDE::CallKDialogOutput, | 379 &SelectFileDialogImplKDE::CallKDialogOutput, |
| 376 this, | 380 this, |
| 377 KDialogParams( | 381 KDialogParams( |
| 378 "--getsavefilename", | 382 "--getsavefilename", |
| 379 GetTitle(title, IDS_SAVE_AS_DIALOG_TITLE), | 383 GetTitle(title, IDS_SAVE_AS_DIALOG_TITLE), |
| 380 default_path.empty() ? *last_saved_path_ : default_path, | 384 default_path.empty() ? *last_saved_path_ : default_path, |
| 381 parent, true, false, params, | 385 parent, true, false, params, |
| 382 &SelectFileDialogImplKDE::OnSelectSingleFileDialogResponse)), | 386 &SelectFileDialogImplKDE::OnSelectSingleFileDialogResponse)), |
| 383 true); | 387 true); |
| 384 } | 388 } |
| 385 | 389 |
| 386 void SelectFileDialogImplKDE::SelectSingleFileHelper(const std::string& output, | 390 void SelectFileDialogImplKDE::SelectSingleFileHelper(const std::string& output, |
| 387 int exit_code, void* params, bool allow_folder) { | 391 int exit_code, void* params, bool allow_folder) { |
| 388 VLOG(1) << "[kdialog] SingleFileResponse: " << output; | 392 VLOG(1) << "[kdialog] SingleFileResponse: " << output; |
| 389 if (exit_code != 0 || output.empty()) { | 393 if (exit_code != 0 || output.empty()) { |
| 390 FileNotSelected(params); | 394 FileNotSelected(params); |
| 391 return; | 395 return; |
| 392 } | 396 } |
| 393 | 397 |
| 394 FilePath path(output); | 398 base::FilePath path(output); |
| 395 if (allow_folder) { | 399 if (allow_folder) { |
| 396 FileSelected(path, params); | 400 FileSelected(path, params); |
| 397 return; | 401 return; |
| 398 } | 402 } |
| 399 | 403 |
| 400 if (CallDirectoryExistsOnUIThread(path)) | 404 if (CallDirectoryExistsOnUIThread(path)) |
| 401 FileNotSelected(params); | 405 FileNotSelected(params); |
| 402 else | 406 else |
| 403 FileSelected(path, params); | 407 FileSelected(path, params); |
| 404 } | 408 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 417 const std::string& output, int exit_code, void* params) { | 421 const std::string& output, int exit_code, void* params) { |
| 418 VLOG(1) << "[kdialog] MultiFileResponse: " << output; | 422 VLOG(1) << "[kdialog] MultiFileResponse: " << output; |
| 419 | 423 |
| 420 if (exit_code != 0 || output.empty()) { | 424 if (exit_code != 0 || output.empty()) { |
| 421 FileNotSelected(params); | 425 FileNotSelected(params); |
| 422 return; | 426 return; |
| 423 } | 427 } |
| 424 | 428 |
| 425 std::vector<std::string> filenames; | 429 std::vector<std::string> filenames; |
| 426 Tokenize(output, "\n", &filenames); | 430 Tokenize(output, "\n", &filenames); |
| 427 std::vector<FilePath> filenames_fp; | 431 std::vector<base::FilePath> filenames_fp; |
| 428 for (std::vector<std::string>::iterator iter = filenames.begin(); | 432 for (std::vector<std::string>::iterator iter = filenames.begin(); |
| 429 iter != filenames.end(); ++iter) { | 433 iter != filenames.end(); ++iter) { |
| 430 FilePath path(*iter); | 434 base::FilePath path(*iter); |
| 431 if (CallDirectoryExistsOnUIThread(path)) | 435 if (CallDirectoryExistsOnUIThread(path)) |
| 432 continue; | 436 continue; |
| 433 filenames_fp.push_back(path); | 437 filenames_fp.push_back(path); |
| 434 } | 438 } |
| 435 | 439 |
| 436 if (filenames_fp.empty()) { | 440 if (filenames_fp.empty()) { |
| 437 FileNotSelected(params); | 441 FileNotSelected(params); |
| 438 return; | 442 return; |
| 439 } | 443 } |
| 440 MultiFilesSelected(filenames_fp, params); | 444 MultiFilesSelected(filenames_fp, params); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 461 // static | 465 // static |
| 462 SelectFileDialogImpl* SelectFileDialogImpl::NewSelectFileDialogImplKDE( | 466 SelectFileDialogImpl* SelectFileDialogImpl::NewSelectFileDialogImplKDE( |
| 463 Listener* listener, | 467 Listener* listener, |
| 464 ui::SelectFilePolicy* policy, | 468 ui::SelectFilePolicy* policy, |
| 465 base::nix::DesktopEnvironment desktop) { | 469 base::nix::DesktopEnvironment desktop) { |
| 466 return new SelectFileDialogImplKDE(listener, policy, desktop); | 470 return new SelectFileDialogImplKDE(listener, policy, desktop); |
| 467 } | 471 } |
| 468 | 472 |
| 469 } // namespace ui | 473 } // namespace ui |
| 470 | 474 |
| OLD | NEW |