/
Form1.cs
1107 lines (885 loc) · 30.3 KB
/
Form1.cs
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Infragistics.Win.UltraWinTree;
using Infragistics.Win.UltraWinListView;
using Infragistics.Win.Misc;
using System.IO;
using System.Threading;
using TagLib;
using LastFmLib.Scrobbler;
using LastFmLib.TypeClasses;
using LastFmLib;
using Infragistics.Win.AppStyling;
using CueSharp;
using C5;
namespace CraftyScrobbler
{
public partial class CraftyScrobbler : Form
{
#region Own Variables
long timeStarted;
TextBox info = new TextBox();
TextBox login = new TextBox();
TextBox password = new TextBox();
Label loginL = new Label();
Label passL = new Label();
UltraButton confirm = new UltraButton();
Label ok = new Label();
TableLayoutPanel panel = new TableLayoutPanel();
//dropdown subbuttons
UltraButton scrobbleDate = new UltraButton();
UltraButton scrobbleConfig = new UltraButton();
TableLayoutPanel dropdownPanelScrobble = new TableLayoutPanel();
UltraButton removeAll = new UltraButton();
//last.fm utilities
private LastFmClient client;
private ScrobblerManager sm;
string userLogin = "";
string userPassword = "";
bool scrobblerInit = false;
//additional controls
//ContextMenu addMenu = new ContextMenu();
UltraButton addAll = new UltraButton();
UltraButton addByPattern = new UltraButton();
TableLayoutPanel addMenu = new TableLayoutPanel();
//
UltraButton inverseSelection = new UltraButton();
UltraButton findButton = new UltraButton();
TableLayoutPanel selectionMenu = new TableLayoutPanel();
#endregion
public CraftyScrobbler()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OwnInitializers();
//StartMarqueeProgressBar();
RefreshFoldersList();
}
#region Own Methods
private void UpdateStats()
{
int count = trackList.Items.Count;
int countScrobble = 0;
object[] items = trackList.Items.All;
TimeSpan total = new TimeSpan(0, 0, 0);
TimeSpan toScrobble = new TimeSpan(0, 0, 0);
try
{
foreach (object item in items)
{
UltraListViewItem current = (UltraListViewItem)item;
total = total.Add(TimeSpan.Parse(current.SubItems[3].Value.ToString()));
toScrobble = toScrobble.Add(new TimeSpan(TimeSpan.Parse(current.SubItems[3].Value.ToString()).Ticks * (int)current.SubItems[4].Value));
countScrobble += (int)current.SubItems[4].Value;
}
}
catch { }
labelStats.Text = "Total items: " + count + " " + "Scrobbles count: " + countScrobble + " " + "Total time: " + total.ToString() +
" " + "Scrobble time: " + toScrobble.ToString();
}
private void StartMarqueeProgressBar()
{
infoLabel.Visible = false;
progressBar.Visible = true;
progressBar.MarqueeAnimationSpeed = 10;
}
private void StopMarqueeProgressBar()
{
if (infoLabel.InvokeRequired == true)
{
this.infoLabel.Invoke((MethodInvoker)delegate()
{
StopMarqueeProgressBar();
});
}
else
{
infoLabel.Visible = true;
progressBar.Visible = false;
progressBar.MarqueeAnimationSpeed = 0;
}
}
private void OwnInitializers()
{
scrobbleDropdown.PopupItem = scrobbleDropdownPopup;
removeDropdown.PopupItem = removePopup;
progressBar.Visible = false;
//
info.Size = new Size(240, 320);
info.Multiline = true;
//
panel.Size = new Size(140, 175);
int offSet = 8;
password.UseSystemPasswordChar = true;
loginL.Text = "Login";
loginL.Size = new Size(panel.Size.Width - offSet, loginL.Size.Height);
loginL.TextAlign = ContentAlignment.MiddleCenter;
login.Size = new Size(panel.Size.Width - offSet, login.Size.Height);
panel.Controls.Add(loginL);
panel.Controls.Add(login);
passL.Text = "Password";
passL.Size = new Size(panel.Size.Width - offSet, passL.Size.Height);
passL.TextAlign = ContentAlignment.MiddleCenter;
password.Size = new Size(panel.Size.Width - offSet, password.Size.Height);
panel.Controls.Add(passL);
panel.Controls.Add(password);
confirm.Click += new EventHandler(onConfirm);
confirm.Text = "Update";
confirm.Size = new Size(panel.Size.Width - offSet, confirm.Size.Height);
panel.Controls.Add(confirm);
ok.Text = "Saved!";
ok.TextAlign = ContentAlignment.MiddleCenter;
ok.Size = new Size(panel.Size.Width - offSet, ok.Size.Height);
ok.Visible = false;
panel.Controls.Add(ok);
panel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset;
//
scrobbleDate.Text = "Specify scrobble date!";
scrobbleDate.Size = scrobbleDropdown.Size;
scrobbleDate.UseOsThemes = Infragistics.Win.DefaultableBoolean.False;
scrobbleDate.ButtonStyle = Infragistics.Win.UIElementButtonStyle.WindowsVistaButton;
scrobbleDate.Click += new EventHandler(scrobbleDate_Click);
//
removeAll.Text = "Remove All";
removeAll.Size = removeDropdown.Size;
removeAll.UseOsThemes = Infragistics.Win.DefaultableBoolean.False;
removeAll.ButtonStyle = Infragistics.Win.UIElementButtonStyle.WindowsVistaButton;
removeAll.Click += new EventHandler(removeAll_Click);
/*
scrobbleConfig.Text = "Initialize & check scrobbler";
scrobbleConfig.Size = scrobbleDropdown.Size;
scrobbleConfig.UseOsThemes = Infragistics.Win.DefaultableBoolean.False;
scrobbleConfig.ButtonStyle = Infragistics.Win.UIElementButtonStyle.WindowsVistaButton;
dropdownPanelScrobble.Controls.Add(scrobbleDate);
dropdownPanelScrobble.Controls.Add(scrobbleConfig);
dropdownPanelScrobble.CellBorderStyle = TableLayoutPanelCellBorderStyle.None;
dropdownPanelScrobble.Size = new Size(scrobbleConfig.Size.Width, scrobbleConfig.Size.Height * 2);
* */
//
//trackList.ContextMenuStrip = new ContextMenuStrip();
addAll.Size = new Size(addDropButton.Size.Width, addDropButton.Size.Height);
addAll.Text = "Add All";
addAll.Margin = new Padding(0, 0, 0, 0);
addAll.UseOsThemes = Infragistics.Win.DefaultableBoolean.False;
addAll.ButtonStyle = Infragistics.Win.UIElementButtonStyle.WindowsVistaButton;
addAll.Click += new EventHandler(addAll_Click);
addByPattern.Size = new Size(addDropButton.Size.Width, addDropButton.Size.Height);
addByPattern.Text = "Add by Pattern";
addByPattern.Margin = new Padding(0, 0, 0, 0);
addByPattern.UseOsThemes = Infragistics.Win.DefaultableBoolean.False;
addByPattern.ButtonStyle = Infragistics.Win.UIElementButtonStyle.WindowsVistaButton;
addByPattern.Click += new EventHandler(addByPattern_Click);
addDropButton.PopupItem = addDropdownPopup;
selectionDropdown.PopupItem = selectionDropdownPopup;
addMenu.Controls.Add(addAll);
addMenu.Controls.Add(addByPattern);
addMenu.Size = new Size(addDropButton.Size.Width, addDropButton.Size.Height * 2);
addMenu.Padding = new Padding(0, 0, 0, 0);
addMenu.Margin = new Padding(0, 0, 0, 0);
//
inverseSelection.Size = new Size(selectionDropdown.Size.Width, selectionDropdown.Size.Height);
inverseSelection.Text = "Invert Selection";
inverseSelection.Margin = new Padding(0, 0, 0, 0);
inverseSelection.UseOsThemes = Infragistics.Win.DefaultableBoolean.False;
inverseSelection.ButtonStyle = Infragistics.Win.UIElementButtonStyle.WindowsVistaButton;
inverseSelection.Click += new EventHandler(inverseSelection_Click);
findButton.Size = new Size(selectionDropdown.Size.Width, selectionDropdown.Size.Height);
findButton.Text = "Find";
findButton.Margin = new Padding(0, 0, 0, 0);
findButton.UseOsThemes = Infragistics.Win.DefaultableBoolean.False;
findButton.ButtonStyle = Infragistics.Win.UIElementButtonStyle.WindowsVistaButton;
findButton.Click += new EventHandler(findButton_Click);
selectionMenu.Controls.Add(inverseSelection);
selectionMenu.Controls.Add(findButton);
selectionMenu.Size = new Size(selectionDropdown.Size.Width, selectionDropdown.Size.Height * 2);
selectionMenu.Padding = new Padding(0, 0, 0, 0);
selectionMenu.Margin = new Padding(0, 0, 0, 0);
Infragistics.Win.AppStyling.StyleManager.Load(".//themes//NoirModerne.isl");
}
private void RefreshFoldersList()
{
StartTimer();
//StartMarqueeProgressBar();
folderTree.Nodes.Clear();
string[] drives = Directory.GetLogicalDrives();
UltraTreeNode rootNode = new UltraTreeNode();
rootNode.Text = System.Environment.MachineName.ToString();
foreach (string drive in drives)
{
UltraTreeNode nodeDrive = new UltraTreeNode();
nodeDrive.Text = drive;
try
{
if (Directory.Exists(drive))
{
foreach (string dir in Directory.GetDirectories(drive))
{
UltraTreeNode node = new UltraTreeNode();
node.Text = dir.Substring(dir.LastIndexOf(@"\") + 1);
nodeDrive.Nodes.Add(node);
}
}
}
catch (Exception) { }
rootNode.Nodes.Add(nodeDrive);
}
folderTree.Nodes.Add(rootNode);
folderTree.Refresh();
StopTimer();
//StopMarqueeProgressBar();
}
private void StartTimer()
{
timeStarted = DateTime.Now.Ticks;
}
private void StopTimer()
{
long elapsed = DateTime.Now.Ticks - timeStarted;
if (timeLabel.InvokeRequired == true)
{
this.timeLabel.Invoke((MethodInvoker)delegate()
{
StopTimer();
});
}else timeLabel.Text = (elapsed / TimeSpan.TicksPerMillisecond).ToString() + " ms";
}
#endregion
#region Event Handlers
private void Size_Changed(object sender, EventArgs e)
{
folderTree.Size = new Size(folderTree.Size.Width, this.Size.Height - 120);
trackList.Size = new Size(this.Size.Width - folderTree.Size.Width - 50, trackList.Size.Height);
fileList.Size = new Size(this.Size.Width - folderTree.Size.Width - 50, this.Size.Height - trackList.Size.Height - 175);
int bottomPadding = 71;
addDropButton.Location = new Point(addDropButton.Location.X, this.Size.Height - bottomPadding);
selectionDropdown.Location = new Point(selectionDropdown.Location.X, this.Size.Height - bottomPadding);
openCue.Location = new Point(openCue.Location.X, this.Size.Height - bottomPadding);
quitButton.Location = new Point(quitButton.Location.X, this.Size.Height - bottomPadding);
treeFullButton.Size = new Size(treeFullButton.Size.Width, folderTree.Size.Height);
tracksFullButton.Size = new Size(trackList.Size.Width, tracksFullButton.Size.Height);
}
private void folderTree_AfterActivate(object sender, NodeEventArgs e)
{
StartTimer();
string path = e.TreeNode.FullPath.Replace(e.TreeNode.RootNode.FullPath + "\\", "");
if (!e.TreeNode.HasNodes)
{
if(Directory.Exists(path))
{
try
{
foreach (string dir in Directory.GetDirectories(path))
{
UltraTreeNode node = new UltraTreeNode();
node.Text = dir.Substring(dir.LastIndexOf(@"\") + 1);
e.TreeNode.Nodes.Add(node);
}
}
catch (UnauthorizedAccessException) { }
}
}
try
{
fileList.Items.Clear();
string[] files = Directory.GetFiles(path); //search does not allow multiple patterns
foreach (string file in files)
{
string ext = Path.GetExtension(file);
object[] subItemsValues = new string[] { };
UltraListViewItem item = new UltraListViewItem();
switch (ext)
{
case ".mp3":
subItemsValues = new string[] { "MP3" };
item = new UltraListViewItem(Path.GetFileName(file), subItemsValues);
item.Key = file;
fileList.Items.Add(item);
break;
case ".ogg":
subItemsValues = new string[] { "OGG" };
item = new UltraListViewItem(Path.GetFileName(file), subItemsValues);
item.Key = file;
fileList.Items.Add(item);
break;
case ".flac":
subItemsValues = new string[] { "FLAC" };
item = new UltraListViewItem(Path.GetFileName(file), subItemsValues);
item.Key = file;
fileList.Items.Add(item);
break;
case ".ape":
subItemsValues = new string[] { "APE" };
item = new UltraListViewItem(Path.GetFileName(file), subItemsValues);
item.Key = file;
fileList.Items.Add(item);
break;
}
}
}
catch (Exception) {}
StopTimer();
}
private void addAll_Click(object sender, EventArgs e)
{
StartTimer();
object[] files = fileList.Items.All;
ArrayList errors = new ArrayList();
foreach (object file in files)
{
try
{
UltraListViewItem item = (UltraListViewItem)file;
TagLib.File tagFile = TagLib.File.Create(item.Key.ToString());
ArrayList subItemValues = new ArrayList();
subItemValues.Add(tagFile.Tag.Title);
subItemValues.Add(tagFile.Tag.FirstPerformer);
subItemValues.Add(tagFile.Tag.Album);
subItemValues.Add(tagFile.Properties.Duration.ToString());
subItemValues.Add(1);
UltraListViewItem track = new UltraListViewItem(tagFile.Name, subItemValues.ToArray());
trackList.Items.Add(track);
}
catch (Exception exp)
{
errors.Add(((UltraListViewItem)file).Value.ToString() + " : " + exp.Message.ToString());
}
}
if (errors.Count > 0)
{
info.Clear();
info.AppendText("Following errors have occured:\r\n\r\n");
foreach (string error in errors.ToArray())
{
info.AppendText(error);
info.AppendText("\r\n");
}
errorPopup.Show(new Point(this.Size.Width + this.Location.X, this.Location.Y + this.Size.Height / 3));
}
UpdateStats();
StopTimer();
}
private void addByPattern_Click(object sender, EventArgs e)
{
}
private void inverseSelection_Click(object sender, EventArgs e)
{
}
private void findButton_Click(object sender, EventArgs e)
{
}
private void ultraPopupControlContainer1_Opening(object sender, CancelEventArgs e)
{
errorPopup.PopupControl = info;
}
void onConfirm(object sender, EventArgs e)
{
StartMarqueeProgressBar();
if (login.Text.Equals(""))
{
MessageBox.Show("You forgot to enter your username!", "Ooops, oook!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ok.Visible = false;
StopMarqueeProgressBar();
}
else
{
userLogin = login.Text;
if (password.Text.Equals(""))
{
MessageBox.Show("You forgot to enter your password!", "Ooops, oook!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ok.Visible = false;
StopMarqueeProgressBar();
}
else
{
userPassword = password.Text;
Thread initSThread = new Thread(new ThreadStart(initializeScrobbler));
initSThread.IsBackground = true;
initSThread.Start();
ok.Text = "Authorizing...";
ok.Visible = true;
}
}
}
private void initializeScrobbler()
{
StartTimer();
//StartMarqueeProgressBar();
client = new LastFmClient();
client.User = new LastFmUser();
client.User.Username = userLogin;
client.User.Password = userPassword;
LastFmLib.WebRequests.Handshake handshake = client.Login();
if (handshake.succeeded)
{
sm = client.GetScrobblerManager();
scrobblerInit = true;
if (ok.InvokeRequired)
{
this.Invoke((MethodInvoker)delegate()
{
ok.Text = "Confirmed!";
optionsPopup.Show(new Point(this.Size.Width + this.Location.X, this.Location.Y + this.Size.Height / 3));
});
}
else ok.Text = "Cofirmed!";
}
else
{
if (ok.InvokeRequired)
{
this.Invoke((MethodInvoker)delegate()
{
ok.Text = "Failed!\n (" + handshake.errorMessage + ")";
ok.Size = new Size(ok.Size.Width, ok.Size.Height * 2);
panel.Size = new Size(panel.Width, panel.Height + ok.Size.Height / 2);
optionsPopup.Show(new Point(this.Size.Width + this.Location.X, this.Location.Y + this.Size.Height / 3));
});
}
else ok.Text = "Failed!";
}
StopTimer();
StopMarqueeProgressBar();
}
private void ultraPopupControlContainer2_Opening(object sender, CancelEventArgs e)
{
optionsPopup.PopupControl = panel;
}
private void ultraButton1_Click(object sender, EventArgs e)
{
optionsPopup.Show(new Point(this.Size.Width + this.Location.X, this.Location.Y + this.Size.Height / 3));
}
private void ultraDropDownButton1_Click(object sender, EventArgs e)
{
if (scrobblerInit)
{
if (trackList.Items.Count > 0)
{
object[] files = trackList.Items.All;
if (files.Length > 50)
{
MessageBox.Show("Scrobbling more than 50 tracks - last.fm response may be lagged.", "Tracks, a lot!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
//UltraListViewItem item = (UltraListViewItem)files[0];
C5.ArrayList<TrackInfo> tracks = new C5.ArrayList<TrackInfo>();
try
{
foreach (object file in files)
{
UltraListViewItem item = (UltraListViewItem)file;
TrackInfo info = new TrackInfo(item.SubItems[1].Value.ToString(), item.SubItems[2].Value.ToString(), item.SubItems[0].Value.ToString()); //artist (!empty), album (may be empty), title (!empty)
info.Username = userLogin;
info.Duration = (int)TimeSpan.Parse(item.SubItems[3].Value.ToString()).TotalSeconds;
info.SourceString = "P";
info.timeStampMe();
for (int i = 0; i < (int)item.SubItems[4].Value; i++ )
tracks.Add(info);
}
tracks.Shuffle();
ScrobblerCache cache = new ScrobblerCache(userLogin);
cache.Append(new List<TrackInfo>(tracks.ToArray()), true);
sm.Scrobble(ref cache);
MessageBox.Show("Scrobbled successfully!", "Oll Korrect", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch(Exception exp)
{
}
}
else
{
MessageBox.Show("Alas, nothing to scrobble!", "Oops, no tracks at all", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
else
{
MessageBox.Show("Hold yer horses! Enter user info first - click 'options' and so on", "Methinks we're forgetting something...", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
private void ultraPopupControlContainer3_Opening(object sender, CancelEventArgs e)
{
scrobbleDropdownPopup.PopupControl = scrobbleDate;
//scrobbleDropdownPopup.PopupControl = dropdownPanelScrobble;
}
private void RefreshButton_Click_1(object sender, EventArgs e)
{
RefreshFoldersList();
}
private void trackList_ItemDoubleClick(object sender, ItemDoubleClickEventArgs e)
{
/*
trackList.Items.RemoveAt(e.Item.Index);
UpdateStats();
* */
}
private void fileList_ItemDoubleClick(object sender, ItemDoubleClickEventArgs e)
{
TagLib.File tagFile = TagLib.File.Create(e.Item.Key.ToString());
ArrayList subItemValues = new ArrayList();
subItemValues.Add(tagFile.Tag.Title);
subItemValues.Add(tagFile.Tag.FirstPerformer);
subItemValues.Add(tagFile.Tag.Album);
subItemValues.Add(tagFile.Properties.Duration.ToString());
subItemValues.Add(1);
UltraListViewItem track = new UltraListViewItem(tagFile.Name, subItemValues.ToArray());
trackList.Items.Add(track);
UpdateStats();
}
private void scrobbleDate_Click(object sender, EventArgs e)
{
DataScrobble dScrobble = new DataScrobble(trackList.Items.All, userLogin, userPassword, sm);
DialogResult dResult = dScrobble.ShowDialog(this);
}
private void folderTree_MouseEnter(object sender, EventArgs e)
{
infoLabel.Text = "Do select a folder with some audio files (mp3, ogg, flac, ape) in it";
}
private void folderTree_MouseLeave(object sender, EventArgs e)
{
if (fileList.Items.Count == 0)
{
infoLabel.Text = "Alas, this directory of yours is but empty: no compatible audio tracks detected";
}
else
{
infoLabel.Text = "Choose tracks you want to scrobble - add those to track (upper) list";
}
}
private void fileList_ItemActivated(object sender, ItemActivatedEventArgs e)
{
//infoLabel.Text = "Good, you may now add selected files to scrobble list";
}
private void fileList_MouseEnter(object sender, EventArgs e)
{
infoLabel.Text = "Double click to add desired file to scrobble list";
}
private void trackList_MouseEnter(object sender, EventArgs e)
{
infoLabel.Text = "Left click to increment scrobble count, right click - to decrement count.";//"Double click to remove unwanted track from scrobble list";
}
private void scrobbleDropdown_MouseEnter(object sender, EventArgs e)
{
infoLabel.Text = "'Album' field may be empty, but the artist and track title must be filled out.";
}
private void removeDropdown_Click(object sender, EventArgs e)
{
object[] selected = trackList.SelectedItems.All;
foreach(UltraListViewItem item in selected) {
trackList.Items.Remove(item);
}
UpdateStats();
}
private void removeAll_Click(object sender, EventArgs e)
{
trackList.Items.Clear();
UpdateStats();
}
private void removePopup_Opening(object sender, CancelEventArgs e)
{
removePopup.PopupControl = removeAll;
}
private void addDropButton_Click(object sender, EventArgs e)
{
StartTimer();
object[] files = fileList.SelectedItems.All;
ArrayList errors = new ArrayList();
foreach (object file in files)
{
try
{
UltraListViewItem item = (UltraListViewItem)file;
TagLib.File tagFile = TagLib.File.Create(item.Key.ToString());
ArrayList subItemValues = new ArrayList();
subItemValues.Add(tagFile.Tag.Title);
subItemValues.Add(tagFile.Tag.FirstPerformer);
subItemValues.Add(tagFile.Tag.Album);
subItemValues.Add(tagFile.Properties.Duration.ToString());
subItemValues.Add(1);
UltraListViewItem track = new UltraListViewItem(tagFile.Name, subItemValues.ToArray());
trackList.Items.Add(track);
}
catch (Exception exp)
{
errors.Add(((UltraListViewItem)file).Value.ToString() + " : " + exp.Message.ToString());
}
}
if (errors.Count > 0)
{
info.Clear();
info.AppendText("Following errors have occured:\r\n\r\n");
foreach (string error in errors.ToArray())
{
info.AppendText(error);
info.AppendText("\r\n");
}
errorPopup.Show(new Point(this.Size.Width + this.Location.X, this.Location.Y + this.Size.Height / 3));
}
UpdateStats();
StopTimer();
}
#endregion
private void addDropdownPopup_Opening(object sender, CancelEventArgs e)
{
addDropdownPopup.PopupControl = addMenu;
}
private void selectionDropdownPopup_Opening(object sender, CancelEventArgs e)
{
selectionDropdownPopup.PopupControl = selectionMenu;
}
private void quitButton_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Oh, leaving already?", "Abandon ship!", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
Application.Exit();
}
}
private void selectionDropdown_Click(object sender, EventArgs e)
{
fileList.SelectedItems.Clear();
}
private void openCue_Click(object sender, EventArgs e)
{
StartTimer();
OpenFileDialog dialog = new OpenFileDialog();
dialog.InitialDirectory = folderTree.ActiveNode.FullPath.Replace(folderTree.ActiveNode.RootNode.FullPath + "\\", "");
dialog.Filter = "CUE'sheet lists (*.cue)|*.cue|Text sheet Files (*.txt)|*.txt";
dialog.Title = "Select CUE'sheet to open";
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
CueSheet sheet = new CueSheet(dialog.FileName);
string artist = sheet.Performer;
string album = sheet.Title;
CueSharp.Track[] tracks = sheet.Tracks;
//TagLib.File tagFile = TagLib.File.Create(dialog.FileName);
//TimeSpan totalTime = new TimeSpan(tagFile.Length);
TimeSpan totalTime = new TimeSpan();
TimeSpan totalTrackTime = new TimeSpan();
int totalTracks = tracks.Length;
bool readFile = false;
try
{
TagLib.File tagFile = TagLib.File.Create(Path.GetDirectoryName(dialog.FileName) + "\\" + tracks[0].DataFile.Filename);
totalTime = tagFile.Properties.Duration;
readFile = true;
}
catch
{
}
foreach (object item in tracks)
{
try
{
CueSharp.Track track = (CueSharp.Track)item;
ArrayList subItemValues = new ArrayList();
subItemValues.Add(track.Title);
subItemValues.Add(track.Performer);
subItemValues.Add(album);
TimeSpan trackTime = new TimeSpan();
if (track.TrackNumber != totalTracks)
{
trackTime = new TimeSpan(0, tracks[track.TrackNumber].Indices[0].Minutes - track.Indices[0].Minutes, tracks[track.TrackNumber].Indices[0].Seconds - track.Indices[0].Seconds);
}
else if(readFile)
trackTime = new TimeSpan(0, totalTime.Minutes - totalTrackTime.Minutes, totalTime.Seconds - totalTrackTime.Seconds);
else trackTime = new TimeSpan(0, totalTrackTime.Minutes/totalTracks, totalTrackTime.Seconds/totalTracks);
totalTrackTime = totalTrackTime.Add(trackTime);
subItemValues.Add(trackTime.ToString());
subItemValues.Add(1);
UltraListViewItem listTrack = new UltraListViewItem("CUE'sheet item", subItemValues.ToArray());
trackList.Items.Add(listTrack);
}
catch (Exception exp)
{
//errors.Add(((UltraListViewItem)file).Value.ToString() + " : " + exp.Message.ToString());
}
}
}
catch
{
MessageBox.Show("Ook!");
}
}
UpdateStats();
StopTimer();
}
private void trackList_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (trackList.SelectedItems.Count == 1)
{
//count column (main column does not count)
trackList.SelectedItems[0].SubItems[4].Value = (int)trackList.SelectedItems[0].SubItems[4].Value + 1;
trackList.Refresh();
}
}
else if (e.Button == MouseButtons.Left)
{
if (trackList.SelectedItems.Count == 1)
{
if ((int)trackList.SelectedItems[0].SubItems[4].Value != 1)
trackList.SelectedItems[0].SubItems[4].Value = (int)trackList.SelectedItems[0].SubItems[4].Value - 1;
trackList.Refresh();
}
}
else if (e.Button == MouseButtons.Middle)
{
if (trackList.SelectedItems.Count == 1)
{
if ((int)trackList.SelectedItems[0].SubItems[4].Value != 1)
trackList.SelectedItems[0].SubItems[4].Value = 1;
trackList.Refresh();
}
}
UpdateStats();
}
private void treeFullButton_Click(object sender, EventArgs e)
{
if (folderTree.Size.Width < this.Size.Width / 3)
{
folderTree.Size = new Size(this.Size.Width - 40, this.Size.Height - 120);
treeFullButton.Location = new Point(folderTree.Location.X + folderTree.Size.Width - treeFullButton.Size.Width + 5,
treeFullButton.Location.Y);
trackList.Visible = false;
fileList.Visible = false;
labelStats.Visible = false;
dropdownPanelScrobble.Visible = false;
removeDropdown.Visible = false;
optionsButton.Visible = false;
scrobbleDropdown.Visible = false;
addDropButton.Visible = false;
openCue.Visible = false;
selectionDropdown.Visible = false;
tracksFullButton.Visible = false;
quitButton.Visible = false;
editFields.Visible = false;
editPanel.Visible = false;
}
else
{
folderTree.Size = new Size(257, this.Size.Height - 120);
treeFullButton.Location = new Point(folderTree.Location.X + folderTree.Size.Width - treeFullButton.Size.Width + 5,
treeFullButton.Location.Y);
trackList.Visible = true;
fileList.Visible = true;
labelStats.Visible = true;
dropdownPanelScrobble.Visible = true;
removeDropdown.Visible = true;
optionsButton.Visible = true;
scrobbleDropdown.Visible = true ;
addDropButton.Visible = true;
openCue.Visible = true;
selectionDropdown.Visible = true;
tracksFullButton.Visible = true;
quitButton.Visible = true;
editFields.Visible = true;
//editPanel.Visible = true;
}
Refresh();
}
private void tracksFullButton_Click(object sender, EventArgs e)
{
if (trackList.Size.Height < this.Size.Height / 2)
{
trackList.Size = new Size(trackList.Size.Width, this.Size.Height - 96);
tracksFullButton.Location = new Point(tracksFullButton.Location.X,
trackList.Location.Y + trackList.Size.Height - tracksFullButton.Size.Height + 5);