aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lggdicdownload.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/lggdicdownload.cpp183
1 files changed, 183 insertions, 0 deletions
diff --git a/linden/indra/newview/lggdicdownload.cpp b/linden/indra/newview/lggdicdownload.cpp
new file mode 100644
index 0000000..7011312
--- /dev/null
+++ b/linden/indra/newview/lggdicdownload.cpp
@@ -0,0 +1,183 @@
1/* Copyright (c) 2009
2*
3* Greg Hendrickson (LordGregGreg Back). All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or
6* without modification, are permitted provided that the following
7* conditions are met:
8*
9* 1. Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* 2. Redistributions in binary form must reproduce the above
12* copyright notice, this list of conditions and the following
13* disclaimer in the documentation and/or other materials provided
14* with the distribution.
15* 3. Neither the name Modular Systems nor the names of its contributors
16* may be used to endorse or promote products derived from this
17* software without specific prior written permission.
18*
19* THIS SOFTWARE IS PROVIDED BY MODULAR SYSTEMS AND CONTRIBUTORS "AS IS"
20* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MODULAR SYSTEMS OR CONTRIBUTORS
23* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29* THE POSSIBILITY OF SUCH DAMAGE.
30*/
31
32#include "llviewerprecompiledheaders.h"
33
34#include "lggdicdownload.h"
35
36#include "llagentdata.h"
37#include "llcommandhandler.h"
38#include "llfloater.h"
39#include "lluictrlfactory.h"
40#include "llagent.h"
41#include "llpanel.h"
42#include "llbutton.h"
43#include "llcolorswatch.h"
44#include "llcombobox.h"
45#include "llview.h"
46#include "llprefsadvanced.h"
47#include "llhttpclient.h"
48#include "llbufferstream.h"
49
50class lggDicDownloadFloater;
51class EmeraldDicDownloader : public LLHTTPClient::Responder
52{
53public:
54 EmeraldDicDownloader(lggDicDownloadFloater * spanel,std::string sname);
55 ~EmeraldDicDownloader() { }
56 void completedRaw(
57 U32 status,
58 const std::string& reason,
59 const LLChannelDescriptors& channels,
60 const LLIOPipe::buffer_ptr_t& buffer);
61private:
62 lggDicDownloadFloater* panel;
63 std::string name;
64};
65
66
67class lggDicDownloadFloater : public LLFloater, public LLFloaterSingleton<lggDicDownloadFloater>
68{
69public:
70 lggDicDownloadFloater(const LLSD& seed);
71 virtual ~lggDicDownloadFloater();
72 BOOL postBuild(void);
73 void setData(std::vector<std::string> shortNames, std::vector<std::string> longNames, void * data);
74 static void onClickDownload(void* data);
75 std::vector<std::string> sNames;
76 std::vector<std::string> lNames;
77 LLPrefsAdvanced * empanel;
78};
79lggDicDownloadFloater::~lggDicDownloadFloater()
80{
81}
82lggDicDownloadFloater::lggDicDownloadFloater(const LLSD& seed)
83{
84 LLUICtrlFactory::getInstance()->buildFloater(this, "floater_dictionaries.xml");
85
86 if (getRect().mLeft == 0
87 && getRect().mBottom == 0)
88 {
89 center();
90 }
91
92}
93
94BOOL lggDicDownloadFloater::postBuild(void)
95{
96 childSetAction("Emerald_dic_download",onClickDownload,this);
97 return true;
98}
99void lggDicDownloadFloater::setData(std::vector<std::string> shortNames, std::vector<std::string> longNames, void * data)
100{
101 sNames=shortNames;
102 lNames=longNames;
103 empanel = (LLPrefsAdvanced*)data;
104
105 LLComboBox* comboBox = getChild<LLComboBox>("Emerald_combo_dics");
106 if(comboBox != NULL)
107 {
108 comboBox->removeall();
109 comboBox->add("");
110 for(int i = 0; i < (int)lNames.size(); i++)
111 {
112 comboBox->add(lNames[i]);
113 }
114 comboBox->setCurrentByIndex(0);
115 }
116}
117void lggDicDownloadFloater::onClickDownload(void* data)
118{
119 lggDicDownloadFloater* self = (lggDicDownloadFloater*)data;
120 if(self)
121 {
122 //std::string selection = self->childGetValue("Emerald_combo_dics").asString();
123 LLComboBox* comboBox = self->getChild<LLComboBox>("Emerald_combo_dics");
124 if(comboBox != NULL)
125 {
126 int index = comboBox->getCurrentIndex();
127 if(index!=0)
128 {
129 index--;
130 std::string newDict(self->sNames[index]);
131 LLHTTPClient::get("http://www.modularsystems.sl/app/dics/"+newDict+".aff", new EmeraldDicDownloader(self,newDict+".aff"));
132 LLHTTPClient::get("http://www.modularsystems.sl/app/dics/"+newDict+".dic", new EmeraldDicDownloader(NULL,newDict+".dic"));
133
134 LLButton* butt = self->getChild<LLButton>("Emerald_dic_download");
135 if(butt)
136 {
137 butt->setLabel(LLStringExplicit("Downloading... Please Wait"));
138 butt->setEnabled(FALSE);
139 }
140
141 }
142 }
143 }
144
145
146}
147
148void LggDicDownload::show(BOOL showin, std::vector<std::string> shortNames, std::vector<std::string> longNames, void * data)
149{
150 if(showin)
151 {
152 lggDicDownloadFloater* dic_floater = lggDicDownloadFloater::showInstance();
153 dic_floater->setData(shortNames,longNames,data);
154 }
155}
156EmeraldDicDownloader::EmeraldDicDownloader(lggDicDownloadFloater* spanel, std::string sname):
157panel(spanel),name(sname){}
158
159
160void EmeraldDicDownloader::completedRaw(U32 status, const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer)
161{
162 if(status < 200 || status >= 300)
163 {
164 return;
165 }
166 LLBufferStream istr(channels, buffer.get());
167 std::string dicpath(gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "dictionaries",
168 name.c_str()));
169
170
171 llofstream ostr(dicpath, std::ios::binary);
172
173 while(istr.good() && ostr.good())
174 ostr << istr.rdbuf();
175 ostr.close();
176 if(panel)
177 {
178 panel->empanel->refresh();
179 panel->close();
180 }
181
182
183}