ShareX/ShareX.UploadersLib/Forms/TwitterTweetForm.cs

181 lines
4.4 KiB
C#
Raw Normal View History

2013-11-03 23:53:49 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2024-01-03 12:57:14 +13:00
Copyright (c) 2007-2024 ShareX Team
2013-11-03 23:53:49 +13:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
2014-12-11 09:25:20 +13:00
using ShareX.HelpersLib;
using ShareX.UploadersLib.ImageUploaders;
2014-12-11 12:19:28 +13:00
using System;
using System.Windows.Forms;
2013-11-03 23:53:49 +13:00
2014-12-11 09:25:20 +13:00
namespace ShareX.UploadersLib
2013-11-03 23:53:49 +13:00
{
public partial class TwitterTweetForm : Form
2013-11-03 23:53:49 +13:00
{
public string Message
{
get
{
return txtTweet.Text;
}
set
2013-11-03 23:53:49 +13:00
{
txtTweet.Text = value;
}
}
2014-06-15 22:29:09 +12:00
private int length;
public int Length
{
get
{
return length;
}
set
{
length = value;
UpdateLength();
}
}
public bool IsValidMessage
{
get
{
return Message != null && (MediaMode || Message.Length > 0) && Message.Length <= Length;
}
}
private bool mediaMode;
public bool MediaMode
{
get
{
return mediaMode;
}
set
{
mediaMode = value;
if (mediaMode)
{
Length = Twitter.MessageMediaLimit;
}
else
{
Length = Twitter.MessageLimit;
}
2014-06-15 22:29:09 +12:00
}
}
public bool IsTweetSent { get; private set; }
2013-11-03 23:53:49 +13:00
public OAuthInfo AuthInfo { get; set; }
public TwitterTweetForm()
2013-11-03 23:53:49 +13:00
{
InitializeComponent();
2023-06-05 10:17:51 +12:00
ShareXResources.ApplyTheme(this, true);
MediaMode = false;
2013-11-03 23:53:49 +13:00
}
2016-04-07 04:02:48 +12:00
public TwitterTweetForm(OAuthInfo oauth) : this()
2013-11-03 23:53:49 +13:00
{
AuthInfo = oauth;
2013-11-03 23:53:49 +13:00
}
2016-04-07 04:02:48 +12:00
public TwitterTweetForm(OAuthInfo oauth, string message) : this(oauth)
2014-07-07 13:21:59 +12:00
{
Message = message;
}
2014-06-15 22:29:09 +12:00
private void UpdateLength()
2013-11-03 23:53:49 +13:00
{
2014-06-15 22:29:09 +12:00
lblTweetLength.Text = (Length - Message.Length).ToString();
btnOK.Enabled = IsValidMessage;
2013-11-03 23:53:49 +13:00
}
private void OK()
2013-11-03 23:53:49 +13:00
{
if (IsValidMessage)
2013-11-03 23:53:49 +13:00
{
SendTweet();
2023-06-05 10:17:51 +12:00
DialogResult = DialogResult.OK;
Close();
2013-11-03 23:53:49 +13:00
}
}
private void SendTweet()
2013-11-03 23:53:49 +13:00
{
if (AuthInfo != null)
2013-11-03 23:53:49 +13:00
{
Hide();
try
2013-11-03 23:53:49 +13:00
{
TwitterStatusResponse status = new Twitter(AuthInfo).TweetMessage(Message);
IsTweetSent = status != null;
2013-11-03 23:53:49 +13:00
}
catch (Exception ex)
2013-11-03 23:53:49 +13:00
{
DebugHelper.WriteException(ex);
2017-04-22 08:42:52 +12:00
ex.ShowError();
2013-11-03 23:53:49 +13:00
}
}
}
private void TwitterMsg_Shown(object sender, EventArgs e)
{
txtTweet.Select(txtTweet.TextLength, 0);
this.ForceActivate();
}
private void txtTweet_TextChanged(object sender, EventArgs e)
{
UpdateLength();
}
private void txtTweet_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == (Keys.Control | Keys.Enter))
{
OK();
}
}
private void btnOK_Click(object sender, EventArgs e)
{
OK();
}
private void btnCancel_Click(object sender, EventArgs e)
2013-11-03 23:53:49 +13:00
{
DialogResult = DialogResult.Cancel;
Close();
2013-11-03 23:53:49 +13:00
}
}
}