diff options
Diffstat (limited to 'linden/indra/newview/llurlhistory.cpp')
-rw-r--r-- | linden/indra/newview/llurlhistory.cpp | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/linden/indra/newview/llurlhistory.cpp b/linden/indra/newview/llurlhistory.cpp new file mode 100644 index 0000000..da69df6 --- /dev/null +++ b/linden/indra/newview/llurlhistory.cpp | |||
@@ -0,0 +1,137 @@ | |||
1 | /** | ||
2 | * @file llurlhistory.cpp | ||
3 | * @brief Manages a list of recent URLs | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2007-2008, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | * $/LicenseInfo$ | ||
30 | */ | ||
31 | |||
32 | #include "llviewerprecompiledheaders.h" | ||
33 | |||
34 | #include "llurlhistory.h" | ||
35 | |||
36 | #include "lldir.h" | ||
37 | #include "llsdserialize.h" | ||
38 | |||
39 | LLSD LLURLHistory::sHistorySD; | ||
40 | |||
41 | const int MAX_URL_COUNT = 10; | ||
42 | |||
43 | ///////////////////////////////////////////////////////////////////////////// | ||
44 | |||
45 | // static | ||
46 | bool LLURLHistory::loadFile(const LLString& filename) | ||
47 | { | ||
48 | LLSD data; | ||
49 | { | ||
50 | LLString temp_str = gDirUtilp->getLindenUserDir() + gDirUtilp->getDirDelimiter(); | ||
51 | |||
52 | llifstream file((temp_str + filename).c_str()); | ||
53 | |||
54 | if (file.is_open()) | ||
55 | { | ||
56 | llinfos << "Loading history.xml file at " << filename << llendl; | ||
57 | LLSDSerialize::fromXML(data, file); | ||
58 | } | ||
59 | |||
60 | if (data.isUndefined()) | ||
61 | { | ||
62 | llinfos << "file missing, ill-formed, " | ||
63 | "or simply undefined; not changing the" | ||
64 | " file" << llendl; | ||
65 | sHistorySD = LLSD(); | ||
66 | return false; | ||
67 | } | ||
68 | } | ||
69 | sHistorySD = data; | ||
70 | return true; | ||
71 | } | ||
72 | |||
73 | // static | ||
74 | bool LLURLHistory::saveFile(const LLString& filename) | ||
75 | { | ||
76 | LLString temp_str = gDirUtilp->getLindenUserDir() + gDirUtilp->getDirDelimiter(); | ||
77 | llofstream out((temp_str + filename).c_str()); | ||
78 | if (!out.good()) | ||
79 | { | ||
80 | llwarns << "Unable to open " << filename << " for output." << llendl; | ||
81 | return false; | ||
82 | } | ||
83 | |||
84 | LLSDSerialize::toXML(sHistorySD, out); | ||
85 | |||
86 | out.close(); | ||
87 | return true; | ||
88 | } | ||
89 | // static | ||
90 | // This function returns a portion of the history llsd that contains the collected | ||
91 | // url history | ||
92 | LLSD LLURLHistory::getURLHistory(const std::string& collection) | ||
93 | { | ||
94 | if(sHistorySD.has(collection)) | ||
95 | { | ||
96 | return sHistorySD[collection]; | ||
97 | } | ||
98 | return LLSD(); | ||
99 | } | ||
100 | |||
101 | // static | ||
102 | void LLURLHistory::addURL(const std::string& collection, const std::string& url) | ||
103 | { | ||
104 | if(! url.empty()) | ||
105 | { | ||
106 | sHistorySD[collection].insert(0, url); | ||
107 | LLURLHistory::limitSize(collection); | ||
108 | } | ||
109 | } | ||
110 | // static | ||
111 | void LLURLHistory::removeURL(const std::string& collection, const std::string& url) | ||
112 | { | ||
113 | LLSD::array_iterator iter = sHistorySD[collection].beginArray(); | ||
114 | LLSD::array_iterator end = sHistorySD[collection].endArray(); | ||
115 | for(int index = 0; index < sHistorySD[collection].size(); index++) | ||
116 | { | ||
117 | if(sHistorySD[collection].get(index).asString() == url) | ||
118 | { | ||
119 | sHistorySD[collection].erase(index); | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | |||
124 | // static | ||
125 | void LLURLHistory::clear(const std::string& collection) | ||
126 | { | ||
127 | sHistorySD[ collection ] = LLSD(); | ||
128 | } | ||
129 | |||
130 | void LLURLHistory::limitSize(const std::string& collection) | ||
131 | { | ||
132 | while(sHistorySD[collection].size() > MAX_URL_COUNT) | ||
133 | { | ||
134 | sHistorySD[collection].erase(MAX_URL_COUNT); | ||
135 | } | ||
136 | } | ||
137 | |||