예제 #1
0
void PlayerPanel::queuePlaylistFile (QString& filename)
{
  qDebug() << "loading playlist" << filename;

  QFile playlistFile(filename);

  if (!playlistFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
    qWarning() << "couldn't open playlist file" << filename;
    return;
  }

  while (!playlistFile.atEnd()) {
    QString line(playlistFile.readLine());
    line = line.left(line.size()-1);
    //qDebug() << "loading playlist entry" << line;
    this->queueMediaFile(line);
  }
}
예제 #2
0
파일: playlist.cpp 프로젝트: meh2481/kissme
std::list<song> playlist_load_PLS(std::string sFilename)
{
	std::list<song> ret;
	
	std::ifstream playlistFile(sFilename.c_str());
	int num = 0;
	if(!playlistFile.fail())
	{	
    std::string s;
    
    //Header starts with a [playlist] line
    while(!s.size() && !playlistFile.fail())
   	{
   		getline(playlistFile,s);
   		removecomment(s, ';');
   		strip_leading_whitespace(s);
   	}
    if(s != "[playlist]") 
    {
    	playlistFile.close();
    	return ret;	//malformed
    }
   	s.clear();
   	
   	//Next up is a line that tells us how many items
    while(!s.size() && !playlistFile.fail())
   	{
   		getline(playlistFile,s);
   		removecomment(s, ';');
   		strip_leading_whitespace(s);
   	}
   	if(s.find("NumberOfEntries") == std::string::npos) 
   	{
   		playlistFile.close();
   		return ret;	//malformed if this missing
   	}
   	s.erase(0, 15);	//Strip off "NumberOfEntries"
   	strip_leading_whitespace(s);	//Strip any whitespace
   	s.erase(0,1);	//Erase '=' character
   	strip_leading_whitespace(s);	//Strip any whitespace
   	std::istringstream iss(s);
   	iss >> num;
   	
	}
예제 #3
0
bool KNMusicPlaylistManager::writeModelToFile(KNMusicPlaylistModel *model,
                                              const QString &filePath)
{
    //Check te model first, then check out the model folder path.
    if(!model ||
            (KNUtil::ensurePathValid(
                 QFileInfo(filePath).absolutePath()).isEmpty()))
    {
        return false;
    }
    //Get the playlist file.
    QFile playlistFile(filePath);
    //Try to open the file as write mode.
    if(!playlistFile.open(QIODevice::WriteOnly))
    {
        return false;
    }
    //Create the playlist content.
    QJsonArray songs;
    //Write all the data to the content.
    for(int row=0; row<model->rowCount(); ++row)
    {
        //Translate the detail info from the model to a QJsonObject, and add it
        //to the playlist content.
        songs.append(
                    KNMusicUtil::detailInfoToObject(model->rowDetailInfo(row)));
    }
    //Create the playlist object.
    QJsonObject playlistObject;
    //Set the data of the playlist.
    playlistObject["Version"]=PlaylistListVersion;
    playlistObject["Name"]=model->title();
    playlistObject["Songs"]=songs;
    //Create playlist document
    QJsonDocument playlistDocument;
    //Set the playlist object to document object.
    playlistDocument.setObject(playlistObject);
    //Write document data to the file.
    playlistFile.write(playlistDocument.toJson(QJsonDocument::Indented));
    //Close the file.
    playlistFile.close();
    //Export complete.
    return true;
}
예제 #4
0
KNMusicPlaylistModel *KNMusicPlaylistManager::loadPlaylist(
        const QString &filePath)
{
    //Get the playlist file.
    QFile playlistFile(filePath);
    //Tried to open it as read only mode.
    if((!playlistFile.exists()) || (!playlistFile.open(QIODevice::ReadOnly)))
    {
        //For the file which is not exist, or we cannot open, treat it as failed
        //to load.
        return nullptr;
    }
    //Get playlist content object from the playlist file.
    QJsonObject contentObject=
            QJsonDocument::fromJson(playlistFile.readAll()).object();
    //Close the playlist file.
    playlistFile.close();
    //Check the content object, the following case will just make it failed to
    //load the playlist.
    // * The content object is empty.
    // * It doesn't contain Version, Name or Songs value.
    if(contentObject.isEmpty() ||
            contentObject.value("Version").toInt()!=PlaylistListVersion ||
            !contentObject.contains("Name") ||
            !contentObject.contains("Songs"))
    {
        return nullptr;
    }
    //Generate the playlist.
    KNMusicPlaylistModel *model=new KNMusicPlaylistModel(m_workingThread,
                                                         m_playlistList);
    //Set the playlist meta data from the json object.
    model->setTitle(contentObject.value("Name").toString());
    model->setContentData(contentObject.value("Songs").toArray());
    //Reset the changed state.
    model->setChanged(false);
    //Add this playlist model to playlist list, give back the model index.
    m_playlistList->append(model);
    //Give back the model.
    return model;
}
예제 #5
0
void playlistWindow::on_openplaylist_clicked(void){
	static Glib::ustring working_dir = Glib::get_home_dir();
  
  Gtk::FileChooserDialog chooser(*this,
    "Select a media to add in the playlist", Gtk::FILE_CHOOSER_ACTION_OPEN);
  chooser.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
  chooser.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
  chooser.set_current_folder(working_dir);
  
  const int response = chooser.run();
  if(response == Gtk::RESPONSE_OK)
  {
    working_dir = chooser.get_current_folder();
		if (isM3U(chooser.get_filename()) ) {
		// open the playlist source file
		std::ifstream playlistFile(chooser.get_filename());
		// read M3Usource
		std::string playlistContent(
							std::istreambuf_iterator<char>(playlistFile), //start
							(std::istreambuf_iterator<char>()) //eof
							);
	
		// locate beginning of the string
    size_t nSearchOffset = 0;
		// locate the first carriage return
    size_t nSubstringOffset = playlistContent.find (NEWLINE, 0);
		// if not EOF, loop
    while (nSubstringOffset != std::string::npos)
    {		
				// if next carriage return different of next beginning
				if (nSubstringOffset != nSearchOffset) {
					std::string strline = playlistContent.substr(nSearchOffset,nSubstringOffset-nSearchOffset);
					std::string str = strline.substr(strline.find_last_of("/")+1,strlen(strline.c_str())-strline.find_last_of("/") );					
					// store the path
					pathfilestoplay.push_back(rewriteM3UPath(strline,working_dir));
					//Fill the TreeView's model from the end
					Gtk::TreeModel::Row row = *(playlistStore->append());
					// track position
					row[playlistColumns.playlistidcol] = getSize();
					// find last dot in filename "name"
					int lastindex = str.find_last_of(".");
					// copy what comes before last dot	--> file name
					std::string name = str.substr (0,lastindex);
					row[playlistColumns.playlistnamecol] = name;
					row[playlistColumns.playlistlengthcol] = "unknown";
					// find last dot in filename
					lastindex = str.find_last_of(".");
					// copy what comes after last dot	--> file extension
					std::string fileextension = str.substr (lastindex+1,str.size()-(lastindex+1));
					//lowerize the character
					for(int i = 0; fileextension[i] != '\0'; i++){
						fileextension[i] = tolower(fileextension[i]);
					}
					row[playlistColumns.playlistformatcol] = fileextension;
					row[playlistColumns.playlistdateofcreationcol] = "unknown";
	
				}
        // Make the 'find' function search the next character onwards
        nSearchOffset = nSubstringOffset + 1;
        nSubstringOffset = playlistContent.find (NEWLINE, nSearchOffset);
    }

  } else {
		Gtk::MessageDialog dialog(*this, "File format error");
		dialog.set_secondary_text("You can only open m3u playlist files.");
		dialog.run();
		}
	}
	colorizePlaylist();
}