void MessageColorListWidgetItemDelegate::paint(QPainter * p, const QStyleOptionViewItem & opt, const QModelIndex & index) const
{

	if(opt.state & QStyle::State_Selected)
	{
		QColor clr;
		const KviTalListWidget *lb = (const KviTalListWidget *)parent();
		MessageColorListWidgetItem *it = static_cast<MessageColorListWidgetItem*>(index.internalPointer());

		if((it->clrIdx() >= 0) && (it->clrIdx() <= 15))
		{
			clr = KVI_OPTION_MIRCCOLOR(it->clrIdx());
		} else {
			clr =lb->palette().color(QPalette::Window);
		}

		QStyleOptionViewItem optz(opt);
		optz.state = opt.state ^ QStyle::State_Selected;
		QItemDelegate::paint(p, optz, index);

		QPen pen(QColor(255-clr.red(), 255-clr.green(), 255-clr.blue()));
		pen.setStyle(Qt::DashLine);
		p->setPen(pen);
		p->drawRect(opt.rect.adjusted(0,0,-1,-1));
		p->drawRect(opt.rect.adjusted (1,1,-2,-2));
		p->drawRect(opt.rect.adjusted (2,2,-3,-3));
	} else {
		QItemDelegate::paint(p, opt, index);
	}
}
Exemple #2
0
int put_command( struct modem *mdm, char* cmd, int cmd_len, char* answer,
											int max, int timeout,char* exp_end)
{
	static char buf[MAX_BUF];
	static int  buf_len = 0;
	char* pos;
	char* foo;
	char* ptr;
	char* to_move;
	char* answer_s;
	char* answer_e;
	int   timeoutcounter;
	int   available;
	int   status;
	int   exp_end_len;
	int   n;

	/* check if fd is "clean" for reading */
	timeoutcounter = 0;
	ioctl(mdm->fd,TIOCMGET,&status);
	while (!(status & TIOCM_CTS))
	{
		usleep( READ_SLEEP );
		timeoutcounter++;
		ioctl(mdm->fd,TIOCMGET,&status);
		if (timeoutcounter>=timeout) {
			LOG(L_INFO,"INFO:put_command: Modem is not clear to send\n");
			return 0;
		}
	}
#ifdef SHOW_SMS_MODEM_COMMAND
	DBG("DEBUG: put_command: -<%d>-->[%.*s] \n",cmd_len,cmd_len,cmd);
#endif
	/* send the command to the modem */
	write(mdm->fd,cmd,cmd_len);
	tcdrain(mdm->fd);

	/* read from the modem */
	exp_end_len = exp_end?strlen(exp_end):0;
	answer_s = buf;
	answer_e = 0;
	to_move = 0;
	do
	{
		/* try to read some bytes */
		ioctl(mdm->fd,FIONREAD,&available);
		/* how many bytes are available to read? */
		if (available<1)  /* if 0 then wait a little bit and retry */
		{
			usleep( READ_SLEEP );
			timeoutcounter++;
			ioctl(mdm->fd,FIONREAD,&available);
		}
		if (available>0)
		{
			/* How many bytes do I want to read maximum?
			Not more than buffer size. And how many bytes are available? */
			n = (available>MAX_BUF-buf_len-1)?MAX_BUF-buf_len-1:available;
			/* read data */
			n = read( mdm->fd, buf+buf_len, n);
			if (n<0) {
				LOG(L_ERR,"ERROR:put_command: error reading from modem: %s\n",
					strerror(errno));
				goto error;
			}
			if (n) {
				buf_len += n;
				buf[buf_len] = 0;
				//DBG("DEBUG:put_commnad: read = [%s]\n",buf+buf_len-n);
				foo = pos = 0;
				if ( (!exp_end && ((pos=strstr(optz(n,4),"OK\r\n"))
				|| (foo=strstr(optz(n,5),"ERROR"))))
				|| (exp_end && (pos=strstr(optz(n,exp_end_len),exp_end)) )) {
					/* we found the end */
					//DBG("DEBUG:put_commnad: end found = %s\n",
					//	(foo?"ERROR":(exp_end?exp_end:"OK")));
					/* for ERROR we still have to read EOL */
					if (!foo || (foo=strstr(foo+5,"\r\n"))) {
						answer_e = foo?foo+2:(pos+(exp_end?exp_end_len:4));
						timeoutcounter = timeout;
					}
				}
			}
		}
	/* repeat until timout */
	}while (timeoutcounter<timeout);

	if (!answer_e)
		answer_e = buf+buf_len;

	/* CDS report is activ? */
	if (sms_report_type==CDS_REPORT) {
		to_move = 0;
		ptr = buf;
		/* do we have a CDS reply inside? */
		while ( (pos=strstr(ptr,CDS_HDR)) ) {
			if (pos!=ptr) {  /* here we have the command response */
				answer_s = ptr;
			}
			/* look for the end of CDS response */
			ptr = pos+CDS_HDR_LEN;
			for( n=0 ; n<2&&(foo=strstr(ptr,"\r\n")) ; ptr=foo+2,n++ );
			if (n<2) { /* we haven't read the entire CDS response */
				DBG("DEBUG:put_command: CDS end not found!\n");
				to_move = pos;
				ptr = buf + buf_len;
			}else{
				/* process the CDS */
				DBG("DEBUG:put_command:CDS=[%.*s]\n",(int)(ptr-pos),pos);
				cds_report_func(mdm,pos,ptr-pos);
			}
		}
		if ((*ptr)) {
			answer_s = ptr;
			ptr = answer_e;
		}
		if (ptr!=buf+buf_len)
			to_move = ptr;
	}

	/* copy the response in answer buffer - as much as fits */
	if (answer && max) {
		n = max-1<answer_e-answer_s?max-1:answer_e-answer_s;
		memcpy(answer,answer_s,n);
		answer[n] = 0;
	}
	/* shift left the remaining data into the buffer - if needs */
	if (sms_report_type==CDS_REPORT && to_move) {
		buf_len = buf_len - (to_move-buf);
		memcpy(buf,to_move,buf_len);
		buf[buf_len] = 0;
		DBG("DEBUG:put_commnad: buffer shifted left=[%d][%s]\n",buf_len,buf);
	} else {
		buf_len = 0;
	}

#ifdef SHOW_SMS_MODEM_COMMAND
	DBG("DEBUG:put_command: <-[%s] \n",answer);
#endif
	return answer_e-answer_s;

error:
	return 0;
}
Exemple #3
0
int put_command(char *cmd, int cmd_len, char *answer, int max, int timeout, char *exp_end)
{
        int timeoutcounter = 0;
        // Send the command to the modem
        info("Serial Tx: %.*s", cmd_len, cmd);
        write(g_serial_fd, cmd, cmd_len);
        tcdrain(g_serial_fd);

        // Read from the modem
        int buf_len = 0;
        int available;
        int n;
        static char buf[MAX_BUF];
        char *foo, *pos, *answer_e, *answer_s;
        int exp_end_len;

        exp_end_len = exp_end ? strlen(exp_end) : 0;
        answer_s = buf;
        answer_e = 0;

        do {
                // try to read some bytes
                ioctl(g_serial_fd, FIONREAD, &available);
                if(available < 1) {
                        usleep(READ_SLEEP);
                        timeoutcounter++;
                        ioctl(g_serial_fd, FIONREAD, &available);
                }
                if(available > 0) {
                        n = (available > MAX_BUF-buf_len-1)?MAX_BUF-buf_len-1:available;
		        info("Reading %d chars from modem", n);
                        // read data
                        n = read(g_serial_fd, buf+buf_len, n);
                        if(n<0) {
                                err_strerror("error reading from modem");
                                goto error;
                        }
                        if(n) {
                                buf_len += n;
                                buf[buf_len] = 0;
                                foo = pos = 0;
                                if ( (!exp_end && ((pos = strstr(optz(n,4),"OK\r\n"))
                                                   || (foo=strstr(optz(n,5),"ERROR"))))
                                                || (exp_end && (pos=strstr(optz(n,exp_end_len),exp_end)) )) {

                                        if(!foo || (foo=strstr(foo+5,"\r\n"))) {
                                                answer_e = foo?foo+2:(pos+(exp_end?exp_end_len:4));
                                                timeoutcounter = timeout;
                                        }
                                }
                        }
                }
        } while(timeoutcounter < timeout);

        if (!answer_e)
                answer_e = buf+buf_len;

        if(answer && max) {
                n = max-1<answer_e-answer_s?max-1:answer_e-answer_s;
                memcpy(answer,answer_s,n);
                answer[n] = 0;
        }

        // show modem command
        info("Serial Rx: %s", answer);
	
        return answer_e-answer_s;

error:
        return 0;
}