Esempio n. 1
0
void newJob::on_pushButton_clicked()
{
    if(!insertJob(ui->lineEdit->text()))
            QMessageBox::information(this,"Creating new job ...","The job could not be created!");
    else
            QMessageBox::information(this,"Creating new job ...","The job is created");
    this->close();

}
void PrintQueueModel::getJobFinished()
{
    KCupsRequest *request = static_cast<KCupsRequest *>(sender());
    if (request) {
        if (request->hasError()) {
//            emit error(request->error(), request->serverError(), request->errorMsg());
            // clear the model after so that the proper widget can be shown
//            clear();// TODO remove also in printerModel
        } else {
            KCupsJobs jobs = request->jobs();
            kDebug() << jobs.size();
            for (int i = 0; i < jobs.size(); ++i) {
                if (jobs.at(i).state() == IPP_JOB_PROCESSING) {
                    m_processingJob = jobs.at(i).name();
                }

                // try to find the job row
                int job_row = jobRow(jobs.at(i).id());
                if (job_row == -1) {
                    // not found, insert new one
                    insertJob(i, jobs.at(i));
                } else if (job_row == i) {
                    // update the job
                    updateJob(i, jobs.at(i));
                } else {
                    // found at wrong position
                    // take it and insert on the right position
                    QList<QStandardItem *> row = takeRow(job_row);
                    insertRow(i, row);
                    updateJob(i, jobs.at(i));
                }
            }

            // remove old printers
            // The above code starts from 0 and make sure
            // dest == modelIndex(x) and if it's not the
            // case it either inserts or moves it.
            // so any item > num_jobs can be safely deleted
            while (rowCount() > jobs.size()) {
                removeRow(rowCount() - 1);
            }
        }
        request->deleteLater();
    } else {
        kWarning() << "Should not be called from a non KCupsRequest class" << sender();
    }
    m_jobRequest = 0;
}
Esempio n. 3
0
/**
 * forks a process and launches a program as child
 */
void launchJob(char *command[], char *file, int newDescriptor,
               int executionMode)
{
        pid_t pid;
        pid = fork();
        switch (pid) {
        case -1:
                perror("R-shell(fork)");
                exit(EXIT_FAILURE);
                break;
        case 0:
                /**
                 *  we set the handling for job control signals back to the default.
                 */
                signal(SIGINT, SIG_DFL);
                signal(SIGQUIT, SIG_DFL);
                signal(SIGTSTP, SIG_DFL);
                signal(SIGCHLD, &signalHandler_child);
                signal(SIGTTIN, SIG_DFL);
                usleep(20000);                                                             // fixes a synchronization bug. Needed for short commands like ls
                setpgrp();                                                                                     // make the child as new process group leader
                if (executionMode == FOREGROUND)
                        tcsetpgrp(RSH_TERMINAL, getpid());                                           // if we want the process to be in foreground
                if (executionMode == BACKGROUND)
                        printf("[%d] %d\n", ++numActiveJobs, (int) getpid());              // inform the user about the new job in bg

                executeCommand(command, file, newDescriptor, executionMode);

                exit(EXIT_SUCCESS);
                break;
        default:
                setpgid(pid, pid);                                                                        // we also make the child a new process group leader from here
                // to avoid race conditions
                jobsList = insertJob(pid, pid, *(command), file, (int) executionMode); // insert the job in the list

                t_job* job = getJob(pid, BY_PROCESS_ID);                             // and get it as job object

                if (executionMode == FOREGROUND) {
                        putJobForeground(job, FALSE);                                              // put the job in foreground (if desired)
                }
                if (executionMode == BACKGROUND)
                        putJobBackground(job, FALSE);                                             // put the job in background (if desired)
                break;
        }
}
Esempio n. 4
0
void launchJob(char *command[], char *file, int newDescriptor,
               int executionMode)
{
        pid_t pid;
        pid = fork();
        switch (pid) {
        case -1:
                perror("MyShell");
                exit(EXIT_FAILURE);
                break;
        case 0:
                signal(SIGINT, SIG_DFL);
                signal(SIGQUIT, SIG_DFL);
                signal(SIGTSTP, SIG_DFL);
                signal(SIGCHLD, &signalHandler_child);
                signal(SIGTTIN, SIG_DFL);
                usleep(20000);
                setpgrp();
                if (executionMode == FOREGROUND)
                        tcsetpgrp(MSH_TERMINAL, getpid());
                if (executionMode == BACKGROUND)
                        printf("[%d] %d\n", ++numActiveJobs, (int) getpid());

                executeCommand(command, file, newDescriptor, executionMode);

                exit(EXIT_SUCCESS);
                break;
        default:
                setpgid(pid, pid);

                jobsList = insertJob(pid, pid, *(command), file, (int) executionMode);

                t_job* job = getJob(pid, BY_PROCESS_ID);

                if (executionMode == FOREGROUND) {
                        putJobForeground(job, FALSE);
                }
                if (executionMode == BACKGROUND)
                        putJobBackground(job, FALSE);
                break;
        }
}
Esempio n. 5
0
//ctrl+z命令挂起前台进程
void ctrlZ(){
	JOB *cur = NULL;
	if(fgPid == 0)
		return;
   	sigchld = 1;
	cur=findJob(fgPid);
    
   	if(cur == NULL)
		cur = insertJob(fgPid);
	//cur->state=(char*)malloc(STLEN);
   	strcpy(cur->state, "stopped"); 
	//cur->command=(char*)malloc(COMMLEN);
  	cur->command[strlen(cur->command)] = '&';
        cur->command[strlen(cur->command) + 1] = '\0';
   	printf("%d\t%s\t%s\n", cur->pid, cur->state, cur->command);
    
	//发送SIGTERM信号挂起前台进程
   	kill(fgPid, SIGSTOP);
        fgPid = 0;

}
Esempio n. 6
0
void kCalendar::addJob(void (*func)(), unsigned long time) {
	kJob job = {func, kCalendar_true_condition, time};
	insertJob(job);
}