Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(725)

Side by Side Diff: base/nix/xdg_util.cc

Issue 10548019: Cleanup: Consolidate declarations of XDG variables. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/nix/xdg_util.h ('k') | chrome/common/auto_start_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/nix/xdg_util.h" 5 #include "base/nix/xdg_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/environment.h" 9 #include "base/environment.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h" 12 #include "base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h"
13 13
14 namespace {
15
16 // The KDE session version environment variable used in KDE 4.
17 const char kKDE4SessionEnvVar[] = "KDE_SESSION_VERSION";
18
19 } // namespace
20
14 namespace base { 21 namespace base {
15 namespace nix { 22 namespace nix {
16 23
24 const char kDotConfigDir[] = ".config";
25 const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";
26
17 FilePath GetXDGDirectory(Environment* env, const char* env_name, 27 FilePath GetXDGDirectory(Environment* env, const char* env_name,
18 const char* fallback_dir) { 28 const char* fallback_dir) {
19 FilePath path; 29 FilePath path;
20 std::string env_value; 30 std::string env_value;
21 if (env->GetVar(env_name, &env_value) && !env_value.empty()) 31 if (env->GetVar(env_name, &env_value) && !env_value.empty())
22 path = FilePath(env_value); 32 path = FilePath(env_value);
23 else 33 else
24 path = file_util::GetHomeDir().Append(fallback_dir); 34 path = file_util::GetHomeDir().Append(fallback_dir);
25 return path.StripTrailingSeparators(); 35 return path.StripTrailingSeparators();
26 } 36 }
(...skipping 12 matching lines...) Expand all
39 49
40 DesktopEnvironment GetDesktopEnvironment(Environment* env) { 50 DesktopEnvironment GetDesktopEnvironment(Environment* env) {
41 std::string desktop_session; 51 std::string desktop_session;
42 if (env->GetVar("DESKTOP_SESSION", &desktop_session)) { 52 if (env->GetVar("DESKTOP_SESSION", &desktop_session)) {
43 if (desktop_session == "gnome") { 53 if (desktop_session == "gnome") {
44 return DESKTOP_ENVIRONMENT_GNOME; 54 return DESKTOP_ENVIRONMENT_GNOME;
45 } else if (desktop_session == "kde4") { 55 } else if (desktop_session == "kde4") {
46 return DESKTOP_ENVIRONMENT_KDE4; 56 return DESKTOP_ENVIRONMENT_KDE4;
47 } else if (desktop_session == "kde") { 57 } else if (desktop_session == "kde") {
48 // This may mean KDE4 on newer systems, so we have to check. 58 // This may mean KDE4 on newer systems, so we have to check.
49 if (env->HasVar("KDE_SESSION_VERSION")) 59 if (env->HasVar(kKDE4SessionEnvVar))
50 return DESKTOP_ENVIRONMENT_KDE4; 60 return DESKTOP_ENVIRONMENT_KDE4;
51 return DESKTOP_ENVIRONMENT_KDE3; 61 return DESKTOP_ENVIRONMENT_KDE3;
52 } else if (desktop_session.find("xfce") != std::string::npos || 62 } else if (desktop_session.find("xfce") != std::string::npos ||
53 desktop_session == "xubuntu") { 63 desktop_session == "xubuntu") {
54 return DESKTOP_ENVIRONMENT_XFCE; 64 return DESKTOP_ENVIRONMENT_XFCE;
55 } 65 }
56 } 66 }
57 67
58 // Fall back on some older environment variables. 68 // Fall back on some older environment variables.
59 // Useful particularly in the DESKTOP_SESSION=default case. 69 // Useful particularly in the DESKTOP_SESSION=default case.
60 if (env->HasVar("GNOME_DESKTOP_SESSION_ID")) { 70 if (env->HasVar("GNOME_DESKTOP_SESSION_ID")) {
61 return DESKTOP_ENVIRONMENT_GNOME; 71 return DESKTOP_ENVIRONMENT_GNOME;
62 } else if (env->HasVar("KDE_FULL_SESSION")) { 72 } else if (env->HasVar("KDE_FULL_SESSION")) {
63 if (env->HasVar("KDE_SESSION_VERSION")) 73 if (env->HasVar(kKDE4SessionEnvVar))
64 return DESKTOP_ENVIRONMENT_KDE4; 74 return DESKTOP_ENVIRONMENT_KDE4;
65 return DESKTOP_ENVIRONMENT_KDE3; 75 return DESKTOP_ENVIRONMENT_KDE3;
66 } 76 }
67 77
68 return DESKTOP_ENVIRONMENT_OTHER; 78 return DESKTOP_ENVIRONMENT_OTHER;
69 } 79 }
70 80
71 const char* GetDesktopEnvironmentName(DesktopEnvironment env) { 81 const char* GetDesktopEnvironmentName(DesktopEnvironment env) {
72 switch (env) { 82 switch (env) {
73 case DESKTOP_ENVIRONMENT_OTHER: 83 case DESKTOP_ENVIRONMENT_OTHER:
74 return NULL; 84 return NULL;
75 case DESKTOP_ENVIRONMENT_GNOME: 85 case DESKTOP_ENVIRONMENT_GNOME:
76 return "GNOME"; 86 return "GNOME";
77 case DESKTOP_ENVIRONMENT_KDE3: 87 case DESKTOP_ENVIRONMENT_KDE3:
78 return "KDE3"; 88 return "KDE3";
79 case DESKTOP_ENVIRONMENT_KDE4: 89 case DESKTOP_ENVIRONMENT_KDE4:
80 return "KDE4"; 90 return "KDE4";
81 case DESKTOP_ENVIRONMENT_XFCE: 91 case DESKTOP_ENVIRONMENT_XFCE:
82 return "XFCE"; 92 return "XFCE";
83 } 93 }
84 return NULL; 94 return NULL;
85 } 95 }
86 96
87 const char* GetDesktopEnvironmentName(Environment* env) { 97 const char* GetDesktopEnvironmentName(Environment* env) {
88 return GetDesktopEnvironmentName(GetDesktopEnvironment(env)); 98 return GetDesktopEnvironmentName(GetDesktopEnvironment(env));
89 } 99 }
90 100
91 } // namespace nix 101 } // namespace nix
92 } // namespace base 102 } // namespace base
OLDNEW
« no previous file with comments | « base/nix/xdg_util.h ('k') | chrome/common/auto_start_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698