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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
|
/**
* Copyright (c) 2000-2004 Charles Samuels <[email protected]>
* 2000-2001 Neil Stevens <[email protected]>
*
* Copyright (c) from the patches of:
* 2001 Klas Kalass <[email protected]>
* 2001 Anno v. Heimburg <[email protected]>
**/
// Abandon All Hope, Ye Who Enter Here
#include <tqdragobject.h>
#include <tqheader.h>
#include <tqlayout.h>
#include <tqmap.h>
#include <tqregexp.h>
#include <tqtextstream.h>
#include <tqpainter.h>
#include <tdeaction.h>
#include <kdebug.h>
#include <tdefiledialog.h>
#include <tdefileitem.h>
#include <tdeio/job.h>
#include <tdeio/netaccess.h>
#include <tdelocale.h>
#include <tdemenubar.h>
#include <ksimpleconfig.h>
#include <kstandarddirs.h>
#include <kstdaction.h>
#include <kedittoolbar.h>
#include <kurldrag.h>
#include <tdemessagebox.h>
#include <noatun/app.h>
#include <noatun/player.h>
#include <noatun/playlistsaver.h>
#include "playlist.h"
#include "view.h"
#include "find.h"
#define SPL SplitPlaylist::SPL()
SafeListViewItem::SafeListViewItem(TQListView *parent, TQListViewItem *after, const KURL &text)
: TQCheckListItem(parent,0, TQCheckListItem::CheckBox), PlaylistItemData(), removed(false)
{
addRef();
setUrl(text);
static_cast<TDEListView*>(TQT_TQWIDGET(parent))->moveItem(this, 0, after);
setOn(true);
// is this really needed, it makes the listview too wide for me :(
// setText(0,text.filename());
// if (!isDownloaded()) setText(1, "0%");
// mProperties.setAutoDelete(true);
if (!streamable() && enqueue(url()))
setUrl(KURL(localFilename()));
PlaylistItemData::added();
}
SafeListViewItem::SafeListViewItem(TQListView *parent, TQListViewItem *after, const TQMap<TQString,TQString> &props)
: TQCheckListItem(parent, 0, TQCheckListItem::CheckBox), removed(false)
{
addRef();
setOn(true);
// A version of setProperty that assumes a key is unique,
// and doesn't call modified for every new key.
// Ugly, but this function is a very hot path on playlist loading
for (TQMap<TQString,TQString>::ConstIterator i=props.begin(); i!=props.end(); ++i )
{
TQString n = i.key();
TQString val = i.data();
if (n=="enabled")
{
setOn(val!="false" && val!="0");
}
else
{
Property p={n,val};
mProperties += p;
}
}
static_cast<TDEListView*>(TQT_TQWIDGET(parent))->moveItem(this, 0, after);
modified();
if (!streamable() && enqueue(url()))
{
KURL u;
u.setPath(localFilename());
setUrl(u);
}
PlaylistItemData::added();
}
SafeListViewItem::~SafeListViewItem()
{
remove();
}
TQString SafeListViewItem::file() const
{
return localFilename();
}
static void pad(TQString &str)
{
int len=str.length();
int at = 0;
int blocklen=0;
static const int paddingsize=12;
// not static for reason
const TQChar chars[paddingsize] =
{
TQChar('0'), TQChar('0'), TQChar('0'), TQChar('0'),
TQChar('0'), TQChar('0'), TQChar('0'), TQChar('0'),
TQChar('0'), TQChar('0'), TQChar('0'), TQChar('0')
};
for (int i=0; i < len; i++)
{
if (str[i].isNumber())
{
if (!blocklen)
at = i;
blocklen++;
}
else if (blocklen)
{
int pads=paddingsize;
pads -= blocklen;
str.insert(at, chars, pads);
i += pads;
blocklen = 0;
}
}
if (blocklen)
{
int pads=paddingsize;
pads -= blocklen;
str.insert(at, chars, pads);
}
}
int SafeListViewItem::compare(TQListViewItem * i, int col, bool) const
{
TQString text1 = text(col);
TQString text2 = i->text(col);
pad(text1);
pad(text2);
return text1.compare(text2);
}
TQString SafeListViewItem::property(const TQString &n, const TQString &def) const
{
for (TQValueList<Property>::ConstIterator i=mProperties.begin(); i != mProperties.end(); ++i)
{
if ((*i).key==n)
return (*i).value;
}
if (n=="enabled")
{
if (isOn()) return "true";
else return "false";
}
return def;
}
void SafeListViewItem::setProperty(const TQString &n, const TQString &val)
{
if (n=="enabled")
{
setOn(val!="false" && val!="0");
}
else
{
if ( property(n,"") == val )
{
// kdDebug(66666) << "SafeListViewItem::setProperty(), property unchanged!" << endl;
return;
}
clearProperty(n);
Property p={n,val};
mProperties += p;
}
modified();
}
void SafeListViewItem::clearProperty(const TQString &n)
{
if (n=="enabled")
{
setOn(true);
modified();
return;
}
for (TQValueList<Property>::Iterator i=mProperties.begin(); i != mProperties.end(); ++i)
{
if ((*i).key==n)
{
mProperties.remove(i);
modified();
break;
}
}
}
TQStringList SafeListViewItem::properties() const
{
TQStringList list;
for (TQValueList<Property>::ConstIterator i=mProperties.begin(); i != mProperties.end(); ++i)
list += (*i).key;
list += "enabled";
return list;
}
bool SafeListViewItem::isProperty(const TQString &n) const
{
for (TQValueList<Property>::ConstIterator i=mProperties.begin(); i != mProperties.end(); ++i)
{
if ((*i).key==n)
return true;
}
return n=="enabled";
}
void SafeListViewItem::downloaded(int percent)
{
if (!removed)
setText(1, TQString::number(percent)+'%');
}
void SafeListViewItem::downloadTimeout()
{
if (!removed)
setText(1, "-");
}
void SafeListViewItem::downloadFinished()
{
if (!removed)
setText(1, "");
}
void SafeListViewItem::modified()
{
bool widthChangeNeeded = false;
if (text(0)!=title())
{
setText(0, title());
widthChangeNeeded = true;
}
if (isDownloaded() && length()!=-1 && text(1)!=lengthString())
{
setText(1, lengthString());
widthChangeNeeded = true;
}
if (widthChangeNeeded)
widthChanged(-1);
PlaylistItemData::modified();
}
void SafeListViewItem::stateChange(bool s)
{
// if you uncheck this, uncheck thet others that
// are selected too
TQPtrList<TQListViewItem> list=SPL->view->listView()->selectedItems();
// but not if I'm not selected
if (list.containsRef(this))
for (TQListViewItem *i=list.first(); i != 0; i=list.next())
static_cast<TQCheckListItem*>(i)->setOn(s);
else
TQCheckListItem::stateChange(s);
}
void SafeListViewItem::paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int align)
{
TQCheckListItem::paintCell(p, cg, column, width, align);
if (SPL->current() == this)
{
p->save();
p->setRasterOp(XorROP);
p->fillRect(0, 0, width, height(), TQColor(255,255,255));
p->restore();
}
}
void SafeListViewItem::remove()
{
removed=true;
if (napp->player()->current()==this && !itemAbove() && !itemBelow())
{
napp->player()->stop();
SPL->setCurrent(0);
}
else if (napp->player()->current()==this)
{
// SPL->setCurrent(0);
// napp->player()->playCurrent();
if (napp->player()->isPlaying() && !SPL->exiting())
napp->player()->forward();
else
SPL->setCurrent(0);
}
if (listView())
{
if (SPL->currentItem==this) // just optimizing for least unreadably
SPL->setCurrent(static_cast<SafeListViewItem*>(itemBelow()));
listView()->takeItem(this);
}
else if (SPL->currentItem==this)
{
SPL->setCurrent(0);
}
dequeue();
PlaylistItemData::removed();
}
List::List(View *parent)
: TDEListView(parent), recursiveAddAfter(0), listJob(0)
{
addColumn(i18n("File"));
addColumn(i18n("Time"));
setAcceptDrops(true);
setSorting(-1);
setDropVisualizer(true);
setDragEnabled(true);
setItemsMovable(true);
setSelectionMode(TQListView::Extended);
connect(TQT_TQOBJECT(this), TQT_SIGNAL(dropped(TQDropEvent*, TQListViewItem*)), TQT_SLOT(dropEvent(TQDropEvent*, TQListViewItem*)));
connect(TQT_TQOBJECT(this), TQT_SIGNAL(moved()), TQT_SLOT(move()));
connect(TQT_TQOBJECT(this), TQT_SIGNAL(aboutToMove()), parent, TQT_SLOT(setNoSorting()));
connect(TQT_TQOBJECT(this), TQT_SIGNAL(deleteCurrentItem()), parent, TQT_SLOT(deleteSelected()));
}
List::~List()
{
}
void List::move()
{
emit modified();
}
bool List::acceptDrag(TQDropEvent *event) const
{
return KURLDrag::canDecode(event) || TDEListView::acceptDrag(event);
}
void List::dropEvent(TQDropEvent *event, TQListViewItem *after)
{
static_cast<View*>(TQT_TQWIDGET(parent()))->setNoSorting();
KURL::List textlist;
if (!KURLDrag::decode(event, textlist)) return;
event->acceptAction();
for (KURL::List::Iterator i=textlist.begin(); i != textlist.end(); ++i)
{
after= addFile(*i, false, after);
}
emit modified();
}
void List::keyPressEvent(TQKeyEvent *e)
{
if (e->key()==Key_Enter || e->key()==Key_Return)
{
if (currentItem())
{
emit TDEListView::executed(currentItem());
}
return;
}
if (e->key()==Key_Delete)
{
if (currentItem())
{
emit deleteCurrentItem();
}
return;
}
TDEListView::keyPressEvent(e);
}
/**
* use this only once!!!
**/
class NoatunSaver : public PlaylistSaver
{
List *mList;
SafeListViewItem *after, *mFirst;
public:
NoatunSaver(List *l, TQListViewItem *after=0)
: mList(l)
{
this->after = static_cast<SafeListViewItem*>(after);
mFirst = 0;
}
TQListViewItem *getAfter() { return after; }
TQListViewItem *getFirst() { return mFirst; }
protected:
virtual void readItem(const TQMap<TQString,TQString> &properties)
{
after = new SafeListViewItem(mList, after, properties);
if (mFirst==0)
mFirst = after;
}
virtual PlaylistItem writeItem()
{
if (!after)
{
after=static_cast<SafeListViewItem*>(mList->firstChild());
}
else
{
after=static_cast<SafeListViewItem*>(static_cast<SafeListViewItem*>(after)->nextSibling());
}
return PlaylistItem(after);
}
};
bool View::saveToURL(const KURL &url)
{
NoatunSaver saver(list);
if(saver.save(url))
{
return true;
}
else
{
KMessageBox::error( this, i18n("Could not write to %1.").arg(url.prettyURL()) );
return false;
}
}
void View::exportTo(const KURL &url)
{
TQString local(napp->tempSaveName(url.path()));
TQFile saver(local);
saver.open(IO_ReadWrite | IO_Truncate);
TQTextStream t(&saver);
// navigate the list
for (SafeListViewItem *i=static_cast<SafeListViewItem*>(listView()->firstChild());
i != 0; i=static_cast<SafeListViewItem*>(i->itemBelow()))
{
KURL u=i->url();
if (u.isLocalFile())
t<< u.path() << '\n';
else
t << u.url() << '\n';
}
saver.close();
TDEIO::NetAccess::upload(local, url, this);
saver.remove();
}
TQListViewItem *List::openGlobal(const KURL &u, TQListViewItem *after)
{
clear();
NoatunSaver saver(this, after);
saver.metalist(u);
return saver.getAfter();
}
// for m3u files
TQListViewItem *List::importGlobal(const KURL &u, TQListViewItem *after)
{
NoatunSaver saver(this, after);
if (!saver.metalist(u))
{
after=new SafeListViewItem(this, after, u);
// SPL->listItemSelected(after);
return after;
}
// return the first item added from this playlist
// that way noatun can start playing the first item
if (saver.getFirst())
return saver.getFirst();
// failsafe in case nothing was added, getFirst() may return 0
return saver.getAfter();
}
TQListViewItem *List::addFile(const KURL& url, bool play, TQListViewItem *after)
{
// when a new item is added, we don't want to sort anymore
SPL->view->setNoSorting();
if (
url.path().right(4).lower()==".m3u"
|| url.path().right(4).lower()==".pls"
|| url.protocol().lower()=="http"
)
{
// a playlist is requested
TQListViewItem *i = importGlobal(url, after);
if (play)
SPL->listItemSelected(i);
return i;
}
else
{
if (!after) after=lastItem();
KFileItem fileItem(KFileItem::Unknown,KFileItem::Unknown,url);
if (fileItem.isDir())
{
addDirectoryRecursive(url, after);
return after; // don't (and can't) know better!?
}
else
{
TQListViewItem *i = new SafeListViewItem(this, after, url);
if (play)
SPL->listItemSelected(i);
return i;
}
}
}
// starts a new listJob if there is no active but work to do
void List::addNextPendingDirectory()
{
KURL::List::Iterator pendingIt= pendingAddDirectories.begin();
if (!listJob && (pendingIt!= pendingAddDirectories.end()))
{
currentJobURL= *pendingIt;
listJob= TDEIO::listRecursive(currentJobURL, false,false);
connect(
listJob, TQT_SIGNAL(entries(TDEIO::Job*, const TDEIO::UDSEntryList&)),
TQT_SLOT(slotEntries(TDEIO::Job*, const TDEIO::UDSEntryList&))
);
connect(
listJob, TQT_SIGNAL(result(TDEIO::Job *)),
TQT_SLOT(slotResult(TDEIO::Job *))
);
connect(
listJob, TQT_SIGNAL(redirection(TDEIO::Job *, const KURL &)),
TQT_SLOT(slotRedirection(TDEIO::Job *, const KURL &))
);
pendingAddDirectories.remove(pendingIt);
}
}
void List::addDirectoryRecursive(const KURL &dir, TQListViewItem *after)
{
if (!after) after=lastItem();
recursiveAddAfter= after;
pendingAddDirectories.append(dir);
addNextPendingDirectory();
}
void List::slotResult(TDEIO::Job *job)
{
listJob= 0;
if (job && job->error())
job->showErrorDialog();
addNextPendingDirectory();
}
void List::slotEntries(TDEIO::Job *, const TDEIO::UDSEntryList &entries)
{
TQMap<TQString,KURL> __list; // temp list to sort entries
TDEIO::UDSEntryListConstIterator it = entries.begin();
TDEIO::UDSEntryListConstIterator end = entries.end();
for (; it != end; ++it)
{
KFileItem file(*it, currentJobURL, false /* no mimetype detection */, true);
// "prudhomm:
// insert the path + url in the map to sort automatically by path
// note also that you use audiocd to rip your CDs then it will be sorted the right way
// now it is an easy fix to have a nice sort BUT it is not the best
// we should sort based on the tracknumber"
// - copied over from old kdirlister hack <[email protected]>
if (!file.isDir())
__list.insert(file.url().path(), file.url());
}
TQMap<TQString,KURL>::Iterator __it;
for( __it = __list.begin(); __it != __list.end(); ++__it )
{
recursiveAddAfter= addFile(__it.data(), false, recursiveAddAfter);
}
}
void List::slotRedirection(TDEIO::Job *, const KURL & url)
{
currentJobURL= url;
}
/////////////////////////////////
View::View(SplitPlaylist *)
: TDEMainWindow(0, "NoatunSplitplaylistView")
{
list=new List(this);
setCentralWidget(list);
connect(list, TQT_SIGNAL(modified(void)), TQT_TQOBJECT(this), TQT_SLOT(setModified(void)) );
// connect the click on the header with sorting
connect(list->header(),TQT_SIGNAL(clicked(int)),this,TQT_SLOT(headerClicked(int)) );
mOpen=new TDEAction(i18n("Add &Files..."), "queue", 0, TQT_TQOBJECT(this), TQT_SLOT(addFiles()), actionCollection(), "add_files");
(void) new TDEAction(i18n("Add Fol&ders..."), "folder", 0, TQT_TQOBJECT(this), TQT_SLOT(addDirectory()), actionCollection(), "add_dir");
mDelete=new TDEAction(i18n("Delete"), "edit-delete", Key_Delete, TQT_TQOBJECT(this), TQT_SLOT(deleteSelected()), actionCollection(), "delete");
mClose=KStdAction::close(TQT_TQOBJECT(this), TQT_SLOT(close()), actionCollection());
mFind=KStdAction::find(TQT_TQOBJECT(this), TQT_SLOT(find()), actionCollection());
(void) KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(configureToolBars()), actionCollection());
mOpenNew=KStdAction::openNew(TQT_TQOBJECT(this), TQT_SLOT(openNew()), actionCollection());
mOpenpl=KStdAction::open(TQT_TQOBJECT(this), TQT_SLOT(open()), actionCollection());
mSave=KStdAction::save(TQT_TQOBJECT(this), TQT_SLOT(save()), actionCollection());
mSaveAs=KStdAction::saveAs(TQT_TQOBJECT(this), TQT_SLOT(saveAs()), actionCollection());
(void) new TDEAction(i18n("Shuffle"), "misc", 0, TQT_TQOBJECT(SPL), TQT_SLOT( randomize() ), actionCollection(), "shuffle");
(void) new TDEAction(i18n("Clear"), "edit-clear", 0, TQT_TQOBJECT(list), TQT_SLOT( clear() ), actionCollection(), "clear");
createGUI("splui.rc");
mFinder = new Finder(this);
applyMainWindowSettings(TDEGlobal::config(), "SPL Window");
list->setFocus();
}
void View::find()
{
mFinder->show();
connect(mFinder, TQT_SIGNAL(search(Finder*)), TQT_SLOT(findIt(Finder*)));
}
static bool testWord(TQListViewItem *i, const TQString &finder)
{
PlaylistItemData *item=static_cast<SafeListViewItem*>(i);
if (item->title().find(finder, 0, false) >=0)
return true;
if (item->file().find(finder, 0, false) >=0)
return true;
if (item->url().path().find(finder.local8Bit().data(), 0, false) >=0)
return true;
if (item->lengthString().find(finder, 0, false) >=0)
return true;
if (item->mimetype().find(finder.local8Bit().data(), 0, false) >=0)
return true;
return false;
}
static bool testWord(TQListViewItem *i, const TQRegExp &finder)
{
PlaylistItemData *item=static_cast<SafeListViewItem*>(i);
if (item->title().find(finder) >=0)
return true;
if (item->file().find(finder) >=0)
return true;
if (item->url().path().find(finder) >=0)
return true;
if (item->lengthString().find(finder) >=0)
return true;
if (item->mimetype().find(finder) >=0)
return true;
return false;
}
void View::findIt(Finder *f)
{
TQListViewItem *search=list->currentItem();
if (list->currentItem())
{
if (f->isForward())
search=list->currentItem()->itemBelow();
else
search=list->currentItem()->itemAbove();
}
else
{
if (f->isForward())
search=list->firstChild();
else
search=list->lastChild();
}
while (search)
{
if (f->regexp())
{
if (testWord(search, TQRegExp(f->string(), false)))
break;
}
else
{
if (testWord(search, f->string()))
break;
}
if (f->isForward())
search=search->itemBelow();
else
search=search->itemAbove();
if (!search)
{
if (f->isForward())
{
if (KMessageBox::questionYesNo(this, i18n("End of playlist reached. Continue searching from beginning?"),TQString(),KStdGuiItem::cont(),KStdGuiItem::cancel()) == KMessageBox::Yes)
search=list->firstChild();
}
else
{
if (KMessageBox::questionYesNo(this, i18n("Beginning of playlist reached. Continue searching from end?"),TQString(),KStdGuiItem::cont(),KStdGuiItem::cancel()) == KMessageBox::Yes)
search=list->lastChild();
}
}
}
if (search)
{
{ // select none
TQPtrList<TQListViewItem> sel=list->selectedItems();
for (TQListViewItem *i=sel.first(); i!=0; i=sel.next())
list->setSelected(i, false);
}
list->setSelected(search, true);
list->setCurrentItem(search);
list->ensureItemVisible(search);
}
}
View::~View()
{
napp->player()->stop();
hide();
saveState();
delete list;
}
void View::init()
{
// see if we are importing an old-style list
bool importing= ! TQFile(napp->dirs()->saveLocation("data", "noatun/") + "splitplaylist.xml").exists();
if (importing)
{
KURL internalURL;
internalURL.setPath(napp->dirs()->saveLocation("data", "noatun/") + "splitplaylistdata");
NoatunSaver saver(list, 0);
saver.load(internalURL, PlaylistSaver::M3U);
}
else
{
KURL internalURL;
internalURL.setPath(napp->dirs()->saveLocation("data", "noatun/") + "splitplaylist.xml");
list->openGlobal(internalURL);
}
for(PlaylistItem item = SPL->getFirst(); item; item = SPL->getAfter(item))
if(item.url().path().isEmpty()) item.remove();
TDEConfig &config = *TDEGlobal::config();
config.setGroup("splitplaylist");
// this has to come after openGlobal, since openGlobal emits modified()
setModified(config.readBoolEntry("modified", false));
TQString path = config.readPathEntry("file");
// don't call setPath with an empty path, that would make the url "valid"
if ( !path.isEmpty() )
mPlaylistFile.setPath(path);
SPL->reset();
int saved = config.readNumEntry("current", 0);
PlaylistItem item=SPL->getFirst();
for(int i = 0 ; i < saved ; i++)
{
item=SPL->getAfter(item);
}
if (item)
SPL->setCurrent(item);
}
void View::save()
{
if(mPlaylistFile.isEmpty() || !mPlaylistFile.isValid())
{
saveAs();
return;
}
if(saveToURL(mPlaylistFile))
setModified(false);
}
void View::saveAs()
{
KURL u=KFileDialog::getSaveURL(0, "*.xml splitplaylistdata *.pls *.m3u\n*", this, i18n("Save Playlist"));
if(!u.isValid())
return;
mPlaylistFile = u;
save();
}
void View::open()
{
KURL u=KFileDialog::getOpenURL(0, "*.xml splitplaylistdata *.pls *.m3u\n*", this, i18n("Open Playlist"));
if(!u.isValid())
return;
mPlaylistFile = u;
list->openGlobal(u);
setModified(false);
}
void View::openNew()
{
mPlaylistFile = "";
listView()->clear();
}
void List::clear()
{
SPL->setCurrent(0);
TQListView::clear();
}
void View::deleteSelected()
{
TQPtrList<TQListViewItem> items(list->selectedItems());
bool stopped=false;
// noatun shouldn't play files for now
TQListViewItem *afterLast=0;
for (TQPtrListIterator<TQListViewItem> it(items); it.current(); ++it)
{
SafeListViewItem *i = static_cast<SafeListViewItem*>(*it);
if (!stopped && SPL->current() == i)
{
napp->player()->stop();
SPL->setCurrent(0);
stopped = true;
}
i->remove();
afterLast = i->itemBelow();
}
if (stopped)
SPL->setCurrent(static_cast<SafeListViewItem*>(afterLast));
setModified(true);
}
void View::addFiles()
{
KURL::List files=KFileDialog::getOpenURLs(":mediadir", napp->mimeTypes(), this, i18n("Select File to Play"));
TQListViewItem *last = list->lastItem();
for(KURL::List::Iterator it=files.begin(); it!=files.end(); ++it)
last = addFile(KURL(*it), false);
setModified(true);
}
void View::addDirectory()
{
TQString file=KFileDialog::getExistingDirectory(0, this, i18n("Select Folder"));
if (!file) return;
KURL url;
url.setPath(file);
list->addDirectoryRecursive(url);
setModified(true);
}
void View::closeEvent(TQCloseEvent*)
{
hide();
}
void View::showEvent(TQShowEvent *)
{
emit shown();
}
void View::hideEvent(TQHideEvent *)
{
emit hidden();
}
void View::setModified(bool b)
{
modified = b;
setCaption(i18n("Playlist"), modified);
}
void View::setModified(void)
{
setModified(true);
}
void View::saveState(void)
{
TDEConfig &config = *TDEGlobal::config();
config.setGroup("splitplaylist");
config.writeEntry("modified", modified);
config.writePathEntry("file", mPlaylistFile.path());
saveToURL(napp->dirs()->saveLocation("data", "noatun/") + "splitplaylist.xml");
unsigned int i;
PlaylistItem item=SPL->getFirst();
for(i = 0; item && item != SPL->current(); )
item=SPL->getAfter(item), i++;
config.writeEntry("current", i);
saveMainWindowSettings(TDEGlobal::config(), "SPL Window");
config.sync();
}
void View::configureToolBars()
{
saveMainWindowSettings(TDEGlobal::config(), "SPL Window");
KEditToolbar dlg(actionCollection(), "splui.rc");
connect(&dlg, TQT_SIGNAL(newToolbarConfig()), TQT_SLOT(newToolBarConfig()));
dlg.exec();
}
void View::newToolBarConfig()
{
createGUI("splui.rc");
applyMainWindowSettings(TDEGlobal::config(), "SPL Window");
}
// turns the sorting on or off
void View::setSorting(bool on, int column)
{
if (on)
{
list->setSorting(column,true);
list->setShowSortIndicator(true);
}
else
{
list->setShowSortIndicator(false);
list->setSorting(-1);
}
}
void View::headerClicked(int column)
{
// this is to avoid that if we already have it sorted,
// we sort it again ascendingly this way, clicking on
// the header a second time will correctly toggle
// ascending/descending sort
if (list->showSortIndicator())
{
return;
}
else
{
setSorting(true,column);
}
}
#include "view.moc"
|