Esempio n. 1
0
/*
 * Print the directory. Only draw from "cur" to bottom.
 */
static void prdir(WIN *dirw, int top, int cur,
                  GETSDIR_ENTRY *dirdat, int longest)
{
  int f, start;
  char f_str[BUFSIZ];
  char t_str[BUFSIZ];

  start = cur - top;
  dirflush = 0;
  sprintf(f_str, " %%-%ds", longest + 2);
  mc_wlocate(dirw, 0, start + FILE_MWTR);
  for (f = start; f < dirw->ys - (1 + FILE_MWTR); f++) {
    GETSDIR_ENTRY *d;
    if (!(d = getno(f + top, dirdat)))
      break;
    if (d->cflags & FL_TAG)
      mc_wsetattr(dirw, XA_REVERSE | stdattr);
    if (S_ISDIR(d->mode)) {
      snprintf(t_str, sizeof(t_str), "[%s]", d->fname);
      mc_wprintf(dirw, f_str, t_str);
    } else
      mc_wprintf(dirw, f_str, d->fname);
    mc_wsetattr(dirw, XA_NORMAL | stdattr);
    mc_wputc(dirw, '\n');
  }
  dirflush = 1;
  mc_wflush();
}
Esempio n. 2
0
/*
 * Draw the file directory.
 *
 *      howmany - How many files can be selected
 *		      0 = none (for directory selection only, as in "rz")
 *		      1 = one  (for single-file up-/down-loads, as in "rx")
 *		     -1 = any number (for multiple files, as in "sz")
 *
 *    downloading - Is this for download selection?
 *		      0 = no
 *		      1 = yes - when single file selected, see if it exists
 */
