From a58993748e03057c9f3a150a28e2b2da41746743 Mon Sep 17 00:00:00 2001 From: Qiu Yuzhou Date: Sat, 18 Mar 2017 17:56:12 +0800 Subject: [PATCH] Better QRCode window. --- ShadowsocksX-NG/AppDelegate.swift | 7 ++-- ShadowsocksX-NG/SWBQRCodeWindowController.h | 3 ++ ShadowsocksX-NG/SWBQRCodeWindowController.xib | 36 ++++++++++++++++--- ShadowsocksX-NG/ServerProfile.swift | 8 +++++ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/ShadowsocksX-NG/AppDelegate.swift b/ShadowsocksX-NG/AppDelegate.swift index 0a19220..4014ad5 100755 --- a/ShadowsocksX-NG/AppDelegate.swift +++ b/ShadowsocksX-NG/AppDelegate.swift @@ -261,6 +261,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele } qrcodeWinCtrl = SWBQRCodeWindowController(windowNibName: "SWBQRCodeWindowController") qrcodeWinCtrl.qrCode = profile.URL()!.absoluteString + qrcodeWinCtrl.title = profile.title() qrcodeWinCtrl.showWindow(self) NSApp.activate(ignoringOtherApps: true) qrcodeWinCtrl.window?.makeKeyAndOrderFront(nil) @@ -486,11 +487,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele for p in mgr.profiles { let item = NSMenuItem() item.tag = i + kProfileMenuItemIndexBase - if p.remark.isEmpty { - item.title = "\(p.serverHost):\(p.serverPort)" - } else { - item.title = "\(p.remark) (\(p.serverHost):\(p.serverPort))" - } + item.title = p.title() if mgr.activeProfileId == p.uuid { item.state = 1 } diff --git a/ShadowsocksX-NG/SWBQRCodeWindowController.h b/ShadowsocksX-NG/SWBQRCodeWindowController.h index 661cadc..85a3e9a 100644 --- a/ShadowsocksX-NG/SWBQRCodeWindowController.h +++ b/ShadowsocksX-NG/SWBQRCodeWindowController.h @@ -12,6 +12,9 @@ @interface SWBQRCodeWindowController : NSWindowController @property (nonatomic, copy) NSString *qrCode; +@property (nonatomic, copy) NSString *title; + +@property (nonatomic, weak) NSTextField *titleTextField; @property (nonatomic, weak) NSImageView *imageView; - (IBAction) copyQRCode: (id) sender; diff --git a/ShadowsocksX-NG/SWBQRCodeWindowController.xib b/ShadowsocksX-NG/SWBQRCodeWindowController.xib index 5133e88..ea35673 100644 --- a/ShadowsocksX-NG/SWBQRCodeWindowController.xib +++ b/ShadowsocksX-NG/SWBQRCodeWindowController.xib @@ -1,9 +1,10 @@ - + + @@ -16,22 +17,46 @@ - - + + - + - + + + + + + + + + + + + + + + @@ -43,5 +68,6 @@ + diff --git a/ShadowsocksX-NG/ServerProfile.swift b/ShadowsocksX-NG/ServerProfile.swift index cfc4be3..82b1916 100644 --- a/ShadowsocksX-NG/ServerProfile.swift +++ b/ShadowsocksX-NG/ServerProfile.swift @@ -252,4 +252,12 @@ class ServerProfile: NSObject, NSCopying { } return nil } + + func title() -> String { + if remark.isEmpty { + return "\(serverHost):\(serverPort)" + } else { + return "\(remark) (\(serverHost):\(serverPort))" + } + } }