mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-24 01:00:27 +12:00
Code refactoring
This commit is contained in:
parent
3382c62c41
commit
7eb59947ec
|
@ -25,7 +25,6 @@
|
|||
|
||||
using ShareX.UploadersLib.Properties;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
@ -36,39 +35,9 @@ public partial class OAuthLoopbackControl : UserControl
|
|||
public event Action ConnectButtonClicked;
|
||||
public event Action DisconnectButtonClicked;
|
||||
|
||||
private bool connected;
|
||||
public bool Connected { get; private set; }
|
||||
|
||||
[DefaultValue(false)]
|
||||
public bool Connected
|
||||
{
|
||||
get
|
||||
{
|
||||
return connected;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (connected != value)
|
||||
{
|
||||
connected = value;
|
||||
UpdateStatus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private OAuthUserInfo userInfo;
|
||||
|
||||
public OAuthUserInfo UserInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return userInfo;
|
||||
}
|
||||
set
|
||||
{
|
||||
userInfo = value;
|
||||
UpdateStatus();
|
||||
}
|
||||
}
|
||||
public OAuthUserInfo UserInfo { get; private set; }
|
||||
|
||||
public OAuthLoopbackControl()
|
||||
{
|
||||
|
@ -91,6 +60,18 @@ private void btnConnect_Click(object sender, EventArgs e)
|
|||
}
|
||||
}
|
||||
|
||||
public void UpdateStatus(OAuth2Info oauth, OAuthUserInfo userInfo = null)
|
||||
{
|
||||
Connected = OAuth2Info.CheckOAuth(oauth);
|
||||
|
||||
if (Connected)
|
||||
{
|
||||
UserInfo = userInfo;
|
||||
}
|
||||
|
||||
UpdateStatus();
|
||||
}
|
||||
|
||||
private void UpdateStatus()
|
||||
{
|
||||
if (Connected)
|
||||
|
@ -109,6 +90,7 @@ private void UpdateStatus()
|
|||
}
|
||||
else
|
||||
{
|
||||
// TODO: Translate
|
||||
btnConnect.Text = "Connect...";
|
||||
lblStatusValue.Text = Resources.OAuthControl_Status_NotLoggedIn;
|
||||
lblStatusValue.ForeColor = Color.FromArgb(220, 0, 0);
|
||||
|
|
|
@ -1788,7 +1788,6 @@ private void InitializeComponent()
|
|||
//
|
||||
resources.ApplyResources(this.oauth2GoogleDrive, "oauth2GoogleDrive");
|
||||
this.oauth2GoogleDrive.Name = "oauth2GoogleDrive";
|
||||
this.oauth2GoogleDrive.UserInfo = null;
|
||||
this.oauth2GoogleDrive.ConnectButtonClicked += new System.Action(this.oauth2GoogleDrive_ConnectButtonClicked);
|
||||
this.oauth2GoogleDrive.DisconnectButtonClicked += new System.Action(this.oauth2GoogleDrive_DisconnectButtonClicked);
|
||||
//
|
||||
|
@ -3805,7 +3804,6 @@ private void InitializeComponent()
|
|||
//
|
||||
resources.ApplyResources(this.oauth2YouTube, "oauth2YouTube");
|
||||
this.oauth2YouTube.Name = "oauth2YouTube";
|
||||
this.oauth2YouTube.UserInfo = null;
|
||||
this.oauth2YouTube.ConnectButtonClicked += new System.Action(this.oauth2YouTube_ConnectButtonClicked);
|
||||
this.oauth2YouTube.DisconnectButtonClicked += new System.Action(this.oauth2YouTube_DisconnectButtonClicked);
|
||||
//
|
||||
|
@ -4766,7 +4764,6 @@ private void InitializeComponent()
|
|||
//
|
||||
resources.ApplyResources(this.oauth2GooglePhotos, "oauth2GooglePhotos");
|
||||
this.oauth2GooglePhotos.Name = "oauth2GooglePhotos";
|
||||
this.oauth2GooglePhotos.UserInfo = null;
|
||||
this.oauth2GooglePhotos.ConnectButtonClicked += new System.Action(this.oauth2GooglePhotos_ConnectButtonClicked);
|
||||
this.oauth2GooglePhotos.DisconnectButtonClicked += new System.Action(this.oauth2GooglePhotos_DisconnectButtonClicked);
|
||||
//
|
||||
|
@ -4947,7 +4944,6 @@ private void InitializeComponent()
|
|||
//
|
||||
resources.ApplyResources(this.oauth2GoogleCloudStorage, "oauth2GoogleCloudStorage");
|
||||
this.oauth2GoogleCloudStorage.Name = "oauth2GoogleCloudStorage";
|
||||
this.oauth2GoogleCloudStorage.UserInfo = null;
|
||||
this.oauth2GoogleCloudStorage.ConnectButtonClicked += new System.Action(this.oauth2GoogleCloudStorage_ConnectButtonClicked);
|
||||
this.oauth2GoogleCloudStorage.DisconnectButtonClicked += new System.Action(this.oauth2GoogleCloudStorage_DisconnectButtonClicked);
|
||||
//
|
||||
|
|
|
@ -226,12 +226,8 @@ private void LoadImageUploaderSettings()
|
|||
|
||||
#region Google Photos
|
||||
|
||||
if (OAuth2Info.CheckOAuth(Config.GooglePhotosOAuth2Info))
|
||||
{
|
||||
oauth2GooglePhotos.Connected = true;
|
||||
oauth2GooglePhotos.UserInfo = Config.GooglePhotosUserInfo;
|
||||
btnPicasaRefreshAlbumList.Enabled = true;
|
||||
}
|
||||
oauth2GooglePhotos.UpdateStatus(Config.GooglePhotosOAuth2Info, Config.GooglePhotosUserInfo);
|
||||
btnPicasaRefreshAlbumList.Enabled = oauth2GooglePhotos.Connected;
|
||||
|
||||
cbGooglePhotosIsPublic.Checked = Config.GooglePhotosIsPublic;
|
||||
txtPicasaAlbumID.Text = Config.GooglePhotosAlbumID;
|
||||
|
@ -386,12 +382,8 @@ private void LoadFileUploaderSettings()
|
|||
|
||||
#region Google Drive
|
||||
|
||||
if (OAuth2Info.CheckOAuth(Config.GoogleDriveOAuth2Info))
|
||||
{
|
||||
oauth2GoogleDrive.Connected = true;
|
||||
oauth2GoogleDrive.UserInfo = Config.GoogleDriveUserInfo;
|
||||
btnGoogleDriveRefreshFolders.Enabled = true;
|
||||
}
|
||||
oauth2GoogleDrive.UpdateStatus(Config.GoogleDriveOAuth2Info, Config.GoogleDriveUserInfo);
|
||||
btnGoogleDriveRefreshFolders.Enabled = oauth2GoogleDrive.Connected;
|
||||
|
||||
cbGoogleDriveIsPublic.Checked = Config.GoogleDriveIsPublic;
|
||||
cbGoogleDriveDirectLink.Checked = Config.GoogleDriveDirectLink;
|
||||
|
@ -734,11 +726,7 @@ private void LoadFileUploaderSettings()
|
|||
|
||||
#region YouTube
|
||||
|
||||
if (OAuth2Info.CheckOAuth(Config.YouTubeOAuth2Info))
|
||||
{
|
||||
oauth2YouTube.Connected = true;
|
||||
oauth2YouTube.UserInfo = Config.YouTubeUserInfo;
|
||||
}
|
||||
oauth2YouTube.UpdateStatus(Config.YouTubeOAuth2Info, Config.YouTubeUserInfo);
|
||||
|
||||
cbYouTubePrivacyType.Items.Clear();
|
||||
cbYouTubePrivacyType.Items.AddRange(Helpers.GetLocalizedEnumDescriptions<YouTubeVideoPrivacy>());
|
||||
|
@ -750,11 +738,7 @@ private void LoadFileUploaderSettings()
|
|||
|
||||
#region Google Cloud Storage
|
||||
|
||||
if (OAuth2Info.CheckOAuth(Config.GoogleCloudStorageOAuth2Info))
|
||||
{
|
||||
oauth2GoogleCloudStorage.Connected = true;
|
||||
oauth2GoogleCloudStorage.UserInfo = Config.GoogleCloudStorageUserInfo;
|
||||
}
|
||||
oauth2GoogleCloudStorage.UpdateStatus(Config.GoogleCloudStorageOAuth2Info, Config.GoogleCloudStorageUserInfo);
|
||||
|
||||
txtGoogleCloudStorageBucket.Text = Config.GoogleCloudStorageBucket;
|
||||
txtGoogleCloudStorageDomain.Text = Config.GoogleCloudStorageDomain;
|
||||
|
@ -1073,9 +1057,9 @@ private void oauth2GooglePhotos_ConnectButtonClicked()
|
|||
Config.GooglePhotosUserInfo = form.UserInfo;
|
||||
}
|
||||
|
||||
oauth2GooglePhotos.Connected = OAuth2Info.CheckOAuth(Config.GooglePhotosOAuth2Info);
|
||||
oauth2GooglePhotos.UserInfo = Config.GooglePhotosUserInfo;
|
||||
oauth2GooglePhotos.UpdateStatus(Config.GooglePhotosOAuth2Info, Config.GooglePhotosUserInfo);
|
||||
btnPicasaRefreshAlbumList.Enabled = oauth2GooglePhotos.Connected;
|
||||
|
||||
this.ForceActivate();
|
||||
}
|
||||
|
||||
|
@ -1722,9 +1706,9 @@ private void oauth2GoogleDrive_ConnectButtonClicked()
|
|||
Config.GoogleDriveUserInfo = form.UserInfo;
|
||||
}
|
||||
|
||||
oauth2GoogleDrive.Connected = OAuth2Info.CheckOAuth(Config.GoogleDriveOAuth2Info);
|
||||
oauth2GoogleDrive.UserInfo = Config.GoogleDriveUserInfo;
|
||||
oauth2GoogleDrive.UpdateStatus(Config.GoogleDriveOAuth2Info, Config.GoogleDriveUserInfo);
|
||||
btnGoogleDriveRefreshFolders.Enabled = oauth2GoogleDrive.Connected;
|
||||
|
||||
this.ForceActivate();
|
||||
}
|
||||
|
||||
|
@ -3047,8 +3031,8 @@ private void oauth2YouTube_ConnectButtonClicked()
|
|||
Config.YouTubeUserInfo = form.UserInfo;
|
||||
}
|
||||
|
||||
oauth2YouTube.Connected = OAuth2Info.CheckOAuth(Config.YouTubeOAuth2Info);
|
||||
oauth2YouTube.UserInfo = Config.YouTubeUserInfo;
|
||||
oauth2YouTube.UpdateStatus(Config.YouTubeOAuth2Info, Config.YouTubeUserInfo);
|
||||
|
||||
this.ForceActivate();
|
||||
}
|
||||
|
||||
|
@ -3094,8 +3078,8 @@ private void oauth2GoogleCloudStorage_ConnectButtonClicked()
|
|||
Config.GoogleCloudStorageUserInfo = form.UserInfo;
|
||||
}
|
||||
|
||||
oauth2GoogleCloudStorage.Connected = OAuth2Info.CheckOAuth(Config.GoogleCloudStorageOAuth2Info);
|
||||
oauth2GoogleCloudStorage.UserInfo = Config.GoogleCloudStorageUserInfo;
|
||||
oauth2GoogleCloudStorage.UpdateStatus(Config.GoogleCloudStorageOAuth2Info, Config.GoogleCloudStorageUserInfo);
|
||||
|
||||
this.ForceActivate();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue