Example #1
0
int deletePlaylist(FILE * fp, char * utf8file) {
	char * file = utf8ToFsCharset(utf8file);
	char * rfile = malloc(strlen(file)+strlen(".")+
			strlen(PLAYLIST_FILE_SUFFIX)+1);
	char * actualFile;

	strcpy(rfile,file);
	strcat(rfile,".");
	strcat(rfile,PLAYLIST_FILE_SUFFIX);

	if((actualFile = rpp2app(rfile)) && isPlaylist(actualFile)) free(rfile);
	else {
		free(rfile);
		commandError(fp, ACK_ERROR_NO_EXIST, 
                                "playlist \"%s\" not found", utf8file);
		return -1;
	}

	if(unlink(actualFile)<0) {
		commandError(fp, ACK_ERROR_SYSTEM,
                                "problems deleting file", NULL);
		return -1;
	}

	return 0;
}
Example #2
0
int savePlaylist(FILE * fp, char * utf8file) {
	FILE * fileP;
	int i;
	struct stat st;
	char * file;
	char * rfile;
	char * actualFile;

	if(strstr(utf8file,"/")) {
		commandError(fp, ACK_ERROR_ARG,
                                "cannot save \"%s\", saving playlists to "
				"subdirectories is not supported", utf8file);
		return -1;
	}

	file = strdup(utf8ToFsCharset(utf8file));

	rfile = malloc(strlen(file)+strlen(".")+
			strlen(PLAYLIST_FILE_SUFFIX)+1);

	strcpy(rfile,file);
	strcat(rfile,".");
	strcat(rfile,PLAYLIST_FILE_SUFFIX);

	free(file);

	actualFile = rpp2app(rfile);

	free(rfile);

	if(0==stat(actualFile,&st)) {
		commandError(fp, ACK_ERROR_EXIST, "a file or directory already " 
                                "exists with the name \"%s\"", utf8file);
		return -1;
	}

	while(!(fileP = fopen(actualFile,"w")) && errno==EINTR);
	if(fileP==NULL) {
		commandError(fp, ACK_ERROR_SYSTEM, "problems opening file", 
				NULL);
		return -1;
	}

	for(i=0;i<playlist.length;i++) {
		if(playlist_saveAbsolutePaths && 
				playlist.songs[i]->type==SONG_TYPE_FILE) 
		{
			myfprintf(fileP,"%s\n",rmp2amp(utf8ToFsCharset((
				        getSongUrl(playlist.songs[i])))));
		}
		else myfprintf(fileP,"%s\n",
				utf8ToFsCharset(getSongUrl(playlist.songs[i])));
	}

	while(fclose(fileP) && errno==EINTR);

	return 0;
}
Example #3
0
int swapSongsInPlaylist(FILE * fp, int song1, int song2) {
	int queuedSong = -1;
	int currentSong = -1;

	if(song1<0 || song1>=playlist.length) {
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "song doesn't exist: \"%i\"", song1);
		return -1;
	}
	if(song2<0 || song2>=playlist.length) {
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "song doesn't exist: \"%i\"", song2);
		return -1;
	}
	
	if(playlist_state==PLAYLIST_STATE_PLAY) {
		if(playlist.queued>=0) {
			queuedSong = playlist.order[playlist.queued];
		}
		currentSong = playlist.order[playlist.current];

		if(queuedSong==song1 || queuedSong==song2 || currentSong==song1 
				|| currentSong==song2)	
		{
			lockPlaylistInteraction();
			clearPlayerQueue();
			unlockPlaylistInteraction();
		}
	}

	swapSongs(song1,song2);
	if(playlist.random) {
		int i;
		int k;
		int j = -1;
		for(i=0;playlist.order[i]!=song1;i++) {
			if(playlist.order[i]==song2) j = i;
		}
		k = i;
		for(;j==-1;i++) if(playlist.order[i]==song2) j = i;
		swapOrder(k,j);
	}
	else {
		if(playlist.current==song1) playlist.current = song2;
		else if(playlist.current==song2) playlist.current = song1;
	}

	incrPlaylistVersion();

	return 0;
}
Example #4
0
int seekSongInPlaylist(FILE * fp, int song, unsigned time) {
	int i = song;

	if(song<0 || song>=playlist.length) {
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "song doesn't exist: \"%i\"", song);
		return -1;
	}

	if(playlist.random) for(i=0;song!=playlist.order[i];i++);

	clearPlayerError();
	playlist_stopOnError = 1;
	playlist_errorCount = 0;

	if(playlist_state == PLAYLIST_STATE_PLAY) {
		if(playlist.queued>=0) {
			lockPlaylistInteraction();
			clearPlayerQueue();
			unlockPlaylistInteraction();
		}
	}
	else if(playPlaylistOrderNumber(fp,i)<0) return -1;

	if(playlist.current!=i) {
		if(playPlaylistOrderNumber(fp,i)<0) return -1;
	}

	return playerSeek(fp, playlist.songs[playlist.order[i]], time);
}
Example #5
0
int setPlaylistRandomStatus(FILE * fp, int status) {
	int statusWas = playlist.random;

	if(status!=0 && status!=1) {
		commandError(fp, ACK_ERROR_ARG, "\"%i\" is not 0 or 1", status);
		return -1;
	}

	playlist.random = status;

	if(status!=statusWas) {
		if(playlist.random) {
			/*if(playlist_state==PLAYLIST_STATE_PLAY) {
				randomizeOrder(playlist.current+1,
						playlist.length-1);
			}
			else */randomizeOrder(0,playlist.length-1);
			if(playlist.current >= 0 && 
					playlist.current < playlist.length)
			{
				swapOrder(playlist.current, 0);
				playlist.current = 0;
			}
		}
		else orderPlaylist();
	}

	return 0;
}
Example #6
0
void argvsAnalyse(int argc, char** argv) {
	char cmd[512];
	char param[512];

	int i = 0;
	while (i < argc) {
		if (argv[i][0] == '-') {
			memset(cmd,0x00,512);
			strcpy(cmd,argv[i]);
			if (isCommandNeedParam(cmd)) {
				if (i + 1 < argc && argv[i + 1][0] != '-') {
					memset(param,0x00,512);
					strcpy(param,argv[++i]);
					doCommand(cmd,param);
				}
				else {
					commandError(cmd);
				}
			}
			else {
				doCommand(cmd,NULL);
			}
		}
		else {
			// do nothing without option
		}
		++i;
	}
	
}
Example #7
0
int handlePlayId(FILE * fp, unsigned int * permission, int argArrayLength, 
		char ** argArray) 
{
        int id = -1;
        char * test;

        if(argArrayLength==2) {
                id = strtol(argArray[1],&test,10);
                if(*test!='\0') {
                        commandError(fp, ACK_ERROR_ARG,
					 "need a positive integer", NULL);
                        return -1;
                }
        }
        return playPlaylistById(fp, id, 0);
}
Example #8
0
int setPlaylistRepeatStatus(FILE * fp, int status) {
	if(status!=0 && status!=1) {
		commandError(fp, ACK_ERROR_ARG, "\"%i\" is not 0 or 1", status);
		return -1;
	}

	if(playlist_state==PLAYLIST_STATE_PLAY) {
		if(playlist.repeat && !status && playlist.queued==0) {
			lockPlaylistInteraction();
			clearPlayerQueue();
			unlockPlaylistInteraction();
		}
	}

	playlist.repeat = status;

	return 0;
}
Example #9
0
int playPlaylist(FILE * fp, int song, int stopOnError) {
	int i = song;

	clearPlayerError();

	if(song==-1) {
		if(playlist.length == 0) return 0;

                if(playlist_state == PLAYLIST_STATE_PLAY) {
                        return playerSetPause(fp, 0);
                }
                if(playlist.current >= 0 && playlist.current < playlist.length)
                {
                        i = playlist.current;
                }
                else {
                        i = 0;
                }
        }
	else if(song<0 || song>=playlist.length) {
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "song doesn't exist: \"%i\"", song);
		return -1;
	}

	if(playlist.random) {
		if(song == -1 && playlist_state==PLAYLIST_STATE_PLAY) {
			randomizeOrder(0,playlist.length-1);
		}
		else {
			if(song>=0) for(i=0;song!=playlist.order[i];i++);
			if(playlist_state==PLAYLIST_STATE_STOP) {
				playlist.current = 0;
			}
			swapOrder(i,playlist.current);
			i = playlist.current;
		}
	}

	playlist_stopOnError = stopOnError;
	playlist_errorCount = 0;

	return playPlaylistOrderNumber(fp,i);
}
Example #10
0
int playlistInfo(FILE * fp, int song) {
	int i;
	int begin = 0;
	int end = playlist.length;

	if(song>=0) {
		begin = song;
		end = song+1;
	}
	if(song>=playlist.length) {
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "song doesn't exist: \"%i\"", song);
		return -1;
	}

	for(i=begin; i<end; i++) printPlaylistSongInfo(fp, i);

	return 0;
}
Example #11
0
int addToPlaylist(FILE * fp, char * url) {
	Song * song;

	DEBUG("add to playlist: %s\n",url);
	
	if((song = getSongFromDB(url))) {
	}
	else if(isValidRemoteUtf8Url(url) && 
                        (song = newSong(url, SONG_TYPE_URL, NULL))) 
        {
	}
	else {
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "\"%s\" is not in the music db or is "
                                "not a valid url\n", url);
		return -1;
	}

	return addSongToPlaylist(fp,song);
}
Example #12
0
void DlvClient::finishedCommandReply()
{
    m_isCommandBlock = false;
    QJsonRpcServiceReply *reply = (QJsonRpcServiceReply*)(sender());
    m_lastJsonData = reply->response().result().toVariant();
    if (reply->response().type() == QJsonRpcMessage::Error) {
        int code = reply->response().errorCode();
        QString msg = reply->response().errorMessage();
        if (msg.isEmpty()) {
            ResponseError resp;
            resp.fromMap(reply->response().toObject().toVariantMap());
            msg = resp.error;
        }
        emit commandError(code,msg);
    } else {
        CommandOut out;
        QVariant data = reply->response().result().toVariant();
        out.fromMap(data.toMap());
        emit commandSuccess(m_lastCommand.Name,out.State,data.toMap());
    }
}
Example #13
0
int commandT48(uint8_t *buffer)
{
	if( (buffer[7] > 7) || (buffer[6] > 1) )
		return commandError(buffer);
	if( buffer[6] == 0 )
	{ //чтение
		int numChanel = buffer[7];
		buffer[6] = configTerem.sensorType[numChanel];
		memcpy((void*)&buffer[7], (void*)&koeffsAB.koef[numChanel],
				10 * sizeof(float));
		return 40 + 7;
	}
	else
	{ //запись
		configTerem.sensorType[buffer[7]] = buffer[8];
		saveConfig();
		memcpy((void*)&koeffsAB.koef[buffer[7]], (void*)&buffer[9],
				10 * sizeof(float));
		saveKoeffAB();
		return 6;
	}
}
Example #14
0
int addSongToPlaylist(FILE * fp, Song * song) {
	if(playlist.length==playlist_max_length) {
		commandError(fp, ACK_ERROR_PLAYLIST_MAX,
                                "playlist is at the max size", NULL);
		return -1;
	}

	if(playlist_state==PLAYLIST_STATE_PLAY) {
		if(playlist.queued>=0 && playlist.current==playlist.length-1) {
			lockPlaylistInteraction();
			clearPlayerQueue();
			unlockPlaylistInteraction();
		}
	}

	playlist.songs[playlist.length] = song;
	playlist.songMod[playlist.length] = playlist.version;
	playlist.order[playlist.length] = playlist.length;
	playlist.positionToId[playlist.length] = getNextId();
	playlist.idToPosition[playlist.positionToId[playlist.length]] = playlist.length;
	playlist.length++;

	if(playlist.random) {
		int swap;
		int start;
		/*if(playlist_state==PLAYLIST_STATE_STOP) start = 0;
		else */if(playlist.queued>=0) start = playlist.queued+1;
		else start = playlist.current+1;
                if(start < playlist.length) {
		        swap = random()%(playlist.length-start);
		        swap+=start;
		        swapOrder(playlist.length-1,swap);
                }
	}
	
	incrPlaylistVersion();

	return 0;
}
Example #15
0
int loadPlaylist(FILE * fp, char * utf8file) {
	FILE * fileP;
	char s[MAXPATHLEN+1];
	int slength = 0;
	char * temp = strdup(utf8ToFsCharset(utf8file));
	char * rfile = malloc(strlen(temp)+strlen(".")+
			strlen(PLAYLIST_FILE_SUFFIX)+1);
	char * actualFile;
	char * parent = parentPath(temp);
	int parentlen = strlen(parent);
	char * erroredFile = NULL;
	int tempInt;
	int commentCharFound = 0;

	strcpy(rfile,temp);
	strcat(rfile,".");
	strcat(rfile,PLAYLIST_FILE_SUFFIX);

	free(temp);

	if((actualFile = rpp2app(rfile)) && isPlaylist(actualFile)) free(rfile);
	else {
		free(rfile);
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "playlist \"%s\" not found", utf8file);
		return -1;
	}

	while(!(fileP = fopen(actualFile,"r")) && errno==EINTR);
	if(fileP==NULL) {
		commandError(fp, ACK_ERROR_SYSTEM,
                                "problems opening file \"%s\"", utf8file);
		return -1;
	}

	while((tempInt = fgetc(fileP))!=EOF) {
		s[slength] = tempInt;
		if(s[slength]=='\n' || s[slength]=='\0') {
			commentCharFound = 0;
			s[slength] = '\0';
			if(s[0]==PLAYLIST_COMMENT) {
				commentCharFound = 1;
			}
			if(strncmp(s,musicDir,strlen(musicDir))==0) {
				strcpy(s,&(s[strlen(musicDir)]));
			}
			else if(parentlen) {
				temp = strdup(s);
				memset(s,0,MAXPATHLEN+1);
				strcpy(s,parent);
				strncat(s,"/",MAXPATHLEN-parentlen);
				strncat(s,temp,MAXPATHLEN-parentlen-1);
				if(strlen(s)>=MAXPATHLEN) {
					commandError(fp, 
                                                        ACK_ERROR_PLAYLIST_LOAD,
                                                        "\"%s\" too long",
                                                        temp);
					free(temp);
					while(fclose(fileP) && errno==EINTR);
					if(erroredFile) free(erroredFile);
					return -1;
				}
				free(temp);
			}
			slength = 0;
			temp = fsCharsetToUtf8(s);
			if(!temp) continue;
			temp = strdup(temp);
			if(commentCharFound && !getSongFromDB(temp)
					&& !isRemoteUrl(temp)) 
			{
				free(temp);
				continue;
			}
			if((addToPlaylist(stderr,temp))<0) {
				if(!erroredFile) erroredFile = strdup(temp);
			}
			free(temp);
		}
		else if(slength==MAXPATHLEN) {
			s[slength] = '\0';
			commandError(fp, ACK_ERROR_PLAYLIST_LOAD,
                                        "line in \"%s\" is too long", utf8file);
			ERROR("line \"%s\" in playlist \"%s\" is too long\n",
				s, utf8file);
			while(fclose(fileP) && errno==EINTR);
			if(erroredFile) free(erroredFile);
			return -1;
		}
		else if(s[slength]!='\r') slength++;
	}

	while(fclose(fileP) && errno==EINTR);

	if(erroredFile) {
		commandError(fp, ACK_ERROR_PLAYLIST_LOAD,
                                "can't add file \"%s\"", erroredFile);
		free(erroredFile);
		return -1;
	}

	return 0;
}
Example #16
0
int moveSongInPlaylist(FILE * fp, int from, int to) {
	int i;
	Song * tmpSong;
	int tmpId;
	int queuedSong = -1;
	int currentSong = -1;

	if(from<0 || from>=playlist.length) {
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "song doesn't exist: \"%i\"", from);
		return -1;
	}

	if(to<0 || to>=playlist.length) {
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "song doesn't exist: \"%i\"", to);
		return -1;
	}

	
	if(playlist_state==PLAYLIST_STATE_PLAY) {
		if(playlist.queued>=0) {
			queuedSong = playlist.order[playlist.queued];
		}
		currentSong = playlist.order[playlist.current];
		if(queuedSong==from || queuedSong==to || currentSong==from ||
				currentSong==to)
		{
			lockPlaylistInteraction();
			clearPlayerQueue();
			unlockPlaylistInteraction();
		}
	}

	tmpSong = playlist.songs[from];
	tmpId = playlist.positionToId[from];
	/* move songs to one less in from->to */
	for(i=from;i<to;i++) {
		moveSongFromTo(i+1, i);
	}
	/* move songs to one more in to->from */
	for(i=from;i>to;i--) {
		moveSongFromTo(i-1, i);
	}
	/* put song at _to_ */
	playlist.idToPosition[tmpId] = to;
	playlist.positionToId[to] = tmpId;
	playlist.songs[to] = tmpSong;
	playlist.songMod[to] = playlist.version;
	/* now deal with order */
	if(playlist.random) {
		for(i=0;i<playlist.length;i++) {
			if(playlist.order[i]>from && playlist.order[i]<=to) {
				playlist.order[i]--;
			}
			else if(playlist.order[i]<from && 
					playlist.order[i]>=to) {
				playlist.order[i]++;
			}
			else if(from==playlist.order[i]) {
				playlist.order[i] = to;
			}
		}
	}
	else if(playlist.current==from) playlist.current = to;
	else if(playlist.current>from && playlist.current<=to) {
		playlist.current--;
	}
	else if(playlist.current>=to && playlist.current<from) {
		playlist.current++;
	}

	incrPlaylistVersion();

	return 0;
}
Example #17
0
int deleteFromPlaylist(FILE * fp, int song) {
	int i;
	int songOrder;

	if(song<0 || song>=playlist.length) {
		commandError(fp, ACK_ERROR_NO_EXIST,
                                "song doesn't exist: \"%i\"", song);
		return -1;
	}

	if(playlist_state==PLAYLIST_STATE_PLAY) {
		if(playlist.queued>=0 && (playlist.order[playlist.queued]==song
			|| playlist.order[playlist.current]==song)) 
		{
			lockPlaylistInteraction();
			clearPlayerQueue();
			unlockPlaylistInteraction();	
		}
	}

	if(playlist.songs[song]->type == SONG_TYPE_URL) {
		freeJustSong(playlist.songs[song]);
	}

	playlist.idToPosition[playlist.positionToId[song]] = -1;

	/* delete song from songs array */
	for(i=song;i<playlist.length-1;i++) {
		moveSongFromTo(i+1, i);
	}
	/* now find it in the order array */
	for(i=0;i<playlist.length-1;i++) {
		if(playlist.order[i]==song) break;
	}
	songOrder = i;
	/* delete the entry from the order array */
	for(;i<playlist.length-1;i++) playlist.order[i] = playlist.order[i+1];
	/* readjust values in the order array */
	for(i=0;i<playlist.length-1;i++) {
		if(playlist.order[i]>song) playlist.order[i]--;
	}
	/* now take care of other misc stuff */
	playlist.songs[playlist.length-1] = NULL;
	playlist.length--;

	incrPlaylistVersion();

	if(playlist_state!=PLAYLIST_STATE_STOP && playlist.current==songOrder) {
		/*if(playlist.current>=playlist.length) return playerStop(fp);
		else return playPlaylistOrderNumber(fp,playlist.current);*/
		playerStop(stderr);
		playlist_noGoToNext = 1;
	}

	if(playlist.current>songOrder) {
		playlist.current--;
	}
	else if(playlist.current>=playlist.length) {
		incrPlaylistCurrent();
	}

	if(playlist.queued>songOrder) {
		playlist.queued--;
	}

	return 0;
}