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