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()
{
}
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;
{
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();
SettingDialog.ProxyPort,
SettingDialog.ProxyUser,
SettingDialog.ProxyPassword);
- this.CreatePictureServices();
+
+ ImageSelector.Reset(tw, SettingDialog.TwitterConfiguration);
try
{
if (uid != tw.Username) this.doGetFollowersMenu();
- SetImageServiceCombo();
if (SettingDialog.IsNotifyUseGrowl) gh.RegisterGrowl();
try
{
// 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;
}
int idx = -1;
DetailsListView lst = null;
- if (ImageSelectionPanel.Enabled)
+ if (ImageSelector.Enabled)
return;
//現在タブから最終タブまで探索
if (this.thumbnailTokenSource != null)
{
var oldTokenSource = this.thumbnailTokenSource;
- oldTokenSource.Cancel();
+
+ // TODO: キャンセルを行うとUIスレッドが阻害される問題を調査
+ //oldTokenSource.Cancel();
+
this.thumbnailTask.ContinueWith(_ => oldTokenSource.Dispose());
}
_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;
{
if (this._curPost == null) return;
- var imageUrl = this._curPost.ImageUrl;
- try
+ await this.UserPicture.SetImageFromTask(async () =>
{
- var image = await this.IconCache.DownloadImageAsync(imageUrl, force: true);
+ var imageUrl = this._curPost.ImageUrl;
- this.ClearUserPicture();
- this.UserPicture.Image = image.Clone();
- }
- catch (Exception)
- {
- this.UserPicture.ShowErrorImage();
- try
- {
- throw;
- }
- catch (HttpRequestException) { }
- catch (InvalidImageException) { }
- catch (TaskCanceledException) { }
- }
+ var image = await this.IconCache.DownloadImageAsync(imageUrl, force: true)
+ .ConfigureAwait(false);
+
+ return await image.CloneAsync()
+ .ConfigureAwait(false);
+ });
}
private void SaveOriginalSizeIconPictureToolStripMenuItem_Click(object sender, EventArgs e)
}
}
- private void doShowUserStatus(TwitterUser user)
+ private async void doShowUserStatus(TwitterUser user)
{
- using (var userinfo = new UserInfoDialog())
+ using (var userDialog = new UserInfoDialog(this, this.tw))
{
- userinfo.Owner = this;
- userinfo.DisplayUser = user;
- userinfo.ShowDialog(this);
+ var showUserTask = userDialog.ShowUserAsync(user);
+ userDialog.ShowDialog(this);
+
this.Activate();
this.BringToFront();
+
+ // ユーザー情報の表示が完了するまで userDialog を破棄しない
+ await showUserTask;
}
}
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);
}