private void TweenMain_Load(object sender, EventArgs e)
{
_ignoreConfigSave = true;
this.Visible = false;
if (MyApplication.StartupOptions.ContainsKey("d"))
MyCommon.TraceFlag = true;
InitializeTraceFrag();
//Win32Api.SetProxy(HttpConnection.ProxyType.Specified, "127.0.0.1", 8080, "user", "pass")
MyCommon.TwitterApiInfo.AccessLimitUpdated += TwitterApiStatus_AccessLimitUpdated;
Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
Regex.CacheSize = 100;
//発言保持クラス
_statuses = TabInformations.GetInstance();
//アイコン設定
LoadIcons();
this.Icon = MainIcon; //メインフォーム(TweenMain)
NotifyIcon1.Icon = NIconAt; //タスクトレイ
TabImage.Images.Add(TabIcon); //タブ見出し
//<<<<<<<<<設定関連>>>>>>>>>
////設定読み出し
LoadConfig();
// 現在の DPI と設定保存時の DPI との比を取得する
var configScaleFactor = this._cfgLocal.GetConfigScaleFactor(this.CurrentAutoScaleDimensions);
// UIフォント設定
var fontUIGlobal = this._cfgLocal.FontUIGlobal;
if (fontUIGlobal != null)
{
OTBaseForm.GlobalFont = fontUIGlobal;
this.Font = fontUIGlobal;
}
//不正値チェック
if (!MyApplication.StartupOptions.ContainsKey("nolimit"))
{
if (this._cfgCommon.TimelinePeriod < 15 && this._cfgCommon.TimelinePeriod > 0)
this._cfgCommon.TimelinePeriod = 15;
if (this._cfgCommon.ReplyPeriod < 15 && this._cfgCommon.ReplyPeriod > 0)
this._cfgCommon.ReplyPeriod = 15;
if (this._cfgCommon.DMPeriod < 15 && this._cfgCommon.DMPeriod > 0)
this._cfgCommon.DMPeriod = 15;
if (this._cfgCommon.PubSearchPeriod < 30 && this._cfgCommon.PubSearchPeriod > 0)
this._cfgCommon.PubSearchPeriod = 30;
if (this._cfgCommon.UserTimelinePeriod < 15 && this._cfgCommon.UserTimelinePeriod > 0)
this._cfgCommon.UserTimelinePeriod = 15;
if (this._cfgCommon.ListsPeriod < 15 && this._cfgCommon.ListsPeriod > 0)
this._cfgCommon.ListsPeriod = 15;
}
if (!Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Timeline, this._cfgCommon.CountApi))
this._cfgCommon.CountApi = 60;
if (!Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Reply, this._cfgCommon.CountApiReply))
this._cfgCommon.CountApiReply = 40;
if (this._cfgCommon.MoreCountApi != 0 && !Twitter.VerifyMoreApiResultCount(this._cfgCommon.MoreCountApi))
this._cfgCommon.MoreCountApi = 200;
if (this._cfgCommon.FirstCountApi != 0 && !Twitter.VerifyFirstApiResultCount(this._cfgCommon.FirstCountApi))
this._cfgCommon.FirstCountApi = 100;
if (this._cfgCommon.FavoritesCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.Favorites, this._cfgCommon.FavoritesCountApi))
this._cfgCommon.FavoritesCountApi = 40;
if (this._cfgCommon.ListCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.List, this._cfgCommon.ListCountApi))
this._cfgCommon.ListCountApi = 100;
if (this._cfgCommon.SearchCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.PublicSearch, this._cfgCommon.SearchCountApi))
this._cfgCommon.SearchCountApi = 100;
if (this._cfgCommon.UserTimelineCountApi != 0 && !Twitter.VerifyApiResultCount(MyCommon.WORKERTYPE.UserTimeline, this._cfgCommon.UserTimelineCountApi))
this._cfgCommon.UserTimelineCountApi = 20;
//廃止サービスが選択されていた場合ux.nuへ読み替え
if (this._cfgCommon.AutoShortUrlFirst < 0)
this._cfgCommon.AutoShortUrlFirst = MyCommon.UrlConverter.Uxnu;
TwitterApiConnection.RestApiHost = this._cfgCommon.TwitterApiHost;
this.tw = new Twitter(this.twitterApi);
//認証関連
if (string.IsNullOrEmpty(this._cfgCommon.Token)) this._cfgCommon.UserName = "";
tw.Initialize(this._cfgCommon.Token, this._cfgCommon.TokenSecret, this._cfgCommon.UserName, this._cfgCommon.UserId);
_initial = true;
Networking.Initialize();
bool saveRequired = false;
bool firstRun = false;
//ユーザー名、パスワードが未設定なら設定画面を表示(初回起動時など)
if (string.IsNullOrEmpty(tw.Username))
{
saveRequired = true;
firstRun = true;
//設定せずにキャンセルされたか、設定されたが依然ユーザー名が未設定ならプログラム終了
if (ShowSettingDialog(showTaskbarIcon: true) != DialogResult.OK ||
string.IsNullOrEmpty(tw.Username))
{
Application.Exit(); //強制終了
return;
}
}
//Twitter用通信クラス初期化
Networking.DefaultTimeout = TimeSpan.FromSeconds(this._cfgCommon.DefaultTimeOut);
Networking.UploadImageTimeout = TimeSpan.FromSeconds(this._cfgCommon.UploadImageTimeout);
Networking.SetWebProxy(this._cfgLocal.ProxyType,
this._cfgLocal.ProxyAddress, this._cfgLocal.ProxyPort,
this._cfgLocal.ProxyUser, this._cfgLocal.ProxyPassword);
Networking.ForceIPv4 = this._cfgCommon.ForceIPv4;
TwitterApiConnection.RestApiHost = this._cfgCommon.TwitterApiHost;
tw.RestrictFavCheck = this._cfgCommon.RestrictFavCheck;
tw.ReadOwnPost = this._cfgCommon.ReadOwnPost;
tw.TrackWord = this._cfgCommon.TrackWord;
TrackToolStripMenuItem.Checked = !String.IsNullOrEmpty(tw.TrackWord);
tw.AllAtReply = this._cfgCommon.AllAtReply;
AllrepliesToolStripMenuItem.Checked = tw.AllAtReply;
ShortUrl.Instance.DisableExpanding = !this._cfgCommon.TinyUrlResolve;
ShortUrl.Instance.BitlyId = this._cfgCommon.BilyUser;
ShortUrl.Instance.BitlyKey = this._cfgCommon.BitlyPwd;
// アクセストークンが有効であるか確認する
// ここが Twitter API への最初のアクセスになるようにすること
try
{
this.tw.VerifyCredentials();
}
catch (WebApiException ex)
{
MessageBox.Show(this, string.Format(Properties.Resources.StartupAuthError_Text, ex.Message),
Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
//サムネイル関連の初期化
//プロキシ設定等の通信まわりの初期化が済んでから処理する
ThumbnailGenerator.InitializeGenerator();
var imgazyobizinet = ThumbnailGenerator.ImgAzyobuziNetInstance;
imgazyobizinet.Enabled = this._cfgCommon.EnableImgAzyobuziNet;
imgazyobizinet.DisabledInDM = this._cfgCommon.ImgAzyobuziNetDisabledInDM;
Thumbnail.Services.TonTwitterCom.GetApiConnection = () => this.twitterApi.Connection;
//画像投稿サービス
ImageSelector.Initialize(tw, this.tw.Configuration, _cfgCommon.UseImageServiceName, _cfgCommon.UseImageService);
//ハッシュタグ/@id関連
AtIdSupl = new AtIdSupplement(SettingAtIdList.Load().AtIdList, "@");
HashSupl = new AtIdSupplement(_cfgCommon.HashTags, "#");
HashMgr = new HashtagManage(HashSupl,
_cfgCommon.HashTags.ToArray(),
_cfgCommon.HashSelected,
_cfgCommon.HashIsPermanent,
_cfgCommon.HashIsHead,
_cfgCommon.HashIsNotAddToAtReply);
if (!string.IsNullOrEmpty(HashMgr.UseHash) && HashMgr.IsPermanent) HashStripSplitButton.Text = HashMgr.UseHash;
//アイコンリスト作成
this.IconCache = new ImageCache();
this.tweetDetailsView.IconCache = this.IconCache;
//フォント&文字色&背景色保持
_fntUnread = this._cfgLocal.FontUnread;
_clUnread = this._cfgLocal.ColorUnread;
_fntReaded = this._cfgLocal.FontRead;
_clReaded = this._cfgLocal.ColorRead;
_clFav = this._cfgLocal.ColorFav;
_clOWL = this._cfgLocal.ColorOWL;
_clRetweet = this._cfgLocal.ColorRetweet;
_fntDetail = this._cfgLocal.FontDetail;
_clDetail = this._cfgLocal.ColorDetail;
_clDetailLink = this._cfgLocal.ColorDetailLink;
_clDetailBackcolor = this._cfgLocal.ColorDetailBackcolor;
_clSelf = this._cfgLocal.ColorSelf;
_clAtSelf = this._cfgLocal.ColorAtSelf;
_clTarget = this._cfgLocal.ColorTarget;
_clAtTarget = this._cfgLocal.ColorAtTarget;
_clAtFromTarget = this._cfgLocal.ColorAtFromTarget;
_clAtTo = this._cfgLocal.ColorAtTo;
_clListBackcolor = this._cfgLocal.ColorListBackcolor;
_clInputBackcolor = this._cfgLocal.ColorInputBackcolor;
_clInputFont = this._cfgLocal.ColorInputFont;
_fntInputFont = this._cfgLocal.FontInputFont;
_brsBackColorMine = new SolidBrush(_clSelf);
_brsBackColorAt = new SolidBrush(_clAtSelf);
_brsBackColorYou = new SolidBrush(_clTarget);
_brsBackColorAtYou = new SolidBrush(_clAtTarget);
_brsBackColorAtFromTarget = new SolidBrush(_clAtFromTarget);
_brsBackColorAtTo = new SolidBrush(_clAtTo);
//_brsBackColorNone = new SolidBrush(Color.FromKnownColor(KnownColor.Window));
_brsBackColorNone = new SolidBrush(_clListBackcolor);
// StringFormatオブジェクトへの事前設定
//sf.Alignment = StringAlignment.Near; // Textを近くへ配置(左から右の場合は左寄せ)
//sf.LineAlignment = StringAlignment.Near; // Textを近くへ配置(上寄せ)
//sf.FormatFlags = StringFormatFlags.LineLimit; //
sfTab.Alignment = StringAlignment.Center;
sfTab.LineAlignment = StringAlignment.Center;
InitDetailHtmlFormat();
//Regex statregex = new Regex("^0*");
this.recommendedStatusFooter = " [TWNv" + Regex.Replace(MyCommon.FileVersion.Replace(".", ""), "^0*", "") + "]";
_history.Add(new PostingStatus());
_hisIdx = 0;
this.inReplyTo = null;
//各種ダイアログ設定
SearchDialog.Owner = this;
UrlDialog.Owner = this;
//新着バルーン通知のチェック状態設定
NewPostPopMenuItem.Checked = _cfgCommon.NewAllPop;
this.NotifyFileMenuItem.Checked = NewPostPopMenuItem.Checked;
//新着取得時のリストスクロールをするか。trueならスクロールしない
ListLockMenuItem.Checked = _cfgCommon.ListLock;
this.LockListFileMenuItem.Checked = _cfgCommon.ListLock;
//サウンド再生(タブ別設定より優先)
this.PlaySoundMenuItem.Checked = this._cfgCommon.PlaySound;
this.PlaySoundFileMenuItem.Checked = this._cfgCommon.PlaySound;
this.IdeographicSpaceToSpaceToolStripMenuItem.Checked = _cfgCommon.WideSpaceConvert;
this.ToolStripFocusLockMenuItem.Checked = _cfgCommon.FocusLockToStatusText;
//ウィンドウ設定
this.ClientSize = ScaleBy(configScaleFactor, _cfgLocal.FormSize);
_mySize = this.ClientSize; // サイズ保持(最小化・最大化されたまま終了した場合の対応用)
_myLoc = _cfgLocal.FormLocation;
//タイトルバー領域
if (this.WindowState != FormWindowState.Minimized)
{
this.DesktopLocation = _cfgLocal.FormLocation;
Rectangle tbarRect = new Rectangle(this.Location, new Size(_mySize.Width, SystemInformation.CaptionHeight));
bool outOfScreen = true;
if (Screen.AllScreens.Length == 1) //ハングするとの報告
{
foreach (Screen scr in Screen.AllScreens)
{
if (!Rectangle.Intersect(tbarRect, scr.Bounds).IsEmpty)
{
outOfScreen = false;
break;
}
}
if (outOfScreen)
{
this.DesktopLocation = new Point(0, 0);
_myLoc = this.DesktopLocation;
}
}
}
this.TopMost = this._cfgCommon.AlwaysTop;
_mySpDis = ScaleBy(configScaleFactor.Height, _cfgLocal.SplitterDistance);
_mySpDis2 = ScaleBy(configScaleFactor.Height, _cfgLocal.StatusTextHeight);
if (_cfgLocal.PreviewDistance == -1)
{
_mySpDis3 = _mySize.Width - ScaleBy(this.CurrentScaleFactor.Width, 150);
if (_mySpDis3 < 1) _mySpDis3 = ScaleBy(this.CurrentScaleFactor.Width, 50);
_cfgLocal.PreviewDistance = _mySpDis3;
}
else
{
_mySpDis3 = ScaleBy(configScaleFactor.Width, _cfgLocal.PreviewDistance);
}
MultiLineMenuItem.Checked = _cfgLocal.StatusMultiline;
//this.Tween_ClientSizeChanged(this, null);
this.PlaySoundMenuItem.Checked = this._cfgCommon.PlaySound;
this.PlaySoundFileMenuItem.Checked = this._cfgCommon.PlaySound;
//入力欄
StatusText.Font = _fntInputFont;
StatusText.ForeColor = _clInputFont;
// SplitContainer2.Panel2MinSize を一行表示の入力欄の高さに合わせる (MS UI Gothic 12pt (96dpi) の場合は 19px)
this.StatusText.Multiline = false; // _cfgLocal.StatusMultiline の設定は後で反映される
this.SplitContainer2.Panel2MinSize = this.StatusText.Height;
// 必要であれば、発言一覧と発言詳細部・入力欄の上下を入れ替える
SplitContainer1.IsPanelInverted = !this._cfgCommon.StatusAreaAtBottom;
//全新着通知のチェック状態により、Reply&DMの新着通知有効無効切り替え(タブ別設定にするため削除予定)
if (this._cfgCommon.UnreadManage == false)
{
ReadedStripMenuItem.Enabled = false;
UnreadStripMenuItem.Enabled = false;
}
//リンク先URL表示部の初期化(画面左下)
StatusLabelUrl.Text = "";
//状態表示部の初期化(画面右下)
StatusLabel.Text = "";
StatusLabel.AutoToolTip = false;
StatusLabel.ToolTipText = "";
//文字カウンタ初期化
lblLen.Text = this.GetRestStatusCount(this.FormatStatusText("")).ToString();
this.JumpReadOpMenuItem.ShortcutKeyDisplayString = "Space";
CopySTOTMenuItem.ShortcutKeyDisplayString = "Ctrl+C";
CopyURLMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+C";
CopyUserIdStripMenuItem.ShortcutKeyDisplayString = "Shift+Alt+C";
// SourceLinkLabel のテキストが SplitContainer2.Panel2.AccessibleName にセットされるのを防ぐ
// (タブオーダー順で SourceLinkLabel の次にある PostBrowser が TabStop = false となっているため、
// さらに次のコントロールである SplitContainer2.Panel2 の AccessibleName がデフォルトで SourceLinkLabel のテキストになってしまう)
this.SplitContainer2.Panel2.AccessibleName = "";
////////////////////////////////////////////////////////////////////////////////
var sortOrder = (SortOrder)_cfgCommon.SortOrder;
var mode = ComparerMode.Id;
switch (_cfgCommon.SortColumn)
{
case 0: //0:アイコン,5:未読マーク,6:プロテクト・フィルターマーク
case 5:
case 6:
//ソートしない
mode = ComparerMode.Id; //Idソートに読み替え
break;
case 1: //ニックネーム
mode = ComparerMode.Nickname;
break;
case 2: //本文
mode = ComparerMode.Data;
break;
case 3: //時刻=発言Id
mode = ComparerMode.Id;
break;
case 4: //名前
mode = ComparerMode.Name;
break;
case 7: //Source
mode = ComparerMode.Source;
break;
}
_statuses.SetSortMode(mode, sortOrder);
////////////////////////////////////////////////////////////////////////////////
ApplyListViewIconSize(this._cfgCommon.IconSize);
//<<<<<<<<タブ関連>>>>>>>
// タブの位置を調整する
SetTabAlignment();
//デフォルトタブの存在チェック、ない場合には追加
if (this._statuses.GetTabByType<HomeTabModel>() == null)
this._statuses.AddTab(new HomeTabModel());
if (this._statuses.GetTabByType<MentionsTabModel>() == null)
this._statuses.AddTab(new MentionsTabModel());
if (this._statuses.GetTabByType<DirectMessagesTabModel>() == null)
this._statuses.AddTab(new DirectMessagesTabModel());
if (this._statuses.GetTabByType<FavoritesTabModel>() == null)
this._statuses.AddTab(new FavoritesTabModel());
if (this._statuses.GetTabByType<MuteTabModel>() == null)
this._statuses.AddTab(new MuteTabModel());
foreach (var tab in _statuses.Tabs.Values)
{
// ミュートタブは表示しない
if (tab.TabType == MyCommon.TabUsageType.Mute)
continue;
if (!AddNewTab(tab, startup: true))
throw new TabException(Properties.Resources.TweenMain_LoadText1);
}
_curTab = ListTab.SelectedTab;
_curItemIndex = -1;
_curList = (DetailsListView)_curTab.Tag;
if (this._cfgCommon.TabIconDisp)
{
ListTab.DrawMode = TabDrawMode.Normal;
}
else
{
ListTab.DrawMode = TabDrawMode.OwnerDrawFixed;
ListTab.DrawItem += ListTab_DrawItem;
ListTab.ImageList = null;
}
if (this._cfgCommon.HotkeyEnabled)
{
//////グローバルホットキーの登録
HookGlobalHotkey.ModKeys modKey = HookGlobalHotkey.ModKeys.None;
if ((this._cfgCommon.HotkeyModifier & Keys.Alt) == Keys.Alt)
modKey |= HookGlobalHotkey.ModKeys.Alt;
if ((this._cfgCommon.HotkeyModifier & Keys.Control) == Keys.Control)
modKey |= HookGlobalHotkey.ModKeys.Ctrl;
if ((this._cfgCommon.HotkeyModifier & Keys.Shift) == Keys.Shift)
modKey |= HookGlobalHotkey.ModKeys.Shift;
if ((this._cfgCommon.HotkeyModifier & Keys.LWin) == Keys.LWin)
modKey |= HookGlobalHotkey.ModKeys.Win;
_hookGlobalHotkey.RegisterOriginalHotkey(this._cfgCommon.HotkeyKey, this._cfgCommon.HotkeyValue, modKey);
}
if (this._cfgCommon.IsUseNotifyGrowl)
gh.RegisterGrowl();
StatusLabel.Text = Properties.Resources.Form1_LoadText1; //画面右下の状態表示を変更
SetMainWindowTitle();
SetNotifyIconText();
if (!this._cfgCommon.MinimizeToTray || this.WindowState != FormWindowState.Minimized)
{
this.Visible = true;
}
//タイマー設定
TimerTimeline.AutoReset = true;
TimerTimeline.SynchronizingObject = this;
//Recent取得間隔
TimerTimeline.Interval = 1000;
TimerTimeline.Enabled = true;
//更新中アイコンアニメーション間隔
TimerRefreshIcon.Interval = 200;
TimerRefreshIcon.Enabled = true;
_ignoreConfigSave = false;
this.TweenMain_Resize(null, null);
if (saveRequired) SaveConfigsAll(false);
foreach (var ua in this._cfgCommon.UserAccounts)
{
if (ua.UserId == 0 && ua.Username.ToLowerInvariant() == tw.Username.ToLowerInvariant())
{
ua.UserId = tw.UserId;
break;
}
}
if (firstRun)
{
// 初回起動時だけ右下のメニューを目立たせる
HashStripSplitButton.ShowDropDown();
}
}