You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MenuViewController.cs 24 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. using Shadowsocks.Controller;
  2. using Shadowsocks.Model;
  3. using Shadowsocks.Properties;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using ZXing;
  11. using ZXing.Common;
  12. using ZXing.QrCode;
  13. namespace Shadowsocks.View
  14. {
  15. public class MenuViewController
  16. {
  17. // yes this is just a menu view controller
  18. // when config form is closed, it moves away from RAM
  19. // and it should just do anything related to the config form
  20. private ShadowsocksController controller;
  21. private UpdateChecker updateChecker;
  22. private NotifyIcon _notifyIcon;
  23. private ContextMenu contextMenu1;
  24. private bool _isFirstRun;
  25. private MenuItem enableItem;
  26. private MenuItem modeItem;
  27. private MenuItem AutoStartupItem;
  28. private MenuItem ShareOverLANItem;
  29. private MenuItem SeperatorItem;
  30. private MenuItem ConfigItem;
  31. private MenuItem ServersItem;
  32. private MenuItem globalModeItem;
  33. private MenuItem PACModeItem;
  34. private MenuItem localPACItem;
  35. private MenuItem onlinePACItem;
  36. private MenuItem editLocalPACItem;
  37. private MenuItem updateFromGFWListItem;
  38. private MenuItem editGFWUserRuleItem;
  39. private MenuItem editOnlinePACItem;
  40. private ConfigForm configForm;
  41. private string _urlToOpen;
  42. public MenuViewController(ShadowsocksController controller)
  43. {
  44. this.controller = controller;
  45. LoadMenu();
  46. controller.EnableStatusChanged += controller_EnableStatusChanged;
  47. controller.ConfigChanged += controller_ConfigChanged;
  48. controller.PACFileReadyToOpen += controller_FileReadyToOpen;
  49. controller.UserRuleFileReadyToOpen += controller_FileReadyToOpen;
  50. controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged;
  51. controller.EnableGlobalChanged += controller_EnableGlobalChanged;
  52. controller.Errored += controller_Errored;
  53. controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted;
  54. controller.UpdatePACFromGFWListError += controller_UpdatePACFromGFWListError;
  55. _notifyIcon = new NotifyIcon();
  56. UpdateTrayIcon();
  57. _notifyIcon.Visible = true;
  58. _notifyIcon.ContextMenu = contextMenu1;
  59. _notifyIcon.MouseDoubleClick += notifyIcon1_DoubleClick;
  60. this.updateChecker = new UpdateChecker();
  61. updateChecker.NewVersionFound += updateChecker_NewVersionFound;
  62. LoadCurrentConfiguration();
  63. updateChecker.CheckUpdate(controller.GetConfigurationCopy());
  64. if (controller.GetConfigurationCopy().isDefault)
  65. {
  66. _isFirstRun = true;
  67. ShowConfigForm();
  68. }
  69. }
  70. void controller_Errored(object sender, System.IO.ErrorEventArgs e)
  71. {
  72. MessageBox.Show(e.GetException().ToString(), String.Format(I18N.GetString("Shadowsocks Error: {0}"), e.GetException().Message));
  73. }
  74. private void UpdateTrayIcon()
  75. {
  76. int dpi;
  77. Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
  78. dpi = (int)graphics.DpiX;
  79. graphics.Dispose();
  80. Bitmap icon = null;
  81. if (dpi < 97)
  82. {
  83. // dpi = 96;
  84. icon = Resources.ss16;
  85. }
  86. else if (dpi < 121)
  87. {
  88. // dpi = 120;
  89. icon = Resources.ss20;
  90. }
  91. else
  92. {
  93. icon = Resources.ss24;
  94. }
  95. Configuration config = controller.GetConfigurationCopy();
  96. bool enabled = config.enabled;
  97. bool global = config.global;
  98. if (!enabled)
  99. {
  100. Bitmap iconCopy = new Bitmap(icon);
  101. for (int x = 0; x < iconCopy.Width; x++)
  102. {
  103. for (int y = 0; y < iconCopy.Height; y++)
  104. {
  105. Color color = icon.GetPixel(x, y);
  106. iconCopy.SetPixel(x, y, Color.FromArgb((byte)(color.A / 1.25), color.R, color.G, color.B));
  107. }
  108. }
  109. icon = iconCopy;
  110. }
  111. _notifyIcon.Icon = Icon.FromHandle(icon.GetHicon());
  112. string serverInfo = null;
  113. if (config.strategy != null)
  114. {
  115. serverInfo = I18N.GetString(controller.GetCurrentStrategy().Name);
  116. }
  117. else
  118. {
  119. serverInfo = config.GetCurrentServer().FriendlyName();
  120. }
  121. // we want to show more details but notify icon title is limited to 63 characters
  122. string text = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version + "\n" +
  123. (enabled ?
  124. I18N.GetString("System Proxy On: ") + (global ? I18N.GetString("Global") : I18N.GetString("PAC")) :
  125. String.Format(I18N.GetString("Running: Port {0}"), config.localPort)) // this feedback is very important because they need to know Shadowsocks is running
  126. + "\n" + serverInfo;
  127. _notifyIcon.Text = text.Substring(0, Math.Min(63, text.Length));
  128. }
  129. private MenuItem CreateMenuItem(string text, EventHandler click)
  130. {
  131. return new MenuItem(I18N.GetString(text), click);
  132. }
  133. private MenuItem CreateMenuGroup(string text, MenuItem[] items)
  134. {
  135. return new MenuItem(I18N.GetString(text), items);
  136. }
  137. private void LoadMenu()
  138. {
  139. this.contextMenu1 = new ContextMenu(new MenuItem[] {
  140. this.enableItem = CreateMenuItem("Enable System Proxy", new EventHandler(this.EnableItem_Click)),
  141. this.modeItem = CreateMenuGroup("Mode", new MenuItem[] {
  142. this.PACModeItem = CreateMenuItem("PAC", new EventHandler(this.PACModeItem_Click)),
  143. this.globalModeItem = CreateMenuItem("Global", new EventHandler(this.GlobalModeItem_Click))
  144. }),
  145. this.ServersItem = CreateMenuGroup("Servers", new MenuItem[] {
  146. this.SeperatorItem = new MenuItem("-"),
  147. this.ConfigItem = CreateMenuItem("Edit Servers...", new EventHandler(this.Config_Click)),
  148. CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)),
  149. CreateMenuItem("Scan QRCode from Screen...", new EventHandler(this.ScanQRCodeItem_Click))
  150. }),
  151. CreateMenuGroup("PAC ", new MenuItem[] {
  152. this.localPACItem = CreateMenuItem("Local PAC", new EventHandler(this.LocalPACItem_Click)),
  153. this.onlinePACItem = CreateMenuItem("Online PAC", new EventHandler(this.OnlinePACItem_Click)),
  154. new MenuItem("-"),
  155. this.editLocalPACItem = CreateMenuItem("Edit Local PAC File...", new EventHandler(this.EditPACFileItem_Click)),
  156. this.updateFromGFWListItem = CreateMenuItem("Update Local PAC from GFWList", new EventHandler(this.UpdatePACFromGFWListItem_Click)),
  157. this.editGFWUserRuleItem = CreateMenuItem("Edit User Rule for GFWList...", new EventHandler(this.EditUserRuleFileForGFWListItem_Click)),
  158. this.editOnlinePACItem = CreateMenuItem("Edit Online PAC URL...", new EventHandler(this.UpdateOnlinePACURLItem_Click)),
  159. }),
  160. new MenuItem("-"),
  161. this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)),
  162. this.ShareOverLANItem = CreateMenuItem("Allow Clients from LAN", new EventHandler(this.ShareOverLANItem_Click)),
  163. new MenuItem("-"),
  164. CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)),
  165. CreateMenuItem("About...", new EventHandler(this.AboutItem_Click)),
  166. new MenuItem("-"),
  167. CreateMenuItem("Quit", new EventHandler(this.Quit_Click))
  168. });
  169. }
  170. private void controller_ConfigChanged(object sender, EventArgs e)
  171. {
  172. LoadCurrentConfiguration();
  173. UpdateTrayIcon();
  174. }
  175. private void controller_EnableStatusChanged(object sender, EventArgs e)
  176. {
  177. enableItem.Checked = controller.GetConfigurationCopy().enabled;
  178. modeItem.Enabled = enableItem.Checked;
  179. }
  180. void controller_ShareOverLANStatusChanged(object sender, EventArgs e)
  181. {
  182. ShareOverLANItem.Checked = controller.GetConfigurationCopy().shareOverLan;
  183. }
  184. void controller_EnableGlobalChanged(object sender, EventArgs e)
  185. {
  186. globalModeItem.Checked = controller.GetConfigurationCopy().global;
  187. PACModeItem.Checked = !globalModeItem.Checked;
  188. }
  189. void controller_FileReadyToOpen(object sender, ShadowsocksController.PathEventArgs e)
  190. {
  191. string argument = @"/select, " + e.Path;
  192. System.Diagnostics.Process.Start("explorer.exe", argument);
  193. }
  194. void ShowBalloonTip(string title, string content, ToolTipIcon icon, int timeout)
  195. {
  196. _notifyIcon.BalloonTipTitle = title;
  197. _notifyIcon.BalloonTipText = content;
  198. _notifyIcon.BalloonTipIcon = icon;
  199. _notifyIcon.ShowBalloonTip(timeout);
  200. }
  201. void controller_UpdatePACFromGFWListError(object sender, System.IO.ErrorEventArgs e)
  202. {
  203. ShowBalloonTip(I18N.GetString("Failed to update PAC file"), e.GetException().Message, ToolTipIcon.Error, 5000);
  204. Logging.LogUsefulException(e.GetException());
  205. }
  206. void controller_UpdatePACFromGFWListCompleted(object sender, GFWListUpdater.ResultEventArgs e)
  207. {
  208. string result = e.Success ? I18N.GetString("PAC updated") : I18N.GetString("No updates found. Please report to GFWList if you have problems with it.");
  209. ShowBalloonTip(I18N.GetString("Shadowsocks"), result, ToolTipIcon.Info, 1000);
  210. }
  211. void updateChecker_NewVersionFound(object sender, EventArgs e)
  212. {
  213. ShowBalloonTip(String.Format(I18N.GetString("Shadowsocks {0} Update Found"), updateChecker.LatestVersionNumber), I18N.GetString("Click here to download"), ToolTipIcon.Info, 5000);
  214. _notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked;
  215. _isFirstRun = false;
  216. }
  217. void notifyIcon1_BalloonTipClicked(object sender, EventArgs e)
  218. {
  219. System.Diagnostics.Process.Start(updateChecker.LatestVersionURL);
  220. _notifyIcon.BalloonTipClicked -= notifyIcon1_BalloonTipClicked;
  221. }
  222. private void LoadCurrentConfiguration()
  223. {
  224. Configuration config = controller.GetConfigurationCopy();
  225. UpdateServersMenu();
  226. enableItem.Checked = config.enabled;
  227. modeItem.Enabled = config.enabled;
  228. globalModeItem.Checked = config.global;
  229. PACModeItem.Checked = !config.global;
  230. ShareOverLANItem.Checked = config.shareOverLan;
  231. AutoStartupItem.Checked = AutoStartup.Check();
  232. onlinePACItem.Checked = onlinePACItem.Enabled && config.useOnlinePac;
  233. localPACItem.Checked = !onlinePACItem.Checked;
  234. UpdatePACItemsEnabledStatus();
  235. }
  236. private void UpdateServersMenu()
  237. {
  238. var items = ServersItem.MenuItems;
  239. while (items[0] != SeperatorItem)
  240. {
  241. items.RemoveAt(0);
  242. }
  243. int i = 0;
  244. foreach (var strategy in controller.GetStrategies())
  245. {
  246. MenuItem item = new MenuItem(I18N.GetString(strategy.Name));
  247. item.Tag = strategy.ID;
  248. item.Click += AStrategyItem_Click;
  249. items.Add(i, item);
  250. i++;
  251. }
  252. Configuration configuration = controller.GetConfigurationCopy();
  253. foreach (var server in configuration.configs)
  254. {
  255. MenuItem item = new MenuItem(server.FriendlyName());
  256. item.Tag = i;
  257. item.Click += AServerItem_Click;
  258. items.Add(i, item);
  259. i++;
  260. }
  261. foreach (MenuItem item in items)
  262. {
  263. if (item.Tag != null && (item.Tag.ToString() == configuration.index.ToString() || item.Tag.ToString() == configuration.strategy))
  264. {
  265. item.Checked = true;
  266. }
  267. }
  268. }
  269. private void ShowConfigForm()
  270. {
  271. if (configForm != null)
  272. {
  273. configForm.Activate();
  274. }
  275. else
  276. {
  277. configForm = new ConfigForm(controller);
  278. configForm.Show();
  279. configForm.FormClosed += configForm_FormClosed;
  280. }
  281. }
  282. void configForm_FormClosed(object sender, FormClosedEventArgs e)
  283. {
  284. configForm = null;
  285. Util.Utils.ReleaseMemory();
  286. ShowFirstTimeBalloon();
  287. }
  288. private void Config_Click(object sender, EventArgs e)
  289. {
  290. ShowConfigForm();
  291. }
  292. private void Quit_Click(object sender, EventArgs e)
  293. {
  294. controller.Stop();
  295. _notifyIcon.Visible = false;
  296. Application.Exit();
  297. }
  298. private void ShowFirstTimeBalloon()
  299. {
  300. if (_isFirstRun)
  301. {
  302. _notifyIcon.BalloonTipTitle = I18N.GetString("Shadowsocks is here");
  303. _notifyIcon.BalloonTipText = I18N.GetString("You can turn on/off Shadowsocks in the context menu");
  304. _notifyIcon.BalloonTipIcon = ToolTipIcon.Info;
  305. _notifyIcon.ShowBalloonTip(0);
  306. _isFirstRun = false;
  307. }
  308. }
  309. private void AboutItem_Click(object sender, EventArgs e)
  310. {
  311. Process.Start("https://github.com/shadowsocks/shadowsocks-csharp");
  312. }
  313. private void notifyIcon1_DoubleClick(object sender, MouseEventArgs e)
  314. {
  315. if (e.Button == MouseButtons.Left)
  316. {
  317. ShowConfigForm();
  318. }
  319. }
  320. private void EnableItem_Click(object sender, EventArgs e)
  321. {
  322. controller.ToggleEnable(!enableItem.Checked);
  323. }
  324. private void GlobalModeItem_Click(object sender, EventArgs e)
  325. {
  326. controller.ToggleGlobal(true);
  327. }
  328. private void PACModeItem_Click(object sender, EventArgs e)
  329. {
  330. controller.ToggleGlobal(false);
  331. }
  332. private void ShareOverLANItem_Click(object sender, EventArgs e)
  333. {
  334. ShareOverLANItem.Checked = !ShareOverLANItem.Checked;
  335. controller.ToggleShareOverLAN(ShareOverLANItem.Checked);
  336. }
  337. private void EditPACFileItem_Click(object sender, EventArgs e)
  338. {
  339. controller.TouchPACFile();
  340. }
  341. private void UpdatePACFromGFWListItem_Click(object sender, EventArgs e)
  342. {
  343. controller.UpdatePACFromGFWList();
  344. }
  345. private void EditUserRuleFileForGFWListItem_Click(object sender, EventArgs e)
  346. {
  347. controller.TouchUserRuleFile();
  348. }
  349. private void AServerItem_Click(object sender, EventArgs e)
  350. {
  351. MenuItem item = (MenuItem)sender;
  352. controller.SelectServerIndex((int)item.Tag);
  353. }
  354. private void AStrategyItem_Click(object sender, EventArgs e)
  355. {
  356. MenuItem item = (MenuItem)sender;
  357. controller.SelectStrategy((string)item.Tag);
  358. }
  359. private void ShowLogItem_Click(object sender, EventArgs e)
  360. {
  361. string argument = Logging.LogFile;
  362. System.Diagnostics.Process.Start("notepad.exe", argument);
  363. }
  364. private void QRCodeItem_Click(object sender, EventArgs e)
  365. {
  366. QRCodeForm qrCodeForm = new QRCodeForm(controller.GetQRCodeForCurrentServer());
  367. //qrCodeForm.Icon = this.Icon;
  368. // TODO
  369. qrCodeForm.Show();
  370. }
  371. private void ScanQRCodeItem_Click(object sender, EventArgs e)
  372. {
  373. foreach (Screen screen in Screen.AllScreens)
  374. {
  375. using (Bitmap fullImage = new Bitmap(screen.Bounds.Width,
  376. screen.Bounds.Height))
  377. {
  378. using (Graphics g = Graphics.FromImage(fullImage))
  379. {
  380. g.CopyFromScreen(screen.Bounds.X,
  381. screen.Bounds.Y,
  382. 0, 0,
  383. fullImage.Size,
  384. CopyPixelOperation.SourceCopy);
  385. }
  386. int maxTry = 10;
  387. for (int i = 0; i < maxTry; i++)
  388. {
  389. int marginLeft = (int)((double)fullImage.Width * i / 2.5 / maxTry);
  390. int marginTop = (int)((double)fullImage.Height * i / 2.5 / maxTry);
  391. Rectangle cropRect = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2);
  392. Bitmap target = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
  393. double imageScale = (double)screen.Bounds.Width / (double)cropRect.Width;
  394. using (Graphics g = Graphics.FromImage(target))
  395. {
  396. g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height),
  397. cropRect,
  398. GraphicsUnit.Pixel);
  399. }
  400. var source = new BitmapLuminanceSource(target);
  401. var bitmap = new BinaryBitmap(new HybridBinarizer(source));
  402. QRCodeReader reader = new QRCodeReader();
  403. var result = reader.decode(bitmap);
  404. if (result != null)
  405. {
  406. var success = controller.AddServerBySSURL(result.Text);
  407. QRCodeSplashForm splash = new QRCodeSplashForm();
  408. if (success)
  409. {
  410. splash.FormClosed += splash_FormClosed;
  411. }
  412. else if (result.Text.StartsWith("http://") || result.Text.StartsWith("https://"))
  413. {
  414. _urlToOpen = result.Text;
  415. splash.FormClosed += openURLFromQRCode;
  416. }
  417. else
  418. {
  419. MessageBox.Show(I18N.GetString("Failed to decode QRCode"));
  420. return;
  421. }
  422. double minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0;
  423. foreach (ResultPoint point in result.ResultPoints)
  424. {
  425. minX = Math.Min(minX, point.X);
  426. minY = Math.Min(minY, point.Y);
  427. maxX = Math.Max(maxX, point.X);
  428. maxY = Math.Max(maxY, point.Y);
  429. }
  430. minX /= imageScale;
  431. minY /= imageScale;
  432. maxX /= imageScale;
  433. maxY /= imageScale;
  434. // make it 20% larger
  435. double margin = (maxX - minX) * 0.20f;
  436. minX += -margin + marginLeft;
  437. maxX += margin + marginLeft;
  438. minY += -margin + marginTop;
  439. maxY += margin + marginTop;
  440. splash.Location = new Point(screen.Bounds.X, screen.Bounds.Y);
  441. // we need a panel because a window has a minimal size
  442. // TODO: test on high DPI
  443. splash.TargetRect = new Rectangle((int)minX + screen.Bounds.X, (int)minY + screen.Bounds.Y, (int)maxX - (int)minX, (int)maxY - (int)minY);
  444. splash.Size = new Size(fullImage.Width, fullImage.Height);
  445. splash.Show();
  446. return;
  447. }
  448. }
  449. }
  450. }
  451. MessageBox.Show(I18N.GetString("No QRCode found. Try to zoom in or move it to the center of the screen."));
  452. }
  453. void splash_FormClosed(object sender, FormClosedEventArgs e)
  454. {
  455. ShowConfigForm();
  456. }
  457. void openURLFromQRCode(object sender, FormClosedEventArgs e)
  458. {
  459. Process.Start(_urlToOpen);
  460. }
  461. private void AutoStartupItem_Click(object sender, EventArgs e) {
  462. AutoStartupItem.Checked = !AutoStartupItem.Checked;
  463. if (!AutoStartup.Set(AutoStartupItem.Checked)) {
  464. MessageBox.Show(I18N.GetString("Failed to update registry"));
  465. }
  466. }
  467. private void LocalPACItem_Click(object sender, EventArgs e)
  468. {
  469. if (!localPACItem.Checked)
  470. {
  471. localPACItem.Checked = true;
  472. onlinePACItem.Checked = false;
  473. controller.UseOnlinePAC(false);
  474. UpdatePACItemsEnabledStatus();
  475. }
  476. }
  477. private void OnlinePACItem_Click(object sender, EventArgs e)
  478. {
  479. if (!onlinePACItem.Checked)
  480. {
  481. if (String.IsNullOrEmpty(controller.GetConfigurationCopy().pacUrl))
  482. {
  483. UpdateOnlinePACURLItem_Click(sender, e);
  484. }
  485. if (!String.IsNullOrEmpty(controller.GetConfigurationCopy().pacUrl))
  486. {
  487. localPACItem.Checked = false;
  488. onlinePACItem.Checked = true;
  489. controller.UseOnlinePAC(true);
  490. }
  491. UpdatePACItemsEnabledStatus();
  492. }
  493. }
  494. private void UpdateOnlinePACURLItem_Click(object sender, EventArgs e)
  495. {
  496. string origPacUrl = controller.GetConfigurationCopy().pacUrl;
  497. string pacUrl = Microsoft.VisualBasic.Interaction.InputBox(
  498. I18N.GetString("Please input PAC Url"),
  499. I18N.GetString("Edit Online PAC URL"),
  500. origPacUrl, -1, -1);
  501. if (!string.IsNullOrEmpty(pacUrl) && pacUrl != origPacUrl)
  502. {
  503. controller.SavePACUrl(pacUrl);
  504. }
  505. }
  506. private void UpdatePACItemsEnabledStatus()
  507. {
  508. if (this.localPACItem.Checked)
  509. {
  510. this.editLocalPACItem.Enabled = true;
  511. this.updateFromGFWListItem.Enabled = true;
  512. this.editGFWUserRuleItem.Enabled = true;
  513. this.editOnlinePACItem.Enabled = false;
  514. }
  515. else
  516. {
  517. this.editLocalPACItem.Enabled = false;
  518. this.updateFromGFWListItem.Enabled = false;
  519. this.editGFWUserRuleItem.Enabled = false;
  520. this.editOnlinePACItem.Enabled = true;
  521. }
  522. }
  523. }
  524. }