-rw-r--r-- | core/launcher/launcherview.cpp | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/playlistwidget.cpp | 10 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/playlistwidget.cpp | 11 |
3 files changed, 15 insertions, 8 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index 0ced256..c54a00f 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp @@ -216,418 +216,418 @@ public: enum SortMethod { Name, Date, Type }; void setSortMethod( SortMethod m ) { if ( sortmeth != m ) { sortmeth = m; sort(); } } int compare(const AppLnk* a, const AppLnk* b) { switch (sortmeth) { case Name: return a->name().compare(b->name()); case Date: { QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); return fa.lastModified().secsTo(fb.lastModified()); } case Type: return a->type().compare(b->type()); } return 0; } protected: void styleChange( QStyle &old ) { QIconView::styleChange( old ); //### duplicated code from LauncherView constructor int dw = QApplication::desktop()->width(); setGridX( (dw-13-style().scrollBarExtent().width())/ (dw/80) ); // tweaked for 8pt+dw=176 and 10pt+dw=240 } private: QList<AppLnk> hidden; QDict<void> mimes; QDict<void> cats; SortMethod sortmeth; QRegExp tf; int cf; QIconViewItem* bsy; bool ike; }; bool LauncherView::bsy=FALSE; void LauncherView::setBusy(bool on) { icons->setBusy(on); } class LauncherItem : public QIconViewItem { public: LauncherItem( QIconView *parent, AppLnk* applnk ); ~LauncherItem() { LauncherIconView* liv = (LauncherIconView*)iconView(); if ( liv->busyItem() == this ) liv->setBusy(FALSE); delete app; } AppLnk* appLnk() const { return app; } AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; } virtual int compare ( QIconViewItem * i ) const; void paintItem( QPainter *p, const QColorGroup &cg ) { LauncherIconView* liv = (LauncherIconView*)iconView(); QBrush oldBrush( liv->itemTextBackground() ); QColorGroup mycg( cg ); if ( liv->currentItem() == this ) { liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); } else { mycg.setColor( QColorGroup::Text, liv->iconText ); } QIconViewItem::paintItem(p,mycg); if ( liv->currentItem() == this ) liv->setItemTextBackground( oldBrush ); if ( liv->busyItem() == this ) { static QPixmap* busypm=0; if ( !busypm ) busypm = new QPixmap(Resource::loadPixmap("launching")); p->drawPixmap(x()+(width()-busypm->width())/2, y(),*busypm); } } protected: AppLnk* app; }; LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk ) : QIconViewItem( parent, applnk->name(), applnk->bigPixmap() ), app(applnk) // Takes ownership { } int LauncherItem::compare ( QIconViewItem * i ) const { LauncherIconView* view = (LauncherIconView*)iconView(); return view->compare(app,((LauncherItem *)i)->appLnk()); } QStringList LauncherIconView::mimeTypes() const { QStringList r; QDictIterator<void> it(mimes); while (it.current()) { r.append(it.currentKey()); ++it; } r.sort(); return r; } void LauncherIconView::addItem(AppLnk* app, bool resort) { addCatsAndMimes(app); if ( (tf.isEmpty() || tf.match(app->type()) >= 0) && (cf == 0 || app->categories().contains(cf) || cf == -1 && app->categories().count() == 0 ) ) (void) new LauncherItem( this, app ); else hidden.append(app); if ( resort ) sort(); } void LauncherIconView::updateCategoriesAndMimeTypes() { mimes.clear(); cats.clear(); LauncherItem* item = (LauncherItem*)firstItem(); while (item) { addCatsAndMimes(item->appLnk()); item = (LauncherItem*)item->nextItem(); } QListIterator<AppLnk> it(hidden); AppLnk* l; while ((l=it.current())) { addCatsAndMimes(l); ++it; } } void LauncherIconView::hideOrShowItems(bool resort) { hidden.setAutoDelete(FALSE); QList<AppLnk> links=hidden; hidden.clear(); hidden.setAutoDelete(TRUE); LauncherItem* item = (LauncherItem*)firstItem(); while (item) { links.append(item->takeAppLnk()); item = (LauncherItem*)item->nextItem(); } bool oldAutoArrange = autoArrange(); setAutoArrange( FALSE ); clear(); QListIterator<AppLnk> it(links); AppLnk* l; while ((l=it.current())) { addItem(l,FALSE); ++it; } if ( resort ) sort(); setAutoArrange( oldAutoArrange ); } bool LauncherIconView::removeLink(const QString& linkfile) { LauncherItem* item = (LauncherItem*)firstItem(); AppLnk* l; bool did = FALSE; DocLnk dl(linkfile); while (item) { l = item->appLnk(); if ( l->linkFileKnown() && l->linkFile() == linkfile/* || l->file() == linkfile || dl.isValid() && dl.file() == l->file()*/ ) { delete item; did = TRUE; } item = (LauncherItem*)item->nextItem(); } QListIterator<AppLnk> it(hidden); while ((l=it.current())) { ++it; if ( l->linkFileKnown() && l->linkFile() == linkfile/* || l->file() == linkfile || dl.isValid() && dl.file() == l->file()*/ ) { hidden.removeRef(l); did = TRUE; } } return did; } LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) : QVBox( parent, name, fl ) { icons = new LauncherIconView( this ); setFocusProxy(icons); QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); int dw = QApplication::desktop()->width(); icons->setItemsMovable( FALSE ); icons->setAutoArrange( TRUE ); icons->setSorting( TRUE ); icons->setGridX( (dw-13-style().scrollBarExtent().width())/ (dw/80) ); // tweaked for 8pt+dw=176 and 10pt+dw=240 icons->setGridY( fontMetrics().height()*2+24 ); icons->setFrameStyle( QFrame::NoFrame ); icons->setSpacing( 4 ); icons->setMargin( 0 ); icons->setSelectionMode( QIconView::Multi ); icons->setBackgroundMode( PaletteBase ); connect( icons, SIGNAL(mouseButtonClicked(int, QIconViewItem *, const QPoint&)), SLOT(itemClicked(int, QIconViewItem *)) ); connect( icons, SIGNAL(selectionChanged()), SLOT(selectionChanged()) ); connect( icons, SIGNAL(returnPressed(QIconViewItem *)), SLOT(returnPressed(QIconViewItem *)) ); connect( icons, SIGNAL(mouseButtonPressed(int, QIconViewItem *, const QPoint&)), SLOT(itemPressed(int, QIconViewItem *)) ); tools = 0; } LauncherView::~LauncherView() { } void LauncherView::setToolsEnabled(bool y) { if ( !y != !tools ) { if ( y ) { tools = new QHBox(this); // Type filter typemb = new MenuButton(tools); typemb->setLabel(tr("Type: %1")); typemb->setFixedHeight ( 20 ); // Category filter catmb = new CategorySelect(tools); catmb->setFixedHeight ( 20 ); updateTools(); tools->show(); } else { delete tools; tools = 0; } } } void LauncherView::updateTools() { disconnect( typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&)) ); disconnect( catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int)) ); icons->updateCategoriesAndMimeTypes(); QString prev; // Type filter QStringList types; types << tr("All"); types << "--"; types += icons->mimeTypes(); prev = typemb->currentText(); typemb->clear(); typemb->insertItems(types); typemb->select(prev); Categories cats( 0 ); cats.load( categoryFileName() ); QArray<int> vl( 0 ); catmb->setCategories( vl, "Document View", tr("Document View") ); catmb->setRemoveCategoryEdit( TRUE ); catmb->setAllCategories( TRUE ); connect(typemb, SIGNAL(selected(const QString&)), this, SLOT(showType(const QString&))); connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); } void LauncherView::sortBy(int s) { icons->setSortMethod((LauncherIconView::SortMethod)s); } void LauncherView::showType(const QString& t) { if ( t == tr("All") ) { icons->setTypeFilter("",TRUE); } else { icons->setTypeFilter(t+"/*",TRUE); } } void LauncherView::showCategory( int c ) { icons->setCategoryFilter( c, TRUE ); } void LauncherView::resizeEvent(QResizeEvent *e) { QVBox::resizeEvent( e ); if ( e->size().width() != e->oldSize().width() ) sort(); } void LauncherView::populate( AppLnkSet *folder, const QString& typefilter ) { icons->clear(); internalPopulate( folder, typefilter ); } void LauncherView::selectionChanged() { QIconViewItem* item = icons->currentItem(); if ( item && item->isSelected() ) { AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); if ( icons->inKeyEvent() ) // not for mouse press emit clicked( appLnk ); item->setSelected(FALSE); } } void LauncherView::returnPressed( QIconViewItem *item ) { if ( item ) { AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); emit clicked( appLnk ); } } void LauncherView::itemClicked( int btn, QIconViewItem *item ) { if ( item ) { AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); if ( btn == LeftButton ) { // Make sure it's the item we execute that gets highlighted icons->setCurrentItem( item ); emit clicked( appLnk ); } item->setSelected(FALSE); } } void LauncherView::itemPressed( int btn, QIconViewItem *item ) { if ( item ) { AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); if ( btn == RightButton ) emit rightPressed( appLnk ); /* else if ( btn == LeftButton ) emit clicked( appLnk ); */ item->setSelected(FALSE); } } void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilter ) { QListIterator<AppLnk> it( folder->children() ); icons->setTypeFilter(typefilter,FALSE); while ( it.current() ) { // show only the icons for existing files - if (!QFile(it.current()->file()).exists() ) + if (!QFile(it.current()->file()).exists() & it.current()->file().left(4) != "http") { //maybe insert some .desktop file deletion code later //maybe dir specific } else { icons->addItem(*it,FALSE); } ++it; } icons->sort(); } bool LauncherView::removeLink(const QString& linkfile) { return icons->removeLink(linkfile); } void LauncherView::sort() { icons->sort(); } void LauncherView::addItem(AppLnk* app, bool resort) { icons->addItem(app,resort); } void LauncherView::setFileSystems(const QList<FileSystem> &) { // ### does nothing now... } diff --git a/core/multimedia/opieplayer/playlistwidget.cpp b/core/multimedia/opieplayer/playlistwidget.cpp index 65dc5fb..8d66407 100644 --- a/core/multimedia/opieplayer/playlistwidget.cpp +++ b/core/multimedia/opieplayer/playlistwidget.cpp @@ -649,709 +649,713 @@ void PlayListWidget::saveList() { Config cfg( filename +".playlist"); writeConfig( cfg ); DocLnk lnk; // lnk.setComment( ""); lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D lnk.setIcon("opieplayer/playlist2"); lnk.setName( filename); //sets file name // qDebug(filename); if(!lnk.writeLink()) qDebug("Writing doclink did not work"); } Config config( "OpiePlayer" ); config.writeEntry("CurrentPlaylist",filename); setCaption(tr("OpiePlayer: ")+filename); d->selectedFiles->first(); if(fileDlg) delete fileDlg; } void PlayListWidget::loadList( const DocLnk & lnk) { QString name= lnk.name(); // qDebug("currentList is "+name); if( name.length()>1) { setCaption("OpiePlayer: "+name); // qDebug("load list "+ name+".playlist"); clearList(); Config cfg( name+".playlist"); readConfig(cfg); tabWidget->setCurrentPage(0); Config config( "OpiePlayer" ); config.writeEntry("CurrentPlaylist", name); // d->selectedFiles->first(); } } void PlayListWidget::setPlaylist( bool shown ) { if ( shown ) d->playListFrame->show(); else d->playListFrame->hide(); } void PlayListWidget::setView( char view ) { if ( view == 'l' ) showMaximized(); else hide(); } void PlayListWidget::addSelected() { Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); switch (tabWidget->currentPageIndex()) { case 0: //playlist break; case 1: { //audio // QString entryName; // entryName.sprintf( "File%i", i + 1 ); // QString linkFile = cfg.readEntry( entryName ); QListViewItemIterator it( audioView ); // iterate through all items of the listview for ( ; it.current(); ++it ) { if ( it.current()->isSelected() ) { QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) { if( dit.current()->name() == it.current()->text(0) ) { d->selectedFiles->addToSelection( **dit ); } } audioView->setSelected( it.current(),FALSE); } } tabWidget->setCurrentPage(0); } break; case 2: { // video QListViewItemIterator it( videoView ); // iterate through all items of the listview for ( ; it.current(); ++it ) { if ( it.current()->isSelected() ) { QListIterator<DocLnk> dit( vFiles.children() ); for ( ; dit.current(); ++dit ) { if( dit.current()->name() == it.current()->text(0) ) { d->selectedFiles->addToSelection( **dit ); } } videoView->setSelected( it.current(),FALSE); } } // for ( int i = 0; i < noOfFiles; i++ ) { // QString entryName; // entryName.sprintf( "File%i", i + 1 ); // QString linkFile = cfg.readEntry( entryName ); // if( DocLnk( linkFile).name() == videoView->selectedItem()->text(0) ) { // int result= QMessageBox::warning(this,tr("OpiePlayer"), // tr("This is all ready in your playlist.\nContinue?"), // tr("Yes"),tr("No"),0,0,1); // if (result !=0) // return; // } // } // addToSelection( videoView->selectedItem() ); tabWidget->setCurrentPage(0); } break; }; } void PlayListWidget::removeSelected() { d->selectedFiles->removeSelected( ); } void PlayListWidget::playIt( QListViewItem *it) { // d->setDocumentUsed = FALSE; // mediaPlayerState->curPosition =0; qDebug("playIt"); mediaPlayerState->setPlaying(FALSE); mediaPlayerState->setPlaying(TRUE); d->selectedFiles->unSelect(); } void PlayListWidget::addToSelection( QListViewItem *it) { d->setDocumentUsed = FALSE; if(it) { switch (tabWidget->currentPageIndex()) { case 1: { QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) { if( dit.current()->name() == it->text(0)) { d->selectedFiles->addToSelection( **dit ); } } } break; case 2: { QListIterator<DocLnk> dit( vFiles.children() ); for ( ; dit.current(); ++dit ) { if( dit.current()->name() == it->text(0)) { d->selectedFiles->addToSelection( **dit ); } } } break; case 0: break; }; tabWidget->setCurrentPage(0); } } void PlayListWidget::tabChanged(QWidget *widg) { switch ( tabWidget->currentPageIndex()) { case 0: { if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(TRUE); d->tbAddToList->setEnabled(FALSE); } break; case 1: { audioView->clear(); populateAudioView(); if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case 2: { videoView->clear(); populateVideoView(); if( !tbDeletePlaylist->isHidden()) tbDeletePlaylist->hide(); d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case 3: { if( tbDeletePlaylist->isHidden()) tbDeletePlaylist->show(); playLists->reread(); } break; }; } void PlayListWidget::btnPlay(bool b) { // mediaPlayerState->setPlaying(b); switch ( tabWidget->currentPageIndex()) { case 0: { // if( d->selectedFiles->current()->file().find(" ",0,TRUE) != -1 // if( d->selectedFiles->current()->file().find("%20",0,TRUE) != -1) { // QMessageBox::message("Note","You are trying to play\na malformed url."); // } else { mediaPlayerState->setPlaying(b); // } } break; case 1: { addToSelection( audioView->currentItem() ); mediaPlayerState->setPlaying(b); d->selectedFiles->removeSelected( ); tabWidget->setCurrentPage(1); d->selectedFiles->unSelect(); insanityBool=FALSE; }// audioView->clearSelection(); break; case 2: { addToSelection( videoView->currentItem() ); mediaPlayerState->setPlaying(b); qApp->processEvents(); d->selectedFiles->removeSelected( ); tabWidget->setCurrentPage(2); d->selectedFiles->unSelect(); insanityBool=FALSE; }// videoView->clearSelection(); break; }; } void PlayListWidget::deletePlaylist() { switch( QMessageBox::information( this, (tr("Remove Playlist?")), (tr("You really want to delete\nthis playlist?")), (tr("Yes")), (tr("No")), 0 )){ case 0: // Yes clicked, QFile().remove(playLists->selected()->file()); QFile().remove(playLists->selected()->linkFile()); playLists->reread(); break; case 1: // Cancel break; }; } void PlayListWidget::viewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) { switch (mouse) { case 1: break; case 2:{ QPopupMenu m; m.insertItem( tr( "Play" ), this, SLOT( playSelected() )); m.insertItem( tr( "Add to Playlist" ), this, SLOT( addSelected() )); m.insertSeparator(); if( QFile(QPEApplication::qpeDir()+"lib/libopie.so").exists() ) m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); m.exec( QCursor::pos() ); } break; }; } void PlayListWidget::playSelected() { btnPlay( TRUE); // d->selectedFiles->unSelect(); } void PlayListWidget::playlistViewPressed( int mouse, QListViewItem *item, const QPoint& point, int i) { switch (mouse) { case 1: break; case 2:{ QPopupMenu m; m.insertItem( tr( "Play Selected" ), this, SLOT( playSelected() )); m.insertItem( tr( "Remove" ), this, SLOT( removeSelected() )); // m.insertSeparator(); // m.insertItem( tr( "Properties" ), this, SLOT( listDelete() )); m.exec( QCursor::pos() ); } break; }; } void PlayListWidget::listDelete() { Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); QString file; int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); switch ( tabWidget->currentPageIndex()) { case 0: break; case 1: { file = audioView->currentItem()->text(0); QListIterator<DocLnk> Pdit( files.children() ); for ( ; Pdit.current(); ++Pdit ) { if( Pdit.current()->name() == file) { LnkProperties prop( Pdit.current() ); prop.showMaximized(); prop.exec(); } } populateAudioView(); } break; case 2: { // file = videoView->selectedItem()->text(0); // for ( int i = 0; i < noOfFiles; i++ ) { // QString entryName; // entryName.sprintf( "File%i", i + 1 ); // QString linkFile = cfg.readEntry( entryName ); // AppLnk lnk( AppLnk(linkFile)); // if( lnk.name() == file ) { // LnkProperties prop( &lnk); // // connect(&prop, SIGNAL(select(const AppLnk *)), this, SLOT(externalSelected(const AppLnk *))); // prop.showMaximized(); // prop.exec(); // } // } } break; }; } void PlayListWidget::scanForAudio() { qDebug("scan for audio"); files.detachChildren(); QListIterator<DocLnk> sdit( files.children() ); for ( ; sdit.current(); ++sdit ) { delete sdit.current(); } Global::findDocuments(&files, "audio/*"); audioScan = TRUE; } void PlayListWidget::scanForVideo() { qDebug("scan for video"); vFiles.detachChildren(); QListIterator<DocLnk> sdit( vFiles.children() ); for ( ; sdit.current(); ++sdit ) { delete sdit.current(); } Global::findDocuments(&vFiles, "video/*"); videoScan = TRUE; } void PlayListWidget::populateAudioView() { audioView->clear(); StorageInfo storageInfo; const QList<FileSystem> &fs = storageInfo.fileSystems(); if(!audioScan) scanForAudio(); QListIterator<DocLnk> dit( files.children() ); QListIterator<FileSystem> it ( fs ); QString storage; for ( ; dit.current(); ++dit ) { for( ; it.current(); ++it ){ const QString name = (*it)->name(); const QString path = (*it)->path(); if(dit.current()->file().find(path) != -1 ) storage=name; } QListViewItem * newItem; - if ( QFile( dit.current()->file()).exists() ) { -// qDebug(dit.current()->name()); + if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { + long size; + if( dit.current()->file().left(4) == "http" ) + size=0; + else + size = QFile( dit.current()->file() ).size(); newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), - QString::number( QFile( dit.current()->file()).size() ), storage); + QString::number(size ), storage); newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/musicfile" )); } } } void PlayListWidget::populateVideoView() { videoView->clear(); StorageInfo storageInfo; const QList<FileSystem> &fs = storageInfo.fileSystems(); if(!videoScan ) scanForVideo(); QListIterator<DocLnk> Vdit( vFiles.children() ); QListIterator<FileSystem> it ( fs ); videoView->clear(); QString storage; for ( ; Vdit.current(); ++Vdit ) { for( ; it.current(); ++it ){ const QString name = (*it)->name(); const QString path = (*it)->path(); if( Vdit.current()->file().find(path) != -1 ) storage=name; } QListViewItem * newItem; if ( QFile( Vdit.current()->file()).exists() ) { newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file()).size() ), storage); newItem->setPixmap(0, Resource::loadPixmap( "opieplayer/videofile" )); } } } void PlayListWidget::openFile() { QString filename, name; InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { filename = fileDlg->LineEdit1->text(); // http://205.188.234.129:8030 // http://66.28.68.70:8000 // filename.replace(QRegExp("%20")," "); qDebug("Selected filename is "+filename); if(filename.right(3) == "m3u") readm3u( filename); else if(filename.right(3) == "pls") readPls( filename); else { DocLnk lnk; lnk.setName(filename); //sets file name if(filename.right(1) != "/" && filename.right(3) != "mp3" && filename.right(3) != "MP3") filename += "/"; lnk.setFile(filename); //sets File property lnk.setType("audio/x-mpegurl"); lnk.setExec("opieplayer"); lnk.setIcon("opieplayer/MPEGPlayer"); if(!lnk.writeLink()) qDebug("Writing doclink did not work"); d->selectedFiles->addToSelection( lnk); // if(fileDlg2) // delete fileDlg2; } } if(fileDlg) delete fileDlg; } void PlayListWidget::keyReleaseEvent( QKeyEvent *e) { switch ( e->key() ) { ////////////////////////////// Zaurus keys case Key_F9: //activity // if(audioUI->isHidden()) // audioUI->showMaximized(); break; case Key_F10: //contacts // if( videoUI->isHidden()) // videoUI->showMaximized(); break; case Key_F11: //menu break; case Key_F12: //home // doBlank(); break; case Key_F13: //mail // doUnblank(); break; case Key_Q: //add to playlist qDebug("Add"); addSelected(); break; case Key_R: //remove from playlist removeSelected(); break; // case Key_P: //play // qDebug("Play"); // playSelected(); // break; case Key_Space: qDebug("Play"); // playSelected(); puh break; case Key_1: tabWidget->setCurrentPage(0); break; case Key_2: tabWidget->setCurrentPage(1); break; case Key_3: tabWidget->setCurrentPage(2); break; case Key_4: tabWidget->setCurrentPage(3); break; case Key_Down: if ( !d->selectedFiles->next() ) d->selectedFiles->first(); break; case Key_Up: if ( !d->selectedFiles->prev() ) // d->selectedFiles->last(); break; } } void PlayListWidget::keyPressEvent( QKeyEvent *e) { // qDebug("Key press"); // switch ( e->key() ) { // ////////////////////////////// Zaurus keys // case Key_A: //add to playlist // qDebug("Add"); // addSelected(); // break; // case Key_R: //remove from playlist // removeSelected(); // break; // case Key_P: //play // qDebug("Play"); // playSelected(); // break; // case Key_Space: // qDebug("Play"); // playSelected(); // break; // } } void PlayListWidget::doBlank() { qDebug("do blanking"); fd=open("/dev/fb0",O_RDWR); if (fd != -1) { ioctl(fd,FBIOBLANK,1); // close(fd); } } void PlayListWidget::doUnblank() { // this crashes opieplayer with a segfault // int fd; // fd=open("/dev/fb0",O_RDWR); qDebug("do unblanking"); if (fd != -1) { ioctl(fd,FBIOBLANK,0); close(fd); } QCopEnvelope h("QPE/System", "setBacklight(int)"); h <<-3;// v[1]; // -3 Force on } void PlayListWidget::readm3u(const QString &filename) { qDebug("m3u filename is "+filename); QFile f(filename); if(f.open(IO_ReadOnly)) { QTextStream t(&f); QString s;//, first, second; int i=0; while ( !t.atEnd()) { // Lview->insertLine(t.readLine(),-1); s=t.readLine(); if(s.find("#",0,TRUE) == -1) { if(s.find(" ",0,TRUE) == -1) { // not sure if this is neede since cf uses vfat if(s.left(2) == "E:" || s.left(2) == "P:") { s=s.right(s.length()-2); DocLnk lnk( s ); QFileInfo f(s); QString name = f.baseName(); name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); lnk.setName( name); s=s.replace( QRegExp("\\"),"/"); lnk.setFile( s); lnk.writeLink(); // lnk.setIcon(opieplayer/MPEGPlayer); qDebug("add "+name); d->selectedFiles->addToSelection( lnk); } else { // is url s.replace(QRegExp("%20")," "); DocLnk lnk( s); QString name; if(name.left(4)=="http") name = s.right( s.length() - 7); else name=s; // name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); lnk.setName(name); if(s.at(s.length()-4) == '.') lnk.setFile( s); else lnk.setFile( s+"/"); // lnk.setFile( filename); // lnk.setComment( s+"/"); lnk.setType("audio/x-mpegurl"); lnk.writeLink(); // lnk.setIcon( "opieplayer/MPEGPlayer"); // qDebug("add "+s); d->selectedFiles->addToSelection( lnk); } i++; } } } } f.close(); } void PlayListWidget::writem3u() { InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Save m3u Playlist "),TRUE, 0); fileDlg->exec(); QString filename,list; if( fileDlg->result() == 1 ) { filename = fileDlg->LineEdit1->text(); qDebug(filename); int noOfFiles = 0; d->selectedFiles->first(); do { // we dont check for existance because of url's // qDebug(d->selectedFiles->current()->file()); list += d->selectedFiles->current()->file()+"\n"; noOfFiles++; } while ( d->selectedFiles->next() ); qDebug(list); if(filename.left(1) != "/") filename=QPEApplication::documentDir()+"/"+filename; if(filename.right(3) != "m3u") filename=filename+".m3u"; QFile f(filename); f.open(IO_WriteOnly); f.writeBlock(list, list.length()); f.close(); } if(fileDlg) delete fileDlg; } void PlayListWidget::readPls(const QString &filename) { qDebug("pls filename is "+filename); QFile f(filename); if(f.open(IO_ReadOnly)) { QTextStream t(&f); QString s;//, first, second; int i=0; while ( !t.atEnd()) { s=t.readLine(); if(s.left(4) == "File") { s=s.right(s.length() - 6); s.replace(QRegExp("%20")," "); qDebug("adding "+s+" to playlist"); // numberofentries=2 // File1=http // Title // Length // Version // File2=http s=s.replace( QRegExp("\\"),"/"); DocLnk lnk( s ); QFileInfo f(s); QString name = f.baseName(); if(name.left(4)=="http") name = s.right( s.length() - 7); else name=s; name = name.right(name.length()-name.findRev("\\",-1,TRUE)-1); // QFileInfo f(s); // QString name = f.baseName(); // name = name.left(name.length()-4); // name = name.right(name.findRev("/",0,TRUE)); lnk.setName( name); if(s.at(s.length()-4) == '.') // if this is probably a file lnk.setFile( s); else { //if its a url if( name.right(1).find('/') == -1) s+="/"; lnk.setFile( s); } lnk.setType("audio/x-mpegurl"); qDebug("DocLnk add "+name); d->selectedFiles->addToSelection( lnk); } } i++; } } diff --git a/noncore/multimedia/opieplayer2/playlistwidget.cpp b/noncore/multimedia/opieplayer2/playlistwidget.cpp index 603a7a3..6c4d07f 100644 --- a/noncore/multimedia/opieplayer2/playlistwidget.cpp +++ b/noncore/multimedia/opieplayer2/playlistwidget.cpp @@ -348,713 +348,716 @@ const DocLnk *PlayListWidget::current() { // this is fugly case 2: // video { // qDebug("videoView"); QListIterator<DocLnk> Vdit( vFiles.children() ); for ( ; Vdit.current(); ++Vdit ) { if( Vdit.current()->name() == videoView->currentItem()->text( 0 ) && !insanityBool) { insanityBool = TRUE; return Vdit; } } } break; }; return 0; } bool PlayListWidget::prev() { if ( mediaPlayerState->playlist() ) { if ( mediaPlayerState->shuffled() ) { const DocLnk *cur = current(); int j = 1 + (int)(97.0 * rand() / (RAND_MAX + 1.0)); for ( int i = 0; i < j; i++ ) { if ( !d->selectedFiles->next() ) d->selectedFiles->first(); } if ( cur == current() ) if ( !d->selectedFiles->next() ) { d->selectedFiles->first(); } return TRUE; } else { if ( !d->selectedFiles->prev() ) { if ( mediaPlayerState->looping() ) { return d->selectedFiles->last(); } else { return FALSE; } } return TRUE; } } else { return mediaPlayerState->looping(); } } bool PlayListWidget::next() { if ( mediaPlayerState->playlist() ) { if ( mediaPlayerState->shuffled() ) { return prev(); } else { if ( !d->selectedFiles->next() ) { if ( mediaPlayerState->looping() ) { return d->selectedFiles->first(); } else { return FALSE; } } return TRUE; } } else { return mediaPlayerState->looping(); } } bool PlayListWidget::first() { if ( mediaPlayerState->playlist() ) return d->selectedFiles->first(); else return mediaPlayerState->looping(); } bool PlayListWidget::last() { if ( mediaPlayerState->playlist() ) return d->selectedFiles->last(); else return mediaPlayerState->looping(); } void PlayListWidget::saveList() { QString filename; InputDialog *fileDlg = 0l; fileDlg = new InputDialog(this,tr("Save Playlist"),TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { if ( d->current ) delete d->current; filename = fileDlg->text();//+".playlist"; // qDebug("saving playlist "+filename+".playlist"); Config cfg( filename +".playlist"); writeConfig( cfg ); DocLnk lnk; lnk.setFile(QDir::homeDirPath()+"/Settings/"+filename+".playlist.conf"); //sets File property lnk.setType("playlist/plain");// hey is this a REGISTERED mime type?!?!? ;D lnk.setIcon("opieplayer2/playlist2"); lnk.setName( filename); //sets file name // qDebug(filename); if(!lnk.writeLink()) { qDebug("Writing doclink did not work"); } } Config config( "OpiePlayer" ); config.writeEntry("CurrentPlaylist",filename); setCaption(tr("OpiePlayer: ")+filename); d->selectedFiles->first(); if(fileDlg) { delete fileDlg; } } void PlayListWidget::loadList( const DocLnk & lnk) { QString name= lnk.name(); // qDebug("currentList is "+name); if( name.length()>1) { setCaption("OpiePlayer: "+name); // qDebug("load list "+ name+".playlist"); clearList(); Config cfg( name+".playlist"); readConfig(cfg); tabWidget->setCurrentPage(0); Config config( "OpiePlayer" ); config.writeEntry("CurrentPlaylist", name); // d->selectedFiles->first(); } } void PlayListWidget::setPlaylist( bool shown ) { if ( shown ) { d->playListFrame->show(); } else { d->playListFrame->hide(); } } void PlayListWidget::addSelected() { Config cfg( "OpiePlayer" ); cfg.setGroup("PlayList"); QString currentPlaylist = cfg.readEntry("CurrentPlaylist",""); // int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); switch (tabWidget->currentPageIndex()) { case 0: //playlist break; case 1: { //audio QListViewItemIterator it( audioView ); // iterate through all items of the listview for ( ; it.current(); ++it ) { if ( it.current()->isSelected() ) { QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) { if( dit.current()->name() == it.current()->text(0) ) { if(QFileInfo( dit.current()->file()).exists()) d->selectedFiles->addToSelection( **dit ); } } audioView->setSelected( it.current(),FALSE); } } tabWidget->setCurrentPage(0); } break; case 2: { // video QListViewItemIterator it( videoView ); // iterate through all items of the listview for ( ; it.current(); ++it ) { if ( it.current()->isSelected() ) { QListIterator<DocLnk> dit( vFiles.children() ); for ( ; dit.current(); ++dit ) { if( dit.current()->name() == it.current()->text(0) ) { if(QFileInfo( dit.current()->file()).exists()) d->selectedFiles->addToSelection( **dit ); } } videoView->setSelected( it.current(),FALSE); } } tabWidget->setCurrentPage(0); } break; }; } void PlayListWidget::removeSelected() { d->selectedFiles->removeSelected( ); } void PlayListWidget::playIt( QListViewItem *it) { if(!it) return; mediaPlayerState->setPlaying(FALSE); mediaPlayerState->setPlaying(TRUE); d->selectedFiles->unSelect(); } void PlayListWidget::addToSelection( QListViewItem *it) { d->setDocumentUsed = FALSE; if(it) { switch (tabWidget->currentPageIndex()) { case 1: { QListIterator<DocLnk> dit( files.children() ); for ( ; dit.current(); ++dit ) { if( dit.current()->name() == it->text(0)) { if(QFileInfo( dit.current()->file()).exists()) d->selectedFiles->addToSelection( **dit ); } } } break; case 2: { QListIterator<DocLnk> dit( vFiles.children() ); for ( ; dit.current(); ++dit ) { if( dit.current()->name() == it->text(0)) { if(QFileInfo( dit.current()->file()).exists()) d->selectedFiles->addToSelection( **dit ); } } } break; case 0: break; }; tabWidget->setCurrentPage(0); } } void PlayListWidget::tabChanged(QWidget *) { switch ( tabWidget->currentPageIndex()) { case 0: { if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } d->tbRemoveFromList->setEnabled(TRUE); d->tbAddToList->setEnabled(FALSE); } break; case 1: { audioView->clear(); populateAudioView(); if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case 2: { videoView->clear(); populateVideoView(); if( !tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->hide(); } d->tbRemoveFromList->setEnabled(FALSE); d->tbAddToList->setEnabled(TRUE); } break; case 3: { if( tbDeletePlaylist->isHidden() ) { tbDeletePlaylist->show(); } playLists->reread(); } break; }; } void PlayListWidget::btnPlay(bool b) { // mediaPlayerState->setPlaying(b); switch ( tabWidget->currentPageIndex()) { case 0: { mediaPlayerState->setPlaying(b); } break; case 1: { addToSelection( audioView->currentItem() ); mediaPlayerState->setPlaying(b); d->selectedFiles->removeSelected( ); tabWidget->setCurrentPage(1); d->selectedFiles->unSelect(); insanityBool=FALSE; }// audioView->clearSelection(); break; case 2: { addToSelection( videoView->currentItem() ); mediaPlayerState->setPlaying(b); qApp->processEvents(); d->selectedFiles->removeSelected( ); tabWidget->setCurrentPage(2); d->selectedFiles->unSelect(); insanityBool=FALSE; }// videoView->clearSelection(); break; }; } void PlayListWidget::deletePlaylist() { switch( QMessageBox::information( this, (tr("Remove Playlist?")), (tr("You really want to delete\nthis playlist?")), (tr("Yes")), (tr("No")), 0 )){ case 0: // Yes clicked, QFile().remove(playLists->selected()->file()); QFile().remove(playLists->selected()->linkFile()); playLists->reread(); break; case 1: // Cancel break; }; } void PlayListWidget::playSelected() { btnPlay( TRUE); } void PlayListWidget::scanForAudio() { // qDebug("scan for audio"); files.detachChildren(); QListIterator<DocLnk> sdit( files.children() ); for ( ; sdit.current(); ++sdit ) { delete sdit.current(); } Global::findDocuments(&files, "audio/*"); audioScan = TRUE; } void PlayListWidget::scanForVideo() { // qDebug("scan for video"); vFiles.detachChildren(); QListIterator<DocLnk> sdit( vFiles.children() ); for ( ; sdit.current(); ++sdit ) { delete sdit.current(); } Global::findDocuments(&vFiles, "video/*"); videoScan = TRUE; } void PlayListWidget::populateAudioView() { audioView->clear(); StorageInfo storageInfo; const QList<FileSystem> &fs = storageInfo.fileSystems(); if(!audioScan) { scanForAudio(); } QListIterator<DocLnk> dit( files.children() ); QListIterator<FileSystem> it ( fs ); QString storage; for ( ; dit.current(); ++dit ) { for( ; it.current(); ++it ){ const QString name = (*it)->name(); const QString path = (*it)->path(); if(dit.current()->file().find(path) != -1 ) { storage = name; } } QListViewItem * newItem; - if ( QFile( dit.current()->file()).exists() ) { - // qDebug(dit.current()->name()); - newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), - QString::number( QFile( dit.current()->file()).size() ), storage); + if ( QFile( dit.current()->file()).exists() || dit.current()->file().left(4) == "http" ) { + long size; + if( dit.current()->file().left(4) == "http" ) + size=0; + else + size = QFile( dit.current()->file() ).size(); + newItem= /*(void)*/ new QListViewItem( audioView, dit.current()->name(), QString::number(size ), storage); newItem->setPixmap( 0, Resource::loadPixmap( "opieplayer2/musicfile" ) ); } } } void PlayListWidget::populateVideoView() { videoView->clear(); StorageInfo storageInfo; const QList<FileSystem> &fs = storageInfo.fileSystems(); if(!videoScan ) { scanForVideo(); } QListIterator<DocLnk> Vdit( vFiles.children() ); QListIterator<FileSystem> it ( fs ); videoView->clear(); QString storage; for ( ; Vdit.current(); ++Vdit ) { for( ; it.current(); ++it ) { const QString name = (*it)->name(); const QString path = (*it)->path(); if( Vdit.current()->file().find(path) != -1 ) { storage=name; } } QListViewItem * newItem; if ( QFile( Vdit.current()->file() ).exists() ) { newItem= /*(void)*/ new QListViewItem( videoView, Vdit.current()->name(), QString::number( QFile( Vdit.current()->file() ).size() ), storage ); newItem->setPixmap(0, Resource::loadPixmap( "opieplayer2/videofile" ) ); } } } void PlayListWidget::openFile() { QString filename, name; InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Open file or URL"),TRUE, 0); fileDlg->exec(); if( fileDlg->result() == 1 ) { filename = fileDlg->text(); qDebug( "Selected filename is " + filename ); if( filename.right( 3 ) == "m3u" ) { readm3u( filename ); } else if( filename.right(3) == "pls" ) { readPls( filename ); } else { // this doesnt need fixing DocLnk lnk; lnk.setName( filename ); //sets file name lnk.setFile( filename ); //sets File property //qWarning( "Mimetype: " + MimeType( QFile::encodeName(filename) ).id() ); lnk.setType( MimeType( QFile::encodeName(filename) ).id() ); lnk.setExec( "opieplayer" ); lnk.setIcon( "opieplayer2/MPEGPlayer" ); if( !lnk.writeLink() ) { qDebug( "Writing doclink did not work" ); } d->selectedFiles->addToSelection( lnk ); } } if( fileDlg ) { delete fileDlg; } } void PlayListWidget::keyReleaseEvent( QKeyEvent *e ) { switch ( e->key() ) { ////////////////////////////// Zaurus keys case Key_F9: //activity // if(audioUI->isHidden()) // audioUI->showMaximized(); break; case Key_F10: //contacts // if( videoUI->isHidden()) // videoUI->showMaximized(); break; case Key_F11: //menu break; case Key_F12: //home // doBlank(); break; case Key_F13: //mail // doUnblank(); break; case Key_Q: //add to playlist addSelected(); break; case Key_R: //remove from playlist removeSelected(); break; // case Key_P: //play // qDebug("Play"); // playSelected(); // break; case Key_Space: // playSelected(); puh break; case Key_1: tabWidget->setCurrentPage( 0 ); break; case Key_2: tabWidget->setCurrentPage( 1 ); break; case Key_3: tabWidget->setCurrentPage( 2 ); break; case Key_4: tabWidget->setCurrentPage( 3 ); break; case Key_Down: if ( !d->selectedFiles->next() ) d->selectedFiles->first(); break; case Key_Up: if ( !d->selectedFiles->prev() ) // d->selectedFiles->last(); break; } } void PlayListWidget::readm3u( const QString &filename ) { qDebug( "m3u filename is " + filename ); QFile f( filename ); if( f.open( IO_ReadOnly ) ) { QTextStream t(&f); QString s;//, first, second; int i=0; while ( !t.atEnd() ) { s=t.readLine(); if( s.find( "#", 0, TRUE) == -1 ) { if( s.find( " ", 0, TRUE) == -1 ) { // not sure if this is neede since cf uses vfat if( s.left(2) == "E:" || s.left(2) == "P:" ) { s = s.right( s.length() -2 ); DocLnk lnk( s ); QFileInfo f( s ); QString name = f.baseName(); name = name.right( name.length() - name.findRev( "\\", -1, TRUE ) -1 ); lnk.setName( name ); s=s.replace( QRegExp( "\\" ), "/" ); lnk.setFile( s ); lnk.writeLink(); qDebug( "add " + name); d->selectedFiles->addToSelection( lnk ); } else { // is url s.replace( QRegExp( "%20" )," " ); DocLnk lnk( s ); QString name; if( name.left( 4 ) == "http" ) { name = s.right( s.length() - 7 ); } else { name = s; } lnk.setName( name ); if( s.at( s.length() - 4) == '.' ) { lnk.setFile( s ); } else { lnk.setFile( s + "/" ); } lnk.setType( "audio/x-mpegurl" ); lnk.writeLink(); d->selectedFiles->addToSelection( lnk ); } i++; } } } } f.close(); } void PlayListWidget::writem3u() { InputDialog *fileDlg; fileDlg = new InputDialog( this, tr( "Save m3u Playlist " ), TRUE, 0); fileDlg->exec(); QString filename, list; if( fileDlg->result() == 1 ) { filename = fileDlg->text(); qDebug( filename ); int noOfFiles = 0; d->selectedFiles->first(); do { // we dont check for existance because of url's // qDebug(d->selectedFiles->current()->file()); // so maybe we should do some net checking to ,-) // no, cause it takes to long... list += d->selectedFiles->current()->file() + "\n"; noOfFiles++; } while ( d->selectedFiles->next() ); qDebug( list ); if( filename.left( 1) != "/" ) { filename=QPEApplication::documentDir() + "/" + filename; } if( filename.right( 3 ) != "m3u" ) { filename=filename+".m3u"; } QFile f( filename ); f.open( IO_WriteOnly ); f.writeBlock( list, list.length() ); f.close(); } if( fileDlg ) { delete fileDlg; } } void PlayListWidget::readPls( const QString &filename ) { qDebug( "pls filename is " + filename ); QFile f( filename ); if( f.open( IO_ReadOnly ) ) { QTextStream t( &f ); QString s;//, first, second; int i = 0; while ( !t.atEnd() ) { s = t.readLine(); if( s.left(4) == "File" ) { s = s.right( s.length() - 6 ); s.replace( QRegExp( "%20" )," "); qDebug( "adding " + s + " to playlist" ); // numberofentries=2 // File1=http // Title // Length // Version // File2=http s = s.replace( QRegExp( "\\" ), "/" ); DocLnk lnk( s ); QFileInfo f( s ); QString name = f.baseName(); if( name.left( 4 ) == "http" ) { name = s.right( s.length() - 7); } else { name = s; } name = name.right( name.length() - name.findRev( "\\", -1, TRUE) - 1 ); lnk.setName( name ); if( s.at( s.length() - 4) == '.') // if this is probably a file lnk.setFile( s ); else { //if its a url if( name.right( 1 ).find( '/' ) == -1) { s += "/"; } lnk.setFile( s ); } lnk.setType( "audio/x-mpegurl" ); //qDebug("DocLnk add "+name); d->selectedFiles->addToSelection( lnk ); } } i++; } } void PlayListWidget::pmViewActivated(int index) { // qDebug("%d", index); switch(index) { case -16: { mediaPlayerState->toggleFullscreen(); bool b=mediaPlayerState->fullscreen(); pmView->setItemChecked( index, b); Config cfg( "OpiePlayer" ); cfg.writeEntry( "FullScreen", b ); } break; }; } void PlayListWidget::populateSkinsMenu() { int item = 0; defaultSkinIndex = 0; QString skinName; Config cfg( "OpiePlayer" ); cfg.setGroup("Options" ); QString skin = cfg.readEntry( "Skin", "default" ); QDir skinsDir( QPEApplication::qpeDir() + "/pics/opieplayer2/skins" ); skinsDir.setFilter( QDir::Dirs ); skinsDir.setSorting(QDir::Name ); const QFileInfoList *skinslist = skinsDir.entryInfoList(); QFileInfoListIterator it( *skinslist ); QFileInfo *fi; while ( ( fi = it.current() ) ) { skinName = fi->fileName(); qDebug( fi->fileName() ); if( skinName != "." && skinName != ".." && skinName !="CVS" ) { item = skinsMenu->insertItem( fi->fileName() ) ; } if( skinName == "default" ) { defaultSkinIndex = item; } if( skinName == skin ) { skinsMenu->setItemChecked( item, TRUE ); } ++it; } } void PlayListWidget::skinsMenuActivated( int item ) { for( uint i = defaultSkinIndex; i > defaultSkinIndex - skinsMenu->count(); i-- ) { skinsMenu->setItemChecked( i, FALSE ); } skinsMenu->setItemChecked( item, TRUE ); Config cfg( "OpiePlayer" ); cfg.setGroup("Options"); cfg.writeEntry("Skin", skinsMenu->text( item ) ); } |