{
public partial class TweenMain : OTBaseForm
{
- private readonly HttpClient http;
-
//各種設定
private Size _mySize; //画面サイズ
private Point _myLoc; //画面位置
private bool _DoFavRetweetFlags = false;
private bool osResumed = false;
- private Dictionary<string, IMultimediaShareService> pictureService;
//////////////////////////////////////////////////////////////////////////////////////////////////////////
private string _postBrowserStatusText = "";
public long? inReplyToId = null;
public string inReplyToName = null;
public string imageService = ""; //画像投稿サービス名
- public string imagePath = "";
+ public string[] imagePath = null;
public PostingStatus()
{
}
this.IconCache.Dispose();
}
- this.http.Dispose();
-
// 終了時にRemoveHandlerしておかないとメモリリークする
// http://msdn.microsoft.com/ja-jp/library/microsoft.win32.systemevents.powermodechanged.aspx
Microsoft.Win32.SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
////設定読み出し
LoadConfig();
- ThumbnailGenerator.InitializeGenerator(this.http);
+ ThumbnailGenerator.InitializeGenerator();
var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
imgazyobizinet.Enabled = this._cfgCommon.EnableImgAzyobuziNet;
_initial = true;
+ Networking.Initialize();
+
//アイコンリスト作成
- this.IconCache = new ImageCache(this.http);
+ this.IconCache = new ImageCache();
bool saveRequired = false;
bool firstRun = false;
}
//Twitter用通信クラス初期化
- HttpConnection.InitializeConnection(SettingDialog.DefaultTimeOut,
- SettingDialog.SelectedProxyType,
- SettingDialog.ProxyAddress,
- SettingDialog.ProxyPort,
- SettingDialog.ProxyUser,
- SettingDialog.ProxyPassword);
+ Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
+ Networking.SetWebProxy(this.SettingDialog.SelectedProxyType,
+ this.SettingDialog.ProxyAddress, this.SettingDialog.ProxyPort,
+ this.SettingDialog.ProxyUser, this.SettingDialog.ProxyPassword);
tw.RestrictFavCheck = SettingDialog.RestrictFavCheck;
tw.ReadOwnPost = SettingDialog.ReadOwnPost;
AllrepliesToolStripMenuItem.Checked = tw.AllAtReply;
//画像投稿サービス
- this.CreatePictureServices();
- SetImageServiceCombo();
- ImageSelectionPanel.Enabled = false;
-
- SelectImageServiceComboItem(_cfgCommon.UseImageServiceName, _cfgCommon.UseImageService);
+ ImageSelector.Initialize(tw, SettingDialog.TwitterConfiguration, _cfgCommon.UseImageServiceName, _cfgCommon.UseImageService);
//ウィンドウ設定
this.ClientSize = _cfgLocal.FormSize;
//アイコン描画不具合あり?
}
this.SelectListItem(lst,
- _statuses.IndexOf(tab.Text, selId[tab.Text]),
- _statuses.IndexOf(tab.Text, focusedId[tab.Text]));
+ tabInfo.IndexOf(selId[tab.Text]),
+ tabInfo.IndexOf(focusedId[tab.Text]));
}
}
if (tabInfo.UnreadCount > 0)
if (MyCommon._endingFlag) return;
foreach (TabPage tab in ListTab.TabPages)
{
- DetailsListView lst = (DetailsListView)tab.Tag;
+ var lst = (DetailsListView)tab.Tag;
+ var tabInfo = _statuses.Tabs[tab.Text];
if (lst.SelectedIndices.Count > 0 && lst.SelectedIndices.Count < 61)
{
- selId.Add(tab.Text, _statuses.GetId(tab.Text, lst.SelectedIndices));
+ selId.Add(tab.Text, tabInfo.GetId(lst.SelectedIndices));
}
else
{
var fIds = new long[2]; // 0 = focus, 1 = selection mark
var item = lst.FocusedItem;
- fIds[0] = (item != null) ? _statuses.GetId(tab.Text, item.Index) : -2;
+ fIds[0] = (item != null) ? tabInfo.GetId(item.Index) : -2;
var mIdx = lst.SelectionMark;
- fIds[1] = (mIdx > -1) ? _statuses.GetId(tab.Text, mIdx) : -2;
+ fIds[1] = (mIdx > -1) ? tabInfo.GetId(mIdx) : -2;
focusedId.Add(tab.Text, fIds);
}
!SettingDialog.LimitBalloon
)
) &&
- !Win32Api.IsScreenSaverRunning())
+ !NativeMethods.IsScreenSaverRunning())
{
return true;
}
//mentions新着時に画面ブリンク
if (!_initial && SettingDialog.BlinkNewMentions && newMentions && Form.ActiveForm == null)
{
- Win32Api.FlashMyWindow(this.Handle, Win32Api.FlashSpecification.FlashTray, 3);
+ NativeMethods.FlashMyWindow(this.Handle, NativeMethods.FlashSpecification.FlashTray, 3);
}
}
private void ChangeCacheStyleRead(bool Read, int Index)
{
+ var tabInfo = _statuses.Tabs[_curTab.Text];
//Read:true=既読 false=未読
//未読管理していなかったら既読として扱う
- if (!_statuses.Tabs[_curTab.Text].UnreadManage ||
+ if (!tabInfo.UnreadManage ||
!SettingDialog.UnreadManage) Read = true;
//対象の特定
if (itm == null || post == null)
{
itm = ((DetailsListView)_curTab.Tag).Items[Index];
- post = _statuses[_curTab.Text, Index];
+ post = tabInfo[Index];
}
ChangeItemStyleRead(Read, itm, post, ((DetailsListView)_curTab.Tag));
{
if (StatusText.Text.Trim().Length == 0)
{
- if (!ImageSelectionPanel.Enabled)
+ if (!ImageSelector.Enabled)
{
DoRefresh();
return;
args.status.inReplyToId = _reply_to_id;
args.status.inReplyToName = _reply_to_name;
- if (ImageSelectionPanel.Visible)
+ if (ImageSelector.Visible)
{
//画像投稿
- if (!TryGetSelectedMedia(out args.status.imageService, out args.status.imagePath))
+ if (!ImageSelector.TryGetSelectedMedia(out args.status.imageService, out args.status.imagePath))
return;
}
case MyCommon.WORKERTYPE.PostMessage:
bw.ReportProgress(200);
- if (string.IsNullOrEmpty(args.status.imagePath))
+ if (args.status.imagePath == null || args.status.imagePath.Length == 0 || string.IsNullOrEmpty(args.status.imagePath[0]))
{
ret = tw.PostStatus(args.status.status, args.status.inReplyToId);
}
else
{
- ret = this.pictureService[args.status.imageService].Upload(ref args.status.imagePath,
- ref args.status.status,
- args.status.inReplyToId);
+ var service = ImageSelector.GetService(args.status.imageService);
+ try
+ {
+ service.PostStatusAsync(args.status.status, args.status.inReplyToId, args.status.imagePath)
+ .Wait();
+ }
+ catch (AggregateException ex)
+ {
+ ret = ex.InnerException.Message;
+ }
}
bw.ReportProgress(300);
rslt.status = args.status;
//_waitFollower = false
if (SettingDialog.TwitterConfiguration.PhotoSizeLimit != 0)
{
- pictureService["Twitter"].Configuration("MaxUploadFilesize", SettingDialog.TwitterConfiguration.PhotoSizeLimit);
+ foreach (var service in this.ImageSelector.GetServices())
+ {
+ service.UpdateTwitterConfiguration(this.SettingDialog.TwitterConfiguration);
+ }
}
this.PurgeListViewItemCache();
if (_curList != null) _curList.Refresh();
ShortUrl.Instance.BitlyKey = SettingDialog.BitlyPwd;
HttpTwitter.TwitterUrl = _cfgCommon.TwitterUrl;
- HttpConnection.InitializeConnection(SettingDialog.DefaultTimeOut,
- SettingDialog.SelectedProxyType,
- SettingDialog.ProxyAddress,
- SettingDialog.ProxyPort,
- SettingDialog.ProxyUser,
- SettingDialog.ProxyPassword);
- this.CreatePictureServices();
+ Networking.DefaultTimeout = TimeSpan.FromSeconds(this.SettingDialog.DefaultTimeOut);
+ Networking.SetWebProxy(this.SettingDialog.SelectedProxyType,
+ this.SettingDialog.ProxyAddress, this.SettingDialog.ProxyPort,
+ this.SettingDialog.ProxyUser, this.SettingDialog.ProxyPassword);
+
+ ImageSelector.Reset(tw, SettingDialog.TwitterConfiguration);
try
{
if (uid != tw.Username) this.doGetFollowersMenu();
- SetImageServiceCombo();
if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
try
{
foreach (TabPage tab in ListTab.TabPages)
{
DetailsListView lst = (DetailsListView)tab.Tag;
+ TabClass tabInfo = _statuses.Tabs[tab.Text];
using (ControlTransaction.Update(lst))
{
this.SelectListItem(lst,
- _statuses.IndexOf(tab.Text, selId[tab.Text]),
- _statuses.IndexOf(tab.Text, focusedId[tab.Text]));
+ tabInfo.IndexOf(selId[tab.Text]),
+ tabInfo.IndexOf(focusedId[tab.Text]));
}
}
}
// pLen += m.Result("${url}").Length - SettingDialog.TwitterConfiguration.ShortUrlLength;
//}
}
- if (ImageSelectionPanel.Visible && ImageSelectedPicture.Tag != null && !string.IsNullOrEmpty(this.ImageService))
+ if (ImageSelector.Visible && !string.IsNullOrEmpty(ImageSelector.ServiceName))
{
pLen -= SettingDialog.TwitterConfiguration.CharactersReservedPerMedia;
}
this.itemCacheLock.EnterWriteLock();
try
{
+ var tabInfo = _statuses.Tabs[_curTab.Text];
+
//キャッシュ要求(要求範囲±30を作成)
StartIndex -= 30;
if (StartIndex < 0) StartIndex = 0;
EndIndex += 30;
- if (EndIndex >= _statuses.Tabs[_curTab.Text].AllCount) EndIndex = _statuses.Tabs[_curTab.Text].AllCount - 1;
- _postCache = _statuses[_curTab.Text, StartIndex, EndIndex]; //配列で取得
+ if (EndIndex >= tabInfo.AllCount) EndIndex = tabInfo.AllCount - 1;
+ _postCache = tabInfo[StartIndex, EndIndex]; //配列で取得
_itemCacheIndex = StartIndex;
_itemCache = new ListViewItem[0] {};
Post.Source};
itm = new ImageListViewItem(sitem, this.IconCache, Post.ImageUrl);
}
- itm.StateImageIndex = Post.StateIndex;
+ itm.StateIndex = Post.StateIndex;
bool read = Post.IsRead;
//未読管理していなかったら既読として扱う
//iconRect.Offset(0, Math.Max(0, (itemRect.Height - realIconSize.Height) / 2));
}
- if (item.StateImageIndex > -1)
+ if (item.StateIndex > -1)
{
Rectangle stateRect = Rectangle.Intersect(new Rectangle(new Point(iconRect.X + realIconSize.Width + 2, iconRect.Y), realStateSize), itemRect);
if (stateRect.Width > 0)
{
//e.Graphics.FillRectangle(Brushes.White, stateRect);
//e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.High;
- e.Graphics.DrawImage(this.PostStateImageList.Images[item.StateImageIndex], stateRect);
+ e.Graphics.DrawImage(this.PostStateImageList.Images[item.StateIndex], stateRect);
}
}
}
int idx = -1;
DetailsListView lst = null;
- if (ImageSelectionPanel.Enabled)
+ if (ImageSelector.Enabled)
return;
//現在タブから最終タブまで探索
var versionInfoUrl = new Uri(ApplicationSettings.VersionInfoUrl + "?" +
DateTime.Now.ToString("yyMMddHHmmss") + Environment.TickCount);
- var responseText = await this.http.GetStringAsync(versionInfoUrl)
+ var responseText = await Networking.Http.GetStringAsync(versionInfoUrl)
.ConfigureAwait(false);
// 改行2つで前後パートを分割(前半がバージョン番号など、後半が詳細テキスト)
DispSelectedPost(false);
}
- private static PostClass displaypost = new PostClass();
+ private PostClass displayPost = new PostClass();
/// <summary>
/// サムネイルの表示処理を表すタスク
if (_curList.SelectedIndices.Count == 0 || _curPost == null)
return;
- if (!forceupdate && _curPost.Equals(displaypost))
+ var oldDisplayPost = this.displayPost;
+ this.displayPost = this._curPost;
+
+ if (!forceupdate && this._curPost.Equals(oldDisplayPost))
return;
- displaypost = _curPost;
if (displayItem != null)
{
displayItem.ImageDownloaded -= this.DisplayItemImage_Downloaded;
displayItem = (ImageListViewItem)_curList.Items[_curList.SelectedIndices[0]];
displayItem.ImageDownloaded += this.DisplayItemImage_Downloaded;
- string dTxt = createDetailHtml(_curPost.IsDeleted ? "(DELETED)" : _curPost.Text);
- if (_curPost.IsDm)
+ using (ControlTransaction.Update(this.TableLayoutPanel1))
{
- SourceLinkLabel.Tag = null;
- SourceLinkLabel.Text = "";
- }
- else
- {
- Match mc = Regex.Match(_curPost.SourceHtml, "<a href=\"(?<sourceurl>.+?)\"");
- if (mc.Success)
+ var sourceText = "";
+ string sourceUrl = null;
+ if (!_curPost.IsDm)
{
- string src = mc.Groups["sourceurl"].Value;
- SourceLinkLabel.Tag = mc.Groups["sourceurl"].Value;
- mc = Regex.Match(src, "^https?://");
- if (!mc.Success)
+ var mc = Regex.Match(_curPost.SourceHtml, "<a href=\"(?<sourceurl>.+?)\"");
+ if (mc.Success)
{
- src = src.Insert(0, "https://twitter.com");
+ var src = mc.Groups["sourceurl"].Value;
+ if (Regex.IsMatch(src, "^https?://"))
+ sourceUrl = src;
+ else
+ sourceUrl = "https://twitter.com/" + src;
}
- SourceLinkLabel.Tag = src;
- }
- else
- {
- SourceLinkLabel.Tag = null;
+
+ if (_curPost.Source != null)
+ sourceText = _curPost.Source;
}
- if (string.IsNullOrEmpty(_curPost.Source))
+ SourceLinkLabel.Text = sourceText;
+ SourceLinkLabel.Tag = sourceUrl;
+ SourceLinkLabel.TabStop = false; // Text を更新すると勝手に true にされる
+
+ string nameText;
+ if (_curPost.IsDm)
{
- SourceLinkLabel.Text = "";
- //SourceLinkLabel.Visible = false;
+ if (_curPost.IsOwl)
+ nameText = "DM FROM <- ";
+ else
+ nameText = "DM TO -> ";
}
else
{
- SourceLinkLabel.Text = _curPost.Source;
- //SourceLinkLabel.Visible = true;
+ nameText = "";
}
- }
- SourceLinkLabel.TabStop = false;
+ nameText += _curPost.ScreenName + "/" + _curPost.Nickname;
+ if (_curPost.RetweetedId != null)
+ nameText += " (RT:" + _curPost.RetweetedBy + ")";
- if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage && !_curPost.IsOwl)
- {
- NameLabel.Text = "DM TO -> ";
- }
- else if (_statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage)
- {
- NameLabel.Text = "DM FROM <- ";
- }
- else
- {
- NameLabel.Text = "";
- }
- NameLabel.Text += _curPost.ScreenName + "/" + _curPost.Nickname;
- NameLabel.Tag = _curPost.ScreenName;
- if (!string.IsNullOrEmpty(_curPost.RetweetedBy))
- {
- NameLabel.Text += " (RT:" + _curPost.RetweetedBy + ")";
- }
+ NameLabel.Text = nameText;
+ NameLabel.Tag = _curPost.ScreenName;
- this.ClearUserPicture();
+ var nameForeColor = SystemColors.ControlText;
+ if (_curPost.IsOwl && (this.SettingDialog.OneWayLove || _curPost.IsDm))
+ nameForeColor = this._clOWL;
+ if (_curPost.RetweetedId != null)
+ nameForeColor = this._clRetweet;
+ if (_curPost.IsFav)
+ nameForeColor = this._clFav;
+ NameLabel.ForeColor = nameForeColor;
- if (!string.IsNullOrEmpty(_curPost.ImageUrl))
- {
- var image = IconCache.TryGetFromCache(_curPost.ImageUrl);
- try
+ this.ClearUserPicture();
+
+ if (!string.IsNullOrEmpty(_curPost.ImageUrl))
{
- UserPicture.Image = image != null ? image.Clone() : null;
+ var image = IconCache.TryGetFromCache(_curPost.ImageUrl);
+ try
+ {
+ UserPicture.Image = image != null ? image.Clone() : null;
+ }
+ catch (Exception)
+ {
+ UserPicture.ShowErrorImage();
+ }
}
- catch (Exception)
+
+ DateTimeLabel.Text = _curPost.CreatedAt.ToString();
+
+ if (DumpPostClassToolStripMenuItem.Checked)
{
- UserPicture.ShowErrorImage();
- }
- }
+ StringBuilder sb = new StringBuilder(512);
- NameLabel.ForeColor = System.Drawing.SystemColors.ControlText;
- DateTimeLabel.Text = _curPost.CreatedAt.ToString();
- if (_curPost.IsOwl && (SettingDialog.OneWayLove || _statuses.Tabs[_curTab.Text].TabType == MyCommon.TabUsageType.DirectMessage)) NameLabel.ForeColor = _clOWL;
- if (_curPost.RetweetedId != null) NameLabel.ForeColor = _clRetweet;
- if (_curPost.IsFav) NameLabel.ForeColor = _clFav;
-
- if (DumpPostClassToolStripMenuItem.Checked)
- {
- StringBuilder sb = new StringBuilder(512);
-
- sb.Append("-----Start PostClass Dump<br>");
- sb.AppendFormat("TextFromApi : {0}<br>", _curPost.TextFromApi);
- sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.TextFromApi);
- sb.AppendFormat("StatusId : {0}<br>", _curPost.StatusId.ToString());
- //sb.AppendFormat("ImageIndex : {0}<br>", _curPost.ImageIndex.ToString());
- sb.AppendFormat("ImageUrl : {0}<br>", _curPost.ImageUrl);
- sb.AppendFormat("InReplyToStatusId : {0}<br>", _curPost.InReplyToStatusId.ToString());
- sb.AppendFormat("InReplyToUser : {0}<br>", _curPost.InReplyToUser);
- sb.AppendFormat("IsDM : {0}<br>", _curPost.IsDm.ToString());
- sb.AppendFormat("IsFav : {0}<br>", _curPost.IsFav.ToString());
- sb.AppendFormat("IsMark : {0}<br>", _curPost.IsMark.ToString());
- sb.AppendFormat("IsMe : {0}<br>", _curPost.IsMe.ToString());
- sb.AppendFormat("IsOwl : {0}<br>", _curPost.IsOwl.ToString());
- sb.AppendFormat("IsProtect : {0}<br>", _curPost.IsProtect.ToString());
- sb.AppendFormat("IsRead : {0}<br>", _curPost.IsRead.ToString());
- sb.AppendFormat("IsReply : {0}<br>", _curPost.IsReply.ToString());
-
- foreach (string nm in _curPost.ReplyToList)
- {
- sb.AppendFormat("ReplyToList : {0}<br>", nm);
- }
-
- sb.AppendFormat("ScreenName : {0}<br>", _curPost.ScreenName);
- sb.AppendFormat("NickName : {0}<br>", _curPost.Nickname);
- sb.AppendFormat("Text : {0}<br>", _curPost.Text);
- sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.Text);
- sb.AppendFormat("CreatedAt : {0}<br>", _curPost.CreatedAt.ToString());
- sb.AppendFormat("Source : {0}<br>", _curPost.Source);
- sb.AppendFormat("UserId : {0}<br>", _curPost.UserId);
- sb.AppendFormat("FilterHit : {0}<br>", _curPost.FilterHit);
- sb.AppendFormat("RetweetedBy : {0}<br>", _curPost.RetweetedBy);
- sb.AppendFormat("RetweetedId : {0}<br>", _curPost.RetweetedId);
- sb.AppendFormat("SearchTabName : {0}<br>", _curPost.RelTabName);
- sb.Append("-----End PostClass Dump<br>");
-
- PostBrowser.Visible = false;
- PostBrowser.DocumentText = detailHtmlFormatHeader + sb.ToString() + detailHtmlFormatFooter;
- PostBrowser.Visible = true;
- }
- else
- {
- try
+ sb.Append("-----Start PostClass Dump<br>");
+ sb.AppendFormat("TextFromApi : {0}<br>", _curPost.TextFromApi);
+ sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.TextFromApi);
+ sb.AppendFormat("StatusId : {0}<br>", _curPost.StatusId.ToString());
+ //sb.AppendFormat("ImageIndex : {0}<br>", _curPost.ImageIndex.ToString());
+ sb.AppendFormat("ImageUrl : {0}<br>", _curPost.ImageUrl);
+ sb.AppendFormat("InReplyToStatusId : {0}<br>", _curPost.InReplyToStatusId.ToString());
+ sb.AppendFormat("InReplyToUser : {0}<br>", _curPost.InReplyToUser);
+ sb.AppendFormat("IsDM : {0}<br>", _curPost.IsDm.ToString());
+ sb.AppendFormat("IsFav : {0}<br>", _curPost.IsFav.ToString());
+ sb.AppendFormat("IsMark : {0}<br>", _curPost.IsMark.ToString());
+ sb.AppendFormat("IsMe : {0}<br>", _curPost.IsMe.ToString());
+ sb.AppendFormat("IsOwl : {0}<br>", _curPost.IsOwl.ToString());
+ sb.AppendFormat("IsProtect : {0}<br>", _curPost.IsProtect.ToString());
+ sb.AppendFormat("IsRead : {0}<br>", _curPost.IsRead.ToString());
+ sb.AppendFormat("IsReply : {0}<br>", _curPost.IsReply.ToString());
+
+ foreach (string nm in _curPost.ReplyToList)
+ {
+ sb.AppendFormat("ReplyToList : {0}<br>", nm);
+ }
+
+ sb.AppendFormat("ScreenName : {0}<br>", _curPost.ScreenName);
+ sb.AppendFormat("NickName : {0}<br>", _curPost.Nickname);
+ sb.AppendFormat("Text : {0}<br>", _curPost.Text);
+ sb.AppendFormat("(PlainText) : <xmp>{0}</xmp><br>", _curPost.Text);
+ sb.AppendFormat("CreatedAt : {0}<br>", _curPost.CreatedAt.ToString());
+ sb.AppendFormat("Source : {0}<br>", _curPost.Source);
+ sb.AppendFormat("UserId : {0}<br>", _curPost.UserId);
+ sb.AppendFormat("FilterHit : {0}<br>", _curPost.FilterHit);
+ sb.AppendFormat("RetweetedBy : {0}<br>", _curPost.RetweetedBy);
+ sb.AppendFormat("RetweetedId : {0}<br>", _curPost.RetweetedId);
+ sb.AppendFormat("SearchTabName : {0}<br>", _curPost.RelTabName);
+ sb.Append("-----End PostClass Dump<br>");
+
+ PostBrowser.DocumentText = detailHtmlFormatHeader + sb.ToString() + detailHtmlFormatFooter;
+ }
+ else
{
- if (PostBrowser.DocumentText != dTxt)
+ // 同じIDのツイートであれば WebBrowser とサムネイルの更新を行わない
+ // (同一ツイートの RT は文面が同じであるため同様に更新しない)
+ if (_curPost.StatusId != oldDisplayPost.StatusId)
{
- PostBrowser.Visible = false;
- PostBrowser.DocumentText = dTxt;
+ this.PostBrowser.DocumentText =
+ this.createDetailHtml(_curPost.IsDeleted ? "(DELETED)" : _curPost.Text);
+
+ this.PostBrowser.Document.Window.ScrollTo(0, 0);
this.SplitContainer3.Panel2Collapsed = true;
{
var oldTokenSource = this.thumbnailTokenSource;
- // TODO: キャンセルを行うとUIスレッドが阻害される問題を調査
- //oldTokenSource.Cancel();
+ var cancelTask = Task.Run(() => oldTokenSource.Cancel());
- this.thumbnailTask.ContinueWith(_ => oldTokenSource.Dispose());
+ Task.WhenAll(this.thumbnailTask, cancelTask)
+ .ContinueWith(_ => oldTokenSource.Dispose(), TaskScheduler.Default);
}
this.thumbnailTokenSource = new CancellationTokenSource();
}
}
}
- catch (System.Runtime.InteropServices.COMException)
- {
- //原因不明
- }
- catch (UriFormatException)
- {
- PostBrowser.DocumentText = dTxt;
- }
- finally
- {
- PostBrowser.Visible = true;
- }
}
}
_cfgCommon.AllAtReply = tw.AllAtReply;
_cfgCommon.OpenUserTimeline = SettingDialog.OpenUserTimeline;
_cfgCommon.ListCountApi = SettingDialog.ListCountApi;
- _cfgCommon.UseImageService = ImageServiceCombo.SelectedIndex;
- _cfgCommon.UseImageServiceName = this.ImageService;
+ _cfgCommon.UseImageService = ImageSelector.ServiceIndex;
+ _cfgCommon.UseImageServiceName = ImageSelector.ServiceName;
_cfgCommon.ListDoubleClickAction = SettingDialog.ListDoubleClickAction;
_cfgCommon.UserAppointUrl = SettingDialog.UserAppointUrl;
_cfgCommon.HideDuplicatedRetweets = SettingDialog.HideDuplicatedRetweets;
var resultUri = await ShortUrl.Instance.ShortenUrlAsync(Converter_Type, srcUri);
result = resultUri.ToString();
}
+ catch (HttpRequestException e)
+ {
+ // 例外のメッセージが「Response status code does not indicate success: 500 (Internal Server Error).」
+ // のように長いので「:」が含まれていればそれ以降のみを抽出する
+ var message = e.Message.Split(new[] { ':' }, count: 2).Last();
+
+ this.StatusLabel.Text = Converter_Type + ":" + message;
+ continue;
+ }
catch (WebApiException e)
{
this.StatusLabel.Text = Converter_Type + ":" + e.Message;
private HookGlobalHotkey _hookGlobalHotkey;
public TweenMain()
{
- this.http = MyCommon.CreateHttpClient();
_hookGlobalHotkey = new HookGlobalHotkey(this);
// この呼び出しは、Windows フォーム デザイナで必要です。
this.gh.NotifyClicked += GrowlHelper_Callback;
// メイリオフォント指定時にタブの最小幅が広くなる問題の対策
- this.ListTab.HandleCreated += (s, e) => Win32Api.SetMinTabWidth((TabControl)s, 40);
+ this.ListTab.HandleCreated += (s, e) => NativeMethods.SetMinTabWidth((TabControl)s, 40);
this._apiGauge = new ToolStripAPIGauge();
this._apiGauge.BorderSides = ToolStripStatusLabelBorderSides.Right;
this.StatusStrip1.Items.Insert(2, this._apiGauge);
- this.ImageSelectedPicture.InitialImage = Properties.Resources.InitialImage;
+ this.ImageSelector.Visible = false;
+ this.ImageSelector.Enabled = false;
+ this.ImageSelector.FilePickDialog = OpenFileDialog1;
this.ReplaceAppName();
}
}
#region "画像投稿"
- private void CreatePictureServices()
- {
- if (this.pictureService != null) this.pictureService.Clear();
- this.pictureService = null;
- this.pictureService = new Dictionary<string, IMultimediaShareService> {
- {"TwitPic", new TwitPic(tw)},
- {"img.ly", new imgly(tw)},
- {"yfrog", new yfrog(tw)},
- {"Twitter", new TwitterPhoto(tw)},
- {"ついっぷるフォト", new TwipplePhoto(tw)},
- {"Imgur", new Imgur(tw)},
- };
- }
-
private void ImageSelectMenuItem_Click(object sender, EventArgs e)
{
- if (ImageSelectionPanel.Visible)
- {
- CloseImageSelectionPanel();
- }
+ if (ImageSelector.Visible)
+ ImageSelector.EndSelection();
else
- {
- OpenImageSelectionPanel();
- ImageFromSelectedFile(true);
- ImagefilePathText.Focus();
- }
- }
-
- private void OpenImageSelectionPanel()
- {
- ImageSelectionPanel.Visible = true;
- ImageSelectionPanel.Enabled = true;
- TimelinePanel.Visible = false;
- TimelinePanel.Enabled = false;
- }
-
- private void CloseImageSelectionPanel()
- {
- ImagefilePathText.CausesValidation = false;
- TimelinePanel.Visible = true;
- TimelinePanel.Enabled = true;
- ImageSelectionPanel.Visible = false;
- ImageSelectionPanel.Enabled = false;
- ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
- ClearImageSelectedPicture();
- ImagefilePathText.CausesValidation = true;
+ ImageSelector.BeginSelection();
}
private void SelectMedia_DragEnter(DragEventArgs e)
{
- string filename = ((string[])e.Data.GetData(DataFormats.FileDrop, false))[0];
- FileInfo fl = new FileInfo(filename);
- string ext = fl.Extension;
-
- if (!string.IsNullOrEmpty(this.ImageService) &&
- this.pictureService[this.ImageService].CheckValidFilesize(ext, fl.Length))
+ if (ImageSelector.HasUploadableService(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0]))
{
e.Effect = DragDropEffects.Copy;
return;
}
- foreach (string svc in ImageServiceCombo.Items)
- {
- if (!string.IsNullOrEmpty(svc) &&
- this.pictureService[svc].CheckValidFilesize(ext, fl.Length))
- {
- //ImageServiceCombo.SelectedItem = svc;
- e.Effect = DragDropEffects.Copy;
- return;
- }
- }
e.Effect = DragDropEffects.None;
}
{
this.Activate();
this.BringToFront();
- OpenImageSelectionPanel();
- ImagefilePathText.Text = ((string[])e.Data.GetData(DataFormats.FileDrop, false))[0];
- ImageFromSelectedFile(false);
+ ImageSelector.BeginSelection(((string[])e.Data.GetData(DataFormats.FileDrop, false))[0]);
StatusText.Focus();
}
- private void FilePickButton_Click(object sender, EventArgs e)
+ private void ImageSelector_BeginSelecting(object sender, EventArgs e)
{
- if (string.IsNullOrEmpty(this.ImageService)) return;
- OpenFileDialog1.Filter = this.pictureService[this.ImageService].GetFileOpenDialogFilter();
- OpenFileDialog1.Title = Properties.Resources.PickPictureDialog1;
- OpenFileDialog1.FileName = "";
-
- try
- {
- this.AllowDrop = false;
- if (OpenFileDialog1.ShowDialog() == DialogResult.Cancel) return;
- }
- finally
- {
- this.AllowDrop = true;
- }
-
- ImagefilePathText.Text = OpenFileDialog1.FileName;
- ImageFromSelectedFile(false);
- }
-
- private void ImagefilePathText_Validating(object sender, CancelEventArgs e)
- {
- if (ImageCancelButton.Focused)
- {
- ImagefilePathText.CausesValidation = false;
- return;
- }
-
- ImageFromSelectedFile(false);
- }
-
- private void ImageFromSelectedFile(bool suppressMsgBox)
- {
- this.ClearImageSelectedPicture();
-
- try
- {
- ImagefilePathText.Text = ImagefilePathText.Text.Trim();
- if (string.IsNullOrEmpty(ImagefilePathText.Text) || string.IsNullOrEmpty(this.ImageService))
- {
- ImagefilePathText.Text = "";
- return;
- }
-
- FileInfo fl = new FileInfo(ImagefilePathText.Text);
- string ext = fl.Extension;
- var imageService = this.pictureService[this.ImageService];
-
- if (!imageService.CheckValidExtension(ext))
- {
- //画像以外の形式
- ImagefilePathText.Text = "";
- if (!suppressMsgBox)
- {
- MessageBox.Show(
- string.Format(Properties.Resources.PostPictureWarn3, this.ImageService, MakeAvailableServiceText(ext, fl.Length), ext),
- Properties.Resources.PostPictureWarn4,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- }
- return;
- }
-
- if (!imageService.CheckValidFilesize(ext, fl.Length))
- {
- // ファイルサイズが大きすぎる
- ImagefilePathText.Text = "";
- if (!suppressMsgBox)
- {
- MessageBox.Show(
- string.Format(Properties.Resources.PostPictureWarn5, this.ImageService, MakeAvailableServiceText(ext, fl.Length)),
- Properties.Resources.PostPictureWarn4,
- MessageBoxButtons.OK,
- MessageBoxIcon.Warning);
- }
- return;
- }
-
- switch (imageService.GetFileType(ext))
- {
- case MyCommon.UploadFileType.Picture:
- using (var fs = File.OpenRead(ImagefilePathText.Text))
- {
- ImageSelectedPicture.Image = MemoryImage.CopyFromStream(fs);
- }
- ImageSelectedPicture.Tag = MyCommon.UploadFileType.Picture;
- break;
- case MyCommon.UploadFileType.MultiMedia:
- ImageSelectedPicture.Tag = MyCommon.UploadFileType.MultiMedia;
- break;
- default:
- ImagefilePathText.Text = "";
- break;
- }
- }
- catch (FileNotFoundException)
- {
- ImagefilePathText.Text = "";
- if (!suppressMsgBox) MessageBox.Show("File not found.");
- }
- catch (Exception)
- {
- ImagefilePathText.Text = "";
- if (!suppressMsgBox) MessageBox.Show("The type of this file is not image.");
- }
- }
-
- private string MakeAvailableServiceText(string ext, long fileSize)
- {
- StringBuilder sb = new StringBuilder();
-
- foreach (string svc in ImageServiceCombo.Items)
- {
- if (!string.IsNullOrEmpty(svc) &&
- this.pictureService[svc].CheckValidFilesize(ext, fileSize))
- {
- if (sb.Length > 0) sb.Append(", ");
- sb.Append(svc);
- }
- }
- if (sb.Length == 0)
- return Properties.Resources.PostPictureWarn6;
-
- return sb.ToString();
- }
-
- private void ClearImageSelectedPicture()
- {
- var oldImage = this.ImageSelectedPicture.Image;
- if (oldImage != null)
- {
- this.ImageSelectedPicture.Image = null;
- oldImage.Dispose();
- }
-
- this.ImageSelectedPicture.Tag = null;
- this.ImageSelectedPicture.ShowInitialImage();
- }
-
- private void ImageCancelButton_Click(object sender, EventArgs e)
- {
- CloseImageSelectionPanel();
- }
-
- private void ImageSelection_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Escape)
- {
- CloseImageSelectionPanel();
- }
- }
-
- private void ImageSelection_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (Convert.ToInt32(e.KeyChar) == 0x1B)
- {
- ImagefilePathText.CausesValidation = false;
- e.Handled = true;
- }
- }
-
- private void ImageSelection_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
- {
- if (e.KeyCode == Keys.Escape)
- {
- ImagefilePathText.CausesValidation = false;
- }
- }
-
- private bool TryGetSelectedMedia(out string imageService, out string imagePath)
- {
- if (ImageSelectedPicture.Tag != null &&
- ImageServiceCombo.SelectedIndex > -1 &&
- !string.IsNullOrEmpty(ImagefilePathText.Text))
- {
- if (MessageBox.Show(string.Format(Properties.Resources.PostPictureConfirm1, this.ImageService),
- Properties.Resources.PostPictureConfirm2,
- MessageBoxButtons.OKCancel,
- MessageBoxIcon.Question,
- MessageBoxDefaultButton.Button1)
- == DialogResult.OK)
- {
- imageService = ImageServiceCombo.Text;
- imagePath = ImagefilePathText.Text;
- CloseImageSelectionPanel();
- ImagefilePathText.Text = "";
- return true;
- }
- }
- else
- {
- MessageBox.Show(Properties.Resources.PostPictureWarn1, Properties.Resources.PostPictureWarn2);
- }
-
- CloseImageSelectionPanel();
- imageService = null;
- imagePath = null;
- return false;
+ TimelinePanel.Visible = false;
+ TimelinePanel.Enabled = false;
}
- private void SetImageServiceCombo()
+ private void ImageSelector_EndSelecting(object sender, EventArgs e)
{
- string svc = "";
- if (ImageServiceCombo.SelectedIndex > -1) svc = ImageServiceCombo.SelectedItem.ToString();
- ImageServiceCombo.Items.Clear();
-
- // Add service names to combobox
- foreach (var key in pictureService.Keys)
- {
- ImageServiceCombo.Items.Add(key);
- }
-
- SelectImageServiceComboItem(svc);
+ TimelinePanel.Visible = true;
+ TimelinePanel.Enabled = true;
+ ((DetailsListView)ListTab.SelectedTab.Tag).Focus();
}
- private void SelectImageServiceComboItem(string svc, int? index = null)
+ private void ImageSelector_FilePickDialogOpening(object sender, EventArgs e)
{
- int idx;
- if (string.IsNullOrEmpty(svc))
- {
- idx = index ?? 0;
- }
- else
- {
- idx = ImageServiceCombo.Items.IndexOf(svc);
- if (idx == -1) idx = index ?? 0;
- }
-
- try
- {
- ImageServiceCombo.SelectedIndex = idx;
- }
- catch (ArgumentOutOfRangeException)
- {
- ImageServiceCombo.SelectedIndex = 0;
- }
+ this.AllowDrop = false;
}
- private string ImageService
+ private void ImageSelector_FilePickDialogClosed(object sender, EventArgs e)
{
- get { return ImageServiceCombo.SelectedItem.ToString(); }
+ this.AllowDrop = true;
}
- private void ImageServiceCombo_SelectedIndexChanged(object sender, EventArgs e)
+ private void ImageSelector_SelectedServiceChanged(object sender, EventArgs e)
{
- if (ImageSelectedPicture.Tag != null && !string.IsNullOrEmpty(this.ImageService))
+ if (ImageSelector.Visible)
{
- try
- {
- FileInfo fi = new FileInfo(ImagefilePathText.Text.Trim());
- string ext = fi.Extension;
- var imageService = this.pictureService[this.ImageService];
- if (!imageService.CheckValidFilesize(ext, fi.Length))
- {
- ClearImageSelectedPicture();
- ImagefilePathText.Text = "";
- }
- }
- catch (Exception)
- {
- ClearImageSelectedPicture();
- ImagefilePathText.Text = "";
- }
_modifySettingCommon = true;
SaveConfigsAll(true);
- if (this.ImageService == "Twitter")
- {
+
+ if (ImageSelector.ServiceName.Equals("Twitter"))
this.StatusText_TextChanged(null, null);
- }
}
}
- private void ImageSelectionPanel_VisibleChanged(object sender, EventArgs e)
+ private void ImageSelector_VisibleChanged(object sender, EventArgs e)
{
this.StatusText_TextChanged(null, null);
}
#region "Userstream"
private bool _isActiveUserstream = false;
- private void tw_PostDeleted(long id)
+ private void tw_PostDeleted(object sender, PostDeletedEventArgs e)
{
try
{
{
Invoke((Action) (() =>
{
- _statuses.RemovePostReserve(id);
- if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(id))
+ _statuses.RemovePostReserve(e.StatusId);
+ if (_curTab != null && _statuses.Tabs[_curTab.Text].Contains(e.StatusId))
{
this.PurgeListViewItemCache();
((DetailsListView)_curTab.Tag).Update();
- if (_curPost != null && _curPost.StatusId == id) DispSelectedPost(true);
+ if (_curPost != null && _curPost.StatusId == e.StatusId) DispSelectedPost(true);
}
}));
return;
}
}
- private void tw_NewPostFromStream()
+ private void tw_NewPostFromStream(object sender, EventArgs e)
{
if (SettingDialog.ReadOldPosts)
{
}
}
- private void tw_UserStreamStarted()
+ private void tw_UserStreamStarted(object sender, EventArgs e)
{
this._isActiveUserstream = true;
try
{
if (InvokeRequired && !IsDisposed)
{
- Invoke(new MethodInvoker(tw_UserStreamStarted));
+ Invoke((Action)(() => this.tw_UserStreamStarted(sender, e)));
return;
}
}
StatusLabel.Text = "UserStream Started.";
}
- private void tw_UserStreamStopped()
+ private void tw_UserStreamStopped(object sender, EventArgs e)
{
this._isActiveUserstream = false;
try
{
if (InvokeRequired && !IsDisposed)
{
- Invoke(new MethodInvoker(tw_UserStreamStopped));
+ Invoke((Action)(() => this.tw_UserStreamStopped(sender, e)));
return;
}
}
StatusLabel.Text = "UserStream Stopped.";
}
- private void tw_UserStreamEventArrived(Twitter.FormattedEvent ev)
+ private void tw_UserStreamEventArrived(object sender, UserStreamEventReceivedEventArgs e)
{
try
{
if (InvokeRequired && !IsDisposed)
{
- Invoke(new Action<Twitter.FormattedEvent>(tw_UserStreamEventArrived), ev);
+ Invoke((Action)(() => this.tw_UserStreamEventArrived(sender, e)));
return;
}
}
{
return;
}
+ var ev = e.EventData;
StatusLabel.Text = "Event: " + ev.Event;
//if (ev.Event == "favorite")
//{
if (string.IsNullOrEmpty(str))
return;
- var bing = new Bing(this.http);
+ var bing = new Bing();
try
{
var translatedText = await bing.TranslateAsync(str,