Example #1
0
void is_this_first_run(char *progname)
{
	if (checkfirstrun(progname)) {
		// drop root priviledge first
		firstrun("autosd", "autosd.cfg", NULL);
		printf("A configuration file 'autosd.cfg' has been installed "
		"at $HOME/.config/autosd/. \nPlease edit this file to meet your"
		" requirements.\n");
		exit(EXIT_SUCCESS);
	}
} // is_this_first_run()
Example #2
0
TextIn::TextIn(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::TextIn)
{
    ui->setupUi(this);
    ui->buttonBox->button(QDialogButtonBox::Cancel)->hide();
    ui->buttonBox->button(QDialogButtonBox::Ok)->setText("&Send");
    ui->lenLabel->setText("0/"+QString::number(MAX_LEN));

    m_settingsDlg = new SettingsDialog(this);
    firstrun();

    m_waitingToLogin = false;
    m_talker = new Talker(this);
    connect(m_talker, SIGNAL(loginFinished(bool)), this, SLOT(loginDone(bool)));
    connect(m_talker, SIGNAL(sendFinished()), this, SLOT(sendDone()));
    login();
}
Example #3
0
int main(int argc, char **argv)
{
	int opt, numcolon;
	int totsec, seconds, minutes, hours;
	fdata sfd;
	time_t now;
	char *user, *start, *end, *prog2run, *mov2show, *timespec;
	char userbuf[FILENAME_MAX];
	char *fmt = "/home/%s/.config/alarm/alarm.txt";
	int cookingmode;
	int ampm = 0;
	// defaults
	cookingmode = 1;
	while((opt = getopt(argc, argv, ":ha")) != -1) {
		switch(opt) {
		case 'h':
			dohelp(0);
		break;
		case 'a':
			// absolute time of day ie alarm clock mode;
			cookingmode = 0;
		break;
		case ':':
			fprintf(stderr, "Option %c requires an argument\n",optopt);
			dohelp(1);
		break;
		case '?':
			fprintf(stderr, "Unknown option: %c\n",optopt);
			dohelp(1);
		break;
		} //switch()
	}//while()
	// now process the non-option arguments

	now = time(NULL);

	// 1.Check that argv[???] exists.
	if (!(argv[optind])) {
		fprintf(stderr, "No time specifier provided.\n");
		dohelp(1);
	}
	timespec = argv[optind];
	optind++;
	// go look for am or pm
	if (argv[optind]) {
		char *cp = argv[optind];
		if (*cp == 'P' || *cp == 'p') ampm = 1;
		// and it just doesn't matter if there is a following M|m or not
	}
	// Read my config file
	user = getenv("USER");
	sprintf(userbuf,  fmt, user);
	sfd = readfile(userbuf, 0, 0);
	if(sfd.from) {
		start = sfd.from;
		end = sfd.to;
	} else {
		firstrun("alarm", "alarm.txt");
		user = getenv("HOME");
		char advice[NAME_MAX];
		sprintf(advice, "Installed alarm.txt at %s.config/alarm/\n",
				user);
		fputs(advice, stderr);
		fputs("Please edit that file to suit your needs.\n", stderr);
		exit(EXIT_SUCCESS);
	}

	prog2run = getactdata(start, end, "program");
	mov2show = getactdata(start, end, "data");

	// now deal with the users timespec
	numcolon = countchars(timespec, ':');
	hours = minutes = seconds = 0;
	char *wstr = strdup(timespec);
	char *tofree = wstr;	// wstr gets altered.
	switch(numcolon) {
		char *cp;
		case 0:
		// the number is minutes;
		if (strlen(wstr)) minutes = strtol(wstr, NULL, 10);
		break;
		case 1:
		// have mm:ss or :ss or mm:
		cp = strchr(wstr, ':');
		*cp = '\0';
		if (strlen(wstr)) minutes = strtol(wstr, NULL, 10);
		cp++; // look at the second half
		wstr = cp;
		if (strlen(wstr)) seconds = strtol(wstr, NULL, 10);
		break;
		case 2:
		// have hh:mm:ss or hh:mm:
		cp = strchr(wstr, ':');
		*cp = '\0';
		if (strlen(wstr)) hours = strtol(wstr, NULL, 10);
		cp++; // next part
		wstr = cp;
		cp = strchr(wstr, ':');
		*cp = '\0';
		if (strlen(wstr)) minutes = strtol(wstr, NULL, 10);
		cp++;
		wstr = cp;
		if (strlen(wstr)) seconds = strtol(wstr, NULL, 10);
		break;
		default:
		fprintf(stderr,
				"Badly formed time specification: %s\n", timespec);
		exit(EXIT_FAILURE);
		break;
	}
	free(tofree);
	// total seconds to elapse before alarm
	if (ampm) {
		if (!(cookingmode)) {
			if (hours < 12) hours += 12;
		}
	}
	if(!(cookingmode)) { // used as an alarm clock, not cooking timer
		totsec = addclocktime(now, hours, minutes, seconds);
	} else {
		totsec = seconds + 60 * minutes + 3600 * hours;
	}
	printf("Total seconds: %d\n", totsec);
	// report every 60 seconds
	int aminute = 60;	// seconds
	while (aminute < totsec) {
		sleep(aminute);
		totsec -= aminute;
		if (cookingmode) {
			fprintf(stdout, "Remaining: %d seconds.\n", totsec);
		}
	}
	sleep(totsec);
	runit(prog2run, mov2show);
	return 0;
}//main()