char * filedir(int howmany, int downloading)
{
  time_t click_time = (time_t) 0;
  size_t i;

  how_many = howmany;
  down_loading = downloading;
  init_filedir();

again:
  mc_wlocate(main_w, 0, cur + FILE_MWTR - top);
  if (first) {
    mc_wredraw(main_w, 1);
    first = 0;
  }
  while (!quit) {
    GETSDIR_ENTRY *d = getno(cur, global_dirdat);
    /*
       if(S_ISDIR(d->mode))
       prone(main_w, d, longest, 0);	
       */
    switch (c = wxgetch()) {
      case K_UP:
      case 'k':
        /*
         if(S_ISDIR(d->mode))
         prone(main_w, d, longest, 1);	
         */
        cur -= cur > 0;
        break;
      case K_DN:
      case 'j':
        /*
         if(S_ISDIR(d->mode))
         prone(main_w, d, longest, 1);
         */
        cur += cur < nrents - 1;
        break;
      case K_LT:
      case 'h':
        subm--;
        if (subm < 0)
          subm = SUBM_OKAY;
        break;
      case K_RT:
      case 'l':
        subm = (subm + 1) % 6;
        break;
      case K_PGUP:
      case '\002': /* Control-B */
        pgud = 1;
        quit = 1;
        break;
      case K_PGDN:
      case '\006': /* Control-F */
        pgud = 2;
        quit = 1;
        break;
      case ' ':    /* Tag if not directory */
        if (S_ISDIR(d->mode)) {
          time_t this_time = time((time_t *)NULL);
          if (this_time - click_time < 2) {
            GETSDIR_ENTRY *d2 = getno(cur, global_dirdat);
            goto_filedir(d2->fname, 0);
            click_time = (time_t)0;
          } else
            click_time = this_time;
        }
        else {
          if (how_many) {
            if ((d->cflags ^= FL_TAG) & FL_TAG) {
              if (tag_cnt && how_many == 1) {
                d->cflags &= ~FL_TAG;
                file_tell(_("Can select only one!"));
                break;
              }
              ++tag_cnt;
            } else
              --tag_cnt;
            mc_wlocate(main_w, 0, cur + FILE_MWTR - top);
            prone(main_w, d, longest, d->cflags & FL_TAG);
            mc_wputc(main_w, '\n');
            cur += cur < nrents - 1;
          }
        }
        break;

      case '\033':
      case '\r':
      case '\n':
        quit = 1;
        break;

      default:
	for (i = 0; i < WHAT_NR_OPTIONS; i++) {
	  if (strchr (_(what[i]), toupper (c)) != NULL) {
	    subm = i;
	    c = '\n';
	    quit = 1;
	    break;
	  }
	 }

        break;
    }

    if (c != ' ')
      click_time = (time_t)0;

    if (cur < top) {
      top--;
      prdir(main_w, top, top, global_dirdat, longest);
    }
    if (cur - top > main_w->ys - (2 + FILE_MWTR)) {
      top++;
      prdir(main_w, top, top, global_dirdat, longest);
    }
    /*
     if(cur != ocur)
     mc_wlocate(main_w, 0, cur + FILE_MWTR - top);
     */

    ocur = cur;
    dhili(subm);
    /* this really needs to go in dhili !!!*/
    mc_wlocate(main_w, 0, cur + FILE_MWTR - top);
  }

  quit = 0;
  /* ESC means quit */
  if (c == '\033') {
    mc_wclose(main_w, 1);
    mc_wclose(dsub, 1);
    free(global_dirdat);
    global_dirdat = NULL;
    return NULL;
  }
  /* Page up or down ? */
  if (pgud == 1) { /* Page up */
    ocur = top;
    top -= main_w->ys - (1 + FILE_MWTR);
    if (top < 0)
      top = 0;
    cur = top;
    pgud = 0;
    if (ocur != top)
      prdir(main_w, top, cur, global_dirdat, longest);
    ocur = cur;
    goto again;
  }
  if (pgud == 2) { /* Page down */
    ocur = top;
    if (top < nrents - main_w->ys + (1 + FILE_MWTR)) {
      top += main_w->ys - (1 + FILE_MWTR);
      if (top > nrents - main_w->ys + (1 + FILE_MWTR)) {
        top = nrents - main_w->ys + (1 + FILE_MWTR);
      }
      cur = top;
    } else
      cur = nrents - 1;
    pgud = 0;
    if (ocur != top)
      prdir(main_w, top, cur, global_dirdat, longest);
    ocur = cur;
    goto again;
  }

  if (c =='\r' || c == '\n') {
    switch(subm) {
      case 0:
        /* Goto directory */
        {
          char buf[128];
          char *s;
          strncpy(buf, down_loading? P_DOWNDIR : P_UPDIR, sizeof(buf) -1);
          s = input(_("Goto directory:"), buf);
          /* if(s == NULL || *s == (char) 0) */
          if (s == NULL)
            break;
          goto_filedir(buf, 1);
        }
        break;
      case 1:
        /* Previous directory */
        goto_filedir(prev_dir, 1);
        break;
      case 2:
        /* File (wildcard) spec */
        {
          char *s = input(_("Filename pattern:"), wc_mem);
          if (s == NULL || *s == (char) 0)
            break;
          strcpy(wc_str, wc_mem);
          new_filedir(global_dirdat, 1);
          wc_str[0] = (char)0;
        }
        break;
      case 3:
        /* Tag */
        if (how_many == 1)
          file_tell(_("Can select only one!"));
        else if (how_many == -1) {
          char tag_buf[128];
          char *s;
          strncpy(tag_buf, wc_mem, 128);

          s = input(_("Tag pattern:"), tag_buf);
          if (s != NULL && *s != (char)0) {
            int newly_tagged;
            if ((newly_tagged = tag_untag(tag_buf, 1)) == 0) {
              file_tell(_("No file(s) tagged"));
              goto tag_end;
            }
            tag_cnt += newly_tagged;
            prdir(main_w, top, top, global_dirdat, longest);  
          }
        }
tag_end:
        break;
      case 4:
        /* Untag */
        {
          char tag_buf[128];
          char *s;
          int untagged;
          strncpy(tag_buf, wc_mem, 128);

          s = input(_("Untag pattern:"), tag_buf);
          if (s == NULL || *s == (char)0)
            goto untag_end;
          if ((untagged = tag_untag(tag_buf, 0)) == 0) {
            file_tell(_("No file(s) untagged"));
            goto untag_end;
          }
          tag_cnt -= untagged;
          prdir(main_w, top, top, global_dirdat, longest);  
        }
untag_end:
        break;
      case 5:
        {
          /* Done */
          char *ret_ptr = NULL;	/* failsafe: assume failure */

          if (how_many != 0 && !tag_cnt) {

            while (1) {
              s = input(_("No file selected - enter filename:"),
                        ret_buf);
              if (s != NULL && *s != (char) 0) {
                int f_exist = access(ret_buf, F_OK);
                if (down_loading) {
                  if (f_exist != -1) {
                    /* ask 'em if they're *sure* */
                    char buf[BUFSIZ];

                    snprintf(buf, sizeof(buf), 
                             _("File: \"%s\" exists! Overwrite?"), ret_buf);
                    if (ask(buf, d_yesno) == 0) {
                      ret_ptr = ret_buf;
                      break;
                    }
                  } else {
                    ret_ptr = ret_buf;
                    break;
                  }
                } else {
                  if (f_exist == -1)
                    file_tell(_("no such file!"));
                  else {
                    ret_ptr = ret_buf;
                    break;
                  }
                }
              } else {
                /* maybe want to ask: "abort?", here */
                goto again;
              }
            }
          }
          else {
            /* put 'em in a buffer for return */
            if (how_many == 0) {
              /* current working directory */
              ret_ptr = work_dir;
            } else {
              ret_ptr = concat_list(global_dirdat);
            }
          }

          mc_wclose(main_w, 1);
          mc_wclose(dsub, 1);
          free(global_dirdat);
	  global_dirdat = NULL;
          return ret_ptr;
        }
        break;
      default:
        /* should "beep", I guess (? shouldn't get here) */
        file_tell("BEEP!");
        break;
    } /* switch */
  }

  goto again;
}
void Cooperativedictionary::on_getNoButton_clicked()
{
	QString strNo = ui.lineEdit->text();
	emit getno(strNo);
	this->close();
}