void PlaylistWindow::importTab() { QString file; file = QFileDialog::getOpenFileName(this, tr("Import File"), QString(), tr("Playlist files (*.m3u *.m3u8)")); if (!file.isEmpty()) emit importPlaylist(file); }
QModelIndex KNMusicPlaylistManager::importPlaylists( const QStringList &filePaths) { //Generate the first index. QModelIndex firstImport=QModelIndex(); //Import all the files. for(auto i=filePaths.constBegin(); i!=filePaths.end(); ++i) { //Get the model index via import the playlist. QModelIndex playlistIndex(importPlaylist(*i)); //Check whether the index is valid. if(playlistIndex.isValid() && (!firstImport.isValid())) { //Save the current index. firstImport=playlistIndex; } } //Give back the first import index. return firstImport; }
void k2send::setupActions() { KAction *action; KShortcut cut; setXMLFile( "k2sendui.rc" ); KStdAction::openNew(this, SLOT(fileNew()), actionCollection(),"file_new"); KStdAction::open(this, SLOT(fileOpen()), actionCollection(),"file_open"); action = new KAction(i18n("Import Playlist"), cut, this, SLOT(importPlaylist()), actionCollection(), "file_import"); KStdAction::print(this, SLOT(filePrint()), actionCollection(),"file_print"); KStdAction::quit(kapp, SLOT(quit()), actionCollection(),"file_quit"); m_toolbarAction = KStdAction::showToolbar(this, SLOT(optionsShowToolbar()), actionCollection()); m_statusbarAction = KStdAction::showStatusbar(this, SLOT(optionsShowStatusbar()), actionCollection()); KStdAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection()); KStdAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection()); KStdAction::preferences(this, SLOT(optionsPreferences()), actionCollection(),"preferences"); action = new KAction(i18n("Remove"), "editdelete", cut, m_view, SLOT(slotRemoveBranch()), actionCollection(), "file_remove"); action = new KAction(i18n("Play"), "player_play", cut, m_view, SLOT(slotPlay()), actionCollection(), "player_play"); action = new KAction(i18n("Stop"), "player_stop", cut,m_view, SLOT(slotStop()), actionCollection(), "player_stop"); action = new KAction(i18n("Next"), "player_fwd", cut,m_view, SLOT(slotSkip()), actionCollection(), "player_next"); action = new KAction(i18n("Loudness"), 0, cut,m_view, SLOT(slotLoudness()), actionCollection(), "player_loudness"); action = new KAction(i18n("Clear"), "reload", cut,m_view, SLOT(slotPlaylistClear()), actionCollection(), "playlist_clear"); action = new KAction(i18n("Play"), "player_play", cut,m_view, SLOT(slotConsolePlay()), actionCollection(), "console_play"); action = new KAction(i18n("Stop"), "player_stop", cut,m_view, SLOT(slotConsoleStop()), actionCollection(), "console_stop"); action = new KAction(i18n("Clear"), "reload", cut,m_view, SLOT(slotConsoleClear()), actionCollection(), "console_clear"); createGUI(); }
TreeItem* RhythmboxFeature::importPlaylists() { QFile db(QDir::homePath() + "/.gnome2/rhythmbox/playlists.xml"); if ( ! db.exists()) { db.setFileName(QDir::homePath() + "/.local/share/rhythmbox/playlists.xml"); if (!db.exists()) return NULL; } //Open file if (!db.open(QIODevice::ReadOnly | QIODevice::Text)) return NULL; QSqlQuery query_insert_to_playlists(m_database); query_insert_to_playlists.prepare("INSERT INTO rhythmbox_playlists (id, name) " "VALUES (:id, :name)"); QSqlQuery query_insert_to_playlist_tracks(m_database); query_insert_to_playlist_tracks.prepare( "INSERT INTO rhythmbox_playlist_tracks (playlist_id, track_id, position) " "VALUES (:playlist_id, :track_id, :position)"); //The tree structure holding the playlists TreeItem* rootItem = new TreeItem(); QXmlStreamReader xml(&db); while (!xml.atEnd() && !m_cancelImport) { xml.readNext(); if (xml.isStartElement() && xml.name() == "playlist") { QXmlStreamAttributes attr = xml.attributes(); //Only parse non build-in playlists if (attr.value("type").toString() == "static") { QString playlist_name = attr.value("name").toString(); //Construct the childmodel TreeItem * item = new TreeItem(playlist_name, playlist_name, this, rootItem); rootItem->appendChild(item); //Execute SQL statement query_insert_to_playlists.bindValue(":name", playlist_name); if (!query_insert_to_playlists.exec()) { LOG_FAILED_QUERY(query_insert_to_playlists) << "Couldn't insert playlist:" << playlist_name; continue; } // get playlist_id int playlist_id = query_insert_to_playlists.lastInsertId().toInt(); //Process playlist entries importPlaylist(xml, query_insert_to_playlist_tracks, playlist_id); } } } if (xml.hasError()) { // do error handling qDebug() << "Cannot process Rhythmbox music collection"; qDebug() << "XML ERROR: " << xml.errorString(); return NULL; } db.close(); return rootItem; }