Changeset 486
- Timestamp:
- Jan 29, 2010, 12:02:49 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/util/qdesktopservices_pm.cpp
r132 r486 50 50 #include <qcoreapplication.h> 51 51 52 53 52 54 #ifndef QT_NO_DESKTOPSERVICES 53 55 … … 59 61 return false; 60 62 61 // @todo implement 63 QString path = file.toLocalFile(); 64 if (path.isEmpty()) 65 return false; 66 67 path = QDir::toNativeSeparators(QDir::cleanPath(QDir::current() 68 .absoluteFilePath(path))); 69 70 HOBJECT hobj = WinQueryObject(QFile::encodeName(path)); 71 if (hobj != NULLHANDLE) 72 return WinOpenObject(hobj, 0 /* OPEN_DEFAULT */, FALSE); 73 62 74 return false; 63 75 } 64 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 65 94 static bool launchWebBrowser(const QUrl &url) 66 95 { 67 // @todo implement 96 if (!url.isValid()) 97 return false; 98 99 struct 100 { 101 const char *proto; 102 const char *exe; 103 const char *params; 104 const char *workDir; 105 } 106 Apps[] = { 107 { "mailto", "DefaultMailExe", "DefaultMailParameters", "DefaultMailWorkingDir" }, 108 { "news", "DefaultNewsExe", "DefaultNewsParameters", "DefaultNewsWorkingDir" }, 109 { "ftp", "DefaultFTPExe", "DefaultFTPParameters", "DefaultFTPWorkingDir" }, 110 { "irc", "DefaultIRCExe", "DefaultIRCParameters", "DefaultIRCWorkingDir" }, 111 // default: proto must be 0 and it must always come last 112 { 0, "DefaultBrowserExe", "DefaultParameters", "DefaultWorkingDir" }, 113 }; 114 115 for (size_t i = 0; i < sizeof(Apps)/sizeof(Apps[0]); ++i) { 116 if (!Apps[i].proto || url.scheme() == QLatin1String(Apps[i].proto)) { 117 QString exe = openUrlParam(Apps[i].exe); 118 if (!exe.isEmpty()) { 119 QString params = openUrlParam(Apps[i].params); 120 QString workDir = openUrlParam(Apps[i].workDir); 121 QStringList args; 122 args << params << url.toString(); 123 QProcess process; 124 return process.startDetached(exe, args, workDir); 125 } 126 } 127 } 128 68 129 return false; 69 130 } … … 71 132 QString QDesktopServices::storageLocation(StandardLocation type) 72 133 { 73 // @todo implement 74 return QString(); 134 if (type == QDesktopServices::HomeLocation) 135 return QDir::homePath(); 136 if (type == QDesktopServices::TempLocation) 137 return QDir::tempPath(); 138 139 // http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html 140 if (type == QDesktopServices::CacheLocation) { 141 QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME")); 142 if (xdgCacheHome.isEmpty()) 143 xdgCacheHome = QDir::homePath() + QLatin1String("/.cache"); 144 xdgCacheHome += QLatin1Char('/') + QCoreApplication::organizationName() 145 + QLatin1Char('/') + QCoreApplication::applicationName(); 146 return QDir::cleanPath(xdgCacheHome); 147 } 148 149 if (type == QDesktopServices::DataLocation) { 150 QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME")); 151 if (xdgDataHome.isEmpty()) 152 xdgDataHome = QDir::homePath() + QLatin1String("/.local/share"); 153 xdgDataHome += QLatin1String("/data/") 154 + QCoreApplication::organizationName() + QLatin1Char('/') 155 + QCoreApplication::applicationName(); 156 return QDir::cleanPath(xdgDataHome); 157 } 158 159 // http://www.freedesktop.org/wiki/Software/xdg-user-dirs 160 QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME")); 161 if (xdgConfigHome.isEmpty()) 162 xdgConfigHome = QDir::homePath() + QLatin1String("/.config"); 163 QFile file(xdgConfigHome + QLatin1String("/user-dirs.dirs")); 164 if (file.exists() && file.open(QIODevice::ReadOnly)) { 165 QHash<QString, QString> lines; 166 QTextStream stream(&file); 167 // Only look for lines like: XDG_DESKTOP_DIR="$HOME/Desktop" 168 QRegExp exp(QLatin1String("^XDG_(.*)_DIR=(.*)$")); 169 while (!stream.atEnd()) { 170 QString line = stream.readLine(); 171 if (exp.indexIn(line) != -1) { 172 QStringList lst = exp.capturedTexts(); 173 QString key = lst.at(1); 174 QString value = lst.at(2); 175 if (value.length() > 2 176 && value.startsWith(QLatin1String("\"")) 177 && value.endsWith(QLatin1String("\""))) 178 value = value.mid(1, value.length() - 2); 179 // Store the key and value: "DESKTOP", "$HOME/Desktop" 180 lines[key] = value; 181 } 182 } 183 184 QString key; 185 switch (type) { 186 case DesktopLocation: key = QLatin1String("DESKTOP"); break; 187 case DocumentsLocation: key = QLatin1String("DOCUMENTS"); break; 188 case PicturesLocation: key = QLatin1String("PICTURES"); break; 189 case MusicLocation: key = QLatin1String("MUSIC"); break; 190 case MoviesLocation: key = QLatin1String("VIDEOS"); break; 191 default: break; 192 } 193 if (!key.isEmpty() && lines.contains(key)) { 194 QString value = lines[key]; 195 // value can start with $HOME or %HOME% 196 if (value.startsWith(QLatin1String("$HOME"))) 197 value = QDir::homePath() + value.mid(5); 198 else if (value.startsWith(QLatin1String("%HOME%"))) 199 value = QDir::homePath() + value.mid(6); 200 return QDir::cleanPath(value); 201 } 202 } 203 204 QString path; 205 switch (type) { 206 case DesktopLocation: { 207 QByteArray buf(CCHMAXPATH, '\0'); 208 WinQueryActiveDesktopPathname(buf.data(), buf.size()); 209 buf.truncate(qstrlen(buf)); 210 if (!buf.isEmpty()) 211 path = QDir::cleanPath(QFile::decodeName(buf)); 212 else 213 path = QDir::rootPath() + QLatin1String("Desktop"); 214 break; 215 } 216 case DocumentsLocation: 217 path = QDir::homePath() + QLatin1String("/Documents"); 218 break; 219 case PicturesLocation: 220 path = QDir::homePath() + QLatin1String("/Pictures"); 221 break; 222 case MusicLocation: 223 path = QDir::homePath() + QLatin1String("/Music"); 224 break; 225 case MoviesLocation: 226 path = QDir::homePath() + QLatin1String("/Videos"); 227 break; 228 229 case ApplicationsLocation: 230 path = QDir::cleanPath(QFile::decodeName(qgetenv("PROGRAMS"))); 231 if (path.isEmpty()) 232 path = QDir::rootPath() + QLatin1String("PROGRAMS"); 233 break; 234 235 case FontsLocation: 236 path = QDir::cleanPath(QFile::decodeName(qgetenv("FONTS"))); 237 if (path.isEmpty()) 238 path = QDir::rootPath() + QLatin1String("PSFONTS"); 239 break; 240 241 default: 242 break; 243 } 244 245 return path; 75 246 } 76 247
Note:
See TracChangeset
for help on using the changeset viewer.