示例#1
0
bool historymanager::addhistory(QWebHistory  * history)
{
    for(int i = 0;i < history->count();i++)
    {
        const QWebHistoryItem item = history->itemAt(i);
        addhistory(item.title() , item.url().toString() , item.lastVisited());
    }
    return true;
}
示例#2
0
webview::webview(QWidget *parent) :
    QWebView(parent)
{
    setAttribute(Qt::WA_DeleteOnClose);
    settings()->setAttribute(QWebSettings::DnsPrefetchEnabled , true);
    settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows , true);
    settings()->setAttribute(QWebSettings::JavascriptCanCloseWindows , true);
    settings()->setAttribute(QWebSettings::JavascriptCanAccessClipboard , true);
    settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled , true);
    settings()->setAttribute(QWebSettings::LocalStorageEnabled , true);
    settings()->setAttribute(QWebSettings::JavaEnabled , true);
    settings()->setAttribute(QWebSettings::LocalStorageEnabled , true);
    settings()->enablePersistentStorage(QApplication::applicationDirPath());
    QObject::connect(this , SIGNAL(urlChanged(QUrl)) , this , SLOT(addhistory(QUrl)));
    QObject::connect(this , SIGNAL(titleChanged(QString)) , this , SLOT(updatetitle(QString)));
}
示例#3
0
int main()
{
    int status;
    // command variable
    char *args[20];
    int i;
    for (i = 0; i < 20; ++i)
    {
        args[i] = NULL;
    }

    // background variable
    int bg;

    // history variables
    int historynbr = 1;
    int *toBeSaved = mmap(NULL, sizeof(int), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
    struct cmd **history =  mmap(NULL, sizeof(struct cmd), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
    int notInitialized = 1;
    while(notInitialized) {
        int i;
        for (i = 0; i < 10; i++) {
            history[i] = (struct cmd*) malloc(sizeof(struct cmd));
        }
        notInitialized = 0;
    }

    // job variable
    struct job * head = NULL;

    
    printf("\n-----------------------------------------\nWelcome!\nThis is a simple shell. \nEnter 'help' for more info.\n-----------------------------------------\n\n");

    while (1) {
        int cnt = getcmd("\n>> ", args, &bg); 

        // int i;
        // for (i = 0; i < cnt; i++)
        //     printf("\nArg[%d] = %s", i, args[i]);

        // if (bg)
        //     printf("\nBackground enabled..\n");
        // else
        //     printf("\nBackground not enabled \n");

        printf("\n");



        /**********************************/
        /******** INTERNAL COMMAND ********/
        /**********************************/

        // HISTORY
        if (cnt != 0 && isnumber(args[0])) {
                int nbr =  stringtoint(args[0]);
                *toBeSaved = 0;
                // find the index of the command in the history, if it is there
                int index = searchhistory(history, nbr);
                if (index == -1){
                    printf("***ERROR  command ID '%s' does not exist\n\n", args[0]);
                }
                else {                
                    int j;
                    for (j = 0; j < 20; j++) {
                        args[j] = history[index]->args[j];
                    }

                    //check is it was in backgorund
                    int bgIndex;
                    if ((bgIndex = isbg(args)) > 0) {
                        bg = 1;
                        args[bgIndex] = NULL;
                    }
                }
        }

        // if nothing is entered
        if(cnt == 0){
            // do nothing
        }

        // HELP
        else if (strcmp(args[0], "help") == 0){
            printf("This is a simple shell brought to you by Felix Dube\n\nIt keeps the last 10 commands in HISTORY.\nEnter 'history' to see the list of commands in history.\n\nProcess can be run un BACKGROUND using the '&' argument.\nEnter 'jobs' to see the list of process running in background\nEnter 'fg' and the process job number to bring a process in the forground.\n\n");
        }

        // PRINT HISTORY
        else if (strcmp(args[0], "history") == 0) {
            printhistory(history);
            initargs(args);
        }
         // PRESENT WORKING DIRECTORY
        else if( strcmp(args[0], "pwd") == 0) {
            char* cwd;
            char buff[PATH_MAX + 1];

            cwd = getcwd( buff, PATH_MAX + 1 );
            if( cwd != NULL ) {
                printf( "My working directory is %s.\n", cwd );
            }
            addhistory(history, args, historynbr);
            historynbr++;
            initargs(args);
        }
        
        // CHANGE DIRECTORY
        else if( strcmp(args[0], "cd") == 0 ){
            chdir(args[1]);
            addhistory(history, args, historynbr);
            historynbr++;
            initargs(args);
       }

        // JOBS
        else if( strcmp(args[0], "jobs") == 0) {
            printjobs(&head);
            addhistory(history, args, historynbr);
            historynbr++;
            initargs(args);
        }

        // FOREGROUND
        else if( strcmp(args[0], "fg") == 0) {
            addhistory(history, args, historynbr);
            historynbr++;
            if (jobexist(head, stringtoint(args[1]))){
                waitpid(stringtoint(args[1]), &status, 0);
            }
            else{
                printf("***ERROR  job PID '%s' does not exist\n\n", args[1]);
            }
            initargs(args);
        }

        // EXIT
        else if ( strcmp(args[0], "exit") == 0){
            exit(0);

        }



        /**********************************/
        /******** EXTERNAL COMMAND ********/
        /**********************************/

        else if (cnt != 0) {
            *toBeSaved = 1;

            pid_t pid = fork();
            


            /**** PARENT ****/
            // the parent process either wait for the child process or not 
            // depending if the command is executed in background or not

            if ( pid != 0 ) {
                if (bg) {
                    pushjob(&head, pid, args);
                    // save the cmd if it was valid and not already in the history
                    if(*toBeSaved){
                        int i = 0;
                        while(args[i] != NULL){
                            i++;
                        }
                        args[i] = "&";
                        addhistory(history, args, historynbr);
                        historynbr++;
                    }
                    initargs(args);
                }
                else {
                    waitpid(pid, &status, 0);
                    // save the cmd if it was valid and not already in the history
                    if(*toBeSaved){
                        addhistory(history, args, historynbr);
                        historynbr++;
                    }
                    initargs(args);
                }
            }



            /**** CHILD ****/
            // the command is exucuted in the child process

            else {

                if (cnt != 0 && isnumber(args[0])){
                    exit(0);
                }

                // change the output of the process when specified (eg. ls > out.txt)
                int argNbr;
                if ((argNbr = isredirected(args)) > 0){
                    freopen(args[argNbr+1], "w", stdout);
                    args[argNbr] = NULL;
                    args[argNbr+1] = NULL;
                }

                // execute the command and make sure it is valid
                if (execvp(args[0], args) == -1) {
                    *toBeSaved = 0;
                    printf("***ERROR  invalid command\n");
                }
            }
        }
    }
}
示例#4
0
bool historymanager::addhistory(QString title, QString url)
{
    return addhistory(title , url , QDateTime::currentDateTime());
}