📄 qmplaylistbrowser.cpp
字号:
m_pFileDialog->setCaption(tr("Apollo - Enter playlist tree name")); m_pFileDialog->show(); } else { save(); }}/*! */voidQmPlayListBrowser::doSaveFile( QFileDialog *dlg, int val){ if ( val == QDialog::Accepted ) { QmConfig::instance()->set("path", "playlisttree", dlg->dirPath()); enableSelfSave(dlg->selectedFile()); save(); } disconnect( m_pFileDialog, SIGNAL( dialogDone( QFileDialog *, int ) ), this, SLOT( doSaveFile( QFileDialog *, int ) ) );}/*! Pops up a dialog asking which playlist(s) to add to the tree */voidQmPlayListBrowser::addOldPlayList(){ if(m_pFileDialog == 0) m_pFileDialog = new QmFileDialog(); m_pFileDialog->setDir(QmConfig::instance()->getString("path", "playlist")); m_pFileDialog->setMode(QFileDialog::ExistingFiles); m_pFileDialog->setFilter("Playlists (*.m3u *.xml)"); connect( m_pFileDialog, SIGNAL( dialogDone( QFileDialog *, int ) ), this, SLOT( doAddOldPlayList( QFileDialog *, int ) ) ); m_pFileDialog->setCaption(tr("Apollo - Select playlist(s)")); m_pFileDialog->show();}/*! Called when the playlist file dialog is done, adds the selected playlists to the tree*/voidQmPlayListBrowser::doAddOldPlayList( QFileDialog *dlg, int val){ if ( val == QDialog::Accepted ) { QmConfig::instance()->set("path", "playlist", dlg->dirPath()); QStringList files = dlg->selectedFiles(); QmPlayListBrowserItem *item = 0; QFileInfo fi; if (m_pPlayListSelected && m_pPlayListSelected->isFolder()) { m_pPlayListSelected->setExpandable(true); m_pPlayListSelected->setOpen(true); clearSelection(); } for (QStringList::Iterator file = files.begin(); file != files.end(); ++file) { fi.setFile(*file); if (m_pPlayListSelected == 0) item = new QmPlayListBrowserItem(this, 0, fi.baseName(), *file); else if (m_pPlayListSelected->isFolder()) item = new QmPlayListBrowserItem(m_pPlayListSelected, 0, fi.baseName(), *file); else item = new QmPlayListBrowserItem(this, 0, fi.baseName(), *file); } } disconnect( m_pFileDialog, SIGNAL( dialogDone( QFileDialog *, int ) ), this, SLOT( doAddOldPlayList( QFileDialog *, int ) ) );}/*! Adds a playlist folder, i.e. an item in the tree to hold playlists or other folders.*/voidQmPlayListBrowser::addPlayListFolder(){ QmPlayListBrowserItem *item = 0; if(m_pPlayListSelected == 0) item = new QmPlayListBrowserItem(this, 0, tr("New folder"), "", true); else { m_pPlayListSelected->setExpandable(true); m_pPlayListSelected->setOpen(true); clearSelection(); item = new QmPlayListBrowserItem(m_pPlayListSelected, 0, tr("New folder"), "", true); } renamePlayList(item);}/*! Renames the stored item to \a text. Sorting will be applied. \bug Accelerator keys in toolbar override the rename edit. Overriding QApplication::event() may be necessary. Focus proxies does not seem to work. */voidQmPlayListBrowser::renameItem( const QString &text){ if(m_pRenameItem == 0) return; m_pRenameItem->setText(0, text); if(m_pRenameItem->parent()) m_pRenameItem->parent()->sort(); else sort();}/*! Renames the \e active playlist tree item. \sa renamePlayList(QListViewItem *) */voidQmPlayListBrowser::renamePlayList(){ if (currentItem()) renamePlayList(currentItem());}/*! Renames the tree item \a item. \sa renamePlayList()*/voidQmPlayListBrowser::renamePlayList( QListViewItem *item){ m_pRenameItem = item; m_pRenameEdit->position(item);}/*! Displays the properties for the active playlist tree item. Currently name and path.*/voidQmPlayListBrowser::propertyPlayList(){ QmPlayListBrowserItem *current = currentPlayList(); if(current == 0) return; if(m_pPropertyPage) delete m_pPropertyPage; m_pPropertyPage = new QmPlayListPropertyPage(current); m_pPropertyPage->show();}/** @name Load functions The family of functions to load the playlists tree from disk. *//*@{*//*! Opens the load file dialog, connects doLoadFile() on close*/voidQmPlayListBrowser::loadFile() { if (QmMainWindow::mainwin->state() == QmMainWindow::Busy) return; QmConfig *conf = QmConfig::instance(); QmFileDialog *dlg = new QmFileDialog(conf->getString("path", "playlisttree"), QString::null, 0, "Apollo - Load playlist tree"); connect(dlg, SIGNAL(dialogDone(QFileDialog *, int)), this, SLOT(doLoadFile(QFileDialog *, int))); dlg->setCaption(tr("Apollo - Load playlist tree")); dlg->setMode(QFileDialog::ExistingFile); QRect file_rect = QmConfig::instance()->getRect( "file-dialog", "geometry" ); if ( file_rect.isValid() ) { dlg->resize( file_rect.size() ); dlg->move( file_rect.topLeft() ); } dlg->show();}/*! Callback from loadFile(). Loads a playlist tree. */voidQmPlayListBrowser::doLoadFile(QFileDialog *dlg, int val){ QmConfig *conf = QmConfig::instance(); conf->set("path", "playlisttree", dlg->dir()->absPath()); conf->set("file-dialog", "geometry", QRect(dlg->pos(), dlg->size())); if (val == QDialog::Accepted) { QString name = dlg->selectedFile(); if (!name.isEmpty()) { enableSelfSave(name); loadPlayListTree(name); } } disconnect(dlg, SIGNAL(dialogDone(QFileDialog *, int)), this, SLOT(doLoadFile(QFileDialog *, int))); delete dlg;}/*! Loads the XML file in the .apollo setting directory that populates the playlist tree (this widget).*/voidQmPlayListBrowser::loadPlayListTree(){ loadPlayListTree(QmConfig::instance()->configPath() + "playlisttree" );}/*! Loads the XML file \a filename and populates the playlist tree (this widget).*/voidQmPlayListBrowser::loadPlayListTree( const QString &filename){ if(QmRecoveryManager::instance()->loadingEnabled(QmConfig::PlayListTree) == false) return; QDomDocument doc( "apollo-playlisttree" ); QFile f( filename ); if ( ! f.open( IO_ReadOnly ) ) { QmMainWindow::mainwin->statusUpdate( new Message(Message::Error, "Could not read %s", filename.latin1())); return; } if ( ! doc.setContent( &f ) ) { QmMainWindow::mainwin->statusUpdate( new Message(Message::Error, "QmPlayListBrowser: doc.setContent failed")); f.close(); return; } f.close(); // Get root node (element) QDomNode node = doc.documentElement(); if(node.nodeName() != "apollo-playlisttree") { QmMainWindow::mainwin->statusUpdate( new Message(Message::Error, "%s is not an apollo-playlisttree", filename.latin1())); return; } m_PlayListTree = filename; clear(); QmMainWindow::mainwin->setState( QmMainWindow::Busy ); // Get the first child in the document. This should be a 'dir' element. QDomNode child = node.firstChild(); int lists = 0, folders = 0; while ( !child.isNull() ) { loadPlayListTree(child, 0, lists, folders); child = child.nextSibling(); } if (folders > 0) QmMainWindow::mainwin->statusUpdate(new Message(Message::Status, "Loaded %s. %d playlists in %d folders", filename.latin1(), lists, folders)); else QmMainWindow::mainwin->statusUpdate(new Message(Message::Status, "Loaded %s. %d playlists.", filename.latin1(), lists)); QmMainWindow::mainwin->setState( QmMainWindow::Ready );}/*! Helper function for recursively loading the playlist tree. This function is for subitems. It has code that is quite similar to loadPlayListTree(), but that function is for root items (i.e. they have the listview as parent), while this function is for child items (i.e. they have some item as parent).*/voidQmPlayListBrowser::loadPlayListTree( QDomNode &node, QmPlayListBrowserItem *parent, int &lists, int &folders){ QmPlayListBrowserItem *child = 0; QString path, name, open; bool isFolder; path = name = open = QString::null; QValueList<QDomNode> nodes; if(node.nodeName() != "dir" && node.nodeName() != "playlist") { qWarning("QmPlayListBrowser::loadPlayListNode(): Expected \"dir\" or \"playlist\", " "found \"%s\".\n", node.nodeName().latin1()); return; } isFolder = node.nodeName() == "dir"; QDomNodeList children = node.childNodes(); QDomNode child_node, data; for(unsigned int i = 0; i < children.count(); i++) { child_node = children.item(i); data = child_node.firstChild(); if(child_node.nodeName() == "name") name = data.nodeValue(); else if(child_node.nodeName() == "title") name = data.nodeValue(); else if(child_node.nodeName() == "path") path = data.nodeValue(); else if(child_node.nodeName() == "open") open = data.nodeValue(); else nodes.append( child_node ); } bool is_dir = false; if (node.nodeName() == "dir" && path.isEmpty()) { folders++; if (parent == 0) child = new QmPlayListBrowserItem(this, child, name, QString::null, true); else child = new QmPlayListBrowserItem(parent, child, name, QString::null, true); if(open == "1") child->setOpen(true); child->setExpandable(true); is_dir = true; } else if (node.nodeName() == "playlist" || ( node.nodeName() == "dir" && !path.isEmpty()) ) { lists++; if (parent == 0) child = new QmPlayListBrowserItem(this, child, name, path, false); else child = new QmPlayListBrowserItem(parent, child, name, path, false); } else { QmMainWindow::mainwin->statusUpdate(new Message(Message::Error, "Error: expected `dir' or `playlist', found %s", node.nodeName().latin1())); return; } if ( is_dir ) { for ( QValueList<QDomNode>::ConstIterator it = nodes.begin(); it != nodes.end(); ++it ) { child_node = *it; loadPlayListTree( child_node, child, lists, folders); } }}/*@}*/ // End of Doxygen group tag./*! \note: identical code in qmdirbrowser - modify both*/voidQmPlayListBrowser::startDragging(){ if (!reorganizable()) return; QStringList files; QList<QListViewItem> *selected = selectedItems(); for (QListViewItem *i=selected->first(); i; i=selected->next()) files.append(reinterpret_cast<QmBrowserItem*>(i)->fileName()); delete selected; QUriDrag *d = new QUriDrag(this); d->setFilenames(files); d->dragMove();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -