OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/mime_util.h" | 5 #include "base/mime_util.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 #include <sys/time.h> | 8 #include <sys/time.h> |
9 #include <time.h> | 9 #include <time.h> |
10 | 10 |
11 #include <cstdlib> | 11 #include <cstdlib> |
12 #include <list> | 12 #include <list> |
13 #include <map> | 13 #include <map> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/environment.h" | |
16 #include "base/file_util.h" | 17 #include "base/file_util.h" |
17 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
20 #include "base/memory/singleton.h" | 21 #include "base/memory/singleton.h" |
21 #include "base/message_loop.h" | 22 #include "base/message_loop.h" |
23 #include "base/nix/xdg_util.h" | |
22 #include "base/string_split.h" | 24 #include "base/string_split.h" |
23 #include "base/string_util.h" | 25 #include "base/string_util.h" |
24 #include "base/synchronization/lock.h" | 26 #include "base/synchronization/lock.h" |
25 #include "base/third_party/xdg_mime/xdgmime.h" | 27 #include "base/third_party/xdg_mime/xdgmime.h" |
26 #include "base/threading/thread_restrictions.h" | 28 #include "base/threading/thread_restrictions.h" |
27 | 29 |
28 namespace { | 30 namespace { |
29 | 31 |
30 // None of the XDG stuff is thread-safe, so serialize all access under | 32 // None of the XDG stuff is thread-safe, so serialize all access under |
31 // this lock. | 33 // this lock. |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 } | 480 } |
479 } | 481 } |
480 return FilePath(); | 482 return FilePath(); |
481 } | 483 } |
482 | 484 |
483 // Initialize the list of default themes. | 485 // Initialize the list of default themes. |
484 void InitDefaultThemes() { | 486 void InitDefaultThemes() { |
485 IconTheme** default_themes = | 487 IconTheme** default_themes = |
486 MimeUtilConstants::GetInstance()->default_themes_; | 488 MimeUtilConstants::GetInstance()->default_themes_; |
487 | 489 |
488 char* env = getenv("KDE_FULL_SESSION"); | 490 scoped_ptr<base::Environment> env(base::Environment::Create()); |
489 if (env) { | 491 base::nix::DesktopEnvironment desktop_env = |
492 base::nix::GetDesktopEnvironment(env.get()); | |
493 if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE3 || | |
494 desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4) { | |
490 // KDE | 495 // KDE |
491 std::string kde_default_theme; | 496 std::string kde_default_theme; |
492 std::string kde_fallback_theme; | 497 std::string kde_fallback_theme; |
493 | 498 |
494 // TODO(thestig): Figure out how to get the current icon theme on KDE. | 499 // TODO(thestig): Figure out how to get the current icon theme on KDE. |
495 // Setting stored in ~/.kde/share/config/kdeglobals under Icons -> Theme. | 500 // Setting stored in ~/.kde/share/config/kdeglobals under Icons -> Theme. |
496 default_themes[0] = NULL; | 501 default_themes[0] = NULL; |
497 | 502 |
498 // Try some reasonable defaults for KDE. | 503 // Try some reasonable defaults for KDE. |
499 env = getenv("KDE_SESSION_VERSION"); | 504 if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE3) { |
500 if (!env || env[0] != '4') { | |
501 // KDE 3 | 505 // KDE 3 |
502 kde_default_theme = "default.kde"; | 506 kde_default_theme = "default.kde"; |
503 kde_fallback_theme = "crystalsvg"; | 507 kde_fallback_theme = "crystalsvg"; |
504 } else { | 508 } else { |
505 // KDE 4 | 509 // KDE 4 |
506 kde_default_theme = "default.kde4"; | 510 kde_default_theme = "default.kde4"; |
507 kde_fallback_theme = "oxygen"; | 511 kde_fallback_theme = "oxygen"; |
508 } | 512 } |
509 default_themes[1] = IconTheme::LoadTheme(kde_default_theme); | 513 default_themes[1] = IconTheme::LoadTheme(kde_default_theme); |
510 default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme); | 514 default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
608 icon_name = mime_type; | 612 icon_name = mime_type; |
609 for (size_t i = icon_name.find('/', 0); i != std::string::npos; | 613 for (size_t i = icon_name.find('/', 0); i != std::string::npos; |
610 i = icon_name.find('/', i + 1)) { | 614 i = icon_name.find('/', i + 1)) { |
611 icon_name[i] = '-'; | 615 icon_name[i] = '-'; |
612 } | 616 } |
613 icon_names.push_back(icon_name); | 617 icon_names.push_back(icon_name); |
614 // Also try gnome-mime-text-plain. | 618 // Also try gnome-mime-text-plain. |
615 icon_names.push_back("gnome-mime-" + icon_name); | 619 icon_names.push_back("gnome-mime-" + icon_name); |
616 | 620 |
617 // Try "deb" for "application/x-deb" in KDE 3. | 621 // Try "deb" for "application/x-deb" in KDE 3. |
618 icon_name = mime_type.substr(mime_type.find("/x-") + 3); | 622 size_t x_substr_pos = mime_type.find("/x-"); |
619 icon_names.push_back(icon_name); | 623 if (x_substr_pos != std::string::npos) { |
willchan no longer on Chromium
2011/11/01 20:54:49
This is a new change that isn't explained by the c
Lei Zhang
2011/11/01 21:03:29
This is the "Also fix a case where we look up bad
willchan no longer on Chromium
2011/11/01 21:04:15
Sorry, I missed that. Explanation sounds great.
| |
624 icon_name = mime_type.substr(x_substr_pos + 3); | |
625 icon_names.push_back(icon_name); | |
626 } | |
620 | 627 |
621 // Try generic name like text-x-generic. | 628 // Try generic name like text-x-generic. |
622 icon_name = mime_type.substr(0, mime_type.find('/')) + "-x-generic"; | 629 icon_name = mime_type.substr(0, mime_type.find('/')) + "-x-generic"; |
623 icon_names.push_back(icon_name); | 630 icon_names.push_back(icon_name); |
624 | 631 |
625 // Last resort | 632 // Last resort |
626 icon_names.push_back("unknown"); | 633 icon_names.push_back("unknown"); |
627 | 634 |
628 for (size_t i = 0; i < icon_names.size(); i++) { | 635 for (size_t i = 0; i < icon_names.size(); i++) { |
629 if (icon_names[i][0] == '/') { | 636 if (icon_names[i][0] == '/') { |
630 icon_file = FilePath(icon_names[i]); | 637 icon_file = FilePath(icon_names[i]); |
631 if (file_util::PathExists(icon_file)) | 638 if (file_util::PathExists(icon_file)) |
632 return icon_file; | 639 return icon_file; |
633 } else { | 640 } else { |
634 icon_file = LookupIconInDefaultTheme(icon_names[i], size); | 641 icon_file = LookupIconInDefaultTheme(icon_names[i], size); |
635 if (!icon_file.empty()) | 642 if (!icon_file.empty()) |
636 return icon_file; | 643 return icon_file; |
637 } | 644 } |
638 } | 645 } |
639 return FilePath(); | 646 return FilePath(); |
640 } | 647 } |
641 | 648 |
642 } // namespace mime_util | 649 } // namespace mime_util |
OLD | NEW |