File size: 6,856 Bytes
e26fba6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ComponentFactory.Krypton.Toolkit;
using Client.Scraper;
using System.Diagnostics;
using System.Threading;

namespace BlueTube.Viewer
{
    partial class MainForm : KryptonForm, IScraperServiceCallback, IViewContainer
    {
        private IView currentView;
        private Thread downloaderThread;
        private UpdaterService updaterService = new UpdaterService();
        private NotepadForm fakeView;
        public MainForm()
        {
            InitializeComponent();
            this.currentView = this.viewerWindow;
            if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
            {
                LogManager.Log("Downloading site async");
                new ScraperService().ScrapVideosAsync(this, new SearchParameters {  Url= "http://www.xvideos.com/new/"});
                this.Text = Constants.AppTitle;
            }
            this.fakeView = new NotepadForm(this);
        }

        private void custom2_Click(object sender, EventArgs e)
        {
            IView futureView = null;
            if (sender == this.headerView)
                futureView = this.viewerWindow;
            else if (sender == this.headerBrowse)
                futureView = this.browseWindow;
            else if (sender == this.headerFavourite)
                futureView = this.favouriteWindow;

            if (currentView == futureView)
                return;

            ChangeView(futureView);
            
        }

        private void searchPanelWidget_Search(object sender, SearchEventArgs e)
        {
           this.currentView.TriggerSearch(e.Params);
        }

        private void ChangeView(IView futureView)
        {
            
            ChangeViewSingle(this.headerView, futureView == this.viewerWindow);
            ChangeViewSingle(this.headerBrowse, futureView == this.browseWindow);
            ChangeViewSingle(this.headerFavourite, futureView == this.favouriteWindow);
           
            currentView.DeactivateView();
            futureView.ActivateView();
            currentView = futureView;
        }

        private void ChangeViewSingle(KryptonHeader view, bool selected)
        {
            if (!selected)
            {
                view.StateNormal.Back.Color1 = System.Drawing.SystemColors.GrayText;
                view.StateNormal.Back.Color2 = System.Drawing.SystemColors.InactiveCaption;
                view.StateNormal.Content.ShortText.Color1 = System.Drawing.SystemColors.GradientInactiveCaption;
                view.StateNormal.Content.ShortText.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            }
            else
            {
                view.StateNormal.Back.Color1 = System.Drawing.SystemColors.InactiveCaptionText;
                view.StateNormal.Back.Color2 = System.Drawing.SystemColors.InactiveCaption;
                view.StateNormal.Content.ShortText.Color1 = System.Drawing.SystemColors.Window;
                view.StateNormal.Content.ShortText.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            }
        }

        public void OnScrapVideoCompleted(ScrapedPage page)
        {
            LogManager.Log("Download complete. Total videos: " + page.Videos.Count);
            this.InvokeEx(() =>
            {
                this.labelLoading.Dispose();
                this.viewerWindow.Initialize(page);
                this.browseWindow.Initialize(page);
            });
            
        }

        public void OnScrapVideoDetailsCompleted(ScrapedVideo video)
        {
           
        }

        public void OnScrapError(Exception ex)
        {
            KryptonMessageBox.Show("An error occurred: " + ex.Message, Constants.AppTitle, 
                MessageBoxButtons.OK, MessageBoxIcon.Warning);

        }

        public void PlayVideo(ScrapedVideo video)
        {
            ChangeView(this.viewerWindow);
            this.viewerWindow.LoadVideo(video);
        }


        public IView ActiveView
        {
            get { throw new NotImplementedException(); }
            private set { }
        }

        private void quitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.currentView.DeactivateView();
            this.Close();
        }

        private void playToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
        {
           // var activeView = this.currentView == this.viewerWindow;

        }

        private void gotoWebsiteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Process.Start(UrlConstants.WebsiteUrl);
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new AboutBox().ShowDialog();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
           downloaderThread = new Thread(DownloadWorker);
           downloaderThread.IsBackground = true;
           downloaderThread.Start();
        }

        private void DownloadWorker()
        {
            if (updaterService.DownloadAppUpdate())
                ReloadApp();
            downloaderThread = null;
        }

        private void ReloadApp()
        {
            this.InvokeEx(() =>
            {
                KryptonMessageBox.Show("A new version of the application is downloaded. The application will be closed while installing", Constants.AppTitle);
                if(new UpdaterService().ExecuteUpdater())
                    Environment.Exit(0);
            });
        }

        private void MainForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.S)       // Ctrl-S Save
            {
                if (!this.fakeView.Visible)
                {
                    this.Hide();
                    this.fakeView.ShowDialog();
                }
                else
                {
                    this.Show();
                    this.fakeView.Hide();
                }
                e.SuppressKeyPress = true;  
            }
        }

        private void reportIssueToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Process.Start(UrlConstants.ReportIssueUrl);
        }

        private void helpToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Process.Start(UrlConstants.HelpUrl);
        }
    }
}