00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034
00035 #include "llpanelnetwork.h"
00036
00037
00038 #include "llerror.h"
00039 #include "llrect.h"
00040 #include "llstring.h"
00041
00042
00043 #include "llbutton.h"
00044 #include "lldirpicker.h"
00045 #include "llui.h"
00046 #include "lluictrlfactory.h"
00047 #include "llresmgr.h"
00048 #include "llsliderctrl.h"
00049 #include "llspinctrl.h"
00050 #include "llcheckboxctrl.h"
00051 #include "lltextbox.h"
00052 #include "llviewerregion.h"
00053 #include "llviewerthrottle.h"
00054 #include "llworld.h"
00055 #include "llviewercontrol.h"
00056 #include "llvieweruictrlfactory.h"
00057 #include "llviewerwindow.h"
00058
00059 LLPanelNetwork::LLPanelNetwork()
00060 {
00061 gUICtrlFactory->buildPanel(this, "panel_preferences_network.xml");
00062 }
00063
00064 BOOL LLPanelNetwork::postBuild()
00065 {
00066 LLString cache_location = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "");
00067 childSetText("cache_location", cache_location);
00068
00069 childSetAction("clear_cache", onClickClearCache, this);
00070 childSetAction("set_cache", onClickSetCache, this);
00071 childSetAction("reset_cache", onClickResetCache, this);
00072
00073 childSetEnabled("connection_port",
00074 gSavedSettings.getBOOL("ConnectionPortEnabled"));
00075 childSetCommitCallback("connection_port_enabled", onCommitPort, this);
00076
00077
00078 refresh();
00079
00080 return TRUE;
00081 }
00082
00083 LLPanelNetwork::~LLPanelNetwork()
00084 {
00085
00086 }
00087
00088
00089 void LLPanelNetwork::apply()
00090 {
00091 }
00092
00093 void LLPanelNetwork::refresh()
00094 {
00095 LLPanel::refresh();
00096
00097 mCacheSetting = gSavedSettings.getU32("CacheSize");
00098 mBandwidthBPS = gSavedSettings.getF32("ThrottleBandwidthKBPS")*1024;
00099 mConnectionPortEnabled = gSavedSettings.getBOOL("ConnectionPortEnabled");
00100 mConnectionPort = gSavedSettings.getU32("ConnectionPort");
00101 }
00102
00103 void LLPanelNetwork::cancel()
00104 {
00105 gSavedSettings.setU32("CacheSize", mCacheSetting);
00106 gSavedSettings.setF32("ThrottleBandwidthKBPS", mBandwidthBPS/1024);
00107 gSavedSettings.setBOOL("ConnectionPortEnabled", mConnectionPortEnabled);
00108 gSavedSettings.setU32("ConnectionPort", mConnectionPort);
00109 }
00110
00111
00112 void LLPanelNetwork::onClickClearCache(void*)
00113 {
00114
00115 gSavedSettings.setBOOL("PurgeCacheOnNextStartup", TRUE);
00116 gViewerWindow->alertXml("CacheWillClear");
00117 }
00118
00119
00120 void LLPanelNetwork::onClickSetCache(void* user_data)
00121 {
00122 LLPanelNetwork* self = (LLPanelNetwork*)user_data;
00123
00124 LLString cur_name(gSavedSettings.getString("CacheLocation"));
00125 LLString proposed_name(cur_name);
00126
00127 LLDirPicker& picker = LLDirPicker::instance();
00128 if (! picker.getDir(&proposed_name ) )
00129 {
00130 return;
00131 }
00132
00133 LLString dir_name = picker.getDirName();
00134 if (!dir_name.empty() && dir_name != cur_name)
00135 {
00136 self->childSetText("cache_location", dir_name);
00137 gViewerWindow->alertXml("CacheWillBeMoved");
00138 gSavedSettings.setString("NewCacheLocation", dir_name);
00139 }
00140 else
00141 {
00142 LLString cache_location = gDirUtilp->getCacheDir();
00143 self->childSetText("cache_location", cache_location);
00144 }
00145 }
00146
00147
00148 void LLPanelNetwork::onClickResetCache(void* user_data)
00149 {
00150 LLPanelNetwork* self = (LLPanelNetwork*)user_data;
00151 if (!gSavedSettings.getString("CacheLocation").empty())
00152 {
00153 gSavedSettings.setString("NewCacheLocation", "");
00154 gViewerWindow->alertXml("CacheWillBeMoved");
00155 }
00156 LLString cache_location = gDirUtilp->getCacheDir(true);
00157 self->childSetText("cache_location", cache_location);
00158 }
00159
00160
00161 void LLPanelNetwork::onCommitPort(LLUICtrl* ctrl, void* data)
00162 {
00163 LLPanelNetwork* self = (LLPanelNetwork*)data;
00164 LLCheckBoxCtrl* check = (LLCheckBoxCtrl*)ctrl;
00165
00166 if (!self || !check) return;
00167 self->childSetEnabled("connection_port", check->get());
00168 gViewerWindow->alertXml("ChangeConnectionPort");
00169 }