Exemplo n.º 1
0
bool TvShowProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
    QVariant leftData = sourceModel()->data(left,this->sortRole());
    QVariant rightData = sourceModel()->data(right,this->sortRole());



    if(leftData.type() == QVariant::Date)
    {
        QDate ldate(leftData.toDate());
        QDate rdate(rightData.toDate());

        if (!ldate.isValid())
        {
            return false;
        }
        else if (!rdate.isValid())
        {
            return true;
        }
        else
        {
            return ldate < rdate;
        }
    }
    else
    {
        qDebug() << "ProxyModel::lessThan: incoming data was not a QDate";
        return false;
    }
}
Exemplo n.º 2
0
static int
showdrec(int fd, int fmt, void *x)
{
	Drec *d = (Drec *)x;
	int namelen;
	int syslen;

	if(d->reclen == 0)
		return 0;
	fprint(fd, "%d %d %ld %ld ",
		d->reclen, d->attrlen, l32(d->addr), l32(d->size));
	fprint(fd, "%s 0x%2.2x %d %d %ld ",
		rdate(d->date, fmt), (fmt=='z' ? d->flags : d->r_flags),
		d->unitsize, d->gapsize, l16(d->vseqno));
	fprint(fd, "%d %s", d->namelen, nstr(d->name, d->namelen));
	if(fmt != 'J'){
		namelen = d->namelen + (1-(d->namelen&1));
		syslen = d->reclen - 33 - namelen;
		if(syslen != 0)
			fprint(fd, " %s", nstr(&d->name[namelen], syslen));
	}
	fprint(fd, "\n");
	return d->reclen + (d->reclen&1);
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
  int i;
  int print_mode = 0, set_mode = 0;
  char **hosts = NULL;
  int nhosts = 0;
  int retval = 0;
  int success = 0;
  
#ifdef EMBED
  program_invocation_short_name = argv[0];
#endif
  for(i = 1; i < argc; i++)
    {
      switch(argv[i][0])
	{
	case '-':
	  switch(argv[i][1])
	    {
	    case 's':
	      set_mode = 1;
	      break;
	    case 'p':
	      print_mode = 1;
	      break;
	    case 'h':
	    case '?':
	      usage(0);
	      break;
	    default:
	      fprintf(stderr, "Unknown option %s\n", argv[i]);
	      break;
	    }
	  break;
	default:
	  hosts = realloc(hosts, sizeof(char *) * nhosts+1);
	  hosts[nhosts++] = argv[i];
	  break;
	}
    }

  if(!set_mode && !print_mode)
    print_mode = 1;

  for(i = 0; i < nhosts; i++)
    {
      time_t timeval;
      if(!rdate(hosts[i], &timeval))
	{
	  /* keep track of the succesful request */
	  success = 1;
	  
	  if(print_mode)
	    printf("[%s]\t%s", hosts[i], ctime(&timeval) /* ctime includes a trailing \n */);

	  /* Do specified action(s) */
	  if(set_mode && stime(&timeval) < 0)
	    {
	      fprintf(stderr, "%s: could not set system time: %s\n", program_invocation_short_name, strerror(errno));
	      retval = 1;
	      break;
	    }
	  set_mode = 0;
	}
    }

  if(!nhosts)
    usage(1);

  if (!retval && !success) retval = 1;
  return retval;
}
Exemplo n.º 4
0
Arquivo: rdate.c Projeto: njh/rdate
int main(int argc, char *argv[])
{
	int set_mode = 0;
	int adjust_time = 0;
	int time_difference = 0;
	int retval = 0;
	int success = 0;
	int c;


	// Store the name of the program
	argv0 = strrchr(argv[0], '/');
	if (argv0)	argv0++;
	else		argv0 = argv[0];


	// Parse parameters 
	while ((c = getopt(argc, argv, "aspuln:t:d:h?")) != -1) {
	
		switch(c) {
			case 'a': adjust_time = 1; break;
			case 's': set_mode = 1;	break;
			case 'p': print_mode = 1; break;
			case 'u': use_tcp = 0; break;
			case 'l': log_mode = 1; break;
			case 't': timeout = atoi(optarg); break;
			case 'd': time_difference = atoi(optarg); break;
			case 'n': service = optarg; break;
			case 'h':
			case '?':
				usage(0);
			break;
			default:
				fprintf(stderr, "Unknown option %c\n", c);
				usage(1);
			break;	
		}
		
	}
	
	// Remove the already parsed parameters
	argc -= optind;
	argv += optind;

	// No hosts on command line ?
	if (argc<1) usage(1);


	if (!set_mode && !print_mode)	print_mode = 1;
	if (log_mode)					openlog(argv0, LOG_PID, LOG_CRON);



	// Query each of the servers on the command line
	for(; argc-- ; argv++)
    {
		time_t timeval=0;
		char timestr[26];

		if(!rdate(*argv, &timeval)) {
			// keep track of the succesful request
			success = 1;

            // apply the requested difference
            timeval += time_difference;

			// Convert the time to a string
			ctime_r( &timeval, timestr );
			timestr[ strlen(timestr)-1 ] = 0;

			write_log(0, "[%s]\t%s", *argv, timestr);


			// Set local time to remote host's ?
			if (set_mode)
			{
				struct timeval tv;
				
				if (!adjust_time) {
					logwtmp("|", "date", "");
					tv.tv_sec = timeval;
					tv.tv_usec = 0;
					if (settimeofday(&tv, NULL)) {
						write_log(1, "could not set system time: %s", strerror(errno));
						retval = 1;
						break;
					}
					logwtmp("{", "date", "");
				} else {
					struct timeval tv_now;

					if (gettimeofday(&tv_now, NULL) == -1) {
						write_log(1, "could not get system time: %s", strerror(errno));
						retval = 1;
						break;
					}
					tv.tv_sec = timeval - tv_now.tv_sec;
					tv.tv_usec = 0;

					write_log(0, "adjusting local clock by %d seconds.", tv.tv_sec);
					if (adjtime(&tv, NULL)) {
						write_log(1, "could not adjust system time: %s", strerror(errno));
						retval = 1;
						break;
					}
				}
				
				// Only set time to first successful host
				set_mode = 0;
			}
		}
    }



	// Close the log
	if (log_mode) closelog();


	// Successful ?
	if (!retval && !success)
		retval = 1;

	return retval;
}